[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 3/3] try to match the columns in the output of locations
From: |
Akim Demaille |
Subject: |
[PATCH 3/3] try to match the columns in the output of locations |
Date: |
Sun, 30 Jun 2019 16:41:49 +0200 |
* src/scan-code.l (indent): New.
(handle_action_dollar, handle_action_at): Use it.
* tests/synclines.at (Output columns): Check it.
---
src/scan-code.l | 24 ++++++++++++++++++------
tests/synclines.at | 9 +++++++++
2 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/src/scan-code.l b/src/scan-code.l
index 414a28a7..ead6f3b0 100644
--- a/src/scan-code.l
+++ b/src/scan-code.l
@@ -587,6 +587,22 @@ fetch_type_name (char *cp, char const **type_name,
return cp;
}
+
+/* Compilers such as GCC 9 quote and underline the source code, it is
+ important for the generated code to (try to) be consistent with the
+ columns of the input file. */
+
+static void
+indent (const location *l)
+{
+ if (!no_lines_flag)
+ obstack_printf (&obstack_for_string,
+ "\n]b4_syncline(%d, %s)dnl\n[%*s",
+ l->start.line,
+ quotearg_style (c_quoting_style, l->start.file),
+ l->end.column - 1, "");
+}
+
/*------------------------------------------------------------------.
| TEXT is pointing to a wannabee semantic value (i.e., a '$'). |
| |
@@ -698,12 +714,7 @@ handle_action_dollar (symbol_list *rule, char *text, const
location *dollar_loc)
}
break;
}
- if (!no_lines_flag)
- obstack_printf (&obstack_for_string,
- "\n]b4_syncline(%d, %s)dnl\n[%*s",
- dollar_loc->start.line,
- quotearg_style (c_quoting_style, dollar_loc->start.file),
- dollar_loc->end.column - 1, "");
+ indent (dollar_loc);
}
@@ -747,6 +758,7 @@ handle_action_at (symbol_list *rule, char *text, const
location *at_loc)
effective_rule_length, n);
break;
}
+ indent (at_loc);
}
diff --git a/tests/synclines.at b/tests/synclines.at
index f900ba44..a2d24d2a 100644
--- a/tests/synclines.at
+++ b/tests/synclines.at
@@ -532,6 +532,7 @@ AT_DATA([input.y],
%%
exp: exp '+' exp { /* --BEGIN */
$$ = $1 + $3;
+ @$ = @1 + @3;
/* --END */ }
| '0'
]])
@@ -561,6 +562,13 @@ AT_CHECK([[sed -ne '/--BEGIN/,/--END/{' \
+ (yyvsp[0].exp)
#line 19 "input.y"
;
+ (yyloc)
+#line 20 "input.y"
+ = (yylsp[-2])
+#line 20 "input.y"
+ + (yylsp[0])
+#line 20 "input.y"
+ ;
/* --END */ }
]])
@@ -583,6 +591,7 @@ AT_CHECK([[sed -ne '/--BEGIN/,/--END/{' \
/* --END */ }
{ /* --BEGIN */
(yyval.exp) = (yyvsp[-2].exp) + (yyvsp[0].exp);
+ (yyloc) = (yylsp[-2]) + (yylsp[0]);
/* --END */ }
]])
--
2.22.0