summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog31
-rw-r--r--gcc/Makefile.in10
-rw-r--r--gcc/c-family/ChangeLog6
-rw-r--r--gcc/c-family/c-format.c18
-rw-r--r--gcc/common.opt24
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/error.c38
-rw-r--r--gcc/diagnostic-core.h2
-rw-r--r--gcc/diagnostic.c42
-rw-r--r--gcc/diagnostic.def26
-rw-r--r--gcc/doc/invoke.texi71
-rw-r--r--gcc/dwarf2out.c1
-rw-r--r--gcc/langhooks.c8
-rw-r--r--gcc/opts.c6
-rw-r--r--gcc/pretty-print.c46
-rw-r--r--gcc/pretty-print.h6
16 files changed, 280 insertions, 61 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c05165f9e8e..9cc89e5dcda 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,34 @@
+2013-04-12 Manuel López-Ibáñez <manu@gcc.gnu.org>
+ Jakub Jelinek <jakub@redhat.com>
+
+ * 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.
+
2013-04-12 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
* ifcvt.c (end_ifcvt_sequence): Mark a and b for unsharing as
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 37569adeabb..109f8654a0e 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1465,7 +1465,7 @@ OBJS = \
# Objects in libcommon.a, potentially used by all host binaries and with
# no target dependencies.
-OBJS-libcommon = diagnostic.o pretty-print.o intl.o input.o version.o
+OBJS-libcommon = diagnostic.o diagnostic-color.o pretty-print.o intl.o input.o version.o
# Objects in libcommon-target.a, used by drivers and by the core
# compiler and containing target-dependent code.
@@ -2668,11 +2668,12 @@ fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \
$(GIMPLE_H) realmpfr.h $(TREE_FLOW_H)
diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
version.h $(DEMANGLE_H) $(INPUT_H) intl.h $(BACKTRACE_H) $(DIAGNOSTIC_H) \
- diagnostic.def
+ diagnostic.def diagnostic-color.h
+diagnostic-color.o : diagnostic-color.c $(CONFIG_H) $(SYSTEM_H) diagnostic-color.h
opts.o : opts.c $(OPTS_H) $(OPTIONS_H) $(DIAGNOSTIC_CORE_H) $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(DUMPFILE_H) $(TM_H) \
$(DIAGNOSTIC_H) insn-attr-common.h intl.h $(COMMON_TARGET_H) \
- $(FLAGS_H) $(PARAMS_H) opts-diagnostic.h
+ $(FLAGS_H) $(PARAMS_H) opts-diagnostic.h diagnostic-color.h
opts-global.o : opts-global.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(DIAGNOSTIC_H) $(OPTS_H) $(FLAGS_H) $(GGC_H) $(TREE_H) langhooks.h \
$(TM_H) $(RTL_H) $(DBGCNT_H) debug.h $(LTO_STREAMER_H) output.h \
@@ -3434,7 +3435,8 @@ params.o : params.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(COMMON_TARGET_H) \
$(PARAMS_H) $(DIAGNOSTIC_CORE_H)
pointer-set.o: pointer-set.c pointer-set.h $(CONFIG_H) $(SYSTEM_H)
hooks.o: hooks.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(HOOKS_H)
-pretty-print.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h intl.h $(PRETTY_PRINT_H)
+pretty-print.o: $(CONFIG_H) $(SYSTEM_H) coretypes.h intl.h $(PRETTY_PRINT_H) \
+ diagnostic-color.h
errors.o : errors.c $(CONFIG_H) $(SYSTEM_H) errors.h
dbgcnt.o: dbgcnt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(DUMPFILE_H) \
$(DIAGNOSTIC_CORE_H) $(DBGCNT_H)
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index fb869da7a1a..96cf7bd1de0 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,9 @@
+2013-04-12 Jakub Jelinek <jakub@redhat.com>
+
+ * 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.
+
2013-04-07 Steven Bosscher <steven@gcc.gnu.org>
* c-pragma.c (add_to_renaming_pragma_list): Fix leading comment.
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 8f1ffedbaf7..c11d93aa89d 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -654,9 +654,10 @@ static const format_char_info gcc_diag_char_table[] =
/* Custom conversion specifiers. */
/* These will require a "tree" at runtime. */
- { "K", 0, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "", NULL },
+ { "K", 0, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "", NULL },
- { "<>'", 0, STD_C89, NOARGUMENTS, "", "", NULL },
+ { "r", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL },
+ { "<>'R",0, STD_C89, NOARGUMENTS, "", "", NULL },
{ "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
};
@@ -676,9 +677,10 @@ static const format_char_info gcc_tdiag_char_table[] =
/* These will require a "tree" at runtime. */
{ "DFKTEV", 0, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q+", "", NULL },
- { "v", 0,STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q#", "", NULL },
+ { "v", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q#", "", NULL },
- { "<>'", 0, STD_C89, NOARGUMENTS, "", "", NULL },
+ { "r", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL },
+ { "<>'R",0, STD_C89, NOARGUMENTS, "", "", NULL },
{ "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
};
@@ -698,9 +700,10 @@ static const format_char_info gcc_cdiag_char_table[] =
/* These will require a "tree" at runtime. */
{ "DEFKTV", 0, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q+", "", NULL },
- { "v", 0,STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q#", "", NULL },
+ { "v", 0, STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q#", "", NULL },
- { "<>'", 0, STD_C89, NOARGUMENTS, "", "", NULL },
+ { "r", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL },
+ { "<>'R",0, STD_C89, NOARGUMENTS, "", "", NULL },
{ "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
};
@@ -725,7 +728,8 @@ static const format_char_info gcc_cxxdiag_char_table[] =
/* These accept either an 'int' or an 'enum tree_code' (which is handled as an 'int'.) */
{ "CLOPQ",0,STD_C89, { T89_I, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q", "", NULL },
- { "<>'", 0, STD_C89, NOARGUMENTS, "", "", NULL },
+ { "r", 1, STD_C89, { T89_C, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "", "cR", NULL },
+ { "<>'R",0, STD_C89, NOARGUMENTS, "", "", NULL },
{ "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
};
diff --git a/gcc/common.opt b/gcc/common.opt
index 6b9b2e192ca..f0cb9e8075e 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1028,6 +1028,30 @@ fdiagnostics-show-caret
Common Var(flag_diagnostics_show_caret) Init(1)
Show the source line with a caret indicating the column
+fdiagnostics-color
+Common Alias(fdiagnostics-color=,always,never)
+;
+
+fdiagnostics-color=
+Common Joined RejectNegative Enum(diagnostic_color_rule)
+-fdiagnostics-color=[never|always|auto] Colorize diagnostics
+
+; Required for these enum values.
+SourceInclude
+diagnostic-color.h
+
+Enum
+Name(diagnostic_color_rule) Type(int)
+
+EnumValue
+Enum(diagnostic_color_rule) String(never) Value(DIAGNOSTICS_COLOR_NO)
+
+EnumValue
+Enum(diagnostic_color_rule) String(always) Value(DIAGNOSTICS_COLOR_YES)
+
+EnumValue
+Enum(diagnostic_color_rule) String(auto) Value(DIAGNOSTICS_COLOR_AUTO)
+
fdiagnostics-show-option
Common Var(flag_diagnostics_show_option) Init(1)
Amend appropriate diagnostic messages with the command line option that controls them
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8ebc904ca10..623760776b5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2013-04-12 Jakub Jelinek <jakub@redhat.com>
+
+ * error.c (cp_print_error_function,
+ print_instantiation_partial_context_line,
+ maybe_print_constexpr_context): Colorize locus strings.
+
2013-04-11 Jason Merrill <jason@redhat.com>
PR c++/52748
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index c599b7dbc46..300fe0c1ffc 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -3022,14 +3022,14 @@ cp_print_error_function (diagnostic_context *context,
{
if (context->show_column && s.column != 0)
pp_printf (context->printer,
- _(" inlined from %qs at %s:%d:%d"),
+ _(" inlined from %qs at %r%s:%d:%d%R"),
cxx_printable_name_translate (fndecl, 2),
- s.file, s.line, s.column);
+ "locus", s.file, s.line, s.column);
else
pp_printf (context->printer,
- _(" inlined from %qs at %s:%d"),
+ _(" inlined from %qs at %r%s:%d%R"),
cxx_printable_name_translate (fndecl, 2),
- s.file, s.line);
+ "locus", s.file, s.line);
}
else
@@ -3111,11 +3111,11 @@ print_instantiation_partial_context_line (diagnostic_context *context,
xloc = expand_location (loc);
if (context->show_column)
- pp_verbatim (context->printer, _("%s:%d:%d: "),
- xloc.file, xloc.line, xloc.column);
+ pp_verbatim (context->printer, _("%r%s:%d:%d:%R "),
+ "locus", xloc.file, xloc.line, xloc.column);
else
- pp_verbatim (context->printer, _("%s:%d: "),
- xloc.file, xloc.line);
+ pp_verbatim (context->printer, _("%r%s:%d:%R "),
+ "locus", xloc.file, xloc.line);
if (t != NULL)
{
@@ -3189,14 +3189,16 @@ print_instantiation_partial_context (diagnostic_context *context,
xloc = expand_location (loc);
if (context->show_column)
pp_verbatim (context->printer,
- _("%s:%d:%d: [ skipping %d instantiation contexts, "
- "use -ftemplate-backtrace-limit=0 to disable ]\n"),
- xloc.file, xloc.line, xloc.column, skip);
+ _("%r%s:%d:%d:%R [ skipping %d instantiation "
+ "contexts, use -ftemplate-backtrace-limit=0 to "
+ "disable ]\n"),
+ "locus", xloc.file, xloc.line, xloc.column, skip);
else
pp_verbatim (context->printer,
- _("%s:%d: [ skipping %d instantiation contexts, "
- "use -ftemplate-backtrace-limit=0 to disable ]\n"),
- xloc.file, xloc.line, skip);
+ _("%r%s:%d:%R [ skipping %d instantiation "
+ "contexts, use -ftemplate-backtrace-limit=0 to "
+ "disable ]\n"),
+ "locus", xloc.file, xloc.line, skip);
do {
loc = t->locus;
@@ -3258,12 +3260,12 @@ maybe_print_constexpr_context (diagnostic_context *context)
const char *s = expr_as_string (t, 0);
if (context->show_column)
pp_verbatim (context->printer,
- _("%s:%d:%d: in constexpr expansion of %qs"),
- xloc.file, xloc.line, xloc.column, s);
+ _("%r%s:%d:%d:%R in constexpr expansion of %qs"),
+ "locus", xloc.file, xloc.line, xloc.column, s);
else
pp_verbatim (context->printer,
- _("%s:%d: in constexpr expansion of %qs"),
- xloc.file, xloc.line, s);
+ _("%r%s:%d:%R in constexpr expansion of %qs"),
+ "locus", xloc.file, xloc.line, s);
pp_base_newline (context->printer);
}
}
diff --git a/gcc/diagnostic-core.h b/gcc/diagnostic-core.h
index 68ec837fc57..a2107820e6e 100644
--- a/gcc/diagnostic-core.h
+++ b/gcc/diagnostic-core.h
@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see
/* Constants used to discriminate diagnostics. */
typedef enum
{
-#define DEFINE_DIAGNOSTIC_KIND(K, msgid) K,
+#define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K,
#include "diagnostic.def"
#undef DEFINE_DIAGNOSTIC_KIND
DK_LAST_DIAGNOSTIC_KIND,
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);
}
diff --git a/gcc/diagnostic.def b/gcc/diagnostic.def
index 9566491ca2a..2f1e36515ad 100644
--- a/gcc/diagnostic.def
+++ b/gcc/diagnostic.def
@@ -22,26 +22,26 @@ along with GCC; see the file COPYING3. If not see
kind specified. I.e. they're uninitialized. Within the diagnostic
machinery, this kind also means "don't change the existing kind",
meaning "no change is specified". */
-DEFINE_DIAGNOSTIC_KIND (DK_UNSPECIFIED, "")
+DEFINE_DIAGNOSTIC_KIND (DK_UNSPECIFIED, "", NULL)
/* If a diagnostic is set to DK_IGNORED, it won't get reported at all.
This is used by the diagnostic machinery when it wants to disable a
diagnostic without disabling the option which causes it. */
-DEFINE_DIAGNOSTIC_KIND (DK_IGNORED, "")
+DEFINE_DIAGNOSTIC_KIND (DK_IGNORED, "", NULL)
/* The remainder are real diagnostic types. */
-DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ")
-DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ")
-DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ")
-DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ")
-DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ")
-DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ")
-DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ")
-DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ")
+DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ", "error")
+DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ", "error")
+DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ", "warning")
+DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ", "warning")
+DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ", "note")
+DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ", "note")
/* These two would be re-classified as DK_WARNING or DK_ERROR, so the
prefix does not matter. */
-DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ")
-DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ")
+DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ", NULL)
+DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ", NULL)
/* This one is just for counting DK_WARNING promoted to DK_ERROR
due to -Werror and -Werror=warning. */
-DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ")
+DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ", NULL)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 1652ebc7c22..30445ec5e0b 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -226,6 +226,7 @@ Objective-C and Objective-C++ Dialects}.
@xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
@gccoptlist{-fmessage-length=@var{n} @gol
-fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]} @gol
+-fdiagnostics-color=@r{[}auto@r{|}never@r{|}always@r{]} @gol
-fno-diagnostics-show-option -fno-diagnostics-show-caret}
@item Warning Options
@@ -2956,6 +2957,76 @@ messages reporter to emit the same source location information (as
prefix) for physical lines that result from the process of breaking
a message which is too long to fit on a single line.
+@item -fdiagnostics-color[=@var{WHEN}]
+@itemx -fno-diagnostics-color
+@opindex fdiagnostics-color
+@cindex highlight, color, colour
+@vindex GCC_COLORS @r{environment variable}
+Use color in diagnostics. @var{WHEN} is @samp{never}, @samp{always},
+or @samp{auto}. The default is @samp{never}, @samp{auto} means to use color
+only when the standard error is a terminal. The forms
+@option{-fdiagnostics-color} and @option{-fno-diagnostics-color} are
+aliases for @option{-fdiagnostics-color=always} and
+@option{-fdiagnostics-color=never}, respectively.
+
+The colors are defined by the environment variable @env{GCC_COLORS}.
+Its value is a colon-separated list of capabilities and Select Graphic
+Rendition (SGR) substrings. SGR commands are interpreted by the
+terminal or terminal emulator. (See the section in the documentation
+of your text terminal for permitted values and their meanings as
+character attributes.) These substring values are integers in decimal
+representation and can be concatenated with semicolons.
+Common values to concatenate include
+@samp{1} for bold,
+@samp{4} for underline,
+@samp{5} for blink,
+@samp{7} for inverse,
+@samp{39} for default foreground color,
+@samp{30} to @samp{37} for foreground colors,
+@samp{90} to @samp{97} for 16-color mode foreground colors,
+@samp{38;5;0} to @samp{38;5;255}
+for 88-color and 256-color modes foreground colors,
+@samp{49} for default background color,
+@samp{40} to @samp{47} for background colors,
+@samp{100} to @samp{107} for 16-color mode background colors,
+and @samp{48;5;0} to @samp{48;5;255}
+for 88-color and 256-color modes background colors.
+
+The default @env{GCC_COLORS} is
+@samp{error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01}
+where @samp{01;31} is bold red, @samp{01;35} is bold magenta,
+@samp{01;36} is bold cyan, @samp{01;32} is bold green and
+@samp{01} is bold. Setting @env{GCC_COLORS} to the empty
+string disables colors.
+Supported capabilities are as follows.
+
+@table @code
+@item error=
+@vindex error GCC_COLORS @r{capability}
+SGR substring for error: markers.
+
+@item warning=
+@vindex warning GCC_COLORS @r{capability}
+SGR substring for warning: markers.
+
+@item note=
+@vindex note GCC_COLORS @r{capability}
+SGR substring for note: markers.
+
+@item caret=
+@vindex caret GCC_COLORS @r{capability}
+SGR substring for caret line.
+
+@item locus=
+@vindex locus GCC_COLORS @r{capability}
+SGR substring for location information, @samp{file:line} or
+@samp{file:line:column} etc.
+
+@item quote=
+@vindex quote GCC_COLORS @r{capability}
+SGR substring for information printed within quotes.
+@end table
+
@item -fno-diagnostics-show-option
@opindex fno-diagnostics-show-option
@opindex fdiagnostics-show-option
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 04e1bd3e222..2475adefc05 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -18828,6 +18828,7 @@ gen_producer_string (void)
case OPT_fdiagnostics_show_location_:
case OPT_fdiagnostics_show_option:
case OPT_fdiagnostics_show_caret:
+ case OPT_fdiagnostics_color_:
case OPT_fverbose_asm:
case OPT____:
case OPT__sysroot_:
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index 3a22d6bf72e..70af8da4b30 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -452,14 +452,14 @@ lhd_print_error_function (diagnostic_context *context, const char *file,
{
if (context->show_column)
pp_printf (context->printer,
- _(" inlined from %qs at %s:%d:%d"),
+ _(" inlined from %qs at %r%s:%d:%d%R"),
identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
- s.file, s.line, s.column);
+ "locus", s.file, s.line, s.column);
else
pp_printf (context->printer,
- _(" inlined from %qs at %s:%d"),
+ _(" inlined from %qs at %r%s:%d%R"),
identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
- s.file, s.line);
+ "locus", s.file, s.line);
}
else
diff --git a/gcc/opts.c b/gcc/opts.c
index 5f0c49f554a..6856c3c8090 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see
#include "flags.h"
#include "params.h"
#include "diagnostic.h"
+#include "diagnostic-color.h"
#include "opts-diagnostic.h"
#include "insn-attr-common.h"
#include "common/common-target.h"
@@ -1497,6 +1498,11 @@ common_handle_option (struct gcc_options *opts,
dc->show_caret = value;
break;
+ case OPT_fdiagnostics_color_:
+ pp_show_color (dc->printer)
+ = colorize_init ((diagnostic_color_rule_t) value);
+ break;
+
case OPT_fdiagnostics_show_option:
dc->show_option_requested = value;
break;
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index 4c45e51ec7f..fe46464538e 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h"
#include "intl.h"
#include "pretty-print.h"
+#include "diagnostic-color.h"
#if HAVE_ICONV
#include <iconv.h>
@@ -226,6 +227,8 @@ pp_base_indent (pretty_printer *pp)
%c: character.
%s: string.
%p: pointer.
+ %r: if pp_show_color(pp), switch to color identified by const char *.
+ %R: if pp_show_color(pp), reset color.
%m: strerror(text->err_no) - does not consume a value from args_ptr.
%%: '%'.
%<: opening quote.
@@ -300,18 +303,37 @@ pp_base_format (pretty_printer *pp, text_info *text)
continue;
case '<':
- obstack_grow (&buffer->chunk_obstack,
- open_quote, strlen (open_quote));
- p++;
- continue;
+ {
+ obstack_grow (&buffer->chunk_obstack,
+ open_quote, strlen (open_quote));
+ const char *colorstr
+ = colorize_start (pp_show_color (pp), "quote");
+ obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr));
+ p++;
+ continue;
+ }
case '>':
+ {
+ const char *colorstr = colorize_stop (pp_show_color (pp));
+ obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr));
+ }
+ /* FALLTHRU */
case '\'':
obstack_grow (&buffer->chunk_obstack,
close_quote, strlen (close_quote));
p++;
continue;
+ case 'R':
+ {
+ const char *colorstr = colorize_stop (pp_show_color (pp));
+ obstack_grow (&buffer->chunk_obstack, colorstr,
+ strlen (colorstr));
+ p++;
+ continue;
+ }
+
case 'm':
{
const char *errstr = xstrerror (text->err_no);
@@ -466,10 +488,19 @@ pp_base_format (pretty_printer *pp, text_info *text)
gcc_assert (!wide || precision == 0);
if (quote)
- pp_string (pp, open_quote);
+ {
+ pp_string (pp, open_quote);
+ pp_string (pp, colorize_start (pp_show_color (pp), "quote"));
+ }
switch (*p)
{
+ case 'r':
+ pp_string (pp, colorize_start (pp_show_color (pp),
+ va_arg (*text->args_ptr,
+ const char *)));
+ break;
+
case 'c':
pp_character (pp, va_arg (*text->args_ptr, int));
break;
@@ -563,7 +594,10 @@ pp_base_format (pretty_printer *pp, text_info *text)
}
if (quote)
- pp_string (pp, close_quote);
+ {
+ pp_string (pp, colorize_stop (pp_show_color (pp)));
+ pp_string (pp, close_quote);
+ }
obstack_1grow (&buffer->chunk_obstack, '\0');
*formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *);
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index 56d2d3e8945..13bb2dede90 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -151,6 +151,9 @@ typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
output. */
#define pp_translate_identifiers(PP) pp_base (PP)->translate_identifiers
+/* True if colors should be shown. */
+#define pp_show_color(PP) pp_base (PP)->show_color
+
/* The data structure that contains the bare minimum required to do
proper pretty-printing. Clients may derived from this structure
and add additional fields they need. */
@@ -194,6 +197,9 @@ struct pretty_print_info
/* Nonzero means identifiers are translated to the locale character
set on output. */
bool translate_identifiers;
+
+ /* Nonzero means that text should be colorized. */
+ bool show_color;
};
#define pp_set_line_maximum_length(PP, L) \