aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/diagnostic.cc')
-rw-r--r--gcc/diagnostic.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/gcc/diagnostic.cc b/gcc/diagnostic.cc
index 0f09308..c523f21 100644
--- a/gcc/diagnostic.cc
+++ b/gcc/diagnostic.cc
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3. If not see
message module. */
#include "config.h"
+#define INCLUDE_VECTOR
#include "system.h"
#include "coretypes.h"
#include "version.h"
@@ -35,11 +36,14 @@ along with GCC; see the file COPYING3. If not see
#include "diagnostic-metadata.h"
#include "diagnostic-path.h"
#include "diagnostic-client-data-hooks.h"
+#include "diagnostic-text-art.h"
+#include "diagnostic-diagram.h"
#include "edit-context.h"
#include "selftest.h"
#include "selftest-diagnostic.h"
#include "opts.h"
#include "cpplib.h"
+#include "text-art/theme.h"
#ifdef HAVE_TERMIOS_H
# include <termios.h>
@@ -244,6 +248,10 @@ diagnostic_initialize (diagnostic_context *context, int n_opts)
context->ice_handler_cb = NULL;
context->includes_seen = NULL;
context->m_client_data_hooks = NULL;
+ context->m_diagrams.m_theme = NULL;
+ context->m_diagrams.m_emission_cb = NULL;
+ diagnostics_text_art_charset_init (context,
+ DIAGNOSTICS_TEXT_ART_CHARSET_DEFAULT);
}
/* Maybe initialize the color support. We require clients to do this
@@ -320,6 +328,12 @@ diagnostic_finish (diagnostic_context *context)
if (context->final_cb)
context->final_cb (context);
+ if (context->m_diagrams.m_theme)
+ {
+ delete context->m_diagrams.m_theme;
+ context->m_diagrams.m_theme = NULL;
+ }
+
diagnostic_file_cache_fini ();
XDELETEVEC (context->classify_diagnostic);
@@ -2174,6 +2188,33 @@ internal_error_no_backtrace (const char *gmsgid, ...)
gcc_unreachable ();
}
+
+/* Emit DIAGRAM to CONTEXT, respecting the output format. */
+
+void
+diagnostic_emit_diagram (diagnostic_context *context,
+ const diagnostic_diagram &diagram)
+{
+ if (context->m_diagrams.m_theme == nullptr)
+ return;
+
+ if (context->m_diagrams.m_emission_cb)
+ {
+ context->m_diagrams.m_emission_cb (context, diagram);
+ return;
+ }
+
+ /* Default implementation. */
+ char *saved_prefix = pp_take_prefix (context->printer);
+ pp_set_prefix (context->printer, NULL);
+ /* Use a newline before and after and a two-space indent
+ to make the diagram stand out a little from the wall of text. */
+ pp_newline (context->printer);
+ diagram.get_canvas ().print_to_pp (context->printer, " ");
+ pp_newline (context->printer);
+ pp_set_prefix (context->printer, saved_prefix);
+ pp_flush (context->printer);
+}
/* Special case error functions. Most are implemented in terms of the
above, or should be. */
@@ -2316,6 +2357,38 @@ diagnostic_output_format_init (diagnostic_context *context,
}
}
+/* Initialize CONTEXT->m_diagrams based on CHARSET.
+ Specifically, make a text_art::theme object for m_diagrams.m_theme,
+ (or NULL for "no diagrams"). */
+
+void
+diagnostics_text_art_charset_init (diagnostic_context *context,
+ enum diagnostic_text_art_charset charset)
+{
+ delete context->m_diagrams.m_theme;
+ switch (charset)
+ {
+ default:
+ gcc_unreachable ();
+
+ case DIAGNOSTICS_TEXT_ART_CHARSET_NONE:
+ context->m_diagrams.m_theme = NULL;
+ break;
+
+ case DIAGNOSTICS_TEXT_ART_CHARSET_ASCII:
+ context->m_diagrams.m_theme = new text_art::ascii_theme ();
+ break;
+
+ case DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE:
+ context->m_diagrams.m_theme = new text_art::unicode_theme ();
+ break;
+
+ case DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI:
+ context->m_diagrams.m_theme = new text_art::emoji_theme ();
+ break;
+ }
+}
+
/* Implementation of diagnostic_path::num_events vfunc for
simple_diagnostic_path: simply get the number of events in the vec. */