Skip to content

Commit df79716

Browse files
authored
Merge pull request #4252 from tautschnig/use-parameter-identifiers
Use goto_functiont::parameter_identifiers instead of looking at the type [blocks: #4167]
2 parents 5b32a61 + 619a47c commit df79716

File tree

7 files changed

+53
-91
lines changed

7 files changed

+53
-91
lines changed

src/goto-instrument/code_contracts.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,24 +324,22 @@ void code_contractst::add_contract_check(
324324
}
325325

326326
// decl parameter1 ...
327-
for(code_typet::parameterst::const_iterator
328-
p_it=gf.type.parameters().begin();
329-
p_it!=gf.type.parameters().end();
330-
++p_it)
327+
for(const auto &parameter : gf.parameter_identifiers)
331328
{
332-
symbol_exprt p =
333-
new_tmp_symbol(
334-
p_it->type(), skip->source_location, function, function_symbol.mode)
335-
.symbol_expr();
329+
PRECONDITION(!parameter.empty());
330+
const symbolt &parameter_symbol = ns.lookup(parameter);
331+
332+
symbol_exprt p = new_tmp_symbol(
333+
parameter_symbol.type,
334+
skip->source_location,
335+
function,
336+
parameter_symbol.mode)
337+
.symbol_expr();
336338
check.add(goto_programt::make_decl(p, skip->source_location));
337339

338340
call.arguments().push_back(p);
339341

340-
if(!p_it->get_identifier().empty())
341-
{
342-
symbol_exprt cur_p(p_it->get_identifier(), p_it->type());
343-
replace.insert(cur_p, p);
344-
}
342+
replace.insert(parameter_symbol.symbol_expr(), p);
345343
}
346344

347345
// assume(requires)

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,24 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
209209
instruction->source_location = function_symbol.location;
210210
return instruction;
211211
};
212+
212213
const namespacet ns(symbol_table);
213-
for(auto const &parameter : function.type.parameters())
214+
for(auto const &parameter : function.parameter_identifiers)
214215
{
216+
const symbolt &parameter_symbol = ns.lookup(parameter);
215217
if(
216-
parameter.type().id() == ID_pointer &&
217-
!parameter.type().subtype().get_bool(ID_C_constant) &&
218+
parameter_symbol.type.id() == ID_pointer &&
219+
!parameter_symbol.type.subtype().get_bool(ID_C_constant) &&
218220
std::regex_match(
219-
id2string(parameter.get_base_name()), parameters_to_havoc))
221+
id2string(parameter_symbol.base_name), parameters_to_havoc))
220222
{
221223
auto goto_instruction =
222224
add_instruction(goto_programt::make_incomplete_goto(equal_exprt(
223-
symbol_exprt(parameter.get_identifier(), parameter.type()),
224-
null_pointer_exprt(to_pointer_type(parameter.type())))));
225-
226-
const irep_idt base_name = parameter.get_base_name();
227-
CHECK_RETURN(!base_name.empty());
225+
parameter_symbol.symbol_expr(),
226+
null_pointer_exprt(to_pointer_type(parameter_symbol.type)))));
228227

229228
dereference_exprt dereference_expr(
230-
symbol_exprt(parameter.get_identifier(), parameter.type()),
231-
parameter.type().subtype());
229+
parameter_symbol.symbol_expr(), parameter_symbol.type.subtype());
232230

233231
goto_programt dest;
234232
havoc_expr_rec(

src/goto-programs/goto_function.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@ void get_local_identifiers(
2121
{
2222
goto_function.body.get_decl_identifiers(dest);
2323

24-
const code_typet::parameterst &parameters = goto_function.type.parameters();
25-
2624
// add parameters
27-
for(const auto &param : parameters)
25+
for(const auto &identifier : goto_function.parameter_identifiers)
2826
{
29-
const irep_idt &identifier = param.get_identifier();
3027
if(identifier != "")
3128
dest.insert(identifier);
3229
}

src/goto-programs/goto_inline_class.cpp

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Author: Daniel Kroening, kroening@kroening.com
3131
void goto_inlinet::parameter_assignments(
3232
const goto_programt::targett target,
3333
const irep_idt &function_name, // name of called function
34-
const code_typet &code_type, // type of called function
34+
const goto_functiont::parameter_identifierst &parameter_identifiers,
3535
const exprt::operandst &arguments, // arguments of call
3636
goto_programt &dest)
3737
{
@@ -43,28 +43,21 @@ void goto_inlinet::parameter_assignments(
4343
// iterates over the operands
4444
exprt::operandst::const_iterator it1=arguments.begin();
4545

46-
const code_typet::parameterst &parameter_types=
47-
code_type.parameters();
48-
49-
// iterates over the types of the parameters
50-
for(const auto &parameter : parameter_types)
46+
// iterates over the parameters
47+
for(const auto &identifier : parameter_identifiers)
5148
{
52-
// this is the type the n-th argument should be
53-
const typet &par_type = parameter.type();
54-
55-
const irep_idt &identifier=parameter.get_identifier();
56-
5749
DATA_INVARIANT(
5850
!identifier.empty(),
5951
source_location.as_string() + ": no identifier for function parameter");
6052

61-
{
62-
const symbolt &symbol=ns.lookup(identifier);
53+
const symbolt &symbol = ns.lookup(identifier);
6354

64-
goto_programt::targett decl = dest.add(
65-
goto_programt::make_decl(symbol.symbol_expr(), source_location));
66-
decl->code.add_source_location()=source_location;
67-
}
55+
// this is the type the n-th argument should have
56+
const typet &parameter_type = symbol.type;
57+
58+
goto_programt::targett decl =
59+
dest.add(goto_programt::make_decl(symbol.symbol_expr(), source_location));
60+
decl->code.add_source_location() = source_location;
6861

6962
// this is the actual parameter
7063
exprt actual;
@@ -77,7 +70,7 @@ void goto_inlinet::parameter_assignments(
7770
<< "not enough arguments, "
7871
<< "inserting non-deterministic value" << eom;
7972

80-
actual = side_effect_expr_nondett(par_type, source_location);
73+
actual = side_effect_expr_nondett(parameter_type, source_location);
8174
}
8275
else
8376
actual=*it1;
@@ -90,9 +83,9 @@ void goto_inlinet::parameter_assignments(
9083
{
9184
// it should be the same exact type as the parameter,
9285
// subject to some exceptions
93-
if(!base_type_eq(par_type, actual.type(), ns))
86+
if(!base_type_eq(parameter_type, actual.type(), ns))
9487
{
95-
const typet &f_partype = par_type;
88+
const typet &f_partype = parameter_type;
9689
const typet &f_acttype = actual.type();
9790

9891
// we are willing to do some conversion
@@ -102,7 +95,7 @@ void goto_inlinet::parameter_assignments(
10295
f_acttype.id()==ID_array &&
10396
f_partype.subtype()==f_acttype.subtype()))
10497
{
105-
actual = typecast_exprt(actual, par_type);
98+
actual = typecast_exprt(actual, f_partype);
10699
}
107100
else if((f_partype.id()==ID_signedbv ||
108101
f_partype.id()==ID_unsignedbv ||
@@ -111,7 +104,7 @@ void goto_inlinet::parameter_assignments(
111104
f_acttype.id()==ID_unsignedbv ||
112105
f_acttype.id()==ID_bool))
113106
{
114-
actual = typecast_exprt(actual, par_type);
107+
actual = typecast_exprt(actual, f_partype);
115108
}
116109
else
117110
{
@@ -120,7 +113,7 @@ void goto_inlinet::parameter_assignments(
120113
}
121114

122115
// adds an assignment of the actual parameter to the formal parameter
123-
code_assignt assignment(symbol_exprt(identifier, par_type), actual);
116+
code_assignt assignment(symbol_exprt(identifier, parameter_type), actual);
124117
assignment.add_source_location()=source_location;
125118

126119
dest.add_instruction(ASSIGN);
@@ -140,22 +133,16 @@ void goto_inlinet::parameter_assignments(
140133

141134
void goto_inlinet::parameter_destruction(
142135
const goto_programt::targett target,
143-
const code_typet &code_type, // type of called function
136+
const goto_functiont::parameter_identifierst &parameter_identifiers,
144137
goto_programt &dest)
145138
{
146139
PRECONDITION(target->is_function_call());
147140
PRECONDITION(dest.empty());
148141

149142
const source_locationt &source_location=target->source_location;
150143

151-
const code_typet::parameterst &parameter_types=
152-
code_type.parameters();
153-
154-
// iterates over the types of the parameters
155-
for(const auto &parameter : parameter_types)
144+
for(const auto &identifier : parameter_identifiers)
156145
{
157-
const irep_idt &identifier=parameter.get_identifier();
158-
159146
INVARIANT(
160147
!identifier.empty(),
161148
source_location.as_string() + ": no identifier for function parameter");
@@ -278,14 +265,10 @@ void goto_inlinet::insert_function_body(
278265

279266
goto_programt tmp1;
280267
parameter_assignments(
281-
target,
282-
identifier,
283-
goto_function.type,
284-
arguments,
285-
tmp1);
268+
target, identifier, goto_function.parameter_identifiers, arguments, tmp1);
286269

287270
goto_programt tmp2;
288-
parameter_destruction(target, goto_function.type, tmp2);
271+
parameter_destruction(target, goto_function.parameter_identifiers, tmp2);
289272

290273
goto_programt tmp;
291274
tmp.destructive_append(tmp1); // par assignment

src/goto-programs/goto_inline_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,13 @@ class goto_inlinet:public messaget
178178
void parameter_assignments(
179179
const goto_programt::targett target,
180180
const irep_idt &function_name,
181-
const code_typet &code_type,
181+
const goto_functiont::parameter_identifierst &parameter_identifiers,
182182
const exprt::operandst &arguments,
183183
goto_programt &dest);
184184

185185
void parameter_destruction(
186186
const goto_programt::targett target,
187-
const code_typet &code_type,
187+
const goto_functiont::parameter_identifierst &parameter_identifiers,
188188
goto_programt &dest);
189189

190190
// goto functions that were already inlined transitively

src/goto-programs/interpreter.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -811,16 +811,14 @@ void interpretert::execute_function_call()
811811
}
812812

813813
// assign the arguments
814-
const code_typet::parameterst &parameters=
815-
to_code_type(f_it->second.type).parameters();
816-
817-
if(argument_values.size()<parameters.size())
814+
const auto &parameter_identifiers = f_it->second.parameter_identifiers;
815+
if(argument_values.size() < parameter_identifiers.size())
818816
throw "not enough arguments";
819817

820-
for(std::size_t i=0; i<parameters.size(); i++)
818+
for(std::size_t i = 0; i < parameter_identifiers.size(); i++)
821819
{
822-
const code_typet::parametert &a=parameters[i];
823-
const symbol_exprt symbol_expr(a.get_identifier(), a.type());
820+
const symbol_exprt symbol_expr =
821+
ns.lookup(parameter_identifiers[i]).symbol_expr();
824822
assign(evaluate_address(symbol_expr), argument_values[i]);
825823
}
826824

src/goto-symex/symex_function_call.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,18 @@ void goto_symext::parameter_assignments(
4141
// iterates over the arguments
4242
exprt::operandst::const_iterator it1=arguments.begin();
4343

44-
// these are the types of the parameters
45-
const code_typet::parameterst &parameter_types=
46-
function_type.parameters();
47-
4844
// iterates over the types of the parameters
49-
for(code_typet::parameterst::const_iterator
50-
it2=parameter_types.begin();
51-
it2!=parameter_types.end();
52-
it2++)
45+
for(const auto &identifier : goto_function.parameter_identifiers)
5346
{
54-
const code_typet::parametert &parameter=*it2;
55-
56-
// this is the type that the n-th argument should have
57-
const typet &parameter_type=parameter.type();
58-
59-
const irep_idt &identifier=parameter.get_identifier();
60-
6147
INVARIANT(
62-
!identifier.empty(),
63-
"function pointer parameter must have an identifier");
48+
!identifier.empty(), "function parameter must have an identifier");
6449

6550
const symbolt &symbol=ns.lookup(identifier);
6651
symbol_exprt lhs=symbol.symbol_expr();
6752

53+
// this is the type that the n-th argument should have
54+
const typet &parameter_type = symbol.type;
55+
6856
exprt rhs;
6957

7058
// if you run out of actual arguments there was a mismatch

0 commit comments

Comments
 (0)