OSDN Git Service

Comment change.
[pf3gnuchains/gcc-fork.git] / gcc / gen-protos.c
1 /* gen-protos.c - massages a list of prototypes, for use by fixproto.
2    Copyright (C) 1993 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any
7 later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
17
18 #include <stdio.h>
19 #include <ctype.h>
20 #include "hconfig.h"
21 #include "scan.h"
22
23 #define HASH_SIZE 2503 /* a prime */
24
25 int hash_tab[HASH_SIZE];
26 int verbose = 0;
27
28 sstring linebuf;
29
30 int
31 main (argc, argv)
32      int argc;
33      char** argv;
34 {
35   FILE *inf = stdin;
36   FILE *outf = stdout;
37   int next_index = 0;
38   int i, i0;
39
40   fprintf (outf, "struct fn_decl std_protos[] = {\n");
41
42   for (;;)
43     {
44       int c = skip_spaces (inf, ' ');
45       int param_nesting = 1;
46       char *param_start, *param_end, *decl_start,
47       *name_start, *name_end;
48       register char *ptr;
49       if (c == EOF)
50         break;
51       linebuf.ptr = linebuf.base;
52       ungetc (c, inf);
53       c = read_upto (inf, &linebuf, '\n');
54       if (linebuf.base[0] == '#') /* skip cpp command */
55         continue;
56       if (linebuf.base[0] == '\0') /* skip empty line */
57         continue;
58
59       ptr = linebuf.ptr - 1;
60       while (*ptr == ' ' || *ptr == '\t') ptr--;
61       if (*ptr-- != ';')
62         {
63           fprintf (stderr, "Funny input line: %s\n", linebuf.base);
64           continue;
65         }
66       while (*ptr == ' ' || *ptr == '\t') ptr--;
67       if (*ptr != ')')
68         {
69           fprintf (stderr, "Funny input line: %s\n", linebuf.base);
70           continue;
71         }
72       param_end = ptr;
73       for (;;)
74         {
75           int c = *--ptr;
76           if (c == '(' && --param_nesting == 0)
77             break;
78           else if (c == ')')
79             param_nesting++;
80         }
81       param_start = ptr+1;
82
83       ptr--;
84       while (*ptr == ' ' || *ptr == '\t') ptr--;
85
86       if (!isalnum (*ptr))
87         {
88           if (verbose)
89             fprintf (stderr, "%s: Can't handle this complex prototype: %s\n",
90                      argv[0], linebuf.base);
91           continue;
92         }
93       name_end = ptr+1;
94
95       while (isalnum (*ptr) || *ptr == '_') --ptr;
96       name_start = ptr+1;
97       while (*ptr == ' ' || *ptr == '\t') ptr--;
98       ptr[1] = 0;
99       *name_end = 0;
100       *param_end = 0;
101       *name_end = 0;
102
103       decl_start = linebuf.base;
104       if (strncmp (decl_start, "typedef ", 8) == 0)
105         continue;
106       if (strncmp (decl_start, "extern ", 7) == 0)
107         decl_start += 7;
108
109
110       /* NOTE:  If you edit this,
111          also edit lookup_std_proto in fix-header.c !! */
112       i = hash(name_start) % HASH_SIZE;
113       i0 = i;
114       if (hash_tab[i] != 0)
115         {
116           for (;;)
117             {
118               i = (i+1) % HASH_SIZE;
119               if (i == i0)
120                 abort();
121               if (hash_tab[i] == 0)
122                 break;
123             }
124         }
125       hash_tab[i] = next_index;
126
127       fprintf (outf, "  {\"%s\", \"%s\", \"%s\" },\n",
128                name_start, decl_start, param_start, i, i0);
129
130       next_index++;
131
132       if (c == EOF)
133         break;
134     }
135   fprintf (outf, "{0, 0, 0}\n};\n");
136
137
138   fprintf (outf, "#define HASH_SIZE %d\n", HASH_SIZE);
139   fprintf (outf, "short hash_tab[HASH_SIZE] = {\n");
140   for (i = 0; i < HASH_SIZE; i++)
141     fprintf (outf, "  %d,\n", hash_tab[i]);
142   fprintf (outf, "};\n");
143
144   return 0;
145 }