From: Yves Orton Date: Thu, 28 Jun 2007 23:14:39 +0000 (+0000) Subject: Rename various regex defined so that they have distinct prefixes based on their usage. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f1b875a0a91038690cebe55acd7ad1e37e6a2621;p=p5sagit%2Fp5-mst-13.2.git Rename various regex defined so that they have distinct prefixes based on their usage. RXf_ => flags used in pm_flags argument to regcomp and stored in the regex via rx->extflags PREGf_ => flags stored in rx->intflags RXapif_ => argument flags for regex named capture api RX_BUFF_IDX_ => special indexes to represent $` $' $& used in the numeric capture buffer api PREGf is untouched by this change, but RXf_ is split into RXapif and RX_BUFF_IDX_. p4raw-id: //depot/perl@31497 --- diff --git a/mg.c b/mg.c index c68543c..06d4c8c 100644 --- a/mg.c +++ b/mg.c @@ -603,15 +603,15 @@ Perl_magic_len(pTHX_ SV *sv, MAGIC *mg) } case '`': do_prematch: - paren = RXf_PREMATCH; + paren = RX_BUFF_IDX_PREMATCH; goto maybegetparen; case '\'': do_postmatch: - paren = RXf_POSTMATCH; + paren = RX_BUFF_IDX_POSTMATCH; goto maybegetparen; case '&': do_match: - paren = RXf_MATCH; + paren = RX_BUFF_IDX_FULLMATCH; goto maybegetparen; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': @@ -2255,15 +2255,15 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) goto do_match; case '`': /* ${^PREMATCH} caught below */ do_prematch: - paren = RXf_PREMATCH; + paren = RX_BUFF_IDX_PREMATCH; goto setparen; case '\'': /* ${^POSTMATCH} caught below */ do_postmatch: - paren = RXf_POSTMATCH; + paren = RX_BUFF_IDX_POSTMATCH; goto setparen; case '&': do_match: - paren = RXf_MATCH; + paren = RX_BUFF_IDX_FULLMATCH; goto setparen; case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': diff --git a/perl.h b/perl.h index 5b8c574..d59ac35 100644 --- a/perl.h +++ b/perl.h @@ -229,31 +229,31 @@ CALL_FPTR((rx)->engine->numbered_buff_LENGTH)(aTHX_ (rx),(sv),(paren)) #define CALLREG_NAMED_BUFF_FETCH(rx, key, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXf_HASH_FETCH)) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXapif_FETCH)) #define CALLREG_NAMED_BUFF_STORE(rx, key, value, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), (value), ((flags) | RXf_HASH_STORE)) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), (value), ((flags) | RXapif_STORE)) #define CALLREG_NAMED_BUFF_DELETE(rx, key, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx),(key), NULL, ((flags) | RXf_HASH_DELETE)) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx),(key), NULL, ((flags) | RXapif_DELETE)) #define CALLREG_NAMED_BUFF_CLEAR(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXf_HASH_CLEAR)) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_CLEAR)) #define CALLREG_NAMED_BUFF_EXISTS(rx, key, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXf_HASH_EXISTS)) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), (key), NULL, ((flags) | RXapif_EXISTS)) #define CALLREG_NAMED_BUFF_FIRSTKEY(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff_iter)(aTHX_ (rx), NULL, ((flags) | RXf_HASH_FIRSTKEY)) + CALL_FPTR((rx)->engine->named_buff_iter)(aTHX_ (rx), NULL, ((flags) | RXapif_FIRSTKEY)) #define CALLREG_NAMED_BUFF_NEXTKEY(rx, lastkey, flags) \ - CALL_FPTR((rx)->engine->named_buff_iter)(aTHX_ (rx), (lastkey), ((flags) | RXf_HASH_NEXTKEY)) + CALL_FPTR((rx)->engine->named_buff_iter)(aTHX_ (rx), (lastkey), ((flags) | RXapif_NEXTKEY)) #define CALLREG_NAMED_BUFF_SCALAR(rx, flags) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXf_HASH_SCALAR)) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, ((flags) | RXapif_SCALAR)) #define CALLREG_NAMED_BUFF_COUNT(rx) \ - CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, RXf_HASH_REGNAMES_COUNT) + CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, RXapif_REGNAMES_COUNT) #define CALLREG_NAMED_BUFF_ALL(rx, flags) \ CALL_FPTR((rx)->engine->named_buff)(aTHX_ (rx), NULL, NULL, flags) diff --git a/pod/perlreapi.pod b/pod/perlreapi.pod index 084762d..cb7bbfc 100644 --- a/pod/perlreapi.pod +++ b/pod/perlreapi.pod @@ -349,27 +349,27 @@ currently defined: Which L operation is being performed from the Perl level on C<%+> or C<%+>, if any: - RXf_HASH_FETCH - RXf_HASH_STORE - RXf_HASH_DELETE - RXf_HASH_CLEAR - RXf_HASH_EXISTS - RXf_HASH_SCALAR - RXf_HASH_FIRSTKEY - RXf_HASH_NEXTKEY + RXapif_FETCH + RXapif_STORE + RXapif_DELETE + RXapif_CLEAR + RXapif_EXISTS + RXapif_SCALAR + RXapif_FIRSTKEY + RXapif_NEXTKEY Whether C<%+> or C<%-> is being operated on, if any. - RXf_HASH_ONE /* %+ */ - RXf_HASH_ALL /* %- */ + RXapif_ONE /* %+ */ + RXapif_ALL /* %- */ Whether this is being called as C, C or C, if any. The first two will be combined with -C or C. +C or C. - RXf_HASH_REGNAME - RXf_HASH_REGNAMES - RXf_HASH_REGNAMES_COUNT + RXapif_REGNAME + RXapif_REGNAMES + RXapif_REGNAMES_COUNT Internally C<%+> and C<%-> are implemented with a real tied interface via L. The methods in that package will call diff --git a/regcomp.c b/regcomp.c index 6266ab3..0f87282 100644 --- a/regcomp.c +++ b/regcomp.c @@ -4760,7 +4760,7 @@ reStudy: r->extflags |= RXf_WHITE; else if (r->prelen == 1 && r->precomp[0] == '^') r->extflags |= RXf_START_ONLY; -#endif +#else if (r->extflags & RXf_SPLIT && r->prelen == 1 && r->precomp[0] == ' ') /* XXX: this should happen BEFORE we compile */ r->extflags |= (RXf_SKIPWHITE|RXf_WHITE); @@ -4774,7 +4774,7 @@ reStudy: else if (fop == PLUS && nop ==SPACE && OP(regnext(first))==END) r->extflags |= RXf_WHITE; } - +#endif #ifdef DEBUGGING if (RExC_paren_names) { ri->name_list_idx = add_data( pRExC_state, 1, "p" ); @@ -4822,18 +4822,18 @@ Perl_reg_named_buff(pTHX_ REGEXP * const rx, SV * const key, SV * const value, { PERL_UNUSED_ARG(value); - if (flags & RXf_HASH_FETCH) { + if (flags & RXapif_FETCH) { return reg_named_buff_fetch(rx, key, flags); - } else if (flags & (RXf_HASH_STORE | RXf_HASH_DELETE | RXf_HASH_CLEAR)) { + } else if (flags & (RXapif_STORE | RXapif_DELETE | RXapif_CLEAR)) { Perl_croak(aTHX_ PL_no_modify); return NULL; - } else if (flags & RXf_HASH_EXISTS) { + } else if (flags & RXapif_EXISTS) { return reg_named_buff_exists(rx, key, flags) ? &PL_sv_yes : &PL_sv_no; - } else if (flags & RXf_HASH_REGNAMES) { + } else if (flags & RXapif_REGNAMES) { return reg_named_buff_all(rx, flags); - } else if (flags & (RXf_HASH_SCALAR | RXf_HASH_REGNAMES_COUNT)) { + } else if (flags & (RXapif_SCALAR | RXapif_REGNAMES_COUNT)) { return reg_named_buff_scalar(rx, flags); } else { Perl_croak(aTHX_ "panic: Unknown flags %d in named_buff", (int)flags); @@ -4847,9 +4847,9 @@ Perl_reg_named_buff_iter(pTHX_ REGEXP * const rx, const SV * const lastkey, { PERL_UNUSED_ARG(lastkey); - if (flags & RXf_HASH_FIRSTKEY) + if (flags & RXapif_FIRSTKEY) return reg_named_buff_firstkey(rx, flags); - else if (flags & RXf_HASH_NEXTKEY) + else if (flags & RXapif_NEXTKEY) return reg_named_buff_nextkey(rx, flags); else { Perl_croak(aTHX_ "panic: Unknown flags %d in named_buff_iter", (int)flags); @@ -4862,7 +4862,7 @@ Perl_reg_named_buff_fetch(pTHX_ REGEXP * const rx, SV * const namesv, const U32 { AV *retarray = NULL; SV *ret; - if (flags & RXf_HASH_ALL) + if (flags & RXapif_ALL) retarray=newAV(); if (rx && rx->paren_names) { @@ -4900,7 +4900,7 @@ Perl_reg_named_buff_exists(pTHX_ REGEXP * const rx, SV * const key, const U32 flags) { if (rx && rx->paren_names) { - if (flags & RXf_HASH_ALL) { + if (flags & RXapif_ALL) { return hv_exists_ent(rx->paren_names, key, 0); } else { SV *sv = CALLREG_NAMED_BUFF_FETCH(rx, key, flags); @@ -4921,7 +4921,7 @@ Perl_reg_named_buff_firstkey(pTHX_ REGEXP * const rx, const U32 flags) { (void)hv_iterinit(rx->paren_names); - return CALLREG_NAMED_BUFF_NEXTKEY(rx, NULL, flags & ~RXf_HASH_FIRSTKEY); + return CALLREG_NAMED_BUFF_NEXTKEY(rx, NULL, flags & ~RXapif_FIRSTKEY); } SV* @@ -4944,7 +4944,7 @@ Perl_reg_named_buff_nextkey(pTHX_ REGEXP * const rx, const U32 flags) break; } } - if (parno || flags & RXf_HASH_ALL) { + if (parno || flags & RXapif_ALL) { STRLEN len; char *pv = HePV(temphe, len); return newSVpvn(pv,len); @@ -4962,10 +4962,10 @@ Perl_reg_named_buff_scalar(pTHX_ REGEXP * const rx, const U32 flags) I32 length; if (rx && rx->paren_names) { - if (flags & (RXf_HASH_ALL | RXf_HASH_REGNAMES_COUNT)) { + if (flags & (RXapif_ALL | RXapif_REGNAMES_COUNT)) { return newSViv(HvTOTALKEYS(rx->paren_names)); - } else if (flags & RXf_HASH_ONE) { - ret = CALLREG_NAMED_BUFF_ALL(rx, (flags | RXf_HASH_REGNAMES)); + } else if (flags & RXapif_ONE) { + ret = CALLREG_NAMED_BUFF_ALL(rx, (flags | RXapif_REGNAMES)); av = (AV*)SvRV(ret); length = av_len(av); return newSViv(length + 1); @@ -5000,7 +5000,7 @@ Perl_reg_named_buff_all(pTHX_ REGEXP * const rx, const U32 flags) break; } } - if (parno || flags & RXf_HASH_ALL) { + if (parno || flags & RXapif_ALL) { STRLEN len; char *pv = HePV(temphe, len); av_push(av, newSVpvn(pv,len)); @@ -5023,13 +5023,13 @@ Perl_reg_numbered_buff_fetch(pTHX_ REGEXP * const rx, const I32 paren, SV * cons return; } else - if (paren == RXf_PREMATCH && rx->offs[0].start != -1) { + if (paren == RX_BUFF_IDX_PREMATCH && rx->offs[0].start != -1) { /* $` */ i = rx->offs[0].start; s = rx->subbeg; } else - if (paren == RXf_POSTMATCH && rx->offs[0].end != -1) { + if (paren == RX_BUFF_IDX_POSTMATCH && rx->offs[0].end != -1) { /* $' */ s = rx->subbeg + rx->offs[0].end; i = rx->sublen - rx->offs[0].end; @@ -5108,7 +5108,7 @@ Perl_reg_numbered_buff_length(pTHX_ REGEXP * const rx, const SV * const sv, /* Some of this code was originally in C in F */ switch (paren) { /* $` / ${^PREMATCH} */ - case RXf_PREMATCH: + case RX_BUFF_IDX_PREMATCH: if (rx->offs[0].start != -1) { i = rx->offs[0].start; if (i > 0) { @@ -5119,7 +5119,7 @@ Perl_reg_numbered_buff_length(pTHX_ REGEXP * const rx, const SV * const sv, } return 0; /* $' / ${^POSTMATCH} */ - case RXf_POSTMATCH: + case RX_BUFF_IDX_POSTMATCH: if (rx->offs[0].end != -1) { i = rx->sublen - rx->offs[0].end; if (i > 0) { diff --git a/regexp.h b/regexp.h index bf4c57d..a40bd1d 100644 --- a/regexp.h +++ b/regexp.h @@ -151,9 +151,9 @@ typedef struct regexp_engine { paren name. >= 1 is reserved for actual numbered captures, i.e. $1, $2 etc. */ -#define RXf_PREMATCH -2 /* $` / ${^PREMATCH} */ -#define RXf_POSTMATCH -1 /* $' / ${^POSTMATCH} */ -#define RXf_MATCH 0 /* $& / ${^MATCH} */ +#define RX_BUFF_IDX_PREMATCH -2 /* $` / ${^PREMATCH} */ +#define RX_BUFF_IDX_POSTMATCH -1 /* $' / ${^POSTMATCH} */ +#define RX_BUFF_IDX_FULLMATCH 0 /* $& / ${^MATCH} */ /* Flags that are passed to the named_buff and named_buff_iter @@ -163,23 +163,23 @@ typedef struct regexp_engine { */ /* The Tie::Hash::NamedCapture operation this is part of, if any */ -#define RXf_HASH_FETCH 0x0001 -#define RXf_HASH_STORE 0x0002 -#define RXf_HASH_DELETE 0x0004 -#define RXf_HASH_CLEAR 0x0008 -#define RXf_HASH_EXISTS 0x0010 -#define RXf_HASH_SCALAR 0x0020 -#define RXf_HASH_FIRSTKEY 0x0040 -#define RXf_HASH_NEXTKEY 0x0080 +#define RXapif_FETCH 0x0001 +#define RXapif_STORE 0x0002 +#define RXapif_DELETE 0x0004 +#define RXapif_CLEAR 0x0008 +#define RXapif_EXISTS 0x0010 +#define RXapif_SCALAR 0x0020 +#define RXapif_FIRSTKEY 0x0040 +#define RXapif_NEXTKEY 0x0080 /* Whether %+ or %- is being operated on */ -#define RXf_HASH_ONE 0x0100 /* %+ */ -#define RXf_HASH_ALL 0x0200 /* %- */ +#define RXapif_ONE 0x0100 /* %+ */ +#define RXapif_ALL 0x0200 /* %- */ /* Whether this is being called from a re:: function */ -#define RXf_HASH_REGNAME 0x0400 -#define RXf_HASH_REGNAMES 0x0800 -#define RXf_HASH_REGNAMES_COUNT 0x1000 +#define RXapif_REGNAME 0x0400 +#define RXapif_REGNAMES 0x0800 +#define RXapif_REGNAMES_COUNT 0x1000 /* =head1 REGEXP Functions @@ -301,7 +301,7 @@ and check for NULL. /* UTF8 related */ #define RXf_UTF8 0x00400000 -#define RXf_MATCH_UTF8 0x00800000 +#define RX_BUFF_IDX_FULLMATCH_UTF8 0x00800000 /* Intuit related */ #define RXf_USE_INTUIT_NOML 0x01000000 @@ -359,9 +359,9 @@ and check for NULL. }} STMT_END #endif -#define RX_MATCH_UTF8(prog) ((prog)->extflags & RXf_MATCH_UTF8) -#define RX_MATCH_UTF8_on(prog) ((prog)->extflags |= RXf_MATCH_UTF8) -#define RX_MATCH_UTF8_off(prog) ((prog)->extflags &= ~RXf_MATCH_UTF8) +#define RX_MATCH_UTF8(prog) ((prog)->extflags & RX_BUFF_IDX_FULLMATCH_UTF8) +#define RX_MATCH_UTF8_on(prog) ((prog)->extflags |= RX_BUFF_IDX_FULLMATCH_UTF8) +#define RX_MATCH_UTF8_off(prog) ((prog)->extflags &= ~RX_BUFF_IDX_FULLMATCH_UTF8) #define RX_MATCH_UTF8_set(prog, t) ((t) \ ? (RX_MATCH_UTF8_on(prog), (PL_reg_match_utf8 = 1)) \ : (RX_MATCH_UTF8_off(prog), (PL_reg_match_utf8 = 0))) diff --git a/universal.c b/universal.c index 2b39583..457fffa 100644 --- a/universal.c +++ b/universal.c @@ -1118,11 +1118,11 @@ XS(XS_re_regname) XSRETURN_UNDEF; if (items == 2 && SvTRUE(ST(1))) { - flags = RXf_HASH_ALL; + flags = RXapif_ALL; } else { - flags = RXf_HASH_ONE; + flags = RXapif_ONE; } - ret = CALLREG_NAMED_BUFF_FETCH(rx, ST(0), (flags | RXf_HASH_REGNAME)); + ret = CALLREG_NAMED_BUFF_FETCH(rx, ST(0), (flags | RXapif_REGNAME)); if (ret) { if (SvROK(ret)) @@ -1157,14 +1157,14 @@ XS(XS_re_regnames) XSRETURN_UNDEF; if (items == 1 && SvTRUE(ST(0))) { - flags = RXf_HASH_ALL; + flags = RXapif_ALL; } else { - flags = RXf_HASH_ONE; + flags = RXapif_ONE; } SP -= items; - ret = CALLREG_NAMED_BUFF_ALL(rx, (flags | RXf_HASH_REGNAMES)); + ret = CALLREG_NAMED_BUFF_ALL(rx, (flags | RXapif_REGNAMES)); SPAGAIN; @@ -1427,8 +1427,8 @@ XS(XS_Tie_Hash_NamedCapture_flags) if (items != 0) Perl_croak(aTHX_ "Usage: Tie::Hash::NamedCapture::flags()"); - XPUSHs(sv_2mortal(newSVuv(RXf_HASH_ONE))); - XPUSHs(sv_2mortal(newSVuv(RXf_HASH_ALL))); + XPUSHs(sv_2mortal(newSVuv(RXapif_ONE))); + XPUSHs(sv_2mortal(newSVuv(RXapif_ALL))); PUTBACK; return; }