Skip to content

Commit f9fe973

Browse files
committed
Revert "WIP"
This reverts commit d39e00ea28937cd4cf7279edf4aad741dad50fae.
1 parent cb9c3d7 commit f9fe973

16 files changed

+120
-107
lines changed

src/assembler/remove_asm.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ void remove_asmt::gcc_asm_function_call(
123123

124124
symbol_table.add(symbol);
125125
}
126-
else
126+
127+
if(
128+
goto_functions.function_map.find(function_identifier) ==
129+
goto_functions.function_map.end())
127130
{
128-
DATA_INVARIANT(
129-
symbol_table.lookup_ref(function_identifier).type == fkt_type,
130-
"function types should match");
131+
auto &f = goto_functions.function_map[function_identifier];
132+
f.type = fkt_type;
131133
}
132134
}
133135

@@ -170,11 +172,13 @@ void remove_asmt::msc_asm_function_call(
170172

171173
symbol_table.add(symbol);
172174
}
173-
else
175+
176+
if(
177+
goto_functions.function_map.find(function_identifier) ==
178+
goto_functions.function_map.end())
174179
{
175-
DATA_INVARIANT(
176-
symbol_table.lookup_ref(function_identifier).type == fkt_type,
177-
"function types should match");
180+
auto &f = goto_functions.function_map[function_identifier];
181+
f.type = fkt_type;
178182
}
179183
}
180184

src/goto-programs/goto_convert_functions.cpp

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

8787
void goto_convert_functionst::add_return(
8888
goto_functionst::goto_functiont &f,
89-
const typet &return_type,
9089
const source_locationt &source_location)
9190
{
9291
#if 0
@@ -130,7 +129,7 @@ void goto_convert_functionst::add_return(
130129

131130
#endif
132131

133-
const side_effect_expr_nondett rhs(return_type, source_location);
132+
const side_effect_expr_nondett rhs(f.type.return_type(), source_location);
134133

135134
goto_programt::targett t=f.body.add_instruction();
136135
t->make_return();
@@ -151,10 +150,7 @@ void goto_convert_functionst::convert_function(
151150
// make tmp variables local to function
152151
tmp_symbol_prefix=id2string(symbol.name)+"::$tmp";
153152

154-
const code_typet &code_type = to_code_type(symbol.type);
155-
f.parameter_identifiers.reserve(code_type.parameters().size());
156-
for(const auto &parameter : code_type.parameters())
157-
f.parameter_identifiers.push_back(parameter.get_identifier());
153+
f.type=to_code_type(symbol.type);
158154

159155
if(symbol.value.is_nil() ||
160156
symbol.is_compiled()) /* goto_inline may have removed the body */
@@ -181,15 +177,15 @@ void goto_convert_functionst::convert_function(
181177
targets=targetst();
182178
targets.set_return(end_function);
183179
targets.has_return_value=
184-
code_type.return_type().id()!=ID_empty &&
185-
code_type.return_type().id()!=ID_constructor &&
186-
code_type.return_type().id()!=ID_destructor;
180+
f.type.return_type().id()!=ID_empty &&
181+
f.type.return_type().id()!=ID_constructor &&
182+
f.type.return_type().id()!=ID_destructor;
187183

188184
goto_convert_rec(code, f.body, mode);
189185

190186
// add non-det return value, if needed
191187
if(targets.has_return_value)
192-
add_return(f, code_type.return_type(), end_location);
188+
add_return(f, end_location);
193189

194190
// handle SV-COMP's __VERIFIER_atomic_
195191
if(!f.body.instructions.empty() &&
@@ -217,7 +213,7 @@ void goto_convert_functionst::convert_function(
217213
f.body.update();
218214

219215
if(hide(f.body))
220-
to_code_type(symbol_table.get_writeable_ref(identifier).type).make_hidden();
216+
f.make_hidden();
221217

222218
lifetime = parent_lifetime;
223219
}

src/goto-programs/goto_convert_functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ class goto_convert_functionst:public goto_convertt
5858
//
5959
void add_return(
6060
goto_functionst::goto_functiont &,
61-
const typet &return_type,
6261
const source_locationt &);
6362
};
6463

src/goto-programs/goto_function.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,61 @@ class goto_functiont
2828
public:
2929
goto_programt body;
3030

31+
/// The type of the function, indicating the return type and parameter types
32+
code_typet type;
33+
3134
typedef std::vector<irep_idt> parameter_identifierst;
35+
3236
/// The identifiers of the parameters of this function
37+
///
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`).
3342
parameter_identifierst parameter_identifiers;
3443

3544
bool body_available() const
3645
{
3746
return !body.instructions.empty();
3847
}
3948

40-
goto_functiont() = default;
49+
bool is_inlined() const
50+
{
51+
return type.get_bool(ID_C_inlined);
52+
}
53+
54+
bool is_hidden() const
55+
{
56+
return type.get_bool(ID_C_hide);
57+
}
58+
59+
void make_hidden()
60+
{
61+
type.set(ID_C_hide, true);
62+
}
63+
64+
goto_functiont() : body(), type({}, empty_typet())
65+
{
66+
}
4167

4268
void clear()
4369
{
4470
body.clear();
71+
type.clear();
4572
parameter_identifiers.clear();
4673
}
4774

4875
void swap(goto_functiont &other)
4976
{
5077
body.swap(other.body);
78+
type.swap(other.type);
5179
parameter_identifiers.swap(other.parameter_identifiers);
5280
}
5381

5482
void copy_from(const goto_functiont &other)
5583
{
5684
body.copy_from(other.body);
85+
type = other.type;
5786
parameter_identifiers = other.parameter_identifiers;
5887
}
5988

@@ -62,13 +91,15 @@ class goto_functiont
6291

6392
goto_functiont(goto_functiont &&other)
6493
: body(std::move(other.body)),
94+
type(std::move(other.type)),
6595
parameter_identifiers(std::move(other.parameter_identifiers))
6696
{
6797
}
6898

6999
goto_functiont &operator=(goto_functiont &&other)
70100
{
71101
body = std::move(other.body);
102+
type = std::move(other.type);
72103
parameter_identifiers = std::move(other.parameter_identifiers);
73104
return *this;
74105
}

src/goto-programs/goto_functions.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,28 +117,13 @@ 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();
123120

124121
DATA_CHECK(
125122
vm,
126-
goto_function.parameter_identifiers.size() == parameters.size(),
127-
id2string(function_name) + " parameter count inconsistency\n" +
128-
"goto program: " + std::to_string(goto_function.parameter_identifiers.size()) +
129-
"\nsymbol table: " + std::to_string(parameters.size()));
130-
131-
auto it = goto_function.parameter_identifiers.begin();
132-
for(const auto &parameter : parameters)
133-
{
134-
DATA_CHECK(
135-
vm,
136-
ns.lookup(*it).type == parameter.type(),
137-
id2string(function_name) + " parameter type inconsistency\n" +
138-
"goto program: " + ns.lookup(*it).type.id_string() +
139-
"\nsymbol table: " + parameter.type().id_string());
140-
++it;
141-
}
123+
goto_function.type == ns.lookup(function_name).type,
124+
id2string(function_name) + " type inconsistency\ngoto program type: " +
125+
goto_function.type.id_string() +
126+
"\nsymbol table type: " + ns.lookup(function_name).type.id_string());
142127

143128
goto_function.validate(ns, vm);
144129
}

src/goto-programs/goto_inline.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ void goto_partial_inline(
195195
continue;
196196

197197
if(
198-
to_code_type(ns.lookup(id).type).get_inlined() ||
198+
called_function.is_inlined() ||
199199
called_function.body.instructions.size() <= smallfunc_limit)
200200
{
201201
PRECONDITION(i_it->is_function_call());

src/goto-programs/goto_inline_class.cpp

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

46-
// iterates over the parameters
47-
for(const auto &identifier : parameter_identifiers)
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)
4851
{
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+
4957
DATA_INVARIANT(
5058
!identifier.empty(),
5159
source_location.as_string() + ": no identifier for function parameter");
5260

53-
const symbolt &symbol=ns.lookup(identifier);
54-
55-
// this is the type the n-th argument should be
56-
const typet &par_type = symbol.type;
61+
{
62+
const symbolt &symbol=ns.lookup(identifier);
5763

58-
goto_programt::targett decl = dest.add(
59-
goto_programt::make_decl(symbol.symbol_expr(), source_location));
60-
decl->code.add_source_location()=source_location;
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+
}
6168

6269
// this is the actual parameter
6370
exprt actual;
@@ -133,16 +140,22 @@ void goto_inlinet::parameter_assignments(
133140

134141
void goto_inlinet::parameter_destruction(
135142
const goto_programt::targett target,
136-
const goto_functiont::parameter_identifierst &parameter_identifiers,
143+
const code_typet &code_type, // type of called function
137144
goto_programt &dest)
138145
{
139146
PRECONDITION(target->is_function_call());
140147
PRECONDITION(dest.empty());
141148

142149
const source_locationt &source_location=target->source_location;
143150

144-
for(const auto &identifier : parameter_identifiers)
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)
145156
{
157+
const irep_idt &identifier=parameter.get_identifier();
158+
146159
INVARIANT(
147160
!identifier.empty(),
148161
source_location.as_string() + ": no identifier for function parameter");
@@ -254,9 +267,8 @@ void goto_inlinet::insert_function_body(
254267
"final instruction of a function must be an END_FUNCTION");
255268
end.type=LOCATION;
256269

257-
const symbolt &function_symbol = ns.lookup(identifier);
258270
// make sure the inlined function does not introduce hiding
259-
if(to_code_type(function_symbol.type).is_hidden())
271+
if(goto_function.is_hidden())
260272
{
261273
for(auto &instruction : body.instructions)
262274
instruction.labels.remove(CPROVER_PREFIX "HIDE");
@@ -268,12 +280,12 @@ void goto_inlinet::insert_function_body(
268280
parameter_assignments(
269281
target,
270282
identifier,
271-
goto_function.parameter_identifiers,
283+
goto_function.type,
272284
arguments,
273285
tmp1);
274286

275287
goto_programt tmp2;
276-
parameter_destruction(target, goto_function.parameter_identifiers, tmp2);
288+
parameter_destruction(target, goto_function.type, tmp2);
277289

278290
goto_programt tmp;
279291
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 goto_functiont::parameter_identifierst &parameter_identifiers,
181+
const code_typet &code_type,
182182
const exprt::operandst &arguments,
183183
goto_programt &dest);
184184

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

190190
// goto functions that were already inlined transitively

src/goto-programs/link_goto_model.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,8 @@ 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-
3730
goto_programt &program=function.body;
31+
rename_symbol(function.type);
3832

3933
Forall_goto_program_instructions(iit, program)
4034
{

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ static bool read_bin_goto_object(
8787
irep_idt fname=irepconverter.read_gb_string(in);
8888
goto_functionst::goto_functiont &f = functions.function_map[fname];
8989

90-
// parameter identifiers
91-
std::size_t param_count = irepconverter.read_gb_word(in);
92-
f.parameter_identifiers.reserve(param_count);
93-
while(param_count-- > 0)
94-
f.parameter_identifiers.push_back(irepconverter.read_string_ref(in));
95-
9690
typedef std::map<goto_programt::targett, std::list<unsigned> > target_mapt;
9791
target_mapt target_map;
9892
typedef std::map<unsigned, goto_programt::targett> rev_target_mapt;

0 commit comments

Comments
 (0)