@@ -56,23 +56,56 @@ class code_contractst
5656
5757 void code_contracts (goto_functionst::goto_functiont &goto_function);
5858
59+ // / Applies (but does not check) a function contract.
60+ // / This will assume that the contract holds, and then use that assumption
61+ // / to remove the function call located at target.
62+ // / \param goto_program The goto program containing the target callsite.
63+ // / \param value_sets A value_setst object containing information about
64+ // / aliasing in the goto program being analyzed
65+ // / \param target An iterator pointing to the function call to be removed.
5966 void apply_contract (
6067 goto_programt &goto_program,
6168 value_setst &value_sets,
6269 goto_programt::targett target);
6370
71+ // / Applies (but does not check) a loop invariant.
72+ // / This will assume that the loop invariant is indeed an invariant, and then
73+ // / use that assumption to remove the loop.
74+ // / \param goto_function The goto function containing the target loop.
75+ // / \param value_sets A value_setst object containing information about
76+ // / aliasing in the goto program being analyzed
77+ // / \param loop_head An iterator pointing to the first instruction of the
78+ // / target loop.
79+ // / \param loop The loop being removed.
6480 void apply_invariant (
6581 goto_functionst::goto_functiont &goto_function,
6682 value_setst &value_sets,
6783 const goto_programt::targett loop_head,
6884 const loopt &loop);
6985
86+ // / Checks (but does not apply) a function contract.
87+ // / This will build a code snippet to be inserted at dest which will check
88+ // that the function contract is satisfied.
89+ // / \param function_id The id of the function being checked.
90+ // / \param goto_function The goto_function object for the function
91+ // / being checked.
92+ // / \param dest An iterator pointing to the place to insert checking code.
7093 void check_contract (
7194 const irep_idt &function_id,
7295 goto_functionst::goto_functiont &goto_function,
7396 goto_programt &dest);
7497
75- void check_apply_invariant (
98+ // / Checks and applies a loop invariant
99+ // / This will replace the loop with a code snippet (based on the loop) which
100+ // / will check that the loop invariant is indeed ian invariant, and then
101+ // / use that invariant in what follows.
102+ // / \param goto_function The goto function containing the target loop.
103+ // / \param value_sets A value_setst object containing information about
104+ // / aliasing in the goto program being analyzed
105+ // / \param loop_head An iterator pointing to the first instruction of the
106+ // / target loop.
107+ // / \param loop The loop being removed.
108+ void check_apply_invariant (
76109 goto_functionst::goto_functiont &goto_function,
77110 value_setst &value_sets,
78111 const goto_programt::targett loop_head,
@@ -298,7 +331,7 @@ void code_contractst::apply_invariant(
298331 inst->make_skip ();
299332 }
300333
301- // Now havoc at the loop head. Use insert_swap to
334+ // Now havoc at the loop head. Use insert_before_swap to
302335 // preserve jumps to loop head.
303336 goto_function.body .insert_before_swap (loop_head, havoc_code);
304337
@@ -324,13 +357,15 @@ void code_contractst::check_contract(
324357 return ;
325358 }
326359
327- // build:
328- // if(nondet)
360+ // We build the following checking code :
361+ // if(nondet) goto end
329362 // decl ret
330363 // decl parameter1 ...
331364 // assume(requires) [optional]
332365 // ret = function(parameter1, ...)
333366 // assert(ensures)
367+ // end:
368+ // skip
334369
335370 // build skip so that if(nondet) can refer to it
336371 goto_programt tmp_skip;
@@ -482,7 +517,7 @@ void code_contractst::check_apply_invariant(
482517 a->source_location .set_comment (" Loop invariant violated before entry" );
483518 }
484519
485- // havoc variables being written to
520+ // havoc variables that can be modified by the loop
486521 build_havoc_code (loop_head, modifies, havoc_code);
487522
488523 // assume the invariant
@@ -517,7 +552,7 @@ void code_contractst::check_apply_invariant(
517552 loop_end->guard .make_not ();
518553 }
519554
520- // Now havoc at the loop head. Use insert_swap to
555+ // Now havoc at the loop head. Use insert_before_swap to
521556 // preserve jumps to loop head.
522557 goto_function.body .insert_before_swap (loop_head, havoc_code);
523558}
0 commit comments