!ASIS Issue #065 !topic SHould Library_Unit_Declaration return the body of a library procedure? !reference ASIS 95-10.6, 10.8 !from Sergey Rybin !keywords Library_Unit_Declaration !discussion I've got the following question from Bill Thomas: > Another problem was that I was using testing this on a procedure, > and calling library_unit_declaration for a library level procedure > that does not have an expilict spec returned a Nil_Compilation_Unit. > When I created a spec, it worked OK. Am I correct that > Library_Unit_Declaration should return the body for a library level > procedure that does not have an explicit spec? This question has refreshed my own doubts concerning Library_Unit_Declaration, Library_Unit_Declarations and the case, when a library level procedure has no explicit separate spec. I am afraid, Bill and me are not the only two persons who are confused by this issue, so it would make sense to clarify it in ASIS. Moreover, why do these queries have no lists of returned unit kinds? May be, to add explicit returned lists would be the simplest way to fix this hole? My answer to Bill's question is appended: ------- This question gives the good reason to send a message to asis-comment. Some time ago I thought, that the answer should be "yes", but then I changed my mind, because of the following reasons: 1. the body for a library level procedure should be classified as A_Procedure_Body, whether or not a separate spec exist in the Context (library); 2. Asis.Compilation_Units says: ------------------------------------------------------------------------------ -- Section 10.6 function Library_Unit_Declaration ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ function Library_Unit_Declaration (Name : in String; The_Context : in Asis.Context) return Asis.Compilation_Unit; ------------------------------------------------------------------------------ -- Name - Specifies the defining program unit name -- The_Context - Specifies a program Context environment -- -- Returns the library_unit_declaration or library_unit_renaming_declaration -- with the name, contained in The_Context. -- -- A Nil_Compilation_Unit is returned if no such declaration exists. -- 3. RM95 10.1.1 defines the following syntax rules: Syntax 2 compilation ::= {compilation_unit} 3 compilation_unit ::= context_clause library_item | context_clause subunit 4 library_item ::= [private] library_unit_declaration | library_unit_body | [private] library_unit_renaming_declaration 5 library_unit_declaration ::= subprogram_declaration | package_declaration | generic_declaration | generic_instantiation Therefore, if the result of Library_Unit_Declaration should represent "library_unit_declaration or library_unit_renaming_declaration", this query should NOT return a body. But, from the other side, the Asis package contains somewhat confusing wording: ------------------------------------------------------------------------------ -- Section 3.14.1 type Unit_Kinds ------------------------------------------------------------------------------ -- ... type Unit_Kinds is ( ... A_Procedure_Body, -- A unit interpreted only as the completion -- of a procedure, or a unit interpreted as -- both the declaration and body of a library -- procedure. RM 95 10.1.4(4) A_Function_Body, -- A unit interpreted only as the completion -- of a function, or a unit interpreted as -- both the declaration and body of a library -- function. RM 95 10.1.4(4) I think I should send the text above to asis-comment, because the issue definitely needs clarification. My opinion still is that a body should not be returned, but this (or the opposite thing, if I'm wrong) should definitely be said explicitly in the ASIS definition. !resolution Accepted, with Modifications. !date 97-03-26 !Notes In the following queries: Subclause 10.6: function Library_Unit_Declaration (Name : in String; The_Context : in Asis.Context) return Asis.Compilation_Unit; Subclause 10.8: function Library_Unit_Declarations (Context : in Asis.Context) return Asis.Compilation_Unit_List; Subclause 9.5: function Library_Unit_Declarations (The_Container : in Container) return Asis.Compilation_Unit_List; The paragraph: -- This query will never return a unit with A_Configuration_Compilation or -- a Nonexistent unit kind. has been modified to be: -- This query will never return a unit with A_Configuration_Compilation or -- a Nonexistent unit kind. It will never return a unit with A_Procedure_Body -- or A_Function_Body unit kind even though the unit is interpreted as both -- the declaration and body of a library procedure or library function. -- RM 95 10.1.4(4) Changes made in ASIS version 2.0.M.