diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 96e0fb9723a..3be610718c8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,17 @@ +2012-04-24 Manuel López-Ibáñez + + * tree-pretty-print.h (default_tree_printer): Do not declare. + * tree-diagnostic.c: Include tree-pretty-print.h, tree-pass.h and + intl.h. + (default_tree_diagnostic_starter): Make static. + (default_tree_printer): Move to here. Make static. + (tree_diagnostics_defaults): New. + * tree-diagnostic.h (default_tree_diagnostic_starter): Do not declare. + * tree.c (free_lang_data): Use tree_diagnostics_defaults. + * toplev.c: Do not include tree-pass.h. + (default_tree_printer): Move from here. + (general_init): Use tree_diagnostics_defaults. + 2012-04-24 Chao-ying Fu * config.gcc (mips64*-*-linux*): Append mips/linux-common.h to tm_file. diff --git a/gcc/toplev.c b/gcc/toplev.c index 574af3bc160..3d9e1626b80 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -74,7 +74,6 @@ along with GCC; see the file COPYING3. If not see #include "value-prof.h" #include "alloc-pool.h" #include "tree-mudflap.h" -#include "tree-pass.h" #include "gimple.h" #include "tree-ssa-alias.h" #include "plugin.h" @@ -962,63 +961,6 @@ init_asm_output (const char *name) } } -/* Default tree printer. Handles declarations only. */ -bool -default_tree_printer (pretty_printer *pp, text_info *text, const char *spec, - int precision, bool wide, bool set_locus, bool hash) -{ - tree t; - - /* FUTURE: %+x should set the locus. */ - if (precision != 0 || wide || hash) - return false; - - switch (*spec) - { - case 'E': - t = va_arg (*text->args_ptr, tree); - if (TREE_CODE (t) == IDENTIFIER_NODE) - { - pp_identifier (pp, IDENTIFIER_POINTER (t)); - return true; - } - break; - - case 'D': - t = va_arg (*text->args_ptr, tree); - if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t)) - t = DECL_DEBUG_EXPR (t); - break; - - case 'F': - case 'T': - t = va_arg (*text->args_ptr, tree); - break; - - case 'K': - percent_K_format (text); - return true; - - default: - return false; - } - - if (set_locus && text->locus) - *text->locus = DECL_SOURCE_LOCATION (t); - - if (DECL_P (t)) - { - const char *n = DECL_NAME (t) - ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2)) - : _(""); - pp_string (pp, n); - } - else - dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0); - - return true; -} - /* A helper function; used as the reallocator function for cpp's line table. */ static void * @@ -1163,13 +1105,15 @@ general_init (const char *argv0) /* Initialize the diagnostics reporting machinery, so option parsing can give warnings and errors. */ diagnostic_initialize (global_dc, N_OPTS); - diagnostic_starter (global_dc) = default_tree_diagnostic_starter; - /* By default print macro expansion contexts in the diagnostic - finalizer -- for tokens resulting from macro macro expansion. */ - diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer; /* Set a default printer. Language specific initializations will override it later. */ - pp_format_decoder (global_dc->printer) = &default_tree_printer; + tree_diagnostics_defaults (global_dc); + /* FIXME: This should probably be moved to C-family + language-specific initializations. */ + /* By default print macro expansion contexts in the diagnostic + finalizer -- for tokens resulting from macro expansion. */ + diagnostic_finalizer (global_dc) = virt_loc_aware_diagnostic_finalizer; + global_dc->show_caret = global_options_init.x_flag_diagnostics_show_caret; global_dc->show_option_requested diff --git a/gcc/tree-diagnostic.c b/gcc/tree-diagnostic.c index b4b60dc44f9..c811fe9cdd2 100644 --- a/gcc/tree-diagnostic.c +++ b/gcc/tree-diagnostic.c @@ -25,10 +25,13 @@ along with GCC; see the file COPYING3. If not see #include "coretypes.h" #include "tree.h" #include "diagnostic.h" +#include "tree-pretty-print.h" #include "tree-diagnostic.h" +#include "tree-pass.h" /* TDF_DIAGNOSTIC */ #include "langhooks.h" #include "langhooks-def.h" #include "vec.h" +#include "intl.h" /* Prints out, if necessary, the name of the current function that caused an error. Called from all error and warning functions. */ @@ -40,7 +43,7 @@ diagnostic_report_current_function (diagnostic_context *context, lang_hooks.print_error_function (context, input_filename, diagnostic); } -void +static void default_tree_diagnostic_starter (diagnostic_context *context, diagnostic_info *diagnostic) { @@ -227,3 +230,69 @@ virt_loc_aware_diagnostic_finalizer (diagnostic_context *context, diagnostic->location, NULL); } + +/* Default tree printer. Handles declarations only. */ +static bool +default_tree_printer (pretty_printer *pp, text_info *text, const char *spec, + int precision, bool wide, bool set_locus, bool hash) +{ + tree t; + + /* FUTURE: %+x should set the locus. */ + if (precision != 0 || wide || hash) + return false; + + switch (*spec) + { + case 'E': + t = va_arg (*text->args_ptr, tree); + if (TREE_CODE (t) == IDENTIFIER_NODE) + { + pp_identifier (pp, IDENTIFIER_POINTER (t)); + return true; + } + break; + + case 'D': + t = va_arg (*text->args_ptr, tree); + if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t)) + t = DECL_DEBUG_EXPR (t); + break; + + case 'F': + case 'T': + t = va_arg (*text->args_ptr, tree); + break; + + case 'K': + percent_K_format (text); + return true; + + default: + return false; + } + + if (set_locus && text->locus) + *text->locus = DECL_SOURCE_LOCATION (t); + + if (DECL_P (t)) + { + const char *n = DECL_NAME (t) + ? identifier_to_locale (lang_hooks.decl_printable_name (t, 2)) + : _(""); + pp_string (pp, n); + } + else + dump_generic_node (pp, t, 0, TDF_DIAGNOSTIC, 0); + + return true; +} + +/* Sets CONTEXT to use language independent diagnostics. */ +void +tree_diagnostics_defaults (diagnostic_context *context) +{ + diagnostic_starter (context) = default_tree_diagnostic_starter; + diagnostic_finalizer (context) = default_diagnostic_finalizer; + diagnostic_format_decoder (context) = default_tree_printer; +} diff --git a/gcc/tree-diagnostic.h b/gcc/tree-diagnostic.h index 6b8e8e6e437..819792caaa7 100644 --- a/gcc/tree-diagnostic.h +++ b/gcc/tree-diagnostic.h @@ -49,9 +49,10 @@ along with GCC; see the file COPYING3. If not see ? diagnostic_abstract_origin (DI) \ : current_function_decl) -void default_tree_diagnostic_starter (diagnostic_context *, diagnostic_info *); -extern void diagnostic_report_current_function (diagnostic_context *, - diagnostic_info *); +void diagnostic_report_current_function (diagnostic_context *, + diagnostic_info *); void virt_loc_aware_diagnostic_finalizer (diagnostic_context *, diagnostic_info *); + +void tree_diagnostics_defaults (diagnostic_context *context); #endif /* ! GCC_TREE_DIAGNOSTIC_H */ diff --git a/gcc/tree-pretty-print.h b/gcc/tree-pretty-print.h index 49e78987d4a..d622e519415 100644 --- a/gcc/tree-pretty-print.h +++ b/gcc/tree-pretty-print.h @@ -50,10 +50,6 @@ extern void debug_generic_stmt (tree); extern void debug_tree_chain (tree); extern void percent_K_format (text_info *); extern void dump_function_header (FILE *, tree, int); - -/* In toplev.c */ -extern bool default_tree_printer (pretty_printer *, text_info *, const char *, - int, bool, bool, bool); /* In c-pretty-print.c */ extern void debug_c_tree (tree); diff --git a/gcc/tree.c b/gcc/tree.c index b0d52b2e0e9..7837d45e11b 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -38,7 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "tm_p.h" #include "function.h" #include "obstack.h" -#include "toplev.h" +#include "toplev.h" /* get_random_seed */ #include "ggc.h" #include "hashtab.h" #include "filenames.h" @@ -5255,9 +5255,7 @@ free_lang_data (void) devise a separate, middle-end private scheme for it. */ /* Reset diagnostic machinery. */ - diagnostic_starter (global_dc) = default_tree_diagnostic_starter; - diagnostic_finalizer (global_dc) = default_diagnostic_finalizer; - diagnostic_format_decoder (global_dc) = default_tree_printer; + tree_diagnostics_defaults (global_dc); return 0; }