comp.lang.ada
 help / color / mirror / Atom feed
* Generic child units with Gnat
@ 1995-03-27  7:39 Fintan Culwin
  1995-03-30  0:00 ` David Weller
  1995-04-04  0:00 ` Robert Dewar
  0 siblings, 2 replies; 4+ messages in thread
From: Fintan Culwin @ 1995-03-27  7:39 UTC (permalink / raw)


Regarding the instantation of generic child packages with Gnat 2.03.

Following the example of such instantiations in section 2.8 of the 
Ada 9X rationale. With regard to Gnat insisting upon one compilation 
unit per source code file and the requirement to have generic package 
bodies available at compile time. 

The following files were produced.

====================================================================


-- Filename ComplexNumbers_.ads

generic
   type FloatType is digits <>;
package ComplexNumbers is
   procedure foo( Dummy : in FloatType); 
end ComplexNumbers;

====================================================================

-- filename ComplexNumbers.adb

package body ComplexNumbers is
   procedure foo( Dummy : in FloatType) is
   begin -- foo
      null;
   end foo;
end ComplexNumbers;

====================================================================

-- filename ComplexNumbers.Polar_.ads
generic
package ComplexNumbers.Polar is
   procedure bar( Dummy : in FloatType); 
end ComplexNumbers.Polar;

====================================================================

-- filename ComplexNumbers.Polar.adb

package body ComplexNumbers.Polar is
   procedure bar( Dummy : in FloatType) is
   begin -- bar
      null;
   end bar;
end ComplexNumbers.Polar;

====================================================================

The client program for this parent/child generic package is

====================================================================


01 -- Filename FooBar.adb
02
03 with ComplexNumbers.Polar;
04
05 -- package RealComplexNumbers is new ComplexNumbers( Float);  
06 -- package RealComplexNumbers.Polar is new ComplexNumbers( Float);
07
08 procedure FooBar is
09
10 --   package RealComplexNumbers is new ComplexNumbers( Float);
11 --   package RealComplexNumbers.Polar is 
12 --                                new ComplexNumbers( Float);
13
14 begin -- FooBar
15   null;
16 end FooBar;

The attempted instantiation at line 05 resulted in the error message
 
           'Keyword body expected here' (following package). 

Presumaby as gnat insists upon one compilation unit per file.

With lines 05 and 06 commented out, the alternative instantaition at 
line 10 was successful. But the attempted instantiation on line 11/12
produced the error message...

              'child unit allowed only at library level'

Where is the library level ??
What have I got wrong ??
How does one instantiate generic children in gnat??
help !!

Private e-mail preferred & I will sumarise later ...

fintan

============================================================

Fintan Culwin
Senior Lecturer Software Engineering
South Bank University : London

fintan@sbu.ac.uk






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

* Re: Generic child units with Gnat
  1995-03-27  7:39 Generic child units with Gnat Fintan Culwin
@ 1995-03-30  0:00 ` David Weller
  1995-03-31  0:00   ` Sean McNeil
  1995-04-04  0:00 ` Robert Dewar
  1 sibling, 1 reply; 4+ messages in thread
From: David Weller @ 1995-03-30  0:00 UTC (permalink / raw)


In article <3l5q2n$6le@unix.sbu.ac.uk>,
Fintan Culwin  <fintan@sbu.ac.uk> wrote:
>[supplied source deleted]
>Where is the library level ??
>What have I got wrong ??
>How does one instantiate generic children in gnat??
>help !!
>
>Private e-mail preferred & I will sumarise later ...
>
I'm posting publicly, since I think a lot of folks would like to know
this (and to prevent your mailbox from getting flooded... :-)

There were only two small problems:
1) generic package instantiations go inside that package declaration,
not before
2) Your child instantion syntax was a little off
3) your filenaming convention was slightly off (to my knowledge, GNAT
still requires a specific manner to naming child units)

(*Ahem*  I'm sure Norm Cohen will point out that I now qualify as the other
half of those "three types of people" :-)

Instead of going into gory details, I'm posting the corrected source
below.  It was pretty easy to fix.

-- File: complexnumbers.ads
generic
   type FloatType is digits <>;
package ComplexNumbers is
   procedure foo( Dummy : in FloatType);
end ComplexNumbers;

--File: complexnumbers.adb
package body ComplexNumbers is
   procedure foo( Dummy : in FloatType) is
   begin -- foo
      null;
   end foo;
end ComplexNumbers;

--File: complexnumbers-polar.ads
generic
package ComplexNumbers.Polar is
   procedure bar( Dummy : in FloatType);
end ComplexNumbers.Polar;

--File: complexnumbers-polar.adb
package body ComplexNumbers.Polar is
   procedure bar( Dummy : in FloatType) is
   begin -- bar
      null;
   end bar;
end ComplexNumbers.Polar;

--Filename foobar.adb
with ComplexNumbers.Polar; -- auto visibility to parent
procedure FooBar is
   package RealComplexNumbers is new ComplexNumbers( Float);
   package PolarRealComplexNumbers is new RealComplexNumbers.Polar;
begin -- FooBar
  null;
end FooBar;


-- 
      Frustrated with C, C++, Pascal, Fortran?  Ada95 _might_ be for you!
	  For all sorts of interesting Ada95 tidbits, run the command:
"finger dweller@starbase.neosoft.com | more" (or e-mail with "finger" as subj.)
		if u cn rd ths, u r gd enuf to chg to Ada   :-)




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

* Re: Generic child units with Gnat
  1995-03-30  0:00 ` David Weller
@ 1995-03-31  0:00   ` Sean McNeil
  0 siblings, 0 replies; 4+ messages in thread
From: Sean McNeil @ 1995-03-31  0:00 UTC (permalink / raw)


In article <3le685$l9h@Starbase.NeoSoft.COM> dweller@Starbase.NeoSoft.COM (David Weller) writes:

>   --File: complexnumbers-polar.ads
>   generic
>   package ComplexNumbers.Polar is
>      procedure bar( Dummy : in FloatType);
>   end ComplexNumbers.Polar;
>
> ...
>
>   --Filename foobar.adb
>   with ComplexNumbers.Polar; -- auto visibility to parent
>   procedure FooBar is
>      package RealComplexNumbers is new ComplexNumbers( Float);
>      package PolarRealComplexNumbers is new RealComplexNumbers.Polar;
>   begin -- FooBar
>     null;
>   end FooBar;
>
  Since it appears that ComplexNumbers.Polar is only dependant on FloatType
from the parent package, wouldn't the following be better?

   --File: complexnumbers-polar.ads
   package ComplexNumbers.Polar is
      procedure bar( Dummy : in FloatType);
   end ComplexNumbers.Polar;

   --Filename foobar.adb
   with ComplexNumbers.Polar; -- auto visibility to parent
   procedure FooBar is
      package RealComplexNumbers is new ComplexNumbers( Float);
      package PolarRealComplexNumbers renames RealComplexNumbers.Polar;
   begin -- FooBar
     null;
   end FooBar;

One less generic instantiation.

Sean McNeil
smcneil@netcom.com




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

* Re: Generic child units with Gnat
  1995-03-27  7:39 Generic child units with Gnat Fintan Culwin
  1995-03-30  0:00 ` David Weller
@ 1995-04-04  0:00 ` Robert Dewar
  1 sibling, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1995-04-04  0:00 UTC (permalink / raw)


egarding Fintan's message, first remember to always send copies of bug
reports for GNAT to gnat-report@cs.nyu.edu.

Second, GNAT 2.00 is quite out of date now, there have been releases
2.02, 2.03 and now 2.04 since then, and many changes and fixes have
been made in the area of child packages. (and may other areas too),
so you should pick up a later version





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

end of thread, other threads:[~1995-04-04  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-03-27  7:39 Generic child units with Gnat Fintan Culwin
1995-03-30  0:00 ` David Weller
1995-03-31  0:00   ` Sean McNeil
1995-04-04  0:00 ` Robert Dewar

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