aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-11-17 04:43:31 -0800
committerNathan Sidwell <nathan@acm.org>2020-11-17 06:10:21 -0800
commite3b55ce50ec294f30106947bd819f12a98069c57 (patch)
tree12ac4a63ac71b5a6f238c1eb10dfe7a65ceea62e
parent7f87b4ef2323769bd71f7ccea2aa6017a7376f76 (diff)
downloadgcc-e3b55ce50ec294f30106947bd819f12a98069c57.zip
gcc-e3b55ce50ec294f30106947bd819f12a98069c57.tar.gz
gcc-e3b55ce50ec294f30106947bd819f12a98069c57.tar.bz2
c-family: token streamer
This is broken out of modules patch 01-langhooks.diff, I realized that this part is independent, and removes some duplicated code -- migrated to the token_streamer class. gcc/c-family/ * c-ppoutput.c (scan_translation_unit): Use token_streamer, remove code duplicating that functionality.
-rw-r--r--gcc/c-family/c-ppoutput.c112
1 files changed, 5 insertions, 107 deletions
diff --git a/gcc/c-family/c-ppoutput.c b/gcc/c-family/c-ppoutput.c
index 44c6f30..517de15 100644
--- a/gcc/c-family/c-ppoutput.c
+++ b/gcc/c-family/c-ppoutput.c
@@ -304,120 +304,18 @@ token_streamer::stream (cpp_reader *pfile, const cpp_token *token,
static void
scan_translation_unit (cpp_reader *pfile)
{
- bool avoid_paste = false;
- bool do_line_adjustments
- = cpp_get_options (parse_in)->lang != CLK_ASM
- && !flag_no_line_commands;
- bool in_pragma = false;
- bool line_marker_emitted = false;
+ token_streamer streamer (pfile);
print.source = NULL;
for (;;)
{
- location_t loc;
- const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
-
- if (token->type == CPP_PADDING)
- {
- avoid_paste = true;
- if (print.source == NULL
- || (!(print.source->flags & PREV_WHITE)
- && token->val.source == NULL))
- print.source = token->val.source;
- continue;
- }
+ location_t spelling_loc;
+ const cpp_token *token
+ = cpp_get_token_with_location (pfile, &spelling_loc);
+ streamer.stream (pfile, token, spelling_loc);
if (token->type == CPP_EOF)
break;
-
- /* Subtle logic to output a space if and only if necessary. */
- if (avoid_paste)
- {
- int src_line = LOCATION_LINE (loc);
-
- if (print.source == NULL)
- print.source = token;
-
- if (src_line != print.src_line
- && do_line_adjustments
- && !in_pragma)
- {
- line_marker_emitted = do_line_change (pfile, token, loc, false);
- putc (' ', print.outf);
- print.printed = true;
- }
- else if (print.source->flags & PREV_WHITE
- || (print.prev
- && cpp_avoid_paste (pfile, print.prev, token))
- || (print.prev == NULL && token->type == CPP_HASH))
- {
- putc (' ', print.outf);
- print.printed = true;
- }
- }
- else if (token->flags & PREV_WHITE)
- {
- int src_line = LOCATION_LINE (loc);
-
- if (src_line != print.src_line
- && do_line_adjustments
- && !in_pragma)
- line_marker_emitted = do_line_change (pfile, token, loc, false);
- putc (' ', print.outf);
- print.printed = true;
- }
-
- avoid_paste = false;
- print.source = NULL;
- print.prev = token;
- if (token->type == CPP_PRAGMA)
- {
- const char *space;
- const char *name;
-
- line_marker_emitted = maybe_print_line (token->src_loc);
- fputs ("#pragma ", print.outf);
- c_pp_lookup_pragma (token->val.pragma, &space, &name);
- if (space)
- fprintf (print.outf, "%s %s", space, name);
- else
- fprintf (print.outf, "%s", name);
- print.printed = true;
- in_pragma = true;
- }
- else if (token->type == CPP_PRAGMA_EOL)
- {
- maybe_print_line (token->src_loc);
- in_pragma = false;
- }
- else
- {
- if (cpp_get_options (parse_in)->debug)
- linemap_dump_location (line_table, token->src_loc, print.outf);
-
- if (do_line_adjustments
- && !in_pragma
- && !line_marker_emitted
- && print.prev_was_system_token != !!in_system_header_at (loc)
- && !is_location_from_builtin_token (loc))
- /* The system-ness of this token is different from the one
- of the previous token. Let's emit a line change to
- mark the new system-ness before we emit the token. */
- {
- do_line_change (pfile, token, loc, false);
- print.prev_was_system_token = !!in_system_header_at (loc);
- }
- cpp_output_token (token, print.outf);
- line_marker_emitted = false;
- print.printed = true;
- }
-
- /* CPP_COMMENT tokens and raw-string literal tokens can
- have embedded new-line characters. Rather than enumerating
- all the possible token types just check if token uses
- val.str union member. */
- if (cpp_token_val_index (token) == CPP_TOKEN_FLD_STR)
- account_for_newlines (token->val.str.text, token->val.str.len);
}
}