This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Remove diagnostic.c use of flags.h global variables
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org, gdr at integrable-solutions dot net
- Date: Mon, 24 May 2010 15:35:37 +0000 (UTC)
- Subject: Remove diagnostic.c use of flags.h global variables
This patch removes dependence of diagnostic.c on flags.h and global
flags (flag_show_column, flag_pedantic_errors, flag_permissive,
flag_fatal_errors) therein, instead checking these flags in the
diagnostic context.
That the context is the correct place for the diagnostics code to
check these flags should be clear. While my aim in disentangling the
diagnostics code from the core compiler is to share both diagnostics
and option processing code between the compiler proper and the driver,
which would make these flags available in the driver, as a matter of
doing this incrementally with reasonable-size individual patches I
want to share the diagnostics code first. Furthermore, the dependence
of option processing on diagnostics should be in that direction only;
it makes sense to use the diagnostics code in other programs such as
gcov and collect2 that have completely different sets of options from
the set of options largely shared by the driver and cc1 (so even if
those programs shared some option processing infrastructure, they
wouldn't share everything related to the particular set of compiler
options GCC has).
It would be possible to change all the code in the compiler (front
ends etc.) that checks the above-mentioned flag_* variables to check
the relevant fields of global_dc instead, and to arrange for the
options to set the fields in global_dc, eliminating the separate
variables. I did not do this. It's not clear to me that it would be
desirable to do so; although I haven't worked out the details of what
option processing will end up looking like to implement the planned
changes to multilib selection, I definitely envisage the flag
variables for different options ending up as fields of a larger
structure variable (in order that multiple such options structures can
exist in the compiler simultaneously). So it seems natural to first
set flags describing the state derived from the options, then later
apply those flags to determine other pieces of state in the compiler
(such as in the global diagnostic context). It would certainly be
reasonable to adjust the diagnostic internal_error hook to take a
context parameter (so that the Ada implementation of that hook can
stop using the flag_show_column variable). If the Fortran people
enhanced the generic diagnostics code to implement all their
requirements, the flag_fatal_errors references in fortran/error.c
would naturally go away.
Bootstrapped with no regressions on x86_64-unknown-linux-gnu. OK to
commit?
2010-05-24 Joseph Myers <joseph@codesourcery.com>
* diagnostic.c: Don't include flags.h.
(pedantic_warning_kind, permissive_error_kind): Take diagnostic
context parameters. Check flags in the context passed as a
parameter.
(diagnostic_build_prefix): Add context parameter. Check
show_column flag in context.
(diagnostic_action_after_output): Check fatal_errors flag in
context.
(diagnostic_report_current_module): Check show_column flag in
context.
(default_diagnostic_starter): Update call to
diagnostic_build_prefix.
(diagnostic_report_diagnostic): Pass context to
pedantic_warning_kind.
(emit_diagnostic): Pass context to permissive_error_kind.
(permerror): Pass context to permissive_error_kind.
* diagnostic.h (struct diagnostic_context): Add show_column,
pedantic_errors, permissive and fatal_errors fields.
(diagnostic_build_prefix): Update prototype.
* langhooks.c
* toplev.c (process_options): Set flags in global_dc from
flag_show_column, flag_pedantic_errors, flag_permissive,
flag_fatal_errors.
* tree-diagnostic.c (default_tree_diagnostic_starter): Update call
to diagnostic_build_prefix.
* Makefile.in (diagnostic.o): Update dependencies.
cp:
2010-05-24 Joseph Myers <joseph@codesourcery.com>
* error.c (cp_diagnostic_starter): Update call to
diagnostic_build_prefix.
(cp_print_error_function,
print_instantiation_partial_context_line): Check show_column flag
in context.
Index: tree-diagnostic.c
===================================================================
--- tree-diagnostic.c (revision 159767)
+++ tree-diagnostic.c (working copy)
@@ -44,5 +44,6 @@ default_tree_diagnostic_starter (diagnos
diagnostic_info *diagnostic)
{
diagnostic_report_current_function (context, diagnostic);
- pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
+ pp_set_prefix (context->printer, diagnostic_build_prefix (context,
+ diagnostic));
}
Index: diagnostic.c
===================================================================
--- diagnostic.c (revision 159767)
+++ diagnostic.c (working copy)
@@ -27,7 +27,6 @@ along with GCC; see the file COPYING3.
#include "system.h"
#include "coretypes.h"
#include "version.h"
-#include "flags.h"
#include "input.h"
#include "toplev.h"
#include "intl.h"
@@ -35,8 +34,9 @@ along with GCC; see the file COPYING3.
#include "opts.h"
#include "plugin.h"
-#define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
-#define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR)
+#define pedantic_warning_kind(DC) \
+ ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
+#define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
/* Prototypes. */
static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
@@ -156,7 +156,8 @@ diagnostic_set_info (diagnostic_info *di
/* Return a malloc'd string describing a location. The caller is
responsible for freeing the memory. */
char *
-diagnostic_build_prefix (diagnostic_info *diagnostic)
+diagnostic_build_prefix (diagnostic_context *context,
+ diagnostic_info *diagnostic)
{
static const char *const diagnostic_kind_text[] = {
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
@@ -173,7 +174,7 @@ diagnostic_build_prefix (diagnostic_info
return
(s.file == NULL
? build_message_string ("%s: %s", progname, text)
- : flag_show_column
+ : 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));
}
@@ -196,7 +197,7 @@ diagnostic_action_after_output (diagnost
case DK_SORRY:
if (context->abort_on_error)
real_abort ();
- if (flag_fatal_errors)
+ if (context->fatal_errors)
{
fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
diagnostic_finish (context);
@@ -246,7 +247,7 @@ diagnostic_report_current_module (diagno
if (! MAIN_FILE_P (map))
{
map = INCLUDED_FROM (line_table, map);
- if (flag_show_column)
+ if (context->show_column)
pp_verbatim (context->printer,
"In file included from %s:%d:%d",
map->to_file,
@@ -273,7 +274,8 @@ default_diagnostic_starter (diagnostic_c
diagnostic_info *diagnostic)
{
diagnostic_report_current_module (context);
- pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
+ pp_set_prefix (context->printer, diagnostic_build_prefix (context,
+ diagnostic));
}
void
@@ -326,7 +328,7 @@ diagnostic_report_diagnostic (diagnostic
if (diagnostic->kind == DK_PEDWARN)
{
- diagnostic->kind = pedantic_warning_kind ();
+ diagnostic->kind = pedantic_warning_kind (context);
/* We do this to avoid giving the message for -pedantic-errors. */
orig_diag_kind = diagnostic->kind;
}
@@ -524,7 +526,7 @@ emit_diagnostic (diagnostic_t kind, loca
if (kind == DK_PERMERROR)
{
diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
- permissive_error_kind ());
+ permissive_error_kind (global_dc));
diagnostic.option_index = OPT_fpermissive;
}
else {
@@ -643,7 +645,7 @@ permerror (location_t location, const ch
va_start (ap, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
- permissive_error_kind ());
+ permissive_error_kind (global_dc));
diagnostic.option_index = OPT_fpermissive;
va_end (ap);
return report_diagnostic (&diagnostic);
Index: diagnostic.h
===================================================================
--- diagnostic.h (revision 159767)
+++ diagnostic.h (working copy)
@@ -87,6 +87,18 @@ struct diagnostic_context
/* True if we should raise a SIGABRT on errors. */
bool abort_on_error;
+ /* True if we should show the column number on diagnostics. */
+ bool show_column;
+
+ /* True if pedwarns are errors. */
+ bool pedantic_errors;
+
+ /* True if permerrors are warnings. */
+ bool permissive;
+
+ /* True if errors are fatal. */
+ bool fatal_errors;
+
/* This function is called before any message is printed out. It is
responsible for preparing message prefix and such. For example, it
might say:
@@ -211,7 +223,7 @@ extern void diagnostic_set_info_translat
extern bool emit_diagnostic (diagnostic_t, location_t, int,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
#endif
-extern char *diagnostic_build_prefix (diagnostic_info *);
+extern char *diagnostic_build_prefix (diagnostic_context *, diagnostic_info *);
void default_diagnostic_starter (diagnostic_context *, diagnostic_info *);
void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *);
Index: toplev.c
===================================================================
--- toplev.c (revision 159767)
+++ toplev.c (working copy)
@@ -1826,6 +1826,11 @@ process_options (void)
if (flag_compare_debug)
diagnostic_inhibit_notes (global_dc);
+ global_dc->show_column = flag_show_column;
+ global_dc->pedantic_errors = flag_pedantic_errors;
+ global_dc->permissive = flag_permissive;
+ global_dc->fatal_errors = flag_fatal_errors;
+
if (flag_section_anchors && !target_supports_section_anchors_p ())
{
warning (OPT_fsection_anchors,
Index: cp/error.c
===================================================================
--- cp/error.c (revision 159767)
+++ cp/error.c (working copy)
@@ -2550,7 +2550,8 @@ cp_diagnostic_starter (diagnostic_contex
diagnostic_report_current_module (context);
cp_print_error_function (context, diagnostic);
maybe_print_instantiation_context (context);
- pp_base_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
+ pp_base_set_prefix (context->printer, diagnostic_build_prefix (context,
+ diagnostic));
}
static void
@@ -2644,7 +2645,7 @@ cp_print_error_function (diagnostic_cont
pp_base_newline (context->printer);
if (s.file != NULL)
{
- if (flag_show_column && s.column != 0)
+ if (context->show_column && s.column != 0)
pp_printf (context->printer,
_(" inlined from %qs at %s:%d:%d"),
cxx_printable_name_translate (fndecl, 2),
@@ -2750,7 +2751,7 @@ print_instantiation_partial_context_line
const char *str;
str = decl_as_string_translate (t->decl,
TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE);
- if (flag_show_column)
+ if (context->show_column)
pp_verbatim (context->printer,
recursive_p
? _("%s:%d:%d: recursively instantiated from %qs\n")
@@ -2765,7 +2766,7 @@ print_instantiation_partial_context_line
}
else
{
- if (flag_show_column)
+ if (context->show_column)
pp_verbatim (context->printer,
recursive_p
? _("%s:%d:%d: recursively instantiated from here")
@@ -2816,7 +2817,7 @@ print_instantiation_partial_context (dia
{
expanded_location xloc;
xloc = expand_location (loc);
- if (flag_show_column)
+ if (context->show_column)
pp_verbatim (context->printer,
_("%s:%d:%d: [ skipping %d instantiation contexts ]\n"),
xloc.file, xloc.line, xloc.column, skip);
Index: langhooks.c
===================================================================
--- langhooks.c (revision 159767)
+++ langhooks.c (working copy)
@@ -426,7 +426,7 @@ lhd_print_error_function (diagnostic_con
pp_newline (context->printer);
if (s.file != NULL)
{
- if (flag_show_column)
+ if (context->show_column)
pp_printf (context->printer,
_(" inlined from %qs at %s:%d:%d"),
identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
Index: Makefile.in
===================================================================
--- Makefile.in (revision 159767)
+++ Makefile.in (working copy)
@@ -2735,7 +2735,7 @@ fold-const.o : fold-const.c $(CONFIG_H)
$(GGC_H) $(TM_P_H) langhooks.h $(MD5_H) intl.h $(TARGET_H) \
$(GIMPLE_H) realmpfr.h
diagnostic.o : diagnostic.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
- version.h $(FLAGS_H) $(INPUT_H) $(TOPLEV_H) intl.h $(DIAGNOSTIC_H) \
+ version.h $(INPUT_H) $(TOPLEV_H) intl.h $(DIAGNOSTIC_H) \
diagnostic.def opts.h $(PLUGIN_H)
opts.o : opts.c opts.h options.h $(TOPLEV_H) $(CONFIG_H) $(SYSTEM_H) \
coretypes.h $(TREE_H) $(TM_H) langhooks.h $(GGC_H) $(EXPR_H) $(RTL_H) \
--
Joseph S. Myers
joseph@codesourcery.com