--  EH7: `'Old` applies to a whole call of a function over an enclave's cells
package Counters
  with Annotate => (Verada, Enclave)
is
   type Counter is limited private
     with Default_Initial_Condition => Value (Counter) = 0;
   function Model (C : Counter) return Natural with Ghost;
   function Value (C : Counter) return Natural
     with Post => Value'Result = Model (C);
   procedure Bump (C : in out Counter)
     with Pre => Value (C) < 1000, Post => Value (C) = Value (C'Old) + 1;
private
   type Cell;
   type Cell_Ptr is access Cell;
   type Cell is record
      Count : Natural;
   end record;
   type Counter is limited record
      Box : Cell_Ptr;
   end record
     with Type_Invariant => Counter.Box = null or else Counter.Box.Count <= 1000;
   function Model (C : Counter) return Natural is (if C.Box = null then 0 else C.Box.Count);
   function Value (C : Counter) return Natural is (if C.Box = null then 0 else C.Box.Count);
end Counters;
