This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / overload.pl
CommitLineData
4ba2a8a0
JH
1#!/usr/bin/perl -w
2
3#
4# Generate overload.h
5# This allows the order of overloading constants to be changed.
6#
7
8BEGIN {
9 # Get function prototypes
10 require 'regen_lib.pl';
11}
12
13use strict;
14
15my (@enums, @names);
16while (<DATA>) {
17 next if /^#/;
18 next if /^$/;
19 my ($enum, $name) = /^(\S+)\s+(\S+)/ or die "Can't parse $_";
20 # No smart match in 5.8.x
21 next if $enum eq 'smart';
22 push @enums, $enum;
23 push @names, $name;
24}
25
26safer_unlink 'overload.h';
27die "overload.h: $!" unless open(H, ">overload.h");
28binmode H;
29select H;
30print <<'EOF';
31/* -*- buffer-read-only: t -*-
32 *
33 * overload.h
34 *
35 * Copyright (C) 1997, 1998, 2000, 2001, 2005 and 2006 by Larry Wall and
36 * others
37 *
38 * You may distribute under the terms of either the GNU General Public
39 * License or the Artistic License, as specified in the README file.
40 *
41 * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
42 * This file is built by overload.pl
43 */
44
45enum {
46EOF
47
48print " ${_}_amg,\n", foreach @enums;
49
50print <<'EOF';
51 max_amg_code
52 /* Do not leave a trailing comma here. C9X allows it, C89 doesn't. */
53};
54
55
56#define NofAMmeth max_amg_code
57#define AMG_id2name(id) (PL_AMG_names[id]+1)
58
59#ifdef DOINIT
60EXTCONST char * const PL_AMG_names[NofAMmeth] = {
61 /* Names kept in the symbol table. fallback => "()", the rest has
62 "(" prepended. The only other place in perl which knows about
63 this convention is AMG_id2name (used for debugging output and
64 'nomethod' only), the only other place which has it hardwired is
65 overload.pm. */
66EOF
67
68my $last = pop @names;
69print " \"$_\",\n" foreach map { s/(["\\"])/\\$1/g; $_ } @names;
70
71print <<"EOT";
72 "$last"
73};
74#else
75EXTCONST char * PL_AMG_names[NofAMmeth];
76#endif /* def INITAMAGIC */
77EOT
78
79close H or die $!;
80
81__DATA__
82# Fallback should be the first
83fallback ()
84
85# These 5 are the most common in the fallback switch statement in amagic_call
86to_sv (${}
87to_av (@{}
88to_hv (%{}
89to_gv (*{}
90to_cv (&{}
91
92# These have non-default cases in that switch statement
93inc (++
94dec (--
95bool_ (bool
96numer (0+
97string (""
98not (!
99copy (=
100abs (abs
101neg (neg
102iter (<>
103int (int
104
105# These 12 feature in the next switch statement
106lt (<
107le (<=
108gt (>
109ge (>=
110eq (==
111ne (!=
112slt (lt
113sle (le
114sgt (gt
115sge (ge
116seq (eq
117sne (ne
118
119nomethod (nomethod
120add (+
121add_ass (+=
122subtr (-
123subtr_ass (-=
124mult (*
125mult_ass (*=
126div (/
127div_ass (/=
128modulo (%
129modulo_ass (%=
130pow (**
131pow_ass (**=
132lshift (<<
133lshift_ass (<<=
134rshift (>>
135rshift_ass (>>=
136band (&
137band_ass (&=
138bor (|
139bor_ass (|=
140bxor (^
141bxor_ass (^=
142ncmp (<=>
143scmp (cmp
144compl (~
145atan2 (atan2
146cos (cos
147sin (sin
148exp (exp
149log (log
150sqrt (sqrt
151repeat (x
152repeat_ass (x=
153concat (.
154concat_ass (.=
155smart (~~
156# Note: Perl_Gv_AMupdate() assumes that DESTROY is the last entry
157DESTROY DESTROY