CBMC
Loading...
Searching...
No Matches
goto_convert_function_call.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Program Transformation
4
5Author: Daniel Kroening, kroening@kroening.com
6
7\*******************************************************************/
8
11
12#include "goto_convert_class.h"
13
14#include <util/expr_util.h>
16#include <util/std_expr.h>
17
18#include "destructor.h"
19
21 const code_function_callt &function_call,
22 goto_programt &dest,
23 const irep_idt &mode)
24{
26 function_call.lhs(),
27 function_call.function(),
28 function_call.arguments(),
29 dest,
30 mode);
31}
32
34 const exprt &lhs,
35 const exprt &function,
36 const exprt::operandst &arguments,
37 goto_programt &dest,
38 const irep_idt &mode)
39{
40 // make it all side effect free
41
42 exprt new_lhs = lhs, new_function = function;
43
45
46 clean_expr_resultt side_effects;
47
48 if(!new_lhs.is_nil())
49 side_effects.add(clean_expr(new_lhs, mode));
50
51 side_effects.add(
53
54 dest.destructive_append(side_effects.side_effects);
55
56 // split on the function
57
58 if(new_function.id() == ID_if)
59 {
62 }
63 else if(new_function.id() == ID_symbol)
64 {
67 }
68 else if(new_function.id() == ID_null_object)
69 {
70 }
71 else if(
73 new_function.id() == "virtual_function")
74 {
76 }
77 else
78 {
80 false,
81 "unexpected function argument",
82 new_function.id(),
83 function.find_source_location());
84 }
85
86 destruct_locals(side_effects.temporaries, dest, ns);
87}
88
90 const exprt &lhs,
91 const if_exprt &function,
92 const exprt::operandst &arguments,
93 goto_programt &dest,
94 const irep_idt &mode)
95{
96 // case split
97
98 // c?f():g()
99 //--------------------
100 // v: if(!c) goto y;
101 // w: f();
102 // x: goto z;
103 // y: g();
104 // z: ;
105
106 // do the v label
109 boolean_negate(function.cond()), function.cond().source_location()));
110
111 // do the x label
115
116 // do the z label
119
120 // y: g();
123
124 do_function_call(lhs, function.false_case(), arguments, tmp_y, mode);
125
126 if(tmp_y.instructions.empty())
128 else
129 y = tmp_y.instructions.begin();
130
131 // v: if(!c) goto y;
132 v->complete_goto(y);
133
134 // w: f();
136
137 do_function_call(lhs, function.true_case(), arguments, tmp_w, mode);
138
139 if(tmp_w.instructions.empty())
141
142 // x: goto z;
143 x->complete_goto(z);
144
150}
151
153 const exprt &lhs,
154 const exprt &function,
155 const exprt::operandst &arguments,
156 goto_programt &dest)
157{
158 // don't know what to do with it
159 code_function_callt function_call(lhs, function, arguments);
160 function_call.add_source_location() = function.source_location();
162 function_call, function.source_location()));
163}
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:566
goto_instruction_codet representation of a function call statement.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Definition dstring.h:38
Base class for all expressions.
Definition expr.h:57
const source_locationt & find_source_location() const
Get a source_locationt from the expression or from its operands (non-recursively).
Definition expr.cpp:68
std::vector< exprt > operandst
Definition expr.h:59
const source_locationt & source_location() const
Definition expr.h:236
source_locationt & add_source_location()
Definition expr.h:241
virtual void do_function_call_if(const exprt &lhs, const if_exprt &function, const exprt::operandst &arguments, goto_programt &dest, const irep_idt &mode)
virtual void do_function_call(const exprt &lhs, const exprt &function, const exprt::operandst &arguments, goto_programt &dest, const irep_idt &mode)
void convert_function_call(const code_function_callt &code, goto_programt &dest, const irep_idt &mode)
virtual void do_function_call_symbol(const exprt &lhs, const symbol_exprt &function, const exprt::operandst &arguments, goto_programt &dest, const irep_idt &mode)
add function calls to function queue for later processing
clean_expr_resultt clean_function_call_operands(exprt &function, exprt::operandst &arguments, const irep_idt &mode)
Remove side effects from the function operand and the argument operands of a function call,...
virtual void do_function_call_other(const exprt &lhs, const exprt &function, const exprt::operandst &arguments, goto_programt &dest)
clean_expr_resultt clean_expr(exprt &expr, const irep_idt &mode, bool result_is_used=true)
A generic container class for the GOTO intermediate representation of one function.
instructionst::iterator targett
void destructive_append(goto_programt &p)
Appends the given program p to *this. p is destroyed.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
static instructiont make_function_call(const code_function_callt &_code, const source_locationt &l=source_locationt::nil())
Create a function call instruction.
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
The trinary if-then-else operator.
Definition std_expr.h:2426
exprt & cond()
Definition std_expr.h:2443
exprt & false_case()
Definition std_expr.h:2463
exprt & true_case()
Definition std_expr.h:2453
The Boolean constant true.
Definition std_expr.h:3126
void destruct_locals(const std::list< irep_idt > &vars, goto_programt &dest, const namespacet &ns)
Destructor Calls.
exprt boolean_negate(const exprt &src)
negate a Boolean expression, possibly removing a not_exprt, and swapping false and true
Definition expr_util.cpp:98
Deprecated expression utility functions.
Program Transformation.
#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...
Definition invariant.h:437
API to expression classes.
const if_exprt & to_if_expr(const exprt &expr)
Cast an exprt to an if_exprt.
Definition std_expr.h:2501
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
Definition std_expr.h:221
std::list< irep_idt > temporaries
Identifiers of temporaries introduced while cleaning an expression.
void add(clean_expr_resultt &&other)
goto_programt side_effects
Statements implementing side effects of the expression that was subject to cleaning.