aboutsummaryrefslogtreecommitdiff
path: root/gcc/diagnostic.h
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2023-11-06 14:28:41 -0500
committerDavid Malcolm <dmalcolm@redhat.com>2023-11-06 14:28:41 -0500
commit38763e2c188fa91dfba1a77206f12db41950935c (patch)
treecc6231694440857fc2d232dad8a28e8fe7074009 /gcc/diagnostic.h
parenta526cc6ff32e22e1a948c1c5f30d977d440c8da5 (diff)
downloadgcc-upstream-38763e2c188fa91dfba1a77206f12db41950935c.tar.gz
diagnostics: introduce class diagnostic_option_classifier
This patch gathers the 6 fields in diagnostic_context relating to keeping track of overriding the severity of warnings, and pushing/popping those severities, moving them all into a new class diagnostic_option_classifier. No functional change intended. gcc/ChangeLog: * diagnostic.cc (diagnostic_context::push_diagnostics): Convert to... (diagnostic_option_classifier::push): ...this. (diagnostic_context::pop_diagnostics): Convert to... (diagnostic_option_classifier::pop): ...this. (diagnostic_context::initialize): Move code to... (diagnostic_option_classifier::init): ...this new function. (diagnostic_context::finish): Move code to... (diagnostic_option_classifier::fini): ...this new function. (diagnostic_context::classify_diagnostic): Convert to... (diagnostic_option_classifier::classify_diagnostic): ...this. (diagnostic_context::update_effective_level_from_pragmas): Convert to... (diagnostic_option_classifier::update_effective_level_from_pragmas): ...this. (diagnostic_context::diagnostic_enabled): Update for refactoring. * diagnostic.h (struct diagnostic_classification_change_t): Move into... (class diagnostic_option_classifier): ...this new class. (diagnostic_context::option_unspecified_p): Update for move of fields into m_option_classifier. (diagnostic_context::classify_diagnostic): Likewise. (diagnostic_context::push_diagnostics): Likewise. (diagnostic_context::pop_diagnostics): Likewise. (diagnostic_context::update_effective_level_from_pragmas): Delete. (diagnostic_context::m_classify_diagnostic): Move into class diagnostic_option_classifier. (diagnostic_context::m_option_classifier): Likewise. (diagnostic_context::m_classification_history): Likewise. (diagnostic_context::m_n_classification_history): Likewise. (diagnostic_context::m_push_list): Likewise. (diagnostic_context::m_n_push): Likewise. (diagnostic_context::m_option_classifier): New. Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/diagnostic.h')
-rw-r--r--gcc/diagnostic.h131
1 files changed, 92 insertions, 39 deletions
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index f9950ec2cf8..b83cdeb35c1 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -168,16 +168,6 @@ struct diagnostic_info
} m_iinfo;
};
-/* Each time a diagnostic's classification is changed with a pragma,
- we record the change and the location of the change in an array of
- these structs. */
-struct diagnostic_classification_change_t
-{
- location_t location;
- int option;
- diagnostic_t kind;
-};
-
/* Forward declarations. */
typedef void (*diagnostic_starter_fn) (diagnostic_context *,
diagnostic_info *);
@@ -240,6 +230,79 @@ public:
void on_diagram (const diagnostic_diagram &diagram) override;
};
+/* A stack of sets of classifications: each entry in the stack is
+ a mapping from option index to diagnostic severity that can be changed
+ via pragmas. The stack can be pushed and popped. */
+
+class diagnostic_option_classifier
+{
+public:
+ void init (int n_opts);
+ void fini ();
+
+ /* Save all diagnostic classifications in a stack. */
+ void push ();
+
+ /* Restore the topmost classification set off the stack. If the stack
+ is empty, revert to the state based on command line parameters. */
+ void pop (location_t where);
+
+ bool option_unspecified_p (int opt) const
+ {
+ return get_current_override (opt) == DK_UNSPECIFIED;
+ }
+
+ diagnostic_t get_current_override (int opt) const
+ {
+ gcc_assert (opt < m_n_opts);
+ return m_classify_diagnostic[opt];
+ }
+
+ diagnostic_t
+ classify_diagnostic (const diagnostic_context *context,
+ int option_index,
+ diagnostic_t new_kind,
+ location_t where);
+
+ diagnostic_t
+ update_effective_level_from_pragmas (diagnostic_info *diagnostic) const;
+
+private:
+ /* Each time a diagnostic's classification is changed with a pragma,
+ we record the change and the location of the change in an array of
+ these structs. */
+ struct diagnostic_classification_change_t
+ {
+ location_t location;
+ int option;
+ diagnostic_t kind;
+ };
+
+ int m_n_opts;
+
+ /* For each option index that can be passed to warning() et al
+ (OPT_* from options.h when using this code with the core GCC
+ options), this array may contain a new kind that the diagnostic
+ should be changed to before reporting, or DK_UNSPECIFIED to leave
+ it as the reported kind, or DK_IGNORED to not report it at
+ all. */
+ diagnostic_t *m_classify_diagnostic;
+
+ /* History of all changes to the classifications above. This list
+ is stored in location-order, so we can search it, either
+ binary-wise or end-to-front, to find the most recent
+ classification for a given diagnostic, given the location of the
+ diagnostic. */
+ diagnostic_classification_change_t *m_classification_history;
+
+ /* The size of the above array. */
+ int m_n_classification_history;
+
+ /* For pragma push/pop. */
+ int *m_push_list;
+ int m_n_push;
+};
+
/* This data structure bundles altogether any information relevant to
the context of a diagnostic message. */
class diagnostic_context
@@ -273,8 +336,7 @@ public:
bool option_unspecified_p (int opt) const
{
- gcc_assert (opt < m_n_opts);
- return m_classify_diagnostic[opt] == DK_UNSPECIFIED;
+ return m_option_classifier.option_unspecified_p (opt);
}
bool report_diagnostic (diagnostic_info *);
@@ -287,9 +349,22 @@ public:
diagnostic_t
classify_diagnostic (int option_index,
diagnostic_t new_kind,
- location_t where);
- void push_diagnostics (location_t where ATTRIBUTE_UNUSED);
- void pop_diagnostics (location_t where);
+ location_t where)
+ {
+ return m_option_classifier.classify_diagnostic (this,
+ option_index,
+ new_kind,
+ where);
+ }
+
+ void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
+ {
+ m_option_classifier.push ();
+ }
+ void pop_diagnostics (location_t where)
+ {
+ m_option_classifier.pop (where);
+ }
void emit_diagram (const diagnostic_diagram &diagram);
@@ -376,9 +451,6 @@ private:
bool diagnostic_enabled (diagnostic_info *diagnostic);
void get_any_inlining_info (diagnostic_info *diagnostic);
- diagnostic_t
- update_effective_level_from_pragmas (diagnostic_info *diagnostic);
-
/* Data members.
Ideally, all of these would be private and have "m_" prefixes. */
@@ -401,27 +473,8 @@ private:
al. */
int m_n_opts;
- /* For each option index that can be passed to warning() et al
- (OPT_* from options.h when using this code with the core GCC
- options), this array may contain a new kind that the diagnostic
- should be changed to before reporting, or DK_UNSPECIFIED to leave
- it as the reported kind, or DK_IGNORED to not report it at
- all. */
- diagnostic_t *m_classify_diagnostic;
-
- /* History of all changes to the classifications above. This list
- is stored in location-order, so we can search it, either
- binary-wise or end-to-front, to find the most recent
- classification for a given diagnostic, given the location of the
- diagnostic. */
- diagnostic_classification_change_t *m_classification_history;
-
- /* The size of the above array. */
- int m_n_classification_history;
-
- /* For pragma push/pop. */
- int *m_push_list;
- int m_n_push;
+ /* The stack of sets of overridden diagnostic option severities. */
+ diagnostic_option_classifier m_option_classifier;
/* True if we should print any CWE identifiers associated with
diagnostics. */