]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/diagnostic-spec.h
Update copyright years.
[thirdparty/gcc.git] / gcc / diagnostic-spec.h
1 /* Language-independent APIs to enable/disable per-location warnings.
2
3 Copyright (C) 2021-2022 Free Software Foundation, Inc.
4 Contributed by Martin Sebor <msebor@redhat.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
21
22 #ifndef DIAGNOSTIC_SPEC_H_INCLUDED
23 #define DIAGNOSTIC_SPEC_H_INCLUDED
24
25 #include "hash-map.h"
26
27 /* A "bitset" of warning groups. */
28
29 class nowarn_spec_t
30 {
31 public:
32 enum
33 {
34 /* Middle end warnings about invalid accesses. */
35 NW_ACCESS = 1 << 0,
36 /* Front end/lexical warnings. */
37 NW_LEXICAL = 1 << 1,
38 /* Warnings about null pointers. */
39 NW_NONNULL = 1 << 2,
40 /* Warnings about uninitialized reads. */
41 NW_UNINIT = 1 << 3,
42 /* Warnings about arithmetic overflow. */
43 NW_VFLOW = 1 << 4,
44 /* All other unclassified warnings. */
45 NW_OTHER = 1 << 5,
46 /* All groups of warnings. */
47 NW_ALL = (NW_ACCESS | NW_LEXICAL | NW_NONNULL
48 | NW_UNINIT | NW_VFLOW | NW_OTHER)
49 };
50
51 nowarn_spec_t (): m_bits () { }
52
53 nowarn_spec_t (opt_code);
54
55 /* Return the raw bitset. */
56 operator unsigned() const
57 {
58 return m_bits;
59 }
60
61 /* Return true if the bitset is clear. */
62 bool operator!() const
63 {
64 return !m_bits;
65 }
66
67 /* Return the inverse of the bitset. */
68 nowarn_spec_t operator~() const
69 {
70 nowarn_spec_t res (*this);
71 res.m_bits &= ~NW_ALL;
72 return res;
73 }
74
75 /* Set *THIS to the bitwise OR of *THIS and RHS. */
76 nowarn_spec_t& operator|= (const nowarn_spec_t &rhs)
77 {
78 m_bits |= rhs.m_bits;
79 return *this;
80 }
81
82 /* Set *THIS to the bitwise AND of *THIS and RHS. */
83 nowarn_spec_t& operator&= (const nowarn_spec_t &rhs)
84 {
85 m_bits &= rhs.m_bits;
86 return *this;
87 }
88
89 /* Set *THIS to the bitwise exclusive OR of *THIS and RHS. */
90 nowarn_spec_t& operator^= (const nowarn_spec_t &rhs)
91 {
92 m_bits ^= rhs.m_bits;
93 return *this;
94 }
95
96 private:
97 /* Bitset of warning groups. */
98 unsigned m_bits;
99 };
100
101 /* Return the bitwise OR of LHS and RHS. */
102
103 inline nowarn_spec_t
104 operator| (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
105 {
106 return nowarn_spec_t (lhs) |= rhs;
107 }
108
109 /* Return the bitwise AND of LHS and RHS. */
110
111 inline nowarn_spec_t
112 operator& (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
113 {
114 return nowarn_spec_t (lhs) &= rhs;
115 }
116
117 /* Return true if LHS is equal RHS. */
118
119 inline bool
120 operator== (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
121 {
122 return static_cast<unsigned>(lhs) == static_cast<unsigned>(rhs);
123 }
124
125 /* Return true if LHS is not equal RHS. */
126
127 inline bool
128 operator!= (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs)
129 {
130 return !(lhs == rhs);
131 }
132
133 typedef hash_map<location_hash, nowarn_spec_t> nowarn_map_t;
134
135 /* A mapping from a 'location_t' to the warning spec set for it. */
136 extern GTY(()) nowarn_map_t *nowarn_map;
137
138 #endif // DIAGNOSTIC_SPEC_H_INCLUDED