]>
Commit | Line | Data |
---|---|---|
996ae0b0 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- S E M _ C H 1 2 -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
1d005acc | 9 | -- Copyright (C) 1992-2019, Free Software Foundation, Inc. -- |
996ae0b0 RK |
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- -- | |
b5c84c3c | 13 | -- ware Foundation; either version 3, or (at your option) any later ver- -- |
996ae0b0 RK |
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 -- | |
b5c84c3c RD |
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. -- | |
996ae0b0 RK |
20 | -- -- |
21 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 22 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
996ae0b0 RK |
23 | -- -- |
24 | ------------------------------------------------------------------------------ | |
25 | ||
26 | with Inline; use Inline; | |
27 | with Types; use Types; | |
28 | ||
29 | package Sem_Ch12 is | |
30 | procedure Analyze_Generic_Package_Declaration (N : Node_Id); | |
31 | procedure Analyze_Generic_Subprogram_Declaration (N : Node_Id); | |
32 | procedure Analyze_Package_Instantiation (N : Node_Id); | |
33 | procedure Analyze_Procedure_Instantiation (N : Node_Id); | |
34 | procedure Analyze_Function_Instantiation (N : Node_Id); | |
35 | procedure Analyze_Formal_Object_Declaration (N : Node_Id); | |
36 | procedure Analyze_Formal_Type_Declaration (N : Node_Id); | |
0f1a6a0b AC |
37 | procedure Analyze_Formal_Subprogram_Declaration (N : Node_Id); |
38 | procedure Analyze_Formal_Package_Declaration (N : Node_Id); | |
996ae0b0 | 39 | |
948ed277 | 40 | function Build_Function_Wrapper |
fc6d9796 AC |
41 | (Formal_Subp : Entity_Id; |
42 | Actual_Subp : Entity_Id) return Node_Id; | |
948ed277 AC |
43 | -- In GNATprove mode, create a wrapper function for actuals that are |
44 | -- functions with any number of formal parameters, in order to propagate | |
45 | -- their contract to the renaming declarations generated for them. This | |
46 | -- is called after the renaming declaration created for the formal in the | |
47 | -- instance has been analyzed, and the actual is known. | |
48 | ||
49 | function Build_Operator_Wrapper | |
fc6d9796 AC |
50 | (Formal_Subp : Entity_Id; |
51 | Actual_Subp : Entity_Id) return Node_Id; | |
948ed277 AC |
52 | -- In GNATprove mode, create a wrapper function for actuals that are |
53 | -- operators, in order to propagate their contract to the renaming | |
fc6d9796 AC |
54 | -- declarations generated for them. The types are (the instances of) |
55 | -- the types of the formal subprogram. | |
948ed277 | 56 | |
996ae0b0 | 57 | procedure Start_Generic; |
04814dad | 58 | -- Must be invoked before starting to process a generic spec or body |
996ae0b0 RK |
59 | |
60 | procedure End_Generic; | |
61 | -- Must be invoked just at the end of the end of the processing of a | |
62 | -- generic spec or body. | |
63 | ||
64 | procedure Check_Generic_Child_Unit | |
65 | (Gen_Id : Node_Id; | |
66 | Parent_Installed : in out Boolean); | |
fb25a60d AC |
67 | -- If the name of the generic unit in an instantiation or a renaming is a |
68 | -- selected component, then the prefix may be an instance and the selector | |
69 | -- may designate a child unit. Retrieve the parent generic and search for | |
70 | -- the child unit that must be declared within. Similarly, if this is the | |
71 | -- name of a generic child unit within an instantiation of its own parent, | |
72 | -- retrieve the parent generic. If the parent is installed as a result of | |
308e6f3a | 73 | -- this call, then Parent_Installed is set True, otherwise Parent_Installed |
fb25a60d | 74 | -- is unchanged by the call. |
996ae0b0 RK |
75 | |
76 | function Copy_Generic_Node | |
77 | (N : Node_Id; | |
78 | Parent_Id : Node_Id; | |
1c0ce9d8 | 79 | Instantiating : Boolean) return Node_Id; |
996ae0b0 RK |
80 | -- Copy the tree for a generic unit or its body. The unit is copied |
81 | -- repeatedly: once to produce a copy on which semantic analysis of | |
82 | -- the generic is performed, and once for each instantiation. The tree | |
83 | -- being copied is not semantically analyzed, except that references to | |
718deaf1 AC |
84 | -- global entities are marked on terminal nodes. Note that this function |
85 | -- copies any aspect specifications from the input node N to the returned | |
86 | -- node, as well as the setting of the Has_Aspects flag. | |
996ae0b0 RK |
87 | |
88 | function Get_Instance_Of (A : Entity_Id) return Entity_Id; | |
89 | -- Retrieve actual associated with given generic parameter. | |
90 | -- If A is uninstantiated or not a generic parameter, return A. | |
91 | ||
ed323421 | 92 | function Get_Unit_Instantiation_Node (A : Entity_Id) return Node_Id; |
04814dad GD |
93 | -- Given the entity of a unit that is an instantiation, retrieve the |
94 | -- original instance node. This is used when loading the instantiations | |
95 | -- of the ancestors of a child generic that is being instantiated. | |
96 | ||
996ae0b0 | 97 | procedure Instantiate_Package_Body |
1c0ce9d8 ES |
98 | (Body_Info : Pending_Body_Info; |
99 | Inlined_Body : Boolean := False; | |
100 | Body_Optional : Boolean := False); | |
996ae0b0 | 101 | -- Called after semantic analysis, to complete the instantiation of |
fbf5a39b | 102 | -- package instances. The flag Inlined_Body is set if the body is |
fd22e260 | 103 | -- being instantiated on the fly for inlining purposes. |
1c0ce9d8 ES |
104 | -- |
105 | -- The flag Body_Optional indicates that the call is for an instance | |
106 | -- that precedes the current instance in the same declarative part. | |
107 | -- This call is needed when instantiating a nested generic whose body | |
108 | -- is to be found in the body of an instance. Normally we instantiate | |
109 | -- package bodies only when they appear in the main unit, or when their | |
110 | -- contents are needed for a nested generic G. If unit U contains several | |
111 | -- instances I1, I2, etc. and I2 contains a nested generic, then when U | |
112 | -- appears in the context of some other unit P that contains an instance | |
113 | -- of G, we compile the body of I2, but not that of I1. However, when we | |
114 | -- compile U as the main unit, we compile both bodies. This will lead to | |
fd22e260 | 115 | -- link-time errors if the compilation of I1 generates public symbols, |
87feba05 AC |
116 | -- because those in I2 will receive different names in both cases. This |
117 | -- forces us to analyze the body of I1 even when U is not the main unit. | |
118 | -- We don't want this additional mechanism to generate an error when the | |
119 | -- body of the generic for I1 is not present, and this is the reason for | |
120 | -- the presence of the flag Body_Optional, which is exchanged between the | |
121 | -- current procedure and Load_Parent_Of_Generic. | |
996ae0b0 RK |
122 | |
123 | procedure Instantiate_Subprogram_Body | |
45fc7ddb HK |
124 | (Body_Info : Pending_Body_Info; |
125 | Body_Optional : Boolean := False); | |
996ae0b0 | 126 | -- Called after semantic analysis, to complete the instantiation of |
45fc7ddb HK |
127 | -- function and procedure instances. The flag Body_Optional has the |
128 | -- same purpose as described for Instantiate_Package_Body. | |
996ae0b0 | 129 | |
cfb02ad1 AC |
130 | function Need_Subprogram_Instance_Body |
131 | (N : Node_Id; | |
132 | Subp : Entity_Id) return Boolean; | |
cfb02ad1 AC |
133 | -- If a subprogram instance is inlined, indicate that the body of it |
134 | -- must be created, to be used in inlined calls by the back-end. The | |
135 | -- subprogram may be inlined because the generic itself carries the | |
136 | -- pragma, or because a pragma appears for the instance in the scope. | |
137 | -- of the instance. | |
138 | ||
caf07df9 | 139 | procedure Save_Global_References (Templ : Node_Id); |
996ae0b0 | 140 | -- Traverse the original generic unit, and capture all references to |
caf07df9 AC |
141 | -- entities that are defined outside of the generic in the analyzed tree |
142 | -- for the template. These references are copied into the original tree, | |
143 | -- so that they appear automatically in every instantiation. A critical | |
144 | -- invariant in this approach is that if an id in the generic resolves to | |
145 | -- a local entity, the corresponding id in the instance will resolve to | |
146 | -- the homologous entity in the instance, even though the enclosing context | |
147 | -- for resolution is different, as long as the global references have been | |
148 | -- captured as described here. | |
996ae0b0 RK |
149 | |
150 | -- Because instantiations can be nested, the environment of the instance, | |
151 | -- involving the actuals and other data-structures, must be saved and | |
152 | -- restored in stack-like fashion. Front-end inlining also uses these | |
153 | -- structures for the management of private/full views. | |
154 | ||
879ac954 AC |
155 | procedure Save_Global_References_In_Aspects (N : Node_Id); |
156 | -- Save all global references found within the expressions of all aspects | |
157 | -- that appear on node N. | |
c9d70ab1 | 158 | |
fbf5a39b AC |
159 | procedure Set_Copied_Sloc_For_Inlined_Body (N : Node_Id; E : Entity_Id); |
160 | -- This procedure is used when a subprogram body is inlined. This process | |
161 | -- shares the same circuitry as the creation of an instantiated copy of | |
162 | -- a generic template. The call to this procedure establishes a new source | |
163 | -- file entry representing the inlined body as an instantiation, marked as | |
164 | -- an inlined body (so that errout can distinguish cases for generating | |
165 | -- error messages, otherwise the treatment is identical). In this call | |
166 | -- N is the subprogram body and E is the defining identifier of the | |
f3d57416 | 167 | -- subprogram in question. The resulting Sloc adjustment factor is |
fbf5a39b AC |
168 | -- saved as part of the internal state of the Sem_Ch12 package for use |
169 | -- in subsequent calls to copy nodes. | |
996ae0b0 | 170 | |
96df3ff4 AC |
171 | procedure Set_Copied_Sloc_For_Inherited_Pragma |
172 | (N : Node_Id; | |
173 | E : Entity_Id); | |
174 | -- This procedure is used when a class-wide pre- or postcondition is | |
175 | -- inherited. This process shares the same circuitry as the creation of | |
176 | -- an instantiated copy of a generic template. The call to this procedure | |
177 | -- establishes a new source file entry representing the inherited pragma | |
178 | -- as an instantiation, marked as an inherited pragma (so that errout can | |
179 | -- distinguish cases for generating error messages, otherwise the treatment | |
d4b56371 | 180 | -- is identical). In this call, N is the subprogram declaration from |
96df3ff4 | 181 | -- which the pragma is inherited and E is the defining identifier of |
d4b56371 | 182 | -- the overriding subprogram (when the subprogram is redefined) or the |
96df3ff4 AC |
183 | -- defining identifier of the extension type (when the subprogram is |
184 | -- inherited). The resulting Sloc adjustment factor is saved as part of the | |
185 | -- internal state of the Sem_Ch12 package for use in subsequent calls to | |
186 | -- copy nodes. | |
187 | ||
188 | procedure Adjust_Inherited_Pragma_Sloc (N : Node_Id); | |
189 | -- This procedure is used when a class-wide pre- or postcondition | |
190 | -- is inherited. It is called on each node of the pragma expression | |
191 | -- to adjust its sloc. These call should be preceded by a call to | |
192 | -- Set_Copied_Sloc_For_Inherited_Pragma that sets the required sloc | |
193 | -- adjustment. This is done directly, instead of using Copy_Generic_Node | |
194 | -- to copy nodes and adjust slocs, as Copy_Generic_Node expects a specific | |
195 | -- structure to be in place, which is not the case for inherited pragmas. | |
196 | ||
996ae0b0 RK |
197 | procedure Save_Env |
198 | (Gen_Unit : Entity_Id; | |
199 | Act_Unit : Entity_Id); | |
00332244 AC |
200 | -- Because instantiations can be nested, the compiler maintains a stack |
201 | -- of environments that holds variables relevant to the current instance: | |
202 | -- most importanty Instantiated_Parent, Exchanged_Views, Hidden_Entities, | |
203 | -- and others (see full list in Instance_Env). | |
996ae0b0 RK |
204 | |
205 | procedure Restore_Env; | |
00332244 AC |
206 | -- After processing an instantiation, or aborting one because of semantic |
207 | -- errors, remove the current Instantiation_Env from Instantation_Envs. | |
fbf5a39b AC |
208 | |
209 | procedure Initialize; | |
210 | -- Initializes internal data structures | |
996ae0b0 | 211 | |
097fdf65 ES |
212 | procedure Check_Private_View (N : Node_Id); |
213 | -- Check whether the type of a generic entity has a different view between | |
214 | -- the point of generic analysis and the point of instantiation. If the | |
215 | -- view has changed, then at the point of instantiation we restore the | |
216 | -- correct view to perform semantic analysis of the instance, and reset | |
217 | -- the current view after instantiation. The processing is driven by the | |
218 | -- current private status of the type of the node, and Has_Private_View, | |
219 | -- a flag that is set at the point of generic compilation. If view and | |
220 | -- flag are inconsistent then the type is updated appropriately. | |
221 | -- | |
222 | -- This subprogram is used in Check_Generic_Actuals and Copy_Generic_Node, | |
223 | -- and is exported here for the purpose of front-end inlining (see Exp_Ch6. | |
224 | -- Expand_Inlined_Call.Process_Formals). | |
225 | ||
996ae0b0 | 226 | end Sem_Ch12; |