* What's wrong with this code?
@ 1999-04-20 0:00 okellogg
1999-04-20 0:00 ` dennison
1999-04-21 0:00 ` Stephen Leake
0 siblings, 2 replies; 7+ messages in thread
From: okellogg @ 1999-04-20 0:00 UTC (permalink / raw)
Dear colleagues:
I can't find what wrong with this code (see full declaration of type Alarm.)
Perhaps someone would like to comment?
Thanks alot,
Oliver Kellogg
DaimlerChrysler Aerospace
Sensor Systems, Dept. VGE15
D-89070 Ulm, Germany
e-mail: oliver.kellogg@vs.dasa.de
--
-- file: alarm_model.ads
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;
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What's wrong with this code?
1999-04-20 0:00 What's wrong with this code? okellogg
@ 1999-04-20 0:00 ` dennison
1999-04-20 0:00 ` dennison
1999-04-20 0:00 ` Matthew Heaney
1999-04-21 0:00 ` Stephen Leake
1 sibling, 2 replies; 7+ messages in thread
From: dennison @ 1999-04-20 0:00 UTC (permalink / raw)
In article <7fi85m$sb3$1@nnrp1.dejanews.com>,
okellogg@my-dejanews.com wrote:
> Dear colleagues:
>
> I can't find what wrong with this code (see full declaration of type Alarm.)
> Perhaps someone would like to comment?
> 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;
That's probably because 'Access can't be applied to a type. :-)
What is it you are trying to accomplish with Alarm'Access? Surely you don't
want a pointer into the compiler's type table for "Alarm", which is about the
only thing this could mean. Perhaps you are hoping to automaticly get a
pointer to the *object* in question when you create objects of this type?
The contexts under which 'Access may be used are listed in Annex K of the LRM
( http://www.adahome.com/rm95/rm9x-K.html ). Its prefix may be a subprogram,
object, or label.
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What's wrong with this code?
1999-04-20 0:00 ` dennison
@ 1999-04-20 0:00 ` dennison
1999-04-20 0:00 ` Matthew Heaney
1999-04-20 0:00 ` Matthew Heaney
1 sibling, 1 reply; 7+ messages in thread
From: dennison @ 1999-04-20 0:00 UTC (permalink / raw)
In article <7fiegr$43q$1@nnrp1.dejanews.com>,
dennison@telepath.com wrote:
> In article <7fi85m$sb3$1@nnrp1.dejanews.com>,
> okellogg@my-dejanews.com wrote:
> > Dear colleagues:
> >
> > I can't find what wrong with this code (see full declaration of type Alarm.)
> > Perhaps someone would like to comment?
>
> > 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;
>
> That's probably because 'Access can't be applied to a type. :-)
Drat.
Before anyone else flames me: yes, I had forgotten about the "current
instance" rule. From what I can see in the LRM its supposed to be valid
anywhere "within the declarative region of a type_declaration". So now I'm
also curious why the compiler doesn't like it.
I tried adding the following declarations:
type Alarm_List is array (1..2) of Alarm_P;
type Alarm is tagged limited
...
Al : Alarm_List := (others => Alarm'Access);
And got this error (on the "Al" field) instead:
alarm_model.ads:52:43: non-local pointer cannot point to local object
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What's wrong with this code?
1999-04-20 0:00 ` dennison
@ 1999-04-20 0:00 ` Matthew Heaney
1999-04-21 0:00 ` dennison
0 siblings, 1 reply; 7+ messages in thread
From: Matthew Heaney @ 1999-04-20 0:00 UTC (permalink / raw)
dennison@telepath.com writes:
> I tried adding the following declarations:
> type Alarm_List is array (1..2) of Alarm_P;
>
> type Alarm is tagged limited
> ...
> Al : Alarm_List := (others => Alarm'Access);
>
> And got this error (on the "Al" field) instead:
> alarm_model.ads:52:43: non-local pointer cannot point to local object
What message do you get if you use 'Unchecked_Access instead of 'Access?
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What's wrong with this code?
1999-04-20 0:00 ` Matthew Heaney
@ 1999-04-21 0:00 ` dennison
0 siblings, 0 replies; 7+ messages in thread
From: dennison @ 1999-04-21 0:00 UTC (permalink / raw)
In article <m3zp43ywi8.fsf@mheaney.ni.net>,
Matthew Heaney <matthew_heaney@acm.org> wrote:
> dennison@telepath.com writes:
>
> > I tried adding the following declarations:
> > type Alarm_List is array (1..2) of Alarm_P;
> >
> > type Alarm is tagged limited
> > ...
> > Al : Alarm_List := (others => Alarm'Access);
> >
> > And got this error (on the "Al" field) instead:
> > alarm_model.ads:52:43: non-local pointer cannot point to local object
>
> What message do you get if you use 'Unchecked_Access instead of 'Access?
Just the same old ""Access" attribute cann be applied to type". Good call.
I tried compiling the same code (the original code, not my modified
version) using my GreenHills (Intermetrics-based) compiler, and got:
d:\test\tmp\alarm_model.ads: Error: line 53 col 26 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
on the same line I got the above Gnat error. Changing the three "'Access"es to
"'Unchecked_Access" caused the GrennHills compile to succeed. But in Gnat the
same code gave me
alarm_model.ads:53:43: "Unchecked_Access" attribute cannot be applied to type
alarm_model.ads:54:41: "Unchecked_Access" attribute cannot be applied to type
alarm_model.ads:55:49: "Unchecked_Access" attribute cannot be applied to type
So it looks like one compiler (gnat) thinks the whole construct is illegal,
while the other (GreenHills) thinks the only problem is accessability levels.
--
T.E.D.
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What's wrong with this code?
1999-04-20 0:00 ` dennison
1999-04-20 0:00 ` dennison
@ 1999-04-20 0:00 ` Matthew Heaney
1 sibling, 0 replies; 7+ messages in thread
From: Matthew Heaney @ 1999-04-20 0:00 UTC (permalink / raw)
dennison@telepath.com writes:
> In article <7fi85m$sb3$1@nnrp1.dejanews.com>,
> okellogg@my-dejanews.com wrote:
> > Dear colleagues:
> >
> > I can't find what wrong with this code (see full declaration of type
> > Alarm.) Perhaps someone would like to comment?
> >
> > 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;
>
> That's probably because 'Access can't be applied to a type. :-)
This statement is incorrect.
Inside the declaration of the Alarm type, Alarm'Access denotes the
"current instance" the type.
> What is it you are trying to accomplish with Alarm'Access? Surely you
> don't want a pointer into the compiler's type table for "Alarm", which
> is about the only thing this could mean. Perhaps you are hoping to
> automaticly get a pointer to the *object* in question when you create
> objects of this type?
Yes.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: What's wrong with this code?
1999-04-20 0:00 What's wrong with this code? okellogg
1999-04-20 0:00 ` dennison
@ 1999-04-21 0:00 ` Stephen Leake
1 sibling, 0 replies; 7+ messages in thread
From: Stephen Leake @ 1999-04-21 0:00 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~1999-04-21 0:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-04-20 0:00 What's wrong with this code? okellogg
1999-04-20 0:00 ` dennison
1999-04-20 0:00 ` dennison
1999-04-20 0:00 ` Matthew Heaney
1999-04-21 0:00 ` dennison
1999-04-20 0:00 ` Matthew Heaney
1999-04-21 0:00 ` Stephen Leake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox