This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perl5337delta: note that stadtx was removed
[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
0f2beabb
TC
15#define FEATURE_BAREWORD_FILEHANDLES_BIT 0x0001
16#define FEATURE_BITWISE_BIT 0x0002
17#define FEATURE___SUB___BIT 0x0004
18#define FEATURE_MYREF_BIT 0x0008
19#define FEATURE_EVALBYTES_BIT 0x0010
20#define FEATURE_FC_BIT 0x0020
21#define FEATURE_INDIRECT_BIT 0x0040
22#define FEATURE_ISA_BIT 0x0080
23#define FEATURE_MULTIDIMENSIONAL_BIT 0x0100
24#define FEATURE_POSTDEREF_QQ_BIT 0x0200
25#define FEATURE_REFALIASING_BIT 0x0400
26#define FEATURE_SAY_BIT 0x0800
27#define FEATURE_SIGNATURES_BIT 0x1000
28#define FEATURE_STATE_BIT 0x2000
29#define FEATURE_SWITCH_BIT 0x4000
a1325b90
PLE
30#define FEATURE_TRY_BIT 0x8000
31#define FEATURE_UNIEVAL_BIT 0x10000
32#define FEATURE_UNICODE_BIT 0x20000
9f601cf3 33
f2c01b15
FC
34#define FEATURE_BUNDLE_DEFAULT 0
35#define FEATURE_BUNDLE_510 1
36#define FEATURE_BUNDLE_511 2
37#define FEATURE_BUNDLE_515 3
2ad792cd 38#define FEATURE_BUNDLE_523 4
401d2aaa 39#define FEATURE_BUNDLE_527 5
2b9e0ab7 40#define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
f2c01b15 41
d1fd0100
FC
42#define CURRENT_HINTS \
43 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
035b6821
FC
44#define CURRENT_FEATURE_BUNDLE \
45 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
d1fd0100 46
9f601cf3
TC
47#define FEATURE_IS_ENABLED_MASK(mask) \
48 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
49 ? (PL_curcop->cop_features & (mask)) : FALSE)
50
7d058bc9 51/* The longest string we pass in. */
0f2beabb 52#define MAX_FEATURE_LEN (sizeof("bareword_filehandles")-1)
7d058bc9 53
2a4315f8
BF
54#define FEATURE_FC_IS_ENABLED \
55 ( \
2ad792cd 56 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 57 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2a4315f8 58 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 59 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
2a4315f8
BF
60 )
61
813e85a0
PLE
62#define FEATURE_ISA_IS_ENABLED \
63 ( \
64 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
65 FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
66 )
67
03222170
FC
68#define FEATURE_SAY_IS_ENABLED \
69 ( \
70 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 71 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 72 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 73 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
03222170
FC
74 )
75
a1325b90
PLE
76#define FEATURE_TRY_IS_ENABLED \
77 ( \
78 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
79 FEATURE_IS_ENABLED_MASK(FEATURE_TRY_BIT) \
80 )
81
03222170
FC
82#define FEATURE_STATE_IS_ENABLED \
83 ( \
84 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 85 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 86 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 87 FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
03222170
FC
88 )
89
90#define FEATURE_SWITCH_IS_ENABLED \
91 ( \
92 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
401d2aaa 93 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 94 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 95 FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
03222170
FC
96 )
97
cec892e7
FC
98#define FEATURE_BITWISE_IS_ENABLED \
99 ( \
401d2aaa
FC
100 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
101 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 102 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
cec892e7
FC
103 )
104
0b657b19
DIM
105#define FEATURE_INDIRECT_IS_ENABLED \
106 ( \
107 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527 \
108 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
109 FEATURE_IS_ENABLED_MASK(FEATURE_INDIRECT_BIT)) \
110 )
111
03222170
FC
112#define FEATURE_EVALBYTES_IS_ENABLED \
113 ( \
2ad792cd 114 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 115 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 116 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 117 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
03222170
FC
118 )
119
30d9c59b
Z
120#define FEATURE_SIGNATURES_IS_ENABLED \
121 ( \
122 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 123 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
30d9c59b
Z
124 )
125
03222170
FC
126#define FEATURE___SUB___IS_ENABLED \
127 ( \
2ad792cd 128 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 129 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 130 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 131 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
03222170
FC
132 )
133
baabe3fb 134#define FEATURE_REFALIASING_IS_ENABLED \
7b1dc818
FC
135 ( \
136 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 137 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
7b1dc818
FC
138 )
139
158becca
FC
140#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
141 ( \
401d2aaa
FC
142 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
143 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
2ad792cd 144 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 145 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
158becca
FC
146 )
147
03222170
FC
148#define FEATURE_UNIEVAL_IS_ENABLED \
149 ( \
2ad792cd 150 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
401d2aaa 151 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 152 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 153 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
03222170
FC
154 )
155
82d83da3
FC
156#define FEATURE_MYREF_IS_ENABLED \
157 ( \
158 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 159 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
82d83da3
FC
160 )
161
03222170
FC
162#define FEATURE_UNICODE_IS_ENABLED \
163 ( \
164 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
401d2aaa 165 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
03222170 166 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
9f601cf3 167 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
03222170
FC
168 )
169
1ad5a39c
TC
170#define FEATURE_MULTIDIMENSIONAL_IS_ENABLED \
171 ( \
172 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527 \
173 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
174 FEATURE_IS_ENABLED_MASK(FEATURE_MULTIDIMENSIONAL_BIT)) \
175 )
176
0f2beabb
TC
177#define FEATURE_BAREWORD_FILEHANDLES_IS_ENABLED \
178 ( \
179 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527 \
180 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
181 FEATURE_IS_ENABLED_MASK(FEATURE_BAREWORD_FILEHANDLES_BIT)) \
182 )
183
03222170 184
9f601cf3
TC
185#define SAVEFEATUREBITS() SAVEI32(PL_compiling.cop_features)
186
187#define CLEARFEATUREBITS() (PL_compiling.cop_features = 0)
188
189#define STOREFEATUREBITSHH(hh) \
190 (hv_stores((hh), "feature/bits", newSVuv(PL_compiling.cop_features)))
191
192#define FETCHFEATUREBITSHH(hh) \
193 STMT_START { \
194 SV **fbsv = hv_fetchs((hh), "feature/bits", FALSE); \
195 PL_compiling.cop_features = fbsv ? SvUV(*fbsv) : 0; \
196 } STMT_END
197
f2c01b15
FC
198#endif /* PERL_CORE or PERL_EXT */
199
4160ddbd
FC
200#ifdef PERL_IN_OP_C
201PERL_STATIC_INLINE void
202S_enable_feature_bundle(pTHX_ SV *ver)
203{
204 SV *comp_ver = sv_newmortal();
205 PL_hints = (PL_hints &~ HINT_FEATURE_MASK)
206 | (
401d2aaa
FC
207 (sv_setnv(comp_ver, 5.027),
208 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
209 ? FEATURE_BUNDLE_527 :
2ad792cd
AC
210 (sv_setnv(comp_ver, 5.023),
211 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
212 ? FEATURE_BUNDLE_523 :
4160ddbd
FC
213 (sv_setnv(comp_ver, 5.015),
214 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
215 ? FEATURE_BUNDLE_515 :
216 (sv_setnv(comp_ver, 5.011),
217 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
218 ? FEATURE_BUNDLE_511 :
219 (sv_setnv(comp_ver, 5.009005),
220 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
221 ? FEATURE_BUNDLE_510 :
222 FEATURE_BUNDLE_DEFAULT
223 ) << HINT_FEATURE_SHIFT;
6389c777
FC
224 /* special case */
225 assert(PL_curcop == &PL_compiling);
226 if (FEATURE_UNICODE_IS_ENABLED) PL_hints |= HINT_UNI_8_BIT;
227 else PL_hints &= ~HINT_UNI_8_BIT;
4160ddbd
FC
228}
229#endif /* PERL_IN_OP_C */
230
b34c1a7e
TC
231#ifdef PERL_IN_MG_C
232
233#define magic_sethint_feature(keysv, keypv, keylen, valsv, valbool) \
234 S_magic_sethint_feature(aTHX_ (keysv), (keypv), (keylen), (valsv), (valbool))
235PERL_STATIC_INLINE void
236S_magic_sethint_feature(pTHX_ SV *keysv, const char *keypv, STRLEN keylen,
237 SV *valsv, bool valbool) {
238 if (keysv)
239 keypv = SvPV_const(keysv, keylen);
240
241 if (memBEGINs(keypv, keylen, "feature_")) {
242 const char *subf = keypv + (sizeof("feature_")-1);
243 U32 mask = 0;
244 switch (*subf) {
245 case '_':
246 if (keylen == sizeof("feature___SUB__")-1
247 && memcmp(subf+1, "_SUB__", keylen - sizeof("feature_")) == 0) {
248 mask = FEATURE___SUB___BIT;
249 break;
250 }
251 return;
252
253 case 'b':
0f2beabb
TC
254 if (keylen == sizeof("feature_bareword_filehandles")-1
255 && memcmp(subf+1, "areword_filehandles", keylen - sizeof("feature_")) == 0) {
256 mask = FEATURE_BAREWORD_FILEHANDLES_BIT;
257 break;
258 }
259 else if (keylen == sizeof("feature_bitwise")-1
b34c1a7e
TC
260 && memcmp(subf+1, "itwise", keylen - sizeof("feature_")) == 0) {
261 mask = FEATURE_BITWISE_BIT;
262 break;
263 }
264 return;
265
266 case 'e':
267 if (keylen == sizeof("feature_evalbytes")-1
268 && memcmp(subf+1, "valbytes", keylen - sizeof("feature_")) == 0) {
269 mask = FEATURE_EVALBYTES_BIT;
270 break;
271 }
272 return;
273
274 case 'f':
275 if (keylen == sizeof("feature_fc")-1
276 && memcmp(subf+1, "c", keylen - sizeof("feature_")) == 0) {
277 mask = FEATURE_FC_BIT;
278 break;
279 }
280 return;
281
813e85a0 282 case 'i':
0b657b19
DIM
283 if (keylen == sizeof("feature_indirect")-1
284 && memcmp(subf+1, "ndirect", keylen - sizeof("feature_")) == 0) {
285 mask = FEATURE_INDIRECT_BIT;
286 break;
287 }
288 else if (keylen == sizeof("feature_isa")-1
813e85a0
PLE
289 && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
290 mask = FEATURE_ISA_BIT;
291 break;
292 }
293 return;
294
b34c1a7e 295 case 'm':
1ad5a39c
TC
296 if (keylen == sizeof("feature_multidimensional")-1
297 && memcmp(subf+1, "ultidimensional", keylen - sizeof("feature_")) == 0) {
298 mask = FEATURE_MULTIDIMENSIONAL_BIT;
299 break;
300 }
301 else if (keylen == sizeof("feature_myref")-1
b34c1a7e
TC
302 && memcmp(subf+1, "yref", keylen - sizeof("feature_")) == 0) {
303 mask = FEATURE_MYREF_BIT;
304 break;
305 }
306 return;
307
308 case 'p':
309 if (keylen == sizeof("feature_postderef_qq")-1
310 && memcmp(subf+1, "ostderef_qq", keylen - sizeof("feature_")) == 0) {
311 mask = FEATURE_POSTDEREF_QQ_BIT;
312 break;
313 }
314 return;
315
316 case 'r':
317 if (keylen == sizeof("feature_refaliasing")-1
318 && memcmp(subf+1, "efaliasing", keylen - sizeof("feature_")) == 0) {
319 mask = FEATURE_REFALIASING_BIT;
320 break;
321 }
322 return;
323
324 case 's':
325 if (keylen == sizeof("feature_say")-1
326 && memcmp(subf+1, "ay", keylen - sizeof("feature_")) == 0) {
327 mask = FEATURE_SAY_BIT;
328 break;
329 }
330 else if (keylen == sizeof("feature_signatures")-1
331 && memcmp(subf+1, "ignatures", keylen - sizeof("feature_")) == 0) {
332 mask = FEATURE_SIGNATURES_BIT;
333 break;
334 }
335 else if (keylen == sizeof("feature_state")-1
336 && memcmp(subf+1, "tate", keylen - sizeof("feature_")) == 0) {
337 mask = FEATURE_STATE_BIT;
338 break;
339 }
340 else if (keylen == sizeof("feature_switch")-1
341 && memcmp(subf+1, "witch", keylen - sizeof("feature_")) == 0) {
342 mask = FEATURE_SWITCH_BIT;
343 break;
344 }
345 return;
346
a1325b90
PLE
347 case 't':
348 if (keylen == sizeof("feature_try")-1
349 && memcmp(subf+1, "ry", keylen - sizeof("feature_")) == 0) {
350 mask = FEATURE_TRY_BIT;
351 break;
352 }
353 return;
354
b34c1a7e
TC
355 case 'u':
356 if (keylen == sizeof("feature_unicode")-1
357 && memcmp(subf+1, "nicode", keylen - sizeof("feature_")) == 0) {
358 mask = FEATURE_UNICODE_BIT;
359 break;
360 }
361 else if (keylen == sizeof("feature_unieval")-1
362 && memcmp(subf+1, "nieval", keylen - sizeof("feature_")) == 0) {
363 mask = FEATURE_UNIEVAL_BIT;
364 break;
365 }
366 return;
367
368 default:
369 return;
370 }
371 if (valsv ? SvTRUE(valsv) : valbool)
372 PL_compiling.cop_features |= mask;
373 else
374 PL_compiling.cop_features &= ~mask;
375 }
376}
377#endif /* PERL_IN_MG_C */
378
3dd7db29
JK
379#endif /* PERL_FEATURE_H_ */
380
f2c01b15 381/* ex: set ro: */