!ASIS Issue #081 !topic recursive calls of generic subprograms !reference ASIS 95- 17.29, 18.25 !from Sergey Rybin 97-08-20 !keywords generic recursive subprogram !discussion What should be returned by Corresponding_Called_Function/Correponding_Called_Entity in case of a recursive subprogram call in the body of a generic recursive subprogram: generic function Factorial (I : Integer) return Integer; function Factorial (I : Integer) return Integer is begin if I = 1 then return 1; else return I * Factorial (I - 1); -- ^^^^^^^^^^^^^^^^^^ ?????? end if; end Factorial; The only reasonable thing to return is the declaration of the generic function Factorial, but Corresponding_Called_Function does not have A_Generic_Function_Declaration in the list of returned kinds. SUGGESTION : A_Generic_Function_Declaration should be added to the list of the ---------- returned Element kinds for Corresponding_Called_Function, and A_Generic_Procedure_Declaration should be added to the list of the returned Element kinds for Corresponding_Called_Function to make it possible to process (recursive) calls of the recursive generic subprograms in generic bodies. --------------------------------------------------------------------------- --------------------------------------------------------------------------------------- -- 17.29 function Corresponding_Called_Function --------------------------------------------------------------------------------------- function Corresponding_Called_Function (Expression : in Asis.Expression) return Asis.Declaration; --------------------------------------------------------------------------------------- -- Expression - Specifies the function_call to query -- -- Returns the declaration of the called function. -- -- Returns a Nil_Element if the: -- -- - function_prefix denotes a predefined operator for which the implementation -- does not provide an artificial function declaration, -- -- - prefix of the call denotes an access to a function implicit or explicit -- dereference, -- -- - argument is a dispatching call. -- -- If function_prefix denotes an attribute_reference, and if the corresponding -- attribute is (re)defined by an attribute definition clause, an implementation -- is encouraged, but not required, to return the definition of the corresponding -- subprogram whose name is used after "use" in this attribute definition -- clause. If an implementation cannot return such a subprogram definition, a -- Nil_Element should be returned. For an attribute reference which is not -- (re)defined by an attribute definition clause, a Nil_Element should be returned. -- -- Appropriate Expression_Kinds: -- A_Function_Call -- -- Returns Declaration_Kinds: -- Not_A_Declaration -- A_Function_Declaration -- A_Function_Body_Declaration -- A_Function_Body_Stub -- A_Function_Renaming_Declaration -- A_Function_Instantiation -- A_Formal_Function_Declaration -- --|IP Implementation Permissions: --|IP --|IP An implementation can choose whether or not to construct and provide --|IP artificial implicit declarations for predefined operators. -- --------------------------------------------------------------------------------------- -- 18.25 function Corresponding_Called_Entity --------------------------------------------------------------------------------------- function Corresponding_Called_Entity (Statement : in Asis.Statement) return Asis.Declaration; --------------------------------------------------------------------------------------- -- Statement - Specifies the procedure_call_statement or -- entry_call_statement to query -- -- Returns the declaration of the procedure or entry denoted by the call. -- -- Returns a Nil_Element if the: -- -- - prefix of the call denotes an access to a procedure implicit -- or explicit dereference, -- -- - argument is a dispatching call, -- -- - argument is a call to a dispatching operation of a tagged type which -- is not statically determined. -- -- If procedure_prefix denotes an attribute_reference, and if the corresponding -- attribute is (re)defined by an attribute definition clause, an implementation -- is encouraged, but not required, to return the definition of the corresponding -- subprogram whose name is used after "use" in this attribute definition -- clause. If an implementation cannot return such a subprogram definition, a -- Nil_Element should be returned. For an attribute reference which is not -- (re)defined by an attribute definition clause, a Nil_Element should be returned. -- -- Appropriate Statement_Kinds: -- An_Entry_Call_Statement -- A_Procedure_Call_Statement -- -- Returns Declaration_Kinds: -- Not_A_Declaration -- A_Procedure_Declaration -- A_Procedure_Body_Declaration -- A_Procedure_Body_Stub -- A_Procedure_Renaming_Declaration -- A_Procedure_Instantiation -- A_Formal_Procedure_Declaration -- An_Entry_Declaration -- --------------------------------------------------------------------------------------- Consider the following example of the recursive call of a generic subprogram in the generic body: procedure Test is generic type Int is range <>; function Factorial (N : Int) return Int; function Factorial (N : Int) return Int is begin if N < 0 then raise Constraint_Error; elsif N = 0 then return 1; else return N * Factorial (N-1); -- ^^^^^^^^^^^^^^^ <- Corresponding_Called_Function ?? end if; end Factorial; begin null; end Test; The question is - what should be returned by the call to Corresponding_Called_Function, if its argument is the recursive call to a function declared by generic function declaration? (The corresponding function is treated as an instance in the generic body, but it does not help in case of ASIS - we have neither A_Generic_Function_Declaration in the list of returned kinds for Corresponding_Called_Function, nor an A_Function_Declaration Element in this Compilation Unit. This shows, that there is a hole in the definition of Corresponding_Called_Function/Corresponding_Called_Entity in case of recursive calls in generic bodies. I would suggest to add A_Generic_Function_Declaration/A_Generic_Procedure_Declaration to the lists of the returned kinds (with corresponding comments in the documentation) to fix this hole. !resolution Accepted. !date 97-08-25 !Notes A_Generic_Function_Declaration was added to the returned Declaration_Kinds to clause 17.29 Corresponding_Called_Function. A_Generic_Procedure_Declaration was added to the returned Declaration_Kinds to clause 18.25 Corresponding_Called_Entity. Changes were made in version 2.0.P.