comp.lang.ada
 help / color / mirror / Atom feed
* Q: generic children of generic packages?
@ 2001-06-11 16:35 Steve Vestal
  2001-06-11 17:27 ` Ted Dennison
  0 siblings, 1 reply; 5+ messages in thread
From: Steve Vestal @ 2001-06-11 16:35 UTC (permalink / raw)


I'm trying to do something like:

    generic  ...
    package Generic_Stuff is ...
    private ...
    end Generic_Stuff;

    generic ...
    package Generic_Stuff.Generic_IO is ...
    end Generic_Stuff.Generic_IO;

Does anyone know how to make this work?  (My intuition was that an
instantiation of Generic_Stuff would have a child Generic_IO that could in
turn be instantiated, but gnat doesn't seem to let me do that.)






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

* Re: Q: generic children of generic packages?
  2001-06-11 16:35 Q: generic children of generic packages? Steve Vestal
@ 2001-06-11 17:27 ` Ted Dennison
  2001-06-11 18:29   ` Steve Vestal
  0 siblings, 1 reply; 5+ messages in thread
From: Ted Dennison @ 2001-06-11 17:27 UTC (permalink / raw)


In article <vc58ziz3rgf.fsf@grinch.htc.honeywell.com>, Steve Vestal says...
>
>I'm trying to do something like:
>
>    generic  ...
>    package Generic_Stuff is ...
>    private ...
>    end Generic_Stuff;
>
>    generic ...
>    package Generic_Stuff.Generic_IO is ...
>    end Generic_Stuff.Generic_IO;
>
>Does anyone know how to make this work?  (My intuition was that an

It looks fine to me. The precise nature of your problem might be a bit clearer
if you specified the exact error you are getting (and the source surrounding
that line).

My guess is that you are actually having instantiation troubles. Remember that
you have to instantiate the child generic from an *instance* of the parent
generic, not from the parent generic itself.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

* Re: Q: generic children of generic packages?
  2001-06-11 17:27 ` Ted Dennison
@ 2001-06-11 18:29   ` Steve Vestal
  2001-06-11 18:41     ` Ed Falis
  2001-06-11 18:55     ` Ted Dennison
  0 siblings, 2 replies; 5+ messages in thread
From: Steve Vestal @ 2001-06-11 18:29 UTC (permalink / raw)


Here's what I tried, with the error messages included as comments.  The
problem seems to occur in the attempt to instantiate the generic child
package.  Any suggestions would be most appreciated.

generic
package Generic_Parent is
   type Hidden_Type is private;
   procedure Frobulate (HT: in out Hidden_Type);
private
   type Hidden_Type is new Integer;
end Generic_Parent;

package body Generic_Parent is
   procedure Frobulate (HT: in out Hidden_Type) is
   begin
       HT := HT + 1;
   end;
end Generic_Parent;

generic
package Generic_Parent.Generic_Child is
    procedure Pre_Frobulate (HT: out Hidden_Type);
end Generic_Parent.Generic_Child;

package body Generic_Parent.Generic_Child is
    procedure Pre_Frobulate (HT: Hidden_Type) is
    begin
        HT := 0;
    end;
end Generic_Parent.Generic_Child;

with Generic_Parent;
package Parent is new Generic_Parent;

with Parent;
-- parent-child.ads:5:35: "Generic_Child" not declared in "Parent"
-- Can also try the following, with following results.
--with Parent.Generic_Child;
-- main.adb:2:06: file "parent-generic_child.ads" not found
package Parent.Child is new Parent.Generic_Child;

with Parent;
with Parent.Child;
procedure Main is
   HT: Parent.Hidden_Type;
begin
   Parent.Child.Pre_Frobulate (HT);
   Parent.Frobulate (HT);
end Main;





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

* Re: Q: generic children of generic packages?
  2001-06-11 18:29   ` Steve Vestal
@ 2001-06-11 18:41     ` Ed Falis
  2001-06-11 18:55     ` Ted Dennison
  1 sibling, 0 replies; 5+ messages in thread
From: Ed Falis @ 2001-06-11 18:41 UTC (permalink / raw)


Steve Vestal wrote:

> Here's what I tried, with the error messages included as comments.  The
> problem seems to occur in the attempt to instantiate the generic child
> package.  Any suggestions would be most appreciated.
>
> with Parent;
> -- parent-child.ads:5:35: "Generic_Child" not declared in "Parent"
> -- Can also try the following, with following results.
> --with Parent.Generic_Child;
> -- main.adb:2:06: file "parent-generic_child.ads" not found
> package Parent.Child is new Parent.Generic_Child;
>
>

Add "with Generic_Parent.Generic_Child;"

- Ed




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

* Re: Q: generic children of generic packages?
  2001-06-11 18:29   ` Steve Vestal
  2001-06-11 18:41     ` Ed Falis
@ 2001-06-11 18:55     ` Ted Dennison
  1 sibling, 0 replies; 5+ messages in thread
From: Ted Dennison @ 2001-06-11 18:55 UTC (permalink / raw)


In article <vc566e250pw.fsf@grinch.htc.honeywell.com>, Steve Vestal says...
>
>Here's what I tried, with the error messages included as comments.  The
>problem seems to occur in the attempt to instantiate the generic child

..as I guessed. (owch! I think I just wrenched my shoulder patting myself on
the back there.)

>generic
>package Generic_Parent is
..
>generic
>package Generic_Parent.Generic_Child is

So far so good...

>package Parent is new Generic_Parent;
>-- parent-child.ads:5:35: "Generic_Child" not declared in "Parent"
>-- Can also try the following, with following results.
>--with Parent.Generic_Child;
>-- main.adb:2:06: file "parent-generic_child.ads" not found
>package Parent.Child is new Parent.Generic_Child;

Three things here. First off, as I said before, you must instantiate from an
instance of the generic, not from a generic. You seem to have picked that one
up. However, you don't need to "with" something you just declared yourself
locally. That's why you are getting an error trying to "with
Parent.Generic_Child".  Lastly, the new "Child" package that you are creating
isn't really a child package once you instantiate it, so you can't give it a
parent in the declaration (Think of it as something akin to a "renames" that
does some actual work).

I haven't compiled this, but you should try:

with Generic_Parent.Generic_Child;  -- implicitly "with"s Generic_Parent

package Parent is new Generic_Parent;
package Child is new Parent.Generic_Child;


If you don't mind downloading and looking through someone else's code, the
example and test directories in OpenToken (
http://www.telepath.com/dennison/Ted/OpenToken/OpenToken.html ) contain quite a
few examples of instantiation of generic children of generic packages. Also, 
any code showing use of the Ada95 Booch Components would contain good examples
(but I don't know where any of those are online).

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



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

end of thread, other threads:[~2001-06-11 18:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-06-11 16:35 Q: generic children of generic packages? Steve Vestal
2001-06-11 17:27 ` Ted Dennison
2001-06-11 18:29   ` Steve Vestal
2001-06-11 18:41     ` Ed Falis
2001-06-11 18:55     ` Ted Dennison

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