aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostics/context.h
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/diagnostics/context.h')
-rw-r--r--gcc/diagnostics/context.h190
1 files changed, 57 insertions, 133 deletions
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h
index f47370b..9464f6a 100644
--- a/gcc/diagnostics/context.h
+++ b/gcc/diagnostics/context.h
@@ -23,7 +23,12 @@ along with GCC; see the file COPYING3. If not see
#include "lazily-created.h"
#include "unique-argv.h"
#include "diagnostics/option-classifier.h"
+#include "diagnostics/option-id-manager.h"
#include "diagnostics/context-options.h"
+#include "diagnostics/source-printing-options.h"
+#include "diagnostics/column-options.h"
+#include "diagnostics/counters.h"
+#include "diagnostics/logging.h"
namespace diagnostics {
@@ -81,84 +86,6 @@ typedef void (*text_finalizer_fn) (text_sink &,
const diagnostic_info *,
enum kind);
-/* Abstract base class for the diagnostic subsystem to make queries
- about command-line options. */
-
-class option_manager
-{
-public:
- virtual ~option_manager () {}
-
- /* Return 1 if option OPT_ID is enabled, 0 if it is disabled,
- or -1 if it isn't a simple on-off switch
- (or if the value is unknown, typically set later in target). */
- virtual int option_enabled_p (option_id opt_id) const = 0;
-
- /* Return malloced memory for the name of the option OPT_ID
- which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
- possibly converted to DIAG_KIND by options such as -Werror.
- May return NULL if no name is to be printed.
- May be passed 0 as well as the index of a particular option. */
- virtual char *make_option_name (option_id opt_id,
- enum kind orig_diag_kind,
- enum kind diag_kind) const = 0;
-
- /* Return malloced memory for a URL describing the option that controls
- a diagnostic.
- May return NULL if no URL is available.
- May be passed 0 as well as the index of a particular option. */
- virtual char *make_option_url (option_id opt_id) const = 0;
-};
-
-/* A bundle of options relating to printing the user's source code
- (potentially with a margin, underlining, labels, etc). */
-
-struct source_printing_options
-{
- /* True if we should print the source line with a caret indicating
- the location.
- Corresponds to -fdiagnostics-show-caret. */
- bool enabled;
-
- /* Maximum width of the source line printed. */
- int max_width;
-
- /* Character used at the caret when printing source locations. */
- char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
-
- /* When printing source code, should the characters at carets and ranges
- be colorized? (assuming colorization is on at all).
- This should be true for frontends that generate range information
- (so that the ranges of code are colorized),
- and false for frontends that merely specify points within the
- source code (to avoid e.g. colorizing just the first character in
- a token, which would look strange). */
- bool colorize_source_p;
-
- /* When printing source code, should labelled ranges be printed?
- Corresponds to -fdiagnostics-show-labels. */
- bool show_labels_p;
-
- /* When printing source code, should there be a left-hand margin
- showing line numbers?
- Corresponds to -fdiagnostics-show-line-numbers. */
- bool show_line_numbers_p;
-
- /* If printing source code, what should the minimum width of the margin
- be? Line numbers will be right-aligned, and padded to this width.
- Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */
- int min_margin_width;
-
- /* Usable by plugins; if true, print a debugging ruler above the
- source output. */
- bool show_ruler_p;
-
- /* When printing events in an inline path, should we print lines
- visualizing links between related events (e.g. for CFG paths)?
- Corresponds to -fdiagnostics-show-event-links. */
- bool show_event_links_p;
-};
-
/* A bundle of state for determining column numbers in diagnostics
(tab stops, whether to start at 0 or 1, etc).
Uses a file_cache to handle tabs. */
@@ -174,13 +101,11 @@ public:
bool show_column,
bool colorize) const;
- int get_tabstop () const { return m_tabstop; }
+ int get_tabstop () const { return m_column_options.m_tabstop; }
private:
file_cache &m_file_cache;
- enum diagnostics_column_unit m_column_unit;
- int m_column_origin;
- int m_tabstop;
+ column_options m_column_options;
};
/* A bundle of state for printing locations within diagnostics
@@ -291,28 +216,6 @@ private:
enum diagnostics_escape_format m_escape_format;
};
-/* A collection of counters of diagnostics, per-kind
- (e.g. "3 errors and 1 warning"), for use by both context
- and by diagnostics::buffer. */
-
-struct counters
-{
- counters ();
-
- void dump (FILE *out, int indent) const;
- void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
-
- int get_count (enum kind kind) const
- {
- return m_count_for_kind[static_cast<size_t> (kind)];
- }
-
- void move_to (counters &dest);
- void clear ();
-
- int m_count_for_kind[static_cast<size_t> (kind::last_diagnostic_kind)];
-};
-
/* This class encapsulates the state of the diagnostics subsystem
as a whole (either directly, or via owned objects of other classes, to
avoid global variables).
@@ -334,7 +237,7 @@ struct counters
- an optional urlifier to inject URLs into formatted messages
- counting the number of diagnostics reported of each kind
(class diagnostics::counters)
- - calling out to a option_manager to determine if
+ - calling out to a option_id_manager to determine if
a particular warning is enabled or disabled
- tracking pragmas that enable/disable warnings in a range of
source code
@@ -362,7 +265,7 @@ public:
friend class text_sink;
friend class buffer;
- typedef void (*set_locations_callback_t) (context *,
+ typedef void (*set_locations_callback_t) (const context &,
diagnostic_info *);
void initialize (int n_opts);
@@ -373,8 +276,10 @@ public:
void finish ();
- void dump (FILE *out) const;
- void DEBUG_FUNCTION dump () const { dump (stderr); }
+ void dump (FILE *out, int indent) const;
+ void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
+
+ logging::logger *get_logger () { return m_logger; }
bool execution_failed_p () const;
@@ -398,6 +303,7 @@ public:
void push_nesting_level ();
void pop_nesting_level ();
+ void set_nesting_level (int new_level);
bool warning_enabled_at (location_t loc, option_id opt_id);
@@ -432,18 +338,35 @@ public:
enum kind new_kind,
location_t where)
{
+ logging::log_function_params
+ (m_logger, "diagnostics::context::classify_diagnostics")
+ .log_param_option_id ("option_id", opt_id)
+ .log_param_kind ("new_kind", new_kind)
+ .log_param_location_t ("where", where);
+ logging::auto_inc_depth depth_sentinel (m_logger);
+
return m_option_classifier.classify_diagnostic (this,
opt_id,
new_kind,
where);
}
- void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
+ void push_diagnostics (location_t where)
{
+ logging::log_function_params
+ (m_logger, "diagnostics::context::push_diagnostics")
+ .log_param_location_t ("where", where);
+ logging::auto_inc_depth depth_sentinel (m_logger);
+
m_option_classifier.push ();
}
void pop_diagnostics (location_t where)
{
+ logging::log_function_params
+ (m_logger, "diagnostics::context::pop_diagnostics")
+ .log_param_location_t ("where", where);
+ logging::auto_inc_depth depth_sentinel (m_logger);
+
m_option_classifier.pop (where);
}
@@ -489,6 +412,9 @@ public:
}
void set_show_path_depths (bool val) { m_show_path_depths = val; }
void set_show_option_requested (bool val) { m_show_option_requested = val; }
+ void set_show_nesting (bool val);
+ void set_show_nesting_locations (bool val);
+ void set_show_nesting_levels (bool val);
void set_max_errors (int val) { m_max_errors = val; }
void set_escape_format (enum diagnostics_escape_format val)
{
@@ -546,32 +472,32 @@ public:
/* Option-related member functions. */
inline bool option_enabled_p (option_id opt_id) const
{
- if (!m_option_mgr)
+ if (!m_option_id_mgr)
return true;
- return m_option_mgr->option_enabled_p (opt_id);
+ return m_option_id_mgr->option_enabled_p (opt_id);
}
inline char *make_option_name (option_id opt_id,
enum kind orig_diag_kind,
enum kind diag_kind) const
{
- if (!m_option_mgr)
+ if (!m_option_id_mgr)
return nullptr;
- return m_option_mgr->make_option_name (opt_id,
- orig_diag_kind,
- diag_kind);
+ return m_option_id_mgr->make_option_name (opt_id,
+ orig_diag_kind,
+ diag_kind);
}
inline char *make_option_url (option_id opt_id) const
{
- if (!m_option_mgr)
+ if (!m_option_id_mgr)
return nullptr;
- return m_option_mgr->make_option_url (opt_id);
+ return m_option_id_mgr->make_option_url (opt_id);
}
void
- set_option_manager (std::unique_ptr<option_manager> mgr,
- unsigned lang_mask);
+ set_option_id_manager (std::unique_ptr<option_id_manager> option_id_mgr,
+ unsigned lang_mask);
unsigned get_lang_mask () const
{
@@ -668,7 +594,7 @@ public:
}
void
- set_adjust_diagnostic_info_callback (void (*cb) (context *,
+ set_adjust_diagnostic_info_callback (void (*cb) (const context &,
diagnostic_info *))
{
m_adjust_diagnostic_info = cb;
@@ -688,6 +614,9 @@ public:
return m_source_printing;
}
+ column_options &get_column_options () { return m_column_options; }
+ const column_options &get_column_options () const { return m_column_options; }
+
void set_caret_max_width (int value);
private:
@@ -804,11 +733,11 @@ private:
/* Client hook to adjust properties of the given diagnostic that we're
about to issue, such as its kind. */
- void (*m_adjust_diagnostic_info)(context *, diagnostic_info *);
+ void (*m_adjust_diagnostic_info)(const context &, diagnostic_info *);
/* Owned by the context; this would be a std::unique_ptr if
context had a proper ctor. */
- option_manager *m_option_mgr;
+ option_id_manager *m_option_id_mgr;
unsigned m_lang_mask;
/* A stack of optional hooks for adding URLs to quoted text strings in
@@ -835,6 +764,7 @@ private:
bool m_inhibit_notes_p;
source_printing_options m_source_printing;
+ column_options m_column_options;
/* True if -freport-bug option is used. */
bool m_report_bug;
@@ -844,17 +774,6 @@ private:
-fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */
enum diagnostics_extra_output_kind m_extra_output_kind;
-public:
- /* What units to use when outputting the column number. */
- enum diagnostics_column_unit m_column_unit;
-
- /* The origin for the column number (1-based or 0-based typically). */
- int m_column_origin;
-
- /* The size of the tabstop for tab expansion. */
- int m_tabstop;
-
-private:
/* How should non-ASCII/non-printable bytes be escaped when
a diagnostic suggests escaping the source code on output. */
enum diagnostics_escape_format m_escape_format;
@@ -927,6 +846,11 @@ private:
later (if the buffer is flushed), moved to other buffers, or
discarded (if the buffer is cleared). */
buffer *m_diagnostic_buffer;
+
+ /* Owned by the context.
+ Debugging option: if non-NULL, report information to the logger
+ on what the context is doing. */
+ logging::logger *m_logger;
};
/* Client supplied function to announce a diagnostic