PR tree-optimization/82929
[official-gcc.git] / gcc / ada / sem_elab.adb
blobb3077adfbf8fe5db31c057335f3def0952cba490
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-2017, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Atree; use Atree;
27 with Debug; use Debug;
28 with Einfo; use Einfo;
29 with Elists; use Elists;
30 with Errout; use Errout;
31 with Exp_Ch11; use Exp_Ch11;
32 with Exp_Tss; use Exp_Tss;
33 with Exp_Util; use Exp_Util;
34 with Lib; use Lib;
35 with Lib.Load; use Lib.Load;
36 with Namet; use Namet;
37 with Nlists; use Nlists;
38 with Nmake; use Nmake;
39 with Opt; use Opt;
40 with Restrict; use Restrict;
41 with Rident; use Rident;
42 with Rtsfind; use Rtsfind;
43 with Sem; use Sem;
44 with Sem_Aux; use Sem_Aux;
45 with Sem_Ch7; use Sem_Ch7;
46 with Sem_Ch8; use Sem_Ch8;
47 with Sem_Prag; use Sem_Prag;
48 with Sem_Util; use Sem_Util;
49 with Sinfo; use Sinfo;
50 with Snames; use Snames;
51 with Stand; use Stand;
52 with Table;
53 with Tbuild; use Tbuild;
54 with Uintp; use Uintp;
55 with Uname; use Uname;
57 with GNAT.HTable; use GNAT.HTable;
59 package body Sem_Elab is
61 -----------------------------------------
62 -- Access-before-elaboration mechanism --
63 -----------------------------------------
65 -- The access-before-elaboration (ABE) mechanism implemented in this unit
66 -- has the following objectives:
68 -- * Diagnose at compile-time or install run-time checks to prevent ABE
69 -- access to data and behaviour.
71 -- The high-level idea is to accurately diagnose ABE issues within a
72 -- single unit because the ABE mechanism can inspect the whole unit.
73 -- As soon as the elaboration graph extends to an external unit, the
74 -- diagnostics stop because the body of the unit may not be available.
75 -- Due to control and data flow, the ABE mechanism cannot accurately
76 -- determine whether a particular scenario will be elaborated or not.
77 -- Conditional ABE checks are therefore used to verify the elaboration
78 -- status of a local and external target at run time.
80 -- * Supply elaboration dependencies for a unit to binde
82 -- The ABE mechanism registers each outgoing elaboration edge for the
83 -- main unit in its ALI file. GNATbind and binde can then reconstruct
84 -- the full elaboration graph and determine the proper elaboration
85 -- order for all units in the compilation.
87 -- The ABE mechanism supports three models of elaboration:
89 -- * Dynamic model - This is the most permissive of the three models.
90 -- When the dynamic model is in effect, the mechanism performs very
91 -- little diagnostics and generates run-time checks to detect ABE
92 -- issues. The behaviour of this model is identical to that specified
93 -- by the Ada RM. This model is enabled with switch -gnatE.
95 -- * Static model - This is the middle ground of the three models. When
96 -- the static model is in effect, the mechanism diagnoses and installs
97 -- run-time checks to detect ABE issues in the main unit. In addition,
98 -- the mechanism generates implicit Elaborate or Elaborate_All pragmas
99 -- to ensure the prior elaboration of withed units. The model employs
100 -- textual order, with clause context, and elaboration-related source
101 -- pragmas. This is the default model.
103 -- * SPARK model - This is the most conservative of the three models and
104 -- impelements the semantics defined in SPARK RM 7.7. The SPARK model
105 -- is in effect only when a context resides in a SPARK_Mode On region,
106 -- otherwise the mechanism falls back to one of the previous models.
108 -- The ABE mechanism consists of a "recording" phase and a "processing"
109 -- phase.
111 -----------------
112 -- Terminology --
113 -----------------
115 -- * Bridge target - A type of target. A bridge target is a link between
116 -- scenarios. It is usually a byproduct of expansion and does not have
117 -- any direct ABE ramifications.
119 -- * Call marker - A special node used to indicate the presence of a call
120 -- in the tree in case expansion transforms or eliminates the original
121 -- call. N_Call_Marker nodes do not have static and run-time semantics.
123 -- * Conditional ABE - A type of ABE. A conditional ABE occurs when the
124 -- elaboration or invocation of a target by a scenario within the main
125 -- unit causes an ABE, but does not cause an ABE for another scenarios
126 -- within the main unit.
128 -- * Declaration level - A type of enclosing level. A scenario or target is
129 -- at the declaration level when it appears within the declarations of a
130 -- block statement, entry body, subprogram body, or task body, ignoring
131 -- enclosing packages.
133 -- * Generic library level - A type of enclosing level. A scenario or
134 -- target is at the generic library level if it appears in a generic
135 -- package library unit, ignoring enclosing packages.
137 -- * Guaranteed ABE - A type of ABE. A guaranteed ABE occurs when the
138 -- elaboration or invocation of a target by all scenarios within the
139 -- main unit causes an ABE.
141 -- * Instantiation library level - A type of enclosing level. A scenario
142 -- or target is at the instantiation library level if it appears in an
143 -- instantiation library unit, ignoring enclosing packages.
145 -- * Library level - A type of enclosing level. A scenario or target is at
146 -- the library level if it appears in a package library unit, ignoring
147 -- enclosng packages.
149 -- * Non-library-level encapsulator - A construct that cannot be elaborated
150 -- on its own and requires elaboration by a top-level scenario.
152 -- * Scenario - A construct or context which may be elaborated or executed
153 -- by elaboration code. The scenarios recognized by the ABE mechanism are
154 -- as follows:
156 -- - '[Unrestricted_]Access of entries, operators, and subprograms
158 -- - Assignments to variables
160 -- - Calls to entries, operators, and subprograms
162 -- - Instantiations
164 -- - Reads of variables
166 -- - Task activation
168 -- * Target - A construct referenced by a scenario. The targets recognized
169 -- by the ABE mechanism are as follows:
171 -- - For '[Unrestricted_]Access of entries, operators, and subprograms,
172 -- the target is the entry, operator, or subprogram.
174 -- - For assignments to variables, the target is the variable
176 -- - For calls, the target is the entry, operator, or subprogram
178 -- - For instantiations, the target is the generic template
180 -- - For reads of variables, the target is the variable
182 -- - For task activation, the target is the task body
184 -- * Top-level scenario - A scenario which appears in a non-generic main
185 -- unit. Depending on the elaboration model is in effect, the following
186 -- addotional restrictions apply:
188 -- - Dynamic model - No restrictions
190 -- - SPARK model - Falls back to either the dynamic or static model
192 -- - Static model - The scenario must be at the library level
194 ---------------------
195 -- Recording phase --
196 ---------------------
198 -- The Recording phase coincides with the analysis/resolution phase of the
199 -- compiler. It has the following objectives:
201 -- * Record all top-level scenarios for examination by the Processing
202 -- phase.
204 -- Saving only a certain number of nodes improves the performance of
205 -- the ABE mechanism. This eliminates the need to examine the whole
206 -- tree in a separate pass.
208 -- * Detect and diagnose calls in preelaborable or pure units, including
209 -- generic bodies.
211 -- This diagnostic is carried out during the Recording phase because it
212 -- does not need the heavy recursive traversal done by the Processing
213 -- phase.
215 -- * Detect and diagnose guaranteed ABEs caused by instantiations,
216 -- calls, and task activation.
218 -- The issues detected by the ABE mechanism are reported as warnings
219 -- because they do not violate Ada semantics. Forward instantiations
220 -- may thus reach gigi, however gigi cannot handle certain kinds of
221 -- premature instantiations and may crash. To avoid this limitation,
222 -- the ABE mechanism must identify forward instantiations as early as
223 -- possible and suppress their bodies. Calls and task activations are
224 -- included in this category for completeness.
226 ----------------------
227 -- Processing phase --
228 ----------------------
230 -- The Processing phase is a separate pass which starts after instantiating
231 -- and/or inlining of bodies, but before the removal of Ghost code. It has
232 -- the following objectives:
234 -- * Examine all top-level scenarios saved during the Recording phase
236 -- The top-level scenarios act as roots for depth-first traversal of
237 -- the call/instantiation/task activation graph. The traversal stops
238 -- when an outgoing edge leaves the main unit.
240 -- * Depending on the elaboration model in effect, perform the following
241 -- actions:
243 -- - Dynamic model - Diagnose guaranteed ABEs and install run-time
244 -- conditional ABE checks.
246 -- - SPARK model - Enforce the SPARK elaboration rules
248 -- - Static model - Diagnose conditional/guaranteed ABEs, install
249 -- run-time conditional ABE checks, and guarantee the elaboration
250 -- of external units.
252 -- * Examine nested scenarios
254 -- Nested scenarios discovered during the depth-first traversal are
255 -- in turn subjected to the same actions outlined above and examined
256 -- for the next level of nested scenarios.
258 ------------------
259 -- Architecture --
260 ------------------
262 -- +------------------------ Recording phase ---------------------------+
263 -- | |
264 -- | Record_Elaboration_Scenario |
265 -- | | |
266 -- | +--> Check_Preelaborated_Call |
267 -- | | |
268 -- | +--> Process_Guaranteed_ABE |
269 -- | | |
270 -- +------------------------- | --------------------------------------+
271 -- |
272 -- |
273 -- v
274 -- Top_Level_Scenarios
275 -- +-----------+-----------+ .. +-----------+
276 -- | Scenario1 | Scenario2 | .. | ScenarioN |
277 -- +-----------+-----------+ .. +-----------+
278 -- |
279 -- |
280 -- +------------------------- | --------------------------------------+
281 -- | | |
282 -- | Check_Elaboration_Scenarios |
283 -- | | |
284 -- | v |
285 -- | +----------- Process_Scenario <-----------+ |
286 -- | | | |
287 -- | +--> Process_Access Is_Suitable_Scenario |
288 -- | | ^ |
289 -- | +--> Process_Activation_Call --+ | |
290 -- | | +---> Traverse_Body |
291 -- | +--> Process_Call -------------+ |
292 -- | | |
293 -- | +--> Process_Instantiation |
294 -- | | |
295 -- | +--> Process_Variable_Assignment |
296 -- | | |
297 -- | +--> Process_Variable_Reference |
298 -- | |
299 -- +------------------------- Processing phase -------------------------+
301 ----------------------
302 -- Important points --
303 ----------------------
305 -- The Processing phase starts after the analysis, resolution, expansion
306 -- phase has completed. As a result, no current semantic information is
307 -- available. The scope stack is empty, global flags such as In_Instance
308 -- or Inside_A_Generic become useless. To remedy this, the ABE mechanism
309 -- must either save or recompute semantic information.
311 -- Expansion heavily transforms calls and to some extent instantiations. To
312 -- remedy this, the ABE mechanism generates N_Call_Marker nodes in order to
313 -- capture the target and relevant attributes of the original call.
315 -- The diagnostics of the ABE mechanism depend on accurate source locations
316 -- to determine the spacial relation of nodes.
318 --------------
319 -- Switches --
320 --------------
322 -- The following switches may be used to control the behavior of the ABE
323 -- mechanism.
325 -- -gnatdE elaboration checks on predefined units
327 -- The ABE mechanism considers scenarios which appear in internal
328 -- units (Ada, GNAT, Interfaces, System).
330 -- -gnatd.G ignore calls through generic formal parameters for elaboration
332 -- The ABE mechanism does not generate N_Call_Marker nodes for
333 -- calls which occur in expanded instances, and invoke generic
334 -- actual subprograms through generic formal subprograms. As a
335 -- result, the calls are not recorded or processed.
337 -- If switches -gnatd.G and -gnatdL are used together, then the
338 -- ABE mechanism effectively ignores all calls which cause the
339 -- elaboration flow to "leave" the instance.
341 -- -gnatdL ignore external calls from instances for elaboration
343 -- The ABE mechanism does not generate N_Call_Marker nodes for
344 -- calls which occur in expanded instances, do not invoke generic
345 -- actual subprograms through formal subprograms, and the target
346 -- is external to the instance. As a result, the calls are not
347 -- recorded or processed.
349 -- If switches -gnatd.G and -gnatdL are used together, then the
350 -- ABE mechanism effectively ignores all calls which cause the
351 -- elaboration flow to "leave" the instance.
353 -- -gnatd.o conservative elaboration order for indirect calls
355 -- The ABE mechanism treats '[Unrestricted_]Access of an entry,
356 -- operator, or subprogram as an immediate invocation of the
357 -- target. As a result, it performs ABE checks and diagnostics on
358 -- the immediate call.
360 -- -gnatd.U ignore indirect calls for static elaboration
362 -- The ABE mechanism does not consider '[Unrestricted_]Access of
363 -- entries, operators, and subprograms. As a result, the scenarios
364 -- are not recorder or processed.
366 -- -gnatd.v enforce SPARK elaboration rules in SPARK code
368 -- The ABE mechanism applies some of the SPARK elaboration rules
369 -- defined in the SPARK reference manual, chapter 7.7. Note that
370 -- certain rules are always enforced, regardless of whether the
371 -- switch is active.
373 -- -gnatd.y disable implicit pragma Elaborate_All on task bodies
375 -- The ABE mechanism does not generate implicit Elaborate_All when
376 -- the need for the pragma came from a task body.
378 -- -gnatE dynamic elaboration checking mode enabled
380 -- The ABE mechanism assumes that any scenario is elaborated or
381 -- invoked by elaboration code. The ABE mechanism performs very
382 -- little diagnostics and generates condintional ABE checks to
383 -- detect ABE issues at run-time.
385 -- -gnatel turn on info messages on generated Elaborate[_All] pragmas
387 -- The ABE mechanism produces information messages on generated
388 -- implicit Elabote[_All] pragmas along with traceback showing
389 -- why the pragma was generated. In addition, the ABE mechanism
390 -- produces information messages for each scenario elaborated or
391 -- invoked by elaboration code.
393 -- -gnateL turn off info messages on generated Elaborate[_All] pragmas
395 -- The complimentary switch for -gnatel.
397 -- -gnatwl turn on warnings for elaboration problems
399 -- The ABE mechanism produces warnings on detected ABEs along with
400 -- traceback showing the graph of the ABE.
402 -- -gnatwL turn off warnings for elaboration problems
404 -- The complimentary switch for -gnatwl.
406 -- -gnatw.f turn on warnings for suspicious Subp'Access
408 -- The ABE mechanism treats '[Unrestricted_]Access of an entry,
409 -- operator, or subprogram as a pseudo invocation of the target.
410 -- As a result, it performs ABE diagnostics on the pseudo call.
412 -- -gnatw.F turn off warnings for suspicious Subp'Access
414 -- The complimentary switch for -gnatw.f.
416 ---------------------------
417 -- Adding a new scenario --
418 ---------------------------
420 -- The following steps describe how to add a new elaboration scenario and
421 -- preserve the existing architecture.
423 -- 1) If necessary, update predicate Is_Scenario
425 -- 2) Add predicate Is_Suitable_xxx. Include a call to it in predicate
426 -- Is_Suitable_Scenario.
428 -- 3) Update routine Record_Elaboration_Scenario
430 -- 4) Add routine Process_xxx. Include a call to it in Process_Scenario.
432 -- 5) Add routine Info_xxx. Include a call to it in Process_xxx.
434 -- 6) Add routine Output_xxx. Include a call to it in routine
435 -- Output_Active_Scenarios.
437 -- 7) If necessary, add a new Extract_xxx_Attributes routine
439 -- 8) If necessary, update routine Is_Potential_Scenario
441 -------------------------
442 -- Adding a new target --
443 -------------------------
445 -- The following steps describe how to add a new elaboration target and
446 -- preserve the existing architecture.
448 -- 1) Add predicate Is_xxx.
450 -- 2) Update predicates Is_Ada_Semantic_Target, Is_Bridge_Target, or
451 -- Is_SPARK_Semantic_Target. If necessary, create a new category.
453 -- 3) Update the appropriate Info_xxx routine.
455 -- 4) Update the appropriate Output_xxx routine.
457 -- 5) Update routine Extract_Target_Attributes. If necessary, create a
458 -- new Extract_xxx routine.
460 --------------------------
461 -- Debugging ABE issues --
462 --------------------------
464 -- * If the issue involves a call, ensure that the call is eligible for ABE
465 -- processing and receives a corresponding call marker. The routines of
466 -- interest are
468 -- Build_Call_Marker
469 -- Record_Elaboration_Scenario
471 -- * If the issue involves an arbitrary scenario, ensure that the scenario
472 -- is either recorded, or is successfully recognized while traversing a
473 -- body. The routines of interest are
475 -- Record_Elaboration_Scenario
476 -- Process_Scenario
477 -- Traverse_Body
479 -- * If the issue involves a circularity in the elaboration order, examine
480 -- the ALI files and look for the following encodings next to units:
482 -- E indicates a source Elaborate
484 -- EA indicates a source Elaborate_All
486 -- AD indicates an implicit Elaborate_All
488 -- ED indicates an implicit Elaborate
490 -- If possible, compare these encodings with those generated by the old
491 -- ABE mechanism. The routines of interest are
493 -- Ensure_Prior_Elaboration
495 ----------------
496 -- Attributes --
497 ----------------
499 -- The following type captures relevant attributes which pertain to a call
501 type Call_Attributes is record
502 Elab_Checks_OK : Boolean;
503 -- This flag is set when the call has elaboration checks enabled
505 From_Source : Boolean;
506 -- This flag is set when the call comes from source
508 Ghost_Mode_Ignore : Boolean;
509 -- This flag is set when the call appears in a region subject to pragma
510 -- Ghost with policy Ignore.
512 In_Declarations : Boolean;
513 -- This flag is set when the call appears at the declaration level
515 Is_Dispatching : Boolean;
516 -- This flag is set when the call is dispatching
518 SPARK_Mode_On : Boolean;
519 -- This flag is set when the call appears in a region subject to pragma
520 -- SPARK_Mode with value On.
521 end record;
523 -- The following type captures relevant attributes which pertain to the
524 -- prior elaboration of a unit. This type is coupled together with a unit
525 -- to form a key -> value relationship.
527 type Elaboration_Attributes is record
528 Source_Pragma : Node_Id;
529 -- This attribute denotes a source Elaborate or Elaborate_All pragma
530 -- which guarantees the prior elaboration of some unit with respect
531 -- to the main unit. The pragma may come from the following contexts:
533 -- * The main unit
534 -- * The spec of the main unit (if applicable)
535 -- * Any parent spec of the main unit (if applicable)
536 -- * Any parent subunit of the main unit (if applicable)
538 -- The attribute remains Empty if no such pragma is available. Source
539 -- pragmas play a role in satisfying SPARK elaboration requirements.
541 With_Clause : Node_Id;
542 -- This attribute denotes an internally generated or source with clause
543 -- for some unit withed by the main unit. With clauses carry flags which
544 -- represent implicit Elaborate or Elaborate_All pragmas. These clauses
545 -- play a role in supplying the elaboration dependencies to binde.
546 end record;
548 No_Elaboration_Attributes : constant Elaboration_Attributes :=
549 (Source_Pragma => Empty,
550 With_Clause => Empty);
552 -- The following type captures relevant attributes which pertain to an
553 -- instantiation.
555 type Instantiation_Attributes is record
556 Elab_Checks_OK : Boolean;
557 -- This flag is set when the instantiation has elaboration checks
558 -- enabled.
560 Ghost_Mode_Ignore : Boolean;
561 -- This flag is set when the instantiation appears in a region subject
562 -- to pragma Ghost with policy ignore, or starts one such region.
564 In_Declarations : Boolean;
565 -- This flag is set when the instantiation appears at the declaration
566 -- level.
568 SPARK_Mode_On : Boolean;
569 -- This flag is set when the instantiation appears in a region subject
570 -- to pragma SPARK_Mode with value On, or starts one such region.
571 end record;
573 -- The following type captures relevant attributes which pertain to a
574 -- target.
576 type Target_Attributes is record
577 Elab_Checks_OK : Boolean;
578 -- This flag is set when the target has elaboration checks enabled
580 From_Source : Boolean;
581 -- This flag is set when the target comes from source
583 Ghost_Mode_Ignore : Boolean;
584 -- This flag is set when the target appears in a region subject to
585 -- pragma Ghost with policy ignore, or starts one such region.
587 SPARK_Mode_On : Boolean;
588 -- This flag is set when the target appears in a region subject to
589 -- pragma SPARK_Mode with value On, or starts one such region.
591 Spec_Decl : Node_Id;
592 -- This attribute denotes the declaration of Spec_Id
594 Unit_Id : Entity_Id;
595 -- This attribute denotes the top unit where Spec_Id resides
597 -- The semantics of the following attributes depend on the target
599 Body_Barf : Node_Id;
600 Body_Decl : Node_Id;
601 Spec_Id : Entity_Id;
603 -- The target is a generic package or a subprogram
605 -- * Body_Barf - Empty
607 -- * Body_Decl - This attribute denotes the generic or subprogram
608 -- body.
610 -- * Spec_Id - This attribute denotes the entity of the generic
611 -- package or subprogram.
613 -- The target is a protected entry
615 -- * Body_Barf - This attribute denotes the body of the barrier
616 -- function if expansion took place, otherwise it is Empty.
618 -- * Body_Decl - This attribute denotes the body of the procedure
619 -- which emulates the entry if expansion took place, otherwise it
620 -- denotes the body of the protected entry.
622 -- * Spec_Id - This attribute denotes the entity of the procedure
623 -- which emulates the entry if expansion took place, otherwise it
624 -- denotes the protected entry.
626 -- The target is a protected subprogram
628 -- * Body_Barf - Empty
630 -- * Body_Decl - This attribute denotes the body of the protected or
631 -- unprotected version of the protected subprogram if expansion took
632 -- place, otherwise it denotes the body of the protected subprogram.
634 -- * Spec_Id - This attribute denotes the entity of the protected or
635 -- unprotected version of the protected subprogram if expansion took
636 -- place, otherwise it is the entity of the protected subprogram.
638 -- The target is a task entry
640 -- * Body_Barf - Empty
642 -- * Body_Decl - This attribute denotes the body of the procedure
643 -- which emulates the task body if expansion took place, otherwise
644 -- it denotes the body of the task type.
646 -- * Spec_Id - This attribute denotes the entity of the procedure
647 -- which emulates the task body if expansion took place, otherwise
648 -- it denotes the entity of the task type.
649 end record;
651 -- The following type captures relevant attributes which pertain to a task
652 -- type.
654 type Task_Attributes is record
655 Body_Decl : Node_Id;
656 -- This attribute denotes the declaration of the procedure body which
657 -- emulates the behaviour of the task body.
659 Elab_Checks_OK : Boolean;
660 -- This flag is set when the task type has elaboration checks enabled
662 Ghost_Mode_Ignore : Boolean;
663 -- This flag is set when the task type appears in a region subject to
664 -- pragma Ghost with policy ignore, or starts one such region.
666 SPARK_Mode_On : Boolean;
667 -- This flag is set when the task type appears in a region subject to
668 -- pragma SPARK_Mode with value On, or starts one such region.
670 Spec_Id : Entity_Id;
671 -- This attribute denotes the entity of the initial declaration of the
672 -- procedure body which emulates the behaviour of the task body.
674 Task_Decl : Node_Id;
675 -- This attribute denotes the declaration of the task type
677 Unit_Id : Entity_Id;
678 -- This attribute denotes the entity of the compilation unit where the
679 -- task type resides.
680 end record;
682 -- The following type captures relevant attributes which pertain to a
683 -- variable.
685 type Variable_Attributes is record
686 Unit_Id : Entity_Id;
687 -- This attribute denotes the entity of the compilation unit where the
688 -- variable resides.
689 end record;
691 ---------------------
692 -- Data structures --
693 ---------------------
695 -- The following table stores the elaboration status of all units withed by
696 -- the main unit.
698 Elaboration_Context_Max : constant := 1009;
700 type Elaboration_Context_Index is range 0 .. Elaboration_Context_Max - 1;
702 function Elaboration_Context_Hash
703 (Key : Entity_Id) return Elaboration_Context_Index;
704 -- Obtain the hash value of entity Key
706 package Elaboration_Context is new Simple_HTable
707 (Header_Num => Elaboration_Context_Index,
708 Element => Elaboration_Attributes,
709 No_Element => No_Elaboration_Attributes,
710 Key => Entity_Id,
711 Hash => Elaboration_Context_Hash,
712 Equal => "=");
714 -- The following table stores a status flag for each top-level scenario
715 -- recorded in table Top_Level_Scenarios.
717 Recorded_Top_Level_Scenarios_Max : constant := 503;
719 type Recorded_Top_Level_Scenarios_Index is
720 range 0 .. Recorded_Top_Level_Scenarios_Max - 1;
722 function Recorded_Top_Level_Scenarios_Hash
723 (Key : Node_Id) return Recorded_Top_Level_Scenarios_Index;
724 -- Obtain the hash value of entity Key
726 package Recorded_Top_Level_Scenarios is new Simple_HTable
727 (Header_Num => Recorded_Top_Level_Scenarios_Index,
728 Element => Boolean,
729 No_Element => False,
730 Key => Node_Id,
731 Hash => Recorded_Top_Level_Scenarios_Hash,
732 Equal => "=");
734 -- The following table stores all active scenarios in a recursive traversal
735 -- starting from a top-level scenario. This table must be maintained in a
736 -- FIFO fashion.
738 package Scenario_Stack is new Table.Table
739 (Table_Component_Type => Node_Id,
740 Table_Index_Type => Int,
741 Table_Low_Bound => 1,
742 Table_Initial => 50,
743 Table_Increment => 100,
744 Table_Name => "Scenario_Stack");
746 -- The following table stores all top-level scenario saved during the
747 -- Recording phase. The contents of this table act as traversal roots
748 -- later in the Processing phase. This table must be maintained in a
749 -- LIFO fashion.
751 package Top_Level_Scenarios is new Table.Table
752 (Table_Component_Type => Node_Id,
753 Table_Index_Type => Int,
754 Table_Low_Bound => 1,
755 Table_Initial => 1000,
756 Table_Increment => 100,
757 Table_Name => "Top_Level_Scenarios");
759 -- The following table stores the bodies of all eligible scenarios visited
760 -- during a traversal starting from a top-level scenario. The contents of
761 -- this table must be reset upon each new traversal.
763 Visited_Bodies_Max : constant := 511;
765 type Visited_Bodies_Index is range 0 .. Visited_Bodies_Max - 1;
767 function Visited_Bodies_Hash (Key : Node_Id) return Visited_Bodies_Index;
768 -- Obtain the hash value of node Key
770 package Visited_Bodies is new Simple_HTable
771 (Header_Num => Visited_Bodies_Index,
772 Element => Boolean,
773 No_Element => False,
774 Key => Node_Id,
775 Hash => Visited_Bodies_Hash,
776 Equal => "=");
778 -----------------------
779 -- Local subprograms --
780 -----------------------
782 procedure Check_Preelaborated_Call (Call : Node_Id);
783 -- Determine whether entry, operator, or subprogram call Call appears at
784 -- the library level of a preelaborated unit. Emit an error if this is the
785 -- case.
787 function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id;
788 pragma Inline (Compilation_Unit);
789 -- Return the N_Compilation_Unit node of unit Unit_Id
791 procedure Elab_Msg_NE
792 (Msg : String;
793 N : Node_Id;
794 Id : Entity_Id;
795 Info_Msg : Boolean;
796 In_SPARK : Boolean);
797 pragma Inline (Elab_Msg_NE);
798 -- Wrapper around Error_Msg_NE. Emit message Msg concerning arbitrary node
799 -- N and entity. If flag Info_Msg is set, the routine emits an information
800 -- message, otherwise it emits an error. If flag In_SPARK is set, then
801 -- string " in SPARK" is added to the end of the message.
803 procedure Ensure_Prior_Elaboration
804 (N : Node_Id;
805 Unit_Id : Entity_Id;
806 In_Partial_Fin : Boolean;
807 In_Task_Body : Boolean);
808 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit.
809 -- N denotes the related scenario. Flag In_Partial_Fin should be set when
810 -- the need for elaboration is initiated by a partial finalization routine.
811 -- Flag In_Task_Body should be set when the need for prior elaboration is
812 -- initiated from a task body.
814 procedure Ensure_Prior_Elaboration_Dynamic
815 (N : Node_Id;
816 Unit_Id : Entity_Id;
817 Prag_Nam : Name_Id);
818 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
819 -- by suggesting the use of Elaborate[_All] with name Prag_Nam. N denotes
820 -- the related scenario.
822 procedure Ensure_Prior_Elaboration_Static
823 (N : Node_Id;
824 Unit_Id : Entity_Id;
825 Prag_Nam : Name_Id);
826 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
827 -- by installing an implicit Elaborate[_All] pragma with name Prag_Nam. N
828 -- denotes the related scenario.
830 function Extract_Assignment_Name (Asmt : Node_Id) return Node_Id;
831 pragma Inline (Extract_Assignment_Name);
832 -- Obtain the Name attribute of assignment statement Asmt
834 procedure Extract_Call_Attributes
835 (Call : Node_Id;
836 Target_Id : out Entity_Id;
837 Attrs : out Call_Attributes);
838 pragma Inline (Extract_Call_Attributes);
839 -- Obtain attributes Attrs associated with call Call. Target_Id is the
840 -- entity of the call target.
842 function Extract_Call_Name (Call : Node_Id) return Node_Id;
843 pragma Inline (Extract_Call_Name);
844 -- Obtain the Name attribute of entry or subprogram call Call
846 procedure Extract_Instance_Attributes
847 (Exp_Inst : Node_Id;
848 Inst_Body : out Node_Id;
849 Inst_Decl : out Node_Id);
850 pragma Inline (Extract_Instance_Attributes);
851 -- Obtain body Inst_Body and spec Inst_Decl of expanded instance Exp_Inst
853 procedure Extract_Instantiation_Attributes
854 (Exp_Inst : Node_Id;
855 Inst : out Node_Id;
856 Inst_Id : out Entity_Id;
857 Gen_Id : out Entity_Id;
858 Attrs : out Instantiation_Attributes);
859 pragma Inline (Extract_Instantiation_Attributes);
860 -- Obtain attributes Attrs associated with expanded instantiation Exp_Inst.
861 -- Inst is the instantiation. Inst_Id is the entity of the instance. Gen_Id
862 -- is the entity of the generic unit being instantiated.
864 procedure Extract_Target_Attributes
865 (Target_Id : Entity_Id;
866 Attrs : out Target_Attributes);
867 -- Obtain attributes Attrs associated with an entry, package, or subprogram
868 -- denoted by Target_Id.
870 procedure Extract_Task_Attributes
871 (Typ : Entity_Id;
872 Attrs : out Task_Attributes);
873 pragma Inline (Extract_Task_Attributes);
874 -- Obtain attributes Attrs associated with task type Typ
876 procedure Extract_Variable_Reference_Attributes
877 (Ref : Node_Id;
878 Var_Id : out Entity_Id;
879 Attrs : out Variable_Attributes);
880 pragma Inline (Extract_Variable_Reference_Attributes);
881 -- Obtain attributes Attrs associated with reference Ref that mentions
882 -- variable Var_Id.
884 function Find_Code_Unit (N : Node_Or_Entity_Id) return Entity_Id;
885 pragma Inline (Find_Code_Unit);
886 -- Return the code unit which contains arbitrary node or entity N. This
887 -- is the unit of the file which physically contains the related construct
888 -- denoted by N except when N is within an instantiation. In that case the
889 -- unit is that of the top-level instantiation.
891 procedure Find_Elaborated_Units;
892 -- Populate table Elaboration_Context with all units which have prior
893 -- elaboration with respect to the main unit.
895 function Find_Enclosing_Instance (N : Node_Id) return Node_Id;
896 pragma Inline (Find_Enclosing_Instance);
897 -- Find the declaration or body of the nearest expanded instance which
898 -- encloses arbitrary node N. Return Empty if no such instance exists.
900 function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id;
901 pragma Inline (Find_Top_Unit);
902 -- Return the top unit which contains arbitrary node or entity N. The unit
903 -- is obtained by logically unwinding instantiations and subunits when N
904 -- resides within one.
906 function Find_Unit_Entity (N : Node_Id) return Entity_Id;
907 pragma Inline (Find_Unit_Entity);
908 -- Return the entity of unit N
910 function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id;
911 pragma Inline (First_Formal_Type);
912 -- Return the type of subprogram Subp_Id's first formal parameter. If the
913 -- subprogram lacks formal parameters, return Empty.
915 function Has_Body (Pack_Decl : Node_Id) return Boolean;
916 -- Determine whether package declaration Pack_Decl has a corresponding body
917 -- or would eventually have one.
919 function Has_Prior_Elaboration
920 (Unit_Id : Entity_Id;
921 Context_OK : Boolean := False;
922 Elab_Body_OK : Boolean := False;
923 Same_Unit_OK : Boolean := False) return Boolean;
924 pragma Inline (Has_Prior_Elaboration);
925 -- Determine whether unit Unit_Id is elaborated prior to the main unit.
926 -- If flag Context_OK is set, the routine considers the following case
927 -- as valid prior elaboration:
929 -- * Unit_Id is in the elaboration context of the main unit
931 -- If flag Elab_Body_OK is set, the routine considers the following case
932 -- as valid prior elaboration:
934 -- * Unit_Id has pragma Elaborate_Body and is not the main unit
936 -- If flag Same_Unit_OK is set, the routine considers the following cases
937 -- as valid prior elaboration:
939 -- * Unit_Id is the main unit
941 -- * Unit_Id denotes the spec of the main unit body
943 function In_External_Instance
944 (N : Node_Id;
945 Target_Decl : Node_Id) return Boolean;
946 pragma Inline (In_External_Instance);
947 -- Determine whether a target desctibed by its declaration Target_Decl
948 -- resides in a package instance which is external to scenario N.
950 function In_Main_Context (N : Node_Id) return Boolean;
951 pragma Inline (In_Main_Context);
952 -- Determine whether arbitrary node N appears within the main compilation
953 -- unit.
955 function In_Same_Context
956 (N1 : Node_Id;
957 N2 : Node_Id;
958 Nested_OK : Boolean := False) return Boolean;
959 -- Determine whether two arbitrary nodes N1 and N2 appear within the same
960 -- context ignoring enclosing library levels. Nested_OK should be set when
961 -- the context of N1 can enclose that of N2.
963 procedure Info_Call
964 (Call : Node_Id;
965 Target_Id : Entity_Id;
966 Info_Msg : Boolean;
967 In_SPARK : Boolean);
968 -- Output information concerning call Call which invokes target Target_Id.
969 -- If flag Info_Msg is set, the routine emits an information message,
970 -- otherwise it emits an error. If flag In_SPARK is set, then the string
971 -- " in SPARK" is added to the end of the message.
973 procedure Info_Instantiation
974 (Inst : Node_Id;
975 Gen_Id : Entity_Id;
976 Info_Msg : Boolean;
977 In_SPARK : Boolean);
978 pragma Inline (Info_Instantiation);
979 -- Output information concerning instantiation Inst which instantiates
980 -- generic unit Gen_Id. If flag Info_Msg is set, the routine emits an
981 -- information message, otherwise it emits an error. If flag In_SPARK
982 -- is set, then string " in SPARK" is added to the end of the message.
984 procedure Info_Variable_Reference
985 (Ref : Node_Id;
986 Var_Id : Entity_Id;
987 Info_Msg : Boolean;
988 In_SPARK : Boolean);
989 pragma Inline (Info_Variable_Reference);
990 -- Output information concerning reference Ref which mentions variable
991 -- Var_Id. If flag Info_Msg is set, the routine emits an information
992 -- message, otherwise it emits an error. If flag In_SPARK is set, then
993 -- string " in SPARK" is added to the end of the message.
995 function Insertion_Node (N : Node_Id; Ins_Nod : Node_Id) return Node_Id;
996 pragma Inline (Insertion_Node);
997 -- Obtain the proper insertion node of an ABE check or failure for scenario
998 -- N and candidate insertion node Ins_Nod.
1000 procedure Install_ABE_Check
1001 (N : Node_Id;
1002 Id : Entity_Id;
1003 Ins_Nod : Node_Id);
1004 -- Insert a run-time ABE check for elaboration scenario N which verifies
1005 -- whether arbitrary entity Id is elaborated. The check in inserted prior
1006 -- to node Ins_Nod.
1008 procedure Install_ABE_Check
1009 (N : Node_Id;
1010 Target_Id : Entity_Id;
1011 Target_Decl : Node_Id;
1012 Target_Body : Node_Id;
1013 Ins_Nod : Node_Id);
1014 -- Insert a run-time ABE check for elaboration scenario N which verifies
1015 -- whether target Target_Id with initial declaration Target_Decl and body
1016 -- Target_Body is elaborated. The check is inserted prior to node Ins_Nod.
1018 procedure Install_ABE_Failure (N : Node_Id; Ins_Nod : Node_Id);
1019 -- Insert a Program_Error concerning a guaranteed ABE for elaboration
1020 -- scenario N. The failure is inserted prior to node Node_Id.
1022 function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean;
1023 pragma Inline (Is_Accept_Alternative_Proc);
1024 -- Determine whether arbitrary entity Id denotes an internally generated
1025 -- procedure which encapsulates the statements of an accept alternative.
1027 function Is_Activation_Proc (Id : Entity_Id) return Boolean;
1028 pragma Inline (Is_Activation_Proc);
1029 -- Determine whether arbitrary entity Id denotes a runtime procedure in
1030 -- charge with activating tasks.
1032 function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean;
1033 pragma Inline (Is_Ada_Semantic_Target);
1034 -- Determine whether arbitrary entity Id nodes a source or internally
1035 -- generated subprogram which emulates Ada semantics.
1037 function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean;
1038 pragma Inline (Is_Bodiless_Subprogram);
1039 -- Determine whether subprogram Subp_Id will never have a body
1041 function Is_Controlled_Proc
1042 (Subp_Id : Entity_Id;
1043 Subp_Nam : Name_Id) return Boolean;
1044 pragma Inline (Is_Controlled_Proc);
1045 -- Determine whether subprogram Subp_Id denotes controlled type primitives
1046 -- Adjust, Finalize, or Initialize as denoted by name Subp_Nam.
1048 function Is_Default_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
1049 pragma Inline (Is_Default_Initial_Condition_Proc);
1050 -- Determine whether arbitrary entity Id denotes internally generated
1051 -- routine Default_Initial_Condition.
1053 function Is_Finalizer_Proc (Id : Entity_Id) return Boolean;
1054 pragma Inline (Is_Finalizer_Proc);
1055 -- Determine whether arbitrary entity Id denotes internally generated
1056 -- routine _Finalizer.
1058 function Is_Guaranteed_ABE
1059 (N : Node_Id;
1060 Target_Decl : Node_Id;
1061 Target_Body : Node_Id) return Boolean;
1062 pragma Inline (Is_Guaranteed_ABE);
1063 -- Determine whether scenario N with a target described by its initial
1064 -- declaration Target_Decl and body Target_Decl results in a guaranteed
1065 -- ABE.
1067 function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
1068 pragma Inline (Is_Initial_Condition_Proc);
1069 -- Determine whether arbitrary entity Id denotes internally generated
1070 -- routine Initial_Condition.
1072 function Is_Initialized (Obj_Decl : Node_Id) return Boolean;
1073 pragma Inline (Is_Initialized);
1074 -- Determine whether object declaration Obj_Decl is initialized
1076 function Is_Invariant_Proc (Id : Entity_Id) return Boolean;
1077 pragma Inline (Is_Invariant_Proc);
1078 -- Determine whether arbitrary entity Id denotes an invariant procedure
1080 function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean;
1081 pragma Inline (Is_Non_Library_Level_Encapsulator);
1082 -- Determine whether arbitrary node N is a non-library encapsulator
1084 function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean;
1085 pragma Inline (Is_Partial_Invariant_Proc);
1086 -- Determine whether arbitrary entity Id denotes a partial invariant
1087 -- procedure.
1089 function Is_Postconditions_Proc (Id : Entity_Id) return Boolean;
1090 pragma Inline (Is_Postconditions_Proc);
1091 -- Determine whether arbitrary entity Id denotes internally generated
1092 -- routine _Postconditions.
1094 function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean;
1095 pragma Inline (Is_Preelaborated_Unit);
1096 -- Determine whether arbitrary entity Id denotes a unit which is subject to
1097 -- one of the following pragmas:
1099 -- * Preelaborable
1100 -- * Pure
1101 -- * Remote_Call_Interface
1102 -- * Remote_Types
1103 -- * Shared_Passive
1105 function Is_Protected_Entry (Id : Entity_Id) return Boolean;
1106 pragma Inline (Is_Protected_Entry);
1107 -- Determine whether arbitrary entity Id denotes a protected entry
1109 function Is_Protected_Subp (Id : Entity_Id) return Boolean;
1110 pragma Inline (Is_Protected_Subp);
1111 -- Determine whether entity Id denotes a protected subprogram
1113 function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean;
1114 pragma Inline (Is_Protected_Body_Subp);
1115 -- Determine whether entity Id denotes the protected or unprotected version
1116 -- of a protected subprogram.
1118 function Is_Recorded_Top_Level_Scenario (N : Node_Id) return Boolean;
1119 pragma Inline (Is_Recorded_Top_Level_Scenario);
1120 -- Determine whether arbitrary node is a recorded top-level scenario which
1121 -- appears in table Top_Level_Scenarios.
1123 function Is_Safe_Activation
1124 (Call : Node_Id;
1125 Task_Decl : Node_Id) return Boolean;
1126 pragma Inline (Is_Safe_Activation);
1127 -- Determine whether call Call which activates a task object described by
1128 -- declaration Task_Decl is always ABE-safe.
1130 function Is_Safe_Call
1131 (Call : Node_Id;
1132 Target_Attrs : Target_Attributes) return Boolean;
1133 pragma Inline (Is_Safe_Call);
1134 -- Determine whether call Call which invokes a target described by
1135 -- attributes Target_Attrs is always ABE-safe.
1137 function Is_Safe_Instantiation
1138 (Inst : Node_Id;
1139 Gen_Attrs : Target_Attributes) return Boolean;
1140 pragma Inline (Is_Safe_Instantiation);
1141 -- Determine whether instance Inst which instantiates a generic unit
1142 -- described by attributes Gen_Attrs is always ABE-safe.
1144 function Is_Same_Unit
1145 (Unit_1 : Entity_Id;
1146 Unit_2 : Entity_Id) return Boolean;
1147 pragma Inline (Is_Same_Unit);
1148 -- Determine whether entities Unit_1 and Unit_2 denote the same unit
1150 function Is_Scenario (N : Node_Id) return Boolean;
1151 pragma Inline (Is_Scenario);
1152 -- Determine whether attribute node N denotes a scenario. The scenario may
1153 -- not necessarily be eligible for ABE processing.
1155 function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean;
1156 pragma Inline (Is_SPARK_Semantic_Target);
1157 -- Determine whether arbitrary entity Id nodes a source or internally
1158 -- generated subprogram which emulates SPARK semantics.
1160 function Is_Suitable_Access (N : Node_Id) return Boolean;
1161 pragma Inline (Is_Suitable_Access);
1162 -- Determine whether arbitrary node N denotes a suitable attribute for ABE
1163 -- processing.
1165 function Is_Suitable_Call (N : Node_Id) return Boolean;
1166 pragma Inline (Is_Suitable_Call);
1167 -- Determine whether arbitrary node N denotes a suitable call for ABE
1168 -- processing.
1170 function Is_Suitable_Instantiation (N : Node_Id) return Boolean;
1171 pragma Inline (Is_Suitable_Instantiation);
1172 -- Determine whether arbitrary node N is a suitable instantiation for ABE
1173 -- processing.
1175 function Is_Suitable_Scenario (N : Node_Id) return Boolean;
1176 pragma Inline (Is_Suitable_Scenario);
1177 -- Determine whether arbitrary node N is a suitable scenario for ABE
1178 -- processing.
1180 function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean;
1181 pragma Inline (Is_Suitable_Variable_Assignment);
1182 -- Determine whether arbitrary node N denotes a suitable assignment for ABE
1183 -- processing.
1185 function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean;
1186 pragma Inline (Is_Suitable_Variable_Reference);
1187 -- Determine whether arbitrary node N is a suitable variable reference for
1188 -- ABE processing.
1190 function Is_Task_Entry (Id : Entity_Id) return Boolean;
1191 pragma Inline (Is_Task_Entry);
1192 -- Determine whether arbitrary entity Id denotes a task entry
1194 function Is_Up_Level_Target (Target_Decl : Node_Id) return Boolean;
1195 pragma Inline (Is_Up_Level_Target);
1196 -- Determine whether the current root resides at the declaration level. If
1197 -- this is the case, determine whether a target described by declaration
1198 -- Target_Decl is within a context which encloses the current root or is in
1199 -- a different unit.
1201 procedure Meet_Elaboration_Requirement
1202 (N : Node_Id;
1203 Target_Id : Entity_Id;
1204 Req_Nam : Name_Id);
1205 -- Determine whether elaboration requirement Req_Nam for scenario N with
1206 -- target Target_Id is met by the context of the main unit using the SPARK
1207 -- rules. Req_Nam must denote either Elaborate or Elaborate_All. Emit an
1208 -- error if this is not the case.
1210 function Non_Private_View (Typ : Entity_Id) return Entity_Id;
1211 pragma Inline (Non_Private_View);
1212 -- Return the full view of private type Typ if available, otherwise return
1213 -- type Typ.
1215 procedure Output_Active_Scenarios (Error_Nod : Node_Id);
1216 -- Output the contents of the active scenario stack from earliest to latest
1217 -- to supplement an earlier error emitted for node Error_Nod.
1219 procedure Pop_Active_Scenario (N : Node_Id);
1220 pragma Inline (Pop_Active_Scenario);
1221 -- Pop the top of the scenario stack. A check is made to ensure that the
1222 -- scenario being removed is the same as N.
1224 procedure Process_Access
1225 (Attr : Node_Id;
1226 In_Partial_Fin : Boolean;
1227 In_Task_Body : Boolean);
1228 -- Perform ABE checks and diagnostics for 'Access to entry, operator, or
1229 -- subprogram denoted by Attr. Flag In_Partial_Fin shoud be set when the
1230 -- processing is initiated by a partial finalization routine. Flag
1231 -- In_Task_Body should be set when the processing is initiated from a task
1232 -- body.
1234 generic
1235 with procedure Process_Single_Activation
1236 (Call : Node_Id;
1237 Call_Attrs : Call_Attributes;
1238 Obj_Id : Entity_Id;
1239 Task_Attrs : Task_Attributes;
1240 In_Partial_Fin : Boolean;
1241 In_Task_Body : Boolean);
1242 -- Perform ABE checks and diagnostics for task activation call Call
1243 -- which activates task Obj_Id. Call_Attrs are the attributes of the
1244 -- activation call. Task_Attrs are the attributes of the task type.
1245 -- Flag In_Partial_Fin shoud be set when the processing is initiated
1246 -- by a partial finalization routine. Flag In_Task_Body should be set
1247 -- when the processing is initiated from a task body.
1249 procedure Process_Activation_Call
1250 (Call : Node_Id;
1251 Call_Attrs : Call_Attributes;
1252 In_Partial_Fin : Boolean;
1253 In_Task_Body : Boolean);
1254 -- Perform ABE checks and diagnostics for activation call Call by invoking
1255 -- routine Process_Single_Activation on each task object being activated.
1256 -- Call_Attrs are the attributes of the activation call. In_Partial_Fin
1257 -- shoud be set when the processing is initiated by a partial finalization
1258 -- routine. Flag In_Task_Body should be set when the processing is started
1259 -- from a task body.
1261 procedure Process_Activation_Conditional_ABE_Impl
1262 (Call : Node_Id;
1263 Call_Attrs : Call_Attributes;
1264 Obj_Id : Entity_Id;
1265 Task_Attrs : Task_Attributes;
1266 In_Partial_Fin : Boolean;
1267 In_Task_Body : Boolean);
1268 -- Perform common conditional ABE checks and diagnostics for call Call
1269 -- which activates task Obj_Id ignoring the Ada or SPARK rules. CAll_Attrs
1270 -- are the attributes of the activation call. Task_Attrs are the attributes
1271 -- of the task type. Flag In_Partial_Fin shoud be set when the processing
1272 -- is initiated by a partial finalization routine. Flag In_Task_Body should
1273 -- be set when the processing is initiated from a task body.
1275 procedure Process_Activation_Guaranteed_ABE_Impl
1276 (Call : Node_Id;
1277 Call_Attrs : Call_Attributes;
1278 Obj_Id : Entity_Id;
1279 Task_Attrs : Task_Attributes;
1280 In_Partial_Fin : Boolean;
1281 In_Task_Body : Boolean);
1282 -- Perform common guaranteed ABE checks and diagnostics for call Call which
1283 -- activates task Obj_Id ignoring the Ada or SPARK rules. Task_Attrs are
1284 -- the attributes of the task type. The following parameters are provided
1285 -- for compatibility and are unused.
1287 -- Call_Attrs
1288 -- In_Partial_Fin
1289 -- In_Task_Body
1291 procedure Process_Call
1292 (Call : Node_Id;
1293 Call_Attrs : Call_Attributes;
1294 Target_Id : Entity_Id;
1295 In_Partial_Fin : Boolean;
1296 In_Task_Body : Boolean);
1297 -- Top-level dispatcher for processing of calls. Perform ABE checks and
1298 -- diagnostics for call Call which invokes target Target_Id. Call_Attrs
1299 -- are the attributes of the call. Flag In_Partial_Fin shoud be set when
1300 -- the processing is initiated by a partial finalization routine. Flag
1301 -- In_Task_Body should be set when the processing is started from a task
1302 -- body.
1304 procedure Process_Call_Ada
1305 (Call : Node_Id;
1306 Call_Attrs : Call_Attributes;
1307 Target_Id : Entity_Id;
1308 Target_Attrs : Target_Attributes;
1309 In_Partial_Fin : Boolean;
1310 In_Task_Body : Boolean);
1311 -- Perform ABE checks and diagnostics for call Call which invokes target
1312 -- Target_Id using the Ada rules. Call_Attrs are the attributes of the
1313 -- call. Target_Attrs are attributes of the target. Flag In_Partial_Fin
1314 -- shoud be set when the processing is initiated by a partial finalization
1315 -- routine. Flag In_Task_Body should be set when the processing is started
1316 -- from a task body.
1318 procedure Process_Call_Conditional_ABE
1319 (Call : Node_Id;
1320 Call_Attrs : Call_Attributes;
1321 Target_Id : Entity_Id;
1322 Target_Attrs : Target_Attributes;
1323 In_Partial_Fin : Boolean);
1324 -- Perform common conditional ABE checks and diagnostics for call Call that
1325 -- invokes target Target_Id ignoring the Ada or SPARK rules. Call_Attrs are
1326 -- the attributes of the call. Target_Attrs are attributes of the target.
1327 -- Flag In_Partial_Fin shoud be set when the processing is initiated by a
1328 -- partial finalization routine.
1330 procedure Process_Call_Guaranteed_ABE
1331 (Call : Node_Id;
1332 Call_Attrs : Call_Attributes;
1333 Target_Id : Entity_Id);
1334 -- Perform common guaranteed ABE checks and diagnostics for call Call which
1335 -- invokes target Target_Id ignoring the Ada or SPARK rules. Call_Attrs are
1336 -- the attributes of the call.
1338 procedure Process_Call_SPARK
1339 (Call : Node_Id;
1340 Call_Attrs : Call_Attributes;
1341 Target_Id : Entity_Id;
1342 Target_Attrs : Target_Attributes;
1343 In_Partial_Fin : Boolean);
1344 -- Perform ABE checks and diagnostics for call Call which invokes target
1345 -- Target_Id using the SPARK rules. Call_Attrs are the attributes of the
1346 -- call. Target_Attrs are attributes of the target. Flag In_Partial_Fin
1347 -- shoud be set when the processing is initiated by a partial finalization
1348 -- routine.
1350 procedure Process_Guaranteed_ABE (N : Node_Id);
1351 -- Top-level dispatcher for processing of scenarios which result in a
1352 -- guaranteed ABE.
1354 procedure Process_Instantiation
1355 (Exp_Inst : Node_Id;
1356 In_Partial_Fin : Boolean;
1357 In_Task_Body : Boolean);
1358 -- Top-level dispatcher for processing of instantiations. Perform ABE
1359 -- checks and diagnostics for expanded instantiation Exp_Inst. Flag
1360 -- In_Partial_Fin shoud be set when the processing is initiated by a
1361 -- partial finalization routine. Flag In_Task_Body should be set when
1362 -- the processing is initiated from a task body.
1364 procedure Process_Instantiation_Ada
1365 (Exp_Inst : Node_Id;
1366 Inst : Node_Id;
1367 Inst_Attrs : Instantiation_Attributes;
1368 Gen_Id : Entity_Id;
1369 Gen_Attrs : Target_Attributes;
1370 In_Partial_Fin : Boolean;
1371 In_Task_Body : Boolean);
1372 -- Perform ABE checks and diagnostics for expanded instantiation Exp_Inst
1373 -- of generic Gen_Id using the Ada rules. Inst is the instantiation node.
1374 -- Inst_Attrs are the attributes of the instance. Gen_Attrs denotes the
1375 -- attributes of the generic. Flag In_Partial_Fin shoud be set when the
1376 -- processing is initiated by a partial finalization routine. In_Task_Body
1377 -- should be set when the processing is initiated from a task body.
1379 procedure Process_Instantiation_Conditional_ABE
1380 (Exp_Inst : Node_Id;
1381 Inst : Node_Id;
1382 Inst_Attrs : Instantiation_Attributes;
1383 Gen_Id : Entity_Id;
1384 Gen_Attrs : Target_Attributes;
1385 In_Partial_Fin : Boolean);
1386 -- Perform common conditional ABE checks and diagnostics for expanded
1387 -- instantiation Exp_Inst of generic Gen_Id ignoring the Ada or SPARK
1388 -- rules. Inst is the instantiation node. Inst_Attrs are the attributes
1389 -- of the instance. Gen_Attrs are the attributes of the generic. Flag
1390 -- In_Partial_Fin shoud be set when the processing is initiated by a
1391 -- partial finalization routine.
1393 procedure Process_Instantiation_Guaranteed_ABE (Exp_Inst : Node_Id);
1394 -- Perform common guaranteed ABE checks and diagnostics for expanded
1395 -- instantiation Exp_Inst of generic Gen_Id ignoring the Ada or SPARK
1396 -- rules.
1398 procedure Process_Instantiation_SPARK
1399 (Exp_Inst : Node_Id;
1400 Inst : Node_Id;
1401 Inst_Attrs : Instantiation_Attributes;
1402 Gen_Id : Entity_Id;
1403 Gen_Attrs : Target_Attributes;
1404 In_Partial_Fin : Boolean);
1405 -- Perform ABE checks and diagnostics for expanded instantiation Exp_Inst
1406 -- of generic Gen_Id using the SPARK rules. Inst is the instantiation node.
1407 -- Inst_Attrs are the attributes of the instance. Gen_Attrs denotes the
1408 -- attributes of the generic. Flag In_Partial_Fin shoud be set when the
1409 -- processing is initiated by a partial finalization routine.
1411 procedure Process_Scenario
1412 (N : Node_Id;
1413 In_Partial_Fin : Boolean := False;
1414 In_Task_Body : Boolean := False);
1415 -- Top-level dispatcher for processing of various elaboration scenarios.
1416 -- Perform ABE checks and diagnostics for scenario N. Flag In_Partial_Fin
1417 -- shoud be set when the processing is initiated by a partial finalization
1418 -- routine. Flag In_Task_Body should be set when the processing is started
1419 -- from a task body.
1421 procedure Process_Variable_Assignment (Asmt : Node_Id);
1422 -- Top-level dispatcher for processing of variable assignments. Perform ABE
1423 -- checks and diagnostics for assignment statement Asmt.
1425 procedure Process_Variable_Assignment_Ada
1426 (Asmt : Node_Id;
1427 Var_Id : Entity_Id);
1428 -- Perform ABE checks and diagnostics for assignment statement Asmt that
1429 -- updates the value of variable Var_Id using the Ada rules.
1431 procedure Process_Variable_Assignment_SPARK
1432 (Asmt : Node_Id;
1433 Var_Id : Entity_Id);
1434 -- Perform ABE checks and diagnostics for assignment statement Asmt that
1435 -- updates the value of variable Var_Id using the SPARK rules.
1437 procedure Process_Variable_Reference (Ref : Node_Id);
1438 -- Top-level dispatcher for processing of variable references. Perform ABE
1439 -- checks and diagnostics for variable reference Ref.
1441 procedure Process_Variable_Reference_Read
1442 (Ref : Node_Id;
1443 Var_Id : Entity_Id;
1444 Attrs : Variable_Attributes);
1445 -- Perform ABE checks and diagnostics for reference Ref described by its
1446 -- attributes Attrs, that reads variable Var_Id.
1448 procedure Push_Active_Scenario (N : Node_Id);
1449 pragma Inline (Push_Active_Scenario);
1450 -- Push scenario N on top of the scenario stack
1452 function Root_Scenario return Node_Id;
1453 pragma Inline (Root_Scenario);
1454 -- Return the top-level scenario which started a recursive search for other
1455 -- scenarios. It is assumed that there is a valid top-level scenario on the
1456 -- active scenario stack.
1458 procedure Set_Is_Recorded_Top_Level_Scenario
1459 (N : Node_Id;
1460 Val : Boolean := True);
1461 pragma Inline (Set_Is_Recorded_Top_Level_Scenario);
1462 -- Mark scenario N as being recorded in table Top_Level_Scenarios
1464 function Static_Elaboration_Checks return Boolean;
1465 pragma Inline (Static_Elaboration_Checks);
1466 -- Determine whether the static model is in effect
1468 procedure Traverse_Body
1469 (N : Node_Id;
1470 In_Partial_Fin : Boolean;
1471 In_Task_Body : Boolean);
1472 -- Inspect the declarations and statements of subprogram body N for
1473 -- suitable elaboration scenarios and process them. Flag In_Partial_Fin
1474 -- shoud be set when the processing is initiated by a partial finalization
1475 -- routine. Flag In_Task_Body should be set when the traversal is initiated
1476 -- from a task body.
1478 procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id);
1479 pragma Inline (Update_Elaboration_Scenario);
1480 -- Update all relevant internal data structures when scenario Old_N is
1481 -- transformed into scenario New_N by Atree.Rewrite.
1483 -----------------------
1484 -- Build_Call_Marker --
1485 -----------------------
1487 procedure Build_Call_Marker (N : Node_Id) is
1488 function In_External_Context
1489 (Call : Node_Id;
1490 Target_Id : Entity_Id) return Boolean;
1491 pragma Inline (In_External_Context);
1492 -- Determine whether target Target_Id is external to call N which must
1493 -- reside within an instance.
1495 function In_Premature_Context (Call : Node_Id) return Boolean;
1496 -- Determine whether call Call appears within a premature context
1498 function Is_Bridge_Target (Id : Entity_Id) return Boolean;
1499 pragma Inline (Is_Bridge_Target);
1500 -- Determine whether arbitrary entity Id denotes a bridge target
1502 function Is_Default_Expression (Call : Node_Id) return Boolean;
1503 pragma Inline (Is_Default_Expression);
1504 -- Determine whether call Call acts as the expression of a defaulted
1505 -- parameter within a source call.
1507 function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean;
1508 pragma Inline (Is_Generic_Formal_Subp);
1509 -- Determine whether subprogram Subp_Id denotes a generic formal
1510 -- subprogram which appears in the "prologue" of an instantiation.
1512 -------------------------
1513 -- In_External_Context --
1514 -------------------------
1516 function In_External_Context
1517 (Call : Node_Id;
1518 Target_Id : Entity_Id) return Boolean
1520 Target_Decl : constant Node_Id := Unit_Declaration_Node (Target_Id);
1522 Inst : Node_Id;
1523 Inst_Body : Node_Id;
1524 Inst_Decl : Node_Id;
1526 begin
1527 -- Performance note: parent traversal
1529 Inst := Find_Enclosing_Instance (Call);
1531 -- The call appears within an instance
1533 if Present (Inst) then
1535 -- The call comes from the main unit and the target does not
1537 if In_Extended_Main_Code_Unit (Call)
1538 and then not In_Extended_Main_Code_Unit (Target_Decl)
1539 then
1540 return True;
1542 -- Otherwise the target declaration must not appear within the
1543 -- instance spec or body.
1545 else
1546 Extract_Instance_Attributes
1547 (Exp_Inst => Inst,
1548 Inst_Decl => Inst_Decl,
1549 Inst_Body => Inst_Body);
1551 -- Performance note: parent traversal
1553 return not In_Subtree
1554 (N => Target_Decl,
1555 Root1 => Inst_Decl,
1556 Root2 => Inst_Body);
1557 end if;
1558 end if;
1560 return False;
1561 end In_External_Context;
1563 --------------------------
1564 -- In_Premature_Context --
1565 --------------------------
1567 function In_Premature_Context (Call : Node_Id) return Boolean is
1568 Par : Node_Id;
1570 begin
1571 -- Climb the parent chain looking for premature contexts
1573 Par := Parent (Call);
1574 while Present (Par) loop
1576 -- Aspect specifications and generic associations are premature
1577 -- contexts because nested calls has not been relocated to their
1578 -- final context.
1580 if Nkind_In (Par, N_Aspect_Specification,
1581 N_Generic_Association)
1582 then
1583 return True;
1585 -- Prevent the search from going too far
1587 elsif Is_Body_Or_Package_Declaration (Par) then
1588 exit;
1589 end if;
1591 Par := Parent (Par);
1592 end loop;
1594 return False;
1595 end In_Premature_Context;
1597 ----------------------
1598 -- Is_Bridge_Target --
1599 ----------------------
1601 function Is_Bridge_Target (Id : Entity_Id) return Boolean is
1602 begin
1603 return
1604 Is_Accept_Alternative_Proc (Id)
1605 or else Is_Finalizer_Proc (Id)
1606 or else Is_Partial_Invariant_Proc (Id)
1607 or else Is_Postconditions_Proc (Id)
1608 or else Is_TSS (Id, TSS_Deep_Adjust)
1609 or else Is_TSS (Id, TSS_Deep_Finalize)
1610 or else Is_TSS (Id, TSS_Deep_Initialize);
1611 end Is_Bridge_Target;
1613 ---------------------------
1614 -- Is_Default_Expression --
1615 ---------------------------
1617 function Is_Default_Expression (Call : Node_Id) return Boolean is
1618 Outer_Call : constant Node_Id := Parent (Call);
1619 Outer_Nam : Node_Id;
1621 begin
1622 -- To qualify, the node must appear immediately within a source call
1623 -- which invokes a source target.
1625 if Nkind_In (Outer_Call, N_Entry_Call_Statement,
1626 N_Function_Call,
1627 N_Procedure_Call_Statement)
1628 and then Comes_From_Source (Outer_Call)
1629 then
1630 Outer_Nam := Extract_Call_Name (Outer_Call);
1632 return
1633 Is_Entity_Name (Outer_Nam)
1634 and then Present (Entity (Outer_Nam))
1635 and then Is_Subprogram_Or_Entry (Entity (Outer_Nam))
1636 and then Comes_From_Source (Entity (Outer_Nam));
1637 end if;
1639 return False;
1640 end Is_Default_Expression;
1642 ----------------------------
1643 -- Is_Generic_Formal_Subp --
1644 ----------------------------
1646 function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean is
1647 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
1648 Context : constant Node_Id := Parent (Subp_Decl);
1650 begin
1651 -- To qualify, the subprogram must rename a generic actual subprogram
1652 -- where the enclosing context is an instantiation.
1654 return
1655 Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
1656 and then not Comes_From_Source (Subp_Decl)
1657 and then Nkind_In (Context, N_Function_Specification,
1658 N_Package_Specification,
1659 N_Procedure_Specification)
1660 and then Present (Generic_Parent (Context));
1661 end Is_Generic_Formal_Subp;
1663 -- Local variables
1665 Call_Attrs : Call_Attributes;
1666 Call_Nam : Node_Id;
1667 Marker : Node_Id;
1668 Target_Id : Entity_Id;
1670 -- Start of processing for Build_Call_Marker
1672 begin
1673 -- Nothing to do for ASIS. As a result, ABE checks and diagnostics are
1674 -- not performed in this mode.
1676 if ASIS_Mode then
1677 return;
1679 -- Nothing to do when the call is being preanalyzed as the marker will
1680 -- be inserted in the wrong place.
1682 elsif Preanalysis_Active then
1683 return;
1685 -- Nothing to do when the input does not denote a call or a requeue
1687 elsif not Nkind_In (N, N_Entry_Call_Statement,
1688 N_Function_Call,
1689 N_Procedure_Call_Statement,
1690 N_Requeue_Statement)
1691 then
1692 return;
1694 -- Nothing to do when the call is analyzed/resolved too early within an
1695 -- intermediate context.
1697 -- Performance note: parent traversal
1699 elsif In_Premature_Context (N) then
1700 return;
1701 end if;
1703 Call_Nam := Extract_Call_Name (N);
1705 -- Nothing to do when the call is erroneous or left in a bad state
1707 if not (Is_Entity_Name (Call_Nam)
1708 and then Present (Entity (Call_Nam))
1709 and then Is_Subprogram_Or_Entry (Entity (Call_Nam)))
1710 then
1711 return;
1713 -- Nothing to do when the call invokes a generic formal subprogram and
1714 -- switch -gnatd.G (ignore calls through generic formal parameters for
1715 -- elaboration) is in effect. This check must be performed with the
1716 -- direct target of the call to avoid the side effects of mapping
1717 -- actuals to formals using renamings.
1719 elsif Debug_Flag_Dot_GG
1720 and then Is_Generic_Formal_Subp (Entity (Call_Nam))
1721 then
1722 return;
1723 end if;
1725 Extract_Call_Attributes
1726 (Call => N,
1727 Target_Id => Target_Id,
1728 Attrs => Call_Attrs);
1730 -- Nothing to do when the call appears within the expanded spec or
1731 -- body of an instantiated generic, the call does not invoke a generic
1732 -- formal subprogram, the target is external to the instance, and switch
1733 -- -gnatdL (ignore external calls from instances for elaboration) is in
1734 -- effect. This behaviour approximates that of the old ABE mechanism.
1736 if Debug_Flag_LL
1737 and then not Is_Generic_Formal_Subp (Entity (Call_Nam))
1739 -- Performance note: parent traversal
1741 and then In_External_Context
1742 (Call => N,
1743 Target_Id => Target_Id)
1744 then
1745 return;
1747 -- Source calls to source targets are always considered because they
1748 -- reflect the original call graph.
1750 elsif Comes_From_Source (Target_Id) and then Call_Attrs.From_Source then
1751 null;
1753 -- A call to a source function which acts as the default expression in
1754 -- another call requires special detection.
1756 elsif Comes_From_Source (Target_Id)
1757 and then Nkind (N) = N_Function_Call
1758 and then Is_Default_Expression (N)
1759 then
1760 null;
1762 -- The target emulates Ada semantics
1764 elsif Is_Ada_Semantic_Target (Target_Id) then
1765 null;
1767 -- The target acts as a link between scenarios
1769 elsif Is_Bridge_Target (Target_Id) then
1770 null;
1772 -- The target emulates SPARK semantics
1774 elsif Is_SPARK_Semantic_Target (Target_Id) then
1775 null;
1777 -- Otherwise the call is not suitable for ABE processing. This prevents
1778 -- the generation of call markers which will never play a role in ABE
1779 -- diagnostics.
1781 else
1782 return;
1783 end if;
1785 -- At this point it is known that the call will play some role in ABE
1786 -- checks and diagnostics. Create a corresponding call marker in case
1787 -- the original call is heavily transformed by expansion later on.
1789 Marker := Make_Call_Marker (Sloc (N));
1791 -- Inherit the attributes of the original call
1793 Set_Target (Marker, Target_Id);
1794 Set_Is_Elaboration_Checks_OK_Node (Marker, Call_Attrs.Elab_Checks_OK);
1795 Set_Is_Declaration_Level_Node (Marker, Call_Attrs.In_Declarations);
1796 Set_Is_Dispatching_Call (Marker, Call_Attrs.Is_Dispatching);
1797 Set_Is_Ignored_Ghost_Node (Marker, Call_Attrs.Ghost_Mode_Ignore);
1798 Set_Is_Source_Call (Marker, Call_Attrs.From_Source);
1799 Set_Is_SPARK_Mode_On_Node (Marker, Call_Attrs.SPARK_Mode_On);
1801 -- The marker is inserted prior to the original call. This placement has
1802 -- several desirable effects:
1804 -- 1) The marker appears in the same context, in close proximity to
1805 -- the call.
1807 -- <marker>
1808 -- <call>
1810 -- 2) Inserting the marker prior to the call ensures that an ABE check
1811 -- will take effect prior to the call.
1813 -- <ABE check>
1814 -- <marker>
1815 -- <call>
1817 -- 3) The above two properties are preserved even when the call is a
1818 -- function which is subsequently relocated in order to capture its
1819 -- result. Note that if the call is relocated to a new context, the
1820 -- relocated call will receive a marker of its own.
1822 -- <ABE check>
1823 -- <maker>
1824 -- Temp : ... := Func_Call ...;
1825 -- ... Temp ...
1827 -- The insertion must take place even when the call does not occur in
1828 -- the main unit to keep the tree symmetric. This ensures that internal
1829 -- name serialization is consistent in case the call marker causes the
1830 -- tree to transform in some way.
1832 Insert_Action (N, Marker);
1834 -- The marker becomes the "corresponding" scenario for the call. Save
1835 -- the marker for later processing by the ABE phase.
1837 Record_Elaboration_Scenario (Marker);
1838 end Build_Call_Marker;
1840 -------------------------------------
1841 -- Build_Variable_Reference_Marker --
1842 -------------------------------------
1844 procedure Build_Variable_Reference_Marker
1845 (N : Node_Id;
1846 Read : Boolean;
1847 Write : Boolean)
1849 function In_Pragma (Nod : Node_Id) return Boolean;
1850 -- Determine whether arbitrary node Nod appears within a pragma
1852 ---------------
1853 -- In_Pragma --
1854 ---------------
1856 function In_Pragma (Nod : Node_Id) return Boolean is
1857 Par : Node_Id;
1859 begin
1860 Par := Nod;
1861 while Present (Par) loop
1862 if Nkind (Par) = N_Pragma then
1863 return True;
1865 -- Prevent the search from going too far
1867 elsif Is_Body_Or_Package_Declaration (Par) then
1868 exit;
1869 end if;
1871 Par := Parent (Par);
1872 end loop;
1874 return False;
1875 end In_Pragma;
1877 -- Local variables
1879 Marker : Node_Id;
1880 Prag : Node_Id;
1881 Var_Attrs : Variable_Attributes;
1882 Var_Id : Entity_Id;
1884 -- Start of processing for Build_Variable_Reference_Marker
1886 begin
1887 -- Nothing to do for ASIS. As a result, ABE checks and diagnostics are
1888 -- not performed in this mode.
1890 if ASIS_Mode then
1891 return;
1893 -- Nothing to do when the reference is being preanalyzed as the marker
1894 -- will be inserted in the wrong place.
1896 elsif Preanalysis_Active then
1897 return;
1899 -- Nothing to do when the input does not denote a reference
1901 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
1902 return;
1904 -- Nothing to do for internally-generated references
1906 elsif not Comes_From_Source (N) then
1907 return;
1909 -- Nothing to do when the reference is erroneous, left in a bad state,
1910 -- or does not denote a variable.
1912 elsif not (Present (Entity (N))
1913 and then Ekind (Entity (N)) = E_Variable
1914 and then Entity (N) /= Any_Id)
1915 then
1916 return;
1917 end if;
1919 Extract_Variable_Reference_Attributes
1920 (Ref => N,
1921 Var_Id => Var_Id,
1922 Attrs => Var_Attrs);
1924 Prag := SPARK_Pragma (Var_Id);
1926 if Comes_From_Source (Var_Id)
1928 -- Both the variable and the reference must appear in SPARK_Mode On
1929 -- regions because this scenario falls under the SPARK rules.
1931 and then Present (Prag)
1932 and then Get_SPARK_Mode_From_Annotation (Prag) = On
1933 and then Is_SPARK_Mode_On_Node (N)
1935 -- The reference must not be considered when it appears in a pragma.
1936 -- If the pragma has run-time semantics, then the reference will be
1937 -- reconsidered once the pragma is expanded.
1939 -- Performance note: parent traversal
1941 and then not In_Pragma (N)
1942 then
1943 null;
1945 -- Otherwise the reference is not suitable for ABE processing. This
1946 -- prevents the generation of variable markers which will never play
1947 -- a role in ABE diagnostics.
1949 else
1950 return;
1951 end if;
1953 -- At this point it is known that the variable reference will play some
1954 -- role in ABE checks and diagnostics. Create a corresponding variable
1955 -- marker in case the original variable reference is folded or optimized
1956 -- away.
1958 Marker := Make_Variable_Reference_Marker (Sloc (N));
1960 -- Inherit the attributes of the original variable reference
1962 Set_Target (Marker, Var_Id);
1963 Set_Is_Read (Marker, Read);
1964 Set_Is_Write (Marker, Write);
1966 -- The marker is inserted prior to the original variable reference. The
1967 -- insertion must take place even when the reference does not occur in
1968 -- the main unit to keep the tree symmetric. This ensures that internal
1969 -- name serialization is consistent in case the variable marker causes
1970 -- the tree to transform in some way.
1972 Insert_Action (N, Marker);
1974 -- The marker becomes the "corresponding" scenario for the reference.
1975 -- Save the marker for later processing for the ABE phase.
1977 Record_Elaboration_Scenario (Marker);
1978 end Build_Variable_Reference_Marker;
1980 ---------------------------------
1981 -- Check_Elaboration_Scenarios --
1982 ---------------------------------
1984 procedure Check_Elaboration_Scenarios is
1985 begin
1986 -- Nothing to do for ASIS. As a result, no ABE checks and diagnostics
1987 -- are performed in this mode.
1989 if ASIS_Mode then
1990 return;
1991 end if;
1993 -- Examine the context of the main unit and record all units with prior
1994 -- elaboration with respect to it.
1996 Find_Elaborated_Units;
1998 -- Examine each top-level scenario saved during the Recording phase and
1999 -- perform various actions depending on the elaboration model in effect.
2001 for Index in Top_Level_Scenarios.First .. Top_Level_Scenarios.Last loop
2003 -- Clear the table of visited scenario bodies for each new top-level
2004 -- scenario.
2006 Visited_Bodies.Reset;
2008 Process_Scenario (Top_Level_Scenarios.Table (Index));
2009 end loop;
2010 end Check_Elaboration_Scenarios;
2012 ------------------------------
2013 -- Check_Preelaborated_Call --
2014 ------------------------------
2016 procedure Check_Preelaborated_Call (Call : Node_Id) is
2017 function In_Preelaborated_Context (N : Node_Id) return Boolean;
2018 -- Determine whether arbitrary node appears in a preelaborated context
2020 ------------------------------
2021 -- In_Preelaborated_Context --
2022 ------------------------------
2024 function In_Preelaborated_Context (N : Node_Id) return Boolean is
2025 Body_Id : constant Entity_Id := Find_Code_Unit (N);
2026 Spec_Id : constant Entity_Id := Unique_Entity (Body_Id);
2028 begin
2029 -- The node appears within a package body whose corresponding spec is
2030 -- subject to pragma Remote_Call_Interface or Remote_Types. This does
2031 -- not result in a preelaborated context because the package body may
2032 -- be on another machine.
2034 if Ekind (Body_Id) = E_Package_Body
2035 and then Ekind_In (Spec_Id, E_Generic_Package, E_Package)
2036 and then (Is_Remote_Call_Interface (Spec_Id)
2037 or else Is_Remote_Types (Spec_Id))
2038 then
2039 return False;
2041 -- Otherwise the node appears within a preelaborated context when the
2042 -- associated unit is preelaborated.
2044 else
2045 return Is_Preelaborated_Unit (Spec_Id);
2046 end if;
2047 end In_Preelaborated_Context;
2049 -- Local variables
2051 Call_Attrs : Call_Attributes;
2052 Level : Enclosing_Level_Kind;
2053 Target_Id : Entity_Id;
2055 -- Start of processing for Check_Preelaborated_Call
2057 begin
2058 Extract_Call_Attributes
2059 (Call => Call,
2060 Target_Id => Target_Id,
2061 Attrs => Call_Attrs);
2063 -- Nothing to do when the call is internally generated because it is
2064 -- assumed that it will never violate preelaboration.
2066 if not Call_Attrs.From_Source then
2067 return;
2068 end if;
2070 -- Performance note: parent traversal
2072 Level := Find_Enclosing_Level (Call);
2074 -- Library-level calls are always considered because they are part of
2075 -- the associated unit's elaboration actions.
2077 if Level in Library_Level then
2078 null;
2080 -- Calls at the library level of a generic package body must be checked
2081 -- because they would render an instantiation illegal if the template is
2082 -- marked as preelaborated. Note that this does not apply to calls at
2083 -- the library level of a generic package spec.
2085 elsif Level = Generic_Package_Body then
2086 null;
2088 -- Otherwise the call does not appear at the proper level and must not
2089 -- be considered for this check.
2091 else
2092 return;
2093 end if;
2095 -- The call appears within a preelaborated unit. Emit a warning only for
2096 -- internal uses, otherwise this is an error.
2098 if In_Preelaborated_Context (Call) then
2099 Error_Msg_Warn := GNAT_Mode;
2100 Error_Msg_N
2101 ("<<non-static call not allowed in preelaborated unit", Call);
2102 end if;
2103 end Check_Preelaborated_Call;
2105 ----------------------
2106 -- Compilation_Unit --
2107 ----------------------
2109 function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id is
2110 Comp_Unit : Node_Id;
2112 begin
2113 Comp_Unit := Parent (Unit_Id);
2115 -- Handle the case where a concurrent subunit is rewritten as a null
2116 -- statement due to expansion activities.
2118 if Nkind (Comp_Unit) = N_Null_Statement
2119 and then Nkind_In (Original_Node (Comp_Unit), N_Protected_Body,
2120 N_Task_Body)
2121 then
2122 Comp_Unit := Parent (Comp_Unit);
2123 pragma Assert (Nkind (Comp_Unit) = N_Subunit);
2125 -- Otherwise use the declaration node of the unit
2127 else
2128 Comp_Unit := Parent (Unit_Declaration_Node (Unit_Id));
2129 end if;
2131 -- Handle the case where a subprogram instantiation which acts as a
2132 -- compilation unit is expanded into an anonymous package that wraps
2133 -- the instantiated subprogram.
2135 if Nkind (Comp_Unit) = N_Package_Specification
2136 and then Nkind_In (Original_Node (Parent (Comp_Unit)),
2137 N_Function_Instantiation,
2138 N_Procedure_Instantiation)
2139 then
2140 Comp_Unit := Parent (Parent (Comp_Unit));
2142 -- Handle the case where the compilation unit is a subunit
2144 elsif Nkind (Comp_Unit) = N_Subunit then
2145 Comp_Unit := Parent (Comp_Unit);
2146 end if;
2148 pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
2150 return Comp_Unit;
2151 end Compilation_Unit;
2153 -----------------
2154 -- Elab_Msg_NE --
2155 -----------------
2157 procedure Elab_Msg_NE
2158 (Msg : String;
2159 N : Node_Id;
2160 Id : Entity_Id;
2161 Info_Msg : Boolean;
2162 In_SPARK : Boolean)
2164 function Prefix return String;
2165 -- Obtain the prefix of the message
2167 function Suffix return String;
2168 -- Obtain the suffix of the message
2170 ------------
2171 -- Prefix --
2172 ------------
2174 function Prefix return String is
2175 begin
2176 if Info_Msg then
2177 return "info: ";
2178 else
2179 return "";
2180 end if;
2181 end Prefix;
2183 ------------
2184 -- Suffix --
2185 ------------
2187 function Suffix return String is
2188 begin
2189 if In_SPARK then
2190 return " in SPARK";
2191 else
2192 return "";
2193 end if;
2194 end Suffix;
2196 -- Start of processing for Elab_Msg_NE
2198 begin
2199 Error_Msg_NE (Prefix & Msg & Suffix, N, Id);
2200 end Elab_Msg_NE;
2202 ------------------------------
2203 -- Elaboration_Context_Hash --
2204 ------------------------------
2206 function Elaboration_Context_Hash
2207 (Key : Entity_Id) return Elaboration_Context_Index
2209 begin
2210 return Elaboration_Context_Index (Key mod Elaboration_Context_Max);
2211 end Elaboration_Context_Hash;
2213 ------------------------------
2214 -- Ensure_Prior_Elaboration --
2215 ------------------------------
2217 procedure Ensure_Prior_Elaboration
2218 (N : Node_Id;
2219 Unit_Id : Entity_Id;
2220 In_Partial_Fin : Boolean;
2221 In_Task_Body : Boolean)
2223 Prag_Nam : Name_Id;
2225 begin
2226 -- Instantiating an external generic unit requires an implicit Elaborate
2227 -- because Elaborate_All is too strong and could introduce non-existent
2228 -- elaboration cycles.
2230 -- package External is
2231 -- function Func ...;
2232 -- end External;
2234 -- with External;
2235 -- generic
2236 -- package Gen is
2237 -- X : ... := External.Func;
2238 -- end Gen;
2240 -- [with External;] -- implicit with for External
2241 -- [pragma Elaborate_All (External);] -- Elaborate_All for External
2242 -- with Gen;
2243 -- [pragma Elaborate (Gen);] -- Elaborate for generic
2244 -- procedure Main is
2245 -- package Inst is new Gen; -- calls External.Func
2246 -- ...
2247 -- end Main;
2249 if Nkind (N) in N_Generic_Instantiation then
2250 Prag_Nam := Name_Elaborate;
2252 -- Otherwise generate an implicit Elaborate_All
2254 else
2255 Prag_Nam := Name_Elaborate_All;
2256 end if;
2258 -- Nothing to do when the need for prior elaboration came from a partial
2259 -- finalization routine which occurs in an initialization context. This
2260 -- behaviour parallels that of the old ABE mechanism.
2262 if In_Partial_Fin then
2263 return;
2265 -- Nothing to do when the need for prior elaboration came from a task
2266 -- body and switch -gnatd.y (disable implicit pragma Elaborate_All on
2267 -- task bodies) is in effect.
2269 elsif Debug_Flag_Dot_Y and then In_Task_Body then
2270 return;
2272 -- Nothing to do when the unit is elaborated prior to the main unit.
2273 -- This check must also consider the following cases:
2275 -- * No check is made against the context of the main unit because this
2276 -- is specific to the elaboration model in effect and requires custom
2277 -- handling (see Ensure_xxx_Prior_Elaboration).
2279 -- * Unit_Id is subject to pragma Elaborate_Body. An implicit pragma
2280 -- Elaborate[_All] MUST be generated even though Unit_Id is always
2281 -- elaborated prior to the main unit. This is a conservative strategy
2282 -- which ensures that other units withed by Unit_Id will not lead to
2283 -- an ABE.
2285 -- package A is package body A is
2286 -- procedure ABE; procedure ABE is ... end ABE;
2287 -- end A; end A;
2289 -- with A;
2290 -- package B is package body B is
2291 -- pragma Elaborate_Body; procedure Proc is
2292 -- begin
2293 -- procedure Proc; A.ABE;
2294 -- package B; end Proc;
2295 -- end B;
2297 -- with B;
2298 -- package C is package body C is
2299 -- ... ...
2300 -- end C; begin
2301 -- B.Proc;
2302 -- end C;
2304 -- In the example above, the elaboration of C invokes B.Proc. B is
2305 -- subject to pragma Elaborate_Body. If no pragma Elaborate[_All] is
2306 -- generated for B in C, then the following elaboratio order will lead
2307 -- to an ABE:
2309 -- spec of A elaborated
2310 -- spec of B elaborated
2311 -- body of B elaborated
2312 -- spec of C elaborated
2313 -- body of C elaborated <-- calls B.Proc which calls A.ABE
2314 -- body of A elaborated <-- problem
2316 -- The generation of an implicit pragma Elaborate_All (B) ensures that
2317 -- the elaboration order mechanism will not pick the above order.
2319 -- An implicit Elaborate is NOT generated when the unit is subject to
2320 -- Elaborate_Body because both pragmas have the exact same effect.
2322 -- * Unit_Id is the main unit. An implicit pragma Elaborate[_All] MUST
2323 -- NOT be generated in this case because a unit cannot depend on its
2324 -- own elaboration. This case is therefore treated as valid prior
2325 -- elaboration.
2327 elsif Has_Prior_Elaboration
2328 (Unit_Id => Unit_Id,
2329 Same_Unit_OK => True,
2330 Elab_Body_OK => Prag_Nam = Name_Elaborate)
2331 then
2332 return;
2334 -- Suggest the use of pragma Prag_Nam when the dynamic model is in
2335 -- effect.
2337 elsif Dynamic_Elaboration_Checks then
2338 Ensure_Prior_Elaboration_Dynamic
2339 (N => N,
2340 Unit_Id => Unit_Id,
2341 Prag_Nam => Prag_Nam);
2343 -- Install an implicit pragma Prag_Nam when the static model is in
2344 -- effect.
2346 else
2347 pragma Assert (Static_Elaboration_Checks);
2349 Ensure_Prior_Elaboration_Static
2350 (N => N,
2351 Unit_Id => Unit_Id,
2352 Prag_Nam => Prag_Nam);
2353 end if;
2354 end Ensure_Prior_Elaboration;
2356 --------------------------------------
2357 -- Ensure_Prior_Elaboration_Dynamic --
2358 --------------------------------------
2360 procedure Ensure_Prior_Elaboration_Dynamic
2361 (N : Node_Id;
2362 Unit_Id : Entity_Id;
2363 Prag_Nam : Name_Id)
2365 procedure Info_Missing_Pragma;
2366 pragma Inline (Info_Missing_Pragma);
2367 -- Output information concerning missing Elaborate or Elaborate_All
2368 -- pragma with name Prag_Nam for scenario N, which would ensure the
2369 -- prior elaboration of Unit_Id.
2371 -------------------------
2372 -- Info_Missing_Pragma --
2373 -------------------------
2375 procedure Info_Missing_Pragma is
2376 begin
2377 -- Internal units are ignored as they cause unnecessary noise
2379 if not In_Internal_Unit (Unit_Id) then
2381 -- The name of the unit subjected to the elaboration pragma is
2382 -- fully qualified to improve the clarity of the info message.
2384 Error_Msg_Name_1 := Prag_Nam;
2385 Error_Msg_Qual_Level := Nat'Last;
2387 Error_Msg_NE ("info: missing pragma % for unit &", N, Unit_Id);
2388 Error_Msg_Qual_Level := 0;
2389 end if;
2390 end Info_Missing_Pragma;
2392 -- Local variables
2394 Elab_Attrs : Elaboration_Attributes;
2395 Level : Enclosing_Level_Kind;
2397 -- Start of processing for Ensure_Prior_Elaboration_Dynamic
2399 begin
2400 Elab_Attrs := Elaboration_Context.Get (Unit_Id);
2402 -- Nothing to do when the unit is guaranteed prior elaboration by means
2403 -- of a source Elaborate[_All] pragma.
2405 if Present (Elab_Attrs.Source_Pragma) then
2406 return;
2407 end if;
2409 -- Output extra information on a missing Elaborate[_All] pragma when
2410 -- switch -gnatel (info messages on implicit Elaborate[_All] pragmas
2411 -- is in effect.
2413 if Elab_Info_Messages then
2415 -- Performance note: parent traversal
2417 Level := Find_Enclosing_Level (N);
2419 -- Declaration-level scenario
2421 if (Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N))
2422 and then Level = Declaration_Level
2423 then
2424 null;
2426 -- Library-level scenario
2428 elsif Level in Library_Level then
2429 null;
2431 -- Instantiation library-level scenario
2433 elsif Level = Instantiation then
2434 null;
2436 -- Otherwise the scenario does not appear at the proper level and
2437 -- cannot possibly act as a top-level scenario.
2439 else
2440 return;
2441 end if;
2443 Info_Missing_Pragma;
2444 end if;
2445 end Ensure_Prior_Elaboration_Dynamic;
2447 -------------------------------------
2448 -- Ensure_Prior_Elaboration_Static --
2449 -------------------------------------
2451 procedure Ensure_Prior_Elaboration_Static
2452 (N : Node_Id;
2453 Unit_Id : Entity_Id;
2454 Prag_Nam : Name_Id)
2456 function Find_With_Clause
2457 (Items : List_Id;
2458 Withed_Id : Entity_Id) return Node_Id;
2459 pragma Inline (Find_With_Clause);
2460 -- Find a nonlimited with clause in the list of context items Items
2461 -- that withs unit Withed_Id. Return Empty if no such clause is found.
2463 procedure Info_Implicit_Pragma;
2464 pragma Inline (Info_Implicit_Pragma);
2465 -- Output information concerning an implicitly generated Elaborate or
2466 -- Elaborate_All pragma with name Prag_Nam for scenario N which ensures
2467 -- the prior elaboration of unit Unit_Id.
2469 ----------------------
2470 -- Find_With_Clause --
2471 ----------------------
2473 function Find_With_Clause
2474 (Items : List_Id;
2475 Withed_Id : Entity_Id) return Node_Id
2477 Item : Node_Id;
2479 begin
2480 -- Examine the context clauses looking for a suitable with. Note that
2481 -- limited clauses do not affect the elaboration order.
2483 Item := First (Items);
2484 while Present (Item) loop
2485 if Nkind (Item) = N_With_Clause
2486 and then not Error_Posted (Item)
2487 and then not Limited_Present (Item)
2488 and then Entity (Name (Item)) = Withed_Id
2489 then
2490 return Item;
2491 end if;
2493 Next (Item);
2494 end loop;
2496 return Empty;
2497 end Find_With_Clause;
2499 --------------------------
2500 -- Info_Implicit_Pragma --
2501 --------------------------
2503 procedure Info_Implicit_Pragma is
2504 begin
2505 -- Internal units are ignored as they cause unnecessary noise
2507 if not In_Internal_Unit (Unit_Id) then
2509 -- The name of the unit subjected to the elaboration pragma is
2510 -- fully qualified to improve the clarity of the info message.
2512 Error_Msg_Name_1 := Prag_Nam;
2513 Error_Msg_Qual_Level := Nat'Last;
2515 Error_Msg_NE
2516 ("info: implicit pragma % generated for unit &", N, Unit_Id);
2518 Error_Msg_Qual_Level := 0;
2519 Output_Active_Scenarios (N);
2520 end if;
2521 end Info_Implicit_Pragma;
2523 -- Local variables
2525 Main_Cunit : constant Node_Id := Cunit (Main_Unit);
2526 Loc : constant Source_Ptr := Sloc (Main_Cunit);
2527 Unit_Cunit : constant Node_Id := Compilation_Unit (Unit_Id);
2529 Is_Instantiation : constant Boolean :=
2530 Nkind (N) in N_Generic_Instantiation;
2532 Clause : Node_Id;
2533 Elab_Attrs : Elaboration_Attributes;
2534 Items : List_Id;
2536 -- Start of processing for Ensure_Prior_Elaboration_Static
2538 begin
2539 Elab_Attrs := Elaboration_Context.Get (Unit_Id);
2541 -- Nothing to do when the unit is guaranteed prior elaboration by means
2542 -- of a source Elaborate[_All] pragma.
2544 if Present (Elab_Attrs.Source_Pragma) then
2545 return;
2547 -- Nothing to do when the unit has an existing implicit Elaborate[_All]
2548 -- pragma installed by a previous scenario.
2550 elsif Present (Elab_Attrs.With_Clause) then
2552 -- The unit is already guaranteed prior elaboration by means of an
2553 -- implicit Elaborate pragma, however the current scenario imposes
2554 -- a stronger requirement of Elaborate_All. "Upgrade" the existing
2555 -- pragma to match this new requirement.
2557 if Elaborate_Desirable (Elab_Attrs.With_Clause)
2558 and then Prag_Nam = Name_Elaborate_All
2559 then
2560 Set_Elaborate_All_Desirable (Elab_Attrs.With_Clause);
2561 Set_Elaborate_Desirable (Elab_Attrs.With_Clause, False);
2562 end if;
2564 return;
2565 end if;
2567 -- At this point it is known that the unit has no prior elaboration
2568 -- according to pragmas and hierarchical relationships.
2570 Items := Context_Items (Main_Cunit);
2572 if No (Items) then
2573 Items := New_List;
2574 Set_Context_Items (Main_Cunit, Items);
2575 end if;
2577 -- Locate the with clause for the unit. Note that there may not be a
2578 -- clause if the unit is visible through a subunit-body, body-spec, or
2579 -- spec-parent relationship.
2581 Clause :=
2582 Find_With_Clause
2583 (Items => Items,
2584 Withed_Id => Unit_Id);
2586 -- Generate:
2587 -- with Id;
2589 -- Note that adding implicit with clauses is safe because analysis,
2590 -- resolution, and expansion have already taken place and it is not
2591 -- possible to interfere with visibility.
2593 if No (Clause) then
2594 Clause :=
2595 Make_With_Clause (Loc,
2596 Name => New_Occurrence_Of (Unit_Id, Loc));
2598 Set_Implicit_With (Clause);
2599 Set_Library_Unit (Clause, Unit_Cunit);
2601 Append_To (Items, Clause);
2602 end if;
2604 -- Instantiations require an implicit Elaborate because Elaborate_All is
2605 -- too conservative and may introduce non-existent elaboration cycles.
2607 if Is_Instantiation then
2608 Set_Elaborate_Desirable (Clause);
2610 -- Otherwise generate an implicit Elaborate_All
2612 else
2613 Set_Elaborate_All_Desirable (Clause);
2614 end if;
2616 -- The implicit Elaborate[_All] ensures the prior elaboration of the
2617 -- unit. Include the unit in the elaboration context of the main unit.
2619 Elaboration_Context.Set (Unit_Id,
2620 Elaboration_Attributes'(Source_Pragma => Empty,
2621 With_Clause => Clause));
2623 -- Output extra information on an implicit Elaborate[_All] pragma when
2624 -- switch -gnatel (info messages on implicit Elaborate[_All] pragmas is
2625 -- in effect.
2627 if Elab_Info_Messages then
2628 Info_Implicit_Pragma;
2629 end if;
2630 end Ensure_Prior_Elaboration_Static;
2632 -----------------------------
2633 -- Extract_Assignment_Name --
2634 -----------------------------
2636 function Extract_Assignment_Name (Asmt : Node_Id) return Node_Id is
2637 Nam : Node_Id;
2639 begin
2640 Nam := Name (Asmt);
2642 -- When the name denotes an array or record component, find the whole
2643 -- object.
2645 while Nkind_In (Nam, N_Explicit_Dereference,
2646 N_Indexed_Component,
2647 N_Selected_Component,
2648 N_Slice)
2649 loop
2650 Nam := Prefix (Nam);
2651 end loop;
2653 return Nam;
2654 end Extract_Assignment_Name;
2656 -----------------------------
2657 -- Extract_Call_Attributes --
2658 -----------------------------
2660 procedure Extract_Call_Attributes
2661 (Call : Node_Id;
2662 Target_Id : out Entity_Id;
2663 Attrs : out Call_Attributes)
2665 From_Source : Boolean;
2666 In_Declarations : Boolean;
2667 Is_Dispatching : Boolean;
2669 begin
2670 -- Extraction for call markers
2672 if Nkind (Call) = N_Call_Marker then
2673 Target_Id := Target (Call);
2674 From_Source := Is_Source_Call (Call);
2675 In_Declarations := Is_Declaration_Level_Node (Call);
2676 Is_Dispatching := Is_Dispatching_Call (Call);
2678 -- Extraction for entry calls, requeue, and subprogram calls
2680 else
2681 pragma Assert (Nkind_In (Call, N_Entry_Call_Statement,
2682 N_Function_Call,
2683 N_Procedure_Call_Statement,
2684 N_Requeue_Statement));
2686 Target_Id := Entity (Extract_Call_Name (Call));
2687 From_Source := Comes_From_Source (Call);
2689 -- Performance note: parent traversal
2691 In_Declarations := Find_Enclosing_Level (Call) = Declaration_Level;
2692 Is_Dispatching :=
2693 Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
2694 and then Present (Controlling_Argument (Call));
2695 end if;
2697 -- Obtain the original entry or subprogram which the target may rename
2698 -- except when the target is an instantiation. In this case the alias
2699 -- is the internally generated subprogram which appears within the the
2700 -- anonymous package created for the instantiation. Such an alias is not
2701 -- a suitable target.
2703 if not (Is_Subprogram (Target_Id)
2704 and then Is_Generic_Instance (Target_Id))
2705 then
2706 Target_Id := Get_Renamed_Entity (Target_Id);
2707 end if;
2709 -- Set all attributes
2711 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Call);
2712 Attrs.From_Source := From_Source;
2713 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Node (Call);
2714 Attrs.In_Declarations := In_Declarations;
2715 Attrs.Is_Dispatching := Is_Dispatching;
2716 Attrs.SPARK_Mode_On := Is_SPARK_Mode_On_Node (Call);
2717 end Extract_Call_Attributes;
2719 -----------------------
2720 -- Extract_Call_Name --
2721 -----------------------
2723 function Extract_Call_Name (Call : Node_Id) return Node_Id is
2724 Nam : Node_Id;
2726 begin
2727 Nam := Name (Call);
2729 -- When the call invokes an entry family, the name appears as an indexed
2730 -- component.
2732 if Nkind (Nam) = N_Indexed_Component then
2733 Nam := Prefix (Nam);
2734 end if;
2736 -- When the call employs the object.operation form, the name appears as
2737 -- a selected component.
2739 if Nkind (Nam) = N_Selected_Component then
2740 Nam := Selector_Name (Nam);
2741 end if;
2743 return Nam;
2744 end Extract_Call_Name;
2746 ---------------------------------
2747 -- Extract_Instance_Attributes --
2748 ---------------------------------
2750 procedure Extract_Instance_Attributes
2751 (Exp_Inst : Node_Id;
2752 Inst_Body : out Node_Id;
2753 Inst_Decl : out Node_Id)
2755 Body_Id : Entity_Id;
2757 begin
2758 -- Assume that the attributes are unavailable
2760 Inst_Body := Empty;
2761 Inst_Decl := Empty;
2763 -- Generic package or subprogram spec
2765 if Nkind_In (Exp_Inst, N_Package_Declaration,
2766 N_Subprogram_Declaration)
2767 then
2768 Inst_Decl := Exp_Inst;
2769 Body_Id := Corresponding_Body (Inst_Decl);
2771 if Present (Body_Id) then
2772 Inst_Body := Unit_Declaration_Node (Body_Id);
2773 end if;
2775 -- Generic package or subprogram body
2777 else
2778 pragma Assert
2779 (Nkind_In (Exp_Inst, N_Package_Body, N_Subprogram_Body));
2781 Inst_Body := Exp_Inst;
2782 Inst_Decl := Unit_Declaration_Node (Corresponding_Spec (Inst_Body));
2783 end if;
2784 end Extract_Instance_Attributes;
2786 --------------------------------------
2787 -- Extract_Instantiation_Attributes --
2788 --------------------------------------
2790 procedure Extract_Instantiation_Attributes
2791 (Exp_Inst : Node_Id;
2792 Inst : out Node_Id;
2793 Inst_Id : out Entity_Id;
2794 Gen_Id : out Entity_Id;
2795 Attrs : out Instantiation_Attributes)
2797 begin
2798 Inst := Original_Node (Exp_Inst);
2799 Inst_Id := Defining_Entity (Inst);
2801 -- Traverse a possible chain of renamings to obtain the original generic
2802 -- being instantiatied.
2804 Gen_Id := Get_Renamed_Entity (Entity (Name (Inst)));
2806 -- Set all attributes
2808 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Inst);
2809 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Node (Inst);
2810 Attrs.In_Declarations := Is_Declaration_Level_Node (Inst);
2811 Attrs.SPARK_Mode_On := Is_SPARK_Mode_On_Node (Inst);
2812 end Extract_Instantiation_Attributes;
2814 -------------------------------
2815 -- Extract_Target_Attributes --
2816 -------------------------------
2818 procedure Extract_Target_Attributes
2819 (Target_Id : Entity_Id;
2820 Attrs : out Target_Attributes)
2822 procedure Extract_Package_Or_Subprogram_Attributes
2823 (Spec_Id : out Entity_Id;
2824 Body_Decl : out Node_Id);
2825 -- Obtain the attributes associated with a package or a subprogram.
2826 -- Spec_Id is the package or subprogram. Body_Decl is the declaration
2827 -- of the corresponding package or subprogram body.
2829 procedure Extract_Protected_Entry_Attributes
2830 (Spec_Id : out Entity_Id;
2831 Body_Decl : out Node_Id;
2832 Body_Barf : out Node_Id);
2833 -- Obtain the attributes associated with a protected entry [family].
2834 -- Spec_Id is the entity of the protected body subprogram. Body_Decl
2835 -- is the declaration of Spec_Id's corresponding body. Body_Barf is
2836 -- the declaration of the barrier function body.
2838 procedure Extract_Protected_Subprogram_Attributes
2839 (Spec_Id : out Entity_Id;
2840 Body_Decl : out Node_Id);
2841 -- Obtain the attributes associated with a protected subprogram. Formal
2842 -- Spec_Id is the entity of the protected body subprogram. Body_Decl is
2843 -- the declaration of Spec_Id's corresponding body.
2845 procedure Extract_Task_Entry_Attributes
2846 (Spec_Id : out Entity_Id;
2847 Body_Decl : out Node_Id);
2848 -- Obtain the attributes associated with a task entry [family]. Formal
2849 -- Spec_Id is the entity of the task body procedure. Body_Decl is the
2850 -- declaration of Spec_Id's corresponding body.
2852 ----------------------------------------------
2853 -- Extract_Package_Or_Subprogram_Attributes --
2854 ----------------------------------------------
2856 procedure Extract_Package_Or_Subprogram_Attributes
2857 (Spec_Id : out Entity_Id;
2858 Body_Decl : out Node_Id)
2860 Body_Id : Entity_Id;
2861 Init_Id : Entity_Id;
2862 Spec_Decl : Node_Id;
2864 begin
2865 -- Assume that the body is not available
2867 Body_Decl := Empty;
2868 Spec_Id := Target_Id;
2870 -- For body retrieval purposes, the entity of the initial declaration
2871 -- is that of the spec.
2873 Init_Id := Spec_Id;
2875 -- The only exception to the above is a function which returns a
2876 -- constrained array type in a SPARK-to-C compilation. In this case
2877 -- the function receives a corresponding procedure which has an out
2878 -- parameter. The proper body for ABE checks and diagnostics is that
2879 -- of the procedure.
2881 if Ekind (Init_Id) = E_Function
2882 and then Rewritten_For_C (Init_Id)
2883 then
2884 Init_Id := Corresponding_Procedure (Init_Id);
2885 end if;
2887 -- Extract the attributes of the body
2889 Spec_Decl := Unit_Declaration_Node (Init_Id);
2891 -- The initial declaration is a stand alone subprogram body
2893 if Nkind (Spec_Decl) = N_Subprogram_Body then
2894 Body_Decl := Spec_Decl;
2896 -- Otherwise the package or subprogram has a spec and a completing
2897 -- body.
2899 elsif Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
2900 N_Generic_Subprogram_Declaration,
2901 N_Package_Declaration,
2902 N_Subprogram_Body_Stub,
2903 N_Subprogram_Declaration)
2904 then
2905 Body_Id := Corresponding_Body (Spec_Decl);
2907 if Present (Body_Id) then
2908 Body_Decl := Unit_Declaration_Node (Body_Id);
2909 end if;
2910 end if;
2911 end Extract_Package_Or_Subprogram_Attributes;
2913 ----------------------------------------
2914 -- Extract_Protected_Entry_Attributes --
2915 ----------------------------------------
2917 procedure Extract_Protected_Entry_Attributes
2918 (Spec_Id : out Entity_Id;
2919 Body_Decl : out Node_Id;
2920 Body_Barf : out Node_Id)
2922 Barf_Id : Entity_Id;
2923 Body_Id : Entity_Id;
2925 begin
2926 -- Assume that the bodies are not available
2928 Body_Barf := Empty;
2929 Body_Decl := Empty;
2931 -- When the entry [family] has already been expanded, it carries both
2932 -- the procedure which emulates the behavior of the entry [family] as
2933 -- well as the barrier function.
2935 if Present (Protected_Body_Subprogram (Target_Id)) then
2936 Spec_Id := Protected_Body_Subprogram (Target_Id);
2938 -- Extract the attributes of the barrier function
2940 Barf_Id :=
2941 Corresponding_Body
2942 (Unit_Declaration_Node (Barrier_Function (Target_Id)));
2944 if Present (Barf_Id) then
2945 Body_Barf := Unit_Declaration_Node (Barf_Id);
2946 end if;
2948 -- Otherwise no expansion took place
2950 else
2951 Spec_Id := Target_Id;
2952 end if;
2954 -- Extract the attributes of the entry body
2956 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
2958 if Present (Body_Id) then
2959 Body_Decl := Unit_Declaration_Node (Body_Id);
2960 end if;
2961 end Extract_Protected_Entry_Attributes;
2963 ---------------------------------------------
2964 -- Extract_Protected_Subprogram_Attributes --
2965 ---------------------------------------------
2967 procedure Extract_Protected_Subprogram_Attributes
2968 (Spec_Id : out Entity_Id;
2969 Body_Decl : out Node_Id)
2971 Body_Id : Entity_Id;
2973 begin
2974 -- Assume that the body is not available
2976 Body_Decl := Empty;
2978 -- When the protected subprogram has already been expanded, it
2979 -- carries the subprogram which seizes the lock and invokes the
2980 -- original statements.
2982 if Present (Protected_Subprogram (Target_Id)) then
2983 Spec_Id :=
2984 Protected_Body_Subprogram (Protected_Subprogram (Target_Id));
2986 -- Otherwise no expansion took place
2988 else
2989 Spec_Id := Target_Id;
2990 end if;
2992 -- Extract the attributes of the body
2994 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
2996 if Present (Body_Id) then
2997 Body_Decl := Unit_Declaration_Node (Body_Id);
2998 end if;
2999 end Extract_Protected_Subprogram_Attributes;
3001 -----------------------------------
3002 -- Extract_Task_Entry_Attributes --
3003 -----------------------------------
3005 procedure Extract_Task_Entry_Attributes
3006 (Spec_Id : out Entity_Id;
3007 Body_Decl : out Node_Id)
3009 Task_Typ : constant Entity_Id := Non_Private_View (Scope (Target_Id));
3010 Body_Id : Entity_Id;
3012 begin
3013 -- Assume that the body is not available
3015 Body_Decl := Empty;
3017 -- The the task type has already been expanded, it carries the
3018 -- procedure which emulates the behavior of the task body.
3020 if Present (Task_Body_Procedure (Task_Typ)) then
3021 Spec_Id := Task_Body_Procedure (Task_Typ);
3023 -- Otherwise no expansion took place
3025 else
3026 Spec_Id := Task_Typ;
3027 end if;
3029 -- Extract the attributes of the body
3031 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3033 if Present (Body_Id) then
3034 Body_Decl := Unit_Declaration_Node (Body_Id);
3035 end if;
3036 end Extract_Task_Entry_Attributes;
3038 -- Local variables
3040 Prag : constant Node_Id := SPARK_Pragma (Target_Id);
3041 Body_Barf : Node_Id;
3042 Body_Decl : Node_Id;
3043 Spec_Id : Entity_Id;
3045 -- Start of processing for Extract_Target_Attributes
3047 begin
3048 -- Assume that the body of the barrier function is not available
3050 Body_Barf := Empty;
3052 -- The target is a protected entry [family]
3054 if Is_Protected_Entry (Target_Id) then
3055 Extract_Protected_Entry_Attributes
3056 (Spec_Id => Spec_Id,
3057 Body_Decl => Body_Decl,
3058 Body_Barf => Body_Barf);
3060 -- The target is a protected subprogram
3062 elsif Is_Protected_Subp (Target_Id)
3063 or else Is_Protected_Body_Subp (Target_Id)
3064 then
3065 Extract_Protected_Subprogram_Attributes
3066 (Spec_Id => Spec_Id,
3067 Body_Decl => Body_Decl);
3069 -- The target is a task entry [family]
3071 elsif Is_Task_Entry (Target_Id) then
3072 Extract_Task_Entry_Attributes
3073 (Spec_Id => Spec_Id,
3074 Body_Decl => Body_Decl);
3076 -- Otherwise the target is a package or a subprogram
3078 else
3079 Extract_Package_Or_Subprogram_Attributes
3080 (Spec_Id => Spec_Id,
3081 Body_Decl => Body_Decl);
3082 end if;
3084 -- Set all attributes
3086 Attrs.Body_Barf := Body_Barf;
3087 Attrs.Body_Decl := Body_Decl;
3088 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Target_Id);
3089 Attrs.From_Source := Comes_From_Source (Target_Id);
3090 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Entity (Target_Id);
3091 Attrs.SPARK_Mode_On :=
3092 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = On;
3093 Attrs.Spec_Decl := Unit_Declaration_Node (Spec_Id);
3094 Attrs.Spec_Id := Spec_Id;
3095 Attrs.Unit_Id := Find_Top_Unit (Target_Id);
3097 -- At this point certain attributes should always be available
3099 pragma Assert (Present (Attrs.Spec_Decl));
3100 pragma Assert (Present (Attrs.Spec_Id));
3101 pragma Assert (Present (Attrs.Unit_Id));
3102 end Extract_Target_Attributes;
3104 -----------------------------
3105 -- Extract_Task_Attributes --
3106 -----------------------------
3108 procedure Extract_Task_Attributes
3109 (Typ : Entity_Id;
3110 Attrs : out Task_Attributes)
3112 Task_Typ : constant Entity_Id := Non_Private_View (Typ);
3114 Body_Decl : Node_Id;
3115 Body_Id : Entity_Id;
3116 Prag : Node_Id;
3117 Spec_Id : Entity_Id;
3119 begin
3120 -- Assume that the body of the task procedure is not available
3122 Body_Decl := Empty;
3124 -- The initial declaration is that of the task body procedure
3126 Spec_Id := Get_Task_Body_Procedure (Task_Typ);
3127 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3129 if Present (Body_Id) then
3130 Body_Decl := Unit_Declaration_Node (Body_Id);
3131 end if;
3133 Prag := SPARK_Pragma (Task_Typ);
3135 -- Set all attributes
3137 Attrs.Body_Decl := Body_Decl;
3138 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Task_Typ);
3139 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Entity (Task_Typ);
3140 Attrs.SPARK_Mode_On :=
3141 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = On;
3142 Attrs.Spec_Id := Spec_Id;
3143 Attrs.Task_Decl := Declaration_Node (Task_Typ);
3144 Attrs.Unit_Id := Find_Top_Unit (Task_Typ);
3146 -- At this point certain attributes should always be available
3148 pragma Assert (Present (Attrs.Spec_Id));
3149 pragma Assert (Present (Attrs.Task_Decl));
3150 pragma Assert (Present (Attrs.Unit_Id));
3151 end Extract_Task_Attributes;
3153 -------------------------------------------
3154 -- Extract_Variable_Reference_Attributes --
3155 -------------------------------------------
3157 procedure Extract_Variable_Reference_Attributes
3158 (Ref : Node_Id;
3159 Var_Id : out Entity_Id;
3160 Attrs : out Variable_Attributes)
3162 function Get_Renamed_Variable (Id : Entity_Id) return Entity_Id;
3163 -- Obtain the ultimate renamed variable of variable Id
3165 --------------------------
3166 -- Get_Renamed_Variable --
3167 --------------------------
3169 function Get_Renamed_Variable (Id : Entity_Id) return Entity_Id is
3170 Ren_Id : Entity_Id;
3172 begin
3173 Ren_Id := Id;
3174 while Present (Renamed_Entity (Ren_Id))
3175 and then Nkind (Renamed_Entity (Ren_Id)) in N_Entity
3176 loop
3177 Ren_Id := Renamed_Entity (Ren_Id);
3178 end loop;
3180 return Ren_Id;
3181 end Get_Renamed_Variable;
3183 -- Start of processing for Extract_Variable_Reference_Attributes
3185 begin
3186 -- Extraction for variable reference markers
3188 if Nkind (Ref) = N_Variable_Reference_Marker then
3189 Var_Id := Target (Ref);
3191 -- Extraction for expanded names and identifiers
3193 else
3194 Var_Id := Entity (Ref);
3195 end if;
3197 -- Obtain the original variable which the reference mentions
3199 Var_Id := Get_Renamed_Variable (Var_Id);
3200 Attrs.Unit_Id := Find_Top_Unit (Var_Id);
3202 -- At this point certain attributes should always be available
3204 pragma Assert (Present (Attrs.Unit_Id));
3205 end Extract_Variable_Reference_Attributes;
3207 --------------------
3208 -- Find_Code_Unit --
3209 --------------------
3211 function Find_Code_Unit (N : Node_Or_Entity_Id) return Entity_Id is
3212 begin
3213 return Find_Unit_Entity (Unit (Cunit (Get_Code_Unit (N))));
3214 end Find_Code_Unit;
3216 ---------------------------
3217 -- Find_Elaborated_Units --
3218 ---------------------------
3220 procedure Find_Elaborated_Units is
3221 procedure Add_Pragma (Prag : Node_Id);
3222 -- Determine whether pragma Prag denotes a legal Elaborate[_All] pragma.
3223 -- If this is the case, add the related unit to the elaboration context.
3224 -- For pragma Elaborate_All, include recursively all units withed by the
3225 -- related unit.
3227 procedure Add_Unit
3228 (Unit_Id : Entity_Id;
3229 Prag : Node_Id;
3230 Full_Context : Boolean);
3231 -- Add unit Unit_Id to the elaboration context. Prag denotes the pragma
3232 -- which prompted the inclusion of the unit to the elaboration context.
3233 -- If flag Full_Context is set, examine the nonlimited clauses of unit
3234 -- Unit_Id and add each withed unit to the context.
3236 procedure Find_Elaboration_Context (Comp_Unit : Node_Id);
3237 -- Examine the context items of compilation unit Comp_Unit for suitable
3238 -- elaboration-related pragmas and add all related units to the context.
3240 ----------------
3241 -- Add_Pragma --
3242 ----------------
3244 procedure Add_Pragma (Prag : Node_Id) is
3245 Prag_Args : constant List_Id := Pragma_Argument_Associations (Prag);
3246 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
3247 Unit_Arg : Node_Id;
3249 begin
3250 -- Nothing to do if the pragma is not related to elaboration
3252 if not Nam_In (Prag_Nam, Name_Elaborate, Name_Elaborate_All) then
3253 return;
3255 -- Nothing to do when the pragma is illegal
3257 elsif Error_Posted (Prag) then
3258 return;
3259 end if;
3261 Unit_Arg := Get_Pragma_Arg (First (Prag_Args));
3263 -- The argument of the pragma may appear in package.package form
3265 if Nkind (Unit_Arg) = N_Selected_Component then
3266 Unit_Arg := Selector_Name (Unit_Arg);
3267 end if;
3269 Add_Unit
3270 (Unit_Id => Entity (Unit_Arg),
3271 Prag => Prag,
3272 Full_Context => Prag_Nam = Name_Elaborate_All);
3273 end Add_Pragma;
3275 --------------
3276 -- Add_Unit --
3277 --------------
3279 procedure Add_Unit
3280 (Unit_Id : Entity_Id;
3281 Prag : Node_Id;
3282 Full_Context : Boolean)
3284 Clause : Node_Id;
3285 Elab_Attrs : Elaboration_Attributes;
3287 begin
3288 -- Nothing to do when some previous error left a with clause or a
3289 -- pragma in a bad state.
3291 if No (Unit_Id) then
3292 return;
3293 end if;
3295 Elab_Attrs := Elaboration_Context.Get (Unit_Id);
3297 -- The current unit is not part of the context. Prepare a new set of
3298 -- attributes.
3300 if Elab_Attrs = No_Elaboration_Attributes then
3301 Elab_Attrs :=
3302 Elaboration_Attributes'(Source_Pragma => Prag,
3303 With_Clause => Empty);
3305 -- The unit is already included in the context by means of pragma
3306 -- Elaborate. "Upgrage" the existing attributes when the unit is
3307 -- subject to Elaborate_All because the new pragma covers a larger
3308 -- set of units. All other properties remain the same.
3310 elsif Pragma_Name (Elab_Attrs.Source_Pragma) = Name_Elaborate
3311 and then Pragma_Name (Prag) = Name_Elaborate_All
3312 then
3313 Elab_Attrs.Source_Pragma := Prag;
3315 -- Otherwise the unit is already included in the context
3317 else
3318 return;
3319 end if;
3321 -- Add or update the attributes of the unit
3323 Elaboration_Context.Set (Unit_Id, Elab_Attrs);
3325 -- Includes all units withed by the current one when computing the
3326 -- full context.
3328 if Full_Context then
3330 -- Process all nonlimited with clauses found in the context of
3331 -- the current unit. Note that limited clauses do not impose an
3332 -- elaboration order.
3334 Clause := First (Context_Items (Compilation_Unit (Unit_Id)));
3335 while Present (Clause) loop
3336 if Nkind (Clause) = N_With_Clause
3337 and then not Error_Posted (Clause)
3338 and then not Limited_Present (Clause)
3339 then
3340 Add_Unit
3341 (Unit_Id => Entity (Name (Clause)),
3342 Prag => Prag,
3343 Full_Context => Full_Context);
3344 end if;
3346 Next (Clause);
3347 end loop;
3348 end if;
3349 end Add_Unit;
3351 ------------------------------
3352 -- Find_Elaboration_Context --
3353 ------------------------------
3355 procedure Find_Elaboration_Context (Comp_Unit : Node_Id) is
3356 Prag : Node_Id;
3358 begin
3359 pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
3361 -- Process all elaboration-related pragmas found in the context of
3362 -- the compilation unit.
3364 Prag := First (Context_Items (Comp_Unit));
3365 while Present (Prag) loop
3366 if Nkind (Prag) = N_Pragma then
3367 Add_Pragma (Prag);
3368 end if;
3370 Next (Prag);
3371 end loop;
3372 end Find_Elaboration_Context;
3374 -- Local variables
3376 Par_Id : Entity_Id;
3377 Unt : Node_Id;
3379 -- Start of processing for Find_Elaborated_Units
3381 begin
3382 -- Perform a traversal which examines the context of the main unit and
3383 -- populates the Elaboration_Context table with all units elaborated
3384 -- prior to the main unit. The traversal performs the following jumps:
3386 -- subunit -> parent subunit
3387 -- parent subunit -> body
3388 -- body -> spec
3389 -- spec -> parent spec
3390 -- parent spec -> grandparent spec and so on
3392 -- The traversal relies on units rather than scopes because the scope of
3393 -- a subunit is some spec, while this traversal must process the body as
3394 -- well. Given that protected and task bodies can also be subunits, this
3395 -- complicates the scope approach even further.
3397 Unt := Unit (Cunit (Main_Unit));
3399 -- Perform the following traversals when the main unit is a subunit
3401 -- subunit -> parent subunit
3402 -- parent subunit -> body
3404 while Present (Unt) and then Nkind (Unt) = N_Subunit loop
3405 Find_Elaboration_Context (Parent (Unt));
3407 -- Continue the traversal by going to the unit which contains the
3408 -- corresponding stub.
3410 if Present (Corresponding_Stub (Unt)) then
3411 Unt := Unit (Cunit (Get_Source_Unit (Corresponding_Stub (Unt))));
3413 -- Otherwise the subunit may be erroneous or left in a bad state
3415 else
3416 exit;
3417 end if;
3418 end loop;
3420 -- Perform the following traversal now that subunits have been taken
3421 -- care of, or the main unit is a body.
3423 -- body -> spec
3425 if Present (Unt)
3426 and then Nkind_In (Unt, N_Package_Body, N_Subprogram_Body)
3427 then
3428 Find_Elaboration_Context (Parent (Unt));
3430 -- Continue the traversal by going to the unit which contains the
3431 -- corresponding spec.
3433 if Present (Corresponding_Spec (Unt)) then
3434 Unt := Unit (Cunit (Get_Source_Unit (Corresponding_Spec (Unt))));
3435 end if;
3436 end if;
3438 -- Perform the following traversals now that the body has been taken
3439 -- care of, or the main unit is a spec.
3441 -- spec -> parent spec
3442 -- parent spec -> grandparent spec and so on
3444 if Present (Unt)
3445 and then Nkind_In (Unt, N_Generic_Package_Declaration,
3446 N_Generic_Subprogram_Declaration,
3447 N_Package_Declaration,
3448 N_Subprogram_Declaration)
3449 then
3450 Find_Elaboration_Context (Parent (Unt));
3452 -- Process a potential chain of parent units which ends with the
3453 -- main unit spec. The traversal can now safely rely on the scope
3454 -- chain.
3456 Par_Id := Scope (Defining_Entity (Unt));
3457 while Present (Par_Id) and then Par_Id /= Standard_Standard loop
3458 Find_Elaboration_Context (Compilation_Unit (Par_Id));
3460 Par_Id := Scope (Par_Id);
3461 end loop;
3462 end if;
3463 end Find_Elaborated_Units;
3465 -----------------------------
3466 -- Find_Enclosing_Instance --
3467 -----------------------------
3469 function Find_Enclosing_Instance (N : Node_Id) return Node_Id is
3470 Par : Node_Id;
3471 Spec_Id : Entity_Id;
3473 begin
3474 -- Climb the parent chain looking for an enclosing instance spec or body
3476 Par := N;
3477 while Present (Par) loop
3479 -- Generic package or subprogram spec
3481 if Nkind_In (Par, N_Package_Declaration,
3482 N_Subprogram_Declaration)
3483 and then Is_Generic_Instance (Defining_Entity (Par))
3484 then
3485 return Par;
3487 -- Generic package or subprogram body
3489 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
3490 Spec_Id := Corresponding_Spec (Par);
3492 if Present (Spec_Id) and then Is_Generic_Instance (Spec_Id) then
3493 return Par;
3494 end if;
3495 end if;
3497 Par := Parent (Par);
3498 end loop;
3500 return Empty;
3501 end Find_Enclosing_Instance;
3503 --------------------------
3504 -- Find_Enclosing_Level --
3505 --------------------------
3507 function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind is
3508 function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind;
3509 -- Obtain the corresponding level of unit Unit
3511 --------------
3512 -- Level_Of --
3513 --------------
3515 function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind is
3516 Spec_Id : Entity_Id;
3518 begin
3519 if Nkind (Unit) in N_Generic_Instantiation then
3520 return Instantiation;
3522 elsif Nkind (Unit) = N_Generic_Package_Declaration then
3523 return Generic_Package_Spec;
3525 elsif Nkind (Unit) = N_Package_Declaration then
3526 return Package_Spec;
3528 elsif Nkind (Unit) = N_Package_Body then
3529 Spec_Id := Corresponding_Spec (Unit);
3531 -- The body belongs to a generic package
3533 if Present (Spec_Id)
3534 and then Ekind (Spec_Id) = E_Generic_Package
3535 then
3536 return Generic_Package_Body;
3538 -- Otherwise the body belongs to a non-generic package. This also
3539 -- treats an illegal package body without a corresponding spec as
3540 -- a non-generic package body.
3542 else
3543 return Package_Body;
3544 end if;
3545 end if;
3547 return No_Level;
3548 end Level_Of;
3550 -- Local variables
3552 Context : Node_Id;
3553 Curr : Node_Id;
3554 Prev : Node_Id;
3556 -- Start of processing for Find_Enclosing_Level
3558 begin
3559 -- Call markers and instantiations which appear at the declaration level
3560 -- but are later relocated in a different context retain their original
3561 -- declaration level.
3563 if Nkind_In (N, N_Call_Marker,
3564 N_Function_Instantiation,
3565 N_Package_Instantiation,
3566 N_Procedure_Instantiation)
3567 and then Is_Declaration_Level_Node (N)
3568 then
3569 return Declaration_Level;
3570 end if;
3572 -- Climb the parent chain looking at the enclosing levels
3574 Prev := N;
3575 Curr := Parent (Prev);
3576 while Present (Curr) loop
3578 -- A traversal from a subunit continues via the corresponding stub
3580 if Nkind (Curr) = N_Subunit then
3581 Curr := Corresponding_Stub (Curr);
3583 -- The current construct is a package. Packages are ignored because
3584 -- they are always elaborated when the enclosing context is invoked
3585 -- or elaborated.
3587 elsif Nkind_In (Curr, N_Package_Body, N_Package_Declaration) then
3588 null;
3590 -- The current construct is a block statement
3592 elsif Nkind (Curr) = N_Block_Statement then
3594 -- Ignore internally generated blocks created by the expander for
3595 -- various purposes such as abort defer/undefer.
3597 if not Comes_From_Source (Curr) then
3598 null;
3600 -- If the traversal came from the handled sequence of statments,
3601 -- then the node appears at the level of the enclosing construct.
3602 -- This is a more reliable test because transients scopes within
3603 -- the declarative region of the encapsulator are hard to detect.
3605 elsif Nkind (Prev) = N_Handled_Sequence_Of_Statements
3606 and then Handled_Statement_Sequence (Curr) = Prev
3607 then
3608 return Find_Enclosing_Level (Parent (Curr));
3610 -- Otherwise the traversal came from the declarations, the node is
3611 -- at the declaration level.
3613 else
3614 return Declaration_Level;
3615 end if;
3617 -- The current construct is a declaration-level encapsulator
3619 elsif Nkind_In (Curr, N_Entry_Body,
3620 N_Subprogram_Body,
3621 N_Task_Body)
3622 then
3623 -- If the traversal came from the handled sequence of statments,
3624 -- then the node cannot possibly appear at any level. This is
3625 -- a more reliable test because transients scopes within the
3626 -- declarative region of the encapsulator are hard to detect.
3628 if Nkind (Prev) = N_Handled_Sequence_Of_Statements
3629 and then Handled_Statement_Sequence (Curr) = Prev
3630 then
3631 return No_Level;
3633 -- Otherwise the traversal came from the declarations, the node is
3634 -- at the declaration level.
3636 else
3637 return Declaration_Level;
3638 end if;
3640 -- The current construct is a non-library-level encapsulator which
3641 -- indicates that the node cannot possibly appear at any level.
3642 -- Note that this check must come after the declaration-level check
3643 -- because both predicates share certain nodes.
3645 elsif Is_Non_Library_Level_Encapsulator (Curr) then
3646 Context := Parent (Curr);
3648 -- The sole exception is when the encapsulator is the compilation
3649 -- utit itself because the compilation unit node requires special
3650 -- processing (see below).
3652 if Present (Context)
3653 and then Nkind (Context) = N_Compilation_Unit
3654 then
3655 null;
3657 -- Otherwise the node is not at any level
3659 else
3660 return No_Level;
3661 end if;
3663 -- The current construct is a compilation unit. The node appears at
3664 -- the [generic] library level when the unit is a [generic] package.
3666 elsif Nkind (Curr) = N_Compilation_Unit then
3667 return Level_Of (Unit (Curr));
3668 end if;
3670 Prev := Curr;
3671 Curr := Parent (Prev);
3672 end loop;
3674 return No_Level;
3675 end Find_Enclosing_Level;
3677 -------------------
3678 -- Find_Top_Unit --
3679 -------------------
3681 function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id is
3682 begin
3683 return Find_Unit_Entity (Unit (Cunit (Get_Top_Level_Code_Unit (N))));
3684 end Find_Top_Unit;
3686 ----------------------
3687 -- Find_Unit_Entity --
3688 ----------------------
3690 function Find_Unit_Entity (N : Node_Id) return Entity_Id is
3691 Context : constant Node_Id := Parent (N);
3692 Orig_N : constant Node_Id := Original_Node (N);
3694 begin
3695 -- The unit denotes a package body of an instantiation which acts as
3696 -- a compilation unit. The proper entity is that of the package spec.
3698 if Nkind (N) = N_Package_Body
3699 and then Nkind (Orig_N) = N_Package_Instantiation
3700 and then Nkind (Context) = N_Compilation_Unit
3701 then
3702 return Corresponding_Spec (N);
3704 -- The unit denotes an anonymous package created to wrap a subprogram
3705 -- instantiation which acts as a compilation unit. The proper entity is
3706 -- that of the "related instance".
3708 elsif Nkind (N) = N_Package_Declaration
3709 and then Nkind_In (Orig_N, N_Function_Instantiation,
3710 N_Procedure_Instantiation)
3711 and then Nkind (Context) = N_Compilation_Unit
3712 then
3713 return
3714 Related_Instance (Defining_Entity (N, Concurrent_Subunit => True));
3716 -- Otherwise the proper entity is the defining entity
3718 else
3719 return Defining_Entity (N, Concurrent_Subunit => True);
3720 end if;
3721 end Find_Unit_Entity;
3723 -----------------------
3724 -- First_Formal_Type --
3725 -----------------------
3727 function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id is
3728 Formal_Id : constant Entity_Id := First_Formal (Subp_Id);
3729 Typ : Entity_Id;
3731 begin
3732 if Present (Formal_Id) then
3733 Typ := Etype (Formal_Id);
3735 -- Handle various combinations of concurrent and private types
3737 loop
3738 if Ekind_In (Typ, E_Protected_Type, E_Task_Type)
3739 and then Present (Anonymous_Object (Typ))
3740 then
3741 Typ := Anonymous_Object (Typ);
3743 elsif Is_Concurrent_Record_Type (Typ) then
3744 Typ := Corresponding_Concurrent_Type (Typ);
3746 elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
3747 Typ := Full_View (Typ);
3749 else
3750 exit;
3751 end if;
3752 end loop;
3754 return Typ;
3755 end if;
3757 return Empty;
3758 end First_Formal_Type;
3760 --------------
3761 -- Has_Body --
3762 --------------
3764 function Has_Body (Pack_Decl : Node_Id) return Boolean is
3765 function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id;
3766 -- Try to locate the corresponding body of spec Spec_Id. If no body is
3767 -- found, return Empty.
3769 function Find_Body
3770 (Spec_Id : Entity_Id;
3771 From : Node_Id) return Node_Id;
3772 -- Try to locate the corresponding body of spec Spec_Id in the node list
3773 -- which follows arbitrary node From. If no body is found, return Empty.
3775 function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id;
3776 -- Attempt to load the body of unit Unit_Nam. If the load failed, return
3777 -- Empty. If the compilation will not generate code, return Empty.
3779 -----------------------------
3780 -- Find_Corresponding_Body --
3781 -----------------------------
3783 function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id is
3784 Context : constant Entity_Id := Scope (Spec_Id);
3785 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
3786 Body_Decl : Node_Id;
3787 Body_Id : Entity_Id;
3789 begin
3790 if Is_Compilation_Unit (Spec_Id) then
3791 Body_Id := Corresponding_Body (Spec_Decl);
3793 if Present (Body_Id) then
3794 return Unit_Declaration_Node (Body_Id);
3796 -- The package is at the library and requires a body. Load the
3797 -- corresponding body because the optional body may be declared
3798 -- there.
3800 elsif Unit_Requires_Body (Spec_Id) then
3801 return
3802 Load_Package_Body
3803 (Get_Body_Name (Unit_Name (Get_Source_Unit (Spec_Decl))));
3805 -- Otherwise there is no optional body
3807 else
3808 return Empty;
3809 end if;
3811 -- The immediate context is a package. The optional body may be
3812 -- within the body of that package.
3814 -- procedure Proc is
3815 -- package Nested_1 is
3816 -- package Nested_2 is
3817 -- generic
3818 -- package Pack is
3819 -- end Pack;
3820 -- end Nested_2;
3821 -- end Nested_1;
3823 -- package body Nested_1 is
3824 -- package body Nested_2 is separate;
3825 -- end Nested_1;
3827 -- separate (Proc.Nested_1.Nested_2)
3828 -- package body Nested_2 is
3829 -- package body Pack is -- optional body
3830 -- ...
3831 -- end Pack;
3832 -- end Nested_2;
3834 elsif Is_Package_Or_Generic_Package (Context) then
3835 Body_Decl := Find_Corresponding_Body (Context);
3837 -- The optional body is within the body of the enclosing package
3839 if Present (Body_Decl) then
3840 return
3841 Find_Body
3842 (Spec_Id => Spec_Id,
3843 From => First (Declarations (Body_Decl)));
3845 -- Otherwise the enclosing package does not have a body. This may
3846 -- be the result of an error or a genuine lack of a body.
3848 else
3849 return Empty;
3850 end if;
3852 -- Otherwise the immediate context is a body. The optional body may
3853 -- be within the same list as the spec.
3855 -- procedure Proc is
3856 -- generic
3857 -- package Pack is
3858 -- end Pack;
3860 -- package body Pack is -- optional body
3861 -- ...
3862 -- end Pack;
3864 else
3865 return
3866 Find_Body
3867 (Spec_Id => Spec_Id,
3868 From => Next (Spec_Decl));
3869 end if;
3870 end Find_Corresponding_Body;
3872 ---------------
3873 -- Find_Body --
3874 ---------------
3876 function Find_Body
3877 (Spec_Id : Entity_Id;
3878 From : Node_Id) return Node_Id
3880 Spec_Nam : constant Name_Id := Chars (Spec_Id);
3881 Item : Node_Id;
3882 Lib_Unit : Node_Id;
3884 begin
3885 Item := From;
3886 while Present (Item) loop
3888 -- The current item denotes the optional body
3890 if Nkind (Item) = N_Package_Body
3891 and then Chars (Defining_Entity (Item)) = Spec_Nam
3892 then
3893 return Item;
3895 -- The current item denotes a stub, the optional body may be in
3896 -- the subunit.
3898 elsif Nkind (Item) = N_Package_Body_Stub
3899 and then Chars (Defining_Entity (Item)) = Spec_Nam
3900 then
3901 Lib_Unit := Library_Unit (Item);
3903 -- The corresponding subunit was previously loaded
3905 if Present (Lib_Unit) then
3906 return Lib_Unit;
3908 -- Otherwise attempt to load the corresponding subunit
3910 else
3911 return Load_Package_Body (Get_Unit_Name (Item));
3912 end if;
3913 end if;
3915 Next (Item);
3916 end loop;
3918 return Empty;
3919 end Find_Body;
3921 -----------------------
3922 -- Load_Package_Body --
3923 -----------------------
3925 function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id is
3926 Body_Decl : Node_Id;
3927 Unit_Num : Unit_Number_Type;
3929 begin
3930 -- The load is performed only when the compilation will generate code
3932 if Operating_Mode = Generate_Code then
3933 Unit_Num :=
3934 Load_Unit
3935 (Load_Name => Unit_Nam,
3936 Required => False,
3937 Subunit => False,
3938 Error_Node => Pack_Decl);
3940 -- The load failed most likely because the physical file is
3941 -- missing.
3943 if Unit_Num = No_Unit then
3944 return Empty;
3946 -- Otherwise the load was successful, return the body of the unit
3948 else
3949 Body_Decl := Unit (Cunit (Unit_Num));
3951 -- If the unit is a subunit with an available proper body,
3952 -- return the proper body.
3954 if Nkind (Body_Decl) = N_Subunit
3955 and then Present (Proper_Body (Body_Decl))
3956 then
3957 Body_Decl := Proper_Body (Body_Decl);
3958 end if;
3960 return Body_Decl;
3961 end if;
3962 end if;
3964 return Empty;
3965 end Load_Package_Body;
3967 -- Local variables
3969 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
3971 -- Start of processing for Has_Body
3973 begin
3974 -- The body is available
3976 if Present (Corresponding_Body (Pack_Decl)) then
3977 return True;
3979 -- The body is required if the package spec contains a construct which
3980 -- requires a completion in a body.
3982 elsif Unit_Requires_Body (Pack_Id) then
3983 return True;
3985 -- The body may be optional
3987 else
3988 return Present (Find_Corresponding_Body (Pack_Id));
3989 end if;
3990 end Has_Body;
3992 ---------------------------
3993 -- Has_Prior_Elaboration --
3994 ---------------------------
3996 function Has_Prior_Elaboration
3997 (Unit_Id : Entity_Id;
3998 Context_OK : Boolean := False;
3999 Elab_Body_OK : Boolean := False;
4000 Same_Unit_OK : Boolean := False) return Boolean
4002 Main_Id : constant Entity_Id := Cunit_Entity (Main_Unit);
4004 begin
4005 -- A preelaborated unit is always elaborated prior to the main unit
4007 if Is_Preelaborated_Unit (Unit_Id) then
4008 return True;
4010 -- An internal unit is always elaborated prior to a non-internal main
4011 -- unit.
4013 elsif In_Internal_Unit (Unit_Id)
4014 and then not In_Internal_Unit (Main_Id)
4015 then
4016 return True;
4018 -- A unit has prior elaboration if it appears within the context of the
4019 -- main unit. Consider this case only when requested by the caller.
4021 elsif Context_OK
4022 and then Elaboration_Context.Get (Unit_Id) /= No_Elaboration_Attributes
4023 then
4024 return True;
4026 -- A unit whose body is elaborated together with its spec has prior
4027 -- elaboration except with respect to itself. Consider this case only
4028 -- when requested by the caller.
4030 elsif Elab_Body_OK
4031 and then Has_Pragma_Elaborate_Body (Unit_Id)
4032 and then not Is_Same_Unit (Unit_Id, Main_Id)
4033 then
4034 return True;
4036 -- A unit has no prior elaboration with respect to itself, but does not
4037 -- require any means of ensuring its own elaboration either. Treat this
4038 -- case as valid prior elaboration only when requested by the caller.
4040 elsif Same_Unit_OK and then Is_Same_Unit (Unit_Id, Main_Id) then
4041 return True;
4042 end if;
4044 return False;
4045 end Has_Prior_Elaboration;
4047 --------------------------
4048 -- In_External_Instance --
4049 --------------------------
4051 function In_External_Instance
4052 (N : Node_Id;
4053 Target_Decl : Node_Id) return Boolean
4055 Dummy : Node_Id;
4056 Inst_Body : Node_Id;
4057 Inst_Decl : Node_Id;
4059 begin
4060 -- Performance note: parent traversal
4062 Inst_Decl := Find_Enclosing_Instance (Target_Decl);
4064 -- The target declaration appears within an instance spec. Visibility is
4065 -- ignored because internally generated primitives for private types may
4066 -- reside in the private declarations and still be invoked from outside.
4068 if Present (Inst_Decl)
4069 and then Nkind (Inst_Decl) = N_Package_Declaration
4070 then
4071 -- The scenario comes from the main unit and the instance does not
4073 if In_Extended_Main_Code_Unit (N)
4074 and then not In_Extended_Main_Code_Unit (Inst_Decl)
4075 then
4076 return True;
4078 -- Otherwise the scenario must not appear within the instance spec or
4079 -- body.
4081 else
4082 Extract_Instance_Attributes
4083 (Exp_Inst => Inst_Decl,
4084 Inst_Body => Inst_Body,
4085 Inst_Decl => Dummy);
4087 -- Performance note: parent traversal
4089 return not In_Subtree
4090 (N => N,
4091 Root1 => Inst_Decl,
4092 Root2 => Inst_Body);
4093 end if;
4094 end if;
4096 return False;
4097 end In_External_Instance;
4099 ---------------------
4100 -- In_Main_Context --
4101 ---------------------
4103 function In_Main_Context (N : Node_Id) return Boolean is
4104 begin
4105 -- Scenarios outside the main unit are not considered because the ALI
4106 -- information supplied to binde is for the main unit only.
4108 if not In_Extended_Main_Code_Unit (N) then
4109 return False;
4111 -- Scenarios within internal units are not considered unless switch
4112 -- -gnatdE (elaboration checks on predefined units) is in effect.
4114 elsif not Debug_Flag_EE and then In_Internal_Unit (N) then
4115 return False;
4116 end if;
4118 return True;
4119 end In_Main_Context;
4121 ---------------------
4122 -- In_Same_Context --
4123 ---------------------
4125 function In_Same_Context
4126 (N1 : Node_Id;
4127 N2 : Node_Id;
4128 Nested_OK : Boolean := False) return Boolean
4130 function Find_Enclosing_Context (N : Node_Id) return Node_Id;
4131 -- Return the nearest enclosing non-library-level or compilation unit
4132 -- node which which encapsulates arbitrary node N. Return Empty is no
4133 -- such context is available.
4135 function In_Nested_Context
4136 (Outer : Node_Id;
4137 Inner : Node_Id) return Boolean;
4138 -- Determine whether arbitrary node Outer encapsulates arbitrary node
4139 -- Inner.
4141 ----------------------------
4142 -- Find_Enclosing_Context --
4143 ----------------------------
4145 function Find_Enclosing_Context (N : Node_Id) return Node_Id is
4146 Context : Node_Id;
4147 Par : Node_Id;
4149 begin
4150 Par := Parent (N);
4151 while Present (Par) loop
4153 -- A traversal from a subunit continues via the corresponding stub
4155 if Nkind (Par) = N_Subunit then
4156 Par := Corresponding_Stub (Par);
4158 -- Stop the traversal when the nearest enclosing non-library level
4159 -- encapsulator has been reached.
4161 elsif Is_Non_Library_Level_Encapsulator (Par) then
4162 Context := Parent (Par);
4164 -- The sole exception is when the encapsulator is the unit of
4165 -- compilation because this case requires special processing
4166 -- (see below).
4168 if Present (Context)
4169 and then Nkind (Context) = N_Compilation_Unit
4170 then
4171 null;
4173 else
4174 return Par;
4175 end if;
4177 -- Reaching a compilation unit node without hitting a non-library-
4178 -- level encapsulator indicates that N is at the library level in
4179 -- which case the compilation unit is the context.
4181 elsif Nkind (Par) = N_Compilation_Unit then
4182 return Par;
4183 end if;
4185 Par := Parent (Par);
4186 end loop;
4188 return Empty;
4189 end Find_Enclosing_Context;
4191 -----------------------
4192 -- In_Nested_Context --
4193 -----------------------
4195 function In_Nested_Context
4196 (Outer : Node_Id;
4197 Inner : Node_Id) return Boolean
4199 Par : Node_Id;
4201 begin
4202 Par := Inner;
4203 while Present (Par) loop
4205 -- A traversal from a subunit continues via the corresponding stub
4207 if Nkind (Par) = N_Subunit then
4208 Par := Corresponding_Stub (Par);
4210 elsif Par = Outer then
4211 return True;
4212 end if;
4214 Par := Parent (Par);
4215 end loop;
4217 return False;
4218 end In_Nested_Context;
4220 -- Local variables
4222 Context_1 : constant Node_Id := Find_Enclosing_Context (N1);
4223 Context_2 : constant Node_Id := Find_Enclosing_Context (N2);
4225 -- Start of processing for In_Same_Context
4227 begin
4228 -- Both nodes appear within the same context
4230 if Context_1 = Context_2 then
4231 return True;
4233 -- Both nodes appear in compilation units. Determine whether one unit
4234 -- is the body of the other.
4236 elsif Nkind (Context_1) = N_Compilation_Unit
4237 and then Nkind (Context_2) = N_Compilation_Unit
4238 then
4239 return
4240 Is_Same_Unit
4241 (Unit_1 => Defining_Entity (Unit (Context_1)),
4242 Unit_2 => Defining_Entity (Unit (Context_2)));
4244 -- The context of N1 encloses the context of N2
4246 elsif Nested_OK and then In_Nested_Context (Context_1, Context_2) then
4247 return True;
4248 end if;
4250 return False;
4251 end In_Same_Context;
4253 ----------------
4254 -- Initialize --
4255 ----------------
4257 procedure Initialize is
4258 begin
4259 -- Set the soft link which enables Atree.Rewrite to update a top-level
4260 -- scenario each time it is transformed into another node.
4262 Set_Rewriting_Proc (Update_Elaboration_Scenario'Access);
4263 end Initialize;
4265 ---------------
4266 -- Info_Call --
4267 ---------------
4269 procedure Info_Call
4270 (Call : Node_Id;
4271 Target_Id : Entity_Id;
4272 Info_Msg : Boolean;
4273 In_SPARK : Boolean)
4275 procedure Info_Accept_Alternative;
4276 pragma Inline (Info_Accept_Alternative);
4277 -- Output information concerning an accept alternative
4279 procedure Info_Simple_Call;
4280 pragma Inline (Info_Simple_Call);
4281 -- Output information concerning the call
4283 procedure Info_Type_Actions (Action : String);
4284 pragma Inline (Info_Type_Actions);
4285 -- Output information concerning action Action of a type
4287 procedure Info_Verification_Call
4288 (Pred : String;
4289 Id : Entity_Id;
4290 Id_Kind : String);
4291 pragma Inline (Info_Verification_Call);
4292 -- Output information concerning the verification of predicate Pred
4293 -- applied to related entity Id with kind Id_Kind.
4295 -----------------------------
4296 -- Info_Accept_Alternative --
4297 -----------------------------
4299 procedure Info_Accept_Alternative is
4300 Entry_Id : constant Entity_Id := Receiving_Entry (Target_Id);
4302 begin
4303 pragma Assert (Present (Entry_Id));
4305 Elab_Msg_NE
4306 (Msg => "accept for entry & during elaboration",
4307 N => Call,
4308 Id => Entry_Id,
4309 Info_Msg => Info_Msg,
4310 In_SPARK => In_SPARK);
4311 end Info_Accept_Alternative;
4313 ----------------------
4314 -- Info_Simple_Call --
4315 ----------------------
4317 procedure Info_Simple_Call is
4318 begin
4319 Elab_Msg_NE
4320 (Msg => "call to & during elaboration",
4321 N => Call,
4322 Id => Target_Id,
4323 Info_Msg => Info_Msg,
4324 In_SPARK => In_SPARK);
4325 end Info_Simple_Call;
4327 -----------------------
4328 -- Info_Type_Actions --
4329 -----------------------
4331 procedure Info_Type_Actions (Action : String) is
4332 Typ : constant Entity_Id := First_Formal_Type (Target_Id);
4334 begin
4335 pragma Assert (Present (Typ));
4337 Elab_Msg_NE
4338 (Msg => Action & " actions for type & during elaboration",
4339 N => Call,
4340 Id => Typ,
4341 Info_Msg => Info_Msg,
4342 In_SPARK => In_SPARK);
4343 end Info_Type_Actions;
4345 ----------------------------
4346 -- Info_Verification_Call --
4347 ----------------------------
4349 procedure Info_Verification_Call
4350 (Pred : String;
4351 Id : Entity_Id;
4352 Id_Kind : String)
4354 begin
4355 pragma Assert (Present (Id));
4357 Elab_Msg_NE
4358 (Msg =>
4359 "verification of " & Pred & " of " & Id_Kind & " & during "
4360 & "elaboration",
4361 N => Call,
4362 Id => Id,
4363 Info_Msg => Info_Msg,
4364 In_SPARK => In_SPARK);
4365 end Info_Verification_Call;
4367 -- Start of processing for Info_Call
4369 begin
4370 -- Do not output anything for targets defined in internal units because
4371 -- this creates noise.
4373 if not In_Internal_Unit (Target_Id) then
4375 -- Accept alternative
4377 if Is_Accept_Alternative_Proc (Target_Id) then
4378 Info_Accept_Alternative;
4380 -- Adjustment
4382 elsif Is_TSS (Target_Id, TSS_Deep_Adjust) then
4383 Info_Type_Actions ("adjustment");
4385 -- Default_Initial_Condition
4387 elsif Is_Default_Initial_Condition_Proc (Target_Id) then
4388 Info_Verification_Call
4389 (Pred => "Default_Initial_Condition",
4390 Id => First_Formal_Type (Target_Id),
4391 Id_Kind => "type");
4393 -- Entries
4395 elsif Is_Protected_Entry (Target_Id) then
4396 Info_Simple_Call;
4398 -- Task entry calls are never processed because the entry being
4399 -- invoked does not have a corresponding "body", it has a select.
4401 elsif Is_Task_Entry (Target_Id) then
4402 null;
4404 -- Finalization
4406 elsif Is_TSS (Target_Id, TSS_Deep_Finalize) then
4407 Info_Type_Actions ("finalization");
4409 -- Calls to _Finalizer procedures must not appear in the output
4410 -- because this creates confusing noise.
4412 elsif Is_Finalizer_Proc (Target_Id) then
4413 null;
4415 -- Initial_Condition
4417 elsif Is_Initial_Condition_Proc (Target_Id) then
4418 Info_Verification_Call
4419 (Pred => "Initial_Condition",
4420 Id => Find_Enclosing_Scope (Call),
4421 Id_Kind => "package");
4423 -- Initialization
4425 elsif Is_Init_Proc (Target_Id)
4426 or else Is_TSS (Target_Id, TSS_Deep_Initialize)
4427 then
4428 Info_Type_Actions ("initialization");
4430 -- Invariant
4432 elsif Is_Invariant_Proc (Target_Id) then
4433 Info_Verification_Call
4434 (Pred => "invariants",
4435 Id => First_Formal_Type (Target_Id),
4436 Id_Kind => "type");
4438 -- Partial invariant calls must not appear in the output because this
4439 -- creates confusing noise.
4441 elsif Is_Partial_Invariant_Proc (Target_Id) then
4442 null;
4444 -- _Postconditions
4446 elsif Is_Postconditions_Proc (Target_Id) then
4447 Info_Verification_Call
4448 (Pred => "postconditions",
4449 Id => Find_Enclosing_Scope (Call),
4450 Id_Kind => "subprogram");
4452 -- Subprograms must come last because some of the previous cases fall
4453 -- under this category.
4455 elsif Ekind (Target_Id) = E_Function then
4456 Info_Simple_Call;
4458 elsif Ekind (Target_Id) = E_Procedure then
4459 Info_Simple_Call;
4461 else
4462 pragma Assert (False);
4463 null;
4464 end if;
4465 end if;
4466 end Info_Call;
4468 ------------------------
4469 -- Info_Instantiation --
4470 ------------------------
4472 procedure Info_Instantiation
4473 (Inst : Node_Id;
4474 Gen_Id : Entity_Id;
4475 Info_Msg : Boolean;
4476 In_SPARK : Boolean)
4478 begin
4479 Elab_Msg_NE
4480 (Msg => "instantiation of & during elaboration",
4481 N => Inst,
4482 Id => Gen_Id,
4483 Info_Msg => Info_Msg,
4484 In_SPARK => In_SPARK);
4485 end Info_Instantiation;
4487 -----------------------------
4488 -- Info_Variable_Reference --
4489 -----------------------------
4491 procedure Info_Variable_Reference
4492 (Ref : Node_Id;
4493 Var_Id : Entity_Id;
4494 Info_Msg : Boolean;
4495 In_SPARK : Boolean)
4497 begin
4498 if Is_Read (Ref) then
4499 Elab_Msg_NE
4500 (Msg => "read of variable & during elaboration",
4501 N => Ref,
4502 Id => Var_Id,
4503 Info_Msg => Info_Msg,
4504 In_SPARK => In_SPARK);
4505 end if;
4506 end Info_Variable_Reference;
4508 --------------------
4509 -- Insertion_Node --
4510 --------------------
4512 function Insertion_Node (N : Node_Id; Ins_Nod : Node_Id) return Node_Id is
4513 begin
4514 -- When the scenario denotes an instantiation, the proper insertion node
4515 -- is the instance spec. This ensures that the generic actuals will not
4516 -- be evaluated prior to a potential ABE.
4518 if Nkind (N) in N_Generic_Instantiation
4519 and then Present (Instance_Spec (N))
4520 then
4521 return Instance_Spec (N);
4523 -- Otherwise the proper insertion node is the candidate insertion node
4525 else
4526 return Ins_Nod;
4527 end if;
4528 end Insertion_Node;
4530 -----------------------
4531 -- Install_ABE_Check --
4532 -----------------------
4534 procedure Install_ABE_Check
4535 (N : Node_Id;
4536 Id : Entity_Id;
4537 Ins_Nod : Node_Id)
4539 Check_Ins_Nod : constant Node_Id := Insertion_Node (N, Ins_Nod);
4540 -- Insert the check prior to this node
4542 Loc : constant Source_Ptr := Sloc (N);
4543 Spec_Id : constant Entity_Id := Unique_Entity (Id);
4544 Unit_Id : constant Entity_Id := Find_Top_Unit (Id);
4545 Scop_Id : Entity_Id;
4547 begin
4548 -- Nothing to do when compiling for GNATprove because raise statements
4549 -- are not supported.
4551 if GNATprove_Mode then
4552 return;
4554 -- Nothing to do when the compilation will not produce an executable
4556 elsif Serious_Errors_Detected > 0 then
4557 return;
4559 -- Nothing to do for a compilation unit because there is no executable
4560 -- environment at that level.
4562 elsif Nkind (Parent (Check_Ins_Nod)) = N_Compilation_Unit then
4563 return;
4565 -- Nothing to do when the unit is elaborated prior to the main unit.
4566 -- This check must also consider the following cases:
4568 -- * Id's unit appears in the context of the main unit
4570 -- * Id's unit is subject to pragma Elaborate_Body. An ABE check MUST
4571 -- NOT be generated because Id's unit is always elaborated prior to
4572 -- the main unit.
4574 -- * Id's unit is the main unit. An ABE check MUST be generated in this
4575 -- case because a conditional ABE may be raised depending on the flow
4576 -- of execution within the main unit (flag Same_Unit_OK is False).
4578 elsif Has_Prior_Elaboration
4579 (Unit_Id => Unit_Id,
4580 Context_OK => True,
4581 Elab_Body_OK => True)
4582 then
4583 return;
4584 end if;
4586 -- Prevent multiple scenarios from installing the same ABE check
4588 Set_Is_Elaboration_Checks_OK_Node (N, False);
4590 -- Install the nearest enclosing scope of the scenario as there must be
4591 -- something on the scope stack.
4593 -- Performance note: parent traversal
4595 Scop_Id := Find_Enclosing_Scope (Check_Ins_Nod);
4596 pragma Assert (Present (Scop_Id));
4598 Push_Scope (Scop_Id);
4600 -- Generate:
4601 -- if not Spec_Id'Elaborated then
4602 -- raise Program_Error with "access before elaboration";
4603 -- end if;
4605 Insert_Action (Check_Ins_Nod,
4606 Make_Raise_Program_Error (Loc,
4607 Condition =>
4608 Make_Op_Not (Loc,
4609 Right_Opnd =>
4610 Make_Attribute_Reference (Loc,
4611 Prefix => New_Occurrence_Of (Spec_Id, Loc),
4612 Attribute_Name => Name_Elaborated)),
4613 Reason => PE_Access_Before_Elaboration));
4615 Pop_Scope;
4616 end Install_ABE_Check;
4618 -----------------------
4619 -- Install_ABE_Check --
4620 -----------------------
4622 procedure Install_ABE_Check
4623 (N : Node_Id;
4624 Target_Id : Entity_Id;
4625 Target_Decl : Node_Id;
4626 Target_Body : Node_Id;
4627 Ins_Nod : Node_Id)
4629 procedure Build_Elaboration_Entity;
4630 pragma Inline (Build_Elaboration_Entity);
4631 -- Create a new elaboration flag for Target_Id, insert it prior to
4632 -- Target_Decl, and set it after Body_Decl.
4634 ------------------------------
4635 -- Build_Elaboration_Entity --
4636 ------------------------------
4638 procedure Build_Elaboration_Entity is
4639 Loc : constant Source_Ptr := Sloc (Target_Id);
4640 Flag_Id : Entity_Id;
4642 begin
4643 -- Create the declaration of the elaboration flag. The name carries a
4644 -- unique counter in case of name overloading.
4646 Flag_Id :=
4647 Make_Defining_Identifier (Loc,
4648 Chars => New_External_Name (Chars (Target_Id), 'E', -1));
4650 Set_Elaboration_Entity (Target_Id, Flag_Id);
4651 Set_Elaboration_Entity_Required (Target_Id);
4653 Push_Scope (Scope (Target_Id));
4655 -- Generate:
4656 -- Enn : Short_Integer := 0;
4658 Insert_Action (Target_Decl,
4659 Make_Object_Declaration (Loc,
4660 Defining_Identifier => Flag_Id,
4661 Object_Definition =>
4662 New_Occurrence_Of (Standard_Short_Integer, Loc),
4663 Expression => Make_Integer_Literal (Loc, Uint_0)));
4665 -- Generate:
4666 -- Enn := 1;
4668 Set_Elaboration_Flag (Target_Body, Target_Id);
4670 Pop_Scope;
4671 end Build_Elaboration_Entity;
4673 -- Local variables
4675 Target_Unit_Id : constant Entity_Id := Find_Top_Unit (Target_Id);
4677 -- Start for processing for Install_ABE_Check
4679 begin
4680 -- Nothing to do when compiling for GNATprove because raise statements
4681 -- are not supported.
4683 if GNATprove_Mode then
4684 return;
4686 -- Nothing to do when the compilation will not produce an executable
4688 elsif Serious_Errors_Detected > 0 then
4689 return;
4691 -- Nothing to do when the target is a protected subprogram because the
4692 -- check is associated with the protected body subprogram.
4694 elsif Is_Protected_Subp (Target_Id) then
4695 return;
4697 -- Nothing to do when the target is elaborated prior to the main unit.
4698 -- This check must also consider the following cases:
4700 -- * The unit of the target appears in the context of the main unit
4702 -- * The unit of the target is subject to pragma Elaborate_Body. An ABE
4703 -- check MUST NOT be generated because the unit is always elaborated
4704 -- prior to the main unit.
4706 -- * The unit of the target is the main unit. An ABE check MUST be added
4707 -- in this case because a conditional ABE may be raised depending on
4708 -- the flow of execution within the main unit (flag Same_Unit_OK is
4709 -- False).
4711 elsif Has_Prior_Elaboration
4712 (Unit_Id => Target_Unit_Id,
4713 Context_OK => True,
4714 Elab_Body_OK => True)
4715 then
4716 return;
4718 -- Create an elaboration flag for the target when it does not have one
4720 elsif No (Elaboration_Entity (Target_Id)) then
4721 Build_Elaboration_Entity;
4722 end if;
4724 Install_ABE_Check
4725 (N => N,
4726 Ins_Nod => Ins_Nod,
4727 Id => Target_Id);
4728 end Install_ABE_Check;
4730 -------------------------
4731 -- Install_ABE_Failure --
4732 -------------------------
4734 procedure Install_ABE_Failure (N : Node_Id; Ins_Nod : Node_Id) is
4735 Fail_Ins_Nod : constant Node_Id := Insertion_Node (N, Ins_Nod);
4736 -- Insert the failure prior to this node
4738 Loc : constant Source_Ptr := Sloc (N);
4739 Scop_Id : Entity_Id;
4741 begin
4742 -- Nothing to do when compiling for GNATprove because raise statements
4743 -- are not supported.
4745 if GNATprove_Mode then
4746 return;
4748 -- Nothing to do when the compilation will not produce an executable
4750 elsif Serious_Errors_Detected > 0 then
4751 return;
4753 -- Do not install an ABE check for a compilation unit because there is
4754 -- no executable environment at that level.
4756 elsif Nkind (Parent (Fail_Ins_Nod)) = N_Compilation_Unit then
4757 return;
4758 end if;
4760 -- Prevent multiple scenarios from installing the same ABE failure
4762 Set_Is_Elaboration_Checks_OK_Node (N, False);
4764 -- Install the nearest enclosing scope of the scenario as there must be
4765 -- something on the scope stack.
4767 -- Performance note: parent traversal
4769 Scop_Id := Find_Enclosing_Scope (Fail_Ins_Nod);
4770 pragma Assert (Present (Scop_Id));
4772 Push_Scope (Scop_Id);
4774 -- Generate:
4775 -- raise Program_Error with "access before elaboration";
4777 Insert_Action (Fail_Ins_Nod,
4778 Make_Raise_Program_Error (Loc,
4779 Reason => PE_Access_Before_Elaboration));
4781 Pop_Scope;
4782 end Install_ABE_Failure;
4784 --------------------------------
4785 -- Is_Accept_Alternative_Proc --
4786 --------------------------------
4788 function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean is
4789 begin
4790 -- To qualify, the entity must denote a procedure with a receiving entry
4792 return Ekind (Id) = E_Procedure and then Present (Receiving_Entry (Id));
4793 end Is_Accept_Alternative_Proc;
4795 ------------------------
4796 -- Is_Activation_Proc --
4797 ------------------------
4799 function Is_Activation_Proc (Id : Entity_Id) return Boolean is
4800 begin
4801 -- To qualify, the entity must denote one of the runtime procedures in
4802 -- charge of task activation.
4804 if Ekind (Id) = E_Procedure then
4805 if Restricted_Profile then
4806 return Is_RTE (Id, RE_Activate_Restricted_Tasks);
4807 else
4808 return Is_RTE (Id, RE_Activate_Tasks);
4809 end if;
4810 end if;
4812 return False;
4813 end Is_Activation_Proc;
4815 ----------------------------
4816 -- Is_Ada_Semantic_Target --
4817 ----------------------------
4819 function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean is
4820 begin
4821 return
4822 Is_Activation_Proc (Id)
4823 or else Is_Controlled_Proc (Id, Name_Adjust)
4824 or else Is_Controlled_Proc (Id, Name_Finalize)
4825 or else Is_Controlled_Proc (Id, Name_Initialize)
4826 or else Is_Init_Proc (Id)
4827 or else Is_Invariant_Proc (Id)
4828 or else Is_Protected_Entry (Id)
4829 or else Is_Protected_Subp (Id)
4830 or else Is_Protected_Body_Subp (Id)
4831 or else Is_Task_Entry (Id);
4832 end Is_Ada_Semantic_Target;
4834 ----------------------------
4835 -- Is_Bodiless_Subprogram --
4836 ----------------------------
4838 function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean is
4839 begin
4840 -- An abstract subprogram does not have a body
4842 if Ekind_In (Subp_Id, E_Function,
4843 E_Operator,
4844 E_Procedure)
4845 and then Is_Abstract_Subprogram (Subp_Id)
4846 then
4847 return True;
4849 -- A formal subprogram does not have a body
4851 elsif Is_Formal_Subprogram (Subp_Id) then
4852 return True;
4854 -- An imported subprogram may have a body, however it is not known at
4855 -- compile or bind time where the body resides and whether it will be
4856 -- elaborated on time.
4858 elsif Is_Imported (Subp_Id) then
4859 return True;
4860 end if;
4862 return False;
4863 end Is_Bodiless_Subprogram;
4865 ------------------------
4866 -- Is_Controlled_Proc --
4867 ------------------------
4869 function Is_Controlled_Proc
4870 (Subp_Id : Entity_Id;
4871 Subp_Nam : Name_Id) return Boolean
4873 Formal_Id : Entity_Id;
4875 begin
4876 pragma Assert (Nam_In (Subp_Nam, Name_Adjust,
4877 Name_Finalize,
4878 Name_Initialize));
4880 -- To qualify, the subprogram must denote a source procedure with name
4881 -- Adjust, Finalize, or Initialize where the sole formal is controlled.
4883 if Comes_From_Source (Subp_Id)
4884 and then Ekind (Subp_Id) = E_Procedure
4885 and then Chars (Subp_Id) = Subp_Nam
4886 then
4887 Formal_Id := First_Formal (Subp_Id);
4889 return
4890 Present (Formal_Id)
4891 and then Is_Controlled (Etype (Formal_Id))
4892 and then No (Next_Formal (Formal_Id));
4893 end if;
4895 return False;
4896 end Is_Controlled_Proc;
4898 ---------------------------------------
4899 -- Is_Default_Initial_Condition_Proc --
4900 ---------------------------------------
4902 function Is_Default_Initial_Condition_Proc
4903 (Id : Entity_Id) return Boolean
4905 begin
4906 -- To qualify, the entity must denote a Default_Initial_Condition
4907 -- procedure.
4909 return Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id);
4910 end Is_Default_Initial_Condition_Proc;
4912 -----------------------
4913 -- Is_Finalizer_Proc --
4914 -----------------------
4916 function Is_Finalizer_Proc (Id : Entity_Id) return Boolean is
4917 begin
4918 -- To qualify, the entity must denote a _Finalizer procedure
4920 return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
4921 end Is_Finalizer_Proc;
4923 -----------------------
4924 -- Is_Guaranteed_ABE --
4925 -----------------------
4927 function Is_Guaranteed_ABE
4928 (N : Node_Id;
4929 Target_Decl : Node_Id;
4930 Target_Body : Node_Id) return Boolean
4932 begin
4933 -- Avoid cascaded errors if there were previous serious infractions.
4934 -- As a result the scenario will not be treated as a guaranteed ABE.
4935 -- This behaviour parallels that of the old ABE mechanism.
4937 if Serious_Errors_Detected > 0 then
4938 return False;
4940 -- The scenario and the target appear within the same context ignoring
4941 -- enclosing library levels.
4943 -- Performance note: parent traversal
4945 elsif In_Same_Context (N, Target_Decl) then
4947 -- The target body has already been encountered. The scenario results
4948 -- in a guaranteed ABE if it appears prior to the body.
4950 if Present (Target_Body) then
4951 return Earlier_In_Extended_Unit (N, Target_Body);
4953 -- Otherwise the body has not been encountered yet. The scenario is
4954 -- a guaranteed ABE since the body will appear later. It is assumed
4955 -- that the caller has already checked whether the scenario is ABE-
4956 -- safe as optional bodies are not considered here.
4958 else
4959 return True;
4960 end if;
4961 end if;
4963 return False;
4964 end Is_Guaranteed_ABE;
4966 -------------------------------
4967 -- Is_Initial_Condition_Proc --
4968 -------------------------------
4970 function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean is
4971 begin
4972 -- To qualify, the entity must denote an Initial_Condition procedure
4974 return
4975 Ekind (Id) = E_Procedure and then Is_Initial_Condition_Procedure (Id);
4976 end Is_Initial_Condition_Proc;
4978 --------------------
4979 -- Is_Initialized --
4980 --------------------
4982 function Is_Initialized (Obj_Decl : Node_Id) return Boolean is
4983 begin
4984 -- To qualify, the object declaration must have an expression
4986 return
4987 Present (Expression (Obj_Decl)) or else Has_Init_Expression (Obj_Decl);
4988 end Is_Initialized;
4990 -----------------------
4991 -- Is_Invariant_Proc --
4992 -----------------------
4994 function Is_Invariant_Proc (Id : Entity_Id) return Boolean is
4995 begin
4996 -- To qualify, the entity must denote the "full" invariant procedure
4998 return Ekind (Id) = E_Procedure and then Is_Invariant_Procedure (Id);
4999 end Is_Invariant_Proc;
5001 ---------------------------------------
5002 -- Is_Non_Library_Level_Encapsulator --
5003 ---------------------------------------
5005 function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean is
5006 begin
5007 case Nkind (N) is
5008 when N_Abstract_Subprogram_Declaration
5009 | N_Aspect_Specification
5010 | N_Component_Declaration
5011 | N_Entry_Body
5012 | N_Entry_Declaration
5013 | N_Expression_Function
5014 | N_Formal_Abstract_Subprogram_Declaration
5015 | N_Formal_Concrete_Subprogram_Declaration
5016 | N_Formal_Object_Declaration
5017 | N_Formal_Package_Declaration
5018 | N_Formal_Type_Declaration
5019 | N_Generic_Association
5020 | N_Implicit_Label_Declaration
5021 | N_Incomplete_Type_Declaration
5022 | N_Private_Extension_Declaration
5023 | N_Private_Type_Declaration
5024 | N_Protected_Body
5025 | N_Protected_Type_Declaration
5026 | N_Single_Protected_Declaration
5027 | N_Single_Task_Declaration
5028 | N_Subprogram_Body
5029 | N_Subprogram_Declaration
5030 | N_Task_Body
5031 | N_Task_Type_Declaration
5033 return True;
5035 when others =>
5036 return Is_Generic_Declaration_Or_Body (N);
5037 end case;
5038 end Is_Non_Library_Level_Encapsulator;
5040 -------------------------------
5041 -- Is_Partial_Invariant_Proc --
5042 -------------------------------
5044 function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean is
5045 begin
5046 -- To qualify, the entity must denote the "partial" invariant procedure
5048 return
5049 Ekind (Id) = E_Procedure and then Is_Partial_Invariant_Procedure (Id);
5050 end Is_Partial_Invariant_Proc;
5052 ----------------------------
5053 -- Is_Postconditions_Proc --
5054 ----------------------------
5056 function Is_Postconditions_Proc (Id : Entity_Id) return Boolean is
5057 begin
5058 -- To qualify, the entity must denote a _Postconditions procedure
5060 return
5061 Ekind (Id) = E_Procedure and then Chars (Id) = Name_uPostconditions;
5062 end Is_Postconditions_Proc;
5064 ---------------------------
5065 -- Is_Preelaborated_Unit --
5066 ---------------------------
5068 function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean is
5069 begin
5070 return
5071 Is_Preelaborated (Id)
5072 or else Is_Pure (Id)
5073 or else Is_Remote_Call_Interface (Id)
5074 or else Is_Remote_Types (Id)
5075 or else Is_Shared_Passive (Id);
5076 end Is_Preelaborated_Unit;
5078 ------------------------
5079 -- Is_Protected_Entry --
5080 ------------------------
5082 function Is_Protected_Entry (Id : Entity_Id) return Boolean is
5083 begin
5084 -- To qualify, the entity must denote an entry defined in a protected
5085 -- type.
5087 return
5088 Is_Entry (Id)
5089 and then Is_Protected_Type (Non_Private_View (Scope (Id)));
5090 end Is_Protected_Entry;
5092 -----------------------
5093 -- Is_Protected_Subp --
5094 -----------------------
5096 function Is_Protected_Subp (Id : Entity_Id) return Boolean is
5097 begin
5098 -- To qualify, the entity must denote a subprogram defined within a
5099 -- protected type.
5101 return
5102 Ekind_In (Id, E_Function, E_Procedure)
5103 and then Is_Protected_Type (Non_Private_View (Scope (Id)));
5104 end Is_Protected_Subp;
5106 ----------------------------
5107 -- Is_Protected_Body_Subp --
5108 ----------------------------
5110 function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean is
5111 begin
5112 -- To qualify, the entity must denote a subprogram with attribute
5113 -- Protected_Subprogram set.
5115 return
5116 Ekind_In (Id, E_Function, E_Procedure)
5117 and then Present (Protected_Subprogram (Id));
5118 end Is_Protected_Body_Subp;
5120 ------------------------------------
5121 -- Is_Recorded_Top_Level_Scenario --
5122 ------------------------------------
5124 function Is_Recorded_Top_Level_Scenario (N : Node_Id) return Boolean is
5125 begin
5126 return Recorded_Top_Level_Scenarios.Get (N);
5127 end Is_Recorded_Top_Level_Scenario;
5129 ------------------------
5130 -- Is_Safe_Activation --
5131 ------------------------
5133 function Is_Safe_Activation
5134 (Call : Node_Id;
5135 Task_Decl : Node_Id) return Boolean
5137 begin
5138 -- The activation of a task coming from an external instance cannot
5139 -- cause an ABE because the generic was already instantiated. Note
5140 -- that the instantiation itself may lead to an ABE.
5142 return
5143 In_External_Instance
5144 (N => Call,
5145 Target_Decl => Task_Decl);
5146 end Is_Safe_Activation;
5148 ------------------
5149 -- Is_Safe_Call --
5150 ------------------
5152 function Is_Safe_Call
5153 (Call : Node_Id;
5154 Target_Attrs : Target_Attributes) return Boolean
5156 begin
5157 -- The target is either an abstract subprogram, formal subprogram, or
5158 -- imported, in which case it does not have a body at compile or bind
5159 -- time. Assume that the call is ABE-safe.
5161 if Is_Bodiless_Subprogram (Target_Attrs.Spec_Id) then
5162 return True;
5164 -- The target is an instantiation of a generic subprogram. The call
5165 -- cannot cause an ABE because the generic was already instantiated.
5166 -- Note that the instantiation itself may lead to an ABE.
5168 elsif Is_Generic_Instance (Target_Attrs.Spec_Id) then
5169 return True;
5171 -- The invocation of a target coming from an external instance cannot
5172 -- cause an ABE because the generic was already instantiated. Note that
5173 -- the instantiation itself may lead to an ABE.
5175 elsif In_External_Instance
5176 (N => Call,
5177 Target_Decl => Target_Attrs.Spec_Decl)
5178 then
5179 return True;
5181 -- The target is a subprogram body without a previous declaration. The
5182 -- call cannot cause an ABE because the body has already been seen.
5184 elsif Nkind (Target_Attrs.Spec_Decl) = N_Subprogram_Body
5185 and then No (Corresponding_Spec (Target_Attrs.Spec_Decl))
5186 then
5187 return True;
5189 -- The target is a subprogram body stub without a prior declaration.
5190 -- The call cannot cause an ABE because the proper body substitutes
5191 -- the stub.
5193 elsif Nkind (Target_Attrs.Spec_Decl) = N_Subprogram_Body_Stub
5194 and then No (Corresponding_Spec_Of_Stub (Target_Attrs.Spec_Decl))
5195 then
5196 return True;
5198 -- Subprogram bodies which wrap attribute references used as actuals
5199 -- in instantiations are always ABE-safe. These bodies are artifacts
5200 -- of expansion.
5202 elsif Present (Target_Attrs.Body_Decl)
5203 and then Nkind (Target_Attrs.Body_Decl) = N_Subprogram_Body
5204 and then Was_Attribute_Reference (Target_Attrs.Body_Decl)
5205 then
5206 return True;
5207 end if;
5209 return False;
5210 end Is_Safe_Call;
5212 ---------------------------
5213 -- Is_Safe_Instantiation --
5214 ---------------------------
5216 function Is_Safe_Instantiation
5217 (Inst : Node_Id;
5218 Gen_Attrs : Target_Attributes) return Boolean
5220 begin
5221 -- The generic is an intrinsic subprogram in which case it does not
5222 -- have a body at compile or bind time. Assume that the instantiation
5223 -- is ABE-safe.
5225 if Is_Bodiless_Subprogram (Gen_Attrs.Spec_Id) then
5226 return True;
5228 -- The instantiation of an external nested generic cannot cause an ABE
5229 -- if the outer generic was already instantiated. Note that the instance
5230 -- of the outer generic may lead to an ABE.
5232 elsif In_External_Instance
5233 (N => Inst,
5234 Target_Decl => Gen_Attrs.Spec_Decl)
5235 then
5236 return True;
5238 -- The generic is a package. The instantiation cannot cause an ABE when
5239 -- the package has no body.
5241 elsif Ekind (Gen_Attrs.Spec_Id) = E_Generic_Package
5242 and then not Has_Body (Gen_Attrs.Spec_Decl)
5243 then
5244 return True;
5245 end if;
5247 return False;
5248 end Is_Safe_Instantiation;
5250 ------------------
5251 -- Is_Same_Unit --
5252 ------------------
5254 function Is_Same_Unit
5255 (Unit_1 : Entity_Id;
5256 Unit_2 : Entity_Id) return Boolean
5258 function Is_Subunit (Unit_Id : Entity_Id) return Boolean;
5259 pragma Inline (Is_Subunit);
5260 -- Determine whether unit Unit_Id is a subunit
5262 function Normalize_Unit (Unit_Id : Entity_Id) return Entity_Id;
5263 -- Strip a potential subunit chain ending with unit Unit_Id and return
5264 -- the corresponding spec.
5266 ----------------
5267 -- Is_Subunit --
5268 ----------------
5270 function Is_Subunit (Unit_Id : Entity_Id) return Boolean is
5271 begin
5272 return Nkind (Parent (Unit_Declaration_Node (Unit_Id))) = N_Subunit;
5273 end Is_Subunit;
5275 --------------------
5276 -- Normalize_Unit --
5277 --------------------
5279 function Normalize_Unit (Unit_Id : Entity_Id) return Entity_Id is
5280 Result : Entity_Id;
5282 begin
5283 -- Eliminate a potential chain of subunits to reach to proper body
5285 Result := Unit_Id;
5286 while Present (Result)
5287 and then Result /= Standard_Standard
5288 and then Is_Subunit (Result)
5289 loop
5290 Result := Scope (Result);
5291 end loop;
5293 -- Obtain the entity of the corresponding spec (if any)
5295 return Unique_Entity (Result);
5296 end Normalize_Unit;
5298 -- Start of processing for Is_Same_Unit
5300 begin
5301 return Normalize_Unit (Unit_1) = Normalize_Unit (Unit_2);
5302 end Is_Same_Unit;
5304 -----------------
5305 -- Is_Scenario --
5306 -----------------
5308 function Is_Scenario (N : Node_Id) return Boolean is
5309 begin
5310 case Nkind (N) is
5311 when N_Assignment_Statement
5312 | N_Attribute_Reference
5313 | N_Call_Marker
5314 | N_Entry_Call_Statement
5315 | N_Expanded_Name
5316 | N_Function_Call
5317 | N_Function_Instantiation
5318 | N_Identifier
5319 | N_Package_Instantiation
5320 | N_Procedure_Call_Statement
5321 | N_Procedure_Instantiation
5322 | N_Requeue_Statement
5324 return True;
5326 when others =>
5327 return False;
5328 end case;
5329 end Is_Scenario;
5331 ------------------------------
5332 -- Is_SPARK_Semantic_Target --
5333 ------------------------------
5335 function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean is
5336 begin
5337 return
5338 Is_Default_Initial_Condition_Proc (Id)
5339 or else Is_Initial_Condition_Proc (Id);
5340 end Is_SPARK_Semantic_Target;
5342 ------------------------
5343 -- Is_Suitable_Access --
5344 ------------------------
5346 function Is_Suitable_Access (N : Node_Id) return Boolean is
5347 Nam : Name_Id;
5348 Pref : Node_Id;
5349 Subp_Id : Entity_Id;
5351 begin
5352 -- This scenario is relevant only when the static model is in effect
5353 -- because it is graph-dependent and does not involve any run-time
5354 -- checks. Allowing it in the dynamic model would create confusing
5355 -- noise.
5357 if not Static_Elaboration_Checks then
5358 return False;
5360 -- Nothing to do when switch -gnatd.U (ignore 'Access) is in effect
5362 elsif Debug_Flag_Dot_UU then
5363 return False;
5365 -- Nothing to do when the scenario is not an attribute reference
5367 elsif Nkind (N) /= N_Attribute_Reference then
5368 return False;
5370 -- Nothing to do for internally-generated attributes because they are
5371 -- assumed to be ABE safe.
5373 elsif not Comes_From_Source (N) then
5374 return False;
5375 end if;
5377 Nam := Attribute_Name (N);
5378 Pref := Prefix (N);
5380 -- Sanitize the prefix of the attribute
5382 if not Is_Entity_Name (Pref) then
5383 return False;
5385 elsif No (Entity (Pref)) then
5386 return False;
5387 end if;
5389 Subp_Id := Entity (Pref);
5391 if not Is_Subprogram_Or_Entry (Subp_Id) then
5392 return False;
5393 end if;
5395 -- Traverse a possible chain of renamings to obtain the original entry
5396 -- or subprogram which the prefix may rename.
5398 Subp_Id := Get_Renamed_Entity (Subp_Id);
5400 -- To qualify, the attribute must meet the following prerequisites:
5402 return
5404 -- The prefix must denote a source entry, operator, or subprogram
5405 -- which is not imported.
5407 Comes_From_Source (Subp_Id)
5408 and then Is_Subprogram_Or_Entry (Subp_Id)
5409 and then not Is_Bodiless_Subprogram (Subp_Id)
5411 -- The attribute name must be one of the 'Access forms. Note that
5412 -- 'Unchecked_Access cannot apply to a subprogram.
5414 and then Nam_In (Nam, Name_Access, Name_Unrestricted_Access);
5415 end Is_Suitable_Access;
5417 ----------------------
5418 -- Is_Suitable_Call --
5419 ----------------------
5421 function Is_Suitable_Call (N : Node_Id) return Boolean is
5422 begin
5423 -- Entry and subprogram calls are intentionally ignored because they
5424 -- may undergo expansion depending on the compilation mode, previous
5425 -- errors, generic context, etc. Call markers play the role of calls
5426 -- and provide a uniform foundation for ABE processing.
5428 return Nkind (N) = N_Call_Marker;
5429 end Is_Suitable_Call;
5431 -------------------------------
5432 -- Is_Suitable_Instantiation --
5433 -------------------------------
5435 function Is_Suitable_Instantiation (N : Node_Id) return Boolean is
5436 Orig_N : constant Node_Id := Original_Node (N);
5437 -- Use the original node in case an instantiation library unit is
5438 -- rewritten as a package or subprogram.
5440 begin
5441 -- To qualify, the instantiation must come from source
5443 return
5444 Comes_From_Source (Orig_N)
5445 and then Nkind (Orig_N) in N_Generic_Instantiation;
5446 end Is_Suitable_Instantiation;
5448 --------------------------
5449 -- Is_Suitable_Scenario --
5450 --------------------------
5452 function Is_Suitable_Scenario (N : Node_Id) return Boolean is
5453 begin
5454 return
5455 Is_Suitable_Access (N)
5456 or else Is_Suitable_Call (N)
5457 or else Is_Suitable_Instantiation (N)
5458 or else Is_Suitable_Variable_Assignment (N)
5459 or else Is_Suitable_Variable_Reference (N);
5460 end Is_Suitable_Scenario;
5462 -------------------------------------
5463 -- Is_Suitable_Variable_Assignment --
5464 -------------------------------------
5466 function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean is
5467 N_Unit : Node_Id;
5468 N_Unit_Id : Entity_Id;
5469 Nam : Node_Id;
5470 Var_Decl : Node_Id;
5471 Var_Id : Entity_Id;
5472 Var_Unit : Node_Id;
5473 Var_Unit_Id : Entity_Id;
5475 begin
5476 -- This scenario is relevant only when the static model is in effect
5477 -- because it is graph-dependent and does not involve any run-time
5478 -- checks. Allowing it in the dynamic model would create confusing
5479 -- noise.
5481 if not Static_Elaboration_Checks then
5482 return False;
5484 -- Nothing to do when the scenario is not an assignment
5486 elsif Nkind (N) /= N_Assignment_Statement then
5487 return False;
5489 -- Nothing to do for internally-generated assignments because they are
5490 -- assumed to be ABE safe.
5492 elsif not Comes_From_Source (N) then
5493 return False;
5495 -- Assignments are ignored in GNAT mode on the assumption that they are
5496 -- ABE-safe. This behaviour parallels that of the old ABE mechanism.
5498 elsif GNAT_Mode then
5499 return False;
5500 end if;
5502 Nam := Extract_Assignment_Name (N);
5504 -- Sanitize the left hand side of the assignment
5506 if not Is_Entity_Name (Nam) then
5507 return False;
5509 elsif No (Entity (Nam)) then
5510 return False;
5511 end if;
5513 Var_Id := Entity (Nam);
5515 -- Sanitize the variable
5517 if Var_Id = Any_Id then
5518 return False;
5520 elsif Ekind (Var_Id) /= E_Variable then
5521 return False;
5522 end if;
5524 Var_Decl := Declaration_Node (Var_Id);
5526 if Nkind (Var_Decl) /= N_Object_Declaration then
5527 return False;
5528 end if;
5530 N_Unit_Id := Find_Top_Unit (N);
5531 N_Unit := Unit_Declaration_Node (N_Unit_Id);
5533 Var_Unit_Id := Find_Top_Unit (Var_Decl);
5534 Var_Unit := Unit_Declaration_Node (Var_Unit_Id);
5536 -- To qualify, the assignment must meet the following prerequisites:
5538 return
5539 Comes_From_Source (Var_Id)
5541 -- The variable must be declared in the spec of compilation unit U
5543 and then Nkind (Var_Unit) = N_Package_Declaration
5545 -- Performance note: parent traversal
5547 and then Find_Enclosing_Level (Var_Decl) = Package_Spec
5549 -- The assignment must occur in the body of compilation unit U
5551 and then Nkind (N_Unit) = N_Package_Body
5552 and then Present (Corresponding_Body (Var_Unit))
5553 and then Corresponding_Body (Var_Unit) = N_Unit_Id;
5554 end Is_Suitable_Variable_Assignment;
5556 ------------------------------------
5557 -- Is_Suitable_Variable_Reference --
5558 ------------------------------------
5560 function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean is
5561 begin
5562 -- Expanded names and identifiers are intentionally ignored because they
5563 -- be folded, optimized away, etc. Variable references markers play the
5564 -- role of variable references and provide a uniform foundation for ABE
5565 -- processing.
5567 return Nkind (N) = N_Variable_Reference_Marker;
5568 end Is_Suitable_Variable_Reference;
5570 -------------------
5571 -- Is_Task_Entry --
5572 -------------------
5574 function Is_Task_Entry (Id : Entity_Id) return Boolean is
5575 begin
5576 -- To qualify, the entity must denote an entry defined in a task type
5578 return
5579 Is_Entry (Id) and then Is_Task_Type (Non_Private_View (Scope (Id)));
5580 end Is_Task_Entry;
5582 ------------------------
5583 -- Is_Up_Level_Target --
5584 ------------------------
5586 function Is_Up_Level_Target (Target_Decl : Node_Id) return Boolean is
5587 Root : constant Node_Id := Root_Scenario;
5589 begin
5590 -- The root appears within the declaratons of a block statement, entry
5591 -- body, subprogram body, or task body ignoring enclosing packages. The
5592 -- root is always within the main unit. An up-level target is a notion
5593 -- applicable only to the static model because scenarios are reached by
5594 -- means of graph traversal started from a fixed declarative or library
5595 -- level.
5597 -- Performance note: parent traversal
5599 if Static_Elaboration_Checks
5600 and then Find_Enclosing_Level (Root) = Declaration_Level
5601 then
5602 -- The target is within the main unit. It acts as an up-level target
5603 -- when it appears within a context which encloses the root.
5605 -- package body Main_Unit is
5606 -- function Func ...; -- target
5608 -- procedure Proc is
5609 -- X : ... := Func; -- root scenario
5611 if In_Extended_Main_Code_Unit (Target_Decl) then
5613 -- Performance note: parent traversal
5615 return not In_Same_Context (Root, Target_Decl, Nested_OK => True);
5617 -- Otherwise the target is external to the main unit which makes it
5618 -- an up-level target.
5620 else
5621 return True;
5622 end if;
5623 end if;
5625 return False;
5626 end Is_Up_Level_Target;
5628 -------------------------------
5629 -- Kill_Elaboration_Scenario --
5630 -------------------------------
5632 procedure Kill_Elaboration_Scenario (N : Node_Id) is
5633 package Scenarios renames Top_Level_Scenarios;
5635 begin
5636 -- Eliminate a recorded top-level scenario when it appears within dead
5637 -- code because it will not be executed at elaboration time.
5639 if Is_Scenario (N)
5640 and then Is_Recorded_Top_Level_Scenario (N)
5641 then
5642 -- Performance node: list traversal
5644 for Index in Scenarios.First .. Scenarios.Last loop
5645 if Scenarios.Table (Index) = N then
5646 Scenarios.Table (Index) := Empty;
5648 -- The top-level scenario is no longer recorded
5650 Set_Is_Recorded_Top_Level_Scenario (N, False);
5651 return;
5652 end if;
5653 end loop;
5655 -- A recorded top-level scenario must be in the table of recorded
5656 -- top-level scenarios.
5658 pragma Assert (False);
5659 end if;
5660 end Kill_Elaboration_Scenario;
5662 ----------------------------------
5663 -- Meet_Elaboration_Requirement --
5664 ----------------------------------
5666 procedure Meet_Elaboration_Requirement
5667 (N : Node_Id;
5668 Target_Id : Entity_Id;
5669 Req_Nam : Name_Id)
5671 Main_Id : constant Entity_Id := Cunit_Entity (Main_Unit);
5672 Unit_Id : constant Entity_Id := Find_Top_Unit (Target_Id);
5674 function Find_Preelaboration_Pragma
5675 (Prag_Nam : Name_Id) return Node_Id;
5676 pragma Inline (Find_Preelaboration_Pragma);
5677 -- Traverse the visible declarations of unit Unit_Id and locate a source
5678 -- preelaboration-related pragma with name Prag_Nam.
5680 procedure Info_Requirement_Met (Prag : Node_Id);
5681 pragma Inline (Info_Requirement_Met);
5682 -- Output information concerning pragma Prag which meets requirement
5683 -- Req_Nam.
5685 procedure Info_Scenario;
5686 pragma Inline (Info_Scenario);
5687 -- Output information concerning scenario N
5689 --------------------------------
5690 -- Find_Preelaboration_Pragma --
5691 --------------------------------
5693 function Find_Preelaboration_Pragma
5694 (Prag_Nam : Name_Id) return Node_Id
5696 Spec : constant Node_Id := Parent (Unit_Id);
5697 Decl : Node_Id;
5699 begin
5700 -- A preelaboration-related pragma comes from source and appears at
5701 -- the top of the visible declarations of a package.
5703 if Nkind (Spec) = N_Package_Specification then
5704 Decl := First (Visible_Declarations (Spec));
5705 while Present (Decl) loop
5706 if Comes_From_Source (Decl) then
5707 if Nkind (Decl) = N_Pragma
5708 and then Pragma_Name (Decl) = Prag_Nam
5709 then
5710 return Decl;
5712 -- Otherwise the construct terminates the region where the
5713 -- preelabortion-related pragma may appear.
5715 else
5716 exit;
5717 end if;
5718 end if;
5720 Next (Decl);
5721 end loop;
5722 end if;
5724 return Empty;
5725 end Find_Preelaboration_Pragma;
5727 --------------------------
5728 -- Info_Requirement_Met --
5729 --------------------------
5731 procedure Info_Requirement_Met (Prag : Node_Id) is
5732 begin
5733 pragma Assert (Present (Prag));
5735 Error_Msg_Name_1 := Req_Nam;
5736 Error_Msg_Sloc := Sloc (Prag);
5737 Error_Msg_NE
5738 ("\\% requirement for unit & met by pragma #", N, Unit_Id);
5739 end Info_Requirement_Met;
5741 -------------------
5742 -- Info_Scenario --
5743 -------------------
5745 procedure Info_Scenario is
5746 begin
5747 if Is_Suitable_Call (N) then
5748 Info_Call
5749 (Call => N,
5750 Target_Id => Target_Id,
5751 Info_Msg => False,
5752 In_SPARK => True);
5754 elsif Is_Suitable_Instantiation (N) then
5755 Info_Instantiation
5756 (Inst => N,
5757 Gen_Id => Target_Id,
5758 Info_Msg => False,
5759 In_SPARK => True);
5761 elsif Is_Suitable_Variable_Reference (N) then
5762 Info_Variable_Reference
5763 (Ref => N,
5764 Var_Id => Target_Id,
5765 Info_Msg => False,
5766 In_SPARK => True);
5768 -- No other scenario may impose a requirement on the context of the
5769 -- main unit.
5771 else
5772 pragma Assert (False);
5773 null;
5774 end if;
5775 end Info_Scenario;
5777 -- Local variables
5779 Elab_Attrs : Elaboration_Attributes;
5780 Elab_Nam : Name_Id;
5781 Req_Met : Boolean;
5783 -- Start of processing for Meet_Elaboration_Requirement
5785 begin
5786 pragma Assert (Nam_In (Req_Nam, Name_Elaborate, Name_Elaborate_All));
5788 -- Assume that the requirement has not been met
5790 Req_Met := False;
5792 -- Elaboration requirements are verified only when the static model is
5793 -- in effect because this diagnostic is graph-dependent.
5795 if not Static_Elaboration_Checks then
5796 return;
5798 -- If the target is within the main unit, either at the source level or
5799 -- through an instantiation, then there is no real requirement to meet
5800 -- because the main unit cannot force its own elaboration by means of an
5801 -- Elaborate[_All] pragma. Treat this case as valid coverage.
5803 elsif In_Extended_Main_Code_Unit (Target_Id) then
5804 Req_Met := True;
5806 -- Otherwise the target resides in an external unit
5808 -- The requirement is met when the target comes from an internal unit
5809 -- because such a unit is elaborated prior to a non-internal unit.
5811 elsif In_Internal_Unit (Unit_Id)
5812 and then not In_Internal_Unit (Main_Id)
5813 then
5814 Req_Met := True;
5816 -- The requirement is met when the target comes from a preelaborated
5817 -- unit. This portion must parallel predicate Is_Preelaborated_Unit.
5819 elsif Is_Preelaborated_Unit (Unit_Id) then
5820 Req_Met := True;
5822 -- Output extra information when switch -gnatel (info messages on
5823 -- implicit Elaborate[_All] pragmas.
5825 if Elab_Info_Messages then
5826 if Is_Preelaborated (Unit_Id) then
5827 Elab_Nam := Name_Preelaborate;
5829 elsif Is_Pure (Unit_Id) then
5830 Elab_Nam := Name_Pure;
5832 elsif Is_Remote_Call_Interface (Unit_Id) then
5833 Elab_Nam := Name_Remote_Call_Interface;
5835 elsif Is_Remote_Types (Unit_Id) then
5836 Elab_Nam := Name_Remote_Types;
5838 else
5839 pragma Assert (Is_Shared_Passive (Unit_Id));
5840 Elab_Nam := Name_Shared_Passive;
5841 end if;
5843 Info_Requirement_Met (Find_Preelaboration_Pragma (Elab_Nam));
5844 end if;
5846 -- Determine whether the context of the main unit has a pragma strong
5847 -- enough to meet the requirement.
5849 else
5850 Elab_Attrs := Elaboration_Context.Get (Unit_Id);
5852 -- The pragma must be either Elaborate_All or be as strong as the
5853 -- requirement.
5855 if Present (Elab_Attrs.Source_Pragma)
5856 and then Nam_In (Pragma_Name (Elab_Attrs.Source_Pragma),
5857 Name_Elaborate_All,
5858 Req_Nam)
5859 then
5860 Req_Met := True;
5862 -- Output extra information when switch -gnatel (info messages on
5863 -- implicit Elaborate[_All] pragmas.
5865 if Elab_Info_Messages then
5866 Info_Requirement_Met (Elab_Attrs.Source_Pragma);
5867 end if;
5868 end if;
5869 end if;
5871 -- The requirement was not met by the context of the main unit, issue an
5872 -- error.
5874 if not Req_Met then
5875 Info_Scenario;
5877 Error_Msg_Name_1 := Req_Nam;
5878 Error_Msg_Node_2 := Unit_Id;
5879 Error_Msg_NE ("\\unit & requires pragma % for &", N, Main_Id);
5881 Output_Active_Scenarios (N);
5882 end if;
5883 end Meet_Elaboration_Requirement;
5885 ----------------------
5886 -- Non_Private_View --
5887 ----------------------
5889 function Non_Private_View (Typ : Entity_Id) return Entity_Id is
5890 Result : Entity_Id;
5892 begin
5893 Result := Typ;
5895 if Is_Private_Type (Result) and then Present (Full_View (Result)) then
5896 Result := Full_View (Result);
5897 end if;
5899 return Result;
5900 end Non_Private_View;
5902 -----------------------------
5903 -- Output_Active_Scenarios --
5904 -----------------------------
5906 procedure Output_Active_Scenarios (Error_Nod : Node_Id) is
5907 procedure Output_Access (N : Node_Id);
5908 -- Emit a specific diagnostic message for 'Access denote by N
5910 procedure Output_Activation_Call (N : Node_Id);
5911 -- Emit a specific diagnostic message for task activation N
5913 procedure Output_Call (N : Node_Id; Target_Id : Entity_Id);
5914 -- Emit a specific diagnostic message for call N which invokes target
5915 -- Target_Id.
5917 procedure Output_Header;
5918 -- Emit a specific diagnostic message for the unit of the root scenario
5920 procedure Output_Instantiation (N : Node_Id);
5921 -- Emit a specific diagnostic message for instantiation N
5923 procedure Output_Variable_Assignment (N : Node_Id);
5924 -- Emit a specific diagnostic message for assignment statement N
5926 procedure Output_Variable_Reference (N : Node_Id);
5927 -- Emit a specific diagnostic message for reference N which mentions a
5928 -- variable.
5930 -------------------
5931 -- Output_Access --
5932 -------------------
5934 procedure Output_Access (N : Node_Id) is
5935 Subp_Id : constant Entity_Id := Entity (Prefix (N));
5937 begin
5938 Error_Msg_Name_1 := Attribute_Name (N);
5939 Error_Msg_Sloc := Sloc (N);
5940 Error_Msg_NE ("\\ % of & taken #", Error_Nod, Subp_Id);
5941 end Output_Access;
5943 ----------------------------
5944 -- Output_Activation_Call --
5945 ----------------------------
5947 procedure Output_Activation_Call (N : Node_Id) is
5948 function Find_Activator (Call : Node_Id) return Entity_Id;
5949 -- Find the nearest enclosing construct which houses call Call
5951 --------------------
5952 -- Find_Activator --
5953 --------------------
5955 function Find_Activator (Call : Node_Id) return Entity_Id is
5956 Par : Node_Id;
5958 begin
5959 -- Climb the parent chain looking for a package [body] or a
5960 -- construct with a statement sequence.
5962 Par := Parent (Call);
5963 while Present (Par) loop
5964 if Nkind_In (Par, N_Package_Body, N_Package_Declaration) then
5965 return Defining_Entity (Par);
5967 elsif Nkind (Par) = N_Handled_Sequence_Of_Statements then
5968 return Defining_Entity (Parent (Par));
5969 end if;
5971 Par := Parent (Par);
5972 end loop;
5974 return Empty;
5975 end Find_Activator;
5977 -- Local variables
5979 Activator : constant Entity_Id := Find_Activator (N);
5981 -- Start of processing for Output_Activation_Call
5983 begin
5984 pragma Assert (Present (Activator));
5986 Error_Msg_NE ("\\ local tasks of & activated", Error_Nod, Activator);
5987 end Output_Activation_Call;
5989 -----------------
5990 -- Output_Call --
5991 -----------------
5993 procedure Output_Call (N : Node_Id; Target_Id : Entity_Id) is
5994 procedure Output_Accept_Alternative;
5995 pragma Inline (Output_Accept_Alternative);
5996 -- Emit a specific diagnostic message concerning an accept
5997 -- alternative.
5999 procedure Output_Call (Kind : String);
6000 pragma Inline (Output_Call);
6001 -- Emit a specific diagnostic message concerning a call of kind Kind
6003 procedure Output_Type_Actions (Action : String);
6004 pragma Inline (Output_Type_Actions);
6005 -- Emit a specific diagnostic message concerning action Action of a
6006 -- type.
6008 procedure Output_Verification_Call
6009 (Pred : String;
6010 Id : Entity_Id;
6011 Id_Kind : String);
6012 pragma Inline (Output_Verification_Call);
6013 -- Emit a specific diagnostic message concerning the verification of
6014 -- predicate Pred applied to related entity Id with kind Id_Kind.
6016 -------------------------------
6017 -- Output_Accept_Alternative --
6018 -------------------------------
6020 procedure Output_Accept_Alternative is
6021 Entry_Id : constant Entity_Id := Receiving_Entry (Target_Id);
6023 begin
6024 pragma Assert (Present (Entry_Id));
6026 Error_Msg_NE ("\\ entry & selected #", Error_Nod, Entry_Id);
6027 end Output_Accept_Alternative;
6029 -----------------
6030 -- Output_Call --
6031 -----------------
6033 procedure Output_Call (Kind : String) is
6034 begin
6035 Error_Msg_NE ("\\ " & Kind & " & called #", Error_Nod, Target_Id);
6036 end Output_Call;
6038 -------------------------
6039 -- Output_Type_Actions --
6040 -------------------------
6042 procedure Output_Type_Actions (Action : String) is
6043 Typ : constant Entity_Id := First_Formal_Type (Target_Id);
6045 begin
6046 pragma Assert (Present (Typ));
6048 Error_Msg_NE
6049 ("\\ " & Action & " actions for type & #", Error_Nod, Typ);
6050 end Output_Type_Actions;
6052 ------------------------------
6053 -- Output_Verification_Call --
6054 ------------------------------
6056 procedure Output_Verification_Call
6057 (Pred : String;
6058 Id : Entity_Id;
6059 Id_Kind : String)
6061 begin
6062 pragma Assert (Present (Id));
6064 Error_Msg_NE
6065 ("\\ " & Pred & " of " & Id_Kind & " & verified #",
6066 Error_Nod, Id);
6067 end Output_Verification_Call;
6069 -- Start of processing for Output_Call
6071 begin
6072 Error_Msg_Sloc := Sloc (N);
6074 -- Accept alternative
6076 if Is_Accept_Alternative_Proc (Target_Id) then
6077 Output_Accept_Alternative;
6079 -- Adjustment
6081 elsif Is_TSS (Target_Id, TSS_Deep_Adjust) then
6082 Output_Type_Actions ("adjustment");
6084 -- Default_Initial_Condition
6086 elsif Is_Default_Initial_Condition_Proc (Target_Id) then
6087 Output_Verification_Call
6088 (Pred => "Default_Initial_Condition",
6089 Id => First_Formal_Type (Target_Id),
6090 Id_Kind => "type");
6092 -- Entries
6094 elsif Is_Protected_Entry (Target_Id) then
6095 Output_Call ("entry");
6097 -- Task entry calls are never processed because the entry being
6098 -- invoked does not have a corresponding "body", it has a select. A
6099 -- task entry call appears in the stack of active scenarios for the
6100 -- sole purpose of checking No_Entry_Calls_In_Elaboration_Code and
6101 -- nothing more.
6103 elsif Is_Task_Entry (Target_Id) then
6104 null;
6106 -- Finalization
6108 elsif Is_TSS (Target_Id, TSS_Deep_Finalize) then
6109 Output_Type_Actions ("finalization");
6111 -- Calls to _Finalizer procedures must not appear in the output
6112 -- because this creates confusing noise.
6114 elsif Is_Finalizer_Proc (Target_Id) then
6115 null;
6117 -- Initial_Condition
6119 elsif Is_Initial_Condition_Proc (Target_Id) then
6120 Output_Verification_Call
6121 (Pred => "Initial_Condition",
6122 Id => Find_Enclosing_Scope (N),
6123 Id_Kind => "package");
6125 -- Initialization
6127 elsif Is_Init_Proc (Target_Id)
6128 or else Is_TSS (Target_Id, TSS_Deep_Initialize)
6129 then
6130 Output_Type_Actions ("initialization");
6132 -- Invariant
6134 elsif Is_Invariant_Proc (Target_Id) then
6135 Output_Verification_Call
6136 (Pred => "invariants",
6137 Id => First_Formal_Type (Target_Id),
6138 Id_Kind => "type");
6140 -- Partial invariant calls must not appear in the output because this
6141 -- creates confusing noise. Note that a partial invariant is always
6142 -- invoked by the "full" invariant which is already placed on the
6143 -- stack.
6145 elsif Is_Partial_Invariant_Proc (Target_Id) then
6146 null;
6148 -- _Postconditions
6150 elsif Is_Postconditions_Proc (Target_Id) then
6151 Output_Verification_Call
6152 (Pred => "postconditions",
6153 Id => Find_Enclosing_Scope (N),
6154 Id_Kind => "subprogram");
6156 -- Subprograms must come last because some of the previous cases fall
6157 -- under this category.
6159 elsif Ekind (Target_Id) = E_Function then
6160 Output_Call ("function");
6162 elsif Ekind (Target_Id) = E_Procedure then
6163 Output_Call ("procedure");
6165 else
6166 pragma Assert (False);
6167 null;
6168 end if;
6169 end Output_Call;
6171 -------------------
6172 -- Output_Header --
6173 -------------------
6175 procedure Output_Header is
6176 Unit_Id : constant Entity_Id := Find_Top_Unit (Root_Scenario);
6178 begin
6179 if Ekind (Unit_Id) = E_Package then
6180 Error_Msg_NE ("\\ spec of unit & elaborated", Error_Nod, Unit_Id);
6182 elsif Ekind (Unit_Id) = E_Package_Body then
6183 Error_Msg_NE ("\\ body of unit & elaborated", Error_Nod, Unit_Id);
6185 else
6186 Error_Msg_NE ("\\ in body of unit &", Error_Nod, Unit_Id);
6187 end if;
6188 end Output_Header;
6190 --------------------------
6191 -- Output_Instantiation --
6192 --------------------------
6194 procedure Output_Instantiation (N : Node_Id) is
6195 procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String);
6196 pragma Inline (Output_Instantiation);
6197 -- Emit a specific diagnostic message concerning an instantiation of
6198 -- generic unit Gen_Id. Kind denotes the kind of the instantiation.
6200 --------------------------
6201 -- Output_Instantiation --
6202 --------------------------
6204 procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String) is
6205 begin
6206 Error_Msg_NE
6207 ("\\ " & Kind & " & instantiated as & #", Error_Nod, Gen_Id);
6208 end Output_Instantiation;
6210 -- Local variables
6212 Inst : Node_Id;
6213 Inst_Attrs : Instantiation_Attributes;
6214 Inst_Id : Entity_Id;
6215 Gen_Id : Entity_Id;
6217 -- Start of processing for Output_Instantiation
6219 begin
6220 Extract_Instantiation_Attributes
6221 (Exp_Inst => N,
6222 Inst => Inst,
6223 Inst_Id => Inst_Id,
6224 Gen_Id => Gen_Id,
6225 Attrs => Inst_Attrs);
6227 Error_Msg_Node_2 := Inst_Id;
6228 Error_Msg_Sloc := Sloc (Inst);
6230 if Nkind (Inst) = N_Function_Instantiation then
6231 Output_Instantiation (Gen_Id, "function");
6233 elsif Nkind (Inst) = N_Package_Instantiation then
6234 Output_Instantiation (Gen_Id, "package");
6236 elsif Nkind (Inst) = N_Procedure_Instantiation then
6237 Output_Instantiation (Gen_Id, "procedure");
6239 else
6240 pragma Assert (False);
6241 null;
6242 end if;
6243 end Output_Instantiation;
6245 --------------------------------
6246 -- Output_Variable_Assignment --
6247 --------------------------------
6249 procedure Output_Variable_Assignment (N : Node_Id) is
6250 Var_Id : constant Entity_Id := Entity (Extract_Assignment_Name (N));
6252 begin
6253 Error_Msg_Sloc := Sloc (N);
6254 Error_Msg_NE ("\\ variable & assigned #", Error_Nod, Var_Id);
6255 end Output_Variable_Assignment;
6257 -------------------------------
6258 -- Output_Variable_Reference --
6259 -------------------------------
6261 procedure Output_Variable_Reference (N : Node_Id) is
6262 Dummy : Variable_Attributes;
6263 Var_Id : Entity_Id;
6265 begin
6266 Extract_Variable_Reference_Attributes
6267 (Ref => N,
6268 Var_Id => Var_Id,
6269 Attrs => Dummy);
6271 Error_Msg_Sloc := Sloc (N);
6273 if Is_Read (N) then
6274 Error_Msg_NE ("\\ variable & read #", Error_Nod, Var_Id);
6275 end if;
6276 end Output_Variable_Reference;
6278 -- Local variables
6280 package Stack renames Scenario_Stack;
6282 Dummy : Call_Attributes;
6283 N : Node_Id;
6284 Posted : Boolean;
6285 Target_Id : Entity_Id;
6287 -- Start of processing for Output_Active_Scenarios
6289 begin
6290 -- Active scenarios are emitted only when the static model is in effect
6291 -- because there is an inherent order by which all these scenarios were
6292 -- reached from the declaration or library level.
6294 if not Static_Elaboration_Checks then
6295 return;
6296 end if;
6298 Posted := False;
6300 for Index in Stack.First .. Stack.Last loop
6301 N := Stack.Table (Index);
6303 if not Posted then
6304 Posted := True;
6305 Output_Header;
6306 end if;
6308 -- 'Access
6310 if Nkind (N) = N_Attribute_Reference then
6311 Output_Access (N);
6313 -- Calls
6315 elsif Is_Suitable_Call (N) then
6316 Extract_Call_Attributes
6317 (Call => N,
6318 Target_Id => Target_Id,
6319 Attrs => Dummy);
6321 if Is_Activation_Proc (Target_Id) then
6322 Output_Activation_Call (N);
6323 else
6324 Output_Call (N, Target_Id);
6325 end if;
6327 -- Instantiations
6329 elsif Is_Suitable_Instantiation (N) then
6330 Output_Instantiation (N);
6332 -- Variable assignments
6334 elsif Nkind (N) = N_Assignment_Statement then
6335 Output_Variable_Assignment (N);
6337 -- Variable references
6339 elsif Is_Suitable_Variable_Reference (N) then
6340 Output_Variable_Reference (N);
6342 else
6343 pragma Assert (False);
6344 null;
6345 end if;
6346 end loop;
6347 end Output_Active_Scenarios;
6349 -------------------------
6350 -- Pop_Active_Scenario --
6351 -------------------------
6353 procedure Pop_Active_Scenario (N : Node_Id) is
6354 Top : Node_Id renames Scenario_Stack.Table (Scenario_Stack.Last);
6356 begin
6357 pragma Assert (Top = N);
6358 Scenario_Stack.Decrement_Last;
6359 end Pop_Active_Scenario;
6361 --------------------
6362 -- Process_Access --
6363 --------------------
6365 procedure Process_Access
6366 (Attr : Node_Id;
6367 In_Partial_Fin : Boolean;
6368 In_Task_Body : Boolean)
6370 function Build_Access_Marker (Target_Id : Entity_Id) return Node_Id;
6371 pragma Inline (Build_Access_Marker);
6372 -- Create a suitable call marker which invokes target Target_Id
6374 -------------------------
6375 -- Build_Access_Marker --
6376 -------------------------
6378 function Build_Access_Marker (Target_Id : Entity_Id) return Node_Id is
6379 Marker : Node_Id;
6381 begin
6382 Marker := Make_Call_Marker (Sloc (Attr));
6384 -- Inherit relevant attributes from the attribute
6386 -- Performance note: parent traversal
6388 Set_Target (Marker, Target_Id);
6389 Set_Is_Declaration_Level_Node
6390 (Marker, Find_Enclosing_Level (Attr) = Declaration_Level);
6391 Set_Is_Dispatching_Call
6392 (Marker, False);
6393 Set_Is_Elaboration_Checks_OK_Node
6394 (Marker, Is_Elaboration_Checks_OK_Node (Attr));
6395 Set_Is_Source_Call
6396 (Marker, Comes_From_Source (Attr));
6397 Set_Is_SPARK_Mode_On_Node
6398 (Marker, Is_SPARK_Mode_On_Node (Attr));
6400 -- Partially insert the call marker into the tree by setting its
6401 -- parent pointer.
6403 Set_Parent (Marker, Attr);
6405 return Marker;
6406 end Build_Access_Marker;
6408 -- Local variables
6410 Root : constant Node_Id := Root_Scenario;
6411 Target_Id : constant Entity_Id := Entity (Prefix (Attr));
6413 Target_Attrs : Target_Attributes;
6415 -- Start of processing for Process_Access
6417 begin
6418 -- Output relevant information when switch -gnatel (info messages on
6419 -- implicit Elaborate[_All] pragmas) is in effect.
6421 if Elab_Info_Messages then
6422 Error_Msg_NE
6423 ("info: access to & during elaboration", Attr, Target_Id);
6424 end if;
6426 Extract_Target_Attributes
6427 (Target_Id => Target_Id,
6428 Attrs => Target_Attrs);
6430 -- Both the attribute and the corresponding body are in the same unit.
6431 -- The corresponding body must appear prior to the root scenario which
6432 -- started the recursive search. If this is not the case, then there is
6433 -- a potential ABE if the access value is used to call the subprogram.
6434 -- Emit a warning only when switch -gnatw.f (warnings on suspucious
6435 -- 'Access) is in effect.
6437 if Warn_On_Elab_Access
6438 and then Present (Target_Attrs.Body_Decl)
6439 and then In_Extended_Main_Code_Unit (Target_Attrs.Body_Decl)
6440 and then Earlier_In_Extended_Unit (Root, Target_Attrs.Body_Decl)
6441 then
6442 Error_Msg_Name_1 := Attribute_Name (Attr);
6443 Error_Msg_NE ("??% attribute of & before body seen", Attr, Target_Id);
6444 Error_Msg_N ("\possible Program_Error on later references", Attr);
6446 Output_Active_Scenarios (Attr);
6447 end if;
6449 -- Treat the attribute as an immediate invocation of the target when
6450 -- switch -gnatd.o (conservative elaboration order for indirect calls)
6451 -- is in effect. Note that the prior elaboration of the unit containing
6452 -- the target is ensured processing the corresponding call marker.
6454 if Debug_Flag_Dot_O then
6455 Process_Scenario
6456 (N => Build_Access_Marker (Target_Id),
6457 In_Partial_Fin => In_Partial_Fin,
6458 In_Task_Body => In_Task_Body);
6460 -- Otherwise ensure that the unit with the corresponding body is
6461 -- elaborated prior to the main unit.
6463 else
6464 Ensure_Prior_Elaboration
6465 (N => Attr,
6466 Unit_Id => Target_Attrs.Unit_Id,
6467 In_Partial_Fin => In_Partial_Fin,
6468 In_Task_Body => In_Task_Body);
6469 end if;
6470 end Process_Access;
6472 -----------------------------
6473 -- Process_Activation_Call --
6474 -----------------------------
6476 procedure Process_Activation_Call
6477 (Call : Node_Id;
6478 Call_Attrs : Call_Attributes;
6479 In_Partial_Fin : Boolean;
6480 In_Task_Body : Boolean)
6482 procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id);
6483 -- Perform ABE checks and diagnostics for object Obj_Id with type Typ.
6484 -- Typ may be a task type or a composite type with at least one task
6485 -- component.
6487 procedure Process_Task_Objects (List : List_Id);
6488 -- Perform ABE checks and diagnostics for all task objects found in
6489 -- the list List.
6491 -------------------------
6492 -- Process_Task_Object --
6493 -------------------------
6495 procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id) is
6496 Base_Typ : constant Entity_Id := Base_Type (Typ);
6498 Comp_Id : Entity_Id;
6499 Task_Attrs : Task_Attributes;
6501 begin
6502 if Is_Task_Type (Typ) then
6503 Extract_Task_Attributes
6504 (Typ => Base_Typ,
6505 Attrs => Task_Attrs);
6507 Process_Single_Activation
6508 (Call => Call,
6509 Call_Attrs => Call_Attrs,
6510 Obj_Id => Obj_Id,
6511 Task_Attrs => Task_Attrs,
6512 In_Partial_Fin => In_Partial_Fin,
6513 In_Task_Body => In_Task_Body);
6515 -- Examine the component type when the object is an array
6517 elsif Is_Array_Type (Typ) and then Has_Task (Base_Typ) then
6518 Process_Task_Object (Obj_Id, Component_Type (Typ));
6520 -- Examine individual component types when the object is a record
6522 elsif Is_Record_Type (Typ) and then Has_Task (Base_Typ) then
6523 Comp_Id := First_Component (Typ);
6524 while Present (Comp_Id) loop
6525 Process_Task_Object (Obj_Id, Etype (Comp_Id));
6526 Next_Component (Comp_Id);
6527 end loop;
6528 end if;
6529 end Process_Task_Object;
6531 --------------------------
6532 -- Process_Task_Objects --
6533 --------------------------
6535 procedure Process_Task_Objects (List : List_Id) is
6536 Item : Node_Id;
6537 Item_Id : Entity_Id;
6538 Item_Typ : Entity_Id;
6540 begin
6541 -- Examine the contents of the list looking for an object declaration
6542 -- of a task type or one that contains a task within.
6544 Item := First (List);
6545 while Present (Item) loop
6546 if Nkind (Item) = N_Object_Declaration then
6547 Item_Id := Defining_Entity (Item);
6548 Item_Typ := Etype (Item_Id);
6550 if Has_Task (Item_Typ) then
6551 Process_Task_Object (Item_Id, Item_Typ);
6552 end if;
6553 end if;
6555 Next (Item);
6556 end loop;
6557 end Process_Task_Objects;
6559 -- Local variables
6561 Context : Node_Id;
6562 Spec : Node_Id;
6564 -- Start of processing for Process_Activation_Call
6566 begin
6567 -- Nothing to do when the activation is a guaranteed ABE
6569 if Is_Known_Guaranteed_ABE (Call) then
6570 return;
6571 end if;
6573 -- Find the proper context of the activation call where all task objects
6574 -- being activated are declared. This is usually the immediate parent of
6575 -- the call.
6577 Context := Parent (Call);
6579 -- In the case of package bodies, the activation call is in the handled
6580 -- sequence of statements, but the task objects are in the declaration
6581 -- list of the body.
6583 if Nkind (Context) = N_Handled_Sequence_Of_Statements
6584 and then Nkind (Parent (Context)) = N_Package_Body
6585 then
6586 Context := Parent (Context);
6587 end if;
6589 -- Process all task objects defined in both the spec and body when the
6590 -- activation call precedes the "begin" of a package body.
6592 if Nkind (Context) = N_Package_Body then
6593 Spec :=
6594 Specification
6595 (Unit_Declaration_Node (Corresponding_Spec (Context)));
6597 Process_Task_Objects (Visible_Declarations (Spec));
6598 Process_Task_Objects (Private_Declarations (Spec));
6599 Process_Task_Objects (Declarations (Context));
6601 -- Process all task objects defined in the spec when the activation call
6602 -- appears at the end of a package spec.
6604 elsif Nkind (Context) = N_Package_Specification then
6605 Process_Task_Objects (Visible_Declarations (Context));
6606 Process_Task_Objects (Private_Declarations (Context));
6608 -- Otherwise the context of the activation is some construct with a
6609 -- declarative part. Note that the corresponding record type of a task
6610 -- type is controlled. Because of this, the finalization machinery must
6611 -- relocate the task object to the handled statements of the construct
6612 -- to perform proper finalization in case of an exception. Examine the
6613 -- statements of the construct rather than the declarations.
6615 else
6616 pragma Assert (Nkind (Context) = N_Handled_Sequence_Of_Statements);
6618 Process_Task_Objects (Statements (Context));
6619 end if;
6620 end Process_Activation_Call;
6622 ---------------------------------------------
6623 -- Process_Activation_Conditional_ABE_Impl --
6624 ---------------------------------------------
6626 procedure Process_Activation_Conditional_ABE_Impl
6627 (Call : Node_Id;
6628 Call_Attrs : Call_Attributes;
6629 Obj_Id : Entity_Id;
6630 Task_Attrs : Task_Attributes;
6631 In_Partial_Fin : Boolean;
6632 In_Task_Body : Boolean)
6634 Check_OK : constant Boolean :=
6635 not Is_Ignored_Ghost_Entity (Obj_Id)
6636 and then not Task_Attrs.Ghost_Mode_Ignore
6637 and then Is_Elaboration_Checks_OK_Id (Obj_Id)
6638 and then Task_Attrs.Elab_Checks_OK;
6639 -- A run-time ABE check may be installed only when the object and the
6640 -- task type have active elaboration checks, and both are not ignored
6641 -- Ghost constructs.
6643 Root : constant Node_Id := Root_Scenario;
6645 begin
6646 -- Output relevant information when switch -gnatel (info messages on
6647 -- implicit Elaborate[_All] pragmas) is in effect.
6649 if Elab_Info_Messages then
6650 Error_Msg_NE
6651 ("info: activation of & during elaboration", Call, Obj_Id);
6652 end if;
6654 -- Nothing to do when the activation is a guaranteed ABE
6656 if Is_Known_Guaranteed_ABE (Call) then
6657 return;
6659 -- Nothing to do when the root scenario appears at the declaration
6660 -- level and the task is in the same unit, but outside this context.
6662 -- task type Task_Typ; -- task declaration
6664 -- procedure Proc is
6665 -- function A ... is
6666 -- begin
6667 -- if Some_Condition then
6668 -- declare
6669 -- T : Task_Typ;
6670 -- begin
6671 -- <activation call> -- activation site
6672 -- end;
6673 -- ...
6674 -- end A;
6676 -- X : ... := A; -- root scenario
6677 -- ...
6679 -- task body Task_Typ is
6680 -- ...
6681 -- end Task_Typ;
6683 -- In the example above, the context of X is the declarative list of
6684 -- Proc. The "elaboration" of X may reach the activation of T whose body
6685 -- is defined outside of X's context. The task body is relevant only
6686 -- when Proc is invoked, but this happens only in "normal" elaboration,
6687 -- therefore the task body must not be considered if this is not the
6688 -- case.
6690 -- Performance note: parent traversal
6692 elsif Is_Up_Level_Target (Task_Attrs.Task_Decl) then
6693 return;
6695 -- Nothing to do when the activation is ABE-safe
6697 -- generic
6698 -- package Gen is
6699 -- task type Task_Typ;
6700 -- end Gen;
6702 -- package body Gen is
6703 -- task body Task_Typ is
6704 -- begin
6705 -- ...
6706 -- end Task_Typ;
6707 -- end Gen;
6709 -- with Gen;
6710 -- procedure Main is
6711 -- package Nested is
6712 -- ...
6713 -- end Nested;
6715 -- package body Nested is
6716 -- package Inst is new Gen;
6717 -- T : Inst.Task_Typ;
6718 -- [begin]
6719 -- <activation call> -- safe activation
6720 -- end Nested;
6721 -- ...
6723 elsif Is_Safe_Activation (Call, Task_Attrs.Task_Decl) then
6725 -- Note that the task body must still be examined for any nested
6726 -- scenarios.
6728 null;
6730 -- The activation call and the task body are both in the main unit
6732 elsif Present (Task_Attrs.Body_Decl)
6733 and then In_Extended_Main_Code_Unit (Task_Attrs.Body_Decl)
6734 then
6735 -- If the root scenario appears prior to the task body, then this is
6736 -- a possible ABE with respect to the root scenario.
6738 -- task type Task_Typ;
6740 -- function A ... is
6741 -- begin
6742 -- if Some_Condition then
6743 -- declare
6744 -- package Pack is
6745 -- ...
6746 -- end Pack;
6748 -- package body Pack is
6749 -- T : Task_Typ;
6750 -- [begin]
6751 -- <activation call> -- activation of T
6752 -- end Pack;
6753 -- ...
6754 -- end A;
6756 -- X : ... := A; -- root scenario
6758 -- task body Task_Typ is -- task body
6759 -- ...
6760 -- end Task_Typ;
6762 -- Y : ... := A; -- root scenario
6764 -- IMPORTANT: The activation of T is a possible ABE for X, but
6765 -- not for Y. Intalling an unconditional ABE raise prior to the
6766 -- activation call would be wrong as it will fail for Y as well
6767 -- but in Y's case the activation of T is never an ABE.
6769 if Earlier_In_Extended_Unit (Root, Task_Attrs.Body_Decl) then
6771 -- Do not emit any ABE diagnostics when the activation occurs in
6772 -- a partial finalization context because this leads to confusing
6773 -- noise.
6775 if In_Partial_Fin then
6776 null;
6778 -- ABE diagnostics are emitted only in the static model because
6779 -- there is a well-defined order to visiting scenarios. Without
6780 -- this order diagnostics appear jumbled and result in unwanted
6781 -- noise.
6783 elsif Static_Elaboration_Checks then
6784 Error_Msg_Sloc := Sloc (Call);
6785 Error_Msg_N
6786 ("??task & will be activated # before elaboration of its "
6787 & "body", Obj_Id);
6788 Error_Msg_N
6789 ("\Program_Error may be raised at run time", Obj_Id);
6791 Output_Active_Scenarios (Obj_Id);
6792 end if;
6794 -- Install a conditional run-time ABE check to verify that the
6795 -- task body has been elaborated prior to the activation call.
6797 if Check_OK then
6798 Install_ABE_Check
6799 (N => Call,
6800 Ins_Nod => Call,
6801 Target_Id => Task_Attrs.Spec_Id,
6802 Target_Decl => Task_Attrs.Task_Decl,
6803 Target_Body => Task_Attrs.Body_Decl);
6804 end if;
6805 end if;
6807 -- Otherwise the task body is not available in this compilation or it
6808 -- resides in an external unit. Install a run-time ABE check to verify
6809 -- that the task body has been elaborated prior to the activation call
6810 -- when the dynamic model is in effect.
6812 elsif Dynamic_Elaboration_Checks and then Check_OK then
6813 Install_ABE_Check
6814 (N => Call,
6815 Ins_Nod => Call,
6816 Id => Task_Attrs.Unit_Id);
6817 end if;
6819 -- Both the activation call and task type are subject to SPARK_Mode
6820 -- On, this triggers the SPARK rules for task activation. Compared to
6821 -- calls and instantiations, task activation in SPARK does not require
6822 -- the presence of Elaborate[_All] pragmas in case the task type is
6823 -- defined outside the main unit. This is because SPARK utilizes a
6824 -- special policy which activates all tasks after the main unit has
6825 -- finished its elaboration.
6827 if Call_Attrs.SPARK_Mode_On and Task_Attrs.SPARK_Mode_On then
6828 null;
6830 -- Otherwise the Ada rules are in effect. Ensure that the unit with the
6831 -- task body is elaborated prior to the main unit.
6833 else
6834 Ensure_Prior_Elaboration
6835 (N => Call,
6836 Unit_Id => Task_Attrs.Unit_Id,
6837 In_Partial_Fin => In_Partial_Fin,
6838 In_Task_Body => In_Task_Body);
6839 end if;
6841 Traverse_Body
6842 (N => Task_Attrs.Body_Decl,
6843 In_Partial_Fin => In_Partial_Fin,
6844 In_Task_Body => True);
6845 end Process_Activation_Conditional_ABE_Impl;
6847 procedure Process_Activation_Conditional_ABE is
6848 new Process_Activation_Call (Process_Activation_Conditional_ABE_Impl);
6850 --------------------------------------------
6851 -- Process_Activation_Guaranteed_ABE_Impl --
6852 --------------------------------------------
6854 procedure Process_Activation_Guaranteed_ABE_Impl
6855 (Call : Node_Id;
6856 Call_Attrs : Call_Attributes;
6857 Obj_Id : Entity_Id;
6858 Task_Attrs : Task_Attributes;
6859 In_Partial_Fin : Boolean;
6860 In_Task_Body : Boolean)
6862 pragma Unreferenced (Call_Attrs);
6863 pragma Unreferenced (In_Partial_Fin);
6864 pragma Unreferenced (In_Task_Body);
6866 Check_OK : constant Boolean :=
6867 not Is_Ignored_Ghost_Entity (Obj_Id)
6868 and then not Task_Attrs.Ghost_Mode_Ignore
6869 and then Is_Elaboration_Checks_OK_Id (Obj_Id)
6870 and then Task_Attrs.Elab_Checks_OK;
6871 -- A run-time ABE check may be installed only when the object and the
6872 -- task type have active elaboration checks, and both are not ignored
6873 -- Ghost constructs.
6875 begin
6876 -- Nothing to do when the root scenario appears at the declaration
6877 -- level and the task is in the same unit, but outside this context.
6879 -- task type Task_Typ; -- task declaration
6881 -- procedure Proc is
6882 -- function A ... is
6883 -- begin
6884 -- if Some_Condition then
6885 -- declare
6886 -- T : Task_Typ;
6887 -- begin
6888 -- <activation call> -- activation site
6889 -- end;
6890 -- ...
6891 -- end A;
6893 -- X : ... := A; -- root scenario
6894 -- ...
6896 -- task body Task_Typ is
6897 -- ...
6898 -- end Task_Typ;
6900 -- In the example above, the context of X is the declarative list of
6901 -- Proc. The "elaboration" of X may reach the activation of T whose body
6902 -- is defined outside of X's context. The task body is relevant only
6903 -- when Proc is invoked, but this happens only in "normal" elaboration,
6904 -- therefore the task body must not be considered if this is not the
6905 -- case.
6907 -- Performance note: parent traversal
6909 if Is_Up_Level_Target (Task_Attrs.Task_Decl) then
6910 return;
6912 -- Nothing to do when the activation is ABE-safe
6914 -- generic
6915 -- package Gen is
6916 -- task type Task_Typ;
6917 -- end Gen;
6919 -- package body Gen is
6920 -- task body Task_Typ is
6921 -- begin
6922 -- ...
6923 -- end Task_Typ;
6924 -- end Gen;
6926 -- with Gen;
6927 -- procedure Main is
6928 -- package Nested is
6929 -- ...
6930 -- end Nested;
6932 -- package body Nested is
6933 -- package Inst is new Gen;
6934 -- T : Inst.Task_Typ;
6935 -- [begin]
6936 -- <activation call> -- safe activation
6937 -- end Nested;
6938 -- ...
6940 elsif Is_Safe_Activation (Call, Task_Attrs.Task_Decl) then
6941 return;
6943 -- An activation call leads to a guaranteed ABE when the activation
6944 -- call and the task appear within the same context ignoring library
6945 -- levels, and the body of the task has not been seen yet or appears
6946 -- after the activation call.
6948 -- procedure Guaranteed_ABE is
6949 -- task type Task_Typ;
6951 -- package Nested is
6952 -- ...
6953 -- end Nested;
6955 -- package body Nested is
6956 -- T : Task_Typ;
6957 -- [begin]
6958 -- <activation call> -- guaranteed ABE
6959 -- end Nested;
6961 -- task body Task_Typ is
6962 -- ...
6963 -- end Task_Typ;
6964 -- ...
6966 -- Performance note: parent traversal
6968 elsif Is_Guaranteed_ABE
6969 (N => Call,
6970 Target_Decl => Task_Attrs.Task_Decl,
6971 Target_Body => Task_Attrs.Body_Decl)
6972 then
6973 Error_Msg_Sloc := Sloc (Call);
6974 Error_Msg_N
6975 ("??task & will be activated # before elaboration of its body",
6976 Obj_Id);
6977 Error_Msg_N ("\Program_Error will be raised at run time", Obj_Id);
6979 -- Mark the activation call as a guaranteed ABE
6981 Set_Is_Known_Guaranteed_ABE (Call);
6983 -- Install a run-time ABE failue because this activation call will
6984 -- always result in an ABE.
6986 if Check_OK then
6987 Install_ABE_Failure
6988 (N => Call,
6989 Ins_Nod => Call);
6990 end if;
6991 end if;
6992 end Process_Activation_Guaranteed_ABE_Impl;
6994 procedure Process_Activation_Guaranteed_ABE is
6995 new Process_Activation_Call (Process_Activation_Guaranteed_ABE_Impl);
6997 ------------------
6998 -- Process_Call --
6999 ------------------
7001 procedure Process_Call
7002 (Call : Node_Id;
7003 Call_Attrs : Call_Attributes;
7004 Target_Id : Entity_Id;
7005 In_Partial_Fin : Boolean;
7006 In_Task_Body : Boolean)
7008 function In_Initialization_Context (N : Node_Id) return Boolean;
7009 -- Determine whether arbitrary node N appears within a type init proc,
7010 -- primitive [Deep_]Initialize, or a block created for initialization
7011 -- purposes.
7013 function Is_Partial_Finalization_Proc return Boolean;
7014 pragma Inline (Is_Partial_Finalization_Proc);
7015 -- Determine whether call Call with target Target_Id invokes a partial
7016 -- finalization procedure.
7018 -------------------------------
7019 -- In_Initialization_Context --
7020 -------------------------------
7022 function In_Initialization_Context (N : Node_Id) return Boolean is
7023 Par : Node_Id;
7024 Spec_Id : Entity_Id;
7026 begin
7027 -- Climb the parent chain looking for initialization actions
7029 Par := Parent (N);
7030 while Present (Par) loop
7032 -- A block may be part of the initialization actions of a default
7033 -- initialized object.
7035 if Nkind (Par) = N_Block_Statement
7036 and then Is_Initialization_Block (Par)
7037 then
7038 return True;
7040 -- A subprogram body may denote an initialization routine
7042 elsif Nkind (Par) = N_Subprogram_Body then
7043 Spec_Id := Unique_Defining_Entity (Par);
7045 -- The current subprogram body denotes a type init proc or
7046 -- primitive [Deep_]Initialize.
7048 if Is_Init_Proc (Spec_Id)
7049 or else Is_Controlled_Proc (Spec_Id, Name_Initialize)
7050 or else Is_TSS (Spec_Id, TSS_Deep_Initialize)
7051 then
7052 return True;
7053 end if;
7055 -- Prevent the search from going too far
7057 elsif Is_Body_Or_Package_Declaration (Par) then
7058 exit;
7059 end if;
7061 Par := Parent (Par);
7062 end loop;
7064 return False;
7065 end In_Initialization_Context;
7067 ----------------------------------
7068 -- Is_Partial_Finalization_Proc --
7069 ----------------------------------
7071 function Is_Partial_Finalization_Proc return Boolean is
7072 begin
7073 -- To qualify, the target must denote primitive [Deep_]Finalize or a
7074 -- finalizer procedure, and the call must appear in an initialization
7075 -- context.
7077 return
7078 (Is_Controlled_Proc (Target_Id, Name_Finalize)
7079 or else Is_Finalizer_Proc (Target_Id)
7080 or else Is_TSS (Target_Id, TSS_Deep_Finalize))
7081 and then In_Initialization_Context (Call);
7082 end Is_Partial_Finalization_Proc;
7084 -- Local variables
7086 Partial_Fin_On : Boolean;
7087 SPARK_Rules_On : Boolean;
7088 Target_Attrs : Target_Attributes;
7090 -- Start of processing for Process_Call
7092 begin
7093 Extract_Target_Attributes
7094 (Target_Id => Target_Id,
7095 Attrs => Target_Attrs);
7097 -- The call occurs in a partial finalization context when a prior
7098 -- scenario is already in that mode, or when the target denotes a
7099 -- [Deep_]Finalize primitive or a finalizer within an initialization
7100 -- context.
7102 Partial_Fin_On := In_Partial_Fin or else Is_Partial_Finalization_Proc;
7104 -- The SPARK rules are in effect when both the call and target are
7105 -- subject to SPARK_Mode On.
7107 SPARK_Rules_On :=
7108 Call_Attrs.SPARK_Mode_On and Target_Attrs.SPARK_Mode_On;
7110 -- Output relevant information when switch -gnatel (info messages on
7111 -- implicit Elaborate[_All] pragmas) is in effect.
7113 if Elab_Info_Messages then
7114 Info_Call
7115 (Call => Call,
7116 Target_Id => Target_Id,
7117 Info_Msg => True,
7118 In_SPARK => SPARK_Rules_On);
7119 end if;
7121 -- Check whether the invocation of an entry clashes with an existing
7122 -- restriction.
7124 if Is_Protected_Entry (Target_Id) then
7125 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
7127 elsif Is_Task_Entry (Target_Id) then
7128 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
7130 -- Task entry calls are never processed because the entry being
7131 -- invoked does not have a corresponding "body", it has a select.
7133 return;
7134 end if;
7136 -- Nothing to do when the call is a guaranteed ABE
7138 if Is_Known_Guaranteed_ABE (Call) then
7139 return;
7141 -- Nothing to do when the root scenario appears at the declaration level
7142 -- and the target is in the same unit, but outside this context.
7144 -- function B ...; -- target declaration
7146 -- procedure Proc is
7147 -- function A ... is
7148 -- begin
7149 -- if Some_Condition then
7150 -- return B; -- call site
7151 -- ...
7152 -- end A;
7154 -- X : ... := A; -- root scenario
7155 -- ...
7157 -- function B ... is
7158 -- ...
7159 -- end B;
7161 -- In the example above, the context of X is the declarative region of
7162 -- Proc. The "elaboration" of X may eventually reach B which is defined
7163 -- outside of X's context. B is relevant only when Proc is invoked, but
7164 -- this happens only by means of "normal" elaboration, therefore B must
7165 -- not be considered if this is not the case.
7167 -- Performance note: parent traversal
7169 elsif Is_Up_Level_Target (Target_Attrs.Spec_Decl) then
7170 return;
7172 -- The SPARK rules are verified only when -gnatd.v (enforce SPARK
7173 -- elaboration rules in SPARK code) is in effect.
7175 elsif SPARK_Rules_On and Debug_Flag_Dot_V then
7176 Process_Call_SPARK
7177 (Call => Call,
7178 Call_Attrs => Call_Attrs,
7179 Target_Id => Target_Id,
7180 Target_Attrs => Target_Attrs,
7181 In_Partial_Fin => In_Partial_Fin);
7183 -- Otherwise the Ada rules are in effect, or SPARK code is allowed to
7184 -- violate the SPARK rules.
7186 else
7187 Process_Call_Ada
7188 (Call => Call,
7189 Call_Attrs => Call_Attrs,
7190 Target_Id => Target_Id,
7191 Target_Attrs => Target_Attrs,
7192 In_Partial_Fin => Partial_Fin_On,
7193 In_Task_Body => In_Task_Body);
7194 end if;
7196 -- Inspect the target body (and barried function) for other suitable
7197 -- elaboration scenarios.
7199 Traverse_Body (Target_Attrs.Body_Barf, Partial_Fin_On, In_Task_Body);
7200 Traverse_Body (Target_Attrs.Body_Decl, Partial_Fin_On, In_Task_Body);
7201 end Process_Call;
7203 ----------------------
7204 -- Process_Call_Ada --
7205 ----------------------
7207 procedure Process_Call_Ada
7208 (Call : Node_Id;
7209 Call_Attrs : Call_Attributes;
7210 Target_Id : Entity_Id;
7211 Target_Attrs : Target_Attributes;
7212 In_Partial_Fin : Boolean;
7213 In_Task_Body : Boolean)
7215 Check_OK : constant Boolean :=
7216 not Call_Attrs.Ghost_Mode_Ignore
7217 and then not Target_Attrs.Ghost_Mode_Ignore
7218 and then Call_Attrs.Elab_Checks_OK
7219 and then Target_Attrs.Elab_Checks_OK;
7220 -- A run-time ABE check may be installed only when both the call and the
7221 -- target have active elaboration checks, and both are not ignored Ghost
7222 -- constructs.
7224 begin
7225 -- Nothing to do for an Ada dispatching call because there are no ABE
7226 -- diagnostics for either models. ABE checks for the dynamic model are
7227 -- handled by Install_Primitive_Elaboration_Check.
7229 if Call_Attrs.Is_Dispatching then
7230 return;
7232 -- Nothing to do when the call is ABE-safe
7234 -- generic
7235 -- function Gen ...;
7237 -- function Gen ... is
7238 -- begin
7239 -- ...
7240 -- end Gen;
7242 -- with Gen;
7243 -- procedure Main is
7244 -- function Inst is new Gen;
7245 -- X : ... := Inst; -- safe call
7246 -- ...
7248 elsif Is_Safe_Call (Call, Target_Attrs) then
7249 return;
7251 -- The call and the target body are both in the main unit
7253 elsif Present (Target_Attrs.Body_Decl)
7254 and then In_Extended_Main_Code_Unit (Target_Attrs.Body_Decl)
7255 then
7256 Process_Call_Conditional_ABE
7257 (Call => Call,
7258 Call_Attrs => Call_Attrs,
7259 Target_Id => Target_Id,
7260 Target_Attrs => Target_Attrs,
7261 In_Partial_Fin => In_Partial_Fin);
7263 -- Otherwise the target body is not available in this compilation or it
7264 -- resides in an external unit. Install a run-time ABE check to verify
7265 -- that the target body has been elaborated prior to the call site when
7266 -- the dynamic model is in effect.
7268 elsif Dynamic_Elaboration_Checks and then Check_OK then
7269 Install_ABE_Check
7270 (N => Call,
7271 Ins_Nod => Call,
7272 Id => Target_Attrs.Unit_Id);
7273 end if;
7275 -- Ensure that the unit with the target body is elaborated prior to the
7276 -- main unit. The implicit Elaborate[_All] is generated only when the
7277 -- call has elaboration checks enabled. This behaviour parallels that of
7278 -- the old ABE mechanism.
7280 if Call_Attrs.Elab_Checks_OK then
7281 Ensure_Prior_Elaboration
7282 (N => Call,
7283 Unit_Id => Target_Attrs.Unit_Id,
7284 In_Partial_Fin => In_Partial_Fin,
7285 In_Task_Body => In_Task_Body);
7286 end if;
7287 end Process_Call_Ada;
7289 ----------------------------------
7290 -- Process_Call_Conditional_ABE --
7291 ----------------------------------
7293 procedure Process_Call_Conditional_ABE
7294 (Call : Node_Id;
7295 Call_Attrs : Call_Attributes;
7296 Target_Id : Entity_Id;
7297 Target_Attrs : Target_Attributes;
7298 In_Partial_Fin : Boolean)
7300 Check_OK : constant Boolean :=
7301 not Call_Attrs.Ghost_Mode_Ignore
7302 and then not Target_Attrs.Ghost_Mode_Ignore
7303 and then Call_Attrs.Elab_Checks_OK
7304 and then Target_Attrs.Elab_Checks_OK;
7305 -- A run-time ABE check may be installed only when both the call and the
7306 -- target have active elaboration checks, and both are not ignored Ghost
7307 -- constructs.
7309 Root : constant Node_Id := Root_Scenario;
7311 begin
7312 -- If the root scenario appears prior to the target body, then this is a
7313 -- possible ABE with respect to the root scenario.
7315 -- function B ...;
7317 -- function A ... is
7318 -- begin
7319 -- if Some_Condition then
7320 -- return B; -- call site
7321 -- ...
7322 -- end A;
7324 -- X : ... := A; -- root scenario
7326 -- function B ... is -- target body
7327 -- ...
7328 -- end B;
7330 -- Y : ... := A; -- root scenario
7332 -- IMPORTANT: The call to B from A is a possible ABE for X, but not for
7333 -- Y. Installing an unconditional ABE raise prior to the call to B would
7334 -- be wrong as it will fail for Y as well, but in Y's case the call to B
7335 -- is never an ABE.
7337 if Earlier_In_Extended_Unit (Root, Target_Attrs.Body_Decl) then
7339 -- Do not emit any ABE diagnostics when the call occurs in a partial
7340 -- finalization context because this leads to confusing noise.
7342 if In_Partial_Fin then
7343 null;
7345 -- ABE diagnostics are emitted only in the static model because there
7346 -- is a well-defined order to visiting scenarios. Without this order
7347 -- diagnostics appear jumbled and result in unwanted noise.
7349 elsif Static_Elaboration_Checks then
7350 Error_Msg_NE ("??cannot call & before body seen", Call, Target_Id);
7351 Error_Msg_N ("\Program_Error may be raised at run time", Call);
7353 Output_Active_Scenarios (Call);
7354 end if;
7356 -- Install a conditional run-time ABE check to verify that the target
7357 -- body has been elaborated prior to the call.
7359 if Check_OK then
7360 Install_ABE_Check
7361 (N => Call,
7362 Ins_Nod => Call,
7363 Target_Id => Target_Attrs.Spec_Id,
7364 Target_Decl => Target_Attrs.Spec_Decl,
7365 Target_Body => Target_Attrs.Body_Decl);
7366 end if;
7367 end if;
7368 end Process_Call_Conditional_ABE;
7370 ---------------------------------
7371 -- Process_Call_Guaranteed_ABE --
7372 ---------------------------------
7374 procedure Process_Call_Guaranteed_ABE
7375 (Call : Node_Id;
7376 Call_Attrs : Call_Attributes;
7377 Target_Id : Entity_Id)
7379 Target_Attrs : Target_Attributes;
7381 begin
7382 Extract_Target_Attributes
7383 (Target_Id => Target_Id,
7384 Attrs => Target_Attrs);
7386 -- Nothing to do when the root scenario appears at the declaration level
7387 -- and the target is in the same unit, but outside this context.
7389 -- function B ...; -- target declaration
7391 -- procedure Proc is
7392 -- function A ... is
7393 -- begin
7394 -- if Some_Condition then
7395 -- return B; -- call site
7396 -- ...
7397 -- end A;
7399 -- X : ... := A; -- root scenario
7400 -- ...
7402 -- function B ... is
7403 -- ...
7404 -- end B;
7406 -- In the example above, the context of X is the declarative region of
7407 -- Proc. The "elaboration" of X may eventually reach B which is defined
7408 -- outside of X's context. B is relevant only when Proc is invoked, but
7409 -- this happens only by means of "normal" elaboration, therefore B must
7410 -- not be considered if this is not the case.
7412 -- Performance note: parent traversal
7414 if Is_Up_Level_Target (Target_Attrs.Spec_Decl) then
7415 return;
7417 -- Nothing to do when the call is ABE-safe
7419 -- generic
7420 -- function Gen ...;
7422 -- function Gen ... is
7423 -- begin
7424 -- ...
7425 -- end Gen;
7427 -- with Gen;
7428 -- procedure Main is
7429 -- function Inst is new Gen;
7430 -- X : ... := Inst; -- safe call
7431 -- ...
7433 elsif Is_Safe_Call (Call, Target_Attrs) then
7434 return;
7436 -- A call leads to a guaranteed ABE when the call and the target appear
7437 -- within the same context ignoring library levels, and the body of the
7438 -- target has not been seen yet or appears after the call.
7440 -- procedure Guaranteed_ABE is
7441 -- function Func ...;
7443 -- package Nested is
7444 -- Obj : ... := Func; -- guaranteed ABE
7445 -- end Nested;
7447 -- function Func ... is
7448 -- ...
7449 -- end Func;
7450 -- ...
7452 -- Performance note: parent traversal
7454 elsif Is_Guaranteed_ABE
7455 (N => Call,
7456 Target_Decl => Target_Attrs.Spec_Decl,
7457 Target_Body => Target_Attrs.Body_Decl)
7458 then
7459 Error_Msg_NE ("??cannot call & before body seen", Call, Target_Id);
7460 Error_Msg_N ("\Program_Error will be raised at run time", Call);
7462 -- Mark the call as a guarnateed ABE
7464 Set_Is_Known_Guaranteed_ABE (Call);
7466 -- Install a run-time ABE failure because the call will always result
7467 -- in an ABE. The failure is installed when both the call and target
7468 -- have enabled elaboration checks, and both are not ignored Ghost
7469 -- constructs.
7471 if Call_Attrs.Elab_Checks_OK
7472 and then Target_Attrs.Elab_Checks_OK
7473 and then not Call_Attrs.Ghost_Mode_Ignore
7474 and then not Target_Attrs.Ghost_Mode_Ignore
7475 then
7476 Install_ABE_Failure
7477 (N => Call,
7478 Ins_Nod => Call);
7479 end if;
7480 end if;
7481 end Process_Call_Guaranteed_ABE;
7483 ------------------------
7484 -- Process_Call_SPARK --
7485 ------------------------
7487 procedure Process_Call_SPARK
7488 (Call : Node_Id;
7489 Call_Attrs : Call_Attributes;
7490 Target_Id : Entity_Id;
7491 Target_Attrs : Target_Attributes;
7492 In_Partial_Fin : Boolean)
7494 begin
7495 -- A call to a source target or to a target which emulates Ada or SPARK
7496 -- semantics imposes an Elaborate_All requirement on the context of the
7497 -- main unit. Determine whether the context has a pragma strong enough
7498 -- to meet the requirement. The check is orthogonal to the ABE effects
7499 -- of the call.
7501 if Target_Attrs.From_Source
7502 or else Is_Ada_Semantic_Target (Target_Id)
7503 or else Is_SPARK_Semantic_Target (Target_Id)
7504 then
7505 Meet_Elaboration_Requirement
7506 (N => Call,
7507 Target_Id => Target_Id,
7508 Req_Nam => Name_Elaborate_All);
7509 end if;
7511 -- Nothing to do when the call is ABE-safe
7513 -- generic
7514 -- function Gen ...;
7516 -- function Gen ... is
7517 -- begin
7518 -- ...
7519 -- end Gen;
7521 -- with Gen;
7522 -- procedure Main is
7523 -- function Inst is new Gen;
7524 -- X : ... := Inst; -- safe call
7525 -- ...
7527 if Is_Safe_Call (Call, Target_Attrs) then
7528 return;
7530 -- The call and the target body are both in the main unit
7532 elsif Present (Target_Attrs.Body_Decl)
7533 and then In_Extended_Main_Code_Unit (Target_Attrs.Body_Decl)
7534 then
7535 Process_Call_Conditional_ABE
7536 (Call => Call,
7537 Call_Attrs => Call_Attrs,
7538 Target_Id => Target_Id,
7539 Target_Attrs => Target_Attrs,
7540 In_Partial_Fin => In_Partial_Fin);
7542 -- Otherwise the target body is not available in this compilation or it
7543 -- resides in an external unit. There is no need to guarantee the prior
7544 -- elaboration of the unit with the target body because either the main
7545 -- unit meets the Elaborate_All requirement imposed by the call, or the
7546 -- program is illegal.
7548 else
7549 null;
7550 end if;
7551 end Process_Call_SPARK;
7553 ----------------------------
7554 -- Process_Guaranteed_ABE --
7555 ----------------------------
7557 procedure Process_Guaranteed_ABE (N : Node_Id) is
7558 Call_Attrs : Call_Attributes;
7559 Target_Id : Entity_Id;
7561 begin
7562 -- Add the current scenario to the stack of active scenarios
7564 Push_Active_Scenario (N);
7566 -- Only calls, instantiations, and task activations may result in a
7567 -- guaranteed ABE.
7569 if Is_Suitable_Call (N) then
7570 Extract_Call_Attributes
7571 (Call => N,
7572 Target_Id => Target_Id,
7573 Attrs => Call_Attrs);
7575 if Is_Activation_Proc (Target_Id) then
7576 Process_Activation_Guaranteed_ABE
7577 (Call => N,
7578 Call_Attrs => Call_Attrs,
7579 In_Partial_Fin => False,
7580 In_Task_Body => False);
7582 else
7583 Process_Call_Guaranteed_ABE
7584 (Call => N,
7585 Call_Attrs => Call_Attrs,
7586 Target_Id => Target_Id);
7587 end if;
7589 elsif Is_Suitable_Instantiation (N) then
7590 Process_Instantiation_Guaranteed_ABE (N);
7591 end if;
7593 -- Remove the current scenario from the stack of active scenarios once
7594 -- all ABE diagnostics and checks have been performed.
7596 Pop_Active_Scenario (N);
7597 end Process_Guaranteed_ABE;
7599 ---------------------------
7600 -- Process_Instantiation --
7601 ---------------------------
7603 procedure Process_Instantiation
7604 (Exp_Inst : Node_Id;
7605 In_Partial_Fin : Boolean;
7606 In_Task_Body : Boolean)
7608 Gen_Attrs : Target_Attributes;
7609 Gen_Id : Entity_Id;
7610 Inst : Node_Id;
7611 Inst_Attrs : Instantiation_Attributes;
7612 Inst_Id : Entity_Id;
7614 SPARK_Rules_On : Boolean;
7615 -- This flag is set when the SPARK rules are in effect
7617 begin
7618 Extract_Instantiation_Attributes
7619 (Exp_Inst => Exp_Inst,
7620 Inst => Inst,
7621 Inst_Id => Inst_Id,
7622 Gen_Id => Gen_Id,
7623 Attrs => Inst_Attrs);
7625 Extract_Target_Attributes (Gen_Id, Gen_Attrs);
7627 -- The SPARK rules are in effect when both the instantiation and generic
7628 -- are subject to SPARK_Mode On.
7630 SPARK_Rules_On := Inst_Attrs.SPARK_Mode_On and Gen_Attrs.SPARK_Mode_On;
7632 -- Output relevant information when switch -gnatel (info messages on
7633 -- implicit Elaborate[_All] pragmas) is in effect.
7635 if Elab_Info_Messages then
7636 Info_Instantiation
7637 (Inst => Inst,
7638 Gen_Id => Gen_Id,
7639 Info_Msg => True,
7640 In_SPARK => SPARK_Rules_On);
7641 end if;
7643 -- Nothing to do when the instantiation is a guaranteed ABE
7645 if Is_Known_Guaranteed_ABE (Inst) then
7646 return;
7648 -- Nothing to do when the root scenario appears at the declaration level
7649 -- and the generic is in the same unit, but outside this context.
7651 -- generic
7652 -- procedure Gen is ...; -- generic declaration
7654 -- procedure Proc is
7655 -- function A ... is
7656 -- begin
7657 -- if Some_Condition then
7658 -- declare
7659 -- procedure I is new Gen; -- instantiation site
7660 -- ...
7661 -- ...
7662 -- end A;
7664 -- X : ... := A; -- root scenario
7665 -- ...
7667 -- procedure Gen is
7668 -- ...
7669 -- end Gen;
7671 -- In the example above, the context of X is the declarative region of
7672 -- Proc. The "elaboration" of X may eventually reach Gen which appears
7673 -- outside of X's context. Gen is relevant only when Proc is invoked,
7674 -- but this happens only by means of "normal" elaboration, therefore
7675 -- Gen must not be considered if this is not the case.
7677 -- Performance note: parent traversal
7679 elsif Is_Up_Level_Target (Gen_Attrs.Spec_Decl) then
7680 return;
7682 -- The SPARK rules are verified only when -gnatd.v (enforce SPARK
7683 -- elaboration rules in SPARK code) is in effect.
7685 elsif SPARK_Rules_On and Debug_Flag_Dot_V then
7686 Process_Instantiation_SPARK
7687 (Exp_Inst => Exp_Inst,
7688 Inst => Inst,
7689 Inst_Attrs => Inst_Attrs,
7690 Gen_Id => Gen_Id,
7691 Gen_Attrs => Gen_Attrs,
7692 In_Partial_Fin => In_Partial_Fin);
7694 -- Otherwise the Ada rules are in effect, or SPARK code is allowed to
7695 -- violate the SPARK rules.
7697 else
7698 Process_Instantiation_Ada
7699 (Exp_Inst => Exp_Inst,
7700 Inst => Inst,
7701 Inst_Attrs => Inst_Attrs,
7702 Gen_Id => Gen_Id,
7703 Gen_Attrs => Gen_Attrs,
7704 In_Partial_Fin => In_Partial_Fin,
7705 In_Task_Body => In_Task_Body);
7706 end if;
7707 end Process_Instantiation;
7709 -------------------------------
7710 -- Process_Instantiation_Ada --
7711 -------------------------------
7713 procedure Process_Instantiation_Ada
7714 (Exp_Inst : Node_Id;
7715 Inst : Node_Id;
7716 Inst_Attrs : Instantiation_Attributes;
7717 Gen_Id : Entity_Id;
7718 Gen_Attrs : Target_Attributes;
7719 In_Partial_Fin : Boolean;
7720 In_Task_Body : Boolean)
7722 Check_OK : constant Boolean :=
7723 not Inst_Attrs.Ghost_Mode_Ignore
7724 and then not Gen_Attrs.Ghost_Mode_Ignore
7725 and then Inst_Attrs.Elab_Checks_OK
7726 and then Gen_Attrs.Elab_Checks_OK;
7727 -- A run-time ABE check may be installed only when both the instance and
7728 -- the generic have active elaboration checks and both are not ignored
7729 -- Ghost constructs.
7731 begin
7732 -- Nothing to do when the instantiation is ABE-safe
7734 -- generic
7735 -- package Gen is
7736 -- ...
7737 -- end Gen;
7739 -- package body Gen is
7740 -- ...
7741 -- end Gen;
7743 -- with Gen;
7744 -- procedure Main is
7745 -- package Inst is new Gen (ABE); -- safe instantiation
7746 -- ...
7748 if Is_Safe_Instantiation (Inst, Gen_Attrs) then
7749 return;
7751 -- The instantiation and the generic body are both in the main unit
7753 elsif Present (Gen_Attrs.Body_Decl)
7754 and then In_Extended_Main_Code_Unit (Gen_Attrs.Body_Decl)
7755 then
7756 Process_Instantiation_Conditional_ABE
7757 (Exp_Inst => Exp_Inst,
7758 Inst => Inst,
7759 Inst_Attrs => Inst_Attrs,
7760 Gen_Id => Gen_Id,
7761 Gen_Attrs => Gen_Attrs,
7762 In_Partial_Fin => In_Partial_Fin);
7764 -- Otherwise the generic body is not available in this compilation or it
7765 -- resides in an external unit. Install a run-time ABE check to verify
7766 -- that the generic body has been elaborated prior to the instantiation
7767 -- when the dynamic model is in effect.
7769 elsif Dynamic_Elaboration_Checks and then Check_OK then
7770 Install_ABE_Check
7771 (N => Inst,
7772 Ins_Nod => Exp_Inst,
7773 Id => Gen_Attrs.Unit_Id);
7774 end if;
7776 -- Ensure that the unit with the generic body is elaborated prior to
7777 -- the main unit. No implicit pragma Elaborate[_All] is generated if
7778 -- the instantiation has elaboration checks suppressed. This behaviour
7779 -- parallels that of the old ABE mechanism.
7781 if Inst_Attrs.Elab_Checks_OK then
7782 Ensure_Prior_Elaboration
7783 (N => Inst,
7784 Unit_Id => Gen_Attrs.Unit_Id,
7785 In_Partial_Fin => In_Partial_Fin,
7786 In_Task_Body => In_Task_Body);
7787 end if;
7788 end Process_Instantiation_Ada;
7790 -------------------------------------------
7791 -- Process_Instantiation_Conditional_ABE --
7792 -------------------------------------------
7794 procedure Process_Instantiation_Conditional_ABE
7795 (Exp_Inst : Node_Id;
7796 Inst : Node_Id;
7797 Inst_Attrs : Instantiation_Attributes;
7798 Gen_Id : Entity_Id;
7799 Gen_Attrs : Target_Attributes;
7800 In_Partial_Fin : Boolean)
7802 Check_OK : constant Boolean :=
7803 not Inst_Attrs.Ghost_Mode_Ignore
7804 and then not Gen_Attrs.Ghost_Mode_Ignore
7805 and then Inst_Attrs.Elab_Checks_OK
7806 and then Gen_Attrs.Elab_Checks_OK;
7807 -- A run-time ABE check may be installed only when both the instance and
7808 -- the generic have active elaboration checks and both are not ignored
7809 -- Ghost constructs.
7811 Root : constant Node_Id := Root_Scenario;
7813 begin
7814 -- If the root scenario appears prior to the generic body, then this is
7815 -- a possible ABE with respect to the root scenario.
7817 -- generic
7818 -- package Gen is
7819 -- ...
7820 -- end Gen;
7822 -- function A ... is
7823 -- begin
7824 -- if Some_Condition then
7825 -- declare
7826 -- package Inst is new Gen; -- instantiation site
7827 -- ...
7828 -- end A;
7830 -- X : ... := A; -- root scenario
7832 -- package body Gen is -- generic body
7833 -- ...
7834 -- end Gen;
7836 -- Y : ... := A; -- root scenario
7838 -- IMPORTANT: The instantiation of Gen is a possible ABE for X, but not
7839 -- for Y. Installing an unconditional ABE raise prior to the instance
7840 -- site would be wrong as it will fail for Y as well, but in Y's case
7841 -- the instantiation of Gen is never an ABE.
7843 if Earlier_In_Extended_Unit (Root, Gen_Attrs.Body_Decl) then
7845 -- Do not emit any ABE diagnostics when the instantiation occurs in a
7846 -- partial finalization context because this leads to unwanted noise.
7848 if In_Partial_Fin then
7849 null;
7851 -- ABE diagnostics are emitted only in the static model because there
7852 -- is a well-defined order to visiting scenarios. Without this order
7853 -- diagnostics appear jumbled and result in unwanted noise.
7855 elsif Static_Elaboration_Checks then
7856 Error_Msg_NE
7857 ("??cannot instantiate & before body seen", Inst, Gen_Id);
7858 Error_Msg_N ("\Program_Error may be raised at run time", Inst);
7860 Output_Active_Scenarios (Inst);
7861 end if;
7863 -- Install a conditional run-time ABE check to verify that the
7864 -- generic body has been elaborated prior to the instantiation.
7866 if Check_OK then
7867 Install_ABE_Check
7868 (N => Inst,
7869 Ins_Nod => Exp_Inst,
7870 Target_Id => Gen_Attrs.Spec_Id,
7871 Target_Decl => Gen_Attrs.Spec_Decl,
7872 Target_Body => Gen_Attrs.Body_Decl);
7873 end if;
7874 end if;
7875 end Process_Instantiation_Conditional_ABE;
7877 ------------------------------------------
7878 -- Process_Instantiation_Guaranteed_ABE --
7879 ------------------------------------------
7881 procedure Process_Instantiation_Guaranteed_ABE (Exp_Inst : Node_Id) is
7882 Gen_Attrs : Target_Attributes;
7883 Gen_Id : Entity_Id;
7884 Inst : Node_Id;
7885 Inst_Attrs : Instantiation_Attributes;
7886 Inst_Id : Entity_Id;
7888 begin
7889 Extract_Instantiation_Attributes
7890 (Exp_Inst => Exp_Inst,
7891 Inst => Inst,
7892 Inst_Id => Inst_Id,
7893 Gen_Id => Gen_Id,
7894 Attrs => Inst_Attrs);
7896 Extract_Target_Attributes (Gen_Id, Gen_Attrs);
7898 -- Nothing to do when the root scenario appears at the declaration level
7899 -- and the generic is in the same unit, but outside this context.
7901 -- generic
7902 -- procedure Gen is ...; -- generic declaration
7904 -- procedure Proc is
7905 -- function A ... is
7906 -- begin
7907 -- if Some_Condition then
7908 -- declare
7909 -- procedure I is new Gen; -- instantiation site
7910 -- ...
7911 -- ...
7912 -- end A;
7914 -- X : ... := A; -- root scenario
7915 -- ...
7917 -- procedure Gen is
7918 -- ...
7919 -- end Gen;
7921 -- In the example above, the context of X is the declarative region of
7922 -- Proc. The "elaboration" of X may eventually reach Gen which appears
7923 -- outside of X's context. Gen is relevant only when Proc is invoked,
7924 -- but this happens only by means of "normal" elaboration, therefore
7925 -- Gen must not be considered if this is not the case.
7927 -- Performance note: parent traversal
7929 if Is_Up_Level_Target (Gen_Attrs.Spec_Decl) then
7930 return;
7932 -- Nothing to do when the instantiation is ABE-safe
7934 -- generic
7935 -- package Gen is
7936 -- ...
7937 -- end Gen;
7939 -- package body Gen is
7940 -- ...
7941 -- end Gen;
7943 -- with Gen;
7944 -- procedure Main is
7945 -- package Inst is new Gen (ABE); -- safe instantiation
7946 -- ...
7948 elsif Is_Safe_Instantiation (Inst, Gen_Attrs) then
7949 return;
7951 -- An instantiation leads to a guaranteed ABE when the instantiation and
7952 -- the generic appear within the same context ignoring library levels,
7953 -- and the body of the generic has not been seen yet or appears after
7954 -- the instantiation.
7956 -- procedure Guaranteed_ABE is
7957 -- generic
7958 -- procedure Gen;
7960 -- package Nested is
7961 -- procedure Inst is new Gen; -- guaranteed ABE
7962 -- end Nested;
7964 -- procedure Gen is
7965 -- ...
7966 -- end Gen;
7967 -- ...
7969 -- Performance note: parent traversal
7971 elsif Is_Guaranteed_ABE
7972 (N => Inst,
7973 Target_Decl => Gen_Attrs.Spec_Decl,
7974 Target_Body => Gen_Attrs.Body_Decl)
7975 then
7976 Error_Msg_NE
7977 ("??cannot instantiate & before body seen", Inst, Gen_Id);
7978 Error_Msg_N ("\Program_Error will be raised at run time", Inst);
7980 -- Mark the instantiation as a guarantee ABE. This automatically
7981 -- suppresses the instantiation of the generic body.
7983 Set_Is_Known_Guaranteed_ABE (Inst);
7985 -- Install a run-time ABE failure because the instantiation will
7986 -- always result in an ABE. The failure is installed when both the
7987 -- instance and the generic have enabled elaboration checks, and both
7988 -- are not ignored Ghost constructs.
7990 if Inst_Attrs.Elab_Checks_OK
7991 and then Gen_Attrs.Elab_Checks_OK
7992 and then not Inst_Attrs.Ghost_Mode_Ignore
7993 and then not Gen_Attrs.Ghost_Mode_Ignore
7994 then
7995 Install_ABE_Failure
7996 (N => Inst,
7997 Ins_Nod => Exp_Inst);
7998 end if;
7999 end if;
8000 end Process_Instantiation_Guaranteed_ABE;
8002 ---------------------------------
8003 -- Process_Instantiation_SPARK --
8004 ---------------------------------
8006 procedure Process_Instantiation_SPARK
8007 (Exp_Inst : Node_Id;
8008 Inst : Node_Id;
8009 Inst_Attrs : Instantiation_Attributes;
8010 Gen_Id : Entity_Id;
8011 Gen_Attrs : Target_Attributes;
8012 In_Partial_Fin : Boolean)
8014 Req_Nam : Name_Id;
8016 begin
8017 -- A source instantiation imposes an Elaborate[_All] requirement on the
8018 -- context of the main unit. Determine whether the context has a pragma
8019 -- strong enough to meet the requirement. The check is orthogonal to the
8020 -- ABE ramifications of the instantiation.
8022 if Nkind (Inst) = N_Package_Instantiation then
8023 Req_Nam := Name_Elaborate_All;
8024 else
8025 Req_Nam := Name_Elaborate;
8026 end if;
8028 Meet_Elaboration_Requirement
8029 (N => Inst,
8030 Target_Id => Gen_Id,
8031 Req_Nam => Req_Nam);
8033 -- Nothing to do when the instantiation is ABE-safe
8035 -- generic
8036 -- package Gen is
8037 -- ...
8038 -- end Gen;
8040 -- package body Gen is
8041 -- ...
8042 -- end Gen;
8044 -- with Gen;
8045 -- procedure Main is
8046 -- package Inst is new Gen (ABE); -- safe instantiation
8047 -- ...
8049 if Is_Safe_Instantiation (Inst, Gen_Attrs) then
8050 return;
8052 -- The instantiation and the generic body are both in the main unit
8054 elsif Present (Gen_Attrs.Body_Decl)
8055 and then In_Extended_Main_Code_Unit (Gen_Attrs.Body_Decl)
8056 then
8057 Process_Instantiation_Conditional_ABE
8058 (Exp_Inst => Exp_Inst,
8059 Inst => Inst,
8060 Inst_Attrs => Inst_Attrs,
8061 Gen_Id => Gen_Id,
8062 Gen_Attrs => Gen_Attrs,
8063 In_Partial_Fin => In_Partial_Fin);
8065 -- Otherwise the generic body is not available in this compilation or
8066 -- it resides in an external unit. There is no need to guarantee the
8067 -- prior elaboration of the unit with the generic body because either
8068 -- the main unit meets the Elaborate[_All] requirement imposed by the
8069 -- instantiation, or the program is illegal.
8071 else
8072 null;
8073 end if;
8074 end Process_Instantiation_SPARK;
8076 ---------------------------------
8077 -- Process_Variable_Assignment --
8078 ---------------------------------
8080 procedure Process_Variable_Assignment (Asmt : Node_Id) is
8081 Var_Id : constant Entity_Id := Entity (Extract_Assignment_Name (Asmt));
8082 Prag : constant Node_Id := SPARK_Pragma (Var_Id);
8084 SPARK_Rules_On : Boolean;
8085 -- This flag is set when the SPARK rules are in effect
8087 begin
8088 -- The SPARK rules are in effect when both the assignment and the
8089 -- variable are subject to SPARK_Mode On.
8091 SPARK_Rules_On :=
8092 Present (Prag)
8093 and then Get_SPARK_Mode_From_Annotation (Prag) = On
8094 and then Is_SPARK_Mode_On_Node (Asmt);
8096 -- Output relevant information when switch -gnatel (info messages on
8097 -- implicit Elaborate[_All] pragmas) is in effect.
8099 if Elab_Info_Messages then
8100 Elab_Msg_NE
8101 (Msg => "assignment to & during elaboration",
8102 N => Asmt,
8103 Id => Var_Id,
8104 Info_Msg => True,
8105 In_SPARK => SPARK_Rules_On);
8106 end if;
8108 -- The SPARK rules are in effect. These rules are applied regardless of
8109 -- whether -gnatd.v (enforce SPARK elaboration rules in SPARK code) is
8110 -- in effect because the static model cannot ensure safe assignment of
8111 -- variables.
8113 if SPARK_Rules_On then
8114 Process_Variable_Assignment_SPARK
8115 (Asmt => Asmt,
8116 Var_Id => Var_Id);
8118 -- Otherwise the Ada rules are in effect
8120 else
8121 Process_Variable_Assignment_Ada
8122 (Asmt => Asmt,
8123 Var_Id => Var_Id);
8124 end if;
8125 end Process_Variable_Assignment;
8127 -------------------------------------
8128 -- Process_Variable_Assignment_Ada --
8129 -------------------------------------
8131 procedure Process_Variable_Assignment_Ada
8132 (Asmt : Node_Id;
8133 Var_Id : Entity_Id)
8135 Var_Decl : constant Node_Id := Declaration_Node (Var_Id);
8136 Spec_Id : constant Entity_Id := Find_Top_Unit (Var_Decl);
8138 begin
8139 -- Emit a warning when an uninitialized variable declared in a package
8140 -- spec without a pragma Elaborate_Body is initialized by elaboration
8141 -- code within the corresponding body.
8143 if not Warnings_Off (Var_Id)
8144 and then not Is_Initialized (Var_Decl)
8145 and then not Has_Pragma_Elaborate_Body (Spec_Id)
8146 then
8147 -- Generate an implicit Elaborate_Body in the spec
8149 Set_Elaborate_Body_Desirable (Spec_Id);
8151 Error_Msg_NE
8152 ("??variable & can be accessed by clients before this "
8153 & "initialization", Asmt, Var_Id);
8155 Error_Msg_NE
8156 ("\add pragma ""Elaborate_Body"" to spec & to ensure proper "
8157 & "initialization", Asmt, Spec_Id);
8159 Output_Active_Scenarios (Asmt);
8160 end if;
8161 end Process_Variable_Assignment_Ada;
8163 ---------------------------------------
8164 -- Process_Variable_Assignment_SPARK --
8165 ---------------------------------------
8167 procedure Process_Variable_Assignment_SPARK
8168 (Asmt : Node_Id;
8169 Var_Id : Entity_Id)
8171 Var_Decl : constant Node_Id := Declaration_Node (Var_Id);
8172 Spec_Id : constant Entity_Id := Find_Top_Unit (Var_Decl);
8174 begin
8175 -- Emit an error when an initialized variable declared in a package spec
8176 -- without pragma Elaborate_Body is further modified by elaboration code
8177 -- within the corresponding body.
8179 if Is_Initialized (Var_Decl)
8180 and then not Has_Pragma_Elaborate_Body (Spec_Id)
8181 then
8182 Error_Msg_NE
8183 ("variable & modified by elaboration code in package body",
8184 Asmt, Var_Id);
8186 Error_Msg_NE
8187 ("\add pragma ""Elaborate_Body"" to spec & to ensure full "
8188 & "initialization", Asmt, Spec_Id);
8190 Output_Active_Scenarios (Asmt);
8191 end if;
8192 end Process_Variable_Assignment_SPARK;
8194 --------------------------------
8195 -- Process_Variable_Reference --
8196 --------------------------------
8198 procedure Process_Variable_Reference (Ref : Node_Id) is
8199 Var_Attrs : Variable_Attributes;
8200 Var_Id : Entity_Id;
8202 begin
8203 Extract_Variable_Reference_Attributes
8204 (Ref => Ref,
8205 Var_Id => Var_Id,
8206 Attrs => Var_Attrs);
8208 if Is_Read (Ref) then
8209 Process_Variable_Reference_Read
8210 (Ref => Ref,
8211 Var_Id => Var_Id,
8212 Attrs => Var_Attrs);
8213 end if;
8214 end Process_Variable_Reference;
8216 -------------------------------------
8217 -- Process_Variable_Reference_Read --
8218 -------------------------------------
8220 procedure Process_Variable_Reference_Read
8221 (Ref : Node_Id;
8222 Var_Id : Entity_Id;
8223 Attrs : Variable_Attributes)
8225 begin
8226 -- Output relevant information when switch -gnatel (info messages on
8227 -- implicit Elaborate[_All] pragmas) is in effect.
8229 if Elab_Info_Messages then
8230 Elab_Msg_NE
8231 (Msg => "read of variable & during elaboration",
8232 N => Ref,
8233 Id => Var_Id,
8234 Info_Msg => True,
8235 In_SPARK => True);
8236 end if;
8238 -- Nothing to do when the variable appears within the main unit because
8239 -- diagnostics on reads are relevant only for external variables.
8241 if Is_Same_Unit (Attrs.Unit_Id, Cunit_Entity (Main_Unit)) then
8242 null;
8244 -- Nothing to do when the variable is already initialized. Note that the
8245 -- variable may be further modified by the external unit.
8247 elsif Is_Initialized (Declaration_Node (Var_Id)) then
8248 null;
8250 -- Nothing to do when the external unit guarantees the initialization of
8251 -- the variable by means of pragma Elaborate_Body.
8253 elsif Has_Pragma_Elaborate_Body (Attrs.Unit_Id) then
8254 null;
8256 -- A variable read imposes an Elaborate requirement on the context of
8257 -- the main unit. Determine whether the context has a pragma strong
8258 -- enough to meet the requirement.
8260 else
8261 Meet_Elaboration_Requirement
8262 (N => Ref,
8263 Target_Id => Var_Id,
8264 Req_Nam => Name_Elaborate);
8265 end if;
8266 end Process_Variable_Reference_Read;
8268 --------------------------
8269 -- Push_Active_Scenario --
8270 --------------------------
8272 procedure Push_Active_Scenario (N : Node_Id) is
8273 begin
8274 Scenario_Stack.Append (N);
8275 end Push_Active_Scenario;
8277 ----------------------
8278 -- Process_Scenario --
8279 ----------------------
8281 procedure Process_Scenario
8282 (N : Node_Id;
8283 In_Partial_Fin : Boolean := False;
8284 In_Task_Body : Boolean := False)
8286 Call_Attrs : Call_Attributes;
8287 Target_Id : Entity_Id;
8289 begin
8290 -- Add the current scenario to the stack of active scenarios
8292 Push_Active_Scenario (N);
8294 -- 'Access
8296 if Is_Suitable_Access (N) then
8297 Process_Access (N, In_Partial_Fin, In_Task_Body);
8299 -- Calls
8301 elsif Is_Suitable_Call (N) then
8303 -- In general, only calls found within the main unit are processed
8304 -- because the ALI information supplied to binde is for the main
8305 -- unit only. However, to preserve the consistency of the tree and
8306 -- ensure proper serialization of internal names, external calls
8307 -- also receive corresponding call markers (see Build_Call_Marker).
8308 -- Regardless of the reason, external calls must not be processed.
8310 if In_Main_Context (N) then
8311 Extract_Call_Attributes
8312 (Call => N,
8313 Target_Id => Target_Id,
8314 Attrs => Call_Attrs);
8316 if Is_Activation_Proc (Target_Id) then
8317 Process_Activation_Conditional_ABE
8318 (Call => N,
8319 Call_Attrs => Call_Attrs,
8320 In_Partial_Fin => In_Partial_Fin,
8321 In_Task_Body => In_Task_Body);
8323 else
8324 Process_Call
8325 (Call => N,
8326 Call_Attrs => Call_Attrs,
8327 Target_Id => Target_Id,
8328 In_Partial_Fin => In_Partial_Fin,
8329 In_Task_Body => In_Task_Body);
8330 end if;
8331 end if;
8333 -- Instantiations
8335 elsif Is_Suitable_Instantiation (N) then
8336 Process_Instantiation (N, In_Partial_Fin, In_Task_Body);
8338 -- Variable assignments
8340 elsif Is_Suitable_Variable_Assignment (N) then
8341 Process_Variable_Assignment (N);
8343 -- Variable references
8345 elsif Is_Suitable_Variable_Reference (N) then
8347 -- In general, only variable references found within the main unit
8348 -- are processed because the ALI information supplied to binde is for
8349 -- the main unit only. However, to preserve the consistency of the
8350 -- tree and ensure proper serialization of internal names, external
8351 -- variable references also receive corresponding variable reference
8352 -- markers (see Build_Varaible_Reference_Marker). Regardless of the
8353 -- reason, external variable references must not be processed.
8355 if In_Main_Context (N) then
8356 Process_Variable_Reference (N);
8357 end if;
8358 end if;
8360 -- Remove the current scenario from the stack of active scenarios once
8361 -- all ABE diagnostics and checks have been performed.
8363 Pop_Active_Scenario (N);
8364 end Process_Scenario;
8366 ---------------------------------
8367 -- Record_Elaboration_Scenario --
8368 ---------------------------------
8370 procedure Record_Elaboration_Scenario (N : Node_Id) is
8371 Level : Enclosing_Level_Kind;
8373 Declaration_Level_OK : Boolean;
8374 -- This flag is set when a particular scenario is allowed to appear at
8375 -- the declaration level.
8377 begin
8378 -- Assume that the scenario must not appear at the declaration level
8380 Declaration_Level_OK := False;
8382 -- Nothing to do for ASIS. As a result, no ABE checks and diagnostics
8383 -- are performed in this mode.
8385 if ASIS_Mode then
8386 return;
8388 -- Nothing to do when the scenario is being preanalyzed
8390 elsif Preanalysis_Active then
8391 return;
8392 end if;
8394 -- Ensure that a library-level call does not appear in a preelaborated
8395 -- unit. The check must come before ignoring scenarios within external
8396 -- units or inside generics because calls in those context must also be
8397 -- verified.
8399 if Is_Suitable_Call (N) then
8400 Check_Preelaborated_Call (N);
8401 end if;
8403 -- Nothing to do when the scenario does not appear within the main unit
8405 if not In_Main_Context (N) then
8406 return;
8408 -- Scenarios within a generic unit are never considered because generics
8409 -- cannot be elaborated.
8411 elsif Inside_A_Generic then
8412 return;
8414 -- Scenarios which do not fall in one of the elaboration categories
8415 -- listed below are not considered. The categories are:
8417 -- 'Access for entries, operators, and subprograms
8418 -- Assignments to variables
8419 -- Calls (includes task activation)
8420 -- Instantiations
8421 -- Reads of variables
8423 elsif Is_Suitable_Access (N) then
8425 -- Signal any enclosing local exception handlers that the 'Access may
8426 -- raise Program_Error due to a failed ABE check when switch -gnatd.o
8427 -- (conservative elaboration order for indirect calls) is in effect.
8428 -- Marking the exception handlers ensures proper expansion by both
8429 -- the front and back end restriction when No_Exception_Propagation
8430 -- is in effect.
8432 if Debug_Flag_Dot_O then
8433 Possible_Local_Raise (N, Standard_Program_Error);
8434 end if;
8436 elsif Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N) then
8437 Declaration_Level_OK := True;
8439 -- Signal any enclosing local exception handlers that the call or
8440 -- instantiation may raise Program_Error due to a failed ABE check.
8441 -- Marking the exception handlers ensures proper expansion by both
8442 -- the front and back end restriction when No_Exception_Propagation
8443 -- is in effect.
8445 Possible_Local_Raise (N, Standard_Program_Error);
8447 elsif Is_Suitable_Variable_Assignment (N)
8448 or else Is_Suitable_Variable_Reference (N)
8449 then
8450 null;
8452 -- Otherwise the input does not denote a suitable scenario
8454 else
8455 return;
8456 end if;
8458 -- The static model imposes additional restrictions on the placement of
8459 -- scenarios. In contrast, the dynamic model assumes that every scenario
8460 -- will be elaborated or invoked at some point.
8462 if Static_Elaboration_Checks then
8464 -- Performance note: parent traversal
8466 Level := Find_Enclosing_Level (N);
8468 -- Declaration-level scenario
8470 if Declaration_Level_OK and then Level = Declaration_Level then
8471 null;
8473 -- Library-level scenario
8475 elsif Level in Library_Level then
8476 null;
8478 -- Instantiation library-level scenario
8480 elsif Level = Instantiation then
8481 null;
8483 -- Otherwise the scenario does not appear at the proper level and
8484 -- cannot possibly act as a top-level scenario.
8486 else
8487 return;
8488 end if;
8489 end if;
8491 -- Perform early detection of guaranteed ABEs in order to suppress the
8492 -- instantiation of generic bodies as gigi cannot handle certain types
8493 -- of premature instantiations.
8495 Process_Guaranteed_ABE (N);
8497 -- At this point all checks have been performed. Record the scenario for
8498 -- later processing by the ABE phase.
8500 Top_Level_Scenarios.Append (N);
8501 Set_Is_Recorded_Top_Level_Scenario (N);
8502 end Record_Elaboration_Scenario;
8504 ---------------------------------------
8505 -- Recorded_Top_Level_Scenarios_Hash --
8506 ---------------------------------------
8508 function Recorded_Top_Level_Scenarios_Hash
8509 (Key : Node_Id) return Recorded_Top_Level_Scenarios_Index
8511 begin
8512 return
8513 Recorded_Top_Level_Scenarios_Index
8514 (Key mod Recorded_Top_Level_Scenarios_Max);
8515 end Recorded_Top_Level_Scenarios_Hash;
8517 -------------------
8518 -- Root_Scenario --
8519 -------------------
8521 function Root_Scenario return Node_Id is
8522 package Stack renames Scenario_Stack;
8524 begin
8525 -- Ensure that the scenario stack has at least one active scenario in
8526 -- it. The one at the bottom (index First) is the root scenario.
8528 pragma Assert (Stack.Last >= Stack.First);
8529 return Stack.Table (Stack.First);
8530 end Root_Scenario;
8532 ----------------------------------------
8533 -- Set_Is_Recorded_Top_Level_Scenario --
8534 ----------------------------------------
8536 procedure Set_Is_Recorded_Top_Level_Scenario
8537 (N : Node_Id;
8538 Val : Boolean := True)
8540 begin
8541 Recorded_Top_Level_Scenarios.Set (N, Val);
8542 end Set_Is_Recorded_Top_Level_Scenario;
8544 -------------------------------
8545 -- Static_Elaboration_Checks --
8546 -------------------------------
8548 function Static_Elaboration_Checks return Boolean is
8549 begin
8550 return not Dynamic_Elaboration_Checks;
8551 end Static_Elaboration_Checks;
8553 -------------------
8554 -- Traverse_Body --
8555 -------------------
8557 procedure Traverse_Body
8558 (N : Node_Id;
8559 In_Partial_Fin : Boolean;
8560 In_Task_Body : Boolean)
8562 procedure Find_And_Process_Nested_Scenarios;
8563 pragma Inline (Find_And_Process_Nested_Scenarios);
8564 -- Examine the declarations and statements of subprogram body N for
8565 -- suitable scenarios. Save each discovered scenario and process it
8566 -- accordingly.
8568 procedure Process_Nested_Scenarios (Nested : Elist_Id);
8569 pragma Inline (Process_Nested_Scenarios);
8570 -- Invoke Process_Scenario on each individual scenario whith appears in
8571 -- list Nested.
8573 ---------------------------------------
8574 -- Find_And_Process_Nested_Scenarios --
8575 ---------------------------------------
8577 procedure Find_And_Process_Nested_Scenarios is
8578 Body_Id : constant Entity_Id := Defining_Entity (N);
8580 function Is_Potential_Scenario
8581 (Nod : Node_Id) return Traverse_Result;
8582 -- Determine whether arbitrary node Nod denotes a suitable scenario.
8583 -- If it does, save it in the Nested_Scenarios list of the subprogram
8584 -- body, and process it.
8586 procedure Save_Scenario (Nod : Node_Id);
8587 pragma Inline (Save_Scenario);
8588 -- Save scenario Nod in the Nested_Scenarios list of the subprogram
8589 -- body.
8591 procedure Traverse_List (List : List_Id);
8592 pragma Inline (Traverse_List);
8593 -- Invoke Traverse_Potential_Scenarios on each node in list List
8595 procedure Traverse_Potential_Scenarios is
8596 new Traverse_Proc (Is_Potential_Scenario);
8598 ---------------------------
8599 -- Is_Potential_Scenario --
8600 ---------------------------
8602 function Is_Potential_Scenario
8603 (Nod : Node_Id) return Traverse_Result
8605 begin
8606 -- Special cases
8608 -- Skip constructs which do not have elaboration of their own and
8609 -- need to be elaborated by other means such as invocation, task
8610 -- activation, etc.
8612 if Is_Non_Library_Level_Encapsulator (Nod) then
8613 return Skip;
8615 -- Terminate the traversal of a task body with an accept statement
8616 -- when no entry calls in elaboration are allowed because the task
8617 -- will block at run-time and the remaining statements will not be
8618 -- executed.
8620 elsif Nkind_In (Original_Node (Nod), N_Accept_Statement,
8621 N_Selective_Accept)
8622 and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
8623 then
8624 return Abandon;
8626 -- Certain nodes carry semantic lists which act as repositories
8627 -- until expansion transforms the node and relocates the contents.
8628 -- Examine these lists in case expansion is disabled.
8630 elsif Nkind_In (Nod, N_And_Then, N_Or_Else) then
8631 Traverse_List (Actions (Nod));
8633 elsif Nkind_In (Nod, N_Elsif_Part, N_Iteration_Scheme) then
8634 Traverse_List (Condition_Actions (Nod));
8636 elsif Nkind (Nod) = N_If_Expression then
8637 Traverse_List (Then_Actions (Nod));
8638 Traverse_List (Else_Actions (Nod));
8640 elsif Nkind_In (Nod, N_Component_Association,
8641 N_Iterated_Component_Association)
8642 then
8643 Traverse_List (Loop_Actions (Nod));
8645 -- General case
8647 -- Save a suitable scenario in the Nested_Scenarios list of the
8648 -- subprogram body. As a result any subsequent traversals of the
8649 -- subprogram body started from a different top-level scenario no
8650 -- longer need to reexamine the tree.
8652 elsif Is_Suitable_Scenario (Nod) then
8653 Save_Scenario (Nod);
8654 Process_Scenario (Nod, In_Partial_Fin, In_Task_Body);
8655 end if;
8657 return OK;
8658 end Is_Potential_Scenario;
8660 -------------------
8661 -- Save_Scenario --
8662 -------------------
8664 procedure Save_Scenario (Nod : Node_Id) is
8665 Nested : Elist_Id;
8667 begin
8668 Nested := Nested_Scenarios (Body_Id);
8670 if No (Nested) then
8671 Nested := New_Elmt_List;
8672 Set_Nested_Scenarios (Body_Id, Nested);
8673 end if;
8675 Append_Elmt (Nod, Nested);
8676 end Save_Scenario;
8678 -------------------
8679 -- Traverse_List --
8680 -------------------
8682 procedure Traverse_List (List : List_Id) is
8683 Item : Node_Id;
8685 begin
8686 Item := First (List);
8687 while Present (Item) loop
8688 Traverse_Potential_Scenarios (Item);
8689 Next (Item);
8690 end loop;
8691 end Traverse_List;
8693 -- Start of processing for Find_And_Process_Nested_Scenarios
8695 begin
8696 -- Examine the declarations for suitable scenarios
8698 Traverse_List (Declarations (N));
8700 -- Examine the handled sequence of statements. This also includes any
8701 -- exceptions handlers.
8703 Traverse_Potential_Scenarios (Handled_Statement_Sequence (N));
8704 end Find_And_Process_Nested_Scenarios;
8706 ------------------------------
8707 -- Process_Nested_Scenarios --
8708 ------------------------------
8710 procedure Process_Nested_Scenarios (Nested : Elist_Id) is
8711 Nested_Elmt : Elmt_Id;
8713 begin
8714 Nested_Elmt := First_Elmt (Nested);
8715 while Present (Nested_Elmt) loop
8716 Process_Scenario
8717 (N => Node (Nested_Elmt),
8718 In_Partial_Fin => In_Partial_Fin,
8719 In_Task_Body => In_Task_Body);
8721 Next_Elmt (Nested_Elmt);
8722 end loop;
8723 end Process_Nested_Scenarios;
8725 -- Local variables
8727 Nested : Elist_Id;
8729 -- Start of processing for Traverse_Body
8731 begin
8732 -- Nothing to do when there is no body
8734 if No (N) then
8735 return;
8737 elsif Nkind (N) /= N_Subprogram_Body then
8738 return;
8739 end if;
8741 -- Nothing to do if the body was already traversed during the processing
8742 -- of the same top-level scenario.
8744 if Visited_Bodies.Get (N) then
8745 return;
8747 -- Otherwise mark the body as traversed
8749 else
8750 Visited_Bodies.Set (N, True);
8751 end if;
8753 Nested := Nested_Scenarios (Defining_Entity (N));
8755 -- The subprogram body was already examined as part of the elaboration
8756 -- graph starting from a different top-level scenario. There is no need
8757 -- to traverse the declarations and statements again because this will
8758 -- yield the exact same scenarios. Use the nested scenarios collected
8759 -- during the first inspection of the body.
8761 if Present (Nested) then
8762 Process_Nested_Scenarios (Nested);
8764 -- Otherwise examine the declarations and statements of the subprogram
8765 -- body for suitable scenarios, save and process them accordingly.
8767 else
8768 Find_And_Process_Nested_Scenarios;
8769 end if;
8770 end Traverse_Body;
8772 ---------------------------------
8773 -- Update_Elaboration_Scenario --
8774 ---------------------------------
8776 procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id) is
8777 package Scenarios renames Top_Level_Scenarios;
8779 begin
8780 -- Nothing to do when the old and new scenarios are one and the same
8782 if Old_N = New_N then
8783 return;
8785 -- A scenario is being transformed by Atree.Rewrite. Update all relevant
8786 -- internal data structures to reflect this change. This ensures that a
8787 -- potential run-time conditional ABE check or a guaranteed ABE failure
8788 -- is inserted at the proper place in the tree.
8790 elsif Is_Scenario (Old_N)
8791 and then Is_Recorded_Top_Level_Scenario (Old_N)
8792 then
8793 -- Performance note: list traversal
8795 for Index in Scenarios.First .. Scenarios.Last loop
8796 if Scenarios.Table (Index) = Old_N then
8797 Scenarios.Table (Index) := New_N;
8799 -- The old top-level scenario is no longer recorded, but the
8800 -- new one is.
8802 Set_Is_Recorded_Top_Level_Scenario (Old_N, False);
8803 Set_Is_Recorded_Top_Level_Scenario (New_N);
8804 return;
8805 end if;
8806 end loop;
8808 -- A recorded top-level scenario must be in the table of recorded
8809 -- top-level scenarios.
8811 pragma Assert (False);
8812 end if;
8813 end Update_Elaboration_Scenario;
8815 -------------------------
8816 -- Visited_Bodies_Hash --
8817 -------------------------
8819 function Visited_Bodies_Hash (Key : Node_Id) return Visited_Bodies_Index is
8820 begin
8821 return Visited_Bodies_Index (Key mod Visited_Bodies_Max);
8822 end Visited_Bodies_Hash;
8824 end Sem_Elab;