diff options
author | Zack Weinberg <zack@wolery.cumb.org> | 2000-04-14 23:29:45 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-04-14 23:29:45 +0000 |
commit | f2d5f0cca244fc70acb45fbe557bd22411175f1b (patch) | |
tree | c91bee0467728e26a3ab2b06fce2d27db8e99983 /gcc/cppinit.c | |
parent | 362c63a5e8b5aacfff3e5af0911e42ba7c775042 (diff) | |
download | gcc-f2d5f0cca244fc70acb45fbe557bd22411175f1b.zip gcc-f2d5f0cca244fc70acb45fbe557bd22411175f1b.tar.gz gcc-f2d5f0cca244fc70acb45fbe557bd22411175f1b.tar.bz2 |
cpplex.c (cpp_output_tokens, [...]): New public interfaces.
* cpplex.c (cpp_output_tokens, cpp_scan_buffer_nooutput): New public
interfaces.
(safe_fwrite, output_line_command): New static functions.
(cpp_expand_to_buffer): Now private to cpplib.
(cpp_scan_buffer): Take a printer.
* cpphash.h: Update prototypes.
* cpplib.h: Update prototypes.
(cpp_printer): New.
(cpp_buffer): Remove last_nominal_fname.
(cpp_reader): Remove lineno.
* cppmain.c: Use a cpp_printer.
* fix-header.c: No need to inhibit line commands. Call
cpp_start_read with no printer.
* cpperror.c (cpp_notice_from_errno): Provide default name.
* cppfiles.c (make_IHASH, _cpp_fake_ihash): New functions.
(find_include_file, cpp_read_file): Use make_IHASH.
(file_cleanup): Set control_macro and clear
input_stack_listing_current here.
(_cpp_execute_include): Don't output entering-file marker.
* cpphash.c (special_symbol): Look for the line number in the
buffer, not the reader.
(_cpp_macroexpand): No need to disable line commands.
(_cpp_dump_definition): No need to generate line commands.
(dump_hash_helper): Remove excess newline from output.
* cppinit.c (dump_special_to_buffer): No need to generate line
commands.
(cpp_printer_init): New.
(cpp_start_read): Take a printer, and start it up if it's not
NULL. No need to generate line commands.
(cpp_finish): Expect no buffers stacked at all. Take a
printer argument, and flush the output buffer if it's not
NULL.
* cpplex.c (_cpp_lex_token): Return EOF if there's no buffer.
Don't put two hashes at the beginning of an assertion.
(cpp_get_token): Don't increment pfile->lineno or emit line
commands here. Return EOF if there's no buffer when we get
EOF.
* cpplib.c (do_define, skip_if_group):
No need to disable line commands.
(_cpp_output_line_command): Delete function.
(do_line): Don't emit line commands here, but set things up so
they will be emitted if necessary. Use _cpp_fake_ihash to
make unique nominal_fnames if necessary.
(do_elif, do_else, _cpp_handle_eof): Call cpp_error_with_line
with 0 for column, not -1.
(_cpp_handle_eof): Don't set the control macro here. Don't
clear input_stack_listing_current here. Don't emit line
commands.
From-SVN: r33159
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 84 |
1 files changed, 59 insertions, 25 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 32293f6..5174da8 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -521,12 +521,11 @@ dump_special_to_buffer (pfile, macro_name) { static const char define_directive[] = "#define "; int macro_name_length = strlen (macro_name); - _cpp_output_line_command (pfile, same_file); CPP_RESERVE (pfile, sizeof(define_directive) + macro_name_length); CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1); CPP_PUTS_Q (pfile, macro_name, macro_name_length); CPP_PUTC_Q (pfile, ' '); - cpp_expand_to_buffer (pfile, macro_name, macro_name_length); + _cpp_expand_to_buffer (pfile, macro_name, macro_name_length); CPP_PUTC (pfile, '\n'); } @@ -554,6 +553,31 @@ cpp_reader_init (pfile) _cpp_init_include_hash (pfile); } +/* Initialize a cpp_printer structure. As a side effect, open the + output file. */ +cpp_printer * +cpp_printer_init (pfile, print) + cpp_reader *pfile; + cpp_printer *print; +{ + memset (print, '\0', sizeof (cpp_printer)); + if (CPP_OPTION (pfile, out_fname) == NULL) + CPP_OPTION (pfile, out_fname) = ""; + + if (CPP_OPTION (pfile, out_fname)[0] == '\0') + print->outf = stdout; + else + { + print->outf = fopen (CPP_OPTION (pfile, out_fname), "w"); + if (! print->outf) + { + cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); + return NULL; + } + } + return print; +} + /* Free resources used by PFILE. This is the cpp_reader 'finalizer' or 'destructor' (in C++ terminology). */ void @@ -829,8 +853,9 @@ initialize_standard_includes (pfile) */ int -cpp_start_read (pfile, fname) +cpp_start_read (pfile, print, fname) cpp_reader *pfile; + cpp_printer *print; const char *fname; { struct pending_option *p, *q; @@ -915,6 +940,14 @@ cpp_start_read (pfile, fname) CPP_BUFFER (pfile)->lineno = 0; + if (print) + { + print->lineno = 0; + print->last_fname = CPP_BUFFER (pfile)->nominal_fname; + print->last_bsd = pfile->buffer_stack_depth; + print->written = CPP_WRITTEN (pfile); + } + /* Install __LINE__, etc. */ initialize_builtins (pfile); @@ -927,42 +960,32 @@ cpp_start_read (pfile, fname) free (p); p = q; } - pfile->done_initializing = 1; - CPP_BUFFER (pfile)->lineno = 1; - - if (CPP_OPTION (pfile, preprocessed)) - /* If we've already processed this code, we want to trust the #line - directives in the input. But we still need to update our line - counter accordingly. */ - pfile->lineno = CPP_BUFFER (pfile)->lineno; - else - _cpp_output_line_command (pfile, same_file); pfile->only_seen_white = 2; + CPP_BUFFER (pfile)->lineno = 1; + if (print && ! CPP_OPTION (pfile, no_output)) + cpp_output_tokens (pfile, print); /* The -imacros files can be scanned now, but the -include files have to be pushed onto the include stack and processed later, in the main loop calling cpp_get_token. */ - CPP_OPTION (pfile, no_output)++; p = CPP_OPTION (pfile, pending)->imacros_head; while (p) { if (cpp_read_file (pfile, p->arg)) - cpp_scan_buffer (pfile); - + cpp_scan_buffer_nooutput (pfile); q = p->next; free (p); p = q; } - CPP_OPTION (pfile, no_output)--; p = CPP_OPTION (pfile, pending)->include_head; while (p) { - if (cpp_read_file (pfile, p->arg)) - _cpp_output_line_command (pfile, enter_file); - + if (cpp_read_file (pfile, p->arg) + && print && ! CPP_OPTION (pfile, no_output)) + cpp_output_tokens (pfile, print); q = p->next; free (p); p = q; @@ -979,13 +1002,16 @@ cpp_start_read (pfile, fname) clear macro definitions, such that you could call cpp_start_read with a new filename to restart processing. */ void -cpp_finish (pfile) +cpp_finish (pfile, print) cpp_reader *pfile; + cpp_printer *print; { - if (CPP_PREV_BUFFER (CPP_BUFFER (pfile))) - cpp_ice (pfile, "buffers still stacked in cpp_finish"); - while (CPP_BUFFER (pfile)) - cpp_pop_buffer (pfile); + if (CPP_BUFFER (pfile)) + { + cpp_ice (pfile, "buffers still stacked in cpp_finish"); + while (CPP_BUFFER (pfile)) + cpp_pop_buffer (pfile); + } /* Don't write the deps file if preprocessing has failed. */ if (CPP_OPTION (pfile, print_deps) && pfile->errors == 0) @@ -1015,6 +1041,14 @@ cpp_finish (pfile) if (CPP_OPTION (pfile, dump_macros) == dump_only) _cpp_dump_macro_hash (pfile); + + /* Flush any pending output. */ + if (print) + { + cpp_output_tokens (pfile, print); + if (ferror (print->outf) || fclose (print->outf)) + cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); + } } static void |