comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <Stephen.Leake@gsfc.nasa.gov>
Subject: Re: What's wrong with this code?
Date: 1999/04/21
Date: 1999-04-21T00:00:00+00:00	[thread overview]
Message-ID: <uso9tapl7.fsf@gsfc.nasa.gov> (raw)
In-Reply-To: 7fi85m$sb3$1@nnrp1.dejanews.com

okellogg@my-dejanews.com writes:

> package Alarm_Model is
> 
>     type Alarm is tagged limited private;
>     type Alarm_P is access all Alarm'Class;
> 
>     procedure Norm (This : access Alarm'Class);
> 
> private
> 
>     type Alarm_State_Et is
>        (Snafu, Data, Proposal);
> 
>     type Alarm_State (My_Alarm : access Alarm) is
>        abstract tagged limited null record;
>     type Alarm_State_P is access all Alarm_State'Class;
> 
>     type Alarm_State_Pool_At is
>        array (Alarm_State_Et) of Alarm_State_P;
> 
>     procedure Enter (This : access Alarm_State);
> 
>     type Snafu_State is new Alarm_State with null record;
>     type Snafu_State_P is access all Snafu_State'Class;
> 
>     procedure Request_Data (This : access Snafu_State);
> 
>     type Data_State is new Alarm_State with null record;
>     type Data_State_P is access all Data_State'Class;
> 
>     type Proposal_State is new Alarm_State with null record;
>     type Proposal_State_P is access all Proposal_State'Class;
> 
>     protected type Alarm_Semaphore (My_Alarm : access Alarm) is
>         function Get return Alarm_State_P;
>         procedure Set (New_State : in Alarm_State_Et);
>     private
>         Current_State : Alarm_State_Et := Snafu;
>         ----------------------------- This is the workaround used
>         -- Alarm_State_Pool : Alarm_State_Pool_At :=
>         --    (Snafu => new Snafu_State (My_Alarm),
>         --     Data => new Data_State (My_Alarm),
>         --     Proposal => new Proposal_State (My_Alarm));
>     end Alarm_Semaphore;
> 
>     type Alarm is tagged limited
>         record
>             -- This compiles alright:
>             Semaphore : Alarm_Semaphore (Alarm'Access);
> 
>             -- But here, GNAT 3.11p says:
>             --  "Access" attribute cannot be applied to type
>             Alarm_State_Pool : Alarm_State_Pool_At :=
>                (Snafu => new Snafu_State (Alarm'Access),
>                 Data => new Data_State (Alarm'Access),
>                 Proposal => new Proposal_State (Alarm'Access));
> 
>         end record;
> 
> end Alarm_Model;

ObjectAda gives the error message (for Alarm_State_Pool):

alarm_model.ads: Error: line 56 col 38 LRM:3.10.2(28), The
accessibility level of the prefix to 'ACCESS shall not be statically
deeper than that of the expected type of the allocator, Continuing

(The LRM reference says the same thing :)

Apparently using 'Access inside an allocator introduces an access
layer? I don't see why it should in this case. In a function call, it
might be a problem. And everything is at library level anyway. 


GNAT 3.11p gives the error:

alarm_model.ads:56:55: "Access" attribute cannot be applied to type

As others have pointed out, and as Semaphore demonstrates, it can too.
So this is clearly a bad error message - send it in to ACT.

I suspect both compilers are confused, not having encountered this
construct before.

As a work around, you could make Alarm a Controlled type, and create
the Alarm_State_Pool objects in Initialize.

-- Stephe




      parent reply	other threads:[~1999-04-21  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-04-20  0:00 What's wrong with this code? okellogg
1999-04-20  0:00 ` dennison
1999-04-20  0:00   ` Matthew Heaney
1999-04-20  0:00   ` dennison
1999-04-20  0:00     ` Matthew Heaney
1999-04-21  0:00       ` dennison
1999-04-21  0:00 ` Stephen Leake [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox