Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,7 @@ blocks of statements have explicit :ada:`begin` and :ada:`end` markers, which
prevents mistakes that are possible in C. The SPARK (also Ada) version of the
above C code is as follows:

.. code:: ada no_button gnat=12.2.0-1 gnatprove=12.1.0-1 project=Courses.SPARK_For_The_MISRA_C_Dev.Syntactic_Guarantees.Semicolon
:class: ada-compile, ada-prove-flow-report-all
.. code:: ada prove_flow_report_all_button compile_button project=Courses.SPARK_For_The_MISRA_C_Dev.Syntactic_Guarantees.Semicolon

function Func return Integer;

Expand All @@ -254,11 +253,17 @@ above C code is as follows:
return 1;
end if;
while True loop
pragma Loop_Variant (Decreases => 1);
return 0;
end loop;
return 0;
end Func;

Note that the :ada:`Loop_Variant` pragma allows GNATprove to prove that the
loop terminates, as it requires its value to decrease between iterations,
which rules out a second iteration for the constant value :ada:`1`.


Avoiding Complex Switch Statements
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,8 @@ Example #6

Let's consider yet another version of our abstract stack unit.

.. code:: ada no_button gnat=12.2.0-1 gnatprove=12.1.0-1 project=Courses.Intro_To_Spark.State_Abstraction.Example_06
:class: ada-compile, ada-prove-flow, ada-expect-compile-error, ada-expect-prove-error
.. code:: ada compile_button prove_flow_button project=Courses.Intro_To_Spark.State_Abstraction.Example_06
:class: ada-expect-compile-error, ada-expect-prove-error

package Stack with
Abstract_State => The_Stack
Expand All @@ -1045,7 +1045,9 @@ Let's consider yet another version of our abstract stack unit.
procedure Push (E : Element) with
Post =>
not Is_Empty and
(if Is_Full'Old then The_Stack = The_Stack'Old else Peek = E);
(if Is_Full'Old then
Element_Array'(The_Stack) = Element_Array'(The_Stack)'Old
Comment thread
gusthoff marked this conversation as resolved.
Resolved
else Peek = E);

function Peek return Element with Pre => not Is_Empty;
function Is_Full return Boolean;
Expand Down
Loading