1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Expand routines for chapter 3 constructs
28 with Types
; use Types
;
29 with Elists
; use Elists
;
30 with Uintp
; use Uintp
;
34 procedure Expand_N_Object_Declaration
(N
: Node_Id
);
35 procedure Expand_N_Subtype_Indication
(N
: Node_Id
);
36 procedure Expand_N_Variant_Part
(N
: Node_Id
);
37 procedure Expand_N_Full_Type_Declaration
(N
: Node_Id
);
39 procedure Expand_Previous_Access_Type
(Def_Id
: Entity_Id
);
40 -- For a full type declaration that contains tasks, or that is a task,
41 -- check whether there exists an access type whose designated type is an
42 -- incomplete declarations for the current composite type. If so, build the
43 -- master for that access type, now that it is known to denote an object
46 procedure Expand_Record_Extension
(T
: Entity_Id
; Def
: Node_Id
);
47 -- Add a field _parent in the extension part of the record
49 procedure Build_Access_Subprogram_Wrapper_Body
52 -- Build the wrapper body, which holds the indirect call through an access-
53 -- to-subprogram, and whose expansion incorporates the contracts of the
54 -- access type declaration. Called from Build_Access_Subprogram_Wrapper.
55 -- Building the wrapper is done during analysis to perform proper semantic
56 -- checks on the relevant aspects. The wrapper body could be simplified to
57 -- a null body when expansion is disabled ???
59 procedure Build_Discr_Checking_Funcs
(N
: Node_Id
);
60 -- Builds function which checks whether the component name is consistent
61 -- with the current discriminants. N is the full type declaration node,
62 -- and the discriminant checking functions are inserted after this node.
64 function Build_Initialization_Call
68 In_Init_Proc
: Boolean := False;
69 Enclos_Type
: Entity_Id
:= Empty
;
70 Discr_Map
: Elist_Id
:= New_Elmt_List
;
71 With_Default_Init
: Boolean := False;
72 Constructor_Ref
: Node_Id
:= Empty
) return List_Id
;
73 -- Builds a call to the initialization procedure for the base type of Typ,
74 -- passing it the object denoted by Id_Ref, plus additional parameters as
75 -- appropriate for the type (the _Master, for task types, for example).
76 -- Loc is the source location for the constructed tree. In_Init_Proc has
77 -- to be set to True when the call is itself in an init proc in order to
78 -- enable the use of discriminals. Enclos_Type is the enclosing type when
79 -- initializing a component in an outer init proc, and it is used for
80 -- various expansion cases including the case where Typ is a task type
81 -- which is an array component, the indexes of the enclosing type are
82 -- used to build the string that identifies each task at runtime.
84 -- Discr_Map is used to replace discriminants by their discriminals in
85 -- expressions used to constrain record components. In the presence of
86 -- entry families bounded by discriminants, protected type discriminants
87 -- can appear within expressions in array bounds (not as stand-alone
88 -- identifiers) and a general replacement is necessary.
90 -- Ada 2005 (AI-287): With_Default_Init is used to indicate that the
91 -- initialization call corresponds to a default initialized component
94 -- Constructor_Ref is a call to a constructor subprogram. It is currently
95 -- used only to support C++ constructors.
97 function Build_Variant_Record_Equality
100 Param_Specs
: List_Id
) return Node_Id
;
101 -- Build the body of the equality function Body_Id for the untagged variant
102 -- record Typ with the given parameters specification list.
104 procedure Ensure_Activation_Chain_And_Master
(Obj_Decl
: Node_Id
);
105 -- If tasks are being declared (or might be declared) by the given object
106 -- declaration then ensure to have an activation chain defined for the
107 -- tasks (has no effect if we already have one), and also that a Master
108 -- variable is established (and that the appropriate enclosing construct
109 -- is established as a task master).
111 function Freeze_Type
(N
: Node_Id
) return Boolean;
112 -- This function executes the freezing actions associated with the given
113 -- freeze type node N and returns True if the node is to be deleted. We
114 -- delete the node if it is present just for front end purpose and we don't
115 -- want Gigi to see the node. This function can't delete the node itself
116 -- since it would confuse any remaining processing of the freeze node.
118 function Get_Simple_Init_Val
121 Size
: Uint
:= No_Uint
) return Node_Id
;
122 -- Build an expression that represents the required initial value of type
123 -- Typ for which predicate Needs_Simple_Initialization is True. N is a node
124 -- whose source location is used in the construction of the expression.
125 -- Size is used as follows:
127 -- * If the size of the object to be initialized it is known, it should
128 -- be passed to the routine.
130 -- * If the size is unknown or is zero, then the Esize of Typ is used as
131 -- an estimate of the size.
133 -- The object size is needed to prepare a known invalid value for use by
134 -- Normalize_Scalars. A call to this routine where Typ denotes a scalar
135 -- type is valid only when Normalize_Scalars or Initialize_Scalars is
136 -- active, or if N is the node for a 'Invalid_Value attribute node.
138 function Init_Proc_Level_Formal
(Proc
: Entity_Id
) return Entity_Id
;
139 -- Fetch the extra formal from an initalization procedure "proc"
140 -- corresponding to the level of the object being initialized. When none
141 -- is present Empty is returned.
143 procedure Init_Secondary_Tags
146 Init_Tags_List
: List_Id
;
147 Stmts_List
: List_Id
;
148 Fixed_Comps
: Boolean := True;
149 Variable_Comps
: Boolean := True);
150 -- Ada 2005 (AI-251): Initialize the tags of the secondary dispatch tables
151 -- of Typ. The generated code referencing tag fields of Target is appended
152 -- to Init_Tags_List and the code required to complete the elaboration of
153 -- the dispatch tables of Typ is appended to Stmts_List. If Fixed_Comps is
154 -- True then the tag components located at fixed positions of Target are
155 -- initialized; if Variable_Comps is True then tags components located at
156 -- variable positions of Target are initialized.
158 function Make_Tag_Assignment
(N
: Node_Id
) return Node_Id
;
159 -- An object declaration that has an initialization for a tagged object
160 -- requires a separate reassignment of the tag of the given type, because
161 -- the expression may include an unchecked conversion. This tag assignment
162 -- is inserted after the declaration, but if the object has an address
163 -- clause the assignment is handled as part of the freezing of the object,
164 -- see Check_Address_Clause.