diff options
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 |