PR preprocessor/63831
[official-gcc.git] / gcc / ada / exp_ch6.ads
blob0c31ea6c3b4f06c722cc0f6eb023cfc5aae96cca
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-2014, 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 ------------------------------------------------------------------------------
26 -- Expand routines for chapter 6 constructs
28 with Types; use Types;
30 package Exp_Ch6 is
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);
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.
44 procedure Expand_Subprogram_Contract
45 (N : Node_Id;
46 Spec_Id : Entity_Id;
47 Body_Id : Entity_Id);
48 -- Expand the contracts of a subprogram body and its correspoding spec (if
49 -- any). This routine processes all [refined] pre- and postconditions as
50 -- well as Contract_Cases, invariants and predicates. N is the body of the
51 -- subprogram. Spec_Id denotes the entity of its specification. Body_Id
52 -- denotes the entity of the subprogram body. This routine is not a "pure"
53 -- expansion mechanism as it is invoked during analysis and may perform
54 -- actions for generic subprograms or set up contract assertions for ASIS.
56 procedure Freeze_Subprogram (N : Node_Id);
57 -- generate the appropriate expansions related to Subprogram freeze
58 -- nodes (e.g. the filling of the corresponding Dispatch Table for
59 -- Primitive Operations)
61 -- The following type defines the various forms of allocation used for the
62 -- results of build-in-place function calls.
64 type BIP_Allocation_Form is
65 (Unspecified,
66 Caller_Allocation,
67 Secondary_Stack,
68 Global_Heap,
69 User_Storage_Pool);
71 type BIP_Formal_Kind is
72 -- Ada 2005 (AI-318-02): This type defines the kinds of implicit extra
73 -- formals created for build-in-place functions. The order of these
74 -- enumeration literals matches the order in which the formals are
75 -- declared. See Sem_Ch6.Create_Extra_Formals.
77 (BIP_Alloc_Form,
78 -- Present if result subtype is unconstrained or tagged. Indicates
79 -- whether the return object is allocated by the caller or callee, and
80 -- if the callee, whether to use the secondary stack or the heap. See
81 -- Create_Extra_Formals.
83 BIP_Storage_Pool,
84 -- Present if result subtype is unconstrained or tagged. If
85 -- BIP_Alloc_Form = User_Storage_Pool, this is a pointer to the pool
86 -- (of type access to Root_Storage_Pool'Class). Otherwise null.
88 BIP_Finalization_Master,
89 -- Present if result type needs finalization. Pointer to caller's
90 -- finalization master.
92 BIP_Task_Master,
93 -- Present if result type contains tasks. Master associated with
94 -- calling context.
96 BIP_Activation_Chain,
97 -- Present if result type contains tasks. Caller's activation chain
99 BIP_Object_Access);
100 -- Present for all build-in-place functions. Address at which to place
101 -- the return object, or null if BIP_Alloc_Form indicates allocated by
102 -- callee.
104 -- ??? We might also need to be able to pass in a constrained flag.
106 function BIP_Formal_Suffix (Kind : BIP_Formal_Kind) return String;
107 -- Ada 2005 (AI-318-02): Returns a string to be used as the suffix of names
108 -- for build-in-place formal parameters of the given kind.
110 function Build_In_Place_Formal
111 (Func : Entity_Id;
112 Kind : BIP_Formal_Kind) return Entity_Id;
113 -- Ada 2005 (AI-318-02): Locates and returns the entity for the implicit
114 -- build-in-place formal parameter of the given kind associated with the
115 -- function Func, and returns its Entity_Id. It is a bug if not found; the
116 -- caller should ensure this is called only when the extra formal exists.
118 function Is_Build_In_Place_Function (E : Entity_Id) return Boolean;
119 -- Ada 2005 (AI-318-02): Returns True if E denotes a function, generic
120 -- function, or access-to-function type whose result must be built in
121 -- place; otherwise returns False. For Ada 2005, this is currently
122 -- restricted to the set of functions whose result subtype is an inherently
123 -- limited type. In Ada 95, this must be False for inherently limited
124 -- result types (but currently returns False for all Ada 95 functions).
125 -- Eventually we plan to support build-in-place for nonlimited types.
126 -- Build-in-place is usually more efficient for large things, and less
127 -- efficient for small things. However, we never use build-in-place if the
128 -- convention is other than Ada, because that would disturb mixed-language
129 -- programs. Note that for the non-inherently-limited cases, we must make
130 -- the same decision for Ada 95 and 2005, so that mixed-dialect programs
131 -- will work.
133 function Is_Build_In_Place_Function_Call (N : Node_Id) return Boolean;
134 -- Ada 2005 (AI-318-02): Returns True if N denotes a call to a function
135 -- that requires handling as a build-in-place call or is a qualified
136 -- expression applied to such a call; otherwise returns False.
138 function Is_Null_Procedure (Subp : Entity_Id) return Boolean;
139 -- Predicate to recognize stubbed procedures and null procedures, which
140 -- can be inlined unconditionally in all cases.
142 procedure Make_Build_In_Place_Call_In_Allocator
143 (Allocator : Node_Id;
144 Function_Call : Node_Id);
145 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
146 -- occurs as the expression initializing an allocator, by passing access
147 -- to the allocated object as an additional parameter of the function call.
148 -- A new access object is declared that is initialized to the result of the
149 -- allocator, passed to the function, and the allocator is rewritten to
150 -- refer to that access object. Function_Call must denote either an
151 -- N_Function_Call node for which Is_Build_In_Place_Call is True, or else
152 -- an N_Qualified_Expression node applied to such a function call.
154 procedure Make_Build_In_Place_Call_In_Anonymous_Context
155 (Function_Call : Node_Id);
156 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
157 -- occurs in a context that does not provide a separate object. A temporary
158 -- object is created to act as the return object and an access to the
159 -- temporary is passed as an additional parameter of the call. This occurs
160 -- in contexts such as subprogram call actuals and object renamings.
161 -- Function_Call must denote either an N_Function_Call node for which
162 -- Is_Build_In_Place_Call is True, or else an N_Qualified_Expression node
163 -- applied to such a function call.
165 procedure Make_Build_In_Place_Call_In_Assignment
166 (Assign : Node_Id;
167 Function_Call : Node_Id);
168 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
169 -- occurs as the right-hand side of an assignment statement by passing
170 -- access to the left-hand side as an additional parameter of the function
171 -- call. Assign must denote a N_Assignment_Statement. Function_Call must
172 -- denote either an N_Function_Call node for which Is_Build_In_Place_Call
173 -- is True, or an N_Qualified_Expression node applied to such a function
174 -- call.
176 procedure Make_Build_In_Place_Call_In_Object_Declaration
177 (Object_Decl : Node_Id;
178 Function_Call : Node_Id);
179 -- Ada 2005 (AI-318-02): Handle a call to a build-in-place function that
180 -- occurs as the expression initializing an object declaration by
181 -- passing access to the declared object as an additional parameter of the
182 -- function call. Function_Call must denote either an N_Function_Call node
183 -- for which Is_Build_In_Place_Call is True, or an N_Qualified_Expression
184 -- node applied to such a function call.
186 procedure Make_CPP_Constructor_Call_In_Allocator
187 (Allocator : Node_Id;
188 Function_Call : Node_Id);
189 -- Handle a call to a CPP constructor that occurs as the expression that
190 -- initializes an allocator, by passing access to the allocated object as
191 -- an additional parameter of the constructor call. A new access object is
192 -- declared that is initialized to the result of the allocator, passed to
193 -- the constructor, and the allocator is rewritten to refer to that access
194 -- object. Function_Call must denote a call to a CPP_Constructor function.
196 function Needs_BIP_Alloc_Form (Func_Id : Entity_Id) return Boolean;
197 -- Ada 2005 (AI-318-02): Return True if the function needs an implicit
198 -- BIP_Alloc_Form parameter (see type BIP_Formal_Kind).
200 function Needs_BIP_Finalization_Master (Func_Id : Entity_Id) return Boolean;
201 -- Ada 2005 (AI-318-02): Return True if the result subtype of function
202 -- Func_Id needs finalization actions.
204 function Needs_Result_Accessibility_Level
205 (Func_Id : Entity_Id) return Boolean;
206 -- Ada 2012 (AI05-0234): Return True if the function needs an implicit
207 -- parameter to identify the accessibility level of the function result
208 -- "determined by the point of call".
210 procedure Add_Extra_Actual_To_Call
211 (Subprogram_Call : Node_Id;
212 Extra_Formal : Entity_Id;
213 Extra_Actual : Node_Id);
214 -- Adds Extra_Actual as a named parameter association for the formal
215 -- Extra_Formal in Subprogram_Call.
217 end Exp_Ch6;