1 /* scan-decls.c - Extracts declarations from cpp output.
2 Copyright (C) 1993 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, 675 Mass Ave, Cambridge, MA 02139, USA.
18 Written by Per Bothner <bothner@cygnus.com>, July 1993. */
29 int brace_nesting = 0;
31 /* The first extern_C_braces_length elements of extern_C_braces
32 indicate the (brace nesting levels of) left braces that were
33 prefixed by extern "C". */
34 int extern_C_braces_length = 0;
35 char extern_C_braces[20];
36 #define in_extern_C_brace (extern_C_braces_length>0)
38 /* True if the function declaration currently being scanned is
39 prefixed by extern "C". */
40 int current_extern_C = 0;
43 skip_to_closing_brace (fp)
49 int c = get_token (fp, &buf);
54 if (c == '}' && --nesting == 0)
59 /* This function scans a C source file (actually, the output of cpp),
60 reading from FP. It looks for function declarations, and certain
61 other interesting sequences (external variables and macros). */
68 int saw_extern, saw_inline;
71 c = get_token (fp, &buf);
78 /* Pop an 'extern "C"' nesting level, if appropriate. */
79 if (extern_C_braces_length
80 && extern_C_braces[extern_C_braces_length - 1] == brace_nesting)
81 extern_C_braces_length--;
94 if (c != IDENTIFIER_TOKEN)
96 rtype.ptr = rtype.base;
97 if (SSTRING_LENGTH (&buf) > 16
98 && strncmp (buf.base, "__DEFINED_MACRO_", 16) == 0)
100 /* For certain interesting macro names, fixproto puts
104 into the file to be pre-processed. So if we see __DEFINED_MACRO_FOO,
105 it means FOO was defined, which we may want to make a note of. */
106 recognized_macro (buf.base+16);
109 if (strcmp (buf.base, "inline") == 0)
112 c = get_token (fp, &buf);
114 if (strcmp (buf.base, "extern") == 0)
117 c = get_token (fp, &buf);
118 if (c == STRING_TOKEN && strcmp (buf.base, "C") == 0)
120 current_extern_C = 1;
121 c = get_token (fp, &buf);
125 extern_C_braces[extern_C_braces_length++] = brace_nesting;
128 c = get_token (fp, &buf);
133 int followingc = getc (fp); /* char following token in buf */
135 MAKE_SSTRING_SPACE (&rtype, 1);
138 if (c == IDENTIFIER_TOKEN)
140 int nextc = skip_spaces (fp, followingc);
144 int func_lineno = source_lineno;
147 arg_list.ptr = arg_list.base;
164 SSTRING_PUT (&arg_list, c);
166 SSTRING_PUT (&arg_list, '\0');
167 args = arg_list.base;
170 recognized_function (buf.base,
172 : in_extern_C_brace || current_extern_C
175 source_filename.base, func_lineno);
176 c = get_token (fp, &buf);
179 /* skip body of (normally) inline function */
180 skip_to_closing_brace (fp);
183 goto handle_statement;
185 else if (nextc == ';' && saw_extern)
187 recognized_extern (buf.base, rtype.base);
193 else if (followingc != EOF)
194 ungetc (followingc, fp);
195 if (c == ';' || c == '{' || c == '}' || c == EOF)
196 goto handle_statement;
197 sstring_append (&rtype, &buf);
198 if (followingc == ' ' || followingc == '\t' || followingc == '\n')
199 SSTRING_PUT (&rtype, ' ');
200 c = get_token (fp, &buf);