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. */
25 int brace_nesting = 0;
27 /* The first extern_C_braces_length elements of extern_C_braces
28 indicate the (brace nesting levels of) left braces that were
29 prefixed by extern "C". */
30 int extern_C_braces_length = 0;
31 char extern_C_braces[20];
32 #define in_extern_C_brace (extern_C_braces_length>0)
34 /* True if the function declaration currently being scanned is
35 prefixed by extern "C". */
36 int current_extern_C = 0;
39 skip_to_closing_brace (pfile)
45 enum cpp_token token = cpp_get_token (pfile);
48 if (token == CPP_LBRACE)
50 if (token == CPP_RBRACE && --nesting == 0)
55 /* This function scans a C source file (actually, the output of cpp),
56 reading from FP. It looks for function declarations, and certain
57 other interesting sequences (external variables and macros). */
60 scan_decls (pfile, argc, argv)
65 int saw_extern, saw_inline;
67 int prev_id_start, prev_id_end;
72 CPP_SET_WRITTEN (pfile, 0);
73 token = cpp_get_token (pfile);
79 if (token == CPP_RBRACE)
81 /* Pop an 'extern "C"' nesting level, if appropriate. */
82 if (extern_C_braces_length
83 && extern_C_braces[extern_C_braces_length - 1] == brace_nesting)
84 extern_C_braces_length--;
88 if (token == CPP_LBRACE)
95 if (token == CPP_SEMICOLON)
97 if (token != CPP_NAME)
99 if (strcmp (pfile->token_buffer, "inline") == 0)
102 CPP_SET_WRITTEN (pfile, 0);
103 token = cpp_get_non_space_token (pfile);
105 if (strcmp (pfile->token_buffer, "extern") == 0)
108 CPP_SET_WRITTEN (pfile, 0);
109 token = cpp_get_non_space_token (pfile);
110 if (token == CPP_STRING
111 && strcmp (pfile->token_buffer, "\"C\"") == 0)
113 CPP_SET_WRITTEN (pfile, 0);
114 current_extern_C = 1;
115 token = cpp_get_non_space_token (pfile);
116 if (token == CPP_LPAREN)
119 extern_C_braces[extern_C_braces_length++] = brace_nesting;
122 token = cpp_get_non_space_token (pfile);
125 prev_id_start = NULL;
128 int start_written = CPP_WRITTEN (pfile);
129 token = cpp_get_token (pfile);
136 int have_arg_list = 0;
137 cpp_buffer *fbuf = cpp_file_buffer (pfile);
139 cpp_buf_line_and_col (fbuf, &func_lineno, NULL);
142 token = cpp_get_token (pfile);
143 if (token == CPP_LPAREN)
145 else if (token == CPP_RPAREN)
151 else if (token == CPP_EOF)
153 else if (token == CPP_NAME || token == CPP_3DOTS)
156 recognized_function (pfile->token_buffer + prev_id_start,
157 prev_id_end - prev_id_start,
159 : in_extern_C_brace || current_extern_C
161 pfile->token_buffer, prev_id_start,
163 fbuf->nominal_fname, func_lineno);
164 token = cpp_get_non_space_token (pfile);
165 if (token == CPP_LBRACE)
167 /* skip body of (normally) inline function */
168 skip_to_closing_brace (pfile);
171 goto handle_statement;
175 if (prev_id_start && saw_extern)
177 recognized_extern (pfile->token_buffer + prev_id_start,
178 prev_id_end - prev_id_start,
184 prev_id_start = start_written;
185 prev_id_end = CPP_WRITTEN (pfile);
189 return; /* ??? FIXME */
191 case CPP_LBRACE: case CPP_RBRACE: case CPP_DIRECTIVE:
192 goto new_statement; /* handle_statement? */
194 case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP:
198 prev_id_start = NULL;