Skip to content

Commit 88c9629

Browse files
authored
Merge pull request #4207 from diffblue/parameter_identifiers
Store identifiers of parameters in goto_functiont::parameter_identifiers [blocks: #4167]
2 parents b9898b1 + aa181b6 commit 88c9629

7 files changed

+75
-29
lines changed

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ void generate_function_bodiest::generate_parameter_names(
3535
symbol_tablet &symbol_table,
3636
const irep_idt &function_name) const
3737
{
38-
const namespacet ns(symbol_table);
38+
auto &function_symbol = symbol_table.get_writeable_ref(function_name);
39+
auto &parameters = to_code_type(function_symbol.type).parameters();
40+
3941
int param_counter = 0;
40-
for(auto &parameter : function.type.parameters())
42+
for(auto &parameter : parameters)
4143
{
4244
if(parameter.get_identifier().empty())
4345
{
@@ -53,15 +55,14 @@ void generate_function_bodiest::generate_parameter_names(
5355
new_param_sym.name = new_param_identifier;
5456
new_param_sym.type = parameter.type();
5557
new_param_sym.base_name = param_base_name;
56-
auto const &function_symbol = symbol_table.lookup_ref(function_name);
5758
new_param_sym.mode = function_symbol.mode;
5859
new_param_sym.module = function_symbol.module;
5960
new_param_sym.location = function_symbol.location;
6061
symbol_table.add(new_param_sym);
6162
}
6263
}
63-
auto &function_symbol = symbol_table.get_writeable_ref(function_name);
64-
function_symbol.type = function.type;
64+
function.type = to_code_type(function_symbol.type);
65+
function.set_parameter_identifiers(to_code_type(function_symbol.type));
6566
}
6667

6768
class assume_false_generate_function_bodiest : public generate_function_bodiest

src/goto-programs/goto_convert_functions.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ void goto_convert_functionst::convert_function(
151151
// make tmp variables local to function
152152
tmp_symbol_prefix=id2string(symbol.name)+"::$tmp";
153153

154-
f.type=to_code_type(symbol.type);
154+
// store the parameter identifiers in the goto functions
155+
const code_typet &code_type = to_code_type(symbol.type);
156+
f.type = code_type;
157+
f.set_parameter_identifiers(code_type);
155158

156159
if(symbol.value.is_nil() ||
157160
symbol.is_compiled()) /* goto_inline may have removed the body */

src/goto-programs/goto_function.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Date: May 2018
1616

1717
#include <iosfwd>
1818

19+
#include <util/deprecate.h>
1920
#include <util/find_symbols.h>
2021
#include <util/std_types.h>
2122

@@ -29,33 +30,43 @@ class goto_functiont
2930
goto_programt body;
3031

3132
/// The type of the function, indicating the return type and parameter types
33+
DEPRECATED("Get the type from the symbol table instead")
3234
code_typet type;
3335

3436
typedef std::vector<irep_idt> parameter_identifierst;
3537

3638
/// The identifiers of the parameters of this function
3739
///
38-
/// Note: This variable is currently unused and the vector is thus always
39-
/// empty. In the future the code base may be refactored to fill in the
40-
/// parameter identifiers here when creating a `goto_functiont`. For now the
41-
/// parameter identifiers should be retrieved from the type (`code_typet`).
40+
/// Note: This is now the preferred way of getting the identifiers of the
41+
/// parameters. The identifiers in the type will go away.
4242
parameter_identifierst parameter_identifiers;
4343

4444
bool body_available() const
4545
{
4646
return !body.instructions.empty();
4747
}
4848

49+
void set_parameter_identifiers(const code_typet &code_type)
50+
{
51+
parameter_identifiers.clear();
52+
parameter_identifiers.reserve(code_type.parameters().size());
53+
for(const auto &parameter : code_type.parameters())
54+
parameter_identifiers.push_back(parameter.get_identifier());
55+
}
56+
57+
DEPRECATED("Get the type from the symbol table instead")
4958
bool is_inlined() const
5059
{
5160
return type.get_bool(ID_C_inlined);
5261
}
5362

63+
DEPRECATED("Get the type from the symbol table instead")
5464
bool is_hidden() const
5565
{
5666
return type.get_bool(ID_C_hide);
5767
}
5868

69+
DEPRECATED("Get the type from the symbol table instead")
5970
void make_hidden()
6071
{
6172
type.set(ID_C_hide, true);

src/goto-programs/goto_functions.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class goto_functionst
117117
{
118118
const goto_functiont &goto_function = entry.second;
119119
const auto &function_name = entry.first;
120+
const symbolt &function_symbol = ns.lookup(function_name);
121+
const code_typet::parameterst &parameters =
122+
to_code_type(function_symbol.type).parameters();
120123

121124
DATA_CHECK(
122125
vm,
@@ -125,6 +128,26 @@ class goto_functionst
125128
goto_function.type.id_string() +
126129
"\nsymbol table type: " + ns.lookup(function_name).type.id_string());
127130

131+
DATA_CHECK(
132+
vm,
133+
goto_function.parameter_identifiers.size() == parameters.size(),
134+
id2string(function_name) + " parameter count inconsistency\n" +
135+
"goto program: " +
136+
std::to_string(goto_function.parameter_identifiers.size()) +
137+
"\nsymbol table: " + std::to_string(parameters.size()));
138+
139+
auto it = goto_function.parameter_identifiers.begin();
140+
for(const auto &parameter : parameters)
141+
{
142+
DATA_CHECK(
143+
vm,
144+
it->empty() || ns.lookup(*it).type == parameter.type(),
145+
id2string(function_name) + " parameter type inconsistency\n" +
146+
"goto program: " + ns.lookup(*it).type.id_string() +
147+
"\nsymbol table: " + parameter.type().id_string());
148+
++it;
149+
}
150+
128151
goto_function.validate(ns, vm);
129152
}
130153
}

src/goto-programs/link_goto_model.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ static void rename_symbols_in_function(
2727
irep_idt &new_function_name,
2828
const rename_symbolt &rename_symbol)
2929
{
30+
for(auto &identifier : function.parameter_identifiers)
31+
{
32+
auto entry = rename_symbol.expr_map.find(identifier);
33+
if(entry != rename_symbol.expr_map.end())
34+
identifier = entry->second;
35+
}
36+
3037
goto_programt &program=function.body;
3138
rename_symbol(function.type);
3239

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,12 @@ static bool read_bin_goto_object(
7272

7373
if(!sym.is_type && sym.type.id()==ID_code)
7474
{
75-
// makes sure there is an empty function
76-
// for every function symbol and fixes
77-
// the function types.
78-
functions.function_map[sym.name].type=to_code_type(sym.type);
75+
// makes sure there is an empty function for every function symbol
76+
auto entry = functions.function_map.emplace(sym.name, goto_functiont());
77+
78+
const code_typet &code_type = to_code_type(sym.type);
79+
entry.first->second.type = code_type;
80+
entry.first->second.set_parameter_identifiers(code_type);
7981
}
8082

8183
symbol_table.add(sym);

src/goto-programs/string_abstraction.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -166,31 +166,30 @@ void string_abstractiont::add_str_arguments(
166166
{
167167
symbolt &fct_symbol=*symbol_table.get_writeable(name);
168168

169-
code_typet::parameterst &parameters=
170-
to_code_type(fct.type).parameters();
171169
code_typet::parameterst str_args;
172170

173-
for(code_typet::parameterst::iterator
174-
it=parameters.begin();
175-
it!=parameters.end();
176-
++it)
171+
for(const auto &identifier : fct.parameter_identifiers)
177172
{
178-
const typet &abstract_type=build_abstraction_type(it->type());
179-
if(abstract_type.is_nil())
180-
continue;
181-
182-
const irep_idt &identifier=it->get_identifier();
183173
if(identifier=="")
184174
continue; // ignore
185175

186-
add_argument(str_args, fct_symbol, abstract_type,
187-
id2string(it->get_base_name())+arg_suffix,
188-
id2string(identifier)+arg_suffix);
176+
const symbolt &param_symbol = ns.lookup(identifier);
177+
const typet &abstract_type = build_abstraction_type(param_symbol.type);
178+
if(abstract_type.is_nil())
179+
continue;
180+
181+
add_argument(
182+
str_args,
183+
fct_symbol,
184+
abstract_type,
185+
id2string(param_symbol.base_name) + arg_suffix,
186+
id2string(identifier) + arg_suffix);
189187

190188
current_args.insert(identifier);
191189
}
192190

193-
parameters.insert(parameters.end(), str_args.begin(), str_args.end());
191+
for(const auto &new_param : str_args)
192+
fct.parameter_identifiers.push_back(new_param.get_identifier());
194193
code_typet::parameterst &symb_parameters=
195194
to_code_type(fct_symbol.type).parameters();
196195
symb_parameters.insert(

0 commit comments

Comments
 (0)