From: Manuel López-Ibáñez Date: Thu, 4 Dec 2014 23:09:41 +0000 (+0000) Subject: diagnostic.c (diagnostic_color_init): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=97aa8bb6e20579f382357ffaa8f7233133fc1e7c;p=gcc.git diagnostic.c (diagnostic_color_init): New. gcc/ChangeLog: 2014-12-04 Manuel López-Ibáñez * diagnostic.c (diagnostic_color_init): New. * diagnostic.h: Declare. * gcc.c (driver::global_initializations): Use it. (driver_handle_option): Handle -fdiagnostics-color_. * toplev.c: Do not include diagnostic-color.h. (process_options): Do not initialize color diagnostics here. * common.opt (fdiagnostics-color=): Add Driver. * opts-global.c (init_options_once): Initialize color here. * opts.c (common_handle_option): Use diagnostics_color_init. * diagnostic-color.h: Fix comment. From-SVN: r218406 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d086e854dd8..54500c5b5d2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2014-12-04 Manuel López-Ibáñez + + * diagnostic.c (diagnostic_color_init): New. + * diagnostic.h: Declare. + * gcc.c (driver::global_initializations): Use it. + (driver_handle_option): Handle -fdiagnostics-color_. + * toplev.c: Do not include diagnostic-color.h. + (process_options): Do not initialize color diagnostics here. + * common.opt (fdiagnostics-color=): Add Driver. + * opts-global.c (init_options_once): Initialize color here. + * opts.c (common_handle_option): Use diagnostics_color_init. + * diagnostic-color.h: Fix comment. + 2014-12-04 David Malcolm * tree-pretty-print.c (INDENT): Rename "buffer" to "pp". diff --git a/gcc/common.opt b/gcc/common.opt index a4dd3b326b1..78b796b8557 100644 --- a/gcc/common.opt +++ b/gcc/common.opt @@ -1096,7 +1096,7 @@ Common Alias(fdiagnostics-color=,always,never) ; fdiagnostics-color= -Common Joined RejectNegative Var(flag_diagnostics_show_color) Enum(diagnostic_color_rule) Init(DIAGNOSTICS_COLOR_NO) +Driver Common Joined RejectNegative Var(flag_diagnostics_show_color) Enum(diagnostic_color_rule) Init(DIAGNOSTICS_COLOR_NO) -fdiagnostics-color=[never|always|auto] Colorize diagnostics ; Required for these enum values. diff --git a/gcc/diagnostic-color.h b/gcc/diagnostic-color.h index 63df6921450..d96e085f49c 100644 --- a/gcc/diagnostic-color.h +++ b/gcc/diagnostic-color.h @@ -41,11 +41,10 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_DIAGNOSTIC_COLOR_H #define GCC_DIAGNOSTIC_COLOR_H -/* How often diagnostics are prefixed by their locations: - o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported; - o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once; - o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical - line is started. */ +/* Whether to add color to diagnostics: + o DIAGNOSTICS_COLOR_NO: never + o DIAGNOSTICS_COLOR_YES: always + o DIAGNOSTICS_COLOR_AUTO: depending on the output stream. */ typedef enum { DIAGNOSTICS_COLOR_NO = 0, diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c index 0c8fbe5f766..07ce6020192 100644 --- a/gcc/diagnostic.c +++ b/gcc/diagnostic.c @@ -155,6 +155,34 @@ diagnostic_initialize (diagnostic_context *context, int n_opts) context->inhibit_notes_p = false; } +/* Maybe initialize the color support. We require clients to do this + explicitly, since most clients don't want color. When called + without a VALUE, it initializes with DIAGNOSTICS_COLOR_DEFAULT. */ + +void +diagnostic_color_init (diagnostic_context *context, int value /*= -1 */) +{ + /* value == -1 is the default value. */ + if (value < 0) + { + /* If DIAGNOSTICS_COLOR_DEFAULT is -1, default to + -fdiagnostics-color=auto if GCC_COLORS is in the environment, + otherwise default to -fdiagnostics-color=never, for other + values default to that + -fdiagnostics-color={never,auto,always}. */ + if (DIAGNOSTICS_COLOR_DEFAULT == -1) + { + if (!getenv ("GCC_COLORS")) + return; + value = DIAGNOSTICS_COLOR_AUTO; + } + else + value = DIAGNOSTICS_COLOR_DEFAULT; + } + pp_show_color (context->printer) + = colorize_init ((diagnostic_color_rule_t) value); +} + /* Do any cleaning up required after the last diagnostic is emitted. */ void diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index 64f90a79324..81e59880169 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -266,6 +266,7 @@ extern diagnostic_context *global_dc; /* Diagnostic related functions. */ extern void diagnostic_initialize (diagnostic_context *, int); +extern void diagnostic_color_init (diagnostic_context *, int value = -1); extern void diagnostic_finish (diagnostic_context *); extern void diagnostic_report_current_module (diagnostic_context *, location_t); extern void diagnostic_show_locus (diagnostic_context *, const diagnostic_info *); diff --git a/gcc/gcc.c b/gcc/gcc.c index 4cb4ba32618..a5408a48e5a 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -3608,6 +3608,10 @@ driver_handle_option (struct gcc_options *opts, save_switch (compare_debug_replacement_opt, 0, NULL, validated, true); return true; + case OPT_fdiagnostics_color_: + diagnostic_color_init (dc, value); + break; + case OPT_Wa_: { int prev, j; @@ -6975,6 +6979,7 @@ driver::global_initializations () gcc_init_libintl (); diagnostic_initialize (global_dc, 0); + diagnostic_color_init (global_dc); #ifdef GCC_DRIVER_HOST_INITIALIZATION /* Perform host dependent initialization when needed. */ diff --git a/gcc/opts-global.c b/gcc/opts-global.c index 80a84f629d2..bb3898e1fe2 100644 --- a/gcc/opts-global.c +++ b/gcc/opts-global.c @@ -261,6 +261,11 @@ init_options_once (void) initial_lang_mask = lang_hooks.option_lang_mask (); lang_hooks.initialize_diagnostics (global_dc); + /* ??? Ideally, we should do this earlier and the FEs will override + it if desired (none do it so far). However, the way the FEs + construct their pretty-printers means that all previous settings + are overriden. */ + diagnostic_color_init (global_dc); } /* Decode command-line options to an array, like diff --git a/gcc/opts.c b/gcc/opts.c index 564b8dc65c2..1b4f97e28d0 100644 --- a/gcc/opts.c +++ b/gcc/opts.c @@ -30,7 +30,6 @@ 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" @@ -1771,8 +1770,7 @@ common_handle_option (struct gcc_options *opts, break; case OPT_fdiagnostics_color_: - pp_show_color (dc->printer) - = colorize_init ((diagnostic_color_rule_t) value); + diagnostic_color_init (dc, value); break; case OPT_fdiagnostics_show_option: diff --git a/gcc/toplev.c b/gcc/toplev.c index 911084db375..04f63df4983 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -86,7 +86,6 @@ along with GCC; see the file COPYING3. If not see #include "gimple-expr.h" #include "gimple.h" #include "plugin.h" -#include "diagnostic-color.h" #include "context.h" #include "pass_manager.h" #include "auto-profile.h" @@ -1268,29 +1267,6 @@ process_options (void) maximum_field_alignment = initial_max_fld_align * BITS_PER_UNIT; - /* If DIAGNOSTICS_COLOR_DEFAULT is -1, default to -fdiagnostics-color=auto - if GCC_COLORS is in the environment, otherwise default to - -fdiagnostics-color=never, for other values default to that - -fdiagnostics-color={never,auto,always}. */ - if (!global_options_set.x_flag_diagnostics_show_color) - switch ((int) DIAGNOSTICS_COLOR_DEFAULT) - { - case -1: - if (!getenv ("GCC_COLORS")) - break; - /* FALLTHRU */ - case DIAGNOSTICS_COLOR_AUTO: - pp_show_color (global_dc->printer) - = colorize_init (DIAGNOSTICS_COLOR_AUTO); - break; - case DIAGNOSTICS_COLOR_YES: - pp_show_color (global_dc->printer) - = colorize_init (DIAGNOSTICS_COLOR_YES); - break; - default: - break; - } - /* Allow the front end to perform consistency checks and do further initialization based on the command line options. This hook also sets the original filename if appropriate (e.g. foo.i -> foo.c)