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
23namespace diagnostics {
24
25/* Forward declarations. */
26class context;
27
28/* A stack of sets of classifications: each entry in the stack is
29 a mapping from option index to diagnostic severity that can be changed
30 via pragmas. The stack can be pushed and popped. */
31
33{
34public:
35 void init (int n_opts);
36 void fini ();
37
38 /* Save all diagnostic classifications in a stack. */
39 void push ();
40
41 /* Restore the topmost classification set off the stack. If the stack
42 is empty, revert to the state based on command line parameters. */
43 void pop (location_t where);
44
45 bool option_unspecified_p (option_id opt_id) const
46 {
47 return get_current_override (opt_id) == kind::unspecified;
48 }
49
51 {
52 gcc_assert (opt_id.m_idx < m_n_opts);
53 return m_classify_diagnostic[opt_id.m_idx];
54 }
55
56 enum kind
58 option_id opt_id,
59 enum kind new_kind,
60 location_t where);
61
62 enum kind
64
65 int pch_save (FILE *);
66 int pch_restore (FILE *);
67
68private:
69 /* Each time a diagnostic's classification is changed with a pragma,
70 we record the change and the location of the change in an array of
71 these structs. */
73 {
74 location_t location;
75
76 /* For kind::pop, this is the index of the corresponding push (as stored
77 in m_push_list).
78 Otherwise, this is an option index. */
79 int option;
80
81 enum kind kind;
82 };
83
85
86 /* For each option index that can be passed to warning() et al
87 (OPT_* from options.h when using this code with the core GCC
88 options), this array may contain a new kind that the diagnostic
89 should be changed to before reporting, or kind::unspecified to leave
90 it as the reported kind, or kind::ignored to not report it at
91 all. */
93
94 /* History of all changes to the classifications above. This list
95 is stored in location-order, so we can search it, either
96 binary-wise or end-to-front, to find the most recent
97 classification for a given diagnostic, given the location of the
98 diagnostic. */
100
101 /* For context::get_classification_history, declared later. */
102 friend class context;
103
104 /* For pragma push/pop. */
106};
107
108} // namespace diagnostics
109
110#endif /* ! GCC_DIAGNOSTICS_OPTION_CLASSIFIER_H */
Definition diagnostics/context.h:253
Definition option-classifier.h:33
enum kind get_current_override(option_id opt_id) const
Definition option-classifier.h:50
void init(int n_opts)
Definition option-classifier.cc:30
vec< int > m_push_list
Definition option-classifier.h:105
int m_n_opts
Definition option-classifier.h:84
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:45
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:102
vec< classification_change_t > m_classification_history
Definition option-classifier.h:99
void push()
Definition option-classifier.cc:96
enum kind * m_classify_diagnostic
Definition option-classifier.h:92
Definition coretypes.h:167
kind
Definition kinds.h:27
@ pop
Definition kinds.h:34
Definition libgdiagnostics.cc:1249
Definition diagnostic-info.h:32
enum kind kind
Definition option-classifier.h:81
int option
Definition option-classifier.h:79
location_t location
Definition option-classifier.h:74
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