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