GCC Middle and Back End API Reference
option-classifier.h
Go to the documentation of this file.
1/* Stacks of set of classifications of diagnostics.
2 Copyright (C) 2000-2025 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
8Software Foundation; either version 3, or (at your option) any later
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
19
20#ifndef GCC_DIAGNOSTICS_OPTION_CLASSIFIER_H
21#define GCC_DIAGNOSTICS_OPTION_CLASSIFIER_H
22
24#include "diagnostics/kinds.h"
25
26namespace diagnostics {
27
28/* Forward declarations. */
29class context;
30struct diagnostic_info;
31
32/* A stack of sets of classifications: each entry in the stack is
33 a mapping from option index to diagnostic severity that can be changed
34 via pragmas. The stack can be pushed and popped. */
35
37{
38public:
39 void init (int n_opts);
40 void fini ();
41
42 /* Save all diagnostic classifications in a stack. */
43 void push ();
44
45 /* Restore the topmost classification set off the stack. If the stack
46 is empty, revert to the state based on command line parameters. */
47 void pop (location_t where);
48
49 bool option_unspecified_p (option_id opt_id) const
50 {
51 return get_current_override (opt_id) == kind::unspecified;
52 }
53
55 {
56 gcc_assert (opt_id.m_idx < m_n_opts);
57 return m_classify_diagnostic[opt_id.m_idx];
58 }
59
60 enum kind
62 option_id opt_id,
63 enum kind new_kind,
64 location_t where);
65
66 enum kind
68
69 int pch_save (FILE *);
70 int pch_restore (FILE *);
71
72private:
73 /* Each time a diagnostic's classification is changed with a pragma,
74 we record the change and the location of the change in an array of
75 these structs. */
77 {
78 location_t location;
79
80 /* For kind::pop, this is the index of the corresponding push (as stored
81 in m_push_list).
82 Otherwise, this is an option index. */
83 int option;
84
85 enum kind kind;
86 };
87
89
90 /* For each option index that can be passed to warning() et al
91 (OPT_* from options.h when using this code with the core GCC
92 options), this array may contain a new kind that the diagnostic
93 should be changed to before reporting, or kind::unspecified to leave
94 it as the reported kind, or kind::ignored to not report it at
95 all. */
97
98 /* History of all changes to the classifications above. This list
99 is stored in location-order, so we can search it, either
100 binary-wise or end-to-front, to find the most recent
101 classification for a given diagnostic, given the location of the
102 diagnostic. */
104
105 /* For context::get_classification_history, declared later. */
106 friend class context;
107
108 /* For pragma push/pop. */
110};
111
112} // namespace diagnostics
113
114#endif /* ! GCC_DIAGNOSTICS_OPTION_CLASSIFIER_H */
Definition diagnostics/context.h:254
Definition option-classifier.h:37
enum kind get_current_override(option_id opt_id) const
Definition option-classifier.h:54
void init(int n_opts)
Definition option-classifier.cc:30
vec< int > m_push_list
Definition option-classifier.h:109
int m_n_opts
Definition option-classifier.h:88
enum kind update_effective_level_from_pragmas(diagnostic_info *diagnostic) const
Definition option-classifier.cc:180
bool option_unspecified_p(option_id opt_id) const
Definition option-classifier.h:49
int pch_restore(FILE *)
Definition option-classifier.cc:73
int pch_save(FILE *)
Definition option-classifier.cc:53
enum kind classify_diagnostic(const context *context, option_id opt_id, enum kind new_kind, location_t where)
Definition option-classifier.cc:124
void fini()
Definition option-classifier.cc:41
friend class context
Definition option-classifier.h:106
vec< classification_change_t > m_classification_history
Definition option-classifier.h:103
void push()
Definition option-classifier.cc:96
enum kind * m_classify_diagnostic
Definition option-classifier.h:96
Definition coretypes.h:167
kind
Definition kinds.h:27
@ pop
Definition kinds.h:34
Definition libgdiagnostics.cc:1256
Definition diagnostic-info.h:32
enum kind kind
Definition option-classifier.h:85
int option
Definition option-classifier.h:83
location_t location
Definition option-classifier.h:78
Definition option-id.h:32
int m_idx
Definition option-id.h:44
Definition vec.h:450
#define gcc_assert(EXPR)
Definition system.h:814