Пример #1
0
/* Preprocess and output.  */
void
preprocess_file (cpp_reader *pfile)
{
  /* A successful cpp_read_main_file guarantees that we can call
     cpp_scan_nooutput or cpp_get_token next.  */
  if (flag_no_output && pfile->buffer)
    {
      /* Scan -included buffers, then the main file.  */
      while (pfile->buffer->prev)
	cpp_scan_nooutput (pfile);
      cpp_scan_nooutput (pfile);
    }
  else if (cpp_get_options (pfile)->traditional)
    scan_translation_unit_trad (pfile);
  else if (cpp_get_options (pfile)->directives_only
	   && !cpp_get_options (pfile)->preprocessed)
    scan_translation_unit_directives_only (pfile);
  else
    scan_translation_unit (pfile);

  /* -dM command line option.  Should this be elsewhere?  */
  if (flag_dump_macros == 'M')
    cpp_forall_identifiers (pfile, dump_macro, NULL);

  /* Flush any pending output.  */
  if (print.printed)
    putc ('\n', print.outf);
}
Пример #2
0
/* This is called at the end of preprocessing.  It pops the last
   buffer and writes dependency output.

   Maybe it should also reset state, such that you could call
   cpp_start_read with a new filename to restart processing.  */
void
cpp_finish (cpp_reader *pfile, FILE *deps_stream)
{
    /* Warn about unused macros before popping the final buffer.  */
    if (CPP_OPTION (pfile, warn_unused_macros))
        cpp_forall_identifiers (pfile, _cpp_warn_if_unused_macro, NULL);

    /* lex.c leaves the final buffer on the stack.  This it so that
       it returns an unending stream of CPP_EOFs to the client.  If we
       popped the buffer, we'd dereference a NULL buffer pointer and
       segfault.  It's nice to allow the client to do worry-free excess
       cpp_get_token calls.  */
    while (pfile->buffer)
        _cpp_pop_buffer (pfile);

    if (CPP_OPTION (pfile, deps.style) != DEPS_NONE
            && deps_stream)
    {
        deps_write (pfile->deps, deps_stream, 72);

        if (CPP_OPTION (pfile, deps.phony_targets))
            deps_phony_targets (pfile->deps, deps_stream);
    }

    /* Report on headers that could use multiple include guards.  */
    if (CPP_OPTION (pfile, print_include_names))
        _cpp_report_missing_guards (pfile);
}