This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Make some refcnt changes NN
[perl5.git] / feature.h
CommitLineData
f2c01b15
FC
1/* -*- buffer-read-only: t -*-
2 !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
3 This file is built by regen/feature.pl.
4 Any changes made here will be lost!
5 */
6
7
3dd7db29
JK
8#ifndef PERL_FEATURE_H_
9#define PERL_FEATURE_H_
10
f2c01b15
FC
11#if defined(PERL_CORE) || defined (PERL_EXT)
12
13#define HINT_FEATURE_SHIFT 26
14
9f601cf3
TC
15#define FEATURE_BITWISE_BIT 0x0001
16#define FEATURE___SUB___BIT 0x0002
17#define FEATURE_MYREF_BIT 0x0004
18#define FEATURE_EVALBYTES_BIT 0x0008
19#define FEATURE_FC_BIT 0x0010
20#define FEATURE_POSTDEREF_QQ_BIT 0x0020
21#define FEATURE_REFALIASING_BIT 0x0040
22#define FEATURE_SAY_BIT 0x0080
23#define FEATURE_SIGNATURES_BIT 0x0100
24#define FEATURE_STATE_BIT 0x0200
25#define FEATURE_SWITCH_BIT 0x0400
26#define FEATURE_UNIEVAL_BIT 0x0800
27#define FEATURE_UNICODE_BIT 0x1000
28
f2c01b15
FC
29#define FEATURE_BUNDLE_DEFAULT 0
30#define FEATURE_BUNDLE_510 1
31#define FEATURE_BUNDLE_511 2
32#define FEATURE_BUNDLE_515 3
2ad792cd 33#define FEATURE_BUNDLE_523 4
401d2aaa 34#define FEATURE_BUNDLE_527 5
2b9e0ab7 35#define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
f2c01b15 36
d1fd0100
FC
37#define CURRENT_HINTS \
38 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
035b6821
FC
39#define CURRENT_FEATURE_BUNDLE \
40 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
d1fd0100 41
9f601cf3
TC
42#define FEATURE_IS_ENABLED_MASK(mask) \
43 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
44 ? (PL_curcop->cop_features & (mask)) : FALSE)
45
7d058bc9 46/* The longest string we pass in. */
158becca 47#define MAX_FEATURE_LEN (sizeof("postderef_qq")-1)
7d058bc9 48
2a4315f8
BF
49#define FEATURE_FC_IS_ENABLED \
50 ( \
2ad792cd 51 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 52 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2a4315f8 53 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 54 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
2a4315f8
BF
55 )
56
03222170
FC
57#define FEATURE_SAY_IS_ENABLED \
58 ( \
59 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 60 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 61 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 62 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
03222170
FC
63 )
64
65#define FEATURE_STATE_IS_ENABLED \
66 ( \
67 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 68 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 69 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 70 FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
03222170
FC
71 )
72
73#define FEATURE_SWITCH_IS_ENABLED \
74 ( \
75 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 76 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 77 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 78 FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
03222170
FC
79 )
80
cec892e7
FC
81#define FEATURE_BITWISE_IS_ENABLED \
82 ( \
401d2aaa
FC
83 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
84 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 85 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
cec892e7
FC
86 )
87
03222170
FC
88#define FEATURE_EVALBYTES_IS_ENABLED \
89 ( \
2ad792cd 90 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 91 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 92 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 93 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
03222170
FC
94 )
95
30d9c59b
Z
96#define FEATURE_SIGNATURES_IS_ENABLED \
97 ( \
98 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 99 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
30d9c59b
Z
100 )
101
03222170
FC
102#define FEATURE___SUB___IS_ENABLED \
103 ( \
2ad792cd 104 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 105 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 106 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 107 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
03222170
FC
108 )
109
baabe3fb 110#define FEATURE_REFALIASING_IS_ENABLED \
7b1dc818
FC
111 ( \
112 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 113 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
7b1dc818
FC
114 )
115
158becca
FC
116#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
117 ( \
401d2aaa
FC
118 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
119 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2ad792cd 120 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 121 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
158becca
FC
122 )
123
03222170
FC
124#define FEATURE_UNIEVAL_IS_ENABLED \
125 ( \
2ad792cd 126 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 127 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 128 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 129 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
03222170
FC
130 )
131
82d83da3
FC
132#define FEATURE_MYREF_IS_ENABLED \
133 ( \
134 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 135 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
82d83da3
FC
136 )
137
03222170
FC
138#define FEATURE_UNICODE_IS_ENABLED \
139 ( \
140 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
401d2aaa 141 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 142 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 143 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
03222170
FC
144 )
145
146
9f601cf3
TC
147#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
148
149#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
150
151#define STOREFEATUREBITSHH(hh) \
152 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
153
154#define FETCHFEATUREBITSHH(hh) \
155 STMT_START { \
156 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \
157 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \
158 } STMT_END
159
f2c01b15
FC
160#endif /* PERL_CORE or PERL_EXT */
161
4160ddbd
FC
162#ifdef PERL_IN_OP_C
163PERL_STATIC_INLINE void
164S_enable_feature_bundle(pTHX_ SV *ver)
165{
166 SV *comp_ver = sv_newmortal();
167 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
168 | (
401d2aaa
FC
169 (sv_setnv(comp_ver, 5.027),
170 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
171 ? FEATURE_BUNDLE_527 :
2ad792cd
AC
172 (sv_setnv(comp_ver, 5.023),
173 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
174 ? FEATURE_BUNDLE_523 :
4160ddbd
FC
175 (sv_setnv(comp_ver, 5.015),
176 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
177 ? FEATURE_BUNDLE_515 :
178 (sv_setnv(comp_ver, 5.011),
179 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
180 ? FEATURE_BUNDLE_511 :
181 (sv_setnv(comp_ver, 5.009005),
182 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
183 ? FEATURE_BUNDLE_510 :
184 FEATURE_BUNDLE_DEFAULT
185 ) << HINT_FEATURE_SHIFT;
6389c777
FC
186 /* special case */
187 assert(PL_curcop == &PL_compiling);
188 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
189 else PL_hints &= ~HINT_UNI_8_BIT;
4160ddbd
FC
190}
191#endif /* PERL_IN_OP_C */
192
b34c1a7e
TC
193#ifdef PERL_IN_MG_C
194
195#define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \
196 S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool))
197PERL_STATIC_INLINE void
198S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
199 SV *valsv, bool valbool) {
200 if (keysv)
201 keypv = SvPV_const(keysv, keylen);
202
203 if (memBEGINs(keypv, keylen, "feature_")) {
204 const char *subf = keypv + (sizeof("feature_")-1);
205 U32 mask = 0;
206 switch (*subf) {
207 case '_':
208 if (keylen == sizeof("feature___SUB__")-1
209 && memcmp(subf+1, "_SUB__", keylen - sizeof("feature_")) == 0) {
210 mask = FEATURE___SUB___BIT;
211 break;
212 }
213 return;
214
215 case 'b':
216 if (keylen == sizeof("feature_bitwise")-1
217 && memcmp(subf+1, "itwise", keylen - sizeof("feature_")) == 0) {
218 mask = FEATURE_BITWISE_BIT;
219 break;
220 }
221 return;
222
223 case 'e':
224 if (keylen == sizeof("feature_evalbytes")-1
225 && memcmp(subf+1, "valbytes", keylen - sizeof("feature_")) == 0) {
226 mask = FEATURE_EVALBYTES_BIT;
227 break;
228 }
229 return;
230
231 case 'f':
232 if (keylen == sizeof("feature_fc")-1
233 && memcmp(subf+1, "c", keylen - sizeof("feature_")) == 0) {
234 mask = FEATURE_FC_BIT;
235 break;
236 }
237 return;
238
239 case 'm':
240 if (keylen == sizeof("feature_myref")-1
241 && memcmp(subf+1, "yref", keylen - sizeof("feature_")) == 0) {
242 mask = FEATURE_MYREF_BIT;
243 break;
244 }
245 return;
246
247 case 'p':
248 if (keylen == sizeof("feature_postderef_qq")-1
249 && memcmp(subf+1, "ostderef_qq", keylen - sizeof("feature_")) == 0) {
250 mask = FEATURE_POSTDEREF_QQ_BIT;
251 break;
252 }
253 return;
254
255 case 'r':
256 if (keylen == sizeof("feature_refaliasing")-1
257 && memcmp(subf+1, "efaliasing", keylen - sizeof("feature_")) == 0) {
258 mask = FEATURE_REFALIASING_BIT;
259 break;
260 }
261 return;
262
263 case 's':
264 if (keylen == sizeof("feature_say")-1
265 && memcmp(subf+1, "ay", keylen - sizeof("feature_")) == 0) {
266 mask = FEATURE_SAY_BIT;
267 break;
268 }
269 else if (keylen == sizeof("feature_signatures")-1
270 && memcmp(subf+1, "ignatures", keylen - sizeof("feature_")) == 0) {
271 mask = FEATURE_SIGNATURES_BIT;
272 break;
273 }
274 else if (keylen == sizeof("feature_state")-1
275 && memcmp(subf+1, "tate", keylen - sizeof("feature_")) == 0) {
276 mask = FEATURE_STATE_BIT;
277 break;
278 }
279 else if (keylen == sizeof("feature_switch")-1
280 && memcmp(subf+1, "witch", keylen - sizeof("feature_")) == 0) {
281 mask = FEATURE_SWITCH_BIT;
282 break;
283 }
284 return;
285
286 case 'u':
287 if (keylen == sizeof("feature_unicode")-1
288 && memcmp(subf+1, "nicode", keylen - sizeof("feature_")) == 0) {
289 mask = FEATURE_UNICODE_BIT;
290 break;
291 }
292 else if (keylen == sizeof("feature_unieval")-1
293 && memcmp(subf+1, "nieval", keylen - sizeof("feature_")) == 0) {
294 mask = FEATURE_UNIEVAL_BIT;
295 break;
296 }
297 return;
298
299 default:
300 return;
301 }
302 if (valsv ? SvTRUE(valsv) : valbool)
303 PL_compiling.cop_features |= mask;
304 else
305 PL_compiling.cop_features &= ~mask;
306 }
307}
308#endif /* PERL_IN_MG_C */
309
3dd7db29
JK
310#endif /* PERL_FEATURE_H_ */
311
f2c01b15 312/* ex: set ro: */