comp.lang.ada
 help / color / mirror / Atom feed
From: Roger_Racine@draper.com (Roger Racine)
Subject: Re: Generic using another generic instantiated elsewhere
Date: 1998/02/13
Date: 1998-02-13T00:00:00+00:00	[thread overview]
Message-ID: <Roger_Racine-1302981239200001@rjr1287.draper.com> (raw)
In-Reply-To: 34E41D3B.474B@cci.de


Please pardon the email address.  It is bogus.  I have never been Spammed
before sending a post to this newsgroup.  Change Roger_Racine to rracine.

In article <34E41D3B.474B@cci.de>, lynch@cci.de wrote:

> Hi,
> 
> a colleague of mine, who is fairly new to Ada, came to me with the
> following "problem". I'm not quite sure what to suggest to him, so
> hopefully you can provide some hints or ideas.
> 
> He has two generic packages, one of which contains a task.
> They are both instantiated in the main program. He wants to call
> an entry of the task from within the other generic package.
> Eg. something like this (not good Ada):
> 
> generic
>    Some_Type ...
>    Some_Procedure ...
> package Foo is
>    ...
>    task Some_Task is
>       entry do_foo ...
>    end Some_Task;
> end Foo;
> 
> generic
>    Some_Other_Type ...
>    Some_Other_Procedure ...
> package Bar is
>    ...
>    procedure FooBar;
> end Bar;
> 
> package body Bar is
>    procedure FooBar is
>    begin
>       ...
>       My_Foo.Some_Task.do_foo( ... );
>       -- somehow call the do_foo entry
>       -- of the My_Foo instantiation below!
>    end FooBar;
> end Bar;
> 
> procedure Main is
>    My_Foo is new Foo();
>    My_Bar is new Bar();
> begin
>    ... call FooBar somewhere
> end Main;
> 
> 
> They are using Ada 83 and I doubt this is possible(*).
> Should I tell him to "forget the whole thing", or are there other
> ways to achieve a similar effect?
> 
> (*) In Ada 95 I guess it would be possible to use a generic formal
> package for this, ie. pass My_Foo to the instantiation of Bar?
> 
> Cheers,
> Andrew.

Add a procedure to the formal parameter list of Bar, and use the entry as
the actual parameter. 

generic
    Some_Type ...
    Some_Procedure ...
 package Foo is
    ...
    task Some_Task is
       entry do_foo ...
    end Some_Task;
 end Foo;
 
 generic
    Some_Other_Type ...
    Some_Other_Procedure ...

    with procedure Do_Foo(...);  -- Note the actual parameter can be an entry

 package Bar is
    ...
    procedure FooBar;
 end Bar;
 
 package body Bar is
    procedure FooBar is
    begin
       ...
       My_Foo.Some_Task.do_foo( ... );
       -- somehow call the do_foo entry
       -- of the My_Foo instantiation below!
    end FooBar;
 end Bar;
 
 procedure Main is
    My_Foo is new Foo();
    My_Bar is new Bar( ... ,My_Foo.Some_Task.do_foo);
 begin
    ... call FooBar somewhere
 end Main;

Roger Racine
Draper Laboratory




      reply	other threads:[~1998-02-13  0:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-02-13  0:00 Generic using another generic instantiated elsewhere Andrew Lynch
1998-02-13  0:00 ` Roger Racine [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