File : exp_ch6.ads


   1 ------------------------------------------------------------------------------
   2 --                                                                          --
   3 --                         GNAT COMPILER COMPONENTS                         --
   4 --                                                                          --
   5 --                              E X P _ C H 6                               --
   6 --                                                                          --
   7 --                                 S p e c                                  --
   8 --                                                                          --
   9 --          Copyright (C) 1992-2016, Free Software Foundation, Inc.         --
  10 --                                                                          --
  11 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  12 -- terms of the  GNU General Public License as published  by the Free Soft- --
  13 -- ware  Foundation;  either version 3,  or (at your option) any later ver- --
  14 -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  15 -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  16 -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  17 -- for  more details.  You should have  received  a copy of the GNU General --
  18 -- Public License  distributed with GNAT; see file COPYING3.  If not, go to --
  19 -- http://www.gnu.org/licenses for a complete copy of the license.          --
  20 --                                                                          --
  21 -- GNAT was originally developed  by the GNAT team at  New York University. --
  22 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
  23 --                                                                          --
  24 ------------------------------------------------------------------------------
  25 
  26 --  Expand routines for chapter 6 constructs
  27 
  28 with Types; use Types;
  29 
  30 package Exp_Ch6 is
  31 
  32    procedure Expand_N_Extended_Return_Statement (N : Node_Id);
  33    procedure Expand_N_Function_Call             (N : Node_Id);
  34    procedure Expand_N_Procedure_Call_Statement  (N : Node_Id);
  35    procedure Expand_N_Simple_Return_Statement   (N : Node_Id);
  36    procedure Expand_N_Subprogram_Body           (N : Node_Id);
  37    procedure Expand_N_Subprogram_Body_Stub      (N : Node_Id);
  38    procedure Expand_N_Subprogram_Declaration    (N : Node_Id);
  39 
  40    procedure Expand_Call (N : Node_Id);
  41    --  This procedure contains common processing for Expand_N_Function_Call,
  42    --  Expand_N_Procedure_Statement, and Expand_N_Entry_Call.
  43 
  44    procedure Freeze_Subprogram (N : Node_Id);
  45    --  generate the appropriate expansions related to Subprogram freeze
  46    --  nodes (e.g. the filling of the corresponding Dispatch Table for
  47    --  Primitive Operations)
  48 
  49    --  The following type defines the various forms of allocation used for the
  50    --  results of build-in-place function calls.
  51 
  52    type BIP_Allocation_Form is
  53      (Unspecified,
  54       Caller_Allocation,
  55       Secondary_Stack,
  56       Global_Heap,
  57       User_Storage_Pool);
  58 
  59    type BIP_Formal_Kind is
  60    --  Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
  61    --  formals created for build-in-place functions. The order of these
  62    --  enumeration literals matches the order in which the formals are
  63    --  declared. See Sem_Ch6.Create_Extra_Formals.
  64 
  65      (BIP_Alloc_Form,
  66       --  Present if result subtype is unconstrained or tagged. Indicates
  67       --  whether the return object is allocated by the caller or callee, and
  68       --  if the callee, whether to use the secondary stack or the heap. See
  69       --  Create_Extra_Formals.
  70 
  71       BIP_Storage_Pool,
  72       --  Present if result subtype is unconstrained or tagged. If
  73       --  BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
  74       --  (of type access to Root_Storage_Pool'Class). Otherwise null.
  75 
  76       BIP_Finalization_Master,
  77       --  Present if result type needs finalization. Pointer to caller's
  78       --  finalization master.
  79 
  80       BIP_Task_Master,
  81       --  Present if result type contains tasks. Master associated with
  82       --  calling context.
  83 
  84       BIP_Activation_Chain,
  85       --  Present if result type contains tasks. Caller's activation chain
  86 
  87       BIP_Object_Access);
  88       --  Present for all build-in-place functions. Address at which to place
  89       --  the return object, or null if BIP_Alloc_Form indicates allocated by
  90       --  callee.
  91       --
  92       --  ??? We might also need to be able to pass in a constrained flag.
  93 
  94    procedure Add_Extra_Actual_To_Call
  95      (Subprogram_Call : Node_Id;
  96       Extra_Formal    : Entity_Id;
  97       Extra_Actual    : Node_Id);
  98    --  Adds Extra_Actual as a named parameter association for the formal
  99    --  Extra_Formal in Subprogram_Call.
 100 
 101    function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
 102    --  Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
 103    --  for build-in-place formal parameters of the given kind.
 104 
 105    function Build_In_Place_Formal
 106      (Func : Entity_Id;
 107       Kind : BIP_Formal_Kind) return Entity_Id;
 108    --  Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
 109    --  build-in-place formal parameter of the given kind associated with the
 110    --  function Func, and returns its Entity_Id. It is a bug if not found; the
 111    --  caller should ensure this is called only when the extra formal exists.
 112 
 113    function Build_Procedure_Body_Form
 114      (Func_Id : Entity_Id; Func_Body : Node_Id) return Node_Id;
 115    --  Create a procedure body which emulates the behavior of function Func_Id.
 116    --  Func_Body is the root of the body of the function before its analysis.
 117    --  The returned node is the root of the procedure body which will replace
 118    --  the original function body, which is not needed for the C program.
 119 
 120    function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
 121    --  Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
 122    --  function, or access-to-function type whose result must be built in
 123    --  place; otherwise returns False. For Ada 2005, this is currently
 124    --  restricted to the set of functions whose result subtype is an inherently
 125    --  limited type. In Ada 95, this must be False for inherently limited
 126    --  result types (but currently returns False for all Ada 95 functions).
 127    --  Eventually we plan to support build-in-place for nonlimited types.
 128    --  Build-in-place is usually more efficient for large things, and less
 129    --  efficient for small things. However, we never use build-in-place if the
 130    --  convention is other than Ada, because that would disturb mixed-language
 131    --  programs. Note that for the non-inherently-limited cases, we must make
 132    --  the same decision for Ada 95 and 2005, so that mixed-dialect programs
 133    --  will work.
 134 
 135    function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
 136    --  Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
 137    --  that requires handling as a build-in-place call or is a qualified
 138    --  expression applied to such a call; otherwise returns False.
 139 
 140    function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
 141    --  Predicate to recognize stubbed procedures and null procedures, which
 142    --  can be inlined unconditionally in all cases.
 143 
 144    procedure Make_Build_In_Place_Call_In_Allocator
 145      (Allocator     : Node_Id;
 146       Function_Call : Node_Id);
 147    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
 148    --  occurs as the expression initializing an allocator, by passing access
 149    --  to the allocated object as an additional parameter of the function call.
 150    --  A new access object is declared that is initialized to the result of the
 151    --  allocator, passed to the function, and the allocator is rewritten to
 152    --  refer to that access object. Function_Call must denote either an
 153    --  N_Function_Call node for which Is_Build_In_Place_Call is True, or else
 154    --  an N_Qualified_Expression node applied to such a function call.
 155 
 156    procedure Make_Build_In_Place_Call_In_Anonymous_Context
 157      (Function_Call : Node_Id);
 158    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
 159    --  occurs in a context that does not provide a separate object. A temporary
 160    --  object is created to act as the return object and an access to the
 161    --  temporary is passed as an additional parameter of the call. This occurs
 162    --  in contexts such as subprogram call actuals and object renamings.
 163    --  Function_Call must denote either an N_Function_Call node for which
 164    --  Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
 165    --  applied to such a function call.
 166 
 167    procedure Make_Build_In_Place_Call_In_Assignment
 168      (Assign        : Node_Id;
 169       Function_Call : Node_Id);
 170    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
 171    --  occurs as the right-hand side of an assignment statement by passing
 172    --  access to the left-hand side as an additional parameter of the function
 173    --  call. Assign must denote a N_Assignment_Statement. Function_Call must
 174    --  denote either an N_Function_Call node for which Is_Build_In_Place_Call
 175    --  is True, or an N_Qualified_Expression node applied to such a function
 176    --  call.
 177 
 178    procedure Make_Build_In_Place_Call_In_Object_Declaration
 179      (Obj_Decl      : Node_Id;
 180       Function_Call : Node_Id);
 181    --  Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
 182    --  occurs as the expression initializing an object declaration by
 183    --  passing access to the declared object as an additional parameter of the
 184    --  function call. Function_Call must denote either an N_Function_Call node
 185    --  for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
 186    --  node applied to such a function call.
 187 
 188    procedure Make_CPP_Constructor_Call_In_Allocator
 189      (Allocator     : Node_Id;
 190       Function_Call : Node_Id);
 191    --  Handle a call to a CPP constructor that occurs as the expression that
 192    --  initializes an allocator, by passing access to the allocated object as
 193    --  an additional parameter of the constructor call. A new access object is
 194    --  declared that is initialized to the result of the allocator, passed to
 195    --  the constructor, and the allocator is rewritten to refer to that access
 196    --  object. Function_Call must denote a call to a CPP_Constructor function.
 197 
 198    function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
 199    --  Ada 2005 (AI-318-02): Return True if the function needs an implicit
 200    --  BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
 201 
 202    function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
 203    --  Ada 2005 (AI-318-02): Return True if the result subtype of function
 204    --  Func_Id needs finalization actions.
 205 
 206    function Needs_Result_Accessibility_Level
 207      (Func_Id : Entity_Id) return Boolean;
 208    --  Ada 2012 (AI05-0234): Return True if the function needs an implicit
 209    --  parameter to identify the accessibility level of the function result
 210    --  "determined by the point of call".
 211 
 212 end Exp_Ch6;