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
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
8#ifndef PERL_FEATURE_H_
9#define PERL_FEATURE_H_
10
11#if defined(PERL_CORE) || defined (PERL_EXT)
12
13#define HINT_FEATURE_SHIFT 26
14
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
30#define FEATURE_TRY_BIT 0x8000
31#define FEATURE_UNIEVAL_BIT 0x10000
32#define FEATURE_UNICODE_BIT 0x20000
33
34#define FEATURE_BUNDLE_DEFAULT 0
35#define FEATURE_BUNDLE_510 1
36#define FEATURE_BUNDLE_511 2
37#define FEATURE_BUNDLE_515 3
38#define FEATURE_BUNDLE_523 4
39#define FEATURE_BUNDLE_527 5
40#define FEATURE_BUNDLE_CUSTOM (HINT_FEATURE_MASK >> HINT_FEATURE_SHIFT)
41
42#define CURRENT_HINTS \
43 (PL_curcop == &PL_compiling ? PL_hints : PL_curcop->cop_hints)
44#define CURRENT_FEATURE_BUNDLE \
45 ((CURRENT_HINTS & HINT_FEATURE_MASK) >> HINT_FEATURE_SHIFT)
46
47#define FEATURE_IS_ENABLED_MASK(mask) \
48 ((CURRENT_HINTS & HINT_LOCALIZE_HH) \
49 ? (PL_curcop->cop_features & (mask)) : FALSE)
50
51/* The longest string we pass in. */
52#define MAX_FEATURE_LEN (sizeof("bareword_filehandles")-1)
53
54#define FEATURE_FC_IS_ENABLED \
55 ( \
56 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
57 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
58 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
59 FEATURE_IS_ENABLED_MASK(FEATURE_FC_BIT)) \
60 )
61
62#define FEATURE_ISA_IS_ENABLED \
63 ( \
64 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
65 FEATURE_IS_ENABLED_MASK(FEATURE_ISA_BIT) \
66 )
67
68#define FEATURE_SAY_IS_ENABLED \
69 ( \
70 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
71 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
72 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
73 FEATURE_IS_ENABLED_MASK(FEATURE_SAY_BIT)) \
74 )
75
76#define FEATURE_TRY_IS_ENABLED \
77 ( \
78 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
79 FEATURE_IS_ENABLED_MASK(FEATURE_TRY_BIT) \
80 )
81
82#define FEATURE_STATE_IS_ENABLED \
83 ( \
84 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
85 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
86 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
87 FEATURE_IS_ENABLED_MASK(FEATURE_STATE_BIT)) \
88 )
89
90#define FEATURE_SWITCH_IS_ENABLED \
91 ( \
92 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_510 && \
93 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
94 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
95 FEATURE_IS_ENABLED_MASK(FEATURE_SWITCH_BIT)) \
96 )
97
98#define FEATURE_BITWISE_IS_ENABLED \
99 ( \
100 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_527 \
101 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
102 FEATURE_IS_ENABLED_MASK(FEATURE_BITWISE_BIT)) \
103 )
104
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
112#define FEATURE_EVALBYTES_IS_ENABLED \
113 ( \
114 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
115 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
116 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
117 FEATURE_IS_ENABLED_MASK(FEATURE_EVALBYTES_BIT)) \
118 )
119
120#define FEATURE_SIGNATURES_IS_ENABLED \
121 ( \
122 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
123 FEATURE_IS_ENABLED_MASK(FEATURE_SIGNATURES_BIT) \
124 )
125
126#define FEATURE___SUB___IS_ENABLED \
127 ( \
128 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
129 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
130 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
131 FEATURE_IS_ENABLED_MASK(FEATURE___SUB___BIT)) \
132 )
133
134#define FEATURE_REFALIASING_IS_ENABLED \
135 ( \
136 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
137 FEATURE_IS_ENABLED_MASK(FEATURE_REFALIASING_BIT) \
138 )
139
140#define FEATURE_POSTDEREF_QQ_IS_ENABLED \
141 ( \
142 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_523 && \
143 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
144 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
145 FEATURE_IS_ENABLED_MASK(FEATURE_POSTDEREF_QQ_BIT)) \
146 )
147
148#define FEATURE_UNIEVAL_IS_ENABLED \
149 ( \
150 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_515 && \
151 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
152 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
153 FEATURE_IS_ENABLED_MASK(FEATURE_UNIEVAL_BIT)) \
154 )
155
156#define FEATURE_MYREF_IS_ENABLED \
157 ( \
158 CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
159 FEATURE_IS_ENABLED_MASK(FEATURE_MYREF_BIT) \
160 )
161
162#define FEATURE_UNICODE_IS_ENABLED \
163 ( \
164 (CURRENT_FEATURE_BUNDLE >= FEATURE_BUNDLE_511 && \
165 CURRENT_FEATURE_BUNDLE <= FEATURE_BUNDLE_527) \
166 || (CURRENT_FEATURE_BUNDLE == FEATURE_BUNDLE_CUSTOM && \
167 FEATURE_IS_ENABLED_MASK(FEATURE_UNICODE_BIT)) \
168 )
169
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
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
184
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
198#endif /* PERL_CORE or PERL_EXT */
199
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 | (
207 (sv_setnv(comp_ver, 5.027),
208 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
209 ? FEATURE_BUNDLE_527 :
210 (sv_setnv(comp_ver, 5.023),
211 vcmp(ver, upg_version(comp_ver, FALSE)) >= 0)
212 ? FEATURE_BUNDLE_523 :
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;
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;
228}
229#endif /* PERL_IN_OP_C */
230
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':
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
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
282 case 'i':
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
289 && memcmp(subf+1, "sa", keylen - sizeof("feature_")) == 0) {
290 mask = FEATURE_ISA_BIT;
291 break;
292 }
293 return;
294
295 case 'm':
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
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
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
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
379#endif /* PERL_FEATURE_H_ */
380
381/* ex: set ro: */