include/ChangeLog:
[official-gcc.git] / gcc / ada / sem_elab.adb
blobf440f7d3cc9388d317264fc9c091380653396e15
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-2002 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 with Atree; use Atree;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Einfo; use Einfo;
31 with Elists; use Elists;
32 with Errout; use Errout;
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 Sem; use Sem;
45 with Sem_Cat; use Sem_Cat;
46 with Sem_Ch7; use Sem_Ch7;
47 with Sem_Ch8; use Sem_Ch8;
48 with Sem_Res; use Sem_Res;
49 with Sem_Util; use Sem_Util;
50 with Sinfo; use Sinfo;
51 with Sinput; use Sinput;
52 with Snames; use Snames;
53 with Stand; use Stand;
54 with Table;
55 with Tbuild; use Tbuild;
56 with Uname; use Uname;
58 package body Sem_Elab is
60 -- The following table records the recursive call chain for output
61 -- in the Output routine. Each entry records the call node and the
62 -- entity of the called routine. The number of entries in the table
63 -- (i.e. the value of Elab_Call.Last) indicates the current depth
64 -- of recursion and is used to identify the outer level.
66 type Elab_Call_Entry is record
67 Cloc : Source_Ptr;
68 Ent : Entity_Id;
69 end record;
71 package Elab_Call is new Table.Table (
72 Table_Component_Type => Elab_Call_Entry,
73 Table_Index_Type => Int,
74 Table_Low_Bound => 1,
75 Table_Initial => 50,
76 Table_Increment => 100,
77 Table_Name => "Elab_Call");
79 -- This table is initialized at the start of each outer level call.
80 -- It holds the entities for all subprograms that have been examined
81 -- for this particular outer level call, and is used to prevent both
82 -- infinite recursion, and useless reanalysis of bodies already seen
84 package Elab_Visited is new Table.Table (
85 Table_Component_Type => Entity_Id,
86 Table_Index_Type => Int,
87 Table_Low_Bound => 1,
88 Table_Initial => 200,
89 Table_Increment => 100,
90 Table_Name => "Elab_Visited");
92 -- This table stores calls to Check_Internal_Call that are delayed
93 -- until all generics are instantiated, and in particular that all
94 -- generic bodies have been inserted. We need to delay, because we
95 -- need to be able to look through the inserted bodies.
97 type Delay_Element is record
98 N : Node_Id;
99 -- The parameter N from the call to Check_Internal_Call. Note that
100 -- this node may get rewritten over the delay period by expansion
101 -- in the call case (but not in the instantiation case).
103 E : Entity_Id;
104 -- The parameter E from the call to Check_Internal_Call
106 Orig_Ent : Entity_Id;
107 -- The parameter Orig_Ent from the call to Check_Internal_Call
109 Curscop : Entity_Id;
110 -- The current scope of the call. This is restored when we complete
111 -- the delayed call, so that we do this in the right scope.
113 From_Elab_Code : Boolean;
114 -- Save indication of whether this call is from elaboration code
116 Outer_Scope : Entity_Id;
117 -- 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 these calls 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 Check_A_Call
168 (N : Node_Id;
169 E : Entity_Id;
170 Outer_Scope : Entity_Id;
171 Inter_Unit_Only : Boolean;
172 Generate_Warnings : Boolean := True);
173 -- This is the internal recursive routine that is called to check for
174 -- a possible elaboration error. The argument N is a subprogram call
175 -- or generic instantiation to be checked, and E is the entity of
176 -- the called subprogram, or instantiated generic unit. The flag
177 -- Outer_Scope is the outer level scope for the original call.
178 -- Inter_Unit_Only is set if the call is only to be checked in the
179 -- case where it is to another unit (and skipped if within a unit).
180 -- Generate_Warnings is set to False to suppress warning messages
181 -- about missing pragma Elaborate_All's. These messages are not
182 -- wanted for inner calls in the dynamic model.
184 procedure Check_Bad_Instantiation (N : Node_Id);
185 -- N is a node for an instantiation (if called with any other node kind,
186 -- Check_Bad_Instantiation ignores the call). This subprogram checks for
187 -- the special case of a generic instantiation of a generic spec in the
188 -- same declarative part as the instantiation where a body is present and
189 -- has not yet been seen. This is an obvious error, but needs to be checked
190 -- specially at the time of the instantiation, since it is a case where we
191 -- cannot insert the body anywhere. If this case is detected, warnings are
192 -- generated, and a raise of Program_Error is inserted. In addition any
193 -- subprograms in the generic spec are stubbed, and the Bad_Instantiation
194 -- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
195 -- flag as an indication that no attempt should be made to insert an
196 -- instance body.
198 procedure Check_Internal_Call
199 (N : Node_Id;
200 E : Entity_Id;
201 Outer_Scope : Entity_Id;
202 Orig_Ent : Entity_Id);
203 -- N is a function call or procedure statement call node and E is
204 -- the entity of the called function, which is within the current
205 -- compilation unit (where subunits count as part of the parent).
206 -- This call checks if this call, or any call within any accessed
207 -- body could cause an ABE, and if so, outputs a warning. Orig_Ent
208 -- differs from E only in the case of renamings, and points to the
209 -- original name of the entity. This is used for error messages.
210 -- Outer_Scope is the outer level scope for the original call.
212 procedure Check_Internal_Call_Continue
213 (N : Node_Id;
214 E : Entity_Id;
215 Outer_Scope : Entity_Id;
216 Orig_Ent : Entity_Id);
217 -- The processing for Check_Internal_Call is divided up into two phases,
218 -- and this represents the second phase. The second phase is delayed if
219 -- Delaying_Elab_Calls is set to True. In this delayed case, the first
220 -- phase makes an entry in the Delay_Check table, which is processed
221 -- when Check_Elab_Calls is called. N, E and Orig_Ent are as for the call
222 -- to Check_Internal_Call. Outer_Scope is the outer level scope for
223 -- the original call.
225 function Has_Generic_Body (N : Node_Id) return Boolean;
226 -- N is a generic package instantiation node, and this routine determines
227 -- if this package spec does in fact have a generic body. If so, then
228 -- True is returned, otherwise False. Note that this is not at all the
229 -- same as checking if the unit requires a body, since it deals with
230 -- the case of optional bodies accurately (i.e. if a body is optional,
231 -- then it looks to see if a body is actually present). Note: this
232 -- function can only do a fully correct job if in generating code mode
233 -- where all bodies have to be present. If we are operating in semantics
234 -- check only mode, then in some cases of optional bodies, a result of
235 -- False may incorrectly be given. In practice this simply means that
236 -- some cases of warnings for incorrect order of elaboration will only
237 -- be given when generating code, which is not a big problem (and is
238 -- inevitable, given the optional body semantics of Ada).
240 procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty);
241 -- Given code for an elaboration check (or unconditional raise if
242 -- the check is not needed), inserts the code in the appropriate
243 -- place. N is the call or instantiation node for which the check
244 -- code is required. C is the test whose failure triggers the raise.
246 procedure Output_Calls (N : Node_Id);
247 -- Outputs chain of calls stored in the Elab_Call table. The caller
248 -- has already generated the main warning message, so the warnings
249 -- generated are all continuation messages. The argument is the
250 -- call node at which the messages are to be placed.
252 function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean;
253 -- Given two scopes, determine whether they are the same scope from an
254 -- elaboration point of view, i.e. packages and blocks are ignored.
256 procedure Set_C_Scope;
257 -- On entry C_Scope is set to some scope. On return, C_Scope is reset
258 -- to be the enclosing compilation unit of this scope.
260 function Spec_Entity (E : Entity_Id) return Entity_Id;
261 -- Given a compilation unit entity, if it is a spec entity, it is
262 -- returned unchanged. If it is a body entity, then the spec for
263 -- the corresponding spec is returned
265 procedure Supply_Bodies (N : Node_Id);
266 -- Given a node, N, that is either a subprogram declaration or a package
267 -- declaration, this procedure supplies dummy bodies for the subprogram
268 -- or for all subprograms in the package. If the given node is not one
269 -- of these two possibilities, then Supply_Bodies does nothing. The
270 -- dummy body is supplied by setting the subprogram to be Imported with
271 -- convention Stubbed.
273 procedure Supply_Bodies (L : List_Id);
274 -- Calls Supply_Bodies for all elements of the given list L.
276 function Within (E1, E2 : Entity_Id) return Boolean;
277 -- Given two scopes E1 and E2, returns True if E1 is equal to E2, or
278 -- is one of its contained scopes, False otherwise.
280 function Within_Elaborate_All (E : Entity_Id) return Boolean;
281 -- Before emitting a warning on a scope E for a missing elaborate_all,
282 -- check whether E may be in the context of a directly visible unit
283 -- U to which the pragma applies. This prevents spurious warnings when
284 -- the called entity is renamed within U.
286 ------------------
287 -- Check_A_Call --
288 ------------------
290 procedure Check_A_Call
291 (N : Node_Id;
292 E : Entity_Id;
293 Outer_Scope : Entity_Id;
294 Inter_Unit_Only : Boolean;
295 Generate_Warnings : Boolean := True)
297 Loc : constant Source_Ptr := Sloc (N);
298 Ent : Entity_Id;
299 Decl : Node_Id;
301 E_Scope : Entity_Id;
302 -- Top level scope of entity for called subprogram
304 Body_Acts_As_Spec : Boolean;
305 -- Set to true if call is to body acting as spec (no separate spec)
307 Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
308 -- Indicates if we have instantiation case
310 Caller_Unit_Internal : Boolean;
311 Callee_Unit_Internal : Boolean;
313 Inst_Caller : Source_Ptr;
314 Inst_Callee : Source_Ptr;
316 Unit_Caller : Unit_Number_Type;
317 Unit_Callee : Unit_Number_Type;
319 Cunit_SW : Boolean := False;
320 -- Set to suppress warnings for case of external reference where
321 -- one of the enclosing scopes has the Suppress_Elaboration_Warnings
322 -- flag set. For the internal case, we ignore this flag.
324 Cunit_SC : Boolean := False;
325 -- Set to suppress dynamic elaboration checks where one of the
326 -- enclosing scopes has Suppress_Elaboration_Checks set. For
327 -- the internal case, we ignore this flag.
329 begin
330 -- Go to parent for derived subprogram, or to original subprogram
331 -- in the case of a renaming (Alias covers both these cases)
333 Ent := E;
334 loop
335 if Suppress_Elaboration_Warnings (Ent) then
336 return;
337 end if;
339 -- Nothing to do for imported entities,
341 if Is_Imported (Ent) then
342 return;
343 end if;
345 exit when Inst_Case or else No (Alias (Ent));
346 Ent := Alias (Ent);
347 end loop;
349 Decl := Unit_Declaration_Node (Ent);
351 if Nkind (Decl) = N_Subprogram_Body then
352 Body_Acts_As_Spec := True;
354 elsif Nkind (Decl) = N_Subprogram_Declaration
355 or else Nkind (Decl) = N_Subprogram_Body_Stub
356 or else Inst_Case
357 then
358 Body_Acts_As_Spec := False;
360 -- If we have none of an instantiation, subprogram body or
361 -- subprogram declaration, then it is not a case that we want
362 -- to check. (One case is a call to a generic formal subprogram,
363 -- where we do not want the check in the template).
365 else
366 return;
367 end if;
369 E_Scope := Ent;
370 loop
371 if Suppress_Elaboration_Warnings (E_Scope) then
372 Cunit_SW := True;
373 end if;
375 if Suppress_Elaboration_Checks (E_Scope) then
376 Cunit_SC := True;
377 end if;
379 -- Exit when we get to compilation unit, not counting subunits
381 exit when Is_Compilation_Unit (E_Scope)
382 and then (Is_Child_Unit (E_Scope)
383 or else Scope (E_Scope) = Standard_Standard);
385 -- If we did not find a compilation unit, other than standard,
386 -- then nothing to check (happens in some instantiation cases)
388 if E_Scope = Standard_Standard then
389 return;
391 -- Otherwise move up a scope looking for compilation unit
393 else
394 E_Scope := Scope (E_Scope);
395 end if;
396 end loop;
398 -- No checks needed for pure or preelaborated compilation units
400 if Is_Pure (E_Scope)
401 or else Is_Preelaborated (E_Scope)
402 then
403 return;
404 end if;
406 -- If the generic entity is within a deeper instance than we are, then
407 -- either the instantiation to which we refer itself caused an ABE, in
408 -- which case that will be handled separately. Otherwise, we know that
409 -- the body we need appears as needed at the point of the instantiation.
410 -- However, this assumption is only valid if we are in static mode.
412 if not Dynamic_Elaboration_Checks
413 and then Instantiation_Depth (Sloc (Ent)) >
414 Instantiation_Depth (Sloc (N))
415 then
416 return;
417 end if;
419 -- Do not give a warning for a package with no body
421 if Ekind (Ent) = E_Generic_Package
422 and then not Has_Generic_Body (N)
423 then
424 return;
425 end if;
427 -- Case of entity is not in current unit (i.e. with'ed unit case)
429 if E_Scope /= C_Scope then
431 -- We are only interested in such calls if the outer call was from
432 -- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
434 if not From_Elab_Code and then not Dynamic_Elaboration_Checks then
435 return;
436 end if;
438 -- Nothing to do if some scope said to ignore warnings
440 if Cunit_SW then
441 return;
442 end if;
444 -- Nothing to do for a generic instance, because in this case
445 -- the checking was at the point of instantiation of the generic
446 -- However, this shortcut is only applicable in static mode.
448 if Is_Generic_Instance (Ent) and not Dynamic_Elaboration_Checks then
449 return;
450 end if;
452 -- Nothing to do if subprogram with no separate spec
454 if Body_Acts_As_Spec then
455 return;
456 end if;
458 -- Check cases of internal units
460 Callee_Unit_Internal :=
461 Is_Internal_File_Name
462 (Unit_File_Name (Get_Source_Unit (E_Scope)));
464 -- Do not give a warning if the with'ed unit is internal
465 -- and this is the generic instantiation case (this saves a
466 -- lot of hassle dealing with the Text_IO special child units)
468 if Callee_Unit_Internal and Inst_Case then
469 return;
470 end if;
472 if C_Scope = Standard_Standard then
473 Caller_Unit_Internal := False;
474 else
475 Caller_Unit_Internal :=
476 Is_Internal_File_Name
477 (Unit_File_Name (Get_Source_Unit (C_Scope)));
478 end if;
480 -- Do not give a warning if the with'ed unit is internal
481 -- and the caller is not internal (since the binder always
482 -- elaborates internal units first).
484 if Callee_Unit_Internal and (not Caller_Unit_Internal) then
485 return;
486 end if;
488 -- For now, if debug flag -gnatdE is not set, do no checking for
489 -- one internal unit withing another. This fixes the problem with
490 -- the sgi build and storage errors. To be resolved later ???
492 if (Callee_Unit_Internal and Caller_Unit_Internal)
493 and then not Debug_Flag_EE
494 then
495 return;
496 end if;
498 Ent := E;
500 -- If the call is in an instance, and the called entity is not
501 -- defined in the same instance, then the elaboration issue
502 -- focuses around the unit containing the template, it is
503 -- this unit which requires an Elaborate_All.
505 -- However, if we are doing dynamic elaboration, we need to
506 -- chase the call in the usual manner.
508 -- We do not handle the case of calling a generic formal correctly
509 -- in the static case. See test 4703-004 to explore this gap ???
511 Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N)));
512 Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent)));
514 if Inst_Caller = No_Location then
515 Unit_Caller := No_Unit;
516 else
517 Unit_Caller := Get_Source_Unit (N);
518 end if;
520 if Inst_Callee = No_Location then
521 Unit_Callee := No_Unit;
522 else
523 Unit_Callee := Get_Source_Unit (Ent);
524 end if;
526 if Unit_Caller /= No_Unit
527 and then Unit_Callee /= Unit_Caller
528 and then not Dynamic_Elaboration_Checks
529 then
530 E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller));
532 -- If we don't get a spec entity, just ignore call. Not
533 -- quite clear why this check is necessary.
535 if No (E_Scope) then
536 return;
537 end if;
539 -- Otherwise step to enclosing compilation unit
541 while not Is_Compilation_Unit (E_Scope) loop
542 E_Scope := Scope (E_Scope);
543 end loop;
545 -- For the case N is not an instance, or a call within instance
546 -- We recompute E_Scope for the error message, since we
547 -- do NOT want to go to the unit which has the ultimate
548 -- declaration in the case of renaming and derivation and
549 -- we also want to go to the generic unit in the case of
550 -- an instance, and no further.
552 else
553 -- Loop to carefully follow renamings and derivations
554 -- one step outside the current unit, but not further.
556 if not Inst_Case
557 and then Present (Alias (Ent))
558 then
559 E_Scope := Alias (Ent);
560 else
561 E_Scope := Ent;
562 end if;
564 loop
565 while not Is_Compilation_Unit (E_Scope) loop
566 E_Scope := Scope (E_Scope);
567 end loop;
569 -- If E_Scope is the same as C_Scope, it means that there
570 -- definitely was a local renaming or derivation, and we
571 -- are not yet out of the current unit.
573 exit when E_Scope /= C_Scope;
574 Ent := Alias (Ent);
575 E_Scope := Ent;
576 end loop;
577 end if;
579 if Within_Elaborate_All (E_Scope) then
580 return;
581 end if;
583 if not Suppress_Elaboration_Warnings (Ent)
584 and then not Suppress_Elaboration_Warnings (E_Scope)
585 and then Elab_Warnings
586 and then Generate_Warnings
587 then
588 Warn_On_Instance := True;
590 if Inst_Case then
591 Error_Msg_NE
592 ("instantiation of& may raise Program_Error?", N, Ent);
593 else
594 Error_Msg_NE
595 ("call to & may raise Program_Error?", N, Ent);
597 if Unit_Callee = No_Unit
598 and then E_Scope = Current_Scope
599 then
600 -- The missing pragma cannot be on the current unit, so
601 -- place it on the compilation unit that contains the
602 -- called entity, which is more likely to be right.
604 E_Scope := Ent;
606 while not Is_Compilation_Unit (E_Scope) loop
607 E_Scope := Scope (E_Scope);
608 end loop;
609 end if;
610 end if;
612 Error_Msg_Qual_Level := Nat'Last;
613 Error_Msg_NE
614 ("\missing pragma Elaborate_All for&?", N, E_Scope);
615 Error_Msg_Qual_Level := 0;
616 Output_Calls (N);
617 Warn_On_Instance := False;
619 -- Set flag to prevent further warnings for same unit
620 -- unless in All_Errors_Mode.
622 if not All_Errors_Mode and not Dynamic_Elaboration_Checks then
623 Set_Suppress_Elaboration_Warnings (E_Scope);
624 end if;
625 end if;
627 -- Check for runtime elaboration check required
629 if Dynamic_Elaboration_Checks then
630 if not Elaboration_Checks_Suppressed (Ent)
631 and then not Suppress_Elaboration_Checks (E_Scope)
632 and then not Cunit_SC
633 then
634 -- Runtime elaboration check required. generate check of the
635 -- elaboration Boolean for the unit containing the entity.
637 Insert_Elab_Check (N,
638 Make_Attribute_Reference (Loc,
639 Attribute_Name => Name_Elaborated,
640 Prefix =>
641 New_Occurrence_Of
642 (Spec_Entity (E_Scope), Loc)));
643 end if;
645 -- If no dynamic check required, then ask binder to guarantee
646 -- that the necessary elaborations will be done properly!
648 else
649 if not Suppress_Elaboration_Warnings (E)
650 and then not Suppress_Elaboration_Warnings (E_Scope)
651 and then Elab_Warnings
652 and then Generate_Warnings
653 and then not Inst_Case
654 then
655 Error_Msg_Node_2 := E_Scope;
656 Error_Msg_NE ("call to& in elaboration code " &
657 "requires pragma Elaborate_All on&?", N, E);
658 end if;
660 Set_Elaborate_All_Desirable (E_Scope);
661 Set_Suppress_Elaboration_Warnings (E_Scope);
662 end if;
664 -- Case of entity is in same unit as call or instantiation
666 elsif not Inter_Unit_Only then
667 Check_Internal_Call (N, Ent, Outer_Scope, E);
668 end if;
670 end Check_A_Call;
672 -----------------------------
673 -- Check_Bad_Instantiation --
674 -----------------------------
676 procedure Check_Bad_Instantiation (N : Node_Id) is
677 Nam : Node_Id;
678 Ent : Entity_Id;
680 begin
681 -- Nothing to do if we do not have an instantiation (happens in some
682 -- error cases, and also in the formal package declaration case)
684 if Nkind (N) not in N_Generic_Instantiation then
685 return;
687 -- Nothing to do if serious errors detected (avoid cascaded errors)
689 elsif Serious_Errors_Detected /= 0 then
690 return;
692 -- Nothing to do if not in full analysis mode
694 elsif not Full_Analysis then
695 return;
697 -- Nothing to do if inside a generic template
699 elsif Inside_A_Generic then
700 return;
702 -- Nothing to do if a library level instantiation
704 elsif Nkind (Parent (N)) = N_Compilation_Unit then
705 return;
707 -- Nothing to do if we are compiling a proper body for semantic
708 -- purposes only. The generic body may be in another proper body.
710 elsif
711 Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit
712 then
713 return;
714 end if;
716 Nam := Name (N);
717 Ent := Get_Generic_Entity (N);
719 -- The case we are interested in is when the generic spec is in the
720 -- current declarative part
722 if not Same_Elaboration_Scope (Current_Scope, Scope (Ent))
723 or else not In_Same_Extended_Unit (Sloc (N), Sloc (Ent))
724 then
725 return;
726 end if;
728 -- If the generic entity is within a deeper instance than we are, then
729 -- either the instantiation to which we refer itself caused an ABE, in
730 -- which case that will be handled separately. Otherwise, we know that
731 -- the body we need appears as needed at the point of the instantiation.
732 -- If they are both at the same level but not within the same instance
733 -- then the body of the generic will be in the earlier instance.
735 declare
736 D1 : constant Int := Instantiation_Depth (Sloc (Ent));
737 D2 : constant Int := Instantiation_Depth (Sloc (N));
739 begin
740 if D1 > D2 then
741 return;
743 elsif D1 = D2
744 and then Is_Generic_Instance (Scope (Ent))
745 and then not In_Open_Scopes (Scope (Ent))
746 then
747 return;
748 end if;
749 end;
751 -- Now we can proceed, if the entity being called has a completion,
752 -- then we are definitely OK, since we have already seen the body.
754 if Has_Completion (Ent) then
755 return;
756 end if;
758 -- If there is no body, then nothing to do
760 if not Has_Generic_Body (N) then
761 return;
762 end if;
764 -- Here we definitely have a bad instantiation
766 Error_Msg_NE
767 ("?cannot instantiate& before body seen", N, Ent);
769 if Present (Instance_Spec (N)) then
770 Supply_Bodies (Instance_Spec (N));
771 end if;
773 Error_Msg_N
774 ("\?Program_Error will be raised at run time", N);
775 Insert_Elab_Check (N);
776 Set_ABE_Is_Certain (N);
778 end Check_Bad_Instantiation;
780 ---------------------
781 -- Check_Elab_Call --
782 ---------------------
784 procedure Check_Elab_Call
785 (N : Node_Id;
786 Outer_Scope : Entity_Id := Empty)
788 Nam : Node_Id;
789 Ent : Entity_Id;
790 P : Node_Id;
792 begin
793 -- For an entry call, check relevant restriction
795 if Nkind (N) = N_Entry_Call_Statement
796 and then not In_Subprogram_Or_Concurrent_Unit
797 then
798 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N);
800 -- Nothing to do if this is not a call (happens in some error
801 -- conditions, and in some cases where rewriting occurs).
803 elsif Nkind (N) /= N_Function_Call
804 and then Nkind (N) /= N_Procedure_Call_Statement
805 then
806 return;
808 -- Nothing to do if this is a call already rewritten for elab checking.
810 elsif Nkind (Parent (N)) = N_Conditional_Expression then
811 return;
813 -- Nothing to do if inside a generic template
815 elsif Inside_A_Generic
816 and then not Present (Enclosing_Generic_Body (N))
817 then
818 return;
819 end if;
821 -- Here we have a call at elaboration time which must be checked
823 if Debug_Flag_LL then
824 Write_Str (" Check_Elab_Call: ");
826 if No (Name (N))
827 or else not Is_Entity_Name (Name (N))
828 then
829 Write_Str ("<<not entity name>> ");
830 else
831 Write_Name (Chars (Entity (Name (N))));
832 end if;
834 Write_Str (" call at ");
835 Write_Location (Sloc (N));
836 Write_Eol;
837 end if;
839 -- Climb up the tree to make sure we are not inside a
840 -- default expression of a parameter specification or
841 -- a record component, since in both these cases, we
842 -- will be doing the actual call later, not now, and it
843 -- is at the time of the actual call (statically speaking)
844 -- that we must do our static check, not at the time of
845 -- its initial analysis).
847 P := Parent (N);
848 while Present (P) loop
849 if Nkind (P) = N_Parameter_Specification
850 or else
851 Nkind (P) = N_Component_Declaration
852 then
853 return;
854 else
855 P := Parent (P);
856 end if;
857 end loop;
859 -- Stuff that happens only at the outer level
861 if No (Outer_Scope) then
862 Elab_Visited.Set_Last (0);
864 -- Nothing to do if current scope is Standard (this is a bit
865 -- odd, but it happens in the case of generic instantiations).
867 C_Scope := Current_Scope;
869 if C_Scope = Standard_Standard then
870 return;
871 end if;
873 -- First case, we are in elaboration code
875 From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
877 if From_Elab_Code then
879 -- Complain if call that comes from source in preelaborated
880 -- unit and we are not inside a subprogram (i.e. we are in
881 -- elab code)
883 if Comes_From_Source (N)
884 and then In_Preelaborated_Unit
885 and then not In_Inlined_Body
886 then
887 Error_Msg_N
888 ("non-static call not allowed in preelaborated unit", N);
889 return;
890 end if;
892 -- Second case, we are inside a subprogram or concurrent unit
893 -- i.e, we are not in elaboration code.
895 else
896 -- In this case, the issue is whether we are inside the
897 -- declarative part of the unit in which we live, or inside
898 -- its statements. In the latter case, there is no issue of
899 -- ABE calls at this level (a call from outside to the unit
900 -- in which we live might cause an ABE, but that will be
901 -- detected when we analyze that outer level call, as it
902 -- recurses into the called unit).
904 -- Climb up the tree, doing this test, and also testing
905 -- for being inside a default expression, which, as
906 -- discussed above, is not checked at this stage.
908 declare
909 P : Node_Id;
910 L : List_Id;
912 begin
913 P := N;
914 loop
915 -- If we find a parentless subtree, it seems safe to
916 -- assume that we are not in a declarative part and
917 -- that no checking is required.
919 if No (P) then
920 return;
921 end if;
923 if Is_List_Member (P) then
924 L := List_Containing (P);
925 P := Parent (L);
926 else
927 L := No_List;
928 P := Parent (P);
929 end if;
931 exit when Nkind (P) = N_Subunit;
933 -- Filter out case of default expressions, where
934 -- we do not do the check at this stage.
936 if Nkind (P) = N_Parameter_Specification
937 or else
938 Nkind (P) = N_Component_Declaration
939 then
940 return;
941 end if;
943 if Nkind (P) = N_Subprogram_Body
944 or else
945 Nkind (P) = N_Protected_Body
946 or else
947 Nkind (P) = N_Task_Body
948 or else
949 Nkind (P) = N_Block_Statement
950 then
951 if L = Declarations (P) then
952 exit;
954 -- We are not in elaboration code, but we are doing
955 -- dynamic elaboration checks, in this case, we still
956 -- need to do the call, since the subprogram we are in
957 -- could be called from another unit, also in dynamic
958 -- elaboration check mode, at elaboration time.
960 elsif Dynamic_Elaboration_Checks then
962 -- This is a rather new check, going into version
963 -- 3.14a1 for the first time (V1.80 of this unit),
964 -- so we provide a debug flag to enable it. That
965 -- way we have an easy work around for regressions
966 -- that are caused by this new check. This debug
967 -- flag can be removed later.
969 if Debug_Flag_DD then
970 return;
971 end if;
973 -- Do the check in this case
975 exit;
977 -- Static model, call is not in elaboration code, we
978 -- never need to worry, because in the static model
979 -- the top level caller always takes care of things.
981 else
982 return;
983 end if;
984 end if;
985 end loop;
986 end;
987 end if;
988 end if;
990 -- Retrieve called entity. If this is a call to a protected subprogram,
991 -- the entity is a selected component.
992 -- The callable entity may be absent, in which case there is nothing
993 -- to do. This happens with non-analyzed calls in nested generics.
995 Nam := Name (N);
997 if No (Nam) then
998 return;
1000 elsif Nkind (Nam) = N_Selected_Component then
1001 Ent := Entity (Selector_Name (Nam));
1003 elsif not Is_Entity_Name (Nam) then
1004 return;
1006 else
1007 Ent := Entity (Nam);
1008 end if;
1010 if No (Ent) then
1011 return;
1012 end if;
1014 -- Nothing to do if this is a recursive call (i.e. a call to
1015 -- an entity that is already in the Elab_Call stack)
1017 for J in 1 .. Elab_Visited.Last loop
1018 if Ent = Elab_Visited.Table (J) then
1019 return;
1020 end if;
1021 end loop;
1023 -- See if we need to analyze this call. We analyze it if either of
1024 -- the following conditions is met:
1026 -- It is an inner level call (since in this case it was triggered
1027 -- by an outer level call from elaboration code), but only if the
1028 -- call is within the scope of the original outer level call.
1030 -- It is an outer level call from elaboration code, or the called
1031 -- entity is in the same elaboration scope.
1033 -- And in these cases, we will check both inter-unit calls and
1034 -- intra-unit (within a single unit) calls.
1036 C_Scope := Current_Scope;
1038 -- If not outer level call, then we follow it if it is within
1039 -- the original scope of the outer call.
1041 if Present (Outer_Scope)
1042 and then Within (Scope (Ent), Outer_Scope)
1043 then
1044 Set_C_Scope;
1045 Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
1047 elsif Elaboration_Checks_Suppressed (Current_Scope) then
1048 null;
1050 elsif From_Elab_Code then
1051 Set_C_Scope;
1052 Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
1054 elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
1055 Set_C_Scope;
1056 Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
1058 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1059 -- is set, then we will do the check, but only in the inter-unit case
1060 -- (this is to accommodate unguarded elaboration calls from other units
1061 -- in which this same mode is set). We don't want warnings in this case,
1062 -- it would generate warnings having nothing to do with elaboration.
1064 elsif Dynamic_Elaboration_Checks then
1065 Set_C_Scope;
1066 Check_A_Call
1068 Ent,
1069 Standard_Standard,
1070 Inter_Unit_Only => True,
1071 Generate_Warnings => False);
1073 else
1074 return;
1075 end if;
1076 end Check_Elab_Call;
1078 ----------------------
1079 -- Check_Elab_Calls --
1080 ----------------------
1082 procedure Check_Elab_Calls is
1083 begin
1084 -- If expansion is disabled, do not generate any checks. Also
1085 -- skip checks if any subunits are missing because in either
1086 -- case we lack the full information that we need, and no object
1087 -- file will be created in any case.
1089 if not Expander_Active or else Subunits_Missing then
1090 return;
1091 end if;
1093 -- Skip delayed calls if we had any errors
1095 if Serious_Errors_Detected = 0 then
1096 Delaying_Elab_Checks := False;
1097 Expander_Mode_Save_And_Set (True);
1099 for J in Delay_Check.First .. Delay_Check.Last loop
1100 New_Scope (Delay_Check.Table (J).Curscop);
1101 From_Elab_Code := Delay_Check.Table (J).From_Elab_Code;
1103 Check_Internal_Call_Continue (
1104 N => Delay_Check.Table (J).N,
1105 E => Delay_Check.Table (J).E,
1106 Outer_Scope => Delay_Check.Table (J).Outer_Scope,
1107 Orig_Ent => Delay_Check.Table (J).Orig_Ent);
1109 Pop_Scope;
1110 end loop;
1112 -- Set Delaying_Elab_Checks back on for next main compilation
1114 Expander_Mode_Restore;
1115 Delaying_Elab_Checks := True;
1116 end if;
1117 end Check_Elab_Calls;
1119 ------------------------------
1120 -- Check_Elab_Instantiation --
1121 ------------------------------
1123 procedure Check_Elab_Instantiation
1124 (N : Node_Id;
1125 Outer_Scope : Entity_Id := Empty)
1127 Nam : Node_Id;
1128 Ent : Entity_Id;
1130 begin
1131 -- Check for and deal with bad instantiation case. There is some
1132 -- duplicated code here, but we will worry about this later ???
1134 Check_Bad_Instantiation (N);
1136 if ABE_Is_Certain (N) then
1137 return;
1138 end if;
1140 -- Nothing to do if we do not have an instantiation (happens in some
1141 -- error cases, and also in the formal package declaration case)
1143 if Nkind (N) not in N_Generic_Instantiation then
1144 return;
1145 end if;
1147 -- Nothing to do if inside a generic template
1149 if Inside_A_Generic then
1150 return;
1151 end if;
1153 Nam := Name (N);
1154 Ent := Get_Generic_Entity (N);
1155 From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit;
1157 -- See if we need to analyze this instantiation. We analyze it if
1158 -- either of the following conditions is met:
1160 -- It is an inner level instantiation (since in this case it was
1161 -- triggered by an outer level call from elaboration code), but
1162 -- only if the instantiation is within the scope of the original
1163 -- outer level call.
1165 -- It is an outer level instantiation from elaboration code, or the
1166 -- instantiated entity is in the same elaboratoin scope.
1168 -- And in these cases, we will check both the inter-unit case and
1169 -- the intra-unit (within a single unit) case.
1171 C_Scope := Current_Scope;
1173 if Present (Outer_Scope)
1174 and then Within (Scope (Ent), Outer_Scope)
1175 then
1176 Set_C_Scope;
1177 Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False);
1179 elsif From_Elab_Code then
1180 Set_C_Scope;
1181 Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False);
1183 elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then
1184 Set_C_Scope;
1185 Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False);
1187 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1188 -- is set, then we will do the check, but only in the inter-unit case
1189 -- (this is to accommodate unguarded elaboration calls from other units
1190 -- in which this same mode is set). We inhibit warnings in this case,
1191 -- since this instantiation is not occurring in elaboration code.
1193 elsif Dynamic_Elaboration_Checks then
1194 Set_C_Scope;
1195 Check_A_Call
1197 Ent,
1198 Standard_Standard,
1199 Inter_Unit_Only => True,
1200 Generate_Warnings => False);
1202 else
1203 return;
1204 end if;
1205 end Check_Elab_Instantiation;
1207 -------------------------
1208 -- Check_Internal_Call --
1209 -------------------------
1211 procedure Check_Internal_Call
1212 (N : Node_Id;
1213 E : Entity_Id;
1214 Outer_Scope : Entity_Id;
1215 Orig_Ent : Entity_Id)
1217 Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation;
1219 begin
1220 -- If not function or procedure call or instantiation, then ignore
1221 -- call (this happens in some error case and rewriting cases)
1223 if Nkind (N) /= N_Function_Call
1224 and then
1225 Nkind (N) /= N_Procedure_Call_Statement
1226 and then
1227 not Inst_Case
1228 then
1229 return;
1231 -- Nothing to do if this is a call or instantiation that has
1232 -- already been found to be a sure ABE
1234 elsif ABE_Is_Certain (N) then
1235 return;
1237 -- Nothing to do if errors already detected (avoid cascaded errors)
1239 elsif Serious_Errors_Detected /= 0 then
1240 return;
1242 -- Nothing to do if not in full analysis mode
1244 elsif not Full_Analysis then
1245 return;
1247 -- Nothing to do if within a default expression, since the call
1248 -- is not actualy being made at this time.
1250 elsif In_Default_Expression then
1251 return;
1253 -- Nothing to do for call to intrinsic subprogram
1255 elsif Is_Intrinsic_Subprogram (E) then
1256 return;
1258 -- No need to trace local calls if checking task activation, because
1259 -- other local bodies are elaborated already.
1261 elsif In_Task_Activation then
1262 return;
1263 end if;
1265 -- Delay this call if we are still delaying calls
1267 if Delaying_Elab_Checks then
1268 Delay_Check.Increment_Last;
1269 Delay_Check.Table (Delay_Check.Last) :=
1270 (N => N,
1271 E => E,
1272 Orig_Ent => Orig_Ent,
1273 Curscop => Current_Scope,
1274 Outer_Scope => Outer_Scope,
1275 From_Elab_Code => From_Elab_Code);
1276 return;
1278 -- Otherwise, call phase 2 continuation right now
1280 else
1281 Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent);
1282 end if;
1284 end Check_Internal_Call;
1286 ----------------------------------
1287 -- Check_Internal_Call_Continue --
1288 ----------------------------------
1290 procedure Check_Internal_Call_Continue
1291 (N : Node_Id;
1292 E : Entity_Id;
1293 Outer_Scope : Entity_Id;
1294 Orig_Ent : Entity_Id)
1296 Loc : constant Source_Ptr := Sloc (N);
1297 Inst_Case : constant Boolean := Is_Generic_Unit (E);
1299 Sbody : Node_Id;
1300 Ebody : Entity_Id;
1302 function Process (N : Node_Id) return Traverse_Result;
1303 -- Function applied to each node as we traverse the body.
1304 -- Checks for call that needs checking, and if so checks
1305 -- it. Always returns OK, so entire tree is traversed.
1307 function Process (N : Node_Id) return Traverse_Result is
1308 begin
1309 -- If user has specified that there are no entry calls in elaboration
1310 -- code, do not trace past an accept statement, because the rendez-
1311 -- vous will happen after elaboration.
1313 if (Nkind (Original_Node (N)) = N_Accept_Statement
1314 or else Nkind (Original_Node (N)) = N_Selective_Accept)
1315 and then Restrictions (No_Entry_Calls_In_Elaboration_Code)
1316 then
1317 return Abandon;
1319 -- If we have a subprogram call, check it
1321 elsif Nkind (N) = N_Function_Call
1322 or else Nkind (N) = N_Procedure_Call_Statement
1323 then
1324 Check_Elab_Call (N, Outer_Scope);
1325 return OK;
1327 -- If we have a generic instantiation, check it
1329 elsif Nkind (N) in N_Generic_Instantiation then
1330 Check_Elab_Instantiation (N, Outer_Scope);
1331 return OK;
1333 -- Skip subprogram bodies that come from source (wait for
1334 -- call to analyze these). The reason for the come from
1335 -- source test is to avoid catching task bodies.
1337 -- For task bodies, we should really avoid these too, waiting
1338 -- for the task activation, but that's too much trouble to
1339 -- catch for now, so we go in unconditionally. This is not
1340 -- so terrible, it means the error backtrace is not quite
1341 -- complete, and we are too eager to scan bodies of tasks
1342 -- that are unused, but this is hardly very significant!
1344 elsif Nkind (N) = N_Subprogram_Body
1345 and then Comes_From_Source (N)
1346 then
1347 return Skip;
1349 else
1350 return OK;
1351 end if;
1352 end Process;
1354 procedure Traverse is new Atree.Traverse_Proc;
1355 -- Traverse procedure using above Process function
1357 -- Start of processing for Check_Internal_Call_Continue
1359 begin
1360 -- Save outer level call if at outer level
1362 if Elab_Call.Last = 0 then
1363 Outer_Level_Sloc := Loc;
1364 end if;
1366 Elab_Visited.Increment_Last;
1367 Elab_Visited.Table (Elab_Visited.Last) := E;
1369 -- If the call is to a function that renames a literal, no check
1370 -- is needed.
1372 if Ekind (E) = E_Enumeration_Literal then
1373 return;
1374 end if;
1376 Sbody := Unit_Declaration_Node (E);
1378 if Nkind (Sbody) /= N_Subprogram_Body
1379 and then
1380 Nkind (Sbody) /= N_Package_Body
1381 then
1382 Ebody := Corresponding_Body (Sbody);
1384 if No (Ebody) then
1385 return;
1386 else
1387 Sbody := Unit_Declaration_Node (Ebody);
1388 end if;
1389 end if;
1391 -- If the body appears after the outer level call or
1392 -- instantiation then we have an error case handled below.
1394 if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody))
1395 and then not In_Task_Activation
1396 then
1397 null;
1399 -- If we have the instantiation case we are done, since we now
1400 -- know that the body of the generic appeared earlier.
1402 elsif Inst_Case then
1403 return;
1405 -- Otherwise we have a call, so we trace through the called
1406 -- body to see if it has any problems ..
1408 else
1409 pragma Assert (Nkind (Sbody) = N_Subprogram_Body);
1411 Elab_Call.Increment_Last;
1412 Elab_Call.Table (Elab_Call.Last).Cloc := Loc;
1413 Elab_Call.Table (Elab_Call.Last).Ent := E;
1415 if Debug_Flag_LL then
1416 Write_Str ("Elab_Call.Last = ");
1417 Write_Int (Int (Elab_Call.Last));
1418 Write_Str (" Ent = ");
1419 Write_Name (Chars (E));
1420 Write_Str (" at ");
1421 Write_Location (Sloc (N));
1422 Write_Eol;
1423 end if;
1425 -- Now traverse declarations and statements of subprogram body.
1426 -- Note that we cannot simply Traverse (Sbody), since traverse
1427 -- does not normally visit subprogram bodies.
1429 declare
1430 Decl : Node_Id := First (Declarations (Sbody));
1432 begin
1433 while Present (Decl) loop
1434 Traverse (Decl);
1435 Next (Decl);
1436 end loop;
1437 end;
1439 Traverse (Handled_Statement_Sequence (Sbody));
1441 Elab_Call.Decrement_Last;
1442 return;
1443 end if;
1445 -- Here is the case of calling a subprogram where the body has
1446 -- not yet been encountered, a warning message is needed.
1448 Warn_On_Instance := True;
1450 -- If we have nothing in the call stack, then this is at the
1451 -- outer level, and the ABE is bound to occur.
1453 if Elab_Call.Last = 0 then
1455 if Inst_Case then
1456 Error_Msg_NE
1457 ("?cannot instantiate& before body seen", N, Orig_Ent);
1458 else
1459 Error_Msg_NE
1460 ("?cannot call& before body seen", N, Orig_Ent);
1461 end if;
1463 Error_Msg_N
1464 ("\?Program_Error will be raised at run time", N);
1465 Insert_Elab_Check (N);
1467 -- Call is not at outer level
1469 else
1470 -- Deal with dynamic elaboration check
1472 if not Elaboration_Checks_Suppressed (E) then
1473 Set_Elaboration_Entity_Required (E);
1475 -- Case of no elaboration entity allocated yet
1477 if No (Elaboration_Entity (E)) then
1479 -- Create object declaration for elaboration entity, and put it
1480 -- just in front of the spec of the subprogram or generic unit,
1481 -- in the same scope as this unit.
1483 declare
1484 Loce : constant Source_Ptr := Sloc (E);
1485 Ent : constant Entity_Id :=
1486 Make_Defining_Identifier (Loc,
1487 Chars => New_External_Name (Chars (E), 'E'));
1489 begin
1490 Set_Elaboration_Entity (E, Ent);
1491 New_Scope (Scope (E));
1493 Insert_Action (Declaration_Node (E),
1494 Make_Object_Declaration (Loce,
1495 Defining_Identifier => Ent,
1496 Object_Definition =>
1497 New_Occurrence_Of (Standard_Boolean, Loce),
1498 Expression => New_Occurrence_Of (Standard_False, Loce)));
1500 -- Set elaboration flag at the point of the body
1502 Set_Elaboration_Flag (Sbody, E);
1504 Pop_Scope;
1505 end;
1506 end if;
1508 -- Generate check of the elaboration Boolean
1510 Insert_Elab_Check (N,
1511 New_Occurrence_Of (Elaboration_Entity (E), Loc));
1512 end if;
1514 -- Generate the warning
1516 if not Suppress_Elaboration_Warnings (E) then
1517 if Inst_Case then
1518 Error_Msg_NE
1519 ("instantiation of& may occur before body is seen?",
1520 N, Orig_Ent);
1521 else
1522 Error_Msg_NE
1523 ("call to& may occur before body is seen?", N, Orig_Ent);
1524 end if;
1526 Error_Msg_N
1527 ("\Program_Error may be raised at run time?", N);
1529 Output_Calls (N);
1530 end if;
1531 end if;
1533 Warn_On_Instance := False;
1535 -- Set flag to suppress further warnings on same subprogram
1536 -- unless in all errors mode
1538 if not All_Errors_Mode then
1539 Set_Suppress_Elaboration_Warnings (E);
1540 end if;
1541 end Check_Internal_Call_Continue;
1543 ----------------------------
1544 -- Check_Task_Activation --
1545 ----------------------------
1547 procedure Check_Task_Activation (N : Node_Id) is
1548 Loc : constant Source_Ptr := Sloc (N);
1549 Ent : Entity_Id;
1550 P : Entity_Id;
1551 Task_Scope : Entity_Id;
1552 Cunit_SC : Boolean := False;
1553 Decl : Node_Id;
1554 Elmt : Elmt_Id;
1555 Inter_Procs : Elist_Id := New_Elmt_List;
1556 Intra_Procs : Elist_Id := New_Elmt_List;
1557 Enclosing : Entity_Id;
1559 procedure Add_Task_Proc (Typ : Entity_Id);
1560 -- Add to Task_Procs the task body procedure(s) of task types in Typ.
1561 -- For record types, this procedure recurses over component types.
1563 procedure Collect_Tasks (Decls : List_Id);
1564 -- Collect the types of the tasks that are to be activated in the given
1565 -- list of declarations, in order to perform elaboration checks on the
1566 -- corresponding task procedures which are called implicitly here.
1568 function Outer_Unit (E : Entity_Id) return Entity_Id;
1569 -- find enclosing compilation unit of Entity, ignoring subunits, or
1570 -- else enclosing subprogram. If E is not a package, there is no need
1571 -- for inter-unit elaboration checks.
1573 -------------------
1574 -- Add_Task_Proc --
1575 -------------------
1577 procedure Add_Task_Proc (Typ : Entity_Id) is
1578 Comp : Entity_Id;
1579 Proc : Entity_Id := Empty;
1581 begin
1582 if Is_Task_Type (Typ) then
1583 Proc := Get_Task_Body_Procedure (Typ);
1585 elsif Is_Array_Type (Typ)
1586 and then Has_Task (Base_Type (Typ))
1587 then
1588 Add_Task_Proc (Component_Type (Typ));
1590 elsif Is_Record_Type (Typ)
1591 and then Has_Task (Base_Type (Typ))
1592 then
1593 Comp := First_Component (Typ);
1595 while Present (Comp) loop
1596 Add_Task_Proc (Etype (Comp));
1597 Comp := Next_Component (Comp);
1598 end loop;
1599 end if;
1601 -- If the task type is another unit, we will perform the usual
1602 -- elaboration check on its enclosing unit. If the type is in the
1603 -- same unit, we can trace the task body as for an internal call,
1604 -- but we only need to examine other external calls, because at
1605 -- the point the task is activated, internal subprogram bodies
1606 -- will have been elaborated already. We keep separate lists for
1607 -- each kind of task.
1609 -- Skip this test if errors have occurred, since in this case
1610 -- we can get false indications.
1612 if Total_Errors_Detected /= 0 then
1613 return;
1614 end if;
1616 if Present (Proc) then
1617 if Outer_Unit (Scope (Proc)) = Enclosing then
1619 if No (Corresponding_Body (Unit_Declaration_Node (Proc)))
1620 and then
1621 (not Is_Generic_Instance (Scope (Proc))
1622 or else
1623 Scope (Proc) = Scope (Defining_Identifier (Decl)))
1624 then
1625 Error_Msg_N
1626 ("task will be activated before elaboration of its body?",
1627 Decl);
1628 Error_Msg_N
1629 ("Program_Error will be raised at run-time?", Decl);
1631 elsif
1632 Present (Corresponding_Body (Unit_Declaration_Node (Proc)))
1633 then
1634 Append_Elmt (Proc, Intra_Procs);
1635 end if;
1637 else
1638 Elmt := First_Elmt (Inter_Procs);
1640 -- No need for multiple entries of the same type.
1642 while Present (Elmt) loop
1643 if Node (Elmt) = Proc then
1644 return;
1645 end if;
1647 Next_Elmt (Elmt);
1648 end loop;
1650 Append_Elmt (Proc, Inter_Procs);
1651 end if;
1652 end if;
1653 end Add_Task_Proc;
1655 -------------------
1656 -- Collect_Tasks --
1657 -------------------
1659 procedure Collect_Tasks (Decls : List_Id) is
1660 begin
1661 if Present (Decls) then
1662 Decl := First (Decls);
1664 while Present (Decl) loop
1666 if Nkind (Decl) = N_Object_Declaration
1667 and then Has_Task (Etype (Defining_Identifier (Decl)))
1668 then
1669 Add_Task_Proc (Etype (Defining_Identifier (Decl)));
1670 end if;
1672 Next (Decl);
1673 end loop;
1674 end if;
1675 end Collect_Tasks;
1677 ----------------
1678 -- Outer_Unit --
1679 ----------------
1681 function Outer_Unit (E : Entity_Id) return Entity_Id is
1682 Outer : Entity_Id := E;
1684 begin
1685 while Present (Outer) loop
1686 if Suppress_Elaboration_Checks (Outer) then
1687 Cunit_SC := True;
1688 end if;
1690 exit when Is_Child_Unit (Outer)
1691 or else Scope (Outer) = Standard_Standard
1692 or else Ekind (Outer) /= E_Package;
1693 Outer := Scope (Outer);
1694 end loop;
1696 return Outer;
1697 end Outer_Unit;
1699 -- Start of processing for Check_Task_Activation
1701 begin
1702 Enclosing := Outer_Unit (Current_Scope);
1704 -- Find all tasks declared in the current unit.
1706 if Nkind (N) = N_Package_Body then
1707 P := Unit_Declaration_Node (Corresponding_Spec (N));
1709 Collect_Tasks (Declarations (N));
1710 Collect_Tasks (Visible_Declarations (Specification (P)));
1711 Collect_Tasks (Private_Declarations (Specification (P)));
1713 elsif Nkind (N) = N_Package_Declaration then
1714 Collect_Tasks (Visible_Declarations (Specification (N)));
1715 Collect_Tasks (Private_Declarations (Specification (N)));
1717 else
1718 Collect_Tasks (Declarations (N));
1719 end if;
1721 -- We only perform detailed checks in all tasks are library level
1722 -- entities. If the master is a subprogram or task, activation will
1723 -- depend on the activation of the master itself.
1724 -- Should dynamic checks be added in the more general case???
1726 if Ekind (Enclosing) /= E_Package then
1727 return;
1728 end if;
1730 -- For task types defined in other units, we want the unit containing
1731 -- the task body to be elaborated before the current one.
1733 Elmt := First_Elmt (Inter_Procs);
1735 while Present (Elmt) loop
1736 Ent := Node (Elmt);
1737 Task_Scope := Outer_Unit (Scope (Ent));
1739 if not Is_Compilation_Unit (Task_Scope) then
1740 null;
1742 elsif Suppress_Elaboration_Warnings (Task_Scope) then
1743 null;
1745 elsif Dynamic_Elaboration_Checks then
1746 if not Elaboration_Checks_Suppressed (Ent)
1747 and then not Cunit_SC
1748 and then not Restrictions (No_Entry_Calls_In_Elaboration_Code)
1749 then
1750 -- Runtime elaboration check required. generate check of the
1751 -- elaboration Boolean for the unit containing the entity.
1753 Insert_Elab_Check (N,
1754 Make_Attribute_Reference (Loc,
1755 Attribute_Name => Name_Elaborated,
1756 Prefix =>
1757 New_Occurrence_Of
1758 (Spec_Entity (Task_Scope), Loc)));
1759 end if;
1761 else
1762 -- Force the binder to elaborate other unit first.
1764 if not Suppress_Elaboration_Warnings (Ent)
1765 and then Elab_Warnings
1766 and then not Suppress_Elaboration_Warnings (Task_Scope)
1767 then
1768 Error_Msg_Node_2 := Task_Scope;
1769 Error_Msg_NE ("activation of an instance of task type&" &
1770 " requires pragma Elaborate_All on &?", N, Ent);
1771 end if;
1773 Set_Elaborate_All_Desirable (Task_Scope);
1774 Set_Suppress_Elaboration_Warnings (Task_Scope);
1775 end if;
1777 Next_Elmt (Elmt);
1778 end loop;
1780 -- For tasks declared in the current unit, trace other calls within
1781 -- the task procedure bodies, which are available.
1783 In_Task_Activation := True;
1784 Elmt := First_Elmt (Intra_Procs);
1786 while Present (Elmt) loop
1787 Ent := Node (Elmt);
1788 Check_Internal_Call_Continue (N, Ent, Enclosing, Ent);
1789 Next_Elmt (Elmt);
1790 end loop;
1792 In_Task_Activation := False;
1793 end Check_Task_Activation;
1795 ----------------------
1796 -- Has_Generic_Body --
1797 ----------------------
1799 function Has_Generic_Body (N : Node_Id) return Boolean is
1800 Ent : constant Entity_Id := Get_Generic_Entity (N);
1801 Decl : constant Node_Id := Unit_Declaration_Node (Ent);
1802 Scop : Entity_Id;
1804 function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id;
1805 -- Determine if the list of nodes headed by N and linked by Next
1806 -- contains a package body for the package spec entity E, and if
1807 -- so return the package body. If not, then returns Empty.
1809 function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id;
1810 -- This procedure is called load the unit whose name is given by Nam.
1811 -- This unit is being loaded to see whether it contains an optional
1812 -- generic body. The returned value is the loaded unit, which is
1813 -- always a package body (only package bodies can contain other
1814 -- entities in the sense in which Has_Generic_Body is interested).
1815 -- We only attempt to load bodies if we are generating code. If we
1816 -- are in semantics check only mode, then it would be wrong to load
1817 -- bodies that are not required from a semantic point of view, so
1818 -- in this case we return Empty. The result is that the caller may
1819 -- incorrectly decide that a generic spec does not have a body when
1820 -- in fact it does, but the only harm in this is that some warnings
1821 -- on elaboration problems may be lost in semantic checks only mode,
1822 -- which is not big loss. We also return Empty if we go for a body
1823 -- and it is not there.
1825 function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id;
1826 -- PE is the entity for a package spec. This function locates the
1827 -- corresponding package body, returning Empty if none is found.
1828 -- The package body returned is fully parsed but may not yet be
1829 -- analyzed, so only syntactic fields should be referenced.
1831 ------------------
1832 -- Find_Body_In --
1833 ------------------
1835 function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is
1836 Nod : Node_Id;
1838 begin
1839 Nod := N;
1840 while Present (Nod) loop
1842 -- If we found the package body we are looking for, return it
1844 if Nkind (Nod) = N_Package_Body
1845 and then Chars (Defining_Unit_Name (Nod)) = Chars (E)
1846 then
1847 return Nod;
1849 -- If we found the stub for the body, go after the subunit,
1850 -- loading it if necessary.
1852 elsif Nkind (Nod) = N_Package_Body_Stub
1853 and then Chars (Defining_Identifier (Nod)) = Chars (E)
1854 then
1855 if Present (Library_Unit (Nod)) then
1856 return Unit (Library_Unit (Nod));
1858 else
1859 return Load_Package_Body (Get_Unit_Name (Nod));
1860 end if;
1862 -- If neither package body nor stub, keep looking on chain
1864 else
1865 Next (Nod);
1866 end if;
1867 end loop;
1869 return Empty;
1870 end Find_Body_In;
1872 -----------------------
1873 -- Load_Package_Body --
1874 -----------------------
1876 function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is
1877 U : Unit_Number_Type;
1879 begin
1880 if Operating_Mode /= Generate_Code then
1881 return Empty;
1882 else
1883 U :=
1884 Load_Unit
1885 (Load_Name => Nam,
1886 Required => False,
1887 Subunit => False,
1888 Error_Node => N);
1890 if U = No_Unit then
1891 return Empty;
1892 else
1893 return Unit (Cunit (U));
1894 end if;
1895 end if;
1896 end Load_Package_Body;
1898 -------------------------------
1899 -- Locate_Corresponding_Body --
1900 -------------------------------
1902 function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is
1903 Spec : constant Node_Id := Declaration_Node (PE);
1904 Decl : constant Node_Id := Parent (Spec);
1905 Scop : constant Entity_Id := Scope (PE);
1906 PBody : Node_Id;
1908 begin
1909 if Is_Library_Level_Entity (PE) then
1911 -- If package is a library unit that requires a body, we have
1912 -- no choice but to go after that body because it might contain
1913 -- an optional body for the original generic package.
1915 if Unit_Requires_Body (PE) then
1917 -- Load the body. Note that we are a little careful here to
1918 -- use Spec to get the unit number, rather than PE or Decl,
1919 -- since in the case where the package is itself a library
1920 -- level instantiation, Spec will properly reference the
1921 -- generic template, which is what we really want.
1923 return
1924 Load_Package_Body
1925 (Get_Body_Name (Unit_Name (Get_Source_Unit (Spec))));
1927 -- But if the package is a library unit that does NOT require
1928 -- a body, then no body is permitted, so we are sure that there
1929 -- is no body for the original generic package.
1931 else
1932 return Empty;
1933 end if;
1935 -- Otherwise look and see if we are embedded in a further package
1937 elsif Is_Package (Scop) then
1939 -- If so, get the body of the enclosing package, and look in
1940 -- its package body for the package body we are looking for.
1942 PBody := Locate_Corresponding_Body (Scop);
1944 if No (PBody) then
1945 return Empty;
1946 else
1947 return Find_Body_In (PE, First (Declarations (PBody)));
1948 end if;
1950 -- If we are not embedded in a further package, then the body
1951 -- must be in the same declarative part as we are.
1953 else
1954 return Find_Body_In (PE, Next (Decl));
1955 end if;
1956 end Locate_Corresponding_Body;
1958 -- Start of processing for Has_Generic_Body
1960 begin
1961 if Present (Corresponding_Body (Decl)) then
1962 return True;
1964 elsif Unit_Requires_Body (Ent) then
1965 return True;
1967 -- Compilation units cannot have optional bodies
1969 elsif Is_Compilation_Unit (Ent) then
1970 return False;
1972 -- Otherwise look at what scope we are in
1974 else
1975 Scop := Scope (Ent);
1977 -- Case of entity is in other than a package spec, in this case
1978 -- the body, if present, must be in the same declarative part.
1980 if not Is_Package (Scop) then
1981 declare
1982 P : Node_Id;
1984 begin
1985 P := Declaration_Node (Ent);
1987 -- Declaration node may get us a spec, so if so, go to
1988 -- the parent declaration.
1990 while not Is_List_Member (P) loop
1991 P := Parent (P);
1992 end loop;
1994 return Present (Find_Body_In (Ent, Next (P)));
1995 end;
1997 -- If the entity is in a package spec, then we have to locate
1998 -- the corresponding package body, and look there.
2000 else
2001 declare
2002 PBody : constant Node_Id := Locate_Corresponding_Body (Scop);
2004 begin
2005 if No (PBody) then
2006 return False;
2007 else
2008 return
2009 Present
2010 (Find_Body_In (Ent, (First (Declarations (PBody)))));
2011 end if;
2012 end;
2013 end if;
2014 end if;
2015 end Has_Generic_Body;
2017 -----------------------
2018 -- Insert_Elab_Check --
2019 -----------------------
2021 procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is
2022 Nod : Node_Id;
2023 Loc : constant Source_Ptr := Sloc (N);
2025 begin
2026 -- If expansion is disabled, do not generate any checks. Also
2027 -- skip checks if any subunits are missing because in either
2028 -- case we lack the full information that we need, and no object
2029 -- file will be created in any case.
2031 if not Expander_Active or else Subunits_Missing then
2032 return;
2033 end if;
2035 -- If we have a generic instantiation, where Instance_Spec is set,
2036 -- then this field points to a generic instance spec that has
2037 -- been inserted before the instantiation node itself, so that
2038 -- is where we want to insert a check.
2040 if Nkind (N) in N_Generic_Instantiation
2041 and then Present (Instance_Spec (N))
2042 then
2043 Nod := Instance_Spec (N);
2044 else
2045 Nod := N;
2046 end if;
2048 -- If we are inserting at the top level, insert in Aux_Decls
2050 if Nkind (Parent (Nod)) = N_Compilation_Unit then
2051 declare
2052 ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod));
2053 R : Node_Id;
2055 begin
2056 if No (C) then
2057 R :=
2058 Make_Raise_Program_Error (Loc,
2059 Reason => PE_Access_Before_Elaboration);
2060 else
2061 R :=
2062 Make_Raise_Program_Error (Loc,
2063 Condition => Make_Op_Not (Loc, C),
2064 Reason => PE_Access_Before_Elaboration);
2065 end if;
2067 if No (Declarations (ADN)) then
2068 Set_Declarations (ADN, New_List (R));
2069 else
2070 Append_To (Declarations (ADN), R);
2071 end if;
2073 Analyze (R);
2074 end;
2076 -- Otherwise just insert before the node in question. However, if
2077 -- the context of the call has already been analyzed, an insertion
2078 -- will not work if it depends on subsequent expansion (e.g. a call in
2079 -- a branch of a short-circuit). In that case we replace the call with
2080 -- a conditional expression, or with a Raise if it is unconditional.
2081 -- Unfortunately this does not work if the call has a dynamic size,
2082 -- because gigi regards it as a dynamic-sized temporary. If such a call
2083 -- appears in a short-circuit expression, the elaboration check will be
2084 -- missed (rare enough ???).
2086 else
2087 if Nkind (N) = N_Function_Call
2088 and then Analyzed (Parent (N))
2089 and then Size_Known_At_Compile_Time (Etype (N))
2090 then
2091 declare
2092 Typ : constant Entity_Id := Etype (N);
2093 Chk : constant Boolean := Do_Range_Check (N);
2095 R : constant Node_Id :=
2096 Make_Raise_Program_Error (Loc,
2097 Reason => PE_Access_Before_Elaboration);
2099 begin
2100 Set_Etype (R, Typ);
2102 if No (C) then
2103 Rewrite (N, R);
2105 else
2106 Rewrite (N,
2107 Make_Conditional_Expression (Loc,
2108 Expressions => New_List (C, Relocate_Node (N), R)));
2109 end if;
2111 Analyze_And_Resolve (N, Typ);
2113 -- If the original call requires a range check, so does the
2114 -- conditional expression.
2116 if Chk then
2117 Enable_Range_Check (N);
2118 else
2119 Set_Do_Range_Check (N, False);
2120 end if;
2121 end;
2123 else
2124 if No (C) then
2125 Insert_Action (Nod,
2126 Make_Raise_Program_Error (Loc,
2127 Reason => PE_Access_Before_Elaboration));
2128 else
2129 Insert_Action (Nod,
2130 Make_Raise_Program_Error (Loc,
2131 Condition =>
2132 Make_Op_Not (Loc,
2133 Right_Opnd => C),
2134 Reason => PE_Access_Before_Elaboration));
2135 end if;
2136 end if;
2137 end if;
2138 end Insert_Elab_Check;
2140 ------------------
2141 -- Output_Calls --
2142 ------------------
2144 procedure Output_Calls (N : Node_Id) is
2145 Ent : Entity_Id;
2147 function Is_Printable_Error_Name (Nm : Name_Id) return Boolean;
2148 -- An internal function, used to determine if a name, Nm, is either
2149 -- a non-internal name, or is an internal name that is printable
2150 -- by the error message circuits (i.e. it has a single upper
2151 -- case letter at the end).
2153 function Is_Printable_Error_Name (Nm : Name_Id) return Boolean is
2154 begin
2155 if not Is_Internal_Name (Nm) then
2156 return True;
2158 elsif Name_Len = 1 then
2159 return False;
2161 else
2162 Name_Len := Name_Len - 1;
2163 return not Is_Internal_Name;
2164 end if;
2165 end Is_Printable_Error_Name;
2167 -- Start of processing for Output_Calls
2169 begin
2170 for J in reverse 1 .. Elab_Call.Last loop
2171 Error_Msg_Sloc := Elab_Call.Table (J).Cloc;
2173 Ent := Elab_Call.Table (J).Ent;
2175 if Is_Generic_Unit (Ent) then
2176 Error_Msg_NE ("\?& instantiated #", N, Ent);
2178 elsif Chars (Ent) = Name_uInit_Proc then
2179 Error_Msg_N ("\?initialization procedure called #", N);
2181 elsif Is_Printable_Error_Name (Chars (Ent)) then
2182 Error_Msg_NE ("\?& called #", N, Ent);
2184 else
2185 Error_Msg_N ("\? called #", N);
2186 end if;
2187 end loop;
2188 end Output_Calls;
2190 ----------------------------
2191 -- Same_Elaboration_Scope --
2192 ----------------------------
2194 function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is
2195 S1 : Entity_Id := Scop1;
2196 S2 : Entity_Id := Scop2;
2198 begin
2199 while S1 /= Standard_Standard
2200 and then (Ekind (S1) = E_Package
2201 or else
2202 Ekind (S1) = E_Block)
2203 loop
2204 S1 := Scope (S1);
2205 end loop;
2207 while S2 /= Standard_Standard
2208 and then (Ekind (S2) = E_Package
2209 or else
2210 Ekind (S2) = E_Protected_Type
2211 or else
2212 Ekind (S2) = E_Block)
2213 loop
2214 S2 := Scope (S2);
2215 end loop;
2217 return S1 = S2;
2218 end Same_Elaboration_Scope;
2220 -----------------
2221 -- Set_C_Scope --
2222 -----------------
2224 procedure Set_C_Scope is
2225 begin
2226 while not Is_Compilation_Unit (C_Scope) loop
2227 C_Scope := Scope (C_Scope);
2228 end loop;
2229 end Set_C_Scope;
2231 -----------------
2232 -- Spec_Entity --
2233 -----------------
2235 function Spec_Entity (E : Entity_Id) return Entity_Id is
2236 Decl : Node_Id;
2238 begin
2239 -- Check for case of body entity
2240 -- Why is the check for E_Void needed???
2242 if Ekind (E) = E_Void
2243 or else Ekind (E) = E_Subprogram_Body
2244 or else Ekind (E) = E_Package_Body
2245 then
2246 Decl := E;
2248 loop
2249 Decl := Parent (Decl);
2250 exit when Nkind (Decl) in N_Proper_Body;
2251 end loop;
2253 return Corresponding_Spec (Decl);
2255 else
2256 return E;
2257 end if;
2258 end Spec_Entity;
2260 -------------------
2261 -- Supply_Bodies --
2262 -------------------
2264 procedure Supply_Bodies (N : Node_Id) is
2265 begin
2266 if Nkind (N) = N_Subprogram_Declaration then
2267 declare
2268 Ent : constant Entity_Id := Defining_Unit_Name (Specification (N));
2270 begin
2271 Set_Is_Imported (Ent);
2272 Set_Convention (Ent, Convention_Stubbed);
2273 end;
2275 elsif Nkind (N) = N_Package_Declaration then
2276 declare
2277 Spec : constant Node_Id := Specification (N);
2279 begin
2280 New_Scope (Defining_Unit_Name (Spec));
2281 Supply_Bodies (Visible_Declarations (Spec));
2282 Supply_Bodies (Private_Declarations (Spec));
2283 Pop_Scope;
2284 end;
2285 end if;
2286 end Supply_Bodies;
2288 procedure Supply_Bodies (L : List_Id) is
2289 Elmt : Node_Id;
2291 begin
2292 if Present (L) then
2293 Elmt := First (L);
2294 while Present (Elmt) loop
2295 Supply_Bodies (Elmt);
2296 Next (Elmt);
2297 end loop;
2298 end if;
2299 end Supply_Bodies;
2301 ------------
2302 -- Within --
2303 ------------
2305 function Within (E1, E2 : Entity_Id) return Boolean is
2306 Scop : Entity_Id;
2308 begin
2309 Scop := E1;
2311 loop
2312 if Scop = E2 then
2313 return True;
2315 elsif Scop = Standard_Standard then
2316 return False;
2318 else
2319 Scop := Scope (Scop);
2320 end if;
2321 end loop;
2323 raise Program_Error;
2324 end Within;
2326 --------------------------
2327 -- Within_Elaborate_All --
2328 --------------------------
2330 function Within_Elaborate_All (E : Entity_Id) return Boolean is
2331 Item : Node_Id;
2332 Item2 : Node_Id;
2333 Elab_Id : Entity_Id;
2334 Par : Node_Id;
2336 begin
2337 Item := First (Context_Items (Cunit (Current_Sem_Unit)));
2339 while Present (Item) loop
2340 if Nkind (Item) = N_Pragma
2341 and then Get_Pragma_Id (Chars (Item)) = Pragma_Elaborate_All
2342 then
2343 Elab_Id :=
2344 Entity (
2345 Expression (First (Pragma_Argument_Associations (Item))));
2346 Par := Parent (Unit_Declaration_Node (Elab_Id));
2347 Item2 := First (Context_Items (Par));
2349 while Present (Item2) loop
2350 if Nkind (Item2) = N_With_Clause
2351 and then Entity (Name (Item2)) = E
2352 then
2353 return True;
2354 end if;
2356 Next (Item2);
2357 end loop;
2358 end if;
2360 Next (Item);
2361 end loop;
2363 return False;
2364 end Within_Elaborate_All;
2366 end Sem_Elab;