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