diff options
Diffstat (limited to 'gcc/diagnostics/context.h')
-rw-r--r-- | gcc/diagnostics/context.h | 128 |
1 files changed, 16 insertions, 112 deletions
diff --git a/gcc/diagnostics/context.h b/gcc/diagnostics/context.h index f47370b..b6ec85c 100644 --- a/gcc/diagnostics/context.h +++ b/gcc/diagnostics/context.h @@ -23,7 +23,10 @@ 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/counters.h" namespace diagnostics { @@ -81,84 +84,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. */ @@ -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 @@ -398,6 +301,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); @@ -546,32 +450,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 { @@ -808,7 +712,7 @@ private: /* 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 |