This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Refactor common parts of op.h, regexp.h into new .h
[perl5.git] / ext / B / defsubs_h.PL
CommitLineData
918c0b2d
CB
1# Do not remove the following line; MakeMaker relies on it to identify
2# this file as a template for defsubs.h
3# Extracting defsubs.h (with variable substitutions)
b7254abc
NC
4#!perl -w
5use File::Spec;
6my (undef, $headerpath) = @ARGV;
32882678 7my ($out) = __FILE__ =~ /(^.*)\.PL/i;
93804878 8$out =~ s/_h$/.h/;
fd40a117 9unlink $out if -l $out;
270c16a1 10open(OUT,">$out") || die "Cannot open $out:$!";
cc50ac46 11print "Extracting $out...\n";
651aa52e
AE
12print OUT <<"END";
13/*
14 !!! Don't modify this file - it's autogenerated from $0 !!!
15 */
16END
17
059a8bb7 18foreach my $const (qw(
7386c4fb 19 CVf_ANON
7386c4fb
JH
20 CVf_CLONE
21 CVf_CLONED
22 CVf_CONST
7386c4fb
JH
23 CVf_LVALUE
24 CVf_METHOD
25 CVf_NODEBUG
7386c4fb
JH
26 CVf_UNIQUE
27 CVf_WEAKOUTSIDE
28 GVf_IMPORTED_AV
29 GVf_IMPORTED_CV
30 GVf_IMPORTED_HV
31 GVf_IMPORTED_SV
b874ff32 32 HEf_SVKEY
7386c4fb
JH
33 SVTYPEMASK
34 SVf_FAKE
35 SVf_IOK
36 SVf_IVisUV
37 SVf_NOK
38 SVf_POK
39 SVf_READONLY
40 SVf_ROK
41 SVp_IOK
42 SVp_NOK
43 SVp_POK
44 SVpad_OUR
45 SVs_RMG
46 SVs_SMG
47 SVt_PVGV
48 SVt_PVHV
077a3fa2
NC
49 PAD_FAKELEX_ANON
50 PAD_FAKELEX_MULTI
059a8bb7 51 ))
4c1f658f
NIS
52 {
53 doconst($const);
54 }
e6663653
NC
55
56if ($] < 5.009) {
57 # This is only present in 5.10, but it's useful to B::Deparse to be able
58 # to import a dummy value from B
59 doconst(OPpPAD_STATE);
60}
61
e412117e
NC
62if ($] >= 5.009) {
63 # Constant not present in 5.8.x
64 doconst(CVf_ISXSUB);
f7192a3f
NC
65} else {
66 # Constant not present after 5.8.x
67 doconst(AVf_REAL);
68}
e412117e 69
aa381260
NC
70if ($] < 5.011) {
71 # Constant not present after 5.10.x
72 doconst(CVf_LOCKED);
73}
74
da8c672f
KW
75# First element in each tuple is the file; second is a regex snippet
76# giving the prefix to limit the names of symbols to define that come
77# from that file. If none, all symbols will be defined whose values
78# match the pattern below.
1850c8f9 79foreach my $tuple (['op_reg_common.h','(?:(?:RXf_)?PMf_)'],['op.h'],['cop.h'],['regexp.h','RXf_'])
4c1f658f 80 {
c737faaf
YO
81 my $file = $tuple->[0];
82 my $pfx = $tuple->[1] || '';
b7254abc 83 my $path = File::Spec->catfile($headerpath, $file);
db5fd395 84 open(OPH,"$path") || die "Cannot open $path:$!";
4c1f658f
NIS
85 while (<OPH>)
86 {
e32a8816
KW
87 doconst($1) if (/ \#define \s+ ( $pfx \w+ ) \s+
88 ( [()|\dx]+ # Parens, '|', digits, 'x'
89 | \(? \d+ \s* << .*? # digits left shifted by anything
90 ) \s* (?: $| \/ \* ) # ending at comment or $
91 /x);
4c1f658f
NIS
92 }
93 close(OPH);
94 }
95close(OUT);
96
97sub doconst
98{
99 my $sym = shift;
100 my $l = length($sym);
101 print OUT <<"END";
102 newCONSTSUB(stash,"$sym",newSViv($sym));
79cb57f6 103 av_push(export_ok,newSVpvn("$sym",$l));
4c1f658f
NIS
104END
105}