This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Generate the enum for want_vtbl_* with regen/mg_vtable.pl
[perl5.git] / regen / mg_vtable.pl
CommitLineData
8b09643d
NC
1#!/usr/bin/perl -w
2#
3# Regenerate (overwriting only if changed):
4#
5# mg_vtable.h
6#
7# from information stored in this file.
8#
9# Accepts the standard regen_lib -q and -v args.
10#
11# This script is normally invoked from regen.pl.
12
13use strict;
14require 5.004;
15
16BEGIN {
17 # Get function prototypes
18 require 'regen/regen_lib.pl';
19}
20
0a1f728a 21# These have a subtly different "namespace" from the magic types.
8b09643d
NC
22my @sig =
23 (
24 'sv' => {get => 'get', set => 'set', len => 'len'},
25 'env' => {set => 'set_all_env', clear => 'clear_all_env'},
26 'envelem' => {set => 'setenv', clear => 'clearenv'},
27 'sigelem' => {get => 'getsig', set => 'setsig', clear => 'clearsig',
28 cond => '#ifndef PERL_MICRO'},
29 'pack' => {len => 'sizepack', clear => 'wipepack'},
30 'packelem' => {get => 'getpack', set => 'setpack', clear => 'clearpack'},
31 'dbline' => {set => 'setdbline'},
32 'isa' => {set => 'setisa', clear => 'clearisa'},
33 'isaelem' => {set => 'setisa'},
34 'arylen' => {get => 'getarylen', set => 'setarylen', const => 1},
35 'arylen_p' => {free => 'freearylen_p'},
36 'mglob' => {set => 'setmglob'},
37 'nkeys' => {get => 'getnkeys', set => 'setnkeys'},
38 'taint' => {get => 'gettaint', set => 'settaint'},
39 'substr' => {get => 'getsubstr', set => 'setsubstr'},
40 'vec' => {get => 'getvec', set => 'setvec'},
41 'pos' => {get => 'getpos', set => 'setpos'},
42 'bm' => {set => 'setregexp'},
43 'fm' => {set => 'setregexp'},
44 'uvar' => {get => 'getuvar', set => 'setuvar'},
45 'defelem' => {get => 'getdefelem', set => 'setdefelem'},
46 'regexp' => {set => 'setregexp'},
47 'regdata' => {len => 'regdata_cnt'},
48 'regdatum' => {get => 'regdatum_get', set => 'regdatum_set'},
49 'amagic' => {set => 'setamagic', free => 'setamagic'},
50 'amagicelem' => {set => 'setamagic', free => 'setamagic'},
51 'backref' => {free => 'killbackrefs'},
52 'ovrld' => {free => 'freeovrld'},
53 'utf8' => {set => 'setutf8'},
54 'collxfrm' => {set => 'setcollxfrm',
55 cond => '#ifdef USE_LOCALE_COLLATE'},
56 'hintselem' => {set => 'sethint', clear => 'clearhint'},
57 'hints' => {clear => 'clearhints'},
58);
59
60my $h = open_new('mg_vtable.h', '>',
61 { by => 'regen/mg_vtable.pl', file => 'mg_vtable.h',
62 style => '*' });
63
ca298f7d
NC
64{
65 my @names = map {"want_vtbl_$_"} grep {!ref $_} @sig;
66 local $" = ",\n ";
67 print $h <<"EOH";
68enum { /* pass one of these to get_vtbl */
69 @names
70};
71
72EOH
73}
74
8b09643d
NC
75print $h <<'EOH';
76/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
77 * pointer to data, whereas we're assigning pointers to functions, which are
78 * not the same beast. ANSI doesn't allow the assignment from one to the other.
79 * (although most, but not all, compilers are prepared to do it)
80 */
81
0ffb5b03 82/* order is:
8b09643d
NC
83 get
84 set
85 len
86 clear
87 free
88 copy
89 dup
90 local
91*/
92
93EOH
94
95while (my ($name, $data) = splice @sig, 0, 2) {
0a1f728a 96 my @funcs = map {
8b09643d
NC
97 $data->{$_} ? "Perl_magic_$data->{$_}" : 0;
98 } qw(get set len clear free copy dup local);
99
0a1f728a 100 $funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const};
0ffb5b03 101 my $funcs = join ", ", @funcs;
8b09643d
NC
102
103 print $h "$data->{cond}\n" if $data->{cond};
104 print $h <<"EOT";
0ffb5b03
NC
105#ifdef DOINIT
106EXT_MGVTBL PL_vtbl_$name
107 = { $funcs };
108#else
109EXT_MGVTBL PL_vtbl_$name;
110#endif
8b09643d
NC
111EOT
112 print $h "#endif\n" if $data->{cond};
113 print $h "\n";
114}
115
116read_only_bottom_close_and_rename($h);