X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/e795e96407a9fc6554e7af8feb583459eaf0cd1e..7dff6b46615bc7810e4e66f957fe993b1c0a968d:/regexp.h diff --git a/regexp.h b/regexp.h index 298a417..db36edd 100644 --- a/regexp.h +++ b/regexp.h @@ -50,11 +50,39 @@ struct reg_substr_data { #define SV_SAVED_COPY #endif +/* offsets within a string of a particular /(.)/ capture */ + typedef struct regexp_paren_pair { I32 start; I32 end; + /* 'start_tmp' records a new opening position before the matching end + * has been found, so that the old start and end values are still + * valid, e.g. + * "abc" =~ /(.(?{print "[$1]"}))+/ + *outputs [][a][b] + * This field is not part of the API. */ + I32 start_tmp; } regexp_paren_pair; +#if defined(PERL_IN_REGCOMP_C) || defined(PERL_IN_UTF8_C) +#define _invlist_union(a, b, output) _invlist_union_maybe_complement_2nd(a, b, FALSE, output) +#define _invlist_intersection(a, b, output) _invlist_intersection_maybe_complement_2nd(a, b, FALSE, output) + +/* Subtracting b from a leaves in a everything that was there that isn't in b, + * that is the intersection of a with b's complement */ +#define _invlist_subtract(a, b, output) _invlist_intersection_maybe_complement_2nd(a, b, TRUE, output) +#endif + +/* record the position of a (?{...}) within a pattern */ + +struct reg_code_block { + STRLEN start; + STRLEN end; + OP *block; + REGEXP *src_regex; +}; + + /* The regexp/REGEXP struct, see L for further documentation on the individual fields. The struct is ordered so that the most @@ -99,8 +127,7 @@ typedef struct regexp_paren_pair { /* Information about the match that isn't often used */ \ /* offset from wrapped to the start of precomp */ \ PERL_BITFIELD32 pre_prefix:4; \ - /* number of eval groups in the pattern - for security checks */\ - PERL_BITFIELD32 seen_evals:28 + CV *qr_anoncv /* the anon sub wrapped round qr/(?{..})/ */ typedef struct regexp { _XPV_HEAD; @@ -143,6 +170,10 @@ typedef struct regexp_engine { #ifdef USE_ITHREADS void* (*dupe) (pTHX_ REGEXP * const rx, CLONE_PARAMS *param); #endif + REGEXP* (*op_comp) (pTHX_ SV ** const patternp, int pat_count, + OP *expr, const struct regexp_engine* eng, + REGEXP *VOL old_re, + bool *is_bare_re, U32 orig_rx_flags, U32 pm_flags); } regexp_engine; /* @@ -190,20 +221,17 @@ equivalent to the following snippet: if (SvMAGICAL(sv)) mg_get(sv); - if (SvROK(sv) && - (tmpsv = (SV*)SvRV(sv)) && - SvTYPE(tmpsv) == SVt_PVMG && - (tmpmg = mg_find(tmpsv, PERL_MAGIC_qr))) - { - return (REGEXP *)tmpmg->mg_obj; - } + if (SvROK(sv)) + sv = MUTABLE_SV(SvRV(sv)); + if (SvTYPE(sv) == SVt_REGEXP) + return (REGEXP*) sv; NULL will be returned if a REGEXP* is not found. =for apidoc Am|bool|SvRXOK|SV* sv -Returns a boolean indicating whether the SV contains qr magic -(PERL_MAGIC_qr). +Returns a boolean indicating whether the SV (or the one it references) +is a REGEXP. If you want to do something with the REGEXP* later use SvRX instead and check for NULL. @@ -221,8 +249,8 @@ and check for NULL. * Note that the flags whose names start with RXf_PMf_ are defined in * op_reg_common.h, being copied from the parallel flags of op_pmflags * - * NOTE: if you modify any RXf flags you should run regen.pl or regcomp.pl - * so that regnodes.h is updated with the changes. + * NOTE: if you modify any RXf flags you should run regen.pl or + * regen/regcomp.pl so that regnodes.h is updated with the changes. * */ @@ -236,13 +264,18 @@ and check for NULL. case SINGLE_PAT_MOD: *(pmfl) |= RXf_PMf_SINGLELINE; break; \ case XTENDED_PAT_MOD: *(pmfl) |= RXf_PMf_EXTENDED; break +/* Note, includes charset ones, assumes 0 is the default for them */ +#define STD_PMMOD_FLAGS_CLEAR(pmfl) \ + *(pmfl) &= ~(RXf_PMf_FOLD|RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_EXTENDED|RXf_PMf_CHARSET) + /* chars and strings used as regex pattern modifiers - * Singlular is a 'c'har, plural is a "string" + * Singular is a 'c'har, plural is a "string" * * NOTE, KEEPCOPY was originally 'k', but was changed to 'p' for preserve * for compatibility reasons with Regexp::Common which highjacked (?k:...) * for its own uses. So 'k' is out as well. */ +#define DEFAULT_PAT_MOD '^' /* Short for all the default modifiers */ #define EXEC_PAT_MOD 'e' #define KEEPCOPY_PAT_MOD 'p' #define ONCE_PAT_MOD 'o' @@ -253,37 +286,79 @@ and check for NULL. #define IGNORE_PAT_MOD 'i' #define XTENDED_PAT_MOD 'x' #define NONDESTRUCT_PAT_MOD 'r' +#define LOCALE_PAT_MOD 'l' +#define UNICODE_PAT_MOD 'u' +#define DEPENDS_PAT_MOD 'd' +#define ASCII_RESTRICT_PAT_MOD 'a' #define ONCE_PAT_MODS "o" #define KEEPCOPY_PAT_MODS "p" #define EXEC_PAT_MODS "e" #define LOOP_PAT_MODS "gc" #define NONDESTRUCT_PAT_MODS "r" +#define LOCALE_PAT_MODS "l" +#define UNICODE_PAT_MODS "u" +#define DEPENDS_PAT_MODS "d" +#define ASCII_RESTRICT_PAT_MODS "a" +#define ASCII_MORE_RESTRICT_PAT_MODS "aa" /* This string is expected by regcomp.c to be ordered so that the first * character is the flag in bit RXf_PMf_STD_PMMOD_SHIFT of extflags; the next * character is bit +1, etc. */ #define STD_PAT_MODS "msix" +#define CHARSET_PAT_MODS ASCII_RESTRICT_PAT_MODS DEPENDS_PAT_MODS LOCALE_PAT_MODS UNICODE_PAT_MODS + /* This string is expected by XS_re_regexp_pattern() in universal.c to be ordered * so that the first character is the flag in bit RXf_PMf_STD_PMMOD_SHIFT of * extflags; the next character is in bit +1, etc. */ #define INT_PAT_MODS STD_PAT_MODS KEEPCOPY_PAT_MODS #define EXT_PAT_MODS ONCE_PAT_MODS KEEPCOPY_PAT_MODS -#define QR_PAT_MODS STD_PAT_MODS EXT_PAT_MODS +#define QR_PAT_MODS STD_PAT_MODS EXT_PAT_MODS CHARSET_PAT_MODS #define M_PAT_MODS QR_PAT_MODS LOOP_PAT_MODS #define S_PAT_MODS M_PAT_MODS EXEC_PAT_MODS NONDESTRUCT_PAT_MODS /* - * NOTE: if you modify any RXf flags you should run regen.pl or regcomp.pl - * so that regnodes.h is updated with the changes. + * NOTE: if you modify any RXf flags you should run regen.pl or + * regen/regcomp.pl so that regnodes.h is updated with the changes. * */ /* Leave some space, so future bit allocations can go either in the shared or * unshared area without affecting binary compatibility */ -#define RXf_BASE_SHIFT (_RXf_PMf_SHIFT_NEXT+3) +#define RXf_BASE_SHIFT (_RXf_PMf_SHIFT_NEXT+1) + +/* Manually decorate this function with gcc-style attributes just to + * avoid having to restructure the header files and their called order, + * as proto.h would have to be included before this file, and isn't */ + +PERL_STATIC_INLINE const char * +get_regex_charset_name(const U32 flags, STRLEN* const lenp) + __attribute__warn_unused_result__; + +#define MAX_CHARSET_NAME_LENGTH 2 + +PERL_STATIC_INLINE const char * +get_regex_charset_name(const U32 flags, STRLEN* const lenp) +{ + /* Returns a string that corresponds to the name of the regex character set + * given by 'flags', and *lenp is set the length of that string, which + * cannot exceed MAX_CHARSET_NAME_LENGTH characters */ + + *lenp = 1; + switch (get_regex_charset(flags)) { + case REGEX_DEPENDS_CHARSET: return DEPENDS_PAT_MODS; + case REGEX_LOCALE_CHARSET: return LOCALE_PAT_MODS; + case REGEX_UNICODE_CHARSET: return UNICODE_PAT_MODS; + case REGEX_ASCII_RESTRICTED_CHARSET: return ASCII_RESTRICT_PAT_MODS; + case REGEX_ASCII_MORE_RESTRICTED_CHARSET: + *lenp = 2; + return ASCII_MORE_RESTRICT_PAT_MODS; + default: + return "?"; /* Unknown */ + } +} /* Anchor and GPOS related stuff */ #define RXf_ANCH_BOL (1<<(RXf_BASE_SHIFT+0)) @@ -325,21 +400,25 @@ and check for NULL. /* Copy and tainted info */ #define RXf_COPY_DONE (1<<(RXf_BASE_SHIFT+16)) + +/* during execution: pattern temporarily tainted by executing locale ops; + * post-execution: $1 et al are tainted */ #define RXf_TAINTED_SEEN (1<<(RXf_BASE_SHIFT+17)) -#define RXf_TAINTED (1<<(RXf_BASE_SHIFT+18)) /* this pattern is tainted */ +/* this pattern was tainted during compilation */ +#define RXf_TAINTED (1<<(RXf_BASE_SHIFT+18)) /* Flags indicating special patterns */ #define RXf_START_ONLY (1<<(RXf_BASE_SHIFT+19)) /* Pattern is /^/ */ #define RXf_SKIPWHITE (1<<(RXf_BASE_SHIFT+20)) /* Pattern is for a split / / */ #define RXf_WHITE (1<<(RXf_BASE_SHIFT+21)) /* Pattern is /\s+/ */ -#define RXf_NULL (1<<(RXf_BASE_SHIFT+22)) /* Pattern is // */ +#define RXf_NULL (1U<<(RXf_BASE_SHIFT+22)) /* Pattern is // */ #if RXf_BASE_SHIFT+22 > 31 # error Too many RXf_PMf bits used. See regnodes.h for any spare in middle #endif /* - * NOTE: if you modify any RXf flags you should run regen.pl or regcomp.pl - * so that regnodes.h is updated with the changes. + * NOTE: if you modify any RXf flags you should run regen.pl or + * regen/regcomp.pl so that regnodes.h is updated with the changes. * */ @@ -420,12 +499,11 @@ and check for NULL. #define RX_GOFS(prog) (((struct regexp *)SvANY(prog))->gofs) #define RX_LASTPAREN(prog) (((struct regexp *)SvANY(prog))->lastparen) #define RX_LASTCLOSEPAREN(prog) (((struct regexp *)SvANY(prog))->lastcloseparen) -#define RX_SEEN_EVALS(prog) (((struct regexp *)SvANY(prog))->seen_evals) #define RX_SAVED_COPY(prog) (((struct regexp *)SvANY(prog))->saved_copy) #endif /* PLUGGABLE_RE_EXTENSION */ -/* Stuff that needs to be included in the plugable extension goes below here */ +/* Stuff that needs to be included in the pluggable extension goes below here */ #ifdef PERL_OLD_COPY_ON_WRITE #define RX_MATCH_COPY_FREE(rx) \ @@ -532,6 +610,7 @@ typedef struct regmatch_state { /* this first element must match u.yes */ struct regmatch_state *prev_yes_state; U32 lastparen; + U32 lastcloseparen; CHECKPOINT cp; } branchlike; @@ -540,6 +619,7 @@ typedef struct regmatch_state { /* the first elements must match u.branchlike */ struct regmatch_state *prev_yes_state; U32 lastparen; + U32 lastcloseparen; CHECKPOINT cp; regnode *next_branch; /* next branch node */ @@ -549,17 +629,17 @@ typedef struct regmatch_state { /* the first elements must match u.branchlike */ struct regmatch_state *prev_yes_state; U32 lastparen; + U32 lastcloseparen; CHECKPOINT cp; U32 accepted; /* how many accepting states left */ + bool longfold;/* saw a fold with a 1->n char mapping */ U16 *jump; /* positive offsets from me */ - regnode *B; /* node following the trie */ regnode *me; /* Which node am I - needed for jump tries*/ U8 *firstpos;/* pos in string of first trie match */ U32 firstchars;/* len in chars of firstpos from start */ U16 nextword;/* next word to try */ U16 topword; /* longest accepted word */ - bool longfold;/* saw a fold with a 1->n char mapping */ } trie; /* special types - these members are used to store state for special @@ -632,6 +712,8 @@ typedef struct regmatch_state { struct regmatch_state *prev_yes_state; I32 c1, c2; /* case fold search */ CHECKPOINT cp; + U32 lastparen; + U32 lastcloseparen; I32 alen; /* length of first-matched A string */ I32 count; bool minmod; @@ -642,6 +724,8 @@ typedef struct regmatch_state { struct { U32 paren; CHECKPOINT cp; + U32 lastparen; + U32 lastcloseparen; I32 c1, c2; /* case fold search */ char *maxpos; /* highest possible point in string to match */ char *oldloc; /* the previous locinput */ @@ -669,12 +753,6 @@ typedef struct regmatch_slab { #define PL_bostr PL_reg_state.re_state_bostr #define PL_reginput PL_reg_state.re_state_reginput #define PL_regeol PL_reg_state.re_state_regeol -#define PL_regoffs PL_reg_state.re_state_regoffs -#define PL_reglastparen PL_reg_state.re_state_reglastparen -#define PL_reglastcloseparen PL_reg_state.re_state_reglastcloseparen -#define PL_reg_start_tmp PL_reg_state.re_state_reg_start_tmp -#define PL_reg_start_tmpl PL_reg_state.re_state_reg_start_tmpl -#define PL_reg_eval_set PL_reg_state.re_state_reg_eval_set #define PL_reg_match_utf8 PL_reg_state.re_state_reg_match_utf8 #define PL_reg_magic PL_reg_state.re_state_reg_magic #define PL_reg_oldpos PL_reg_state.re_state_reg_oldpos @@ -692,16 +770,12 @@ typedef struct regmatch_slab { struct re_save_state { U32 re_state_reg_flags; /* from regexec.c */ - U32 re_state_reg_start_tmpl; /* from regexec.c */ - I32 re_state_reg_eval_set; /* from regexec.c */ + bool re_state_eval_setup_done; /* from regexec.c */ bool re_state_reg_match_utf8; /* from regexec.c */ + bool re_reparsing; /* runtime (?{}) fed back into parser */ char *re_state_bostr; char *re_state_reginput; /* String-input pointer. */ char *re_state_regeol; /* End of input, for $ check. */ - regexp_paren_pair *re_state_regoffs; /* Pointer to start/end pairs */ - U32 *re_state_reglastparen; /* Similarly for lastparen. */ - U32 *re_state_reglastcloseparen; /* Similarly for lastcloseparen. */ - char **re_state_reg_start_tmp; /* from regexec.c */ MAGIC *re_state_reg_magic; /* from regexec.c */ PMOP *re_state_reg_oldcurpm; /* from regexec.c */ PMOP *re_state_reg_curpm; /* from regexec.c */ @@ -726,8 +800,8 @@ struct re_save_state { * Local variables: * c-indentation-style: bsd * c-basic-offset: 4 - * indent-tabs-mode: t + * indent-tabs-mode: nil * End: * - * ex: set ts=8 sts=4 sw=4 noet: + * ex: set ts=8 sts=4 sw=4 et: */