Merged with mainline at revision 128810.
[official-gcc.git] / gcc / ada / sem_elab.adb
blobe3bd6897a1c73776f2803cfd1a64e3c5ccd07957
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-2007, 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 ------------------------------------------------------------------------------
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_Cat; use Sem_Cat;
47 with Sem_Ch7; use Sem_Ch7;
48 with Sem_Ch8; use Sem_Ch8;
49 with Sem_Res; use Sem_Res;
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 Uname; use Uname;
59 package body Sem_Elab is
61 -- The following table records the recursive call chain for output
62 -- in the Output routine. Each entry records the call node and the
63 -- entity of the called routine. The number of entries in the table
64 -- (i.e. the value of Elab_Call.Last) indicates the current depth
65 -- of recursion and is used to identify the outer level.
67 type Elab_Call_Entry is record
68 Cloc : Source_Ptr;
69 Ent : Entity_Id;
70 end record;
72 package Elab_Call is new Table.Table (
73 Table_Component_Type => Elab_Call_Entry,
74 Table_Index_Type => Int,
75 Table_Low_Bound => 1,
76 Table_Initial => 50,
77 Table_Increment => 100,
78 Table_Name => "Elab_Call");
80 -- This table is initialized at the start of each outer level call.
81 -- It holds the entities for all subprograms that have been examined
82 -- for this particular outer level call, and is used to prevent both
83 -- infinite recursion, and useless reanalysis of bodies already seen
85 package Elab_Visited is new Table.Table (
86 Table_Component_Type => Entity_Id,
87 Table_Index_Type => Int,
88 Table_Low_Bound => 1,
89 Table_Initial => 200,
90 Table_Increment => 100,
91 Table_Name => "Elab_Visited");
93 -- This table stores calls to Check_Internal_Call that are delayed
94 -- until all generics are instantiated, and in particular that all
95 -- generic bodies have been inserted. We need to delay, because we
96 -- need to be able to look through the inserted bodies.
98 type Delay_Element is record
99 N : Node_Id;
100 -- The parameter N from the call to Check_Internal_Call. Note that
101 -- this node may get rewritten over the delay period by expansion
102 -- in the call case (but not in the instantiation case).
104 E : Entity_Id;
105 -- The parameter E from the call to Check_Internal_Call
107 Orig_Ent : Entity_Id;
108 -- The parameter Orig_Ent from the call to Check_Internal_Call
110 Curscop : Entity_Id;
111 -- The current scope of the call. This is restored when we complete
112 -- the delayed call, so that we do this in the right scope.
114 From_Elab_Code : Boolean;
115 -- Save indication of whether this call is from elaboration code
117 Outer_Scope : Entity_Id;
118 -- Save scope of outer level call
119 end record;
121 package Delay_Check is new Table.Table (
122 Table_Component_Type => Delay_Element,
123 Table_Index_Type => Int,
124 Table_Low_Bound => 1,
125 Table_Initial => 1000,
126 Table_Increment => 100,
127 Table_Name => "Delay_Check");
129 C_Scope : Entity_Id;
130 -- Top level scope of current scope. We need to compute this only
131 -- once at the outer level, i.e. for a call to Check_Elab_Call from
132 -- outside this unit.
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.
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.
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.
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
153 -- called, the delay table is used to make the delayed calls and
154 -- this flag is reset to False, so that the calls are processed
156 -----------------------
157 -- Local Subprograms --
158 -----------------------
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.
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.
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 -- This is the internal recursive routine that is called to check for
181 -- a possible elaboration error. The argument N is a subprogram call
182 -- or generic instantiation to be checked, and E is the entity of
183 -- the called subprogram, or instantiated generic unit. The flag
184 -- Outer_Scope is the outer level scope for the original call.
185 -- Inter_Unit_Only is set if the call is only to be checked in the
186 -- case where it is to another unit (and skipped if within a unit).
187 -- Generate_Warnings is set to False to suppress warning messages
188 -- about missing pragma Elaborate_All's. These messages are not
189 -- wanted for inner calls in the dynamic model.
191 procedure Check_Bad_Instantiation (N : Node_Id);
192 -- N is a node for an instantiation (if called with any other node kind,
193 -- Check_Bad_Instantiation ignores the call). This subprogram checks for
194 -- the special case of a generic instantiation of a generic spec in the
195 -- same declarative part as the instantiation where a body is present and
196 -- has not yet been seen. This is an obvious error, but needs to be checked
197 -- specially at the time of the instantiation, since it is a case where we
198 -- cannot insert the body anywhere. If this case is detected, warnings are
199 -- generated, and a raise of Program_Error is inserted. In addition any
200 -- subprograms in the generic spec are stubbed, and the Bad_Instantiation
201 -- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
202 -- flag as an indication that no attempt should be made to insert an
203 -- instance body.
205 procedure Check_Internal_Call
206 (N : Node_Id;
207 E : Entity_Id;
208 Outer_Scope : Entity_Id;
209 Orig_Ent : Entity_Id);
210 -- N is a function call or procedure statement call node and E is
211 -- the entity of the called function, which is within the current
212 -- compilation unit (where subunits count as part of the parent).
213 -- This call checks if this call, or any call within any accessed
214 -- body could cause an ABE, and if so, outputs a warning. Orig_Ent
215 -- differs from E only in the case of renamings, and points to the
216 -- original name of the entity. This is used for error messages.
217 -- Outer_Scope is the outer level scope for the original call.
219 procedure Check_Internal_Call_Continue
220 (N : Node_Id;
221 E : Entity_Id;
222 Outer_Scope : Entity_Id;
223 Orig_Ent : Entity_Id);
224 -- The processing for Check_Internal_Call is divided up into two phases,
225 -- and this represents the second phase. The second phase is delayed if
226 -- Delaying_Elab_Calls is set to True. In this delayed case, the first
227 -- phase makes an entry in the Delay_Check table, which is processed
228 -- when Check_Elab_Calls is called. N, E and Orig_Ent are as for the call
229 -- to Check_Internal_Call. Outer_Scope is the outer level scope for
230 -- the original call.
232 procedure Set_Elaboration_Constraint
233 (Call : Node_Id;
234 Subp : Entity_Id;
235 Scop : Entity_Id);
236 -- The current unit U may depend semantically on some unit P which is not
237 -- in the current context. If there is an elaboration call that reaches P,
238 -- we need to indicate that P requires an Elaborate_All, but this is not
239 -- effective in U's ali file, if there is no with_clause for P. In this
240 -- case we add the Elaborate_All on the unit Q that directly or indirectly
241 -- makes P available. This can happen in two cases:
243 -- a) Q declares a subtype of a type declared in P, and the call is an
244 -- initialization call for an object of that subtype.
246 -- b) Q declares an object of some tagged type whose root type is
247 -- declared in P, and the initialization call uses object notation on
248 -- that object to reach a primitive operation or a classwide operation
249 -- declared in P.
251 -- If P appears in the context of U, the current processing is correct.
252 -- Otherwise we must identify these two cases to retrieve Q and place the
253 -- Elaborate_All_Desirable on it.
255 function Has_Generic_Body (N : Node_Id) return Boolean;
256 -- N is a generic package instantiation node, and this routine determines
257 -- if this package spec does in fact have a generic body. If so, then
258 -- True is returned, otherwise False. Note that this is not at all the
259 -- same as checking if the unit requires a body, since it deals with
260 -- the case of optional bodies accurately (i.e. if a body is optional,
261 -- then it looks to see if a body is actually present). Note: this
262 -- function can only do a fully correct job if in generating code mode
263 -- where all bodies have to be present. If we are operating in semantics
264 -- check only mode, then in some cases of optional bodies, a result of
265 -- False may incorrectly be given. In practice this simply means that
266 -- some cases of warnings for incorrect order of elaboration will only
267 -- be given when generating code, which is not a big problem (and is
268 -- inevitable, given the optional body semantics of Ada).
270 procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty);
271 -- Given code for an elaboration check (or unconditional raise if
272 -- the check is not needed), inserts the code in the appropriate
273 -- place. N is the call or instantiation node for which the check
274 -- code is required. C is the test whose failure triggers the raise.
276 procedure Output_Calls (N : Node_Id);
277 -- Outputs chain of calls stored in the Elab_Call table. The caller
278 -- has already generated the main warning message, so the warnings
279 -- generated are all continuation messages. The argument is the
280 -- call node at which the messages are to be placed.
282 function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean;
283 -- Given two scopes, determine whether they are the same scope from an
284 -- elaboration point of view, i.e. packages and blocks are ignored.
286 procedure Set_C_Scope;
287 -- On entry C_Scope is set to some scope. On return, C_Scope is reset
288 -- to be the enclosing compilation unit of this scope.
290 function Spec_Entity (E : Entity_Id) return Entity_Id;
291 -- Given a compilation unit entity, if it is a spec entity, it is
292 -- returned unchanged. If it is a body entity, then the spec for
293 -- the corresponding spec is returned
295 procedure Supply_Bodies (N : Node_Id);
296 -- Given a node, N, that is either a subprogram declaration or a package
297 -- declaration, this procedure supplies dummy bodies for the subprogram
298 -- or for all subprograms in the package. If the given node is not one
299 -- of these two possibilities, then Supply_Bodies does nothing. The
300 -- dummy body is supplied by setting the subprogram to be Imported with
301 -- convention Stubbed.
303 procedure Supply_Bodies (L : List_Id);
304 -- Calls Supply_Bodies for all elements of the given list L
306 function Within (E1, E2 : Entity_Id) return Boolean;
307 -- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one
308 -- of its contained scopes, False otherwise.
310 function Within_Elaborate_All (E : Entity_Id) return Boolean;
311 -- Before emitting a warning on a scope E for a missing elaborate_all,
312 -- check whether E may be in the context of a directly visible unit U to
313 -- which the pragma applies. This prevents spurious warnings when the
314 -- called entity is renamed within U.
316 --------------------------------------
317 -- Activate_Elaborate_All_Desirable --
318 --------------------------------------
320 procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id) is
321 UN : constant Unit_Number_Type := Get_Code_Unit (N);
322 CU : constant Node_Id := Cunit (UN);
323 UE : constant Entity_Id := Cunit_Entity (UN);
324 Unm : constant Unit_Name_Type := Unit_Name (UN);
325 CI : constant List_Id := Context_Items (CU);
326 Itm : Node_Id;
327 Ent : Entity_Id;
329 procedure Add_To_Context_And_Mark (Itm : Node_Id);
330 -- This procedure is called when the elaborate indication must be
331 -- applied to a unit not in the context of the referencing unit. The
332 -- unit gets added to the context as an implicit with.
334 function In_Withs_Of (UEs : Entity_Id) return Boolean;
335 -- UEs is the spec entity of a unit. If the unit to be marked is
336 -- in the context item list of this unit spec, then the call returns
337 -- True and Itm is left set to point to the relevant N_With_Clause node.
339 procedure Set_Elab_Flag (Itm : Node_Id);
340 -- Sets Elaborate_[All_]Desirable as appropriate on Itm
342 -----------------------------
343 -- Add_To_Context_And_Mark --
344 -----------------------------
346 procedure Add_To_Context_And_Mark (Itm : Node_Id) is
347 CW : constant Node_Id :=
348 Make_With_Clause (Sloc (Itm),
349 Name => Name (Itm));
351 begin
352 Set_Library_Unit (CW, Library_Unit (Itm));
353 Set_Implicit_With (CW, True);
355 -- Set elaborate all desirable on copy and then append the copy to
356 -- the list of body with's and we are done.
358 Set_Elab_Flag (CW);
359 Append_To (CI, CW);
360 end Add_To_Context_And_Mark;
362 -----------------
363 -- In_Withs_Of --
364 -----------------
366 function In_Withs_Of (UEs : Entity_Id) return Boolean is
367 UNs : constant Unit_Number_Type := Get_Source_Unit (UEs);
368 CUs : constant Node_Id := Cunit (UNs);
369 CIs : constant List_Id := Context_Items (CUs);
371 begin
372 Itm := First (CIs);
373 while Present (Itm) loop
374 if Nkind (Itm) = N_With_Clause then
375 Ent :=
376 Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
378 if U = Ent then
379 return True;
380 end if;
381 end if;
383 Next (Itm);
384 end loop;
386 return False;
387 end In_Withs_Of;
389 -------------------
390 -- Set_Elab_Flag --
391 -------------------
393 procedure Set_Elab_Flag (Itm : Node_Id) is
394 begin
395 if Nkind (N) in N_Subprogram_Instantiation then
396 Set_Elaborate_Desirable (Itm);
397 else
398 Set_Elaborate_All_Desirable (Itm);
399 end if;
400 end Set_Elab_Flag;
402 -- Start of processing for Activate_Elaborate_All_Desirable
404 begin
405 -- Do not set binder indication if expansion is disabled, as when
406 -- compiling a generic unit.
408 if not Expander_Active then
409 return;
410 end if;
412 Itm := First (CI);
413 while Present (Itm) loop
414 if Nkind (Itm) = N_With_Clause then
415 Ent := Cunit_Entity (Get_Cunit_Unit_Number (Library_Unit (Itm)));
417 -- If we find it, then mark elaborate all desirable and return
419 if U = Ent then
420 Set_Elab_Flag (Itm);
421 return;
422 end if;
423 end if;
425 Next (Itm);
426 end loop;
428 -- If we fall through then the with clause is not present in the
429 -- current unit. One legitimate possibility is that the with clause
430 -- is present in the spec when we are a body.
432 if Is_Body_Name (Unm)
433 and then In_Withs_Of (Spec_Entity (UE))
434 then
435 Add_To_Context_And_Mark (Itm);
436 return;
437 end if;
439 -- Similarly, we may be in the spec or body of a child unit, where
440 -- the unit in question is with'ed by some ancestor of the child unit.
442 if Is_Child_Name (Unm) then
443 declare
444 Pkg : Entity_Id;
446 begin
447 Pkg := UE;
448 loop
449 Pkg := Scope (Pkg);
450 exit when Pkg = Standard_Standard;
452 if In_Withs_Of (Pkg) then
453 Add_To_Context_And_Mark (Itm);
454 return;
455 end if;
456 end loop;
457 end;
458 end if;
460 -- Here if we do not find with clause on spec or body. We just ignore
461 -- this case, it means that the elaboration involves some other unit
462 -- than the unit being compiled, and will be caught elsewhere.
464 null;
465 end Activate_Elaborate_All_Desirable;
467 ------------------
468 -- Check_A_Call --
469 ------------------
471 procedure Check_A_Call
472 (N : Node_Id;
473 E : Entity_Id;
474 Outer_Scope : Entity_Id;
475 Inter_Unit_Only : Boolean;
476 Generate_Warnings : Boolean := True)
478 Loc : constant Source_Ptr := Sloc (N);
479 Ent : Entity_Id;
480 Decl : Node_Id;
482 E_Scope : Entity_Id;
483 -- Top level scope of entity for called subprogram. This
484 -- value includes following renamings and derivations, so
485 -- this scope can be in a non-visible unit. This is the
486 -- scope that is to be investigated to see whether an
487 -- elaboration check is required.
489 W_Scope : Entity_Id;
490 -- Top level scope of directly called entity for subprogram. This
491 -- differs from E_Scope in the case where renamings or derivations
492 -- are involved, since it does not follow these links. W_Scope is
493 -- generally in a visible unit, and it is this scope that may require
494 -- an Elaborate_All. However, there are some cases (initialization
495 -- calls and calls involving object notation) where W_Scope might not
496 -- be in the context of the current unit, and there is an intermediate
497 -- package that is, in which case the Elaborate_All has to be placed
498 -- on this intedermediate package. These special cases are handled in
499 -- Set_Elaboration_Constraint.
501 Body_Acts_As_Spec : Boolean;
502 -- Set to true if call is to body acting as spec (no separate spec)
504 Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
505 -- Indicates if we have instantiation case
507 Caller_Unit_Internal : Boolean;
508 Callee_Unit_Internal : Boolean;
510 Inst_Caller : Source_Ptr;
511 Inst_Callee : Source_Ptr;
513 Unit_Caller : Unit_Number_Type;
514 Unit_Callee : Unit_Number_Type;
516 Cunit_SC : Boolean := False;
517 -- Set to suppress dynamic elaboration checks where one of the
518 -- enclosing scopes has Elaboration_Checks_Suppressed set, or else
519 -- if a pragma Elaborate (_All) applies to that scope, in which case
520 -- warnings on the scope are also suppressed. For the internal case,
521 -- we ignore this flag.
523 begin
524 -- If the call is known to be within a local Suppress Elaboration
525 -- pragma, nothing to check. This can happen in task bodies.
527 if (Nkind (N) = N_Function_Call
528 or else Nkind (N) = N_Procedure_Call_Statement)
529 and then No_Elaboration_Check (N)
530 then
531 return;
532 end if;
534 -- Go to parent for derived subprogram, or to original subprogram
535 -- in the case of a renaming (Alias covers both these cases)
537 Ent := E;
538 loop
539 if (Suppress_Elaboration_Warnings (Ent)
540 or else Elaboration_Checks_Suppressed (Ent))
541 and then (Inst_Case or else No (Alias (Ent)))
542 then
543 return;
544 end if;
546 -- Nothing to do for imported entities
548 if Is_Imported (Ent) then
549 return;
550 end if;
552 exit when Inst_Case or else No (Alias (Ent));
553 Ent := Alias (Ent);
554 end loop;
556 Decl := Unit_Declaration_Node (Ent);
558 if Nkind (Decl) = N_Subprogram_Body then
559 Body_Acts_As_Spec := True;
561 elsif Nkind (Decl) = N_Subprogram_Declaration
562 or else Nkind (Decl) = N_Subprogram_Body_Stub
563 or else Inst_Case
564 then
565 Body_Acts_As_Spec := False;
567 -- If we have none of an instantiation, subprogram body or
568 -- subprogram declaration, then it is not a case that we want
569 -- to check. (One case is a call to a generic formal subprogram,
570 -- where we do not want the check in the template).
572 else
573 return;
574 end if;
576 E_Scope := Ent;
577 loop
578 if Elaboration_Checks_Suppressed (E_Scope)
579 or else Suppress_Elaboration_Warnings (E_Scope)
580 then
581 Cunit_SC := True;
582 end if;
584 -- Exit when we get to compilation unit, not counting subunits
586 exit when Is_Compilation_Unit (E_Scope)
587 and then (Is_Child_Unit (E_Scope)
588 or else Scope (E_Scope) = Standard_Standard);
590 -- If we did not find a compilation unit, other than standard,
591 -- then nothing to check (happens in some instantiation cases)
593 if E_Scope = Standard_Standard then
594 return;
596 -- Otherwise move up a scope looking for compilation unit
598 else
599 E_Scope := Scope (E_Scope);
600 end if;
601 end loop;
603 -- No checks needed for pure or preelaborated compilation units
605 if Is_Pure (E_Scope)
606 or else Is_Preelaborated (E_Scope)
607 then
608 return;
609 end if;
611 -- If the generic entity is within a deeper instance than we are, then
612 -- either the instantiation to which we refer itself caused an ABE, in
613 -- which case that will be handled separately, or else we know that the
614 -- body we need appears as needed at the point of the instantiation.
615 -- However, this assumption is only valid if we are in static mode.
617 if not Dynamic_Elaboration_Checks
618 and then Instantiation_Depth (Sloc (Ent)) >
619 Instantiation_Depth (Sloc (N))
620 then
621 return;
622 end if;
624 -- Do not give a warning for a package with no body
626 if Ekind (Ent) = E_Generic_Package
627 and then not Has_Generic_Body (N)
628 then
629 return;
630 end if;
632 -- Case of entity is not in current unit (i.e. with'ed unit case)
634 if E_Scope /= C_Scope then
636 -- We are only interested in such calls if the outer call was from
637 -- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
639 if not From_Elab_Code and then not Dynamic_Elaboration_Checks then
640 return;
641 end if;
643 -- Nothing to do if some scope said that no checks were required
645 if Cunit_SC then
646 return;
647 end if;
649 -- Nothing to do for a generic instance, because in this case
650 -- the checking was at the point of instantiation of the generic
651 -- However, this shortcut is only applicable in static mode.
653 if Is_Generic_Instance (Ent) and not Dynamic_Elaboration_Checks then
654 return;
655 end if;
657 -- Nothing to do if subprogram with no separate spec. However,
658 -- a call to Deep_Initialize may result in a call to a user-defined
659 -- Initialize procedure, which imposes a body dependency. This
660 -- happens only if the type is controlled and the Initialize
661 -- procedure is not inherited.
663 if Body_Acts_As_Spec then
664 if Is_TSS (Ent, TSS_Deep_Initialize) then
665 declare
666 Typ : Entity_Id;
667 Init : Entity_Id;
668 begin
669 Typ := Etype (Next_Formal (First_Formal (Ent)));
671 if not Is_Controlled (Typ) then
672 return;
673 else
674 Init := Find_Prim_Op (Typ, Name_Initialize);
676 if Comes_From_Source (Init) then
677 Ent := Init;
678 else
679 return;
680 end if;
681 end if;
682 end;
684 else
685 return;
686 end if;
687 end if;
689 -- Check cases of internal units
691 Callee_Unit_Internal :=
692 Is_Internal_File_Name
693 (Unit_File_Name (Get_Source_Unit (E_Scope)));
695 -- Do not give a warning if the with'ed unit is internal
696 -- and this is the generic instantiation case (this saves a
697 -- lot of hassle dealing with the Text_IO special child units)
699 if Callee_Unit_Internal and Inst_Case then
700 return;
701 end if;
703 if C_Scope = Standard_Standard then
704 Caller_Unit_Internal := False;
705 else
706 Caller_Unit_Internal :=
707 Is_Internal_File_Name
708 (Unit_File_Name (Get_Source_Unit (C_Scope)));
709 end if;
711 -- Do not give a warning if the with'ed unit is internal
712 -- and the caller is not internal (since the binder always
713 -- elaborates internal units first).
715 if Callee_Unit_Internal and (not Caller_Unit_Internal) then
716 return;
717 end if;
719 -- For now, if debug flag -gnatdE is not set, do no checking for
720 -- one internal unit withing another. This fixes the problem with
721 -- the sgi build and storage errors. To be resolved later ???
723 if (Callee_Unit_Internal and Caller_Unit_Internal)
724 and then not Debug_Flag_EE
725 then
726 return;
727 end if;
729 if Is_TSS (E, TSS_Deep_Initialize) then
730 Ent := E;
731 end if;
733 -- If the call is in an instance, and the called entity is not
734 -- defined in the same instance, then the elaboration issue
735 -- focuses around the unit containing the template, it is
736 -- this unit which requires an Elaborate_All.
738 -- However, if we are doing dynamic elaboration, we need to
739 -- chase the call in the usual manner.
741 -- We do not handle the case of calling a generic formal correctly
742 -- in the static case. See test 4703-004 to explore this gap ???
744 Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N)));
745 Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent)));
747 if Inst_Caller = No_Location then
748 Unit_Caller := No_Unit;
749 else
750 Unit_Caller := Get_Source_Unit (N);
751 end if;
753 if Inst_Callee = No_Location then
754 Unit_Callee := No_Unit;
755 else
756 Unit_Callee := Get_Source_Unit (Ent);
757 end if;
759 if Unit_Caller /= No_Unit
760 and then Unit_Callee /= Unit_Caller
761 and then not Dynamic_Elaboration_Checks
762 then
763 E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller));
765 -- If we don't get a spec entity, just ignore call. Not
766 -- quite clear why this check is necessary.
768 if No (E_Scope) then
769 return;
770 end if;
772 -- Otherwise step to enclosing compilation unit
774 while not Is_Compilation_Unit (E_Scope) loop
775 E_Scope := Scope (E_Scope);
776 end loop;
778 -- For the case N is not an instance, or a call within instance
779 -- We recompute E_Scope for the error message, since we
780 -- do NOT want to go to the unit which has the ultimate
781 -- declaration in the case of renaming and derivation and
782 -- we also want to go to the generic unit in the case of
783 -- an instance, and no further.
785 else
786 -- Loop to carefully follow renamings and derivations
787 -- one step outside the current unit, but not further.
789 if not Inst_Case
790 and then Present (Alias (Ent))
791 then
792 E_Scope := Alias (Ent);
793 else
794 E_Scope := Ent;
795 end if;
797 loop
798 while not Is_Compilation_Unit (E_Scope) loop
799 E_Scope := Scope (E_Scope);
800 end loop;
802 -- If E_Scope is the same as C_Scope, it means that there
803 -- definitely was a local renaming or derivation, and we
804 -- are not yet out of the current unit.
806 exit when E_Scope /= C_Scope;
807 Ent := Alias (Ent);
808 E_Scope := Ent;
810 -- If no alias, there is a previous error
812 if No (Ent) then
813 return;
814 end if;
815 end loop;
816 end if;
818 if Within_Elaborate_All (E_Scope) then
819 return;
820 end if;
822 -- Find top level scope for called entity (not following renamings
823 -- or derivations). This is where the Elaborate_All will go if it
824 -- is needed. We start with the called entity, except in the case
825 -- of an initialization procedure outside the current package, where
826 -- the init proc is in the root package, and we start from the entity
827 -- of the name in the call.
829 if Is_Entity_Name (Name (N))
830 and then Is_Init_Proc (Entity (Name (N)))
831 and then not In_Same_Extended_Unit (N, Entity (Name (N)))
832 then
833 W_Scope := Scope (Entity (Name (N)));
834 else
835 W_Scope := E;
836 end if;
838 while not Is_Compilation_Unit (W_Scope) loop
839 W_Scope := Scope (W_Scope);
840 end loop;
842 -- Now check if an elaborate_all (or dynamic check) is needed
844 if not Suppress_Elaboration_Warnings (Ent)
845 and then not Elaboration_Checks_Suppressed (Ent)
846 and then not Suppress_Elaboration_Warnings (E_Scope)
847 and then not Elaboration_Checks_Suppressed (E_Scope)
848 and then Elab_Warnings
849 and then Generate_Warnings
850 then
851 Generate_Elab_Warnings : declare
852 procedure Elab_Warning
853 (Msg_D : String;
854 Msg_S : String;
855 Ent : Node_Or_Entity_Id);
856 -- Generate a call to Error_Msg_NE with parameters Msg_D or
857 -- Msg_S (for dynamic or static elaboration model), N and Ent.
859 ------------------
860 -- Elab_Warning --
861 ------------------
863 procedure Elab_Warning
864 (Msg_D : String;
865 Msg_S : String;
866 Ent : Node_Or_Entity_Id)
868 begin
869 if Dynamic_Elaboration_Checks then
870 Error_Msg_NE (Msg_D, N, Ent);
871 else
872 Error_Msg_NE (Msg_S, N, Ent);
873 end if;
874 end Elab_Warning;
876 -- Start of processing for Generate_Elab_Warnings
878 begin
879 if Inst_Case then
880 Elab_Warning
881 ("instantiation of& may raise Program_Error?",
882 "instantiation of& during elaboration?", Ent);
884 else
885 if Nkind (Name (N)) in N_Has_Entity
886 and then Is_Init_Proc (Entity (Name (N)))
887 and then Comes_From_Source (Ent)
888 then
889 Elab_Warning
890 ("implicit call to & may raise Program_Error?",
891 "implicit call to & during elaboration?",
892 Ent);
894 else
895 Elab_Warning
896 ("call to & may raise Program_Error?",
897 "call to & during elaboration?",
898 Ent);
899 end if;
900 end if;
902 Error_Msg_Qual_Level := Nat'Last;
904 if Nkind (N) in N_Subprogram_Instantiation then
905 Elab_Warning
906 ("\missing pragma Elaborate for&?",
907 "\implicit pragma Elaborate for& generated?",
908 W_Scope);
909 else
910 Elab_Warning
911 ("\missing pragma Elaborate_All for&?",
912 "\implicit pragma Elaborate_All for & generated?",
913 W_Scope);
914 end if;
915 end Generate_Elab_Warnings;
917 Error_Msg_Qual_Level := 0;
918 Output_Calls (N);
920 -- Set flag to prevent further warnings for same unit unless in
921 -- All_Errors_Mode.
923 if not All_Errors_Mode and not Dynamic_Elaboration_Checks then
924 Set_Suppress_Elaboration_Warnings (W_Scope, True);
925 end if;
926 end if;
928 -- Check for runtime elaboration check required
930 if Dynamic_Elaboration_Checks then
931 if not Elaboration_Checks_Suppressed (Ent)
932 and then not Elaboration_Checks_Suppressed (W_Scope)
933 and then not Elaboration_Checks_Suppressed (E_Scope)
934 and then not Cunit_SC
935 then
936 -- Runtime elaboration check required. Generate check of the
937 -- elaboration Boolean for the unit containing the entity.
939 -- Note that for this case, we do check the real unit (the
940 -- one from following renamings, since that is the issue!)
942 -- Could this possibly miss a useless but required PE???
944 Insert_Elab_Check (N,
945 Make_Attribute_Reference (Loc,
946 Attribute_Name => Name_Elaborated,
947 Prefix =>
948 New_Occurrence_Of
949 (Spec_Entity (E_Scope), Loc)));
950 end if;
952 -- Case of static elaboration model
954 else
955 -- Do not do anything if elaboration checks suppressed. Note
956 -- that we check Ent here, not E, since we want the real entity
957 -- for the body to see if checks are suppressed for it, not the
958 -- dummy entry for renamings or derivations.
960 if Elaboration_Checks_Suppressed (Ent)
961 or else Elaboration_Checks_Suppressed (E_Scope)
962 or else Elaboration_Checks_Suppressed (W_Scope)
963 then
964 null;
966 -- Here we need to generate an implicit elaborate all
968 else
969 -- Generate elaborate_all warning unless suppressed
971 if (Elab_Warnings and Generate_Warnings and not Inst_Case)
972 and then not Suppress_Elaboration_Warnings (Ent)
973 and then not Suppress_Elaboration_Warnings (E_Scope)
974 and then not Suppress_Elaboration_Warnings (W_Scope)
975 then
976 Error_Msg_Node_2 := W_Scope;
977 Error_Msg_NE
978 ("call to& in elaboration code " &
979 "requires pragma Elaborate_All on&?", N, E);
980 end if;
982 -- Set indication for binder to generate Elaborate_All
984 Set_Elaboration_Constraint (N, E, W_Scope);
985 end if;
986 end if;
988 -- Case of entity is in same unit as call or instantiation
990 elsif not Inter_Unit_Only then
991 Check_Internal_Call (N, Ent, Outer_Scope, E);
992 end if;
993 end Check_A_Call;
995 -----------------------------
996 -- Check_Bad_Instantiation --
997 -----------------------------
999 procedure Check_Bad_Instantiation (N : Node_Id) is
1000 Ent : Entity_Id;
1002 begin
1003 -- Nothing to do if we do not have an instantiation (happens in some
1004 -- error cases, and also in the formal package declaration case)
1006 if Nkind (N) not in N_Generic_Instantiation then
1007 return;
1009 -- Nothing to do if serious errors detected (avoid cascaded errors)
1011 elsif Serious_Errors_Detected /= 0 then
1012 return;
1014 -- Nothing to do if not in full analysis mode
1016 elsif not Full_Analysis then
1017 return;
1019 -- Nothing to do if inside a generic template
1021 elsif Inside_A_Generic then
1022 return;
1024 -- Nothing to do if a library level instantiation
1026 elsif Nkind (Parent (N)) = N_Compilation_Unit then
1027 return;
1029 -- Nothing to do if we are compiling a proper body for semantic
1030 -- purposes only. The generic body may be in another proper body.
1032 elsif
1033 Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit
1034 then
1035 return;
1036 end if;
1038 Ent := Get_Generic_Entity (N);
1040 -- The case we are interested in is when the generic spec is in the
1041 -- current declarative part
1043 if not Same_Elaboration_Scope (Current_Scope, Scope (Ent))
1044 or else not In_Same_Extended_Unit (N, Ent)
1045 then
1046 return;
1047 end if;
1049 -- If the generic entity is within a deeper instance than we are, then
1050 -- either the instantiation to which we refer itself caused an ABE, in
1051 -- which case that will be handled separately. Otherwise, we know that
1052 -- the body we need appears as needed at the point of the instantiation.
1053 -- If they are both at the same level but not within the same instance
1054 -- then the body of the generic will be in the earlier instance.
1056 declare
1057 D1 : constant Int := Instantiation_Depth (Sloc (Ent));
1058 D2 : constant Int := Instantiation_Depth (Sloc (N));
1060 begin
1061 if D1 > D2 then
1062 return;
1064 elsif D1 = D2
1065 and then Is_Generic_Instance (Scope (Ent))
1066 and then not In_Open_Scopes (Scope (Ent))
1067 then
1068 return;
1069 end if;
1070 end;
1072 -- Now we can proceed, if the entity being called has a completion,
1073 -- then we are definitely OK, since we have already seen the body.
1075 if Has_Completion (Ent) then
1076 return;
1077 end if;
1079 -- If there is no body, then nothing to do
1081 if not Has_Generic_Body (N) then
1082 return;
1083 end if;
1085 -- Here we definitely have a bad instantiation
1087 Error_Msg_NE
1088 ("?cannot instantiate& before body seen", N, Ent);
1090 if Present (Instance_Spec (N)) then
1091 Supply_Bodies (Instance_Spec (N));
1092 end if;
1094 Error_Msg_N
1095 ("\?Program_Error will be raised at run time", N);
1096 Insert_Elab_Check (N);
1097 Set_ABE_Is_Certain (N);
1098 end Check_Bad_Instantiation;
1100 ---------------------
1101 -- Check_Elab_Call --
1102 ---------------------
1104 procedure Check_Elab_Call
1105 (N : Node_Id;
1106 Outer_Scope : Entity_Id := Empty)
1108 Ent : Entity_Id;
1109 P : Node_Id;
1111 function Get_Called_Ent return Entity_Id;
1112 -- Retrieve called entity. If this is a call to a protected subprogram,
1113 -- entity is a selected component. The callable entity may be absent,
1114 -- in which case there is no check to perform. This happens with
1115 -- non-analyzed calls in nested generics.
1117 --------------------
1118 -- Get_Called_Ent --
1119 --------------------
1121 function Get_Called_Ent return Entity_Id is
1122 Nam : Node_Id;
1124 begin
1125 Nam := Name (N);
1127 if No (Nam) then
1128 return Empty;
1130 elsif Nkind (Nam) = N_Selected_Component then
1131 return Entity (Selector_Name (Nam));
1133 elsif not Is_Entity_Name (Nam) then
1134 return Empty;
1136 else
1137 return Entity (Nam);
1138 end if;
1139 end Get_Called_Ent;
1141 -- Start of processing for Check_Elab_Call
1143 begin
1144 -- If the call does not come from the main unit, there is nothing to
1145 -- check. Elaboration call from units in the context of the main unit
1146 -- will lead to semantic dependencies when those units are compiled.
1148 if not In_Extended_Main_Code_Unit (N) then
1149 return;
1150 end if;
1152 -- For an entry call, check relevant restriction
1154 if Nkind (N) = N_Entry_Call_Statement
1155 and then not In_Subprogram_Or_Concurrent_Unit
1156 then
1157 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N);
1159 -- Nothing to do if this is not a call (happens in some error
1160 -- conditions, and in some cases where rewriting occurs).
1162 elsif Nkind (N) /= N_Function_Call
1163 and then Nkind (N) /= N_Procedure_Call_Statement
1164 then
1165 return;
1167 -- Nothing to do if this is a call already rewritten for elab checking
1169 elsif Nkind (Parent (N)) = N_Conditional_Expression then
1170 return;
1172 -- Nothing to do if inside a generic template
1174 elsif Inside_A_Generic
1175 and then No (Enclosing_Generic_Body (N))
1176 then
1177 return;
1178 end if;
1180 -- Here we have a call at elaboration time which must be checked
1182 if Debug_Flag_LL then
1183 Write_Str (" Check_Elab_Call: ");
1185 if No (Name (N))
1186 or else not Is_Entity_Name (Name (N))
1187 then
1188 Write_Str ("<<not entity name>> ");
1189 else
1190 Write_Name (Chars (Entity (Name (N))));
1191 end if;
1193 Write_Str (" call at ");
1194 Write_Location (Sloc (N));
1195 Write_Eol;
1196 end if;
1198 -- Climb up the tree to make sure we are not inside default expression
1199 -- of a parameter specification or a record component, since in both
1200 -- these cases, we will be doing the actual call later, not now, and it
1201 -- is at the time of the actual call (statically speaking) that we must
1202 -- do our static check, not at the time of its initial analysis).
1204 -- However, we have to check calls within component definitions (e.g., a
1205 -- function call that determines an array component bound), so we
1206 -- terminate the loop in that case.
1208 P := Parent (N);
1209 while Present (P) loop
1210 if Nkind (P) = N_Parameter_Specification
1211 or else
1212 Nkind (P) = N_Component_Declaration
1213 then
1214 return;
1216 -- The call occurs within the constraint of a component,
1217 -- so it must be checked.
1219 elsif Nkind (P) = N_Component_Definition then
1220 exit;
1222 else
1223 P := Parent (P);
1224 end if;
1225 end loop;
1227 -- Stuff that happens only at the outer level
1229 if No (Outer_Scope) then
1230 Elab_Visited.Set_Last (0);
1232 -- Nothing to do if current scope is Standard (this is a bit
1233 -- odd, but it happens in the case of generic instantiations).
1235 C_Scope := Current_Scope;
1237 if C_Scope = Standard_Standard then
1238 return;
1239 end if;
1241 -- First case, we are in elaboration code
1243 From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
1244 if From_Elab_Code then
1246 -- Complain if call that comes from source in preelaborated
1247 -- unit and we are not inside a subprogram (i.e. we are in
1248 -- elab code)
1250 if Comes_From_Source (N)
1251 and then In_Preelaborated_Unit
1252 and then not In_Inlined_Body
1253 then
1254 -- This is a warning in GNAT mode allowing such calls to be
1255 -- used in the predefined library with appropriate care.
1257 Error_Msg_Warn := GNAT_Mode;
1258 Error_Msg_N
1259 ("<non-static call not allowed in preelaborated unit", N);
1260 return;
1261 end if;
1263 -- Second case, we are inside a subprogram or concurrent unit, which
1264 -- means we are not in elaboration code.
1266 else
1267 -- In this case, the issue is whether we are inside the
1268 -- declarative part of the unit in which we live, or inside its
1269 -- statements. In the latter case, there is no issue of ABE calls
1270 -- at this level (a call from outside to the unit in which we live
1271 -- might cause an ABE, but that will be detected when we analyze
1272 -- that outer level call, as it recurses into the called unit).
1274 -- Climb up the tree, doing this test, and also testing for being
1275 -- inside a default expression, which, as discussed above, is not
1276 -- checked at this stage.
1278 declare
1279 P : Node_Id;
1280 L : List_Id;
1282 begin
1283 P := N;
1284 loop
1285 -- If we find a parentless subtree, it seems safe to assume
1286 -- that we are not in a declarative part and that no
1287 -- checking is required.
1289 if No (P) then
1290 return;
1291 end if;
1293 if Is_List_Member (P) then
1294 L := List_Containing (P);
1295 P := Parent (L);
1296 else
1297 L := No_List;
1298 P := Parent (P);
1299 end if;
1301 exit when Nkind (P) = N_Subunit;
1303 -- Filter out case of default expressions, where we do not
1304 -- do the check at this stage.
1306 if Nkind (P) = N_Parameter_Specification
1307 or else
1308 Nkind (P) = N_Component_Declaration
1309 then
1310 return;
1311 end if;
1313 -- A protected body has no elaboration code and contains
1314 -- only other bodies.
1316 if Nkind (P) = N_Protected_Body then
1317 return;
1319 elsif Nkind (P) = N_Subprogram_Body
1320 or else
1321 Nkind (P) = N_Task_Body
1322 or else
1323 Nkind (P) = N_Block_Statement
1324 or else
1325 Nkind (P) = N_Entry_Body
1326 then
1327 if L = Declarations (P) then
1328 exit;
1330 -- We are not in elaboration code, but we are doing
1331 -- dynamic elaboration checks, in this case, we still
1332 -- need to do the call, since the subprogram we are in
1333 -- could be called from another unit, also in dynamic
1334 -- elaboration check mode, at elaboration time.
1336 elsif Dynamic_Elaboration_Checks then
1338 -- This is a rather new check, going into version
1339 -- 3.14a1 for the first time (V1.80 of this unit), so
1340 -- we provide a debug flag to enable it. That way we
1341 -- have an easy work around for regressions that are
1342 -- caused by this new check. This debug flag can be
1343 -- removed later.
1345 if Debug_Flag_DD then
1346 return;
1347 end if;
1349 -- Do the check in this case
1351 exit;
1353 elsif Nkind (P) = N_Task_Body then
1355 -- The check is deferred until Check_Task_Activation
1356 -- but we need to capture local suppress pragmas
1357 -- that may inhibit checks on this call.
1359 Ent := Get_Called_Ent;
1361 if No (Ent) then
1362 return;
1364 elsif Elaboration_Checks_Suppressed (Current_Scope)
1365 or else Elaboration_Checks_Suppressed (Ent)
1366 or else Elaboration_Checks_Suppressed (Scope (Ent))
1367 then
1368 Set_No_Elaboration_Check (N);
1369 end if;
1371 return;
1373 -- Static model, call is not in elaboration code, we
1374 -- never need to worry, because in the static model the
1375 -- top level caller always takes care of things.
1377 else
1378 return;
1379 end if;
1380 end if;
1381 end loop;
1382 end;
1383 end if;
1384 end if;
1386 Ent := Get_Called_Ent;
1388 if No (Ent) then
1389 return;
1390 end if;
1392 -- Nothing to do if this is a recursive call (i.e. a call to
1393 -- an entity that is already in the Elab_Call stack)
1395 for J in 1 .. Elab_Visited.Last loop
1396 if Ent = Elab_Visited.Table (J) then
1397 return;
1398 end if;
1399 end loop;
1401 -- See if we need to analyze this call. We analyze it if either of
1402 -- the following conditions is met:
1404 -- It is an inner level call (since in this case it was triggered
1405 -- by an outer level call from elaboration code), but only if the
1406 -- call is within the scope of the original outer level call.
1408 -- It is an outer level call from elaboration code, or the called
1409 -- entity is in the same elaboration scope.
1411 -- And in these cases, we will check both inter-unit calls and
1412 -- intra-unit (within a single unit) calls.
1414 C_Scope := Current_Scope;
1416 -- If not outer level call, then we follow it if it is within
1417 -- the original scope of the outer call.
1419 if Present (Outer_Scope)
1420 and then Within (Scope (Ent), Outer_Scope)
1421 then
1422 Set_C_Scope;
1423 Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
1425 elsif Elaboration_Checks_Suppressed (Current_Scope) then
1426 null;
1428 elsif From_Elab_Code then
1429 Set_C_Scope;
1430 Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
1432 elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
1433 Set_C_Scope;
1434 Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
1436 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1437 -- is set, then we will do the check, but only in the inter-unit case
1438 -- (this is to accommodate unguarded elaboration calls from other units
1439 -- in which this same mode is set). We don't want warnings in this case,
1440 -- it would generate warnings having nothing to do with elaboration.
1442 elsif Dynamic_Elaboration_Checks then
1443 Set_C_Scope;
1444 Check_A_Call
1446 Ent,
1447 Standard_Standard,
1448 Inter_Unit_Only => True,
1449 Generate_Warnings => False);
1451 -- Otherwise nothing to do
1453 else
1454 return;
1455 end if;
1457 -- A call to an Init_Proc in elaboration code may bring additional
1458 -- dependencies, if some of the record components thereof have
1459 -- initializations that are function calls that come from source.
1460 -- We treat the current node as a call to each of these functions,
1461 -- to check their elaboration impact.
1463 if Is_Init_Proc (Ent)
1464 and then From_Elab_Code
1465 then
1466 Process_Init_Proc : declare
1467 Unit_Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1469 function Find_Init_Call (Nod : Node_Id) return Traverse_Result;
1470 -- Find subprogram calls within body of Init_Proc for Traverse
1471 -- instantiation below.
1473 procedure Traverse_Body is new Traverse_Proc (Find_Init_Call);
1474 -- Traversal procedure to find all calls with body of Init_Proc
1476 --------------------
1477 -- Find_Init_Call --
1478 --------------------
1480 function Find_Init_Call (Nod : Node_Id) return Traverse_Result is
1481 Func : Entity_Id;
1483 begin
1484 if (Nkind (Nod) = N_Function_Call
1485 or else Nkind (Nod) = N_Procedure_Call_Statement)
1486 and then Is_Entity_Name (Name (Nod))
1487 then
1488 Func := Entity (Name (Nod));
1490 if Comes_From_Source (Func) then
1491 Check_A_Call
1492 (N, Func, Standard_Standard, Inter_Unit_Only => True);
1493 end if;
1495 return OK;
1497 else
1498 return OK;
1499 end if;
1500 end Find_Init_Call;
1502 -- Start of processing for Process_Init_Proc
1504 begin
1505 if Nkind (Unit_Decl) = N_Subprogram_Body then
1506 Traverse_Body (Handled_Statement_Sequence (Unit_Decl));
1507 end if;
1508 end Process_Init_Proc;
1509 end if;
1510 end Check_Elab_Call;
1512 -----------------------
1513 -- Check_Elab_Assign --
1514 -----------------------
1516 procedure Check_Elab_Assign (N : Node_Id) is
1517 Ent : Entity_Id;
1518 Scop : Entity_Id;
1520 Pkg_Spec : Entity_Id;
1521 Pkg_Body : Entity_Id;
1523 begin
1524 -- For record or array component, check prefix. If it is an access
1525 -- type, then there is nothing to do (we do not know what is being
1526 -- assigned), but otherwise this is an assignment to the prefix.
1528 if Nkind (N) = N_Indexed_Component
1529 or else
1530 Nkind (N) = N_Selected_Component
1531 or else
1532 Nkind (N) = N_Slice
1533 then
1534 if not Is_Access_Type (Etype (Prefix (N))) then
1535 Check_Elab_Assign (Prefix (N));
1536 end if;
1538 return;
1539 end if;
1541 -- For type conversion, check expression
1543 if Nkind (N) = N_Type_Conversion then
1544 Check_Elab_Assign (Expression (N));
1545 return;
1546 end if;
1548 -- Nothing to do if this is not an entity reference otherwise get entity
1550 if Is_Entity_Name (N) then
1551 Ent := Entity (N);
1552 else
1553 return;
1554 end if;
1556 -- What we are looking for is a reference in the body of a package that
1557 -- modifies a variable declared in the visible part of the package spec.
1559 if Present (Ent)
1560 and then Comes_From_Source (N)
1561 and then not Suppress_Elaboration_Warnings (Ent)
1562 and then Ekind (Ent) = E_Variable
1563 and then not In_Private_Part (Ent)
1564 and then Is_Library_Level_Entity (Ent)
1565 then
1566 Scop := Current_Scope;
1567 loop
1568 if No (Scop) or else Scop = Standard_Standard then
1569 return;
1570 elsif Ekind (Scop) = E_Package
1571 and then Is_Compilation_Unit (Scop)
1572 then
1573 exit;
1574 else
1575 Scop := Scope (Scop);
1576 end if;
1577 end loop;
1579 -- Here Scop points to the containing library package
1581 Pkg_Spec := Scop;
1582 Pkg_Body := Body_Entity (Pkg_Spec);
1584 -- All OK if the package has an Elaborate_Body pragma
1586 if Has_Pragma_Elaborate_Body (Scop) then
1587 return;
1588 end if;
1590 -- OK if entity being modified is not in containing package spec
1592 if not In_Same_Source_Unit (Scop, Ent) then
1593 return;
1594 end if;
1596 -- All OK if entity appears in generic package or generic instance.
1597 -- We just get too messed up trying to give proper warnings in the
1598 -- presence of generics. Better no message than a junk one.
1600 Scop := Scope (Ent);
1601 while Present (Scop) and then Scop /= Pkg_Spec loop
1602 if Ekind (Scop) = E_Generic_Package then
1603 return;
1604 elsif Ekind (Scop) = E_Package
1605 and then Is_Generic_Instance (Scop)
1606 then
1607 return;
1608 end if;
1610 Scop := Scope (Scop);
1611 end loop;
1613 -- All OK if in task, don't issue warnings there
1615 if In_Task_Activation then
1616 return;
1617 end if;
1619 -- OK if no package body
1621 if No (Pkg_Body) then
1622 return;
1623 end if;
1625 -- OK if reference is not in package body
1627 if not In_Same_Source_Unit (Pkg_Body, N) then
1628 return;
1629 end if;
1631 -- OK if package body has no handled statement sequence
1633 declare
1634 HSS : constant Node_Id :=
1635 Handled_Statement_Sequence (Declaration_Node (Pkg_Body));
1636 begin
1637 if No (HSS) or else not Comes_From_Source (HSS) then
1638 return;
1639 end if;
1640 end;
1642 -- We definitely have a case of a modification of an entity in
1643 -- the package spec from the elaboration code of the package body.
1644 -- We may not give the warning (because there are some additional
1645 -- checks to avoid too many false positives), but it would be a good
1646 -- idea for the binder to try to keep the body elaboration close to
1647 -- the spec elaboration.
1649 Set_Elaborate_Body_Desirable (Pkg_Spec);
1651 -- All OK in gnat mode (we know what we are doing)
1653 if GNAT_Mode then
1654 return;
1655 end if;
1657 -- All OK if warnings suppressed on the entity
1659 if Warnings_Off (Ent) then
1660 return;
1661 end if;
1663 -- All OK if all warnings suppressed
1665 if Warning_Mode = Suppress then
1666 return;
1667 end if;
1669 -- All OK if elaboration checks suppressed for entity
1671 if Checks_May_Be_Suppressed (Ent)
1672 and then Is_Check_Suppressed (Ent, Elaboration_Check)
1673 then
1674 return;
1675 end if;
1677 -- OK if the entity is initialized. Note that the No_Initialization
1678 -- flag usually means that the initialization has been rewritten into
1679 -- assignments, but that still counts for us.
1681 declare
1682 Decl : constant Node_Id := Declaration_Node (Ent);
1683 begin
1684 if Nkind (Decl) = N_Object_Declaration
1685 and then (Present (Expression (Decl))
1686 or else No_Initialization (Decl))
1687 then
1688 return;
1689 end if;
1690 end;
1692 -- Here is where we give the warning
1694 Error_Msg_Sloc := Sloc (Ent);
1696 Error_Msg_NE
1697 ("?elaboration code may access& before it is initialized",
1698 N, Ent);
1699 Error_Msg_NE
1700 ("\?suggest adding pragma Elaborate_Body to spec of &",
1701 N, Scop);
1702 Error_Msg_N
1703 ("\?or an explicit initialization could be added #", N);
1705 if not All_Errors_Mode then
1706 Set_Suppress_Elaboration_Warnings (Ent);
1707 end if;
1708 end if;
1709 end Check_Elab_Assign;
1711 ----------------------
1712 -- Check_Elab_Calls --
1713 ----------------------
1715 procedure Check_Elab_Calls is
1716 begin
1717 -- If expansion is disabled, do not generate any checks. Also
1718 -- skip checks if any subunits are missing because in either
1719 -- case we lack the full information that we need, and no object
1720 -- file will be created in any case.
1722 if not Expander_Active
1723 or else Is_Generic_Unit (Cunit_Entity (Main_Unit))
1724 or else Subunits_Missing
1725 then
1726 return;
1727 end if;
1729 -- Skip delayed calls if we had any errors
1731 if Serious_Errors_Detected = 0 then
1732 Delaying_Elab_Checks := False;
1733 Expander_Mode_Save_And_Set (True);
1735 for J in Delay_Check.First .. Delay_Check.Last loop
1736 Push_Scope (Delay_Check.Table (J).Curscop);
1737 From_Elab_Code := Delay_Check.Table (J).From_Elab_Code;
1739 Check_Internal_Call_Continue (
1740 N => Delay_Check.Table (J).N,
1741 E => Delay_Check.Table (J).E,
1742 Outer_Scope => Delay_Check.Table (J).Outer_Scope,
1743 Orig_Ent => Delay_Check.Table (J).Orig_Ent);
1745 Pop_Scope;
1746 end loop;
1748 -- Set Delaying_Elab_Checks back on for next main compilation
1750 Expander_Mode_Restore;
1751 Delaying_Elab_Checks := True;
1752 end if;
1753 end Check_Elab_Calls;
1755 ------------------------------
1756 -- Check_Elab_Instantiation --
1757 ------------------------------
1759 procedure Check_Elab_Instantiation
1760 (N : Node_Id;
1761 Outer_Scope : Entity_Id := Empty)
1763 Ent : Entity_Id;
1765 begin
1766 -- Check for and deal with bad instantiation case. There is some
1767 -- duplicated code here, but we will worry about this later ???
1769 Check_Bad_Instantiation (N);
1771 if ABE_Is_Certain (N) then
1772 return;
1773 end if;
1775 -- Nothing to do if we do not have an instantiation (happens in some
1776 -- error cases, and also in the formal package declaration case)
1778 if Nkind (N) not in N_Generic_Instantiation then
1779 return;
1780 end if;
1782 -- Nothing to do if inside a generic template
1784 if Inside_A_Generic then
1785 return;
1786 end if;
1788 -- Nothing to do if the instantiation is not in the main unit
1790 if not In_Extended_Main_Code_Unit (N) then
1791 return;
1792 end if;
1794 Ent := Get_Generic_Entity (N);
1795 From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
1797 -- See if we need to analyze this instantiation. We analyze it if
1798 -- either of the following conditions is met:
1800 -- It is an inner level instantiation (since in this case it was
1801 -- triggered by an outer level call from elaboration code), but
1802 -- only if the instantiation is within the scope of the original
1803 -- outer level call.
1805 -- It is an outer level instantiation from elaboration code, or the
1806 -- instantiated entity is in the same elaboratoin scope.
1808 -- And in these cases, we will check both the inter-unit case and
1809 -- the intra-unit (within a single unit) case.
1811 C_Scope := Current_Scope;
1813 if Present (Outer_Scope)
1814 and then Within (Scope (Ent), Outer_Scope)
1815 then
1816 Set_C_Scope;
1817 Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
1819 elsif From_Elab_Code then
1820 Set_C_Scope;
1821 Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
1823 elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
1824 Set_C_Scope;
1825 Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
1827 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1828 -- is set, then we will do the check, but only in the inter-unit case
1829 -- (this is to accommodate unguarded elaboration calls from other units
1830 -- in which this same mode is set). We inhibit warnings in this case,
1831 -- since this instantiation is not occurring in elaboration code.
1833 elsif Dynamic_Elaboration_Checks then
1834 Set_C_Scope;
1835 Check_A_Call
1837 Ent,
1838 Standard_Standard,
1839 Inter_Unit_Only => True,
1840 Generate_Warnings => False);
1842 else
1843 return;
1844 end if;
1845 end Check_Elab_Instantiation;
1847 -------------------------
1848 -- Check_Internal_Call --
1849 -------------------------
1851 procedure Check_Internal_Call
1852 (N : Node_Id;
1853 E : Entity_Id;
1854 Outer_Scope : Entity_Id;
1855 Orig_Ent : Entity_Id)
1857 Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
1859 begin
1860 -- If not function or procedure call or instantiation, then ignore
1861 -- call (this happens in some error case and rewriting cases)
1863 if Nkind (N) /= N_Function_Call
1864 and then
1865 Nkind (N) /= N_Procedure_Call_Statement
1866 and then
1867 not Inst_Case
1868 then
1869 return;
1871 -- Nothing to do if this is a call or instantiation that has
1872 -- already been found to be a sure ABE
1874 elsif ABE_Is_Certain (N) then
1875 return;
1877 -- Nothing to do if errors already detected (avoid cascaded errors)
1879 elsif Serious_Errors_Detected /= 0 then
1880 return;
1882 -- Nothing to do if not in full analysis mode
1884 elsif not Full_Analysis then
1885 return;
1887 -- Nothing to do if within a default expression, since the call
1888 -- is not actualy being made at this time.
1890 elsif In_Default_Expression then
1891 return;
1893 -- Nothing to do for call to intrinsic subprogram
1895 elsif Is_Intrinsic_Subprogram (E) then
1896 return;
1898 -- No need to trace local calls if checking task activation, because
1899 -- other local bodies are elaborated already.
1901 elsif In_Task_Activation then
1902 return;
1903 end if;
1905 -- Delay this call if we are still delaying calls
1907 if Delaying_Elab_Checks then
1908 Delay_Check.Append (
1909 (N => N,
1910 E => E,
1911 Orig_Ent => Orig_Ent,
1912 Curscop => Current_Scope,
1913 Outer_Scope => Outer_Scope,
1914 From_Elab_Code => From_Elab_Code));
1915 return;
1917 -- Otherwise, call phase 2 continuation right now
1919 else
1920 Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent);
1921 end if;
1922 end Check_Internal_Call;
1924 ----------------------------------
1925 -- Check_Internal_Call_Continue --
1926 ----------------------------------
1928 procedure Check_Internal_Call_Continue
1929 (N : Node_Id;
1930 E : Entity_Id;
1931 Outer_Scope : Entity_Id;
1932 Orig_Ent : Entity_Id)
1934 Loc : constant Source_Ptr := Sloc (N);
1935 Inst_Case : constant Boolean := Is_Generic_Unit (E);
1937 Sbody : Node_Id;
1938 Ebody : Entity_Id;
1940 function Find_Elab_Reference (N : Node_Id) return Traverse_Result;
1941 -- Function applied to each node as we traverse the body. Checks for
1942 -- call or entity reference that needs checking, and if so checks it.
1943 -- Always returns OK, so entire tree is traversed, except that as
1944 -- described below subprogram bodies are skipped for now.
1946 procedure Traverse is new Atree.Traverse_Proc (Find_Elab_Reference);
1947 -- Traverse procedure using above Find_Elab_Reference function
1949 -------------------------
1950 -- Find_Elab_Reference --
1951 -------------------------
1953 function Find_Elab_Reference (N : Node_Id) return Traverse_Result is
1954 Actual : Node_Id;
1956 begin
1957 -- If user has specified that there are no entry calls in elaboration
1958 -- code, do not trace past an accept statement, because the rendez-
1959 -- vous will happen after elaboration.
1961 if (Nkind (Original_Node (N)) = N_Accept_Statement
1962 or else Nkind (Original_Node (N)) = N_Selective_Accept)
1963 and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
1964 then
1965 return Abandon;
1967 -- If we have a function call, check it
1969 elsif Nkind (N) = N_Function_Call then
1970 Check_Elab_Call (N, Outer_Scope);
1971 return OK;
1973 -- If we have a procedure call, check the call, and also check
1974 -- arguments that are assignments (OUT or IN OUT mode formals).
1976 elsif Nkind (N) = N_Procedure_Call_Statement then
1977 Check_Elab_Call (N, Outer_Scope);
1979 Actual := First_Actual (N);
1980 while Present (Actual) loop
1981 if Known_To_Be_Assigned (Actual) then
1982 Check_Elab_Assign (Actual);
1983 end if;
1985 Next_Actual (Actual);
1986 end loop;
1988 return OK;
1990 -- If we have a generic instantiation, check it
1992 elsif Nkind (N) in N_Generic_Instantiation then
1993 Check_Elab_Instantiation (N, Outer_Scope);
1994 return OK;
1996 -- Skip subprogram bodies that come from source (wait for
1997 -- call to analyze these). The reason for the come from
1998 -- source test is to avoid catching task bodies.
2000 -- For task bodies, we should really avoid these too, waiting
2001 -- for the task activation, but that's too much trouble to
2002 -- catch for now, so we go in unconditionally. This is not
2003 -- so terrible, it means the error backtrace is not quite
2004 -- complete, and we are too eager to scan bodies of tasks
2005 -- that are unused, but this is hardly very significant!
2007 elsif Nkind (N) = N_Subprogram_Body
2008 and then Comes_From_Source (N)
2009 then
2010 return Skip;
2012 elsif Nkind (N) = N_Assignment_Statement
2013 and then Comes_From_Source (N)
2014 then
2015 Check_Elab_Assign (Name (N));
2016 return OK;
2018 else
2019 return OK;
2020 end if;
2021 end Find_Elab_Reference;
2023 -- Start of processing for Check_Internal_Call_Continue
2025 begin
2026 -- Save outer level call if at outer level
2028 if Elab_Call.Last = 0 then
2029 Outer_Level_Sloc := Loc;
2030 end if;
2032 Elab_Visited.Append (E);
2034 -- If the call is to a function that renames a literal, no check
2035 -- is needed.
2037 if Ekind (E) = E_Enumeration_Literal then
2038 return;
2039 end if;
2041 Sbody := Unit_Declaration_Node (E);
2043 if Nkind (Sbody) /= N_Subprogram_Body
2044 and then
2045 Nkind (Sbody) /= N_Package_Body
2046 then
2047 Ebody := Corresponding_Body (Sbody);
2049 if No (Ebody) then
2050 return;
2051 else
2052 Sbody := Unit_Declaration_Node (Ebody);
2053 end if;
2054 end if;
2056 -- If the body appears after the outer level call or
2057 -- instantiation then we have an error case handled below.
2059 if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody))
2060 and then not In_Task_Activation
2061 then
2062 null;
2064 -- If we have the instantiation case we are done, since we now
2065 -- know that the body of the generic appeared earlier.
2067 elsif Inst_Case then
2068 return;
2070 -- Otherwise we have a call, so we trace through the called
2071 -- body to see if it has any problems ..
2073 else
2074 pragma Assert (Nkind (Sbody) = N_Subprogram_Body);
2076 Elab_Call.Append ((Cloc => Loc, Ent => E));
2078 if Debug_Flag_LL then
2079 Write_Str ("Elab_Call.Last = ");
2080 Write_Int (Int (Elab_Call.Last));
2081 Write_Str (" Ent = ");
2082 Write_Name (Chars (E));
2083 Write_Str (" at ");
2084 Write_Location (Sloc (N));
2085 Write_Eol;
2086 end if;
2088 -- Now traverse declarations and statements of subprogram body.
2089 -- Note that we cannot simply Traverse (Sbody), since traverse
2090 -- does not normally visit subprogram bodies.
2092 declare
2093 Decl : Node_Id;
2094 begin
2095 Decl := First (Declarations (Sbody));
2096 while Present (Decl) loop
2097 Traverse (Decl);
2098 Next (Decl);
2099 end loop;
2100 end;
2102 Traverse (Handled_Statement_Sequence (Sbody));
2104 Elab_Call.Decrement_Last;
2105 return;
2106 end if;
2108 -- Here is the case of calling a subprogram where the body has
2109 -- not yet been encountered, a warning message is needed.
2111 -- If we have nothing in the call stack, then this is at the
2112 -- outer level, and the ABE is bound to occur.
2114 if Elab_Call.Last = 0 then
2115 if Inst_Case then
2116 Error_Msg_NE
2117 ("?cannot instantiate& before body seen", N, Orig_Ent);
2118 else
2119 Error_Msg_NE
2120 ("?cannot call& before body seen", N, Orig_Ent);
2121 end if;
2123 Error_Msg_N
2124 ("\?Program_Error will be raised at run time", N);
2125 Insert_Elab_Check (N);
2127 -- Call is not at outer level
2129 else
2130 -- Deal with dynamic elaboration check
2132 if not Elaboration_Checks_Suppressed (E) then
2133 Set_Elaboration_Entity_Required (E);
2135 -- Case of no elaboration entity allocated yet
2137 if No (Elaboration_Entity (E)) then
2139 -- Create object declaration for elaboration entity, and put it
2140 -- just in front of the spec of the subprogram or generic unit,
2141 -- in the same scope as this unit.
2143 declare
2144 Loce : constant Source_Ptr := Sloc (E);
2145 Ent : constant Entity_Id :=
2146 Make_Defining_Identifier (Loc,
2147 Chars => New_External_Name (Chars (E), 'E'));
2149 begin
2150 Set_Elaboration_Entity (E, Ent);
2151 Push_Scope (Scope (E));
2153 Insert_Action (Declaration_Node (E),
2154 Make_Object_Declaration (Loce,
2155 Defining_Identifier => Ent,
2156 Object_Definition =>
2157 New_Occurrence_Of (Standard_Boolean, Loce),
2158 Expression => New_Occurrence_Of (Standard_False, Loce)));
2160 -- Set elaboration flag at the point of the body
2162 Set_Elaboration_Flag (Sbody, E);
2164 -- Kill current value indication. This is necessary because
2165 -- the tests of this flag are inserted out of sequence and
2166 -- must not pick up bogus indications of the wrong constant
2167 -- value. Also, this is never a true constant, since one way
2168 -- or another, it gets reset.
2170 Set_Current_Value (Ent, Empty);
2171 Set_Last_Assignment (Ent, Empty);
2172 Set_Is_True_Constant (Ent, False);
2173 Pop_Scope;
2174 end;
2175 end if;
2177 -- Generate check of the elaboration Boolean
2179 Insert_Elab_Check (N,
2180 New_Occurrence_Of (Elaboration_Entity (E), Loc));
2181 end if;
2183 -- Generate the warning
2185 if not Suppress_Elaboration_Warnings (E)
2186 and then not Elaboration_Checks_Suppressed (E)
2187 then
2188 if Inst_Case then
2189 Error_Msg_NE
2190 ("instantiation of& may occur before body is seen?",
2191 N, Orig_Ent);
2192 else
2193 Error_Msg_NE
2194 ("call to& may occur before body is seen?", N, Orig_Ent);
2195 end if;
2197 Error_Msg_N
2198 ("\Program_Error may be raised at run time?", N);
2200 Output_Calls (N);
2201 end if;
2202 end if;
2204 -- Set flag to suppress further warnings on same subprogram
2205 -- unless in all errors mode
2207 if not All_Errors_Mode then
2208 Set_Suppress_Elaboration_Warnings (E);
2209 end if;
2210 end Check_Internal_Call_Continue;
2212 ---------------------------
2213 -- Check_Task_Activation --
2214 ---------------------------
2216 procedure Check_Task_Activation (N : Node_Id) is
2217 Loc : constant Source_Ptr := Sloc (N);
2218 Inter_Procs : constant Elist_Id := New_Elmt_List;
2219 Intra_Procs : constant Elist_Id := New_Elmt_List;
2220 Ent : Entity_Id;
2221 P : Entity_Id;
2222 Task_Scope : Entity_Id;
2223 Cunit_SC : Boolean := False;
2224 Decl : Node_Id;
2225 Elmt : Elmt_Id;
2226 Enclosing : Entity_Id;
2228 procedure Add_Task_Proc (Typ : Entity_Id);
2229 -- Add to Task_Procs the task body procedure(s) of task types in Typ.
2230 -- For record types, this procedure recurses over component types.
2232 procedure Collect_Tasks (Decls : List_Id);
2233 -- Collect the types of the tasks that are to be activated in the given
2234 -- list of declarations, in order to perform elaboration checks on the
2235 -- corresponding task procedures which are called implicitly here.
2237 function Outer_Unit (E : Entity_Id) return Entity_Id;
2238 -- find enclosing compilation unit of Entity, ignoring subunits, or
2239 -- else enclosing subprogram. If E is not a package, there is no need
2240 -- for inter-unit elaboration checks.
2242 -------------------
2243 -- Add_Task_Proc --
2244 -------------------
2246 procedure Add_Task_Proc (Typ : Entity_Id) is
2247 Comp : Entity_Id;
2248 Proc : Entity_Id := Empty;
2250 begin
2251 if Is_Task_Type (Typ) then
2252 Proc := Get_Task_Body_Procedure (Typ);
2254 elsif Is_Array_Type (Typ)
2255 and then Has_Task (Base_Type (Typ))
2256 then
2257 Add_Task_Proc (Component_Type (Typ));
2259 elsif Is_Record_Type (Typ)
2260 and then Has_Task (Base_Type (Typ))
2261 then
2262 Comp := First_Component (Typ);
2263 while Present (Comp) loop
2264 Add_Task_Proc (Etype (Comp));
2265 Comp := Next_Component (Comp);
2266 end loop;
2267 end if;
2269 -- If the task type is another unit, we will perform the usual
2270 -- elaboration check on its enclosing unit. If the type is in the
2271 -- same unit, we can trace the task body as for an internal call,
2272 -- but we only need to examine other external calls, because at
2273 -- the point the task is activated, internal subprogram bodies
2274 -- will have been elaborated already. We keep separate lists for
2275 -- each kind of task.
2277 -- Skip this test if errors have occurred, since in this case
2278 -- we can get false indications.
2280 if Serious_Errors_Detected /= 0 then
2281 return;
2282 end if;
2284 if Present (Proc) then
2285 if Outer_Unit (Scope (Proc)) = Enclosing then
2287 if No (Corresponding_Body (Unit_Declaration_Node (Proc)))
2288 and then
2289 (not Is_Generic_Instance (Scope (Proc))
2290 or else
2291 Scope (Proc) = Scope (Defining_Identifier (Decl)))
2292 then
2293 Error_Msg_N
2294 ("task will be activated before elaboration of its body?",
2295 Decl);
2296 Error_Msg_N
2297 ("\Program_Error will be raised at run-time?", Decl);
2299 elsif
2300 Present (Corresponding_Body (Unit_Declaration_Node (Proc)))
2301 then
2302 Append_Elmt (Proc, Intra_Procs);
2303 end if;
2305 else
2306 -- No need for multiple entries of the same type
2308 Elmt := First_Elmt (Inter_Procs);
2309 while Present (Elmt) loop
2310 if Node (Elmt) = Proc then
2311 return;
2312 end if;
2314 Next_Elmt (Elmt);
2315 end loop;
2317 Append_Elmt (Proc, Inter_Procs);
2318 end if;
2319 end if;
2320 end Add_Task_Proc;
2322 -------------------
2323 -- Collect_Tasks --
2324 -------------------
2326 procedure Collect_Tasks (Decls : List_Id) is
2327 begin
2328 if Present (Decls) then
2329 Decl := First (Decls);
2330 while Present (Decl) loop
2331 if Nkind (Decl) = N_Object_Declaration
2332 and then Has_Task (Etype (Defining_Identifier (Decl)))
2333 then
2334 Add_Task_Proc (Etype (Defining_Identifier (Decl)));
2335 end if;
2337 Next (Decl);
2338 end loop;
2339 end if;
2340 end Collect_Tasks;
2342 ----------------
2343 -- Outer_Unit --
2344 ----------------
2346 function Outer_Unit (E : Entity_Id) return Entity_Id is
2347 Outer : Entity_Id;
2349 begin
2350 Outer := E;
2351 while Present (Outer) loop
2352 if Elaboration_Checks_Suppressed (Outer) then
2353 Cunit_SC := True;
2354 end if;
2356 exit when Is_Child_Unit (Outer)
2357 or else Scope (Outer) = Standard_Standard
2358 or else Ekind (Outer) /= E_Package;
2359 Outer := Scope (Outer);
2360 end loop;
2362 return Outer;
2363 end Outer_Unit;
2365 -- Start of processing for Check_Task_Activation
2367 begin
2368 Enclosing := Outer_Unit (Current_Scope);
2370 -- Find all tasks declared in the current unit
2372 if Nkind (N) = N_Package_Body then
2373 P := Unit_Declaration_Node (Corresponding_Spec (N));
2375 Collect_Tasks (Declarations (N));
2376 Collect_Tasks (Visible_Declarations (Specification (P)));
2377 Collect_Tasks (Private_Declarations (Specification (P)));
2379 elsif Nkind (N) = N_Package_Declaration then
2380 Collect_Tasks (Visible_Declarations (Specification (N)));
2381 Collect_Tasks (Private_Declarations (Specification (N)));
2383 else
2384 Collect_Tasks (Declarations (N));
2385 end if;
2387 -- We only perform detailed checks in all tasks are library level
2388 -- entities. If the master is a subprogram or task, activation will
2389 -- depend on the activation of the master itself.
2391 -- Should dynamic checks be added in the more general case???
2393 if Ekind (Enclosing) /= E_Package then
2394 return;
2395 end if;
2397 -- For task types defined in other units, we want the unit containing
2398 -- the task body to be elaborated before the current one.
2400 Elmt := First_Elmt (Inter_Procs);
2401 while Present (Elmt) loop
2402 Ent := Node (Elmt);
2403 Task_Scope := Outer_Unit (Scope (Ent));
2405 if not Is_Compilation_Unit (Task_Scope) then
2406 null;
2408 elsif Suppress_Elaboration_Warnings (Task_Scope)
2409 or else Elaboration_Checks_Suppressed (Task_Scope)
2410 then
2411 null;
2413 elsif Dynamic_Elaboration_Checks then
2414 if not Elaboration_Checks_Suppressed (Ent)
2415 and then not Cunit_SC
2416 and then
2417 not Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
2418 then
2419 -- Runtime elaboration check required. generate check of the
2420 -- elaboration Boolean for the unit containing the entity.
2422 Insert_Elab_Check (N,
2423 Make_Attribute_Reference (Loc,
2424 Attribute_Name => Name_Elaborated,
2425 Prefix =>
2426 New_Occurrence_Of
2427 (Spec_Entity (Task_Scope), Loc)));
2428 end if;
2430 else
2431 -- Force the binder to elaborate other unit first
2433 if not Suppress_Elaboration_Warnings (Ent)
2434 and then not Elaboration_Checks_Suppressed (Ent)
2435 and then Elab_Warnings
2436 and then not Suppress_Elaboration_Warnings (Task_Scope)
2437 and then not Elaboration_Checks_Suppressed (Task_Scope)
2438 then
2439 Error_Msg_Node_2 := Task_Scope;
2440 Error_Msg_NE ("activation of an instance of task type&" &
2441 " requires pragma Elaborate_All on &?", N, Ent);
2442 end if;
2444 Activate_Elaborate_All_Desirable (N, Task_Scope);
2445 Set_Suppress_Elaboration_Warnings (Task_Scope);
2446 end if;
2448 Next_Elmt (Elmt);
2449 end loop;
2451 -- For tasks declared in the current unit, trace other calls within
2452 -- the task procedure bodies, which are available.
2454 In_Task_Activation := True;
2456 Elmt := First_Elmt (Intra_Procs);
2457 while Present (Elmt) loop
2458 Ent := Node (Elmt);
2459 Check_Internal_Call_Continue (N, Ent, Enclosing, Ent);
2460 Next_Elmt (Elmt);
2461 end loop;
2463 In_Task_Activation := False;
2464 end Check_Task_Activation;
2466 --------------------------------
2467 -- Set_Elaboration_Constraint --
2468 --------------------------------
2470 procedure Set_Elaboration_Constraint
2471 (Call : Node_Id;
2472 Subp : Entity_Id;
2473 Scop : Entity_Id)
2475 Elab_Unit : Entity_Id;
2476 Init_Call : constant Boolean :=
2477 Chars (Subp) = Name_Initialize
2478 and then Comes_From_Source (Subp)
2479 and then Present (Parameter_Associations (Call))
2480 and then Is_Controlled (Etype (First_Actual (Call)));
2481 begin
2482 -- If the unit is mentioned in a with_clause of the current
2483 -- unit, it is visible, and we can set the elaboration flag.
2485 if Is_Immediately_Visible (Scop)
2486 or else (Is_Child_Unit (Scop) and then Is_Visible_Child_Unit (Scop))
2487 then
2488 Activate_Elaborate_All_Desirable (Call, Scop);
2489 Set_Suppress_Elaboration_Warnings (Scop, True);
2490 return;
2491 end if;
2493 -- If this is not an initialization call or a call using object notation
2494 -- we know that the unit of the called entity is in the context, and
2495 -- we can set the flag as well. The unit need not be visible if the call
2496 -- occurs within an instantiation.
2498 if Is_Init_Proc (Subp)
2499 or else Init_Call
2500 or else Nkind (Original_Node (Call)) = N_Selected_Component
2501 then
2502 null; -- detailed processing follows.
2504 else
2505 Activate_Elaborate_All_Desirable (Call, Scop);
2506 Set_Suppress_Elaboration_Warnings (Scop, True);
2507 return;
2508 end if;
2510 -- If the unit is not in the context, there must be an intermediate
2511 -- unit that is, on which we need to place to elaboration flag. This
2512 -- happens with init proc calls.
2514 if Is_Init_Proc (Subp)
2515 or else Init_Call
2516 then
2517 -- The initialization call is on an object whose type is not declared
2518 -- in the same scope as the subprogram. The type of the object must
2519 -- be a subtype of the type of operation. This object is the first
2520 -- actual in the call.
2522 declare
2523 Typ : constant Entity_Id :=
2524 Etype (First (Parameter_Associations (Call)));
2525 begin
2526 Elab_Unit := Scope (Typ);
2527 while (Present (Elab_Unit))
2528 and then not Is_Compilation_Unit (Elab_Unit)
2529 loop
2530 Elab_Unit := Scope (Elab_Unit);
2531 end loop;
2532 end;
2534 -- If original node uses selected component notation, the prefix is
2535 -- visible and determines the scope that must be elaborated. After
2536 -- rewriting, the prefix is the first actual in the call.
2538 elsif Nkind (Original_Node (Call)) = N_Selected_Component then
2539 Elab_Unit := Scope (Etype (First (Parameter_Associations (Call))));
2541 -- Not one of special cases above
2543 else
2544 -- Using previously computed scope. If the elaboration check is
2545 -- done after analysis, the scope is not visible any longer, but
2546 -- must still be in the context.
2548 Elab_Unit := Scop;
2549 end if;
2551 Activate_Elaborate_All_Desirable (Call, Elab_Unit);
2552 Set_Suppress_Elaboration_Warnings (Elab_Unit, True);
2553 end Set_Elaboration_Constraint;
2555 ----------------------
2556 -- Has_Generic_Body --
2557 ----------------------
2559 function Has_Generic_Body (N : Node_Id) return Boolean is
2560 Ent : constant Entity_Id := Get_Generic_Entity (N);
2561 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
2562 Scop : Entity_Id;
2564 function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id;
2565 -- Determine if the list of nodes headed by N and linked by Next
2566 -- contains a package body for the package spec entity E, and if
2567 -- so return the package body. If not, then returns Empty.
2569 function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id;
2570 -- This procedure is called load the unit whose name is given by Nam.
2571 -- This unit is being loaded to see whether it contains an optional
2572 -- generic body. The returned value is the loaded unit, which is
2573 -- always a package body (only package bodies can contain other
2574 -- entities in the sense in which Has_Generic_Body is interested).
2575 -- We only attempt to load bodies if we are generating code. If we
2576 -- are in semantics check only mode, then it would be wrong to load
2577 -- bodies that are not required from a semantic point of view, so
2578 -- in this case we return Empty. The result is that the caller may
2579 -- incorrectly decide that a generic spec does not have a body when
2580 -- in fact it does, but the only harm in this is that some warnings
2581 -- on elaboration problems may be lost in semantic checks only mode,
2582 -- which is not big loss. We also return Empty if we go for a body
2583 -- and it is not there.
2585 function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id;
2586 -- PE is the entity for a package spec. This function locates the
2587 -- corresponding package body, returning Empty if none is found.
2588 -- The package body returned is fully parsed but may not yet be
2589 -- analyzed, so only syntactic fields should be referenced.
2591 ------------------
2592 -- Find_Body_In --
2593 ------------------
2595 function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is
2596 Nod : Node_Id;
2598 begin
2599 Nod := N;
2600 while Present (Nod) loop
2602 -- If we found the package body we are looking for, return it
2604 if Nkind (Nod) = N_Package_Body
2605 and then Chars (Defining_Unit_Name (Nod)) = Chars (E)
2606 then
2607 return Nod;
2609 -- If we found the stub for the body, go after the subunit,
2610 -- loading it if necessary.
2612 elsif Nkind (Nod) = N_Package_Body_Stub
2613 and then Chars (Defining_Identifier (Nod)) = Chars (E)
2614 then
2615 if Present (Library_Unit (Nod)) then
2616 return Unit (Library_Unit (Nod));
2618 else
2619 return Load_Package_Body (Get_Unit_Name (Nod));
2620 end if;
2622 -- If neither package body nor stub, keep looking on chain
2624 else
2625 Next (Nod);
2626 end if;
2627 end loop;
2629 return Empty;
2630 end Find_Body_In;
2632 -----------------------
2633 -- Load_Package_Body --
2634 -----------------------
2636 function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is
2637 U : Unit_Number_Type;
2639 begin
2640 if Operating_Mode /= Generate_Code then
2641 return Empty;
2642 else
2643 U :=
2644 Load_Unit
2645 (Load_Name => Nam,
2646 Required => False,
2647 Subunit => False,
2648 Error_Node => N);
2650 if U = No_Unit then
2651 return Empty;
2652 else
2653 return Unit (Cunit (U));
2654 end if;
2655 end if;
2656 end Load_Package_Body;
2658 -------------------------------
2659 -- Locate_Corresponding_Body --
2660 -------------------------------
2662 function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is
2663 Spec : constant Node_Id := Declaration_Node (PE);
2664 Decl : constant Node_Id := Parent (Spec);
2665 Scop : constant Entity_Id := Scope (PE);
2666 PBody : Node_Id;
2668 begin
2669 if Is_Library_Level_Entity (PE) then
2671 -- If package is a library unit that requires a body, we have
2672 -- no choice but to go after that body because it might contain
2673 -- an optional body for the original generic package.
2675 if Unit_Requires_Body (PE) then
2677 -- Load the body. Note that we are a little careful here to
2678 -- use Spec to get the unit number, rather than PE or Decl,
2679 -- since in the case where the package is itself a library
2680 -- level instantiation, Spec will properly reference the
2681 -- generic template, which is what we really want.
2683 return
2684 Load_Package_Body
2685 (Get_Body_Name (Unit_Name (Get_Source_Unit (Spec))));
2687 -- But if the package is a library unit that does NOT require
2688 -- a body, then no body is permitted, so we are sure that there
2689 -- is no body for the original generic package.
2691 else
2692 return Empty;
2693 end if;
2695 -- Otherwise look and see if we are embedded in a further package
2697 elsif Is_Package_Or_Generic_Package (Scop) then
2699 -- If so, get the body of the enclosing package, and look in
2700 -- its package body for the package body we are looking for.
2702 PBody := Locate_Corresponding_Body (Scop);
2704 if No (PBody) then
2705 return Empty;
2706 else
2707 return Find_Body_In (PE, First (Declarations (PBody)));
2708 end if;
2710 -- If we are not embedded in a further package, then the body
2711 -- must be in the same declarative part as we are.
2713 else
2714 return Find_Body_In (PE, Next (Decl));
2715 end if;
2716 end Locate_Corresponding_Body;
2718 -- Start of processing for Has_Generic_Body
2720 begin
2721 if Present (Corresponding_Body (Decl)) then
2722 return True;
2724 elsif Unit_Requires_Body (Ent) then
2725 return True;
2727 -- Compilation units cannot have optional bodies
2729 elsif Is_Compilation_Unit (Ent) then
2730 return False;
2732 -- Otherwise look at what scope we are in
2734 else
2735 Scop := Scope (Ent);
2737 -- Case of entity is in other than a package spec, in this case
2738 -- the body, if present, must be in the same declarative part.
2740 if not Is_Package_Or_Generic_Package (Scop) then
2741 declare
2742 P : Node_Id;
2744 begin
2745 -- Declaration node may get us a spec, so if so, go to
2746 -- the parent declaration.
2748 P := Declaration_Node (Ent);
2749 while not Is_List_Member (P) loop
2750 P := Parent (P);
2751 end loop;
2753 return Present (Find_Body_In (Ent, Next (P)));
2754 end;
2756 -- If the entity is in a package spec, then we have to locate
2757 -- the corresponding package body, and look there.
2759 else
2760 declare
2761 PBody : constant Node_Id := Locate_Corresponding_Body (Scop);
2763 begin
2764 if No (PBody) then
2765 return False;
2766 else
2767 return
2768 Present
2769 (Find_Body_In (Ent, (First (Declarations (PBody)))));
2770 end if;
2771 end;
2772 end if;
2773 end if;
2774 end Has_Generic_Body;
2776 -----------------------
2777 -- Insert_Elab_Check --
2778 -----------------------
2780 procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is
2781 Nod : Node_Id;
2782 Loc : constant Source_Ptr := Sloc (N);
2784 begin
2785 -- If expansion is disabled, do not generate any checks. Also
2786 -- skip checks if any subunits are missing because in either
2787 -- case we lack the full information that we need, and no object
2788 -- file will be created in any case.
2790 if not Expander_Active or else Subunits_Missing then
2791 return;
2792 end if;
2794 -- If we have a generic instantiation, where Instance_Spec is set,
2795 -- then this field points to a generic instance spec that has
2796 -- been inserted before the instantiation node itself, so that
2797 -- is where we want to insert a check.
2799 if Nkind (N) in N_Generic_Instantiation
2800 and then Present (Instance_Spec (N))
2801 then
2802 Nod := Instance_Spec (N);
2803 else
2804 Nod := N;
2805 end if;
2807 -- If we are inserting at the top level, insert in Aux_Decls
2809 if Nkind (Parent (Nod)) = N_Compilation_Unit then
2810 declare
2811 ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod));
2812 R : Node_Id;
2814 begin
2815 if No (C) then
2816 R :=
2817 Make_Raise_Program_Error (Loc,
2818 Reason => PE_Access_Before_Elaboration);
2819 else
2820 R :=
2821 Make_Raise_Program_Error (Loc,
2822 Condition => Make_Op_Not (Loc, C),
2823 Reason => PE_Access_Before_Elaboration);
2824 end if;
2826 if No (Declarations (ADN)) then
2827 Set_Declarations (ADN, New_List (R));
2828 else
2829 Append_To (Declarations (ADN), R);
2830 end if;
2832 Analyze (R);
2833 end;
2835 -- Otherwise just insert before the node in question. However, if
2836 -- the context of the call has already been analyzed, an insertion
2837 -- will not work if it depends on subsequent expansion (e.g. a call in
2838 -- a branch of a short-circuit). In that case we replace the call with
2839 -- a conditional expression, or with a Raise if it is unconditional.
2840 -- Unfortunately this does not work if the call has a dynamic size,
2841 -- because gigi regards it as a dynamic-sized temporary. If such a call
2842 -- appears in a short-circuit expression, the elaboration check will be
2843 -- missed (rare enough ???). Otherwise, the code below inserts the check
2844 -- at the appropriate place before the call. Same applies in the even
2845 -- rarer case the return type has a known size but is unconstrained.
2847 else
2848 if Nkind (N) = N_Function_Call
2849 and then Analyzed (Parent (N))
2850 and then Size_Known_At_Compile_Time (Etype (N))
2851 and then
2852 (not Has_Discriminants (Etype (N))
2853 or else Is_Constrained (Etype (N)))
2855 then
2856 declare
2857 Typ : constant Entity_Id := Etype (N);
2858 Chk : constant Boolean := Do_Range_Check (N);
2860 R : constant Node_Id :=
2861 Make_Raise_Program_Error (Loc,
2862 Reason => PE_Access_Before_Elaboration);
2864 begin
2865 Set_Etype (R, Typ);
2867 if No (C) then
2868 Rewrite (N, R);
2870 else
2871 Rewrite (N,
2872 Make_Conditional_Expression (Loc,
2873 Expressions => New_List (C, Relocate_Node (N), R)));
2874 end if;
2876 Analyze_And_Resolve (N, Typ);
2878 -- If the original call requires a range check, so does the
2879 -- conditional expression.
2881 if Chk then
2882 Enable_Range_Check (N);
2883 else
2884 Set_Do_Range_Check (N, False);
2885 end if;
2886 end;
2888 else
2889 if No (C) then
2890 Insert_Action (Nod,
2891 Make_Raise_Program_Error (Loc,
2892 Reason => PE_Access_Before_Elaboration));
2893 else
2894 Insert_Action (Nod,
2895 Make_Raise_Program_Error (Loc,
2896 Condition =>
2897 Make_Op_Not (Loc,
2898 Right_Opnd => C),
2899 Reason => PE_Access_Before_Elaboration));
2900 end if;
2901 end if;
2902 end if;
2903 end Insert_Elab_Check;
2905 ------------------
2906 -- Output_Calls --
2907 ------------------
2909 procedure Output_Calls (N : Node_Id) is
2910 Ent : Entity_Id;
2912 function Is_Printable_Error_Name (Nm : Name_Id) return Boolean;
2913 -- An internal function, used to determine if a name, Nm, is either
2914 -- a non-internal name, or is an internal name that is printable
2915 -- by the error message circuits (i.e. it has a single upper
2916 -- case letter at the end).
2918 function Is_Printable_Error_Name (Nm : Name_Id) return Boolean is
2919 begin
2920 if not Is_Internal_Name (Nm) then
2921 return True;
2923 elsif Name_Len = 1 then
2924 return False;
2926 else
2927 Name_Len := Name_Len - 1;
2928 return not Is_Internal_Name;
2929 end if;
2930 end Is_Printable_Error_Name;
2932 -- Start of processing for Output_Calls
2934 begin
2935 for J in reverse 1 .. Elab_Call.Last loop
2936 Error_Msg_Sloc := Elab_Call.Table (J).Cloc;
2938 Ent := Elab_Call.Table (J).Ent;
2940 if Is_Generic_Unit (Ent) then
2941 Error_Msg_NE ("\?& instantiated #", N, Ent);
2943 elsif Is_Init_Proc (Ent) then
2944 Error_Msg_N ("\?initialization procedure called #", N);
2946 elsif Is_Printable_Error_Name (Chars (Ent)) then
2947 Error_Msg_NE ("\?& called #", N, Ent);
2949 else
2950 Error_Msg_N ("\? called #", N);
2951 end if;
2952 end loop;
2953 end Output_Calls;
2955 ----------------------------
2956 -- Same_Elaboration_Scope --
2957 ----------------------------
2959 function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is
2960 S1 : Entity_Id;
2961 S2 : Entity_Id;
2963 begin
2964 -- Find elaboration scope for Scop1
2965 -- This is either a subprogram or a compilation unit.
2967 S1 := Scop1;
2968 while S1 /= Standard_Standard
2969 and then not Is_Compilation_Unit (S1)
2970 and then (Ekind (S1) = E_Package
2971 or else
2972 Ekind (S1) = E_Protected_Type
2973 or else
2974 Ekind (S1) = E_Block)
2975 loop
2976 S1 := Scope (S1);
2977 end loop;
2979 -- Find elaboration scope for Scop2
2981 S2 := Scop2;
2982 while S2 /= Standard_Standard
2983 and then not Is_Compilation_Unit (S2)
2984 and then (Ekind (S2) = E_Package
2985 or else
2986 Ekind (S2) = E_Protected_Type
2987 or else
2988 Ekind (S2) = E_Block)
2989 loop
2990 S2 := Scope (S2);
2991 end loop;
2993 return S1 = S2;
2994 end Same_Elaboration_Scope;
2996 -----------------
2997 -- Set_C_Scope --
2998 -----------------
3000 procedure Set_C_Scope is
3001 begin
3002 while not Is_Compilation_Unit (C_Scope) loop
3003 C_Scope := Scope (C_Scope);
3004 end loop;
3005 end Set_C_Scope;
3007 -----------------
3008 -- Spec_Entity --
3009 -----------------
3011 function Spec_Entity (E : Entity_Id) return Entity_Id is
3012 Decl : Node_Id;
3014 begin
3015 -- Check for case of body entity
3016 -- Why is the check for E_Void needed???
3018 if Ekind (E) = E_Void
3019 or else Ekind (E) = E_Subprogram_Body
3020 or else Ekind (E) = E_Package_Body
3021 then
3022 Decl := E;
3024 loop
3025 Decl := Parent (Decl);
3026 exit when Nkind (Decl) in N_Proper_Body;
3027 end loop;
3029 return Corresponding_Spec (Decl);
3031 else
3032 return E;
3033 end if;
3034 end Spec_Entity;
3036 -------------------
3037 -- Supply_Bodies --
3038 -------------------
3040 procedure Supply_Bodies (N : Node_Id) is
3041 begin
3042 if Nkind (N) = N_Subprogram_Declaration then
3043 declare
3044 Ent : constant Entity_Id := Defining_Unit_Name (Specification (N));
3045 begin
3046 Set_Is_Imported (Ent);
3047 Set_Convention (Ent, Convention_Stubbed);
3048 end;
3050 elsif Nkind (N) = N_Package_Declaration then
3051 declare
3052 Spec : constant Node_Id := Specification (N);
3053 begin
3054 Push_Scope (Defining_Unit_Name (Spec));
3055 Supply_Bodies (Visible_Declarations (Spec));
3056 Supply_Bodies (Private_Declarations (Spec));
3057 Pop_Scope;
3058 end;
3059 end if;
3060 end Supply_Bodies;
3062 procedure Supply_Bodies (L : List_Id) is
3063 Elmt : Node_Id;
3064 begin
3065 if Present (L) then
3066 Elmt := First (L);
3067 while Present (Elmt) loop
3068 Supply_Bodies (Elmt);
3069 Next (Elmt);
3070 end loop;
3071 end if;
3072 end Supply_Bodies;
3074 ------------
3075 -- Within --
3076 ------------
3078 function Within (E1, E2 : Entity_Id) return Boolean is
3079 Scop : Entity_Id;
3081 begin
3082 Scop := E1;
3083 loop
3084 if Scop = E2 then
3085 return True;
3087 elsif Scop = Standard_Standard then
3088 return False;
3090 else
3091 Scop := Scope (Scop);
3092 end if;
3093 end loop;
3095 raise Program_Error;
3096 end Within;
3098 --------------------------
3099 -- Within_Elaborate_All --
3100 --------------------------
3102 function Within_Elaborate_All (E : Entity_Id) return Boolean is
3103 Item : Node_Id;
3104 Item2 : Node_Id;
3105 Elab_Id : Entity_Id;
3106 Par : Node_Id;
3108 begin
3109 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
3110 while Present (Item) loop
3111 if Nkind (Item) = N_Pragma
3112 and then Get_Pragma_Id (Chars (Item)) = Pragma_Elaborate_All
3113 then
3114 -- Return if some previous error on the pragma itself
3116 if Error_Posted (Item) then
3117 return False;
3118 end if;
3120 Elab_Id :=
3121 Entity
3122 (Expression (First (Pragma_Argument_Associations (Item))));
3124 Par := Parent (Unit_Declaration_Node (Elab_Id));
3126 Item2 := First (Context_Items (Par));
3127 while Present (Item2) loop
3128 if Nkind (Item2) = N_With_Clause
3129 and then Entity (Name (Item2)) = E
3130 then
3131 return True;
3132 end if;
3134 Next (Item2);
3135 end loop;
3136 end if;
3138 Next (Item);
3139 end loop;
3141 return False;
3142 end Within_Elaborate_All;
3144 end Sem_Elab;