annotate gcc/ada/sem_ch7.adb @ 144:8f4e72ab4e11

fix segmentation fault caused by nothing next cur_op to end
author Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 21:23:56 +0900
parents 84e7813d76e9
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 7 --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
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 -- This package contains the routines to process package specifications and
kono
parents:
diff changeset
27 -- bodies. The most important semantic aspects of package processing are the
kono
parents:
diff changeset
28 -- handling of private and full declarations, and the construction of dispatch
kono
parents:
diff changeset
29 -- tables for tagged types.
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 with Aspects; use Aspects;
kono
parents:
diff changeset
32 with Atree; use Atree;
kono
parents:
diff changeset
33 with Contracts; use Contracts;
kono
parents:
diff changeset
34 with Debug; use Debug;
kono
parents:
diff changeset
35 with Einfo; use Einfo;
kono
parents:
diff changeset
36 with Elists; use Elists;
kono
parents:
diff changeset
37 with Errout; use Errout;
kono
parents:
diff changeset
38 with Exp_Disp; use Exp_Disp;
kono
parents:
diff changeset
39 with Exp_Dist; use Exp_Dist;
kono
parents:
diff changeset
40 with Exp_Dbug; use Exp_Dbug;
kono
parents:
diff changeset
41 with Freeze; use Freeze;
kono
parents:
diff changeset
42 with Ghost; use Ghost;
kono
parents:
diff changeset
43 with Lib; use Lib;
kono
parents:
diff changeset
44 with Lib.Xref; use Lib.Xref;
kono
parents:
diff changeset
45 with Namet; use Namet;
kono
parents:
diff changeset
46 with Nmake; use Nmake;
kono
parents:
diff changeset
47 with Nlists; use Nlists;
kono
parents:
diff changeset
48 with Opt; use Opt;
kono
parents:
diff changeset
49 with Output; use Output;
kono
parents:
diff changeset
50 with Restrict; use Restrict;
kono
parents:
diff changeset
51 with Rtsfind; use Rtsfind;
kono
parents:
diff changeset
52 with Sem; use Sem;
kono
parents:
diff changeset
53 with Sem_Aux; use Sem_Aux;
kono
parents:
diff changeset
54 with Sem_Cat; use Sem_Cat;
kono
parents:
diff changeset
55 with Sem_Ch3; use Sem_Ch3;
kono
parents:
diff changeset
56 with Sem_Ch6; use Sem_Ch6;
kono
parents:
diff changeset
57 with Sem_Ch8; use Sem_Ch8;
kono
parents:
diff changeset
58 with Sem_Ch10; use Sem_Ch10;
kono
parents:
diff changeset
59 with Sem_Ch12; use Sem_Ch12;
kono
parents:
diff changeset
60 with Sem_Ch13; use Sem_Ch13;
kono
parents:
diff changeset
61 with Sem_Disp; use Sem_Disp;
kono
parents:
diff changeset
62 with Sem_Eval; use Sem_Eval;
kono
parents:
diff changeset
63 with Sem_Prag; use Sem_Prag;
kono
parents:
diff changeset
64 with Sem_Util; use Sem_Util;
kono
parents:
diff changeset
65 with Sem_Warn; use Sem_Warn;
kono
parents:
diff changeset
66 with Snames; use Snames;
kono
parents:
diff changeset
67 with Stand; use Stand;
kono
parents:
diff changeset
68 with Sinfo; use Sinfo;
kono
parents:
diff changeset
69 with Sinput; use Sinput;
kono
parents:
diff changeset
70 with Style;
kono
parents:
diff changeset
71 with Uintp; use Uintp;
kono
parents:
diff changeset
72
kono
parents:
diff changeset
73 with GNAT.HTable;
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 package body Sem_Ch7 is
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 -----------------------------------
kono
parents:
diff changeset
78 -- Handling private declarations --
kono
parents:
diff changeset
79 -----------------------------------
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 -- The principle that each entity has a single defining occurrence clashes
kono
parents:
diff changeset
82 -- with the presence of two separate definitions for private types: the
kono
parents:
diff changeset
83 -- first is the private type declaration, and the second is the full type
kono
parents:
diff changeset
84 -- declaration. It is important that all references to the type point to
kono
parents:
diff changeset
85 -- the same defining occurrence, namely the first one. To enforce the two
kono
parents:
diff changeset
86 -- separate views of the entity, the corresponding information is swapped
kono
parents:
diff changeset
87 -- between the two declarations. Outside of the package, the defining
kono
parents:
diff changeset
88 -- occurrence only contains the private declaration information, while in
kono
parents:
diff changeset
89 -- the private part and the body of the package the defining occurrence
kono
parents:
diff changeset
90 -- contains the full declaration. To simplify the swap, the defining
kono
parents:
diff changeset
91 -- occurrence that currently holds the private declaration points to the
kono
parents:
diff changeset
92 -- full declaration. During semantic processing the defining occurrence
kono
parents:
diff changeset
93 -- also points to a list of private dependents, that is to say access types
kono
parents:
diff changeset
94 -- or composite types whose designated types or component types are
kono
parents:
diff changeset
95 -- subtypes or derived types of the private type in question. After the
kono
parents:
diff changeset
96 -- full declaration has been seen, the private dependents are updated to
kono
parents:
diff changeset
97 -- indicate that they have full definitions.
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 -----------------------
kono
parents:
diff changeset
100 -- Local Subprograms --
kono
parents:
diff changeset
101 -----------------------
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 procedure Analyze_Package_Body_Helper (N : Node_Id);
kono
parents:
diff changeset
104 -- Does all the real work of Analyze_Package_Body
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 procedure Check_Anonymous_Access_Types
kono
parents:
diff changeset
107 (Spec_Id : Entity_Id;
kono
parents:
diff changeset
108 P_Body : Node_Id);
kono
parents:
diff changeset
109 -- If the spec of a package has a limited_with_clause, it may declare
kono
parents:
diff changeset
110 -- anonymous access types whose designated type is a limited view, such an
kono
parents:
diff changeset
111 -- anonymous access return type for a function. This access type cannot be
kono
parents:
diff changeset
112 -- elaborated in the spec itself, but it may need an itype reference if it
kono
parents:
diff changeset
113 -- is used within a nested scope. In that case the itype reference is
kono
parents:
diff changeset
114 -- created at the beginning of the corresponding package body and inserted
kono
parents:
diff changeset
115 -- before other body declarations.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 procedure Declare_Inherited_Private_Subprograms (Id : Entity_Id);
kono
parents:
diff changeset
118 -- Called upon entering the private part of a public child package and the
kono
parents:
diff changeset
119 -- body of a nested package, to potentially declare certain inherited
kono
parents:
diff changeset
120 -- subprograms that were inherited by types in the visible part, but whose
kono
parents:
diff changeset
121 -- declaration was deferred because the parent operation was private and
kono
parents:
diff changeset
122 -- not visible at that point. These subprograms are located by traversing
kono
parents:
diff changeset
123 -- the visible part declarations looking for non-private type extensions
kono
parents:
diff changeset
124 -- and then examining each of the primitive operations of such types to
kono
parents:
diff changeset
125 -- find those that were inherited but declared with a special internal
kono
parents:
diff changeset
126 -- name. Each such operation is now declared as an operation with a normal
kono
parents:
diff changeset
127 -- name (using the name of the parent operation) and replaces the previous
kono
parents:
diff changeset
128 -- implicit operation in the primitive operations list of the type. If the
kono
parents:
diff changeset
129 -- inherited private operation has been overridden, then it's replaced by
kono
parents:
diff changeset
130 -- the overriding operation.
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 procedure Install_Package_Entity (Id : Entity_Id);
kono
parents:
diff changeset
133 -- Supporting procedure for Install_{Visible,Private}_Declarations. Places
kono
parents:
diff changeset
134 -- one entity on its visibility chain, and recurses on the visible part if
kono
parents:
diff changeset
135 -- the entity is an inner package.
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 function Is_Private_Base_Type (E : Entity_Id) return Boolean;
kono
parents:
diff changeset
138 -- True for a private type that is not a subtype
kono
parents:
diff changeset
139
kono
parents:
diff changeset
140 function Is_Visible_Dependent (Dep : Entity_Id) return Boolean;
kono
parents:
diff changeset
141 -- If the private dependent is a private type whose full view is derived
kono
parents:
diff changeset
142 -- from the parent type, its full properties are revealed only if we are in
kono
parents:
diff changeset
143 -- the immediate scope of the private dependent. Should this predicate be
kono
parents:
diff changeset
144 -- tightened further???
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 function Requires_Completion_In_Body
kono
parents:
diff changeset
147 (Id : Entity_Id;
kono
parents:
diff changeset
148 Pack_Id : Entity_Id;
kono
parents:
diff changeset
149 Do_Abstract_States : Boolean := False) return Boolean;
kono
parents:
diff changeset
150 -- Subsidiary to routines Unit_Requires_Body and Unit_Requires_Body_Info.
kono
parents:
diff changeset
151 -- Determine whether entity Id declared in package spec Pack_Id requires
kono
parents:
diff changeset
152 -- completion in a package body. Flag Do_Abstract_Stats should be set when
kono
parents:
diff changeset
153 -- abstract states are to be considered in the completion test.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 procedure Unit_Requires_Body_Info (Pack_Id : Entity_Id);
kono
parents:
diff changeset
156 -- Outputs info messages showing why package Pack_Id requires a body. The
kono
parents:
diff changeset
157 -- caller has checked that the switch requesting this information is set,
kono
parents:
diff changeset
158 -- and that the package does indeed require a body.
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 --------------------------
kono
parents:
diff changeset
161 -- Analyze_Package_Body --
kono
parents:
diff changeset
162 --------------------------
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 procedure Analyze_Package_Body (N : Node_Id) is
kono
parents:
diff changeset
165 Loc : constant Source_Ptr := Sloc (N);
kono
parents:
diff changeset
166
kono
parents:
diff changeset
167 begin
kono
parents:
diff changeset
168 if Debug_Flag_C then
kono
parents:
diff changeset
169 Write_Str ("==> package body ");
kono
parents:
diff changeset
170 Write_Name (Chars (Defining_Entity (N)));
kono
parents:
diff changeset
171 Write_Str (" from ");
kono
parents:
diff changeset
172 Write_Location (Loc);
kono
parents:
diff changeset
173 Write_Eol;
kono
parents:
diff changeset
174 Indent;
kono
parents:
diff changeset
175 end if;
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 -- The real work is split out into the helper, so it can do "return;"
kono
parents:
diff changeset
178 -- without skipping the debug output.
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 Analyze_Package_Body_Helper (N);
kono
parents:
diff changeset
181
kono
parents:
diff changeset
182 if Debug_Flag_C then
kono
parents:
diff changeset
183 Outdent;
kono
parents:
diff changeset
184 Write_Str ("<== package body ");
kono
parents:
diff changeset
185 Write_Name (Chars (Defining_Entity (N)));
kono
parents:
diff changeset
186 Write_Str (" from ");
kono
parents:
diff changeset
187 Write_Location (Loc);
kono
parents:
diff changeset
188 Write_Eol;
kono
parents:
diff changeset
189 end if;
kono
parents:
diff changeset
190 end Analyze_Package_Body;
kono
parents:
diff changeset
191
kono
parents:
diff changeset
192 ------------------------------------------------------
kono
parents:
diff changeset
193 -- Analyze_Package_Body_Helper Data and Subprograms --
kono
parents:
diff changeset
194 ------------------------------------------------------
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 Entity_Table_Size : constant := 4093;
kono
parents:
diff changeset
197 -- Number of headers in hash table
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 subtype Entity_Header_Num is Integer range 0 .. Entity_Table_Size - 1;
kono
parents:
diff changeset
200 -- Range of headers in hash table
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 function Node_Hash (Id : Entity_Id) return Entity_Header_Num;
kono
parents:
diff changeset
203 -- Simple hash function for Entity_Ids
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 package Subprogram_Table is new GNAT.Htable.Simple_HTable
kono
parents:
diff changeset
206 (Header_Num => Entity_Header_Num,
kono
parents:
diff changeset
207 Element => Boolean,
kono
parents:
diff changeset
208 No_Element => False,
kono
parents:
diff changeset
209 Key => Entity_Id,
kono
parents:
diff changeset
210 Hash => Node_Hash,
kono
parents:
diff changeset
211 Equal => "=");
kono
parents:
diff changeset
212 -- Hash table to record which subprograms are referenced. It is declared
kono
parents:
diff changeset
213 -- at library level to avoid elaborating it for every call to Analyze.
kono
parents:
diff changeset
214
kono
parents:
diff changeset
215 package Traversed_Table is new GNAT.Htable.Simple_HTable
kono
parents:
diff changeset
216 (Header_Num => Entity_Header_Num,
kono
parents:
diff changeset
217 Element => Boolean,
kono
parents:
diff changeset
218 No_Element => False,
kono
parents:
diff changeset
219 Key => Node_Id,
kono
parents:
diff changeset
220 Hash => Node_Hash,
kono
parents:
diff changeset
221 Equal => "=");
kono
parents:
diff changeset
222 -- Hash table to record which nodes we have traversed, so we can avoid
kono
parents:
diff changeset
223 -- traversing the same nodes repeatedly.
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 -----------------
kono
parents:
diff changeset
226 -- Node_Hash --
kono
parents:
diff changeset
227 -----------------
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 function Node_Hash (Id : Entity_Id) return Entity_Header_Num is
kono
parents:
diff changeset
230 begin
kono
parents:
diff changeset
231 return Entity_Header_Num (Id mod Entity_Table_Size);
kono
parents:
diff changeset
232 end Node_Hash;
kono
parents:
diff changeset
233
kono
parents:
diff changeset
234 ---------------------------------
kono
parents:
diff changeset
235 -- Analyze_Package_Body_Helper --
kono
parents:
diff changeset
236 ---------------------------------
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- WARNING: This routine manages Ghost regions. Return statements must be
kono
parents:
diff changeset
239 -- replaced by gotos which jump to the end of the routine and restore the
kono
parents:
diff changeset
240 -- Ghost mode.
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 procedure Analyze_Package_Body_Helper (N : Node_Id) is
kono
parents:
diff changeset
243 procedure Hide_Public_Entities (Decls : List_Id);
kono
parents:
diff changeset
244 -- Attempt to hide all public entities found in declarative list Decls
kono
parents:
diff changeset
245 -- by resetting their Is_Public flag to False depending on whether the
kono
parents:
diff changeset
246 -- entities are not referenced by inlined or generic bodies. This kind
kono
parents:
diff changeset
247 -- of processing is a conservative approximation and will still leave
kono
parents:
diff changeset
248 -- entities externally visible if the package is not simple enough.
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 procedure Install_Composite_Operations (P : Entity_Id);
kono
parents:
diff changeset
251 -- Composite types declared in the current scope may depend on types
kono
parents:
diff changeset
252 -- that were private at the point of declaration, and whose full view
kono
parents:
diff changeset
253 -- is now in scope. Indicate that the corresponding operations on the
kono
parents:
diff changeset
254 -- composite type are available.
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 --------------------------
kono
parents:
diff changeset
257 -- Hide_Public_Entities --
kono
parents:
diff changeset
258 --------------------------
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 procedure Hide_Public_Entities (Decls : List_Id) is
kono
parents:
diff changeset
261 function Has_Referencer
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
262 (Decls : List_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
263 In_Nested_Instance : Boolean;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
264 Has_Outer_Referencer_Of_Non_Subprograms : Boolean) return Boolean;
111
kono
parents:
diff changeset
265 -- A "referencer" is a construct which may reference a previous
kono
parents:
diff changeset
266 -- declaration. Examine all declarations in list Decls in reverse
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
267 -- and determine whether one such referencer exists. All entities
111
kono
parents:
diff changeset
268 -- in the range Last (Decls) .. Referencer are hidden from external
kono
parents:
diff changeset
269 -- visibility.
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 function Scan_Subprogram_Ref (N : Node_Id) return Traverse_Result;
kono
parents:
diff changeset
272 -- Determine whether a node denotes a reference to a subprogram
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 procedure Traverse_And_Scan_Subprogram_Refs is
kono
parents:
diff changeset
275 new Traverse_Proc (Scan_Subprogram_Ref);
kono
parents:
diff changeset
276 -- Subsidiary to routine Has_Referencer. Determine whether a node
kono
parents:
diff changeset
277 -- contains references to a subprogram and record them.
kono
parents:
diff changeset
278 -- WARNING: this is a very expensive routine as it performs a full
kono
parents:
diff changeset
279 -- tree traversal.
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 procedure Scan_Subprogram_Refs (Node : Node_Id);
kono
parents:
diff changeset
282 -- If we haven't already traversed Node, then mark it and traverse
kono
parents:
diff changeset
283 -- it.
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 --------------------
kono
parents:
diff changeset
286 -- Has_Referencer --
kono
parents:
diff changeset
287 --------------------
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 function Has_Referencer
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
290 (Decls : List_Id;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
291 In_Nested_Instance : Boolean;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
292 Has_Outer_Referencer_Of_Non_Subprograms : Boolean) return Boolean
111
kono
parents:
diff changeset
293 is
kono
parents:
diff changeset
294 Decl : Node_Id;
kono
parents:
diff changeset
295 Decl_Id : Entity_Id;
kono
parents:
diff changeset
296 Spec : Node_Id;
kono
parents:
diff changeset
297
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
298 Has_Referencer_Of_Non_Subprograms : Boolean :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
299 Has_Outer_Referencer_Of_Non_Subprograms;
111
kono
parents:
diff changeset
300 -- Set if an inlined subprogram body was detected as a referencer.
kono
parents:
diff changeset
301 -- In this case, we do not return True immediately but keep hiding
kono
parents:
diff changeset
302 -- subprograms from external visibility.
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 begin
kono
parents:
diff changeset
305 if No (Decls) then
kono
parents:
diff changeset
306 return False;
kono
parents:
diff changeset
307 end if;
kono
parents:
diff changeset
308
kono
parents:
diff changeset
309 -- Examine all declarations in reverse order, hiding all entities
kono
parents:
diff changeset
310 -- from external visibility until a referencer has been found. The
kono
parents:
diff changeset
311 -- algorithm recurses into nested packages.
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 Decl := Last (Decls);
kono
parents:
diff changeset
314 while Present (Decl) loop
kono
parents:
diff changeset
315
kono
parents:
diff changeset
316 -- A stub is always considered a referencer
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 if Nkind (Decl) in N_Body_Stub then
kono
parents:
diff changeset
319 return True;
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 -- Package declaration
kono
parents:
diff changeset
322
kono
parents:
diff changeset
323 elsif Nkind (Decl) = N_Package_Declaration then
kono
parents:
diff changeset
324 Spec := Specification (Decl);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
325 Decl_Id := Defining_Entity (Spec);
111
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 -- Inspect the declarations of a non-generic package to try
kono
parents:
diff changeset
328 -- and hide more entities from external visibility.
kono
parents:
diff changeset
329
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
330 if not Is_Generic_Unit (Decl_Id) then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
331 if Has_Referencer (Private_Declarations (Spec),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
332 In_Nested_Instance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
333 or else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
334 Is_Generic_Instance (Decl_Id),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
335 Has_Referencer_Of_Non_Subprograms)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
336 or else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
337 Has_Referencer (Visible_Declarations (Spec),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
338 In_Nested_Instance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
339 or else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
340 Is_Generic_Instance (Decl_Id),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
341 Has_Referencer_Of_Non_Subprograms)
111
kono
parents:
diff changeset
342 then
kono
parents:
diff changeset
343 return True;
kono
parents:
diff changeset
344 end if;
kono
parents:
diff changeset
345 end if;
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 -- Package body
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 elsif Nkind (Decl) = N_Package_Body
kono
parents:
diff changeset
350 and then Present (Corresponding_Spec (Decl))
kono
parents:
diff changeset
351 then
kono
parents:
diff changeset
352 Decl_Id := Corresponding_Spec (Decl);
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 -- A generic package body is a referencer. It would seem
kono
parents:
diff changeset
355 -- that we only have to consider generics that can be
kono
parents:
diff changeset
356 -- exported, i.e. where the corresponding spec is the
kono
parents:
diff changeset
357 -- spec of the current package, but because of nested
kono
parents:
diff changeset
358 -- instantiations, a fully private generic body may export
kono
parents:
diff changeset
359 -- other private body entities. Furthermore, regardless of
kono
parents:
diff changeset
360 -- whether there was a previous inlined subprogram, (an
kono
parents:
diff changeset
361 -- instantiation of) the generic package may reference any
kono
parents:
diff changeset
362 -- entity declared before it.
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 if Is_Generic_Unit (Decl_Id) then
kono
parents:
diff changeset
365 return True;
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 -- Inspect the declarations of a non-generic package body to
kono
parents:
diff changeset
368 -- try and hide more entities from external visibility.
kono
parents:
diff changeset
369
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
370 elsif Has_Referencer (Declarations (Decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
371 In_Nested_Instance
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
372 or else
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
373 Is_Generic_Instance (Decl_Id),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
374 Has_Referencer_Of_Non_Subprograms)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
375 then
111
kono
parents:
diff changeset
376 return True;
kono
parents:
diff changeset
377 end if;
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 -- Subprogram body
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 elsif Nkind (Decl) = N_Subprogram_Body then
kono
parents:
diff changeset
382 if Present (Corresponding_Spec (Decl)) then
kono
parents:
diff changeset
383 Decl_Id := Corresponding_Spec (Decl);
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 -- A generic subprogram body acts as a referencer
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 if Is_Generic_Unit (Decl_Id) then
kono
parents:
diff changeset
388 return True;
kono
parents:
diff changeset
389 end if;
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 -- An inlined subprogram body acts as a referencer
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 -- Note that we test Has_Pragma_Inline here in addition
kono
parents:
diff changeset
394 -- to Is_Inlined. We are doing this for a client, since
kono
parents:
diff changeset
395 -- we are computing which entities should be public, and
kono
parents:
diff changeset
396 -- it is the client who will decide if actual inlining
kono
parents:
diff changeset
397 -- should occur, so we need to catch all cases where the
kono
parents:
diff changeset
398 -- subprogram may be inlined by the client.
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 if Is_Inlined (Decl_Id)
kono
parents:
diff changeset
401 or else Has_Pragma_Inline (Decl_Id)
kono
parents:
diff changeset
402 then
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
403 Has_Referencer_Of_Non_Subprograms := True;
111
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 -- Inspect the statements of the subprogram body
kono
parents:
diff changeset
406 -- to determine whether the body references other
kono
parents:
diff changeset
407 -- subprograms.
kono
parents:
diff changeset
408
kono
parents:
diff changeset
409 Scan_Subprogram_Refs (Decl);
kono
parents:
diff changeset
410 end if;
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 -- Otherwise this is a stand alone subprogram body
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 else
kono
parents:
diff changeset
415 Decl_Id := Defining_Entity (Decl);
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 -- An inlined subprogram body acts as a referencer
kono
parents:
diff changeset
418
kono
parents:
diff changeset
419 if Is_Inlined (Decl_Id)
kono
parents:
diff changeset
420 or else Has_Pragma_Inline (Decl_Id)
kono
parents:
diff changeset
421 then
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
422 Has_Referencer_Of_Non_Subprograms := True;
111
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 -- Inspect the statements of the subprogram body
kono
parents:
diff changeset
425 -- to determine whether the body references other
kono
parents:
diff changeset
426 -- subprograms.
kono
parents:
diff changeset
427
kono
parents:
diff changeset
428 Scan_Subprogram_Refs (Decl);
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 -- Otherwise we can reset Is_Public right away
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 elsif not Subprogram_Table.Get (Decl_Id) then
kono
parents:
diff changeset
433 Set_Is_Public (Decl_Id, False);
kono
parents:
diff changeset
434 end if;
kono
parents:
diff changeset
435 end if;
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 -- Freeze node
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 elsif Nkind (Decl) = N_Freeze_Entity then
kono
parents:
diff changeset
440 declare
kono
parents:
diff changeset
441 Discard : Boolean;
kono
parents:
diff changeset
442 pragma Unreferenced (Discard);
kono
parents:
diff changeset
443 begin
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
444 -- Inspect the actions to find references to subprograms.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
445 -- We assume that the actions do not contain other kinds
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
446 -- of references and, therefore, we do not stop the scan
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
447 -- or set Has_Referencer_Of_Non_Subprograms here. Doing
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
448 -- it would pessimize common cases for which the actions
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
449 -- contain the declaration of an init procedure, since
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
450 -- such a procedure is automatically marked inline.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
451
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
452 Discard :=
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
453 Has_Referencer (Actions (Decl),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
454 In_Nested_Instance,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
455 Has_Referencer_Of_Non_Subprograms);
111
kono
parents:
diff changeset
456 end;
kono
parents:
diff changeset
457
kono
parents:
diff changeset
458 -- Exceptions, objects and renamings do not need to be public
kono
parents:
diff changeset
459 -- if they are not followed by a construct which can reference
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
460 -- and export them. Likewise for subprograms but we work harder
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
461 -- for them to see whether they are referenced on an individual
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
462 -- basis by looking into the table of referenced subprograms.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
463 -- But we cannot say anything for entities declared in nested
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
464 -- instances because instantiations are not done yet so the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
465 -- bodies are not visible and could contain references to them.
111
kono
parents:
diff changeset
466 elsif Nkind_In (Decl, N_Exception_Declaration,
kono
parents:
diff changeset
467 N_Object_Declaration,
kono
parents:
diff changeset
468 N_Object_Renaming_Declaration,
kono
parents:
diff changeset
469 N_Subprogram_Declaration,
kono
parents:
diff changeset
470 N_Subprogram_Renaming_Declaration)
kono
parents:
diff changeset
471 then
kono
parents:
diff changeset
472 Decl_Id := Defining_Entity (Decl);
kono
parents:
diff changeset
473
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
474 if not In_Nested_Instance
111
kono
parents:
diff changeset
475 and then not Is_Imported (Decl_Id)
kono
parents:
diff changeset
476 and then not Is_Exported (Decl_Id)
kono
parents:
diff changeset
477 and then No (Interface_Name (Decl_Id))
kono
parents:
diff changeset
478 and then
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
479 ((Nkind (Decl) /= N_Subprogram_Declaration
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
480 and then not Has_Referencer_Of_Non_Subprograms)
111
kono
parents:
diff changeset
481 or else (Nkind (Decl) = N_Subprogram_Declaration
kono
parents:
diff changeset
482 and then not Subprogram_Table.Get (Decl_Id)))
kono
parents:
diff changeset
483 then
kono
parents:
diff changeset
484 Set_Is_Public (Decl_Id, False);
kono
parents:
diff changeset
485 end if;
kono
parents:
diff changeset
486
kono
parents:
diff changeset
487 -- For a subprogram renaming, if the entity is referenced,
kono
parents:
diff changeset
488 -- then so is the renamed subprogram. But there is an issue
kono
parents:
diff changeset
489 -- with generic bodies because instantiations are not done
kono
parents:
diff changeset
490 -- yet and, therefore, cannot be scanned for referencers.
kono
parents:
diff changeset
491 -- That's why we use an approximation and test that we have
kono
parents:
diff changeset
492 -- at least one subprogram referenced by an inlined body
kono
parents:
diff changeset
493 -- instead of precisely the entity of this renaming.
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 if Nkind (Decl) = N_Subprogram_Renaming_Declaration
kono
parents:
diff changeset
496 and then Subprogram_Table.Get_First
kono
parents:
diff changeset
497 and then Is_Entity_Name (Name (Decl))
kono
parents:
diff changeset
498 and then Present (Entity (Name (Decl)))
kono
parents:
diff changeset
499 and then Is_Subprogram (Entity (Name (Decl)))
kono
parents:
diff changeset
500 then
kono
parents:
diff changeset
501 Subprogram_Table.Set (Entity (Name (Decl)), True);
kono
parents:
diff changeset
502 end if;
kono
parents:
diff changeset
503 end if;
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 Prev (Decl);
kono
parents:
diff changeset
506 end loop;
kono
parents:
diff changeset
507
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
508 return Has_Referencer_Of_Non_Subprograms;
111
kono
parents:
diff changeset
509 end Has_Referencer;
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -------------------------
kono
parents:
diff changeset
512 -- Scan_Subprogram_Ref --
kono
parents:
diff changeset
513 -------------------------
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 function Scan_Subprogram_Ref (N : Node_Id) return Traverse_Result is
kono
parents:
diff changeset
516 begin
kono
parents:
diff changeset
517 -- Detect a reference of the form
kono
parents:
diff changeset
518 -- Subp_Call
kono
parents:
diff changeset
519
kono
parents:
diff changeset
520 if Nkind (N) in N_Subprogram_Call
kono
parents:
diff changeset
521 and then Is_Entity_Name (Name (N))
kono
parents:
diff changeset
522 and then Present (Entity (Name (N)))
kono
parents:
diff changeset
523 and then Is_Subprogram (Entity (Name (N)))
kono
parents:
diff changeset
524 then
kono
parents:
diff changeset
525 Subprogram_Table.Set (Entity (Name (N)), True);
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 -- Detect a reference of the form
kono
parents:
diff changeset
528 -- Subp'Some_Attribute
kono
parents:
diff changeset
529
kono
parents:
diff changeset
530 elsif Nkind (N) = N_Attribute_Reference
kono
parents:
diff changeset
531 and then Is_Entity_Name (Prefix (N))
kono
parents:
diff changeset
532 and then Present (Entity (Prefix (N)))
kono
parents:
diff changeset
533 and then Is_Subprogram (Entity (Prefix (N)))
kono
parents:
diff changeset
534 then
kono
parents:
diff changeset
535 Subprogram_Table.Set (Entity (Prefix (N)), True);
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 -- Constants can be substituted by their value in gigi, which may
kono
parents:
diff changeset
538 -- contain a reference, so scan the value recursively.
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 elsif Is_Entity_Name (N)
kono
parents:
diff changeset
541 and then Present (Entity (N))
kono
parents:
diff changeset
542 and then Ekind (Entity (N)) = E_Constant
kono
parents:
diff changeset
543 then
kono
parents:
diff changeset
544 declare
kono
parents:
diff changeset
545 Val : constant Node_Id := Constant_Value (Entity (N));
kono
parents:
diff changeset
546 begin
kono
parents:
diff changeset
547 if Present (Val)
kono
parents:
diff changeset
548 and then not Compile_Time_Known_Value (Val)
kono
parents:
diff changeset
549 then
kono
parents:
diff changeset
550 Scan_Subprogram_Refs (Val);
kono
parents:
diff changeset
551 end if;
kono
parents:
diff changeset
552 end;
kono
parents:
diff changeset
553 end if;
kono
parents:
diff changeset
554
kono
parents:
diff changeset
555 return OK;
kono
parents:
diff changeset
556 end Scan_Subprogram_Ref;
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 --------------------------
kono
parents:
diff changeset
559 -- Scan_Subprogram_Refs --
kono
parents:
diff changeset
560 --------------------------
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 procedure Scan_Subprogram_Refs (Node : Node_Id) is
kono
parents:
diff changeset
563 begin
kono
parents:
diff changeset
564 if not Traversed_Table.Get (Node) then
kono
parents:
diff changeset
565 Traversed_Table.Set (Node, True);
kono
parents:
diff changeset
566 Traverse_And_Scan_Subprogram_Refs (Node);
kono
parents:
diff changeset
567 end if;
kono
parents:
diff changeset
568 end Scan_Subprogram_Refs;
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 -- Local variables
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 Discard : Boolean;
kono
parents:
diff changeset
573 pragma Unreferenced (Discard);
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575 -- Start of processing for Hide_Public_Entities
kono
parents:
diff changeset
576
kono
parents:
diff changeset
577 begin
kono
parents:
diff changeset
578 -- The algorithm examines the top level declarations of a package
kono
parents:
diff changeset
579 -- body in reverse looking for a construct that may export entities
kono
parents:
diff changeset
580 -- declared prior to it. If such a scenario is encountered, then all
kono
parents:
diff changeset
581 -- entities in the range Last (Decls) .. construct are hidden from
kono
parents:
diff changeset
582 -- external visibility. Consider:
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 -- package Pack is
kono
parents:
diff changeset
585 -- generic
kono
parents:
diff changeset
586 -- package Gen is
kono
parents:
diff changeset
587 -- end Gen;
kono
parents:
diff changeset
588 -- end Pack;
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 -- package body Pack is
kono
parents:
diff changeset
591 -- External_Obj : ...; -- (1)
kono
parents:
diff changeset
592
kono
parents:
diff changeset
593 -- package body Gen is -- (2)
kono
parents:
diff changeset
594 -- ... External_Obj ... -- (3)
kono
parents:
diff changeset
595 -- end Gen;
kono
parents:
diff changeset
596
kono
parents:
diff changeset
597 -- Local_Obj : ...; -- (4)
kono
parents:
diff changeset
598 -- end Pack;
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 -- In this example Local_Obj (4) must not be externally visible as
kono
parents:
diff changeset
601 -- it cannot be exported by anything in Pack. The body of generic
kono
parents:
diff changeset
602 -- package Gen (2) on the other hand acts as a "referencer" and may
kono
parents:
diff changeset
603 -- export anything declared before it. Since the compiler does not
kono
parents:
diff changeset
604 -- perform flow analysis, it is not possible to determine precisely
kono
parents:
diff changeset
605 -- which entities will be exported when Gen is instantiated. In the
kono
parents:
diff changeset
606 -- example above External_Obj (1) is exported at (3), but this may
kono
parents:
diff changeset
607 -- not always be the case. The algorithm takes a conservative stance
kono
parents:
diff changeset
608 -- and leaves entity External_Obj public.
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 -- This very conservative algorithm is supplemented by a more precise
kono
parents:
diff changeset
611 -- processing for inlined bodies. For them, we traverse the syntactic
kono
parents:
diff changeset
612 -- tree and record which subprograms are actually referenced from it.
kono
parents:
diff changeset
613 -- This makes it possible to compute a much smaller set of externally
kono
parents:
diff changeset
614 -- visible subprograms in the absence of generic bodies, which can
kono
parents:
diff changeset
615 -- have a significant impact on the inlining decisions made in the
kono
parents:
diff changeset
616 -- back end and the removal of out-of-line bodies from the object
kono
parents:
diff changeset
617 -- code. We do it only for inlined bodies because they are supposed
kono
parents:
diff changeset
618 -- to be reasonably small and tree traversal is very expensive.
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 -- Note that even this special processing is not optimal for inlined
kono
parents:
diff changeset
621 -- bodies, because we treat all inlined subprograms alike. An optimal
kono
parents:
diff changeset
622 -- algorithm would require computing the transitive closure of the
kono
parents:
diff changeset
623 -- inlined subprograms that can really be referenced from other units
kono
parents:
diff changeset
624 -- in the source code.
kono
parents:
diff changeset
625
kono
parents:
diff changeset
626 -- We could extend this processing for inlined bodies and record all
kono
parents:
diff changeset
627 -- entities, not just subprograms, referenced from them, which would
kono
parents:
diff changeset
628 -- make it possible to compute a much smaller set of all externally
kono
parents:
diff changeset
629 -- visible entities in the absence of generic bodies. But this would
kono
parents:
diff changeset
630 -- mean implementing a more thorough tree traversal of the bodies,
kono
parents:
diff changeset
631 -- i.e. not just syntactic, and the gain would very likely be worth
kono
parents:
diff changeset
632 -- neither the hassle nor the slowdown of the compiler.
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 -- Finally, an important thing to be aware of is that, at this point,
kono
parents:
diff changeset
635 -- instantiations are not done yet so we cannot directly see inlined
kono
parents:
diff changeset
636 -- bodies coming from them. That's not catastrophic because only the
kono
parents:
diff changeset
637 -- actual parameters of the instantiations matter here, and they are
kono
parents:
diff changeset
638 -- present in the declarations list of the instantiated packages.
kono
parents:
diff changeset
639
kono
parents:
diff changeset
640 Traversed_Table.Reset;
kono
parents:
diff changeset
641 Subprogram_Table.Reset;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
642 Discard := Has_Referencer (Decls, False, False);
111
kono
parents:
diff changeset
643 end Hide_Public_Entities;
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 ----------------------------------
kono
parents:
diff changeset
646 -- Install_Composite_Operations --
kono
parents:
diff changeset
647 ----------------------------------
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 procedure Install_Composite_Operations (P : Entity_Id) is
kono
parents:
diff changeset
650 Id : Entity_Id;
kono
parents:
diff changeset
651
kono
parents:
diff changeset
652 begin
kono
parents:
diff changeset
653 Id := First_Entity (P);
kono
parents:
diff changeset
654 while Present (Id) loop
kono
parents:
diff changeset
655 if Is_Type (Id)
kono
parents:
diff changeset
656 and then (Is_Limited_Composite (Id)
kono
parents:
diff changeset
657 or else Is_Private_Composite (Id))
kono
parents:
diff changeset
658 and then No (Private_Component (Id))
kono
parents:
diff changeset
659 then
kono
parents:
diff changeset
660 Set_Is_Limited_Composite (Id, False);
kono
parents:
diff changeset
661 Set_Is_Private_Composite (Id, False);
kono
parents:
diff changeset
662 end if;
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 Next_Entity (Id);
kono
parents:
diff changeset
665 end loop;
kono
parents:
diff changeset
666 end Install_Composite_Operations;
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 -- Local variables
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 Saved_GM : constant Ghost_Mode_Type := Ghost_Mode;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
671 Saved_IGR : constant Node_Id := Ignored_Ghost_Region;
111
kono
parents:
diff changeset
672 Saved_ISMP : constant Boolean :=
kono
parents:
diff changeset
673 Ignore_SPARK_Mode_Pragmas_In_Instance;
kono
parents:
diff changeset
674 -- Save the Ghost and SPARK mode-related data to restore on exit
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 Body_Id : Entity_Id;
kono
parents:
diff changeset
677 HSS : Node_Id;
kono
parents:
diff changeset
678 Last_Spec_Entity : Entity_Id;
kono
parents:
diff changeset
679 New_N : Node_Id;
kono
parents:
diff changeset
680 Pack_Decl : Node_Id;
kono
parents:
diff changeset
681 Spec_Id : Entity_Id;
kono
parents:
diff changeset
682
kono
parents:
diff changeset
683 -- Start of processing for Analyze_Package_Body_Helper
kono
parents:
diff changeset
684
kono
parents:
diff changeset
685 begin
kono
parents:
diff changeset
686 -- Find corresponding package specification, and establish the current
kono
parents:
diff changeset
687 -- scope. The visible defining entity for the package is the defining
kono
parents:
diff changeset
688 -- occurrence in the spec. On exit from the package body, all body
kono
parents:
diff changeset
689 -- declarations are attached to the defining entity for the body, but
kono
parents:
diff changeset
690 -- the later is never used for name resolution. In this fashion there
kono
parents:
diff changeset
691 -- is only one visible entity that denotes the package.
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 -- Set Body_Id. Note that this will be reset to point to the generic
kono
parents:
diff changeset
694 -- copy later on in the generic case.
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696 Body_Id := Defining_Entity (N);
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 -- Body is body of package instantiation. Corresponding spec has already
kono
parents:
diff changeset
699 -- been set.
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 if Present (Corresponding_Spec (N)) then
kono
parents:
diff changeset
702 Spec_Id := Corresponding_Spec (N);
kono
parents:
diff changeset
703 Pack_Decl := Unit_Declaration_Node (Spec_Id);
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 else
kono
parents:
diff changeset
706 Spec_Id := Current_Entity_In_Scope (Defining_Entity (N));
kono
parents:
diff changeset
707
kono
parents:
diff changeset
708 if Present (Spec_Id)
kono
parents:
diff changeset
709 and then Is_Package_Or_Generic_Package (Spec_Id)
kono
parents:
diff changeset
710 then
kono
parents:
diff changeset
711 Pack_Decl := Unit_Declaration_Node (Spec_Id);
kono
parents:
diff changeset
712
kono
parents:
diff changeset
713 if Nkind (Pack_Decl) = N_Package_Renaming_Declaration then
kono
parents:
diff changeset
714 Error_Msg_N ("cannot supply body for package renaming", N);
kono
parents:
diff changeset
715 return;
kono
parents:
diff changeset
716
kono
parents:
diff changeset
717 elsif Present (Corresponding_Body (Pack_Decl)) then
kono
parents:
diff changeset
718 Error_Msg_N ("redefinition of package body", N);
kono
parents:
diff changeset
719 return;
kono
parents:
diff changeset
720 end if;
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 else
kono
parents:
diff changeset
723 Error_Msg_N ("missing specification for package body", N);
kono
parents:
diff changeset
724 return;
kono
parents:
diff changeset
725 end if;
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 if Is_Package_Or_Generic_Package (Spec_Id)
kono
parents:
diff changeset
728 and then (Scope (Spec_Id) = Standard_Standard
kono
parents:
diff changeset
729 or else Is_Child_Unit (Spec_Id))
kono
parents:
diff changeset
730 and then not Unit_Requires_Body (Spec_Id)
kono
parents:
diff changeset
731 then
kono
parents:
diff changeset
732 if Ada_Version = Ada_83 then
kono
parents:
diff changeset
733 Error_Msg_N
kono
parents:
diff changeset
734 ("optional package body (not allowed in Ada 95)??", N);
kono
parents:
diff changeset
735 else
kono
parents:
diff changeset
736 Error_Msg_N ("spec of this package does not allow a body", N);
kono
parents:
diff changeset
737 end if;
kono
parents:
diff changeset
738 end if;
kono
parents:
diff changeset
739 end if;
kono
parents:
diff changeset
740
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
741 -- A [generic] package body freezes the contract of the nearest
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
742 -- enclosing package body and all other contracts encountered in
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
743 -- the same declarative part up to and excluding the package body:
111
kono
parents:
diff changeset
744
kono
parents:
diff changeset
745 -- package body Nearest_Enclosing_Package
kono
parents:
diff changeset
746 -- with Refined_State => (State => Constit)
kono
parents:
diff changeset
747 -- is
kono
parents:
diff changeset
748 -- Constit : ...;
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 -- package body Freezes_Enclosing_Package_Body
kono
parents:
diff changeset
751 -- with Refined_State => (State_2 => Constit_2)
kono
parents:
diff changeset
752 -- is
kono
parents:
diff changeset
753 -- Constit_2 : ...;
kono
parents:
diff changeset
754
kono
parents:
diff changeset
755 -- procedure Proc
kono
parents:
diff changeset
756 -- with Refined_Depends => (Input => (Constit, Constit_2)) ...
kono
parents:
diff changeset
757
kono
parents:
diff changeset
758 -- This ensures that any annotations referenced by the contract of a
kono
parents:
diff changeset
759 -- [generic] subprogram body declared within the current package body
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
760 -- are available. This form of freezing is decoupled from the usual
111
kono
parents:
diff changeset
761 -- Freeze_xxx mechanism because it must also work in the context of
kono
parents:
diff changeset
762 -- generics where normal freezing is disabled.
kono
parents:
diff changeset
763
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
764 -- Only bodies coming from source should cause this type of freezing.
111
kono
parents:
diff changeset
765 -- Instantiated generic bodies are excluded because their processing is
kono
parents:
diff changeset
766 -- performed in a separate compilation pass which lacks enough semantic
kono
parents:
diff changeset
767 -- information with respect to contract analysis. It is safe to suppress
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
768 -- the freezing of contracts in this case because this action already
111
kono
parents:
diff changeset
769 -- took place at the end of the enclosing declarative part.
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 if Comes_From_Source (N)
kono
parents:
diff changeset
772 and then not Is_Generic_Instance (Spec_Id)
kono
parents:
diff changeset
773 then
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
774 Freeze_Previous_Contracts (N);
111
kono
parents:
diff changeset
775 end if;
kono
parents:
diff changeset
776
kono
parents:
diff changeset
777 -- A package body is Ghost when the corresponding spec is Ghost. Set
kono
parents:
diff changeset
778 -- the mode now to ensure that any nodes generated during analysis and
kono
parents:
diff changeset
779 -- expansion are properly flagged as ignored Ghost.
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 Mark_And_Set_Ghost_Body (N, Spec_Id);
kono
parents:
diff changeset
782
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
783 -- If the body completes the initial declaration of a compilation unit
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
784 -- which is subject to pragma Elaboration_Checks, set the model of the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
785 -- pragma because it applies to all parts of the unit.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
786
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
787 Install_Elaboration_Model (Spec_Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
788
111
kono
parents:
diff changeset
789 Set_Is_Compilation_Unit (Body_Id, Is_Compilation_Unit (Spec_Id));
kono
parents:
diff changeset
790 Style.Check_Identifier (Body_Id, Spec_Id);
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 if Is_Child_Unit (Spec_Id) then
kono
parents:
diff changeset
793 if Nkind (Parent (N)) /= N_Compilation_Unit then
kono
parents:
diff changeset
794 Error_Msg_NE
kono
parents:
diff changeset
795 ("body of child unit& cannot be an inner package", N, Spec_Id);
kono
parents:
diff changeset
796 end if;
kono
parents:
diff changeset
797
kono
parents:
diff changeset
798 Set_Is_Child_Unit (Body_Id);
kono
parents:
diff changeset
799 end if;
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 -- Generic package case
kono
parents:
diff changeset
802
kono
parents:
diff changeset
803 if Ekind (Spec_Id) = E_Generic_Package then
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 -- Disable expansion and perform semantic analysis on copy. The
kono
parents:
diff changeset
806 -- unannotated body will be used in all instantiations.
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 Body_Id := Defining_Entity (N);
kono
parents:
diff changeset
809 Set_Ekind (Body_Id, E_Package_Body);
kono
parents:
diff changeset
810 Set_Scope (Body_Id, Scope (Spec_Id));
kono
parents:
diff changeset
811 Set_Is_Obsolescent (Body_Id, Is_Obsolescent (Spec_Id));
kono
parents:
diff changeset
812 Set_Body_Entity (Spec_Id, Body_Id);
kono
parents:
diff changeset
813 Set_Spec_Entity (Body_Id, Spec_Id);
kono
parents:
diff changeset
814
kono
parents:
diff changeset
815 New_N := Copy_Generic_Node (N, Empty, Instantiating => False);
kono
parents:
diff changeset
816 Rewrite (N, New_N);
kono
parents:
diff changeset
817
kono
parents:
diff changeset
818 -- Once the contents of the generic copy and the template are
kono
parents:
diff changeset
819 -- swapped, do the same for their respective aspect specifications.
kono
parents:
diff changeset
820
kono
parents:
diff changeset
821 Exchange_Aspects (N, New_N);
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 -- Collect all contract-related source pragmas found within the
kono
parents:
diff changeset
824 -- template and attach them to the contract of the package body.
kono
parents:
diff changeset
825 -- This contract is used in the capture of global references within
kono
parents:
diff changeset
826 -- annotations.
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 Create_Generic_Contract (N);
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 -- Update Body_Id to point to the copied node for the remainder of
kono
parents:
diff changeset
831 -- the processing.
kono
parents:
diff changeset
832
kono
parents:
diff changeset
833 Body_Id := Defining_Entity (N);
kono
parents:
diff changeset
834 Start_Generic;
kono
parents:
diff changeset
835 end if;
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 -- The Body_Id is that of the copied node in the generic case, the
kono
parents:
diff changeset
838 -- current node otherwise. Note that N was rewritten above, so we must
kono
parents:
diff changeset
839 -- be sure to get the latest Body_Id value.
kono
parents:
diff changeset
840
kono
parents:
diff changeset
841 Set_Ekind (Body_Id, E_Package_Body);
kono
parents:
diff changeset
842 Set_Body_Entity (Spec_Id, Body_Id);
kono
parents:
diff changeset
843 Set_Spec_Entity (Body_Id, Spec_Id);
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 -- Defining name for the package body is not a visible entity: Only the
kono
parents:
diff changeset
846 -- defining name for the declaration is visible.
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 Set_Etype (Body_Id, Standard_Void_Type);
kono
parents:
diff changeset
849 Set_Scope (Body_Id, Scope (Spec_Id));
kono
parents:
diff changeset
850 Set_Corresponding_Spec (N, Spec_Id);
kono
parents:
diff changeset
851 Set_Corresponding_Body (Pack_Decl, Body_Id);
kono
parents:
diff changeset
852
kono
parents:
diff changeset
853 -- The body entity is not used for semantics or code generation, but
kono
parents:
diff changeset
854 -- it is attached to the entity list of the enclosing scope to simplify
kono
parents:
diff changeset
855 -- the listing of back-annotations for the types it main contain.
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 if Scope (Spec_Id) /= Standard_Standard then
kono
parents:
diff changeset
858 Append_Entity (Body_Id, Scope (Spec_Id));
kono
parents:
diff changeset
859 end if;
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 -- Indicate that we are currently compiling the body of the package
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 Set_In_Package_Body (Spec_Id);
kono
parents:
diff changeset
864 Set_Has_Completion (Spec_Id);
kono
parents:
diff changeset
865 Last_Spec_Entity := Last_Entity (Spec_Id);
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867 if Has_Aspects (N) then
kono
parents:
diff changeset
868 Analyze_Aspect_Specifications (N, Body_Id);
kono
parents:
diff changeset
869 end if;
kono
parents:
diff changeset
870
kono
parents:
diff changeset
871 Push_Scope (Spec_Id);
kono
parents:
diff changeset
872
kono
parents:
diff changeset
873 -- Set SPARK_Mode only for non-generic package
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 if Ekind (Spec_Id) = E_Package then
kono
parents:
diff changeset
876 Set_SPARK_Pragma (Body_Id, SPARK_Mode_Pragma);
kono
parents:
diff changeset
877 Set_SPARK_Aux_Pragma (Body_Id, SPARK_Mode_Pragma);
kono
parents:
diff changeset
878 Set_SPARK_Pragma_Inherited (Body_Id);
kono
parents:
diff changeset
879 Set_SPARK_Aux_Pragma_Inherited (Body_Id);
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 -- A package body may be instantiated or inlined at a later pass.
kono
parents:
diff changeset
882 -- Restore the state of Ignore_SPARK_Mode_Pragmas_In_Instance when
kono
parents:
diff changeset
883 -- it applied to the package spec.
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 if Ignore_SPARK_Mode_Pragmas (Spec_Id) then
kono
parents:
diff changeset
886 Ignore_SPARK_Mode_Pragmas_In_Instance := True;
kono
parents:
diff changeset
887 end if;
kono
parents:
diff changeset
888 end if;
kono
parents:
diff changeset
889
kono
parents:
diff changeset
890 Set_Categorization_From_Pragmas (N);
kono
parents:
diff changeset
891
kono
parents:
diff changeset
892 Install_Visible_Declarations (Spec_Id);
kono
parents:
diff changeset
893 Install_Private_Declarations (Spec_Id);
kono
parents:
diff changeset
894 Install_Private_With_Clauses (Spec_Id);
kono
parents:
diff changeset
895 Install_Composite_Operations (Spec_Id);
kono
parents:
diff changeset
896
kono
parents:
diff changeset
897 Check_Anonymous_Access_Types (Spec_Id, N);
kono
parents:
diff changeset
898
kono
parents:
diff changeset
899 if Ekind (Spec_Id) = E_Generic_Package then
kono
parents:
diff changeset
900 Set_Use (Generic_Formal_Declarations (Pack_Decl));
kono
parents:
diff changeset
901 end if;
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 Set_Use (Visible_Declarations (Specification (Pack_Decl)));
kono
parents:
diff changeset
904 Set_Use (Private_Declarations (Specification (Pack_Decl)));
kono
parents:
diff changeset
905
kono
parents:
diff changeset
906 -- This is a nested package, so it may be necessary to declare certain
kono
parents:
diff changeset
907 -- inherited subprograms that are not yet visible because the parent
kono
parents:
diff changeset
908 -- type's subprograms are now visible.
kono
parents:
diff changeset
909
kono
parents:
diff changeset
910 if Ekind (Scope (Spec_Id)) = E_Package
kono
parents:
diff changeset
911 and then Scope (Spec_Id) /= Standard_Standard
kono
parents:
diff changeset
912 then
kono
parents:
diff changeset
913 Declare_Inherited_Private_Subprograms (Spec_Id);
kono
parents:
diff changeset
914 end if;
kono
parents:
diff changeset
915
kono
parents:
diff changeset
916 if Present (Declarations (N)) then
kono
parents:
diff changeset
917 Analyze_Declarations (Declarations (N));
kono
parents:
diff changeset
918 Inspect_Deferred_Constant_Completion (Declarations (N));
kono
parents:
diff changeset
919 end if;
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 -- Verify that the SPARK_Mode of the body agrees with that of its spec
kono
parents:
diff changeset
922
kono
parents:
diff changeset
923 if Present (SPARK_Pragma (Body_Id)) then
kono
parents:
diff changeset
924 if Present (SPARK_Aux_Pragma (Spec_Id)) then
kono
parents:
diff changeset
925 if Get_SPARK_Mode_From_Annotation (SPARK_Aux_Pragma (Spec_Id)) =
kono
parents:
diff changeset
926 Off
kono
parents:
diff changeset
927 and then
kono
parents:
diff changeset
928 Get_SPARK_Mode_From_Annotation (SPARK_Pragma (Body_Id)) = On
kono
parents:
diff changeset
929 then
kono
parents:
diff changeset
930 Error_Msg_Sloc := Sloc (SPARK_Pragma (Body_Id));
kono
parents:
diff changeset
931 Error_Msg_N ("incorrect application of SPARK_Mode#", N);
kono
parents:
diff changeset
932 Error_Msg_Sloc := Sloc (SPARK_Aux_Pragma (Spec_Id));
kono
parents:
diff changeset
933 Error_Msg_NE
kono
parents:
diff changeset
934 ("\value Off was set for SPARK_Mode on & #", N, Spec_Id);
kono
parents:
diff changeset
935 end if;
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 else
kono
parents:
diff changeset
938 Error_Msg_Sloc := Sloc (SPARK_Pragma (Body_Id));
kono
parents:
diff changeset
939 Error_Msg_N ("incorrect application of SPARK_Mode#", N);
kono
parents:
diff changeset
940 Error_Msg_Sloc := Sloc (Spec_Id);
kono
parents:
diff changeset
941 Error_Msg_NE
kono
parents:
diff changeset
942 ("\no value was set for SPARK_Mode on & #", N, Spec_Id);
kono
parents:
diff changeset
943 end if;
kono
parents:
diff changeset
944 end if;
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 -- Analyze_Declarations has caused freezing of all types. Now generate
kono
parents:
diff changeset
947 -- bodies for RACW primitives and stream attributes, if any.
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 if Ekind (Spec_Id) = E_Package and then Has_RACW (Spec_Id) then
kono
parents:
diff changeset
950
kono
parents:
diff changeset
951 -- Attach subprogram bodies to support RACWs declared in spec
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 Append_RACW_Bodies (Declarations (N), Spec_Id);
kono
parents:
diff changeset
954 Analyze_List (Declarations (N));
kono
parents:
diff changeset
955 end if;
kono
parents:
diff changeset
956
kono
parents:
diff changeset
957 HSS := Handled_Statement_Sequence (N);
kono
parents:
diff changeset
958
kono
parents:
diff changeset
959 if Present (HSS) then
kono
parents:
diff changeset
960 Process_End_Label (HSS, 't', Spec_Id);
kono
parents:
diff changeset
961 Analyze (HSS);
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 -- Check that elaboration code in a preelaborable package body is
kono
parents:
diff changeset
964 -- empty other than null statements and labels (RM 10.2.1(6)).
kono
parents:
diff changeset
965
kono
parents:
diff changeset
966 Validate_Null_Statement_Sequence (N);
kono
parents:
diff changeset
967 end if;
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 Validate_Categorization_Dependency (N, Spec_Id);
kono
parents:
diff changeset
970 Check_Completion (Body_Id);
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 -- Generate start of body reference. Note that we do this fairly late,
kono
parents:
diff changeset
973 -- because the call will use In_Extended_Main_Source_Unit as a check,
kono
parents:
diff changeset
974 -- and we want to make sure that Corresponding_Stub links are set
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 Generate_Reference (Spec_Id, Body_Id, 'b', Set_Ref => False);
kono
parents:
diff changeset
977
kono
parents:
diff changeset
978 -- For a generic package, collect global references and mark them on
kono
parents:
diff changeset
979 -- the original body so that they are not resolved again at the point
kono
parents:
diff changeset
980 -- of instantiation.
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 if Ekind (Spec_Id) /= E_Package then
kono
parents:
diff changeset
983 Save_Global_References (Original_Node (N));
kono
parents:
diff changeset
984 End_Generic;
kono
parents:
diff changeset
985 end if;
kono
parents:
diff changeset
986
kono
parents:
diff changeset
987 -- The entities of the package body have so far been chained onto the
kono
parents:
diff changeset
988 -- declaration chain for the spec. That's been fine while we were in the
kono
parents:
diff changeset
989 -- body, since we wanted them to be visible, but now that we are leaving
kono
parents:
diff changeset
990 -- the package body, they are no longer visible, so we remove them from
kono
parents:
diff changeset
991 -- the entity chain of the package spec entity, and copy them to the
kono
parents:
diff changeset
992 -- entity chain of the package body entity, where they will never again
kono
parents:
diff changeset
993 -- be visible.
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 if Present (Last_Spec_Entity) then
kono
parents:
diff changeset
996 Set_First_Entity (Body_Id, Next_Entity (Last_Spec_Entity));
kono
parents:
diff changeset
997 Set_Next_Entity (Last_Spec_Entity, Empty);
kono
parents:
diff changeset
998 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
kono
parents:
diff changeset
999 Set_Last_Entity (Spec_Id, Last_Spec_Entity);
kono
parents:
diff changeset
1000
kono
parents:
diff changeset
1001 else
kono
parents:
diff changeset
1002 Set_First_Entity (Body_Id, First_Entity (Spec_Id));
kono
parents:
diff changeset
1003 Set_Last_Entity (Body_Id, Last_Entity (Spec_Id));
kono
parents:
diff changeset
1004 Set_First_Entity (Spec_Id, Empty);
kono
parents:
diff changeset
1005 Set_Last_Entity (Spec_Id, Empty);
kono
parents:
diff changeset
1006 end if;
kono
parents:
diff changeset
1007
kono
parents:
diff changeset
1008 Update_Use_Clause_Chain;
kono
parents:
diff changeset
1009 End_Package_Scope (Spec_Id);
kono
parents:
diff changeset
1010
kono
parents:
diff changeset
1011 -- All entities declared in body are not visible
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 declare
kono
parents:
diff changeset
1014 E : Entity_Id;
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 begin
kono
parents:
diff changeset
1017 E := First_Entity (Body_Id);
kono
parents:
diff changeset
1018 while Present (E) loop
kono
parents:
diff changeset
1019 Set_Is_Immediately_Visible (E, False);
kono
parents:
diff changeset
1020 Set_Is_Potentially_Use_Visible (E, False);
kono
parents:
diff changeset
1021 Set_Is_Hidden (E);
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 -- Child units may appear on the entity list (e.g. if they appear
kono
parents:
diff changeset
1024 -- in the context of a subunit) but they are not body entities.
kono
parents:
diff changeset
1025
kono
parents:
diff changeset
1026 if not Is_Child_Unit (E) then
kono
parents:
diff changeset
1027 Set_Is_Package_Body_Entity (E);
kono
parents:
diff changeset
1028 end if;
kono
parents:
diff changeset
1029
kono
parents:
diff changeset
1030 Next_Entity (E);
kono
parents:
diff changeset
1031 end loop;
kono
parents:
diff changeset
1032 end;
kono
parents:
diff changeset
1033
kono
parents:
diff changeset
1034 Check_References (Body_Id);
kono
parents:
diff changeset
1035
kono
parents:
diff changeset
1036 -- For a generic unit, check that the formal parameters are referenced,
kono
parents:
diff changeset
1037 -- and that local variables are used, as for regular packages.
kono
parents:
diff changeset
1038
kono
parents:
diff changeset
1039 if Ekind (Spec_Id) = E_Generic_Package then
kono
parents:
diff changeset
1040 Check_References (Spec_Id);
kono
parents:
diff changeset
1041 end if;
kono
parents:
diff changeset
1042
kono
parents:
diff changeset
1043 -- At this point all entities of the package body are externally visible
kono
parents:
diff changeset
1044 -- to the linker as their Is_Public flag is set to True. This proactive
kono
parents:
diff changeset
1045 -- approach is necessary because an inlined or a generic body for which
kono
parents:
diff changeset
1046 -- code is generated in other units may need to see these entities. Cut
kono
parents:
diff changeset
1047 -- down the number of global symbols that do not neet public visibility
kono
parents:
diff changeset
1048 -- as this has two beneficial effects:
kono
parents:
diff changeset
1049 -- (1) It makes the compilation process more efficient.
kono
parents:
diff changeset
1050 -- (2) It gives the code generator more leeway to optimize within each
kono
parents:
diff changeset
1051 -- unit, especially subprograms.
kono
parents:
diff changeset
1052
kono
parents:
diff changeset
1053 -- This is done only for top-level library packages or child units as
kono
parents:
diff changeset
1054 -- the algorithm does a top-down traversal of the package body.
kono
parents:
diff changeset
1055
kono
parents:
diff changeset
1056 if (Scope (Spec_Id) = Standard_Standard or else Is_Child_Unit (Spec_Id))
kono
parents:
diff changeset
1057 and then not Is_Generic_Unit (Spec_Id)
kono
parents:
diff changeset
1058 then
kono
parents:
diff changeset
1059 Hide_Public_Entities (Declarations (N));
kono
parents:
diff changeset
1060 end if;
kono
parents:
diff changeset
1061
kono
parents:
diff changeset
1062 -- If expander is not active, then here is where we turn off the
kono
parents:
diff changeset
1063 -- In_Package_Body flag, otherwise it is turned off at the end of the
kono
parents:
diff changeset
1064 -- corresponding expansion routine. If this is an instance body, we need
kono
parents:
diff changeset
1065 -- to qualify names of local entities, because the body may have been
kono
parents:
diff changeset
1066 -- compiled as a preliminary to another instantiation.
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 if not Expander_Active then
kono
parents:
diff changeset
1069 Set_In_Package_Body (Spec_Id, False);
kono
parents:
diff changeset
1070
kono
parents:
diff changeset
1071 if Is_Generic_Instance (Spec_Id)
kono
parents:
diff changeset
1072 and then Operating_Mode = Generate_Code
kono
parents:
diff changeset
1073 then
kono
parents:
diff changeset
1074 Qualify_Entity_Names (N);
kono
parents:
diff changeset
1075 end if;
kono
parents:
diff changeset
1076 end if;
kono
parents:
diff changeset
1077
kono
parents:
diff changeset
1078 Ignore_SPARK_Mode_Pragmas_In_Instance := Saved_ISMP;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1079 Restore_Ghost_Region (Saved_GM, Saved_IGR);
111
kono
parents:
diff changeset
1080 end Analyze_Package_Body_Helper;
kono
parents:
diff changeset
1081
kono
parents:
diff changeset
1082 ---------------------------------
kono
parents:
diff changeset
1083 -- Analyze_Package_Declaration --
kono
parents:
diff changeset
1084 ---------------------------------
kono
parents:
diff changeset
1085
kono
parents:
diff changeset
1086 procedure Analyze_Package_Declaration (N : Node_Id) is
kono
parents:
diff changeset
1087 Id : constant Node_Id := Defining_Entity (N);
kono
parents:
diff changeset
1088
kono
parents:
diff changeset
1089 Is_Comp_Unit : constant Boolean :=
kono
parents:
diff changeset
1090 Nkind (Parent (N)) = N_Compilation_Unit;
kono
parents:
diff changeset
1091
kono
parents:
diff changeset
1092 Body_Required : Boolean;
kono
parents:
diff changeset
1093 -- True when this package declaration requires a corresponding body
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 begin
kono
parents:
diff changeset
1096 if Debug_Flag_C then
kono
parents:
diff changeset
1097 Write_Str ("==> package spec ");
kono
parents:
diff changeset
1098 Write_Name (Chars (Id));
kono
parents:
diff changeset
1099 Write_Str (" from ");
kono
parents:
diff changeset
1100 Write_Location (Sloc (N));
kono
parents:
diff changeset
1101 Write_Eol;
kono
parents:
diff changeset
1102 Indent;
kono
parents:
diff changeset
1103 end if;
kono
parents:
diff changeset
1104
kono
parents:
diff changeset
1105 Generate_Definition (Id);
kono
parents:
diff changeset
1106 Enter_Name (Id);
kono
parents:
diff changeset
1107 Set_Ekind (Id, E_Package);
kono
parents:
diff changeset
1108 Set_Etype (Id, Standard_Void_Type);
kono
parents:
diff changeset
1109
kono
parents:
diff changeset
1110 -- Set SPARK_Mode from context
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
kono
parents:
diff changeset
1113 Set_SPARK_Aux_Pragma (Id, SPARK_Mode_Pragma);
kono
parents:
diff changeset
1114 Set_SPARK_Pragma_Inherited (Id);
kono
parents:
diff changeset
1115 Set_SPARK_Aux_Pragma_Inherited (Id);
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 -- Save the state of flag Ignore_SPARK_Mode_Pragmas_In_Instance in case
kono
parents:
diff changeset
1118 -- the body of this package is instantiated or inlined later and out of
kono
parents:
diff changeset
1119 -- context. The body uses this attribute to restore the value of the
kono
parents:
diff changeset
1120 -- global flag.
kono
parents:
diff changeset
1121
kono
parents:
diff changeset
1122 if Ignore_SPARK_Mode_Pragmas_In_Instance then
kono
parents:
diff changeset
1123 Set_Ignore_SPARK_Mode_Pragmas (Id);
kono
parents:
diff changeset
1124 end if;
kono
parents:
diff changeset
1125
kono
parents:
diff changeset
1126 -- Analyze aspect specifications immediately, since we need to recognize
kono
parents:
diff changeset
1127 -- things like Pure early enough to diagnose violations during analysis.
kono
parents:
diff changeset
1128
kono
parents:
diff changeset
1129 if Has_Aspects (N) then
kono
parents:
diff changeset
1130 Analyze_Aspect_Specifications (N, Id);
kono
parents:
diff changeset
1131 end if;
kono
parents:
diff changeset
1132
kono
parents:
diff changeset
1133 -- Ada 2005 (AI-217): Check if the package has been illegally named in
kono
parents:
diff changeset
1134 -- a limited-with clause of its own context. In this case the error has
kono
parents:
diff changeset
1135 -- been previously notified by Analyze_Context.
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 -- limited with Pkg; -- ERROR
kono
parents:
diff changeset
1138 -- package Pkg is ...
kono
parents:
diff changeset
1139
kono
parents:
diff changeset
1140 if From_Limited_With (Id) then
kono
parents:
diff changeset
1141 return;
kono
parents:
diff changeset
1142 end if;
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 Push_Scope (Id);
kono
parents:
diff changeset
1145
kono
parents:
diff changeset
1146 Set_Is_Pure (Id, Is_Pure (Enclosing_Lib_Unit_Entity));
kono
parents:
diff changeset
1147 Set_Categorization_From_Pragmas (N);
kono
parents:
diff changeset
1148
kono
parents:
diff changeset
1149 Analyze (Specification (N));
kono
parents:
diff changeset
1150 Validate_Categorization_Dependency (N, Id);
kono
parents:
diff changeset
1151
kono
parents:
diff changeset
1152 -- Determine whether the package requires a body. Abstract states are
kono
parents:
diff changeset
1153 -- intentionally ignored because they do require refinement which can
kono
parents:
diff changeset
1154 -- only come in a body, but at the same time they do not force the need
kono
parents:
diff changeset
1155 -- for a body on their own (SPARK RM 7.1.4(4) and 7.2.2(3)).
kono
parents:
diff changeset
1156
kono
parents:
diff changeset
1157 Body_Required := Unit_Requires_Body (Id);
kono
parents:
diff changeset
1158
kono
parents:
diff changeset
1159 if not Body_Required then
kono
parents:
diff changeset
1160
kono
parents:
diff changeset
1161 -- If the package spec does not require an explicit body, then there
kono
parents:
diff changeset
1162 -- are not entities requiring completion in the language sense. Call
kono
parents:
diff changeset
1163 -- Check_Completion now to ensure that nested package declarations
kono
parents:
diff changeset
1164 -- that require an implicit body get one. (In the case where a body
kono
parents:
diff changeset
1165 -- is required, Check_Completion is called at the end of the body's
kono
parents:
diff changeset
1166 -- declarative part.)
kono
parents:
diff changeset
1167
kono
parents:
diff changeset
1168 Check_Completion;
kono
parents:
diff changeset
1169
kono
parents:
diff changeset
1170 -- If the package spec does not require an explicit body, then all
kono
parents:
diff changeset
1171 -- abstract states declared in nested packages cannot possibly get
kono
parents:
diff changeset
1172 -- a proper refinement (SPARK RM 7.2.2(3)). This check is performed
kono
parents:
diff changeset
1173 -- only when the compilation unit is the main unit to allow for
kono
parents:
diff changeset
1174 -- modular SPARK analysis where packages do not necessarily have
kono
parents:
diff changeset
1175 -- bodies.
kono
parents:
diff changeset
1176
kono
parents:
diff changeset
1177 if Is_Comp_Unit then
kono
parents:
diff changeset
1178 Check_State_Refinements
kono
parents:
diff changeset
1179 (Context => N,
kono
parents:
diff changeset
1180 Is_Main_Unit => Parent (N) = Cunit (Main_Unit));
kono
parents:
diff changeset
1181 end if;
kono
parents:
diff changeset
1182 end if;
kono
parents:
diff changeset
1183
kono
parents:
diff changeset
1184 -- Set Body_Required indication on the compilation unit node
kono
parents:
diff changeset
1185
kono
parents:
diff changeset
1186 if Is_Comp_Unit then
kono
parents:
diff changeset
1187 Set_Body_Required (Parent (N), Body_Required);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1188
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1189 if Legacy_Elaboration_Checks and not Body_Required then
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1190 Set_Suppress_Elaboration_Warnings (Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1191 end if;
111
kono
parents:
diff changeset
1192 end if;
kono
parents:
diff changeset
1193
kono
parents:
diff changeset
1194 End_Package_Scope (Id);
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 -- For the declaration of a library unit that is a remote types package,
kono
parents:
diff changeset
1197 -- check legality rules regarding availability of stream attributes for
kono
parents:
diff changeset
1198 -- types that contain non-remote access values. This subprogram performs
kono
parents:
diff changeset
1199 -- visibility tests that rely on the fact that we have exited the scope
kono
parents:
diff changeset
1200 -- of Id.
kono
parents:
diff changeset
1201
kono
parents:
diff changeset
1202 if Is_Comp_Unit then
kono
parents:
diff changeset
1203 Validate_RT_RAT_Component (N);
kono
parents:
diff changeset
1204 end if;
kono
parents:
diff changeset
1205
kono
parents:
diff changeset
1206 if Debug_Flag_C then
kono
parents:
diff changeset
1207 Outdent;
kono
parents:
diff changeset
1208 Write_Str ("<== package spec ");
kono
parents:
diff changeset
1209 Write_Name (Chars (Id));
kono
parents:
diff changeset
1210 Write_Str (" from ");
kono
parents:
diff changeset
1211 Write_Location (Sloc (N));
kono
parents:
diff changeset
1212 Write_Eol;
kono
parents:
diff changeset
1213 end if;
kono
parents:
diff changeset
1214 end Analyze_Package_Declaration;
kono
parents:
diff changeset
1215
kono
parents:
diff changeset
1216 -----------------------------------
kono
parents:
diff changeset
1217 -- Analyze_Package_Specification --
kono
parents:
diff changeset
1218 -----------------------------------
kono
parents:
diff changeset
1219
kono
parents:
diff changeset
1220 -- Note that this code is shared for the analysis of generic package specs
kono
parents:
diff changeset
1221 -- (see Sem_Ch12.Analyze_Generic_Package_Declaration for details).
kono
parents:
diff changeset
1222
kono
parents:
diff changeset
1223 procedure Analyze_Package_Specification (N : Node_Id) is
kono
parents:
diff changeset
1224 Id : constant Entity_Id := Defining_Entity (N);
kono
parents:
diff changeset
1225 Orig_Decl : constant Node_Id := Original_Node (Parent (N));
kono
parents:
diff changeset
1226 Vis_Decls : constant List_Id := Visible_Declarations (N);
kono
parents:
diff changeset
1227 Priv_Decls : constant List_Id := Private_Declarations (N);
kono
parents:
diff changeset
1228 E : Entity_Id;
kono
parents:
diff changeset
1229 L : Entity_Id;
kono
parents:
diff changeset
1230 Public_Child : Boolean;
kono
parents:
diff changeset
1231
kono
parents:
diff changeset
1232 Private_With_Clauses_Installed : Boolean := False;
kono
parents:
diff changeset
1233 -- In Ada 2005, private with_clauses are visible in the private part
kono
parents:
diff changeset
1234 -- of a nested package, even if it appears in the public part of the
kono
parents:
diff changeset
1235 -- enclosing package. This requires a separate step to install these
kono
parents:
diff changeset
1236 -- private_with_clauses, and remove them at the end of the nested
kono
parents:
diff changeset
1237 -- package.
kono
parents:
diff changeset
1238
kono
parents:
diff changeset
1239 procedure Check_One_Tagged_Type_Or_Extension_At_Most;
kono
parents:
diff changeset
1240 -- Issue an error in SPARK mode if a package specification contains
kono
parents:
diff changeset
1241 -- more than one tagged type or type extension.
kono
parents:
diff changeset
1242
kono
parents:
diff changeset
1243 procedure Clear_Constants (Id : Entity_Id; FE : Entity_Id);
kono
parents:
diff changeset
1244 -- Clears constant indications (Never_Set_In_Source, Constant_Value, and
kono
parents:
diff changeset
1245 -- Is_True_Constant) on all variables that are entities of Id, and on
kono
parents:
diff changeset
1246 -- the chain whose first element is FE. A recursive call is made for all
kono
parents:
diff changeset
1247 -- packages and generic packages.
kono
parents:
diff changeset
1248
kono
parents:
diff changeset
1249 procedure Generate_Parent_References;
kono
parents:
diff changeset
1250 -- For a child unit, generate references to parent units, for
kono
parents:
diff changeset
1251 -- GPS navigation purposes.
kono
parents:
diff changeset
1252
kono
parents:
diff changeset
1253 function Is_Public_Child (Child, Unit : Entity_Id) return Boolean;
kono
parents:
diff changeset
1254 -- Child and Unit are entities of compilation units. True if Child
kono
parents:
diff changeset
1255 -- is a public child of Parent as defined in 10.1.1
kono
parents:
diff changeset
1256
kono
parents:
diff changeset
1257 procedure Inspect_Unchecked_Union_Completion (Decls : List_Id);
kono
parents:
diff changeset
1258 -- Reject completion of an incomplete or private type declarations
kono
parents:
diff changeset
1259 -- having a known discriminant part by an unchecked union.
kono
parents:
diff changeset
1260
kono
parents:
diff changeset
1261 procedure Install_Parent_Private_Declarations (Inst_Id : Entity_Id);
kono
parents:
diff changeset
1262 -- Given the package entity of a generic package instantiation or
kono
parents:
diff changeset
1263 -- formal package whose corresponding generic is a child unit, installs
kono
parents:
diff changeset
1264 -- the private declarations of each of the child unit's parents.
kono
parents:
diff changeset
1265 -- This has to be done at the point of entering the instance package's
kono
parents:
diff changeset
1266 -- private part rather than being done in Sem_Ch12.Install_Parent
kono
parents:
diff changeset
1267 -- (which is where the parents' visible declarations are installed).
kono
parents:
diff changeset
1268
kono
parents:
diff changeset
1269 ------------------------------------------------
kono
parents:
diff changeset
1270 -- Check_One_Tagged_Type_Or_Extension_At_Most --
kono
parents:
diff changeset
1271 ------------------------------------------------
kono
parents:
diff changeset
1272
kono
parents:
diff changeset
1273 procedure Check_One_Tagged_Type_Or_Extension_At_Most is
kono
parents:
diff changeset
1274 Previous : Node_Id;
kono
parents:
diff changeset
1275
kono
parents:
diff changeset
1276 procedure Check_Decls (Decls : List_Id);
kono
parents:
diff changeset
1277 -- Check that either Previous is Empty and Decls does not contain
kono
parents:
diff changeset
1278 -- more than one tagged type or type extension, or Previous is
kono
parents:
diff changeset
1279 -- already set and Decls contains no tagged type or type extension.
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 -----------------
kono
parents:
diff changeset
1282 -- Check_Decls --
kono
parents:
diff changeset
1283 -----------------
kono
parents:
diff changeset
1284
kono
parents:
diff changeset
1285 procedure Check_Decls (Decls : List_Id) is
kono
parents:
diff changeset
1286 Decl : Node_Id;
kono
parents:
diff changeset
1287
kono
parents:
diff changeset
1288 begin
kono
parents:
diff changeset
1289 Decl := First (Decls);
kono
parents:
diff changeset
1290 while Present (Decl) loop
kono
parents:
diff changeset
1291 if Nkind (Decl) = N_Full_Type_Declaration
kono
parents:
diff changeset
1292 and then Is_Tagged_Type (Defining_Identifier (Decl))
kono
parents:
diff changeset
1293 then
kono
parents:
diff changeset
1294 if No (Previous) then
kono
parents:
diff changeset
1295 Previous := Decl;
kono
parents:
diff changeset
1296
kono
parents:
diff changeset
1297 else
kono
parents:
diff changeset
1298 Error_Msg_Sloc := Sloc (Previous);
kono
parents:
diff changeset
1299 Check_SPARK_05_Restriction
kono
parents:
diff changeset
1300 ("at most one tagged type or type extension allowed",
kono
parents:
diff changeset
1301 "\\ previous declaration#",
kono
parents:
diff changeset
1302 Decl);
kono
parents:
diff changeset
1303 end if;
kono
parents:
diff changeset
1304 end if;
kono
parents:
diff changeset
1305
kono
parents:
diff changeset
1306 Next (Decl);
kono
parents:
diff changeset
1307 end loop;
kono
parents:
diff changeset
1308 end Check_Decls;
kono
parents:
diff changeset
1309
kono
parents:
diff changeset
1310 -- Start of processing for Check_One_Tagged_Type_Or_Extension_At_Most
kono
parents:
diff changeset
1311
kono
parents:
diff changeset
1312 begin
kono
parents:
diff changeset
1313 Previous := Empty;
kono
parents:
diff changeset
1314 Check_Decls (Vis_Decls);
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 if Present (Priv_Decls) then
kono
parents:
diff changeset
1317 Check_Decls (Priv_Decls);
kono
parents:
diff changeset
1318 end if;
kono
parents:
diff changeset
1319 end Check_One_Tagged_Type_Or_Extension_At_Most;
kono
parents:
diff changeset
1320
kono
parents:
diff changeset
1321 ---------------------
kono
parents:
diff changeset
1322 -- Clear_Constants --
kono
parents:
diff changeset
1323 ---------------------
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 procedure Clear_Constants (Id : Entity_Id; FE : Entity_Id) is
kono
parents:
diff changeset
1326 E : Entity_Id;
kono
parents:
diff changeset
1327
kono
parents:
diff changeset
1328 begin
kono
parents:
diff changeset
1329 -- Ignore package renamings, not interesting and they can cause self
kono
parents:
diff changeset
1330 -- referential loops in the code below.
kono
parents:
diff changeset
1331
kono
parents:
diff changeset
1332 if Nkind (Parent (Id)) = N_Package_Renaming_Declaration then
kono
parents:
diff changeset
1333 return;
kono
parents:
diff changeset
1334 end if;
kono
parents:
diff changeset
1335
kono
parents:
diff changeset
1336 -- Note: in the loop below, the check for Next_Entity pointing back
kono
parents:
diff changeset
1337 -- to the package entity may seem odd, but it is needed, because a
kono
parents:
diff changeset
1338 -- package can contain a renaming declaration to itself, and such
kono
parents:
diff changeset
1339 -- renamings are generated automatically within package instances.
kono
parents:
diff changeset
1340
kono
parents:
diff changeset
1341 E := FE;
kono
parents:
diff changeset
1342 while Present (E) and then E /= Id loop
kono
parents:
diff changeset
1343 if Is_Assignable (E) then
kono
parents:
diff changeset
1344 Set_Never_Set_In_Source (E, False);
kono
parents:
diff changeset
1345 Set_Is_True_Constant (E, False);
kono
parents:
diff changeset
1346 Set_Current_Value (E, Empty);
kono
parents:
diff changeset
1347 Set_Is_Known_Null (E, False);
kono
parents:
diff changeset
1348 Set_Last_Assignment (E, Empty);
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 if not Can_Never_Be_Null (E) then
kono
parents:
diff changeset
1351 Set_Is_Known_Non_Null (E, False);
kono
parents:
diff changeset
1352 end if;
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354 elsif Is_Package_Or_Generic_Package (E) then
kono
parents:
diff changeset
1355 Clear_Constants (E, First_Entity (E));
kono
parents:
diff changeset
1356 Clear_Constants (E, First_Private_Entity (E));
kono
parents:
diff changeset
1357 end if;
kono
parents:
diff changeset
1358
kono
parents:
diff changeset
1359 Next_Entity (E);
kono
parents:
diff changeset
1360 end loop;
kono
parents:
diff changeset
1361 end Clear_Constants;
kono
parents:
diff changeset
1362
kono
parents:
diff changeset
1363 --------------------------------
kono
parents:
diff changeset
1364 -- Generate_Parent_References --
kono
parents:
diff changeset
1365 --------------------------------
kono
parents:
diff changeset
1366
kono
parents:
diff changeset
1367 procedure Generate_Parent_References is
kono
parents:
diff changeset
1368 Decl : constant Node_Id := Parent (N);
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370 begin
kono
parents:
diff changeset
1371 if Id = Cunit_Entity (Main_Unit)
kono
parents:
diff changeset
1372 or else Parent (Decl) = Library_Unit (Cunit (Main_Unit))
kono
parents:
diff changeset
1373 then
kono
parents:
diff changeset
1374 Generate_Reference (Id, Scope (Id), 'k', False);
kono
parents:
diff changeset
1375
kono
parents:
diff changeset
1376 elsif not Nkind_In (Unit (Cunit (Main_Unit)), N_Subprogram_Body,
kono
parents:
diff changeset
1377 N_Subunit)
kono
parents:
diff changeset
1378 then
kono
parents:
diff changeset
1379 -- If current unit is an ancestor of main unit, generate a
kono
parents:
diff changeset
1380 -- reference to its own parent.
kono
parents:
diff changeset
1381
kono
parents:
diff changeset
1382 declare
kono
parents:
diff changeset
1383 U : Node_Id;
kono
parents:
diff changeset
1384 Main_Spec : Node_Id := Unit (Cunit (Main_Unit));
kono
parents:
diff changeset
1385
kono
parents:
diff changeset
1386 begin
kono
parents:
diff changeset
1387 if Nkind (Main_Spec) = N_Package_Body then
kono
parents:
diff changeset
1388 Main_Spec := Unit (Library_Unit (Cunit (Main_Unit)));
kono
parents:
diff changeset
1389 end if;
kono
parents:
diff changeset
1390
kono
parents:
diff changeset
1391 U := Parent_Spec (Main_Spec);
kono
parents:
diff changeset
1392 while Present (U) loop
kono
parents:
diff changeset
1393 if U = Parent (Decl) then
kono
parents:
diff changeset
1394 Generate_Reference (Id, Scope (Id), 'k', False);
kono
parents:
diff changeset
1395 exit;
kono
parents:
diff changeset
1396
kono
parents:
diff changeset
1397 elsif Nkind (Unit (U)) = N_Package_Body then
kono
parents:
diff changeset
1398 exit;
kono
parents:
diff changeset
1399
kono
parents:
diff changeset
1400 else
kono
parents:
diff changeset
1401 U := Parent_Spec (Unit (U));
kono
parents:
diff changeset
1402 end if;
kono
parents:
diff changeset
1403 end loop;
kono
parents:
diff changeset
1404 end;
kono
parents:
diff changeset
1405 end if;
kono
parents:
diff changeset
1406 end Generate_Parent_References;
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 ---------------------
kono
parents:
diff changeset
1409 -- Is_Public_Child --
kono
parents:
diff changeset
1410 ---------------------
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 function Is_Public_Child (Child, Unit : Entity_Id) return Boolean is
kono
parents:
diff changeset
1413 begin
kono
parents:
diff changeset
1414 if not Is_Private_Descendant (Child) then
kono
parents:
diff changeset
1415 return True;
kono
parents:
diff changeset
1416 else
kono
parents:
diff changeset
1417 if Child = Unit then
kono
parents:
diff changeset
1418 return not Private_Present (
kono
parents:
diff changeset
1419 Parent (Unit_Declaration_Node (Child)));
kono
parents:
diff changeset
1420 else
kono
parents:
diff changeset
1421 return Is_Public_Child (Scope (Child), Unit);
kono
parents:
diff changeset
1422 end if;
kono
parents:
diff changeset
1423 end if;
kono
parents:
diff changeset
1424 end Is_Public_Child;
kono
parents:
diff changeset
1425
kono
parents:
diff changeset
1426 ----------------------------------------
kono
parents:
diff changeset
1427 -- Inspect_Unchecked_Union_Completion --
kono
parents:
diff changeset
1428 ----------------------------------------
kono
parents:
diff changeset
1429
kono
parents:
diff changeset
1430 procedure Inspect_Unchecked_Union_Completion (Decls : List_Id) is
kono
parents:
diff changeset
1431 Decl : Node_Id;
kono
parents:
diff changeset
1432
kono
parents:
diff changeset
1433 begin
kono
parents:
diff changeset
1434 Decl := First (Decls);
kono
parents:
diff changeset
1435 while Present (Decl) loop
kono
parents:
diff changeset
1436
kono
parents:
diff changeset
1437 -- We are looking at an incomplete or private type declaration
kono
parents:
diff changeset
1438 -- with a known_discriminant_part whose full view is an
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1439 -- Unchecked_Union. The seemingly useless check with Is_Type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1440 -- prevents cascaded errors when routines defined only for type
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1441 -- entities are called with non-type entities.
111
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 if Nkind_In (Decl, N_Incomplete_Type_Declaration,
kono
parents:
diff changeset
1444 N_Private_Type_Declaration)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1445 and then Is_Type (Defining_Identifier (Decl))
111
kono
parents:
diff changeset
1446 and then Has_Discriminants (Defining_Identifier (Decl))
kono
parents:
diff changeset
1447 and then Present (Full_View (Defining_Identifier (Decl)))
kono
parents:
diff changeset
1448 and then
kono
parents:
diff changeset
1449 Is_Unchecked_Union (Full_View (Defining_Identifier (Decl)))
kono
parents:
diff changeset
1450 then
kono
parents:
diff changeset
1451 Error_Msg_N
kono
parents:
diff changeset
1452 ("completion of discriminated partial view "
kono
parents:
diff changeset
1453 & "cannot be an unchecked union",
kono
parents:
diff changeset
1454 Full_View (Defining_Identifier (Decl)));
kono
parents:
diff changeset
1455 end if;
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 Next (Decl);
kono
parents:
diff changeset
1458 end loop;
kono
parents:
diff changeset
1459 end Inspect_Unchecked_Union_Completion;
kono
parents:
diff changeset
1460
kono
parents:
diff changeset
1461 -----------------------------------------
kono
parents:
diff changeset
1462 -- Install_Parent_Private_Declarations --
kono
parents:
diff changeset
1463 -----------------------------------------
kono
parents:
diff changeset
1464
kono
parents:
diff changeset
1465 procedure Install_Parent_Private_Declarations (Inst_Id : Entity_Id) is
kono
parents:
diff changeset
1466 Inst_Par : Entity_Id;
kono
parents:
diff changeset
1467 Gen_Par : Entity_Id;
kono
parents:
diff changeset
1468 Inst_Node : Node_Id;
kono
parents:
diff changeset
1469
kono
parents:
diff changeset
1470 begin
kono
parents:
diff changeset
1471 Inst_Par := Inst_Id;
kono
parents:
diff changeset
1472
kono
parents:
diff changeset
1473 Gen_Par :=
kono
parents:
diff changeset
1474 Generic_Parent (Specification (Unit_Declaration_Node (Inst_Par)));
kono
parents:
diff changeset
1475 while Present (Gen_Par) and then Is_Child_Unit (Gen_Par) loop
kono
parents:
diff changeset
1476 Inst_Node := Get_Unit_Instantiation_Node (Inst_Par);
kono
parents:
diff changeset
1477
kono
parents:
diff changeset
1478 if Nkind_In (Inst_Node, N_Package_Instantiation,
kono
parents:
diff changeset
1479 N_Formal_Package_Declaration)
kono
parents:
diff changeset
1480 and then Nkind (Name (Inst_Node)) = N_Expanded_Name
kono
parents:
diff changeset
1481 then
kono
parents:
diff changeset
1482 Inst_Par := Entity (Prefix (Name (Inst_Node)));
kono
parents:
diff changeset
1483
kono
parents:
diff changeset
1484 if Present (Renamed_Entity (Inst_Par)) then
kono
parents:
diff changeset
1485 Inst_Par := Renamed_Entity (Inst_Par);
kono
parents:
diff changeset
1486 end if;
kono
parents:
diff changeset
1487
kono
parents:
diff changeset
1488 Gen_Par :=
kono
parents:
diff changeset
1489 Generic_Parent
kono
parents:
diff changeset
1490 (Specification (Unit_Declaration_Node (Inst_Par)));
kono
parents:
diff changeset
1491
kono
parents:
diff changeset
1492 -- Install the private declarations and private use clauses
kono
parents:
diff changeset
1493 -- of a parent instance of the child instance, unless the
kono
parents:
diff changeset
1494 -- parent instance private declarations have already been
kono
parents:
diff changeset
1495 -- installed earlier in Analyze_Package_Specification, which
kono
parents:
diff changeset
1496 -- happens when a generic child is instantiated, and the
kono
parents:
diff changeset
1497 -- instance is a child of the parent instance.
kono
parents:
diff changeset
1498
kono
parents:
diff changeset
1499 -- Installing the use clauses of the parent instance twice
kono
parents:
diff changeset
1500 -- is both unnecessary and wrong, because it would cause the
kono
parents:
diff changeset
1501 -- clauses to be chained to themselves in the use clauses
kono
parents:
diff changeset
1502 -- list of the scope stack entry. That in turn would cause
kono
parents:
diff changeset
1503 -- an endless loop from End_Use_Clauses upon scope exit.
kono
parents:
diff changeset
1504
kono
parents:
diff changeset
1505 -- The parent is now fully visible. It may be a hidden open
kono
parents:
diff changeset
1506 -- scope if we are currently compiling some child instance
kono
parents:
diff changeset
1507 -- declared within it, but while the current instance is being
kono
parents:
diff changeset
1508 -- compiled the parent is immediately visible. In particular
kono
parents:
diff changeset
1509 -- its entities must remain visible if a stack save/restore
kono
parents:
diff changeset
1510 -- takes place through a call to Rtsfind.
kono
parents:
diff changeset
1511
kono
parents:
diff changeset
1512 if Present (Gen_Par) then
kono
parents:
diff changeset
1513 if not In_Private_Part (Inst_Par) then
kono
parents:
diff changeset
1514 Install_Private_Declarations (Inst_Par);
kono
parents:
diff changeset
1515 Set_Use (Private_Declarations
kono
parents:
diff changeset
1516 (Specification
kono
parents:
diff changeset
1517 (Unit_Declaration_Node (Inst_Par))));
kono
parents:
diff changeset
1518 Set_Is_Hidden_Open_Scope (Inst_Par, False);
kono
parents:
diff changeset
1519 end if;
kono
parents:
diff changeset
1520
kono
parents:
diff changeset
1521 -- If we've reached the end of the generic instance parents,
kono
parents:
diff changeset
1522 -- then finish off by looping through the nongeneric parents
kono
parents:
diff changeset
1523 -- and installing their private declarations.
kono
parents:
diff changeset
1524
kono
parents:
diff changeset
1525 -- If one of the non-generic parents is itself on the scope
kono
parents:
diff changeset
1526 -- stack, do not install its private declarations: they are
kono
parents:
diff changeset
1527 -- installed in due time when the private part of that parent
kono
parents:
diff changeset
1528 -- is analyzed.
kono
parents:
diff changeset
1529
kono
parents:
diff changeset
1530 else
kono
parents:
diff changeset
1531 while Present (Inst_Par)
kono
parents:
diff changeset
1532 and then Inst_Par /= Standard_Standard
kono
parents:
diff changeset
1533 and then (not In_Open_Scopes (Inst_Par)
kono
parents:
diff changeset
1534 or else not In_Private_Part (Inst_Par))
kono
parents:
diff changeset
1535 loop
kono
parents:
diff changeset
1536 if Nkind (Inst_Node) = N_Formal_Package_Declaration
kono
parents:
diff changeset
1537 or else
kono
parents:
diff changeset
1538 not Is_Ancestor_Package
kono
parents:
diff changeset
1539 (Inst_Par, Cunit_Entity (Current_Sem_Unit))
kono
parents:
diff changeset
1540 then
kono
parents:
diff changeset
1541 Install_Private_Declarations (Inst_Par);
kono
parents:
diff changeset
1542 Set_Use
kono
parents:
diff changeset
1543 (Private_Declarations
kono
parents:
diff changeset
1544 (Specification
kono
parents:
diff changeset
1545 (Unit_Declaration_Node (Inst_Par))));
kono
parents:
diff changeset
1546 Inst_Par := Scope (Inst_Par);
kono
parents:
diff changeset
1547 else
kono
parents:
diff changeset
1548 exit;
kono
parents:
diff changeset
1549 end if;
kono
parents:
diff changeset
1550 end loop;
kono
parents:
diff changeset
1551
kono
parents:
diff changeset
1552 exit;
kono
parents:
diff changeset
1553 end if;
kono
parents:
diff changeset
1554
kono
parents:
diff changeset
1555 else
kono
parents:
diff changeset
1556 exit;
kono
parents:
diff changeset
1557 end if;
kono
parents:
diff changeset
1558 end loop;
kono
parents:
diff changeset
1559 end Install_Parent_Private_Declarations;
kono
parents:
diff changeset
1560
kono
parents:
diff changeset
1561 -- Start of processing for Analyze_Package_Specification
kono
parents:
diff changeset
1562
kono
parents:
diff changeset
1563 begin
kono
parents:
diff changeset
1564 if Present (Vis_Decls) then
kono
parents:
diff changeset
1565 Analyze_Declarations (Vis_Decls);
kono
parents:
diff changeset
1566 end if;
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 -- Inspect the entities defined in the package and ensure that all
kono
parents:
diff changeset
1569 -- incomplete types have received full declarations. Build default
kono
parents:
diff changeset
1570 -- initial condition and invariant procedures for all qualifying types.
kono
parents:
diff changeset
1571
kono
parents:
diff changeset
1572 E := First_Entity (Id);
kono
parents:
diff changeset
1573 while Present (E) loop
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 -- Check on incomplete types
kono
parents:
diff changeset
1576
kono
parents:
diff changeset
1577 -- AI05-0213: A formal incomplete type has no completion, and neither
kono
parents:
diff changeset
1578 -- does the corresponding subtype in an instance.
kono
parents:
diff changeset
1579
kono
parents:
diff changeset
1580 if Is_Incomplete_Type (E)
kono
parents:
diff changeset
1581 and then No (Full_View (E))
kono
parents:
diff changeset
1582 and then not Is_Generic_Type (E)
kono
parents:
diff changeset
1583 and then not From_Limited_With (E)
kono
parents:
diff changeset
1584 and then not Is_Generic_Actual_Type (E)
kono
parents:
diff changeset
1585 then
kono
parents:
diff changeset
1586 Error_Msg_N ("no declaration in visible part for incomplete}", E);
kono
parents:
diff changeset
1587 end if;
kono
parents:
diff changeset
1588
kono
parents:
diff changeset
1589 Next_Entity (E);
kono
parents:
diff changeset
1590 end loop;
kono
parents:
diff changeset
1591
kono
parents:
diff changeset
1592 if Is_Remote_Call_Interface (Id)
kono
parents:
diff changeset
1593 and then Nkind (Parent (Parent (N))) = N_Compilation_Unit
kono
parents:
diff changeset
1594 then
kono
parents:
diff changeset
1595 Validate_RCI_Declarations (Id);
kono
parents:
diff changeset
1596 end if;
kono
parents:
diff changeset
1597
kono
parents:
diff changeset
1598 -- Save global references in the visible declarations, before installing
kono
parents:
diff changeset
1599 -- private declarations of parent unit if there is one, because the
kono
parents:
diff changeset
1600 -- privacy status of types defined in the parent will change. This is
kono
parents:
diff changeset
1601 -- only relevant for generic child units, but is done in all cases for
kono
parents:
diff changeset
1602 -- uniformity.
kono
parents:
diff changeset
1603
kono
parents:
diff changeset
1604 if Ekind (Id) = E_Generic_Package
kono
parents:
diff changeset
1605 and then Nkind (Orig_Decl) = N_Generic_Package_Declaration
kono
parents:
diff changeset
1606 then
kono
parents:
diff changeset
1607 declare
kono
parents:
diff changeset
1608 Orig_Spec : constant Node_Id := Specification (Orig_Decl);
kono
parents:
diff changeset
1609 Save_Priv : constant List_Id := Private_Declarations (Orig_Spec);
kono
parents:
diff changeset
1610
kono
parents:
diff changeset
1611 begin
kono
parents:
diff changeset
1612 -- Insert the freezing nodes after the visible declarations to
kono
parents:
diff changeset
1613 -- ensure that we analyze its aspects; needed to ensure that
kono
parents:
diff changeset
1614 -- global entities referenced in the aspects are properly handled.
kono
parents:
diff changeset
1615
kono
parents:
diff changeset
1616 if Ada_Version >= Ada_2012
kono
parents:
diff changeset
1617 and then Is_Non_Empty_List (Vis_Decls)
kono
parents:
diff changeset
1618 and then Is_Empty_List (Priv_Decls)
kono
parents:
diff changeset
1619 then
kono
parents:
diff changeset
1620 Insert_List_After_And_Analyze
kono
parents:
diff changeset
1621 (Last (Vis_Decls), Freeze_Entity (Id, Last (Vis_Decls)));
kono
parents:
diff changeset
1622 end if;
kono
parents:
diff changeset
1623
kono
parents:
diff changeset
1624 Set_Private_Declarations (Orig_Spec, Empty_List);
kono
parents:
diff changeset
1625 Save_Global_References (Orig_Decl);
kono
parents:
diff changeset
1626 Set_Private_Declarations (Orig_Spec, Save_Priv);
kono
parents:
diff changeset
1627 end;
kono
parents:
diff changeset
1628 end if;
kono
parents:
diff changeset
1629
kono
parents:
diff changeset
1630 -- If package is a public child unit, then make the private declarations
kono
parents:
diff changeset
1631 -- of the parent visible.
kono
parents:
diff changeset
1632
kono
parents:
diff changeset
1633 Public_Child := False;
kono
parents:
diff changeset
1634
kono
parents:
diff changeset
1635 declare
kono
parents:
diff changeset
1636 Par : Entity_Id;
kono
parents:
diff changeset
1637 Pack_Decl : Node_Id;
kono
parents:
diff changeset
1638 Par_Spec : Node_Id;
kono
parents:
diff changeset
1639
kono
parents:
diff changeset
1640 begin
kono
parents:
diff changeset
1641 Par := Id;
kono
parents:
diff changeset
1642 Par_Spec := Parent_Spec (Parent (N));
kono
parents:
diff changeset
1643
kono
parents:
diff changeset
1644 -- If the package is formal package of an enclosing generic, it is
kono
parents:
diff changeset
1645 -- transformed into a local generic declaration, and compiled to make
kono
parents:
diff changeset
1646 -- its spec available. We need to retrieve the original generic to
kono
parents:
diff changeset
1647 -- determine whether it is a child unit, and install its parents.
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 if No (Par_Spec)
kono
parents:
diff changeset
1650 and then
kono
parents:
diff changeset
1651 Nkind (Original_Node (Parent (N))) = N_Formal_Package_Declaration
kono
parents:
diff changeset
1652 then
kono
parents:
diff changeset
1653 Par := Entity (Name (Original_Node (Parent (N))));
kono
parents:
diff changeset
1654 Par_Spec := Parent_Spec (Unit_Declaration_Node (Par));
kono
parents:
diff changeset
1655 end if;
kono
parents:
diff changeset
1656
kono
parents:
diff changeset
1657 if Present (Par_Spec) then
kono
parents:
diff changeset
1658 Generate_Parent_References;
kono
parents:
diff changeset
1659
kono
parents:
diff changeset
1660 while Scope (Par) /= Standard_Standard
kono
parents:
diff changeset
1661 and then Is_Public_Child (Id, Par)
kono
parents:
diff changeset
1662 and then In_Open_Scopes (Par)
kono
parents:
diff changeset
1663 loop
kono
parents:
diff changeset
1664 Public_Child := True;
kono
parents:
diff changeset
1665 Par := Scope (Par);
kono
parents:
diff changeset
1666 Install_Private_Declarations (Par);
kono
parents:
diff changeset
1667 Install_Private_With_Clauses (Par);
kono
parents:
diff changeset
1668 Pack_Decl := Unit_Declaration_Node (Par);
kono
parents:
diff changeset
1669 Set_Use (Private_Declarations (Specification (Pack_Decl)));
kono
parents:
diff changeset
1670 end loop;
kono
parents:
diff changeset
1671 end if;
kono
parents:
diff changeset
1672 end;
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 if Is_Compilation_Unit (Id) then
kono
parents:
diff changeset
1675 Install_Private_With_Clauses (Id);
kono
parents:
diff changeset
1676 else
kono
parents:
diff changeset
1677 -- The current compilation unit may include private with_clauses,
kono
parents:
diff changeset
1678 -- which are visible in the private part of the current nested
kono
parents:
diff changeset
1679 -- package, and have to be installed now. This is not done for
kono
parents:
diff changeset
1680 -- nested instantiations, where the private with_clauses of the
kono
parents:
diff changeset
1681 -- enclosing unit have no effect once the instantiation info is
kono
parents:
diff changeset
1682 -- established and we start analyzing the package declaration.
kono
parents:
diff changeset
1683
kono
parents:
diff changeset
1684 declare
kono
parents:
diff changeset
1685 Comp_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
kono
parents:
diff changeset
1686 begin
kono
parents:
diff changeset
1687 if Is_Package_Or_Generic_Package (Comp_Unit)
kono
parents:
diff changeset
1688 and then not In_Private_Part (Comp_Unit)
kono
parents:
diff changeset
1689 and then not In_Instance
kono
parents:
diff changeset
1690 then
kono
parents:
diff changeset
1691 Install_Private_With_Clauses (Comp_Unit);
kono
parents:
diff changeset
1692 Private_With_Clauses_Installed := True;
kono
parents:
diff changeset
1693 end if;
kono
parents:
diff changeset
1694 end;
kono
parents:
diff changeset
1695 end if;
kono
parents:
diff changeset
1696
kono
parents:
diff changeset
1697 -- If this is a package associated with a generic instance or formal
kono
parents:
diff changeset
1698 -- package, then the private declarations of each of the generic's
kono
parents:
diff changeset
1699 -- parents must be installed at this point.
kono
parents:
diff changeset
1700
kono
parents:
diff changeset
1701 if Is_Generic_Instance (Id) then
kono
parents:
diff changeset
1702 Install_Parent_Private_Declarations (Id);
kono
parents:
diff changeset
1703 end if;
kono
parents:
diff changeset
1704
kono
parents:
diff changeset
1705 -- Analyze private part if present. The flag In_Private_Part is reset
kono
parents:
diff changeset
1706 -- in End_Package_Scope.
kono
parents:
diff changeset
1707
kono
parents:
diff changeset
1708 L := Last_Entity (Id);
kono
parents:
diff changeset
1709
kono
parents:
diff changeset
1710 if Present (Priv_Decls) then
kono
parents:
diff changeset
1711 Set_In_Private_Part (Id);
kono
parents:
diff changeset
1712
kono
parents:
diff changeset
1713 -- Upon entering a public child's private part, it may be necessary
kono
parents:
diff changeset
1714 -- to declare subprograms that were derived in the package's visible
kono
parents:
diff changeset
1715 -- part but not yet made visible.
kono
parents:
diff changeset
1716
kono
parents:
diff changeset
1717 if Public_Child then
kono
parents:
diff changeset
1718 Declare_Inherited_Private_Subprograms (Id);
kono
parents:
diff changeset
1719 end if;
kono
parents:
diff changeset
1720
kono
parents:
diff changeset
1721 Analyze_Declarations (Priv_Decls);
kono
parents:
diff changeset
1722
kono
parents:
diff changeset
1723 -- Check the private declarations for incomplete deferred constants
kono
parents:
diff changeset
1724
kono
parents:
diff changeset
1725 Inspect_Deferred_Constant_Completion (Priv_Decls);
kono
parents:
diff changeset
1726
kono
parents:
diff changeset
1727 -- The first private entity is the immediate follower of the last
kono
parents:
diff changeset
1728 -- visible entity, if there was one.
kono
parents:
diff changeset
1729
kono
parents:
diff changeset
1730 if Present (L) then
kono
parents:
diff changeset
1731 Set_First_Private_Entity (Id, Next_Entity (L));
kono
parents:
diff changeset
1732 else
kono
parents:
diff changeset
1733 Set_First_Private_Entity (Id, First_Entity (Id));
kono
parents:
diff changeset
1734 end if;
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 -- There may be inherited private subprograms that need to be declared,
kono
parents:
diff changeset
1737 -- even in the absence of an explicit private part. If there are any
kono
parents:
diff changeset
1738 -- public declarations in the package and the package is a public child
kono
parents:
diff changeset
1739 -- unit, then an implicit private part is assumed.
kono
parents:
diff changeset
1740
kono
parents:
diff changeset
1741 elsif Present (L) and then Public_Child then
kono
parents:
diff changeset
1742 Set_In_Private_Part (Id);
kono
parents:
diff changeset
1743 Declare_Inherited_Private_Subprograms (Id);
kono
parents:
diff changeset
1744 Set_First_Private_Entity (Id, Next_Entity (L));
kono
parents:
diff changeset
1745 end if;
kono
parents:
diff changeset
1746
kono
parents:
diff changeset
1747 E := First_Entity (Id);
kono
parents:
diff changeset
1748 while Present (E) loop
kono
parents:
diff changeset
1749
kono
parents:
diff changeset
1750 -- Check rule of 3.6(11), which in general requires waiting till all
kono
parents:
diff changeset
1751 -- full types have been seen.
kono
parents:
diff changeset
1752
kono
parents:
diff changeset
1753 if Ekind (E) = E_Record_Type or else Ekind (E) = E_Array_Type then
kono
parents:
diff changeset
1754 Check_Aliased_Component_Types (E);
kono
parents:
diff changeset
1755 end if;
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 -- Check preelaborable initialization for full type completing a
kono
parents:
diff changeset
1758 -- private type for which pragma Preelaborable_Initialization given.
kono
parents:
diff changeset
1759
kono
parents:
diff changeset
1760 if Is_Type (E)
kono
parents:
diff changeset
1761 and then Must_Have_Preelab_Init (E)
kono
parents:
diff changeset
1762 and then not Has_Preelaborable_Initialization (E)
kono
parents:
diff changeset
1763 then
kono
parents:
diff changeset
1764 Error_Msg_N
kono
parents:
diff changeset
1765 ("full view of & does not have preelaborable initialization", E);
kono
parents:
diff changeset
1766 end if;
kono
parents:
diff changeset
1767
kono
parents:
diff changeset
1768 Next_Entity (E);
kono
parents:
diff changeset
1769 end loop;
kono
parents:
diff changeset
1770
kono
parents:
diff changeset
1771 -- Ada 2005 (AI-216): The completion of an incomplete or private type
kono
parents:
diff changeset
1772 -- declaration having a known_discriminant_part shall not be an
kono
parents:
diff changeset
1773 -- unchecked union type.
kono
parents:
diff changeset
1774
kono
parents:
diff changeset
1775 if Present (Vis_Decls) then
kono
parents:
diff changeset
1776 Inspect_Unchecked_Union_Completion (Vis_Decls);
kono
parents:
diff changeset
1777 end if;
kono
parents:
diff changeset
1778
kono
parents:
diff changeset
1779 if Present (Priv_Decls) then
kono
parents:
diff changeset
1780 Inspect_Unchecked_Union_Completion (Priv_Decls);
kono
parents:
diff changeset
1781 end if;
kono
parents:
diff changeset
1782
kono
parents:
diff changeset
1783 if Ekind (Id) = E_Generic_Package
kono
parents:
diff changeset
1784 and then Nkind (Orig_Decl) = N_Generic_Package_Declaration
kono
parents:
diff changeset
1785 and then Present (Priv_Decls)
kono
parents:
diff changeset
1786 then
kono
parents:
diff changeset
1787 -- Save global references in private declarations, ignoring the
kono
parents:
diff changeset
1788 -- visible declarations that were processed earlier.
kono
parents:
diff changeset
1789
kono
parents:
diff changeset
1790 declare
kono
parents:
diff changeset
1791 Orig_Spec : constant Node_Id := Specification (Orig_Decl);
kono
parents:
diff changeset
1792 Save_Vis : constant List_Id := Visible_Declarations (Orig_Spec);
kono
parents:
diff changeset
1793 Save_Form : constant List_Id :=
kono
parents:
diff changeset
1794 Generic_Formal_Declarations (Orig_Decl);
kono
parents:
diff changeset
1795
kono
parents:
diff changeset
1796 begin
kono
parents:
diff changeset
1797 -- Insert the freezing nodes after the private declarations to
kono
parents:
diff changeset
1798 -- ensure that we analyze its aspects; needed to ensure that
kono
parents:
diff changeset
1799 -- global entities referenced in the aspects are properly handled.
kono
parents:
diff changeset
1800
kono
parents:
diff changeset
1801 if Ada_Version >= Ada_2012
kono
parents:
diff changeset
1802 and then Is_Non_Empty_List (Priv_Decls)
kono
parents:
diff changeset
1803 then
kono
parents:
diff changeset
1804 Insert_List_After_And_Analyze
kono
parents:
diff changeset
1805 (Last (Priv_Decls), Freeze_Entity (Id, Last (Priv_Decls)));
kono
parents:
diff changeset
1806 end if;
kono
parents:
diff changeset
1807
kono
parents:
diff changeset
1808 Set_Visible_Declarations (Orig_Spec, Empty_List);
kono
parents:
diff changeset
1809 Set_Generic_Formal_Declarations (Orig_Decl, Empty_List);
kono
parents:
diff changeset
1810 Save_Global_References (Orig_Decl);
kono
parents:
diff changeset
1811 Set_Generic_Formal_Declarations (Orig_Decl, Save_Form);
kono
parents:
diff changeset
1812 Set_Visible_Declarations (Orig_Spec, Save_Vis);
kono
parents:
diff changeset
1813 end;
kono
parents:
diff changeset
1814 end if;
kono
parents:
diff changeset
1815
kono
parents:
diff changeset
1816 Process_End_Label (N, 'e', Id);
kono
parents:
diff changeset
1817
kono
parents:
diff changeset
1818 -- Remove private_with_clauses of enclosing compilation unit, if they
kono
parents:
diff changeset
1819 -- were installed.
kono
parents:
diff changeset
1820
kono
parents:
diff changeset
1821 if Private_With_Clauses_Installed then
kono
parents:
diff changeset
1822 Remove_Private_With_Clauses (Cunit (Current_Sem_Unit));
kono
parents:
diff changeset
1823 end if;
kono
parents:
diff changeset
1824
kono
parents:
diff changeset
1825 -- For the case of a library level package, we must go through all the
kono
parents:
diff changeset
1826 -- entities clearing the indications that the value may be constant and
kono
parents:
diff changeset
1827 -- not modified. Why? Because any client of this package may modify
kono
parents:
diff changeset
1828 -- these values freely from anywhere. This also applies to any nested
kono
parents:
diff changeset
1829 -- packages or generic packages.
kono
parents:
diff changeset
1830
kono
parents:
diff changeset
1831 -- For now we unconditionally clear constants for packages that are
kono
parents:
diff changeset
1832 -- instances of generic packages. The reason is that we do not have the
kono
parents:
diff changeset
1833 -- body yet, and we otherwise think things are unreferenced when they
kono
parents:
diff changeset
1834 -- are not. This should be fixed sometime (the effect is not terrible,
kono
parents:
diff changeset
1835 -- we just lose some warnings, and also some cases of value propagation)
kono
parents:
diff changeset
1836 -- ???
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 if Is_Library_Level_Entity (Id)
kono
parents:
diff changeset
1839 or else Is_Generic_Instance (Id)
kono
parents:
diff changeset
1840 then
kono
parents:
diff changeset
1841 Clear_Constants (Id, First_Entity (Id));
kono
parents:
diff changeset
1842 Clear_Constants (Id, First_Private_Entity (Id));
kono
parents:
diff changeset
1843 end if;
kono
parents:
diff changeset
1844
kono
parents:
diff changeset
1845 -- Issue an error in SPARK mode if a package specification contains
kono
parents:
diff changeset
1846 -- more than one tagged type or type extension.
kono
parents:
diff changeset
1847
kono
parents:
diff changeset
1848 Check_One_Tagged_Type_Or_Extension_At_Most;
kono
parents:
diff changeset
1849
kono
parents:
diff changeset
1850 -- Output relevant information as to why the package requires a body.
kono
parents:
diff changeset
1851 -- Do not consider generated packages as this exposes internal symbols
kono
parents:
diff changeset
1852 -- and leads to confusing messages.
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 if List_Body_Required_Info
kono
parents:
diff changeset
1855 and then In_Extended_Main_Source_Unit (Id)
kono
parents:
diff changeset
1856 and then Unit_Requires_Body (Id)
kono
parents:
diff changeset
1857 and then Comes_From_Source (Id)
kono
parents:
diff changeset
1858 then
kono
parents:
diff changeset
1859 Unit_Requires_Body_Info (Id);
kono
parents:
diff changeset
1860 end if;
kono
parents:
diff changeset
1861
kono
parents:
diff changeset
1862 -- Nested package specs that do not require bodies are not checked for
kono
parents:
diff changeset
1863 -- ineffective use clauses due to the possbility of subunits. This is
kono
parents:
diff changeset
1864 -- because at this stage it is impossible to tell whether there will be
kono
parents:
diff changeset
1865 -- a separate body.
kono
parents:
diff changeset
1866
kono
parents:
diff changeset
1867 if not Unit_Requires_Body (Id)
kono
parents:
diff changeset
1868 and then Is_Compilation_Unit (Id)
kono
parents:
diff changeset
1869 and then not Is_Private_Descendant (Id)
kono
parents:
diff changeset
1870 then
kono
parents:
diff changeset
1871 Update_Use_Clause_Chain;
kono
parents:
diff changeset
1872 end if;
kono
parents:
diff changeset
1873 end Analyze_Package_Specification;
kono
parents:
diff changeset
1874
kono
parents:
diff changeset
1875 --------------------------------------
kono
parents:
diff changeset
1876 -- Analyze_Private_Type_Declaration --
kono
parents:
diff changeset
1877 --------------------------------------
kono
parents:
diff changeset
1878
kono
parents:
diff changeset
1879 procedure Analyze_Private_Type_Declaration (N : Node_Id) is
kono
parents:
diff changeset
1880 Id : constant Entity_Id := Defining_Identifier (N);
kono
parents:
diff changeset
1881 PF : constant Boolean := Is_Pure (Enclosing_Lib_Unit_Entity);
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 begin
kono
parents:
diff changeset
1884 Generate_Definition (Id);
kono
parents:
diff changeset
1885 Set_Is_Pure (Id, PF);
kono
parents:
diff changeset
1886 Init_Size_Align (Id);
kono
parents:
diff changeset
1887
kono
parents:
diff changeset
1888 if not Is_Package_Or_Generic_Package (Current_Scope)
kono
parents:
diff changeset
1889 or else In_Private_Part (Current_Scope)
kono
parents:
diff changeset
1890 then
kono
parents:
diff changeset
1891 Error_Msg_N ("invalid context for private declaration", N);
kono
parents:
diff changeset
1892 end if;
kono
parents:
diff changeset
1893
kono
parents:
diff changeset
1894 New_Private_Type (N, Id, N);
kono
parents:
diff changeset
1895 Set_Depends_On_Private (Id);
kono
parents:
diff changeset
1896
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1897 -- Set the SPARK mode from the current context
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1898
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1899 Set_SPARK_Pragma (Id, SPARK_Mode_Pragma);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1900 Set_SPARK_Pragma_Inherited (Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1901
111
kono
parents:
diff changeset
1902 if Has_Aspects (N) then
kono
parents:
diff changeset
1903 Analyze_Aspect_Specifications (N, Id);
kono
parents:
diff changeset
1904 end if;
kono
parents:
diff changeset
1905 end Analyze_Private_Type_Declaration;
kono
parents:
diff changeset
1906
kono
parents:
diff changeset
1907 ----------------------------------
kono
parents:
diff changeset
1908 -- Check_Anonymous_Access_Types --
kono
parents:
diff changeset
1909 ----------------------------------
kono
parents:
diff changeset
1910
kono
parents:
diff changeset
1911 procedure Check_Anonymous_Access_Types
kono
parents:
diff changeset
1912 (Spec_Id : Entity_Id;
kono
parents:
diff changeset
1913 P_Body : Node_Id)
kono
parents:
diff changeset
1914 is
kono
parents:
diff changeset
1915 E : Entity_Id;
kono
parents:
diff changeset
1916 IR : Node_Id;
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 begin
kono
parents:
diff changeset
1919 -- Itype references are only needed by gigi, to force elaboration of
kono
parents:
diff changeset
1920 -- itypes. In the absence of code generation, they are not needed.
kono
parents:
diff changeset
1921
kono
parents:
diff changeset
1922 if not Expander_Active then
kono
parents:
diff changeset
1923 return;
kono
parents:
diff changeset
1924 end if;
kono
parents:
diff changeset
1925
kono
parents:
diff changeset
1926 E := First_Entity (Spec_Id);
kono
parents:
diff changeset
1927 while Present (E) loop
kono
parents:
diff changeset
1928 if Ekind (E) = E_Anonymous_Access_Type
kono
parents:
diff changeset
1929 and then From_Limited_With (E)
kono
parents:
diff changeset
1930 then
kono
parents:
diff changeset
1931 IR := Make_Itype_Reference (Sloc (P_Body));
kono
parents:
diff changeset
1932 Set_Itype (IR, E);
kono
parents:
diff changeset
1933
kono
parents:
diff changeset
1934 if No (Declarations (P_Body)) then
kono
parents:
diff changeset
1935 Set_Declarations (P_Body, New_List (IR));
kono
parents:
diff changeset
1936 else
kono
parents:
diff changeset
1937 Prepend (IR, Declarations (P_Body));
kono
parents:
diff changeset
1938 end if;
kono
parents:
diff changeset
1939 end if;
kono
parents:
diff changeset
1940
kono
parents:
diff changeset
1941 Next_Entity (E);
kono
parents:
diff changeset
1942 end loop;
kono
parents:
diff changeset
1943 end Check_Anonymous_Access_Types;
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 -------------------------------------------
kono
parents:
diff changeset
1946 -- Declare_Inherited_Private_Subprograms --
kono
parents:
diff changeset
1947 -------------------------------------------
kono
parents:
diff changeset
1948
kono
parents:
diff changeset
1949 procedure Declare_Inherited_Private_Subprograms (Id : Entity_Id) is
kono
parents:
diff changeset
1950
kono
parents:
diff changeset
1951 function Is_Primitive_Of (T : Entity_Id; S : Entity_Id) return Boolean;
kono
parents:
diff changeset
1952 -- Check whether an inherited subprogram S is an operation of an
kono
parents:
diff changeset
1953 -- untagged derived type T.
kono
parents:
diff changeset
1954
kono
parents:
diff changeset
1955 ---------------------
kono
parents:
diff changeset
1956 -- Is_Primitive_Of --
kono
parents:
diff changeset
1957 ---------------------
kono
parents:
diff changeset
1958
kono
parents:
diff changeset
1959 function Is_Primitive_Of (T : Entity_Id; S : Entity_Id) return Boolean is
kono
parents:
diff changeset
1960 Formal : Entity_Id;
kono
parents:
diff changeset
1961
kono
parents:
diff changeset
1962 begin
kono
parents:
diff changeset
1963 -- If the full view is a scalar type, the type is the anonymous base
kono
parents:
diff changeset
1964 -- type, but the operation mentions the first subtype, so check the
kono
parents:
diff changeset
1965 -- signature against the base type.
kono
parents:
diff changeset
1966
kono
parents:
diff changeset
1967 if Base_Type (Etype (S)) = Base_Type (T) then
kono
parents:
diff changeset
1968 return True;
kono
parents:
diff changeset
1969
kono
parents:
diff changeset
1970 else
kono
parents:
diff changeset
1971 Formal := First_Formal (S);
kono
parents:
diff changeset
1972 while Present (Formal) loop
kono
parents:
diff changeset
1973 if Base_Type (Etype (Formal)) = Base_Type (T) then
kono
parents:
diff changeset
1974 return True;
kono
parents:
diff changeset
1975 end if;
kono
parents:
diff changeset
1976
kono
parents:
diff changeset
1977 Next_Formal (Formal);
kono
parents:
diff changeset
1978 end loop;
kono
parents:
diff changeset
1979
kono
parents:
diff changeset
1980 return False;
kono
parents:
diff changeset
1981 end if;
kono
parents:
diff changeset
1982 end Is_Primitive_Of;
kono
parents:
diff changeset
1983
kono
parents:
diff changeset
1984 -- Local variables
kono
parents:
diff changeset
1985
kono
parents:
diff changeset
1986 E : Entity_Id;
kono
parents:
diff changeset
1987 Op_List : Elist_Id;
kono
parents:
diff changeset
1988 Op_Elmt : Elmt_Id;
kono
parents:
diff changeset
1989 Op_Elmt_2 : Elmt_Id;
kono
parents:
diff changeset
1990 Prim_Op : Entity_Id;
kono
parents:
diff changeset
1991 New_Op : Entity_Id := Empty;
kono
parents:
diff changeset
1992 Parent_Subp : Entity_Id;
kono
parents:
diff changeset
1993 Tag : Entity_Id;
kono
parents:
diff changeset
1994
kono
parents:
diff changeset
1995 -- Start of processing for Declare_Inherited_Private_Subprograms
kono
parents:
diff changeset
1996
kono
parents:
diff changeset
1997 begin
kono
parents:
diff changeset
1998 E := First_Entity (Id);
kono
parents:
diff changeset
1999 while Present (E) loop
kono
parents:
diff changeset
2000
kono
parents:
diff changeset
2001 -- If the entity is a nonprivate type extension whose parent type
kono
parents:
diff changeset
2002 -- is declared in an open scope, then the type may have inherited
kono
parents:
diff changeset
2003 -- operations that now need to be made visible. Ditto if the entity
kono
parents:
diff changeset
2004 -- is a formal derived type in a child unit.
kono
parents:
diff changeset
2005
kono
parents:
diff changeset
2006 if ((Is_Derived_Type (E) and then not Is_Private_Type (E))
kono
parents:
diff changeset
2007 or else
kono
parents:
diff changeset
2008 (Nkind (Parent (E)) = N_Private_Extension_Declaration
kono
parents:
diff changeset
2009 and then Is_Generic_Type (E)))
kono
parents:
diff changeset
2010 and then In_Open_Scopes (Scope (Etype (E)))
kono
parents:
diff changeset
2011 and then Is_Base_Type (E)
kono
parents:
diff changeset
2012 then
kono
parents:
diff changeset
2013 if Is_Tagged_Type (E) then
kono
parents:
diff changeset
2014 Op_List := Primitive_Operations (E);
kono
parents:
diff changeset
2015 New_Op := Empty;
kono
parents:
diff changeset
2016 Tag := First_Tag_Component (E);
kono
parents:
diff changeset
2017
kono
parents:
diff changeset
2018 Op_Elmt := First_Elmt (Op_List);
kono
parents:
diff changeset
2019 while Present (Op_Elmt) loop
kono
parents:
diff changeset
2020 Prim_Op := Node (Op_Elmt);
kono
parents:
diff changeset
2021
kono
parents:
diff changeset
2022 -- Search primitives that are implicit operations with an
kono
parents:
diff changeset
2023 -- internal name whose parent operation has a normal name.
kono
parents:
diff changeset
2024
kono
parents:
diff changeset
2025 if Present (Alias (Prim_Op))
kono
parents:
diff changeset
2026 and then Find_Dispatching_Type (Alias (Prim_Op)) /= E
kono
parents:
diff changeset
2027 and then not Comes_From_Source (Prim_Op)
kono
parents:
diff changeset
2028 and then Is_Internal_Name (Chars (Prim_Op))
kono
parents:
diff changeset
2029 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
kono
parents:
diff changeset
2030 then
kono
parents:
diff changeset
2031 Parent_Subp := Alias (Prim_Op);
kono
parents:
diff changeset
2032
kono
parents:
diff changeset
2033 -- Case 1: Check if the type has also an explicit
kono
parents:
diff changeset
2034 -- overriding for this primitive.
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 Op_Elmt_2 := Next_Elmt (Op_Elmt);
kono
parents:
diff changeset
2037 while Present (Op_Elmt_2) loop
kono
parents:
diff changeset
2038
kono
parents:
diff changeset
2039 -- Skip entities with attribute Interface_Alias since
kono
parents:
diff changeset
2040 -- they are not overriding primitives (these entities
kono
parents:
diff changeset
2041 -- link an interface primitive with their covering
kono
parents:
diff changeset
2042 -- primitive)
kono
parents:
diff changeset
2043
kono
parents:
diff changeset
2044 if Chars (Node (Op_Elmt_2)) = Chars (Parent_Subp)
kono
parents:
diff changeset
2045 and then Type_Conformant (Prim_Op, Node (Op_Elmt_2))
kono
parents:
diff changeset
2046 and then No (Interface_Alias (Node (Op_Elmt_2)))
kono
parents:
diff changeset
2047 then
kono
parents:
diff changeset
2048 -- The private inherited operation has been
kono
parents:
diff changeset
2049 -- overridden by an explicit subprogram:
kono
parents:
diff changeset
2050 -- replace the former by the latter.
kono
parents:
diff changeset
2051
kono
parents:
diff changeset
2052 New_Op := Node (Op_Elmt_2);
kono
parents:
diff changeset
2053 Replace_Elmt (Op_Elmt, New_Op);
kono
parents:
diff changeset
2054 Remove_Elmt (Op_List, Op_Elmt_2);
kono
parents:
diff changeset
2055 Set_Overridden_Operation (New_Op, Parent_Subp);
kono
parents:
diff changeset
2056
kono
parents:
diff changeset
2057 -- We don't need to inherit its dispatching slot.
kono
parents:
diff changeset
2058 -- Set_All_DT_Position has previously ensured that
kono
parents:
diff changeset
2059 -- the same slot was assigned to the two primitives
kono
parents:
diff changeset
2060
kono
parents:
diff changeset
2061 if Present (Tag)
kono
parents:
diff changeset
2062 and then Present (DTC_Entity (New_Op))
kono
parents:
diff changeset
2063 and then Present (DTC_Entity (Prim_Op))
kono
parents:
diff changeset
2064 then
kono
parents:
diff changeset
2065 pragma Assert
kono
parents:
diff changeset
2066 (DT_Position (New_Op) = DT_Position (Prim_Op));
kono
parents:
diff changeset
2067 null;
kono
parents:
diff changeset
2068 end if;
kono
parents:
diff changeset
2069
kono
parents:
diff changeset
2070 goto Next_Primitive;
kono
parents:
diff changeset
2071 end if;
kono
parents:
diff changeset
2072
kono
parents:
diff changeset
2073 Next_Elmt (Op_Elmt_2);
kono
parents:
diff changeset
2074 end loop;
kono
parents:
diff changeset
2075
kono
parents:
diff changeset
2076 -- Case 2: We have not found any explicit overriding and
kono
parents:
diff changeset
2077 -- hence we need to declare the operation (i.e., make it
kono
parents:
diff changeset
2078 -- visible).
kono
parents:
diff changeset
2079
kono
parents:
diff changeset
2080 Derive_Subprogram (New_Op, Alias (Prim_Op), E, Etype (E));
kono
parents:
diff changeset
2081
kono
parents:
diff changeset
2082 -- Inherit the dispatching slot if E is already frozen
kono
parents:
diff changeset
2083
kono
parents:
diff changeset
2084 if Is_Frozen (E)
kono
parents:
diff changeset
2085 and then Present (DTC_Entity (Alias (Prim_Op)))
kono
parents:
diff changeset
2086 then
kono
parents:
diff changeset
2087 Set_DTC_Entity_Value (E, New_Op);
kono
parents:
diff changeset
2088 Set_DT_Position_Value (New_Op,
kono
parents:
diff changeset
2089 DT_Position (Alias (Prim_Op)));
kono
parents:
diff changeset
2090 end if;
kono
parents:
diff changeset
2091
kono
parents:
diff changeset
2092 pragma Assert
kono
parents:
diff changeset
2093 (Is_Dispatching_Operation (New_Op)
kono
parents:
diff changeset
2094 and then Node (Last_Elmt (Op_List)) = New_Op);
kono
parents:
diff changeset
2095
kono
parents:
diff changeset
2096 -- Substitute the new operation for the old one in the
kono
parents:
diff changeset
2097 -- type's primitive operations list. Since the new
kono
parents:
diff changeset
2098 -- operation was also just added to the end of list,
kono
parents:
diff changeset
2099 -- the last element must be removed.
kono
parents:
diff changeset
2100
kono
parents:
diff changeset
2101 -- (Question: is there a simpler way of declaring the
kono
parents:
diff changeset
2102 -- operation, say by just replacing the name of the
kono
parents:
diff changeset
2103 -- earlier operation, reentering it in the in the symbol
kono
parents:
diff changeset
2104 -- table (how?), and marking it as private???)
kono
parents:
diff changeset
2105
kono
parents:
diff changeset
2106 Replace_Elmt (Op_Elmt, New_Op);
kono
parents:
diff changeset
2107 Remove_Last_Elmt (Op_List);
kono
parents:
diff changeset
2108 end if;
kono
parents:
diff changeset
2109
kono
parents:
diff changeset
2110 <<Next_Primitive>>
kono
parents:
diff changeset
2111 Next_Elmt (Op_Elmt);
kono
parents:
diff changeset
2112 end loop;
kono
parents:
diff changeset
2113
kono
parents:
diff changeset
2114 -- Generate listing showing the contents of the dispatch table
kono
parents:
diff changeset
2115
kono
parents:
diff changeset
2116 if Debug_Flag_ZZ then
kono
parents:
diff changeset
2117 Write_DT (E);
kono
parents:
diff changeset
2118 end if;
kono
parents:
diff changeset
2119
kono
parents:
diff changeset
2120 else
kono
parents:
diff changeset
2121 -- For untagged type, scan forward to locate inherited hidden
kono
parents:
diff changeset
2122 -- operations.
kono
parents:
diff changeset
2123
kono
parents:
diff changeset
2124 Prim_Op := Next_Entity (E);
kono
parents:
diff changeset
2125 while Present (Prim_Op) loop
kono
parents:
diff changeset
2126 if Is_Subprogram (Prim_Op)
kono
parents:
diff changeset
2127 and then Present (Alias (Prim_Op))
kono
parents:
diff changeset
2128 and then not Comes_From_Source (Prim_Op)
kono
parents:
diff changeset
2129 and then Is_Internal_Name (Chars (Prim_Op))
kono
parents:
diff changeset
2130 and then not Is_Internal_Name (Chars (Alias (Prim_Op)))
kono
parents:
diff changeset
2131 and then Is_Primitive_Of (E, Prim_Op)
kono
parents:
diff changeset
2132 then
kono
parents:
diff changeset
2133 Derive_Subprogram (New_Op, Alias (Prim_Op), E, Etype (E));
kono
parents:
diff changeset
2134 end if;
kono
parents:
diff changeset
2135
kono
parents:
diff changeset
2136 Next_Entity (Prim_Op);
kono
parents:
diff changeset
2137
kono
parents:
diff changeset
2138 -- Derived operations appear immediately after the type
kono
parents:
diff changeset
2139 -- declaration (or the following subtype indication for
kono
parents:
diff changeset
2140 -- a derived scalar type). Further declarations cannot
kono
parents:
diff changeset
2141 -- include inherited operations of the type.
kono
parents:
diff changeset
2142
kono
parents:
diff changeset
2143 if Present (Prim_Op) then
kono
parents:
diff changeset
2144 exit when Ekind (Prim_Op) not in Overloadable_Kind;
kono
parents:
diff changeset
2145 end if;
kono
parents:
diff changeset
2146 end loop;
kono
parents:
diff changeset
2147 end if;
kono
parents:
diff changeset
2148 end if;
kono
parents:
diff changeset
2149
kono
parents:
diff changeset
2150 Next_Entity (E);
kono
parents:
diff changeset
2151 end loop;
kono
parents:
diff changeset
2152 end Declare_Inherited_Private_Subprograms;
kono
parents:
diff changeset
2153
kono
parents:
diff changeset
2154 -----------------------
kono
parents:
diff changeset
2155 -- End_Package_Scope --
kono
parents:
diff changeset
2156 -----------------------
kono
parents:
diff changeset
2157
kono
parents:
diff changeset
2158 procedure End_Package_Scope (P : Entity_Id) is
kono
parents:
diff changeset
2159 begin
kono
parents:
diff changeset
2160 Uninstall_Declarations (P);
kono
parents:
diff changeset
2161 Pop_Scope;
kono
parents:
diff changeset
2162 end End_Package_Scope;
kono
parents:
diff changeset
2163
kono
parents:
diff changeset
2164 ---------------------------
kono
parents:
diff changeset
2165 -- Exchange_Declarations --
kono
parents:
diff changeset
2166 ---------------------------
kono
parents:
diff changeset
2167
kono
parents:
diff changeset
2168 procedure Exchange_Declarations (Id : Entity_Id) is
kono
parents:
diff changeset
2169 Full_Id : constant Entity_Id := Full_View (Id);
kono
parents:
diff changeset
2170 H1 : constant Entity_Id := Homonym (Id);
kono
parents:
diff changeset
2171 Next1 : constant Entity_Id := Next_Entity (Id);
kono
parents:
diff changeset
2172 H2 : Entity_Id;
kono
parents:
diff changeset
2173 Next2 : Entity_Id;
kono
parents:
diff changeset
2174
kono
parents:
diff changeset
2175 begin
kono
parents:
diff changeset
2176 -- If missing full declaration for type, nothing to exchange
kono
parents:
diff changeset
2177
kono
parents:
diff changeset
2178 if No (Full_Id) then
kono
parents:
diff changeset
2179 return;
kono
parents:
diff changeset
2180 end if;
kono
parents:
diff changeset
2181
kono
parents:
diff changeset
2182 -- Otherwise complete the exchange, and preserve semantic links
kono
parents:
diff changeset
2183
kono
parents:
diff changeset
2184 Next2 := Next_Entity (Full_Id);
kono
parents:
diff changeset
2185 H2 := Homonym (Full_Id);
kono
parents:
diff changeset
2186
kono
parents:
diff changeset
2187 -- Reset full declaration pointer to reflect the switched entities and
kono
parents:
diff changeset
2188 -- readjust the next entity chains.
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 Exchange_Entities (Id, Full_Id);
kono
parents:
diff changeset
2191
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2192 Link_Entities (Id, Next1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2193 Set_Homonym (Id, H1);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2194
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2195 Set_Full_View (Full_Id, Id);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2196 Link_Entities (Full_Id, Next2);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2197 Set_Homonym (Full_Id, H2);
111
kono
parents:
diff changeset
2198 end Exchange_Declarations;
kono
parents:
diff changeset
2199
kono
parents:
diff changeset
2200 ----------------------------
kono
parents:
diff changeset
2201 -- Install_Package_Entity --
kono
parents:
diff changeset
2202 ----------------------------
kono
parents:
diff changeset
2203
kono
parents:
diff changeset
2204 procedure Install_Package_Entity (Id : Entity_Id) is
kono
parents:
diff changeset
2205 begin
kono
parents:
diff changeset
2206 if not Is_Internal (Id) then
kono
parents:
diff changeset
2207 if Debug_Flag_E then
kono
parents:
diff changeset
2208 Write_Str ("Install: ");
kono
parents:
diff changeset
2209 Write_Name (Chars (Id));
kono
parents:
diff changeset
2210 Write_Eol;
kono
parents:
diff changeset
2211 end if;
kono
parents:
diff changeset
2212
kono
parents:
diff changeset
2213 if Is_Child_Unit (Id) then
kono
parents:
diff changeset
2214 null;
kono
parents:
diff changeset
2215
kono
parents:
diff changeset
2216 -- Do not enter implicitly inherited non-overridden subprograms of
kono
parents:
diff changeset
2217 -- a tagged type back into visibility if they have non-conformant
kono
parents:
diff changeset
2218 -- homographs (Ada RM 8.3 12.3/2).
kono
parents:
diff changeset
2219
kono
parents:
diff changeset
2220 elsif Is_Hidden_Non_Overridden_Subpgm (Id) then
kono
parents:
diff changeset
2221 null;
kono
parents:
diff changeset
2222
kono
parents:
diff changeset
2223 else
kono
parents:
diff changeset
2224 Set_Is_Immediately_Visible (Id);
kono
parents:
diff changeset
2225 end if;
kono
parents:
diff changeset
2226 end if;
kono
parents:
diff changeset
2227 end Install_Package_Entity;
kono
parents:
diff changeset
2228
kono
parents:
diff changeset
2229 ----------------------------------
kono
parents:
diff changeset
2230 -- Install_Private_Declarations --
kono
parents:
diff changeset
2231 ----------------------------------
kono
parents:
diff changeset
2232
kono
parents:
diff changeset
2233 procedure Install_Private_Declarations (P : Entity_Id) is
kono
parents:
diff changeset
2234 Id : Entity_Id;
kono
parents:
diff changeset
2235 Full : Entity_Id;
kono
parents:
diff changeset
2236 Priv_Deps : Elist_Id;
kono
parents:
diff changeset
2237
kono
parents:
diff changeset
2238 procedure Swap_Private_Dependents (Priv_Deps : Elist_Id);
kono
parents:
diff changeset
2239 -- When the full view of a private type is made available, we do the
kono
parents:
diff changeset
2240 -- same for its private dependents under proper visibility conditions.
kono
parents:
diff changeset
2241 -- When compiling a grand-chid unit this needs to be done recursively.
kono
parents:
diff changeset
2242
kono
parents:
diff changeset
2243 -----------------------------
kono
parents:
diff changeset
2244 -- Swap_Private_Dependents --
kono
parents:
diff changeset
2245 -----------------------------
kono
parents:
diff changeset
2246
kono
parents:
diff changeset
2247 procedure Swap_Private_Dependents (Priv_Deps : Elist_Id) is
kono
parents:
diff changeset
2248 Deps : Elist_Id;
kono
parents:
diff changeset
2249 Priv : Entity_Id;
kono
parents:
diff changeset
2250 Priv_Elmt : Elmt_Id;
kono
parents:
diff changeset
2251 Is_Priv : Boolean;
kono
parents:
diff changeset
2252
kono
parents:
diff changeset
2253 begin
kono
parents:
diff changeset
2254 Priv_Elmt := First_Elmt (Priv_Deps);
kono
parents:
diff changeset
2255 while Present (Priv_Elmt) loop
kono
parents:
diff changeset
2256 Priv := Node (Priv_Elmt);
kono
parents:
diff changeset
2257
kono
parents:
diff changeset
2258 -- Before the exchange, verify that the presence of the Full_View
kono
parents:
diff changeset
2259 -- field. This field will be empty if the entity has already been
kono
parents:
diff changeset
2260 -- installed due to a previous call.
kono
parents:
diff changeset
2261
kono
parents:
diff changeset
2262 if Present (Full_View (Priv)) and then Is_Visible_Dependent (Priv)
kono
parents:
diff changeset
2263 then
kono
parents:
diff changeset
2264 if Is_Private_Type (Priv) then
kono
parents:
diff changeset
2265 Deps := Private_Dependents (Priv);
kono
parents:
diff changeset
2266 Is_Priv := True;
kono
parents:
diff changeset
2267 else
kono
parents:
diff changeset
2268 Is_Priv := False;
kono
parents:
diff changeset
2269 end if;
kono
parents:
diff changeset
2270
kono
parents:
diff changeset
2271 -- For each subtype that is swapped, we also swap the reference
kono
parents:
diff changeset
2272 -- to it in Private_Dependents, to allow access to it when we
kono
parents:
diff changeset
2273 -- swap them out in End_Package_Scope.
kono
parents:
diff changeset
2274
kono
parents:
diff changeset
2275 Replace_Elmt (Priv_Elmt, Full_View (Priv));
kono
parents:
diff changeset
2276
kono
parents:
diff changeset
2277 -- Ensure that both views of the dependent private subtype are
kono
parents:
diff changeset
2278 -- immediately visible if within some open scope. Check full
kono
parents:
diff changeset
2279 -- view before exchanging views.
kono
parents:
diff changeset
2280
kono
parents:
diff changeset
2281 if In_Open_Scopes (Scope (Full_View (Priv))) then
kono
parents:
diff changeset
2282 Set_Is_Immediately_Visible (Priv);
kono
parents:
diff changeset
2283 end if;
kono
parents:
diff changeset
2284
kono
parents:
diff changeset
2285 Exchange_Declarations (Priv);
kono
parents:
diff changeset
2286 Set_Is_Immediately_Visible
kono
parents:
diff changeset
2287 (Priv, In_Open_Scopes (Scope (Priv)));
kono
parents:
diff changeset
2288
kono
parents:
diff changeset
2289 Set_Is_Potentially_Use_Visible
kono
parents:
diff changeset
2290 (Priv, Is_Potentially_Use_Visible (Node (Priv_Elmt)));
kono
parents:
diff changeset
2291
kono
parents:
diff changeset
2292 -- Within a child unit, recurse, except in generic child unit,
kono
parents:
diff changeset
2293 -- which (unfortunately) handle private_dependents separately.
kono
parents:
diff changeset
2294
kono
parents:
diff changeset
2295 if Is_Priv
kono
parents:
diff changeset
2296 and then Is_Child_Unit (Cunit_Entity (Current_Sem_Unit))
kono
parents:
diff changeset
2297 and then not Is_Empty_Elmt_List (Deps)
kono
parents:
diff changeset
2298 and then not Inside_A_Generic
kono
parents:
diff changeset
2299 then
kono
parents:
diff changeset
2300 Swap_Private_Dependents (Deps);
kono
parents:
diff changeset
2301 end if;
kono
parents:
diff changeset
2302 end if;
kono
parents:
diff changeset
2303
kono
parents:
diff changeset
2304 Next_Elmt (Priv_Elmt);
kono
parents:
diff changeset
2305 end loop;
kono
parents:
diff changeset
2306 end Swap_Private_Dependents;
kono
parents:
diff changeset
2307
kono
parents:
diff changeset
2308 -- Start of processing for Install_Private_Declarations
kono
parents:
diff changeset
2309
kono
parents:
diff changeset
2310 begin
kono
parents:
diff changeset
2311 -- First exchange declarations for private types, so that the full
kono
parents:
diff changeset
2312 -- declaration is visible. For each private type, we check its
kono
parents:
diff changeset
2313 -- Private_Dependents list and also exchange any subtypes of or derived
kono
parents:
diff changeset
2314 -- types from it. Finally, if this is a Taft amendment type, the
kono
parents:
diff changeset
2315 -- incomplete declaration is irrelevant, and we want to link the
kono
parents:
diff changeset
2316 -- eventual full declaration with the original private one so we
kono
parents:
diff changeset
2317 -- also skip the exchange.
kono
parents:
diff changeset
2318
kono
parents:
diff changeset
2319 Id := First_Entity (P);
kono
parents:
diff changeset
2320 while Present (Id) and then Id /= First_Private_Entity (P) loop
kono
parents:
diff changeset
2321 if Is_Private_Base_Type (Id)
kono
parents:
diff changeset
2322 and then Present (Full_View (Id))
kono
parents:
diff changeset
2323 and then Comes_From_Source (Full_View (Id))
kono
parents:
diff changeset
2324 and then Scope (Full_View (Id)) = Scope (Id)
kono
parents:
diff changeset
2325 and then Ekind (Full_View (Id)) /= E_Incomplete_Type
kono
parents:
diff changeset
2326 then
kono
parents:
diff changeset
2327 -- If there is a use-type clause on the private type, set the full
kono
parents:
diff changeset
2328 -- view accordingly.
kono
parents:
diff changeset
2329
kono
parents:
diff changeset
2330 Set_In_Use (Full_View (Id), In_Use (Id));
kono
parents:
diff changeset
2331 Full := Full_View (Id);
kono
parents:
diff changeset
2332
kono
parents:
diff changeset
2333 if Is_Private_Base_Type (Full)
kono
parents:
diff changeset
2334 and then Has_Private_Declaration (Full)
kono
parents:
diff changeset
2335 and then Nkind (Parent (Full)) = N_Full_Type_Declaration
kono
parents:
diff changeset
2336 and then In_Open_Scopes (Scope (Etype (Full)))
kono
parents:
diff changeset
2337 and then In_Package_Body (Current_Scope)
kono
parents:
diff changeset
2338 and then not Is_Private_Type (Etype (Full))
kono
parents:
diff changeset
2339 then
kono
parents:
diff changeset
2340 -- This is the completion of a private type by a derivation
kono
parents:
diff changeset
2341 -- from another private type which is not private anymore. This
kono
parents:
diff changeset
2342 -- can only happen in a package nested within a child package,
kono
parents:
diff changeset
2343 -- when the parent type is defined in the parent unit. At this
kono
parents:
diff changeset
2344 -- point the current type is not private either, and we have
kono
parents:
diff changeset
2345 -- to install the underlying full view, which is now visible.
kono
parents:
diff changeset
2346 -- Save the current full view as well, so that all views can be
kono
parents:
diff changeset
2347 -- restored on exit. It may seem that after compiling the child
kono
parents:
diff changeset
2348 -- body there are not environments to restore, but the back-end
kono
parents:
diff changeset
2349 -- expects those links to be valid, and freeze nodes depend on
kono
parents:
diff changeset
2350 -- them.
kono
parents:
diff changeset
2351
kono
parents:
diff changeset
2352 if No (Full_View (Full))
kono
parents:
diff changeset
2353 and then Present (Underlying_Full_View (Full))
kono
parents:
diff changeset
2354 then
kono
parents:
diff changeset
2355 Set_Full_View (Id, Underlying_Full_View (Full));
kono
parents:
diff changeset
2356 Set_Underlying_Full_View (Id, Full);
kono
parents:
diff changeset
2357 Set_Is_Underlying_Full_View (Full);
kono
parents:
diff changeset
2358
kono
parents:
diff changeset
2359 Set_Underlying_Full_View (Full, Empty);
kono
parents:
diff changeset
2360 Set_Is_Frozen (Full_View (Id));
kono
parents:
diff changeset
2361 end if;
kono
parents:
diff changeset
2362 end if;
kono
parents:
diff changeset
2363
kono
parents:
diff changeset
2364 Priv_Deps := Private_Dependents (Id);
kono
parents:
diff changeset
2365 Exchange_Declarations (Id);
kono
parents:
diff changeset
2366 Set_Is_Immediately_Visible (Id);
kono
parents:
diff changeset
2367 Swap_Private_Dependents (Priv_Deps);
kono
parents:
diff changeset
2368 end if;
kono
parents:
diff changeset
2369
kono
parents:
diff changeset
2370 Next_Entity (Id);
kono
parents:
diff changeset
2371 end loop;
kono
parents:
diff changeset
2372
kono
parents:
diff changeset
2373 -- Next make other declarations in the private part visible as well
kono
parents:
diff changeset
2374
kono
parents:
diff changeset
2375 Id := First_Private_Entity (P);
kono
parents:
diff changeset
2376 while Present (Id) loop
kono
parents:
diff changeset
2377 Install_Package_Entity (Id);
kono
parents:
diff changeset
2378 Set_Is_Hidden (Id, False);
kono
parents:
diff changeset
2379 Next_Entity (Id);
kono
parents:
diff changeset
2380 end loop;
kono
parents:
diff changeset
2381
kono
parents:
diff changeset
2382 -- An abstract state is partially refined when it has at least one
kono
parents:
diff changeset
2383 -- Part_Of constituent. Since these constituents are being installed
kono
parents:
diff changeset
2384 -- into visibility, update the partial refinement status of any state
kono
parents:
diff changeset
2385 -- defined in the associated package, subject to at least one Part_Of
kono
parents:
diff changeset
2386 -- constituent.
kono
parents:
diff changeset
2387
kono
parents:
diff changeset
2388 if Ekind_In (P, E_Generic_Package, E_Package) then
kono
parents:
diff changeset
2389 declare
kono
parents:
diff changeset
2390 States : constant Elist_Id := Abstract_States (P);
kono
parents:
diff changeset
2391 State_Elmt : Elmt_Id;
kono
parents:
diff changeset
2392 State_Id : Entity_Id;
kono
parents:
diff changeset
2393
kono
parents:
diff changeset
2394 begin
kono
parents:
diff changeset
2395 if Present (States) then
kono
parents:
diff changeset
2396 State_Elmt := First_Elmt (States);
kono
parents:
diff changeset
2397 while Present (State_Elmt) loop
kono
parents:
diff changeset
2398 State_Id := Node (State_Elmt);
kono
parents:
diff changeset
2399
kono
parents:
diff changeset
2400 if Present (Part_Of_Constituents (State_Id)) then
kono
parents:
diff changeset
2401 Set_Has_Partial_Visible_Refinement (State_Id);
kono
parents:
diff changeset
2402 end if;
kono
parents:
diff changeset
2403
kono
parents:
diff changeset
2404 Next_Elmt (State_Elmt);
kono
parents:
diff changeset
2405 end loop;
kono
parents:
diff changeset
2406 end if;
kono
parents:
diff changeset
2407 end;
kono
parents:
diff changeset
2408 end if;
kono
parents:
diff changeset
2409
kono
parents:
diff changeset
2410 -- Indicate that the private part is currently visible, so it can be
kono
parents:
diff changeset
2411 -- properly reset on exit.
kono
parents:
diff changeset
2412
kono
parents:
diff changeset
2413 Set_In_Private_Part (P);
kono
parents:
diff changeset
2414 end Install_Private_Declarations;
kono
parents:
diff changeset
2415
kono
parents:
diff changeset
2416 ----------------------------------
kono
parents:
diff changeset
2417 -- Install_Visible_Declarations --
kono
parents:
diff changeset
2418 ----------------------------------
kono
parents:
diff changeset
2419
kono
parents:
diff changeset
2420 procedure Install_Visible_Declarations (P : Entity_Id) is
kono
parents:
diff changeset
2421 Id : Entity_Id;
kono
parents:
diff changeset
2422 Last_Entity : Entity_Id;
kono
parents:
diff changeset
2423
kono
parents:
diff changeset
2424 begin
kono
parents:
diff changeset
2425 pragma Assert
kono
parents:
diff changeset
2426 (Is_Package_Or_Generic_Package (P) or else Is_Record_Type (P));
kono
parents:
diff changeset
2427
kono
parents:
diff changeset
2428 if Is_Package_Or_Generic_Package (P) then
kono
parents:
diff changeset
2429 Last_Entity := First_Private_Entity (P);
kono
parents:
diff changeset
2430 else
kono
parents:
diff changeset
2431 Last_Entity := Empty;
kono
parents:
diff changeset
2432 end if;
kono
parents:
diff changeset
2433
kono
parents:
diff changeset
2434 Id := First_Entity (P);
kono
parents:
diff changeset
2435 while Present (Id) and then Id /= Last_Entity loop
kono
parents:
diff changeset
2436 Install_Package_Entity (Id);
kono
parents:
diff changeset
2437 Next_Entity (Id);
kono
parents:
diff changeset
2438 end loop;
kono
parents:
diff changeset
2439 end Install_Visible_Declarations;
kono
parents:
diff changeset
2440
kono
parents:
diff changeset
2441 --------------------------
kono
parents:
diff changeset
2442 -- Is_Private_Base_Type --
kono
parents:
diff changeset
2443 --------------------------
kono
parents:
diff changeset
2444
kono
parents:
diff changeset
2445 function Is_Private_Base_Type (E : Entity_Id) return Boolean is
kono
parents:
diff changeset
2446 begin
kono
parents:
diff changeset
2447 return Ekind (E) = E_Private_Type
kono
parents:
diff changeset
2448 or else Ekind (E) = E_Limited_Private_Type
kono
parents:
diff changeset
2449 or else Ekind (E) = E_Record_Type_With_Private;
kono
parents:
diff changeset
2450 end Is_Private_Base_Type;
kono
parents:
diff changeset
2451
kono
parents:
diff changeset
2452 --------------------------
kono
parents:
diff changeset
2453 -- Is_Visible_Dependent --
kono
parents:
diff changeset
2454 --------------------------
kono
parents:
diff changeset
2455
kono
parents:
diff changeset
2456 function Is_Visible_Dependent (Dep : Entity_Id) return Boolean
kono
parents:
diff changeset
2457 is
kono
parents:
diff changeset
2458 S : constant Entity_Id := Scope (Dep);
kono
parents:
diff changeset
2459
kono
parents:
diff changeset
2460 begin
kono
parents:
diff changeset
2461 -- Renamings created for actual types have the visibility of the actual
kono
parents:
diff changeset
2462
kono
parents:
diff changeset
2463 if Ekind (S) = E_Package
kono
parents:
diff changeset
2464 and then Is_Generic_Instance (S)
kono
parents:
diff changeset
2465 and then (Is_Generic_Actual_Type (Dep)
kono
parents:
diff changeset
2466 or else Is_Generic_Actual_Type (Full_View (Dep)))
kono
parents:
diff changeset
2467 then
kono
parents:
diff changeset
2468 return True;
kono
parents:
diff changeset
2469
kono
parents:
diff changeset
2470 elsif not (Is_Derived_Type (Dep))
kono
parents:
diff changeset
2471 and then Is_Derived_Type (Full_View (Dep))
kono
parents:
diff changeset
2472 then
kono
parents:
diff changeset
2473 -- When instantiating a package body, the scope stack is empty, so
kono
parents:
diff changeset
2474 -- check instead whether the dependent type is defined in the same
kono
parents:
diff changeset
2475 -- scope as the instance itself.
kono
parents:
diff changeset
2476
kono
parents:
diff changeset
2477 return In_Open_Scopes (S)
kono
parents:
diff changeset
2478 or else (Is_Generic_Instance (Current_Scope)
kono
parents:
diff changeset
2479 and then Scope (Dep) = Scope (Current_Scope));
kono
parents:
diff changeset
2480 else
kono
parents:
diff changeset
2481 return True;
kono
parents:
diff changeset
2482 end if;
kono
parents:
diff changeset
2483 end Is_Visible_Dependent;
kono
parents:
diff changeset
2484
kono
parents:
diff changeset
2485 ----------------------------
kono
parents:
diff changeset
2486 -- May_Need_Implicit_Body --
kono
parents:
diff changeset
2487 ----------------------------
kono
parents:
diff changeset
2488
kono
parents:
diff changeset
2489 procedure May_Need_Implicit_Body (E : Entity_Id) is
kono
parents:
diff changeset
2490 P : constant Node_Id := Unit_Declaration_Node (E);
kono
parents:
diff changeset
2491 S : constant Node_Id := Parent (P);
kono
parents:
diff changeset
2492 B : Node_Id;
kono
parents:
diff changeset
2493 Decls : List_Id;
kono
parents:
diff changeset
2494
kono
parents:
diff changeset
2495 begin
kono
parents:
diff changeset
2496 if not Has_Completion (E)
kono
parents:
diff changeset
2497 and then Nkind (P) = N_Package_Declaration
kono
parents:
diff changeset
2498 and then (Present (Activation_Chain_Entity (P)) or else Has_RACW (E))
kono
parents:
diff changeset
2499 then
kono
parents:
diff changeset
2500 B :=
kono
parents:
diff changeset
2501 Make_Package_Body (Sloc (E),
kono
parents:
diff changeset
2502 Defining_Unit_Name => Make_Defining_Identifier (Sloc (E),
kono
parents:
diff changeset
2503 Chars => Chars (E)),
kono
parents:
diff changeset
2504 Declarations => New_List);
kono
parents:
diff changeset
2505
kono
parents:
diff changeset
2506 if Nkind (S) = N_Package_Specification then
kono
parents:
diff changeset
2507 if Present (Private_Declarations (S)) then
kono
parents:
diff changeset
2508 Decls := Private_Declarations (S);
kono
parents:
diff changeset
2509 else
kono
parents:
diff changeset
2510 Decls := Visible_Declarations (S);
kono
parents:
diff changeset
2511 end if;
kono
parents:
diff changeset
2512 else
kono
parents:
diff changeset
2513 Decls := Declarations (S);
kono
parents:
diff changeset
2514 end if;
kono
parents:
diff changeset
2515
kono
parents:
diff changeset
2516 Append (B, Decls);
kono
parents:
diff changeset
2517 Analyze (B);
kono
parents:
diff changeset
2518 end if;
kono
parents:
diff changeset
2519 end May_Need_Implicit_Body;
kono
parents:
diff changeset
2520
kono
parents:
diff changeset
2521 ----------------------
kono
parents:
diff changeset
2522 -- New_Private_Type --
kono
parents:
diff changeset
2523 ----------------------
kono
parents:
diff changeset
2524
kono
parents:
diff changeset
2525 procedure New_Private_Type (N : Node_Id; Id : Entity_Id; Def : Node_Id) is
kono
parents:
diff changeset
2526 begin
kono
parents:
diff changeset
2527 -- For other than Ada 2012, enter the name in the current scope
kono
parents:
diff changeset
2528
kono
parents:
diff changeset
2529 if Ada_Version < Ada_2012 then
kono
parents:
diff changeset
2530 Enter_Name (Id);
kono
parents:
diff changeset
2531
kono
parents:
diff changeset
2532 -- Ada 2012 (AI05-0162): Enter the name in the current scope. Note that
kono
parents:
diff changeset
2533 -- there may be an incomplete previous view.
kono
parents:
diff changeset
2534
kono
parents:
diff changeset
2535 else
kono
parents:
diff changeset
2536 declare
kono
parents:
diff changeset
2537 Prev : Entity_Id;
kono
parents:
diff changeset
2538 begin
kono
parents:
diff changeset
2539 Prev := Find_Type_Name (N);
kono
parents:
diff changeset
2540 pragma Assert (Prev = Id
kono
parents:
diff changeset
2541 or else (Ekind (Prev) = E_Incomplete_Type
kono
parents:
diff changeset
2542 and then Present (Full_View (Prev))
kono
parents:
diff changeset
2543 and then Full_View (Prev) = Id));
kono
parents:
diff changeset
2544 end;
kono
parents:
diff changeset
2545 end if;
kono
parents:
diff changeset
2546
kono
parents:
diff changeset
2547 if Limited_Present (Def) then
kono
parents:
diff changeset
2548 Set_Ekind (Id, E_Limited_Private_Type);
kono
parents:
diff changeset
2549 else
kono
parents:
diff changeset
2550 Set_Ekind (Id, E_Private_Type);
kono
parents:
diff changeset
2551 end if;
kono
parents:
diff changeset
2552
kono
parents:
diff changeset
2553 Set_Etype (Id, Id);
kono
parents:
diff changeset
2554 Set_Has_Delayed_Freeze (Id);
kono
parents:
diff changeset
2555 Set_Is_First_Subtype (Id);
kono
parents:
diff changeset
2556 Init_Size_Align (Id);
kono
parents:
diff changeset
2557
kono
parents:
diff changeset
2558 Set_Is_Constrained (Id,
kono
parents:
diff changeset
2559 No (Discriminant_Specifications (N))
kono
parents:
diff changeset
2560 and then not Unknown_Discriminants_Present (N));
kono
parents:
diff changeset
2561
kono
parents:
diff changeset
2562 -- Set tagged flag before processing discriminants, to catch illegal
kono
parents:
diff changeset
2563 -- usage.
kono
parents:
diff changeset
2564
kono
parents:
diff changeset
2565 Set_Is_Tagged_Type (Id, Tagged_Present (Def));
kono
parents:
diff changeset
2566
kono
parents:
diff changeset
2567 Set_Discriminant_Constraint (Id, No_Elist);
kono
parents:
diff changeset
2568 Set_Stored_Constraint (Id, No_Elist);
kono
parents:
diff changeset
2569
kono
parents:
diff changeset
2570 if Present (Discriminant_Specifications (N)) then
kono
parents:
diff changeset
2571 Push_Scope (Id);
kono
parents:
diff changeset
2572 Process_Discriminants (N);
kono
parents:
diff changeset
2573 End_Scope;
kono
parents:
diff changeset
2574
kono
parents:
diff changeset
2575 elsif Unknown_Discriminants_Present (N) then
kono
parents:
diff changeset
2576 Set_Has_Unknown_Discriminants (Id);
kono
parents:
diff changeset
2577 end if;
kono
parents:
diff changeset
2578
kono
parents:
diff changeset
2579 Set_Private_Dependents (Id, New_Elmt_List);
kono
parents:
diff changeset
2580
kono
parents:
diff changeset
2581 if Tagged_Present (Def) then
kono
parents:
diff changeset
2582 Set_Ekind (Id, E_Record_Type_With_Private);
kono
parents:
diff changeset
2583 Set_Direct_Primitive_Operations (Id, New_Elmt_List);
kono
parents:
diff changeset
2584 Set_Is_Abstract_Type (Id, Abstract_Present (Def));
kono
parents:
diff changeset
2585 Set_Is_Limited_Record (Id, Limited_Present (Def));
kono
parents:
diff changeset
2586 Set_Has_Delayed_Freeze (Id, True);
kono
parents:
diff changeset
2587
kono
parents:
diff changeset
2588 -- Recognize Ada.Real_Time.Timing_Events.Timing_Events here
kono
parents:
diff changeset
2589
kono
parents:
diff changeset
2590 if Is_RTE (Id, RE_Timing_Event) then
kono
parents:
diff changeset
2591 Set_Has_Timing_Event (Id);
kono
parents:
diff changeset
2592 end if;
kono
parents:
diff changeset
2593
kono
parents:
diff changeset
2594 -- Create a class-wide type with the same attributes
kono
parents:
diff changeset
2595
kono
parents:
diff changeset
2596 Make_Class_Wide_Type (Id);
kono
parents:
diff changeset
2597
kono
parents:
diff changeset
2598 elsif Abstract_Present (Def) then
kono
parents:
diff changeset
2599 Error_Msg_N ("only a tagged type can be abstract", N);
kono
parents:
diff changeset
2600 end if;
kono
parents:
diff changeset
2601 end New_Private_Type;
kono
parents:
diff changeset
2602
kono
parents:
diff changeset
2603 ---------------------------------
kono
parents:
diff changeset
2604 -- Requires_Completion_In_Body --
kono
parents:
diff changeset
2605 ---------------------------------
kono
parents:
diff changeset
2606
kono
parents:
diff changeset
2607 function Requires_Completion_In_Body
kono
parents:
diff changeset
2608 (Id : Entity_Id;
kono
parents:
diff changeset
2609 Pack_Id : Entity_Id;
kono
parents:
diff changeset
2610 Do_Abstract_States : Boolean := False) return Boolean
kono
parents:
diff changeset
2611 is
kono
parents:
diff changeset
2612 begin
kono
parents:
diff changeset
2613 -- Always ignore child units. Child units get added to the entity list
kono
parents:
diff changeset
2614 -- of a parent unit, but are not original entities of the parent, and
kono
parents:
diff changeset
2615 -- so do not affect whether the parent needs a body.
kono
parents:
diff changeset
2616
kono
parents:
diff changeset
2617 if Is_Child_Unit (Id) then
kono
parents:
diff changeset
2618 return False;
kono
parents:
diff changeset
2619
kono
parents:
diff changeset
2620 -- Ignore formal packages and their renamings
kono
parents:
diff changeset
2621
kono
parents:
diff changeset
2622 elsif Ekind (Id) = E_Package
kono
parents:
diff changeset
2623 and then Nkind (Original_Node (Unit_Declaration_Node (Id))) =
kono
parents:
diff changeset
2624 N_Formal_Package_Declaration
kono
parents:
diff changeset
2625 then
kono
parents:
diff changeset
2626 return False;
kono
parents:
diff changeset
2627
kono
parents:
diff changeset
2628 -- Otherwise test to see if entity requires a completion. Note that
kono
parents:
diff changeset
2629 -- subprogram entities whose declaration does not come from source are
kono
parents:
diff changeset
2630 -- ignored here on the basis that we assume the expander will provide an
kono
parents:
diff changeset
2631 -- implicit completion at some point.
kono
parents:
diff changeset
2632
kono
parents:
diff changeset
2633 elsif (Is_Overloadable (Id)
kono
parents:
diff changeset
2634 and then not Ekind_In (Id, E_Enumeration_Literal, E_Operator)
kono
parents:
diff changeset
2635 and then not Is_Abstract_Subprogram (Id)
kono
parents:
diff changeset
2636 and then not Has_Completion (Id)
kono
parents:
diff changeset
2637 and then Comes_From_Source (Parent (Id)))
kono
parents:
diff changeset
2638
kono
parents:
diff changeset
2639 or else
kono
parents:
diff changeset
2640 (Ekind (Id) = E_Package
kono
parents:
diff changeset
2641 and then Id /= Pack_Id
kono
parents:
diff changeset
2642 and then not Has_Completion (Id)
kono
parents:
diff changeset
2643 and then Unit_Requires_Body (Id, Do_Abstract_States))
kono
parents:
diff changeset
2644
kono
parents:
diff changeset
2645 or else
kono
parents:
diff changeset
2646 (Ekind (Id) = E_Incomplete_Type
kono
parents:
diff changeset
2647 and then No (Full_View (Id))
kono
parents:
diff changeset
2648 and then not Is_Generic_Type (Id))
kono
parents:
diff changeset
2649
kono
parents:
diff changeset
2650 or else
kono
parents:
diff changeset
2651 (Ekind_In (Id, E_Task_Type, E_Protected_Type)
kono
parents:
diff changeset
2652 and then not Has_Completion (Id))
kono
parents:
diff changeset
2653
kono
parents:
diff changeset
2654 or else
kono
parents:
diff changeset
2655 (Ekind (Id) = E_Generic_Package
kono
parents:
diff changeset
2656 and then Id /= Pack_Id
kono
parents:
diff changeset
2657 and then not Has_Completion (Id)
kono
parents:
diff changeset
2658 and then Unit_Requires_Body (Id, Do_Abstract_States))
kono
parents:
diff changeset
2659
kono
parents:
diff changeset
2660 or else
kono
parents:
diff changeset
2661 (Is_Generic_Subprogram (Id)
kono
parents:
diff changeset
2662 and then not Has_Completion (Id))
kono
parents:
diff changeset
2663 then
kono
parents:
diff changeset
2664 return True;
kono
parents:
diff changeset
2665
kono
parents:
diff changeset
2666 -- Otherwise the entity does not require completion in a package body
kono
parents:
diff changeset
2667
kono
parents:
diff changeset
2668 else
kono
parents:
diff changeset
2669 return False;
kono
parents:
diff changeset
2670 end if;
kono
parents:
diff changeset
2671 end Requires_Completion_In_Body;
kono
parents:
diff changeset
2672
kono
parents:
diff changeset
2673 ----------------------------
kono
parents:
diff changeset
2674 -- Uninstall_Declarations --
kono
parents:
diff changeset
2675 ----------------------------
kono
parents:
diff changeset
2676
kono
parents:
diff changeset
2677 procedure Uninstall_Declarations (P : Entity_Id) is
kono
parents:
diff changeset
2678 Decl : constant Node_Id := Unit_Declaration_Node (P);
kono
parents:
diff changeset
2679 Id : Entity_Id;
kono
parents:
diff changeset
2680 Full : Entity_Id;
kono
parents:
diff changeset
2681 Priv_Elmt : Elmt_Id;
kono
parents:
diff changeset
2682 Priv_Sub : Entity_Id;
kono
parents:
diff changeset
2683
kono
parents:
diff changeset
2684 procedure Preserve_Full_Attributes (Priv : Entity_Id; Full : Entity_Id);
kono
parents:
diff changeset
2685 -- Copy to the private declaration the attributes of the full view that
kono
parents:
diff changeset
2686 -- need to be available for the partial view also.
kono
parents:
diff changeset
2687
kono
parents:
diff changeset
2688 function Type_In_Use (T : Entity_Id) return Boolean;
kono
parents:
diff changeset
2689 -- Check whether type or base type appear in an active use_type clause
kono
parents:
diff changeset
2690
kono
parents:
diff changeset
2691 ------------------------------
kono
parents:
diff changeset
2692 -- Preserve_Full_Attributes --
kono
parents:
diff changeset
2693 ------------------------------
kono
parents:
diff changeset
2694
kono
parents:
diff changeset
2695 procedure Preserve_Full_Attributes
kono
parents:
diff changeset
2696 (Priv : Entity_Id;
kono
parents:
diff changeset
2697 Full : Entity_Id)
kono
parents:
diff changeset
2698 is
kono
parents:
diff changeset
2699 Full_Base : constant Entity_Id := Base_Type (Full);
kono
parents:
diff changeset
2700 Priv_Is_Base_Type : constant Boolean := Is_Base_Type (Priv);
kono
parents:
diff changeset
2701
kono
parents:
diff changeset
2702 begin
kono
parents:
diff changeset
2703 Set_Size_Info (Priv, Full);
kono
parents:
diff changeset
2704 Set_RM_Size (Priv, RM_Size (Full));
kono
parents:
diff changeset
2705 Set_Size_Known_At_Compile_Time
kono
parents:
diff changeset
2706 (Priv, Size_Known_At_Compile_Time (Full));
kono
parents:
diff changeset
2707 Set_Is_Volatile (Priv, Is_Volatile (Full));
kono
parents:
diff changeset
2708 Set_Treat_As_Volatile (Priv, Treat_As_Volatile (Full));
kono
parents:
diff changeset
2709 Set_Is_Ada_2005_Only (Priv, Is_Ada_2005_Only (Full));
kono
parents:
diff changeset
2710 Set_Is_Ada_2012_Only (Priv, Is_Ada_2012_Only (Full));
kono
parents:
diff changeset
2711 Set_Has_Pragma_Unmodified (Priv, Has_Pragma_Unmodified (Full));
kono
parents:
diff changeset
2712 Set_Has_Pragma_Unreferenced (Priv, Has_Pragma_Unreferenced (Full));
kono
parents:
diff changeset
2713 Set_Has_Pragma_Unreferenced_Objects
kono
parents:
diff changeset
2714 (Priv, Has_Pragma_Unreferenced_Objects
kono
parents:
diff changeset
2715 (Full));
kono
parents:
diff changeset
2716 if Is_Unchecked_Union (Full) then
kono
parents:
diff changeset
2717 Set_Is_Unchecked_Union (Base_Type (Priv));
kono
parents:
diff changeset
2718 end if;
kono
parents:
diff changeset
2719 -- Why is atomic not copied here ???
kono
parents:
diff changeset
2720
kono
parents:
diff changeset
2721 if Referenced (Full) then
kono
parents:
diff changeset
2722 Set_Referenced (Priv);
kono
parents:
diff changeset
2723 end if;
kono
parents:
diff changeset
2724
kono
parents:
diff changeset
2725 if Priv_Is_Base_Type then
kono
parents:
diff changeset
2726 Set_Is_Controlled_Active
kono
parents:
diff changeset
2727 (Priv, Is_Controlled_Active (Full_Base));
kono
parents:
diff changeset
2728 Set_Finalize_Storage_Only
kono
parents:
diff changeset
2729 (Priv, Finalize_Storage_Only (Full_Base));
kono
parents:
diff changeset
2730 Set_Has_Controlled_Component
kono
parents:
diff changeset
2731 (Priv, Has_Controlled_Component (Full_Base));
kono
parents:
diff changeset
2732
kono
parents:
diff changeset
2733 Propagate_Concurrent_Flags (Priv, Base_Type (Full));
kono
parents:
diff changeset
2734 end if;
kono
parents:
diff changeset
2735
kono
parents:
diff changeset
2736 Set_Freeze_Node (Priv, Freeze_Node (Full));
kono
parents:
diff changeset
2737
kono
parents:
diff changeset
2738 -- Propagate Default_Initial_Condition-related attributes from the
kono
parents:
diff changeset
2739 -- base type of the full view to the full view and vice versa. This
kono
parents:
diff changeset
2740 -- may seem strange, but is necessary depending on which type
kono
parents:
diff changeset
2741 -- triggered the generation of the DIC procedure body. As a result,
kono
parents:
diff changeset
2742 -- both the full view and its base type carry the same DIC-related
kono
parents:
diff changeset
2743 -- information.
kono
parents:
diff changeset
2744
kono
parents:
diff changeset
2745 Propagate_DIC_Attributes (Full, From_Typ => Full_Base);
kono
parents:
diff changeset
2746 Propagate_DIC_Attributes (Full_Base, From_Typ => Full);
kono
parents:
diff changeset
2747
kono
parents:
diff changeset
2748 -- Propagate Default_Initial_Condition-related attributes from the
kono
parents:
diff changeset
2749 -- full view to the private view.
kono
parents:
diff changeset
2750
kono
parents:
diff changeset
2751 Propagate_DIC_Attributes (Priv, From_Typ => Full);
kono
parents:
diff changeset
2752
kono
parents:
diff changeset
2753 -- Propagate invariant-related attributes from the base type of the
kono
parents:
diff changeset
2754 -- full view to the full view and vice versa. This may seem strange,
kono
parents:
diff changeset
2755 -- but is necessary depending on which type triggered the generation
kono
parents:
diff changeset
2756 -- of the invariant procedure body. As a result, both the full view
kono
parents:
diff changeset
2757 -- and its base type carry the same invariant-related information.
kono
parents:
diff changeset
2758
kono
parents:
diff changeset
2759 Propagate_Invariant_Attributes (Full, From_Typ => Full_Base);
kono
parents:
diff changeset
2760 Propagate_Invariant_Attributes (Full_Base, From_Typ => Full);
kono
parents:
diff changeset
2761
kono
parents:
diff changeset
2762 -- Propagate invariant-related attributes from the full view to the
kono
parents:
diff changeset
2763 -- private view.
kono
parents:
diff changeset
2764
kono
parents:
diff changeset
2765 Propagate_Invariant_Attributes (Priv, From_Typ => Full);
kono
parents:
diff changeset
2766
kono
parents:
diff changeset
2767 if Is_Tagged_Type (Priv)
kono
parents:
diff changeset
2768 and then Is_Tagged_Type (Full)
kono
parents:
diff changeset
2769 and then not Error_Posted (Full)
kono
parents:
diff changeset
2770 then
kono
parents:
diff changeset
2771 if Is_Tagged_Type (Priv) then
kono
parents:
diff changeset
2772
kono
parents:
diff changeset
2773 -- If the type is tagged, the tag itself must be available on
kono
parents:
diff changeset
2774 -- the partial view, for expansion purposes.
kono
parents:
diff changeset
2775
kono
parents:
diff changeset
2776 Set_First_Entity (Priv, First_Entity (Full));
kono
parents:
diff changeset
2777
kono
parents:
diff changeset
2778 -- If there are discriminants in the partial view, these remain
kono
parents:
diff changeset
2779 -- visible. Otherwise only the tag itself is visible, and there
kono
parents:
diff changeset
2780 -- are no nameable components in the partial view.
kono
parents:
diff changeset
2781
kono
parents:
diff changeset
2782 if No (Last_Entity (Priv)) then
kono
parents:
diff changeset
2783 Set_Last_Entity (Priv, First_Entity (Priv));
kono
parents:
diff changeset
2784 end if;
kono
parents:
diff changeset
2785 end if;
kono
parents:
diff changeset
2786
kono
parents:
diff changeset
2787 Set_Has_Discriminants (Priv, Has_Discriminants (Full));
kono
parents:
diff changeset
2788
kono
parents:
diff changeset
2789 if Has_Discriminants (Full) then
kono
parents:
diff changeset
2790 Set_Discriminant_Constraint (Priv,
kono
parents:
diff changeset
2791 Discriminant_Constraint (Full));
kono
parents:
diff changeset
2792 end if;
kono
parents:
diff changeset
2793 end if;
kono
parents:
diff changeset
2794 end Preserve_Full_Attributes;
kono
parents:
diff changeset
2795
kono
parents:
diff changeset
2796 -----------------
kono
parents:
diff changeset
2797 -- Type_In_Use --
kono
parents:
diff changeset
2798 -----------------
kono
parents:
diff changeset
2799
kono
parents:
diff changeset
2800 function Type_In_Use (T : Entity_Id) return Boolean is
kono
parents:
diff changeset
2801 begin
kono
parents:
diff changeset
2802 return Scope (Base_Type (T)) = P
kono
parents:
diff changeset
2803 and then (In_Use (T) or else In_Use (Base_Type (T)));
kono
parents:
diff changeset
2804 end Type_In_Use;
kono
parents:
diff changeset
2805
kono
parents:
diff changeset
2806 -- Start of processing for Uninstall_Declarations
kono
parents:
diff changeset
2807
kono
parents:
diff changeset
2808 begin
kono
parents:
diff changeset
2809 Id := First_Entity (P);
kono
parents:
diff changeset
2810 while Present (Id) and then Id /= First_Private_Entity (P) loop
kono
parents:
diff changeset
2811 if Debug_Flag_E then
kono
parents:
diff changeset
2812 Write_Str ("unlinking visible entity ");
kono
parents:
diff changeset
2813 Write_Int (Int (Id));
kono
parents:
diff changeset
2814 Write_Eol;
kono
parents:
diff changeset
2815 end if;
kono
parents:
diff changeset
2816
kono
parents:
diff changeset
2817 -- On exit from the package scope, we must preserve the visibility
kono
parents:
diff changeset
2818 -- established by use clauses in the current scope. Two cases:
kono
parents:
diff changeset
2819
kono
parents:
diff changeset
2820 -- a) If the entity is an operator, it may be a primitive operator of
kono
parents:
diff changeset
2821 -- a type for which there is a visible use-type clause.
kono
parents:
diff changeset
2822
kono
parents:
diff changeset
2823 -- b) for other entities, their use-visibility is determined by a
kono
parents:
diff changeset
2824 -- visible use clause for the package itself. For a generic instance,
kono
parents:
diff changeset
2825 -- the instantiation of the formals appears in the visible part,
kono
parents:
diff changeset
2826 -- but the formals are private and remain so.
kono
parents:
diff changeset
2827
kono
parents:
diff changeset
2828 if Ekind (Id) = E_Function
kono
parents:
diff changeset
2829 and then Is_Operator_Symbol_Name (Chars (Id))
kono
parents:
diff changeset
2830 and then not Is_Hidden (Id)
kono
parents:
diff changeset
2831 and then not Error_Posted (Id)
kono
parents:
diff changeset
2832 then
kono
parents:
diff changeset
2833 Set_Is_Potentially_Use_Visible (Id,
kono
parents:
diff changeset
2834 In_Use (P)
kono
parents:
diff changeset
2835 or else Type_In_Use (Etype (Id))
kono
parents:
diff changeset
2836 or else Type_In_Use (Etype (First_Formal (Id)))
kono
parents:
diff changeset
2837 or else (Present (Next_Formal (First_Formal (Id)))
kono
parents:
diff changeset
2838 and then
kono
parents:
diff changeset
2839 Type_In_Use
kono
parents:
diff changeset
2840 (Etype (Next_Formal (First_Formal (Id))))));
kono
parents:
diff changeset
2841 else
kono
parents:
diff changeset
2842 if In_Use (P) and then not Is_Hidden (Id) then
kono
parents:
diff changeset
2843
kono
parents:
diff changeset
2844 -- A child unit of a use-visible package remains use-visible
kono
parents:
diff changeset
2845 -- only if it is itself a visible child unit. Otherwise it
kono
parents:
diff changeset
2846 -- would remain visible in other contexts where P is use-
kono
parents:
diff changeset
2847 -- visible, because once compiled it stays in the entity list
kono
parents:
diff changeset
2848 -- of its parent unit.
kono
parents:
diff changeset
2849
kono
parents:
diff changeset
2850 if Is_Child_Unit (Id) then
kono
parents:
diff changeset
2851 Set_Is_Potentially_Use_Visible
kono
parents:
diff changeset
2852 (Id, Is_Visible_Lib_Unit (Id));
kono
parents:
diff changeset
2853 else
kono
parents:
diff changeset
2854 Set_Is_Potentially_Use_Visible (Id);
kono
parents:
diff changeset
2855 end if;
kono
parents:
diff changeset
2856
kono
parents:
diff changeset
2857 else
kono
parents:
diff changeset
2858 Set_Is_Potentially_Use_Visible (Id, False);
kono
parents:
diff changeset
2859 end if;
kono
parents:
diff changeset
2860 end if;
kono
parents:
diff changeset
2861
kono
parents:
diff changeset
2862 -- Local entities are not immediately visible outside of the package
kono
parents:
diff changeset
2863
kono
parents:
diff changeset
2864 Set_Is_Immediately_Visible (Id, False);
kono
parents:
diff changeset
2865
kono
parents:
diff changeset
2866 -- If this is a private type with a full view (for example a local
kono
parents:
diff changeset
2867 -- subtype of a private type declared elsewhere), ensure that the
kono
parents:
diff changeset
2868 -- full view is also removed from visibility: it may be exposed when
kono
parents:
diff changeset
2869 -- swapping views in an instantiation. Similarly, ensure that the
kono
parents:
diff changeset
2870 -- use-visibility is properly set on both views.
kono
parents:
diff changeset
2871
kono
parents:
diff changeset
2872 if Is_Type (Id) and then Present (Full_View (Id)) then
kono
parents:
diff changeset
2873 Set_Is_Immediately_Visible (Full_View (Id), False);
kono
parents:
diff changeset
2874 Set_Is_Potentially_Use_Visible (Full_View (Id),
kono
parents:
diff changeset
2875 Is_Potentially_Use_Visible (Id));
kono
parents:
diff changeset
2876 end if;
kono
parents:
diff changeset
2877
kono
parents:
diff changeset
2878 if Is_Tagged_Type (Id) and then Ekind (Id) = E_Record_Type then
kono
parents:
diff changeset
2879 Check_Abstract_Overriding (Id);
kono
parents:
diff changeset
2880 Check_Conventions (Id);
kono
parents:
diff changeset
2881 end if;
kono
parents:
diff changeset
2882
kono
parents:
diff changeset
2883 if Ekind_In (Id, E_Private_Type, E_Limited_Private_Type)
kono
parents:
diff changeset
2884 and then No (Full_View (Id))
kono
parents:
diff changeset
2885 and then not Is_Generic_Type (Id)
kono
parents:
diff changeset
2886 and then not Is_Derived_Type (Id)
kono
parents:
diff changeset
2887 then
kono
parents:
diff changeset
2888 Error_Msg_N ("missing full declaration for private type&", Id);
kono
parents:
diff changeset
2889
kono
parents:
diff changeset
2890 elsif Ekind (Id) = E_Record_Type_With_Private
kono
parents:
diff changeset
2891 and then not Is_Generic_Type (Id)
kono
parents:
diff changeset
2892 and then No (Full_View (Id))
kono
parents:
diff changeset
2893 then
kono
parents:
diff changeset
2894 if Nkind (Parent (Id)) = N_Private_Type_Declaration then
kono
parents:
diff changeset
2895 Error_Msg_N ("missing full declaration for private type&", Id);
kono
parents:
diff changeset
2896 else
kono
parents:
diff changeset
2897 Error_Msg_N
kono
parents:
diff changeset
2898 ("missing full declaration for private extension", Id);
kono
parents:
diff changeset
2899 end if;
kono
parents:
diff changeset
2900
kono
parents:
diff changeset
2901 -- Case of constant, check for deferred constant declaration with
kono
parents:
diff changeset
2902 -- no full view. Likely just a matter of a missing expression, or
kono
parents:
diff changeset
2903 -- accidental use of the keyword constant.
kono
parents:
diff changeset
2904
kono
parents:
diff changeset
2905 elsif Ekind (Id) = E_Constant
kono
parents:
diff changeset
2906
kono
parents:
diff changeset
2907 -- OK if constant value present
kono
parents:
diff changeset
2908
kono
parents:
diff changeset
2909 and then No (Constant_Value (Id))
kono
parents:
diff changeset
2910
kono
parents:
diff changeset
2911 -- OK if full view present
kono
parents:
diff changeset
2912
kono
parents:
diff changeset
2913 and then No (Full_View (Id))
kono
parents:
diff changeset
2914
kono
parents:
diff changeset
2915 -- OK if imported, since that provides the completion
kono
parents:
diff changeset
2916
kono
parents:
diff changeset
2917 and then not Is_Imported (Id)
kono
parents:
diff changeset
2918
kono
parents:
diff changeset
2919 -- OK if object declaration replaced by renaming declaration as
kono
parents:
diff changeset
2920 -- a result of OK_To_Rename processing (e.g. for concatenation)
kono
parents:
diff changeset
2921
kono
parents:
diff changeset
2922 and then Nkind (Parent (Id)) /= N_Object_Renaming_Declaration
kono
parents:
diff changeset
2923
kono
parents:
diff changeset
2924 -- OK if object declaration with the No_Initialization flag set
kono
parents:
diff changeset
2925
kono
parents:
diff changeset
2926 and then not (Nkind (Parent (Id)) = N_Object_Declaration
kono
parents:
diff changeset
2927 and then No_Initialization (Parent (Id)))
kono
parents:
diff changeset
2928 then
kono
parents:
diff changeset
2929 -- If no private declaration is present, we assume the user did
kono
parents:
diff changeset
2930 -- not intend a deferred constant declaration and the problem
kono
parents:
diff changeset
2931 -- is simply that the initializing expression is missing.
kono
parents:
diff changeset
2932
kono
parents:
diff changeset
2933 if not Has_Private_Declaration (Etype (Id)) then
kono
parents:
diff changeset
2934
kono
parents:
diff changeset
2935 -- We assume that the user did not intend a deferred constant
kono
parents:
diff changeset
2936 -- declaration, and the expression is just missing.
kono
parents:
diff changeset
2937
kono
parents:
diff changeset
2938 Error_Msg_N
kono
parents:
diff changeset
2939 ("constant declaration requires initialization expression",
kono
parents:
diff changeset
2940 Parent (Id));
kono
parents:
diff changeset
2941
kono
parents:
diff changeset
2942 if Is_Limited_Type (Etype (Id)) then
kono
parents:
diff changeset
2943 Error_Msg_N
kono
parents:
diff changeset
2944 ("\if variable intended, remove CONSTANT from declaration",
kono
parents:
diff changeset
2945 Parent (Id));
kono
parents:
diff changeset
2946 end if;
kono
parents:
diff changeset
2947
kono
parents:
diff changeset
2948 -- Otherwise if a private declaration is present, then we are
kono
parents:
diff changeset
2949 -- missing the full declaration for the deferred constant.
kono
parents:
diff changeset
2950
kono
parents:
diff changeset
2951 else
kono
parents:
diff changeset
2952 Error_Msg_N
kono
parents:
diff changeset
2953 ("missing full declaration for deferred constant (RM 7.4)",
kono
parents:
diff changeset
2954 Id);
kono
parents:
diff changeset
2955
kono
parents:
diff changeset
2956 if Is_Limited_Type (Etype (Id)) then
kono
parents:
diff changeset
2957 Error_Msg_N
kono
parents:
diff changeset
2958 ("\if variable intended, remove CONSTANT from declaration",
kono
parents:
diff changeset
2959 Parent (Id));
kono
parents:
diff changeset
2960 end if;
kono
parents:
diff changeset
2961 end if;
kono
parents:
diff changeset
2962 end if;
kono
parents:
diff changeset
2963
kono
parents:
diff changeset
2964 Next_Entity (Id);
kono
parents:
diff changeset
2965 end loop;
kono
parents:
diff changeset
2966
kono
parents:
diff changeset
2967 -- If the specification was installed as the parent of a public child
kono
parents:
diff changeset
2968 -- unit, the private declarations were not installed, and there is
kono
parents:
diff changeset
2969 -- nothing to do.
kono
parents:
diff changeset
2970
kono
parents:
diff changeset
2971 if not In_Private_Part (P) then
kono
parents:
diff changeset
2972 return;
kono
parents:
diff changeset
2973 else
kono
parents:
diff changeset
2974 Set_In_Private_Part (P, False);
kono
parents:
diff changeset
2975 end if;
kono
parents:
diff changeset
2976
kono
parents:
diff changeset
2977 -- Make private entities invisible and exchange full and private
kono
parents:
diff changeset
2978 -- declarations for private types. Id is now the first private entity
kono
parents:
diff changeset
2979 -- in the package.
kono
parents:
diff changeset
2980
kono
parents:
diff changeset
2981 while Present (Id) loop
kono
parents:
diff changeset
2982 if Debug_Flag_E then
kono
parents:
diff changeset
2983 Write_Str ("unlinking private entity ");
kono
parents:
diff changeset
2984 Write_Int (Int (Id));
kono
parents:
diff changeset
2985 Write_Eol;
kono
parents:
diff changeset
2986 end if;
kono
parents:
diff changeset
2987
kono
parents:
diff changeset
2988 if Is_Tagged_Type (Id) and then Ekind (Id) = E_Record_Type then
kono
parents:
diff changeset
2989 Check_Abstract_Overriding (Id);
kono
parents:
diff changeset
2990 Check_Conventions (Id);
kono
parents:
diff changeset
2991 end if;
kono
parents:
diff changeset
2992
kono
parents:
diff changeset
2993 Set_Is_Immediately_Visible (Id, False);
kono
parents:
diff changeset
2994
kono
parents:
diff changeset
2995 if Is_Private_Base_Type (Id) and then Present (Full_View (Id)) then
kono
parents:
diff changeset
2996 Full := Full_View (Id);
kono
parents:
diff changeset
2997
kono
parents:
diff changeset
2998 -- If the partial view is not declared in the visible part of the
kono
parents:
diff changeset
2999 -- package (as is the case when it is a type derived from some
kono
parents:
diff changeset
3000 -- other private type in the private part of the current package),
kono
parents:
diff changeset
3001 -- no exchange takes place.
kono
parents:
diff changeset
3002
kono
parents:
diff changeset
3003 if No (Parent (Id))
kono
parents:
diff changeset
3004 or else List_Containing (Parent (Id)) /=
kono
parents:
diff changeset
3005 Visible_Declarations (Specification (Decl))
kono
parents:
diff changeset
3006 then
kono
parents:
diff changeset
3007 goto Next_Id;
kono
parents:
diff changeset
3008 end if;
kono
parents:
diff changeset
3009
kono
parents:
diff changeset
3010 -- The entry in the private part points to the full declaration,
kono
parents:
diff changeset
3011 -- which is currently visible. Exchange them so only the private
kono
parents:
diff changeset
3012 -- type declaration remains accessible, and link private and full
kono
parents:
diff changeset
3013 -- declaration in the opposite direction. Before the actual
kono
parents:
diff changeset
3014 -- exchange, we copy back attributes of the full view that must
kono
parents:
diff changeset
3015 -- be available to the partial view too.
kono
parents:
diff changeset
3016
kono
parents:
diff changeset
3017 Preserve_Full_Attributes (Id, Full);
kono
parents:
diff changeset
3018
kono
parents:
diff changeset
3019 Set_Is_Potentially_Use_Visible (Id, In_Use (P));
kono
parents:
diff changeset
3020
kono
parents:
diff changeset
3021 -- The following test may be redundant, as this is already
kono
parents:
diff changeset
3022 -- diagnosed in sem_ch3. ???
kono
parents:
diff changeset
3023
kono
parents:
diff changeset
3024 if not Is_Definite_Subtype (Full)
kono
parents:
diff changeset
3025 and then Is_Definite_Subtype (Id)
kono
parents:
diff changeset
3026 then
kono
parents:
diff changeset
3027 Error_Msg_Sloc := Sloc (Parent (Id));
kono
parents:
diff changeset
3028 Error_Msg_NE
kono
parents:
diff changeset
3029 ("full view of& not compatible with declaration#", Full, Id);
kono
parents:
diff changeset
3030 end if;
kono
parents:
diff changeset
3031
kono
parents:
diff changeset
3032 -- Swap out the subtypes and derived types of Id that
kono
parents:
diff changeset
3033 -- were compiled in this scope, or installed previously
kono
parents:
diff changeset
3034 -- by Install_Private_Declarations.
kono
parents:
diff changeset
3035
kono
parents:
diff changeset
3036 -- Before we do the swap, we verify the presence of the Full_View
kono
parents:
diff changeset
3037 -- field which may be empty due to a swap by a previous call to
kono
parents:
diff changeset
3038 -- End_Package_Scope (e.g. from the freezing mechanism).
kono
parents:
diff changeset
3039
kono
parents:
diff changeset
3040 Priv_Elmt := First_Elmt (Private_Dependents (Id));
kono
parents:
diff changeset
3041 while Present (Priv_Elmt) loop
kono
parents:
diff changeset
3042 Priv_Sub := Node (Priv_Elmt);
kono
parents:
diff changeset
3043
kono
parents:
diff changeset
3044 if Present (Full_View (Priv_Sub)) then
kono
parents:
diff changeset
3045 if Scope (Priv_Sub) = P
kono
parents:
diff changeset
3046 or else not In_Open_Scopes (Scope (Priv_Sub))
kono
parents:
diff changeset
3047 then
kono
parents:
diff changeset
3048 Set_Is_Immediately_Visible (Priv_Sub, False);
kono
parents:
diff changeset
3049 end if;
kono
parents:
diff changeset
3050
kono
parents:
diff changeset
3051 if Is_Visible_Dependent (Priv_Sub) then
kono
parents:
diff changeset
3052 Preserve_Full_Attributes
kono
parents:
diff changeset
3053 (Priv_Sub, Full_View (Priv_Sub));
kono
parents:
diff changeset
3054 Replace_Elmt (Priv_Elmt, Full_View (Priv_Sub));
kono
parents:
diff changeset
3055 Exchange_Declarations (Priv_Sub);
kono
parents:
diff changeset
3056 end if;
kono
parents:
diff changeset
3057 end if;
kono
parents:
diff changeset
3058
kono
parents:
diff changeset
3059 Next_Elmt (Priv_Elmt);
kono
parents:
diff changeset
3060 end loop;
kono
parents:
diff changeset
3061
kono
parents:
diff changeset
3062 -- Now restore the type itself to its private view
kono
parents:
diff changeset
3063
kono
parents:
diff changeset
3064 Exchange_Declarations (Id);
kono
parents:
diff changeset
3065
kono
parents:
diff changeset
3066 -- If we have installed an underlying full view for a type derived
kono
parents:
diff changeset
3067 -- from a private type in a child unit, restore the proper views
kono
parents:
diff changeset
3068 -- of private and full view. See corresponding code in
kono
parents:
diff changeset
3069 -- Install_Private_Declarations.
kono
parents:
diff changeset
3070
kono
parents:
diff changeset
3071 -- After the exchange, Full denotes the private type in the
kono
parents:
diff changeset
3072 -- visible part of the package.
kono
parents:
diff changeset
3073
kono
parents:
diff changeset
3074 if Is_Private_Base_Type (Full)
kono
parents:
diff changeset
3075 and then Present (Full_View (Full))
kono
parents:
diff changeset
3076 and then Present (Underlying_Full_View (Full))
kono
parents:
diff changeset
3077 and then In_Package_Body (Current_Scope)
kono
parents:
diff changeset
3078 then
kono
parents:
diff changeset
3079 Set_Full_View (Full, Underlying_Full_View (Full));
kono
parents:
diff changeset
3080 Set_Underlying_Full_View (Full, Empty);
kono
parents:
diff changeset
3081 end if;
kono
parents:
diff changeset
3082
kono
parents:
diff changeset
3083 elsif Ekind (Id) = E_Incomplete_Type
kono
parents:
diff changeset
3084 and then Comes_From_Source (Id)
kono
parents:
diff changeset
3085 and then No (Full_View (Id))
kono
parents:
diff changeset
3086 then
kono
parents:
diff changeset
3087 -- Mark Taft amendment types. Verify that there are no primitive
kono
parents:
diff changeset
3088 -- operations declared for the type (3.10.1(9)).
kono
parents:
diff changeset
3089
kono
parents:
diff changeset
3090 Set_Has_Completion_In_Body (Id);
kono
parents:
diff changeset
3091
kono
parents:
diff changeset
3092 declare
kono
parents:
diff changeset
3093 Elmt : Elmt_Id;
kono
parents:
diff changeset
3094 Subp : Entity_Id;
kono
parents:
diff changeset
3095
kono
parents:
diff changeset
3096 begin
kono
parents:
diff changeset
3097 Elmt := First_Elmt (Private_Dependents (Id));
kono
parents:
diff changeset
3098 while Present (Elmt) loop
kono
parents:
diff changeset
3099 Subp := Node (Elmt);
kono
parents:
diff changeset
3100
kono
parents:
diff changeset
3101 -- Is_Primitive is tested because there can be cases where
kono
parents:
diff changeset
3102 -- nonprimitive subprograms (in nested packages) are added
kono
parents:
diff changeset
3103 -- to the Private_Dependents list.
kono
parents:
diff changeset
3104
kono
parents:
diff changeset
3105 if Is_Overloadable (Subp) and then Is_Primitive (Subp) then
kono
parents:
diff changeset
3106 Error_Msg_NE
kono
parents:
diff changeset
3107 ("type& must be completed in the private part",
kono
parents:
diff changeset
3108 Parent (Subp), Id);
kono
parents:
diff changeset
3109
kono
parents:
diff changeset
3110 -- The result type of an access-to-function type cannot be a
kono
parents:
diff changeset
3111 -- Taft-amendment type, unless the version is Ada 2012 or
kono
parents:
diff changeset
3112 -- later (see AI05-151).
kono
parents:
diff changeset
3113
kono
parents:
diff changeset
3114 elsif Ada_Version < Ada_2012
kono
parents:
diff changeset
3115 and then Ekind (Subp) = E_Subprogram_Type
kono
parents:
diff changeset
3116 then
kono
parents:
diff changeset
3117 if Etype (Subp) = Id
kono
parents:
diff changeset
3118 or else
kono
parents:
diff changeset
3119 (Is_Class_Wide_Type (Etype (Subp))
kono
parents:
diff changeset
3120 and then Etype (Etype (Subp)) = Id)
kono
parents:
diff changeset
3121 then
kono
parents:
diff changeset
3122 Error_Msg_NE
kono
parents:
diff changeset
3123 ("type& must be completed in the private part",
kono
parents:
diff changeset
3124 Associated_Node_For_Itype (Subp), Id);
kono
parents:
diff changeset
3125 end if;
kono
parents:
diff changeset
3126 end if;
kono
parents:
diff changeset
3127
kono
parents:
diff changeset
3128 Next_Elmt (Elmt);
kono
parents:
diff changeset
3129 end loop;
kono
parents:
diff changeset
3130 end;
kono
parents:
diff changeset
3131
kono
parents:
diff changeset
3132 elsif not Is_Child_Unit (Id)
kono
parents:
diff changeset
3133 and then (not Is_Private_Type (Id) or else No (Full_View (Id)))
kono
parents:
diff changeset
3134 then
kono
parents:
diff changeset
3135 Set_Is_Hidden (Id);
kono
parents:
diff changeset
3136 Set_Is_Potentially_Use_Visible (Id, False);
kono
parents:
diff changeset
3137 end if;
kono
parents:
diff changeset
3138
kono
parents:
diff changeset
3139 <<Next_Id>>
kono
parents:
diff changeset
3140 Next_Entity (Id);
kono
parents:
diff changeset
3141 end loop;
kono
parents:
diff changeset
3142 end Uninstall_Declarations;
kono
parents:
diff changeset
3143
kono
parents:
diff changeset
3144 ------------------------
kono
parents:
diff changeset
3145 -- Unit_Requires_Body --
kono
parents:
diff changeset
3146 ------------------------
kono
parents:
diff changeset
3147
kono
parents:
diff changeset
3148 function Unit_Requires_Body
kono
parents:
diff changeset
3149 (Pack_Id : Entity_Id;
kono
parents:
diff changeset
3150 Do_Abstract_States : Boolean := False) return Boolean
kono
parents:
diff changeset
3151 is
kono
parents:
diff changeset
3152 E : Entity_Id;
kono
parents:
diff changeset
3153
kono
parents:
diff changeset
3154 Requires_Body : Boolean := False;
kono
parents:
diff changeset
3155 -- Flag set when the unit has at least one construct that requries
kono
parents:
diff changeset
3156 -- completion in a body.
kono
parents:
diff changeset
3157
kono
parents:
diff changeset
3158 begin
kono
parents:
diff changeset
3159 -- Imported entity never requires body. Right now, only subprograms can
kono
parents:
diff changeset
3160 -- be imported, but perhaps in the future we will allow import of
kono
parents:
diff changeset
3161 -- packages.
kono
parents:
diff changeset
3162
kono
parents:
diff changeset
3163 if Is_Imported (Pack_Id) then
kono
parents:
diff changeset
3164 return False;
kono
parents:
diff changeset
3165
kono
parents:
diff changeset
3166 -- Body required if library package with pragma Elaborate_Body
kono
parents:
diff changeset
3167
kono
parents:
diff changeset
3168 elsif Has_Pragma_Elaborate_Body (Pack_Id) then
kono
parents:
diff changeset
3169 return True;
kono
parents:
diff changeset
3170
kono
parents:
diff changeset
3171 -- Body required if subprogram
kono
parents:
diff changeset
3172
kono
parents:
diff changeset
3173 elsif Is_Subprogram_Or_Generic_Subprogram (Pack_Id) then
kono
parents:
diff changeset
3174 return True;
kono
parents:
diff changeset
3175
kono
parents:
diff changeset
3176 -- Treat a block as requiring a body
kono
parents:
diff changeset
3177
kono
parents:
diff changeset
3178 elsif Ekind (Pack_Id) = E_Block then
kono
parents:
diff changeset
3179 return True;
kono
parents:
diff changeset
3180
kono
parents:
diff changeset
3181 elsif Ekind (Pack_Id) = E_Package
kono
parents:
diff changeset
3182 and then Nkind (Parent (Pack_Id)) = N_Package_Specification
kono
parents:
diff changeset
3183 and then Present (Generic_Parent (Parent (Pack_Id)))
kono
parents:
diff changeset
3184 then
kono
parents:
diff changeset
3185 declare
kono
parents:
diff changeset
3186 G_P : constant Entity_Id := Generic_Parent (Parent (Pack_Id));
kono
parents:
diff changeset
3187 begin
kono
parents:
diff changeset
3188 if Has_Pragma_Elaborate_Body (G_P) then
kono
parents:
diff changeset
3189 return True;
kono
parents:
diff changeset
3190 end if;
kono
parents:
diff changeset
3191 end;
kono
parents:
diff changeset
3192 end if;
kono
parents:
diff changeset
3193
kono
parents:
diff changeset
3194 -- Traverse the entity chain of the package and look for constructs that
kono
parents:
diff changeset
3195 -- require a completion in a body.
kono
parents:
diff changeset
3196
kono
parents:
diff changeset
3197 E := First_Entity (Pack_Id);
kono
parents:
diff changeset
3198 while Present (E) loop
kono
parents:
diff changeset
3199
kono
parents:
diff changeset
3200 -- Skip abstract states because their completion depends on several
kono
parents:
diff changeset
3201 -- criteria (see below).
kono
parents:
diff changeset
3202
kono
parents:
diff changeset
3203 if Ekind (E) = E_Abstract_State then
kono
parents:
diff changeset
3204 null;
kono
parents:
diff changeset
3205
kono
parents:
diff changeset
3206 elsif Requires_Completion_In_Body
kono
parents:
diff changeset
3207 (E, Pack_Id, Do_Abstract_States)
kono
parents:
diff changeset
3208 then
kono
parents:
diff changeset
3209 Requires_Body := True;
kono
parents:
diff changeset
3210 exit;
kono
parents:
diff changeset
3211 end if;
kono
parents:
diff changeset
3212
kono
parents:
diff changeset
3213 Next_Entity (E);
kono
parents:
diff changeset
3214 end loop;
kono
parents:
diff changeset
3215
kono
parents:
diff changeset
3216 -- A [generic] package that defines at least one non-null abstract state
kono
parents:
diff changeset
3217 -- requires a completion only when at least one other construct requires
kono
parents:
diff changeset
3218 -- a completion in a body (SPARK RM 7.1.4(4) and (6)). This check is not
kono
parents:
diff changeset
3219 -- performed if the caller requests this behavior.
kono
parents:
diff changeset
3220
kono
parents:
diff changeset
3221 if Do_Abstract_States
kono
parents:
diff changeset
3222 and then Ekind_In (Pack_Id, E_Generic_Package, E_Package)
kono
parents:
diff changeset
3223 and then Has_Non_Null_Abstract_State (Pack_Id)
kono
parents:
diff changeset
3224 and then Requires_Body
kono
parents:
diff changeset
3225 then
kono
parents:
diff changeset
3226 return True;
kono
parents:
diff changeset
3227 end if;
kono
parents:
diff changeset
3228
kono
parents:
diff changeset
3229 return Requires_Body;
kono
parents:
diff changeset
3230 end Unit_Requires_Body;
kono
parents:
diff changeset
3231
kono
parents:
diff changeset
3232 -----------------------------
kono
parents:
diff changeset
3233 -- Unit_Requires_Body_Info --
kono
parents:
diff changeset
3234 -----------------------------
kono
parents:
diff changeset
3235
kono
parents:
diff changeset
3236 procedure Unit_Requires_Body_Info (Pack_Id : Entity_Id) is
kono
parents:
diff changeset
3237 E : Entity_Id;
kono
parents:
diff changeset
3238
kono
parents:
diff changeset
3239 begin
kono
parents:
diff changeset
3240 -- An imported entity never requires body. Right now, only subprograms
kono
parents:
diff changeset
3241 -- can be imported, but perhaps in the future we will allow import of
kono
parents:
diff changeset
3242 -- packages.
kono
parents:
diff changeset
3243
kono
parents:
diff changeset
3244 if Is_Imported (Pack_Id) then
kono
parents:
diff changeset
3245 return;
kono
parents:
diff changeset
3246
kono
parents:
diff changeset
3247 -- Body required if library package with pragma Elaborate_Body
kono
parents:
diff changeset
3248
kono
parents:
diff changeset
3249 elsif Has_Pragma_Elaborate_Body (Pack_Id) then
kono
parents:
diff changeset
3250 Error_Msg_N ("info: & requires body (Elaborate_Body)?Y?", Pack_Id);
kono
parents:
diff changeset
3251
kono
parents:
diff changeset
3252 -- Body required if subprogram
kono
parents:
diff changeset
3253
kono
parents:
diff changeset
3254 elsif Is_Subprogram_Or_Generic_Subprogram (Pack_Id) then
kono
parents:
diff changeset
3255 Error_Msg_N ("info: & requires body (subprogram case)?Y?", Pack_Id);
kono
parents:
diff changeset
3256
kono
parents:
diff changeset
3257 -- Body required if generic parent has Elaborate_Body
kono
parents:
diff changeset
3258
kono
parents:
diff changeset
3259 elsif Ekind (Pack_Id) = E_Package
kono
parents:
diff changeset
3260 and then Nkind (Parent (Pack_Id)) = N_Package_Specification
kono
parents:
diff changeset
3261 and then Present (Generic_Parent (Parent (Pack_Id)))
kono
parents:
diff changeset
3262 then
kono
parents:
diff changeset
3263 declare
kono
parents:
diff changeset
3264 G_P : constant Entity_Id := Generic_Parent (Parent (Pack_Id));
kono
parents:
diff changeset
3265 begin
kono
parents:
diff changeset
3266 if Has_Pragma_Elaborate_Body (G_P) then
kono
parents:
diff changeset
3267 Error_Msg_N
kono
parents:
diff changeset
3268 ("info: & requires body (generic parent Elaborate_Body)?Y?",
kono
parents:
diff changeset
3269 Pack_Id);
kono
parents:
diff changeset
3270 end if;
kono
parents:
diff changeset
3271 end;
kono
parents:
diff changeset
3272
kono
parents:
diff changeset
3273 -- A [generic] package that introduces at least one non-null abstract
kono
parents:
diff changeset
3274 -- state requires completion. However, there is a separate rule that
kono
parents:
diff changeset
3275 -- requires that such a package have a reason other than this for a
kono
parents:
diff changeset
3276 -- body being required (if necessary a pragma Elaborate_Body must be
kono
parents:
diff changeset
3277 -- provided). If Ignore_Abstract_State is True, we don't do this check
kono
parents:
diff changeset
3278 -- (so we can use Unit_Requires_Body to check for some other reason).
kono
parents:
diff changeset
3279
kono
parents:
diff changeset
3280 elsif Ekind_In (Pack_Id, E_Generic_Package, E_Package)
kono
parents:
diff changeset
3281 and then Present (Abstract_States (Pack_Id))
kono
parents:
diff changeset
3282 and then not Is_Null_State
kono
parents:
diff changeset
3283 (Node (First_Elmt (Abstract_States (Pack_Id))))
kono
parents:
diff changeset
3284 then
kono
parents:
diff changeset
3285 Error_Msg_N
kono
parents:
diff changeset
3286 ("info: & requires body (non-null abstract state aspect)?Y?",
kono
parents:
diff changeset
3287 Pack_Id);
kono
parents:
diff changeset
3288 end if;
kono
parents:
diff changeset
3289
kono
parents:
diff changeset
3290 -- Otherwise search entity chain for entity requiring completion
kono
parents:
diff changeset
3291
kono
parents:
diff changeset
3292 E := First_Entity (Pack_Id);
kono
parents:
diff changeset
3293 while Present (E) loop
kono
parents:
diff changeset
3294 if Requires_Completion_In_Body (E, Pack_Id) then
kono
parents:
diff changeset
3295 Error_Msg_Node_2 := E;
kono
parents:
diff changeset
3296 Error_Msg_NE
kono
parents:
diff changeset
3297 ("info: & requires body (& requires completion)?Y?", E, Pack_Id);
kono
parents:
diff changeset
3298 end if;
kono
parents:
diff changeset
3299
kono
parents:
diff changeset
3300 Next_Entity (E);
kono
parents:
diff changeset
3301 end loop;
kono
parents:
diff changeset
3302 end Unit_Requires_Body_Info;
kono
parents:
diff changeset
3303
kono
parents:
diff changeset
3304 end Sem_Ch7;