aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/diagnostic.h')
-rw-r--r--gcc/diagnostic.h210
1 files changed, 161 insertions, 49 deletions
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 202760b..00f6e35 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -31,6 +31,11 @@ namespace text_art
class theme;
} // namespace text_art
+namespace xml
+{
+ class printer;
+} // namespace xml
+
/* An enum for controlling what units to use for the column number
when diagnostics are output, used by the -fdiagnostics-column-unit option.
Tabs will be expanded or not according to the value of -ftabstop. The origin
@@ -66,16 +71,10 @@ enum diagnostics_output_format
/* The default: textual output. */
DIAGNOSTICS_OUTPUT_FORMAT_TEXT,
- /* JSON-based output, to stderr. */
- DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR,
-
- /* JSON-based output, to a file. */
- DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE,
-
- /* SARIF-based output, to stderr. */
+ /* SARIF-based output, as JSON to stderr. */
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR,
- /* SARIF-based output, to a file. */
+ /* SARIF-based output, to a JSON file. */
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE
};
@@ -177,10 +176,15 @@ class diagnostic_source_print_policy;
typedef void (*diagnostic_text_starter_fn) (diagnostic_text_output_format &,
const diagnostic_info *);
-typedef void
-(*diagnostic_start_span_fn) (const diagnostic_location_print_policy &,
- pretty_printer *,
- expanded_location);
+struct to_text;
+struct to_html;
+
+extern pretty_printer *get_printer (to_text &);
+
+template <typename Sink>
+using diagnostic_start_span_fn = void (*) (const diagnostic_location_print_policy &,
+ Sink &sink,
+ expanded_location);
typedef void (*diagnostic_text_finalizer_fn) (diagnostic_text_output_format &,
const diagnostic_info *,
@@ -217,7 +221,7 @@ public:
class edit_context;
class diagnostic_client_data_hooks;
-class logical_location;
+class logical_location_manager;
class diagnostic_diagram;
class diagnostic_source_effect_info;
class diagnostic_output_format;
@@ -297,6 +301,9 @@ private:
diagnostic. */
vec<diagnostic_classification_change_t> m_classification_history;
+ /* For diagnostic_context::get_classification_history, declared later. */
+ friend class diagnostic_context;
+
/* For pragma push/pop. */
vec<int> m_push_list;
};
@@ -389,11 +396,32 @@ public:
const diagnostic_column_policy &
get_column_policy () const { return m_column_policy; }
+ void
+ print_text_span_start (const diagnostic_context &dc,
+ pretty_printer &pp,
+ const expanded_location &exploc);
+
+ void
+ print_html_span_start (const diagnostic_context &dc,
+ xml::printer &xp,
+ const expanded_location &exploc);
+
private:
diagnostic_column_policy m_column_policy;
bool m_show_column;
};
+/* Abstract base class for optionally supplying extra tags when writing
+ out annotation labels in HTML output. */
+
+class html_label_writer
+{
+public:
+ virtual ~html_label_writer () {}
+ virtual void begin_label () = 0;
+ virtual void end_label () = 0;
+};
+
/* A bundle of state for printing source within a diagnostic,
to isolate the interactions between diagnostic_context and the
implementation of diagnostic_show_locus. */
@@ -411,11 +439,21 @@ public:
diagnostic_t diagnostic_kind,
diagnostic_source_effect_info *effect_info) const;
+ void
+ print_as_html (xml::printer &xp,
+ const rich_location &richloc,
+ diagnostic_t diagnostic_kind,
+ diagnostic_source_effect_info *effect_info,
+ html_label_writer *label_writer) const;
+
const diagnostic_source_printing_options &
get_options () const { return m_options; }
- diagnostic_start_span_fn
- get_start_span_fn () const { return m_start_span_cb; }
+ diagnostic_start_span_fn<to_text>
+ get_text_start_span_fn () const { return m_text_start_span_cb; }
+
+ diagnostic_start_span_fn<to_html>
+ get_html_start_span_fn () const { return m_html_start_span_cb; }
file_cache &
get_file_cache () const { return m_file_cache; }
@@ -442,7 +480,8 @@ public:
private:
const diagnostic_source_printing_options &m_options;
class diagnostic_location_print_policy m_location_policy;
- diagnostic_start_span_fn m_start_span_cb;
+ diagnostic_start_span_fn<to_text> m_text_start_span_cb;
+ diagnostic_start_span_fn<to_html> m_html_start_span_cb;
file_cache &m_file_cache;
/* Other data copied from diagnostic_context. */
@@ -508,7 +547,7 @@ public:
/* Give access to m_text_callbacks. */
friend diagnostic_text_starter_fn &
diagnostic_text_starter (diagnostic_context *context);
- friend diagnostic_start_span_fn &
+ friend diagnostic_start_span_fn<to_text> &
diagnostic_start_span (diagnostic_context *context);
friend diagnostic_text_finalizer_fn &
diagnostic_text_finalizer (diagnostic_context *context);
@@ -602,6 +641,12 @@ public:
diagnostic_t diagnostic_kind,
pretty_printer &pp,
diagnostic_source_effect_info *effect_info);
+ void maybe_show_locus_as_html (const rich_location &richloc,
+ const diagnostic_source_printing_options &opts,
+ diagnostic_t diagnostic_kind,
+ xml::printer &xp,
+ diagnostic_source_effect_info *effect_info,
+ html_label_writer *label_writer);
void emit_diagram (const diagnostic_diagram &diagram);
@@ -609,8 +654,11 @@ public:
void set_output_format (std::unique_ptr<diagnostic_output_format> output_format);
void set_text_art_charset (enum diagnostic_text_art_charset charset);
void set_client_data_hooks (std::unique_ptr<diagnostic_client_data_hooks> hooks);
- void set_urlifier (std::unique_ptr<urlifier>);
- void override_urlifier (urlifier *);
+
+ void push_owned_urlifier (std::unique_ptr<urlifier>);
+ void push_borrowed_urlifier (const urlifier &);
+ void pop_urlifier ();
+
void create_edit_context ();
void set_warning_as_error_requested (bool val)
{
@@ -667,7 +715,11 @@ public:
{
return m_client_data_hooks;
}
- urlifier *get_urlifier () const { return m_urlifier; }
+
+ const logical_location_manager *
+ get_logical_location_manager () const;
+
+ const urlifier *get_urlifier () const;
text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
@@ -768,6 +820,52 @@ public:
bool supports_fnotice_on_stderr_p () const;
+ /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
+ void
+ set_abort_on_error (bool val)
+ {
+ m_abort_on_error = val;
+ }
+
+ /* Accessor for use in serialization, e.g. by C++ modules. */
+ auto &
+ get_classification_history ()
+ {
+ return m_option_classifier.m_classification_history;
+ }
+
+ void set_main_input_filename (const char *filename);
+
+ void
+ set_permissive_option (diagnostic_option_id opt_permissive)
+ {
+ m_opt_permissive = opt_permissive;
+ }
+
+ void
+ set_fatal_errors (bool fatal_errors)
+ {
+ m_fatal_errors = fatal_errors;
+ }
+
+ void
+ set_internal_error_callback (void (*cb) (diagnostic_context *,
+ const char *,
+ va_list *))
+ {
+ m_internal_error = cb;
+ }
+
+ void
+ set_adjust_diagnostic_info_callback (void (*cb) (diagnostic_context *,
+ diagnostic_info *))
+ {
+ m_adjust_diagnostic_info = cb;
+ }
+
+ void
+ inhibit_notes () { m_inhibit_notes_p = true; }
+
private:
void error_recursion () ATTRIBUTE_NORETURN;
@@ -824,10 +922,10 @@ private:
each diagnostic, if known. */
bool m_show_option_requested;
-public:
/* True if we should raise a SIGABRT on errors. */
bool m_abort_on_error;
+public:
/* True if we should show the column number on diagnostics. */
bool m_show_column;
@@ -837,13 +935,15 @@ public:
/* True if permerrors are warnings. */
bool m_permissive;
- /* The index of the option to associate with turning permerrors into
- warnings. */
- int m_opt_permissive;
+private:
+ /* The option to associate with turning permerrors into warnings,
+ if any. */
+ diagnostic_option_id m_opt_permissive;
/* True if errors are fatal. */
bool m_fatal_errors;
+public:
/* True if all warnings should be disabled. */
bool m_inhibit_warnings;
@@ -868,13 +968,13 @@ private:
/* This function is called by diagnostic_show_locus in between
disjoint spans of source code, so that the context can print
something to indicate that a new span of source code has begun. */
- diagnostic_start_span_fn m_start_span;
+ diagnostic_start_span_fn<to_text> m_text_start_span;
+ diagnostic_start_span_fn<to_html> m_html_start_span;
/* This function is called after the diagnostic message is printed. */
diagnostic_text_finalizer_fn m_end_diagnostic;
} m_text_callbacks;
-public:
/* Client hook to report an internal error. */
void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
@@ -882,17 +982,21 @@ public:
about to issue, such as its kind. */
void (*m_adjust_diagnostic_info)(diagnostic_context *, diagnostic_info *);
-private:
/* Owned by the context; this would be a std::unique_ptr if
diagnostic_context had a proper ctor. */
diagnostic_option_manager *m_option_mgr;
unsigned m_lang_mask;
- /* An optional hook for adding URLs to quoted text strings in
+ /* A stack of optional hooks for adding URLs to quoted text strings in
diagnostics. Only used for the main diagnostic message.
- Owned by the context; this would be a std::unique_ptr if
- diagnostic_context had a proper ctor. */
- urlifier *m_urlifier;
+ Typically a single one owner by the context, but can be temporarily
+ overridden by a borrowed urlifier (e.g. on-stack). */
+ struct urlifier_stack_node
+ {
+ urlifier *m_urlifier;
+ bool m_owned;
+ };
+ auto_vec<urlifier_stack_node> *m_urlifier_stack;
public:
/* Auxiliary data for client. */
@@ -904,9 +1008,9 @@ public:
private:
int m_lock;
-public:
bool m_inhibit_notes_p;
+public:
diagnostic_source_printing_options m_source_printing;
private:
@@ -950,8 +1054,14 @@ private:
/* How many diagnostics have been emitted since the bottommost
diagnostic_group was pushed. */
int m_emission_count;
+
+ /* The "group+diagnostic" nesting depth from which to inhibit notes. */
+ int m_inhibiting_notes_from;
} m_diagnostic_groups;
+ void inhibit_notes_in_group (bool inhibit = true);
+ bool notes_inhibited_in_group () const;
+
/* The various sinks to which diagnostics are to be outputted
(text vs structured formats such as SARIF).
The sinks are owned by the context; this would be a
@@ -997,13 +1107,6 @@ private:
diagnostic_buffer *m_diagnostic_buffer;
};
-inline void
-diagnostic_inhibit_notes (diagnostic_context * context)
-{
- context->m_inhibit_notes_p = true;
-}
-
-
/* Client supplied function to announce a diagnostic
(for text-based diagnostic output). */
inline diagnostic_text_starter_fn &
@@ -1015,10 +1118,10 @@ diagnostic_text_starter (diagnostic_context *context)
/* Client supplied function called between disjoint spans of source code,
so that the context can print
something to indicate that a new span of source code has begun. */
-inline diagnostic_start_span_fn &
+inline diagnostic_start_span_fn<to_text> &
diagnostic_start_span (diagnostic_context *context)
{
- return context->m_text_callbacks.m_start_span;
+ return context->m_text_callbacks.m_text_start_span;
}
/* Client supplied function called after a diagnostic message is
@@ -1033,13 +1136,6 @@ diagnostic_text_finalizer (diagnostic_context *context)
#define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
#define diagnostic_info_auxiliary_data(DI) (DI)->x_data
-/* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
-inline void
-diagnostic_abort_on_error (diagnostic_context *context)
-{
- context->m_abort_on_error = true;
-}
-
/* This diagnostic_context is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
and similar functions. */
@@ -1110,6 +1206,21 @@ diagnostic_show_locus (diagnostic_context *context,
context->maybe_show_locus (*richloc, opts, diagnostic_kind, *pp, effect_info);
}
+inline void
+diagnostic_show_locus_as_html (diagnostic_context *context,
+ const diagnostic_source_printing_options &opts,
+ rich_location *richloc,
+ diagnostic_t diagnostic_kind,
+ xml::printer &xp,
+ diagnostic_source_effect_info *effect_info = nullptr,
+ html_label_writer *label_writer = nullptr)
+{
+ gcc_assert (context);
+ gcc_assert (richloc);
+ context->maybe_show_locus_as_html (*richloc, opts, diagnostic_kind, xp,
+ effect_info, label_writer);
+}
+
/* Because we read source files a second time after the frontend did it the
first time, we need to know how the frontend handled things like character
set conversion and UTF-8 BOM stripping, in order to make everything
@@ -1183,8 +1294,9 @@ extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
#endif
void default_diagnostic_text_starter (diagnostic_text_output_format &,
const diagnostic_info *);
+template <typename Sink>
void default_diagnostic_start_span_fn (const diagnostic_location_print_policy &,
- pretty_printer *,
+ Sink &sink,
expanded_location);
void default_diagnostic_text_finalizer (diagnostic_text_output_format &,
const diagnostic_info *,