Skip to content

Commit 5206e12

Browse files
Daniel Kroeningtautschnig
Daniel Kroening
authored andcommitted
Store identifiers of parameters in goto_functiont::parameter_identifiers
This is to enable a transition towards #4167.
1 parent 7e5bf13 commit 5206e12

7 files changed

+79
-29
lines changed

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ 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+
41+
PRECONDITION(parameters.size() == function.parameter_identifiers.size());
42+
3943
int param_counter = 0;
40-
for(auto &parameter : function.type.parameters())
44+
auto it = function.parameter_identifiers.begin();
45+
for(auto &parameter : parameters)
4146
{
4247
if(parameter.get_identifier().empty())
4348
{
@@ -53,15 +58,17 @@ void generate_function_bodiest::generate_parameter_names(
5358
new_param_sym.name = new_param_identifier;
5459
new_param_sym.type = parameter.type();
5560
new_param_sym.base_name = param_base_name;
56-
auto const &function_symbol = symbol_table.lookup_ref(function_name);
5761
new_param_sym.mode = function_symbol.mode;
5862
new_param_sym.module = function_symbol.module;
5963
new_param_sym.location = function_symbol.location;
6064
symbol_table.add(new_param_sym);
65+
66+
*it = new_param_identifier;
6167
}
68+
69+
++it;
6270
}
63-
auto &function_symbol = symbol_table.get_writeable_ref(function_name);
64-
function_symbol.type = function.type;
71+
function.type = to_code_type(function_symbol.type);
6572
}
6673

6774
class assume_false_generate_function_bodiest : public generate_function_bodiest

src/goto-programs/goto_convert_functions.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ 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.parameter_identifiers.clear();
158+
f.parameter_identifiers.reserve(code_type.parameters().size());
159+
for(const auto &parameter : code_type.parameters())
160+
f.parameter_identifiers.push_back(parameter.get_identifier());
155161

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

src/goto-programs/goto_function.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,35 @@ class goto_functiont
2929
goto_programt body;
3030

3131
/// The type of the function, indicating the return type and parameter types
32+
/// This is deprecated; get the type from the namespace instead.
3233
code_typet type;
3334

3435
typedef std::vector<irep_idt> parameter_identifierst;
3536

3637
/// The identifiers of the parameters of this function
3738
///
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`).
39+
/// Note: This is now the preferred way of getting the identifiers of the
40+
/// parameters. The identifiers in the type will go away.
4241
parameter_identifierst parameter_identifiers;
4342

4443
bool body_available() const
4544
{
4645
return !body.instructions.empty();
4746
}
4847

48+
/// This is deprecated; get the type from the namespace instead.
4949
bool is_inlined() const
5050
{
5151
return type.get_bool(ID_C_inlined);
5252
}
5353

54+
/// This is deprecated; get the type from the namespace instead.
5455
bool is_hidden() const
5556
{
5657
return type.get_bool(ID_C_hide);
5758
}
5859

60+
/// This is deprecated; modify the type in the namespace instead.
5961
void make_hidden()
6062
{
6163
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: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,16 @@ 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.parameter_identifiers.reserve(
81+
code_type.parameters().size());
82+
for(const auto &parameter : code_type.parameters())
83+
entry.first->second.parameter_identifiers.push_back(
84+
parameter.get_identifier());
7985
}
8086

8187
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)