diff options
author | Neil Booth <neilb@earthling.net> | 2000-11-28 21:13:35 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2000-11-28 21:13:35 +0000 |
commit | cf44ea523133ce4e91d097471bad44232c550a55 (patch) | |
tree | e48c58ce615d53fe8e02183447bad8c0843a2462 /gcc | |
parent | 74d2f859d248c7181a01a6d54bd45a27ce22ae21 (diff) | |
download | gcc-cf44ea523133ce4e91d097471bad44232c550a55.zip gcc-cf44ea523133ce4e91d097471bad44232c550a55.tar.gz gcc-cf44ea523133ce4e91d097471bad44232c550a55.tar.bz2 |
c-lex.h (parse_in): Change parse_in to a cpp_reader *.
* c-lex.h (parse_in): Change parse_in to a cpp_reader *.
* c-decl.c (c_decode_option): Update to match.
* c-lex.c (init_c_lex, yyparse): Update to match.
* c-lang.c (lang_init_options): Use cpp_create_reader.
* cppinit.c (cpp_init): Rename initialize.
(cpp_reader_init): Rename cpp_create_reader. Create the
reader. Initialize cpplib if appropriate.
* cpplib.h (cpp_create_reader) New prototype.
(cpp_init, cpp_reader_init): Delete prototypes.
* cppmain.c (general_init, setup_callbacks): New functions.
(main): Use them.
* fix-header.c (scan_in): Change type to cpp_reader *.
(read_scan_file): Update for new cpplib interface and scan_in type.
* cp/decl.c (parse_in): Change to cpp_reader *.
(lang_decode_option): Update.
* cp/lex.c (lang_init_options): Use new cpplib interface.
(init_cp_pragma, finish_parse, handle_pragma_implementation): Update.
* cp/spew.c (read_token): Update.
* objc/objc-act.c (lang_init_options): Update new cpplib interface.
From-SVN: r37826
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 23 | ||||
-rw-r--r-- | gcc/c-decl.c | 2 | ||||
-rw-r--r-- | gcc/c-lang.c | 3 | ||||
-rw-r--r-- | gcc/c-lex.c | 16 | ||||
-rw-r--r-- | gcc/c-lex.h | 2 | ||||
-rw-r--r-- | gcc/cp/decl2.c | 4 | ||||
-rw-r--r-- | gcc/cp/lex.c | 24 | ||||
-rw-r--r-- | gcc/cp/spew.c | 4 | ||||
-rw-r--r-- | gcc/cppinit.c | 68 | ||||
-rw-r--r-- | gcc/cpplib.h | 4 | ||||
-rw-r--r-- | gcc/cppmain.c | 99 | ||||
-rw-r--r-- | gcc/fix-header.c | 37 | ||||
-rw-r--r-- | gcc/objc/objc-act.c | 4 |
13 files changed, 156 insertions, 134 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 662b849..abd1692 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,26 @@ +2000-11-28 Neil Booth <neilb@earthling.net> + + * c-lex.h (parse_in): Change parse_in to a cpp_reader *. + * c-decl.c (c_decode_option): Update to match. + * c-lex.c (init_c_lex, yyparse): Update to match. + * c-lang.c (lang_init_options): Use cpp_create_reader. + * cppinit.c (cpp_init): Rename initialize. + (cpp_reader_init): Rename cpp_create_reader. Create the + reader. Initialize cpplib if appropriate. + * cpplib.h (cpp_create_reader) New prototype. + (cpp_init, cpp_reader_init): Delete prototypes. + * cppmain.c (general_init, setup_callbacks): New functions. + (main): Use them. + * fix-header.c (scan_in): Change type to cpp_reader *. + (read_scan_file): Update for new cpplib interface and scan_in type. + + * cp/decl.c (parse_in): Change to cpp_reader *. + (lang_decode_option): Update. + * cp/lex.c (lang_init_options): Use new cpplib interface. + (init_cp_pragma, finish_parse, handle_pragma_implementation): Update. + * cp/spew.c (read_token): Update. + * objc/objc-act.c (lang_init_options): Update new cpplib interface. + 2000-11-28 Jakub Jelinek <jakub@redhat.com> * loop.c (load_mems): Avoid using next_label to find end_label. If diff --git a/gcc/c-decl.c b/gcc/c-decl.c index a7a4dbf..50e557a 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -509,7 +509,7 @@ c_decode_option (argc, argv) const char *option_value = NULL; char *p = argv[0]; - strings_processed = cpp_handle_option (&parse_in, argc, argv); + strings_processed = cpp_handle_option (parse_in, argc, argv); if (!strcmp (p, "-lang-objc")) c_language = clk_objective_c; diff --git a/gcc/c-lang.c b/gcc/c-lang.c index bec4ccf..fb4dbee 100644 --- a/gcc/c-lang.c +++ b/gcc/c-lang.c @@ -52,8 +52,7 @@ lang_decode_option (argc, argv) void lang_init_options () { - cpp_init (); - cpp_reader_init (&parse_in, CLK_GNUC89); + parse_in = cpp_create_reader (CLK_GNUC89); /* Mark as "unspecified". */ flag_bounds_check = -1; diff --git a/gcc/c-lex.c b/gcc/c-lex.c index 959b103..c76d86c 100644 --- a/gcc/c-lex.c +++ b/gcc/c-lex.c @@ -122,12 +122,12 @@ init_c_lex (filename) GET_ENVIRONMENT (literal_codeset, "LANG"); #endif - parse_in.cb.ident = cb_ident; - parse_in.cb.change_file = cb_change_file; - parse_in.cb.def_pragma = cb_def_pragma; + parse_in->cb.ident = cb_ident; + parse_in->cb.change_file = cb_change_file; + parse_in->cb.def_pragma = cb_def_pragma; - /* Make sure parse_in.digraphs matches flag_digraphs. */ - CPP_OPTION (&parse_in, digraphs) = flag_digraphs; + /* Make sure parse_in->digraphs matches flag_digraphs. */ + CPP_OPTION (parse_in, digraphs) = flag_digraphs; if (filename == 0 || !strcmp (filename, "-")) filename = "stdin"; @@ -145,7 +145,7 @@ init_c_lex (filename) int yyparse() { - if (! cpp_start_read (&parse_in, orig_filename)) + if (! cpp_start_read (parse_in, orig_filename)) return 1; /* cpplib has emitted an error. */ return yyparse_1(); @@ -951,13 +951,13 @@ c_lex (value) retry: timevar_push (TV_CPP); - cpp_get_token (&parse_in, &tok); + cpp_get_token (parse_in, &tok); timevar_pop (TV_CPP); /* The C++ front end does horrible things with the current line number. To ensure an accurate line number, we must reset it every time we return a token. */ - lex_lineno = cpp_get_line (&parse_in)->line; + lex_lineno = cpp_get_line (parse_in)->line; *value = NULL_TREE; lineno = lex_lineno; diff --git a/gcc/c-lex.h b/gcc/c-lex.h index 256e509..17fdc07 100644 --- a/gcc/c-lex.h +++ b/gcc/c-lex.h @@ -35,6 +35,6 @@ extern tree is_class_name PARAMS ((tree)); extern int indent_level; struct cpp_reader; -extern struct cpp_reader parse_in; +extern struct cpp_reader* parse_in; #endif diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index c73cec3..00017aa 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -46,7 +46,7 @@ Boston, MA 02111-1307, USA. */ #include "ggc.h" #include "timevar.h" #include "cpplib.h" -extern cpp_reader parse_in; +extern cpp_reader *parse_in; /* This structure contains information about the initializations and/or destructions required for a particular priority level. */ @@ -569,7 +569,7 @@ lang_decode_option (argc, argv) int strings_processed; const char *p = argv[0]; - strings_processed = cpp_handle_option (&parse_in, argc, argv); + strings_processed = cpp_handle_option (parse_in, argc, argv); if (!strcmp (p, "-ftraditional") || !strcmp (p, "-traditional")) /* ignore */; diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 79919f9..0565704 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -79,7 +79,6 @@ static void init_operators PARAMS ((void)); #endif #include "cpplib.h" -extern cpp_reader parse_in; /* Pending language change. Positive is push count, negative is pop count. */ @@ -246,8 +245,7 @@ static const char *cplus_tree_code_name[] = { void lang_init_options () { - cpp_init (); - cpp_reader_init (&parse_in, CLK_GNUCXX); + parse_in = cpp_create_reader (CLK_GNUCXX); /* Default exceptions on. */ flag_exceptions = 1; @@ -661,16 +659,16 @@ init_reswords () static void init_cp_pragma () { - cpp_register_pragma (&parse_in, 0, "vtable", handle_pragma_vtable); - cpp_register_pragma (&parse_in, 0, "unit", handle_pragma_unit); + cpp_register_pragma (parse_in, 0, "vtable", handle_pragma_vtable); + cpp_register_pragma (parse_in, 0, "unit", handle_pragma_unit); - cpp_register_pragma (&parse_in, 0, "interface", handle_pragma_interface); - cpp_register_pragma (&parse_in, 0, "implementation", + cpp_register_pragma (parse_in, 0, "interface", handle_pragma_interface); + cpp_register_pragma (parse_in, 0, "implementation", handle_pragma_implementation); - cpp_register_pragma_space (&parse_in, "GCC"); - cpp_register_pragma (&parse_in, "GCC", "interface", handle_pragma_interface); - cpp_register_pragma (&parse_in, "GCC", "implementation", + cpp_register_pragma_space (parse_in, "GCC"); + cpp_register_pragma (parse_in, "GCC", "interface", handle_pragma_interface); + cpp_register_pragma (parse_in, "GCC", "implementation", handle_pragma_implementation); } @@ -742,8 +740,8 @@ init_parse (filename) void finish_parse () { - cpp_finish (&parse_in); - errorcount += parse_in.errors; + cpp_finish (parse_in); + errorcount += parse_in->errors; } inline void @@ -1150,7 +1148,7 @@ handle_pragma_implementation (dfile) else { main_filename = TREE_STRING_POINTER (fname); - if (cpp_included (&parse_in, main_filename)) + if (cpp_included (parse_in, main_filename)) warning ("#pragma implementation for %s appears after file is included", main_filename); } diff --git a/gcc/cp/spew.c b/gcc/cp/spew.c index 38d8bd0..3fc1469 100644 --- a/gcc/cp/spew.c +++ b/gcc/cp/spew.c @@ -323,8 +323,8 @@ read_token (t) #undef YYCODE case CPP_EOF: - cpp_pop_buffer (&parse_in); - if (CPP_BUFFER (&parse_in)) + cpp_pop_buffer (parse_in); + if (CPP_BUFFER (parse_in)) goto retry; t->yychar = 0; break; diff --git a/gcc/cppinit.c b/gcc/cppinit.c index daa8a87..39e1562 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -398,30 +398,6 @@ merge_include_chains (pfile) CPP_OPTION (pfile, bracket_include) = brack; } -/* cpp_init initializes library global state. It might not need to do - anything depending on the platform and compiler, so we have a static - flag to make sure it gets called before cpp_reader_init. */ - -static int cpp_init_completed = 0; - -void -cpp_init () -{ -#ifdef HOST_EBCDIC - /* For non-ASCII hosts, the cl_options array needs to be sorted at - runtime. */ - qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp); -#endif - - /* Set up the trigraph map and the IStable. These don't need to do - anything if we were compiled with a compiler that supports C99 - designated initializers. */ - init_trigraph_map (); - init_IStable (); - - cpp_init_completed = 1; -} - /* Sets internal flags correctly for a given language, and defines macros if necessary. */ static void @@ -516,24 +492,40 @@ set_lang (pfile, lang) } } +/* initialize initializes library global state. It might not need to + do anything depending on the platform and compiler. */ + +static int initialized = 0; + +static void +initialize () +{ +#ifdef HOST_EBCDIC + /* For non-ASCII hosts, the cl_options array needs to be sorted at + runtime. */ + qsort (cl_options, N_OPTS, sizeof (struct cl_option), opt_comp); +#endif + + /* Set up the trigraph map and the IStable. These don't need to do + anything if we were compiled with a compiler that supports C99 + designated initializers. */ + init_trigraph_map (); + init_IStable (); + + initialized = 1; +} + /* Initialize a cpp_reader structure. */ -void -cpp_reader_init (pfile, lang) - cpp_reader *pfile; +cpp_reader * +cpp_create_reader (lang) enum c_lang lang; { struct spec_nodes *s; + cpp_reader *pfile = (cpp_reader *) xcalloc (1, sizeof (cpp_reader)); - memset ((char *) pfile, 0, sizeof (cpp_reader)); - - /* If cpp_init hasn't been called, generate a fatal error (by hand) - and call it here. */ - if (!cpp_init_completed) - { - fputs ("cpp_reader_init: internal error: cpp_init not called.\n", stderr); - pfile->errors = CPP_FATAL_LIMIT; - cpp_init (); - } + /* Initialise this instance of the library if it hasn't been already. */ + if (! initialized) + initialize (); CPP_OPTION (pfile, warn_import) = 1; CPP_OPTION (pfile, discard_comments) = 1; @@ -586,6 +578,8 @@ cpp_reader_init (pfile, lang) s->n__CHAR_UNSIGNED__ = cpp_lookup (pfile, DSC("__CHAR_UNSIGNED__")); s->n__VA_ARGS__ = cpp_lookup (pfile, DSC("__VA_ARGS__")); s->n__VA_ARGS__->flags |= NODE_DIAGNOSTIC; + + return pfile; } /* Free resources used by PFILE. diff --git a/gcc/cpplib.h b/gcc/cpplib.h index b75e9ac..3732556 100644 --- a/gcc/cpplib.h +++ b/gcc/cpplib.h @@ -696,16 +696,14 @@ struct cpp_hashnode union tree_node *fe_value; /* Front end value. */ }; +extern cpp_reader *cpp_create_reader PARAMS ((enum c_lang)); extern unsigned int cpp_token_len PARAMS ((const cpp_token *)); extern unsigned char *cpp_token_as_text PARAMS ((cpp_reader *, const cpp_token *)); extern unsigned char *cpp_spell_token PARAMS ((cpp_reader *, const cpp_token *, unsigned char *)); -extern void cpp_init PARAMS ((void)); extern int cpp_handle_options PARAMS ((cpp_reader *, int, char **)); extern int cpp_handle_option PARAMS ((cpp_reader *, int, char **)); -extern void cpp_reader_init PARAMS ((cpp_reader *, enum c_lang)); - extern void cpp_register_pragma PARAMS ((cpp_reader *, const char *, const char *, void (*) PARAMS ((cpp_reader *)))); diff --git a/gcc/cppmain.c b/gcc/cppmain.c index 7a597fb..8b15f65 100644 --- a/gcc/cppmain.c +++ b/gcc/cppmain.c @@ -38,6 +38,8 @@ struct printer }; int main PARAMS ((int, char **)); +static void general_init PARAMS ((const char *)); +static void setup_callbacks PARAMS ((void)); /* General output routines. */ static void scan_buffer PARAMS ((cpp_reader *)); @@ -58,8 +60,8 @@ static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *)); static void cb_def_pragma PARAMS ((cpp_reader *)); static void do_pragma_implementation PARAMS ((cpp_reader *)); -const char *progname; -static cpp_reader parse_in; +const char *progname; /* Needs to be global. */ +static cpp_reader *pfile; static struct printer print; int @@ -67,25 +69,11 @@ main (argc, argv) int argc; char **argv; { - char *p; - cpp_reader *pfile = &parse_in; int argi = 1; /* Next argument to handle. */ - p = argv[0] + strlen (argv[0]); - while (p != argv[0] && ! IS_DIR_SEPARATOR (p[-1])) --p; - progname = p; - - xmalloc_set_program_name (progname); - -#ifdef HAVE_LC_MESSAGES - setlocale (LC_MESSAGES, ""); -#endif - (void) bindtextdomain (PACKAGE, localedir); - (void) textdomain (PACKAGE); - - cpp_init (); + general_init (argv[0]); /* Default language is GNU C89. */ - cpp_reader_init (pfile, CLK_GNUC89); + pfile = cpp_create_reader (CLK_GNUC89); argi += cpp_handle_options (pfile, argc - argi , argv + argi); if (argi < argc && ! CPP_FATAL_ERRORS (pfile)) @@ -99,30 +87,7 @@ main (argc, argv) if (printer_init (pfile)) return (FATAL_EXIT_CODE); - /* Set callbacks. */ - if (! CPP_OPTION (pfile, no_output)) - { - pfile->cb.ident = cb_ident; - pfile->cb.def_pragma = cb_def_pragma; - if (! CPP_OPTION (pfile, no_line_commands)) - pfile->cb.change_file = cb_change_file; - } - - if (CPP_OPTION (pfile, dump_includes)) - pfile->cb.include = cb_include; - - if (CPP_OPTION (pfile, debug_output) - || CPP_OPTION (pfile, dump_macros) == dump_names - || CPP_OPTION (pfile, dump_macros) == dump_definitions) - { - pfile->cb.define = cb_define; - pfile->cb.undef = cb_undef; - pfile->cb.poison = cb_def_pragma; - } - - /* Register one #pragma which needs special handling. */ - cpp_register_pragma(pfile, 0, "implementation", do_pragma_implementation); - cpp_register_pragma(pfile, "GCC", "implementation", do_pragma_implementation); + setup_callbacks (); if (! cpp_start_read (pfile, CPP_OPTION (pfile, in_fname))) return (FATAL_EXIT_CODE); @@ -148,11 +113,59 @@ main (argc, argv) if (ferror (print.outf) || fclose (print.outf)) cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); - if (parse_in.errors) + if (pfile->errors) return (FATAL_EXIT_CODE); return (SUCCESS_EXIT_CODE); } +/* Store the program name, and set the locale. */ +static void +general_init (const char *argv0) +{ + progname = argv0 + strlen (argv0); + + while (progname != argv0 && ! IS_DIR_SEPARATOR (progname[-1])) + --progname; + + xmalloc_set_program_name (progname); + +#ifdef HAVE_LC_MESSAGES + setlocale (LC_MESSAGES, ""); +#endif + (void) bindtextdomain (PACKAGE, localedir); + (void) textdomain (PACKAGE); +} + +/* Set up the callbacks and register the pragmas we handle. */ +static void +setup_callbacks () +{ + /* Set callbacks. */ + if (! CPP_OPTION (pfile, no_output)) + { + pfile->cb.ident = cb_ident; + pfile->cb.def_pragma = cb_def_pragma; + if (! CPP_OPTION (pfile, no_line_commands)) + pfile->cb.change_file = cb_change_file; + } + + if (CPP_OPTION (pfile, dump_includes)) + pfile->cb.include = cb_include; + + if (CPP_OPTION (pfile, debug_output) + || CPP_OPTION (pfile, dump_macros) == dump_names + || CPP_OPTION (pfile, dump_macros) == dump_definitions) + { + pfile->cb.define = cb_define; + pfile->cb.undef = cb_undef; + pfile->cb.poison = cb_def_pragma; + } + + /* Register one #pragma which needs special handling. */ + cpp_register_pragma(pfile, 0, "implementation", do_pragma_implementation); + cpp_register_pragma(pfile, "GCC", "implementation", do_pragma_implementation); +} + /* Writes out the preprocessed file. Alternates between two tokens, so that we can avoid accidental token pasting. */ static void diff --git a/gcc/fix-header.c b/gcc/fix-header.c index 5fb2c6a..7e030d8 100644 --- a/gcc/fix-header.c +++ b/gcc/fix-header.c @@ -612,36 +612,35 @@ read_scan_file (in_fname, argc, argv) int argc; char **argv; { - cpp_reader scan_in; + cpp_reader* scan_in; struct fn_decl *fn; int i; register struct symbol_list *cur_symbols; obstack_init (&scan_file_obstack); - cpp_init (); /* Initialize cpplib. */ - cpp_reader_init (&scan_in, CLK_GNUC89); - scan_in.cb.change_file = cb_change_file; + scan_in = cpp_create_reader (CLK_GNUC89); + scan_in->cb.change_file = cb_change_file; /* We are going to be scanning a header file out of its proper context, so ignore warnings and errors. */ - CPP_OPTION (&scan_in, inhibit_warnings) = 1; - CPP_OPTION (&scan_in, inhibit_errors) = 1; - i = cpp_handle_options (&scan_in, argc, argv); - if (i < argc && ! CPP_FATAL_ERRORS (&scan_in)) - cpp_fatal (&scan_in, "Invalid option `%s'", argv[i]); - if (CPP_FATAL_ERRORS (&scan_in)) + CPP_OPTION (scan_in, inhibit_warnings) = 1; + CPP_OPTION (scan_in, inhibit_errors) = 1; + i = cpp_handle_options (scan_in, argc, argv); + if (i < argc && ! CPP_FATAL_ERRORS (scan_in)) + cpp_fatal (scan_in, "Invalid option `%s'", argv[i]); + if (CPP_FATAL_ERRORS (scan_in)) exit (FATAL_EXIT_CODE); - if (! cpp_start_read (&scan_in, in_fname)) + if (! cpp_start_read (scan_in, in_fname)) exit (FATAL_EXIT_CODE); /* We are scanning a system header, so mark it as such. */ - cpp_make_system_header (&scan_in, CPP_BUFFER (&scan_in), 1); + cpp_make_system_header (scan_in, CPP_BUFFER (scan_in), 1); - scan_decls (&scan_in, argc, argv); + scan_decls (scan_in, argc, argv); for (cur_symbols = &symbol_table[0]; cur_symbols->names; cur_symbols++) - check_macro_names (&scan_in, cur_symbols->names); + check_macro_names (scan_in, cur_symbols->names); /* Traditionally, getc and putc are defined in terms of _filbuf and _flsbuf. If so, those functions are also required. */ @@ -650,8 +649,8 @@ read_scan_file (in_fname, argc, argv) { static const unsigned char getchar_call[] = "getchar();"; int seen_filbuf = 0; - cpp_buffer *buf = CPP_BUFFER (&scan_in); - if (cpp_push_buffer (&scan_in, getchar_call, + cpp_buffer *buf = CPP_BUFFER (scan_in); + if (cpp_push_buffer (scan_in, getchar_call, sizeof(getchar_call) - 1) == NULL) return; @@ -660,11 +659,11 @@ read_scan_file (in_fname, argc, argv) { cpp_token t; - cpp_get_token (&scan_in, &t); + cpp_get_token (scan_in, &t); if (t.type == CPP_EOF) { - cpp_pop_buffer (&scan_in); - if (CPP_BUFFER (&scan_in) == buf) + cpp_pop_buffer (scan_in); + if (CPP_BUFFER (scan_in) == buf) break; } else if (cpp_ideq (&t, "_filbuf")) diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 2eff6e7..e15ddd0 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -56,7 +56,6 @@ Boston, MA 02111-1307, USA. */ #include "toplev.h" #include "ggc.h" #include "cpplib.h" -extern cpp_reader parse_in; /* This is the default way of generating a method name. */ /* I am not sure it is really correct. @@ -695,8 +694,7 @@ generate_struct_by_value_array () void lang_init_options () { - cpp_init (); - cpp_reader_init (&parse_in, CLK_GNUC89); + parse_in = cpp_create_reader (CLK_GNUC89); } void |