From 330a968c0ad9c465993dda9f034475117039a893 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 6 Dec 2019 08:25:12 +0000 Subject: [PATCH] genmatch.c (c_expr::gen_transform): Emit newlines from line number changes rather than after every semicolon. 2019-12-06 Richard Biener * genmatch.c (c_expr::gen_transform): Emit newlines from line number changes rather than after every semicolon. From-SVN: r279034 --- gcc/ChangeLog | 5 +++++ gcc/genmatch.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3e747a620c5..e626e459c4a 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-12-06 Richard Biener + + * genmatch.c (c_expr::gen_transform): Emit newlines from line + number changes rather than after every semicolon. + 2019-12-06 Richard Biener PR tree-optimization/92819 diff --git a/gcc/genmatch.c b/gcc/genmatch.c index a822ce5ee64..4a21bc93da7 100644 --- a/gcc/genmatch.c +++ b/gcc/genmatch.c @@ -2599,10 +2599,22 @@ c_expr::gen_transform (FILE *f, int indent, const char *dest, fprintf_indent (f, indent, "%s = ", dest); unsigned stmt_nr = 1; + int prev_line = -1; for (unsigned i = 0; i < code.length (); ++i) { const cpp_token *token = &code[i]; + /* We can't recover from all lexing losses but we can roughly restore line + breaks from location info. */ + const line_map_ordinary *map; + linemap_resolve_location (line_table, token->src_loc, + LRK_SPELLING_LOCATION, &map); + expanded_location loc = linemap_expand_location (line_table, map, + token->src_loc); + if (prev_line != -1 && loc.line != prev_line) + fputc ('\n', f); + prev_line = loc.line; + /* Replace captures for code-gen. */ if (token->type == CPP_ATSIGN) { @@ -2653,11 +2665,11 @@ c_expr::gen_transform (FILE *f, int indent, const char *dest, if (token->type == CPP_SEMICOLON) { stmt_nr++; - fputc ('\n', f); if (dest && stmt_nr == nr_stmts) fprintf_indent (f, indent, "%s = ", dest); } } + fputc ('\n', f); } /* Generate transform code for a capture. */ -- 2.30.2