+/* The default function to print out name of current function that caused
+ an error. */
+void
+lhd_print_error_function (diagnostic_context *context, const char *file,
+ diagnostic_info *diagnostic)
+{
+ if (diagnostic_last_function_changed (context, diagnostic))
+ {
+ const char *old_prefix = context->printer->prefix;
+ tree abstract_origin = diagnostic->abstract_origin;
+ char *new_prefix = (file && abstract_origin == NULL)
+ ? file_name_as_prefix (file) : NULL;
+
+ pp_set_prefix (context->printer, new_prefix);
+
+ if (current_function_decl == NULL)
+ pp_printf (context->printer, _("At top level:"));
+ else
+ {
+ tree fndecl, ao;
+
+ if (abstract_origin)
+ {
+ ao = BLOCK_ABSTRACT_ORIGIN (abstract_origin);
+ while (TREE_CODE (ao) == BLOCK
+ && BLOCK_ABSTRACT_ORIGIN (ao)
+ && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
+ ao = BLOCK_ABSTRACT_ORIGIN (ao);
+ gcc_assert (TREE_CODE (ao) == FUNCTION_DECL);
+ fndecl = ao;
+ }
+ else
+ fndecl = current_function_decl;
+
+ if (TREE_CODE (TREE_TYPE (fndecl)) == METHOD_TYPE)
+ pp_printf
+ (context->printer, _("In member function %qs"),
+ identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
+ else
+ pp_printf
+ (context->printer, _("In function %qs"),
+ identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
+
+ while (abstract_origin)
+ {
+ location_t *locus;
+ tree block = abstract_origin;
+
+ locus = &BLOCK_SOURCE_LOCATION (block);
+ fndecl = NULL;
+ block = BLOCK_SUPERCONTEXT (block);
+ while (block && TREE_CODE (block) == BLOCK
+ && BLOCK_ABSTRACT_ORIGIN (block))
+ {
+ ao = BLOCK_ABSTRACT_ORIGIN (block);
+
+ while (TREE_CODE (ao) == BLOCK
+ && BLOCK_ABSTRACT_ORIGIN (ao)
+ && BLOCK_ABSTRACT_ORIGIN (ao) != ao)
+ ao = BLOCK_ABSTRACT_ORIGIN (ao);
+
+ if (TREE_CODE (ao) == FUNCTION_DECL)
+ {
+ fndecl = ao;
+ break;
+ }
+ else if (TREE_CODE (ao) != BLOCK)
+ break;
+
+ block = BLOCK_SUPERCONTEXT (block);
+ }
+ if (fndecl)
+ abstract_origin = block;
+ else
+ {
+ while (block && TREE_CODE (block) == BLOCK)
+ block = BLOCK_SUPERCONTEXT (block);
+
+ if (block && TREE_CODE (block) == FUNCTION_DECL)
+ fndecl = block;
+ abstract_origin = NULL;
+ }
+ if (fndecl)
+ {
+ expanded_location s = expand_location (*locus);
+ pp_character (context->printer, ',');
+ pp_newline (context->printer);
+ if (s.file != NULL)
+ {
+ if (flag_show_column)
+ pp_printf (context->printer,
+ _(" inlined from %qs at %s:%d:%d"),
+ identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
+ s.file, s.line, s.column);
+ else
+ pp_printf (context->printer,
+ _(" inlined from %qs at %s:%d"),
+ identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)),
+ s.file, s.line);
+
+ }
+ else
+ pp_printf (context->printer, _(" inlined from %qs"),
+ identifier_to_locale (lang_hooks.decl_printable_name (fndecl, 2)));
+ }
+ }
+ pp_character (context->printer, ':');
+ }
+
+ diagnostic_set_last_function (context, diagnostic);
+ pp_flush (context->printer);
+ context->printer->prefix = old_prefix;
+ free ((char*) new_prefix);
+ }
+}