comp.lang.ada
 help / color / mirror / Atom feed
* Re: Generic using another generic instantiated elsewhere
  1998-02-13  0:00 Generic using another generic instantiated elsewhere Andrew Lynch
@ 1998-02-13  0:00 ` Roger Racine
  0 siblings, 0 replies; 2+ messages in thread
From: Roger Racine @ 1998-02-13  0:00 UTC (permalink / raw)



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




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

* Generic using another generic instantiated elsewhere
@ 1998-02-13  0:00 Andrew Lynch
  1998-02-13  0:00 ` Roger Racine
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Lynch @ 1998-02-13  0:00 UTC (permalink / raw)



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.




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

end of thread, other threads:[~1998-02-13  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-02-13  0:00 Generic using another generic instantiated elsewhere Andrew Lynch
1998-02-13  0:00 ` Roger Racine

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