summaryrefslogtreecommitdiff
path: root/gcc/diagnostic.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2013-04-12 06:19:58 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2013-04-12 06:19:58 +0000
commit41609f8bc12a3e7feeaf7749a03f880e5b3c2819 (patch)
tree6c0949bd9c81eb35e9a104c1b13c71602bef3a0c /gcc/diagnostic.c
parent79f85ed59b356e24986dda057360c8782a652e69 (diff)
downloadgcc-41609f8bc12a3e7feeaf7749a03f880e5b3c2819.tar.gz
* opts.c: Include diagnostic-color.h.
(common_handle_option): Handle OPT_fdiagnostics_color_. * Makefile.in (OBJS-libcommon): Add diagnostic-color.o. (diagnostic.o, opts.o, pretty-print.o): Depend on diagnostic-color.h. (diagnostic-color.o): New. * common.opt (fdiagnostics-color, fdiagnostics-color=): New options. (diagnostic_color_rule): New enum. * dwarf2out.c (gen_producer_string): Don't print -fdiagnostics-color*. * langhooks.c (lhd_print_error_function): Add %r "locus" and %R around the location string. * diagnostic.def: Add 3rd argument to DEFINE_DIAGNOSTIC_KIND macros, either NULL, or color kind. * diagnostic-color.c: New file. * diagnostic-color.h: New file. * diagnostic-core.h (DEFINE_DIAGNOSTIC_KIND): Adjust macro for 3 arguments. * doc/invoke.texi (-fdiagnostics-color): Document. * pretty-print.h (pp_show_color): Define. (struct pretty_print_info): Add show_color field. * diagnostic.c: Include diagnostic-color.h. (diagnostic_build_prefix): Adjust for 3 argument DEFINE_DIAGNOSTIC_KIND macros. Colorize error:, warning: etc. strings and also the location string. (diagnostic_show_locus): Colorize the caret line. * pretty-print.c: Include diagnostic-color.h. (pp_base_format): Handle %r and %R format specifiers. Colorize strings inside of %< %> quotes or quoted through q format modifier. c-family/ * c-format.c (gcc_diag_char_table, gcc_tdiag_char_table, gcc_cdiag_char_table, gcc_cxxdiag_char_table): Add %r and %R format specifiers. cp/ * error.c (cp_print_error_function, print_instantiation_partial_context_line, maybe_print_constexpr_context): Colorize locus strings. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@197841 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/diagnostic.c')
-rw-r--r--gcc/diagnostic.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 87eb8dc40ab..e454cf31af2 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "intl.h"
#include "backtrace.h"
#include "diagnostic.h"
+#include "diagnostic-color.h"
#define pedantic_warning_kind(DC) \
((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
@@ -53,7 +54,6 @@ const char *progname;
/* A diagnostic_context surrogate for stderr. */
static diagnostic_context global_diagnostic_context;
diagnostic_context *global_dc = &global_diagnostic_context;
-
/* Return a malloc'd string containing MSG formatted a la printf. The
caller is responsible for freeing the memory. */
@@ -210,12 +210,31 @@ diagnostic_build_prefix (diagnostic_context *context,
const diagnostic_info *diagnostic)
{
static const char *const diagnostic_kind_text[] = {
-#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
+#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
#include "diagnostic.def"
#undef DEFINE_DIAGNOSTIC_KIND
"must-not-happen"
};
+ static const char *const diagnostic_kind_color[] = {
+#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
+#include "diagnostic.def"
+#undef DEFINE_DIAGNOSTIC_KIND
+ NULL
+ };
const char *text = _(diagnostic_kind_text[diagnostic->kind]);
+ const char *text_cs = "", *text_ce = "";
+ const char *locus_cs, *locus_ce;
+ pretty_printer *pp = context->printer;
+
+ if (diagnostic_kind_color[diagnostic->kind])
+ {
+ text_cs = colorize_start (pp_show_color (pp),
+ diagnostic_kind_color[diagnostic->kind]);
+ text_ce = colorize_stop (pp_show_color (pp));
+ }
+ locus_cs = colorize_start (pp_show_color (pp), "locus");
+ locus_ce = colorize_stop (pp_show_color (pp));
+
expanded_location s = expand_location_to_spelling_point (diagnostic->location);
if (diagnostic->override_column)
s.column = diagnostic->override_column;
@@ -223,10 +242,13 @@ diagnostic_build_prefix (diagnostic_context *context,
return
(s.file == NULL
- ? build_message_string ("%s: %s", progname, text)
+ ? build_message_string ("%s%s:%s %s%s%s", locus_cs, progname, locus_ce,
+ text_cs, text, text_ce)
: context->show_column
- ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
- : build_message_string ("%s:%d: %s", s.file, s.line, text));
+ ? build_message_string ("%s%s:%d:%d:%s %s%s%s", locus_cs, s.file, s.line,
+ s.column, locus_ce, text_cs, text, text_ce)
+ : build_message_string ("%s%s:%d:%s %s%s%s", locus_cs, s.file, s.line, locus_ce,
+ text_cs, text, text_ce));
}
/* If LINE is longer than MAX_WIDTH, and COLUMN is not smaller than
@@ -262,7 +284,7 @@ diagnostic_show_locus (diagnostic_context * context,
expanded_location s;
int max_width;
const char *saved_prefix;
-
+ const char *caret_cs, *caret_ce;
if (!context->show_caret
|| diagnostic->location <= BUILTINS_LOCATION
@@ -290,9 +312,13 @@ diagnostic_show_locus (diagnostic_context * context,
line++;
}
pp_newline (context->printer);
+ caret_cs = colorize_start (pp_show_color (context->printer), "caret");
+ caret_ce = colorize_stop (pp_show_color (context->printer));
+
/* pp_printf does not implement %*c. */
- buffer = XALLOCAVEC (char, s.column + 3);
- snprintf (buffer, s.column + 3, " %*c", s.column, '^');
+ size_t len = s.column + 3 + strlen (caret_cs) + strlen (caret_ce);
+ buffer = XALLOCAVEC (char, len);
+ snprintf (buffer, len, "%s %*c%s", caret_cs, s.column, '^', caret_ce);
pp_string (context->printer, buffer);
pp_set_prefix (context->printer, saved_prefix);
}