/* Return a malloc'd string describing a location and the severity of the diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for freeing the memory. */ char * diagnostic_build_prefix (diagnostic_context *context, const diagnostic_info *diagnostic) { static const char *const diagnostic_kind_text[] = { #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), #include "diagnostic.def" #undef DEFINE_DIAGNOSTIC_KIND "must-not-happen" }; gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); const char *text = _(diagnostic_kind_text[diagnostic->kind]); const char *text_cs = "", *text_ce = ""; pretty_printer *pp = context->printer; if (diagnostic_kind_color[diagnostic->kind]) { text_cs = colorize_start (pp_show_color (pp), diagnostic_kind_color[diagnostic->kind]); text_ce = colorize_stop (pp_show_color (pp)); } expanded_location s = diagnostic_expand_location (diagnostic); char *location_text = diagnostic_get_location_text (context, s); char *result = build_message_string ("%s %s%s%s", location_text, text_cs, text, text_ce); free (location_text); return result; }
/* Same as diagnostic_build_prefix, but only the source FILE is given. */ char * file_name_as_prefix (diagnostic_context *context, const char *f) { const char *locus_cs = colorize_start (pp_show_color (context->printer), "locus"); const char *locus_ce = colorize_stop (pp_show_color (context->printer)); return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce); }
/* Return a malloc'd string describing a location. The caller is responsible for freeing the memory. */ char * diagnostic_build_prefix (diagnostic_context *context, const diagnostic_info *diagnostic) { static const char *const diagnostic_kind_text[] = { #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), #include "diagnostic.def" #undef DEFINE_DIAGNOSTIC_KIND "must-not-happen" }; static const char *const diagnostic_kind_color[] = { #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C), #include "diagnostic.def" #undef DEFINE_DIAGNOSTIC_KIND NULL }; const char *text = _(diagnostic_kind_text[diagnostic->kind]); const char *text_cs = "", *text_ce = ""; const char *locus_cs, *locus_ce; pretty_printer *pp = context->printer; if (diagnostic_kind_color[diagnostic->kind]) { text_cs = colorize_start (pp_show_color (pp), diagnostic_kind_color[diagnostic->kind]); text_ce = colorize_stop (pp_show_color (pp)); } locus_cs = colorize_start (pp_show_color (pp), "locus"); locus_ce = colorize_stop (pp_show_color (pp)); expanded_location s = expand_location_to_spelling_point (diagnostic->location); if (diagnostic->override_column) s.column = diagnostic->override_column; gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); return (s.file == NULL ? build_message_string ("%s%s:%s %s%s%s", locus_cs, progname, locus_ce, text_cs, text, text_ce) : context->show_column ? build_message_string ("%s%s:%d:%d:%s %s%s%s", locus_cs, s.file, s.line, s.column, locus_ce, text_cs, text, text_ce) : build_message_string ("%s%s:%d:%s %s%s%s", locus_cs, s.file, s.line, locus_ce, text_cs, text, text_ce)); }
static char * diagnostic_get_location_text (diagnostic_context *context, expanded_location s) { pretty_printer *pp = context->printer; const char *locus_cs = colorize_start (pp_show_color (pp), "locus"); const char *locus_ce = colorize_stop (pp_show_color (pp)); if (s.file == NULL) return build_message_string ("%s%s:%s", locus_cs, progname, locus_ce); if (!strcmp (s.file, N_("<built-in>"))) return build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce); if (context->show_column) return build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line, s.column, locus_ce); else return build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line, locus_ce); }
/* Return a malloc'd string describing a location. The caller is responsible for freeing the memory. */ char * diagnostic_build_prefix (diagnostic_info *diagnostic) { static const char *const diagnostic_kind_text[] = { #define DEFINE_DIAGNOSTIC_KIND(K, T) (T), #include "diagnostic.def" #undef DEFINE_DIAGNOSTIC_KIND "must-not-happen" }; const char *text = _(diagnostic_kind_text[diagnostic->kind]); expanded_location s = expand_location (diagnostic->location); if (diagnostic->override_column) s.column = diagnostic->override_column; gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); return (s.file == NULL ? build_message_string ("%s: %s", progname, text) : flag_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)); }
/* Same as diagnostic_build_prefix, but only the source FILE is given. */ char * file_name_as_prefix (const char *f) { return build_message_string ("%s: ", f); }