11 sub DEFAULT_ON () { 1 }
12 sub DEFAULT_OFF () { 2 }
17 'io' => { 'pipe' => DEFAULT_OFF,
18 'unopened' => DEFAULT_OFF,
19 'closed' => DEFAULT_OFF,
20 'newline' => DEFAULT_OFF,
21 'exec' => DEFAULT_OFF,
23 'syntax' => { 'ambiguous' => DEFAULT_OFF,
24 'semicolon' => DEFAULT_OFF,
25 'precedence' => DEFAULT_OFF,
26 'bareword' => DEFAULT_OFF,
27 'reserved' => DEFAULT_OFF,
28 'digit' => DEFAULT_OFF,
29 'parenthesis' => DEFAULT_OFF,
30 'deprecated' => DEFAULT_OFF,
31 'printf' => DEFAULT_OFF,
32 'prototype' => DEFAULT_OFF,
35 'severe' => { 'inplace' => DEFAULT_ON,
36 'internal' => DEFAULT_ON,
37 'debugging' => DEFAULT_ON,
38 'malloc' => DEFAULT_ON,
40 'void' => DEFAULT_OFF,
41 'recursion' => DEFAULT_OFF,
42 'redefine' => DEFAULT_OFF,
43 'numeric' => DEFAULT_OFF,
44 'uninitialized' => DEFAULT_OFF,
45 'once' => DEFAULT_OFF,
46 'misc' => DEFAULT_OFF,
47 'regexp' => DEFAULT_OFF,
48 'glob' => DEFAULT_OFF,
50 'untie' => DEFAULT_OFF,
51 'substr' => DEFAULT_OFF,
52 'taint' => DEFAULT_OFF,
53 'signal' => DEFAULT_OFF,
54 'closure' => DEFAULT_OFF,
55 'overflow' => DEFAULT_OFF,
56 'portable' => DEFAULT_OFF,
57 'utf8' => DEFAULT_OFF,
58 'exiting' => DEFAULT_OFF,
59 'pack' => DEFAULT_OFF,
60 'unpack' => DEFAULT_OFF,
61 #'default' => DEFAULT_ON,
66 ###########################################################################
69 $t .= "\t" x ($l - (length($t) + 1) / 8);
73 ###########################################################################
85 foreach $k (sort keys %$tre) {
87 die "duplicate key $k\n" if defined $list{$k} ;
88 $Value{$index} = uc $k ;
89 push @{ $list{$k} }, $index ++ ;
91 { push (@{ $list{$k} }, walk ($v)) }
92 push @list, @{ $list{$k} } ;
98 ###########################################################################
107 for ($i = 1 ; $i < @a; ++ $i) {
109 if $a[$i] == $a[$i - 1] + 1 && $a[$i] + 1 == $a[$i + 1] ;
112 my $out = join(",",@out);
114 $out =~ s/,(\.\.,)+/../g ;
118 ###########################################################################
126 my $max = (sort {$a <=> $b} map { length $_ } keys %$tre)[-1] ;
128 $prefix .= " " x $indent ;
129 foreach $k (sort keys %$tre) {
131 print $prefix . "|\n" ;
132 print $prefix . "+- $k" ;
135 print " " . "-" x ($max - length $k ) . "+\n" ;
136 printTree ($v, $prefix . "|" , $max + $indent - 1)
144 ###########################################################################
149 my $mask = "\x00" x $max ;
153 vec($mask, $_, 1) = 1 ;
156 #$string = unpack("H$max", $mask) ;
157 #$string =~ s/(..)/\x$1/g;
158 foreach (unpack("C*", $mask)) {
159 $string .= '\x' . sprintf("%2.2x", $_) ;
164 ###########################################################################
166 if (@ARGV && $ARGV[0] eq "tree")
169 printTree($tree, " ", 4) ;
174 unlink "lib/warnings.pm";
175 open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
176 open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
179 /* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
180 This file is built by warnings.pl
181 Any changes made here will be lost!
185 #define Off(x) ((x) / 8)
186 #define Bit(x) (1 << ((x) % 8))
187 #define IsSet(a, x) ((a)[Off(x)] & Bit(x))
190 #define G_WARN_OFF 0 /* $^W == 0 */
191 #define G_WARN_ON 1 /* -w flag and $^W != 0 */
192 #define G_WARN_ALL_ON 2 /* -W flag */
193 #define G_WARN_ALL_OFF 4 /* -X flag */
194 #define G_WARN_ONCE 8 /* set if 'once' ever enabled */
195 #define G_WARN_ALL_MASK (G_WARN_ALL_ON|G_WARN_ALL_OFF)
197 #define pWARN_STD Nullsv
198 #define pWARN_ALL (Nullsv+1) /* use warnings 'all' */
199 #define pWARN_NONE (Nullsv+2) /* no warnings 'all' */
201 #define specialWARN(x) ((x) == pWARN_STD || (x) == pWARN_ALL || \
208 #@{ $list{"all"} } = walk ($tree) ;
213 my $warn_size = int($index / 8) + ($index % 8 != 0) ;
216 foreach $k (sort { $a <=> $b } keys %Value) {
217 print WARN tab(5, "#define WARN_$Value{$k}"), "$k\n" ;
221 print WARN tab(5, '#define WARNsize'), "$warn_size\n" ;
222 #print WARN tab(5, '#define WARN_ALLstring'), '"', ('\377' x $warn_size) , "\"\n" ;
223 print WARN tab(5, '#define WARN_ALLstring'), '"', ('\125' x $warn_size) , "\"\n" ;
224 print WARN tab(5, '#define WARN_NONEstring'), '"', ('\0' x $warn_size) , "\"\n" ;
228 #define isLEXWARN_on (PL_curcop->cop_warnings != pWARN_STD)
229 #define isLEXWARN_off (PL_curcop->cop_warnings == pWARN_STD)
230 #define isWARN_ONCE (PL_dowarn & (G_WARN_ON|G_WARN_ONCE))
231 #define isWARN_on(c,x) (IsSet(SvPVX(c), 2*(x)))
232 #define isWARNf_on(c,x) (IsSet(SvPVX(c), 2*(x)+1))
235 ( ! specialWARN(PL_curcop->cop_warnings) && \
236 ( isWARNf_on(PL_curcop->cop_warnings, WARN_ALL) || \
237 isWARNf_on(PL_curcop->cop_warnings, x)))
240 ( (isLEXWARN_on && PL_curcop->cop_warnings != pWARN_NONE && \
241 (PL_curcop->cop_warnings == pWARN_ALL || \
242 isWARN_on(PL_curcop->cop_warnings, x) ) ) \
243 || (isLEXWARN_off && PL_dowarn & G_WARN_ON) )
245 #define ckWARN2(x,y) \
246 ( (isLEXWARN_on && PL_curcop->cop_warnings != pWARN_NONE && \
247 (PL_curcop->cop_warnings == pWARN_ALL || \
248 isWARN_on(PL_curcop->cop_warnings, x) || \
249 isWARN_on(PL_curcop->cop_warnings, y) ) ) \
250 || (isLEXWARN_off && PL_dowarn & G_WARN_ON) )
252 #define ckWARN_d(x) \
253 (isLEXWARN_off || PL_curcop->cop_warnings == pWARN_ALL || \
254 (PL_curcop->cop_warnings != pWARN_NONE && \
255 isWARN_on(PL_curcop->cop_warnings, x) ) )
257 #define ckWARN2_d(x,y) \
258 (isLEXWARN_off || PL_curcop->cop_warnings == pWARN_ALL || \
259 (PL_curcop->cop_warnings != pWARN_NONE && \
260 (isWARN_on(PL_curcop->cop_warnings, x) || \
261 isWARN_on(PL_curcop->cop_warnings, y) ) ) )
263 /* end of file warnings.h */
270 last if /^KEYWORDS$/ ;
274 #$list{'all'} = [ $offset .. 8 * ($warn_size/2) - 1 ] ;
276 #my %Keys = map {lc $Value{$_}, $_} keys %Value ;
278 print PM "%Offsets = (\n" ;
279 foreach my $k (sort { $a <=> $b } keys %Value) {
280 my $v = lc $Value{$k} ;
282 print PM tab(4, " '$v'"), "=> $k,\n" ;
287 print PM "%Bits = (\n" ;
288 foreach $k (sort keys %list) {
291 my @list = sort { $a <=> $b } @$v ;
293 print PM tab(4, " '$k'"), '=> "',
294 # mkHex($warn_size, @list),
295 mkHex($warn_size, map $_ * 2 , @list),
296 '", # [', mkRange(@list), "]\n" ;
301 print PM "%DeadBits = (\n" ;
302 foreach $k (sort keys %list) {
305 my @list = sort { $a <=> $b } @$v ;
307 print PM tab(4, " '$k'"), '=> "',
308 # mkHex($warn_size, @list),
309 mkHex($warn_size, map $_ * 2 + 1 , @list),
310 '", # [', mkRange(@list), "]\n" ;
314 print PM '$NONE = "', ('\0' x $warn_size) , "\";\n" ;
315 print PM '$LAST_BIT = ' . "$index ;\n" ;
316 print PM '$BYTES = ' . "$warn_size ;\n" ;
325 # This file was created by warnings.pl
326 # Any changes made here will be lost.
331 our $VERSION = '1.00';
335 warnings - Perl pragma to control optional warnings
345 use warnings::register;
346 if (warnings::enabled()) {
347 warnings::warn("some warning");
350 if (warnings::enabled("void")) {
351 warnings::warn("void", "some warning");
354 if (warnings::enabled($object)) {
355 warnings::warn($object, "some warning");
358 warnif("some warning");
359 warnif("void", "some warning");
360 warnif($object, "some warning");
364 If no import list is supplied, all possible warnings are either enabled
367 A number of functions are provided to assist module authors.
371 =item use warnings::register
373 Creates a new warnings category with the same name as the package where
374 the call to the pragma is used.
376 =item warnings::enabled()
378 Use the warnings category with the same name as the current package.
380 Return TRUE if that warnings category is enabled in the calling module.
381 Otherwise returns FALSE.
383 =item warnings::enabled($category)
385 Return TRUE if the warnings category, C<$category>, is enabled in the
387 Otherwise returns FALSE.
389 =item warnings::enabled($object)
391 Use the name of the class for the object reference, C<$object>, as the
394 Return TRUE if that warnings category is enabled in the first scope
395 where the object is used.
396 Otherwise returns FALSE.
398 =item warnings::warn($message)
400 Print C<$message> to STDERR.
402 Use the warnings category with the same name as the current package.
404 If that warnings category has been set to "FATAL" in the calling module
405 then die. Otherwise return.
407 =item warnings::warn($category, $message)
409 Print C<$message> to STDERR.
411 If the warnings category, C<$category>, has been set to "FATAL" in the
412 calling module then die. Otherwise return.
414 =item warnings::warn($object, $message)
416 Print C<$message> to STDERR.
418 Use the name of the class for the object reference, C<$object>, as the
421 If that warnings category has been set to "FATAL" in the scope where C<$object>
422 is first used then die. Otherwise return.
425 =item warnings::warnif($message)
429 if (warnings::enabled())
430 { warnings::warn($message) }
432 =item warnings::warnif($category, $message)
436 if (warnings::enabled($category))
437 { warnings::warn($category, $message) }
439 =item warnings::warnif($object, $message)
443 if (warnings::enabled($object))
444 { warnings::warn($object, $message) }
448 See L<perlmodlib/Pragmatic Modules> and L<perllexwarn>.
456 $All = "" ; vec($All, $Offsets{'all'}, 2) = 3 ;
462 foreach my $word (@_) {
463 if ($word eq 'FATAL') {
466 elsif ($catmask = $Bits{$word}) {
468 $mask |= $DeadBits{$word} if $fatal ;
471 { croak("unknown warnings category '$word'")}
479 my $mask = ${^WARNING_BITS} ;
480 if (vec($mask, $Offsets{'all'}, 1)) {
481 $mask |= $Bits{'all'} ;
482 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
484 ${^WARNING_BITS} = $mask | bits(@_ ? @_ : 'all') ;
489 my $mask = ${^WARNING_BITS} ;
490 if (vec($mask, $Offsets{'all'}, 1)) {
491 $mask |= $Bits{'all'} ;
492 $mask |= $DeadBits{'all'} if vec($mask, $Offsets{'all'}+1, 1);
494 ${^WARNING_BITS} = $mask & ~ (bits('FATAL' => (@_ ? @_ : 'all')) | $All) ;
504 # check the category supplied.
507 croak ("not an object")
508 if $category !~ /^([^=]+)=/ ;+
512 $offset = $Offsets{$category};
513 croak("unknown warnings category '$category'")
514 unless defined $offset;
517 $category = (caller(1))[0] ;
518 $offset = $Offsets{$category};
519 croak("package '$category' not registered for warnings")
520 unless defined $offset ;
523 my $this_pkg = (caller(1))[0] ;
528 while (do { { package DB; $pkg = (caller($i++))[0] } } ) {
529 last unless @DB::args && $DB::args[0] =~ /^$category=/ ;
534 for ($i = 2 ; $pkg = (caller($i))[0] ; ++ $i) {
535 last if $pkg ne $this_pkg ;
538 if !$pkg || $pkg eq $this_pkg ;
541 my $callers_bitmask = (caller($i))[9] ;
542 return ($callers_bitmask, $offset, $i) ;
547 croak("Usage: warnings::enabled([category])")
548 unless @_ == 1 || @_ == 0 ;
550 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
552 return 0 unless defined $callers_bitmask ;
553 return vec($callers_bitmask, $offset, 1) ||
554 vec($callers_bitmask, $Offsets{'all'}, 1) ;
560 croak("Usage: warnings::warn([category,] 'message')")
561 unless @_ == 2 || @_ == 1 ;
564 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
565 local $Carp::CarpLevel = $i ;
567 if vec($callers_bitmask, $offset+1, 1) ||
568 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;
574 croak("Usage: warnings::warnif([category,] 'message')")
575 unless @_ == 2 || @_ == 1 ;
578 my ($callers_bitmask, $offset, $i) = __chk(@_) ;
579 local $Carp::CarpLevel = $i ;
582 unless defined $callers_bitmask &&
583 (vec($callers_bitmask, $offset, 1) ||
584 vec($callers_bitmask, $Offsets{'all'}, 1)) ;
587 if vec($callers_bitmask, $offset+1, 1) ||
588 vec($callers_bitmask, $Offsets{'all'}+1, 1) ;