aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/diagnostic.h')
-rw-r--r--gcc/diagnostic.h150
1 files changed, 122 insertions, 28 deletions
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 00d7812..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,12 +71,6 @@ 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, as JSON to stderr. */
DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR,
@@ -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 *,
@@ -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);
@@ -782,6 +827,45 @@ public:
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;
@@ -851,6 +935,7 @@ public:
/* True if permerrors are warnings. */
bool m_permissive;
+private:
/* The option to associate with turning permerrors into warnings,
if any. */
diagnostic_option_id m_opt_permissive;
@@ -858,6 +943,7 @@ public:
/* True if errors are fatal. */
bool m_fatal_errors;
+public:
/* True if all warnings should be disabled. */
bool m_inhibit_warnings;
@@ -882,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 *);
@@ -896,7 +982,6 @@ 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;
@@ -923,9 +1008,9 @@ public:
private:
int m_lock;
-public:
bool m_inhibit_notes_p;
+public:
diagnostic_source_printing_options m_source_printing;
private:
@@ -1022,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 &
@@ -1040,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
@@ -1128,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
@@ -1201,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 *,