diff --git a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst index 4d27b2d82..a951ba6a1 100644 --- a/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst +++ b/content/courses/SPARK_for_the_MISRA_C_Developer/chapters/03_syntactic_guarantees.rst @@ -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; @@ -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 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst b/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst index 592e2a974..986745e3f 100644 --- a/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst +++ b/content/courses/intro-to-spark/chapters/04_State_Abstraction.rst @@ -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 @@ -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 + else Peek = E); function Peek return Element with Pre => not Is_Empty; function Is_Full return Boolean;