This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor generate_uudmap.c to use a helper function to output init blocks.
[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'},
8b09643d
NC
42 'uvar' => {get => 'getuvar', set => 'setuvar'},
43 'defelem' => {get => 'getdefelem', set => 'setdefelem'},
b2e9fc6f 44 'regexp' => {set => 'setregexp', alias => [qw(bm fm)]},
8b09643d
NC
45 'regdata' => {len => 'regdata_cnt'},
46 'regdatum' => {get => 'regdatum_get', set => 'regdatum_set'},
47 'amagic' => {set => 'setamagic', free => 'setamagic'},
48 'amagicelem' => {set => 'setamagic', free => 'setamagic'},
49 'backref' => {free => 'killbackrefs'},
50 'ovrld' => {free => 'freeovrld'},
51 'utf8' => {set => 'setutf8'},
52 'collxfrm' => {set => 'setcollxfrm',
53 cond => '#ifdef USE_LOCALE_COLLATE'},
54 'hintselem' => {set => 'sethint', clear => 'clearhint'},
55 'hints' => {clear => 'clearhints'},
56);
57
58my $h = open_new('mg_vtable.h', '>',
59 { by => 'regen/mg_vtable.pl', file => 'mg_vtable.h',
60 style => '*' });
61
ca298f7d 62{
2d1f1fe5
NC
63 my @names = grep {!ref $_} @sig;
64 my $want = join ",\n ", (map {"want_vtbl_$_"} @names), 'magic_vtable_max';
65 my $names = join qq{",\n "}, @names;
66
ca298f7d
NC
67 print $h <<"EOH";
68enum { /* pass one of these to get_vtbl */
2d1f1fe5
NC
69 $want
70};
71
72#ifdef DOINIT
73EXTCONST char *PL_magic_vtable_names[magic_vtable_max] = {
74 "$names"
ca298f7d 75};
2d1f1fe5
NC
76#else
77EXTCONST char *PL_magic_vtable_names[magic_vtable_max];
78#endif
ca298f7d
NC
79
80EOH
81}
82
8b09643d
NC
83print $h <<'EOH';
84/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
85 * pointer to data, whereas we're assigning pointers to functions, which are
86 * not the same beast. ANSI doesn't allow the assignment from one to the other.
87 * (although most, but not all, compilers are prepared to do it)
88 */
89
0ffb5b03 90/* order is:
8b09643d
NC
91 get
92 set
93 len
94 clear
95 free
96 copy
97 dup
98 local
99*/
100
b7b5e578 101#ifdef DOINIT
c7fdacb9 102EXT_MGVTBL PL_magic_vtables[magic_vtable_max] = {
8b09643d
NC
103EOH
104
b7b5e578 105my @vtable_names;
b2e9fc6f 106my @aliases;
b7b5e578 107
8b09643d 108while (my ($name, $data) = splice @sig, 0, 2) {
b7b5e578 109 push @vtable_names, $name;
0a1f728a 110 my @funcs = map {
8b09643d
NC
111 $data->{$_} ? "Perl_magic_$data->{$_}" : 0;
112 } qw(get set len clear free copy dup local);
113
0a1f728a 114 $funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const};
0ffb5b03 115 my $funcs = join ", ", @funcs;
8b09643d 116
b7b5e578
NC
117 # Because we can't have a , after the last {...}
118 my $comma = @sig ? ',' : '';
119
8b09643d 120 print $h "$data->{cond}\n" if $data->{cond};
b7b5e578
NC
121 print $h " { $funcs }$comma\n";
122 print $h <<"EOH" if $data->{cond};
0ffb5b03 123#else
b7b5e578 124 { 0, 0, 0, 0, 0, 0, 0, 0 }$comma
0ffb5b03 125#endif
b7b5e578 126EOH
b2e9fc6f
NC
127 foreach(@{$data->{alias}}) {
128 push @aliases, "#define want_vtbl_$_ want_vtbl_$name\n";
129 push @vtable_names, $_;
130 }
8b09643d
NC
131}
132
b7b5e578
NC
133print $h <<'EOH';
134};
135#else
c7fdacb9 136EXT_MGVTBL PL_magic_vtables[magic_vtable_max];
b7b5e578
NC
137#endif
138
139EOH
140
b76b0bf9 141print $h (sort @aliases), "\n";
b7b5e578
NC
142
143print $h "#define PL_vtbl_$_ PL_magic_vtables[want_vtbl_$_]\n"
144 foreach sort @vtable_names;
145
8b09643d 146read_only_bottom_close_and_rename($h);