From 4f5b7f1b738f7206402d008e52718abfd78e2a07 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 6 Dec 2024 11:29:54 -0500 Subject: [PATCH] c++: consolidate location printing in error.cc [PR116253] Consolidate the location-printing logic in cp/error.cc, as preliminary work towards supporting nested diagnostics (PR other/116253). gcc/cp/ChangeLog: PR other/116253 * error.cc (print_location): Move to earlier in the file. (print_instantiation_partial_context_line): Replace location-printing logic with a call to print_location. (print_instantiation_partial_context): Likewise, splitting up pp_verbatim calls. (maybe_print_constexpr_context): Likewise. Signed-off-by: David Malcolm --- gcc/cp/error.cc | 71 +++++++++++++++++-------------------------------- 1 file changed, 24 insertions(+), 47 deletions(-) diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index ce8d5b15ac0..b3ab8fa8a7f 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -3828,6 +3828,20 @@ print_instantiation_full_context (diagnostic_text_output_format &text_output) print_instantiation_partial_context (text_output, p, location); } +static void +print_location (diagnostic_text_output_format &text_output, + location_t loc) +{ + expanded_location xloc = expand_location (loc); + pretty_printer *const pp = text_output.get_printer (); + if (text_output.show_column_p ()) + pp_verbatim (pp, _("%r%s:%d:%d:%R "), + "locus", xloc.file, xloc.line, xloc.column); + else + pp_verbatim (pp, _("%r%s:%d:%R "), + "locus", xloc.file, xloc.line); +} + /* Helper function of print_instantiation_partial_context() that prints a single line of instantiation context. */ @@ -3839,17 +3853,10 @@ print_instantiation_partial_context_line (diagnostic_text_output_format &text_ou if (loc == UNKNOWN_LOCATION) return; - expanded_location xloc = expand_location (loc); + print_location (text_output, loc); pretty_printer *const pp = text_output.get_printer (); - if (text_output.show_column_p ()) - pp_verbatim (pp, _("%r%s:%d:%d:%R "), - "locus", xloc.file, xloc.line, xloc.column); - else - pp_verbatim (pp, _("%r%s:%d:%R "), - "locus", xloc.file, xloc.line); - if (t != NULL) { if (t->list_p ()) @@ -3922,22 +3929,11 @@ print_instantiation_partial_context (diagnostic_text_output_format &text_output, } if (t != NULL && skip > 0) { - expanded_location xloc; - xloc = expand_location (loc); - pretty_printer *const pp = text_output.get_printer (); - if (text_output.show_column_p ()) - pp_verbatim (pp, - _("%r%s:%d:%d:%R [ skipping %d instantiation " - "contexts, use -ftemplate-backtrace-limit=0 to " - "disable ]\n"), - "locus", xloc.file, xloc.line, xloc.column, skip); - else - pp_verbatim (pp, - _("%r%s:%d:%R [ skipping %d instantiation " - "contexts, use -ftemplate-backtrace-limit=0 to " - "disable ]\n"), - "locus", xloc.file, xloc.line, skip); - + print_location (text_output, loc); + pp_verbatim (text_output.get_printer (), + _("[ skipping %d instantiation contexts," + " use -ftemplate-backtrace-limit=0 to disable ]\n"), + skip); do { loc = t->locus; t = t->next; @@ -3983,36 +3979,17 @@ maybe_print_constexpr_context (diagnostic_text_output_format &text_output) FOR_EACH_VEC_ELT (call_stack, ix, t) { - expanded_location xloc = expand_location (EXPR_LOCATION (t)); const char *s = expr_as_string (t, 0); pretty_printer *const pp = text_output.get_printer (); - if (text_output.show_column_p ()) - pp_verbatim (pp, - _("%r%s:%d:%d:%R in % expansion of %qs"), - "locus", xloc.file, xloc.line, xloc.column, s); - else - pp_verbatim (pp, - _("%r%s:%d:%R in % expansion of %qs"), - "locus", xloc.file, xloc.line, s); + print_location (text_output, EXPR_LOCATION (t)); + pp_verbatim (pp, + _("in % expansion of %qs"), + s); pp_newline (pp); } } -static void -print_location (diagnostic_text_output_format &text_output, - location_t loc) -{ - expanded_location xloc = expand_location (loc); - pretty_printer *const pp = text_output.get_printer (); - if (text_output.show_column_p ()) - pp_verbatim (pp, _("%r%s:%d:%d:%R "), - "locus", xloc.file, xloc.line, xloc.column); - else - pp_verbatim (pp, _("%r%s:%d:%R "), - "locus", xloc.file, xloc.line); -} - static void print_constrained_decl_info (diagnostic_text_output_format &text_output, tree decl)