[comp.lang.ada] Visibility in Embedded Packages

dyer@ajpo.sei.cmu.edu (Richard Dye) (10/28/90)

In the previous edition of Ada Letters, Bird wrote to Dear Ada that he liked
to embed an operators package in his types packages so he could provide 
direct visibility to the infix operators without providing direct 
visibility to the types themselves (via a use clause).  We've tried this
on three different compilers and each compiler requires a different syntax
to achieve the effect.  My question to all the language lawyers is why?
Which one is right?  (The three compilers are Telesoft 1.3 and 1.4 self-
hosted on Sun 3s and VAX ACS (Don't know the version.))

The code we tried is:

package Standard_Types is
Min_Integer : constant := -1 * (2 ** 31);
Max_Integer : constant := (2 ** 31) -1;
type Integer_Type is range Min_Integer .. Max_Integer;

package Operators is
function "+"(L,R : Integer_Type) return Integer_Type renames "+";
end Operators;

end Standard_Types;

The above works fine on the Telesoft 1.4.

The Telesoft 1.3 requires:
function "+"(L,R : Integer_Type) return Integer_Type renames Standard."+";

The VAX requires:
function "+"(L,R : Integer_Type) return Integer_Type renames Standard_Types."+";


I'm working from memory so I may not have the correct associations between
compilers and requirements but the three fixes were what we had to do.
Dick

Dick Dye
CTA, Inc.
M/S N8910
National Test Bed
Falcon AFB, CO 80912-5000
(719) 380-2578
FAX: (719) 380-3100 (Put M/S N8910 on the first page)
dyer@ajpo.sei.cmu.edu

stt@inmet.inmet.com (10/29/90)

Re: Visibility in embedded packages

Only the third method:
  package Operators
   function "+"(Left, Right : Integer_Type) return Integer_Type
      renames Standard_Types."+";
   . . .

is correct.
This is because that the declaration of "+" in
package Operators hides the outer declaration of "+" in Standard_Types,
requiring the expanded-name notation.

The version which requires Standard."+" is totally wrong,
since the Integer_Type is not declared in package Standard.


S. Tucker Taft
Intermetrics, Inc.
Cambridge, MA  02138

NCOHEN@IBM.COM ("Norman H. Cohen") (10/30/90)

Dick Dye writes:

 >The code we tried is:
 >
 >package Standard_Types is
 >Min_Integer : constant := -1 * (2 ** 31);
 >Max_Integer : constant := (2 ** 31) -1;
 >type Integer_Type is range Min_Integer .. Max_Integer;
 >
 >package Operators is
 >function "+"(L,R : Integer_Type) return Integer_Type renames "+";
 >end Operators;
 >
 >end Standard_Types;
 >
 >The above works fine on the Telesoft 1.4.
 >
 >The Telesoft 1.3 requires:
 >function "+"(L,R : Integer_Type) return Integer_Type renames Standard."+";
 >
 >The VAX requires:
 >function "+"(L,R : Integer_Type) return Integer_Type renames Standard_Types."+";

The version said to be required by Telesoft 1.3 can be dismissed out of
hand:  There is no version of "+" for the user-declared type Integer_Type
in package Standard.

The version shown in full, said to be accepted by Telesoft 1.4, is also
incorrect.  The inner declaration of "+" (the renaming declaration) is a
homograph of the outer declaration of "+" (the subprogram declaration),
since they have the same name and parameter/result-type profile.
Therefore the outer declaration is hidden within the immediate scope of
the inner declaration (see RM 8.3(15)).  The immediate scope of the inner
declaration starts at the BEGINNING of that declaration (RM 8.2(2)), so
the outer declaration is hidden within the renaming declaration itself.
(On the other hand, even though the SCOPE of the inner declaration
starts at the beginning of that declaration, the inner declaration does
not become VISIBLE until the end of that declaration--see RM 8.3(5)--so
neither the "+" that hides nor the "+" that is hidden is visible within
the renaming declaration.)

However, the outer declaration can be made visible by selection anywhere
in its scope after the declaration itself, so the version said to be
accepted on the VAX is legal.  (The outer declaration of "+" is visible
by selection in the context Standard_Types."+" both by RM 8.3(7)--
because "+" is exported by Standard_Types--and by RM 8.3(13)--because
Standard_Types is the name of a surrounding construct.)

It is irrelevant that the two declarations of "+" declare names denoting
the same entity.  The visibility rules are given in terms of
declarations, not entities.  Two declarations corresponding to the same
entity can be homographs.

Norman H. Cohen

rosen@ulysse.enst.fr (Jean Pierre Rosen) (11/01/90)

In article <718@ajpo.sei.cmu.edu>, dyer@ajpo.sei.cmu.edu (Richard Dye) writes:
...
> function "+"(L,R : Integer_Type) return Integer_Type renames "+";
> The above works fine on the Telesoft 1.4.
Seems OK to me.

> The Telesoft 1.3 requires:
> function "+"(L,R : Integer_Type) return Integer_Type renames Standard."+";
This one is certainly wrong. STANDARD has no "+" operator with the correct
profile.

> The VAX requires:
> function "+"(L,R : Integer_Type) return Integer_Type renames Standard_Types."+";
This is certainly allowed, but I don't see why it is required.