15
15
16
16
#include < util/expr.h>
17
17
18
- class c_qualifierst
18
+ class qualifierst
19
+ {
20
+ protected:
21
+ // Only derived classes can construct
22
+ qualifierst () = default ;
23
+
24
+ public:
25
+ // Copy/move construction/assignment is deleted here and in derived classes
26
+ qualifierst (const qualifierst &) = delete ;
27
+ qualifierst (qualifierst &&) = delete ;
28
+ qualifierst &operator =(const qualifierst &) = delete ;
29
+ qualifierst &operator =(qualifierst &&) = delete ;
30
+
31
+ // Destruction is virtual
32
+ virtual ~qualifierst () = default ;
33
+
34
+ public:
35
+ virtual std::unique_ptr<qualifierst> clone () const = 0;
36
+
37
+ virtual qualifierst &operator +=(const qualifierst &b) = 0 ;
38
+
39
+ virtual std::size_t count () const = 0;
40
+
41
+ virtual void clear () = 0;
42
+
43
+ virtual void read (const typet &src) = 0;
44
+ virtual void write (typet &src) const = 0;
45
+
46
+ // Comparisons
47
+ virtual bool is_subset_of (const qualifierst &q) const = 0;
48
+ virtual bool operator ==(const qualifierst &other) const = 0 ;
49
+ bool operator !=(const qualifierst &other) const
50
+ {
51
+ return !(*this == other);
52
+ }
53
+
54
+ // String conversion
55
+ virtual std::string as_string () const = 0;
56
+ friend std::ostream &operator <<(std::ostream &, const qualifierst &);
57
+ };
58
+
59
+
60
+ class c_qualifierst : public qualifierst
19
61
{
20
62
public:
21
63
c_qualifierst ()
@@ -29,13 +71,12 @@ class c_qualifierst
29
71
read (src);
30
72
}
31
73
32
- c_qualifierst (const c_qualifierst &other) = delete ;
33
- virtual c_qualifierst &operator =(const c_qualifierst &other);
34
- virtual std::unique_ptr<c_qualifierst> clone () const ;
35
-
36
- virtual ~c_qualifierst () = default ;
74
+ protected:
75
+ c_qualifierst &operator =(const c_qualifierst &other);
76
+ public:
77
+ virtual std::unique_ptr<qualifierst> clone () const override ;
37
78
38
- virtual void clear ()
79
+ virtual void clear () override
39
80
{
40
81
is_constant=false ;
41
82
is_volatile=false ;
@@ -57,62 +98,60 @@ class c_qualifierst
57
98
58
99
// will likely add alignment here as well
59
100
60
- virtual std::string as_string () const ;
61
- virtual void read (const typet &src);
62
- virtual void write (typet &src) const ;
101
+ virtual std::string as_string () const override ;
102
+ virtual void read (const typet &src) override ;
103
+ virtual void write (typet &src) const override ;
63
104
64
105
static void clear (typet &dest);
65
106
66
- virtual bool is_subset_of (const c_qualifierst &q ) const
107
+ virtual bool is_subset_of (const qualifierst &other ) const override
67
108
{
68
- return (!is_constant || q.is_constant ) &&
69
- (!is_volatile || q.is_volatile ) &&
70
- (!is_restricted || q.is_restricted ) &&
71
- (!is_atomic || q.is_atomic ) &&
72
- (!is_ptr32 || q.is_ptr32 ) &&
73
- (!is_ptr64 || q.is_ptr64 ) &&
74
- (!is_noreturn || q.is_noreturn );
109
+ const c_qualifierst *cq = dynamic_cast <const c_qualifierst *>(&other);
110
+ return
111
+ (!is_constant || cq->is_constant ) &&
112
+ (!is_volatile || cq->is_volatile ) &&
113
+ (!is_restricted || cq->is_restricted ) &&
114
+ (!is_atomic || cq->is_atomic ) &&
115
+ (!is_ptr32 || cq->is_ptr32 ) &&
116
+ (!is_ptr64 || cq->is_ptr64 ) &&
117
+ (!is_noreturn || cq->is_noreturn );
75
118
76
119
// is_transparent_union isn't checked
77
120
}
78
121
79
- virtual bool operator ==(const c_qualifierst &other) const
122
+ virtual bool operator ==(const qualifierst &other) const override
80
123
{
81
- return is_constant==other.is_constant &&
82
- is_volatile==other.is_volatile &&
83
- is_restricted==other.is_restricted &&
84
- is_atomic==other.is_atomic &&
85
- is_ptr32==other.is_ptr32 &&
86
- is_ptr64==other.is_ptr64 &&
87
- is_transparent_union==other.is_transparent_union &&
88
- is_noreturn==other.is_noreturn ;
124
+ const c_qualifierst *cq = dynamic_cast <const c_qualifierst *>(&other);
125
+ return
126
+ is_constant == cq->is_constant &&
127
+ is_volatile == cq->is_volatile &&
128
+ is_restricted == cq->is_restricted &&
129
+ is_atomic == cq->is_atomic &&
130
+ is_ptr32 == cq->is_ptr32 &&
131
+ is_ptr64 == cq->is_ptr64 &&
132
+ is_transparent_union == cq->is_transparent_union &&
133
+ is_noreturn == cq->is_noreturn ;
89
134
}
90
135
91
- bool operator ! =(const c_qualifierst &other) const
136
+ virtual qualifierst & operator + =(const qualifierst &other) override
92
137
{
93
- return !(*this ==other);
94
- }
95
-
96
- virtual c_qualifierst &operator +=(const c_qualifierst &b)
97
- {
98
- is_constant|=b.is_constant ;
99
- is_volatile|=b.is_volatile ;
100
- is_restricted|=b.is_restricted ;
101
- is_atomic|=b.is_atomic ;
102
- is_ptr32|=b.is_ptr32 ;
103
- is_ptr64|=b.is_ptr64 ;
104
- is_transparent_union|=b.is_transparent_union ;
105
- is_noreturn|=b.is_noreturn ;
138
+ const c_qualifierst *cq = dynamic_cast <const c_qualifierst *>(&other);
139
+ is_constant |= cq->is_constant ;
140
+ is_volatile |= cq->is_volatile ;
141
+ is_restricted |= cq->is_restricted ;
142
+ is_atomic |= cq->is_atomic ;
143
+ is_ptr32 |= cq->is_ptr32 ;
144
+ is_ptr64 |= cq->is_ptr64 ;
145
+ is_transparent_union |= cq->is_transparent_union ;
146
+ is_noreturn |= cq->is_noreturn ;
106
147
return *this ;
107
148
}
108
149
109
- virtual std::size_t count () const
150
+ virtual std::size_t count () const override
110
151
{
111
152
return is_constant+is_volatile+is_restricted+is_atomic+
112
153
is_ptr32+is_ptr64+is_noreturn;
113
154
}
114
155
};
115
156
116
- std::ostream &operator << (std::ostream &, const c_qualifierst &);
117
-
118
157
#endif // CPROVER_ANSI_C_C_QUALIFIERS_H
0 commit comments