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_noreturn = other.is_noreturn;
20  is_ptr32 = other.is_ptr32;
21  is_ptr64 = other.is_ptr64;
23  return *this;
24 }
25 
26 std::unique_ptr<qualifierst> c_qualifierst::clone() const
27 {
28  auto other = std::make_unique<c_qualifierst>();
29  *other = *this;
30  return std::move(other);
31 }
32 
33 std::string c_qualifierst::as_string() const
34 {
35  std::string qualifiers;
36 
37  if(is_constant)
38  qualifiers+="const ";
39 
40  if(is_volatile)
41  qualifiers+="volatile ";
42 
43  if(is_restricted)
44  qualifiers+="restrict ";
45 
46  if(is_atomic)
47  qualifiers+="_Atomic ";
48 
49  if(is_ptr32)
50  qualifiers+="__ptr32 ";
51 
52  if(is_ptr64)
53  qualifiers+="__ptr64 ";
54 
55  if(is_noreturn)
56  qualifiers+="_Noreturn ";
57 
58  return qualifiers;
59 }
60 
61 void c_qualifierst::read(const typet &src)
62 {
63  if(src.get_bool(ID_C_constant))
64  is_constant=true;
65 
66  if(src.get_bool(ID_C_volatile))
67  is_volatile=true;
68 
69  if(src.get_bool(ID_C_restricted))
70  is_restricted=true;
71 
72  if(src.get_bool(ID_C_atomic))
73  is_atomic=true;
74 
75  if(src.get_bool(ID_C_ptr32))
76  is_ptr32=true;
77 
78  if(src.get_bool(ID_C_ptr64))
79  is_ptr64=true;
80 
81  if(src.get_bool(ID_C_transparent_union))
83 
84  if(src.get_bool(ID_C_noreturn))
85  is_noreturn=true;
86 }
87 
88 void c_qualifierst::write(typet &dest) const
89 {
90  if(is_constant)
91  dest.set(ID_C_constant, true);
92  else
93  dest.remove(ID_C_constant);
94 
95  if(is_volatile)
96  dest.set(ID_C_volatile, true);
97  else
98  dest.remove(ID_C_volatile);
99 
100  if(is_restricted)
101  dest.set(ID_C_restricted, true);
102  else
103  dest.remove(ID_C_restricted);
104 
105  if(is_atomic)
106  dest.set(ID_C_atomic, true);
107  else
108  dest.remove(ID_C_atomic);
109 
110  if(is_ptr32)
111  dest.set(ID_C_ptr32, true);
112  else
113  dest.remove(ID_C_ptr32);
114 
115  if(is_ptr64)
116  dest.set(ID_C_ptr64, true);
117  else
118  dest.remove(ID_C_ptr64);
119 
121  dest.set(ID_C_transparent_union, true);
122  else
123  dest.remove(ID_C_transparent_union);
124 
125  if(is_noreturn)
126  dest.set(ID_C_noreturn, true);
127  else
128  dest.remove(ID_C_noreturn);
129 }
130 
132 {
133  dest.remove(ID_C_constant);
134  dest.remove(ID_C_volatile);
135  dest.remove(ID_C_restricted);
136  dest.remove(ID_C_ptr32);
137  dest.remove(ID_C_ptr64);
138  dest.remove(ID_C_transparent_union);
139  dest.remove(ID_C_noreturn);
140 }
141 
143 std::ostream &operator<<(std::ostream &out, const qualifierst &qualifiers)
144 {
145  return out << qualifiers.as_string();
146 }
std::ostream & operator<<(std::ostream &out, const qualifierst &qualifiers)
pretty-print the qualifiers
virtual void clear() override
Definition: c_qualifiers.h:80
bool is_restricted
Definition: c_qualifiers.h:92
virtual std::string as_string() const override
virtual void write(typet &src) const override
bool is_transparent_union
Definition: c_qualifiers.h:98
virtual std::unique_ptr< qualifierst > clone() const override
virtual void read(const typet &src) override
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:408
virtual std::string as_string() const =0
The type of an expression, extends irept.
Definition: type.h:29
Defines typet, type_with_subtypet and type_with_subtypest.