22 bool no_change =
true;
28 auto &index = new_expr.
index();
29 auto &array = new_expr.array();
33 if(index.id() == ID_div)
38 index_div_expr.dividend().id() == ID_mult &&
39 index_div_expr.dividend().operands().size() == 2 &&
40 to_mult_expr(index_div_expr.dividend()).
op1() == index_div_expr.divisor())
47 index_div_expr.dividend().id() == ID_mult &&
48 index_div_expr.dividend().operands().size() == 2 &&
49 to_mult_expr(index_div_expr.dividend()).
op0() == index_div_expr.divisor())
57 if(array.id() == ID_array_comprehension)
63 if(index.type() == comprehension.arg().type())
65 exprt tmp = comprehension.body();
70 else if(array.id()==ID_with)
74 if(array.operands().size() != 3)
79 if(with_expr.where() == index)
82 return with_expr.new_value();
88 const exprt rhs_casted =
94 index_exprt(with_expr.old(), index, new_expr.type()));
98 return with_expr.new_value();
102 return new_index_expr;
105 if_exprt if_expr(equality_expr, with_expr.new_value(), new_index_expr);
110 array.is_constant() || array.id() == ID_array || array.id() == ID_vector)
112 const auto i = numeric_cast<mp_integer>(index);
117 else if(*i < 0 || *i >= array.operands().size())
124 return array.operands()[numeric_cast_v<std::size_t>(*i)];
127 else if(array.id()==ID_string_constant)
129 const auto i = numeric_cast<mp_integer>(index);
136 else if(*i < 0 || *i > value.size())
144 (*i == value.size()) ? 0 : value[numeric_cast_v<std::size_t>(*i)];
148 else if(array.id()==ID_array_of)
152 else if(array.id() == ID_array_list)
155 for(
size_t i=0; i<array.operands().size()/2; i++)
161 return array.operands()[i * 2 + 1];
165 else if(array.id()==ID_byte_extract_little_endian ||
166 array.id()==ID_byte_extract_big_endian)
170 if(array.type().id() == ID_array || array.type().id() == ID_vector)
172 std::optional<typet> subtype;
173 if(array.type().id() == ID_array)
182 if(!sub_size.has_value())
187 from_integer(*sub_size, byte_extract_expr.offset().type()),
189 index, byte_extract_expr.offset().type())});
193 auto result_expr = byte_extract_expr;
194 result_expr.type() = expr.
type();
195 result_expr.offset() = final_offset;
204 return std::move(new_expr);
218 std::optional<exprt::operandst> new_operands;
220 for(std::size_t i = 0; i < expr.
operands().size(); ++i)
223 if(r_it.has_changed())
225 if(!new_operands.has_value())
227 (*new_operands)[i] = std::move(r_it.expr);
231 if(new_operands.has_value())
234 std::swap(result.
operands(), *new_operands);
Expression classes for byte-level operators.
const byte_extract_exprt & to_byte_extract_expr(const exprt &expr)
const typet & element_type() const
The type of the elements of the array.
Base class for all expressions.
bool is_true() const
Return whether the expression is a constant representing true.
bool is_false() const
Return whether the expression is a constant representing false.
typet & type()
Return the type of the expression.
The trinary if-then-else operator.
const irep_idt & id() const
Binary multiplication Associativity is not specified.
The plus expression Associativity is not specified.
resultt simplify_byte_extract(const byte_extract_exprt &)
static resultt changed(resultt<> result)
resultt simplify_if(const if_exprt &)
resultt simplify_rec(const exprt &)
resultt simplify_index_preorder(const index_exprt &)
resultt simplify_inequality(const binary_relation_exprt &)
simplifies inequalities !=, <=, <, >=, >, and also ==
resultt simplify_index(const index_exprt &)
static resultt unchanged(exprt expr)
resultt simplify_plus(const plus_exprt &)
virtual bool simplify(exprt &expr)
resultt simplify_if_preorder(const if_exprt &expr)
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
const typet & element_type() const
The type of the elements of the vector.
if_exprt lift_if(const exprt &src, std::size_t operand_number)
lift up an if_exprt one level
Deprecated expression utility functions.
const std::string & id2string(const irep_idt &d)
std::optional< mp_integer > pointer_offset_size(const typet &type, const namespacet &ns)
Compute the size of a type in bytes, rounding up to full bytes.
bool replace_expr(const exprt &what, const exprt &by, exprt &dest)
API to expression classes.
const array_comprehension_exprt & to_array_comprehension_expr(const exprt &expr)
Cast an exprt to a array_comprehension_exprt.
const div_exprt & to_div_expr(const exprt &expr)
Cast an exprt to a div_exprt.
const with_exprt & to_with_expr(const exprt &expr)
Cast an exprt to a with_exprt.
const array_of_exprt & to_array_of_expr(const exprt &expr)
Cast an exprt to an array_of_exprt.
const mult_exprt & to_mult_expr(const exprt &expr)
Cast an exprt to a mult_exprt.
const vector_typet & to_vector_type(const typet &type)
Cast a typet to a vector_typet.
const array_typet & to_array_type(const typet &type)
Cast a typet to an array_typet.
const string_constantt & to_string_constant(const exprt &expr)