ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
c_typecast.h
Go to the documentation of this file.
1#ifndef CPROVER_C_TYPECAST_H
2#define CPROVER_C_TYPECAST_H
3
4#include <util/irep/expr.h>
6
7// try a type cast from expr.type() to type
8//
9// false: typecast successfull, expr modified
10// true: typecast failed
11
15
16bool check_c_implicit_typecast(const typet &src_type, const typet &dest_type);
17
19 const type2tc &src_type,
20 const type2tc &dest_type);
21
23 const typet &src_type,
24 const typet &dest_type,
25 const namespacet &ns);
26
28 const type2tc &src_type,
29 const type2tc &dest_type,
30 const namespacet &ns);
31
33 exprt &expr,
34 const typet &dest_type,
35 const namespacet &ns);
36
38 expr2tc &expr,
39 const type2tc &dest_type,
40 const namespacet &ns);
41
43 exprt &expr1,
44 exprt &expr2,
45 const namespacet &ns);
46
48 expr2tc &expr1,
49 expr2tc &expr2,
50 const namespacet &ns);
51
53{
54public:
56 : ns(_ns), no_simplify(config.options.get_bool_option("no-simplify"))
57 {
58 }
59
60 virtual ~c_typecastt() = default;
61
62 virtual void implicit_typecast(exprt &expr, const typet &type);
63
64 virtual void implicit_typecast(expr2tc &expr, const type2tc &type);
65
66 virtual void implicit_typecast_arithmetic(exprt &expr);
67
68 virtual void implicit_typecast_arithmetic(expr2tc &expr);
69
70 virtual void implicit_typecast_arithmetic(exprt &expr1, exprt &expr2);
71
72 virtual void implicit_typecast_arithmetic(expr2tc &expr1, expr2tc &expr2);
73
74 std::list<std::string> errors;
75 std::list<std::string> warnings;
76
77protected:
78 const namespacet &ns;
80
82 {
92 // Integer rank, however wide, sits below every floating type
93 // (C17 6.3.1.8) and below PTR: pointer arithmetic converts neither
94 // operand (6.5.6).
103 };
104
105 c_typet get_c_type(const typet &type);
106 c_typet get_c_type(const type2tc &type);
107
108 // Shared by both get_c_type overloads so the two copies cannot drift on the
109 // width buckets, which is the divergence unit/util/c_typecast.test.cpp pins.
110 static c_typet rank_integer(unsigned width, bool is_signed);
111 static c_typet rank_floating(unsigned width);
112
113 void implicit_typecast_arithmetic(exprt &expr, c_typet c_type);
114
115 void implicit_typecast_arithmetic(expr2tc &expr, c_typet c_type);
116
118
120
121 // after follow_with_qualifiers
122 virtual void implicit_typecast_followed(
123 exprt &expr,
124 const typet &src_type,
125 const typet &dest_type);
126
127 virtual void implicit_typecast_followed(
128 expr2tc &expr,
129 const type2tc &src_type,
130 const type2tc &dest_type);
131
132 // Arms of the IREP2 implicit_typecast_followed, split out to keep it under
133 // the complexity gate. convert_reference returns true when a reference arm
134 // applied (the caller still runs the tail); convert_to_pointer returns true
135 // when the conversion is complete.
137 expr2tc &expr,
138 const type2tc &src_type,
139 const type2tc &dest_type);
140
142 expr2tc &expr,
143 const type2tc &src_type,
144 const type2tc &dest_type);
145
146 void do_typecast(exprt &dest, const typet &type);
147
148 void do_typecast(expr2tc &dest, const type2tc &type);
149};
150
151#endif
void take_reference_address(expr2tc &expr, pointer_ref_kindt rk)
Take the address of an object bound to a reference; see c_typecast.cpp for why a conditional takes it...
Definition c_typecast.cpp:783
bool c_implicit_typecast(exprt &expr, const typet &dest_type, const namespacet &ns)
Definition c_typecast.cpp:17
bool c_implicit_typecast_arithmetic(exprt &expr1, exprt &expr2, const namespacet &ns)
Definition c_typecast.cpp:62
bool check_c_implicit_typecast(const typet &src_type, const typet &dest_type)
Definition c_typecast.cpp:82
c_typet
Definition c_typecast.h:82
@ CHAR
Definition c_typecast.h:84
@ UCHAR
Definition c_typecast.h:85
@ PTR
Definition c_typecast.h:101
@ SINGLE
Definition c_typecast.h:97
@ INT
Definition c_typecast.h:86
@ LONGDOUBLE
Definition c_typecast.h:99
@ LONGLONG
Definition c_typecast.h:90
@ VOIDPTR
Definition c_typecast.h:100
@ BOOL
Definition c_typecast.h:83
@ INT128
Definition c_typecast.h:95
@ OTHER
Definition c_typecast.h:102
@ ULONGLONG
Definition c_typecast.h:91
@ ULONG
Definition c_typecast.h:89
@ DOUBLE
Definition c_typecast.h:98
@ UINT128
Definition c_typecast.h:96
@ LONG
Definition c_typecast.h:88
@ UINT
Definition c_typecast.h:87
c_typecastt(const namespacet &_ns)
Definition c_typecast.h:55
static c_typet rank_floating(unsigned width)
Definition c_typecast.cpp:327
typet follow_with_qualifiers(const typet &src)
Definition c_typecast.cpp:279
void do_typecast(exprt &dest, const typet &type)
Definition c_typecast.cpp:1007
virtual void implicit_typecast(exprt &expr, const typet &type)
Definition c_typecast.cpp:564
virtual ~c_typecastt()=default
virtual void implicit_typecast_followed(exprt &expr, const typet &src_type, const typet &dest_type)
Definition c_typecast.cpp:604
virtual void implicit_typecast_arithmetic(exprt &expr)
Definition c_typecast.cpp:550
std::list< std::string > warnings
Definition c_typecast.h:75
const namespacet & ns
Definition c_typecast.h:78
static c_typet rank_integer(unsigned width, bool is_signed)
Definition c_typecast.cpp:304
bool convert_to_pointer(expr2tc &expr, const type2tc &src_type, const type2tc &dest_type)
Definition c_typecast.cpp:887
bool no_simplify
Definition c_typecast.h:79
c_typet get_c_type(const typet &type)
Definition c_typecast.cpp:338
bool convert_reference(expr2tc &expr, const type2tc &src_type, const type2tc &dest_type)
The two reference arms, split out to keep implicit_typecast_followed under the complexity gate.
Definition c_typecast.cpp:809
std::list< std::string > errors
Definition c_typecast.h:74
Definition expr.h:34
Definition namespace.h:10
Definition type.h:9
configt config
Definition config.cpp:8
irep_container< type2t > type2tc
Definition irep2.h:430
irep_container< expr2t > expr2tc
Definition irep2.h:431
pointer_ref_kindt
How the source spelled a pointer.
Definition irep2_type.h:556