blob: 4279ff0a5ca4e422a8a6f0bf7b1af19a20938325 [file] [log] [blame]
Rashed Abdel-Tawab4db47f42019-09-06 10:38:22 -07001# -*- 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
6package feature;
7
8our $VERSION = '1.47';
9
10our %feature = (
11 fc => 'feature_fc',
12 say => 'feature_say',
13 state => 'feature_state',
14 switch => 'feature_switch',
15 bitwise => 'feature_bitwise',
16 evalbytes => 'feature_evalbytes',
17 array_base => 'feature_arybase',
18 signatures => 'feature_signatures',
19 current_sub => 'feature___SUB__',
20 refaliasing => 'feature_refaliasing',
21 postderef_qq => 'feature_postderef_qq',
22 unicode_eval => 'feature_unieval',
23 declared_refs => 'feature_myref',
24 unicode_strings => 'feature_unicode',
25);
26
27our %feature_bundle = (
28 "5.10" => [qw(array_base say state switch)],
29 "5.11" => [qw(array_base say state switch unicode_strings)],
30 "5.15" => [qw(current_sub evalbytes fc say state switch unicode_eval unicode_strings)],
31 "5.23" => [qw(current_sub evalbytes fc postderef_qq say state switch unicode_eval unicode_strings)],
32 "all" => [qw(array_base bitwise current_sub declared_refs evalbytes fc postderef_qq refaliasing say signatures state switch unicode_eval unicode_strings)],
33 "default" => [qw(array_base)],
34);
35
36$feature_bundle{"5.12"} = $feature_bundle{"5.11"};
37$feature_bundle{"5.13"} = $feature_bundle{"5.11"};
38$feature_bundle{"5.14"} = $feature_bundle{"5.11"};
39$feature_bundle{"5.16"} = $feature_bundle{"5.15"};
40$feature_bundle{"5.17"} = $feature_bundle{"5.15"};
41$feature_bundle{"5.18"} = $feature_bundle{"5.15"};
42$feature_bundle{"5.19"} = $feature_bundle{"5.15"};
43$feature_bundle{"5.20"} = $feature_bundle{"5.15"};
44$feature_bundle{"5.21"} = $feature_bundle{"5.15"};
45$feature_bundle{"5.22"} = $feature_bundle{"5.15"};
46$feature_bundle{"5.24"} = $feature_bundle{"5.23"};
47$feature_bundle{"5.25"} = $feature_bundle{"5.23"};
48$feature_bundle{"5.26"} = $feature_bundle{"5.23"};
49$feature_bundle{"5.9.5"} = $feature_bundle{"5.10"};
50my %noops = (
51 postderef => 1,
52 lexical_subs => 1,
53);
54
55our $hint_shift = 26;
56our $hint_mask = 0x1c000000;
57our @hint_bundles = qw( default 5.10 5.11 5.15 5.23 );
58
59# This gets set (for now) in $^H as well as in %^H,
60# for runtime speed of the uc/lc/ucfirst/lcfirst functions.
61# See HINT_UNI_8_BIT in perl.h.
62our $hint_uni8bit = 0x00000800;
63
64# TODO:
65# - think about versioned features (use feature switch => 2)
66
67sub import {
68 shift;
69
70 if (!@_) {
71 croak("No features specified");
72 }
73
74 __common(1, @_);
75}
76
77sub unimport {
78 shift;
79
80 # A bare C<no feature> should reset to the default bundle
81 if (!@_) {
82 $^H &= ~($hint_uni8bit|$hint_mask);
83 return;
84 }
85
86 __common(0, @_);
87}
88
89sub __common {
90 my $import = shift;
91 my $bundle_number = $^H & $hint_mask;
92 my $features = $bundle_number != $hint_mask
93 && $feature_bundle{$hint_bundles[$bundle_number >> $hint_shift]};
94 if ($features) {
95 # Features are enabled implicitly via bundle hints.
96 # Delete any keys that may be left over from last time.
97 delete @^H{ values(%feature) };
98 $^H |= $hint_mask;
99 for (@$features) {
100 $^H{$feature{$_}} = 1;
101 $^H |= $hint_uni8bit if $_ eq 'unicode_strings';
102 }
103 }
104 while (@_) {
105 my $name = shift;
106 if (substr($name, 0, 1) eq ":") {
107 my $v = substr($name, 1);
108 if (!exists $feature_bundle{$v}) {
109 $v =~ s/^([0-9]+)\.([0-9]+).[0-9]+$/$1.$2/;
110 if (!exists $feature_bundle{$v}) {
111 unknown_feature_bundle(substr($name, 1));
112 }
113 }
114 unshift @_, @{$feature_bundle{$v}};
115 next;
116 }
117 if (!exists $feature{$name}) {
118 if (exists $noops{$name}) {
119 next;
120 }
121 unknown_feature($name);
122 }
123 if ($import) {
124 $^H{$feature{$name}} = 1;
125 $^H |= $hint_uni8bit if $name eq 'unicode_strings';
126 } else {
127 delete $^H{$feature{$name}};
128 $^H &= ~ $hint_uni8bit if $name eq 'unicode_strings';
129 }
130 }
131}
132
133sub unknown_feature {
134 my $feature = shift;
135 croak(sprintf('Feature "%s" is not supported by Perl %vd',
136 $feature, $^V));
137}
138
139sub unknown_feature_bundle {
140 my $feature = shift;
141 croak(sprintf('Feature bundle "%s" is not supported by Perl %vd',
142 $feature, $^V));
143}
144
145sub croak {
146 require Carp;
147 Carp::croak(@_);
148}
149
1501;
151
152# ex: set ro: