From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!rochester!pt.cs.cmu.edu!sei!ajpo!dyer From: dyer@ajpo.sei.cmu.edu (Richard Dye) Newsgroups: comp.lang.ada Subject: Using the Use Clause to Limit Direct Visibility Keywords: use,visibility,infix operators Message-ID: <692@ajpo.sei.cmu.edu> Date: 30 Aug 90 13:23:54 GMT List-Id: There have recently been several discussions of the use clause in this newsgroup. On my project, we build our types packages with an embedded operators package to provide limited direct visibility to the infix operators of the types package. Here's an example: with Constants; package Types is type Integer_Type is new Integer range Constants.Min .. Constants.Max; -- etc for other types package Operators is function "+"(L,R : Integer_Type) return Integer_Type renames "+"; -- etc for the other infix operators end Operators; end Types; Every package or subpragram which needs visibility to the Types packages withs it in. Every package or subprogram which needs direct visibility to the infix operators on the Types package does a use on Types.Operators. There is a subtlety to the use clause in this case. In general, the use clause can be either a context clause (occurs before the package or subprogram specification) or a basic declaration (occurs after the package or subprogram specification). When the use clause is a context clause, it can only refer to a simple_name (see LRM 10.1.1(3)). This means that a use clause which is a context clause can not say "use Types.Operators;" Only a use clause which is a basic declaration can say "use Types.Operators;" because a use clause which is a basic declaration can refer to a name (LRM 8.4(2)) which can be a selected component (LRM 4.1(2)). I mention this because we generated a multitude of strange syntax errors until we moved our use clauses to a position after the specifications. We were unable to locate this difference in the Ada semantics until we talked with Geoff Mendal of Stanford. (Our thanks to Geoff.) Hopefully this note will help others limit direct visibility to only those portions of a package which warrant direct visibility. Dick Dye CTA, Inc. M/S N8910 National Test Bed Falcon AFB, CO 80912-5000 (719) 380-2578 dyer@ajpo.sei.cmu.edu