Commit 4b84d650 by Jakub Jelinek

opts.c: Include diagnostic-color.h.

	* 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.

From-SVN: r197841
parent 067a1e71
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> 2013-04-12 Andreas Krebbel <Andreas.Krebbel@de.ibm.com>
* ifcvt.c (end_ifcvt_sequence): Mark a and b for unsharing as * ifcvt.c (end_ifcvt_sequence): Mark a and b for unsharing as
......
...@@ -1465,7 +1465,7 @@ OBJS = \ ...@@ -1465,7 +1465,7 @@ OBJS = \
# Objects in libcommon.a, potentially used by all host binaries and with # Objects in libcommon.a, potentially used by all host binaries and with
# no target dependencies. # 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 # Objects in libcommon-target.a, used by drivers and by the core
# compiler and containing target-dependent code. # compiler and containing target-dependent code.
...@@ -2668,11 +2668,12 @@ fold-const.o : fold-const.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ ...@@ -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) $(GIMPLE_H) realmpfr.h $(TREE_FLOW_H)
diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \ diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
version.h $(DEMANGLE_H) $(INPUT_H) intl.h $(BACKTRACE_H) $(DIAGNOSTIC_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) \ opts.o : opts.c $(OPTS_H) $(OPTIONS_H) $(DIAGNOSTIC_CORE_H) $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(DUMPFILE_H) $(TM_H) \ coretypes.h $(DUMPFILE_H) $(TM_H) \
$(DIAGNOSTIC_H) insn-attr-common.h intl.h $(COMMON_TARGET_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 \ opts-global.o : opts-global.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
$(DIAGNOSTIC_H) $(OPTS_H) $(FLAGS_H) $(GGC_H) $(TREE_H) langhooks.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 \ $(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) \ ...@@ -3434,7 +3435,8 @@ params.o : params.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(COMMON_TARGET_H) \
$(PARAMS_H) $(DIAGNOSTIC_CORE_H) $(PARAMS_H) $(DIAGNOSTIC_CORE_H)
pointer-set.o: pointer-set.c pointer-set.h $(CONFIG_H) $(SYSTEM_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) 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 errors.o : errors.c $(CONFIG_H) $(SYSTEM_H) errors.h
dbgcnt.o: dbgcnt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(DUMPFILE_H) \ dbgcnt.o: dbgcnt.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(DUMPFILE_H) \
$(DIAGNOSTIC_CORE_H) $(DBGCNT_H) $(DIAGNOSTIC_CORE_H) $(DBGCNT_H)
......
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> 2013-04-07 Steven Bosscher <steven@gcc.gnu.org>
* c-pragma.c (add_to_renaming_pragma_list): Fix leading comment. * c-pragma.c (add_to_renaming_pragma_list): Fix leading comment.
......
...@@ -654,9 +654,10 @@ static const format_char_info gcc_diag_char_table[] = ...@@ -654,9 +654,10 @@ static const format_char_info gcc_diag_char_table[] =
/* Custom conversion specifiers. */ /* Custom conversion specifiers. */
/* These will require a "tree" at runtime. */ /* 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 }, { "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
}; };
...@@ -676,9 +677,10 @@ static const format_char_info gcc_tdiag_char_table[] = ...@@ -676,9 +677,10 @@ static const format_char_info gcc_tdiag_char_table[] =
/* These will require a "tree" at runtime. */ /* These will require a "tree" at runtime. */
{ "DFKTEV", 0, STD_C89, { T89_V, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN, BADLEN }, "q+", "", NULL }, { "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 }, { "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
}; };
...@@ -698,9 +700,10 @@ static const format_char_info gcc_cdiag_char_table[] = ...@@ -698,9 +700,10 @@ static const format_char_info gcc_cdiag_char_table[] =
/* These will require a "tree" at runtime. */ /* 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 }, { "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 }, { "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
}; };
...@@ -725,7 +728,8 @@ static const format_char_info gcc_cxxdiag_char_table[] = ...@@ -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'.) */ /* 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 }, { "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 }, { "m", 0, STD_C89, NOARGUMENTS, "q", "", NULL },
{ NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL } { NULL, 0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
}; };
......
...@@ -1028,6 +1028,30 @@ fdiagnostics-show-caret ...@@ -1028,6 +1028,30 @@ fdiagnostics-show-caret
Common Var(flag_diagnostics_show_caret) Init(1) Common Var(flag_diagnostics_show_caret) Init(1)
Show the source line with a caret indicating the column 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 fdiagnostics-show-option
Common Var(flag_diagnostics_show_option) Init(1) Common Var(flag_diagnostics_show_option) Init(1)
Amend appropriate diagnostic messages with the command line option that controls them Amend appropriate diagnostic messages with the command line option that controls them
......
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> 2013-04-11 Jason Merrill <jason@redhat.com>
PR c++/52748 PR c++/52748
......
...@@ -3022,14 +3022,14 @@ cp_print_error_function (diagnostic_context *context, ...@@ -3022,14 +3022,14 @@ cp_print_error_function (diagnostic_context *context,
{ {
if (context->show_column && s.column != 0) if (context->show_column && s.column != 0)
pp_printf (context->printer, 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), cxx_printable_name_translate (fndecl, 2),
s.file, s.line, s.column); "locus", s.file, s.line, s.column);
else else
pp_printf (context->printer, pp_printf (context->printer,
_(" inlined from %qs at %s:%d"), _(" inlined from %qs at %r%s:%d%R"),
cxx_printable_name_translate (fndecl, 2), cxx_printable_name_translate (fndecl, 2),
s.file, s.line); "locus", s.file, s.line);
} }
else else
...@@ -3111,11 +3111,11 @@ print_instantiation_partial_context_line (diagnostic_context *context, ...@@ -3111,11 +3111,11 @@ print_instantiation_partial_context_line (diagnostic_context *context,
xloc = expand_location (loc); xloc = expand_location (loc);
if (context->show_column) if (context->show_column)
pp_verbatim (context->printer, _("%s:%d:%d: "), pp_verbatim (context->printer, _("%r%s:%d:%d:%R "),
xloc.file, xloc.line, xloc.column); "locus", xloc.file, xloc.line, xloc.column);
else else
pp_verbatim (context->printer, _("%s:%d: "), pp_verbatim (context->printer, _("%r%s:%d:%R "),
xloc.file, xloc.line); "locus", xloc.file, xloc.line);
if (t != NULL) if (t != NULL)
{ {
...@@ -3189,14 +3189,16 @@ print_instantiation_partial_context (diagnostic_context *context, ...@@ -3189,14 +3189,16 @@ print_instantiation_partial_context (diagnostic_context *context,
xloc = expand_location (loc); xloc = expand_location (loc);
if (context->show_column) if (context->show_column)
pp_verbatim (context->printer, pp_verbatim (context->printer,
_("%s:%d:%d: [ skipping %d instantiation contexts, " _("%r%s:%d:%d:%R [ skipping %d instantiation "
"use -ftemplate-backtrace-limit=0 to disable ]\n"), "contexts, use -ftemplate-backtrace-limit=0 to "
xloc.file, xloc.line, xloc.column, skip); "disable ]\n"),
"locus", xloc.file, xloc.line, xloc.column, skip);
else else
pp_verbatim (context->printer, pp_verbatim (context->printer,
_("%s:%d: [ skipping %d instantiation contexts, " _("%r%s:%d:%R [ skipping %d instantiation "
"use -ftemplate-backtrace-limit=0 to disable ]\n"), "contexts, use -ftemplate-backtrace-limit=0 to "
xloc.file, xloc.line, skip); "disable ]\n"),
"locus", xloc.file, xloc.line, skip);
do { do {
loc = t->locus; loc = t->locus;
...@@ -3258,12 +3260,12 @@ maybe_print_constexpr_context (diagnostic_context *context) ...@@ -3258,12 +3260,12 @@ maybe_print_constexpr_context (diagnostic_context *context)
const char *s = expr_as_string (t, 0); const char *s = expr_as_string (t, 0);
if (context->show_column) if (context->show_column)
pp_verbatim (context->printer, pp_verbatim (context->printer,
_("%s:%d:%d: in constexpr expansion of %qs"), _("%r%s:%d:%d:%R in constexpr expansion of %qs"),
xloc.file, xloc.line, xloc.column, s); "locus", xloc.file, xloc.line, xloc.column, s);
else else
pp_verbatim (context->printer, pp_verbatim (context->printer,
_("%s:%d: in constexpr expansion of %qs"), _("%r%s:%d:%R in constexpr expansion of %qs"),
xloc.file, xloc.line, s); "locus", xloc.file, xloc.line, s);
pp_base_newline (context->printer); pp_base_newline (context->printer);
} }
} }
......
...@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -28,7 +28,7 @@ along with GCC; see the file COPYING3. If not see
/* Constants used to discriminate diagnostics. */ /* Constants used to discriminate diagnostics. */
typedef enum typedef enum
{ {
#define DEFINE_DIAGNOSTIC_KIND(K, msgid) K, #define DEFINE_DIAGNOSTIC_KIND(K, msgid, C) K,
#include "diagnostic.def" #include "diagnostic.def"
#undef DEFINE_DIAGNOSTIC_KIND #undef DEFINE_DIAGNOSTIC_KIND
DK_LAST_DIAGNOSTIC_KIND, DK_LAST_DIAGNOSTIC_KIND,
......
...@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -31,6 +31,7 @@ along with GCC; see the file COPYING3. If not see
#include "intl.h" #include "intl.h"
#include "backtrace.h" #include "backtrace.h"
#include "diagnostic.h" #include "diagnostic.h"
#include "diagnostic-color.h"
#define pedantic_warning_kind(DC) \ #define pedantic_warning_kind(DC) \
((DC)->pedantic_errors ? DK_ERROR : DK_WARNING) ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
...@@ -53,7 +54,6 @@ const char *progname; ...@@ -53,7 +54,6 @@ const char *progname;
/* A diagnostic_context surrogate for stderr. */ /* A diagnostic_context surrogate for stderr. */
static diagnostic_context global_diagnostic_context; static diagnostic_context global_diagnostic_context;
diagnostic_context *global_dc = &global_diagnostic_context; diagnostic_context *global_dc = &global_diagnostic_context;
/* Return a malloc'd string containing MSG formatted a la printf. The /* Return a malloc'd string containing MSG formatted a la printf. The
caller is responsible for freeing the memory. */ caller is responsible for freeing the memory. */
...@@ -210,12 +210,31 @@ diagnostic_build_prefix (diagnostic_context *context, ...@@ -210,12 +210,31 @@ diagnostic_build_prefix (diagnostic_context *context,
const diagnostic_info *diagnostic) const diagnostic_info *diagnostic)
{ {
static const char *const diagnostic_kind_text[] = { 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" #include "diagnostic.def"
#undef DEFINE_DIAGNOSTIC_KIND #undef DEFINE_DIAGNOSTIC_KIND
"must-not-happen" "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 = _(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); expanded_location s = expand_location_to_spelling_point (diagnostic->location);
if (diagnostic->override_column) if (diagnostic->override_column)
s.column = diagnostic->override_column; s.column = diagnostic->override_column;
...@@ -223,10 +242,13 @@ diagnostic_build_prefix (diagnostic_context *context, ...@@ -223,10 +242,13 @@ diagnostic_build_prefix (diagnostic_context *context,
return return
(s.file == NULL (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 : context->show_column
? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text) ? build_message_string ("%s%s:%d:%d:%s %s%s%s", locus_cs, s.file, s.line,
: build_message_string ("%s:%d: %s", s.file, s.line, text)); 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 /* If LINE is longer than MAX_WIDTH, and COLUMN is not smaller than
...@@ -262,7 +284,7 @@ diagnostic_show_locus (diagnostic_context * context, ...@@ -262,7 +284,7 @@ diagnostic_show_locus (diagnostic_context * context,
expanded_location s; expanded_location s;
int max_width; int max_width;
const char *saved_prefix; const char *saved_prefix;
const char *caret_cs, *caret_ce;
if (!context->show_caret if (!context->show_caret
|| diagnostic->location <= BUILTINS_LOCATION || diagnostic->location <= BUILTINS_LOCATION
...@@ -290,9 +312,13 @@ diagnostic_show_locus (diagnostic_context * context, ...@@ -290,9 +312,13 @@ diagnostic_show_locus (diagnostic_context * context,
line++; line++;
} }
pp_newline (context->printer); 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. */ /* pp_printf does not implement %*c. */
buffer = XALLOCAVEC (char, s.column + 3); size_t len = s.column + 3 + strlen (caret_cs) + strlen (caret_ce);
snprintf (buffer, s.column + 3, " %*c", s.column, '^'); buffer = XALLOCAVEC (char, len);
snprintf (buffer, len, "%s %*c%s", caret_cs, s.column, '^', caret_ce);
pp_string (context->printer, buffer); pp_string (context->printer, buffer);
pp_set_prefix (context->printer, saved_prefix); pp_set_prefix (context->printer, saved_prefix);
} }
......
...@@ -22,26 +22,26 @@ along with GCC; see the file COPYING3. If not see ...@@ -22,26 +22,26 @@ along with GCC; see the file COPYING3. If not see
kind specified. I.e. they're uninitialized. Within the diagnostic kind specified. I.e. they're uninitialized. Within the diagnostic
machinery, this kind also means "don't change the existing kind", machinery, this kind also means "don't change the existing kind",
meaning "no change is specified". */ 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. /* 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 This is used by the diagnostic machinery when it wants to disable a
diagnostic without disabling the option which causes it. */ 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. */ /* The remainder are real diagnostic types. */
DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ") DEFINE_DIAGNOSTIC_KIND (DK_FATAL, "fatal error: ", "error")
DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ") DEFINE_DIAGNOSTIC_KIND (DK_ICE, "internal compiler error: ", "error")
DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ") DEFINE_DIAGNOSTIC_KIND (DK_ERROR, "error: ", "error")
DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ") DEFINE_DIAGNOSTIC_KIND (DK_SORRY, "sorry, unimplemented: ", "error")
DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ") DEFINE_DIAGNOSTIC_KIND (DK_WARNING, "warning: ", "warning")
DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ") DEFINE_DIAGNOSTIC_KIND (DK_ANACHRONISM, "anachronism: ", "warning")
DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ") DEFINE_DIAGNOSTIC_KIND (DK_NOTE, "note: ", "note")
DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ") DEFINE_DIAGNOSTIC_KIND (DK_DEBUG, "debug: ", "note")
/* These two would be re-classified as DK_WARNING or DK_ERROR, so the /* These two would be re-classified as DK_WARNING or DK_ERROR, so the
prefix does not matter. */ prefix does not matter. */
DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ") DEFINE_DIAGNOSTIC_KIND (DK_PEDWARN, "pedwarn: ", NULL)
DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ") DEFINE_DIAGNOSTIC_KIND (DK_PERMERROR, "permerror: ", NULL)
/* This one is just for counting DK_WARNING promoted to DK_ERROR /* This one is just for counting DK_WARNING promoted to DK_ERROR
due to -Werror and -Werror=warning. */ due to -Werror and -Werror=warning. */
DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ") DEFINE_DIAGNOSTIC_KIND (DK_WERROR, "error: ", NULL)
...@@ -226,6 +226,7 @@ Objective-C and Objective-C++ Dialects}. ...@@ -226,6 +226,7 @@ Objective-C and Objective-C++ Dialects}.
@xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}. @xref{Language Independent Options,,Options to Control Diagnostic Messages Formatting}.
@gccoptlist{-fmessage-length=@var{n} @gol @gccoptlist{-fmessage-length=@var{n} @gol
-fdiagnostics-show-location=@r{[}once@r{|}every-line@r{]} @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} -fno-diagnostics-show-option -fno-diagnostics-show-caret}
@item Warning Options @item Warning Options
...@@ -2956,6 +2957,76 @@ messages reporter to emit the same source location information (as ...@@ -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 prefix) for physical lines that result from the process of breaking
a message which is too long to fit on a single line. 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 @item -fno-diagnostics-show-option
@opindex fno-diagnostics-show-option @opindex fno-diagnostics-show-option
@opindex fdiagnostics-show-option @opindex fdiagnostics-show-option
......
...@@ -18828,6 +18828,7 @@ gen_producer_string (void) ...@@ -18828,6 +18828,7 @@ gen_producer_string (void)
case OPT_fdiagnostics_show_location_: case OPT_fdiagnostics_show_location_:
case OPT_fdiagnostics_show_option: case OPT_fdiagnostics_show_option:
case OPT_fdiagnostics_show_caret: case OPT_fdiagnostics_show_caret:
case OPT_fdiagnostics_color_:
case OPT_fverbose_asm: case OPT_fverbose_asm:
case OPT____: case OPT____:
case OPT__sysroot_: case OPT__sysroot_:
......
...@@ -452,14 +452,14 @@ lhd_print_error_function (diagnostic_context *context, const char *file, ...@@ -452,14 +452,14 @@ lhd_print_error_function (diagnostic_context *context, const char *file,
{ {
if (context->show_column) if (context->show_column)
pp_printf (context->printer, 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)), identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
s.file, s.line, s.column); "locus", s.file, s.line, s.column);
else else
pp_printf (context->printer, 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)), identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
s.file, s.line); "locus", s.file, s.line);
} }
else else
......
...@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -30,6 +30,7 @@ along with GCC; see the file COPYING3. If not see
#include "flags.h" #include "flags.h"
#include "params.h" #include "params.h"
#include "diagnostic.h" #include "diagnostic.h"
#include "diagnostic-color.h"
#include "opts-diagnostic.h" #include "opts-diagnostic.h"
#include "insn-attr-common.h" #include "insn-attr-common.h"
#include "common/common-target.h" #include "common/common-target.h"
...@@ -1497,6 +1498,11 @@ common_handle_option (struct gcc_options *opts, ...@@ -1497,6 +1498,11 @@ common_handle_option (struct gcc_options *opts,
dc->show_caret = value; dc->show_caret = value;
break; break;
case OPT_fdiagnostics_color_:
pp_show_color (dc->printer)
= colorize_init ((diagnostic_color_rule_t) value);
break;
case OPT_fdiagnostics_show_option: case OPT_fdiagnostics_show_option:
dc->show_option_requested = value; dc->show_option_requested = value;
break; break;
......
...@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see ...@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
#include "coretypes.h" #include "coretypes.h"
#include "intl.h" #include "intl.h"
#include "pretty-print.h" #include "pretty-print.h"
#include "diagnostic-color.h"
#if HAVE_ICONV #if HAVE_ICONV
#include <iconv.h> #include <iconv.h>
...@@ -226,6 +227,8 @@ pp_base_indent (pretty_printer *pp) ...@@ -226,6 +227,8 @@ pp_base_indent (pretty_printer *pp)
%c: character. %c: character.
%s: string. %s: string.
%p: pointer. %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. %m: strerror(text->err_no) - does not consume a value from args_ptr.
%%: '%'. %%: '%'.
%<: opening quote. %<: opening quote.
...@@ -300,18 +303,37 @@ pp_base_format (pretty_printer *pp, text_info *text) ...@@ -300,18 +303,37 @@ pp_base_format (pretty_printer *pp, text_info *text)
continue; continue;
case '<': case '<':
obstack_grow (&buffer->chunk_obstack, {
open_quote, strlen (open_quote)); obstack_grow (&buffer->chunk_obstack,
p++; open_quote, strlen (open_quote));
continue; const char *colorstr
= colorize_start (pp_show_color (pp), "quote");
obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr));
p++;
continue;
}
case '>': case '>':
{
const char *colorstr = colorize_stop (pp_show_color (pp));
obstack_grow (&buffer->chunk_obstack, colorstr, strlen (colorstr));
}
/* FALLTHRU */
case '\'': case '\'':
obstack_grow (&buffer->chunk_obstack, obstack_grow (&buffer->chunk_obstack,
close_quote, strlen (close_quote)); close_quote, strlen (close_quote));
p++; p++;
continue; continue;
case 'R':
{
const char *colorstr = colorize_stop (pp_show_color (pp));
obstack_grow (&buffer->chunk_obstack, colorstr,
strlen (colorstr));
p++;
continue;
}
case 'm': case 'm':
{ {
const char *errstr = xstrerror (text->err_no); const char *errstr = xstrerror (text->err_no);
...@@ -466,10 +488,19 @@ pp_base_format (pretty_printer *pp, text_info *text) ...@@ -466,10 +488,19 @@ pp_base_format (pretty_printer *pp, text_info *text)
gcc_assert (!wide || precision == 0); gcc_assert (!wide || precision == 0);
if (quote) if (quote)
pp_string (pp, open_quote); {
pp_string (pp, open_quote);
pp_string (pp, colorize_start (pp_show_color (pp), "quote"));
}
switch (*p) switch (*p)
{ {
case 'r':
pp_string (pp, colorize_start (pp_show_color (pp),
va_arg (*text->args_ptr,
const char *)));
break;
case 'c': case 'c':
pp_character (pp, va_arg (*text->args_ptr, int)); pp_character (pp, va_arg (*text->args_ptr, int));
break; break;
...@@ -563,7 +594,10 @@ pp_base_format (pretty_printer *pp, text_info *text) ...@@ -563,7 +594,10 @@ pp_base_format (pretty_printer *pp, text_info *text)
} }
if (quote) 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'); obstack_1grow (&buffer->chunk_obstack, '\0');
*formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *); *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *);
......
...@@ -151,6 +151,9 @@ typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *, ...@@ -151,6 +151,9 @@ typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
output. */ output. */
#define pp_translate_identifiers(PP) pp_base (PP)->translate_identifiers #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 /* The data structure that contains the bare minimum required to do
proper pretty-printing. Clients may derived from this structure proper pretty-printing. Clients may derived from this structure
and add additional fields they need. */ and add additional fields they need. */
...@@ -194,6 +197,9 @@ struct pretty_print_info ...@@ -194,6 +197,9 @@ struct pretty_print_info
/* Nonzero means identifiers are translated to the locale character /* Nonzero means identifiers are translated to the locale character
set on output. */ set on output. */
bool translate_identifiers; bool translate_identifiers;
/* Nonzero means that text should be colorized. */
bool show_color;
}; };
#define pp_set_line_maximum_length(PP, L) \ #define pp_set_line_maximum_length(PP, L) \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment