Mercurial > repo
comparison perl-5.22.2/op_reg_common.h @ 8045:a16537d2fe07
<xfix> tar xf perl-5.22.2.tar.gz # Ah, whatever, I\'m doing it anyway
author | HackBot |
---|---|
date | Sat, 14 May 2016 14:54:38 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
8044:711c038a7dce | 8045:a16537d2fe07 |
---|---|
1 /* op_reg_common.h | |
2 * | |
3 * Definitions common to by op.h and regexp.h | |
4 * | |
5 * Copyright (C) 2010, 2011 by Larry Wall and others | |
6 * | |
7 * You may distribute under the terms of either the GNU General Public | |
8 * License or the Artistic License, as specified in the README file. | |
9 * | |
10 */ | |
11 | |
12 /* These defines are used in both op.h and regexp.h The definitions use the | |
13 * shift form so that ext/B/Makefile.PL will pick them up. | |
14 * | |
15 * Data structures used in the two headers have common fields, and in fact one | |
16 * is copied onto the other. This makes it easy to keep them in sync */ | |
17 | |
18 /* This tells where the first of these bits is. Setting it to 0 saved cycles | |
19 * and memory. I (khw) think the code will work if changed back, but haven't | |
20 * tested it */ | |
21 /* Make sure to update ext/re/re.pm when changing this! */ | |
22 #ifndef RXf_PMf_STD_PMMOD_SHIFT /* Only expand #include of this file once */ | |
23 | |
24 #define RXf_PMf_STD_PMMOD_SHIFT 0 | |
25 | |
26 /* The bits need to be ordered so that the msixn are contiguous starting at bit | |
27 * RXf_PMf_STD_PMMOD_SHIFT, followed by the p. See STD_PAT_MODS and | |
28 * INT_PAT_MODS in regexp.h for the reason contiguity is needed */ | |
29 /* Make sure to update lib/re.pm when changing these! */ | |
30 /* Make sure you keep the pure PMf_ versions below in sync */ | |
31 #define RXf_PMf_MULTILINE (1U << (RXf_PMf_STD_PMMOD_SHIFT+0)) /* /m */ | |
32 #define RXf_PMf_SINGLELINE (1U << (RXf_PMf_STD_PMMOD_SHIFT+1)) /* /s */ | |
33 #define RXf_PMf_FOLD (1U << (RXf_PMf_STD_PMMOD_SHIFT+2)) /* /i */ | |
34 #define RXf_PMf_EXTENDED (1U << (RXf_PMf_STD_PMMOD_SHIFT+3)) /* /x */ | |
35 #define RXf_PMf_EXTENDED_MORE (1U << (RXf_PMf_STD_PMMOD_SHIFT+4)) /* /xx */ | |
36 #define RXf_PMf_NOCAPTURE (1U << (RXf_PMf_STD_PMMOD_SHIFT+5)) /* /n */ | |
37 | |
38 #define RXf_PMf_KEEPCOPY (1U << (RXf_PMf_STD_PMMOD_SHIFT+6)) /* /p */ | |
39 | |
40 /* The character set for the regex is stored in a field of more than one bit | |
41 * using an enum, for reasons of compactness and to ensure that the options are | |
42 * mutually exclusive */ | |
43 /* Make sure to update ext/re/re.pm and regcomp.sym (as these are used as | |
44 * offsets for various node types, like POSIXD vs POSIXL, etc) when changing | |
45 * this! */ | |
46 typedef enum { | |
47 REGEX_DEPENDS_CHARSET = 0, | |
48 REGEX_LOCALE_CHARSET, | |
49 REGEX_UNICODE_CHARSET, | |
50 REGEX_ASCII_RESTRICTED_CHARSET, | |
51 REGEX_ASCII_MORE_RESTRICTED_CHARSET | |
52 } regex_charset; | |
53 | |
54 #define _RXf_PMf_CHARSET_SHIFT ((RXf_PMf_STD_PMMOD_SHIFT)+7) | |
55 #define RXf_PMf_CHARSET (7U << (_RXf_PMf_CHARSET_SHIFT)) /* 3 bits */ | |
56 | |
57 /* Manually decorate these functions here with gcc-style attributes just to | |
58 * avoid making the regex_charset typedef global, which it would need to be for | |
59 * proto.h to understand it */ | |
60 PERL_STATIC_INLINE void | |
61 set_regex_charset(U32 * const flags, const regex_charset cs) | |
62 __attribute__nonnull__(1); | |
63 | |
64 PERL_STATIC_INLINE void | |
65 set_regex_charset(U32 * const flags, const regex_charset cs) | |
66 { | |
67 /* Sets the character set portion of 'flags' to 'cs', which is a member of | |
68 * the above enum */ | |
69 | |
70 *flags &= ~RXf_PMf_CHARSET; | |
71 *flags |= (cs << _RXf_PMf_CHARSET_SHIFT); | |
72 } | |
73 | |
74 PERL_STATIC_INLINE regex_charset | |
75 get_regex_charset(const U32 flags) | |
76 __attribute__warn_unused_result__; | |
77 | |
78 PERL_STATIC_INLINE regex_charset | |
79 get_regex_charset(const U32 flags) | |
80 { | |
81 /* Returns the enum corresponding to the character set in 'flags' */ | |
82 | |
83 return (regex_charset) ((flags & RXf_PMf_CHARSET) >> _RXf_PMf_CHARSET_SHIFT); | |
84 } | |
85 | |
86 #define RXf_PMf_STRICT (1U<<(RXf_PMf_STD_PMMOD_SHIFT+10)) | |
87 | |
88 #define _RXf_PMf_SHIFT_COMPILETIME (RXf_PMf_STD_PMMOD_SHIFT+11) | |
89 | |
90 | |
91 /* | |
92 Set in Perl_pmruntime if op_flags & OPf_SPECIAL, i.e. split. Will | |
93 be used by regex engines to check whether they should set | |
94 RXf_SKIPWHITE | |
95 */ | |
96 #define RXf_PMf_SPLIT (1U<<(RXf_PMf_STD_PMMOD_SHIFT+11)) | |
97 | |
98 /* Next available bit after the above. Name begins with '_' so won't be | |
99 * exported by B */ | |
100 #define _RXf_PMf_SHIFT_NEXT (RXf_PMf_STD_PMMOD_SHIFT+12) | |
101 | |
102 /* Mask of the above bits. These need to be transferred from op_pmflags to | |
103 * re->extflags during compilation */ | |
104 #define RXf_PMf_COMPILETIME (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_FOLD|RXf_PMf_EXTENDED|RXf_PMf_EXTENDED_MORE|RXf_PMf_KEEPCOPY|RXf_PMf_NOCAPTURE|RXf_PMf_CHARSET|RXf_PMf_STRICT) | |
105 #define RXf_PMf_FLAGCOPYMASK (RXf_PMf_COMPILETIME|RXf_PMf_SPLIT) | |
106 | |
107 #if 0 /* Temporary to get Jenkins happy again */ | |
108 See thread starting at http://nntp.perl.org/group/perl.perl5.porters/220710 | |
109 /* Exclude win32 because it can't cope with I32_MAX definition */ | |
110 #ifndef WIN32 | |
111 # if RXf_PMf_COMPILETIME > I32_MAX | |
112 # error RXf_PMf_COMPILETIME wont fit in arg2 field of eval node | |
113 # endif | |
114 #endif | |
115 #endif | |
116 | |
117 /* These copies need to be numerical or ext/B/Makefile.PL won't think they are | |
118 * constants */ | |
119 #define PMf_MULTILINE (1U<<0) | |
120 #define PMf_SINGLELINE (1U<<1) | |
121 #define PMf_FOLD (1U<<2) | |
122 #define PMf_EXTENDED (1U<<3) | |
123 #define PMf_EXTENDED_MORE (1U<<4) | |
124 #define PMf_NOCAPTURE (1U<<5) | |
125 #define PMf_KEEPCOPY (1U<<6) | |
126 #define PMf_CHARSET (7U<<7) | |
127 #define PMf_STRICT (1U<<10) | |
128 #define PMf_SPLIT (1U<<11) | |
129 | |
130 #if PMf_MULTILINE != RXf_PMf_MULTILINE || PMf_SINGLELINE != RXf_PMf_SINGLELINE || PMf_FOLD != RXf_PMf_FOLD || PMf_EXTENDED != RXf_PMf_EXTENDED || PMf_EXTENDED_MORE != RXf_PMf_EXTENDED_MORE || PMf_KEEPCOPY != RXf_PMf_KEEPCOPY || PMf_SPLIT != RXf_PMf_SPLIT || PMf_CHARSET != RXf_PMf_CHARSET || PMf_NOCAPTURE != RXf_PMf_NOCAPTURE || PMf_STRICT != RXf_PMf_STRICT | |
131 # error RXf_PMf defines are wrong | |
132 #endif | |
133 | |
134 /* Error check that haven't left something out of this. This isn't done | |
135 * directly in the #define because doing so confuses regcomp.pl. | |
136 * (2**n - 1) is n 1 bits, so the below gets the contiguous bits between the | |
137 * beginning and ending shifts */ | |
138 #if RXf_PMf_COMPILETIME != (((1 << (_RXf_PMf_SHIFT_COMPILETIME))-1) \ | |
139 & (~((1 << RXf_PMf_STD_PMMOD_SHIFT)-1))) | |
140 # error RXf_PMf_COMPILETIME is invalid | |
141 #endif | |
142 | |
143 #endif /* Include only once */ |