diff options
Diffstat (limited to 'gcc/diagnostic.cc')
-rw-r--r-- | gcc/diagnostic.cc | 129 |
1 files changed, 57 insertions, 72 deletions
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc index b43fc90..088390b 100644 --- a/gcc/diagnostic.cc +++ b/gcc/diagnostic.cc @@ -95,7 +95,7 @@ int get_terminal_width (void) { const char * s = getenv ("COLUMNS"); - if (s != NULL) { + if (s != nullptr) { int n = atoi (s); if (n > 0) return n; @@ -250,7 +250,10 @@ diagnostic_context::initialize (int n_opts) m_internal_error = nullptr; m_adjust_diagnostic_info = nullptr; m_text_callbacks.m_begin_diagnostic = default_diagnostic_text_starter; - m_text_callbacks.m_start_span = default_diagnostic_start_span_fn; + m_text_callbacks.m_text_start_span + = default_diagnostic_start_span_fn<to_text>; + m_text_callbacks.m_html_start_span + = default_diagnostic_start_span_fn<to_html>; m_text_callbacks.m_end_diagnostic = default_diagnostic_text_finalizer; m_option_mgr = nullptr; m_urlifier_stack = new auto_vec<urlifier_stack_node> (); @@ -522,6 +525,13 @@ diagnostic_context::supports_fnotice_on_stderr_p () const } void +diagnostic_context::set_main_input_filename (const char *filename) +{ + for (auto sink : m_output_sinks) + sink->set_main_input_filename (filename); +} + +void diagnostic_context:: set_client_data_hooks (std::unique_ptr<diagnostic_client_data_hooks> hooks) { @@ -669,7 +679,7 @@ diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg, diagnostic->message.m_format_spec = msg; diagnostic->message.m_richloc = richloc; diagnostic->richloc = richloc; - diagnostic->metadata = NULL; + diagnostic->metadata = nullptr; diagnostic->kind = kind; diagnostic->option_id = 0; } @@ -689,11 +699,11 @@ static const char *const diagnostic_kind_color[] = { #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C), #include "diagnostic.def" #undef DEFINE_DIAGNOSTIC_KIND - NULL + nullptr }; /* Get a color name for diagnostics of type KIND - Result could be NULL. */ + Result could be nullptr. */ const char * diagnostic_get_color_for_kind (diagnostic_t kind) @@ -827,12 +837,12 @@ bt_callback (void *data, uintptr_t pc, const char *filename, int lineno, /* If we don't have any useful information, don't print anything. */ - if (filename == NULL && function == NULL) + if (filename == nullptr && function == nullptr) return 0; /* Skip functions in diagnostic.cc. */ if (*pcount == 0 - && filename != NULL + && filename != nullptr && strcmp (lbasename (filename), "diagnostic.cc") == 0) return 0; @@ -845,13 +855,13 @@ bt_callback (void *data, uintptr_t pc, const char *filename, int lineno, } ++*pcount; - char *alc = NULL; - if (function != NULL) + char *alc = nullptr; + if (function != nullptr) { char *str = cplus_demangle_v3 (function, (DMGL_VERBOSE | DMGL_ANSI | DMGL_GNU_V3 | DMGL_PARAMS)); - if (str != NULL) + if (str != nullptr) { alc = str; function = str; @@ -863,7 +873,7 @@ bt_callback (void *data, uintptr_t pc, const char *filename, int lineno, if (strncmp (function, bt_stop[i], len) == 0 && (function[len] == '\0' || function[len] == '(')) { - if (alc != NULL) + if (alc != nullptr) free (alc); /* Returning a non-zero value stops the backtrace. */ return 1; @@ -873,11 +883,11 @@ bt_callback (void *data, uintptr_t pc, const char *filename, int lineno, fprintf (stderr, "0x%lx %s\n\t%s:%d\n", (unsigned long) pc, - function == NULL ? "???" : function, - filename == NULL ? "???" : filename, + function == nullptr ? "???" : function, + filename == nullptr ? "???" : filename, lineno); - if (alc != NULL) + if (alc != nullptr) free (alc); return 0; @@ -963,11 +973,11 @@ diagnostic_context::action_after_output (diagnostic_t diag_kind) finish (); } - struct backtrace_state *state = NULL; + struct backtrace_state *state = nullptr; if (diag_kind == DK_ICE) - state = backtrace_create_state (NULL, 0, bt_err_callback, NULL); + state = backtrace_create_state (nullptr, 0, bt_err_callback, nullptr); int count = 0; - if (state != NULL) + if (state != nullptr) backtrace_full (state, 2, bt_callback, bt_err_callback, (void *) &count); @@ -1056,36 +1066,21 @@ logical_location_manager::function_p (key k) const { default: gcc_unreachable (); - case LOGICAL_LOCATION_KIND_UNKNOWN: - case LOGICAL_LOCATION_KIND_MODULE: - case LOGICAL_LOCATION_KIND_NAMESPACE: - case LOGICAL_LOCATION_KIND_TYPE: - case LOGICAL_LOCATION_KIND_RETURN_TYPE: - case LOGICAL_LOCATION_KIND_PARAMETER: - case LOGICAL_LOCATION_KIND_VARIABLE: + case logical_location_kind::unknown: + case logical_location_kind::module_: + case logical_location_kind::namespace_: + case logical_location_kind::type: + case logical_location_kind::return_type: + case logical_location_kind::parameter: + case logical_location_kind::variable: return false; - case LOGICAL_LOCATION_KIND_FUNCTION: - case LOGICAL_LOCATION_KIND_MEMBER: + case logical_location_kind::function: + case logical_location_kind::member: return true; } } -void -default_diagnostic_start_span_fn (const diagnostic_location_print_policy &loc_policy, - pretty_printer *pp, - expanded_location exploc) -{ - const diagnostic_column_policy &column_policy - = loc_policy.get_column_policy (); - label_text text - = column_policy.get_location_text (exploc, - loc_policy.show_column_p (), - pp_show_color (pp)); - pp_string (pp, text.get ()); - pp_newline (pp); -} - /* Interface to specify diagnostic kind overrides. Returns the previous setting, or DK_UNSPECIFIED if the parameters are out of range. If OPTION_ID is zero, the new setting is for all the @@ -1199,7 +1194,7 @@ print_parseable_fixits (file_cache &fc, gcc_assert (richloc); char *saved_prefix = pp_take_prefix (pp); - pp_set_prefix (pp, NULL); + pp_set_prefix (pp, nullptr); for (unsigned i = 0; i < richloc->get_num_fixit_hints (); i++) { @@ -1599,7 +1594,7 @@ diagnostic_context::report_diagnostic (diagnostic_info *diagnostic) || diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT) action_after_output (diagnostic->kind); - diagnostic->x_data = NULL; + diagnostic->x_data = nullptr; if (m_edit_context_ptr) if (diagnostic->richloc->fixits_can_be_auto_applied_p ()) @@ -1798,9 +1793,9 @@ fancy_abort (const char *file, int line, const char *function) /* Attempt to print a backtrace. */ struct backtrace_state *state - = backtrace_create_state (NULL, 0, bt_err_callback, NULL); + = backtrace_create_state (nullptr, 0, bt_err_callback, nullptr); int count = 0; - if (state != NULL) + if (state != nullptr) backtrace_full (state, 2, bt_callback, bt_err_callback, (void *) &count); @@ -1877,6 +1872,7 @@ diagnostic_output_format_init (diagnostic_context &context, enum diagnostics_output_format format, bool json_formatting) { + diagnostic_output_format *new_sink = nullptr; switch (format) { default: @@ -1885,37 +1881,26 @@ diagnostic_output_format_init (diagnostic_context &context, /* The default; do nothing. */ break; - case DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR: - diagnostic_output_format_init_json_stderr (context, - json_formatting); - break; - - case DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE: - diagnostic_output_format_init_json_file (context, - json_formatting, - base_file_name); - break; - case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR: - diagnostic_output_format_init_sarif_stderr (context, - line_table, - main_input_filename_, - json_formatting); + new_sink = &diagnostic_output_format_init_sarif_stderr (context, + line_table, + json_formatting); break; case DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE: - diagnostic_output_format_init_sarif_file (context, - line_table, - main_input_filename_, - json_formatting, - base_file_name); + new_sink = &diagnostic_output_format_init_sarif_file (context, + line_table, + json_formatting, + base_file_name); break; } + if (new_sink) + new_sink->set_main_input_filename (main_input_filename_); } /* Initialize this context's m_diagrams based on CHARSET. Specifically, make a text_art::theme object for m_diagrams.m_theme, - (or NULL for "no diagrams"). */ + (or nullptr for "no diagrams"). */ void diagnostic_context:: @@ -2240,7 +2225,7 @@ test_print_parseable_fixits_insert () linemap_add (line_table, LC_ENTER, false, "test.c", 0); linemap_line_start (line_table, 5, 100); - linemap_add (line_table, LC_LEAVE, false, NULL, 0); + linemap_add (line_table, LC_LEAVE, false, nullptr, 0); location_t where = linemap_position_for_column (line_table, 10); richloc.add_fixit_insert_before (where, "added content"); @@ -2261,7 +2246,7 @@ test_print_parseable_fixits_remove () linemap_add (line_table, LC_ENTER, false, "test.c", 0); linemap_line_start (line_table, 5, 100); - linemap_add (line_table, LC_LEAVE, false, NULL, 0); + linemap_add (line_table, LC_LEAVE, false, nullptr, 0); source_range where; where.m_start = linemap_position_for_column (line_table, 10); where.m_finish = linemap_position_for_column (line_table, 20); @@ -2284,7 +2269,7 @@ test_print_parseable_fixits_replace () linemap_add (line_table, LC_ENTER, false, "test.c", 0); linemap_line_start (line_table, 5, 100); - linemap_add (line_table, LC_LEAVE, false, NULL, 0); + linemap_add (line_table, LC_LEAVE, false, nullptr, 0); source_range where; where.m_start = linemap_position_for_column (line_table, 10); where.m_finish = linemap_position_for_column (line_table, 20); @@ -2315,7 +2300,7 @@ test_print_parseable_fixits_bytes_vs_display_columns () linemap_add (line_table, LC_ENTER, false, fname, 0); linemap_line_start (line_table, 1, 100); - linemap_add (line_table, LC_LEAVE, false, NULL, 0); + linemap_add (line_table, LC_LEAVE, false, nullptr, 0); source_range where; where.m_start = linemap_position_for_column (line_table, 12); where.m_finish = linemap_position_for_column (line_table, 17); @@ -2373,7 +2358,7 @@ assert_location_text (const char *expected_loc_text, xloc.file = filename; xloc.line = line; xloc.column = column; - xloc.data = NULL; + xloc.data = nullptr; xloc.sysp = false; diagnostic_column_policy column_policy (dc); @@ -2389,7 +2374,7 @@ test_get_location_text () { const char *old_progname = progname; progname = "PROGNAME"; - assert_location_text ("PROGNAME:", NULL, 0, 0, true); + assert_location_text ("PROGNAME:", nullptr, 0, 0, true); char *built_in_colon = concat (special_fname_builtin (), ":", (char *) 0); assert_location_text (built_in_colon, special_fname_builtin (), 42, 10, true); |