Go to the documentation of this file.
27 const typet &dest_type,
32 return !c_typecast.
errors.empty();
36 const typet &src_type,
37 const typet &dest_type,
44 return !c_typecast.
errors.empty();
54 return !c_typecast.
errors.empty();
59 if(type.
id()==ID_pointer)
73 const typet &src_type,
74 const typet &dest_type)
79 src_type.
id() == ID_pointer && dest_type.
id() == ID_pointer &&
86 if(src_type==dest_type)
91 if(src_type_id==ID_c_bit_field)
97 if(dest_type.
id()==ID_c_bit_field)
103 if(src_type_id==ID_natural)
105 if(dest_type.
id()==ID_bool ||
106 dest_type.
id()==ID_c_bool ||
107 dest_type.
id()==ID_integer ||
108 dest_type.
id()==ID_real ||
109 dest_type.
id()==ID_complex ||
110 dest_type.
id()==ID_unsignedbv ||
111 dest_type.
id()==ID_signedbv ||
112 dest_type.
id()==ID_floatbv ||
113 dest_type.
id()==ID_complex)
116 else if(src_type_id==ID_integer)
118 if(dest_type.
id()==ID_bool ||
119 dest_type.
id()==ID_c_bool ||
120 dest_type.
id()==ID_real ||
121 dest_type.
id()==ID_complex ||
122 dest_type.
id()==ID_unsignedbv ||
123 dest_type.
id()==ID_signedbv ||
124 dest_type.
id()==ID_floatbv ||
125 dest_type.
id()==ID_fixedbv ||
126 dest_type.
id()==ID_pointer ||
127 dest_type.
id()==ID_complex)
130 else if(src_type_id==ID_real)
132 if(dest_type.
id()==ID_bool ||
133 dest_type.
id()==ID_c_bool ||
134 dest_type.
id()==ID_complex ||
135 dest_type.
id()==ID_floatbv ||
136 dest_type.
id()==ID_fixedbv ||
137 dest_type.
id()==ID_complex)
140 else if(src_type_id==ID_rational)
142 if(dest_type.
id()==ID_bool ||
143 dest_type.
id()==ID_c_bool ||
144 dest_type.
id()==ID_complex ||
145 dest_type.
id()==ID_floatbv ||
146 dest_type.
id()==ID_fixedbv ||
147 dest_type.
id()==ID_complex)
150 else if(src_type_id==ID_bool)
152 if(dest_type.
id()==ID_c_bool ||
153 dest_type.
id()==ID_integer ||
154 dest_type.
id()==ID_real ||
155 dest_type.
id()==ID_unsignedbv ||
156 dest_type.
id()==ID_signedbv ||
157 dest_type.
id()==ID_pointer ||
158 dest_type.
id()==ID_floatbv ||
159 dest_type.
id()==ID_fixedbv ||
160 dest_type.
id()==ID_c_enum ||
161 dest_type.
id()==ID_c_enum_tag ||
162 dest_type.
id()==ID_complex)
165 else if(src_type_id==ID_unsignedbv ||
166 src_type_id==ID_signedbv ||
167 src_type_id==ID_c_enum ||
168 src_type_id==ID_c_enum_tag ||
169 src_type_id==ID_c_bool)
171 if(dest_type.
id()==ID_unsignedbv ||
172 dest_type.
id()==ID_bool ||
173 dest_type.
id()==ID_c_bool ||
174 dest_type.
id()==ID_integer ||
175 dest_type.
id()==ID_real ||
176 dest_type.
id()==ID_rational ||
177 dest_type.
id()==ID_signedbv ||
178 dest_type.
id()==ID_floatbv ||
179 dest_type.
id()==ID_fixedbv ||
180 dest_type.
id()==ID_pointer ||
181 dest_type.
id()==ID_c_enum ||
182 dest_type.
id()==ID_c_enum_tag ||
183 dest_type.
id()==ID_complex)
186 else if(src_type_id==ID_floatbv ||
187 src_type_id==ID_fixedbv)
189 if(dest_type.
id()==ID_bool ||
190 dest_type.
id()==ID_c_bool ||
191 dest_type.
id()==ID_integer ||
192 dest_type.
id()==ID_real ||
193 dest_type.
id()==ID_rational ||
194 dest_type.
id()==ID_signedbv ||
195 dest_type.
id()==ID_unsignedbv ||
196 dest_type.
id()==ID_floatbv ||
197 dest_type.
id()==ID_fixedbv ||
198 dest_type.
id()==ID_complex)
201 else if(src_type_id==ID_complex)
203 if(dest_type.
id()==ID_complex)
222 else if(src_type_id==ID_array ||
223 src_type_id==ID_pointer)
225 if(dest_type.
id()==ID_pointer)
230 if(src_subtype == dest_subtype)
249 if(dest_type.
id()==ID_bool ||
250 dest_type.
id()==ID_c_bool ||
251 dest_type.
id()==ID_unsignedbv ||
252 dest_type.
id()==ID_signedbv)
255 else if(src_type_id==ID_vector)
257 if(dest_type.
id()==ID_vector)
260 else if(src_type_id==ID_complex)
262 if(dest_type.
id()==ID_complex)
281 src_type.
id() != ID_struct_tag &&
282 src_type.
id() != ID_union_tag)
287 typet result_type=src_type;
292 while(result_type.
id() == ID_struct_tag || result_type.
id() == ID_union_tag)
295 result_type = followed_type;
299 qualifiers.
write(result_type);
305 const typet &type)
const
307 if(type.
id()==ID_signedbv)
324 else if(type.
id()==ID_unsignedbv)
341 else if(type.
id()==ID_bool)
343 else if(type.
id()==ID_c_bool)
345 else if(type.
id()==ID_floatbv)
358 else if(type.
id()==ID_fixedbv)
362 else if(type.
id()==ID_pointer)
369 else if(type.
id()==ID_array)
373 else if(type.
id() == ID_c_enum || type.
id() == ID_c_enum_tag)
377 else if(type.
id()==ID_rational)
379 else if(type.
id()==ID_real)
381 else if(type.
id()==ID_complex)
383 else if(type.
id()==ID_c_bit_field)
389 typet underlying_type;
391 if(bit_field_type.underlying_type().id() == ID_c_enum_tag)
393 const auto &followed =
395 if(followed.is_incomplete())
398 underlying_type = followed.underlying_type();
401 underlying_type = bit_field_type.underlying_type();
404 underlying_type.
id(), bit_field_type.get_width());
408 else if(type.
id() == ID_integer)
423 if(expr.
type().
id() == ID_array)
458 if(new_type != expr.
type())
463 const typet &type)
const
487 type.
id()==ID_c_bit_field &&
507 typet type_qual=type;
509 qualifiers.
write(type_qual);
516 const typet &src_type,
517 const typet &orig_dest_type,
518 const typet &dest_type)
521 if(dest_type.
id()==ID_union &&
522 dest_type.
get_bool(ID_C_transparent_union) &&
523 src_type.
id()!=ID_union)
533 typet src_type_no_const=src_type;
535 src_type.
id() == ID_pointer &&
542 for(
const auto &comp :
to_union_type(dest_type).components())
547 union_exprt union_expr(comp.get_name(), expr, orig_dest_type);
548 if(!src_type.
full_eq(src_type_no_const))
556 if(dest_type.
id()==ID_pointer)
561 src_type.
id()==ID_unsignedbv ||
562 src_type.
id()==ID_signedbv ||
563 src_type.
id()==ID_natural ||
564 src_type.
id()==ID_integer))
570 if(src_type.
id()==ID_pointer ||
571 src_type.
id()==ID_array)
582 else if(src_sub.
id()==ID_code &&
583 dest_sub.
id()==ID_code)
588 else if(src_sub == dest_sub)
593 src_sub.
id()==ID_c_enum ||
594 src_sub.
id()==ID_c_enum_tag) &&
596 dest_sub.
id()==ID_c_enum ||
597 src_sub.
id()==ID_c_enum_tag))
603 src_sub.
id() == ID_array && dest_sub.
id() == ID_array &&
611 warnings.push_back(
"incompatible pointer types");
619 warnings.push_back(
"disregarding volatile");
622 if(src_type==dest_type)
624 expr.
type()=src_type;
634 errors.push_back(
"implicit conversion not permitted");
635 else if(src_type!=dest_type)
649 c_typet max_type=std::max(c_type1, c_type2);
654 typet result_type = (max_type == c_type1) ? type1 : type2;
723 else if(max_type ==
OTHER)
725 errors.push_back(
"implicit arithmetic conversion not permitted");
740 if(src_type.
id()==ID_array)
747 if(src_type!=dest_type)
754 if(dest_type.
get(ID_C_c_type)==ID_bool)
758 else if(dest_type.
id()==ID_bool)
#define UNREACHABLE
This should be used to mark dead code.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
static exprt conditional_cast(const exprt &expr, const typet &type)
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
signedbv_typet signed_long_long_int_type()
Unbounded, signed rational numbers.
bool full_eq(const irept &other) const
The type of an expression, extends irept.
floatbv_typet long_double_type()
Union constructor from single element.
Unbounded, signed integers (mathematical integers, not bitvectors)
const type_with_subtypet & to_type_with_subtype(const typet &type)
Base class for all expressions.
static ieee_float_spect quadruple_precision()
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
bool c_implicit_typecast_arithmetic(exprt &expr1, exprt &expr2, const namespacet &ns)
perform arithmetic prompotions and conversions
c_typet minimum_promotion(const typet &type) const
struct configt::ansi_ct ansi_c
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
const fixedbv_typet & to_fixedbv_type(const typet &type)
Cast a typet to a fixedbv_typet.
const irep_idt & get(const irep_idt &name) const
unsignedbv_typet unsigned_long_long_int_type()
unsignedbv_typet unsigned_long_int_type()
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
typet & type()
Return the type of the expression.
c_typet get_c_type(const typet &type) const
std::list< std::string > warnings
Unbounded, signed real numbers.
signedbv_typet signed_int_type()
bool check_c_implicit_typecast(const typet &src_type, const typet &dest_type, const namespacet &ns)
The null pointer constant.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
class floatbv_typet to_type() const
virtual void write(typet &src) const override
floatbv_typet float_type()
std::size_t long_long_int_width
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
exprt simplify_expr(exprt src, const namespacet &ns)
pointer_typet pointer_type(const typet &subtype)
unsignedbv_typet unsigned_int_type()
const irep_idt & id() const
bool c_implicit_typecast(exprt &expr, const typet &dest_type, const namespacet &ns)
virtual void implicit_typecast_followed(exprt &expr, const typet &src_type, const typet &orig_dest_type, const typet &dest_type)
floatbv_typet double_type()
std::size_t get_width() const
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
Deprecated expression utility functions.
bool has_a_void_pointer(const typet &type)
virtual void implicit_typecast_arithmetic(exprt &expr)
Base class of fixed-width bit-vector types.
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
exprt is_not_zero(const exprt &src, const namespacet &ns)
converts a scalar/float expression to C/C++ Booleans
std::list< std::string > errors
const typet & base_type() const
The type of the data what we point to.
std::size_t long_double_width
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
std::size_t short_int_width
const typet & subtype() const
signedbv_typet signed_long_int_type()
There are a large number of kinds of tree structured or tree-like data in CPROVER.
void remove(const irep_idt &name)
Operator to return the address of an object.
Semantic type conversion.
virtual void implicit_typecast(exprt &expr, const typet &type)
typet follow_with_qualifiers(const typet &src)
void do_typecast(exprt &dest, const typet &type)
bitvector_typet c_index_type()
bool get_bool(const irep_idt &name) const
std::size_t long_int_width
const typet & element_type() const
The type of the elements of the array.