CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
c_qualifiers.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module:
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
9#include "c_qualifiers.h"
10
11#include <util/type.h>
12
26
27std::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
34std::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
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
65void 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
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
87
89 is_nodiscard = true;
90
91 if(src.get_bool(ID_C_noreturn))
92 is_noreturn=true;
93}
94
95void 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
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
131
132 if(is_nodiscard)
133 dest.set(ID_C_nodiscard, true);
134 else
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);
148 dest.remove(ID_C_ptr32);
149 dest.remove(ID_C_ptr64);
152 dest.remove(ID_C_noreturn);
153}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
virtual void write(typet &src) const
virtual void read(const typet &src)
bool is_transparent_union
virtual std::unique_ptr< c_qualifierst > clone() const
virtual void clear()
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.