diff mbox series

[09/32] core diagnostics

Message ID 1fbe900e-a07d-1aa6-32f1-a36ab5b66715@acm.org
State New
Headers show
Series C++ 20 Modules | expand

Commit Message

Nathan Sidwell Nov. 3, 2020, 9:14 p.m. UTC
The 'included from ...' chain that one gets at the start of a diagnostic 
needs extending to include importing.  There are a few combinations to 
handle, but nothing particularly exciting.

Comments

Jeff Law Nov. 21, 2020, 4:57 p.m. UTC | #1
On 11/3/20 2:14 PM, Nathan Sidwell wrote:
> The 'included from ...' chain that one gets at the start of a
> diagnostic needs extending to include importing.  There are a few
> combinations to handle, but nothing particularly exciting.
>
>
> 09-core-diag.diff
>
OK with a ChangeLog
jeff
diff mbox series

Patch

diff --git c/gcc/diagnostic.c w/gcc/diagnostic.c
index 1b6c9845892..52bf5e0da1f 100644
--- c/gcc/diagnostic.c
+++ w/gcc/diagnostic.c
@@ -689,12 +705,13 @@  diagnostic_report_current_module (diagnostic_context *context, location_t where)
       set_last_module (context, map);
       if (! MAIN_FILE_P (map))
 	{
-	  bool first = true;
+	  bool first = true, need_inc = true, was_module = MAP_MODULE_P (map);
 	  expanded_location s = {};
 	  do
 	    {
 	      where = linemap_included_from (map);
 	      map = linemap_included_from_linemap (line_table, map);
+	      bool is_module = MAP_MODULE_P (map);
 	      s.file = LINEMAP_FILE (map);
 	      s.line = SOURCE_LINE (map, where);
 	      int col = -1;
@@ -706,14 +723,24 @@  diagnostic_report_current_module (diagnostic_context *context, location_t where)
 	      const char *line_col = maybe_line_and_column (s.line, col);
 	      static const char *const msgs[] =
 		{
-		 N_("In file included from"),
+		 NULL,
 		 N_("                 from"),
+		 N_("In file included from"),	/* 2 */
+		 N_("        included from"),
+		 N_("In module"),		/* 4 */
+		 N_("of module"),
+		 N_("In module imported at"),	/* 6 */
+		 N_("imported at"),
 		};
-	      unsigned index = !first;
+
+	      unsigned index = (was_module ? 6 : is_module ? 4
+				: need_inc ? 2 : 0) + !first;
+
 	      pp_verbatim (context->printer, "%s%s %r%s%s%R",
-			   first ? "" : ",\n", _(msgs[index]),
+			   first ? "" : was_module ? ", " : ",\n",
+			   _(msgs[index]),
 			   "locus", s.file, line_col);
-	      first = false;
+	      first = false, need_inc = was_module, was_module = is_module;
 	    }
 	  while (! MAIN_FILE_P (map));
 	  pp_verbatim (context->printer, ":");