CBMC
c_qualifiers.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "c_qualifiers.h"
10 
11 #include <util/type.h>
12 
14 {
15  is_constant = other.is_constant;
16  is_volatile = other.is_volatile;
18  is_atomic = other.is_atomic;
19  is_nodiscard = other.is_nodiscard;
20  is_noreturn = other.is_noreturn;
21  is_ptr32 = other.is_ptr32;
22  is_ptr64 = other.is_ptr64;
24  return *this;
25 }
26 
27 std::unique_ptr<c_qualifierst> c_qualifierst::clone() const
28 {
29  auto other = std::make_unique<c_qualifierst>();
30  *other = *this;
31  return other;
32 }
33 
34 std::string c_qualifierst::as_string() const
35 {
36  std::string qualifiers;
37 
38  if(is_constant)
39  qualifiers+="const ";
40 
41  if(is_volatile)
42  qualifiers+="volatile ";
43 
44  if(is_restricted)
45  qualifiers+="restrict ";
46 
47  if(is_atomic)
48  qualifiers+="_Atomic ";
49 
50  if(is_ptr32)
51  qualifiers+="__ptr32 ";
52 
53  if(is_ptr64)
54  qualifiers+="__ptr64 ";
55 
56  if(is_nodiscard)
57  qualifiers += "[[nodiscard]] ";
58 
59  if(is_noreturn)
60  qualifiers+="_Noreturn ";
61 
62  return qualifiers;
63 }
64 
65 void c_qualifierst::read(const typet &src)
66 {
67  if(src.get_bool(ID_C_constant))
68  is_constant=true;
69 
70  if(src.get_bool(ID_C_volatile))
71  is_volatile=true;
72 
73  if(src.get_bool(ID_C_restricted))
74  is_restricted=true;
75 
76  if(src.get_bool(ID_C_atomic))
77  is_atomic=true;
78 
79  if(src.get_bool(ID_C_ptr32))
80  is_ptr32=true;
81 
82  if(src.get_bool(ID_C_ptr64))
83  is_ptr64=true;
84 
85  if(src.get_bool(ID_C_transparent_union))
87 
88  if(src.get_bool(ID_C_nodiscard))
89  is_nodiscard = true;
90 
91  if(src.get_bool(ID_C_noreturn))
92  is_noreturn=true;
93 }
94 
95 void c_qualifierst::write(typet &dest) const
96 {
97  if(is_constant)
98  dest.set(ID_C_constant, true);
99  else
100  dest.remove(ID_C_constant);
101 
102  if(is_volatile)
103  dest.set(ID_C_volatile, true);
104  else
105  dest.remove(ID_C_volatile);
106 
107  if(is_restricted)
108  dest.set(ID_C_restricted, true);
109  else
110  dest.remove(ID_C_restricted);
111 
112  if(is_atomic)
113  dest.set(ID_C_atomic, true);
114  else
115  dest.remove(ID_C_atomic);
116 
117  if(is_ptr32)
118  dest.set(ID_C_ptr32, true);
119  else
120  dest.remove(ID_C_ptr32);
121 
122  if(is_ptr64)
123  dest.set(ID_C_ptr64, true);
124  else
125  dest.remove(ID_C_ptr64);
126 
128  dest.set(ID_C_transparent_union, true);
129  else
130  dest.remove(ID_C_transparent_union);
131 
132  if(is_nodiscard)
133  dest.set(ID_C_nodiscard, true);
134  else
135  dest.remove(ID_C_nodiscard);
136 
137  if(is_noreturn)
138  dest.set(ID_C_noreturn, true);
139  else
140  dest.remove(ID_C_noreturn);
141 }
142 
144 {
145  dest.remove(ID_C_constant);
146  dest.remove(ID_C_volatile);
147  dest.remove(ID_C_restricted);
148  dest.remove(ID_C_ptr32);
149  dest.remove(ID_C_ptr64);
150  dest.remove(ID_C_transparent_union);
151  dest.remove(ID_C_nodiscard);
152  dest.remove(ID_C_noreturn);
153 }
bool is_restricted
Definition: c_qualifiers.h:52
virtual void write(typet &src) const
virtual void read(const typet &src)
bool is_transparent_union
Definition: c_qualifiers.h:59
virtual std::unique_ptr< c_qualifierst > clone() const
virtual void clear()
Definition: c_qualifiers.h:39
virtual std::string as_string() const
c_qualifierst & operator=(const c_qualifierst &other)
bool get_bool(const irep_idt &name) const
Definition: irep.cpp:57
void remove(const irep_idt &name)
Definition: irep.cpp:87
void set(const irep_idt &name, const irep_idt &value)
Definition: irep.h:412
The type of an expression, extends irept.
Definition: type.h:29
Defines typet, type_with_subtypet and type_with_subtypest.