This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp.c: Fix Win32 compilation problems
[perl5.git] / regen / keywords.pl
1 #!/usr/bin/perl -w
2 #
3 # Regenerate (overwriting only if changed):
4 #
5 #    keywords.h keywords.c
6 #
7 # from information stored in the DATA section of this file.
8 #
9 # Accepts the standard regen_lib -q and -v args.
10
11 use strict;
12 use Devel::Tokenizer::C 0.05;
13
14 require 'regen/regen_lib.pl';
15
16 my $h = open_new('keywords.h', '>',
17                  { by => 'regen/keywords.pl', from => 'its data',
18                    file => 'keywords.h', style => '*',
19                    copyright => [1994 .. 1997, 1999 .. 2002, 2005 .. 2007]});
20 my $c = open_new('keywords.c', '>',
21                  { by => 'regen/keywords.pl', from => 'its data', style => '*'});
22
23 my %by_strength;
24
25 my $keynum = 0;
26 while (<DATA>) {
27     chop;
28     next unless $_;
29     next if /^#/;
30     my ($strength, $keyword) = /^([- +])([A-Z_a-z2]+)/;
31     die "Bad line '$_'" unless defined $strength;
32     print $h tab(5, "#define KEY_$keyword"), $keynum++, "\n";
33     push @{$by_strength{$strength}}, $keyword;
34 }
35
36 # If this hash changes, make sure the equivalent hash in
37 # dist/B-Deparse/Deparse.pm is also updated.
38 my %feature_kw = (
39         given   => 'switch',
40         when    => 'switch',
41         default => 'switch',
42         # continue is already a keyword
43         break   => 'switch',
44
45         say     => 'say',
46
47         state   => 'state',
48
49         evalbytes=>'evalbytes',
50
51         __SUB__ => '__SUB__',
52
53         fc      => 'fc',
54         );
55
56 my %pos = map { ($_ => 1) } @{$by_strength{'+'}};
57
58 my $t = Devel::Tokenizer::C->new(TokenFunc     => \&perl_keyword,
59                                  TokenString   => 'name',
60                                  StringLength  => 'len',
61                                  MergeSwitches => 1,
62                                 );
63
64 $t->add_tokens(@{$by_strength{'+'}}, @{$by_strength{'-'}}, 'elseif');
65
66 my $switch = $t->generate(Indent => '  ');
67
68 print $c <<"END";
69 #include "EXTERN.h"
70 #define PERL_IN_KEYWORDS_C
71 #include "perl.h"
72 #include "keywords.h"
73 #include "feature.h"
74
75 I32
76 Perl_keyword (pTHX_ const char *name, I32 len, bool all_keywords)
77 {
78   dVAR;
79
80   PERL_ARGS_ASSERT_KEYWORD;
81
82 $switch
83 unknown:
84   return 0;
85 }
86 END
87
88 sub perl_keyword
89 {
90   my $k = shift;
91   my $sign = $pos{$k} ? '' : '-';
92
93   if ($k eq 'elseif') {
94     return <<END;
95 Perl_ck_warner_d(aTHX_ packWARN(WARN_SYNTAX), "elseif should be elsif");
96 END
97   }
98   elsif (my $feature = $feature_kw{$k}) {
99     $feature =~ s/([\\"])/\\$1/g;
100     return <<END;
101 return (all_keywords || FEATURE_\U$feature\E_IS_ENABLED ? ${sign}KEY_$k : 0);
102 END
103   }
104   return <<END;
105 return ${sign}KEY_$k;
106 END
107 }
108
109 read_only_bottom_close_and_rename($_, [$0]) foreach $c, $h;
110
111
112 # coresub_op in op.c expects __FILE__, __LINE__ and __PACKAGE__ to be the
113 # first three.
114
115 __END__
116
117  NULL
118 -__FILE__
119 -__LINE__
120 -__PACKAGE__
121 +__DATA__
122 +__END__
123 -__SUB__
124 +AUTOLOAD
125 +BEGIN
126 +UNITCHECK
127 +DESTROY
128 +END
129 +INIT
130 +CHECK
131 -abs
132 -accept
133 -alarm
134 -and
135 -atan2
136 -bind
137 -binmode
138 -bless
139 -break
140 -caller
141 -chdir
142 -chmod
143 -chomp
144 -chop
145 -chown
146 -chr
147 -chroot
148 -close
149 -closedir
150 -cmp
151 -connect
152 -continue
153 -cos
154 -crypt
155 -dbmclose
156 -dbmopen
157 +default
158 +defined
159 +delete
160 -die
161 +do
162 -dump
163 -each
164 +else
165 +elsif
166 -endgrent
167 -endhostent
168 -endnetent
169 -endprotoent
170 -endpwent
171 -endservent
172 -eof
173 -eq
174 +eval
175 -evalbytes
176 -exec
177 +exists
178 -exit
179 -exp
180 -fc
181 -fcntl
182 -fileno
183 -flock
184 +for
185 +foreach
186 -fork
187 +format
188 -formline
189 -ge
190 -getc
191 -getgrent
192 -getgrgid
193 -getgrnam
194 -gethostbyaddr
195 -gethostbyname
196 -gethostent
197 -getlogin
198 -getnetbyaddr
199 -getnetbyname
200 -getnetent
201 -getpeername
202 -getpgrp
203 -getppid
204 -getpriority
205 -getprotobyname
206 -getprotobynumber
207 -getprotoent
208 -getpwent
209 -getpwnam
210 -getpwuid
211 -getservbyname
212 -getservbyport
213 -getservent
214 -getsockname
215 -getsockopt
216 +given
217 +glob
218 -gmtime
219 +goto
220 +grep
221 -gt
222 -hex
223 +if
224 -index
225 -int
226 -ioctl
227 -join
228 -keys
229 -kill
230 +last
231 -lc
232 -lcfirst
233 -le
234 -length
235 -link
236 -listen
237 +local
238 -localtime
239 -lock
240 -log
241 -lstat
242 -lt
243 +m
244 +map
245 -mkdir
246 -msgctl
247 -msgget
248 -msgrcv
249 -msgsnd
250 +my
251 -ne
252 +next
253 +no
254 -not
255 -oct
256 -open
257 -opendir
258 -or
259 -ord
260 +our
261 -pack
262 +package
263 -pipe
264 -pop
265 +pos
266 +print
267 +printf
268 +prototype
269 -push
270 +q
271 +qq
272 +qr
273 -quotemeta
274 +qw
275 +qx
276 -rand
277 -read
278 -readdir
279 -readline
280 -readlink
281 -readpipe
282 -recv
283 +redo
284 -ref
285 -rename
286 +require
287 -reset
288 +return
289 -reverse
290 -rewinddir
291 -rindex
292 -rmdir
293 +s
294 +say
295 +scalar
296 -seek
297 -seekdir
298 -select
299 -semctl
300 -semget
301 -semop
302 -send
303 -setgrent
304 -sethostent
305 -setnetent
306 -setpgrp
307 -setpriority
308 -setprotoent
309 -setpwent
310 -setservent
311 -setsockopt
312 -shift
313 -shmctl
314 -shmget
315 -shmread
316 -shmwrite
317 -shutdown
318 -sin
319 -sleep
320 -socket
321 -socketpair
322 +sort
323 -splice
324 +split
325 -sprintf
326 -sqrt
327 -srand
328 -stat
329 +state
330 +study
331 +sub
332 -substr
333 -symlink
334 -syscall
335 -sysopen
336 -sysread
337 -sysseek
338 -system
339 -syswrite
340 -tell
341 -telldir
342 -tie
343 -tied
344 -time
345 -times
346 +tr
347 -truncate
348 -uc
349 -ucfirst
350 -umask
351 +undef
352 +unless
353 -unlink
354 -unpack
355 -unshift
356 -untie
357 +until
358 +use
359 -utime
360 -values
361 -vec
362 -wait
363 -waitpid
364 -wantarray
365 -warn
366 +when
367 +while
368 -write
369 -x
370 -xor
371 +y