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/cppmain.c | |
parent | 74d2f859d248c7181a01a6d54bd45a27ce22ae21 (diff) | |
download | gcc-cf44ea523133ce4e91d097471bad44232c550a55.tar.gz |
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/cppmain.c')
-rw-r--r-- | gcc/cppmain.c | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/gcc/cppmain.c b/gcc/cppmain.c index 7a597fbbaaf..8b15f65d0b3 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 |