PageRenderTime 26ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/gcc/ada/exp_ch6.ads

https://bitbucket.org/codefirex/toolchain_gcc-4.9
Ada | 250 lines | 61 code | 33 blank | 156 comment | 0 complexity | 2aa5880aca0d74aeffaf80565313c266 MD5 | raw file
  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-2013, 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. -- Expand routines for chapter 6 constructs
  26. with Types; use Types;
  27. package Exp_Ch6 is
  28. procedure Expand_N_Extended_Return_Statement (N : Node_Id);
  29. procedure Expand_N_Function_Call (N : Node_Id);
  30. procedure Expand_N_Procedure_Call_Statement (N : Node_Id);
  31. procedure Expand_N_Simple_Return_Statement (N : Node_Id);
  32. procedure Expand_N_Subprogram_Body (N : Node_Id);
  33. procedure Expand_N_Subprogram_Body_Stub (N : Node_Id);
  34. procedure Expand_N_Subprogram_Declaration (N : Node_Id);
  35. procedure Expand_Actuals (N : Node_Id; Subp : Entity_Id);
  36. -- For each actual of an in-out or out parameter which is a numeric
  37. -- (view) conversion of the form T (A), where A denotes a variable,
  38. -- we insert the declaration:
  39. --
  40. -- Temp : T[ := T (A)];
  41. --
  42. -- prior to the call. Then we replace the actual with a reference to Temp,
  43. -- and append the assignment:
  44. --
  45. -- A := TypeA (Temp);
  46. --
  47. -- after the call. Here TypeA is the actual type of variable A. For out
  48. -- parameters, the initial declaration has no expression. If A is not an
  49. -- entity name, we generate instead:
  50. --
  51. -- Var : TypeA renames A;
  52. -- Temp : T := Var; -- omitting expression for out parameter.
  53. -- ...
  54. -- Var := TypeA (Temp);
  55. --
  56. -- For other in-out parameters, we emit the required constraint checks
  57. -- before and/or after the call.
  58. --
  59. -- For all parameter modes, actuals that denote components and slices of
  60. -- packed arrays are expanded into suitable temporaries.
  61. --
  62. -- For non-scalar objects that are possibly unaligned, add call by copy
  63. -- code (copy in for IN and IN OUT, copy out for OUT and IN OUT).
  64. procedure Expand_Call (N : Node_Id);
  65. -- This procedure contains common processing for Expand_N_Function_Call,
  66. -- Expand_N_Procedure_Statement, and Expand_N_Entry_Call.
  67. procedure Expand_Contract_Cases
  68. (CCs : Node_Id;
  69. Subp_Id : Entity_Id;
  70. Decls : List_Id;
  71. Stmts : in out List_Id);
  72. -- Given pragma Contract_Cases CCs, create the circuitry needed to evaluate
  73. -- case guards and trigger consequence expressions. Subp_Id is the related
  74. -- subprogram for which the pragma applies. Decls are the declarations of
  75. -- Subp_Id's body. All generated code is added to list Stmts. If Stmts is
  76. -- empty, a new list is created.
  77. procedure Freeze_Subprogram (N : Node_Id);
  78. -- generate the appropriate expansions related to Subprogram freeze
  79. -- nodes (e.g. the filling of the corresponding Dispatch Table for
  80. -- Primitive Operations)
  81. -- The following type defines the various forms of allocation used for the
  82. -- results of build-in-place function calls.
  83. type BIP_Allocation_Form is
  84. (Unspecified,
  85. Caller_Allocation,
  86. Secondary_Stack,
  87. Global_Heap,
  88. User_Storage_Pool);
  89. type BIP_Formal_Kind is
  90. -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
  91. -- formals created for build-in-place functions. The order of these
  92. -- enumeration literals matches the order in which the formals are
  93. -- declared. See Sem_Ch6.Create_Extra_Formals.
  94. (BIP_Alloc_Form,
  95. -- Present if result subtype is unconstrained or tagged. Indicates
  96. -- whether the return object is allocated by the caller or callee, and
  97. -- if the callee, whether to use the secondary stack or the heap. See
  98. -- Create_Extra_Formals.
  99. BIP_Storage_Pool,
  100. -- Present if result subtype is unconstrained or tagged. If
  101. -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
  102. -- (of type access to Root_Storage_Pool'Class). Otherwise null.
  103. BIP_Finalization_Master,
  104. -- Present if result type needs finalization. Pointer to caller's
  105. -- finalization master.
  106. BIP_Task_Master,
  107. -- Present if result type contains tasks. Master associated with
  108. -- calling context.
  109. BIP_Activation_Chain,
  110. -- Present if result type contains tasks. Caller's activation chain
  111. BIP_Object_Access);
  112. -- Present for all build-in-place functions. Address at which to place
  113. -- the return object, or null if BIP_Alloc_Form indicates allocated by
  114. -- callee.
  115. --
  116. -- ??? We might also need to be able to pass in a constrained flag.
  117. function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
  118. -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
  119. -- for build-in-place formal parameters of the given kind.
  120. function Build_In_Place_Formal
  121. (Func : Entity_Id;
  122. Kind : BIP_Formal_Kind) return Entity_Id;
  123. -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
  124. -- build-in-place formal parameter of the given kind associated with the
  125. -- function Func, and returns its Entity_Id. It is a bug if not found; the
  126. -- caller should ensure this is called only when the extra formal exists.
  127. function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
  128. -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
  129. -- function, or access-to-function type whose result must be built in
  130. -- place; otherwise returns False. For Ada 2005, this is currently
  131. -- restricted to the set of functions whose result subtype is an inherently
  132. -- limited type. In Ada 95, this must be False for inherently limited
  133. -- result types (but currently returns False for all Ada 95 functions).
  134. -- Eventually we plan to support build-in-place for nonlimited types.
  135. -- Build-in-place is usually more efficient for large things, and less
  136. -- efficient for small things. However, we never use build-in-place if the
  137. -- convention is other than Ada, because that would disturb mixed-language
  138. -- programs. Note that for the non-inherently-limited cases, we must make
  139. -- the same decision for Ada 95 and 2005, so that mixed-dialect programs
  140. -- will work.
  141. function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
  142. -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
  143. -- that requires handling as a build-in-place call or is a qualified
  144. -- expression applied to such a call; otherwise returns False.
  145. function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
  146. -- Predicate to recognize stubbed procedures and null procedures, which
  147. -- can be inlined unconditionally in all cases.
  148. procedure List_Inlining_Info;
  149. -- Generate listing of calls inlined by the frontend plus listing of
  150. -- calls to inline subprograms passed to the backend.
  151. procedure Make_Build_In_Place_Call_In_Allocator
  152. (Allocator : Node_Id;
  153. Function_Call : Node_Id);
  154. -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
  155. -- occurs as the expression initializing an allocator, by passing access
  156. -- to the allocated object as an additional parameter of the function call.
  157. -- A new access object is declared that is initialized to the result of the
  158. -- allocator, passed to the function, and the allocator is rewritten to
  159. -- refer to that access object. Function_Call must denote either an
  160. -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
  161. -- an N_Qualified_Expression node applied to such a function call.
  162. procedure Make_Build_In_Place_Call_In_Anonymous_Context
  163. (Function_Call : Node_Id);
  164. -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
  165. -- occurs in a context that does not provide a separate object. A temporary
  166. -- object is created to act as the return object and an access to the
  167. -- temporary is passed as an additional parameter of the call. This occurs
  168. -- in contexts such as subprogram call actuals and object renamings.
  169. -- Function_Call must denote either an N_Function_Call node for which
  170. -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
  171. -- applied to such a function call.
  172. procedure Make_Build_In_Place_Call_In_Assignment
  173. (Assign : Node_Id;
  174. Function_Call : Node_Id);
  175. -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
  176. -- occurs as the right-hand side of an assignment statement by passing
  177. -- access to the left-hand side as an additional parameter of the function
  178. -- call. Assign must denote a N_Assignment_Statement. Function_Call must
  179. -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
  180. -- is True, or an N_Qualified_Expression node applied to such a function
  181. -- call.
  182. procedure Make_Build_In_Place_Call_In_Object_Declaration
  183. (Object_Decl : Node_Id;
  184. Function_Call : Node_Id);
  185. -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
  186. -- occurs as the expression initializing an object declaration by
  187. -- passing access to the declared object as an additional parameter of the
  188. -- function call. Function_Call must denote either an N_Function_Call node
  189. -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
  190. -- node applied to such a function call.
  191. procedure Make_CPP_Constructor_Call_In_Allocator
  192. (Allocator : Node_Id;
  193. Function_Call : Node_Id);
  194. -- Handle a call to a CPP constructor that occurs as the expression that
  195. -- initializes an allocator, by passing access to the allocated object as
  196. -- an additional parameter of the constructor call. A new access object is
  197. -- declared that is initialized to the result of the allocator, passed to
  198. -- the constructor, and the allocator is rewritten to refer to that access
  199. -- object. Function_Call must denote a call to a CPP_Constructor function.
  200. function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
  201. -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
  202. -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
  203. function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
  204. -- Ada 2005 (AI-318-02): Return True if the result subtype of function
  205. -- Func_Id needs finalization actions.
  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. procedure Add_Extra_Actual_To_Call
  212. (Subprogram_Call : Node_Id;
  213. Extra_Formal : Entity_Id;
  214. Extra_Actual : Node_Id);
  215. -- Adds Extra_Actual as a named parameter association for the formal
  216. -- Extra_Formal in Subprogram_Call.
  217. end Exp_Ch6;