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 Checks
; use Checks
;
28 with Debug
; use Debug
;
29 with Einfo
; use Einfo
;
30 with Elists
; use Elists
;
31 with Errout
; use Errout
;
32 with Exp_Ch11
; use Exp_Ch11
;
33 with Exp_Tss
; use Exp_Tss
;
34 with Exp_Util
; use Exp_Util
;
35 with Expander
; use Expander
;
37 with Lib
.Load
; use Lib
.Load
;
38 with Namet
; use Namet
;
39 with Nlists
; use Nlists
;
40 with Nmake
; use Nmake
;
42 with Output
; use Output
;
43 with Restrict
; use Restrict
;
44 with Rident
; use Rident
;
45 with Rtsfind
; use Rtsfind
;
47 with Sem_Aux
; use Sem_Aux
;
48 with Sem_Cat
; use Sem_Cat
;
49 with Sem_Ch7
; use Sem_Ch7
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Prag
; use Sem_Prag
;
52 with Sem_Util
; use Sem_Util
;
53 with Sinfo
; use Sinfo
;
54 with Sinput
; use Sinput
;
55 with Snames
; use Snames
;
56 with Stand
; use Stand
;
58 with Tbuild
; use Tbuild
;
59 with Uintp
; use Uintp
;
60 with Uname
; use Uname
;
62 with GNAT
.HTable
; use GNAT
.HTable
;
64 package body Sem_Elab
is
66 -----------------------------------------
67 -- Access-before-elaboration mechanism --
68 -----------------------------------------
70 -- The access-before-elaboration (ABE) mechanism implemented in this unit
71 -- has the following objectives:
73 -- * Diagnose at compile-time or install run-time checks to prevent ABE
74 -- access to data and behaviour.
76 -- The high-level idea is to accurately diagnose ABE issues within a
77 -- single unit because the ABE mechanism can inspect the whole unit.
78 -- As soon as the elaboration graph extends to an external unit, the
79 -- diagnostics stop because the body of the unit may not be available.
80 -- Due to control and data flow, the ABE mechanism cannot accurately
81 -- determine whether a particular scenario will be elaborated or not.
82 -- Conditional ABE checks are therefore used to verify the elaboration
83 -- status of a local and external target at run time.
85 -- * Supply elaboration dependencies for a unit to binde
87 -- The ABE mechanism registers each outgoing elaboration edge for the
88 -- main unit in its ALI file. GNATbind and binde can then reconstruct
89 -- the full elaboration graph and determine the proper elaboration
90 -- order for all units in the compilation.
92 -- The ABE mechanism supports three models of elaboration:
94 -- * Dynamic model - This is the most permissive of the three models.
95 -- When the dynamic model is in effect, the mechanism performs very
96 -- little diagnostics and generates run-time checks to detect ABE
97 -- issues. The behaviour of this model is identical to that specified
98 -- by the Ada RM. This model is enabled with switch -gnatE.
100 -- * Static model - This is the middle ground of the three models. When
101 -- the static model is in effect, the mechanism diagnoses and installs
102 -- run-time checks to detect ABE issues in the main unit. In addition,
103 -- the mechanism generates implicit Elaborate or Elaborate_All pragmas
104 -- to ensure the prior elaboration of withed units. The model employs
105 -- textual order, with clause context, and elaboration-related source
106 -- pragmas. This is the default model.
108 -- * SPARK model - This is the most conservative of the three models and
109 -- impelements the semantics defined in SPARK RM 7.7. The SPARK model
110 -- is in effect only when a context resides in a SPARK_Mode On region,
111 -- otherwise the mechanism falls back to one of the previous models.
113 -- The ABE mechanism consists of a "recording" phase and a "processing"
120 -- * ABE - An attempt to activate, call, or instantiate a scenario which
121 -- has not been fully elaborated.
123 -- * Bridge target - A type of target. A bridge target is a link between
124 -- scenarios. It is usually a byproduct of expansion and does not have
125 -- any direct ABE ramifications.
127 -- * Call marker - A special node used to indicate the presence of a call
128 -- in the tree in case expansion transforms or eliminates the original
129 -- call. N_Call_Marker nodes do not have static and run-time semantics.
131 -- * Conditional ABE - A type of ABE. A conditional ABE occurs when the
132 -- elaboration or invocation of a target by a scenario within the main
133 -- unit causes an ABE, but does not cause an ABE for another scenarios
134 -- within the main unit.
136 -- * Declaration level - A type of enclosing level. A scenario or target is
137 -- at the declaration level when it appears within the declarations of a
138 -- block statement, entry body, subprogram body, or task body, ignoring
139 -- enclosing packages.
141 -- * Early call region - A section of code which ends at a subprogram body
142 -- and starts from the nearest non-preelaborable construct which precedes
143 -- the subprogram body. The early call region extends from a package body
144 -- to a package spec when the spec carries pragma Elaborate_Body.
146 -- * Generic library level - A type of enclosing level. A scenario or
147 -- target is at the generic library level if it appears in a generic
148 -- package library unit, ignoring enclosing packages.
150 -- * Guaranteed ABE - A type of ABE. A guaranteed ABE occurs when the
151 -- elaboration or invocation of a target by all scenarios within the
152 -- main unit causes an ABE.
154 -- * Instantiation library level - A type of enclosing level. A scenario
155 -- or target is at the instantiation library level if it appears in an
156 -- instantiation library unit, ignoring enclosing packages.
158 -- * Library level - A type of enclosing level. A scenario or target is at
159 -- the library level if it appears in a package library unit, ignoring
160 -- enclosng packages.
162 -- * Non-library-level encapsulator - A construct that cannot be elaborated
163 -- on its own and requires elaboration by a top-level scenario.
165 -- * Scenario - A construct or context which may be elaborated or executed
166 -- by elaboration code. The scenarios recognized by the ABE mechanism are
169 -- - '[Unrestricted_]Access of entries, operators, and subprograms
171 -- - Assignments to variables
173 -- - Calls to entries, operators, and subprograms
175 -- - Derived type declarations
179 -- - Pragma Refined_State
181 -- - Reads of variables
185 -- * Target - A construct referenced by a scenario. The targets recognized
186 -- by the ABE mechanism are as follows:
188 -- - For '[Unrestricted_]Access of entries, operators, and subprograms,
189 -- the target is the entry, operator, or subprogram.
191 -- - For assignments to variables, the target is the variable
193 -- - For calls, the target is the entry, operator, or subprogram
195 -- - For derived type declarations, the target is the derived type
197 -- - For instantiations, the target is the generic template
199 -- - For pragma Refined_State, the targets are the constituents
201 -- - For reads of variables, the target is the variable
203 -- - For task activation, the target is the task body
205 -- * Top-level scenario - A scenario which appears in a non-generic main
206 -- unit. Depending on the elaboration model is in effect, the following
207 -- addotional restrictions apply:
209 -- - Dynamic model - No restrictions
211 -- - SPARK model - Falls back to either the dynamic or static model
213 -- - Static model - The scenario must be at the library level
215 ---------------------
216 -- Recording phase --
217 ---------------------
219 -- The Recording phase coincides with the analysis/resolution phase of the
220 -- compiler. It has the following objectives:
222 -- * Record all top-level scenarios for examination by the Processing
225 -- Saving only a certain number of nodes improves the performance of
226 -- the ABE mechanism. This eliminates the need to examine the whole
227 -- tree in a separate pass.
229 -- * Record certain SPARK scenarios which are not necessarily executable
230 -- during elaboration, but still require elaboration-related checks.
232 -- Saving only a certain number of nodes improves the performance of
233 -- the ABE mechanism. This eliminates the need to examine the whole
234 -- tree in a separate pass.
236 -- * Detect and diagnose calls in preelaborable or pure units, including
239 -- This diagnostic is carried out during the Recording phase because it
240 -- does not need the heavy recursive traversal done by the Processing
243 -- * Detect and diagnose guaranteed ABEs caused by instantiations,
244 -- calls, and task activation.
246 -- The issues detected by the ABE mechanism are reported as warnings
247 -- because they do not violate Ada semantics. Forward instantiations
248 -- may thus reach gigi, however gigi cannot handle certain kinds of
249 -- premature instantiations and may crash. To avoid this limitation,
250 -- the ABE mechanism must identify forward instantiations as early as
251 -- possible and suppress their bodies. Calls and task activations are
252 -- included in this category for completeness.
254 ----------------------
255 -- Processing phase --
256 ----------------------
258 -- The Processing phase is a separate pass which starts after instantiating
259 -- and/or inlining of bodies, but before the removal of Ghost code. It has
260 -- the following objectives:
262 -- * Examine all top-level scenarios saved during the Recording phase
264 -- The top-level scenarios act as roots for depth-first traversal of
265 -- the call/instantiation/task activation graph. The traversal stops
266 -- when an outgoing edge leaves the main unit.
268 -- * Examine all SPARK scenarios saved during the Recording phase
270 -- * Depending on the elaboration model in effect, perform the following
273 -- - Dynamic model - Install run-time conditional ABE checks.
275 -- - SPARK model - Enforce the SPARK elaboration rules
277 -- - Static model - Diagnose conditional ABEs, install run-time
278 -- conditional ABE checks, and guarantee the elaboration of
281 -- * Examine nested scenarios
283 -- Nested scenarios discovered during the depth-first traversal are
284 -- in turn subjected to the same actions outlined above and examined
285 -- for the next level of nested scenarios.
291 -- Analysis/Resolution
293 -- +- Build_Call_Marker
295 -- +- Build_Variable_Reference_Marker
297 -- +- | -------------------- Recording phase ---------------------------+
299 -- | Record_Elaboration_Scenario |
301 -- | +--> Check_Preelaborated_Call |
303 -- | +--> Process_Guaranteed_ABE |
305 -- | | +--> Process_Guaranteed_ABE_Activation |
307 -- | | +--> Process_Guaranteed_ABE_Call |
309 -- | | +--> Process_Guaranteed_ABE_Instantiation |
311 -- +- | ----------------------------------------------------------------+
314 -- +--> SPARK_Scenarios
315 -- | +-----------+-----------+ .. +-----------+
316 -- | | Scenario1 | Scenario2 | .. | ScenarioN |
317 -- | +-----------+-----------+ .. +-----------+
319 -- +--> Top_Level_Scenarios
320 -- | +-----------+-----------+ .. +-----------+
321 -- | | Scenario1 | Scenario2 | .. | ScenarioN |
322 -- | +-----------+-----------+ .. +-----------+
324 -- End of Compilation
326 -- +- | --------------------- Processing phase -------------------------+
328 -- | Check_Elaboration_Scenarios |
330 -- | +--> Check_SPARK_Scenario |
332 -- | | +--> Check_SPARK_Derived_Type |
334 -- | | +--> Check_SPARK_Instantiation |
336 -- | | +--> Check_SPARK_Refined_State_Pragma |
338 -- | +--> Process_Conditional_ABE <---------------------------+ |
340 -- | +--> Process_Conditional_ABE_Access Is_Suitable_Scenario |
342 -- | +--> Process_Conditional_ABE_Activation | |
344 -- | | +-----------------------------+ | |
346 -- | +--> Process_Conditional_ABE_Call +--------> Traverse_Body |
348 -- | | +-----------------------------+ |
350 -- | +--> Process_Conditional_ABE_Instantiation |
352 -- | +--> Process_Conditional_ABE_Variable_Assignment |
354 -- | +--> Process_Conditional_ABE_Variable_Reference |
356 -- +--------------------------------------------------------------------+
358 ----------------------
359 -- Important points --
360 ----------------------
362 -- The Processing phase starts after the analysis, resolution, expansion
363 -- phase has completed. As a result, no current semantic information is
364 -- available. The scope stack is empty, global flags such as In_Instance
365 -- or Inside_A_Generic become useless. To remedy this, the ABE mechanism
366 -- must either save or recompute semantic information.
368 -- Expansion heavily transforms calls and to some extent instantiations. To
369 -- remedy this, the ABE mechanism generates N_Call_Marker nodes in order to
370 -- capture the target and relevant attributes of the original call.
372 -- The diagnostics of the ABE mechanism depend on accurate source locations
373 -- to determine the spacial relation of nodes.
379 -- The following switches may be used to control the behavior of the ABE
382 -- -gnatd_a stop elaboration checks on accept or select statement
384 -- The ABE mechanism stops the traversal of a task body when it
385 -- encounters an accept or a select statement. This behavior is
386 -- equivalent to restriction No_Entry_Calls_In_Elaboration_Code,
387 -- but without penalizing actual entry calls during elaboration.
389 -- -gnatd_e ignore entry calls and requeue statements for elaboration
391 -- The ABE mechanism does not generate N_Call_Marker nodes for
392 -- protected or task entry calls as well as requeue statements.
393 -- As a result, the calls and requeues are not recorded or
396 -- -gnatdE elaboration checks on predefined units
398 -- The ABE mechanism considers scenarios which appear in internal
399 -- units (Ada, GNAT, Interfaces, System).
401 -- -gnatd.G ignore calls through generic formal parameters for elaboration
403 -- The ABE mechanism does not generate N_Call_Marker nodes for
404 -- calls which occur in expanded instances, and invoke generic
405 -- actual subprograms through generic formal subprograms. As a
406 -- result, the calls are not recorded or processed.
408 -- -gnatdL ignore activations and calls to instances for elaboration
410 -- The ABE mechanism ignores calls and task activations when they
411 -- target a subprogram or task type defined an external instance.
412 -- As a result, the calls and task activations are not processed.
414 -- -gnatd.o conservative elaboration order for indirect calls
416 -- The ABE mechanism treats '[Unrestricted_]Access of an entry,
417 -- operator, or subprogram as an immediate invocation of the
418 -- target. As a result, it performs ABE checks and diagnostics on
419 -- the immediate call.
421 -- -gnatd_p ignore assertion pragmas for elaboration
423 -- The ABE mechanism does not generate N_Call_Marker nodes for
424 -- calls to subprograms which verify the run-time semantics of
425 -- the following assertion pragmas:
427 -- Default_Initial_Condition
435 -- Type_Invariant_Class
437 -- As a result, the assertion expressions of the pragmas are not
440 -- -gnatd.U ignore indirect calls for static elaboration
442 -- The ABE mechanism does not consider '[Unrestricted_]Access of
443 -- entries, operators, and subprograms. As a result, the scenarios
444 -- are not recorder or processed.
446 -- -gnatd.v enforce SPARK elaboration rules in SPARK code
448 -- The ABE mechanism applies some of the SPARK elaboration rules
449 -- defined in the SPARK reference manual, chapter 7.7. Note that
450 -- certain rules are always enforced, regardless of whether the
453 -- -gnatd.y disable implicit pragma Elaborate_All on task bodies
455 -- The ABE mechanism does not generate implicit Elaborate_All when
456 -- the need for the pragma came from a task body.
458 -- -gnatE dynamic elaboration checking mode enabled
460 -- The ABE mechanism assumes that any scenario is elaborated or
461 -- invoked by elaboration code. The ABE mechanism performs very
462 -- little diagnostics and generates condintional ABE checks to
463 -- detect ABE issues at run-time.
465 -- -gnatel turn on info messages on generated Elaborate[_All] pragmas
467 -- The ABE mechanism produces information messages on generated
468 -- implicit Elabote[_All] pragmas along with traceback showing
469 -- why the pragma was generated. In addition, the ABE mechanism
470 -- produces information messages for each scenario elaborated or
471 -- invoked by elaboration code.
473 -- -gnateL turn off info messages on generated Elaborate[_All] pragmas
475 -- The complementary switch for -gnatel.
477 -- -gnatH legacy elaboration checking mode enabled
479 -- When this switch is in effect, the pre-18.x ABE model becomes
480 -- the defacto ABE model. This ammounts to cutting off all entry
481 -- points into the new ABE mechanism, and giving full control to
482 -- the old ABE mechanism.
484 -- -gnatJ permissive elaboration checking mode enabled
486 -- This switch activates the following switches:
496 -- IMPORTANT: The behavior of the ABE mechanism becomes more
497 -- permissive at the cost of accurate diagnostics and runtime
500 -- -gnatw.f turn on warnings for suspicious Subp'Access
502 -- The ABE mechanism treats '[Unrestricted_]Access of an entry,
503 -- operator, or subprogram as a pseudo invocation of the target.
504 -- As a result, it performs ABE diagnostics on the pseudo call.
506 -- -gnatw.F turn off warnings for suspicious Subp'Access
508 -- The complementary switch for -gnatw.f.
510 -- -gnatwl turn on warnings for elaboration problems
512 -- The ABE mechanism produces warnings on detected ABEs along with
513 -- a traceback showing the graph of the ABE.
515 -- -gnatwL turn off warnings for elaboration problems
517 -- The complementary switch for -gnatwl.
519 ---------------------------
520 -- Adding a new scenario --
521 ---------------------------
523 -- The following steps describe how to add a new elaboration scenario and
524 -- preserve the existing architecture. Note that not all of the steps may
525 -- need to be carried out.
527 -- 1) Update predicate Is_Scenario
529 -- 2) Add predicate Is_Suitable_xxx. Include a call to it in predicate
530 -- Is_Suitable_Scenario.
532 -- 3) Update routine Record_Elaboration_Scenario
534 -- 4) Add routine Process_Conditional_ABE_xxx. Include a call to it in
535 -- routine Process_Conditional_ABE.
537 -- 5) Add routine Process_Guaranteed_ABE_xxx. Include a call to it in
538 -- routine Process_Guaranteed_ABE.
540 -- 6) Add routine Check_SPARK_xxx. Include a call to it in routine
541 -- Check_SPARK_Scenario.
543 -- 7) Add routine Info_xxx. Include a call to it in routine
544 -- Process_Conditional_ABE_xxx.
546 -- 8) Add routine Output_xxx. Include a call to it in routine
547 -- Output_Active_Scenarios.
549 -- 9) Add routine Extract_xxx_Attributes
551 -- 10) Update routine Is_Potential_Scenario
553 -------------------------
554 -- Adding a new target --
555 -------------------------
557 -- The following steps describe how to add a new elaboration target and
558 -- preserve the existing architecture. Note that not all of the steps may
559 -- need to be carried out.
561 -- 1) Add predicate Is_xxx.
563 -- 2) Update the following predicates
565 -- Is_Ada_Semantic_Target
566 -- Is_Assertion_Pragma_Target
568 -- Is_SPARK_Semantic_Target
570 -- If necessary, create a new category.
572 -- 3) Update the appropriate Info_xxx routine.
574 -- 4) Update the appropriate Output_xxx routine.
576 -- 5) Update routine Extract_Target_Attributes. If necessary, create a
577 -- new Extract_xxx routine.
579 --------------------------
580 -- Debugging ABE issues --
581 --------------------------
583 -- * If the issue involves a call, ensure that the call is eligible for ABE
584 -- processing and receives a corresponding call marker. The routines of
588 -- Record_Elaboration_Scenario
590 -- * If the issue involves an arbitrary scenario, ensure that the scenario
591 -- is either recorded, or is successfully recognized while traversing a
592 -- body. The routines of interest are
594 -- Record_Elaboration_Scenario
595 -- Process_Conditional_ABE
596 -- Process_Guaranteed_ABE
599 -- * If the issue involves a circularity in the elaboration order, examine
600 -- the ALI files and look for the following encodings next to units:
602 -- E indicates a source Elaborate
604 -- EA indicates a source Elaborate_All
606 -- AD indicates an implicit Elaborate_All
608 -- ED indicates an implicit Elaborate
610 -- If possible, compare these encodings with those generated by the old
611 -- ABE mechanism. The routines of interest are
613 -- Ensure_Prior_Elaboration
619 -- To minimize the amount of code within routines, the ABE mechanism relies
620 -- on "attribute" records to capture relevant information for a scenario or
623 -- The following type captures relevant attributes which pertain to a call
625 type Call_Attributes
is record
626 Elab_Checks_OK
: Boolean;
627 -- This flag is set when the call has elaboration checks enabled
629 Elab_Warnings_OK
: Boolean;
630 -- This flag is set when the call has elaboration warnings elabled
632 From_Source
: Boolean;
633 -- This flag is set when the call comes from source
635 Ghost_Mode_Ignore
: Boolean;
636 -- This flag is set when the call appears in a region subject to pragma
637 -- Ghost with policy Ignore.
639 In_Declarations
: Boolean;
640 -- This flag is set when the call appears at the declaration level
642 Is_Dispatching
: Boolean;
643 -- This flag is set when the call is dispatching
645 SPARK_Mode_On
: Boolean;
646 -- This flag is set when the call appears in a region subject to pragma
647 -- SPARK_Mode with value On.
650 -- The following type captures relevant attributes which pertain to the
651 -- prior elaboration of a unit. This type is coupled together with a unit
652 -- to form a key -> value relationship.
654 type Elaboration_Attributes
is record
655 Source_Pragma
: Node_Id
;
656 -- This attribute denotes a source Elaborate or Elaborate_All pragma
657 -- which guarantees the prior elaboration of some unit with respect
658 -- to the main unit. The pragma may come from the following contexts:
661 -- * The spec of the main unit (if applicable)
662 -- * Any parent spec of the main unit (if applicable)
663 -- * Any parent subunit of the main unit (if applicable)
665 -- The attribute remains Empty if no such pragma is available. Source
666 -- pragmas play a role in satisfying SPARK elaboration requirements.
668 With_Clause
: Node_Id
;
669 -- This attribute denotes an internally generated or source with clause
670 -- for some unit withed by the main unit. With clauses carry flags which
671 -- represent implicit Elaborate or Elaborate_All pragmas. These clauses
672 -- play a role in supplying the elaboration dependencies to binde.
675 No_Elaboration_Attributes
: constant Elaboration_Attributes
:=
676 (Source_Pragma
=> Empty
,
677 With_Clause
=> Empty
);
679 -- The following type captures relevant attributes which pertain to an
682 type Instantiation_Attributes
is record
683 Elab_Checks_OK
: Boolean;
684 -- This flag is set when the instantiation has elaboration checks
687 Elab_Warnings_OK
: Boolean;
688 -- This flag is set when the instantiation has elaboration warnings
691 Ghost_Mode_Ignore
: Boolean;
692 -- This flag is set when the instantiation appears in a region subject
693 -- to pragma Ghost with policy ignore, or starts one such region.
695 In_Declarations
: Boolean;
696 -- This flag is set when the instantiation appears at the declaration
699 SPARK_Mode_On
: Boolean;
700 -- This flag is set when the instantiation appears in a region subject
701 -- to pragma SPARK_Mode with value On, or starts one such region.
704 -- The following type captures relevant attributes which pertain to the
705 -- state of the Processing phase.
707 type Processing_Attributes
is record
708 Suppress_Implicit_Pragmas
: Boolean;
709 -- This flag is set when the Processing phase must not generate any
710 -- implicit Elaborate[_All] pragmas.
712 Within_Initial_Condition
: Boolean;
713 -- This flag is set when the Processing phase is currently examining a
714 -- scenario which was reached from an initial condition procedure.
716 Within_Instance
: Boolean;
717 -- This flag is set when the Processing phase is currently examining a
718 -- scenario which was reached from a scenario defined in an instance.
720 Within_Partial_Finalization
: Boolean;
721 -- This flag is set when the Processing phase is currently examining a
722 -- scenario which was reached from a partial finalization procedure.
724 Within_Task_Body
: Boolean;
725 -- This flag is set when the Processing phase is currently examining a
726 -- scenario which was reached from a task body.
729 Initial_State
: constant Processing_Attributes
:=
730 (Suppress_Implicit_Pragmas
=> False,
731 Within_Initial_Condition
=> False,
732 Within_Instance
=> False,
733 Within_Partial_Finalization
=> False,
734 Within_Task_Body
=> False);
736 -- The following type captures relevant attributes which pertain to a
739 type Target_Attributes
is record
740 Elab_Checks_OK
: Boolean;
741 -- This flag is set when the target has elaboration checks enabled
743 From_Source
: Boolean;
744 -- This flag is set when the target comes from source
746 Ghost_Mode_Ignore
: Boolean;
747 -- This flag is set when the target appears in a region subject to
748 -- pragma Ghost with policy ignore, or starts one such region.
750 SPARK_Mode_On
: Boolean;
751 -- This flag is set when the target appears in a region subject to
752 -- pragma SPARK_Mode with value On, or starts one such region.
755 -- This attribute denotes the declaration of Spec_Id
758 -- This attribute denotes the top unit where Spec_Id resides
760 -- The semantics of the following attributes depend on the target
766 -- The target is a generic package or a subprogram
768 -- * Body_Barf - Empty
770 -- * Body_Decl - This attribute denotes the generic or subprogram
773 -- * Spec_Id - This attribute denotes the entity of the generic
774 -- package or subprogram.
776 -- The target is a protected entry
778 -- * Body_Barf - This attribute denotes the body of the barrier
779 -- function if expansion took place, otherwise it is Empty.
781 -- * Body_Decl - This attribute denotes the body of the procedure
782 -- which emulates the entry if expansion took place, otherwise it
783 -- denotes the body of the protected entry.
785 -- * Spec_Id - This attribute denotes the entity of the procedure
786 -- which emulates the entry if expansion took place, otherwise it
787 -- denotes the protected entry.
789 -- The target is a protected subprogram
791 -- * Body_Barf - Empty
793 -- * Body_Decl - This attribute denotes the body of the protected or
794 -- unprotected version of the protected subprogram if expansion took
795 -- place, otherwise it denotes the body of the protected subprogram.
797 -- * Spec_Id - This attribute denotes the entity of the protected or
798 -- unprotected version of the protected subprogram if expansion took
799 -- place, otherwise it is the entity of the protected subprogram.
801 -- The target is a task entry
803 -- * Body_Barf - Empty
805 -- * Body_Decl - This attribute denotes the body of the procedure
806 -- which emulates the task body if expansion took place, otherwise
807 -- it denotes the body of the task type.
809 -- * Spec_Id - This attribute denotes the entity of the procedure
810 -- which emulates the task body if expansion took place, otherwise
811 -- it denotes the entity of the task type.
814 -- The following type captures relevant attributes which pertain to a task
817 type Task_Attributes
is record
819 -- This attribute denotes the declaration of the procedure body which
820 -- emulates the behaviour of the task body.
822 Elab_Checks_OK
: Boolean;
823 -- This flag is set when the task type has elaboration checks enabled
825 Ghost_Mode_Ignore
: Boolean;
826 -- This flag is set when the task type appears in a region subject to
827 -- pragma Ghost with policy ignore, or starts one such region.
829 SPARK_Mode_On
: Boolean;
830 -- This flag is set when the task type appears in a region subject to
831 -- pragma SPARK_Mode with value On, or starts one such region.
834 -- This attribute denotes the entity of the initial declaration of the
835 -- procedure body which emulates the behaviour of the task body.
838 -- This attribute denotes the declaration of the task type
841 -- This attribute denotes the entity of the compilation unit where the
842 -- task type resides.
845 -- The following type captures relevant attributes which pertain to a
848 type Variable_Attributes
is record
850 -- This attribute denotes the entity of the compilation unit where the
854 ---------------------
855 -- Data structures --
856 ---------------------
858 -- The ABE mechanism employs lists and hash tables to store information
859 -- pertaining to scenarios and targets, as well as the Processing phase.
860 -- The need for data structures comes partly from the size limitation of
861 -- nodes. Note that the use of hash tables is conservative and operations
862 -- are carried out only when a particular hash table has at least one key
863 -- value pair (see xxx_In_Use flags).
865 -- The following table stores the early call regions of subprogram bodies
867 Early_Call_Regions_Max
: constant := 101;
869 type Early_Call_Regions_Index
is range 0 .. Early_Call_Regions_Max
- 1;
871 function Early_Call_Regions_Hash
872 (Key
: Entity_Id
) return Early_Call_Regions_Index
;
873 -- Obtain the hash value of entity Key
875 Early_Call_Regions_In_Use
: Boolean := False;
876 -- This flag determines whether table Early_Call_Regions contains at least
877 -- least one key/value pair.
879 Early_Call_Regions_No_Element
: constant Node_Id
:= Empty
;
881 package Early_Call_Regions
is new Simple_HTable
882 (Header_Num
=> Early_Call_Regions_Index
,
884 No_Element
=> Early_Call_Regions_No_Element
,
886 Hash
=> Early_Call_Regions_Hash
,
889 -- The following table stores the elaboration status of all units withed by
892 Elaboration_Statuses_Max
: constant := 1009;
894 type Elaboration_Statuses_Index
is range 0 .. Elaboration_Statuses_Max
- 1;
896 function Elaboration_Statuses_Hash
897 (Key
: Entity_Id
) return Elaboration_Statuses_Index
;
898 -- Obtain the hash value of entity Key
900 Elaboration_Statuses_In_Use
: Boolean := False;
901 -- This flag flag determines whether table Elaboration_Statuses contains at
902 -- least one key/value pair.
904 Elaboration_Statuses_No_Element
: constant Elaboration_Attributes
:=
905 No_Elaboration_Attributes
;
907 package Elaboration_Statuses
is new Simple_HTable
908 (Header_Num
=> Elaboration_Statuses_Index
,
909 Element
=> Elaboration_Attributes
,
910 No_Element
=> Elaboration_Statuses_No_Element
,
912 Hash
=> Elaboration_Statuses_Hash
,
915 -- The following table stores a status flag for each SPARK scenario saved
916 -- in table SPARK_Scenarios.
918 Recorded_SPARK_Scenarios_Max
: constant := 127;
920 type Recorded_SPARK_Scenarios_Index
is
921 range 0 .. Recorded_SPARK_Scenarios_Max
- 1;
923 function Recorded_SPARK_Scenarios_Hash
924 (Key
: Node_Id
) return Recorded_SPARK_Scenarios_Index
;
925 -- Obtain the hash value of Key
927 Recorded_SPARK_Scenarios_In_Use
: Boolean := False;
928 -- This flag flag determines whether table Recorded_SPARK_Scenarios
929 -- contains at least one key/value pair.
931 Recorded_SPARK_Scenarios_No_Element
: constant Boolean := False;
933 package Recorded_SPARK_Scenarios
is new Simple_HTable
934 (Header_Num
=> Recorded_SPARK_Scenarios_Index
,
936 No_Element
=> Recorded_SPARK_Scenarios_No_Element
,
938 Hash
=> Recorded_SPARK_Scenarios_Hash
,
941 -- The following table stores a status flag for each top-level scenario
942 -- recorded in table Top_Level_Scenarios.
944 Recorded_Top_Level_Scenarios_Max
: constant := 503;
946 type Recorded_Top_Level_Scenarios_Index
is
947 range 0 .. Recorded_Top_Level_Scenarios_Max
- 1;
949 function Recorded_Top_Level_Scenarios_Hash
950 (Key
: Node_Id
) return Recorded_Top_Level_Scenarios_Index
;
951 -- Obtain the hash value of entity Key
953 Recorded_Top_Level_Scenarios_In_Use
: Boolean := False;
954 -- This flag flag determines whether table Recorded_Top_Level_Scenarios
955 -- contains at least one key/value pair.
957 Recorded_Top_Level_Scenarios_No_Element
: constant Boolean := False;
959 package Recorded_Top_Level_Scenarios
is new Simple_HTable
960 (Header_Num
=> Recorded_Top_Level_Scenarios_Index
,
962 No_Element
=> Recorded_Top_Level_Scenarios_No_Element
,
964 Hash
=> Recorded_Top_Level_Scenarios_Hash
,
967 -- The following table stores all active scenarios in a recursive traversal
968 -- starting from a top-level scenario. This table must be maintained in a
971 package Scenario_Stack
is new Table
.Table
972 (Table_Component_Type
=> Node_Id
,
973 Table_Index_Type
=> Int
,
974 Table_Low_Bound
=> 1,
976 Table_Increment
=> 100,
977 Table_Name
=> "Scenario_Stack");
979 -- The following table stores SPARK scenarios which are not necessarily
980 -- executable during elaboration, but still require elaboration-related
983 package SPARK_Scenarios
is new Table
.Table
984 (Table_Component_Type
=> Node_Id
,
985 Table_Index_Type
=> Int
,
986 Table_Low_Bound
=> 1,
988 Table_Increment
=> 100,
989 Table_Name
=> "SPARK_Scenarios");
991 -- The following table stores all top-level scenario saved during the
992 -- Recording phase. The contents of this table act as traversal roots
993 -- later in the Processing phase. This table must be maintained in a
996 package Top_Level_Scenarios
is new Table
.Table
997 (Table_Component_Type
=> Node_Id
,
998 Table_Index_Type
=> Int
,
999 Table_Low_Bound
=> 1,
1000 Table_Initial
=> 1000,
1001 Table_Increment
=> 100,
1002 Table_Name
=> "Top_Level_Scenarios");
1004 -- The following table stores the bodies of all eligible scenarios visited
1005 -- during a traversal starting from a top-level scenario. The contents of
1006 -- this table must be reset upon each new traversal.
1008 Visited_Bodies_Max
: constant := 511;
1010 type Visited_Bodies_Index
is range 0 .. Visited_Bodies_Max
- 1;
1012 function Visited_Bodies_Hash
(Key
: Node_Id
) return Visited_Bodies_Index
;
1013 -- Obtain the hash value of node Key
1015 Visited_Bodies_In_Use
: Boolean := False;
1016 -- This flag determines whether table Visited_Bodies contains at least one
1019 Visited_Bodies_No_Element
: constant Boolean := False;
1021 package Visited_Bodies
is new Simple_HTable
1022 (Header_Num
=> Visited_Bodies_Index
,
1024 No_Element
=> Visited_Bodies_No_Element
,
1026 Hash
=> Visited_Bodies_Hash
,
1029 -----------------------
1030 -- Local subprograms --
1031 -----------------------
1033 -- Multiple local subprograms are utilized to lower the semantic complexity
1034 -- of the Recording and Processing phase.
1036 procedure Check_Preelaborated_Call
(Call
: Node_Id
);
1037 pragma Inline
(Check_Preelaborated_Call
);
1038 -- Verify that entry, operator, or subprogram call Call does not appear at
1039 -- the library level of a preelaborated unit.
1041 procedure Check_SPARK_Derived_Type
(Typ_Decl
: Node_Id
);
1042 pragma Inline
(Check_SPARK_Derived_Type
);
1043 -- Verify that the freeze node of a derived type denoted by declaration
1044 -- Typ_Decl is within the early call region of each overriding primitive
1045 -- body that belongs to the derived type (SPARK RM 7.7(8)).
1047 procedure Check_SPARK_Instantiation
(Exp_Inst
: Node_Id
);
1048 pragma Inline
(Check_SPARK_Instantiation
);
1049 -- Verify that expanded instance Exp_Inst does not precede the generic body
1050 -- it instantiates (SPARK RM 7.7(6)).
1052 procedure Check_SPARK_Model_In_Effect
(N
: Node_Id
);
1053 pragma Inline
(Check_SPARK_Model_In_Effect
);
1054 -- Determine whether a suitable elaboration model is currently in effect
1055 -- for verifying the SPARK rules of scenario N. Emit a warning if this is
1058 procedure Check_SPARK_Scenario
(N
: Node_Id
);
1059 pragma Inline
(Check_SPARK_Scenario
);
1060 -- Top-level dispatcher for verifying SPARK scenarios which are not always
1061 -- executable during elaboration but still need elaboration-related checks.
1063 procedure Check_SPARK_Refined_State_Pragma
(N
: Node_Id
);
1064 pragma Inline
(Check_SPARK_Refined_State_Pragma
);
1065 -- Verify that each constituent of Refined_State pragma N which belongs to
1066 -- an abstract state mentioned in pragma Initializes has prior elaboration
1067 -- with respect to the main unit (SPARK RM 7.7.1(7)).
1069 function Compilation_Unit
(Unit_Id
: Entity_Id
) return Node_Id
;
1070 pragma Inline
(Compilation_Unit
);
1071 -- Return the N_Compilation_Unit node of unit Unit_Id
1073 function Early_Call_Region
(Body_Id
: Entity_Id
) return Node_Id
;
1074 pragma Inline
(Early_Call_Region
);
1075 -- Return the early call region associated with entry or subprogram body
1076 -- Body_Id. IMPORTANT: This routine does not find the early call region.
1077 -- To compute it, use routine Find_Early_Call_Region.
1079 procedure Elab_Msg_NE
1084 In_SPARK
: Boolean);
1085 pragma Inline
(Elab_Msg_NE
);
1086 -- Wrapper around Error_Msg_NE. Emit message Msg concerning arbitrary node
1087 -- N and entity. If flag Info_Msg is set, the routine emits an information
1088 -- message, otherwise it emits an error. If flag In_SPARK is set, then
1089 -- string " in SPARK" is added to the end of the message.
1091 function Elaboration_Status
1092 (Unit_Id
: Entity_Id
) return Elaboration_Attributes
;
1093 pragma Inline
(Elaboration_Status
);
1094 -- Return the set of elaboration attributes associated with unit Unit_Id
1096 procedure Ensure_Prior_Elaboration
1098 Unit_Id
: Entity_Id
;
1100 State
: Processing_Attributes
);
1101 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
1102 -- by installing pragma Elaborate or Elaborate_All denoted by Prag_Nam. N
1103 -- denotes the related scenario. State denotes the current state of the
1104 -- Processing phase.
1106 procedure Ensure_Prior_Elaboration_Dynamic
1108 Unit_Id
: Entity_Id
;
1109 Prag_Nam
: Name_Id
);
1110 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
1111 -- by suggesting the use of Elaborate[_All] with name Prag_Nam. N denotes
1112 -- the related scenario.
1114 procedure Ensure_Prior_Elaboration_Static
1116 Unit_Id
: Entity_Id
;
1117 Prag_Nam
: Name_Id
);
1118 -- Guarantee the elaboration of unit Unit_Id with respect to the main unit
1119 -- by installing an implicit Elaborate[_All] pragma with name Prag_Nam. N
1120 -- denotes the related scenario.
1122 function Extract_Assignment_Name
(Asmt
: Node_Id
) return Node_Id
;
1123 pragma Inline
(Extract_Assignment_Name
);
1124 -- Obtain the Name attribute of assignment statement Asmt
1126 procedure Extract_Call_Attributes
1128 Target_Id
: out Entity_Id
;
1129 Attrs
: out Call_Attributes
);
1130 pragma Inline
(Extract_Call_Attributes
);
1131 -- Obtain attributes Attrs associated with call Call. Target_Id is the
1132 -- entity of the call target.
1134 function Extract_Call_Name
(Call
: Node_Id
) return Node_Id
;
1135 pragma Inline
(Extract_Call_Name
);
1136 -- Obtain the Name attribute of entry or subprogram call Call
1138 procedure Extract_Instance_Attributes
1139 (Exp_Inst
: Node_Id
;
1140 Inst_Body
: out Node_Id
;
1141 Inst_Decl
: out Node_Id
);
1142 pragma Inline
(Extract_Instance_Attributes
);
1143 -- Obtain body Inst_Body and spec Inst_Decl of expanded instance Exp_Inst
1145 procedure Extract_Instantiation_Attributes
1146 (Exp_Inst
: Node_Id
;
1148 Inst_Id
: out Entity_Id
;
1149 Gen_Id
: out Entity_Id
;
1150 Attrs
: out Instantiation_Attributes
);
1151 pragma Inline
(Extract_Instantiation_Attributes
);
1152 -- Obtain attributes Attrs associated with expanded instantiation Exp_Inst.
1153 -- Inst is the instantiation. Inst_Id is the entity of the instance. Gen_Id
1154 -- is the entity of the generic unit being instantiated.
1156 procedure Extract_Target_Attributes
1157 (Target_Id
: Entity_Id
;
1158 Attrs
: out Target_Attributes
);
1159 -- Obtain attributes Attrs associated with an entry, package, or subprogram
1160 -- denoted by Target_Id.
1162 procedure Extract_Task_Attributes
1164 Attrs
: out Task_Attributes
);
1165 pragma Inline
(Extract_Task_Attributes
);
1166 -- Obtain attributes Attrs associated with task type Typ
1168 procedure Extract_Variable_Reference_Attributes
1170 Var_Id
: out Entity_Id
;
1171 Attrs
: out Variable_Attributes
);
1172 pragma Inline
(Extract_Variable_Reference_Attributes
);
1173 -- Obtain attributes Attrs associated with reference Ref that mentions
1176 function Find_Code_Unit
(N
: Node_Or_Entity_Id
) return Entity_Id
;
1177 pragma Inline
(Find_Code_Unit
);
1178 -- Return the code unit which contains arbitrary node or entity N. This
1179 -- is the unit of the file which physically contains the related construct
1180 -- denoted by N except when N is within an instantiation. In that case the
1181 -- unit is that of the top-level instantiation.
1183 function Find_Early_Call_Region
1184 (Body_Decl
: Node_Id
;
1185 Assume_Elab_Body
: Boolean := False;
1186 Skip_Memoization
: Boolean := False) return Node_Id
;
1187 -- Find the start of the early call region which belongs to subprogram body
1188 -- Body_Decl as defined in SPARK RM 7.7. The behavior of the routine is to
1189 -- find the early call region, memoize it, and return it, but this behavior
1190 -- can be altered. Flag Assume_Elab_Body should be set when a package spec
1191 -- may lack pragma Elaborate_Body, but the routine must still examine that
1192 -- spec. Flag Skip_Memoization should be set when the routine must avoid
1193 -- memoizing the region.
1195 procedure Find_Elaborated_Units
;
1196 -- Populate table Elaboration_Statuses with all units which have prior
1197 -- elaboration with respect to the main unit.
1199 function Find_Enclosing_Instance
(N
: Node_Id
) return Node_Id
;
1200 pragma Inline
(Find_Enclosing_Instance
);
1201 -- Find the declaration or body of the nearest expanded instance which
1202 -- encloses arbitrary node N. Return Empty if no such instance exists.
1204 function Find_Top_Unit
(N
: Node_Or_Entity_Id
) return Entity_Id
;
1205 pragma Inline
(Find_Top_Unit
);
1206 -- Return the top unit which contains arbitrary node or entity N. The unit
1207 -- is obtained by logically unwinding instantiations and subunits when N
1208 -- resides within one.
1210 function Find_Unit_Entity
(N
: Node_Id
) return Entity_Id
;
1211 pragma Inline
(Find_Unit_Entity
);
1212 -- Return the entity of unit N
1214 function First_Formal_Type
(Subp_Id
: Entity_Id
) return Entity_Id
;
1215 pragma Inline
(First_Formal_Type
);
1216 -- Return the type of subprogram Subp_Id's first formal parameter. If the
1217 -- subprogram lacks formal parameters, return Empty.
1219 function Has_Body
(Pack_Decl
: Node_Id
) return Boolean;
1220 -- Determine whether package declaration Pack_Decl has a corresponding body
1221 -- or would eventually have one.
1223 function Has_Prior_Elaboration
1224 (Unit_Id
: Entity_Id
;
1225 Context_OK
: Boolean := False;
1226 Elab_Body_OK
: Boolean := False;
1227 Same_Unit_OK
: Boolean := False) return Boolean;
1228 pragma Inline
(Has_Prior_Elaboration
);
1229 -- Determine whether unit Unit_Id is elaborated prior to the main unit.
1230 -- If flag Context_OK is set, the routine considers the following case
1231 -- as valid prior elaboration:
1233 -- * Unit_Id is in the elaboration context of the main unit
1235 -- If flag Elab_Body_OK is set, the routine considers the following case
1236 -- as valid prior elaboration:
1238 -- * Unit_Id has pragma Elaborate_Body and is not the main unit
1240 -- If flag Same_Unit_OK is set, the routine considers the following cases
1241 -- as valid prior elaboration:
1243 -- * Unit_Id is the main unit
1245 -- * Unit_Id denotes the spec of the main unit body
1247 function In_External_Instance
1249 Target_Decl
: Node_Id
) return Boolean;
1250 pragma Inline
(In_External_Instance
);
1251 -- Determine whether a target desctibed by its declaration Target_Decl
1252 -- resides in a package instance which is external to scenario N.
1254 function In_Main_Context
(N
: Node_Id
) return Boolean;
1255 pragma Inline
(In_Main_Context
);
1256 -- Determine whether arbitrary node N appears within the main compilation
1259 function In_Same_Context
1262 Nested_OK
: Boolean := False) return Boolean;
1263 -- Determine whether two arbitrary nodes N1 and N2 appear within the same
1264 -- context ignoring enclosing library levels. Nested_OK should be set when
1265 -- the context of N1 can enclose that of N2.
1269 Target_Id
: Entity_Id
;
1271 In_SPARK
: Boolean);
1272 -- Output information concerning call Call which invokes target Target_Id.
1273 -- If flag Info_Msg is set, the routine emits an information message,
1274 -- otherwise it emits an error. If flag In_SPARK is set, then the string
1275 -- " in SPARK" is added to the end of the message.
1277 procedure Info_Instantiation
1281 In_SPARK
: Boolean);
1282 pragma Inline
(Info_Instantiation
);
1283 -- Output information concerning instantiation Inst which instantiates
1284 -- generic unit Gen_Id. If flag Info_Msg is set, the routine emits an
1285 -- information message, otherwise it emits an error. If flag In_SPARK
1286 -- is set, then string " in SPARK" is added to the end of the message.
1288 procedure Info_Variable_Reference
1292 In_SPARK
: Boolean);
1293 pragma Inline
(Info_Variable_Reference
);
1294 -- Output information concerning reference Ref which mentions variable
1295 -- Var_Id. If flag Info_Msg is set, the routine emits an information
1296 -- message, otherwise it emits an error. If flag In_SPARK is set, then
1297 -- string " in SPARK" is added to the end of the message.
1299 function Insertion_Node
(N
: Node_Id
; Ins_Nod
: Node_Id
) return Node_Id
;
1300 pragma Inline
(Insertion_Node
);
1301 -- Obtain the proper insertion node of an ABE check or failure for scenario
1302 -- N and candidate insertion node Ins_Nod.
1304 procedure Install_ABE_Check
1308 -- Insert a run-time ABE check for elaboration scenario N which verifies
1309 -- whether arbitrary entity Id is elaborated. The check in inserted prior
1312 procedure Install_ABE_Check
1314 Target_Id
: Entity_Id
;
1315 Target_Decl
: Node_Id
;
1316 Target_Body
: Node_Id
;
1318 -- Insert a run-time ABE check for elaboration scenario N which verifies
1319 -- whether target Target_Id with initial declaration Target_Decl and body
1320 -- Target_Body is elaborated. The check is inserted prior to node Ins_Nod.
1322 procedure Install_ABE_Failure
(N
: Node_Id
; Ins_Nod
: Node_Id
);
1323 -- Insert a Program_Error concerning a guaranteed ABE for elaboration
1324 -- scenario N. The failure is inserted prior to node Node_Id.
1326 function Is_Accept_Alternative_Proc
(Id
: Entity_Id
) return Boolean;
1327 pragma Inline
(Is_Accept_Alternative_Proc
);
1328 -- Determine whether arbitrary entity Id denotes an internally generated
1329 -- procedure which encapsulates the statements of an accept alternative.
1331 function Is_Activation_Proc
(Id
: Entity_Id
) return Boolean;
1332 pragma Inline
(Is_Activation_Proc
);
1333 -- Determine whether arbitrary entity Id denotes a runtime procedure in
1334 -- charge with activating tasks.
1336 function Is_Ada_Semantic_Target
(Id
: Entity_Id
) return Boolean;
1337 pragma Inline
(Is_Ada_Semantic_Target
);
1338 -- Determine whether arbitrary entity Id denodes a source or internally
1339 -- generated subprogram which emulates Ada semantics.
1341 function Is_Assertion_Pragma_Target
(Id
: Entity_Id
) return Boolean;
1342 pragma Inline
(Is_Assertion_Pragma_Target
);
1343 -- Determine whether arbitrary entity Id denotes a procedure which varifies
1344 -- the run-time semantics of an assertion pragma.
1346 function Is_Bodiless_Subprogram
(Subp_Id
: Entity_Id
) return Boolean;
1347 pragma Inline
(Is_Bodiless_Subprogram
);
1348 -- Determine whether subprogram Subp_Id will never have a body
1350 function Is_Controlled_Proc
1351 (Subp_Id
: Entity_Id
;
1352 Subp_Nam
: Name_Id
) return Boolean;
1353 pragma Inline
(Is_Controlled_Proc
);
1354 -- Determine whether subprogram Subp_Id denotes controlled type primitives
1355 -- Adjust, Finalize, or Initialize as denoted by name Subp_Nam.
1357 function Is_Default_Initial_Condition_Proc
(Id
: Entity_Id
) return Boolean;
1358 pragma Inline
(Is_Default_Initial_Condition_Proc
);
1359 -- Determine whether arbitrary entity Id denotes internally generated
1360 -- routine Default_Initial_Condition.
1362 function Is_Finalizer_Proc
(Id
: Entity_Id
) return Boolean;
1363 pragma Inline
(Is_Finalizer_Proc
);
1364 -- Determine whether arbitrary entity Id denotes internally generated
1365 -- routine _Finalizer.
1367 function Is_Guaranteed_ABE
1369 Target_Decl
: Node_Id
;
1370 Target_Body
: Node_Id
) return Boolean;
1371 pragma Inline
(Is_Guaranteed_ABE
);
1372 -- Determine whether scenario N with a target described by its initial
1373 -- declaration Target_Decl and body Target_Decl results in a guaranteed
1376 function Is_Initial_Condition_Proc
(Id
: Entity_Id
) return Boolean;
1377 pragma Inline
(Is_Initial_Condition_Proc
);
1378 -- Determine whether arbitrary entity Id denotes internally generated
1379 -- routine Initial_Condition.
1381 function Is_Initialized
(Obj_Decl
: Node_Id
) return Boolean;
1382 pragma Inline
(Is_Initialized
);
1383 -- Determine whether object declaration Obj_Decl is initialized
1385 function Is_Invariant_Proc
(Id
: Entity_Id
) return Boolean;
1386 pragma Inline
(Is_Invariant_Proc
);
1387 -- Determine whether arbitrary entity Id denotes an invariant procedure
1389 function Is_Non_Library_Level_Encapsulator
(N
: Node_Id
) return Boolean;
1390 pragma Inline
(Is_Non_Library_Level_Encapsulator
);
1391 -- Determine whether arbitrary node N is a non-library encapsulator
1393 function Is_Partial_Invariant_Proc
(Id
: Entity_Id
) return Boolean;
1394 pragma Inline
(Is_Partial_Invariant_Proc
);
1395 -- Determine whether arbitrary entity Id denotes a partial invariant
1398 function Is_Postconditions_Proc
(Id
: Entity_Id
) return Boolean;
1399 pragma Inline
(Is_Postconditions_Proc
);
1400 -- Determine whether arbitrary entity Id denotes internally generated
1401 -- routine _Postconditions.
1403 function Is_Preelaborated_Unit
(Id
: Entity_Id
) return Boolean;
1404 pragma Inline
(Is_Preelaborated_Unit
);
1405 -- Determine whether arbitrary entity Id denotes a unit which is subject to
1406 -- one of the following pragmas:
1410 -- * Remote_Call_Interface
1414 function Is_Protected_Entry
(Id
: Entity_Id
) return Boolean;
1415 pragma Inline
(Is_Protected_Entry
);
1416 -- Determine whether arbitrary entity Id denotes a protected entry
1418 function Is_Protected_Subp
(Id
: Entity_Id
) return Boolean;
1419 pragma Inline
(Is_Protected_Subp
);
1420 -- Determine whether entity Id denotes a protected subprogram
1422 function Is_Protected_Body_Subp
(Id
: Entity_Id
) return Boolean;
1423 pragma Inline
(Is_Protected_Body_Subp
);
1424 -- Determine whether entity Id denotes the protected or unprotected version
1425 -- of a protected subprogram.
1427 function Is_Recorded_SPARK_Scenario
(N
: Node_Id
) return Boolean;
1428 pragma Inline
(Is_Recorded_SPARK_Scenario
);
1429 -- Determine whether arbitrary node N is a recorded SPARK scenario which
1430 -- appears in table SPARK_Scenarios.
1432 function Is_Recorded_Top_Level_Scenario
(N
: Node_Id
) return Boolean;
1433 pragma Inline
(Is_Recorded_Top_Level_Scenario
);
1434 -- Determine whether arbitrary node N is a recorded top-level scenario
1435 -- which appears in table Top_Level_Scenarios.
1437 function Is_Safe_Activation
1439 Task_Decl
: Node_Id
) return Boolean;
1440 pragma Inline
(Is_Safe_Activation
);
1441 -- Determine whether call Call which activates a task object described by
1442 -- declaration Task_Decl is always ABE-safe.
1444 function Is_Safe_Call
1446 Target_Attrs
: Target_Attributes
) return Boolean;
1447 pragma Inline
(Is_Safe_Call
);
1448 -- Determine whether call Call which invokes a target described by
1449 -- attributes Target_Attrs is always ABE-safe.
1451 function Is_Safe_Instantiation
1453 Gen_Attrs
: Target_Attributes
) return Boolean;
1454 pragma Inline
(Is_Safe_Instantiation
);
1455 -- Determine whether instance Inst which instantiates a generic unit
1456 -- described by attributes Gen_Attrs is always ABE-safe.
1458 function Is_Same_Unit
1459 (Unit_1
: Entity_Id
;
1460 Unit_2
: Entity_Id
) return Boolean;
1461 pragma Inline
(Is_Same_Unit
);
1462 -- Determine whether entities Unit_1 and Unit_2 denote the same unit
1464 function Is_Scenario
(N
: Node_Id
) return Boolean;
1465 pragma Inline
(Is_Scenario
);
1466 -- Determine whether attribute node N denotes a scenario. The scenario may
1467 -- not necessarily be eligible for ABE processing.
1469 function Is_SPARK_Semantic_Target
(Id
: Entity_Id
) return Boolean;
1470 pragma Inline
(Is_SPARK_Semantic_Target
);
1471 -- Determine whether arbitrary entity Id nodes a source or internally
1472 -- generated subprogram which emulates SPARK semantics.
1474 function Is_Suitable_Access
(N
: Node_Id
) return Boolean;
1475 pragma Inline
(Is_Suitable_Access
);
1476 -- Determine whether arbitrary node N denotes a suitable attribute for ABE
1479 function Is_Suitable_Call
(N
: Node_Id
) return Boolean;
1480 pragma Inline
(Is_Suitable_Call
);
1481 -- Determine whether arbitrary node N denotes a suitable call for ABE
1484 function Is_Suitable_Instantiation
(N
: Node_Id
) return Boolean;
1485 pragma Inline
(Is_Suitable_Instantiation
);
1486 -- Determine whether arbitrary node N is a suitable instantiation for ABE
1489 function Is_Suitable_Scenario
(N
: Node_Id
) return Boolean;
1490 pragma Inline
(Is_Suitable_Scenario
);
1491 -- Determine whether arbitrary node N is a suitable scenario for ABE
1494 function Is_Suitable_SPARK_Derived_Type
(N
: Node_Id
) return Boolean;
1495 pragma Inline
(Is_Suitable_SPARK_Derived_Type
);
1496 -- Determine whether arbitrary node N denotes a suitable derived type
1497 -- declaration for ABE processing using the SPARK rules.
1499 function Is_Suitable_SPARK_Instantiation
(N
: Node_Id
) return Boolean;
1500 pragma Inline
(Is_Suitable_SPARK_Instantiation
);
1501 -- Determine whether arbitrary node N denotes a suitable instantiation for
1502 -- ABE processing using the SPARK rules.
1504 function Is_Suitable_SPARK_Refined_State_Pragma
1505 (N
: Node_Id
) return Boolean;
1506 pragma Inline
(Is_Suitable_SPARK_Refined_State_Pragma
);
1507 -- Determine whether arbitrary node N denotes a suitable Refined_State
1508 -- pragma for ABE processing using the SPARK rules.
1510 function Is_Suitable_Variable_Assignment
(N
: Node_Id
) return Boolean;
1511 pragma Inline
(Is_Suitable_Variable_Assignment
);
1512 -- Determine whether arbitrary node N denotes a suitable assignment for ABE
1515 function Is_Suitable_Variable_Reference
(N
: Node_Id
) return Boolean;
1516 pragma Inline
(Is_Suitable_Variable_Reference
);
1517 -- Determine whether arbitrary node N is a suitable variable reference for
1520 function Is_Task_Entry
(Id
: Entity_Id
) return Boolean;
1521 pragma Inline
(Is_Task_Entry
);
1522 -- Determine whether arbitrary entity Id denotes a task entry
1524 function Is_Up_Level_Target
(Target_Decl
: Node_Id
) return Boolean;
1525 pragma Inline
(Is_Up_Level_Target
);
1526 -- Determine whether the current root resides at the declaration level. If
1527 -- this is the case, determine whether a target described by declaration
1528 -- Target_Decl is within a context which encloses the current root or is in
1529 -- a different unit.
1531 function Is_Visited_Body
(Body_Decl
: Node_Id
) return Boolean;
1532 pragma Inline
(Is_Visited_Body
);
1533 -- Determine whether subprogram body Body_Decl is already visited during a
1534 -- recursive traversal started from a top-level scenario.
1536 procedure Meet_Elaboration_Requirement
1538 Target_Id
: Entity_Id
;
1540 -- Determine whether elaboration requirement Req_Nam for scenario N with
1541 -- target Target_Id is met by the context of the main unit using the SPARK
1542 -- rules. Req_Nam must denote either Elaborate or Elaborate_All. Emit an
1543 -- error if this is not the case.
1545 function Non_Private_View
(Typ
: Entity_Id
) return Entity_Id
;
1546 pragma Inline
(Non_Private_View
);
1547 -- Return the full view of private type Typ if available, otherwise return
1550 procedure Output_Active_Scenarios
(Error_Nod
: Node_Id
);
1551 -- Output the contents of the active scenario stack from earliest to latest
1552 -- to supplement an earlier error emitted for node Error_Nod.
1554 procedure Pop_Active_Scenario
(N
: Node_Id
);
1555 pragma Inline
(Pop_Active_Scenario
);
1556 -- Pop the top of the scenario stack. A check is made to ensure that the
1557 -- scenario being removed is the same as N.
1560 with procedure Process_Single_Activation
1562 Call_Attrs
: Call_Attributes
;
1564 Task_Attrs
: Task_Attributes
;
1565 State
: Processing_Attributes
);
1566 -- Perform ABE checks and diagnostics for task activation call Call
1567 -- which activates task Obj_Id. Call_Attrs are the attributes of the
1568 -- activation call. Task_Attrs are the attributes of the task type.
1569 -- State is the current state of the Processing phase.
1571 procedure Process_Activation_Generic
1573 Call_Attrs
: Call_Attributes
;
1574 State
: Processing_Attributes
);
1575 -- Perform ABE checks and diagnostics for activation call Call by invoking
1576 -- routine Process_Single_Activation on each task object being activated.
1577 -- Call_Attrs are the attributes of the activation call. State is the
1578 -- current state of the Processing phase.
1580 procedure Process_Conditional_ABE
1582 State
: Processing_Attributes
:= Initial_State
);
1583 -- Top-level dispatcher for processing of various elaboration scenarios.
1584 -- Perform conditional ABE checks and diagnostics for scenario N. State
1585 -- is the current state of the Processing phase.
1587 procedure Process_Conditional_ABE_Access
1589 State
: Processing_Attributes
);
1590 -- Perform ABE checks and diagnostics for 'Access to entry, operator, or
1591 -- subprogram denoted by Attr. State is the current state of the Processing
1594 procedure Process_Conditional_ABE_Activation_Impl
1596 Call_Attrs
: Call_Attributes
;
1598 Task_Attrs
: Task_Attributes
;
1599 State
: Processing_Attributes
);
1600 -- Perform common conditional ABE checks and diagnostics for call Call
1601 -- which activates task Obj_Id ignoring the Ada or SPARK rules. Call_Attrs
1602 -- are the attributes of the activation call. Task_Attrs are the attributes
1603 -- of the task type. State is the current state of the Processing phase.
1605 procedure Process_Conditional_ABE_Call
1607 Call_Attrs
: Call_Attributes
;
1608 Target_Id
: Entity_Id
;
1609 State
: Processing_Attributes
);
1610 -- Top-level dispatcher for processing of calls. Perform ABE checks and
1611 -- diagnostics for call Call which invokes target Target_Id. Call_Attrs
1612 -- are the attributes of the call. State is the current state of the
1613 -- Processing phase.
1615 procedure Process_Conditional_ABE_Call_Ada
1617 Call_Attrs
: Call_Attributes
;
1618 Target_Id
: Entity_Id
;
1619 Target_Attrs
: Target_Attributes
;
1620 State
: Processing_Attributes
);
1621 -- Perform ABE checks and diagnostics for call Call which invokes target
1622 -- Target_Id using the Ada rules. Call_Attrs are the attributes of the
1623 -- call. Target_Attrs are attributes of the target. State is the current
1624 -- state of the Processing phase.
1626 procedure Process_Conditional_ABE_Call_SPARK
1628 Target_Id
: Entity_Id
;
1629 Target_Attrs
: Target_Attributes
;
1630 State
: Processing_Attributes
);
1631 -- Perform ABE checks and diagnostics for call Call which invokes target
1632 -- Target_Id using the SPARK rules. Target_Attrs denotes the attributes of
1633 -- the target. State is the current state of the Processing phase.
1635 procedure Process_Conditional_ABE_Instantiation
1636 (Exp_Inst
: Node_Id
;
1637 State
: Processing_Attributes
);
1638 -- Top-level dispatcher for processing of instantiations. Perform ABE
1639 -- checks and diagnostics for expanded instantiation Exp_Inst. State is
1640 -- the current state of the Processing phase.
1642 procedure Process_Conditional_ABE_Instantiation_Ada
1643 (Exp_Inst
: Node_Id
;
1645 Inst_Attrs
: Instantiation_Attributes
;
1647 Gen_Attrs
: Target_Attributes
;
1648 State
: Processing_Attributes
);
1649 -- Perform ABE checks and diagnostics for expanded instantiation Exp_Inst
1650 -- of generic Gen_Id using the Ada rules. Inst is the instantiation node.
1651 -- Inst_Attrs are the attributes of the instance. Gen_Attrs denotes the
1652 -- attributes of the generic. State is the current state of the Processing
1655 procedure Process_Conditional_ABE_Instantiation_SPARK
1658 Gen_Attrs
: Target_Attributes
;
1659 State
: Processing_Attributes
);
1660 -- Perform ABE checks and diagnostics for instantiation Inst of generic
1661 -- Gen_Id using the SPARK rules. Gen_Attrs denotes the attributes of the
1662 -- generic. State is the current state of the Processing phase.
1664 procedure Process_Conditional_ABE_Variable_Assignment
(Asmt
: Node_Id
);
1665 -- Top-level dispatcher for processing of variable assignments. Perform ABE
1666 -- checks and diagnostics for assignment statement Asmt.
1668 procedure Process_Conditional_ABE_Variable_Assignment_Ada
1670 Var_Id
: Entity_Id
);
1671 -- Perform ABE checks and diagnostics for assignment statement Asmt that
1672 -- updates the value of variable Var_Id using the Ada rules.
1674 procedure Process_Conditional_ABE_Variable_Assignment_SPARK
1676 Var_Id
: Entity_Id
);
1677 -- Perform ABE checks and diagnostics for assignment statement Asmt that
1678 -- updates the value of variable Var_Id using the SPARK rules.
1680 procedure Process_Conditional_ABE_Variable_Reference
(Ref
: Node_Id
);
1681 -- Top-level dispatcher for processing of variable references. Perform ABE
1682 -- checks and diagnostics for variable reference Ref.
1684 procedure Process_Conditional_ABE_Variable_Reference_Read
1687 Attrs
: Variable_Attributes
);
1688 -- Perform ABE checks and diagnostics for reference Ref described by its
1689 -- attributes Attrs, that reads variable Var_Id.
1691 procedure Process_Guaranteed_ABE
(N
: Node_Id
);
1692 -- Top-level dispatcher for processing of scenarios which result in a
1695 procedure Process_Guaranteed_ABE_Activation_Impl
1697 Call_Attrs
: Call_Attributes
;
1699 Task_Attrs
: Task_Attributes
;
1700 State
: Processing_Attributes
);
1701 -- Perform common guaranteed ABE checks and diagnostics for call Call which
1702 -- activates task Obj_Id ignoring the Ada or SPARK rules. Call_Attrs are
1703 -- the attributes of the activation call. Task_Attrs are the attributes of
1704 -- the task type. State is provided for compatibility and is not used.
1706 procedure Process_Guaranteed_ABE_Call
1708 Call_Attrs
: Call_Attributes
;
1709 Target_Id
: Entity_Id
);
1710 -- Perform common guaranteed ABE checks and diagnostics for call Call which
1711 -- invokes target Target_Id ignoring the Ada or SPARK rules. Call_Attrs are
1712 -- the attributes of the call.
1714 procedure Process_Guaranteed_ABE_Instantiation
(Exp_Inst
: Node_Id
);
1715 -- Perform common guaranteed ABE checks and diagnostics for expanded
1716 -- instantiation Exp_Inst of generic Gen_Id ignoring the Ada or SPARK
1719 procedure Push_Active_Scenario
(N
: Node_Id
);
1720 pragma Inline
(Push_Active_Scenario
);
1721 -- Push scenario N on top of the scenario stack
1723 procedure Record_SPARK_Elaboration_Scenario
(N
: Node_Id
);
1724 pragma Inline
(Record_SPARK_Elaboration_Scenario
);
1725 -- Save SPARK scenario N in table SPARK_Scenarios for later processing
1727 procedure Reset_Visited_Bodies
;
1728 pragma Inline
(Reset_Visited_Bodies
);
1729 -- Clear the contents of table Visited_Bodies
1731 function Root_Scenario
return Node_Id
;
1732 pragma Inline
(Root_Scenario
);
1733 -- Return the top-level scenario which started a recursive search for other
1734 -- scenarios. It is assumed that there is a valid top-level scenario on the
1735 -- active scenario stack.
1737 procedure Set_Early_Call_Region
(Body_Id
: Entity_Id
; Start
: Node_Id
);
1738 pragma Inline
(Set_Early_Call_Region
);
1739 -- Associate an early call region with begins at construct Start with entry
1740 -- or subprogram body Body_Id.
1742 procedure Set_Elaboration_Status
1743 (Unit_Id
: Entity_Id
;
1744 Val
: Elaboration_Attributes
);
1745 pragma Inline
(Set_Elaboration_Status
);
1746 -- Associate an set of elaboration attributes with unit Unit_Id
1748 procedure Set_Is_Recorded_SPARK_Scenario
1750 Val
: Boolean := True);
1751 pragma Inline
(Set_Is_Recorded_SPARK_Scenario
);
1752 -- Mark scenario N as being recorded in table SPARK_Scenarios
1754 procedure Set_Is_Recorded_Top_Level_Scenario
1756 Val
: Boolean := True);
1757 pragma Inline
(Set_Is_Recorded_Top_Level_Scenario
);
1758 -- Mark scenario N as being recorded in table Top_Level_Scenarios
1760 procedure Set_Is_Visited_Body
(Subp_Body
: Node_Id
);
1761 pragma Inline
(Set_Is_Visited_Body
);
1762 -- Mark subprogram body Subp_Body as being visited during a recursive
1763 -- traversal started from a top-level scenario.
1765 function Static_Elaboration_Checks
return Boolean;
1766 pragma Inline
(Static_Elaboration_Checks
);
1767 -- Determine whether the static model is in effect
1769 procedure Traverse_Body
(N
: Node_Id
; State
: Processing_Attributes
);
1770 -- Inspect the declarative and statement lists of subprogram body N for
1771 -- suitable elaboration scenarios and process them. State is the current
1772 -- state of the Processing phase.
1774 procedure Update_Elaboration_Scenario
(New_N
: Node_Id
; Old_N
: Node_Id
);
1775 pragma Inline
(Update_Elaboration_Scenario
);
1776 -- Update all relevant internal data structures when scenario Old_N is
1777 -- transformed into scenario New_N by Atree.Rewrite.
1779 -----------------------
1780 -- Build_Call_Marker --
1781 -----------------------
1783 procedure Build_Call_Marker
(N
: Node_Id
) is
1784 function In_Premature_Context
(Call
: Node_Id
) return Boolean;
1785 -- Determine whether call Call appears within a premature context
1787 function Is_Bridge_Target
(Id
: Entity_Id
) return Boolean;
1788 pragma Inline
(Is_Bridge_Target
);
1789 -- Determine whether arbitrary entity Id denotes a bridge target
1791 function Is_Default_Expression
(Call
: Node_Id
) return Boolean;
1792 pragma Inline
(Is_Default_Expression
);
1793 -- Determine whether call Call acts as the expression of a defaulted
1794 -- parameter within a source call.
1796 function Is_Generic_Formal_Subp
(Subp_Id
: Entity_Id
) return Boolean;
1797 pragma Inline
(Is_Generic_Formal_Subp
);
1798 -- Determine whether subprogram Subp_Id denotes a generic formal
1799 -- subprogram which appears in the "prologue" of an instantiation.
1801 --------------------------
1802 -- In_Premature_Context --
1803 --------------------------
1805 function In_Premature_Context
(Call
: Node_Id
) return Boolean is
1809 -- Climb the parent chain looking for premature contexts
1811 Par
:= Parent
(Call
);
1812 while Present
(Par
) loop
1814 -- Aspect specifications and generic associations are premature
1815 -- contexts because nested calls has not been relocated to their
1818 if Nkind_In
(Par
, N_Aspect_Specification
,
1819 N_Generic_Association
)
1823 -- Prevent the search from going too far
1825 elsif Is_Body_Or_Package_Declaration
(Par
) then
1829 Par
:= Parent
(Par
);
1833 end In_Premature_Context
;
1835 ----------------------
1836 -- Is_Bridge_Target --
1837 ----------------------
1839 function Is_Bridge_Target
(Id
: Entity_Id
) return Boolean is
1842 Is_Accept_Alternative_Proc
(Id
)
1843 or else Is_Finalizer_Proc
(Id
)
1844 or else Is_Partial_Invariant_Proc
(Id
)
1845 or else Is_Postconditions_Proc
(Id
)
1846 or else Is_TSS
(Id
, TSS_Deep_Adjust
)
1847 or else Is_TSS
(Id
, TSS_Deep_Finalize
)
1848 or else Is_TSS
(Id
, TSS_Deep_Initialize
);
1849 end Is_Bridge_Target
;
1851 ---------------------------
1852 -- Is_Default_Expression --
1853 ---------------------------
1855 function Is_Default_Expression
(Call
: Node_Id
) return Boolean is
1856 Outer_Call
: constant Node_Id
:= Parent
(Call
);
1857 Outer_Nam
: Node_Id
;
1860 -- To qualify, the node must appear immediately within a source call
1861 -- which invokes a source target.
1863 if Nkind_In
(Outer_Call
, N_Entry_Call_Statement
,
1865 N_Procedure_Call_Statement
)
1866 and then Comes_From_Source
(Outer_Call
)
1868 Outer_Nam
:= Extract_Call_Name
(Outer_Call
);
1871 Is_Entity_Name
(Outer_Nam
)
1872 and then Present
(Entity
(Outer_Nam
))
1873 and then Is_Subprogram_Or_Entry
(Entity
(Outer_Nam
))
1874 and then Comes_From_Source
(Entity
(Outer_Nam
));
1878 end Is_Default_Expression
;
1880 ----------------------------
1881 -- Is_Generic_Formal_Subp --
1882 ----------------------------
1884 function Is_Generic_Formal_Subp
(Subp_Id
: Entity_Id
) return Boolean is
1885 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
1886 Context
: constant Node_Id
:= Parent
(Subp_Decl
);
1889 -- To qualify, the subprogram must rename a generic actual subprogram
1890 -- where the enclosing context is an instantiation.
1893 Nkind
(Subp_Decl
) = N_Subprogram_Renaming_Declaration
1894 and then not Comes_From_Source
(Subp_Decl
)
1895 and then Nkind_In
(Context
, N_Function_Specification
,
1896 N_Package_Specification
,
1897 N_Procedure_Specification
)
1898 and then Present
(Generic_Parent
(Context
));
1899 end Is_Generic_Formal_Subp
;
1903 Call_Attrs
: Call_Attributes
;
1906 Target_Attrs
: Target_Attributes
;
1907 Target_Id
: Entity_Id
;
1909 -- Start of processing for Build_Call_Marker
1912 -- Nothing to do when switch -gnatH (legacy elaboration checking mode
1913 -- enabled) is in effect because the legacy ABE mechanism does not need
1914 -- to carry out this action.
1916 if Legacy_Elaboration_Checks
then
1919 -- Nothing to do for ASIS. As a result, ABE checks and diagnostics are
1920 -- not performed in this mode.
1922 elsif ASIS_Mode
then
1925 -- Nothing to do when the call is being preanalyzed as the marker will
1926 -- be inserted in the wrong place.
1928 elsif Preanalysis_Active
then
1931 -- Nothing to do when the input does not denote a call or a requeue
1933 elsif not Nkind_In
(N
, N_Entry_Call_Statement
,
1935 N_Procedure_Call_Statement
,
1936 N_Requeue_Statement
)
1940 -- Nothing to do when the input denotes entry call or requeue statement,
1941 -- and switch -gnatd_e (ignore entry calls and requeue statements for
1942 -- elaboration) is in effect.
1944 elsif Debug_Flag_Underscore_E
1945 and then Nkind_In
(N
, N_Entry_Call_Statement
, N_Requeue_Statement
)
1950 Call_Nam
:= Extract_Call_Name
(N
);
1952 -- Nothing to do when the call is erroneous or left in a bad state
1954 if not (Is_Entity_Name
(Call_Nam
)
1955 and then Present
(Entity
(Call_Nam
))
1956 and then Is_Subprogram_Or_Entry
(Entity
(Call_Nam
)))
1960 -- Nothing to do when the call invokes a generic formal subprogram and
1961 -- switch -gnatd.G (ignore calls through generic formal parameters for
1962 -- elaboration) is in effect. This check must be performed with the
1963 -- direct target of the call to avoid the side effects of mapping
1964 -- actuals to formals using renamings.
1966 elsif Debug_Flag_Dot_GG
1967 and then Is_Generic_Formal_Subp
(Entity
(Call_Nam
))
1971 -- Nothing to do when the call is analyzed/resolved too early within an
1972 -- intermediate context. This check is saved for last because it incurs
1973 -- a performance penalty.
1975 -- Performance note: parent traversal
1977 elsif In_Premature_Context
(N
) then
1981 Extract_Call_Attributes
1983 Target_Id
=> Target_Id
,
1984 Attrs
=> Call_Attrs
);
1986 Extract_Target_Attributes
1987 (Target_Id
=> Target_Id
,
1988 Attrs
=> Target_Attrs
);
1990 -- Nothing to do when the call invokes an assertion pragma procedure
1991 -- and switch -gnatd_p (ignore assertion pragmas for elaboration) is
1994 if Debug_Flag_Underscore_P
1995 and then Is_Assertion_Pragma_Target
(Target_Id
)
1999 -- Source calls to source targets are always considered because they
2000 -- reflect the original call graph.
2002 elsif Target_Attrs
.From_Source
and then Call_Attrs
.From_Source
then
2005 -- A call to a source function which acts as the default expression in
2006 -- another call requires special detection.
2008 elsif Target_Attrs
.From_Source
2009 and then Nkind
(N
) = N_Function_Call
2010 and then Is_Default_Expression
(N
)
2014 -- The target emulates Ada semantics
2016 elsif Is_Ada_Semantic_Target
(Target_Id
) then
2019 -- The target acts as a link between scenarios
2021 elsif Is_Bridge_Target
(Target_Id
) then
2024 -- The target emulates SPARK semantics
2026 elsif Is_SPARK_Semantic_Target
(Target_Id
) then
2029 -- Otherwise the call is not suitable for ABE processing. This prevents
2030 -- the generation of call markers which will never play a role in ABE
2037 -- At this point it is known that the call will play some role in ABE
2038 -- checks and diagnostics. Create a corresponding call marker in case
2039 -- the original call is heavily transformed by expansion later on.
2041 Marker
:= Make_Call_Marker
(Sloc
(N
));
2043 -- Inherit the attributes of the original call
2045 Set_Target
(Marker
, Target_Id
);
2046 Set_Is_Declaration_Level_Node
(Marker
, Call_Attrs
.In_Declarations
);
2047 Set_Is_Dispatching_Call
(Marker
, Call_Attrs
.Is_Dispatching
);
2048 Set_Is_Elaboration_Checks_OK_Node
2049 (Marker
, Call_Attrs
.Elab_Checks_OK
);
2050 Set_Is_Elaboration_Warnings_OK_Node
2051 (Marker
, Call_Attrs
.Elab_Warnings_OK
);
2052 Set_Is_Ignored_Ghost_Node
(Marker
, Call_Attrs
.Ghost_Mode_Ignore
);
2053 Set_Is_Source_Call
(Marker
, Call_Attrs
.From_Source
);
2054 Set_Is_SPARK_Mode_On_Node
(Marker
, Call_Attrs
.SPARK_Mode_On
);
2056 -- The marker is inserted prior to the original call. This placement has
2057 -- several desirable effects:
2059 -- 1) The marker appears in the same context, in close proximity to
2065 -- 2) Inserting the marker prior to the call ensures that an ABE check
2066 -- will take effect prior to the call.
2072 -- 3) The above two properties are preserved even when the call is a
2073 -- function which is subsequently relocated in order to capture its
2074 -- result. Note that if the call is relocated to a new context, the
2075 -- relocated call will receive a marker of its own.
2079 -- Temp : ... := Func_Call ...;
2082 -- The insertion must take place even when the call does not occur in
2083 -- the main unit to keep the tree symmetric. This ensures that internal
2084 -- name serialization is consistent in case the call marker causes the
2085 -- tree to transform in some way.
2087 Insert_Action
(N
, Marker
);
2089 -- The marker becomes the "corresponding" scenario for the call. Save
2090 -- the marker for later processing by the ABE phase.
2092 Record_Elaboration_Scenario
(Marker
);
2093 end Build_Call_Marker
;
2095 -------------------------------------
2096 -- Build_Variable_Reference_Marker --
2097 -------------------------------------
2099 procedure Build_Variable_Reference_Marker
2104 function In_Pragma
(Nod
: Node_Id
) return Boolean;
2105 -- Determine whether arbitrary node Nod appears within a pragma
2111 function In_Pragma
(Nod
: Node_Id
) return Boolean is
2116 while Present
(Par
) loop
2117 if Nkind
(Par
) = N_Pragma
then
2120 -- Prevent the search from going too far
2122 elsif Is_Body_Or_Package_Declaration
(Par
) then
2126 Par
:= Parent
(Par
);
2136 Var_Attrs
: Variable_Attributes
;
2139 -- Start of processing for Build_Variable_Reference_Marker
2142 -- Nothing to do when switch -gnatH (legacy elaboration checking mode
2143 -- enabled) is in effect because the legacy ABE mechanism does not need
2144 -- to carry out this action.
2146 if Legacy_Elaboration_Checks
then
2149 -- Nothing to do for ASIS. As a result, ABE checks and diagnostics are
2150 -- not performed in this mode.
2152 elsif ASIS_Mode
then
2155 -- Nothing to do when the reference is being preanalyzed as the marker
2156 -- will be inserted in the wrong place.
2158 elsif Preanalysis_Active
then
2161 -- Nothing to do when the input does not denote a reference
2163 elsif not Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
2166 -- Nothing to do for internally-generated references
2168 elsif not Comes_From_Source
(N
) then
2171 -- Nothing to do when the reference is erroneous, left in a bad state,
2172 -- or does not denote a variable.
2174 elsif not (Present
(Entity
(N
))
2175 and then Ekind
(Entity
(N
)) = E_Variable
2176 and then Entity
(N
) /= Any_Id
)
2181 Extract_Variable_Reference_Attributes
2184 Attrs
=> Var_Attrs
);
2186 Prag
:= SPARK_Pragma
(Var_Id
);
2188 if Comes_From_Source
(Var_Id
)
2190 -- Both the variable and the reference must appear in SPARK_Mode On
2191 -- regions because this scenario falls under the SPARK rules.
2193 and then Present
(Prag
)
2194 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
2195 and then Is_SPARK_Mode_On_Node
(N
)
2197 -- The reference must not be considered when it appears in a pragma.
2198 -- If the pragma has run-time semantics, then the reference will be
2199 -- reconsidered once the pragma is expanded.
2201 -- Performance note: parent traversal
2203 and then not In_Pragma
(N
)
2207 -- Otherwise the reference is not suitable for ABE processing. This
2208 -- prevents the generation of variable markers which will never play
2209 -- a role in ABE diagnostics.
2215 -- At this point it is known that the variable reference will play some
2216 -- role in ABE checks and diagnostics. Create a corresponding variable
2217 -- marker in case the original variable reference is folded or optimized
2220 Marker
:= Make_Variable_Reference_Marker
(Sloc
(N
));
2222 -- Inherit the attributes of the original variable reference
2224 Set_Target
(Marker
, Var_Id
);
2225 Set_Is_Read
(Marker
, Read
);
2226 Set_Is_Write
(Marker
, Write
);
2228 -- The marker is inserted prior to the original variable reference. The
2229 -- insertion must take place even when the reference does not occur in
2230 -- the main unit to keep the tree symmetric. This ensures that internal
2231 -- name serialization is consistent in case the variable marker causes
2232 -- the tree to transform in some way.
2234 Insert_Action
(N
, Marker
);
2236 -- The marker becomes the "corresponding" scenario for the reference.
2237 -- Save the marker for later processing for the ABE phase.
2239 Record_Elaboration_Scenario
(Marker
);
2240 end Build_Variable_Reference_Marker
;
2242 ---------------------------------
2243 -- Check_Elaboration_Scenarios --
2244 ---------------------------------
2246 procedure Check_Elaboration_Scenarios
is
2248 -- Nothing to do when switch -gnatH (legacy elaboration checking mode
2249 -- enabled) is in effect because the legacy ABE mechanism does not need
2250 -- to carry out this action.
2252 if Legacy_Elaboration_Checks
then
2255 -- Nothing to do for ASIS. As a result, no ABE checks and diagnostics
2256 -- are performed in this mode.
2258 elsif ASIS_Mode
then
2262 -- Examine the context of the main unit and record all units with prior
2263 -- elaboration with respect to it.
2265 Find_Elaborated_Units
;
2267 -- Examine each top-level scenario saved during the Recording phase for
2268 -- conditional ABEs and perform various actions depending on the model
2269 -- in effect. The table of visited bodies is created for each new top-
2272 for Index
in Top_Level_Scenarios
.First
.. Top_Level_Scenarios
.Last
loop
2273 Reset_Visited_Bodies
;
2275 Process_Conditional_ABE
(Top_Level_Scenarios
.Table
(Index
));
2278 -- Examine each SPARK scenario saved during the Recording phase which
2279 -- is not necessarily executable during elaboration, but still requires
2280 -- elaboration-related checks.
2282 for Index
in SPARK_Scenarios
.First
.. SPARK_Scenarios
.Last
loop
2283 Check_SPARK_Scenario
(SPARK_Scenarios
.Table
(Index
));
2285 end Check_Elaboration_Scenarios
;
2287 ------------------------------
2288 -- Check_Preelaborated_Call --
2289 ------------------------------
2291 procedure Check_Preelaborated_Call
(Call
: Node_Id
) is
2292 function In_Preelaborated_Context
(N
: Node_Id
) return Boolean;
2293 -- Determine whether arbitrary node appears in a preelaborated context
2295 ------------------------------
2296 -- In_Preelaborated_Context --
2297 ------------------------------
2299 function In_Preelaborated_Context
(N
: Node_Id
) return Boolean is
2300 Body_Id
: constant Entity_Id
:= Find_Code_Unit
(N
);
2301 Spec_Id
: constant Entity_Id
:= Unique_Entity
(Body_Id
);
2304 -- The node appears within a package body whose corresponding spec is
2305 -- subject to pragma Remote_Call_Interface or Remote_Types. This does
2306 -- not result in a preelaborated context because the package body may
2307 -- be on another machine.
2309 if Ekind
(Body_Id
) = E_Package_Body
2310 and then Ekind_In
(Spec_Id
, E_Generic_Package
, E_Package
)
2311 and then (Is_Remote_Call_Interface
(Spec_Id
)
2312 or else Is_Remote_Types
(Spec_Id
))
2316 -- Otherwise the node appears within a preelaborated context when the
2317 -- associated unit is preelaborated.
2320 return Is_Preelaborated_Unit
(Spec_Id
);
2322 end In_Preelaborated_Context
;
2326 Call_Attrs
: Call_Attributes
;
2327 Level
: Enclosing_Level_Kind
;
2328 Target_Id
: Entity_Id
;
2330 -- Start of processing for Check_Preelaborated_Call
2333 Extract_Call_Attributes
2335 Target_Id
=> Target_Id
,
2336 Attrs
=> Call_Attrs
);
2338 -- Nothing to do when the call is internally generated because it is
2339 -- assumed that it will never violate preelaboration.
2341 if not Call_Attrs
.From_Source
then
2345 -- Performance note: parent traversal
2347 Level
:= Find_Enclosing_Level
(Call
);
2349 -- Library-level calls are always considered because they are part of
2350 -- the associated unit's elaboration actions.
2352 if Level
in Library_Level
then
2355 -- Calls at the library level of a generic package body must be checked
2356 -- because they would render an instantiation illegal if the template is
2357 -- marked as preelaborated. Note that this does not apply to calls at
2358 -- the library level of a generic package spec.
2360 elsif Level
= Generic_Package_Body
then
2363 -- Otherwise the call does not appear at the proper level and must not
2364 -- be considered for this check.
2370 -- The call appears within a preelaborated unit. Emit a warning only for
2371 -- internal uses, otherwise this is an error.
2373 if In_Preelaborated_Context
(Call
) then
2374 Error_Msg_Warn
:= GNAT_Mode
;
2376 ("<<non-static call not allowed in preelaborated unit", Call
);
2378 end Check_Preelaborated_Call
;
2380 ------------------------------
2381 -- Check_SPARK_Derived_Type --
2382 ------------------------------
2384 procedure Check_SPARK_Derived_Type
(Typ_Decl
: Node_Id
) is
2385 Typ
: constant Entity_Id
:= Defining_Entity
(Typ_Decl
);
2387 -- NOTE: The routines within Check_SPARK_Derived_Type are intentionally
2388 -- unnested to avoid deep indentation of code.
2390 Stop_Check
: exception;
2391 -- This exception is raised when the freeze node violates the placement
2394 procedure Check_Overriding_Primitive
2397 pragma Inline
(Check_Overriding_Primitive
);
2398 -- Verify that freeze node FNode is within the early call region of
2399 -- overriding primitive Prim's body.
2401 function Freeze_Node_Location
(FNode
: Node_Id
) return Source_Ptr
;
2402 pragma Inline
(Freeze_Node_Location
);
2403 -- Return a more accurate source location associated with freeze node
2406 function Precedes_Source_Construct
(N
: Node_Id
) return Boolean;
2407 pragma Inline
(Precedes_Source_Construct
);
2408 -- Determine whether arbitrary node N appears prior to some source
2411 procedure Suggest_Elaborate_Body
2413 Body_Decl
: Node_Id
;
2414 Error_Nod
: Node_Id
);
2415 pragma Inline
(Suggest_Elaborate_Body
);
2416 -- Suggest the use of pragma Elaborate_Body when the pragma will allow
2417 -- for node N to appear within the early call region of subprogram body
2418 -- Body_Decl. The suggestion is attached to Error_Nod as a continuation
2421 --------------------------------
2422 -- Check_Overriding_Primitive --
2423 --------------------------------
2425 procedure Check_Overriding_Primitive
2429 Prim_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Prim
);
2430 Body_Decl
: Node_Id
;
2431 Body_Id
: Entity_Id
;
2435 Body_Id
:= Corresponding_Body
(Prim_Decl
);
2437 -- Nothing to do when the primitive does not have a corresponding
2438 -- body. This can happen when the unit with the bodies is not the
2439 -- main unit subjected to ABE checks.
2441 if No
(Body_Id
) then
2444 -- The primitive overrides a parent or progenitor primitive
2446 elsif Present
(Overridden_Operation
(Prim
)) then
2448 -- Nothing to do when overriding an interface primitive happens by
2449 -- inheriting a non-interface primitive as the check would be done
2450 -- on the parent primitive.
2452 if Present
(Alias
(Prim
)) then
2456 -- Nothing to do when the primitive is not overriding. The body of
2457 -- such a primitive cannot be targeted by a dispatching call which
2458 -- is executable during elaboration, and cannot cause an ABE.
2464 Body_Decl
:= Unit_Declaration_Node
(Body_Id
);
2465 Region
:= Find_Early_Call_Region
(Body_Decl
);
2467 -- The freeze node appears prior to the early call region of the
2470 -- IMPORTANT: This check must always be performed even when -gnatd.v
2471 -- (enforce SPARK elaboration rules in SPARK code) is not specified
2472 -- because the static model cannot guarantee the absence of ABEs in
2473 -- in the presence of dispatching calls.
2475 if Earlier_In_Extended_Unit
(FNode
, Region
) then
2476 Error_Msg_Node_2
:= Prim
;
2478 ("first freezing point of type & must appear within early call "
2479 & "region of primitive body & (SPARK RM 7.7(8))",
2482 Error_Msg_Sloc
:= Sloc
(Region
);
2483 Error_Msg_N
("\region starts #", Typ_Decl
);
2485 Error_Msg_Sloc
:= Sloc
(Body_Decl
);
2486 Error_Msg_N
("\region ends #", Typ_Decl
);
2488 Error_Msg_Sloc
:= Freeze_Node_Location
(FNode
);
2489 Error_Msg_N
("\first freezing point #", Typ_Decl
);
2491 -- If applicable, suggest the use of pragma Elaborate_Body in the
2492 -- associated package spec.
2494 Suggest_Elaborate_Body
2496 Body_Decl
=> Body_Decl
,
2497 Error_Nod
=> Typ_Decl
);
2501 end Check_Overriding_Primitive
;
2503 --------------------------
2504 -- Freeze_Node_Location --
2505 --------------------------
2507 function Freeze_Node_Location
(FNode
: Node_Id
) return Source_Ptr
is
2508 Context
: constant Node_Id
:= Parent
(FNode
);
2509 Loc
: constant Source_Ptr
:= Sloc
(FNode
);
2511 Prv_Decls
: List_Id
;
2512 Vis_Decls
: List_Id
;
2515 -- In general, the source location of the freeze node is as close as
2516 -- possible to the real freeze point, except when the freeze node is
2517 -- at the "bottom" of a package spec.
2519 if Nkind
(Context
) = N_Package_Specification
then
2520 Prv_Decls
:= Private_Declarations
(Context
);
2521 Vis_Decls
:= Visible_Declarations
(Context
);
2523 -- The freeze node appears in the private declarations of the
2526 if Present
(Prv_Decls
)
2527 and then List_Containing
(FNode
) = Prv_Decls
2531 -- The freeze node appears in the visible declarations of the
2532 -- package and there are no private declarations.
2534 elsif Present
(Vis_Decls
)
2535 and then List_Containing
(FNode
) = Vis_Decls
2536 and then (No
(Prv_Decls
) or else Is_Empty_List
(Prv_Decls
))
2540 -- Otherwise the freeze node is not in the "last" declarative list
2541 -- of the package. Use the existing source location of the freeze
2548 -- The freeze node appears at the "bottom" of the package when it
2549 -- is in the "last" declarative list and is either the last in the
2550 -- list or is followed by internal constructs only. In that case
2551 -- the more appropriate source location is that of the package end
2554 if not Precedes_Source_Construct
(FNode
) then
2555 return Sloc
(End_Label
(Context
));
2560 end Freeze_Node_Location
;
2562 -------------------------------
2563 -- Precedes_Source_Construct --
2564 -------------------------------
2566 function Precedes_Source_Construct
(N
: Node_Id
) return Boolean is
2571 while Present
(Decl
) loop
2572 if Comes_From_Source
(Decl
) then
2575 -- A generated body for a source expression function is treated as
2576 -- a source construct.
2578 elsif Nkind
(Decl
) = N_Subprogram_Body
2579 and then Was_Expression_Function
(Decl
)
2580 and then Comes_From_Source
(Original_Node
(Decl
))
2589 end Precedes_Source_Construct
;
2591 ----------------------------
2592 -- Suggest_Elaborate_Body --
2593 ----------------------------
2595 procedure Suggest_Elaborate_Body
2597 Body_Decl
: Node_Id
;
2598 Error_Nod
: Node_Id
)
2600 Unt
: constant Node_Id
:= Unit
(Cunit
(Main_Unit
));
2604 -- The suggestion applies only when the subprogram body resides in a
2605 -- compilation package body, and a pragma Elaborate_Body would allow
2606 -- for the node to appear in the early call region of the subprogram
2607 -- body. This implies that all code from the subprogram body up to
2608 -- the node is preelaborable.
2610 if Nkind
(Unt
) = N_Package_Body
then
2612 -- Find the start of the early call region again assuming that the
2613 -- package spec has pragma Elaborate_Body. Note that the internal
2614 -- data structures are intentionally not updated because this is a
2615 -- speculative search.
2618 Find_Early_Call_Region
2619 (Body_Decl
=> Body_Decl
,
2620 Assume_Elab_Body
=> True,
2621 Skip_Memoization
=> True);
2623 -- If the node appears within the early call region, assuming that
2624 -- the package spec carries pragma Elaborate_Body, then it is safe
2625 -- to suggest the pragma.
2627 if Earlier_In_Extended_Unit
(Region
, N
) then
2628 Error_Msg_Name_1
:= Name_Elaborate_Body
;
2630 ("\consider adding pragma % in spec of unit &",
2631 Error_Nod
, Defining_Entity
(Unt
));
2634 end Suggest_Elaborate_Body
;
2638 FNode
: constant Node_Id
:= Freeze_Node
(Typ
);
2639 Prims
: constant Elist_Id
:= Direct_Primitive_Operations
(Typ
);
2641 Prim_Elmt
: Elmt_Id
;
2643 -- Start of processing for Check_SPARK_Derived_Type
2646 -- A type should have its freeze node set by the time SPARK scenarios
2647 -- are being verified.
2649 pragma Assert
(Present
(FNode
));
2651 -- Verify that the freeze node of the derived type is within the early
2652 -- call region of each overriding primitive body (SPARK RM 7.7(8)).
2654 if Present
(Prims
) then
2655 Prim_Elmt
:= First_Elmt
(Prims
);
2656 while Present
(Prim_Elmt
) loop
2657 Check_Overriding_Primitive
2658 (Prim
=> Node
(Prim_Elmt
),
2661 Next_Elmt
(Prim_Elmt
);
2668 end Check_SPARK_Derived_Type
;
2670 -------------------------------
2671 -- Check_SPARK_Instantiation --
2672 -------------------------------
2674 procedure Check_SPARK_Instantiation
(Exp_Inst
: Node_Id
) is
2675 Gen_Attrs
: Target_Attributes
;
2678 Inst_Attrs
: Instantiation_Attributes
;
2679 Inst_Id
: Entity_Id
;
2682 Extract_Instantiation_Attributes
2683 (Exp_Inst
=> Exp_Inst
,
2687 Attrs
=> Inst_Attrs
);
2689 Extract_Target_Attributes
(Gen_Id
, Gen_Attrs
);
2691 -- The instantiation and the generic body are both in the main unit
2693 if Present
(Gen_Attrs
.Body_Decl
)
2694 and then In_Extended_Main_Code_Unit
(Gen_Attrs
.Body_Decl
)
2696 -- If the instantiation appears prior to the generic body, then the
2697 -- instantiation is illegal (SPARK RM 7.7(6)).
2699 -- IMPORTANT: This check must always be performed even when -gnatd.v
2700 -- (enforce SPARK elaboration rules in SPARK code) is not specified
2701 -- because the rule prevents use-before-declaration of objects that
2702 -- may precede the generic body.
2704 and then Earlier_In_Extended_Unit
(Inst
, Gen_Attrs
.Body_Decl
)
2706 Error_Msg_NE
("cannot instantiate & before body seen", Inst
, Gen_Id
);
2708 end Check_SPARK_Instantiation
;
2710 ---------------------------------
2711 -- Check_SPARK_Model_In_Effect --
2712 ---------------------------------
2714 SPARK_Model_Warning_Posted
: Boolean := False;
2715 -- This flag prevents the same SPARK model-related warning from being
2716 -- emitted multiple times.
2718 procedure Check_SPARK_Model_In_Effect
(N
: Node_Id
) is
2720 -- Do not emit the warning multiple times as this creates useless noise
2722 if SPARK_Model_Warning_Posted
then
2725 -- SPARK rule verification requires the "strict" static model
2727 elsif Static_Elaboration_Checks
and not Relaxed_Elaboration_Checks
then
2730 -- Any other combination of models does not guarantee the absence of ABE
2731 -- problems for SPARK rule verification purposes. Note that there is no
2732 -- need to check for the legacy ABE mechanism because the legacy code
2733 -- has its own orthogonal processing for SPARK rules.
2736 SPARK_Model_Warning_Posted
:= True;
2739 ("??SPARK elaboration checks require static elaboration model", N
);
2741 if Dynamic_Elaboration_Checks
then
2742 Error_Msg_N
("\dynamic elaboration model is in effect", N
);
2744 pragma Assert
(Relaxed_Elaboration_Checks
);
2745 Error_Msg_N
("\relaxed elaboration model is in effect", N
);
2748 end Check_SPARK_Model_In_Effect
;
2750 --------------------------
2751 -- Check_SPARK_Scenario --
2752 --------------------------
2754 procedure Check_SPARK_Scenario
(N
: Node_Id
) is
2756 -- Ensure that a suitable elaboration model is in effect for SPARK rule
2759 Check_SPARK_Model_In_Effect
(N
);
2761 -- Add the current scenario to the stack of active scenarios
2763 Push_Active_Scenario
(N
);
2765 if Is_Suitable_SPARK_Derived_Type
(N
) then
2766 Check_SPARK_Derived_Type
(N
);
2768 elsif Is_Suitable_SPARK_Instantiation
(N
) then
2769 Check_SPARK_Instantiation
(N
);
2771 elsif Is_Suitable_SPARK_Refined_State_Pragma
(N
) then
2772 Check_SPARK_Refined_State_Pragma
(N
);
2775 -- Remove the current scenario from the stack of active scenarios once
2776 -- all ABE diagnostics and checks have been performed.
2778 Pop_Active_Scenario
(N
);
2779 end Check_SPARK_Scenario
;
2781 --------------------------------------
2782 -- Check_SPARK_Refined_State_Pragma --
2783 --------------------------------------
2785 procedure Check_SPARK_Refined_State_Pragma
(N
: Node_Id
) is
2787 -- NOTE: The routines within Check_SPARK_Refined_State_Pragma are
2788 -- intentionally unnested to avoid deep indentation of code.
2790 procedure Check_SPARK_Constituent
(Constit_Id
: Entity_Id
);
2791 pragma Inline
(Check_SPARK_Constituent
);
2792 -- Ensure that a single constituent Constit_Id is elaborated prior to
2795 procedure Check_SPARK_Constituents
(Constits
: Elist_Id
);
2796 pragma Inline
(Check_SPARK_Constituents
);
2797 -- Ensure that all constituents found in list Constits are elaborated
2798 -- prior to the main unit.
2800 procedure Check_SPARK_Initialized_State
(State
: Node_Id
);
2801 pragma Inline
(Check_SPARK_Initialized_State
);
2802 -- Ensure that the constituents of single abstract state State are
2803 -- elaborated prior to the main unit.
2805 procedure Check_SPARK_Initialized_States
(Pack_Id
: Entity_Id
);
2806 pragma Inline
(Check_SPARK_Initialized_States
);
2807 -- Ensure that the constituents of all abstract states which appear in
2808 -- the Initializes pragma of package Pack_Id are elaborated prior to the
2811 -----------------------------
2812 -- Check_SPARK_Constituent --
2813 -----------------------------
2815 procedure Check_SPARK_Constituent
(Constit_Id
: Entity_Id
) is
2819 -- Nothing to do for "null" constituents
2821 if Nkind
(Constit_Id
) = N_Null
then
2824 -- Nothing to do for illegal constituents
2826 elsif Error_Posted
(Constit_Id
) then
2830 Prag
:= SPARK_Pragma
(Constit_Id
);
2832 -- The check applies only when the constituent is subject to pragma
2836 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
2838 -- An external constituent of an abstract state which appears in
2839 -- the Initializes pragma of a package spec imposes an Elaborate
2840 -- requirement on the context of the main unit. Determine whether
2841 -- the context has a pragma strong enough to meet the requirement.
2843 -- IMPORTANT: This check is performed only when -gnatd.v (enforce
2844 -- SPARK elaboration rules in SPARK code) is in effect because the
2845 -- static model can ensure the prior elaboration of the unit which
2846 -- contains a constituent by installing implicit Elaborate pragma.
2848 if Debug_Flag_Dot_V
then
2849 Meet_Elaboration_Requirement
2851 Target_Id
=> Constit_Id
,
2852 Req_Nam
=> Name_Elaborate
);
2854 -- Otherwise ensure that the unit with the external constituent is
2855 -- elaborated prior to the main unit.
2858 Ensure_Prior_Elaboration
2860 Unit_Id
=> Find_Top_Unit
(Constit_Id
),
2861 Prag_Nam
=> Name_Elaborate
,
2862 State
=> Initial_State
);
2865 end Check_SPARK_Constituent
;
2867 ------------------------------
2868 -- Check_SPARK_Constituents --
2869 ------------------------------
2871 procedure Check_SPARK_Constituents
(Constits
: Elist_Id
) is
2872 Constit_Elmt
: Elmt_Id
;
2875 if Present
(Constits
) then
2876 Constit_Elmt
:= First_Elmt
(Constits
);
2877 while Present
(Constit_Elmt
) loop
2878 Check_SPARK_Constituent
(Node
(Constit_Elmt
));
2879 Next_Elmt
(Constit_Elmt
);
2882 end Check_SPARK_Constituents
;
2884 -----------------------------------
2885 -- Check_SPARK_Initialized_State --
2886 -----------------------------------
2888 procedure Check_SPARK_Initialized_State
(State
: Node_Id
) is
2890 State_Id
: Entity_Id
;
2893 -- Nothing to do for "null" initialization items
2895 if Nkind
(State
) = N_Null
then
2898 -- Nothing to do for illegal states
2900 elsif Error_Posted
(State
) then
2904 State_Id
:= Entity_Of
(State
);
2906 -- Sanitize the state
2908 if No
(State_Id
) then
2911 elsif Error_Posted
(State_Id
) then
2914 elsif Ekind
(State_Id
) /= E_Abstract_State
then
2918 -- The check is performed only when the abstract state is subject to
2921 Prag
:= SPARK_Pragma
(State_Id
);
2924 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
2926 Check_SPARK_Constituents
(Refinement_Constituents
(State_Id
));
2928 end Check_SPARK_Initialized_State
;
2930 ------------------------------------
2931 -- Check_SPARK_Initialized_States --
2932 ------------------------------------
2934 procedure Check_SPARK_Initialized_States
(Pack_Id
: Entity_Id
) is
2935 Prag
: constant Node_Id
:= Get_Pragma
(Pack_Id
, Pragma_Initializes
);
2940 if Present
(Prag
) then
2941 Inits
:= Expression
(Get_Argument
(Prag
, Pack_Id
));
2943 -- Avoid processing a "null" initialization list. The only other
2944 -- alternative is an aggregate.
2946 if Nkind
(Inits
) = N_Aggregate
then
2948 -- The initialization items appear in list form:
2952 if Present
(Expressions
(Inits
)) then
2953 Init
:= First
(Expressions
(Inits
));
2954 while Present
(Init
) loop
2955 Check_SPARK_Initialized_State
(Init
);
2960 -- The initialization items appear in associated form:
2962 -- (state1 => item1,
2963 -- state2 => (item2, item3))
2965 if Present
(Component_Associations
(Inits
)) then
2966 Init
:= First
(Component_Associations
(Inits
));
2967 while Present
(Init
) loop
2968 Check_SPARK_Initialized_State
(Init
);
2974 end Check_SPARK_Initialized_States
;
2978 Pack_Body
: constant Node_Id
:= Find_Related_Package_Or_Body
(N
);
2980 -- Start of processing for Check_SPARK_Refined_State_Pragma
2983 -- Pragma Refined_State must be associated with a package body
2986 (Present
(Pack_Body
) and then Nkind
(Pack_Body
) = N_Package_Body
);
2988 -- Verify that each external contitunent of an abstract state mentioned
2989 -- in pragma Initializes is properly elaborated.
2991 Check_SPARK_Initialized_States
(Unique_Defining_Entity
(Pack_Body
));
2992 end Check_SPARK_Refined_State_Pragma
;
2994 ----------------------
2995 -- Compilation_Unit --
2996 ----------------------
2998 function Compilation_Unit
(Unit_Id
: Entity_Id
) return Node_Id
is
2999 Comp_Unit
: Node_Id
;
3002 Comp_Unit
:= Parent
(Unit_Id
);
3004 -- Handle the case where a concurrent subunit is rewritten as a null
3005 -- statement due to expansion activities.
3007 if Nkind
(Comp_Unit
) = N_Null_Statement
3008 and then Nkind_In
(Original_Node
(Comp_Unit
), N_Protected_Body
,
3011 Comp_Unit
:= Parent
(Comp_Unit
);
3012 pragma Assert
(Nkind
(Comp_Unit
) = N_Subunit
);
3014 -- Otherwise use the declaration node of the unit
3017 Comp_Unit
:= Parent
(Unit_Declaration_Node
(Unit_Id
));
3020 -- Handle the case where a subprogram instantiation which acts as a
3021 -- compilation unit is expanded into an anonymous package that wraps
3022 -- the instantiated subprogram.
3024 if Nkind
(Comp_Unit
) = N_Package_Specification
3025 and then Nkind_In
(Original_Node
(Parent
(Comp_Unit
)),
3026 N_Function_Instantiation
,
3027 N_Procedure_Instantiation
)
3029 Comp_Unit
:= Parent
(Parent
(Comp_Unit
));
3031 -- Handle the case where the compilation unit is a subunit
3033 elsif Nkind
(Comp_Unit
) = N_Subunit
then
3034 Comp_Unit
:= Parent
(Comp_Unit
);
3037 pragma Assert
(Nkind
(Comp_Unit
) = N_Compilation_Unit
);
3040 end Compilation_Unit
;
3042 -----------------------
3043 -- Early_Call_Region --
3044 -----------------------
3046 function Early_Call_Region
(Body_Id
: Entity_Id
) return Node_Id
is
3048 pragma Assert
(Ekind_In
(Body_Id
, E_Entry
,
3052 E_Subprogram_Body
));
3054 if Early_Call_Regions_In_Use
then
3055 return Early_Call_Regions
.Get
(Body_Id
);
3058 return Early_Call_Regions_No_Element
;
3059 end Early_Call_Region
;
3061 -----------------------------
3062 -- Early_Call_Regions_Hash --
3063 -----------------------------
3065 function Early_Call_Regions_Hash
3066 (Key
: Entity_Id
) return Early_Call_Regions_Index
3069 return Early_Call_Regions_Index
(Key
mod Early_Call_Regions_Max
);
3070 end Early_Call_Regions_Hash
;
3076 procedure Elab_Msg_NE
3083 function Prefix
return String;
3084 -- Obtain the prefix of the message
3086 function Suffix
return String;
3087 -- Obtain the suffix of the message
3093 function Prefix
return String is
3106 function Suffix
return String is
3115 -- Start of processing for Elab_Msg_NE
3118 Error_Msg_NE
(Prefix
& Msg
& Suffix
, N
, Id
);
3121 ------------------------
3122 -- Elaboration_Status --
3123 ------------------------
3125 function Elaboration_Status
3126 (Unit_Id
: Entity_Id
) return Elaboration_Attributes
3129 if Elaboration_Statuses_In_Use
then
3130 return Elaboration_Statuses
.Get
(Unit_Id
);
3133 return Elaboration_Statuses_No_Element
;
3134 end Elaboration_Status
;
3136 -------------------------------
3137 -- Elaboration_Statuses_Hash --
3138 -------------------------------
3140 function Elaboration_Statuses_Hash
3141 (Key
: Entity_Id
) return Elaboration_Statuses_Index
3144 return Elaboration_Statuses_Index
(Key
mod Elaboration_Statuses_Max
);
3145 end Elaboration_Statuses_Hash
;
3147 ------------------------------
3148 -- Ensure_Prior_Elaboration --
3149 ------------------------------
3151 procedure Ensure_Prior_Elaboration
3153 Unit_Id
: Entity_Id
;
3155 State
: Processing_Attributes
)
3158 pragma Assert
(Nam_In
(Prag_Nam
, Name_Elaborate
, Name_Elaborate_All
));
3160 -- Nothing to do when the caller has suppressed the generation of
3161 -- implicit Elaborate[_All] pragmas.
3163 if State
.Suppress_Implicit_Pragmas
then
3166 -- Nothing to do when the need for prior elaboration came from a partial
3167 -- finalization routine which occurs in an initialization context. This
3168 -- behaviour parallels that of the old ABE mechanism.
3170 elsif State
.Within_Partial_Finalization
then
3173 -- Nothing to do when the need for prior elaboration came from a task
3174 -- body and switch -gnatd.y (disable implicit pragma Elaborate_All on
3175 -- task bodies) is in effect.
3177 elsif Debug_Flag_Dot_Y
and then State
.Within_Task_Body
then
3180 -- Nothing to do when the unit is elaborated prior to the main unit.
3181 -- This check must also consider the following cases:
3183 -- * No check is made against the context of the main unit because this
3184 -- is specific to the elaboration model in effect and requires custom
3185 -- handling (see Ensure_xxx_Prior_Elaboration).
3187 -- * Unit_Id is subject to pragma Elaborate_Body. An implicit pragma
3188 -- Elaborate[_All] MUST be generated even though Unit_Id is always
3189 -- elaborated prior to the main unit. This is a conservative strategy
3190 -- which ensures that other units withed by Unit_Id will not lead to
3193 -- package A is package body A is
3194 -- procedure ABE; procedure ABE is ... end ABE;
3198 -- package B is package body B is
3199 -- pragma Elaborate_Body; procedure Proc is
3201 -- procedure Proc; A.ABE;
3202 -- package B; end Proc;
3206 -- package C is package body C is
3212 -- In the example above, the elaboration of C invokes B.Proc. B is
3213 -- subject to pragma Elaborate_Body. If no pragma Elaborate[_All] is
3214 -- generated for B in C, then the following elaboratio order will lead
3217 -- spec of A elaborated
3218 -- spec of B elaborated
3219 -- body of B elaborated
3220 -- spec of C elaborated
3221 -- body of C elaborated <-- calls B.Proc which calls A.ABE
3222 -- body of A elaborated <-- problem
3224 -- The generation of an implicit pragma Elaborate_All (B) ensures that
3225 -- the elaboration order mechanism will not pick the above order.
3227 -- An implicit Elaborate is NOT generated when the unit is subject to
3228 -- Elaborate_Body because both pragmas have the exact same effect.
3230 -- * Unit_Id is the main unit. An implicit pragma Elaborate[_All] MUST
3231 -- NOT be generated in this case because a unit cannot depend on its
3232 -- own elaboration. This case is therefore treated as valid prior
3235 elsif Has_Prior_Elaboration
3236 (Unit_Id
=> Unit_Id
,
3237 Same_Unit_OK
=> True,
3238 Elab_Body_OK
=> Prag_Nam
= Name_Elaborate
)
3242 -- Suggest the use of pragma Prag_Nam when the dynamic model is in
3245 elsif Dynamic_Elaboration_Checks
then
3246 Ensure_Prior_Elaboration_Dynamic
3249 Prag_Nam
=> Prag_Nam
);
3251 -- Install an implicit pragma Prag_Nam when the static model is in
3255 pragma Assert
(Static_Elaboration_Checks
);
3257 Ensure_Prior_Elaboration_Static
3260 Prag_Nam
=> Prag_Nam
);
3262 end Ensure_Prior_Elaboration
;
3264 --------------------------------------
3265 -- Ensure_Prior_Elaboration_Dynamic --
3266 --------------------------------------
3268 procedure Ensure_Prior_Elaboration_Dynamic
3270 Unit_Id
: Entity_Id
;
3273 procedure Info_Missing_Pragma
;
3274 pragma Inline
(Info_Missing_Pragma
);
3275 -- Output information concerning missing Elaborate or Elaborate_All
3276 -- pragma with name Prag_Nam for scenario N, which would ensure the
3277 -- prior elaboration of Unit_Id.
3279 -------------------------
3280 -- Info_Missing_Pragma --
3281 -------------------------
3283 procedure Info_Missing_Pragma
is
3285 -- Internal units are ignored as they cause unnecessary noise
3287 if not In_Internal_Unit
(Unit_Id
) then
3289 -- The name of the unit subjected to the elaboration pragma is
3290 -- fully qualified to improve the clarity of the info message.
3292 Error_Msg_Name_1
:= Prag_Nam
;
3293 Error_Msg_Qual_Level
:= Nat
'Last;
3295 Error_Msg_NE
("info: missing pragma % for unit &", N
, Unit_Id
);
3296 Error_Msg_Qual_Level
:= 0;
3298 end Info_Missing_Pragma
;
3302 Elab_Attrs
: Elaboration_Attributes
;
3303 Level
: Enclosing_Level_Kind
;
3305 -- Start of processing for Ensure_Prior_Elaboration_Dynamic
3308 Elab_Attrs
:= Elaboration_Status
(Unit_Id
);
3310 -- Nothing to do when the unit is guaranteed prior elaboration by means
3311 -- of a source Elaborate[_All] pragma.
3313 if Present
(Elab_Attrs
.Source_Pragma
) then
3317 -- Output extra information on a missing Elaborate[_All] pragma when
3318 -- switch -gnatel (info messages on implicit Elaborate[_All] pragmas
3321 if Elab_Info_Messages
then
3323 -- Performance note: parent traversal
3325 Level
:= Find_Enclosing_Level
(N
);
3327 -- Declaration-level scenario
3329 if (Is_Suitable_Call
(N
) or else Is_Suitable_Instantiation
(N
))
3330 and then Level
= Declaration_Level
3334 -- Library-level scenario
3336 elsif Level
in Library_Level
then
3339 -- Instantiation library-level scenario
3341 elsif Level
= Instantiation
then
3344 -- Otherwise the scenario does not appear at the proper level and
3345 -- cannot possibly act as a top-level scenario.
3351 Info_Missing_Pragma
;
3353 end Ensure_Prior_Elaboration_Dynamic
;
3355 -------------------------------------
3356 -- Ensure_Prior_Elaboration_Static --
3357 -------------------------------------
3359 procedure Ensure_Prior_Elaboration_Static
3361 Unit_Id
: Entity_Id
;
3364 function Find_With_Clause
3366 Withed_Id
: Entity_Id
) return Node_Id
;
3367 pragma Inline
(Find_With_Clause
);
3368 -- Find a nonlimited with clause in the list of context items Items
3369 -- that withs unit Withed_Id. Return Empty if no such clause is found.
3371 procedure Info_Implicit_Pragma
;
3372 pragma Inline
(Info_Implicit_Pragma
);
3373 -- Output information concerning an implicitly generated Elaborate or
3374 -- Elaborate_All pragma with name Prag_Nam for scenario N which ensures
3375 -- the prior elaboration of unit Unit_Id.
3377 ----------------------
3378 -- Find_With_Clause --
3379 ----------------------
3381 function Find_With_Clause
3383 Withed_Id
: Entity_Id
) return Node_Id
3388 -- Examine the context clauses looking for a suitable with. Note that
3389 -- limited clauses do not affect the elaboration order.
3391 Item
:= First
(Items
);
3392 while Present
(Item
) loop
3393 if Nkind
(Item
) = N_With_Clause
3394 and then not Error_Posted
(Item
)
3395 and then not Limited_Present
(Item
)
3396 and then Entity
(Name
(Item
)) = Withed_Id
3405 end Find_With_Clause
;
3407 --------------------------
3408 -- Info_Implicit_Pragma --
3409 --------------------------
3411 procedure Info_Implicit_Pragma
is
3413 -- Internal units are ignored as they cause unnecessary noise
3415 if not In_Internal_Unit
(Unit_Id
) then
3417 -- The name of the unit subjected to the elaboration pragma is
3418 -- fully qualified to improve the clarity of the info message.
3420 Error_Msg_Name_1
:= Prag_Nam
;
3421 Error_Msg_Qual_Level
:= Nat
'Last;
3424 ("info: implicit pragma % generated for unit &", N
, Unit_Id
);
3426 Error_Msg_Qual_Level
:= 0;
3427 Output_Active_Scenarios
(N
);
3429 end Info_Implicit_Pragma
;
3433 Main_Cunit
: constant Node_Id
:= Cunit
(Main_Unit
);
3434 Loc
: constant Source_Ptr
:= Sloc
(Main_Cunit
);
3435 Unit_Cunit
: constant Node_Id
:= Compilation_Unit
(Unit_Id
);
3438 Elab_Attrs
: Elaboration_Attributes
;
3441 -- Start of processing for Ensure_Prior_Elaboration_Static
3444 Elab_Attrs
:= Elaboration_Status
(Unit_Id
);
3446 -- Nothing to do when the unit is guaranteed prior elaboration by means
3447 -- of a source Elaborate[_All] pragma.
3449 if Present
(Elab_Attrs
.Source_Pragma
) then
3452 -- Nothing to do when the unit has an existing implicit Elaborate[_All]
3453 -- pragma installed by a previous scenario.
3455 elsif Present
(Elab_Attrs
.With_Clause
) then
3457 -- The unit is already guaranteed prior elaboration by means of an
3458 -- implicit Elaborate pragma, however the current scenario imposes
3459 -- a stronger requirement of Elaborate_All. "Upgrade" the existing
3460 -- pragma to match this new requirement.
3462 if Elaborate_Desirable
(Elab_Attrs
.With_Clause
)
3463 and then Prag_Nam
= Name_Elaborate_All
3465 Set_Elaborate_All_Desirable
(Elab_Attrs
.With_Clause
);
3466 Set_Elaborate_Desirable
(Elab_Attrs
.With_Clause
, False);
3472 -- At this point it is known that the unit has no prior elaboration
3473 -- according to pragmas and hierarchical relationships.
3475 Items
:= Context_Items
(Main_Cunit
);
3479 Set_Context_Items
(Main_Cunit
, Items
);
3482 -- Locate the with clause for the unit. Note that there may not be a
3483 -- clause if the unit is visible through a subunit-body, body-spec, or
3484 -- spec-parent relationship.
3489 Withed_Id
=> Unit_Id
);
3494 -- Note that adding implicit with clauses is safe because analysis,
3495 -- resolution, and expansion have already taken place and it is not
3496 -- possible to interfere with visibility.
3500 Make_With_Clause
(Loc
,
3501 Name
=> New_Occurrence_Of
(Unit_Id
, Loc
));
3503 Set_Implicit_With
(Clause
);
3504 Set_Library_Unit
(Clause
, Unit_Cunit
);
3506 Append_To
(Items
, Clause
);
3509 -- Mark the with clause depending on the pragma required
3511 if Prag_Nam
= Name_Elaborate
then
3512 Set_Elaborate_Desirable
(Clause
);
3514 Set_Elaborate_All_Desirable
(Clause
);
3517 -- The implicit Elaborate[_All] ensures the prior elaboration of the
3518 -- unit. Include the unit in the elaboration context of the main unit.
3520 Set_Elaboration_Status
3521 (Unit_Id
=> Unit_Id
,
3522 Val
=> Elaboration_Attributes
'(Source_Pragma => Empty,
3523 With_Clause => Clause));
3525 -- Output extra information on an implicit Elaborate[_All] pragma when
3526 -- switch -gnatel (info messages on implicit Elaborate[_All] pragmas is
3529 if Elab_Info_Messages then
3530 Info_Implicit_Pragma;
3532 end Ensure_Prior_Elaboration_Static;
3534 -----------------------------
3535 -- Extract_Assignment_Name --
3536 -----------------------------
3538 function Extract_Assignment_Name (Asmt : Node_Id) return Node_Id is
3544 -- When the name denotes an array or record component, find the whole
3547 while Nkind_In (Nam, N_Explicit_Dereference,
3548 N_Indexed_Component,
3549 N_Selected_Component,
3552 Nam := Prefix (Nam);
3556 end Extract_Assignment_Name;
3558 -----------------------------
3559 -- Extract_Call_Attributes --
3560 -----------------------------
3562 procedure Extract_Call_Attributes
3564 Target_Id : out Entity_Id;
3565 Attrs : out Call_Attributes)
3567 From_Source : Boolean;
3568 In_Declarations : Boolean;
3569 Is_Dispatching : Boolean;
3572 -- Extraction for call markers
3574 if Nkind (Call) = N_Call_Marker then
3575 Target_Id := Target (Call);
3576 From_Source := Is_Source_Call (Call);
3577 In_Declarations := Is_Declaration_Level_Node (Call);
3578 Is_Dispatching := Is_Dispatching_Call (Call);
3580 -- Extraction for entry calls, requeue, and subprogram calls
3583 pragma Assert (Nkind_In (Call, N_Entry_Call_Statement,
3585 N_Procedure_Call_Statement,
3586 N_Requeue_Statement));
3588 Target_Id := Entity (Extract_Call_Name (Call));
3589 From_Source := Comes_From_Source (Call);
3591 -- Performance note: parent traversal
3593 In_Declarations := Find_Enclosing_Level (Call) = Declaration_Level;
3595 Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
3596 and then Present (Controlling_Argument (Call));
3599 -- Obtain the original entry or subprogram which the target may rename
3600 -- except when the target is an instantiation. In this case the alias
3601 -- is the internally generated subprogram which appears within the the
3602 -- anonymous package created for the instantiation. Such an alias is not
3603 -- a suitable target.
3605 if not (Is_Subprogram (Target_Id)
3606 and then Is_Generic_Instance (Target_Id))
3608 Target_Id := Get_Renamed_Entity (Target_Id);
3611 -- Set all attributes
3613 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Call);
3614 Attrs.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Call);
3615 Attrs.From_Source := From_Source;
3616 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Node (Call);
3617 Attrs.In_Declarations := In_Declarations;
3618 Attrs.Is_Dispatching := Is_Dispatching;
3619 Attrs.SPARK_Mode_On := Is_SPARK_Mode_On_Node (Call);
3620 end Extract_Call_Attributes;
3622 -----------------------
3623 -- Extract_Call_Name --
3624 -----------------------
3626 function Extract_Call_Name (Call : Node_Id) return Node_Id is
3632 -- When the call invokes an entry family, the name appears as an indexed
3635 if Nkind (Nam) = N_Indexed_Component then
3636 Nam := Prefix (Nam);
3639 -- When the call employs the object.operation form, the name appears as
3640 -- a selected component.
3642 if Nkind (Nam) = N_Selected_Component then
3643 Nam := Selector_Name (Nam);
3647 end Extract_Call_Name;
3649 ---------------------------------
3650 -- Extract_Instance_Attributes --
3651 ---------------------------------
3653 procedure Extract_Instance_Attributes
3654 (Exp_Inst : Node_Id;
3655 Inst_Body : out Node_Id;
3656 Inst_Decl : out Node_Id)
3658 Body_Id : Entity_Id;
3661 -- Assume that the attributes are unavailable
3666 -- Generic package or subprogram spec
3668 if Nkind_In (Exp_Inst, N_Package_Declaration,
3669 N_Subprogram_Declaration)
3671 Inst_Decl := Exp_Inst;
3672 Body_Id := Corresponding_Body (Inst_Decl);
3674 if Present (Body_Id) then
3675 Inst_Body := Unit_Declaration_Node (Body_Id);
3678 -- Generic package or subprogram body
3682 (Nkind_In (Exp_Inst, N_Package_Body, N_Subprogram_Body));
3684 Inst_Body := Exp_Inst;
3685 Inst_Decl := Unit_Declaration_Node (Corresponding_Spec (Inst_Body));
3687 end Extract_Instance_Attributes;
3689 --------------------------------------
3690 -- Extract_Instantiation_Attributes --
3691 --------------------------------------
3693 procedure Extract_Instantiation_Attributes
3694 (Exp_Inst : Node_Id;
3696 Inst_Id : out Entity_Id;
3697 Gen_Id : out Entity_Id;
3698 Attrs : out Instantiation_Attributes)
3701 Inst := Original_Node (Exp_Inst);
3702 Inst_Id := Defining_Entity (Inst);
3704 -- Traverse a possible chain of renamings to obtain the original generic
3705 -- being instantiatied.
3707 Gen_Id := Get_Renamed_Entity (Entity (Name (Inst)));
3709 -- Set all attributes
3711 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Inst);
3712 Attrs.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Inst);
3713 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Node (Inst);
3714 Attrs.In_Declarations := Is_Declaration_Level_Node (Inst);
3715 Attrs.SPARK_Mode_On := Is_SPARK_Mode_On_Node (Inst);
3716 end Extract_Instantiation_Attributes;
3718 -------------------------------
3719 -- Extract_Target_Attributes --
3720 -------------------------------
3722 procedure Extract_Target_Attributes
3723 (Target_Id : Entity_Id;
3724 Attrs : out Target_Attributes)
3726 procedure Extract_Package_Or_Subprogram_Attributes
3727 (Spec_Id : out Entity_Id;
3728 Body_Decl : out Node_Id);
3729 -- Obtain the attributes associated with a package or a subprogram.
3730 -- Spec_Id is the package or subprogram. Body_Decl is the declaration
3731 -- of the corresponding package or subprogram body.
3733 procedure Extract_Protected_Entry_Attributes
3734 (Spec_Id : out Entity_Id;
3735 Body_Decl : out Node_Id;
3736 Body_Barf : out Node_Id);
3737 -- Obtain the attributes associated with a protected entry [family].
3738 -- Spec_Id is the entity of the protected body subprogram. Body_Decl
3739 -- is the declaration of Spec_Id's corresponding body. Body_Barf is
3740 -- the declaration of the barrier function body.
3742 procedure Extract_Protected_Subprogram_Attributes
3743 (Spec_Id : out Entity_Id;
3744 Body_Decl : out Node_Id);
3745 -- Obtain the attributes associated with a protected subprogram. Formal
3746 -- Spec_Id is the entity of the protected body subprogram. Body_Decl is
3747 -- the declaration of Spec_Id's corresponding body.
3749 procedure Extract_Task_Entry_Attributes
3750 (Spec_Id : out Entity_Id;
3751 Body_Decl : out Node_Id);
3752 -- Obtain the attributes associated with a task entry [family]. Formal
3753 -- Spec_Id is the entity of the task body procedure. Body_Decl is the
3754 -- declaration of Spec_Id's corresponding body.
3756 ----------------------------------------------
3757 -- Extract_Package_Or_Subprogram_Attributes --
3758 ----------------------------------------------
3760 procedure Extract_Package_Or_Subprogram_Attributes
3761 (Spec_Id : out Entity_Id;
3762 Body_Decl : out Node_Id)
3764 Body_Id : Entity_Id;
3765 Init_Id : Entity_Id;
3766 Spec_Decl : Node_Id;
3769 -- Assume that the body is not available
3772 Spec_Id := Target_Id;
3774 -- For body retrieval purposes, the entity of the initial declaration
3775 -- is that of the spec.
3779 -- The only exception to the above is a function which returns a
3780 -- constrained array type in a SPARK-to-C compilation. In this case
3781 -- the function receives a corresponding procedure which has an out
3782 -- parameter. The proper body for ABE checks and diagnostics is that
3783 -- of the procedure.
3785 if Ekind (Init_Id) = E_Function
3786 and then Rewritten_For_C (Init_Id)
3788 Init_Id := Corresponding_Procedure (Init_Id);
3791 -- Extract the attributes of the body
3793 Spec_Decl := Unit_Declaration_Node (Init_Id);
3795 -- The initial declaration is a stand alone subprogram body
3797 if Nkind (Spec_Decl) = N_Subprogram_Body then
3798 Body_Decl := Spec_Decl;
3800 -- Otherwise the package or subprogram has a spec and a completing
3803 elsif Nkind_In (Spec_Decl, N_Generic_Package_Declaration,
3804 N_Generic_Subprogram_Declaration,
3805 N_Package_Declaration,
3806 N_Subprogram_Body_Stub,
3807 N_Subprogram_Declaration)
3809 Body_Id := Corresponding_Body (Spec_Decl);
3811 if Present (Body_Id) then
3812 Body_Decl := Unit_Declaration_Node (Body_Id);
3815 end Extract_Package_Or_Subprogram_Attributes;
3817 ----------------------------------------
3818 -- Extract_Protected_Entry_Attributes --
3819 ----------------------------------------
3821 procedure Extract_Protected_Entry_Attributes
3822 (Spec_Id : out Entity_Id;
3823 Body_Decl : out Node_Id;
3824 Body_Barf : out Node_Id)
3826 Barf_Id : Entity_Id;
3827 Body_Id : Entity_Id;
3830 -- Assume that the bodies are not available
3835 -- When the entry [family] has already been expanded, it carries both
3836 -- the procedure which emulates the behavior of the entry [family] as
3837 -- well as the barrier function.
3839 if Present (Protected_Body_Subprogram (Target_Id)) then
3840 Spec_Id := Protected_Body_Subprogram (Target_Id);
3842 -- Extract the attributes of the barrier function
3846 (Unit_Declaration_Node (Barrier_Function (Target_Id)));
3848 if Present (Barf_Id) then
3849 Body_Barf := Unit_Declaration_Node (Barf_Id);
3852 -- Otherwise no expansion took place
3855 Spec_Id := Target_Id;
3858 -- Extract the attributes of the entry body
3860 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3862 if Present (Body_Id) then
3863 Body_Decl := Unit_Declaration_Node (Body_Id);
3865 end Extract_Protected_Entry_Attributes;
3867 ---------------------------------------------
3868 -- Extract_Protected_Subprogram_Attributes --
3869 ---------------------------------------------
3871 procedure Extract_Protected_Subprogram_Attributes
3872 (Spec_Id : out Entity_Id;
3873 Body_Decl : out Node_Id)
3875 Body_Id : Entity_Id;
3878 -- Assume that the body is not available
3882 -- When the protected subprogram has already been expanded, it
3883 -- carries the subprogram which seizes the lock and invokes the
3884 -- original statements.
3886 if Present (Protected_Subprogram (Target_Id)) then
3888 Protected_Body_Subprogram (Protected_Subprogram (Target_Id));
3890 -- Otherwise no expansion took place
3893 Spec_Id := Target_Id;
3896 -- Extract the attributes of the body
3898 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3900 if Present (Body_Id) then
3901 Body_Decl := Unit_Declaration_Node (Body_Id);
3903 end Extract_Protected_Subprogram_Attributes;
3905 -----------------------------------
3906 -- Extract_Task_Entry_Attributes --
3907 -----------------------------------
3909 procedure Extract_Task_Entry_Attributes
3910 (Spec_Id : out Entity_Id;
3911 Body_Decl : out Node_Id)
3913 Task_Typ : constant Entity_Id := Non_Private_View (Scope (Target_Id));
3914 Body_Id : Entity_Id;
3917 -- Assume that the body is not available
3921 -- The the task type has already been expanded, it carries the
3922 -- procedure which emulates the behavior of the task body.
3924 if Present (Task_Body_Procedure (Task_Typ)) then
3925 Spec_Id := Task_Body_Procedure (Task_Typ);
3927 -- Otherwise no expansion took place
3930 Spec_Id := Task_Typ;
3933 -- Extract the attributes of the body
3935 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
3937 if Present (Body_Id) then
3938 Body_Decl := Unit_Declaration_Node (Body_Id);
3940 end Extract_Task_Entry_Attributes;
3944 Prag : constant Node_Id := SPARK_Pragma (Target_Id);
3945 Body_Barf : Node_Id;
3946 Body_Decl : Node_Id;
3947 Spec_Id : Entity_Id;
3949 -- Start of processing for Extract_Target_Attributes
3952 -- Assume that the body of the barrier function is not available
3956 -- The target is a protected entry [family]
3958 if Is_Protected_Entry (Target_Id) then
3959 Extract_Protected_Entry_Attributes
3960 (Spec_Id => Spec_Id,
3961 Body_Decl => Body_Decl,
3962 Body_Barf => Body_Barf);
3964 -- The target is a protected subprogram
3966 elsif Is_Protected_Subp (Target_Id)
3967 or else Is_Protected_Body_Subp (Target_Id)
3969 Extract_Protected_Subprogram_Attributes
3970 (Spec_Id => Spec_Id,
3971 Body_Decl => Body_Decl);
3973 -- The target is a task entry [family]
3975 elsif Is_Task_Entry (Target_Id) then
3976 Extract_Task_Entry_Attributes
3977 (Spec_Id => Spec_Id,
3978 Body_Decl => Body_Decl);
3980 -- Otherwise the target is a package or a subprogram
3983 Extract_Package_Or_Subprogram_Attributes
3984 (Spec_Id => Spec_Id,
3985 Body_Decl => Body_Decl);
3988 -- Set all attributes
3990 Attrs.Body_Barf := Body_Barf;
3991 Attrs.Body_Decl := Body_Decl;
3992 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Target_Id);
3993 Attrs.From_Source := Comes_From_Source (Target_Id);
3994 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Entity (Target_Id);
3995 Attrs.SPARK_Mode_On :=
3996 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = On;
3997 Attrs.Spec_Decl := Unit_Declaration_Node (Spec_Id);
3998 Attrs.Spec_Id := Spec_Id;
3999 Attrs.Unit_Id := Find_Top_Unit (Target_Id);
4001 -- At this point certain attributes should always be available
4003 pragma Assert (Present (Attrs.Spec_Decl));
4004 pragma Assert (Present (Attrs.Spec_Id));
4005 pragma Assert (Present (Attrs.Unit_Id));
4006 end Extract_Target_Attributes;
4008 -----------------------------
4009 -- Extract_Task_Attributes --
4010 -----------------------------
4012 procedure Extract_Task_Attributes
4014 Attrs : out Task_Attributes)
4016 Task_Typ : constant Entity_Id := Non_Private_View (Typ);
4018 Body_Decl : Node_Id;
4019 Body_Id : Entity_Id;
4021 Spec_Id : Entity_Id;
4024 -- Assume that the body of the task procedure is not available
4028 -- The initial declaration is that of the task body procedure
4030 Spec_Id := Get_Task_Body_Procedure (Task_Typ);
4031 Body_Id := Corresponding_Body (Unit_Declaration_Node (Spec_Id));
4033 if Present (Body_Id) then
4034 Body_Decl := Unit_Declaration_Node (Body_Id);
4037 Prag := SPARK_Pragma (Task_Typ);
4039 -- Set all attributes
4041 Attrs.Body_Decl := Body_Decl;
4042 Attrs.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Task_Typ);
4043 Attrs.Ghost_Mode_Ignore := Is_Ignored_Ghost_Entity (Task_Typ);
4044 Attrs.SPARK_Mode_On :=
4045 Present (Prag) and then Get_SPARK_Mode_From_Annotation (Prag) = On;
4046 Attrs.Spec_Id := Spec_Id;
4047 Attrs.Task_Decl := Declaration_Node (Task_Typ);
4048 Attrs.Unit_Id := Find_Top_Unit (Task_Typ);
4050 -- At this point certain attributes should always be available
4052 pragma Assert (Present (Attrs.Spec_Id));
4053 pragma Assert (Present (Attrs.Task_Decl));
4054 pragma Assert (Present (Attrs.Unit_Id));
4055 end Extract_Task_Attributes;
4057 -------------------------------------------
4058 -- Extract_Variable_Reference_Attributes --
4059 -------------------------------------------
4061 procedure Extract_Variable_Reference_Attributes
4063 Var_Id : out Entity_Id;
4064 Attrs : out Variable_Attributes)
4066 function Get_Renamed_Variable (Id : Entity_Id) return Entity_Id;
4067 -- Obtain the ultimate renamed variable of variable Id
4069 --------------------------
4070 -- Get_Renamed_Variable --
4071 --------------------------
4073 function Get_Renamed_Variable (Id : Entity_Id) return Entity_Id is
4078 while Present (Renamed_Entity (Ren_Id))
4079 and then Nkind (Renamed_Entity (Ren_Id)) in N_Entity
4081 Ren_Id := Renamed_Entity (Ren_Id);
4085 end Get_Renamed_Variable;
4087 -- Start of processing for Extract_Variable_Reference_Attributes
4090 -- Extraction for variable reference markers
4092 if Nkind (Ref) = N_Variable_Reference_Marker then
4093 Var_Id := Target (Ref);
4095 -- Extraction for expanded names and identifiers
4098 Var_Id := Entity (Ref);
4101 -- Obtain the original variable which the reference mentions
4103 Var_Id := Get_Renamed_Variable (Var_Id);
4104 Attrs.Unit_Id := Find_Top_Unit (Var_Id);
4106 -- At this point certain attributes should always be available
4108 pragma Assert (Present (Attrs.Unit_Id));
4109 end Extract_Variable_Reference_Attributes;
4111 --------------------
4112 -- Find_Code_Unit --
4113 --------------------
4115 function Find_Code_Unit (N : Node_Or_Entity_Id) return Entity_Id is
4117 return Find_Unit_Entity (Unit (Cunit (Get_Code_Unit (N))));
4120 ----------------------------
4121 -- Find_Early_Call_Region --
4122 ----------------------------
4124 function Find_Early_Call_Region
4125 (Body_Decl : Node_Id;
4126 Assume_Elab_Body : Boolean := False;
4127 Skip_Memoization : Boolean := False) return Node_Id
4129 -- NOTE: The routines within Find_Early_Call_Region are intentionally
4130 -- unnested to avoid deep indentation of code.
4132 ECR_Found : exception;
4133 -- This exception is raised when the early call region has been found
4135 Start : Node_Id := Empty;
4136 -- The start of the early call region. This variable is updated by the
4137 -- various nested routines. Due to the use of exceptions, the variable
4138 -- must be global to the nested routines.
4140 -- The algorithm implemented in this routine attempts to find the early
4141 -- call region of a subprogram body by inspecting constructs in reverse
4142 -- declarative order, while navigating the tree. The algorithm consists
4143 -- of an Inspection phase and an Advancement phase. The pseudocode is as
4148 -- advancement phase
4151 -- The infinite loop is terminated by raising exception ECR_Found. The
4152 -- algorithm utilizes two pointers, Curr and Start, to represent the
4153 -- current construct to inspect and the start of the early call region.
4155 -- IMPORTANT: The algorithm must maintain the following invariant at all
4156 -- time for it to function properly - a nested construct is entered only
4157 -- when it contains suitable constructs. This guarantees that leaving a
4158 -- nested or encapsulating construct functions properly.
4160 -- The Inspection phase determines whether the current construct is non-
4161 -- preelaborable, and if it is, the algorithm terminates.
4163 -- The Advancement phase walks the tree in reverse declarative order,
4164 -- while entering and leaving nested and encapsulating constructs. It
4165 -- may also terminate the elaborithm. There are several special cases
4172 -- <construct N-1> <- Curr
4173 -- <construct N> <- Start
4174 -- <subprogram body>
4176 -- In the general case, a declarative or statement list is traversed in
4177 -- reverse order where Curr is the lead pointer, and Start indicates the
4178 -- last preelaborable construct.
4180 -- 2) Entering handled bodies
4182 -- package body Nested is <- Curr (2.3)
4183 -- <declarations> <- Curr (2.2)
4185 -- <statements> <- Curr (2.1)
4187 -- <construct> <- Start
4189 -- In this case, the algorithm enters a handled body by starting from
4190 -- the last statement (2.1), or the last declaration (2.2), or the body
4191 -- is consumed (2.3) because it is empty and thus preelaborable.
4193 -- 3) Entering package declarations
4195 -- package Nested is <- Curr (2.3)
4196 -- <visible declarations> <- Curr (2.2)
4198 -- <private declarations> <- Curr (2.1)
4200 -- <construct> <- Start
4202 -- In this case, the algorithm enters a package declaration by starting
4203 -- from the last private declaration (2.1), the last visible declaration
4204 -- (2.2), or the package is consumed (2.3) because it is empty and thus
4207 -- 4) Transitioning from list to list of the same construct
4209 -- Certain constructs have two eligible lists. The algorithm must thus
4210 -- transition from the second to the first list when the second list is
4213 -- declare <- Curr (4.2)
4214 -- <declarations> <- Curr (4.1)
4216 -- <statements> <- Start
4219 -- In this case, the algorithm has exhausted the second list (statements
4220 -- in the example), and continues with the last declaration (4.1) or the
4221 -- construct is consumed (4.2) because it contains only preelaborable
4224 -- 5) Transitioning from list to construct
4226 -- tack body Task is <- Curr (5.1)
4228 -- <construct 1> <- Start
4230 -- In this case, the algorithm has exhausted a list, Curr is Empty, and
4231 -- the owner of the list is consumed (5.1).
4233 -- 6) Transitioning from unit to unit
4235 -- A package body with a spec subject to pragma Elaborate_Body extends
4236 -- the possible range of the early call region to the package spec.
4238 -- package Pack is <- Curr (6.3)
4239 -- pragma Elaborate_Body; <- Curr (6.2)
4240 -- <visible declarations> <- Curr (6.2)
4242 -- <private declarations> <- Curr (6.1)
4245 -- package body Pack is <- Curr, Start
4247 -- In this case, the algorithm has reached a package body compilation
4248 -- unit whose spec is subject to pragma Elaborate_Body, or the caller
4249 -- of the algorithm has specified this behavior. This transition is
4250 -- equivalent to 3).
4252 -- 7) Transitioning from unit to termination
4254 -- Reaching a compilation unit always terminates the algorithm as there
4255 -- are no more lists to examine. This must take 6) into account.
4257 -- 8) Transitioning from subunit to stub
4259 -- package body Pack is separate; <- Curr (8.1)
4262 -- package body Pack is <- Curr, Start
4264 -- Reaching a subunit continues the search from the corresponding stub
4267 procedure Advance (Curr : in out Node_Id);
4268 pragma Inline (Advance);
4269 -- Update the Curr and Start pointers depending on their location in the
4270 -- tree to the next eligible construct. This routine raises ECR_Found.
4272 procedure Enter_Handled_Body (Curr : in out Node_Id);
4273 pragma Inline (Enter_Handled_Body);
4274 -- Update the Curr and Start pointers to enter a nested handled body if
4275 -- applicable. This routine raises ECR_Found.
4277 procedure Enter_Package_Declaration (Curr : in out Node_Id);
4278 pragma Inline (Enter_Package_Declaration);
4279 -- Update the Curr and Start pointers to enter a nested package spec if
4280 -- applicable. This routine raises ECR_Found.
4282 function Find_ECR (N : Node_Id) return Node_Id;
4283 pragma Inline (Find_ECR);
4284 -- Find an early call region starting from arbitrary node N
4286 function Has_Suitable_Construct (List : List_Id) return Boolean;
4287 pragma Inline (Has_Suitable_Construct);
4288 -- Determine whether list List contains at least one suitable construct
4289 -- for inclusion into an early call region.
4291 procedure Include (N : Node_Id; Curr : out Node_Id);
4292 pragma Inline (Include);
4293 -- Update the Curr and Start pointers to include arbitrary construct N
4294 -- in the early call region. This routine raises ECR_Found.
4296 function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean;
4297 pragma Inline (Is_OK_Preelaborable_Construct);
4298 -- Determine whether arbitrary node N denotes a preelaboration-safe
4301 function Is_Suitable_Construct (N : Node_Id) return Boolean;
4302 pragma Inline (Is_Suitable_Construct);
4303 -- Determine whether arbitrary node N denotes a suitable construct for
4304 -- inclusion into the early call region.
4306 procedure Transition_Body_Declarations
4308 Curr : in out Node_Id);
4309 pragma Inline (Transition_Body_Declarations);
4310 -- Update the Curr and Start pointers when construct Bod denotes a block
4311 -- statement or a suitable body. This routine raises ECR_Found.
4313 procedure Transition_Handled_Statements
4315 Curr : in out Node_Id);
4316 pragma Inline (Transition_Handled_Statements);
4317 -- Update the Curr and Start pointers when node HSS denotes a handled
4318 -- sequence of statements. This routine raises ECR_Found.
4320 procedure Transition_Spec_Declarations
4322 Curr : in out Node_Id);
4323 pragma Inline (Transition_Spec_Declarations);
4324 -- Update the Curr and Start pointers when construct Spec denotes
4325 -- a concurrent definition or a package spec. This routine raises
4328 procedure Transition_Unit (Unit : Node_Id; Curr : in out Node_Id);
4329 pragma Inline (Transition_Unit);
4330 -- Update the Curr and Start pointers when node Unit denotes a potential
4331 -- compilation unit. This routine raises ECR_Found.
4337 procedure Advance (Curr : in out Node_Id) is
4341 -- Curr denotes one of the following cases upon entry into this
4344 -- * Empty - There is no current construct when a declarative or a
4345 -- statement list has been exhausted. This does not necessarily
4346 -- indicate that the early call region has been computed as it
4347 -- may still be possible to transition to another list.
4349 -- * Encapsulator - The current construct encapsulates declarations
4350 -- and/or statements. This indicates that the early call region
4351 -- may extend within the nested construct.
4353 -- * Preelaborable - The current construct is always preelaborable
4354 -- because Find_ECR would not invoke Advance if this was not the
4357 -- The current construct is an encapsulator or is preelaborable
4359 if Present (Curr) then
4361 -- Enter encapsulators by inspecting their declarations and/or
4364 if Nkind_In (Curr, N_Block_Statement, N_Package_Body) then
4365 Enter_Handled_Body (Curr);
4367 elsif Nkind (Curr) = N_Package_Declaration then
4368 Enter_Package_Declaration (Curr);
4370 -- Early call regions have a property which can be exploited to
4371 -- optimize the algorithm.
4373 -- <preceding subprogram body>
4374 -- <preelaborable construct 1>
4376 -- <preelaborable construct N>
4377 -- <initiating subprogram body>
4379 -- If a traversal initiated from a subprogram body reaches a
4380 -- preceding subprogram body, then both bodies share the same
4381 -- early call region.
4383 -- The property results in the following desirable effects:
4385 -- * If the preceding body already has an early call region, then
4386 -- the initiating body can reuse it. This minimizes the amount
4387 -- of processing performed by the algorithm.
4389 -- * If the preceding body lack an early call region, then the
4390 -- algorithm can compute the early call region, and reuse it
4391 -- for the initiating body. This processing performs the same
4392 -- amount of work, but has the beneficial effect of computing
4393 -- the early call regions of all preceding bodies.
4395 elsif Nkind_In (Curr, N_Entry_Body, N_Subprogram_Body) then
4397 Find_Early_Call_Region
4399 Assume_Elab_Body => Assume_Elab_Body,
4400 Skip_Memoization => Skip_Memoization);
4404 -- Otherwise current construct is preelaborable. Unpdate the early
4405 -- call region to include it.
4408 Include (Curr, Curr);
4411 -- Otherwise the current construct is missing, indicating that the
4412 -- current list has been exhausted. Depending on the context of the
4413 -- list, several transitions are possible.
4416 -- The invariant of the algorithm ensures that Curr and Start are
4417 -- at the same level of nesting at the point of a transition. The
4418 -- algorithm can determine which list the traversal came from by
4421 Context := Parent (Start);
4423 -- Attempt the following transitions:
4425 -- private declarations -> visible declarations
4426 -- private declarations -> upper level
4427 -- private declarations -> terminate
4428 -- visible declarations -> upper level
4429 -- visible declarations -> terminate
4431 if Nkind_In (Context, N_Package_Specification,
4432 N_Protected_Definition,
4435 Transition_Spec_Declarations (Context, Curr);
4437 -- Attempt the following transitions:
4439 -- statements -> declarations
4440 -- statements -> upper level
4441 -- statements -> corresponding package spec (Elab_Body)
4442 -- statements -> terminate
4444 elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then
4445 Transition_Handled_Statements (Context, Curr);
4447 -- Attempt the following transitions:
4449 -- declarations -> upper level
4450 -- declarations -> corresponding package spec (Elab_Body)
4451 -- declarations -> terminate
4453 elsif Nkind_In (Context, N_Block_Statement,
4460 Transition_Body_Declarations (Context, Curr);
4462 -- Otherwise it is not possible to transition. Stop the search
4463 -- because there are no more declarations or statements to check.
4471 --------------------------
4472 -- Enter_Handled_Body --
4473 --------------------------
4475 procedure Enter_Handled_Body (Curr : in out Node_Id) is
4476 Decls : constant List_Id := Declarations (Curr);
4477 HSS : constant Node_Id := Handled_Statement_Sequence (Curr);
4478 Stmts : List_Id := No_List;
4481 if Present (HSS) then
4482 Stmts := Statements (HSS);
4485 -- The handled body has a non-empty statement sequence. The construct
4486 -- to inspect is the last statement.
4488 if Has_Suitable_Construct (Stmts) then
4489 Curr := Last (Stmts);
4491 -- The handled body lacks statements, but has non-empty declarations.
4492 -- The construct to inspect is the last declaration.
4494 elsif Has_Suitable_Construct (Decls) then
4495 Curr := Last (Decls);
4497 -- Otherwise the handled body lacks both declarations and statements.
4498 -- The construct to inspect is the node which precedes the handled
4499 -- body. Update the early call region to include the handled body.
4502 Include (Curr, Curr);
4504 end Enter_Handled_Body;
4506 -------------------------------
4507 -- Enter_Package_Declaration --
4508 -------------------------------
4510 procedure Enter_Package_Declaration (Curr : in out Node_Id) is
4511 Pack_Spec : constant Node_Id := Specification (Curr);
4512 Prv_Decls : constant List_Id := Private_Declarations (Pack_Spec);
4513 Vis_Decls : constant List_Id := Visible_Declarations (Pack_Spec);
4516 -- The package has a non-empty private declarations. The construct to
4517 -- inspect is the last private declaration.
4519 if Has_Suitable_Construct (Prv_Decls) then
4520 Curr := Last (Prv_Decls);
4522 -- The package lacks private declarations, but has non-empty visible
4523 -- declarations. In this case the construct to inspect is the last
4524 -- visible declaration.
4526 elsif Has_Suitable_Construct (Vis_Decls) then
4527 Curr := Last (Vis_Decls);
4529 -- Otherwise the package lacks any declarations. The construct to
4530 -- inspect is the node which precedes the package. Update the early
4531 -- call region to include the package declaration.
4534 Include (Curr, Curr);
4536 end Enter_Package_Declaration;
4542 function Find_ECR (N : Node_Id) return Node_Id is
4546 -- The early call region starts at N
4551 -- Inspect each node in reverse declarative order while going in and
4552 -- out of nested and enclosing constructs. Note that the only way to
4553 -- terminate this infinite loop is to raise exception ECR_Found.
4556 -- The current construct is not preelaboration-safe. Terminate the
4560 and then not Is_OK_Preelaborable_Construct (Curr)
4565 -- Advance to the next suitable construct. This may terminate the
4566 -- traversal by raising ECR_Found.
4576 ----------------------------
4577 -- Has_Suitable_Construct --
4578 ----------------------------
4580 function Has_Suitable_Construct (List : List_Id) return Boolean is
4584 -- Examine the list in reverse declarative order, looking for a
4585 -- suitable construct.
4587 if Present (List) then
4588 Item := Last (List);
4589 while Present (Item) loop
4590 if Is_Suitable_Construct (Item) then
4599 end Has_Suitable_Construct;
4605 procedure Include (N : Node_Id; Curr : out Node_Id) is
4609 -- The input node is a compilation unit. This terminates the search
4610 -- because there are no more lists to inspect and there are no more
4611 -- enclosing constructs to climb up to. The transitions are:
4613 -- private declarations -> terminate
4614 -- visible declarations -> terminate
4615 -- statements -> terminate
4616 -- declarations -> terminate
4618 if Nkind (Parent (Start)) = N_Compilation_Unit then
4621 -- Otherwise the input node is still within some list
4624 Curr := Prev (Start);
4628 -----------------------------------
4629 -- Is_OK_Preelaborable_Construct --
4630 -----------------------------------
4632 function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean is
4634 -- Assignment statements are acceptable as long as they were produced
4635 -- by the ABE mechanism to update elaboration flags.
4637 if Nkind (N) = N_Assignment_Statement then
4638 return Is_Elaboration_Code (N);
4640 -- Block statements are acceptable even though they directly violate
4641 -- preelaborability. The intention is not to penalize the early call
4642 -- region when a block contains only preelaborable constructs.
4645 -- Val : constant Integer := 1;
4647 -- pragma Assert (Val = 1);
4651 -- Note that the Advancement phase does enter blocks, and will detect
4652 -- any non-preelaborable declarations or statements within.
4654 elsif Nkind (N) = N_Block_Statement then
4658 -- Otherwise the construct must be preelaborable. The check must take
4659 -- the syntactic and semantic structure of the construct. DO NOT use
4660 -- Is_Preelaborable_Construct here.
4662 return not Is_Non_Preelaborable_Construct (N);
4663 end Is_OK_Preelaborable_Construct;
4665 ---------------------------
4666 -- Is_Suitable_Construct --
4667 ---------------------------
4669 function Is_Suitable_Construct (N : Node_Id) return Boolean is
4670 Context : constant Node_Id := Parent (N);
4673 -- An internally-generated statement sequence which contains only a
4674 -- single null statement is not a suitable construct because it is a
4675 -- byproduct of the parser. Such a null statement should be excluded
4676 -- from the early call region because it carries the source location
4677 -- of the "end" keyword, and may lead to confusing diagnistics.
4679 if Nkind (N) = N_Null_Statement
4680 and then not Comes_From_Source (N)
4681 and then Present (Context)
4682 and then Nkind (Context) = N_Handled_Sequence_Of_Statements
4683 and then not Comes_From_Source (N)
4688 -- Otherwise only constructs which correspond to pure Ada constructs
4689 -- are considered suitable.
4694 | N_Freeze_Generic_Entity
4695 | N_Implicit_Label_Declaration
4697 | N_Pop_Constraint_Error_Label
4698 | N_Pop_Program_Error_Label
4699 | N_Pop_Storage_Error_Label
4700 | N_Push_Constraint_Error_Label
4701 | N_Push_Program_Error_Label
4702 | N_Push_Storage_Error_Label
4703 | N_SCIL_Dispatch_Table_Tag_Init
4704 | N_SCIL_Dispatching_Call
4705 | N_SCIL_Membership_Test
4706 | N_Variable_Reference_Marker
4713 end Is_Suitable_Construct;
4715 ----------------------------------
4716 -- Transition_Body_Declarations --
4717 ----------------------------------
4719 procedure Transition_Body_Declarations
4721 Curr : in out Node_Id)
4723 Decls : constant List_Id := Declarations (Bod);
4726 -- The search must come from the declarations of the body
4729 (Is_Non_Empty_List (Decls)
4730 and then List_Containing (Start) = Decls);
4732 -- The search finished inspecting the declarations. The construct
4733 -- to inspect is the node which precedes the handled body, unless
4734 -- the body is a compilation unit. The transitions are:
4736 -- declarations -> upper level
4737 -- declarations -> corresponding package spec (Elab_Body)
4738 -- declarations -> terminate
4740 Transition_Unit (Bod, Curr);
4741 end Transition_Body_Declarations;
4743 -----------------------------------
4744 -- Transition_Handled_Statements --
4745 -----------------------------------
4747 procedure Transition_Handled_Statements
4749 Curr : in out Node_Id)
4751 Bod : constant Node_Id := Parent (HSS);
4752 Decls : constant List_Id := Declarations (Bod);
4753 Stmts : constant List_Id := Statements (HSS);
4756 -- The search must come from the statements of certain bodies or
4759 pragma Assert (Nkind_In (Bod, N_Block_Statement,
4766 -- The search must come from the statements of the handled sequence
4769 (Is_Non_Empty_List (Stmts)
4770 and then List_Containing (Start) = Stmts);
4772 -- The search finished inspecting the statements. The handled body
4773 -- has non-empty declarations. The construct to inspect is the last
4774 -- declaration. The transitions are:
4776 -- statements -> declarations
4778 if Has_Suitable_Construct (Decls) then
4779 Curr := Last (Decls);
4781 -- Otherwise the handled body lacks declarations. The construct to
4782 -- inspect is the node which precedes the handled body, unless the
4783 -- body is a compilation unit. The transitions are:
4785 -- statements -> upper level
4786 -- statements -> corresponding package spec (Elab_Body)
4787 -- statements -> terminate
4790 Transition_Unit (Bod, Curr);
4792 end Transition_Handled_Statements;
4794 ----------------------------------
4795 -- Transition_Spec_Declarations --
4796 ----------------------------------
4798 procedure Transition_Spec_Declarations
4800 Curr : in out Node_Id)
4802 Prv_Decls : constant List_Id := Private_Declarations (Spec);
4803 Vis_Decls : constant List_Id := Visible_Declarations (Spec);
4806 pragma Assert (Present (Start) and then Is_List_Member (Start));
4808 -- The search came from the private declarations and finished their
4811 if Has_Suitable_Construct (Prv_Decls)
4812 and then List_Containing (Start) = Prv_Decls
4814 -- The context has non-empty visible declarations. The node to
4815 -- inspect is the last visible declaration. The transitions are:
4817 -- private declarations -> visible declarations
4819 if Has_Suitable_Construct (Vis_Decls) then
4820 Curr := Last (Vis_Decls);
4822 -- Otherwise the context lacks visible declarations. The construct
4823 -- to inspect is the node which precedes the context unless the
4824 -- context is a compilation unit. The transitions are:
4826 -- private declarations -> upper level
4827 -- private declarations -> terminate
4830 Transition_Unit (Parent (Spec), Curr);
4833 -- The search came from the visible declarations and finished their
4834 -- inspections. The construct to inspect is the node which precedes
4835 -- the context, unless the context is a compilaton unit. The
4838 -- visible declarations -> upper level
4839 -- visible declarations -> terminate
4841 elsif Has_Suitable_Construct (Vis_Decls)
4842 and then List_Containing (Start) = Vis_Decls
4844 Transition_Unit (Parent (Spec), Curr);
4846 -- At this point both declarative lists are empty, but the traversal
4847 -- still came from within the spec. This indicates that the invariant
4848 -- of the algorithm has been violated.
4851 pragma Assert (False);
4854 end Transition_Spec_Declarations;
4856 ---------------------
4857 -- Transition_Unit --
4858 ---------------------
4860 procedure Transition_Unit
4862 Curr : in out Node_Id)
4864 Context : constant Node_Id := Parent (Unit);
4867 -- The unit is a compilation unit. This terminates the search because
4868 -- there are no more lists to inspect and there are no more enclosing
4869 -- constructs to climb up to.
4871 if Nkind (Context) = N_Compilation_Unit then
4873 -- A package body with a corresponding spec subject to pragma
4874 -- Elaborate_Body is an exception to the above. The annotation
4875 -- allows the search to continue into the package declaration.
4876 -- The transitions are:
4878 -- statements -> corresponding package spec (Elab_Body)
4879 -- declarations -> corresponding package spec (Elab_Body)
4881 if Nkind (Unit) = N_Package_Body
4882 and then (Assume_Elab_Body
4883 or else Has_Pragma_Elaborate_Body
4884 (Corresponding_Spec (Unit)))
4886 Curr := Unit_Declaration_Node (Corresponding_Spec (Unit));
4887 Enter_Package_Declaration (Curr);
4889 -- Otherwise terminate the search. The transitions are:
4891 -- private declarations -> terminate
4892 -- visible declarations -> terminate
4893 -- statements -> terminate
4894 -- declarations -> terminate
4900 -- The unit is a subunit. The construct to inspect is the node which
4901 -- precedes the corresponding stub. Update the early call region to
4902 -- include the unit.
4904 elsif Nkind (Context) = N_Subunit then
4906 Curr := Corresponding_Stub (Context);
4908 -- Otherwise the unit is nested. The construct to inspect is the node
4909 -- which precedes the unit. Update the early call region to include
4913 Include (Unit, Curr);
4915 end Transition_Unit;
4919 Body_Id : constant Entity_Id := Defining_Entity (Body_Decl);
4922 -- Start of processing for Find_Early_Call_Region
4925 -- The caller demands the start of the early call region without saving
4926 -- or retrieving it to/from internal data structures.
4928 if Skip_Memoization then
4929 Region := Find_ECR (Body_Decl);
4934 -- Check whether the early call region of the subprogram body is
4937 Region := Early_Call_Region (Body_Id);
4941 -- Traverse the declarations in reverse order, starting from the
4942 -- subprogram body, searching for the nearest non-preelaborable
4943 -- construct. The early call region starts after this construct
4944 -- and ends at the subprogram body.
4946 Region := Find_ECR (Body_Decl);
4948 -- Associate the early call region with the subprogram body in
4949 -- case other scenarios need it.
4951 Set_Early_Call_Region (Body_Id, Region);
4955 -- A subprogram body must always have an early call region
4957 pragma Assert (Present (Region));
4960 end Find_Early_Call_Region;
4962 ---------------------------
4963 -- Find_Elaborated_Units --
4964 ---------------------------
4966 procedure Find_Elaborated_Units is
4967 procedure Add_Pragma (Prag : Node_Id);
4968 -- Determine whether pragma Prag denotes a legal Elaborate[_All] pragma.
4969 -- If this is the case, add the related unit to the elaboration context.
4970 -- For pragma Elaborate_All, include recursively all units withed by the
4974 (Unit_Id : Entity_Id;
4976 Full_Context : Boolean);
4977 -- Add unit Unit_Id to the elaboration context. Prag denotes the pragma
4978 -- which prompted the inclusion of the unit to the elaboration context.
4979 -- If flag Full_Context is set, examine the nonlimited clauses of unit
4980 -- Unit_Id and add each withed unit to the context.
4982 procedure Find_Elaboration_Context (Comp_Unit : Node_Id);
4983 -- Examine the context items of compilation unit Comp_Unit for suitable
4984 -- elaboration-related pragmas and add all related units to the context.
4990 procedure Add_Pragma (Prag : Node_Id) is
4991 Prag_Args : constant List_Id := Pragma_Argument_Associations (Prag);
4992 Prag_Nam : constant Name_Id := Pragma_Name (Prag);
4996 -- Nothing to do if the pragma is not related to elaboration
4998 if not Nam_In (Prag_Nam, Name_Elaborate, Name_Elaborate_All) then
5001 -- Nothing to do when the pragma is illegal
5003 elsif Error_Posted (Prag) then
5007 Unit_Arg := Get_Pragma_Arg (First (Prag_Args));
5009 -- The argument of the pragma may appear in package.package form
5011 if Nkind (Unit_Arg) = N_Selected_Component then
5012 Unit_Arg := Selector_Name (Unit_Arg);
5016 (Unit_Id => Entity (Unit_Arg),
5018 Full_Context => Prag_Nam = Name_Elaborate_All);
5026 (Unit_Id : Entity_Id;
5028 Full_Context : Boolean)
5031 Elab_Attrs : Elaboration_Attributes;
5034 -- Nothing to do when some previous error left a with clause or a
5035 -- pragma in a bad state.
5037 if No (Unit_Id) then
5041 Elab_Attrs := Elaboration_Status (Unit_Id);
5043 -- The unit is already included in the context by means of pragma
5046 if Present (Elab_Attrs.Source_Pragma) then
5048 -- Upgrade an existing pragma Elaborate when the unit is subject
5049 -- to Elaborate_All because the new pragma covers a larger set of
5052 if Pragma_Name (Elab_Attrs.Source_Pragma) = Name_Elaborate
5053 and then Pragma_Name (Prag) = Name_Elaborate_All
5055 Elab_Attrs.Source_Pragma := Prag;
5057 -- Otherwise the unit retains its existing pragma and does not
5058 -- need to be included in the context again.
5064 -- The current unit is not part of the context. Prepare a new set of
5069 Elaboration_Attributes'(Source_Pragma
=> Prag
,
5070 With_Clause
=> Empty
);
5073 -- Add or update the attributes of the unit
5075 Set_Elaboration_Status
(Unit_Id
, Elab_Attrs
);
5077 -- Includes all units withed by the current one when computing the
5080 if Full_Context
then
5082 -- Process all nonlimited with clauses found in the context of
5083 -- the current unit. Note that limited clauses do not impose an
5084 -- elaboration order.
5086 Clause
:= First
(Context_Items
(Compilation_Unit
(Unit_Id
)));
5087 while Present
(Clause
) loop
5088 if Nkind
(Clause
) = N_With_Clause
5089 and then not Error_Posted
(Clause
)
5090 and then not Limited_Present
(Clause
)
5093 (Unit_Id
=> Entity
(Name
(Clause
)),
5095 Full_Context
=> Full_Context
);
5103 ------------------------------
5104 -- Find_Elaboration_Context --
5105 ------------------------------
5107 procedure Find_Elaboration_Context
(Comp_Unit
: Node_Id
) is
5111 pragma Assert
(Nkind
(Comp_Unit
) = N_Compilation_Unit
);
5113 -- Process all elaboration-related pragmas found in the context of
5114 -- the compilation unit.
5116 Prag
:= First
(Context_Items
(Comp_Unit
));
5117 while Present
(Prag
) loop
5118 if Nkind
(Prag
) = N_Pragma
then
5124 end Find_Elaboration_Context
;
5131 -- Start of processing for Find_Elaborated_Units
5134 -- Perform a traversal which examines the context of the main unit and
5135 -- populates the Elaboration_Context table with all units elaborated
5136 -- prior to the main unit. The traversal performs the following jumps:
5138 -- subunit -> parent subunit
5139 -- parent subunit -> body
5141 -- spec -> parent spec
5142 -- parent spec -> grandparent spec and so on
5144 -- The traversal relies on units rather than scopes because the scope of
5145 -- a subunit is some spec, while this traversal must process the body as
5146 -- well. Given that protected and task bodies can also be subunits, this
5147 -- complicates the scope approach even further.
5149 Unt
:= Unit
(Cunit
(Main_Unit
));
5151 -- Perform the following traversals when the main unit is a subunit
5153 -- subunit -> parent subunit
5154 -- parent subunit -> body
5156 while Present
(Unt
) and then Nkind
(Unt
) = N_Subunit
loop
5157 Find_Elaboration_Context
(Parent
(Unt
));
5159 -- Continue the traversal by going to the unit which contains the
5160 -- corresponding stub.
5162 if Present
(Corresponding_Stub
(Unt
)) then
5163 Unt
:= Unit
(Cunit
(Get_Source_Unit
(Corresponding_Stub
(Unt
))));
5165 -- Otherwise the subunit may be erroneous or left in a bad state
5172 -- Perform the following traversal now that subunits have been taken
5173 -- care of, or the main unit is a body.
5178 and then Nkind_In
(Unt
, N_Package_Body
, N_Subprogram_Body
)
5180 Find_Elaboration_Context
(Parent
(Unt
));
5182 -- Continue the traversal by going to the unit which contains the
5183 -- corresponding spec.
5185 if Present
(Corresponding_Spec
(Unt
)) then
5186 Unt
:= Unit
(Cunit
(Get_Source_Unit
(Corresponding_Spec
(Unt
))));
5190 -- Perform the following traversals now that the body has been taken
5191 -- care of, or the main unit is a spec.
5193 -- spec -> parent spec
5194 -- parent spec -> grandparent spec and so on
5197 and then Nkind_In
(Unt
, N_Generic_Package_Declaration
,
5198 N_Generic_Subprogram_Declaration
,
5199 N_Package_Declaration
,
5200 N_Subprogram_Declaration
)
5202 Find_Elaboration_Context
(Parent
(Unt
));
5204 -- Process a potential chain of parent units which ends with the
5205 -- main unit spec. The traversal can now safely rely on the scope
5208 Par_Id
:= Scope
(Defining_Entity
(Unt
));
5209 while Present
(Par_Id
) and then Par_Id
/= Standard_Standard
loop
5210 Find_Elaboration_Context
(Compilation_Unit
(Par_Id
));
5212 Par_Id
:= Scope
(Par_Id
);
5215 end Find_Elaborated_Units
;
5217 -----------------------------
5218 -- Find_Enclosing_Instance --
5219 -----------------------------
5221 function Find_Enclosing_Instance
(N
: Node_Id
) return Node_Id
is
5223 Spec_Id
: Entity_Id
;
5226 -- Climb the parent chain looking for an enclosing instance spec or body
5229 while Present
(Par
) loop
5231 -- Generic package or subprogram spec
5233 if Nkind_In
(Par
, N_Package_Declaration
,
5234 N_Subprogram_Declaration
)
5235 and then Is_Generic_Instance
(Defining_Entity
(Par
))
5239 -- Generic package or subprogram body
5241 elsif Nkind_In
(Par
, N_Package_Body
, N_Subprogram_Body
) then
5242 Spec_Id
:= Corresponding_Spec
(Par
);
5244 if Present
(Spec_Id
) and then Is_Generic_Instance
(Spec_Id
) then
5249 Par
:= Parent
(Par
);
5253 end Find_Enclosing_Instance
;
5255 --------------------------
5256 -- Find_Enclosing_Level --
5257 --------------------------
5259 function Find_Enclosing_Level
(N
: Node_Id
) return Enclosing_Level_Kind
is
5260 function Level_Of
(Unit
: Node_Id
) return Enclosing_Level_Kind
;
5261 -- Obtain the corresponding level of unit Unit
5267 function Level_Of
(Unit
: Node_Id
) return Enclosing_Level_Kind
is
5268 Spec_Id
: Entity_Id
;
5271 if Nkind
(Unit
) in N_Generic_Instantiation
then
5272 return Instantiation
;
5274 elsif Nkind
(Unit
) = N_Generic_Package_Declaration
then
5275 return Generic_Package_Spec
;
5277 elsif Nkind
(Unit
) = N_Package_Declaration
then
5278 return Package_Spec
;
5280 elsif Nkind
(Unit
) = N_Package_Body
then
5281 Spec_Id
:= Corresponding_Spec
(Unit
);
5283 -- The body belongs to a generic package
5285 if Present
(Spec_Id
)
5286 and then Ekind
(Spec_Id
) = E_Generic_Package
5288 return Generic_Package_Body
;
5290 -- Otherwise the body belongs to a non-generic package. This also
5291 -- treats an illegal package body without a corresponding spec as
5292 -- a non-generic package body.
5295 return Package_Body
;
5308 -- Start of processing for Find_Enclosing_Level
5311 -- Call markers and instantiations which appear at the declaration level
5312 -- but are later relocated in a different context retain their original
5313 -- declaration level.
5315 if Nkind_In
(N
, N_Call_Marker
,
5316 N_Function_Instantiation
,
5317 N_Package_Instantiation
,
5318 N_Procedure_Instantiation
)
5319 and then Is_Declaration_Level_Node
(N
)
5321 return Declaration_Level
;
5324 -- Climb the parent chain looking at the enclosing levels
5327 Curr
:= Parent
(Prev
);
5328 while Present
(Curr
) loop
5330 -- A traversal from a subunit continues via the corresponding stub
5332 if Nkind
(Curr
) = N_Subunit
then
5333 Curr
:= Corresponding_Stub
(Curr
);
5335 -- The current construct is a package. Packages are ignored because
5336 -- they are always elaborated when the enclosing context is invoked
5339 elsif Nkind_In
(Curr
, N_Package_Body
, N_Package_Declaration
) then
5342 -- The current construct is a block statement
5344 elsif Nkind
(Curr
) = N_Block_Statement
then
5346 -- Ignore internally generated blocks created by the expander for
5347 -- various purposes such as abort defer/undefer.
5349 if not Comes_From_Source
(Curr
) then
5352 -- If the traversal came from the handled sequence of statments,
5353 -- then the node appears at the level of the enclosing construct.
5354 -- This is a more reliable test because transients scopes within
5355 -- the declarative region of the encapsulator are hard to detect.
5357 elsif Nkind
(Prev
) = N_Handled_Sequence_Of_Statements
5358 and then Handled_Statement_Sequence
(Curr
) = Prev
5360 return Find_Enclosing_Level
(Parent
(Curr
));
5362 -- Otherwise the traversal came from the declarations, the node is
5363 -- at the declaration level.
5366 return Declaration_Level
;
5369 -- The current construct is a declaration-level encapsulator
5371 elsif Nkind_In
(Curr
, N_Entry_Body
,
5375 -- If the traversal came from the handled sequence of statments,
5376 -- then the node cannot possibly appear at any level. This is
5377 -- a more reliable test because transients scopes within the
5378 -- declarative region of the encapsulator are hard to detect.
5380 if Nkind
(Prev
) = N_Handled_Sequence_Of_Statements
5381 and then Handled_Statement_Sequence
(Curr
) = Prev
5385 -- Otherwise the traversal came from the declarations, the node is
5386 -- at the declaration level.
5389 return Declaration_Level
;
5392 -- The current construct is a non-library-level encapsulator which
5393 -- indicates that the node cannot possibly appear at any level.
5394 -- Note that this check must come after the declaration-level check
5395 -- because both predicates share certain nodes.
5397 elsif Is_Non_Library_Level_Encapsulator
(Curr
) then
5398 Context
:= Parent
(Curr
);
5400 -- The sole exception is when the encapsulator is the compilation
5401 -- utit itself because the compilation unit node requires special
5402 -- processing (see below).
5404 if Present
(Context
)
5405 and then Nkind
(Context
) = N_Compilation_Unit
5409 -- Otherwise the node is not at any level
5415 -- The current construct is a compilation unit. The node appears at
5416 -- the [generic] library level when the unit is a [generic] package.
5418 elsif Nkind
(Curr
) = N_Compilation_Unit
then
5419 return Level_Of
(Unit
(Curr
));
5423 Curr
:= Parent
(Prev
);
5427 end Find_Enclosing_Level
;
5433 function Find_Top_Unit
(N
: Node_Or_Entity_Id
) return Entity_Id
is
5435 return Find_Unit_Entity
(Unit
(Cunit
(Get_Top_Level_Code_Unit
(N
))));
5438 ----------------------
5439 -- Find_Unit_Entity --
5440 ----------------------
5442 function Find_Unit_Entity
(N
: Node_Id
) return Entity_Id
is
5443 Context
: constant Node_Id
:= Parent
(N
);
5444 Orig_N
: constant Node_Id
:= Original_Node
(N
);
5447 -- The unit denotes a package body of an instantiation which acts as
5448 -- a compilation unit. The proper entity is that of the package spec.
5450 if Nkind
(N
) = N_Package_Body
5451 and then Nkind
(Orig_N
) = N_Package_Instantiation
5452 and then Nkind
(Context
) = N_Compilation_Unit
5454 return Corresponding_Spec
(N
);
5456 -- The unit denotes an anonymous package created to wrap a subprogram
5457 -- instantiation which acts as a compilation unit. The proper entity is
5458 -- that of the "related instance".
5460 elsif Nkind
(N
) = N_Package_Declaration
5461 and then Nkind_In
(Orig_N
, N_Function_Instantiation
,
5462 N_Procedure_Instantiation
)
5463 and then Nkind
(Context
) = N_Compilation_Unit
5466 Related_Instance
(Defining_Entity
(N
, Concurrent_Subunit
=> True));
5468 -- Otherwise the proper entity is the defining entity
5471 return Defining_Entity
(N
, Concurrent_Subunit
=> True);
5473 end Find_Unit_Entity
;
5475 -----------------------
5476 -- First_Formal_Type --
5477 -----------------------
5479 function First_Formal_Type
(Subp_Id
: Entity_Id
) return Entity_Id
is
5480 Formal_Id
: constant Entity_Id
:= First_Formal
(Subp_Id
);
5484 if Present
(Formal_Id
) then
5485 Typ
:= Etype
(Formal_Id
);
5487 -- Handle various combinations of concurrent and private types
5490 if Ekind_In
(Typ
, E_Protected_Type
, E_Task_Type
)
5491 and then Present
(Anonymous_Object
(Typ
))
5493 Typ
:= Anonymous_Object
(Typ
);
5495 elsif Is_Concurrent_Record_Type
(Typ
) then
5496 Typ
:= Corresponding_Concurrent_Type
(Typ
);
5498 elsif Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
5499 Typ
:= Full_View
(Typ
);
5510 end First_Formal_Type
;
5516 function Has_Body
(Pack_Decl
: Node_Id
) return Boolean is
5517 function Find_Corresponding_Body
(Spec_Id
: Entity_Id
) return Node_Id
;
5518 -- Try to locate the corresponding body of spec Spec_Id. If no body is
5519 -- found, return Empty.
5522 (Spec_Id
: Entity_Id
;
5523 From
: Node_Id
) return Node_Id
;
5524 -- Try to locate the corresponding body of spec Spec_Id in the node list
5525 -- which follows arbitrary node From. If no body is found, return Empty.
5527 function Load_Package_Body
(Unit_Nam
: Unit_Name_Type
) return Node_Id
;
5528 -- Attempt to load the body of unit Unit_Nam. If the load failed, return
5529 -- Empty. If the compilation will not generate code, return Empty.
5531 -----------------------------
5532 -- Find_Corresponding_Body --
5533 -----------------------------
5535 function Find_Corresponding_Body
(Spec_Id
: Entity_Id
) return Node_Id
is
5536 Context
: constant Entity_Id
:= Scope
(Spec_Id
);
5537 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Spec_Id
);
5538 Body_Decl
: Node_Id
;
5539 Body_Id
: Entity_Id
;
5542 if Is_Compilation_Unit
(Spec_Id
) then
5543 Body_Id
:= Corresponding_Body
(Spec_Decl
);
5545 if Present
(Body_Id
) then
5546 return Unit_Declaration_Node
(Body_Id
);
5548 -- The package is at the library and requires a body. Load the
5549 -- corresponding body because the optional body may be declared
5552 elsif Unit_Requires_Body
(Spec_Id
) then
5555 (Get_Body_Name
(Unit_Name
(Get_Source_Unit
(Spec_Decl
))));
5557 -- Otherwise there is no optional body
5563 -- The immediate context is a package. The optional body may be
5564 -- within the body of that package.
5566 -- procedure Proc is
5567 -- package Nested_1 is
5568 -- package Nested_2 is
5575 -- package body Nested_1 is
5576 -- package body Nested_2 is separate;
5579 -- separate (Proc.Nested_1.Nested_2)
5580 -- package body Nested_2 is
5581 -- package body Pack is -- optional body
5586 elsif Is_Package_Or_Generic_Package
(Context
) then
5587 Body_Decl
:= Find_Corresponding_Body
(Context
);
5589 -- The optional body is within the body of the enclosing package
5591 if Present
(Body_Decl
) then
5594 (Spec_Id
=> Spec_Id
,
5595 From
=> First
(Declarations
(Body_Decl
)));
5597 -- Otherwise the enclosing package does not have a body. This may
5598 -- be the result of an error or a genuine lack of a body.
5604 -- Otherwise the immediate context is a body. The optional body may
5605 -- be within the same list as the spec.
5607 -- procedure Proc is
5612 -- package body Pack is -- optional body
5619 (Spec_Id
=> Spec_Id
,
5620 From
=> Next
(Spec_Decl
));
5622 end Find_Corresponding_Body
;
5629 (Spec_Id
: Entity_Id
;
5630 From
: Node_Id
) return Node_Id
5632 Spec_Nam
: constant Name_Id
:= Chars
(Spec_Id
);
5638 while Present
(Item
) loop
5640 -- The current item denotes the optional body
5642 if Nkind
(Item
) = N_Package_Body
5643 and then Chars
(Defining_Entity
(Item
)) = Spec_Nam
5647 -- The current item denotes a stub, the optional body may be in
5650 elsif Nkind
(Item
) = N_Package_Body_Stub
5651 and then Chars
(Defining_Entity
(Item
)) = Spec_Nam
5653 Lib_Unit
:= Library_Unit
(Item
);
5655 -- The corresponding subunit was previously loaded
5657 if Present
(Lib_Unit
) then
5660 -- Otherwise attempt to load the corresponding subunit
5663 return Load_Package_Body
(Get_Unit_Name
(Item
));
5673 -----------------------
5674 -- Load_Package_Body --
5675 -----------------------
5677 function Load_Package_Body
(Unit_Nam
: Unit_Name_Type
) return Node_Id
is
5678 Body_Decl
: Node_Id
;
5679 Unit_Num
: Unit_Number_Type
;
5682 -- The load is performed only when the compilation will generate code
5684 if Operating_Mode
= Generate_Code
then
5687 (Load_Name
=> Unit_Nam
,
5690 Error_Node
=> Pack_Decl
);
5692 -- The load failed most likely because the physical file is
5695 if Unit_Num
= No_Unit
then
5698 -- Otherwise the load was successful, return the body of the unit
5701 Body_Decl
:= Unit
(Cunit
(Unit_Num
));
5703 -- If the unit is a subunit with an available proper body,
5704 -- return the proper body.
5706 if Nkind
(Body_Decl
) = N_Subunit
5707 and then Present
(Proper_Body
(Body_Decl
))
5709 Body_Decl
:= Proper_Body
(Body_Decl
);
5717 end Load_Package_Body
;
5721 Pack_Id
: constant Entity_Id
:= Defining_Entity
(Pack_Decl
);
5723 -- Start of processing for Has_Body
5726 -- The body is available
5728 if Present
(Corresponding_Body
(Pack_Decl
)) then
5731 -- The body is required if the package spec contains a construct which
5732 -- requires a completion in a body.
5734 elsif Unit_Requires_Body
(Pack_Id
) then
5737 -- The body may be optional
5740 return Present
(Find_Corresponding_Body
(Pack_Id
));
5744 ---------------------------
5745 -- Has_Prior_Elaboration --
5746 ---------------------------
5748 function Has_Prior_Elaboration
5749 (Unit_Id
: Entity_Id
;
5750 Context_OK
: Boolean := False;
5751 Elab_Body_OK
: Boolean := False;
5752 Same_Unit_OK
: Boolean := False) return Boolean
5754 Main_Id
: constant Entity_Id
:= Cunit_Entity
(Main_Unit
);
5757 -- A preelaborated unit is always elaborated prior to the main unit
5759 if Is_Preelaborated_Unit
(Unit_Id
) then
5762 -- An internal unit is always elaborated prior to a non-internal main
5765 elsif In_Internal_Unit
(Unit_Id
)
5766 and then not In_Internal_Unit
(Main_Id
)
5770 -- A unit has prior elaboration if it appears within the context of the
5771 -- main unit. Consider this case only when requested by the caller.
5774 and then Elaboration_Status
(Unit_Id
) /= No_Elaboration_Attributes
5778 -- A unit whose body is elaborated together with its spec has prior
5779 -- elaboration except with respect to itself. Consider this case only
5780 -- when requested by the caller.
5783 and then Has_Pragma_Elaborate_Body
(Unit_Id
)
5784 and then not Is_Same_Unit
(Unit_Id
, Main_Id
)
5788 -- A unit has no prior elaboration with respect to itself, but does not
5789 -- require any means of ensuring its own elaboration either. Treat this
5790 -- case as valid prior elaboration only when requested by the caller.
5792 elsif Same_Unit_OK
and then Is_Same_Unit
(Unit_Id
, Main_Id
) then
5797 end Has_Prior_Elaboration
;
5799 --------------------------
5800 -- In_External_Instance --
5801 --------------------------
5803 function In_External_Instance
5805 Target_Decl
: Node_Id
) return Boolean
5808 Inst_Body
: Node_Id
;
5809 Inst_Decl
: Node_Id
;
5812 -- Performance note: parent traversal
5814 Inst_Decl
:= Find_Enclosing_Instance
(Target_Decl
);
5816 -- The target declaration appears within an instance spec. Visibility is
5817 -- ignored because internally generated primitives for private types may
5818 -- reside in the private declarations and still be invoked from outside.
5820 if Present
(Inst_Decl
)
5821 and then Nkind
(Inst_Decl
) = N_Package_Declaration
5823 -- The scenario comes from the main unit and the instance does not
5825 if In_Extended_Main_Code_Unit
(N
)
5826 and then not In_Extended_Main_Code_Unit
(Inst_Decl
)
5830 -- Otherwise the scenario must not appear within the instance spec or
5834 Extract_Instance_Attributes
5835 (Exp_Inst
=> Inst_Decl
,
5836 Inst_Body
=> Inst_Body
,
5837 Inst_Decl
=> Dummy
);
5839 -- Performance note: parent traversal
5841 return not In_Subtree
5844 Root2
=> Inst_Body
);
5849 end In_External_Instance
;
5851 ---------------------
5852 -- In_Main_Context --
5853 ---------------------
5855 function In_Main_Context
(N
: Node_Id
) return Boolean is
5857 -- Scenarios outside the main unit are not considered because the ALI
5858 -- information supplied to binde is for the main unit only.
5860 if not In_Extended_Main_Code_Unit
(N
) then
5863 -- Scenarios within internal units are not considered unless switch
5864 -- -gnatdE (elaboration checks on predefined units) is in effect.
5866 elsif not Debug_Flag_EE
and then In_Internal_Unit
(N
) then
5871 end In_Main_Context
;
5873 ---------------------
5874 -- In_Same_Context --
5875 ---------------------
5877 function In_Same_Context
5880 Nested_OK
: Boolean := False) return Boolean
5882 function Find_Enclosing_Context
(N
: Node_Id
) return Node_Id
;
5883 -- Return the nearest enclosing non-library-level or compilation unit
5884 -- node which which encapsulates arbitrary node N. Return Empty is no
5885 -- such context is available.
5887 function In_Nested_Context
5889 Inner
: Node_Id
) return Boolean;
5890 -- Determine whether arbitrary node Outer encapsulates arbitrary node
5893 ----------------------------
5894 -- Find_Enclosing_Context --
5895 ----------------------------
5897 function Find_Enclosing_Context
(N
: Node_Id
) return Node_Id
is
5903 while Present
(Par
) loop
5905 -- A traversal from a subunit continues via the corresponding stub
5907 if Nkind
(Par
) = N_Subunit
then
5908 Par
:= Corresponding_Stub
(Par
);
5910 -- Stop the traversal when the nearest enclosing non-library-level
5911 -- encapsulator has been reached.
5913 elsif Is_Non_Library_Level_Encapsulator
(Par
) then
5914 Context
:= Parent
(Par
);
5916 -- The sole exception is when the encapsulator is the unit of
5917 -- compilation because this case requires special processing
5920 if Present
(Context
)
5921 and then Nkind
(Context
) = N_Compilation_Unit
5929 -- Reaching a compilation unit node without hitting a non-library-
5930 -- level encapsulator indicates that N is at the library level in
5931 -- which case the compilation unit is the context.
5933 elsif Nkind
(Par
) = N_Compilation_Unit
then
5937 Par
:= Parent
(Par
);
5941 end Find_Enclosing_Context
;
5943 -----------------------
5944 -- In_Nested_Context --
5945 -----------------------
5947 function In_Nested_Context
5949 Inner
: Node_Id
) return Boolean
5955 while Present
(Par
) loop
5957 -- A traversal from a subunit continues via the corresponding stub
5959 if Nkind
(Par
) = N_Subunit
then
5960 Par
:= Corresponding_Stub
(Par
);
5962 elsif Par
= Outer
then
5966 Par
:= Parent
(Par
);
5970 end In_Nested_Context
;
5974 Context_1
: constant Node_Id
:= Find_Enclosing_Context
(N1
);
5975 Context_2
: constant Node_Id
:= Find_Enclosing_Context
(N2
);
5977 -- Start of processing for In_Same_Context
5980 -- Both nodes appear within the same context
5982 if Context_1
= Context_2
then
5985 -- Both nodes appear in compilation units. Determine whether one unit
5986 -- is the body of the other.
5988 elsif Nkind
(Context_1
) = N_Compilation_Unit
5989 and then Nkind
(Context_2
) = N_Compilation_Unit
5993 (Unit_1
=> Defining_Entity
(Unit
(Context_1
)),
5994 Unit_2
=> Defining_Entity
(Unit
(Context_2
)));
5996 -- The context of N1 encloses the context of N2
5998 elsif Nested_OK
and then In_Nested_Context
(Context_1
, Context_2
) then
6003 end In_Same_Context
;
6009 procedure Initialize
is
6011 -- Set the soft link which enables Atree.Rewrite to update a top-level
6012 -- scenario each time it is transformed into another node.
6014 Set_Rewriting_Proc
(Update_Elaboration_Scenario
'Access);
6023 Target_Id
: Entity_Id
;
6027 procedure Info_Accept_Alternative
;
6028 pragma Inline
(Info_Accept_Alternative
);
6029 -- Output information concerning an accept alternative
6031 procedure Info_Simple_Call
;
6032 pragma Inline
(Info_Simple_Call
);
6033 -- Output information concerning the call
6035 procedure Info_Type_Actions
(Action
: String);
6036 pragma Inline
(Info_Type_Actions
);
6037 -- Output information concerning action Action of a type
6039 procedure Info_Verification_Call
6043 pragma Inline
(Info_Verification_Call
);
6044 -- Output information concerning the verification of predicate Pred
6045 -- applied to related entity Id with kind Id_Kind.
6047 -----------------------------
6048 -- Info_Accept_Alternative --
6049 -----------------------------
6051 procedure Info_Accept_Alternative
is
6052 Entry_Id
: constant Entity_Id
:= Receiving_Entry
(Target_Id
);
6055 pragma Assert
(Present
(Entry_Id
));
6058 (Msg
=> "accept for entry & during elaboration",
6061 Info_Msg
=> Info_Msg
,
6062 In_SPARK
=> In_SPARK
);
6063 end Info_Accept_Alternative
;
6065 ----------------------
6066 -- Info_Simple_Call --
6067 ----------------------
6069 procedure Info_Simple_Call
is
6072 (Msg
=> "call to & during elaboration",
6075 Info_Msg
=> Info_Msg
,
6076 In_SPARK
=> In_SPARK
);
6077 end Info_Simple_Call
;
6079 -----------------------
6080 -- Info_Type_Actions --
6081 -----------------------
6083 procedure Info_Type_Actions
(Action
: String) is
6084 Typ
: constant Entity_Id
:= First_Formal_Type
(Target_Id
);
6087 pragma Assert
(Present
(Typ
));
6090 (Msg
=> Action
& " actions for type & during elaboration",
6093 Info_Msg
=> Info_Msg
,
6094 In_SPARK
=> In_SPARK
);
6095 end Info_Type_Actions
;
6097 ----------------------------
6098 -- Info_Verification_Call --
6099 ----------------------------
6101 procedure Info_Verification_Call
6107 pragma Assert
(Present
(Id
));
6111 "verification of " & Pred
& " of " & Id_Kind
& " & during "
6115 Info_Msg
=> Info_Msg
,
6116 In_SPARK
=> In_SPARK
);
6117 end Info_Verification_Call
;
6119 -- Start of processing for Info_Call
6122 -- Do not output anything for targets defined in internal units because
6123 -- this creates noise.
6125 if not In_Internal_Unit
(Target_Id
) then
6127 -- Accept alternative
6129 if Is_Accept_Alternative_Proc
(Target_Id
) then
6130 Info_Accept_Alternative
;
6134 elsif Is_TSS
(Target_Id
, TSS_Deep_Adjust
) then
6135 Info_Type_Actions
("adjustment");
6137 -- Default_Initial_Condition
6139 elsif Is_Default_Initial_Condition_Proc
(Target_Id
) then
6140 Info_Verification_Call
6141 (Pred
=> "Default_Initial_Condition",
6142 Id
=> First_Formal_Type
(Target_Id
),
6147 elsif Is_Protected_Entry
(Target_Id
) then
6150 -- Task entry calls are never processed because the entry being
6151 -- invoked does not have a corresponding "body", it has a select.
6153 elsif Is_Task_Entry
(Target_Id
) then
6158 elsif Is_TSS
(Target_Id
, TSS_Deep_Finalize
) then
6159 Info_Type_Actions
("finalization");
6161 -- Calls to _Finalizer procedures must not appear in the output
6162 -- because this creates confusing noise.
6164 elsif Is_Finalizer_Proc
(Target_Id
) then
6167 -- Initial_Condition
6169 elsif Is_Initial_Condition_Proc
(Target_Id
) then
6170 Info_Verification_Call
6171 (Pred
=> "Initial_Condition",
6172 Id
=> Find_Enclosing_Scope
(Call
),
6173 Id_Kind
=> "package");
6177 elsif Is_Init_Proc
(Target_Id
)
6178 or else Is_TSS
(Target_Id
, TSS_Deep_Initialize
)
6180 Info_Type_Actions
("initialization");
6184 elsif Is_Invariant_Proc
(Target_Id
) then
6185 Info_Verification_Call
6186 (Pred
=> "invariants",
6187 Id
=> First_Formal_Type
(Target_Id
),
6190 -- Partial invariant calls must not appear in the output because this
6191 -- creates confusing noise.
6193 elsif Is_Partial_Invariant_Proc
(Target_Id
) then
6198 elsif Is_Postconditions_Proc
(Target_Id
) then
6199 Info_Verification_Call
6200 (Pred
=> "postconditions",
6201 Id
=> Find_Enclosing_Scope
(Call
),
6202 Id_Kind
=> "subprogram");
6204 -- Subprograms must come last because some of the previous cases fall
6205 -- under this category.
6207 elsif Ekind
(Target_Id
) = E_Function
then
6210 elsif Ekind
(Target_Id
) = E_Procedure
then
6214 pragma Assert
(False);
6220 ------------------------
6221 -- Info_Instantiation --
6222 ------------------------
6224 procedure Info_Instantiation
6232 (Msg
=> "instantiation of & during elaboration",
6235 Info_Msg
=> Info_Msg
,
6236 In_SPARK
=> In_SPARK
);
6237 end Info_Instantiation
;
6239 -----------------------------
6240 -- Info_Variable_Reference --
6241 -----------------------------
6243 procedure Info_Variable_Reference
6250 if Is_Read
(Ref
) then
6252 (Msg
=> "read of variable & during elaboration",
6255 Info_Msg
=> Info_Msg
,
6256 In_SPARK
=> In_SPARK
);
6258 end Info_Variable_Reference
;
6260 --------------------
6261 -- Insertion_Node --
6262 --------------------
6264 function Insertion_Node
(N
: Node_Id
; Ins_Nod
: Node_Id
) return Node_Id
is
6266 -- When the scenario denotes an instantiation, the proper insertion node
6267 -- is the instance spec. This ensures that the generic actuals will not
6268 -- be evaluated prior to a potential ABE.
6270 if Nkind
(N
) in N_Generic_Instantiation
6271 and then Present
(Instance_Spec
(N
))
6273 return Instance_Spec
(N
);
6275 -- Otherwise the proper insertion node is the candidate insertion node
6282 -----------------------
6283 -- Install_ABE_Check --
6284 -----------------------
6286 procedure Install_ABE_Check
6291 Check_Ins_Nod
: constant Node_Id
:= Insertion_Node
(N
, Ins_Nod
);
6292 -- Insert the check prior to this node
6294 Loc
: constant Source_Ptr
:= Sloc
(N
);
6295 Spec_Id
: constant Entity_Id
:= Unique_Entity
(Id
);
6296 Unit_Id
: constant Entity_Id
:= Find_Top_Unit
(Id
);
6297 Scop_Id
: Entity_Id
;
6300 -- Nothing to do when compiling for GNATprove because raise statements
6301 -- are not supported.
6303 if GNATprove_Mode
then
6306 -- Nothing to do when the compilation will not produce an executable
6308 elsif Serious_Errors_Detected
> 0 then
6311 -- Nothing to do for a compilation unit because there is no executable
6312 -- environment at that level.
6314 elsif Nkind
(Parent
(Check_Ins_Nod
)) = N_Compilation_Unit
then
6317 -- Nothing to do when the unit is elaborated prior to the main unit.
6318 -- This check must also consider the following cases:
6320 -- * Id's unit appears in the context of the main unit
6322 -- * Id's unit is subject to pragma Elaborate_Body. An ABE check MUST
6323 -- NOT be generated because Id's unit is always elaborated prior to
6326 -- * Id's unit is the main unit. An ABE check MUST be generated in this
6327 -- case because a conditional ABE may be raised depending on the flow
6328 -- of execution within the main unit (flag Same_Unit_OK is False).
6330 elsif Has_Prior_Elaboration
6331 (Unit_Id
=> Unit_Id
,
6333 Elab_Body_OK
=> True)
6338 -- Prevent multiple scenarios from installing the same ABE check
6340 Set_Is_Elaboration_Checks_OK_Node
(N
, False);
6342 -- Install the nearest enclosing scope of the scenario as there must be
6343 -- something on the scope stack.
6345 -- Performance note: parent traversal
6347 Scop_Id
:= Find_Enclosing_Scope
(Check_Ins_Nod
);
6348 pragma Assert
(Present
(Scop_Id
));
6350 Push_Scope
(Scop_Id
);
6353 -- if not Spec_Id'Elaborated then
6354 -- raise Program_Error with "access before elaboration";
6357 Insert_Action
(Check_Ins_Nod
,
6358 Make_Raise_Program_Error
(Loc
,
6362 Make_Attribute_Reference
(Loc
,
6363 Prefix
=> New_Occurrence_Of
(Spec_Id
, Loc
),
6364 Attribute_Name
=> Name_Elaborated
)),
6365 Reason
=> PE_Access_Before_Elaboration
));
6368 end Install_ABE_Check
;
6370 -----------------------
6371 -- Install_ABE_Check --
6372 -----------------------
6374 procedure Install_ABE_Check
6376 Target_Id
: Entity_Id
;
6377 Target_Decl
: Node_Id
;
6378 Target_Body
: Node_Id
;
6381 procedure Build_Elaboration_Entity
;
6382 pragma Inline
(Build_Elaboration_Entity
);
6383 -- Create a new elaboration flag for Target_Id, insert it prior to
6384 -- Target_Decl, and set it after Body_Decl.
6386 ------------------------------
6387 -- Build_Elaboration_Entity --
6388 ------------------------------
6390 procedure Build_Elaboration_Entity
is
6391 Loc
: constant Source_Ptr
:= Sloc
(Target_Id
);
6392 Flag_Id
: Entity_Id
;
6395 -- Create the declaration of the elaboration flag. The name carries a
6396 -- unique counter in case of name overloading.
6399 Make_Defining_Identifier
(Loc
,
6400 Chars
=> New_External_Name
(Chars
(Target_Id
), 'E', -1));
6402 Set_Elaboration_Entity
(Target_Id
, Flag_Id
);
6403 Set_Elaboration_Entity_Required
(Target_Id
);
6405 Push_Scope
(Scope
(Target_Id
));
6408 -- Enn : Short_Integer := 0;
6410 Insert_Action
(Target_Decl
,
6411 Make_Object_Declaration
(Loc
,
6412 Defining_Identifier
=> Flag_Id
,
6413 Object_Definition
=>
6414 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
6415 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
)));
6420 Set_Elaboration_Flag
(Target_Body
, Target_Id
);
6423 end Build_Elaboration_Entity
;
6427 Target_Unit_Id
: constant Entity_Id
:= Find_Top_Unit
(Target_Id
);
6429 -- Start for processing for Install_ABE_Check
6432 -- Nothing to do when compiling for GNATprove because raise statements
6433 -- are not supported.
6435 if GNATprove_Mode
then
6438 -- Nothing to do when the compilation will not produce an executable
6440 elsif Serious_Errors_Detected
> 0 then
6443 -- Nothing to do when the target is a protected subprogram because the
6444 -- check is associated with the protected body subprogram.
6446 elsif Is_Protected_Subp
(Target_Id
) then
6449 -- Nothing to do when the target is elaborated prior to the main unit.
6450 -- This check must also consider the following cases:
6452 -- * The unit of the target appears in the context of the main unit
6454 -- * The unit of the target is subject to pragma Elaborate_Body. An ABE
6455 -- check MUST NOT be generated because the unit is always elaborated
6456 -- prior to the main unit.
6458 -- * The unit of the target is the main unit. An ABE check MUST be added
6459 -- in this case because a conditional ABE may be raised depending on
6460 -- the flow of execution within the main unit (flag Same_Unit_OK is
6463 elsif Has_Prior_Elaboration
6464 (Unit_Id
=> Target_Unit_Id
,
6466 Elab_Body_OK
=> True)
6470 -- Create an elaboration flag for the target when it does not have one
6472 elsif No
(Elaboration_Entity
(Target_Id
)) then
6473 Build_Elaboration_Entity
;
6480 end Install_ABE_Check
;
6482 -------------------------
6483 -- Install_ABE_Failure --
6484 -------------------------
6486 procedure Install_ABE_Failure
(N
: Node_Id
; Ins_Nod
: Node_Id
) is
6487 Fail_Ins_Nod
: constant Node_Id
:= Insertion_Node
(N
, Ins_Nod
);
6488 -- Insert the failure prior to this node
6490 Loc
: constant Source_Ptr
:= Sloc
(N
);
6491 Scop_Id
: Entity_Id
;
6494 -- Nothing to do when compiling for GNATprove because raise statements
6495 -- are not supported.
6497 if GNATprove_Mode
then
6500 -- Nothing to do when the compilation will not produce an executable
6502 elsif Serious_Errors_Detected
> 0 then
6505 -- Do not install an ABE check for a compilation unit because there is
6506 -- no executable environment at that level.
6508 elsif Nkind
(Parent
(Fail_Ins_Nod
)) = N_Compilation_Unit
then
6512 -- Prevent multiple scenarios from installing the same ABE failure
6514 Set_Is_Elaboration_Checks_OK_Node
(N
, False);
6516 -- Install the nearest enclosing scope of the scenario as there must be
6517 -- something on the scope stack.
6519 -- Performance note: parent traversal
6521 Scop_Id
:= Find_Enclosing_Scope
(Fail_Ins_Nod
);
6522 pragma Assert
(Present
(Scop_Id
));
6524 Push_Scope
(Scop_Id
);
6527 -- raise Program_Error with "access before elaboration";
6529 Insert_Action
(Fail_Ins_Nod
,
6530 Make_Raise_Program_Error
(Loc
,
6531 Reason
=> PE_Access_Before_Elaboration
));
6534 end Install_ABE_Failure
;
6536 --------------------------------
6537 -- Is_Accept_Alternative_Proc --
6538 --------------------------------
6540 function Is_Accept_Alternative_Proc
(Id
: Entity_Id
) return Boolean is
6542 -- To qualify, the entity must denote a procedure with a receiving entry
6544 return Ekind
(Id
) = E_Procedure
and then Present
(Receiving_Entry
(Id
));
6545 end Is_Accept_Alternative_Proc
;
6547 ------------------------
6548 -- Is_Activation_Proc --
6549 ------------------------
6551 function Is_Activation_Proc
(Id
: Entity_Id
) return Boolean is
6553 -- To qualify, the entity must denote one of the runtime procedures in
6554 -- charge of task activation.
6556 if Ekind
(Id
) = E_Procedure
then
6557 if Restricted_Profile
then
6558 return Is_RTE
(Id
, RE_Activate_Restricted_Tasks
);
6560 return Is_RTE
(Id
, RE_Activate_Tasks
);
6565 end Is_Activation_Proc
;
6567 ----------------------------
6568 -- Is_Ada_Semantic_Target --
6569 ----------------------------
6571 function Is_Ada_Semantic_Target
(Id
: Entity_Id
) return Boolean is
6574 Is_Activation_Proc
(Id
)
6575 or else Is_Controlled_Proc
(Id
, Name_Adjust
)
6576 or else Is_Controlled_Proc
(Id
, Name_Finalize
)
6577 or else Is_Controlled_Proc
(Id
, Name_Initialize
)
6578 or else Is_Init_Proc
(Id
)
6579 or else Is_Invariant_Proc
(Id
)
6580 or else Is_Protected_Entry
(Id
)
6581 or else Is_Protected_Subp
(Id
)
6582 or else Is_Protected_Body_Subp
(Id
)
6583 or else Is_Task_Entry
(Id
);
6584 end Is_Ada_Semantic_Target
;
6586 --------------------------------
6587 -- Is_Assertion_Pragma_Target --
6588 --------------------------------
6590 function Is_Assertion_Pragma_Target
(Id
: Entity_Id
) return Boolean is
6593 Is_Default_Initial_Condition_Proc
(Id
)
6594 or else Is_Initial_Condition_Proc
(Id
)
6595 or else Is_Invariant_Proc
(Id
)
6596 or else Is_Partial_Invariant_Proc
(Id
)
6597 or else Is_Postconditions_Proc
(Id
);
6598 end Is_Assertion_Pragma_Target
;
6600 ----------------------------
6601 -- Is_Bodiless_Subprogram --
6602 ----------------------------
6604 function Is_Bodiless_Subprogram
(Subp_Id
: Entity_Id
) return Boolean is
6606 -- An abstract subprogram does not have a body
6608 if Ekind_In
(Subp_Id
, E_Function
,
6611 and then Is_Abstract_Subprogram
(Subp_Id
)
6615 -- A formal subprogram does not have a body
6617 elsif Is_Formal_Subprogram
(Subp_Id
) then
6620 -- An imported subprogram may have a body, however it is not known at
6621 -- compile or bind time where the body resides and whether it will be
6622 -- elaborated on time.
6624 elsif Is_Imported
(Subp_Id
) then
6629 end Is_Bodiless_Subprogram
;
6631 ------------------------
6632 -- Is_Controlled_Proc --
6633 ------------------------
6635 function Is_Controlled_Proc
6636 (Subp_Id
: Entity_Id
;
6637 Subp_Nam
: Name_Id
) return Boolean
6639 Formal_Id
: Entity_Id
;
6642 pragma Assert
(Nam_In
(Subp_Nam
, Name_Adjust
,
6646 -- To qualify, the subprogram must denote a source procedure with name
6647 -- Adjust, Finalize, or Initialize where the sole formal is controlled.
6649 if Comes_From_Source
(Subp_Id
)
6650 and then Ekind
(Subp_Id
) = E_Procedure
6651 and then Chars
(Subp_Id
) = Subp_Nam
6653 Formal_Id
:= First_Formal
(Subp_Id
);
6657 and then Is_Controlled
(Etype
(Formal_Id
))
6658 and then No
(Next_Formal
(Formal_Id
));
6662 end Is_Controlled_Proc
;
6664 ---------------------------------------
6665 -- Is_Default_Initial_Condition_Proc --
6666 ---------------------------------------
6668 function Is_Default_Initial_Condition_Proc
6669 (Id
: Entity_Id
) return Boolean
6672 -- To qualify, the entity must denote a Default_Initial_Condition
6675 return Ekind
(Id
) = E_Procedure
and then Is_DIC_Procedure
(Id
);
6676 end Is_Default_Initial_Condition_Proc
;
6678 -----------------------
6679 -- Is_Finalizer_Proc --
6680 -----------------------
6682 function Is_Finalizer_Proc
(Id
: Entity_Id
) return Boolean is
6684 -- To qualify, the entity must denote a _Finalizer procedure
6686 return Ekind
(Id
) = E_Procedure
and then Chars
(Id
) = Name_uFinalizer
;
6687 end Is_Finalizer_Proc
;
6689 -----------------------
6690 -- Is_Guaranteed_ABE --
6691 -----------------------
6693 function Is_Guaranteed_ABE
6695 Target_Decl
: Node_Id
;
6696 Target_Body
: Node_Id
) return Boolean
6699 -- Avoid cascaded errors if there were previous serious infractions.
6700 -- As a result the scenario will not be treated as a guaranteed ABE.
6701 -- This behaviour parallels that of the old ABE mechanism.
6703 if Serious_Errors_Detected
> 0 then
6706 -- The scenario and the target appear within the same context ignoring
6707 -- enclosing library levels.
6709 -- Performance note: parent traversal
6711 elsif In_Same_Context
(N
, Target_Decl
) then
6713 -- The target body has already been encountered. The scenario results
6714 -- in a guaranteed ABE if it appears prior to the body.
6716 if Present
(Target_Body
) then
6717 return Earlier_In_Extended_Unit
(N
, Target_Body
);
6719 -- Otherwise the body has not been encountered yet. The scenario is
6720 -- a guaranteed ABE since the body will appear later. It is assumed
6721 -- that the caller has already checked whether the scenario is ABE-
6722 -- safe as optional bodies are not considered here.
6730 end Is_Guaranteed_ABE
;
6732 -------------------------------
6733 -- Is_Initial_Condition_Proc --
6734 -------------------------------
6736 function Is_Initial_Condition_Proc
(Id
: Entity_Id
) return Boolean is
6738 -- To qualify, the entity must denote an Initial_Condition procedure
6741 Ekind
(Id
) = E_Procedure
and then Is_Initial_Condition_Procedure
(Id
);
6742 end Is_Initial_Condition_Proc
;
6744 --------------------
6745 -- Is_Initialized --
6746 --------------------
6748 function Is_Initialized
(Obj_Decl
: Node_Id
) return Boolean is
6750 -- To qualify, the object declaration must have an expression
6753 Present
(Expression
(Obj_Decl
)) or else Has_Init_Expression
(Obj_Decl
);
6756 -----------------------
6757 -- Is_Invariant_Proc --
6758 -----------------------
6760 function Is_Invariant_Proc
(Id
: Entity_Id
) return Boolean is
6762 -- To qualify, the entity must denote the "full" invariant procedure
6764 return Ekind
(Id
) = E_Procedure
and then Is_Invariant_Procedure
(Id
);
6765 end Is_Invariant_Proc
;
6767 ---------------------------------------
6768 -- Is_Non_Library_Level_Encapsulator --
6769 ---------------------------------------
6771 function Is_Non_Library_Level_Encapsulator
(N
: Node_Id
) return Boolean is
6774 when N_Abstract_Subprogram_Declaration
6775 | N_Aspect_Specification
6776 | N_Component_Declaration
6778 | N_Entry_Declaration
6779 | N_Expression_Function
6780 | N_Formal_Abstract_Subprogram_Declaration
6781 | N_Formal_Concrete_Subprogram_Declaration
6782 | N_Formal_Object_Declaration
6783 | N_Formal_Package_Declaration
6784 | N_Formal_Type_Declaration
6785 | N_Generic_Association
6786 | N_Implicit_Label_Declaration
6787 | N_Incomplete_Type_Declaration
6788 | N_Private_Extension_Declaration
6789 | N_Private_Type_Declaration
6791 | N_Protected_Type_Declaration
6792 | N_Single_Protected_Declaration
6793 | N_Single_Task_Declaration
6795 | N_Subprogram_Declaration
6797 | N_Task_Type_Declaration
6802 return Is_Generic_Declaration_Or_Body
(N
);
6804 end Is_Non_Library_Level_Encapsulator
;
6806 -------------------------------
6807 -- Is_Partial_Invariant_Proc --
6808 -------------------------------
6810 function Is_Partial_Invariant_Proc
(Id
: Entity_Id
) return Boolean is
6812 -- To qualify, the entity must denote the "partial" invariant procedure
6815 Ekind
(Id
) = E_Procedure
and then Is_Partial_Invariant_Procedure
(Id
);
6816 end Is_Partial_Invariant_Proc
;
6818 ----------------------------
6819 -- Is_Postconditions_Proc --
6820 ----------------------------
6822 function Is_Postconditions_Proc
(Id
: Entity_Id
) return Boolean is
6824 -- To qualify, the entity must denote a _Postconditions procedure
6827 Ekind
(Id
) = E_Procedure
and then Chars
(Id
) = Name_uPostconditions
;
6828 end Is_Postconditions_Proc
;
6830 ---------------------------
6831 -- Is_Preelaborated_Unit --
6832 ---------------------------
6834 function Is_Preelaborated_Unit
(Id
: Entity_Id
) return Boolean is
6837 Is_Preelaborated
(Id
)
6838 or else Is_Pure
(Id
)
6839 or else Is_Remote_Call_Interface
(Id
)
6840 or else Is_Remote_Types
(Id
)
6841 or else Is_Shared_Passive
(Id
);
6842 end Is_Preelaborated_Unit
;
6844 ------------------------
6845 -- Is_Protected_Entry --
6846 ------------------------
6848 function Is_Protected_Entry
(Id
: Entity_Id
) return Boolean is
6850 -- To qualify, the entity must denote an entry defined in a protected
6855 and then Is_Protected_Type
(Non_Private_View
(Scope
(Id
)));
6856 end Is_Protected_Entry
;
6858 -----------------------
6859 -- Is_Protected_Subp --
6860 -----------------------
6862 function Is_Protected_Subp
(Id
: Entity_Id
) return Boolean is
6864 -- To qualify, the entity must denote a subprogram defined within a
6868 Ekind_In
(Id
, E_Function
, E_Procedure
)
6869 and then Is_Protected_Type
(Non_Private_View
(Scope
(Id
)));
6870 end Is_Protected_Subp
;
6872 ----------------------------
6873 -- Is_Protected_Body_Subp --
6874 ----------------------------
6876 function Is_Protected_Body_Subp
(Id
: Entity_Id
) return Boolean is
6878 -- To qualify, the entity must denote a subprogram with attribute
6879 -- Protected_Subprogram set.
6882 Ekind_In
(Id
, E_Function
, E_Procedure
)
6883 and then Present
(Protected_Subprogram
(Id
));
6884 end Is_Protected_Body_Subp
;
6886 --------------------------------
6887 -- Is_Recorded_SPARK_Scenario --
6888 --------------------------------
6890 function Is_Recorded_SPARK_Scenario
(N
: Node_Id
) return Boolean is
6892 if Recorded_SPARK_Scenarios_In_Use
then
6893 return Recorded_SPARK_Scenarios
.Get
(N
);
6896 return Recorded_SPARK_Scenarios_No_Element
;
6897 end Is_Recorded_SPARK_Scenario
;
6899 ------------------------------------
6900 -- Is_Recorded_Top_Level_Scenario --
6901 ------------------------------------
6903 function Is_Recorded_Top_Level_Scenario
(N
: Node_Id
) return Boolean is
6905 if Recorded_Top_Level_Scenarios_In_Use
then
6906 return Recorded_Top_Level_Scenarios
.Get
(N
);
6909 return Recorded_Top_Level_Scenarios_No_Element
;
6910 end Is_Recorded_Top_Level_Scenario
;
6912 ------------------------
6913 -- Is_Safe_Activation --
6914 ------------------------
6916 function Is_Safe_Activation
6918 Task_Decl
: Node_Id
) return Boolean
6921 -- The activation of a task coming from an external instance cannot
6922 -- cause an ABE because the generic was already instantiated. Note
6923 -- that the instantiation itself may lead to an ABE.
6926 In_External_Instance
6928 Target_Decl
=> Task_Decl
);
6929 end Is_Safe_Activation
;
6935 function Is_Safe_Call
6937 Target_Attrs
: Target_Attributes
) return Boolean
6940 -- The target is either an abstract subprogram, formal subprogram, or
6941 -- imported, in which case it does not have a body at compile or bind
6942 -- time. Assume that the call is ABE-safe.
6944 if Is_Bodiless_Subprogram
(Target_Attrs
.Spec_Id
) then
6947 -- The target is an instantiation of a generic subprogram. The call
6948 -- cannot cause an ABE because the generic was already instantiated.
6949 -- Note that the instantiation itself may lead to an ABE.
6951 elsif Is_Generic_Instance
(Target_Attrs
.Spec_Id
) then
6954 -- The invocation of a target coming from an external instance cannot
6955 -- cause an ABE because the generic was already instantiated. Note that
6956 -- the instantiation itself may lead to an ABE.
6958 elsif In_External_Instance
6960 Target_Decl
=> Target_Attrs
.Spec_Decl
)
6964 -- The target is a subprogram body without a previous declaration. The
6965 -- call cannot cause an ABE because the body has already been seen.
6967 elsif Nkind
(Target_Attrs
.Spec_Decl
) = N_Subprogram_Body
6968 and then No
(Corresponding_Spec
(Target_Attrs
.Spec_Decl
))
6972 -- The target is a subprogram body stub without a prior declaration.
6973 -- The call cannot cause an ABE because the proper body substitutes
6976 elsif Nkind
(Target_Attrs
.Spec_Decl
) = N_Subprogram_Body_Stub
6977 and then No
(Corresponding_Spec_Of_Stub
(Target_Attrs
.Spec_Decl
))
6981 -- Subprogram bodies which wrap attribute references used as actuals
6982 -- in instantiations are always ABE-safe. These bodies are artifacts
6985 elsif Present
(Target_Attrs
.Body_Decl
)
6986 and then Nkind
(Target_Attrs
.Body_Decl
) = N_Subprogram_Body
6987 and then Was_Attribute_Reference
(Target_Attrs
.Body_Decl
)
6995 ---------------------------
6996 -- Is_Safe_Instantiation --
6997 ---------------------------
6999 function Is_Safe_Instantiation
7001 Gen_Attrs
: Target_Attributes
) return Boolean
7004 -- The generic is an intrinsic subprogram in which case it does not
7005 -- have a body at compile or bind time. Assume that the instantiation
7008 if Is_Bodiless_Subprogram
(Gen_Attrs
.Spec_Id
) then
7011 -- The instantiation of an external nested generic cannot cause an ABE
7012 -- if the outer generic was already instantiated. Note that the instance
7013 -- of the outer generic may lead to an ABE.
7015 elsif In_External_Instance
7017 Target_Decl
=> Gen_Attrs
.Spec_Decl
)
7021 -- The generic is a package. The instantiation cannot cause an ABE when
7022 -- the package has no body.
7024 elsif Ekind
(Gen_Attrs
.Spec_Id
) = E_Generic_Package
7025 and then not Has_Body
(Gen_Attrs
.Spec_Decl
)
7031 end Is_Safe_Instantiation
;
7037 function Is_Same_Unit
7038 (Unit_1
: Entity_Id
;
7039 Unit_2
: Entity_Id
) return Boolean
7041 function Is_Subunit
(Unit_Id
: Entity_Id
) return Boolean;
7042 pragma Inline
(Is_Subunit
);
7043 -- Determine whether unit Unit_Id is a subunit
7045 function Normalize_Unit
(Unit_Id
: Entity_Id
) return Entity_Id
;
7046 -- Strip a potential subunit chain ending with unit Unit_Id and return
7047 -- the corresponding spec.
7053 function Is_Subunit
(Unit_Id
: Entity_Id
) return Boolean is
7055 return Nkind
(Parent
(Unit_Declaration_Node
(Unit_Id
))) = N_Subunit
;
7058 --------------------
7059 -- Normalize_Unit --
7060 --------------------
7062 function Normalize_Unit
(Unit_Id
: Entity_Id
) return Entity_Id
is
7066 -- Eliminate a potential chain of subunits to reach to proper body
7069 while Present
(Result
)
7070 and then Result
/= Standard_Standard
7071 and then Is_Subunit
(Result
)
7073 Result
:= Scope
(Result
);
7076 -- Obtain the entity of the corresponding spec (if any)
7078 return Unique_Entity
(Result
);
7081 -- Start of processing for Is_Same_Unit
7084 return Normalize_Unit
(Unit_1
) = Normalize_Unit
(Unit_2
);
7091 function Is_Scenario
(N
: Node_Id
) return Boolean is
7094 when N_Assignment_Statement
7095 | N_Attribute_Reference
7097 | N_Entry_Call_Statement
7100 | N_Function_Instantiation
7102 | N_Package_Instantiation
7103 | N_Procedure_Call_Statement
7104 | N_Procedure_Instantiation
7105 | N_Requeue_Statement
7114 ------------------------------
7115 -- Is_SPARK_Semantic_Target --
7116 ------------------------------
7118 function Is_SPARK_Semantic_Target
(Id
: Entity_Id
) return Boolean is
7121 Is_Default_Initial_Condition_Proc
(Id
)
7122 or else Is_Initial_Condition_Proc
(Id
);
7123 end Is_SPARK_Semantic_Target
;
7125 ------------------------
7126 -- Is_Suitable_Access --
7127 ------------------------
7129 function Is_Suitable_Access
(N
: Node_Id
) return Boolean is
7132 Subp_Id
: Entity_Id
;
7135 -- This scenario is relevant only when the static model is in effect
7136 -- because it is graph-dependent and does not involve any run-time
7137 -- checks. Allowing it in the dynamic model would create confusing
7140 if not Static_Elaboration_Checks
then
7143 -- Nothing to do when switch -gnatd.U (ignore 'Access) is in effect
7145 elsif Debug_Flag_Dot_UU
then
7148 -- Nothing to do when the scenario is not an attribute reference
7150 elsif Nkind
(N
) /= N_Attribute_Reference
then
7153 -- Nothing to do for internally-generated attributes because they are
7154 -- assumed to be ABE safe.
7156 elsif not Comes_From_Source
(N
) then
7160 Nam
:= Attribute_Name
(N
);
7163 -- Sanitize the prefix of the attribute
7165 if not Is_Entity_Name
(Pref
) then
7168 elsif No
(Entity
(Pref
)) then
7172 Subp_Id
:= Entity
(Pref
);
7174 if not Is_Subprogram_Or_Entry
(Subp_Id
) then
7178 -- Traverse a possible chain of renamings to obtain the original entry
7179 -- or subprogram which the prefix may rename.
7181 Subp_Id
:= Get_Renamed_Entity
(Subp_Id
);
7183 -- To qualify, the attribute must meet the following prerequisites:
7187 -- The prefix must denote a source entry, operator, or subprogram
7188 -- which is not imported.
7190 Comes_From_Source
(Subp_Id
)
7191 and then Is_Subprogram_Or_Entry
(Subp_Id
)
7192 and then not Is_Bodiless_Subprogram
(Subp_Id
)
7194 -- The attribute name must be one of the 'Access forms. Note that
7195 -- 'Unchecked_Access cannot apply to a subprogram.
7197 and then Nam_In
(Nam
, Name_Access
, Name_Unrestricted_Access
);
7198 end Is_Suitable_Access
;
7200 ----------------------
7201 -- Is_Suitable_Call --
7202 ----------------------
7204 function Is_Suitable_Call
(N
: Node_Id
) return Boolean is
7206 -- Entry and subprogram calls are intentionally ignored because they
7207 -- may undergo expansion depending on the compilation mode, previous
7208 -- errors, generic context, etc. Call markers play the role of calls
7209 -- and provide a uniform foundation for ABE processing.
7211 return Nkind
(N
) = N_Call_Marker
;
7212 end Is_Suitable_Call
;
7214 -------------------------------
7215 -- Is_Suitable_Instantiation --
7216 -------------------------------
7218 function Is_Suitable_Instantiation
(N
: Node_Id
) return Boolean is
7219 Orig_N
: constant Node_Id
:= Original_Node
(N
);
7220 -- Use the original node in case an instantiation library unit is
7221 -- rewritten as a package or subprogram.
7224 -- To qualify, the instantiation must come from source
7227 Comes_From_Source
(Orig_N
)
7228 and then Nkind
(Orig_N
) in N_Generic_Instantiation
;
7229 end Is_Suitable_Instantiation
;
7231 --------------------------
7232 -- Is_Suitable_Scenario --
7233 --------------------------
7235 function Is_Suitable_Scenario
(N
: Node_Id
) return Boolean is
7237 -- NOTE: Derived types and pragma Refined_State are intentionally left
7238 -- out because they are not executable during elaboration.
7241 Is_Suitable_Access
(N
)
7242 or else Is_Suitable_Call
(N
)
7243 or else Is_Suitable_Instantiation
(N
)
7244 or else Is_Suitable_Variable_Assignment
(N
)
7245 or else Is_Suitable_Variable_Reference
(N
);
7246 end Is_Suitable_Scenario
;
7248 ------------------------------------
7249 -- Is_Suitable_SPARK_Derived_Type --
7250 ------------------------------------
7252 function Is_Suitable_SPARK_Derived_Type
(N
: Node_Id
) return Boolean is
7257 -- To qualify, the type declaration must denote a derived tagged type
7258 -- with primitive operations, subject to pragma SPARK_Mode On.
7260 if Nkind
(N
) = N_Full_Type_Declaration
7261 and then Nkind
(Type_Definition
(N
)) = N_Derived_Type_Definition
7263 Typ
:= Defining_Entity
(N
);
7264 Prag
:= SPARK_Pragma
(Typ
);
7267 Is_Tagged_Type
(Typ
)
7268 and then Has_Primitive_Operations
(Typ
)
7269 and then Present
(Prag
)
7270 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
;
7274 end Is_Suitable_SPARK_Derived_Type
;
7276 -------------------------------------
7277 -- Is_Suitable_SPARK_Instantiation --
7278 -------------------------------------
7280 function Is_Suitable_SPARK_Instantiation
(N
: Node_Id
) return Boolean is
7281 Gen_Attrs
: Target_Attributes
;
7284 Inst_Attrs
: Instantiation_Attributes
;
7285 Inst_Id
: Entity_Id
;
7288 -- To qualify, both the instantiation and the generic must be subject to
7291 if Is_Suitable_Instantiation
(N
) then
7292 Extract_Instantiation_Attributes
7297 Attrs
=> Inst_Attrs
);
7299 Extract_Target_Attributes
(Gen_Id
, Gen_Attrs
);
7301 return Inst_Attrs
.SPARK_Mode_On
and Gen_Attrs
.SPARK_Mode_On
;
7305 end Is_Suitable_SPARK_Instantiation
;
7307 --------------------------------------------
7308 -- Is_Suitable_SPARK_Refined_State_Pragma --
7309 --------------------------------------------
7311 function Is_Suitable_SPARK_Refined_State_Pragma
7312 (N
: Node_Id
) return Boolean
7315 -- To qualfy, the pragma must denote Refined_State
7318 Nkind
(N
) = N_Pragma
7319 and then Pragma_Name
(N
) = Name_Refined_State
;
7320 end Is_Suitable_SPARK_Refined_State_Pragma
;
7322 -------------------------------------
7323 -- Is_Suitable_Variable_Assignment --
7324 -------------------------------------
7326 function Is_Suitable_Variable_Assignment
(N
: Node_Id
) return Boolean is
7328 N_Unit_Id
: Entity_Id
;
7333 Var_Unit_Id
: Entity_Id
;
7336 -- This scenario is relevant only when the static model is in effect
7337 -- because it is graph-dependent and does not involve any run-time
7338 -- checks. Allowing it in the dynamic model would create confusing
7341 if not Static_Elaboration_Checks
then
7344 -- Nothing to do when the scenario is not an assignment
7346 elsif Nkind
(N
) /= N_Assignment_Statement
then
7349 -- Nothing to do for internally-generated assignments because they are
7350 -- assumed to be ABE safe.
7352 elsif not Comes_From_Source
(N
) then
7355 -- Assignments are ignored in GNAT mode on the assumption that they are
7356 -- ABE-safe. This behaviour parallels that of the old ABE mechanism.
7358 elsif GNAT_Mode
then
7362 Nam
:= Extract_Assignment_Name
(N
);
7364 -- Sanitize the left hand side of the assignment
7366 if not Is_Entity_Name
(Nam
) then
7369 elsif No
(Entity
(Nam
)) then
7373 Var_Id
:= Entity
(Nam
);
7375 -- Sanitize the variable
7377 if Var_Id
= Any_Id
then
7380 elsif Ekind
(Var_Id
) /= E_Variable
then
7384 Var_Decl
:= Declaration_Node
(Var_Id
);
7386 if Nkind
(Var_Decl
) /= N_Object_Declaration
then
7390 N_Unit_Id
:= Find_Top_Unit
(N
);
7391 N_Unit
:= Unit_Declaration_Node
(N_Unit_Id
);
7393 Var_Unit_Id
:= Find_Top_Unit
(Var_Decl
);
7394 Var_Unit
:= Unit_Declaration_Node
(Var_Unit_Id
);
7396 -- To qualify, the assignment must meet the following prerequisites:
7399 Comes_From_Source
(Var_Id
)
7401 -- The variable must be declared in the spec of compilation unit U
7403 and then Nkind
(Var_Unit
) = N_Package_Declaration
7405 -- Performance note: parent traversal
7407 and then Find_Enclosing_Level
(Var_Decl
) = Package_Spec
7409 -- The assignment must occur in the body of compilation unit U
7411 and then Nkind
(N_Unit
) = N_Package_Body
7412 and then Present
(Corresponding_Body
(Var_Unit
))
7413 and then Corresponding_Body
(Var_Unit
) = N_Unit_Id
;
7414 end Is_Suitable_Variable_Assignment
;
7416 ------------------------------------
7417 -- Is_Suitable_Variable_Reference --
7418 ------------------------------------
7420 function Is_Suitable_Variable_Reference
(N
: Node_Id
) return Boolean is
7422 -- Expanded names and identifiers are intentionally ignored because they
7423 -- be folded, optimized away, etc. Variable references markers play the
7424 -- role of variable references and provide a uniform foundation for ABE
7427 return Nkind
(N
) = N_Variable_Reference_Marker
;
7428 end Is_Suitable_Variable_Reference
;
7434 function Is_Task_Entry
(Id
: Entity_Id
) return Boolean is
7436 -- To qualify, the entity must denote an entry defined in a task type
7439 Is_Entry
(Id
) and then Is_Task_Type
(Non_Private_View
(Scope
(Id
)));
7442 ------------------------
7443 -- Is_Up_Level_Target --
7444 ------------------------
7446 function Is_Up_Level_Target
(Target_Decl
: Node_Id
) return Boolean is
7447 Root
: constant Node_Id
:= Root_Scenario
;
7450 -- The root appears within the declaratons of a block statement, entry
7451 -- body, subprogram body, or task body ignoring enclosing packages. The
7452 -- root is always within the main unit. An up-level target is a notion
7453 -- applicable only to the static model because scenarios are reached by
7454 -- means of graph traversal started from a fixed declarative or library
7457 -- Performance note: parent traversal
7459 if Static_Elaboration_Checks
7460 and then Find_Enclosing_Level
(Root
) = Declaration_Level
7462 -- The target is within the main unit. It acts as an up-level target
7463 -- when it appears within a context which encloses the root.
7465 -- package body Main_Unit is
7466 -- function Func ...; -- target
7468 -- procedure Proc is
7469 -- X : ... := Func; -- root scenario
7471 if In_Extended_Main_Code_Unit
(Target_Decl
) then
7473 -- Performance note: parent traversal
7475 return not In_Same_Context
(Root
, Target_Decl
, Nested_OK
=> True);
7477 -- Otherwise the target is external to the main unit which makes it
7478 -- an up-level target.
7486 end Is_Up_Level_Target
;
7488 ---------------------
7489 -- Is_Visited_Body --
7490 ---------------------
7492 function Is_Visited_Body
(Body_Decl
: Node_Id
) return Boolean is
7494 if Visited_Bodies_In_Use
then
7495 return Visited_Bodies
.Get
(Body_Decl
);
7498 return Visited_Bodies_No_Element
;
7499 end Is_Visited_Body
;
7501 -------------------------------
7502 -- Kill_Elaboration_Scenario --
7503 -------------------------------
7505 procedure Kill_Elaboration_Scenario
(N
: Node_Id
) is
7506 procedure Kill_SPARK_Scenario
;
7507 pragma Inline
(Kill_SPARK_Scenario
);
7508 -- Eliminate scenario N from table SPARK_Scenarios if it is recorded
7511 procedure Kill_Top_Level_Scenario
;
7512 pragma Inline
(Kill_Top_Level_Scenario
);
7513 -- Eliminate scenario N from table Top_Level_Scenarios if it is recorded
7516 -------------------------
7517 -- Kill_SPARK_Scenario --
7518 -------------------------
7520 procedure Kill_SPARK_Scenario
is
7521 package Scenarios
renames SPARK_Scenarios
;
7524 if Is_Recorded_SPARK_Scenario
(N
) then
7526 -- Performance note: list traversal
7528 for Index
in Scenarios
.First
.. Scenarios
.Last
loop
7529 if Scenarios
.Table
(Index
) = N
then
7530 Scenarios
.Table
(Index
) := Empty
;
7532 -- The SPARK scenario is no longer recorded
7534 Set_Is_Recorded_SPARK_Scenario
(N
, False);
7539 -- A recorded SPARK scenario must be in the table of recorded
7542 pragma Assert
(False);
7544 end Kill_SPARK_Scenario
;
7546 -----------------------------
7547 -- Kill_Top_Level_Scenario --
7548 -----------------------------
7550 procedure Kill_Top_Level_Scenario
is
7551 package Scenarios
renames Top_Level_Scenarios
;
7554 if Is_Recorded_Top_Level_Scenario
(N
) then
7556 -- Performance node: list traversal
7558 for Index
in Scenarios
.First
.. Scenarios
.Last
loop
7559 if Scenarios
.Table
(Index
) = N
then
7560 Scenarios
.Table
(Index
) := Empty
;
7562 -- The top-level scenario is no longer recorded
7564 Set_Is_Recorded_Top_Level_Scenario
(N
, False);
7569 -- A recorded top-level scenario must be in the table of recorded
7570 -- top-level scenarios.
7572 pragma Assert
(False);
7574 end Kill_Top_Level_Scenario
;
7576 -- Start of processing for Kill_Elaboration_Scenario
7579 -- Nothing to do when switch -gnatH (legacy elaboration checking mode
7580 -- enabled) is in effect because the legacy ABE lechanism does not need
7581 -- to carry out this action.
7583 if Legacy_Elaboration_Checks
then
7587 -- Eliminate a recorded scenario when it appears within dead code
7588 -- because it will not be executed at elaboration time.
7590 if Is_Scenario
(N
) then
7591 Kill_SPARK_Scenario
;
7592 Kill_Top_Level_Scenario
;
7594 end Kill_Elaboration_Scenario
;
7596 ----------------------------------
7597 -- Meet_Elaboration_Requirement --
7598 ----------------------------------
7600 procedure Meet_Elaboration_Requirement
7602 Target_Id
: Entity_Id
;
7605 Main_Id
: constant Entity_Id
:= Cunit_Entity
(Main_Unit
);
7606 Unit_Id
: constant Entity_Id
:= Find_Top_Unit
(Target_Id
);
7608 function Find_Preelaboration_Pragma
7609 (Prag_Nam
: Name_Id
) return Node_Id
;
7610 pragma Inline
(Find_Preelaboration_Pragma
);
7611 -- Traverse the visible declarations of unit Unit_Id and locate a source
7612 -- preelaboration-related pragma with name Prag_Nam.
7614 procedure Info_Requirement_Met
(Prag
: Node_Id
);
7615 pragma Inline
(Info_Requirement_Met
);
7616 -- Output information concerning pragma Prag which meets requirement
7619 procedure Info_Scenario
;
7620 pragma Inline
(Info_Scenario
);
7621 -- Output information concerning scenario N
7623 --------------------------------
7624 -- Find_Preelaboration_Pragma --
7625 --------------------------------
7627 function Find_Preelaboration_Pragma
7628 (Prag_Nam
: Name_Id
) return Node_Id
7630 Spec
: constant Node_Id
:= Parent
(Unit_Id
);
7634 -- A preelaboration-related pragma comes from source and appears at
7635 -- the top of the visible declarations of a package.
7637 if Nkind
(Spec
) = N_Package_Specification
then
7638 Decl
:= First
(Visible_Declarations
(Spec
));
7639 while Present
(Decl
) loop
7640 if Comes_From_Source
(Decl
) then
7641 if Nkind
(Decl
) = N_Pragma
7642 and then Pragma_Name
(Decl
) = Prag_Nam
7646 -- Otherwise the construct terminates the region where the
7647 -- preelabortion-related pragma may appear.
7659 end Find_Preelaboration_Pragma
;
7661 --------------------------
7662 -- Info_Requirement_Met --
7663 --------------------------
7665 procedure Info_Requirement_Met
(Prag
: Node_Id
) is
7667 pragma Assert
(Present
(Prag
));
7669 Error_Msg_Name_1
:= Req_Nam
;
7670 Error_Msg_Sloc
:= Sloc
(Prag
);
7672 ("\\% requirement for unit & met by pragma #", N
, Unit_Id
);
7673 end Info_Requirement_Met
;
7679 procedure Info_Scenario
is
7681 if Is_Suitable_Call
(N
) then
7684 Target_Id
=> Target_Id
,
7688 elsif Is_Suitable_Instantiation
(N
) then
7691 Gen_Id
=> Target_Id
,
7695 elsif Is_Suitable_SPARK_Refined_State_Pragma
(N
) then
7697 ("read of refinement constituents during elaboration in SPARK",
7700 elsif Is_Suitable_Variable_Reference
(N
) then
7701 Info_Variable_Reference
7703 Var_Id
=> Target_Id
,
7707 -- No other scenario may impose a requirement on the context of the
7711 pragma Assert
(False);
7718 Elab_Attrs
: Elaboration_Attributes
;
7722 -- Start of processing for Meet_Elaboration_Requirement
7725 pragma Assert
(Nam_In
(Req_Nam
, Name_Elaborate
, Name_Elaborate_All
));
7727 -- Assume that the requirement has not been met
7731 -- Elaboration requirements are verified only when the static model is
7732 -- in effect because this diagnostic is graph-dependent.
7734 if not Static_Elaboration_Checks
then
7737 -- If the target is within the main unit, either at the source level or
7738 -- through an instantiation, then there is no real requirement to meet
7739 -- because the main unit cannot force its own elaboration by means of an
7740 -- Elaborate[_All] pragma. Treat this case as valid coverage.
7742 elsif In_Extended_Main_Code_Unit
(Target_Id
) then
7745 -- Otherwise the target resides in an external unit
7747 -- The requirement is met when the target comes from an internal unit
7748 -- because such a unit is elaborated prior to a non-internal unit.
7750 elsif In_Internal_Unit
(Unit_Id
)
7751 and then not In_Internal_Unit
(Main_Id
)
7755 -- The requirement is met when the target comes from a preelaborated
7756 -- unit. This portion must parallel predicate Is_Preelaborated_Unit.
7758 elsif Is_Preelaborated_Unit
(Unit_Id
) then
7761 -- Output extra information when switch -gnatel (info messages on
7762 -- implicit Elaborate[_All] pragmas.
7764 if Elab_Info_Messages
then
7765 if Is_Preelaborated
(Unit_Id
) then
7766 Elab_Nam
:= Name_Preelaborate
;
7768 elsif Is_Pure
(Unit_Id
) then
7769 Elab_Nam
:= Name_Pure
;
7771 elsif Is_Remote_Call_Interface
(Unit_Id
) then
7772 Elab_Nam
:= Name_Remote_Call_Interface
;
7774 elsif Is_Remote_Types
(Unit_Id
) then
7775 Elab_Nam
:= Name_Remote_Types
;
7778 pragma Assert
(Is_Shared_Passive
(Unit_Id
));
7779 Elab_Nam
:= Name_Shared_Passive
;
7782 Info_Requirement_Met
(Find_Preelaboration_Pragma
(Elab_Nam
));
7785 -- Determine whether the context of the main unit has a pragma strong
7786 -- enough to meet the requirement.
7789 Elab_Attrs
:= Elaboration_Status
(Unit_Id
);
7791 -- The pragma must be either Elaborate_All or be as strong as the
7794 if Present
(Elab_Attrs
.Source_Pragma
)
7795 and then Nam_In
(Pragma_Name
(Elab_Attrs
.Source_Pragma
),
7801 -- Output extra information when switch -gnatel (info messages on
7802 -- implicit Elaborate[_All] pragmas.
7804 if Elab_Info_Messages
then
7805 Info_Requirement_Met
(Elab_Attrs
.Source_Pragma
);
7810 -- The requirement was not met by the context of the main unit, issue an
7816 Error_Msg_Name_1
:= Req_Nam
;
7817 Error_Msg_Node_2
:= Unit_Id
;
7818 Error_Msg_NE
("\\unit & requires pragma % for &", N
, Main_Id
);
7820 Output_Active_Scenarios
(N
);
7822 end Meet_Elaboration_Requirement
;
7824 ----------------------
7825 -- Non_Private_View --
7826 ----------------------
7828 function Non_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
7834 if Is_Private_Type
(Result
) and then Present
(Full_View
(Result
)) then
7835 Result
:= Full_View
(Result
);
7839 end Non_Private_View
;
7841 -----------------------------
7842 -- Output_Active_Scenarios --
7843 -----------------------------
7845 procedure Output_Active_Scenarios
(Error_Nod
: Node_Id
) is
7846 procedure Output_Access
(N
: Node_Id
);
7847 -- Emit a specific diagnostic message for 'Access denote by N
7849 procedure Output_Activation_Call
(N
: Node_Id
);
7850 -- Emit a specific diagnostic message for task activation N
7852 procedure Output_Call
(N
: Node_Id
; Target_Id
: Entity_Id
);
7853 -- Emit a specific diagnostic message for call N which invokes target
7856 procedure Output_Header
;
7857 -- Emit a specific diagnostic message for the unit of the root scenario
7859 procedure Output_Instantiation
(N
: Node_Id
);
7860 -- Emit a specific diagnostic message for instantiation N
7862 procedure Output_SPARK_Refined_State_Pragma
(N
: Node_Id
);
7863 -- Emit a specific diagnostic message for Refined_State pragma N
7865 procedure Output_Variable_Assignment
(N
: Node_Id
);
7866 -- Emit a specific diagnostic message for assignment statement N
7868 procedure Output_Variable_Reference
(N
: Node_Id
);
7869 -- Emit a specific diagnostic message for reference N which mentions a
7876 procedure Output_Access
(N
: Node_Id
) is
7877 Subp_Id
: constant Entity_Id
:= Entity
(Prefix
(N
));
7880 Error_Msg_Name_1
:= Attribute_Name
(N
);
7881 Error_Msg_Sloc
:= Sloc
(N
);
7882 Error_Msg_NE
("\\ % of & taken #", Error_Nod
, Subp_Id
);
7885 ----------------------------
7886 -- Output_Activation_Call --
7887 ----------------------------
7889 procedure Output_Activation_Call
(N
: Node_Id
) is
7890 function Find_Activator
(Call
: Node_Id
) return Entity_Id
;
7891 -- Find the nearest enclosing construct which houses call Call
7893 --------------------
7894 -- Find_Activator --
7895 --------------------
7897 function Find_Activator
(Call
: Node_Id
) return Entity_Id
is
7901 -- Climb the parent chain looking for a package [body] or a
7902 -- construct with a statement sequence.
7904 Par
:= Parent
(Call
);
7905 while Present
(Par
) loop
7906 if Nkind_In
(Par
, N_Package_Body
, N_Package_Declaration
) then
7907 return Defining_Entity
(Par
);
7909 elsif Nkind
(Par
) = N_Handled_Sequence_Of_Statements
then
7910 return Defining_Entity
(Parent
(Par
));
7913 Par
:= Parent
(Par
);
7921 Activator
: constant Entity_Id
:= Find_Activator
(N
);
7923 -- Start of processing for Output_Activation_Call
7926 pragma Assert
(Present
(Activator
));
7928 Error_Msg_NE
("\\ local tasks of & activated", Error_Nod
, Activator
);
7929 end Output_Activation_Call
;
7935 procedure Output_Call
(N
: Node_Id
; Target_Id
: Entity_Id
) is
7936 procedure Output_Accept_Alternative
;
7937 pragma Inline
(Output_Accept_Alternative
);
7938 -- Emit a specific diagnostic message concerning an accept
7941 procedure Output_Call
(Kind
: String);
7942 pragma Inline
(Output_Call
);
7943 -- Emit a specific diagnostic message concerning a call of kind Kind
7945 procedure Output_Type_Actions
(Action
: String);
7946 pragma Inline
(Output_Type_Actions
);
7947 -- Emit a specific diagnostic message concerning action Action of a
7950 procedure Output_Verification_Call
7954 pragma Inline
(Output_Verification_Call
);
7955 -- Emit a specific diagnostic message concerning the verification of
7956 -- predicate Pred applied to related entity Id with kind Id_Kind.
7958 -------------------------------
7959 -- Output_Accept_Alternative --
7960 -------------------------------
7962 procedure Output_Accept_Alternative
is
7963 Entry_Id
: constant Entity_Id
:= Receiving_Entry
(Target_Id
);
7966 pragma Assert
(Present
(Entry_Id
));
7968 Error_Msg_NE
("\\ entry & selected #", Error_Nod
, Entry_Id
);
7969 end Output_Accept_Alternative
;
7975 procedure Output_Call
(Kind
: String) is
7977 Error_Msg_NE
("\\ " & Kind
& " & called #", Error_Nod
, Target_Id
);
7980 -------------------------
7981 -- Output_Type_Actions --
7982 -------------------------
7984 procedure Output_Type_Actions
(Action
: String) is
7985 Typ
: constant Entity_Id
:= First_Formal_Type
(Target_Id
);
7988 pragma Assert
(Present
(Typ
));
7991 ("\\ " & Action
& " actions for type & #", Error_Nod
, Typ
);
7992 end Output_Type_Actions
;
7994 ------------------------------
7995 -- Output_Verification_Call --
7996 ------------------------------
7998 procedure Output_Verification_Call
8004 pragma Assert
(Present
(Id
));
8007 ("\\ " & Pred
& " of " & Id_Kind
& " & verified #",
8009 end Output_Verification_Call
;
8011 -- Start of processing for Output_Call
8014 Error_Msg_Sloc
:= Sloc
(N
);
8016 -- Accept alternative
8018 if Is_Accept_Alternative_Proc
(Target_Id
) then
8019 Output_Accept_Alternative
;
8023 elsif Is_TSS
(Target_Id
, TSS_Deep_Adjust
) then
8024 Output_Type_Actions
("adjustment");
8026 -- Default_Initial_Condition
8028 elsif Is_Default_Initial_Condition_Proc
(Target_Id
) then
8029 Output_Verification_Call
8030 (Pred
=> "Default_Initial_Condition",
8031 Id
=> First_Formal_Type
(Target_Id
),
8036 elsif Is_Protected_Entry
(Target_Id
) then
8037 Output_Call
("entry");
8039 -- Task entry calls are never processed because the entry being
8040 -- invoked does not have a corresponding "body", it has a select. A
8041 -- task entry call appears in the stack of active scenarios for the
8042 -- sole purpose of checking No_Entry_Calls_In_Elaboration_Code and
8045 elsif Is_Task_Entry
(Target_Id
) then
8050 elsif Is_TSS
(Target_Id
, TSS_Deep_Finalize
) then
8051 Output_Type_Actions
("finalization");
8053 -- Calls to _Finalizer procedures must not appear in the output
8054 -- because this creates confusing noise.
8056 elsif Is_Finalizer_Proc
(Target_Id
) then
8059 -- Initial_Condition
8061 elsif Is_Initial_Condition_Proc
(Target_Id
) then
8062 Output_Verification_Call
8063 (Pred
=> "Initial_Condition",
8064 Id
=> Find_Enclosing_Scope
(N
),
8065 Id_Kind
=> "package");
8069 elsif Is_Init_Proc
(Target_Id
)
8070 or else Is_TSS
(Target_Id
, TSS_Deep_Initialize
)
8072 Output_Type_Actions
("initialization");
8076 elsif Is_Invariant_Proc
(Target_Id
) then
8077 Output_Verification_Call
8078 (Pred
=> "invariants",
8079 Id
=> First_Formal_Type
(Target_Id
),
8082 -- Partial invariant calls must not appear in the output because this
8083 -- creates confusing noise. Note that a partial invariant is always
8084 -- invoked by the "full" invariant which is already placed on the
8087 elsif Is_Partial_Invariant_Proc
(Target_Id
) then
8092 elsif Is_Postconditions_Proc
(Target_Id
) then
8093 Output_Verification_Call
8094 (Pred
=> "postconditions",
8095 Id
=> Find_Enclosing_Scope
(N
),
8096 Id_Kind
=> "subprogram");
8098 -- Subprograms must come last because some of the previous cases fall
8099 -- under this category.
8101 elsif Ekind
(Target_Id
) = E_Function
then
8102 Output_Call
("function");
8104 elsif Ekind
(Target_Id
) = E_Procedure
then
8105 Output_Call
("procedure");
8108 pragma Assert
(False);
8117 procedure Output_Header
is
8118 Unit_Id
: constant Entity_Id
:= Find_Top_Unit
(Root_Scenario
);
8121 if Ekind
(Unit_Id
) = E_Package
then
8122 Error_Msg_NE
("\\ spec of unit & elaborated", Error_Nod
, Unit_Id
);
8124 elsif Ekind
(Unit_Id
) = E_Package_Body
then
8125 Error_Msg_NE
("\\ body of unit & elaborated", Error_Nod
, Unit_Id
);
8128 Error_Msg_NE
("\\ in body of unit &", Error_Nod
, Unit_Id
);
8132 --------------------------
8133 -- Output_Instantiation --
8134 --------------------------
8136 procedure Output_Instantiation
(N
: Node_Id
) is
8137 procedure Output_Instantiation
(Gen_Id
: Entity_Id
; Kind
: String);
8138 pragma Inline
(Output_Instantiation
);
8139 -- Emit a specific diagnostic message concerning an instantiation of
8140 -- generic unit Gen_Id. Kind denotes the kind of the instantiation.
8142 --------------------------
8143 -- Output_Instantiation --
8144 --------------------------
8146 procedure Output_Instantiation
(Gen_Id
: Entity_Id
; Kind
: String) is
8149 ("\\ " & Kind
& " & instantiated as & #", Error_Nod
, Gen_Id
);
8150 end Output_Instantiation
;
8155 Inst_Attrs
: Instantiation_Attributes
;
8156 Inst_Id
: Entity_Id
;
8159 -- Start of processing for Output_Instantiation
8162 Extract_Instantiation_Attributes
8167 Attrs
=> Inst_Attrs
);
8169 Error_Msg_Node_2
:= Inst_Id
;
8170 Error_Msg_Sloc
:= Sloc
(Inst
);
8172 if Nkind
(Inst
) = N_Function_Instantiation
then
8173 Output_Instantiation
(Gen_Id
, "function");
8175 elsif Nkind
(Inst
) = N_Package_Instantiation
then
8176 Output_Instantiation
(Gen_Id
, "package");
8178 elsif Nkind
(Inst
) = N_Procedure_Instantiation
then
8179 Output_Instantiation
(Gen_Id
, "procedure");
8182 pragma Assert
(False);
8185 end Output_Instantiation
;
8187 ---------------------------------------
8188 -- Output_SPARK_Refined_State_Pragma --
8189 ---------------------------------------
8191 procedure Output_SPARK_Refined_State_Pragma
(N
: Node_Id
) is
8193 Error_Msg_Sloc
:= Sloc
(N
);
8194 Error_Msg_N
("\\ refinement constituents read #", Error_Nod
);
8195 end Output_SPARK_Refined_State_Pragma
;
8197 --------------------------------
8198 -- Output_Variable_Assignment --
8199 --------------------------------
8201 procedure Output_Variable_Assignment
(N
: Node_Id
) is
8202 Var_Id
: constant Entity_Id
:= Entity
(Extract_Assignment_Name
(N
));
8205 Error_Msg_Sloc
:= Sloc
(N
);
8206 Error_Msg_NE
("\\ variable & assigned #", Error_Nod
, Var_Id
);
8207 end Output_Variable_Assignment
;
8209 -------------------------------
8210 -- Output_Variable_Reference --
8211 -------------------------------
8213 procedure Output_Variable_Reference
(N
: Node_Id
) is
8214 Dummy
: Variable_Attributes
;
8218 Extract_Variable_Reference_Attributes
8223 Error_Msg_Sloc
:= Sloc
(N
);
8226 Error_Msg_NE
("\\ variable & read #", Error_Nod
, Var_Id
);
8229 pragma Assert
(False);
8232 end Output_Variable_Reference
;
8236 package Stack
renames Scenario_Stack
;
8238 Dummy
: Call_Attributes
;
8241 Target_Id
: Entity_Id
;
8243 -- Start of processing for Output_Active_Scenarios
8246 -- Active scenarios are emitted only when the static model is in effect
8247 -- because there is an inherent order by which all these scenarios were
8248 -- reached from the declaration or library level.
8250 if not Static_Elaboration_Checks
then
8256 for Index
in Stack
.First
.. Stack
.Last
loop
8257 N
:= Stack
.Table
(Index
);
8266 if Nkind
(N
) = N_Attribute_Reference
then
8271 elsif Is_Suitable_Call
(N
) then
8272 Extract_Call_Attributes
8274 Target_Id
=> Target_Id
,
8277 if Is_Activation_Proc
(Target_Id
) then
8278 Output_Activation_Call
(N
);
8280 Output_Call
(N
, Target_Id
);
8285 elsif Is_Suitable_Instantiation
(N
) then
8286 Output_Instantiation
(N
);
8288 -- Pragma Refined_State
8290 elsif Is_Suitable_SPARK_Refined_State_Pragma
(N
) then
8291 Output_SPARK_Refined_State_Pragma
(N
);
8293 -- Variable assignments
8295 elsif Nkind
(N
) = N_Assignment_Statement
then
8296 Output_Variable_Assignment
(N
);
8298 -- Variable references
8300 elsif Is_Suitable_Variable_Reference
(N
) then
8301 Output_Variable_Reference
(N
);
8304 pragma Assert
(False);
8308 end Output_Active_Scenarios
;
8310 -------------------------
8311 -- Pop_Active_Scenario --
8312 -------------------------
8314 procedure Pop_Active_Scenario
(N
: Node_Id
) is
8315 Top
: Node_Id
renames Scenario_Stack
.Table
(Scenario_Stack
.Last
);
8318 pragma Assert
(Top
= N
);
8319 Scenario_Stack
.Decrement_Last
;
8320 end Pop_Active_Scenario
;
8322 --------------------------------
8323 -- Process_Activation_Generic --
8324 --------------------------------
8326 procedure Process_Activation_Generic
8328 Call_Attrs
: Call_Attributes
;
8329 State
: Processing_Attributes
)
8331 procedure Process_Task_Object
(Obj_Id
: Entity_Id
; Typ
: Entity_Id
);
8332 -- Perform ABE checks and diagnostics for object Obj_Id with type Typ.
8333 -- Typ may be a task type or a composite type with at least one task
8336 procedure Process_Task_Objects
(List
: List_Id
);
8337 -- Perform ABE checks and diagnostics for all task objects found in
8340 -------------------------
8341 -- Process_Task_Object --
8342 -------------------------
8344 procedure Process_Task_Object
(Obj_Id
: Entity_Id
; Typ
: Entity_Id
) is
8345 Base_Typ
: constant Entity_Id
:= Base_Type
(Typ
);
8347 Comp_Id
: Entity_Id
;
8348 Task_Attrs
: Task_Attributes
;
8351 if Is_Task_Type
(Typ
) then
8352 Extract_Task_Attributes
8354 Attrs
=> Task_Attrs
);
8356 Process_Single_Activation
8358 Call_Attrs
=> Call_Attrs
,
8360 Task_Attrs
=> Task_Attrs
,
8363 -- Examine the component type when the object is an array
8365 elsif Is_Array_Type
(Typ
) and then Has_Task
(Base_Typ
) then
8366 Process_Task_Object
(Obj_Id
, Component_Type
(Typ
));
8368 -- Examine individual component types when the object is a record
8370 elsif Is_Record_Type
(Typ
) and then Has_Task
(Base_Typ
) then
8371 Comp_Id
:= First_Component
(Typ
);
8372 while Present
(Comp_Id
) loop
8373 Process_Task_Object
(Obj_Id
, Etype
(Comp_Id
));
8374 Next_Component
(Comp_Id
);
8377 end Process_Task_Object
;
8379 --------------------------
8380 -- Process_Task_Objects --
8381 --------------------------
8383 procedure Process_Task_Objects
(List
: List_Id
) is
8385 Item_Id
: Entity_Id
;
8386 Item_Typ
: Entity_Id
;
8389 -- Examine the contents of the list looking for an object declaration
8390 -- of a task type or one that contains a task within.
8392 Item
:= First
(List
);
8393 while Present
(Item
) loop
8394 if Nkind
(Item
) = N_Object_Declaration
then
8395 Item_Id
:= Defining_Entity
(Item
);
8396 Item_Typ
:= Etype
(Item_Id
);
8398 if Has_Task
(Item_Typ
) then
8399 Process_Task_Object
(Item_Id
, Item_Typ
);
8405 end Process_Task_Objects
;
8412 -- Start of processing for Process_Activation_Generic
8415 -- Nothing to do when the activation is a guaranteed ABE
8417 if Is_Known_Guaranteed_ABE
(Call
) then
8421 -- Find the proper context of the activation call where all task objects
8422 -- being activated are declared. This is usually the immediate parent of
8425 Context
:= Parent
(Call
);
8427 -- In the case of package bodies, the activation call is in the handled
8428 -- sequence of statements, but the task objects are in the declaration
8429 -- list of the body.
8431 if Nkind
(Context
) = N_Handled_Sequence_Of_Statements
8432 and then Nkind
(Parent
(Context
)) = N_Package_Body
8434 Context
:= Parent
(Context
);
8437 -- Process all task objects defined in both the spec and body when the
8438 -- activation call precedes the "begin" of a package body.
8440 if Nkind
(Context
) = N_Package_Body
then
8443 (Unit_Declaration_Node
(Corresponding_Spec
(Context
)));
8445 Process_Task_Objects
(Visible_Declarations
(Spec
));
8446 Process_Task_Objects
(Private_Declarations
(Spec
));
8447 Process_Task_Objects
(Declarations
(Context
));
8449 -- Process all task objects defined in the spec when the activation call
8450 -- appears at the end of a package spec.
8452 elsif Nkind
(Context
) = N_Package_Specification
then
8453 Process_Task_Objects
(Visible_Declarations
(Context
));
8454 Process_Task_Objects
(Private_Declarations
(Context
));
8456 -- Otherwise the context of the activation is some construct with a
8457 -- declarative part. Note that the corresponding record type of a task
8458 -- type is controlled. Because of this, the finalization machinery must
8459 -- relocate the task object to the handled statements of the construct
8460 -- to perform proper finalization in case of an exception. Examine the
8461 -- statements of the construct rather than the declarations.
8464 pragma Assert
(Nkind
(Context
) = N_Handled_Sequence_Of_Statements
);
8466 Process_Task_Objects
(Statements
(Context
));
8468 end Process_Activation_Generic
;
8470 ------------------------------------
8471 -- Process_Conditional_ABE_Access --
8472 ------------------------------------
8474 procedure Process_Conditional_ABE_Access
8476 State
: Processing_Attributes
)
8478 function Build_Access_Marker
(Target_Id
: Entity_Id
) return Node_Id
;
8479 pragma Inline
(Build_Access_Marker
);
8480 -- Create a suitable call marker which invokes target Target_Id
8482 -------------------------
8483 -- Build_Access_Marker --
8484 -------------------------
8486 function Build_Access_Marker
(Target_Id
: Entity_Id
) return Node_Id
is
8490 Marker
:= Make_Call_Marker
(Sloc
(Attr
));
8492 -- Inherit relevant attributes from the attribute
8494 -- Performance note: parent traversal
8496 Set_Target
(Marker
, Target_Id
);
8497 Set_Is_Declaration_Level_Node
8498 (Marker
, Find_Enclosing_Level
(Attr
) = Declaration_Level
);
8499 Set_Is_Dispatching_Call
8501 Set_Is_Elaboration_Checks_OK_Node
8502 (Marker
, Is_Elaboration_Checks_OK_Node
(Attr
));
8504 (Marker
, Comes_From_Source
(Attr
));
8505 Set_Is_SPARK_Mode_On_Node
8506 (Marker
, Is_SPARK_Mode_On_Node
(Attr
));
8508 -- Partially insert the call marker into the tree by setting its
8511 Set_Parent
(Marker
, Attr
);
8514 end Build_Access_Marker
;
8518 Root
: constant Node_Id
:= Root_Scenario
;
8519 Target_Id
: constant Entity_Id
:= Entity
(Prefix
(Attr
));
8521 Target_Attrs
: Target_Attributes
;
8523 -- Start of processing for Process_Conditional_ABE_Access
8526 -- Output relevant information when switch -gnatel (info messages on
8527 -- implicit Elaborate[_All] pragmas) is in effect.
8529 if Elab_Info_Messages
then
8531 ("info: access to & during elaboration", Attr
, Target_Id
);
8534 Extract_Target_Attributes
8535 (Target_Id
=> Target_Id
,
8536 Attrs
=> Target_Attrs
);
8538 -- Both the attribute and the corresponding body are in the same unit.
8539 -- The corresponding body must appear prior to the root scenario which
8540 -- started the recursive search. If this is not the case, then there is
8541 -- a potential ABE if the access value is used to call the subprogram.
8542 -- Emit a warning only when switch -gnatw.f (warnings on suspucious
8543 -- 'Access) is in effect.
8545 if Warn_On_Elab_Access
8546 and then Present
(Target_Attrs
.Body_Decl
)
8547 and then In_Extended_Main_Code_Unit
(Target_Attrs
.Body_Decl
)
8548 and then Earlier_In_Extended_Unit
(Root
, Target_Attrs
.Body_Decl
)
8550 Error_Msg_Name_1
:= Attribute_Name
(Attr
);
8551 Error_Msg_NE
("??% attribute of & before body seen", Attr
, Target_Id
);
8552 Error_Msg_N
("\possible Program_Error on later references", Attr
);
8554 Output_Active_Scenarios
(Attr
);
8557 -- Treat the attribute as an immediate invocation of the target when
8558 -- switch -gnatd.o (conservative elaboration order for indirect calls)
8559 -- is in effect. Note that the prior elaboration of the unit containing
8560 -- the target is ensured processing the corresponding call marker.
8562 if Debug_Flag_Dot_O
then
8563 Process_Conditional_ABE
8564 (N
=> Build_Access_Marker
(Target_Id
),
8567 -- Otherwise ensure that the unit with the corresponding body is
8568 -- elaborated prior to the main unit.
8571 Ensure_Prior_Elaboration
8573 Unit_Id
=> Target_Attrs
.Unit_Id
,
8574 Prag_Nam
=> Name_Elaborate_All
,
8577 end Process_Conditional_ABE_Access
;
8579 ---------------------------------------------
8580 -- Process_Conditional_ABE_Activation_Impl --
8581 ---------------------------------------------
8583 procedure Process_Conditional_ABE_Activation_Impl
8585 Call_Attrs
: Call_Attributes
;
8587 Task_Attrs
: Task_Attributes
;
8588 State
: Processing_Attributes
)
8590 Check_OK
: constant Boolean :=
8591 not Is_Ignored_Ghost_Entity
(Obj_Id
)
8592 and then not Task_Attrs
.Ghost_Mode_Ignore
8593 and then Is_Elaboration_Checks_OK_Id
(Obj_Id
)
8594 and then Task_Attrs
.Elab_Checks_OK
;
8595 -- A run-time ABE check may be installed only when the object and the
8596 -- task type have active elaboration checks, and both are not ignored
8597 -- Ghost constructs.
8599 Root
: constant Node_Id
:= Root_Scenario
;
8601 New_State
: Processing_Attributes
:= State
;
8602 -- Each step of the Processing phase constitutes a new state
8605 -- Output relevant information when switch -gnatel (info messages on
8606 -- implicit Elaborate[_All] pragmas) is in effect.
8608 if Elab_Info_Messages
then
8610 ("info: activation of & during elaboration", Call
, Obj_Id
);
8613 -- Nothing to do when the call activates a task whose type is defined
8614 -- within an instance and switch -gnatdL (ignore activations and calls
8615 -- to instances for elaboration) is in effect.
8618 and then In_External_Instance
8620 Target_Decl
=> Task_Attrs
.Task_Decl
)
8624 -- Nothing to do when the activation is a guaranteed ABE
8626 elsif Is_Known_Guaranteed_ABE
(Call
) then
8629 -- Nothing to do when the root scenario appears at the declaration
8630 -- level and the task is in the same unit, but outside this context.
8632 -- task type Task_Typ; -- task declaration
8634 -- procedure Proc is
8635 -- function A ... is
8637 -- if Some_Condition then
8641 -- <activation call> -- activation site
8646 -- X : ... := A; -- root scenario
8649 -- task body Task_Typ is
8653 -- In the example above, the context of X is the declarative list of
8654 -- Proc. The "elaboration" of X may reach the activation of T whose body
8655 -- is defined outside of X's context. The task body is relevant only
8656 -- when Proc is invoked, but this happens only in "normal" elaboration,
8657 -- therefore the task body must not be considered if this is not the
8660 -- Performance note: parent traversal
8662 elsif Is_Up_Level_Target
(Task_Attrs
.Task_Decl
) then
8665 -- Nothing to do when the activation is ABE-safe
8669 -- task type Task_Typ;
8672 -- package body Gen is
8673 -- task body Task_Typ is
8680 -- procedure Main is
8681 -- package Nested is
8682 -- package Inst is new Gen;
8683 -- T : Inst.Task_Typ;
8684 -- <activation call> -- safe activation
8688 elsif Is_Safe_Activation
(Call
, Task_Attrs
.Task_Decl
) then
8690 -- Note that the task body must still be examined for any nested
8695 -- The activation call and the task body are both in the main unit
8697 elsif Present
(Task_Attrs
.Body_Decl
)
8698 and then In_Extended_Main_Code_Unit
(Task_Attrs
.Body_Decl
)
8700 -- If the root scenario appears prior to the task body, then this is
8701 -- a possible ABE with respect to the root scenario.
8703 -- task type Task_Typ;
8705 -- function A ... is
8707 -- if Some_Condition then
8711 -- end Pack; -- activation of T
8715 -- X : ... := A; -- root scenario
8717 -- task body Task_Typ is -- task body
8721 -- Y : ... := A; -- root scenario
8723 -- IMPORTANT: The activation of T is a possible ABE for X, but
8724 -- not for Y. Intalling an unconditional ABE raise prior to the
8725 -- activation call would be wrong as it will fail for Y as well
8726 -- but in Y's case the activation of T is never an ABE.
8728 if Earlier_In_Extended_Unit
(Root
, Task_Attrs
.Body_Decl
) then
8730 -- Do not emit any ABE diagnostics when the activation occurs in
8731 -- a partial finalization context because this leads to confusing
8734 if State
.Within_Partial_Finalization
then
8737 -- ABE diagnostics are emitted only in the static model because
8738 -- there is a well-defined order to visiting scenarios. Without
8739 -- this order diagnostics appear jumbled and result in unwanted
8742 elsif Static_Elaboration_Checks
8743 and then Call_Attrs
.Elab_Warnings_OK
8745 Error_Msg_Sloc
:= Sloc
(Call
);
8747 ("??task & will be activated # before elaboration of its "
8750 ("\Program_Error may be raised at run time", Obj_Id
);
8752 Output_Active_Scenarios
(Obj_Id
);
8755 -- Install a conditional run-time ABE check to verify that the
8756 -- task body has been elaborated prior to the activation call.
8762 Target_Id
=> Task_Attrs
.Spec_Id
,
8763 Target_Decl
=> Task_Attrs
.Task_Decl
,
8764 Target_Body
=> Task_Attrs
.Body_Decl
);
8766 -- Update the state of the Processing phase to indicate that
8767 -- no implicit Elaborate[_All] pragmas must be generated from
8770 -- task type Task_Typ;
8772 -- function A ... is
8774 -- if Some_Condition then
8779 -- end Pack; -- activation of T
8785 -- task body Task_Typ is
8787 -- External.Subp; -- imparts Elaborate_All
8790 -- If Some_Condition is True, then the ABE check will fail at
8791 -- runtime and the call to External.Subp will never take place,
8792 -- rendering the implicit Elaborate_All useless.
8794 -- If Some_Condition is False, then the call to External.Subp
8795 -- will never take place, rendering the implicit Elaborate_All
8798 New_State
.Suppress_Implicit_Pragmas
:= True;
8802 -- Otherwise the task body is not available in this compilation or it
8803 -- resides in an external unit. Install a run-time ABE check to verify
8804 -- that the task body has been elaborated prior to the activation call
8805 -- when the dynamic model is in effect.
8807 elsif Dynamic_Elaboration_Checks
and then Check_OK
then
8811 Id
=> Task_Attrs
.Unit_Id
);
8814 -- Update the state of the Processing phase to indicate that any further
8815 -- traversal is now within a task body.
8817 New_State
.Within_Task_Body
:= True;
8819 -- Both the activation call and task type are subject to SPARK_Mode
8820 -- On, this triggers the SPARK rules for task activation. Compared to
8821 -- calls and instantiations, task activation in SPARK does not require
8822 -- the presence of Elaborate[_All] pragmas in case the task type is
8823 -- defined outside the main unit. This is because SPARK utilizes a
8824 -- special policy which activates all tasks after the main unit has
8825 -- finished its elaboration.
8827 if Call_Attrs
.SPARK_Mode_On
and Task_Attrs
.SPARK_Mode_On
then
8830 -- Otherwise the Ada rules are in effect. Ensure that the unit with the
8831 -- task body is elaborated prior to the main unit.
8834 Ensure_Prior_Elaboration
8836 Unit_Id
=> Task_Attrs
.Unit_Id
,
8837 Prag_Nam
=> Name_Elaborate_All
,
8838 State
=> New_State
);
8842 (N
=> Task_Attrs
.Body_Decl
,
8843 State
=> New_State
);
8844 end Process_Conditional_ABE_Activation_Impl
;
8846 procedure Process_Conditional_ABE_Activation
is
8847 new Process_Activation_Generic
(Process_Conditional_ABE_Activation_Impl
);
8849 ----------------------------------
8850 -- Process_Conditional_ABE_Call --
8851 ----------------------------------
8853 procedure Process_Conditional_ABE_Call
8855 Call_Attrs
: Call_Attributes
;
8856 Target_Id
: Entity_Id
;
8857 State
: Processing_Attributes
)
8859 function In_Initialization_Context
(N
: Node_Id
) return Boolean;
8860 -- Determine whether arbitrary node N appears within a type init proc,
8861 -- primitive [Deep_]Initialize, or a block created for initialization
8864 function Is_Partial_Finalization_Proc
return Boolean;
8865 pragma Inline
(Is_Partial_Finalization_Proc
);
8866 -- Determine whether call Call with target Target_Id invokes a partial
8867 -- finalization procedure.
8869 -------------------------------
8870 -- In_Initialization_Context --
8871 -------------------------------
8873 function In_Initialization_Context
(N
: Node_Id
) return Boolean is
8875 Spec_Id
: Entity_Id
;
8878 -- Climb the parent chain looking for initialization actions
8881 while Present
(Par
) loop
8883 -- A block may be part of the initialization actions of a default
8884 -- initialized object.
8886 if Nkind
(Par
) = N_Block_Statement
8887 and then Is_Initialization_Block
(Par
)
8891 -- A subprogram body may denote an initialization routine
8893 elsif Nkind
(Par
) = N_Subprogram_Body
then
8894 Spec_Id
:= Unique_Defining_Entity
(Par
);
8896 -- The current subprogram body denotes a type init proc or
8897 -- primitive [Deep_]Initialize.
8899 if Is_Init_Proc
(Spec_Id
)
8900 or else Is_Controlled_Proc
(Spec_Id
, Name_Initialize
)
8901 or else Is_TSS
(Spec_Id
, TSS_Deep_Initialize
)
8906 -- Prevent the search from going too far
8908 elsif Is_Body_Or_Package_Declaration
(Par
) then
8912 Par
:= Parent
(Par
);
8916 end In_Initialization_Context
;
8918 ----------------------------------
8919 -- Is_Partial_Finalization_Proc --
8920 ----------------------------------
8922 function Is_Partial_Finalization_Proc
return Boolean is
8924 -- To qualify, the target must denote primitive [Deep_]Finalize or a
8925 -- finalizer procedure, and the call must appear in an initialization
8929 (Is_Controlled_Proc
(Target_Id
, Name_Finalize
)
8930 or else Is_Finalizer_Proc
(Target_Id
)
8931 or else Is_TSS
(Target_Id
, TSS_Deep_Finalize
))
8932 and then In_Initialization_Context
(Call
);
8933 end Is_Partial_Finalization_Proc
;
8937 SPARK_Rules_On
: Boolean;
8938 Target_Attrs
: Target_Attributes
;
8940 New_State
: Processing_Attributes
:= State
;
8941 -- Each step of the Processing phase constitutes a new state
8943 -- Start of processing for Process_Conditional_ABE_Call
8946 Extract_Target_Attributes
8947 (Target_Id
=> Target_Id
,
8948 Attrs
=> Target_Attrs
);
8950 -- The SPARK rules are in effect when both the call and target are
8951 -- subject to SPARK_Mode On.
8954 Call_Attrs
.SPARK_Mode_On
and Target_Attrs
.SPARK_Mode_On
;
8956 -- Output relevant information when switch -gnatel (info messages on
8957 -- implicit Elaborate[_All] pragmas) is in effect.
8959 if Elab_Info_Messages
then
8962 Target_Id
=> Target_Id
,
8964 In_SPARK
=> SPARK_Rules_On
);
8967 -- Check whether the invocation of an entry clashes with an existing
8970 if Is_Protected_Entry
(Target_Id
) then
8971 Check_Restriction
(No_Entry_Calls_In_Elaboration_Code
, Call
);
8973 elsif Is_Task_Entry
(Target_Id
) then
8974 Check_Restriction
(No_Entry_Calls_In_Elaboration_Code
, Call
);
8976 -- Task entry calls are never processed because the entry being
8977 -- invoked does not have a corresponding "body", it has a select.
8982 -- Nothing to do when the call invokes a target defined within an
8983 -- instance and switch -gnatdL (ignore activations and calls to
8984 -- instances for elaboration) is in effect.
8987 and then In_External_Instance
8989 Target_Decl
=> Target_Attrs
.Spec_Decl
)
8993 -- Nothing to do when the call is a guaranteed ABE
8995 elsif Is_Known_Guaranteed_ABE
(Call
) then
8998 -- Nothing to do when the root scenario appears at the declaration level
8999 -- and the target is in the same unit, but outside this context.
9001 -- function B ...; -- target declaration
9003 -- procedure Proc is
9004 -- function A ... is
9006 -- if Some_Condition then
9007 -- return B; -- call site
9011 -- X : ... := A; -- root scenario
9014 -- function B ... is
9018 -- In the example above, the context of X is the declarative region of
9019 -- Proc. The "elaboration" of X may eventually reach B which is defined
9020 -- outside of X's context. B is relevant only when Proc is invoked, but
9021 -- this happens only by means of "normal" elaboration, therefore B must
9022 -- not be considered if this is not the case.
9024 -- Performance note: parent traversal
9026 elsif Is_Up_Level_Target
(Target_Attrs
.Spec_Decl
) then
9030 -- The call occurs in an initial condition context when a prior scenario
9031 -- is already in that mode, or when the target is an Initial_Condition
9032 -- procedure. Update the state of the Processing phase to reflect this.
9034 New_State
.Within_Initial_Condition
:=
9035 New_State
.Within_Initial_Condition
9036 or else Is_Initial_Condition_Proc
(Target_Id
);
9038 -- The call occurs in a partial finalization context when a prior
9039 -- scenario is already in that mode, or when the target denotes a
9040 -- [Deep_]Finalize primitive or a finalizer within an initialization
9041 -- context. Update the state of the Processing phase to reflect this.
9043 New_State
.Within_Partial_Finalization
:=
9044 New_State
.Within_Partial_Finalization
9045 or else Is_Partial_Finalization_Proc
;
9047 -- The SPARK rules are in effect. Note that -gnatd.v (enforce SPARK
9048 -- elaboration rules in SPARK code) is intentionally not taken into
9049 -- account here because Process_Conditional_ABE_Call_SPARK has two
9050 -- separate modes of operation.
9052 if SPARK_Rules_On
then
9053 Process_Conditional_ABE_Call_SPARK
9055 Target_Id
=> Target_Id
,
9056 Target_Attrs
=> Target_Attrs
,
9057 State
=> New_State
);
9059 -- Otherwise the Ada rules are in effect
9062 Process_Conditional_ABE_Call_Ada
9064 Call_Attrs
=> Call_Attrs
,
9065 Target_Id
=> Target_Id
,
9066 Target_Attrs
=> Target_Attrs
,
9067 State
=> New_State
);
9070 -- Inspect the target body (and barried function) for other suitable
9071 -- elaboration scenarios.
9074 (N
=> Target_Attrs
.Body_Barf
,
9075 State
=> New_State
);
9078 (N
=> Target_Attrs
.Body_Decl
,
9079 State
=> New_State
);
9080 end Process_Conditional_ABE_Call
;
9082 --------------------------------------
9083 -- Process_Conditional_ABE_Call_Ada --
9084 --------------------------------------
9086 procedure Process_Conditional_ABE_Call_Ada
9088 Call_Attrs
: Call_Attributes
;
9089 Target_Id
: Entity_Id
;
9090 Target_Attrs
: Target_Attributes
;
9091 State
: Processing_Attributes
)
9093 Check_OK
: constant Boolean :=
9094 not Call_Attrs
.Ghost_Mode_Ignore
9095 and then not Target_Attrs
.Ghost_Mode_Ignore
9096 and then Call_Attrs
.Elab_Checks_OK
9097 and then Target_Attrs
.Elab_Checks_OK
;
9098 -- A run-time ABE check may be installed only when both the call and the
9099 -- target have active elaboration checks, and both are not ignored Ghost
9102 Root
: constant Node_Id
:= Root_Scenario
;
9104 New_State
: Processing_Attributes
:= State
;
9105 -- Each step of the Processing phase constitutes a new state
9108 -- Nothing to do for an Ada dispatching call because there are no ABE
9109 -- diagnostics for either models. ABE checks for the dynamic model are
9110 -- handled by Install_Primitive_Elaboration_Check.
9112 if Call_Attrs
.Is_Dispatching
then
9115 -- Nothing to do when the call is ABE-safe
9118 -- function Gen ...;
9120 -- function Gen ... is
9126 -- procedure Main is
9127 -- function Inst is new Gen;
9128 -- X : ... := Inst; -- safe call
9131 elsif Is_Safe_Call
(Call
, Target_Attrs
) then
9134 -- The call and the target body are both in the main unit
9136 elsif Present
(Target_Attrs
.Body_Decl
)
9137 and then In_Extended_Main_Code_Unit
(Target_Attrs
.Body_Decl
)
9139 -- If the root scenario appears prior to the target body, then this
9140 -- is a possible ABE with respect to the root scenario.
9144 -- function A ... is
9146 -- if Some_Condition then
9147 -- return B; -- call site
9151 -- X : ... := A; -- root scenario
9153 -- function B ... is -- target body
9157 -- Y : ... := A; -- root scenario
9159 -- IMPORTANT: The call to B from A is a possible ABE for X, but not
9160 -- for Y. Installing an unconditional ABE raise prior to the call to
9161 -- B would be wrong as it will fail for Y as well, but in Y's case
9162 -- the call to B is never an ABE.
9164 if Earlier_In_Extended_Unit
(Root
, Target_Attrs
.Body_Decl
) then
9166 -- Do not emit any ABE diagnostics when the call occurs in a
9167 -- partial finalization context because this leads to confusing
9170 if State
.Within_Partial_Finalization
then
9173 -- ABE diagnostics are emitted only in the static model because
9174 -- there is a well-defined order to visiting scenarios. Without
9175 -- this order diagnostics appear jumbled and result in unwanted
9178 elsif Static_Elaboration_Checks
9179 and then Call_Attrs
.Elab_Warnings_OK
9182 ("??cannot call & before body seen", Call
, Target_Id
);
9183 Error_Msg_N
("\Program_Error may be raised at run time", Call
);
9185 Output_Active_Scenarios
(Call
);
9188 -- Install a conditional run-time ABE check to verify that the
9189 -- target body has been elaborated prior to the call.
9195 Target_Id
=> Target_Attrs
.Spec_Id
,
9196 Target_Decl
=> Target_Attrs
.Spec_Decl
,
9197 Target_Body
=> Target_Attrs
.Body_Decl
);
9199 -- Update the state of the Processing phase to indicate that
9200 -- no implicit Elaborate[_All] pragmas must be generated from
9205 -- function A ... is
9207 -- if Some_Condition then
9215 -- function B ... is
9216 -- External.Subp; -- imparts Elaborate_All
9219 -- If Some_Condition is True, then the ABE check will fail at
9220 -- runtime and the call to External.Subp will never take place,
9221 -- rendering the implicit Elaborate_All useless.
9223 -- If Some_Condition is False, then the call to External.Subp
9224 -- will never take place, rendering the implicit Elaborate_All
9227 New_State
.Suppress_Implicit_Pragmas
:= True;
9231 -- Otherwise the target body is not available in this compilation or it
9232 -- resides in an external unit. Install a run-time ABE check to verify
9233 -- that the target body has been elaborated prior to the call site when
9234 -- the dynamic model is in effect.
9236 elsif Dynamic_Elaboration_Checks
and then Check_OK
then
9240 Id
=> Target_Attrs
.Unit_Id
);
9243 -- Ensure that the unit with the target body is elaborated prior to the
9244 -- main unit. The implicit Elaborate[_All] is generated only when the
9245 -- call has elaboration checks enabled. This behaviour parallels that of
9246 -- the old ABE mechanism.
9248 if Call_Attrs
.Elab_Checks_OK
then
9249 Ensure_Prior_Elaboration
9251 Unit_Id
=> Target_Attrs
.Unit_Id
,
9252 Prag_Nam
=> Name_Elaborate_All
,
9253 State
=> New_State
);
9255 end Process_Conditional_ABE_Call_Ada
;
9257 ----------------------------------------
9258 -- Process_Conditional_ABE_Call_SPARK --
9259 ----------------------------------------
9261 procedure Process_Conditional_ABE_Call_SPARK
9263 Target_Id
: Entity_Id
;
9264 Target_Attrs
: Target_Attributes
;
9265 State
: Processing_Attributes
)
9270 -- Ensure that a suitable elaboration model is in effect for SPARK rule
9273 Check_SPARK_Model_In_Effect
(Call
);
9275 -- The call and the target body are both in the main unit
9277 if Present
(Target_Attrs
.Body_Decl
)
9278 and then In_Extended_Main_Code_Unit
(Target_Attrs
.Body_Decl
)
9280 -- If the call appears prior to the target body, then the call must
9281 -- appear within the early call region of the target body.
9285 -- X : ... := B; -- call site
9287 -- <preelaborable construct 1> --+
9288 -- ... | early call region
9289 -- <preelaborable construct N> --+
9291 -- function B ... is -- target body
9295 -- When the call to B is not nested within some other scenario, the
9296 -- call is automatically illegal because it can never appear in the
9297 -- early call region of B's body. This is equivalent to a guaranteed
9300 -- <preelaborable construct 1> --+
9302 -- function B ...; |
9304 -- function A ... is |
9305 -- begin | early call region
9306 -- if Some_Condition then
9307 -- return B; -- call site
9311 -- <preelaborable construct N> --+
9313 -- function B ... is -- target body
9317 -- When the call to B is nested within some other scenario, the call
9318 -- is always ABE-safe. It is not immediately obvious why this is the
9319 -- case. The elaboration safety follows from the early call region
9320 -- rule being applied to ALL calls preceding their associated bodies.
9322 -- In the example above, the call to B is safe as long as the call to
9323 -- A is safe. There are several cases to consider:
9329 -- function A ... is
9331 -- if Some_Condition then
9337 -- function B ... is
9341 -- * Call 1 - This call is either nested within some scenario or not,
9342 -- which falls under the two general cases outlined above.
9344 -- * Call 2 - This is the same case as Call 1.
9346 -- * Call 3 - The placement of this call limits the range of B's
9347 -- early call region unto call 3, therefore the call to B is no
9348 -- longer within the early call region of B's body, making it ABE-
9349 -- unsafe and therefore illegal.
9351 if Earlier_In_Extended_Unit
(Call
, Target_Attrs
.Body_Decl
) then
9353 -- Do not emit any ABE diagnostics when the call occurs in an
9354 -- initial condition context because this leads to incorrect
9357 if State
.Within_Initial_Condition
then
9360 -- Do not emit any ABE diagnostics when the call occurs in a
9361 -- partial finalization context because this leads to confusing
9364 elsif State
.Within_Partial_Finalization
then
9367 -- ABE diagnostics are emitted only in the static model because
9368 -- there is a well-defined order to visiting scenarios. Without
9369 -- this order diagnostics appear jumbled and result in unwanted
9372 elsif Static_Elaboration_Checks
then
9374 -- Ensure that a call which textually precedes the subprogram
9375 -- body it invokes appears within the early call region of the
9378 -- IMPORTANT: This check must always be performed even when
9379 -- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is
9380 -- not specified because the static model cannot guarantee the
9381 -- absence of elaboration issues in the presence of dispatching
9384 Region
:= Find_Early_Call_Region
(Target_Attrs
.Body_Decl
);
9386 if Earlier_In_Extended_Unit
(Call
, Region
) then
9388 ("call must appear within early call region of subprogram "
9389 & "body & (SPARK RM 7.7(3))", Call
, Target_Id
);
9391 Error_Msg_Sloc
:= Sloc
(Region
);
9392 Error_Msg_N
("\region starts #", Call
);
9394 Error_Msg_Sloc
:= Sloc
(Target_Attrs
.Body_Decl
);
9395 Error_Msg_N
("\region ends #", Call
);
9397 Output_Active_Scenarios
(Call
);
9401 -- Otherwise the call appears after the target body. The call is
9402 -- ABE-safe as a consequence of applying the early call region rule
9403 -- to ALL calls preceding their associated bodies.
9410 -- A call to a source target or to a target which emulates Ada or SPARK
9411 -- semantics imposes an Elaborate_All requirement on the context of the
9412 -- main unit. Determine whether the context has a pragma strong enough
9413 -- to meet the requirement.
9415 -- IMPORTANT: This check must be performed only when -gnatd.v (enforce
9416 -- SPARK elaboration rules in SPARK code) is active because the static
9417 -- model can ensure the prior elaboration of the unit which contains a
9418 -- body by installing an implicit Elaborate[_All] pragma.
9420 if Debug_Flag_Dot_V
then
9421 if Target_Attrs
.From_Source
9422 or else Is_Ada_Semantic_Target
(Target_Id
)
9423 or else Is_SPARK_Semantic_Target
(Target_Id
)
9425 Meet_Elaboration_Requirement
9427 Target_Id
=> Target_Id
,
9428 Req_Nam
=> Name_Elaborate_All
);
9431 -- Otherwise ensure that the unit with the target body is elaborated
9432 -- prior to the main unit.
9435 Ensure_Prior_Elaboration
9437 Unit_Id
=> Target_Attrs
.Unit_Id
,
9438 Prag_Nam
=> Name_Elaborate_All
,
9441 end Process_Conditional_ABE_Call_SPARK
;
9443 -------------------------------------------
9444 -- Process_Conditional_ABE_Instantiation --
9445 -------------------------------------------
9447 procedure Process_Conditional_ABE_Instantiation
9448 (Exp_Inst
: Node_Id
;
9449 State
: Processing_Attributes
)
9451 Gen_Attrs
: Target_Attributes
;
9454 Inst_Attrs
: Instantiation_Attributes
;
9455 Inst_Id
: Entity_Id
;
9457 SPARK_Rules_On
: Boolean;
9458 -- This flag is set when the SPARK rules are in effect
9461 Extract_Instantiation_Attributes
9462 (Exp_Inst
=> Exp_Inst
,
9466 Attrs
=> Inst_Attrs
);
9468 Extract_Target_Attributes
(Gen_Id
, Gen_Attrs
);
9470 -- The SPARK rules are in effect when both the instantiation and generic
9471 -- are subject to SPARK_Mode On.
9473 SPARK_Rules_On
:= Inst_Attrs
.SPARK_Mode_On
and Gen_Attrs
.SPARK_Mode_On
;
9475 -- Output relevant information when switch -gnatel (info messages on
9476 -- implicit Elaborate[_All] pragmas) is in effect.
9478 if Elab_Info_Messages
then
9483 In_SPARK
=> SPARK_Rules_On
);
9486 -- Nothing to do when the instantiation is a guaranteed ABE
9488 if Is_Known_Guaranteed_ABE
(Inst
) then
9491 -- Nothing to do when the root scenario appears at the declaration level
9492 -- and the generic is in the same unit, but outside this context.
9495 -- procedure Gen is ...; -- generic declaration
9497 -- procedure Proc is
9498 -- function A ... is
9500 -- if Some_Condition then
9502 -- procedure I is new Gen; -- instantiation site
9507 -- X : ... := A; -- root scenario
9514 -- In the example above, the context of X is the declarative region of
9515 -- Proc. The "elaboration" of X may eventually reach Gen which appears
9516 -- outside of X's context. Gen is relevant only when Proc is invoked,
9517 -- but this happens only by means of "normal" elaboration, therefore
9518 -- Gen must not be considered if this is not the case.
9520 -- Performance note: parent traversal
9522 elsif Is_Up_Level_Target
(Gen_Attrs
.Spec_Decl
) then
9525 -- The SPARK rules are in effect
9527 elsif SPARK_Rules_On
then
9528 Process_Conditional_ABE_Instantiation_SPARK
9531 Gen_Attrs
=> Gen_Attrs
,
9534 -- Otherwise the Ada rules are in effect, or SPARK code is allowed to
9535 -- violate the SPARK rules.
9538 Process_Conditional_ABE_Instantiation_Ada
9539 (Exp_Inst
=> Exp_Inst
,
9541 Inst_Attrs
=> Inst_Attrs
,
9543 Gen_Attrs
=> Gen_Attrs
,
9546 end Process_Conditional_ABE_Instantiation
;
9548 -----------------------------------------------
9549 -- Process_Conditional_ABE_Instantiation_Ada --
9550 -----------------------------------------------
9552 procedure Process_Conditional_ABE_Instantiation_Ada
9553 (Exp_Inst
: Node_Id
;
9555 Inst_Attrs
: Instantiation_Attributes
;
9557 Gen_Attrs
: Target_Attributes
;
9558 State
: Processing_Attributes
)
9560 Check_OK
: constant Boolean :=
9561 not Inst_Attrs
.Ghost_Mode_Ignore
9562 and then not Gen_Attrs
.Ghost_Mode_Ignore
9563 and then Inst_Attrs
.Elab_Checks_OK
9564 and then Gen_Attrs
.Elab_Checks_OK
;
9565 -- A run-time ABE check may be installed only when both the instance and
9566 -- the generic have active elaboration checks and both are not ignored
9567 -- Ghost constructs.
9569 New_State
: Processing_Attributes
:= State
;
9570 -- Each step of the Processing phase constitutes a new state
9572 Root
: constant Node_Id
:= Root_Scenario
;
9575 -- Nothing to do when the instantiation is ABE-safe
9582 -- package body Gen is
9587 -- procedure Main is
9588 -- package Inst is new Gen (ABE); -- safe instantiation
9591 if Is_Safe_Instantiation
(Inst
, Gen_Attrs
) then
9594 -- The instantiation and the generic body are both in the main unit
9596 elsif Present
(Gen_Attrs
.Body_Decl
)
9597 and then In_Extended_Main_Code_Unit
(Gen_Attrs
.Body_Decl
)
9599 -- If the root scenario appears prior to the generic body, then this
9600 -- is a possible ABE with respect to the root scenario.
9607 -- function A ... is
9609 -- if Some_Condition then
9611 -- package Inst is new Gen; -- instantiation site
9615 -- X : ... := A; -- root scenario
9617 -- package body Gen is -- generic body
9621 -- Y : ... := A; -- root scenario
9623 -- IMPORTANT: The instantiation of Gen is a possible ABE for X, but
9624 -- not for Y. Installing an unconditional ABE raise prior to the
9625 -- instance site would be wrong as it will fail for Y as well, but in
9626 -- Y's case the instantiation of Gen is never an ABE.
9628 if Earlier_In_Extended_Unit
(Root
, Gen_Attrs
.Body_Decl
) then
9630 -- Do not emit any ABE diagnostics when the instantiation occurs
9631 -- in partial finalization context because this leads to unwanted
9634 if State
.Within_Partial_Finalization
then
9637 -- ABE diagnostics are emitted only in the static model because
9638 -- there is a well-defined order to visiting scenarios. Without
9639 -- this order diagnostics appear jumbled and result in unwanted
9642 elsif Static_Elaboration_Checks
9643 and then Inst_Attrs
.Elab_Warnings_OK
9646 ("??cannot instantiate & before body seen", Inst
, Gen_Id
);
9647 Error_Msg_N
("\Program_Error may be raised at run time", Inst
);
9649 Output_Active_Scenarios
(Inst
);
9652 -- Install a conditional run-time ABE check to verify that the
9653 -- generic body has been elaborated prior to the instantiation.
9658 Ins_Nod
=> Exp_Inst
,
9659 Target_Id
=> Gen_Attrs
.Spec_Id
,
9660 Target_Decl
=> Gen_Attrs
.Spec_Decl
,
9661 Target_Body
=> Gen_Attrs
.Body_Decl
);
9663 -- Update the state of the Processing phase to indicate that
9664 -- no implicit Elaborate[_All] pragmas must be generated from
9672 -- function A ... is
9674 -- if Some_Condition then
9676 -- declare Inst is new Gen;
9682 -- package body Gen is
9684 -- External.Subp; -- imparts Elaborate_All
9687 -- If Some_Condition is True, then the ABE check will fail at
9688 -- runtime and the call to External.Subp will never take place,
9689 -- rendering the implicit Elaborate_All useless.
9691 -- If Some_Condition is False, then the call to External.Subp
9692 -- will never take place, rendering the implicit Elaborate_All
9695 New_State
.Suppress_Implicit_Pragmas
:= True;
9699 -- Otherwise the generic body is not available in this compilation or it
9700 -- resides in an external unit. Install a run-time ABE check to verify
9701 -- that the generic body has been elaborated prior to the instantiation
9702 -- when the dynamic model is in effect.
9704 elsif Dynamic_Elaboration_Checks
and then Check_OK
then
9707 Ins_Nod
=> Exp_Inst
,
9708 Id
=> Gen_Attrs
.Unit_Id
);
9711 -- Ensure that the unit with the generic body is elaborated prior to
9712 -- the main unit. No implicit pragma is generated if the instantiation
9713 -- has elaboration checks suppressed. This behaviour parallels that of
9714 -- the old ABE mechanism.
9716 if Inst_Attrs
.Elab_Checks_OK
then
9717 Ensure_Prior_Elaboration
9719 Unit_Id
=> Gen_Attrs
.Unit_Id
,
9720 Prag_Nam
=> Name_Elaborate
,
9721 State
=> New_State
);
9723 end Process_Conditional_ABE_Instantiation_Ada
;
9725 -------------------------------------------------
9726 -- Process_Conditional_ABE_Instantiation_SPARK --
9727 -------------------------------------------------
9729 procedure Process_Conditional_ABE_Instantiation_SPARK
9732 Gen_Attrs
: Target_Attributes
;
9733 State
: Processing_Attributes
)
9738 -- Ensure that a suitable elaboration model is in effect for SPARK rule
9741 Check_SPARK_Model_In_Effect
(Inst
);
9743 -- A source instantiation imposes an Elaborate[_All] requirement on the
9744 -- context of the main unit. Determine whether the context has a pragma
9745 -- strong enough to meet the requirement. The check is orthogonal to the
9746 -- ABE ramifications of the instantiation.
9748 -- IMPORTANT: This check must be performed only when -gnatd.v (enforce
9749 -- SPARK elaboration rules in SPARK code) is active because the static
9750 -- model can ensure the prior elaboration of the unit which contains a
9751 -- body by installing an implicit Elaborate[_All] pragma.
9753 if Debug_Flag_Dot_V
then
9754 if Nkind
(Inst
) = N_Package_Instantiation
then
9755 Req_Nam
:= Name_Elaborate_All
;
9757 Req_Nam
:= Name_Elaborate
;
9760 Meet_Elaboration_Requirement
9762 Target_Id
=> Gen_Id
,
9763 Req_Nam
=> Req_Nam
);
9765 -- Otherwise ensure that the unit with the target body is elaborated
9766 -- prior to the main unit.
9769 Ensure_Prior_Elaboration
9771 Unit_Id
=> Gen_Attrs
.Unit_Id
,
9772 Prag_Nam
=> Name_Elaborate
,
9775 end Process_Conditional_ABE_Instantiation_SPARK
;
9777 -------------------------------------------------
9778 -- Process_Conditional_ABE_Variable_Assignment --
9779 -------------------------------------------------
9781 procedure Process_Conditional_ABE_Variable_Assignment
(Asmt
: Node_Id
) is
9782 Var_Id
: constant Entity_Id
:= Entity
(Extract_Assignment_Name
(Asmt
));
9783 Prag
: constant Node_Id
:= SPARK_Pragma
(Var_Id
);
9785 SPARK_Rules_On
: Boolean;
9786 -- This flag is set when the SPARK rules are in effect
9789 -- The SPARK rules are in effect when both the assignment and the
9790 -- variable are subject to SPARK_Mode On.
9794 and then Get_SPARK_Mode_From_Annotation
(Prag
) = On
9795 and then Is_SPARK_Mode_On_Node
(Asmt
);
9797 -- Output relevant information when switch -gnatel (info messages on
9798 -- implicit Elaborate[_All] pragmas) is in effect.
9800 if Elab_Info_Messages
then
9802 (Msg
=> "assignment to & during elaboration",
9806 In_SPARK
=> SPARK_Rules_On
);
9809 -- The SPARK rules are in effect. These rules are applied regardless of
9810 -- whether -gnatd.v (enforce SPARK elaboration rules in SPARK code) is
9811 -- in effect because the static model cannot ensure safe assignment of
9814 if SPARK_Rules_On
then
9815 Process_Conditional_ABE_Variable_Assignment_SPARK
9819 -- Otherwise the Ada rules are in effect
9822 Process_Conditional_ABE_Variable_Assignment_Ada
9826 end Process_Conditional_ABE_Variable_Assignment
;
9828 -----------------------------------------------------
9829 -- Process_Conditional_ABE_Variable_Assignment_Ada --
9830 -----------------------------------------------------
9832 procedure Process_Conditional_ABE_Variable_Assignment_Ada
9836 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
9837 Spec_Id
: constant Entity_Id
:= Find_Top_Unit
(Var_Decl
);
9840 -- Emit a warning when an uninitialized variable declared in a package
9841 -- spec without a pragma Elaborate_Body is initialized by elaboration
9842 -- code within the corresponding body.
9844 if not Warnings_Off
(Var_Id
)
9845 and then not Is_Initialized
(Var_Decl
)
9846 and then not Has_Pragma_Elaborate_Body
(Spec_Id
)
9849 ("??variable & can be accessed by clients before this "
9850 & "initialization", Asmt
, Var_Id
);
9853 ("\add pragma ""Elaborate_Body"" to spec & to ensure proper "
9854 & "initialization", Asmt
, Spec_Id
);
9856 Output_Active_Scenarios
(Asmt
);
9858 -- Generate an implicit Elaborate_Body in the spec
9860 Set_Elaborate_Body_Desirable
(Spec_Id
);
9862 end Process_Conditional_ABE_Variable_Assignment_Ada
;
9864 -------------------------------------------------------
9865 -- Process_Conditional_ABE_Variable_Assignment_SPARK --
9866 -------------------------------------------------------
9868 procedure Process_Conditional_ABE_Variable_Assignment_SPARK
9872 Var_Decl
: constant Node_Id
:= Declaration_Node
(Var_Id
);
9873 Spec_Id
: constant Entity_Id
:= Find_Top_Unit
(Var_Decl
);
9876 -- Ensure that a suitable elaboration model is in effect for SPARK rule
9879 Check_SPARK_Model_In_Effect
(Asmt
);
9881 -- Emit an error when an initialized variable declared in a package spec
9882 -- without pragma Elaborate_Body is further modified by elaboration code
9883 -- within the corresponding body.
9885 if Is_Initialized
(Var_Decl
)
9886 and then not Has_Pragma_Elaborate_Body
(Spec_Id
)
9889 ("variable & modified by elaboration code in package body",
9893 ("\add pragma ""Elaborate_Body"" to spec & to ensure full "
9894 & "initialization", Asmt
, Spec_Id
);
9896 Output_Active_Scenarios
(Asmt
);
9898 end Process_Conditional_ABE_Variable_Assignment_SPARK
;
9900 ------------------------------------------------
9901 -- Process_Conditional_ABE_Variable_Reference --
9902 ------------------------------------------------
9904 procedure Process_Conditional_ABE_Variable_Reference
(Ref
: Node_Id
) is
9905 Var_Attrs
: Variable_Attributes
;
9909 Extract_Variable_Reference_Attributes
9912 Attrs
=> Var_Attrs
);
9914 if Is_Read
(Ref
) then
9915 Process_Conditional_ABE_Variable_Reference_Read
9918 Attrs
=> Var_Attrs
);
9920 end Process_Conditional_ABE_Variable_Reference
;
9922 -----------------------------------------------------
9923 -- Process_Conditional_ABE_Variable_Reference_Read --
9924 -----------------------------------------------------
9926 procedure Process_Conditional_ABE_Variable_Reference_Read
9929 Attrs
: Variable_Attributes
)
9932 -- Output relevant information when switch -gnatel (info messages on
9933 -- implicit Elaborate[_All] pragmas) is in effect.
9935 if Elab_Info_Messages
then
9937 (Msg
=> "read of variable & during elaboration",
9944 -- Nothing to do when the variable appears within the main unit because
9945 -- diagnostics on reads are relevant only for external variables.
9947 if Is_Same_Unit
(Attrs
.Unit_Id
, Cunit_Entity
(Main_Unit
)) then
9950 -- Nothing to do when the variable is already initialized. Note that the
9951 -- variable may be further modified by the external unit.
9953 elsif Is_Initialized
(Declaration_Node
(Var_Id
)) then
9956 -- Nothing to do when the external unit guarantees the initialization of
9957 -- the variable by means of pragma Elaborate_Body.
9959 elsif Has_Pragma_Elaborate_Body
(Attrs
.Unit_Id
) then
9962 -- A variable read imposes an Elaborate requirement on the context of
9963 -- the main unit. Determine whether the context has a pragma strong
9964 -- enough to meet the requirement.
9967 Meet_Elaboration_Requirement
9969 Target_Id
=> Var_Id
,
9970 Req_Nam
=> Name_Elaborate
);
9972 end Process_Conditional_ABE_Variable_Reference_Read
;
9974 -----------------------------
9975 -- Process_Conditional_ABE --
9976 -----------------------------
9978 -- NOTE: The body of this routine is intentionally out of order because it
9979 -- invokes an instantiated subprogram (Process_Conditional_ABE_Activation).
9980 -- Placing the body in alphabetical order will result in a guaranteed ABE.
9982 procedure Process_Conditional_ABE
9984 State
: Processing_Attributes
:= Initial_State
)
9986 Call_Attrs
: Call_Attributes
;
9987 Target_Id
: Entity_Id
;
9990 -- Add the current scenario to the stack of active scenarios
9992 Push_Active_Scenario
(N
);
9996 if Is_Suitable_Access
(N
) then
9997 Process_Conditional_ABE_Access
10001 -- Activations and calls
10003 elsif Is_Suitable_Call
(N
) then
10005 -- In general, only calls found within the main unit are processed
10006 -- because the ALI information supplied to binde is for the main
10007 -- unit only. However, to preserve the consistency of the tree and
10008 -- ensure proper serialization of internal names, external calls
10009 -- also receive corresponding call markers (see Build_Call_Marker).
10010 -- Regardless of the reason, external calls must not be processed.
10012 if In_Main_Context
(N
) then
10013 Extract_Call_Attributes
10015 Target_Id
=> Target_Id
,
10016 Attrs
=> Call_Attrs
);
10018 if Is_Activation_Proc
(Target_Id
) then
10019 Process_Conditional_ABE_Activation
10021 Call_Attrs
=> Call_Attrs
,
10025 Process_Conditional_ABE_Call
10027 Call_Attrs
=> Call_Attrs
,
10028 Target_Id
=> Target_Id
,
10035 elsif Is_Suitable_Instantiation
(N
) then
10036 Process_Conditional_ABE_Instantiation
10040 -- Variable assignments
10042 elsif Is_Suitable_Variable_Assignment
(N
) then
10043 Process_Conditional_ABE_Variable_Assignment
(N
);
10045 -- Variable references
10047 elsif Is_Suitable_Variable_Reference
(N
) then
10049 -- In general, only variable references found within the main unit
10050 -- are processed because the ALI information supplied to binde is for
10051 -- the main unit only. However, to preserve the consistency of the
10052 -- tree and ensure proper serialization of internal names, external
10053 -- variable references also receive corresponding variable reference
10054 -- markers (see Build_Varaible_Reference_Marker). Regardless of the
10055 -- reason, external variable references must not be processed.
10057 if In_Main_Context
(N
) then
10058 Process_Conditional_ABE_Variable_Reference
(N
);
10062 -- Remove the current scenario from the stack of active scenarios once
10063 -- all ABE diagnostics and checks have been performed.
10065 Pop_Active_Scenario
(N
);
10066 end Process_Conditional_ABE
;
10068 --------------------------------------------
10069 -- Process_Guaranteed_ABE_Activation_Impl --
10070 --------------------------------------------
10072 procedure Process_Guaranteed_ABE_Activation_Impl
10074 Call_Attrs
: Call_Attributes
;
10075 Obj_Id
: Entity_Id
;
10076 Task_Attrs
: Task_Attributes
;
10077 State
: Processing_Attributes
)
10079 pragma Unreferenced
(State
);
10081 Check_OK
: constant Boolean :=
10082 not Is_Ignored_Ghost_Entity
(Obj_Id
)
10083 and then not Task_Attrs
.Ghost_Mode_Ignore
10084 and then Is_Elaboration_Checks_OK_Id
(Obj_Id
)
10085 and then Task_Attrs
.Elab_Checks_OK
;
10086 -- A run-time ABE check may be installed only when the object and the
10087 -- task type have active elaboration checks, and both are not ignored
10088 -- Ghost constructs.
10091 -- Nothing to do when the root scenario appears at the declaration
10092 -- level and the task is in the same unit, but outside this context.
10094 -- task type Task_Typ; -- task declaration
10096 -- procedure Proc is
10097 -- function A ... is
10099 -- if Some_Condition then
10103 -- <activation call> -- activation site
10108 -- X : ... := A; -- root scenario
10111 -- task body Task_Typ is
10115 -- In the example above, the context of X is the declarative list of
10116 -- Proc. The "elaboration" of X may reach the activation of T whose body
10117 -- is defined outside of X's context. The task body is relevant only
10118 -- when Proc is invoked, but this happens only in "normal" elaboration,
10119 -- therefore the task body must not be considered if this is not the
10122 -- Performance note: parent traversal
10124 if Is_Up_Level_Target
(Task_Attrs
.Task_Decl
) then
10127 -- Nothing to do when the activation is ABE-safe
10131 -- task type Task_Typ;
10134 -- package body Gen is
10135 -- task body Task_Typ is
10142 -- procedure Main is
10143 -- package Nested is
10144 -- package Inst is new Gen;
10145 -- T : Inst.Task_Typ;
10146 -- end Nested; -- safe activation
10149 elsif Is_Safe_Activation
(Call
, Task_Attrs
.Task_Decl
) then
10152 -- An activation call leads to a guaranteed ABE when the activation
10153 -- call and the task appear within the same context ignoring library
10154 -- levels, and the body of the task has not been seen yet or appears
10155 -- after the activation call.
10157 -- procedure Guaranteed_ABE is
10158 -- task type Task_Typ;
10160 -- package Nested is
10162 -- <activation call> -- guaranteed ABE
10165 -- task body Task_Typ is
10170 -- Performance note: parent traversal
10172 elsif Is_Guaranteed_ABE
10174 Target_Decl
=> Task_Attrs
.Task_Decl
,
10175 Target_Body
=> Task_Attrs
.Body_Decl
)
10177 if Call_Attrs
.Elab_Warnings_OK
then
10178 Error_Msg_Sloc
:= Sloc
(Call
);
10180 ("??task & will be activated # before elaboration of its body",
10182 Error_Msg_N
("\Program_Error will be raised at run time", Obj_Id
);
10185 -- Mark the activation call as a guaranteed ABE
10187 Set_Is_Known_Guaranteed_ABE
(Call
);
10189 -- Install a run-time ABE failue because this activation call will
10190 -- always result in an ABE.
10193 Install_ABE_Failure
10198 end Process_Guaranteed_ABE_Activation_Impl
;
10200 procedure Process_Guaranteed_ABE_Activation
is
10201 new Process_Activation_Generic
(Process_Guaranteed_ABE_Activation_Impl
);
10203 ---------------------------------
10204 -- Process_Guaranteed_ABE_Call --
10205 ---------------------------------
10207 procedure Process_Guaranteed_ABE_Call
10209 Call_Attrs
: Call_Attributes
;
10210 Target_Id
: Entity_Id
)
10212 Target_Attrs
: Target_Attributes
;
10215 Extract_Target_Attributes
10216 (Target_Id
=> Target_Id
,
10217 Attrs
=> Target_Attrs
);
10219 -- Nothing to do when the root scenario appears at the declaration level
10220 -- and the target is in the same unit, but outside this context.
10222 -- function B ...; -- target declaration
10224 -- procedure Proc is
10225 -- function A ... is
10227 -- if Some_Condition then
10228 -- return B; -- call site
10232 -- X : ... := A; -- root scenario
10235 -- function B ... is
10239 -- In the example above, the context of X is the declarative region of
10240 -- Proc. The "elaboration" of X may eventually reach B which is defined
10241 -- outside of X's context. B is relevant only when Proc is invoked, but
10242 -- this happens only by means of "normal" elaboration, therefore B must
10243 -- not be considered if this is not the case.
10245 -- Performance note: parent traversal
10247 if Is_Up_Level_Target
(Target_Attrs
.Spec_Decl
) then
10250 -- Nothing to do when the call is ABE-safe
10253 -- function Gen ...;
10255 -- function Gen ... is
10261 -- procedure Main is
10262 -- function Inst is new Gen;
10263 -- X : ... := Inst; -- safe call
10266 elsif Is_Safe_Call
(Call
, Target_Attrs
) then
10269 -- A call leads to a guaranteed ABE when the call and the target appear
10270 -- within the same context ignoring library levels, and the body of the
10271 -- target has not been seen yet or appears after the call.
10273 -- procedure Guaranteed_ABE is
10274 -- function Func ...;
10276 -- package Nested is
10277 -- Obj : ... := Func; -- guaranteed ABE
10280 -- function Func ... is
10285 -- Performance note: parent traversal
10287 elsif Is_Guaranteed_ABE
10289 Target_Decl
=> Target_Attrs
.Spec_Decl
,
10290 Target_Body
=> Target_Attrs
.Body_Decl
)
10292 if Call_Attrs
.Elab_Warnings_OK
then
10293 Error_Msg_NE
("??cannot call & before body seen", Call
, Target_Id
);
10294 Error_Msg_N
("\Program_Error will be raised at run time", Call
);
10297 -- Mark the call as a guarnateed ABE
10299 Set_Is_Known_Guaranteed_ABE
(Call
);
10301 -- Install a run-time ABE failure because the call will always result
10302 -- in an ABE. The failure is installed when both the call and target
10303 -- have enabled elaboration checks, and both are not ignored Ghost
10306 if Call_Attrs
.Elab_Checks_OK
10307 and then Target_Attrs
.Elab_Checks_OK
10308 and then not Call_Attrs
.Ghost_Mode_Ignore
10309 and then not Target_Attrs
.Ghost_Mode_Ignore
10311 Install_ABE_Failure
10316 end Process_Guaranteed_ABE_Call
;
10318 ------------------------------------------
10319 -- Process_Guaranteed_ABE_Instantiation --
10320 ------------------------------------------
10322 procedure Process_Guaranteed_ABE_Instantiation
(Exp_Inst
: Node_Id
) is
10323 Gen_Attrs
: Target_Attributes
;
10324 Gen_Id
: Entity_Id
;
10326 Inst_Attrs
: Instantiation_Attributes
;
10327 Inst_Id
: Entity_Id
;
10330 Extract_Instantiation_Attributes
10331 (Exp_Inst
=> Exp_Inst
,
10333 Inst_Id
=> Inst_Id
,
10335 Attrs
=> Inst_Attrs
);
10337 Extract_Target_Attributes
(Gen_Id
, Gen_Attrs
);
10339 -- Nothing to do when the root scenario appears at the declaration level
10340 -- and the generic is in the same unit, but outside this context.
10343 -- procedure Gen is ...; -- generic declaration
10345 -- procedure Proc is
10346 -- function A ... is
10348 -- if Some_Condition then
10350 -- procedure I is new Gen; -- instantiation site
10355 -- X : ... := A; -- root scenario
10358 -- procedure Gen is
10362 -- In the example above, the context of X is the declarative region of
10363 -- Proc. The "elaboration" of X may eventually reach Gen which appears
10364 -- outside of X's context. Gen is relevant only when Proc is invoked,
10365 -- but this happens only by means of "normal" elaboration, therefore
10366 -- Gen must not be considered if this is not the case.
10368 -- Performance note: parent traversal
10370 if Is_Up_Level_Target
(Gen_Attrs
.Spec_Decl
) then
10373 -- Nothing to do when the instantiation is ABE-safe
10380 -- package body Gen is
10385 -- procedure Main is
10386 -- package Inst is new Gen (ABE); -- safe instantiation
10389 elsif Is_Safe_Instantiation
(Inst
, Gen_Attrs
) then
10392 -- An instantiation leads to a guaranteed ABE when the instantiation and
10393 -- the generic appear within the same context ignoring library levels,
10394 -- and the body of the generic has not been seen yet or appears after
10395 -- the instantiation.
10397 -- procedure Guaranteed_ABE is
10401 -- package Nested is
10402 -- procedure Inst is new Gen; -- guaranteed ABE
10405 -- procedure Gen is
10410 -- Performance note: parent traversal
10412 elsif Is_Guaranteed_ABE
10414 Target_Decl
=> Gen_Attrs
.Spec_Decl
,
10415 Target_Body
=> Gen_Attrs
.Body_Decl
)
10417 if Inst_Attrs
.Elab_Warnings_OK
then
10419 ("??cannot instantiate & before body seen", Inst
, Gen_Id
);
10420 Error_Msg_N
("\Program_Error will be raised at run time", Inst
);
10423 -- Mark the instantiation as a guarantee ABE. This automatically
10424 -- suppresses the instantiation of the generic body.
10426 Set_Is_Known_Guaranteed_ABE
(Inst
);
10428 -- Install a run-time ABE failure because the instantiation will
10429 -- always result in an ABE. The failure is installed when both the
10430 -- instance and the generic have enabled elaboration checks, and both
10431 -- are not ignored Ghost constructs.
10433 if Inst_Attrs
.Elab_Checks_OK
10434 and then Gen_Attrs
.Elab_Checks_OK
10435 and then not Inst_Attrs
.Ghost_Mode_Ignore
10436 and then not Gen_Attrs
.Ghost_Mode_Ignore
10438 Install_ABE_Failure
10440 Ins_Nod
=> Exp_Inst
);
10443 end Process_Guaranteed_ABE_Instantiation
;
10445 ----------------------------
10446 -- Process_Guaranteed_ABE --
10447 ----------------------------
10449 -- NOTE: The body of this routine is intentionally out of order because it
10450 -- invokes an instantiated subprogram (Process_Guaranteed_ABE_Activation).
10451 -- Placing the body in alphabetical order will result in a guaranteed ABE.
10453 procedure Process_Guaranteed_ABE
(N
: Node_Id
) is
10454 Call_Attrs
: Call_Attributes
;
10455 Target_Id
: Entity_Id
;
10458 -- Add the current scenario to the stack of active scenarios
10460 Push_Active_Scenario
(N
);
10462 -- Only calls, instantiations, and task activations may result in a
10465 if Is_Suitable_Call
(N
) then
10466 Extract_Call_Attributes
10468 Target_Id
=> Target_Id
,
10469 Attrs
=> Call_Attrs
);
10471 if Is_Activation_Proc
(Target_Id
) then
10472 Process_Guaranteed_ABE_Activation
10474 Call_Attrs
=> Call_Attrs
,
10475 State
=> Initial_State
);
10478 Process_Guaranteed_ABE_Call
10480 Call_Attrs
=> Call_Attrs
,
10481 Target_Id
=> Target_Id
);
10484 elsif Is_Suitable_Instantiation
(N
) then
10485 Process_Guaranteed_ABE_Instantiation
(N
);
10488 -- Remove the current scenario from the stack of active scenarios once
10489 -- all ABE diagnostics and checks have been performed.
10491 Pop_Active_Scenario
(N
);
10492 end Process_Guaranteed_ABE
;
10494 --------------------------
10495 -- Push_Active_Scenario --
10496 --------------------------
10498 procedure Push_Active_Scenario
(N
: Node_Id
) is
10500 Scenario_Stack
.Append
(N
);
10501 end Push_Active_Scenario
;
10503 ---------------------------------
10504 -- Record_Elaboration_Scenario --
10505 ---------------------------------
10507 procedure Record_Elaboration_Scenario
(N
: Node_Id
) is
10508 Level
: Enclosing_Level_Kind
;
10510 Any_Level_OK
: Boolean;
10511 -- This flag is set when a particular scenario is allowed to appear at
10514 Declaration_Level_OK
: Boolean;
10515 -- This flag is set when a particular scenario is allowed to appear at
10516 -- the declaration level.
10518 Library_Level_OK
: Boolean;
10519 -- This flag is set when a particular scenario is allowed to appear at
10520 -- the library level.
10523 -- Assume that the scenario cannot appear on any level
10525 Any_Level_OK
:= False;
10526 Declaration_Level_OK
:= False;
10527 Library_Level_OK
:= False;
10529 -- Nothing to do when switch -gnatH (legacy elaboration checking mode
10530 -- enabled) is in effect because the legacy ABE mechanism does not need
10531 -- to carry out this action.
10533 if Legacy_Elaboration_Checks
then
10536 -- Nothing to do for ASIS. As a result, no ABE checks and diagnostics
10537 -- are performed in this mode.
10539 elsif ASIS_Mode
then
10542 -- Nothing to do when the scenario is being preanalyzed
10544 elsif Preanalysis_Active
then
10548 -- Ensure that a library-level call does not appear in a preelaborated
10549 -- unit. The check must come before ignoring scenarios within external
10550 -- units or inside generics because calls in those context must also be
10553 if Is_Suitable_Call
(N
) then
10554 Check_Preelaborated_Call
(N
);
10557 -- Nothing to do when the scenario does not appear within the main unit
10559 if not In_Main_Context
(N
) then
10562 -- Scenarios within a generic unit are never considered because generics
10563 -- cannot be elaborated.
10565 elsif Inside_A_Generic
then
10568 -- Scenarios which do not fall in one of the elaboration categories
10569 -- listed below are not considered. The categories are:
10571 -- 'Access for entries, operators, and subprograms
10572 -- Assignments to variables
10573 -- Calls (includes task activation)
10576 -- Pragma Refined_State
10577 -- Reads of variables
10579 elsif Is_Suitable_Access
(N
) then
10580 Library_Level_OK
:= True;
10582 -- Signal any enclosing local exception handlers that the 'Access may
10583 -- raise Program_Error due to a failed ABE check when switch -gnatd.o
10584 -- (conservative elaboration order for indirect calls) is in effect.
10585 -- Marking the exception handlers ensures proper expansion by both
10586 -- the front and back end restriction when No_Exception_Propagation
10589 if Debug_Flag_Dot_O
then
10590 Possible_Local_Raise
(N
, Standard_Program_Error
);
10593 elsif Is_Suitable_Call
(N
) or else Is_Suitable_Instantiation
(N
) then
10594 Declaration_Level_OK
:= True;
10595 Library_Level_OK
:= True;
10597 -- Signal any enclosing local exception handlers that the call or
10598 -- instantiation may raise Program_Error due to a failed ABE check.
10599 -- Marking the exception handlers ensures proper expansion by both
10600 -- the front and back end restriction when No_Exception_Propagation
10603 Possible_Local_Raise
(N
, Standard_Program_Error
);
10605 elsif Is_Suitable_SPARK_Derived_Type
(N
) then
10606 Any_Level_OK
:= True;
10608 elsif Is_Suitable_SPARK_Refined_State_Pragma
(N
) then
10609 Library_Level_OK
:= True;
10611 elsif Is_Suitable_Variable_Assignment
(N
)
10612 or else Is_Suitable_Variable_Reference
(N
)
10614 Library_Level_OK
:= True;
10616 -- Otherwise the input does not denote a suitable scenario
10622 -- The static model imposes additional restrictions on the placement of
10623 -- scenarios. In contrast, the dynamic model assumes that every scenario
10624 -- will be elaborated or invoked at some point.
10626 if Static_Elaboration_Checks
then
10628 -- Certain scenarios are allowed to appear at any level. This check
10629 -- is performed here in order to save on a parent traversal.
10631 if Any_Level_OK
then
10634 -- Otherwise the scenario must appear at a specific level
10637 -- Performance note: parent traversal
10639 Level
:= Find_Enclosing_Level
(N
);
10641 -- Declaration-level scenario
10643 if Declaration_Level_OK
and then Level
= Declaration_Level
then
10646 -- Library-level or instantiation scenario
10648 elsif Library_Level_OK
10649 and then Level
in Library_Or_Instantiation_Level
10653 -- Otherwise the scenario does not appear at the proper level and
10654 -- cannot possibly act as a top-level scenario.
10662 -- Derived types subject to SPARK_Mode On require elaboration-related
10663 -- checks even though the type may not be declared within elaboration
10664 -- code. The types are recorded in a separate table which is examined
10665 -- during the Processing phase. Note that the checks must be delayed
10666 -- because the bodies of overriding primitives are not available yet.
10668 if Is_Suitable_SPARK_Derived_Type
(N
) then
10669 Record_SPARK_Elaboration_Scenario
(N
);
10671 -- Nothing left to do for derived types
10675 -- Instantiations of generics both subject to SPARK_Mode On require
10676 -- elaboration-related checks even though the instantiations may not
10677 -- appear within elaboration code. The instantiations are recored in
10678 -- a separate table which is examined during the Procesing phase. Note
10679 -- that the checks must be delayed because it is not known yet whether
10680 -- the generic unit has a body or not.
10682 -- IMPORTANT: A SPARK instantiation is also a normal instantiation which
10683 -- is subject to common conditional and guaranteed ABE checks.
10685 elsif Is_Suitable_SPARK_Instantiation
(N
) then
10686 Record_SPARK_Elaboration_Scenario
(N
);
10688 -- External constituents that refine abstract states which appear in
10689 -- pragma Initializes require elaboration-related checks even though
10690 -- a Refined_State pragma lacks any elaboration semantic.
10692 elsif Is_Suitable_SPARK_Refined_State_Pragma
(N
) then
10693 Record_SPARK_Elaboration_Scenario
(N
);
10695 -- Nothing left to do for pragma Refined_State
10700 -- Perform early detection of guaranteed ABEs in order to suppress the
10701 -- instantiation of generic bodies as gigi cannot handle certain types
10702 -- of premature instantiations.
10704 Process_Guaranteed_ABE
(N
);
10706 -- At this point all checks have been performed. Record the scenario for
10707 -- later processing by the ABE phase.
10709 Top_Level_Scenarios
.Append
(N
);
10710 Set_Is_Recorded_Top_Level_Scenario
(N
);
10711 end Record_Elaboration_Scenario
;
10713 ---------------------------------------
10714 -- Record_SPARK_Elaboration_Scenario --
10715 ---------------------------------------
10717 procedure Record_SPARK_Elaboration_Scenario
(N
: Node_Id
) is
10719 SPARK_Scenarios
.Append
(N
);
10720 Set_Is_Recorded_SPARK_Scenario
(N
);
10721 end Record_SPARK_Elaboration_Scenario
;
10723 -----------------------------------
10724 -- Recorded_SPARK_Scenarios_Hash --
10725 -----------------------------------
10727 function Recorded_SPARK_Scenarios_Hash
10728 (Key
: Node_Id
) return Recorded_SPARK_Scenarios_Index
10732 Recorded_SPARK_Scenarios_Index
(Key
mod Recorded_SPARK_Scenarios_Max
);
10733 end Recorded_SPARK_Scenarios_Hash
;
10735 ---------------------------------------
10736 -- Recorded_Top_Level_Scenarios_Hash --
10737 ---------------------------------------
10739 function Recorded_Top_Level_Scenarios_Hash
10740 (Key
: Node_Id
) return Recorded_Top_Level_Scenarios_Index
10744 Recorded_Top_Level_Scenarios_Index
10745 (Key
mod Recorded_Top_Level_Scenarios_Max
);
10746 end Recorded_Top_Level_Scenarios_Hash
;
10748 --------------------------
10749 -- Reset_Visited_Bodies --
10750 --------------------------
10752 procedure Reset_Visited_Bodies
is
10754 if Visited_Bodies_In_Use
then
10755 Visited_Bodies_In_Use
:= False;
10756 Visited_Bodies
.Reset
;
10758 end Reset_Visited_Bodies
;
10760 -------------------
10761 -- Root_Scenario --
10762 -------------------
10764 function Root_Scenario
return Node_Id
is
10765 package Stack
renames Scenario_Stack
;
10768 -- Ensure that the scenario stack has at least one active scenario in
10769 -- it. The one at the bottom (index First) is the root scenario.
10771 pragma Assert
(Stack
.Last
>= Stack
.First
);
10772 return Stack
.Table
(Stack
.First
);
10775 ---------------------------
10776 -- Set_Early_Call_Region --
10777 ---------------------------
10779 procedure Set_Early_Call_Region
(Body_Id
: Entity_Id
; Start
: Node_Id
) is
10781 pragma Assert
(Ekind_In
(Body_Id
, E_Entry
,
10785 E_Subprogram_Body
));
10787 Early_Call_Regions_In_Use
:= True;
10788 Early_Call_Regions
.Set
(Body_Id
, Start
);
10789 end Set_Early_Call_Region
;
10791 ----------------------------
10792 -- Set_Elaboration_Status --
10793 ----------------------------
10795 procedure Set_Elaboration_Status
10796 (Unit_Id
: Entity_Id
;
10797 Val
: Elaboration_Attributes
)
10800 Elaboration_Statuses_In_Use
:= True;
10801 Elaboration_Statuses
.Set
(Unit_Id
, Val
);
10802 end Set_Elaboration_Status
;
10804 ------------------------------------
10805 -- Set_Is_Recorded_SPARK_Scenario --
10806 ------------------------------------
10808 procedure Set_Is_Recorded_SPARK_Scenario
10810 Val
: Boolean := True)
10813 Recorded_SPARK_Scenarios_In_Use
:= True;
10814 Recorded_SPARK_Scenarios
.Set
(N
, Val
);
10815 end Set_Is_Recorded_SPARK_Scenario
;
10817 ----------------------------------------
10818 -- Set_Is_Recorded_Top_Level_Scenario --
10819 ----------------------------------------
10821 procedure Set_Is_Recorded_Top_Level_Scenario
10823 Val
: Boolean := True)
10826 Recorded_Top_Level_Scenarios_In_Use
:= True;
10827 Recorded_Top_Level_Scenarios
.Set
(N
, Val
);
10828 end Set_Is_Recorded_Top_Level_Scenario
;
10830 -------------------------
10831 -- Set_Is_Visited_Body --
10832 -------------------------
10834 procedure Set_Is_Visited_Body
(Subp_Body
: Node_Id
) is
10836 Visited_Bodies_In_Use
:= True;
10837 Visited_Bodies
.Set
(Subp_Body
, True);
10838 end Set_Is_Visited_Body
;
10840 -------------------------------
10841 -- Static_Elaboration_Checks --
10842 -------------------------------
10844 function Static_Elaboration_Checks
return Boolean is
10846 return not Dynamic_Elaboration_Checks
;
10847 end Static_Elaboration_Checks
;
10849 -------------------
10850 -- Traverse_Body --
10851 -------------------
10853 procedure Traverse_Body
(N
: Node_Id
; State
: Processing_Attributes
) is
10854 procedure Find_And_Process_Nested_Scenarios
;
10855 pragma Inline
(Find_And_Process_Nested_Scenarios
);
10856 -- Examine the declarations and statements of subprogram body N for
10857 -- suitable scenarios. Save each discovered scenario and process it
10860 procedure Process_Nested_Scenarios
(Nested
: Elist_Id
);
10861 pragma Inline
(Process_Nested_Scenarios
);
10862 -- Invoke Process_Conditional_ABE on each individual scenario found in
10865 ---------------------------------------
10866 -- Find_And_Process_Nested_Scenarios --
10867 ---------------------------------------
10869 procedure Find_And_Process_Nested_Scenarios
is
10870 Body_Id
: constant Entity_Id
:= Defining_Entity
(N
);
10872 function Is_Potential_Scenario
10873 (Nod
: Node_Id
) return Traverse_Result
;
10874 -- Determine whether arbitrary node Nod denotes a suitable scenario.
10875 -- If it does, save it in the Nested_Scenarios list of the subprogram
10876 -- body, and process it.
10878 procedure Save_Scenario
(Nod
: Node_Id
);
10879 pragma Inline
(Save_Scenario
);
10880 -- Save scenario Nod in the Nested_Scenarios list of the subprogram
10883 procedure Traverse_List
(List
: List_Id
);
10884 pragma Inline
(Traverse_List
);
10885 -- Invoke Traverse_Potential_Scenarios on each node in list List
10887 procedure Traverse_Potential_Scenarios
is
10888 new Traverse_Proc
(Is_Potential_Scenario
);
10890 ---------------------------
10891 -- Is_Potential_Scenario --
10892 ---------------------------
10894 function Is_Potential_Scenario
10895 (Nod
: Node_Id
) return Traverse_Result
10900 -- Skip constructs which do not have elaboration of their own and
10901 -- need to be elaborated by other means such as invocation, task
10902 -- activation, etc.
10904 if Is_Non_Library_Level_Encapsulator
(Nod
) then
10907 -- Terminate the traversal of a task body with an accept statement
10908 -- when no entry calls in elaboration are allowed because the task
10909 -- will block at run-time and the remaining statements will not be
10912 elsif Nkind_In
(Original_Node
(Nod
), N_Accept_Statement
,
10913 N_Selective_Accept
)
10915 if Restriction_Active
(No_Entry_Calls_In_Elaboration_Code
) then
10918 -- The same behavior is achieved when switch -gnatd_a (stop
10919 -- elabortion checks on accept or select statement) is in
10922 elsif Debug_Flag_Underscore_A
then
10926 -- Certain nodes carry semantic lists which act as repositories
10927 -- until expansion transforms the node and relocates the contents.
10928 -- Examine these lists in case expansion is disabled.
10930 elsif Nkind_In
(Nod
, N_And_Then
, N_Or_Else
) then
10931 Traverse_List
(Actions
(Nod
));
10933 elsif Nkind_In
(Nod
, N_Elsif_Part
, N_Iteration_Scheme
) then
10934 Traverse_List
(Condition_Actions
(Nod
));
10936 elsif Nkind
(Nod
) = N_If_Expression
then
10937 Traverse_List
(Then_Actions
(Nod
));
10938 Traverse_List
(Else_Actions
(Nod
));
10940 elsif Nkind_In
(Nod
, N_Component_Association
,
10941 N_Iterated_Component_Association
)
10943 Traverse_List
(Loop_Actions
(Nod
));
10947 -- Save a suitable scenario in the Nested_Scenarios list of the
10948 -- subprogram body. As a result any subsequent traversals of the
10949 -- subprogram body started from a different top-level scenario no
10950 -- longer need to reexamine the tree.
10952 elsif Is_Suitable_Scenario
(Nod
) then
10953 Save_Scenario
(Nod
);
10955 Process_Conditional_ABE
10961 end Is_Potential_Scenario
;
10963 -------------------
10964 -- Save_Scenario --
10965 -------------------
10967 procedure Save_Scenario
(Nod
: Node_Id
) is
10971 Nested
:= Nested_Scenarios
(Body_Id
);
10973 if No
(Nested
) then
10974 Nested
:= New_Elmt_List
;
10975 Set_Nested_Scenarios
(Body_Id
, Nested
);
10978 Append_Elmt
(Nod
, Nested
);
10981 -------------------
10982 -- Traverse_List --
10983 -------------------
10985 procedure Traverse_List
(List
: List_Id
) is
10989 Item
:= First
(List
);
10990 while Present
(Item
) loop
10991 Traverse_Potential_Scenarios
(Item
);
10996 -- Start of processing for Find_And_Process_Nested_Scenarios
10999 -- Examine the declarations for suitable scenarios
11001 Traverse_List
(Declarations
(N
));
11003 -- Examine the handled sequence of statements. This also includes any
11004 -- exceptions handlers.
11006 Traverse_Potential_Scenarios
(Handled_Statement_Sequence
(N
));
11007 end Find_And_Process_Nested_Scenarios
;
11009 ------------------------------
11010 -- Process_Nested_Scenarios --
11011 ------------------------------
11013 procedure Process_Nested_Scenarios
(Nested
: Elist_Id
) is
11014 Nested_Elmt
: Elmt_Id
;
11017 Nested_Elmt
:= First_Elmt
(Nested
);
11018 while Present
(Nested_Elmt
) loop
11019 Process_Conditional_ABE
11020 (N
=> Node
(Nested_Elmt
),
11023 Next_Elmt
(Nested_Elmt
);
11025 end Process_Nested_Scenarios
;
11031 -- Start of processing for Traverse_Body
11034 -- Nothing to do when there is no body
11039 elsif Nkind
(N
) /= N_Subprogram_Body
then
11043 -- Nothing to do if the body was already traversed during the processing
11044 -- of the same top-level scenario.
11046 if Is_Visited_Body
(N
) then
11049 -- Otherwise mark the body as traversed
11052 Set_Is_Visited_Body
(N
);
11055 Nested
:= Nested_Scenarios
(Defining_Entity
(N
));
11057 -- The subprogram body was already examined as part of the elaboration
11058 -- graph starting from a different top-level scenario. There is no need
11059 -- to traverse the declarations and statements again because this will
11060 -- yield the exact same scenarios. Use the nested scenarios collected
11061 -- during the first inspection of the body.
11063 if Present
(Nested
) then
11064 Process_Nested_Scenarios
(Nested
);
11066 -- Otherwise examine the declarations and statements of the subprogram
11067 -- body for suitable scenarios, save and process them accordingly.
11070 Find_And_Process_Nested_Scenarios
;
11074 ---------------------------------
11075 -- Update_Elaboration_Scenario --
11076 ---------------------------------
11078 procedure Update_Elaboration_Scenario
(New_N
: Node_Id
; Old_N
: Node_Id
) is
11079 procedure Update_SPARK_Scenario
;
11080 pragma Inline
(Update_SPARK_Scenario
);
11081 -- Update the contents of table SPARK_Scenarios if Old_N is recorded
11084 procedure Update_Top_Level_Scenario
;
11085 pragma Inline
(Update_Top_Level_Scenario
);
11086 -- Update the contexts of table Top_Level_Scenarios if Old_N is recorded
11089 ---------------------------
11090 -- Update_SPARK_Scenario --
11091 ---------------------------
11093 procedure Update_SPARK_Scenario
is
11094 package Scenarios
renames SPARK_Scenarios
;
11097 if Is_Recorded_SPARK_Scenario
(Old_N
) then
11099 -- Performance note: list traversal
11101 for Index
in Scenarios
.First
.. Scenarios
.Last
loop
11102 if Scenarios
.Table
(Index
) = Old_N
then
11103 Scenarios
.Table
(Index
) := New_N
;
11105 -- The old SPARK scenario is no longer recorded, but the new
11108 Set_Is_Recorded_Top_Level_Scenario
(Old_N
, False);
11109 Set_Is_Recorded_Top_Level_Scenario
(New_N
);
11114 -- A recorded SPARK scenario must be in the table of recorded
11115 -- SPARK scenarios.
11117 pragma Assert
(False);
11119 end Update_SPARK_Scenario
;
11121 -------------------------------
11122 -- Update_Top_Level_Scenario --
11123 -------------------------------
11125 procedure Update_Top_Level_Scenario
is
11126 package Scenarios
renames Top_Level_Scenarios
;
11129 if Is_Recorded_Top_Level_Scenario
(Old_N
) then
11131 -- Performance note: list traversal
11133 for Index
in Scenarios
.First
.. Scenarios
.Last
loop
11134 if Scenarios
.Table
(Index
) = Old_N
then
11135 Scenarios
.Table
(Index
) := New_N
;
11137 -- The old top-level scenario is no longer recorded, but the
11140 Set_Is_Recorded_Top_Level_Scenario
(Old_N
, False);
11141 Set_Is_Recorded_Top_Level_Scenario
(New_N
);
11146 -- A recorded top-level scenario must be in the table of recorded
11147 -- top-level scenarios.
11149 pragma Assert
(False);
11151 end Update_Top_Level_Scenario
;
11153 -- Start of processing for Update_Elaboration_Requirement
11156 -- Nothing to do when the old and new scenarios are one and the same
11158 if Old_N
= New_N
then
11161 -- A scenario is being transformed by Atree.Rewrite. Update all relevant
11162 -- internal data structures to reflect this change. This ensures that a
11163 -- potential run-time conditional ABE check or a guaranteed ABE failure
11164 -- is inserted at the proper place in the tree.
11166 elsif Is_Scenario
(Old_N
) then
11167 Update_SPARK_Scenario
;
11168 Update_Top_Level_Scenario
;
11170 end Update_Elaboration_Scenario
;
11172 -------------------------
11173 -- Visited_Bodies_Hash --
11174 -------------------------
11176 function Visited_Bodies_Hash
(Key
: Node_Id
) return Visited_Bodies_Index
is
11178 return Visited_Bodies_Index
(Key
mod Visited_Bodies_Max
);
11179 end Visited_Bodies_Hash
;
11181 ---------------------------------------------------------------------------
11183 -- L E G A C Y A C C E S S B E F O R E E L A B O R A T I O N --
11185 -- M E C H A N I S M --
11187 ---------------------------------------------------------------------------
11189 -- This section contains the implementation of the pre-18.x legacy ABE
11190 -- mechanism. The mechanism can be activated using switch -gnatH (legacy
11191 -- elaboration checking mode enabled).
11193 -----------------------------
11194 -- Description of Approach --
11195 -----------------------------
11197 -- Every non-static call that is encountered by Sem_Res results in a call
11198 -- to Check_Elab_Call, with N being the call node, and Outer set to its
11199 -- default value of True. In addition X'Access is treated like a call
11200 -- for the access-to-procedure case, and in SPARK mode only we also
11201 -- check variable references.
11203 -- The goal of Check_Elab_Call is to determine whether or not the reference
11204 -- in question can generate an access before elaboration error (raising
11205 -- Program_Error) either by directly calling a subprogram whose body
11206 -- has not yet been elaborated, or indirectly, by calling a subprogram
11207 -- whose body has been elaborated, but which contains a call to such a
11210 -- In addition, in SPARK mode, we are checking for a variable reference in
11211 -- another package, which requires an explicit Elaborate_All pragma.
11213 -- The only references that we need to look at the outer level are
11214 -- references that occur in elaboration code. There are two cases. The
11215 -- reference can be at the outer level of elaboration code, or it can
11216 -- be within another unit, e.g. the elaboration code of a subprogram.
11218 -- In the case of an elaboration call at the outer level, we must trace
11219 -- all calls to outer level routines either within the current unit or to
11220 -- other units that are with'ed. For calls within the current unit, we can
11221 -- determine if the body has been elaborated or not, and if it has not,
11222 -- then a warning is generated.
11224 -- Note that there are two subcases. If the original call directly calls a
11225 -- subprogram whose body has not been elaborated, then we know that an ABE
11226 -- will take place, and we replace the call by a raise of Program_Error.
11227 -- If the call is indirect, then we don't know that the PE will be raised,
11228 -- since the call might be guarded by a conditional. In this case we set
11229 -- Do_Elab_Check on the call so that a dynamic check is generated, and
11230 -- output a warning.
11232 -- For calls to a subprogram in a with'ed unit or a 'Access or variable
11233 -- reference (SPARK mode case), we require that a pragma Elaborate_All
11234 -- or pragma Elaborate be present, or that the referenced unit have a
11235 -- pragma Preelaborate, pragma Pure, or pragma Elaborate_Body. If none
11236 -- of these conditions is met, then a warning is generated that a pragma
11237 -- Elaborate_All may be needed (error in the SPARK case), or an implicit
11238 -- pragma is generated.
11240 -- For the case of an elaboration call at some inner level, we are
11241 -- interested in tracing only calls to subprograms at the same level, i.e.
11242 -- those that can be called during elaboration. Any calls to outer level
11243 -- routines cannot cause ABE's as a result of the original call (there
11244 -- might be an outer level call to the subprogram from outside that causes
11245 -- the ABE, but that gets analyzed separately).
11247 -- Note that we never trace calls to inner level subprograms, since these
11248 -- cannot result in ABE's unless there is an elaboration problem at a lower
11249 -- level, which will be separately detected.
11251 -- Note on pragma Elaborate. The checking here assumes that a pragma
11252 -- Elaborate on a with'ed unit guarantees that subprograms within the unit
11253 -- can be called without causing an ABE. This is not in fact the case since
11254 -- pragma Elaborate does not guarantee the transitive coverage guaranteed
11255 -- by Elaborate_All. However, we decide to trust the user in this case.
11257 --------------------------------------
11258 -- Instantiation Elaboration Errors --
11259 --------------------------------------
11261 -- A special case arises when an instantiation appears in a context that is
11262 -- known to be before the body is elaborated, e.g.
11264 -- generic package x is ...
11266 -- package xx is new x;
11268 -- package body x is ...
11270 -- In this situation it is certain that an elaboration error will occur,
11271 -- and an unconditional raise Program_Error statement is inserted before
11272 -- the instantiation, and a warning generated.
11274 -- The problem is that in this case we have no place to put the body of
11275 -- the instantiation. We can't put it in the normal place, because it is
11276 -- too early, and will cause errors to occur as a result of referencing
11277 -- entities before they are declared.
11279 -- Our approach in this case is simply to avoid creating the body of the
11280 -- instantiation in such a case. The instantiation spec is modified to
11281 -- include dummy bodies for all subprograms, so that the resulting code
11282 -- does not contain subprogram specs with no corresponding bodies.
11284 -- The following table records the recursive call chain for output in the
11285 -- Output routine. Each entry records the call node and the entity of the
11286 -- called routine. The number of entries in the table (i.e. the value of
11287 -- Elab_Call.Last) indicates the current depth of recursion and is used to
11288 -- identify the outer level.
11290 type Elab_Call_Element
is record
11295 package Elab_Call
is new Table
.Table
11296 (Table_Component_Type
=> Elab_Call_Element
,
11297 Table_Index_Type
=> Int
,
11298 Table_Low_Bound
=> 1,
11299 Table_Initial
=> 50,
11300 Table_Increment
=> 100,
11301 Table_Name
=> "Elab_Call");
11303 -- The following table records all calls that have been processed starting
11304 -- from an outer level call. The table prevents both infinite recursion and
11305 -- useless reanalysis of calls within the same context. The use of context
11306 -- is important because it allows for proper checks in more complex code:
11309 -- Call; -- requires a check
11310 -- Call; -- does not need a check thanks to the table
11312 -- Call; -- requires a check, different context
11315 -- Call; -- requires a check, different context
11317 type Visited_Element
is record
11318 Subp_Id
: Entity_Id
;
11319 -- The entity of the subprogram being called
11322 -- The context where the call to the subprogram occurs
11325 package Elab_Visited
is new Table
.Table
11326 (Table_Component_Type
=> Visited_Element
,
11327 Table_Index_Type
=> Int
,
11328 Table_Low_Bound
=> 1,
11329 Table_Initial
=> 200,
11330 Table_Increment
=> 100,
11331 Table_Name
=> "Elab_Visited");
11333 -- The following table records delayed calls which must be examined after
11334 -- all generic bodies have been instantiated.
11336 type Delay_Element
is record
11338 -- The parameter N from the call to Check_Internal_Call. Note that this
11339 -- node may get rewritten over the delay period by expansion in the call
11340 -- case (but not in the instantiation case).
11343 -- The parameter E from the call to Check_Internal_Call
11345 Orig_Ent
: Entity_Id
;
11346 -- The parameter Orig_Ent from the call to Check_Internal_Call
11348 Curscop
: Entity_Id
;
11349 -- The current scope of the call. This is restored when we complete the
11350 -- delayed call, so that we do this in the right scope.
11352 Outer_Scope
: Entity_Id
;
11353 -- Save scope of outer level call
11355 From_Elab_Code
: Boolean;
11356 -- Save indication of whether this call is from elaboration code
11358 In_Task_Activation
: Boolean;
11359 -- Save indication of whether this call is from a task body. Tasks are
11360 -- activated at the "begin", which is after all local procedure bodies,
11361 -- so calls to those procedures can't fail, even if they occur after the
11364 From_SPARK_Code
: Boolean;
11365 -- Save indication of whether this call is under SPARK_Mode => On
11368 package Delay_Check
is new Table
.Table
11369 (Table_Component_Type
=> Delay_Element
,
11370 Table_Index_Type
=> Int
,
11371 Table_Low_Bound
=> 1,
11372 Table_Initial
=> 1000,
11373 Table_Increment
=> 100,
11374 Table_Name
=> "Delay_Check");
11376 C_Scope
: Entity_Id
;
11377 -- Top-level scope of current scope. Compute this only once at the outer
11378 -- level, i.e. for a call to Check_Elab_Call from outside this unit.
11380 Outer_Level_Sloc
: Source_Ptr
;
11381 -- Save Sloc value for outer level call node for comparisons of source
11382 -- locations. A body is too late if it appears after the *outer* level
11383 -- call, not the particular call that is being analyzed.
11385 From_Elab_Code
: Boolean;
11386 -- This flag shows whether the outer level call currently being examined
11387 -- is or is not in elaboration code. We are only interested in calls to
11388 -- routines in other units if this flag is True.
11390 In_Task_Activation
: Boolean := False;
11391 -- This flag indicates whether we are performing elaboration checks on task
11392 -- bodies, at the point of activation. If true, we do not raise
11393 -- Program_Error for calls to local procedures, because all local bodies
11394 -- are known to be elaborated. However, we still need to trace such calls,
11395 -- because a local procedure could call a procedure in another package,
11396 -- so we might need an implicit Elaborate_All.
11398 Delaying_Elab_Checks
: Boolean := True;
11399 -- This is set True till the compilation is complete, including the
11400 -- insertion of all instance bodies. Then when Check_Elab_Calls is called,
11401 -- the delay table is used to make the delayed calls and this flag is reset
11402 -- to False, so that the calls are processed.
11404 -----------------------
11405 -- Local Subprograms --
11406 -----------------------
11408 -- Note: Outer_Scope in all following specs represents the scope of
11409 -- interest of the outer level call. If it is set to Standard_Standard,
11410 -- then it means the outer level call was at elaboration level, and that
11411 -- thus all calls are of interest. If it was set to some other scope,
11412 -- then the original call was an inner call, and we are not interested
11413 -- in calls that go outside this scope.
11415 procedure Activate_Elaborate_All_Desirable
(N
: Node_Id
; U
: Entity_Id
);
11416 -- Analysis of construct N shows that we should set Elaborate_All_Desirable
11417 -- for the WITH clause for unit U (which will always be present). A special
11418 -- case is when N is a function or procedure instantiation, in which case
11419 -- it is sufficient to set Elaborate_Desirable, since in this case there is
11420 -- no possibility of transitive elaboration issues.
11422 procedure Check_A_Call
11425 Outer_Scope
: Entity_Id
;
11426 Inter_Unit_Only
: Boolean;
11427 Generate_Warnings
: Boolean := True;
11428 In_Init_Proc
: Boolean := False);
11429 -- This is the internal recursive routine that is called to check for
11430 -- possible elaboration error. The argument N is a subprogram call or
11431 -- generic instantiation, or 'Access attribute reference to be checked, and
11432 -- E is the entity of the called subprogram, or instantiated generic unit,
11433 -- or subprogram referenced by 'Access.
11435 -- In SPARK mode, N can also be a variable reference, since in SPARK this
11436 -- also triggers a requirement for Elaborate_All, and in this case E is the
11437 -- entity being referenced.
11439 -- Outer_Scope is the outer level scope for the original reference.
11440 -- Inter_Unit_Only is set if the call is only to be checked in the
11441 -- case where it is to another unit (and skipped if within a unit).
11442 -- Generate_Warnings is set to False to suppress warning messages about
11443 -- missing pragma Elaborate_All's. These messages are not wanted for
11444 -- inner calls in the dynamic model. Note that an instance of the Access
11445 -- attribute applied to a subprogram also generates a call to this
11446 -- procedure (since the referenced subprogram may be called later
11447 -- indirectly). Flag In_Init_Proc should be set whenever the current
11448 -- context is a type init proc.
11450 -- Note: this might better be called Check_A_Reference to recognize the
11451 -- variable case for SPARK, but we prefer to retain the historical name
11452 -- since in practice this is mostly about checking calls for the possible
11453 -- occurrence of an access-before-elaboration exception.
11455 procedure Check_Bad_Instantiation
(N
: Node_Id
);
11456 -- N is a node for an instantiation (if called with any other node kind,
11457 -- Check_Bad_Instantiation ignores the call). This subprogram checks for
11458 -- the special case of a generic instantiation of a generic spec in the
11459 -- same declarative part as the instantiation where a body is present and
11460 -- has not yet been seen. This is an obvious error, but needs to be checked
11461 -- specially at the time of the instantiation, since it is a case where we
11462 -- cannot insert the body anywhere. If this case is detected, warnings are
11463 -- generated, and a raise of Program_Error is inserted. In addition any
11464 -- subprograms in the generic spec are stubbed, and the Bad_Instantiation
11465 -- flag is set on the instantiation node. The caller in Sem_Ch12 uses this
11466 -- flag as an indication that no attempt should be made to insert an
11469 procedure Check_Internal_Call
11472 Outer_Scope
: Entity_Id
;
11473 Orig_Ent
: Entity_Id
);
11474 -- N is a function call or procedure statement call node and E is the
11475 -- entity of the called function, which is within the current compilation
11476 -- unit (where subunits count as part of the parent). This call checks if
11477 -- this call, or any call within any accessed body could cause an ABE, and
11478 -- if so, outputs a warning. Orig_Ent differs from E only in the case of
11479 -- renamings, and points to the original name of the entity. This is used
11480 -- for error messages. Outer_Scope is the outer level scope for the
11483 procedure Check_Internal_Call_Continue
11486 Outer_Scope
: Entity_Id
;
11487 Orig_Ent
: Entity_Id
);
11488 -- The processing for Check_Internal_Call is divided up into two phases,
11489 -- and this represents the second phase. The second phase is delayed if
11490 -- Delaying_Elab_Checks is set to True. In this delayed case, the first
11491 -- phase makes an entry in the Delay_Check table, which is processed when
11492 -- Check_Elab_Calls is called. N, E and Orig_Ent are as for the call to
11493 -- Check_Internal_Call. Outer_Scope is the outer level scope for the
11496 function Get_Referenced_Ent
(N
: Node_Id
) return Entity_Id
;
11497 -- N is either a function or procedure call or an access attribute that
11498 -- references a subprogram. This call retrieves the relevant entity. If
11499 -- this is a call to a protected subprogram, the entity is a selected
11500 -- component. The callable entity may be absent, in which case Empty is
11501 -- returned. This happens with non-analyzed calls in nested generics.
11503 -- If SPARK_Mode is On, then N can also be a reference to an E_Variable
11504 -- entity, in which case, the value returned is simply this entity.
11506 function Has_Generic_Body
(N
: Node_Id
) return Boolean;
11507 -- N is a generic package instantiation node, and this routine determines
11508 -- if this package spec does in fact have a generic body. If so, then
11509 -- True is returned, otherwise False. Note that this is not at all the
11510 -- same as checking if the unit requires a body, since it deals with
11511 -- the case of optional bodies accurately (i.e. if a body is optional,
11512 -- then it looks to see if a body is actually present). Note: this
11513 -- function can only do a fully correct job if in generating code mode
11514 -- where all bodies have to be present. If we are operating in semantics
11515 -- check only mode, then in some cases of optional bodies, a result of
11516 -- False may incorrectly be given. In practice this simply means that
11517 -- some cases of warnings for incorrect order of elaboration will only
11518 -- be given when generating code, which is not a big problem (and is
11519 -- inevitable, given the optional body semantics of Ada).
11521 procedure Insert_Elab_Check
(N
: Node_Id
; C
: Node_Id
:= Empty
);
11522 -- Given code for an elaboration check (or unconditional raise if the check
11523 -- is not needed), inserts the code in the appropriate place. N is the call
11524 -- or instantiation node for which the check code is required. C is the
11525 -- test whose failure triggers the raise.
11527 function Is_Call_Of_Generic_Formal
(N
: Node_Id
) return Boolean;
11528 -- Returns True if node N is a call to a generic formal subprogram
11530 function Is_Finalization_Procedure
(Id
: Entity_Id
) return Boolean;
11531 -- Determine whether entity Id denotes a [Deep_]Finalize procedure
11533 procedure Output_Calls
11535 Check_Elab_Flag
: Boolean);
11536 -- Outputs chain of calls stored in the Elab_Call table. The caller has
11537 -- already generated the main warning message, so the warnings generated
11538 -- are all continuation messages. The argument is the call node at which
11539 -- the messages are to be placed. When Check_Elab_Flag is set, calls are
11540 -- enumerated only when flag Elab_Warning is set for the dynamic case or
11541 -- when flag Elab_Info_Messages is set for the static case.
11543 function Same_Elaboration_Scope
(Scop1
, Scop2
: Entity_Id
) return Boolean;
11544 -- Given two scopes, determine whether they are the same scope from an
11545 -- elaboration point of view, i.e. packages and blocks are ignored.
11547 procedure Set_C_Scope
;
11548 -- On entry C_Scope is set to some scope. On return, C_Scope is reset
11549 -- to be the enclosing compilation unit of this scope.
11551 procedure Set_Elaboration_Constraint
11555 -- The current unit U may depend semantically on some unit P that is not
11556 -- in the current context. If there is an elaboration call that reaches P,
11557 -- we need to indicate that P requires an Elaborate_All, but this is not
11558 -- effective in U's ali file, if there is no with_clause for P. In this
11559 -- case we add the Elaborate_All on the unit Q that directly or indirectly
11560 -- makes P available. This can happen in two cases:
11562 -- a) Q declares a subtype of a type declared in P, and the call is an
11563 -- initialization call for an object of that subtype.
11565 -- b) Q declares an object of some tagged type whose root type is
11566 -- declared in P, and the initialization call uses object notation on
11567 -- that object to reach a primitive operation or a classwide operation
11570 -- If P appears in the context of U, the current processing is correct.
11571 -- Otherwise we must identify these two cases to retrieve Q and place the
11572 -- Elaborate_All_Desirable on it.
11574 function Spec_Entity
(E
: Entity_Id
) return Entity_Id
;
11575 -- Given a compilation unit entity, if it is a spec entity, it is returned
11576 -- unchanged. If it is a body entity, then the spec for the corresponding
11577 -- spec is returned
11579 function Within
(E1
, E2
: Entity_Id
) return Boolean;
11580 -- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one
11581 -- of its contained scopes, False otherwise.
11583 function Within_Elaborate_All
11584 (Unit
: Unit_Number_Type
;
11585 E
: Entity_Id
) return Boolean;
11586 -- Return True if we are within the scope of an Elaborate_All for E, or if
11587 -- we are within the scope of an Elaborate_All for some other unit U, and U
11588 -- with's E. This prevents spurious warnings when the called entity is
11589 -- renamed within U, or in case of generic instances.
11591 --------------------------------------
11592 -- Activate_Elaborate_All_Desirable --
11593 --------------------------------------
11595 procedure Activate_Elaborate_All_Desirable
(N
: Node_Id
; U
: Entity_Id
) is
11596 UN
: constant Unit_Number_Type
:= Get_Code_Unit
(N
);
11597 CU
: constant Node_Id
:= Cunit
(UN
);
11598 UE
: constant Entity_Id
:= Cunit_Entity
(UN
);
11599 Unm
: constant Unit_Name_Type
:= Unit_Name
(UN
);
11600 CI
: constant List_Id
:= Context_Items
(CU
);
11604 procedure Add_To_Context_And_Mark
(Itm
: Node_Id
);
11605 -- This procedure is called when the elaborate indication must be
11606 -- applied to a unit not in the context of the referencing unit. The
11607 -- unit gets added to the context as an implicit with.
11609 function In_Withs_Of
(UEs
: Entity_Id
) return Boolean;
11610 -- UEs is the spec entity of a unit. If the unit to be marked is
11611 -- in the context item list of this unit spec, then the call returns
11612 -- True and Itm is left set to point to the relevant N_With_Clause node.
11614 procedure Set_Elab_Flag
(Itm
: Node_Id
);
11615 -- Sets Elaborate_[All_]Desirable as appropriate on Itm
11617 -----------------------------
11618 -- Add_To_Context_And_Mark --
11619 -----------------------------
11621 procedure Add_To_Context_And_Mark
(Itm
: Node_Id
) is
11622 CW
: constant Node_Id
:=
11623 Make_With_Clause
(Sloc
(Itm
),
11624 Name
=> Name
(Itm
));
11627 Set_Library_Unit
(CW
, Library_Unit
(Itm
));
11628 Set_Implicit_With
(CW
, True);
11630 -- Set elaborate all desirable on copy and then append the copy to
11631 -- the list of body with's and we are done.
11633 Set_Elab_Flag
(CW
);
11634 Append_To
(CI
, CW
);
11635 end Add_To_Context_And_Mark
;
11641 function In_Withs_Of
(UEs
: Entity_Id
) return Boolean is
11642 UNs
: constant Unit_Number_Type
:= Get_Source_Unit
(UEs
);
11643 CUs
: constant Node_Id
:= Cunit
(UNs
);
11644 CIs
: constant List_Id
:= Context_Items
(CUs
);
11647 Itm
:= First
(CIs
);
11648 while Present
(Itm
) loop
11649 if Nkind
(Itm
) = N_With_Clause
then
11651 Cunit_Entity
(Get_Cunit_Unit_Number
(Library_Unit
(Itm
)));
11664 -------------------
11665 -- Set_Elab_Flag --
11666 -------------------
11668 procedure Set_Elab_Flag
(Itm
: Node_Id
) is
11670 if Nkind
(N
) in N_Subprogram_Instantiation
then
11671 Set_Elaborate_Desirable
(Itm
);
11673 Set_Elaborate_All_Desirable
(Itm
);
11677 -- Start of processing for Activate_Elaborate_All_Desirable
11680 -- Do not set binder indication if expansion is disabled, as when
11681 -- compiling a generic unit.
11683 if not Expander_Active
then
11687 -- If an instance of a generic package contains a controlled object (so
11688 -- we're calling Initialize at elaboration time), and the instance is in
11689 -- a package body P that says "with P;", then we need to return without
11690 -- adding "pragma Elaborate_All (P);" to P.
11692 if U
= Main_Unit_Entity
then
11697 while Present
(Itm
) loop
11698 if Nkind
(Itm
) = N_With_Clause
then
11699 Ent
:= Cunit_Entity
(Get_Cunit_Unit_Number
(Library_Unit
(Itm
)));
11701 -- If we find it, then mark elaborate all desirable and return
11704 Set_Elab_Flag
(Itm
);
11712 -- If we fall through then the with clause is not present in the
11713 -- current unit. One legitimate possibility is that the with clause
11714 -- is present in the spec when we are a body.
11716 if Is_Body_Name
(Unm
)
11717 and then In_Withs_Of
(Spec_Entity
(UE
))
11719 Add_To_Context_And_Mark
(Itm
);
11723 -- Similarly, we may be in the spec or body of a child unit, where
11724 -- the unit in question is with'ed by some ancestor of the child unit.
11726 if Is_Child_Name
(Unm
) then
11733 Pkg
:= Scope
(Pkg
);
11734 exit when Pkg
= Standard_Standard
;
11736 if In_Withs_Of
(Pkg
) then
11737 Add_To_Context_And_Mark
(Itm
);
11744 -- Here if we do not find with clause on spec or body. We just ignore
11745 -- this case; it means that the elaboration involves some other unit
11746 -- than the unit being compiled, and will be caught elsewhere.
11747 end Activate_Elaborate_All_Desirable
;
11753 procedure Check_A_Call
11756 Outer_Scope
: Entity_Id
;
11757 Inter_Unit_Only
: Boolean;
11758 Generate_Warnings
: Boolean := True;
11759 In_Init_Proc
: Boolean := False)
11761 Access_Case
: constant Boolean := Nkind
(N
) = N_Attribute_Reference
;
11762 -- Indicates if we have Access attribute case
11764 function Call_To_Instance_From_Outside
(Id
: Entity_Id
) return Boolean;
11765 -- True if we're calling an instance of a generic subprogram, or a
11766 -- subprogram in an instance of a generic package, and the call is
11767 -- outside that instance.
11769 procedure Elab_Warning
11772 Ent
: Node_Or_Entity_Id
);
11773 -- Generate a call to Error_Msg_NE with parameters Msg_D or Msg_S (for
11774 -- dynamic or static elaboration model), N and Ent. Msg_D is a real
11775 -- warning (output if Msg_D is non-null and Elab_Warnings is set),
11776 -- Msg_S is an info message (output if Elab_Info_Messages is set).
11778 function Find_W_Scope
return Entity_Id
;
11779 -- Find top-level scope for called entity (not following renamings
11780 -- or derivations). This is where the Elaborate_All will go if it is
11781 -- needed. We start with the called entity, except in the case of an
11782 -- initialization procedure outside the current package, where the init
11783 -- proc is in the root package, and we start from the entity of the name
11786 -----------------------------------
11787 -- Call_To_Instance_From_Outside --
11788 -----------------------------------
11790 function Call_To_Instance_From_Outside
(Id
: Entity_Id
) return Boolean is
11791 Scop
: Entity_Id
:= Id
;
11795 if Scop
= Standard_Standard
then
11799 if Is_Generic_Instance
(Scop
) then
11800 return not In_Open_Scopes
(Scop
);
11803 Scop
:= Scope
(Scop
);
11805 end Call_To_Instance_From_Outside
;
11811 procedure Elab_Warning
11814 Ent
: Node_Or_Entity_Id
)
11817 -- Dynamic elaboration checks, real warning
11819 if Dynamic_Elaboration_Checks
then
11820 if not Access_Case
then
11821 if Msg_D
/= "" and then Elab_Warnings
then
11822 Error_Msg_NE
(Msg_D
, N
, Ent
);
11825 -- In the access case emit first warning message as well,
11826 -- otherwise list of calls will appear as errors.
11828 elsif Elab_Warnings
then
11829 Error_Msg_NE
(Msg_S
, N
, Ent
);
11832 -- Static elaboration checks, info message
11835 if Elab_Info_Messages
then
11836 Error_Msg_NE
(Msg_S
, N
, Ent
);
11845 function Find_W_Scope
return Entity_Id
is
11846 Refed_Ent
: constant Entity_Id
:= Get_Referenced_Ent
(N
);
11847 W_Scope
: Entity_Id
;
11850 if Is_Init_Proc
(Refed_Ent
)
11851 and then not In_Same_Extended_Unit
(N
, Refed_Ent
)
11853 W_Scope
:= Scope
(Refed_Ent
);
11858 -- Now loop through scopes to get to the enclosing compilation unit
11860 while not Is_Compilation_Unit
(W_Scope
) loop
11861 W_Scope
:= Scope
(W_Scope
);
11869 Inst_Case
: constant Boolean := Nkind
(N
) in N_Generic_Instantiation
;
11870 -- Indicates if we have instantiation case
11872 Loc
: constant Source_Ptr
:= Sloc
(N
);
11874 Variable_Case
: constant Boolean :=
11875 Nkind
(N
) in N_Has_Entity
11876 and then Present
(Entity
(N
))
11877 and then Ekind
(Entity
(N
)) = E_Variable
;
11878 -- Indicates if we have variable reference case
11880 W_Scope
: constant Entity_Id
:= Find_W_Scope
;
11881 -- Top-level scope of directly called entity for subprogram. This
11882 -- differs from E_Scope in the case where renamings or derivations
11883 -- are involved, since it does not follow these links. W_Scope is
11884 -- generally in a visible unit, and it is this scope that may require
11885 -- an Elaborate_All. However, there are some cases (initialization
11886 -- calls and calls involving object notation) where W_Scope might not
11887 -- be in the context of the current unit, and there is an intermediate
11888 -- package that is, in which case the Elaborate_All has to be placed
11889 -- on this intermediate package. These special cases are handled in
11890 -- Set_Elaboration_Constraint.
11893 Callee_Unit_Internal
: Boolean;
11894 Caller_Unit_Internal
: Boolean;
11896 Inst_Callee
: Source_Ptr
;
11897 Inst_Caller
: Source_Ptr
;
11898 Unit_Callee
: Unit_Number_Type
;
11899 Unit_Caller
: Unit_Number_Type
;
11901 Body_Acts_As_Spec
: Boolean;
11902 -- Set to true if call is to body acting as spec (no separate spec)
11904 Cunit_SC
: Boolean := False;
11905 -- Set to suppress dynamic elaboration checks where one of the
11906 -- enclosing scopes has Elaboration_Checks_Suppressed set, or else
11907 -- if a pragma Elaborate[_All] applies to that scope, in which case
11908 -- warnings on the scope are also suppressed. For the internal case,
11909 -- we ignore this flag.
11911 E_Scope
: Entity_Id
;
11912 -- Top-level scope of entity for called subprogram. This value includes
11913 -- following renamings and derivations, so this scope can be in a
11914 -- non-visible unit. This is the scope that is to be investigated to
11915 -- see whether an elaboration check is required.
11918 -- Flag set when the subprogram being invoked is the procedure generated
11919 -- for pragma Default_Initial_Condition.
11921 SPARK_Elab_Errors
: Boolean;
11922 -- Flag set when an entity is called or a variable is read during SPARK
11923 -- dynamic elaboration.
11925 -- Start of processing for Check_A_Call
11928 -- If the call is known to be within a local Suppress Elaboration
11929 -- pragma, nothing to check. This can happen in task bodies. But
11930 -- we ignore this for a call to a generic formal.
11932 if Nkind
(N
) in N_Subprogram_Call
11933 and then No_Elaboration_Check
(N
)
11934 and then not Is_Call_Of_Generic_Formal
(N
)
11938 -- If this is a rewrite of a Valid_Scalars attribute, then nothing to
11939 -- check, we don't mind in this case if the call occurs before the body
11940 -- since this is all generated code.
11942 elsif Nkind
(Original_Node
(N
)) = N_Attribute_Reference
11943 and then Attribute_Name
(Original_Node
(N
)) = Name_Valid_Scalars
11947 -- Intrinsics such as instances of Unchecked_Deallocation do not have
11948 -- any body, so elaboration checking is not needed, and would be wrong.
11950 elsif Is_Intrinsic_Subprogram
(E
) then
11953 -- Do not consider references to internal variables for SPARK semantics
11955 elsif Variable_Case
and then not Comes_From_Source
(E
) then
11959 -- Proceed with check
11963 -- For a variable reference, just set Body_Acts_As_Spec to False
11965 if Variable_Case
then
11966 Body_Acts_As_Spec
:= False;
11968 -- Additional checks for all other cases
11971 -- Go to parent for derived subprogram, or to original subprogram in
11972 -- the case of a renaming (Alias covers both these cases).
11975 if (Suppress_Elaboration_Warnings
(Ent
)
11976 or else Elaboration_Checks_Suppressed
(Ent
))
11977 and then (Inst_Case
or else No
(Alias
(Ent
)))
11982 -- Nothing to do for imported entities
11984 if Is_Imported
(Ent
) then
11988 exit when Inst_Case
or else No
(Alias
(Ent
));
11989 Ent
:= Alias
(Ent
);
11992 Decl
:= Unit_Declaration_Node
(Ent
);
11994 if Nkind
(Decl
) = N_Subprogram_Body
then
11995 Body_Acts_As_Spec
:= True;
11997 elsif Nkind_In
(Decl
, N_Subprogram_Declaration
,
11998 N_Subprogram_Body_Stub
)
12001 Body_Acts_As_Spec
:= False;
12003 -- If we have none of an instantiation, subprogram body or subprogram
12004 -- declaration, or in the SPARK case, a variable reference, then
12005 -- it is not a case that we want to check. (One case is a call to a
12006 -- generic formal subprogram, where we do not want the check in the
12016 if Elaboration_Checks_Suppressed
(E_Scope
)
12017 or else Suppress_Elaboration_Warnings
(E_Scope
)
12022 -- Exit when we get to compilation unit, not counting subunits
12024 exit when Is_Compilation_Unit
(E_Scope
)
12025 and then (Is_Child_Unit
(E_Scope
)
12026 or else Scope
(E_Scope
) = Standard_Standard
);
12028 pragma Assert
(E_Scope
/= Standard_Standard
);
12030 -- Move up a scope looking for compilation unit
12032 E_Scope
:= Scope
(E_Scope
);
12035 -- No checks needed for pure or preelaborated compilation units
12037 if Is_Pure
(E_Scope
) or else Is_Preelaborated
(E_Scope
) then
12041 -- If the generic entity is within a deeper instance than we are, then
12042 -- either the instantiation to which we refer itself caused an ABE, in
12043 -- which case that will be handled separately, or else we know that the
12044 -- body we need appears as needed at the point of the instantiation.
12045 -- However, this assumption is only valid if we are in static mode.
12047 if not Dynamic_Elaboration_Checks
12049 Instantiation_Depth
(Sloc
(Ent
)) > Instantiation_Depth
(Sloc
(N
))
12054 -- Do not give a warning for a package with no body
12056 if Ekind
(Ent
) = E_Generic_Package
and then not Has_Generic_Body
(N
) then
12060 -- Case of entity is in same unit as call or instantiation. In the
12061 -- instantiation case, W_Scope may be different from E_Scope; we want
12062 -- the unit in which the instantiation occurs, since we're analyzing
12063 -- based on the expansion.
12065 if W_Scope
= C_Scope
then
12066 if not Inter_Unit_Only
then
12067 Check_Internal_Call
(N
, Ent
, Outer_Scope
, E
);
12073 -- Case of entity is not in current unit (i.e. with'ed unit case)
12075 -- We are only interested in such calls if the outer call was from
12076 -- elaboration code, or if we are in Dynamic_Elaboration_Checks mode.
12078 if not From_Elab_Code
and then not Dynamic_Elaboration_Checks
then
12082 -- Nothing to do if some scope said that no checks were required
12088 -- Nothing to do for a generic instance, because a call to an instance
12089 -- cannot fail the elaboration check, because the body of the instance
12090 -- is always elaborated immediately after the spec.
12092 if Call_To_Instance_From_Outside
(Ent
) then
12096 -- Nothing to do if subprogram with no separate spec. However, a call
12097 -- to Deep_Initialize may result in a call to a user-defined Initialize
12098 -- procedure, which imposes a body dependency. This happens only if the
12099 -- type is controlled and the Initialize procedure is not inherited.
12101 if Body_Acts_As_Spec
then
12102 if Is_TSS
(Ent
, TSS_Deep_Initialize
) then
12104 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Ent
));
12108 if not Is_Controlled
(Typ
) then
12111 Init
:= Find_Prim_Op
(Typ
, Name_Initialize
);
12113 if Comes_From_Source
(Init
) then
12126 -- Check cases of internal units
12128 Callee_Unit_Internal
:= In_Internal_Unit
(E_Scope
);
12130 -- Do not give a warning if the with'ed unit is internal and this is
12131 -- the generic instantiation case (this saves a lot of hassle dealing
12132 -- with the Text_IO special child units)
12134 if Callee_Unit_Internal
and Inst_Case
then
12138 if C_Scope
= Standard_Standard
then
12139 Caller_Unit_Internal
:= False;
12141 Caller_Unit_Internal
:= In_Internal_Unit
(C_Scope
);
12144 -- Do not give a warning if the with'ed unit is internal and the caller
12145 -- is not internal (since the binder always elaborates internal units
12148 if Callee_Unit_Internal
and not Caller_Unit_Internal
then
12152 -- For now, if debug flag -gnatdE is not set, do no checking for one
12153 -- internal unit withing another. This fixes the problem with the sgi
12154 -- build and storage errors. To be resolved later ???
12156 if (Callee_Unit_Internal
and Caller_Unit_Internal
)
12157 and not Debug_Flag_EE
12162 if Is_TSS
(E
, TSS_Deep_Initialize
) then
12166 -- If the call is in an instance, and the called entity is not
12167 -- defined in the same instance, then the elaboration issue focuses
12168 -- around the unit containing the template, it is this unit that
12169 -- requires an Elaborate_All.
12171 -- However, if we are doing dynamic elaboration, we need to chase the
12172 -- call in the usual manner.
12174 -- We also need to chase the call in the usual manner if it is a call
12175 -- to a generic formal parameter, since that case was not handled as
12176 -- part of the processing of the template.
12178 Inst_Caller
:= Instantiation
(Get_Source_File_Index
(Sloc
(N
)));
12179 Inst_Callee
:= Instantiation
(Get_Source_File_Index
(Sloc
(Ent
)));
12181 if Inst_Caller
= No_Location
then
12182 Unit_Caller
:= No_Unit
;
12184 Unit_Caller
:= Get_Source_Unit
(N
);
12187 if Inst_Callee
= No_Location
then
12188 Unit_Callee
:= No_Unit
;
12190 Unit_Callee
:= Get_Source_Unit
(Ent
);
12193 if Unit_Caller
/= No_Unit
12194 and then Unit_Callee
/= Unit_Caller
12195 and then not Dynamic_Elaboration_Checks
12196 and then not Is_Call_Of_Generic_Formal
(N
)
12198 E_Scope
:= Spec_Entity
(Cunit_Entity
(Unit_Caller
));
12200 -- If we don't get a spec entity, just ignore call. Not quite
12201 -- clear why this check is necessary. ???
12203 if No
(E_Scope
) then
12207 -- Otherwise step to enclosing compilation unit
12209 while not Is_Compilation_Unit
(E_Scope
) loop
12210 E_Scope
:= Scope
(E_Scope
);
12213 -- For the case where N is not an instance, and is not a call within
12214 -- instance to other than a generic formal, we recompute E_Scope
12215 -- for the error message, since we do NOT want to go to the unit
12216 -- that has the ultimate declaration in the case of renaming and
12217 -- derivation and we also want to go to the generic unit in the
12218 -- case of an instance, and no further.
12221 -- Loop to carefully follow renamings and derivations one step
12222 -- outside the current unit, but not further.
12224 if not (Inst_Case
or Variable_Case
)
12225 and then Present
(Alias
(Ent
))
12227 E_Scope
:= Alias
(Ent
);
12233 while not Is_Compilation_Unit
(E_Scope
) loop
12234 E_Scope
:= Scope
(E_Scope
);
12237 -- If E_Scope is the same as C_Scope, it means that there
12238 -- definitely was a local renaming or derivation, and we
12239 -- are not yet out of the current unit.
12241 exit when E_Scope
/= C_Scope
;
12242 Ent
:= Alias
(Ent
);
12245 -- If no alias, there could be a previous error, but not if we've
12246 -- already reached the outermost level (Standard).
12254 if Within_Elaborate_All
(Current_Sem_Unit
, E_Scope
) then
12258 -- Determine whether the Default_Initial_Condition procedure of some
12259 -- type is being invoked.
12261 Is_DIC
:= Ekind
(Ent
) = E_Procedure
and then Is_DIC_Procedure
(Ent
);
12263 -- Checks related to Default_Initial_Condition fall under the SPARK
12264 -- umbrella because this is a SPARK-specific annotation.
12266 SPARK_Elab_Errors
:=
12267 SPARK_Mode
= On
and (Is_DIC
or Dynamic_Elaboration_Checks
);
12269 -- Now check if an Elaborate_All (or dynamic check) is needed
12271 if (Elab_Info_Messages
or Elab_Warnings
or SPARK_Elab_Errors
)
12272 and then Generate_Warnings
12273 and then not Suppress_Elaboration_Warnings
(Ent
)
12274 and then not Elaboration_Checks_Suppressed
(Ent
)
12275 and then not Suppress_Elaboration_Warnings
(E_Scope
)
12276 and then not Elaboration_Checks_Suppressed
(E_Scope
)
12278 -- Instantiation case
12281 if Comes_From_Source
(Ent
) and then SPARK_Elab_Errors
then
12283 ("instantiation of & during elaboration in SPARK", N
, Ent
);
12286 ("instantiation of & may raise Program_Error?l?",
12287 "info: instantiation of & during elaboration?$?", Ent
);
12290 -- Indirect call case, info message only in static elaboration
12291 -- case, because the attribute reference itself cannot raise an
12292 -- exception. Note that SPARK does not permit indirect calls.
12294 elsif Access_Case
then
12295 Elab_Warning
("", "info: access to & during elaboration?$?", Ent
);
12297 -- Variable reference in SPARK mode
12299 elsif Variable_Case
then
12300 if Comes_From_Source
(Ent
) and then SPARK_Elab_Errors
then
12302 ("reference to & during elaboration in SPARK", N
, Ent
);
12305 -- Subprogram call case
12308 if Nkind
(Name
(N
)) in N_Has_Entity
12309 and then Is_Init_Proc
(Entity
(Name
(N
)))
12310 and then Comes_From_Source
(Ent
)
12313 ("implicit call to & may raise Program_Error?l?",
12314 "info: implicit call to & during elaboration?$?",
12317 elsif SPARK_Elab_Errors
then
12319 -- Emit a specialized error message when the elaboration of an
12320 -- object of a private type evaluates the expression of pragma
12321 -- Default_Initial_Condition. This prevents the internal name
12322 -- of the procedure from appearing in the error message.
12326 ("call to Default_Initial_Condition during elaboration in "
12330 ("call to & during elaboration in SPARK", N
, Ent
);
12335 ("call to & may raise Program_Error?l?",
12336 "info: call to & during elaboration?$?",
12341 Error_Msg_Qual_Level
:= Nat
'Last;
12343 -- Case of Elaborate_All not present and required, for SPARK this
12344 -- is an error, so give an error message.
12346 if SPARK_Elab_Errors
then
12347 Error_Msg_NE
-- CODEFIX
12348 ("\Elaborate_All pragma required for&", N
, W_Scope
);
12350 -- Otherwise we generate an implicit pragma. For a subprogram
12351 -- instantiation, Elaborate is good enough, since no transitive
12352 -- call is possible at elaboration time in this case.
12354 elsif Nkind
(N
) in N_Subprogram_Instantiation
then
12356 ("\missing pragma Elaborate for&?l?",
12357 "\implicit pragma Elaborate for& generated?$?",
12360 -- For all other cases, we need an implicit Elaborate_All
12364 ("\missing pragma Elaborate_All for&?l?",
12365 "\implicit pragma Elaborate_All for & generated?$?",
12369 Error_Msg_Qual_Level
:= 0;
12371 -- Take into account the flags related to elaboration warning
12372 -- messages when enumerating the various calls involved. This
12373 -- ensures the proper pairing of the main warning and the
12374 -- clarification messages generated by Output_Calls.
12376 Output_Calls
(N
, Check_Elab_Flag
=> True);
12378 -- Set flag to prevent further warnings for same unit unless in
12379 -- All_Errors_Mode.
12381 if not All_Errors_Mode
and not Dynamic_Elaboration_Checks
then
12382 Set_Suppress_Elaboration_Warnings
(W_Scope
);
12386 -- Check for runtime elaboration check required
12388 if Dynamic_Elaboration_Checks
then
12389 if not Elaboration_Checks_Suppressed
(Ent
)
12390 and then not Elaboration_Checks_Suppressed
(W_Scope
)
12391 and then not Elaboration_Checks_Suppressed
(E_Scope
)
12392 and then not Cunit_SC
12394 -- Runtime elaboration check required. Generate check of the
12395 -- elaboration Boolean for the unit containing the entity.
12397 -- Note that for this case, we do check the real unit (the one
12398 -- from following renamings, since that is the issue).
12400 -- Could this possibly miss a useless but required PE???
12402 Insert_Elab_Check
(N
,
12403 Make_Attribute_Reference
(Loc
,
12404 Attribute_Name
=> Name_Elaborated
,
12406 New_Occurrence_Of
(Spec_Entity
(E_Scope
), Loc
)));
12408 -- Prevent duplicate elaboration checks on the same call, which
12409 -- can happen if the body enclosing the call appears itself in a
12410 -- call whose elaboration check is delayed.
12412 if Nkind
(N
) in N_Subprogram_Call
then
12413 Set_No_Elaboration_Check
(N
);
12417 -- Case of static elaboration model
12420 -- Do not do anything if elaboration checks suppressed. Note that
12421 -- we check Ent here, not E, since we want the real entity for the
12422 -- body to see if checks are suppressed for it, not the dummy
12423 -- entry for renamings or derivations.
12425 if Elaboration_Checks_Suppressed
(Ent
)
12426 or else Elaboration_Checks_Suppressed
(E_Scope
)
12427 or else Elaboration_Checks_Suppressed
(W_Scope
)
12431 -- Do not generate an Elaborate_All for finalization routines
12432 -- that perform partial clean up as part of initialization.
12434 elsif In_Init_Proc
and then Is_Finalization_Procedure
(Ent
) then
12437 -- Here we need to generate an implicit elaborate all
12440 -- Generate Elaborate_All warning unless suppressed
12442 if (Elab_Info_Messages
and Generate_Warnings
and not Inst_Case
)
12443 and then not Suppress_Elaboration_Warnings
(Ent
)
12444 and then not Suppress_Elaboration_Warnings
(E_Scope
)
12445 and then not Suppress_Elaboration_Warnings
(W_Scope
)
12447 Error_Msg_Node_2
:= W_Scope
;
12449 ("info: call to& in elaboration code requires pragma "
12450 & "Elaborate_All on&?$?", N
, E
);
12453 -- Set indication for binder to generate Elaborate_All
12455 Set_Elaboration_Constraint
(N
, E
, W_Scope
);
12460 -----------------------------
12461 -- Check_Bad_Instantiation --
12462 -----------------------------
12464 procedure Check_Bad_Instantiation
(N
: Node_Id
) is
12468 -- Nothing to do if we do not have an instantiation (happens in some
12469 -- error cases, and also in the formal package declaration case)
12471 if Nkind
(N
) not in N_Generic_Instantiation
then
12474 -- Nothing to do if serious errors detected (avoid cascaded errors)
12476 elsif Serious_Errors_Detected
/= 0 then
12479 -- Nothing to do if not in full analysis mode
12481 elsif not Full_Analysis
then
12484 -- Nothing to do if inside a generic template
12486 elsif Inside_A_Generic
then
12489 -- Nothing to do if a library level instantiation
12491 elsif Nkind
(Parent
(N
)) = N_Compilation_Unit
then
12494 -- Nothing to do if we are compiling a proper body for semantic
12495 -- purposes only. The generic body may be in another proper body.
12498 Nkind
(Parent
(Unit_Declaration_Node
(Main_Unit_Entity
))) = N_Subunit
12503 Ent
:= Get_Generic_Entity
(N
);
12505 -- The case we are interested in is when the generic spec is in the
12506 -- current declarative part
12508 if not Same_Elaboration_Scope
(Current_Scope
, Scope
(Ent
))
12509 or else not In_Same_Extended_Unit
(N
, Ent
)
12514 -- If the generic entity is within a deeper instance than we are, then
12515 -- either the instantiation to which we refer itself caused an ABE, in
12516 -- which case that will be handled separately. Otherwise, we know that
12517 -- the body we need appears as needed at the point of the instantiation.
12518 -- If they are both at the same level but not within the same instance
12519 -- then the body of the generic will be in the earlier instance.
12522 D1
: constant Nat
:= Instantiation_Depth
(Sloc
(Ent
));
12523 D2
: constant Nat
:= Instantiation_Depth
(Sloc
(N
));
12530 and then Is_Generic_Instance
(Scope
(Ent
))
12531 and then not In_Open_Scopes
(Scope
(Ent
))
12537 -- Now we can proceed, if the entity being called has a completion,
12538 -- then we are definitely OK, since we have already seen the body.
12540 if Has_Completion
(Ent
) then
12544 -- If there is no body, then nothing to do
12546 if not Has_Generic_Body
(N
) then
12550 -- Here we definitely have a bad instantiation
12552 Error_Msg_Warn
:= SPARK_Mode
/= On
;
12553 Error_Msg_NE
("cannot instantiate& before body seen<<", N
, Ent
);
12554 Error_Msg_N
("\Program_Error [<<", N
);
12556 Insert_Elab_Check
(N
);
12557 Set_Is_Known_Guaranteed_ABE
(N
);
12558 end Check_Bad_Instantiation
;
12560 ---------------------
12561 -- Check_Elab_Call --
12562 ---------------------
12564 procedure Check_Elab_Call
12566 Outer_Scope
: Entity_Id
:= Empty
;
12567 In_Init_Proc
: Boolean := False)
12573 pragma Assert
(Legacy_Elaboration_Checks
);
12575 -- If the reference is not in the main unit, there is nothing to check.
12576 -- Elaboration call from units in the context of the main unit will lead
12577 -- to semantic dependencies when those units are compiled.
12579 if not In_Extended_Main_Code_Unit
(N
) then
12583 -- For an entry call, check relevant restriction
12585 if Nkind
(N
) = N_Entry_Call_Statement
12586 and then not In_Subprogram_Or_Concurrent_Unit
12588 Check_Restriction
(No_Entry_Calls_In_Elaboration_Code
, N
);
12590 -- Nothing to do if this is not an expected type of reference (happens
12591 -- in some error conditions, and in some cases where rewriting occurs).
12593 elsif Nkind
(N
) not in N_Subprogram_Call
12594 and then Nkind
(N
) /= N_Attribute_Reference
12595 and then (SPARK_Mode
/= On
12596 or else Nkind
(N
) not in N_Has_Entity
12597 or else No
(Entity
(N
))
12598 or else Ekind
(Entity
(N
)) /= E_Variable
)
12602 -- Nothing to do if this is a call already rewritten for elab checking.
12603 -- Such calls appear as the targets of If_Expressions.
12605 -- This check MUST be wrong, it catches far too much
12607 elsif Nkind
(Parent
(N
)) = N_If_Expression
then
12610 -- Nothing to do if inside a generic template
12612 elsif Inside_A_Generic
12613 and then No
(Enclosing_Generic_Body
(N
))
12617 -- Nothing to do if call is being pre-analyzed, as when within a
12618 -- pre/postcondition, a predicate, or an invariant.
12620 elsif In_Spec_Expression
then
12624 -- Nothing to do if this is a call to a postcondition, which is always
12625 -- within a subprogram body, even though the current scope may be the
12626 -- enclosing scope of the subprogram.
12628 if Nkind
(N
) = N_Procedure_Call_Statement
12629 and then Is_Entity_Name
(Name
(N
))
12630 and then Chars
(Entity
(Name
(N
))) = Name_uPostconditions
12635 -- Here we have a reference at elaboration time that must be checked
12637 if Debug_Flag_Underscore_LL
then
12638 Write_Str
(" Check_Elab_Ref: ");
12640 if Nkind
(N
) = N_Attribute_Reference
then
12641 if not Is_Entity_Name
(Prefix
(N
)) then
12642 Write_Str
("<<not entity name>>");
12644 Write_Name
(Chars
(Entity
(Prefix
(N
))));
12647 Write_Str
("'Access");
12649 elsif No
(Name
(N
)) or else not Is_Entity_Name
(Name
(N
)) then
12650 Write_Str
("<<not entity name>> ");
12653 Write_Name
(Chars
(Entity
(Name
(N
))));
12656 Write_Str
(" reference at ");
12657 Write_Location
(Sloc
(N
));
12661 -- Climb up the tree to make sure we are not inside default expression
12662 -- of a parameter specification or a record component, since in both
12663 -- these cases, we will be doing the actual reference later, not now,
12664 -- and it is at the time of the actual reference (statically speaking)
12665 -- that we must do our static check, not at the time of its initial
12668 -- However, we have to check references within component definitions
12669 -- (e.g. a function call that determines an array component bound),
12670 -- so we terminate the loop in that case.
12673 while Present
(P
) loop
12674 if Nkind_In
(P
, N_Parameter_Specification
,
12675 N_Component_Declaration
)
12679 -- The reference occurs within the constraint of a component,
12680 -- so it must be checked.
12682 elsif Nkind
(P
) = N_Component_Definition
then
12690 -- Stuff that happens only at the outer level
12692 if No
(Outer_Scope
) then
12693 Elab_Visited
.Set_Last
(0);
12695 -- Nothing to do if current scope is Standard (this is a bit odd, but
12696 -- it happens in the case of generic instantiations).
12698 C_Scope
:= Current_Scope
;
12700 if C_Scope
= Standard_Standard
then
12704 -- First case, we are in elaboration code
12706 From_Elab_Code
:= not In_Subprogram_Or_Concurrent_Unit
;
12708 if From_Elab_Code
then
12710 -- Complain if ref that comes from source in preelaborated unit
12711 -- and we are not inside a subprogram (i.e. we are in elab code).
12713 if Comes_From_Source
(N
)
12714 and then In_Preelaborated_Unit
12715 and then not In_Inlined_Body
12716 and then Nkind
(N
) /= N_Attribute_Reference
12718 -- This is a warning in GNAT mode allowing such calls to be
12719 -- used in the predefined library with appropriate care.
12721 Error_Msg_Warn
:= GNAT_Mode
;
12723 ("<<non-static call not allowed in preelaborated unit", N
);
12727 -- Second case, we are inside a subprogram or concurrent unit, which
12728 -- means we are not in elaboration code.
12731 -- In this case, the issue is whether we are inside the
12732 -- declarative part of the unit in which we live, or inside its
12733 -- statements. In the latter case, there is no issue of ABE calls
12734 -- at this level (a call from outside to the unit in which we live
12735 -- might cause an ABE, but that will be detected when we analyze
12736 -- that outer level call, as it recurses into the called unit).
12738 -- Climb up the tree, doing this test, and also testing for being
12739 -- inside a default expression, which, as discussed above, is not
12740 -- checked at this stage.
12749 -- If we find a parentless subtree, it seems safe to assume
12750 -- that we are not in a declarative part and that no
12751 -- checking is required.
12757 if Is_List_Member
(P
) then
12758 L
:= List_Containing
(P
);
12765 exit when Nkind
(P
) = N_Subunit
;
12767 -- Filter out case of default expressions, where we do not
12768 -- do the check at this stage.
12770 if Nkind_In
(P
, N_Parameter_Specification
,
12771 N_Component_Declaration
)
12776 -- A protected body has no elaboration code and contains
12777 -- only other bodies.
12779 if Nkind
(P
) = N_Protected_Body
then
12782 elsif Nkind_In
(P
, N_Subprogram_Body
,
12787 if L
= Declarations
(P
) then
12790 -- We are not in elaboration code, but we are doing
12791 -- dynamic elaboration checks, in this case, we still
12792 -- need to do the reference, since the subprogram we are
12793 -- in could be called from another unit, also in dynamic
12794 -- elaboration check mode, at elaboration time.
12796 elsif Dynamic_Elaboration_Checks
then
12798 -- We provide a debug flag to disable this check. That
12799 -- way we have an easy work around for regressions
12800 -- that are caused by this new check. This debug flag
12801 -- can be removed later.
12803 if Debug_Flag_DD
then
12807 -- Do the check in this case
12811 elsif Nkind
(P
) = N_Task_Body
then
12813 -- The check is deferred until Check_Task_Activation
12814 -- but we need to capture local suppress pragmas
12815 -- that may inhibit checks on this call.
12817 Ent
:= Get_Referenced_Ent
(N
);
12822 elsif Elaboration_Checks_Suppressed
(Current_Scope
)
12823 or else Elaboration_Checks_Suppressed
(Ent
)
12824 or else Elaboration_Checks_Suppressed
(Scope
(Ent
))
12826 if Nkind
(N
) in N_Subprogram_Call
then
12827 Set_No_Elaboration_Check
(N
);
12833 -- Static model, call is not in elaboration code, we
12834 -- never need to worry, because in the static model the
12835 -- top-level caller always takes care of things.
12846 Ent
:= Get_Referenced_Ent
(N
);
12852 -- Determine whether a prior call to the same subprogram was already
12853 -- examined within the same context. If this is the case, then there is
12854 -- no need to proceed with the various warnings and checks because the
12855 -- work was already done for the previous call.
12858 Self
: constant Visited_Element
:=
12859 (Subp_Id
=> Ent
, Context
=> Parent
(N
));
12862 for Index
in 1 .. Elab_Visited
.Last
loop
12863 if Self
= Elab_Visited
.Table
(Index
) then
12869 -- See if we need to analyze this reference. We analyze it if either of
12870 -- the following conditions is met:
12872 -- It is an inner level call (since in this case it was triggered
12873 -- by an outer level call from elaboration code), but only if the
12874 -- call is within the scope of the original outer level call.
12876 -- It is an outer level reference from elaboration code, or a call to
12877 -- an entity is in the same elaboration scope.
12879 -- And in these cases, we will check both inter-unit calls and
12880 -- intra-unit (within a single unit) calls.
12882 C_Scope
:= Current_Scope
;
12884 -- If not outer level reference, then we follow it if it is within the
12885 -- original scope of the outer reference.
12887 if Present
(Outer_Scope
)
12888 and then Within
(Scope
(Ent
), Outer_Scope
)
12894 Outer_Scope
=> Outer_Scope
,
12895 Inter_Unit_Only
=> False,
12896 In_Init_Proc
=> In_Init_Proc
);
12898 -- Nothing to do if elaboration checks suppressed for this scope.
12899 -- However, an interesting exception, the fact that elaboration checks
12900 -- are suppressed within an instance (because we can trace the body when
12901 -- we process the template) does not extend to calls to generic formal
12904 elsif Elaboration_Checks_Suppressed
(Current_Scope
)
12905 and then not Is_Call_Of_Generic_Formal
(N
)
12909 elsif From_Elab_Code
then
12911 Check_A_Call
(N
, Ent
, Standard_Standard
, Inter_Unit_Only
=> False);
12913 elsif Same_Elaboration_Scope
(C_Scope
, Scope
(Ent
)) then
12915 Check_A_Call
(N
, Ent
, Scope
(Ent
), Inter_Unit_Only
=> False);
12917 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode
12918 -- is set, then we will do the check, but only in the inter-unit case
12919 -- (this is to accommodate unguarded elaboration calls from other units
12920 -- in which this same mode is set). We don't want warnings in this case,
12921 -- it would generate warnings having nothing to do with elaboration.
12923 elsif Dynamic_Elaboration_Checks
then
12929 Inter_Unit_Only
=> True,
12930 Generate_Warnings
=> False);
12932 -- Otherwise nothing to do
12938 -- A call to an Init_Proc in elaboration code may bring additional
12939 -- dependencies, if some of the record components thereof have
12940 -- initializations that are function calls that come from source. We
12941 -- treat the current node as a call to each of these functions, to check
12942 -- their elaboration impact.
12944 if Is_Init_Proc
(Ent
) and then From_Elab_Code
then
12945 Process_Init_Proc
: declare
12946 Unit_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
12948 function Check_Init_Call
(Nod
: Node_Id
) return Traverse_Result
;
12949 -- Find subprogram calls within body of Init_Proc for Traverse
12950 -- instantiation below.
12952 procedure Traverse_Body
is new Traverse_Proc
(Check_Init_Call
);
12953 -- Traversal procedure to find all calls with body of Init_Proc
12955 ---------------------
12956 -- Check_Init_Call --
12957 ---------------------
12959 function Check_Init_Call
(Nod
: Node_Id
) return Traverse_Result
is
12963 if Nkind
(Nod
) in N_Subprogram_Call
12964 and then Is_Entity_Name
(Name
(Nod
))
12966 Func
:= Entity
(Name
(Nod
));
12968 if Comes_From_Source
(Func
) then
12970 (N
, Func
, Standard_Standard
, Inter_Unit_Only
=> True);
12978 end Check_Init_Call
;
12980 -- Start of processing for Process_Init_Proc
12983 if Nkind
(Unit_Decl
) = N_Subprogram_Body
then
12984 Traverse_Body
(Handled_Statement_Sequence
(Unit_Decl
));
12986 end Process_Init_Proc
;
12988 end Check_Elab_Call
;
12990 -----------------------
12991 -- Check_Elab_Assign --
12992 -----------------------
12994 procedure Check_Elab_Assign
(N
: Node_Id
) is
12998 Pkg_Spec
: Entity_Id
;
12999 Pkg_Body
: Entity_Id
;
13002 pragma Assert
(Legacy_Elaboration_Checks
);
13004 -- For record or array component, check prefix. If it is an access type,
13005 -- then there is nothing to do (we do not know what is being assigned),
13006 -- but otherwise this is an assignment to the prefix.
13008 if Nkind_In
(N
, N_Indexed_Component
,
13009 N_Selected_Component
,
13012 if not Is_Access_Type
(Etype
(Prefix
(N
))) then
13013 Check_Elab_Assign
(Prefix
(N
));
13019 -- For type conversion, check expression
13021 if Nkind
(N
) = N_Type_Conversion
then
13022 Check_Elab_Assign
(Expression
(N
));
13026 -- Nothing to do if this is not an entity reference otherwise get entity
13028 if Is_Entity_Name
(N
) then
13034 -- What we are looking for is a reference in the body of a package that
13035 -- modifies a variable declared in the visible part of the package spec.
13038 and then Comes_From_Source
(N
)
13039 and then not Suppress_Elaboration_Warnings
(Ent
)
13040 and then Ekind
(Ent
) = E_Variable
13041 and then not In_Private_Part
(Ent
)
13042 and then Is_Library_Level_Entity
(Ent
)
13044 Scop
:= Current_Scope
;
13046 if No
(Scop
) or else Scop
= Standard_Standard
then
13048 elsif Ekind
(Scop
) = E_Package
13049 and then Is_Compilation_Unit
(Scop
)
13053 Scop
:= Scope
(Scop
);
13057 -- Here Scop points to the containing library package
13060 Pkg_Body
:= Body_Entity
(Pkg_Spec
);
13062 -- All OK if the package has an Elaborate_Body pragma
13064 if Has_Pragma_Elaborate_Body
(Scop
) then
13068 -- OK if entity being modified is not in containing package spec
13070 if not In_Same_Source_Unit
(Scop
, Ent
) then
13074 -- All OK if entity appears in generic package or generic instance.
13075 -- We just get too messed up trying to give proper warnings in the
13076 -- presence of generics. Better no message than a junk one.
13078 Scop
:= Scope
(Ent
);
13079 while Present
(Scop
) and then Scop
/= Pkg_Spec
loop
13080 if Ekind
(Scop
) = E_Generic_Package
then
13082 elsif Ekind
(Scop
) = E_Package
13083 and then Is_Generic_Instance
(Scop
)
13088 Scop
:= Scope
(Scop
);
13091 -- All OK if in task, don't issue warnings there
13093 if In_Task_Activation
then
13097 -- OK if no package body
13099 if No
(Pkg_Body
) then
13103 -- OK if reference is not in package body
13105 if not In_Same_Source_Unit
(Pkg_Body
, N
) then
13109 -- OK if package body has no handled statement sequence
13112 HSS
: constant Node_Id
:=
13113 Handled_Statement_Sequence
(Declaration_Node
(Pkg_Body
));
13115 if No
(HSS
) or else not Comes_From_Source
(HSS
) then
13120 -- We definitely have a case of a modification of an entity in
13121 -- the package spec from the elaboration code of the package body.
13122 -- We may not give the warning (because there are some additional
13123 -- checks to avoid too many false positives), but it would be a good
13124 -- idea for the binder to try to keep the body elaboration close to
13125 -- the spec elaboration.
13127 Set_Elaborate_Body_Desirable
(Pkg_Spec
);
13129 -- All OK in gnat mode (we know what we are doing)
13135 -- All OK if all warnings suppressed
13137 if Warning_Mode
= Suppress
then
13141 -- All OK if elaboration checks suppressed for entity
13143 if Checks_May_Be_Suppressed
(Ent
)
13144 and then Is_Check_Suppressed
(Ent
, Elaboration_Check
)
13149 -- OK if the entity is initialized. Note that the No_Initialization
13150 -- flag usually means that the initialization has been rewritten into
13151 -- assignments, but that still counts for us.
13154 Decl
: constant Node_Id
:= Declaration_Node
(Ent
);
13156 if Nkind
(Decl
) = N_Object_Declaration
13157 and then (Present
(Expression
(Decl
))
13158 or else No_Initialization
(Decl
))
13164 -- Here is where we give the warning
13166 -- All OK if warnings suppressed on the entity
13168 if not Has_Warnings_Off
(Ent
) then
13169 Error_Msg_Sloc
:= Sloc
(Ent
);
13172 ("??& can be accessed by clients before this initialization",
13175 ("\??add Elaborate_Body to spec to ensure & is initialized",
13179 if not All_Errors_Mode
then
13180 Set_Suppress_Elaboration_Warnings
(Ent
);
13183 end Check_Elab_Assign
;
13185 ----------------------
13186 -- Check_Elab_Calls --
13187 ----------------------
13189 -- WARNING: This routine manages SPARK regions
13191 procedure Check_Elab_Calls
is
13192 Saved_SM
: SPARK_Mode_Type
;
13193 Saved_SMP
: Node_Id
;
13196 pragma Assert
(Legacy_Elaboration_Checks
);
13198 -- If expansion is disabled, do not generate any checks, unless we
13199 -- are in GNATprove mode, so that errors are issued in GNATprove for
13200 -- violations of static elaboration rules in SPARK code. Also skip
13201 -- checks if any subunits are missing because in either case we lack the
13202 -- full information that we need, and no object file will be created in
13205 if (not Expander_Active
and not GNATprove_Mode
)
13206 or else Is_Generic_Unit
(Cunit_Entity
(Main_Unit
))
13207 or else Subunits_Missing
13212 -- Skip delayed calls if we had any errors
13214 if Serious_Errors_Detected
= 0 then
13215 Delaying_Elab_Checks
:= False;
13216 Expander_Mode_Save_And_Set
(True);
13218 for J
in Delay_Check
.First
.. Delay_Check
.Last
loop
13219 Push_Scope
(Delay_Check
.Table
(J
).Curscop
);
13220 From_Elab_Code
:= Delay_Check
.Table
(J
).From_Elab_Code
;
13221 In_Task_Activation
:= Delay_Check
.Table
(J
).In_Task_Activation
;
13223 Saved_SM
:= SPARK_Mode
;
13224 Saved_SMP
:= SPARK_Mode_Pragma
;
13226 -- Set appropriate value of SPARK_Mode
13228 if Delay_Check
.Table
(J
).From_SPARK_Code
then
13232 Check_Internal_Call_Continue
13233 (N
=> Delay_Check
.Table
(J
).N
,
13234 E
=> Delay_Check
.Table
(J
).E
,
13235 Outer_Scope
=> Delay_Check
.Table
(J
).Outer_Scope
,
13236 Orig_Ent
=> Delay_Check
.Table
(J
).Orig_Ent
);
13238 Restore_SPARK_Mode
(Saved_SM
, Saved_SMP
);
13242 -- Set Delaying_Elab_Checks back on for next main compilation
13244 Expander_Mode_Restore
;
13245 Delaying_Elab_Checks
:= True;
13247 end Check_Elab_Calls
;
13249 ------------------------------
13250 -- Check_Elab_Instantiation --
13251 ------------------------------
13253 procedure Check_Elab_Instantiation
13255 Outer_Scope
: Entity_Id
:= Empty
)
13260 pragma Assert
(Legacy_Elaboration_Checks
);
13262 -- Check for and deal with bad instantiation case. There is some
13263 -- duplicated code here, but we will worry about this later ???
13265 Check_Bad_Instantiation
(N
);
13267 if Is_Known_Guaranteed_ABE
(N
) then
13271 -- Nothing to do if we do not have an instantiation (happens in some
13272 -- error cases, and also in the formal package declaration case)
13274 if Nkind
(N
) not in N_Generic_Instantiation
then
13278 -- Nothing to do if inside a generic template
13280 if Inside_A_Generic
then
13284 -- Nothing to do if the instantiation is not in the main unit
13286 if not In_Extended_Main_Code_Unit
(N
) then
13290 Ent
:= Get_Generic_Entity
(N
);
13291 From_Elab_Code
:= not In_Subprogram_Or_Concurrent_Unit
;
13293 -- See if we need to analyze this instantiation. We analyze it if
13294 -- either of the following conditions is met:
13296 -- It is an inner level instantiation (since in this case it was
13297 -- triggered by an outer level call from elaboration code), but
13298 -- only if the instantiation is within the scope of the original
13299 -- outer level call.
13301 -- It is an outer level instantiation from elaboration code, or the
13302 -- instantiated entity is in the same elaboration scope.
13304 -- And in these cases, we will check both the inter-unit case and
13305 -- the intra-unit (within a single unit) case.
13307 C_Scope
:= Current_Scope
;
13309 if Present
(Outer_Scope
) and then Within
(Scope
(Ent
), Outer_Scope
) then
13311 Check_A_Call
(N
, Ent
, Outer_Scope
, Inter_Unit_Only
=> False);
13313 elsif From_Elab_Code
then
13315 Check_A_Call
(N
, Ent
, Standard_Standard
, Inter_Unit_Only
=> False);
13317 elsif Same_Elaboration_Scope
(C_Scope
, Scope
(Ent
)) then
13319 Check_A_Call
(N
, Ent
, Scope
(Ent
), Inter_Unit_Only
=> False);
13321 -- If none of those cases holds, but Dynamic_Elaboration_Checks mode is
13322 -- set, then we will do the check, but only in the inter-unit case (this
13323 -- is to accommodate unguarded elaboration calls from other units in
13324 -- which this same mode is set). We inhibit warnings in this case, since
13325 -- this instantiation is not occurring in elaboration code.
13327 elsif Dynamic_Elaboration_Checks
then
13333 Inter_Unit_Only
=> True,
13334 Generate_Warnings
=> False);
13339 end Check_Elab_Instantiation
;
13341 -------------------------
13342 -- Check_Internal_Call --
13343 -------------------------
13345 procedure Check_Internal_Call
13348 Outer_Scope
: Entity_Id
;
13349 Orig_Ent
: Entity_Id
)
13351 function Within_Initial_Condition
(Call
: Node_Id
) return Boolean;
13352 -- Determine whether call Call occurs within pragma Initial_Condition or
13353 -- pragma Check with check_kind set to Initial_Condition.
13355 ------------------------------
13356 -- Within_Initial_Condition --
13357 ------------------------------
13359 function Within_Initial_Condition
(Call
: Node_Id
) return Boolean is
13365 -- Traverse the parent chain looking for an enclosing pragma
13368 while Present
(Par
) loop
13369 if Nkind
(Par
) = N_Pragma
then
13370 Nam
:= Pragma_Name
(Par
);
13372 -- Pragma Initial_Condition appears in its alternative from as
13373 -- Check (Initial_Condition, ...).
13375 if Nam
= Name_Check
then
13376 Args
:= Pragma_Argument_Associations
(Par
);
13378 -- Pragma Check should have at least two arguments
13380 pragma Assert
(Present
(Args
));
13383 Chars
(Expression
(First
(Args
))) = Name_Initial_Condition
;
13387 elsif Nam
= Name_Initial_Condition
then
13390 -- Since pragmas are never nested within other pragmas, stop
13397 -- Prevent the search from going too far
13399 elsif Is_Body_Or_Package_Declaration
(Par
) then
13403 Par
:= Parent
(Par
);
13405 -- If assertions are not enabled, the check pragma is rewritten
13406 -- as an if_statement in sem_prag, to generate various warnings
13407 -- on boolean expressions. Retrieve the original pragma.
13409 if Nkind
(Original_Node
(Par
)) = N_Pragma
then
13410 Par
:= Original_Node
(Par
);
13415 end Within_Initial_Condition
;
13419 Inst_Case
: constant Boolean := Nkind
(N
) in N_Generic_Instantiation
;
13421 -- Start of processing for Check_Internal_Call
13424 -- For P'Access, we want to warn if the -gnatw.f switch is set, and the
13425 -- node comes from source.
13427 if Nkind
(N
) = N_Attribute_Reference
13428 and then ((not Warn_On_Elab_Access
and then not Debug_Flag_Dot_O
)
13429 or else not Comes_From_Source
(N
))
13433 -- If not function or procedure call, instantiation, or 'Access, then
13434 -- ignore call (this happens in some error cases and rewriting cases).
13436 elsif not Nkind_In
(N
, N_Attribute_Reference
,
13438 N_Procedure_Call_Statement
)
13439 and then not Inst_Case
13443 -- Nothing to do if this is a call or instantiation that has already
13444 -- been found to be a sure ABE.
13446 elsif Nkind
(N
) /= N_Attribute_Reference
13447 and then Is_Known_Guaranteed_ABE
(N
)
13451 -- Nothing to do if errors already detected (avoid cascaded errors)
13453 elsif Serious_Errors_Detected
/= 0 then
13456 -- Nothing to do if not in full analysis mode
13458 elsif not Full_Analysis
then
13461 -- Nothing to do if analyzing in special spec-expression mode, since the
13462 -- call is not actually being made at this time.
13464 elsif In_Spec_Expression
then
13467 -- Nothing to do for call to intrinsic subprogram
13469 elsif Is_Intrinsic_Subprogram
(E
) then
13472 -- Nothing to do if call is within a generic unit
13474 elsif Inside_A_Generic
then
13477 -- Nothing to do when the call appears within pragma Initial_Condition.
13478 -- The pragma is part of the elaboration statements of a package body
13479 -- and may only call external subprograms or subprograms whose body is
13480 -- already available.
13482 elsif Within_Initial_Condition
(N
) then
13486 -- Delay this call if we are still delaying calls
13488 if Delaying_Elab_Checks
then
13492 Orig_Ent
=> Orig_Ent
,
13493 Curscop
=> Current_Scope
,
13494 Outer_Scope
=> Outer_Scope
,
13495 From_Elab_Code
=> From_Elab_Code
,
13496 In_Task_Activation
=> In_Task_Activation
,
13497 From_SPARK_Code
=> SPARK_Mode
= On
));
13500 -- Otherwise, call phase 2 continuation right now
13503 Check_Internal_Call_Continue
(N
, E
, Outer_Scope
, Orig_Ent
);
13505 end Check_Internal_Call
;
13507 ----------------------------------
13508 -- Check_Internal_Call_Continue --
13509 ----------------------------------
13511 procedure Check_Internal_Call_Continue
13514 Outer_Scope
: Entity_Id
;
13515 Orig_Ent
: Entity_Id
)
13517 function Find_Elab_Reference
(N
: Node_Id
) return Traverse_Result
;
13518 -- Function applied to each node as we traverse the body. Checks for
13519 -- call or entity reference that needs checking, and if so checks it.
13520 -- Always returns OK, so entire tree is traversed, except that as
13521 -- described below subprogram bodies are skipped for now.
13523 procedure Traverse
is new Atree
.Traverse_Proc
(Find_Elab_Reference
);
13524 -- Traverse procedure using above Find_Elab_Reference function
13526 -------------------------
13527 -- Find_Elab_Reference --
13528 -------------------------
13530 function Find_Elab_Reference
(N
: Node_Id
) return Traverse_Result
is
13534 -- If user has specified that there are no entry calls in elaboration
13535 -- code, do not trace past an accept statement, because the rendez-
13536 -- vous will happen after elaboration.
13538 if Nkind_In
(Original_Node
(N
), N_Accept_Statement
,
13539 N_Selective_Accept
)
13540 and then Restriction_Active
(No_Entry_Calls_In_Elaboration_Code
)
13544 -- If we have a function call, check it
13546 elsif Nkind
(N
) = N_Function_Call
then
13547 Check_Elab_Call
(N
, Outer_Scope
);
13550 -- If we have a procedure call, check the call, and also check
13551 -- arguments that are assignments (OUT or IN OUT mode formals).
13553 elsif Nkind
(N
) = N_Procedure_Call_Statement
then
13554 Check_Elab_Call
(N
, Outer_Scope
, In_Init_Proc
=> Is_Init_Proc
(E
));
13556 Actual
:= First_Actual
(N
);
13557 while Present
(Actual
) loop
13558 if Known_To_Be_Assigned
(Actual
) then
13559 Check_Elab_Assign
(Actual
);
13562 Next_Actual
(Actual
);
13567 -- If we have an access attribute for a subprogram, check it.
13568 -- Suppress this behavior under debug flag.
13570 elsif not Debug_Flag_Dot_UU
13571 and then Nkind
(N
) = N_Attribute_Reference
13572 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
13573 Name_Unrestricted_Access
)
13574 and then Is_Entity_Name
(Prefix
(N
))
13575 and then Is_Subprogram
(Entity
(Prefix
(N
)))
13577 Check_Elab_Call
(N
, Outer_Scope
);
13580 -- In SPARK mode, if we have an entity reference to a variable, then
13581 -- check it. For now we consider any reference.
13583 elsif SPARK_Mode
= On
13584 and then Nkind
(N
) in N_Has_Entity
13585 and then Present
(Entity
(N
))
13586 and then Ekind
(Entity
(N
)) = E_Variable
13588 Check_Elab_Call
(N
, Outer_Scope
);
13591 -- If we have a generic instantiation, check it
13593 elsif Nkind
(N
) in N_Generic_Instantiation
then
13594 Check_Elab_Instantiation
(N
, Outer_Scope
);
13597 -- Skip subprogram bodies that come from source (wait for call to
13598 -- analyze these). The reason for the come from source test is to
13599 -- avoid catching task bodies.
13601 -- For task bodies, we should really avoid these too, waiting for the
13602 -- task activation, but that's too much trouble to catch for now, so
13603 -- we go in unconditionally. This is not so terrible, it means the
13604 -- error backtrace is not quite complete, and we are too eager to
13605 -- scan bodies of tasks that are unused, but this is hardly very
13608 elsif Nkind
(N
) = N_Subprogram_Body
13609 and then Comes_From_Source
(N
)
13613 elsif Nkind
(N
) = N_Assignment_Statement
13614 and then Comes_From_Source
(N
)
13616 Check_Elab_Assign
(Name
(N
));
13622 end Find_Elab_Reference
;
13624 Inst_Case
: constant Boolean := Is_Generic_Unit
(E
);
13625 Loc
: constant Source_Ptr
:= Sloc
(N
);
13630 -- Start of processing for Check_Internal_Call_Continue
13633 -- Save outer level call if at outer level
13635 if Elab_Call
.Last
= 0 then
13636 Outer_Level_Sloc
:= Loc
;
13639 -- If the call is to a function that renames a literal, no check needed
13641 if Ekind
(E
) = E_Enumeration_Literal
then
13645 -- Register the subprogram as examined within this particular context.
13646 -- This ensures that calls to the same subprogram but in different
13647 -- contexts receive warnings and checks of their own since the calls
13648 -- may be reached through different flow paths.
13650 Elab_Visited
.Append
((Subp_Id
=> E
, Context
=> Parent
(N
)));
13652 Sbody
:= Unit_Declaration_Node
(E
);
13654 if not Nkind_In
(Sbody
, N_Subprogram_Body
, N_Package_Body
) then
13655 Ebody
:= Corresponding_Body
(Sbody
);
13660 Sbody
:= Unit_Declaration_Node
(Ebody
);
13664 -- If the body appears after the outer level call or instantiation then
13665 -- we have an error case handled below.
13667 if Earlier_In_Extended_Unit
(Outer_Level_Sloc
, Sloc
(Sbody
))
13668 and then not In_Task_Activation
13672 -- If we have the instantiation case we are done, since we now know that
13673 -- the body of the generic appeared earlier.
13675 elsif Inst_Case
then
13678 -- Otherwise we have a call, so we trace through the called body to see
13679 -- if it has any problems.
13682 pragma Assert
(Nkind
(Sbody
) = N_Subprogram_Body
);
13684 Elab_Call
.Append
((Cloc
=> Loc
, Ent
=> E
));
13686 if Debug_Flag_Underscore_LL
then
13687 Write_Str
("Elab_Call.Last = ");
13688 Write_Int
(Int
(Elab_Call
.Last
));
13689 Write_Str
(" Ent = ");
13690 Write_Name
(Chars
(E
));
13691 Write_Str
(" at ");
13692 Write_Location
(Sloc
(N
));
13696 -- Now traverse declarations and statements of subprogram body. Note
13697 -- that we cannot simply Traverse (Sbody), since traverse does not
13698 -- normally visit subprogram bodies.
13703 Decl
:= First
(Declarations
(Sbody
));
13704 while Present
(Decl
) loop
13710 Traverse
(Handled_Statement_Sequence
(Sbody
));
13712 Elab_Call
.Decrement_Last
;
13716 -- Here is the case of calling a subprogram where the body has not yet
13717 -- been encountered. A warning message is needed, except if this is the
13718 -- case of appearing within an aspect specification that results in
13719 -- a check call, we do not really have such a situation, so no warning
13720 -- is needed (e.g. the case of a precondition, where the call appears
13721 -- textually before the body, but in actual fact is moved to the
13722 -- appropriate subprogram body and so does not need a check).
13731 -- Keep looking at parents if we are still in the subexpression
13733 if Nkind
(P
) in N_Subexpr
then
13736 -- Here P is the parent of the expression, check for special case
13739 O
:= Original_Node
(P
);
13741 -- Definitely not the special case if orig node is not a pragma
13743 exit when Nkind
(O
) /= N_Pragma
;
13745 -- Check we have an If statement or a null statement (happens
13746 -- when the If has been expanded to be True).
13748 exit when not Nkind_In
(P
, N_If_Statement
, N_Null_Statement
);
13750 -- Our special case will be indicated either by the pragma
13751 -- coming from an aspect ...
13753 if Present
(Corresponding_Aspect
(O
)) then
13756 -- Or, in the case of an initial condition, specifically by a
13757 -- Check pragma specifying an Initial_Condition check.
13759 elsif Pragma_Name
(O
) = Name_Check
13762 (Expression
(First
(Pragma_Argument_Associations
(O
)))) =
13763 Name_Initial_Condition
13767 -- For anything else, we have an error
13776 -- Not that special case, warning and dynamic check is required
13778 -- If we have nothing in the call stack, then this is at the outer
13779 -- level, and the ABE is bound to occur, unless it's a 'Access, or
13780 -- it's a renaming.
13782 if Elab_Call
.Last
= 0 then
13783 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13786 Insert_Check
: Boolean := True;
13787 -- This flag is set to True if an elaboration check should be
13791 if In_Task_Activation
then
13792 Insert_Check
:= False;
13794 elsif Inst_Case
then
13796 ("cannot instantiate& before body seen<<", N
, Orig_Ent
);
13798 elsif Nkind
(N
) = N_Attribute_Reference
then
13800 ("Access attribute of & before body seen<<", N
, Orig_Ent
);
13801 Error_Msg_N
("\possible Program_Error on later references<", N
);
13802 Insert_Check
:= False;
13804 elsif Nkind
(Unit_Declaration_Node
(Orig_Ent
)) /=
13805 N_Subprogram_Renaming_Declaration
13808 ("cannot call& before body seen<<", N
, Orig_Ent
);
13810 elsif not Is_Generic_Actual_Subprogram
(Orig_Ent
) then
13811 Insert_Check
:= False;
13814 if Insert_Check
then
13815 Error_Msg_N
("\Program_Error [<<", N
);
13816 Insert_Elab_Check
(N
);
13820 -- Call is not at outer level
13823 -- Do not generate elaboration checks in GNATprove mode because the
13824 -- elaboration counter and the check are both forms of expansion.
13826 if GNATprove_Mode
then
13829 -- Generate an elaboration check
13831 elsif not Elaboration_Checks_Suppressed
(E
) then
13832 Set_Elaboration_Entity_Required
(E
);
13834 -- Create a declaration of the elaboration entity, and insert it
13835 -- prior to the subprogram or the generic unit, within the same
13836 -- scope. Since the subprogram may be overloaded, create a unique
13839 if No
(Elaboration_Entity
(E
)) then
13841 Loce
: constant Source_Ptr
:= Sloc
(E
);
13842 Ent
: constant Entity_Id
:=
13843 Make_Defining_Identifier
(Loc
,
13844 New_External_Name
(Chars
(E
), 'E', -1));
13847 Set_Elaboration_Entity
(E
, Ent
);
13848 Push_Scope
(Scope
(E
));
13850 Insert_Action
(Declaration_Node
(E
),
13851 Make_Object_Declaration
(Loce
,
13852 Defining_Identifier
=> Ent
,
13853 Object_Definition
=>
13854 New_Occurrence_Of
(Standard_Short_Integer
, Loce
),
13856 Make_Integer_Literal
(Loc
, Uint_0
)));
13858 -- Set elaboration flag at the point of the body
13860 Set_Elaboration_Flag
(Sbody
, E
);
13862 -- Kill current value indication. This is necessary because
13863 -- the tests of this flag are inserted out of sequence and
13864 -- must not pick up bogus indications of the wrong constant
13865 -- value. Also, this is never a true constant, since one way
13866 -- or another, it gets reset.
13868 Set_Current_Value
(Ent
, Empty
);
13869 Set_Last_Assignment
(Ent
, Empty
);
13870 Set_Is_True_Constant
(Ent
, False);
13877 -- raise Program_Error with "access before elaboration";
13880 Insert_Elab_Check
(N
,
13881 Make_Attribute_Reference
(Loc
,
13882 Attribute_Name
=> Name_Elaborated
,
13883 Prefix
=> New_Occurrence_Of
(E
, Loc
)));
13886 -- Generate the warning
13888 if not Suppress_Elaboration_Warnings
(E
)
13889 and then not Elaboration_Checks_Suppressed
(E
)
13891 -- Suppress this warning if we have a function call that occurred
13892 -- within an assertion expression, since we can get false warnings
13893 -- in this case, due to the out of order handling in this case.
13896 (Nkind
(Original_Node
(N
)) /= N_Function_Call
13897 or else not In_Assertion_Expression_Pragma
(Original_Node
(N
)))
13899 Error_Msg_Warn
:= SPARK_Mode
/= On
;
13903 ("instantiation of& may occur before body is seen<l<",
13906 -- A rather specific check. For Finalize/Adjust/Initialize, if
13907 -- the type has Warnings_Off set, suppress the warning.
13909 if Nam_In
(Chars
(E
), Name_Adjust
,
13912 and then Present
(First_Formal
(E
))
13915 T
: constant Entity_Id
:= Etype
(First_Formal
(E
));
13917 if Is_Controlled
(T
) then
13918 if Warnings_Off
(T
)
13919 or else (Ekind
(T
) = E_Private_Type
13920 and then Warnings_Off
(Full_View
(T
)))
13928 -- Go ahead and give warning if not this special case
13931 ("call to& may occur before body is seen<l<", N
, Orig_Ent
);
13934 Error_Msg_N
("\Program_Error ]<l<", N
);
13936 -- There is no need to query the elaboration warning message flags
13937 -- because the main message is an error, not a warning, therefore
13938 -- all the clarification messages produces by Output_Calls must be
13939 -- emitted unconditionally.
13943 Output_Calls
(N
, Check_Elab_Flag
=> False);
13946 end Check_Internal_Call_Continue
;
13948 ---------------------------
13949 -- Check_Task_Activation --
13950 ---------------------------
13952 procedure Check_Task_Activation
(N
: Node_Id
) is
13953 Loc
: constant Source_Ptr
:= Sloc
(N
);
13954 Inter_Procs
: constant Elist_Id
:= New_Elmt_List
;
13955 Intra_Procs
: constant Elist_Id
:= New_Elmt_List
;
13958 Task_Scope
: Entity_Id
;
13959 Cunit_SC
: Boolean := False;
13962 Enclosing
: Entity_Id
;
13964 procedure Add_Task_Proc
(Typ
: Entity_Id
);
13965 -- Add to Task_Procs the task body procedure(s) of task types in Typ.
13966 -- For record types, this procedure recurses over component types.
13968 procedure Collect_Tasks
(Decls
: List_Id
);
13969 -- Collect the types of the tasks that are to be activated in the given
13970 -- list of declarations, in order to perform elaboration checks on the
13971 -- corresponding task procedures that are called implicitly here.
13973 function Outer_Unit
(E
: Entity_Id
) return Entity_Id
;
13974 -- find enclosing compilation unit of Entity, ignoring subunits, or
13975 -- else enclosing subprogram. If E is not a package, there is no need
13976 -- for inter-unit elaboration checks.
13978 -------------------
13979 -- Add_Task_Proc --
13980 -------------------
13982 procedure Add_Task_Proc
(Typ
: Entity_Id
) is
13984 Proc
: Entity_Id
:= Empty
;
13987 if Is_Task_Type
(Typ
) then
13988 Proc
:= Get_Task_Body_Procedure
(Typ
);
13990 elsif Is_Array_Type
(Typ
)
13991 and then Has_Task
(Base_Type
(Typ
))
13993 Add_Task_Proc
(Component_Type
(Typ
));
13995 elsif Is_Record_Type
(Typ
)
13996 and then Has_Task
(Base_Type
(Typ
))
13998 Comp
:= First_Component
(Typ
);
13999 while Present
(Comp
) loop
14000 Add_Task_Proc
(Etype
(Comp
));
14001 Comp
:= Next_Component
(Comp
);
14005 -- If the task type is another unit, we will perform the usual
14006 -- elaboration check on its enclosing unit. If the type is in the
14007 -- same unit, we can trace the task body as for an internal call,
14008 -- but we only need to examine other external calls, because at
14009 -- the point the task is activated, internal subprogram bodies
14010 -- will have been elaborated already. We keep separate lists for
14011 -- each kind of task.
14013 -- Skip this test if errors have occurred, since in this case
14014 -- we can get false indications.
14016 if Serious_Errors_Detected
/= 0 then
14020 if Present
(Proc
) then
14021 if Outer_Unit
(Scope
(Proc
)) = Enclosing
then
14023 if No
(Corresponding_Body
(Unit_Declaration_Node
(Proc
)))
14025 (not Is_Generic_Instance
(Scope
(Proc
))
14026 or else Scope
(Proc
) = Scope
(Defining_Identifier
(Decl
)))
14028 Error_Msg_Warn
:= SPARK_Mode
/= On
;
14030 ("task will be activated before elaboration of its body<<",
14032 Error_Msg_N
("\Program_Error [<<", Decl
);
14035 (Corresponding_Body
(Unit_Declaration_Node
(Proc
)))
14037 Append_Elmt
(Proc
, Intra_Procs
);
14041 -- No need for multiple entries of the same type
14043 Elmt
:= First_Elmt
(Inter_Procs
);
14044 while Present
(Elmt
) loop
14045 if Node
(Elmt
) = Proc
then
14052 Append_Elmt
(Proc
, Inter_Procs
);
14057 -------------------
14058 -- Collect_Tasks --
14059 -------------------
14061 procedure Collect_Tasks
(Decls
: List_Id
) is
14063 if Present
(Decls
) then
14064 Decl
:= First
(Decls
);
14065 while Present
(Decl
) loop
14066 if Nkind
(Decl
) = N_Object_Declaration
14067 and then Has_Task
(Etype
(Defining_Identifier
(Decl
)))
14069 Add_Task_Proc
(Etype
(Defining_Identifier
(Decl
)));
14081 function Outer_Unit
(E
: Entity_Id
) return Entity_Id
is
14086 while Present
(Outer
) loop
14087 if Elaboration_Checks_Suppressed
(Outer
) then
14091 exit when Is_Child_Unit
(Outer
)
14092 or else Scope
(Outer
) = Standard_Standard
14093 or else Ekind
(Outer
) /= E_Package
;
14094 Outer
:= Scope
(Outer
);
14100 -- Start of processing for Check_Task_Activation
14103 pragma Assert
(Legacy_Elaboration_Checks
);
14105 Enclosing
:= Outer_Unit
(Current_Scope
);
14107 -- Find all tasks declared in the current unit
14109 if Nkind
(N
) = N_Package_Body
then
14110 P
:= Unit_Declaration_Node
(Corresponding_Spec
(N
));
14112 Collect_Tasks
(Declarations
(N
));
14113 Collect_Tasks
(Visible_Declarations
(Specification
(P
)));
14114 Collect_Tasks
(Private_Declarations
(Specification
(P
)));
14116 elsif Nkind
(N
) = N_Package_Declaration
then
14117 Collect_Tasks
(Visible_Declarations
(Specification
(N
)));
14118 Collect_Tasks
(Private_Declarations
(Specification
(N
)));
14121 Collect_Tasks
(Declarations
(N
));
14124 -- We only perform detailed checks in all tasks that are library level
14125 -- entities. If the master is a subprogram or task, activation will
14126 -- depend on the activation of the master itself.
14128 -- Should dynamic checks be added in the more general case???
14130 if Ekind
(Enclosing
) /= E_Package
then
14134 -- For task types defined in other units, we want the unit containing
14135 -- the task body to be elaborated before the current one.
14137 Elmt
:= First_Elmt
(Inter_Procs
);
14138 while Present
(Elmt
) loop
14139 Ent
:= Node
(Elmt
);
14140 Task_Scope
:= Outer_Unit
(Scope
(Ent
));
14142 if not Is_Compilation_Unit
(Task_Scope
) then
14145 elsif Suppress_Elaboration_Warnings
(Task_Scope
)
14146 or else Elaboration_Checks_Suppressed
(Task_Scope
)
14150 elsif Dynamic_Elaboration_Checks
then
14151 if not Elaboration_Checks_Suppressed
(Ent
)
14152 and then not Cunit_SC
14153 and then not Restriction_Active
14154 (No_Entry_Calls_In_Elaboration_Code
)
14156 -- Runtime elaboration check required. Generate check of the
14157 -- elaboration counter for the unit containing the entity.
14159 Insert_Elab_Check
(N
,
14160 Make_Attribute_Reference
(Loc
,
14162 New_Occurrence_Of
(Spec_Entity
(Task_Scope
), Loc
),
14163 Attribute_Name
=> Name_Elaborated
));
14167 -- Force the binder to elaborate other unit first
14169 if Elab_Info_Messages
14170 and then not Suppress_Elaboration_Warnings
(Ent
)
14171 and then not Elaboration_Checks_Suppressed
(Ent
)
14172 and then not Suppress_Elaboration_Warnings
(Task_Scope
)
14173 and then not Elaboration_Checks_Suppressed
(Task_Scope
)
14175 Error_Msg_Node_2
:= Task_Scope
;
14177 ("info: activation of an instance of task type & requires "
14178 & "pragma Elaborate_All on &?$?", N
, Ent
);
14181 Activate_Elaborate_All_Desirable
(N
, Task_Scope
);
14182 Set_Suppress_Elaboration_Warnings
(Task_Scope
);
14188 -- For tasks declared in the current unit, trace other calls within the
14189 -- task procedure bodies, which are available.
14191 if not Debug_Flag_Dot_Y
then
14192 In_Task_Activation
:= True;
14194 Elmt
:= First_Elmt
(Intra_Procs
);
14195 while Present
(Elmt
) loop
14196 Ent
:= Node
(Elmt
);
14197 Check_Internal_Call_Continue
(N
, Ent
, Enclosing
, Ent
);
14201 In_Task_Activation
:= False;
14203 end Check_Task_Activation
;
14205 ------------------------
14206 -- Get_Referenced_Ent --
14207 ------------------------
14209 function Get_Referenced_Ent
(N
: Node_Id
) return Entity_Id
is
14213 if Nkind
(N
) in N_Has_Entity
14214 and then Present
(Entity
(N
))
14215 and then Ekind
(Entity
(N
)) = E_Variable
14220 if Nkind
(N
) = N_Attribute_Reference
then
14228 elsif Nkind
(Nam
) = N_Selected_Component
then
14229 return Entity
(Selector_Name
(Nam
));
14230 elsif not Is_Entity_Name
(Nam
) then
14233 return Entity
(Nam
);
14235 end Get_Referenced_Ent
;
14237 ----------------------
14238 -- Has_Generic_Body --
14239 ----------------------
14241 function Has_Generic_Body
(N
: Node_Id
) return Boolean is
14242 Ent
: constant Entity_Id
:= Get_Generic_Entity
(N
);
14243 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Ent
);
14246 function Find_Body_In
(E
: Entity_Id
; N
: Node_Id
) return Node_Id
;
14247 -- Determine if the list of nodes headed by N and linked by Next
14248 -- contains a package body for the package spec entity E, and if so
14249 -- return the package body. If not, then returns Empty.
14251 function Load_Package_Body
(Nam
: Unit_Name_Type
) return Node_Id
;
14252 -- This procedure is called load the unit whose name is given by Nam.
14253 -- This unit is being loaded to see whether it contains an optional
14254 -- generic body. The returned value is the loaded unit, which is always
14255 -- a package body (only package bodies can contain other entities in the
14256 -- sense in which Has_Generic_Body is interested). We only attempt to
14257 -- load bodies if we are generating code. If we are in semantics check
14258 -- only mode, then it would be wrong to load bodies that are not
14259 -- required from a semantic point of view, so in this case we return
14260 -- Empty. The result is that the caller may incorrectly decide that a
14261 -- generic spec does not have a body when in fact it does, but the only
14262 -- harm in this is that some warnings on elaboration problems may be
14263 -- lost in semantic checks only mode, which is not big loss. We also
14264 -- return Empty if we go for a body and it is not there.
14266 function Locate_Corresponding_Body
(PE
: Entity_Id
) return Node_Id
;
14267 -- PE is the entity for a package spec. This function locates the
14268 -- corresponding package body, returning Empty if none is found. The
14269 -- package body returned is fully parsed but may not yet be analyzed,
14270 -- so only syntactic fields should be referenced.
14276 function Find_Body_In
(E
: Entity_Id
; N
: Node_Id
) return Node_Id
is
14281 while Present
(Nod
) loop
14283 -- If we found the package body we are looking for, return it
14285 if Nkind
(Nod
) = N_Package_Body
14286 and then Chars
(Defining_Unit_Name
(Nod
)) = Chars
(E
)
14290 -- If we found the stub for the body, go after the subunit,
14291 -- loading it if necessary.
14293 elsif Nkind
(Nod
) = N_Package_Body_Stub
14294 and then Chars
(Defining_Identifier
(Nod
)) = Chars
(E
)
14296 if Present
(Library_Unit
(Nod
)) then
14297 return Unit
(Library_Unit
(Nod
));
14300 return Load_Package_Body
(Get_Unit_Name
(Nod
));
14303 -- If neither package body nor stub, keep looking on chain
14313 -----------------------
14314 -- Load_Package_Body --
14315 -----------------------
14317 function Load_Package_Body
(Nam
: Unit_Name_Type
) return Node_Id
is
14318 U
: Unit_Number_Type
;
14321 if Operating_Mode
/= Generate_Code
then
14331 if U
= No_Unit
then
14334 return Unit
(Cunit
(U
));
14337 end Load_Package_Body
;
14339 -------------------------------
14340 -- Locate_Corresponding_Body --
14341 -------------------------------
14343 function Locate_Corresponding_Body
(PE
: Entity_Id
) return Node_Id
is
14344 Spec
: constant Node_Id
:= Declaration_Node
(PE
);
14345 Decl
: constant Node_Id
:= Parent
(Spec
);
14346 Scop
: constant Entity_Id
:= Scope
(PE
);
14350 if Is_Library_Level_Entity
(PE
) then
14352 -- If package is a library unit that requires a body, we have no
14353 -- choice but to go after that body because it might contain an
14354 -- optional body for the original generic package.
14356 if Unit_Requires_Body
(PE
) then
14358 -- Load the body. Note that we are a little careful here to use
14359 -- Spec to get the unit number, rather than PE or Decl, since
14360 -- in the case where the package is itself a library level
14361 -- instantiation, Spec will properly reference the generic
14362 -- template, which is what we really want.
14366 (Get_Body_Name
(Unit_Name
(Get_Source_Unit
(Spec
))));
14368 -- But if the package is a library unit that does NOT require
14369 -- a body, then no body is permitted, so we are sure that there
14370 -- is no body for the original generic package.
14376 -- Otherwise look and see if we are embedded in a further package
14378 elsif Is_Package_Or_Generic_Package
(Scop
) then
14380 -- If so, get the body of the enclosing package, and look in
14381 -- its package body for the package body we are looking for.
14383 PBody
:= Locate_Corresponding_Body
(Scop
);
14388 return Find_Body_In
(PE
, First
(Declarations
(PBody
)));
14391 -- If we are not embedded in a further package, then the body
14392 -- must be in the same declarative part as we are.
14395 return Find_Body_In
(PE
, Next
(Decl
));
14397 end Locate_Corresponding_Body
;
14399 -- Start of processing for Has_Generic_Body
14402 if Present
(Corresponding_Body
(Decl
)) then
14405 elsif Unit_Requires_Body
(Ent
) then
14408 -- Compilation units cannot have optional bodies
14410 elsif Is_Compilation_Unit
(Ent
) then
14413 -- Otherwise look at what scope we are in
14416 Scop
:= Scope
(Ent
);
14418 -- Case of entity is in other than a package spec, in this case
14419 -- the body, if present, must be in the same declarative part.
14421 if not Is_Package_Or_Generic_Package
(Scop
) then
14426 -- Declaration node may get us a spec, so if so, go to
14427 -- the parent declaration.
14429 P
:= Declaration_Node
(Ent
);
14430 while not Is_List_Member
(P
) loop
14434 return Present
(Find_Body_In
(Ent
, Next
(P
)));
14437 -- If the entity is in a package spec, then we have to locate
14438 -- the corresponding package body, and look there.
14442 PBody
: constant Node_Id
:= Locate_Corresponding_Body
(Scop
);
14450 (Find_Body_In
(Ent
, (First
(Declarations
(PBody
)))));
14455 end Has_Generic_Body
;
14457 -----------------------
14458 -- Insert_Elab_Check --
14459 -----------------------
14461 procedure Insert_Elab_Check
(N
: Node_Id
; C
: Node_Id
:= Empty
) is
14463 Loc
: constant Source_Ptr
:= Sloc
(N
);
14466 -- The check (N_Raise_Program_Error) node to be inserted
14469 -- If expansion is disabled, do not generate any checks. Also
14470 -- skip checks if any subunits are missing because in either
14471 -- case we lack the full information that we need, and no object
14472 -- file will be created in any case.
14474 if not Expander_Active
or else Subunits_Missing
then
14478 -- If we have a generic instantiation, where Instance_Spec is set,
14479 -- then this field points to a generic instance spec that has
14480 -- been inserted before the instantiation node itself, so that
14481 -- is where we want to insert a check.
14483 if Nkind
(N
) in N_Generic_Instantiation
14484 and then Present
(Instance_Spec
(N
))
14486 Nod
:= Instance_Spec
(N
);
14491 -- Build check node, possibly with condition
14494 Make_Raise_Program_Error
(Loc
, Reason
=> PE_Access_Before_Elaboration
);
14496 if Present
(C
) then
14497 Set_Condition
(Chk
, Make_Op_Not
(Loc
, Right_Opnd
=> C
));
14500 -- If we are inserting at the top level, insert in Aux_Decls
14502 if Nkind
(Parent
(Nod
)) = N_Compilation_Unit
then
14504 ADN
: constant Node_Id
:= Aux_Decls_Node
(Parent
(Nod
));
14507 if No
(Declarations
(ADN
)) then
14508 Set_Declarations
(ADN
, New_List
(Chk
));
14510 Append_To
(Declarations
(ADN
), Chk
);
14516 -- Otherwise just insert as an action on the node in question
14519 Insert_Action
(Nod
, Chk
);
14521 end Insert_Elab_Check
;
14523 -------------------------------
14524 -- Is_Call_Of_Generic_Formal --
14525 -------------------------------
14527 function Is_Call_Of_Generic_Formal
(N
: Node_Id
) return Boolean is
14529 return Nkind_In
(N
, N_Function_Call
, N_Procedure_Call_Statement
)
14531 -- Always return False if debug flag -gnatd.G is set
14533 and then not Debug_Flag_Dot_GG
14535 -- For now, we detect this by looking for the strange identifier
14536 -- node, whose Chars reflect the name of the generic formal, but
14537 -- the Chars of the Entity references the generic actual.
14539 and then Nkind
(Name
(N
)) = N_Identifier
14540 and then Chars
(Name
(N
)) /= Chars
(Entity
(Name
(N
)));
14541 end Is_Call_Of_Generic_Formal
;
14543 -------------------------------
14544 -- Is_Finalization_Procedure --
14545 -------------------------------
14547 function Is_Finalization_Procedure
(Id
: Entity_Id
) return Boolean is
14549 -- Check whether Id is a procedure with at least one parameter
14551 if Ekind
(Id
) = E_Procedure
and then Present
(First_Formal
(Id
)) then
14553 Typ
: constant Entity_Id
:= Etype
(First_Formal
(Id
));
14554 Deep_Fin
: Entity_Id
:= Empty
;
14555 Fin
: Entity_Id
:= Empty
;
14558 -- If the type of the first formal does not require finalization
14559 -- actions, then this is definitely not [Deep_]Finalize.
14561 if not Needs_Finalization
(Typ
) then
14565 -- At this point we have the following scenario:
14567 -- procedure Name (Param1 : [in] [out] Ctrl[; Param2 : ...]);
14569 -- Recover the two possible versions of [Deep_]Finalize using the
14570 -- type of the first parameter and compare with the input.
14572 Deep_Fin
:= TSS
(Typ
, TSS_Deep_Finalize
);
14574 if Is_Controlled
(Typ
) then
14575 Fin
:= Find_Prim_Op
(Typ
, Name_Finalize
);
14578 return (Present
(Deep_Fin
) and then Id
= Deep_Fin
)
14579 or else (Present
(Fin
) and then Id
= Fin
);
14584 end Is_Finalization_Procedure
;
14590 procedure Output_Calls
14592 Check_Elab_Flag
: Boolean)
14594 function Emit
(Flag
: Boolean) return Boolean;
14595 -- Determine whether to emit an error message based on the combination
14596 -- of flags Check_Elab_Flag and Flag.
14598 function Is_Printable_Error_Name
return Boolean;
14599 -- An internal function, used to determine if a name, stored in the
14600 -- Name_Buffer, is either a non-internal name, or is an internal name
14601 -- that is printable by the error message circuits (i.e. it has a single
14602 -- upper case letter at the end).
14608 function Emit
(Flag
: Boolean) return Boolean is
14610 if Check_Elab_Flag
then
14617 -----------------------------
14618 -- Is_Printable_Error_Name --
14619 -----------------------------
14621 function Is_Printable_Error_Name
return Boolean is
14623 if not Is_Internal_Name
then
14626 elsif Name_Len
= 1 then
14630 Name_Len
:= Name_Len
- 1;
14631 return not Is_Internal_Name
;
14633 end Is_Printable_Error_Name
;
14639 -- Start of processing for Output_Calls
14642 for J
in reverse 1 .. Elab_Call
.Last
loop
14643 Error_Msg_Sloc
:= Elab_Call
.Table
(J
).Cloc
;
14645 Ent
:= Elab_Call
.Table
(J
).Ent
;
14646 Get_Name_String
(Chars
(Ent
));
14648 -- Dynamic elaboration model, warnings controlled by -gnatwl
14650 if Dynamic_Elaboration_Checks
then
14651 if Emit
(Elab_Warnings
) then
14652 if Is_Generic_Unit
(Ent
) then
14653 Error_Msg_NE
("\\?l?& instantiated #", N
, Ent
);
14654 elsif Is_Init_Proc
(Ent
) then
14655 Error_Msg_N
("\\?l?initialization procedure called #", N
);
14656 elsif Is_Printable_Error_Name
then
14657 Error_Msg_NE
("\\?l?& called #", N
, Ent
);
14659 Error_Msg_N
("\\?l?called #", N
);
14663 -- Static elaboration model, info messages controlled by -gnatel
14666 if Emit
(Elab_Info_Messages
) then
14667 if Is_Generic_Unit
(Ent
) then
14668 Error_Msg_NE
("\\?$?& instantiated #", N
, Ent
);
14669 elsif Is_Init_Proc
(Ent
) then
14670 Error_Msg_N
("\\?$?initialization procedure called #", N
);
14671 elsif Is_Printable_Error_Name
then
14672 Error_Msg_NE
("\\?$?& called #", N
, Ent
);
14674 Error_Msg_N
("\\?$?called #", N
);
14681 ----------------------------
14682 -- Same_Elaboration_Scope --
14683 ----------------------------
14685 function Same_Elaboration_Scope
(Scop1
, Scop2
: Entity_Id
) return Boolean is
14690 -- Find elaboration scope for Scop1
14691 -- This is either a subprogram or a compilation unit.
14694 while S1
/= Standard_Standard
14695 and then not Is_Compilation_Unit
(S1
)
14696 and then Ekind_In
(S1
, E_Package
, E_Protected_Type
, E_Block
)
14701 -- Find elaboration scope for Scop2
14704 while S2
/= Standard_Standard
14705 and then not Is_Compilation_Unit
(S2
)
14706 and then Ekind_In
(S2
, E_Package
, E_Protected_Type
, E_Block
)
14712 end Same_Elaboration_Scope
;
14718 procedure Set_C_Scope
is
14720 while not Is_Compilation_Unit
(C_Scope
) loop
14721 C_Scope
:= Scope
(C_Scope
);
14725 --------------------------------
14726 -- Set_Elaboration_Constraint --
14727 --------------------------------
14729 procedure Set_Elaboration_Constraint
14734 Elab_Unit
: Entity_Id
;
14736 -- Check whether this is a call to an Initialize subprogram for a
14737 -- controlled type. Note that Call can also be a 'Access attribute
14738 -- reference, which now generates an elaboration check.
14740 Init_Call
: constant Boolean :=
14741 Nkind
(Call
) = N_Procedure_Call_Statement
14742 and then Chars
(Subp
) = Name_Initialize
14743 and then Comes_From_Source
(Subp
)
14744 and then Present
(Parameter_Associations
(Call
))
14745 and then Is_Controlled
(Etype
(First_Actual
(Call
)));
14748 -- If the unit is mentioned in a with_clause of the current unit, it is
14749 -- visible, and we can set the elaboration flag.
14751 if Is_Immediately_Visible
(Scop
)
14752 or else (Is_Child_Unit
(Scop
) and then Is_Visible_Lib_Unit
(Scop
))
14754 Activate_Elaborate_All_Desirable
(Call
, Scop
);
14755 Set_Suppress_Elaboration_Warnings
(Scop
);
14759 -- If this is not an initialization call or a call using object notation
14760 -- we know that the unit of the called entity is in the context, and we
14761 -- can set the flag as well. The unit need not be visible if the call
14762 -- occurs within an instantiation.
14764 if Is_Init_Proc
(Subp
)
14766 or else Nkind
(Original_Node
(Call
)) = N_Selected_Component
14768 null; -- detailed processing follows.
14771 Activate_Elaborate_All_Desirable
(Call
, Scop
);
14772 Set_Suppress_Elaboration_Warnings
(Scop
);
14776 -- If the unit is not in the context, there must be an intermediate unit
14777 -- that is, on which we need to place to elaboration flag. This happens
14778 -- with init proc calls.
14780 if Is_Init_Proc
(Subp
) or else Init_Call
then
14782 -- The initialization call is on an object whose type is not declared
14783 -- in the same scope as the subprogram. The type of the object must
14784 -- be a subtype of the type of operation. This object is the first
14785 -- actual in the call.
14788 Typ
: constant Entity_Id
:=
14789 Etype
(First
(Parameter_Associations
(Call
)));
14791 Elab_Unit
:= Scope
(Typ
);
14792 while (Present
(Elab_Unit
))
14793 and then not Is_Compilation_Unit
(Elab_Unit
)
14795 Elab_Unit
:= Scope
(Elab_Unit
);
14799 -- If original node uses selected component notation, the prefix is
14800 -- visible and determines the scope that must be elaborated. After
14801 -- rewriting, the prefix is the first actual in the call.
14803 elsif Nkind
(Original_Node
(Call
)) = N_Selected_Component
then
14804 Elab_Unit
:= Scope
(Etype
(First
(Parameter_Associations
(Call
))));
14806 -- Not one of special cases above
14809 -- Using previously computed scope. If the elaboration check is
14810 -- done after analysis, the scope is not visible any longer, but
14811 -- must still be in the context.
14816 Activate_Elaborate_All_Desirable
(Call
, Elab_Unit
);
14817 Set_Suppress_Elaboration_Warnings
(Elab_Unit
);
14818 end Set_Elaboration_Constraint
;
14824 function Spec_Entity
(E
: Entity_Id
) return Entity_Id
is
14828 -- Check for case of body entity
14829 -- Why is the check for E_Void needed???
14831 if Ekind_In
(E
, E_Void
, E_Subprogram_Body
, E_Package_Body
) then
14835 Decl
:= Parent
(Decl
);
14836 exit when Nkind
(Decl
) in N_Proper_Body
;
14839 return Corresponding_Spec
(Decl
);
14850 function Within
(E1
, E2
: Entity_Id
) return Boolean is
14857 elsif Scop
= Standard_Standard
then
14860 Scop
:= Scope
(Scop
);
14865 --------------------------
14866 -- Within_Elaborate_All --
14867 --------------------------
14869 function Within_Elaborate_All
14870 (Unit
: Unit_Number_Type
;
14871 E
: Entity_Id
) return Boolean
14873 type Unit_Number_Set
is array (Main_Unit
.. Last_Unit
) of Boolean;
14874 pragma Pack
(Unit_Number_Set
);
14876 Seen
: Unit_Number_Set
:= (others => False);
14877 -- Seen (X) is True after we have seen unit X in the walk. This is used
14878 -- to prevent processing the same unit more than once.
14880 Result
: Boolean := False;
14882 procedure Helper
(Unit
: Unit_Number_Type
);
14883 -- This helper procedure does all the work for Within_Elaborate_All. It
14884 -- walks the dependency graph, and sets Result to True if it finds an
14885 -- appropriate Elaborate_All.
14891 procedure Helper
(Unit
: Unit_Number_Type
) is
14892 CU
: constant Node_Id
:= Cunit
(Unit
);
14896 Elab_Id
: Entity_Id
;
14900 if Seen
(Unit
) then
14903 Seen
(Unit
) := True;
14906 -- First, check for Elaborate_Alls on this unit
14908 Item
:= First
(Context_Items
(CU
));
14909 while Present
(Item
) loop
14910 if Nkind
(Item
) = N_Pragma
14911 and then Pragma_Name
(Item
) = Name_Elaborate_All
14913 -- Return if some previous error on the pragma itself. The
14914 -- pragma may be unanalyzed, because of a previous error, or
14915 -- if it is the context of a subunit, inherited by its parent.
14917 if Error_Posted
(Item
) or else not Analyzed
(Item
) then
14923 (Expression
(First
(Pragma_Argument_Associations
(Item
))));
14925 if E
= Elab_Id
then
14930 Par
:= Parent
(Unit_Declaration_Node
(Elab_Id
));
14932 Item2
:= First
(Context_Items
(Par
));
14933 while Present
(Item2
) loop
14934 if Nkind
(Item2
) = N_With_Clause
14935 and then Entity
(Name
(Item2
)) = E
14936 and then not Limited_Present
(Item2
)
14949 -- Second, recurse on with's. We could do this as part of the above
14950 -- loop, but it's probably more efficient to have two loops, because
14951 -- the relevant Elaborate_All is likely to be on the initial unit. In
14952 -- other words, we're walking the with's breadth-first. This part is
14953 -- only necessary in the dynamic elaboration model.
14955 if Dynamic_Elaboration_Checks
then
14956 Item
:= First
(Context_Items
(CU
));
14957 while Present
(Item
) loop
14958 if Nkind
(Item
) = N_With_Clause
14959 and then not Limited_Present
(Item
)
14961 -- Note: the following call to Get_Cunit_Unit_Number does a
14962 -- linear search, which could be slow, but it's OK because
14963 -- we're about to give a warning anyway. Also, there might
14964 -- be hundreds of units, but not millions. If it turns out
14965 -- to be a problem, we could store the Get_Cunit_Unit_Number
14966 -- in each N_Compilation_Unit node, but that would involve
14967 -- rearranging N_Compilation_Unit_Aux to make room.
14969 Helper
(Get_Cunit_Unit_Number
(Library_Unit
(Item
)));
14981 -- Start of processing for Within_Elaborate_All
14986 end Within_Elaborate_All
;