comp.lang.ada
 help / color / mirror / Atom feed
* Visibility problems in Parent.Child configuration
@ 2002-07-30 11:41 Keld Lund Nielsen
  2002-07-30 19:04 ` Robert A Duff
  2002-07-31 10:57 ` Thomas Wolf
  0 siblings, 2 replies; 6+ messages in thread
From: Keld Lund Nielsen @ 2002-07-30 11:41 UTC (permalink / raw)


Dear All,

a question regarding type visibility. The configuration is as follows:

----file Parent.ads:
 with Ada.Numerics.Generic_Elementary_Functions;
package Parent is

   package Float_64 is
      type Instance is digits 15;
        for Instance'Size use 64;
        package Operations is
          new Ada.Numerics.Generic_Elementary_Functions( Instance );
   end Float_64;

end Parent;

----file Parent.Generic_Child.ads:
 generic
  type Instance is private;

package Parent.Generic_Child is
   --void...
end Parent.Generic_Child;


Then I create a test system with the structure:

  Test.Parent.Child

but when I try to create an instance of Generic_Child or just declare
a subtype of the Parent.Float_64.Instance, then the compiler protests
and gives the message that Float_64 is not in Parent!

Moreover, when instantiated from a simple package - say "my_package" -
then it works perfectly, yet not from the "Test.Parent.Child".

I have swept through my "Cohen" and other books, however I have not
found any solution to the problem - hope you can help me.

Cheers
Keld



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

* Re: Visibility problems in Parent.Child configuration
  2002-07-30 11:41 Visibility problems in Parent.Child configuration Keld Lund Nielsen
@ 2002-07-30 19:04 ` Robert A Duff
  2002-07-31 10:01   ` Keld Lund Nielsen
  2002-07-31 10:57 ` Thomas Wolf
  1 sibling, 1 reply; 6+ messages in thread
From: Robert A Duff @ 2002-07-30 19:04 UTC (permalink / raw)


I think you have to show us the exact code that gets the error.
I can't see what the problem is from the description below.

keld.nielsen@agip.it (Keld Lund Nielsen) writes:

> Dear All,
> 
> a question regarding type visibility. The configuration is as follows:
> 
> ----file Parent.ads:
>  with Ada.Numerics.Generic_Elementary_Functions;
> package Parent is
> 
>    package Float_64 is
>       type Instance is digits 15;
>         for Instance'Size use 64;
>         package Operations is
>           new Ada.Numerics.Generic_Elementary_Functions( Instance );
>    end Float_64;
> 
> end Parent;
> 
> ----file Parent.Generic_Child.ads:
>  generic
>   type Instance is private;
> 
> package Parent.Generic_Child is
>    --void...
> end Parent.Generic_Child;
> 
> 
> Then I create a test system with the structure:
> 
>   Test.Parent.Child
> 
> but when I try to create an instance of Generic_Child or just declare
> a subtype of the Parent.Float_64.Instance, then the compiler protests
> and gives the message that Float_64 is not in Parent!
> 
> Moreover, when instantiated from a simple package - say "my_package" -
> then it works perfectly, yet not from the "Test.Parent.Child".
> 
> I have swept through my "Cohen" and other books, however I have not
> found any solution to the problem - hope you can help me.
> 
> Cheers
> Keld



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

* Re: Visibility problems in Parent.Child configuration
  2002-07-30 19:04 ` Robert A Duff
@ 2002-07-31 10:01   ` Keld Lund Nielsen
  2002-08-01 19:09     ` Stephen Leake
  0 siblings, 1 reply; 6+ messages in thread
From: Keld Lund Nielsen @ 2002-07-31 10:01 UTC (permalink / raw)


You are right. Here is an edited example, which compile except for the
last
file "unit_test.math.G_scalar.adb".

The structure is:

Math.ads (compiles)
\
 Math.G_Scalar.ads  (compiles)

and

Unit_Test.ads  (compiles)
\
 Unit_Test.Math.ads & Unit_Test.Math.adb  (compiles)
 \
  Unit_Test.Math.G_Scalar.ads (compiles) & Unit_Test.Math.G_Scalar
(comp.error)

--Example:

------------------------------
-- Math.ads
------------------------------
 with Ada.Numerics.Generic_Elementary_Functions;
 
package Math is

  package Float_32 is
     type Instance is digits 6;
       for Instance'Size use 32;
         package Operations is 
           new Ada.Numerics.Generic_Elementary_Functions( Instance );
  end Float_32;
  
  package Float_64 is
     type Instance is digits 15;
       for Instance'Size use 64;
         package Operations is 
           new Ada.Numerics.Generic_Elementary_Functions( Instance );
  end Float_64;
           
end Math;


------------------------------
-- Math.G_Scalar.ads
------------------------------
 generic
 
  type Scalar_Type is private;
  
package Math.G_Scalar is

  subtype Instance is Scalar_Type;
  
end Math.G_Scalar;


---
--  unit test 
---

package Unit_Test is
 
  
  procedure Write_Test( Result          : in Boolean; 
                        Routine_Name    : in String;
                        Name_Of_Package : in String);
  
  
  
end Unit_Test;


------------------------------
-- Unit_Test.Math.ads
------------------------------

package Unit_Test.Math is


  procedure Check;


end Unit_Test.Math;


------------------------------
-- Unit_Test.Math.adb
------------------------------

 with Math;
 use Math;


package body Unit_Test.Math is


  procedure Check is

   Name_Of_Package: constant String := "Math";

    Xs : Float_32.Instance;
    Xd : Float_64.Instance;

  begin -- Check

    Write_Test( (Xs'Size = 32), "Float_32 size", Name_Of_Package);
    
    Write_Test( (Xd'Size = 64), "Float_64 size", Name_Of_Package);

  end Check;


end Unit_Test.Math;


------------------------------
-- Unit_Test.Math.G_Scalar.ads
------------------------------

package Unit_Test.Math.G_Scalar is


  procedure Check;


end Unit_Test.Math.G_Scalar;


------------------------------
-- Unit_Test.Math.G_Scalar.adb
------------------------------
 with Math.G_Scalar;

package body Unit_Test.Math.G_Scalar is


  procedure Check is

   Name_Of_Package: constant String := "Math.G_Scalar";

    subtype F64 is Math.Float_64.Instance; ------> ERROR HERE
    
    package Scalar is
      new Math.G_Scalar( Math.Float_64.Instance ); ------> ERROR HERE

  begin -- Check

    Write_Test( false, "Insert routine name here", Name_Of_Package);

  end Check;


end Unit_Test.Math.G_Scalar;


Error message is simply that Float_64 is not in Math according to the
compiler(Gnat).

Do you have any suggestions?
Cheers
Keld


Robert A Duff <bobduff@shell01.TheWorld.com> wrote in message news:<wccfzy1ghpn.fsf@shell01.TheWorld.com>...
> I think you have to show us the exact code that gets the error.
> I can't see what the problem is from the description below.



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

* Re: Visibility problems in Parent.Child configuration
  2002-07-30 11:41 Visibility problems in Parent.Child configuration Keld Lund Nielsen
  2002-07-30 19:04 ` Robert A Duff
@ 2002-07-31 10:57 ` Thomas Wolf
  2002-08-01  7:51   ` Keld Lund Nielsen
  1 sibling, 1 reply; 6+ messages in thread
From: Thomas Wolf @ 2002-07-31 10:57 UTC (permalink / raw)


keld.nielsen@agip.it (Keld Lund Nielsen) wrote in message news:<383f908a.0207300341.1047c075@posting.google.com>...
> Dear All,
> 
> a question regarding type visibility. The configuration is as follows:
> 
> ----file Parent.ads:
>  with Ada.Numerics.Generic_Elementary_Functions;
> package Parent is
> 
>    package Float_64 is
>       type Instance is digits 15;
>         for Instance'Size use 64;
>         package Operations is
>           new Ada.Numerics.Generic_Elementary_Functions( Instance );
>    end Float_64;
> 
> end Parent;
> 
> ----file Parent.Generic_Child.ads:
>  generic
>   type Instance is private;
> 
> package Parent.Generic_Child is
>    --void...
> end Parent.Generic_Child;
> 
> 
> Then I create a test system with the structure:
> 
>   Test.Parent.Child
> 
> but when I try to create an instance of Generic_Child or just declare
> a subtype of the Parent.Float_64.Instance, then the compiler protests
> and gives the message that Float_64 is not in Parent!
> 
> Moreover, when instantiated from a simple package - say "my_package" -
> then it works perfectly, yet not from the "Test.Parent.Child".

That's because if you do e.g.

package Test.Parent.Child is

  subtype My_Float is Parent.Float_64.Instance;

end Test.Parent.Child;

the name "Parent" refers to package "Test.Parent", not
to package "Parent". To refer from within "Test.Parent" or
one of its children to the top-level package "Parent", use
"Standard.Parent". E.g.

package Test.Parent.Child is

  subtype My_Float is Standard.Parent.Float_64.Instance;

end Test.Parent.Child;

should work.

--
----------------------------------------------------------------
Thomas Wolf                         e-mail: t_wolf@angelfire.com



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

* Re: Visibility problems in Parent.Child configuration
  2002-07-31 10:57 ` Thomas Wolf
@ 2002-08-01  7:51   ` Keld Lund Nielsen
  0 siblings, 0 replies; 6+ messages in thread
From: Keld Lund Nielsen @ 2002-08-01  7:51 UTC (permalink / raw)


t_wolf@angelfire.com (Thomas Wolf) wrote in message news:<719a5d07.0207310257.63c9645@posting.google.com>...
> keld.nielsen@agip.it (Keld Lund Nielsen) wrote in message news:<383f908a.0207300341.1047c075@posting.google.com>...
> > Dear All,
> > 
> > a question regarding type visibility. The configuration is as follows:
> > 
> > ----file Parent.ads:
> >  with Ada.Numerics.Generic_Elementary_Functions;
> > package Parent is
> > 
> >    package Float_64 is
> >       type Instance is digits 15;
> >         for Instance'Size use 64;
> >         package Operations is
> >           new Ada.Numerics.Generic_Elementary_Functions( Instance );
> >    end Float_64;
> > 
> > end Parent;
> > 
> > ----file Parent.Generic_Child.ads:
> >  generic
> >   type Instance is private;
> > 
> > package Parent.Generic_Child is
> >    --void...
> > end Parent.Generic_Child;
> > 
> > 
> > Then I create a test system with the structure:
> > 
> >   Test.Parent.Child
> > 
> > but when I try to create an instance of Generic_Child or just declare
> > a subtype of the Parent.Float_64.Instance, then the compiler protests
> > and gives the message that Float_64 is not in Parent!
> > 
> > Moreover, when instantiated from a simple package - say "my_package" -
> > then it works perfectly, yet not from the "Test.Parent.Child".
> 
> That's because if you do e.g.
> 
> package Test.Parent.Child is
> 
>   subtype My_Float is Parent.Float_64.Instance;
> 
> end Test.Parent.Child;
> 
> the name "Parent" refers to package "Test.Parent", not
> to package "Parent". To refer from within "Test.Parent" or
> one of its children to the top-level package "Parent", use
> "Standard.Parent". E.g.
> 
> package Test.Parent.Child is
> 
>   subtype My_Float is Standard.Parent.Float_64.Instance;
> 
> end Test.Parent.Child;
> 
> should work.

It DOES work - thank you very much.
Cheers
Keld



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

* Re: Visibility problems in Parent.Child configuration
  2002-07-31 10:01   ` Keld Lund Nielsen
@ 2002-08-01 19:09     ` Stephen Leake
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Leake @ 2002-08-01 19:09 UTC (permalink / raw)


keld.nielsen@agip.it (Keld Lund Nielsen) writes:

> You are right. Here is an edited example, which compile except for the
> last
> file "unit_test.math.G_scalar.adb".

Your problem is you have too many things called "Math". You have both
"Standard.Math" in your file math.ads and "Standard.Unit_Test.Math"
in some other file. At the point of the error, "Math" refers to
"Standard.Unit_Test.Math", which does not in fact contain Float_64.

code snipped.

-- 
-- Stephe



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

end of thread, other threads:[~2002-08-01 19:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-30 11:41 Visibility problems in Parent.Child configuration Keld Lund Nielsen
2002-07-30 19:04 ` Robert A Duff
2002-07-31 10:01   ` Keld Lund Nielsen
2002-08-01 19:09     ` Stephen Leake
2002-07-31 10:57 ` Thomas Wolf
2002-08-01  7:51   ` Keld Lund Nielsen

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