From rybin@possum.srcc.msu.su Mon Mar 3 06:25:05 1997 Return-Path: Received: from ida.org by cronus.csed.ida.org (SMI-8.6/SMI-SVR4) id GAA12138; Mon, 3 Mar 1997 06:25:05 -0500 Received: from by ida.org (4.1/SMI-4.1) id AB05104; Mon, 3 Mar 97 06:22:01 EST Received: from crocus.gamma.ru by sw-eng.falls-church.va.us (8.7.1/) id KAA07876; Mon, 3 Mar 1997 10:24:18 GMT Received: from srcc.UUCP (uucp@localhost) by crocus.gamma.ru (8.7.6/8.7.3) with UUCP id NAA05575 for asis-comment@sw-eng.falls-church.va.us; Mon, 3 Mar 1997 13:26:59 +0300 (MSK) Received: by gamma.srcc.msu.su; Mon, 3 Mar 1997 13:25:54 +0300 Received: by possum.srcc.msu.su (UUPC/@ v5.09gamma, 14Mar93); Mon, 3 Mar 1997 12:58:52 +0300 To: asis-comment@sw-eng.falls-church.va.us Cc: rybin@crocus.gamma.ru Message-Id: Organization: Information Systems, SRCC, MSU From: "Sergey I. Rybin" Date: Mon, 3 Mar 97 12:58:52 +0300 X-Mailer: BML [MS/DOS Beauty Mail v.1.36] Subject: queries having a Context as an additional parameter Lines: 232 Content-Length: 8818 Status: OR !topic Queries having a Context as an additional parameter !reference ASIS 95-10, 15 !from Sergey Rybin !keywords Context !discussion ASIS contains a number of pairs of queries, in each of these pairs, both queries have the same name, they have similar functionality, the first query in the pair has one parameter, but the second one contains additional parameter of a Context type. There are two groups of these pairs - one contains queries from Asis.Compilation_Units, another contains semantic queries from Asis.Declarations working on Elements. Some time ago I sent to the ASIS forum the question about the semantic of Compilation unit queries having a Context as an additional parameter. We had a short discussion with Steve about these queries resulting with some kind of "semi-formalization" of the semantic of this additional parameter (Steve, correct me if I'm wrong, unfortunately I've failed to find the corresponding messages in my archive). For example, for the Corresponding_Parent_Declaration query (its definition is appended to this message), the semantic of the second "version" of the query may be expressed in Ada pseudo-code as: function Corresponding_Parent_Declaration (Library_Unit : in Asis.Compilation_Unit; The_Context : in Asis.Context) return Asis.Compilation_Unit is begin if Is_Identical (Enclosing_Context (Library_Unit), The_Context) then -- no difference with the "first version" of -- Corresponding_Parent_Declaration, therefore return Corresponding_Parent_Declaration (Library_Unit); else if (there exists a unit Library_Unit_1 in the context The_Context such that Is_Equal (Library_Unit_1, Library_Unit) then return Corresponding_Parent_Declaration (Library_Unit_1); else return Nil_Compilation_Unit; end if; end if; end Corresponding_Parent_Declaration; Now let's consider some example of a query working on Elements and having a Context as an additional parameter: ------------------------------------------------------------------------------ -- Section 15.13 function Corresponding_Type_Declaration ------------------------------------------------------------------------------ function Corresponding_Type_Declaration (Declaration : in Asis.Declaration) return Asis.Declaration; function Corresponding_Type_Declaration (Declaration : in Asis.Declaration; The_Context : in Asis.Context) return Asis.Declaration; ------------------------------------------------------------------------------ -- Declaration - Specifies the type declaration to query -- The_Context - Specifies the program Context to use for obtaining package -- body information -- -- Returns the corresponding full type declaration when given a private or -- incomplete type declaration. Returns the corresponding private or -- incomplete type declaration when given a full type declaration. -- -- These two function calls will always produce identical results: -- -- Decl2 := Corresponding_Type_Declaration( Decl1 ); -- Decl2 := Corresponding_Type_Declaration -- ( Decl1, -- Enclosing_Context( Enclosing_Compilation_Unit( Decl1 ))); -- -- Returns a Nil_Element when a full type declaration is given that has no -- corresponding private or incomplete type declaration, or when a -- corresponding type declaration does not exist within The_Context. -- -- The parameter The_Context is used whenever the corresponding full type of -- an incomplete type is in a corresponding package body. See RM 95 3.10.1(3). -- Any non-Nil result will always have the given Context as its -- Enclosing_Context. -- -- Appropriate Declaration_Kinds: -- An_Ordinary_Type_Declaration -- A_Task_Type_Declaration -- A_Protected_Type_Declaration -- An_Incomplete_Type_Declaration -- A_Private_Type_Declaration -- A_Private_Extension_Declaration -- -- Returns Declaration_Kinds: -- Not_A_Declaration -- An_Ordinary_Type_Declaration -- A_Task_Type_Declaration -- A_Protected_Type_Declaration -- An_Incomplete_Type_Declaration -- A_Private_Type_Declaration -- ------------------------------------------------------------------------------ First, I would say, that the definition of all the queries from Asis.Declarations, which have a Context as an additional parameter, is not very clear. Second, I would suggest the following interpretation of this query: function Corresponding_Type_Declaration (Declaration : in Asis.Declaration; The_Context : in Asis.Context) return Asis.Declaration is Arg_Enclosing_Context : Asis.Context := Enclosing_Context (Enclosing_Compilation_Unit (Declaration)); begin if Is_Identical (Arg_Enclosing_Context, The_Context) then -- no difference with the "first version" of -- Corresponding_Type_Declaration, therefore return Corresponding_Type_Declaration (Declaration); else if (there exists a unit Library_Unit_1 in the context The_Context such that Is_Equal (Library_Unit_1, Enclosing_Compilatin_Unit (Declaration)) and then (there exists an Element Declaration_1 in Library_Unit_1 such that Is_Equal (Declaration, Declaration_1) ) then return Corresponding_Type_Declaration (Declaration_1); else return Nil_Element; end if; end if; end Corresponding_Type_Declaration; And, the most important: if both these interpretations are correct (look reasonable), I would definitely say, that all the queries having a Context as an additional parameter are *SECONDARY QUERIES*, and as being secondary, they should be *MOVED* from the official ASIS definition into the corresponding ASIS secondary layer. I do not think, that something really important for applications would be lost, even if we would simply delete all these queries, but deleting these queries would definitely make ASIS more clear (and shorter, of course :-) Sergey Rybin. ------------------------------------------------------------------------------ -- Section 10.12 function Corresponding_Parent_Declaration ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ function Corresponding_Parent_Declaration (Library_Unit : in Asis.Compilation_Unit) return Asis.Compilation_Unit; function Corresponding_Parent_Declaration (Library_Unit : in Asis.Compilation_Unit; The_Context : in Asis.Context) return Asis.Compilation_Unit; ------------------------------------------------------------------------------ -- Library_Unit - Specifies the unit whose parent is desired -- The_Context - Specifies a program Context environment -- -- Returns the parent unit of the given library_unit. -- -- Returns a Nil_Compilation_Unit if the Library_Unit argument represents -- package Standard. Root Library_Unit arguments return the package Standard. -- -- Returns A_Nonexistent_Declaration when the Library_Unit has a -- parent_unit_name denoted in the defining_program_unit_name but the parent -- unit is not contained in The_Context. -- -- These two function calls will always produce identical results: -- -- Unit := Corresponding_Parent_Declaration( Unit ); -- Unit := Corresponding_Parent_Declaration( Unit, Enclosing_Context( Unit )); -- -- Any non-Nil result will have an Enclosing_Context value that Is_Identical -- to The_Context. -- -- The Enclosing_Context for any non-Nil result will always be The_Context, -- regardless of the Enclosing_Context value for the Library_Unit -- argument. This query is one means of obtaining (Is_Equal) parent units -- from separate ASIS Context values whose underlying implementations -- overlap. -- -- Appropriate Unit_Kinds: -- A_Procedure -- A_Function -- A_Package -- A_Generic_Procedure -- A_Generic_Function -- A_Generic_Package -- A_Procedure_Instance -- A_Function_Instance -- A_Package_Instance -- A_Procedure_Renaming -- A_Function_Renaming -- A_Package_Renaming -- A_Generic_Procedure_Renaming -- A_Generic_Function_Renaming -- A_Generic_Package_Renaming -- A_Procedure_Body -- A_Function_Body -- A_Package_Body -- -- Returns Unit_Kinds: -- Not_A_Unit -- A_Package -- A_Generic_Package -- A_Package_Instance -- A_Nonexistent_Declaration -- An_Unknown_Unit -- -- If a parent is inconsistent with a child passed as the argument, -- A_Nonexistent_Declaration should be returned. -- ------------------------------------------------------------------------------