Go to the documentation of this file.
31 if(expr.
id()==ID_side_effect &&
32 expr.
get(ID_statement)==ID_function_call)
49 if(statement==ID_assign)
54 result_is_used && !address_taken &&
57 if(!old_assignment.rhs().is_constant())
60 replacement_expr_opt = old_assignment.rhs();
66 code_assignt new_assignment(std::move(new_lhs), std::move(new_rhs));
71 else if(statement==ID_assign_plus ||
72 statement==ID_assign_minus ||
73 statement==ID_assign_mult ||
74 statement==ID_assign_div ||
75 statement==ID_assign_mod ||
76 statement==ID_assign_shl ||
77 statement==ID_assign_ashr ||
78 statement==ID_assign_lshr ||
79 statement==ID_assign_bitand ||
80 statement==ID_assign_bitxor ||
81 statement==ID_assign_bitor)
85 id2string(statement) +
" expects two arguments",
90 if(statement==ID_assign_plus)
92 else if(statement==ID_assign_minus)
94 else if(statement==ID_assign_mult)
96 else if(statement==ID_assign_div)
98 else if(statement==ID_assign_mod)
100 else if(statement==ID_assign_shl)
102 else if(statement==ID_assign_ashr)
104 else if(statement==ID_assign_lshr)
106 else if(statement==ID_assign_bitand)
108 else if(statement==ID_assign_bitxor)
110 else if(statement==ID_assign_bitor)
121 op0_type.
id() != ID_c_enum_tag && op0_type.
id() != ID_c_enum &&
122 op0_type.
id() != ID_c_bool && op0_type.
id() != ID_bool);
128 result_is_used && !address_taken &&
132 replacement_expr_opt = rhs;
141 convert(assignment, dest, mode);
147 if(replacement_expr_opt.has_value())
153 else if(result_is_used)
164 lhs.
id() == ID_typecast,
166 " expression with different operand type expected to have a "
170 id2string(expr.
id()) +
" type mismatch in lhs operand");
188 "preincrement/predecrement must have one operand",
194 statement == ID_preincrement || statement == ID_predecrement,
195 "expects preincrement or predecrement");
198 const typet &op_type = op.type();
201 op_type.
id() != ID_c_enum_tag && op_type.
id() != ID_c_enum &&
202 op_type.
id() != ID_c_bool && op_type.
id() != ID_bool);
206 if(op_type.
id() == ID_pointer)
209 constant_type = op_type;
217 if(constant_type.
id() == ID_complex)
227 op, statement == ID_preincrement ? ID_plus : ID_minus, std::move(constant)};
233 if(op.id() == ID_typecast)
243 const bool cannot_use_lhs =
251 convert(assignment, dest, mode);
283 "postincrement/postdecrement must have one operand",
289 statement == ID_postincrement || statement == ID_postdecrement,
290 "expects postincrement or postdecrement");
293 const typet &op_type = op.type();
296 op_type.
id() != ID_c_enum_tag && op_type.
id() != ID_c_enum &&
297 op_type.
id() != ID_c_bool && op_type.
id() != ID_bool);
301 if(op_type.
id() == ID_pointer)
304 constant_type = op_type;
312 if(constant_type.
id() == ID_complex)
323 statement == ID_postincrement ? ID_plus : ID_minus,
324 std::move(constant)};
330 convert(assignment, tmp2, mode);
337 std::string suffix =
"post";
338 if(
auto sym_expr = expr_try_dynamic_cast<symbol_exprt>(tmp))
370 std::string new_base_name =
"return_value";
381 new_symbol_mode = symbol.
mode;
413 if(dest.
id()==
"new_object")
456 tmp.
set(ID_destructor, expr.
find(ID_destructor));
503 "temporary_object takes zero or one operands",
514 convert(assignment, dest, mode);
521 "temporary_object takes zero operands",
523 exprt initializer=
static_cast<const exprt &
>(expr.
find(ID_initializer));
554 "statement_expression takes block as operand",
559 "statement_expression takes non-empty block as operand",
568 expr.
type(),
"statement_expression", dest, source_location, mode);
573 if(last.
get(ID_statement)==ID_expression)
580 else if(last.
get(ID_statement)==ID_assign)
585 code.
operands().push_back(assignment);
598 static_cast<exprt &
>(expr)=tmp_symbol_expr;
612 if(
result.type().id() != ID_pointer)
627 expr.
swap(overflow_check);
636 statement == ID_overflow_plus
638 : statement == ID_overflow_minus
640 : statement == ID_overflow_mult ? ID_mult : ID_nil;
644 arithmetic_operation,
657 member_exprt{overflow_with_result, result_comps[0]}, arith_type),
663 member_exprt overflow_check{overflow_with_result, result_comps[1]};
666 expr.
swap(overflow_check);
682 if(statement==ID_function_call)
685 else if(statement==ID_assign ||
686 statement==ID_assign_plus ||
687 statement==ID_assign_minus ||
688 statement==ID_assign_mult ||
689 statement==ID_assign_div ||
690 statement==ID_assign_bitor ||
691 statement==ID_assign_bitxor ||
692 statement==ID_assign_bitand ||
693 statement==ID_assign_lshr ||
694 statement==ID_assign_ashr ||
695 statement==ID_assign_shl ||
696 statement==ID_assign_mod)
698 else if(statement==ID_postincrement ||
699 statement==ID_postdecrement)
701 else if(statement==ID_preincrement ||
702 statement==ID_predecrement)
703 remove_pre(expr, dest, result_is_used, address_taken, mode);
704 else if(statement==ID_cpp_new ||
705 statement==ID_cpp_new_array)
707 else if(statement==ID_cpp_delete ||
708 statement==ID_cpp_delete_array)
710 else if(statement==ID_allocate)
712 else if(statement==ID_temporary_object)
714 else if(statement==ID_statement_expression)
716 else if(statement==ID_nondet)
720 else if(statement==ID_skip)
724 else if(statement==ID_throw)
737 statement == ID_overflow_plus || statement == ID_overflow_minus ||
738 statement == ID_overflow_mult)
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.
const componentst & components() const
void convert_function_call(const code_function_callt &code, goto_programt &dest, const irep_idt &mode)
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
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.
code_expressiont & to_code_expression(codet &code)
const exprt & skip_typecast(const exprt &expr)
find the expression nested inside typecasts, if any
side_effect_expr_function_callt & to_side_effect_expr_function_call(exprt &expr)
#define Forall_operands(it, expr)
const side_effect_expr_overflowt & to_side_effect_expr_overflow(const exprt &expr)
Cast an exprt to a side_effect_expr_overflowt.
bool is_number(const typet &type)
Returns true if the type is a rational, real, integer, natural, complex, unsignedbv,...
const struct_typet & to_struct_type(const typet &type)
Cast a typet to a struct_typet.
static void replace_new_object(const exprt &object, exprt &dest)
void convert(const codet &code, goto_programt &dest, const irep_idt &mode)
converts 'code' and appends the result to 'dest'
#define CHECK_RETURN(CONDITION)
The type of an expression, extends irept.
void convert_frontend_decl(const code_frontend_declt &, goto_programt &, const irep_idt &mode)
void clean_expr(exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used=true)
const irept & find(const irep_idt &name) const
typet type
Type of symbol.
Operator to dereference a pointer.
static bool has_function_call(const exprt &expr)
A side_effect_exprt representation of a function call side effect.
std::string tmp_symbol_prefix
targett add(instructiont &&instruction)
Adds a given instruction at the end.
A codet representing the declaration of a local variable.
void remove_function_call(side_effect_expr_function_callt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
Base class for all expressions.
std::vector< componentt > componentst
A base class for binary expressions.
irep_idt base_name
Base (non-scoped) name.
An expression returning both the result of the arithmetic operation under wrap-around semantics as we...
const complex_typet & to_complex_type(const typet &type)
Cast a typet to a complex_typet.
Expression to hold a symbol (variable)
side_effect_expr_statement_expressiont & to_side_effect_expr_statement_expression(exprt &expr)
symbolt & new_tmp_symbol(const typet &type, const std::string &suffix, goto_programt &dest, const source_locationt &, const irep_idt &mode)
const irep_idt & get(const irep_idt &name) const
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
#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...
void remove_overflow(side_effect_expr_overflowt &expr, goto_programt &dest, bool result_is_used, const irep_idt &mode)
const codet & to_code(const exprt &expr)
typet & type()
Return the type of the expression.
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
goto_instruction_codet representation of a function call statement.
irep_idt mode
Language mode.
mstreamt & result() const
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
const std::string & id2string(const irep_idt &d)
#define forall_operands(it, expr)
void set(const irep_idt &name, const irep_idt &value)
A Boolean expression returning true, iff operation kind would result in an overflow when applied to o...
void remove_assignment(side_effect_exprt &expr, goto_programt &dest, bool result_is_used, bool address_taken, const irep_idt &mode)
#define PRECONDITION(CONDITION)
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
const irep_idt & get_identifier() const
void remove_statement_expression(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
class symbol_exprt symbol_expr() const
Produces a symbol_exprt for a symbol.
void remove_malloc(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
const pointer_typet & to_pointer_type(const typet &type)
Cast a typet to a pointer_typet.
void remove_cpp_new(side_effect_exprt &expr, goto_programt &dest, bool result_is_used)
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const irep_idt & id() const
Complex constructor from a pair of numbers.
void remove_cpp_delete(side_effect_exprt &expr, goto_programt &dest)
void remove_post(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used)
nonstd::optional< T > optionalt
void convert_assign(const code_assignt &code, goto_programt &dest, const irep_idt &mode)
side_effect_expr_assignt & to_side_effect_expr_assign(exprt &expr)
const irep_idt & get_statement() const
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
Extract member of struct or union.
Deprecated expression utility functions.
void remove_temporary_object(side_effect_exprt &expr, goto_programt &dest)
source_locationt location
Source code location of definition of symbol.
exprt::operandst & arguments()
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.
const typet & base_type() const
The type of the data what we point to.
void remove_pre(side_effect_exprt &expr, goto_programt &dest, bool result_is_used, bool address_taken, const irep_idt &mode)
A generic container class for the GOTO intermediate representation of one function.
void remove_side_effect(side_effect_exprt &expr, goto_programt &dest, const irep_idt &mode, bool result_is_used, bool address_taken)
A side_effect_exprt representation of a side effect that throws an exception.
symbol_table_baset & symbol_table
const code_blockt & to_code_block(const codet &code)
void convert_cpp_delete(const codet &code, goto_programt &dest)
static bool assignment_lhs_needs_temporary(const exprt &lhs)
const exprt & expression() const
A Boolean expression returning true, iff the result of performing operation kind on operands a and b ...
codet & find_last_statement()
source_locationt & add_source_location()
Semantic type conversion.
A goto_instruction_codet representing an assignment in the program.
const irep_idt & get_statement() const
bitvector_typet c_index_type()
This class represents an instruction in the GOTO intermediate representation.
const source_locationt & source_location() const
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 ...
irep_idt name
The unique identifier.
An expression containing a side effect.
const code_assignt & to_code_assign(const goto_instruction_codet &code)
codet representation of an expression statement.
Data structure for representing an arbitrary statement in a program.
void make_temp_symbol(exprt &expr, const std::string &suffix, goto_programt &, const irep_idt &mode)