Commit 620ef26c by Neil Booth Committed by Neil Booth

cppmain.c (struct printer): Remove no_line_dirs.

        * cppmain.c (struct printer): Remove no_line_dirs.
        (options, cb): New.
        (main, setup_callbacks, scan_buffer, printer_init, cb_define)
        : Use options rather than CPP_OPTION.
        (setup_callbacks): Use cb rather than pfile->cb.
        (main): No need to check for a buffer.  Use cpp_errors.
        (printer_init): Don't set no_line_dirs.
        (maybe_print_line): Use options not no_line_dirs.
        (cb_file_change): Don't call print_line if -P.

From-SVN: r38983
parent b61c5ed0
2001-01-13 Neil Booth <neil@daikokuya.demon.co.uk> 2001-01-13 Neil Booth <neil@daikokuya.demon.co.uk>
* cppmain.c (struct printer): Remove no_line_dirs.
(options, cb): New.
(main, setup_callbacks, scan_buffer, printer_init, cb_define)
: Use options rather than CPP_OPTION.
(setup_callbacks): Use cb rather than pfile->cb.
(main): No need to check for a buffer. Use cpp_errors.
(printer_init): Don't set no_line_dirs.
(maybe_print_line): Use options not no_line_dirs.
(cb_file_change): Don't call print_line if -P.
2001-01-13 Neil Booth <neil@daikokuya.demon.co.uk>
* c-lex.c (init_c_lex): Use cpp_get_callbacks to set * c-lex.c (init_c_lex): Use cpp_get_callbacks to set
callbacks. callbacks.
* c-parse.in (finish_parse): Use cpp_errors. * c-parse.in (finish_parse): Use cpp_errors.
......
...@@ -34,7 +34,6 @@ struct printer ...@@ -34,7 +34,6 @@ struct printer
const char *syshdr_flags; /* system header flags, if any. */ const char *syshdr_flags; /* system header flags, if any. */
unsigned int lineno; /* line currently being written. */ unsigned int lineno; /* line currently being written. */
unsigned char printed; /* nonzero if something output at lineno. */ unsigned char printed; /* nonzero if something output at lineno. */
unsigned char no_line_dirs; /* nonzero to output no line directives. */
}; };
int main PARAMS ((int, char **)); int main PARAMS ((int, char **));
...@@ -62,7 +61,9 @@ static void cb_def_pragma PARAMS ((cpp_reader *)); ...@@ -62,7 +61,9 @@ static void cb_def_pragma PARAMS ((cpp_reader *));
static void do_pragma_implementation PARAMS ((cpp_reader *)); static void do_pragma_implementation PARAMS ((cpp_reader *));
const char *progname; /* Needs to be global. */ const char *progname; /* Needs to be global. */
static cpp_reader *pfile; static cpp_reader *pfile; /* An opaque handle. */
static cpp_options *options; /* Options of pfile. */
static cpp_callbacks *cb; /* Callbacks of pfile. */
static struct printer print; static struct printer print;
int int
...@@ -75,6 +76,8 @@ main (argc, argv) ...@@ -75,6 +76,8 @@ main (argc, argv)
general_init (argv[0]); general_init (argv[0]);
/* Default language is GNU C89. */ /* Default language is GNU C89. */
pfile = cpp_create_reader (CLK_GNUC89); pfile = cpp_create_reader (CLK_GNUC89);
options = cpp_get_options (pfile);
cb = cpp_get_callbacks (pfile);
argi += cpp_handle_options (pfile, argc - argi , argv + argi); argi += cpp_handle_options (pfile, argc - argi , argv + argi);
if (argi < argc && ! CPP_FATAL_ERRORS (pfile)) if (argi < argc && ! CPP_FATAL_ERRORS (pfile))
...@@ -87,7 +90,7 @@ main (argc, argv) ...@@ -87,7 +90,7 @@ main (argc, argv)
line, it will have set pfile->help_only to indicate this. Exit line, it will have set pfile->help_only to indicate this. Exit
successfully. [The library does not exit itself, because successfully. [The library does not exit itself, because
e.g. cc1 needs to print its own --help message at this point.] */ e.g. cc1 needs to print its own --help message at this point.] */
if (CPP_OPTION (pfile, help_only)) if (options->help_only)
return (SUCCESS_EXIT_CODE); return (SUCCESS_EXIT_CODE);
/* Open the output now. We must do so even if no_output is on, /* Open the output now. We must do so even if no_output is on,
...@@ -98,19 +101,18 @@ main (argc, argv) ...@@ -98,19 +101,18 @@ main (argc, argv)
setup_callbacks (); setup_callbacks ();
if (! cpp_start_read (pfile, CPP_OPTION (pfile, in_fname))) if (! cpp_start_read (pfile, options->in_fname))
return (FATAL_EXIT_CODE); return (FATAL_EXIT_CODE);
if (CPP_BUFFER (pfile)) /* A successful cpp_start_read guarantees that we can call
{ cpp_scan_buffer_nooutput or cpp_get_token next. */
if (CPP_OPTION (pfile, no_output)) if (options->no_output)
cpp_scan_buffer_nooutput (pfile, 1); cpp_scan_buffer_nooutput (pfile, 1);
else else
scan_buffer (pfile); scan_buffer (pfile);
}
/* -dM command line option. */ /* -dM command line option. */
if (CPP_OPTION (pfile, dump_macros) == dump_only) if (options->dump_macros == dump_only)
cpp_forall_identifiers (pfile, dump_macro, NULL); cpp_forall_identifiers (pfile, dump_macro, NULL);
cpp_finish (pfile); cpp_finish (pfile);
...@@ -120,11 +122,12 @@ main (argc, argv) ...@@ -120,11 +122,12 @@ main (argc, argv)
if (print.printed) if (print.printed)
putc ('\n', print.outf); putc ('\n', print.outf);
if (ferror (print.outf) || fclose (print.outf)) if (ferror (print.outf) || fclose (print.outf))
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); cpp_notice_from_errno (pfile, options->out_fname);
if (pfile->errors) if (cpp_errors (pfile))
return (FATAL_EXIT_CODE); return FATAL_EXIT_CODE;
return (SUCCESS_EXIT_CODE);
return SUCCESS_EXIT_CODE;
} }
/* Store the program name, and set the locale. */ /* Store the program name, and set the locale. */
...@@ -152,28 +155,27 @@ general_init (const char *argv0) ...@@ -152,28 +155,27 @@ general_init (const char *argv0)
(void) textdomain (PACKAGE); (void) textdomain (PACKAGE);
} }
/* Set up the callbacks and register the pragmas we handle. */ /* Set up the callbacks as appropriate. */
static void static void
setup_callbacks () setup_callbacks ()
{ {
/* Set callbacks. */ if (! options->no_output)
if (! CPP_OPTION (pfile, no_output))
{ {
pfile->cb.ident = cb_ident; cb->ident = cb_ident;
pfile->cb.def_pragma = cb_def_pragma; cb->def_pragma = cb_def_pragma;
if (! CPP_OPTION (pfile, no_line_commands)) if (! options->no_line_commands)
pfile->cb.file_change = cb_file_change; cb->file_change = cb_file_change;
} }
if (CPP_OPTION (pfile, dump_includes)) if (options->dump_includes)
pfile->cb.include = cb_include; cb->include = cb_include;
if (CPP_OPTION (pfile, dump_macros) == dump_names if (options->dump_macros == dump_names
|| CPP_OPTION (pfile, dump_macros) == dump_definitions) || options->dump_macros == dump_definitions)
{ {
pfile->cb.define = cb_define; cb->define = cb_define;
pfile->cb.undef = cb_undef; cb->undef = cb_undef;
pfile->cb.poison = cb_def_pragma; cb->poison = cb_def_pragma;
} }
/* Register one #pragma which needs special handling. */ /* Register one #pragma which needs special handling. */
...@@ -220,7 +222,7 @@ scan_buffer (pfile) ...@@ -220,7 +222,7 @@ scan_buffer (pfile)
} }
else if (print.printed else if (print.printed
&& ! (token->flags & PREV_WHITE) && ! (token->flags & PREV_WHITE)
&& CPP_OPTION (pfile, lang) != CLK_ASM && options->lang != CLK_ASM
&& cpp_avoid_paste (pfile, &tokens[1 - index], token)) && cpp_avoid_paste (pfile, &tokens[1 - index], token))
token->flags |= PREV_WHITE; token->flags |= PREV_WHITE;
...@@ -255,19 +257,18 @@ printer_init (pfile) ...@@ -255,19 +257,18 @@ printer_init (pfile)
print.last_fname = 0; print.last_fname = 0;
print.lineno = 0; print.lineno = 0;
print.printed = 0; print.printed = 0;
print.no_line_dirs = CPP_OPTION (pfile, no_line_commands);
if (CPP_OPTION (pfile, out_fname) == NULL) if (options->out_fname == NULL)
CPP_OPTION (pfile, out_fname) = ""; options->out_fname = "";
if (CPP_OPTION (pfile, out_fname)[0] == '\0') if (options->out_fname[0] == '\0')
print.outf = stdout; print.outf = stdout;
else else
{ {
print.outf = fopen (CPP_OPTION (pfile, out_fname), "w"); print.outf = fopen (options->out_fname, "w");
if (! print.outf) if (! print.outf)
{ {
cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); cpp_notice_from_errno (pfile, options-> out_fname);
return 1; return 1;
} }
} }
...@@ -290,7 +291,7 @@ maybe_print_line (line) ...@@ -290,7 +291,7 @@ maybe_print_line (line)
print.printed = 0; print.printed = 0;
} }
if (print.no_line_dirs) if (options->no_line_commands)
{ {
print.lineno = line; print.lineno = line;
return; return;
...@@ -348,7 +349,7 @@ cb_define (pfile, node) ...@@ -348,7 +349,7 @@ cb_define (pfile, node)
fprintf (print.outf, "#define %s", node->name); fprintf (print.outf, "#define %s", node->name);
/* -dD command line option. */ /* -dD command line option. */
if (CPP_OPTION (pfile, dump_macros) == dump_definitions) if (options->dump_macros == dump_definitions)
fputs ((const char *) cpp_macro_definition (pfile, node), print.outf); fputs ((const char *) cpp_macro_definition (pfile, node), print.outf);
putc ('\n', print.outf); putc ('\n', print.outf);
...@@ -402,7 +403,9 @@ cb_file_change (pfile, fc) ...@@ -402,7 +403,9 @@ cb_file_change (pfile, fc)
flags = " 1"; flags = " 1";
else if (fc->reason == FC_LEAVE) else if (fc->reason == FC_LEAVE)
flags = " 2"; flags = " 2";
print_line (flags);
if (! options->no_line_commands)
print_line (flags);
} }
} }
...@@ -448,7 +451,7 @@ do_pragma_implementation (pfile) ...@@ -448,7 +451,7 @@ do_pragma_implementation (pfile)
/* Output? This is nasty, but we don't have [GCC] implementation in /* Output? This is nasty, but we don't have [GCC] implementation in
the buffer. */ the buffer. */
if (pfile->cb.def_pragma) if (cb->def_pragma)
{ {
maybe_print_line (cpp_get_line (pfile)->output_line); maybe_print_line (cpp_get_line (pfile)->output_line);
fputs ("#pragma GCC implementation ", print.outf); fputs ("#pragma GCC implementation ", print.outf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment