]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gen-protos.c
2bec04c4db86685e15d876218cb4951fa62d658a
1 /* gen-protos.c - massages a list of prototypes, for use by fixproto.
2 Copyright (C) 1993, 94-96, 1998 Free Software Foundation, Inc.
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
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.
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #define HASH_SIZE 2503 /* a prime */
28 int hash_tab
[HASH_SIZE
];
32 hashf (name
, len
, hashsize
)
33 register U_CHAR
*name
;
40 r
= HASHSTEP (r
, *name
++);
42 return MAKE_POS (r
) % hashsize
;
51 /* NOTE: If you edit this, also edit lookup_std_proto in fix-header.c !! */
52 i
= hashf (fname
, strlen (fname
), HASH_SIZE
);
58 i
= (i
+1) % HASH_SIZE
;
65 hash_tab
[i
] = next_index
;
70 /* Given a function prototype, fill in the fields of FN.
71 The result is a boolean indicating if a function prototype was found.
73 The input string is modified (trailing NULs are inserted).
74 The fields of FN point to the input string. */
77 parse_fn_proto (start
, end
, fn
)
82 int param_nesting
= 1;
83 char *param_start
, *param_end
, *decl_start
, *name_start
, *name_end
;
86 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
89 fprintf (stderr
, "Funny input line: %s\n", start
);
92 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
95 fprintf (stderr
, "Funny input line: %s\n", start
);
102 if (c
== '(' && --param_nesting
== 0)
110 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
115 fprintf (stderr
, "%s: Can't handle this complex prototype: %s\n",
121 while (isalnum (*ptr
) || *ptr
== '_') --ptr
;
123 while (*ptr
== ' ' || *ptr
== '\t') ptr
--;
129 if (strncmp (decl_start
, "typedef ", 8) == 0)
131 if (strncmp (decl_start
, "extern ", 7) == 0)
134 fn
->fname
= name_start
;
135 fn
->rtype
= decl_start
;
136 fn
->params
= param_start
;
149 struct fn_decl fn_decl
;
151 i
= strlen (argv
[0]);
152 while (i
> 0 && argv
[0][i
-1] != '/') --i
;
153 progname
= &argv
[0][i
];
155 INIT_SSTRING (&linebuf
);
157 fprintf (outf
, "struct fn_decl std_protos[] = {\n");
159 /* A hash table entry of 0 means "unused" so reserve it. */
160 fprintf (outf
, " {\"\", \"\", \"\"},\n");
165 int c
= skip_spaces (inf
, ' ');
169 linebuf
.ptr
= linebuf
.base
;
171 c
= read_upto (inf
, &linebuf
, '\n');
172 if (linebuf
.base
[0] == '#') /* skip cpp command */
174 if (linebuf
.base
[0] == '\0') /* skip empty line */
177 if (! parse_fn_proto (linebuf
.base
, linebuf
.ptr
, &fn_decl
))
180 add_hash (fn_decl
.fname
);
182 fprintf (outf
, " {\"%s\", \"%s\", \"%s\"},\n",
183 fn_decl
.fname
, fn_decl
.rtype
, fn_decl
.params
);
188 fprintf (outf
, " {0, 0, 0}\n};\n");
191 fprintf (outf
, "#define HASH_SIZE %d\n", HASH_SIZE
);
192 fprintf (outf
, "short hash_tab[HASH_SIZE] = {\n");
193 for (i
= 0; i
< HASH_SIZE
; i
++)
194 fprintf (outf
, " %d,\n", hash_tab
[i
]);
195 fprintf (outf
, "};\n");
200 /* Avoid error if config defines abort as fancy_abort.
201 It's not worth "really" implementing this because ordinary
202 compiler users never run fix-header. */
214 fprintf (stderr
, "%s: %s\n", "gen-protos", s
);
215 exit (FATAL_EXIT_CODE
);