fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / scripts / classes.pl
blob7e77c59227ef05bbd144609fd5f269aecc2ef687
1 # classes.pl - A perl program to generate most of the contents of
2 # javaprims.h automatically.
4 # Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
6 # This file is part of libjava.
8 # This software is copyrighted work licensed under the terms of the
9 # Libjava License. Please consult the file "LIBJAVA_LICENSE" for
10 # details.
12 # Usage: cd <top-srcdir> ; perl classes.pl.
13 # Can also be run from the `include' directory; this lets us
14 # more easily insert the output into javaprims.h (which is where it goes).
16 use DirHandle;
18 if (-d 'java')
20 # Ok here.
22 elsif (-d '../java')
24 chdir ('..');
26 else
28 die "couldn't find java directory\n";
31 &scan ('java', 2);
33 exit 0;
35 sub scan
37 local ($dir, $indent) = @_;
38 local (@subdirs) = ();
39 local (%classes) = ();
41 local ($d) = new DirHandle $dir;
42 local (*JFILE);
43 local ($name);
44 if (defined $d)
46 while (defined ($name = $d->read))
48 next if $name eq 'CVS';
49 next if $name eq '.';
50 next if $name eq '..';
51 if ($dir eq 'java'
52 && $name ne 'lang'
53 && $name ne 'util'
54 && $name ne 'io')
56 # We only generate decls for java.lang, java.io, and
57 # java.util.
58 next;
60 if (-d ($dir . '/' . $name))
62 push (@subdirs, $name);
63 next;
65 next unless $name =~ /\.java$/;
67 open (FILE, "< $dir/$name");
68 local ($outer, $classname);
69 while (<FILE>)
71 s,//.*$,,;
72 # NOTE: we don't skip `/*' comments. However, we do
73 # skip lines with a `*' with leading whitespace. This
74 # catches the most important cases.
75 s,^\s*\*.*$,,;
77 # For now assume that class names start with upper
78 # case letter.
79 next unless /\b(class|interface) ([A-Z][A-Za-z0-9]+)/;
80 $classname = $2;
82 # We assume the code is properly indented, so that we
83 # can print inner classes properly.
84 if (/^\s/)
86 die "no outer class for $classname in $dir/$name"
87 unless $outer;
88 $classes{$outer . "\$" . $classname} = 1;
90 else
92 $classes{$classname} = 1;
93 $outer = $classname;
96 close (FILE);
99 undef $d;
102 local ($spaces) = ' ' x $indent;
103 local ($classname);
104 ($classname = $dir) =~ s/^.*\///;
105 print $spaces, "namespace ", $classname, "\n";
106 print $spaces, "{\n";
108 foreach (sort keys %classes)
110 print $spaces, " class ", $_, ";\n";
112 print "\n" if scalar @classes > 0 && scalar @subdirs > 0;
114 local ($first) = 1;
115 foreach (sort @subdirs)
117 print "\n" unless $first;
118 $first = 0;
119 &scan ("$dir/$_", $indent + 2);
122 print $spaces, "}\n";