From c224fa34178e236fd7e96702e5bcae0bc27f8506 Mon Sep 17 00:00:00 2001 From: manu Date: Tue, 24 Apr 2012 19:21:21 +0000 Subject: =?UTF-8?q?2012-04-24=20=20Manuel=20L=C3=B3pez-Ib=C3=A1=C3=B1ez=20?= =?UTF-8?q?=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc/ * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@186780 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/tree-diagnostic.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'gcc/tree-diagnostic.c') 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; +} -- cgit v1.2.1