diff options
Diffstat (limited to 'gcc/cp/error.cc')
-rw-r--r-- | gcc/cp/error.cc | 208 |
1 files changed, 149 insertions, 59 deletions
diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index 499eb1b..c427163 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "stringpool.h" #include "tree-diagnostic.h" -#include "diagnostic-color.h" +#include "diagnostics/color.h" #include "langhooks-def.h" #include "intl.h" #include "cxx-pretty-print.h" @@ -38,8 +38,7 @@ along with GCC; see the file COPYING3. If not see #include "cp-name-hint.h" #include "attribs.h" #include "pretty-print-format-impl.h" -#include "make-unique.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') @@ -97,17 +96,17 @@ static void dump_scope (cxx_pretty_printer *, tree, int); static void dump_template_parms (cxx_pretty_printer *, tree, int, int); static int get_non_default_template_args_count (tree, int); static const char *function_category (tree); -static void maybe_print_constexpr_context (diagnostic_text_output_format &); -static void maybe_print_instantiation_context (diagnostic_text_output_format &); -static void print_instantiation_full_context (diagnostic_text_output_format &); -static void print_instantiation_partial_context (diagnostic_text_output_format &, +static void maybe_print_constexpr_context (diagnostics::text_sink &); +static void maybe_print_instantiation_context (diagnostics::text_sink &); +static void print_instantiation_full_context (diagnostics::text_sink &); +static void print_instantiation_partial_context (diagnostics::text_sink &, struct tinst_level *, location_t); -static void maybe_print_constraint_context (diagnostic_text_output_format &); -static void cp_diagnostic_text_starter (diagnostic_text_output_format &, - const diagnostic_info *); -static void cp_print_error_function (diagnostic_text_output_format &, - const diagnostic_info *); +static void maybe_print_constraint_context (diagnostics::text_sink &); +static void cp_diagnostic_text_starter (diagnostics::text_sink &, + const diagnostics::diagnostic_info *); +static void cp_print_error_function (diagnostics::text_sink &, + const diagnostics::diagnostic_info *); static bool cp_printer (pretty_printer *, text_info *, const char *, int, bool, bool, bool, bool *, pp_token_list &); @@ -183,9 +182,10 @@ class cxx_format_postprocessor : public format_postprocessor : m_type_a (), m_type_b () {} - format_postprocessor *clone() const final override + std::unique_ptr<format_postprocessor> + clone() const final override { - return new cxx_format_postprocessor (); + return std::make_unique<cxx_format_postprocessor> (); } void handle (pretty_printer *pp) final override; @@ -194,6 +194,32 @@ class cxx_format_postprocessor : public format_postprocessor deferred_printed_type m_type_b; }; +/* Constructor and destructor for cxx_dump_pretty_printer, defined here to + avoid needing to move cxx_format_postprocessor into the header as well. */ + +cxx_dump_pretty_printer:: +cxx_dump_pretty_printer (int phase) + : phase (phase) +{ + outf = dump_begin (phase, &flags); + if (outf) + { + pp_format_decoder (this) = cp_printer; + set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ()); + set_output_stream (outf); + } +} + +cxx_dump_pretty_printer:: +~cxx_dump_pretty_printer () +{ + if (outf) + { + pp_flush (this); + dump_end (phase, outf); + } +} + /* Return the in-scope template that's currently being parsed, or NULL_TREE otherwise. */ @@ -216,7 +242,7 @@ get_current_template () erroneous_templates_t *erroneous_templates; -/* Callback function diagnostic_context::m_adjust_diagnostic_info. +/* Callback function diagnostics::context::m_adjust_diagnostic_info. Errors issued when parsing a template are automatically treated like permerrors associated with the -Wtemplate-body flag and can be @@ -224,16 +250,16 @@ erroneous_templates_t *erroneous_templates; issue an error if we later need to instantiate the template. */ static void -cp_adjust_diagnostic_info (diagnostic_context *context, - diagnostic_info *diagnostic) +cp_adjust_diagnostic_info (diagnostics::context *context, + diagnostics::diagnostic_info *diagnostic) { - if (diagnostic->kind == DK_ERROR) + if (diagnostic->m_kind == diagnostics::kind::error) if (tree tmpl = get_current_template ()) { - diagnostic->option_id = OPT_Wtemplate_body; + diagnostic->m_option_id = OPT_Wtemplate_body; if (context->m_permissive) - diagnostic->kind = DK_WARNING; + diagnostic->m_kind = diagnostics::kind::warning; bool existed; location_t &error_loc @@ -243,7 +269,7 @@ cp_adjust_diagnostic_info (diagnostic_context *context, /* Remember that this template had a parse-time error so that we'll ensure a hard error has been issued upon its instantiation. */ - error_loc = diagnostic->richloc->get_loc (); + error_loc = diagnostic->m_richloc->get_loc (); } } @@ -272,17 +298,17 @@ cp_seen_error () capacities. */ void -cxx_initialize_diagnostics (diagnostic_context *context) +cxx_initialize_diagnostics (diagnostics::context *context) { cxx_pretty_printer *pp = new cxx_pretty_printer (); - pp_format_postprocessor (pp) = new cxx_format_postprocessor (); + pp->set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ()); context->set_pretty_printer (std::unique_ptr<pretty_printer> (pp)); c_common_diagnostics_set_defaults (context); - diagnostic_text_starter (context) = cp_diagnostic_text_starter; + diagnostics::text_starter (context) = cp_diagnostic_text_starter; /* diagnostic_finalizer is already c_diagnostic_text_finalizer. */ context->set_format_decoder (cp_printer); - context->m_adjust_diagnostic_info = cp_adjust_diagnostic_info; + context->set_adjust_diagnostic_info_callback (cp_adjust_diagnostic_info); } /* Dump an '@module' name suffix for DECL, if it's attached to an import. */ @@ -542,12 +568,13 @@ dump_template_bindings (cxx_pretty_printer *pp, tree parms, tree args, /* If the template argument repeats the template parameter (T = T), skip the parameter.*/ if (arg && TREE_CODE (arg) == TEMPLATE_TYPE_PARM - && TREE_CODE (parm_i) == TREE_LIST - && TREE_CODE (TREE_VALUE (parm_i)) == TYPE_DECL - && TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i))) - == TEMPLATE_TYPE_PARM - && DECL_NAME (TREE_VALUE (parm_i)) - == DECL_NAME (TREE_CHAIN (arg))) + && arg == TYPE_MAIN_VARIANT (arg) + && TREE_CODE (parm_i) == TREE_LIST + && TREE_CODE (TREE_VALUE (parm_i)) == TYPE_DECL + && (TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i))) + == TEMPLATE_TYPE_PARM) + && (DECL_NAME (TREE_VALUE (parm_i)) + == DECL_NAME (TYPE_STUB_DECL (arg)))) continue; semicolon_or_introducer (); @@ -677,6 +704,20 @@ dump_type (cxx_pretty_printer *pp, tree t, int flags) } break; + case TREE_VEC: + { + /* A list of types used for a trait. */ + bool need_comma = false; + for (tree arg : tree_vec_range (t)) + { + if (need_comma) + pp_separate_with_comma (pp); + dump_type (pp, arg, flags); + need_comma = true; + } + } + break; + case TREE_LIST: /* A list of function parms. */ dump_parameters (pp, t, flags); @@ -783,6 +824,7 @@ dump_type (cxx_pretty_printer *pp, tree t, int flags) pp_cxx_ws_string (pp, TYPENAME_IS_ENUM_P (t) ? "enum" : TYPENAME_IS_CLASS_P (t) ? "class" + : TYPENAME_IS_UNION_P (t) ? "union" : "typename"); dump_typename (pp, t, flags); break; @@ -1255,12 +1297,37 @@ dump_global_iord (cxx_pretty_printer *pp, tree t) pp_printf (pp, p, DECL_SOURCE_FILE (t)); } +/* Write a representation of OpenMP "declare mapper" T to PP in a manner + suitable for error messages. */ + +static void +dump_omp_declare_mapper (cxx_pretty_printer *pp, tree t, int flags) +{ + pp_string (pp, "#pragma omp declare mapper"); + if (t == NULL_TREE || t == error_mark_node) + return; + pp_space (pp); + pp_cxx_left_paren (pp); + if (OMP_DECLARE_MAPPER_ID (t)) + { + pp_cxx_tree_identifier (pp, OMP_DECLARE_MAPPER_ID (t)); + pp_colon (pp); + } + dump_type (pp, TREE_TYPE (t), flags); + pp_cxx_right_paren (pp); +} + static void dump_simple_decl (cxx_pretty_printer *pp, tree t, tree type, int flags) { if (VAR_P (t) && DECL_NTTP_OBJECT_P (t)) return dump_expr (pp, DECL_INITIAL (t), flags); + if (TREE_CODE (t) == VAR_DECL + && DECL_LANG_SPECIFIC (t) + && DECL_OMP_DECLARE_MAPPER_P (t)) + return dump_omp_declare_mapper (pp, DECL_INITIAL (t), flags); + if (flags & TFF_DECL_SPECIFIERS) { if (concept_definition_p (t)) @@ -3217,6 +3284,27 @@ dump_expr (cxx_pretty_printer *pp, tree t, int flags) break; } + case CO_AWAIT_EXPR: + pp_cxx_ws_string (pp, "co_await"); + pp_cxx_whitespace (pp); + dump_expr (pp, TREE_OPERAND (t, 0), flags); + break; + + case CO_YIELD_EXPR: + pp_cxx_ws_string (pp, "co_yield"); + pp_cxx_whitespace (pp); + dump_expr (pp, TREE_OPERAND (t, 0), flags); + break; + + case CO_RETURN_EXPR: + pp_cxx_ws_string (pp, "co_return"); + if (TREE_OPERAND (t, 0)) + { + pp_cxx_whitespace (pp); + dump_expr (pp, TREE_OPERAND (t, 0), flags); + } + break; + /* This list is incomplete, but should suffice for now. It is very important that `sorry' does not call `report_error_function'. That could cause an infinite loop. */ @@ -3673,9 +3761,9 @@ eh_spec_to_string (tree p, int /*v*/) /* Langhook for print_error_function. */ void -cxx_print_error_function (diagnostic_text_output_format &text_output, +cxx_print_error_function (diagnostics::text_sink &text_output, const char *file, - const diagnostic_info *diagnostic) + const diagnostics::diagnostic_info *diagnostic) { char *prefix; if (file) @@ -3689,8 +3777,8 @@ cxx_print_error_function (diagnostic_text_output_format &text_output, } static void -cp_diagnostic_text_starter (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic) +cp_diagnostic_text_starter (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic) { pp_set_prefix (text_output.get_printer (), text_output.build_indent_prefix (true)); @@ -3706,8 +3794,8 @@ cp_diagnostic_text_starter (diagnostic_text_output_format &text_output, /* Print current function onto BUFFER, in the process of reporting a diagnostic message. Called from cp_diagnostic_starter. */ static void -cp_print_error_function (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic) +cp_print_error_function (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic) { /* If we are in an instantiation context, current_function_decl is likely to be wrong, so just rely on print_instantiation_full_context. */ @@ -3716,7 +3804,7 @@ cp_print_error_function (diagnostic_text_output_format &text_output, /* The above is true for constraint satisfaction also. */ if (current_failed_constraint) return; - diagnostic_context *const context = &text_output.get_context (); + diagnostics::context *const context = &text_output.get_context (); if (diagnostic_last_function_changed (context, diagnostic)) { pretty_printer *const pp = text_output.get_printer (); @@ -3854,7 +3942,7 @@ function_category (tree fn) /* Report the full context of a current template instantiation, onto BUFFER. */ static void -print_instantiation_full_context (diagnostic_text_output_format &text_output) +print_instantiation_full_context (diagnostics::text_sink &text_output) { struct tinst_level *p = current_instantiation (); location_t location = input_location; @@ -3882,7 +3970,7 @@ print_instantiation_full_context (diagnostic_text_output_format &text_output) } static void -print_location (diagnostic_text_output_format &text_output, +print_location (diagnostics::text_sink &text_output, location_t loc) { expanded_location xloc = expand_location (loc); @@ -3896,7 +3984,7 @@ print_location (diagnostic_text_output_format &text_output, } /* A RAII class for use when emitting a line of contextual information - via pp_verbatim to a diagnostic_text_output_format to add before/after + via pp_verbatim to a diagnostics::text_sink to add before/after behaviors to the pp_verbatim calls. If the text output has show_nesting_p (), then the ctor prints @@ -3911,7 +3999,7 @@ print_location (diagnostic_text_output_format &text_output, class auto_context_line { public: - auto_context_line (diagnostic_text_output_format &text_output, + auto_context_line (diagnostics::text_sink &text_output, location_t loc, bool show_locus = false) : m_text_output (text_output), @@ -3942,7 +4030,7 @@ public: diagnostic_show_locus (&m_text_output.get_context (), m_text_output.get_source_printing_options (), &rich_loc, - DK_NOTE, pp); + diagnostics::kind::note, pp); pp_set_prefix (pp, saved_prefix); } } @@ -3954,12 +4042,12 @@ public: diagnostic_show_locus (&m_text_output.get_context (), m_text_output.get_source_printing_options (), &rich_loc, - DK_NOTE, pp); + diagnostics::kind::note, pp); pp_set_prefix (pp, saved_prefix); } } private: - diagnostic_text_output_format &m_text_output; + diagnostics::text_sink &m_text_output; location_t m_loc; bool m_show_locus; }; @@ -3968,7 +4056,7 @@ private: prints a single line of instantiation context. */ static void -print_instantiation_partial_context_line (diagnostic_text_output_format &text_output, +print_instantiation_partial_context_line (diagnostics::text_sink &text_output, struct tinst_level *t, location_t loc, bool recursive_p) { @@ -4006,7 +4094,7 @@ print_instantiation_partial_context_line (diagnostic_text_output_format &text_ou /* Same as print_instantiation_full_context but less verbose. */ static void -print_instantiation_partial_context (diagnostic_text_output_format &text_output, +print_instantiation_partial_context (diagnostics::text_sink &text_output, struct tinst_level *t0, location_t loc) { struct tinst_level *t; @@ -4077,7 +4165,7 @@ print_instantiation_partial_context (diagnostic_text_output_format &text_output, /* Called from cp_thing to print the template context for an error. */ static void -maybe_print_instantiation_context (diagnostic_text_output_format &text_output) +maybe_print_instantiation_context (diagnostics::text_sink &text_output) { if (!problematic_instantiation_changed () || current_instantiation () == 0) return; @@ -4089,7 +4177,7 @@ maybe_print_instantiation_context (diagnostic_text_output_format &text_output) /* Report what constexpr call(s) we're trying to expand, if any. */ void -maybe_print_constexpr_context (diagnostic_text_output_format &text_output) +maybe_print_constexpr_context (diagnostics::text_sink &text_output) { vec<tree> call_stack = cx_error_context (); unsigned ix; @@ -4109,7 +4197,7 @@ maybe_print_constexpr_context (diagnostic_text_output_format &text_output) static void -print_constrained_decl_info (diagnostic_text_output_format &text_output, +print_constrained_decl_info (diagnostics::text_sink &text_output, tree decl) { auto_context_line sentinel (text_output, DECL_SOURCE_LOCATION (decl)); @@ -4118,7 +4206,7 @@ print_constrained_decl_info (diagnostic_text_output_format &text_output, } static void -print_concept_check_info (diagnostic_text_output_format &text_output, +print_concept_check_info (diagnostics::text_sink &text_output, tree expr, tree map, tree args) { gcc_assert (concept_check_p (expr)); @@ -4143,7 +4231,7 @@ print_concept_check_info (diagnostic_text_output_format &text_output, context, if any. */ static tree -print_constraint_context_head (diagnostic_text_output_format &text_output, +print_constraint_context_head (diagnostics::text_sink &text_output, tree cxt, tree args) { tree src = TREE_VALUE (cxt); @@ -4167,7 +4255,7 @@ print_constraint_context_head (diagnostic_text_output_format &text_output, } static void -print_requires_expression_info (diagnostic_text_output_format &text_output, +print_requires_expression_info (diagnostics::text_sink &text_output, tree constr, tree args) { @@ -4197,7 +4285,7 @@ print_requires_expression_info (diagnostic_text_output_format &text_output, } void -maybe_print_single_constraint_context (diagnostic_text_output_format &text_output, +maybe_print_single_constraint_context (diagnostics::text_sink &text_output, tree failed) { if (!failed) @@ -4228,7 +4316,7 @@ maybe_print_single_constraint_context (diagnostic_text_output_format &text_outpu } void -maybe_print_constraint_context (diagnostic_text_output_format &text_output) +maybe_print_constraint_context (diagnostics::text_sink &text_output) { if (!current_failed_constraint) return; @@ -4841,18 +4929,20 @@ maybe_warn_variadic_templates (void) C++0x. */ bool pedwarn_cxx98 (location_t location, - diagnostic_option_id option_id, + diagnostics::option_id option_id, const char *gmsgid, ...) { - diagnostic_info diagnostic; + diagnostics::diagnostic_info diagnostic; va_list ap; bool ret; rich_location richloc (line_table, location); va_start (ap, gmsgid); diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, - (cxx_dialect == cxx98) ? DK_PEDWARN : DK_WARNING); - diagnostic.option_id = option_id; + (cxx_dialect == cxx98 + ? diagnostics::kind::pedwarn + : diagnostics::kind::warning)); + diagnostic.m_option_id = option_id; ret = diagnostic_report_diagnostic (global_dc, &diagnostic); va_end (ap); return ret; |