Skip to content

Commit d0427d4

Browse files
committed
Also prefix assigns, frees, and ensures.
Also adds the "c_" prefix to the assigns, frees, and ensures for consistency.
1 parent df3667b commit d0427d4

10 files changed

+46
-44
lines changed

src/ansi-c/ansi_c_convert_type.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@ void ansi_c_convert_typet::write(typet &type)
326326
to_code_with_contract_type(type).c_requires() = std::move(c_requires);
327327

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

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

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

337337
if(constructor || destructor)
338338
{

src/ansi-c/c_typecheck_base.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,8 +917,8 @@ void c_typecheck_baset::typecheck_declaration(
917917
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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.c_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.c_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");
@@ -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

Lines changed: 7 additions & 5 deletions
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
}))
@@ -699,7 +701,7 @@ void code_contractst::apply_function_contract(
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(
@@ -1327,7 +1329,7 @@ void code_contractst::add_contract_check(
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 1 deletion
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();

src/linking/remove_internal_symbols.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ static void get_symbols(
6767
to_code_with_contract_type(code_type);
6868

6969
find_symbols_sett new_symbols;
70-
for(const exprt &a : maybe_contract.assigns())
70+
for(const exprt &a : maybe_contract.c_assigns())
7171
find_type_and_expr_symbols(a, new_symbols);
72-
for(const exprt &e : maybe_contract.ensures())
72+
for(const exprt &e : maybe_contract.c_ensures())
7373
find_type_and_expr_symbols(e, new_symbols);
7474
for(const exprt &r : maybe_contract.c_requires())
7575
find_type_and_expr_symbols(r, new_symbols);

src/util/c_types.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,26 +390,26 @@ class code_with_contract_typet : public code_typet
390390

391391
bool has_contract() const
392392
{
393-
return !ensures().empty() || !c_requires().empty() || !assigns().empty() ||
394-
!frees().empty();
393+
return !c_ensures().empty() || !c_requires().empty() ||
394+
!c_assigns().empty() || !c_frees().empty();
395395
}
396396

397-
const exprt::operandst &assigns() const
397+
const exprt::operandst &c_assigns() const
398398
{
399399
return static_cast<const exprt &>(find(ID_C_spec_assigns)).operands();
400400
}
401401

402-
exprt::operandst &assigns()
402+
exprt::operandst &c_assigns()
403403
{
404404
return static_cast<exprt &>(add(ID_C_spec_assigns)).operands();
405405
}
406406

407-
const exprt::operandst &frees() const
407+
const exprt::operandst &c_frees() const
408408
{
409409
return static_cast<const exprt &>(find(ID_C_spec_frees)).operands();
410410
}
411411

412-
exprt::operandst &frees()
412+
exprt::operandst &c_frees()
413413
{
414414
return static_cast<exprt &>(add(ID_C_spec_frees)).operands();
415415
}
@@ -424,12 +424,12 @@ class code_with_contract_typet : public code_typet
424424
return static_cast<exprt &>(add(ID_C_spec_requires)).operands();
425425
}
426426

427-
const exprt::operandst &ensures() const
427+
const exprt::operandst &c_ensures() const
428428
{
429429
return static_cast<const exprt &>(find(ID_C_spec_ensures)).operands();
430430
}
431431

432-
exprt::operandst &ensures()
432+
exprt::operandst &c_ensures()
433433
{
434434
return static_cast<exprt &>(add(ID_C_spec_ensures)).operands();
435435
}

0 commit comments

Comments
 (0)