1993-07-25 20:11:20 -04:00
|
|
|
/* scan-decls.c - Extracts declarations from cpp output.
|
1999-01-18 01:17:31 -05:00
|
|
|
Copyright (C) 1993, 1995, 97-98, 1999 Free Software Foundation, Inc.
|
1993-07-25 20:11:20 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
1995-06-15 08:05:01 -04:00
|
|
|
Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1993-07-25 20:11:20 -04:00
|
|
|
|
1993-10-12 19:01:18 -04:00
|
|
|
Written by Per Bothner <bothner@cygnus.com>, July 1993. */
|
1993-07-25 20:11:20 -04:00
|
|
|
|
1993-10-26 21:53:30 -04:00
|
|
|
#include "hconfig.h"
|
More cutover to system.h:
* Makefile.in (cppalloc.o, cpperror.o, cppexp.o, cpphash.o,
cpplib.o, cppmain.o, fix-header.o, gcov.o, gen-protos.o,
gengenrtl.o, halfpic.o, hash.o, scan-decls.o, scan.o): Depend on
system.h.
* cpphash.c: Include config.h.
* cppalloc.c: Include system.h. Add parameters to various
function prototypes.
* cpperror.c: Likewise.
* cppexp.c: Likewise.
* cpphash.c: Likewise.
* cpplib.c: Likewise.
* cppmain.c: Likewise.
* fix-header.c: Likewise.
* gcov.c: Likewise.
* gen-protos.c: Likewise.
* gengenrtl.c: Likewise.
* halfpic.c: Likewise.
* hash.c: Likewise.
* scan-decls.c: Likewise.
* scan.c: Likewise.
From-SVN: r18911
1998-03-30 07:05:54 -05:00
|
|
|
#include "system.h"
|
1995-04-05 17:16:26 -04:00
|
|
|
#include "cpplib.h"
|
Warning fixes:
* Makefile.in (c-lang.o): Depend on c-tree.h, c-lex.h and toplev.h.
(c-lex.o): Depend on output.h.
(c-common.o): Likewise.
(stmt.o): Likewise.
(calls.o): Likewise.
(integrate.o): Depend on toplev.h.
(regclass.o): Depend on output.h.
(final.o): Depend on reload.h.
* c-common.c: Include output.h.
(check_format_info): Remove unused variable `integral_format'.
* c-decl.c (print_lang_decl): Mark parameters `file', `node' and
`indent' with ATTRIBUTE_UNUSED.
(print_lang_type): Likewise.
(maybe_build_cleanup): Likewise for parameter `decl'.
(copy_lang_decl): Likewise for parameter `node'.
* c-lang.c: Include c-tree.h, c-lex.h and toplev.h.
(lang_print_xnode): Mark parameters `file', `node' and `indent'
with ATTRIBUTE_UNUSED.
(lookup_interface): Likewise for parameter `arg'.
(is_class_name): Likewise.
(maybe_objc_check_decl): Likewise for parameter `decl'.
(maybe_objc_comptypes): Likewise for parameters `lhs', `rhs' and
`reflexive'.
(maybe_objc_method_name): Likewise for parameter `decl'.
(build_objc_string): Likewise for parameters `len' and `str'.
* c-lex.c: Include output.h.
* c-lex.h (position_after_white_space): Correct typo in prototype.
* c-tree.h (finish_file, c_expand_start_cond, c_expand_start_else,
c_expand_end_cond, init_iterators): Add prototypes.
* caller-save.c (set_reg_live): Mark parameters `reg' and `setter'
with ATTRIBUTE_UNUSED.
* calls.c: Include output.h.
* cccp.c (pipe_closed): Mark parameter `signo' with
ATTRIBUTE_UNUSED.
* combine.c: Move inclusion of expr.h to after insn-config.h.
* iris6.h (ASM_IDENTIFY_GCC, ASM_IDENTIFY_LANGUAGE): Don't define
as empty, rather define as ((void)0).
* sparc.c (sparc_check_64): Add braces around ambiguous `else'.
Add parentheses around assignment used as truth value.
* cplus-dem.c (squangle_mop_up): Change return type to void.
(internal_cplus_demangle): Remove unused parameter `options'.
All callers changed.
(cplus_demangle_opname): Remove function wide variable `int i' and
replace with `size_t i' at each location where it is used.
(cplus_demangle_opname): change type of `i' from int to size_t.
* cppexp.c (right_shift): Mark parameter `pfile' with
ATTRIBUTE_UNUSED.
* cpphash.c (cpp_lookup): Likewise.
(cpp_hash_cleanup): Likewise.
* cpplib.c (parse_name): Add a prototype and make it static.
(null_underflow): Mark parameter `pfile' with ATTRIBUTE_UNUSED.
(null_cleanup): Likewise for parameters `pbuf' and `pfile'.
(macro_cleanup): Likewise for parameter `pfile'.
(file_cleanup): Likewise.
* cpplib.h (cpp_reader_init, cpp_options_init, cpp_start_read,
cpp_read_check_assertion, skip_rest_of_line): Add prototypes.
* crtstuff.c (force_to_data, __CTOR_LIST__, force_to_data,
__DTOR_END__, __FRAME_END__): Mark with ATTRIBUTE_UNUSED.
* cse.c (cse_check_loop_start): Mark parameter `set' with
ATTRIBUTE_UNUSED.
* dbxout.c (flag_minimal_debug, have_used_extensions,
source_label_number): Move inside macro wrapper check against
defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO).
* dwarf2out.c (gen_entry_point_die): Hide prototype and definition.
* except.h (doing_eh): Provide prototype.
* expr.c: Move inclusion of expr.h to after insn-config.h.
* final.c: Include reload.h.
(shorten_branches): Cast the first argument of bzero to char *.
* fix-header.c (cpp_print_containing_files): Mark parameter
`pfile' with ATTRIBUTE_UNUSED.
(cpp_fatal): Likewise.
* flow.c (find_basic_blocks_1): Cast the first argument of bzero
to char *.
* genattrtab.c (make_length_attrs): Change the type of variable
`i' from int to size_t.
(zero_fn): Mark parameter `exp' with ATTRIBUTE_UNUSED.
(one_fn): Likewise.
* genextract.c (main): When generating insn-extract.c, mark
variable `junk' with ATTRIBUTE_UNUSED.
* gengenrtl.c (gencode): When generating genrtl.c, cast the first
argument of bzero to char*.
* integrate.c: Include toplev.h.
* libgcc2.c: Wrap `struct exception_table' and
`find_exception_handler' in macro DWARF2_UNWIND_INFO.
* objc/Make-lang.in (objc-act.o): Depend on toplev.h.
* objc/objc-act.c: Include toplev.h.
(lang_print_xnode): Mark parameters `file', `node' and `indent'
with ATTRIBUTE_UNUSED.
(finish_protocol): Likewise for parameter `protocol'.
* output.h (declare_weak): Add prototype.
(decode_reg_name): Don't wrap with TREE_CODE macro.
(assemble_alias): Add prototype.
* regclass.c: Include output.h.
* reload.h (reloads_conflict): Add prototype.
* rtl.h (print_rtl_single, mark_elimiation, reg_class_subset_p,
output_func_start_profiler): Add prototypes.
* rtlanal.c (reg_set_p_1): Mark parameters `x' and `pat' with
ATTRIBUTE_UNUSED.
* scan-decls.c: Include scan.h.
* scan.h (recognized_function, recognized_extern): Add prototypes.
* stmt.c: Include output.h.
* toplev.c (error_for_asm, warning_for_asm): Remove prototypes.
(output_lang_identify): Hide prototype and definition.
(float_signal): Mark parameter `signo' with ATTRIBUTE_UNUSED.
(pipe_closed): Likewise.
* toplev.h (count_error, strip_off_ending, error_for_asm,
warning_for_asm): Add prototypes.
From-SVN: r19712
1998-05-13 08:40:39 -04:00
|
|
|
#include "scan.h"
|
1993-07-25 20:11:20 -04:00
|
|
|
|
|
|
|
int brace_nesting = 0;
|
|
|
|
|
|
|
|
/* The first extern_C_braces_length elements of extern_C_braces
|
|
|
|
indicate the (brace nesting levels of) left braces that were
|
1993-10-25 22:56:57 -04:00
|
|
|
prefixed by extern "C". */
|
1993-07-25 20:11:20 -04:00
|
|
|
int extern_C_braces_length = 0;
|
|
|
|
char extern_C_braces[20];
|
|
|
|
#define in_extern_C_brace (extern_C_braces_length>0)
|
|
|
|
|
|
|
|
/* True if the function declaration currently being scanned is
|
1993-10-25 22:56:57 -04:00
|
|
|
prefixed by extern "C". */
|
1993-07-25 20:11:20 -04:00
|
|
|
int current_extern_C = 0;
|
|
|
|
|
1993-08-09 21:59:37 -04:00
|
|
|
static void
|
1995-04-05 17:16:26 -04:00
|
|
|
skip_to_closing_brace (pfile)
|
|
|
|
cpp_reader *pfile;
|
1993-08-09 21:59:37 -04:00
|
|
|
{
|
|
|
|
int nesting = 1;
|
|
|
|
for (;;)
|
|
|
|
{
|
1995-04-05 17:16:26 -04:00
|
|
|
enum cpp_token token = cpp_get_token (pfile);
|
|
|
|
if (token == CPP_EOF)
|
1993-08-09 21:59:37 -04:00
|
|
|
break;
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token == CPP_LBRACE)
|
1993-08-09 21:59:37 -04:00
|
|
|
nesting++;
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token == CPP_RBRACE && --nesting == 0)
|
1993-08-09 21:59:37 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1993-10-12 19:01:18 -04:00
|
|
|
/* This function scans a C source file (actually, the output of cpp),
|
1995-06-09 17:28:52 -04:00
|
|
|
reading from FP. It looks for function declarations, and
|
|
|
|
external variable declarations.
|
|
|
|
|
|
|
|
The following grammar (as well as some extra stuff) is recognized:
|
|
|
|
|
|
|
|
declaration:
|
|
|
|
(decl-specifier)* declarator ("," declarator)* ";"
|
|
|
|
decl-specifier:
|
|
|
|
identifier
|
|
|
|
keyword
|
|
|
|
extern "C"
|
|
|
|
declarator:
|
|
|
|
(ptr-operator)* dname [ "(" argument-declaration-list ")" ]
|
|
|
|
ptr-operator:
|
|
|
|
("*" | "&") ("const" | "volatile")*
|
|
|
|
dname:
|
|
|
|
identifier
|
|
|
|
|
|
|
|
Here dname is the actual name being declared.
|
|
|
|
*/
|
1993-10-12 19:01:18 -04:00
|
|
|
|
1993-07-25 20:11:20 -04:00
|
|
|
int
|
1995-04-05 17:16:26 -04:00
|
|
|
scan_decls (pfile, argc, argv)
|
|
|
|
cpp_reader *pfile;
|
1998-12-23 02:09:01 -05:00
|
|
|
int argc ATTRIBUTE_UNUSED;
|
|
|
|
char **argv ATTRIBUTE_UNUSED;
|
1993-07-25 20:11:20 -04:00
|
|
|
{
|
1993-08-09 21:59:37 -04:00
|
|
|
int saw_extern, saw_inline;
|
1997-12-20 06:31:54 -05:00
|
|
|
int start_written;
|
1995-06-09 17:28:52 -04:00
|
|
|
/* If declarator_start is non-zero, it marks the start of the current
|
|
|
|
declarator. If it is zero, we are either still parsing the
|
1996-07-03 18:07:53 -04:00
|
|
|
decl-specs, or prev_id_start marks the start of the declarator. */
|
1995-06-09 17:28:52 -04:00
|
|
|
int declarator_start;
|
1995-04-05 17:16:26 -04:00
|
|
|
int prev_id_start, prev_id_end;
|
|
|
|
enum cpp_token token;
|
|
|
|
|
1993-07-25 20:11:20 -04:00
|
|
|
new_statement:
|
1995-04-05 17:16:26 -04:00
|
|
|
CPP_SET_WRITTEN (pfile, 0);
|
1997-12-20 06:31:54 -05:00
|
|
|
start_written = 0;
|
1995-04-05 17:16:26 -04:00
|
|
|
token = cpp_get_token (pfile);
|
|
|
|
|
1993-07-25 20:11:20 -04:00
|
|
|
handle_statement:
|
|
|
|
current_extern_C = 0;
|
|
|
|
saw_extern = 0;
|
1993-08-09 21:59:37 -04:00
|
|
|
saw_inline = 0;
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token == CPP_RBRACE)
|
1993-07-25 20:11:20 -04:00
|
|
|
{
|
1993-10-25 22:56:57 -04:00
|
|
|
/* Pop an 'extern "C"' nesting level, if appropriate. */
|
1993-07-25 20:11:20 -04:00
|
|
|
if (extern_C_braces_length
|
|
|
|
&& extern_C_braces[extern_C_braces_length - 1] == brace_nesting)
|
|
|
|
extern_C_braces_length--;
|
|
|
|
brace_nesting--;
|
|
|
|
goto new_statement;
|
|
|
|
}
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token == CPP_LBRACE)
|
1993-07-25 20:11:20 -04:00
|
|
|
{
|
|
|
|
brace_nesting++;
|
|
|
|
goto new_statement;
|
|
|
|
}
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token == CPP_EOF)
|
1993-07-25 20:11:20 -04:00
|
|
|
return 0;
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token == CPP_SEMICOLON)
|
1993-07-25 20:11:20 -04:00
|
|
|
goto new_statement;
|
1995-04-05 17:16:26 -04:00
|
|
|
if (token != CPP_NAME)
|
1993-07-25 20:11:20 -04:00
|
|
|
goto new_statement;
|
1995-06-09 17:28:52 -04:00
|
|
|
|
|
|
|
prev_id_start = 0;
|
|
|
|
declarator_start = 0;
|
1993-07-25 20:11:20 -04:00
|
|
|
for (;;)
|
|
|
|
{
|
1995-04-05 17:16:26 -04:00
|
|
|
switch (token)
|
1993-07-25 20:11:20 -04:00
|
|
|
{
|
1995-04-05 17:16:26 -04:00
|
|
|
case CPP_LPAREN:
|
1996-07-03 18:07:53 -04:00
|
|
|
/* Looks like this is the start of a formal parameter list. */
|
1995-04-05 17:16:26 -04:00
|
|
|
if (prev_id_start)
|
1993-07-25 20:11:20 -04:00
|
|
|
{
|
|
|
|
int nesting = 1;
|
1995-04-05 17:16:26 -04:00
|
|
|
int have_arg_list = 0;
|
|
|
|
cpp_buffer *fbuf = cpp_file_buffer (pfile);
|
|
|
|
long func_lineno;
|
|
|
|
cpp_buf_line_and_col (fbuf, &func_lineno, NULL);
|
1993-07-25 20:11:20 -04:00
|
|
|
for (;;)
|
|
|
|
{
|
1995-04-05 17:16:26 -04:00
|
|
|
token = cpp_get_token (pfile);
|
|
|
|
if (token == CPP_LPAREN)
|
1993-07-25 20:11:20 -04:00
|
|
|
nesting++;
|
1995-04-05 17:16:26 -04:00
|
|
|
else if (token == CPP_RPAREN)
|
1993-10-25 22:56:57 -04:00
|
|
|
{
|
1995-04-05 17:16:26 -04:00
|
|
|
nesting--;
|
|
|
|
if (nesting == 0)
|
|
|
|
break;
|
1993-10-25 22:56:57 -04:00
|
|
|
}
|
1995-04-05 17:16:26 -04:00
|
|
|
else if (token == CPP_EOF)
|
|
|
|
break;
|
|
|
|
else if (token == CPP_NAME || token == CPP_3DOTS)
|
|
|
|
have_arg_list = 1;
|
1993-07-25 20:11:20 -04:00
|
|
|
}
|
1995-04-05 17:16:26 -04:00
|
|
|
recognized_function (pfile->token_buffer + prev_id_start,
|
|
|
|
prev_id_end - prev_id_start,
|
1993-10-25 22:56:57 -04:00
|
|
|
(saw_inline ? 'I'
|
|
|
|
: in_extern_C_brace || current_extern_C
|
|
|
|
? 'F' : 'f'),
|
1995-04-05 17:16:26 -04:00
|
|
|
pfile->token_buffer, prev_id_start,
|
|
|
|
have_arg_list,
|
|
|
|
fbuf->nominal_fname, func_lineno);
|
|
|
|
token = cpp_get_non_space_token (pfile);
|
|
|
|
if (token == CPP_LBRACE)
|
1993-08-09 21:59:37 -04:00
|
|
|
{
|
|
|
|
/* skip body of (normally) inline function */
|
1995-04-05 17:16:26 -04:00
|
|
|
skip_to_closing_brace (pfile);
|
1993-08-09 21:59:37 -04:00
|
|
|
goto new_statement;
|
|
|
|
}
|
1995-06-09 17:28:52 -04:00
|
|
|
goto maybe_handle_comma;
|
1993-07-25 20:11:20 -04:00
|
|
|
}
|
1995-04-05 17:16:26 -04:00
|
|
|
break;
|
1995-06-09 17:28:52 -04:00
|
|
|
case CPP_OTHER:
|
1998-12-23 02:09:01 -05:00
|
|
|
if (CPP_WRITTEN (pfile) == (size_t) start_written + 1
|
1995-06-09 17:28:52 -04:00
|
|
|
&& (CPP_PWRITTEN (pfile)[-1] == '*'
|
|
|
|
|| CPP_PWRITTEN (pfile)[-1] == '&'))
|
|
|
|
declarator_start = start_written;
|
|
|
|
else
|
|
|
|
goto handle_statement;
|
|
|
|
break;
|
|
|
|
case CPP_COMMA:
|
1995-04-05 17:16:26 -04:00
|
|
|
case CPP_SEMICOLON:
|
|
|
|
if (prev_id_start && saw_extern)
|
1993-07-25 20:11:20 -04:00
|
|
|
{
|
1995-04-05 17:16:26 -04:00
|
|
|
recognized_extern (pfile->token_buffer + prev_id_start,
|
|
|
|
prev_id_end - prev_id_start,
|
|
|
|
pfile->token_buffer,
|
|
|
|
prev_id_start);
|
1993-07-25 20:11:20 -04:00
|
|
|
}
|
1996-07-03 18:07:53 -04:00
|
|
|
/* ... fall through ... */
|
1995-06-09 17:28:52 -04:00
|
|
|
maybe_handle_comma:
|
|
|
|
if (token != CPP_COMMA)
|
|
|
|
goto new_statement;
|
1999-01-18 01:17:31 -05:00
|
|
|
#if 0
|
1995-06-09 17:28:52 -04:00
|
|
|
handle_comma:
|
1999-01-18 01:17:31 -05:00
|
|
|
#endif
|
1995-06-09 17:28:52 -04:00
|
|
|
/* Handle multiple declarators in a single declaration,
|
|
|
|
as in: extern char *strcpy (), *strcat (), ... ; */
|
|
|
|
if (declarator_start == 0)
|
|
|
|
declarator_start = prev_id_start;
|
|
|
|
CPP_SET_WRITTEN (pfile, declarator_start);
|
|
|
|
break;
|
1995-04-05 17:16:26 -04:00
|
|
|
case CPP_NAME:
|
1995-06-09 17:28:52 -04:00
|
|
|
/* "inline" and "extern" are recognized but skipped */
|
|
|
|
if (strcmp (pfile->token_buffer, "inline") == 0)
|
|
|
|
{
|
|
|
|
saw_inline = 1;
|
|
|
|
CPP_SET_WRITTEN (pfile, start_written);
|
|
|
|
}
|
|
|
|
if (strcmp (pfile->token_buffer, "extern") == 0)
|
|
|
|
{
|
|
|
|
saw_extern = 1;
|
|
|
|
CPP_SET_WRITTEN (pfile, start_written);
|
|
|
|
token = cpp_get_non_space_token (pfile);
|
|
|
|
if (token == CPP_STRING
|
|
|
|
&& strcmp (pfile->token_buffer, "\"C\"") == 0)
|
|
|
|
{
|
|
|
|
CPP_SET_WRITTEN (pfile, start_written);
|
|
|
|
current_extern_C = 1;
|
|
|
|
token = cpp_get_non_space_token (pfile);
|
|
|
|
if (token == CPP_LBRACE)
|
|
|
|
{
|
|
|
|
brace_nesting++;
|
|
|
|
extern_C_braces[extern_C_braces_length++]
|
|
|
|
= brace_nesting;
|
|
|
|
goto new_statement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
1997-12-20 06:31:54 -05:00
|
|
|
continue;
|
1995-06-09 17:28:52 -04:00
|
|
|
break;
|
|
|
|
}
|
1996-07-03 18:07:53 -04:00
|
|
|
/* This may be the name of a variable or function. */
|
1995-04-05 17:16:26 -04:00
|
|
|
prev_id_start = start_written;
|
|
|
|
prev_id_end = CPP_WRITTEN (pfile);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CPP_EOF:
|
1997-12-20 06:31:54 -05:00
|
|
|
return 0;
|
1995-04-05 17:16:26 -04:00
|
|
|
|
|
|
|
case CPP_LBRACE: case CPP_RBRACE: case CPP_DIRECTIVE:
|
|
|
|
goto new_statement; /* handle_statement? */
|
|
|
|
|
|
|
|
case CPP_HSPACE: case CPP_VSPACE: case CPP_COMMENT: case CPP_POP:
|
1996-07-03 18:07:53 -04:00
|
|
|
/* Skip initial white space. */
|
1995-06-09 17:28:52 -04:00
|
|
|
if (start_written == 0)
|
|
|
|
CPP_SET_WRITTEN (pfile, 0);
|
1995-04-05 17:16:26 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1995-06-19 14:19:07 -04:00
|
|
|
prev_id_start = 0;
|
1993-07-25 20:11:20 -04:00
|
|
|
}
|
1997-12-20 06:31:54 -05:00
|
|
|
|
|
|
|
start_written = CPP_WRITTEN (pfile);
|
|
|
|
token = cpp_get_token (pfile);
|
1993-07-25 20:11:20 -04:00
|
|
|
}
|
|
|
|
}
|