Go to the documentation of this file.
48 exprt &new_expr)
const
52 if(expr.
type().
id() == ID_code)
56 expr.
type().
id() == ID_struct &&
64 new_expr.
remove(ID_C_lvalue);
79 exprt &new_expr)
const
81 assert(expr.
type().
id()==ID_array);
87 index.
set(ID_C_lvalue,
true);
120 exprt &new_expr)
const
122 if(expr.
type().
id()!=ID_pointer ||
129 if(expr.
type()!=type)
136 while(sub_from.
id()==ID_pointer)
147 if(qual_from!=qual_to && !const_to)
163 new_expr.
type()=type;
197 exprt &new_expr)
const
206 qual_from.
write(int_type);
208 if(expr.
type().
id()==ID_signedbv)
217 if(expr.
type().
id()==ID_unsignedbv)
226 if(expr.
type().
id() == ID_bool || expr.
type().
id() == ID_c_bool)
232 if(expr.
type().
id()==ID_c_enum_tag)
250 exprt &new_expr)
const
305 exprt &new_expr)
const
307 if(type.
id()!=ID_signedbv &&
308 type.
id()!=ID_unsignedbv)
312 expr.
type().
id() != ID_signedbv && expr.
type().
id() != ID_unsignedbv &&
313 expr.
type().
id() != ID_c_bool && expr.
type().
id() != ID_bool &&
314 expr.
type().
id() != ID_c_enum_tag)
352 exprt &new_expr)
const
357 if(expr.
type().
id()==ID_floatbv ||
358 expr.
type().
id()==ID_fixedbv)
360 if(type.
id()!=ID_signedbv &&
361 type.
id()!=ID_unsignedbv)
364 else if(expr.
type().
id()==ID_signedbv ||
365 expr.
type().
id()==ID_unsignedbv ||
366 expr.
type().
id()==ID_c_enum_tag)
368 if(type.
id()!=ID_fixedbv &&
369 type.
id()!=ID_floatbv)
403 exprt &new_expr)
const
405 if(expr.
type().
id()!=ID_floatbv &&
406 expr.
type().
id()!=ID_fixedbv)
409 if(type.
id()!=ID_floatbv &&
410 type.
id()!=ID_fixedbv)
462 if(type.
id()!=ID_pointer ||
471 expr.
type().
id()!=ID_pointer)
474 new_expr.
set(ID_value, ID_NULL);
475 new_expr.
type()=type;
483 expr.
type().
id() != ID_pointer ||
493 if(sub_from.
id()==ID_nullptr)
497 if(sub_from.
id()!=ID_code && sub_to.
id()==ID_empty)
507 if(sub_from.
id()==ID_struct && sub_to.
id()==ID_struct)
603 if(expr.
id()==ID_constant &&
604 expr.
get(ID_value)==ID_NULL)
641 expr.
type().
id() != ID_signedbv && expr.
type().
id() != ID_unsignedbv &&
642 expr.
type().
id() != ID_pointer && expr.
type().
id() != ID_bool &&
643 expr.
type().
id() != ID_c_enum_tag)
652 qual_from.
write(Bool);
686 exprt curr_expr=expr;
689 if(type.
id()==ID_c_bit_field)
693 if(curr_expr.
type().
id()==ID_c_bit_field)
696 if(curr_expr.
type().
id()==ID_array)
698 if(type.
id()==ID_pointer)
704 else if(curr_expr.
type().
id()==ID_code &&
705 type.
id()==ID_pointer)
710 else if(curr_expr.
get_bool(ID_C_lvalue))
718 curr_expr.
swap(new_expr);
722 if(
follow(type).
id()==ID_c_enum &&
725 if(
follow(type).find(ID_tag)==
738 curr_expr.
type().
get(ID_C_c_type)!=type.
get(ID_C_c_type))
740 if(type.
id()==ID_signedbv ||
741 type.
id()==ID_unsignedbv ||
742 follow(type).
id()==ID_c_enum)
745 new_expr.
type() != type)
750 curr_expr, type, new_expr))
759 else if(type.
id()==ID_floatbv || type.
id()==ID_fixedbv)
762 new_expr.
type() != type)
765 curr_expr, type, new_expr) &&
767 curr_expr, type, new_expr))
775 else if(type.
id()==ID_pointer)
790 else if(type.
id() == ID_c_bool)
797 else if(type.
id() == ID_bool)
809 curr_expr.
swap(new_expr);
811 if(curr_expr.
type().
id()==ID_pointer)
819 sub_from.
swap(tmp_from);
824 qual_from.
read(sub_from);
827 qual_to.
read(sub_to);
829 if(qual_from!=qual_to)
835 while(sub_from.
id()==ID_pointer);
843 new_expr.
type()=type;
877 if(to.
id()==ID_struct)
883 if(from.
id()==ID_struct)
896 if(expr.
id()==ID_dereference)
911 tmp_object_expr.
set(ID_C_lvalue,
true);
912 tmp_object_expr.
set(ID_mode, ID_cpp);
914 new_expr.
swap(tmp_object_expr);
933 if(comp_type.
id() !=ID_code)
943 if(parameters.size() != 2)
946 exprt curr_arg1 = parameters[1];
956 if(arg1_type.
id() != ID_struct_tag)
960 expr, arg1_type, tmp_expr, tmp_rank))
968 tmp_expr.
set(ID_C_lvalue,
true);
973 func_symb.
type()=comp_type;
978 std::move(func_symb),
984 new_expr.
swap(ctor_expr);
985 assert(new_expr.
get(ID_statement)==ID_temporary_object);
988 new_expr.
type().
set(ID_C_constant,
true);
993 else if(from.
id() == ID_struct && arg1_type.
id() == ID_struct_tag)
1002 expr_pfrom, pto, expr_ptmp, tmp_rank))
1013 expr_deref.
set(ID_C_lvalue,
true);
1016 exprt new_object(ID_new_object, type);
1017 new_object.
set(ID_C_lvalue,
true);
1018 new_object.
type().
set(ID_C_constant,
false);
1021 func_symb.
type()=comp_type;
1025 std::move(func_symb),
1031 new_expr.
swap(ctor_expr);
1034 new_expr.
get(ID_statement)==ID_temporary_object,
1038 new_expr.
type().
set(ID_C_constant,
true);
1048 if(from.
id()==ID_struct)
1056 if(!
component.get_bool(ID_is_cast_operator))
1061 comp_type.
parameters().size() == 1,
"expected exactly one parameter");
1064 this_type.
set(ID_C_reference,
true);
1066 exprt this_expr(expr);
1067 this_type.
set(ID_C_this,
true);
1069 unsigned tmp_rank=0;
1073 this_expr, this_type, tmp_expr, tmp_rank))
1079 exprt member_func(ID_member);
1080 member_func.
add(ID_component_cpp_name)=cpp_func_name;
1084 std::move(member_func),
1098 new_expr.
swap(tmp_expr);
1115 const typet &type)
const
1124 if(from.
get(ID_C_c_type)!=to.
get(ID_C_c_type))
1130 if(from.
id()==ID_struct &&
1135 if(from.
id()==ID_struct &&
1153 unsigned &rank)
const
1170 if(qual_from!=qual_to)
1222 unsigned backup_rank=rank;
1228 if(expr.
get(ID_statement)==ID_temporary_object)
1229 expr.
set(ID_C_lvalue,
true);
1230 else if(expr.
get(ID_statement)==ID_function_call)
1231 expr.
set(ID_C_lvalue,
true);
1232 else if(expr.
get_bool(ID_C_temporary_avoided))
1234 expr.
remove(ID_C_temporary_avoided);
1237 expr.
swap(temporary);
1238 expr.
set(ID_C_lvalue,
true);
1255 tmp.
set(ID_mode, ID_cpp);
1288 if(!
component.get_bool(ID_is_cast_operator))
1297 assert(component_type.
parameters().size()==1);
1301 this_type.
set(ID_C_reference,
true);
1303 exprt this_expr(expr);
1305 this_type.
set(ID_C_this,
true);
1307 unsigned tmp_rank=0;
1311 this_expr, this_type, tmp_expr, tmp_rank))
1317 exprt member_func(ID_member);
1318 member_func.
add(ID_component_cpp_name)=cpp_func_name;
1322 std::move(member_func),
1329 exprt returned_value=func_expr;
1332 if(returned_value.
get_bool(ID_C_lvalue) &&
1338 "the returned value must be pointer to reference");
1345 qual_from.
read(returned_value.
type());
1369 exprt arg_expr=expr;
1371 if(arg_expr.
type().
id() == ID_struct_tag)
1374 arg_expr.
set(ID_C_lvalue,
true);
1392 tmp.
set(ID_mode, ID_cpp);
1399 tmp.
type().
set(ID_C_reference,
true);
1421 unsigned backup_rank=rank;
1434 new_expr.
type().
set(ID_C_reference,
true);
1499 str <<
"\n " << type.
pretty() <<
'\n';
1558 expr.
swap(new_expr);
1563 error() <<
"bad reference initializer" <<
eom;
1569 const typet &t2)
const
1571 assert(t1.
id()==ID_pointer && t2.
id()==ID_pointer);
1576 nt1.
remove(ID_C_reference);
1577 nt1.
remove(ID_to_member);
1580 nt2.
remove(ID_C_reference);
1581 nt2.
remove(ID_to_member);
1584 std::vector<typet> snt1;
1585 snt1.push_back(nt1);
1587 while(snt1.back().has_subtype())
1589 snt1.reserve(snt1.size()+1);
1590 snt1.push_back(snt1.back().subtype());
1594 q1.
read(snt1.back());
1600 std::vector<typet> snt2;
1601 snt2.push_back(nt2);
1602 while(snt2.back().has_subtype())
1604 snt2.reserve(snt2.size()+1);
1605 snt2.push_back(snt2.back().subtype());
1609 q2.
read(snt2.back());
1615 const std::size_t k=snt1.size() < snt2.size() ? snt1.size() : snt2.size();
1617 for(std::size_t i=k; i > 1; i--)
1619 snt1[snt1.size()-2].subtype()=snt1[snt1.size()-1];
1622 snt2[snt2.size()-2].subtype()=snt2[snt2.size()-1];
1626 exprt e1(
"Dummy", snt1.back());
1639 exprt curr_expr=expr;
1641 if(curr_expr.
type().
id()==ID_array)
1643 if(type.
id()==ID_pointer)
1649 else if(curr_expr.
type().
id()==ID_code &&
1650 type.
id()==ID_pointer)
1655 else if(curr_expr.
get_bool(ID_C_lvalue))
1673 new_expr=address_of;
1676 else if(type.
id()==ID_pointer)
1678 if(type!=new_expr.
type())
1683 new_expr.
swap(typecast_expr);
1697 if(type.
id()==ID_pointer)
1699 if(e.
id()==ID_dereference && e.
get_bool(ID_C_implicit))
1702 if(e.
type().
id()==ID_pointer &&
1711 if(type.
subtype().
id() != ID_struct_tag)
1714 else if(type.
id()==ID_pointer)
1725 else if(type.
subtype().
id() == ID_struct_tag)
1746 bool check_constantness)
1750 if(check_constantness && type.
id()==ID_pointer)
1752 if(e.
id()==ID_dereference && e.
get_bool(ID_C_implicit))
1755 if(e.
type().
id()==ID_pointer &&
1774 if(e.
type().
id()==ID_array)
1791 if(e.
type().
id()==ID_pointer &&
1792 (type.
id()==ID_unsignedbv || type.
id()==ID_signedbv))
1800 (e.
type().
id() == ID_unsignedbv || e.
type().
id() == ID_signedbv ||
1801 e.
type().
id() == ID_c_bool || e.
type().
id() == ID_bool) &&
1809 new_expr.
set(ID_value, ID_NULL);
1810 new_expr.
type()=type;
1819 if(e.
type().
id()==ID_pointer &&
1820 type.
id()==ID_pointer &&
1842 bool check_constantness)
1846 if(check_constantness && type.
id()==ID_pointer)
1848 if(e.
id()==ID_dereference && e.
get_bool(ID_C_implicit))
1851 if(e.
type().
id()==ID_pointer &&
1867 if(subto.
id()==ID_struct && from.
id()==ID_struct)
1886 if(e.
id()==ID_dereference)
1895 new_expr.
swap(address_of);
1902 if(type.
id()==ID_empty)
1909 if(type.
id()==ID_c_enum_tag &&
1910 (e.
type().
id()==ID_signedbv ||
1911 e.
type().
id()==ID_unsignedbv ||
1912 e.
type().
id()==ID_c_enum_tag))
1915 new_expr.
remove(ID_C_lvalue);
1929 new_expr.
swap(temporary);
1934 new_expr.
set(ID_C_temporary_avoided,
true);
1936 new_expr.
remove(ID_C_lvalue);
1942 if(type.
id()==ID_pointer && e.
type().
id()==ID_pointer)
1949 if(from.
id()==ID_empty)
1955 if(to.
id()==ID_struct && from.
id()==ID_struct)
2006 new_expr.
type().
add(ID_to_member) = from_struct;
virtual void read(const typet &src) override
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
#define UNREACHABLE
This should be used to mark dead code.
static exprt conditional_cast(const exprt &expr, const typet &type)
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const typet & subtype() const
bool standard_conversion_floating_point_promotion(const exprt &expr, exprt &new_expr) const
Floating-point-promotion conversion.
bool standard_conversion_boolean(const exprt &expr, exprt &new_expr) const
Boolean conversion.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
bool reference_binding(exprt expr, const typet &type, exprt &new_expr, unsigned &rank)
Reference binding.
The type of an expression, extends irept.
void show_instantiation_stack(std::ostream &)
std::string pretty(unsigned indent=0, unsigned max_indent=0) const
bool reinterpret_typecast(const exprt &expr, const typet &type, exprt &new_expr, bool check_constantness=true)
Operator to dereference a pointer.
A side_effect_exprt representation of a function call side effect.
bool standard_conversion_integral_promotion(const exprt &expr, exprt &new_expr) const
Integral-promotion conversion.
irept & add(const irep_namet &name)
const irept & find(const irep_namet &name) const
void new_temporary(const source_locationt &source_location, const typet &, const exprt::operandst &ops, exprt &temporary)
bool standard_conversion_lvalue_to_rvalue(const exprt &expr, exprt &new_expr) const
Lvalue-to-rvalue conversion.
const symbolt & lookup(const irep_idt &name) const
Lookup a symbol in the namespace.
bool standard_conversion_sequence(const exprt &expr, const typet &type, exprt &new_expr, unsigned &rank)
Standard Conversion Sequence.
Base class for all expressions.
std::string from_type(const namespacet &ns, const irep_idt &identifier, const typet &type)
auto component(T &struct_expr, const irep_idt &name, const namespacet &ns) -> decltype(struct_expr.op0())
bool reference_compatible(const exprt &expr, const typet &type, unsigned &rank) const
Reference-compatible.
struct configt::ansi_ct ansi_c
virtual bool is_subset_of(const qualifierst &other) const override
bitvector_typet index_type()
bool standard_conversion_array_to_pointer(const exprt &expr, exprt &new_expr) const
Array-to-pointer conversion.
bool cpp_is_pod(const typet &type) const
typet & type()
Return the type of the expression.
bool get_bool(const irep_namet &name) const
bool standard_conversion_floating_point_conversion(const exprt &expr, const typet &type, exprt &new_expr) const
Floating-point conversion.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.
void typecheck_side_effect_function_call(side_effect_expr_function_callt &) override
signedbv_typet signed_int_type()
static void make_already_typechecked(exprt &expr)
const unsignedbv_typet & to_unsignedbv_type(const typet &type)
Cast a typet to an unsignedbv_typet.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
void add_implicit_dereference(exprt &)
source_locationt source_location
void reference_initializer(exprt &expr, const typet &type)
A reference to type "cv1 T1" is initialized by an expression of type "cv2 T2" as follows:
#define PRECONDITION(CONDITION)
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
symbol_exprt cpp_symbol_expr(const symbolt &symbol)
virtual void write(typet &src) const override
floatbv_typet float_type()
bool simplify(exprt &expr, const namespacet &ns)
void make_ptr_typecast(exprt &expr, const typet &dest_type)
exprt simplify_expr(exprt src, const namespacet &ns)
pointer_typet pointer_type(const typet &subtype)
bool subtype_typecast(const struct_typet &from, const struct_typet &to) const
const irep_idt & id() const
bool standard_conversion_function_to_pointer(const exprt &expr, exprt &new_expr) const
Function-to-pointer conversion.
void remove(const irep_namet &name)
const parameterst & parameters() const
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
bool standard_conversion_pointer_to_member(const exprt &expr, const typet &type, exprt &new_expr)
Pointer-to-member conversion.
bool static_typecast(const exprt &expr, const typet &type, exprt &new_expr, bool check_constantness=true)
C++ Language Type Checking.
bool standard_conversion_integral_conversion(const exprt &expr, const typet &type, exprt &new_expr) const
Integral conversion.
floatbv_typet double_type()
std::size_t get_width() const
bool user_defined_conversion_sequence(const exprt &expr, const typet &type, exprt &new_expr, unsigned &rank)
User-defined conversion sequence.
bool reference_related(const exprt &expr, const typet &type) const
Reference-related.
reference_typet reference_type(const typet &subtype)
Deprecated expression utility functions.
bool standard_conversion_qualification(const exprt &expr, const typet &, exprt &new_expr) const
Qualification conversion.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
Structure type, corresponds to C style structs.
bool const_typecast(const exprt &expr, const typet &type, exprt &new_expr)
const typet & follow(const typet &) const
Resolve type symbol to the type it points to.
bool is_reference(const typet &type)
Returns true if the type is a reference.
const irep_idt & get(const irep_namet &name) const
exprt is_not_zero(const exprt &src, const namespacet &ns)
converts a scalar/float expression to C/C++ Booleans
void set(const irep_namet &name, const irep_idt &value)
bool cast_away_constness(const typet &t1, const typet &t2) const
const signedbv_typet & to_signedbv_type(const typet &type)
Cast a typet to a signedbv_typet.
void implicit_typecast(exprt &expr, const typet &type) override
bool standard_conversion_pointer(const exprt &expr, const typet &type, exprt &new_expr)
Pointer conversion.
void add_to_operands(const exprt &expr)
Add the given argument to the end of exprt's operands.
const floatbv_typet & to_floatbv_type(const typet &type)
Cast a typet to a floatbv_typet.
const typet & return_type() const
bool standard_conversion_floating_integral_conversion(const exprt &expr, const typet &type, exprt &new_expr) const
Floating-integral conversion.
bool implicit_conversion_sequence(const exprt &expr, const typet &type, exprt &new_expr, unsigned &rank)
implicit conversion sequence
bool dynamic_typecast(const exprt &expr, const typet &type, exprt &new_expr)
std::string to_string(const typet &) override
const union_typet & to_union_type(const typet &type)
Cast a typet to a union_typet.
Operator to return the address of an object.
source_locationt & add_source_location()
Semantic type conversion.
The pointer type These are both 'bitvector_typet' (they have a width) and 'type_with_subtypet' (they ...
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
API to expression classes.
const source_locationt & source_location() const
bool is_incomplete() const
A struct/union may be incomplete.
An expression containing a side effect.