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_lib.pl';
24 use File::Spec::Functions qw(catdir catfile);;
30 my ($enum, $name) = /^(\S+)\s+(\S+)/ or die "Can't parse $_";
35 safer_unlink (catfile(qw(lib overload numbers.pm)));
36 my $c = safer_open("overload.c-new");
37 my $h = safer_open("overload.h-new");
38 mkdir("lib/overload") unless -d catdir(qw(lib overload));
39 my $p = safer_open(catfile(qw(lib overload numbers.pm)));
47 # -*- buffer-read-only: t -*-
49 # lib/overload/numbers.pm
51 # Copyright (C) 2008 by Larry Wall and others
53 # You may distribute under the terms of either the GNU General Public
54 # License or the Artistic License, as specified in the README file.
56 # !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
57 # This file is built by overload.pl
60 package overload::numbers;
70 { my \$i = 0; our %names = map { \$_ => \$i++ } \@names }
72 { my \$i = 0; our %enums = map { \$_ => \$i++ } \@enums }
81 /* -*- buffer-read-only: t -*-
85 * Copyright (C) 1997, 1998, 2000, 2001, 2005, 2006, 2007 by Larry Wall
88 * You may distribute under the terms of either the GNU General Public
89 * License or the Artistic License, as specified in the README file.
91 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
92 * This file is built by overload.pl
98 print_header('overload.c');
101 print_header('overload.h');
107 print " ${_}_amg,\n", foreach @enums;
111 /* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */
114 #define NofAMmeth max_amg_code
120 #define AMG_id2name(id) (PL_AMG_names[id]+1)
121 #define AMG_id2namelen(id) (PL_AMG_namelens[id]-1)
123 static const U8 PL_AMG_namelens[NofAMmeth] = {
126 my $last = pop @names;
128 print $c " $_,\n" foreach map { length $_ } @names;
130 my $lastlen = length $last;
135 static const char * const PL_AMG_names[NofAMmeth] = {
136 /* Names kept in the symbol table. fallback => "()", the rest has
137 "(" prepended. The only other place in perl which knows about
138 this convention is AMG_id2name (used for debugging output and
139 'nomethod' only), the only other place which has it hardwired is
143 print $c " \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
153 rename_if_different("overload.c-new", "overload.c");
154 rename_if_different("overload.h-new","overload.h");
157 # Fallback should be the first
160 # These 5 are the most common in the fallback switch statement in amagic_call
167 # These have non-default cases in that switch statement
180 # These 12 feature in the next switch statement
232 # Note: Perl_Gv_AMupdate() assumes that DESTROY is the last entry