Commit | Line | Data |
---|---|---|
bab3dc31 | 1 | #!/usr/bin/perl -w |
bab3dc31 | 2 | # |
8bc7f08e | 3 | # Regenerate (overwriting only if changed): |
6294c161 DM |
4 | # |
5 | # overload.h | |
6 | # overload.c | |
7 | # lib/overload/numbers.pm | |
8 | # | |
9 | # from information stored in the DATA section of this file. | |
10 | # | |
8c798f87 | 11 | # This allows the order of overloading constants to be changed. |
6294c161 DM |
12 | # |
13 | # Accepts the standard regen_lib -q and -v args. | |
14 | # | |
15 | # This script is normally invoked from regen.pl. | |
bab3dc31 NC |
16 | |
17 | BEGIN { | |
18 | # Get function prototypes | |
19 | require 'regen_lib.pl'; | |
20 | } | |
21 | ||
22 | use strict; | |
23 | ||
24 | my (@enums, @names); | |
25 | while (<DATA>) { | |
26 | next if /^#/; | |
27 | next if /^$/; | |
28 | my ($enum, $name) = /^(\S+)\s+(\S+)/ or die "Can't parse $_"; | |
29 | push @enums, $enum; | |
30 | push @names, $name; | |
31 | } | |
32 | ||
916e4025 | 33 | safer_unlink ('lib/overload/numbers.pm'); |
81372052 JC |
34 | my $c = safer_open("overload.c-new"); |
35 | my $h = safer_open("overload.h-new"); | |
916e4025 NC |
36 | mkdir("lib/overload", 0777) unless -d 'lib/overload'; |
37 | my $p = safer_open('lib/overload/numbers.pm'); | |
e46c382e YK |
38 | |
39 | ||
40 | select $p; | |
41 | ||
42 | { | |
43 | local $" = "\n "; | |
44 | print <<"EOF"; | |
45 | # -*- buffer-read-only: t -*- | |
46 | # | |
47 | # lib/overload/numbers.pm | |
48 | # | |
49 | # Copyright (C) 2008 by Larry Wall and others | |
50 | # | |
51 | # You may distribute under the terms of either the GNU General Public | |
52 | # License or the Artistic License, as specified in the README file. | |
53 | # | |
54 | # !!!!!!! DO NOT EDIT THIS FILE !!!!!!! | |
55 | # This file is built by overload.pl | |
56 | # | |
57 | ||
58 | package overload::numbers; | |
59 | ||
60 | our \@names = qw# | |
61 | @names | |
62 | #; | |
63 | ||
64 | our \@enums = qw# | |
65 | @enums | |
66 | #; | |
67 | ||
d87d3eed | 68 | { my \$i = 0; our %names = map { \$_ => \$i++ } \@names } |
e46c382e | 69 | |
d87d3eed | 70 | { my \$i = 0; our %enums = map { \$_ => \$i++ } \@enums } |
e46c382e YK |
71 | |
72 | EOF | |
73 | } | |
74 | ||
8261f8eb NC |
75 | |
76 | sub print_header { | |
77 | my $file = shift; | |
78 | print <<"EOF"; | |
bab3dc31 NC |
79 | /* -*- buffer-read-only: t -*- |
80 | * | |
8261f8eb | 81 | * $file |
bab3dc31 | 82 | * |
38f14693 RGS |
83 | * Copyright (C) 1997, 1998, 2000, 2001, 2005, 2006, 2007 by Larry Wall |
84 | * and others | |
bab3dc31 NC |
85 | * |
86 | * You may distribute under the terms of either the GNU General Public | |
87 | * License or the Artistic License, as specified in the README file. | |
88 | * | |
89 | * !!!!!!! DO NOT EDIT THIS FILE !!!!!!! | |
90 | * This file is built by overload.pl | |
91 | */ | |
8261f8eb NC |
92 | EOF |
93 | } | |
94 | ||
08858ed2 | 95 | select $c; |
8261f8eb NC |
96 | print_header('overload.c'); |
97 | ||
08858ed2 | 98 | select $h; |
8261f8eb NC |
99 | print_header('overload.h'); |
100 | print <<'EOF'; | |
bab3dc31 NC |
101 | |
102 | enum { | |
103 | EOF | |
104 | ||
916e4025 | 105 | print map " ${_}_amg,\n", @enums; |
bab3dc31 NC |
106 | |
107 | print <<'EOF'; | |
108 | max_amg_code | |
109 | /* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */ | |
110 | }; | |
111 | ||
bab3dc31 | 112 | #define NofAMmeth max_amg_code |
8261f8eb NC |
113 | |
114 | EOF | |
115 | ||
08858ed2 | 116 | print $c <<'EOF'; |
8261f8eb | 117 | |
bab3dc31 | 118 | #define AMG_id2name(id) (PL_AMG_names[id]+1) |
82af6593 | 119 | #define AMG_id2namelen(id) (PL_AMG_namelens[id]-1) |
bab3dc31 | 120 | |
2e1c5ef0 | 121 | static const U8 PL_AMG_namelens[NofAMmeth] = { |
d279ab82 NC |
122 | EOF |
123 | ||
124 | my $last = pop @names; | |
125 | ||
916e4025 | 126 | print $c map { " " . (length $_) . ",\n" } @names; |
d279ab82 NC |
127 | |
128 | my $lastlen = length $last; | |
08858ed2 | 129 | print $c <<"EOT"; |
d279ab82 NC |
130 | $lastlen |
131 | }; | |
132 | ||
2e1c5ef0 | 133 | static const char * const PL_AMG_names[NofAMmeth] = { |
bab3dc31 NC |
134 | /* Names kept in the symbol table. fallback => "()", the rest has |
135 | "(" prepended. The only other place in perl which knows about | |
136 | this convention is AMG_id2name (used for debugging output and | |
137 | 'nomethod' only), the only other place which has it hardwired is | |
138 | overload.pm. */ | |
d279ab82 | 139 | EOT |
bab3dc31 | 140 | |
916e4025 | 141 | print $c map { s/(["\\"])/\\$1/g; " \"$_\",\n" } @names; |
bab3dc31 | 142 | |
08858ed2 | 143 | print $c <<"EOT"; |
bab3dc31 NC |
144 | "$last" |
145 | }; | |
bab3dc31 NC |
146 | EOT |
147 | ||
08858ed2 NC |
148 | safer_close($h); |
149 | safer_close($c); | |
e46c382e | 150 | safer_close($p); |
81372052 JC |
151 | rename_if_different("overload.c-new", "overload.c"); |
152 | rename_if_different("overload.h-new","overload.h"); | |
8c798f87 | 153 | |
bab3dc31 NC |
154 | __DATA__ |
155 | # Fallback should be the first | |
156 | fallback () | |
157 | ||
158 | # These 5 are the most common in the fallback switch statement in amagic_call | |
159 | to_sv (${} | |
160 | to_av (@{} | |
161 | to_hv (%{} | |
162 | to_gv (*{} | |
163 | to_cv (&{} | |
164 | ||
165 | # These have non-default cases in that switch statement | |
166 | inc (++ | |
167 | dec (-- | |
168 | bool_ (bool | |
169 | numer (0+ | |
170 | string ("" | |
171 | not (! | |
172 | copy (= | |
173 | abs (abs | |
174 | neg (neg | |
175 | iter (<> | |
176 | int (int | |
177 | ||
178 | # These 12 feature in the next switch statement | |
179 | lt (< | |
180 | le (<= | |
181 | gt (> | |
182 | ge (>= | |
183 | eq (== | |
184 | ne (!= | |
185 | slt (lt | |
186 | sle (le | |
187 | sgt (gt | |
188 | sge (ge | |
189 | seq (eq | |
190 | sne (ne | |
191 | ||
192 | nomethod (nomethod | |
193 | add (+ | |
194 | add_ass (+= | |
195 | subtr (- | |
196 | subtr_ass (-= | |
197 | mult (* | |
198 | mult_ass (*= | |
199 | div (/ | |
200 | div_ass (/= | |
201 | modulo (% | |
202 | modulo_ass (%= | |
203 | pow (** | |
204 | pow_ass (**= | |
205 | lshift (<< | |
206 | lshift_ass (<<= | |
207 | rshift (>> | |
208 | rshift_ass (>>= | |
209 | band (& | |
210 | band_ass (&= | |
211 | bor (| | |
212 | bor_ass (|= | |
213 | bxor (^ | |
214 | bxor_ass (^= | |
215 | ncmp (<=> | |
216 | scmp (cmp | |
217 | compl (~ | |
218 | atan2 (atan2 | |
219 | cos (cos | |
220 | sin (sin | |
221 | exp (exp | |
222 | log (log | |
223 | sqrt (sqrt | |
224 | repeat (x | |
225 | repeat_ass (x= | |
226 | concat (. | |
227 | concat_ass (.= | |
228 | smart (~~ | |
8c8d0d99 | 229 | ftest (-X |
d9151963 | 230 | regexp (qr |
bab3dc31 NC |
231 | # Note: Perl_Gv_AMupdate() assumes that DESTROY is the last entry |
232 | DESTROY DESTROY |