comp.lang.ada
 help / color / mirror / Atom feed
From: rayssd!swlvx2!dep@uunet.uu.net  (DONALD PRINCIOTTA)
Subject: Re: Generic Package Visibility Problems! (help)
Date: 4 Oct 92 22:10:53 GMT	[thread overview]
Message-ID: <1992Oct4.221053.26787@swlvx2.msd.ray.com> (raw)

young@gdfwc3 (Mark Young) writes:


>I am having visibility problems with generic packages.

>Here's an example:

>file #1
>-----------------------------------------------
>generic 

>  Generic_Parameter : Generic_Parameter_Type;

>package Color is

>  type RGB_Type is (RED,GREEN,BLUE);

>  function Get_Color return RGB_Type;

>end Color;
>----------------------------------------------
>file #2
>----------------------------------------------
>with Color;

>package Caller is

>  package C_1 is new Caller( Generic_Argument );

>  procedure Test_Color;

>end Caller;

>package body Caller is 

>  procedure Test_Color is separate;

>end Caller;
>---------------------------------------------
>file #3
>---------------------------------------------
>separate( Caller )

>procedure Test_Color is

>begin

>  if ( C_1.Get_Color = C_1.RED ) then
>	               -------
>	null;

>  end if;

>end Test_Color;
>----------------------------------------------

>This will not work.  For some reason the compiler cannot
>resolve C_1.RED.  It tells me that = is not a legal 
>operation, that C_1.Get_Color returns type RGB_Type but, 
>that it does not understand C_1.RED and that perhaps I 
>needed a "use" clause in the body of Caller.  I don't
>understand this.  My understanding of Ada scoping would
>lead me to believe that this is correct.  Am I missing 
>something?  

>BTW: this is not a complete example, it is only to illustrate
>a point.

>Thanks,

>Mark Young


--- START OF RESPONSE -------------------------------------------------------

Mark,
  The answer to your problem is simple... Just a plain old
everyday visibility problem.  I won't comment of the worth
of your test program, lets just say it could use a little
imagination and leave it at that.... 

The error message displayed by your compile was exactly right...
You don't have an equality operation visible at the point within
your program where you are attempting to invoke the function.

Think on where a types operations are visible??? The operations
are visible where the type is defined (i.e. inside of the 
package in this case.  If you did use the "use clause" it would
solve your visibility problem but that would be the LAMO way to
solve the problem.  You do in have visibility to the "=" operation
the problem stems from the fact that you don't have direct visibility
the the operation.  The following two examples demonstrate 
possible ways to get at your "=" operation.

separate( Caller )
procedure Test_Color is
begin
  if C_1."="(C_1.Get_Color,C_1.RED) then  -- "=" exists within C_1
       null;
  end if;
end Test_Color;

OR --------------------------------



separate( Caller )
procedure Test_Color is
   function "=" ( Left  : in C1.RGB_Type
                  Right : in C1.RGB_Type ) return Boolean renames C_1."=";
   -- Make only the "=" operation directly visible.
   -- This renaming clause could als0 have been placed inside of
   -- the parent routine Caller
begin
  if ( C_1.Get_Color = C_1.RED) then  -- "=" exists within C_1
       null;
  end if;
end Test_Color;


Hope this answers your question .................

                                Don Princiotta
                                dep@swlvx6.msd.ray.com

--- END OF RESPONSE ---------------------------------------------------------

             reply	other threads:[~1992-10-04 22:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-10-04 22:10 DONALD PRINCIOTTA [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-10-04 21:02 Generic Package Visibility Problems! (help) Adam Beneschan
1992-10-02 23:25 dog.ee.lbl.gov!overload.lbl.gov!agate!spool.mu.edu!nigel.msen.com!caen!de
1992-10-02 18:35 Mark Young
replies disabled

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