3 # Regenerate (overwriting only if changed):
7 # lib/overload/numbers.pm
9 # from information stored in the DATA section of this file.
11 # This allows the order of overloading constants to be changed.
13 # Accepts the standard regen_lib -q and -v args.
15 # This script is normally invoked from regen.pl.
18 # Get function prototypes
19 require 'regen/regen_lib.pl';
28 my ($enum, $name) = /^(\S+)\s+(\S+)/ or die "Can't parse $_";
33 my $c = safer_open('overload.c-new', 'overload.c');
34 my $h = safer_open('overload.h-new', 'overload.h');
35 mkdir("lib/overload", 0777) unless -d 'lib/overload';
36 my $p = safer_open('lib/overload/numbers.pm-new', 'lib/overload/numbers.pm');
38 print $p read_only_top(lang => 'Perl', by => 'regen/overload.pl',
39 file => 'lib/overload/numbers.pm', copyright => [2008]);
44 package overload::numbers;
54 { my \$i = 0; our %names = map { \$_ => \$i++ } \@names }
56 { my \$i = 0; our %enums = map { \$_ => \$i++ } \@enums }
60 for ([$c, 'overload.c'], [$h, 'overload.h']) {
61 my ($handle, $file) = @$_;
62 print $handle read_only_top(lang => 'C', by => 'regen/overload.pl',
63 file => $file, style => '*',
64 copyright => [1997, 1998, 2000, 2001,
72 $op = 'fallback' if $op eq '()';
75 my $l = 3 - int((length($enums[$_]) + 9) / 8);
77 printf $h " %s_amg,%s/* 0x%02x %-8s */\n", $enums[$_],
83 /* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */
86 #define NofAMmeth max_amg_code
90 #define AMG_id2name(id) (PL_AMG_names[id]+1)
91 #define AMG_id2namelen(id) (PL_AMG_namelens[id]-1)
93 static const U8 PL_AMG_namelens[NofAMmeth] = {
96 my $last = pop @names;
98 print $c map { " " . (length $_) . ",\n" } @names;
100 my $lastlen = length $last;
105 static const char * const PL_AMG_names[NofAMmeth] = {
106 /* Names kept in the symbol table. fallback => "()", the rest has
107 "(" prepended. The only other place in perl which knows about
108 this convention is AMG_id2name (used for debugging output and
109 'nomethod' only), the only other place which has it hardwired is
115 $n =~ s/(["\\])/\\$1/g;
116 my $l = 3 - int((length($n) + 7) / 8);
118 printf $c " \"%s\",%s/* %-10s */\n", $n, ("\t" x $l), $enums[$_];
126 foreach ($h, $c, $p) {
127 read_only_bottom_close_and_rename($_);
130 # Fallback should be the first
133 # These 5 are the most common in the fallback switch statement in amagic_call
140 # These have non-default cases in that switch statement
153 # These 12 feature in the next switch statement
206 # Note: Perl_Gv_AMupdate() assumes that DESTROY is the last entry