annotate gcc/ada/sem_ch12.ads @ 131:84e7813d76e9

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