Hi!

While writing the HTML sample for changes.html, I've noticed one
omission, while when we start lines with test.C:1 or test.C:1:28
or similar (i.e. diagnostic_build_prefix created prefix), it is colorized
with locus color, if we start it just with test.C (filename only),
we don't.  The following patch fixes that, and attached is also
corresponding changes.html adjustment.

Ok for trunk?

2013-04-12  Jakub Jelinek  <ja...@redhat.com>

        * diagnostic.h (file_name_as_prefix): Add context argument.
        * diagnostic.c (file_name_as_prefix): Likewise.  Colorize
        the string as locus.
        * langhooks.c (lhd_print_error_function): Adjust caller.
cp/
        * error.c (cp_print_error_function): Adjust file_name_as_prefix
        caller.

--- gcc/diagnostic.h.jj 2013-04-08 15:38:20.000000000 +0200
+++ gcc/diagnostic.h    2013-04-12 11:25:53.031235252 +0200
@@ -293,6 +293,6 @@ void diagnostic_set_caret_max_width (dia
 
 
 /* Pure text formatting support functions.  */
-extern char *file_name_as_prefix (const char *);
+extern char *file_name_as_prefix (diagnostic_context *, const char *);
 
 #endif /* ! GCC_DIAGNOSTIC_H */
--- gcc/diagnostic.c.jj 2013-04-12 08:13:22.000000000 +0200
+++ gcc/diagnostic.c    2013-04-12 11:27:54.086563485 +0200
@@ -72,9 +72,12 @@ build_message_string (const char *msg, .
 
 /* Same as diagnostic_build_prefix, but only the source FILE is given.  */
 char *
-file_name_as_prefix (const char *f)
+file_name_as_prefix (diagnostic_context *context, const char *f)
 {
-  return build_message_string ("%s: ", f);
+  const char *locus_cs, *locus_ce;
+  locus_cs = colorize_start (pp_show_color (context->printer), "locus");
+  locus_ce = colorize_stop (pp_show_color (context->printer));
+  return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce);
 }
 
 
--- gcc/langhooks.c.jj  2013-04-12 08:13:22.000000000 +0200
+++ gcc/langhooks.c     2013-04-12 11:28:32.068365378 +0200
@@ -372,7 +372,7 @@ lhd_print_error_function (diagnostic_con
       const char *old_prefix = context->printer->prefix;
       tree abstract_origin = diagnostic_abstract_origin (diagnostic);
       char *new_prefix = (file && abstract_origin == NULL)
-                        ? file_name_as_prefix (file) : NULL;
+                        ? file_name_as_prefix (context, file) : NULL;
 
       pp_set_prefix (context->printer, new_prefix);
 
--- gcc/cp/error.c.jj   2013-04-12 08:13:22.000000000 +0200
+++ gcc/cp/error.c      2013-04-12 11:28:46.053286955 +0200
@@ -2948,7 +2948,7 @@ cp_print_error_function (diagnostic_cont
       const char *file = LOCATION_FILE (diagnostic->location);
       tree abstract_origin = diagnostic_abstract_origin (diagnostic);
       char *new_prefix = (file && abstract_origin == NULL)
-                        ? file_name_as_prefix (file) : NULL;
+                        ? file_name_as_prefix (context, file) : NULL;
 
       pp_base_set_prefix (context->printer, new_prefix);
 

        Jakub
--- htdocs/gcc-4.9/changes.html 2013-04-12 09:10:29.655357028 +0200
+++ htdocs/gcc-4.9/changes.html 2013-04-12 11:33:43.336660425 +0200
@@ -42,7 +42,7 @@
     Sample diagnostics output:<br/>
     <pre>
     $ g++ -fdiagnostics-color=always -S -Wall test.C
-    test.C: In function &lsquo;<b>int foo()</b>&rsquo;:
+    <b>test.C:</b> In function &lsquo;<b>int foo()</b>&rsquo;:
     <b>test.C:1:14:</b> <b style='color:magenta'>warning:</b> no return 
statement in function returning non-void [-Wreturn-type]
      int foo () { }
                   <b style='color:lime'>^</b>

Reply via email to