Skip to content

Commit ee3b3fb

Browse files
authored
Merge pull request #4167 from tautschnig/parameter-identifiers
Use goto_functiont::parameter_identifiers and remove goto_functiont::type
2 parents 53750fa + 33d85ff commit ee3b3fb

23 files changed

+79
-198
lines changed

src/assembler/remove_asm.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ void remove_asmt::gcc_asm_function_call(
122122
symbol.mode = ID_C;
123123

124124
symbol_table.add(symbol);
125-
}
126125

127-
if(
128-
goto_functions.function_map.find(function_identifier) ==
129-
goto_functions.function_map.end())
126+
goto_functions.function_map.emplace(function_identifier, goto_functiont());
127+
}
128+
else
130129
{
131-
auto &f = goto_functions.function_map[function_identifier];
132-
f.type = fkt_type;
130+
DATA_INVARIANT(
131+
symbol_table.lookup_ref(function_identifier).type == fkt_type,
132+
"function types should match");
133133
}
134134
}
135135

@@ -171,14 +171,14 @@ void remove_asmt::msc_asm_function_call(
171171
symbol.mode = ID_C;
172172

173173
symbol_table.add(symbol);
174-
}
175174

176-
if(
177-
goto_functions.function_map.find(function_identifier) ==
178-
goto_functions.function_map.end())
175+
goto_functions.function_map.emplace(function_identifier, goto_functiont());
176+
}
177+
else
179178
{
180-
auto &f = goto_functions.function_map[function_identifier];
181-
f.type = fkt_type;
179+
DATA_INVARIANT(
180+
symbol_table.lookup_ref(function_identifier).type == fkt_type,
181+
"function types should match");
182182
}
183183
}
184184

src/goto-checker/symex_coverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ goto_program_coverage_recordt::goto_program_coverage_recordt(
161161
xml.set_attribute("name", id2string(gf_it->first));
162162

163163
xml.set_attribute(
164-
"signature", from_type(ns, gf_it->first, gf_it->second.type));
164+
"signature", from_type(ns, gf_it->first, ns.lookup(gf_it->first).type));
165165

166166
xml.set_attribute("line-rate", rate_detailed(lines_covered, lines_total));
167167
xml.set_attribute("branch-rate", rate(branches_covered, branches_total));

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,6 @@ void function_call_harness_generatort::implt::
453453

454454
symbol_table->insert(harness_function_symbol);
455455

456-
auto const &generated_harness =
457-
symbol_table->lookup_ref(harness_function_name);
458-
goto_functions->function_map[harness_function_name].type =
459-
to_code_type(generated_harness.type);
460456
goto_convert(*symbol_table, *goto_functions, *message_handler);
461457
}
462458

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ void memory_snapshot_harness_generatort::
322322
CHECK_RETURN(function_iterator_pair.second);
323323

324324
goto_functiont &harness_function = function_iterator_pair.first->second;
325-
harness_function.type = to_code_type(function.type);
326325

327326
goto_convert(
328327
goto_model.symbol_table, goto_model.goto_functions, message_handler);

src/goto-harness/recursive_initialization.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ irep_idt recursive_initializationt::build_constructor(const exprt &expr)
366366
expr_name,
367367
is_nullable);
368368

369-
goto_model.goto_functions.function_map[function_symbol.name].type =
370-
to_code_type(function_symbol.type);
371369
return type_constructor_names.at(key);
372370
}
373371

src/goto-instrument/code_contracts.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,8 @@ void code_contractst::instrument_call_statement(
484484
return;
485485
}
486486

487-
exprt called_assigns = static_cast<const exprt &>(
488-
called_func->second.type.find(ID_C_spec_assigns));
487+
exprt called_assigns =
488+
static_cast<const exprt &>(called_sym.type.find(ID_C_spec_assigns));
489489
if(called_assigns.is_nil()) // Called function has no assigns clause
490490
{
491491
// Fail if called function has no assigns clause.
@@ -749,8 +749,6 @@ bool code_contractst::enforce_contract(const std::string &fun_to_enforce)
749749

750750
goto_functiont &wrapper = goto_functions.function_map[original];
751751
wrapper.parameter_identifiers = mangled_fun->second.parameter_identifiers;
752-
if(mangled_fun->second.type.is_not_nil())
753-
wrapper.type = mangled_fun->second.type;
754752
wrapper.body.add(goto_programt::make_end_function(sl));
755753
add_contract_check(original, mangled, wrapper.body);
756754
return false;
@@ -763,18 +761,15 @@ void code_contractst::add_contract_check(
763761
{
764762
PRECONDITION(!dest.instructions.empty());
765763

766-
goto_functionst::function_mapt::iterator f_it =
767-
goto_functions.function_map.find(mangled_fun);
768-
PRECONDITION(f_it != goto_functions.function_map.end());
769-
770-
const goto_functionst::goto_functiont &gf = f_it->second;
764+
const symbolt &function_symbol = ns.lookup(mangled_fun);
765+
const code_typet &code_type = to_code_type(function_symbol.type);
771766

772767
const exprt &assigns =
773-
static_cast<const exprt &>(gf.type.find(ID_C_spec_assigns));
768+
static_cast<const exprt &>(code_type.find(ID_C_spec_assigns));
774769
const exprt &requires =
775-
static_cast<const exprt &>(gf.type.find(ID_C_spec_requires));
770+
static_cast<const exprt &>(code_type.find(ID_C_spec_requires));
776771
const exprt &ensures =
777-
static_cast<const exprt &>(gf.type.find(ID_C_spec_ensures));
772+
static_cast<const exprt &>(code_type.find(ID_C_spec_ensures));
778773
INVARIANT(
779774
ensures.is_not_nil() || assigns.is_not_nil(),
780775
"Code contract enforcement is trivial without an ensures or assigns "
@@ -803,15 +798,14 @@ void code_contractst::add_contract_check(
803798
skip->source_location));
804799

805800
// prepare function call including all declarations
806-
const symbolt &function_symbol = ns.lookup(mangled_fun);
807801
code_function_callt call(function_symbol.symbol_expr());
808802
replace_symbolt replace;
809803

810804
// decl ret
811-
if(gf.type.return_type()!=empty_typet())
805+
if(code_type.return_type() != empty_typet())
812806
{
813807
symbol_exprt r = new_tmp_symbol(
814-
gf.type.return_type(),
808+
code_type.return_type(),
815809
skip->source_location,
816810
wrapper_fun,
817811
function_symbol.mode)
@@ -825,6 +819,11 @@ void code_contractst::add_contract_check(
825819
}
826820

827821
// decl parameter1 ...
822+
goto_functionst::function_mapt::iterator f_it =
823+
goto_functions.function_map.find(mangled_fun);
824+
PRECONDITION(f_it != goto_functions.function_map.end());
825+
826+
const goto_functionst::goto_functiont &gf = f_it->second;
828827
for(const auto &parameter : gf.parameter_identifiers)
829828
{
830829
PRECONDITION(!parameter.empty());

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void generate_function_bodiest::generate_parameter_names(
6464
symbol_table.add(new_param_sym);
6565
}
6666
}
67-
function.type = to_code_type(function_symbol.type);
6867
function.set_parameter_identifiers(to_code_type(function_symbol.type));
6968
}
7069

@@ -321,9 +320,10 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
321320
function.body.destructive_append(dest);
322321
}
323322

324-
if(function.type.return_type() != empty_typet())
323+
const typet &return_type = to_code_type(function_symbol.type).return_type();
324+
if(return_type != empty_typet())
325325
{
326-
typet type(function.type.return_type());
326+
typet type(return_type);
327327
type.remove(ID_C_constant);
328328

329329
symbolt &aux_symbol = get_fresh_aux_symbol(
@@ -350,8 +350,8 @@ class havoc_generate_function_bodiest : public generate_function_bodiest
350350

351351
function.body.destructive_append(dest);
352352

353-
exprt return_expr = typecast_exprt::conditional_cast(
354-
aux_symbol.symbol_expr(), function.type.return_type());
353+
exprt return_expr =
354+
typecast_exprt::conditional_cast(aux_symbol.symbol_expr(), return_type);
355355

356356
add_instruction(goto_programt::make_return(code_returnt(return_expr)));
357357

@@ -590,8 +590,6 @@ void generate_function_bodies(
590590
model.symbol_table.lookup_ref(havoc_function_symbol.name);
591591

592592
// convert to get the function stub to goto-model
593-
model.goto_functions.function_map[havoc_function_symbol.name].type =
594-
to_code_type(generated_havoc.type);
595593
goto_convert(model.symbol_table, model.goto_functions, message_handler);
596594

597595
// now generate body as above

src/goto-instrument/replace_calls.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,8 @@ void replace_callst::operator()(
9494
auto f_it2 = goto_functions.function_map.find(new_id);
9595
PRECONDITION(f_it2 != goto_functions.function_map.end());
9696

97-
PRECONDITION(base_type_eq(f_it1->second.type, f_it2->second.type, ns));
98-
9997
// check that returns have not been removed
100-
if(to_code_type(f_it1->second.type).return_type().id() != ID_empty)
98+
if(to_code_type(function.type()).return_type().id() != ID_empty)
10199
{
102100
goto_programt::const_targett next_it = std::next(it);
103101
if(next_it != goto_program.instructions.end() && next_it->is_assign())
@@ -112,7 +110,7 @@ void replace_callst::operator()(
112110
}
113111

114112
// Finally modify the call
115-
function.type() = f_it2->second.type;
113+
function.type() = ns.lookup(f_it2->first).type;
116114
se.set_identifier(new_id);
117115

118116
ins.set_function_call(cfc);
@@ -167,7 +165,8 @@ void replace_callst::check_replacement_map(
167165
auto it1 = goto_functions.function_map.find(p.first);
168166
if(it1 != goto_functions.function_map.end())
169167
{
170-
if(!base_type_eq(it1->second.type, it2->second.type, ns))
168+
if(!base_type_eq(
169+
ns.lookup(it1->first).type, ns.lookup(it2->first).type, ns))
171170
throw invalid_command_line_argument_exceptiont(
172171
"functions " + id2string(p.first) + " and " + id2string(p.second) +
173172
" are not type-compatible",

src/goto-programs/goto_convert_functions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ bool goto_convert_functionst::hide(const goto_programt &goto_program)
8787

8888
void goto_convert_functionst::add_return(
8989
goto_functionst::goto_functiont &f,
90+
const typet &return_type,
9091
const source_locationt &source_location)
9192
{
9293
#if 0
@@ -133,7 +134,7 @@ void goto_convert_functionst::add_return(
133134

134135
#endif
135136

136-
side_effect_expr_nondett rhs(f.type.return_type(), source_location);
137+
side_effect_expr_nondett rhs(return_type, source_location);
137138

138139
f.body.add(
139140
goto_programt::make_return(code_returnt(std::move(rhs)), source_location));
@@ -154,7 +155,6 @@ void goto_convert_functionst::convert_function(
154155

155156
// store the parameter identifiers in the goto functions
156157
const code_typet &code_type = to_code_type(symbol.type);
157-
f.type = code_type;
158158
f.set_parameter_identifiers(code_type);
159159

160160
if(
@@ -190,15 +190,15 @@ void goto_convert_functionst::convert_function(
190190

191191
targets = targetst();
192192
targets.set_return(end_function);
193-
targets.has_return_value = f.type.return_type().id() != ID_empty &&
194-
f.type.return_type().id() != ID_constructor &&
195-
f.type.return_type().id() != ID_destructor;
193+
targets.has_return_value = code_type.return_type().id() != ID_empty &&
194+
code_type.return_type().id() != ID_constructor &&
195+
code_type.return_type().id() != ID_destructor;
196196

197197
goto_convert_rec(code, f.body, mode);
198198

199199
// add non-det return value, if needed
200200
if(targets.has_return_value)
201-
add_return(f, end_location);
201+
add_return(f, code_type.return_type(), end_location);
202202

203203
// handle SV-COMP's __VERIFIER_atomic_
204204
if(

src/goto-programs/goto_convert_functions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class goto_convert_functionst:public goto_convertt
5858
//
5959
void add_return(
6060
goto_functionst::goto_functiont &,
61+
const typet &return_type,
6162
const source_locationt &);
6263
};
6364

src/goto-programs/goto_function.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,4 @@ void goto_functiont::validate(const namespacet &ns, const validation_modet vm)
4646
}
4747

4848
body.validate(ns, vm);
49-
50-
find_symbols_sett typetags;
51-
find_type_symbols(type, typetags);
52-
const symbolt *symbol;
53-
for(const auto &identifier : typetags)
54-
{
55-
DATA_CHECK(
56-
vm, !ns.lookup(identifier, symbol), id2string(identifier) + " not found");
57-
}
58-
59-
// Check that a void function does not contain any RETURN instructions
60-
if(to_code_type(type).return_type().id() == ID_empty)
61-
{
62-
forall_goto_program_instructions(instruction, body)
63-
{
64-
DATA_CHECK(
65-
vm,
66-
!instruction->is_return(),
67-
"void function should not return a value");
68-
}
69-
}
70-
71-
validate_full_type(type, ns, vm);
7249
}

src/goto-programs/goto_function.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,19 @@ Date: May 2018
1616

1717
#include <iosfwd>
1818

19-
#include <util/deprecate.h>
2019
#include <util/find_symbols.h>
2120
#include <util/std_types.h>
2221

2322
#include "goto_program.h"
2423

25-
/// A goto function, consisting of function type (see #type), function body (see
26-
/// #body), and parameter identifiers (see #parameter_identifiers).
24+
/// A goto function, consisting of function body (see #body) and parameter
25+
/// identifiers (see #parameter_identifiers).
2726
class goto_functiont
2827
{
2928
public:
3029
goto_programt body;
3130

32-
/// The type of the function, indicating the return type and parameter types
33-
DEPRECATED(SINCE(2019, 2, 16, "Get the type from the symbol table instead"))
34-
code_typet type;
35-
3631
typedef std::vector<irep_idt> parameter_identifierst;
37-
3832
/// The identifiers of the parameters of this function
3933
///
4034
/// Note: This is now the preferred way of getting the identifiers of the
@@ -54,12 +48,6 @@ class goto_functiont
5448
parameter_identifiers.push_back(parameter.get_identifier());
5549
}
5650

57-
DEPRECATED(SINCE(2019, 2, 16, "Get the type from the symbol table instead"))
58-
bool is_inlined() const
59-
{
60-
return type.get_bool(ID_C_inlined);
61-
}
62-
6351
bool is_hidden() const
6452
{
6553
return function_is_hidden;
@@ -70,30 +58,27 @@ class goto_functiont
7058
function_is_hidden = true;
7159
}
7260

73-
goto_functiont() : body(), type({}, empty_typet()), function_is_hidden(false)
61+
goto_functiont() : body(), function_is_hidden(false)
7462
{
7563
}
7664

7765
void clear()
7866
{
7967
body.clear();
80-
type.clear();
8168
parameter_identifiers.clear();
8269
function_is_hidden = false;
8370
}
8471

8572
void swap(goto_functiont &other)
8673
{
8774
body.swap(other.body);
88-
type.swap(other.type);
8975
parameter_identifiers.swap(other.parameter_identifiers);
9076
std::swap(function_is_hidden, other.function_is_hidden);
9177
}
9278

9379
void copy_from(const goto_functiont &other)
9480
{
9581
body.copy_from(other.body);
96-
type = other.type;
9782
parameter_identifiers = other.parameter_identifiers;
9883
function_is_hidden = other.function_is_hidden;
9984
}
@@ -103,7 +88,6 @@ class goto_functiont
10388

10489
goto_functiont(goto_functiont &&other)
10590
: body(std::move(other.body)),
106-
type(std::move(other.type)),
10791
parameter_identifiers(std::move(other.parameter_identifiers)),
10892
function_is_hidden(other.function_is_hidden)
10993
{
@@ -112,7 +96,6 @@ class goto_functiont
11296
goto_functiont &operator=(goto_functiont &&other)
11397
{
11498
body = std::move(other.body);
115-
type = std::move(other.type);
11699
parameter_identifiers = std::move(other.parameter_identifiers);
117100
function_is_hidden = other.function_is_hidden;
118101
return *this;

0 commit comments

Comments
 (0)