This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Replace references to PL_vtbl_{bm,fm} in the code with PL_vtbl_regexp.
[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
NC
62{
63 my @names = map {"want_vtbl_$_"} grep {!ref $_} @sig;
c7fdacb9 64 push @names, 'magic_vtable_max';
ca298f7d
NC
65 local $" = ",\n ";
66 print $h <<"EOH";
67enum { /* pass one of these to get_vtbl */
68 @names
69};
70
71EOH
72}
73
8b09643d
NC
74print $h <<'EOH';
75/* These all need to be 0, not NULL, as NULL can be (void*)0, which is a
76 * pointer to data, whereas we're assigning pointers to functions, which are
77 * not the same beast. ANSI doesn't allow the assignment from one to the other.
78 * (although most, but not all, compilers are prepared to do it)
79 */
80
0ffb5b03 81/* order is:
8b09643d
NC
82 get
83 set
84 len
85 clear
86 free
87 copy
88 dup
89 local
90*/
91
b7b5e578 92#ifdef DOINIT
c7fdacb9 93EXT_MGVTBL PL_magic_vtables[magic_vtable_max] = {
8b09643d
NC
94EOH
95
b7b5e578 96my @vtable_names;
b2e9fc6f 97my @aliases;
b7b5e578 98
8b09643d 99while (my ($name, $data) = splice @sig, 0, 2) {
b7b5e578 100 push @vtable_names, $name;
0a1f728a 101 my @funcs = map {
8b09643d
NC
102 $data->{$_} ? "Perl_magic_$data->{$_}" : 0;
103 } qw(get set len clear free copy dup local);
104
0a1f728a 105 $funcs[0] = "(int (*)(pTHX_ SV *, MAGIC *))" . $funcs[0] if $data->{const};
0ffb5b03 106 my $funcs = join ", ", @funcs;
8b09643d 107
b7b5e578
NC
108 # Because we can't have a , after the last {...}
109 my $comma = @sig ? ',' : '';
110
8b09643d 111 print $h "$data->{cond}\n" if $data->{cond};
b7b5e578
NC
112 print $h " { $funcs }$comma\n";
113 print $h <<"EOH" if $data->{cond};
0ffb5b03 114#else
b7b5e578 115 { 0, 0, 0, 0, 0, 0, 0, 0 }$comma
0ffb5b03 116#endif
b7b5e578 117EOH
b2e9fc6f
NC
118 foreach(@{$data->{alias}}) {
119 push @aliases, "#define want_vtbl_$_ want_vtbl_$name\n";
120 push @vtable_names, $_;
121 }
8b09643d
NC
122}
123
b7b5e578
NC
124print $h <<'EOH';
125};
126#else
c7fdacb9 127EXT_MGVTBL PL_magic_vtables[magic_vtable_max];
b7b5e578
NC
128#endif
129
130EOH
131
b76b0bf9 132print $h (sort @aliases), "\n";
b7b5e578
NC
133
134print $h "#define PL_vtbl_$_ PL_magic_vtables[want_vtbl_$_]\n"
135 foreach sort @vtable_names;
136
8b09643d 137read_only_bottom_close_and_rename($h);