From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.99.96.4 with SMTP id u4mr2322935pgb.61.1498957184295; Sat, 01 Jul 2017 17:59:44 -0700 (PDT) X-Received: by 10.36.3.72 with SMTP id e69mr879225ite.1.1498957184249; Sat, 01 Jul 2017 17:59:44 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.glorb.com!188no584602itx.0!news-out.google.com!k7ni5777itk.0!nntp.google.com!188no584596itx.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Sat, 1 Jul 2017 17:59:43 -0700 (PDT) In-Reply-To: <8dd3c359-2486-46a2-9be8-b298659e5e95@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=24.6.20.197; posting-account=Qh2kiQoAAADpCLlhT_KTYoGO8dU3n4I6 NNTP-Posting-Host: 24.6.20.197 References: <7f7a804e-b90d-4a60-b759-21ae14da3835@googlegroups.com> <9d8c9cd9-f6b8-4ca3-859e-46f8c1ef019b@googlegroups.com> <8dd3c359-2486-46a2-9be8-b298659e5e95@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <0453e3ad-01e5-4654-b4fa-50b1d14c3e14@googlegroups.com> Subject: Re: Puzzled by SPARK global aspect From: Anh Vo Injection-Date: Sun, 02 Jul 2017 00:59:44 +0000 Content-Type: text/plain; charset="UTF-8" Xref: news.eternal-september.org comp.lang.ada:47257 Date: 2017-07-01T17:59:43-07:00 List-Id: On Saturday, July 1, 2017 at 5:45:28 PM UTC-7, Anh Vo wrote: > On Saturday, July 1, 2017 at 11:25:20 AM UTC-7, digitig wrote: > > On Saturday, July 1, 2017 at 4:51:22 PM UTC+1, Anh Vo wrote: > > > On Friday, June 30, 2017 at 2:29:38 PM UTC-7, digitig wrote: > > Here's a fairly minimal spec and body, then, which gives the problem I describe: > > > > ---- main.ads ---- > > package Main > > with > > SPARK_Mode => On > > is > > type Quadrant_Specification is record > > N_Klingons: Integer := 0; > > end record; > > > > subtype Klingon_Counter is Integer range 0..20; > > > > type Quadrant_Specification_Array is > > array(1..8, 1..8) > > of Quadrant_Specification; > > > > > > function N_Total_Klingons return Integer > > with > > Global => null, > > Depends => (N_Total_Klingons'Result => null), > > Pre => True; > > > > end Main; > > > > ---- Main.adb ---- > > package body Main > > with > > SPARK_Mode => On > > is > > Quadrant_Specifications: Quadrant_Specification_Array; > > > > function N_Total_Klingons return Integer > > -- with > > -- Refined_Global => Quadrant_Specifications > > is > > Total: Integer := 0; > > begin > > for X in Quadrant_Specifications'Range loop > > for Y in Quadrant_Specifications'Range(2) loop > > Total := Total + Quadrant_Specifications(X, Y).N_Klingons; > > end loop; > > end loop; > > return Total; > > end N_Total_Klingons; > > end Main; > > Both Global and Depends are under umbrella of Abstract_State at the package level. Therefore, Abstract_State must be defined below. Note that Package_State is an arbitrary name. package Main with SPARK_Mode => On, Abstract_State => Package_State is --... function N_Total_Klingons return Integer with Global => Package_State, Depends => (N_Total_Klingons'Result => Package_State); end Main; In the package body, the Refined_State must be defined to associated with the constituents Quadrant_Specifications as shown below. > package body Main > with > SPARK_Mode => On, > Refined_State => (Package_State => Quadrant_Specifications) > is > -- ... > > In addition, Global and Depends are defined below because this function depends on local global variable. > > function N_Total_Klingons return Integer > with > Global => Package_State, > Depends => (N_Total_Klingons'Result => Package_State) > is > -- ... > > In the package body Refined_State must be defined to use Quadrant_Specifications as shown below. > > package body Main > with > SPARK_Mode => On, > Refined_State => (Package_State => Quadrant_Specifications) > is > -- ... > > Moreover, Refined_Global and Refined_Depends aspects must be declared to use the array variable Quadrant_Specifications. Sorry, I cut out some good part before hitting the send button. Please ignore the previously incomplete post. Below is the complete one. Both Global and Depends are under umbrella of Abstract_State at the package level. Therefore, Abstract_State must be defined below. Note that Package_State is an arbitrary name. package Main with SPARK_Mode => On, Abstract_State => Package_State is --... function N_Total_Klingons return Integer with Global => Package_State, Depends => (N_Total_Klingons'Result => Package_State); end Main; In the package body, the Refined_State must be defined to associated with the constituents Quadrant_Specifications as shown below. package body Main with SPARK_Mode => On, Refined_State => (Package_State => Quadrant_Specifications) is -- ... In addition, Global and Depends are defined below because this function depends on local global variable. function N_Total_Klingons return Integer with Global => Package_State, Depends => (N_Total_Klingons'Result => Package_State) is -- ...