1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1997-2017, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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;
35 with Lib.Load; use Lib.Load;
36 with Namet; use Namet;
37 with Nlists; use Nlists;
38 with Nmake; use Nmake;
40 with Restrict; use Restrict;
41 with Rident; use Rident;
42 with Rtsfind; use Rtsfind;
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;
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"
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 -- * Early call region - A section of code which ends at a subprogram body
134 -- and starts from the nearest non-preelaborable construct which precedes
135 -- the subprogram body. The early call region extends from a package body
136 -- to a package spec when the spec carries pragma Elaborate_Body.
138 -- * Generic library level - A type of enclosing level. A scenario or
139 -- target is at the generic library level if it appears in a generic
140 -- package library unit, ignoring enclosing packages.
142 -- * Guaranteed ABE - A type of ABE. A guaranteed ABE occurs when the
143 -- elaboration or invocation of a target by all scenarios within the
144 -- main unit causes an ABE.
146 -- * Instantiation library level - A type of enclosing level. A scenario
147 -- or target is at the instantiation library level if it appears in an
148 -- instantiation library unit, ignoring enclosing packages.
150 -- * Library level - A type of enclosing level. A scenario or target is at
151 -- the library level if it appears in a package library unit, ignoring
152 -- enclosng packages.
154 -- * Non-library-level encapsulator - A construct that cannot be elaborated
155 -- on its own and requires elaboration by a top-level scenario.
157 -- * Scenario - A construct or context which may be elaborated or executed
158 -- by elaboration code. The scenarios recognized by the ABE mechanism are
161 -- - '[Unrestricted_]Access of entries, operators, and subprograms
163 -- - Assignments to variables
165 -- - Calls to entries, operators, and subprograms
167 -- - Derived type declarations
171 -- - Pragma Refined_State
173 -- - Reads of variables
177 -- * Target - A construct referenced by a scenario. The targets recognized
178 -- by the ABE mechanism are as follows:
180 -- - For '[Unrestricted_]Access of entries, operators, and subprograms,
181 -- the target is the entry, operator, or subprogram.
183 -- - For assignments to variables, the target is the variable
185 -- - For calls, the target is the entry, operator, or subprogram
187 -- - For derived type declarations, the target is the derived type
189 -- - For instantiations, the target is the generic template
191 -- - For pragma Refined_State, the targets are the constituents
193 -- - For reads of variables, the target is the variable
195 -- - For task activation, the target is the task body
197 -- * Top-level scenario - A scenario which appears in a non-generic main
198 -- unit. Depending on the elaboration model is in effect, the following
199 -- addotional restrictions apply:
201 -- - Dynamic model - No restrictions
203 -- - SPARK model - Falls back to either the dynamic or static model
205 -- - Static model - The scenario must be at the library level
207 ---------------------
208 -- Recording phase --
209 ---------------------
211 -- The Recording phase coincides with the analysis/resolution phase of the
212 -- compiler. It has the following objectives:
214 -- * Record all top-level scenarios for examination by the Processing
217 -- Saving only a certain number of nodes improves the performance of
218 -- the ABE mechanism. This eliminates the need to examine the whole
219 -- tree in a separate pass.
221 -- * Record certain SPARK scenarios which are not necessarily executable
222 -- during elaboration, but still require elaboration-related checks.
224 -- Saving only a certain number of nodes improves the performance of
225 -- the ABE mechanism. This eliminates the need to examine the whole
226 -- tree in a separate pass.
228 -- * Detect and diagnose calls in preelaborable or pure units, including
231 -- This diagnostic is carried out during the Recording phase because it
232 -- does not need the heavy recursive traversal done by the Processing
235 -- * Detect and diagnose guaranteed ABEs caused by instantiations,
236 -- calls, and task activation.
238 -- The issues detected by the ABE mechanism are reported as warnings
239 -- because they do not violate Ada semantics. Forward instantiations
240 -- may thus reach gigi, however gigi cannot handle certain kinds of
241 -- premature instantiations and may crash. To avoid this limitation,
242 -- the ABE mechanism must identify forward instantiations as early as
243 -- possible and suppress their bodies. Calls and task activations are
244 -- included in this category for completeness.
246 ----------------------
247 -- Processing phase --
248 ----------------------
250 -- The Processing phase is a separate pass which starts after instantiating
251 -- and/or inlining of bodies, but before the removal of Ghost code. It has
252 -- the following objectives:
254 -- * Examine all top-level scenarios saved during the Recording phase
256 -- The top-level scenarios act as roots for depth-first traversal of
257 -- the call/instantiation/task activation graph. The traversal stops
258 -- when an outgoing edge leaves the main unit.
260 -- * Examine all SPARK scenarios saved during the Recording phase
262 -- * Depending on the elaboration model in effect, perform the following
265 -- - Dynamic model - Diagnose guaranteed ABEs and install run-time
266 -- conditional ABE checks.
268 -- - SPARK model - Enforce the SPARK elaboration rules
270 -- - Static model - Diagnose conditional/guaranteed ABEs, install
271 -- run-time conditional ABE checks, and guarantee the elaboration
272 -- of external units.
274 -- * Examine nested scenarios
276 -- Nested scenarios discovered during the depth-first traversal are
277 -- in turn subjected to the same actions outlined above and examined
278 -- for the next level of nested scenarios.
284 -- Analysis/Resolution
286 -- +- Build_Call_Marker
288 -- +- Build_Variable_Reference_Marker
290 -- +- | -------------------- Recording phase ---------------------------+
292 -- | Record_Elaboration_Scenario |
294 -- | +--> Check_Preelaborated_Call |
296 -- | +--> Process_Guaranteed_ABE |
298 -- | | +--> Process_Guaranteed_ABE_Activation |
300 -- | | +--> Process_Guaranteed_ABE_Call |
302 -- | | +--> Process_Guaranteed_ABE_Instantiation |
304 -- +- | ----------------------------------------------------------------+
307 -- +--> SPARK_Scenarios
308 -- | +-----------+-----------+ .. +-----------+
309 -- | | Scenario1 | Scenario2 | .. | ScenarioN |
310 -- | +-----------+-----------+ .. +-----------+
312 -- +--> Top_Level_Scenarios
313 -- | +-----------+-----------+ .. +-----------+
314 -- | | Scenario1 | Scenario2 | .. | ScenarioN |
315 -- | +-----------+-----------+ .. +-----------+
317 -- End of Compilation
319 -- +- | --------------------- Processing phase -------------------------+
321 -- | Check_Elaboration_Scenarios |
323 -- | +--> Check_SPARK_Scenario |
325 -- | | +--> Check_SPARK_Derived_Type |
327 -- | | +--> Check_SPARK_Instantiation |
329 -- | | +--> Check_SPARK_Refined_State_Pragma |
331 -- | +--> Process_Conditional_ABE <---------------------------+ |
333 -- | +--> Process_Conditional_ABE_Access Is_Suitable_Scenario |
335 -- | +--> Process_Conditional_ABE_Activation | |
337 -- | | +-----------------------------+ | |
339 -- | +--> Process_Conditional_ABE_Call +--------> Traverse_Body |
341 -- | | +-----------------------------+ |
343 -- | +--> Process_Conditional_ABE_Instantiation |
345 -- | +--> Process_Conditional_ABE_Variable_Assignment |
347 -- | +--> Process_Conditional_ABE_Variable_Reference |
349 -- +--------------------------------------------------------------------+
351 ----------------------
352 -- Important points --
353 ----------------------
355 -- The Processing phase starts after the analysis, resolution, expansion
356 -- phase has completed. As a result, no current semantic information is
357 -- available. The scope stack is empty, global flags such as In_Instance
358 -- or Inside_A_Generic become useless. To remedy this, the ABE mechanism
359 -- must either save or recompute semantic information.
361 -- Expansion heavily transforms calls and to some extent instantiations. To
362 -- remedy this, the ABE mechanism generates N_Call_Marker nodes in order to
363 -- capture the target and relevant attributes of the original call.
365 -- The diagnostics of the ABE mechanism depend on accurate source locations
366 -- to determine the spacial relation of nodes.
372 -- The following switches may be used to control the behavior of the ABE
375 -- -gnatdE elaboration checks on predefined units
377 -- The ABE mechanism considers scenarios which appear in internal
378 -- units (Ada, GNAT, Interfaces, System).
380 -- -gnatd.G ignore calls through generic formal parameters for elaboration
382 -- The ABE mechanism does not generate N_Call_Marker nodes for
383 -- calls which occur in expanded instances, and invoke generic
384 -- actual subprograms through generic formal subprograms. As a
385 -- result, the calls are not recorded or processed.
387 -- If switches -gnatd.G and -gnatdL are used together, then the
388 -- ABE mechanism effectively ignores all calls which cause the
389 -- elaboration flow to "leave" the instance.
391 -- -gnatdL ignore external calls from instances for elaboration
393 -- The ABE mechanism does not generate N_Call_Marker nodes for
394 -- calls which occur in expanded instances, do not invoke generic
395 -- actual subprograms through formal subprograms, and the target
396 -- is external to the instance. As a result, the calls are not
397 -- recorded or processed.
399 -- If switches -gnatd.G and -gnatdL are used together, then the
400 -- ABE mechanism effectively ignores all calls which cause the
401 -- elaboration flow to "leave" the instance.
403 -- -gnatd.o conservative elaboration order for indirect calls
405 -- The ABE mechanism treats '[Unrestricted_]Access of an entry,
406 -- operator, or subprogram as an immediate invocation of the
407 -- target. As a result, it performs ABE checks and diagnostics on
408 -- the immediate call.
410 -- -gnatd.U ignore indirect calls for static elaboration
412 -- The ABE mechanism does not consider '[Unrestricted_]Access of
413 -- entries, operators, and subprograms. As a result, the scenarios
414 -- are not recorder or processed.
416 -- -gnatd.v enforce SPARK elaboration rules in SPARK code
418 -- The ABE mechanism applies some of the SPARK elaboration rules
419 -- defined in the SPARK reference manual, chapter 7.7. Note that
420 -- certain rules are always enforced, regardless of whether the
423 -- -gnatd.y disable implicit pragma Elaborate_All on task bodies
425 -- The ABE mechanism does not generate implicit Elaborate_All when
426 -- the need for the pragma came from a task body.
428 -- -gnatE dynamic elaboration checking mode enabled
430 -- The ABE mechanism assumes that any scenario is elaborated or
431 -- invoked by elaboration code. The ABE mechanism performs very
432 -- little diagnostics and generates condintional ABE checks to
433 -- detect ABE issues at run-time.
435 -- -gnatel turn on info messages on generated Elaborate[_All] pragmas
437 -- The ABE mechanism produces information messages on generated
438 -- implicit Elabote[_All] pragmas along with traceback showing
439 -- why the pragma was generated. In addition, the ABE mechanism
440 -- produces information messages for each scenario elaborated or
441 -- invoked by elaboration code.
443 -- -gnateL turn off info messages on generated Elaborate[_All] pragmas
445 -- The complimentary switch for -gnatel.
447 -- -gnatwl turn on warnings for elaboration problems
449 -- The ABE mechanism produces warnings on detected ABEs along with
450 -- traceback showing the graph of the ABE.
452 -- -gnatwL turn off warnings for elaboration problems
454 -- The complimentary switch for -gnatwl.
456 -- -gnatw.f turn on warnings for suspicious Subp'Access
458 -- The ABE mechanism treats '[Unrestricted_]Access of an entry,
459 -- operator, or subprogram as a pseudo invocation of the target.
460 -- As a result, it performs ABE diagnostics on the pseudo call.
462 -- -gnatw.F turn off warnings for suspicious Subp'Access
464 -- The complimentary switch for -gnatw.f.
466 ---------------------------
467 -- Adding a new scenario --
468 ---------------------------
470 -- The following steps describe how to add a new elaboration scenario and
471 -- preserve the existing architecture. Note that not all of the steps may
472 -- need to be carried out.
474 -- 1) Update predicate Is_Scenario
476 -- 2) Add predicate Is_Suitable_xxx. Include a call to it in predicate
477 -- Is_Suitable_Scenario.
479 -- 3) Update routine Record_Elaboration_Scenario
481 -- 4) Add routine Process_Conditional_ABE_xxx. Include a call to it in
482 -- routine Process_Conditional_ABE.
484 -- 5) Add routine Process_Guaranteed_ABE_xxx. Include a call to it in
485 -- routine Process_Guaranteed_ABE.
487 -- 6) Add routine Check_SPARK_xxx. Include a call to it in routine
488 -- Check_SPARK_Scenario.
490 -- 7) Add routine Info_xxx. Include a call to it in routine
491 -- Process_Conditional_ABE_xxx.
493 -- 8) Add routine Output_xxx. Include a call to it in routine
494 -- Output_Active_Scenarios.
496 -- 9) Add routine Extract_xxx_Attributes
498 -- 10) Update routine Is_Potential_Scenario
500 -------------------------
501 -- Adding a new target --
502 -------------------------
504 -- The following steps describe how to add a new elaboration target and
505 -- preserve the existing architecture. Note that not all of the steps may
506 -- need to be carried out.
508 -- 1) Add predicate Is_xxx.
510 -- 2) Update predicates Is_Ada_Semantic_Target, Is_Bridge_Target, or
511 -- Is_SPARK_Semantic_Target. If necessary, create a new category.
513 -- 3) Update the appropriate Info_xxx routine.
515 -- 4) Update the appropriate Output_xxx routine.
517 -- 5) Update routine Extract_Target_Attributes. If necessary, create a
518 -- new Extract_xxx routine.
520 --------------------------
521 -- Debugging ABE issues --
522 --------------------------
524 -- * If the issue involves a call, ensure that the call is eligible for ABE
525 -- processing and receives a corresponding call marker. The routines of
529 -- Record_Elaboration_Scenario
531 -- * If the issue involves an arbitrary scenario, ensure that the scenario
532 -- is either recorded, or is successfully recognized while traversing a
533 -- body. The routines of interest are
535 -- Record_Elaboration_Scenario
536 -- Process_Conditional_ABE
537 -- Process_Guaranteed_ABE
540 -- * If the issue involves a circularity in the elaboration order, examine
541 -- the ALI files and look for the following encodings next to units:
543 -- E indicates a source Elaborate
545 -- EA indicates a source Elaborate_All
547 -- AD indicates an implicit Elaborate_All
549 -- ED indicates an implicit Elaborate
551 -- If possible, compare these encodings with those generated by the old
552 -- ABE mechanism. The routines of interest are
554 -- Ensure_Prior_Elaboration
560 -- To minimize the amount of code within routines, the ABE mechanism relies
561 -- on "attribute" records to capture relevant information for a scenario or
564 -- The following type captures relevant attributes which pertain to a call
566 type Call_Attributes is record
567 Elab_Checks_OK : Boolean;
568 -- This flag is set when the call has elaboration checks enabled
570 From_Source : Boolean;
571 -- This flag is set when the call comes from source
573 Ghost_Mode_Ignore : Boolean;
574 -- This flag is set when the call appears in a region subject to pragma
575 -- Ghost with policy Ignore.
577 In_Declarations : Boolean;
578 -- This flag is set when the call appears at the declaration level
580 Is_Dispatching : Boolean;
581 -- This flag is set when the call is dispatching
583 SPARK_Mode_On : Boolean;
584 -- This flag is set when the call appears in a region subject to pragma
585 -- SPARK_Mode with value On.
588 -- The following type captures relevant attributes which pertain to the
589 -- prior elaboration of a unit. This type is coupled together with a unit
590 -- to form a key -> value relationship.
592 type Elaboration_Attributes is record
593 Source_Pragma : Node_Id;
594 -- This attribute denotes a source Elaborate or Elaborate_All pragma
595 -- which guarantees the prior elaboration of some unit with respect
596 -- to the main unit. The pragma may come from the following contexts:
599 -- * The spec of the main unit (if applicable)
600 -- * Any parent spec of the main unit (if applicable)
601 -- * Any parent subunit of the main unit (if applicable)
603 -- The attribute remains Empty if no such pragma is available. Source
604 -- pragmas play a role in satisfying SPARK elaboration requirements.
606 With_Clause : Node_Id;
607 -- This attribute denotes an internally generated or source with clause
608 -- for some unit withed by the main unit. With clauses carry flags which
609 -- represent implicit Elaborate or Elaborate_All pragmas. These clauses
610 -- play a role in supplying the elaboration dependencies to binde.
613 No_Elaboration_Attributes : constant Elaboration_Attributes :=
614 (Source_Pragma => Empty,
615 With_Clause => Empty);
617 -- The following type captures relevant attributes which pertain to an
620 type Instantiation_Attributes is record
621 Elab_Checks_OK : Boolean;
622 -- This flag is set when the instantiation has elaboration checks
625 Ghost_Mode_Ignore : Boolean;
626 -- This flag is set when the instantiation appears in a region subject
627 -- to pragma Ghost with policy ignore, or starts one such region.
629 In_Declarations : Boolean;
630 -- This flag is set when the instantiation appears at the declaration
633 SPARK_Mode_On : Boolean;
634 -- This flag is set when the instantiation appears in a region subject
635 -- to pragma SPARK_Mode with value On, or starts one such region.
638 -- The following type captures relevant attributes which pertain to a
641 type Target_Attributes is record
642 Elab_Checks_OK : Boolean;
643 -- This flag is set when the target has elaboration checks enabled
645 From_Source : Boolean;
646 -- This flag is set when the target comes from source
648 Ghost_Mode_Ignore : Boolean;
649 -- This flag is set when the target appears in a region subject to
650 -- pragma Ghost with policy ignore, or starts one such region.
652 SPARK_Mode_On : Boolean;
653 -- This flag is set when the target appears in a region subject to
654 -- pragma SPARK_Mode with value On, or starts one such region.
657 -- This attribute denotes the declaration of Spec_Id
660 -- This attribute denotes the top unit where Spec_Id resides
662 -- The semantics of the following attributes depend on the target
668 -- The target is a generic package or a subprogram
670 -- * Body_Barf - Empty
672 -- * Body_Decl - This attribute denotes the generic or subprogram
675 -- * Spec_Id - This attribute denotes the entity of the generic
676 -- package or subprogram.
678 -- The target is a protected entry
680 -- * Body_Barf - This attribute denotes the body of the barrier
681 -- function if expansion took place, otherwise it is Empty.
683 -- * Body_Decl - This attribute denotes the body of the procedure
684 -- which emulates the entry if expansion took place, otherwise it
685 -- denotes the body of the protected entry.
687 -- * Spec_Id - This attribute denotes the entity of the procedure
688 -- which emulates the entry if expansion took place, otherwise it
689 -- denotes the protected entry.
691 -- The target is a protected subprogram
693 -- * Body_Barf - Empty
695 -- * Body_Decl - This attribute denotes the body of the protected or
696 -- unprotected version of the protected subprogram if expansion took
697 -- place, otherwise it denotes the body of the protected subprogram.
699 -- * Spec_Id - This attribute denotes the entity of the protected or
700 -- unprotected version of the protected subprogram if expansion took
701 -- place, otherwise it is the entity of the protected subprogram.
703 -- The target is a task entry
705 -- * Body_Barf - Empty
707 -- * Body_Decl - This attribute denotes the body of the procedure
708 -- which emulates the task body if expansion took place, otherwise
709 -- it denotes the body of the task type.
711 -- * Spec_Id - This attribute denotes the entity of the procedure
712 -- which emulates the task body if expansion took place, otherwise
713 -- it denotes the entity of the task type.
716 -- The following type captures relevant attributes which pertain to a task
719 type Task_Attributes is record
721 -- This attribute denotes the declaration of the procedure body which
722 -- emulates the behaviour of the task body.
724 Elab_Checks_OK : Boolean;
725 -- This flag is set when the task type has elaboration checks enabled
727 Ghost_Mode_Ignore : Boolean;
728 -- This flag is set when the task type appears in a region subject to
729 -- pragma Ghost with policy ignore, or starts one such region.
731 SPARK_Mode_On : Boolean;
732 -- This flag is set when the task type appears in a region subject to
733 -- pragma SPARK_Mode with value On, or starts one such region.
736 -- This attribute denotes the entity of the initial declaration of the
737 -- procedure body which emulates the behaviour of the task body.
740 -- This attribute denotes the declaration of the task type
743 -- This attribute denotes the entity of the compilation unit where the
744 -- task type resides.
747 -- The following type captures relevant attributes which pertain to a
750 type Variable_Attributes is record
752 -- This attribute denotes the entity of the compilation unit where the
756 ---------------------
757 -- Data structures --
758 ---------------------
760 -- The ABE mechanism employs lists and hash tables to store information
761 -- pertaining to scenarios and targets, as well as the Processing phase.
762 -- The need for data structures comes partly from the size limitation of
763 -- nodes. Note that the use of hash tables is conservative and operations
764 -- are carried out only when a particular hash table has at least one key
765 -- value pair (see xxx_In_Use flags).
767 -- The following table stores the early call regions of subprogram bodies
769 Early_Call_Regions_Max : constant := 101;
771 type Early_Call_Regions_Index is range 0 .. Early_Call_Regions_Max - 1;
773 function Early_Call_Regions_Hash
774 (Key : Entity_Id) return Early_Call_Regions_Index;
775 -- Obtain the hash value of entity Key
777 Early_Call_Regions_In_Use : Boolean := False;
778 -- This flag determines whether table Early_Call_Regions contains at least
779 -- least one key/value pair.
781 Early_Call_Regions_No_Element : constant Node_Id := Empty;
783 package Early_Call_Regions is new Simple_HTable
784 (Header_Num => Early_Call_Regions_Index,
786 No_Element => Early_Call_Regions_No_Element,
788 Hash => Early_Call_Regions_Hash,
791 -- The following table stores the elaboration status of all units withed by
794 Elaboration_Statuses_Max : constant := 1009;
796 type Elaboration_Statuses_Index is range 0 .. Elaboration_Statuses_Max - 1;
798 function Elaboration_Statuses_Hash
799 (Key : Entity_Id) return Elaboration_Statuses_Index;
800 -- Obtain the hash value of entity Key
802 Elaboration_Statuses_In_Use : Boolean := False;
803 -- This flag flag determines whether table Elaboration_Statuses contains at
804 -- least one key/value pair.
806 Elaboration_Statuses_No_Element : constant Elaboration_Attributes :=
807 No_Elaboration_Attributes;
809 package Elaboration_Statuses is new Simple_HTable
810 (Header_Num => Elaboration_Statuses_Index,
811 Element => Elaboration_Attributes,
812 No_Element => Elaboration_Statuses_No_Element,
814 Hash => Elaboration_Statuses_Hash,
817 -- The following table stores a status flag for each SPARK scenario saved
818 -- in table SPARK_Scenarios.
820 Recorded_SPARK_Scenarios_Max : constant := 127;
822 type Recorded_SPARK_Scenarios_Index is
823 range 0 .. Recorded_SPARK_Scenarios_Max - 1;
825 function Recorded_SPARK_Scenarios_Hash
826 (Key : Node_Id) return Recorded_SPARK_Scenarios_Index;
827 -- Obtain the hash value of Key
829 Recorded_SPARK_Scenarios_In_Use : Boolean := False;
830 -- This flag flag determines whether table Recorded_SPARK_Scenarios
831 -- contains at least one key/value pair.
833 Recorded_SPARK_Scenarios_No_Element : constant Boolean := False;
835 package Recorded_SPARK_Scenarios is new Simple_HTable
836 (Header_Num => Recorded_SPARK_Scenarios_Index,
838 No_Element => Recorded_SPARK_Scenarios_No_Element,
840 Hash => Recorded_SPARK_Scenarios_Hash,
843 -- The following table stores a status flag for each top-level scenario
844 -- recorded in table Top_Level_Scenarios.
846 Recorded_Top_Level_Scenarios_Max : constant := 503;
848 type Recorded_Top_Level_Scenarios_Index is
849 range 0 .. Recorded_Top_Level_Scenarios_Max - 1;
851 function Recorded_Top_Level_Scenarios_Hash
852 (Key : Node_Id) return Recorded_Top_Level_Scenarios_Index;
853 -- Obtain the hash value of entity Key
855 Recorded_Top_Level_Scenarios_In_Use : Boolean := False;
856 -- This flag flag determines whether table Recorded_Top_Level_Scenarios
857 -- contains at least one key/value pair.
859 Recorded_Top_Level_Scenarios_No_Element : constant Boolean := False;
861 package Recorded_Top_Level_Scenarios is new Simple_HTable
862 (Header_Num => Recorded_Top_Level_Scenarios_Index,
864 No_Element => Recorded_Top_Level_Scenarios_No_Element,
866 Hash => Recorded_Top_Level_Scenarios_Hash,
869 -- The following table stores all active scenarios in a recursive traversal
870 -- starting from a top-level scenario. This table must be maintained in a
873 package Scenario_Stack is new Table.Table
874 (Table_Component_Type => Node_Id,
875 Table_Index_Type => Int,
876 Table_Low_Bound => 1,
878 Table_Increment => 100,
879 Table_Name => "Scenario_Stack");
881 -- The following table stores SPARK scenarios which are not necessarily
882 -- executable during elaboration, but still require elaboration-related
885 package SPARK_Scenarios is new Table.Table
886 (Table_Component_Type => Node_Id,
887 Table_Index_Type => Int,
888 Table_Low_Bound => 1,
890 Table_Increment => 100,
891 Table_Name => "SPARK_Scenarios");
893 -- The following table stores all top-level scenario saved during the
894 -- Recording phase. The contents of this table act as traversal roots
895 -- later in the Processing phase. This table must be maintained in a
898 package Top_Level_Scenarios is new Table.Table
899 (Table_Component_Type => Node_Id,
900 Table_Index_Type => Int,
901 Table_Low_Bound => 1,
902 Table_Initial => 1000,
903 Table_Increment => 100,
904 Table_Name => "Top_Level_Scenarios");
906 -- The following table stores the bodies of all eligible scenarios visited
907 -- during a traversal starting from a top-level scenario. The contents of
908 -- this table must be reset upon each new traversal.
910 Visited_Bodies_Max : constant := 511;
912 type Visited_Bodies_Index is range 0 .. Visited_Bodies_Max - 1;
914 function Visited_Bodies_Hash (Key : Node_Id) return Visited_Bodies_Index;
915 -- Obtain the hash value of node Key
917 Visited_Bodies_In_Use : Boolean := False;
918 -- This flag determines whether table Visited_Bodies contains at least one
921 Visited_Bodies_No_Element : constant Boolean := False;
923 package Visited_Bodies is new Simple_HTable
924 (Header_Num => Visited_Bodies_Index,
926 No_Element => Visited_Bodies_No_Element,
928 Hash => Visited_Bodies_Hash,
931 -----------------------
932 -- Local subprograms --
933 -----------------------
935 -- Multiple local subprograms are utilized to lower the semantic complexity
936 -- of the Recording and Processing phase.
938 procedure Check_Preelaborated_Call (Call : Node_Id);
939 pragma Inline (Check_Preelaborated_Call);
940 -- Verify that entry, operator, or subprogram call Call does not appear at
941 -- the library level of a preelaborated unit.
943 procedure Check_SPARK_Derived_Type (Typ_Decl : Node_Id);
944 pragma Inline (Check_SPARK_Derived_Type);
945 -- Verify that the freeze node of a derived type denoted by declaration
946 -- Typ_Decl is within the early call region of each overriding primitive
947 -- body that belongs to the derived type (SPARK RM 7.7(8)).
949 procedure Check_SPARK_Instantiation (Exp_Inst : Node_Id);
950 pragma Inline (Check_SPARK_Instantiation);
951 -- Verify that expanded instance Exp_Inst does not precede the generic body
952 -- it instantiates (SPARK RM 7.7(6)).
954 procedure Check_SPARK_Scenario (N : Node_Id);
955 pragma Inline (Check_SPARK_Scenario);
956 -- Top-level dispatcher for verifying SPARK scenarios which are not always
957 -- executable during elaboration but still need elaboration-related checks.
959 procedure Check_SPARK_Refined_State_Pragma (N : Node_Id);
960 pragma Inline (Check_SPARK_Refined_State_Pragma);
961 -- Verify that each constituent of Refined_State pragma N which belongs to
962 -- an abstract state mentioned in pragma Initializes has prior elaboration
963 -- with respect to the main unit (SPARK RM 7.7.1(7)).
965 function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id;
966 pragma Inline (Compilation_Unit);
967 -- Return the N_Compilation_Unit node of unit Unit_Id
969 function Early_Call_Region (Body_Id : Entity_Id) return Node_Id;
970 pragma Inline (Early_Call_Region);
971 -- Return the early call region associated with entry or subprogram body
972 -- Body_Id. IMPORTANT: This routine does not find the early call region.
973 -- To compute it, use routine Find_Early_Call_Region.
975 procedure Elab_Msg_NE
981 pragma Inline (Elab_Msg_NE);
982 -- Wrapper around Error_Msg_NE. Emit message Msg concerning arbitrary node
983 -- N and entity. If flag Info_Msg is set, the routine emits an information
984 -- message, otherwise it emits an error. If flag In_SPARK is set, then
985 -- string " in SPARK" is added to the end of the message.
987 function Elaboration_Status
988 (Unit_Id : Entity_Id) return Elaboration_Attributes;
989 pragma Inline (Elaboration_Status);
990 -- Return the set of elaboration attributes associated with unit Unit_Id
992 procedure Ensure_Prior_Elaboration
996 In_Partial_Fin : Boolean;
997 In_Task_Body : Boolean);
998 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
999 -- by installing pragma Elaborate or Elaborate_All denoted by Prag_Nam. N
1000 -- denotes the related scenario. The flags should be set when the need for
1001 -- elaboration was initiated as follows:
1003 -- In_Partial_Fin - partial finalization procedure
1004 -- In_Task_Body - task body
1006 procedure Ensure_Prior_Elaboration_Dynamic
1008 Unit_Id : Entity_Id;
1009 Prag_Nam : Name_Id);
1010 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
1011 -- by suggesting the use of Elaborate[_All] with name Prag_Nam. N denotes
1012 -- the related scenario.
1014 procedure Ensure_Prior_Elaboration_Static
1016 Unit_Id : Entity_Id;
1017 Prag_Nam : Name_Id);
1018 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
1019 -- by installing an implicit Elaborate[_All] pragma with name Prag_Nam. N
1020 -- denotes the related scenario.
1022 function Extract_Assignment_Name (Asmt : Node_Id) return Node_Id;
1023 pragma Inline (Extract_Assignment_Name);
1024 -- Obtain the Name attribute of assignment statement Asmt
1026 procedure Extract_Call_Attributes
1028 Target_Id : out Entity_Id;
1029 Attrs : out Call_Attributes);
1030 pragma Inline (Extract_Call_Attributes);
1031 -- Obtain attributes Attrs associated with call Call. Target_Id is the
1032 -- entity of the call target.
1034 function Extract_Call_Name (Call : Node_Id) return Node_Id;
1035 pragma Inline (Extract_Call_Name);
1036 -- Obtain the Name attribute of entry or subprogram call Call
1038 procedure Extract_Instance_Attributes
1039 (Exp_Inst : Node_Id;
1040 Inst_Body : out Node_Id;
1041 Inst_Decl : out Node_Id);
1042 pragma Inline (Extract_Instance_Attributes);
1043 -- Obtain body Inst_Body and spec Inst_Decl of expanded instance Exp_Inst
1045 procedure Extract_Instantiation_Attributes
1046 (Exp_Inst : Node_Id;
1048 Inst_Id : out Entity_Id;
1049 Gen_Id : out Entity_Id;
1050 Attrs : out Instantiation_Attributes);
1051 pragma Inline (Extract_Instantiation_Attributes);
1052 -- Obtain attributes Attrs associated with expanded instantiation Exp_Inst.
1053 -- Inst is the instantiation. Inst_Id is the entity of the instance. Gen_Id
1054 -- is the entity of the generic unit being instantiated.
1056 procedure Extract_Target_Attributes
1057 (Target_Id : Entity_Id;
1058 Attrs : out Target_Attributes);
1059 -- Obtain attributes Attrs associated with an entry, package, or subprogram
1060 -- denoted by Target_Id.
1062 procedure Extract_Task_Attributes
1064 Attrs : out Task_Attributes);
1065 pragma Inline (Extract_Task_Attributes);
1066 -- Obtain attributes Attrs associated with task type Typ
1068 procedure Extract_Variable_Reference_Attributes
1070 Var_Id : out Entity_Id;
1071 Attrs : out Variable_Attributes);
1072 pragma Inline (Extract_Variable_Reference_Attributes);
1073 -- Obtain attributes Attrs associated with reference Ref that mentions
1076 function Find_Code_Unit (N : Node_Or_Entity_Id) return Entity_Id;
1077 pragma Inline (Find_Code_Unit);
1078 -- Return the code unit which contains arbitrary node or entity N. This
1079 -- is the unit of the file which physically contains the related construct
1080 -- denoted by N except when N is within an instantiation. In that case the
1081 -- unit is that of the top-level instantiation.
1083 function Find_Early_Call_Region
1084 (Body_Decl : Node_Id;
1085 Assume_Elab_Body : Boolean := False;
1086 Skip_Memoization : Boolean := False) return Node_Id;
1087 -- Find the start of the early call region which belongs to subprogram body
1088 -- Body_Decl as defined in SPARK RM 7.7. The behavior of the routine is to
1089 -- find the early call region, memoize it, and return it, but this behavior
1090 -- can be altered. Flag Assume_Elab_Body should be set when a package spec
1091 -- may lack pragma Elaborate_Body, but the routine must still examine that
1092 -- spec. Flag Skip_Memoization should be set when the routine must avoid
1093 -- memoizing the region.
1095 procedure Find_Elaborated_Units;
1096 -- Populate table Elaboration_Statuses with all units which have prior
1097 -- elaboration with respect to the main unit.
1099 function Find_Enclosing_Instance (N : Node_Id) return Node_Id;
1100 pragma Inline (Find_Enclosing_Instance);
1101 -- Find the declaration or body of the nearest expanded instance which
1102 -- encloses arbitrary node N. Return Empty if no such instance exists.
1104 function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id;
1105 pragma Inline (Find_Top_Unit);
1106 -- Return the top unit which contains arbitrary node or entity N. The unit
1107 -- is obtained by logically unwinding instantiations and subunits when N
1108 -- resides within one.
1110 function Find_Unit_Entity (N : Node_Id) return Entity_Id;
1111 pragma Inline (Find_Unit_Entity);
1112 -- Return the entity of unit N
1114 function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id;
1115 pragma Inline (First_Formal_Type);
1116 -- Return the type of subprogram Subp_Id's first formal parameter. If the
1117 -- subprogram lacks formal parameters, return Empty.
1119 function Has_Body (Pack_Decl : Node_Id) return Boolean;
1120 -- Determine whether package declaration Pack_Decl has a corresponding body
1121 -- or would eventually have one.
1123 function Has_Prior_Elaboration
1124 (Unit_Id : Entity_Id;
1125 Context_OK : Boolean := False;
1126 Elab_Body_OK : Boolean := False;
1127 Same_Unit_OK : Boolean := False) return Boolean;
1128 pragma Inline (Has_Prior_Elaboration);
1129 -- Determine whether unit Unit_Id is elaborated prior to the main unit.
1130 -- If flag Context_OK is set, the routine considers the following case
1131 -- as valid prior elaboration:
1133 -- * Unit_Id is in the elaboration context of the main unit
1135 -- If flag Elab_Body_OK is set, the routine considers the following case
1136 -- as valid prior elaboration:
1138 -- * Unit_Id has pragma Elaborate_Body and is not the main unit
1140 -- If flag Same_Unit_OK is set, the routine considers the following cases
1141 -- as valid prior elaboration:
1143 -- * Unit_Id is the main unit
1145 -- * Unit_Id denotes the spec of the main unit body
1147 function In_External_Instance
1149 Target_Decl : Node_Id) return Boolean;
1150 pragma Inline (In_External_Instance);
1151 -- Determine whether a target desctibed by its declaration Target_Decl
1152 -- resides in a package instance which is external to scenario N.
1154 function In_Main_Context (N : Node_Id) return Boolean;
1155 pragma Inline (In_Main_Context);
1156 -- Determine whether arbitrary node N appears within the main compilation
1159 function In_Same_Context
1162 Nested_OK : Boolean := False) return Boolean;
1163 -- Determine whether two arbitrary nodes N1 and N2 appear within the same
1164 -- context ignoring enclosing library levels. Nested_OK should be set when
1165 -- the context of N1 can enclose that of N2.
1169 Target_Id : Entity_Id;
1171 In_SPARK : Boolean);
1172 -- Output information concerning call Call which invokes target Target_Id.
1173 -- If flag Info_Msg is set, the routine emits an information message,
1174 -- otherwise it emits an error. If flag In_SPARK is set, then the string
1175 -- " in SPARK" is added to the end of the message.
1177 procedure Info_Instantiation
1181 In_SPARK : Boolean);
1182 pragma Inline (Info_Instantiation);
1183 -- Output information concerning instantiation Inst which instantiates
1184 -- generic unit Gen_Id. If flag Info_Msg is set, the routine emits an
1185 -- information message, otherwise it emits an error. If flag In_SPARK
1186 -- is set, then string " in SPARK" is added to the end of the message.
1188 procedure Info_Variable_Reference
1192 In_SPARK : Boolean);
1193 pragma Inline (Info_Variable_Reference);
1194 -- Output information concerning reference Ref which mentions variable
1195 -- Var_Id. If flag Info_Msg is set, the routine emits an information
1196 -- message, otherwise it emits an error. If flag In_SPARK is set, then
1197 -- string " in SPARK" is added to the end of the message.
1199 function Insertion_Node (N : Node_Id; Ins_Nod : Node_Id) return Node_Id;
1200 pragma Inline (Insertion_Node);
1201 -- Obtain the proper insertion node of an ABE check or failure for scenario
1202 -- N and candidate insertion node Ins_Nod.
1204 procedure Install_ABE_Check
1208 -- Insert a run-time ABE check for elaboration scenario N which verifies
1209 -- whether arbitrary entity Id is elaborated. The check in inserted prior
1212 procedure Install_ABE_Check
1214 Target_Id : Entity_Id;
1215 Target_Decl : Node_Id;
1216 Target_Body : Node_Id;
1218 -- Insert a run-time ABE check for elaboration scenario N which verifies
1219 -- whether target Target_Id with initial declaration Target_Decl and body
1220 -- Target_Body is elaborated. The check is inserted prior to node Ins_Nod.
1222 procedure Install_ABE_Failure (N : Node_Id; Ins_Nod : Node_Id);
1223 -- Insert a Program_Error concerning a guaranteed ABE for elaboration
1224 -- scenario N. The failure is inserted prior to node Node_Id.
1226 function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean;
1227 pragma Inline (Is_Accept_Alternative_Proc);
1228 -- Determine whether arbitrary entity Id denotes an internally generated
1229 -- procedure which encapsulates the statements of an accept alternative.
1231 function Is_Activation_Proc (Id : Entity_Id) return Boolean;
1232 pragma Inline (Is_Activation_Proc);
1233 -- Determine whether arbitrary entity Id denotes a runtime procedure in
1234 -- charge with activating tasks.
1236 function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean;
1237 pragma Inline (Is_Ada_Semantic_Target);
1238 -- Determine whether arbitrary entity Id nodes a source or internally
1239 -- generated subprogram which emulates Ada semantics.
1241 function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean;
1242 pragma Inline (Is_Bodiless_Subprogram);
1243 -- Determine whether subprogram Subp_Id will never have a body
1245 function Is_Controlled_Proc
1246 (Subp_Id : Entity_Id;
1247 Subp_Nam : Name_Id) return Boolean;
1248 pragma Inline (Is_Controlled_Proc);
1249 -- Determine whether subprogram Subp_Id denotes controlled type primitives
1250 -- Adjust, Finalize, or Initialize as denoted by name Subp_Nam.
1252 function Is_Default_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
1253 pragma Inline (Is_Default_Initial_Condition_Proc);
1254 -- Determine whether arbitrary entity Id denotes internally generated
1255 -- routine Default_Initial_Condition.
1257 function Is_Finalizer_Proc (Id : Entity_Id) return Boolean;
1258 pragma Inline (Is_Finalizer_Proc);
1259 -- Determine whether arbitrary entity Id denotes internally generated
1260 -- routine _Finalizer.
1262 function Is_Guaranteed_ABE
1264 Target_Decl : Node_Id;
1265 Target_Body : Node_Id) return Boolean;
1266 pragma Inline (Is_Guaranteed_ABE);
1267 -- Determine whether scenario N with a target described by its initial
1268 -- declaration Target_Decl and body Target_Decl results in a guaranteed
1271 function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean;
1272 pragma Inline (Is_Initial_Condition_Proc);
1273 -- Determine whether arbitrary entity Id denotes internally generated
1274 -- routine Initial_Condition.
1276 function Is_Initialized (Obj_Decl : Node_Id) return Boolean;
1277 pragma Inline (Is_Initialized);
1278 -- Determine whether object declaration Obj_Decl is initialized
1280 function Is_Invariant_Proc (Id : Entity_Id) return Boolean;
1281 pragma Inline (Is_Invariant_Proc);
1282 -- Determine whether arbitrary entity Id denotes an invariant procedure
1284 function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean;
1285 pragma Inline (Is_Non_Library_Level_Encapsulator);
1286 -- Determine whether arbitrary node N is a non-library encapsulator
1288 function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean;
1289 pragma Inline (Is_Partial_Invariant_Proc);
1290 -- Determine whether arbitrary entity Id denotes a partial invariant
1293 function Is_Postconditions_Proc (Id : Entity_Id) return Boolean;
1294 pragma Inline (Is_Postconditions_Proc);
1295 -- Determine whether arbitrary entity Id denotes internally generated
1296 -- routine _Postconditions.
1298 function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean;
1299 pragma Inline (Is_Preelaborated_Unit);
1300 -- Determine whether arbitrary entity Id denotes a unit which is subject to
1301 -- one of the following pragmas:
1305 -- * Remote_Call_Interface
1309 function Is_Protected_Entry (Id : Entity_Id) return Boolean;
1310 pragma Inline (Is_Protected_Entry);
1311 -- Determine whether arbitrary entity Id denotes a protected entry
1313 function Is_Protected_Subp (Id : Entity_Id) return Boolean;
1314 pragma Inline (Is_Protected_Subp);
1315 -- Determine whether entity Id denotes a protected subprogram
1317 function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean;
1318 pragma Inline (Is_Protected_Body_Subp);
1319 -- Determine whether entity Id denotes the protected or unprotected version
1320 -- of a protected subprogram.
1322 function Is_Recorded_SPARK_Scenario (N : Node_Id) return Boolean;
1323 pragma Inline (Is_Recorded_SPARK_Scenario);
1324 -- Determine whether arbitrary node N is a recorded SPARK scenario which
1325 -- appears in table SPARK_Scenarios.
1327 function Is_Recorded_Top_Level_Scenario (N : Node_Id) return Boolean;
1328 pragma Inline (Is_Recorded_Top_Level_Scenario);
1329 -- Determine whether arbitrary node N is a recorded top-level scenario
1330 -- which appears in table Top_Level_Scenarios.
1332 function Is_Safe_Activation
1334 Task_Decl : Node_Id) return Boolean;
1335 pragma Inline (Is_Safe_Activation);
1336 -- Determine whether call Call which activates a task object described by
1337 -- declaration Task_Decl is always ABE-safe.
1339 function Is_Safe_Call
1341 Target_Attrs : Target_Attributes) return Boolean;
1342 pragma Inline (Is_Safe_Call);
1343 -- Determine whether call Call which invokes a target described by
1344 -- attributes Target_Attrs is always ABE-safe.
1346 function Is_Safe_Instantiation
1348 Gen_Attrs : Target_Attributes) return Boolean;
1349 pragma Inline (Is_Safe_Instantiation);
1350 -- Determine whether instance Inst which instantiates a generic unit
1351 -- described by attributes Gen_Attrs is always ABE-safe.
1353 function Is_Same_Unit
1354 (Unit_1 : Entity_Id;
1355 Unit_2 : Entity_Id) return Boolean;
1356 pragma Inline (Is_Same_Unit);
1357 -- Determine whether entities Unit_1 and Unit_2 denote the same unit
1359 function Is_Scenario (N : Node_Id) return Boolean;
1360 pragma Inline (Is_Scenario);
1361 -- Determine whether attribute node N denotes a scenario. The scenario may
1362 -- not necessarily be eligible for ABE processing.
1364 function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean;
1365 pragma Inline (Is_SPARK_Semantic_Target);
1366 -- Determine whether arbitrary entity Id nodes a source or internally
1367 -- generated subprogram which emulates SPARK semantics.
1369 function Is_Suitable_Access (N : Node_Id) return Boolean;
1370 pragma Inline (Is_Suitable_Access);
1371 -- Determine whether arbitrary node N denotes a suitable attribute for ABE
1374 function Is_Suitable_Call (N : Node_Id) return Boolean;
1375 pragma Inline (Is_Suitable_Call);
1376 -- Determine whether arbitrary node N denotes a suitable call for ABE
1379 function Is_Suitable_Instantiation (N : Node_Id) return Boolean;
1380 pragma Inline (Is_Suitable_Instantiation);
1381 -- Determine whether arbitrary node N is a suitable instantiation for ABE
1384 function Is_Suitable_Scenario (N : Node_Id) return Boolean;
1385 pragma Inline (Is_Suitable_Scenario);
1386 -- Determine whether arbitrary node N is a suitable scenario for ABE
1389 function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean;
1390 pragma Inline (Is_Suitable_SPARK_Derived_Type);
1391 -- Determine whether arbitrary node N denotes a suitable derived type
1392 -- declaration for ABE processing using the SPARK rules.
1394 function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean;
1395 pragma Inline (Is_Suitable_SPARK_Instantiation);
1396 -- Determine whether arbitrary node N denotes a suitable instantiation for
1397 -- ABE processing using the SPARK rules.
1399 function Is_Suitable_SPARK_Refined_State_Pragma
1400 (N : Node_Id) return Boolean;
1401 pragma Inline (Is_Suitable_SPARK_Refined_State_Pragma);
1402 -- Determine whether arbitrary node N denotes a suitable Refined_State
1403 -- pragma for ABE processing using the SPARK rules.
1405 function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean;
1406 pragma Inline (Is_Suitable_Variable_Assignment);
1407 -- Determine whether arbitrary node N denotes a suitable assignment for ABE
1410 function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean;
1411 pragma Inline (Is_Suitable_Variable_Reference);
1412 -- Determine whether arbitrary node N is a suitable variable reference for
1415 function Is_Task_Entry (Id : Entity_Id) return Boolean;
1416 pragma Inline (Is_Task_Entry);
1417 -- Determine whether arbitrary entity Id denotes a task entry
1419 function Is_Up_Level_Target (Target_Decl : Node_Id) return Boolean;
1420 pragma Inline (Is_Up_Level_Target);
1421 -- Determine whether the current root resides at the declaration level. If
1422 -- this is the case, determine whether a target described by declaration
1423 -- Target_Decl is within a context which encloses the current root or is in
1424 -- a different unit.
1426 function Is_Visited_Body (Body_Decl : Node_Id) return Boolean;
1427 pragma Inline (Is_Visited_Body);
1428 -- Determine whether subprogram body Body_Decl is already visited during a
1429 -- recursive traversal started from a top-level scenario.
1431 procedure Meet_Elaboration_Requirement
1433 Target_Id : Entity_Id;
1435 -- Determine whether elaboration requirement Req_Nam for scenario N with
1436 -- target Target_Id is met by the context of the main unit using the SPARK
1437 -- rules. Req_Nam must denote either Elaborate or Elaborate_All. Emit an
1438 -- error if this is not the case.
1440 function Non_Private_View (Typ : Entity_Id) return Entity_Id;
1441 pragma Inline (Non_Private_View);
1442 -- Return the full view of private type Typ if available, otherwise return
1445 procedure Output_Active_Scenarios (Error_Nod : Node_Id);
1446 -- Output the contents of the active scenario stack from earliest to latest
1447 -- to supplement an earlier error emitted for node Error_Nod.
1449 procedure Pop_Active_Scenario (N : Node_Id);
1450 pragma Inline (Pop_Active_Scenario);
1451 -- Pop the top of the scenario stack. A check is made to ensure that the
1452 -- scenario being removed is the same as N.
1455 with procedure Process_Single_Activation
1457 Call_Attrs : Call_Attributes;
1459 Task_Attrs : Task_Attributes;
1460 In_Init_Cond : Boolean;
1461 In_Partial_Fin : Boolean;
1462 In_Task_Body : Boolean);
1463 -- Perform ABE checks and diagnostics for task activation call Call
1464 -- which activates task Obj_Id. Call_Attrs are the attributes of the
1465 -- activation call. Task_Attrs are the attributes of the task type.
1466 -- The flags should be set when the processing was initiated as follows:
1468 -- In_Init_Cond - initial condition procedure
1469 -- In_Partial_Fin - partial finalization procedure
1470 -- In_Task_Body - task body
1472 procedure Process_Activation_Generic
1474 Call_Attrs : Call_Attributes;
1475 In_Init_Cond : Boolean;
1476 In_Partial_Fin : Boolean;
1477 In_Task_Body : Boolean);
1478 -- Perform ABE checks and diagnostics for activation call Call by invoking
1479 -- routine Process_Single_Activation on each task object being activated.
1480 -- Call_Attrs are the attributes of the activation call. The flags should
1481 -- be set when the processing was initiated as follows:
1483 -- In_Init_Cond - initial condition procedure
1484 -- In_Partial_Fin - partial finalization procedure
1485 -- In_Task_Body - task body
1487 procedure Process_Conditional_ABE
1489 In_Init_Cond : Boolean := False;
1490 In_Partial_Fin : Boolean := False;
1491 In_Task_Body : Boolean := False);
1492 -- Top-level dispatcher for processing of various elaboration scenarios.
1493 -- Perform conditional ABE checks and diagnostics for scenario N. The flags
1494 -- should be set when the processing was initiated as follows:
1496 -- In_Init_Cond - initial condition procedure
1497 -- In_Partial_Fin - partial finalization procedure
1498 -- In_Task_Body - task body
1500 procedure Process_Conditional_ABE_Access
1502 In_Init_Cond : Boolean;
1503 In_Partial_Fin : Boolean;
1504 In_Task_Body : Boolean);
1505 -- Perform ABE checks and diagnostics for 'Access to entry, operator, or
1506 -- subprogram denoted by Attr. The flags should be set when the processing
1507 -- was initiated as follows:
1509 -- In_Init_Cond - initial condition procedure
1510 -- In_Partial_Fin - partial finalization procedure
1511 -- In_Task_Body - task body
1513 procedure Process_Conditional_ABE_Activation_Impl
1515 Call_Attrs : Call_Attributes;
1517 Task_Attrs : Task_Attributes;
1518 In_Init_Cond : Boolean;
1519 In_Partial_Fin : Boolean;
1520 In_Task_Body : Boolean);
1521 -- Perform common conditional ABE checks and diagnostics for call Call
1522 -- which activates task Obj_Id ignoring the Ada or SPARK rules. CAll_Attrs
1523 -- are the attributes of the activation call. Task_Attrs are the attributes
1524 -- of the task type. The flags should be set when the processing was
1525 -- initiated as follows:
1527 -- In_Init_Cond - initial condition procedure
1528 -- In_Partial_Fin - partial finalization procedure
1529 -- In_Task_Body - task body
1531 procedure Process_Conditional_ABE_Call
1533 Call_Attrs : Call_Attributes;
1534 Target_Id : Entity_Id;
1535 In_Init_Cond : Boolean;
1536 In_Partial_Fin : Boolean;
1537 In_Task_Body : Boolean);
1538 -- Top-level dispatcher for processing of calls. Perform ABE checks and
1539 -- diagnostics for call Call which invokes target Target_Id. Call_Attrs
1540 -- are the attributes of the call. The flags should be set when the
1541 -- processing was initiated as follows:
1543 -- In_Init_Cond - initial condition procedure
1544 -- In_Partial_Fin - partial finalization procedure
1545 -- In_Task_Body - task body
1547 procedure Process_Conditional_ABE_Call_Ada
1549 Call_Attrs : Call_Attributes;
1550 Target_Id : Entity_Id;
1551 Target_Attrs : Target_Attributes;
1552 In_Partial_Fin : Boolean;
1553 In_Task_Body : Boolean);
1554 -- Perform ABE checks and diagnostics for call Call which invokes target
1555 -- Target_Id using the Ada rules. Call_Attrs are the attributes of the
1556 -- call. Target_Attrs are attributes of the target. The flags should be
1557 -- set when the processing was initiated as follows:
1559 -- In_Partial_Fin - partial finalization procedure
1560 -- In_Task_Body - task body
1562 procedure Process_Conditional_ABE_Call_SPARK
1564 Target_Id : Entity_Id;
1565 Target_Attrs : Target_Attributes;
1566 In_Init_Cond : Boolean;
1567 In_Partial_Fin : Boolean;
1568 In_Task_Body : Boolean);
1569 -- Perform ABE checks and diagnostics for call Call which invokes target
1570 -- Target_Id using the SPARK rules. Target_Attrs denotes the attributes of
1571 -- the target. The flags should be set when the processing was initiated as
1574 -- In_Init_Cond - initial condition procedure
1575 -- In_Partial_Fin - partial finalization procedure
1576 -- In_Task_Body - task body
1578 procedure Process_Conditional_ABE_Instantiation
1579 (Exp_Inst : Node_Id;
1580 In_Partial_Fin : Boolean;
1581 In_Task_Body : Boolean);
1582 -- Top-level dispatcher for processing of instantiations. Perform ABE
1583 -- checks and diagnostics for expanded instantiation Exp_Inst. The flags
1584 -- should be set when the processing was initiated as follows:
1586 -- In_Partial_Fin - partial finalization procedure
1587 -- In_Task_Body - task body
1589 procedure Process_Conditional_ABE_Instantiation_Ada
1590 (Exp_Inst : Node_Id;
1592 Inst_Attrs : Instantiation_Attributes;
1594 Gen_Attrs : Target_Attributes;
1595 In_Partial_Fin : Boolean;
1596 In_Task_Body : Boolean);
1597 -- Perform ABE checks and diagnostics for expanded instantiation Exp_Inst
1598 -- of generic Gen_Id using the Ada rules. Inst is the instantiation node.
1599 -- Inst_Attrs are the attributes of the instance. Gen_Attrs denotes the
1600 -- attributes of the generic. The flags should be set when the processing
1601 -- was initiated as follows:
1603 -- In_Partial_Fin - partial finalization procedure
1604 -- In_Task_Body - task body
1606 procedure Process_Conditional_ABE_Instantiation_SPARK
1609 Gen_Attrs : Target_Attributes;
1610 In_Partial_Fin : Boolean;
1611 In_Task_Body : Boolean);
1612 -- Perform ABE checks and diagnostics for instantiation Inst of generic
1613 -- Gen_Id using the SPARK rules. Gen_Attrs denotes the attributes of the
1614 -- generic. The flags should be set when the processing was initiated as
1617 -- In_Partial_Fin - partial finalization procedure
1618 -- In_Task_Body - task body
1620 procedure Process_Conditional_ABE_Variable_Assignment (Asmt : Node_Id);
1621 -- Top-level dispatcher for processing of variable assignments. Perform ABE
1622 -- checks and diagnostics for assignment statement Asmt.
1624 procedure Process_Conditional_ABE_Variable_Assignment_Ada
1626 Var_Id : Entity_Id);
1627 -- Perform ABE checks and diagnostics for assignment statement Asmt that
1628 -- updates the value of variable Var_Id using the Ada rules.
1630 procedure Process_Conditional_ABE_Variable_Assignment_SPARK
1632 Var_Id : Entity_Id);
1633 -- Perform ABE checks and diagnostics for assignment statement Asmt that
1634 -- updates the value of variable Var_Id using the SPARK rules.
1636 procedure Process_Conditional_ABE_Variable_Reference (Ref : Node_Id);
1637 -- Top-level dispatcher for processing of variable references. Perform ABE
1638 -- checks and diagnostics for variable reference Ref.
1640 procedure Process_Conditional_ABE_Variable_Reference_Read
1643 Attrs : Variable_Attributes);
1644 -- Perform ABE checks and diagnostics for reference Ref described by its
1645 -- attributes Attrs, that reads variable Var_Id.
1647 procedure Process_Guaranteed_ABE (N : Node_Id);
1648 -- Top-level dispatcher for processing of scenarios which result in a
1651 procedure Process_Guaranteed_ABE_Activation_Impl
1653 Call_Attrs : Call_Attributes;
1655 Task_Attrs : Task_Attributes;
1656 In_Init_Cond : Boolean;
1657 In_Partial_Fin : Boolean;
1658 In_Task_Body : Boolean);
1659 -- Perform common guaranteed ABE checks and diagnostics for call Call which
1660 -- activates task Obj_Id ignoring the Ada or SPARK rules. Task_Attrs are
1661 -- the attributes of the task type. The following parameters are provided
1662 -- for compatibility and are unused.
1669 procedure Process_Guaranteed_ABE_Call
1671 Call_Attrs : Call_Attributes;
1672 Target_Id : Entity_Id);
1673 -- Perform common guaranteed ABE checks and diagnostics for call Call which
1674 -- invokes target Target_Id ignoring the Ada or SPARK rules. Call_Attrs are
1675 -- the attributes of the call.
1677 procedure Process_Guaranteed_ABE_Instantiation (Exp_Inst : Node_Id);
1678 -- Perform common guaranteed ABE checks and diagnostics for expanded
1679 -- instantiation Exp_Inst of generic Gen_Id ignoring the Ada or SPARK
1682 procedure Push_Active_Scenario (N : Node_Id);
1683 pragma Inline (Push_Active_Scenario);
1684 -- Push scenario N on top of the scenario stack
1686 procedure Record_SPARK_Elaboration_Scenario (N : Node_Id);
1687 pragma Inline (Record_SPARK_Elaboration_Scenario);
1688 -- Save SPARK scenario N in table SPARK_Scenarios for later processing
1690 procedure Reset_Visited_Bodies;
1691 pragma Inline (Reset_Visited_Bodies);
1692 -- Clear the contents of table Visited_Bodies
1694 function Root_Scenario return Node_Id;
1695 pragma Inline (Root_Scenario);
1696 -- Return the top-level scenario which started a recursive search for other
1697 -- scenarios. It is assumed that there is a valid top-level scenario on the
1698 -- active scenario stack.
1700 procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id);
1701 pragma Inline (Set_Early_Call_Region);
1702 -- Associate an early call region with begins at construct Start with entry
1703 -- or subprogram body Body_Id.
1705 procedure Set_Elaboration_Status
1706 (Unit_Id : Entity_Id;
1707 Val : Elaboration_Attributes);
1708 pragma Inline (Set_Elaboration_Status);
1709 -- Associate an set of elaboration attributes with unit Unit_Id
1711 procedure Set_Is_Recorded_SPARK_Scenario
1713 Val : Boolean := True);
1714 pragma Inline (Set_Is_Recorded_SPARK_Scenario);
1715 -- Mark scenario N as being recorded in table SPARK_Scenarios
1717 procedure Set_Is_Recorded_Top_Level_Scenario
1719 Val : Boolean := True);
1720 pragma Inline (Set_Is_Recorded_Top_Level_Scenario);
1721 -- Mark scenario N as being recorded in table Top_Level_Scenarios
1723 procedure Set_Is_Visited_Body (Subp_Body : Node_Id);
1724 pragma Inline (Set_Is_Visited_Body);
1725 -- Mark subprogram body Subp_Body as being visited during a recursive
1726 -- traversal started from a top-level scenario.
1728 function Static_Elaboration_Checks return Boolean;
1729 pragma Inline (Static_Elaboration_Checks);
1730 -- Determine whether the static model is in effect
1732 procedure Traverse_Body
1734 In_Init_Cond : Boolean;
1735 In_Partial_Fin : Boolean;
1736 In_Task_Body : Boolean);
1737 -- Inspect the declarations and statements of subprogram body N for
1738 -- suitable elaboration scenarios and process them. The flags should
1739 -- be set when the processing was initiated as follows:
1741 -- In_Init_Cond - initial condition procedure
1742 -- In_Partial_Fin - partial finalization procedure
1743 -- In_Task_Body - task body
1745 procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id);
1746 pragma Inline (Update_Elaboration_Scenario);
1747 -- Update all relevant internal data structures when scenario Old_N is
1748 -- transformed into scenario New_N by Atree.Rewrite.
1750 -----------------------
1751 -- Build_Call_Marker --
1752 -----------------------
1754 procedure Build_Call_Marker (N : Node_Id) is
1755 function In_External_Context
1757 Target_Id : Entity_Id) return Boolean;
1758 pragma Inline (In_External_Context);
1759 -- Determine whether target Target_Id is external to call N which must
1760 -- reside within an instance.
1762 function In_Premature_Context (Call : Node_Id) return Boolean;
1763 -- Determine whether call Call appears within a premature context
1765 function Is_Bridge_Target (Id : Entity_Id) return Boolean;
1766 pragma Inline (Is_Bridge_Target);
1767 -- Determine whether arbitrary entity Id denotes a bridge target
1769 function Is_Default_Expression (Call : Node_Id) return Boolean;
1770 pragma Inline (Is_Default_Expression);
1771 -- Determine whether call Call acts as the expression of a defaulted
1772 -- parameter within a source call.
1774 function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean;
1775 pragma Inline (Is_Generic_Formal_Subp);
1776 -- Determine whether subprogram Subp_Id denotes a generic formal
1777 -- subprogram which appears in the "prologue" of an instantiation.
1779 -------------------------
1780 -- In_External_Context --
1781 -------------------------
1783 function In_External_Context
1785 Target_Id : Entity_Id) return Boolean
1787 Target_Decl : constant Node_Id := Unit_Declaration_Node (Target_Id);
1790 Inst_Body : Node_Id;
1791 Inst_Decl : Node_Id;
1794 -- Performance note: parent traversal
1796 Inst := Find_Enclosing_Instance (Call);
1798 -- The call appears within an instance
1800 if Present (Inst) then
1802 -- The call comes from the main unit and the target does not
1804 if In_Extended_Main_Code_Unit (Call)
1805 and then not In_Extended_Main_Code_Unit (Target_Decl)
1809 -- Otherwise the target declaration must not appear within the
1810 -- instance spec or body.
1813 Extract_Instance_Attributes
1815 Inst_Decl => Inst_Decl,
1816 Inst_Body => Inst_Body);
1818 -- Performance note: parent traversal
1820 return not In_Subtree
1823 Root2 => Inst_Body);
1828 end In_External_Context;
1830 --------------------------
1831 -- In_Premature_Context --
1832 --------------------------
1834 function In_Premature_Context (Call : Node_Id) return Boolean is
1838 -- Climb the parent chain looking for premature contexts
1840 Par := Parent (Call);
1841 while Present (Par) loop
1843 -- Aspect specifications and generic associations are premature
1844 -- contexts because nested calls has not been relocated to their
1847 if Nkind_In (Par, N_Aspect_Specification,
1848 N_Generic_Association)
1852 -- Prevent the search from going too far
1854 elsif Is_Body_Or_Package_Declaration (Par) then
1858 Par := Parent (Par);
1862 end In_Premature_Context;
1864 ----------------------
1865 -- Is_Bridge_Target --
1866 ----------------------
1868 function Is_Bridge_Target (Id : Entity_Id) return Boolean is
1871 Is_Accept_Alternative_Proc (Id)
1872 or else Is_Finalizer_Proc (Id)
1873 or else Is_Partial_Invariant_Proc (Id)
1874 or else Is_Postconditions_Proc (Id)
1875 or else Is_TSS (Id, TSS_Deep_Adjust)
1876 or else Is_TSS (Id, TSS_Deep_Finalize)
1877 or else Is_TSS (Id, TSS_Deep_Initialize);
1878 end Is_Bridge_Target;
1880 ---------------------------
1881 -- Is_Default_Expression --
1882 ---------------------------
1884 function Is_Default_Expression (Call : Node_Id) return Boolean is
1885 Outer_Call : constant Node_Id := Parent (Call);
1886 Outer_Nam : Node_Id;
1889 -- To qualify, the node must appear immediately within a source call
1890 -- which invokes a source target.
1892 if Nkind_In (Outer_Call, N_Entry_Call_Statement,
1894 N_Procedure_Call_Statement)
1895 and then Comes_From_Source (Outer_Call)
1897 Outer_Nam := Extract_Call_Name (Outer_Call);
1900 Is_Entity_Name (Outer_Nam)
1901 and then Present (Entity (Outer_Nam))
1902 and then Is_Subprogram_Or_Entry (Entity (Outer_Nam))
1903 and then Comes_From_Source (Entity (Outer_Nam));
1907 end Is_Default_Expression;
1909 ----------------------------
1910 -- Is_Generic_Formal_Subp --
1911 ----------------------------
1913 function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean is
1914 Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id);
1915 Context : constant Node_Id := Parent (Subp_Decl);
1918 -- To qualify, the subprogram must rename a generic actual subprogram
1919 -- where the enclosing context is an instantiation.
1922 Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration
1923 and then not Comes_From_Source (Subp_Decl)
1924 and then Nkind_In (Context, N_Function_Specification,
1925 N_Package_Specification,
1926 N_Procedure_Specification)
1927 and then Present (Generic_Parent (Context));
1928 end Is_Generic_Formal_Subp;
1932 Call_Attrs : Call_Attributes;
1935 Target_Id : Entity_Id;
1937 -- Start of processing for Build_Call_Marker
1940 -- Nothing to do for ASIS. As a result, ABE checks and diagnostics are
1941 -- not performed in this mode.
1946 -- Nothing to do when the call is being preanalyzed as the marker will
1947 -- be inserted in the wrong place.
1949 elsif Preanalysis_Active then
1952 -- Nothing to do when the input does not denote a call or a requeue
1954 elsif not Nkind_In (N, N_Entry_Call_Statement,
1956 N_Procedure_Call_Statement,
1957 N_Requeue_Statement)
1961 -- Nothing to do when the call is analyzed/resolved too early within an
1962 -- intermediate context.
1964 -- Performance note: parent traversal
1966 elsif In_Premature_Context (N) then
1970 Call_Nam := Extract_Call_Name (N);
1972 -- Nothing to do when the call is erroneous or left in a bad state
1974 if not (Is_Entity_Name (Call_Nam)
1975 and then Present (Entity (Call_Nam))
1976 and then Is_Subprogram_Or_Entry (Entity (Call_Nam)))
1980 -- Nothing to do when the call invokes a generic formal subprogram and
1981 -- switch -gnatd.G (ignore calls through generic formal parameters for
1982 -- elaboration) is in effect. This check must be performed with the
1983 -- direct target of the call to avoid the side effects of mapping
1984 -- actuals to formals using renamings.
1986 elsif Debug_Flag_Dot_GG
1987 and then Is_Generic_Formal_Subp (Entity (Call_Nam))
1992 Extract_Call_Attributes
1994 Target_Id => Target_Id,
1995 Attrs => Call_Attrs);
1997 -- Nothing to do when the call appears within the expanded spec or
1998 -- body of an instantiated generic, the call does not invoke a generic
1999 -- formal subprogram, the target is external to the instance, and switch
2000 -- -gnatdL (ignore external calls from instances for elaboration) is in
2001 -- effect. This behaviour approximates that of the old ABE mechanism.
2004 and then not Is_Generic_Formal_Subp (Entity (Call_Nam))
2006 -- Performance note: parent traversal
2008 and then In_External_Context
2010 Target_Id => Target_Id)
2014 -- Source calls to source targets are always considered because they
2015 -- reflect the original call graph.
2017 elsif Comes_From_Source (Target_Id) and then Call_Attrs.From_Source then
2020 -- A call to a source function which acts as the default expression in
2021 -- another call requires special detection.
2023 elsif Comes_From_Source (Target_Id)
2024 and then Nkind (N) = N_Function_Call
2025 and then Is_Default_Expression (N)
2029 -- The target emulates Ada semantics
2031 elsif Is_Ada_Semantic_Target (Target_Id) then
2034 -- The target acts as a link between scenarios
2036 elsif Is_Bridge_Target (Target_Id) then
2039 -- The target emulates SPARK semantics
2041 elsif Is_SPARK_Semantic_Target (Target_Id) then
2044 -- Otherwise the call is not suitable for ABE processing. This prevents
2045 -- the generation of call markers which will never play a role in ABE
2052 -- At this point it is known that the call will play some role in ABE
2053 -- checks and diagnostics. Create a corresponding call marker in case
2054 -- the original call is heavily transformed by expansion later on.
2056 Marker := Make_Call_Marker (Sloc (N));
2058 -- Inherit the attributes of the original call
2060 Set_Target (Marker, Target_Id);
2061 Set_Is_Elaboration_Checks_OK_Node (Marker, Call_Attrs.Elab_Checks_OK);
2062 Set_Is_Declaration_Level_Node (Marker, Call_Attrs.In_Declarations);
2063 Set_Is_Dispatching_Call (Marker, Call_Attrs.Is_Dispatching);
2064 Set_Is_Ignored_Ghost_Node (Marker, Call_Attrs.Ghost_Mode_Ignore);
2065 Set_Is_Source_Call (Marker, Call_Attrs.From_Source);
2066 Set_Is_SPARK_Mode_On_Node (Marker, Call_Attrs.SPARK_Mode_On);
2068 -- The marker is inserted prior to the original call. This placement has
2069 -- several desirable effects:
2071 -- 1) The marker appears in the same context, in close proximity to
2077 -- 2) Inserting the marker prior to the call ensures that an ABE check
2078 -- will take effect prior to the call.
2084 -- 3) The above two properties are preserved even when the call is a
2085 -- function which is subsequently relocated in order to capture its
2086 -- result. Note that if the call is relocated to a new context, the
2087 -- relocated call will receive a marker of its own.
2091 -- Temp : ... := Func_Call ...;
2094 -- The insertion must take place even when the call does not occur in
2095 -- the main unit to keep the tree symmetric. This ensures that internal
2096 -- name serialization is consistent in case the call marker causes the
2097 -- tree to transform in some way.
2099 Insert_Action (N, Marker);
2101 -- The marker becomes the "corresponding" scenario for the call. Save
2102 -- the marker for later processing by the ABE phase.
2104 Record_Elaboration_Scenario (Marker);
2105 end Build_Call_Marker;
2107 -------------------------------------
2108 -- Build_Variable_Reference_Marker --
2109 -------------------------------------
2111 procedure Build_Variable_Reference_Marker
2116 function In_Pragma (Nod : Node_Id) return Boolean;
2117 -- Determine whether arbitrary node Nod appears within a pragma
2123 function In_Pragma (Nod : Node_Id) return Boolean is
2128 while Present (Par) loop
2129 if Nkind (Par) = N_Pragma then
2132 -- Prevent the search from going too far
2134 elsif Is_Body_Or_Package_Declaration (Par) then
2138 Par := Parent (Par);
2148 Var_Attrs : Variable_Attributes;
2151 -- Start of processing for Build_Variable_Reference_Marker
2154 -- Nothing to do for ASIS. As a result, ABE checks and diagnostics are
2155 -- not performed in this mode.
2160 -- Nothing to do when the reference is being preanalyzed as the marker
2161 -- will be inserted in the wrong place.
2163 elsif Preanalysis_Active then
2166 -- Nothing to do when the input does not denote a reference
2168 elsif not Nkind_In (N, N_Expanded_Name, N_Identifier) then
2171 -- Nothing to do for internally-generated references
2173 elsif not Comes_From_Source (N) then
2176 -- Nothing to do when the reference is erroneous, left in a bad state,
2177 -- or does not denote a variable.
2179 elsif not (Present (Entity (N))
2180 and then Ekind (Entity (N)) = E_Variable
2181 and then Entity (N) /= Any_Id)
2186 Extract_Variable_Reference_Attributes
2189 Attrs => Var_Attrs);
2191 Prag := SPARK_Pragma (Var_Id);
2193 if Comes_From_Source (Var_Id)
2195 -- Both the variable and the reference must appear in SPARK_Mode On
2196 -- regions because this scenario falls under the SPARK rules.
2198 and then Present (Prag)
2199 and then Get_SPARK_Mode_From_Annotation (Prag) = On
2200 and then Is_SPARK_Mode_On_Node (N)
2202 -- The reference must not be considered when it appears in a pragma.
2203 -- If the pragma has run-time semantics, then the reference will be
2204 -- reconsidered once the pragma is expanded.
2206 -- Performance note: parent traversal
2208 and then not In_Pragma (N)
2212 -- Otherwise the reference is not suitable for ABE processing. This
2213 -- prevents the generation of variable markers which will never play
2214 -- a role in ABE diagnostics.
2220 -- At this point it is known that the variable reference will play some
2221 -- role in ABE checks and diagnostics. Create a corresponding variable
2222 -- marker in case the original variable reference is folded or optimized
2225 Marker := Make_Variable_Reference_Marker (Sloc (N));
2227 -- Inherit the attributes of the original variable reference
2229 Set_Target (Marker, Var_Id);
2230 Set_Is_Read (Marker, Read);
2231 Set_Is_Write (Marker, Write);
2233 -- The marker is inserted prior to the original variable reference. The
2234 -- insertion must take place even when the reference does not occur in
2235 -- the main unit to keep the tree symmetric. This ensures that internal
2236 -- name serialization is consistent in case the variable marker causes
2237 -- the tree to transform in some way.
2239 Insert_Action (N, Marker);
2241 -- The marker becomes the "corresponding" scenario for the reference.
2242 -- Save the marker for later processing for the ABE phase.
2244 Record_Elaboration_Scenario (Marker);
2245 end Build_Variable_Reference_Marker;
2247 ---------------------------------
2248 -- Check_Elaboration_Scenarios --
2249 ---------------------------------
2251 procedure Check_Elaboration_Scenarios is
2253 -- Nothing to do for ASIS. As a result, no ABE checks and diagnostics
2254 -- are performed in this mode.
2260 -- Examine the context of the main unit and record all units with prior
2261 -- elaboration with respect to it.
2263 Find_Elaborated_Units;
2265 -- Examine each top-level scenario saved during the Recording phase for
2266 -- conditional ABEs and perform various actions depending on the model
2267 -- in effect. The table of visited bodies is created for each new top-
2270 for Index in Top_Level_Scenarios.First .. Top_Level_Scenarios.Last loop
2271 Reset_Visited_Bodies;
2273 Process_Conditional_ABE (Top_Level_Scenarios.Table (Index));
2276 -- Examine each SPARK scenario saved during the Recording phase which
2277 -- is not necessarily executable during elaboration, but still requires
2278 -- elaboration-related checks.
2280 for Index in SPARK_Scenarios.First .. SPARK_Scenarios.Last loop
2281 Check_SPARK_Scenario (SPARK_Scenarios.Table (Index));
2283 end Check_Elaboration_Scenarios;
2285 ------------------------------
2286 -- Check_Preelaborated_Call --
2287 ------------------------------
2289 procedure Check_Preelaborated_Call (Call : Node_Id) is
2290 function In_Preelaborated_Context (N : Node_Id) return Boolean;
2291 -- Determine whether arbitrary node appears in a preelaborated context
2293 ------------------------------
2294 -- In_Preelaborated_Context --
2295 ------------------------------
2297 function In_Preelaborated_Context (N : Node_Id) return Boolean is
2298 Body_Id : constant Entity_Id := Find_Code_Unit (N);
2299 Spec_Id : constant Entity_Id := Unique_Entity (Body_Id);
2302 -- The node appears within a package body whose corresponding spec is
2303 -- subject to pragma Remote_Call_Interface or Remote_Types. This does
2304 -- not result in a preelaborated context because the package body may
2305 -- be on another machine.
2307 if Ekind (Body_Id) = E_Package_Body
2308 and then Ekind_In (Spec_Id, E_Generic_Package, E_Package)
2309 and then (Is_Remote_Call_Interface (Spec_Id)
2310 or else Is_Remote_Types (Spec_Id))
2314 -- Otherwise the node appears within a preelaborated context when the
2315 -- associated unit is preelaborated.
2318 return Is_Preelaborated_Unit (Spec_Id);
2320 end In_Preelaborated_Context;
2324 Call_Attrs : Call_Attributes;
2325 Level : Enclosing_Level_Kind;
2326 Target_Id : Entity_Id;
2328 -- Start of processing for Check_Preelaborated_Call
2331 Extract_Call_Attributes
2333 Target_Id => Target_Id,
2334 Attrs => Call_Attrs);
2336 -- Nothing to do when the call is internally generated because it is
2337 -- assumed that it will never violate preelaboration.
2339 if not Call_Attrs.From_Source then
2343 -- Performance note: parent traversal
2345 Level := Find_Enclosing_Level (Call);
2347 -- Library-level calls are always considered because they are part of
2348 -- the associated unit's elaboration actions.
2350 if Level in Library_Level then
2353 -- Calls at the library level of a generic package body must be checked
2354 -- because they would render an instantiation illegal if the template is
2355 -- marked as preelaborated. Note that this does not apply to calls at
2356 -- the library level of a generic package spec.
2358 elsif Level = Generic_Package_Body then
2361 -- Otherwise the call does not appear at the proper level and must not
2362 -- be considered for this check.
2368 -- The call appears within a preelaborated unit. Emit a warning only for
2369 -- internal uses, otherwise this is an error.
2371 if In_Preelaborated_Context (Call) then
2372 Error_Msg_Warn := GNAT_Mode;
2374 ("<<non-static call not allowed in preelaborated unit", Call);
2376 end Check_Preelaborated_Call;
2378 ------------------------------
2379 -- Check_SPARK_Derived_Type --
2380 ------------------------------
2382 procedure Check_SPARK_Derived_Type (Typ_Decl : Node_Id) is
2383 Typ : constant Entity_Id := Defining_Entity (Typ_Decl);
2385 -- NOTE: The routines within Check_SPARK_Derived_Type are intentionally
2386 -- unnested to avoid deep indentation of code.
2388 Stop_Check : exception;
2389 -- This exception is raised when the freeze node violates the placement
2392 procedure Check_Overriding_Primitive
2395 pragma Inline (Check_Overriding_Primitive);
2396 -- Verify that freeze node FNode is within the early call region of
2397 -- overriding primitive Prim's body.
2399 function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr;
2400 pragma Inline (Freeze_Node_Location);
2401 -- Return a more accurate source location associated with freeze node
2404 function Precedes_Source_Construct (N : Node_Id) return Boolean;
2405 pragma Inline (Precedes_Source_Construct);
2406 -- Determine whether arbitrary node N appears prior to some source
2409 procedure Suggest_Elaborate_Body
2411 Body_Decl : Node_Id;
2412 Error_Nod : Node_Id);
2413 pragma Inline (Suggest_Elaborate_Body);
2414 -- Suggest the use of pragma Elaborate_Body when the pragma will allow
2415 -- for node N to appear within the early call region of subprogram body
2416 -- Body_Decl. The suggestion is attached to Error_Nod as a continuation
2419 --------------------------------
2420 -- Check_Overriding_Primitive --
2421 --------------------------------
2423 procedure Check_Overriding_Primitive
2427 Prim_Decl : constant Node_Id := Unit_Declaration_Node (Prim);
2428 Body_Decl : Node_Id;
2429 Body_Id : Entity_Id;
2433 Body_Id := Corresponding_Body (Prim_Decl);
2435 -- Nothing to do when the primitive does not have a corresponding
2436 -- body. This can happen when the unit with the bodies is not the
2437 -- main unit subjected to ABE checks.
2439 if No (Body_Id) then
2442 -- The primitive overrides a parent or progenitor primitive
2444 elsif Present (Overridden_Operation (Prim)) then
2446 -- Nothing to do when overriding an interface primitive happens by
2447 -- inheriting a non-interface primitive as the check would be done
2448 -- on the parent primitive.
2450 if Present (Alias (Prim)) then
2454 -- Nothing to do when the primitive is not overriding. The body of
2455 -- such a primitive cannot be targeted by a dispatching call which
2456 -- is executable during elaboration, and cannot cause an ABE.
2462 Body_Decl := Unit_Declaration_Node (Body_Id);
2463 Region := Find_Early_Call_Region (Body_Decl);
2465 -- The freeze node appears prior to the early call region of the
2468 -- IMPORTANT: This check must always be performed even when -gnatd.v
2469 -- (enforce SPARK elaboration rules in SPARK code) is not specified
2470 -- because the static model cannot guarantee the absence of ABEs in
2471 -- in the presence of dispatching calls.
2473 if Earlier_In_Extended_Unit (FNode, Region) then
2474 Error_Msg_Node_2 := Prim;
2476 ("first freezing point of type & must appear within early call "
2477 & "region of primitive body & (SPARK RM 7.7(8))",
2480 Error_Msg_Sloc := Sloc (Region);
2481 Error_Msg_N ("\region starts #", Typ_Decl);
2483 Error_Msg_Sloc := Sloc (Body_Decl);
2484 Error_Msg_N ("\region ends #", Typ_Decl);
2486 Error_Msg_Sloc := Freeze_Node_Location (FNode);
2487 Error_Msg_N ("\first freezing point #", Typ_Decl);
2489 -- If applicable, suggest the use of pragma Elaborate_Body in the
2490 -- associated package spec.
2492 Suggest_Elaborate_Body
2494 Body_Decl => Body_Decl,
2495 Error_Nod => Typ_Decl);
2499 end Check_Overriding_Primitive;
2501 --------------------------
2502 -- Freeze_Node_Location --
2503 --------------------------
2505 function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr is
2506 Context : constant Node_Id := Parent (FNode);
2507 Loc : constant Source_Ptr := Sloc (FNode);
2509 Prv_Decls : List_Id;
2510 Vis_Decls : List_Id;
2513 -- In general, the source location of the freeze node is as close as
2514 -- possible to the real freeze point, except when the freeze node is
2515 -- at the "bottom" of a package spec.
2517 if Nkind (Context) = N_Package_Specification then
2518 Prv_Decls := Private_Declarations (Context);
2519 Vis_Decls := Visible_Declarations (Context);
2521 -- The freeze node appears in the private declarations of the
2524 if Present (Prv_Decls)
2525 and then List_Containing (FNode) = Prv_Decls
2529 -- The freeze node appears in the visible declarations of the
2530 -- package and there are no private declarations.
2532 elsif Present (Vis_Decls)
2533 and then List_Containing (FNode) = Vis_Decls
2534 and then (No (Prv_Decls) or else Is_Empty_List (Prv_Decls))
2538 -- Otherwise the freeze node is not in the "last" declarative list
2539 -- of the package. Use the existing source location of the freeze
2546 -- The freeze node appears at the "bottom" of the package when it
2547 -- is in the "last" declarative list and is either the last in the
2548 -- list or is followed by internal constructs only. In that case
2549 -- the more appropriate source location is that of the package end
2552 if not Precedes_Source_Construct (FNode) then
2553 return Sloc (End_Label (Context));
2558 end Freeze_Node_Location;
2560 -------------------------------
2561 -- Precedes_Source_Construct --
2562 -------------------------------
2564 function Precedes_Source_Construct (N : Node_Id) return Boolean is
2569 while Present (Decl) loop
2570 if Comes_From_Source (Decl) then
2573 -- A generated body for a source expression function is treated as
2574 -- a source construct.
2576 elsif Nkind (Decl) = N_Subprogram_Body
2577 and then Was_Expression_Function (Decl)
2578 and then Comes_From_Source (Original_Node (Decl))
2587 end Precedes_Source_Construct;
2589 ----------------------------
2590 -- Suggest_Elaborate_Body --
2591 ----------------------------
2593 procedure Suggest_Elaborate_Body
2595 Body_Decl : Node_Id;
2596 Error_Nod : Node_Id)
2598 Unt : constant Node_Id := Unit (Cunit (Main_Unit));
2602 -- The suggestion applies only when the subprogram body resides in a
2603 -- compilation package body, and a pragma Elaborate_Body would allow
2604 -- for the node to appear in the early call region of the subprogram
2605 -- body. This implies that all code from the subprogram body up to
2606 -- the node is preelaborable.
2608 if Nkind (Unt) = N_Package_Body then
2610 -- Find the start of the early call region again assuming that the
2611 -- package spec has pragma Elaborate_Body. Note that the internal
2612 -- data structures are intentionally not updated because this is a
2613 -- speculative search.
2616 Find_Early_Call_Region
2617 (Body_Decl => Body_Decl,
2618 Assume_Elab_Body => True,
2619 Skip_Memoization => True);
2621 -- If the node appears within the early call region, assuming that
2622 -- the package spec carries pragma Elaborate_Body, then it is safe
2623 -- to suggest the pragma.
2625 if Earlier_In_Extended_Unit (Region, N) then
2626 Error_Msg_Name_1 := Name_Elaborate_Body;
2628 ("\consider adding pragma % in spec of unit &",
2629 Error_Nod, Defining_Entity (Unt));
2632 end Suggest_Elaborate_Body;
2636 FNode : constant Node_Id := Freeze_Node (Typ);
2637 Prims : constant Elist_Id := Direct_Primitive_Operations (Typ);
2639 Prim_Elmt : Elmt_Id;
2641 -- Start of processing for Check_SPARK_Derived_Type
2644 -- A type should have its freeze node set by the time SPARK scenarios
2645 -- are being verified.
2647 pragma Assert (Present (FNode));
2649 -- Verify that the freeze node of the derived type is within the early
2650 -- call region of each overriding primitive body (SPARK RM 7.7(8)).
2652 if Present (Prims) then
2653 Prim_Elmt := First_Elmt (Prims);
2654 while Present (Prim_Elmt) loop
2655 Check_Overriding_Primitive
2656 (Prim => Node (Prim_Elmt),
2659 Next_Elmt (Prim_Elmt);
2666 end Check_SPARK_Derived_Type;
2668 -------------------------------
2669 -- Check_SPARK_Instantiation --
2670 -------------------------------
2672 procedure Check_SPARK_Instantiation (Exp_Inst : Node_Id) is
2673 Gen_Attrs : Target_Attributes;
2676 Inst_Attrs : Instantiation_Attributes;
2677 Inst_Id : Entity_Id;
2680 Extract_Instantiation_Attributes
2681 (Exp_Inst => Exp_Inst,
2685 Attrs => Inst_Attrs);
2687 Extract_Target_Attributes (Gen_Id, Gen_Attrs);
2689 -- The instantiation and the generic body are both in the main unit
2691 if Present (Gen_Attrs.Body_Decl)
2692 and then In_Extended_Main_Code_Unit (Gen_Attrs.Body_Decl)
2694 -- If the instantiation appears prior to the generic body, then the
2695 -- instantiation is illegal (SPARK RM 7.7(6)).
2697 -- IMPORTANT: This check must always be performed even when -gnatd.v
2698 -- (enforce SPARK elaboration rules in SPARK code) is not specified
2699 -- because the rule prevents use-before-declaration of objects that
2700 -- may precede the generic body.
2702 and then Earlier_In_Extended_Unit (Inst, Gen_Attrs.Body_Decl)
2704 Error_Msg_NE ("cannot instantiate & before body seen", Inst, Gen_Id);
2706 end Check_SPARK_Instantiation;
2708 --------------------------
2709 -- Check_SPARK_Scenario --
2710 --------------------------
2712 procedure Check_SPARK_Scenario (N : Node_Id) is
2714 -- Add the current scenario to the stack of active scenarios
2716 Push_Active_Scenario (N);
2718 if Is_Suitable_SPARK_Derived_Type (N) then
2719 Check_SPARK_Derived_Type (N);
2721 elsif Is_Suitable_SPARK_Instantiation (N) then
2722 Check_SPARK_Instantiation (N);
2724 elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
2725 Check_SPARK_Refined_State_Pragma (N);
2728 -- Remove the current scenario from the stack of active scenarios once
2729 -- all ABE diagnostics and checks have been performed.
2731 Pop_Active_Scenario (N);
2732 end Check_SPARK_Scenario;
2734 --------------------------------------
2735 -- Check_SPARK_Refined_State_Pragma --
2736 --------------------------------------
2738 procedure Check_SPARK_Refined_State_Pragma (N : Node_Id) is
2740 -- NOTE: The routines within Check_SPARK_Refined_State_Pragma are
2741 -- intentionally unnested to avoid deep indentation of code.
2743 procedure Check_SPARK_Constituent (Constit_Id : Entity_Id);
2744 pragma Inline (Check_SPARK_Constituent);
2745 -- Ensure that a single constituent Constit_Id is elaborated prior to
2748 procedure Check_SPARK_Constituents (Constits : Elist_Id);
2749 pragma Inline (Check_SPARK_Constituents);
2750 -- Ensure that all constituents found in list Constits are elaborated
2751 -- prior to the main unit.
2753 procedure Check_SPARK_Initialized_State (State : Node_Id);
2754 pragma Inline (Check_SPARK_Initialized_State);
2755 -- Ensure that the constituents of single abstract state State are
2756 -- elaborated prior to the main unit.
2758 procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id);
2759 pragma Inline (Check_SPARK_Initialized_States);
2760 -- Ensure that the constituents of all abstract states which appear in
2761 -- the Initializes pragma of package Pack_Id are elaborated prior to the
2764 -----------------------------
2765 -- Check_SPARK_Constituent --
2766 -----------------------------
2768 procedure Check_SPARK_Constituent (Constit_Id : Entity_Id) is
2772 -- Nothing to do for "null" constituents
2774 if Nkind (Constit_Id) = N_Null then
2777 -- Nothing to do for illegal constituents
2779 elsif Error_Posted (Constit_Id) then
2783 Prag := SPARK_Pragma (Constit_Id);
2785 -- The check applies only when the constituent is subject to pragma
2789 and then Get_SPARK_Mode_From_Annotation (Prag) = On
2791 -- An external constituent of an abstract state which appears in
2792 -- the Initializes pragma of a package spec imposes an Elaborate
2793 -- requirement on the context of the main unit. Determine whether
2794 -- the context has a pragma strong enough to meet the requirement.
2796 -- IMPORTANT: This check is performed only when -gnatd.v (enforce
2797 -- SPARK elaboration rules in SPARK code) is in effect because the
2798 -- static model can ensure the prior elaboration of the unit which
2799 -- contains a constituent by installing implicit Elaborate pragma.
2801 if Debug_Flag_Dot_V then
2802 Meet_Elaboration_Requirement
2804 Target_Id => Constit_Id,
2805 Req_Nam => Name_Elaborate);
2807 -- Otherwise ensure that the unit with the external constituent is
2808 -- elaborated prior to the main unit.
2811 Ensure_Prior_Elaboration
2813 Unit_Id => Find_Top_Unit (Constit_Id),
2814 Prag_Nam => Name_Elaborate,
2815 In_Partial_Fin => False,
2816 In_Task_Body => False);
2819 end Check_SPARK_Constituent;
2821 ------------------------------
2822 -- Check_SPARK_Constituents --
2823 ------------------------------
2825 procedure Check_SPARK_Constituents (Constits : Elist_Id) is
2826 Constit_Elmt : Elmt_Id;
2829 if Present (Constits) then
2830 Constit_Elmt := First_Elmt (Constits);
2831 while Present (Constit_Elmt) loop
2832 Check_SPARK_Constituent (Node (Constit_Elmt));
2833 Next_Elmt (Constit_Elmt);
2836 end Check_SPARK_Constituents;
2838 -----------------------------------
2839 -- Check_SPARK_Initialized_State --
2840 -----------------------------------
2842 procedure Check_SPARK_Initialized_State (State : Node_Id) is
2844 State_Id : Entity_Id;
2847 -- Nothing to do for "null" initialization items
2849 if Nkind (State) = N_Null then
2852 -- Nothing to do for illegal states
2854 elsif Error_Posted (State) then
2858 State_Id := Entity_Of (State);
2860 -- Sanitize the state
2862 if No (State_Id) then
2865 elsif Error_Posted (State_Id) then
2868 elsif Ekind (State_Id) /= E_Abstract_State then
2872 -- The check is performed only when the abstract state is subject to
2875 Prag := SPARK_Pragma (State_Id);
2878 and then Get_SPARK_Mode_From_Annotation (Prag) = On
2880 Check_SPARK_Constituents (Refinement_Constituents (State_Id));
2882 end Check_SPARK_Initialized_State;
2884 ------------------------------------
2885 -- Check_SPARK_Initialized_States --
2886 ------------------------------------
2888 procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id) is
2889 Prag : constant Node_Id := Get_Pragma (Pack_Id, Pragma_Initializes);
2894 if Present (Prag) then
2895 Inits := Expression (Get_Argument (Prag, Pack_Id));
2897 -- Avoid processing a "null" initialization list. The only other
2898 -- alternative is an aggregate.
2900 if Nkind (Inits) = N_Aggregate then
2902 -- The initialization items appear in list form:
2906 if Present (Expressions (Inits)) then
2907 Init := First (Expressions (Inits));
2908 while Present (Init) loop
2909 Check_SPARK_Initialized_State (Init);
2914 -- The initialization items appear in associated form:
2916 -- (state1 => item1,
2917 -- state2 => (item2, item3))
2919 if Present (Component_Associations (Inits)) then
2920 Init := First (Component_Associations (Inits));
2921 while Present (Init) loop
2922 Check_SPARK_Initialized_State (Init);
2928 end Check_SPARK_Initialized_States;
2932 Pack_Body : constant Node_Id := Find_Related_Package_Or_Body (N);
2934 -- Start of processing for Check_SPARK_Refined_State_Pragma
2937 -- Pragma Refined_State must be associated with a package body
2940 (Present (Pack_Body) and then Nkind (Pack_Body) = N_Package_Body);
2942 -- Verify that each external contitunent of an abstract state mentioned
2943 -- in pragma Initializes is properly elaborated.
2945 Check_SPARK_Initialized_States (Unique_Defining_Entity (Pack_Body));
2946 end Check_SPARK_Refined_State_Pragma;
2948 ----------------------
2949 -- Compilation_Unit --
2950 ----------------------
2952 function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id is
2953 Comp_Unit : Node_Id;
2956 Comp_Unit := Parent (Unit_Id);
2958 -- Handle the case where a concurrent subunit is rewritten as a null
2959 -- statement due to expansion activities.
2961 if Nkind (Comp_Unit) = N_Null_Statement
2962 and then Nkind_In (Original_Node (Comp_Unit), N_Protected_Body,
2965 Comp_Unit := Parent (Comp_Unit);
2966 pragma Assert (Nkind (Comp_Unit) = N_Subunit);
2968 -- Otherwise use the declaration node of the unit
2971 Comp_Unit := Parent (Unit_Declaration_Node (Unit_Id));
2974 -- Handle the case where a subprogram instantiation which acts as a
2975 -- compilation unit is expanded into an anonymous package that wraps
2976 -- the instantiated subprogram.
2978 if Nkind (Comp_Unit) = N_Package_Specification
2979 and then Nkind_In (Original_Node (Parent (Comp_Unit)),
2980 N_Function_Instantiation,
2981 N_Procedure_Instantiation)
2983 Comp_Unit := Parent (Parent (Comp_Unit));
2985 -- Handle the case where the compilation unit is a subunit
2987 elsif Nkind (Comp_Unit) = N_Subunit then
2988 Comp_Unit := Parent (Comp_Unit);
2991 pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
2994 end Compilation_Unit;
2996 -----------------------
2997 -- Early_Call_Region --
2998 -----------------------
3000 function Early_Call_Region (Body_Id : Entity_Id) return Node_Id is
3002 pragma Assert (Ekind_In (Body_Id, E_Entry,
3006 E_Subprogram_Body));
3008 if Early_Call_Regions_In_Use then
3009 return Early_Call_Regions.Get (Body_Id);
3012 return Early_Call_Regions_No_Element;
3013 end Early_Call_Region;
3015 -----------------------------
3016 -- Early_Call_Regions_Hash --
3017 -----------------------------
3019 function Early_Call_Regions_Hash
3020 (Key : Entity_Id) return Early_Call_Regions_Index
3023 return Early_Call_Regions_Index (Key mod Early_Call_Regions_Max);
3024 end Early_Call_Regions_Hash;
3030 procedure Elab_Msg_NE
3037 function Prefix return String;
3038 -- Obtain the prefix of the message
3040 function Suffix return String;
3041 -- Obtain the suffix of the message
3047 function Prefix return String is
3060 function Suffix return String is
3069 -- Start of processing for Elab_Msg_NE
3072 Error_Msg_NE (Prefix & Msg & Suffix, N, Id);
3075 ------------------------
3076 -- Elaboration_Status --
3077 ------------------------
3079 function Elaboration_Status
3080 (Unit_Id : Entity_Id) return Elaboration_Attributes
3083 if Elaboration_Statuses_In_Use then
3084 return Elaboration_Statuses.Get (Unit_Id);
3087 return Elaboration_Statuses_No_Element;
3088 end Elaboration_Status;
3090 -------------------------------
3091 -- Elaboration_Statuses_Hash --
3092 -------------------------------
3094 function Elaboration_Statuses_Hash
3095 (Key : Entity_Id) return Elaboration_Statuses_Index
3098 return Elaboration_Statuses_Index (Key mod Elaboration_Statuses_Max);
3099 end Elaboration_Statuses_Hash;
3101 ------------------------------
3102 -- Ensure_Prior_Elaboration --
3103 ------------------------------
3105 procedure Ensure_Prior_Elaboration
3107 Unit_Id : Entity_Id;
3109 In_Partial_Fin : Boolean;
3110 In_Task_Body : Boolean)
3113 pragma Assert (Nam_In (Prag_Nam, Name_Elaborate, Name_Elaborate_All));
3115 -- Nothing to do when the need for prior elaboration came from a partial
3116 -- finalization routine which occurs in an initialization context. This
3117 -- behaviour parallels that of the old ABE mechanism.
3119 if In_Partial_Fin then
3122 -- Nothing to do when the need for prior elaboration came from a task
3123 -- body and switch -gnatd.y (disable implicit pragma Elaborate_All on
3124 -- task bodies) is in effect.
3126 elsif Debug_Flag_Dot_Y and then In_Task_Body then
3129 -- Nothing to do when the unit is elaborated prior to the main unit.
3130 -- This check must also consider the following cases:
3132 -- * No check is made against the context of the main unit because this
3133 -- is specific to the elaboration model in effect and requires custom
3134 -- handling (see Ensure_xxx_Prior_Elaboration).
3136 -- * Unit_Id is subject to pragma Elaborate_Body. An implicit pragma
3137 -- Elaborate[_All] MUST be generated even though Unit_Id is always
3138 -- elaborated prior to the main unit. This is a conservative strategy
3139 -- which ensures that other units withed by Unit_Id will not lead to
3142 -- package A is package body A is
3143 -- procedure ABE; procedure ABE is ... end ABE;
3147 -- package B is package body B is
3148 -- pragma Elaborate_Body; procedure Proc is
3150 -- procedure Proc; A.ABE;
3151 -- package B; end Proc;
3155 -- package C is package body C is
3161 -- In the example above, the elaboration of C invokes B.Proc. B is
3162 -- subject to pragma Elaborate_Body. If no pragma Elaborate[_All] is
3163 -- generated for B in C, then the following elaboratio order will lead
3166 -- spec of A elaborated
3167 -- spec of B elaborated
3168 -- body of B elaborated
3169 -- spec of C elaborated
3170 -- body of C elaborated <-- calls B.Proc which calls A.ABE
3171 -- body of A elaborated <-- problem
3173 -- The generation of an implicit pragma Elaborate_All (B) ensures that
3174 -- the elaboration order mechanism will not pick the above order.
3176 -- An implicit Elaborate is NOT generated when the unit is subject to
3177 -- Elaborate_Body because both pragmas have the exact same effect.
3179 -- * Unit_Id is the main unit. An implicit pragma Elaborate[_All] MUST
3180 -- NOT be generated in this case because a unit cannot depend on its
3181 -- own elaboration. This case is therefore treated as valid prior
3184 elsif Has_Prior_Elaboration
3185 (Unit_Id => Unit_Id,
3186 Same_Unit_OK => True,
3187 Elab_Body_OK => Prag_Nam = Name_Elaborate)
3191 -- Suggest the use of pragma Prag_Nam when the dynamic model is in
3194 elsif Dynamic_Elaboration_Checks then
3195 Ensure_Prior_Elaboration_Dynamic
3198 Prag_Nam => Prag_Nam);
3200 -- Install an implicit pragma Prag_Nam when the static model is in
3204 pragma Assert (Static_Elaboration_Checks);
3206 Ensure_Prior_Elaboration_Static
3209 Prag_Nam => Prag_Nam);
3211 end Ensure_Prior_Elaboration;
3213 --------------------------------------
3214 -- Ensure_Prior_Elaboration_Dynamic --
3215 --------------------------------------
3217 procedure Ensure_Prior_Elaboration_Dynamic
3219 Unit_Id : Entity_Id;
3222 procedure Info_Missing_Pragma;
3223 pragma Inline (Info_Missing_Pragma);
3224 -- Output information concerning missing Elaborate or Elaborate_All
3225 -- pragma with name Prag_Nam for scenario N, which would ensure the
3226 -- prior elaboration of Unit_Id.
3228 -------------------------
3229 -- Info_Missing_Pragma --
3230 -------------------------
3232 procedure Info_Missing_Pragma is
3234 -- Internal units are ignored as they cause unnecessary noise
3236 if not In_Internal_Unit (Unit_Id) then
3238 -- The name of the unit subjected to the elaboration pragma is
3239 -- fully qualified to improve the clarity of the info message.
3241 Error_Msg_Name_1 := Prag_Nam;
3242 Error_Msg_Qual_Level := Nat'Last;
3244 Error_Msg_NE ("info: missing pragma % for unit &", N, Unit_Id);
3245 Error_Msg_Qual_Level := 0;
3247 end Info_Missing_Pragma;
3251 Elab_Attrs : Elaboration_Attributes;
3252 Level : Enclosing_Level_Kind;
3254 -- Start of processing for Ensure_Prior_Elaboration_Dynamic
3257 Elab_Attrs := Elaboration_Status (Unit_Id);
3259 -- Nothing to do when the unit is guaranteed prior elaboration by means
3260 -- of a source Elaborate[_All] pragma.
3262 if Present (Elab_Attrs.Source_Pragma) then
3266 -- Output extra information on a missing Elaborate[_All] pragma when
3267 -- switch -gnatel (info messages on implicit Elaborate[_All] pragmas
3270 if Elab_Info_Messages then
3272 -- Performance note: parent traversal
3274 Level := Find_Enclosing_Level (N);
3276 -- Declaration-level scenario
3278 if (Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N))
3279 and then Level = Declaration_Level
3283 -- Library-level scenario
3285 elsif Level in Library_Level then
3288 -- Instantiation library-level scenario
3290 elsif Level = Instantiation then
3293 -- Otherwise the scenario does not appear at the proper level and
3294 -- cannot possibly act as a top-level scenario.
3300 Info_Missing_Pragma;
3302 end Ensure_Prior_Elaboration_Dynamic;
3304 -------------------------------------
3305 -- Ensure_Prior_Elaboration_Static --
3306 -------------------------------------
3308 procedure Ensure_Prior_Elaboration_Static
3310 Unit_Id : Entity_Id;
3313 function Find_With_Clause
3315 Withed_Id : Entity_Id) return Node_Id;
3316 pragma Inline (Find_With_Clause);
3317 -- Find a nonlimited with clause in the list of context items Items
3318 -- that withs unit Withed_Id. Return Empty if no such clause is found.
3320 procedure Info_Implicit_Pragma;
3321 pragma Inline (Info_Implicit_Pragma);
3322 -- Output information concerning an implicitly generated Elaborate or
3323 -- Elaborate_All pragma with name Prag_Nam for scenario N which ensures
3324 -- the prior elaboration of unit Unit_Id.
3326 ----------------------
3327 -- Find_With_Clause --
3328 ----------------------
3330 function Find_With_Clause
3332 Withed_Id : Entity_Id) return Node_Id
3337 -- Examine the context clauses looking for a suitable with. Note that
3338 -- limited clauses do not affect the elaboration order.
3340 Item := First (Items);
3341 while Present (Item) loop
3342 if Nkind (Item) = N_With_Clause
3343 and then not Error_Posted (Item)
3344 and then not Limited_Present (Item)
3345 and then Entity (Name (Item)) = Withed_Id
3354 end Find_With_Clause;
3356 --------------------------
3357 -- Info_Implicit_Pragma --
3358 --------------------------
3360 procedure Info_Implicit_Pragma is
3362 -- Internal units are ignored as they cause unnecessary noise
3364 if not In_Internal_Unit (Unit_Id) then
3366 -- The name of the unit subjected to the elaboration pragma is
3367 -- fully qualified to improve the clarity of the info message.
3369 Error_Msg_Name_1 := Prag_Nam;
3370 Error_Msg_Qual_Level := Nat'Last;
3373 ("info: implicit pragma % generated for unit &", N, Unit_Id);
3375 Error_Msg_Qual_Level := 0;
3376 Output_Active_Scenarios (N);
3378 end Info_Implicit_Pragma;
3382 Main_Cunit : constant Node_Id := Cunit (Main_Unit);
3383 Loc : constant Source_Ptr := Sloc (Main_Cunit);
3384 Unit_Cunit : constant Node_Id := Compilation_Unit (Unit_Id);
3386 Is_Instantiation : constant Boolean :=
3387 Nkind (N) in N_Generic_Instantiation;
3390 Elab_Attrs : Elaboration_Attributes;
3393 -- Start of processing for Ensure_Prior_Elaboration_Static
3396 Elab_Attrs := Elaboration_Status (Unit_Id);
3398 -- Nothing to do when the unit is guaranteed prior elaboration by means
3399 -- of a source Elaborate[_All] pragma.
3401 if Present (Elab_Attrs.Source_Pragma) then
3404 -- Nothing to do when the unit has an existing implicit Elaborate[_All]
3405 -- pragma installed by a previous scenario.
3407 elsif Present (Elab_Attrs.With_Clause) then
3409 -- The unit is already guaranteed prior elaboration by means of an
3410 -- implicit Elaborate pragma, however the current scenario imposes
3411 -- a stronger requirement of Elaborate_All. "Upgrade" the existing
3412 -- pragma to match this new requirement.
3414 if Elaborate_Desirable (Elab_Attrs.With_Clause)
3415 and then Prag_Nam = Name_Elaborate_All
3417 Set_Elaborate_All_Desirable (Elab_Attrs.With_Clause);
3418 Set_Elaborate_Desirable (Elab_Attrs.With_Clause, False);
3424 -- At this point it is known that the unit has no prior elaboration
3425 -- according to pragmas and hierarchical relationships.
3427 Items := Context_Items (Main_Cunit);
3431 Set_Context_Items (Main_Cunit, Items);
3434 -- Locate the with clause for the unit. Note that there may not be a
3435 -- clause if the unit is visible through a subunit-body, body-spec, or
3436 -- spec-parent relationship.
3441 Withed_Id => Unit_Id);
3446 -- Note that adding implicit with clauses is safe because analysis,
3447 -- resolution, and expansion have already taken place and it is not
3448 -- possible to interfere with visibility.
3452 Make_With_Clause (Loc,
3453 Name => New_Occurrence_Of (Unit_Id, Loc));
3455 Set_Implicit_With (Clause);
3456 Set_Library_Unit (Clause, Unit_Cunit);
3458 Append_To (Items, Clause);
3461 -- Instantiations require an implicit Elaborate because Elaborate_All is
3462 -- too conservative and may introduce non-existent elaboration cycles.
3464 if Is_Instantiation then
3465 Set_Elaborate_Desirable (Clause);
3467 -- Otherwise generate an implicit Elaborate_All
3470 Set_Elaborate_All_Desirable (Clause);
3473 -- The implicit Elaborate[_All] ensures the prior elaboration of the
3474 -- unit. Include the unit in the elaboration context of the main unit.
3476 Set_Elaboration_Status
3477 (Unit_Id => Unit_Id,
3478 Val => Elaboration_Attributes'(Source_Pragma => Empty,
3479 With_Clause => Clause));
3481 -- Output extra information on an implicit Elaborate[_All] pragma when
3482 -- switch -gnatel (info messages on implicit Elaborate[_All] pragmas is
3485 if Elab_Info_Messages then
3486 Info_Implicit_Pragma;
3488 end Ensure_Prior_Elaboration_Static;
3490 -----------------------------
3491 -- Extract_Assignment_Name --
3492 -----------------------------
3494 function Extract_Assignment_Name (Asmt : Node_Id) return Node_Id is
3500 -- When the name denotes an array or record component, find the whole
3503 while Nkind_In (Nam, N_Explicit_Dereference,
3504 N_Indexed_Component,
3505 N_Selected_Component,
3508 Nam := Prefix (Nam);
3512 end Extract_Assignment_Name;
3514 -----------------------------
3515 -- Extract_Call_Attributes --
3516 -----------------------------
3518 procedure Extract_Call_Attributes
3520 Target_Id : out Entity_Id;
3521 Attrs : out Call_Attributes)
3523 From_Source : Boolean;
3524 In_Declarations : Boolean;
3525 Is_Dispatching : Boolean;
3528 -- Extraction for call markers
3530 if Nkind (Call) = N_Call_Marker then
3531 Target_Id := Target (Call);
3532 From_Source := Is_Source_Call (Call);
3533 In_Declarations := Is_Declaration_Level_Node (Call);
3534 Is_Dispatching := Is_Dispatching_Call (Call);
3536 -- Extraction for entry calls, requeue, and subprogram calls
3539 pragma Assert (Nkind_In (Call, N_Entry_Call_Statement,
3541 N_Procedure_Call_Statement,
3542 N_Requeue_Statement));
3544 Target_Id := Entity (Extract_Call_Name (Call));
3545 From_Source := Comes_From_Source (Call);
3547 -- Performance note: parent traversal
3549 In_Declarations := Find_Enclosing_Level (Call) = Declaration_Level;
3551 Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
3552 and then Present (Controlling_Argument (Call));
3555 -- Obtain the original entry or subprogram which the target may rename
3556 -- except when the target is an instantiation. In this case the alias
3557 -- is the internally generated subprogram which appears within the the
3558 -- anonymous package created for the instantiation. Such an alias is not
3559 -- a suitable target.
3561 if not (Is_Subprogram (Target_Id)
3562 and then Is_Generic_Instance (Target_Id))
3564 Target_Id := Get_Renamed_Entity (Target_Id);
3567 -- Set all attributes
3569 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Call);
3570 Attrs.From_Source := From_Source;
3571 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Node (Call);
3572 Attrs.In_Declarations := In_Declarations;
3573 Attrs.Is_Dispatching := Is_Dispatching;
3574 Attrs.SPARK_Mode_On := Is_SPARK_Mode_On_Node (Call);
3575 end Extract_Call_Attributes;
3577 -----------------------
3578 -- Extract_Call_Name --
3579 -----------------------
3581 function Extract_Call_Name (Call : Node_Id) return Node_Id is
3587 -- When the call invokes an entry family, the name appears as an indexed
3590 if Nkind (Nam) = N_Indexed_Component then
3591 Nam := Prefix (Nam);
3594 -- When the call employs the object.operation form, the name appears as
3595 -- a selected component.
3597 if Nkind (Nam) = N_Selected_Component then
3598 Nam := Selector_Name (Nam);
3602 end Extract_Call_Name;
3604 ---------------------------------
3605 -- Extract_Instance_Attributes --
3606 ---------------------------------
3608 procedure Extract_Instance_Attributes
3609 (Exp_Inst : Node_Id;
3610 Inst_Body : out Node_Id;
3611 Inst_Decl : out Node_Id)
3613 Body_Id : Entity_Id;
3616 -- Assume that the attributes are unavailable
3621 -- Generic package or subprogram spec
3623 if Nkind_In (Exp_Inst, N_Package_Declaration,
3624 N_Subprogram_Declaration)
3626 Inst_Decl := Exp_Inst;
3627 Body_Id := Corresponding_Body (Inst_Decl);
3629 if Present (Body_Id) then
3630 Inst_Body := Unit_Declaration_Node (Body_Id);
3633 -- Generic package or subprogram body
3637 (Nkind_In (Exp_Inst, N_Package_Body, N_Subprogram_Body));
3639 Inst_Body := Exp_Inst;
3640 Inst_Decl := Unit_Declaration_Node (Corresponding_Spec (Inst_Body));
3642 end Extract_Instance_Attributes;
3644 --------------------------------------
3645 -- Extract_Instantiation_Attributes --
3646 --------------------------------------
3648 procedure Extract_Instantiation_Attributes
3649 (Exp_Inst : Node_Id;
3651 Inst_Id : out Entity_Id;
3652 Gen_Id : out Entity_Id;
3653 Attrs : out Instantiation_Attributes)
3656 Inst := Original_Node (Exp_Inst);
3657 Inst_Id := Defining_Entity (Inst);
3659 -- Traverse a possible chain of renamings to obtain the original generic
3660 -- being instantiatied.
3662 Gen_Id := Get_Renamed_Entity (Entity (Name (Inst)));
3664 -- Set all attributes
3666 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Inst);
3667 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Node (Inst);
3668 Attrs.In_Declarations := Is_Declaration_Level_Node (Inst);
3669 Attrs.SPARK_Mode_On := Is_SPARK_Mode_On_Node (Inst);
3670 end Extract_Instantiation_Attributes;
3672 -------------------------------
3673 -- Extract_Target_Attributes --
3674 -------------------------------
3676 procedure Extract_Target_Attributes
3677 (Target_Id : Entity_Id;
3678 Attrs : out Target_Attributes)
3680 procedure Extract_Package_Or_Subprogram_Attributes
3681 (Spec_Id : out Entity_Id;
3682 Body_Decl : out Node_Id);
3683 -- Obtain the attributes associated with a package or a subprogram.
3684 -- Spec_Id is the package or subprogram. Body_Decl is the declaration
3685 -- of the corresponding package or subprogram body.
3687 procedure Extract_Protected_Entry_Attributes
3688 (Spec_Id : out Entity_Id;
3689 Body_Decl : out Node_Id;
3690 Body_Barf : out Node_Id);
3691 -- Obtain the attributes associated with a protected entry [family].
3692 -- Spec_Id is the entity of the protected body subprogram. Body_Decl
3693 -- is the declaration of Spec_Id's corresponding body. Body_Barf is
3694 -- the declaration of the barrier function body.
3696 procedure Extract_Protected_Subprogram_Attributes
3697 (Spec_Id : out Entity_Id;
3698 Body_Decl : out Node_Id);
3699 -- Obtain the attributes associated with a protected subprogram. Formal
3700 -- Spec_Id is the entity of the protected body subprogram. Body_Decl is
3701 -- the declaration of Spec_Id's corresponding body.
3703 procedure Extract_Task_Entry_Attributes
3704 (Spec_Id : out Entity_Id;
3705 Body_Decl : out Node_Id);
3706 -- Obtain the attributes associated with a task entry [family]. Formal
3707 -- Spec_Id is the entity of the task body procedure. Body_Decl is the
3708 -- declaration of Spec_Id's corresponding body.
3710 ----------------------------------------------
3711 -- Extract_Package_Or_Subprogram_Attributes --
3712 ----------------------------------------------
3714 procedure Extract_Package_Or_Subprogram_Attributes
3715 (Spec_Id : out Entity_Id;
3716 Body_Decl : out Node_Id)
3718 Body_Id : Entity_Id;
3719 Init_Id : Entity_Id;
3720 Spec_Decl : Node_Id;
3723 -- Assume that the body is not available
3726 Spec_Id := Target_Id;
3728 -- For body retrieval purposes, the entity of the initial declaration
3729 -- is that of the spec.
3733 -- The only exception to the above is a function which returns a
3734 -- constrained array type in a SPARK-to-C compilation. In this case
3735 -- the function receives a corresponding procedure which has an out
3736 -- parameter. The proper body for ABE checks and diagnostics is that
3737 -- of the procedure.
3739 if Ekind (Init_Id) = E_Function
3740 and then Rewritten_For_C (Init_Id)
3742 Init_Id := Corresponding_Procedure (Init_Id);
3745 -- Extract the attributes of the body
3747 Spec_Decl := Unit_Declaration_Node (Init_Id);
3749 -- The initial declaration is a stand alone subprogram body
3751 if Nkind (Spec_Decl) = N_Subprogram_Body then
3752 Body_Decl := Spec_Decl;
3754 -- Otherwise the package or subprogram has a spec and a completing
3757 elsif Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
3758 N_Generic_Subprogram_Declaration,
3759 N_Package_Declaration,
3760 N_Subprogram_Body_Stub,
3761 N_Subprogram_Declaration)
3763 Body_Id := Corresponding_Body (Spec_Decl);
3765 if Present (Body_Id) then
3766 Body_Decl := Unit_Declaration_Node (Body_Id);
3769 end Extract_Package_Or_Subprogram_Attributes;
3771 ----------------------------------------
3772 -- Extract_Protected_Entry_Attributes --
3773 ----------------------------------------
3775 procedure Extract_Protected_Entry_Attributes
3776 (Spec_Id : out Entity_Id;
3777 Body_Decl : out Node_Id;
3778 Body_Barf : out Node_Id)
3780 Barf_Id : Entity_Id;
3781 Body_Id : Entity_Id;
3784 -- Assume that the bodies are not available
3789 -- When the entry [family] has already been expanded, it carries both
3790 -- the procedure which emulates the behavior of the entry [family] as
3791 -- well as the barrier function.
3793 if Present (Protected_Body_Subprogram (Target_Id)) then
3794 Spec_Id := Protected_Body_Subprogram (Target_Id);
3796 -- Extract the attributes of the barrier function
3800 (Unit_Declaration_Node (Barrier_Function (Target_Id)));
3802 if Present (Barf_Id) then
3803 Body_Barf := Unit_Declaration_Node (Barf_Id);
3806 -- Otherwise no expansion took place
3809 Spec_Id := Target_Id;
3812 -- Extract the attributes of the entry body
3814 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3816 if Present (Body_Id) then
3817 Body_Decl := Unit_Declaration_Node (Body_Id);
3819 end Extract_Protected_Entry_Attributes;
3821 ---------------------------------------------
3822 -- Extract_Protected_Subprogram_Attributes --
3823 ---------------------------------------------
3825 procedure Extract_Protected_Subprogram_Attributes
3826 (Spec_Id : out Entity_Id;
3827 Body_Decl : out Node_Id)
3829 Body_Id : Entity_Id;
3832 -- Assume that the body is not available
3836 -- When the protected subprogram has already been expanded, it
3837 -- carries the subprogram which seizes the lock and invokes the
3838 -- original statements.
3840 if Present (Protected_Subprogram (Target_Id)) then
3842 Protected_Body_Subprogram (Protected_Subprogram (Target_Id));
3844 -- Otherwise no expansion took place
3847 Spec_Id := Target_Id;
3850 -- Extract the attributes of the body
3852 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3854 if Present (Body_Id) then
3855 Body_Decl := Unit_Declaration_Node (Body_Id);
3857 end Extract_Protected_Subprogram_Attributes;
3859 -----------------------------------
3860 -- Extract_Task_Entry_Attributes --
3861 -----------------------------------
3863 procedure Extract_Task_Entry_Attributes
3864 (Spec_Id : out Entity_Id;
3865 Body_Decl : out Node_Id)
3867 Task_Typ : constant Entity_Id := Non_Private_View (Scope (Target_Id));
3868 Body_Id : Entity_Id;
3871 -- Assume that the body is not available
3875 -- The the task type has already been expanded, it carries the
3876 -- procedure which emulates the behavior of the task body.
3878 if Present (Task_Body_Procedure (Task_Typ)) then
3879 Spec_Id := Task_Body_Procedure (Task_Typ);
3881 -- Otherwise no expansion took place
3884 Spec_Id := Task_Typ;
3887 -- Extract the attributes of the body
3889 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3891 if Present (Body_Id) then
3892 Body_Decl := Unit_Declaration_Node (Body_Id);
3894 end Extract_Task_Entry_Attributes;
3898 Prag : constant Node_Id := SPARK_Pragma (Target_Id);
3899 Body_Barf : Node_Id;
3900 Body_Decl : Node_Id;
3901 Spec_Id : Entity_Id;
3903 -- Start of processing for Extract_Target_Attributes
3906 -- Assume that the body of the barrier function is not available
3910 -- The target is a protected entry [family]
3912 if Is_Protected_Entry (Target_Id) then
3913 Extract_Protected_Entry_Attributes
3914 (Spec_Id => Spec_Id,
3915 Body_Decl => Body_Decl,
3916 Body_Barf => Body_Barf);
3918 -- The target is a protected subprogram
3920 elsif Is_Protected_Subp (Target_Id)
3921 or else Is_Protected_Body_Subp (Target_Id)
3923 Extract_Protected_Subprogram_Attributes
3924 (Spec_Id => Spec_Id,
3925 Body_Decl => Body_Decl);
3927 -- The target is a task entry [family]
3929 elsif Is_Task_Entry (Target_Id) then
3930 Extract_Task_Entry_Attributes
3931 (Spec_Id => Spec_Id,
3932 Body_Decl => Body_Decl);
3934 -- Otherwise the target is a package or a subprogram
3937 Extract_Package_Or_Subprogram_Attributes
3938 (Spec_Id => Spec_Id,
3939 Body_Decl => Body_Decl);
3942 -- Set all attributes
3944 Attrs.Body_Barf := Body_Barf;
3945 Attrs.Body_Decl := Body_Decl;
3946 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Target_Id);
3947 Attrs.From_Source := Comes_From_Source (Target_Id);
3948 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Entity (Target_Id);
3949 Attrs.SPARK_Mode_On :=
3950 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = On;
3951 Attrs.Spec_Decl := Unit_Declaration_Node (Spec_Id);
3952 Attrs.Spec_Id := Spec_Id;
3953 Attrs.Unit_Id := Find_Top_Unit (Target_Id);
3955 -- At this point certain attributes should always be available
3957 pragma Assert (Present (Attrs.Spec_Decl));
3958 pragma Assert (Present (Attrs.Spec_Id));
3959 pragma Assert (Present (Attrs.Unit_Id));
3960 end Extract_Target_Attributes;
3962 -----------------------------
3963 -- Extract_Task_Attributes --
3964 -----------------------------
3966 procedure Extract_Task_Attributes
3968 Attrs : out Task_Attributes)
3970 Task_Typ : constant Entity_Id := Non_Private_View (Typ);
3972 Body_Decl : Node_Id;
3973 Body_Id : Entity_Id;
3975 Spec_Id : Entity_Id;
3978 -- Assume that the body of the task procedure is not available
3982 -- The initial declaration is that of the task body procedure
3984 Spec_Id := Get_Task_Body_Procedure (Task_Typ);
3985 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3987 if Present (Body_Id) then
3988 Body_Decl := Unit_Declaration_Node (Body_Id);
3991 Prag := SPARK_Pragma (Task_Typ);
3993 -- Set all attributes
3995 Attrs.Body_Decl := Body_Decl;
3996 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Task_Typ);
3997 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Entity (Task_Typ);
3998 Attrs.SPARK_Mode_On :=
3999 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = On;
4000 Attrs.Spec_Id := Spec_Id;
4001 Attrs.Task_Decl := Declaration_Node (Task_Typ);
4002 Attrs.Unit_Id := Find_Top_Unit (Task_Typ);
4004 -- At this point certain attributes should always be available
4006 pragma Assert (Present (Attrs.Spec_Id));
4007 pragma Assert (Present (Attrs.Task_Decl));
4008 pragma Assert (Present (Attrs.Unit_Id));
4009 end Extract_Task_Attributes;
4011 -------------------------------------------
4012 -- Extract_Variable_Reference_Attributes --
4013 -------------------------------------------
4015 procedure Extract_Variable_Reference_Attributes
4017 Var_Id : out Entity_Id;
4018 Attrs : out Variable_Attributes)
4020 function Get_Renamed_Variable (Id : Entity_Id) return Entity_Id;
4021 -- Obtain the ultimate renamed variable of variable Id
4023 --------------------------
4024 -- Get_Renamed_Variable --
4025 --------------------------
4027 function Get_Renamed_Variable (Id : Entity_Id) return Entity_Id is
4032 while Present (Renamed_Entity (Ren_Id))
4033 and then Nkind (Renamed_Entity (Ren_Id)) in N_Entity
4035 Ren_Id := Renamed_Entity (Ren_Id);
4039 end Get_Renamed_Variable;
4041 -- Start of processing for Extract_Variable_Reference_Attributes
4044 -- Extraction for variable reference markers
4046 if Nkind (Ref) = N_Variable_Reference_Marker then
4047 Var_Id := Target (Ref);
4049 -- Extraction for expanded names and identifiers
4052 Var_Id := Entity (Ref);
4055 -- Obtain the original variable which the reference mentions
4057 Var_Id := Get_Renamed_Variable (Var_Id);
4058 Attrs.Unit_Id := Find_Top_Unit (Var_Id);
4060 -- At this point certain attributes should always be available
4062 pragma Assert (Present (Attrs.Unit_Id));
4063 end Extract_Variable_Reference_Attributes;
4065 --------------------
4066 -- Find_Code_Unit --
4067 --------------------
4069 function Find_Code_Unit (N : Node_Or_Entity_Id) return Entity_Id is
4071 return Find_Unit_Entity (Unit (Cunit (Get_Code_Unit (N))));
4074 ----------------------------
4075 -- Find_Early_Call_Region --
4076 ----------------------------
4078 function Find_Early_Call_Region
4079 (Body_Decl : Node_Id;
4080 Assume_Elab_Body : Boolean := False;
4081 Skip_Memoization : Boolean := False) return Node_Id
4083 -- NOTE: The routines within Find_Early_Call_Region are intentionally
4084 -- unnested to avoid deep indentation of code.
4086 ECR_Found : exception;
4087 -- This exception is raised when the early call region has been found
4089 Start : Node_Id := Empty;
4090 -- The start of the early call region. This variable is updated by the
4091 -- various nested routines. Due to the use of exceptions, the variable
4092 -- must be global to the nested routines.
4094 -- The algorithm implemented in this routine attempts to find the early
4095 -- call region of a subprogram body by inspecting constructs in reverse
4096 -- declarative order, while navigating the tree. The algorithm consists
4097 -- of an Inspection phase and an Advancement phase. The pseudocode is as
4102 -- advancement phase
4105 -- The infinite loop is terminated by raising exception ECR_Found. The
4106 -- algorithm utilizes two pointers, Curr and Start, to represent the
4107 -- current construct to inspect and the start of the early call region.
4109 -- IMPORTANT: The algorithm must maintain the following invariant at all
4110 -- time for it to function properly - a nested construct is entered only
4111 -- when it contains suitable constructs. This guarantees that leaving a
4112 -- nested or encapsulating construct functions properly.
4114 -- The Inspection phase determines whether the current construct is non-
4115 -- preelaborable, and if it is, the algorithm terminates.
4117 -- The Advancement phase walks the tree in reverse declarative order,
4118 -- while entering and leaving nested and encapsulating constructs. It
4119 -- may also terminate the elaborithm. There are several special cases
4126 -- <construct N-1> <- Curr
4127 -- <construct N> <- Start
4128 -- <subprogram body>
4130 -- In the general case, a declarative or statement list is traversed in
4131 -- reverse order where Curr is the lead pointer, and Start indicates the
4132 -- last preelaborable construct.
4134 -- 2) Entering handled bodies
4136 -- package body Nested is <- Curr (2.3)
4137 -- <declarations> <- Curr (2.2)
4139 -- <statements> <- Curr (2.1)
4141 -- <construct> <- Start
4143 -- In this case, the algorithm enters a handled body by starting from
4144 -- the last statement (2.1), or the last declaration (2.2), or the body
4145 -- is consumed (2.3) because it is empty and thus preelaborable.
4147 -- 3) Entering package declarations
4149 -- package Nested is <- Curr (2.3)
4150 -- <visible declarations> <- Curr (2.2)
4152 -- <private declarations> <- Curr (2.1)
4154 -- <construct> <- Start
4156 -- In this case, the algorithm enters a package declaration by starting
4157 -- from the last private declaration (2.1), the last visible declaration
4158 -- (2.2), or the package is consumed (2.3) because it is empty and thus
4161 -- 4) Transitioning from list to list of the same construct
4163 -- Certain constructs have two eligible lists. The algorithm must thus
4164 -- transition from the second to the first list when the second list is
4167 -- declare <- Curr (4.2)
4168 -- <declarations> <- Curr (4.1)
4170 -- <statements> <- Start
4173 -- In this case, the algorithm has exhausted the second list (statements
4174 -- in the example), and continues with the last declaration (4.1) or the
4175 -- construct is consumed (4.2) because it contains only preelaborable
4178 -- 5) Transitioning from list to construct
4180 -- tack body Task is <- Curr (5.1)
4182 -- <construct 1> <- Start
4184 -- In this case, the algorithm has exhausted a list, Curr is Empty, and
4185 -- the owner of the list is consumed (5.1).
4187 -- 6) Transitioning from unit to unit
4189 -- A package body with a spec subject to pragma Elaborate_Body extends
4190 -- the possible range of the early call region to the package spec.
4192 -- package Pack is <- Curr (6.3)
4193 -- pragma Elaborate_Body; <- Curr (6.2)
4194 -- <visible declarations> <- Curr (6.2)
4196 -- <private declarations> <- Curr (6.1)
4199 -- package body Pack is <- Curr, Start
4201 -- In this case, the algorithm has reached a package body compilation
4202 -- unit whose spec is subject to pragma Elaborate_Body, or the caller
4203 -- of the algorithm has specified this behavior. This transition is
4204 -- equivalent to 3).
4206 -- 7) Transitioning from unit to termination
4208 -- Reaching a compilation unit always terminates the algorithm as there
4209 -- are no more lists to examine. This must take 6) into account.
4211 -- 8) Transitioning from subunit to stub
4213 -- package body Pack is separate; <- Curr (8.1)
4216 -- package body Pack is <- Curr, Start
4218 -- Reaching a subunit continues the search from the corresponding stub
4221 procedure Advance (Curr : in out Node_Id);
4222 pragma Inline (Advance);
4223 -- Update the Curr and Start pointers depending on their location in the
4224 -- tree to the next eligible construct. This routine raises ECR_Found.
4226 procedure Enter_Handled_Body (Curr : in out Node_Id);
4227 pragma Inline (Enter_Handled_Body);
4228 -- Update the Curr and Start pointers to enter a nested handled body if
4229 -- applicable. This routine raises ECR_Found.
4231 procedure Enter_Package_Declaration (Curr : in out Node_Id);
4232 pragma Inline (Enter_Package_Declaration);
4233 -- Update the Curr and Start pointers to enter a nested package spec if
4234 -- applicable. This routine raises ECR_Found.
4236 function Find_ECR (N : Node_Id) return Node_Id;
4237 pragma Inline (Find_ECR);
4238 -- Find an early call region starting from arbitrary node N
4240 function Has_Suitable_Construct (List : List_Id) return Boolean;
4241 pragma Inline (Has_Suitable_Construct);
4242 -- Determine whether list List contains at least one suitable construct
4243 -- for inclusion into an early call region.
4245 procedure Include (N : Node_Id; Curr : in out Node_Id);
4246 pragma Inline (Include);
4247 -- Update the Curr and Start pointers to include arbitrary construct N
4248 -- in the early call region.
4250 function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean;
4251 pragma Inline (Is_OK_Preelaborable_Construct);
4252 -- Determine whether arbitrary node N denotes a preelaboration-safe
4255 function Is_Suitable_Construct (N : Node_Id) return Boolean;
4256 pragma Inline (Is_Suitable_Construct);
4257 -- Determine whether arbitrary node N denotes a suitable construct for
4258 -- inclusion into the early call region.
4260 procedure Transition_Body_Declarations
4262 Curr : in out Node_Id);
4263 pragma Inline (Transition_Body_Declarations);
4264 -- Update the Curr and Start pointers when construct Bod denotes a block
4265 -- statement or a suitable body. This routine raises ECR_Found.
4267 procedure Transition_Handled_Statements
4269 Curr : in out Node_Id);
4270 pragma Inline (Transition_Handled_Statements);
4271 -- Update the Curr and Start pointers when node HSS denotes a handled
4272 -- sequence of statements. This routine raises ECR_Found.
4274 procedure Transition_Spec_Declarations
4276 Curr : in out Node_Id);
4277 pragma Inline (Transition_Spec_Declarations);
4278 -- Update the Curr and Start pointers when construct Spec denotes
4279 -- a concurrent definition or a package spec. This routine raises
4282 procedure Transition_Unit (Unit : Node_Id; Curr : in out Node_Id);
4283 pragma Inline (Transition_Unit);
4284 -- Update the Curr and Start pointers when node Unit denotes a potential
4285 -- compilation unit. This routine raises ECR_Found.
4291 procedure Advance (Curr : in out Node_Id) is
4295 -- Curr denotes one of the following cases upon entry into this
4298 -- * Empty - There is no current construct when a declarative or a
4299 -- statement list has been exhausted. This does not necessarily
4300 -- indicate that the early call region has been computed as it
4301 -- may still be possible to transition to another list.
4303 -- * Encapsulator - The current construct encapsulates declarations
4304 -- and/or statements. This indicates that the early call region
4305 -- may extend within the nested construct.
4307 -- * Preelaborable - The current construct is always preelaborable
4308 -- because Find_ECR would not invoke Advance if this was not the
4311 -- The current construct is an encapsulator or is preelaborable
4313 if Present (Curr) then
4315 -- Enter encapsulators by inspecting their declarations and/or
4318 if Nkind_In (Curr, N_Block_Statement, N_Package_Body) then
4319 Enter_Handled_Body (Curr);
4321 elsif Nkind (Curr) = N_Package_Declaration then
4322 Enter_Package_Declaration (Curr);
4324 -- Early call regions have a property which can be exploited to
4325 -- optimize the algorithm.
4327 -- <preceding subprogram body>
4328 -- <preelaborable construct 1>
4330 -- <preelaborable construct N>
4331 -- <initiating subprogram body>
4333 -- If a traversal initiated from a subprogram body reaches a
4334 -- preceding subprogram body, then both bodies share the same
4335 -- early call region.
4337 -- The property results in the following desirable effects:
4339 -- * If the preceding body already has an early call region, then
4340 -- the initiating body can reuse it. This minimizes the amount
4341 -- of processing performed by the algorithm.
4343 -- * If the preceding body lack an early call region, then the
4344 -- algorithm can compute the early call region, and reuse it
4345 -- for the initiating body. This processing performs the same
4346 -- amount of work, but has the beneficial effect of computing
4347 -- the early call regions of all preceding bodies.
4349 elsif Nkind_In (Curr, N_Entry_Body, N_Subprogram_Body) then
4351 Find_Early_Call_Region
4353 Assume_Elab_Body => Assume_Elab_Body,
4354 Skip_Memoization => Skip_Memoization);
4358 -- Otherwise current construct is preelaborable. Unpdate the early
4359 -- call region to include it.
4362 Include (Curr, Curr);
4365 -- Otherwise the current construct is missing, indicating that the
4366 -- current list has been exhausted. Depending on the context of the
4367 -- list, several transitions are possible.
4370 -- The invariant of the algorithm ensures that Curr and Start are
4371 -- at the same level of nesting at the point of a transition. The
4372 -- algorithm can determine which list the traversal came from by
4375 Context := Parent (Start);
4377 -- Attempt the following transitions:
4379 -- private declarations -> visible declarations
4380 -- private declarations -> upper level
4381 -- private declarations -> terminate
4382 -- visible declarations -> upper level
4383 -- visible declarations -> terminate
4385 if Nkind_In (Context, N_Package_Specification,
4386 N_Protected_Definition,
4389 Transition_Spec_Declarations (Context, Curr);
4391 -- Attempt the following transitions:
4393 -- statements -> declarations
4394 -- statements -> upper level
4395 -- statements -> corresponding package spec (Elab_Body)
4396 -- statements -> terminate
4398 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
4399 Transition_Handled_Statements (Context, Curr);
4401 -- Attempt the following transitions:
4403 -- declarations -> upper level
4404 -- declarations -> corresponding package spec (Elab_Body)
4405 -- declarations -> terminate
4407 elsif Nkind_In (Context, N_Block_Statement,
4414 Transition_Body_Declarations (Context, Curr);
4416 -- Otherwise it is not possible to transition. Stop the search
4417 -- because there are no more declarations or statements to check.
4425 --------------------------
4426 -- Enter_Handled_Body --
4427 --------------------------
4429 procedure Enter_Handled_Body (Curr : in out Node_Id) is
4430 Decls : constant List_Id := Declarations (Curr);
4431 HSS : constant Node_Id := Handled_Statement_Sequence (Curr);
4432 Stmts : List_Id := No_List;
4435 if Present (HSS) then
4436 Stmts := Statements (HSS);
4439 -- The handled body has a non-empty statement sequence. The construct
4440 -- to inspect is the last statement.
4442 if Has_Suitable_Construct (Stmts) then
4443 Curr := Last (Stmts);
4445 -- The handled body lacks statements, but has non-empty declarations.
4446 -- The construct to inspect is the last declaration.
4448 elsif Has_Suitable_Construct (Decls) then
4449 Curr := Last (Decls);
4451 -- Otherwise the handled body lacks both declarations and statements.
4452 -- The construct to inspect is the node which precedes the handled
4453 -- body. Update the early call region to include the handled body.
4456 Include (Curr, Curr);
4458 end Enter_Handled_Body;
4460 -------------------------------
4461 -- Enter_Package_Declaration --
4462 -------------------------------
4464 procedure Enter_Package_Declaration (Curr : in out Node_Id) is
4465 Pack_Spec : constant Node_Id := Specification (Curr);
4466 Prv_Decls : constant List_Id := Private_Declarations (Pack_Spec);
4467 Vis_Decls : constant List_Id := Visible_Declarations (Pack_Spec);
4470 -- The package has a non-empty private declarations. The construct to
4471 -- inspect is the last private declaration.
4473 if Has_Suitable_Construct (Prv_Decls) then
4474 Curr := Last (Prv_Decls);
4476 -- The package lacks private declarations, but has non-empty visible
4477 -- declarations. In this case the construct to inspect is the last
4478 -- visible declaration.
4480 elsif Has_Suitable_Construct (Vis_Decls) then
4481 Curr := Last (Vis_Decls);
4483 -- Otherwise the package lacks any declarations. The construct to
4484 -- inspect is the node which precedes the package. Update the early
4485 -- call region to include the package declaration.
4488 Include (Curr, Curr);
4490 end Enter_Package_Declaration;
4496 function Find_ECR (N : Node_Id) return Node_Id is
4500 -- The early call region starts at N
4505 -- Inspect each node in reverse declarative order while going in and
4506 -- out of nested and enclosing constructs. Note that the only way to
4507 -- terminate this infinite loop is to raise exception ECR_Found.
4510 -- The current construct is not preelaboration-safe. Terminate the
4514 and then not Is_OK_Preelaborable_Construct (Curr)
4519 -- Advance to the next suitable construct. This may terminate the
4520 -- traversal by raising ECR_Found.
4530 ----------------------------
4531 -- Has_Suitable_Construct --
4532 ----------------------------
4534 function Has_Suitable_Construct (List : List_Id) return Boolean is
4538 -- Examine the list in reverse declarative order, looking for a
4539 -- suitable construct.
4541 if Present (List) then
4542 Item := Last (List);
4543 while Present (Item) loop
4544 if Is_Suitable_Construct (Item) then
4553 end Has_Suitable_Construct;
4559 procedure Include (N : Node_Id; Curr : in out Node_Id) is
4562 Curr := Prev (Start);
4565 -----------------------------------
4566 -- Is_OK_Preelaborable_Construct --
4567 -----------------------------------
4569 function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean is
4571 -- Assignment statements are acceptable as long as they were produced
4572 -- by the ABE mechanism to update elaboration flags.
4574 if Nkind (N) = N_Assignment_Statement then
4575 return Is_Elaboration_Code (N);
4577 -- Block statements are acceptable even though they directly violate
4578 -- preelaborability. The intention is not to penalize the early call
4579 -- region when a block contains only preelaborable constructs.
4582 -- Val : constant Integer := 1;
4584 -- pragma Assert (Val = 1);
4588 -- Note that the Advancement phase does enter blocks, and will detect
4589 -- any non-preelaborable declarations or statements within.
4591 elsif Nkind (N) = N_Block_Statement then
4595 -- Otherwise the construct must be preelaborable. The check must take
4596 -- the syntactic and semantic structure of the construct. DO NOT use
4597 -- Is_Preelaborable_Construct here.
4599 return not Is_Non_Preelaborable_Construct (N);
4600 end Is_OK_Preelaborable_Construct;
4602 ---------------------------
4603 -- Is_Suitable_Construct --
4604 ---------------------------
4606 function Is_Suitable_Construct (N : Node_Id) return Boolean is
4607 Context : constant Node_Id := Parent (N);
4610 -- An internally-generated statement sequence which contains only a
4611 -- single null statement is not a suitable construct because it is a
4612 -- byproduct of the parser. Such a null statement should be excluded
4613 -- from the early call region because it carries the source location
4614 -- of the "end" keyword, and may lead to confusing diagnistics.
4616 if Nkind (N) = N_Null_Statement
4617 and then not Comes_From_Source (N)
4618 and then Present (Context)
4619 and then Nkind (Context) = N_Handled_Sequence_Of_Statements
4620 and then not Comes_From_Source (N)
4625 -- Otherwise only constructs which correspond to pure Ada constructs
4626 -- are considered suitable.
4631 | N_Freeze_Generic_Entity
4632 | N_Implicit_Label_Declaration
4634 | N_Pop_Constraint_Error_Label
4635 | N_Pop_Program_Error_Label
4636 | N_Pop_Storage_Error_Label
4637 | N_Push_Constraint_Error_Label
4638 | N_Push_Program_Error_Label
4639 | N_Push_Storage_Error_Label
4640 | N_SCIL_Dispatch_Table_Tag_Init
4641 | N_SCIL_Dispatching_Call
4642 | N_SCIL_Membership_Test
4643 | N_Variable_Reference_Marker
4650 end Is_Suitable_Construct;
4652 ----------------------------------
4653 -- Transition_Body_Declarations --
4654 ----------------------------------
4656 procedure Transition_Body_Declarations
4658 Curr : in out Node_Id)
4660 Decls : constant List_Id := Declarations (Bod);
4663 -- The search must come from the declarations of the body
4666 (Is_Non_Empty_List (Decls)
4667 and then List_Containing (Start) = Decls);
4669 -- The search finished inspecting the declarations. The construct
4670 -- to inspect is the node which precedes the handled body, unless
4671 -- the body is a compilation unit. The transitions are:
4673 -- declarations -> upper level
4674 -- declarations -> corresponding package spec (Elab_Body)
4675 -- declarations -> terminate
4677 Transition_Unit (Bod, Curr);
4678 end Transition_Body_Declarations;
4680 -----------------------------------
4681 -- Transition_Handled_Statements --
4682 -----------------------------------
4684 procedure Transition_Handled_Statements
4686 Curr : in out Node_Id)
4688 Bod : constant Node_Id := Parent (HSS);
4689 Decls : constant List_Id := Declarations (Bod);
4690 Stmts : constant List_Id := Statements (HSS);
4693 -- The search must come from the statements of certain bodies or
4696 pragma Assert (Nkind_In (Bod, N_Block_Statement,
4703 -- The search must come from the statements of the handled sequence
4706 (Is_Non_Empty_List (Stmts)
4707 and then List_Containing (Start) = Stmts);
4709 -- The search finished inspecting the statements. The handled body
4710 -- has non-empty declarations. The construct to inspect is the last
4711 -- declaration. The transitions are:
4713 -- statements -> declarations
4715 if Has_Suitable_Construct (Decls) then
4716 Curr := Last (Decls);
4718 -- Otherwise the handled body lacks declarations. The construct to
4719 -- inspect is the node which precedes the handled body, unless the
4720 -- body is a compilation unit. The transitions are:
4722 -- statements -> upper level
4723 -- statements -> corresponding package spec (Elab_Body)
4724 -- statements -> terminate
4727 Transition_Unit (Bod, Curr);
4729 end Transition_Handled_Statements;
4731 ----------------------------------
4732 -- Transition_Spec_Declarations --
4733 ----------------------------------
4735 procedure Transition_Spec_Declarations
4737 Curr : in out Node_Id)
4739 Prv_Decls : constant List_Id := Private_Declarations (Spec);
4740 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
4743 pragma Assert (Present (Start) and then Is_List_Member (Start));
4745 -- The search came from the private declarations and finished their
4748 if Has_Suitable_Construct (Prv_Decls)
4749 and then List_Containing (Start) = Prv_Decls
4751 -- The context has non-empty visible declarations. The node to
4752 -- inspect is the last visible declaration. The transitions are:
4754 -- private declarations -> visible declarations
4756 if Has_Suitable_Construct (Vis_Decls) then
4757 Curr := Last (Vis_Decls);
4759 -- Otherwise the context lacks visible declarations. The construct
4760 -- to inspect is the node which precedes the context unless the
4761 -- context is a compilation unit. The transitions are:
4763 -- private declarations -> upper level
4764 -- private declarations -> terminate
4767 Transition_Unit (Parent (Spec), Curr);
4770 -- The search came from the visible declarations and finished their
4771 -- inspections. The construct to inspect is the node which precedes
4772 -- the context, unless the context is a compilaton unit. The
4775 -- visible declarations -> upper level
4776 -- visible declarations -> terminate
4778 elsif Has_Suitable_Construct (Vis_Decls)
4779 and then List_Containing (Start) = Vis_Decls
4781 Transition_Unit (Parent (Spec), Curr);
4783 -- At this point both declarative lists are empty, but the traversal
4784 -- still came from within the spec. This indicates that the invariant
4785 -- of the algorithm has been violated.
4788 pragma Assert (False);
4791 end Transition_Spec_Declarations;
4793 ---------------------
4794 -- Transition_Unit --
4795 ---------------------
4797 procedure Transition_Unit
4799 Curr : in out Node_Id)
4801 Context : constant Node_Id := Parent (Unit);
4804 -- The unit is a compilation unit. This terminates the search because
4805 -- there are no more lists to inspect and there are no more enclosing
4806 -- constructs to climb up to.
4808 if Nkind (Context) = N_Compilation_Unit then
4810 -- A package body with a corresponding spec subject to pragma
4811 -- Elaborate_Body is an exception to the above. The annotation
4812 -- allows the search to continue into the package declaration.
4813 -- The transitions are:
4815 -- statements -> corresponding package spec (Elab_Body)
4816 -- declarations -> corresponding package spec (Elab_Body)
4818 if Nkind (Unit) = N_Package_Body
4819 and then (Assume_Elab_Body
4820 or else Has_Pragma_Elaborate_Body
4821 (Corresponding_Spec (Unit)))
4823 Curr := Unit_Declaration_Node (Corresponding_Spec (Unit));
4824 Enter_Package_Declaration (Curr);
4826 -- Otherwise terminate the search. The transitions are:
4828 -- private declarations -> terminate
4829 -- visible declarations -> terminate
4830 -- statements -> terminate
4831 -- declarations -> terminate
4837 -- The unit is a subunit. The construct to inspect is the node which
4838 -- precedes the corresponding stub. Update the early call region to
4839 -- include the unit.
4841 elsif Nkind (Context) = N_Subunit then
4843 Curr := Corresponding_Stub (Context);
4845 -- Otherwise the unit is nested. The construct to inspect is the node
4846 -- which precedes the unit. Update the early call region to include
4850 Include (Unit, Curr);
4852 end Transition_Unit;
4856 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
4859 -- Start of processing for Find_Early_Call_Region
4862 -- The caller demands the start of the early call region without saving
4863 -- or retrieving it to/from internal data structures.
4865 if Skip_Memoization then
4866 Region := Find_ECR (Body_Decl);
4871 -- Check whether the early call region of the subprogram body is
4874 Region := Early_Call_Region (Body_Id);
4878 -- Traverse the declarations in reverse order, starting from the
4879 -- subprogram body, searching for the nearest non-preelaborable
4880 -- construct. The early call region starts after this construct
4881 -- and ends at the subprogram body.
4883 Region := Find_ECR (Body_Decl);
4885 -- Associate the early call region with the subprogram body in
4886 -- case other scenarios need it.
4888 Set_Early_Call_Region (Body_Id, Region);
4892 -- A subprogram body must always have an early call region
4894 pragma Assert (Present (Region));
4897 end Find_Early_Call_Region;
4899 ---------------------------
4900 -- Find_Elaborated_Units --
4901 ---------------------------
4903 procedure Find_Elaborated_Units is
4904 procedure Add_Pragma (Prag : Node_Id);
4905 -- Determine whether pragma Prag denotes a legal Elaborate[_All] pragma.
4906 -- If this is the case, add the related unit to the elaboration context.
4907 -- For pragma Elaborate_All, include recursively all units withed by the
4911 (Unit_Id : Entity_Id;
4913 Full_Context : Boolean);
4914 -- Add unit Unit_Id to the elaboration context. Prag denotes the pragma
4915 -- which prompted the inclusion of the unit to the elaboration context.
4916 -- If flag Full_Context is set, examine the nonlimited clauses of unit
4917 -- Unit_Id and add each withed unit to the context.
4919 procedure Find_Elaboration_Context (Comp_Unit : Node_Id);
4920 -- Examine the context items of compilation unit Comp_Unit for suitable
4921 -- elaboration-related pragmas and add all related units to the context.
4927 procedure Add_Pragma (Prag : Node_Id) is
4928 Prag_Args : constant List_Id := Pragma_Argument_Associations (Prag);
4929 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
4933 -- Nothing to do if the pragma is not related to elaboration
4935 if not Nam_In (Prag_Nam, Name_Elaborate, Name_Elaborate_All) then
4938 -- Nothing to do when the pragma is illegal
4940 elsif Error_Posted (Prag) then
4944 Unit_Arg := Get_Pragma_Arg (First (Prag_Args));
4946 -- The argument of the pragma may appear in package.package form
4948 if Nkind (Unit_Arg) = N_Selected_Component then
4949 Unit_Arg := Selector_Name (Unit_Arg);
4953 (Unit_Id => Entity (Unit_Arg),
4955 Full_Context => Prag_Nam = Name_Elaborate_All);
4963 (Unit_Id : Entity_Id;
4965 Full_Context : Boolean)
4968 Elab_Attrs : Elaboration_Attributes;
4971 -- Nothing to do when some previous error left a with clause or a
4972 -- pragma in a bad state.
4974 if No (Unit_Id) then
4978 Elab_Attrs := Elaboration_Status (Unit_Id);
4980 -- The unit is already included in the context by means of pragma
4983 if Present (Elab_Attrs.Source_Pragma) then
4985 -- Upgrade an existing pragma Elaborate when the unit is subject
4986 -- to Elaborate_All because the new pragma covers a larger set of
4989 if Pragma_Name (Elab_Attrs.Source_Pragma) = Name_Elaborate
4990 and then Pragma_Name (Prag) = Name_Elaborate_All
4992 Elab_Attrs.Source_Pragma := Prag;
4994 -- Otherwise the unit retains its existing pragma and does not
4995 -- need to be included in the context again.
5001 -- The current unit is not part of the context. Prepare a new set of
5006 Elaboration_Attributes'(Source_Pragma => Prag,
5007 With_Clause => Empty);
5010 -- Add or update the attributes of the unit
5012 Set_Elaboration_Status (Unit_Id, Elab_Attrs);
5014 -- Includes all units withed by the current one when computing the
5017 if Full_Context then
5019 -- Process all nonlimited with clauses found in the context of
5020 -- the current unit. Note that limited clauses do not impose an
5021 -- elaboration order.
5023 Clause := First (Context_Items (Compilation_Unit (Unit_Id)));
5024 while Present (Clause) loop
5025 if Nkind (Clause) = N_With_Clause
5026 and then not Error_Posted (Clause)
5027 and then not Limited_Present (Clause)
5030 (Unit_Id => Entity (Name (Clause)),
5032 Full_Context => Full_Context);
5040 ------------------------------
5041 -- Find_Elaboration_Context --
5042 ------------------------------
5044 procedure Find_Elaboration_Context (Comp_Unit : Node_Id) is
5048 pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit);
5050 -- Process all elaboration-related pragmas found in the context of
5051 -- the compilation unit.
5053 Prag := First (Context_Items (Comp_Unit));
5054 while Present (Prag) loop
5055 if Nkind (Prag) = N_Pragma then
5061 end Find_Elaboration_Context;
5068 -- Start of processing for Find_Elaborated_Units
5071 -- Perform a traversal which examines the context of the main unit and
5072 -- populates the Elaboration_Context table with all units elaborated
5073 -- prior to the main unit. The traversal performs the following jumps:
5075 -- subunit -> parent subunit
5076 -- parent subunit -> body
5078 -- spec -> parent spec
5079 -- parent spec -> grandparent spec and so on
5081 -- The traversal relies on units rather than scopes because the scope of
5082 -- a subunit is some spec, while this traversal must process the body as
5083 -- well. Given that protected and task bodies can also be subunits, this
5084 -- complicates the scope approach even further.
5086 Unt := Unit (Cunit (Main_Unit));
5088 -- Perform the following traversals when the main unit is a subunit
5090 -- subunit -> parent subunit
5091 -- parent subunit -> body
5093 while Present (Unt) and then Nkind (Unt) = N_Subunit loop
5094 Find_Elaboration_Context (Parent (Unt));
5096 -- Continue the traversal by going to the unit which contains the
5097 -- corresponding stub.
5099 if Present (Corresponding_Stub (Unt)) then
5100 Unt := Unit (Cunit (Get_Source_Unit (Corresponding_Stub (Unt))));
5102 -- Otherwise the subunit may be erroneous or left in a bad state
5109 -- Perform the following traversal now that subunits have been taken
5110 -- care of, or the main unit is a body.
5115 and then Nkind_In (Unt, N_Package_Body, N_Subprogram_Body)
5117 Find_Elaboration_Context (Parent (Unt));
5119 -- Continue the traversal by going to the unit which contains the
5120 -- corresponding spec.
5122 if Present (Corresponding_Spec (Unt)) then
5123 Unt := Unit (Cunit (Get_Source_Unit (Corresponding_Spec (Unt))));
5127 -- Perform the following traversals now that the body has been taken
5128 -- care of, or the main unit is a spec.
5130 -- spec -> parent spec
5131 -- parent spec -> grandparent spec and so on
5134 and then Nkind_In (Unt, N_Generic_Package_Declaration,
5135 N_Generic_Subprogram_Declaration,
5136 N_Package_Declaration,
5137 N_Subprogram_Declaration)
5139 Find_Elaboration_Context (Parent (Unt));
5141 -- Process a potential chain of parent units which ends with the
5142 -- main unit spec. The traversal can now safely rely on the scope
5145 Par_Id := Scope (Defining_Entity (Unt));
5146 while Present (Par_Id) and then Par_Id /= Standard_Standard loop
5147 Find_Elaboration_Context (Compilation_Unit (Par_Id));
5149 Par_Id := Scope (Par_Id);
5152 end Find_Elaborated_Units;
5154 -----------------------------
5155 -- Find_Enclosing_Instance --
5156 -----------------------------
5158 function Find_Enclosing_Instance (N : Node_Id) return Node_Id is
5160 Spec_Id : Entity_Id;
5163 -- Climb the parent chain looking for an enclosing instance spec or body
5166 while Present (Par) loop
5168 -- Generic package or subprogram spec
5170 if Nkind_In (Par, N_Package_Declaration,
5171 N_Subprogram_Declaration)
5172 and then Is_Generic_Instance (Defining_Entity (Par))
5176 -- Generic package or subprogram body
5178 elsif Nkind_In (Par, N_Package_Body, N_Subprogram_Body) then
5179 Spec_Id := Corresponding_Spec (Par);
5181 if Present (Spec_Id) and then Is_Generic_Instance (Spec_Id) then
5186 Par := Parent (Par);
5190 end Find_Enclosing_Instance;
5192 --------------------------
5193 -- Find_Enclosing_Level --
5194 --------------------------
5196 function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind is
5197 function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind;
5198 -- Obtain the corresponding level of unit Unit
5204 function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind is
5205 Spec_Id : Entity_Id;
5208 if Nkind (Unit) in N_Generic_Instantiation then
5209 return Instantiation;
5211 elsif Nkind (Unit) = N_Generic_Package_Declaration then
5212 return Generic_Package_Spec;
5214 elsif Nkind (Unit) = N_Package_Declaration then
5215 return Package_Spec;
5217 elsif Nkind (Unit) = N_Package_Body then
5218 Spec_Id := Corresponding_Spec (Unit);
5220 -- The body belongs to a generic package
5222 if Present (Spec_Id)
5223 and then Ekind (Spec_Id) = E_Generic_Package
5225 return Generic_Package_Body;
5227 -- Otherwise the body belongs to a non-generic package. This also
5228 -- treats an illegal package body without a corresponding spec as
5229 -- a non-generic package body.
5232 return Package_Body;
5245 -- Start of processing for Find_Enclosing_Level
5248 -- Call markers and instantiations which appear at the declaration level
5249 -- but are later relocated in a different context retain their original
5250 -- declaration level.
5252 if Nkind_In (N, N_Call_Marker,
5253 N_Function_Instantiation,
5254 N_Package_Instantiation,
5255 N_Procedure_Instantiation)
5256 and then Is_Declaration_Level_Node (N)
5258 return Declaration_Level;
5261 -- Climb the parent chain looking at the enclosing levels
5264 Curr := Parent (Prev);
5265 while Present (Curr) loop
5267 -- A traversal from a subunit continues via the corresponding stub
5269 if Nkind (Curr) = N_Subunit then
5270 Curr := Corresponding_Stub (Curr);
5272 -- The current construct is a package. Packages are ignored because
5273 -- they are always elaborated when the enclosing context is invoked
5276 elsif Nkind_In (Curr, N_Package_Body, N_Package_Declaration) then
5279 -- The current construct is a block statement
5281 elsif Nkind (Curr) = N_Block_Statement then
5283 -- Ignore internally generated blocks created by the expander for
5284 -- various purposes such as abort defer/undefer.
5286 if not Comes_From_Source (Curr) then
5289 -- If the traversal came from the handled sequence of statments,
5290 -- then the node appears at the level of the enclosing construct.
5291 -- This is a more reliable test because transients scopes within
5292 -- the declarative region of the encapsulator are hard to detect.
5294 elsif Nkind (Prev) = N_Handled_Sequence_Of_Statements
5295 and then Handled_Statement_Sequence (Curr) = Prev
5297 return Find_Enclosing_Level (Parent (Curr));
5299 -- Otherwise the traversal came from the declarations, the node is
5300 -- at the declaration level.
5303 return Declaration_Level;
5306 -- The current construct is a declaration-level encapsulator
5308 elsif Nkind_In (Curr, N_Entry_Body,
5312 -- If the traversal came from the handled sequence of statments,
5313 -- then the node cannot possibly appear at any level. This is
5314 -- a more reliable test because transients scopes within the
5315 -- declarative region of the encapsulator are hard to detect.
5317 if Nkind (Prev) = N_Handled_Sequence_Of_Statements
5318 and then Handled_Statement_Sequence (Curr) = Prev
5322 -- Otherwise the traversal came from the declarations, the node is
5323 -- at the declaration level.
5326 return Declaration_Level;
5329 -- The current construct is a non-library-level encapsulator which
5330 -- indicates that the node cannot possibly appear at any level.
5331 -- Note that this check must come after the declaration-level check
5332 -- because both predicates share certain nodes.
5334 elsif Is_Non_Library_Level_Encapsulator (Curr) then
5335 Context := Parent (Curr);
5337 -- The sole exception is when the encapsulator is the compilation
5338 -- utit itself because the compilation unit node requires special
5339 -- processing (see below).
5341 if Present (Context)
5342 and then Nkind (Context) = N_Compilation_Unit
5346 -- Otherwise the node is not at any level
5352 -- The current construct is a compilation unit. The node appears at
5353 -- the [generic] library level when the unit is a [generic] package.
5355 elsif Nkind (Curr) = N_Compilation_Unit then
5356 return Level_Of (Unit (Curr));
5360 Curr := Parent (Prev);
5364 end Find_Enclosing_Level;
5370 function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id is
5372 return Find_Unit_Entity (Unit (Cunit (Get_Top_Level_Code_Unit (N))));
5375 ----------------------
5376 -- Find_Unit_Entity --
5377 ----------------------
5379 function Find_Unit_Entity (N : Node_Id) return Entity_Id is
5380 Context : constant Node_Id := Parent (N);
5381 Orig_N : constant Node_Id := Original_Node (N);
5384 -- The unit denotes a package body of an instantiation which acts as
5385 -- a compilation unit. The proper entity is that of the package spec.
5387 if Nkind (N) = N_Package_Body
5388 and then Nkind (Orig_N) = N_Package_Instantiation
5389 and then Nkind (Context) = N_Compilation_Unit
5391 return Corresponding_Spec (N);
5393 -- The unit denotes an anonymous package created to wrap a subprogram
5394 -- instantiation which acts as a compilation unit. The proper entity is
5395 -- that of the "related instance".
5397 elsif Nkind (N) = N_Package_Declaration
5398 and then Nkind_In (Orig_N, N_Function_Instantiation,
5399 N_Procedure_Instantiation)
5400 and then Nkind (Context) = N_Compilation_Unit
5403 Related_Instance (Defining_Entity (N, Concurrent_Subunit => True));
5405 -- Otherwise the proper entity is the defining entity
5408 return Defining_Entity (N, Concurrent_Subunit => True);
5410 end Find_Unit_Entity;
5412 -----------------------
5413 -- First_Formal_Type --
5414 -----------------------
5416 function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id is
5417 Formal_Id : constant Entity_Id := First_Formal (Subp_Id);
5421 if Present (Formal_Id) then
5422 Typ := Etype (Formal_Id);
5424 -- Handle various combinations of concurrent and private types
5427 if Ekind_In (Typ, E_Protected_Type, E_Task_Type)
5428 and then Present (Anonymous_Object (Typ))
5430 Typ := Anonymous_Object (Typ);
5432 elsif Is_Concurrent_Record_Type (Typ) then
5433 Typ := Corresponding_Concurrent_Type (Typ);
5435 elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
5436 Typ := Full_View (Typ);
5447 end First_Formal_Type;
5453 function Has_Body (Pack_Decl : Node_Id) return Boolean is
5454 function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id;
5455 -- Try to locate the corresponding body of spec Spec_Id. If no body is
5456 -- found, return Empty.
5459 (Spec_Id : Entity_Id;
5460 From : Node_Id) return Node_Id;
5461 -- Try to locate the corresponding body of spec Spec_Id in the node list
5462 -- which follows arbitrary node From. If no body is found, return Empty.
5464 function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id;
5465 -- Attempt to load the body of unit Unit_Nam. If the load failed, return
5466 -- Empty. If the compilation will not generate code, return Empty.
5468 -----------------------------
5469 -- Find_Corresponding_Body --
5470 -----------------------------
5472 function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id is
5473 Context : constant Entity_Id := Scope (Spec_Id);
5474 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id);
5475 Body_Decl : Node_Id;
5476 Body_Id : Entity_Id;
5479 if Is_Compilation_Unit (Spec_Id) then
5480 Body_Id := Corresponding_Body (Spec_Decl);
5482 if Present (Body_Id) then
5483 return Unit_Declaration_Node (Body_Id);
5485 -- The package is at the library and requires a body. Load the
5486 -- corresponding body because the optional body may be declared
5489 elsif Unit_Requires_Body (Spec_Id) then
5492 (Get_Body_Name (Unit_Name (Get_Source_Unit (Spec_Decl))));
5494 -- Otherwise there is no optional body
5500 -- The immediate context is a package. The optional body may be
5501 -- within the body of that package.
5503 -- procedure Proc is
5504 -- package Nested_1 is
5505 -- package Nested_2 is
5512 -- package body Nested_1 is
5513 -- package body Nested_2 is separate;
5516 -- separate (Proc.Nested_1.Nested_2)
5517 -- package body Nested_2 is
5518 -- package body Pack is -- optional body
5523 elsif Is_Package_Or_Generic_Package (Context) then
5524 Body_Decl := Find_Corresponding_Body (Context);
5526 -- The optional body is within the body of the enclosing package
5528 if Present (Body_Decl) then
5531 (Spec_Id => Spec_Id,
5532 From => First (Declarations (Body_Decl)));
5534 -- Otherwise the enclosing package does not have a body. This may
5535 -- be the result of an error or a genuine lack of a body.
5541 -- Otherwise the immediate context is a body. The optional body may
5542 -- be within the same list as the spec.
5544 -- procedure Proc is
5549 -- package body Pack is -- optional body
5556 (Spec_Id => Spec_Id,
5557 From => Next (Spec_Decl));
5559 end Find_Corresponding_Body;
5566 (Spec_Id : Entity_Id;
5567 From : Node_Id) return Node_Id
5569 Spec_Nam : constant Name_Id := Chars (Spec_Id);
5575 while Present (Item) loop
5577 -- The current item denotes the optional body
5579 if Nkind (Item) = N_Package_Body
5580 and then Chars (Defining_Entity (Item)) = Spec_Nam
5584 -- The current item denotes a stub, the optional body may be in
5587 elsif Nkind (Item) = N_Package_Body_Stub
5588 and then Chars (Defining_Entity (Item)) = Spec_Nam
5590 Lib_Unit := Library_Unit (Item);
5592 -- The corresponding subunit was previously loaded
5594 if Present (Lib_Unit) then
5597 -- Otherwise attempt to load the corresponding subunit
5600 return Load_Package_Body (Get_Unit_Name (Item));
5610 -----------------------
5611 -- Load_Package_Body --
5612 -----------------------
5614 function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id is
5615 Body_Decl : Node_Id;
5616 Unit_Num : Unit_Number_Type;
5619 -- The load is performed only when the compilation will generate code
5621 if Operating_Mode = Generate_Code then
5624 (Load_Name => Unit_Nam,
5627 Error_Node => Pack_Decl);
5629 -- The load failed most likely because the physical file is
5632 if Unit_Num = No_Unit then
5635 -- Otherwise the load was successful, return the body of the unit
5638 Body_Decl := Unit (Cunit (Unit_Num));
5640 -- If the unit is a subunit with an available proper body,
5641 -- return the proper body.
5643 if Nkind (Body_Decl) = N_Subunit
5644 and then Present (Proper_Body (Body_Decl))
5646 Body_Decl := Proper_Body (Body_Decl);
5654 end Load_Package_Body;
5658 Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl);
5660 -- Start of processing for Has_Body
5663 -- The body is available
5665 if Present (Corresponding_Body (Pack_Decl)) then
5668 -- The body is required if the package spec contains a construct which
5669 -- requires a completion in a body.
5671 elsif Unit_Requires_Body (Pack_Id) then
5674 -- The body may be optional
5677 return Present (Find_Corresponding_Body (Pack_Id));
5681 ---------------------------
5682 -- Has_Prior_Elaboration --
5683 ---------------------------
5685 function Has_Prior_Elaboration
5686 (Unit_Id : Entity_Id;
5687 Context_OK : Boolean := False;
5688 Elab_Body_OK : Boolean := False;
5689 Same_Unit_OK : Boolean := False) return Boolean
5691 Main_Id : constant Entity_Id := Cunit_Entity (Main_Unit);
5694 -- A preelaborated unit is always elaborated prior to the main unit
5696 if Is_Preelaborated_Unit (Unit_Id) then
5699 -- An internal unit is always elaborated prior to a non-internal main
5702 elsif In_Internal_Unit (Unit_Id)
5703 and then not In_Internal_Unit (Main_Id)
5707 -- A unit has prior elaboration if it appears within the context of the
5708 -- main unit. Consider this case only when requested by the caller.
5711 and then Elaboration_Status (Unit_Id) /= No_Elaboration_Attributes
5715 -- A unit whose body is elaborated together with its spec has prior
5716 -- elaboration except with respect to itself. Consider this case only
5717 -- when requested by the caller.
5720 and then Has_Pragma_Elaborate_Body (Unit_Id)
5721 and then not Is_Same_Unit (Unit_Id, Main_Id)
5725 -- A unit has no prior elaboration with respect to itself, but does not
5726 -- require any means of ensuring its own elaboration either. Treat this
5727 -- case as valid prior elaboration only when requested by the caller.
5729 elsif Same_Unit_OK and then Is_Same_Unit (Unit_Id, Main_Id) then
5734 end Has_Prior_Elaboration;
5736 --------------------------
5737 -- In_External_Instance --
5738 --------------------------
5740 function In_External_Instance
5742 Target_Decl : Node_Id) return Boolean
5745 Inst_Body : Node_Id;
5746 Inst_Decl : Node_Id;
5749 -- Performance note: parent traversal
5751 Inst_Decl := Find_Enclosing_Instance (Target_Decl);
5753 -- The target declaration appears within an instance spec. Visibility is
5754 -- ignored because internally generated primitives for private types may
5755 -- reside in the private declarations and still be invoked from outside.
5757 if Present (Inst_Decl)
5758 and then Nkind (Inst_Decl) = N_Package_Declaration
5760 -- The scenario comes from the main unit and the instance does not
5762 if In_Extended_Main_Code_Unit (N)
5763 and then not In_Extended_Main_Code_Unit (Inst_Decl)
5767 -- Otherwise the scenario must not appear within the instance spec or
5771 Extract_Instance_Attributes
5772 (Exp_Inst => Inst_Decl,
5773 Inst_Body => Inst_Body,
5774 Inst_Decl => Dummy);
5776 -- Performance note: parent traversal
5778 return not In_Subtree
5781 Root2 => Inst_Body);
5786 end In_External_Instance;
5788 ---------------------
5789 -- In_Main_Context --
5790 ---------------------
5792 function In_Main_Context (N : Node_Id) return Boolean is
5794 -- Scenarios outside the main unit are not considered because the ALI
5795 -- information supplied to binde is for the main unit only.
5797 if not In_Extended_Main_Code_Unit (N) then
5800 -- Scenarios within internal units are not considered unless switch
5801 -- -gnatdE (elaboration checks on predefined units) is in effect.
5803 elsif not Debug_Flag_EE and then In_Internal_Unit (N) then
5808 end In_Main_Context;
5810 ---------------------
5811 -- In_Same_Context --
5812 ---------------------
5814 function In_Same_Context
5817 Nested_OK : Boolean := False) return Boolean
5819 function Find_Enclosing_Context (N : Node_Id) return Node_Id;
5820 -- Return the nearest enclosing non-library-level or compilation unit
5821 -- node which which encapsulates arbitrary node N. Return Empty is no
5822 -- such context is available.
5824 function In_Nested_Context
5826 Inner : Node_Id) return Boolean;
5827 -- Determine whether arbitrary node Outer encapsulates arbitrary node
5830 ----------------------------
5831 -- Find_Enclosing_Context --
5832 ----------------------------
5834 function Find_Enclosing_Context (N : Node_Id) return Node_Id is
5840 while Present (Par) loop
5842 -- A traversal from a subunit continues via the corresponding stub
5844 if Nkind (Par) = N_Subunit then
5845 Par := Corresponding_Stub (Par);
5847 -- Stop the traversal when the nearest enclosing non-library-level
5848 -- encapsulator has been reached.
5850 elsif Is_Non_Library_Level_Encapsulator (Par) then
5851 Context := Parent (Par);
5853 -- The sole exception is when the encapsulator is the unit of
5854 -- compilation because this case requires special processing
5857 if Present (Context)
5858 and then Nkind (Context) = N_Compilation_Unit
5866 -- Reaching a compilation unit node without hitting a non-library-
5867 -- level encapsulator indicates that N is at the library level in
5868 -- which case the compilation unit is the context.
5870 elsif Nkind (Par) = N_Compilation_Unit then
5874 Par := Parent (Par);
5878 end Find_Enclosing_Context;
5880 -----------------------
5881 -- In_Nested_Context --
5882 -----------------------
5884 function In_Nested_Context
5886 Inner : Node_Id) return Boolean
5892 while Present (Par) loop
5894 -- A traversal from a subunit continues via the corresponding stub
5896 if Nkind (Par) = N_Subunit then
5897 Par := Corresponding_Stub (Par);
5899 elsif Par = Outer then
5903 Par := Parent (Par);
5907 end In_Nested_Context;
5911 Context_1 : constant Node_Id := Find_Enclosing_Context (N1);
5912 Context_2 : constant Node_Id := Find_Enclosing_Context (N2);
5914 -- Start of processing for In_Same_Context
5917 -- Both nodes appear within the same context
5919 if Context_1 = Context_2 then
5922 -- Both nodes appear in compilation units. Determine whether one unit
5923 -- is the body of the other.
5925 elsif Nkind (Context_1) = N_Compilation_Unit
5926 and then Nkind (Context_2) = N_Compilation_Unit
5930 (Unit_1 => Defining_Entity (Unit (Context_1)),
5931 Unit_2 => Defining_Entity (Unit (Context_2)));
5933 -- The context of N1 encloses the context of N2
5935 elsif Nested_OK and then In_Nested_Context (Context_1, Context_2) then
5940 end In_Same_Context;
5946 procedure Initialize is
5948 -- Set the soft link which enables Atree.Rewrite to update a top-level
5949 -- scenario each time it is transformed into another node.
5951 Set_Rewriting_Proc (Update_Elaboration_Scenario'Access);
5960 Target_Id : Entity_Id;
5964 procedure Info_Accept_Alternative;
5965 pragma Inline (Info_Accept_Alternative);
5966 -- Output information concerning an accept alternative
5968 procedure Info_Simple_Call;
5969 pragma Inline (Info_Simple_Call);
5970 -- Output information concerning the call
5972 procedure Info_Type_Actions (Action : String);
5973 pragma Inline (Info_Type_Actions);
5974 -- Output information concerning action Action of a type
5976 procedure Info_Verification_Call
5980 pragma Inline (Info_Verification_Call);
5981 -- Output information concerning the verification of predicate Pred
5982 -- applied to related entity Id with kind Id_Kind.
5984 -----------------------------
5985 -- Info_Accept_Alternative --
5986 -----------------------------
5988 procedure Info_Accept_Alternative is
5989 Entry_Id : constant Entity_Id := Receiving_Entry (Target_Id);
5992 pragma Assert (Present (Entry_Id));
5995 (Msg => "accept for entry & during elaboration",
5998 Info_Msg => Info_Msg,
5999 In_SPARK => In_SPARK);
6000 end Info_Accept_Alternative;
6002 ----------------------
6003 -- Info_Simple_Call --
6004 ----------------------
6006 procedure Info_Simple_Call is
6009 (Msg => "call to & during elaboration",
6012 Info_Msg => Info_Msg,
6013 In_SPARK => In_SPARK);
6014 end Info_Simple_Call;
6016 -----------------------
6017 -- Info_Type_Actions --
6018 -----------------------
6020 procedure Info_Type_Actions (Action : String) is
6021 Typ : constant Entity_Id := First_Formal_Type (Target_Id);
6024 pragma Assert (Present (Typ));
6027 (Msg => Action & " actions for type & during elaboration",
6030 Info_Msg => Info_Msg,
6031 In_SPARK => In_SPARK);
6032 end Info_Type_Actions;
6034 ----------------------------
6035 -- Info_Verification_Call --
6036 ----------------------------
6038 procedure Info_Verification_Call
6044 pragma Assert (Present (Id));
6048 "verification of " & Pred & " of " & Id_Kind & " & during "
6052 Info_Msg => Info_Msg,
6053 In_SPARK => In_SPARK);
6054 end Info_Verification_Call;
6056 -- Start of processing for Info_Call
6059 -- Do not output anything for targets defined in internal units because
6060 -- this creates noise.
6062 if not In_Internal_Unit (Target_Id) then
6064 -- Accept alternative
6066 if Is_Accept_Alternative_Proc (Target_Id) then
6067 Info_Accept_Alternative;
6071 elsif Is_TSS (Target_Id, TSS_Deep_Adjust) then
6072 Info_Type_Actions ("adjustment");
6074 -- Default_Initial_Condition
6076 elsif Is_Default_Initial_Condition_Proc (Target_Id) then
6077 Info_Verification_Call
6078 (Pred => "Default_Initial_Condition",
6079 Id => First_Formal_Type (Target_Id),
6084 elsif Is_Protected_Entry (Target_Id) then
6087 -- Task entry calls are never processed because the entry being
6088 -- invoked does not have a corresponding "body", it has a select.
6090 elsif Is_Task_Entry (Target_Id) then
6095 elsif Is_TSS (Target_Id, TSS_Deep_Finalize) then
6096 Info_Type_Actions ("finalization");
6098 -- Calls to _Finalizer procedures must not appear in the output
6099 -- because this creates confusing noise.
6101 elsif Is_Finalizer_Proc (Target_Id) then
6104 -- Initial_Condition
6106 elsif Is_Initial_Condition_Proc (Target_Id) then
6107 Info_Verification_Call
6108 (Pred => "Initial_Condition",
6109 Id => Find_Enclosing_Scope (Call),
6110 Id_Kind => "package");
6114 elsif Is_Init_Proc (Target_Id)
6115 or else Is_TSS (Target_Id, TSS_Deep_Initialize)
6117 Info_Type_Actions ("initialization");
6121 elsif Is_Invariant_Proc (Target_Id) then
6122 Info_Verification_Call
6123 (Pred => "invariants",
6124 Id => First_Formal_Type (Target_Id),
6127 -- Partial invariant calls must not appear in the output because this
6128 -- creates confusing noise.
6130 elsif Is_Partial_Invariant_Proc (Target_Id) then
6135 elsif Is_Postconditions_Proc (Target_Id) then
6136 Info_Verification_Call
6137 (Pred => "postconditions",
6138 Id => Find_Enclosing_Scope (Call),
6139 Id_Kind => "subprogram");
6141 -- Subprograms must come last because some of the previous cases fall
6142 -- under this category.
6144 elsif Ekind (Target_Id) = E_Function then
6147 elsif Ekind (Target_Id) = E_Procedure then
6151 pragma Assert (False);
6157 ------------------------
6158 -- Info_Instantiation --
6159 ------------------------
6161 procedure Info_Instantiation
6169 (Msg => "instantiation of & during elaboration",
6172 Info_Msg => Info_Msg,
6173 In_SPARK => In_SPARK);
6174 end Info_Instantiation;
6176 -----------------------------
6177 -- Info_Variable_Reference --
6178 -----------------------------
6180 procedure Info_Variable_Reference
6187 if Is_Read (Ref) then
6189 (Msg => "read of variable & during elaboration",
6192 Info_Msg => Info_Msg,
6193 In_SPARK => In_SPARK);
6195 end Info_Variable_Reference;
6197 --------------------
6198 -- Insertion_Node --
6199 --------------------
6201 function Insertion_Node (N : Node_Id; Ins_Nod : Node_Id) return Node_Id is
6203 -- When the scenario denotes an instantiation, the proper insertion node
6204 -- is the instance spec. This ensures that the generic actuals will not
6205 -- be evaluated prior to a potential ABE.
6207 if Nkind (N) in N_Generic_Instantiation
6208 and then Present (Instance_Spec (N))
6210 return Instance_Spec (N);
6212 -- Otherwise the proper insertion node is the candidate insertion node
6219 -----------------------
6220 -- Install_ABE_Check --
6221 -----------------------
6223 procedure Install_ABE_Check
6228 Check_Ins_Nod : constant Node_Id := Insertion_Node (N, Ins_Nod);
6229 -- Insert the check prior to this node
6231 Loc : constant Source_Ptr := Sloc (N);
6232 Spec_Id : constant Entity_Id := Unique_Entity (Id);
6233 Unit_Id : constant Entity_Id := Find_Top_Unit (Id);
6234 Scop_Id : Entity_Id;
6237 -- Nothing to do when compiling for GNATprove because raise statements
6238 -- are not supported.
6240 if GNATprove_Mode then
6243 -- Nothing to do when the compilation will not produce an executable
6245 elsif Serious_Errors_Detected > 0 then
6248 -- Nothing to do for a compilation unit because there is no executable
6249 -- environment at that level.
6251 elsif Nkind (Parent (Check_Ins_Nod)) = N_Compilation_Unit then
6254 -- Nothing to do when the unit is elaborated prior to the main unit.
6255 -- This check must also consider the following cases:
6257 -- * Id's unit appears in the context of the main unit
6259 -- * Id's unit is subject to pragma Elaborate_Body. An ABE check MUST
6260 -- NOT be generated because Id's unit is always elaborated prior to
6263 -- * Id's unit is the main unit. An ABE check MUST be generated in this
6264 -- case because a conditional ABE may be raised depending on the flow
6265 -- of execution within the main unit (flag Same_Unit_OK is False).
6267 elsif Has_Prior_Elaboration
6268 (Unit_Id => Unit_Id,
6270 Elab_Body_OK => True)
6275 -- Prevent multiple scenarios from installing the same ABE check
6277 Set_Is_Elaboration_Checks_OK_Node (N, False);
6279 -- Install the nearest enclosing scope of the scenario as there must be
6280 -- something on the scope stack.
6282 -- Performance note: parent traversal
6284 Scop_Id := Find_Enclosing_Scope (Check_Ins_Nod);
6285 pragma Assert (Present (Scop_Id));
6287 Push_Scope (Scop_Id);
6290 -- if not Spec_Id'Elaborated then
6291 -- raise Program_Error with "access before elaboration";
6294 Insert_Action (Check_Ins_Nod,
6295 Make_Raise_Program_Error (Loc,
6299 Make_Attribute_Reference (Loc,
6300 Prefix => New_Occurrence_Of (Spec_Id, Loc),
6301 Attribute_Name => Name_Elaborated)),
6302 Reason => PE_Access_Before_Elaboration));
6305 end Install_ABE_Check;
6307 -----------------------
6308 -- Install_ABE_Check --
6309 -----------------------
6311 procedure Install_ABE_Check
6313 Target_Id : Entity_Id;
6314 Target_Decl : Node_Id;
6315 Target_Body : Node_Id;
6318 procedure Build_Elaboration_Entity;
6319 pragma Inline (Build_Elaboration_Entity);
6320 -- Create a new elaboration flag for Target_Id, insert it prior to
6321 -- Target_Decl, and set it after Body_Decl.
6323 ------------------------------
6324 -- Build_Elaboration_Entity --
6325 ------------------------------
6327 procedure Build_Elaboration_Entity is
6328 Loc : constant Source_Ptr := Sloc (Target_Id);
6329 Flag_Id : Entity_Id;
6332 -- Create the declaration of the elaboration flag. The name carries a
6333 -- unique counter in case of name overloading.
6336 Make_Defining_Identifier (Loc,
6337 Chars => New_External_Name (Chars (Target_Id), 'E', -1));
6339 Set_Elaboration_Entity (Target_Id, Flag_Id);
6340 Set_Elaboration_Entity_Required (Target_Id);
6342 Push_Scope (Scope (Target_Id));
6345 -- Enn : Short_Integer := 0;
6347 Insert_Action (Target_Decl,
6348 Make_Object_Declaration (Loc,
6349 Defining_Identifier => Flag_Id,
6350 Object_Definition =>
6351 New_Occurrence_Of (Standard_Short_Integer, Loc),
6352 Expression => Make_Integer_Literal (Loc, Uint_0)));
6357 Set_Elaboration_Flag (Target_Body, Target_Id);
6360 end Build_Elaboration_Entity;
6364 Target_Unit_Id : constant Entity_Id := Find_Top_Unit (Target_Id);
6366 -- Start for processing for Install_ABE_Check
6369 -- Nothing to do when compiling for GNATprove because raise statements
6370 -- are not supported.
6372 if GNATprove_Mode then
6375 -- Nothing to do when the compilation will not produce an executable
6377 elsif Serious_Errors_Detected > 0 then
6380 -- Nothing to do when the target is a protected subprogram because the
6381 -- check is associated with the protected body subprogram.
6383 elsif Is_Protected_Subp (Target_Id) then
6386 -- Nothing to do when the target is elaborated prior to the main unit.
6387 -- This check must also consider the following cases:
6389 -- * The unit of the target appears in the context of the main unit
6391 -- * The unit of the target is subject to pragma Elaborate_Body. An ABE
6392 -- check MUST NOT be generated because the unit is always elaborated
6393 -- prior to the main unit.
6395 -- * The unit of the target is the main unit. An ABE check MUST be added
6396 -- in this case because a conditional ABE may be raised depending on
6397 -- the flow of execution within the main unit (flag Same_Unit_OK is
6400 elsif Has_Prior_Elaboration
6401 (Unit_Id => Target_Unit_Id,
6403 Elab_Body_OK => True)
6407 -- Create an elaboration flag for the target when it does not have one
6409 elsif No (Elaboration_Entity (Target_Id)) then
6410 Build_Elaboration_Entity;
6417 end Install_ABE_Check;
6419 -------------------------
6420 -- Install_ABE_Failure --
6421 -------------------------
6423 procedure Install_ABE_Failure (N : Node_Id; Ins_Nod : Node_Id) is
6424 Fail_Ins_Nod : constant Node_Id := Insertion_Node (N, Ins_Nod);
6425 -- Insert the failure prior to this node
6427 Loc : constant Source_Ptr := Sloc (N);
6428 Scop_Id : Entity_Id;
6431 -- Nothing to do when compiling for GNATprove because raise statements
6432 -- are not supported.
6434 if GNATprove_Mode then
6437 -- Nothing to do when the compilation will not produce an executable
6439 elsif Serious_Errors_Detected > 0 then
6442 -- Do not install an ABE check for a compilation unit because there is
6443 -- no executable environment at that level.
6445 elsif Nkind (Parent (Fail_Ins_Nod)) = N_Compilation_Unit then
6449 -- Prevent multiple scenarios from installing the same ABE failure
6451 Set_Is_Elaboration_Checks_OK_Node (N, False);
6453 -- Install the nearest enclosing scope of the scenario as there must be
6454 -- something on the scope stack.
6456 -- Performance note: parent traversal
6458 Scop_Id := Find_Enclosing_Scope (Fail_Ins_Nod);
6459 pragma Assert (Present (Scop_Id));
6461 Push_Scope (Scop_Id);
6464 -- raise Program_Error with "access before elaboration";
6466 Insert_Action (Fail_Ins_Nod,
6467 Make_Raise_Program_Error (Loc,
6468 Reason => PE_Access_Before_Elaboration));
6471 end Install_ABE_Failure;
6473 --------------------------------
6474 -- Is_Accept_Alternative_Proc --
6475 --------------------------------
6477 function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean is
6479 -- To qualify, the entity must denote a procedure with a receiving entry
6481 return Ekind (Id) = E_Procedure and then Present (Receiving_Entry (Id));
6482 end Is_Accept_Alternative_Proc;
6484 ------------------------
6485 -- Is_Activation_Proc --
6486 ------------------------
6488 function Is_Activation_Proc (Id : Entity_Id) return Boolean is
6490 -- To qualify, the entity must denote one of the runtime procedures in
6491 -- charge of task activation.
6493 if Ekind (Id) = E_Procedure then
6494 if Restricted_Profile then
6495 return Is_RTE (Id, RE_Activate_Restricted_Tasks);
6497 return Is_RTE (Id, RE_Activate_Tasks);
6502 end Is_Activation_Proc;
6504 ----------------------------
6505 -- Is_Ada_Semantic_Target --
6506 ----------------------------
6508 function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean is
6511 Is_Activation_Proc (Id)
6512 or else Is_Controlled_Proc (Id, Name_Adjust)
6513 or else Is_Controlled_Proc (Id, Name_Finalize)
6514 or else Is_Controlled_Proc (Id, Name_Initialize)
6515 or else Is_Init_Proc (Id)
6516 or else Is_Invariant_Proc (Id)
6517 or else Is_Protected_Entry (Id)
6518 or else Is_Protected_Subp (Id)
6519 or else Is_Protected_Body_Subp (Id)
6520 or else Is_Task_Entry (Id);
6521 end Is_Ada_Semantic_Target;
6523 ----------------------------
6524 -- Is_Bodiless_Subprogram --
6525 ----------------------------
6527 function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean is
6529 -- An abstract subprogram does not have a body
6531 if Ekind_In (Subp_Id, E_Function,
6534 and then Is_Abstract_Subprogram (Subp_Id)
6538 -- A formal subprogram does not have a body
6540 elsif Is_Formal_Subprogram (Subp_Id) then
6543 -- An imported subprogram may have a body, however it is not known at
6544 -- compile or bind time where the body resides and whether it will be
6545 -- elaborated on time.
6547 elsif Is_Imported (Subp_Id) then
6552 end Is_Bodiless_Subprogram;
6554 ------------------------
6555 -- Is_Controlled_Proc --
6556 ------------------------
6558 function Is_Controlled_Proc
6559 (Subp_Id : Entity_Id;
6560 Subp_Nam : Name_Id) return Boolean
6562 Formal_Id : Entity_Id;
6565 pragma Assert (Nam_In (Subp_Nam, Name_Adjust,
6569 -- To qualify, the subprogram must denote a source procedure with name
6570 -- Adjust, Finalize, or Initialize where the sole formal is controlled.
6572 if Comes_From_Source (Subp_Id)
6573 and then Ekind (Subp_Id) = E_Procedure
6574 and then Chars (Subp_Id) = Subp_Nam
6576 Formal_Id := First_Formal (Subp_Id);
6580 and then Is_Controlled (Etype (Formal_Id))
6581 and then No (Next_Formal (Formal_Id));
6585 end Is_Controlled_Proc;
6587 ---------------------------------------
6588 -- Is_Default_Initial_Condition_Proc --
6589 ---------------------------------------
6591 function Is_Default_Initial_Condition_Proc
6592 (Id : Entity_Id) return Boolean
6595 -- To qualify, the entity must denote a Default_Initial_Condition
6598 return Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id);
6599 end Is_Default_Initial_Condition_Proc;
6601 -----------------------
6602 -- Is_Finalizer_Proc --
6603 -----------------------
6605 function Is_Finalizer_Proc (Id : Entity_Id) return Boolean is
6607 -- To qualify, the entity must denote a _Finalizer procedure
6609 return Ekind (Id) = E_Procedure and then Chars (Id) = Name_uFinalizer;
6610 end Is_Finalizer_Proc;
6612 -----------------------
6613 -- Is_Guaranteed_ABE --
6614 -----------------------
6616 function Is_Guaranteed_ABE
6618 Target_Decl : Node_Id;
6619 Target_Body : Node_Id) return Boolean
6622 -- Avoid cascaded errors if there were previous serious infractions.
6623 -- As a result the scenario will not be treated as a guaranteed ABE.
6624 -- This behaviour parallels that of the old ABE mechanism.
6626 if Serious_Errors_Detected > 0 then
6629 -- The scenario and the target appear within the same context ignoring
6630 -- enclosing library levels.
6632 -- Performance note: parent traversal
6634 elsif In_Same_Context (N, Target_Decl) then
6636 -- The target body has already been encountered. The scenario results
6637 -- in a guaranteed ABE if it appears prior to the body.
6639 if Present (Target_Body) then
6640 return Earlier_In_Extended_Unit (N, Target_Body);
6642 -- Otherwise the body has not been encountered yet. The scenario is
6643 -- a guaranteed ABE since the body will appear later. It is assumed
6644 -- that the caller has already checked whether the scenario is ABE-
6645 -- safe as optional bodies are not considered here.
6653 end Is_Guaranteed_ABE;
6655 -------------------------------
6656 -- Is_Initial_Condition_Proc --
6657 -------------------------------
6659 function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean is
6661 -- To qualify, the entity must denote an Initial_Condition procedure
6664 Ekind (Id) = E_Procedure and then Is_Initial_Condition_Procedure (Id);
6665 end Is_Initial_Condition_Proc;
6667 --------------------
6668 -- Is_Initialized --
6669 --------------------
6671 function Is_Initialized (Obj_Decl : Node_Id) return Boolean is
6673 -- To qualify, the object declaration must have an expression
6676 Present (Expression (Obj_Decl)) or else Has_Init_Expression (Obj_Decl);
6679 -----------------------
6680 -- Is_Invariant_Proc --
6681 -----------------------
6683 function Is_Invariant_Proc (Id : Entity_Id) return Boolean is
6685 -- To qualify, the entity must denote the "full" invariant procedure
6687 return Ekind (Id) = E_Procedure and then Is_Invariant_Procedure (Id);
6688 end Is_Invariant_Proc;
6690 ---------------------------------------
6691 -- Is_Non_Library_Level_Encapsulator --
6692 ---------------------------------------
6694 function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean is
6697 when N_Abstract_Subprogram_Declaration
6698 | N_Aspect_Specification
6699 | N_Component_Declaration
6701 | N_Entry_Declaration
6702 | N_Expression_Function
6703 | N_Formal_Abstract_Subprogram_Declaration
6704 | N_Formal_Concrete_Subprogram_Declaration
6705 | N_Formal_Object_Declaration
6706 | N_Formal_Package_Declaration
6707 | N_Formal_Type_Declaration
6708 | N_Generic_Association
6709 | N_Implicit_Label_Declaration
6710 | N_Incomplete_Type_Declaration
6711 | N_Private_Extension_Declaration
6712 | N_Private_Type_Declaration
6714 | N_Protected_Type_Declaration
6715 | N_Single_Protected_Declaration
6716 | N_Single_Task_Declaration
6718 | N_Subprogram_Declaration
6720 | N_Task_Type_Declaration
6725 return Is_Generic_Declaration_Or_Body (N);
6727 end Is_Non_Library_Level_Encapsulator;
6729 -------------------------------
6730 -- Is_Partial_Invariant_Proc --
6731 -------------------------------
6733 function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean is
6735 -- To qualify, the entity must denote the "partial" invariant procedure
6738 Ekind (Id) = E_Procedure and then Is_Partial_Invariant_Procedure (Id);
6739 end Is_Partial_Invariant_Proc;
6741 ----------------------------
6742 -- Is_Postconditions_Proc --
6743 ----------------------------
6745 function Is_Postconditions_Proc (Id : Entity_Id) return Boolean is
6747 -- To qualify, the entity must denote a _Postconditions procedure
6750 Ekind (Id) = E_Procedure and then Chars (Id) = Name_uPostconditions;
6751 end Is_Postconditions_Proc;
6753 ---------------------------
6754 -- Is_Preelaborated_Unit --
6755 ---------------------------
6757 function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean is
6760 Is_Preelaborated (Id)
6761 or else Is_Pure (Id)
6762 or else Is_Remote_Call_Interface (Id)
6763 or else Is_Remote_Types (Id)
6764 or else Is_Shared_Passive (Id);
6765 end Is_Preelaborated_Unit;
6767 ------------------------
6768 -- Is_Protected_Entry --
6769 ------------------------
6771 function Is_Protected_Entry (Id : Entity_Id) return Boolean is
6773 -- To qualify, the entity must denote an entry defined in a protected
6778 and then Is_Protected_Type (Non_Private_View (Scope (Id)));
6779 end Is_Protected_Entry;
6781 -----------------------
6782 -- Is_Protected_Subp --
6783 -----------------------
6785 function Is_Protected_Subp (Id : Entity_Id) return Boolean is
6787 -- To qualify, the entity must denote a subprogram defined within a
6791 Ekind_In (Id, E_Function, E_Procedure)
6792 and then Is_Protected_Type (Non_Private_View (Scope (Id)));
6793 end Is_Protected_Subp;
6795 ----------------------------
6796 -- Is_Protected_Body_Subp --
6797 ----------------------------
6799 function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean is
6801 -- To qualify, the entity must denote a subprogram with attribute
6802 -- Protected_Subprogram set.
6805 Ekind_In (Id, E_Function, E_Procedure)
6806 and then Present (Protected_Subprogram (Id));
6807 end Is_Protected_Body_Subp;
6809 --------------------------------
6810 -- Is_Recorded_SPARK_Scenario --
6811 --------------------------------
6813 function Is_Recorded_SPARK_Scenario (N : Node_Id) return Boolean is
6815 if Recorded_SPARK_Scenarios_In_Use then
6816 return Recorded_SPARK_Scenarios.Get (N);
6819 return Recorded_SPARK_Scenarios_No_Element;
6820 end Is_Recorded_SPARK_Scenario;
6822 ------------------------------------
6823 -- Is_Recorded_Top_Level_Scenario --
6824 ------------------------------------
6826 function Is_Recorded_Top_Level_Scenario (N : Node_Id) return Boolean is
6828 if Recorded_Top_Level_Scenarios_In_Use then
6829 return Recorded_Top_Level_Scenarios.Get (N);
6832 return Recorded_Top_Level_Scenarios_No_Element;
6833 end Is_Recorded_Top_Level_Scenario;
6835 ------------------------
6836 -- Is_Safe_Activation --
6837 ------------------------
6839 function Is_Safe_Activation
6841 Task_Decl : Node_Id) return Boolean
6844 -- The activation of a task coming from an external instance cannot
6845 -- cause an ABE because the generic was already instantiated. Note
6846 -- that the instantiation itself may lead to an ABE.
6849 In_External_Instance
6851 Target_Decl => Task_Decl);
6852 end Is_Safe_Activation;
6858 function Is_Safe_Call
6860 Target_Attrs : Target_Attributes) return Boolean
6863 -- The target is either an abstract subprogram, formal subprogram, or
6864 -- imported, in which case it does not have a body at compile or bind
6865 -- time. Assume that the call is ABE-safe.
6867 if Is_Bodiless_Subprogram (Target_Attrs.Spec_Id) then
6870 -- The target is an instantiation of a generic subprogram. The call
6871 -- cannot cause an ABE because the generic was already instantiated.
6872 -- Note that the instantiation itself may lead to an ABE.
6874 elsif Is_Generic_Instance (Target_Attrs.Spec_Id) then
6877 -- The invocation of a target coming from an external instance cannot
6878 -- cause an ABE because the generic was already instantiated. Note that
6879 -- the instantiation itself may lead to an ABE.
6881 elsif In_External_Instance
6883 Target_Decl => Target_Attrs.Spec_Decl)
6887 -- The target is a subprogram body without a previous declaration. The
6888 -- call cannot cause an ABE because the body has already been seen.
6890 elsif Nkind (Target_Attrs.Spec_Decl) = N_Subprogram_Body
6891 and then No (Corresponding_Spec (Target_Attrs.Spec_Decl))
6895 -- The target is a subprogram body stub without a prior declaration.
6896 -- The call cannot cause an ABE because the proper body substitutes
6899 elsif Nkind (Target_Attrs.Spec_Decl) = N_Subprogram_Body_Stub
6900 and then No (Corresponding_Spec_Of_Stub (Target_Attrs.Spec_Decl))
6904 -- Subprogram bodies which wrap attribute references used as actuals
6905 -- in instantiations are always ABE-safe. These bodies are artifacts
6908 elsif Present (Target_Attrs.Body_Decl)
6909 and then Nkind (Target_Attrs.Body_Decl) = N_Subprogram_Body
6910 and then Was_Attribute_Reference (Target_Attrs.Body_Decl)
6918 ---------------------------
6919 -- Is_Safe_Instantiation --
6920 ---------------------------
6922 function Is_Safe_Instantiation
6924 Gen_Attrs : Target_Attributes) return Boolean
6927 -- The generic is an intrinsic subprogram in which case it does not
6928 -- have a body at compile or bind time. Assume that the instantiation
6931 if Is_Bodiless_Subprogram (Gen_Attrs.Spec_Id) then
6934 -- The instantiation of an external nested generic cannot cause an ABE
6935 -- if the outer generic was already instantiated. Note that the instance
6936 -- of the outer generic may lead to an ABE.
6938 elsif In_External_Instance
6940 Target_Decl => Gen_Attrs.Spec_Decl)
6944 -- The generic is a package. The instantiation cannot cause an ABE when
6945 -- the package has no body.
6947 elsif Ekind (Gen_Attrs.Spec_Id) = E_Generic_Package
6948 and then not Has_Body (Gen_Attrs.Spec_Decl)
6954 end Is_Safe_Instantiation;
6960 function Is_Same_Unit
6961 (Unit_1 : Entity_Id;
6962 Unit_2 : Entity_Id) return Boolean
6964 function Is_Subunit (Unit_Id : Entity_Id) return Boolean;
6965 pragma Inline (Is_Subunit);
6966 -- Determine whether unit Unit_Id is a subunit
6968 function Normalize_Unit (Unit_Id : Entity_Id) return Entity_Id;
6969 -- Strip a potential subunit chain ending with unit Unit_Id and return
6970 -- the corresponding spec.
6976 function Is_Subunit (Unit_Id : Entity_Id) return Boolean is
6978 return Nkind (Parent (Unit_Declaration_Node (Unit_Id))) = N_Subunit;
6981 --------------------
6982 -- Normalize_Unit --
6983 --------------------
6985 function Normalize_Unit (Unit_Id : Entity_Id) return Entity_Id is
6989 -- Eliminate a potential chain of subunits to reach to proper body
6992 while Present (Result)
6993 and then Result /= Standard_Standard
6994 and then Is_Subunit (Result)
6996 Result := Scope (Result);
6999 -- Obtain the entity of the corresponding spec (if any)
7001 return Unique_Entity (Result);
7004 -- Start of processing for Is_Same_Unit
7007 return Normalize_Unit (Unit_1) = Normalize_Unit (Unit_2);
7014 function Is_Scenario (N : Node_Id) return Boolean is
7017 when N_Assignment_Statement
7018 | N_Attribute_Reference
7020 | N_Entry_Call_Statement
7023 | N_Function_Instantiation
7025 | N_Package_Instantiation
7026 | N_Procedure_Call_Statement
7027 | N_Procedure_Instantiation
7028 | N_Requeue_Statement
7037 ------------------------------
7038 -- Is_SPARK_Semantic_Target --
7039 ------------------------------
7041 function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean is
7044 Is_Default_Initial_Condition_Proc (Id)
7045 or else Is_Initial_Condition_Proc (Id);
7046 end Is_SPARK_Semantic_Target;
7048 ------------------------
7049 -- Is_Suitable_Access --
7050 ------------------------
7052 function Is_Suitable_Access (N : Node_Id) return Boolean is
7055 Subp_Id : Entity_Id;
7058 -- This scenario is relevant only when the static model is in effect
7059 -- because it is graph-dependent and does not involve any run-time
7060 -- checks. Allowing it in the dynamic model would create confusing
7063 if not Static_Elaboration_Checks then
7066 -- Nothing to do when switch -gnatd.U (ignore 'Access) is in effect
7068 elsif Debug_Flag_Dot_UU then
7071 -- Nothing to do when the scenario is not an attribute reference
7073 elsif Nkind (N) /= N_Attribute_Reference then
7076 -- Nothing to do for internally-generated attributes because they are
7077 -- assumed to be ABE safe.
7079 elsif not Comes_From_Source (N) then
7083 Nam := Attribute_Name (N);
7086 -- Sanitize the prefix of the attribute
7088 if not Is_Entity_Name (Pref) then
7091 elsif No (Entity (Pref)) then
7095 Subp_Id := Entity (Pref);
7097 if not Is_Subprogram_Or_Entry (Subp_Id) then
7101 -- Traverse a possible chain of renamings to obtain the original entry
7102 -- or subprogram which the prefix may rename.
7104 Subp_Id := Get_Renamed_Entity (Subp_Id);
7106 -- To qualify, the attribute must meet the following prerequisites:
7110 -- The prefix must denote a source entry, operator, or subprogram
7111 -- which is not imported.
7113 Comes_From_Source (Subp_Id)
7114 and then Is_Subprogram_Or_Entry (Subp_Id)
7115 and then not Is_Bodiless_Subprogram (Subp_Id)
7117 -- The attribute name must be one of the 'Access forms. Note that
7118 -- 'Unchecked_Access cannot apply to a subprogram.
7120 and then Nam_In (Nam, Name_Access, Name_Unrestricted_Access);
7121 end Is_Suitable_Access;
7123 ----------------------
7124 -- Is_Suitable_Call --
7125 ----------------------
7127 function Is_Suitable_Call (N : Node_Id) return Boolean is
7129 -- Entry and subprogram calls are intentionally ignored because they
7130 -- may undergo expansion depending on the compilation mode, previous
7131 -- errors, generic context, etc. Call markers play the role of calls
7132 -- and provide a uniform foundation for ABE processing.
7134 return Nkind (N) = N_Call_Marker;
7135 end Is_Suitable_Call;
7137 -------------------------------
7138 -- Is_Suitable_Instantiation --
7139 -------------------------------
7141 function Is_Suitable_Instantiation (N : Node_Id) return Boolean is
7142 Orig_N : constant Node_Id := Original_Node (N);
7143 -- Use the original node in case an instantiation library unit is
7144 -- rewritten as a package or subprogram.
7147 -- To qualify, the instantiation must come from source
7150 Comes_From_Source (Orig_N)
7151 and then Nkind (Orig_N) in N_Generic_Instantiation;
7152 end Is_Suitable_Instantiation;
7154 --------------------------
7155 -- Is_Suitable_Scenario --
7156 --------------------------
7158 function Is_Suitable_Scenario (N : Node_Id) return Boolean is
7160 -- NOTE: Derived types and pragma Refined_State are intentionally left
7161 -- out because they are not executable during elaboration.
7164 Is_Suitable_Access (N)
7165 or else Is_Suitable_Call (N)
7166 or else Is_Suitable_Instantiation (N)
7167 or else Is_Suitable_Variable_Assignment (N)
7168 or else Is_Suitable_Variable_Reference (N);
7169 end Is_Suitable_Scenario;
7171 ------------------------------------
7172 -- Is_Suitable_SPARK_Derived_Type --
7173 ------------------------------------
7175 function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean is
7180 -- To qualify, the type declaration must denote a derived tagged type
7181 -- with primitive operations, subject to pragma SPARK_Mode On.
7183 if Nkind (N) = N_Full_Type_Declaration
7184 and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition
7186 Typ := Defining_Entity (N);
7187 Prag := SPARK_Pragma (Typ);
7190 Is_Tagged_Type (Typ)
7191 and then Has_Primitive_Operations (Typ)
7192 and then Present (Prag)
7193 and then Get_SPARK_Mode_From_Annotation (Prag) = On;
7197 end Is_Suitable_SPARK_Derived_Type;
7199 -------------------------------------
7200 -- Is_Suitable_SPARK_Instantiation --
7201 -------------------------------------
7203 function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean is
7204 Gen_Attrs : Target_Attributes;
7207 Inst_Attrs : Instantiation_Attributes;
7208 Inst_Id : Entity_Id;
7211 -- To qualify, both the instantiation and the generic must be subject to
7214 if Is_Suitable_Instantiation (N) then
7215 Extract_Instantiation_Attributes
7220 Attrs => Inst_Attrs);
7222 Extract_Target_Attributes (Gen_Id, Gen_Attrs);
7224 return Inst_Attrs.SPARK_Mode_On and Gen_Attrs.SPARK_Mode_On;
7228 end Is_Suitable_SPARK_Instantiation;
7230 --------------------------------------------
7231 -- Is_Suitable_SPARK_Refined_State_Pragma --
7232 --------------------------------------------
7234 function Is_Suitable_SPARK_Refined_State_Pragma
7235 (N : Node_Id) return Boolean
7238 -- To qualfy, the pragma must denote Refined_State
7241 Nkind (N) = N_Pragma
7242 and then Pragma_Name (N) = Name_Refined_State;
7243 end Is_Suitable_SPARK_Refined_State_Pragma;
7245 -------------------------------------
7246 -- Is_Suitable_Variable_Assignment --
7247 -------------------------------------
7249 function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean is
7251 N_Unit_Id : Entity_Id;
7256 Var_Unit_Id : Entity_Id;
7259 -- This scenario is relevant only when the static model is in effect
7260 -- because it is graph-dependent and does not involve any run-time
7261 -- checks. Allowing it in the dynamic model would create confusing
7264 if not Static_Elaboration_Checks then
7267 -- Nothing to do when the scenario is not an assignment
7269 elsif Nkind (N) /= N_Assignment_Statement then
7272 -- Nothing to do for internally-generated assignments because they are
7273 -- assumed to be ABE safe.
7275 elsif not Comes_From_Source (N) then
7278 -- Assignments are ignored in GNAT mode on the assumption that they are
7279 -- ABE-safe. This behaviour parallels that of the old ABE mechanism.
7281 elsif GNAT_Mode then
7285 Nam := Extract_Assignment_Name (N);
7287 -- Sanitize the left hand side of the assignment
7289 if not Is_Entity_Name (Nam) then
7292 elsif No (Entity (Nam)) then
7296 Var_Id := Entity (Nam);
7298 -- Sanitize the variable
7300 if Var_Id = Any_Id then
7303 elsif Ekind (Var_Id) /= E_Variable then
7307 Var_Decl := Declaration_Node (Var_Id);
7309 if Nkind (Var_Decl) /= N_Object_Declaration then
7313 N_Unit_Id := Find_Top_Unit (N);
7314 N_Unit := Unit_Declaration_Node (N_Unit_Id);
7316 Var_Unit_Id := Find_Top_Unit (Var_Decl);
7317 Var_Unit := Unit_Declaration_Node (Var_Unit_Id);
7319 -- To qualify, the assignment must meet the following prerequisites:
7322 Comes_From_Source (Var_Id)
7324 -- The variable must be declared in the spec of compilation unit U
7326 and then Nkind (Var_Unit) = N_Package_Declaration
7328 -- Performance note: parent traversal
7330 and then Find_Enclosing_Level (Var_Decl) = Package_Spec
7332 -- The assignment must occur in the body of compilation unit U
7334 and then Nkind (N_Unit) = N_Package_Body
7335 and then Present (Corresponding_Body (Var_Unit))
7336 and then Corresponding_Body (Var_Unit) = N_Unit_Id;
7337 end Is_Suitable_Variable_Assignment;
7339 ------------------------------------
7340 -- Is_Suitable_Variable_Reference --
7341 ------------------------------------
7343 function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean is
7345 -- Expanded names and identifiers are intentionally ignored because they
7346 -- be folded, optimized away, etc. Variable references markers play the
7347 -- role of variable references and provide a uniform foundation for ABE
7350 return Nkind (N) = N_Variable_Reference_Marker;
7351 end Is_Suitable_Variable_Reference;
7357 function Is_Task_Entry (Id : Entity_Id) return Boolean is
7359 -- To qualify, the entity must denote an entry defined in a task type
7362 Is_Entry (Id) and then Is_Task_Type (Non_Private_View (Scope (Id)));
7365 ------------------------
7366 -- Is_Up_Level_Target --
7367 ------------------------
7369 function Is_Up_Level_Target (Target_Decl : Node_Id) return Boolean is
7370 Root : constant Node_Id := Root_Scenario;
7373 -- The root appears within the declaratons of a block statement, entry
7374 -- body, subprogram body, or task body ignoring enclosing packages. The
7375 -- root is always within the main unit. An up-level target is a notion
7376 -- applicable only to the static model because scenarios are reached by
7377 -- means of graph traversal started from a fixed declarative or library
7380 -- Performance note: parent traversal
7382 if Static_Elaboration_Checks
7383 and then Find_Enclosing_Level (Root) = Declaration_Level
7385 -- The target is within the main unit. It acts as an up-level target
7386 -- when it appears within a context which encloses the root.
7388 -- package body Main_Unit is
7389 -- function Func ...; -- target
7391 -- procedure Proc is
7392 -- X : ... := Func; -- root scenario
7394 if In_Extended_Main_Code_Unit (Target_Decl) then
7396 -- Performance note: parent traversal
7398 return not In_Same_Context (Root, Target_Decl, Nested_OK => True);
7400 -- Otherwise the target is external to the main unit which makes it
7401 -- an up-level target.
7409 end Is_Up_Level_Target;
7411 ---------------------
7412 -- Is_Visited_Body --
7413 ---------------------
7415 function Is_Visited_Body (Body_Decl : Node_Id) return Boolean is
7417 if Visited_Bodies_In_Use then
7418 return Visited_Bodies.Get (Body_Decl);
7421 return Visited_Bodies_No_Element;
7422 end Is_Visited_Body;
7424 -------------------------------
7425 -- Kill_Elaboration_Scenario --
7426 -------------------------------
7428 procedure Kill_Elaboration_Scenario (N : Node_Id) is
7429 procedure Kill_SPARK_Scenario;
7430 pragma Inline (Kill_SPARK_Scenario);
7431 -- Eliminate scenario N from table SPARK_Scenarios if it is recorded
7434 procedure Kill_Top_Level_Scenario;
7435 pragma Inline (Kill_Top_Level_Scenario);
7436 -- Eliminate scenario N from table Top_Level_Scenarios if it is recorded
7439 -------------------------
7440 -- Kill_SPARK_Scenario --
7441 -------------------------
7443 procedure Kill_SPARK_Scenario is
7444 package Scenarios renames SPARK_Scenarios;
7447 if Is_Recorded_SPARK_Scenario (N) then
7449 -- Performance note: list traversal
7451 for Index in Scenarios.First .. Scenarios.Last loop
7452 if Scenarios.Table (Index) = N then
7453 Scenarios.Table (Index) := Empty;
7455 -- The SPARK scenario is no longer recorded
7457 Set_Is_Recorded_SPARK_Scenario (N, False);
7462 -- A recorded SPARK scenario must be in the table of recorded
7465 pragma Assert (False);
7467 end Kill_SPARK_Scenario;
7469 -----------------------------
7470 -- Kill_Top_Level_Scenario --
7471 -----------------------------
7473 procedure Kill_Top_Level_Scenario is
7474 package Scenarios renames Top_Level_Scenarios;
7477 if Is_Recorded_Top_Level_Scenario (N) then
7479 -- Performance node: list traversal
7481 for Index in Scenarios.First .. Scenarios.Last loop
7482 if Scenarios.Table (Index) = N then
7483 Scenarios.Table (Index) := Empty;
7485 -- The top-level scenario is no longer recorded
7487 Set_Is_Recorded_Top_Level_Scenario (N, False);
7492 -- A recorded top-level scenario must be in the table of recorded
7493 -- top-level scenarios.
7495 pragma Assert (False);
7497 end Kill_Top_Level_Scenario;
7499 -- Start of processing for Kill_Elaboration_Scenario
7502 -- Eliminate a recorded scenario when it appears within dead code
7503 -- because it will not be executed at elaboration time.
7505 if Is_Scenario (N) then
7506 Kill_SPARK_Scenario;
7507 Kill_Top_Level_Scenario;
7509 end Kill_Elaboration_Scenario;
7511 ----------------------------------
7512 -- Meet_Elaboration_Requirement --
7513 ----------------------------------
7515 procedure Meet_Elaboration_Requirement
7517 Target_Id : Entity_Id;
7520 Main_Id : constant Entity_Id := Cunit_Entity (Main_Unit);
7521 Unit_Id : constant Entity_Id := Find_Top_Unit (Target_Id);
7523 function Find_Preelaboration_Pragma
7524 (Prag_Nam : Name_Id) return Node_Id;
7525 pragma Inline (Find_Preelaboration_Pragma);
7526 -- Traverse the visible declarations of unit Unit_Id and locate a source
7527 -- preelaboration-related pragma with name Prag_Nam.
7529 procedure Info_Requirement_Met (Prag : Node_Id);
7530 pragma Inline (Info_Requirement_Met);
7531 -- Output information concerning pragma Prag which meets requirement
7534 procedure Info_Scenario;
7535 pragma Inline (Info_Scenario);
7536 -- Output information concerning scenario N
7538 --------------------------------
7539 -- Find_Preelaboration_Pragma --
7540 --------------------------------
7542 function Find_Preelaboration_Pragma
7543 (Prag_Nam : Name_Id) return Node_Id
7545 Spec : constant Node_Id := Parent (Unit_Id);
7549 -- A preelaboration-related pragma comes from source and appears at
7550 -- the top of the visible declarations of a package.
7552 if Nkind (Spec) = N_Package_Specification then
7553 Decl := First (Visible_Declarations (Spec));
7554 while Present (Decl) loop
7555 if Comes_From_Source (Decl) then
7556 if Nkind (Decl) = N_Pragma
7557 and then Pragma_Name (Decl) = Prag_Nam
7561 -- Otherwise the construct terminates the region where the
7562 -- preelabortion-related pragma may appear.
7574 end Find_Preelaboration_Pragma;
7576 --------------------------
7577 -- Info_Requirement_Met --
7578 --------------------------
7580 procedure Info_Requirement_Met (Prag : Node_Id) is
7582 pragma Assert (Present (Prag));
7584 Error_Msg_Name_1 := Req_Nam;
7585 Error_Msg_Sloc := Sloc (Prag);
7587 ("\\% requirement for unit & met by pragma #", N, Unit_Id);
7588 end Info_Requirement_Met;
7594 procedure Info_Scenario is
7596 if Is_Suitable_Call (N) then
7599 Target_Id => Target_Id,
7603 elsif Is_Suitable_Instantiation (N) then
7606 Gen_Id => Target_Id,
7610 elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
7612 ("read of refinement constituents during elaboration in SPARK",
7615 elsif Is_Suitable_Variable_Reference (N) then
7616 Info_Variable_Reference
7618 Var_Id => Target_Id,
7622 -- No other scenario may impose a requirement on the context of the
7626 pragma Assert (False);
7633 Elab_Attrs : Elaboration_Attributes;
7637 -- Start of processing for Meet_Elaboration_Requirement
7640 pragma Assert (Nam_In (Req_Nam, Name_Elaborate, Name_Elaborate_All));
7642 -- Assume that the requirement has not been met
7646 -- Elaboration requirements are verified only when the static model is
7647 -- in effect because this diagnostic is graph-dependent.
7649 if not Static_Elaboration_Checks then
7652 -- If the target is within the main unit, either at the source level or
7653 -- through an instantiation, then there is no real requirement to meet
7654 -- because the main unit cannot force its own elaboration by means of an
7655 -- Elaborate[_All] pragma. Treat this case as valid coverage.
7657 elsif In_Extended_Main_Code_Unit (Target_Id) then
7660 -- Otherwise the target resides in an external unit
7662 -- The requirement is met when the target comes from an internal unit
7663 -- because such a unit is elaborated prior to a non-internal unit.
7665 elsif In_Internal_Unit (Unit_Id)
7666 and then not In_Internal_Unit (Main_Id)
7670 -- The requirement is met when the target comes from a preelaborated
7671 -- unit. This portion must parallel predicate Is_Preelaborated_Unit.
7673 elsif Is_Preelaborated_Unit (Unit_Id) then
7676 -- Output extra information when switch -gnatel (info messages on
7677 -- implicit Elaborate[_All] pragmas.
7679 if Elab_Info_Messages then
7680 if Is_Preelaborated (Unit_Id) then
7681 Elab_Nam := Name_Preelaborate;
7683 elsif Is_Pure (Unit_Id) then
7684 Elab_Nam := Name_Pure;
7686 elsif Is_Remote_Call_Interface (Unit_Id) then
7687 Elab_Nam := Name_Remote_Call_Interface;
7689 elsif Is_Remote_Types (Unit_Id) then
7690 Elab_Nam := Name_Remote_Types;
7693 pragma Assert (Is_Shared_Passive (Unit_Id));
7694 Elab_Nam := Name_Shared_Passive;
7697 Info_Requirement_Met (Find_Preelaboration_Pragma (Elab_Nam));
7700 -- Determine whether the context of the main unit has a pragma strong
7701 -- enough to meet the requirement.
7704 Elab_Attrs := Elaboration_Status (Unit_Id);
7706 -- The pragma must be either Elaborate_All or be as strong as the
7709 if Present (Elab_Attrs.Source_Pragma)
7710 and then Nam_In (Pragma_Name (Elab_Attrs.Source_Pragma),
7716 -- Output extra information when switch -gnatel (info messages on
7717 -- implicit Elaborate[_All] pragmas.
7719 if Elab_Info_Messages then
7720 Info_Requirement_Met (Elab_Attrs.Source_Pragma);
7725 -- The requirement was not met by the context of the main unit, issue an
7731 Error_Msg_Name_1 := Req_Nam;
7732 Error_Msg_Node_2 := Unit_Id;
7733 Error_Msg_NE ("\\unit & requires pragma % for &", N, Main_Id);
7735 Output_Active_Scenarios (N);
7737 end Meet_Elaboration_Requirement;
7739 ----------------------
7740 -- Non_Private_View --
7741 ----------------------
7743 function Non_Private_View (Typ : Entity_Id) return Entity_Id is
7749 if Is_Private_Type (Result) and then Present (Full_View (Result)) then
7750 Result := Full_View (Result);
7754 end Non_Private_View;
7756 -----------------------------
7757 -- Output_Active_Scenarios --
7758 -----------------------------
7760 procedure Output_Active_Scenarios (Error_Nod : Node_Id) is
7761 procedure Output_Access (N : Node_Id);
7762 -- Emit a specific diagnostic message for 'Access denote by N
7764 procedure Output_Activation_Call (N : Node_Id);
7765 -- Emit a specific diagnostic message for task activation N
7767 procedure Output_Call (N : Node_Id; Target_Id : Entity_Id);
7768 -- Emit a specific diagnostic message for call N which invokes target
7771 procedure Output_Header;
7772 -- Emit a specific diagnostic message for the unit of the root scenario
7774 procedure Output_Instantiation (N : Node_Id);
7775 -- Emit a specific diagnostic message for instantiation N
7777 procedure Output_SPARK_Refined_State_Pragma (N : Node_Id);
7778 -- Emit a specific diagnostic message for Refined_State pragma N
7780 procedure Output_Variable_Assignment (N : Node_Id);
7781 -- Emit a specific diagnostic message for assignment statement N
7783 procedure Output_Variable_Reference (N : Node_Id);
7784 -- Emit a specific diagnostic message for reference N which mentions a
7791 procedure Output_Access (N : Node_Id) is
7792 Subp_Id : constant Entity_Id := Entity (Prefix (N));
7795 Error_Msg_Name_1 := Attribute_Name (N);
7796 Error_Msg_Sloc := Sloc (N);
7797 Error_Msg_NE ("\\ % of & taken #", Error_Nod, Subp_Id);
7800 ----------------------------
7801 -- Output_Activation_Call --
7802 ----------------------------
7804 procedure Output_Activation_Call (N : Node_Id) is
7805 function Find_Activator (Call : Node_Id) return Entity_Id;
7806 -- Find the nearest enclosing construct which houses call Call
7808 --------------------
7809 -- Find_Activator --
7810 --------------------
7812 function Find_Activator (Call : Node_Id) return Entity_Id is
7816 -- Climb the parent chain looking for a package [body] or a
7817 -- construct with a statement sequence.
7819 Par := Parent (Call);
7820 while Present (Par) loop
7821 if Nkind_In (Par, N_Package_Body, N_Package_Declaration) then
7822 return Defining_Entity (Par);
7824 elsif Nkind (Par) = N_Handled_Sequence_Of_Statements then
7825 return Defining_Entity (Parent (Par));
7828 Par := Parent (Par);
7836 Activator : constant Entity_Id := Find_Activator (N);
7838 -- Start of processing for Output_Activation_Call
7841 pragma Assert (Present (Activator));
7843 Error_Msg_NE ("\\ local tasks of & activated", Error_Nod, Activator);
7844 end Output_Activation_Call;
7850 procedure Output_Call (N : Node_Id; Target_Id : Entity_Id) is
7851 procedure Output_Accept_Alternative;
7852 pragma Inline (Output_Accept_Alternative);
7853 -- Emit a specific diagnostic message concerning an accept
7856 procedure Output_Call (Kind : String);
7857 pragma Inline (Output_Call);
7858 -- Emit a specific diagnostic message concerning a call of kind Kind
7860 procedure Output_Type_Actions (Action : String);
7861 pragma Inline (Output_Type_Actions);
7862 -- Emit a specific diagnostic message concerning action Action of a
7865 procedure Output_Verification_Call
7869 pragma Inline (Output_Verification_Call);
7870 -- Emit a specific diagnostic message concerning the verification of
7871 -- predicate Pred applied to related entity Id with kind Id_Kind.
7873 -------------------------------
7874 -- Output_Accept_Alternative --
7875 -------------------------------
7877 procedure Output_Accept_Alternative is
7878 Entry_Id : constant Entity_Id := Receiving_Entry (Target_Id);
7881 pragma Assert (Present (Entry_Id));
7883 Error_Msg_NE ("\\ entry & selected #", Error_Nod, Entry_Id);
7884 end Output_Accept_Alternative;
7890 procedure Output_Call (Kind : String) is
7892 Error_Msg_NE ("\\ " & Kind & " & called #", Error_Nod, Target_Id);
7895 -------------------------
7896 -- Output_Type_Actions --
7897 -------------------------
7899 procedure Output_Type_Actions (Action : String) is
7900 Typ : constant Entity_Id := First_Formal_Type (Target_Id);
7903 pragma Assert (Present (Typ));
7906 ("\\ " & Action & " actions for type & #", Error_Nod, Typ);
7907 end Output_Type_Actions;
7909 ------------------------------
7910 -- Output_Verification_Call --
7911 ------------------------------
7913 procedure Output_Verification_Call
7919 pragma Assert (Present (Id));
7922 ("\\ " & Pred & " of " & Id_Kind & " & verified #",
7924 end Output_Verification_Call;
7926 -- Start of processing for Output_Call
7929 Error_Msg_Sloc := Sloc (N);
7931 -- Accept alternative
7933 if Is_Accept_Alternative_Proc (Target_Id) then
7934 Output_Accept_Alternative;
7938 elsif Is_TSS (Target_Id, TSS_Deep_Adjust) then
7939 Output_Type_Actions ("adjustment");
7941 -- Default_Initial_Condition
7943 elsif Is_Default_Initial_Condition_Proc (Target_Id) then
7944 Output_Verification_Call
7945 (Pred => "Default_Initial_Condition",
7946 Id => First_Formal_Type (Target_Id),
7951 elsif Is_Protected_Entry (Target_Id) then
7952 Output_Call ("entry");
7954 -- Task entry calls are never processed because the entry being
7955 -- invoked does not have a corresponding "body", it has a select. A
7956 -- task entry call appears in the stack of active scenarios for the
7957 -- sole purpose of checking No_Entry_Calls_In_Elaboration_Code and
7960 elsif Is_Task_Entry (Target_Id) then
7965 elsif Is_TSS (Target_Id, TSS_Deep_Finalize) then
7966 Output_Type_Actions ("finalization");
7968 -- Calls to _Finalizer procedures must not appear in the output
7969 -- because this creates confusing noise.
7971 elsif Is_Finalizer_Proc (Target_Id) then
7974 -- Initial_Condition
7976 elsif Is_Initial_Condition_Proc (Target_Id) then
7977 Output_Verification_Call
7978 (Pred => "Initial_Condition",
7979 Id => Find_Enclosing_Scope (N),
7980 Id_Kind => "package");
7984 elsif Is_Init_Proc (Target_Id)
7985 or else Is_TSS (Target_Id, TSS_Deep_Initialize)
7987 Output_Type_Actions ("initialization");
7991 elsif Is_Invariant_Proc (Target_Id) then
7992 Output_Verification_Call
7993 (Pred => "invariants",
7994 Id => First_Formal_Type (Target_Id),
7997 -- Partial invariant calls must not appear in the output because this
7998 -- creates confusing noise. Note that a partial invariant is always
7999 -- invoked by the "full" invariant which is already placed on the
8002 elsif Is_Partial_Invariant_Proc (Target_Id) then
8007 elsif Is_Postconditions_Proc (Target_Id) then
8008 Output_Verification_Call
8009 (Pred => "postconditions",
8010 Id => Find_Enclosing_Scope (N),
8011 Id_Kind => "subprogram");
8013 -- Subprograms must come last because some of the previous cases fall
8014 -- under this category.
8016 elsif Ekind (Target_Id) = E_Function then
8017 Output_Call ("function");
8019 elsif Ekind (Target_Id) = E_Procedure then
8020 Output_Call ("procedure");
8023 pragma Assert (False);
8032 procedure Output_Header is
8033 Unit_Id : constant Entity_Id := Find_Top_Unit (Root_Scenario);
8036 if Ekind (Unit_Id) = E_Package then
8037 Error_Msg_NE ("\\ spec of unit & elaborated", Error_Nod, Unit_Id);
8039 elsif Ekind (Unit_Id) = E_Package_Body then
8040 Error_Msg_NE ("\\ body of unit & elaborated", Error_Nod, Unit_Id);
8043 Error_Msg_NE ("\\ in body of unit &", Error_Nod, Unit_Id);
8047 --------------------------
8048 -- Output_Instantiation --
8049 --------------------------
8051 procedure Output_Instantiation (N : Node_Id) is
8052 procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String);
8053 pragma Inline (Output_Instantiation);
8054 -- Emit a specific diagnostic message concerning an instantiation of
8055 -- generic unit Gen_Id. Kind denotes the kind of the instantiation.
8057 --------------------------
8058 -- Output_Instantiation --
8059 --------------------------
8061 procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String) is
8064 ("\\ " & Kind & " & instantiated as & #", Error_Nod, Gen_Id);
8065 end Output_Instantiation;
8070 Inst_Attrs : Instantiation_Attributes;
8071 Inst_Id : Entity_Id;
8074 -- Start of processing for Output_Instantiation
8077 Extract_Instantiation_Attributes
8082 Attrs => Inst_Attrs);
8084 Error_Msg_Node_2 := Inst_Id;
8085 Error_Msg_Sloc := Sloc (Inst);
8087 if Nkind (Inst) = N_Function_Instantiation then
8088 Output_Instantiation (Gen_Id, "function");
8090 elsif Nkind (Inst) = N_Package_Instantiation then
8091 Output_Instantiation (Gen_Id, "package");
8093 elsif Nkind (Inst) = N_Procedure_Instantiation then
8094 Output_Instantiation (Gen_Id, "procedure");
8097 pragma Assert (False);
8100 end Output_Instantiation;
8102 ---------------------------------------
8103 -- Output_SPARK_Refined_State_Pragma --
8104 ---------------------------------------
8106 procedure Output_SPARK_Refined_State_Pragma (N : Node_Id) is
8108 Error_Msg_Sloc := Sloc (N);
8109 Error_Msg_N ("\\ refinement constituents read #", Error_Nod);
8110 end Output_SPARK_Refined_State_Pragma;
8112 --------------------------------
8113 -- Output_Variable_Assignment --
8114 --------------------------------
8116 procedure Output_Variable_Assignment (N : Node_Id) is
8117 Var_Id : constant Entity_Id := Entity (Extract_Assignment_Name (N));
8120 Error_Msg_Sloc := Sloc (N);
8121 Error_Msg_NE ("\\ variable & assigned #", Error_Nod, Var_Id);
8122 end Output_Variable_Assignment;
8124 -------------------------------
8125 -- Output_Variable_Reference --
8126 -------------------------------
8128 procedure Output_Variable_Reference (N : Node_Id) is
8129 Dummy : Variable_Attributes;
8133 Extract_Variable_Reference_Attributes
8138 Error_Msg_Sloc := Sloc (N);
8141 Error_Msg_NE ("\\ variable & read #", Error_Nod, Var_Id);
8144 pragma Assert (False);
8147 end Output_Variable_Reference;
8151 package Stack renames Scenario_Stack;
8153 Dummy : Call_Attributes;
8156 Target_Id : Entity_Id;
8158 -- Start of processing for Output_Active_Scenarios
8161 -- Active scenarios are emitted only when the static model is in effect
8162 -- because there is an inherent order by which all these scenarios were
8163 -- reached from the declaration or library level.
8165 if not Static_Elaboration_Checks then
8171 for Index in Stack.First .. Stack.Last loop
8172 N := Stack.Table (Index);
8181 if Nkind (N) = N_Attribute_Reference then
8186 elsif Is_Suitable_Call (N) then
8187 Extract_Call_Attributes
8189 Target_Id => Target_Id,
8192 if Is_Activation_Proc (Target_Id) then
8193 Output_Activation_Call (N);
8195 Output_Call (N, Target_Id);
8200 elsif Is_Suitable_Instantiation (N) then
8201 Output_Instantiation (N);
8203 -- Pragma Refined_State
8205 elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
8206 Output_SPARK_Refined_State_Pragma (N);
8208 -- Variable assignments
8210 elsif Nkind (N) = N_Assignment_Statement then
8211 Output_Variable_Assignment (N);
8213 -- Variable references
8215 elsif Is_Suitable_Variable_Reference (N) then
8216 Output_Variable_Reference (N);
8219 pragma Assert (False);
8223 end Output_Active_Scenarios;
8225 -------------------------
8226 -- Pop_Active_Scenario --
8227 -------------------------
8229 procedure Pop_Active_Scenario (N : Node_Id) is
8230 Top : Node_Id renames Scenario_Stack.Table (Scenario_Stack.Last);
8233 pragma Assert (Top = N);
8234 Scenario_Stack.Decrement_Last;
8235 end Pop_Active_Scenario;
8237 --------------------------------
8238 -- Process_Activation_Generic --
8239 --------------------------------
8241 procedure Process_Activation_Generic
8243 Call_Attrs : Call_Attributes;
8244 In_Init_Cond : Boolean;
8245 In_Partial_Fin : Boolean;
8246 In_Task_Body : Boolean)
8248 procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id);
8249 -- Perform ABE checks and diagnostics for object Obj_Id with type Typ.
8250 -- Typ may be a task type or a composite type with at least one task
8253 procedure Process_Task_Objects (List : List_Id);
8254 -- Perform ABE checks and diagnostics for all task objects found in
8257 -------------------------
8258 -- Process_Task_Object --
8259 -------------------------
8261 procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id) is
8262 Base_Typ : constant Entity_Id := Base_Type (Typ);
8264 Comp_Id : Entity_Id;
8265 Task_Attrs : Task_Attributes;
8268 if Is_Task_Type (Typ) then
8269 Extract_Task_Attributes
8271 Attrs => Task_Attrs);
8273 Process_Single_Activation
8275 Call_Attrs => Call_Attrs,
8277 Task_Attrs => Task_Attrs,
8278 In_Init_Cond => In_Init_Cond,
8279 In_Partial_Fin => In_Partial_Fin,
8280 In_Task_Body => In_Task_Body);
8282 -- Examine the component type when the object is an array
8284 elsif Is_Array_Type (Typ) and then Has_Task (Base_Typ) then
8285 Process_Task_Object (Obj_Id, Component_Type (Typ));
8287 -- Examine individual component types when the object is a record
8289 elsif Is_Record_Type (Typ) and then Has_Task (Base_Typ) then
8290 Comp_Id := First_Component (Typ);
8291 while Present (Comp_Id) loop
8292 Process_Task_Object (Obj_Id, Etype (Comp_Id));
8293 Next_Component (Comp_Id);
8296 end Process_Task_Object;
8298 --------------------------
8299 -- Process_Task_Objects --
8300 --------------------------
8302 procedure Process_Task_Objects (List : List_Id) is
8304 Item_Id : Entity_Id;
8305 Item_Typ : Entity_Id;
8308 -- Examine the contents of the list looking for an object declaration
8309 -- of a task type or one that contains a task within.
8311 Item := First (List);
8312 while Present (Item) loop
8313 if Nkind (Item) = N_Object_Declaration then
8314 Item_Id := Defining_Entity (Item);
8315 Item_Typ := Etype (Item_Id);
8317 if Has_Task (Item_Typ) then
8318 Process_Task_Object (Item_Id, Item_Typ);
8324 end Process_Task_Objects;
8331 -- Start of processing for Process_Activation_Generic
8334 -- Nothing to do when the activation is a guaranteed ABE
8336 if Is_Known_Guaranteed_ABE (Call) then
8340 -- Find the proper context of the activation call where all task objects
8341 -- being activated are declared. This is usually the immediate parent of
8344 Context := Parent (Call);
8346 -- In the case of package bodies, the activation call is in the handled
8347 -- sequence of statements, but the task objects are in the declaration
8348 -- list of the body.
8350 if Nkind (Context) = N_Handled_Sequence_Of_Statements
8351 and then Nkind (Parent (Context)) = N_Package_Body
8353 Context := Parent (Context);
8356 -- Process all task objects defined in both the spec and body when the
8357 -- activation call precedes the "begin" of a package body.
8359 if Nkind (Context) = N_Package_Body then
8362 (Unit_Declaration_Node (Corresponding_Spec (Context)));
8364 Process_Task_Objects (Visible_Declarations (Spec));
8365 Process_Task_Objects (Private_Declarations (Spec));
8366 Process_Task_Objects (Declarations (Context));
8368 -- Process all task objects defined in the spec when the activation call
8369 -- appears at the end of a package spec.
8371 elsif Nkind (Context) = N_Package_Specification then
8372 Process_Task_Objects (Visible_Declarations (Context));
8373 Process_Task_Objects (Private_Declarations (Context));
8375 -- Otherwise the context of the activation is some construct with a
8376 -- declarative part. Note that the corresponding record type of a task
8377 -- type is controlled. Because of this, the finalization machinery must
8378 -- relocate the task object to the handled statements of the construct
8379 -- to perform proper finalization in case of an exception. Examine the
8380 -- statements of the construct rather than the declarations.
8383 pragma Assert (Nkind (Context) = N_Handled_Sequence_Of_Statements);
8385 Process_Task_Objects (Statements (Context));
8387 end Process_Activation_Generic;
8389 ------------------------------------
8390 -- Process_Conditional_ABE_Access --
8391 ------------------------------------
8393 procedure Process_Conditional_ABE_Access
8395 In_Init_Cond : Boolean;
8396 In_Partial_Fin : Boolean;
8397 In_Task_Body : Boolean)
8399 function Build_Access_Marker (Target_Id : Entity_Id) return Node_Id;
8400 pragma Inline (Build_Access_Marker);
8401 -- Create a suitable call marker which invokes target Target_Id
8403 -------------------------
8404 -- Build_Access_Marker --
8405 -------------------------
8407 function Build_Access_Marker (Target_Id : Entity_Id) return Node_Id is
8411 Marker := Make_Call_Marker (Sloc (Attr));
8413 -- Inherit relevant attributes from the attribute
8415 -- Performance note: parent traversal
8417 Set_Target (Marker, Target_Id);
8418 Set_Is_Declaration_Level_Node
8419 (Marker, Find_Enclosing_Level (Attr) = Declaration_Level);
8420 Set_Is_Dispatching_Call
8422 Set_Is_Elaboration_Checks_OK_Node
8423 (Marker, Is_Elaboration_Checks_OK_Node (Attr));
8425 (Marker, Comes_From_Source (Attr));
8426 Set_Is_SPARK_Mode_On_Node
8427 (Marker, Is_SPARK_Mode_On_Node (Attr));
8429 -- Partially insert the call marker into the tree by setting its
8432 Set_Parent (Marker, Attr);
8435 end Build_Access_Marker;
8439 Root : constant Node_Id := Root_Scenario;
8440 Target_Id : constant Entity_Id := Entity (Prefix (Attr));
8442 Target_Attrs : Target_Attributes;
8444 -- Start of processing for Process_Conditional_ABE_Access
8447 -- Output relevant information when switch -gnatel (info messages on
8448 -- implicit Elaborate[_All] pragmas) is in effect.
8450 if Elab_Info_Messages then
8452 ("info: access to & during elaboration", Attr, Target_Id);
8455 Extract_Target_Attributes
8456 (Target_Id => Target_Id,
8457 Attrs => Target_Attrs);
8459 -- Both the attribute and the corresponding body are in the same unit.
8460 -- The corresponding body must appear prior to the root scenario which
8461 -- started the recursive search. If this is not the case, then there is
8462 -- a potential ABE if the access value is used to call the subprogram.
8463 -- Emit a warning only when switch -gnatw.f (warnings on suspucious
8464 -- 'Access) is in effect.
8466 if Warn_On_Elab_Access
8467 and then Present (Target_Attrs.Body_Decl)
8468 and then In_Extended_Main_Code_Unit (Target_Attrs.Body_Decl)
8469 and then Earlier_In_Extended_Unit (Root, Target_Attrs.Body_Decl)
8471 Error_Msg_Name_1 := Attribute_Name (Attr);
8472 Error_Msg_NE ("??% attribute of & before body seen", Attr, Target_Id);
8473 Error_Msg_N ("\possible Program_Error on later references", Attr);
8475 Output_Active_Scenarios (Attr);
8478 -- Treat the attribute as an immediate invocation of the target when
8479 -- switch -gnatd.o (conservative elaboration order for indirect calls)
8480 -- is in effect. Note that the prior elaboration of the unit containing
8481 -- the target is ensured processing the corresponding call marker.
8483 if Debug_Flag_Dot_O then
8484 Process_Conditional_ABE
8485 (N => Build_Access_Marker (Target_Id),
8486 In_Init_Cond => In_Init_Cond,
8487 In_Partial_Fin => In_Partial_Fin,
8488 In_Task_Body => In_Task_Body);
8490 -- Otherwise ensure that the unit with the corresponding body is
8491 -- elaborated prior to the main unit.
8494 Ensure_Prior_Elaboration
8496 Unit_Id => Target_Attrs.Unit_Id,
8497 Prag_Nam => Name_Elaborate_All,
8498 In_Partial_Fin => In_Partial_Fin,
8499 In_Task_Body => In_Task_Body);
8501 end Process_Conditional_ABE_Access;
8503 ---------------------------------------------
8504 -- Process_Conditional_ABE_Activation_Impl --
8505 ---------------------------------------------
8507 procedure Process_Conditional_ABE_Activation_Impl
8509 Call_Attrs : Call_Attributes;
8511 Task_Attrs : Task_Attributes;
8512 In_Init_Cond : Boolean;
8513 In_Partial_Fin : Boolean;
8514 In_Task_Body : Boolean)
8516 Check_OK : constant Boolean :=
8517 not Is_Ignored_Ghost_Entity (Obj_Id)
8518 and then not Task_Attrs.Ghost_Mode_Ignore
8519 and then Is_Elaboration_Checks_OK_Id (Obj_Id)
8520 and then Task_Attrs.Elab_Checks_OK;
8521 -- A run-time ABE check may be installed only when the object and the
8522 -- task type have active elaboration checks, and both are not ignored
8523 -- Ghost constructs.
8525 Root : constant Node_Id := Root_Scenario;
8528 -- Output relevant information when switch -gnatel (info messages on
8529 -- implicit Elaborate[_All] pragmas) is in effect.
8531 if Elab_Info_Messages then
8533 ("info: activation of & during elaboration", Call, Obj_Id);
8536 -- Nothing to do when the activation is a guaranteed ABE
8538 if Is_Known_Guaranteed_ABE (Call) then
8541 -- Nothing to do when the root scenario appears at the declaration
8542 -- level and the task is in the same unit, but outside this context.
8544 -- task type Task_Typ; -- task declaration
8546 -- procedure Proc is
8547 -- function A ... is
8549 -- if Some_Condition then
8553 -- <activation call> -- activation site
8558 -- X : ... := A; -- root scenario
8561 -- task body Task_Typ is
8565 -- In the example above, the context of X is the declarative list of
8566 -- Proc. The "elaboration" of X may reach the activation of T whose body
8567 -- is defined outside of X's context. The task body is relevant only
8568 -- when Proc is invoked, but this happens only in "normal" elaboration,
8569 -- therefore the task body must not be considered if this is not the
8572 -- Performance note: parent traversal
8574 elsif Is_Up_Level_Target (Task_Attrs.Task_Decl) then
8577 -- Nothing to do when the activation is ABE-safe
8581 -- task type Task_Typ;
8584 -- package body Gen is
8585 -- task body Task_Typ is
8592 -- procedure Main is
8593 -- package Nested is
8597 -- package body Nested is
8598 -- package Inst is new Gen;
8599 -- T : Inst.Task_Typ;
8601 -- <activation call> -- safe activation
8605 elsif Is_Safe_Activation (Call, Task_Attrs.Task_Decl) then
8607 -- Note that the task body must still be examined for any nested
8612 -- The activation call and the task body are both in the main unit
8614 elsif Present (Task_Attrs.Body_Decl)
8615 and then In_Extended_Main_Code_Unit (Task_Attrs.Body_Decl)
8617 -- If the root scenario appears prior to the task body, then this is
8618 -- a possible ABE with respect to the root scenario.
8620 -- task type Task_Typ;
8622 -- function A ... is
8624 -- if Some_Condition then
8630 -- package body Pack is
8633 -- <activation call> -- activation of T
8638 -- X : ... := A; -- root scenario
8640 -- task body Task_Typ is -- task body
8644 -- Y : ... := A; -- root scenario
8646 -- IMPORTANT: The activation of T is a possible ABE for X, but
8647 -- not for Y. Intalling an unconditional ABE raise prior to the
8648 -- activation call would be wrong as it will fail for Y as well
8649 -- but in Y's case the activation of T is never an ABE.
8651 if Earlier_In_Extended_Unit (Root, Task_Attrs.Body_Decl) then
8653 -- Do not emit any ABE diagnostics when the activation occurs in
8654 -- a partial finalization context because this leads to confusing
8657 if In_Partial_Fin then
8660 -- ABE diagnostics are emitted only in the static model because
8661 -- there is a well-defined order to visiting scenarios. Without
8662 -- this order diagnostics appear jumbled and result in unwanted
8665 elsif Static_Elaboration_Checks then
8666 Error_Msg_Sloc := Sloc (Call);
8668 ("??task & will be activated # before elaboration of its "
8671 ("\Program_Error may be raised at run time", Obj_Id);
8673 Output_Active_Scenarios (Obj_Id);
8676 -- Install a conditional run-time ABE check to verify that the
8677 -- task body has been elaborated prior to the activation call.
8683 Target_Id => Task_Attrs.Spec_Id,
8684 Target_Decl => Task_Attrs.Task_Decl,
8685 Target_Body => Task_Attrs.Body_Decl);
8689 -- Otherwise the task body is not available in this compilation or it
8690 -- resides in an external unit. Install a run-time ABE check to verify
8691 -- that the task body has been elaborated prior to the activation call
8692 -- when the dynamic model is in effect.
8694 elsif Dynamic_Elaboration_Checks and then Check_OK then
8698 Id => Task_Attrs.Unit_Id);
8701 -- Both the activation call and task type are subject to SPARK_Mode
8702 -- On, this triggers the SPARK rules for task activation. Compared to
8703 -- calls and instantiations, task activation in SPARK does not require
8704 -- the presence of Elaborate[_All] pragmas in case the task type is
8705 -- defined outside the main unit. This is because SPARK utilizes a
8706 -- special policy which activates all tasks after the main unit has
8707 -- finished its elaboration.
8709 if Call_Attrs.SPARK_Mode_On and Task_Attrs.SPARK_Mode_On then
8712 -- Otherwise the Ada rules are in effect. Ensure that the unit with the
8713 -- task body is elaborated prior to the main unit.
8716 Ensure_Prior_Elaboration
8718 Unit_Id => Task_Attrs.Unit_Id,
8719 Prag_Nam => Name_Elaborate_All,
8720 In_Partial_Fin => In_Partial_Fin,
8721 In_Task_Body => In_Task_Body);
8725 (N => Task_Attrs.Body_Decl,
8726 In_Init_Cond => In_Init_Cond,
8727 In_Partial_Fin => In_Partial_Fin,
8728 In_Task_Body => True);
8729 end Process_Conditional_ABE_Activation_Impl;
8731 procedure Process_Conditional_ABE_Activation is
8732 new Process_Activation_Generic (Process_Conditional_ABE_Activation_Impl);
8734 ----------------------------------
8735 -- Process_Conditional_ABE_Call --
8736 ----------------------------------
8738 procedure Process_Conditional_ABE_Call
8740 Call_Attrs : Call_Attributes;
8741 Target_Id : Entity_Id;
8742 In_Init_Cond : Boolean;
8743 In_Partial_Fin : Boolean;
8744 In_Task_Body : Boolean)
8746 function In_Initialization_Context (N : Node_Id) return Boolean;
8747 -- Determine whether arbitrary node N appears within a type init proc,
8748 -- primitive [Deep_]Initialize, or a block created for initialization
8751 function Is_Partial_Finalization_Proc return Boolean;
8752 pragma Inline (Is_Partial_Finalization_Proc);
8753 -- Determine whether call Call with target Target_Id invokes a partial
8754 -- finalization procedure.
8756 -------------------------------
8757 -- In_Initialization_Context --
8758 -------------------------------
8760 function In_Initialization_Context (N : Node_Id) return Boolean is
8762 Spec_Id : Entity_Id;
8765 -- Climb the parent chain looking for initialization actions
8768 while Present (Par) loop
8770 -- A block may be part of the initialization actions of a default
8771 -- initialized object.
8773 if Nkind (Par) = N_Block_Statement
8774 and then Is_Initialization_Block (Par)
8778 -- A subprogram body may denote an initialization routine
8780 elsif Nkind (Par) = N_Subprogram_Body then
8781 Spec_Id := Unique_Defining_Entity (Par);
8783 -- The current subprogram body denotes a type init proc or
8784 -- primitive [Deep_]Initialize.
8786 if Is_Init_Proc (Spec_Id)
8787 or else Is_Controlled_Proc (Spec_Id, Name_Initialize)
8788 or else Is_TSS (Spec_Id, TSS_Deep_Initialize)
8793 -- Prevent the search from going too far
8795 elsif Is_Body_Or_Package_Declaration (Par) then
8799 Par := Parent (Par);
8803 end In_Initialization_Context;
8805 ----------------------------------
8806 -- Is_Partial_Finalization_Proc --
8807 ----------------------------------
8809 function Is_Partial_Finalization_Proc return Boolean is
8811 -- To qualify, the target must denote primitive [Deep_]Finalize or a
8812 -- finalizer procedure, and the call must appear in an initialization
8816 (Is_Controlled_Proc (Target_Id, Name_Finalize)
8817 or else Is_Finalizer_Proc (Target_Id)
8818 or else Is_TSS (Target_Id, TSS_Deep_Finalize))
8819 and then In_Initialization_Context (Call);
8820 end Is_Partial_Finalization_Proc;
8824 Init_Cond_On : Boolean;
8825 Partial_Fin_On : Boolean;
8826 SPARK_Rules_On : Boolean;
8827 Target_Attrs : Target_Attributes;
8829 -- Start of processing for Process_Conditional_ABE_Call
8832 Extract_Target_Attributes
8833 (Target_Id => Target_Id,
8834 Attrs => Target_Attrs);
8836 -- The call occurs in an initial condition context when a prior
8837 -- scenario is already in that mode, or when the target denotes
8838 -- an Initial_Condition procedure.
8841 In_Init_Cond or else Is_Initial_Condition_Proc (Target_Id);
8843 -- The call occurs in a partial finalization context when a prior
8844 -- scenario is already in that mode, or when the target denotes a
8845 -- [Deep_]Finalize primitive or a finalizer within an initialization
8848 Partial_Fin_On := In_Partial_Fin or else Is_Partial_Finalization_Proc;
8850 -- The SPARK rules are in effect when both the call and target are
8851 -- subject to SPARK_Mode On.
8854 Call_Attrs.SPARK_Mode_On and Target_Attrs.SPARK_Mode_On;
8856 -- Output relevant information when switch -gnatel (info messages on
8857 -- implicit Elaborate[_All] pragmas) is in effect.
8859 if Elab_Info_Messages then
8862 Target_Id => Target_Id,
8864 In_SPARK => SPARK_Rules_On);
8867 -- Check whether the invocation of an entry clashes with an existing
8870 if Is_Protected_Entry (Target_Id) then
8871 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
8873 elsif Is_Task_Entry (Target_Id) then
8874 Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call);
8876 -- Task entry calls are never processed because the entry being
8877 -- invoked does not have a corresponding "body", it has a select.
8882 -- Nothing to do when the call is a guaranteed ABE
8884 if Is_Known_Guaranteed_ABE (Call) then
8887 -- Nothing to do when the root scenario appears at the declaration level
8888 -- and the target is in the same unit, but outside this context.
8890 -- function B ...; -- target declaration
8892 -- procedure Proc is
8893 -- function A ... is
8895 -- if Some_Condition then
8896 -- return B; -- call site
8900 -- X : ... := A; -- root scenario
8903 -- function B ... is
8907 -- In the example above, the context of X is the declarative region of
8908 -- Proc. The "elaboration" of X may eventually reach B which is defined
8909 -- outside of X's context. B is relevant only when Proc is invoked, but
8910 -- this happens only by means of "normal" elaboration, therefore B must
8911 -- not be considered if this is not the case.
8913 -- Performance note: parent traversal
8915 elsif Is_Up_Level_Target (Target_Attrs.Spec_Decl) then
8918 -- The SPARK rules are in effect. Note that -gnatd.v (enforce SPARK
8919 -- elaboration rules in SPARK code) is intentionally not taken into
8920 -- account here because Process_Conditional_ABE_Call_SPARK has two
8921 -- separate modes of operation.
8923 elsif SPARK_Rules_On then
8924 Process_Conditional_ABE_Call_SPARK
8926 Target_Id => Target_Id,
8927 Target_Attrs => Target_Attrs,
8928 In_Init_Cond => Init_Cond_On,
8929 In_Partial_Fin => Partial_Fin_On,
8930 In_Task_Body => In_Task_Body);
8932 -- Otherwise the Ada rules are in effect
8935 Process_Conditional_ABE_Call_Ada
8937 Call_Attrs => Call_Attrs,
8938 Target_Id => Target_Id,
8939 Target_Attrs => Target_Attrs,
8940 In_Partial_Fin => Partial_Fin_On,
8941 In_Task_Body => In_Task_Body);
8944 -- Inspect the target body (and barried function) for other suitable
8945 -- elaboration scenarios.
8948 (N => Target_Attrs.Body_Barf,
8949 In_Init_Cond => Init_Cond_On,
8950 In_Partial_Fin => Partial_Fin_On,
8951 In_Task_Body => In_Task_Body);
8954 (N => Target_Attrs.Body_Decl,
8955 In_Init_Cond => Init_Cond_On,
8956 In_Partial_Fin => Partial_Fin_On,
8957 In_Task_Body => In_Task_Body);
8958 end Process_Conditional_ABE_Call;
8960 --------------------------------------
8961 -- Process_Conditional_ABE_Call_Ada --
8962 --------------------------------------
8964 procedure Process_Conditional_ABE_Call_Ada
8966 Call_Attrs : Call_Attributes;
8967 Target_Id : Entity_Id;
8968 Target_Attrs : Target_Attributes;
8969 In_Partial_Fin : Boolean;
8970 In_Task_Body : Boolean)
8972 Check_OK : constant Boolean :=
8973 not Call_Attrs.Ghost_Mode_Ignore
8974 and then not Target_Attrs.Ghost_Mode_Ignore
8975 and then Call_Attrs.Elab_Checks_OK
8976 and then Target_Attrs.Elab_Checks_OK;
8977 -- A run-time ABE check may be installed only when both the call and the
8978 -- target have active elaboration checks, and both are not ignored Ghost
8981 Root : constant Node_Id := Root_Scenario;
8984 -- Nothing to do for an Ada dispatching call because there are no ABE
8985 -- diagnostics for either models. ABE checks for the dynamic model are
8986 -- handled by Install_Primitive_Elaboration_Check.
8988 if Call_Attrs.Is_Dispatching then
8991 -- Nothing to do when the call is ABE-safe
8994 -- function Gen ...;
8996 -- function Gen ... is
9002 -- procedure Main is
9003 -- function Inst is new Gen;
9004 -- X : ... := Inst; -- safe call
9007 elsif Is_Safe_Call (Call, Target_Attrs) then
9010 -- The call and the target body are both in the main unit
9012 elsif Present (Target_Attrs.Body_Decl)
9013 and then In_Extended_Main_Code_Unit (Target_Attrs.Body_Decl)
9015 -- If the root scenario appears prior to the target body, then this
9016 -- is a possible ABE with respect to the root scenario.
9020 -- function A ... is
9022 -- if Some_Condition then
9023 -- return B; -- call site
9027 -- X : ... := A; -- root scenario
9029 -- function B ... is -- target body
9033 -- Y : ... := A; -- root scenario
9035 -- IMPORTANT: The call to B from A is a possible ABE for X, but not
9036 -- for Y. Installing an unconditional ABE raise prior to the call to
9037 -- B would be wrong as it will fail for Y as well, but in Y's case
9038 -- the call to B is never an ABE.
9040 if Earlier_In_Extended_Unit (Root, Target_Attrs.Body_Decl) then
9042 -- Do not emit any ABE diagnostics when the call occurs in a
9043 -- partial finalization context because this leads to confusing
9046 if In_Partial_Fin then
9049 -- ABE diagnostics are emitted only in the static model because
9050 -- there is a well-defined order to visiting scenarios. Without
9051 -- this order diagnostics appear jumbled and result in unwanted
9054 elsif Static_Elaboration_Checks then
9056 ("??cannot call & before body seen", Call, Target_Id);
9057 Error_Msg_N ("\Program_Error may be raised at run time", Call);
9059 Output_Active_Scenarios (Call);
9062 -- Install a conditional run-time ABE check to verify that the
9063 -- target body has been elaborated prior to the call.
9069 Target_Id => Target_Attrs.Spec_Id,
9070 Target_Decl => Target_Attrs.Spec_Decl,
9071 Target_Body => Target_Attrs.Body_Decl);
9075 -- Otherwise the target body is not available in this compilation or it
9076 -- resides in an external unit. Install a run-time ABE check to verify
9077 -- that the target body has been elaborated prior to the call site when
9078 -- the dynamic model is in effect.
9080 elsif Dynamic_Elaboration_Checks and then Check_OK then
9084 Id => Target_Attrs.Unit_Id);
9087 -- Ensure that the unit with the target body is elaborated prior to the
9088 -- main unit. The implicit Elaborate[_All] is generated only when the
9089 -- call has elaboration checks enabled. This behaviour parallels that of
9090 -- the old ABE mechanism.
9092 if Call_Attrs.Elab_Checks_OK then
9093 Ensure_Prior_Elaboration
9095 Unit_Id => Target_Attrs.Unit_Id,
9096 Prag_Nam => Name_Elaborate_All,
9097 In_Partial_Fin => In_Partial_Fin,
9098 In_Task_Body => In_Task_Body);
9100 end Process_Conditional_ABE_Call_Ada;
9102 ----------------------------------------
9103 -- Process_Conditional_ABE_Call_SPARK --
9104 ----------------------------------------
9106 procedure Process_Conditional_ABE_Call_SPARK
9108 Target_Id : Entity_Id;
9109 Target_Attrs : Target_Attributes;
9110 In_Init_Cond : Boolean;
9111 In_Partial_Fin : Boolean;
9112 In_Task_Body : Boolean)
9117 -- The call and the target body are both in the main unit
9119 if Present (Target_Attrs.Body_Decl)
9120 and then In_Extended_Main_Code_Unit (Target_Attrs.Body_Decl)
9122 -- If the call appears prior to the target body, then the call must
9123 -- appear within the early call region of the target body.
9127 -- X : ... := B; -- call site
9129 -- <preelaborable construct 1> --+
9130 -- ... | early call region
9131 -- <preelaborable construct N> --+
9133 -- function B ... is -- target body
9137 -- When the call to B is not nested within some other scenario, the
9138 -- call is automatically illegal because it can never appear in the
9139 -- early call region of B's body. This is equivalent to a guaranteed
9142 -- <preelaborable construct 1> --+
9144 -- function B ...; |
9146 -- function A ... is |
9147 -- begin | early call region
9148 -- if Some_Condition then
9149 -- return B; -- call site
9153 -- <preelaborable construct N> --+
9155 -- function B ... is -- target body
9159 -- When the call to B is nested within some other scenario, the call
9160 -- is always ABE-safe. It is not immediately obvious why this is the
9161 -- case. The elaboration safety follows from the early call region
9162 -- rule being applied to ALL calls preceding their associated bodies.
9164 -- In the example above, the call to B is safe as long as the call to
9165 -- A is safe. There are several cases to consider:
9171 -- function A ... is
9173 -- if Some_Condition then
9179 -- function B ... is
9183 -- * Call 1 - This call is either nested within some scenario or not,
9184 -- which falls under the two general cases outlined above.
9186 -- * Call 2 - This is the same case as Call 1.
9188 -- * Call 3 - The placement of this call limits the range of B's
9189 -- early call region unto call 3, therefore the call to B is no
9190 -- longer within the early call region of B's body, making it ABE-
9191 -- unsafe and therefore illegal.
9193 if Earlier_In_Extended_Unit (Call, Target_Attrs.Body_Decl) then
9195 -- Do not emit any ABE diagnostics when the call occurs in an
9196 -- initial condition context because this leads to incorrect
9199 if In_Init_Cond then
9202 -- Do not emit any ABE diagnostics when the call occurs in a
9203 -- partial finalization context because this leads to confusing
9206 elsif In_Partial_Fin then
9209 -- ABE diagnostics are emitted only in the static model because
9210 -- there is a well-defined order to visiting scenarios. Without
9211 -- this order diagnostics appear jumbled and result in unwanted
9214 elsif Static_Elaboration_Checks then
9216 -- Ensure that a call which textually precedes the subprogram
9217 -- body it invokes appears within the early call region of the
9220 -- IMPORTANT: This check must always be performed even when
9221 -- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is
9222 -- not specified because the static model cannot guarantee the
9223 -- absence of elaboration issues in the presence of dispatching
9226 Region := Find_Early_Call_Region (Target_Attrs.Body_Decl);
9228 if Earlier_In_Extended_Unit (Call, Region) then
9230 ("call must appear within early call region of subprogram "
9231 & "body & (SPARK RM 7.7(3))", Call, Target_Id);
9233 Error_Msg_Sloc := Sloc (Region);
9234 Error_Msg_N ("\region starts #", Call);
9236 Error_Msg_Sloc := Sloc (Target_Attrs.Body_Decl);
9237 Error_Msg_N ("\region ends #", Call);
9239 Output_Active_Scenarios (Call);
9243 -- Otherwise the call appears after the target body. The call is
9244 -- ABE-safe as a consequence of applying the early call region rule
9245 -- to ALL calls preceding their associated bodies.
9252 -- A call to a source target or to a target which emulates Ada or SPARK
9253 -- semantics imposes an Elaborate_All requirement on the context of the
9254 -- main unit. Determine whether the context has a pragma strong enough
9255 -- to meet the requirement.
9257 -- IMPORTANT: This check must be performed only when -gnatd.v (enforce
9258 -- SPARK elaboration rules in SPARK code) is active because the static
9259 -- model can ensure the prior elaboration of the unit which contains a
9260 -- body by installing an implicit Elaborate[_All] pragma.
9262 if Debug_Flag_Dot_V then
9263 if Target_Attrs.From_Source
9264 or else Is_Ada_Semantic_Target (Target_Id)
9265 or else Is_SPARK_Semantic_Target (Target_Id)
9267 Meet_Elaboration_Requirement
9269 Target_Id => Target_Id,
9270 Req_Nam => Name_Elaborate_All);
9273 -- Otherwise ensure that the unit with the target body is elaborated
9274 -- prior to the main unit.
9277 Ensure_Prior_Elaboration
9279 Unit_Id => Target_Attrs.Unit_Id,
9280 Prag_Nam => Name_Elaborate_All,
9281 In_Partial_Fin => In_Partial_Fin,
9282 In_Task_Body => In_Task_Body);
9284 end Process_Conditional_ABE_Call_SPARK;
9286 -------------------------------------------
9287 -- Process_Conditional_ABE_Instantiation --
9288 -------------------------------------------
9290 procedure Process_Conditional_ABE_Instantiation
9291 (Exp_Inst : Node_Id;
9292 In_Partial_Fin : Boolean;
9293 In_Task_Body : Boolean)
9295 Gen_Attrs : Target_Attributes;
9298 Inst_Attrs : Instantiation_Attributes;
9299 Inst_Id : Entity_Id;
9301 SPARK_Rules_On : Boolean;
9302 -- This flag is set when the SPARK rules are in effect
9305 Extract_Instantiation_Attributes
9306 (Exp_Inst => Exp_Inst,
9310 Attrs => Inst_Attrs);
9312 Extract_Target_Attributes (Gen_Id, Gen_Attrs);
9314 -- The SPARK rules are in effect when both the instantiation and generic
9315 -- are subject to SPARK_Mode On.
9317 SPARK_Rules_On := Inst_Attrs.SPARK_Mode_On and Gen_Attrs.SPARK_Mode_On;
9319 -- Output relevant information when switch -gnatel (info messages on
9320 -- implicit Elaborate[_All] pragmas) is in effect.
9322 if Elab_Info_Messages then
9327 In_SPARK => SPARK_Rules_On);
9330 -- Nothing to do when the instantiation is a guaranteed ABE
9332 if Is_Known_Guaranteed_ABE (Inst) then
9335 -- Nothing to do when the root scenario appears at the declaration level
9336 -- and the generic is in the same unit, but outside this context.
9339 -- procedure Gen is ...; -- generic declaration
9341 -- procedure Proc is
9342 -- function A ... is
9344 -- if Some_Condition then
9346 -- procedure I is new Gen; -- instantiation site
9351 -- X : ... := A; -- root scenario
9358 -- In the example above, the context of X is the declarative region of
9359 -- Proc. The "elaboration" of X may eventually reach Gen which appears
9360 -- outside of X's context. Gen is relevant only when Proc is invoked,
9361 -- but this happens only by means of "normal" elaboration, therefore
9362 -- Gen must not be considered if this is not the case.
9364 -- Performance note: parent traversal
9366 elsif Is_Up_Level_Target (Gen_Attrs.Spec_Decl) then
9369 -- The SPARK rules are in effect
9371 elsif SPARK_Rules_On then
9372 Process_Conditional_ABE_Instantiation_SPARK
9375 Gen_Attrs => Gen_Attrs,
9376 In_Partial_Fin => In_Partial_Fin,
9377 In_Task_Body => In_Task_Body);
9379 -- Otherwise the Ada rules are in effect, or SPARK code is allowed to
9380 -- violate the SPARK rules.
9383 Process_Conditional_ABE_Instantiation_Ada
9384 (Exp_Inst => Exp_Inst,
9386 Inst_Attrs => Inst_Attrs,
9388 Gen_Attrs => Gen_Attrs,
9389 In_Partial_Fin => In_Partial_Fin,
9390 In_Task_Body => In_Task_Body);
9392 end Process_Conditional_ABE_Instantiation;
9394 -----------------------------------------------
9395 -- Process_Conditional_ABE_Instantiation_Ada --
9396 -----------------------------------------------
9398 procedure Process_Conditional_ABE_Instantiation_Ada
9399 (Exp_Inst : Node_Id;
9401 Inst_Attrs : Instantiation_Attributes;
9403 Gen_Attrs : Target_Attributes;
9404 In_Partial_Fin : Boolean;
9405 In_Task_Body : Boolean)
9407 Check_OK : constant Boolean :=
9408 not Inst_Attrs.Ghost_Mode_Ignore
9409 and then not Gen_Attrs.Ghost_Mode_Ignore
9410 and then Inst_Attrs.Elab_Checks_OK
9411 and then Gen_Attrs.Elab_Checks_OK;
9412 -- A run-time ABE check may be installed only when both the instance and
9413 -- the generic have active elaboration checks and both are not ignored
9414 -- Ghost constructs.
9416 Root : constant Node_Id := Root_Scenario;
9419 -- Nothing to do when the instantiation is ABE-safe
9426 -- package body Gen is
9431 -- procedure Main is
9432 -- package Inst is new Gen (ABE); -- safe instantiation
9435 if Is_Safe_Instantiation (Inst, Gen_Attrs) then
9438 -- The instantiation and the generic body are both in the main unit
9440 elsif Present (Gen_Attrs.Body_Decl)
9441 and then In_Extended_Main_Code_Unit (Gen_Attrs.Body_Decl)
9443 -- If the root scenario appears prior to the generic body, then this
9444 -- is a possible ABE with respect to the root scenario.
9451 -- function A ... is
9453 -- if Some_Condition then
9455 -- package Inst is new Gen; -- instantiation site
9459 -- X : ... := A; -- root scenario
9461 -- package body Gen is -- generic body
9465 -- Y : ... := A; -- root scenario
9467 -- IMPORTANT: The instantiation of Gen is a possible ABE for X, but
9468 -- not for Y. Installing an unconditional ABE raise prior to the
9469 -- instance site would be wrong as it will fail for Y as well, but in
9470 -- Y's case the instantiation of Gen is never an ABE.
9472 if Earlier_In_Extended_Unit (Root, Gen_Attrs.Body_Decl) then
9474 -- Do not emit any ABE diagnostics when the instantiation occurs
9475 -- in partial finalization context because this leads to unwanted
9478 if In_Partial_Fin then
9481 -- ABE diagnostics are emitted only in the static model because
9482 -- there is a well-defined order to visiting scenarios. Without
9483 -- this order diagnostics appear jumbled and result in unwanted
9486 elsif Static_Elaboration_Checks then
9488 ("??cannot instantiate & before body seen", Inst, Gen_Id);
9489 Error_Msg_N ("\Program_Error may be raised at run time", Inst);
9491 Output_Active_Scenarios (Inst);
9494 -- Install a conditional run-time ABE check to verify that the
9495 -- generic body has been elaborated prior to the instantiation.
9500 Ins_Nod => Exp_Inst,
9501 Target_Id => Gen_Attrs.Spec_Id,
9502 Target_Decl => Gen_Attrs.Spec_Decl,
9503 Target_Body => Gen_Attrs.Body_Decl);
9507 -- Otherwise the generic body is not available in this compilation or it
9508 -- resides in an external unit. Install a run-time ABE check to verify
9509 -- that the generic body has been elaborated prior to the instantiation
9510 -- when the dynamic model is in effect.
9512 elsif Dynamic_Elaboration_Checks and then Check_OK then
9515 Ins_Nod => Exp_Inst,
9516 Id => Gen_Attrs.Unit_Id);
9519 -- Ensure that the unit with the generic body is elaborated prior to
9520 -- the main unit. No implicit pragma Elaborate is generated if the
9521 -- instantiation has elaboration checks suppressed. This behaviour
9522 -- parallels that of the old ABE mechanism.
9524 if Inst_Attrs.Elab_Checks_OK then
9525 Ensure_Prior_Elaboration
9527 Unit_Id => Gen_Attrs.Unit_Id,
9528 Prag_Nam => Name_Elaborate,
9529 In_Partial_Fin => In_Partial_Fin,
9530 In_Task_Body => In_Task_Body);
9532 end Process_Conditional_ABE_Instantiation_Ada;
9534 -------------------------------------------------
9535 -- Process_Conditional_ABE_Instantiation_SPARK --
9536 -------------------------------------------------
9538 procedure Process_Conditional_ABE_Instantiation_SPARK
9541 Gen_Attrs : Target_Attributes;
9542 In_Partial_Fin : Boolean;
9543 In_Task_Body : Boolean)
9548 -- A source instantiation imposes an Elaborate[_All] requirement on the
9549 -- context of the main unit. Determine whether the context has a pragma
9550 -- strong enough to meet the requirement. The check is orthogonal to the
9551 -- ABE ramifications of the instantiation.
9553 -- IMPORTANT: This check must be performed only when -gnatd.v (enforce
9554 -- SPARK elaboration rules in SPARK code) is active because the static
9555 -- model can ensure the prior elaboration of the unit which contains a
9556 -- body by installing an implicit Elaborate[_All] pragma.
9558 if Debug_Flag_Dot_V then
9559 if Nkind (Inst) = N_Package_Instantiation then
9560 Req_Nam := Name_Elaborate_All;
9562 Req_Nam := Name_Elaborate;
9565 Meet_Elaboration_Requirement
9567 Target_Id => Gen_Id,
9568 Req_Nam => Req_Nam);
9570 -- Otherwise ensure that the unit with the target body is elaborated
9571 -- prior to the main unit.
9574 Ensure_Prior_Elaboration
9576 Unit_Id => Gen_Attrs.Unit_Id,
9577 Prag_Nam => Name_Elaborate,
9578 In_Partial_Fin => In_Partial_Fin,
9579 In_Task_Body => In_Task_Body);
9581 end Process_Conditional_ABE_Instantiation_SPARK;
9583 -------------------------------------------------
9584 -- Process_Conditional_ABE_Variable_Assignment --
9585 -------------------------------------------------
9587 procedure Process_Conditional_ABE_Variable_Assignment (Asmt : Node_Id) is
9588 Var_Id : constant Entity_Id := Entity (Extract_Assignment_Name (Asmt));
9589 Prag : constant Node_Id := SPARK_Pragma (Var_Id);
9591 SPARK_Rules_On : Boolean;
9592 -- This flag is set when the SPARK rules are in effect
9595 -- The SPARK rules are in effect when both the assignment and the
9596 -- variable are subject to SPARK_Mode On.
9600 and then Get_SPARK_Mode_From_Annotation (Prag) = On
9601 and then Is_SPARK_Mode_On_Node (Asmt);
9603 -- Output relevant information when switch -gnatel (info messages on
9604 -- implicit Elaborate[_All] pragmas) is in effect.
9606 if Elab_Info_Messages then
9608 (Msg => "assignment to & during elaboration",
9612 In_SPARK => SPARK_Rules_On);
9615 -- The SPARK rules are in effect. These rules are applied regardless of
9616 -- whether -gnatd.v (enforce SPARK elaboration rules in SPARK code) is
9617 -- in effect because the static model cannot ensure safe assignment of
9620 if SPARK_Rules_On then
9621 Process_Conditional_ABE_Variable_Assignment_SPARK
9625 -- Otherwise the Ada rules are in effect
9628 Process_Conditional_ABE_Variable_Assignment_Ada
9632 end Process_Conditional_ABE_Variable_Assignment;
9634 -----------------------------------------------------
9635 -- Process_Conditional_ABE_Variable_Assignment_Ada --
9636 -----------------------------------------------------
9638 procedure Process_Conditional_ABE_Variable_Assignment_Ada
9642 Var_Decl : constant Node_Id := Declaration_Node (Var_Id);
9643 Spec_Id : constant Entity_Id := Find_Top_Unit (Var_Decl);
9646 -- Emit a warning when an uninitialized variable declared in a package
9647 -- spec without a pragma Elaborate_Body is initialized by elaboration
9648 -- code within the corresponding body.
9650 if not Warnings_Off (Var_Id)
9651 and then not Is_Initialized (Var_Decl)
9652 and then not Has_Pragma_Elaborate_Body (Spec_Id)
9654 -- Generate an implicit Elaborate_Body in the spec
9656 Set_Elaborate_Body_Desirable (Spec_Id);
9659 ("??variable & can be accessed by clients before this "
9660 & "initialization", Asmt, Var_Id);
9663 ("\add pragma ""Elaborate_Body"" to spec & to ensure proper "
9664 & "initialization", Asmt, Spec_Id);
9666 Output_Active_Scenarios (Asmt);
9668 end Process_Conditional_ABE_Variable_Assignment_Ada;
9670 -------------------------------------------------------
9671 -- Process_Conditional_ABE_Variable_Assignment_SPARK --
9672 -------------------------------------------------------
9674 procedure Process_Conditional_ABE_Variable_Assignment_SPARK
9678 Var_Decl : constant Node_Id := Declaration_Node (Var_Id);
9679 Spec_Id : constant Entity_Id := Find_Top_Unit (Var_Decl);
9682 -- Emit an error when an initialized variable declared in a package spec
9683 -- without pragma Elaborate_Body is further modified by elaboration code
9684 -- within the corresponding body.
9686 if Is_Initialized (Var_Decl)
9687 and then not Has_Pragma_Elaborate_Body (Spec_Id)
9690 ("variable & modified by elaboration code in package body",
9694 ("\add pragma ""Elaborate_Body"" to spec & to ensure full "
9695 & "initialization", Asmt, Spec_Id);
9697 Output_Active_Scenarios (Asmt);
9699 end Process_Conditional_ABE_Variable_Assignment_SPARK;
9701 ------------------------------------------------
9702 -- Process_Conditional_ABE_Variable_Reference --
9703 ------------------------------------------------
9705 procedure Process_Conditional_ABE_Variable_Reference (Ref : Node_Id) is
9706 Var_Attrs : Variable_Attributes;
9710 Extract_Variable_Reference_Attributes
9713 Attrs => Var_Attrs);
9715 if Is_Read (Ref) then
9716 Process_Conditional_ABE_Variable_Reference_Read
9719 Attrs => Var_Attrs);
9721 end Process_Conditional_ABE_Variable_Reference;
9723 -----------------------------------------------------
9724 -- Process_Conditional_ABE_Variable_Reference_Read --
9725 -----------------------------------------------------
9727 procedure Process_Conditional_ABE_Variable_Reference_Read
9730 Attrs : Variable_Attributes)
9733 -- Output relevant information when switch -gnatel (info messages on
9734 -- implicit Elaborate[_All] pragmas) is in effect.
9736 if Elab_Info_Messages then
9738 (Msg => "read of variable & during elaboration",
9745 -- Nothing to do when the variable appears within the main unit because
9746 -- diagnostics on reads are relevant only for external variables.
9748 if Is_Same_Unit (Attrs.Unit_Id, Cunit_Entity (Main_Unit)) then
9751 -- Nothing to do when the variable is already initialized. Note that the
9752 -- variable may be further modified by the external unit.
9754 elsif Is_Initialized (Declaration_Node (Var_Id)) then
9757 -- Nothing to do when the external unit guarantees the initialization of
9758 -- the variable by means of pragma Elaborate_Body.
9760 elsif Has_Pragma_Elaborate_Body (Attrs.Unit_Id) then
9763 -- A variable read imposes an Elaborate requirement on the context of
9764 -- the main unit. Determine whether the context has a pragma strong
9765 -- enough to meet the requirement.
9768 Meet_Elaboration_Requirement
9770 Target_Id => Var_Id,
9771 Req_Nam => Name_Elaborate);
9773 end Process_Conditional_ABE_Variable_Reference_Read;
9775 -----------------------------
9776 -- Process_Conditional_ABE --
9777 -----------------------------
9779 -- NOTE: The body of this routine is intentionally out of order because it
9780 -- invokes an instantiated subprogram (Process_Conditional_ABE_Activation).
9781 -- Placing the body in alphabetical order will result in a guaranteed ABE.
9783 procedure Process_Conditional_ABE
9785 In_Init_Cond : Boolean := False;
9786 In_Partial_Fin : Boolean := False;
9787 In_Task_Body : Boolean := False)
9789 Call_Attrs : Call_Attributes;
9790 Target_Id : Entity_Id;
9793 -- Add the current scenario to the stack of active scenarios
9795 Push_Active_Scenario (N);
9799 if Is_Suitable_Access (N) then
9800 Process_Conditional_ABE_Access
9802 In_Init_Cond => In_Init_Cond,
9803 In_Partial_Fin => In_Partial_Fin,
9804 In_Task_Body => In_Task_Body);
9808 elsif Is_Suitable_Call (N) then
9810 -- In general, only calls found within the main unit are processed
9811 -- because the ALI information supplied to binde is for the main
9812 -- unit only. However, to preserve the consistency of the tree and
9813 -- ensure proper serialization of internal names, external calls
9814 -- also receive corresponding call markers (see Build_Call_Marker).
9815 -- Regardless of the reason, external calls must not be processed.
9817 if In_Main_Context (N) then
9818 Extract_Call_Attributes
9820 Target_Id => Target_Id,
9821 Attrs => Call_Attrs);
9823 if Is_Activation_Proc (Target_Id) then
9824 Process_Conditional_ABE_Activation
9826 Call_Attrs => Call_Attrs,
9827 In_Init_Cond => In_Init_Cond,
9828 In_Partial_Fin => In_Partial_Fin,
9829 In_Task_Body => In_Task_Body);
9832 Process_Conditional_ABE_Call
9834 Call_Attrs => Call_Attrs,
9835 Target_Id => Target_Id,
9836 In_Init_Cond => In_Init_Cond,
9837 In_Partial_Fin => In_Partial_Fin,
9838 In_Task_Body => In_Task_Body);
9844 elsif Is_Suitable_Instantiation (N) then
9845 Process_Conditional_ABE_Instantiation
9847 In_Partial_Fin => In_Partial_Fin,
9848 In_Task_Body => In_Task_Body);
9850 -- Variable assignments
9852 elsif Is_Suitable_Variable_Assignment (N) then
9853 Process_Conditional_ABE_Variable_Assignment (N);
9855 -- Variable references
9857 elsif Is_Suitable_Variable_Reference (N) then
9859 -- In general, only variable references found within the main unit
9860 -- are processed because the ALI information supplied to binde is for
9861 -- the main unit only. However, to preserve the consistency of the
9862 -- tree and ensure proper serialization of internal names, external
9863 -- variable references also receive corresponding variable reference
9864 -- markers (see Build_Varaible_Reference_Marker). Regardless of the
9865 -- reason, external variable references must not be processed.
9867 if In_Main_Context (N) then
9868 Process_Conditional_ABE_Variable_Reference (N);
9872 -- Remove the current scenario from the stack of active scenarios once
9873 -- all ABE diagnostics and checks have been performed.
9875 Pop_Active_Scenario (N);
9876 end Process_Conditional_ABE;
9878 --------------------------------------------
9879 -- Process_Guaranteed_ABE_Activation_Impl --
9880 --------------------------------------------
9882 procedure Process_Guaranteed_ABE_Activation_Impl
9884 Call_Attrs : Call_Attributes;
9886 Task_Attrs : Task_Attributes;
9887 In_Init_Cond : Boolean;
9888 In_Partial_Fin : Boolean;
9889 In_Task_Body : Boolean)
9891 pragma Unreferenced (Call_Attrs);
9892 pragma Unreferenced (In_Init_Cond);
9893 pragma Unreferenced (In_Partial_Fin);
9894 pragma Unreferenced (In_Task_Body);
9896 Check_OK : constant Boolean :=
9897 not Is_Ignored_Ghost_Entity (Obj_Id)
9898 and then not Task_Attrs.Ghost_Mode_Ignore
9899 and then Is_Elaboration_Checks_OK_Id (Obj_Id)
9900 and then Task_Attrs.Elab_Checks_OK;
9901 -- A run-time ABE check may be installed only when the object and the
9902 -- task type have active elaboration checks, and both are not ignored
9903 -- Ghost constructs.
9906 -- Nothing to do when the root scenario appears at the declaration
9907 -- level and the task is in the same unit, but outside this context.
9909 -- task type Task_Typ; -- task declaration
9911 -- procedure Proc is
9912 -- function A ... is
9914 -- if Some_Condition then
9918 -- <activation call> -- activation site
9923 -- X : ... := A; -- root scenario
9926 -- task body Task_Typ is
9930 -- In the example above, the context of X is the declarative list of
9931 -- Proc. The "elaboration" of X may reach the activation of T whose body
9932 -- is defined outside of X's context. The task body is relevant only
9933 -- when Proc is invoked, but this happens only in "normal" elaboration,
9934 -- therefore the task body must not be considered if this is not the
9937 -- Performance note: parent traversal
9939 if Is_Up_Level_Target (Task_Attrs.Task_Decl) then
9942 -- Nothing to do when the activation is ABE-safe
9946 -- task type Task_Typ;
9949 -- package body Gen is
9950 -- task body Task_Typ is
9957 -- procedure Main is
9958 -- package Nested is
9962 -- package body Nested is
9963 -- package Inst is new Gen;
9964 -- T : Inst.Task_Typ;
9966 -- <activation call> -- safe activation
9970 elsif Is_Safe_Activation (Call, Task_Attrs.Task_Decl) then
9973 -- An activation call leads to a guaranteed ABE when the activation
9974 -- call and the task appear within the same context ignoring library
9975 -- levels, and the body of the task has not been seen yet or appears
9976 -- after the activation call.
9978 -- procedure Guaranteed_ABE is
9979 -- task type Task_Typ;
9981 -- package Nested is
9985 -- package body Nested is
9988 -- <activation call> -- guaranteed ABE
9991 -- task body Task_Typ is
9996 -- Performance note: parent traversal
9998 elsif Is_Guaranteed_ABE
10000 Target_Decl => Task_Attrs.Task_Decl,
10001 Target_Body => Task_Attrs.Body_Decl)
10003 Error_Msg_Sloc := Sloc (Call);
10005 ("??task & will be activated # before elaboration of its body",
10007 Error_Msg_N ("\Program_Error will be raised at run time", Obj_Id);
10009 -- Mark the activation call as a guaranteed ABE
10011 Set_Is_Known_Guaranteed_ABE (Call);
10013 -- Install a run-time ABE failue because this activation call will
10014 -- always result in an ABE.
10017 Install_ABE_Failure
10022 end Process_Guaranteed_ABE_Activation_Impl;
10024 procedure Process_Guaranteed_ABE_Activation is
10025 new Process_Activation_Generic (Process_Guaranteed_ABE_Activation_Impl);
10027 ---------------------------------
10028 -- Process_Guaranteed_ABE_Call --
10029 ---------------------------------
10031 procedure Process_Guaranteed_ABE_Call
10033 Call_Attrs : Call_Attributes;
10034 Target_Id : Entity_Id)
10036 Target_Attrs : Target_Attributes;
10039 Extract_Target_Attributes
10040 (Target_Id => Target_Id,
10041 Attrs => Target_Attrs);
10043 -- Nothing to do when the root scenario appears at the declaration level
10044 -- and the target is in the same unit, but outside this context.
10046 -- function B ...; -- target declaration
10048 -- procedure Proc is
10049 -- function A ... is
10051 -- if Some_Condition then
10052 -- return B; -- call site
10056 -- X : ... := A; -- root scenario
10059 -- function B ... is
10063 -- In the example above, the context of X is the declarative region of
10064 -- Proc. The "elaboration" of X may eventually reach B which is defined
10065 -- outside of X's context. B is relevant only when Proc is invoked, but
10066 -- this happens only by means of "normal" elaboration, therefore B must
10067 -- not be considered if this is not the case.
10069 -- Performance note: parent traversal
10071 if Is_Up_Level_Target (Target_Attrs.Spec_Decl) then
10074 -- Nothing to do when the call is ABE-safe
10077 -- function Gen ...;
10079 -- function Gen ... is
10085 -- procedure Main is
10086 -- function Inst is new Gen;
10087 -- X : ... := Inst; -- safe call
10090 elsif Is_Safe_Call (Call, Target_Attrs) then
10093 -- A call leads to a guaranteed ABE when the call and the target appear
10094 -- within the same context ignoring library levels, and the body of the
10095 -- target has not been seen yet or appears after the call.
10097 -- procedure Guaranteed_ABE is
10098 -- function Func ...;
10100 -- package Nested is
10101 -- Obj : ... := Func; -- guaranteed ABE
10104 -- function Func ... is
10109 -- Performance note: parent traversal
10111 elsif Is_Guaranteed_ABE
10113 Target_Decl => Target_Attrs.Spec_Decl,
10114 Target_Body => Target_Attrs.Body_Decl)
10116 Error_Msg_NE ("??cannot call & before body seen", Call, Target_Id);
10117 Error_Msg_N ("\Program_Error will be raised at run time", Call);
10119 -- Mark the call as a guarnateed ABE
10121 Set_Is_Known_Guaranteed_ABE (Call);
10123 -- Install a run-time ABE failure because the call will always result
10124 -- in an ABE. The failure is installed when both the call and target
10125 -- have enabled elaboration checks, and both are not ignored Ghost
10128 if Call_Attrs.Elab_Checks_OK
10129 and then Target_Attrs.Elab_Checks_OK
10130 and then not Call_Attrs.Ghost_Mode_Ignore
10131 and then not Target_Attrs.Ghost_Mode_Ignore
10133 Install_ABE_Failure
10138 end Process_Guaranteed_ABE_Call;
10140 ------------------------------------------
10141 -- Process_Guaranteed_ABE_Instantiation --
10142 ------------------------------------------
10144 procedure Process_Guaranteed_ABE_Instantiation (Exp_Inst : Node_Id) is
10145 Gen_Attrs : Target_Attributes;
10146 Gen_Id : Entity_Id;
10148 Inst_Attrs : Instantiation_Attributes;
10149 Inst_Id : Entity_Id;
10152 Extract_Instantiation_Attributes
10153 (Exp_Inst => Exp_Inst,
10155 Inst_Id => Inst_Id,
10157 Attrs => Inst_Attrs);
10159 Extract_Target_Attributes (Gen_Id, Gen_Attrs);
10161 -- Nothing to do when the root scenario appears at the declaration level
10162 -- and the generic is in the same unit, but outside this context.
10165 -- procedure Gen is ...; -- generic declaration
10167 -- procedure Proc is
10168 -- function A ... is
10170 -- if Some_Condition then
10172 -- procedure I is new Gen; -- instantiation site
10177 -- X : ... := A; -- root scenario
10180 -- procedure Gen is
10184 -- In the example above, the context of X is the declarative region of
10185 -- Proc. The "elaboration" of X may eventually reach Gen which appears
10186 -- outside of X's context. Gen is relevant only when Proc is invoked,
10187 -- but this happens only by means of "normal" elaboration, therefore
10188 -- Gen must not be considered if this is not the case.
10190 -- Performance note: parent traversal
10192 if Is_Up_Level_Target (Gen_Attrs.Spec_Decl) then
10195 -- Nothing to do when the instantiation is ABE-safe
10202 -- package body Gen is
10207 -- procedure Main is
10208 -- package Inst is new Gen (ABE); -- safe instantiation
10211 elsif Is_Safe_Instantiation (Inst, Gen_Attrs) then
10214 -- An instantiation leads to a guaranteed ABE when the instantiation and
10215 -- the generic appear within the same context ignoring library levels,
10216 -- and the body of the generic has not been seen yet or appears after
10217 -- the instantiation.
10219 -- procedure Guaranteed_ABE is
10223 -- package Nested is
10224 -- procedure Inst is new Gen; -- guaranteed ABE
10227 -- procedure Gen is
10232 -- Performance note: parent traversal
10234 elsif Is_Guaranteed_ABE
10236 Target_Decl => Gen_Attrs.Spec_Decl,
10237 Target_Body => Gen_Attrs.Body_Decl)
10240 ("??cannot instantiate & before body seen", Inst, Gen_Id);
10241 Error_Msg_N ("\Program_Error will be raised at run time", Inst);
10243 -- Mark the instantiation as a guarantee ABE. This automatically
10244 -- suppresses the instantiation of the generic body.
10246 Set_Is_Known_Guaranteed_ABE (Inst);
10248 -- Install a run-time ABE failure because the instantiation will
10249 -- always result in an ABE. The failure is installed when both the
10250 -- instance and the generic have enabled elaboration checks, and both
10251 -- are not ignored Ghost constructs.
10253 if Inst_Attrs.Elab_Checks_OK
10254 and then Gen_Attrs.Elab_Checks_OK
10255 and then not Inst_Attrs.Ghost_Mode_Ignore
10256 and then not Gen_Attrs.Ghost_Mode_Ignore
10258 Install_ABE_Failure
10260 Ins_Nod => Exp_Inst);
10263 end Process_Guaranteed_ABE_Instantiation;
10265 ----------------------------
10266 -- Process_Guaranteed_ABE --
10267 ----------------------------
10269 -- NOTE: The body of this routine is intentionally out of order because it
10270 -- invokes an instantiated subprogram (Process_Guaranteed_ABE_Activation).
10271 -- Placing the body in alphabetical order will result in a guaranteed ABE.
10273 procedure Process_Guaranteed_ABE (N : Node_Id) is
10274 Call_Attrs : Call_Attributes;
10275 Target_Id : Entity_Id;
10278 -- Add the current scenario to the stack of active scenarios
10280 Push_Active_Scenario (N);
10282 -- Only calls, instantiations, and task activations may result in a
10285 if Is_Suitable_Call (N) then
10286 Extract_Call_Attributes
10288 Target_Id => Target_Id,
10289 Attrs => Call_Attrs);
10291 if Is_Activation_Proc (Target_Id) then
10292 Process_Guaranteed_ABE_Activation
10294 Call_Attrs => Call_Attrs,
10295 In_Init_Cond => False,
10296 In_Partial_Fin => False,
10297 In_Task_Body => False);
10300 Process_Guaranteed_ABE_Call
10302 Call_Attrs => Call_Attrs,
10303 Target_Id => Target_Id);
10306 elsif Is_Suitable_Instantiation (N) then
10307 Process_Guaranteed_ABE_Instantiation (N);
10310 -- Remove the current scenario from the stack of active scenarios once
10311 -- all ABE diagnostics and checks have been performed.
10313 Pop_Active_Scenario (N);
10314 end Process_Guaranteed_ABE;
10316 --------------------------
10317 -- Push_Active_Scenario --
10318 --------------------------
10320 procedure Push_Active_Scenario (N : Node_Id) is
10322 Scenario_Stack.Append (N);
10323 end Push_Active_Scenario;
10325 ---------------------------------
10326 -- Record_Elaboration_Scenario --
10327 ---------------------------------
10329 procedure Record_Elaboration_Scenario (N : Node_Id) is
10330 Level : Enclosing_Level_Kind;
10332 Any_Level_OK : Boolean;
10333 -- This flag is set when a particular scenario is allowed to appear at
10336 Declaration_Level_OK : Boolean;
10337 -- This flag is set when a particular scenario is allowed to appear at
10338 -- the declaration level.
10340 Library_Level_OK : Boolean;
10341 -- This flag is set when a particular scenario is allowed to appear at
10342 -- the library level.
10345 -- Assume that the scenario cannot appear on any level
10347 Any_Level_OK := False;
10348 Declaration_Level_OK := False;
10349 Library_Level_OK := False;
10351 -- Nothing to do for ASIS. As a result, no ABE checks and diagnostics
10352 -- are performed in this mode.
10357 -- Nothing to do when the scenario is being preanalyzed
10359 elsif Preanalysis_Active then
10363 -- Ensure that a library-level call does not appear in a preelaborated
10364 -- unit. The check must come before ignoring scenarios within external
10365 -- units or inside generics because calls in those context must also be
10368 if Is_Suitable_Call (N) then
10369 Check_Preelaborated_Call (N);
10372 -- Nothing to do when the scenario does not appear within the main unit
10374 if not In_Main_Context (N) then
10377 -- Scenarios within a generic unit are never considered because generics
10378 -- cannot be elaborated.
10380 elsif Inside_A_Generic then
10383 -- Scenarios which do not fall in one of the elaboration categories
10384 -- listed below are not considered. The categories are:
10386 -- 'Access for entries, operators, and subprograms
10387 -- Assignments to variables
10388 -- Calls (includes task activation)
10391 -- Pragma Refined_State
10392 -- Reads of variables
10394 elsif Is_Suitable_Access (N) then
10395 Library_Level_OK := True;
10397 -- Signal any enclosing local exception handlers that the 'Access may
10398 -- raise Program_Error due to a failed ABE check when switch -gnatd.o
10399 -- (conservative elaboration order for indirect calls) is in effect.
10400 -- Marking the exception handlers ensures proper expansion by both
10401 -- the front and back end restriction when No_Exception_Propagation
10404 if Debug_Flag_Dot_O then
10405 Possible_Local_Raise (N, Standard_Program_Error);
10408 elsif Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N) then
10409 Declaration_Level_OK := True;
10410 Library_Level_OK := True;
10412 -- Signal any enclosing local exception handlers that the call or
10413 -- instantiation may raise Program_Error due to a failed ABE check.
10414 -- Marking the exception handlers ensures proper expansion by both
10415 -- the front and back end restriction when No_Exception_Propagation
10418 Possible_Local_Raise (N, Standard_Program_Error);
10420 elsif Is_Suitable_SPARK_Derived_Type (N) then
10421 Any_Level_OK := True;
10423 elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
10424 Library_Level_OK := True;
10426 elsif Is_Suitable_Variable_Assignment (N)
10427 or else Is_Suitable_Variable_Reference (N)
10429 Library_Level_OK := True;
10431 -- Otherwise the input does not denote a suitable scenario
10437 -- The static model imposes additional restrictions on the placement of
10438 -- scenarios. In contrast, the dynamic model assumes that every scenario
10439 -- will be elaborated or invoked at some point.
10441 if Static_Elaboration_Checks then
10443 -- Certain scenarios are allowed to appear at any level. This check
10444 -- is performed here in order to save on a parent traversal.
10446 if Any_Level_OK then
10449 -- Otherwise the scenario must appear at a specific level
10452 -- Performance note: parent traversal
10454 Level := Find_Enclosing_Level (N);
10456 -- Declaration-level scenario
10458 if Declaration_Level_OK and then Level = Declaration_Level then
10461 -- Library-level scenario
10463 elsif Library_Level_OK
10464 and then Level in Library_Or_Instantiation_Level
10468 -- Otherwise the scenario does not appear at the proper level and
10469 -- cannot possibly act as a top-level scenario.
10477 -- Derived types subject to SPARK_Mode On require elaboration-related
10478 -- checks even though the type may not be declared within elaboration
10479 -- code. The types are recorded in a separate table which is examined
10480 -- during the Processing phase. Note that the checks must be delayed
10481 -- because the bodies of overriding primitives are not available yet.
10483 if Is_Suitable_SPARK_Derived_Type (N) then
10484 Record_SPARK_Elaboration_Scenario (N);
10486 -- Nothing left to do for derived types
10490 -- Instantiations of generics both subject to SPARK_Mode On require
10491 -- elaboration-related checks even though the instantiations may not
10492 -- appear within elaboration code. The instantiations are recored in
10493 -- a separate table which is examined during the Procesing phase. Note
10494 -- that the checks must be delayed because it is not known yet whether
10495 -- the generic unit has a body or not.
10497 -- IMPORTANT: A SPARK instantiation is also a normal instantiation which
10498 -- is subject to common conditional and guaranteed ABE checks.
10500 elsif Is_Suitable_SPARK_Instantiation (N) then
10501 Record_SPARK_Elaboration_Scenario (N);
10503 -- External constituents that refine abstract states which appear in
10504 -- pragma Initializes require elaboration-related checks even though
10505 -- a Refined_State pragma lacks any elaboration semantic.
10507 elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then
10508 Record_SPARK_Elaboration_Scenario (N);
10510 -- Nothing left to do for pragma Refined_State
10515 -- Perform early detection of guaranteed ABEs in order to suppress the
10516 -- instantiation of generic bodies as gigi cannot handle certain types
10517 -- of premature instantiations.
10519 Process_Guaranteed_ABE (N);
10521 -- At this point all checks have been performed. Record the scenario for
10522 -- later processing by the ABE phase.
10524 Top_Level_Scenarios.Append (N);
10525 Set_Is_Recorded_Top_Level_Scenario (N);
10526 end Record_Elaboration_Scenario;
10528 ---------------------------------------
10529 -- Record_SPARK_Elaboration_Scenario --
10530 ---------------------------------------
10532 procedure Record_SPARK_Elaboration_Scenario (N : Node_Id) is
10534 SPARK_Scenarios.Append (N);
10535 Set_Is_Recorded_SPARK_Scenario (N);
10536 end Record_SPARK_Elaboration_Scenario;
10538 -----------------------------------
10539 -- Recorded_SPARK_Scenarios_Hash --
10540 -----------------------------------
10542 function Recorded_SPARK_Scenarios_Hash
10543 (Key : Node_Id) return Recorded_SPARK_Scenarios_Index
10547 Recorded_SPARK_Scenarios_Index (Key mod Recorded_SPARK_Scenarios_Max);
10548 end Recorded_SPARK_Scenarios_Hash;
10550 ---------------------------------------
10551 -- Recorded_Top_Level_Scenarios_Hash --
10552 ---------------------------------------
10554 function Recorded_Top_Level_Scenarios_Hash
10555 (Key : Node_Id) return Recorded_Top_Level_Scenarios_Index
10559 Recorded_Top_Level_Scenarios_Index
10560 (Key mod Recorded_Top_Level_Scenarios_Max);
10561 end Recorded_Top_Level_Scenarios_Hash;
10563 --------------------------
10564 -- Reset_Visited_Bodies --
10565 --------------------------
10567 procedure Reset_Visited_Bodies is
10569 if Visited_Bodies_In_Use then
10570 Visited_Bodies_In_Use := False;
10571 Visited_Bodies.Reset;
10573 end Reset_Visited_Bodies;
10575 -------------------
10576 -- Root_Scenario --
10577 -------------------
10579 function Root_Scenario return Node_Id is
10580 package Stack renames Scenario_Stack;
10583 -- Ensure that the scenario stack has at least one active scenario in
10584 -- it. The one at the bottom (index First) is the root scenario.
10586 pragma Assert (Stack.Last >= Stack.First);
10587 return Stack.Table (Stack.First);
10590 ---------------------------
10591 -- Set_Early_Call_Region --
10592 ---------------------------
10594 procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id) is
10596 pragma Assert (Ekind_In (Body_Id, E_Entry,
10600 E_Subprogram_Body));
10602 Early_Call_Regions_In_Use := True;
10603 Early_Call_Regions.Set (Body_Id, Start);
10604 end Set_Early_Call_Region;
10606 ----------------------------
10607 -- Set_Elaboration_Status --
10608 ----------------------------
10610 procedure Set_Elaboration_Status
10611 (Unit_Id : Entity_Id;
10612 Val : Elaboration_Attributes)
10615 Elaboration_Statuses_In_Use := True;
10616 Elaboration_Statuses.Set (Unit_Id, Val);
10617 end Set_Elaboration_Status;
10619 ------------------------------------
10620 -- Set_Is_Recorded_SPARK_Scenario --
10621 ------------------------------------
10623 procedure Set_Is_Recorded_SPARK_Scenario
10625 Val : Boolean := True)
10628 Recorded_SPARK_Scenarios_In_Use := True;
10629 Recorded_SPARK_Scenarios.Set (N, Val);
10630 end Set_Is_Recorded_SPARK_Scenario;
10632 ----------------------------------------
10633 -- Set_Is_Recorded_Top_Level_Scenario --
10634 ----------------------------------------
10636 procedure Set_Is_Recorded_Top_Level_Scenario
10638 Val : Boolean := True)
10641 Recorded_Top_Level_Scenarios_In_Use := True;
10642 Recorded_Top_Level_Scenarios.Set (N, Val);
10643 end Set_Is_Recorded_Top_Level_Scenario;
10645 -------------------------
10646 -- Set_Is_Visited_Body --
10647 -------------------------
10649 procedure Set_Is_Visited_Body (Subp_Body : Node_Id) is
10651 Visited_Bodies_In_Use := True;
10652 Visited_Bodies.Set (Subp_Body, True);
10653 end Set_Is_Visited_Body;
10655 -------------------------------
10656 -- Static_Elaboration_Checks --
10657 -------------------------------
10659 function Static_Elaboration_Checks return Boolean is
10661 return not Dynamic_Elaboration_Checks;
10662 end Static_Elaboration_Checks;
10664 -------------------
10665 -- Traverse_Body --
10666 -------------------
10668 procedure Traverse_Body
10670 In_Init_Cond : Boolean;
10671 In_Partial_Fin : Boolean;
10672 In_Task_Body : Boolean)
10674 procedure Find_And_Process_Nested_Scenarios;
10675 pragma Inline (Find_And_Process_Nested_Scenarios);
10676 -- Examine the declarations and statements of subprogram body N for
10677 -- suitable scenarios. Save each discovered scenario and process it
10680 procedure Process_Nested_Scenarios (Nested : Elist_Id);
10681 pragma Inline (Process_Nested_Scenarios);
10682 -- Invoke Process_Conditional_ABE on each individual scenario found in
10685 ---------------------------------------
10686 -- Find_And_Process_Nested_Scenarios --
10687 ---------------------------------------
10689 procedure Find_And_Process_Nested_Scenarios is
10690 Body_Id : constant Entity_Id := Defining_Entity (N);
10692 function Is_Potential_Scenario
10693 (Nod : Node_Id) return Traverse_Result;
10694 -- Determine whether arbitrary node Nod denotes a suitable scenario.
10695 -- If it does, save it in the Nested_Scenarios list of the subprogram
10696 -- body, and process it.
10698 procedure Save_Scenario (Nod : Node_Id);
10699 pragma Inline (Save_Scenario);
10700 -- Save scenario Nod in the Nested_Scenarios list of the subprogram
10703 procedure Traverse_List (List : List_Id);
10704 pragma Inline (Traverse_List);
10705 -- Invoke Traverse_Potential_Scenarios on each node in list List
10707 procedure Traverse_Potential_Scenarios is
10708 new Traverse_Proc (Is_Potential_Scenario);
10710 ---------------------------
10711 -- Is_Potential_Scenario --
10712 ---------------------------
10714 function Is_Potential_Scenario
10715 (Nod : Node_Id) return Traverse_Result
10720 -- Skip constructs which do not have elaboration of their own and
10721 -- need to be elaborated by other means such as invocation, task
10722 -- activation, etc.
10724 if Is_Non_Library_Level_Encapsulator (Nod) then
10727 -- Terminate the traversal of a task body with an accept statement
10728 -- when no entry calls in elaboration are allowed because the task
10729 -- will block at run-time and the remaining statements will not be
10732 elsif Nkind_In (Original_Node (Nod), N_Accept_Statement,
10733 N_Selective_Accept)
10734 and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code)
10738 -- Certain nodes carry semantic lists which act as repositories
10739 -- until expansion transforms the node and relocates the contents.
10740 -- Examine these lists in case expansion is disabled.
10742 elsif Nkind_In (Nod, N_And_Then, N_Or_Else) then
10743 Traverse_List (Actions (Nod));
10745 elsif Nkind_In (Nod, N_Elsif_Part, N_Iteration_Scheme) then
10746 Traverse_List (Condition_Actions (Nod));
10748 elsif Nkind (Nod) = N_If_Expression then
10749 Traverse_List (Then_Actions (Nod));
10750 Traverse_List (Else_Actions (Nod));
10752 elsif Nkind_In (Nod, N_Component_Association,
10753 N_Iterated_Component_Association)
10755 Traverse_List (Loop_Actions (Nod));
10759 -- Save a suitable scenario in the Nested_Scenarios list of the
10760 -- subprogram body. As a result any subsequent traversals of the
10761 -- subprogram body started from a different top-level scenario no
10762 -- longer need to reexamine the tree.
10764 elsif Is_Suitable_Scenario (Nod) then
10765 Save_Scenario (Nod);
10767 Process_Conditional_ABE
10769 In_Init_Cond => In_Init_Cond,
10770 In_Partial_Fin => In_Partial_Fin,
10771 In_Task_Body => In_Task_Body);
10775 end Is_Potential_Scenario;
10777 -------------------
10778 -- Save_Scenario --
10779 -------------------
10781 procedure Save_Scenario (Nod : Node_Id) is
10785 Nested := Nested_Scenarios (Body_Id);
10787 if No (Nested) then
10788 Nested := New_Elmt_List;
10789 Set_Nested_Scenarios (Body_Id, Nested);
10792 Append_Elmt (Nod, Nested);
10795 -------------------
10796 -- Traverse_List --
10797 -------------------
10799 procedure Traverse_List (List : List_Id) is
10803 Item := First (List);
10804 while Present (Item) loop
10805 Traverse_Potential_Scenarios (Item);
10810 -- Start of processing for Find_And_Process_Nested_Scenarios
10813 -- Examine the declarations for suitable scenarios
10815 Traverse_List (Declarations (N));
10817 -- Examine the handled sequence of statements. This also includes any
10818 -- exceptions handlers.
10820 Traverse_Potential_Scenarios (Handled_Statement_Sequence (N));
10821 end Find_And_Process_Nested_Scenarios;
10823 ------------------------------
10824 -- Process_Nested_Scenarios --
10825 ------------------------------
10827 procedure Process_Nested_Scenarios (Nested : Elist_Id) is
10828 Nested_Elmt : Elmt_Id;
10831 Nested_Elmt := First_Elmt (Nested);
10832 while Present (Nested_Elmt) loop
10833 Process_Conditional_ABE
10834 (N => Node (Nested_Elmt),
10835 In_Init_Cond => In_Init_Cond,
10836 In_Partial_Fin => In_Partial_Fin,
10837 In_Task_Body => In_Task_Body);
10839 Next_Elmt (Nested_Elmt);
10841 end Process_Nested_Scenarios;
10847 -- Start of processing for Traverse_Body
10850 -- Nothing to do when there is no body
10855 elsif Nkind (N) /= N_Subprogram_Body then
10859 -- Nothing to do if the body was already traversed during the processing
10860 -- of the same top-level scenario.
10862 if Is_Visited_Body (N) then
10865 -- Otherwise mark the body as traversed
10868 Set_Is_Visited_Body (N);
10871 Nested := Nested_Scenarios (Defining_Entity (N));
10873 -- The subprogram body was already examined as part of the elaboration
10874 -- graph starting from a different top-level scenario. There is no need
10875 -- to traverse the declarations and statements again because this will
10876 -- yield the exact same scenarios. Use the nested scenarios collected
10877 -- during the first inspection of the body.
10879 if Present (Nested) then
10880 Process_Nested_Scenarios (Nested);
10882 -- Otherwise examine the declarations and statements of the subprogram
10883 -- body for suitable scenarios, save and process them accordingly.
10886 Find_And_Process_Nested_Scenarios;
10890 ---------------------------------
10891 -- Update_Elaboration_Scenario --
10892 ---------------------------------
10894 procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id) is
10895 procedure Update_SPARK_Scenario;
10896 pragma Inline (Update_SPARK_Scenario);
10897 -- Update the contents of table SPARK_Scenarios if Old_N is recorded
10900 procedure Update_Top_Level_Scenario;
10901 pragma Inline (Update_Top_Level_Scenario);
10902 -- Update the contexts of table Top_Level_Scenarios if Old_N is recorded
10905 ---------------------------
10906 -- Update_SPARK_Scenario --
10907 ---------------------------
10909 procedure Update_SPARK_Scenario is
10910 package Scenarios renames SPARK_Scenarios;
10913 if Is_Recorded_SPARK_Scenario (Old_N) then
10915 -- Performance note: list traversal
10917 for Index in Scenarios.First .. Scenarios.Last loop
10918 if Scenarios.Table (Index) = Old_N then
10919 Scenarios.Table (Index) := New_N;
10921 -- The old SPARK scenario is no longer recorded, but the new
10924 Set_Is_Recorded_Top_Level_Scenario (Old_N, False);
10925 Set_Is_Recorded_Top_Level_Scenario (New_N);
10930 -- A recorded SPARK scenario must be in the table of recorded
10931 -- SPARK scenarios.
10933 pragma Assert (False);
10935 end Update_SPARK_Scenario;
10937 -------------------------------
10938 -- Update_Top_Level_Scenario --
10939 -------------------------------
10941 procedure Update_Top_Level_Scenario is
10942 package Scenarios renames Top_Level_Scenarios;
10945 if Is_Recorded_Top_Level_Scenario (Old_N) then
10947 -- Performance note: list traversal
10949 for Index in Scenarios.First .. Scenarios.Last loop
10950 if Scenarios.Table (Index) = Old_N then
10951 Scenarios.Table (Index) := New_N;
10953 -- The old top-level scenario is no longer recorded, but the
10956 Set_Is_Recorded_Top_Level_Scenario (Old_N, False);
10957 Set_Is_Recorded_Top_Level_Scenario (New_N);
10962 -- A recorded top-level scenario must be in the table of recorded
10963 -- top-level scenarios.
10965 pragma Assert (False);
10967 end Update_Top_Level_Scenario;
10969 -- Start of processing for Update_Elaboration_Requirement
10972 -- Nothing to do when the old and new scenarios are one and the same
10974 if Old_N = New_N then
10977 -- A scenario is being transformed by Atree.Rewrite. Update all relevant
10978 -- internal data structures to reflect this change. This ensures that a
10979 -- potential run-time conditional ABE check or a guaranteed ABE failure
10980 -- is inserted at the proper place in the tree.
10982 elsif Is_Scenario (Old_N) then
10983 Update_SPARK_Scenario;
10984 Update_Top_Level_Scenario;
10986 end Update_Elaboration_Scenario;
10988 -------------------------
10989 -- Visited_Bodies_Hash --
10990 -------------------------
10992 function Visited_Bodies_Hash (Key : Node_Id) return Visited_Bodies_Index is
10994 return Visited_Bodies_Index (Key mod Visited_Bodies_Max);
10995 end Visited_Bodies_Hash;