comp.lang.ada
 help / color / mirror / Atom feed
* Problem with protected type
@ 2003-11-25 15:15 Ekkehard Morgenstern
  2003-11-25 15:43 ` Ekkehard Morgenstern
  2003-11-25 18:03 ` Jeffrey Carter
  0 siblings, 2 replies; 11+ messages in thread
From: Ekkehard Morgenstern @ 2003-11-25 15:15 UTC (permalink / raw)



Hi guys,

I'm an Ada newbie, and I have a problem with a protected type definition
(Ada 95, GNAT 3.15p):

 type CoreEvent is limited private;

 protected BaseEvent is
  entry Wait;
  procedure Signal;
  procedure ManualMode;
  procedure AutoMode;
  procedure Reset;
  function IsSignaled return Boolean;
 private
  EventObject : CoreEvent;
  ManualReset : Boolean := FALSE;
 end BaseEvent;

The compiler reports "premature usage of incomplete type derived from
"BaseEvent"".

What's wrong here?

Can I use a barrier expression that is doing a function call?

The barrier expression in this case would be "IsSignaled( EventObject )",
which is a function defined as "function IsSignaled( Evt : in CoreEvent )
return Boolean".








^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 15:15 Problem with protected type Ekkehard Morgenstern
@ 2003-11-25 15:43 ` Ekkehard Morgenstern
  2003-11-25 16:06   ` Robert I. Eachus
  2003-11-25 16:45   ` Ludovic Brenta
  2003-11-25 18:03 ` Jeffrey Carter
  1 sibling, 2 replies; 11+ messages in thread
From: Ekkehard Morgenstern @ 2003-11-25 15:43 UTC (permalink / raw)



I solved the problem by using a class-wide type access and an init
procedure:

 type CoreEvent is tagged private;
 type CoreEvent_Ptr is access all CoreEvent'Class;

 function CreateCoreEvent return CoreEvent_Ptr;

 protected BaseEvent is
  procedure Init;
  entry Wait;
  procedure Signal;
  procedure ManualMode;
  procedure AutoMode;
  procedure Reset;
  function IsSignaled return Boolean;
 private
  EventObject : CoreEvent_Ptr := null;
  ManualReset : Boolean      := FALSE;
 end BaseEvent;

But why is this necessary?

And can I create inheritable protected classes?

regards,
Ekkehard.






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 15:43 ` Ekkehard Morgenstern
@ 2003-11-25 16:06   ` Robert I. Eachus
  2003-11-25 18:39     ` Ekkehard Morgenstern
  2003-11-25 16:45   ` Ludovic Brenta
  1 sibling, 1 reply; 11+ messages in thread
From: Robert I. Eachus @ 2003-11-25 16:06 UTC (permalink / raw)


Ekkehard Morgenstern wrote:

> But why is this necessary?

It isn't in general.  What you are missing is a complete definition of 
CoreEvent before you try to create an object of the type:

  type CoreEvent is limited private;

  protected BaseEvent is
   entry Wait;
   procedure Signal;
   procedure ManualMode;
   procedure AutoMode;
   procedure Reset;
   function IsSignaled return Boolean;
  private
   EventObject : CoreEvent;  <----
   ManualReset : Boolean := FALSE;
  end BaseEvent;

Replacing EventObject by a pointer to CoreEvent eliminates the need for 
"knowing" the size of CoreEvent.  Other fixes would be to complete the 
declaration of CoreEvent before the declaration of BaseEvent, or to make 
  BaseEvent a protected type, then not create any objects of the type in 
the public part of the package specification.  (You may want to create 
such objects in child packages.)

I would think that the intent is to have several objects of type 
BaseEvent, so the latter would be the best fix.

This principle of linear elaboration order is followed thoughout Ada. 
There are cases where it is a pain, and other cases where it has 
benefits.  But there needs to be one rule for such things, and this rule 
was chosen as the simplest for users to understand.

Incidently, there is no language rule against the style of identifier 
you are using, but Ada compilers and editors do a better job of 
supporting Base_Event instead of BaseEvent.  For example the emacs 
ada-mode I use automatically converts BaseEvent to Baseevent unless I go 
to extra effort.
-- 
                                           Robert I. Eachus

100% Ada, no bugs--the only way to create software.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 15:43 ` Ekkehard Morgenstern
  2003-11-25 16:06   ` Robert I. Eachus
@ 2003-11-25 16:45   ` Ludovic Brenta
  2003-11-25 18:45     ` Ekkehard Morgenstern
  2003-11-25 20:09     ` Randy Brukardt
  1 sibling, 2 replies; 11+ messages in thread
From: Ludovic Brenta @ 2003-11-25 16:45 UTC (permalink / raw)


"Ekkehard Morgenstern" <ekkehard.morgenstern@onlinehome.de> writes:

> I solved the problem by using a class-wide type access and an init
> procedure:
> 
>  type CoreEvent is tagged private;
>  type CoreEvent_Ptr is access all CoreEvent'Class;
> 
>  function CreateCoreEvent return CoreEvent_Ptr;
> 
>  protected BaseEvent is
>   procedure Init;
>   entry Wait;
>   procedure Signal;
>   procedure ManualMode;
>   procedure AutoMode;
>   procedure Reset;
>   function IsSignaled return Boolean;
>  private
>   EventObject : CoreEvent_Ptr := null;
>   ManualReset : Boolean      := FALSE;
>  end BaseEvent;
> 
> But why is this necessary?

Because, I think, CoreEvent is not completely defined at the point
where you use it inside BaseEvent.  Therefore the compiler does not
know how much memory to allocate for a BaseEvent.

By contrast, the access type is completely defined, so you can use it
in the BaseEvent.

> And can I create inheritable protected classes?

No.  This has been proposed as an extension to the language [1] back
in 2000, but the discussions concluded that there was no demand for
this feature from paying customers, so therefore no compiler vendors
were going to implement it.

[1] http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00250.TXT?rev=HEAD

-- 
Ludovic Brenta.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 15:15 Problem with protected type Ekkehard Morgenstern
  2003-11-25 15:43 ` Ekkehard Morgenstern
@ 2003-11-25 18:03 ` Jeffrey Carter
  2003-11-25 18:31   ` Ekkehard Morgenstern
  1 sibling, 1 reply; 11+ messages in thread
From: Jeffrey Carter @ 2003-11-25 18:03 UTC (permalink / raw)


Ekkehard Morgenstern wrote:

>  type CoreEvent is limited private;
> 
>  protected BaseEvent is
>   entry Wait;
>   procedure Signal;
>   procedure ManualMode;
>   procedure AutoMode;
>   procedure Reset;
>   function IsSignaled return Boolean;
>  private
>   EventObject : CoreEvent;
>   ManualReset : Boolean := FALSE;
>  end BaseEvent;
> 
> The compiler reports "premature usage of incomplete type derived from
> "BaseEvent"".

That's not a great error message.

I suspect that your real problem is that you omitted the word "type" 
between "protected" and "Baseevent". "protected Baseevent" declares a 
single protected object; "protected type Baseevent" declares a type 
which may then be used to declare many objects of the type.

A type declaration may include a reference to an incomplete type, such 
as Coreevent. An object declaration may not, since it has to allocate 
space for the components, and the compiler does not yet know how much 
space needs to be allocated for Coreevent.

> Can I use a barrier expression that is doing a function call?

Yes, a barrier can be any boolean expression. If you limit yourself to 
the Ravenscar profile, however, a barrier must be a Boolean component of 
the object.

BTW, I find the Ada way, Base_Event, much easier to read than Baseevent, 
which is what my reformatter does with your kind of identifiers.

-- 
Jeff Carter
"Sheriff murdered, crops burned, stores looted,
people stampeded, and cattle raped."
Blazing Saddles
35




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 18:03 ` Jeffrey Carter
@ 2003-11-25 18:31   ` Ekkehard Morgenstern
  2003-11-26  0:42     ` Jeffrey Carter
  0 siblings, 1 reply; 11+ messages in thread
From: Ekkehard Morgenstern @ 2003-11-25 18:31 UTC (permalink / raw)



"Jeffrey Carter" <spam@spam.com> schrieb im Newsbeitrag
news:uPMwb.14566$n56.8738@newsread1.news.pas.earthlink.net...
> > The compiler reports "premature usage of incomplete type derived from
> > "BaseEvent"".
>
> That's not a great error message.

That's true, because CoreEvent is not derived from BaseEvent. I already
figured it had to do with the CoreEvent component instantiation, but the
message is strange indeed.

> I suspect that your real problem is that you omitted the word "type"
> between "protected" and "Baseevent". "protected Baseevent" declares a
> single protected object; "protected type Baseevent" declares a type
> which may then be used to declare many objects of the type.

Thank you! I completely overlooked that! ;-)

> A type declaration may include a reference to an incomplete type, such
> as Coreevent. An object declaration may not, since it has to allocate
> space for the components, and the compiler does not yet know how much
> space needs to be allocated for Coreevent.

Ok. It's clear to me now! :-)

I thought I was creating a type, not a object. But of course it seems
logical that "type" would be required to designate a type. ;-)

> > Can I use a barrier expression that is doing a function call?
>
> Yes, a barrier can be any boolean expression. If you limit yourself to
> the Ravenscar profile, however, a barrier must be a Boolean component of
> the object.

What is the Ravenscar profile?  And why would a barrier be limited to a
Boolean component then?

> BTW, I find the Ada way, Base_Event, much easier to read than Baseevent,
> which is what my reformatter does with your kind of identifiers.

Ok. I can change it, I always fear I clash with predefined names, and
thought the contracted version would be less a candidate for that.

But as far as I understand, the default namespace includes only the Standard
package, right?

BTW, are there any predefined Lists, Queues, Events, Message Queues, and
Containers I could use? I didn't find anything in the Ada 95 reference.






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 16:06   ` Robert I. Eachus
@ 2003-11-25 18:39     ` Ekkehard Morgenstern
  2003-11-26 15:43       ` Robert I. Eachus
  0 siblings, 1 reply; 11+ messages in thread
From: Ekkehard Morgenstern @ 2003-11-25 18:39 UTC (permalink / raw)



"Robert I. Eachus" <rieachus@comcast.net> schrieb im Newsbeitrag
news:Kp6dnRXjpqyY416iRVn-sw@comcast.com...
> > But why is this necessary?
>
> It isn't in general.  What you are missing is a complete definition of
> CoreEvent before you try to create an object of the type:
>
>    EventObject : CoreEvent;  <----

Thanks. I didn't realize was creating an object named BaseEvent, I omitted
the "type" keyword.


> Replacing EventObject by a pointer to CoreEvent eliminates the need for
> "knowing" the size of CoreEvent.  Other fixes would be to complete the
> declaration of CoreEvent before the declaration of BaseEvent,

How could I declare the CoreEvent record layout as private without putting
the declaration in the private section?

>  or to make
>   BaseEvent a protected type, then not create any objects of the type in
> the public part of the package specification.  (You may want to create
> such objects in child packages.)

That's true, I wanted to declare a type, not an object. ;-)

> I would think that the intent is to have several objects of type
> BaseEvent, so the latter would be the best fix.

Yes!

> This principle of linear elaboration order is followed thoughout Ada.
> There are cases where it is a pain, and other cases where it has
> benefits.  But there needs to be one rule for such things, and this rule
> was chosen as the simplest for users to understand.

Ok.

> Incidently, there is no language rule against the style of identifier
> you are using, but Ada compilers and editors do a better job of
> supporting Base_Event instead of BaseEvent.  For example the emacs
> ada-mode I use automatically converts BaseEvent to Baseevent unless I go
> to extra effort.

Thanks. I didn't know that! :-)






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 16:45   ` Ludovic Brenta
@ 2003-11-25 18:45     ` Ekkehard Morgenstern
  2003-11-25 20:09     ` Randy Brukardt
  1 sibling, 0 replies; 11+ messages in thread
From: Ekkehard Morgenstern @ 2003-11-25 18:45 UTC (permalink / raw)



"Ludovic Brenta" <ludovic.brenta@insalien.org> schrieb im Newsbeitrag
news:m38ym4xuqq.fsf@insalien.org...
>
> Because, I think, CoreEvent is not completely defined at the point
> where you use it inside BaseEvent.  Therefore the compiler does not
> know how much memory to allocate for a BaseEvent.

Yup. I wanted to declare a type, not an object, and forgot the "type"
keyword. ;-)

> By contrast, the access type is completely defined, so you can use it
> in the BaseEvent.

Yeah. I wonder now if I should go and change it back to using direct object
instances instead of class-wide access and dynamic allocation.






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 16:45   ` Ludovic Brenta
  2003-11-25 18:45     ` Ekkehard Morgenstern
@ 2003-11-25 20:09     ` Randy Brukardt
  1 sibling, 0 replies; 11+ messages in thread
From: Randy Brukardt @ 2003-11-25 20:09 UTC (permalink / raw)


"Ludovic Brenta" <ludovic.brenta@insalien.org> wrote in message
news:m38ym4xuqq.fsf@insalien.org...
> > And can I create inheritable protected classes?
>
> No.  This has been proposed as an extension to the language [1] back
> in 2000, but the discussions concluded that there was no demand for
> this feature from paying customers, so therefore no compiler vendors
> were going to implement it.
>
> [1] http://www.ada-auth.org/cgi-bin/cvsweb.cgi/AIs/AI-00250.TXT?rev=HEAD

That's not quite the right conclusion. Besides the importance question,
there are also technical issues related to locking that are quite difficult
to solve usefully. Moreover, having the code for locking an protected object
in several units could be very difficult to understand and analyze. The ARG
decided to look at protected interfaces instead (that is, provide interface
inheritance, but not implementation inheritance.) That's AI-345. I don't
know if these will be adopted (there are several issues that need to be
resolved), but it looks like a more promising approach than that given in
AI-250.

               Randy Brukardt.






^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 18:31   ` Ekkehard Morgenstern
@ 2003-11-26  0:42     ` Jeffrey Carter
  0 siblings, 0 replies; 11+ messages in thread
From: Jeffrey Carter @ 2003-11-26  0:42 UTC (permalink / raw)


Ekkehard Morgenstern wrote:

> BTW, are there any predefined Lists, Queues, Events, Message Queues, and
> Containers I could use? I didn't find anything in the Ada 95 reference.

There are a number of libraries available; see adapower.com or 
adaworld.com for links. I'm partial to the PragmAda Reusable Components

http://home.earthlink.net/~jrcarter010/pragmarc.htm

but I may be biased.

The next revision of the Ada standard may contain a standard library of 
data-structure components; see AI-302 for the proposals.

-- 
Jeff Carter
"Sheriff murdered, crops burned, stores looted,
people stampeded, and cattle raped."
Blazing Saddles
35




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Problem with protected type
  2003-11-25 18:39     ` Ekkehard Morgenstern
@ 2003-11-26 15:43       ` Robert I. Eachus
  0 siblings, 0 replies; 11+ messages in thread
From: Robert I. Eachus @ 2003-11-26 15:43 UTC (permalink / raw)


Ekkehard Morgenstern wrote:

>>Replacing EventObject by a pointer to CoreEvent eliminates the need for
>>"knowing" the size of CoreEvent.  Other fixes would be to complete the
>>declaration of CoreEvent before the declaration of BaseEvent, 
> 
> How could I declare the CoreEvent record layout as private without putting
> the declaration in the private section?

Hmmm.  Let me change your question to, "...without putting the 
declaration in SOME private part?"

The answer is you can't.  But the private part which contains the 
completion of CoreEvent need not be the one for the package that 
declares BaseEvent.  The best solution for this problem, when it occurs, 
is to declare BaseEvent in a child package.  I think we agreed though 
that the right solution in this case is to make BaseEvent a protected 
type, and create any objects of the type in the package private part, in 
the package body, or elsewhere.

-- 
                                           Robert I. Eachus

100% Ada, no bugs--the only way to create software.




^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-11-26 15:43 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-25 15:15 Problem with protected type Ekkehard Morgenstern
2003-11-25 15:43 ` Ekkehard Morgenstern
2003-11-25 16:06   ` Robert I. Eachus
2003-11-25 18:39     ` Ekkehard Morgenstern
2003-11-26 15:43       ` Robert I. Eachus
2003-11-25 16:45   ` Ludovic Brenta
2003-11-25 18:45     ` Ekkehard Morgenstern
2003-11-25 20:09     ` Randy Brukardt
2003-11-25 18:03 ` Jeffrey Carter
2003-11-25 18:31   ` Ekkehard Morgenstern
2003-11-26  0:42     ` Jeffrey Carter

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