@@ -51,7 +51,6 @@ exprt get_size(const typet &type, const namespacet &ns, messaget &log)
51
51
52
52
void code_contractst::check_apply_loop_contracts (
53
53
goto_functionst::goto_functiont &goto_function,
54
- const irep_idt &function_name,
55
54
const local_may_aliast &local_may_alias,
56
55
const goto_programt::targett loop_head,
57
56
const loopt &loop,
@@ -161,12 +160,10 @@ void code_contractst::check_apply_loop_contracts(
161
160
for (const auto &clause : decreases_clause.operands ())
162
161
{
163
162
old_temporary_variables.push_back (
164
- new_tmp_symbol (
165
- clause.type (), loop_head->source_location , function_name, mode)
163
+ new_tmp_symbol (clause.type (), loop_head->source_location , mode)
166
164
.symbol_expr ());
167
165
new_temporary_variables.push_back (
168
- new_tmp_symbol (
169
- clause.type (), loop_head->source_location , function_name, mode)
166
+ new_tmp_symbol (clause.type (), loop_head->source_location , mode)
170
167
.symbol_expr ());
171
168
}
172
169
@@ -396,14 +393,12 @@ void code_contractst::replace_old_parameter(
396
393
exprt &expr,
397
394
std::map<exprt, exprt> ¶meter2history,
398
395
source_locationt location,
399
- const irep_idt &function,
400
396
const irep_idt &mode,
401
397
goto_programt &history)
402
398
{
403
399
for (auto &op : expr.operands ())
404
400
{
405
- replace_old_parameter (
406
- op, parameter2history, location, function, mode, history);
401
+ replace_old_parameter (op, parameter2history, location, mode, history);
407
402
}
408
403
409
404
if (expr.id () == ID_old)
@@ -425,8 +420,7 @@ void code_contractst::replace_old_parameter(
425
420
// 1. Create a temporary symbol expression that represents the
426
421
// history variable
427
422
symbol_exprt tmp_symbol =
428
- new_tmp_symbol (dereference_expr.type (), location, function, mode)
429
- .symbol_expr ();
423
+ new_tmp_symbol (dereference_expr.type (), location, mode).symbol_expr ();
430
424
431
425
// 2. Associate the above temporary variable to it's corresponding
432
426
// expression
@@ -458,15 +452,13 @@ std::pair<goto_programt, goto_programt>
458
452
code_contractst::create_ensures_instruction (
459
453
codet &expression,
460
454
source_locationt location,
461
- const irep_idt &function,
462
455
const irep_idt &mode)
463
456
{
464
457
std::map<exprt, exprt> parameter2history;
465
458
goto_programt history;
466
459
467
460
// Find and replace "old" expression in the "expression" variable
468
- replace_old_parameter (
469
- expression, parameter2history, location, function, mode, history);
461
+ replace_old_parameter (expression, parameter2history, location, mode, history);
470
462
471
463
// Create instructions corresponding to the ensures clause
472
464
goto_programt ensures_program;
@@ -479,7 +471,6 @@ code_contractst::create_ensures_instruction(
479
471
}
480
472
481
473
bool code_contractst::apply_function_contract (
482
- const irep_idt &function_id,
483
474
goto_programt &goto_program,
484
475
goto_programt::targett target)
485
476
{
@@ -603,7 +594,6 @@ bool code_contractst::apply_function_contract(
603
594
ensures_pair = create_ensures_instruction (
604
595
assumption,
605
596
ensures.source_location (),
606
- function,
607
597
symbol_table.lookup_ref (function).mode );
608
598
609
599
// add all the history variable initialization instructions
@@ -617,9 +607,9 @@ bool code_contractst::apply_function_contract(
617
607
// in the assigns clause.
618
608
if (assigns.is_not_nil ())
619
609
{
620
- assigns_clauset assigns_cause (assigns, *this , function_id , log );
610
+ assigns_clauset assigns_cause (assigns, *this , function , log );
621
611
goto_programt assigns_havoc = assigns_cause.havoc_code (
622
- function_symbol.location , function_id , function_symbol.mode );
612
+ function_symbol.location , function , function_symbol.mode );
623
613
624
614
// Insert the non-deterministic assignment immediately before the call site.
625
615
std::size_t lines_to_iterate = assigns_havoc.instructions .size ();
@@ -644,7 +634,7 @@ bool code_contractst::apply_function_contract(
644
634
}
645
635
646
636
void code_contractst::apply_loop_contract (
647
- const irep_idt &function_name ,
637
+ const irep_idt &function ,
648
638
goto_functionst::goto_functiont &goto_function)
649
639
{
650
640
local_may_aliast local_may_alias (goto_function);
@@ -656,23 +646,21 @@ void code_contractst::apply_loop_contract(
656
646
{
657
647
check_apply_loop_contracts (
658
648
goto_function,
659
- function_name,
660
649
local_may_alias,
661
650
loop.first ,
662
651
loop.second ,
663
- symbol_table.lookup_ref (function_name ).mode );
652
+ symbol_table.lookup_ref (function ).mode );
664
653
}
665
654
}
666
655
667
656
const symbolt &code_contractst::new_tmp_symbol (
668
657
const typet &type,
669
658
const source_locationt &source_location,
670
- const irep_idt &function_id,
671
659
const irep_idt &mode)
672
660
{
673
661
return get_fresh_aux_symbol (
674
662
type,
675
- id2string (function_id ) + " ::tmp_cc" ,
663
+ id2string (source_location. get_function () ) + " ::tmp_cc" ,
676
664
" tmp_cc" ,
677
665
source_location,
678
666
mode,
@@ -731,7 +719,6 @@ void code_contractst::instrument_call_statement(
731
719
goto_programt::instructionst::iterator &instruction_iterator,
732
720
goto_programt &program,
733
721
exprt &assigns,
734
- const irep_idt &function_id,
735
722
std::set<irep_idt> &freely_assignable_symbols,
736
723
assigns_clauset &assigns_clause)
737
724
{
@@ -827,7 +814,7 @@ void code_contractst::instrument_call_statement(
827
814
828
815
// check compatibility of assigns clause with the called function
829
816
assigns_clauset called_assigns_clause (
830
- called_assigns, *this , function_id , log );
817
+ called_assigns, *this , called_name , log );
831
818
exprt compatible =
832
819
assigns_clause.compatible_expression (called_assigns_clause);
833
820
goto_programt alias_assertion;
@@ -992,7 +979,6 @@ void code_contractst::check_frame_conditions(
992
979
instruction_it,
993
980
program,
994
981
assigns_expr,
995
- target.name ,
996
982
freely_assignable_symbols,
997
983
assigns);
998
984
}
@@ -1073,13 +1059,13 @@ bool code_contractst::enforce_contract(const irep_idt &function)
1073
1059
}
1074
1060
1075
1061
void code_contractst::add_contract_check (
1076
- const irep_idt &wrapper_fun ,
1077
- const irep_idt &mangled_fun ,
1062
+ const irep_idt &wrapper_function ,
1063
+ const irep_idt &mangled_function ,
1078
1064
goto_programt &dest)
1079
1065
{
1080
1066
PRECONDITION (!dest.instructions .empty ());
1081
1067
1082
- const symbolt &function_symbol = ns.lookup (mangled_fun );
1068
+ const symbolt &function_symbol = ns.lookup (mangled_function );
1083
1069
const auto &code_type = to_code_with_contract_type (function_symbol.type );
1084
1070
1085
1071
exprt assigns = code_type.assigns ();
@@ -1123,7 +1109,6 @@ void code_contractst::add_contract_check(
1123
1109
symbol_exprt r = new_tmp_symbol (
1124
1110
code_type.return_type (),
1125
1111
skip->source_location ,
1126
- wrapper_fun,
1127
1112
function_symbol.mode )
1128
1113
.symbol_expr ();
1129
1114
check.add (goto_programt::make_decl (r, skip->source_location ));
@@ -1137,7 +1122,7 @@ void code_contractst::add_contract_check(
1137
1122
1138
1123
// decl parameter1 ...
1139
1124
goto_functionst::function_mapt::iterator f_it =
1140
- goto_functions.function_map .find (mangled_fun );
1125
+ goto_functions.function_map .find (mangled_function );
1141
1126
PRECONDITION (f_it != goto_functions.function_map .end ());
1142
1127
1143
1128
const goto_functionst::goto_functiont &gf = f_it->second ;
@@ -1148,7 +1133,6 @@ void code_contractst::add_contract_check(
1148
1133
symbol_exprt p = new_tmp_symbol (
1149
1134
parameter_symbol.type ,
1150
1135
skip->source_location ,
1151
- wrapper_fun,
1152
1136
parameter_symbol.mode )
1153
1137
.symbol_expr ();
1154
1138
check.add (goto_programt::make_decl (p, skip->source_location ));
@@ -1160,7 +1144,7 @@ void code_contractst::add_contract_check(
1160
1144
common_replace.insert (parameter_symbol.symbol_expr (), p);
1161
1145
}
1162
1146
1163
- is_fresh_enforcet visitor (*this , log , wrapper_fun );
1147
+ is_fresh_enforcet visitor (*this , log , wrapper_function );
1164
1148
visitor.create_declarations ();
1165
1149
1166
1150
// Generate: assume(requires)
@@ -1197,7 +1181,7 @@ void code_contractst::add_contract_check(
1197
1181
auto assertion = code_assertt (ensures);
1198
1182
assertion.add_source_location () = ensures.source_location ();
1199
1183
ensures_pair = create_ensures_instruction (
1200
- assertion, ensures.source_location (), wrapper_fun, function_symbol.mode );
1184
+ assertion, ensures.source_location (), function_symbol.mode );
1201
1185
ensures_pair.first .instructions .back ().source_location .set_comment (
1202
1186
" Check ensures clause" );
1203
1187
ensures_pair.first .instructions .back ().source_location .set_property_class (
@@ -1208,7 +1192,7 @@ void code_contractst::add_contract_check(
1208
1192
check.destructive_append (ensures_pair.second );
1209
1193
}
1210
1194
1211
- // ret=mangled_fun (parameter1, ...)
1195
+ // ret=mangled_function (parameter1, ...)
1212
1196
check.add (goto_programt::make_function_call (call, skip->source_location ));
1213
1197
1214
1198
// Generate: assert(ensures)
@@ -1227,15 +1211,14 @@ void code_contractst::add_contract_check(
1227
1211
dest.destructive_insert (dest.instructions .begin (), check);
1228
1212
}
1229
1213
1230
- bool code_contractst::replace_calls (
1231
- const std::set<std::string> &funs_to_replace)
1214
+ bool code_contractst::replace_calls (const std::set<std::string> &functions)
1232
1215
{
1233
1216
bool fail = false ;
1234
- for (const auto &fun : funs_to_replace )
1217
+ for (const auto &function : functions )
1235
1218
{
1236
- if (!has_contract (fun ))
1219
+ if (!has_contract (function ))
1237
1220
{
1238
- log .error () << " Function '" << fun
1221
+ log .error () << " Function '" << function
1239
1222
<< " ' does not have a contract; "
1240
1223
" not replacing calls with contract."
1241
1224
<< messaget::eom;
@@ -1256,17 +1239,14 @@ bool code_contractst::replace_calls(
1256
1239
if (call.function ().id () != ID_symbol)
1257
1240
continue ;
1258
1241
1259
- const irep_idt &function_name =
1242
+ const irep_idt &called_function =
1260
1243
to_symbol_expr (call.function ()).get_identifier ();
1261
1244
auto found = std::find (
1262
- funs_to_replace.begin (),
1263
- funs_to_replace.end (),
1264
- id2string (function_name));
1265
- if (found == funs_to_replace.end ())
1245
+ functions.begin (), functions.end (), id2string (called_function));
1246
+ if (found == functions.end ())
1266
1247
continue ;
1267
1248
1268
- fail |= apply_function_contract (
1269
- function_name, goto_function.second .body , ins);
1249
+ fail |= apply_function_contract (goto_function.second .body , ins);
1270
1250
}
1271
1251
}
1272
1252
}
@@ -1290,52 +1270,51 @@ void code_contractst::apply_loop_contracts()
1290
1270
1291
1271
bool code_contractst::replace_calls ()
1292
1272
{
1293
- std::set<std::string> funs_to_replace ;
1273
+ std::set<std::string> functions ;
1294
1274
for (auto &goto_function : goto_functions.function_map )
1295
1275
{
1296
1276
if (has_contract (goto_function.first ))
1297
- funs_to_replace .insert (id2string (goto_function.first ));
1277
+ functions .insert (id2string (goto_function.first ));
1298
1278
}
1299
- return replace_calls (funs_to_replace );
1279
+ return replace_calls (functions );
1300
1280
}
1301
1281
1302
1282
bool code_contractst::enforce_contracts ()
1303
1283
{
1304
- std::set<std::string> funs_to_enforce ;
1284
+ std::set<std::string> functions ;
1305
1285
for (auto &goto_function : goto_functions.function_map )
1306
1286
{
1307
1287
if (has_contract (goto_function.first ))
1308
- funs_to_enforce .insert (id2string (goto_function.first ));
1288
+ functions .insert (id2string (goto_function.first ));
1309
1289
}
1310
- return enforce_contracts (funs_to_enforce );
1290
+ return enforce_contracts (functions );
1311
1291
}
1312
1292
1313
- bool code_contractst::enforce_contracts (
1314
- const std::set<std::string> &funs_to_enforce)
1293
+ bool code_contractst::enforce_contracts (const std::set<std::string> &functions)
1315
1294
{
1316
1295
bool fail = false ;
1317
- for (const auto &fun : funs_to_enforce )
1296
+ for (const auto &function : functions )
1318
1297
{
1319
- auto goto_function = goto_functions.function_map .find (fun );
1298
+ auto goto_function = goto_functions.function_map .find (function );
1320
1299
if (goto_function == goto_functions.function_map .end ())
1321
1300
{
1322
1301
fail = true ;
1323
- log .error () << " Could not find function '" << fun
1302
+ log .error () << " Could not find function '" << function
1324
1303
<< " ' in goto-program; not enforcing contracts."
1325
1304
<< messaget::eom;
1326
1305
continue ;
1327
1306
}
1328
1307
1329
- if (!has_contract (fun ))
1308
+ if (!has_contract (function ))
1330
1309
{
1331
1310
fail = true ;
1332
- log .error () << " Could not find any contracts within function '" << fun
1333
- << " '; nothing to enforce." << messaget::eom;
1311
+ log .error () << " Could not find any contracts within function '"
1312
+ << function << " '; nothing to enforce." << messaget::eom;
1334
1313
continue ;
1335
1314
}
1336
1315
1337
1316
if (!fail)
1338
- fail = enforce_contract (fun );
1317
+ fail = enforce_contract (function );
1339
1318
}
1340
1319
return fail;
1341
1320
}
0 commit comments