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;
293 auto struct_tag_type = type_try_dynamic_cast<struct_tag_typet>(result_type))
296 result_type = followed_type;
300 auto union_tag_type = type_try_dynamic_cast<union_tag_typet>(result_type))
303 result_type = followed_type;
307 qualifiers.
write(result_type);
313 const typet &type)
const
315 if(type.
id()==ID_signedbv)
332 else if(type.
id()==ID_unsignedbv)
349 else if(type.
id()==ID_bool)
351 else if(type.
id()==ID_c_bool)
353 else if(type.
id()==ID_floatbv)
366 else if(type.
id()==ID_fixedbv)
370 else if(type.
id()==ID_pointer)
377 else if(type.
id()==ID_array)
381 else if(type.
id() == ID_c_enum || type.
id() == ID_c_enum_tag)
385 else if(type.
id()==ID_rational)
387 else if(type.
id()==ID_real)
389 else if(type.
id()==ID_complex)
391 else if(type.
id()==ID_c_bit_field)
397 typet underlying_type;
399 if(bit_field_type.underlying_type().id() == ID_c_enum_tag)
401 const auto &followed =
403 if(followed.is_incomplete())
406 underlying_type = followed.underlying_type();
409 underlying_type = bit_field_type.underlying_type();
412 underlying_type.
id(), bit_field_type.get_width());
416 else if(type.
id() == ID_integer)
431 if(expr.
type().
id() == ID_array)
466 if(new_type != expr.
type())
471 const typet &type)
const
495 type.
id()==ID_c_bit_field &&
515 typet type_qual=type;
517 qualifiers.
write(type_qual);
524 const typet &src_type,
525 const typet &orig_dest_type,
526 const typet &dest_type)
529 if(dest_type.
id()==ID_union &&
530 dest_type.
get_bool(ID_C_transparent_union) &&
531 src_type.
id()!=ID_union)
541 typet src_type_no_const=src_type;
543 src_type.
id() == ID_pointer &&
550 for(
const auto &comp :
to_union_type(dest_type).components())
555 union_exprt union_expr(comp.get_name(), expr, orig_dest_type);
556 if(!src_type.
full_eq(src_type_no_const))
564 if(dest_type.
id()==ID_pointer)
569 src_type.
id()==ID_unsignedbv ||
570 src_type.
id()==ID_signedbv ||
571 src_type.
id()==ID_natural ||
572 src_type.
id()==ID_integer))
578 if(src_type.
id()==ID_pointer ||
579 src_type.
id()==ID_array)
590 else if(src_sub.
id()==ID_code &&
591 dest_sub.
id()==ID_code)
596 else if(src_sub == dest_sub)
601 src_sub.
id()==ID_c_enum ||
602 src_sub.
id()==ID_c_enum_tag) &&
604 dest_sub.
id()==ID_c_enum ||
605 src_sub.
id()==ID_c_enum_tag))
611 src_sub.
id() == ID_array && dest_sub.
id() == ID_array &&
619 warnings.push_back(
"incompatible pointer types");
627 warnings.push_back(
"disregarding volatile");
630 if(src_type==dest_type)
632 expr.
type()=src_type;
642 errors.push_back(
"implicit conversion not permitted");
643 else if(src_type!=dest_type)
657 c_typet max_type=std::max(c_type1, c_type2);
662 typet result_type = (max_type == c_type1) ? type1 : type2;
731 else if(max_type ==
OTHER)
733 errors.push_back(
"implicit arithmetic conversion not permitted");
748 if(src_type.
id()==ID_array)
753 if(error_opt.has_value())
755 errors.push_back(error_opt.value());
764 if(src_type!=dest_type)
771 if(dest_type.
get(ID_C_c_type)==ID_bool)
775 else if(dest_type.
id()==ID_bool)
786 std::optional<std::string>
789 if(type.
id() == ID_c_bit_field)
790 return std::string(
"cannot take address of a bit field");
792 if(type.
id() == ID_bool)
793 return std::string(
"cannot take address of a proper Boolean");
802 "bitvector must have width that is a multiple of CHAR_BIT");
808 if(type.
id() == ID_array)
const bitvector_typet & to_bitvector_type(const typet &type)
Cast a typet to a bitvector_typet.
const fixedbv_typet & to_fixedbv_type(const typet &type)
Cast a typet to a fixedbv_typet.
bool c_implicit_typecast(exprt &expr, const typet &dest_type, const namespacet &ns)
bool c_implicit_typecast_arithmetic(exprt &expr1, exprt &expr2, const namespacet &ns)
perform arithmetic prompotions and conversions
bool has_a_void_pointer(const typet &type)
bool check_c_implicit_typecast(const typet &src_type, const typet &dest_type, const namespacet &ns)
floatbv_typet float_type()
signedbv_typet signed_long_int_type()
unsignedbv_typet unsigned_int_type()
unsignedbv_typet unsigned_long_long_int_type()
unsignedbv_typet unsigned_long_int_type()
signedbv_typet signed_int_type()
pointer_typet pointer_type(const typet &subtype)
signedbv_typet signed_long_long_int_type()
floatbv_typet long_double_type()
bitvector_typet c_index_type()
floatbv_typet double_type()
const c_bit_field_typet & to_c_bit_field_type(const typet &type)
Cast a typet to a c_bit_field_typet.
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
const c_enum_tag_typet & to_c_enum_tag_type(const typet &type)
Cast a typet to a c_enum_tag_typet.
Operator to return the address of an object.
const typet & element_type() const
The type of the elements of the array.
Base class of fixed-width bit-vector types.
std::size_t get_width() const
virtual void write(typet &src) const
virtual void implicit_typecast_followed(exprt &expr, const typet &src_type, const typet &orig_dest_type, const typet &dest_type)
typet follow_with_qualifiers(const typet &src)
void do_typecast(exprt &dest, const typet &type)
virtual void implicit_typecast(exprt &expr, const typet &type)
c_typet get_c_type(const typet &type) const
virtual void implicit_typecast_arithmetic(exprt &expr)
std::list< std::string > warnings
static std::optional< std::string > check_address_can_be_taken(const typet &)
c_typet minimum_promotion(const typet &type) const
std::list< std::string > errors
struct configt::ansi_ct ansi_c
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
typet & type()
Return the type of the expression.
static ieee_float_spect quadruple_precision()
class floatbv_typet to_type() const
Unbounded, signed integers (mathematical integers, not bitvectors)
There are a large number of kinds of tree structured or tree-like data in CPROVER.
bool get_bool(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void remove(const irep_idt &name)
const irep_idt & id() const
bool full_eq(const irept &other) const
const union_typet & follow_tag(const union_tag_typet &) const
Follow type tag of union type.
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
The null pointer constant.
const typet & base_type() const
The type of the data what we point to.
Unbounded, signed rational numbers.
Unbounded, signed real numbers.
const typet & subtype() const
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
Union constructor from single element.
exprt is_not_zero(const exprt &src, const namespacet &ns)
converts a scalar/float expression to C/C++ Booleans
Deprecated expression utility functions.
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
API to expression classes for Pointers.
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
exprt simplify_expr(exprt src, const namespacet &ns)
#define UNREACHABLE
This should be used to mark dead code.
API to expression classes.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
bool can_cast_type< bitvector_typet >(const typet &type)
Check whether a reference to a typet is a bitvector_typet.
std::size_t long_double_width
std::size_t long_long_int_width
std::size_t long_int_width
std::size_t short_int_width
const type_with_subtypet & to_type_with_subtype(const typet &type)