]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/sem_elab.adb
2015-05-12 Pierre-Marie de Rodat <derodat@adacore.com>
[thirdparty/gcc.git] / gcc / ada / sem_elab.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ E L A B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1997-2015, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 with Atree; use Atree;
27 with Checks; use Checks;
28 with Debug; use Debug;
29 with Einfo; use Einfo;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Tss; use Exp_Tss;
33 with Exp_Util; use Exp_Util;
34 with Expander; use Expander;
35 with Fname; use Fname;
36 with Lib; use Lib;
37 with Lib.Load; use Lib.Load;
38 with Namet; use Namet;
39 with Nlists; use Nlists;
40 with Nmake; use Nmake;
41 with Opt; use Opt;
42 with Output; use Output;
43 with Restrict; use Restrict;
44 with Rident; use Rident;
45 with Sem; use Sem;
46 with Sem_Aux; use Sem_Aux;
47 with Sem_Cat; use Sem_Cat;
48 with Sem_Ch7; use Sem_Ch7;
49 with Sem_Ch8; use Sem_Ch8;
50 with Sem_Util; use Sem_Util;
51 with Sinfo; use Sinfo;
52 with Sinput; use Sinput;
53 with Snames; use Snames;
54 with Stand; use Stand;
55 with Table;
56 with Tbuild; use Tbuild;
57 with Uintp; use Uintp;
58 with Uname; use Uname;
59
60 package body Sem_Elab is
61
62 -- The following table records the recursive call chain for output in the
63 -- Output routine. Each entry records the call node and the entity of the
64 -- called routine. The number of entries in the table (i.e. the value of
65 -- Elab_Call.Last) indicates the current depth of recursion and is used to
66 -- identify the outer level.
67
68 type Elab_Call_Entry is record
69 Cloc : Source_Ptr;
70 Ent : Entity_Id;
71 end record;
72
73 package Elab_Call is new Table.Table (
74 Table_Component_Type => Elab_Call_Entry,
75 Table_Index_Type => Int,
76 Table_Low_Bound => 1,
77 Table_Initial => 50,
78 Table_Increment => 100,
79 Table_Name => "Elab_Call");
80
81 -- This table is initialized at the start of each outer level call. It
82 -- holds the entities for all subprograms that have been examined for this
83 -- particular outer level call, and is used to prevent both infinite
84 -- recursion, and useless reanalysis of bodies already seen
85
86 package Elab_Visited is new Table.Table (
87 Table_Component_Type => Entity_Id,
88 Table_Index_Type => Int,
89 Table_Low_Bound => 1,
90 Table_Initial => 200,
91 Table_Increment => 100,
92 Table_Name => "Elab_Visited");
93
94 -- This table stores calls to Check_Internal_Call that are delayed
95 -- until all generics are instantiated, and in particular that all
96 -- generic bodies have been inserted. We need to delay, because we
97 -- need to be able to look through the inserted bodies.
98
99 type Delay_Element is record
100 N : Node_Id;
101 -- The parameter N from the call to Check_Internal_Call. Note that
102 -- this node may get rewritten over the delay period by expansion
103 -- in the call case (but not in the instantiation case).
104
105 E : Entity_Id;
106 -- The parameter E from the call to Check_Internal_Call
107
108 Orig_Ent : Entity_Id;
109 -- The parameter Orig_Ent from the call to Check_Internal_Call
110
111 Curscop : Entity_Id;
112 -- The current scope of the call. This is restored when we complete
113 -- the delayed call, so that we do this in the right scope.
114
115 From_Elab_Code : Boolean;
116 -- Save indication of whether this call is from elaboration code
117
118 Outer_Scope : Entity_Id;
119 -- Save scope of outer level call
120 end record;
121
122 package Delay_Check is new Table.Table (
123 Table_Component_Type => Delay_Element,
124 Table_Index_Type => Int,
125 Table_Low_Bound => 1,
126 Table_Initial => 1000,
127 Table_Increment => 100,
128 Table_Name => "Delay_Check");
129
130 C_Scope : Entity_Id;
131 -- Top level scope of current scope. Compute this only once at the outer
132 -- level, i.e. for a call to Check_Elab_Call from outside this unit.
133
134 Outer_Level_Sloc : Source_Ptr;
135 -- Save Sloc value for outer level call node for comparisons of source
136 -- locations. A body is too late if it appears after the *outer* level
137 -- call, not the particular call that is being analyzed.
138
139 From_Elab_Code : Boolean;
140 -- This flag shows whether the outer level call currently being examined
141 -- is or is not in elaboration code. We are only interested in calls to
142 -- routines in other units if this flag is True.
143
144 In_Task_Activation : Boolean := False;
145 -- This flag indicates whether we are performing elaboration checks on
146 -- task procedures, at the point of activation. If true, we do not trace
147 -- internal calls in these procedures, because all local bodies are known
148 -- to be elaborated.
149
150 Delaying_Elab_Checks : Boolean := True;
151 -- This is set True till the compilation is complete, including the
152 -- insertion of all instance bodies. Then when Check_Elab_Calls is called,
153 -- the delay table is used to make the delayed calls and this flag is reset
154 -- to False, so that the calls are processed.
155
156 -----------------------
157 -- Local Subprograms --
158 -----------------------
159
160 -- Note: Outer_Scope in all following specs represents the scope of
161 -- interest of the outer level call. If it is set to Standard_Standard,
162 -- then it means the outer level call was at elaboration level, and that
163 -- thus all calls are of interest. If it was set to some other scope,
164 -- then the original call was an inner call, and we are not interested
165 -- in calls that go outside this scope.
166
167 procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id);
168 -- Analysis of construct N shows that we should set Elaborate_All_Desirable
169 -- for the WITH clause for unit U (which will always be present). A special
170 -- case is when N is a function or procedure instantiation, in which case
171 -- it is sufficient to set Elaborate_Desirable, since in this case there is
172 -- no possibility of transitive elaboration issues.
173
174 procedure Check_A_Call
175 (N : Node_Id;
176 E : Entity_Id;
177 Outer_Scope : Entity_Id;
178 Inter_Unit_Only : Boolean;
179 Generate_Warnings : Boolean := True;
180 In_Init_Proc : Boolean := False);
181 -- This is the internal recursive routine that is called to check for
182 -- possible elaboration error. The argument N is a subprogram call or
183 -- generic instantiation, or 'Access attribute reference to be checked, and
184 -- E is the entity of the called subprogram, or instantiated generic unit,
185 -- or subprogram referenced by 'Access.
186 --
187 -- In SPARK mode, N can also be a variable reference, since in SPARK this
188 -- also triggers a requirement for Elaborate_All, and in this case E is the
189 -- entity being referenced.
190 --
191 -- Outer_Scope is the outer level scope for the original reference.
192 -- Inter_Unit_Only is set if the call is only to be checked in the
193 -- case where it is to another unit (and skipped if within a unit).
194 -- Generate_Warnings is set to False to suppress warning messages about
195 -- missing pragma Elaborate_All's. These messages are not wanted for
196 -- inner calls in the dynamic model. Note that an instance of the Access
197 -- attribute applied to a subprogram also generates a call to this
198 -- procedure (since the referenced subprogram may be called later
199 -- indirectly). Flag In_Init_Proc should be set whenever the current
200 -- context is a type init proc.
201 --
202 -- Note: this might better be called Check_A_Reference to recognize the
203 -- variable case for SPARK, but we prefer to retain the historical name
204 -- since in practice this is mostly about checking calls for the possible
205 -- occurrence of an access-before-elaboration exception.
206
207 procedure Check_Bad_Instantiation (N : Node_Id);
208 -- N is a node for an instantiation (if called with any other node kind,
209 -- Check_Bad_Instantiation ignores the call). This subprogram checks for
210 -- the special case of a generic instantiation of a generic spec in the
211 -- same declarative part as the instantiation where a body is present and
212 -- has not yet been seen. This is an obvious error, but needs to be checked
213 -- specially at the time of the instantiation, since it is a case where we
214 -- cannot insert the body anywhere. If this case is detected, warnings are
215 -- generated, and a raise of Program_Error is inserted. In addition any
216 -- subprograms in the generic spec are stubbed, and the Bad_Instantiation
217 -- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
218 -- flag as an indication that no attempt should be made to insert an
219 -- instance body.
220
221 procedure Check_Internal_Call
222 (N : Node_Id;
223 E : Entity_Id;
224 Outer_Scope : Entity_Id;
225 Orig_Ent : Entity_Id);
226 -- N is a function call or procedure statement call node and E is the
227 -- entity of the called function, which is within the current compilation
228 -- unit (where subunits count as part of the parent). This call checks if
229 -- this call, or any call within any accessed body could cause an ABE, and
230 -- if so, outputs a warning. Orig_Ent differs from E only in the case of
231 -- renamings, and points to the original name of the entity. This is used
232 -- for error messages. Outer_Scope is the outer level scope for the
233 -- original call.
234
235 procedure Check_Internal_Call_Continue
236 (N : Node_Id;
237 E : Entity_Id;
238 Outer_Scope : Entity_Id;
239 Orig_Ent : Entity_Id);
240 -- The processing for Check_Internal_Call is divided up into two phases,
241 -- and this represents the second phase. The second phase is delayed if
242 -- Delaying_Elab_Calls is set to True. In this delayed case, the first
243 -- phase makes an entry in the Delay_Check table, which is processed when
244 -- Check_Elab_Calls is called. N, E and Orig_Ent are as for the call to
245 -- Check_Internal_Call. Outer_Scope is the outer level scope for the
246 -- original call.
247
248 function Has_Generic_Body (N : Node_Id) return Boolean;
249 -- N is a generic package instantiation node, and this routine determines
250 -- if this package spec does in fact have a generic body. If so, then
251 -- True is returned, otherwise False. Note that this is not at all the
252 -- same as checking if the unit requires a body, since it deals with
253 -- the case of optional bodies accurately (i.e. if a body is optional,
254 -- then it looks to see if a body is actually present). Note: this
255 -- function can only do a fully correct job if in generating code mode
256 -- where all bodies have to be present. If we are operating in semantics
257 -- check only mode, then in some cases of optional bodies, a result of
258 -- False may incorrectly be given. In practice this simply means that
259 -- some cases of warnings for incorrect order of elaboration will only
260 -- be given when generating code, which is not a big problem (and is
261 -- inevitable, given the optional body semantics of Ada).
262
263 procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty);
264 -- Given code for an elaboration check (or unconditional raise if the check
265 -- is not needed), inserts the code in the appropriate place. N is the call
266 -- or instantiation node for which the check code is required. C is the
267 -- test whose failure triggers the raise.
268
269 function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean;
270 -- Returns True if node N is a call to a generic formal subprogram
271
272 function Is_Finalization_Procedure (Id : Entity_Id) return Boolean;
273 -- Determine whether entity Id denotes a [Deep_]Finalize procedure
274
275 procedure Output_Calls
276 (N : Node_Id;
277 Check_Elab_Flag : Boolean);
278 -- Outputs chain of calls stored in the Elab_Call table. The caller has
279 -- already generated the main warning message, so the warnings generated
280 -- are all continuation messages. The argument is the call node at which
281 -- the messages are to be placed. When Check_Elab_Flag is set, calls are
282 -- enumerated only when flag Elab_Warning is set for the dynamic case or
283 -- when flag Elab_Info_Messages is set for the static case.
284
285 function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean;
286 -- Given two scopes, determine whether they are the same scope from an
287 -- elaboration point of view, i.e. packages and blocks are ignored.
288
289 procedure Set_C_Scope;
290 -- On entry C_Scope is set to some scope. On return, C_Scope is reset
291 -- to be the enclosing compilation unit of this scope.
292
293 function Get_Referenced_Ent (N : Node_Id) return Entity_Id;
294 -- N is either a function or procedure call or an access attribute that
295 -- references a subprogram. This call retrieves the relevant entity. If
296 -- this is a call to a protected subprogram, the entity is a selected
297 -- component. The callable entity may be absent, in which case Empty is
298 -- returned. This happens with non-analyzed calls in nested generics.
299 --
300 -- If SPARK_Mode is On, then N can also be a reference to an E_Variable
301 -- entity, in which case, the value returned is simply this entity.
302
303 procedure Set_Elaboration_Constraint
304 (Call : Node_Id;
305 Subp : Entity_Id;
306 Scop : Entity_Id);
307 -- The current unit U may depend semantically on some unit P which is not
308 -- in the current context. If there is an elaboration call that reaches P,
309 -- we need to indicate that P requires an Elaborate_All, but this is not
310 -- effective in U's ali file, if there is no with_clause for P. In this
311 -- case we add the Elaborate_All on the unit Q that directly or indirectly
312 -- makes P available. This can happen in two cases:
313 --
314 -- a) Q declares a subtype of a type declared in P, and the call is an
315 -- initialization call for an object of that subtype.
316 --
317 -- b) Q declares an object of some tagged type whose root type is
318 -- declared in P, and the initialization call uses object notation on
319 -- that object to reach a primitive operation or a classwide operation
320 -- declared in P.
321 --
322 -- If P appears in the context of U, the current processing is correct.
323 -- Otherwise we must identify these two cases to retrieve Q and place the
324 -- Elaborate_All_Desirable on it.
325
326 function Spec_Entity (E : Entity_Id) return Entity_Id;
327 -- Given a compilation unit entity, if it is a spec entity, it is returned
328 -- unchanged. If it is a body entity, then the spec for the corresponding
329 -- spec is returned
330
331 procedure Supply_Bodies (N : Node_Id);
332 -- Given a node, N, that is either a subprogram declaration or a package
333 -- declaration, this procedure supplies dummy bodies for the subprogram
334 -- or for all subprograms in the package. If the given node is not one of
335 -- these two possibilities, then Supply_Bodies does nothing. The dummy body
336 -- contains a single Raise statement.
337
338 procedure Supply_Bodies (L : List_Id);
339 -- Calls Supply_Bodies for all elements of the given list L
340
341 function Within (E1, E2 : Entity_Id) return Boolean;
342 -- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one
343 -- of its contained scopes, False otherwise.
344
345 function Within_Elaborate_All
346 (Unit : Unit_Number_Type;
347 E : Entity_Id) return Boolean;
348 -- Return True if we are within the scope of an Elaborate_All for E, or if
349 -- we are within the scope of an Elaborate_All for some other unit U, and U
350 -- with's E. This prevents spurious warnings when the called entity is
351 -- renamed within U, or in case of generic instances.
352
353 --------------------------------------
354 -- Activate_Elaborate_All_Desirable --
355 --------------------------------------
356
357 procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id) is
358 UN : constant Unit_Number_Type := Get_Code_Unit (N);
359 CU : constant Node_Id := Cunit (UN);
360 UE : constant Entity_Id := Cunit_Entity (UN);
361 Unm : constant Unit_Name_Type := Unit_Name (UN);
362 CI : constant List_Id := Context_Items (CU);
363 Itm : Node_Id;
364 Ent : Entity_Id;
365
366 procedure Add_To_Context_And_Mark (Itm : Node_Id);
367 -- This procedure is called when the elaborate indication must be
368 -- applied to a unit not in the context of the referencing unit. The
369 -- unit gets added to the context as an implicit with.
370
371 function In_Withs_Of (UEs : Entity_Id) return Boolean;
372 -- UEs is the spec entity of a unit. If the unit to be marked is
373 -- in the context item list of this unit spec, then the call returns
374 -- True and Itm is left set to point to the relevant N_With_Clause node.
375
376 procedure Set_Elab_Flag (Itm : Node_Id);
377 -- Sets Elaborate_[All_]Desirable as appropriate on Itm
378
379 -----------------------------
380 -- Add_To_Context_And_Mark --
381 -----------------------------
382
383 procedure Add_To_Context_And_Mark (Itm : Node_Id) is
384 CW : constant Node_Id :=
385 Make_With_Clause (Sloc (Itm),
386 Name => Name (Itm));
387
388 begin
389 Set_Library_Unit (CW, Library_Unit (Itm));
390 Set_Implicit_With (CW, True);
391
392 -- Set elaborate all desirable on copy and then append the copy to
393 -- the list of body with's and we are done.
394
395 Set_Elab_Flag (CW);
396 Append_To (CI, CW);
397 end Add_To_Context_And_Mark;
398
399 -----------------
400 -- In_Withs_Of --
401 -----------------
402
403 function In_Withs_Of (UEs : Entity_Id) return Boolean is
404 UNs : constant Unit_Number_Type := Get_Source_Unit (UEs);
405 CUs : constant Node_Id := Cunit (UNs);
406 CIs : constant List_Id := Context_Items (CUs);
407
408 begin
409 Itm := First (CIs);
410 while Present (Itm) loop
411 if Nkind (Itm) = N_With_Clause then
412 Ent :=
413 Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
414
415 if U = Ent then
416 return True;
417 end if;
418 end if;
419
420 Next (Itm);
421 end loop;
422
423 return False;
424 end In_Withs_Of;
425
426 -------------------
427 -- Set_Elab_Flag --
428 -------------------
429
430 procedure Set_Elab_Flag (Itm : Node_Id) is
431 begin
432 if Nkind (N) in N_Subprogram_Instantiation then
433 Set_Elaborate_Desirable (Itm);
434 else
435 Set_Elaborate_All_Desirable (Itm);
436 end if;
437 end Set_Elab_Flag;
438
439 -- Start of processing for Activate_Elaborate_All_Desirable
440
441 begin
442 -- Do not set binder indication if expansion is disabled, as when
443 -- compiling a generic unit.
444
445 if not Expander_Active then
446 return;
447 end if;
448
449 Itm := First (CI);
450 while Present (Itm) loop
451 if Nkind (Itm) = N_With_Clause then
452 Ent := Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
453
454 -- If we find it, then mark elaborate all desirable and return
455
456 if U = Ent then
457 Set_Elab_Flag (Itm);
458 return;
459 end if;
460 end if;
461
462 Next (Itm);
463 end loop;
464
465 -- If we fall through then the with clause is not present in the
466 -- current unit. One legitimate possibility is that the with clause
467 -- is present in the spec when we are a body.
468
469 if Is_Body_Name (Unm)
470 and then In_Withs_Of (Spec_Entity (UE))
471 then
472 Add_To_Context_And_Mark (Itm);
473 return;
474 end if;
475
476 -- Similarly, we may be in the spec or body of a child unit, where
477 -- the unit in question is with'ed by some ancestor of the child unit.
478
479 if Is_Child_Name (Unm) then
480 declare
481 Pkg : Entity_Id;
482
483 begin
484 Pkg := UE;
485 loop
486 Pkg := Scope (Pkg);
487 exit when Pkg = Standard_Standard;
488
489 if In_Withs_Of (Pkg) then
490 Add_To_Context_And_Mark (Itm);
491 return;
492 end if;
493 end loop;
494 end;
495 end if;
496
497 -- Here if we do not find with clause on spec or body. We just ignore
498 -- this case, it means that the elaboration involves some other unit
499 -- than the unit being compiled, and will be caught elsewhere.
500
501 null;
502 end Activate_Elaborate_All_Desirable;
503
504 ------------------
505 -- Check_A_Call --
506 ------------------
507
508 procedure Check_A_Call
509 (N : Node_Id;
510 E : Entity_Id;
511 Outer_Scope : Entity_Id;
512 Inter_Unit_Only : Boolean;
513 Generate_Warnings : Boolean := True;
514 In_Init_Proc : Boolean := False)
515 is
516 Access_Case : constant Boolean := Nkind (N) = N_Attribute_Reference;
517 -- Indicates if we have Access attribute case
518
519 Variable_Case : constant Boolean :=
520 Nkind (N) in N_Has_Entity
521 and then Present (Entity (N))
522 and then Ekind (Entity (N)) = E_Variable;
523 -- Indicates if we have variable reference case
524
525 procedure Elab_Warning
526 (Msg_D : String;
527 Msg_S : String;
528 Ent : Node_Or_Entity_Id);
529 -- Generate a call to Error_Msg_NE with parameters Msg_D or Msg_S (for
530 -- dynamic or static elaboration model), N and Ent. Msg_D is a real
531 -- warning (output if Msg_D is non-null and Elab_Warnings is set),
532 -- Msg_S is an info message (output if Elab_Info_Messages is set.
533
534 ------------------
535 -- Elab_Warning --
536 ------------------
537
538 procedure Elab_Warning
539 (Msg_D : String;
540 Msg_S : String;
541 Ent : Node_Or_Entity_Id)
542 is
543 begin
544 -- Dynamic elaboration checks, real warning
545
546 if Dynamic_Elaboration_Checks then
547 if not Access_Case then
548 if Msg_D /= "" and then Elab_Warnings then
549 Error_Msg_NE (Msg_D, N, Ent);
550 end if;
551 end if;
552
553 -- Static elaboration checks, info message
554
555 else
556 if Elab_Info_Messages then
557 Error_Msg_NE (Msg_S, N, Ent);
558 end if;
559 end if;
560 end Elab_Warning;
561
562 -- Local variables
563
564 Loc : constant Source_Ptr := Sloc (N);
565 Ent : Entity_Id;
566 Decl : Node_Id;
567
568 E_Scope : Entity_Id;
569 -- Top level scope of entity for called subprogram. This value includes
570 -- following renamings and derivations, so this scope can be in a
571 -- non-visible unit. This is the scope that is to be investigated to
572 -- see whether an elaboration check is required.
573
574 W_Scope : Entity_Id;
575 -- Top level scope of directly called entity for subprogram. This
576 -- differs from E_Scope in the case where renamings or derivations
577 -- are involved, since it does not follow these links. W_Scope is
578 -- generally in a visible unit, and it is this scope that may require
579 -- an Elaborate_All. However, there are some cases (initialization
580 -- calls and calls involving object notation) where W_Scope might not
581 -- be in the context of the current unit, and there is an intermediate
582 -- package that is, in which case the Elaborate_All has to be placed
583 -- on this intermediate package. These special cases are handled in
584 -- Set_Elaboration_Constraint.
585
586 Body_Acts_As_Spec : Boolean;
587 -- Set to true if call is to body acting as spec (no separate spec)
588
589 Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
590 -- Indicates if we have instantiation case
591
592 Caller_Unit_Internal : Boolean;
593 Callee_Unit_Internal : Boolean;
594
595 Inst_Caller : Source_Ptr;
596 Inst_Callee : Source_Ptr;
597
598 Unit_Caller : Unit_Number_Type;
599 Unit_Callee : Unit_Number_Type;
600
601 Cunit_SC : Boolean := False;
602 -- Set to suppress dynamic elaboration checks where one of the
603 -- enclosing scopes has Elaboration_Checks_Suppressed set, or else
604 -- if a pragma Elaborate[_All] applies to that scope, in which case
605 -- warnings on the scope are also suppressed. For the internal case,
606 -- we ignore this flag.
607
608 -- Start of processing for Check_A_Call
609
610 begin
611 -- If the call is known to be within a local Suppress Elaboration
612 -- pragma, nothing to check. This can happen in task bodies. But
613 -- we ignore this for a call to a generic formal.
614
615 if Nkind (N) in N_Subprogram_Call
616 and then No_Elaboration_Check (N)
617 and then not Is_Call_Of_Generic_Formal (N)
618 then
619 return;
620 end if;
621
622 -- If this is a rewrite of a Valid_Scalars attribute, then nothing to
623 -- check, we don't mind in this case if the call occurs before the body
624 -- since this is all generated code.
625
626 if Nkind (Original_Node (N)) = N_Attribute_Reference
627 and then Attribute_Name (Original_Node (N)) = Name_Valid_Scalars
628 then
629 return;
630 end if;
631
632 -- Proceed with check
633
634 Ent := E;
635
636 -- For a variable reference, just set Body_Acts_As_Spec to False
637
638 if Variable_Case then
639 Body_Acts_As_Spec := False;
640
641 -- Additional checks for all other cases
642
643 else
644 -- Go to parent for derived subprogram, or to original subprogram in
645 -- the case of a renaming (Alias covers both these cases).
646
647 loop
648 if (Suppress_Elaboration_Warnings (Ent)
649 or else Elaboration_Checks_Suppressed (Ent))
650 and then (Inst_Case or else No (Alias (Ent)))
651 then
652 return;
653 end if;
654
655 -- Nothing to do for imported entities
656
657 if Is_Imported (Ent) then
658 return;
659 end if;
660
661 exit when Inst_Case or else No (Alias (Ent));
662 Ent := Alias (Ent);
663 end loop;
664
665 Decl := Unit_Declaration_Node (Ent);
666
667 if Nkind (Decl) = N_Subprogram_Body then
668 Body_Acts_As_Spec := True;
669
670 elsif Nkind_In (Decl, N_Subprogram_Declaration,
671 N_Subprogram_Body_Stub)
672 or else Inst_Case
673 then
674 Body_Acts_As_Spec := False;
675
676 -- If we have none of an instantiation, subprogram body or subprogram
677 -- declaration, or in the SPARK case, a variable reference, then
678 -- it is not a case that we want to check. (One case is a call to a
679 -- generic formal subprogram, where we do not want the check in the
680 -- template).
681
682 else
683 return;
684 end if;
685 end if;
686
687 E_Scope := Ent;
688 loop
689 if Elaboration_Checks_Suppressed (E_Scope)
690 or else Suppress_Elaboration_Warnings (E_Scope)
691 then
692 Cunit_SC := True;
693 end if;
694
695 -- Exit when we get to compilation unit, not counting subunits
696
697 exit when Is_Compilation_Unit (E_Scope)
698 and then (Is_Child_Unit (E_Scope)
699 or else Scope (E_Scope) = Standard_Standard);
700
701 -- If we did not find a compilation unit, other than standard,
702 -- then nothing to check (happens in some instantiation cases)
703
704 if E_Scope = Standard_Standard then
705 return;
706
707 -- Otherwise move up a scope looking for compilation unit
708
709 else
710 E_Scope := Scope (E_Scope);
711 end if;
712 end loop;
713
714 -- No checks needed for pure or preelaborated compilation units
715
716 if Is_Pure (E_Scope) or else Is_Preelaborated (E_Scope) then
717 return;
718 end if;
719
720 -- If the generic entity is within a deeper instance than we are, then
721 -- either the instantiation to which we refer itself caused an ABE, in
722 -- which case that will be handled separately, or else we know that the
723 -- body we need appears as needed at the point of the instantiation.
724 -- However, this assumption is only valid if we are in static mode.
725
726 if not Dynamic_Elaboration_Checks
727 and then
728 Instantiation_Depth (Sloc (Ent)) > Instantiation_Depth (Sloc (N))
729 then
730 return;
731 end if;
732
733 -- Do not give a warning for a package with no body
734
735 if Ekind (Ent) = E_Generic_Package and then not Has_Generic_Body (N) then
736 return;
737 end if;
738
739 -- Case of entity is not in current unit (i.e. with'ed unit case)
740
741 if E_Scope /= C_Scope then
742
743 -- We are only interested in such calls if the outer call was from
744 -- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
745
746 if not From_Elab_Code and then not Dynamic_Elaboration_Checks then
747 return;
748 end if;
749
750 -- Nothing to do if some scope said that no checks were required
751
752 if Cunit_SC then
753 return;
754 end if;
755
756 -- Nothing to do for a generic instance, because in this case the
757 -- checking was at the point of instantiation of the generic However,
758 -- this shortcut is only applicable in static mode.
759
760 if Is_Generic_Instance (Ent) and not Dynamic_Elaboration_Checks then
761 return;
762 end if;
763
764 -- Nothing to do if subprogram with no separate spec. However, a
765 -- call to Deep_Initialize may result in a call to a user-defined
766 -- Initialize procedure, which imposes a body dependency. This
767 -- happens only if the type is controlled and the Initialize
768 -- procedure is not inherited.
769
770 if Body_Acts_As_Spec then
771 if Is_TSS (Ent, TSS_Deep_Initialize) then
772 declare
773 Typ : constant Entity_Id := Etype (First_Formal (Ent));
774 Init : Entity_Id;
775
776 begin
777 if not Is_Controlled (Typ) then
778 return;
779 else
780 Init := Find_Prim_Op (Typ, Name_Initialize);
781
782 if Comes_From_Source (Init) then
783 Ent := Init;
784 else
785 return;
786 end if;
787 end if;
788 end;
789
790 else
791 return;
792 end if;
793 end if;
794
795 -- Check cases of internal units
796
797 Callee_Unit_Internal :=
798 Is_Internal_File_Name
799 (Unit_File_Name (Get_Source_Unit (E_Scope)));
800
801 -- Do not give a warning if the with'ed unit is internal and this is
802 -- the generic instantiation case (this saves a lot of hassle dealing
803 -- with the Text_IO special child units)
804
805 if Callee_Unit_Internal and Inst_Case then
806 return;
807 end if;
808
809 if C_Scope = Standard_Standard then
810 Caller_Unit_Internal := False;
811 else
812 Caller_Unit_Internal :=
813 Is_Internal_File_Name
814 (Unit_File_Name (Get_Source_Unit (C_Scope)));
815 end if;
816
817 -- Do not give a warning if the with'ed unit is internal and the
818 -- caller is not internal (since the binder always elaborates
819 -- internal units first).
820
821 if Callee_Unit_Internal and (not Caller_Unit_Internal) then
822 return;
823 end if;
824
825 -- For now, if debug flag -gnatdE is not set, do no checking for
826 -- one internal unit withing another. This fixes the problem with
827 -- the sgi build and storage errors. To be resolved later ???
828
829 if (Callee_Unit_Internal and Caller_Unit_Internal)
830 and then not Debug_Flag_EE
831 then
832 return;
833 end if;
834
835 if Is_TSS (E, TSS_Deep_Initialize) then
836 Ent := E;
837 end if;
838
839 -- If the call is in an instance, and the called entity is not
840 -- defined in the same instance, then the elaboration issue focuses
841 -- around the unit containing the template, it is this unit which
842 -- requires an Elaborate_All.
843
844 -- However, if we are doing dynamic elaboration, we need to chase the
845 -- call in the usual manner.
846
847 -- We also need to chase the call in the usual manner if it is a call
848 -- to a generic formal parameter, since that case was not handled as
849 -- part of the processing of the template.
850
851 Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N)));
852 Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent)));
853
854 if Inst_Caller = No_Location then
855 Unit_Caller := No_Unit;
856 else
857 Unit_Caller := Get_Source_Unit (N);
858 end if;
859
860 if Inst_Callee = No_Location then
861 Unit_Callee := No_Unit;
862 else
863 Unit_Callee := Get_Source_Unit (Ent);
864 end if;
865
866 if Unit_Caller /= No_Unit
867 and then Unit_Callee /= Unit_Caller
868 and then not Dynamic_Elaboration_Checks
869 and then not Is_Call_Of_Generic_Formal (N)
870 then
871 E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller));
872
873 -- If we don't get a spec entity, just ignore call. Not quite
874 -- clear why this check is necessary. ???
875
876 if No (E_Scope) then
877 return;
878 end if;
879
880 -- Otherwise step to enclosing compilation unit
881
882 while not Is_Compilation_Unit (E_Scope) loop
883 E_Scope := Scope (E_Scope);
884 end loop;
885
886 -- For the case where N is not an instance, and is not a call within
887 -- instance to other than a generic formal, we recompute E_Scope
888 -- for the error message, since we do NOT want to go to the unit
889 -- which has the ultimate declaration in the case of renaming and
890 -- derivation and we also want to go to the generic unit in the
891 -- case of an instance, and no further.
892
893 else
894 -- Loop to carefully follow renamings and derivations one step
895 -- outside the current unit, but not further.
896
897 if not (Inst_Case or Variable_Case)
898 and then Present (Alias (Ent))
899 then
900 E_Scope := Alias (Ent);
901 else
902 E_Scope := Ent;
903 end if;
904
905 loop
906 while not Is_Compilation_Unit (E_Scope) loop
907 E_Scope := Scope (E_Scope);
908 end loop;
909
910 -- If E_Scope is the same as C_Scope, it means that there
911 -- definitely was a local renaming or derivation, and we
912 -- are not yet out of the current unit.
913
914 exit when E_Scope /= C_Scope;
915 Ent := Alias (Ent);
916 E_Scope := Ent;
917
918 -- If no alias, there is a previous error
919
920 if No (Ent) then
921 Check_Error_Detected;
922 return;
923 end if;
924 end loop;
925 end if;
926
927 if Within_Elaborate_All (Current_Sem_Unit, E_Scope) then
928 return;
929 end if;
930
931 -- Find top level scope for called entity (not following renamings
932 -- or derivations). This is where the Elaborate_All will go if it
933 -- is needed. We start with the called entity, except in the case
934 -- of an initialization procedure outside the current package, where
935 -- the init proc is in the root package, and we start from the entity
936 -- of the name in the call.
937
938 declare
939 Ent : constant Entity_Id := Get_Referenced_Ent (N);
940 begin
941 if Is_Init_Proc (Ent)
942 and then not In_Same_Extended_Unit (N, Ent)
943 then
944 W_Scope := Scope (Ent);
945 else
946 W_Scope := E;
947 end if;
948 end;
949
950 -- Now loop through scopes to get to the enclosing compilation unit
951
952 while not Is_Compilation_Unit (W_Scope) loop
953 W_Scope := Scope (W_Scope);
954 end loop;
955
956 -- Now check if an elaborate_all (or dynamic check) is needed
957
958 if not Suppress_Elaboration_Warnings (Ent)
959 and then not Elaboration_Checks_Suppressed (Ent)
960 and then not Suppress_Elaboration_Warnings (E_Scope)
961 and then not Elaboration_Checks_Suppressed (E_Scope)
962 and then ((Elab_Warnings or Elab_Info_Messages)
963 or else SPARK_Mode = On)
964 and then Generate_Warnings
965 then
966 -- Instantiation case
967
968 if Inst_Case then
969 if SPARK_Mode = On then
970 Error_Msg_NE
971 ("instantiation of & during elaboration in SPARK",
972 N, Ent);
973
974 else
975 Elab_Warning
976 ("instantiation of & may raise Program_Error?l?",
977 "info: instantiation of & during elaboration?$?", Ent);
978 end if;
979
980 -- Indirect call case, info message only in static elaboration
981 -- case, because the attribute reference itself cannot raise an
982 -- exception. Note that SPARK does not permit indirect calls.
983
984 elsif Access_Case then
985 Elab_Warning
986 ("", "info: access to & during elaboration?$?", Ent);
987
988 -- Variable reference in SPARK mode
989
990 elsif Variable_Case then
991 Error_Msg_NE
992 ("reference to & during elaboration in SPARK", N, Ent);
993
994 -- Subprogram call case
995
996 else
997 if Nkind (Name (N)) in N_Has_Entity
998 and then Is_Init_Proc (Entity (Name (N)))
999 and then Comes_From_Source (Ent)
1000 then
1001 Elab_Warning
1002 ("implicit call to & may raise Program_Error?l?",
1003 "info: implicit call to & during elaboration?$?",
1004 Ent);
1005
1006 elsif SPARK_Mode = On then
1007 Error_Msg_NE
1008 ("call to & during elaboration in SPARK", N, Ent);
1009
1010 else
1011 Elab_Warning
1012 ("call to & may raise Program_Error?l?",
1013 "info: call to & during elaboration?$?",
1014 Ent);
1015 end if;
1016 end if;
1017
1018 Error_Msg_Qual_Level := Nat'Last;
1019
1020 -- Case of Elaborate_All not present and required, for SPARK this
1021 -- is an error, so give an error message.
1022
1023 if SPARK_Mode = On then
1024 Error_Msg_NE
1025 ("\Elaborate_All pragma required for&", N, W_Scope);
1026
1027 -- Otherwise we generate an implicit pragma. For a subprogram
1028 -- instantiation, Elaborate is good enough, since no transitive
1029 -- call is possible at elaboration time in this case.
1030
1031 elsif Nkind (N) in N_Subprogram_Instantiation then
1032 Elab_Warning
1033 ("\missing pragma Elaborate for&?l?",
1034 "\implicit pragma Elaborate for& generated?$?",
1035 W_Scope);
1036
1037 -- For all other cases, we need an implicit Elaborate_All
1038
1039 else
1040 Elab_Warning
1041 ("\missing pragma Elaborate_All for&?l?",
1042 "\implicit pragma Elaborate_All for & generated?$?",
1043 W_Scope);
1044 end if;
1045
1046 Error_Msg_Qual_Level := 0;
1047
1048 -- Take into account the flags related to elaboration warning
1049 -- messages when enumerating the various calls involved. This
1050 -- ensures the proper pairing of the main warning and the
1051 -- clarification messages generated by Output_Calls.
1052
1053 Output_Calls (N, Check_Elab_Flag => True);
1054
1055 -- Set flag to prevent further warnings for same unit unless in
1056 -- All_Errors_Mode.
1057
1058 if not All_Errors_Mode and not Dynamic_Elaboration_Checks then
1059 Set_Suppress_Elaboration_Warnings (W_Scope, True);
1060 end if;
1061 end if;
1062
1063 -- Check for runtime elaboration check required
1064
1065 if Dynamic_Elaboration_Checks then
1066 if not Elaboration_Checks_Suppressed (Ent)
1067 and then not Elaboration_Checks_Suppressed (W_Scope)
1068 and then not Elaboration_Checks_Suppressed (E_Scope)
1069 and then not Cunit_SC
1070 then
1071 -- Runtime elaboration check required. Generate check of the
1072 -- elaboration Boolean for the unit containing the entity.
1073
1074 -- Note that for this case, we do check the real unit (the one
1075 -- from following renamings, since that is the issue).
1076
1077 -- Could this possibly miss a useless but required PE???
1078
1079 Insert_Elab_Check (N,
1080 Make_Attribute_Reference (Loc,
1081 Attribute_Name => Name_Elaborated,
1082 Prefix =>
1083 New_Occurrence_Of (Spec_Entity (E_Scope), Loc)));
1084
1085 -- Prevent duplicate elaboration checks on the same call,
1086 -- which can happen if the body enclosing the call appears
1087 -- itself in a call whose elaboration check is delayed.
1088
1089 if Nkind (N) in N_Subprogram_Call then
1090 Set_No_Elaboration_Check (N);
1091 end if;
1092 end if;
1093
1094 -- Case of static elaboration model
1095
1096 else
1097 -- Do not do anything if elaboration checks suppressed. Note that
1098 -- we check Ent here, not E, since we want the real entity for the
1099 -- body to see if checks are suppressed for it, not the dummy
1100 -- entry for renamings or derivations.
1101
1102 if Elaboration_Checks_Suppressed (Ent)
1103 or else Elaboration_Checks_Suppressed (E_Scope)
1104 or else Elaboration_Checks_Suppressed (W_Scope)
1105 then
1106 null;
1107
1108 -- Do not generate an Elaborate_All for finalization routines
1109 -- which perform partial clean up as part of initialization.
1110
1111 elsif In_Init_Proc and then Is_Finalization_Procedure (Ent) then
1112 null;
1113
1114 -- Here we need to generate an implicit elaborate all
1115
1116 else
1117 -- Generate Elaborate_all warning unless suppressed
1118
1119 if (Elab_Info_Messages and Generate_Warnings and not Inst_Case)
1120 and then not Suppress_Elaboration_Warnings (Ent)
1121 and then not Suppress_Elaboration_Warnings (E_Scope)
1122 and then not Suppress_Elaboration_Warnings (W_Scope)
1123 then
1124 Error_Msg_Node_2 := W_Scope;
1125 Error_Msg_NE
1126 ("info: call to& in elaboration code " &
1127 "requires pragma Elaborate_All on&?$?", N, E);
1128 end if;
1129
1130 -- Set indication for binder to generate Elaborate_All
1131
1132 Set_Elaboration_Constraint (N, E, W_Scope);
1133 end if;
1134 end if;
1135
1136 -- Case of entity is in same unit as call or instantiation
1137
1138 elsif not Inter_Unit_Only then
1139 Check_Internal_Call (N, Ent, Outer_Scope, E);
1140 end if;
1141 end Check_A_Call;
1142
1143 -----------------------------
1144 -- Check_Bad_Instantiation --
1145 -----------------------------
1146
1147 procedure Check_Bad_Instantiation (N : Node_Id) is
1148 Ent : Entity_Id;
1149
1150 begin
1151 -- Nothing to do if we do not have an instantiation (happens in some
1152 -- error cases, and also in the formal package declaration case)
1153
1154 if Nkind (N) not in N_Generic_Instantiation then
1155 return;
1156
1157 -- Nothing to do if serious errors detected (avoid cascaded errors)
1158
1159 elsif Serious_Errors_Detected /= 0 then
1160 return;
1161
1162 -- Nothing to do if not in full analysis mode
1163
1164 elsif not Full_Analysis then
1165 return;
1166
1167 -- Nothing to do if inside a generic template
1168
1169 elsif Inside_A_Generic then
1170 return;
1171
1172 -- Nothing to do if a library level instantiation
1173
1174 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1175 return;
1176
1177 -- Nothing to do if we are compiling a proper body for semantic
1178 -- purposes only. The generic body may be in another proper body.
1179
1180 elsif
1181 Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit
1182 then
1183 return;
1184 end if;
1185
1186 Ent := Get_Generic_Entity (N);
1187
1188 -- The case we are interested in is when the generic spec is in the
1189 -- current declarative part
1190
1191 if not Same_Elaboration_Scope (Current_Scope, Scope (Ent))
1192 or else not In_Same_Extended_Unit (N, Ent)
1193 then
1194 return;
1195 end if;
1196
1197 -- If the generic entity is within a deeper instance than we are, then
1198 -- either the instantiation to which we refer itself caused an ABE, in
1199 -- which case that will be handled separately. Otherwise, we know that
1200 -- the body we need appears as needed at the point of the instantiation.
1201 -- If they are both at the same level but not within the same instance
1202 -- then the body of the generic will be in the earlier instance.
1203
1204 declare
1205 D1 : constant Int := Instantiation_Depth (Sloc (Ent));
1206 D2 : constant Int := Instantiation_Depth (Sloc (N));
1207
1208 begin
1209 if D1 > D2 then
1210 return;
1211
1212 elsif D1 = D2
1213 and then Is_Generic_Instance (Scope (Ent))
1214 and then not In_Open_Scopes (Scope (Ent))
1215 then
1216 return;
1217 end if;
1218 end;
1219
1220 -- Now we can proceed, if the entity being called has a completion,
1221 -- then we are definitely OK, since we have already seen the body.
1222
1223 if Has_Completion (Ent) then
1224 return;
1225 end if;
1226
1227 -- If there is no body, then nothing to do
1228
1229 if not Has_Generic_Body (N) then
1230 return;
1231 end if;
1232
1233 -- Here we definitely have a bad instantiation
1234
1235 Error_Msg_Warn := SPARK_Mode /= On;
1236 Error_Msg_NE ("cannot instantiate& before body seen<<", N, Ent);
1237
1238 if Present (Instance_Spec (N)) then
1239 Supply_Bodies (Instance_Spec (N));
1240 end if;
1241
1242 Error_Msg_N ("\Program_Error [<<", N);
1243 Insert_Elab_Check (N);
1244 Set_ABE_Is_Certain (N);
1245 end Check_Bad_Instantiation;
1246
1247 ---------------------
1248 -- Check_Elab_Call --
1249 ---------------------
1250
1251 procedure Check_Elab_Call
1252 (N : Node_Id;
1253 Outer_Scope : Entity_Id := Empty;
1254 In_Init_Proc : Boolean := False)
1255 is
1256 Ent : Entity_Id;
1257 P : Node_Id;
1258
1259 begin
1260 -- If the reference is not in the main unit, there is nothing to check.
1261 -- Elaboration call from units in the context of the main unit will lead
1262 -- to semantic dependencies when those units are compiled.
1263
1264 if not In_Extended_Main_Code_Unit (N) then
1265 return;
1266 end if;
1267
1268 -- For an entry call, check relevant restriction
1269
1270 if Nkind (N) = N_Entry_Call_Statement
1271 and then not In_Subprogram_Or_Concurrent_Unit
1272 then
1273 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N);
1274
1275 -- Nothing to do if this is not an expected type of reference (happens
1276 -- in some error conditions, and in some cases where rewriting occurs).
1277
1278 elsif Nkind (N) not in N_Subprogram_Call
1279 and then Nkind (N) /= N_Attribute_Reference
1280 and then (SPARK_Mode /= On
1281 or else Nkind (N) not in N_Has_Entity
1282 or else No (Entity (N))
1283 or else Ekind (Entity (N)) /= E_Variable)
1284 then
1285 return;
1286
1287 -- Nothing to do if this is a call already rewritten for elab checking.
1288 -- Such calls appear as the targets of If_Expressions.
1289
1290 -- This check MUST be wrong, it catches far too much
1291
1292 elsif Nkind (Parent (N)) = N_If_Expression then
1293 return;
1294
1295 -- Nothing to do if inside a generic template
1296
1297 elsif Inside_A_Generic
1298 and then No (Enclosing_Generic_Body (N))
1299 then
1300 return;
1301
1302 -- Nothing to do if call is being pre-analyzed, as when within a
1303 -- pre/postcondition, a predicate, or an invariant.
1304
1305 elsif In_Spec_Expression then
1306 return;
1307 end if;
1308
1309 -- Nothing to do if this is a call to a postcondition, which is always
1310 -- within a subprogram body, even though the current scope may be the
1311 -- enclosing scope of the subprogram.
1312
1313 if Nkind (N) = N_Procedure_Call_Statement
1314 and then Is_Entity_Name (Name (N))
1315 and then Chars (Entity (Name (N))) = Name_uPostconditions
1316 then
1317 return;
1318 end if;
1319
1320 -- Here we have a reference at elaboration time which must be checked
1321
1322 if Debug_Flag_LL then
1323 Write_Str (" Check_Elab_Ref: ");
1324
1325 if Nkind (N) = N_Attribute_Reference then
1326 if not Is_Entity_Name (Prefix (N)) then
1327 Write_Str ("<<not entity name>>");
1328 else
1329 Write_Name (Chars (Entity (Prefix (N))));
1330 end if;
1331
1332 Write_Str ("'Access");
1333
1334 elsif No (Name (N)) or else not Is_Entity_Name (Name (N)) then
1335 Write_Str ("<<not entity name>> ");
1336
1337 else
1338 Write_Name (Chars (Entity (Name (N))));
1339 end if;
1340
1341 Write_Str (" reference at ");
1342 Write_Location (Sloc (N));
1343 Write_Eol;
1344 end if;
1345
1346 -- Climb up the tree to make sure we are not inside default expression
1347 -- of a parameter specification or a record component, since in both
1348 -- these cases, we will be doing the actual reference later, not now,
1349 -- and it is at the time of the actual reference (statically speaking)
1350 -- that we must do our static check, not at the time of its initial
1351 -- analysis).
1352
1353 -- However, we have to check references within component definitions
1354 -- (e.g. a function call that determines an array component bound),
1355 -- so we terminate the loop in that case.
1356
1357 P := Parent (N);
1358 while Present (P) loop
1359 if Nkind_In (P, N_Parameter_Specification,
1360 N_Component_Declaration)
1361 then
1362 return;
1363
1364 -- The reference occurs within the constraint of a component,
1365 -- so it must be checked.
1366
1367 elsif Nkind (P) = N_Component_Definition then
1368 exit;
1369
1370 else
1371 P := Parent (P);
1372 end if;
1373 end loop;
1374
1375 -- Stuff that happens only at the outer level
1376
1377 if No (Outer_Scope) then
1378 Elab_Visited.Set_Last (0);
1379
1380 -- Nothing to do if current scope is Standard (this is a bit odd, but
1381 -- it happens in the case of generic instantiations).
1382
1383 C_Scope := Current_Scope;
1384
1385 if C_Scope = Standard_Standard then
1386 return;
1387 end if;
1388
1389 -- First case, we are in elaboration code
1390
1391 From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
1392
1393 if From_Elab_Code then
1394
1395 -- Complain if ref that comes from source in preelaborated unit
1396 -- and we are not inside a subprogram (i.e. we are in elab code).
1397
1398 if Comes_From_Source (N)
1399 and then In_Preelaborated_Unit
1400 and then not In_Inlined_Body
1401 and then Nkind (N) /= N_Attribute_Reference
1402 then
1403 -- This is a warning in GNAT mode allowing such calls to be
1404 -- used in the predefined library with appropriate care.
1405
1406 Error_Msg_Warn := GNAT_Mode;
1407 Error_Msg_N
1408 ("<<non-static call not allowed in preelaborated unit", N);
1409 return;
1410 end if;
1411
1412 -- Second case, we are inside a subprogram or concurrent unit, which
1413 -- means we are not in elaboration code.
1414
1415 else
1416 -- In this case, the issue is whether we are inside the
1417 -- declarative part of the unit in which we live, or inside its
1418 -- statements. In the latter case, there is no issue of ABE calls
1419 -- at this level (a call from outside to the unit in which we live
1420 -- might cause an ABE, but that will be detected when we analyze
1421 -- that outer level call, as it recurses into the called unit).
1422
1423 -- Climb up the tree, doing this test, and also testing for being
1424 -- inside a default expression, which, as discussed above, is not
1425 -- checked at this stage.
1426
1427 declare
1428 P : Node_Id;
1429 L : List_Id;
1430
1431 begin
1432 P := N;
1433 loop
1434 -- If we find a parentless subtree, it seems safe to assume
1435 -- that we are not in a declarative part and that no
1436 -- checking is required.
1437
1438 if No (P) then
1439 return;
1440 end if;
1441
1442 if Is_List_Member (P) then
1443 L := List_Containing (P);
1444 P := Parent (L);
1445 else
1446 L := No_List;
1447 P := Parent (P);
1448 end if;
1449
1450 exit when Nkind (P) = N_Subunit;
1451
1452 -- Filter out case of default expressions, where we do not
1453 -- do the check at this stage.
1454
1455 if Nkind_In (P, N_Parameter_Specification,
1456 N_Component_Declaration)
1457 then
1458 return;
1459 end if;
1460
1461 -- A protected body has no elaboration code and contains
1462 -- only other bodies.
1463
1464 if Nkind (P) = N_Protected_Body then
1465 return;
1466
1467 elsif Nkind_In (P, N_Subprogram_Body,
1468 N_Task_Body,
1469 N_Block_Statement,
1470 N_Entry_Body)
1471 then
1472 if L = Declarations (P) then
1473 exit;
1474
1475 -- We are not in elaboration code, but we are doing
1476 -- dynamic elaboration checks, in this case, we still
1477 -- need to do the reference, since the subprogram we are
1478 -- in could be called from another unit, also in dynamic
1479 -- elaboration check mode, at elaboration time.
1480
1481 elsif Dynamic_Elaboration_Checks then
1482
1483 -- We provide a debug flag to disable this check. That
1484 -- way we have an easy work around for regressions
1485 -- that are caused by this new check. This debug flag
1486 -- can be removed later.
1487
1488 if Debug_Flag_DD then
1489 return;
1490 end if;
1491
1492 -- Do the check in this case
1493
1494 exit;
1495
1496 elsif Nkind (P) = N_Task_Body then
1497
1498 -- The check is deferred until Check_Task_Activation
1499 -- but we need to capture local suppress pragmas
1500 -- that may inhibit checks on this call.
1501
1502 Ent := Get_Referenced_Ent (N);
1503
1504 if No (Ent) then
1505 return;
1506
1507 elsif Elaboration_Checks_Suppressed (Current_Scope)
1508 or else Elaboration_Checks_Suppressed (Ent)
1509 or else Elaboration_Checks_Suppressed (Scope (Ent))
1510 then
1511 Set_No_Elaboration_Check (N);
1512 end if;
1513
1514 return;
1515
1516 -- Static model, call is not in elaboration code, we
1517 -- never need to worry, because in the static model the
1518 -- top level caller always takes care of things.
1519
1520 else
1521 return;
1522 end if;
1523 end if;
1524 end loop;
1525 end;
1526 end if;
1527 end if;
1528
1529 Ent := Get_Referenced_Ent (N);
1530
1531 if No (Ent) then
1532 return;
1533 end if;
1534
1535 -- Nothing to do if this is a recursive call (i.e. a call to
1536 -- an entity that is already in the Elab_Call stack)
1537
1538 for J in 1 .. Elab_Visited.Last loop
1539 if Ent = Elab_Visited.Table (J) then
1540 return;
1541 end if;
1542 end loop;
1543
1544 -- See if we need to analyze this reference. We analyze it if either of
1545 -- the following conditions is met:
1546
1547 -- It is an inner level call (since in this case it was triggered
1548 -- by an outer level call from elaboration code), but only if the
1549 -- call is within the scope of the original outer level call.
1550
1551 -- It is an outer level reference from elaboration code, or a call to
1552 -- an entity is in the same elaboration scope.
1553
1554 -- And in these cases, we will check both inter-unit calls and
1555 -- intra-unit (within a single unit) calls.
1556
1557 C_Scope := Current_Scope;
1558
1559 -- If not outer level reference, then we follow it if it is within the
1560 -- original scope of the outer reference.
1561
1562 if Present (Outer_Scope)
1563 and then Within (Scope (Ent), Outer_Scope)
1564 then
1565 Set_C_Scope;
1566 Check_A_Call
1567 (N => N,
1568 E => Ent,
1569 Outer_Scope => Outer_Scope,
1570 Inter_Unit_Only => False,
1571 In_Init_Proc => In_Init_Proc);
1572
1573 -- Nothing to do if elaboration checks suppressed for this scope.
1574 -- However, an interesting exception, the fact that elaboration checks
1575 -- are suppressed within an instance (because we can trace the body when
1576 -- we process the template) does not extend to calls to generic formal
1577 -- subprograms.
1578
1579 elsif Elaboration_Checks_Suppressed (Current_Scope)
1580 and then not Is_Call_Of_Generic_Formal (N)
1581 then
1582 null;
1583
1584 elsif From_Elab_Code then
1585 Set_C_Scope;
1586 Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
1587
1588 elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
1589 Set_C_Scope;
1590 Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
1591
1592 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1593 -- is set, then we will do the check, but only in the inter-unit case
1594 -- (this is to accommodate unguarded elaboration calls from other units
1595 -- in which this same mode is set). We don't want warnings in this case,
1596 -- it would generate warnings having nothing to do with elaboration.
1597
1598 elsif Dynamic_Elaboration_Checks then
1599 Set_C_Scope;
1600 Check_A_Call
1601 (N,
1602 Ent,
1603 Standard_Standard,
1604 Inter_Unit_Only => True,
1605 Generate_Warnings => False);
1606
1607 -- Otherwise nothing to do
1608
1609 else
1610 return;
1611 end if;
1612
1613 -- A call to an Init_Proc in elaboration code may bring additional
1614 -- dependencies, if some of the record components thereof have
1615 -- initializations that are function calls that come from source. We
1616 -- treat the current node as a call to each of these functions, to check
1617 -- their elaboration impact.
1618
1619 if Is_Init_Proc (Ent) and then From_Elab_Code then
1620 Process_Init_Proc : declare
1621 Unit_Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1622
1623 function Check_Init_Call (Nod : Node_Id) return Traverse_Result;
1624 -- Find subprogram calls within body of Init_Proc for Traverse
1625 -- instantiation below.
1626
1627 procedure Traverse_Body is new Traverse_Proc (Check_Init_Call);
1628 -- Traversal procedure to find all calls with body of Init_Proc
1629
1630 ---------------------
1631 -- Check_Init_Call --
1632 ---------------------
1633
1634 function Check_Init_Call (Nod : Node_Id) return Traverse_Result is
1635 Func : Entity_Id;
1636
1637 begin
1638 if Nkind (Nod) in N_Subprogram_Call
1639 and then Is_Entity_Name (Name (Nod))
1640 then
1641 Func := Entity (Name (Nod));
1642
1643 if Comes_From_Source (Func) then
1644 Check_A_Call
1645 (N, Func, Standard_Standard, Inter_Unit_Only => True);
1646 end if;
1647
1648 return OK;
1649
1650 else
1651 return OK;
1652 end if;
1653 end Check_Init_Call;
1654
1655 -- Start of processing for Process_Init_Proc
1656
1657 begin
1658 if Nkind (Unit_Decl) = N_Subprogram_Body then
1659 Traverse_Body (Handled_Statement_Sequence (Unit_Decl));
1660 end if;
1661 end Process_Init_Proc;
1662 end if;
1663 end Check_Elab_Call;
1664
1665 -----------------------
1666 -- Check_Elab_Assign --
1667 -----------------------
1668
1669 procedure Check_Elab_Assign (N : Node_Id) is
1670 Ent : Entity_Id;
1671 Scop : Entity_Id;
1672
1673 Pkg_Spec : Entity_Id;
1674 Pkg_Body : Entity_Id;
1675
1676 begin
1677 -- For record or array component, check prefix. If it is an access type,
1678 -- then there is nothing to do (we do not know what is being assigned),
1679 -- but otherwise this is an assignment to the prefix.
1680
1681 if Nkind_In (N, N_Indexed_Component,
1682 N_Selected_Component,
1683 N_Slice)
1684 then
1685 if not Is_Access_Type (Etype (Prefix (N))) then
1686 Check_Elab_Assign (Prefix (N));
1687 end if;
1688
1689 return;
1690 end if;
1691
1692 -- For type conversion, check expression
1693
1694 if Nkind (N) = N_Type_Conversion then
1695 Check_Elab_Assign (Expression (N));
1696 return;
1697 end if;
1698
1699 -- Nothing to do if this is not an entity reference otherwise get entity
1700
1701 if Is_Entity_Name (N) then
1702 Ent := Entity (N);
1703 else
1704 return;
1705 end if;
1706
1707 -- What we are looking for is a reference in the body of a package that
1708 -- modifies a variable declared in the visible part of the package spec.
1709
1710 if Present (Ent)
1711 and then Comes_From_Source (N)
1712 and then not Suppress_Elaboration_Warnings (Ent)
1713 and then Ekind (Ent) = E_Variable
1714 and then not In_Private_Part (Ent)
1715 and then Is_Library_Level_Entity (Ent)
1716 then
1717 Scop := Current_Scope;
1718 loop
1719 if No (Scop) or else Scop = Standard_Standard then
1720 return;
1721 elsif Ekind (Scop) = E_Package
1722 and then Is_Compilation_Unit (Scop)
1723 then
1724 exit;
1725 else
1726 Scop := Scope (Scop);
1727 end if;
1728 end loop;
1729
1730 -- Here Scop points to the containing library package
1731
1732 Pkg_Spec := Scop;
1733 Pkg_Body := Body_Entity (Pkg_Spec);
1734
1735 -- All OK if the package has an Elaborate_Body pragma
1736
1737 if Has_Pragma_Elaborate_Body (Scop) then
1738 return;
1739 end if;
1740
1741 -- OK if entity being modified is not in containing package spec
1742
1743 if not In_Same_Source_Unit (Scop, Ent) then
1744 return;
1745 end if;
1746
1747 -- All OK if entity appears in generic package or generic instance.
1748 -- We just get too messed up trying to give proper warnings in the
1749 -- presence of generics. Better no message than a junk one.
1750
1751 Scop := Scope (Ent);
1752 while Present (Scop) and then Scop /= Pkg_Spec loop
1753 if Ekind (Scop) = E_Generic_Package then
1754 return;
1755 elsif Ekind (Scop) = E_Package
1756 and then Is_Generic_Instance (Scop)
1757 then
1758 return;
1759 end if;
1760
1761 Scop := Scope (Scop);
1762 end loop;
1763
1764 -- All OK if in task, don't issue warnings there
1765
1766 if In_Task_Activation then
1767 return;
1768 end if;
1769
1770 -- OK if no package body
1771
1772 if No (Pkg_Body) then
1773 return;
1774 end if;
1775
1776 -- OK if reference is not in package body
1777
1778 if not In_Same_Source_Unit (Pkg_Body, N) then
1779 return;
1780 end if;
1781
1782 -- OK if package body has no handled statement sequence
1783
1784 declare
1785 HSS : constant Node_Id :=
1786 Handled_Statement_Sequence (Declaration_Node (Pkg_Body));
1787 begin
1788 if No (HSS) or else not Comes_From_Source (HSS) then
1789 return;
1790 end if;
1791 end;
1792
1793 -- We definitely have a case of a modification of an entity in
1794 -- the package spec from the elaboration code of the package body.
1795 -- We may not give the warning (because there are some additional
1796 -- checks to avoid too many false positives), but it would be a good
1797 -- idea for the binder to try to keep the body elaboration close to
1798 -- the spec elaboration.
1799
1800 Set_Elaborate_Body_Desirable (Pkg_Spec);
1801
1802 -- All OK in gnat mode (we know what we are doing)
1803
1804 if GNAT_Mode then
1805 return;
1806 end if;
1807
1808 -- All OK if all warnings suppressed
1809
1810 if Warning_Mode = Suppress then
1811 return;
1812 end if;
1813
1814 -- All OK if elaboration checks suppressed for entity
1815
1816 if Checks_May_Be_Suppressed (Ent)
1817 and then Is_Check_Suppressed (Ent, Elaboration_Check)
1818 then
1819 return;
1820 end if;
1821
1822 -- OK if the entity is initialized. Note that the No_Initialization
1823 -- flag usually means that the initialization has been rewritten into
1824 -- assignments, but that still counts for us.
1825
1826 declare
1827 Decl : constant Node_Id := Declaration_Node (Ent);
1828 begin
1829 if Nkind (Decl) = N_Object_Declaration
1830 and then (Present (Expression (Decl))
1831 or else No_Initialization (Decl))
1832 then
1833 return;
1834 end if;
1835 end;
1836
1837 -- Here is where we give the warning
1838
1839 -- All OK if warnings suppressed on the entity
1840
1841 if not Has_Warnings_Off (Ent) then
1842 Error_Msg_Sloc := Sloc (Ent);
1843
1844 Error_Msg_NE
1845 ("??& can be accessed by clients before this initialization",
1846 N, Ent);
1847 Error_Msg_NE
1848 ("\??add Elaborate_Body to spec to ensure & is initialized",
1849 N, Ent);
1850 end if;
1851
1852 if not All_Errors_Mode then
1853 Set_Suppress_Elaboration_Warnings (Ent);
1854 end if;
1855 end if;
1856 end Check_Elab_Assign;
1857
1858 ----------------------
1859 -- Check_Elab_Calls --
1860 ----------------------
1861
1862 procedure Check_Elab_Calls is
1863 begin
1864 -- If expansion is disabled, do not generate any checks. Also skip
1865 -- checks if any subunits are missing because in either case we lack the
1866 -- full information that we need, and no object file will be created in
1867 -- any case.
1868
1869 if not Expander_Active
1870 or else Is_Generic_Unit (Cunit_Entity (Main_Unit))
1871 or else Subunits_Missing
1872 then
1873 return;
1874 end if;
1875
1876 -- Skip delayed calls if we had any errors
1877
1878 if Serious_Errors_Detected = 0 then
1879 Delaying_Elab_Checks := False;
1880 Expander_Mode_Save_And_Set (True);
1881
1882 for J in Delay_Check.First .. Delay_Check.Last loop
1883 Push_Scope (Delay_Check.Table (J).Curscop);
1884 From_Elab_Code := Delay_Check.Table (J).From_Elab_Code;
1885
1886 Check_Internal_Call_Continue (
1887 N => Delay_Check.Table (J).N,
1888 E => Delay_Check.Table (J).E,
1889 Outer_Scope => Delay_Check.Table (J).Outer_Scope,
1890 Orig_Ent => Delay_Check.Table (J).Orig_Ent);
1891
1892 Pop_Scope;
1893 end loop;
1894
1895 -- Set Delaying_Elab_Checks back on for next main compilation
1896
1897 Expander_Mode_Restore;
1898 Delaying_Elab_Checks := True;
1899 end if;
1900 end Check_Elab_Calls;
1901
1902 ------------------------------
1903 -- Check_Elab_Instantiation --
1904 ------------------------------
1905
1906 procedure Check_Elab_Instantiation
1907 (N : Node_Id;
1908 Outer_Scope : Entity_Id := Empty)
1909 is
1910 Ent : Entity_Id;
1911
1912 begin
1913 -- Check for and deal with bad instantiation case. There is some
1914 -- duplicated code here, but we will worry about this later ???
1915
1916 Check_Bad_Instantiation (N);
1917
1918 if ABE_Is_Certain (N) then
1919 return;
1920 end if;
1921
1922 -- Nothing to do if we do not have an instantiation (happens in some
1923 -- error cases, and also in the formal package declaration case)
1924
1925 if Nkind (N) not in N_Generic_Instantiation then
1926 return;
1927 end if;
1928
1929 -- Nothing to do if inside a generic template
1930
1931 if Inside_A_Generic then
1932 return;
1933 end if;
1934
1935 -- Nothing to do if the instantiation is not in the main unit
1936
1937 if not In_Extended_Main_Code_Unit (N) then
1938 return;
1939 end if;
1940
1941 Ent := Get_Generic_Entity (N);
1942 From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
1943
1944 -- See if we need to analyze this instantiation. We analyze it if
1945 -- either of the following conditions is met:
1946
1947 -- It is an inner level instantiation (since in this case it was
1948 -- triggered by an outer level call from elaboration code), but
1949 -- only if the instantiation is within the scope of the original
1950 -- outer level call.
1951
1952 -- It is an outer level instantiation from elaboration code, or the
1953 -- instantiated entity is in the same elaboration scope.
1954
1955 -- And in these cases, we will check both the inter-unit case and
1956 -- the intra-unit (within a single unit) case.
1957
1958 C_Scope := Current_Scope;
1959
1960 if Present (Outer_Scope) and then Within (Scope (Ent), Outer_Scope) then
1961 Set_C_Scope;
1962 Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
1963
1964 elsif From_Elab_Code then
1965 Set_C_Scope;
1966 Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
1967
1968 elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
1969 Set_C_Scope;
1970 Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
1971
1972 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode is
1973 -- set, then we will do the check, but only in the inter-unit case (this
1974 -- is to accommodate unguarded elaboration calls from other units in
1975 -- which this same mode is set). We inhibit warnings in this case, since
1976 -- this instantiation is not occurring in elaboration code.
1977
1978 elsif Dynamic_Elaboration_Checks then
1979 Set_C_Scope;
1980 Check_A_Call
1981 (N,
1982 Ent,
1983 Standard_Standard,
1984 Inter_Unit_Only => True,
1985 Generate_Warnings => False);
1986
1987 else
1988 return;
1989 end if;
1990 end Check_Elab_Instantiation;
1991
1992 -------------------------
1993 -- Check_Internal_Call --
1994 -------------------------
1995
1996 procedure Check_Internal_Call
1997 (N : Node_Id;
1998 E : Entity_Id;
1999 Outer_Scope : Entity_Id;
2000 Orig_Ent : Entity_Id)
2001 is
2002 Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
2003
2004 begin
2005 -- For P'Access, we want to warn if the -gnatw.f switch is set, and the
2006 -- node comes from source.
2007
2008 if Nkind (N) = N_Attribute_Reference and then
2009 (not Warn_On_Elab_Access or else not Comes_From_Source (N))
2010 then
2011 return;
2012
2013 -- If not function or procedure call, instantiation, or 'Access, then
2014 -- ignore call (this happens in some error cases and rewriting cases).
2015
2016 elsif not Nkind_In
2017 (N, N_Function_Call,
2018 N_Procedure_Call_Statement,
2019 N_Attribute_Reference)
2020 and then not Inst_Case
2021 then
2022 return;
2023
2024 -- Nothing to do if this is a call or instantiation that has already
2025 -- been found to be a sure ABE.
2026
2027 elsif Nkind (N) /= N_Attribute_Reference and then ABE_Is_Certain (N) then
2028 return;
2029
2030 -- Nothing to do if errors already detected (avoid cascaded errors)
2031
2032 elsif Serious_Errors_Detected /= 0 then
2033 return;
2034
2035 -- Nothing to do if not in full analysis mode
2036
2037 elsif not Full_Analysis then
2038 return;
2039
2040 -- Nothing to do if analyzing in special spec-expression mode, since the
2041 -- call is not actually being made at this time.
2042
2043 elsif In_Spec_Expression then
2044 return;
2045
2046 -- Nothing to do for call to intrinsic subprogram
2047
2048 elsif Is_Intrinsic_Subprogram (E) then
2049 return;
2050
2051 -- No need to trace local calls if checking task activation, because
2052 -- other local bodies are elaborated already.
2053
2054 elsif In_Task_Activation then
2055 return;
2056
2057 -- Nothing to do if call is within a generic unit
2058
2059 elsif Inside_A_Generic then
2060 return;
2061 end if;
2062
2063 -- Delay this call if we are still delaying calls
2064
2065 if Delaying_Elab_Checks then
2066 Delay_Check.Append (
2067 (N => N,
2068 E => E,
2069 Orig_Ent => Orig_Ent,
2070 Curscop => Current_Scope,
2071 Outer_Scope => Outer_Scope,
2072 From_Elab_Code => From_Elab_Code));
2073 return;
2074
2075 -- Otherwise, call phase 2 continuation right now
2076
2077 else
2078 Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent);
2079 end if;
2080 end Check_Internal_Call;
2081
2082 ----------------------------------
2083 -- Check_Internal_Call_Continue --
2084 ----------------------------------
2085
2086 procedure Check_Internal_Call_Continue
2087 (N : Node_Id;
2088 E : Entity_Id;
2089 Outer_Scope : Entity_Id;
2090 Orig_Ent : Entity_Id)
2091 is
2092 Loc : constant Source_Ptr := Sloc (N);
2093 Inst_Case : constant Boolean := Is_Generic_Unit (E);
2094
2095 Sbody : Node_Id;
2096 Ebody : Entity_Id;
2097
2098 function Find_Elab_Reference (N : Node_Id) return Traverse_Result;
2099 -- Function applied to each node as we traverse the body. Checks for
2100 -- call or entity reference that needs checking, and if so checks it.
2101 -- Always returns OK, so entire tree is traversed, except that as
2102 -- described below subprogram bodies are skipped for now.
2103
2104 procedure Traverse is new Atree.Traverse_Proc (Find_Elab_Reference);
2105 -- Traverse procedure using above Find_Elab_Reference function
2106
2107 -------------------------
2108 -- Find_Elab_Reference --
2109 -------------------------
2110
2111 function Find_Elab_Reference (N : Node_Id) return Traverse_Result is
2112 Actual : Node_Id;
2113
2114 begin
2115 -- If user has specified that there are no entry calls in elaboration
2116 -- code, do not trace past an accept statement, because the rendez-
2117 -- vous will happen after elaboration.
2118
2119 if Nkind_In (Original_Node (N), N_Accept_Statement,
2120 N_Selective_Accept)
2121 and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
2122 then
2123 return Abandon;
2124
2125 -- If we have a function call, check it
2126
2127 elsif Nkind (N) = N_Function_Call then
2128 Check_Elab_Call (N, Outer_Scope);
2129 return OK;
2130
2131 -- If we have a procedure call, check the call, and also check
2132 -- arguments that are assignments (OUT or IN OUT mode formals).
2133
2134 elsif Nkind (N) = N_Procedure_Call_Statement then
2135 Check_Elab_Call (N, Outer_Scope, In_Init_Proc => Is_Init_Proc (E));
2136
2137 Actual := First_Actual (N);
2138 while Present (Actual) loop
2139 if Known_To_Be_Assigned (Actual) then
2140 Check_Elab_Assign (Actual);
2141 end if;
2142
2143 Next_Actual (Actual);
2144 end loop;
2145
2146 return OK;
2147
2148 -- If we have an access attribute for a subprogram, check it.
2149 -- Suppress this behavior under debug flag.
2150
2151 elsif not Debug_Flag_Dot_UU
2152 and then Nkind (N) = N_Attribute_Reference
2153 and then Nam_In (Attribute_Name (N), Name_Access,
2154 Name_Unrestricted_Access)
2155 and then Is_Entity_Name (Prefix (N))
2156 and then Is_Subprogram (Entity (Prefix (N)))
2157 then
2158 Check_Elab_Call (N, Outer_Scope);
2159 return OK;
2160
2161 -- In SPARK mode, if we have an entity reference to a variable, then
2162 -- check it. For now we consider any reference.
2163
2164 elsif SPARK_Mode = On
2165 and then Nkind (N) in N_Has_Entity
2166 and then Present (Entity (N))
2167 and then Ekind (Entity (N)) = E_Variable
2168 then
2169 Check_Elab_Call (N, Outer_Scope);
2170 return OK;
2171
2172 -- If we have a generic instantiation, check it
2173
2174 elsif Nkind (N) in N_Generic_Instantiation then
2175 Check_Elab_Instantiation (N, Outer_Scope);
2176 return OK;
2177
2178 -- Skip subprogram bodies that come from source (wait for call to
2179 -- analyze these). The reason for the come from source test is to
2180 -- avoid catching task bodies.
2181
2182 -- For task bodies, we should really avoid these too, waiting for the
2183 -- task activation, but that's too much trouble to catch for now, so
2184 -- we go in unconditionally. This is not so terrible, it means the
2185 -- error backtrace is not quite complete, and we are too eager to
2186 -- scan bodies of tasks that are unused, but this is hardly very
2187 -- significant.
2188
2189 elsif Nkind (N) = N_Subprogram_Body
2190 and then Comes_From_Source (N)
2191 then
2192 return Skip;
2193
2194 elsif Nkind (N) = N_Assignment_Statement
2195 and then Comes_From_Source (N)
2196 then
2197 Check_Elab_Assign (Name (N));
2198 return OK;
2199
2200 else
2201 return OK;
2202 end if;
2203 end Find_Elab_Reference;
2204
2205 -- Start of processing for Check_Internal_Call_Continue
2206
2207 begin
2208 -- Save outer level call if at outer level
2209
2210 if Elab_Call.Last = 0 then
2211 Outer_Level_Sloc := Loc;
2212 end if;
2213
2214 Elab_Visited.Append (E);
2215
2216 -- If the call is to a function that renames a literal, no check needed
2217
2218 if Ekind (E) = E_Enumeration_Literal then
2219 return;
2220 end if;
2221
2222 Sbody := Unit_Declaration_Node (E);
2223
2224 if not Nkind_In (Sbody, N_Subprogram_Body, N_Package_Body) then
2225 Ebody := Corresponding_Body (Sbody);
2226
2227 if No (Ebody) then
2228 return;
2229 else
2230 Sbody := Unit_Declaration_Node (Ebody);
2231 end if;
2232 end if;
2233
2234 -- If the body appears after the outer level call or instantiation then
2235 -- we have an error case handled below.
2236
2237 if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody))
2238 and then not In_Task_Activation
2239 then
2240 null;
2241
2242 -- If we have the instantiation case we are done, since we now
2243 -- know that the body of the generic appeared earlier.
2244
2245 elsif Inst_Case then
2246 return;
2247
2248 -- Otherwise we have a call, so we trace through the called body to see
2249 -- if it has any problems.
2250
2251 else
2252 pragma Assert (Nkind (Sbody) = N_Subprogram_Body);
2253
2254 Elab_Call.Append ((Cloc => Loc, Ent => E));
2255
2256 if Debug_Flag_LL then
2257 Write_Str ("Elab_Call.Last = ");
2258 Write_Int (Int (Elab_Call.Last));
2259 Write_Str (" Ent = ");
2260 Write_Name (Chars (E));
2261 Write_Str (" at ");
2262 Write_Location (Sloc (N));
2263 Write_Eol;
2264 end if;
2265
2266 -- Now traverse declarations and statements of subprogram body. Note
2267 -- that we cannot simply Traverse (Sbody), since traverse does not
2268 -- normally visit subprogram bodies.
2269
2270 declare
2271 Decl : Node_Id;
2272 begin
2273 Decl := First (Declarations (Sbody));
2274 while Present (Decl) loop
2275 Traverse (Decl);
2276 Next (Decl);
2277 end loop;
2278 end;
2279
2280 Traverse (Handled_Statement_Sequence (Sbody));
2281
2282 Elab_Call.Decrement_Last;
2283 return;
2284 end if;
2285
2286 -- Here is the case of calling a subprogram where the body has not yet
2287 -- been encountered. A warning message is needed, except if this is the
2288 -- case of appearing within an aspect specification that results in
2289 -- a check call, we do not really have such a situation, so no warning
2290 -- is needed (e.g. the case of a precondition, where the call appears
2291 -- textually before the body, but in actual fact is moved to the
2292 -- appropriate subprogram body and so does not need a check).
2293
2294 declare
2295 P : Node_Id;
2296 O : Node_Id;
2297
2298 begin
2299 P := Parent (N);
2300 loop
2301 -- Keep looking at parents if we are still in the subexpression
2302
2303 if Nkind (P) in N_Subexpr then
2304 P := Parent (P);
2305
2306 -- Here P is the parent of the expression, check for special case
2307
2308 else
2309 O := Original_Node (P);
2310
2311 -- Definitely not the special case if orig node is not a pragma
2312
2313 exit when Nkind (O) /= N_Pragma;
2314
2315 -- Check we have an If statement or a null statement (happens
2316 -- when the If has been expanded to be True).
2317
2318 exit when not Nkind_In (P, N_If_Statement, N_Null_Statement);
2319
2320 -- Our special case will be indicated either by the pragma
2321 -- coming from an aspect ...
2322
2323 if Present (Corresponding_Aspect (O)) then
2324 return;
2325
2326 -- Or, in the case of an initial condition, specifically by a
2327 -- Check pragma specifying an Initial_Condition check.
2328
2329 elsif Pragma_Name (O) = Name_Check
2330 and then
2331 Chars
2332 (Expression (First (Pragma_Argument_Associations (O)))) =
2333 Name_Initial_Condition
2334 then
2335 return;
2336
2337 -- For anything else, we have an error
2338
2339 else
2340 exit;
2341 end if;
2342 end if;
2343 end loop;
2344 end;
2345
2346 -- Not that special case, warning and dynamic check is required
2347
2348 -- If we have nothing in the call stack, then this is at the outer
2349 -- level, and the ABE is bound to occur, unless it's a 'Access.
2350
2351 if Elab_Call.Last = 0 then
2352 Error_Msg_Warn := SPARK_Mode /= On;
2353
2354 if Inst_Case then
2355 Error_Msg_NE
2356 ("cannot instantiate& before body seen<<", N, Orig_Ent);
2357 elsif Nkind (N) /= N_Attribute_Reference then
2358 Error_Msg_NE
2359 ("cannot call& before body seen<<", N, Orig_Ent);
2360 else
2361 Error_Msg_NE
2362 ("Access attribute of & before body seen<<", N, Orig_Ent);
2363 Error_Msg_N ("\possible Program_Error on later references<", N);
2364 end if;
2365
2366 if Nkind (N) /= N_Attribute_Reference then
2367 Error_Msg_N ("\Program_Error [<<", N);
2368 Insert_Elab_Check (N);
2369 end if;
2370
2371 -- Call is not at outer level
2372
2373 else
2374 -- Deal with dynamic elaboration check
2375
2376 if not Elaboration_Checks_Suppressed (E) then
2377 Set_Elaboration_Entity_Required (E);
2378
2379 -- Case of no elaboration entity allocated yet
2380
2381 if No (Elaboration_Entity (E)) then
2382
2383 -- Create object declaration for elaboration entity, and put it
2384 -- just in front of the spec of the subprogram or generic unit,
2385 -- in the same scope as this unit. The subprogram may be over-
2386 -- loaded, so make the name of elaboration entity unique by
2387 -- means of a numeric suffix.
2388
2389 declare
2390 Loce : constant Source_Ptr := Sloc (E);
2391 Ent : constant Entity_Id :=
2392 Make_Defining_Identifier (Loc,
2393 Chars => New_External_Name (Chars (E), 'E', -1));
2394
2395 begin
2396 Set_Elaboration_Entity (E, Ent);
2397 Push_Scope (Scope (E));
2398
2399 Insert_Action (Declaration_Node (E),
2400 Make_Object_Declaration (Loce,
2401 Defining_Identifier => Ent,
2402 Object_Definition =>
2403 New_Occurrence_Of (Standard_Short_Integer, Loce),
2404 Expression =>
2405 Make_Integer_Literal (Loc, Uint_0)));
2406
2407 -- Set elaboration flag at the point of the body
2408
2409 Set_Elaboration_Flag (Sbody, E);
2410
2411 -- Kill current value indication. This is necessary because
2412 -- the tests of this flag are inserted out of sequence and
2413 -- must not pick up bogus indications of the wrong constant
2414 -- value. Also, this is never a true constant, since one way
2415 -- or another, it gets reset.
2416
2417 Set_Current_Value (Ent, Empty);
2418 Set_Last_Assignment (Ent, Empty);
2419 Set_Is_True_Constant (Ent, False);
2420 Pop_Scope;
2421 end;
2422 end if;
2423
2424 -- Generate check of the elaboration counter
2425
2426 Insert_Elab_Check (N,
2427 Make_Attribute_Reference (Loc,
2428 Attribute_Name => Name_Elaborated,
2429 Prefix => New_Occurrence_Of (E, Loc)));
2430 end if;
2431
2432 -- Generate the warning
2433
2434 if not Suppress_Elaboration_Warnings (E)
2435 and then not Elaboration_Checks_Suppressed (E)
2436
2437 -- Suppress this warning if we have a function call that occurred
2438 -- within an assertion expression, since we can get false warnings
2439 -- in this case, due to the out of order handling in this case.
2440
2441 and then
2442 (Nkind (Original_Node (N)) /= N_Function_Call
2443 or else not In_Assertion_Expression_Pragma (Original_Node (N)))
2444 then
2445 Error_Msg_Warn := SPARK_Mode /= On;
2446
2447 if Inst_Case then
2448 Error_Msg_NE
2449 ("instantiation of& may occur before body is seen<l<",
2450 N, Orig_Ent);
2451 else
2452 Error_Msg_NE
2453 ("call to& may occur before body is seen<l<", N, Orig_Ent);
2454 end if;
2455
2456 Error_Msg_N ("\Program_Error ]<l<", N);
2457
2458 -- There is no need to query the elaboration warning message flags
2459 -- because the main message is an error, not a warning, therefore
2460 -- all the clarification messages produces by Output_Calls must be
2461 -- emitted unconditionally.
2462
2463 Output_Calls (N, Check_Elab_Flag => False);
2464 end if;
2465 end if;
2466
2467 -- Set flag to suppress further warnings on same subprogram
2468 -- unless in all errors mode
2469
2470 if not All_Errors_Mode then
2471 Set_Suppress_Elaboration_Warnings (E);
2472 end if;
2473 end Check_Internal_Call_Continue;
2474
2475 ---------------------------
2476 -- Check_Task_Activation --
2477 ---------------------------
2478
2479 procedure Check_Task_Activation (N : Node_Id) is
2480 Loc : constant Source_Ptr := Sloc (N);
2481 Inter_Procs : constant Elist_Id := New_Elmt_List;
2482 Intra_Procs : constant Elist_Id := New_Elmt_List;
2483 Ent : Entity_Id;
2484 P : Entity_Id;
2485 Task_Scope : Entity_Id;
2486 Cunit_SC : Boolean := False;
2487 Decl : Node_Id;
2488 Elmt : Elmt_Id;
2489 Enclosing : Entity_Id;
2490
2491 procedure Add_Task_Proc (Typ : Entity_Id);
2492 -- Add to Task_Procs the task body procedure(s) of task types in Typ.
2493 -- For record types, this procedure recurses over component types.
2494
2495 procedure Collect_Tasks (Decls : List_Id);
2496 -- Collect the types of the tasks that are to be activated in the given
2497 -- list of declarations, in order to perform elaboration checks on the
2498 -- corresponding task procedures which are called implicitly here.
2499
2500 function Outer_Unit (E : Entity_Id) return Entity_Id;
2501 -- find enclosing compilation unit of Entity, ignoring subunits, or
2502 -- else enclosing subprogram. If E is not a package, there is no need
2503 -- for inter-unit elaboration checks.
2504
2505 -------------------
2506 -- Add_Task_Proc --
2507 -------------------
2508
2509 procedure Add_Task_Proc (Typ : Entity_Id) is
2510 Comp : Entity_Id;
2511 Proc : Entity_Id := Empty;
2512
2513 begin
2514 if Is_Task_Type (Typ) then
2515 Proc := Get_Task_Body_Procedure (Typ);
2516
2517 elsif Is_Array_Type (Typ)
2518 and then Has_Task (Base_Type (Typ))
2519 then
2520 Add_Task_Proc (Component_Type (Typ));
2521
2522 elsif Is_Record_Type (Typ)
2523 and then Has_Task (Base_Type (Typ))
2524 then
2525 Comp := First_Component (Typ);
2526 while Present (Comp) loop
2527 Add_Task_Proc (Etype (Comp));
2528 Comp := Next_Component (Comp);
2529 end loop;
2530 end if;
2531
2532 -- If the task type is another unit, we will perform the usual
2533 -- elaboration check on its enclosing unit. If the type is in the
2534 -- same unit, we can trace the task body as for an internal call,
2535 -- but we only need to examine other external calls, because at
2536 -- the point the task is activated, internal subprogram bodies
2537 -- will have been elaborated already. We keep separate lists for
2538 -- each kind of task.
2539
2540 -- Skip this test if errors have occurred, since in this case
2541 -- we can get false indications.
2542
2543 if Serious_Errors_Detected /= 0 then
2544 return;
2545 end if;
2546
2547 if Present (Proc) then
2548 if Outer_Unit (Scope (Proc)) = Enclosing then
2549
2550 if No (Corresponding_Body (Unit_Declaration_Node (Proc)))
2551 and then
2552 (not Is_Generic_Instance (Scope (Proc))
2553 or else Scope (Proc) = Scope (Defining_Identifier (Decl)))
2554 then
2555 Error_Msg_Warn := SPARK_Mode /= On;
2556 Error_Msg_N
2557 ("task will be activated before elaboration of its body<<",
2558 Decl);
2559 Error_Msg_N ("\Program_Error [<<", Decl);
2560
2561 elsif Present
2562 (Corresponding_Body (Unit_Declaration_Node (Proc)))
2563 then
2564 Append_Elmt (Proc, Intra_Procs);
2565 end if;
2566
2567 else
2568 -- No need for multiple entries of the same type
2569
2570 Elmt := First_Elmt (Inter_Procs);
2571 while Present (Elmt) loop
2572 if Node (Elmt) = Proc then
2573 return;
2574 end if;
2575
2576 Next_Elmt (Elmt);
2577 end loop;
2578
2579 Append_Elmt (Proc, Inter_Procs);
2580 end if;
2581 end if;
2582 end Add_Task_Proc;
2583
2584 -------------------
2585 -- Collect_Tasks --
2586 -------------------
2587
2588 procedure Collect_Tasks (Decls : List_Id) is
2589 begin
2590 if Present (Decls) then
2591 Decl := First (Decls);
2592 while Present (Decl) loop
2593 if Nkind (Decl) = N_Object_Declaration
2594 and then Has_Task (Etype (Defining_Identifier (Decl)))
2595 then
2596 Add_Task_Proc (Etype (Defining_Identifier (Decl)));
2597 end if;
2598
2599 Next (Decl);
2600 end loop;
2601 end if;
2602 end Collect_Tasks;
2603
2604 ----------------
2605 -- Outer_Unit --
2606 ----------------
2607
2608 function Outer_Unit (E : Entity_Id) return Entity_Id is
2609 Outer : Entity_Id;
2610
2611 begin
2612 Outer := E;
2613 while Present (Outer) loop
2614 if Elaboration_Checks_Suppressed (Outer) then
2615 Cunit_SC := True;
2616 end if;
2617
2618 exit when Is_Child_Unit (Outer)
2619 or else Scope (Outer) = Standard_Standard
2620 or else Ekind (Outer) /= E_Package;
2621 Outer := Scope (Outer);
2622 end loop;
2623
2624 return Outer;
2625 end Outer_Unit;
2626
2627 -- Start of processing for Check_Task_Activation
2628
2629 begin
2630 Enclosing := Outer_Unit (Current_Scope);
2631
2632 -- Find all tasks declared in the current unit
2633
2634 if Nkind (N) = N_Package_Body then
2635 P := Unit_Declaration_Node (Corresponding_Spec (N));
2636
2637 Collect_Tasks (Declarations (N));
2638 Collect_Tasks (Visible_Declarations (Specification (P)));
2639 Collect_Tasks (Private_Declarations (Specification (P)));
2640
2641 elsif Nkind (N) = N_Package_Declaration then
2642 Collect_Tasks (Visible_Declarations (Specification (N)));
2643 Collect_Tasks (Private_Declarations (Specification (N)));
2644
2645 else
2646 Collect_Tasks (Declarations (N));
2647 end if;
2648
2649 -- We only perform detailed checks in all tasks that are library level
2650 -- entities. If the master is a subprogram or task, activation will
2651 -- depend on the activation of the master itself.
2652
2653 -- Should dynamic checks be added in the more general case???
2654
2655 if Ekind (Enclosing) /= E_Package then
2656 return;
2657 end if;
2658
2659 -- For task types defined in other units, we want the unit containing
2660 -- the task body to be elaborated before the current one.
2661
2662 Elmt := First_Elmt (Inter_Procs);
2663 while Present (Elmt) loop
2664 Ent := Node (Elmt);
2665 Task_Scope := Outer_Unit (Scope (Ent));
2666
2667 if not Is_Compilation_Unit (Task_Scope) then
2668 null;
2669
2670 elsif Suppress_Elaboration_Warnings (Task_Scope)
2671 or else Elaboration_Checks_Suppressed (Task_Scope)
2672 then
2673 null;
2674
2675 elsif Dynamic_Elaboration_Checks then
2676 if not Elaboration_Checks_Suppressed (Ent)
2677 and then not Cunit_SC
2678 and then
2679 not Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
2680 then
2681 -- Runtime elaboration check required. Generate check of the
2682 -- elaboration counter for the unit containing the entity.
2683
2684 Insert_Elab_Check (N,
2685 Make_Attribute_Reference (Loc,
2686 Attribute_Name => Name_Elaborated,
2687 Prefix =>
2688 New_Occurrence_Of (Spec_Entity (Task_Scope), Loc)));
2689 end if;
2690
2691 else
2692 -- Force the binder to elaborate other unit first
2693
2694 if not Suppress_Elaboration_Warnings (Ent)
2695 and then not Elaboration_Checks_Suppressed (Ent)
2696 and then Elab_Info_Messages
2697 and then not Suppress_Elaboration_Warnings (Task_Scope)
2698 and then not Elaboration_Checks_Suppressed (Task_Scope)
2699 then
2700 Error_Msg_Node_2 := Task_Scope;
2701 Error_Msg_NE
2702 ("info: activation of an instance of task type&" &
2703 " requires pragma Elaborate_All on &?$?", N, Ent);
2704 end if;
2705
2706 Activate_Elaborate_All_Desirable (N, Task_Scope);
2707 Set_Suppress_Elaboration_Warnings (Task_Scope);
2708 end if;
2709
2710 Next_Elmt (Elmt);
2711 end loop;
2712
2713 -- For tasks declared in the current unit, trace other calls within
2714 -- the task procedure bodies, which are available.
2715
2716 In_Task_Activation := True;
2717
2718 Elmt := First_Elmt (Intra_Procs);
2719 while Present (Elmt) loop
2720 Ent := Node (Elmt);
2721 Check_Internal_Call_Continue (N, Ent, Enclosing, Ent);
2722 Next_Elmt (Elmt);
2723 end loop;
2724
2725 In_Task_Activation := False;
2726 end Check_Task_Activation;
2727
2728 -------------------------------
2729 -- Is_Call_Of_Generic_Formal --
2730 -------------------------------
2731
2732 function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean is
2733 begin
2734 return Nkind_In (N, N_Function_Call, N_Procedure_Call_Statement)
2735
2736 -- Always return False if debug flag -gnatd.G is set
2737
2738 and then not Debug_Flag_Dot_GG
2739
2740 -- For now, we detect this by looking for the strange identifier
2741 -- node, whose Chars reflect the name of the generic formal, but
2742 -- the Chars of the Entity references the generic actual.
2743
2744 and then Nkind (Name (N)) = N_Identifier
2745 and then Chars (Name (N)) /= Chars (Entity (Name (N)));
2746 end Is_Call_Of_Generic_Formal;
2747
2748 --------------------------------
2749 -- Set_Elaboration_Constraint --
2750 --------------------------------
2751
2752 procedure Set_Elaboration_Constraint
2753 (Call : Node_Id;
2754 Subp : Entity_Id;
2755 Scop : Entity_Id)
2756 is
2757 Elab_Unit : Entity_Id;
2758
2759 -- Check whether this is a call to an Initialize subprogram for a
2760 -- controlled type. Note that Call can also be a 'Access attribute
2761 -- reference, which now generates an elaboration check.
2762
2763 Init_Call : constant Boolean :=
2764 Nkind (Call) = N_Procedure_Call_Statement
2765 and then Chars (Subp) = Name_Initialize
2766 and then Comes_From_Source (Subp)
2767 and then Present (Parameter_Associations (Call))
2768 and then Is_Controlled (Etype (First_Actual (Call)));
2769 begin
2770 -- If the unit is mentioned in a with_clause of the current unit, it is
2771 -- visible, and we can set the elaboration flag.
2772
2773 if Is_Immediately_Visible (Scop)
2774 or else (Is_Child_Unit (Scop) and then Is_Visible_Lib_Unit (Scop))
2775 then
2776 Activate_Elaborate_All_Desirable (Call, Scop);
2777 Set_Suppress_Elaboration_Warnings (Scop, True);
2778 return;
2779 end if;
2780
2781 -- If this is not an initialization call or a call using object notation
2782 -- we know that the unit of the called entity is in the context, and
2783 -- we can set the flag as well. The unit need not be visible if the call
2784 -- occurs within an instantiation.
2785
2786 if Is_Init_Proc (Subp)
2787 or else Init_Call
2788 or else Nkind (Original_Node (Call)) = N_Selected_Component
2789 then
2790 null; -- detailed processing follows.
2791
2792 else
2793 Activate_Elaborate_All_Desirable (Call, Scop);
2794 Set_Suppress_Elaboration_Warnings (Scop, True);
2795 return;
2796 end if;
2797
2798 -- If the unit is not in the context, there must be an intermediate unit
2799 -- that is, on which we need to place to elaboration flag. This happens
2800 -- with init proc calls.
2801
2802 if Is_Init_Proc (Subp) or else Init_Call then
2803
2804 -- The initialization call is on an object whose type is not declared
2805 -- in the same scope as the subprogram. The type of the object must
2806 -- be a subtype of the type of operation. This object is the first
2807 -- actual in the call.
2808
2809 declare
2810 Typ : constant Entity_Id :=
2811 Etype (First (Parameter_Associations (Call)));
2812 begin
2813 Elab_Unit := Scope (Typ);
2814 while (Present (Elab_Unit))
2815 and then not Is_Compilation_Unit (Elab_Unit)
2816 loop
2817 Elab_Unit := Scope (Elab_Unit);
2818 end loop;
2819 end;
2820
2821 -- If original node uses selected component notation, the prefix is
2822 -- visible and determines the scope that must be elaborated. After
2823 -- rewriting, the prefix is the first actual in the call.
2824
2825 elsif Nkind (Original_Node (Call)) = N_Selected_Component then
2826 Elab_Unit := Scope (Etype (First (Parameter_Associations (Call))));
2827
2828 -- Not one of special cases above
2829
2830 else
2831 -- Using previously computed scope. If the elaboration check is
2832 -- done after analysis, the scope is not visible any longer, but
2833 -- must still be in the context.
2834
2835 Elab_Unit := Scop;
2836 end if;
2837
2838 Activate_Elaborate_All_Desirable (Call, Elab_Unit);
2839 Set_Suppress_Elaboration_Warnings (Elab_Unit, True);
2840 end Set_Elaboration_Constraint;
2841
2842 ------------------------
2843 -- Get_Referenced_Ent --
2844 ------------------------
2845
2846 function Get_Referenced_Ent (N : Node_Id) return Entity_Id is
2847 Nam : Node_Id;
2848
2849 begin
2850 if Nkind (N) in N_Has_Entity
2851 and then Present (Entity (N))
2852 and then Ekind (Entity (N)) = E_Variable
2853 then
2854 return Entity (N);
2855 end if;
2856
2857 if Nkind (N) = N_Attribute_Reference then
2858 Nam := Prefix (N);
2859 else
2860 Nam := Name (N);
2861 end if;
2862
2863 if No (Nam) then
2864 return Empty;
2865 elsif Nkind (Nam) = N_Selected_Component then
2866 return Entity (Selector_Name (Nam));
2867 elsif not Is_Entity_Name (Nam) then
2868 return Empty;
2869 else
2870 return Entity (Nam);
2871 end if;
2872 end Get_Referenced_Ent;
2873
2874 ----------------------
2875 -- Has_Generic_Body --
2876 ----------------------
2877
2878 function Has_Generic_Body (N : Node_Id) return Boolean is
2879 Ent : constant Entity_Id := Get_Generic_Entity (N);
2880 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
2881 Scop : Entity_Id;
2882
2883 function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id;
2884 -- Determine if the list of nodes headed by N and linked by Next
2885 -- contains a package body for the package spec entity E, and if so
2886 -- return the package body. If not, then returns Empty.
2887
2888 function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id;
2889 -- This procedure is called load the unit whose name is given by Nam.
2890 -- This unit is being loaded to see whether it contains an optional
2891 -- generic body. The returned value is the loaded unit, which is always
2892 -- a package body (only package bodies can contain other entities in the
2893 -- sense in which Has_Generic_Body is interested). We only attempt to
2894 -- load bodies if we are generating code. If we are in semantics check
2895 -- only mode, then it would be wrong to load bodies that are not
2896 -- required from a semantic point of view, so in this case we return
2897 -- Empty. The result is that the caller may incorrectly decide that a
2898 -- generic spec does not have a body when in fact it does, but the only
2899 -- harm in this is that some warnings on elaboration problems may be
2900 -- lost in semantic checks only mode, which is not big loss. We also
2901 -- return Empty if we go for a body and it is not there.
2902
2903 function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id;
2904 -- PE is the entity for a package spec. This function locates the
2905 -- corresponding package body, returning Empty if none is found. The
2906 -- package body returned is fully parsed but may not yet be analyzed,
2907 -- so only syntactic fields should be referenced.
2908
2909 ------------------
2910 -- Find_Body_In --
2911 ------------------
2912
2913 function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is
2914 Nod : Node_Id;
2915
2916 begin
2917 Nod := N;
2918 while Present (Nod) loop
2919
2920 -- If we found the package body we are looking for, return it
2921
2922 if Nkind (Nod) = N_Package_Body
2923 and then Chars (Defining_Unit_Name (Nod)) = Chars (E)
2924 then
2925 return Nod;
2926
2927 -- If we found the stub for the body, go after the subunit,
2928 -- loading it if necessary.
2929
2930 elsif Nkind (Nod) = N_Package_Body_Stub
2931 and then Chars (Defining_Identifier (Nod)) = Chars (E)
2932 then
2933 if Present (Library_Unit (Nod)) then
2934 return Unit (Library_Unit (Nod));
2935
2936 else
2937 return Load_Package_Body (Get_Unit_Name (Nod));
2938 end if;
2939
2940 -- If neither package body nor stub, keep looking on chain
2941
2942 else
2943 Next (Nod);
2944 end if;
2945 end loop;
2946
2947 return Empty;
2948 end Find_Body_In;
2949
2950 -----------------------
2951 -- Load_Package_Body --
2952 -----------------------
2953
2954 function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is
2955 U : Unit_Number_Type;
2956
2957 begin
2958 if Operating_Mode /= Generate_Code then
2959 return Empty;
2960 else
2961 U :=
2962 Load_Unit
2963 (Load_Name => Nam,
2964 Required => False,
2965 Subunit => False,
2966 Error_Node => N);
2967
2968 if U = No_Unit then
2969 return Empty;
2970 else
2971 return Unit (Cunit (U));
2972 end if;
2973 end if;
2974 end Load_Package_Body;
2975
2976 -------------------------------
2977 -- Locate_Corresponding_Body --
2978 -------------------------------
2979
2980 function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is
2981 Spec : constant Node_Id := Declaration_Node (PE);
2982 Decl : constant Node_Id := Parent (Spec);
2983 Scop : constant Entity_Id := Scope (PE);
2984 PBody : Node_Id;
2985
2986 begin
2987 if Is_Library_Level_Entity (PE) then
2988
2989 -- If package is a library unit that requires a body, we have no
2990 -- choice but to go after that body because it might contain an
2991 -- optional body for the original generic package.
2992
2993 if Unit_Requires_Body (PE) then
2994
2995 -- Load the body. Note that we are a little careful here to use
2996 -- Spec to get the unit number, rather than PE or Decl, since
2997 -- in the case where the package is itself a library level
2998 -- instantiation, Spec will properly reference the generic
2999 -- template, which is what we really want.
3000
3001 return
3002 Load_Package_Body
3003 (Get_Body_Name (Unit_Name (Get_Source_Unit (Spec))));
3004
3005 -- But if the package is a library unit that does NOT require
3006 -- a body, then no body is permitted, so we are sure that there
3007 -- is no body for the original generic package.
3008
3009 else
3010 return Empty;
3011 end if;
3012
3013 -- Otherwise look and see if we are embedded in a further package
3014
3015 elsif Is_Package_Or_Generic_Package (Scop) then
3016
3017 -- If so, get the body of the enclosing package, and look in
3018 -- its package body for the package body we are looking for.
3019
3020 PBody := Locate_Corresponding_Body (Scop);
3021
3022 if No (PBody) then
3023 return Empty;
3024 else
3025 return Find_Body_In (PE, First (Declarations (PBody)));
3026 end if;
3027
3028 -- If we are not embedded in a further package, then the body
3029 -- must be in the same declarative part as we are.
3030
3031 else
3032 return Find_Body_In (PE, Next (Decl));
3033 end if;
3034 end Locate_Corresponding_Body;
3035
3036 -- Start of processing for Has_Generic_Body
3037
3038 begin
3039 if Present (Corresponding_Body (Decl)) then
3040 return True;
3041
3042 elsif Unit_Requires_Body (Ent) then
3043 return True;
3044
3045 -- Compilation units cannot have optional bodies
3046
3047 elsif Is_Compilation_Unit (Ent) then
3048 return False;
3049
3050 -- Otherwise look at what scope we are in
3051
3052 else
3053 Scop := Scope (Ent);
3054
3055 -- Case of entity is in other than a package spec, in this case
3056 -- the body, if present, must be in the same declarative part.
3057
3058 if not Is_Package_Or_Generic_Package (Scop) then
3059 declare
3060 P : Node_Id;
3061
3062 begin
3063 -- Declaration node may get us a spec, so if so, go to
3064 -- the parent declaration.
3065
3066 P := Declaration_Node (Ent);
3067 while not Is_List_Member (P) loop
3068 P := Parent (P);
3069 end loop;
3070
3071 return Present (Find_Body_In (Ent, Next (P)));
3072 end;
3073
3074 -- If the entity is in a package spec, then we have to locate
3075 -- the corresponding package body, and look there.
3076
3077 else
3078 declare
3079 PBody : constant Node_Id := Locate_Corresponding_Body (Scop);
3080
3081 begin
3082 if No (PBody) then
3083 return False;
3084 else
3085 return
3086 Present
3087 (Find_Body_In (Ent, (First (Declarations (PBody)))));
3088 end if;
3089 end;
3090 end if;
3091 end if;
3092 end Has_Generic_Body;
3093
3094 -----------------------
3095 -- Insert_Elab_Check --
3096 -----------------------
3097
3098 procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is
3099 Nod : Node_Id;
3100 Loc : constant Source_Ptr := Sloc (N);
3101
3102 Chk : Node_Id;
3103 -- The check (N_Raise_Program_Error) node to be inserted
3104
3105 begin
3106 -- If expansion is disabled, do not generate any checks. Also
3107 -- skip checks if any subunits are missing because in either
3108 -- case we lack the full information that we need, and no object
3109 -- file will be created in any case.
3110
3111 if not Expander_Active or else Subunits_Missing then
3112 return;
3113 end if;
3114
3115 -- If we have a generic instantiation, where Instance_Spec is set,
3116 -- then this field points to a generic instance spec that has
3117 -- been inserted before the instantiation node itself, so that
3118 -- is where we want to insert a check.
3119
3120 if Nkind (N) in N_Generic_Instantiation
3121 and then Present (Instance_Spec (N))
3122 then
3123 Nod := Instance_Spec (N);
3124 else
3125 Nod := N;
3126 end if;
3127
3128 -- Build check node, possibly with condition
3129
3130 Chk :=
3131 Make_Raise_Program_Error (Loc, Reason => PE_Access_Before_Elaboration);
3132
3133 if Present (C) then
3134 Set_Condition (Chk, Make_Op_Not (Loc, Right_Opnd => C));
3135 end if;
3136
3137 -- If we are inserting at the top level, insert in Aux_Decls
3138
3139 if Nkind (Parent (Nod)) = N_Compilation_Unit then
3140 declare
3141 ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod));
3142
3143 begin
3144 if No (Declarations (ADN)) then
3145 Set_Declarations (ADN, New_List (Chk));
3146 else
3147 Append_To (Declarations (ADN), Chk);
3148 end if;
3149
3150 Analyze (Chk);
3151 end;
3152
3153 -- Otherwise just insert as an action on the node in question
3154
3155 else
3156 Insert_Action (Nod, Chk);
3157 end if;
3158 end Insert_Elab_Check;
3159
3160 -------------------------------
3161 -- Is_Finalization_Procedure --
3162 -------------------------------
3163
3164 function Is_Finalization_Procedure (Id : Entity_Id) return Boolean is
3165 begin
3166 -- Check whether Id is a procedure with at least one parameter
3167
3168 if Ekind (Id) = E_Procedure and then Present (First_Formal (Id)) then
3169 declare
3170 Typ : constant Entity_Id := Etype (First_Formal (Id));
3171 Deep_Fin : Entity_Id := Empty;
3172 Fin : Entity_Id := Empty;
3173
3174 begin
3175 -- If the type of the first formal does not require finalization
3176 -- actions, then this is definitely not [Deep_]Finalize.
3177
3178 if not Needs_Finalization (Typ) then
3179 return False;
3180 end if;
3181
3182 -- At this point we have the following scenario:
3183
3184 -- procedure Name (Param1 : [in] [out] Ctrl[; Param2 : ...]);
3185
3186 -- Recover the two possible versions of [Deep_]Finalize using the
3187 -- type of the first parameter and compare with the input.
3188
3189 Deep_Fin := TSS (Typ, TSS_Deep_Finalize);
3190
3191 if Is_Controlled (Typ) then
3192 Fin := Find_Prim_Op (Typ, Name_Finalize);
3193 end if;
3194
3195 return (Present (Deep_Fin) and then Id = Deep_Fin)
3196 or else (Present (Fin) and then Id = Fin);
3197 end;
3198 end if;
3199
3200 return False;
3201 end Is_Finalization_Procedure;
3202
3203 ------------------
3204 -- Output_Calls --
3205 ------------------
3206
3207 procedure Output_Calls
3208 (N : Node_Id;
3209 Check_Elab_Flag : Boolean)
3210 is
3211 function Emit (Flag : Boolean) return Boolean;
3212 -- Determine whether to emit an error message based on the combination
3213 -- of flags Check_Elab_Flag and Flag.
3214
3215 function Is_Printable_Error_Name (Nm : Name_Id) return Boolean;
3216 -- An internal function, used to determine if a name, Nm, is either
3217 -- a non-internal name, or is an internal name that is printable
3218 -- by the error message circuits (i.e. it has a single upper
3219 -- case letter at the end).
3220
3221 ----------
3222 -- Emit --
3223 ----------
3224
3225 function Emit (Flag : Boolean) return Boolean is
3226 begin
3227 if Check_Elab_Flag then
3228 return Flag;
3229 else
3230 return True;
3231 end if;
3232 end Emit;
3233
3234 -----------------------------
3235 -- Is_Printable_Error_Name --
3236 -----------------------------
3237
3238 function Is_Printable_Error_Name (Nm : Name_Id) return Boolean is
3239 begin
3240 if not Is_Internal_Name (Nm) then
3241 return True;
3242
3243 elsif Name_Len = 1 then
3244 return False;
3245
3246 else
3247 Name_Len := Name_Len - 1;
3248 return not Is_Internal_Name;
3249 end if;
3250 end Is_Printable_Error_Name;
3251
3252 -- Local variables
3253
3254 Ent : Entity_Id;
3255
3256 -- Start of processing for Output_Calls
3257
3258 begin
3259 for J in reverse 1 .. Elab_Call.Last loop
3260 Error_Msg_Sloc := Elab_Call.Table (J).Cloc;
3261
3262 Ent := Elab_Call.Table (J).Ent;
3263
3264 -- Dynamic elaboration model, warnings controlled by -gnatwl
3265
3266 if Dynamic_Elaboration_Checks then
3267 if Emit (Elab_Warnings) then
3268 if Is_Generic_Unit (Ent) then
3269 Error_Msg_NE ("\\?l?& instantiated #", N, Ent);
3270 elsif Is_Init_Proc (Ent) then
3271 Error_Msg_N ("\\?l?initialization procedure called #", N);
3272 elsif Is_Printable_Error_Name (Chars (Ent)) then
3273 Error_Msg_NE ("\\?l?& called #", N, Ent);
3274 else
3275 Error_Msg_N ("\\?l?called #", N);
3276 end if;
3277 end if;
3278
3279 -- Static elaboration model, info messages controlled by -gnatel
3280
3281 else
3282 if Emit (Elab_Info_Messages) then
3283 if Is_Generic_Unit (Ent) then
3284 Error_Msg_NE ("\\?$?& instantiated #", N, Ent);
3285 elsif Is_Init_Proc (Ent) then
3286 Error_Msg_N ("\\?$?initialization procedure called #", N);
3287 elsif Is_Printable_Error_Name (Chars (Ent)) then
3288 Error_Msg_NE ("\\?$?& called #", N, Ent);
3289 else
3290 Error_Msg_N ("\\?$?called #", N);
3291 end if;
3292 end if;
3293 end if;
3294 end loop;
3295 end Output_Calls;
3296
3297 ----------------------------
3298 -- Same_Elaboration_Scope --
3299 ----------------------------
3300
3301 function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is
3302 S1 : Entity_Id;
3303 S2 : Entity_Id;
3304
3305 begin
3306 -- Find elaboration scope for Scop1
3307 -- This is either a subprogram or a compilation unit.
3308
3309 S1 := Scop1;
3310 while S1 /= Standard_Standard
3311 and then not Is_Compilation_Unit (S1)
3312 and then Ekind_In (S1, E_Package, E_Protected_Type, E_Block)
3313 loop
3314 S1 := Scope (S1);
3315 end loop;
3316
3317 -- Find elaboration scope for Scop2
3318
3319 S2 := Scop2;
3320 while S2 /= Standard_Standard
3321 and then not Is_Compilation_Unit (S2)
3322 and then Ekind_In (S2, E_Package, E_Protected_Type, E_Block)
3323 loop
3324 S2 := Scope (S2);
3325 end loop;
3326
3327 return S1 = S2;
3328 end Same_Elaboration_Scope;
3329
3330 -----------------
3331 -- Set_C_Scope --
3332 -----------------
3333
3334 procedure Set_C_Scope is
3335 begin
3336 while not Is_Compilation_Unit (C_Scope) loop
3337 C_Scope := Scope (C_Scope);
3338 end loop;
3339 end Set_C_Scope;
3340
3341 -----------------
3342 -- Spec_Entity --
3343 -----------------
3344
3345 function Spec_Entity (E : Entity_Id) return Entity_Id is
3346 Decl : Node_Id;
3347
3348 begin
3349 -- Check for case of body entity
3350 -- Why is the check for E_Void needed???
3351
3352 if Ekind_In (E, E_Void, E_Subprogram_Body, E_Package_Body) then
3353 Decl := E;
3354
3355 loop
3356 Decl := Parent (Decl);
3357 exit when Nkind (Decl) in N_Proper_Body;
3358 end loop;
3359
3360 return Corresponding_Spec (Decl);
3361
3362 else
3363 return E;
3364 end if;
3365 end Spec_Entity;
3366
3367 -------------------
3368 -- Supply_Bodies --
3369 -------------------
3370
3371 procedure Supply_Bodies (N : Node_Id) is
3372 begin
3373 if Nkind (N) = N_Subprogram_Declaration then
3374 declare
3375 Ent : constant Entity_Id := Defining_Unit_Name (Specification (N));
3376
3377 begin
3378 -- Internal subprograms will already have a generated body, so
3379 -- there is no need to provide a stub for them.
3380
3381 if No (Corresponding_Body (N)) then
3382 declare
3383 Loc : constant Source_Ptr := Sloc (N);
3384 B : Node_Id;
3385 Formals : constant List_Id := Copy_Parameter_List (Ent);
3386 Nam : constant Entity_Id :=
3387 Make_Defining_Identifier (Loc, Chars (Ent));
3388 Spec : Node_Id;
3389 Stats : constant List_Id :=
3390 New_List
3391 (Make_Raise_Program_Error (Loc,
3392 Reason => PE_Access_Before_Elaboration));
3393
3394 begin
3395 if Ekind (Ent) = E_Function then
3396 Spec :=
3397 Make_Function_Specification (Loc,
3398 Defining_Unit_Name => Nam,
3399 Parameter_Specifications => Formals,
3400 Result_Definition =>
3401 New_Copy_Tree
3402 (Result_Definition (Specification (N))));
3403
3404 -- We cannot reliably make a return statement for this
3405 -- body, but none is needed because the call raises
3406 -- program error.
3407
3408 Set_Return_Present (Ent);
3409
3410 else
3411 Spec :=
3412 Make_Procedure_Specification (Loc,
3413 Defining_Unit_Name => Nam,
3414 Parameter_Specifications => Formals);
3415 end if;
3416
3417 B := Make_Subprogram_Body (Loc,
3418 Specification => Spec,
3419 Declarations => New_List,
3420 Handled_Statement_Sequence =>
3421 Make_Handled_Sequence_Of_Statements (Loc, Stats));
3422 Insert_After (N, B);
3423 Analyze (B);
3424 end;
3425 end if;
3426 end;
3427
3428 elsif Nkind (N) = N_Package_Declaration then
3429 declare
3430 Spec : constant Node_Id := Specification (N);
3431 begin
3432 Push_Scope (Defining_Unit_Name (Spec));
3433 Supply_Bodies (Visible_Declarations (Spec));
3434 Supply_Bodies (Private_Declarations (Spec));
3435 Pop_Scope;
3436 end;
3437 end if;
3438 end Supply_Bodies;
3439
3440 procedure Supply_Bodies (L : List_Id) is
3441 Elmt : Node_Id;
3442 begin
3443 if Present (L) then
3444 Elmt := First (L);
3445 while Present (Elmt) loop
3446 Supply_Bodies (Elmt);
3447 Next (Elmt);
3448 end loop;
3449 end if;
3450 end Supply_Bodies;
3451
3452 ------------
3453 -- Within --
3454 ------------
3455
3456 function Within (E1, E2 : Entity_Id) return Boolean is
3457 Scop : Entity_Id;
3458 begin
3459 Scop := E1;
3460 loop
3461 if Scop = E2 then
3462 return True;
3463 elsif Scop = Standard_Standard then
3464 return False;
3465 else
3466 Scop := Scope (Scop);
3467 end if;
3468 end loop;
3469 end Within;
3470
3471 --------------------------
3472 -- Within_Elaborate_All --
3473 --------------------------
3474
3475 function Within_Elaborate_All
3476 (Unit : Unit_Number_Type;
3477 E : Entity_Id) return Boolean
3478 is
3479 type Unit_Number_Set is array (Main_Unit .. Last_Unit) of Boolean;
3480 pragma Pack (Unit_Number_Set);
3481
3482 Seen : Unit_Number_Set := (others => False);
3483 -- Seen (X) is True after we have seen unit X in the walk. This is used
3484 -- to prevent processing the same unit more than once.
3485
3486 Result : Boolean := False;
3487
3488 procedure Helper (Unit : Unit_Number_Type);
3489 -- This helper procedure does all the work for Within_Elaborate_All. It
3490 -- walks the dependency graph, and sets Result to True if it finds an
3491 -- appropriate Elaborate_All.
3492
3493 ------------
3494 -- Helper --
3495 ------------
3496
3497 procedure Helper (Unit : Unit_Number_Type) is
3498 CU : constant Node_Id := Cunit (Unit);
3499
3500 Item : Node_Id;
3501 Item2 : Node_Id;
3502 Elab_Id : Entity_Id;
3503 Par : Node_Id;
3504
3505 begin
3506 if Seen (Unit) then
3507 return;
3508 else
3509 Seen (Unit) := True;
3510 end if;
3511
3512 -- First, check for Elaborate_Alls on this unit
3513
3514 Item := First (Context_Items (CU));
3515 while Present (Item) loop
3516 if Nkind (Item) = N_Pragma
3517 and then Pragma_Name (Item) = Name_Elaborate_All
3518 then
3519 -- Return if some previous error on the pragma itself. The
3520 -- pragma may be unanalyzed, because of a previous error, or
3521 -- if it is the context of a subunit, inherited by its parent.
3522
3523 if Error_Posted (Item) or else not Analyzed (Item) then
3524 return;
3525 end if;
3526
3527 Elab_Id :=
3528 Entity
3529 (Expression (First (Pragma_Argument_Associations (Item))));
3530
3531 if E = Elab_Id then
3532 Result := True;
3533 return;
3534 end if;
3535
3536 Par := Parent (Unit_Declaration_Node (Elab_Id));
3537
3538 Item2 := First (Context_Items (Par));
3539 while Present (Item2) loop
3540 if Nkind (Item2) = N_With_Clause
3541 and then Entity (Name (Item2)) = E
3542 and then not Limited_Present (Item2)
3543 then
3544 Result := True;
3545 return;
3546 end if;
3547
3548 Next (Item2);
3549 end loop;
3550 end if;
3551
3552 Next (Item);
3553 end loop;
3554
3555 -- Second, recurse on with's. We could do this as part of the above
3556 -- loop, but it's probably more efficient to have two loops, because
3557 -- the relevant Elaborate_All is likely to be on the initial unit. In
3558 -- other words, we're walking the with's breadth-first. This part is
3559 -- only necessary in the dynamic elaboration model.
3560
3561 if Dynamic_Elaboration_Checks then
3562 Item := First (Context_Items (CU));
3563 while Present (Item) loop
3564 if Nkind (Item) = N_With_Clause
3565 and then not Limited_Present (Item)
3566 then
3567 -- Note: the following call to Get_Cunit_Unit_Number does a
3568 -- linear search, which could be slow, but it's OK because
3569 -- we're about to give a warning anyway. Also, there might
3570 -- be hundreds of units, but not millions. If it turns out
3571 -- to be a problem, we could store the Get_Cunit_Unit_Number
3572 -- in each N_Compilation_Unit node, but that would involve
3573 -- rearranging N_Compilation_Unit_Aux to make room.
3574
3575 Helper (Get_Cunit_Unit_Number (Library_Unit (Item)));
3576
3577 if Result then
3578 return;
3579 end if;
3580 end if;
3581
3582 Next (Item);
3583 end loop;
3584 end if;
3585 end Helper;
3586
3587 -- Start of processing for Within_Elaborate_All
3588
3589 begin
3590 Helper (Unit);
3591 return Result;
3592 end Within_Elaborate_All;
3593
3594 end Sem_Elab;