Skip to content

Commit ba47c86

Browse files
authored
Merge pull request #7698 from diffblue/20230503-rename-requires
Replace requires with c_requires
2 parents c64e9f7 + 3a6cef0 commit ba47c86

11 files changed

+77
-75
lines changed

src/ansi-c/ansi_c_convert_type.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -250,29 +250,29 @@ void ansi_c_convert_typet::read_rec(const typet &type)
250250
{
251251
const exprt &as_expr =
252252
static_cast<const exprt &>(static_cast<const irept &>(type));
253-
requires.push_back(to_unary_expr(as_expr).op());
253+
c_requires.push_back(to_unary_expr(as_expr).op());
254254
}
255255
else if(type.id() == ID_C_spec_assigns)
256256
{
257257
const exprt &as_expr =
258258
static_cast<const exprt &>(static_cast<const irept &>(type));
259259

260260
for(const exprt &target : to_unary_expr(as_expr).op().operands())
261-
assigns.push_back(target);
261+
c_assigns.push_back(target);
262262
}
263263
else if(type.id() == ID_C_spec_frees)
264264
{
265265
const exprt &as_expr =
266266
static_cast<const exprt &>(static_cast<const irept &>(type));
267267

268268
for(const exprt &target : to_unary_expr(as_expr).op().operands())
269-
frees.push_back(target);
269+
c_frees.push_back(target);
270270
}
271271
else if(type.id() == ID_C_spec_ensures)
272272
{
273273
const exprt &as_expr =
274274
static_cast<const exprt &>(static_cast<const irept &>(type));
275-
ensures.push_back(to_unary_expr(as_expr).op());
275+
c_ensures.push_back(to_unary_expr(as_expr).op());
276276
}
277277
else
278278
other.push_back(type);
@@ -322,17 +322,17 @@ void ansi_c_convert_typet::write(typet &type)
322322
type.swap(other.front());
323323

324324
// the contract expressions are meant for function types only
325-
if(!requires.empty())
326-
to_code_with_contract_type(type).requires() = std::move(requires);
325+
if(!c_requires.empty())
326+
to_code_with_contract_type(type).c_requires() = std::move(c_requires);
327327

328-
if(!assigns.empty())
329-
to_code_with_contract_type(type).assigns() = std::move(assigns);
328+
if(!c_assigns.empty())
329+
to_code_with_contract_type(type).c_assigns() = std::move(c_assigns);
330330

331-
if(!frees.empty())
332-
to_code_with_contract_type(type).frees() = std::move(frees);
331+
if(!c_frees.empty())
332+
to_code_with_contract_type(type).c_frees() = std::move(c_frees);
333333

334-
if(!ensures.empty())
335-
to_code_with_contract_type(type).ensures() = std::move(ensures);
334+
if(!c_ensures.empty())
335+
to_code_with_contract_type(type).c_ensures() = std::move(c_ensures);
336336

337337
if(constructor || destructor)
338338
{

src/ansi-c/ansi_c_convert_type.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class ansi_c_convert_typet
4848
bool constructor, destructor;
4949

5050
// contracts
51-
exprt::operandst assigns, frees, ensures, requires;
51+
exprt::operandst c_assigns, c_frees, c_ensures, c_requires;
5252

5353
// storage spec
5454
c_storage_spect c_storage_spec;

src/ansi-c/c_typecheck_base.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -905,20 +905,20 @@ void c_typecheck_baset::typecheck_declaration(
905905
parameter_identifier, p.type());
906906
}
907907

908-
for(auto &requires : code_type.requires())
908+
for(auto &c_requires : code_type.c_requires())
909909
{
910-
typecheck_expr(requires);
911-
implicit_typecast_bool(requires);
910+
typecheck_expr(c_requires);
911+
implicit_typecast_bool(c_requires);
912912
std::string clause_type = "preconditions";
913-
check_history_expr_return_value(requires, clause_type);
914-
check_was_freed(requires, clause_type);
915-
lambda_exprt lambda{temporary_parameter_symbols, requires};
916-
lambda.add_source_location() = requires.source_location();
917-
requires.swap(lambda);
913+
check_history_expr_return_value(c_requires, clause_type);
914+
check_was_freed(c_requires, clause_type);
915+
lambda_exprt lambda{temporary_parameter_symbols, c_requires};
916+
lambda.add_source_location() = c_requires.source_location();
917+
c_requires.swap(lambda);
918918
}
919919

920-
typecheck_spec_assigns(code_type.assigns());
921-
for(auto &assigns : code_type.assigns())
920+
typecheck_spec_assigns(code_type.c_assigns());
921+
for(auto &assigns : code_type.c_assigns())
922922
{
923923
std::string clause_type = "assigns clauses";
924924
check_history_expr_return_value(assigns, clause_type);
@@ -927,15 +927,15 @@ void c_typecheck_baset::typecheck_declaration(
927927
assigns.swap(lambda);
928928
}
929929

930-
typecheck_spec_frees(code_type.frees());
931-
for(auto &frees : code_type.frees())
930+
typecheck_spec_frees(code_type.c_frees());
931+
for(auto &frees : code_type.c_frees())
932932
{
933933
lambda_exprt lambda{temporary_parameter_symbols, frees};
934934
lambda.add_source_location() = frees.source_location();
935935
frees.swap(lambda);
936936
}
937937

938-
for(auto &ensures : code_type.ensures())
938+
for(auto &ensures : code_type.c_ensures())
939939
{
940940
typecheck_expr(ensures);
941941
implicit_typecast_bool(ensures);

src/cprover/instrument_contracts.cpp

+13-13
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,11 @@ void instrument_contract_checks(
286286
goto_programt add_at_beginning;
287287

288288
// precondition?
289-
if(!contract.requires().empty())
289+
if(!contract.c_requires().empty())
290290
{
291291
// stick these in as assumptions, preserving the ordering
292292
goto_programt dest;
293-
for(auto &assumption : contract.requires())
293+
for(auto &assumption : contract.c_requires())
294294
{
295295
exprt assumption_instance = instantiate_contract_lambda(assumption);
296296
auto fixed_assumption = add_function(f.first, assumption_instance);
@@ -304,19 +304,19 @@ void instrument_contract_checks(
304304
const auto old_prefix = "old::" + id2string(f.first);
305305

306306
// postcondition?
307-
if(!contract.ensures().empty())
307+
if(!contract.c_ensures().empty())
308308
{
309309
// Stick the postconditions in as assertions at the end
310310
auto last = body.instructions.end();
311311
if(std::prev(last)->is_end_function())
312312
last = std::prev(last);
313313

314-
for(auto &assertion : contract.ensures())
314+
for(auto &assertion : contract.c_ensures())
315315
{
316316
exprt assertion_instance = instantiate_contract_lambda(assertion);
317317

318318
std::string comment = "postcondition";
319-
if(contract.ensures().size() >= 2)
319+
if(contract.c_ensures().size() >= 2)
320320
comment += " " + expr2text(assertion_instance, ns);
321321

322322
auto location = assertion.source_location();
@@ -338,8 +338,8 @@ void instrument_contract_checks(
338338

339339
// do 'old' in the body
340340
if(
341-
!contract.assigns().empty() || !contract.requires().empty() ||
342-
!contract.ensures().empty())
341+
!contract.c_assigns().empty() || !contract.c_requires().empty() ||
342+
!contract.c_ensures().empty())
343343
{
344344
for(auto &instruction : body.instructions)
345345
instruction.transform(
@@ -359,8 +359,8 @@ void instrument_contract_checks(
359359

360360
// assigns?
361361
if(
362-
!contract.assigns().empty() || !contract.requires().empty() ||
363-
!contract.ensures().empty())
362+
!contract.c_assigns().empty() || !contract.c_requires().empty() ||
363+
!contract.c_ensures().empty())
364364
{
365365
for(auto it = body.instructions.begin(); it != body.instructions.end();
366366
it++)
@@ -378,7 +378,7 @@ void instrument_contract_checks(
378378

379379
// maybe not ok
380380
auto assigns_assertion =
381-
make_assigns_assertion(f.first, contract.assigns(), lhs);
381+
make_assigns_assertion(f.first, contract.c_assigns(), lhs);
382382
auto location = it->source_location();
383383
location.set_property_class("assigns");
384384
location.set_comment("assigns clause");
@@ -449,7 +449,7 @@ void replace_function_calls_by_contracts(
449449
goto_programt dest;
450450

451451
// assert the preconditions
452-
for(auto &precondition : contract.requires())
452+
for(auto &precondition : contract.c_requires())
453453
{
454454
auto instantiated_precondition =
455455
instantiate_contract_lambda(precondition);
@@ -468,7 +468,7 @@ void replace_function_calls_by_contracts(
468468
}
469469

470470
// havoc the 'assigned' variables
471-
for(auto &assigns_clause_lambda : contract.assigns())
471+
for(auto &assigns_clause_lambda : contract.c_assigns())
472472
{
473473
auto location = it->source_location();
474474

@@ -519,7 +519,7 @@ void replace_function_calls_by_contracts(
519519
}
520520

521521
// assume the postconditions
522-
for(auto &postcondition : contract.ensures())
522+
for(auto &postcondition : contract.c_ensures())
523523
{
524524
auto &location = it->source_location();
525525

src/goto-instrument/contracts/contracts.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ void code_contractst::apply_function_contract(
629629
// If the function does return a value, but the return value is
630630
// disregarded, check if the postcondition includes the return value.
631631
if(std::any_of(
632-
type.ensures().begin(), type.ensures().end(), [](const exprt &e) {
632+
type.c_ensures().begin(),
633+
type.c_ensures().end(),
634+
[](const exprt &e) {
633635
return has_symbol_expr(
634636
to_lambda_expr(e).where(), CPROVER_PREFIX "return_value", true);
635637
}))
@@ -674,7 +676,7 @@ void code_contractst::apply_function_contract(
674676
is_fresh.add_memory_map_decl(new_program);
675677

676678
// Generate: assert(requires)
677-
for(const auto &clause : type.requires())
679+
for(const auto &clause : type.c_requires())
678680
{
679681
auto instantiated_clause =
680682
to_lambda_expr(clause).application(instantiation_values);
@@ -690,16 +692,16 @@ void code_contractst::apply_function_contract(
690692
converter,
691693
instantiated_clause,
692694
mode,
693-
[&is_fresh](goto_programt &requires) {
694-
is_fresh.update_requires(requires);
695+
[&is_fresh](goto_programt &c_requires) {
696+
is_fresh.update_requires(c_requires);
695697
},
696698
new_program,
697699
_location);
698700
}
699701

700702
// Generate all the instructions required to initialize history variables
701703
exprt::operandst instantiated_ensures_clauses;
702-
for(auto clause : type.ensures())
704+
for(auto clause : type.c_ensures())
703705
{
704706
auto instantiated_clause =
705707
to_lambda_expr(clause).application(instantiation_values);
@@ -712,7 +714,7 @@ void code_contractst::apply_function_contract(
712714
// ASSIGNS clause should not refer to any quantified variables,
713715
// and only refer to the common symbols to be replaced.
714716
exprt::operandst targets;
715-
for(auto &target : type.assigns())
717+
for(auto &target : type.c_assigns())
716718
targets.push_back(to_lambda_expr(target).application(instantiation_values));
717719

718720
// Create a sequence of non-deterministic assignments ...
@@ -1138,7 +1140,7 @@ void code_contractst::check_frame_conditions_function(const irep_idt &function)
11381140
instantiation_values.push_back(
11391141
ns.lookup(param.get_identifier()).symbol_expr());
11401142
}
1141-
for(auto &target : get_contract(function, ns).assigns())
1143+
for(auto &target : get_contract(function, ns).c_assigns())
11421144
{
11431145
goto_programt payload;
11441146
instrument_spec_assigns.track_spec_target(
@@ -1299,7 +1301,7 @@ void code_contractst::add_contract_check(
12991301
visitor.add_memory_map_decl(check);
13001302

13011303
// Generate: assume(requires)
1302-
for(const auto &clause : code_type.requires())
1304+
for(const auto &clause : code_type.c_requires())
13031305
{
13041306
auto instantiated_clause =
13051307
to_lambda_expr(clause).application(instantiation_values);
@@ -1318,16 +1320,16 @@ void code_contractst::add_contract_check(
13181320
converter,
13191321
instantiated_clause,
13201322
function_symbol.mode,
1321-
[&visitor](goto_programt &requires) {
1322-
visitor.update_requires(requires);
1323+
[&visitor](goto_programt &c_requires) {
1324+
visitor.update_requires(c_requires);
13231325
},
13241326
check,
13251327
_location);
13261328
}
13271329

13281330
// Generate all the instructions required to initialize history variables
13291331
exprt::operandst instantiated_ensures_clauses;
1330-
for(auto clause : code_type.ensures())
1332+
for(auto clause : code_type.c_ensures())
13311333
{
13321334
auto instantiated_clause =
13331335
to_lambda_expr(clause).application(instantiation_values);

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_functions.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ void dfcc_contract_functionst::gen_spec_assigns_function()
150150

151151
exprt::operandst targets;
152152

153-
for(const exprt &target : code_with_contract.assigns())
153+
for(const exprt &target : code_with_contract.c_assigns())
154154
{
155155
auto new_target = to_lambda_expr(target).application(lambda_parameters);
156156
new_target.add_source_location() = target.source_location();
@@ -201,7 +201,7 @@ void dfcc_contract_functionst::gen_spec_frees_function()
201201

202202
exprt::operandst targets;
203203

204-
for(const exprt &target : code_with_contract.frees())
204+
for(const exprt &target : code_with_contract.c_frees())
205205
{
206206
auto new_target = to_lambda_expr(target).application(lambda_parameters);
207207
new_target.add_source_location() = target.source_location();

src/goto-instrument/contracts/dynamic-frames/dfcc_contract_functions.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ class conditional_target_group_exprt;
4242
/// ```c
4343
/// // Populates write_set_to_fill with targets of the assigns clause
4444
/// // checks its own body against write_set_to_check:
45-
/// void contract_id::assigns(
45+
/// void contract_id::c_assigns(
4646
/// function-params,
4747
/// write_set_to_fill,
4848
/// write_set_to_check);
4949
/// ```
5050
///
5151
/// ```c
5252
/// // Havocs the targets specified in the assigns clause, assuming
53-
/// // write_set_to_havoc is a snapshot created using contract_id::assigns
54-
/// void contract_id::assigns::havoc(write_set_to_havoc);
53+
/// // write_set_to_havoc is a snapshot created using contract_id::c_assigns
54+
/// void contract_id::c_assigns::havoc(write_set_to_havoc);
5555
/// ```
5656
///
5757
/// ```c
@@ -89,10 +89,10 @@ class dfcc_contract_functionst
8989
void instrument_without_loop_contracts_check_no_pointer_contracts(
9090
const irep_idt &spec_function_id);
9191

92-
/// Returns the contract::assigns function symbol
92+
/// Returns the contract::c_assigns function symbol
9393
const symbolt &get_spec_assigns_function_symbol() const;
9494

95-
/// Returns the contract::assigns::havoc function symbol
95+
/// Returns the contract::c_assigns::havoc function symbol
9696
const symbolt &get_spec_assigns_havoc_function_symbol() const;
9797

9898
/// Returns the contract::frees function symbol
@@ -110,10 +110,10 @@ class dfcc_contract_functionst
110110
/// The code_with_contract_type carrying the contract clauses
111111
const code_with_contract_typet &code_with_contract;
112112

113-
/// Identifier of the contract::assigns function
113+
/// Identifier of the contract::c_assigns function
114114
const irep_idt spec_assigns_function_id;
115115

116-
/// Identifier of the contract::assigns::havoc function
116+
/// Identifier of the contract::c_assigns::havoc function
117117
const irep_idt spec_assigns_havoc_function_id;
118118

119119
/// Identifier of the contract::frees function

src/goto-instrument/contracts/dynamic-frames/dfcc_wrapper_program.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ void dfcc_wrapper_programt::encode_requires_clauses()
577577
goto_programt requires_program;
578578

579579
// translate each requires clause
580-
for(const auto &r : contract_code_type.requires())
580+
for(const auto &r : contract_code_type.c_requires())
581581
{
582582
exprt requires = to_lambda_expr(r).application(contract_lambda_parameters);
583583
requires.add_source_location() = r.source_location();
@@ -621,7 +621,7 @@ void dfcc_wrapper_programt::encode_ensures_clauses()
621621
goto_programt ensures_program;
622622

623623
// translate each ensures clause
624-
for(const auto &e : contract_code_type.ensures())
624+
for(const auto &e : contract_code_type.c_ensures())
625625
{
626626
exprt ensures = to_lambda_expr(e)
627627
.application(contract_lambda_parameters)

src/goto-instrument/contracts/dynamic-frames/dfcc_wrapper_program.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class dfcc_wrapper_programt
224224
/// (populated by calling functions provided in contract_functions)
225225
/// - Adds declaration of write set and pointer to write set to \ref preamble
226226
/// - Adds initialisation function call in \ref write_set_checks
227-
/// - Adds contract::assigns and contract::frees function call
227+
/// - Adds contract::c_assigns and contract::frees function call
228228
/// in \ref write_set_checks
229229
/// - Adds release function call in \ref postamble
230230
void encode_contract_write_set();

0 commit comments

Comments
 (0)