Fortran: fix passing of optional dummy as actual to optional argument [PR55978]
[official-gcc.git] / gcc / ada / exp_ch3.ads
bloba8018d8dff30a66f153d2715b18c38b26b473cc3
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E X P _ C H 3 --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2024, 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 3 constructs
28 with Elists; use Elists;
29 with Exp_Tss; use Exp_Tss;
30 with Types; use Types;
31 with Uintp; use Uintp;
33 package Exp_Ch3 is
35 procedure Expand_N_Object_Declaration (N : Node_Id);
36 procedure Expand_N_Subtype_Indication (N : Node_Id);
37 procedure Expand_N_Variant_Part (N : Node_Id);
38 procedure Expand_N_Full_Type_Declaration (N : Node_Id);
40 procedure Expand_Previous_Access_Type (Def_Id : Entity_Id);
41 -- For a full type declaration that contains tasks, or that is a task,
42 -- check whether there exists an access type whose designated type is an
43 -- incomplete declarations for the current composite type. If so, build the
44 -- master for that access type, now that it is known to denote an object
45 -- with tasks.
47 procedure Expand_Record_Extension (T : Entity_Id; Def : Node_Id);
48 -- Add a field _parent in the extension part of the record
50 procedure Build_Access_Subprogram_Wrapper_Body
51 (Decl : Node_Id;
52 New_Decl : Node_Id);
53 -- Build the wrapper body, which holds the indirect call through an access-
54 -- to-subprogram, and whose expansion incorporates the contracts of the
55 -- access type declaration. Called from Build_Access_Subprogram_Wrapper.
56 -- Building the wrapper is done during analysis to perform proper semantic
57 -- checks on the relevant aspects. The wrapper body could be simplified to
58 -- a null body when expansion is disabled ???
60 function Build_Default_Initialization
61 (N : Node_Id;
62 Typ : Entity_Id;
63 Obj_Id : Entity_Id;
64 For_CW : Boolean := False;
65 Target_Ref : Node_Id := Empty) return List_Id;
66 -- Build the code to default-initialize an object of Typ either declared
67 -- or allocated by node N if this is necessary. In the former case Obj_Id
68 -- is the entity for the object whereas, in the second case, Obj_Id is a
69 -- temporary generated to hold the result of the allocator. For_CW is set
70 -- to True in the second case if this result is of a class-wide type.
72 -- Target_Ref is only passed identically to Build_Initialization_Call, so
73 -- its description given for Build_Initialization_Call is also valid here.
75 function Build_Default_Simple_Initialization
76 (N : Node_Id;
77 Typ : Entity_Id;
78 Obj_Id : Entity_Id) return Node_Id;
79 -- Try to build an expression to default-initialize an object of Typ either
80 -- declared or allocated by node N if this is necessary. In the former case
81 -- Obj_Id is the entity for the object whereas, in the second case, it must
82 -- be set to Empty.
84 procedure Build_Or_Copy_Discr_Checking_Funcs (N : Node_Id);
85 -- For each variant component, builds a function that checks whether
86 -- the component name is consistent with the current discriminants
87 -- and sets the component's Dcheck_Function attribute to refer to it.
88 -- N is the full type declaration node; the discriminant checking
89 -- functions are inserted after this node.
90 -- In the case of a derived untagged type, copy the attributes that were
91 -- set for the components of the parent type onto the components of the
92 -- derived type; no new subprograms are constructed in this case.
94 function Build_Initialization_Call
95 (N : Node_Id;
96 Id_Ref : Node_Id;
97 Typ : Entity_Id;
98 In_Init_Proc : Boolean := False;
99 Enclos_Type : Entity_Id := Empty;
100 Target_Ref : Node_Id := Empty;
101 Discr_Map : Elist_Id := New_Elmt_List;
102 With_Default_Init : Boolean := False;
103 Constructor_Ref : Node_Id := Empty;
104 Init_Control_Actual : Entity_Id := Empty) return List_Id;
105 -- Builds a call to the initialization procedure for the base type of Typ,
106 -- passing it the object denoted by Id_Ref, plus additional parameters as
107 -- appropriate for the type (the _Master, for task types, for example).
108 -- N is the construct for which the call is to be built. In_Init_Proc has
109 -- to be set to True when the call is itself in an init proc in order to
110 -- enable the use of discriminals.
112 -- Enclos_Type is the enclosing type when initializing a component of a
113 -- composite type, and is used for the case where Typ is a task type of
114 -- an array component: the indices of this enclosing type are then used
115 -- to build the image string that identifies each task at run time.
117 -- Target_Ref is also used when Typ is a task type if the initialization
118 -- call is to be generated for an allocator. It is either the name of a
119 -- simple assignment whose expression is the allocator, or the defining
120 -- identifier of an object declaration whose initializing expression is
121 -- the allocator, or else the allocator's access type. It is used both
122 -- to build the image string and to pass the task master.
124 -- Discr_Map is used to replace discriminants by their discriminals in
125 -- expressions used to constrain record components. In the presence of
126 -- entry families bounded by discriminants, protected type discriminants
127 -- can appear within expressions in array bounds (not as stand-alone
128 -- identifiers) and a general replacement is necessary.
130 -- Ada 2005 (AI-287): With_Default_Init is used to indicate that the
131 -- initialization call corresponds to a default initialized component
132 -- of an aggregate.
134 -- Constructor_Ref is a call to a constructor subprogram. It is currently
135 -- used only to support C++ constructors.
137 -- Init_Control_Actual is Empty except in the case where the init proc
138 -- for a tagged type calls the init proc for its parent type in order
139 -- to initialize its _Parent component. In that case, it is the
140 -- actual parameter value corresponding to the Init_Control formal
141 -- parameter to be used in the call of the parent type's init proc.
143 function Build_Variant_Record_Equality
144 (Typ : Entity_Id;
145 Spec_Id : Entity_Id;
146 Body_Id : Entity_Id;
147 Param_Specs : List_Id) return Node_Id;
148 -- Build the body of the equality function Body_Id for the untagged variant
149 -- record Typ with the given parameters specification list. If Spec_Id is
150 -- present, the body is built for a renaming of the equality function.
152 function Freeze_Type (N : Node_Id) return Boolean;
153 -- This function executes the freezing actions associated with the given
154 -- freeze type node N and returns True if the node is to be deleted. We
155 -- delete the node if it is present just for front end purpose and we don't
156 -- want Gigi to see the node. This function can't delete the node itself
157 -- since it would confuse any remaining processing of the freeze node.
159 -- Note: for GNATprove we have a minimal variant of this routine in
160 -- Exp_SPARK.SPARK_Freeze_Type. They need to be kept in sync.
162 function Get_Simple_Init_Val
163 (Typ : Entity_Id;
164 N : Node_Id;
165 Size : Uint := No_Uint) return Node_Id;
166 -- Build an expression that represents the required initial value of type
167 -- Typ for which predicate Needs_Simple_Initialization is True. N is a node
168 -- whose source location is used in the construction of the expression.
169 -- Size is used as follows:
171 -- * If the size of the object to be initialized it is known, it should
172 -- be passed to the routine.
174 -- * If the size is unknown or is zero, then the Esize of Typ is used as
175 -- an estimate of the size.
177 -- The object size is needed to prepare a known invalid value for use by
178 -- Normalize_Scalars. A call to this routine where Typ denotes a scalar
179 -- type is valid only when Normalize_Scalars or Initialize_Scalars is
180 -- active, or if N is the node for a 'Invalid_Value attribute node.
182 procedure Init_Secondary_Tags
183 (Typ : Entity_Id;
184 Target : Node_Id;
185 Init_Tags_List : List_Id;
186 Stmts_List : List_Id;
187 Fixed_Comps : Boolean := True;
188 Variable_Comps : Boolean := True);
189 -- Ada 2005 (AI-251): Initialize the tags of the secondary dispatch tables
190 -- of Typ. The generated code referencing tag fields of Target is appended
191 -- to Init_Tags_List and the code required to complete the elaboration of
192 -- the dispatch tables of Typ is appended to Stmts_List. If Fixed_Comps is
193 -- True then the tag components located at fixed positions of Target are
194 -- initialized; if Variable_Comps is True then tags components located at
195 -- variable positions of Target are initialized.
197 procedure Make_Controlling_Function_Wrappers
198 (Tag_Typ : Entity_Id;
199 Decl_List : out List_Id;
200 Body_List : out List_Id);
201 -- Ada 2005 (AI-391): Makes specs and bodies for the wrapper functions
202 -- associated with inherited functions with controlling results which
203 -- are not overridden. The body of each wrapper function consists solely
204 -- of a return statement whose expression is an extension aggregate
205 -- invoking the inherited subprogram's parent subprogram and extended
206 -- with a null association list.
208 procedure Make_Predefined_Primitive_Eq_Spec
209 (Tag_Typ : Entity_Id;
210 Predef_List : List_Id;
211 Renamed_Eq : out Entity_Id);
212 -- Creates spec for the predefined equality on a tagged type Tag_Typ, if
213 -- required. If created, it will be appended to Predef_List.
215 -- The Parameter Renamed_Eq either returns the value Empty, or else
216 -- the defining unit name for the predefined equality function in the
217 -- case where the type has a primitive operation that is a renaming
218 -- of predefined equality (but only if there is also an overriding
219 -- user-defined equality function). The returned Renamed_Eq will be
220 -- passed to the corresponding parameter of Predefined_Primitive_Bodies.
222 function Make_Tag_Assignment (N : Node_Id) return Node_Id;
223 -- An object declaration that has an initialization for a tagged object
224 -- requires a separate reassignment of the tag of the given type, because
225 -- the expression may include an unchecked conversion. This tag assignment
226 -- is inserted after the declaration, but if the object has an address
227 -- clause the assignment is handled as part of the freezing of the object,
228 -- see Check_Address_Clause.
230 procedure Predefined_Primitive_Eq_Body
231 (Tag_Typ : Entity_Id;
232 Predef_List : List_Id;
233 Renamed_Eq : Entity_Id);
234 -- Creates body for the predefined equality (and ineqality, if required) on
235 -- a tagged type Tag_Typ. If created they will be appended to Predef_List.
237 -- The spec for the equality function has been created by
238 -- Make_Predefined_Primitive_Eq_Spec; see there for description of
239 -- the Renamed_Eq parameter.
241 function Stream_Operation_OK
242 (Typ : Entity_Id;
243 Operation : TSS_Name_Type) return Boolean;
244 -- Check whether the named stream operation must be emitted for a given
245 -- type. The rules for inheritance of stream attributes by type extensions
246 -- are enforced by this function. Furthermore, various restrictions prevent
247 -- the generation of these operations, as a useful optimization or for
248 -- certification purposes and to save unnecessary generated code.
250 end Exp_Ch3;