1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1997-2005 Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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_Tss
; use Exp_Tss
;
34 with Exp_Util
; use Exp_Util
;
35 with Expander
; use Expander
;
36 with Fname
; use Fname
;
38 with Lib
.Load
; use Lib
.Load
;
39 with Namet
; use Namet
;
40 with Nlists
; use Nlists
;
41 with Nmake
; use Nmake
;
43 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
47 with Sem_Cat
; use Sem_Cat
;
48 with Sem_Ch7
; use Sem_Ch7
;
49 with Sem_Ch8
; use Sem_Ch8
;
50 with Sem_Res
; use Sem_Res
;
51 with Sem_Util
; use Sem_Util
;
52 with Sinfo
; use Sinfo
;
53 with Sinput
; use Sinput
;
54 with Snames
; use Snames
;
55 with Stand
; use Stand
;
57 with Tbuild
; use Tbuild
;
58 with Uname
; use Uname
;
60 package body Sem_Elab
is
62 -- The following table records the recursive call chain for output
63 -- in the Output routine. Each entry records the call node and the
64 -- entity of the called routine. The number of entries in the table
65 -- (i.e. the value of Elab_Call.Last) indicates the current depth
66 -- of recursion and is used to identify the outer level.
68 type Elab_Call_Entry
is record
73 package Elab_Call
is new Table
.Table
(
74 Table_Component_Type
=> Elab_Call_Entry
,
75 Table_Index_Type
=> Int
,
78 Table_Increment
=> 100,
79 Table_Name
=> "Elab_Call");
81 -- This table is initialized at the start of each outer level call.
82 -- It holds the entities for all subprograms that have been examined
83 -- for this particular outer level call, and is used to prevent both
84 -- infinite recursion, and useless reanalysis of bodies already seen
86 package Elab_Visited
is new Table
.Table
(
87 Table_Component_Type
=> Entity_Id
,
88 Table_Index_Type
=> Int
,
91 Table_Increment
=> 100,
92 Table_Name
=> "Elab_Visited");
94 -- This table stores calls to Check_Internal_Call that are delayed
95 -- until all generics are instantiated, and in particular that all
96 -- generic bodies have been inserted. We need to delay, because we
97 -- need to be able to look through the inserted bodies.
99 type Delay_Element
is record
101 -- The parameter N from the call to Check_Internal_Call. Note that
102 -- this node may get rewritten over the delay period by expansion
103 -- in the call case (but not in the instantiation case).
106 -- The parameter E from the call to Check_Internal_Call
108 Orig_Ent
: Entity_Id
;
109 -- The parameter Orig_Ent from the call to Check_Internal_Call
112 -- The current scope of the call. This is restored when we complete
113 -- the delayed call, so that we do this in the right scope.
115 From_Elab_Code
: Boolean;
116 -- Save indication of whether this call is from elaboration code
118 Outer_Scope
: Entity_Id
;
119 -- Save scope of outer level call
123 package Delay_Check
is new Table
.Table
(
124 Table_Component_Type
=> Delay_Element
,
125 Table_Index_Type
=> Int
,
126 Table_Low_Bound
=> 1,
127 Table_Initial
=> 1000,
128 Table_Increment
=> 100,
129 Table_Name
=> "Delay_Check");
132 -- Top level scope of current scope. We need to compute this only
133 -- once at the outer level, i.e. for a call to Check_Elab_Call from
134 -- outside this unit.
136 Outer_Level_Sloc
: Source_Ptr
;
137 -- Save Sloc value for outer level call node for comparisons of source
138 -- locations. A body is too late if it appears after the *outer* level
139 -- call, not the particular call that is being analyzed.
141 From_Elab_Code
: Boolean;
142 -- This flag shows whether the outer level call currently being examined
143 -- is or is not in elaboration code. We are only interested in calls to
144 -- routines in other units if this flag is True.
146 In_Task_Activation
: Boolean := False;
147 -- This flag indicates whether we are performing elaboration checks on
148 -- task procedures, at the point of activation. If true, we do not trace
149 -- internal calls in these procedures, because all local bodies are known
152 Delaying_Elab_Checks
: Boolean := True;
153 -- This is set True till the compilation is complete, including the
154 -- insertion of all instance bodies. Then when Check_Elab_Calls is
155 -- called, the delay table is used to make the delayed calls and
156 -- this flag is reset to False, so that the calls are processed
158 -----------------------
159 -- Local Subprograms --
160 -----------------------
162 -- Note: Outer_Scope in all following specs represents the scope of
163 -- interest of the outer level call. If it is set to Standard_Standard,
164 -- then it means the outer level call was at elaboration level, and that
165 -- thus all calls are of interest. If it was set to some other scope,
166 -- then the original call was an inner call, and we are not interested
167 -- in calls that go outside this scope.
169 procedure Check_A_Call
172 Outer_Scope
: Entity_Id
;
173 Inter_Unit_Only
: Boolean;
174 Generate_Warnings
: Boolean := True);
175 -- This is the internal recursive routine that is called to check for
176 -- a possible elaboration error. The argument N is a subprogram call
177 -- or generic instantiation to be checked, and E is the entity of
178 -- the called subprogram, or instantiated generic unit. The flag
179 -- Outer_Scope is the outer level scope for the original call.
180 -- Inter_Unit_Only is set if the call is only to be checked in the
181 -- case where it is to another unit (and skipped if within a unit).
182 -- Generate_Warnings is set to False to suppress warning messages
183 -- about missing pragma Elaborate_All's. These messages are not
184 -- wanted for inner calls in the dynamic model.
186 procedure Check_Bad_Instantiation
(N
: Node_Id
);
187 -- N is a node for an instantiation (if called with any other node kind,
188 -- Check_Bad_Instantiation ignores the call). This subprogram checks for
189 -- the special case of a generic instantiation of a generic spec in the
190 -- same declarative part as the instantiation where a body is present and
191 -- has not yet been seen. This is an obvious error, but needs to be checked
192 -- specially at the time of the instantiation, since it is a case where we
193 -- cannot insert the body anywhere. If this case is detected, warnings are
194 -- generated, and a raise of Program_Error is inserted. In addition any
195 -- subprograms in the generic spec are stubbed, and the Bad_Instantiation
196 -- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
197 -- flag as an indication that no attempt should be made to insert an
200 procedure Check_Internal_Call
203 Outer_Scope
: Entity_Id
;
204 Orig_Ent
: Entity_Id
);
205 -- N is a function call or procedure statement call node and E is
206 -- the entity of the called function, which is within the current
207 -- compilation unit (where subunits count as part of the parent).
208 -- This call checks if this call, or any call within any accessed
209 -- body could cause an ABE, and if so, outputs a warning. Orig_Ent
210 -- differs from E only in the case of renamings, and points to the
211 -- original name of the entity. This is used for error messages.
212 -- Outer_Scope is the outer level scope for the original call.
214 procedure Check_Internal_Call_Continue
217 Outer_Scope
: Entity_Id
;
218 Orig_Ent
: Entity_Id
);
219 -- The processing for Check_Internal_Call is divided up into two phases,
220 -- and this represents the second phase. The second phase is delayed if
221 -- Delaying_Elab_Calls is set to True. In this delayed case, the first
222 -- phase makes an entry in the Delay_Check table, which is processed
223 -- when Check_Elab_Calls is called. N, E and Orig_Ent are as for the call
224 -- to Check_Internal_Call. Outer_Scope is the outer level scope for
225 -- the original call.
227 procedure Set_Elaboration_Constraint
231 -- The current unit U may depend semantically on some unit P which is not
232 -- in the current context. If there is an elaboration call that reaches P,
233 -- we need to indicate that P requires an Elaborate_All, but this is not
234 -- effective in U's ali file, if there is no with_clause for P. In this
235 -- case we add the Elaborate_All on the unit Q that directly or indirectly
236 -- makes P available. This can happen in two cases:
238 -- a) Q declares a subtype of a type declared in P, and the call is an
239 -- initialization call for an object of that subtype.
241 -- b) Q declares an object of some tagged type whose root type is
242 -- declared in P, and the initialization call uses object notation on
243 -- that object to reach a primitive operation or a classwide operation
246 -- If P appears in the context of U, the current processing is correct.
247 -- Otherwise we must identify these two cases to retrieve Q and place the
248 -- Elaborate_All_Desirable on it.
250 function Has_Generic_Body
(N
: Node_Id
) return Boolean;
251 -- N is a generic package instantiation node, and this routine determines
252 -- if this package spec does in fact have a generic body. If so, then
253 -- True is returned, otherwise False. Note that this is not at all the
254 -- same as checking if the unit requires a body, since it deals with
255 -- the case of optional bodies accurately (i.e. if a body is optional,
256 -- then it looks to see if a body is actually present). Note: this
257 -- function can only do a fully correct job if in generating code mode
258 -- where all bodies have to be present. If we are operating in semantics
259 -- check only mode, then in some cases of optional bodies, a result of
260 -- False may incorrectly be given. In practice this simply means that
261 -- some cases of warnings for incorrect order of elaboration will only
262 -- be given when generating code, which is not a big problem (and is
263 -- inevitable, given the optional body semantics of Ada).
265 procedure Insert_Elab_Check
(N
: Node_Id
; C
: Node_Id
:= Empty
);
266 -- Given code for an elaboration check (or unconditional raise if
267 -- the check is not needed), inserts the code in the appropriate
268 -- place. N is the call or instantiation node for which the check
269 -- code is required. C is the test whose failure triggers the raise.
271 procedure Output_Calls
(N
: Node_Id
);
272 -- Outputs chain of calls stored in the Elab_Call table. The caller
273 -- has already generated the main warning message, so the warnings
274 -- generated are all continuation messages. The argument is the
275 -- call node at which the messages are to be placed.
277 function Same_Elaboration_Scope
(Scop1
, Scop2
: Entity_Id
) return Boolean;
278 -- Given two scopes, determine whether they are the same scope from an
279 -- elaboration point of view, i.e. packages and blocks are ignored.
281 procedure Set_C_Scope
;
282 -- On entry C_Scope is set to some scope. On return, C_Scope is reset
283 -- to be the enclosing compilation unit of this scope.
285 function Spec_Entity
(E
: Entity_Id
) return Entity_Id
;
286 -- Given a compilation unit entity, if it is a spec entity, it is
287 -- returned unchanged. If it is a body entity, then the spec for
288 -- the corresponding spec is returned
290 procedure Supply_Bodies
(N
: Node_Id
);
291 -- Given a node, N, that is either a subprogram declaration or a package
292 -- declaration, this procedure supplies dummy bodies for the subprogram
293 -- or for all subprograms in the package. If the given node is not one
294 -- of these two possibilities, then Supply_Bodies does nothing. The
295 -- dummy body is supplied by setting the subprogram to be Imported with
296 -- convention Stubbed.
298 procedure Supply_Bodies
(L
: List_Id
);
299 -- Calls Supply_Bodies for all elements of the given list L
301 function Within
(E1
, E2
: Entity_Id
) return Boolean;
302 -- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one
303 -- of its contained scopes, False otherwise.
305 function Within_Elaborate_All
(E
: Entity_Id
) return Boolean;
306 -- Before emitting a warning on a scope E for a missing elaborate_all,
307 -- check whether E may be in the context of a directly visible unit U to
308 -- which the pragma applies. This prevents spurious warnings when the
309 -- called entity is renamed within U.
315 procedure Check_A_Call
318 Outer_Scope
: Entity_Id
;
319 Inter_Unit_Only
: Boolean;
320 Generate_Warnings
: Boolean := True)
322 Loc
: constant Source_Ptr
:= Sloc
(N
);
327 -- Top level scope of entity for called subprogram. This
328 -- value includes following renamings and derivations, so
329 -- this scope can be in a non-visible unit. This is the
330 -- scope that is to be investigated to see whether an
331 -- elaboration check is required.
334 -- Top level scope of directly called entity for subprogram. This
335 -- differs from E_Scope in the case where renamings or derivations
336 -- are involved, since it does not follow these links. W_Scope is
337 -- generally in a visible unit, and it is this scope that may require
338 -- an Elaborate_All. However, there are some cases (initialization
339 -- calls and calls involving object notation) where W_Scope might not
340 -- be in the context of the current unit, and there is an intermediate
341 -- package that is, in which case the Elaborate_All has to be placed
342 -- on this intedermediate package. These special cases are handled in
343 -- Set_Elaboration_Constraint.
345 Body_Acts_As_Spec
: Boolean;
346 -- Set to true if call is to body acting as spec (no separate spec)
348 Inst_Case
: constant Boolean := Nkind
(N
) in N_Generic_Instantiation
;
349 -- Indicates if we have instantiation case
351 Caller_Unit_Internal
: Boolean;
352 Callee_Unit_Internal
: Boolean;
354 Inst_Caller
: Source_Ptr
;
355 Inst_Callee
: Source_Ptr
;
357 Unit_Caller
: Unit_Number_Type
;
358 Unit_Callee
: Unit_Number_Type
;
360 Cunit_SC
: Boolean := False;
361 -- Set to suppress dynamic elaboration checks where one of the
362 -- enclosing scopes has Elaboration_Checks_Suppressed set, or else
363 -- if a pragma Elaborate (_All) applies to that scope, in which case
364 -- warnings on the scope are also suppressed. For the internal case,
365 -- we ignore this flag.
368 -- If the call is known to be within a local Suppress Elaboration
369 -- pragma, nothing to check. This can happen in task bodies.
371 if (Nkind
(N
) = N_Function_Call
372 or else Nkind
(N
) = N_Procedure_Call_Statement
)
373 and then No_Elaboration_Check
(N
)
378 -- Go to parent for derived subprogram, or to original subprogram
379 -- in the case of a renaming (Alias covers both these cases)
383 if (Suppress_Elaboration_Warnings
(Ent
)
384 or else Elaboration_Checks_Suppressed
(Ent
))
385 and then (Inst_Case
or else No
(Alias
(Ent
)))
390 -- Nothing to do for imported entities
392 if Is_Imported
(Ent
) then
396 exit when Inst_Case
or else No
(Alias
(Ent
));
400 Decl
:= Unit_Declaration_Node
(Ent
);
402 if Nkind
(Decl
) = N_Subprogram_Body
then
403 Body_Acts_As_Spec
:= True;
405 elsif Nkind
(Decl
) = N_Subprogram_Declaration
406 or else Nkind
(Decl
) = N_Subprogram_Body_Stub
409 Body_Acts_As_Spec
:= False;
411 -- If we have none of an instantiation, subprogram body or
412 -- subprogram declaration, then it is not a case that we want
413 -- to check. (One case is a call to a generic formal subprogram,
414 -- where we do not want the check in the template).
422 if Elaboration_Checks_Suppressed
(E_Scope
)
423 or else Suppress_Elaboration_Warnings
(E_Scope
)
428 -- Exit when we get to compilation unit, not counting subunits
430 exit when Is_Compilation_Unit
(E_Scope
)
431 and then (Is_Child_Unit
(E_Scope
)
432 or else Scope
(E_Scope
) = Standard_Standard
);
434 -- If we did not find a compilation unit, other than standard,
435 -- then nothing to check (happens in some instantiation cases)
437 if E_Scope
= Standard_Standard
then
440 -- Otherwise move up a scope looking for compilation unit
443 E_Scope
:= Scope
(E_Scope
);
447 -- No checks needed for pure or preelaborated compilation units
450 or else Is_Preelaborated
(E_Scope
)
455 -- If the generic entity is within a deeper instance than we are, then
456 -- either the instantiation to which we refer itself caused an ABE, in
457 -- which case that will be handled separately, or else we know that the
458 -- body we need appears as needed at the point of the instantiation.
459 -- However, this assumption is only valid if we are in static mode.
461 if not Dynamic_Elaboration_Checks
462 and then Instantiation_Depth
(Sloc
(Ent
)) >
463 Instantiation_Depth
(Sloc
(N
))
468 -- Do not give a warning for a package with no body
470 if Ekind
(Ent
) = E_Generic_Package
471 and then not Has_Generic_Body
(N
)
476 -- Case of entity is not in current unit (i.e. with'ed unit case)
478 if E_Scope
/= C_Scope
then
480 -- We are only interested in such calls if the outer call was from
481 -- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
483 if not From_Elab_Code
and then not Dynamic_Elaboration_Checks
then
487 -- Nothing to do if some scope said that no checks were required
493 -- Nothing to do for a generic instance, because in this case
494 -- the checking was at the point of instantiation of the generic
495 -- However, this shortcut is only applicable in static mode.
497 if Is_Generic_Instance
(Ent
) and not Dynamic_Elaboration_Checks
then
501 -- Nothing to do if subprogram with no separate spec. However,
502 -- a call to Deep_Initialize may result in a call to a user-defined
503 -- Initialize procedure, which imposes a body dependency. This
504 -- happens only if the type is controlled and the Initialize
505 -- procedure is not inherited.
507 if Body_Acts_As_Spec
then
508 if Is_TSS
(Ent
, TSS_Deep_Initialize
) then
513 Typ
:= Etype
(Next_Formal
(First_Formal
(Ent
)));
515 if not Is_Controlled
(Typ
) then
518 Init
:= Find_Prim_Op
(Typ
, Name_Initialize
);
520 if Comes_From_Source
(Init
) then
533 -- Check cases of internal units
535 Callee_Unit_Internal
:=
536 Is_Internal_File_Name
537 (Unit_File_Name
(Get_Source_Unit
(E_Scope
)));
539 -- Do not give a warning if the with'ed unit is internal
540 -- and this is the generic instantiation case (this saves a
541 -- lot of hassle dealing with the Text_IO special child units)
543 if Callee_Unit_Internal
and Inst_Case
then
547 if C_Scope
= Standard_Standard
then
548 Caller_Unit_Internal
:= False;
550 Caller_Unit_Internal
:=
551 Is_Internal_File_Name
552 (Unit_File_Name
(Get_Source_Unit
(C_Scope
)));
555 -- Do not give a warning if the with'ed unit is internal
556 -- and the caller is not internal (since the binder always
557 -- elaborates internal units first).
559 if Callee_Unit_Internal
and (not Caller_Unit_Internal
) then
563 -- For now, if debug flag -gnatdE is not set, do no checking for
564 -- one internal unit withing another. This fixes the problem with
565 -- the sgi build and storage errors. To be resolved later ???
567 if (Callee_Unit_Internal
and Caller_Unit_Internal
)
568 and then not Debug_Flag_EE
573 if Is_TSS
(E
, TSS_Deep_Initialize
) then
577 -- If the call is in an instance, and the called entity is not
578 -- defined in the same instance, then the elaboration issue
579 -- focuses around the unit containing the template, it is
580 -- this unit which requires an Elaborate_All.
582 -- However, if we are doing dynamic elaboration, we need to
583 -- chase the call in the usual manner.
585 -- We do not handle the case of calling a generic formal correctly
586 -- in the static case. See test 4703-004 to explore this gap ???
588 Inst_Caller
:= Instantiation
(Get_Source_File_Index
(Sloc
(N
)));
589 Inst_Callee
:= Instantiation
(Get_Source_File_Index
(Sloc
(Ent
)));
591 if Inst_Caller
= No_Location
then
592 Unit_Caller
:= No_Unit
;
594 Unit_Caller
:= Get_Source_Unit
(N
);
597 if Inst_Callee
= No_Location
then
598 Unit_Callee
:= No_Unit
;
600 Unit_Callee
:= Get_Source_Unit
(Ent
);
603 if Unit_Caller
/= No_Unit
604 and then Unit_Callee
/= Unit_Caller
605 and then not Dynamic_Elaboration_Checks
607 E_Scope
:= Spec_Entity
(Cunit_Entity
(Unit_Caller
));
609 -- If we don't get a spec entity, just ignore call. Not
610 -- quite clear why this check is necessary.
616 -- Otherwise step to enclosing compilation unit
618 while not Is_Compilation_Unit
(E_Scope
) loop
619 E_Scope
:= Scope
(E_Scope
);
622 -- For the case N is not an instance, or a call within instance
623 -- We recompute E_Scope for the error message, since we
624 -- do NOT want to go to the unit which has the ultimate
625 -- declaration in the case of renaming and derivation and
626 -- we also want to go to the generic unit in the case of
627 -- an instance, and no further.
630 -- Loop to carefully follow renamings and derivations
631 -- one step outside the current unit, but not further.
634 and then Present
(Alias
(Ent
))
636 E_Scope
:= Alias
(Ent
);
642 while not Is_Compilation_Unit
(E_Scope
) loop
643 E_Scope
:= Scope
(E_Scope
);
646 -- If E_Scope is the same as C_Scope, it means that there
647 -- definitely was a local renaming or derivation, and we
648 -- are not yet out of the current unit.
650 exit when E_Scope
/= C_Scope
;
654 -- If no alias, there is a previous error
662 if Within_Elaborate_All
(E_Scope
) then
666 -- Find top level scope for called entity (not following renamings
667 -- or derivations). This is where the Elaborate_All will go if it
668 -- is needed. We start with the called entity, except in the case
669 -- of an initialization procedure outside the current package, where
670 -- the init proc is in the root package, and we start from the entity
671 -- of the name in the call.
673 if Is_Entity_Name
(Name
(N
))
674 and then Is_Init_Proc
(Entity
(Name
(N
)))
675 and then not In_Same_Extended_Unit
(N
, Entity
(Name
(N
)))
677 W_Scope
:= Scope
(Entity
(Name
(N
)));
682 while not Is_Compilation_Unit
(W_Scope
) loop
683 W_Scope
:= Scope
(W_Scope
);
686 -- Now check if an elaborate_all (or dynamic check) is needed
688 if not Suppress_Elaboration_Warnings
(Ent
)
689 and then not Elaboration_Checks_Suppressed
(Ent
)
690 and then not Suppress_Elaboration_Warnings
(E_Scope
)
691 and then not Elaboration_Checks_Suppressed
(E_Scope
)
692 and then Elab_Warnings
693 and then Generate_Warnings
697 ("instantiation of& may raise Program_Error?", N
, Ent
);
700 if Is_Init_Proc
(Entity
(Name
(N
)))
701 and then Comes_From_Source
(Ent
)
704 ("implicit call to & may raise Program_Error?", N
, Ent
);
708 ("call to & may raise Program_Error?", N
, Ent
);
712 Error_Msg_Qual_Level
:= Nat
'Last;
714 ("\missing pragma Elaborate_All for&?", N
, W_Scope
);
715 Error_Msg_Qual_Level
:= 0;
718 -- Set flag to prevent further warnings for same unit
719 -- unless in All_Errors_Mode.
721 if not All_Errors_Mode
and not Dynamic_Elaboration_Checks
then
722 Set_Suppress_Elaboration_Warnings
(W_Scope
, True);
726 -- Check for runtime elaboration check required
728 if Dynamic_Elaboration_Checks
then
729 if not Elaboration_Checks_Suppressed
(Ent
)
730 and then not Elaboration_Checks_Suppressed
(W_Scope
)
731 and then not Elaboration_Checks_Suppressed
(E_Scope
)
732 and then not Cunit_SC
734 -- Runtime elaboration check required. Generate check of the
735 -- elaboration Boolean for the unit containing the entity.
737 -- Note that for this case, we do check the real unit (the
738 -- one from following renamings, since that is the issue!)
740 -- Could this possibly miss a useless but required PE???
742 Insert_Elab_Check
(N
,
743 Make_Attribute_Reference
(Loc
,
744 Attribute_Name
=> Name_Elaborated
,
747 (Spec_Entity
(E_Scope
), Loc
)));
750 -- Case of static elaboration model
753 -- Do not do anything if elaboration checks suppressed. Note
754 -- that we check Ent here, not E, since we want the real entity
755 -- for the body to see if checks are suppressed for it, not the
756 -- dummy entry for renamings or derivations.
758 if Elaboration_Checks_Suppressed
(Ent
)
759 or else Elaboration_Checks_Suppressed
(E_Scope
)
760 or else Elaboration_Checks_Suppressed
(W_Scope
)
764 -- Here we need to generate an implicit elaborate all
767 -- Generate elaborate_all warning unless suppressed
769 if (Elab_Warnings
and Generate_Warnings
and not Inst_Case
)
770 and then not Suppress_Elaboration_Warnings
(Ent
)
771 and then not Suppress_Elaboration_Warnings
(E_Scope
)
772 and then not Suppress_Elaboration_Warnings
(W_Scope
)
774 Error_Msg_Node_2
:= W_Scope
;
776 ("call to& in elaboration code " &
777 "requires pragma Elaborate_All on&?", N
, E
);
780 -- Set indication for binder to generate Elaborate_All
782 Set_Elaboration_Constraint
(N
, E
, W_Scope
);
786 -- Case of entity is in same unit as call or instantiation
788 elsif not Inter_Unit_Only
then
789 Check_Internal_Call
(N
, Ent
, Outer_Scope
, E
);
793 -----------------------------
794 -- Check_Bad_Instantiation --
795 -----------------------------
797 procedure Check_Bad_Instantiation
(N
: Node_Id
) is
801 -- Nothing to do if we do not have an instantiation (happens in some
802 -- error cases, and also in the formal package declaration case)
804 if Nkind
(N
) not in N_Generic_Instantiation
then
807 -- Nothing to do if serious errors detected (avoid cascaded errors)
809 elsif Serious_Errors_Detected
/= 0 then
812 -- Nothing to do if not in full analysis mode
814 elsif not Full_Analysis
then
817 -- Nothing to do if inside a generic template
819 elsif Inside_A_Generic
then
822 -- Nothing to do if a library level instantiation
824 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
827 -- Nothing to do if we are compiling a proper body for semantic
828 -- purposes only. The generic body may be in another proper body.
831 Nkind
(Parent
(Unit_Declaration_Node
(Main_Unit_Entity
))) = N_Subunit
836 Ent
:= Get_Generic_Entity
(N
);
838 -- The case we are interested in is when the generic spec is in the
839 -- current declarative part
841 if not Same_Elaboration_Scope
(Current_Scope
, Scope
(Ent
))
842 or else not In_Same_Extended_Unit
(N
, Ent
)
847 -- If the generic entity is within a deeper instance than we are, then
848 -- either the instantiation to which we refer itself caused an ABE, in
849 -- which case that will be handled separately. Otherwise, we know that
850 -- the body we need appears as needed at the point of the instantiation.
851 -- If they are both at the same level but not within the same instance
852 -- then the body of the generic will be in the earlier instance.
855 D1
: constant Int
:= Instantiation_Depth
(Sloc
(Ent
));
856 D2
: constant Int
:= Instantiation_Depth
(Sloc
(N
));
863 and then Is_Generic_Instance
(Scope
(Ent
))
864 and then not In_Open_Scopes
(Scope
(Ent
))
870 -- Now we can proceed, if the entity being called has a completion,
871 -- then we are definitely OK, since we have already seen the body.
873 if Has_Completion
(Ent
) then
877 -- If there is no body, then nothing to do
879 if not Has_Generic_Body
(N
) then
883 -- Here we definitely have a bad instantiation
886 ("?cannot instantiate& before body seen", N
, Ent
);
888 if Present
(Instance_Spec
(N
)) then
889 Supply_Bodies
(Instance_Spec
(N
));
893 ("\?Program_Error will be raised at run time", N
);
894 Insert_Elab_Check
(N
);
895 Set_ABE_Is_Certain
(N
);
897 end Check_Bad_Instantiation
;
899 ---------------------
900 -- Check_Elab_Call --
901 ---------------------
903 procedure Check_Elab_Call
905 Outer_Scope
: Entity_Id
:= Empty
)
910 function Get_Called_Ent
return Entity_Id
;
911 -- Retrieve called entity. If this is a call to a protected subprogram,
912 -- entity is a selected component. The callable entity may be absent,
913 -- in which case there is no check to perform. This happens with
914 -- non-analyzed calls in nested generics.
920 function Get_Called_Ent
return Entity_Id
is
929 elsif Nkind
(Nam
) = N_Selected_Component
then
930 return Entity
(Selector_Name
(Nam
));
932 elsif not Is_Entity_Name
(Nam
) then
940 -- Start of processing for Check_Elab_Call
943 -- If the call does not come from the main unit, there is nothing to
944 -- check. Elaboration call from units in the context of the main unit
945 -- will lead to semantic dependencies when those units are compiled.
947 if not In_Extended_Main_Code_Unit
(N
) then
951 -- For an entry call, check relevant restriction
953 if Nkind
(N
) = N_Entry_Call_Statement
954 and then not In_Subprogram_Or_Concurrent_Unit
956 Check_Restriction
(No_Entry_Calls_In_Elaboration_Code
, N
);
958 -- Nothing to do if this is not a call (happens in some error
959 -- conditions, and in some cases where rewriting occurs).
961 elsif Nkind
(N
) /= N_Function_Call
962 and then Nkind
(N
) /= N_Procedure_Call_Statement
966 -- Nothing to do if this is a call already rewritten for elab checking
968 elsif Nkind
(Parent
(N
)) = N_Conditional_Expression
then
971 -- Nothing to do if inside a generic template
973 elsif Inside_A_Generic
974 and then not Present
(Enclosing_Generic_Body
(N
))
979 -- Here we have a call at elaboration time which must be checked
981 if Debug_Flag_LL
then
982 Write_Str
(" Check_Elab_Call: ");
985 or else not Is_Entity_Name
(Name
(N
))
987 Write_Str
("<<not entity name>> ");
989 Write_Name
(Chars
(Entity
(Name
(N
))));
992 Write_Str
(" call at ");
993 Write_Location
(Sloc
(N
));
997 -- Climb up the tree to make sure we are not inside a
998 -- default expression of a parameter specification or
999 -- a record component, since in both these cases, we
1000 -- will be doing the actual call later, not now, and it
1001 -- is at the time of the actual call (statically speaking)
1002 -- that we must do our static check, not at the time of
1003 -- its initial analysis). However, we have to check calls
1004 -- within component definitions (e.g., a function call
1005 -- that determines an array component bound), so we
1006 -- terminate the loop in that case.
1009 while Present
(P
) loop
1010 if Nkind
(P
) = N_Parameter_Specification
1012 Nkind
(P
) = N_Component_Declaration
1016 -- The call occurs within the constraint of a component,
1017 -- so it must be checked.
1019 elsif Nkind
(P
) = N_Component_Definition
then
1027 -- Stuff that happens only at the outer level
1029 if No
(Outer_Scope
) then
1030 Elab_Visited
.Set_Last
(0);
1032 -- Nothing to do if current scope is Standard (this is a bit
1033 -- odd, but it happens in the case of generic instantiations).
1035 C_Scope
:= Current_Scope
;
1037 if C_Scope
= Standard_Standard
then
1041 -- First case, we are in elaboration code
1043 From_Elab_Code
:= not In_Subprogram_Or_Concurrent_Unit
;
1044 if From_Elab_Code
then
1046 -- Complain if call that comes from source in preelaborated
1047 -- unit and we are not inside a subprogram (i.e. we are in
1050 if Comes_From_Source
(N
)
1051 and then In_Preelaborated_Unit
1052 and then not In_Inlined_Body
1054 -- This is a warning in GNAT mode allowing such calls to be
1055 -- used in the predefined library with appropriate care.
1057 Error_Msg_Warn
:= GNAT_Mode
;
1059 ("<non-static call not allowed in preelaborated unit", N
);
1063 -- Second case, we are inside a subprogram or concurrent unit, which
1064 -- means we are not in elaboration code.
1067 -- In this case, the issue is whether we are inside the
1068 -- declarative part of the unit in which we live, or inside its
1069 -- statements. In the latter case, there is no issue of ABE calls
1070 -- at this level (a call from outside to the unit in which we live
1071 -- might cause an ABE, but that will be detected when we analyze
1072 -- that outer level call, as it recurses into the called unit).
1074 -- Climb up the tree, doing this test, and also testing for being
1075 -- inside a default expression, which, as discussed above, is not
1076 -- checked at this stage.
1085 -- If we find a parentless subtree, it seems safe to assume
1086 -- that we are not in a declarative part and that no
1087 -- checking is required.
1093 if Is_List_Member
(P
) then
1094 L
:= List_Containing
(P
);
1101 exit when Nkind
(P
) = N_Subunit
;
1103 -- Filter out case of default expressions, where we do not
1104 -- do the check at this stage.
1106 if Nkind
(P
) = N_Parameter_Specification
1108 Nkind
(P
) = N_Component_Declaration
1113 if Nkind
(P
) = N_Subprogram_Body
1115 Nkind
(P
) = N_Protected_Body
1117 Nkind
(P
) = N_Task_Body
1119 Nkind
(P
) = N_Block_Statement
1121 if L
= Declarations
(P
) then
1124 -- We are not in elaboration code, but we are doing
1125 -- dynamic elaboration checks, in this case, we still
1126 -- need to do the call, since the subprogram we are in
1127 -- could be called from another unit, also in dynamic
1128 -- elaboration check mode, at elaboration time.
1130 elsif Dynamic_Elaboration_Checks
then
1132 -- This is a rather new check, going into version
1133 -- 3.14a1 for the first time (V1.80 of this unit), so
1134 -- we provide a debug flag to enable it. That way we
1135 -- have an easy work around for regressions that are
1136 -- caused by this new check. This debug flag can be
1139 if Debug_Flag_DD
then
1143 -- Do the check in this case
1147 elsif Nkind
(P
) = N_Task_Body
then
1149 -- The check is deferred until Check_Task_Activation
1150 -- but we need to capture local suppress pragmas
1151 -- that may inhibit checks on this call.
1153 Ent
:= Get_Called_Ent
;
1158 elsif Elaboration_Checks_Suppressed
(Current_Scope
)
1159 or else Elaboration_Checks_Suppressed
(Ent
)
1160 or else Elaboration_Checks_Suppressed
(Scope
(Ent
))
1162 Set_No_Elaboration_Check
(N
);
1167 -- Static model, call is not in elaboration code, we
1168 -- never need to worry, because in the static model
1169 -- the top level caller always takes care of things.
1180 Ent
:= Get_Called_Ent
;
1186 -- Nothing to do if this is a recursive call (i.e. a call to
1187 -- an entity that is already in the Elab_Call stack)
1189 for J
in 1 .. Elab_Visited
.Last
loop
1190 if Ent
= Elab_Visited
.Table
(J
) then
1195 -- See if we need to analyze this call. We analyze it if either of
1196 -- the following conditions is met:
1198 -- It is an inner level call (since in this case it was triggered
1199 -- by an outer level call from elaboration code), but only if the
1200 -- call is within the scope of the original outer level call.
1202 -- It is an outer level call from elaboration code, or the called
1203 -- entity is in the same elaboration scope.
1205 -- And in these cases, we will check both inter-unit calls and
1206 -- intra-unit (within a single unit) calls.
1208 C_Scope
:= Current_Scope
;
1210 -- If not outer level call, then we follow it if it is within
1211 -- the original scope of the outer call.
1213 if Present
(Outer_Scope
)
1214 and then Within
(Scope
(Ent
), Outer_Scope
)
1217 Check_A_Call
(N
, Ent
, Outer_Scope
, Inter_Unit_Only
=> False);
1219 elsif Elaboration_Checks_Suppressed
(Current_Scope
) then
1222 elsif From_Elab_Code
then
1224 Check_A_Call
(N
, Ent
, Standard_Standard
, Inter_Unit_Only
=> False);
1226 elsif Same_Elaboration_Scope
(C_Scope
, Scope
(Ent
)) then
1228 Check_A_Call
(N
, Ent
, Scope
(Ent
), Inter_Unit_Only
=> False);
1230 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1231 -- is set, then we will do the check, but only in the inter-unit case
1232 -- (this is to accommodate unguarded elaboration calls from other units
1233 -- in which this same mode is set). We don't want warnings in this case,
1234 -- it would generate warnings having nothing to do with elaboration.
1236 elsif Dynamic_Elaboration_Checks
then
1242 Inter_Unit_Only
=> True,
1243 Generate_Warnings
=> False);
1245 -- Otherwise nothing to do
1251 -- A call to an Init_Proc in elaboration code may bring additional
1252 -- dependencies, if some of the record components thereof have
1253 -- initializations that are function calls that come from source.
1254 -- We treat the current node as a call to each of these functions,
1255 -- to check their elaboration impact.
1257 if Is_Init_Proc
(Ent
)
1258 and then From_Elab_Code
1260 Process_Init_Proc
: declare
1261 Unit_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
1263 function Process
(Nod
: Node_Id
) return Traverse_Result
;
1264 -- Find subprogram calls within body of init_proc for
1265 -- Traverse instantiation below.
1267 function Process
(Nod
: Node_Id
) return Traverse_Result
is
1271 if (Nkind
(Nod
) = N_Function_Call
1272 or else Nkind
(Nod
) = N_Procedure_Call_Statement
)
1273 and then Is_Entity_Name
(Name
(Nod
))
1275 Func
:= Entity
(Name
(Nod
));
1277 if Comes_From_Source
(Func
) then
1279 (N
, Func
, Standard_Standard
, Inter_Unit_Only
=> True);
1289 procedure Traverse_Body
is new Traverse_Proc
(Process
);
1291 -- Start of processing for Process_Init_Proc
1294 if Nkind
(Unit_Decl
) = N_Subprogram_Body
then
1295 Traverse_Body
(Handled_Statement_Sequence
(Unit_Decl
));
1297 end Process_Init_Proc
;
1299 end Check_Elab_Call
;
1301 ----------------------
1302 -- Check_Elab_Calls --
1303 ----------------------
1305 procedure Check_Elab_Calls
is
1307 -- If expansion is disabled, do not generate any checks. Also
1308 -- skip checks if any subunits are missing because in either
1309 -- case we lack the full information that we need, and no object
1310 -- file will be created in any case.
1312 if not Expander_Active
1313 or else Is_Generic_Unit
(Cunit_Entity
(Main_Unit
))
1314 or else Subunits_Missing
1319 -- Skip delayed calls if we had any errors
1321 if Serious_Errors_Detected
= 0 then
1322 Delaying_Elab_Checks
:= False;
1323 Expander_Mode_Save_And_Set
(True);
1325 for J
in Delay_Check
.First
.. Delay_Check
.Last
loop
1326 New_Scope
(Delay_Check
.Table
(J
).Curscop
);
1327 From_Elab_Code
:= Delay_Check
.Table
(J
).From_Elab_Code
;
1329 Check_Internal_Call_Continue
(
1330 N
=> Delay_Check
.Table
(J
).N
,
1331 E
=> Delay_Check
.Table
(J
).E
,
1332 Outer_Scope
=> Delay_Check
.Table
(J
).Outer_Scope
,
1333 Orig_Ent
=> Delay_Check
.Table
(J
).Orig_Ent
);
1338 -- Set Delaying_Elab_Checks back on for next main compilation
1340 Expander_Mode_Restore
;
1341 Delaying_Elab_Checks
:= True;
1343 end Check_Elab_Calls
;
1345 ------------------------------
1346 -- Check_Elab_Instantiation --
1347 ------------------------------
1349 procedure Check_Elab_Instantiation
1351 Outer_Scope
: Entity_Id
:= Empty
)
1356 -- Check for and deal with bad instantiation case. There is some
1357 -- duplicated code here, but we will worry about this later ???
1359 Check_Bad_Instantiation
(N
);
1361 if ABE_Is_Certain
(N
) then
1365 -- Nothing to do if we do not have an instantiation (happens in some
1366 -- error cases, and also in the formal package declaration case)
1368 if Nkind
(N
) not in N_Generic_Instantiation
then
1372 -- Nothing to do if inside a generic template
1374 if Inside_A_Generic
then
1378 -- Nothing to do if the instantiation is not in the main unit
1380 if not In_Extended_Main_Code_Unit
(N
) then
1384 Ent
:= Get_Generic_Entity
(N
);
1385 From_Elab_Code
:= not In_Subprogram_Or_Concurrent_Unit
;
1387 -- See if we need to analyze this instantiation. We analyze it if
1388 -- either of the following conditions is met:
1390 -- It is an inner level instantiation (since in this case it was
1391 -- triggered by an outer level call from elaboration code), but
1392 -- only if the instantiation is within the scope of the original
1393 -- outer level call.
1395 -- It is an outer level instantiation from elaboration code, or the
1396 -- instantiated entity is in the same elaboratoin scope.
1398 -- And in these cases, we will check both the inter-unit case and
1399 -- the intra-unit (within a single unit) case.
1401 C_Scope
:= Current_Scope
;
1403 if Present
(Outer_Scope
)
1404 and then Within
(Scope
(Ent
), Outer_Scope
)
1407 Check_A_Call
(N
, Ent
, Outer_Scope
, Inter_Unit_Only
=> False);
1409 elsif From_Elab_Code
then
1411 Check_A_Call
(N
, Ent
, Standard_Standard
, Inter_Unit_Only
=> False);
1413 elsif Same_Elaboration_Scope
(C_Scope
, Scope
(Ent
)) then
1415 Check_A_Call
(N
, Ent
, Scope
(Ent
), Inter_Unit_Only
=> False);
1417 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
1418 -- is set, then we will do the check, but only in the inter-unit case
1419 -- (this is to accommodate unguarded elaboration calls from other units
1420 -- in which this same mode is set). We inhibit warnings in this case,
1421 -- since this instantiation is not occurring in elaboration code.
1423 elsif Dynamic_Elaboration_Checks
then
1429 Inter_Unit_Only
=> True,
1430 Generate_Warnings
=> False);
1435 end Check_Elab_Instantiation
;
1437 -------------------------
1438 -- Check_Internal_Call --
1439 -------------------------
1441 procedure Check_Internal_Call
1444 Outer_Scope
: Entity_Id
;
1445 Orig_Ent
: Entity_Id
)
1447 Inst_Case
: constant Boolean := Nkind
(N
) in N_Generic_Instantiation
;
1450 -- If not function or procedure call or instantiation, then ignore
1451 -- call (this happens in some error case and rewriting cases)
1453 if Nkind
(N
) /= N_Function_Call
1455 Nkind
(N
) /= N_Procedure_Call_Statement
1461 -- Nothing to do if this is a call or instantiation that has
1462 -- already been found to be a sure ABE
1464 elsif ABE_Is_Certain
(N
) then
1467 -- Nothing to do if errors already detected (avoid cascaded errors)
1469 elsif Serious_Errors_Detected
/= 0 then
1472 -- Nothing to do if not in full analysis mode
1474 elsif not Full_Analysis
then
1477 -- Nothing to do if within a default expression, since the call
1478 -- is not actualy being made at this time.
1480 elsif In_Default_Expression
then
1483 -- Nothing to do for call to intrinsic subprogram
1485 elsif Is_Intrinsic_Subprogram
(E
) then
1488 -- No need to trace local calls if checking task activation, because
1489 -- other local bodies are elaborated already.
1491 elsif In_Task_Activation
then
1495 -- Delay this call if we are still delaying calls
1497 if Delaying_Elab_Checks
then
1498 Delay_Check
.Increment_Last
;
1499 Delay_Check
.Table
(Delay_Check
.Last
) :=
1502 Orig_Ent
=> Orig_Ent
,
1503 Curscop
=> Current_Scope
,
1504 Outer_Scope
=> Outer_Scope
,
1505 From_Elab_Code
=> From_Elab_Code
);
1508 -- Otherwise, call phase 2 continuation right now
1511 Check_Internal_Call_Continue
(N
, E
, Outer_Scope
, Orig_Ent
);
1514 end Check_Internal_Call
;
1516 ----------------------------------
1517 -- Check_Internal_Call_Continue --
1518 ----------------------------------
1520 procedure Check_Internal_Call_Continue
1523 Outer_Scope
: Entity_Id
;
1524 Orig_Ent
: Entity_Id
)
1526 Loc
: constant Source_Ptr
:= Sloc
(N
);
1527 Inst_Case
: constant Boolean := Is_Generic_Unit
(E
);
1532 function Process
(N
: Node_Id
) return Traverse_Result
;
1533 -- Function applied to each node as we traverse the body.
1534 -- Checks for call that needs checking, and if so checks
1535 -- it. Always returns OK, so entire tree is traversed.
1541 function Process
(N
: Node_Id
) return Traverse_Result
is
1543 -- If user has specified that there are no entry calls in elaboration
1544 -- code, do not trace past an accept statement, because the rendez-
1545 -- vous will happen after elaboration.
1547 if (Nkind
(Original_Node
(N
)) = N_Accept_Statement
1548 or else Nkind
(Original_Node
(N
)) = N_Selective_Accept
)
1549 and then Restriction_Active
(No_Entry_Calls_In_Elaboration_Code
)
1553 -- If we have a subprogram call, check it
1555 elsif Nkind
(N
) = N_Function_Call
1556 or else Nkind
(N
) = N_Procedure_Call_Statement
1558 Check_Elab_Call
(N
, Outer_Scope
);
1561 -- If we have a generic instantiation, check it
1563 elsif Nkind
(N
) in N_Generic_Instantiation
then
1564 Check_Elab_Instantiation
(N
, Outer_Scope
);
1567 -- Skip subprogram bodies that come from source (wait for
1568 -- call to analyze these). The reason for the come from
1569 -- source test is to avoid catching task bodies.
1571 -- For task bodies, we should really avoid these too, waiting
1572 -- for the task activation, but that's too much trouble to
1573 -- catch for now, so we go in unconditionally. This is not
1574 -- so terrible, it means the error backtrace is not quite
1575 -- complete, and we are too eager to scan bodies of tasks
1576 -- that are unused, but this is hardly very significant!
1578 elsif Nkind
(N
) = N_Subprogram_Body
1579 and then Comes_From_Source
(N
)
1588 procedure Traverse
is new Atree
.Traverse_Proc
;
1589 -- Traverse procedure using above Process function
1591 -- Start of processing for Check_Internal_Call_Continue
1594 -- Save outer level call if at outer level
1596 if Elab_Call
.Last
= 0 then
1597 Outer_Level_Sloc
:= Loc
;
1600 Elab_Visited
.Increment_Last
;
1601 Elab_Visited
.Table
(Elab_Visited
.Last
) := E
;
1603 -- If the call is to a function that renames a literal, no check
1606 if Ekind
(E
) = E_Enumeration_Literal
then
1610 Sbody
:= Unit_Declaration_Node
(E
);
1612 if Nkind
(Sbody
) /= N_Subprogram_Body
1614 Nkind
(Sbody
) /= N_Package_Body
1616 Ebody
:= Corresponding_Body
(Sbody
);
1621 Sbody
:= Unit_Declaration_Node
(Ebody
);
1625 -- If the body appears after the outer level call or
1626 -- instantiation then we have an error case handled below.
1628 if Earlier_In_Extended_Unit
(Outer_Level_Sloc
, Sloc
(Sbody
))
1629 and then not In_Task_Activation
1633 -- If we have the instantiation case we are done, since we now
1634 -- know that the body of the generic appeared earlier.
1636 elsif Inst_Case
then
1639 -- Otherwise we have a call, so we trace through the called
1640 -- body to see if it has any problems ..
1643 pragma Assert
(Nkind
(Sbody
) = N_Subprogram_Body
);
1645 Elab_Call
.Increment_Last
;
1646 Elab_Call
.Table
(Elab_Call
.Last
).Cloc
:= Loc
;
1647 Elab_Call
.Table
(Elab_Call
.Last
).Ent
:= E
;
1649 if Debug_Flag_LL
then
1650 Write_Str
("Elab_Call.Last = ");
1651 Write_Int
(Int
(Elab_Call
.Last
));
1652 Write_Str
(" Ent = ");
1653 Write_Name
(Chars
(E
));
1655 Write_Location
(Sloc
(N
));
1659 -- Now traverse declarations and statements of subprogram body.
1660 -- Note that we cannot simply Traverse (Sbody), since traverse
1661 -- does not normally visit subprogram bodies.
1664 Decl
: Node_Id
:= First
(Declarations
(Sbody
));
1667 while Present
(Decl
) loop
1673 Traverse
(Handled_Statement_Sequence
(Sbody
));
1675 Elab_Call
.Decrement_Last
;
1679 -- Here is the case of calling a subprogram where the body has
1680 -- not yet been encountered, a warning message is needed.
1682 -- If we have nothing in the call stack, then this is at the
1683 -- outer level, and the ABE is bound to occur.
1685 if Elab_Call
.Last
= 0 then
1688 ("?cannot instantiate& before body seen", N
, Orig_Ent
);
1691 ("?cannot call& before body seen", N
, Orig_Ent
);
1695 ("\?Program_Error will be raised at run time", N
);
1696 Insert_Elab_Check
(N
);
1698 -- Call is not at outer level
1701 -- Deal with dynamic elaboration check
1703 if not Elaboration_Checks_Suppressed
(E
) then
1704 Set_Elaboration_Entity_Required
(E
);
1706 -- Case of no elaboration entity allocated yet
1708 if No
(Elaboration_Entity
(E
)) then
1710 -- Create object declaration for elaboration entity, and put it
1711 -- just in front of the spec of the subprogram or generic unit,
1712 -- in the same scope as this unit.
1715 Loce
: constant Source_Ptr
:= Sloc
(E
);
1716 Ent
: constant Entity_Id
:=
1717 Make_Defining_Identifier
(Loc
,
1718 Chars
=> New_External_Name
(Chars
(E
), 'E'));
1721 Set_Elaboration_Entity
(E
, Ent
);
1722 New_Scope
(Scope
(E
));
1724 Insert_Action
(Declaration_Node
(E
),
1725 Make_Object_Declaration
(Loce
,
1726 Defining_Identifier
=> Ent
,
1727 Object_Definition
=>
1728 New_Occurrence_Of
(Standard_Boolean
, Loce
),
1729 Expression
=> New_Occurrence_Of
(Standard_False
, Loce
)));
1731 -- Set elaboration flag at the point of the body
1733 Set_Elaboration_Flag
(Sbody
, E
);
1735 -- Kill current value indication. This is necessary
1736 -- because the tests of this flag are inserted out of
1737 -- sequence and must not pick up bogus indications of
1738 -- the wrong constant value. Also, this is never a true
1739 -- constant, since one way or another, it gets reset.
1741 Set_Current_Value
(Ent
, Empty
);
1742 Set_Is_True_Constant
(Ent
, False);
1747 -- Generate check of the elaboration Boolean
1749 Insert_Elab_Check
(N
,
1750 New_Occurrence_Of
(Elaboration_Entity
(E
), Loc
));
1753 -- Generate the warning
1755 if not Suppress_Elaboration_Warnings
(E
)
1756 and then not Elaboration_Checks_Suppressed
(E
)
1760 ("instantiation of& may occur before body is seen?",
1764 ("call to& may occur before body is seen?", N
, Orig_Ent
);
1768 ("\Program_Error may be raised at run time?", N
);
1774 -- Set flag to suppress further warnings on same subprogram
1775 -- unless in all errors mode
1777 if not All_Errors_Mode
then
1778 Set_Suppress_Elaboration_Warnings
(E
);
1780 end Check_Internal_Call_Continue
;
1782 ---------------------------
1783 -- Check_Task_Activation --
1784 ---------------------------
1786 procedure Check_Task_Activation
(N
: Node_Id
) is
1787 Loc
: constant Source_Ptr
:= Sloc
(N
);
1788 Inter_Procs
: constant Elist_Id
:= New_Elmt_List
;
1789 Intra_Procs
: constant Elist_Id
:= New_Elmt_List
;
1792 Task_Scope
: Entity_Id
;
1793 Cunit_SC
: Boolean := False;
1796 Enclosing
: Entity_Id
;
1798 procedure Add_Task_Proc
(Typ
: Entity_Id
);
1799 -- Add to Task_Procs the task body procedure(s) of task types in Typ.
1800 -- For record types, this procedure recurses over component types.
1802 procedure Collect_Tasks
(Decls
: List_Id
);
1803 -- Collect the types of the tasks that are to be activated in the given
1804 -- list of declarations, in order to perform elaboration checks on the
1805 -- corresponding task procedures which are called implicitly here.
1807 function Outer_Unit
(E
: Entity_Id
) return Entity_Id
;
1808 -- find enclosing compilation unit of Entity, ignoring subunits, or
1809 -- else enclosing subprogram. If E is not a package, there is no need
1810 -- for inter-unit elaboration checks.
1816 procedure Add_Task_Proc
(Typ
: Entity_Id
) is
1818 Proc
: Entity_Id
:= Empty
;
1821 if Is_Task_Type
(Typ
) then
1822 Proc
:= Get_Task_Body_Procedure
(Typ
);
1824 elsif Is_Array_Type
(Typ
)
1825 and then Has_Task
(Base_Type
(Typ
))
1827 Add_Task_Proc
(Component_Type
(Typ
));
1829 elsif Is_Record_Type
(Typ
)
1830 and then Has_Task
(Base_Type
(Typ
))
1832 Comp
:= First_Component
(Typ
);
1834 while Present
(Comp
) loop
1835 Add_Task_Proc
(Etype
(Comp
));
1836 Comp
:= Next_Component
(Comp
);
1840 -- If the task type is another unit, we will perform the usual
1841 -- elaboration check on its enclosing unit. If the type is in the
1842 -- same unit, we can trace the task body as for an internal call,
1843 -- but we only need to examine other external calls, because at
1844 -- the point the task is activated, internal subprogram bodies
1845 -- will have been elaborated already. We keep separate lists for
1846 -- each kind of task.
1848 -- Skip this test if errors have occurred, since in this case
1849 -- we can get false indications.
1851 if Serious_Errors_Detected
/= 0 then
1855 if Present
(Proc
) then
1856 if Outer_Unit
(Scope
(Proc
)) = Enclosing
then
1858 if No
(Corresponding_Body
(Unit_Declaration_Node
(Proc
)))
1860 (not Is_Generic_Instance
(Scope
(Proc
))
1862 Scope
(Proc
) = Scope
(Defining_Identifier
(Decl
)))
1865 ("task will be activated before elaboration of its body?",
1868 ("Program_Error will be raised at run-time?", Decl
);
1871 Present
(Corresponding_Body
(Unit_Declaration_Node
(Proc
)))
1873 Append_Elmt
(Proc
, Intra_Procs
);
1877 Elmt
:= First_Elmt
(Inter_Procs
);
1879 -- No need for multiple entries of the same type
1881 while Present
(Elmt
) loop
1882 if Node
(Elmt
) = Proc
then
1889 Append_Elmt
(Proc
, Inter_Procs
);
1898 procedure Collect_Tasks
(Decls
: List_Id
) is
1900 if Present
(Decls
) then
1901 Decl
:= First
(Decls
);
1903 while Present
(Decl
) loop
1905 if Nkind
(Decl
) = N_Object_Declaration
1906 and then Has_Task
(Etype
(Defining_Identifier
(Decl
)))
1908 Add_Task_Proc
(Etype
(Defining_Identifier
(Decl
)));
1920 function Outer_Unit
(E
: Entity_Id
) return Entity_Id
is
1921 Outer
: Entity_Id
:= E
;
1924 while Present
(Outer
) loop
1925 if Elaboration_Checks_Suppressed
(Outer
) then
1929 exit when Is_Child_Unit
(Outer
)
1930 or else Scope
(Outer
) = Standard_Standard
1931 or else Ekind
(Outer
) /= E_Package
;
1932 Outer
:= Scope
(Outer
);
1938 -- Start of processing for Check_Task_Activation
1941 Enclosing
:= Outer_Unit
(Current_Scope
);
1943 -- Find all tasks declared in the current unit
1945 if Nkind
(N
) = N_Package_Body
then
1946 P
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
1948 Collect_Tasks
(Declarations
(N
));
1949 Collect_Tasks
(Visible_Declarations
(Specification
(P
)));
1950 Collect_Tasks
(Private_Declarations
(Specification
(P
)));
1952 elsif Nkind
(N
) = N_Package_Declaration
then
1953 Collect_Tasks
(Visible_Declarations
(Specification
(N
)));
1954 Collect_Tasks
(Private_Declarations
(Specification
(N
)));
1957 Collect_Tasks
(Declarations
(N
));
1960 -- We only perform detailed checks in all tasks are library level
1961 -- entities. If the master is a subprogram or task, activation will
1962 -- depend on the activation of the master itself.
1963 -- Should dynamic checks be added in the more general case???
1965 if Ekind
(Enclosing
) /= E_Package
then
1969 -- For task types defined in other units, we want the unit containing
1970 -- the task body to be elaborated before the current one.
1972 Elmt
:= First_Elmt
(Inter_Procs
);
1974 while Present
(Elmt
) loop
1976 Task_Scope
:= Outer_Unit
(Scope
(Ent
));
1978 if not Is_Compilation_Unit
(Task_Scope
) then
1981 elsif Suppress_Elaboration_Warnings
(Task_Scope
)
1982 or else Elaboration_Checks_Suppressed
(Task_Scope
)
1986 elsif Dynamic_Elaboration_Checks
then
1987 if not Elaboration_Checks_Suppressed
(Ent
)
1988 and then not Cunit_SC
1990 not Restriction_Active
(No_Entry_Calls_In_Elaboration_Code
)
1992 -- Runtime elaboration check required. generate check of the
1993 -- elaboration Boolean for the unit containing the entity.
1995 Insert_Elab_Check
(N
,
1996 Make_Attribute_Reference
(Loc
,
1997 Attribute_Name
=> Name_Elaborated
,
2000 (Spec_Entity
(Task_Scope
), Loc
)));
2004 -- Force the binder to elaborate other unit first
2006 if not Suppress_Elaboration_Warnings
(Ent
)
2007 and then not Elaboration_Checks_Suppressed
(Ent
)
2008 and then Elab_Warnings
2009 and then not Suppress_Elaboration_Warnings
(Task_Scope
)
2010 and then not Elaboration_Checks_Suppressed
(Task_Scope
)
2012 Error_Msg_Node_2
:= Task_Scope
;
2013 Error_Msg_NE
("activation of an instance of task type&" &
2014 " requires pragma Elaborate_All on &?", N
, Ent
);
2017 Set_Elaborate_All_Desirable
(Task_Scope
);
2018 Set_Suppress_Elaboration_Warnings
(Task_Scope
);
2024 -- For tasks declared in the current unit, trace other calls within
2025 -- the task procedure bodies, which are available.
2027 In_Task_Activation
:= True;
2028 Elmt
:= First_Elmt
(Intra_Procs
);
2030 while Present
(Elmt
) loop
2032 Check_Internal_Call_Continue
(N
, Ent
, Enclosing
, Ent
);
2036 In_Task_Activation
:= False;
2037 end Check_Task_Activation
;
2039 --------------------------------
2040 -- Set_Elaboration_Constraint --
2041 --------------------------------
2043 procedure Set_Elaboration_Constraint
2048 Elab_Unit
: Entity_Id
;
2049 Init_Call
: constant Boolean :=
2050 Chars
(Subp
) = Name_Initialize
2051 and then Comes_From_Source
(Subp
)
2052 and then Present
(Parameter_Associations
(Call
))
2053 and then Is_Controlled
2054 (Etype
(First
(Parameter_Associations
(Call
))));
2056 -- If the unit is mentioned in a with_clause of the current
2057 -- unit, it is visible, and we can set the elaboration flag.
2059 if Is_Immediately_Visible
(Scop
)
2061 (Is_Child_Unit
(Scop
) and then Is_Visible_Child_Unit
(Scop
))
2063 Set_Elaborate_All_Desirable
(Scop
);
2064 Set_Suppress_Elaboration_Warnings
(Scop
, True);
2068 -- If this is not an initialization call or a call using object notation
2069 -- we know that the unit of the called entity is in the context, and
2070 -- we can set the flag as well. The unit need not be visible if the call
2071 -- occurs within an instantiation.
2073 if Is_Init_Proc
(Subp
)
2075 or else Nkind
(Original_Node
(Call
)) = N_Selected_Component
2077 null; -- detailed processing follows.
2080 Set_Elaborate_All_Desirable
(Scop
);
2081 Set_Suppress_Elaboration_Warnings
(Scop
, True);
2085 -- If the unit is not in the context, there must be an intermediate
2086 -- unit that is, on which we need to place to elaboration flag.
2088 if Is_Init_Proc
(Subp
)
2091 -- The initialization call is on an object whose type is not
2092 -- declared in the same scope as the subprogram. The type of
2093 -- the object must be a subtype of the type of operation. This
2094 -- object is the first actual in the call.
2097 Typ
: constant Entity_Id
:=
2098 Etype
(First
(Parameter_Associations
(Call
)));
2100 Elab_Unit
:= Scope
(Typ
);
2102 while (Present
(Elab_Unit
))
2103 and then not Is_Compilation_Unit
(Elab_Unit
)
2105 Elab_Unit
:= Scope
(Elab_Unit
);
2108 elsif Nkind
(Original_Node
(Call
)) = N_Selected_Component
then
2110 -- If original node uses selected component notation, the
2111 -- prefix is visible and determines the scope that must be
2112 -- elaborated. After rewriting, the prefix is the first actual
2115 Elab_Unit
:= Scope
(Etype
(First
(Parameter_Associations
(Call
))));
2118 -- Using previously computed scope. If the elaboration check is
2119 -- done after analysis, the scope is not visible any longer, but
2120 -- must still be in the context.
2125 Set_Elaborate_All_Desirable
(Elab_Unit
);
2126 Set_Suppress_Elaboration_Warnings
(Elab_Unit
, True);
2127 end Set_Elaboration_Constraint
;
2129 ----------------------
2130 -- Has_Generic_Body --
2131 ----------------------
2133 function Has_Generic_Body
(N
: Node_Id
) return Boolean is
2134 Ent
: constant Entity_Id
:= Get_Generic_Entity
(N
);
2135 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
2138 function Find_Body_In
(E
: Entity_Id
; N
: Node_Id
) return Node_Id
;
2139 -- Determine if the list of nodes headed by N and linked by Next
2140 -- contains a package body for the package spec entity E, and if
2141 -- so return the package body. If not, then returns Empty.
2143 function Load_Package_Body
(Nam
: Unit_Name_Type
) return Node_Id
;
2144 -- This procedure is called load the unit whose name is given by Nam.
2145 -- This unit is being loaded to see whether it contains an optional
2146 -- generic body. The returned value is the loaded unit, which is
2147 -- always a package body (only package bodies can contain other
2148 -- entities in the sense in which Has_Generic_Body is interested).
2149 -- We only attempt to load bodies if we are generating code. If we
2150 -- are in semantics check only mode, then it would be wrong to load
2151 -- bodies that are not required from a semantic point of view, so
2152 -- in this case we return Empty. The result is that the caller may
2153 -- incorrectly decide that a generic spec does not have a body when
2154 -- in fact it does, but the only harm in this is that some warnings
2155 -- on elaboration problems may be lost in semantic checks only mode,
2156 -- which is not big loss. We also return Empty if we go for a body
2157 -- and it is not there.
2159 function Locate_Corresponding_Body
(PE
: Entity_Id
) return Node_Id
;
2160 -- PE is the entity for a package spec. This function locates the
2161 -- corresponding package body, returning Empty if none is found.
2162 -- The package body returned is fully parsed but may not yet be
2163 -- analyzed, so only syntactic fields should be referenced.
2169 function Find_Body_In
(E
: Entity_Id
; N
: Node_Id
) return Node_Id
is
2174 while Present
(Nod
) loop
2176 -- If we found the package body we are looking for, return it
2178 if Nkind
(Nod
) = N_Package_Body
2179 and then Chars
(Defining_Unit_Name
(Nod
)) = Chars
(E
)
2183 -- If we found the stub for the body, go after the subunit,
2184 -- loading it if necessary.
2186 elsif Nkind
(Nod
) = N_Package_Body_Stub
2187 and then Chars
(Defining_Identifier
(Nod
)) = Chars
(E
)
2189 if Present
(Library_Unit
(Nod
)) then
2190 return Unit
(Library_Unit
(Nod
));
2193 return Load_Package_Body
(Get_Unit_Name
(Nod
));
2196 -- If neither package body nor stub, keep looking on chain
2206 -----------------------
2207 -- Load_Package_Body --
2208 -----------------------
2210 function Load_Package_Body
(Nam
: Unit_Name_Type
) return Node_Id
is
2211 U
: Unit_Number_Type
;
2214 if Operating_Mode
/= Generate_Code
then
2227 return Unit
(Cunit
(U
));
2230 end Load_Package_Body
;
2232 -------------------------------
2233 -- Locate_Corresponding_Body --
2234 -------------------------------
2236 function Locate_Corresponding_Body
(PE
: Entity_Id
) return Node_Id
is
2237 Spec
: constant Node_Id
:= Declaration_Node
(PE
);
2238 Decl
: constant Node_Id
:= Parent
(Spec
);
2239 Scop
: constant Entity_Id
:= Scope
(PE
);
2243 if Is_Library_Level_Entity
(PE
) then
2245 -- If package is a library unit that requires a body, we have
2246 -- no choice but to go after that body because it might contain
2247 -- an optional body for the original generic package.
2249 if Unit_Requires_Body
(PE
) then
2251 -- Load the body. Note that we are a little careful here to
2252 -- use Spec to get the unit number, rather than PE or Decl,
2253 -- since in the case where the package is itself a library
2254 -- level instantiation, Spec will properly reference the
2255 -- generic template, which is what we really want.
2259 (Get_Body_Name
(Unit_Name
(Get_Source_Unit
(Spec
))));
2261 -- But if the package is a library unit that does NOT require
2262 -- a body, then no body is permitted, so we are sure that there
2263 -- is no body for the original generic package.
2269 -- Otherwise look and see if we are embedded in a further package
2271 elsif Is_Package
(Scop
) then
2273 -- If so, get the body of the enclosing package, and look in
2274 -- its package body for the package body we are looking for.
2276 PBody
:= Locate_Corresponding_Body
(Scop
);
2281 return Find_Body_In
(PE
, First
(Declarations
(PBody
)));
2284 -- If we are not embedded in a further package, then the body
2285 -- must be in the same declarative part as we are.
2288 return Find_Body_In
(PE
, Next
(Decl
));
2290 end Locate_Corresponding_Body
;
2292 -- Start of processing for Has_Generic_Body
2295 if Present
(Corresponding_Body
(Decl
)) then
2298 elsif Unit_Requires_Body
(Ent
) then
2301 -- Compilation units cannot have optional bodies
2303 elsif Is_Compilation_Unit
(Ent
) then
2306 -- Otherwise look at what scope we are in
2309 Scop
:= Scope
(Ent
);
2311 -- Case of entity is in other than a package spec, in this case
2312 -- the body, if present, must be in the same declarative part.
2314 if not Is_Package
(Scop
) then
2319 P
:= Declaration_Node
(Ent
);
2321 -- Declaration node may get us a spec, so if so, go to
2322 -- the parent declaration.
2324 while not Is_List_Member
(P
) loop
2328 return Present
(Find_Body_In
(Ent
, Next
(P
)));
2331 -- If the entity is in a package spec, then we have to locate
2332 -- the corresponding package body, and look there.
2336 PBody
: constant Node_Id
:= Locate_Corresponding_Body
(Scop
);
2344 (Find_Body_In
(Ent
, (First
(Declarations
(PBody
)))));
2349 end Has_Generic_Body
;
2351 -----------------------
2352 -- Insert_Elab_Check --
2353 -----------------------
2355 procedure Insert_Elab_Check
(N
: Node_Id
; C
: Node_Id
:= Empty
) is
2357 Loc
: constant Source_Ptr
:= Sloc
(N
);
2360 -- If expansion is disabled, do not generate any checks. Also
2361 -- skip checks if any subunits are missing because in either
2362 -- case we lack the full information that we need, and no object
2363 -- file will be created in any case.
2365 if not Expander_Active
or else Subunits_Missing
then
2369 -- If we have a generic instantiation, where Instance_Spec is set,
2370 -- then this field points to a generic instance spec that has
2371 -- been inserted before the instantiation node itself, so that
2372 -- is where we want to insert a check.
2374 if Nkind
(N
) in N_Generic_Instantiation
2375 and then Present
(Instance_Spec
(N
))
2377 Nod
:= Instance_Spec
(N
);
2382 -- If we are inserting at the top level, insert in Aux_Decls
2384 if Nkind
(Parent
(Nod
)) = N_Compilation_Unit
then
2386 ADN
: constant Node_Id
:= Aux_Decls_Node
(Parent
(Nod
));
2392 Make_Raise_Program_Error
(Loc
,
2393 Reason
=> PE_Access_Before_Elaboration
);
2396 Make_Raise_Program_Error
(Loc
,
2397 Condition
=> Make_Op_Not
(Loc
, C
),
2398 Reason
=> PE_Access_Before_Elaboration
);
2401 if No
(Declarations
(ADN
)) then
2402 Set_Declarations
(ADN
, New_List
(R
));
2404 Append_To
(Declarations
(ADN
), R
);
2410 -- Otherwise just insert before the node in question. However, if
2411 -- the context of the call has already been analyzed, an insertion
2412 -- will not work if it depends on subsequent expansion (e.g. a call in
2413 -- a branch of a short-circuit). In that case we replace the call with
2414 -- a conditional expression, or with a Raise if it is unconditional.
2415 -- Unfortunately this does not work if the call has a dynamic size,
2416 -- because gigi regards it as a dynamic-sized temporary. If such a call
2417 -- appears in a short-circuit expression, the elaboration check will be
2418 -- missed (rare enough ???). Otherwise, the code below inserts the check
2419 -- at the appropriate place before the call. Same applies in the even
2420 -- rarer case the return type has a known size but is unconstrained.
2423 if Nkind
(N
) = N_Function_Call
2424 and then Analyzed
(Parent
(N
))
2425 and then Size_Known_At_Compile_Time
(Etype
(N
))
2427 (not Has_Discriminants
(Etype
(N
))
2428 or else Is_Constrained
(Etype
(N
)))
2432 Typ
: constant Entity_Id
:= Etype
(N
);
2433 Chk
: constant Boolean := Do_Range_Check
(N
);
2435 R
: constant Node_Id
:=
2436 Make_Raise_Program_Error
(Loc
,
2437 Reason
=> PE_Access_Before_Elaboration
);
2447 Make_Conditional_Expression
(Loc
,
2448 Expressions
=> New_List
(C
, Relocate_Node
(N
), R
)));
2451 Analyze_And_Resolve
(N
, Typ
);
2453 -- If the original call requires a range check, so does the
2454 -- conditional expression.
2457 Enable_Range_Check
(N
);
2459 Set_Do_Range_Check
(N
, False);
2466 Make_Raise_Program_Error
(Loc
,
2467 Reason
=> PE_Access_Before_Elaboration
));
2470 Make_Raise_Program_Error
(Loc
,
2474 Reason
=> PE_Access_Before_Elaboration
));
2478 end Insert_Elab_Check
;
2484 procedure Output_Calls
(N
: Node_Id
) is
2487 function Is_Printable_Error_Name
(Nm
: Name_Id
) return Boolean;
2488 -- An internal function, used to determine if a name, Nm, is either
2489 -- a non-internal name, or is an internal name that is printable
2490 -- by the error message circuits (i.e. it has a single upper
2491 -- case letter at the end).
2493 function Is_Printable_Error_Name
(Nm
: Name_Id
) return Boolean is
2495 if not Is_Internal_Name
(Nm
) then
2498 elsif Name_Len
= 1 then
2502 Name_Len
:= Name_Len
- 1;
2503 return not Is_Internal_Name
;
2505 end Is_Printable_Error_Name
;
2507 -- Start of processing for Output_Calls
2510 for J
in reverse 1 .. Elab_Call
.Last
loop
2511 Error_Msg_Sloc
:= Elab_Call
.Table
(J
).Cloc
;
2513 Ent
:= Elab_Call
.Table
(J
).Ent
;
2515 if Is_Generic_Unit
(Ent
) then
2516 Error_Msg_NE
("\?& instantiated #", N
, Ent
);
2518 elsif Is_Init_Proc
(Ent
) then
2519 Error_Msg_N
("\?initialization procedure called #", N
);
2521 elsif Is_Printable_Error_Name
(Chars
(Ent
)) then
2522 Error_Msg_NE
("\?& called #", N
, Ent
);
2525 Error_Msg_N
("\? called #", N
);
2530 ----------------------------
2531 -- Same_Elaboration_Scope --
2532 ----------------------------
2534 function Same_Elaboration_Scope
(Scop1
, Scop2
: Entity_Id
) return Boolean is
2535 S1
: Entity_Id
:= Scop1
;
2536 S2
: Entity_Id
:= Scop2
;
2539 while S1
/= Standard_Standard
2540 and then (Ekind
(S1
) = E_Package
2542 Ekind
(S1
) = E_Block
)
2547 while S2
/= Standard_Standard
2548 and then (Ekind
(S2
) = E_Package
2550 Ekind
(S2
) = E_Protected_Type
2552 Ekind
(S2
) = E_Block
)
2558 end Same_Elaboration_Scope
;
2564 procedure Set_C_Scope
is
2566 while not Is_Compilation_Unit
(C_Scope
) loop
2567 C_Scope
:= Scope
(C_Scope
);
2575 function Spec_Entity
(E
: Entity_Id
) return Entity_Id
is
2579 -- Check for case of body entity
2580 -- Why is the check for E_Void needed???
2582 if Ekind
(E
) = E_Void
2583 or else Ekind
(E
) = E_Subprogram_Body
2584 or else Ekind
(E
) = E_Package_Body
2589 Decl
:= Parent
(Decl
);
2590 exit when Nkind
(Decl
) in N_Proper_Body
;
2593 return Corresponding_Spec
(Decl
);
2604 procedure Supply_Bodies
(N
: Node_Id
) is
2606 if Nkind
(N
) = N_Subprogram_Declaration
then
2608 Ent
: constant Entity_Id
:= Defining_Unit_Name
(Specification
(N
));
2611 Set_Is_Imported
(Ent
);
2612 Set_Convention
(Ent
, Convention_Stubbed
);
2615 elsif Nkind
(N
) = N_Package_Declaration
then
2617 Spec
: constant Node_Id
:= Specification
(N
);
2620 New_Scope
(Defining_Unit_Name
(Spec
));
2621 Supply_Bodies
(Visible_Declarations
(Spec
));
2622 Supply_Bodies
(Private_Declarations
(Spec
));
2628 procedure Supply_Bodies
(L
: List_Id
) is
2634 while Present
(Elmt
) loop
2635 Supply_Bodies
(Elmt
);
2645 function Within
(E1
, E2
: Entity_Id
) return Boolean is
2655 elsif Scop
= Standard_Standard
then
2659 Scop
:= Scope
(Scop
);
2663 raise Program_Error
;
2666 --------------------------
2667 -- Within_Elaborate_All --
2668 --------------------------
2670 function Within_Elaborate_All
(E
: Entity_Id
) return Boolean is
2673 Elab_Id
: Entity_Id
;
2677 Item
:= First
(Context_Items
(Cunit
(Current_Sem_Unit
)));
2679 while Present
(Item
) loop
2680 if Nkind
(Item
) = N_Pragma
2681 and then Get_Pragma_Id
(Chars
(Item
)) = Pragma_Elaborate_All
2683 if Error_Posted
(Item
) then
2685 -- Some previous error on the pragma itself
2692 Expression
(First
(Pragma_Argument_Associations
(Item
))));
2694 Par
:= Parent
(Unit_Declaration_Node
(Elab_Id
));
2695 Item2
:= First
(Context_Items
(Par
));
2697 while Present
(Item2
) loop
2698 if Nkind
(Item2
) = N_With_Clause
2699 and then Entity
(Name
(Item2
)) = E
2712 end Within_Elaborate_All
;