27 for(
const auto &op : expr.
operands())
33 if(expr.
id()==ID_side_effect &&
34 expr.
get(ID_statement)==ID_function_call)
51 if(statement==ID_assign)
60 if(!old_assignment.rhs().is_constant())
63 replacement_expr_opt =
69 code_assignt new_assignment(std::move(new_lhs), std::move(new_rhs));
74 else if(statement==ID_assign_plus ||
75 statement==ID_assign_minus ||
76 statement==ID_assign_mult ||
77 statement==ID_assign_div ||
78 statement==ID_assign_mod ||
79 statement==ID_assign_shl ||
80 statement==ID_assign_ashr ||
81 statement==ID_assign_lshr ||
82 statement==ID_assign_bitand ||
83 statement==ID_assign_bitxor ||
84 statement==ID_assign_bitor)
88 id2string(statement) +
" expects two arguments",
93 if(statement==ID_assign_plus)
95 else if(statement==ID_assign_minus)
97 else if(statement==ID_assign_mult)
99 else if(statement==ID_assign_div)
101 else if(statement==ID_assign_mod)
103 else if(statement==ID_assign_shl)
105 else if(statement==ID_assign_ashr)
107 else if(statement==ID_assign_lshr)
109 else if(statement==ID_assign_bitand)
111 else if(statement==ID_assign_bitxor)
113 else if(statement==ID_assign_bitor)
125 op0_type.
id() != ID_c_enum_tag && op0_type.
id() != ID_c_enum &&
126 op0_type.
id() != ID_c_bool && op0_type.
id() != ID_bool);
136 replacement_expr_opt =
145 convert(assignment, dest, mode);
151 if(replacement_expr_opt.has_value())
157 else if(result_is_used)
168 lhs.
id() == ID_typecast,
170 " expression with different operand type expected to have a "
174 id2string(expr.
id()) +
" type mismatch in lhs operand");
192 "preincrement/predecrement must have one operand",
198 statement == ID_preincrement || statement == ID_predecrement,
199 "expects preincrement or predecrement");
202 const typet &op_type = op.type();
205 op_type.
id() != ID_c_enum_tag && op_type.
id() != ID_c_enum &&
206 op_type.
id() != ID_c_bool && op_type.
id() != ID_bool);
210 if(op_type.
id() == ID_pointer)
213 constant_type = op_type;
221 if(constant_type.
id() == ID_complex)
231 op, statement == ID_preincrement ? ID_plus : ID_minus, std::move(constant)};
237 if(op.id() == ID_typecast)
247 const bool cannot_use_lhs =
255 convert(assignment, dest, mode);
287 "postincrement/postdecrement must have one operand",
293 statement == ID_postincrement || statement == ID_postdecrement,
294 "expects postincrement or postdecrement");
297 const typet &op_type = op.type();
300 op_type.
id() != ID_c_enum_tag && op_type.
id() != ID_c_enum &&
301 op_type.
id() != ID_c_bool && op_type.
id() != ID_bool);
305 if(op_type.
id() == ID_pointer)
308 constant_type = op_type;
316 if(constant_type.
id() == ID_complex)
327 statement == ID_postincrement ? ID_plus : ID_minus,
328 std::move(constant)};
334 convert(assignment, tmp2, mode);
341 std::string suffix =
"post";
374 std::string new_base_name =
"return_value";
385 new_symbol_mode = symbol.
mode;
417 if(dest.
id()==
"new_object")
460 tmp.
set(ID_destructor, expr.
find(ID_destructor));
507 "temporary_object takes zero or one operands",
518 convert(assignment, dest, mode);
525 "temporary_object takes zero operands",
527 exprt initializer=
static_cast<const exprt &
>(expr.
find(ID_initializer));
558 "statement_expression takes block as operand",
563 "statement_expression takes non-empty block as operand",
572 expr.
type(),
"statement_expression", dest, source_location, mode);
577 if(last.
get(ID_statement)==ID_expression)
584 else if(last.
get(ID_statement)==ID_assign)
589 code.
operands().push_back(assignment);
602 static_cast<exprt &
>(expr)=tmp_symbol_expr;
616 if(
result.type().id() != ID_pointer)
631 expr.
swap(overflow_check);
640 statement == ID_overflow_plus
642 : statement == ID_overflow_minus
644 : statement == ID_overflow_mult ? ID_mult : ID_nil;
648 arithmetic_operation,
661 member_exprt{overflow_with_result, result_comps[0]}, arith_type),
667 member_exprt overflow_check{overflow_with_result, result_comps[1]};
670 expr.
swap(overflow_check);
686 if(statement==ID_function_call)
689 else if(statement==ID_assign ||
690 statement==ID_assign_plus ||
691 statement==ID_assign_minus ||
692 statement==ID_assign_mult ||
693 statement==ID_assign_div ||
694 statement==ID_assign_bitor ||
695 statement==ID_assign_bitxor ||
696 statement==ID_assign_bitand ||
697 statement==ID_assign_lshr ||
698 statement==ID_assign_ashr ||
699 statement==ID_assign_shl ||
700 statement==ID_assign_mod)
702 else if(statement==ID_postincrement ||
703 statement==ID_postdecrement)
705 else if(statement==ID_preincrement ||
706 statement==ID_predecrement)
708 else if(statement==ID_cpp_new ||
709 statement==ID_cpp_new_array)
711 else if(statement==ID_cpp_delete ||
712 statement==ID_cpp_delete_array)
714 else if(statement==ID_allocate)
716 else if(statement==ID_temporary_object)
718 else if(statement==ID_statement_expression)
720 else if(statement==ID_nondet)
724 else if(statement==ID_skip)
728 else if(statement==ID_throw)
741 statement == ID_overflow_plus || statement == ID_overflow_minus ||
742 statement == ID_overflow_mult)
std::unordered_set< symbol_exprt, irep_hash > address_taken(const std::vector< exprt > &src)
API to expression classes for bitvectors.
API to expression classes that are internal to the C frontend.
const side_effect_expr_overflowt & to_side_effect_expr_overflow(const exprt &expr)
Cast an exprt to a side_effect_expr_overflowt.
bitvector_typet c_index_type()
A base class for binary expressions.
A Boolean expression returning true, iff operation kind would result in an overflow when applied to o...
A goto_instruction_codet representing an assignment in the program.
codet & find_last_statement()
codet representation of an expression statement.
const exprt & expression() const
A codet representing the declaration of a local variable.
goto_instruction_codet representation of a function call statement.
Data structure for representing an arbitrary statement in a program.
const irep_idt & get_statement() const
Complex constructor from a pair of numbers.
Operator to dereference a pointer.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
void copy_to_operands(const exprt &expr)
Copy the given argument to the end of exprt's operands.
typet & type()
Return the type of the expression.
const source_locationt & source_location() const
source_locationt & add_source_location()
void remove_temporary_object(side_effect_exprt &expr, goto_programt &dest)
void remove_function_call(side_effect_expr_function_callt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
symbol_table_baset & symbol_table
void remove_pre(side_effect_exprt &expr, goto_programt &dest, bool result_is_used, bool address_taken, const irep_idt &mode)
void convert_assign(const code_assignt &code, goto_programt &dest, const irep_idt &mode)
void remove_overflow(side_effect_expr_overflowt &expr, goto_programt &dest, bool result_is_used, const irep_idt &mode)
void remove_post(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
void remove_malloc(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
void remove_cpp_delete(side_effect_exprt &expr, goto_programt &dest)
std::string tmp_symbol_prefix
void convert_frontend_decl(const code_frontend_declt &, goto_programt &, const irep_idt &mode)
void remove_side_effect(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used, bool address_taken)
void convert_function_call(const code_function_callt &code, goto_programt &dest, const irep_idt &mode)
symbolt & new_tmp_symbol(const typet &type, const std::string &suffix, goto_programt &dest, const source_locationt &, const irep_idt &mode)
void remove_statement_expression(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
void convert_cpp_delete(const codet &code, goto_programt &dest)
void clean_expr(exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used=true)
static bool has_function_call(const exprt &expr)
void remove_assignment(side_effect_exprt &expr, goto_programt &dest, bool result_is_used, bool address_taken, const irep_idt &mode)
void convert(const codet &code, goto_programt &dest, const irep_idt &mode)
converts 'code' and appends the result to 'dest'
void remove_cpp_new(side_effect_exprt &expr, goto_programt &dest, bool result_is_used)
static void replace_new_object(const exprt &object, exprt &dest)
void make_temp_symbol(exprt &expr, const std::string &suffix, goto_programt &, const irep_idt &mode)
static bool assignment_lhs_needs_temporary(const exprt &lhs)
This class represents an instruction in the GOTO intermediate representation.
A generic container class for the GOTO intermediate representation of one function.
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
const irept & find(const irep_idt &name) const
const irep_idt & get(const irep_idt &name) const
void set(const irep_idt &name, const irep_idt &value)
const irep_idt & id() const
Extract member of struct or union.
mstreamt & result() const
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
An expression returning both the result of the arithmetic operation under wrap-around semantics as we...
const typet & base_type() const
The type of the data what we point to.
A side_effect_exprt representation of a function call side effect.
exprt::operandst & arguments()
A Boolean expression returning true, iff the result of performing operation kind on operands a and b ...
A side_effect_exprt representation of a side effect that throws an exception.
An expression containing a side effect.
const irep_idt & get_statement() const
const componentst & components() const
std::vector< componentt > componentst
Expression to hold a symbol (variable)
const irep_idt & get_identifier() const
irep_idt base_name
Base (non-scoped) name.
source_locationt location
Source code location of definition of symbol.
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
typet type
Type of symbol.
irep_idt name
The unique identifier.
irep_idt mode
Language mode.
Semantic type conversion.
static exprt conditional_cast(const exprt &expr, const typet &type)
The type of an expression, extends irept.
#define Forall_operands(it, expr)
auto expr_try_dynamic_cast(TExpr &base) -> typename detail::expr_try_dynamic_cast_return_typet< T, TExpr >::type
Try to cast a reference to a generic exprt to a specific derived class.
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
Deprecated expression utility functions.
symbolt & get_fresh_aux_symbol(const typet &type, const std::string &name_prefix, const std::string &basename_prefix, const source_locationt &source_location, const irep_idt &symbol_mode, const namespacet &ns, symbol_table_baset &symbol_table)
Installs a fresh-named symbol with respect to the given namespace ns with the requested name pattern ...
Fresh auxiliary symbol creation.
const code_assignt & to_code_assign(const goto_instruction_codet &code)
const std::string & id2string(const irep_idt &d)
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
nonstd::optional< T > optionalt
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
#define CHECK_RETURN(CONDITION)
#define UNREACHABLE
This should be used to mark dead code.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define PRECONDITION(CONDITION)
#define INVARIANT_WITH_DIAGNOSTICS(CONDITION, REASON,...)
Same as invariant, with one or more diagnostics attached Diagnostics can be of any type that has a sp...
side_effect_expr_statement_expressiont & to_side_effect_expr_statement_expression(exprt &expr)
side_effect_expr_function_callt & to_side_effect_expr_function_call(exprt &expr)
const code_blockt & to_code_block(const codet &code)
side_effect_expr_assignt & to_side_effect_expr_assign(exprt &expr)
code_expressiont & to_code_expression(codet &code)
const codet & to_code(const exprt &expr)
API to expression classes.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.