| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S E M _ E L A B -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1997-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with ALI; use ALI; |
| 27 |
with Atree; use Atree; |
| 28 |
with Checks; use Checks; |
| 29 |
with Debug; use Debug; |
| 30 |
with Einfo; use Einfo; |
| 31 |
with Einfo.Entities; use Einfo.Entities; |
| 32 |
with Einfo.Utils; use Einfo.Utils; |
| 33 |
with Elists; use Elists; |
| 34 |
with Errout; use Errout; |
| 35 |
with Exp_Ch11; use Exp_Ch11; |
| 36 |
with Exp_Tss; use Exp_Tss; |
| 37 |
with Exp_Util; use Exp_Util; |
| 38 |
with Expander; use Expander; |
| 39 |
with Lib; use Lib; |
| 40 |
with Lib.Load; use Lib.Load; |
| 41 |
with Nlists; use Nlists; |
| 42 |
with Nmake; use Nmake; |
| 43 |
with Opt; use Opt; |
| 44 |
with Output; use Output; |
| 45 |
with Restrict; use Restrict; |
| 46 |
with Rident; use Rident; |
| 47 |
with Rtsfind; use Rtsfind; |
| 48 |
with Sem; use Sem; |
| 49 |
with Sem_Aux; use Sem_Aux; |
| 50 |
with Sem_Cat; use Sem_Cat; |
| 51 |
with Sem_Ch7; use Sem_Ch7; |
| 52 |
with Sem_Ch8; use Sem_Ch8; |
| 53 |
with Sem_Disp; use Sem_Disp; |
| 54 |
with Sem_Prag; use Sem_Prag; |
| 55 |
with Sem_Util; use Sem_Util; |
| 56 |
with Sinfo; use Sinfo; |
| 57 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 58 |
with Sinfo.Utils; use Sinfo.Utils; |
| 59 |
with Sinput; use Sinput; |
| 60 |
with Snames; use Snames; |
| 61 |
with Stand; use Stand; |
| 62 |
with Table; |
| 63 |
with Tbuild; use Tbuild; |
| 64 |
with Uintp; use Uintp; |
| 65 |
with Uname; use Uname; |
| 66 |
with Warnsw; use Warnsw; |
| 67 |
|
| 68 |
with GNAT; use GNAT; |
| 69 |
with GNAT.Dynamic_HTables; use GNAT.Dynamic_HTables; |
| 70 |
with GNAT.Lists; use GNAT.Lists; |
| 71 |
with GNAT.Sets; use GNAT.Sets; |
| 72 |
|
| 73 |
package body Sem_Elab is |
| 74 |
|
| 75 |
----------------------------------------- |
| 76 |
-- Access-before-elaboration mechanism -- |
| 77 |
----------------------------------------- |
| 78 |
|
| 79 |
-- The access-before-elaboration (ABE) mechanism implemented in this unit |
| 80 |
-- has the following objectives: |
| 81 |
-- |
| 82 |
-- * Diagnose at compile time or install run-time checks to prevent ABE |
| 83 |
-- access to data and behavior. |
| 84 |
-- |
| 85 |
-- The high-level idea is to accurately diagnose ABE issues within a |
| 86 |
-- single unit because the ABE mechanism can inspect the whole unit. |
| 87 |
-- As soon as the elaboration graph extends to an external unit, the |
| 88 |
-- diagnostics stop because the body of the unit may not be available. |
| 89 |
-- Due to control and data flow, the ABE mechanism cannot accurately |
| 90 |
-- determine whether a particular scenario will be elaborated or not. |
| 91 |
-- Conditional ABE checks are therefore used to verify the elaboration |
| 92 |
-- status of local and external targets at run time. |
| 93 |
-- |
| 94 |
-- * Supply implicit elaboration dependencies for a unit to binde |
| 95 |
-- |
| 96 |
-- The ABE mechanism creates implicit dependencies in the form of with |
| 97 |
-- clauses subject to pragma Elaborate[_All] when the elaboration graph |
| 98 |
-- reaches into an external unit. The implicit dependencies are encoded |
| 99 |
-- in the ALI file of the main unit. GNATbind and binde then use these |
| 100 |
-- dependencies to augment the library item graph and determine the |
| 101 |
-- elaboration order of all units in the compilation. |
| 102 |
-- |
| 103 |
-- * Supply pieces of the invocation graph for a unit to bindo |
| 104 |
-- |
| 105 |
-- The ABE mechanism captures paths starting from elaboration code or |
| 106 |
-- top level constructs that reach into an external unit. The paths are |
| 107 |
-- encoded in the ALI file of the main unit in the form of declarations |
| 108 |
-- which represent nodes, and relations which represent edges. GNATbind |
| 109 |
-- and bindo then build the full invocation graph in order to augment |
| 110 |
-- the library item graph and determine the elaboration order of all |
| 111 |
-- units in the compilation. |
| 112 |
-- |
| 113 |
-- The ABE mechanism supports three models of elaboration: |
| 114 |
-- |
| 115 |
-- * Dynamic model - This is the most permissive of the three models. |
| 116 |
-- When the dynamic model is in effect, the mechanism diagnoses and |
| 117 |
-- installs run-time checks to detect ABE issues in the main unit. |
| 118 |
-- The behavior of this model is identical to that specified by the |
| 119 |
-- Ada RM. This model is enabled with switch -gnatE. |
| 120 |
-- |
| 121 |
-- Static model - This is the middle ground of the three models. When |
| 122 |
-- the static model is in effect, the mechanism diagnoses and installs |
| 123 |
-- run-time checks to detect ABE issues in the main unit. In addition, |
| 124 |
-- the mechanism generates implicit dependencies between units in the |
| 125 |
-- form of with clauses subject to pragma Elaborate[_All] to ensure |
| 126 |
-- the prior elaboration of withed units. This is the default model. |
| 127 |
-- |
| 128 |
-- * SPARK model - This is the most conservative of the three models and |
| 129 |
-- implements the semantics defined in SPARK RM 7.7. The SPARK model |
| 130 |
-- is in effect only when a context resides in a SPARK_Mode On region, |
| 131 |
-- otherwise the mechanism falls back to one of the previous models. |
| 132 |
-- |
| 133 |
-- The ABE mechanism consists of a "recording" phase and a "processing" |
| 134 |
-- phase. |
| 135 |
|
| 136 |
----------------- |
| 137 |
-- Terminology -- |
| 138 |
----------------- |
| 139 |
|
| 140 |
-- * ABE - An attempt to invoke a scenario which has not been elaborated |
| 141 |
-- yet. |
| 142 |
-- |
| 143 |
-- * Bridge target - A type of target. A bridge target is a link between |
| 144 |
-- scenarios. It is usually a byproduct of expansion and does not have |
| 145 |
-- any direct ABE ramifications. |
| 146 |
-- |
| 147 |
-- * Call marker - A special node used to indicate the presence of a call |
| 148 |
-- in the tree in case expansion transforms or eliminates the original |
| 149 |
-- call. N_Call_Marker nodes do not have static and run-time semantics. |
| 150 |
-- |
| 151 |
-- * Conditional ABE - A type of ABE. A conditional ABE occurs when the |
| 152 |
-- invocation of a target by a scenario within the main unit causes an |
| 153 |
-- ABE, but does not cause an ABE for another scenarios within the main |
| 154 |
-- unit. |
| 155 |
-- |
| 156 |
-- * Declaration level - A type of enclosing level. A scenario or target is |
| 157 |
-- at the declaration level when it appears within the declarations of a |
| 158 |
-- block statement, entry body, subprogram body, or task body, ignoring |
| 159 |
-- enclosing packages. |
| 160 |
-- |
| 161 |
-- * Early call region - A section of code which ends at a subprogram body |
| 162 |
-- and starts from the nearest non-preelaborable construct which precedes |
| 163 |
-- the subprogram body. The early call region extends from a package body |
| 164 |
-- to a package spec when the spec carries pragma Elaborate_Body. |
| 165 |
-- |
| 166 |
-- * Generic library level - A type of enclosing level. A scenario or |
| 167 |
-- target is at the generic library level if it appears in a generic |
| 168 |
-- package library unit, ignoring enclosing packages. |
| 169 |
-- |
| 170 |
-- * Guaranteed ABE - A type of ABE. A guaranteed ABE occurs when the |
| 171 |
-- invocation of a target by all scenarios within the main unit causes |
| 172 |
-- an ABE. |
| 173 |
-- |
| 174 |
-- * Instantiation library level - A type of enclosing level. A scenario |
| 175 |
-- or target is at the instantiation library level if it appears in an |
| 176 |
-- instantiation library unit, ignoring enclosing packages. |
| 177 |
-- |
| 178 |
-- * Invocation - The act of activating a task, calling a subprogram, or |
| 179 |
-- instantiating a generic. |
| 180 |
-- |
| 181 |
-- * Invocation construct - An entry declaration, [single] protected type, |
| 182 |
-- subprogram declaration, subprogram instantiation, or a [single] task |
| 183 |
-- type declared in the visible, private, or body declarations of the |
| 184 |
-- main unit. |
| 185 |
-- |
| 186 |
-- * Invocation relation - A flow link between two invocation constructs |
| 187 |
-- |
| 188 |
-- * Invocation signature - A set of attributes that uniquely identify an |
| 189 |
-- invocation construct within the namespace of all ALI files. |
| 190 |
-- |
| 191 |
-- * Library level - A type of enclosing level. A scenario or target is at |
| 192 |
-- the library level if it appears in a package library unit, ignoring |
| 193 |
-- enclosing packages. |
| 194 |
-- |
| 195 |
-- * Non-library-level encapsulator - A construct that cannot be elaborated |
| 196 |
-- on its own and requires elaboration by a top-level scenario. |
| 197 |
-- |
| 198 |
-- * Scenario - A construct or context which is invoked by elaboration code |
| 199 |
-- or invocation construct. The scenarios recognized by the ABE mechanism |
| 200 |
-- are as follows: |
| 201 |
-- |
| 202 |
-- - '[Unrestricted_]Access of entries, operators, and subprograms |
| 203 |
-- |
| 204 |
-- - Assignments to variables |
| 205 |
-- |
| 206 |
-- - Calls to entries, operators, and subprograms |
| 207 |
-- |
| 208 |
-- - Derived type declarations |
| 209 |
-- |
| 210 |
-- - Instantiations |
| 211 |
-- |
| 212 |
-- - Pragma Refined_State |
| 213 |
-- |
| 214 |
-- - Reads of variables |
| 215 |
-- |
| 216 |
-- - Task activation |
| 217 |
-- |
| 218 |
-- * Target - A construct invoked by a scenario. The targets recognized by |
| 219 |
-- the ABE mechanism are as follows: |
| 220 |
-- |
| 221 |
-- - For '[Unrestricted_]Access of entries, operators, and subprograms, |
| 222 |
-- the target is the entry, operator, or subprogram. |
| 223 |
-- |
| 224 |
-- - For assignments to variables, the target is the variable |
| 225 |
-- |
| 226 |
-- - For calls, the target is the entry, operator, or subprogram |
| 227 |
-- |
| 228 |
-- - For derived type declarations, the target is the derived type |
| 229 |
-- |
| 230 |
-- - For instantiations, the target is the generic template |
| 231 |
-- |
| 232 |
-- - For pragma Refined_State, the targets are the constituents |
| 233 |
-- |
| 234 |
-- - For reads of variables, the target is the variable |
| 235 |
-- |
| 236 |
-- - For task activation, the target is the task body |
| 237 |
|
| 238 |
------------------ |
| 239 |
-- Architecture -- |
| 240 |
------------------ |
| 241 |
|
| 242 |
-- Analysis/Resolution |
| 243 |
-- | |
| 244 |
-- +- Build_Call_Marker |
| 245 |
-- | |
| 246 |
-- +- Build_Variable_Reference_Marker |
| 247 |
-- | |
| 248 |
-- +- | -------------------- Recording phase ---------------------------+ |
| 249 |
-- | v | |
| 250 |
-- | Record_Elaboration_Scenario | |
| 251 |
-- | | | |
| 252 |
-- | +--> Check_Preelaborated_Call | |
| 253 |
-- | | | |
| 254 |
-- | +--> Process_Guaranteed_ABE | |
| 255 |
-- | | | | |
| 256 |
-- | | +--> Process_Guaranteed_ABE_Activation | |
| 257 |
-- | | +--> Process_Guaranteed_ABE_Call | |
| 258 |
-- | | +--> Process_Guaranteed_ABE_Instantiation | |
| 259 |
-- | | | |
| 260 |
-- +- | ----------------------------------------------------------------+ |
| 261 |
-- | |
| 262 |
-- | |
| 263 |
-- +--> Internal_Representation |
| 264 |
-- | |
| 265 |
-- +--> Scenario_Storage |
| 266 |
-- | |
| 267 |
-- End of Compilation |
| 268 |
-- | |
| 269 |
-- +- | --------------------- Processing phase -------------------------+ |
| 270 |
-- | v | |
| 271 |
-- | Check_Elaboration_Scenarios | |
| 272 |
-- | | | |
| 273 |
-- | +--> Check_Conditional_ABE_Scenarios | |
| 274 |
-- | | | | |
| 275 |
-- | | +--> Process_Conditional_ABE <----------------------+ | |
| 276 |
-- | | | | | |
| 277 |
-- | | +--> Process_Conditional_ABE_Activation | | |
| 278 |
-- | | | | | | |
| 279 |
-- | | | +-----------------------------+ | | |
| 280 |
-- | | | | | | |
| 281 |
-- | | +--> Process_Conditional_ABE_Call +---> Traverse_Body | |
| 282 |
-- | | | | | | |
| 283 |
-- | | | +-----------------------------+ | |
| 284 |
-- | | | | |
| 285 |
-- | | +--> Process_Conditional_ABE_Access_Taken | |
| 286 |
-- | | +--> Process_Conditional_ABE_Instantiation | |
| 287 |
-- | | +--> Process_Conditional_ABE_Variable_Assignment | |
| 288 |
-- | | +--> Process_Conditional_ABE_Variable_Reference | |
| 289 |
-- | | | |
| 290 |
-- | +--> Check_SPARK_Scenario | |
| 291 |
-- | | | | |
| 292 |
-- | | +--> Process_SPARK_Scenario | |
| 293 |
-- | | | | |
| 294 |
-- | | +--> Process_SPARK_Derived_Type | |
| 295 |
-- | | +--> Process_SPARK_Instantiation | |
| 296 |
-- | | +--> Process_SPARK_Refined_State_Pragma | |
| 297 |
-- | | | |
| 298 |
-- | +--> Record_Invocation_Graph | |
| 299 |
-- | | | |
| 300 |
-- | +--> Process_Invocation_Body_Scenarios | |
| 301 |
-- | +--> Process_Invocation_Spec_Scenarios | |
| 302 |
-- | +--> Process_Main_Unit | |
| 303 |
-- | | | |
| 304 |
-- | +--> Process_Invocation_Scenario <-------------+ | |
| 305 |
-- | | | | |
| 306 |
-- | +--> Process_Invocation_Activation | | |
| 307 |
-- | | | | | |
| 308 |
-- | | +------------------------+ | | |
| 309 |
-- | | | | | |
| 310 |
-- | +--> Process_Invocation_Call +---> Traverse_Body | |
| 311 |
-- | | | | |
| 312 |
-- | +------------------------+ | |
| 313 |
-- | | |
| 314 |
-- +--------------------------------------------------------------------+ |
| 315 |
|
| 316 |
--------------------- |
| 317 |
-- Recording phase -- |
| 318 |
--------------------- |
| 319 |
|
| 320 |
-- The Recording phase coincides with the analysis/resolution phase of the |
| 321 |
-- compiler. It has the following objectives: |
| 322 |
-- |
| 323 |
-- * Record all suitable scenarios for examination by the Processing |
| 324 |
-- phase. |
| 325 |
-- |
| 326 |
-- Saving only a certain number of nodes improves the performance of |
| 327 |
-- the ABE mechanism. This eliminates the need to examine the whole |
| 328 |
-- tree in a separate pass. |
| 329 |
-- |
| 330 |
-- * Record certain SPARK scenarios which are not necessarily invoked |
| 331 |
-- during elaboration, but still require elaboration-related checks. |
| 332 |
-- |
| 333 |
-- Saving only a certain number of nodes improves the performance of |
| 334 |
-- the ABE mechanism. This eliminates the need to examine the whole |
| 335 |
-- tree in a separate pass. |
| 336 |
-- |
| 337 |
-- * Detect and diagnose calls in preelaborable or pure units, including |
| 338 |
-- generic bodies. |
| 339 |
-- |
| 340 |
-- This diagnostic is carried out during the Recording phase because it |
| 341 |
-- does not need the heavy recursive traversal done by the Processing |
| 342 |
-- phase. |
| 343 |
-- |
| 344 |
-- * Detect and diagnose guaranteed ABEs caused by instantiations, calls, |
| 345 |
-- and task activation. |
| 346 |
-- |
| 347 |
-- The issues detected by the ABE mechanism are reported as warnings |
| 348 |
-- because they do not violate Ada semantics. Forward instantiations |
| 349 |
-- may thus reach gigi, however gigi cannot handle certain kinds of |
| 350 |
-- premature instantiations and may crash. To avoid this limitation, |
| 351 |
-- the ABE mechanism must identify forward instantiations as early as |
| 352 |
-- possible and suppress their bodies. Calls and task activations are |
| 353 |
-- included in this category for completeness. |
| 354 |
|
| 355 |
---------------------- |
| 356 |
-- Processing phase -- |
| 357 |
---------------------- |
| 358 |
|
| 359 |
-- The Processing phase is a separate pass which starts after instantiating |
| 360 |
-- and/or inlining of bodies, but before the removal of Ghost code. It has |
| 361 |
-- the following objectives: |
| 362 |
-- |
| 363 |
-- * Examine all scenarios saved during the Recording phase, and perform |
| 364 |
-- the following actions: |
| 365 |
-- |
| 366 |
-- - Dynamic model |
| 367 |
-- |
| 368 |
-- Diagnose conditional ABEs, and install run-time conditional ABE |
| 369 |
-- checks for all scenarios. |
| 370 |
-- |
| 371 |
-- - SPARK model |
| 372 |
-- |
| 373 |
-- Enforce the SPARK elaboration rules |
| 374 |
-- |
| 375 |
-- - Static model |
| 376 |
-- |
| 377 |
-- Diagnose conditional ABEs, install run-time conditional ABE |
| 378 |
-- checks only for scenarios are reachable from elaboration code, |
| 379 |
-- and guarantee the elaboration of external units by creating |
| 380 |
-- implicit with clauses subject to pragma Elaborate[_All]. |
| 381 |
-- |
| 382 |
-- * Examine library-level scenarios and invocation constructs, and |
| 383 |
-- perform the following actions: |
| 384 |
-- |
| 385 |
-- - Determine whether the flow of execution reaches into an external |
| 386 |
-- unit. If this is the case, encode the path in the ALI file of |
| 387 |
-- the main unit. |
| 388 |
-- |
| 389 |
-- - Create declarations for invocation constructs in the ALI file of |
| 390 |
-- the main unit. |
| 391 |
|
| 392 |
---------------------- |
| 393 |
-- Important points -- |
| 394 |
---------------------- |
| 395 |
|
| 396 |
-- The Processing phase starts after the analysis, resolution, expansion |
| 397 |
-- phase has completed. As a result, no current semantic information is |
| 398 |
-- available. The scope stack is empty, global flags such as In_Instance |
| 399 |
-- or Inside_A_Generic become useless. To remedy this, the ABE mechanism |
| 400 |
-- must either save or recompute semantic information. |
| 401 |
-- |
| 402 |
-- Expansion heavily transforms calls and to some extent instantiations. To |
| 403 |
-- remedy this, the ABE mechanism generates N_Call_Marker nodes in order to |
| 404 |
-- capture the target and relevant attributes of the original call. |
| 405 |
-- |
| 406 |
-- The diagnostics of the ABE mechanism depend on accurate source locations |
| 407 |
-- to determine the spatial relation of nodes. |
| 408 |
|
| 409 |
----------------------------------------- |
| 410 |
-- Suppression of elaboration warnings -- |
| 411 |
----------------------------------------- |
| 412 |
|
| 413 |
-- Elaboration warnings along multiple traversal paths rooted at a scenario |
| 414 |
-- are suppressed when the scenario has elaboration warnings suppressed. |
| 415 |
-- |
| 416 |
-- Root scenario |
| 417 |
-- | |
| 418 |
-- +-- Child scenario 1 |
| 419 |
-- | | |
| 420 |
-- | +-- Grandchild scenario 1 |
| 421 |
-- | | |
| 422 |
-- | +-- Grandchild scenario N |
| 423 |
-- | |
| 424 |
-- +-- Child scenario N |
| 425 |
-- |
| 426 |
-- If the root scenario has elaboration warnings suppressed, then all its |
| 427 |
-- child, grandchild, etc. scenarios will have their elaboration warnings |
| 428 |
-- suppressed. |
| 429 |
-- |
| 430 |
-- In addition to switch -gnatwL, pragma Warnings may be used to suppress |
| 431 |
-- elaboration-related warnings when used in the following manner: |
| 432 |
-- |
| 433 |
-- pragma Warnings ("L"); |
| 434 |
-- <scenario-or-target> |
| 435 |
-- |
| 436 |
-- <target> |
| 437 |
-- pragma Warnings (Off, target); |
| 438 |
-- |
| 439 |
-- pragma Warnings (Off); |
| 440 |
-- <scenario-or-target> |
| 441 |
-- |
| 442 |
-- * To suppress elaboration warnings for '[Unrestricted_]Access of |
| 443 |
-- entries, operators, and subprograms, either: |
| 444 |
-- |
| 445 |
-- - Suppress the entry, operator, or subprogram, or |
| 446 |
-- - Suppress the attribute, or |
| 447 |
-- - Use switch -gnatw.f |
| 448 |
-- |
| 449 |
-- * To suppress elaboration warnings for calls to entries, operators, |
| 450 |
-- and subprograms, either: |
| 451 |
-- |
| 452 |
-- - Suppress the entry, operator, or subprogram, or |
| 453 |
-- - Suppress the call |
| 454 |
-- |
| 455 |
-- * To suppress elaboration warnings for instantiations, suppress the |
| 456 |
-- instantiation. |
| 457 |
-- |
| 458 |
-- * To suppress elaboration warnings for task activations, either: |
| 459 |
-- |
| 460 |
-- - Suppress the task object, or |
| 461 |
-- - Suppress the task type, or |
| 462 |
-- - Suppress the activation call |
| 463 |
|
| 464 |
-------------- |
| 465 |
-- Switches -- |
| 466 |
-------------- |
| 467 |
|
| 468 |
-- The following switches may be used to control the behavior of the ABE |
| 469 |
-- mechanism. |
| 470 |
-- |
| 471 |
-- -gnatd_a stop elaboration checks on accept or select statement |
| 472 |
-- |
| 473 |
-- The ABE mechanism stops the traversal of a task body when it |
| 474 |
-- encounters an accept or a select statement. This behavior is |
| 475 |
-- equivalent to restriction No_Entry_Calls_In_Elaboration_Code, |
| 476 |
-- but without penalizing actual entry calls during elaboration. |
| 477 |
-- |
| 478 |
-- -gnatd_e ignore entry calls and requeue statements for elaboration |
| 479 |
-- |
| 480 |
-- The ABE mechanism does not generate N_Call_Marker nodes for |
| 481 |
-- protected or task entry calls as well as requeue statements. |
| 482 |
-- As a result, the calls and requeues are not recorded or |
| 483 |
-- processed. |
| 484 |
-- |
| 485 |
-- -gnatdE elaboration checks on predefined units |
| 486 |
-- |
| 487 |
-- The ABE mechanism considers scenarios which appear in internal |
| 488 |
-- units (Ada, GNAT, Interfaces, System). |
| 489 |
-- |
| 490 |
-- -gnatd_F encode full invocation paths in ALI files |
| 491 |
-- |
| 492 |
-- The ABE mechanism encodes the full path from an elaboration |
| 493 |
-- procedure or invocable construct to an external target. The |
| 494 |
-- path contains all intermediate activations, instantiations, |
| 495 |
-- and calls. |
| 496 |
-- |
| 497 |
-- -gnatd.G ignore calls through generic formal parameters for elaboration |
| 498 |
-- |
| 499 |
-- The ABE mechanism does not generate N_Call_Marker nodes for |
| 500 |
-- calls which occur in expanded instances, and invoke generic |
| 501 |
-- actual subprograms through generic formal subprograms. As a |
| 502 |
-- result, the calls are not recorded or processed. |
| 503 |
-- |
| 504 |
-- -gnatd_i ignore activations and calls to instances for elaboration |
| 505 |
-- |
| 506 |
-- The ABE mechanism ignores calls and task activations when they |
| 507 |
-- target a subprogram or task type defined an external instance. |
| 508 |
-- As a result, the calls and task activations are not processed. |
| 509 |
-- |
| 510 |
-- -gnatdL ignore external calls from instances for elaboration |
| 511 |
-- |
| 512 |
-- The ABE mechanism does not generate N_Call_Marker nodes for |
| 513 |
-- calls which occur in expanded instances, do not invoke generic |
| 514 |
-- actual subprograms through formal subprograms, and the target |
| 515 |
-- is external to the instance. As a result, the calls are not |
| 516 |
-- recorded or processed. |
| 517 |
-- |
| 518 |
-- -gnatd.o conservative elaboration order for indirect calls |
| 519 |
-- |
| 520 |
-- The ABE mechanism treats '[Unrestricted_]Access of an entry, |
| 521 |
-- operator, or subprogram as an immediate invocation of the |
| 522 |
-- target. As a result, it performs ABE checks and diagnostics on |
| 523 |
-- the immediate call. |
| 524 |
-- |
| 525 |
-- -gnatd_p ignore assertion pragmas for elaboration |
| 526 |
-- |
| 527 |
-- The ABE mechanism does not generate N_Call_Marker nodes for |
| 528 |
-- calls to subprograms which verify the run-time semantics of |
| 529 |
-- the following assertion pragmas: |
| 530 |
-- |
| 531 |
-- Default_Initial_Condition |
| 532 |
-- Initial_Condition |
| 533 |
-- Invariant |
| 534 |
-- Invariant'Class |
| 535 |
-- Post |
| 536 |
-- Post'Class |
| 537 |
-- Postcondition |
| 538 |
-- Type_Invariant |
| 539 |
-- Type_Invariant_Class |
| 540 |
-- |
| 541 |
-- As a result, the assertion expressions of the pragmas are not |
| 542 |
-- processed. |
| 543 |
-- |
| 544 |
-- -gnatd_s stop elaboration checks on synchronous suspension |
| 545 |
-- |
| 546 |
-- The ABE mechanism stops the traversal of a task body when it |
| 547 |
-- encounters a call to one of the following routines: |
| 548 |
-- |
| 549 |
-- Ada.Synchronous_Barriers.Wait_For_Release |
| 550 |
-- Ada.Synchronous_Task_Control.Suspend_Until_True |
| 551 |
-- |
| 552 |
-- -gnatd_T output trace information on invocation relation construction |
| 553 |
-- |
| 554 |
-- The ABE mechanism outputs text information concerning relation |
| 555 |
-- construction to standard output. |
| 556 |
-- |
| 557 |
-- -gnatd.U ignore indirect calls for static elaboration |
| 558 |
-- |
| 559 |
-- The ABE mechanism does not consider '[Unrestricted_]Access of |
| 560 |
-- entries, operators, and subprograms. As a result, the scenarios |
| 561 |
-- are not recorder or processed. |
| 562 |
-- |
| 563 |
-- -gnatd.v enforce SPARK elaboration rules in SPARK code |
| 564 |
-- |
| 565 |
-- The ABE mechanism applies some of the SPARK elaboration rules |
| 566 |
-- defined in the SPARK reference manual, chapter 7.7. Note that |
| 567 |
-- certain rules are always enforced, regardless of whether the |
| 568 |
-- switch is active. |
| 569 |
-- |
| 570 |
-- -gnatd.y disable implicit pragma Elaborate_All on task bodies |
| 571 |
-- |
| 572 |
-- The ABE mechanism does not generate implicit Elaborate_All when |
| 573 |
-- the need for the pragma came from a task body. |
| 574 |
-- |
| 575 |
-- -gnatE dynamic elaboration checking mode enabled |
| 576 |
-- |
| 577 |
-- The ABE mechanism assumes that any scenario is elaborated or |
| 578 |
-- invoked by elaboration code. The ABE mechanism performs very |
| 579 |
-- little diagnostics and generates condintional ABE checks to |
| 580 |
-- detect ABE issues at run-time. |
| 581 |
-- |
| 582 |
-- -gnatel turn on info messages on generated Elaborate[_All] pragmas |
| 583 |
-- |
| 584 |
-- The ABE mechanism produces information messages on generated |
| 585 |
-- implicit Elabote[_All] pragmas along with traceback showing |
| 586 |
-- why the pragma was generated. In addition, the ABE mechanism |
| 587 |
-- produces information messages for each scenario elaborated or |
| 588 |
-- invoked by elaboration code. |
| 589 |
-- |
| 590 |
-- -gnateL turn off info messages on generated Elaborate[_All] pragmas |
| 591 |
-- |
| 592 |
-- The complementary switch for -gnatel. |
| 593 |
-- |
| 594 |
-- -gnatH legacy elaboration checking mode enabled |
| 595 |
-- |
| 596 |
-- When this switch is in effect, the pre-18.x ABE model becomes |
| 597 |
-- the de facto ABE model. This amounts to cutting off all entry |
| 598 |
-- points into the new ABE mechanism, and giving full control to |
| 599 |
-- the old ABE mechanism. |
| 600 |
-- |
| 601 |
-- -gnatJ permissive elaboration checking mode enabled |
| 602 |
-- |
| 603 |
-- This switch activates the following switches: |
| 604 |
-- |
| 605 |
-- -gnatd_a |
| 606 |
-- -gnatd_e |
| 607 |
-- -gnatd.G |
| 608 |
-- -gnatd_i |
| 609 |
-- -gnatdL |
| 610 |
-- -gnatd_p |
| 611 |
-- -gnatd_s |
| 612 |
-- -gnatd.U |
| 613 |
-- -gnatd.y |
| 614 |
-- |
| 615 |
-- IMPORTANT: The behavior of the ABE mechanism becomes more |
| 616 |
-- permissive at the cost of accurate diagnostics and runtime |
| 617 |
-- ABE checks. |
| 618 |
-- |
| 619 |
-- -gnatw.f turn on warnings for suspicious Subp'Access |
| 620 |
-- |
| 621 |
-- The ABE mechanism treats '[Unrestricted_]Access of an entry, |
| 622 |
-- operator, or subprogram as a pseudo invocation of the target. |
| 623 |
-- As a result, it performs ABE diagnostics on the pseudo call. |
| 624 |
-- |
| 625 |
-- -gnatw.F turn off warnings for suspicious Subp'Access |
| 626 |
-- |
| 627 |
-- The complementary switch for -gnatw.f. |
| 628 |
-- |
| 629 |
-- -gnatwl turn on warnings for elaboration problems |
| 630 |
-- |
| 631 |
-- The ABE mechanism produces warnings on detected ABEs along with |
| 632 |
-- a traceback showing the graph of the ABE. |
| 633 |
-- |
| 634 |
-- -gnatwL turn off warnings for elaboration problems |
| 635 |
-- |
| 636 |
-- The complementary switch for -gnatwl. |
| 637 |
|
| 638 |
-------------------------- |
| 639 |
-- Debugging ABE issues -- |
| 640 |
-------------------------- |
| 641 |
|
| 642 |
-- * If the issue involves a call, ensure that the call is eligible for ABE |
| 643 |
-- processing and receives a corresponding call marker. The routines of |
| 644 |
-- interest are |
| 645 |
-- |
| 646 |
-- Build_Call_Marker |
| 647 |
-- Record_Elaboration_Scenario |
| 648 |
-- |
| 649 |
-- * If the issue involves an arbitrary scenario, ensure that the scenario |
| 650 |
-- is either recorded, or is successfully recognized while traversing a |
| 651 |
-- body. The routines of interest are |
| 652 |
-- |
| 653 |
-- Record_Elaboration_Scenario |
| 654 |
-- Process_Conditional_ABE |
| 655 |
-- Process_Guaranteed_ABE |
| 656 |
-- Traverse_Body |
| 657 |
-- |
| 658 |
-- * If the issue involves a circularity in the elaboration order, examine |
| 659 |
-- the ALI files and look for the following encodings next to units: |
| 660 |
-- |
| 661 |
-- E indicates a source Elaborate |
| 662 |
-- |
| 663 |
-- EA indicates a source Elaborate_All |
| 664 |
-- |
| 665 |
-- AD indicates an implicit Elaborate_All |
| 666 |
-- |
| 667 |
-- ED indicates an implicit Elaborate |
| 668 |
-- |
| 669 |
-- If possible, compare these encodings with those generated by the old |
| 670 |
-- ABE mechanism. The routines of interest are |
| 671 |
-- |
| 672 |
-- Ensure_Prior_Elaboration |
| 673 |
|
| 674 |
----------- |
| 675 |
-- Kinds -- |
| 676 |
----------- |
| 677 |
|
| 678 |
-- The following type enumerates all possible elaboration phase statutes |
| 679 |
|
| 680 |
type Elaboration_Phase_Status is |
| 681 |
(Inactive, |
| 682 |
-- The elaboration phase of the compiler has not started yet |
| 683 |
|
| 684 |
Active, |
| 685 |
-- The elaboration phase of the compiler is currently in progress |
| 686 |
|
| 687 |
Completed); |
| 688 |
-- The elaboration phase of the compiler has finished |
| 689 |
|
| 690 |
Elaboration_Phase : Elaboration_Phase_Status := Inactive; |
| 691 |
-- The status of the elaboration phase. Use routine Set_Elaboration_Phase |
| 692 |
-- to alter its value. |
| 693 |
|
| 694 |
-- The following type enumerates all subprogram body traversal modes |
| 695 |
|
| 696 |
type Body_Traversal_Kind is |
| 697 |
(Deep_Traversal, |
| 698 |
-- The traversal examines the internals of a subprogram |
| 699 |
|
| 700 |
No_Traversal); |
| 701 |
|
| 702 |
-- The following type enumerates all operation modes |
| 703 |
|
| 704 |
type Processing_Kind is |
| 705 |
(Conditional_ABE_Processing, |
| 706 |
-- The ABE mechanism detects and diagnoses conditional ABEs for library |
| 707 |
-- and declaration-level scenarios. |
| 708 |
|
| 709 |
Dynamic_Model_Processing, |
| 710 |
-- The ABE mechanism installs conditional ABE checks for all eligible |
| 711 |
-- scenarios when the dynamic model is in effect. |
| 712 |
|
| 713 |
Guaranteed_ABE_Processing, |
| 714 |
-- The ABE mechanism detects and diagnoses guaranteed ABEs caused by |
| 715 |
-- calls, instantiations, and task activations. |
| 716 |
|
| 717 |
Invocation_Construct_Processing, |
| 718 |
-- The ABE mechanism locates all invocation constructs within the main |
| 719 |
-- unit and utilizes them as roots of miltiple DFS traversals aimed at |
| 720 |
-- detecting transitions from the main unit to an external unit. |
| 721 |
|
| 722 |
Invocation_Body_Processing, |
| 723 |
-- The ABE mechanism utilizes all library-level body scenarios as roots |
| 724 |
-- of miltiple DFS traversals aimed at detecting transitions from the |
| 725 |
-- main unit to an external unit. |
| 726 |
|
| 727 |
Invocation_Spec_Processing, |
| 728 |
-- The ABE mechanism utilizes all library-level spec scenarios as roots |
| 729 |
-- of miltiple DFS traversals aimed at detecting transitions from the |
| 730 |
-- main unit to an external unit. |
| 731 |
|
| 732 |
SPARK_Processing, |
| 733 |
-- The ABE mechanism detects and diagnoses violations of the SPARK |
| 734 |
-- elaboration rules for SPARK-specific scenarios. |
| 735 |
|
| 736 |
No_Processing); |
| 737 |
|
| 738 |
-- The following type enumerates all possible scenario kinds |
| 739 |
|
| 740 |
type Scenario_Kind is |
| 741 |
(Access_Taken_Scenario, |
| 742 |
-- An attribute reference which takes 'Access or 'Unrestricted_Access of |
| 743 |
-- an entry, operator, or subprogram. |
| 744 |
|
| 745 |
Call_Scenario, |
| 746 |
-- A call which invokes an entry, operator, or subprogram |
| 747 |
|
| 748 |
Derived_Type_Scenario, |
| 749 |
-- A declaration of a derived type. This is a SPARK-specific scenario. |
| 750 |
|
| 751 |
Instantiation_Scenario, |
| 752 |
-- An instantiation which instantiates a generic package or subprogram. |
| 753 |
-- This scenario is also subject to SPARK-specific rules. |
| 754 |
|
| 755 |
Refined_State_Pragma_Scenario, |
| 756 |
-- A Refined_State pragma. This is a SPARK-specific scenario. |
| 757 |
|
| 758 |
Task_Activation_Scenario, |
| 759 |
-- A call which activates objects of various task types |
| 760 |
|
| 761 |
Variable_Assignment_Scenario, |
| 762 |
-- An assignment statement which modifies the value of some variable |
| 763 |
|
| 764 |
Variable_Reference_Scenario, |
| 765 |
-- A reference to a variable. This is a SPARK-specific scenario. |
| 766 |
|
| 767 |
No_Scenario); |
| 768 |
|
| 769 |
-- The following type enumerates all possible consistency models of target |
| 770 |
-- and scenario representations. |
| 771 |
|
| 772 |
type Representation_Kind is |
| 773 |
(Inconsistent_Representation, |
| 774 |
-- A representation is said to be "inconsistent" when it is created from |
| 775 |
-- a partially analyzed tree. In such an environment, certain attributes |
| 776 |
-- such as a completing body may not be available yet. |
| 777 |
|
| 778 |
Consistent_Representation, |
| 779 |
-- A representation is said to be "consistent" when it is created from a |
| 780 |
-- fully analyzed tree, where all attributes are available. |
| 781 |
|
| 782 |
No_Representation); |
| 783 |
|
| 784 |
-- The following type enumerates all possible target kinds |
| 785 |
|
| 786 |
type Target_Kind is |
| 787 |
(Generic_Target, |
| 788 |
-- A generic unit being instantiated |
| 789 |
|
| 790 |
Package_Target, |
| 791 |
-- The package form of an instantiation |
| 792 |
|
| 793 |
Subprogram_Target, |
| 794 |
-- An entry, operator, or subprogram being invoked, or aliased through |
| 795 |
-- 'Access or 'Unrestricted_Access. |
| 796 |
|
| 797 |
Task_Target, |
| 798 |
-- A task being activated by an activation call |
| 799 |
|
| 800 |
Variable_Target, |
| 801 |
-- A variable being updated through an assignment statement, or read |
| 802 |
-- through a variable reference. |
| 803 |
|
| 804 |
No_Target); |
| 805 |
|
| 806 |
----------- |
| 807 |
-- Types -- |
| 808 |
----------- |
| 809 |
|
| 810 |
procedure Destroy (NE : in out Node_Or_Entity_Id); |
| 811 |
pragma Inline (Destroy); |
| 812 |
-- Destroy node or entity NE |
| 813 |
|
| 814 |
function Hash (NE : Node_Or_Entity_Id) return Bucket_Range_Type; |
| 815 |
pragma Inline (Hash); |
| 816 |
-- Obtain the hash value of key NE |
| 817 |
|
| 818 |
-- The following is a general purpose list for nodes and entities |
| 819 |
|
| 820 |
package NE_List is new Doubly_Linked_Lists |
| 821 |
(Element_Type => Node_Or_Entity_Id, |
| 822 |
"=" => "=", |
| 823 |
Destroy_Element => Destroy); |
| 824 |
|
| 825 |
-- The following is a general purpose map which relates nodes and entities |
| 826 |
-- to lists of nodes and entities. |
| 827 |
|
| 828 |
package NE_List_Map is new Dynamic_Hash_Tables |
| 829 |
(Key_Type => Node_Or_Entity_Id, |
| 830 |
Value_Type => NE_List.Doubly_Linked_List, |
| 831 |
No_Value => NE_List.Nil, |
| 832 |
Expansion_Threshold => 1.5, |
| 833 |
Expansion_Factor => 2, |
| 834 |
Compression_Threshold => 0.3, |
| 835 |
Compression_Factor => 2, |
| 836 |
"=" => "=", |
| 837 |
Destroy_Value => NE_List.Destroy, |
| 838 |
Hash => Hash); |
| 839 |
|
| 840 |
-- The following is a general purpose membership set for nodes and entities |
| 841 |
|
| 842 |
package NE_Set is new Membership_Sets |
| 843 |
(Element_Type => Node_Or_Entity_Id, |
| 844 |
"=" => "=", |
| 845 |
Hash => Hash); |
| 846 |
|
| 847 |
-- The following type captures relevant attributes which pertain to the |
| 848 |
-- in state of the Processing phase. |
| 849 |
|
| 850 |
type Processing_In_State is record |
| 851 |
Processing : Processing_Kind := No_Processing; |
| 852 |
-- Operation mode of the Processing phase. Once set, this value should |
| 853 |
-- not be changed. |
| 854 |
|
| 855 |
Representation : Representation_Kind := No_Representation; |
| 856 |
-- Required level of scenario and target representation. Once set, this |
| 857 |
-- value should not be changed. |
| 858 |
|
| 859 |
Suppress_Checks : Boolean := False; |
| 860 |
-- This flag is set when the Processing phase must not generate any ABE |
| 861 |
-- checks. |
| 862 |
|
| 863 |
Suppress_Implicit_Pragmas : Boolean := False; |
| 864 |
-- This flag is set when the Processing phase must not generate any |
| 865 |
-- implicit Elaborate[_All] pragmas. |
| 866 |
|
| 867 |
Suppress_Info_Messages : Boolean := False; |
| 868 |
-- This flag is set when the Processing phase must not emit any info |
| 869 |
-- messages. |
| 870 |
|
| 871 |
Suppress_Up_Level_Targets : Boolean := False; |
| 872 |
-- This flag is set when the Processing phase must ignore up-level |
| 873 |
-- targets. |
| 874 |
|
| 875 |
Suppress_Warnings : Boolean := False; |
| 876 |
-- This flag is set when the Processing phase must not emit any warnings |
| 877 |
-- on elaboration problems. |
| 878 |
|
| 879 |
Traversal : Body_Traversal_Kind := No_Traversal; |
| 880 |
-- The subprogram body traversal mode. Once set, this value should not |
| 881 |
-- be changed. |
| 882 |
|
| 883 |
Within_Freezing_Actions : Boolean := False; |
| 884 |
-- This flag is set when the Processing phase is currently examining a |
| 885 |
-- scenario which was reached from the actions of a freeze node. |
| 886 |
|
| 887 |
Within_Generic : Boolean := False; |
| 888 |
-- This flag is set when the Processing phase is currently within a |
| 889 |
-- generic unit. |
| 890 |
|
| 891 |
Within_Initial_Condition : Boolean := False; |
| 892 |
-- This flag is set when the Processing phase is currently examining a |
| 893 |
-- scenario which was reached from an initial condition procedure. |
| 894 |
|
| 895 |
Within_Partial_Finalization : Boolean := False; |
| 896 |
-- This flag is set when the Processing phase is currently examining a |
| 897 |
-- scenario which was reached from a partial finalization procedure. |
| 898 |
|
| 899 |
Within_Task_Body : Boolean := False; |
| 900 |
-- This flag is set when the Processing phase is currently examining a |
| 901 |
-- scenario which was reached from a task body. |
| 902 |
end record; |
| 903 |
|
| 904 |
-- The following constants define the various operational states of the |
| 905 |
-- Processing phase. |
| 906 |
|
| 907 |
-- The conditional ABE state is used when processing scenarios that appear |
| 908 |
-- at the declaration, instantiation, and library levels to detect errors |
| 909 |
-- and install conditional ABE checks. |
| 910 |
|
| 911 |
Conditional_ABE_State : constant Processing_In_State := |
| 912 |
(Processing => Conditional_ABE_Processing, |
| 913 |
Representation => Consistent_Representation, |
| 914 |
Traversal => Deep_Traversal, |
| 915 |
others => False); |
| 916 |
|
| 917 |
-- The dynamic model state is used to install conditional ABE checks when |
| 918 |
-- switch -gnatE (dynamic elaboration checking mode enabled) is in effect. |
| 919 |
|
| 920 |
Dynamic_Model_State : constant Processing_In_State := |
| 921 |
(Processing => Dynamic_Model_Processing, |
| 922 |
Representation => Consistent_Representation, |
| 923 |
Suppress_Implicit_Pragmas => True, |
| 924 |
Suppress_Info_Messages => True, |
| 925 |
Suppress_Up_Level_Targets => True, |
| 926 |
Suppress_Warnings => True, |
| 927 |
Traversal => No_Traversal, |
| 928 |
others => False); |
| 929 |
|
| 930 |
-- The guaranteed ABE state is used when processing scenarios that appear |
| 931 |
-- at the declaration, instantiation, and library levels to detect errors |
| 932 |
-- and install guarateed ABE failures. |
| 933 |
|
| 934 |
Guaranteed_ABE_State : constant Processing_In_State := |
| 935 |
(Processing => Guaranteed_ABE_Processing, |
| 936 |
Representation => Inconsistent_Representation, |
| 937 |
Suppress_Implicit_Pragmas => True, |
| 938 |
Traversal => No_Traversal, |
| 939 |
others => False); |
| 940 |
|
| 941 |
-- The invocation body state is used when processing scenarios that appear |
| 942 |
-- at the body library level to encode paths that start from elaboration |
| 943 |
-- code and ultimately reach into external units. |
| 944 |
|
| 945 |
Invocation_Body_State : constant Processing_In_State := |
| 946 |
(Processing => Invocation_Body_Processing, |
| 947 |
Representation => Consistent_Representation, |
| 948 |
Suppress_Checks => True, |
| 949 |
Suppress_Implicit_Pragmas => True, |
| 950 |
Suppress_Info_Messages => True, |
| 951 |
Suppress_Up_Level_Targets => True, |
| 952 |
Suppress_Warnings => True, |
| 953 |
Traversal => Deep_Traversal, |
| 954 |
others => False); |
| 955 |
|
| 956 |
-- The invocation construct state is used when processing constructs that |
| 957 |
-- appear within the spec and body of the main unit and eventually reach |
| 958 |
-- into external units. |
| 959 |
|
| 960 |
Invocation_Construct_State : constant Processing_In_State := |
| 961 |
(Processing => Invocation_Construct_Processing, |
| 962 |
Representation => Consistent_Representation, |
| 963 |
Suppress_Checks => True, |
| 964 |
Suppress_Implicit_Pragmas => True, |
| 965 |
Suppress_Info_Messages => True, |
| 966 |
Suppress_Up_Level_Targets => True, |
| 967 |
Suppress_Warnings => True, |
| 968 |
Traversal => Deep_Traversal, |
| 969 |
others => False); |
| 970 |
|
| 971 |
-- The invocation spec state is used when processing scenarios that appear |
| 972 |
-- at the spec library level to encode paths that start from elaboration |
| 973 |
-- code and ultimately reach into external units. |
| 974 |
|
| 975 |
Invocation_Spec_State : constant Processing_In_State := |
| 976 |
(Processing => Invocation_Spec_Processing, |
| 977 |
Representation => Consistent_Representation, |
| 978 |
Suppress_Checks => True, |
| 979 |
Suppress_Implicit_Pragmas => True, |
| 980 |
Suppress_Info_Messages => True, |
| 981 |
Suppress_Up_Level_Targets => True, |
| 982 |
Suppress_Warnings => True, |
| 983 |
Traversal => Deep_Traversal, |
| 984 |
others => False); |
| 985 |
|
| 986 |
-- The SPARK state is used when verying SPARK-specific semantics of certain |
| 987 |
-- scenarios. |
| 988 |
|
| 989 |
SPARK_State : constant Processing_In_State := |
| 990 |
(Processing => SPARK_Processing, |
| 991 |
Representation => Consistent_Representation, |
| 992 |
Traversal => No_Traversal, |
| 993 |
others => False); |
| 994 |
|
| 995 |
-- The following type identifies a scenario representation |
| 996 |
|
| 997 |
type Scenario_Rep_Id is new Natural; |
| 998 |
|
| 999 |
No_Scenario_Rep : constant Scenario_Rep_Id := Scenario_Rep_Id'First; |
| 1000 |
First_Scenario_Rep : constant Scenario_Rep_Id := No_Scenario_Rep + 1; |
| 1001 |
|
| 1002 |
-- The following type identifies a target representation |
| 1003 |
|
| 1004 |
type Target_Rep_Id is new Natural; |
| 1005 |
|
| 1006 |
No_Target_Rep : constant Target_Rep_Id := Target_Rep_Id'First; |
| 1007 |
First_Target_Rep : constant Target_Rep_Id := No_Target_Rep + 1; |
| 1008 |
|
| 1009 |
-------------- |
| 1010 |
-- Services -- |
| 1011 |
-------------- |
| 1012 |
|
| 1013 |
-- The following package keeps track of all active scenarios during a DFS |
| 1014 |
-- traversal. |
| 1015 |
|
| 1016 |
package Active_Scenarios is |
| 1017 |
|
| 1018 |
----------- |
| 1019 |
-- Types -- |
| 1020 |
----------- |
| 1021 |
|
| 1022 |
-- The following type defines the position within the active scenario |
| 1023 |
-- stack. |
| 1024 |
|
| 1025 |
type Active_Scenario_Pos is new Natural; |
| 1026 |
|
| 1027 |
--------------------- |
| 1028 |
-- Data structures -- |
| 1029 |
--------------------- |
| 1030 |
|
| 1031 |
-- The following table stores all active scenarios in a DFS traversal. |
| 1032 |
-- This table must be maintained in a FIFO fashion. |
| 1033 |
|
| 1034 |
package Active_Scenario_Stack is new Table.Table |
| 1035 |
(Table_Index_Type => Active_Scenario_Pos, |
| 1036 |
Table_Component_Type => Node_Id, |
| 1037 |
Table_Low_Bound => 1, |
| 1038 |
Table_Initial => 50, |
| 1039 |
Table_Increment => 200, |
| 1040 |
Table_Name => "Active_Scenario_Stack"); |
| 1041 |
|
| 1042 |
--------- |
| 1043 |
-- API -- |
| 1044 |
--------- |
| 1045 |
|
| 1046 |
procedure Output_Active_Scenarios |
| 1047 |
(Error_Nod : Node_Id; |
| 1048 |
In_State : Processing_In_State); |
| 1049 |
pragma Inline (Output_Active_Scenarios); |
| 1050 |
-- Output the contents of the active scenario stack from earliest to |
| 1051 |
-- latest to supplement an earlier error emitted for node Error_Nod. |
| 1052 |
-- In_State denotes the current state of the Processing phase. |
| 1053 |
|
| 1054 |
procedure Pop_Active_Scenario (N : Node_Id); |
| 1055 |
pragma Inline (Pop_Active_Scenario); |
| 1056 |
-- Pop the top of the scenario stack. A check is made to ensure that the |
| 1057 |
-- scenario being removed is the same as N. |
| 1058 |
|
| 1059 |
procedure Push_Active_Scenario (N : Node_Id); |
| 1060 |
pragma Inline (Push_Active_Scenario); |
| 1061 |
-- Push scenario N on top of the scenario stack |
| 1062 |
|
| 1063 |
function Root_Scenario return Node_Id; |
| 1064 |
pragma Inline (Root_Scenario); |
| 1065 |
-- Return the scenario which started a DFS traversal |
| 1066 |
|
| 1067 |
end Active_Scenarios; |
| 1068 |
use Active_Scenarios; |
| 1069 |
|
| 1070 |
-- The following package provides the main entry point for task activation |
| 1071 |
-- processing. |
| 1072 |
|
| 1073 |
package Activation_Processor is |
| 1074 |
|
| 1075 |
----------- |
| 1076 |
-- Types -- |
| 1077 |
----------- |
| 1078 |
|
| 1079 |
type Activation_Processor_Ptr is access procedure |
| 1080 |
(Call : Node_Id; |
| 1081 |
Call_Rep : Scenario_Rep_Id; |
| 1082 |
Obj_Id : Entity_Id; |
| 1083 |
Obj_Rep : Target_Rep_Id; |
| 1084 |
Task_Typ : Entity_Id; |
| 1085 |
Task_Rep : Target_Rep_Id; |
| 1086 |
In_State : Processing_In_State); |
| 1087 |
-- Reference to a procedure that takes all attributes of an activation |
| 1088 |
-- and performs a desired action. Call is the activation call. Call_Rep |
| 1089 |
-- is the representation of the call. Obj_Id is the task object being |
| 1090 |
-- activated. Obj_Rep is the representation of the object. Task_Typ is |
| 1091 |
-- the task type whose body is being activated. Task_Rep denotes the |
| 1092 |
-- representation of the task type. In_State is the current state of |
| 1093 |
-- the Processing phase. |
| 1094 |
|
| 1095 |
--------- |
| 1096 |
-- API -- |
| 1097 |
--------- |
| 1098 |
|
| 1099 |
procedure Process_Activation |
| 1100 |
(Call : Node_Id; |
| 1101 |
Call_Rep : Scenario_Rep_Id; |
| 1102 |
Processor : Activation_Processor_Ptr; |
| 1103 |
In_State : Processing_In_State); |
| 1104 |
-- Find all task objects activated by activation call Call and invoke |
| 1105 |
-- Processor on them. Call_Rep denotes the representation of the call. |
| 1106 |
-- In_State is the current state of the Processing phase. |
| 1107 |
|
| 1108 |
end Activation_Processor; |
| 1109 |
use Activation_Processor; |
| 1110 |
|
| 1111 |
-- The following package profides functionality for traversing subprogram |
| 1112 |
-- bodies in DFS manner and processing of eligible scenarios within. |
| 1113 |
|
| 1114 |
package Body_Processor is |
| 1115 |
|
| 1116 |
----------- |
| 1117 |
-- Types -- |
| 1118 |
----------- |
| 1119 |
|
| 1120 |
type Scenario_Predicate_Ptr is access function |
| 1121 |
(N : Node_Id) return Boolean; |
| 1122 |
-- Reference to a function which determines whether arbitrary node N |
| 1123 |
-- denotes a suitable scenario for processing. |
| 1124 |
|
| 1125 |
type Scenario_Processor_Ptr is access procedure |
| 1126 |
(N : Node_Id; In_State : Processing_In_State); |
| 1127 |
-- Reference to a procedure which processes scenario N. In_State is the |
| 1128 |
-- current state of the Processing phase. |
| 1129 |
|
| 1130 |
--------- |
| 1131 |
-- API -- |
| 1132 |
--------- |
| 1133 |
|
| 1134 |
procedure Traverse_Body |
| 1135 |
(N : Node_Id; |
| 1136 |
Requires_Processing : Scenario_Predicate_Ptr; |
| 1137 |
Processor : Scenario_Processor_Ptr; |
| 1138 |
In_State : Processing_In_State); |
| 1139 |
pragma Inline (Traverse_Body); |
| 1140 |
-- Traverse the declarations and handled statements of subprogram body |
| 1141 |
-- N, looking for scenarios that satisfy predicate Requires_Processing. |
| 1142 |
-- Routine Processor is invoked for each such scenario. |
| 1143 |
|
| 1144 |
procedure Reset_Traversed_Bodies; |
| 1145 |
pragma Inline (Reset_Traversed_Bodies); |
| 1146 |
-- Reset the visited status of all subprogram bodies that have already |
| 1147 |
-- been processed by routine Traverse_Body. |
| 1148 |
|
| 1149 |
----------------- |
| 1150 |
-- Maintenance -- |
| 1151 |
----------------- |
| 1152 |
|
| 1153 |
procedure Finalize_Body_Processor; |
| 1154 |
pragma Inline (Finalize_Body_Processor); |
| 1155 |
-- Finalize all internal data structures |
| 1156 |
|
| 1157 |
procedure Initialize_Body_Processor; |
| 1158 |
pragma Inline (Initialize_Body_Processor); |
| 1159 |
-- Initialize all internal data structures |
| 1160 |
|
| 1161 |
end Body_Processor; |
| 1162 |
use Body_Processor; |
| 1163 |
|
| 1164 |
-- The following package provides functionality for installing ABE-related |
| 1165 |
-- checks and failures. |
| 1166 |
|
| 1167 |
package Check_Installer is |
| 1168 |
|
| 1169 |
--------- |
| 1170 |
-- API -- |
| 1171 |
--------- |
| 1172 |
|
| 1173 |
function Check_Or_Failure_Generation_OK return Boolean; |
| 1174 |
pragma Inline (Check_Or_Failure_Generation_OK); |
| 1175 |
-- Determine whether a conditional ABE check or guaranteed ABE failure |
| 1176 |
-- can be generated. |
| 1177 |
|
| 1178 |
procedure Install_Dynamic_ABE_Checks; |
| 1179 |
pragma Inline (Install_Dynamic_ABE_Checks); |
| 1180 |
-- Install conditional ABE checks for all saved scenarios when the |
| 1181 |
-- dynamic model is in effect. |
| 1182 |
|
| 1183 |
procedure Install_Scenario_ABE_Check |
| 1184 |
(N : Node_Id; |
| 1185 |
Targ_Id : Entity_Id; |
| 1186 |
Targ_Rep : Target_Rep_Id; |
| 1187 |
Disable : Scenario_Rep_Id); |
| 1188 |
pragma Inline (Install_Scenario_ABE_Check); |
| 1189 |
-- Install a conditional ABE check for scenario N to ensure that target |
| 1190 |
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the |
| 1191 |
-- target. If the check is installed, disable the elaboration checks of |
| 1192 |
-- scenario Disable. |
| 1193 |
|
| 1194 |
procedure Install_Scenario_ABE_Check |
| 1195 |
(N : Node_Id; |
| 1196 |
Targ_Id : Entity_Id; |
| 1197 |
Targ_Rep : Target_Rep_Id; |
| 1198 |
Disable : Target_Rep_Id); |
| 1199 |
pragma Inline (Install_Scenario_ABE_Check); |
| 1200 |
-- Install a conditional ABE check for scenario N to ensure that target |
| 1201 |
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the |
| 1202 |
-- target. If the check is installed, disable the elaboration checks of |
| 1203 |
-- target Disable. |
| 1204 |
|
| 1205 |
procedure Install_Scenario_ABE_Failure |
| 1206 |
(N : Node_Id; |
| 1207 |
Targ_Id : Entity_Id; |
| 1208 |
Targ_Rep : Target_Rep_Id; |
| 1209 |
Disable : Scenario_Rep_Id); |
| 1210 |
pragma Inline (Install_Scenario_ABE_Failure); |
| 1211 |
-- Install a guaranteed ABE failure for scenario N with target Targ_Id. |
| 1212 |
-- Targ_Rep denotes the representation of the target. If the failure is |
| 1213 |
-- installed, disable the elaboration checks of scenario Disable. |
| 1214 |
|
| 1215 |
procedure Install_Scenario_ABE_Failure |
| 1216 |
(N : Node_Id; |
| 1217 |
Targ_Id : Entity_Id; |
| 1218 |
Targ_Rep : Target_Rep_Id; |
| 1219 |
Disable : Target_Rep_Id); |
| 1220 |
pragma Inline (Install_Scenario_ABE_Failure); |
| 1221 |
-- Install a guaranteed ABE failure for scenario N with target Targ_Id. |
| 1222 |
-- Targ_Rep denotes the representation of the target. If the failure is |
| 1223 |
-- installed, disable the elaboration checks of target Disable. |
| 1224 |
|
| 1225 |
procedure Install_Unit_ABE_Check |
| 1226 |
(N : Node_Id; |
| 1227 |
Unit_Id : Entity_Id; |
| 1228 |
Disable : Scenario_Rep_Id); |
| 1229 |
pragma Inline (Install_Unit_ABE_Check); |
| 1230 |
-- Install a conditional ABE check for scenario N to ensure that unit |
| 1231 |
-- Unit_Id is properly elaborated. If the check is installed, disable |
| 1232 |
-- the elaboration checks of scenario Disable. |
| 1233 |
|
| 1234 |
procedure Install_Unit_ABE_Check |
| 1235 |
(N : Node_Id; |
| 1236 |
Unit_Id : Entity_Id; |
| 1237 |
Disable : Target_Rep_Id); |
| 1238 |
pragma Inline (Install_Unit_ABE_Check); |
| 1239 |
-- Install a conditional ABE check for scenario N to ensure that unit |
| 1240 |
-- Unit_Id is properly elaborated. If the check is installed, disable |
| 1241 |
-- the elaboration checks of target Disable. |
| 1242 |
|
| 1243 |
end Check_Installer; |
| 1244 |
use Check_Installer; |
| 1245 |
|
| 1246 |
-- The following package provides the main entry point for conditional ABE |
| 1247 |
-- checks and diagnostics. |
| 1248 |
|
| 1249 |
package Conditional_ABE_Processor is |
| 1250 |
|
| 1251 |
--------- |
| 1252 |
-- API -- |
| 1253 |
--------- |
| 1254 |
|
| 1255 |
procedure Check_Conditional_ABE_Scenarios |
| 1256 |
(Iter : in out NE_Set.Iterator); |
| 1257 |
pragma Inline (Check_Conditional_ABE_Scenarios); |
| 1258 |
-- Perform conditional ABE checks and diagnostics for all scenarios |
| 1259 |
-- available through iterator Iter. |
| 1260 |
|
| 1261 |
procedure Process_Conditional_ABE |
| 1262 |
(N : Node_Id; |
| 1263 |
In_State : Processing_In_State); |
| 1264 |
pragma Inline (Process_Conditional_ABE); |
| 1265 |
-- Perform conditional ABE checks and diagnostics for scenario N. |
| 1266 |
-- In_State denotes the current state of the Processing phase. |
| 1267 |
|
| 1268 |
end Conditional_ABE_Processor; |
| 1269 |
use Conditional_ABE_Processor; |
| 1270 |
|
| 1271 |
-- The following package provides functionality to emit errors, information |
| 1272 |
-- messages, and warnings. |
| 1273 |
|
| 1274 |
package Diagnostics is |
| 1275 |
|
| 1276 |
--------- |
| 1277 |
-- API -- |
| 1278 |
--------- |
| 1279 |
|
| 1280 |
procedure Elab_Msg_NE |
| 1281 |
(Msg : String; |
| 1282 |
N : Node_Id; |
| 1283 |
Id : Entity_Id; |
| 1284 |
Info_Msg : Boolean; |
| 1285 |
In_SPARK : Boolean); |
| 1286 |
pragma Inline (Elab_Msg_NE); |
| 1287 |
-- Wrapper around Error_Msg_NE. Emit message Msg concerning arbitrary |
| 1288 |
-- node N and entity. If flag Info_Msg is set, the routine emits an |
| 1289 |
-- information message, otherwise it emits an error. If flag In_SPARK |
| 1290 |
-- is set, then string " in SPARK" is added to the end of the message. |
| 1291 |
|
| 1292 |
procedure Info_Call |
| 1293 |
(Call : Node_Id; |
| 1294 |
Subp_Id : Entity_Id; |
| 1295 |
Info_Msg : Boolean; |
| 1296 |
In_SPARK : Boolean); |
| 1297 |
pragma Inline (Info_Call); |
| 1298 |
-- Output information concerning call Call that invokes subprogram |
| 1299 |
-- Subp_Id. When flag Info_Msg is set, the routine emits an information |
| 1300 |
-- message, otherwise it emits an error. When flag In_SPARK is set, " in |
| 1301 |
-- SPARK" is added to the end of the message. |
| 1302 |
|
| 1303 |
procedure Info_Instantiation |
| 1304 |
(Inst : Node_Id; |
| 1305 |
Gen_Id : Entity_Id; |
| 1306 |
Info_Msg : Boolean; |
| 1307 |
In_SPARK : Boolean); |
| 1308 |
pragma Inline (Info_Instantiation); |
| 1309 |
-- Output information concerning instantiation Inst which instantiates |
| 1310 |
-- generic unit Gen_Id. If flag Info_Msg is set, the routine emits an |
| 1311 |
-- information message, otherwise it emits an error. If flag In_SPARK |
| 1312 |
-- is set, then string " in SPARK" is added to the end of the message. |
| 1313 |
|
| 1314 |
procedure Info_Variable_Reference |
| 1315 |
(Ref : Node_Id; |
| 1316 |
Var_Id : Entity_Id); |
| 1317 |
pragma Inline (Info_Variable_Reference); |
| 1318 |
-- Output information concerning reference Ref which mentions variable |
| 1319 |
-- Var_Id. The routine emits an error suffixed with " in SPARK". |
| 1320 |
|
| 1321 |
end Diagnostics; |
| 1322 |
use Diagnostics; |
| 1323 |
|
| 1324 |
-- The following package provides functionality to locate the early call |
| 1325 |
-- region of a subprogram body. |
| 1326 |
|
| 1327 |
package Early_Call_Region_Processor is |
| 1328 |
|
| 1329 |
--------- |
| 1330 |
-- API -- |
| 1331 |
--------- |
| 1332 |
|
| 1333 |
function Find_Early_Call_Region |
| 1334 |
(Body_Decl : Node_Id; |
| 1335 |
Assume_Elab_Body : Boolean := False; |
| 1336 |
Skip_Memoization : Boolean := False) return Node_Id; |
| 1337 |
pragma Inline (Find_Early_Call_Region); |
| 1338 |
-- Find the start of the early call region that belongs to subprogram |
| 1339 |
-- body Body_Decl as defined in SPARK RM 7.7. This routine finds the |
| 1340 |
-- early call region, memoizes it, and returns it, but this behavior |
| 1341 |
-- can be altered. Flag Assume_Elab_Body should be set when a package |
| 1342 |
-- spec may lack pragma Elaborate_Body, but the routine must still |
| 1343 |
-- examine that spec. Flag Skip_Memoization should be set when the |
| 1344 |
-- routine must avoid memoizing the region. |
| 1345 |
|
| 1346 |
----------------- |
| 1347 |
-- Maintenance -- |
| 1348 |
----------------- |
| 1349 |
|
| 1350 |
procedure Finalize_Early_Call_Region_Processor; |
| 1351 |
pragma Inline (Finalize_Early_Call_Region_Processor); |
| 1352 |
-- Finalize all internal data structures |
| 1353 |
|
| 1354 |
procedure Initialize_Early_Call_Region_Processor; |
| 1355 |
pragma Inline (Initialize_Early_Call_Region_Processor); |
| 1356 |
-- Initialize all internal data structures |
| 1357 |
|
| 1358 |
end Early_Call_Region_Processor; |
| 1359 |
use Early_Call_Region_Processor; |
| 1360 |
|
| 1361 |
-- The following package provides access to the elaboration statuses of all |
| 1362 |
-- units withed by the main unit. |
| 1363 |
|
| 1364 |
package Elaborated_Units is |
| 1365 |
|
| 1366 |
--------- |
| 1367 |
-- API -- |
| 1368 |
--------- |
| 1369 |
|
| 1370 |
procedure Collect_Elaborated_Units; |
| 1371 |
pragma Inline (Collect_Elaborated_Units); |
| 1372 |
-- Save the elaboration statuses of all units withed by the main unit |
| 1373 |
|
| 1374 |
procedure Ensure_Prior_Elaboration |
| 1375 |
(N : Node_Id; |
| 1376 |
Unit_Id : Entity_Id; |
| 1377 |
Prag_Nam : Name_Id; |
| 1378 |
In_State : Processing_In_State); |
| 1379 |
pragma Inline (Ensure_Prior_Elaboration); |
| 1380 |
-- Guarantee the elaboration of unit Unit_Id with respect to the main |
| 1381 |
-- unit by either suggesting or installing an Elaborate[_All] pragma |
| 1382 |
-- denoted by Prag_Nam. N denotes the related scenario. In_State is the |
| 1383 |
-- current state of the Processing phase. |
| 1384 |
|
| 1385 |
function Has_Prior_Elaboration |
| 1386 |
(Unit_Id : Entity_Id; |
| 1387 |
Context_OK : Boolean := False; |
| 1388 |
Elab_Body_OK : Boolean := False; |
| 1389 |
Same_Unit_OK : Boolean := False) return Boolean; |
| 1390 |
pragma Inline (Has_Prior_Elaboration); |
| 1391 |
-- Determine whether unit Unit_Id is elaborated prior to the main unit. |
| 1392 |
-- If flag Context_OK is set, the routine considers the following case |
| 1393 |
-- as valid prior elaboration: |
| 1394 |
-- |
| 1395 |
-- * Unit_Id is in the elaboration context of the main unit |
| 1396 |
-- |
| 1397 |
-- If flag Elab_Body_OK is set, the routine considers the following case |
| 1398 |
-- as valid prior elaboration: |
| 1399 |
-- |
| 1400 |
-- * Unit_Id has pragma Elaborate_Body and is not the main unit |
| 1401 |
-- |
| 1402 |
-- If flag Same_Unit_OK is set, the routine considers the following |
| 1403 |
-- cases as valid prior elaboration: |
| 1404 |
-- |
| 1405 |
-- * Unit_Id is the main unit |
| 1406 |
-- |
| 1407 |
-- * Unit_Id denotes the spec of the main unit body |
| 1408 |
|
| 1409 |
procedure Meet_Elaboration_Requirement |
| 1410 |
(N : Node_Id; |
| 1411 |
Targ_Id : Entity_Id; |
| 1412 |
Req_Nam : Name_Id; |
| 1413 |
In_State : Processing_In_State); |
| 1414 |
pragma Inline (Meet_Elaboration_Requirement); |
| 1415 |
-- Determine whether elaboration requirement Req_Nam for scenario N with |
| 1416 |
-- target Targ_Id is met by the context of the main unit using the SPARK |
| 1417 |
-- rules. Req_Nam must denote either Elaborate or Elaborate_All. Emit an |
| 1418 |
-- error if this is not the case. In_State denotes the current state of |
| 1419 |
-- the Processing phase. |
| 1420 |
|
| 1421 |
----------------- |
| 1422 |
-- Maintenance -- |
| 1423 |
----------------- |
| 1424 |
|
| 1425 |
procedure Finalize_Elaborated_Units; |
| 1426 |
pragma Inline (Finalize_Elaborated_Units); |
| 1427 |
-- Finalize all internal data structures |
| 1428 |
|
| 1429 |
procedure Initialize_Elaborated_Units; |
| 1430 |
pragma Inline (Initialize_Elaborated_Units); |
| 1431 |
-- Initialize all internal data structures |
| 1432 |
|
| 1433 |
end Elaborated_Units; |
| 1434 |
use Elaborated_Units; |
| 1435 |
|
| 1436 |
-- The following package provides the main entry point for guaranteed ABE |
| 1437 |
-- checks and diagnostics. |
| 1438 |
|
| 1439 |
package Guaranteed_ABE_Processor is |
| 1440 |
|
| 1441 |
--------- |
| 1442 |
-- API -- |
| 1443 |
--------- |
| 1444 |
|
| 1445 |
procedure Process_Guaranteed_ABE |
| 1446 |
(N : Node_Id; |
| 1447 |
In_State : Processing_In_State); |
| 1448 |
pragma Inline (Process_Guaranteed_ABE); |
| 1449 |
-- Perform guaranteed ABE checks and diagnostics for scenario N. |
| 1450 |
-- In_State is the current state of the Processing phase. |
| 1451 |
|
| 1452 |
end Guaranteed_ABE_Processor; |
| 1453 |
use Guaranteed_ABE_Processor; |
| 1454 |
|
| 1455 |
-- The following package provides access to the internal representation of |
| 1456 |
-- scenarios and targets. |
| 1457 |
|
| 1458 |
package Internal_Representation is |
| 1459 |
|
| 1460 |
----------- |
| 1461 |
-- Types -- |
| 1462 |
----------- |
| 1463 |
|
| 1464 |
-- The following type enumerates all possible Ghost mode kinds |
| 1465 |
|
| 1466 |
type Extended_Ghost_Mode is |
| 1467 |
(Is_Ignored, |
| 1468 |
Is_Checked_Or_Not_Specified); |
| 1469 |
|
| 1470 |
-- The following type enumerates all possible SPARK mode kinds |
| 1471 |
|
| 1472 |
type Extended_SPARK_Mode is |
| 1473 |
(Is_On, |
| 1474 |
Is_Off_Or_Not_Specified); |
| 1475 |
|
| 1476 |
-------------- |
| 1477 |
-- Builders -- |
| 1478 |
-------------- |
| 1479 |
|
| 1480 |
function Scenario_Representation_Of |
| 1481 |
(N : Node_Id; |
| 1482 |
In_State : Processing_In_State) return Scenario_Rep_Id; |
| 1483 |
pragma Inline (Scenario_Representation_Of); |
| 1484 |
-- Obtain the id of elaboration scenario N's representation. The routine |
| 1485 |
-- constructs the representation if it is not available. In_State is the |
| 1486 |
-- current state of the Processing phase. |
| 1487 |
|
| 1488 |
function Target_Representation_Of |
| 1489 |
(Id : Entity_Id; |
| 1490 |
In_State : Processing_In_State) return Target_Rep_Id; |
| 1491 |
pragma Inline (Target_Representation_Of); |
| 1492 |
-- Obtain the id of elaboration target Id's representation. The routine |
| 1493 |
-- constructs the representation if it is not available. In_State is the |
| 1494 |
-- current state of the Processing phase. |
| 1495 |
|
| 1496 |
------------------------- |
| 1497 |
-- Scenario attributes -- |
| 1498 |
------------------------- |
| 1499 |
|
| 1500 |
function Activated_Task_Objects |
| 1501 |
(S_Id : Scenario_Rep_Id) return NE_List.Doubly_Linked_List; |
| 1502 |
pragma Inline (Activated_Task_Objects); |
| 1503 |
-- For Task_Activation_Scenario S_Id, obtain the list of task objects |
| 1504 |
-- the scenario is activating. |
| 1505 |
|
| 1506 |
function Activated_Task_Type (S_Id : Scenario_Rep_Id) return Entity_Id; |
| 1507 |
pragma Inline (Activated_Task_Type); |
| 1508 |
-- For Task_Activation_Scenario S_Id, obtain the currently activated |
| 1509 |
-- task type. |
| 1510 |
|
| 1511 |
procedure Disable_Elaboration_Checks (S_Id : Scenario_Rep_Id); |
| 1512 |
pragma Inline (Disable_Elaboration_Checks); |
| 1513 |
-- Disable elaboration checks of scenario S_Id |
| 1514 |
|
| 1515 |
function Elaboration_Checks_OK (S_Id : Scenario_Rep_Id) return Boolean; |
| 1516 |
pragma Inline (Elaboration_Checks_OK); |
| 1517 |
-- Determine whether scenario S_Id may be subjected to elaboration |
| 1518 |
-- checks. |
| 1519 |
|
| 1520 |
function Elaboration_Warnings_OK (S_Id : Scenario_Rep_Id) return Boolean; |
| 1521 |
pragma Inline (Elaboration_Warnings_OK); |
| 1522 |
-- Determine whether scenario S_Id may be subjected to elaboration |
| 1523 |
-- warnings. |
| 1524 |
|
| 1525 |
function Ghost_Mode_Of |
| 1526 |
(S_Id : Scenario_Rep_Id) return Extended_Ghost_Mode; |
| 1527 |
pragma Inline (Ghost_Mode_Of); |
| 1528 |
-- Obtain the Ghost mode of scenario S_Id |
| 1529 |
|
| 1530 |
function Is_Dispatching_Call (S_Id : Scenario_Rep_Id) return Boolean; |
| 1531 |
pragma Inline (Is_Dispatching_Call); |
| 1532 |
-- For Call_Scenario S_Id, determine whether the call is dispatching |
| 1533 |
|
| 1534 |
function Is_Read_Reference (S_Id : Scenario_Rep_Id) return Boolean; |
| 1535 |
pragma Inline (Is_Read_Reference); |
| 1536 |
-- For Variable_Reference_Scenario S_Id, determine whether the reference |
| 1537 |
-- is a read. |
| 1538 |
|
| 1539 |
function Kind (S_Id : Scenario_Rep_Id) return Scenario_Kind; |
| 1540 |
pragma Inline (Kind); |
| 1541 |
-- Obtain the nature of scenario S_Id |
| 1542 |
|
| 1543 |
function Level (S_Id : Scenario_Rep_Id) return Enclosing_Level_Kind; |
| 1544 |
pragma Inline (Level); |
| 1545 |
-- Obtain the enclosing level of scenario S_Id |
| 1546 |
|
| 1547 |
procedure Set_Activated_Task_Objects |
| 1548 |
(S_Id : Scenario_Rep_Id; |
| 1549 |
Task_Objs : NE_List.Doubly_Linked_List); |
| 1550 |
pragma Inline (Set_Activated_Task_Objects); |
| 1551 |
-- For Task_Activation_Scenario S_Id, set the list of task objects |
| 1552 |
-- activated by the scenario to Task_Objs. |
| 1553 |
|
| 1554 |
procedure Set_Activated_Task_Type |
| 1555 |
(S_Id : Scenario_Rep_Id; |
| 1556 |
Task_Typ : Entity_Id); |
| 1557 |
pragma Inline (Set_Activated_Task_Type); |
| 1558 |
-- For Task_Activation_Scenario S_Id, set the currently activated task |
| 1559 |
-- type to Task_Typ. |
| 1560 |
|
| 1561 |
function SPARK_Mode_Of |
| 1562 |
(S_Id : Scenario_Rep_Id) return Extended_SPARK_Mode; |
| 1563 |
pragma Inline (SPARK_Mode_Of); |
| 1564 |
-- Obtain the SPARK mode of scenario S_Id |
| 1565 |
|
| 1566 |
function Target (S_Id : Scenario_Rep_Id) return Entity_Id; |
| 1567 |
pragma Inline (Target); |
| 1568 |
-- Obtain the target of scenario S_Id |
| 1569 |
|
| 1570 |
----------------------- |
| 1571 |
-- Target attributes -- |
| 1572 |
----------------------- |
| 1573 |
|
| 1574 |
function Barrier_Body_Declaration (T_Id : Target_Rep_Id) return Node_Id; |
| 1575 |
pragma Inline (Barrier_Body_Declaration); |
| 1576 |
-- For Subprogram_Target T_Id, obtain the declaration of the barrier |
| 1577 |
-- function's body. |
| 1578 |
|
| 1579 |
function Body_Declaration (T_Id : Target_Rep_Id) return Node_Id; |
| 1580 |
pragma Inline (Body_Declaration); |
| 1581 |
-- Obtain the declaration of the body which belongs to target T_Id |
| 1582 |
|
| 1583 |
procedure Disable_Elaboration_Checks (T_Id : Target_Rep_Id); |
| 1584 |
pragma Inline (Disable_Elaboration_Checks); |
| 1585 |
-- Disable elaboration checks of target T_Id |
| 1586 |
|
| 1587 |
function Elaboration_Checks_OK (T_Id : Target_Rep_Id) return Boolean; |
| 1588 |
pragma Inline (Elaboration_Checks_OK); |
| 1589 |
-- Determine whether target T_Id may be subjected to elaboration checks |
| 1590 |
|
| 1591 |
function Elaboration_Warnings_OK (T_Id : Target_Rep_Id) return Boolean; |
| 1592 |
pragma Inline (Elaboration_Warnings_OK); |
| 1593 |
-- Determine whether target T_Id may be subjected to elaboration |
| 1594 |
-- warnings. |
| 1595 |
|
| 1596 |
function Ghost_Mode_Of (T_Id : Target_Rep_Id) return Extended_Ghost_Mode; |
| 1597 |
pragma Inline (Ghost_Mode_Of); |
| 1598 |
-- Obtain the Ghost mode of target T_Id |
| 1599 |
|
| 1600 |
function Kind (T_Id : Target_Rep_Id) return Target_Kind; |
| 1601 |
pragma Inline (Kind); |
| 1602 |
-- Obtain the nature of target T_Id |
| 1603 |
|
| 1604 |
function SPARK_Mode_Of (T_Id : Target_Rep_Id) return Extended_SPARK_Mode; |
| 1605 |
pragma Inline (SPARK_Mode_Of); |
| 1606 |
-- Obtain the SPARK mode of target T_Id |
| 1607 |
|
| 1608 |
function Spec_Declaration (T_Id : Target_Rep_Id) return Node_Id; |
| 1609 |
pragma Inline (Spec_Declaration); |
| 1610 |
-- Obtain the declaration of the spec which belongs to target T_Id |
| 1611 |
|
| 1612 |
function Unit (T_Id : Target_Rep_Id) return Entity_Id; |
| 1613 |
pragma Inline (Unit); |
| 1614 |
-- Obtain the unit where the target is defined |
| 1615 |
|
| 1616 |
function Variable_Declaration (T_Id : Target_Rep_Id) return Node_Id; |
| 1617 |
pragma Inline (Variable_Declaration); |
| 1618 |
-- For Variable_Target T_Id, obtain the declaration of the variable |
| 1619 |
|
| 1620 |
----------------- |
| 1621 |
-- Maintenance -- |
| 1622 |
----------------- |
| 1623 |
|
| 1624 |
procedure Finalize_Internal_Representation; |
| 1625 |
pragma Inline (Finalize_Internal_Representation); |
| 1626 |
-- Finalize all internal data structures |
| 1627 |
|
| 1628 |
procedure Initialize_Internal_Representation; |
| 1629 |
pragma Inline (Initialize_Internal_Representation); |
| 1630 |
-- Initialize all internal data structures |
| 1631 |
|
| 1632 |
end Internal_Representation; |
| 1633 |
use Internal_Representation; |
| 1634 |
|
| 1635 |
-- The following package provides functionality for recording pieces of the |
| 1636 |
-- invocation graph in the ALI file of the main unit. |
| 1637 |
|
| 1638 |
package Invocation_Graph is |
| 1639 |
|
| 1640 |
--------- |
| 1641 |
-- API -- |
| 1642 |
--------- |
| 1643 |
|
| 1644 |
procedure Record_Invocation_Graph; |
| 1645 |
pragma Inline (Record_Invocation_Graph); |
| 1646 |
-- Process all declaration, instantiation, and library level scenarios, |
| 1647 |
-- along with invocation construct within the spec and body of the main |
| 1648 |
-- unit to determine whether any of these reach into an external unit. |
| 1649 |
-- If such a path exists, encode in the ALI file of the main unit. |
| 1650 |
|
| 1651 |
----------------- |
| 1652 |
-- Maintenance -- |
| 1653 |
----------------- |
| 1654 |
|
| 1655 |
procedure Finalize_Invocation_Graph; |
| 1656 |
pragma Inline (Finalize_Invocation_Graph); |
| 1657 |
-- Finalize all internal data structures |
| 1658 |
|
| 1659 |
procedure Initialize_Invocation_Graph; |
| 1660 |
pragma Inline (Initialize_Invocation_Graph); |
| 1661 |
-- Initialize all internal data structures |
| 1662 |
|
| 1663 |
end Invocation_Graph; |
| 1664 |
use Invocation_Graph; |
| 1665 |
|
| 1666 |
-- The following package stores scenarios |
| 1667 |
|
| 1668 |
package Scenario_Storage is |
| 1669 |
|
| 1670 |
--------- |
| 1671 |
-- API -- |
| 1672 |
--------- |
| 1673 |
|
| 1674 |
procedure Add_Declaration_Scenario (N : Node_Id); |
| 1675 |
pragma Inline (Add_Declaration_Scenario); |
| 1676 |
-- Save declaration level scenario N |
| 1677 |
|
| 1678 |
procedure Add_Dynamic_ABE_Check_Scenario (N : Node_Id); |
| 1679 |
pragma Inline (Add_Dynamic_ABE_Check_Scenario); |
| 1680 |
-- Save scenario N for conditional ABE check installation purposes when |
| 1681 |
-- the dynamic model is in effect. |
| 1682 |
|
| 1683 |
procedure Add_Library_Body_Scenario (N : Node_Id); |
| 1684 |
pragma Inline (Add_Library_Body_Scenario); |
| 1685 |
-- Save library-level body scenario N |
| 1686 |
|
| 1687 |
procedure Add_Library_Spec_Scenario (N : Node_Id); |
| 1688 |
pragma Inline (Add_Library_Spec_Scenario); |
| 1689 |
-- Save library-level spec scenario N |
| 1690 |
|
| 1691 |
procedure Add_SPARK_Scenario (N : Node_Id); |
| 1692 |
pragma Inline (Add_SPARK_Scenario); |
| 1693 |
-- Save SPARK scenario N |
| 1694 |
|
| 1695 |
procedure Delete_Scenario (N : Node_Id); |
| 1696 |
pragma Inline (Delete_Scenario); |
| 1697 |
-- Delete arbitrary scenario N |
| 1698 |
|
| 1699 |
function Iterate_Declaration_Scenarios return NE_Set.Iterator; |
| 1700 |
pragma Inline (Iterate_Declaration_Scenarios); |
| 1701 |
-- Obtain an iterator over all declaration level scenarios |
| 1702 |
|
| 1703 |
function Iterate_Dynamic_ABE_Check_Scenarios return NE_Set.Iterator; |
| 1704 |
pragma Inline (Iterate_Dynamic_ABE_Check_Scenarios); |
| 1705 |
-- Obtain an iterator over all scenarios that require a conditional ABE |
| 1706 |
-- check when the dynamic model is in effect. |
| 1707 |
|
| 1708 |
function Iterate_Library_Body_Scenarios return NE_Set.Iterator; |
| 1709 |
pragma Inline (Iterate_Library_Body_Scenarios); |
| 1710 |
-- Obtain an iterator over all library level body scenarios |
| 1711 |
|
| 1712 |
function Iterate_Library_Spec_Scenarios return NE_Set.Iterator; |
| 1713 |
pragma Inline (Iterate_Library_Spec_Scenarios); |
| 1714 |
-- Obtain an iterator over all library level spec scenarios |
| 1715 |
|
| 1716 |
function Iterate_SPARK_Scenarios return NE_Set.Iterator; |
| 1717 |
pragma Inline (Iterate_SPARK_Scenarios); |
| 1718 |
-- Obtain an iterator over all SPARK scenarios |
| 1719 |
|
| 1720 |
procedure Replace_Scenario (Old_N : Node_Id; New_N : Node_Id); |
| 1721 |
pragma Inline (Replace_Scenario); |
| 1722 |
-- Replace scenario Old_N with scenario New_N |
| 1723 |
|
| 1724 |
----------------- |
| 1725 |
-- Maintenance -- |
| 1726 |
----------------- |
| 1727 |
|
| 1728 |
procedure Finalize_Scenario_Storage; |
| 1729 |
pragma Inline (Finalize_Scenario_Storage); |
| 1730 |
-- Finalize all internal data structures |
| 1731 |
|
| 1732 |
procedure Initialize_Scenario_Storage; |
| 1733 |
pragma Inline (Initialize_Scenario_Storage); |
| 1734 |
-- Initialize all internal data structures |
| 1735 |
|
| 1736 |
end Scenario_Storage; |
| 1737 |
use Scenario_Storage; |
| 1738 |
|
| 1739 |
-- The following package provides various semantic predicates |
| 1740 |
|
| 1741 |
package Semantics is |
| 1742 |
|
| 1743 |
--------- |
| 1744 |
-- API -- |
| 1745 |
--------- |
| 1746 |
|
| 1747 |
function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean; |
| 1748 |
pragma Inline (Is_Accept_Alternative_Proc); |
| 1749 |
-- Determine whether arbitrary entity Id denotes an internally generated |
| 1750 |
-- procedure which encapsulates the statements of an accept alternative. |
| 1751 |
|
| 1752 |
function Is_Activation_Proc (Id : Entity_Id) return Boolean; |
| 1753 |
pragma Inline (Is_Activation_Proc); |
| 1754 |
-- Determine whether arbitrary entity Id denotes a runtime procedure in |
| 1755 |
-- charge with activating tasks. |
| 1756 |
|
| 1757 |
function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean; |
| 1758 |
pragma Inline (Is_Ada_Semantic_Target); |
| 1759 |
-- Determine whether arbitrary entity Id denotes a source or internally |
| 1760 |
-- generated subprogram which emulates Ada semantics. |
| 1761 |
|
| 1762 |
function Is_Assertion_Pragma_Target (Id : Entity_Id) return Boolean; |
| 1763 |
pragma Inline (Is_Assertion_Pragma_Target); |
| 1764 |
-- Determine whether arbitrary entity Id denotes a procedure which |
| 1765 |
-- verifies the run-time semantics of an assertion pragma. |
| 1766 |
|
| 1767 |
function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean; |
| 1768 |
pragma Inline (Is_Bodiless_Subprogram); |
| 1769 |
-- Determine whether subprogram Subp_Id will never have a body |
| 1770 |
|
| 1771 |
function Is_Bridge_Target (Id : Entity_Id) return Boolean; |
| 1772 |
pragma Inline (Is_Bridge_Target); |
| 1773 |
-- Determine whether arbitrary entity Id denotes a bridge target |
| 1774 |
|
| 1775 |
function Is_Default_Initial_Condition_Proc |
| 1776 |
(Id : Entity_Id) return Boolean; |
| 1777 |
pragma Inline (Is_Default_Initial_Condition_Proc); |
| 1778 |
-- Determine whether arbitrary entity Id denotes internally generated |
| 1779 |
-- routine Default_Initial_Condition. |
| 1780 |
|
| 1781 |
function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean; |
| 1782 |
pragma Inline (Is_Initial_Condition_Proc); |
| 1783 |
-- Determine whether arbitrary entity Id denotes internally generated |
| 1784 |
-- routine Initial_Condition. |
| 1785 |
|
| 1786 |
function Is_Initialized (Obj_Decl : Node_Id) return Boolean; |
| 1787 |
pragma Inline (Is_Initialized); |
| 1788 |
-- Determine whether object declaration Obj_Decl is initialized |
| 1789 |
|
| 1790 |
function Is_Invariant_Proc (Id : Entity_Id) return Boolean; |
| 1791 |
pragma Inline (Is_Invariant_Proc); |
| 1792 |
-- Determine whether arbitrary entity Id denotes an invariant procedure |
| 1793 |
|
| 1794 |
function Is_Non_Library_Level_Encapsulator (N : Node_Id) return Boolean; |
| 1795 |
pragma Inline (Is_Non_Library_Level_Encapsulator); |
| 1796 |
-- Determine whether arbitrary node N is a non-library encapsulator |
| 1797 |
|
| 1798 |
function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean; |
| 1799 |
pragma Inline (Is_Partial_Invariant_Proc); |
| 1800 |
-- Determine whether arbitrary entity Id denotes a partial invariant |
| 1801 |
-- procedure. |
| 1802 |
|
| 1803 |
function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean; |
| 1804 |
pragma Inline (Is_Preelaborated_Unit); |
| 1805 |
-- Determine whether arbitrary entity Id denotes a unit which is subject |
| 1806 |
-- to one of the following pragmas: |
| 1807 |
-- |
| 1808 |
-- * Preelaborable |
| 1809 |
-- * Pure |
| 1810 |
-- * Remote_Call_Interface |
| 1811 |
-- * Remote_Types |
| 1812 |
-- * Shared_Passive |
| 1813 |
|
| 1814 |
function Is_Protected_Entry (Id : Entity_Id) return Boolean; |
| 1815 |
pragma Inline (Is_Protected_Entry); |
| 1816 |
-- Determine whether arbitrary entity Id denotes a protected entry |
| 1817 |
|
| 1818 |
function Is_Protected_Subp (Id : Entity_Id) return Boolean; |
| 1819 |
pragma Inline (Is_Protected_Subp); |
| 1820 |
-- Determine whether entity Id denotes a protected subprogram |
| 1821 |
|
| 1822 |
function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean; |
| 1823 |
pragma Inline (Is_Protected_Body_Subp); |
| 1824 |
-- Determine whether entity Id denotes the protected or unprotected |
| 1825 |
-- version of a protected subprogram. |
| 1826 |
|
| 1827 |
function Is_Scenario (N : Node_Id) return Boolean; |
| 1828 |
pragma Inline (Is_Scenario); |
| 1829 |
-- Determine whether attribute node N denotes a scenario. The scenario |
| 1830 |
-- may not necessarily be eligible for ABE processing. |
| 1831 |
|
| 1832 |
function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean; |
| 1833 |
pragma Inline (Is_SPARK_Semantic_Target); |
| 1834 |
-- Determine whether arbitrary entity Id denotes a source or internally |
| 1835 |
-- generated subprogram which emulates SPARK semantics. |
| 1836 |
|
| 1837 |
function Is_Subprogram_Inst (Id : Entity_Id) return Boolean; |
| 1838 |
pragma Inline (Is_Subprogram_Inst); |
| 1839 |
-- Determine whether arbitrary entity Id denotes a subprogram instance |
| 1840 |
|
| 1841 |
function Is_Suitable_Access_Taken (N : Node_Id) return Boolean; |
| 1842 |
pragma Inline (Is_Suitable_Access_Taken); |
| 1843 |
-- Determine whether arbitrary node N denotes a suitable attribute for |
| 1844 |
-- ABE processing. |
| 1845 |
|
| 1846 |
function Is_Suitable_Call (N : Node_Id) return Boolean; |
| 1847 |
pragma Inline (Is_Suitable_Call); |
| 1848 |
-- Determine whether arbitrary node N denotes a suitable call for ABE |
| 1849 |
-- processing. |
| 1850 |
|
| 1851 |
function Is_Suitable_Instantiation (N : Node_Id) return Boolean; |
| 1852 |
pragma Inline (Is_Suitable_Instantiation); |
| 1853 |
-- Determine whether arbitrary node N is a suitable instantiation for |
| 1854 |
-- ABE processing. |
| 1855 |
|
| 1856 |
function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean; |
| 1857 |
pragma Inline (Is_Suitable_SPARK_Derived_Type); |
| 1858 |
-- Determine whether arbitrary node N denotes a suitable derived type |
| 1859 |
-- declaration for ABE processing using the SPARK rules. |
| 1860 |
|
| 1861 |
function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean; |
| 1862 |
pragma Inline (Is_Suitable_SPARK_Instantiation); |
| 1863 |
-- Determine whether arbitrary node N denotes a suitable instantiation |
| 1864 |
-- for ABE processing using the SPARK rules. |
| 1865 |
|
| 1866 |
function Is_Suitable_SPARK_Refined_State_Pragma |
| 1867 |
(N : Node_Id) return Boolean; |
| 1868 |
pragma Inline (Is_Suitable_SPARK_Refined_State_Pragma); |
| 1869 |
-- Determine whether arbitrary node N denotes a suitable Refined_State |
| 1870 |
-- pragma for ABE processing using the SPARK rules. |
| 1871 |
|
| 1872 |
function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean; |
| 1873 |
pragma Inline (Is_Suitable_Variable_Assignment); |
| 1874 |
-- Determine whether arbitrary node N denotes a suitable assignment for |
| 1875 |
-- ABE processing. |
| 1876 |
|
| 1877 |
function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean; |
| 1878 |
pragma Inline (Is_Suitable_Variable_Reference); |
| 1879 |
-- Determine whether arbitrary node N is a suitable variable reference |
| 1880 |
-- for ABE processing. |
| 1881 |
|
| 1882 |
function Is_Task_Entry (Id : Entity_Id) return Boolean; |
| 1883 |
pragma Inline (Is_Task_Entry); |
| 1884 |
-- Determine whether arbitrary entity Id denotes a task entry |
| 1885 |
|
| 1886 |
function Is_Up_Level_Target |
| 1887 |
(Targ_Decl : Node_Id; |
| 1888 |
In_State : Processing_In_State) return Boolean; |
| 1889 |
pragma Inline (Is_Up_Level_Target); |
| 1890 |
-- Determine whether the current root resides at the declaration level. |
| 1891 |
-- If this is the case, determine whether a target with by declaration |
| 1892 |
-- Target_Decl is within a context which encloses the current root or is |
| 1893 |
-- in a different unit. In_State is the current state of the Processing |
| 1894 |
-- phase. |
| 1895 |
|
| 1896 |
end Semantics; |
| 1897 |
use Semantics; |
| 1898 |
|
| 1899 |
-- The following package provides the main entry point for SPARK-related |
| 1900 |
-- checks and diagnostics. |
| 1901 |
|
| 1902 |
package SPARK_Processor is |
| 1903 |
|
| 1904 |
--------- |
| 1905 |
-- API -- |
| 1906 |
--------- |
| 1907 |
|
| 1908 |
procedure Check_SPARK_Model_In_Effect; |
| 1909 |
pragma Inline (Check_SPARK_Model_In_Effect); |
| 1910 |
-- Determine whether a suitable elaboration model is currently in effect |
| 1911 |
-- for verifying SPARK rules. Emit a warning if this is not the case. |
| 1912 |
|
| 1913 |
procedure Check_SPARK_Scenarios; |
| 1914 |
pragma Inline (Check_SPARK_Scenarios); |
| 1915 |
-- Examine SPARK scenarios which are not necessarily executable during |
| 1916 |
-- elaboration, but still requires elaboration-related checks. |
| 1917 |
|
| 1918 |
end SPARK_Processor; |
| 1919 |
use SPARK_Processor; |
| 1920 |
|
| 1921 |
----------------------- |
| 1922 |
-- Local subprograms -- |
| 1923 |
----------------------- |
| 1924 |
|
| 1925 |
function Assignment_Target (Asmt : Node_Id) return Node_Id; |
| 1926 |
pragma Inline (Assignment_Target); |
| 1927 |
-- Obtain the target of assignment statement Asmt |
| 1928 |
|
| 1929 |
function Call_Name (Call : Node_Id) return Node_Id; |
| 1930 |
pragma Inline (Call_Name); |
| 1931 |
-- Obtain the name of an entry, operator, or subprogram call Call |
| 1932 |
|
| 1933 |
function Canonical_Subprogram (Subp_Id : Entity_Id) return Entity_Id; |
| 1934 |
pragma Inline (Canonical_Subprogram); |
| 1935 |
-- Obtain the uniform canonical entity of subprogram Subp_Id |
| 1936 |
|
| 1937 |
function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id; |
| 1938 |
pragma Inline (Compilation_Unit); |
| 1939 |
-- Return the N_Compilation_Unit node of unit Unit_Id |
| 1940 |
|
| 1941 |
function Elaboration_Phase_Active return Boolean; |
| 1942 |
pragma Inline (Elaboration_Phase_Active); |
| 1943 |
-- Determine whether the elaboration phase of the compilation has started |
| 1944 |
|
| 1945 |
procedure Error_Preelaborated_Call (N : Node_Id); |
| 1946 |
-- Give an error or warning for a non-static/non-preelaborable call in a |
| 1947 |
-- preelaborated unit. |
| 1948 |
|
| 1949 |
procedure Finalize_All_Data_Structures; |
| 1950 |
pragma Inline (Finalize_All_Data_Structures); |
| 1951 |
-- Destroy all internal data structures |
| 1952 |
|
| 1953 |
function Find_Enclosing_Instance (N : Node_Id) return Node_Id; |
| 1954 |
pragma Inline (Find_Enclosing_Instance); |
| 1955 |
-- Find the declaration or body of the nearest expanded instance which |
| 1956 |
-- encloses arbitrary node N. Return Empty if no such instance exists. |
| 1957 |
|
| 1958 |
function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id; |
| 1959 |
pragma Inline (Find_Top_Unit); |
| 1960 |
-- Return the top unit which contains arbitrary node or entity N. The unit |
| 1961 |
-- is obtained by logically unwinding instantiations and subunits when N |
| 1962 |
-- resides within one. |
| 1963 |
|
| 1964 |
function Find_Unit_Entity (N : Node_Id) return Entity_Id; |
| 1965 |
pragma Inline (Find_Unit_Entity); |
| 1966 |
-- Return the entity of unit N |
| 1967 |
|
| 1968 |
function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id; |
| 1969 |
pragma Inline (First_Formal_Type); |
| 1970 |
-- Return the type of subprogram Subp_Id's first formal parameter. If the |
| 1971 |
-- subprogram lacks formal parameters, return Empty. |
| 1972 |
|
| 1973 |
function Has_Body (Pack_Decl : Node_Id) return Boolean; |
| 1974 |
pragma Inline (Has_Body); |
| 1975 |
-- Determine whether package declaration Pack_Decl has a corresponding body |
| 1976 |
-- or would eventually have one. |
| 1977 |
|
| 1978 |
function In_External_Instance |
| 1979 |
(N : Node_Id; |
| 1980 |
Target_Decl : Node_Id) return Boolean; |
| 1981 |
pragma Inline (In_External_Instance); |
| 1982 |
-- Determine whether a target desctibed by its declaration Target_Decl |
| 1983 |
-- resides in a package instance which is external to scenario N. |
| 1984 |
|
| 1985 |
function In_Main_Context (N : Node_Id) return Boolean; |
| 1986 |
pragma Inline (In_Main_Context); |
| 1987 |
-- Determine whether arbitrary node N appears within the main compilation |
| 1988 |
-- unit. |
| 1989 |
|
| 1990 |
function In_Same_Context |
| 1991 |
(N1 : Node_Id; |
| 1992 |
N2 : Node_Id; |
| 1993 |
Nested_OK : Boolean := False) return Boolean; |
| 1994 |
pragma Inline (In_Same_Context); |
| 1995 |
-- Determine whether two arbitrary nodes N1 and N2 appear within the same |
| 1996 |
-- context ignoring enclosing library levels. Nested_OK should be set when |
| 1997 |
-- the context of N1 can enclose that of N2. |
| 1998 |
|
| 1999 |
procedure Initialize_All_Data_Structures; |
| 2000 |
pragma Inline (Initialize_All_Data_Structures); |
| 2001 |
-- Create all internal data structures |
| 2002 |
|
| 2003 |
function Instantiated_Generic (Inst : Node_Id) return Entity_Id; |
| 2004 |
pragma Inline (Instantiated_Generic); |
| 2005 |
-- Obtain the generic instantiated by instance Inst |
| 2006 |
|
| 2007 |
function Is_Safe_Activation |
| 2008 |
(Call : Node_Id; |
| 2009 |
Task_Rep : Target_Rep_Id) return Boolean; |
| 2010 |
pragma Inline (Is_Safe_Activation); |
| 2011 |
-- Determine whether activation call Call which activates an object of a |
| 2012 |
-- task type described by representation Task_Rep is always ABE-safe. |
| 2013 |
|
| 2014 |
function Is_Safe_Call |
| 2015 |
(Call : Node_Id; |
| 2016 |
Subp_Id : Entity_Id; |
| 2017 |
Subp_Rep : Target_Rep_Id) return Boolean; |
| 2018 |
pragma Inline (Is_Safe_Call); |
| 2019 |
-- Determine whether call Call which invokes entry, operator, or subprogram |
| 2020 |
-- Subp_Id is always ABE-safe. Subp_Rep is the representation of the entry, |
| 2021 |
-- operator, or subprogram. |
| 2022 |
|
| 2023 |
function Is_Safe_Instantiation |
| 2024 |
(Inst : Node_Id; |
| 2025 |
Gen_Id : Entity_Id; |
| 2026 |
Gen_Rep : Target_Rep_Id) return Boolean; |
| 2027 |
pragma Inline (Is_Safe_Instantiation); |
| 2028 |
-- Determine whether instantiation Inst which instantiates generic Gen_Id |
| 2029 |
-- is always ABE-safe. Gen_Rep is the representation of the generic. |
| 2030 |
|
| 2031 |
function Is_Same_Unit |
| 2032 |
(Unit_1 : Entity_Id; |
| 2033 |
Unit_2 : Entity_Id) return Boolean; |
| 2034 |
pragma Inline (Is_Same_Unit); |
| 2035 |
-- Determine whether entities Unit_1 and Unit_2 denote the same unit |
| 2036 |
|
| 2037 |
function Main_Unit_Entity return Entity_Id; |
| 2038 |
pragma Inline (Main_Unit_Entity); |
| 2039 |
-- Return the entity of the main unit |
| 2040 |
|
| 2041 |
function Non_Private_View (Typ : Entity_Id) return Entity_Id; |
| 2042 |
pragma Inline (Non_Private_View); |
| 2043 |
-- Return the full view of private type Typ if available, otherwise return |
| 2044 |
-- type Typ. |
| 2045 |
|
| 2046 |
function Scenario (N : Node_Id) return Node_Id; |
| 2047 |
pragma Inline (Scenario); |
| 2048 |
-- Return the appropriate scenario node for scenario N |
| 2049 |
|
| 2050 |
procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status); |
| 2051 |
pragma Inline (Set_Elaboration_Phase); |
| 2052 |
-- Change the status of the elaboration phase of the compiler to Status |
| 2053 |
|
| 2054 |
procedure Spec_And_Body_From_Entity |
| 2055 |
(Id : Entity_Id; |
| 2056 |
Spec_Decl : out Node_Id; |
| 2057 |
Body_Decl : out Node_Id); |
| 2058 |
pragma Inline (Spec_And_Body_From_Entity); |
| 2059 |
-- Given arbitrary entity Id representing a construct with a spec and body, |
| 2060 |
-- retrieve declaration of the spec in Spec_Decl and the declaration of the |
| 2061 |
-- body in Body_Decl. |
| 2062 |
|
| 2063 |
procedure Spec_And_Body_From_Node |
| 2064 |
(N : Node_Id; |
| 2065 |
Spec_Decl : out Node_Id; |
| 2066 |
Body_Decl : out Node_Id); |
| 2067 |
pragma Inline (Spec_And_Body_From_Node); |
| 2068 |
-- Given arbitrary node N representing a construct with a spec and body, |
| 2069 |
-- retrieve declaration of the spec in Spec_Decl and the declaration of |
| 2070 |
-- the body in Body_Decl. |
| 2071 |
|
| 2072 |
function Static_Elaboration_Checks return Boolean; |
| 2073 |
pragma Inline (Static_Elaboration_Checks); |
| 2074 |
-- Determine whether the static model is in effect |
| 2075 |
|
| 2076 |
function Unit_Entity (Unit_Id : Entity_Id) return Entity_Id; |
| 2077 |
pragma Inline (Unit_Entity); |
| 2078 |
-- Return the entity of the initial declaration for unit Unit_Id |
| 2079 |
|
| 2080 |
procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id); |
| 2081 |
pragma Inline (Update_Elaboration_Scenario); |
| 2082 |
-- Update all relevant internal data structures when scenario Old_N is |
| 2083 |
-- transformed into scenario New_N by Atree.Rewrite. |
| 2084 |
|
| 2085 |
---------------------- |
| 2086 |
-- Active_Scenarios -- |
| 2087 |
---------------------- |
| 2088 |
|
| 2089 |
package body Active_Scenarios is |
| 2090 |
|
| 2091 |
----------------------- |
| 2092 |
-- Local subprograms -- |
| 2093 |
----------------------- |
| 2094 |
|
| 2095 |
procedure Output_Access_Taken |
| 2096 |
(Attr : Node_Id; |
| 2097 |
Attr_Rep : Scenario_Rep_Id; |
| 2098 |
Error_Nod : Node_Id); |
| 2099 |
pragma Inline (Output_Access_Taken); |
| 2100 |
-- Emit a specific diagnostic message for 'Access attribute reference |
| 2101 |
-- Attr with representation Attr_Rep. The message is associated with |
| 2102 |
-- node Error_Nod. |
| 2103 |
|
| 2104 |
procedure Output_Active_Scenario |
| 2105 |
(N : Node_Id; |
| 2106 |
Error_Nod : Node_Id; |
| 2107 |
In_State : Processing_In_State); |
| 2108 |
pragma Inline (Output_Active_Scenario); |
| 2109 |
-- Top level dispatcher for outputting a scenario. Emit a specific |
| 2110 |
-- diagnostic message for scenario N. The message is associated with |
| 2111 |
-- node Error_Nod. In_State is the current state of the Processing |
| 2112 |
-- phase. |
| 2113 |
|
| 2114 |
procedure Output_Call |
| 2115 |
(Call : Node_Id; |
| 2116 |
Call_Rep : Scenario_Rep_Id; |
| 2117 |
Error_Nod : Node_Id); |
| 2118 |
pragma Inline (Output_Call); |
| 2119 |
-- Emit a diagnostic message for call Call with representation Call_Rep. |
| 2120 |
-- The message is associated with node Error_Nod. |
| 2121 |
|
| 2122 |
procedure Output_Header (Error_Nod : Node_Id); |
| 2123 |
pragma Inline (Output_Header); |
| 2124 |
-- Emit a specific diagnostic message for the unit of the root scenario. |
| 2125 |
-- The message is associated with node Error_Nod. |
| 2126 |
|
| 2127 |
procedure Output_Instantiation |
| 2128 |
(Inst : Node_Id; |
| 2129 |
Inst_Rep : Scenario_Rep_Id; |
| 2130 |
Error_Nod : Node_Id); |
| 2131 |
pragma Inline (Output_Instantiation); |
| 2132 |
-- Emit a specific diagnostic message for instantiation Inst with |
| 2133 |
-- representation Inst_Rep. The message is associated with node |
| 2134 |
-- Error_Nod. |
| 2135 |
|
| 2136 |
procedure Output_Refined_State_Pragma |
| 2137 |
(Prag : Node_Id; |
| 2138 |
Prag_Rep : Scenario_Rep_Id; |
| 2139 |
Error_Nod : Node_Id); |
| 2140 |
pragma Inline (Output_Refined_State_Pragma); |
| 2141 |
-- Emit a specific diagnostic message for Refined_State pragma Prag |
| 2142 |
-- with representation Prag_Rep. The message is associated with node |
| 2143 |
-- Error_Nod. |
| 2144 |
|
| 2145 |
procedure Output_Task_Activation |
| 2146 |
(Call : Node_Id; |
| 2147 |
Call_Rep : Scenario_Rep_Id; |
| 2148 |
Error_Nod : Node_Id); |
| 2149 |
pragma Inline (Output_Task_Activation); |
| 2150 |
-- Emit a specific diagnostic message for activation call Call |
| 2151 |
-- with representation Call_Rep. The message is associated with |
| 2152 |
-- node Error_Nod. |
| 2153 |
|
| 2154 |
procedure Output_Variable_Assignment |
| 2155 |
(Asmt : Node_Id; |
| 2156 |
Asmt_Rep : Scenario_Rep_Id; |
| 2157 |
Error_Nod : Node_Id); |
| 2158 |
pragma Inline (Output_Variable_Assignment); |
| 2159 |
-- Emit a specific diagnostic message for assignment statement Asmt |
| 2160 |
-- with representation Asmt_Rep. The message is associated with node |
| 2161 |
-- Error_Nod. |
| 2162 |
|
| 2163 |
procedure Output_Variable_Reference |
| 2164 |
(Ref : Node_Id; |
| 2165 |
Ref_Rep : Scenario_Rep_Id; |
| 2166 |
Error_Nod : Node_Id); |
| 2167 |
pragma Inline (Output_Variable_Reference); |
| 2168 |
-- Emit a specific diagnostic message for read reference Ref with |
| 2169 |
-- representation Ref_Rep. The message is associated with node |
| 2170 |
-- Error_Nod. |
| 2171 |
|
| 2172 |
------------------- |
| 2173 |
-- Output_Access -- |
| 2174 |
------------------- |
| 2175 |
|
| 2176 |
procedure Output_Access_Taken |
| 2177 |
(Attr : Node_Id; |
| 2178 |
Attr_Rep : Scenario_Rep_Id; |
| 2179 |
Error_Nod : Node_Id) |
| 2180 |
is |
| 2181 |
Subp_Id : constant Entity_Id := Target (Attr_Rep); |
| 2182 |
|
| 2183 |
begin |
| 2184 |
Error_Msg_Name_1 := Attribute_Name (Attr); |
| 2185 |
Error_Msg_Sloc := Sloc (Attr); |
| 2186 |
Error_Msg_NE ("\\ % of & taken #", Error_Nod, Subp_Id); |
| 2187 |
end Output_Access_Taken; |
| 2188 |
|
| 2189 |
---------------------------- |
| 2190 |
-- Output_Active_Scenario -- |
| 2191 |
---------------------------- |
| 2192 |
|
| 2193 |
procedure Output_Active_Scenario |
| 2194 |
(N : Node_Id; |
| 2195 |
Error_Nod : Node_Id; |
| 2196 |
In_State : Processing_In_State) |
| 2197 |
is |
| 2198 |
Scen : constant Node_Id := Scenario (N); |
| 2199 |
Scen_Rep : Scenario_Rep_Id; |
| 2200 |
|
| 2201 |
begin |
| 2202 |
-- 'Access |
| 2203 |
|
| 2204 |
if Is_Suitable_Access_Taken (Scen) then |
| 2205 |
Output_Access_Taken |
| 2206 |
(Attr => Scen, |
| 2207 |
Attr_Rep => Scenario_Representation_Of (Scen, In_State), |
| 2208 |
Error_Nod => Error_Nod); |
| 2209 |
|
| 2210 |
-- Call or task activation |
| 2211 |
|
| 2212 |
elsif Is_Suitable_Call (Scen) then |
| 2213 |
Scen_Rep := Scenario_Representation_Of (Scen, In_State); |
| 2214 |
|
| 2215 |
if Kind (Scen_Rep) = Call_Scenario then |
| 2216 |
Output_Call |
| 2217 |
(Call => Scen, |
| 2218 |
Call_Rep => Scen_Rep, |
| 2219 |
Error_Nod => Error_Nod); |
| 2220 |
|
| 2221 |
else |
| 2222 |
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario); |
| 2223 |
|
| 2224 |
Output_Task_Activation |
| 2225 |
(Call => Scen, |
| 2226 |
Call_Rep => Scen_Rep, |
| 2227 |
Error_Nod => Error_Nod); |
| 2228 |
end if; |
| 2229 |
|
| 2230 |
-- Instantiation |
| 2231 |
|
| 2232 |
elsif Is_Suitable_Instantiation (Scen) then |
| 2233 |
Output_Instantiation |
| 2234 |
(Inst => Scen, |
| 2235 |
Inst_Rep => Scenario_Representation_Of (Scen, In_State), |
| 2236 |
Error_Nod => Error_Nod); |
| 2237 |
|
| 2238 |
-- Pragma Refined_State |
| 2239 |
|
| 2240 |
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then |
| 2241 |
Output_Refined_State_Pragma |
| 2242 |
(Prag => Scen, |
| 2243 |
Prag_Rep => Scenario_Representation_Of (Scen, In_State), |
| 2244 |
Error_Nod => Error_Nod); |
| 2245 |
|
| 2246 |
-- Variable assignment |
| 2247 |
|
| 2248 |
elsif Is_Suitable_Variable_Assignment (Scen) then |
| 2249 |
Output_Variable_Assignment |
| 2250 |
(Asmt => Scen, |
| 2251 |
Asmt_Rep => Scenario_Representation_Of (Scen, In_State), |
| 2252 |
Error_Nod => Error_Nod); |
| 2253 |
|
| 2254 |
-- Variable reference |
| 2255 |
|
| 2256 |
elsif Is_Suitable_Variable_Reference (Scen) then |
| 2257 |
Output_Variable_Reference |
| 2258 |
(Ref => Scen, |
| 2259 |
Ref_Rep => Scenario_Representation_Of (Scen, In_State), |
| 2260 |
Error_Nod => Error_Nod); |
| 2261 |
end if; |
| 2262 |
end Output_Active_Scenario; |
| 2263 |
|
| 2264 |
----------------------------- |
| 2265 |
-- Output_Active_Scenarios -- |
| 2266 |
----------------------------- |
| 2267 |
|
| 2268 |
procedure Output_Active_Scenarios |
| 2269 |
(Error_Nod : Node_Id; |
| 2270 |
In_State : Processing_In_State) |
| 2271 |
is |
| 2272 |
package Scenarios renames Active_Scenario_Stack; |
| 2273 |
|
| 2274 |
Header_Posted : Boolean := False; |
| 2275 |
|
| 2276 |
begin |
| 2277 |
-- Output the contents of the active scenario stack starting from the |
| 2278 |
-- bottom, or the least recent scenario. |
| 2279 |
|
| 2280 |
for Index in Scenarios.First .. Scenarios.Last loop |
| 2281 |
if not Header_Posted then |
| 2282 |
Output_Header (Error_Nod); |
| 2283 |
Header_Posted := True; |
| 2284 |
end if; |
| 2285 |
|
| 2286 |
Output_Active_Scenario |
| 2287 |
(N => Scenarios.Table (Index), |
| 2288 |
Error_Nod => Error_Nod, |
| 2289 |
In_State => In_State); |
| 2290 |
end loop; |
| 2291 |
end Output_Active_Scenarios; |
| 2292 |
|
| 2293 |
----------------- |
| 2294 |
-- Output_Call -- |
| 2295 |
----------------- |
| 2296 |
|
| 2297 |
procedure Output_Call |
| 2298 |
(Call : Node_Id; |
| 2299 |
Call_Rep : Scenario_Rep_Id; |
| 2300 |
Error_Nod : Node_Id) |
| 2301 |
is |
| 2302 |
procedure Output_Accept_Alternative (Alt_Id : Entity_Id); |
| 2303 |
pragma Inline (Output_Accept_Alternative); |
| 2304 |
-- Emit a specific diagnostic message concerning accept alternative |
| 2305 |
-- with entity Alt_Id. |
| 2306 |
|
| 2307 |
procedure Output_Call (Subp_Id : Entity_Id; Kind : String); |
| 2308 |
pragma Inline (Output_Call); |
| 2309 |
-- Emit a specific diagnostic message concerning a call of kind Kind |
| 2310 |
-- which invokes subprogram Subp_Id. |
| 2311 |
|
| 2312 |
procedure Output_Type_Actions (Subp_Id : Entity_Id; Action : String); |
| 2313 |
pragma Inline (Output_Type_Actions); |
| 2314 |
-- Emit a specific diagnostic message concerning action Action of a |
| 2315 |
-- type performed by subprogram Subp_Id. |
| 2316 |
|
| 2317 |
procedure Output_Verification_Call |
| 2318 |
(Pred : String; |
| 2319 |
Id : Entity_Id; |
| 2320 |
Id_Kind : String); |
| 2321 |
pragma Inline (Output_Verification_Call); |
| 2322 |
-- Emit a specific diagnostic message concerning the verification of |
| 2323 |
-- predicate Pred applied to related entity Id with kind Id_Kind. |
| 2324 |
|
| 2325 |
------------------------------- |
| 2326 |
-- Output_Accept_Alternative -- |
| 2327 |
------------------------------- |
| 2328 |
|
| 2329 |
procedure Output_Accept_Alternative (Alt_Id : Entity_Id) is |
| 2330 |
Entry_Id : constant Entity_Id := Receiving_Entry (Alt_Id); |
| 2331 |
|
| 2332 |
begin |
| 2333 |
pragma Assert (Present (Entry_Id)); |
| 2334 |
|
| 2335 |
Error_Msg_NE ("\\ entry & selected #", Error_Nod, Entry_Id); |
| 2336 |
end Output_Accept_Alternative; |
| 2337 |
|
| 2338 |
----------------- |
| 2339 |
-- Output_Call -- |
| 2340 |
----------------- |
| 2341 |
|
| 2342 |
procedure Output_Call (Subp_Id : Entity_Id; Kind : String) is |
| 2343 |
begin |
| 2344 |
Error_Msg_NE ("\\ " & Kind & " & called #", Error_Nod, Subp_Id); |
| 2345 |
end Output_Call; |
| 2346 |
|
| 2347 |
------------------------- |
| 2348 |
-- Output_Type_Actions -- |
| 2349 |
------------------------- |
| 2350 |
|
| 2351 |
procedure Output_Type_Actions |
| 2352 |
(Subp_Id : Entity_Id; |
| 2353 |
Action : String) |
| 2354 |
is |
| 2355 |
Typ : constant Entity_Id := First_Formal_Type (Subp_Id); |
| 2356 |
|
| 2357 |
begin |
| 2358 |
pragma Assert (Present (Typ)); |
| 2359 |
|
| 2360 |
Error_Msg_NE |
| 2361 |
("\\ " & Action & " actions for type & #", Error_Nod, Typ); |
| 2362 |
end Output_Type_Actions; |
| 2363 |
|
| 2364 |
------------------------------ |
| 2365 |
-- Output_Verification_Call -- |
| 2366 |
------------------------------ |
| 2367 |
|
| 2368 |
procedure Output_Verification_Call |
| 2369 |
(Pred : String; |
| 2370 |
Id : Entity_Id; |
| 2371 |
Id_Kind : String) |
| 2372 |
is |
| 2373 |
begin |
| 2374 |
pragma Assert (Present (Id)); |
| 2375 |
|
| 2376 |
Error_Msg_NE |
| 2377 |
("\\ " & Pred & " of " & Id_Kind & " & verified #", |
| 2378 |
Error_Nod, Id); |
| 2379 |
end Output_Verification_Call; |
| 2380 |
|
| 2381 |
-- Local variables |
| 2382 |
|
| 2383 |
Subp_Id : constant Entity_Id := Target (Call_Rep); |
| 2384 |
|
| 2385 |
-- Start of processing for Output_Call |
| 2386 |
|
| 2387 |
begin |
| 2388 |
Error_Msg_Sloc := Sloc (Call); |
| 2389 |
|
| 2390 |
-- Accept alternative |
| 2391 |
|
| 2392 |
if Is_Accept_Alternative_Proc (Subp_Id) then |
| 2393 |
Output_Accept_Alternative (Subp_Id); |
| 2394 |
|
| 2395 |
-- Adjustment |
| 2396 |
|
| 2397 |
elsif Is_TSS (Subp_Id, TSS_Deep_Adjust) then |
| 2398 |
Output_Type_Actions (Subp_Id, "adjustment"); |
| 2399 |
|
| 2400 |
-- Default_Initial_Condition |
| 2401 |
|
| 2402 |
elsif Is_Default_Initial_Condition_Proc (Subp_Id) then |
| 2403 |
|
| 2404 |
-- Only do output for a normal DIC procedure, since partial DIC |
| 2405 |
-- procedures are subsidiary to those. |
| 2406 |
|
| 2407 |
if not Is_Partial_DIC_Procedure (Subp_Id) then |
| 2408 |
Output_Verification_Call |
| 2409 |
(Pred => "Default_Initial_Condition", |
| 2410 |
Id => First_Formal_Type (Subp_Id), |
| 2411 |
Id_Kind => "type"); |
| 2412 |
end if; |
| 2413 |
|
| 2414 |
-- Entries |
| 2415 |
|
| 2416 |
elsif Is_Protected_Entry (Subp_Id) then |
| 2417 |
Output_Call (Subp_Id, "entry"); |
| 2418 |
|
| 2419 |
-- Task entry calls are never processed because the entry being |
| 2420 |
-- invoked does not have a corresponding "body", it has a select. A |
| 2421 |
-- task entry call appears in the stack of active scenarios for the |
| 2422 |
-- sole purpose of checking No_Entry_Calls_In_Elaboration_Code and |
| 2423 |
-- nothing more. |
| 2424 |
|
| 2425 |
elsif Is_Task_Entry (Subp_Id) then |
| 2426 |
null; |
| 2427 |
|
| 2428 |
-- Finalization |
| 2429 |
|
| 2430 |
elsif Is_TSS (Subp_Id, TSS_Deep_Finalize) then |
| 2431 |
Output_Type_Actions (Subp_Id, "finalization"); |
| 2432 |
|
| 2433 |
-- Calls to _Finalizer procedures must not appear in the output |
| 2434 |
-- because this creates confusing noise. |
| 2435 |
|
| 2436 |
elsif Is_Finalizer (Subp_Id) then |
| 2437 |
null; |
| 2438 |
|
| 2439 |
-- Initial_Condition |
| 2440 |
|
| 2441 |
elsif Is_Initial_Condition_Proc (Subp_Id) then |
| 2442 |
Output_Verification_Call |
| 2443 |
(Pred => "Initial_Condition", |
| 2444 |
Id => Find_Enclosing_Scope (Call), |
| 2445 |
Id_Kind => "package"); |
| 2446 |
|
| 2447 |
-- Initialization |
| 2448 |
|
| 2449 |
elsif Is_Init_Proc (Subp_Id) |
| 2450 |
or else Is_TSS (Subp_Id, TSS_Deep_Initialize) |
| 2451 |
then |
| 2452 |
Output_Type_Actions (Subp_Id, "initialization"); |
| 2453 |
|
| 2454 |
-- Invariant |
| 2455 |
|
| 2456 |
elsif Is_Invariant_Proc (Subp_Id) then |
| 2457 |
Output_Verification_Call |
| 2458 |
(Pred => "invariants", |
| 2459 |
Id => First_Formal_Type (Subp_Id), |
| 2460 |
Id_Kind => "type"); |
| 2461 |
|
| 2462 |
-- Partial invariant calls must not appear in the output because this |
| 2463 |
-- creates confusing noise. Note that a partial invariant is always |
| 2464 |
-- invoked by the "full" invariant which is already placed on the |
| 2465 |
-- stack. |
| 2466 |
|
| 2467 |
elsif Is_Partial_Invariant_Proc (Subp_Id) then |
| 2468 |
null; |
| 2469 |
|
| 2470 |
-- Subprograms must come last because some of the previous cases fall |
| 2471 |
-- under this category. |
| 2472 |
|
| 2473 |
elsif Ekind (Subp_Id) = E_Function then |
| 2474 |
Output_Call (Subp_Id, "function"); |
| 2475 |
|
| 2476 |
elsif Ekind (Subp_Id) = E_Procedure then |
| 2477 |
Output_Call (Subp_Id, "procedure"); |
| 2478 |
|
| 2479 |
else |
| 2480 |
pragma Assert (False); |
| 2481 |
return; |
| 2482 |
end if; |
| 2483 |
end Output_Call; |
| 2484 |
|
| 2485 |
------------------- |
| 2486 |
-- Output_Header -- |
| 2487 |
------------------- |
| 2488 |
|
| 2489 |
procedure Output_Header (Error_Nod : Node_Id) is |
| 2490 |
Unit_Id : constant Entity_Id := Find_Top_Unit (Root_Scenario); |
| 2491 |
|
| 2492 |
begin |
| 2493 |
if Ekind (Unit_Id) = E_Package then |
| 2494 |
Error_Msg_NE ("\\ spec of unit & elaborated", Error_Nod, Unit_Id); |
| 2495 |
|
| 2496 |
elsif Ekind (Unit_Id) = E_Package_Body then |
| 2497 |
Error_Msg_NE ("\\ body of unit & elaborated", Error_Nod, Unit_Id); |
| 2498 |
|
| 2499 |
else |
| 2500 |
Error_Msg_NE ("\\ in body of unit &", Error_Nod, Unit_Id); |
| 2501 |
end if; |
| 2502 |
end Output_Header; |
| 2503 |
|
| 2504 |
-------------------------- |
| 2505 |
-- Output_Instantiation -- |
| 2506 |
-------------------------- |
| 2507 |
|
| 2508 |
procedure Output_Instantiation |
| 2509 |
(Inst : Node_Id; |
| 2510 |
Inst_Rep : Scenario_Rep_Id; |
| 2511 |
Error_Nod : Node_Id) |
| 2512 |
is |
| 2513 |
procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String); |
| 2514 |
pragma Inline (Output_Instantiation); |
| 2515 |
-- Emit a specific diagnostic message concerning an instantiation of |
| 2516 |
-- generic unit Gen_Id. Kind denotes the kind of the instantiation. |
| 2517 |
|
| 2518 |
-------------------------- |
| 2519 |
-- Output_Instantiation -- |
| 2520 |
-------------------------- |
| 2521 |
|
| 2522 |
procedure Output_Instantiation (Gen_Id : Entity_Id; Kind : String) is |
| 2523 |
begin |
| 2524 |
Error_Msg_NE |
| 2525 |
("\\ " & Kind & " & instantiated as & #", Error_Nod, Gen_Id); |
| 2526 |
end Output_Instantiation; |
| 2527 |
|
| 2528 |
-- Local variables |
| 2529 |
|
| 2530 |
Gen_Id : constant Entity_Id := Target (Inst_Rep); |
| 2531 |
|
| 2532 |
-- Start of processing for Output_Instantiation |
| 2533 |
|
| 2534 |
begin |
| 2535 |
Error_Msg_Node_2 := Defining_Entity (Inst); |
| 2536 |
Error_Msg_Sloc := Sloc (Inst); |
| 2537 |
|
| 2538 |
if Nkind (Inst) = N_Function_Instantiation then |
| 2539 |
Output_Instantiation (Gen_Id, "function"); |
| 2540 |
|
| 2541 |
elsif Nkind (Inst) = N_Package_Instantiation then |
| 2542 |
Output_Instantiation (Gen_Id, "package"); |
| 2543 |
|
| 2544 |
elsif Nkind (Inst) = N_Procedure_Instantiation then |
| 2545 |
Output_Instantiation (Gen_Id, "procedure"); |
| 2546 |
|
| 2547 |
else |
| 2548 |
pragma Assert (False); |
| 2549 |
return; |
| 2550 |
end if; |
| 2551 |
end Output_Instantiation; |
| 2552 |
|
| 2553 |
--------------------------------- |
| 2554 |
-- Output_Refined_State_Pragma -- |
| 2555 |
--------------------------------- |
| 2556 |
|
| 2557 |
procedure Output_Refined_State_Pragma |
| 2558 |
(Prag : Node_Id; |
| 2559 |
Prag_Rep : Scenario_Rep_Id; |
| 2560 |
Error_Nod : Node_Id) |
| 2561 |
is |
| 2562 |
pragma Unreferenced (Prag_Rep); |
| 2563 |
|
| 2564 |
begin |
| 2565 |
Error_Msg_Sloc := Sloc (Prag); |
| 2566 |
Error_Msg_N ("\\ refinement constituents read #", Error_Nod); |
| 2567 |
end Output_Refined_State_Pragma; |
| 2568 |
|
| 2569 |
---------------------------- |
| 2570 |
-- Output_Task_Activation -- |
| 2571 |
---------------------------- |
| 2572 |
|
| 2573 |
procedure Output_Task_Activation |
| 2574 |
(Call : Node_Id; |
| 2575 |
Call_Rep : Scenario_Rep_Id; |
| 2576 |
Error_Nod : Node_Id) |
| 2577 |
is |
| 2578 |
pragma Unreferenced (Call_Rep); |
| 2579 |
|
| 2580 |
function Find_Activator return Entity_Id; |
| 2581 |
-- Find the nearest enclosing construct which houses call Call |
| 2582 |
|
| 2583 |
-------------------- |
| 2584 |
-- Find_Activator -- |
| 2585 |
-------------------- |
| 2586 |
|
| 2587 |
function Find_Activator return Entity_Id is |
| 2588 |
Par : Node_Id; |
| 2589 |
|
| 2590 |
begin |
| 2591 |
-- Climb the parent chain looking for a package [body] or a |
| 2592 |
-- construct with a statement sequence. |
| 2593 |
|
| 2594 |
Par := Parent (Call); |
| 2595 |
while Present (Par) loop |
| 2596 |
if Nkind (Par) in N_Package_Body | N_Package_Declaration then |
| 2597 |
return Defining_Entity (Par); |
| 2598 |
|
| 2599 |
elsif Nkind (Par) = N_Handled_Sequence_Of_Statements then |
| 2600 |
return Defining_Entity (Parent (Par)); |
| 2601 |
end if; |
| 2602 |
|
| 2603 |
Par := Parent (Par); |
| 2604 |
end loop; |
| 2605 |
|
| 2606 |
return Empty; |
| 2607 |
end Find_Activator; |
| 2608 |
|
| 2609 |
-- Local variables |
| 2610 |
|
| 2611 |
Activator : constant Entity_Id := Find_Activator; |
| 2612 |
|
| 2613 |
-- Start of processing for Output_Task_Activation |
| 2614 |
|
| 2615 |
begin |
| 2616 |
pragma Assert (Present (Activator)); |
| 2617 |
|
| 2618 |
Error_Msg_NE ("\\ local tasks of & activated", Error_Nod, Activator); |
| 2619 |
end Output_Task_Activation; |
| 2620 |
|
| 2621 |
-------------------------------- |
| 2622 |
-- Output_Variable_Assignment -- |
| 2623 |
-------------------------------- |
| 2624 |
|
| 2625 |
procedure Output_Variable_Assignment |
| 2626 |
(Asmt : Node_Id; |
| 2627 |
Asmt_Rep : Scenario_Rep_Id; |
| 2628 |
Error_Nod : Node_Id) |
| 2629 |
is |
| 2630 |
Var_Id : constant Entity_Id := Target (Asmt_Rep); |
| 2631 |
|
| 2632 |
begin |
| 2633 |
Error_Msg_Sloc := Sloc (Asmt); |
| 2634 |
Error_Msg_NE ("\\ variable & assigned #", Error_Nod, Var_Id); |
| 2635 |
end Output_Variable_Assignment; |
| 2636 |
|
| 2637 |
------------------------------- |
| 2638 |
-- Output_Variable_Reference -- |
| 2639 |
------------------------------- |
| 2640 |
|
| 2641 |
procedure Output_Variable_Reference |
| 2642 |
(Ref : Node_Id; |
| 2643 |
Ref_Rep : Scenario_Rep_Id; |
| 2644 |
Error_Nod : Node_Id) |
| 2645 |
is |
| 2646 |
Var_Id : constant Entity_Id := Target (Ref_Rep); |
| 2647 |
|
| 2648 |
begin |
| 2649 |
Error_Msg_Sloc := Sloc (Ref); |
| 2650 |
Error_Msg_NE ("\\ variable & read #", Error_Nod, Var_Id); |
| 2651 |
end Output_Variable_Reference; |
| 2652 |
|
| 2653 |
------------------------- |
| 2654 |
-- Pop_Active_Scenario -- |
| 2655 |
------------------------- |
| 2656 |
|
| 2657 |
procedure Pop_Active_Scenario (N : Node_Id) is |
| 2658 |
package Scenarios renames Active_Scenario_Stack; |
| 2659 |
Top : Node_Id renames Scenarios.Table (Scenarios.Last); |
| 2660 |
|
| 2661 |
begin |
| 2662 |
pragma Assert (Top = N); |
| 2663 |
Scenarios.Decrement_Last; |
| 2664 |
end Pop_Active_Scenario; |
| 2665 |
|
| 2666 |
-------------------------- |
| 2667 |
-- Push_Active_Scenario -- |
| 2668 |
-------------------------- |
| 2669 |
|
| 2670 |
procedure Push_Active_Scenario (N : Node_Id) is |
| 2671 |
begin |
| 2672 |
Active_Scenario_Stack.Append (N); |
| 2673 |
end Push_Active_Scenario; |
| 2674 |
|
| 2675 |
------------------- |
| 2676 |
-- Root_Scenario -- |
| 2677 |
------------------- |
| 2678 |
|
| 2679 |
function Root_Scenario return Node_Id is |
| 2680 |
package Scenarios renames Active_Scenario_Stack; |
| 2681 |
|
| 2682 |
begin |
| 2683 |
-- Ensure that the scenario stack has at least one active scenario in |
| 2684 |
-- it. The one at the bottom (index First) is the root scenario. |
| 2685 |
|
| 2686 |
pragma Assert (Scenarios.Last >= Scenarios.First); |
| 2687 |
return Scenarios.Table (Scenarios.First); |
| 2688 |
end Root_Scenario; |
| 2689 |
end Active_Scenarios; |
| 2690 |
|
| 2691 |
-------------------------- |
| 2692 |
-- Activation_Processor -- |
| 2693 |
-------------------------- |
| 2694 |
|
| 2695 |
package body Activation_Processor is |
| 2696 |
|
| 2697 |
------------------------ |
| 2698 |
-- Process_Activation -- |
| 2699 |
------------------------ |
| 2700 |
|
| 2701 |
procedure Process_Activation |
| 2702 |
(Call : Node_Id; |
| 2703 |
Call_Rep : Scenario_Rep_Id; |
| 2704 |
Processor : Activation_Processor_Ptr; |
| 2705 |
In_State : Processing_In_State) |
| 2706 |
is |
| 2707 |
procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id); |
| 2708 |
pragma Inline (Process_Task_Object); |
| 2709 |
-- Invoke Processor for task object Obj_Id of type Typ |
| 2710 |
|
| 2711 |
procedure Process_Task_Objects |
| 2712 |
(Task_Objs : NE_List.Doubly_Linked_List); |
| 2713 |
pragma Inline (Process_Task_Objects); |
| 2714 |
-- Invoke Processor for all task objects found in list Task_Objs |
| 2715 |
|
| 2716 |
procedure Traverse_List |
| 2717 |
(List : List_Id; |
| 2718 |
Task_Objs : NE_List.Doubly_Linked_List); |
| 2719 |
pragma Inline (Traverse_List); |
| 2720 |
-- Traverse declarative or statement list List while searching for |
| 2721 |
-- objects of a task type, or containing task components. If such an |
| 2722 |
-- object is found, first save it in list Task_Objs and then invoke |
| 2723 |
-- Processor on it. |
| 2724 |
|
| 2725 |
------------------------- |
| 2726 |
-- Process_Task_Object -- |
| 2727 |
------------------------- |
| 2728 |
|
| 2729 |
procedure Process_Task_Object (Obj_Id : Entity_Id; Typ : Entity_Id) is |
| 2730 |
Root_Typ : constant Entity_Id := |
| 2731 |
Non_Private_View (Root_Type (Typ)); |
| 2732 |
Comp_Id : Entity_Id; |
| 2733 |
Obj_Rep : Target_Rep_Id; |
| 2734 |
Root_Rep : Target_Rep_Id; |
| 2735 |
|
| 2736 |
New_In_State : Processing_In_State := In_State; |
| 2737 |
-- Each step of the Processing phase constitutes a new state |
| 2738 |
|
| 2739 |
begin |
| 2740 |
if Is_Task_Type (Typ) then |
| 2741 |
Obj_Rep := Target_Representation_Of (Obj_Id, New_In_State); |
| 2742 |
Root_Rep := Target_Representation_Of (Root_Typ, New_In_State); |
| 2743 |
|
| 2744 |
-- Warnings are suppressed when a prior scenario is already in |
| 2745 |
-- that mode, or when the object, activation call, or task type |
| 2746 |
-- have warnings suppressed. Update the state of the Processing |
| 2747 |
-- phase to reflect this. |
| 2748 |
|
| 2749 |
New_In_State.Suppress_Warnings := |
| 2750 |
New_In_State.Suppress_Warnings |
| 2751 |
or else not Elaboration_Warnings_OK (Call_Rep) |
| 2752 |
or else not Elaboration_Warnings_OK (Obj_Rep) |
| 2753 |
or else not Elaboration_Warnings_OK (Root_Rep); |
| 2754 |
|
| 2755 |
-- Update the state of the Processing phase to indicate that |
| 2756 |
-- any further traversal is now within a task body. |
| 2757 |
|
| 2758 |
New_In_State.Within_Task_Body := True; |
| 2759 |
|
| 2760 |
-- Associate the current task type with the activation call |
| 2761 |
|
| 2762 |
Set_Activated_Task_Type (Call_Rep, Root_Typ); |
| 2763 |
|
| 2764 |
-- Process the activation of the current task object by calling |
| 2765 |
-- the supplied processor. |
| 2766 |
|
| 2767 |
Processor.all |
| 2768 |
(Call => Call, |
| 2769 |
Call_Rep => Call_Rep, |
| 2770 |
Obj_Id => Obj_Id, |
| 2771 |
Obj_Rep => Obj_Rep, |
| 2772 |
Task_Typ => Root_Typ, |
| 2773 |
Task_Rep => Root_Rep, |
| 2774 |
In_State => New_In_State); |
| 2775 |
|
| 2776 |
-- Reset the association between the current task and the |
| 2777 |
-- activtion call. |
| 2778 |
|
| 2779 |
Set_Activated_Task_Type (Call_Rep, Empty); |
| 2780 |
|
| 2781 |
-- Examine the component type when the object is an array |
| 2782 |
|
| 2783 |
elsif Is_Array_Type (Typ) and then Has_Task (Root_Typ) then |
| 2784 |
Process_Task_Object |
| 2785 |
(Obj_Id => Obj_Id, |
| 2786 |
Typ => Component_Type (Typ)); |
| 2787 |
|
| 2788 |
-- Examine individual component types when the object is a record |
| 2789 |
|
| 2790 |
elsif Is_Record_Type (Typ) and then Has_Task (Root_Typ) then |
| 2791 |
Comp_Id := First_Component (Typ); |
| 2792 |
while Present (Comp_Id) loop |
| 2793 |
Process_Task_Object |
| 2794 |
(Obj_Id => Obj_Id, |
| 2795 |
Typ => Etype (Comp_Id)); |
| 2796 |
|
| 2797 |
Next_Component (Comp_Id); |
| 2798 |
end loop; |
| 2799 |
end if; |
| 2800 |
end Process_Task_Object; |
| 2801 |
|
| 2802 |
-------------------------- |
| 2803 |
-- Process_Task_Objects -- |
| 2804 |
-------------------------- |
| 2805 |
|
| 2806 |
procedure Process_Task_Objects |
| 2807 |
(Task_Objs : NE_List.Doubly_Linked_List) |
| 2808 |
is |
| 2809 |
Iter : NE_List.Iterator; |
| 2810 |
Obj_Id : Entity_Id; |
| 2811 |
|
| 2812 |
begin |
| 2813 |
Iter := NE_List.Iterate (Task_Objs); |
| 2814 |
while NE_List.Has_Next (Iter) loop |
| 2815 |
NE_List.Next (Iter, Obj_Id); |
| 2816 |
|
| 2817 |
Process_Task_Object |
| 2818 |
(Obj_Id => Obj_Id, |
| 2819 |
Typ => Etype (Obj_Id)); |
| 2820 |
end loop; |
| 2821 |
end Process_Task_Objects; |
| 2822 |
|
| 2823 |
------------------- |
| 2824 |
-- Traverse_List -- |
| 2825 |
------------------- |
| 2826 |
|
| 2827 |
procedure Traverse_List |
| 2828 |
(List : List_Id; |
| 2829 |
Task_Objs : NE_List.Doubly_Linked_List) |
| 2830 |
is |
| 2831 |
Item : Node_Id; |
| 2832 |
Item_Id : Entity_Id; |
| 2833 |
Item_Typ : Entity_Id; |
| 2834 |
|
| 2835 |
begin |
| 2836 |
-- Examine the contents of the list looking for an object |
| 2837 |
-- declaration of a task type or one that contains a task |
| 2838 |
-- within. |
| 2839 |
|
| 2840 |
Item := First (List); |
| 2841 |
while Present (Item) loop |
| 2842 |
if Nkind (Item) = N_Object_Declaration then |
| 2843 |
Item_Id := Defining_Entity (Item); |
| 2844 |
Item_Typ := Etype (Item_Id); |
| 2845 |
|
| 2846 |
if Has_Task (Item_Typ) then |
| 2847 |
|
| 2848 |
-- The object is either of a task type, or contains a |
| 2849 |
-- task component. Save it in the list of task objects |
| 2850 |
-- associated with the activation call. |
| 2851 |
|
| 2852 |
NE_List.Append (Task_Objs, Item_Id); |
| 2853 |
|
| 2854 |
Process_Task_Object |
| 2855 |
(Obj_Id => Item_Id, |
| 2856 |
Typ => Item_Typ); |
| 2857 |
end if; |
| 2858 |
end if; |
| 2859 |
|
| 2860 |
Next (Item); |
| 2861 |
end loop; |
| 2862 |
end Traverse_List; |
| 2863 |
|
| 2864 |
-- Local variables |
| 2865 |
|
| 2866 |
Context : Node_Id; |
| 2867 |
Spec : Node_Id; |
| 2868 |
Task_Objs : NE_List.Doubly_Linked_List; |
| 2869 |
|
| 2870 |
-- Start of processing for Process_Activation |
| 2871 |
|
| 2872 |
begin |
| 2873 |
-- Nothing to do when the activation is a guaranteed ABE |
| 2874 |
|
| 2875 |
if Is_Known_Guaranteed_ABE (Call) then |
| 2876 |
return; |
| 2877 |
end if; |
| 2878 |
|
| 2879 |
Task_Objs := Activated_Task_Objects (Call_Rep); |
| 2880 |
|
| 2881 |
-- The activation call has been processed at least once, and all |
| 2882 |
-- task objects have already been collected. Directly process the |
| 2883 |
-- objects without having to reexamine the context of the call. |
| 2884 |
|
| 2885 |
if NE_List.Present (Task_Objs) then |
| 2886 |
Process_Task_Objects (Task_Objs); |
| 2887 |
|
| 2888 |
-- Otherwise the activation call is being processed for the first |
| 2889 |
-- time. Collect all task objects in case the call is reprocessed |
| 2890 |
-- multiple times. |
| 2891 |
|
| 2892 |
else |
| 2893 |
Task_Objs := NE_List.Create; |
| 2894 |
Set_Activated_Task_Objects (Call_Rep, Task_Objs); |
| 2895 |
|
| 2896 |
-- Find the context of the activation call where all task objects |
| 2897 |
-- being activated are declared. This is usually the parent of the |
| 2898 |
-- call. |
| 2899 |
|
| 2900 |
Context := Parent (Call); |
| 2901 |
|
| 2902 |
-- Handle the case where the activation call appears within the |
| 2903 |
-- handled statements of a block or a body. |
| 2904 |
|
| 2905 |
if Nkind (Context) = N_Handled_Sequence_Of_Statements then |
| 2906 |
Context := Parent (Context); |
| 2907 |
end if; |
| 2908 |
|
| 2909 |
-- Process all task objects in both the spec and body when the |
| 2910 |
-- activation call appears in a package body. |
| 2911 |
|
| 2912 |
if Nkind (Context) = N_Package_Body then |
| 2913 |
Spec := |
| 2914 |
Specification |
| 2915 |
(Unit_Declaration_Node (Corresponding_Spec (Context))); |
| 2916 |
|
| 2917 |
Traverse_List |
| 2918 |
(List => Visible_Declarations (Spec), |
| 2919 |
Task_Objs => Task_Objs); |
| 2920 |
|
| 2921 |
Traverse_List |
| 2922 |
(List => Private_Declarations (Spec), |
| 2923 |
Task_Objs => Task_Objs); |
| 2924 |
|
| 2925 |
Traverse_List |
| 2926 |
(List => Declarations (Context), |
| 2927 |
Task_Objs => Task_Objs); |
| 2928 |
|
| 2929 |
-- Process all task objects in the spec when the activation call |
| 2930 |
-- appears in a package spec. |
| 2931 |
|
| 2932 |
elsif Nkind (Context) = N_Package_Specification then |
| 2933 |
Traverse_List |
| 2934 |
(List => Visible_Declarations (Context), |
| 2935 |
Task_Objs => Task_Objs); |
| 2936 |
|
| 2937 |
Traverse_List |
| 2938 |
(List => Private_Declarations (Context), |
| 2939 |
Task_Objs => Task_Objs); |
| 2940 |
|
| 2941 |
-- Otherwise the context must be a block or a body. Process all |
| 2942 |
-- task objects found in the declarations. |
| 2943 |
|
| 2944 |
else |
| 2945 |
pragma Assert |
| 2946 |
(Nkind (Context) in |
| 2947 |
N_Block_Statement | N_Entry_Body | N_Protected_Body | |
| 2948 |
N_Subprogram_Body | N_Task_Body); |
| 2949 |
|
| 2950 |
Traverse_List |
| 2951 |
(List => Declarations (Context), |
| 2952 |
Task_Objs => Task_Objs); |
| 2953 |
end if; |
| 2954 |
end if; |
| 2955 |
end Process_Activation; |
| 2956 |
end Activation_Processor; |
| 2957 |
|
| 2958 |
----------------------- |
| 2959 |
-- Assignment_Target -- |
| 2960 |
----------------------- |
| 2961 |
|
| 2962 |
function Assignment_Target (Asmt : Node_Id) return Node_Id is |
| 2963 |
Nam : Node_Id; |
| 2964 |
|
| 2965 |
begin |
| 2966 |
Nam := Name (Asmt); |
| 2967 |
|
| 2968 |
-- When the name denotes an array or record component, find the whole |
| 2969 |
-- object. |
| 2970 |
|
| 2971 |
while Nkind (Nam) in |
| 2972 |
N_Explicit_Dereference | N_Indexed_Component | |
| 2973 |
N_Selected_Component | N_Slice |
| 2974 |
loop |
| 2975 |
Nam := Prefix (Nam); |
| 2976 |
end loop; |
| 2977 |
|
| 2978 |
return Nam; |
| 2979 |
end Assignment_Target; |
| 2980 |
|
| 2981 |
-------------------- |
| 2982 |
-- Body_Processor -- |
| 2983 |
-------------------- |
| 2984 |
|
| 2985 |
package body Body_Processor is |
| 2986 |
|
| 2987 |
--------------------- |
| 2988 |
-- Data structures -- |
| 2989 |
--------------------- |
| 2990 |
|
| 2991 |
-- The following map relates scenario lists to subprogram bodies |
| 2992 |
|
| 2993 |
Nested_Scenarios_Map : NE_List_Map.Dynamic_Hash_Table := NE_List_Map.Nil; |
| 2994 |
|
| 2995 |
-- The following set contains all subprogram bodies that have been |
| 2996 |
-- processed by routine Traverse_Body. |
| 2997 |
|
| 2998 |
Traversed_Bodies_Set : NE_Set.Membership_Set := NE_Set.Nil; |
| 2999 |
|
| 3000 |
----------------------- |
| 3001 |
-- Local subprograms -- |
| 3002 |
----------------------- |
| 3003 |
|
| 3004 |
function Is_Traversed_Body (N : Node_Id) return Boolean; |
| 3005 |
pragma Inline (Is_Traversed_Body); |
| 3006 |
-- Determine whether subprogram body N has already been traversed |
| 3007 |
|
| 3008 |
function Nested_Scenarios |
| 3009 |
(N : Node_Id) return NE_List.Doubly_Linked_List; |
| 3010 |
pragma Inline (Nested_Scenarios); |
| 3011 |
-- Obtain the list of scenarios associated with subprogram body N |
| 3012 |
|
| 3013 |
procedure Set_Is_Traversed_Body (N : Node_Id); |
| 3014 |
pragma Inline (Set_Is_Traversed_Body); |
| 3015 |
-- Mark subprogram body N as traversed |
| 3016 |
|
| 3017 |
procedure Set_Nested_Scenarios |
| 3018 |
(N : Node_Id; |
| 3019 |
Scenarios : NE_List.Doubly_Linked_List); |
| 3020 |
pragma Inline (Set_Nested_Scenarios); |
| 3021 |
-- Associate scenario list Scenarios with subprogram body N |
| 3022 |
|
| 3023 |
----------------------------- |
| 3024 |
-- Finalize_Body_Processor -- |
| 3025 |
----------------------------- |
| 3026 |
|
| 3027 |
procedure Finalize_Body_Processor is |
| 3028 |
begin |
| 3029 |
NE_List_Map.Destroy (Nested_Scenarios_Map); |
| 3030 |
NE_Set.Destroy (Traversed_Bodies_Set); |
| 3031 |
end Finalize_Body_Processor; |
| 3032 |
|
| 3033 |
------------------------------- |
| 3034 |
-- Initialize_Body_Processor -- |
| 3035 |
------------------------------- |
| 3036 |
|
| 3037 |
procedure Initialize_Body_Processor is |
| 3038 |
begin |
| 3039 |
Nested_Scenarios_Map := NE_List_Map.Create (250); |
| 3040 |
Traversed_Bodies_Set := NE_Set.Create (250); |
| 3041 |
end Initialize_Body_Processor; |
| 3042 |
|
| 3043 |
----------------------- |
| 3044 |
-- Is_Traversed_Body -- |
| 3045 |
----------------------- |
| 3046 |
|
| 3047 |
function Is_Traversed_Body (N : Node_Id) return Boolean is |
| 3048 |
pragma Assert (Present (N)); |
| 3049 |
begin |
| 3050 |
return NE_Set.Contains (Traversed_Bodies_Set, N); |
| 3051 |
end Is_Traversed_Body; |
| 3052 |
|
| 3053 |
---------------------- |
| 3054 |
-- Nested_Scenarios -- |
| 3055 |
---------------------- |
| 3056 |
|
| 3057 |
function Nested_Scenarios |
| 3058 |
(N : Node_Id) return NE_List.Doubly_Linked_List |
| 3059 |
is |
| 3060 |
pragma Assert (Present (N)); |
| 3061 |
pragma Assert (Nkind (N) = N_Subprogram_Body); |
| 3062 |
|
| 3063 |
begin |
| 3064 |
return NE_List_Map.Get (Nested_Scenarios_Map, N); |
| 3065 |
end Nested_Scenarios; |
| 3066 |
|
| 3067 |
---------------------------- |
| 3068 |
-- Reset_Traversed_Bodies -- |
| 3069 |
---------------------------- |
| 3070 |
|
| 3071 |
procedure Reset_Traversed_Bodies is |
| 3072 |
begin |
| 3073 |
NE_Set.Reset (Traversed_Bodies_Set); |
| 3074 |
end Reset_Traversed_Bodies; |
| 3075 |
|
| 3076 |
--------------------------- |
| 3077 |
-- Set_Is_Traversed_Body -- |
| 3078 |
--------------------------- |
| 3079 |
|
| 3080 |
procedure Set_Is_Traversed_Body (N : Node_Id) is |
| 3081 |
pragma Assert (Present (N)); |
| 3082 |
|
| 3083 |
begin |
| 3084 |
NE_Set.Insert (Traversed_Bodies_Set, N); |
| 3085 |
end Set_Is_Traversed_Body; |
| 3086 |
|
| 3087 |
-------------------------- |
| 3088 |
-- Set_Nested_Scenarios -- |
| 3089 |
-------------------------- |
| 3090 |
|
| 3091 |
procedure Set_Nested_Scenarios |
| 3092 |
(N : Node_Id; |
| 3093 |
Scenarios : NE_List.Doubly_Linked_List) |
| 3094 |
is |
| 3095 |
pragma Assert (Present (N)); |
| 3096 |
begin |
| 3097 |
NE_List_Map.Put (Nested_Scenarios_Map, N, Scenarios); |
| 3098 |
end Set_Nested_Scenarios; |
| 3099 |
|
| 3100 |
------------------- |
| 3101 |
-- Traverse_Body -- |
| 3102 |
------------------- |
| 3103 |
|
| 3104 |
procedure Traverse_Body |
| 3105 |
(N : Node_Id; |
| 3106 |
Requires_Processing : Scenario_Predicate_Ptr; |
| 3107 |
Processor : Scenario_Processor_Ptr; |
| 3108 |
In_State : Processing_In_State) |
| 3109 |
is |
| 3110 |
Scenarios : NE_List.Doubly_Linked_List := NE_List.Nil; |
| 3111 |
-- The list of scenarios that appear within the declarations and |
| 3112 |
-- statement of subprogram body N. The variable is intentionally |
| 3113 |
-- global because Is_Potential_Scenario needs to populate it. |
| 3114 |
|
| 3115 |
function In_Task_Body (Nod : Node_Id) return Boolean; |
| 3116 |
pragma Inline (In_Task_Body); |
| 3117 |
-- Determine whether arbitrary node Nod appears within a task body |
| 3118 |
|
| 3119 |
function Is_Synchronous_Suspension_Call |
| 3120 |
(Nod : Node_Id) return Boolean; |
| 3121 |
pragma Inline (Is_Synchronous_Suspension_Call); |
| 3122 |
-- Determine whether arbitrary node Nod denotes a call to one of |
| 3123 |
-- these routines: |
| 3124 |
-- |
| 3125 |
-- Ada.Synchronous_Barriers.Wait_For_Release |
| 3126 |
-- Ada.Synchronous_Task_Control.Suspend_Until_True |
| 3127 |
|
| 3128 |
procedure Traverse_Collected_Scenarios; |
| 3129 |
pragma Inline (Traverse_Collected_Scenarios); |
| 3130 |
-- Traverse the already collected scenarios in list Scenarios by |
| 3131 |
-- invoking Processor on each individual one. |
| 3132 |
|
| 3133 |
procedure Traverse_List (List : List_Id); |
| 3134 |
pragma Inline (Traverse_List); |
| 3135 |
-- Invoke Traverse_Potential_Scenarios on each node in list List |
| 3136 |
|
| 3137 |
function Traverse_Potential_Scenario |
| 3138 |
(Scen : Node_Id) return Traverse_Result; |
| 3139 |
pragma Inline (Traverse_Potential_Scenario); |
| 3140 |
-- Determine whether arbitrary node Scen is a suitable scenario using |
| 3141 |
-- predicate Is_Scenario and traverse it by invoking Processor on it. |
| 3142 |
|
| 3143 |
procedure Traverse_Potential_Scenarios is |
| 3144 |
new Traverse_Proc (Traverse_Potential_Scenario); |
| 3145 |
|
| 3146 |
------------------ |
| 3147 |
-- In_Task_Body -- |
| 3148 |
------------------ |
| 3149 |
|
| 3150 |
function In_Task_Body (Nod : Node_Id) return Boolean is |
| 3151 |
Par : Node_Id; |
| 3152 |
|
| 3153 |
begin |
| 3154 |
-- Climb the parent chain looking for a task body [procedure] |
| 3155 |
|
| 3156 |
Par := Nod; |
| 3157 |
while Present (Par) loop |
| 3158 |
if Nkind (Par) = N_Task_Body then |
| 3159 |
return True; |
| 3160 |
|
| 3161 |
elsif Nkind (Par) = N_Subprogram_Body |
| 3162 |
and then Is_Task_Body_Procedure (Par) |
| 3163 |
then |
| 3164 |
return True; |
| 3165 |
|
| 3166 |
-- Prevent the search from going too far. Note that this test |
| 3167 |
-- shares nodes with the two cases above, and must come last. |
| 3168 |
|
| 3169 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 3170 |
return False; |
| 3171 |
end if; |
| 3172 |
|
| 3173 |
Par := Parent (Par); |
| 3174 |
end loop; |
| 3175 |
|
| 3176 |
return False; |
| 3177 |
end In_Task_Body; |
| 3178 |
|
| 3179 |
------------------------------------ |
| 3180 |
-- Is_Synchronous_Suspension_Call -- |
| 3181 |
------------------------------------ |
| 3182 |
|
| 3183 |
function Is_Synchronous_Suspension_Call |
| 3184 |
(Nod : Node_Id) return Boolean |
| 3185 |
is |
| 3186 |
Subp_Id : Entity_Id; |
| 3187 |
|
| 3188 |
begin |
| 3189 |
-- To qualify, the call must invoke one of the runtime routines |
| 3190 |
-- which perform synchronous suspension. |
| 3191 |
|
| 3192 |
if Is_Suitable_Call (Nod) then |
| 3193 |
Subp_Id := Target (Nod); |
| 3194 |
|
| 3195 |
return |
| 3196 |
Is_RTE (Subp_Id, RE_Suspend_Until_True) |
| 3197 |
or else |
| 3198 |
Is_RTE (Subp_Id, RE_Wait_For_Release); |
| 3199 |
end if; |
| 3200 |
|
| 3201 |
return False; |
| 3202 |
end Is_Synchronous_Suspension_Call; |
| 3203 |
|
| 3204 |
---------------------------------- |
| 3205 |
-- Traverse_Collected_Scenarios -- |
| 3206 |
---------------------------------- |
| 3207 |
|
| 3208 |
procedure Traverse_Collected_Scenarios is |
| 3209 |
Iter : NE_List.Iterator; |
| 3210 |
Scen : Node_Id; |
| 3211 |
|
| 3212 |
begin |
| 3213 |
Iter := NE_List.Iterate (Scenarios); |
| 3214 |
while NE_List.Has_Next (Iter) loop |
| 3215 |
NE_List.Next (Iter, Scen); |
| 3216 |
|
| 3217 |
-- The current scenario satisfies the input predicate, process |
| 3218 |
-- it. |
| 3219 |
|
| 3220 |
if Requires_Processing.all (Scen) then |
| 3221 |
Processor.all (Scen, In_State); |
| 3222 |
end if; |
| 3223 |
end loop; |
| 3224 |
end Traverse_Collected_Scenarios; |
| 3225 |
|
| 3226 |
------------------- |
| 3227 |
-- Traverse_List -- |
| 3228 |
------------------- |
| 3229 |
|
| 3230 |
procedure Traverse_List (List : List_Id) is |
| 3231 |
Scen : Node_Id; |
| 3232 |
|
| 3233 |
begin |
| 3234 |
Scen := First (List); |
| 3235 |
while Present (Scen) loop |
| 3236 |
Traverse_Potential_Scenarios (Scen); |
| 3237 |
Next (Scen); |
| 3238 |
end loop; |
| 3239 |
end Traverse_List; |
| 3240 |
|
| 3241 |
--------------------------------- |
| 3242 |
-- Traverse_Potential_Scenario -- |
| 3243 |
--------------------------------- |
| 3244 |
|
| 3245 |
function Traverse_Potential_Scenario |
| 3246 |
(Scen : Node_Id) return Traverse_Result |
| 3247 |
is |
| 3248 |
begin |
| 3249 |
-- Special cases |
| 3250 |
|
| 3251 |
-- Skip constructs which do not have elaboration of their own and |
| 3252 |
-- need to be elaborated by other means such as invocation, task |
| 3253 |
-- activation, etc. |
| 3254 |
|
| 3255 |
if Is_Non_Library_Level_Encapsulator (Scen) then |
| 3256 |
return Skip; |
| 3257 |
|
| 3258 |
-- Terminate the traversal of a task body when encountering an |
| 3259 |
-- accept or select statement, and |
| 3260 |
-- |
| 3261 |
-- * Entry calls during elaboration are not allowed. In this |
| 3262 |
-- case the accept or select statement will cause the task |
| 3263 |
-- to block at elaboration time because there are no entry |
| 3264 |
-- calls to unblock it. |
| 3265 |
-- |
| 3266 |
-- or |
| 3267 |
-- |
| 3268 |
-- * Switch -gnatd_a (stop elaboration checks on accept or |
| 3269 |
-- select statement) is in effect. |
| 3270 |
|
| 3271 |
elsif (Debug_Flag_Underscore_A |
| 3272 |
or else Restriction_Active |
| 3273 |
(No_Entry_Calls_In_Elaboration_Code)) |
| 3274 |
and then Nkind (Original_Node (Scen)) in |
| 3275 |
N_Accept_Statement | N_Selective_Accept |
| 3276 |
then |
| 3277 |
return Abandon; |
| 3278 |
|
| 3279 |
-- Terminate the traversal of a task body when encountering a |
| 3280 |
-- suspension call, and |
| 3281 |
-- |
| 3282 |
-- * Entry calls during elaboration are not allowed. In this |
| 3283 |
-- case the suspension call emulates an entry call and will |
| 3284 |
-- cause the task to block at elaboration time. |
| 3285 |
-- |
| 3286 |
-- or |
| 3287 |
-- |
| 3288 |
-- * Switch -gnatd_s (stop elaboration checks on synchronous |
| 3289 |
-- suspension) is in effect. |
| 3290 |
-- |
| 3291 |
-- Note that the guard should not be checking the state of flag |
| 3292 |
-- Within_Task_Body because only suspension calls which appear |
| 3293 |
-- immediately within the statements of the task are supported. |
| 3294 |
-- Flag Within_Task_Body carries over to deeper levels of the |
| 3295 |
-- traversal. |
| 3296 |
|
| 3297 |
elsif (Debug_Flag_Underscore_S |
| 3298 |
or else Restriction_Active |
| 3299 |
(No_Entry_Calls_In_Elaboration_Code)) |
| 3300 |
and then Is_Synchronous_Suspension_Call (Scen) |
| 3301 |
and then In_Task_Body (Scen) |
| 3302 |
then |
| 3303 |
return Abandon; |
| 3304 |
|
| 3305 |
-- Certain nodes carry semantic lists which act as repositories |
| 3306 |
-- until expansion transforms the node and relocates the contents. |
| 3307 |
-- Examine these lists in case expansion is disabled. |
| 3308 |
|
| 3309 |
elsif Nkind (Scen) in N_And_Then | N_Or_Else then |
| 3310 |
Traverse_List (Actions (Scen)); |
| 3311 |
|
| 3312 |
elsif Nkind (Scen) in N_Elsif_Part | N_Iteration_Scheme then |
| 3313 |
Traverse_List (Condition_Actions (Scen)); |
| 3314 |
|
| 3315 |
elsif Nkind (Scen) = N_If_Expression then |
| 3316 |
Traverse_List (Then_Actions (Scen)); |
| 3317 |
Traverse_List (Else_Actions (Scen)); |
| 3318 |
|
| 3319 |
elsif Nkind (Scen) in |
| 3320 |
N_Component_Association |
| 3321 |
| N_Iterated_Component_Association |
| 3322 |
| N_Iterated_Element_Association |
| 3323 |
then |
| 3324 |
Traverse_List (Loop_Actions (Scen)); |
| 3325 |
|
| 3326 |
-- General case |
| 3327 |
|
| 3328 |
-- The current node satisfies the input predicate, process it |
| 3329 |
|
| 3330 |
elsif Requires_Processing.all (Scen) then |
| 3331 |
Processor.all (Scen, In_State); |
| 3332 |
end if; |
| 3333 |
|
| 3334 |
-- Save a general scenario regardless of whether it satisfies the |
| 3335 |
-- input predicate. This allows for quick subsequent traversals of |
| 3336 |
-- general scenarios, even with different predicates. |
| 3337 |
|
| 3338 |
if Is_Suitable_Access_Taken (Scen) |
| 3339 |
or else Is_Suitable_Call (Scen) |
| 3340 |
or else Is_Suitable_Instantiation (Scen) |
| 3341 |
or else Is_Suitable_Variable_Assignment (Scen) |
| 3342 |
or else Is_Suitable_Variable_Reference (Scen) |
| 3343 |
then |
| 3344 |
NE_List.Append (Scenarios, Scen); |
| 3345 |
end if; |
| 3346 |
|
| 3347 |
return OK; |
| 3348 |
end Traverse_Potential_Scenario; |
| 3349 |
|
| 3350 |
-- Start of processing for Traverse_Body |
| 3351 |
|
| 3352 |
begin |
| 3353 |
-- Nothing to do when the traversal is suppressed |
| 3354 |
|
| 3355 |
if In_State.Traversal = No_Traversal then |
| 3356 |
return; |
| 3357 |
|
| 3358 |
-- Nothing to do when there is no input |
| 3359 |
|
| 3360 |
elsif No (N) then |
| 3361 |
return; |
| 3362 |
|
| 3363 |
-- Nothing to do when the input is not a subprogram body |
| 3364 |
|
| 3365 |
elsif Nkind (N) /= N_Subprogram_Body then |
| 3366 |
return; |
| 3367 |
|
| 3368 |
-- Nothing to do if the subprogram body was already traversed |
| 3369 |
|
| 3370 |
elsif Is_Traversed_Body (N) then |
| 3371 |
return; |
| 3372 |
end if; |
| 3373 |
|
| 3374 |
-- Mark the subprogram body as traversed |
| 3375 |
|
| 3376 |
Set_Is_Traversed_Body (N); |
| 3377 |
|
| 3378 |
Scenarios := Nested_Scenarios (N); |
| 3379 |
|
| 3380 |
-- The subprogram body has been traversed at least once, and all |
| 3381 |
-- scenarios that appear within its declarations and statements |
| 3382 |
-- have already been collected. Directly retraverse the scenarios |
| 3383 |
-- without having to retraverse the subprogram body subtree. |
| 3384 |
|
| 3385 |
if NE_List.Present (Scenarios) then |
| 3386 |
Traverse_Collected_Scenarios; |
| 3387 |
|
| 3388 |
-- Otherwise the subprogram body is being traversed for the first |
| 3389 |
-- time. Collect all scenarios that appear within its declarations |
| 3390 |
-- and statements in case the subprogram body has to be retraversed |
| 3391 |
-- multiple times. |
| 3392 |
|
| 3393 |
else |
| 3394 |
Scenarios := NE_List.Create; |
| 3395 |
Set_Nested_Scenarios (N, Scenarios); |
| 3396 |
|
| 3397 |
Traverse_List (Declarations (N)); |
| 3398 |
Traverse_Potential_Scenarios (Handled_Statement_Sequence (N)); |
| 3399 |
end if; |
| 3400 |
end Traverse_Body; |
| 3401 |
end Body_Processor; |
| 3402 |
|
| 3403 |
----------------------- |
| 3404 |
-- Build_Call_Marker -- |
| 3405 |
----------------------- |
| 3406 |
|
| 3407 |
procedure Build_Call_Marker (N : Node_Id) is |
| 3408 |
function In_External_Context |
| 3409 |
(Call : Node_Id; |
| 3410 |
Subp_Id : Entity_Id) return Boolean; |
| 3411 |
pragma Inline (In_External_Context); |
| 3412 |
-- Determine whether entry, operator, or subprogram Subp_Id is external |
| 3413 |
-- to call Call which must reside within an instance. |
| 3414 |
|
| 3415 |
function In_Premature_Context (Call : Node_Id) return Boolean; |
| 3416 |
pragma Inline (In_Premature_Context); |
| 3417 |
-- Determine whether call Call appears within a premature context |
| 3418 |
|
| 3419 |
function Is_Default_Expression (Call : Node_Id) return Boolean; |
| 3420 |
pragma Inline (Is_Default_Expression); |
| 3421 |
-- Determine whether call Call acts as the expression of a defaulted |
| 3422 |
-- parameter within a source call. |
| 3423 |
|
| 3424 |
function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean; |
| 3425 |
pragma Inline (Is_Generic_Formal_Subp); |
| 3426 |
-- Determine whether subprogram Subp_Id denotes a generic formal |
| 3427 |
-- subprogram which appears in the "prologue" of an instantiation. |
| 3428 |
|
| 3429 |
------------------------- |
| 3430 |
-- In_External_Context -- |
| 3431 |
------------------------- |
| 3432 |
|
| 3433 |
function In_External_Context |
| 3434 |
(Call : Node_Id; |
| 3435 |
Subp_Id : Entity_Id) return Boolean |
| 3436 |
is |
| 3437 |
Spec_Decl : constant Entity_Id := Unit_Declaration_Node (Subp_Id); |
| 3438 |
|
| 3439 |
Inst : Node_Id; |
| 3440 |
Inst_Body : Node_Id; |
| 3441 |
Inst_Spec : Node_Id; |
| 3442 |
|
| 3443 |
begin |
| 3444 |
Inst := Find_Enclosing_Instance (Call); |
| 3445 |
|
| 3446 |
-- The call appears within an instance |
| 3447 |
|
| 3448 |
if Present (Inst) then |
| 3449 |
|
| 3450 |
-- The call comes from the main unit and the target does not |
| 3451 |
|
| 3452 |
if In_Extended_Main_Code_Unit (Call) |
| 3453 |
and then not In_Extended_Main_Code_Unit (Spec_Decl) |
| 3454 |
then |
| 3455 |
return True; |
| 3456 |
|
| 3457 |
-- Otherwise the target declaration must not appear within the |
| 3458 |
-- instance spec or body. |
| 3459 |
|
| 3460 |
else |
| 3461 |
Spec_And_Body_From_Node |
| 3462 |
(N => Inst, |
| 3463 |
Spec_Decl => Inst_Spec, |
| 3464 |
Body_Decl => Inst_Body); |
| 3465 |
|
| 3466 |
return not In_Subtree |
| 3467 |
(N => Spec_Decl, |
| 3468 |
Root1 => Inst_Spec, |
| 3469 |
Root2 => Inst_Body); |
| 3470 |
end if; |
| 3471 |
end if; |
| 3472 |
|
| 3473 |
return False; |
| 3474 |
end In_External_Context; |
| 3475 |
|
| 3476 |
-------------------------- |
| 3477 |
-- In_Premature_Context -- |
| 3478 |
-------------------------- |
| 3479 |
|
| 3480 |
function In_Premature_Context (Call : Node_Id) return Boolean is |
| 3481 |
Par : Node_Id; |
| 3482 |
|
| 3483 |
begin |
| 3484 |
-- Climb the parent chain looking for premature contexts |
| 3485 |
|
| 3486 |
Par := Parent (Call); |
| 3487 |
while Present (Par) loop |
| 3488 |
|
| 3489 |
-- Aspect specifications and generic associations are premature |
| 3490 |
-- contexts because nested calls has not been relocated to their |
| 3491 |
-- final context. |
| 3492 |
|
| 3493 |
if Nkind (Par) in N_Aspect_Specification | N_Generic_Association |
| 3494 |
then |
| 3495 |
return True; |
| 3496 |
|
| 3497 |
-- Prevent the search from going too far |
| 3498 |
|
| 3499 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 3500 |
exit; |
| 3501 |
end if; |
| 3502 |
|
| 3503 |
Par := Parent (Par); |
| 3504 |
end loop; |
| 3505 |
|
| 3506 |
return False; |
| 3507 |
end In_Premature_Context; |
| 3508 |
|
| 3509 |
--------------------------- |
| 3510 |
-- Is_Default_Expression -- |
| 3511 |
--------------------------- |
| 3512 |
|
| 3513 |
function Is_Default_Expression (Call : Node_Id) return Boolean is |
| 3514 |
Outer_Call : constant Node_Id := Parent (Call); |
| 3515 |
Outer_Nam : Node_Id; |
| 3516 |
|
| 3517 |
begin |
| 3518 |
-- To qualify, the node must appear immediately within a source call |
| 3519 |
-- which invokes a source target. |
| 3520 |
|
| 3521 |
if Nkind (Outer_Call) in N_Entry_Call_Statement |
| 3522 |
| N_Function_Call |
| 3523 |
| N_Procedure_Call_Statement |
| 3524 |
and then Comes_From_Source (Outer_Call) |
| 3525 |
then |
| 3526 |
Outer_Nam := Call_Name (Outer_Call); |
| 3527 |
|
| 3528 |
return |
| 3529 |
Is_Entity_Name (Outer_Nam) |
| 3530 |
and then Present (Entity (Outer_Nam)) |
| 3531 |
and then Is_Subprogram_Or_Entry (Entity (Outer_Nam)) |
| 3532 |
and then Comes_From_Source (Entity (Outer_Nam)); |
| 3533 |
end if; |
| 3534 |
|
| 3535 |
return False; |
| 3536 |
end Is_Default_Expression; |
| 3537 |
|
| 3538 |
---------------------------- |
| 3539 |
-- Is_Generic_Formal_Subp -- |
| 3540 |
---------------------------- |
| 3541 |
|
| 3542 |
function Is_Generic_Formal_Subp (Subp_Id : Entity_Id) return Boolean is |
| 3543 |
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id); |
| 3544 |
Context : constant Node_Id := Parent (Subp_Decl); |
| 3545 |
|
| 3546 |
begin |
| 3547 |
-- To qualify, the subprogram must rename a generic actual subprogram |
| 3548 |
-- where the enclosing context is an instantiation. |
| 3549 |
|
| 3550 |
return |
| 3551 |
Nkind (Subp_Decl) = N_Subprogram_Renaming_Declaration |
| 3552 |
and then not Comes_From_Source (Subp_Decl) |
| 3553 |
and then Nkind (Context) in N_Function_Specification |
| 3554 |
| N_Package_Specification |
| 3555 |
| N_Procedure_Specification |
| 3556 |
and then Present (Generic_Parent (Context)); |
| 3557 |
end Is_Generic_Formal_Subp; |
| 3558 |
|
| 3559 |
-- Local variables |
| 3560 |
|
| 3561 |
Call_Nam : Node_Id; |
| 3562 |
Marker : Node_Id; |
| 3563 |
Subp_Id : Entity_Id; |
| 3564 |
|
| 3565 |
-- Start of processing for Build_Call_Marker |
| 3566 |
|
| 3567 |
begin |
| 3568 |
-- Nothing to do when switch -gnatH (legacy elaboration checking mode |
| 3569 |
-- enabled) is in effect because the legacy ABE mechanism does not need |
| 3570 |
-- to carry out this action. |
| 3571 |
|
| 3572 |
if Legacy_Elaboration_Checks then |
| 3573 |
return; |
| 3574 |
|
| 3575 |
-- Nothing to do when the call is being preanalyzed as the marker will |
| 3576 |
-- be inserted in the wrong place. |
| 3577 |
|
| 3578 |
elsif Preanalysis_Active then |
| 3579 |
return; |
| 3580 |
|
| 3581 |
-- Nothing to do when the elaboration phase of the compiler is not |
| 3582 |
-- active. |
| 3583 |
|
| 3584 |
elsif not Elaboration_Phase_Active then |
| 3585 |
return; |
| 3586 |
|
| 3587 |
-- Nothing to do when the input does not denote a call or a requeue |
| 3588 |
|
| 3589 |
elsif Nkind (N) not in N_Entry_Call_Statement |
| 3590 |
| N_Function_Call |
| 3591 |
| N_Procedure_Call_Statement |
| 3592 |
| N_Requeue_Statement |
| 3593 |
then |
| 3594 |
return; |
| 3595 |
|
| 3596 |
-- Nothing to do when the input denotes entry call or requeue statement, |
| 3597 |
-- and switch -gnatd_e (ignore entry calls and requeue statements for |
| 3598 |
-- elaboration) is in effect. |
| 3599 |
|
| 3600 |
elsif Debug_Flag_Underscore_E |
| 3601 |
and then Nkind (N) in N_Entry_Call_Statement | N_Requeue_Statement |
| 3602 |
then |
| 3603 |
return; |
| 3604 |
|
| 3605 |
-- Nothing to do when the call is analyzed/resolved too early within an |
| 3606 |
-- intermediate context. This check is saved for last because it incurs |
| 3607 |
-- a performance penalty. |
| 3608 |
|
| 3609 |
elsif In_Premature_Context (N) then |
| 3610 |
return; |
| 3611 |
end if; |
| 3612 |
|
| 3613 |
Call_Nam := Call_Name (N); |
| 3614 |
|
| 3615 |
-- Nothing to do when the call is erroneous or left in a bad state |
| 3616 |
|
| 3617 |
if not (Is_Entity_Name (Call_Nam) |
| 3618 |
and then Present (Entity (Call_Nam)) |
| 3619 |
and then Is_Subprogram_Or_Entry (Entity (Call_Nam))) |
| 3620 |
then |
| 3621 |
return; |
| 3622 |
end if; |
| 3623 |
|
| 3624 |
Subp_Id := Canonical_Subprogram (Entity (Call_Nam)); |
| 3625 |
|
| 3626 |
-- Nothing to do when the call invokes a generic formal subprogram and |
| 3627 |
-- switch -gnatd.G (ignore calls through generic formal parameters for |
| 3628 |
-- elaboration) is in effect. This check must be performed with the |
| 3629 |
-- direct target of the call to avoid the side effects of mapping |
| 3630 |
-- actuals to formals using renamings. |
| 3631 |
|
| 3632 |
if Debug_Flag_Dot_GG |
| 3633 |
and then Is_Generic_Formal_Subp (Entity (Call_Nam)) |
| 3634 |
then |
| 3635 |
return; |
| 3636 |
|
| 3637 |
-- Nothing to do when the call appears within the expanded spec or |
| 3638 |
-- body of an instantiated generic, the call does not invoke a generic |
| 3639 |
-- formal subprogram, the target is external to the instance, and switch |
| 3640 |
-- -gnatdL (ignore external calls from instances for elaboration) is in |
| 3641 |
-- effect. This check must be performed with the direct target of the |
| 3642 |
-- call to avoid the side effects of mapping actuals to formals using |
| 3643 |
-- renamings. |
| 3644 |
|
| 3645 |
elsif Debug_Flag_LL |
| 3646 |
and then not Is_Generic_Formal_Subp (Entity (Call_Nam)) |
| 3647 |
and then In_External_Context |
| 3648 |
(Call => N, |
| 3649 |
Subp_Id => Subp_Id) |
| 3650 |
then |
| 3651 |
return; |
| 3652 |
|
| 3653 |
-- Nothing to do when the call invokes an assertion pragma procedure |
| 3654 |
-- and switch -gnatd_p (ignore assertion pragmas for elaboration) is |
| 3655 |
-- in effect. |
| 3656 |
|
| 3657 |
elsif Debug_Flag_Underscore_P |
| 3658 |
and then Is_Assertion_Pragma_Target (Subp_Id) |
| 3659 |
then |
| 3660 |
return; |
| 3661 |
|
| 3662 |
-- Static expression functions require no ABE processing |
| 3663 |
|
| 3664 |
elsif Is_Static_Function (Subp_Id) then |
| 3665 |
return; |
| 3666 |
|
| 3667 |
-- Source calls to source targets are always considered because they |
| 3668 |
-- reflect the original call graph. |
| 3669 |
|
| 3670 |
elsif Comes_From_Source (N) and then Comes_From_Source (Subp_Id) then |
| 3671 |
null; |
| 3672 |
|
| 3673 |
-- A call to a source function which acts as the default expression in |
| 3674 |
-- another call requires special detection. |
| 3675 |
|
| 3676 |
elsif Comes_From_Source (Subp_Id) |
| 3677 |
and then Nkind (N) = N_Function_Call |
| 3678 |
and then Is_Default_Expression (N) |
| 3679 |
then |
| 3680 |
null; |
| 3681 |
|
| 3682 |
-- The target emulates Ada semantics |
| 3683 |
|
| 3684 |
elsif Is_Ada_Semantic_Target (Subp_Id) then |
| 3685 |
null; |
| 3686 |
|
| 3687 |
-- The target acts as a link between scenarios |
| 3688 |
|
| 3689 |
elsif Is_Bridge_Target (Subp_Id) then |
| 3690 |
null; |
| 3691 |
|
| 3692 |
-- The target emulates SPARK semantics |
| 3693 |
|
| 3694 |
elsif Is_SPARK_Semantic_Target (Subp_Id) then |
| 3695 |
null; |
| 3696 |
|
| 3697 |
-- Otherwise the call is not suitable for ABE processing. This prevents |
| 3698 |
-- the generation of call markers which will never play a role in ABE |
| 3699 |
-- diagnostics. |
| 3700 |
|
| 3701 |
else |
| 3702 |
return; |
| 3703 |
end if; |
| 3704 |
|
| 3705 |
-- At this point it is known that the call will play some role in ABE |
| 3706 |
-- checks and diagnostics. Create a corresponding call marker in case |
| 3707 |
-- the original call is heavily transformed by expansion later on. |
| 3708 |
|
| 3709 |
Marker := Make_Call_Marker (Sloc (N)); |
| 3710 |
|
| 3711 |
-- Inherit the attributes of the original call |
| 3712 |
|
| 3713 |
Set_Is_Declaration_Level_Node |
| 3714 |
(Marker, Find_Enclosing_Level (N) = Declaration_Level); |
| 3715 |
|
| 3716 |
Set_Is_Dispatching_Call |
| 3717 |
(Marker, |
| 3718 |
Nkind (N) in N_Subprogram_Call |
| 3719 |
and then Present (Controlling_Argument (N))); |
| 3720 |
|
| 3721 |
Set_Is_Elaboration_Checks_OK_Node |
| 3722 |
(Marker, Is_Elaboration_Checks_OK_Node (N)); |
| 3723 |
|
| 3724 |
Set_Is_Elaboration_Warnings_OK_Node |
| 3725 |
(Marker, Is_Elaboration_Warnings_OK_Node (N)); |
| 3726 |
|
| 3727 |
Set_Is_Ignored_Ghost_Node (Marker, Is_Ignored_Ghost_Node (N)); |
| 3728 |
Set_Is_Source_Call (Marker, Comes_From_Source (N)); |
| 3729 |
Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N)); |
| 3730 |
Set_Target (Marker, Subp_Id); |
| 3731 |
|
| 3732 |
-- Ada 2022 (AI12-0175): Calls to certain functions that are essentially |
| 3733 |
-- unchecked conversions are preelaborable. |
| 3734 |
|
| 3735 |
if Ada_Version >= Ada_2022 then |
| 3736 |
Set_Is_Preelaborable_Call (Marker, Is_Preelaborable_Construct (N)); |
| 3737 |
else |
| 3738 |
Set_Is_Preelaborable_Call (Marker, False); |
| 3739 |
end if; |
| 3740 |
|
| 3741 |
-- The marker is inserted prior to the original call. This placement has |
| 3742 |
-- several desirable effects: |
| 3743 |
|
| 3744 |
-- 1) The marker appears in the same context, in close proximity to |
| 3745 |
-- the call. |
| 3746 |
|
| 3747 |
-- <marker> |
| 3748 |
-- <call> |
| 3749 |
|
| 3750 |
-- 2) Inserting the marker prior to the call ensures that an ABE check |
| 3751 |
-- will take effect prior to the call. |
| 3752 |
|
| 3753 |
-- <ABE check> |
| 3754 |
-- <marker> |
| 3755 |
-- <call> |
| 3756 |
|
| 3757 |
-- 3) The above two properties are preserved even when the call is a |
| 3758 |
-- function which is subsequently relocated in order to capture its |
| 3759 |
-- result. Note that if the call is relocated to a new context, the |
| 3760 |
-- relocated call will receive a marker of its own. |
| 3761 |
|
| 3762 |
-- <ABE check> |
| 3763 |
-- <maker> |
| 3764 |
-- Temp : ... := Func_Call ...; |
| 3765 |
-- ... Temp ... |
| 3766 |
|
| 3767 |
-- The insertion must take place even when the call does not occur in |
| 3768 |
-- the main unit to keep the tree symmetric. This ensures that internal |
| 3769 |
-- name serialization is consistent in case the call marker causes the |
| 3770 |
-- tree to transform in some way. |
| 3771 |
|
| 3772 |
Insert_Action (N, Marker); |
| 3773 |
|
| 3774 |
-- The marker becomes the "corresponding" scenario for the call. Save |
| 3775 |
-- the marker for later processing by the ABE phase. |
| 3776 |
|
| 3777 |
Record_Elaboration_Scenario (Marker); |
| 3778 |
end Build_Call_Marker; |
| 3779 |
|
| 3780 |
------------------------------------- |
| 3781 |
-- Build_Variable_Reference_Marker -- |
| 3782 |
------------------------------------- |
| 3783 |
|
| 3784 |
procedure Build_Variable_Reference_Marker |
| 3785 |
(N : Node_Id; |
| 3786 |
Read : Boolean; |
| 3787 |
Write : Boolean) |
| 3788 |
is |
| 3789 |
function Ultimate_Variable (Var_Id : Entity_Id) return Entity_Id; |
| 3790 |
pragma Inline (Ultimate_Variable); |
| 3791 |
-- Obtain the ultimate renamed variable of variable Var_Id |
| 3792 |
|
| 3793 |
----------------------- |
| 3794 |
-- Ultimate_Variable -- |
| 3795 |
----------------------- |
| 3796 |
|
| 3797 |
function Ultimate_Variable (Var_Id : Entity_Id) return Entity_Id is |
| 3798 |
pragma Assert (Ekind (Var_Id) = E_Variable); |
| 3799 |
Ren_Id : Entity_Id; |
| 3800 |
begin |
| 3801 |
Ren_Id := Var_Id; |
| 3802 |
while Present (Renamed_Object (Ren_Id)) |
| 3803 |
and then Nkind (Renamed_Object (Ren_Id)) in N_Entity |
| 3804 |
loop |
| 3805 |
Ren_Id := Renamed_Object (Ren_Id); |
| 3806 |
end loop; |
| 3807 |
|
| 3808 |
return Ren_Id; |
| 3809 |
end Ultimate_Variable; |
| 3810 |
|
| 3811 |
-- Local variables |
| 3812 |
|
| 3813 |
Var_Id : constant Entity_Id := Ultimate_Variable (Entity (N)); |
| 3814 |
Marker : Node_Id; |
| 3815 |
|
| 3816 |
-- Start of processing for Build_Variable_Reference_Marker |
| 3817 |
|
| 3818 |
begin |
| 3819 |
-- Nothing to do when the elaboration phase of the compiler is not |
| 3820 |
-- active. |
| 3821 |
|
| 3822 |
if not Elaboration_Phase_Active then |
| 3823 |
return; |
| 3824 |
end if; |
| 3825 |
|
| 3826 |
Marker := Make_Variable_Reference_Marker (Sloc (N)); |
| 3827 |
|
| 3828 |
-- Inherit the attributes of the original variable reference |
| 3829 |
|
| 3830 |
Set_Is_Elaboration_Checks_OK_Node |
| 3831 |
(Marker, Is_Elaboration_Checks_OK_Node (N)); |
| 3832 |
|
| 3833 |
Set_Is_Elaboration_Warnings_OK_Node |
| 3834 |
(Marker, Is_Elaboration_Warnings_OK_Node (N)); |
| 3835 |
|
| 3836 |
Set_Is_Read (Marker, Read); |
| 3837 |
Set_Is_SPARK_Mode_On_Node (Marker, Is_SPARK_Mode_On_Node (N)); |
| 3838 |
Set_Is_Write (Marker, Write); |
| 3839 |
Set_Target (Marker, Var_Id); |
| 3840 |
|
| 3841 |
-- The marker is inserted prior to the original variable reference. The |
| 3842 |
-- insertion must take place even when the reference does not occur in |
| 3843 |
-- the main unit to keep the tree symmetric. This ensures that internal |
| 3844 |
-- name serialization is consistent in case the variable marker causes |
| 3845 |
-- the tree to transform in some way. |
| 3846 |
|
| 3847 |
Insert_Action (N, Marker); |
| 3848 |
|
| 3849 |
-- The marker becomes the "corresponding" scenario for the reference. |
| 3850 |
-- Save the marker for later processing for the ABE phase. |
| 3851 |
|
| 3852 |
Record_Elaboration_Scenario (Marker); |
| 3853 |
end Build_Variable_Reference_Marker; |
| 3854 |
|
| 3855 |
--------------- |
| 3856 |
-- Call_Name -- |
| 3857 |
--------------- |
| 3858 |
|
| 3859 |
function Call_Name (Call : Node_Id) return Node_Id is |
| 3860 |
Nam : Node_Id; |
| 3861 |
|
| 3862 |
begin |
| 3863 |
Nam := Name (Call); |
| 3864 |
|
| 3865 |
-- When the call invokes an entry family, the name appears as an indexed |
| 3866 |
-- component. |
| 3867 |
|
| 3868 |
if Nkind (Nam) = N_Indexed_Component then |
| 3869 |
Nam := Prefix (Nam); |
| 3870 |
end if; |
| 3871 |
|
| 3872 |
-- When the call employs the object.operation form, the name appears as |
| 3873 |
-- a selected component. |
| 3874 |
|
| 3875 |
if Nkind (Nam) = N_Selected_Component then |
| 3876 |
Nam := Selector_Name (Nam); |
| 3877 |
end if; |
| 3878 |
|
| 3879 |
return Nam; |
| 3880 |
end Call_Name; |
| 3881 |
|
| 3882 |
-------------------------- |
| 3883 |
-- Canonical_Subprogram -- |
| 3884 |
-------------------------- |
| 3885 |
|
| 3886 |
function Canonical_Subprogram (Subp_Id : Entity_Id) return Entity_Id is |
| 3887 |
Canon_Id : Entity_Id; |
| 3888 |
|
| 3889 |
begin |
| 3890 |
Canon_Id := Subp_Id; |
| 3891 |
|
| 3892 |
-- Use the original protected subprogram when dealing with one of the |
| 3893 |
-- specialized lock-manipulating versions. |
| 3894 |
|
| 3895 |
if Is_Protected_Body_Subp (Canon_Id) then |
| 3896 |
Canon_Id := Protected_Subprogram (Canon_Id); |
| 3897 |
end if; |
| 3898 |
|
| 3899 |
-- Obtain the original subprogram except when the subprogram is also |
| 3900 |
-- an instantiation. In this case the alias is the internally generated |
| 3901 |
-- subprogram which appears within the anonymous package created for the |
| 3902 |
-- instantiation, making it unuitable. |
| 3903 |
|
| 3904 |
if not Is_Generic_Instance (Canon_Id) then |
| 3905 |
Canon_Id := Get_Renamed_Entity (Canon_Id); |
| 3906 |
end if; |
| 3907 |
|
| 3908 |
return Canon_Id; |
| 3909 |
end Canonical_Subprogram; |
| 3910 |
|
| 3911 |
--------------------------------- |
| 3912 |
-- Check_Elaboration_Scenarios -- |
| 3913 |
--------------------------------- |
| 3914 |
|
| 3915 |
procedure Check_Elaboration_Scenarios is |
| 3916 |
Iter : NE_Set.Iterator; |
| 3917 |
|
| 3918 |
begin |
| 3919 |
-- Nothing to do when switch -gnatH (legacy elaboration checking mode |
| 3920 |
-- enabled) is in effect because the legacy ABE mechanism does not need |
| 3921 |
-- to carry out this action. |
| 3922 |
|
| 3923 |
if Legacy_Elaboration_Checks then |
| 3924 |
Finalize_All_Data_Structures; |
| 3925 |
return; |
| 3926 |
|
| 3927 |
-- Nothing to do when the elaboration phase of the compiler is not |
| 3928 |
-- active. |
| 3929 |
|
| 3930 |
elsif not Elaboration_Phase_Active then |
| 3931 |
Finalize_All_Data_Structures; |
| 3932 |
return; |
| 3933 |
end if; |
| 3934 |
|
| 3935 |
-- Restore the original elaboration model which was in effect when the |
| 3936 |
-- scenarios were first recorded. The model may be specified by pragma |
| 3937 |
-- Elaboration_Checks which appears on the initial declaration of the |
| 3938 |
-- main unit. |
| 3939 |
|
| 3940 |
Install_Elaboration_Model (Unit_Entity (Main_Unit_Entity)); |
| 3941 |
|
| 3942 |
-- Examine the context of the main unit and record all units with prior |
| 3943 |
-- elaboration with respect to it. |
| 3944 |
|
| 3945 |
Collect_Elaborated_Units; |
| 3946 |
|
| 3947 |
-- Examine all scenarios saved during the Recording phase applying the |
| 3948 |
-- Ada or SPARK elaboration rules in order to detect and diagnose ABE |
| 3949 |
-- issues, install conditional ABE checks, and ensure the elaboration |
| 3950 |
-- of units. |
| 3951 |
|
| 3952 |
Iter := Iterate_Declaration_Scenarios; |
| 3953 |
Check_Conditional_ABE_Scenarios (Iter); |
| 3954 |
|
| 3955 |
Iter := Iterate_Library_Body_Scenarios; |
| 3956 |
Check_Conditional_ABE_Scenarios (Iter); |
| 3957 |
|
| 3958 |
Iter := Iterate_Library_Spec_Scenarios; |
| 3959 |
Check_Conditional_ABE_Scenarios (Iter); |
| 3960 |
|
| 3961 |
-- Examine each SPARK scenario saved during the Recording phase which |
| 3962 |
-- is not necessarily executable during elaboration, but still requires |
| 3963 |
-- elaboration-related checks. |
| 3964 |
|
| 3965 |
Check_SPARK_Scenarios; |
| 3966 |
|
| 3967 |
-- Add conditional ABE checks for all scenarios that require one when |
| 3968 |
-- the dynamic model is in effect. |
| 3969 |
|
| 3970 |
Install_Dynamic_ABE_Checks; |
| 3971 |
|
| 3972 |
-- Examine all scenarios saved during the Recording phase along with |
| 3973 |
-- invocation constructs within the spec and body of the main unit. |
| 3974 |
-- Record the declarations and paths that reach into an external unit |
| 3975 |
-- in the ALI file of the main unit. |
| 3976 |
|
| 3977 |
Record_Invocation_Graph; |
| 3978 |
|
| 3979 |
-- Destroy all internal data structures and complete the elaboration |
| 3980 |
-- phase of the compiler. |
| 3981 |
|
| 3982 |
Finalize_All_Data_Structures; |
| 3983 |
Set_Elaboration_Phase (Completed); |
| 3984 |
end Check_Elaboration_Scenarios; |
| 3985 |
|
| 3986 |
--------------------- |
| 3987 |
-- Check_Installer -- |
| 3988 |
--------------------- |
| 3989 |
|
| 3990 |
package body Check_Installer is |
| 3991 |
|
| 3992 |
----------------------- |
| 3993 |
-- Local subprograms -- |
| 3994 |
----------------------- |
| 3995 |
|
| 3996 |
function ABE_Check_Or_Failure_OK |
| 3997 |
(N : Node_Id; |
| 3998 |
Targ_Id : Entity_Id; |
| 3999 |
Unit_Id : Entity_Id) return Boolean; |
| 4000 |
pragma Inline (ABE_Check_Or_Failure_OK); |
| 4001 |
-- Determine whether a conditional ABE check or guaranteed ABE failure |
| 4002 |
-- can be installed for scenario N with target Targ_Id which resides in |
| 4003 |
-- unit Unit_Id. |
| 4004 |
|
| 4005 |
function Insertion_Node (N : Node_Id) return Node_Id; |
| 4006 |
pragma Inline (Insertion_Node); |
| 4007 |
-- Obtain the proper insertion node of an ABE check or failure for |
| 4008 |
-- scenario N. |
| 4009 |
|
| 4010 |
procedure Insert_ABE_Check_Or_Failure (N : Node_Id; Check : Node_Id); |
| 4011 |
pragma Inline (Insert_ABE_Check_Or_Failure); |
| 4012 |
-- Insert conditional ABE check or guaranteed ABE failure Check prior to |
| 4013 |
-- scenario N. |
| 4014 |
|
| 4015 |
procedure Install_Scenario_ABE_Check_Common |
| 4016 |
(N : Node_Id; |
| 4017 |
Targ_Id : Entity_Id; |
| 4018 |
Targ_Rep : Target_Rep_Id); |
| 4019 |
pragma Inline (Install_Scenario_ABE_Check_Common); |
| 4020 |
-- Install a conditional ABE check for scenario N to ensure that target |
| 4021 |
-- Targ_Id is properly elaborated. Targ_Rep is the representation of the |
| 4022 |
-- target. |
| 4023 |
|
| 4024 |
procedure Install_Scenario_ABE_Failure_Common (N : Node_Id); |
| 4025 |
pragma Inline (Install_Scenario_ABE_Failure_Common); |
| 4026 |
-- Install a guaranteed ABE failure for scenario N |
| 4027 |
|
| 4028 |
procedure Install_Unit_ABE_Check_Common |
| 4029 |
(N : Node_Id; |
| 4030 |
Unit_Id : Entity_Id); |
| 4031 |
pragma Inline (Install_Unit_ABE_Check_Common); |
| 4032 |
-- Install a conditional ABE check for scenario N to ensure that unit |
| 4033 |
-- Unit_Id is properly elaborated. |
| 4034 |
|
| 4035 |
----------------------------- |
| 4036 |
-- ABE_Check_Or_Failure_OK -- |
| 4037 |
----------------------------- |
| 4038 |
|
| 4039 |
function ABE_Check_Or_Failure_OK |
| 4040 |
(N : Node_Id; |
| 4041 |
Targ_Id : Entity_Id; |
| 4042 |
Unit_Id : Entity_Id) return Boolean |
| 4043 |
is |
| 4044 |
pragma Unreferenced (Targ_Id); |
| 4045 |
|
| 4046 |
Ins_Node : constant Node_Id := Insertion_Node (N); |
| 4047 |
|
| 4048 |
begin |
| 4049 |
if not Check_Or_Failure_Generation_OK then |
| 4050 |
return False; |
| 4051 |
|
| 4052 |
-- Nothing to do when the scenario denots a compilation unit because |
| 4053 |
-- there is no executable environment at that level. |
| 4054 |
|
| 4055 |
elsif Nkind (Parent (Ins_Node)) = N_Compilation_Unit then |
| 4056 |
return False; |
| 4057 |
|
| 4058 |
-- An ABE check or failure is not needed when the target is defined |
| 4059 |
-- in a unit which is elaborated prior to the main unit. This check |
| 4060 |
-- must also consider the following cases: |
| 4061 |
-- |
| 4062 |
-- * The unit of the target appears in the context of the main unit |
| 4063 |
-- |
| 4064 |
-- * The unit of the target is subject to pragma Elaborate_Body. An |
| 4065 |
-- ABE check MUST NOT be generated because the unit is always |
| 4066 |
-- elaborated prior to the main unit. |
| 4067 |
-- |
| 4068 |
-- * The unit of the target is the main unit. An ABE check MUST be |
| 4069 |
-- added in this case because a conditional ABE may be raised |
| 4070 |
-- depending on the flow of execution within the main unit (flag |
| 4071 |
-- Same_Unit_OK is False). |
| 4072 |
|
| 4073 |
elsif Has_Prior_Elaboration |
| 4074 |
(Unit_Id => Unit_Id, |
| 4075 |
Context_OK => True, |
| 4076 |
Elab_Body_OK => True) |
| 4077 |
then |
| 4078 |
return False; |
| 4079 |
end if; |
| 4080 |
|
| 4081 |
return True; |
| 4082 |
end ABE_Check_Or_Failure_OK; |
| 4083 |
|
| 4084 |
------------------------------------ |
| 4085 |
-- Check_Or_Failure_Generation_OK -- |
| 4086 |
------------------------------------ |
| 4087 |
|
| 4088 |
function Check_Or_Failure_Generation_OK return Boolean is |
| 4089 |
begin |
| 4090 |
-- An ABE check or failure is not needed when the compilation will |
| 4091 |
-- not produce an executable. |
| 4092 |
|
| 4093 |
if Serious_Errors_Detected > 0 then |
| 4094 |
return False; |
| 4095 |
|
| 4096 |
-- An ABE check or failure must not be installed when compiling for |
| 4097 |
-- GNATprove because raise statements are not supported. |
| 4098 |
|
| 4099 |
elsif GNATprove_Mode then |
| 4100 |
return False; |
| 4101 |
end if; |
| 4102 |
|
| 4103 |
return True; |
| 4104 |
end Check_Or_Failure_Generation_OK; |
| 4105 |
|
| 4106 |
-------------------- |
| 4107 |
-- Insertion_Node -- |
| 4108 |
-------------------- |
| 4109 |
|
| 4110 |
function Insertion_Node (N : Node_Id) return Node_Id is |
| 4111 |
begin |
| 4112 |
-- When the scenario denotes an instantiation, the proper insertion |
| 4113 |
-- node is the instance spec. This ensures that the generic actuals |
| 4114 |
-- will not be evaluated prior to a potential ABE. |
| 4115 |
|
| 4116 |
if Nkind (N) in N_Generic_Instantiation |
| 4117 |
and then Present (Instance_Spec (N)) |
| 4118 |
then |
| 4119 |
return Instance_Spec (N); |
| 4120 |
|
| 4121 |
-- Otherwise the proper insertion node is the scenario itself |
| 4122 |
|
| 4123 |
else |
| 4124 |
return N; |
| 4125 |
end if; |
| 4126 |
end Insertion_Node; |
| 4127 |
|
| 4128 |
--------------------------------- |
| 4129 |
-- Insert_ABE_Check_Or_Failure -- |
| 4130 |
--------------------------------- |
| 4131 |
|
| 4132 |
procedure Insert_ABE_Check_Or_Failure (N : Node_Id; Check : Node_Id) is |
| 4133 |
Ins_Nod : constant Node_Id := Insertion_Node (N); |
| 4134 |
Scop_Id : constant Entity_Id := Find_Enclosing_Scope (Ins_Nod); |
| 4135 |
|
| 4136 |
begin |
| 4137 |
-- Install the nearest enclosing scope of the scenario as there must |
| 4138 |
-- be something on the scope stack. |
| 4139 |
|
| 4140 |
Push_Scope (Scop_Id); |
| 4141 |
|
| 4142 |
Insert_Action (Ins_Nod, Check); |
| 4143 |
|
| 4144 |
Pop_Scope; |
| 4145 |
end Insert_ABE_Check_Or_Failure; |
| 4146 |
|
| 4147 |
-------------------------------- |
| 4148 |
-- Install_Dynamic_ABE_Checks -- |
| 4149 |
-------------------------------- |
| 4150 |
|
| 4151 |
procedure Install_Dynamic_ABE_Checks is |
| 4152 |
Iter : NE_Set.Iterator; |
| 4153 |
N : Node_Id; |
| 4154 |
|
| 4155 |
begin |
| 4156 |
if not Check_Or_Failure_Generation_OK then |
| 4157 |
return; |
| 4158 |
|
| 4159 |
-- Nothing to do if the dynamic model is not in effect |
| 4160 |
|
| 4161 |
elsif not Dynamic_Elaboration_Checks then |
| 4162 |
return; |
| 4163 |
end if; |
| 4164 |
|
| 4165 |
-- Install a conditional ABE check for each saved scenario |
| 4166 |
|
| 4167 |
Iter := Iterate_Dynamic_ABE_Check_Scenarios; |
| 4168 |
while NE_Set.Has_Next (Iter) loop |
| 4169 |
NE_Set.Next (Iter, N); |
| 4170 |
|
| 4171 |
Process_Conditional_ABE |
| 4172 |
(N => N, |
| 4173 |
In_State => Dynamic_Model_State); |
| 4174 |
end loop; |
| 4175 |
end Install_Dynamic_ABE_Checks; |
| 4176 |
|
| 4177 |
-------------------------------- |
| 4178 |
-- Install_Scenario_ABE_Check -- |
| 4179 |
-------------------------------- |
| 4180 |
|
| 4181 |
procedure Install_Scenario_ABE_Check |
| 4182 |
(N : Node_Id; |
| 4183 |
Targ_Id : Entity_Id; |
| 4184 |
Targ_Rep : Target_Rep_Id; |
| 4185 |
Disable : Scenario_Rep_Id) |
| 4186 |
is |
| 4187 |
begin |
| 4188 |
-- Nothing to do when the scenario does not need an ABE check |
| 4189 |
|
| 4190 |
if not ABE_Check_Or_Failure_OK |
| 4191 |
(N => N, |
| 4192 |
Targ_Id => Targ_Id, |
| 4193 |
Unit_Id => Unit (Targ_Rep)) |
| 4194 |
then |
| 4195 |
return; |
| 4196 |
end if; |
| 4197 |
|
| 4198 |
-- Prevent multiple attempts to install the same ABE check |
| 4199 |
|
| 4200 |
Disable_Elaboration_Checks (Disable); |
| 4201 |
|
| 4202 |
Install_Scenario_ABE_Check_Common |
| 4203 |
(N => N, |
| 4204 |
Targ_Id => Targ_Id, |
| 4205 |
Targ_Rep => Targ_Rep); |
| 4206 |
end Install_Scenario_ABE_Check; |
| 4207 |
|
| 4208 |
-------------------------------- |
| 4209 |
-- Install_Scenario_ABE_Check -- |
| 4210 |
-------------------------------- |
| 4211 |
|
| 4212 |
procedure Install_Scenario_ABE_Check |
| 4213 |
(N : Node_Id; |
| 4214 |
Targ_Id : Entity_Id; |
| 4215 |
Targ_Rep : Target_Rep_Id; |
| 4216 |
Disable : Target_Rep_Id) |
| 4217 |
is |
| 4218 |
begin |
| 4219 |
-- Nothing to do when the scenario does not need an ABE check |
| 4220 |
|
| 4221 |
if not ABE_Check_Or_Failure_OK |
| 4222 |
(N => N, |
| 4223 |
Targ_Id => Targ_Id, |
| 4224 |
Unit_Id => Unit (Targ_Rep)) |
| 4225 |
then |
| 4226 |
return; |
| 4227 |
end if; |
| 4228 |
|
| 4229 |
-- Prevent multiple attempts to install the same ABE check |
| 4230 |
|
| 4231 |
Disable_Elaboration_Checks (Disable); |
| 4232 |
|
| 4233 |
Install_Scenario_ABE_Check_Common |
| 4234 |
(N => N, |
| 4235 |
Targ_Id => Targ_Id, |
| 4236 |
Targ_Rep => Targ_Rep); |
| 4237 |
end Install_Scenario_ABE_Check; |
| 4238 |
|
| 4239 |
--------------------------------------- |
| 4240 |
-- Install_Scenario_ABE_Check_Common -- |
| 4241 |
--------------------------------------- |
| 4242 |
|
| 4243 |
procedure Install_Scenario_ABE_Check_Common |
| 4244 |
(N : Node_Id; |
| 4245 |
Targ_Id : Entity_Id; |
| 4246 |
Targ_Rep : Target_Rep_Id) |
| 4247 |
is |
| 4248 |
Targ_Body : constant Node_Id := Body_Declaration (Targ_Rep); |
| 4249 |
Targ_Decl : constant Node_Id := Spec_Declaration (Targ_Rep); |
| 4250 |
|
| 4251 |
pragma Assert (Present (Targ_Body)); |
| 4252 |
pragma Assert (Present (Targ_Decl)); |
| 4253 |
|
| 4254 |
procedure Build_Elaboration_Entity; |
| 4255 |
pragma Inline (Build_Elaboration_Entity); |
| 4256 |
-- Create a new elaboration flag for Targ_Id, insert it prior to |
| 4257 |
-- Targ_Decl, and set it after Targ_Body. |
| 4258 |
|
| 4259 |
------------------------------ |
| 4260 |
-- Build_Elaboration_Entity -- |
| 4261 |
------------------------------ |
| 4262 |
|
| 4263 |
procedure Build_Elaboration_Entity is |
| 4264 |
Loc : constant Source_Ptr := Sloc (Targ_Id); |
| 4265 |
Flag_Id : Entity_Id; |
| 4266 |
|
| 4267 |
begin |
| 4268 |
-- Nothing to do if the target has an elaboration flag |
| 4269 |
|
| 4270 |
if Present (Elaboration_Entity (Targ_Id)) then |
| 4271 |
return; |
| 4272 |
end if; |
| 4273 |
|
| 4274 |
-- Create the declaration of the elaboration flag. The name |
| 4275 |
-- carries a unique counter in case the name is overloaded. |
| 4276 |
|
| 4277 |
Flag_Id := |
| 4278 |
Make_Defining_Identifier (Loc, |
| 4279 |
Chars => New_External_Name (Chars (Targ_Id), 'E', -1)); |
| 4280 |
|
| 4281 |
Set_Elaboration_Entity (Targ_Id, Flag_Id); |
| 4282 |
Set_Elaboration_Entity_Required (Targ_Id); |
| 4283 |
|
| 4284 |
Push_Scope (Scope (Targ_Id)); |
| 4285 |
|
| 4286 |
-- Generate: |
| 4287 |
-- Enn : Short_Integer := 0; |
| 4288 |
|
| 4289 |
Insert_Action (Targ_Decl, |
| 4290 |
Make_Object_Declaration (Loc, |
| 4291 |
Defining_Identifier => Flag_Id, |
| 4292 |
Object_Definition => |
| 4293 |
New_Occurrence_Of (Standard_Short_Integer, Loc), |
| 4294 |
Expression => Make_Integer_Literal (Loc, Uint_0))); |
| 4295 |
|
| 4296 |
-- Generate: |
| 4297 |
-- Enn := 1; |
| 4298 |
|
| 4299 |
Set_Elaboration_Flag (Targ_Body, Targ_Id); |
| 4300 |
|
| 4301 |
Pop_Scope; |
| 4302 |
end Build_Elaboration_Entity; |
| 4303 |
|
| 4304 |
-- Local variables |
| 4305 |
|
| 4306 |
Loc : constant Source_Ptr := Sloc (N); |
| 4307 |
|
| 4308 |
-- Start for processing for Install_Scenario_ABE_Check_Common |
| 4309 |
|
| 4310 |
begin |
| 4311 |
-- Create an elaboration flag for the target when it does not have |
| 4312 |
-- one. |
| 4313 |
|
| 4314 |
Build_Elaboration_Entity; |
| 4315 |
|
| 4316 |
-- Generate: |
| 4317 |
-- if not Targ_Id'Elaborated then |
| 4318 |
-- raise Program_Error with "access before elaboration"; |
| 4319 |
-- end if; |
| 4320 |
|
| 4321 |
Insert_ABE_Check_Or_Failure |
| 4322 |
(N => N, |
| 4323 |
Check => |
| 4324 |
Make_Raise_Program_Error (Loc, |
| 4325 |
Condition => |
| 4326 |
Make_Op_Not (Loc, |
| 4327 |
Right_Opnd => |
| 4328 |
Make_Attribute_Reference (Loc, |
| 4329 |
Prefix => New_Occurrence_Of (Targ_Id, Loc), |
| 4330 |
Attribute_Name => Name_Elaborated)), |
| 4331 |
Reason => PE_Access_Before_Elaboration)); |
| 4332 |
end Install_Scenario_ABE_Check_Common; |
| 4333 |
|
| 4334 |
---------------------------------- |
| 4335 |
-- Install_Scenario_ABE_Failure -- |
| 4336 |
---------------------------------- |
| 4337 |
|
| 4338 |
procedure Install_Scenario_ABE_Failure |
| 4339 |
(N : Node_Id; |
| 4340 |
Targ_Id : Entity_Id; |
| 4341 |
Targ_Rep : Target_Rep_Id; |
| 4342 |
Disable : Scenario_Rep_Id) |
| 4343 |
is |
| 4344 |
begin |
| 4345 |
-- Nothing to do when the scenario does not require an ABE failure |
| 4346 |
|
| 4347 |
if not ABE_Check_Or_Failure_OK |
| 4348 |
(N => N, |
| 4349 |
Targ_Id => Targ_Id, |
| 4350 |
Unit_Id => Unit (Targ_Rep)) |
| 4351 |
then |
| 4352 |
return; |
| 4353 |
end if; |
| 4354 |
|
| 4355 |
-- Prevent multiple attempts to install the same ABE check |
| 4356 |
|
| 4357 |
Disable_Elaboration_Checks (Disable); |
| 4358 |
|
| 4359 |
Install_Scenario_ABE_Failure_Common (N); |
| 4360 |
end Install_Scenario_ABE_Failure; |
| 4361 |
|
| 4362 |
---------------------------------- |
| 4363 |
-- Install_Scenario_ABE_Failure -- |
| 4364 |
---------------------------------- |
| 4365 |
|
| 4366 |
procedure Install_Scenario_ABE_Failure |
| 4367 |
(N : Node_Id; |
| 4368 |
Targ_Id : Entity_Id; |
| 4369 |
Targ_Rep : Target_Rep_Id; |
| 4370 |
Disable : Target_Rep_Id) |
| 4371 |
is |
| 4372 |
begin |
| 4373 |
-- Nothing to do when the scenario does not require an ABE failure |
| 4374 |
|
| 4375 |
if not ABE_Check_Or_Failure_OK |
| 4376 |
(N => N, |
| 4377 |
Targ_Id => Targ_Id, |
| 4378 |
Unit_Id => Unit (Targ_Rep)) |
| 4379 |
then |
| 4380 |
return; |
| 4381 |
end if; |
| 4382 |
|
| 4383 |
-- Prevent multiple attempts to install the same ABE check |
| 4384 |
|
| 4385 |
Disable_Elaboration_Checks (Disable); |
| 4386 |
|
| 4387 |
Install_Scenario_ABE_Failure_Common (N); |
| 4388 |
end Install_Scenario_ABE_Failure; |
| 4389 |
|
| 4390 |
----------------------------------------- |
| 4391 |
-- Install_Scenario_ABE_Failure_Common -- |
| 4392 |
----------------------------------------- |
| 4393 |
|
| 4394 |
procedure Install_Scenario_ABE_Failure_Common (N : Node_Id) is |
| 4395 |
Loc : constant Source_Ptr := Sloc (N); |
| 4396 |
|
| 4397 |
begin |
| 4398 |
-- Generate: |
| 4399 |
-- raise Program_Error with "access before elaboration"; |
| 4400 |
|
| 4401 |
Insert_ABE_Check_Or_Failure |
| 4402 |
(N => N, |
| 4403 |
Check => |
| 4404 |
Make_Raise_Program_Error (Loc, |
| 4405 |
Reason => PE_Access_Before_Elaboration)); |
| 4406 |
end Install_Scenario_ABE_Failure_Common; |
| 4407 |
|
| 4408 |
---------------------------- |
| 4409 |
-- Install_Unit_ABE_Check -- |
| 4410 |
---------------------------- |
| 4411 |
|
| 4412 |
procedure Install_Unit_ABE_Check |
| 4413 |
(N : Node_Id; |
| 4414 |
Unit_Id : Entity_Id; |
| 4415 |
Disable : Scenario_Rep_Id) |
| 4416 |
is |
| 4417 |
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id); |
| 4418 |
|
| 4419 |
begin |
| 4420 |
-- Nothing to do when the scenario does not require an ABE check |
| 4421 |
|
| 4422 |
if not ABE_Check_Or_Failure_OK |
| 4423 |
(N => N, |
| 4424 |
Targ_Id => Empty, |
| 4425 |
Unit_Id => Spec_Id) |
| 4426 |
then |
| 4427 |
return; |
| 4428 |
end if; |
| 4429 |
|
| 4430 |
-- Prevent multiple attempts to install the same ABE check |
| 4431 |
|
| 4432 |
Disable_Elaboration_Checks (Disable); |
| 4433 |
|
| 4434 |
Install_Unit_ABE_Check_Common |
| 4435 |
(N => N, |
| 4436 |
Unit_Id => Unit_Id); |
| 4437 |
end Install_Unit_ABE_Check; |
| 4438 |
|
| 4439 |
---------------------------- |
| 4440 |
-- Install_Unit_ABE_Check -- |
| 4441 |
---------------------------- |
| 4442 |
|
| 4443 |
procedure Install_Unit_ABE_Check |
| 4444 |
(N : Node_Id; |
| 4445 |
Unit_Id : Entity_Id; |
| 4446 |
Disable : Target_Rep_Id) |
| 4447 |
is |
| 4448 |
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id); |
| 4449 |
|
| 4450 |
begin |
| 4451 |
-- Nothing to do when the scenario does not require an ABE check |
| 4452 |
|
| 4453 |
if not ABE_Check_Or_Failure_OK |
| 4454 |
(N => N, |
| 4455 |
Targ_Id => Empty, |
| 4456 |
Unit_Id => Spec_Id) |
| 4457 |
then |
| 4458 |
return; |
| 4459 |
end if; |
| 4460 |
|
| 4461 |
-- Prevent multiple attempts to install the same ABE check |
| 4462 |
|
| 4463 |
Disable_Elaboration_Checks (Disable); |
| 4464 |
|
| 4465 |
Install_Unit_ABE_Check_Common |
| 4466 |
(N => N, |
| 4467 |
Unit_Id => Unit_Id); |
| 4468 |
end Install_Unit_ABE_Check; |
| 4469 |
|
| 4470 |
----------------------------------- |
| 4471 |
-- Install_Unit_ABE_Check_Common -- |
| 4472 |
----------------------------------- |
| 4473 |
|
| 4474 |
procedure Install_Unit_ABE_Check_Common |
| 4475 |
(N : Node_Id; |
| 4476 |
Unit_Id : Entity_Id) |
| 4477 |
is |
| 4478 |
Loc : constant Source_Ptr := Sloc (N); |
| 4479 |
Spec_Id : constant Entity_Id := Unique_Entity (Unit_Id); |
| 4480 |
|
| 4481 |
begin |
| 4482 |
-- Generate: |
| 4483 |
-- if not Spec_Id'Elaborated then |
| 4484 |
-- raise Program_Error with "access before elaboration"; |
| 4485 |
-- end if; |
| 4486 |
|
| 4487 |
Insert_ABE_Check_Or_Failure |
| 4488 |
(N => N, |
| 4489 |
Check => |
| 4490 |
Make_Raise_Program_Error (Loc, |
| 4491 |
Condition => |
| 4492 |
Make_Op_Not (Loc, |
| 4493 |
Right_Opnd => |
| 4494 |
Make_Attribute_Reference (Loc, |
| 4495 |
Prefix => New_Occurrence_Of (Spec_Id, Loc), |
| 4496 |
Attribute_Name => Name_Elaborated)), |
| 4497 |
Reason => PE_Access_Before_Elaboration)); |
| 4498 |
end Install_Unit_ABE_Check_Common; |
| 4499 |
end Check_Installer; |
| 4500 |
|
| 4501 |
---------------------- |
| 4502 |
-- Compilation_Unit -- |
| 4503 |
---------------------- |
| 4504 |
|
| 4505 |
function Compilation_Unit (Unit_Id : Entity_Id) return Node_Id is |
| 4506 |
Comp_Unit : Node_Id; |
| 4507 |
|
| 4508 |
begin |
| 4509 |
Comp_Unit := Parent (Unit_Id); |
| 4510 |
|
| 4511 |
-- Handle the case where a concurrent subunit is rewritten as a null |
| 4512 |
-- statement due to expansion activities. |
| 4513 |
|
| 4514 |
if Nkind (Comp_Unit) = N_Null_Statement |
| 4515 |
and then Nkind (Original_Node (Comp_Unit)) in |
| 4516 |
N_Protected_Body | N_Task_Body |
| 4517 |
then |
| 4518 |
Comp_Unit := Parent (Comp_Unit); |
| 4519 |
pragma Assert (Nkind (Comp_Unit) = N_Subunit); |
| 4520 |
|
| 4521 |
-- Otherwise use the declaration node of the unit |
| 4522 |
|
| 4523 |
else |
| 4524 |
Comp_Unit := Parent (Unit_Declaration_Node (Unit_Id)); |
| 4525 |
end if; |
| 4526 |
|
| 4527 |
-- Handle the case where a subprogram instantiation which acts as a |
| 4528 |
-- compilation unit is expanded into an anonymous package that wraps |
| 4529 |
-- the instantiated subprogram. |
| 4530 |
|
| 4531 |
if Nkind (Comp_Unit) = N_Package_Specification |
| 4532 |
and then Nkind (Original_Node (Parent (Comp_Unit))) in |
| 4533 |
N_Function_Instantiation | N_Procedure_Instantiation |
| 4534 |
then |
| 4535 |
Comp_Unit := Parent (Parent (Comp_Unit)); |
| 4536 |
|
| 4537 |
-- Handle the case where the compilation unit is a subunit |
| 4538 |
|
| 4539 |
elsif Nkind (Comp_Unit) = N_Subunit then |
| 4540 |
Comp_Unit := Parent (Comp_Unit); |
| 4541 |
end if; |
| 4542 |
|
| 4543 |
pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit); |
| 4544 |
|
| 4545 |
return Comp_Unit; |
| 4546 |
end Compilation_Unit; |
| 4547 |
|
| 4548 |
------------------------------- |
| 4549 |
-- Conditional_ABE_Processor -- |
| 4550 |
------------------------------- |
| 4551 |
|
| 4552 |
package body Conditional_ABE_Processor is |
| 4553 |
|
| 4554 |
----------------------- |
| 4555 |
-- Local subprograms -- |
| 4556 |
----------------------- |
| 4557 |
|
| 4558 |
function Is_Conditional_ABE_Scenario (N : Node_Id) return Boolean; |
| 4559 |
pragma Inline (Is_Conditional_ABE_Scenario); |
| 4560 |
-- Determine whether node N is a suitable scenario for conditional ABE |
| 4561 |
-- checks and diagnostics. |
| 4562 |
|
| 4563 |
procedure Process_Conditional_ABE_Access_Taken |
| 4564 |
(Attr : Node_Id; |
| 4565 |
Attr_Rep : Scenario_Rep_Id; |
| 4566 |
In_State : Processing_In_State); |
| 4567 |
pragma Inline (Process_Conditional_ABE_Access_Taken); |
| 4568 |
-- Perform ABE checks and diagnostics for attribute reference Attr with |
| 4569 |
-- representation Attr_Rep which takes 'Access of an entry, operator, or |
| 4570 |
-- subprogram. In_State is the current state of the Processing phase. |
| 4571 |
|
| 4572 |
procedure Process_Conditional_ABE_Activation |
| 4573 |
(Call : Node_Id; |
| 4574 |
Call_Rep : Scenario_Rep_Id; |
| 4575 |
Obj_Id : Entity_Id; |
| 4576 |
Obj_Rep : Target_Rep_Id; |
| 4577 |
Task_Typ : Entity_Id; |
| 4578 |
Task_Rep : Target_Rep_Id; |
| 4579 |
In_State : Processing_In_State); |
| 4580 |
pragma Inline (Process_Conditional_ABE_Activation); |
| 4581 |
-- Perform common conditional ABE checks and diagnostics for activation |
| 4582 |
-- call Call which activates object Obj_Id of task type Task_Typ. Formal |
| 4583 |
-- Call_Rep denotes the representation of the call. Obj_Rep denotes the |
| 4584 |
-- representation of the object. Task_Rep denotes the representation of |
| 4585 |
-- the task type. In_State is the current state of the Processing phase. |
| 4586 |
|
| 4587 |
procedure Process_Conditional_ABE_Call |
| 4588 |
(Call : Node_Id; |
| 4589 |
Call_Rep : Scenario_Rep_Id; |
| 4590 |
In_State : Processing_In_State); |
| 4591 |
pragma Inline (Process_Conditional_ABE_Call); |
| 4592 |
-- Top-level dispatcher for processing of calls. Perform ABE checks and |
| 4593 |
-- diagnostics for call Call with representation Call_Rep. In_State is |
| 4594 |
-- the current state of the Processing phase. |
| 4595 |
|
| 4596 |
procedure Process_Conditional_ABE_Call_Ada |
| 4597 |
(Call : Node_Id; |
| 4598 |
Call_Rep : Scenario_Rep_Id; |
| 4599 |
Subp_Id : Entity_Id; |
| 4600 |
Subp_Rep : Target_Rep_Id; |
| 4601 |
In_State : Processing_In_State); |
| 4602 |
pragma Inline (Process_Conditional_ABE_Call_Ada); |
| 4603 |
-- Perform ABE checks and diagnostics for call Call which invokes entry, |
| 4604 |
-- operator, or subprogram Subp_Id using the Ada rules. Call_Rep denotes |
| 4605 |
-- the representation of the call. Subp_Rep denotes the representation |
| 4606 |
-- of the subprogram. In_State is the current state of the Processing |
| 4607 |
-- phase. |
| 4608 |
|
| 4609 |
procedure Process_Conditional_ABE_Call_SPARK |
| 4610 |
(Call : Node_Id; |
| 4611 |
Call_Rep : Scenario_Rep_Id; |
| 4612 |
Subp_Id : Entity_Id; |
| 4613 |
Subp_Rep : Target_Rep_Id; |
| 4614 |
In_State : Processing_In_State); |
| 4615 |
pragma Inline (Process_Conditional_ABE_Call_SPARK); |
| 4616 |
-- Perform ABE checks and diagnostics for call Call which invokes entry, |
| 4617 |
-- operator, or subprogram Subp_Id using the SPARK rules. Call_Rep is |
| 4618 |
-- the representation of the call. Subp_Rep denotes the representation |
| 4619 |
-- of the subprogram. In_State is the current state of the Processing |
| 4620 |
-- phase. |
| 4621 |
|
| 4622 |
procedure Process_Conditional_ABE_Instantiation |
| 4623 |
(Inst : Node_Id; |
| 4624 |
Inst_Rep : Scenario_Rep_Id; |
| 4625 |
In_State : Processing_In_State); |
| 4626 |
pragma Inline (Process_Conditional_ABE_Instantiation); |
| 4627 |
-- Top-level dispatcher for processing of instantiations. Perform ABE |
| 4628 |
-- checks and diagnostics for instantiation Inst with representation |
| 4629 |
-- Inst_Rep. In_State is the current state of the Processing phase. |
| 4630 |
|
| 4631 |
procedure Process_Conditional_ABE_Instantiation_Ada |
| 4632 |
(Inst : Node_Id; |
| 4633 |
Inst_Rep : Scenario_Rep_Id; |
| 4634 |
Gen_Id : Entity_Id; |
| 4635 |
Gen_Rep : Target_Rep_Id; |
| 4636 |
In_State : Processing_In_State); |
| 4637 |
pragma Inline (Process_Conditional_ABE_Instantiation_Ada); |
| 4638 |
-- Perform ABE checks and diagnostics for instantiation Inst of generic |
| 4639 |
-- Gen_Id using the Ada rules. Inst_Rep denotes the representation of |
| 4640 |
-- the instnace. Gen_Rep is the representation of the generic. In_State |
| 4641 |
-- is the current state of the Processing phase. |
| 4642 |
|
| 4643 |
procedure Process_Conditional_ABE_Instantiation_SPARK |
| 4644 |
(Inst : Node_Id; |
| 4645 |
Inst_Rep : Scenario_Rep_Id; |
| 4646 |
Gen_Id : Entity_Id; |
| 4647 |
Gen_Rep : Target_Rep_Id; |
| 4648 |
In_State : Processing_In_State); |
| 4649 |
pragma Inline (Process_Conditional_ABE_Instantiation_SPARK); |
| 4650 |
-- Perform ABE checks and diagnostics for instantiation Inst of generic |
| 4651 |
-- Gen_Id using the SPARK rules. Inst_Rep denotes the representation of |
| 4652 |
-- the instnace. Gen_Rep is the representation of the generic. In_State |
| 4653 |
-- is the current state of the Processing phase. |
| 4654 |
|
| 4655 |
procedure Process_Conditional_ABE_Variable_Assignment |
| 4656 |
(Asmt : Node_Id; |
| 4657 |
Asmt_Rep : Scenario_Rep_Id; |
| 4658 |
In_State : Processing_In_State); |
| 4659 |
pragma Inline (Process_Conditional_ABE_Variable_Assignment); |
| 4660 |
-- Top-level dispatcher for processing of variable assignments. Perform |
| 4661 |
-- ABE checks and diagnostics for assignment Asmt with representation |
| 4662 |
-- Asmt_Rep. In_State denotes the current state of the Processing phase. |
| 4663 |
|
| 4664 |
procedure Process_Conditional_ABE_Variable_Assignment_Ada |
| 4665 |
(Asmt : Node_Id; |
| 4666 |
Asmt_Rep : Scenario_Rep_Id; |
| 4667 |
Var_Id : Entity_Id; |
| 4668 |
Var_Rep : Target_Rep_Id; |
| 4669 |
In_State : Processing_In_State); |
| 4670 |
pragma Inline (Process_Conditional_ABE_Variable_Assignment_Ada); |
| 4671 |
-- Perform ABE checks and diagnostics for assignment statement Asmt that |
| 4672 |
-- modifies the value of variable Var_Id using the Ada rules. Asmt_Rep |
| 4673 |
-- denotes the representation of the assignment. Var_Rep denotes the |
| 4674 |
-- representation of the variable. In_State is the current state of the |
| 4675 |
-- Processing phase. |
| 4676 |
|
| 4677 |
procedure Process_Conditional_ABE_Variable_Assignment_SPARK |
| 4678 |
(Asmt : Node_Id; |
| 4679 |
Asmt_Rep : Scenario_Rep_Id; |
| 4680 |
Var_Id : Entity_Id; |
| 4681 |
Var_Rep : Target_Rep_Id; |
| 4682 |
In_State : Processing_In_State); |
| 4683 |
pragma Inline (Process_Conditional_ABE_Variable_Assignment_SPARK); |
| 4684 |
-- Perform ABE checks and diagnostics for assignment statement Asmt that |
| 4685 |
-- modifies the value of variable Var_Id using the SPARK rules. Asmt_Rep |
| 4686 |
-- denotes the representation of the assignment. Var_Rep denotes the |
| 4687 |
-- representation of the variable. In_State is the current state of the |
| 4688 |
-- Processing phase. |
| 4689 |
|
| 4690 |
procedure Process_Conditional_ABE_Variable_Reference |
| 4691 |
(Ref : Node_Id; |
| 4692 |
Ref_Rep : Scenario_Rep_Id; |
| 4693 |
In_State : Processing_In_State); |
| 4694 |
pragma Inline (Process_Conditional_ABE_Variable_Reference); |
| 4695 |
-- Perform ABE checks and diagnostics for variable reference Ref with |
| 4696 |
-- representation Ref_Rep. In_State denotes the current state of the |
| 4697 |
-- Processing phase. |
| 4698 |
|
| 4699 |
procedure Traverse_Conditional_ABE_Body |
| 4700 |
(N : Node_Id; |
| 4701 |
In_State : Processing_In_State); |
| 4702 |
pragma Inline (Traverse_Conditional_ABE_Body); |
| 4703 |
-- Traverse subprogram body N looking for suitable scenarios that need |
| 4704 |
-- to be processed for conditional ABE checks and diagnostics. In_State |
| 4705 |
-- is the current state of the Processing phase. |
| 4706 |
|
| 4707 |
------------------------------------- |
| 4708 |
-- Check_Conditional_ABE_Scenarios -- |
| 4709 |
------------------------------------- |
| 4710 |
|
| 4711 |
procedure Check_Conditional_ABE_Scenarios |
| 4712 |
(Iter : in out NE_Set.Iterator) |
| 4713 |
is |
| 4714 |
N : Node_Id; |
| 4715 |
|
| 4716 |
begin |
| 4717 |
while NE_Set.Has_Next (Iter) loop |
| 4718 |
NE_Set.Next (Iter, N); |
| 4719 |
|
| 4720 |
-- Reset the traversed status of all subprogram bodies because the |
| 4721 |
-- current conditional scenario acts as a new DFS traversal root. |
| 4722 |
|
| 4723 |
Reset_Traversed_Bodies; |
| 4724 |
|
| 4725 |
Process_Conditional_ABE |
| 4726 |
(N => N, |
| 4727 |
In_State => Conditional_ABE_State); |
| 4728 |
end loop; |
| 4729 |
end Check_Conditional_ABE_Scenarios; |
| 4730 |
|
| 4731 |
--------------------------------- |
| 4732 |
-- Is_Conditional_ABE_Scenario -- |
| 4733 |
--------------------------------- |
| 4734 |
|
| 4735 |
function Is_Conditional_ABE_Scenario (N : Node_Id) return Boolean is |
| 4736 |
begin |
| 4737 |
return |
| 4738 |
Is_Suitable_Access_Taken (N) |
| 4739 |
or else Is_Suitable_Call (N) |
| 4740 |
or else Is_Suitable_Instantiation (N) |
| 4741 |
or else Is_Suitable_Variable_Assignment (N) |
| 4742 |
or else Is_Suitable_Variable_Reference (N); |
| 4743 |
end Is_Conditional_ABE_Scenario; |
| 4744 |
|
| 4745 |
----------------------------- |
| 4746 |
-- Process_Conditional_ABE -- |
| 4747 |
----------------------------- |
| 4748 |
|
| 4749 |
procedure Process_Conditional_ABE |
| 4750 |
(N : Node_Id; |
| 4751 |
In_State : Processing_In_State) |
| 4752 |
is |
| 4753 |
Scen : constant Node_Id := Scenario (N); |
| 4754 |
Scen_Rep : Scenario_Rep_Id; |
| 4755 |
|
| 4756 |
begin |
| 4757 |
-- Add the current scenario to the stack of active scenarios |
| 4758 |
|
| 4759 |
Push_Active_Scenario (Scen); |
| 4760 |
|
| 4761 |
-- 'Access |
| 4762 |
|
| 4763 |
if Is_Suitable_Access_Taken (Scen) then |
| 4764 |
Process_Conditional_ABE_Access_Taken |
| 4765 |
(Attr => Scen, |
| 4766 |
Attr_Rep => Scenario_Representation_Of (Scen, In_State), |
| 4767 |
In_State => In_State); |
| 4768 |
|
| 4769 |
-- Call or task activation |
| 4770 |
|
| 4771 |
elsif Is_Suitable_Call (Scen) then |
| 4772 |
Scen_Rep := Scenario_Representation_Of (Scen, In_State); |
| 4773 |
|
| 4774 |
-- Routine Build_Call_Marker creates call markers regardless of |
| 4775 |
-- whether the call occurs within the main unit or not. This way |
| 4776 |
-- the serialization of internal names is kept consistent. Only |
| 4777 |
-- call markers found within the main unit must be processed. |
| 4778 |
|
| 4779 |
if In_Main_Context (Scen) then |
| 4780 |
Scen_Rep := Scenario_Representation_Of (Scen, In_State); |
| 4781 |
|
| 4782 |
if Kind (Scen_Rep) = Call_Scenario then |
| 4783 |
Process_Conditional_ABE_Call |
| 4784 |
(Call => Scen, |
| 4785 |
Call_Rep => Scen_Rep, |
| 4786 |
In_State => In_State); |
| 4787 |
|
| 4788 |
else |
| 4789 |
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario); |
| 4790 |
|
| 4791 |
Process_Activation |
| 4792 |
(Call => Scen, |
| 4793 |
Call_Rep => Scen_Rep, |
| 4794 |
Processor => Process_Conditional_ABE_Activation'Access, |
| 4795 |
In_State => In_State); |
| 4796 |
end if; |
| 4797 |
end if; |
| 4798 |
|
| 4799 |
-- Instantiation |
| 4800 |
|
| 4801 |
elsif Is_Suitable_Instantiation (Scen) then |
| 4802 |
Process_Conditional_ABE_Instantiation |
| 4803 |
(Inst => Scen, |
| 4804 |
Inst_Rep => Scenario_Representation_Of (Scen, In_State), |
| 4805 |
In_State => In_State); |
| 4806 |
|
| 4807 |
-- Variable assignments |
| 4808 |
|
| 4809 |
elsif Is_Suitable_Variable_Assignment (Scen) then |
| 4810 |
Process_Conditional_ABE_Variable_Assignment |
| 4811 |
(Asmt => Scen, |
| 4812 |
Asmt_Rep => Scenario_Representation_Of (Scen, In_State), |
| 4813 |
In_State => In_State); |
| 4814 |
|
| 4815 |
-- Variable references |
| 4816 |
|
| 4817 |
elsif Is_Suitable_Variable_Reference (Scen) then |
| 4818 |
|
| 4819 |
-- Routine Build_Variable_Reference_Marker makes variable markers |
| 4820 |
-- regardless of whether the reference occurs within the main unit |
| 4821 |
-- or not. This way the serialization of internal names is kept |
| 4822 |
-- consistent. Only variable markers within the main unit must be |
| 4823 |
-- processed. |
| 4824 |
|
| 4825 |
if In_Main_Context (Scen) then |
| 4826 |
Process_Conditional_ABE_Variable_Reference |
| 4827 |
(Ref => Scen, |
| 4828 |
Ref_Rep => Scenario_Representation_Of (Scen, In_State), |
| 4829 |
In_State => In_State); |
| 4830 |
end if; |
| 4831 |
end if; |
| 4832 |
|
| 4833 |
-- Remove the current scenario from the stack of active scenarios |
| 4834 |
-- once all ABE diagnostics and checks have been performed. |
| 4835 |
|
| 4836 |
Pop_Active_Scenario (Scen); |
| 4837 |
end Process_Conditional_ABE; |
| 4838 |
|
| 4839 |
------------------------------------------ |
| 4840 |
-- Process_Conditional_ABE_Access_Taken -- |
| 4841 |
------------------------------------------ |
| 4842 |
|
| 4843 |
procedure Process_Conditional_ABE_Access_Taken |
| 4844 |
(Attr : Node_Id; |
| 4845 |
Attr_Rep : Scenario_Rep_Id; |
| 4846 |
In_State : Processing_In_State) |
| 4847 |
is |
| 4848 |
function Build_Access_Marker (Subp_Id : Entity_Id) return Node_Id; |
| 4849 |
pragma Inline (Build_Access_Marker); |
| 4850 |
-- Create a suitable call marker which invokes subprogram Subp_Id |
| 4851 |
|
| 4852 |
------------------------- |
| 4853 |
-- Build_Access_Marker -- |
| 4854 |
------------------------- |
| 4855 |
|
| 4856 |
function Build_Access_Marker (Subp_Id : Entity_Id) return Node_Id is |
| 4857 |
Marker : Node_Id; |
| 4858 |
|
| 4859 |
begin |
| 4860 |
Marker := Make_Call_Marker (Sloc (Attr)); |
| 4861 |
|
| 4862 |
-- Inherit relevant attributes from the attribute |
| 4863 |
|
| 4864 |
Set_Target (Marker, Subp_Id); |
| 4865 |
Set_Is_Declaration_Level_Node |
| 4866 |
(Marker, Level (Attr_Rep) = Declaration_Level); |
| 4867 |
Set_Is_Dispatching_Call |
| 4868 |
(Marker, False); |
| 4869 |
Set_Is_Elaboration_Checks_OK_Node |
| 4870 |
(Marker, Elaboration_Checks_OK (Attr_Rep)); |
| 4871 |
Set_Is_Elaboration_Warnings_OK_Node |
| 4872 |
(Marker, Elaboration_Warnings_OK (Attr_Rep)); |
| 4873 |
Set_Is_Preelaborable_Call |
| 4874 |
(Marker, False); |
| 4875 |
Set_Is_Source_Call |
| 4876 |
(Marker, Comes_From_Source (Attr)); |
| 4877 |
Set_Is_SPARK_Mode_On_Node |
| 4878 |
(Marker, SPARK_Mode_Of (Attr_Rep) = Is_On); |
| 4879 |
|
| 4880 |
-- Partially insert the call marker into the tree by setting its |
| 4881 |
-- parent pointer. |
| 4882 |
|
| 4883 |
Set_Parent (Marker, Attr); |
| 4884 |
|
| 4885 |
return Marker; |
| 4886 |
end Build_Access_Marker; |
| 4887 |
|
| 4888 |
-- Local variables |
| 4889 |
|
| 4890 |
Root : constant Node_Id := Root_Scenario; |
| 4891 |
Subp_Id : constant Entity_Id := Target (Attr_Rep); |
| 4892 |
Subp_Rep : constant Target_Rep_Id := |
| 4893 |
Target_Representation_Of (Subp_Id, In_State); |
| 4894 |
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep); |
| 4895 |
|
| 4896 |
New_In_State : Processing_In_State := In_State; |
| 4897 |
-- Each step of the Processing phase constitutes a new state |
| 4898 |
|
| 4899 |
-- Start of processing for Process_Conditional_ABE_Access |
| 4900 |
|
| 4901 |
begin |
| 4902 |
-- Output relevant information when switch -gnatel (info messages on |
| 4903 |
-- implicit Elaborate[_All] pragmas) is in effect. |
| 4904 |
|
| 4905 |
if Elab_Info_Messages |
| 4906 |
and then not New_In_State.Suppress_Info_Messages |
| 4907 |
then |
| 4908 |
Error_Msg_NE |
| 4909 |
("info: access to & during elaboration?$?", Attr, Subp_Id); |
| 4910 |
end if; |
| 4911 |
|
| 4912 |
-- Warnings are suppressed when a prior scenario is already in that |
| 4913 |
-- mode or when the attribute or the target have warnings suppressed. |
| 4914 |
-- Update the state of the Processing phase to reflect this. |
| 4915 |
|
| 4916 |
New_In_State.Suppress_Warnings := |
| 4917 |
New_In_State.Suppress_Warnings |
| 4918 |
or else not Elaboration_Warnings_OK (Attr_Rep) |
| 4919 |
or else not Elaboration_Warnings_OK (Subp_Rep); |
| 4920 |
|
| 4921 |
-- Do not emit any ABE diagnostics when the current or previous |
| 4922 |
-- scenario in this traversal has suppressed elaboration warnings. |
| 4923 |
|
| 4924 |
if New_In_State.Suppress_Warnings then |
| 4925 |
null; |
| 4926 |
|
| 4927 |
-- Both the attribute and the corresponding subprogram body are in |
| 4928 |
-- the same unit. The body must appear prior to the root scenario |
| 4929 |
-- which started the recursive search. If this is not the case, then |
| 4930 |
-- there is a potential ABE if the access value is used to call the |
| 4931 |
-- subprogram. Emit a warning only when switch -gnatw.f (warnings on |
| 4932 |
-- suspicious 'Access) is in effect. |
| 4933 |
|
| 4934 |
elsif Warn_On_Elab_Access |
| 4935 |
and then Present (Body_Decl) |
| 4936 |
and then In_Extended_Main_Code_Unit (Body_Decl) |
| 4937 |
and then Earlier_In_Extended_Unit (Root, Body_Decl) |
| 4938 |
then |
| 4939 |
Error_Msg_Name_1 := Attribute_Name (Attr); |
| 4940 |
Error_Msg_NE |
| 4941 |
("?.f?% attribute of & before body seen", Attr, Subp_Id); |
| 4942 |
Error_Msg_N ("\possible Program_Error on later references", Attr); |
| 4943 |
|
| 4944 |
Output_Active_Scenarios (Attr, New_In_State); |
| 4945 |
end if; |
| 4946 |
|
| 4947 |
-- Treat the attribute an immediate invocation of the target when |
| 4948 |
-- switch -gnatd.o (conservative elaboration order for indirect |
| 4949 |
-- calls) is in effect. This has the following desirable effects: |
| 4950 |
-- |
| 4951 |
-- * Ensure that the unit with the corresponding body is elaborated |
| 4952 |
-- prior to the main unit. |
| 4953 |
-- |
| 4954 |
-- * Perform conditional ABE checks and diagnostics |
| 4955 |
-- |
| 4956 |
-- * Traverse the body of the target (if available) |
| 4957 |
|
| 4958 |
if Debug_Flag_Dot_O then |
| 4959 |
Process_Conditional_ABE |
| 4960 |
(N => Build_Access_Marker (Subp_Id), |
| 4961 |
In_State => New_In_State); |
| 4962 |
|
| 4963 |
-- Otherwise ensure that the unit with the corresponding body is |
| 4964 |
-- elaborated prior to the main unit. |
| 4965 |
|
| 4966 |
else |
| 4967 |
Ensure_Prior_Elaboration |
| 4968 |
(N => Attr, |
| 4969 |
Unit_Id => Unit (Subp_Rep), |
| 4970 |
Prag_Nam => Name_Elaborate_All, |
| 4971 |
In_State => New_In_State); |
| 4972 |
end if; |
| 4973 |
end Process_Conditional_ABE_Access_Taken; |
| 4974 |
|
| 4975 |
---------------------------------------- |
| 4976 |
-- Process_Conditional_ABE_Activation -- |
| 4977 |
---------------------------------------- |
| 4978 |
|
| 4979 |
procedure Process_Conditional_ABE_Activation |
| 4980 |
(Call : Node_Id; |
| 4981 |
Call_Rep : Scenario_Rep_Id; |
| 4982 |
Obj_Id : Entity_Id; |
| 4983 |
Obj_Rep : Target_Rep_Id; |
| 4984 |
Task_Typ : Entity_Id; |
| 4985 |
Task_Rep : Target_Rep_Id; |
| 4986 |
In_State : Processing_In_State) |
| 4987 |
is |
| 4988 |
pragma Unreferenced (Task_Typ); |
| 4989 |
|
| 4990 |
Body_Decl : constant Node_Id := Body_Declaration (Task_Rep); |
| 4991 |
Spec_Decl : constant Node_Id := Spec_Declaration (Task_Rep); |
| 4992 |
Root : constant Node_Id := Root_Scenario; |
| 4993 |
Unit_Id : constant Node_Id := Unit (Task_Rep); |
| 4994 |
|
| 4995 |
Check_OK : constant Boolean := |
| 4996 |
not In_State.Suppress_Checks |
| 4997 |
and then Ghost_Mode_Of (Obj_Rep) /= Is_Ignored |
| 4998 |
and then Ghost_Mode_Of (Task_Rep) /= Is_Ignored |
| 4999 |
and then Elaboration_Checks_OK (Obj_Rep) |
| 5000 |
and then Elaboration_Checks_OK (Task_Rep); |
| 5001 |
-- A run-time ABE check may be installed only when the object and the |
| 5002 |
-- task type have active elaboration checks, and both are not ignored |
| 5003 |
-- Ghost constructs. |
| 5004 |
|
| 5005 |
New_In_State : Processing_In_State := In_State; |
| 5006 |
-- Each step of the Processing phase constitutes a new state |
| 5007 |
|
| 5008 |
begin |
| 5009 |
-- Output relevant information when switch -gnatel (info messages on |
| 5010 |
-- implicit Elaborate[_All] pragmas) is in effect. |
| 5011 |
|
| 5012 |
if Elab_Info_Messages |
| 5013 |
and then not New_In_State.Suppress_Info_Messages |
| 5014 |
then |
| 5015 |
Error_Msg_NE |
| 5016 |
("info: activation of & during elaboration?$?", Call, Obj_Id); |
| 5017 |
end if; |
| 5018 |
|
| 5019 |
-- Nothing to do when the call activates a task whose type is defined |
| 5020 |
-- within an instance and switch -gnatd_i (ignore activations and |
| 5021 |
-- calls to instances for elaboration) is in effect. |
| 5022 |
|
| 5023 |
if Debug_Flag_Underscore_I |
| 5024 |
and then In_External_Instance |
| 5025 |
(N => Call, |
| 5026 |
Target_Decl => Spec_Decl) |
| 5027 |
then |
| 5028 |
return; |
| 5029 |
|
| 5030 |
-- Nothing to do when the activation is a guaranteed ABE |
| 5031 |
|
| 5032 |
elsif Is_Known_Guaranteed_ABE (Call) then |
| 5033 |
return; |
| 5034 |
|
| 5035 |
-- Nothing to do when the root scenario appears at the declaration |
| 5036 |
-- level and the task is in the same unit, but outside this context. |
| 5037 |
-- |
| 5038 |
-- task type Task_Typ; -- task declaration |
| 5039 |
-- |
| 5040 |
-- procedure Proc is |
| 5041 |
-- function A ... is |
| 5042 |
-- begin |
| 5043 |
-- if Some_Condition then |
| 5044 |
-- declare |
| 5045 |
-- T : Task_Typ; |
| 5046 |
-- begin |
| 5047 |
-- <activation call> -- activation site |
| 5048 |
-- end; |
| 5049 |
-- ... |
| 5050 |
-- end A; |
| 5051 |
-- |
| 5052 |
-- X : ... := A; -- root scenario |
| 5053 |
-- ... |
| 5054 |
-- |
| 5055 |
-- task body Task_Typ is |
| 5056 |
-- ... |
| 5057 |
-- end Task_Typ; |
| 5058 |
-- |
| 5059 |
-- In the example above, the context of X is the declarative list of |
| 5060 |
-- Proc. The "elaboration" of X may reach the activation of T whose |
| 5061 |
-- body is defined outside of X's context. The task body is relevant |
| 5062 |
-- only when Proc is invoked, but this happens only during "normal" |
| 5063 |
-- elaboration, therefore the task body must not be considered if |
| 5064 |
-- this is not the case. |
| 5065 |
|
| 5066 |
elsif Is_Up_Level_Target |
| 5067 |
(Targ_Decl => Spec_Decl, |
| 5068 |
In_State => New_In_State) |
| 5069 |
then |
| 5070 |
return; |
| 5071 |
|
| 5072 |
-- Nothing to do when the activation is ABE-safe |
| 5073 |
-- |
| 5074 |
-- generic |
| 5075 |
-- package Gen is |
| 5076 |
-- task type Task_Typ; |
| 5077 |
-- end Gen; |
| 5078 |
-- |
| 5079 |
-- package body Gen is |
| 5080 |
-- task body Task_Typ is |
| 5081 |
-- begin |
| 5082 |
-- ... |
| 5083 |
-- end Task_Typ; |
| 5084 |
-- end Gen; |
| 5085 |
-- |
| 5086 |
-- with Gen; |
| 5087 |
-- procedure Main is |
| 5088 |
-- package Nested is |
| 5089 |
-- package Inst is new Gen; |
| 5090 |
-- T : Inst.Task_Typ; |
| 5091 |
-- <activation call> -- safe activation |
| 5092 |
-- end Nested; |
| 5093 |
-- ... |
| 5094 |
|
| 5095 |
elsif Is_Safe_Activation (Call, Task_Rep) then |
| 5096 |
|
| 5097 |
-- Note that the task body must still be examined for any nested |
| 5098 |
-- scenarios. |
| 5099 |
|
| 5100 |
null; |
| 5101 |
|
| 5102 |
-- The activation call and the task body are both in the main unit |
| 5103 |
-- |
| 5104 |
-- If the root scenario appears prior to the task body, then this is |
| 5105 |
-- a possible ABE with respect to the root scenario. |
| 5106 |
-- |
| 5107 |
-- task type Task_Typ; |
| 5108 |
-- |
| 5109 |
-- function A ... is |
| 5110 |
-- begin |
| 5111 |
-- if Some_Condition then |
| 5112 |
-- declare |
| 5113 |
-- package Pack is |
| 5114 |
-- T : Task_Typ; |
| 5115 |
-- end Pack; -- activation of T |
| 5116 |
-- ... |
| 5117 |
-- end A; |
| 5118 |
-- |
| 5119 |
-- X : ... := A; -- root scenario |
| 5120 |
-- |
| 5121 |
-- task body Task_Typ is -- task body |
| 5122 |
-- ... |
| 5123 |
-- end Task_Typ; |
| 5124 |
-- |
| 5125 |
-- Y : ... := A; -- root scenario |
| 5126 |
-- |
| 5127 |
-- IMPORTANT: The activation of T is a possible ABE for X, but |
| 5128 |
-- not for Y. Intalling an unconditional ABE raise prior to the |
| 5129 |
-- activation call would be wrong as it will fail for Y as well |
| 5130 |
-- but in Y's case the activation of T is never an ABE. |
| 5131 |
|
| 5132 |
elsif Present (Body_Decl) |
| 5133 |
and then In_Extended_Main_Code_Unit (Body_Decl) |
| 5134 |
then |
| 5135 |
if Earlier_In_Extended_Unit (Root, Body_Decl) then |
| 5136 |
|
| 5137 |
-- Do not emit any ABE diagnostics when a previous scenario in |
| 5138 |
-- this traversal has suppressed elaboration warnings. |
| 5139 |
|
| 5140 |
if New_In_State.Suppress_Warnings then |
| 5141 |
null; |
| 5142 |
|
| 5143 |
-- Do not emit any ABE diagnostics when the activation occurs |
| 5144 |
-- in a partial finalization context because this action leads |
| 5145 |
-- to confusing noise. |
| 5146 |
|
| 5147 |
elsif New_In_State.Within_Partial_Finalization then |
| 5148 |
null; |
| 5149 |
|
| 5150 |
-- Otherwise emit the ABE disgnostic |
| 5151 |
|
| 5152 |
else |
| 5153 |
Error_Msg_Sloc := Sloc (Call); |
| 5154 |
Error_Msg_N |
| 5155 |
("??task & will be activated # before elaboration of its " |
| 5156 |
& "body", Obj_Id); |
| 5157 |
Error_Msg_N |
| 5158 |
("\Program_Error may be raised at run time", Obj_Id); |
| 5159 |
|
| 5160 |
Output_Active_Scenarios (Obj_Id, New_In_State); |
| 5161 |
end if; |
| 5162 |
|
| 5163 |
-- Install a conditional run-time ABE check to verify that the |
| 5164 |
-- task body has been elaborated prior to the activation call. |
| 5165 |
|
| 5166 |
if Check_OK then |
| 5167 |
Install_Scenario_ABE_Check |
| 5168 |
(N => Call, |
| 5169 |
Targ_Id => Defining_Entity (Spec_Decl), |
| 5170 |
Targ_Rep => Task_Rep, |
| 5171 |
Disable => Obj_Rep); |
| 5172 |
|
| 5173 |
-- Update the state of the Processing phase to indicate that |
| 5174 |
-- no implicit Elaborate[_All] pragma must be generated from |
| 5175 |
-- this point on. |
| 5176 |
-- |
| 5177 |
-- task type Task_Typ; |
| 5178 |
-- |
| 5179 |
-- function A ... is |
| 5180 |
-- begin |
| 5181 |
-- if Some_Condition then |
| 5182 |
-- declare |
| 5183 |
-- package Pack is |
| 5184 |
-- <ABE check> |
| 5185 |
-- T : Task_Typ; |
| 5186 |
-- end Pack; -- activation of T |
| 5187 |
-- ... |
| 5188 |
-- end A; |
| 5189 |
-- |
| 5190 |
-- X : ... := A; |
| 5191 |
-- |
| 5192 |
-- task body Task_Typ is |
| 5193 |
-- begin |
| 5194 |
-- External.Subp; -- imparts Elaborate_All |
| 5195 |
-- end Task_Typ; |
| 5196 |
-- |
| 5197 |
-- If Some_Condition is True, then the ABE check will fail |
| 5198 |
-- at runtime and the call to External.Subp will never take |
| 5199 |
-- place, rendering the implicit Elaborate_All useless. |
| 5200 |
-- |
| 5201 |
-- If the value of Some_Condition is False, then the call |
| 5202 |
-- to External.Subp will never take place, rendering the |
| 5203 |
-- implicit Elaborate_All useless. |
| 5204 |
|
| 5205 |
New_In_State.Suppress_Implicit_Pragmas := True; |
| 5206 |
end if; |
| 5207 |
end if; |
| 5208 |
|
| 5209 |
-- Otherwise the task body is not available in this compilation or |
| 5210 |
-- it resides in an external unit. Install a run-time ABE check to |
| 5211 |
-- verify that the task body has been elaborated prior to the |
| 5212 |
-- activation call when the dynamic model is in effect. |
| 5213 |
|
| 5214 |
elsif Check_OK |
| 5215 |
and then New_In_State.Processing = Dynamic_Model_Processing |
| 5216 |
then |
| 5217 |
Install_Unit_ABE_Check |
| 5218 |
(N => Call, |
| 5219 |
Unit_Id => Unit_Id, |
| 5220 |
Disable => Obj_Rep); |
| 5221 |
end if; |
| 5222 |
|
| 5223 |
-- Both the activation call and task type are subject to SPARK_Mode |
| 5224 |
-- On, this triggers the SPARK rules for task activation. Compared |
| 5225 |
-- to calls and instantiations, task activation in SPARK does not |
| 5226 |
-- require the presence of Elaborate[_All] pragmas in case the task |
| 5227 |
-- type is defined outside the main unit. This is because SPARK uses |
| 5228 |
-- a special policy which activates all tasks after the main unit has |
| 5229 |
-- finished its elaboration. |
| 5230 |
|
| 5231 |
if SPARK_Mode_Of (Call_Rep) = Is_On |
| 5232 |
and then SPARK_Mode_Of (Task_Rep) = Is_On |
| 5233 |
then |
| 5234 |
null; |
| 5235 |
|
| 5236 |
-- Otherwise the Ada rules are in effect. Ensure that the unit with |
| 5237 |
-- the task body is elaborated prior to the main unit. |
| 5238 |
|
| 5239 |
else |
| 5240 |
Ensure_Prior_Elaboration |
| 5241 |
(N => Call, |
| 5242 |
Unit_Id => Unit_Id, |
| 5243 |
Prag_Nam => Name_Elaborate_All, |
| 5244 |
In_State => New_In_State); |
| 5245 |
end if; |
| 5246 |
|
| 5247 |
Traverse_Conditional_ABE_Body |
| 5248 |
(N => Body_Decl, |
| 5249 |
In_State => New_In_State); |
| 5250 |
end Process_Conditional_ABE_Activation; |
| 5251 |
|
| 5252 |
---------------------------------- |
| 5253 |
-- Process_Conditional_ABE_Call -- |
| 5254 |
---------------------------------- |
| 5255 |
|
| 5256 |
procedure Process_Conditional_ABE_Call |
| 5257 |
(Call : Node_Id; |
| 5258 |
Call_Rep : Scenario_Rep_Id; |
| 5259 |
In_State : Processing_In_State) |
| 5260 |
is |
| 5261 |
function In_Initialization_Context (N : Node_Id) return Boolean; |
| 5262 |
pragma Inline (In_Initialization_Context); |
| 5263 |
-- Determine whether arbitrary node N appears within a type init |
| 5264 |
-- proc, primitive [Deep_]Initialize, or a block created for |
| 5265 |
-- initialization purposes. |
| 5266 |
|
| 5267 |
function Is_Partial_Finalization_Proc |
| 5268 |
(Subp_Id : Entity_Id) return Boolean; |
| 5269 |
pragma Inline (Is_Partial_Finalization_Proc); |
| 5270 |
-- Determine whether subprogram Subp_Id is a partial finalization |
| 5271 |
-- procedure. |
| 5272 |
|
| 5273 |
------------------------------- |
| 5274 |
-- In_Initialization_Context -- |
| 5275 |
------------------------------- |
| 5276 |
|
| 5277 |
function In_Initialization_Context (N : Node_Id) return Boolean is |
| 5278 |
Par : Node_Id; |
| 5279 |
Spec_Id : Entity_Id; |
| 5280 |
|
| 5281 |
begin |
| 5282 |
-- Climb the parent chain looking for initialization actions |
| 5283 |
|
| 5284 |
Par := Parent (N); |
| 5285 |
while Present (Par) loop |
| 5286 |
|
| 5287 |
-- A block may be part of the initialization actions of a |
| 5288 |
-- default initialized object. |
| 5289 |
|
| 5290 |
if Nkind (Par) = N_Block_Statement |
| 5291 |
and then Is_Initialization_Block (Par) |
| 5292 |
then |
| 5293 |
return True; |
| 5294 |
|
| 5295 |
-- A subprogram body may denote an initialization routine |
| 5296 |
|
| 5297 |
elsif Nkind (Par) = N_Subprogram_Body then |
| 5298 |
Spec_Id := Unique_Defining_Entity (Par); |
| 5299 |
|
| 5300 |
-- The current subprogram body denotes a type init proc or |
| 5301 |
-- primitive [Deep_]Initialize. |
| 5302 |
|
| 5303 |
if Is_Init_Proc (Spec_Id) |
| 5304 |
or else Is_Controlled_Procedure (Spec_Id, Name_Initialize) |
| 5305 |
or else Is_TSS (Spec_Id, TSS_Deep_Initialize) |
| 5306 |
then |
| 5307 |
return True; |
| 5308 |
end if; |
| 5309 |
|
| 5310 |
-- Prevent the search from going too far |
| 5311 |
|
| 5312 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 5313 |
exit; |
| 5314 |
end if; |
| 5315 |
|
| 5316 |
Par := Parent (Par); |
| 5317 |
end loop; |
| 5318 |
|
| 5319 |
return False; |
| 5320 |
end In_Initialization_Context; |
| 5321 |
|
| 5322 |
---------------------------------- |
| 5323 |
-- Is_Partial_Finalization_Proc -- |
| 5324 |
---------------------------------- |
| 5325 |
|
| 5326 |
function Is_Partial_Finalization_Proc |
| 5327 |
(Subp_Id : Entity_Id) return Boolean |
| 5328 |
is |
| 5329 |
begin |
| 5330 |
-- To qualify, the subprogram must denote a finalizer procedure |
| 5331 |
-- or primitive [Deep_]Finalize, and the call must appear within |
| 5332 |
-- an initialization context. |
| 5333 |
|
| 5334 |
return |
| 5335 |
(Is_Controlled_Procedure (Subp_Id, Name_Finalize) |
| 5336 |
or else Is_Finalizer (Subp_Id) |
| 5337 |
or else Is_TSS (Subp_Id, TSS_Deep_Finalize)) |
| 5338 |
and then In_Initialization_Context (Call); |
| 5339 |
end Is_Partial_Finalization_Proc; |
| 5340 |
|
| 5341 |
-- Local variables |
| 5342 |
|
| 5343 |
Subp_Id : constant Entity_Id := Target (Call_Rep); |
| 5344 |
Subp_Rep : constant Target_Rep_Id := |
| 5345 |
Target_Representation_Of (Subp_Id, In_State); |
| 5346 |
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep); |
| 5347 |
Subp_Decl : constant Node_Id := Spec_Declaration (Subp_Rep); |
| 5348 |
|
| 5349 |
SPARK_Rules_On : constant Boolean := |
| 5350 |
SPARK_Mode_Of (Call_Rep) = Is_On |
| 5351 |
and then SPARK_Mode_Of (Subp_Rep) = Is_On; |
| 5352 |
|
| 5353 |
New_In_State : Processing_In_State := In_State; |
| 5354 |
-- Each step of the Processing phase constitutes a new state |
| 5355 |
|
| 5356 |
-- Start of processing for Process_Conditional_ABE_Call |
| 5357 |
|
| 5358 |
begin |
| 5359 |
-- Output relevant information when switch -gnatel (info messages on |
| 5360 |
-- implicit Elaborate[_All] pragmas) is in effect. |
| 5361 |
|
| 5362 |
if Elab_Info_Messages |
| 5363 |
and then not New_In_State.Suppress_Info_Messages |
| 5364 |
then |
| 5365 |
Info_Call |
| 5366 |
(Call => Call, |
| 5367 |
Subp_Id => Subp_Id, |
| 5368 |
Info_Msg => True, |
| 5369 |
In_SPARK => SPARK_Rules_On); |
| 5370 |
end if; |
| 5371 |
|
| 5372 |
-- Check whether the invocation of an entry clashes with an existing |
| 5373 |
-- restriction. This check is relevant only when the processing was |
| 5374 |
-- started from some library-level scenario. |
| 5375 |
|
| 5376 |
if Is_Protected_Entry (Subp_Id) then |
| 5377 |
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call); |
| 5378 |
|
| 5379 |
elsif Is_Task_Entry (Subp_Id) then |
| 5380 |
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, Call); |
| 5381 |
|
| 5382 |
-- Task entry calls are never processed because the entry being |
| 5383 |
-- invoked does not have a corresponding "body", it has a select. |
| 5384 |
|
| 5385 |
return; |
| 5386 |
end if; |
| 5387 |
|
| 5388 |
-- Nothing to do when the call invokes a target defined within an |
| 5389 |
-- instance and switch -gnatd_i (ignore activations and calls to |
| 5390 |
-- instances for elaboration) is in effect. |
| 5391 |
|
| 5392 |
if Debug_Flag_Underscore_I |
| 5393 |
and then In_External_Instance |
| 5394 |
(N => Call, |
| 5395 |
Target_Decl => Subp_Decl) |
| 5396 |
then |
| 5397 |
return; |
| 5398 |
|
| 5399 |
-- Nothing to do when the call is a guaranteed ABE |
| 5400 |
|
| 5401 |
elsif Is_Known_Guaranteed_ABE (Call) then |
| 5402 |
return; |
| 5403 |
|
| 5404 |
-- Nothing to do when the root scenario appears at the declaration |
| 5405 |
-- level and the target is in the same unit but outside this context. |
| 5406 |
-- |
| 5407 |
-- function B ...; -- target declaration |
| 5408 |
-- |
| 5409 |
-- procedure Proc is |
| 5410 |
-- function A ... is |
| 5411 |
-- begin |
| 5412 |
-- if Some_Condition then |
| 5413 |
-- return B; -- call site |
| 5414 |
-- ... |
| 5415 |
-- end A; |
| 5416 |
-- |
| 5417 |
-- X : ... := A; -- root scenario |
| 5418 |
-- ... |
| 5419 |
-- |
| 5420 |
-- function B ... is |
| 5421 |
-- ... |
| 5422 |
-- end B; |
| 5423 |
-- |
| 5424 |
-- In the example above, the context of X is the declarative region |
| 5425 |
-- of Proc. The "elaboration" of X may eventually reach B which is |
| 5426 |
-- defined outside of X's context. B is relevant only when Proc is |
| 5427 |
-- invoked, but this happens only by means of "normal" elaboration, |
| 5428 |
-- therefore B must not be considered if this is not the case. |
| 5429 |
|
| 5430 |
elsif Is_Up_Level_Target |
| 5431 |
(Targ_Decl => Subp_Decl, |
| 5432 |
In_State => New_In_State) |
| 5433 |
then |
| 5434 |
return; |
| 5435 |
end if; |
| 5436 |
|
| 5437 |
-- Warnings are suppressed when a prior scenario is already in that |
| 5438 |
-- mode, or the call or target have warnings suppressed. Update the |
| 5439 |
-- state of the Processing phase to reflect this. |
| 5440 |
|
| 5441 |
New_In_State.Suppress_Warnings := |
| 5442 |
New_In_State.Suppress_Warnings |
| 5443 |
or else not Elaboration_Warnings_OK (Call_Rep) |
| 5444 |
or else not Elaboration_Warnings_OK (Subp_Rep); |
| 5445 |
|
| 5446 |
-- The call occurs in freezing actions context when a prior scenario |
| 5447 |
-- is already in that mode, or when the target is a subprogram whose |
| 5448 |
-- body has been generated as a freezing action. Update the state of |
| 5449 |
-- the Processing phase to reflect this. |
| 5450 |
|
| 5451 |
New_In_State.Within_Freezing_Actions := |
| 5452 |
New_In_State.Within_Freezing_Actions |
| 5453 |
or else (Present (Body_Decl) |
| 5454 |
and then Nkind (Parent (Body_Decl)) = N_Freeze_Entity); |
| 5455 |
|
| 5456 |
-- The call occurs in an initial condition context when a prior |
| 5457 |
-- scenario is already in that mode, or when the target is an |
| 5458 |
-- Initial_Condition procedure. Update the state of the Processing |
| 5459 |
-- phase to reflect this. |
| 5460 |
|
| 5461 |
New_In_State.Within_Initial_Condition := |
| 5462 |
New_In_State.Within_Initial_Condition |
| 5463 |
or else Is_Initial_Condition_Proc (Subp_Id); |
| 5464 |
|
| 5465 |
-- The call occurs in a partial finalization context when a prior |
| 5466 |
-- scenario is already in that mode, or when the target denotes a |
| 5467 |
-- [Deep_]Finalize primitive or a finalizer within an initialization |
| 5468 |
-- context. Update the state of the Processing phase to reflect this. |
| 5469 |
|
| 5470 |
New_In_State.Within_Partial_Finalization := |
| 5471 |
New_In_State.Within_Partial_Finalization |
| 5472 |
or else Is_Partial_Finalization_Proc (Subp_Id); |
| 5473 |
|
| 5474 |
-- The SPARK rules are in effect. Note that -gnatd.v (enforce SPARK |
| 5475 |
-- elaboration rules in SPARK code) is intentionally not taken into |
| 5476 |
-- account here because Process_Conditional_ABE_Call_SPARK has two |
| 5477 |
-- separate modes of operation. |
| 5478 |
|
| 5479 |
if SPARK_Rules_On then |
| 5480 |
Process_Conditional_ABE_Call_SPARK |
| 5481 |
(Call => Call, |
| 5482 |
Call_Rep => Call_Rep, |
| 5483 |
Subp_Id => Subp_Id, |
| 5484 |
Subp_Rep => Subp_Rep, |
| 5485 |
In_State => New_In_State); |
| 5486 |
|
| 5487 |
-- Otherwise the Ada rules are in effect |
| 5488 |
|
| 5489 |
else |
| 5490 |
Process_Conditional_ABE_Call_Ada |
| 5491 |
(Call => Call, |
| 5492 |
Call_Rep => Call_Rep, |
| 5493 |
Subp_Id => Subp_Id, |
| 5494 |
Subp_Rep => Subp_Rep, |
| 5495 |
In_State => New_In_State); |
| 5496 |
end if; |
| 5497 |
|
| 5498 |
-- Inspect the target body (and barried function) for other suitable |
| 5499 |
-- elaboration scenarios. |
| 5500 |
|
| 5501 |
Traverse_Conditional_ABE_Body |
| 5502 |
(N => Barrier_Body_Declaration (Subp_Rep), |
| 5503 |
In_State => New_In_State); |
| 5504 |
|
| 5505 |
Traverse_Conditional_ABE_Body |
| 5506 |
(N => Body_Decl, |
| 5507 |
In_State => New_In_State); |
| 5508 |
end Process_Conditional_ABE_Call; |
| 5509 |
|
| 5510 |
-------------------------------------- |
| 5511 |
-- Process_Conditional_ABE_Call_Ada -- |
| 5512 |
-------------------------------------- |
| 5513 |
|
| 5514 |
procedure Process_Conditional_ABE_Call_Ada |
| 5515 |
(Call : Node_Id; |
| 5516 |
Call_Rep : Scenario_Rep_Id; |
| 5517 |
Subp_Id : Entity_Id; |
| 5518 |
Subp_Rep : Target_Rep_Id; |
| 5519 |
In_State : Processing_In_State) |
| 5520 |
is |
| 5521 |
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep); |
| 5522 |
Root : constant Node_Id := Root_Scenario; |
| 5523 |
Unit_Id : constant Node_Id := Unit (Subp_Rep); |
| 5524 |
|
| 5525 |
Check_OK : constant Boolean := |
| 5526 |
not In_State.Suppress_Checks |
| 5527 |
and then Ghost_Mode_Of (Call_Rep) /= Is_Ignored |
| 5528 |
and then Ghost_Mode_Of (Subp_Rep) /= Is_Ignored |
| 5529 |
and then Elaboration_Checks_OK (Call_Rep) |
| 5530 |
and then Elaboration_Checks_OK (Subp_Rep); |
| 5531 |
-- A run-time ABE check may be installed only when both the call |
| 5532 |
-- and the target have active elaboration checks, and both are not |
| 5533 |
-- ignored Ghost constructs. |
| 5534 |
|
| 5535 |
New_In_State : Processing_In_State := In_State; |
| 5536 |
-- Each step of the Processing phase constitutes a new state |
| 5537 |
|
| 5538 |
begin |
| 5539 |
-- Nothing to do for an Ada dispatching call because there are no |
| 5540 |
-- ABE diagnostics for either models. ABE checks for the dynamic |
| 5541 |
-- model are handled by Install_Primitive_Elaboration_Check. |
| 5542 |
|
| 5543 |
if Is_Dispatching_Call (Call_Rep) then |
| 5544 |
return; |
| 5545 |
|
| 5546 |
-- Nothing to do when the call is ABE-safe |
| 5547 |
-- |
| 5548 |
-- generic |
| 5549 |
-- function Gen ...; |
| 5550 |
-- |
| 5551 |
-- function Gen ... is |
| 5552 |
-- begin |
| 5553 |
-- ... |
| 5554 |
-- end Gen; |
| 5555 |
-- |
| 5556 |
-- with Gen; |
| 5557 |
-- procedure Main is |
| 5558 |
-- function Inst is new Gen; |
| 5559 |
-- X : ... := Inst; -- safe call |
| 5560 |
-- ... |
| 5561 |
|
| 5562 |
elsif Is_Safe_Call (Call, Subp_Id, Subp_Rep) then |
| 5563 |
return; |
| 5564 |
|
| 5565 |
-- The call and the target body are both in the main unit |
| 5566 |
-- |
| 5567 |
-- If the root scenario appears prior to the target body, then this |
| 5568 |
-- is a possible ABE with respect to the root scenario. |
| 5569 |
-- |
| 5570 |
-- function B ...; |
| 5571 |
-- |
| 5572 |
-- function A ... is |
| 5573 |
-- begin |
| 5574 |
-- if Some_Condition then |
| 5575 |
-- return B; -- call site |
| 5576 |
-- ... |
| 5577 |
-- end A; |
| 5578 |
-- |
| 5579 |
-- X : ... := A; -- root scenario |
| 5580 |
-- |
| 5581 |
-- function B ... is -- target body |
| 5582 |
-- ... |
| 5583 |
-- end B; |
| 5584 |
-- |
| 5585 |
-- Y : ... := A; -- root scenario |
| 5586 |
-- |
| 5587 |
-- IMPORTANT: The call to B from A is a possible ABE for X, but |
| 5588 |
-- not for Y. Installing an unconditional ABE raise prior to the |
| 5589 |
-- call to B would be wrong as it will fail for Y as well, but in |
| 5590 |
-- Y's case the call to B is never an ABE. |
| 5591 |
|
| 5592 |
elsif Present (Body_Decl) |
| 5593 |
and then In_Extended_Main_Code_Unit (Body_Decl) |
| 5594 |
then |
| 5595 |
if Earlier_In_Extended_Unit (Root, Body_Decl) then |
| 5596 |
|
| 5597 |
-- Do not emit any ABE diagnostics when a previous scenario in |
| 5598 |
-- this traversal has suppressed elaboration warnings. |
| 5599 |
|
| 5600 |
if New_In_State.Suppress_Warnings then |
| 5601 |
null; |
| 5602 |
|
| 5603 |
-- Do not emit any ABE diagnostics when the call occurs in a |
| 5604 |
-- partial finalization context because this leads to confusing |
| 5605 |
-- noise. |
| 5606 |
|
| 5607 |
elsif New_In_State.Within_Partial_Finalization then |
| 5608 |
null; |
| 5609 |
|
| 5610 |
-- Otherwise emit the ABE diagnostic |
| 5611 |
|
| 5612 |
else |
| 5613 |
Error_Msg_NE |
| 5614 |
("??cannot call & before body seen", Call, Subp_Id); |
| 5615 |
Error_Msg_N |
| 5616 |
("\Program_Error may be raised at run time", Call); |
| 5617 |
|
| 5618 |
Output_Active_Scenarios (Call, New_In_State); |
| 5619 |
end if; |
| 5620 |
|
| 5621 |
-- Install a conditional run-time ABE check to verify that the |
| 5622 |
-- target body has been elaborated prior to the call. |
| 5623 |
|
| 5624 |
if Check_OK then |
| 5625 |
Install_Scenario_ABE_Check |
| 5626 |
(N => Call, |
| 5627 |
Targ_Id => Subp_Id, |
| 5628 |
Targ_Rep => Subp_Rep, |
| 5629 |
Disable => Call_Rep); |
| 5630 |
|
| 5631 |
-- Update the state of the Processing phase to indicate that |
| 5632 |
-- no implicit Elaborate[_All] pragma must be generated from |
| 5633 |
-- this point on. |
| 5634 |
-- |
| 5635 |
-- function B ...; |
| 5636 |
-- |
| 5637 |
-- function A ... is |
| 5638 |
-- begin |
| 5639 |
-- if Some_Condition then |
| 5640 |
-- <ABE check> |
| 5641 |
-- return B; |
| 5642 |
-- ... |
| 5643 |
-- end A; |
| 5644 |
-- |
| 5645 |
-- X : ... := A; |
| 5646 |
-- |
| 5647 |
-- function B ... is |
| 5648 |
-- External.Subp; -- imparts Elaborate_All |
| 5649 |
-- end B; |
| 5650 |
-- |
| 5651 |
-- If Some_Condition is True, then the ABE check will fail |
| 5652 |
-- at runtime and the call to External.Subp will never take |
| 5653 |
-- place, rendering the implicit Elaborate_All useless. |
| 5654 |
-- |
| 5655 |
-- If the value of Some_Condition is False, then the call |
| 5656 |
-- to External.Subp will never take place, rendering the |
| 5657 |
-- implicit Elaborate_All useless. |
| 5658 |
|
| 5659 |
New_In_State.Suppress_Implicit_Pragmas := True; |
| 5660 |
end if; |
| 5661 |
end if; |
| 5662 |
|
| 5663 |
-- Otherwise the target body is not available in this compilation or |
| 5664 |
-- it resides in an external unit. Install a run-time ABE check to |
| 5665 |
-- verify that the target body has been elaborated prior to the call |
| 5666 |
-- site when the dynamic model is in effect. |
| 5667 |
|
| 5668 |
elsif Check_OK |
| 5669 |
and then New_In_State.Processing = Dynamic_Model_Processing |
| 5670 |
then |
| 5671 |
Install_Unit_ABE_Check |
| 5672 |
(N => Call, |
| 5673 |
Unit_Id => Unit_Id, |
| 5674 |
Disable => Call_Rep); |
| 5675 |
end if; |
| 5676 |
|
| 5677 |
-- Ensure that the unit with the target body is elaborated prior to |
| 5678 |
-- the main unit. The implicit Elaborate[_All] is generated only when |
| 5679 |
-- the call has elaboration checks enabled. This behavior parallels |
| 5680 |
-- that of the old ABE mechanism. |
| 5681 |
|
| 5682 |
if Elaboration_Checks_OK (Call_Rep) then |
| 5683 |
Ensure_Prior_Elaboration |
| 5684 |
(N => Call, |
| 5685 |
Unit_Id => Unit_Id, |
| 5686 |
Prag_Nam => Name_Elaborate_All, |
| 5687 |
In_State => New_In_State); |
| 5688 |
end if; |
| 5689 |
end Process_Conditional_ABE_Call_Ada; |
| 5690 |
|
| 5691 |
---------------------------------------- |
| 5692 |
-- Process_Conditional_ABE_Call_SPARK -- |
| 5693 |
---------------------------------------- |
| 5694 |
|
| 5695 |
procedure Process_Conditional_ABE_Call_SPARK |
| 5696 |
(Call : Node_Id; |
| 5697 |
Call_Rep : Scenario_Rep_Id; |
| 5698 |
Subp_Id : Entity_Id; |
| 5699 |
Subp_Rep : Target_Rep_Id; |
| 5700 |
In_State : Processing_In_State) |
| 5701 |
is |
| 5702 |
pragma Unreferenced (Call_Rep); |
| 5703 |
|
| 5704 |
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep); |
| 5705 |
Region : Node_Id; |
| 5706 |
|
| 5707 |
begin |
| 5708 |
-- Ensure that a suitable elaboration model is in effect for SPARK |
| 5709 |
-- rule verification. |
| 5710 |
|
| 5711 |
Check_SPARK_Model_In_Effect; |
| 5712 |
|
| 5713 |
-- The call and the target body are both in the main unit |
| 5714 |
|
| 5715 |
if Present (Body_Decl) |
| 5716 |
and then In_Extended_Main_Code_Unit (Body_Decl) |
| 5717 |
and then Earlier_In_Extended_Unit (Call, Body_Decl) |
| 5718 |
then |
| 5719 |
-- Do not emit any ABE diagnostics when a previous scenario in |
| 5720 |
-- this traversal has suppressed elaboration warnings. |
| 5721 |
|
| 5722 |
if In_State.Suppress_Warnings then |
| 5723 |
null; |
| 5724 |
|
| 5725 |
-- Do not emit any ABE diagnostics when the call occurs in a |
| 5726 |
-- freezing actions context because this leads to incorrect |
| 5727 |
-- diagnostics. |
| 5728 |
|
| 5729 |
elsif In_State.Within_Freezing_Actions then |
| 5730 |
null; |
| 5731 |
|
| 5732 |
-- Do not emit any ABE diagnostics when the call occurs in an |
| 5733 |
-- initial condition context because this leads to incorrect |
| 5734 |
-- diagnostics. |
| 5735 |
|
| 5736 |
elsif In_State.Within_Initial_Condition then |
| 5737 |
null; |
| 5738 |
|
| 5739 |
-- Do not emit any ABE diagnostics when the call occurs in a |
| 5740 |
-- partial finalization context because this leads to confusing |
| 5741 |
-- noise. |
| 5742 |
|
| 5743 |
elsif In_State.Within_Partial_Finalization then |
| 5744 |
null; |
| 5745 |
|
| 5746 |
-- Ensure that a call that textually precedes the subprogram body |
| 5747 |
-- it invokes appears within the early call region of the body. |
| 5748 |
-- |
| 5749 |
-- IMPORTANT: This check must always be performed even when switch |
| 5750 |
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not |
| 5751 |
-- specified because the static model cannot guarantee the absence |
| 5752 |
-- of elaboration issues when dispatching calls are involved. |
| 5753 |
|
| 5754 |
else |
| 5755 |
Region := Find_Early_Call_Region (Body_Decl); |
| 5756 |
|
| 5757 |
if Earlier_In_Extended_Unit (Call, Region) then |
| 5758 |
Error_Msg_NE |
| 5759 |
("call must appear within early call region of subprogram " |
| 5760 |
& "body & (SPARK RM 7.7(3))", |
| 5761 |
Call, Subp_Id); |
| 5762 |
|
| 5763 |
Error_Msg_Sloc := Sloc (Region); |
| 5764 |
Error_Msg_N ("\region starts #", Call); |
| 5765 |
|
| 5766 |
Error_Msg_Sloc := Sloc (Body_Decl); |
| 5767 |
Error_Msg_N ("\region ends #", Call); |
| 5768 |
|
| 5769 |
Output_Active_Scenarios (Call, In_State); |
| 5770 |
end if; |
| 5771 |
end if; |
| 5772 |
end if; |
| 5773 |
|
| 5774 |
-- A call to a source target or to a target which emulates Ada |
| 5775 |
-- or SPARK semantics imposes an Elaborate_All requirement on the |
| 5776 |
-- context of the main unit. Determine whether the context has a |
| 5777 |
-- pragma strong enough to meet the requirement. |
| 5778 |
-- |
| 5779 |
-- IMPORTANT: This check must be performed only when switch -gnatd.v |
| 5780 |
-- (enforce SPARK elaboration rules in SPARK code) is active because |
| 5781 |
-- the static model can ensure the prior elaboration of the unit |
| 5782 |
-- which contains a body by installing an implicit Elaborate[_All] |
| 5783 |
-- pragma. |
| 5784 |
|
| 5785 |
if Debug_Flag_Dot_V then |
| 5786 |
if Comes_From_Source (Subp_Id) |
| 5787 |
or else Is_Ada_Semantic_Target (Subp_Id) |
| 5788 |
or else Is_SPARK_Semantic_Target (Subp_Id) |
| 5789 |
then |
| 5790 |
Meet_Elaboration_Requirement |
| 5791 |
(N => Call, |
| 5792 |
Targ_Id => Subp_Id, |
| 5793 |
Req_Nam => Name_Elaborate_All, |
| 5794 |
In_State => In_State); |
| 5795 |
end if; |
| 5796 |
|
| 5797 |
-- Otherwise ensure that the unit with the target body is elaborated |
| 5798 |
-- prior to the main unit. |
| 5799 |
|
| 5800 |
else |
| 5801 |
Ensure_Prior_Elaboration |
| 5802 |
(N => Call, |
| 5803 |
Unit_Id => Unit (Subp_Rep), |
| 5804 |
Prag_Nam => Name_Elaborate_All, |
| 5805 |
In_State => In_State); |
| 5806 |
end if; |
| 5807 |
end Process_Conditional_ABE_Call_SPARK; |
| 5808 |
|
| 5809 |
------------------------------------------- |
| 5810 |
-- Process_Conditional_ABE_Instantiation -- |
| 5811 |
------------------------------------------- |
| 5812 |
|
| 5813 |
procedure Process_Conditional_ABE_Instantiation |
| 5814 |
(Inst : Node_Id; |
| 5815 |
Inst_Rep : Scenario_Rep_Id; |
| 5816 |
In_State : Processing_In_State) |
| 5817 |
is |
| 5818 |
Gen_Id : constant Entity_Id := Target (Inst_Rep); |
| 5819 |
Gen_Rep : constant Target_Rep_Id := |
| 5820 |
Target_Representation_Of (Gen_Id, In_State); |
| 5821 |
|
| 5822 |
SPARK_Rules_On : constant Boolean := |
| 5823 |
SPARK_Mode_Of (Inst_Rep) = Is_On |
| 5824 |
and then SPARK_Mode_Of (Gen_Rep) = Is_On; |
| 5825 |
|
| 5826 |
New_In_State : Processing_In_State := In_State; |
| 5827 |
-- Each step of the Processing phase constitutes a new state |
| 5828 |
|
| 5829 |
begin |
| 5830 |
-- Output relevant information when switch -gnatel (info messages on |
| 5831 |
-- implicit Elaborate[_All] pragmas) is in effect. |
| 5832 |
|
| 5833 |
if Elab_Info_Messages |
| 5834 |
and then not New_In_State.Suppress_Info_Messages |
| 5835 |
then |
| 5836 |
Info_Instantiation |
| 5837 |
(Inst => Inst, |
| 5838 |
Gen_Id => Gen_Id, |
| 5839 |
Info_Msg => True, |
| 5840 |
In_SPARK => SPARK_Rules_On); |
| 5841 |
end if; |
| 5842 |
|
| 5843 |
-- Nothing to do when the instantiation is a guaranteed ABE |
| 5844 |
|
| 5845 |
if Is_Known_Guaranteed_ABE (Inst) then |
| 5846 |
return; |
| 5847 |
|
| 5848 |
-- Nothing to do when the root scenario appears at the declaration |
| 5849 |
-- level and the generic is in the same unit, but outside this |
| 5850 |
-- context. |
| 5851 |
-- |
| 5852 |
-- generic |
| 5853 |
-- procedure Gen is ...; -- generic declaration |
| 5854 |
-- |
| 5855 |
-- procedure Proc is |
| 5856 |
-- function A ... is |
| 5857 |
-- begin |
| 5858 |
-- if Some_Condition then |
| 5859 |
-- declare |
| 5860 |
-- procedure I is new Gen; -- instantiation site |
| 5861 |
-- ... |
| 5862 |
-- ... |
| 5863 |
-- end A; |
| 5864 |
-- |
| 5865 |
-- X : ... := A; -- root scenario |
| 5866 |
-- ... |
| 5867 |
-- |
| 5868 |
-- procedure Gen is |
| 5869 |
-- ... |
| 5870 |
-- end Gen; |
| 5871 |
-- |
| 5872 |
-- In the example above, the context of X is the declarative region |
| 5873 |
-- of Proc. The "elaboration" of X may eventually reach Gen which |
| 5874 |
-- appears outside of X's context. Gen is relevant only when Proc is |
| 5875 |
-- invoked, but this happens only by means of "normal" elaboration, |
| 5876 |
-- therefore Gen must not be considered if this is not the case. |
| 5877 |
|
| 5878 |
elsif Is_Up_Level_Target |
| 5879 |
(Targ_Decl => Spec_Declaration (Gen_Rep), |
| 5880 |
In_State => New_In_State) |
| 5881 |
then |
| 5882 |
return; |
| 5883 |
end if; |
| 5884 |
|
| 5885 |
-- Warnings are suppressed when a prior scenario is already in that |
| 5886 |
-- mode, or when the instantiation has warnings suppressed. Update |
| 5887 |
-- the state of the processing phase to reflect this. |
| 5888 |
|
| 5889 |
New_In_State.Suppress_Warnings := |
| 5890 |
New_In_State.Suppress_Warnings |
| 5891 |
or else not Elaboration_Warnings_OK (Inst_Rep); |
| 5892 |
|
| 5893 |
-- The SPARK rules are in effect |
| 5894 |
|
| 5895 |
if SPARK_Rules_On then |
| 5896 |
Process_Conditional_ABE_Instantiation_SPARK |
| 5897 |
(Inst => Inst, |
| 5898 |
Inst_Rep => Inst_Rep, |
| 5899 |
Gen_Id => Gen_Id, |
| 5900 |
Gen_Rep => Gen_Rep, |
| 5901 |
In_State => New_In_State); |
| 5902 |
|
| 5903 |
-- Otherwise the Ada rules are in effect, or SPARK code is allowed to |
| 5904 |
-- violate the SPARK rules. |
| 5905 |
|
| 5906 |
else |
| 5907 |
Process_Conditional_ABE_Instantiation_Ada |
| 5908 |
(Inst => Inst, |
| 5909 |
Inst_Rep => Inst_Rep, |
| 5910 |
Gen_Id => Gen_Id, |
| 5911 |
Gen_Rep => Gen_Rep, |
| 5912 |
In_State => New_In_State); |
| 5913 |
end if; |
| 5914 |
end Process_Conditional_ABE_Instantiation; |
| 5915 |
|
| 5916 |
----------------------------------------------- |
| 5917 |
-- Process_Conditional_ABE_Instantiation_Ada -- |
| 5918 |
----------------------------------------------- |
| 5919 |
|
| 5920 |
procedure Process_Conditional_ABE_Instantiation_Ada |
| 5921 |
(Inst : Node_Id; |
| 5922 |
Inst_Rep : Scenario_Rep_Id; |
| 5923 |
Gen_Id : Entity_Id; |
| 5924 |
Gen_Rep : Target_Rep_Id; |
| 5925 |
In_State : Processing_In_State) |
| 5926 |
is |
| 5927 |
Body_Decl : constant Node_Id := Body_Declaration (Gen_Rep); |
| 5928 |
Root : constant Node_Id := Root_Scenario; |
| 5929 |
Unit_Id : constant Entity_Id := Unit (Gen_Rep); |
| 5930 |
|
| 5931 |
Check_OK : constant Boolean := |
| 5932 |
not In_State.Suppress_Checks |
| 5933 |
and then Ghost_Mode_Of (Inst_Rep) /= Is_Ignored |
| 5934 |
and then Ghost_Mode_Of (Gen_Rep) /= Is_Ignored |
| 5935 |
and then Elaboration_Checks_OK (Inst_Rep) |
| 5936 |
and then Elaboration_Checks_OK (Gen_Rep); |
| 5937 |
-- A run-time ABE check may be installed only when both the instance |
| 5938 |
-- and the generic have active elaboration checks and both are not |
| 5939 |
-- ignored Ghost constructs. |
| 5940 |
|
| 5941 |
New_In_State : Processing_In_State := In_State; |
| 5942 |
-- Each step of the Processing phase constitutes a new state |
| 5943 |
|
| 5944 |
begin |
| 5945 |
-- Nothing to do when the instantiation is ABE-safe |
| 5946 |
-- |
| 5947 |
-- generic |
| 5948 |
-- package Gen is |
| 5949 |
-- ... |
| 5950 |
-- end Gen; |
| 5951 |
-- |
| 5952 |
-- package body Gen is |
| 5953 |
-- ... |
| 5954 |
-- end Gen; |
| 5955 |
-- |
| 5956 |
-- with Gen; |
| 5957 |
-- procedure Main is |
| 5958 |
-- package Inst is new Gen (ABE); -- safe instantiation |
| 5959 |
-- ... |
| 5960 |
|
| 5961 |
if Is_Safe_Instantiation (Inst, Gen_Id, Gen_Rep) then |
| 5962 |
return; |
| 5963 |
|
| 5964 |
-- The instantiation and the generic body are both in the main unit |
| 5965 |
-- |
| 5966 |
-- If the root scenario appears prior to the generic body, then this |
| 5967 |
-- is a possible ABE with respect to the root scenario. |
| 5968 |
-- |
| 5969 |
-- generic |
| 5970 |
-- package Gen is |
| 5971 |
-- ... |
| 5972 |
-- end Gen; |
| 5973 |
-- |
| 5974 |
-- function A ... is |
| 5975 |
-- begin |
| 5976 |
-- if Some_Condition then |
| 5977 |
-- declare |
| 5978 |
-- package Inst is new Gen; -- instantiation site |
| 5979 |
-- ... |
| 5980 |
-- end A; |
| 5981 |
-- |
| 5982 |
-- X : ... := A; -- root scenario |
| 5983 |
-- |
| 5984 |
-- package body Gen is -- generic body |
| 5985 |
-- ... |
| 5986 |
-- end Gen; |
| 5987 |
-- |
| 5988 |
-- Y : ... := A; -- root scenario |
| 5989 |
-- |
| 5990 |
-- IMPORTANT: The instantiation of Gen is a possible ABE for X, |
| 5991 |
-- but not for Y. Installing an unconditional ABE raise prior to |
| 5992 |
-- the instance site would be wrong as it will fail for Y as well, |
| 5993 |
-- but in Y's case the instantiation of Gen is never an ABE. |
| 5994 |
|
| 5995 |
elsif Present (Body_Decl) |
| 5996 |
and then In_Extended_Main_Code_Unit (Body_Decl) |
| 5997 |
then |
| 5998 |
if Earlier_In_Extended_Unit (Root, Body_Decl) then |
| 5999 |
|
| 6000 |
-- Do not emit any ABE diagnostics when a previous scenario in |
| 6001 |
-- this traversal has suppressed elaboration warnings. |
| 6002 |
|
| 6003 |
if New_In_State.Suppress_Warnings then |
| 6004 |
null; |
| 6005 |
|
| 6006 |
-- Do not emit any ABE diagnostics when the instantiation |
| 6007 |
-- occurs in partial finalization context because this leads |
| 6008 |
-- to unwanted noise. |
| 6009 |
|
| 6010 |
elsif New_In_State.Within_Partial_Finalization then |
| 6011 |
null; |
| 6012 |
|
| 6013 |
-- Otherwise output the diagnostic |
| 6014 |
|
| 6015 |
else |
| 6016 |
Error_Msg_NE |
| 6017 |
("??cannot instantiate & before body seen", Inst, Gen_Id); |
| 6018 |
Error_Msg_N |
| 6019 |
("\Program_Error may be raised at run time", Inst); |
| 6020 |
|
| 6021 |
Output_Active_Scenarios (Inst, New_In_State); |
| 6022 |
end if; |
| 6023 |
|
| 6024 |
-- Install a conditional run-time ABE check to verify that the |
| 6025 |
-- generic body has been elaborated prior to the instantiation. |
| 6026 |
|
| 6027 |
if Check_OK then |
| 6028 |
Install_Scenario_ABE_Check |
| 6029 |
(N => Inst, |
| 6030 |
Targ_Id => Gen_Id, |
| 6031 |
Targ_Rep => Gen_Rep, |
| 6032 |
Disable => Inst_Rep); |
| 6033 |
|
| 6034 |
-- Update the state of the Processing phase to indicate that |
| 6035 |
-- no implicit Elaborate[_All] pragma must be generated from |
| 6036 |
-- this point on. |
| 6037 |
-- |
| 6038 |
-- generic |
| 6039 |
-- package Gen is |
| 6040 |
-- ... |
| 6041 |
-- end Gen; |
| 6042 |
-- |
| 6043 |
-- function A ... is |
| 6044 |
-- begin |
| 6045 |
-- if Some_Condition then |
| 6046 |
-- <ABE check> |
| 6047 |
-- declare Inst is new Gen; |
| 6048 |
-- ... |
| 6049 |
-- end A; |
| 6050 |
-- |
| 6051 |
-- X : ... := A; |
| 6052 |
-- |
| 6053 |
-- package body Gen is |
| 6054 |
-- begin |
| 6055 |
-- External.Subp; -- imparts Elaborate_All |
| 6056 |
-- end Gen; |
| 6057 |
-- |
| 6058 |
-- If Some_Condition is True, then the ABE check will fail |
| 6059 |
-- at runtime and the call to External.Subp will never take |
| 6060 |
-- place, rendering the implicit Elaborate_All useless. |
| 6061 |
-- |
| 6062 |
-- If the value of Some_Condition is False, then the call |
| 6063 |
-- to External.Subp will never take place, rendering the |
| 6064 |
-- implicit Elaborate_All useless. |
| 6065 |
|
| 6066 |
New_In_State.Suppress_Implicit_Pragmas := True; |
| 6067 |
end if; |
| 6068 |
end if; |
| 6069 |
|
| 6070 |
-- Otherwise the generic body is not available in this compilation |
| 6071 |
-- or it resides in an external unit. Install a run-time ABE check |
| 6072 |
-- to verify that the generic body has been elaborated prior to the |
| 6073 |
-- instantiation when the dynamic model is in effect. |
| 6074 |
|
| 6075 |
elsif Check_OK |
| 6076 |
and then New_In_State.Processing = Dynamic_Model_Processing |
| 6077 |
then |
| 6078 |
Install_Unit_ABE_Check |
| 6079 |
(N => Inst, |
| 6080 |
Unit_Id => Unit_Id, |
| 6081 |
Disable => Inst_Rep); |
| 6082 |
end if; |
| 6083 |
|
| 6084 |
-- Ensure that the unit with the generic body is elaborated prior |
| 6085 |
-- to the main unit. No implicit pragma has to be generated if the |
| 6086 |
-- instantiation has elaboration checks suppressed. This behavior |
| 6087 |
-- parallels that of the old ABE mechanism. |
| 6088 |
|
| 6089 |
if Elaboration_Checks_OK (Inst_Rep) then |
| 6090 |
Ensure_Prior_Elaboration |
| 6091 |
(N => Inst, |
| 6092 |
Unit_Id => Unit_Id, |
| 6093 |
Prag_Nam => Name_Elaborate, |
| 6094 |
In_State => New_In_State); |
| 6095 |
end if; |
| 6096 |
end Process_Conditional_ABE_Instantiation_Ada; |
| 6097 |
|
| 6098 |
------------------------------------------------- |
| 6099 |
-- Process_Conditional_ABE_Instantiation_SPARK -- |
| 6100 |
------------------------------------------------- |
| 6101 |
|
| 6102 |
procedure Process_Conditional_ABE_Instantiation_SPARK |
| 6103 |
(Inst : Node_Id; |
| 6104 |
Inst_Rep : Scenario_Rep_Id; |
| 6105 |
Gen_Id : Entity_Id; |
| 6106 |
Gen_Rep : Target_Rep_Id; |
| 6107 |
In_State : Processing_In_State) |
| 6108 |
is |
| 6109 |
pragma Unreferenced (Inst_Rep); |
| 6110 |
|
| 6111 |
Req_Nam : Name_Id; |
| 6112 |
|
| 6113 |
begin |
| 6114 |
-- Ensure that a suitable elaboration model is in effect for SPARK |
| 6115 |
-- rule verification. |
| 6116 |
|
| 6117 |
Check_SPARK_Model_In_Effect; |
| 6118 |
|
| 6119 |
-- A source instantiation imposes an Elaborate[_All] requirement |
| 6120 |
-- on the context of the main unit. Determine whether the context |
| 6121 |
-- has a pragma strong enough to meet the requirement. The check |
| 6122 |
-- is orthogonal to the ABE ramifications of the instantiation. |
| 6123 |
-- |
| 6124 |
-- IMPORTANT: This check must be performed only when switch -gnatd.v |
| 6125 |
-- (enforce SPARK elaboration rules in SPARK code) is active because |
| 6126 |
-- the static model can ensure the prior elaboration of the unit |
| 6127 |
-- which contains a body by installing an implicit Elaborate[_All] |
| 6128 |
-- pragma. |
| 6129 |
|
| 6130 |
if Debug_Flag_Dot_V then |
| 6131 |
if Nkind (Inst) = N_Package_Instantiation then |
| 6132 |
Req_Nam := Name_Elaborate_All; |
| 6133 |
else |
| 6134 |
Req_Nam := Name_Elaborate; |
| 6135 |
end if; |
| 6136 |
|
| 6137 |
Meet_Elaboration_Requirement |
| 6138 |
(N => Inst, |
| 6139 |
Targ_Id => Gen_Id, |
| 6140 |
Req_Nam => Req_Nam, |
| 6141 |
In_State => In_State); |
| 6142 |
|
| 6143 |
-- Otherwise ensure that the unit with the target body is elaborated |
| 6144 |
-- prior to the main unit. |
| 6145 |
|
| 6146 |
else |
| 6147 |
Ensure_Prior_Elaboration |
| 6148 |
(N => Inst, |
| 6149 |
Unit_Id => Unit (Gen_Rep), |
| 6150 |
Prag_Nam => Name_Elaborate, |
| 6151 |
In_State => In_State); |
| 6152 |
end if; |
| 6153 |
end Process_Conditional_ABE_Instantiation_SPARK; |
| 6154 |
|
| 6155 |
------------------------------------------------- |
| 6156 |
-- Process_Conditional_ABE_Variable_Assignment -- |
| 6157 |
------------------------------------------------- |
| 6158 |
|
| 6159 |
procedure Process_Conditional_ABE_Variable_Assignment |
| 6160 |
(Asmt : Node_Id; |
| 6161 |
Asmt_Rep : Scenario_Rep_Id; |
| 6162 |
In_State : Processing_In_State) |
| 6163 |
is |
| 6164 |
|
| 6165 |
Var_Id : constant Entity_Id := Target (Asmt_Rep); |
| 6166 |
Var_Rep : constant Target_Rep_Id := |
| 6167 |
Target_Representation_Of (Var_Id, In_State); |
| 6168 |
|
| 6169 |
SPARK_Rules_On : constant Boolean := |
| 6170 |
SPARK_Mode_Of (Asmt_Rep) = Is_On |
| 6171 |
and then SPARK_Mode_Of (Var_Rep) = Is_On; |
| 6172 |
|
| 6173 |
begin |
| 6174 |
-- Output relevant information when switch -gnatel (info messages on |
| 6175 |
-- implicit Elaborate[_All] pragmas) is in effect. |
| 6176 |
|
| 6177 |
if Elab_Info_Messages |
| 6178 |
and then not In_State.Suppress_Info_Messages |
| 6179 |
then |
| 6180 |
Elab_Msg_NE |
| 6181 |
(Msg => "assignment to & during elaboration", |
| 6182 |
N => Asmt, |
| 6183 |
Id => Var_Id, |
| 6184 |
Info_Msg => True, |
| 6185 |
In_SPARK => SPARK_Rules_On); |
| 6186 |
end if; |
| 6187 |
|
| 6188 |
-- The SPARK rules are in effect. These rules are applied regardless |
| 6189 |
-- of whether switch -gnatd.v (enforce SPARK elaboration rules in |
| 6190 |
-- SPARK code) is in effect because the static model cannot ensure |
| 6191 |
-- safe assignment of variables. |
| 6192 |
|
| 6193 |
if SPARK_Rules_On then |
| 6194 |
Process_Conditional_ABE_Variable_Assignment_SPARK |
| 6195 |
(Asmt => Asmt, |
| 6196 |
Asmt_Rep => Asmt_Rep, |
| 6197 |
Var_Id => Var_Id, |
| 6198 |
Var_Rep => Var_Rep, |
| 6199 |
In_State => In_State); |
| 6200 |
|
| 6201 |
-- Otherwise the Ada rules are in effect |
| 6202 |
|
| 6203 |
else |
| 6204 |
Process_Conditional_ABE_Variable_Assignment_Ada |
| 6205 |
(Asmt => Asmt, |
| 6206 |
Asmt_Rep => Asmt_Rep, |
| 6207 |
Var_Id => Var_Id, |
| 6208 |
Var_Rep => Var_Rep, |
| 6209 |
In_State => In_State); |
| 6210 |
end if; |
| 6211 |
end Process_Conditional_ABE_Variable_Assignment; |
| 6212 |
|
| 6213 |
----------------------------------------------------- |
| 6214 |
-- Process_Conditional_ABE_Variable_Assignment_Ada -- |
| 6215 |
----------------------------------------------------- |
| 6216 |
|
| 6217 |
procedure Process_Conditional_ABE_Variable_Assignment_Ada |
| 6218 |
(Asmt : Node_Id; |
| 6219 |
Asmt_Rep : Scenario_Rep_Id; |
| 6220 |
Var_Id : Entity_Id; |
| 6221 |
Var_Rep : Target_Rep_Id; |
| 6222 |
In_State : Processing_In_State) |
| 6223 |
is |
| 6224 |
pragma Unreferenced (Asmt_Rep); |
| 6225 |
|
| 6226 |
Var_Decl : constant Node_Id := Variable_Declaration (Var_Rep); |
| 6227 |
Unit_Id : constant Entity_Id := Unit (Var_Rep); |
| 6228 |
|
| 6229 |
begin |
| 6230 |
-- Emit a warning when an uninitialized variable declared in a |
| 6231 |
-- package spec without a pragma Elaborate_Body is initialized |
| 6232 |
-- by elaboration code within the corresponding body. |
| 6233 |
|
| 6234 |
if Is_Elaboration_Warnings_OK_Id (Var_Id) |
| 6235 |
and then not Is_Initialized (Var_Decl) |
| 6236 |
and then not Has_Pragma_Elaborate_Body (Unit_Id) |
| 6237 |
then |
| 6238 |
-- Do not emit any ABE diagnostics when a previous scenario in |
| 6239 |
-- this traversal has suppressed elaboration warnings. |
| 6240 |
|
| 6241 |
if not In_State.Suppress_Warnings then |
| 6242 |
Error_Msg_NE |
| 6243 |
("??variable & can be accessed by clients before this " |
| 6244 |
& "initialization", Asmt, Var_Id); |
| 6245 |
|
| 6246 |
Error_Msg_NE |
| 6247 |
("\add pragma ""Elaborate_Body"" to spec & to ensure proper " |
| 6248 |
& "initialization", Asmt, Unit_Id); |
| 6249 |
|
| 6250 |
Output_Active_Scenarios (Asmt, In_State); |
| 6251 |
end if; |
| 6252 |
|
| 6253 |
-- Generate an implicit Elaborate_Body in the spec |
| 6254 |
|
| 6255 |
Set_Elaborate_Body_Desirable (Unit_Id); |
| 6256 |
end if; |
| 6257 |
end Process_Conditional_ABE_Variable_Assignment_Ada; |
| 6258 |
|
| 6259 |
------------------------------------------------------- |
| 6260 |
-- Process_Conditional_ABE_Variable_Assignment_SPARK -- |
| 6261 |
------------------------------------------------------- |
| 6262 |
|
| 6263 |
procedure Process_Conditional_ABE_Variable_Assignment_SPARK |
| 6264 |
(Asmt : Node_Id; |
| 6265 |
Asmt_Rep : Scenario_Rep_Id; |
| 6266 |
Var_Id : Entity_Id; |
| 6267 |
Var_Rep : Target_Rep_Id; |
| 6268 |
In_State : Processing_In_State) |
| 6269 |
is |
| 6270 |
pragma Unreferenced (Asmt_Rep); |
| 6271 |
|
| 6272 |
Var_Decl : constant Node_Id := Variable_Declaration (Var_Rep); |
| 6273 |
Unit_Id : constant Entity_Id := Unit (Var_Rep); |
| 6274 |
|
| 6275 |
begin |
| 6276 |
-- Ensure that a suitable elaboration model is in effect for SPARK |
| 6277 |
-- rule verification. |
| 6278 |
|
| 6279 |
Check_SPARK_Model_In_Effect; |
| 6280 |
|
| 6281 |
-- Do not emit any ABE diagnostics when a previous scenario in this |
| 6282 |
-- traversal has suppressed elaboration warnings. |
| 6283 |
|
| 6284 |
if In_State.Suppress_Warnings then |
| 6285 |
null; |
| 6286 |
|
| 6287 |
-- Emit an error when an initialized variable declared in a package |
| 6288 |
-- spec that is missing pragma Elaborate_Body is further modified by |
| 6289 |
-- elaboration code within the corresponding body. |
| 6290 |
|
| 6291 |
elsif Is_Elaboration_Warnings_OK_Id (Var_Id) |
| 6292 |
and then Is_Initialized (Var_Decl) |
| 6293 |
and then not Has_Pragma_Elaborate_Body (Unit_Id) |
| 6294 |
then |
| 6295 |
Error_Msg_NE |
| 6296 |
("variable & modified by elaboration code in package body", |
| 6297 |
Asmt, Var_Id); |
| 6298 |
|
| 6299 |
Error_Msg_NE |
| 6300 |
("\add pragma ""Elaborate_Body"" to spec & to ensure full " |
| 6301 |
& "initialization", Asmt, Unit_Id); |
| 6302 |
|
| 6303 |
Output_Active_Scenarios (Asmt, In_State); |
| 6304 |
end if; |
| 6305 |
end Process_Conditional_ABE_Variable_Assignment_SPARK; |
| 6306 |
|
| 6307 |
------------------------------------------------ |
| 6308 |
-- Process_Conditional_ABE_Variable_Reference -- |
| 6309 |
------------------------------------------------ |
| 6310 |
|
| 6311 |
procedure Process_Conditional_ABE_Variable_Reference |
| 6312 |
(Ref : Node_Id; |
| 6313 |
Ref_Rep : Scenario_Rep_Id; |
| 6314 |
In_State : Processing_In_State) |
| 6315 |
is |
| 6316 |
Var_Id : constant Entity_Id := Target (Ref); |
| 6317 |
Var_Rep : Target_Rep_Id; |
| 6318 |
Unit_Id : Entity_Id; |
| 6319 |
|
| 6320 |
begin |
| 6321 |
-- Nothing to do when the variable reference is not a read |
| 6322 |
|
| 6323 |
if not Is_Read_Reference (Ref_Rep) then |
| 6324 |
return; |
| 6325 |
end if; |
| 6326 |
|
| 6327 |
Var_Rep := Target_Representation_Of (Var_Id, In_State); |
| 6328 |
Unit_Id := Unit (Var_Rep); |
| 6329 |
|
| 6330 |
-- Output relevant information when switch -gnatel (info messages on |
| 6331 |
-- implicit Elaborate[_All] pragmas) is in effect. |
| 6332 |
|
| 6333 |
if Elab_Info_Messages |
| 6334 |
and then not In_State.Suppress_Info_Messages |
| 6335 |
then |
| 6336 |
Elab_Msg_NE |
| 6337 |
(Msg => "read of variable & during elaboration", |
| 6338 |
N => Ref, |
| 6339 |
Id => Var_Id, |
| 6340 |
Info_Msg => True, |
| 6341 |
In_SPARK => True); |
| 6342 |
end if; |
| 6343 |
|
| 6344 |
-- Nothing to do when the variable appears within the main unit |
| 6345 |
-- because diagnostics on reads are relevant only for external |
| 6346 |
-- variables. |
| 6347 |
|
| 6348 |
if Is_Same_Unit (Unit_Id, Main_Unit_Entity) then |
| 6349 |
null; |
| 6350 |
|
| 6351 |
-- Nothing to do when the variable is already initialized. Note that |
| 6352 |
-- the variable may be further modified by the external unit. |
| 6353 |
|
| 6354 |
elsif Is_Initialized (Variable_Declaration (Var_Rep)) then |
| 6355 |
null; |
| 6356 |
|
| 6357 |
-- Nothing to do when the external unit guarantees the initialization |
| 6358 |
-- of the variable by means of pragma Elaborate_Body. |
| 6359 |
|
| 6360 |
elsif Has_Pragma_Elaborate_Body (Unit_Id) then |
| 6361 |
null; |
| 6362 |
|
| 6363 |
-- A variable read imposes an Elaborate requirement on the context of |
| 6364 |
-- the main unit. Determine whether the context has a pragma strong |
| 6365 |
-- enough to meet the requirement. |
| 6366 |
|
| 6367 |
else |
| 6368 |
Meet_Elaboration_Requirement |
| 6369 |
(N => Ref, |
| 6370 |
Targ_Id => Var_Id, |
| 6371 |
Req_Nam => Name_Elaborate, |
| 6372 |
In_State => In_State); |
| 6373 |
end if; |
| 6374 |
end Process_Conditional_ABE_Variable_Reference; |
| 6375 |
|
| 6376 |
----------------------------------- |
| 6377 |
-- Traverse_Conditional_ABE_Body -- |
| 6378 |
----------------------------------- |
| 6379 |
|
| 6380 |
procedure Traverse_Conditional_ABE_Body |
| 6381 |
(N : Node_Id; |
| 6382 |
In_State : Processing_In_State) |
| 6383 |
is |
| 6384 |
begin |
| 6385 |
Traverse_Body |
| 6386 |
(N => N, |
| 6387 |
Requires_Processing => Is_Conditional_ABE_Scenario'Access, |
| 6388 |
Processor => Process_Conditional_ABE'Access, |
| 6389 |
In_State => In_State); |
| 6390 |
end Traverse_Conditional_ABE_Body; |
| 6391 |
end Conditional_ABE_Processor; |
| 6392 |
|
| 6393 |
------------- |
| 6394 |
-- Destroy -- |
| 6395 |
------------- |
| 6396 |
|
| 6397 |
procedure Destroy (NE : in out Node_Or_Entity_Id) is |
| 6398 |
pragma Unreferenced (NE); |
| 6399 |
begin |
| 6400 |
null; |
| 6401 |
end Destroy; |
| 6402 |
|
| 6403 |
----------------- |
| 6404 |
-- Diagnostics -- |
| 6405 |
----------------- |
| 6406 |
|
| 6407 |
package body Diagnostics is |
| 6408 |
|
| 6409 |
----------------- |
| 6410 |
-- Elab_Msg_NE -- |
| 6411 |
----------------- |
| 6412 |
|
| 6413 |
procedure Elab_Msg_NE |
| 6414 |
(Msg : String; |
| 6415 |
N : Node_Id; |
| 6416 |
Id : Entity_Id; |
| 6417 |
Info_Msg : Boolean; |
| 6418 |
In_SPARK : Boolean) |
| 6419 |
is |
| 6420 |
function Prefix return String; |
| 6421 |
pragma Inline (Prefix); |
| 6422 |
-- Obtain the prefix of the message |
| 6423 |
|
| 6424 |
function Suffix return String; |
| 6425 |
pragma Inline (Suffix); |
| 6426 |
-- Obtain the suffix of the message |
| 6427 |
|
| 6428 |
------------ |
| 6429 |
-- Prefix -- |
| 6430 |
------------ |
| 6431 |
|
| 6432 |
function Prefix return String is |
| 6433 |
begin |
| 6434 |
if Info_Msg then |
| 6435 |
return "info: "; |
| 6436 |
else |
| 6437 |
return ""; |
| 6438 |
end if; |
| 6439 |
end Prefix; |
| 6440 |
|
| 6441 |
------------ |
| 6442 |
-- Suffix -- |
| 6443 |
------------ |
| 6444 |
|
| 6445 |
function Suffix return String is |
| 6446 |
begin |
| 6447 |
if In_SPARK then |
| 6448 |
return " in SPARK"; |
| 6449 |
else |
| 6450 |
return "?$?"; |
| 6451 |
end if; |
| 6452 |
end Suffix; |
| 6453 |
|
| 6454 |
-- Start of processing for Elab_Msg_NE |
| 6455 |
|
| 6456 |
begin |
| 6457 |
Error_Msg_NE (Prefix & Msg & Suffix, N, Id); |
| 6458 |
end Elab_Msg_NE; |
| 6459 |
|
| 6460 |
--------------- |
| 6461 |
-- Info_Call -- |
| 6462 |
--------------- |
| 6463 |
|
| 6464 |
procedure Info_Call |
| 6465 |
(Call : Node_Id; |
| 6466 |
Subp_Id : Entity_Id; |
| 6467 |
Info_Msg : Boolean; |
| 6468 |
In_SPARK : Boolean) |
| 6469 |
is |
| 6470 |
procedure Info_Accept_Alternative; |
| 6471 |
pragma Inline (Info_Accept_Alternative); |
| 6472 |
-- Output information concerning an accept alternative |
| 6473 |
|
| 6474 |
procedure Info_Simple_Call; |
| 6475 |
pragma Inline (Info_Simple_Call); |
| 6476 |
-- Output information concerning the call |
| 6477 |
|
| 6478 |
procedure Info_Type_Actions (Action : String); |
| 6479 |
pragma Inline (Info_Type_Actions); |
| 6480 |
-- Output information concerning action Action of a type |
| 6481 |
|
| 6482 |
procedure Info_Verification_Call |
| 6483 |
(Pred : String; |
| 6484 |
Id : Entity_Id; |
| 6485 |
Id_Kind : String); |
| 6486 |
pragma Inline (Info_Verification_Call); |
| 6487 |
-- Output information concerning the verification of predicate Pred |
| 6488 |
-- applied to related entity Id with kind Id_Kind. |
| 6489 |
|
| 6490 |
----------------------------- |
| 6491 |
-- Info_Accept_Alternative -- |
| 6492 |
----------------------------- |
| 6493 |
|
| 6494 |
procedure Info_Accept_Alternative is |
| 6495 |
Entry_Id : constant Entity_Id := Receiving_Entry (Subp_Id); |
| 6496 |
pragma Assert (Present (Entry_Id)); |
| 6497 |
|
| 6498 |
begin |
| 6499 |
Elab_Msg_NE |
| 6500 |
(Msg => "accept for entry & during elaboration", |
| 6501 |
N => Call, |
| 6502 |
Id => Entry_Id, |
| 6503 |
Info_Msg => Info_Msg, |
| 6504 |
In_SPARK => In_SPARK); |
| 6505 |
end Info_Accept_Alternative; |
| 6506 |
|
| 6507 |
---------------------- |
| 6508 |
-- Info_Simple_Call -- |
| 6509 |
---------------------- |
| 6510 |
|
| 6511 |
procedure Info_Simple_Call is |
| 6512 |
begin |
| 6513 |
Elab_Msg_NE |
| 6514 |
(Msg => "call to & during elaboration", |
| 6515 |
N => Call, |
| 6516 |
Id => Subp_Id, |
| 6517 |
Info_Msg => Info_Msg, |
| 6518 |
In_SPARK => In_SPARK); |
| 6519 |
end Info_Simple_Call; |
| 6520 |
|
| 6521 |
----------------------- |
| 6522 |
-- Info_Type_Actions -- |
| 6523 |
----------------------- |
| 6524 |
|
| 6525 |
procedure Info_Type_Actions (Action : String) is |
| 6526 |
Typ : constant Entity_Id := First_Formal_Type (Subp_Id); |
| 6527 |
pragma Assert (Present (Typ)); |
| 6528 |
|
| 6529 |
begin |
| 6530 |
Elab_Msg_NE |
| 6531 |
(Msg => Action & " actions for type & during elaboration", |
| 6532 |
N => Call, |
| 6533 |
Id => Typ, |
| 6534 |
Info_Msg => Info_Msg, |
| 6535 |
In_SPARK => In_SPARK); |
| 6536 |
end Info_Type_Actions; |
| 6537 |
|
| 6538 |
---------------------------- |
| 6539 |
-- Info_Verification_Call -- |
| 6540 |
---------------------------- |
| 6541 |
|
| 6542 |
procedure Info_Verification_Call |
| 6543 |
(Pred : String; |
| 6544 |
Id : Entity_Id; |
| 6545 |
Id_Kind : String) |
| 6546 |
is |
| 6547 |
pragma Assert (Present (Id)); |
| 6548 |
|
| 6549 |
begin |
| 6550 |
Elab_Msg_NE |
| 6551 |
(Msg => |
| 6552 |
"verification of " & Pred & " of " & Id_Kind & " & during " |
| 6553 |
& "elaboration", |
| 6554 |
N => Call, |
| 6555 |
Id => Id, |
| 6556 |
Info_Msg => Info_Msg, |
| 6557 |
In_SPARK => In_SPARK); |
| 6558 |
end Info_Verification_Call; |
| 6559 |
|
| 6560 |
-- Start of processing for Info_Call |
| 6561 |
|
| 6562 |
begin |
| 6563 |
-- Do not output anything for targets defined in internal units |
| 6564 |
-- because this creates noise. |
| 6565 |
|
| 6566 |
if not In_Internal_Unit (Subp_Id) then |
| 6567 |
|
| 6568 |
-- Accept alternative |
| 6569 |
|
| 6570 |
if Is_Accept_Alternative_Proc (Subp_Id) then |
| 6571 |
Info_Accept_Alternative; |
| 6572 |
|
| 6573 |
-- Adjustment |
| 6574 |
|
| 6575 |
elsif Is_TSS (Subp_Id, TSS_Deep_Adjust) then |
| 6576 |
Info_Type_Actions ("adjustment"); |
| 6577 |
|
| 6578 |
-- Default_Initial_Condition |
| 6579 |
|
| 6580 |
elsif Is_Default_Initial_Condition_Proc (Subp_Id) then |
| 6581 |
Info_Verification_Call |
| 6582 |
(Pred => "Default_Initial_Condition", |
| 6583 |
Id => First_Formal_Type (Subp_Id), |
| 6584 |
Id_Kind => "type"); |
| 6585 |
|
| 6586 |
-- Entries |
| 6587 |
|
| 6588 |
elsif Is_Protected_Entry (Subp_Id) then |
| 6589 |
Info_Simple_Call; |
| 6590 |
|
| 6591 |
-- Task entry calls are never processed because the entry being |
| 6592 |
-- invoked does not have a corresponding "body", it has a select. |
| 6593 |
|
| 6594 |
elsif Is_Task_Entry (Subp_Id) then |
| 6595 |
null; |
| 6596 |
|
| 6597 |
-- Finalization |
| 6598 |
|
| 6599 |
elsif Is_TSS (Subp_Id, TSS_Deep_Finalize) then |
| 6600 |
Info_Type_Actions ("finalization"); |
| 6601 |
|
| 6602 |
-- Calls to _Finalizer procedures must not appear in the output |
| 6603 |
-- because this creates confusing noise. |
| 6604 |
|
| 6605 |
elsif Is_Finalizer (Subp_Id) then |
| 6606 |
null; |
| 6607 |
|
| 6608 |
-- Initial_Condition |
| 6609 |
|
| 6610 |
elsif Is_Initial_Condition_Proc (Subp_Id) then |
| 6611 |
Info_Verification_Call |
| 6612 |
(Pred => "Initial_Condition", |
| 6613 |
Id => Find_Enclosing_Scope (Call), |
| 6614 |
Id_Kind => "package"); |
| 6615 |
|
| 6616 |
-- Initialization |
| 6617 |
|
| 6618 |
elsif Is_Init_Proc (Subp_Id) |
| 6619 |
or else Is_TSS (Subp_Id, TSS_Deep_Initialize) |
| 6620 |
then |
| 6621 |
Info_Type_Actions ("initialization"); |
| 6622 |
|
| 6623 |
-- Invariant |
| 6624 |
|
| 6625 |
elsif Is_Invariant_Proc (Subp_Id) then |
| 6626 |
Info_Verification_Call |
| 6627 |
(Pred => "invariants", |
| 6628 |
Id => First_Formal_Type (Subp_Id), |
| 6629 |
Id_Kind => "type"); |
| 6630 |
|
| 6631 |
-- Partial invariant calls must not appear in the output because |
| 6632 |
-- this creates confusing noise. |
| 6633 |
|
| 6634 |
elsif Is_Partial_Invariant_Proc (Subp_Id) then |
| 6635 |
null; |
| 6636 |
|
| 6637 |
-- Subprograms must come last because some of the previous cases |
| 6638 |
-- fall under this category. |
| 6639 |
|
| 6640 |
elsif Ekind (Subp_Id) = E_Function then |
| 6641 |
Info_Simple_Call; |
| 6642 |
|
| 6643 |
elsif Ekind (Subp_Id) = E_Procedure then |
| 6644 |
Info_Simple_Call; |
| 6645 |
|
| 6646 |
else |
| 6647 |
pragma Assert (False); |
| 6648 |
return; |
| 6649 |
end if; |
| 6650 |
end if; |
| 6651 |
end Info_Call; |
| 6652 |
|
| 6653 |
------------------------ |
| 6654 |
-- Info_Instantiation -- |
| 6655 |
------------------------ |
| 6656 |
|
| 6657 |
procedure Info_Instantiation |
| 6658 |
(Inst : Node_Id; |
| 6659 |
Gen_Id : Entity_Id; |
| 6660 |
Info_Msg : Boolean; |
| 6661 |
In_SPARK : Boolean) |
| 6662 |
is |
| 6663 |
begin |
| 6664 |
Elab_Msg_NE |
| 6665 |
(Msg => "instantiation of & during elaboration", |
| 6666 |
N => Inst, |
| 6667 |
Id => Gen_Id, |
| 6668 |
Info_Msg => Info_Msg, |
| 6669 |
In_SPARK => In_SPARK); |
| 6670 |
end Info_Instantiation; |
| 6671 |
|
| 6672 |
----------------------------- |
| 6673 |
-- Info_Variable_Reference -- |
| 6674 |
----------------------------- |
| 6675 |
|
| 6676 |
procedure Info_Variable_Reference |
| 6677 |
(Ref : Node_Id; |
| 6678 |
Var_Id : Entity_Id) |
| 6679 |
is |
| 6680 |
begin |
| 6681 |
if Is_Read (Ref) then |
| 6682 |
Elab_Msg_NE |
| 6683 |
(Msg => "read of variable & during elaboration", |
| 6684 |
N => Ref, |
| 6685 |
Id => Var_Id, |
| 6686 |
Info_Msg => False, |
| 6687 |
In_SPARK => True); |
| 6688 |
end if; |
| 6689 |
end Info_Variable_Reference; |
| 6690 |
end Diagnostics; |
| 6691 |
|
| 6692 |
--------------------------------- |
| 6693 |
-- Early_Call_Region_Processor -- |
| 6694 |
--------------------------------- |
| 6695 |
|
| 6696 |
package body Early_Call_Region_Processor is |
| 6697 |
|
| 6698 |
--------------------- |
| 6699 |
-- Data structures -- |
| 6700 |
--------------------- |
| 6701 |
|
| 6702 |
-- The following map relates early call regions to subprogram bodies |
| 6703 |
|
| 6704 |
procedure Destroy (N : in out Node_Id); |
| 6705 |
-- Destroy node N |
| 6706 |
|
| 6707 |
package ECR_Map is new Dynamic_Hash_Tables |
| 6708 |
(Key_Type => Entity_Id, |
| 6709 |
Value_Type => Node_Id, |
| 6710 |
No_Value => Empty, |
| 6711 |
Expansion_Threshold => 1.5, |
| 6712 |
Expansion_Factor => 2, |
| 6713 |
Compression_Threshold => 0.3, |
| 6714 |
Compression_Factor => 2, |
| 6715 |
"=" => "=", |
| 6716 |
Destroy_Value => Destroy, |
| 6717 |
Hash => Hash); |
| 6718 |
|
| 6719 |
Early_Call_Regions_Map : ECR_Map.Dynamic_Hash_Table := ECR_Map.Nil; |
| 6720 |
|
| 6721 |
----------------------- |
| 6722 |
-- Local subprograms -- |
| 6723 |
----------------------- |
| 6724 |
|
| 6725 |
function Early_Call_Region (Body_Id : Entity_Id) return Node_Id; |
| 6726 |
pragma Inline (Early_Call_Region); |
| 6727 |
-- Obtain the early call region associated with entry or subprogram body |
| 6728 |
-- Body_Id. |
| 6729 |
|
| 6730 |
procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id); |
| 6731 |
pragma Inline (Set_Early_Call_Region); |
| 6732 |
-- Associate an early call region with begins at construct Start with |
| 6733 |
-- entry or subprogram body Body_Id. |
| 6734 |
|
| 6735 |
------------- |
| 6736 |
-- Destroy -- |
| 6737 |
------------- |
| 6738 |
|
| 6739 |
procedure Destroy (N : in out Node_Id) is |
| 6740 |
pragma Unreferenced (N); |
| 6741 |
begin |
| 6742 |
null; |
| 6743 |
end Destroy; |
| 6744 |
|
| 6745 |
----------------------- |
| 6746 |
-- Early_Call_Region -- |
| 6747 |
----------------------- |
| 6748 |
|
| 6749 |
function Early_Call_Region (Body_Id : Entity_Id) return Node_Id is |
| 6750 |
pragma Assert (Present (Body_Id)); |
| 6751 |
begin |
| 6752 |
return ECR_Map.Get (Early_Call_Regions_Map, Body_Id); |
| 6753 |
end Early_Call_Region; |
| 6754 |
|
| 6755 |
------------------------------------------ |
| 6756 |
-- Finalize_Early_Call_Region_Processor -- |
| 6757 |
------------------------------------------ |
| 6758 |
|
| 6759 |
procedure Finalize_Early_Call_Region_Processor is |
| 6760 |
begin |
| 6761 |
ECR_Map.Destroy (Early_Call_Regions_Map); |
| 6762 |
end Finalize_Early_Call_Region_Processor; |
| 6763 |
|
| 6764 |
---------------------------- |
| 6765 |
-- Find_Early_Call_Region -- |
| 6766 |
---------------------------- |
| 6767 |
|
| 6768 |
function Find_Early_Call_Region |
| 6769 |
(Body_Decl : Node_Id; |
| 6770 |
Assume_Elab_Body : Boolean := False; |
| 6771 |
Skip_Memoization : Boolean := False) return Node_Id |
| 6772 |
is |
| 6773 |
-- NOTE: The routines within Find_Early_Call_Region are intentionally |
| 6774 |
-- unnested to avoid deep indentation of code. |
| 6775 |
|
| 6776 |
ECR_Found : exception; |
| 6777 |
-- This exception is raised when the early call region has been found |
| 6778 |
|
| 6779 |
Start : Node_Id := Empty; |
| 6780 |
-- The start of the early call region. This variable is updated by |
| 6781 |
-- the various nested routines. Due to the use of exceptions, the |
| 6782 |
-- variable must be global to the nested routines. |
| 6783 |
|
| 6784 |
-- The algorithm implemented in this routine attempts to find the |
| 6785 |
-- early call region of a subprogram body by inspecting constructs |
| 6786 |
-- in reverse declarative order, while navigating the tree. The |
| 6787 |
-- algorithm consists of an Inspection phase and Advancement phase. |
| 6788 |
-- The pseudocode is as follows: |
| 6789 |
-- |
| 6790 |
-- loop |
| 6791 |
-- inspection phase |
| 6792 |
-- advancement phase |
| 6793 |
-- end loop |
| 6794 |
-- |
| 6795 |
-- The infinite loop is terminated by raising exception ECR_Found. |
| 6796 |
-- The algorithm utilizes two pointers, Curr and Start, to represent |
| 6797 |
-- the current construct to inspect and the start of the early call |
| 6798 |
-- region. |
| 6799 |
-- |
| 6800 |
-- IMPORTANT: The algorithm must maintain the following invariant at |
| 6801 |
-- all time for it to function properly: |
| 6802 |
-- |
| 6803 |
-- A nested construct is entered only when it contains suitable |
| 6804 |
-- constructs. |
| 6805 |
-- |
| 6806 |
-- This guarantees that leaving a nested or encapsulating construct |
| 6807 |
-- functions properly. |
| 6808 |
-- |
| 6809 |
-- The Inspection phase determines whether the current construct is |
| 6810 |
-- non-preelaborable, and if it is, the algorithm terminates. |
| 6811 |
-- |
| 6812 |
-- The Advancement phase walks the tree in reverse declarative order, |
| 6813 |
-- while entering and leaving nested and encapsulating constructs. It |
| 6814 |
-- may also terminate the elaborithm. There are several special cases |
| 6815 |
-- of advancement. |
| 6816 |
-- |
| 6817 |
-- 1) General case: |
| 6818 |
-- |
| 6819 |
-- <construct 1> |
| 6820 |
-- ... |
| 6821 |
-- <construct N-1> <- Curr |
| 6822 |
-- <construct N> <- Start |
| 6823 |
-- <subprogram body> |
| 6824 |
-- |
| 6825 |
-- In the general case, a declarative or statement list is traversed |
| 6826 |
-- in reverse order where Curr is the lead pointer, and Start is the |
| 6827 |
-- last preelaborable construct. |
| 6828 |
-- |
| 6829 |
-- 2) Entering handled bodies |
| 6830 |
-- |
| 6831 |
-- package body Nested is <- Curr (2.3) |
| 6832 |
-- <declarations> <- Curr (2.2) |
| 6833 |
-- begin |
| 6834 |
-- <statements> <- Curr (2.1) |
| 6835 |
-- end Nested; |
| 6836 |
-- <construct> <- Start |
| 6837 |
-- |
| 6838 |
-- In this case, the algorithm enters a handled body by starting from |
| 6839 |
-- the last statement (2.1), or the last declaration (2.2), or the |
| 6840 |
-- body is consumed (2.3) because it is empty and thus preelaborable. |
| 6841 |
-- |
| 6842 |
-- 3) Entering package declarations |
| 6843 |
-- |
| 6844 |
-- package Nested is <- Curr (2.3) |
| 6845 |
-- <visible declarations> <- Curr (2.2) |
| 6846 |
-- private |
| 6847 |
-- <private declarations> <- Curr (2.1) |
| 6848 |
-- end Nested; |
| 6849 |
-- <construct> <- Start |
| 6850 |
-- |
| 6851 |
-- In this case, the algorithm enters a package declaration by |
| 6852 |
-- starting from the last private declaration (2.1), the last visible |
| 6853 |
-- declaration (2.2), or the package is consumed (2.3) because it is |
| 6854 |
-- empty and thus preelaborable. |
| 6855 |
-- |
| 6856 |
-- 4) Transitioning from list to list of the same construct |
| 6857 |
-- |
| 6858 |
-- Certain constructs have two eligible lists. The algorithm must |
| 6859 |
-- thus transition from the second to the first list when the second |
| 6860 |
-- list is exhausted. |
| 6861 |
-- |
| 6862 |
-- declare <- Curr (4.2) |
| 6863 |
-- <declarations> <- Curr (4.1) |
| 6864 |
-- begin |
| 6865 |
-- <statements> <- Start |
| 6866 |
-- end; |
| 6867 |
-- |
| 6868 |
-- In this case, the algorithm has exhausted the second list (the |
| 6869 |
-- statements in the example above), and continues with the last |
| 6870 |
-- declaration (4.1) or the construct is consumed (4.2) because it |
| 6871 |
-- contains only preelaborable code. |
| 6872 |
-- |
| 6873 |
-- 5) Transitioning from list to construct |
| 6874 |
-- |
| 6875 |
-- tack body Task is <- Curr (5.1) |
| 6876 |
-- <- Curr (Empty) |
| 6877 |
-- <construct 1> <- Start |
| 6878 |
-- |
| 6879 |
-- In this case, the algorithm has exhausted a list, Curr is Empty, |
| 6880 |
-- and the owner of the list is consumed (5.1). |
| 6881 |
-- |
| 6882 |
-- 6) Transitioning from unit to unit |
| 6883 |
-- |
| 6884 |
-- A package body with a spec subject to pragma Elaborate_Body |
| 6885 |
-- extends the possible range of the early call region to the package |
| 6886 |
-- spec. |
| 6887 |
-- |
| 6888 |
-- package Pack is <- Curr (6.3) |
| 6889 |
-- pragma Elaborate_Body; <- Curr (6.2) |
| 6890 |
-- <visible declarations> <- Curr (6.2) |
| 6891 |
-- private |
| 6892 |
-- <private declarations> <- Curr (6.1) |
| 6893 |
-- end Pack; |
| 6894 |
-- |
| 6895 |
-- package body Pack is <- Curr, Start |
| 6896 |
-- |
| 6897 |
-- In this case, the algorithm has reached a package body compilation |
| 6898 |
-- unit whose spec is subject to pragma Elaborate_Body, or the caller |
| 6899 |
-- of the algorithm has specified this behavior. This transition is |
| 6900 |
-- equivalent to 3). |
| 6901 |
-- |
| 6902 |
-- 7) Transitioning from unit to termination |
| 6903 |
-- |
| 6904 |
-- Reaching a compilation unit always terminates the algorithm as |
| 6905 |
-- there are no more lists to examine. This must take case 6) into |
| 6906 |
-- account. |
| 6907 |
-- |
| 6908 |
-- 8) Transitioning from subunit to stub |
| 6909 |
-- |
| 6910 |
-- package body Pack is separate; <- Curr (8.1) |
| 6911 |
-- |
| 6912 |
-- separate (...) |
| 6913 |
-- package body Pack is <- Curr, Start |
| 6914 |
-- |
| 6915 |
-- Reaching a subunit continues the search from the corresponding |
| 6916 |
-- stub (8.1). |
| 6917 |
|
| 6918 |
procedure Advance (Curr : in out Node_Id); |
| 6919 |
pragma Inline (Advance); |
| 6920 |
-- Update the Curr and Start pointers depending on their location |
| 6921 |
-- in the tree to the next eligible construct. This routine raises |
| 6922 |
-- ECR_Found. |
| 6923 |
|
| 6924 |
procedure Enter_Handled_Body (Curr : in out Node_Id); |
| 6925 |
pragma Inline (Enter_Handled_Body); |
| 6926 |
-- Update the Curr and Start pointers to enter a nested handled body |
| 6927 |
-- if applicable. This routine raises ECR_Found. |
| 6928 |
|
| 6929 |
procedure Enter_Package_Declaration (Curr : in out Node_Id); |
| 6930 |
pragma Inline (Enter_Package_Declaration); |
| 6931 |
-- Update the Curr and Start pointers to enter a nested package spec |
| 6932 |
-- if applicable. This routine raises ECR_Found. |
| 6933 |
|
| 6934 |
function Find_ECR (N : Node_Id) return Node_Id; |
| 6935 |
pragma Inline (Find_ECR); |
| 6936 |
-- Find an early call region starting from arbitrary node N |
| 6937 |
|
| 6938 |
function Has_Suitable_Construct (List : List_Id) return Boolean; |
| 6939 |
pragma Inline (Has_Suitable_Construct); |
| 6940 |
-- Determine whether list List contains a suitable construct for |
| 6941 |
-- inclusion into an early call region. |
| 6942 |
|
| 6943 |
procedure Include (N : Node_Id; Curr : out Node_Id); |
| 6944 |
pragma Inline (Include); |
| 6945 |
-- Update the Curr and Start pointers to include arbitrary construct |
| 6946 |
-- N in the early call region. This routine raises ECR_Found. |
| 6947 |
|
| 6948 |
function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean; |
| 6949 |
pragma Inline (Is_OK_Preelaborable_Construct); |
| 6950 |
-- Determine whether arbitrary node N denotes a preelaboration-safe |
| 6951 |
-- construct. |
| 6952 |
|
| 6953 |
function Is_Suitable_Construct (N : Node_Id) return Boolean; |
| 6954 |
pragma Inline (Is_Suitable_Construct); |
| 6955 |
-- Determine whether arbitrary node N denotes a suitable construct |
| 6956 |
-- for inclusion into the early call region. |
| 6957 |
|
| 6958 |
function Previous_Suitable_Construct (N : Node_Id) return Node_Id; |
| 6959 |
pragma Inline (Previous_Suitable_Construct); |
| 6960 |
-- Return the previous node suitable for inclusion into the early |
| 6961 |
-- call region. |
| 6962 |
|
| 6963 |
procedure Transition_Body_Declarations |
| 6964 |
(Bod : Node_Id; |
| 6965 |
Curr : out Node_Id); |
| 6966 |
pragma Inline (Transition_Body_Declarations); |
| 6967 |
-- Update the Curr and Start pointers when construct Bod denotes a |
| 6968 |
-- block statement or a suitable body. This routine raises ECR_Found. |
| 6969 |
|
| 6970 |
procedure Transition_Handled_Statements |
| 6971 |
(HSS : Node_Id; |
| 6972 |
Curr : out Node_Id); |
| 6973 |
pragma Inline (Transition_Handled_Statements); |
| 6974 |
-- Update the Curr and Start pointers when node HSS denotes a handled |
| 6975 |
-- sequence of statements. This routine raises ECR_Found. |
| 6976 |
|
| 6977 |
procedure Transition_Spec_Declarations |
| 6978 |
(Spec : Node_Id; |
| 6979 |
Curr : out Node_Id); |
| 6980 |
pragma Inline (Transition_Spec_Declarations); |
| 6981 |
-- Update the Curr and Start pointers when construct Spec denotes |
| 6982 |
-- a concurrent definition or a package spec. This routine raises |
| 6983 |
-- ECR_Found. |
| 6984 |
|
| 6985 |
procedure Transition_Unit (Unit : Node_Id; Curr : out Node_Id); |
| 6986 |
pragma Inline (Transition_Unit); |
| 6987 |
-- Update the Curr and Start pointers when node Unit denotes a |
| 6988 |
-- potential compilation unit. This routine raises ECR_Found. |
| 6989 |
|
| 6990 |
------------- |
| 6991 |
-- Advance -- |
| 6992 |
------------- |
| 6993 |
|
| 6994 |
procedure Advance (Curr : in out Node_Id) is |
| 6995 |
Context : Node_Id; |
| 6996 |
|
| 6997 |
begin |
| 6998 |
-- Curr denotes one of the following cases upon entry into this |
| 6999 |
-- routine: |
| 7000 |
-- |
| 7001 |
-- * Empty - There is no current construct when a declarative or |
| 7002 |
-- a statement list has been exhausted. This does not indicate |
| 7003 |
-- that the early call region has been computed as it is still |
| 7004 |
-- possible to transition to another list. |
| 7005 |
-- |
| 7006 |
-- * Encapsulator - The current construct wraps declarations |
| 7007 |
-- and/or statements. This indicates that the early call |
| 7008 |
-- region may extend within the nested construct. |
| 7009 |
-- |
| 7010 |
-- * Preelaborable - The current construct is preelaborable |
| 7011 |
-- because Find_ECR would not invoke Advance if this was not |
| 7012 |
-- the case. |
| 7013 |
|
| 7014 |
-- The current construct is an encapsulator or is preelaborable |
| 7015 |
|
| 7016 |
if Present (Curr) then |
| 7017 |
|
| 7018 |
-- Enter encapsulators by inspecting their declarations and/or |
| 7019 |
-- statements. |
| 7020 |
|
| 7021 |
if Nkind (Curr) in N_Block_Statement | N_Package_Body then |
| 7022 |
Enter_Handled_Body (Curr); |
| 7023 |
|
| 7024 |
elsif Nkind (Curr) = N_Package_Declaration then |
| 7025 |
Enter_Package_Declaration (Curr); |
| 7026 |
|
| 7027 |
-- Early call regions have a property which can be exploited to |
| 7028 |
-- optimize the algorithm. |
| 7029 |
-- |
| 7030 |
-- <preceding subprogram body> |
| 7031 |
-- <preelaborable construct 1> |
| 7032 |
-- ... |
| 7033 |
-- <preelaborable construct N> |
| 7034 |
-- <initiating subprogram body> |
| 7035 |
-- |
| 7036 |
-- If a traversal initiated from a subprogram body reaches a |
| 7037 |
-- preceding subprogram body, then both bodies share the same |
| 7038 |
-- early call region. |
| 7039 |
-- |
| 7040 |
-- The property results in the following desirable effects: |
| 7041 |
-- |
| 7042 |
-- * If the preceding body already has an early call region, |
| 7043 |
-- then the initiating body can reuse it. This minimizes the |
| 7044 |
-- amount of processing performed by the algorithm. |
| 7045 |
-- |
| 7046 |
-- * If the preceding body lack an early call region, then the |
| 7047 |
-- algorithm can compute the early call region, and reuse it |
| 7048 |
-- for the initiating body. This processing performs the same |
| 7049 |
-- amount of work, but has the beneficial effect of computing |
| 7050 |
-- the early call regions of all preceding bodies. |
| 7051 |
|
| 7052 |
elsif Nkind (Curr) in N_Entry_Body | N_Subprogram_Body then |
| 7053 |
Start := |
| 7054 |
Find_Early_Call_Region |
| 7055 |
(Body_Decl => Curr, |
| 7056 |
Assume_Elab_Body => Assume_Elab_Body, |
| 7057 |
Skip_Memoization => Skip_Memoization); |
| 7058 |
|
| 7059 |
raise ECR_Found; |
| 7060 |
|
| 7061 |
-- Otherwise current construct is preelaborable. Unpdate the |
| 7062 |
-- early call region to include it. |
| 7063 |
|
| 7064 |
else |
| 7065 |
Include (Curr, Curr); |
| 7066 |
end if; |
| 7067 |
|
| 7068 |
-- Otherwise the current construct is missing, indicating that the |
| 7069 |
-- current list has been exhausted. Depending on the context of |
| 7070 |
-- the list, several transitions are possible. |
| 7071 |
|
| 7072 |
else |
| 7073 |
-- The invariant of the algorithm ensures that Curr and Start |
| 7074 |
-- are at the same level of nesting at the point of transition. |
| 7075 |
-- The algorithm can determine which list the traversal came |
| 7076 |
-- from by examining Start. |
| 7077 |
|
| 7078 |
Context := Parent (Start); |
| 7079 |
|
| 7080 |
-- Attempt the following transitions: |
| 7081 |
-- |
| 7082 |
-- private declarations -> visible declarations |
| 7083 |
-- private declarations -> upper level |
| 7084 |
-- private declarations -> terminate |
| 7085 |
-- visible declarations -> upper level |
| 7086 |
-- visible declarations -> terminate |
| 7087 |
|
| 7088 |
if Nkind (Context) in N_Package_Specification |
| 7089 |
| N_Protected_Definition |
| 7090 |
| N_Task_Definition |
| 7091 |
then |
| 7092 |
Transition_Spec_Declarations (Context, Curr); |
| 7093 |
|
| 7094 |
-- Attempt the following transitions: |
| 7095 |
-- |
| 7096 |
-- statements -> declarations |
| 7097 |
-- statements -> upper level |
| 7098 |
-- statements -> corresponding package spec (Elab_Body) |
| 7099 |
-- statements -> terminate |
| 7100 |
|
| 7101 |
elsif Nkind (Context) = N_Handled_Sequence_Of_Statements then |
| 7102 |
Transition_Handled_Statements (Context, Curr); |
| 7103 |
|
| 7104 |
-- Attempt the following transitions: |
| 7105 |
-- |
| 7106 |
-- declarations -> upper level |
| 7107 |
-- declarations -> corresponding package spec (Elab_Body) |
| 7108 |
-- declarations -> terminate |
| 7109 |
|
| 7110 |
elsif Nkind (Context) in N_Block_Statement |
| 7111 |
| N_Entry_Body |
| 7112 |
| N_Package_Body |
| 7113 |
| N_Protected_Body |
| 7114 |
| N_Subprogram_Body |
| 7115 |
| N_Task_Body |
| 7116 |
then |
| 7117 |
Transition_Body_Declarations (Context, Curr); |
| 7118 |
|
| 7119 |
-- Otherwise it is not possible to transition. Stop the search |
| 7120 |
-- because there are no more declarations or statements to |
| 7121 |
-- check. |
| 7122 |
|
| 7123 |
else |
| 7124 |
raise ECR_Found; |
| 7125 |
end if; |
| 7126 |
end if; |
| 7127 |
end Advance; |
| 7128 |
|
| 7129 |
-------------------------- |
| 7130 |
-- Enter_Handled_Body -- |
| 7131 |
-------------------------- |
| 7132 |
|
| 7133 |
procedure Enter_Handled_Body (Curr : in out Node_Id) is |
| 7134 |
Decls : constant List_Id := Declarations (Curr); |
| 7135 |
HSS : constant Node_Id := Handled_Statement_Sequence (Curr); |
| 7136 |
Stmts : List_Id := No_List; |
| 7137 |
|
| 7138 |
begin |
| 7139 |
if Present (HSS) then |
| 7140 |
Stmts := Statements (HSS); |
| 7141 |
end if; |
| 7142 |
|
| 7143 |
-- The handled body has a non-empty statement sequence. The |
| 7144 |
-- construct to inspect is the last statement. |
| 7145 |
|
| 7146 |
if Has_Suitable_Construct (Stmts) then |
| 7147 |
Curr := Last (Stmts); |
| 7148 |
|
| 7149 |
-- The handled body lacks statements, but has non-empty |
| 7150 |
-- declarations. The construct to inspect is the last declaration. |
| 7151 |
|
| 7152 |
elsif Has_Suitable_Construct (Decls) then |
| 7153 |
Curr := Last (Decls); |
| 7154 |
|
| 7155 |
-- Otherwise the handled body lacks both declarations and |
| 7156 |
-- statements. The construct to inspect is the node which precedes |
| 7157 |
-- the handled body. Update the early call region to include the |
| 7158 |
-- handled body. |
| 7159 |
|
| 7160 |
else |
| 7161 |
Include (Curr, Curr); |
| 7162 |
end if; |
| 7163 |
end Enter_Handled_Body; |
| 7164 |
|
| 7165 |
------------------------------- |
| 7166 |
-- Enter_Package_Declaration -- |
| 7167 |
------------------------------- |
| 7168 |
|
| 7169 |
procedure Enter_Package_Declaration (Curr : in out Node_Id) is |
| 7170 |
Pack_Spec : constant Node_Id := Specification (Curr); |
| 7171 |
Prv_Decls : constant List_Id := Private_Declarations (Pack_Spec); |
| 7172 |
Vis_Decls : constant List_Id := Visible_Declarations (Pack_Spec); |
| 7173 |
|
| 7174 |
begin |
| 7175 |
-- The package has a non-empty private declarations. The construct |
| 7176 |
-- to inspect is the last private declaration. |
| 7177 |
|
| 7178 |
if Has_Suitable_Construct (Prv_Decls) then |
| 7179 |
Curr := Last (Prv_Decls); |
| 7180 |
|
| 7181 |
-- The package lacks private declarations, but has non-empty |
| 7182 |
-- visible declarations. In this case the construct to inspect |
| 7183 |
-- is the last visible declaration. |
| 7184 |
|
| 7185 |
elsif Has_Suitable_Construct (Vis_Decls) then |
| 7186 |
Curr := Last (Vis_Decls); |
| 7187 |
|
| 7188 |
-- Otherwise the package lacks any declarations. The construct |
| 7189 |
-- to inspect is the node which precedes the package. Update the |
| 7190 |
-- early call region to include the package declaration. |
| 7191 |
|
| 7192 |
else |
| 7193 |
Include (Curr, Curr); |
| 7194 |
end if; |
| 7195 |
end Enter_Package_Declaration; |
| 7196 |
|
| 7197 |
-------------- |
| 7198 |
-- Find_ECR -- |
| 7199 |
-------------- |
| 7200 |
|
| 7201 |
function Find_ECR (N : Node_Id) return Node_Id is |
| 7202 |
Curr : Node_Id; |
| 7203 |
|
| 7204 |
begin |
| 7205 |
-- The early call region starts at N |
| 7206 |
|
| 7207 |
Curr := Previous_Suitable_Construct (N); |
| 7208 |
Start := N; |
| 7209 |
|
| 7210 |
-- Inspect each node in reverse declarative order while going in |
| 7211 |
-- and out of nested and enclosing constructs. Note that the only |
| 7212 |
-- way to terminate this infinite loop is to raise ECR_Found. |
| 7213 |
|
| 7214 |
loop |
| 7215 |
-- The current construct is not preelaboration-safe. Terminate |
| 7216 |
-- the traversal. |
| 7217 |
|
| 7218 |
if Present (Curr) |
| 7219 |
and then not Is_OK_Preelaborable_Construct (Curr) |
| 7220 |
then |
| 7221 |
raise ECR_Found; |
| 7222 |
end if; |
| 7223 |
|
| 7224 |
-- Advance to the next suitable construct. This may terminate |
| 7225 |
-- the traversal by raising ECR_Found. |
| 7226 |
|
| 7227 |
Advance (Curr); |
| 7228 |
end loop; |
| 7229 |
|
| 7230 |
exception |
| 7231 |
when ECR_Found => |
| 7232 |
return Start; |
| 7233 |
end Find_ECR; |
| 7234 |
|
| 7235 |
---------------------------- |
| 7236 |
-- Has_Suitable_Construct -- |
| 7237 |
---------------------------- |
| 7238 |
|
| 7239 |
function Has_Suitable_Construct (List : List_Id) return Boolean is |
| 7240 |
Item : Node_Id; |
| 7241 |
|
| 7242 |
begin |
| 7243 |
-- Examine the list in reverse declarative order, looking for a |
| 7244 |
-- suitable construct. |
| 7245 |
|
| 7246 |
if Present (List) then |
| 7247 |
Item := Last (List); |
| 7248 |
while Present (Item) loop |
| 7249 |
if Is_Suitable_Construct (Item) then |
| 7250 |
return True; |
| 7251 |
end if; |
| 7252 |
|
| 7253 |
Prev (Item); |
| 7254 |
end loop; |
| 7255 |
end if; |
| 7256 |
|
| 7257 |
return False; |
| 7258 |
end Has_Suitable_Construct; |
| 7259 |
|
| 7260 |
------------- |
| 7261 |
-- Include -- |
| 7262 |
------------- |
| 7263 |
|
| 7264 |
procedure Include (N : Node_Id; Curr : out Node_Id) is |
| 7265 |
begin |
| 7266 |
Start := N; |
| 7267 |
|
| 7268 |
-- The input node is a compilation unit. This terminates the |
| 7269 |
-- search because there are no more lists to inspect and there are |
| 7270 |
-- no more enclosing constructs to climb up to. The transitions |
| 7271 |
-- are: |
| 7272 |
-- |
| 7273 |
-- private declarations -> terminate |
| 7274 |
-- visible declarations -> terminate |
| 7275 |
-- statements -> terminate |
| 7276 |
-- declarations -> terminate |
| 7277 |
|
| 7278 |
if Nkind (Parent (Start)) = N_Compilation_Unit then |
| 7279 |
raise ECR_Found; |
| 7280 |
|
| 7281 |
-- Otherwise the input node is still within some list |
| 7282 |
|
| 7283 |
else |
| 7284 |
Curr := Previous_Suitable_Construct (Start); |
| 7285 |
end if; |
| 7286 |
end Include; |
| 7287 |
|
| 7288 |
----------------------------------- |
| 7289 |
-- Is_OK_Preelaborable_Construct -- |
| 7290 |
----------------------------------- |
| 7291 |
|
| 7292 |
function Is_OK_Preelaborable_Construct (N : Node_Id) return Boolean is |
| 7293 |
begin |
| 7294 |
-- Assignment statements are acceptable as long as they were |
| 7295 |
-- produced by the ABE mechanism to update elaboration flags. |
| 7296 |
|
| 7297 |
if Nkind (N) = N_Assignment_Statement then |
| 7298 |
return Is_Elaboration_Code (N); |
| 7299 |
|
| 7300 |
-- Block statements are acceptable even though they directly |
| 7301 |
-- violate preelaborability. The intention is not to penalize |
| 7302 |
-- the early call region when a block contains only preelaborable |
| 7303 |
-- constructs. |
| 7304 |
-- |
| 7305 |
-- declare |
| 7306 |
-- Val : constant Integer := 1; |
| 7307 |
-- begin |
| 7308 |
-- pragma Assert (Val = 1); |
| 7309 |
-- null; |
| 7310 |
-- end; |
| 7311 |
-- |
| 7312 |
-- Note that the Advancement phase does enter blocks, and will |
| 7313 |
-- detect any non-preelaborable declarations or statements within. |
| 7314 |
|
| 7315 |
elsif Nkind (N) = N_Block_Statement then |
| 7316 |
return True; |
| 7317 |
end if; |
| 7318 |
|
| 7319 |
-- Otherwise the construct must be preelaborable. The check must |
| 7320 |
-- take the syntactic and semantic structure of the construct. DO |
| 7321 |
-- NOT use Is_Preelaborable_Construct here. |
| 7322 |
|
| 7323 |
return not Is_Non_Preelaborable_Construct (N); |
| 7324 |
end Is_OK_Preelaborable_Construct; |
| 7325 |
|
| 7326 |
--------------------------- |
| 7327 |
-- Is_Suitable_Construct -- |
| 7328 |
--------------------------- |
| 7329 |
|
| 7330 |
function Is_Suitable_Construct (N : Node_Id) return Boolean is |
| 7331 |
Context : constant Node_Id := Parent (N); |
| 7332 |
|
| 7333 |
begin |
| 7334 |
-- An internally-generated statement sequence which contains only |
| 7335 |
-- a single null statement is not a suitable construct because it |
| 7336 |
-- is a byproduct of the parser. Such a null statement should be |
| 7337 |
-- excluded from the early call region because it carries the |
| 7338 |
-- source location of the "end" keyword, and may lead to confusing |
| 7339 |
-- diagnostics. |
| 7340 |
|
| 7341 |
if Nkind (N) = N_Null_Statement |
| 7342 |
and then not Comes_From_Source (N) |
| 7343 |
and then Present (Context) |
| 7344 |
and then Nkind (Context) = N_Handled_Sequence_Of_Statements |
| 7345 |
then |
| 7346 |
return False; |
| 7347 |
|
| 7348 |
-- Similarly, internally-generated objects and types may have |
| 7349 |
-- out-of-order source locations that confuse diagnostics, e.g. |
| 7350 |
-- source locations in the body for objects/types generated in |
| 7351 |
-- the spec. |
| 7352 |
|
| 7353 |
elsif Nkind (N) in N_Full_Type_Declaration | N_Object_Declaration |
| 7354 |
and then not Comes_From_Source (N) |
| 7355 |
then |
| 7356 |
return False; |
| 7357 |
end if; |
| 7358 |
|
| 7359 |
-- Otherwise only constructs which correspond to pure Ada |
| 7360 |
-- constructs are considered suitable. |
| 7361 |
|
| 7362 |
case Nkind (N) is |
| 7363 |
when N_Call_Marker |
| 7364 |
| N_Freeze_Entity |
| 7365 |
| N_Freeze_Generic_Entity |
| 7366 |
| N_Implicit_Label_Declaration |
| 7367 |
| N_Itype_Reference |
| 7368 |
| N_Pop_Constraint_Error_Label |
| 7369 |
| N_Pop_Program_Error_Label |
| 7370 |
| N_Pop_Storage_Error_Label |
| 7371 |
| N_Push_Constraint_Error_Label |
| 7372 |
| N_Push_Program_Error_Label |
| 7373 |
| N_Push_Storage_Error_Label |
| 7374 |
| N_SCIL_Dispatch_Table_Tag_Init |
| 7375 |
| N_SCIL_Dispatching_Call |
| 7376 |
| N_SCIL_Membership_Test |
| 7377 |
| N_Variable_Reference_Marker |
| 7378 |
=> |
| 7379 |
return False; |
| 7380 |
|
| 7381 |
when others => |
| 7382 |
return True; |
| 7383 |
end case; |
| 7384 |
end Is_Suitable_Construct; |
| 7385 |
|
| 7386 |
--------------------------------- |
| 7387 |
-- Previous_Suitable_Construct -- |
| 7388 |
--------------------------------- |
| 7389 |
|
| 7390 |
function Previous_Suitable_Construct (N : Node_Id) return Node_Id is |
| 7391 |
P : Node_Id; |
| 7392 |
|
| 7393 |
begin |
| 7394 |
P := Prev (N); |
| 7395 |
|
| 7396 |
while Present (P) and then not Is_Suitable_Construct (P) loop |
| 7397 |
Prev (P); |
| 7398 |
end loop; |
| 7399 |
|
| 7400 |
return P; |
| 7401 |
end Previous_Suitable_Construct; |
| 7402 |
|
| 7403 |
---------------------------------- |
| 7404 |
-- Transition_Body_Declarations -- |
| 7405 |
---------------------------------- |
| 7406 |
|
| 7407 |
procedure Transition_Body_Declarations |
| 7408 |
(Bod : Node_Id; |
| 7409 |
Curr : out Node_Id) |
| 7410 |
is |
| 7411 |
Decls : constant List_Id := Declarations (Bod); |
| 7412 |
|
| 7413 |
begin |
| 7414 |
-- The search must come from the declarations of the body |
| 7415 |
|
| 7416 |
pragma Assert |
| 7417 |
(Is_Non_Empty_List (Decls) |
| 7418 |
and then List_Containing (Start) = Decls); |
| 7419 |
|
| 7420 |
-- The search finished inspecting the declarations. The construct |
| 7421 |
-- to inspect is the node which precedes the handled body, unless |
| 7422 |
-- the body is a compilation unit. The transitions are: |
| 7423 |
-- |
| 7424 |
-- declarations -> upper level |
| 7425 |
-- declarations -> corresponding package spec (Elab_Body) |
| 7426 |
-- declarations -> terminate |
| 7427 |
|
| 7428 |
Transition_Unit (Bod, Curr); |
| 7429 |
end Transition_Body_Declarations; |
| 7430 |
|
| 7431 |
----------------------------------- |
| 7432 |
-- Transition_Handled_Statements -- |
| 7433 |
----------------------------------- |
| 7434 |
|
| 7435 |
procedure Transition_Handled_Statements |
| 7436 |
(HSS : Node_Id; |
| 7437 |
Curr : out Node_Id) |
| 7438 |
is |
| 7439 |
Bod : constant Node_Id := Parent (HSS); |
| 7440 |
Decls : constant List_Id := Declarations (Bod); |
| 7441 |
Stmts : constant List_Id := Statements (HSS); |
| 7442 |
|
| 7443 |
begin |
| 7444 |
-- The search must come from the statements of certain bodies or |
| 7445 |
-- statements. |
| 7446 |
|
| 7447 |
pragma Assert |
| 7448 |
(Nkind (Bod) in |
| 7449 |
N_Block_Statement | |
| 7450 |
N_Entry_Body | |
| 7451 |
N_Package_Body | |
| 7452 |
N_Protected_Body | |
| 7453 |
N_Subprogram_Body | |
| 7454 |
N_Task_Body); |
| 7455 |
|
| 7456 |
-- The search must come from the statements of the handled |
| 7457 |
-- sequence. |
| 7458 |
|
| 7459 |
pragma Assert |
| 7460 |
(Is_Non_Empty_List (Stmts) |
| 7461 |
and then List_Containing (Start) = Stmts); |
| 7462 |
|
| 7463 |
-- The search finished inspecting the statements. The handled body |
| 7464 |
-- has non-empty declarations. The construct to inspect is the |
| 7465 |
-- last declaration. The transitions are: |
| 7466 |
-- |
| 7467 |
-- statements -> declarations |
| 7468 |
|
| 7469 |
if Has_Suitable_Construct (Decls) then |
| 7470 |
Curr := Last (Decls); |
| 7471 |
|
| 7472 |
-- Otherwise the handled body lacks declarations. The construct to |
| 7473 |
-- inspect is the node which precedes the handled body, unless the |
| 7474 |
-- body is a compilation unit. The transitions are: |
| 7475 |
-- |
| 7476 |
-- statements -> upper level |
| 7477 |
-- statements -> corresponding package spec (Elab_Body) |
| 7478 |
-- statements -> terminate |
| 7479 |
|
| 7480 |
else |
| 7481 |
Transition_Unit (Bod, Curr); |
| 7482 |
end if; |
| 7483 |
end Transition_Handled_Statements; |
| 7484 |
|
| 7485 |
---------------------------------- |
| 7486 |
-- Transition_Spec_Declarations -- |
| 7487 |
---------------------------------- |
| 7488 |
|
| 7489 |
procedure Transition_Spec_Declarations |
| 7490 |
(Spec : Node_Id; |
| 7491 |
Curr : out Node_Id) |
| 7492 |
is |
| 7493 |
Prv_Decls : constant List_Id := Private_Declarations (Spec); |
| 7494 |
Vis_Decls : constant List_Id := Visible_Declarations (Spec); |
| 7495 |
|
| 7496 |
begin |
| 7497 |
pragma Assert (Present (Start) and then Is_List_Member (Start)); |
| 7498 |
|
| 7499 |
-- The search came from the private declarations and finished |
| 7500 |
-- their inspection. |
| 7501 |
|
| 7502 |
if Has_Suitable_Construct (Prv_Decls) |
| 7503 |
and then List_Containing (Start) = Prv_Decls |
| 7504 |
then |
| 7505 |
-- The context has non-empty visible declarations. The node to |
| 7506 |
-- inspect is the last visible declaration. The transitions |
| 7507 |
-- are: |
| 7508 |
-- |
| 7509 |
-- private declarations -> visible declarations |
| 7510 |
|
| 7511 |
if Has_Suitable_Construct (Vis_Decls) then |
| 7512 |
Curr := Last (Vis_Decls); |
| 7513 |
|
| 7514 |
-- Otherwise the context lacks visible declarations. The |
| 7515 |
-- construct to inspect is the node which precedes the context |
| 7516 |
-- unless the context is a compilation unit. The transitions |
| 7517 |
-- are: |
| 7518 |
-- |
| 7519 |
-- private declarations -> upper level |
| 7520 |
-- private declarations -> terminate |
| 7521 |
|
| 7522 |
else |
| 7523 |
Transition_Unit (Parent (Spec), Curr); |
| 7524 |
end if; |
| 7525 |
|
| 7526 |
-- The search came from the visible declarations and finished |
| 7527 |
-- their inspections. The construct to inspect is the node which |
| 7528 |
-- precedes the context, unless the context is a compilaton unit. |
| 7529 |
-- The transitions are: |
| 7530 |
-- |
| 7531 |
-- visible declarations -> upper level |
| 7532 |
-- visible declarations -> terminate |
| 7533 |
|
| 7534 |
elsif Has_Suitable_Construct (Vis_Decls) |
| 7535 |
and then List_Containing (Start) = Vis_Decls |
| 7536 |
then |
| 7537 |
Transition_Unit (Parent (Spec), Curr); |
| 7538 |
|
| 7539 |
-- At this point both declarative lists are empty, but the |
| 7540 |
-- traversal still came from within the spec. This indicates |
| 7541 |
-- that the invariant of the algorithm has been violated. |
| 7542 |
|
| 7543 |
else |
| 7544 |
pragma Assert (False); |
| 7545 |
raise ECR_Found; |
| 7546 |
end if; |
| 7547 |
end Transition_Spec_Declarations; |
| 7548 |
|
| 7549 |
--------------------- |
| 7550 |
-- Transition_Unit -- |
| 7551 |
--------------------- |
| 7552 |
|
| 7553 |
procedure Transition_Unit |
| 7554 |
(Unit : Node_Id; |
| 7555 |
Curr : out Node_Id) |
| 7556 |
is |
| 7557 |
Context : constant Node_Id := Parent (Unit); |
| 7558 |
|
| 7559 |
begin |
| 7560 |
-- The unit is a compilation unit. This terminates the search |
| 7561 |
-- because there are no more lists to inspect and there are no |
| 7562 |
-- more enclosing constructs to climb up to. |
| 7563 |
|
| 7564 |
if Nkind (Context) = N_Compilation_Unit then |
| 7565 |
|
| 7566 |
-- A package body with a corresponding spec subject to pragma |
| 7567 |
-- Elaborate_Body is an exception to the above. The annotation |
| 7568 |
-- allows the search to continue into the package declaration. |
| 7569 |
-- The transitions are: |
| 7570 |
-- |
| 7571 |
-- statements -> corresponding package spec (Elab_Body) |
| 7572 |
-- declarations -> corresponding package spec (Elab_Body) |
| 7573 |
|
| 7574 |
if Nkind (Unit) = N_Package_Body |
| 7575 |
and then (Assume_Elab_Body |
| 7576 |
or else Has_Pragma_Elaborate_Body |
| 7577 |
(Corresponding_Spec (Unit))) |
| 7578 |
then |
| 7579 |
Curr := Unit_Declaration_Node (Corresponding_Spec (Unit)); |
| 7580 |
Enter_Package_Declaration (Curr); |
| 7581 |
|
| 7582 |
-- Otherwise terminate the search. The transitions are: |
| 7583 |
-- |
| 7584 |
-- private declarations -> terminate |
| 7585 |
-- visible declarations -> terminate |
| 7586 |
-- statements -> terminate |
| 7587 |
-- declarations -> terminate |
| 7588 |
|
| 7589 |
else |
| 7590 |
raise ECR_Found; |
| 7591 |
end if; |
| 7592 |
|
| 7593 |
-- The unit is a subunit. The construct to inspect is the node |
| 7594 |
-- which precedes the corresponding stub. Update the early call |
| 7595 |
-- region to include the unit. |
| 7596 |
|
| 7597 |
elsif Nkind (Context) = N_Subunit then |
| 7598 |
Start := Unit; |
| 7599 |
Curr := Corresponding_Stub (Context); |
| 7600 |
|
| 7601 |
-- Otherwise the unit is nested. The construct to inspect is the |
| 7602 |
-- node which precedes the unit. Update the early call region to |
| 7603 |
-- include the unit. |
| 7604 |
|
| 7605 |
else |
| 7606 |
Include (Unit, Curr); |
| 7607 |
end if; |
| 7608 |
end Transition_Unit; |
| 7609 |
|
| 7610 |
-- Local variables |
| 7611 |
|
| 7612 |
Body_Id : constant Entity_Id := Unique_Defining_Entity (Body_Decl); |
| 7613 |
Region : Node_Id; |
| 7614 |
|
| 7615 |
-- Start of processing for Find_Early_Call_Region |
| 7616 |
|
| 7617 |
begin |
| 7618 |
-- The caller demands the start of the early call region without |
| 7619 |
-- saving or retrieving it to/from internal data structures. |
| 7620 |
|
| 7621 |
if Skip_Memoization then |
| 7622 |
Region := Find_ECR (Body_Decl); |
| 7623 |
|
| 7624 |
-- Default behavior |
| 7625 |
|
| 7626 |
else |
| 7627 |
-- Check whether the early call region of the subprogram body is |
| 7628 |
-- available. |
| 7629 |
|
| 7630 |
Region := Early_Call_Region (Body_Id); |
| 7631 |
|
| 7632 |
if No (Region) then |
| 7633 |
Region := Find_ECR (Body_Decl); |
| 7634 |
|
| 7635 |
-- Associate the early call region with the subprogram body in |
| 7636 |
-- case other scenarios need it. |
| 7637 |
|
| 7638 |
Set_Early_Call_Region (Body_Id, Region); |
| 7639 |
end if; |
| 7640 |
end if; |
| 7641 |
|
| 7642 |
-- A subprogram body must always have an early call region |
| 7643 |
|
| 7644 |
pragma Assert (Present (Region)); |
| 7645 |
|
| 7646 |
return Region; |
| 7647 |
end Find_Early_Call_Region; |
| 7648 |
|
| 7649 |
-------------------------------------------- |
| 7650 |
-- Initialize_Early_Call_Region_Processor -- |
| 7651 |
-------------------------------------------- |
| 7652 |
|
| 7653 |
procedure Initialize_Early_Call_Region_Processor is |
| 7654 |
begin |
| 7655 |
Early_Call_Regions_Map := ECR_Map.Create (100); |
| 7656 |
end Initialize_Early_Call_Region_Processor; |
| 7657 |
|
| 7658 |
--------------------------- |
| 7659 |
-- Set_Early_Call_Region -- |
| 7660 |
--------------------------- |
| 7661 |
|
| 7662 |
procedure Set_Early_Call_Region (Body_Id : Entity_Id; Start : Node_Id) is |
| 7663 |
pragma Assert (Present (Body_Id)); |
| 7664 |
pragma Assert (Present (Start)); |
| 7665 |
|
| 7666 |
begin |
| 7667 |
ECR_Map.Put (Early_Call_Regions_Map, Body_Id, Start); |
| 7668 |
end Set_Early_Call_Region; |
| 7669 |
end Early_Call_Region_Processor; |
| 7670 |
|
| 7671 |
---------------------- |
| 7672 |
-- Elaborated_Units -- |
| 7673 |
---------------------- |
| 7674 |
|
| 7675 |
package body Elaborated_Units is |
| 7676 |
|
| 7677 |
----------- |
| 7678 |
-- Types -- |
| 7679 |
----------- |
| 7680 |
|
| 7681 |
-- The following type idenfities the elaboration attributes of a unit |
| 7682 |
|
| 7683 |
type Elaboration_Attributes_Id is new Natural; |
| 7684 |
|
| 7685 |
No_Elaboration_Attributes : constant Elaboration_Attributes_Id := |
| 7686 |
Elaboration_Attributes_Id'First; |
| 7687 |
First_Elaboration_Attributes : constant Elaboration_Attributes_Id := |
| 7688 |
No_Elaboration_Attributes + 1; |
| 7689 |
|
| 7690 |
-- The following type represents the elaboration attributes of a unit |
| 7691 |
|
| 7692 |
type Elaboration_Attributes_Record is record |
| 7693 |
Elab_Pragma : Node_Id := Empty; |
| 7694 |
-- This attribute denotes a source Elaborate or Elaborate_All pragma |
| 7695 |
-- which guarantees the prior elaboration of some unit with respect |
| 7696 |
-- to the main unit. The pragma may come from the following contexts: |
| 7697 |
-- |
| 7698 |
-- * The main unit |
| 7699 |
-- * The spec of the main unit (if applicable) |
| 7700 |
-- * Any parent spec of the main unit (if applicable) |
| 7701 |
-- * Any parent subunit of the main unit (if applicable) |
| 7702 |
-- |
| 7703 |
-- The attribute remains Empty if no such pragma is available. Source |
| 7704 |
-- pragmas play a role in satisfying SPARK elaboration requirements. |
| 7705 |
|
| 7706 |
With_Clause : Node_Id := Empty; |
| 7707 |
-- This attribute denotes an internally-generated or a source with |
| 7708 |
-- clause for some unit withed by the main unit. With clauses carry |
| 7709 |
-- flags which represent implicit Elaborate or Elaborate_All pragmas. |
| 7710 |
-- These clauses play a role in supplying elaboration dependencies to |
| 7711 |
-- binde. |
| 7712 |
end record; |
| 7713 |
|
| 7714 |
--------------------- |
| 7715 |
-- Data structures -- |
| 7716 |
--------------------- |
| 7717 |
|
| 7718 |
-- The following table stores all elaboration attributes |
| 7719 |
|
| 7720 |
package Elaboration_Attributes is new Table.Table |
| 7721 |
(Table_Index_Type => Elaboration_Attributes_Id, |
| 7722 |
Table_Component_Type => Elaboration_Attributes_Record, |
| 7723 |
Table_Low_Bound => First_Elaboration_Attributes, |
| 7724 |
Table_Initial => 250, |
| 7725 |
Table_Increment => 200, |
| 7726 |
Table_Name => "Elaboration_Attributes"); |
| 7727 |
|
| 7728 |
procedure Destroy (EA_Id : in out Elaboration_Attributes_Id); |
| 7729 |
-- Destroy elaboration attributes EA_Id |
| 7730 |
|
| 7731 |
package UA_Map is new Dynamic_Hash_Tables |
| 7732 |
(Key_Type => Entity_Id, |
| 7733 |
Value_Type => Elaboration_Attributes_Id, |
| 7734 |
No_Value => No_Elaboration_Attributes, |
| 7735 |
Expansion_Threshold => 1.5, |
| 7736 |
Expansion_Factor => 2, |
| 7737 |
Compression_Threshold => 0.3, |
| 7738 |
Compression_Factor => 2, |
| 7739 |
"=" => "=", |
| 7740 |
Destroy_Value => Destroy, |
| 7741 |
Hash => Hash); |
| 7742 |
|
| 7743 |
-- The following map relates an elaboration attributes of a unit to the |
| 7744 |
-- unit. |
| 7745 |
|
| 7746 |
Unit_To_Attributes_Map : UA_Map.Dynamic_Hash_Table := UA_Map.Nil; |
| 7747 |
|
| 7748 |
------------------ |
| 7749 |
-- Constructors -- |
| 7750 |
------------------ |
| 7751 |
|
| 7752 |
function Elaboration_Attributes_Of |
| 7753 |
(Unit_Id : Entity_Id) return Elaboration_Attributes_Id; |
| 7754 |
pragma Inline (Elaboration_Attributes_Of); |
| 7755 |
-- Obtain the elaboration attributes of unit Unit_Id |
| 7756 |
|
| 7757 |
----------------------- |
| 7758 |
-- Local subprograms -- |
| 7759 |
----------------------- |
| 7760 |
|
| 7761 |
function Elab_Pragma (EA_Id : Elaboration_Attributes_Id) return Node_Id; |
| 7762 |
pragma Inline (Elab_Pragma); |
| 7763 |
-- Obtain the Elaborate[_All] pragma of elaboration attributes EA_Id |
| 7764 |
|
| 7765 |
procedure Ensure_Prior_Elaboration_Dynamic |
| 7766 |
(N : Node_Id; |
| 7767 |
Unit_Id : Entity_Id; |
| 7768 |
Prag_Nam : Name_Id; |
| 7769 |
In_State : Processing_In_State); |
| 7770 |
pragma Inline (Ensure_Prior_Elaboration_Dynamic); |
| 7771 |
-- Guarantee the elaboration of unit Unit_Id with respect to the main |
| 7772 |
-- unit by suggesting the use of Elaborate[_All] with name Prag_Nam. N |
| 7773 |
-- denotes the related scenario. In_State is the current state of the |
| 7774 |
-- Processing phase. |
| 7775 |
|
| 7776 |
procedure Ensure_Prior_Elaboration_Static |
| 7777 |
(N : Node_Id; |
| 7778 |
Unit_Id : Entity_Id; |
| 7779 |
Prag_Nam : Name_Id; |
| 7780 |
In_State : Processing_In_State); |
| 7781 |
pragma Inline (Ensure_Prior_Elaboration_Static); |
| 7782 |
-- Guarantee the elaboration of unit Unit_Id with respect to the main |
| 7783 |
-- unit by installing an implicit Elaborate[_All] pragma with name |
| 7784 |
-- Prag_Nam. N denotes the related scenario. In_State is the current |
| 7785 |
-- state of the Processing phase. |
| 7786 |
|
| 7787 |
function Present (EA_Id : Elaboration_Attributes_Id) return Boolean; |
| 7788 |
pragma Inline (Present); |
| 7789 |
-- Determine whether elaboration attributes UA_Id exist |
| 7790 |
|
| 7791 |
procedure Set_Elab_Pragma |
| 7792 |
(EA_Id : Elaboration_Attributes_Id; |
| 7793 |
Prag : Node_Id); |
| 7794 |
pragma Inline (Set_Elab_Pragma); |
| 7795 |
-- Set the Elaborate[_All] pragma of elaboration attributes EA_Id to |
| 7796 |
-- Prag. |
| 7797 |
|
| 7798 |
procedure Set_With_Clause |
| 7799 |
(EA_Id : Elaboration_Attributes_Id; |
| 7800 |
Clause : Node_Id); |
| 7801 |
pragma Inline (Set_With_Clause); |
| 7802 |
-- Set the with clause of elaboration attributes EA_Id to Clause |
| 7803 |
|
| 7804 |
function With_Clause (EA_Id : Elaboration_Attributes_Id) return Node_Id; |
| 7805 |
pragma Inline (With_Clause); |
| 7806 |
-- Obtain the implicit or source with clause of elaboration attributes |
| 7807 |
-- EA_Id. |
| 7808 |
|
| 7809 |
------------------------------ |
| 7810 |
-- Collect_Elaborated_Units -- |
| 7811 |
------------------------------ |
| 7812 |
|
| 7813 |
procedure Collect_Elaborated_Units is |
| 7814 |
procedure Add_Pragma (Prag : Node_Id); |
| 7815 |
pragma Inline (Add_Pragma); |
| 7816 |
-- Determine whether pragma Prag denotes a legal Elaborate[_All] |
| 7817 |
-- pragma. If this is the case, add the related unit to the context. |
| 7818 |
-- For pragma Elaborate_All, include recursively all units withed by |
| 7819 |
-- the related unit. |
| 7820 |
|
| 7821 |
procedure Add_Unit |
| 7822 |
(Unit_Id : Entity_Id; |
| 7823 |
Prag : Node_Id; |
| 7824 |
Full_Context : Boolean); |
| 7825 |
pragma Inline (Add_Unit); |
| 7826 |
-- Add unit Unit_Id to the elaboration context. Prag denotes the |
| 7827 |
-- pragma which prompted the inclusion of the unit to the context. |
| 7828 |
-- If flag Full_Context is set, examine the nonlimited clauses of |
| 7829 |
-- unit Unit_Id and add each withed unit to the context. |
| 7830 |
|
| 7831 |
procedure Find_Elaboration_Context (Comp_Unit : Node_Id); |
| 7832 |
pragma Inline (Find_Elaboration_Context); |
| 7833 |
-- Examine the context items of compilation unit Comp_Unit for |
| 7834 |
-- suitable elaboration-related pragmas and add all related units |
| 7835 |
-- to the context. |
| 7836 |
|
| 7837 |
---------------- |
| 7838 |
-- Add_Pragma -- |
| 7839 |
---------------- |
| 7840 |
|
| 7841 |
procedure Add_Pragma (Prag : Node_Id) is |
| 7842 |
Prag_Args : constant List_Id := |
| 7843 |
Pragma_Argument_Associations (Prag); |
| 7844 |
Prag_Nam : constant Name_Id := Pragma_Name (Prag); |
| 7845 |
Unit_Arg : Node_Id; |
| 7846 |
|
| 7847 |
begin |
| 7848 |
-- Nothing to do if the pragma is not related to elaboration |
| 7849 |
|
| 7850 |
if Prag_Nam not in Name_Elaborate | Name_Elaborate_All then |
| 7851 |
return; |
| 7852 |
|
| 7853 |
-- Nothing to do when the pragma is illegal |
| 7854 |
|
| 7855 |
elsif Error_Posted (Prag) then |
| 7856 |
return; |
| 7857 |
end if; |
| 7858 |
|
| 7859 |
Unit_Arg := Get_Pragma_Arg (First (Prag_Args)); |
| 7860 |
|
| 7861 |
-- The argument of the pragma may appear in package.package form |
| 7862 |
|
| 7863 |
if Nkind (Unit_Arg) = N_Selected_Component then |
| 7864 |
Unit_Arg := Selector_Name (Unit_Arg); |
| 7865 |
end if; |
| 7866 |
|
| 7867 |
Add_Unit |
| 7868 |
(Unit_Id => Entity (Unit_Arg), |
| 7869 |
Prag => Prag, |
| 7870 |
Full_Context => Prag_Nam = Name_Elaborate_All); |
| 7871 |
end Add_Pragma; |
| 7872 |
|
| 7873 |
-------------- |
| 7874 |
-- Add_Unit -- |
| 7875 |
-------------- |
| 7876 |
|
| 7877 |
procedure Add_Unit |
| 7878 |
(Unit_Id : Entity_Id; |
| 7879 |
Prag : Node_Id; |
| 7880 |
Full_Context : Boolean) |
| 7881 |
is |
| 7882 |
Clause : Node_Id; |
| 7883 |
EA_Id : Elaboration_Attributes_Id; |
| 7884 |
Unit_Prag : Node_Id; |
| 7885 |
|
| 7886 |
begin |
| 7887 |
-- Nothing to do when some previous error left a with clause or a |
| 7888 |
-- pragma in a bad state. |
| 7889 |
|
| 7890 |
if No (Unit_Id) then |
| 7891 |
return; |
| 7892 |
end if; |
| 7893 |
|
| 7894 |
EA_Id := Elaboration_Attributes_Of (Unit_Id); |
| 7895 |
Unit_Prag := Elab_Pragma (EA_Id); |
| 7896 |
|
| 7897 |
-- The unit is already included in the context by means of pragma |
| 7898 |
-- Elaborate[_All]. |
| 7899 |
|
| 7900 |
if Present (Unit_Prag) then |
| 7901 |
|
| 7902 |
-- Upgrade an existing pragma Elaborate when the unit is |
| 7903 |
-- subject to Elaborate_All because the new pragma covers a |
| 7904 |
-- larger set of units. |
| 7905 |
|
| 7906 |
if Pragma_Name (Unit_Prag) = Name_Elaborate |
| 7907 |
and then Pragma_Name (Prag) = Name_Elaborate_All |
| 7908 |
then |
| 7909 |
Set_Elab_Pragma (EA_Id, Prag); |
| 7910 |
|
| 7911 |
-- Otherwise the unit retains its existing pragma and does not |
| 7912 |
-- need to be included in the context again. |
| 7913 |
|
| 7914 |
else |
| 7915 |
return; |
| 7916 |
end if; |
| 7917 |
|
| 7918 |
-- Otherwise the current unit is not included in the context |
| 7919 |
|
| 7920 |
else |
| 7921 |
Set_Elab_Pragma (EA_Id, Prag); |
| 7922 |
end if; |
| 7923 |
|
| 7924 |
-- Includes all units withed by the current one when computing the |
| 7925 |
-- full context. |
| 7926 |
|
| 7927 |
if Full_Context then |
| 7928 |
|
| 7929 |
-- Process all nonlimited with clauses found in the context of |
| 7930 |
-- the current unit. Note that limited clauses do not impose an |
| 7931 |
-- elaboration order. |
| 7932 |
|
| 7933 |
Clause := First (Context_Items (Compilation_Unit (Unit_Id))); |
| 7934 |
while Present (Clause) loop |
| 7935 |
if Nkind (Clause) = N_With_Clause |
| 7936 |
and then not Error_Posted (Clause) |
| 7937 |
and then not Limited_Present (Clause) |
| 7938 |
then |
| 7939 |
Add_Unit |
| 7940 |
(Unit_Id => Entity (Name (Clause)), |
| 7941 |
Prag => Prag, |
| 7942 |
Full_Context => Full_Context); |
| 7943 |
end if; |
| 7944 |
|
| 7945 |
Next (Clause); |
| 7946 |
end loop; |
| 7947 |
end if; |
| 7948 |
end Add_Unit; |
| 7949 |
|
| 7950 |
------------------------------ |
| 7951 |
-- Find_Elaboration_Context -- |
| 7952 |
------------------------------ |
| 7953 |
|
| 7954 |
procedure Find_Elaboration_Context (Comp_Unit : Node_Id) is |
| 7955 |
pragma Assert (Nkind (Comp_Unit) = N_Compilation_Unit); |
| 7956 |
|
| 7957 |
Prag : Node_Id; |
| 7958 |
|
| 7959 |
begin |
| 7960 |
-- Process all elaboration-related pragmas found in the context of |
| 7961 |
-- the compilation unit. |
| 7962 |
|
| 7963 |
Prag := First (Context_Items (Comp_Unit)); |
| 7964 |
while Present (Prag) loop |
| 7965 |
if Nkind (Prag) = N_Pragma then |
| 7966 |
Add_Pragma (Prag); |
| 7967 |
end if; |
| 7968 |
|
| 7969 |
Next (Prag); |
| 7970 |
end loop; |
| 7971 |
end Find_Elaboration_Context; |
| 7972 |
|
| 7973 |
-- Local variables |
| 7974 |
|
| 7975 |
Par_Id : Entity_Id; |
| 7976 |
Unit_Id : Node_Id; |
| 7977 |
|
| 7978 |
-- Start of processing for Collect_Elaborated_Units |
| 7979 |
|
| 7980 |
begin |
| 7981 |
-- Perform a traversal to examines the context of the main unit. The |
| 7982 |
-- traversal performs the following jumps: |
| 7983 |
-- |
| 7984 |
-- subunit -> parent subunit |
| 7985 |
-- parent subunit -> body |
| 7986 |
-- body -> spec |
| 7987 |
-- spec -> parent spec |
| 7988 |
-- parent spec -> grandparent spec and so on |
| 7989 |
-- |
| 7990 |
-- The traversal relies on units rather than scopes because the scope |
| 7991 |
-- of a subunit is some spec, while this traversal must process the |
| 7992 |
-- body as well. Given that protected and task bodies can also be |
| 7993 |
-- subunits, this complicates the scope approach even further. |
| 7994 |
|
| 7995 |
Unit_Id := Unit (Cunit (Main_Unit)); |
| 7996 |
|
| 7997 |
-- Perform the following traversals when the main unit is a subunit |
| 7998 |
-- |
| 7999 |
-- subunit -> parent subunit |
| 8000 |
-- parent subunit -> body |
| 8001 |
|
| 8002 |
while Present (Unit_Id) and then Nkind (Unit_Id) = N_Subunit loop |
| 8003 |
Find_Elaboration_Context (Parent (Unit_Id)); |
| 8004 |
|
| 8005 |
-- Continue the traversal by going to the unit which contains the |
| 8006 |
-- corresponding stub. |
| 8007 |
|
| 8008 |
if Present (Corresponding_Stub (Unit_Id)) then |
| 8009 |
Unit_Id := |
| 8010 |
Unit (Cunit (Get_Source_Unit (Corresponding_Stub (Unit_Id)))); |
| 8011 |
|
| 8012 |
-- Otherwise the subunit may be erroneous or left in a bad state |
| 8013 |
|
| 8014 |
else |
| 8015 |
exit; |
| 8016 |
end if; |
| 8017 |
end loop; |
| 8018 |
|
| 8019 |
-- Perform the following traversal now that subunits have been taken |
| 8020 |
-- care of, or the main unit is a body. |
| 8021 |
-- |
| 8022 |
-- body -> spec |
| 8023 |
|
| 8024 |
if Present (Unit_Id) |
| 8025 |
and then Nkind (Unit_Id) in N_Package_Body | N_Subprogram_Body |
| 8026 |
then |
| 8027 |
Find_Elaboration_Context (Parent (Unit_Id)); |
| 8028 |
|
| 8029 |
-- Continue the traversal by going to the unit which contains the |
| 8030 |
-- corresponding spec. |
| 8031 |
|
| 8032 |
if Present (Corresponding_Spec (Unit_Id)) then |
| 8033 |
Unit_Id := |
| 8034 |
Unit (Cunit (Get_Source_Unit (Corresponding_Spec (Unit_Id)))); |
| 8035 |
end if; |
| 8036 |
end if; |
| 8037 |
|
| 8038 |
-- Perform the following traversals now that the body has been taken |
| 8039 |
-- care of, or the main unit is a spec. |
| 8040 |
-- |
| 8041 |
-- spec -> parent spec |
| 8042 |
-- parent spec -> grandparent spec and so on |
| 8043 |
|
| 8044 |
if Present (Unit_Id) |
| 8045 |
and then Nkind (Unit_Id) in N_Generic_Package_Declaration |
| 8046 |
| N_Generic_Subprogram_Declaration |
| 8047 |
| N_Package_Declaration |
| 8048 |
| N_Subprogram_Declaration |
| 8049 |
then |
| 8050 |
Find_Elaboration_Context (Parent (Unit_Id)); |
| 8051 |
|
| 8052 |
-- Process a potential chain of parent units which ends with the |
| 8053 |
-- main unit spec. The traversal can now safely rely on the scope |
| 8054 |
-- chain. |
| 8055 |
|
| 8056 |
Par_Id := Scope (Defining_Entity (Unit_Id)); |
| 8057 |
while Present (Par_Id) and then Par_Id /= Standard_Standard loop |
| 8058 |
Find_Elaboration_Context (Compilation_Unit (Par_Id)); |
| 8059 |
|
| 8060 |
Par_Id := Scope (Par_Id); |
| 8061 |
end loop; |
| 8062 |
end if; |
| 8063 |
end Collect_Elaborated_Units; |
| 8064 |
|
| 8065 |
------------- |
| 8066 |
-- Destroy -- |
| 8067 |
------------- |
| 8068 |
|
| 8069 |
procedure Destroy (EA_Id : in out Elaboration_Attributes_Id) is |
| 8070 |
pragma Unreferenced (EA_Id); |
| 8071 |
begin |
| 8072 |
null; |
| 8073 |
end Destroy; |
| 8074 |
|
| 8075 |
----------------- |
| 8076 |
-- Elab_Pragma -- |
| 8077 |
----------------- |
| 8078 |
|
| 8079 |
function Elab_Pragma |
| 8080 |
(EA_Id : Elaboration_Attributes_Id) return Node_Id |
| 8081 |
is |
| 8082 |
pragma Assert (Present (EA_Id)); |
| 8083 |
begin |
| 8084 |
return Elaboration_Attributes.Table (EA_Id).Elab_Pragma; |
| 8085 |
end Elab_Pragma; |
| 8086 |
|
| 8087 |
------------------------------- |
| 8088 |
-- Elaboration_Attributes_Of -- |
| 8089 |
------------------------------- |
| 8090 |
|
| 8091 |
function Elaboration_Attributes_Of |
| 8092 |
(Unit_Id : Entity_Id) return Elaboration_Attributes_Id |
| 8093 |
is |
| 8094 |
EA_Id : Elaboration_Attributes_Id; |
| 8095 |
|
| 8096 |
begin |
| 8097 |
EA_Id := UA_Map.Get (Unit_To_Attributes_Map, Unit_Id); |
| 8098 |
|
| 8099 |
-- The unit lacks elaboration attributes. This indicates that the |
| 8100 |
-- unit is encountered for the first time. Create the elaboration |
| 8101 |
-- attributes for it. |
| 8102 |
|
| 8103 |
if not Present (EA_Id) then |
| 8104 |
Elaboration_Attributes.Append |
| 8105 |
((Elab_Pragma => Empty, |
| 8106 |
With_Clause => Empty)); |
| 8107 |
EA_Id := Elaboration_Attributes.Last; |
| 8108 |
|
| 8109 |
-- Associate the elaboration attributes with the unit |
| 8110 |
|
| 8111 |
UA_Map.Put (Unit_To_Attributes_Map, Unit_Id, EA_Id); |
| 8112 |
end if; |
| 8113 |
|
| 8114 |
pragma Assert (Present (EA_Id)); |
| 8115 |
|
| 8116 |
return EA_Id; |
| 8117 |
end Elaboration_Attributes_Of; |
| 8118 |
|
| 8119 |
------------------------------ |
| 8120 |
-- Ensure_Prior_Elaboration -- |
| 8121 |
------------------------------ |
| 8122 |
|
| 8123 |
procedure Ensure_Prior_Elaboration |
| 8124 |
(N : Node_Id; |
| 8125 |
Unit_Id : Entity_Id; |
| 8126 |
Prag_Nam : Name_Id; |
| 8127 |
In_State : Processing_In_State) |
| 8128 |
is |
| 8129 |
pragma Assert (Prag_Nam in Name_Elaborate | Name_Elaborate_All); |
| 8130 |
|
| 8131 |
begin |
| 8132 |
-- Nothing to do when the need for prior elaboration came from a |
| 8133 |
-- partial finalization routine which occurs in an initialization |
| 8134 |
-- context. This behavior parallels that of the old ABE mechanism. |
| 8135 |
|
| 8136 |
if In_State.Within_Partial_Finalization then |
| 8137 |
return; |
| 8138 |
|
| 8139 |
-- Nothing to do when the need for prior elaboration came from a task |
| 8140 |
-- body and switch -gnatd.y (disable implicit pragma Elaborate_All on |
| 8141 |
-- task bodies) is in effect. |
| 8142 |
|
| 8143 |
elsif Debug_Flag_Dot_Y and then In_State.Within_Task_Body then |
| 8144 |
return; |
| 8145 |
|
| 8146 |
-- Nothing to do when the unit is elaborated prior to the main unit. |
| 8147 |
-- This check must also consider the following cases: |
| 8148 |
-- |
| 8149 |
-- * No check is made against the context of the main unit because |
| 8150 |
-- this is specific to the elaboration model in effect and requires |
| 8151 |
-- custom handling (see Ensure_xxx_Prior_Elaboration). |
| 8152 |
-- |
| 8153 |
-- * Unit_Id is subject to pragma Elaborate_Body. An implicit pragma |
| 8154 |
-- Elaborate[_All] MUST be generated even though Unit_Id is always |
| 8155 |
-- elaborated prior to the main unit. This conservative strategy |
| 8156 |
-- ensures that other units withed by Unit_Id will not lead to an |
| 8157 |
-- ABE. |
| 8158 |
-- |
| 8159 |
-- package A is package body A is |
| 8160 |
-- procedure ABE; procedure ABE is ... end ABE; |
| 8161 |
-- end A; end A; |
| 8162 |
-- |
| 8163 |
-- with A; |
| 8164 |
-- package B is package body B is |
| 8165 |
-- pragma Elaborate_Body; procedure Proc is |
| 8166 |
-- begin |
| 8167 |
-- procedure Proc; A.ABE; |
| 8168 |
-- package B; end Proc; |
| 8169 |
-- end B; |
| 8170 |
-- |
| 8171 |
-- with B; |
| 8172 |
-- package C is package body C is |
| 8173 |
-- ... ... |
| 8174 |
-- end C; begin |
| 8175 |
-- B.Proc; |
| 8176 |
-- end C; |
| 8177 |
-- |
| 8178 |
-- In the example above, the elaboration of C invokes B.Proc. B is |
| 8179 |
-- subject to pragma Elaborate_Body. If no pragma Elaborate[_All] |
| 8180 |
-- is gnerated for B in C, then the following elaboratio order will |
| 8181 |
-- lead to an ABE: |
| 8182 |
-- |
| 8183 |
-- spec of A elaborated |
| 8184 |
-- spec of B elaborated |
| 8185 |
-- body of B elaborated |
| 8186 |
-- spec of C elaborated |
| 8187 |
-- body of C elaborated <-- calls B.Proc which calls A.ABE |
| 8188 |
-- body of A elaborated <-- problem |
| 8189 |
-- |
| 8190 |
-- The generation of an implicit pragma Elaborate_All (B) ensures |
| 8191 |
-- that the elaboration-order mechanism will not pick the above |
| 8192 |
-- order. |
| 8193 |
-- |
| 8194 |
-- An implicit Elaborate is NOT generated when the unit is subject |
| 8195 |
-- to Elaborate_Body because both pragmas have the same effect. |
| 8196 |
-- |
| 8197 |
-- * Unit_Id is the main unit. An implicit pragma Elaborate[_All] |
| 8198 |
-- MUST NOT be generated in this case because a unit cannot depend |
| 8199 |
-- on its own elaboration. This case is therefore treated as valid |
| 8200 |
-- prior elaboration. |
| 8201 |
|
| 8202 |
elsif Has_Prior_Elaboration |
| 8203 |
(Unit_Id => Unit_Id, |
| 8204 |
Same_Unit_OK => True, |
| 8205 |
Elab_Body_OK => Prag_Nam = Name_Elaborate) |
| 8206 |
then |
| 8207 |
return; |
| 8208 |
end if; |
| 8209 |
|
| 8210 |
-- Suggest the use of pragma Prag_Nam when the dynamic model is in |
| 8211 |
-- effect. |
| 8212 |
|
| 8213 |
if Dynamic_Elaboration_Checks then |
| 8214 |
Ensure_Prior_Elaboration_Dynamic |
| 8215 |
(N => N, |
| 8216 |
Unit_Id => Unit_Id, |
| 8217 |
Prag_Nam => Prag_Nam, |
| 8218 |
In_State => In_State); |
| 8219 |
|
| 8220 |
-- Install an implicit pragma Prag_Nam when the static model is in |
| 8221 |
-- effect. |
| 8222 |
|
| 8223 |
else |
| 8224 |
pragma Assert (Static_Elaboration_Checks); |
| 8225 |
|
| 8226 |
Ensure_Prior_Elaboration_Static |
| 8227 |
(N => N, |
| 8228 |
Unit_Id => Unit_Id, |
| 8229 |
Prag_Nam => Prag_Nam, |
| 8230 |
In_State => In_State); |
| 8231 |
end if; |
| 8232 |
end Ensure_Prior_Elaboration; |
| 8233 |
|
| 8234 |
-------------------------------------- |
| 8235 |
-- Ensure_Prior_Elaboration_Dynamic -- |
| 8236 |
-------------------------------------- |
| 8237 |
|
| 8238 |
procedure Ensure_Prior_Elaboration_Dynamic |
| 8239 |
(N : Node_Id; |
| 8240 |
Unit_Id : Entity_Id; |
| 8241 |
Prag_Nam : Name_Id; |
| 8242 |
In_State : Processing_In_State) |
| 8243 |
is |
| 8244 |
procedure Info_Missing_Pragma; |
| 8245 |
pragma Inline (Info_Missing_Pragma); |
| 8246 |
-- Output information concerning missing Elaborate or Elaborate_All |
| 8247 |
-- pragma with name Prag_Nam for scenario N, which would ensure the |
| 8248 |
-- prior elaboration of Unit_Id. |
| 8249 |
|
| 8250 |
------------------------- |
| 8251 |
-- Info_Missing_Pragma -- |
| 8252 |
------------------------- |
| 8253 |
|
| 8254 |
procedure Info_Missing_Pragma is |
| 8255 |
begin |
| 8256 |
-- Internal units are ignored as they cause unnecessary noise |
| 8257 |
|
| 8258 |
if not In_Internal_Unit (Unit_Id) then |
| 8259 |
|
| 8260 |
-- The name of the unit subjected to the elaboration pragma is |
| 8261 |
-- fully qualified to improve the clarity of the info message. |
| 8262 |
|
| 8263 |
Error_Msg_Name_1 := Prag_Nam; |
| 8264 |
Error_Msg_Qual_Level := Nat'Last; |
| 8265 |
|
| 8266 |
Error_Msg_NE |
| 8267 |
("info: missing pragma % for unit &?$?", N, |
| 8268 |
Unit_Id); |
| 8269 |
Error_Msg_Qual_Level := 0; |
| 8270 |
end if; |
| 8271 |
end Info_Missing_Pragma; |
| 8272 |
|
| 8273 |
-- Local variables |
| 8274 |
|
| 8275 |
EA_Id : constant Elaboration_Attributes_Id := |
| 8276 |
Elaboration_Attributes_Of (Unit_Id); |
| 8277 |
N_Lvl : Enclosing_Level_Kind; |
| 8278 |
N_Rep : Scenario_Rep_Id; |
| 8279 |
|
| 8280 |
-- Start of processing for Ensure_Prior_Elaboration_Dynamic |
| 8281 |
|
| 8282 |
begin |
| 8283 |
-- Nothing to do when the unit is guaranteed prior elaboration by |
| 8284 |
-- means of a source Elaborate[_All] pragma. |
| 8285 |
|
| 8286 |
if Present (Elab_Pragma (EA_Id)) then |
| 8287 |
return; |
| 8288 |
end if; |
| 8289 |
|
| 8290 |
-- Output extra information on a missing Elaborate[_All] pragma when |
| 8291 |
-- switch -gnatel (info messages on implicit Elaborate[_All] pragmas |
| 8292 |
-- is in effect. |
| 8293 |
|
| 8294 |
if Elab_Info_Messages |
| 8295 |
and then not In_State.Suppress_Info_Messages |
| 8296 |
then |
| 8297 |
N_Rep := Scenario_Representation_Of (N, In_State); |
| 8298 |
N_Lvl := Level (N_Rep); |
| 8299 |
|
| 8300 |
-- Declaration-level scenario |
| 8301 |
|
| 8302 |
if (Is_Suitable_Call (N) or else Is_Suitable_Instantiation (N)) |
| 8303 |
and then N_Lvl = Declaration_Level |
| 8304 |
then |
| 8305 |
null; |
| 8306 |
|
| 8307 |
-- Library-level scenario |
| 8308 |
|
| 8309 |
elsif N_Lvl in Library_Level then |
| 8310 |
null; |
| 8311 |
|
| 8312 |
-- Instantiation library-level scenario |
| 8313 |
|
| 8314 |
elsif N_Lvl = Instantiation_Level then |
| 8315 |
null; |
| 8316 |
|
| 8317 |
-- Otherwise the scenario does not appear at the proper level |
| 8318 |
|
| 8319 |
else |
| 8320 |
return; |
| 8321 |
end if; |
| 8322 |
|
| 8323 |
Info_Missing_Pragma; |
| 8324 |
end if; |
| 8325 |
end Ensure_Prior_Elaboration_Dynamic; |
| 8326 |
|
| 8327 |
------------------------------------- |
| 8328 |
-- Ensure_Prior_Elaboration_Static -- |
| 8329 |
------------------------------------- |
| 8330 |
|
| 8331 |
procedure Ensure_Prior_Elaboration_Static |
| 8332 |
(N : Node_Id; |
| 8333 |
Unit_Id : Entity_Id; |
| 8334 |
Prag_Nam : Name_Id; |
| 8335 |
In_State : Processing_In_State) |
| 8336 |
is |
| 8337 |
function Find_With_Clause |
| 8338 |
(Items : List_Id; |
| 8339 |
Withed_Id : Entity_Id) return Node_Id; |
| 8340 |
pragma Inline (Find_With_Clause); |
| 8341 |
-- Find a nonlimited with clause in the list of context items Items |
| 8342 |
-- that withs unit Withed_Id. Return Empty if no such clause exists. |
| 8343 |
|
| 8344 |
procedure Info_Implicit_Pragma; |
| 8345 |
pragma Inline (Info_Implicit_Pragma); |
| 8346 |
-- Output information concerning an implicitly generated Elaborate |
| 8347 |
-- or Elaborate_All pragma with name Prag_Nam for scenario N which |
| 8348 |
-- ensures the prior elaboration of unit Unit_Id. |
| 8349 |
|
| 8350 |
---------------------- |
| 8351 |
-- Find_With_Clause -- |
| 8352 |
---------------------- |
| 8353 |
|
| 8354 |
function Find_With_Clause |
| 8355 |
(Items : List_Id; |
| 8356 |
Withed_Id : Entity_Id) return Node_Id |
| 8357 |
is |
| 8358 |
Item : Node_Id; |
| 8359 |
|
| 8360 |
begin |
| 8361 |
-- Examine the context clauses looking for a suitable with. Note |
| 8362 |
-- that limited clauses do not affect the elaboration order. |
| 8363 |
|
| 8364 |
Item := First (Items); |
| 8365 |
while Present (Item) loop |
| 8366 |
if Nkind (Item) = N_With_Clause |
| 8367 |
and then not Error_Posted (Item) |
| 8368 |
and then not Limited_Present (Item) |
| 8369 |
and then Entity (Name (Item)) = Withed_Id |
| 8370 |
then |
| 8371 |
return Item; |
| 8372 |
end if; |
| 8373 |
|
| 8374 |
Next (Item); |
| 8375 |
end loop; |
| 8376 |
|
| 8377 |
return Empty; |
| 8378 |
end Find_With_Clause; |
| 8379 |
|
| 8380 |
-------------------------- |
| 8381 |
-- Info_Implicit_Pragma -- |
| 8382 |
-------------------------- |
| 8383 |
|
| 8384 |
procedure Info_Implicit_Pragma is |
| 8385 |
begin |
| 8386 |
-- Internal units are ignored as they cause unnecessary noise |
| 8387 |
|
| 8388 |
if not In_Internal_Unit (Unit_Id) then |
| 8389 |
|
| 8390 |
-- The name of the unit subjected to the elaboration pragma is |
| 8391 |
-- fully qualified to improve the clarity of the info message. |
| 8392 |
|
| 8393 |
Error_Msg_Name_1 := Prag_Nam; |
| 8394 |
Error_Msg_Qual_Level := Nat'Last; |
| 8395 |
|
| 8396 |
Error_Msg_NE |
| 8397 |
("info: implicit pragma % generated for unit &?$?", |
| 8398 |
N, Unit_Id); |
| 8399 |
|
| 8400 |
Error_Msg_Qual_Level := 0; |
| 8401 |
Output_Active_Scenarios (N, In_State); |
| 8402 |
end if; |
| 8403 |
end Info_Implicit_Pragma; |
| 8404 |
|
| 8405 |
-- Local variables |
| 8406 |
|
| 8407 |
EA_Id : constant Elaboration_Attributes_Id := |
| 8408 |
Elaboration_Attributes_Of (Unit_Id); |
| 8409 |
|
| 8410 |
Main_Cunit : constant Node_Id := Cunit (Main_Unit); |
| 8411 |
Loc : constant Source_Ptr := Sloc (Main_Cunit); |
| 8412 |
Unit_Cunit : constant Node_Id := Compilation_Unit (Unit_Id); |
| 8413 |
Unit_Prag : constant Node_Id := Elab_Pragma (EA_Id); |
| 8414 |
Unit_With : constant Node_Id := With_Clause (EA_Id); |
| 8415 |
|
| 8416 |
Clause : Node_Id; |
| 8417 |
Items : List_Id; |
| 8418 |
|
| 8419 |
-- Start of processing for Ensure_Prior_Elaboration_Static |
| 8420 |
|
| 8421 |
begin |
| 8422 |
-- Nothing to do when the caller has suppressed the generation of |
| 8423 |
-- implicit Elaborate[_All] pragmas. |
| 8424 |
|
| 8425 |
if In_State.Suppress_Implicit_Pragmas then |
| 8426 |
return; |
| 8427 |
|
| 8428 |
-- Nothing to do when the unit is guaranteed prior elaboration by |
| 8429 |
-- means of a source Elaborate[_All] pragma. |
| 8430 |
|
| 8431 |
elsif Present (Unit_Prag) then |
| 8432 |
return; |
| 8433 |
|
| 8434 |
-- Nothing to do when the unit has an existing implicit Elaborate or |
| 8435 |
-- Elaborate_All pragma installed by a previous scenario. |
| 8436 |
|
| 8437 |
elsif Present (Unit_With) then |
| 8438 |
|
| 8439 |
-- The unit is already guaranteed prior elaboration by means of an |
| 8440 |
-- implicit Elaborate pragma, however the current scenario imposes |
| 8441 |
-- a stronger requirement of Elaborate_All. "Upgrade" the existing |
| 8442 |
-- pragma to match this new requirement. |
| 8443 |
|
| 8444 |
if Elaborate_Desirable (Unit_With) |
| 8445 |
and then Prag_Nam = Name_Elaborate_All |
| 8446 |
then |
| 8447 |
Set_Elaborate_All_Desirable (Unit_With); |
| 8448 |
Set_Elaborate_Desirable (Unit_With, False); |
| 8449 |
end if; |
| 8450 |
|
| 8451 |
return; |
| 8452 |
end if; |
| 8453 |
|
| 8454 |
-- At this point it is known that the unit has no prior elaboration |
| 8455 |
-- according to pragmas and hierarchical relationships. |
| 8456 |
|
| 8457 |
Items := Context_Items (Main_Cunit); |
| 8458 |
|
| 8459 |
if No (Items) then |
| 8460 |
Items := New_List; |
| 8461 |
Set_Context_Items (Main_Cunit, Items); |
| 8462 |
end if; |
| 8463 |
|
| 8464 |
-- Locate the with clause for the unit. Note that there might not be |
| 8465 |
-- a with clause if the unit is visible through a subunit-body, |
| 8466 |
-- body-spec, or spec-parent relationship. |
| 8467 |
|
| 8468 |
Clause := |
| 8469 |
Find_With_Clause |
| 8470 |
(Items => Items, |
| 8471 |
Withed_Id => Unit_Id); |
| 8472 |
|
| 8473 |
-- Generate: |
| 8474 |
-- with Id; |
| 8475 |
|
| 8476 |
-- Note that adding implicit with clauses is safe because analysis, |
| 8477 |
-- resolution, and expansion have already taken place and it is not |
| 8478 |
-- possible to interfere with visibility. Note that this implicit |
| 8479 |
-- with clause can point at (for example) a package body, which |
| 8480 |
-- is not the case for normal with clauses. |
| 8481 |
|
| 8482 |
if No (Clause) then |
| 8483 |
Clause := |
| 8484 |
Make_With_Clause (Loc, |
| 8485 |
Name => New_Occurrence_Of (Unit_Id, Loc)); |
| 8486 |
Set_Is_Implicit_With (Clause); |
| 8487 |
Set_Withed_Lib_Unit (Clause, Unit_Cunit); |
| 8488 |
Append_To (Items, Clause); |
| 8489 |
end if; |
| 8490 |
|
| 8491 |
-- Mark the with clause depending on the pragma required |
| 8492 |
|
| 8493 |
if Prag_Nam = Name_Elaborate then |
| 8494 |
Set_Elaborate_Desirable (Clause); |
| 8495 |
else |
| 8496 |
Set_Elaborate_All_Desirable (Clause); |
| 8497 |
end if; |
| 8498 |
|
| 8499 |
-- The implicit Elaborate[_All] ensures the prior elaboration of |
| 8500 |
-- the unit. Include the unit in the elaboration context of the |
| 8501 |
-- main unit. |
| 8502 |
|
| 8503 |
Set_With_Clause (EA_Id, Clause); |
| 8504 |
|
| 8505 |
-- Output extra information on an implicit Elaborate[_All] pragma |
| 8506 |
-- when switch -gnatel (info messages on implicit Elaborate[_All] |
| 8507 |
-- pragmas is in effect. |
| 8508 |
|
| 8509 |
if Elab_Info_Messages then |
| 8510 |
Info_Implicit_Pragma; |
| 8511 |
end if; |
| 8512 |
end Ensure_Prior_Elaboration_Static; |
| 8513 |
|
| 8514 |
------------------------------- |
| 8515 |
-- Finalize_Elaborated_Units -- |
| 8516 |
------------------------------- |
| 8517 |
|
| 8518 |
procedure Finalize_Elaborated_Units is |
| 8519 |
begin |
| 8520 |
UA_Map.Destroy (Unit_To_Attributes_Map); |
| 8521 |
end Finalize_Elaborated_Units; |
| 8522 |
|
| 8523 |
--------------------------- |
| 8524 |
-- Has_Prior_Elaboration -- |
| 8525 |
--------------------------- |
| 8526 |
|
| 8527 |
function Has_Prior_Elaboration |
| 8528 |
(Unit_Id : Entity_Id; |
| 8529 |
Context_OK : Boolean := False; |
| 8530 |
Elab_Body_OK : Boolean := False; |
| 8531 |
Same_Unit_OK : Boolean := False) return Boolean |
| 8532 |
is |
| 8533 |
EA_Id : constant Elaboration_Attributes_Id := |
| 8534 |
Elaboration_Attributes_Of (Unit_Id); |
| 8535 |
Main_Id : constant Entity_Id := Main_Unit_Entity; |
| 8536 |
Unit_Prag : constant Node_Id := Elab_Pragma (EA_Id); |
| 8537 |
Unit_With : constant Node_Id := With_Clause (EA_Id); |
| 8538 |
|
| 8539 |
begin |
| 8540 |
-- A preelaborated unit is always elaborated prior to the main unit |
| 8541 |
|
| 8542 |
if Is_Preelaborated_Unit (Unit_Id) then |
| 8543 |
return True; |
| 8544 |
|
| 8545 |
-- An internal unit is always elaborated prior to a non-internal main |
| 8546 |
-- unit. |
| 8547 |
|
| 8548 |
elsif In_Internal_Unit (Unit_Id) |
| 8549 |
and then not In_Internal_Unit (Main_Id) |
| 8550 |
then |
| 8551 |
return True; |
| 8552 |
|
| 8553 |
-- A unit has prior elaboration if it appears within the context |
| 8554 |
-- of the main unit. Consider this case only when requested by the |
| 8555 |
-- caller. |
| 8556 |
|
| 8557 |
elsif Context_OK |
| 8558 |
and then (Present (Unit_Prag) or else Present (Unit_With)) |
| 8559 |
then |
| 8560 |
return True; |
| 8561 |
|
| 8562 |
-- A unit whose body is elaborated together with its spec has prior |
| 8563 |
-- elaboration except with respect to itself. Consider this case only |
| 8564 |
-- when requested by the caller. |
| 8565 |
|
| 8566 |
elsif Elab_Body_OK |
| 8567 |
and then Has_Pragma_Elaborate_Body (Unit_Id) |
| 8568 |
and then not Is_Same_Unit (Unit_Id, Main_Id) |
| 8569 |
then |
| 8570 |
return True; |
| 8571 |
|
| 8572 |
-- A unit has no prior elaboration with respect to itself, but does |
| 8573 |
-- not require any means of ensuring its own elaboration either. |
| 8574 |
-- Treat this case as valid prior elaboration only when requested by |
| 8575 |
-- the caller. |
| 8576 |
|
| 8577 |
elsif Same_Unit_OK and then Is_Same_Unit (Unit_Id, Main_Id) then |
| 8578 |
return True; |
| 8579 |
end if; |
| 8580 |
|
| 8581 |
return False; |
| 8582 |
end Has_Prior_Elaboration; |
| 8583 |
|
| 8584 |
--------------------------------- |
| 8585 |
-- Initialize_Elaborated_Units -- |
| 8586 |
--------------------------------- |
| 8587 |
|
| 8588 |
procedure Initialize_Elaborated_Units is |
| 8589 |
begin |
| 8590 |
Unit_To_Attributes_Map := UA_Map.Create (250); |
| 8591 |
end Initialize_Elaborated_Units; |
| 8592 |
|
| 8593 |
---------------------------------- |
| 8594 |
-- Meet_Elaboration_Requirement -- |
| 8595 |
---------------------------------- |
| 8596 |
|
| 8597 |
procedure Meet_Elaboration_Requirement |
| 8598 |
(N : Node_Id; |
| 8599 |
Targ_Id : Entity_Id; |
| 8600 |
Req_Nam : Name_Id; |
| 8601 |
In_State : Processing_In_State) |
| 8602 |
is |
| 8603 |
pragma Assert (Req_Nam in Name_Elaborate | Name_Elaborate_All); |
| 8604 |
|
| 8605 |
Main_Id : constant Entity_Id := Main_Unit_Entity; |
| 8606 |
Unit_Id : constant Entity_Id := Find_Top_Unit (Targ_Id); |
| 8607 |
|
| 8608 |
procedure Elaboration_Requirement_Error; |
| 8609 |
pragma Inline (Elaboration_Requirement_Error); |
| 8610 |
-- Emit an error concerning scenario N which has failed to meet the |
| 8611 |
-- elaboration requirement. |
| 8612 |
|
| 8613 |
function Find_Preelaboration_Pragma |
| 8614 |
(Prag_Nam : Name_Id) return Node_Id; |
| 8615 |
pragma Inline (Find_Preelaboration_Pragma); |
| 8616 |
-- Traverse the visible declarations of unit Unit_Id and locate a |
| 8617 |
-- source preelaboration-related pragma with name Prag_Nam. |
| 8618 |
|
| 8619 |
procedure Info_Requirement_Met (Prag : Node_Id); |
| 8620 |
pragma Inline (Info_Requirement_Met); |
| 8621 |
-- Output information concerning pragma Prag which meets requirement |
| 8622 |
-- Req_Nam. |
| 8623 |
|
| 8624 |
----------------------------------- |
| 8625 |
-- Elaboration_Requirement_Error -- |
| 8626 |
----------------------------------- |
| 8627 |
|
| 8628 |
procedure Elaboration_Requirement_Error is |
| 8629 |
begin |
| 8630 |
if Is_Suitable_Call (N) then |
| 8631 |
Info_Call |
| 8632 |
(Call => N, |
| 8633 |
Subp_Id => Targ_Id, |
| 8634 |
Info_Msg => False, |
| 8635 |
In_SPARK => True); |
| 8636 |
|
| 8637 |
elsif Is_Suitable_Instantiation (N) then |
| 8638 |
Info_Instantiation |
| 8639 |
(Inst => N, |
| 8640 |
Gen_Id => Targ_Id, |
| 8641 |
Info_Msg => False, |
| 8642 |
In_SPARK => True); |
| 8643 |
|
| 8644 |
elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then |
| 8645 |
Error_Msg_N |
| 8646 |
("read of refinement constituents during elaboration in " |
| 8647 |
& "SPARK", N); |
| 8648 |
|
| 8649 |
elsif Is_Suitable_Variable_Reference (N) then |
| 8650 |
Info_Variable_Reference |
| 8651 |
(Ref => N, |
| 8652 |
Var_Id => Targ_Id); |
| 8653 |
|
| 8654 |
-- No other scenario may impose a requirement on the context of |
| 8655 |
-- the main unit. |
| 8656 |
|
| 8657 |
else |
| 8658 |
pragma Assert (False); |
| 8659 |
return; |
| 8660 |
end if; |
| 8661 |
|
| 8662 |
Error_Msg_Name_1 := Req_Nam; |
| 8663 |
Error_Msg_Node_2 := Unit_Id; |
| 8664 |
Error_Msg_NE ("\\unit & requires pragma % for &", N, Main_Id); |
| 8665 |
|
| 8666 |
Output_Active_Scenarios (N, In_State); |
| 8667 |
end Elaboration_Requirement_Error; |
| 8668 |
|
| 8669 |
-------------------------------- |
| 8670 |
-- Find_Preelaboration_Pragma -- |
| 8671 |
-------------------------------- |
| 8672 |
|
| 8673 |
function Find_Preelaboration_Pragma |
| 8674 |
(Prag_Nam : Name_Id) return Node_Id |
| 8675 |
is |
| 8676 |
Spec : constant Node_Id := Parent (Unit_Id); |
| 8677 |
Decl : Node_Id; |
| 8678 |
|
| 8679 |
begin |
| 8680 |
-- A preelaboration-related pragma comes from source and appears |
| 8681 |
-- at the top of the visible declarations of a package. |
| 8682 |
|
| 8683 |
if Nkind (Spec) = N_Package_Specification then |
| 8684 |
Decl := First (Visible_Declarations (Spec)); |
| 8685 |
while Present (Decl) loop |
| 8686 |
if Comes_From_Source (Decl) then |
| 8687 |
if Nkind (Decl) = N_Pragma |
| 8688 |
and then Pragma_Name (Decl) = Prag_Nam |
| 8689 |
then |
| 8690 |
return Decl; |
| 8691 |
|
| 8692 |
-- Otherwise the construct terminates the region where |
| 8693 |
-- the preelaboration-related pragma may appear. |
| 8694 |
|
| 8695 |
else |
| 8696 |
exit; |
| 8697 |
end if; |
| 8698 |
end if; |
| 8699 |
|
| 8700 |
Next (Decl); |
| 8701 |
end loop; |
| 8702 |
end if; |
| 8703 |
|
| 8704 |
return Empty; |
| 8705 |
end Find_Preelaboration_Pragma; |
| 8706 |
|
| 8707 |
-------------------------- |
| 8708 |
-- Info_Requirement_Met -- |
| 8709 |
-------------------------- |
| 8710 |
|
| 8711 |
procedure Info_Requirement_Met (Prag : Node_Id) is |
| 8712 |
pragma Assert (Present (Prag)); |
| 8713 |
|
| 8714 |
begin |
| 8715 |
Error_Msg_Name_1 := Req_Nam; |
| 8716 |
Error_Msg_Sloc := Sloc (Prag); |
| 8717 |
Error_Msg_NE |
| 8718 |
("\\% requirement for unit & met by pragma #", N, Unit_Id); |
| 8719 |
end Info_Requirement_Met; |
| 8720 |
|
| 8721 |
-- Local variables |
| 8722 |
|
| 8723 |
EA_Id : Elaboration_Attributes_Id; |
| 8724 |
Elab_Nam : Name_Id; |
| 8725 |
Req_Met : Boolean; |
| 8726 |
Unit_Prag : Node_Id; |
| 8727 |
|
| 8728 |
-- Start of processing for Meet_Elaboration_Requirement |
| 8729 |
|
| 8730 |
begin |
| 8731 |
-- Assume that the requirement has not been met |
| 8732 |
|
| 8733 |
Req_Met := False; |
| 8734 |
|
| 8735 |
-- If the target is within the main unit, either at the source level |
| 8736 |
-- or through an instantiation, then there is no real requirement to |
| 8737 |
-- meet because the main unit cannot force its own elaboration by |
| 8738 |
-- means of an Elaborate[_All] pragma. Treat this case as valid |
| 8739 |
-- coverage. |
| 8740 |
|
| 8741 |
if In_Extended_Main_Code_Unit (Targ_Id) then |
| 8742 |
Req_Met := True; |
| 8743 |
|
| 8744 |
-- Otherwise the target resides in an external unit |
| 8745 |
|
| 8746 |
-- The requirement is met when the target comes from an internal unit |
| 8747 |
-- because such a unit is elaborated prior to a non-internal unit. |
| 8748 |
|
| 8749 |
elsif In_Internal_Unit (Unit_Id) |
| 8750 |
and then not In_Internal_Unit (Main_Id) |
| 8751 |
then |
| 8752 |
Req_Met := True; |
| 8753 |
|
| 8754 |
-- The requirement is met when the target comes from a preelaborated |
| 8755 |
-- unit. This portion must parallel predicate Is_Preelaborated_Unit. |
| 8756 |
|
| 8757 |
elsif Is_Preelaborated_Unit (Unit_Id) then |
| 8758 |
Req_Met := True; |
| 8759 |
|
| 8760 |
-- Output extra information when switch -gnatel (info messages on |
| 8761 |
-- implicit Elaborate[_All] pragmas. |
| 8762 |
|
| 8763 |
if Elab_Info_Messages |
| 8764 |
and then not In_State.Suppress_Info_Messages |
| 8765 |
then |
| 8766 |
if Is_Preelaborated (Unit_Id) then |
| 8767 |
Elab_Nam := Name_Preelaborate; |
| 8768 |
|
| 8769 |
elsif Is_Pure (Unit_Id) then |
| 8770 |
Elab_Nam := Name_Pure; |
| 8771 |
|
| 8772 |
elsif Is_Remote_Call_Interface (Unit_Id) then |
| 8773 |
Elab_Nam := Name_Remote_Call_Interface; |
| 8774 |
|
| 8775 |
elsif Is_Remote_Types (Unit_Id) then |
| 8776 |
Elab_Nam := Name_Remote_Types; |
| 8777 |
|
| 8778 |
else |
| 8779 |
pragma Assert (Is_Shared_Passive (Unit_Id)); |
| 8780 |
Elab_Nam := Name_Shared_Passive; |
| 8781 |
end if; |
| 8782 |
|
| 8783 |
Info_Requirement_Met (Find_Preelaboration_Pragma (Elab_Nam)); |
| 8784 |
end if; |
| 8785 |
|
| 8786 |
-- Determine whether the context of the main unit has a pragma strong |
| 8787 |
-- enough to meet the requirement. |
| 8788 |
|
| 8789 |
else |
| 8790 |
EA_Id := Elaboration_Attributes_Of (Unit_Id); |
| 8791 |
Unit_Prag := Elab_Pragma (EA_Id); |
| 8792 |
|
| 8793 |
-- The pragma must be either Elaborate_All or be as strong as the |
| 8794 |
-- requirement. |
| 8795 |
|
| 8796 |
if Present (Unit_Prag) |
| 8797 |
and then Pragma_Name (Unit_Prag) in Name_Elaborate_All | Req_Nam |
| 8798 |
then |
| 8799 |
Req_Met := True; |
| 8800 |
|
| 8801 |
-- Output extra information when switch -gnatel (info messages |
| 8802 |
-- on implicit Elaborate[_All] pragmas. |
| 8803 |
|
| 8804 |
if Elab_Info_Messages |
| 8805 |
and then not In_State.Suppress_Info_Messages |
| 8806 |
then |
| 8807 |
Info_Requirement_Met (Unit_Prag); |
| 8808 |
end if; |
| 8809 |
end if; |
| 8810 |
end if; |
| 8811 |
|
| 8812 |
-- The requirement was not met by the context of the main unit, issue |
| 8813 |
-- an error. |
| 8814 |
|
| 8815 |
if not Req_Met then |
| 8816 |
Elaboration_Requirement_Error; |
| 8817 |
end if; |
| 8818 |
end Meet_Elaboration_Requirement; |
| 8819 |
|
| 8820 |
------------- |
| 8821 |
-- Present -- |
| 8822 |
------------- |
| 8823 |
|
| 8824 |
function Present (EA_Id : Elaboration_Attributes_Id) return Boolean is |
| 8825 |
begin |
| 8826 |
return EA_Id /= No_Elaboration_Attributes; |
| 8827 |
end Present; |
| 8828 |
|
| 8829 |
--------------------- |
| 8830 |
-- Set_Elab_Pragma -- |
| 8831 |
--------------------- |
| 8832 |
|
| 8833 |
procedure Set_Elab_Pragma |
| 8834 |
(EA_Id : Elaboration_Attributes_Id; |
| 8835 |
Prag : Node_Id) |
| 8836 |
is |
| 8837 |
pragma Assert (Present (EA_Id)); |
| 8838 |
begin |
| 8839 |
Elaboration_Attributes.Table (EA_Id).Elab_Pragma := Prag; |
| 8840 |
end Set_Elab_Pragma; |
| 8841 |
|
| 8842 |
--------------------- |
| 8843 |
-- Set_With_Clause -- |
| 8844 |
--------------------- |
| 8845 |
|
| 8846 |
procedure Set_With_Clause |
| 8847 |
(EA_Id : Elaboration_Attributes_Id; |
| 8848 |
Clause : Node_Id) |
| 8849 |
is |
| 8850 |
pragma Assert (Present (EA_Id)); |
| 8851 |
begin |
| 8852 |
Elaboration_Attributes.Table (EA_Id).With_Clause := Clause; |
| 8853 |
end Set_With_Clause; |
| 8854 |
|
| 8855 |
----------------- |
| 8856 |
-- With_Clause -- |
| 8857 |
----------------- |
| 8858 |
|
| 8859 |
function With_Clause |
| 8860 |
(EA_Id : Elaboration_Attributes_Id) return Node_Id |
| 8861 |
is |
| 8862 |
pragma Assert (Present (EA_Id)); |
| 8863 |
begin |
| 8864 |
return Elaboration_Attributes.Table (EA_Id).With_Clause; |
| 8865 |
end With_Clause; |
| 8866 |
end Elaborated_Units; |
| 8867 |
|
| 8868 |
------------------------------ |
| 8869 |
-- Elaboration_Phase_Active -- |
| 8870 |
------------------------------ |
| 8871 |
|
| 8872 |
function Elaboration_Phase_Active return Boolean is |
| 8873 |
begin |
| 8874 |
return Elaboration_Phase = Active; |
| 8875 |
end Elaboration_Phase_Active; |
| 8876 |
|
| 8877 |
------------------------------ |
| 8878 |
-- Error_Preelaborated_Call -- |
| 8879 |
------------------------------ |
| 8880 |
|
| 8881 |
procedure Error_Preelaborated_Call (N : Node_Id) is |
| 8882 |
begin |
| 8883 |
-- This is a warning in GNAT mode allowing such calls to be used in the |
| 8884 |
-- predefined library units with appropriate care. |
| 8885 |
|
| 8886 |
Error_Msg_Warn := GNAT_Mode; |
| 8887 |
|
| 8888 |
-- Ada 2022 (AI12-0175): Calls to certain functions that are essentially |
| 8889 |
-- unchecked conversions are preelaborable. |
| 8890 |
|
| 8891 |
if Ada_Version >= Ada_2022 then |
| 8892 |
Error_Msg_N |
| 8893 |
("<<non-preelaborable call not allowed in preelaborated unit", N); |
| 8894 |
else |
| 8895 |
Error_Msg_N |
| 8896 |
("<<non-static call not allowed in preelaborated unit", N); |
| 8897 |
end if; |
| 8898 |
end Error_Preelaborated_Call; |
| 8899 |
|
| 8900 |
---------------------------------- |
| 8901 |
-- Finalize_All_Data_Structures -- |
| 8902 |
---------------------------------- |
| 8903 |
|
| 8904 |
procedure Finalize_All_Data_Structures is |
| 8905 |
begin |
| 8906 |
Finalize_Body_Processor; |
| 8907 |
Finalize_Early_Call_Region_Processor; |
| 8908 |
Finalize_Elaborated_Units; |
| 8909 |
Finalize_Internal_Representation; |
| 8910 |
Finalize_Invocation_Graph; |
| 8911 |
Finalize_Scenario_Storage; |
| 8912 |
end Finalize_All_Data_Structures; |
| 8913 |
|
| 8914 |
----------------------------- |
| 8915 |
-- Find_Enclosing_Instance -- |
| 8916 |
----------------------------- |
| 8917 |
|
| 8918 |
function Find_Enclosing_Instance (N : Node_Id) return Node_Id is |
| 8919 |
Par : Node_Id; |
| 8920 |
|
| 8921 |
begin |
| 8922 |
-- Climb the parent chain looking for an enclosing instance spec or body |
| 8923 |
|
| 8924 |
Par := N; |
| 8925 |
while Present (Par) loop |
| 8926 |
if Nkind (Par) in N_Package_Body |
| 8927 |
| N_Package_Declaration |
| 8928 |
| N_Subprogram_Body |
| 8929 |
| N_Subprogram_Declaration |
| 8930 |
and then Is_Generic_Instance (Unique_Defining_Entity (Par)) |
| 8931 |
then |
| 8932 |
return Par; |
| 8933 |
end if; |
| 8934 |
|
| 8935 |
Par := Parent (Par); |
| 8936 |
end loop; |
| 8937 |
|
| 8938 |
return Empty; |
| 8939 |
end Find_Enclosing_Instance; |
| 8940 |
|
| 8941 |
-------------------------- |
| 8942 |
-- Find_Enclosing_Level -- |
| 8943 |
-------------------------- |
| 8944 |
|
| 8945 |
function Find_Enclosing_Level (N : Node_Id) return Enclosing_Level_Kind is |
| 8946 |
function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind; |
| 8947 |
pragma Inline (Level_Of); |
| 8948 |
-- Obtain the corresponding level of unit Unit |
| 8949 |
|
| 8950 |
-------------- |
| 8951 |
-- Level_Of -- |
| 8952 |
-------------- |
| 8953 |
|
| 8954 |
function Level_Of (Unit : Node_Id) return Enclosing_Level_Kind is |
| 8955 |
Spec_Id : Entity_Id; |
| 8956 |
|
| 8957 |
begin |
| 8958 |
if Nkind (Unit) in N_Generic_Instantiation then |
| 8959 |
return Instantiation_Level; |
| 8960 |
|
| 8961 |
elsif Nkind (Unit) = N_Generic_Package_Declaration then |
| 8962 |
return Generic_Spec_Level; |
| 8963 |
|
| 8964 |
elsif Nkind (Unit) = N_Package_Declaration then |
| 8965 |
return Library_Spec_Level; |
| 8966 |
|
| 8967 |
elsif Nkind (Unit) = N_Package_Body then |
| 8968 |
Spec_Id := Corresponding_Spec (Unit); |
| 8969 |
|
| 8970 |
-- The body belongs to a generic package |
| 8971 |
|
| 8972 |
if Present (Spec_Id) |
| 8973 |
and then Ekind (Spec_Id) = E_Generic_Package |
| 8974 |
then |
| 8975 |
return Generic_Body_Level; |
| 8976 |
|
| 8977 |
-- Otherwise the body belongs to a non-generic package. This also |
| 8978 |
-- treats an illegal package body without a corresponding spec as |
| 8979 |
-- a non-generic package body. |
| 8980 |
|
| 8981 |
else |
| 8982 |
return Library_Body_Level; |
| 8983 |
end if; |
| 8984 |
end if; |
| 8985 |
|
| 8986 |
return No_Level; |
| 8987 |
end Level_Of; |
| 8988 |
|
| 8989 |
-- Local variables |
| 8990 |
|
| 8991 |
Context : Node_Id; |
| 8992 |
Curr : Node_Id; |
| 8993 |
Prev : Node_Id; |
| 8994 |
|
| 8995 |
-- Start of processing for Find_Enclosing_Level |
| 8996 |
|
| 8997 |
begin |
| 8998 |
-- Call markers and instantiations which appear at the declaration level |
| 8999 |
-- but are later relocated in a different context retain their original |
| 9000 |
-- declaration level. |
| 9001 |
|
| 9002 |
if Nkind (N) in N_Call_Marker |
| 9003 |
| N_Function_Instantiation |
| 9004 |
| N_Package_Instantiation |
| 9005 |
| N_Procedure_Instantiation |
| 9006 |
and then Is_Declaration_Level_Node (N) |
| 9007 |
then |
| 9008 |
return Declaration_Level; |
| 9009 |
end if; |
| 9010 |
|
| 9011 |
-- Climb the parent chain looking at the enclosing levels |
| 9012 |
|
| 9013 |
Prev := N; |
| 9014 |
Curr := Parent (Prev); |
| 9015 |
while Present (Curr) loop |
| 9016 |
|
| 9017 |
-- A traversal from a subunit continues via the corresponding stub |
| 9018 |
|
| 9019 |
if Nkind (Curr) = N_Subunit then |
| 9020 |
Curr := Corresponding_Stub (Curr); |
| 9021 |
|
| 9022 |
-- The current construct is a package. Packages are ignored because |
| 9023 |
-- they are always elaborated when the enclosing context is invoked |
| 9024 |
-- or elaborated. |
| 9025 |
|
| 9026 |
elsif Nkind (Curr) in N_Package_Body | N_Package_Declaration then |
| 9027 |
null; |
| 9028 |
|
| 9029 |
-- The current construct is a block statement |
| 9030 |
|
| 9031 |
elsif Nkind (Curr) = N_Block_Statement then |
| 9032 |
|
| 9033 |
-- Ignore internally generated blocks created by the expander for |
| 9034 |
-- various purposes such as abort defer/undefer. |
| 9035 |
|
| 9036 |
if not Comes_From_Source (Curr) then |
| 9037 |
null; |
| 9038 |
|
| 9039 |
-- If the traversal came from the handled sequence of statements, |
| 9040 |
-- then the node appears at the level of the enclosing construct. |
| 9041 |
-- This is a more reliable test because transients scopes within |
| 9042 |
-- the declarative region of the encapsulator are hard to detect. |
| 9043 |
|
| 9044 |
elsif Nkind (Prev) = N_Handled_Sequence_Of_Statements |
| 9045 |
and then Handled_Statement_Sequence (Curr) = Prev |
| 9046 |
then |
| 9047 |
return Find_Enclosing_Level (Parent (Curr)); |
| 9048 |
|
| 9049 |
-- Otherwise the traversal came from the declarations, the node is |
| 9050 |
-- at the declaration level. |
| 9051 |
|
| 9052 |
else |
| 9053 |
return Declaration_Level; |
| 9054 |
end if; |
| 9055 |
|
| 9056 |
-- The current construct is a declaration-level encapsulator |
| 9057 |
|
| 9058 |
elsif Nkind (Curr) in |
| 9059 |
N_Entry_Body | N_Subprogram_Body | N_Task_Body |
| 9060 |
then |
| 9061 |
-- If the traversal came from the handled sequence of statements, |
| 9062 |
-- then the node cannot possibly appear at any level. This is |
| 9063 |
-- a more reliable test because transients scopes within the |
| 9064 |
-- declarative region of the encapsulator are hard to detect. |
| 9065 |
|
| 9066 |
if Nkind (Prev) = N_Handled_Sequence_Of_Statements |
| 9067 |
and then Handled_Statement_Sequence (Curr) = Prev |
| 9068 |
then |
| 9069 |
return No_Level; |
| 9070 |
|
| 9071 |
-- Otherwise the traversal came from the declarations, the node is |
| 9072 |
-- at the declaration level. |
| 9073 |
|
| 9074 |
else |
| 9075 |
return Declaration_Level; |
| 9076 |
end if; |
| 9077 |
|
| 9078 |
-- The current construct is a non-library-level encapsulator which |
| 9079 |
-- indicates that the node cannot possibly appear at any level. Note |
| 9080 |
-- that the check must come after the declaration-level check because |
| 9081 |
-- both predicates share certain nodes. |
| 9082 |
|
| 9083 |
elsif Is_Non_Library_Level_Encapsulator (Curr) then |
| 9084 |
Context := Parent (Curr); |
| 9085 |
|
| 9086 |
-- The sole exception is when the encapsulator is the compilation |
| 9087 |
-- utit itself because the compilation unit node requires special |
| 9088 |
-- processing (see below). |
| 9089 |
|
| 9090 |
if Present (Context) |
| 9091 |
and then Nkind (Context) = N_Compilation_Unit |
| 9092 |
then |
| 9093 |
null; |
| 9094 |
|
| 9095 |
-- Otherwise the node is not at any level |
| 9096 |
|
| 9097 |
else |
| 9098 |
return No_Level; |
| 9099 |
end if; |
| 9100 |
|
| 9101 |
-- The current construct is a compilation unit. The node appears at |
| 9102 |
-- the [generic] library level when the unit is a [generic] package. |
| 9103 |
|
| 9104 |
elsif Nkind (Curr) = N_Compilation_Unit then |
| 9105 |
return Level_Of (Unit (Curr)); |
| 9106 |
end if; |
| 9107 |
|
| 9108 |
Prev := Curr; |
| 9109 |
Curr := Parent (Prev); |
| 9110 |
end loop; |
| 9111 |
|
| 9112 |
return No_Level; |
| 9113 |
end Find_Enclosing_Level; |
| 9114 |
|
| 9115 |
------------------- |
| 9116 |
-- Find_Top_Unit -- |
| 9117 |
------------------- |
| 9118 |
|
| 9119 |
function Find_Top_Unit (N : Node_Or_Entity_Id) return Entity_Id is |
| 9120 |
begin |
| 9121 |
return Find_Unit_Entity (Unit (Cunit (Get_Top_Level_Code_Unit (N)))); |
| 9122 |
end Find_Top_Unit; |
| 9123 |
|
| 9124 |
---------------------- |
| 9125 |
-- Find_Unit_Entity -- |
| 9126 |
---------------------- |
| 9127 |
|
| 9128 |
function Find_Unit_Entity (N : Node_Id) return Entity_Id is |
| 9129 |
Context : constant Node_Id := Parent (N); |
| 9130 |
Orig_N : constant Node_Id := Original_Node (N); |
| 9131 |
|
| 9132 |
begin |
| 9133 |
-- The unit denotes a package body of an instantiation which acts as |
| 9134 |
-- a compilation unit. The proper entity is that of the package spec. |
| 9135 |
|
| 9136 |
if Nkind (N) = N_Package_Body |
| 9137 |
and then Nkind (Orig_N) = N_Package_Instantiation |
| 9138 |
and then Nkind (Context) = N_Compilation_Unit |
| 9139 |
then |
| 9140 |
return Corresponding_Spec (N); |
| 9141 |
|
| 9142 |
-- The unit denotes an anonymous package created to wrap a subprogram |
| 9143 |
-- instantiation which acts as a compilation unit. The proper entity is |
| 9144 |
-- that of the "related instance". |
| 9145 |
|
| 9146 |
elsif Nkind (N) = N_Package_Declaration |
| 9147 |
and then Nkind (Orig_N) in |
| 9148 |
N_Function_Instantiation | N_Procedure_Instantiation |
| 9149 |
and then Nkind (Context) = N_Compilation_Unit |
| 9150 |
then |
| 9151 |
return Related_Instance (Defining_Entity (N)); |
| 9152 |
|
| 9153 |
-- The unit denotes a concurrent body acting as a subunit. Such bodies |
| 9154 |
-- are generally rewritten into null statements. The proper entity is |
| 9155 |
-- that of the "original node". |
| 9156 |
|
| 9157 |
elsif Nkind (N) = N_Subunit |
| 9158 |
and then Nkind (Proper_Body (N)) = N_Null_Statement |
| 9159 |
and then Nkind (Original_Node (Proper_Body (N))) in |
| 9160 |
N_Protected_Body | N_Task_Body |
| 9161 |
then |
| 9162 |
return Defining_Entity (Original_Node (Proper_Body (N))); |
| 9163 |
|
| 9164 |
-- Otherwise the proper entity is the defining entity |
| 9165 |
|
| 9166 |
else |
| 9167 |
return Defining_Entity (N); |
| 9168 |
end if; |
| 9169 |
end Find_Unit_Entity; |
| 9170 |
|
| 9171 |
----------------------- |
| 9172 |
-- First_Formal_Type -- |
| 9173 |
----------------------- |
| 9174 |
|
| 9175 |
function First_Formal_Type (Subp_Id : Entity_Id) return Entity_Id is |
| 9176 |
Formal_Id : constant Entity_Id := First_Formal (Subp_Id); |
| 9177 |
Typ : Entity_Id; |
| 9178 |
|
| 9179 |
begin |
| 9180 |
if Present (Formal_Id) then |
| 9181 |
Typ := Etype (Formal_Id); |
| 9182 |
|
| 9183 |
-- Handle various combinations of concurrent and private types |
| 9184 |
|
| 9185 |
loop |
| 9186 |
if Ekind (Typ) in E_Protected_Type | E_Task_Type |
| 9187 |
and then Present (Anonymous_Object (Typ)) |
| 9188 |
then |
| 9189 |
Typ := Anonymous_Object (Typ); |
| 9190 |
|
| 9191 |
elsif Is_Concurrent_Record_Type (Typ) then |
| 9192 |
Typ := Corresponding_Concurrent_Type (Typ); |
| 9193 |
|
| 9194 |
elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
| 9195 |
Typ := Full_View (Typ); |
| 9196 |
|
| 9197 |
else |
| 9198 |
exit; |
| 9199 |
end if; |
| 9200 |
end loop; |
| 9201 |
|
| 9202 |
return Typ; |
| 9203 |
end if; |
| 9204 |
|
| 9205 |
return Empty; |
| 9206 |
end First_Formal_Type; |
| 9207 |
|
| 9208 |
------------------------------ |
| 9209 |
-- Guaranteed_ABE_Processor -- |
| 9210 |
------------------------------ |
| 9211 |
|
| 9212 |
package body Guaranteed_ABE_Processor is |
| 9213 |
function Is_Guaranteed_ABE |
| 9214 |
(N : Node_Id; |
| 9215 |
Target_Decl : Node_Id; |
| 9216 |
Target_Body : Node_Id) return Boolean; |
| 9217 |
pragma Inline (Is_Guaranteed_ABE); |
| 9218 |
-- Determine whether scenario N with a target described by its initial |
| 9219 |
-- declaration Target_Decl and body Target_Decl results in a guaranteed |
| 9220 |
-- ABE. |
| 9221 |
|
| 9222 |
procedure Process_Guaranteed_ABE_Activation |
| 9223 |
(Call : Node_Id; |
| 9224 |
Call_Rep : Scenario_Rep_Id; |
| 9225 |
Obj_Id : Entity_Id; |
| 9226 |
Obj_Rep : Target_Rep_Id; |
| 9227 |
Task_Typ : Entity_Id; |
| 9228 |
Task_Rep : Target_Rep_Id; |
| 9229 |
In_State : Processing_In_State); |
| 9230 |
pragma Inline (Process_Guaranteed_ABE_Activation); |
| 9231 |
-- Perform common guaranteed ABE checks and diagnostics for activation |
| 9232 |
-- call Call which activates object Obj_Id of task type Task_Typ. Formal |
| 9233 |
-- Call_Rep denotes the representation of the call. Obj_Rep denotes the |
| 9234 |
-- representation of the object. Task_Rep denotes the representation of |
| 9235 |
-- the task type. In_State is the current state of the Processing phase. |
| 9236 |
|
| 9237 |
procedure Process_Guaranteed_ABE_Call |
| 9238 |
(Call : Node_Id; |
| 9239 |
Call_Rep : Scenario_Rep_Id; |
| 9240 |
In_State : Processing_In_State); |
| 9241 |
pragma Inline (Process_Guaranteed_ABE_Call); |
| 9242 |
-- Perform common guaranteed ABE checks and diagnostics for call Call |
| 9243 |
-- with representation Call_Rep. In_State denotes the current state of |
| 9244 |
-- the Processing phase. |
| 9245 |
|
| 9246 |
procedure Process_Guaranteed_ABE_Instantiation |
| 9247 |
(Inst : Node_Id; |
| 9248 |
Inst_Rep : Scenario_Rep_Id; |
| 9249 |
In_State : Processing_In_State); |
| 9250 |
pragma Inline (Process_Guaranteed_ABE_Instantiation); |
| 9251 |
-- Perform common guaranteed ABE checks and diagnostics for instance |
| 9252 |
-- Inst with representation Inst_Rep. In_State is the current state of |
| 9253 |
-- the Processing phase. |
| 9254 |
|
| 9255 |
----------------------- |
| 9256 |
-- Is_Guaranteed_ABE -- |
| 9257 |
----------------------- |
| 9258 |
|
| 9259 |
function Is_Guaranteed_ABE |
| 9260 |
(N : Node_Id; |
| 9261 |
Target_Decl : Node_Id; |
| 9262 |
Target_Body : Node_Id) return Boolean |
| 9263 |
is |
| 9264 |
Spec : Node_Id; |
| 9265 |
begin |
| 9266 |
-- Avoid cascaded errors if there were previous serious infractions. |
| 9267 |
-- As a result the scenario will not be treated as a guaranteed ABE. |
| 9268 |
-- This behavior parallels that of the old ABE mechanism. |
| 9269 |
|
| 9270 |
if Serious_Errors_Detected > 0 then |
| 9271 |
return False; |
| 9272 |
|
| 9273 |
-- The scenario and the target appear in the same context ignoring |
| 9274 |
-- enclosing library levels. |
| 9275 |
|
| 9276 |
elsif In_Same_Context (N, Target_Decl) then |
| 9277 |
|
| 9278 |
-- The target body has already been encountered. The scenario |
| 9279 |
-- results in a guaranteed ABE if it appears prior to the body. |
| 9280 |
|
| 9281 |
if Present (Target_Body) then |
| 9282 |
return Earlier_In_Extended_Unit (N, Target_Body); |
| 9283 |
|
| 9284 |
-- Otherwise the body has not been encountered yet. The scenario |
| 9285 |
-- is a guaranteed ABE since the body will appear later, unless |
| 9286 |
-- this is a null specification, which can occur if expansion is |
| 9287 |
-- disabled (e.g. -gnatc or GNATprove mode). It is assumed that |
| 9288 |
-- the caller has already ensured that the scenario is ABE-safe |
| 9289 |
-- because optional bodies are not considered here. |
| 9290 |
|
| 9291 |
else |
| 9292 |
Spec := Specification (Target_Decl); |
| 9293 |
|
| 9294 |
if Nkind (Spec) /= N_Procedure_Specification |
| 9295 |
or else not Null_Present (Spec) |
| 9296 |
then |
| 9297 |
return True; |
| 9298 |
end if; |
| 9299 |
end if; |
| 9300 |
end if; |
| 9301 |
|
| 9302 |
return False; |
| 9303 |
end Is_Guaranteed_ABE; |
| 9304 |
|
| 9305 |
---------------------------- |
| 9306 |
-- Process_Guaranteed_ABE -- |
| 9307 |
---------------------------- |
| 9308 |
|
| 9309 |
procedure Process_Guaranteed_ABE |
| 9310 |
(N : Node_Id; |
| 9311 |
In_State : Processing_In_State) |
| 9312 |
is |
| 9313 |
Scen : constant Node_Id := Scenario (N); |
| 9314 |
Scen_Rep : Scenario_Rep_Id; |
| 9315 |
|
| 9316 |
begin |
| 9317 |
-- Add the current scenario to the stack of active scenarios |
| 9318 |
|
| 9319 |
Push_Active_Scenario (Scen); |
| 9320 |
|
| 9321 |
-- Only calls, instantiations, and task activations may result in a |
| 9322 |
-- guaranteed ABE. |
| 9323 |
|
| 9324 |
-- Call or task activation |
| 9325 |
|
| 9326 |
if Is_Suitable_Call (Scen) then |
| 9327 |
Scen_Rep := Scenario_Representation_Of (Scen, In_State); |
| 9328 |
|
| 9329 |
if Kind (Scen_Rep) = Call_Scenario then |
| 9330 |
Process_Guaranteed_ABE_Call |
| 9331 |
(Call => Scen, |
| 9332 |
Call_Rep => Scen_Rep, |
| 9333 |
In_State => In_State); |
| 9334 |
|
| 9335 |
else |
| 9336 |
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario); |
| 9337 |
|
| 9338 |
Process_Activation |
| 9339 |
(Call => Scen, |
| 9340 |
Call_Rep => Scenario_Representation_Of (Scen, In_State), |
| 9341 |
Processor => Process_Guaranteed_ABE_Activation'Access, |
| 9342 |
In_State => In_State); |
| 9343 |
end if; |
| 9344 |
|
| 9345 |
-- Instantiation |
| 9346 |
|
| 9347 |
elsif Is_Suitable_Instantiation (Scen) then |
| 9348 |
Process_Guaranteed_ABE_Instantiation |
| 9349 |
(Inst => Scen, |
| 9350 |
Inst_Rep => Scenario_Representation_Of (Scen, In_State), |
| 9351 |
In_State => In_State); |
| 9352 |
end if; |
| 9353 |
|
| 9354 |
-- Remove the current scenario from the stack of active scenarios |
| 9355 |
-- once all ABE diagnostics and checks have been performed. |
| 9356 |
|
| 9357 |
Pop_Active_Scenario (Scen); |
| 9358 |
end Process_Guaranteed_ABE; |
| 9359 |
|
| 9360 |
--------------------------------------- |
| 9361 |
-- Process_Guaranteed_ABE_Activation -- |
| 9362 |
--------------------------------------- |
| 9363 |
|
| 9364 |
procedure Process_Guaranteed_ABE_Activation |
| 9365 |
(Call : Node_Id; |
| 9366 |
Call_Rep : Scenario_Rep_Id; |
| 9367 |
Obj_Id : Entity_Id; |
| 9368 |
Obj_Rep : Target_Rep_Id; |
| 9369 |
Task_Typ : Entity_Id; |
| 9370 |
Task_Rep : Target_Rep_Id; |
| 9371 |
In_State : Processing_In_State) |
| 9372 |
is |
| 9373 |
Spec_Decl : constant Node_Id := Spec_Declaration (Task_Rep); |
| 9374 |
|
| 9375 |
Check_OK : constant Boolean := |
| 9376 |
not In_State.Suppress_Checks |
| 9377 |
and then Ghost_Mode_Of (Obj_Rep) /= Is_Ignored |
| 9378 |
and then Ghost_Mode_Of (Task_Rep) /= Is_Ignored |
| 9379 |
and then Elaboration_Checks_OK (Obj_Rep) |
| 9380 |
and then Elaboration_Checks_OK (Task_Rep); |
| 9381 |
-- A run-time ABE check may be installed only when the object and the |
| 9382 |
-- task type have active elaboration checks, and both are not ignored |
| 9383 |
-- Ghost constructs. |
| 9384 |
|
| 9385 |
begin |
| 9386 |
-- Nothing to do when the root scenario appears at the declaration |
| 9387 |
-- level and the task is in the same unit, but outside this context. |
| 9388 |
-- |
| 9389 |
-- task type Task_Typ; -- task declaration |
| 9390 |
-- |
| 9391 |
-- procedure Proc is |
| 9392 |
-- function A ... is |
| 9393 |
-- begin |
| 9394 |
-- if Some_Condition then |
| 9395 |
-- declare |
| 9396 |
-- T : Task_Typ; |
| 9397 |
-- begin |
| 9398 |
-- <activation call> -- activation site |
| 9399 |
-- end; |
| 9400 |
-- ... |
| 9401 |
-- end A; |
| 9402 |
-- |
| 9403 |
-- X : ... := A; -- root scenario |
| 9404 |
-- ... |
| 9405 |
-- |
| 9406 |
-- task body Task_Typ is |
| 9407 |
-- ... |
| 9408 |
-- end Task_Typ; |
| 9409 |
-- |
| 9410 |
-- In the example above, the context of X is the declarative list |
| 9411 |
-- of Proc. The "elaboration" of X may reach the activation of T |
| 9412 |
-- whose body is defined outside of X's context. The task body is |
| 9413 |
-- relevant only when Proc is invoked, but this happens only in |
| 9414 |
-- "normal" elaboration, therefore the task body must not be |
| 9415 |
-- considered if this is not the case. |
| 9416 |
|
| 9417 |
if Is_Up_Level_Target |
| 9418 |
(Targ_Decl => Spec_Decl, |
| 9419 |
In_State => In_State) |
| 9420 |
then |
| 9421 |
return; |
| 9422 |
|
| 9423 |
-- Nothing to do when the activation is ABE-safe |
| 9424 |
-- |
| 9425 |
-- generic |
| 9426 |
-- package Gen is |
| 9427 |
-- task type Task_Typ; |
| 9428 |
-- end Gen; |
| 9429 |
-- |
| 9430 |
-- package body Gen is |
| 9431 |
-- task body Task_Typ is |
| 9432 |
-- begin |
| 9433 |
-- ... |
| 9434 |
-- end Task_Typ; |
| 9435 |
-- end Gen; |
| 9436 |
-- |
| 9437 |
-- with Gen; |
| 9438 |
-- procedure Main is |
| 9439 |
-- package Nested is |
| 9440 |
-- package Inst is new Gen; |
| 9441 |
-- T : Inst.Task_Typ; |
| 9442 |
-- end Nested; -- safe activation |
| 9443 |
-- ... |
| 9444 |
|
| 9445 |
elsif Is_Safe_Activation (Call, Task_Rep) then |
| 9446 |
return; |
| 9447 |
|
| 9448 |
-- An activation call leads to a guaranteed ABE when the activation |
| 9449 |
-- call and the task appear within the same context ignoring library |
| 9450 |
-- levels, and the body of the task has not been seen yet or appears |
| 9451 |
-- after the activation call. |
| 9452 |
-- |
| 9453 |
-- procedure Guaranteed_ABE is |
| 9454 |
-- task type Task_Typ; |
| 9455 |
-- |
| 9456 |
-- package Nested is |
| 9457 |
-- T : Task_Typ; |
| 9458 |
-- <activation call> -- guaranteed ABE |
| 9459 |
-- end Nested; |
| 9460 |
-- |
| 9461 |
-- task body Task_Typ is |
| 9462 |
-- ... |
| 9463 |
-- end Task_Typ; |
| 9464 |
-- ... |
| 9465 |
|
| 9466 |
elsif Is_Guaranteed_ABE |
| 9467 |
(N => Call, |
| 9468 |
Target_Decl => Spec_Decl, |
| 9469 |
Target_Body => Body_Declaration (Task_Rep)) |
| 9470 |
then |
| 9471 |
if Elaboration_Warnings_OK (Call_Rep) then |
| 9472 |
Error_Msg_Sloc := Sloc (Call); |
| 9473 |
Error_Msg_N |
| 9474 |
("??task & will be activated # before elaboration of its " |
| 9475 |
& "body", Obj_Id); |
| 9476 |
Error_Msg_N |
| 9477 |
("\Program_Error will be raised at run time", Obj_Id); |
| 9478 |
end if; |
| 9479 |
|
| 9480 |
-- Mark the activation call as a guaranteed ABE |
| 9481 |
|
| 9482 |
Set_Is_Known_Guaranteed_ABE (Call); |
| 9483 |
|
| 9484 |
-- Install a run-time ABE failue because this activation call will |
| 9485 |
-- always result in an ABE. |
| 9486 |
|
| 9487 |
if Check_OK then |
| 9488 |
Install_Scenario_ABE_Failure |
| 9489 |
(N => Call, |
| 9490 |
Targ_Id => Task_Typ, |
| 9491 |
Targ_Rep => Task_Rep, |
| 9492 |
Disable => Obj_Rep); |
| 9493 |
end if; |
| 9494 |
end if; |
| 9495 |
end Process_Guaranteed_ABE_Activation; |
| 9496 |
|
| 9497 |
--------------------------------- |
| 9498 |
-- Process_Guaranteed_ABE_Call -- |
| 9499 |
--------------------------------- |
| 9500 |
|
| 9501 |
procedure Process_Guaranteed_ABE_Call |
| 9502 |
(Call : Node_Id; |
| 9503 |
Call_Rep : Scenario_Rep_Id; |
| 9504 |
In_State : Processing_In_State) |
| 9505 |
is |
| 9506 |
Subp_Id : constant Entity_Id := Target (Call_Rep); |
| 9507 |
Subp_Rep : constant Target_Rep_Id := |
| 9508 |
Target_Representation_Of (Subp_Id, In_State); |
| 9509 |
Spec_Decl : constant Node_Id := Spec_Declaration (Subp_Rep); |
| 9510 |
|
| 9511 |
Check_OK : constant Boolean := |
| 9512 |
not In_State.Suppress_Checks |
| 9513 |
and then Ghost_Mode_Of (Call_Rep) /= Is_Ignored |
| 9514 |
and then Ghost_Mode_Of (Subp_Rep) /= Is_Ignored |
| 9515 |
and then Elaboration_Checks_OK (Call_Rep) |
| 9516 |
and then Elaboration_Checks_OK (Subp_Rep); |
| 9517 |
-- A run-time ABE check may be installed only when both the call |
| 9518 |
-- and the target have active elaboration checks, and both are not |
| 9519 |
-- ignored Ghost constructs. |
| 9520 |
|
| 9521 |
begin |
| 9522 |
-- Nothing to do when the root scenario appears at the declaration |
| 9523 |
-- level and the target is in the same unit but outside this context. |
| 9524 |
-- |
| 9525 |
-- function B ...; -- target declaration |
| 9526 |
-- |
| 9527 |
-- procedure Proc is |
| 9528 |
-- function A ... is |
| 9529 |
-- begin |
| 9530 |
-- if Some_Condition then |
| 9531 |
-- return B; -- call site |
| 9532 |
-- ... |
| 9533 |
-- end A; |
| 9534 |
-- |
| 9535 |
-- X : ... := A; -- root scenario |
| 9536 |
-- ... |
| 9537 |
-- |
| 9538 |
-- function B ... is |
| 9539 |
-- ... |
| 9540 |
-- end B; |
| 9541 |
-- |
| 9542 |
-- In the example above, the context of X is the declarative region |
| 9543 |
-- of Proc. The "elaboration" of X may eventually reach B which is |
| 9544 |
-- defined outside of X's context. B is relevant only when Proc is |
| 9545 |
-- invoked, but this happens only by means of "normal" elaboration, |
| 9546 |
-- therefore B must not be considered if this is not the case. |
| 9547 |
|
| 9548 |
if Is_Up_Level_Target |
| 9549 |
(Targ_Decl => Spec_Decl, |
| 9550 |
In_State => In_State) |
| 9551 |
then |
| 9552 |
return; |
| 9553 |
|
| 9554 |
-- Nothing to do when the call is ABE-safe |
| 9555 |
-- |
| 9556 |
-- generic |
| 9557 |
-- function Gen ...; |
| 9558 |
-- |
| 9559 |
-- function Gen ... is |
| 9560 |
-- begin |
| 9561 |
-- ... |
| 9562 |
-- end Gen; |
| 9563 |
-- |
| 9564 |
-- with Gen; |
| 9565 |
-- procedure Main is |
| 9566 |
-- function Inst is new Gen; |
| 9567 |
-- X : ... := Inst; -- safe call |
| 9568 |
-- ... |
| 9569 |
|
| 9570 |
elsif Is_Safe_Call (Call, Subp_Id, Subp_Rep) then |
| 9571 |
return; |
| 9572 |
|
| 9573 |
-- A call leads to a guaranteed ABE when the call and the target |
| 9574 |
-- appear within the same context ignoring library levels, and the |
| 9575 |
-- body of the target has not been seen yet or appears after the |
| 9576 |
-- call. |
| 9577 |
-- |
| 9578 |
-- procedure Guaranteed_ABE is |
| 9579 |
-- function Func ...; |
| 9580 |
-- |
| 9581 |
-- package Nested is |
| 9582 |
-- Obj : ... := Func; -- guaranteed ABE |
| 9583 |
-- end Nested; |
| 9584 |
-- |
| 9585 |
-- function Func ... is |
| 9586 |
-- ... |
| 9587 |
-- end Func; |
| 9588 |
-- ... |
| 9589 |
|
| 9590 |
elsif Is_Guaranteed_ABE |
| 9591 |
(N => Call, |
| 9592 |
Target_Decl => Spec_Decl, |
| 9593 |
Target_Body => Body_Declaration (Subp_Rep)) |
| 9594 |
then |
| 9595 |
if Elaboration_Warnings_OK (Call_Rep) then |
| 9596 |
Error_Msg_NE |
| 9597 |
("??cannot call & before body seen", Call, Subp_Id); |
| 9598 |
Error_Msg_N ("\Program_Error will be raised at run time", Call); |
| 9599 |
end if; |
| 9600 |
|
| 9601 |
-- Mark the call as a guaranteed ABE |
| 9602 |
|
| 9603 |
Set_Is_Known_Guaranteed_ABE (Call); |
| 9604 |
|
| 9605 |
-- Install a run-time ABE failure because the call will always |
| 9606 |
-- result in an ABE. |
| 9607 |
|
| 9608 |
if Check_OK then |
| 9609 |
Install_Scenario_ABE_Failure |
| 9610 |
(N => Call, |
| 9611 |
Targ_Id => Subp_Id, |
| 9612 |
Targ_Rep => Subp_Rep, |
| 9613 |
Disable => Call_Rep); |
| 9614 |
end if; |
| 9615 |
end if; |
| 9616 |
end Process_Guaranteed_ABE_Call; |
| 9617 |
|
| 9618 |
------------------------------------------ |
| 9619 |
-- Process_Guaranteed_ABE_Instantiation -- |
| 9620 |
------------------------------------------ |
| 9621 |
|
| 9622 |
procedure Process_Guaranteed_ABE_Instantiation |
| 9623 |
(Inst : Node_Id; |
| 9624 |
Inst_Rep : Scenario_Rep_Id; |
| 9625 |
In_State : Processing_In_State) |
| 9626 |
is |
| 9627 |
Gen_Id : constant Entity_Id := Target (Inst_Rep); |
| 9628 |
Gen_Rep : constant Target_Rep_Id := |
| 9629 |
Target_Representation_Of (Gen_Id, In_State); |
| 9630 |
Spec_Decl : constant Node_Id := Spec_Declaration (Gen_Rep); |
| 9631 |
|
| 9632 |
Check_OK : constant Boolean := |
| 9633 |
not In_State.Suppress_Checks |
| 9634 |
and then Ghost_Mode_Of (Inst_Rep) /= Is_Ignored |
| 9635 |
and then Ghost_Mode_Of (Gen_Rep) /= Is_Ignored |
| 9636 |
and then Elaboration_Checks_OK (Inst_Rep) |
| 9637 |
and then Elaboration_Checks_OK (Gen_Rep); |
| 9638 |
-- A run-time ABE check may be installed only when both the instance |
| 9639 |
-- and the generic have active elaboration checks and both are not |
| 9640 |
-- ignored Ghost constructs. |
| 9641 |
|
| 9642 |
begin |
| 9643 |
-- Nothing to do when the root scenario appears at the declaration |
| 9644 |
-- level and the generic is in the same unit, but outside this |
| 9645 |
-- context. |
| 9646 |
-- |
| 9647 |
-- generic |
| 9648 |
-- procedure Gen is ...; -- generic declaration |
| 9649 |
-- |
| 9650 |
-- procedure Proc is |
| 9651 |
-- function A ... is |
| 9652 |
-- begin |
| 9653 |
-- if Some_Condition then |
| 9654 |
-- declare |
| 9655 |
-- procedure I is new Gen; -- instantiation site |
| 9656 |
-- ... |
| 9657 |
-- ... |
| 9658 |
-- end A; |
| 9659 |
-- |
| 9660 |
-- X : ... := A; -- root scenario |
| 9661 |
-- ... |
| 9662 |
-- |
| 9663 |
-- procedure Gen is |
| 9664 |
-- ... |
| 9665 |
-- end Gen; |
| 9666 |
-- |
| 9667 |
-- In the example above, the context of X is the declarative region |
| 9668 |
-- of Proc. The "elaboration" of X may eventually reach Gen which |
| 9669 |
-- appears outside of X's context. Gen is relevant only when Proc is |
| 9670 |
-- invoked, but this happens only by means of "normal" elaboration, |
| 9671 |
-- therefore Gen must not be considered if this is not the case. |
| 9672 |
|
| 9673 |
if Is_Up_Level_Target |
| 9674 |
(Targ_Decl => Spec_Decl, |
| 9675 |
In_State => In_State) |
| 9676 |
then |
| 9677 |
return; |
| 9678 |
|
| 9679 |
-- Nothing to do when the instantiation is ABE-safe |
| 9680 |
-- |
| 9681 |
-- generic |
| 9682 |
-- package Gen is |
| 9683 |
-- ... |
| 9684 |
-- end Gen; |
| 9685 |
-- |
| 9686 |
-- package body Gen is |
| 9687 |
-- ... |
| 9688 |
-- end Gen; |
| 9689 |
-- |
| 9690 |
-- with Gen; |
| 9691 |
-- procedure Main is |
| 9692 |
-- package Inst is new Gen (ABE); -- safe instantiation |
| 9693 |
-- ... |
| 9694 |
|
| 9695 |
elsif Is_Safe_Instantiation (Inst, Gen_Id, Gen_Rep) then |
| 9696 |
return; |
| 9697 |
|
| 9698 |
-- An instantiation leads to a guaranteed ABE when the instantiation |
| 9699 |
-- and the generic appear within the same context ignoring library |
| 9700 |
-- levels, and the body of the generic has not been seen yet or |
| 9701 |
-- appears after the instantiation. |
| 9702 |
-- |
| 9703 |
-- procedure Guaranteed_ABE is |
| 9704 |
-- generic |
| 9705 |
-- procedure Gen; |
| 9706 |
-- |
| 9707 |
-- package Nested is |
| 9708 |
-- procedure Inst is new Gen; -- guaranteed ABE |
| 9709 |
-- end Nested; |
| 9710 |
-- |
| 9711 |
-- procedure Gen is |
| 9712 |
-- ... |
| 9713 |
-- end Gen; |
| 9714 |
-- ... |
| 9715 |
|
| 9716 |
elsif Is_Guaranteed_ABE |
| 9717 |
(N => Inst, |
| 9718 |
Target_Decl => Spec_Decl, |
| 9719 |
Target_Body => Body_Declaration (Gen_Rep)) |
| 9720 |
then |
| 9721 |
if Elaboration_Warnings_OK (Inst_Rep) then |
| 9722 |
Error_Msg_NE |
| 9723 |
("??cannot instantiate & before body seen", Inst, Gen_Id); |
| 9724 |
Error_Msg_N ("\Program_Error will be raised at run time", Inst); |
| 9725 |
end if; |
| 9726 |
|
| 9727 |
-- Mark the instantiation as a guarantee ABE. This automatically |
| 9728 |
-- suppresses the instantiation of the generic body. |
| 9729 |
|
| 9730 |
Set_Is_Known_Guaranteed_ABE (Inst); |
| 9731 |
|
| 9732 |
-- Install a run-time ABE failure because the instantiation will |
| 9733 |
-- always result in an ABE. |
| 9734 |
|
| 9735 |
if Check_OK then |
| 9736 |
Install_Scenario_ABE_Failure |
| 9737 |
(N => Inst, |
| 9738 |
Targ_Id => Gen_Id, |
| 9739 |
Targ_Rep => Gen_Rep, |
| 9740 |
Disable => Inst_Rep); |
| 9741 |
end if; |
| 9742 |
end if; |
| 9743 |
end Process_Guaranteed_ABE_Instantiation; |
| 9744 |
end Guaranteed_ABE_Processor; |
| 9745 |
|
| 9746 |
-------------- |
| 9747 |
-- Has_Body -- |
| 9748 |
-------------- |
| 9749 |
|
| 9750 |
function Has_Body (Pack_Decl : Node_Id) return Boolean is |
| 9751 |
function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id; |
| 9752 |
pragma Inline (Find_Corresponding_Body); |
| 9753 |
-- Try to locate the corresponding body of spec Spec_Id. If no body is |
| 9754 |
-- found, return Empty. |
| 9755 |
|
| 9756 |
function Find_Body |
| 9757 |
(Spec_Id : Entity_Id; |
| 9758 |
From : Node_Id) return Node_Id; |
| 9759 |
pragma Inline (Find_Body); |
| 9760 |
-- Try to locate the corresponding body of spec Spec_Id in the node list |
| 9761 |
-- which follows arbitrary node From. If no body is found, return Empty. |
| 9762 |
|
| 9763 |
function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id; |
| 9764 |
pragma Inline (Load_Package_Body); |
| 9765 |
-- Attempt to load the body of unit Unit_Nam. If the load failed, return |
| 9766 |
-- Empty. If the compilation will not generate code, return Empty. |
| 9767 |
|
| 9768 |
----------------------------- |
| 9769 |
-- Find_Corresponding_Body -- |
| 9770 |
----------------------------- |
| 9771 |
|
| 9772 |
function Find_Corresponding_Body (Spec_Id : Entity_Id) return Node_Id is |
| 9773 |
Context : constant Entity_Id := Scope (Spec_Id); |
| 9774 |
Spec_Decl : constant Node_Id := Unit_Declaration_Node (Spec_Id); |
| 9775 |
Body_Decl : Node_Id; |
| 9776 |
Body_Id : Entity_Id; |
| 9777 |
|
| 9778 |
begin |
| 9779 |
if Is_Compilation_Unit (Spec_Id) then |
| 9780 |
Body_Id := Corresponding_Body (Spec_Decl); |
| 9781 |
|
| 9782 |
if Present (Body_Id) then |
| 9783 |
return Unit_Declaration_Node (Body_Id); |
| 9784 |
|
| 9785 |
-- The package is at the library and requires a body. Load the |
| 9786 |
-- corresponding body because the optional body may be declared |
| 9787 |
-- there. |
| 9788 |
|
| 9789 |
elsif Unit_Requires_Body (Spec_Id) then |
| 9790 |
return |
| 9791 |
Load_Package_Body |
| 9792 |
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec_Decl)))); |
| 9793 |
|
| 9794 |
-- Otherwise there is no optional body |
| 9795 |
|
| 9796 |
else |
| 9797 |
return Empty; |
| 9798 |
end if; |
| 9799 |
|
| 9800 |
-- The immediate context is a package. The optional body may be |
| 9801 |
-- within the body of that package. |
| 9802 |
|
| 9803 |
-- procedure Proc is |
| 9804 |
-- package Nested_1 is |
| 9805 |
-- package Nested_2 is |
| 9806 |
-- generic |
| 9807 |
-- package Pack is |
| 9808 |
-- end Pack; |
| 9809 |
-- end Nested_2; |
| 9810 |
-- end Nested_1; |
| 9811 |
|
| 9812 |
-- package body Nested_1 is |
| 9813 |
-- package body Nested_2 is separate; |
| 9814 |
-- end Nested_1; |
| 9815 |
|
| 9816 |
-- separate (Proc.Nested_1.Nested_2) |
| 9817 |
-- package body Nested_2 is |
| 9818 |
-- package body Pack is -- optional body |
| 9819 |
-- ... |
| 9820 |
-- end Pack; |
| 9821 |
-- end Nested_2; |
| 9822 |
|
| 9823 |
elsif Is_Package_Or_Generic_Package (Context) then |
| 9824 |
Body_Decl := Find_Corresponding_Body (Context); |
| 9825 |
|
| 9826 |
-- The optional body is within the body of the enclosing package |
| 9827 |
|
| 9828 |
if Present (Body_Decl) then |
| 9829 |
return |
| 9830 |
Find_Body |
| 9831 |
(Spec_Id => Spec_Id, |
| 9832 |
From => First (Declarations (Body_Decl))); |
| 9833 |
|
| 9834 |
-- Otherwise the enclosing package does not have a body. This may |
| 9835 |
-- be the result of an error or a genuine lack of a body. |
| 9836 |
|
| 9837 |
else |
| 9838 |
return Empty; |
| 9839 |
end if; |
| 9840 |
|
| 9841 |
-- Otherwise the immediate context is a body. The optional body may |
| 9842 |
-- be within the same list as the spec. |
| 9843 |
|
| 9844 |
-- procedure Proc is |
| 9845 |
-- generic |
| 9846 |
-- package Pack is |
| 9847 |
-- end Pack; |
| 9848 |
|
| 9849 |
-- package body Pack is -- optional body |
| 9850 |
-- ... |
| 9851 |
-- end Pack; |
| 9852 |
|
| 9853 |
else |
| 9854 |
return |
| 9855 |
Find_Body |
| 9856 |
(Spec_Id => Spec_Id, |
| 9857 |
From => Next (Spec_Decl)); |
| 9858 |
end if; |
| 9859 |
end Find_Corresponding_Body; |
| 9860 |
|
| 9861 |
--------------- |
| 9862 |
-- Find_Body -- |
| 9863 |
--------------- |
| 9864 |
|
| 9865 |
function Find_Body |
| 9866 |
(Spec_Id : Entity_Id; |
| 9867 |
From : Node_Id) return Node_Id |
| 9868 |
is |
| 9869 |
Spec_Nam : constant Name_Id := Chars (Spec_Id); |
| 9870 |
Item : Node_Id; |
| 9871 |
Lib_Unit : Node_Id; |
| 9872 |
|
| 9873 |
begin |
| 9874 |
Item := From; |
| 9875 |
while Present (Item) loop |
| 9876 |
|
| 9877 |
-- The current item denotes the optional body |
| 9878 |
|
| 9879 |
if Nkind (Item) = N_Package_Body |
| 9880 |
and then Chars (Defining_Entity (Item)) = Spec_Nam |
| 9881 |
then |
| 9882 |
return Item; |
| 9883 |
|
| 9884 |
-- The current item denotes a stub, the optional body may be in |
| 9885 |
-- the subunit. |
| 9886 |
|
| 9887 |
elsif Nkind (Item) = N_Package_Body_Stub |
| 9888 |
and then Chars (Defining_Entity (Item)) = Spec_Nam |
| 9889 |
then |
| 9890 |
Lib_Unit := Stub_Subunit (Item); |
| 9891 |
|
| 9892 |
-- The corresponding subunit was previously loaded |
| 9893 |
|
| 9894 |
if Present (Lib_Unit) then |
| 9895 |
return Proper_Body (Unit (Lib_Unit)); |
| 9896 |
|
| 9897 |
-- Otherwise attempt to load the corresponding subunit |
| 9898 |
|
| 9899 |
else |
| 9900 |
return Load_Package_Body (Get_Unit_Name (Item)); |
| 9901 |
end if; |
| 9902 |
end if; |
| 9903 |
|
| 9904 |
Next (Item); |
| 9905 |
end loop; |
| 9906 |
|
| 9907 |
return Empty; |
| 9908 |
end Find_Body; |
| 9909 |
|
| 9910 |
----------------------- |
| 9911 |
-- Load_Package_Body -- |
| 9912 |
----------------------- |
| 9913 |
|
| 9914 |
function Load_Package_Body (Unit_Nam : Unit_Name_Type) return Node_Id is |
| 9915 |
Body_Decl : Node_Id; |
| 9916 |
Unit_Num : Unit_Number_Type; |
| 9917 |
|
| 9918 |
begin |
| 9919 |
-- The load is performed only when the compilation will generate code |
| 9920 |
|
| 9921 |
if Operating_Mode = Generate_Code then |
| 9922 |
Unit_Num := |
| 9923 |
Load_Unit |
| 9924 |
(Load_Name => Unit_Nam, |
| 9925 |
Required => False, |
| 9926 |
Subunit => False, |
| 9927 |
Error_Node => Pack_Decl); |
| 9928 |
|
| 9929 |
-- The load failed most likely because the physical file is |
| 9930 |
-- missing. |
| 9931 |
|
| 9932 |
if Unit_Num = No_Unit then |
| 9933 |
return Empty; |
| 9934 |
|
| 9935 |
-- Otherwise the load was successful, return the body of the unit |
| 9936 |
|
| 9937 |
else |
| 9938 |
Body_Decl := Unit (Cunit (Unit_Num)); |
| 9939 |
|
| 9940 |
-- If the unit is a subunit with an available proper body, |
| 9941 |
-- return the proper body. |
| 9942 |
|
| 9943 |
if Nkind (Body_Decl) = N_Subunit |
| 9944 |
and then Present (Proper_Body (Body_Decl)) |
| 9945 |
then |
| 9946 |
Body_Decl := Proper_Body (Body_Decl); |
| 9947 |
end if; |
| 9948 |
|
| 9949 |
return Body_Decl; |
| 9950 |
end if; |
| 9951 |
end if; |
| 9952 |
|
| 9953 |
return Empty; |
| 9954 |
end Load_Package_Body; |
| 9955 |
|
| 9956 |
-- Local variables |
| 9957 |
|
| 9958 |
Pack_Id : constant Entity_Id := Defining_Entity (Pack_Decl); |
| 9959 |
|
| 9960 |
-- Start of processing for Has_Body |
| 9961 |
|
| 9962 |
begin |
| 9963 |
-- The body is available |
| 9964 |
|
| 9965 |
if Present (Corresponding_Body (Pack_Decl)) then |
| 9966 |
return True; |
| 9967 |
|
| 9968 |
-- The body is required if the package spec contains a construct which |
| 9969 |
-- requires a completion in a body. |
| 9970 |
|
| 9971 |
elsif Unit_Requires_Body (Pack_Id) then |
| 9972 |
return True; |
| 9973 |
|
| 9974 |
-- The body may be optional |
| 9975 |
|
| 9976 |
else |
| 9977 |
return Present (Find_Corresponding_Body (Pack_Id)); |
| 9978 |
end if; |
| 9979 |
end Has_Body; |
| 9980 |
|
| 9981 |
---------- |
| 9982 |
-- Hash -- |
| 9983 |
---------- |
| 9984 |
|
| 9985 |
function Hash (NE : Node_Or_Entity_Id) return Bucket_Range_Type is |
| 9986 |
pragma Assert (Present (NE)); |
| 9987 |
begin |
| 9988 |
return Bucket_Range_Type (NE); |
| 9989 |
end Hash; |
| 9990 |
|
| 9991 |
-------------------------- |
| 9992 |
-- In_External_Instance -- |
| 9993 |
-------------------------- |
| 9994 |
|
| 9995 |
function In_External_Instance |
| 9996 |
(N : Node_Id; |
| 9997 |
Target_Decl : Node_Id) return Boolean |
| 9998 |
is |
| 9999 |
Inst : Node_Id; |
| 10000 |
Inst_Body : Node_Id; |
| 10001 |
Inst_Spec : Node_Id; |
| 10002 |
|
| 10003 |
begin |
| 10004 |
Inst := Find_Enclosing_Instance (Target_Decl); |
| 10005 |
|
| 10006 |
-- The target declaration appears within an instance spec. Visibility is |
| 10007 |
-- ignored because internally generated primitives for private types may |
| 10008 |
-- reside in the private declarations and still be invoked from outside. |
| 10009 |
|
| 10010 |
if Present (Inst) and then Nkind (Inst) = N_Package_Declaration then |
| 10011 |
|
| 10012 |
-- The scenario comes from the main unit and the instance does not |
| 10013 |
|
| 10014 |
if In_Extended_Main_Code_Unit (N) |
| 10015 |
and then not In_Extended_Main_Code_Unit (Inst) |
| 10016 |
then |
| 10017 |
return True; |
| 10018 |
|
| 10019 |
-- Otherwise the scenario must not appear within the instance spec or |
| 10020 |
-- body. |
| 10021 |
|
| 10022 |
else |
| 10023 |
Spec_And_Body_From_Node |
| 10024 |
(N => Inst, |
| 10025 |
Spec_Decl => Inst_Spec, |
| 10026 |
Body_Decl => Inst_Body); |
| 10027 |
|
| 10028 |
return not In_Subtree |
| 10029 |
(N => N, |
| 10030 |
Root1 => Inst_Spec, |
| 10031 |
Root2 => Inst_Body); |
| 10032 |
end if; |
| 10033 |
end if; |
| 10034 |
|
| 10035 |
return False; |
| 10036 |
end In_External_Instance; |
| 10037 |
|
| 10038 |
--------------------- |
| 10039 |
-- In_Main_Context -- |
| 10040 |
--------------------- |
| 10041 |
|
| 10042 |
function In_Main_Context (N : Node_Id) return Boolean is |
| 10043 |
begin |
| 10044 |
-- Scenarios outside the main unit are not considered because the ALI |
| 10045 |
-- information supplied to binde is for the main unit only. |
| 10046 |
|
| 10047 |
if not In_Extended_Main_Code_Unit (N) then |
| 10048 |
return False; |
| 10049 |
|
| 10050 |
-- Scenarios within internal units are not considered unless switch |
| 10051 |
-- -gnatdE (elaboration checks on predefined units) is in effect. |
| 10052 |
|
| 10053 |
elsif not Debug_Flag_EE and then In_Internal_Unit (N) then |
| 10054 |
return False; |
| 10055 |
end if; |
| 10056 |
|
| 10057 |
return True; |
| 10058 |
end In_Main_Context; |
| 10059 |
|
| 10060 |
--------------------- |
| 10061 |
-- In_Same_Context -- |
| 10062 |
--------------------- |
| 10063 |
|
| 10064 |
function In_Same_Context |
| 10065 |
(N1 : Node_Id; |
| 10066 |
N2 : Node_Id; |
| 10067 |
Nested_OK : Boolean := False) return Boolean |
| 10068 |
is |
| 10069 |
function Find_Enclosing_Context (N : Node_Id) return Node_Id; |
| 10070 |
pragma Inline (Find_Enclosing_Context); |
| 10071 |
-- Return the nearest enclosing non-library-level or compilation unit |
| 10072 |
-- node which encapsulates arbitrary node N. Return Empty is no such |
| 10073 |
-- context is available. |
| 10074 |
|
| 10075 |
function In_Nested_Context |
| 10076 |
(Outer : Node_Id; |
| 10077 |
Inner : Node_Id) return Boolean; |
| 10078 |
pragma Inline (In_Nested_Context); |
| 10079 |
-- Determine whether arbitrary node Outer encapsulates arbitrary node |
| 10080 |
-- Inner. |
| 10081 |
|
| 10082 |
---------------------------- |
| 10083 |
-- Find_Enclosing_Context -- |
| 10084 |
---------------------------- |
| 10085 |
|
| 10086 |
function Find_Enclosing_Context (N : Node_Id) return Node_Id is |
| 10087 |
Context : Node_Id; |
| 10088 |
Par : Node_Id; |
| 10089 |
|
| 10090 |
begin |
| 10091 |
Par := Parent (N); |
| 10092 |
while Present (Par) loop |
| 10093 |
|
| 10094 |
-- A traversal from a subunit continues via the corresponding stub |
| 10095 |
|
| 10096 |
if Nkind (Par) = N_Subunit then |
| 10097 |
Par := Corresponding_Stub (Par); |
| 10098 |
|
| 10099 |
-- Stop the traversal when the nearest enclosing non-library-level |
| 10100 |
-- encapsulator has been reached. |
| 10101 |
|
| 10102 |
elsif Is_Non_Library_Level_Encapsulator (Par) then |
| 10103 |
Context := Parent (Par); |
| 10104 |
|
| 10105 |
-- The sole exception is when the encapsulator is the unit of |
| 10106 |
-- compilation because this case requires special processing |
| 10107 |
-- (see below). |
| 10108 |
|
| 10109 |
if Present (Context) |
| 10110 |
and then Nkind (Context) = N_Compilation_Unit |
| 10111 |
then |
| 10112 |
null; |
| 10113 |
|
| 10114 |
else |
| 10115 |
return Par; |
| 10116 |
end if; |
| 10117 |
|
| 10118 |
-- Reaching a compilation unit node without hitting a non-library- |
| 10119 |
-- level encapsulator indicates that N is at the library level in |
| 10120 |
-- which case the compilation unit is the context. |
| 10121 |
|
| 10122 |
elsif Nkind (Par) = N_Compilation_Unit then |
| 10123 |
return Par; |
| 10124 |
end if; |
| 10125 |
|
| 10126 |
Par := Parent (Par); |
| 10127 |
end loop; |
| 10128 |
|
| 10129 |
return Empty; |
| 10130 |
end Find_Enclosing_Context; |
| 10131 |
|
| 10132 |
----------------------- |
| 10133 |
-- In_Nested_Context -- |
| 10134 |
----------------------- |
| 10135 |
|
| 10136 |
function In_Nested_Context |
| 10137 |
(Outer : Node_Id; |
| 10138 |
Inner : Node_Id) return Boolean |
| 10139 |
is |
| 10140 |
Par : Node_Id; |
| 10141 |
|
| 10142 |
begin |
| 10143 |
Par := Inner; |
| 10144 |
while Present (Par) loop |
| 10145 |
|
| 10146 |
-- A traversal from a subunit continues via the corresponding stub |
| 10147 |
|
| 10148 |
if Nkind (Par) = N_Subunit then |
| 10149 |
Par := Corresponding_Stub (Par); |
| 10150 |
|
| 10151 |
elsif Par = Outer then |
| 10152 |
return True; |
| 10153 |
end if; |
| 10154 |
|
| 10155 |
Par := Parent (Par); |
| 10156 |
end loop; |
| 10157 |
|
| 10158 |
return False; |
| 10159 |
end In_Nested_Context; |
| 10160 |
|
| 10161 |
-- Local variables |
| 10162 |
|
| 10163 |
Context_1 : constant Node_Id := Find_Enclosing_Context (N1); |
| 10164 |
Context_2 : constant Node_Id := Find_Enclosing_Context (N2); |
| 10165 |
|
| 10166 |
-- Start of processing for In_Same_Context |
| 10167 |
|
| 10168 |
begin |
| 10169 |
-- Both nodes appear within the same context |
| 10170 |
|
| 10171 |
if Context_1 = Context_2 then |
| 10172 |
return True; |
| 10173 |
|
| 10174 |
-- Both nodes appear in compilation units. Determine whether one unit |
| 10175 |
-- is the body of the other. |
| 10176 |
|
| 10177 |
elsif Nkind (Context_1) = N_Compilation_Unit |
| 10178 |
and then Nkind (Context_2) = N_Compilation_Unit |
| 10179 |
then |
| 10180 |
return |
| 10181 |
Is_Same_Unit |
| 10182 |
(Unit_1 => Defining_Entity (Unit (Context_1)), |
| 10183 |
Unit_2 => Defining_Entity (Unit (Context_2))); |
| 10184 |
|
| 10185 |
-- The context of N1 encloses the context of N2 |
| 10186 |
|
| 10187 |
elsif Nested_OK and then In_Nested_Context (Context_1, Context_2) then |
| 10188 |
return True; |
| 10189 |
end if; |
| 10190 |
|
| 10191 |
return False; |
| 10192 |
end In_Same_Context; |
| 10193 |
|
| 10194 |
---------------- |
| 10195 |
-- Initialize -- |
| 10196 |
---------------- |
| 10197 |
|
| 10198 |
procedure Initialize is |
| 10199 |
begin |
| 10200 |
-- Set the soft link which enables Atree.Rewrite to update a scenario |
| 10201 |
-- each time it is transformed into another node. |
| 10202 |
|
| 10203 |
Set_Rewriting_Proc (Update_Elaboration_Scenario'Access); |
| 10204 |
|
| 10205 |
-- Create all internal data structures and activate the elaboration |
| 10206 |
-- phase of the compiler. |
| 10207 |
|
| 10208 |
Initialize_All_Data_Structures; |
| 10209 |
Set_Elaboration_Phase (Active); |
| 10210 |
end Initialize; |
| 10211 |
|
| 10212 |
------------------------------------ |
| 10213 |
-- Initialize_All_Data_Structures -- |
| 10214 |
------------------------------------ |
| 10215 |
|
| 10216 |
procedure Initialize_All_Data_Structures is |
| 10217 |
begin |
| 10218 |
Initialize_Body_Processor; |
| 10219 |
Initialize_Early_Call_Region_Processor; |
| 10220 |
Initialize_Elaborated_Units; |
| 10221 |
Initialize_Internal_Representation; |
| 10222 |
Initialize_Invocation_Graph; |
| 10223 |
Initialize_Scenario_Storage; |
| 10224 |
end Initialize_All_Data_Structures; |
| 10225 |
|
| 10226 |
-------------------------- |
| 10227 |
-- Instantiated_Generic -- |
| 10228 |
-------------------------- |
| 10229 |
|
| 10230 |
function Instantiated_Generic (Inst : Node_Id) return Entity_Id is |
| 10231 |
begin |
| 10232 |
-- Traverse a possible chain of renamings to obtain the original generic |
| 10233 |
-- being instantiatied. |
| 10234 |
|
| 10235 |
return Get_Renamed_Entity (Entity (Name (Inst))); |
| 10236 |
end Instantiated_Generic; |
| 10237 |
|
| 10238 |
----------------------------- |
| 10239 |
-- Internal_Representation -- |
| 10240 |
----------------------------- |
| 10241 |
|
| 10242 |
package body Internal_Representation is |
| 10243 |
|
| 10244 |
----------- |
| 10245 |
-- Types -- |
| 10246 |
----------- |
| 10247 |
|
| 10248 |
-- The following type represents the contents of a scenario |
| 10249 |
|
| 10250 |
type Scenario_Rep_Record is record |
| 10251 |
Elab_Checks_OK : Boolean := False; |
| 10252 |
-- The status of elaboration checks for the scenario |
| 10253 |
|
| 10254 |
Elab_Warnings_OK : Boolean := False; |
| 10255 |
-- The status of elaboration warnings for the scenario |
| 10256 |
|
| 10257 |
GM : Extended_Ghost_Mode := Is_Checked_Or_Not_Specified; |
| 10258 |
-- The Ghost mode of the scenario |
| 10259 |
|
| 10260 |
Kind : Scenario_Kind := No_Scenario; |
| 10261 |
-- The nature of the scenario |
| 10262 |
|
| 10263 |
Level : Enclosing_Level_Kind := No_Level; |
| 10264 |
-- The enclosing level where the scenario resides |
| 10265 |
|
| 10266 |
SM : Extended_SPARK_Mode := Is_Off_Or_Not_Specified; |
| 10267 |
-- The SPARK mode of the scenario |
| 10268 |
|
| 10269 |
Target : Entity_Id := Empty; |
| 10270 |
-- The target of the scenario |
| 10271 |
|
| 10272 |
-- The following attributes are multiplexed and depend on the Kind of |
| 10273 |
-- the scenario. They are mapped as follows: |
| 10274 |
-- |
| 10275 |
-- Call_Scenario |
| 10276 |
-- Is_Dispatching_Call (Flag_1) |
| 10277 |
-- |
| 10278 |
-- Task_Activation_Scenario |
| 10279 |
-- Activated_Task_Objects (List_1) |
| 10280 |
-- Activated_Task_Type (Field_1) |
| 10281 |
-- |
| 10282 |
-- Variable_Reference |
| 10283 |
-- Is_Read_Reference (Flag_1) |
| 10284 |
|
| 10285 |
Flag_1 : Boolean := False; |
| 10286 |
Field_1 : Node_Or_Entity_Id := Empty; |
| 10287 |
List_1 : NE_List.Doubly_Linked_List := NE_List.Nil; |
| 10288 |
end record; |
| 10289 |
|
| 10290 |
-- The following type represents the contents of a target |
| 10291 |
|
| 10292 |
type Target_Rep_Record is record |
| 10293 |
Body_Decl : Node_Id := Empty; |
| 10294 |
-- The declaration of the target body |
| 10295 |
|
| 10296 |
Elab_Checks_OK : Boolean := False; |
| 10297 |
-- The status of elaboration checks for the target |
| 10298 |
|
| 10299 |
Elab_Warnings_OK : Boolean := False; |
| 10300 |
-- The status of elaboration warnings for the target |
| 10301 |
|
| 10302 |
GM : Extended_Ghost_Mode := Is_Checked_Or_Not_Specified; |
| 10303 |
-- The Ghost mode of the target |
| 10304 |
|
| 10305 |
Kind : Target_Kind := No_Target; |
| 10306 |
-- The nature of the target |
| 10307 |
|
| 10308 |
SM : Extended_SPARK_Mode := Is_Off_Or_Not_Specified; |
| 10309 |
-- The SPARK mode of the target |
| 10310 |
|
| 10311 |
Spec_Decl : Node_Id := Empty; |
| 10312 |
-- The declaration of the target spec |
| 10313 |
|
| 10314 |
Unit : Entity_Id := Empty; |
| 10315 |
-- The top unit where the target is declared |
| 10316 |
|
| 10317 |
Version : Representation_Kind := No_Representation; |
| 10318 |
-- The version of the target representation |
| 10319 |
|
| 10320 |
-- The following attributes are multiplexed and depend on the Kind of |
| 10321 |
-- the target. They are mapped as follows: |
| 10322 |
-- |
| 10323 |
-- Subprogram_Target |
| 10324 |
-- Barrier_Body_Declaration (Field_1) |
| 10325 |
-- |
| 10326 |
-- Variable_Target |
| 10327 |
-- Variable_Declaration (Field_1) |
| 10328 |
|
| 10329 |
Field_1 : Node_Or_Entity_Id := Empty; |
| 10330 |
end record; |
| 10331 |
|
| 10332 |
--------------------- |
| 10333 |
-- Data structures -- |
| 10334 |
--------------------- |
| 10335 |
|
| 10336 |
procedure Destroy (T_Id : in out Target_Rep_Id); |
| 10337 |
-- Destroy a target representation T_Id |
| 10338 |
|
| 10339 |
package ETT_Map is new Dynamic_Hash_Tables |
| 10340 |
(Key_Type => Entity_Id, |
| 10341 |
Value_Type => Target_Rep_Id, |
| 10342 |
No_Value => No_Target_Rep, |
| 10343 |
Expansion_Threshold => 1.5, |
| 10344 |
Expansion_Factor => 2, |
| 10345 |
Compression_Threshold => 0.3, |
| 10346 |
Compression_Factor => 2, |
| 10347 |
"=" => "=", |
| 10348 |
Destroy_Value => Destroy, |
| 10349 |
Hash => Hash); |
| 10350 |
|
| 10351 |
-- The following map relates target representations to entities |
| 10352 |
|
| 10353 |
Entity_To_Target_Map : ETT_Map.Dynamic_Hash_Table := ETT_Map.Nil; |
| 10354 |
|
| 10355 |
procedure Destroy (S_Id : in out Scenario_Rep_Id); |
| 10356 |
-- Destroy a scenario representation S_Id |
| 10357 |
|
| 10358 |
package NTS_Map is new Dynamic_Hash_Tables |
| 10359 |
(Key_Type => Node_Id, |
| 10360 |
Value_Type => Scenario_Rep_Id, |
| 10361 |
No_Value => No_Scenario_Rep, |
| 10362 |
Expansion_Threshold => 1.5, |
| 10363 |
Expansion_Factor => 2, |
| 10364 |
Compression_Threshold => 0.3, |
| 10365 |
Compression_Factor => 2, |
| 10366 |
"=" => "=", |
| 10367 |
Destroy_Value => Destroy, |
| 10368 |
Hash => Hash); |
| 10369 |
|
| 10370 |
-- The following map relates scenario representations to nodes |
| 10371 |
|
| 10372 |
Node_To_Scenario_Map : NTS_Map.Dynamic_Hash_Table := NTS_Map.Nil; |
| 10373 |
|
| 10374 |
-- The following table stores all scenario representations |
| 10375 |
|
| 10376 |
package Scenario_Reps is new Table.Table |
| 10377 |
(Table_Index_Type => Scenario_Rep_Id, |
| 10378 |
Table_Component_Type => Scenario_Rep_Record, |
| 10379 |
Table_Low_Bound => First_Scenario_Rep, |
| 10380 |
Table_Initial => 1000, |
| 10381 |
Table_Increment => 200, |
| 10382 |
Table_Name => "Scenario_Reps"); |
| 10383 |
|
| 10384 |
-- The following table stores all target representations |
| 10385 |
|
| 10386 |
package Target_Reps is new Table.Table |
| 10387 |
(Table_Index_Type => Target_Rep_Id, |
| 10388 |
Table_Component_Type => Target_Rep_Record, |
| 10389 |
Table_Low_Bound => First_Target_Rep, |
| 10390 |
Table_Initial => 1000, |
| 10391 |
Table_Increment => 200, |
| 10392 |
Table_Name => "Target_Reps"); |
| 10393 |
|
| 10394 |
-------------- |
| 10395 |
-- Builders -- |
| 10396 |
-------------- |
| 10397 |
|
| 10398 |
function Create_Access_Taken_Rep |
| 10399 |
(Attr : Node_Id) return Scenario_Rep_Record; |
| 10400 |
pragma Inline (Create_Access_Taken_Rep); |
| 10401 |
-- Create the representation of 'Access attribute Attr |
| 10402 |
|
| 10403 |
function Create_Call_Or_Task_Activation_Rep |
| 10404 |
(Call : Node_Id) return Scenario_Rep_Record; |
| 10405 |
pragma Inline (Create_Call_Or_Task_Activation_Rep); |
| 10406 |
-- Create the representation of call or task activation Call |
| 10407 |
|
| 10408 |
function Create_Derived_Type_Rep |
| 10409 |
(Typ_Decl : Node_Id) return Scenario_Rep_Record; |
| 10410 |
pragma Inline (Create_Derived_Type_Rep); |
| 10411 |
-- Create the representation of a derived type described by declaration |
| 10412 |
-- Typ_Decl. |
| 10413 |
|
| 10414 |
function Create_Generic_Rep |
| 10415 |
(Gen_Id : Entity_Id) return Target_Rep_Record; |
| 10416 |
pragma Inline (Create_Generic_Rep); |
| 10417 |
-- Create the representation of generic Gen_Id |
| 10418 |
|
| 10419 |
function Create_Instantiation_Rep |
| 10420 |
(Inst : Node_Id) return Scenario_Rep_Record; |
| 10421 |
pragma Inline (Create_Instantiation_Rep); |
| 10422 |
-- Create the representation of instantiation Inst |
| 10423 |
|
| 10424 |
function Create_Package_Rep |
| 10425 |
(Pack_Id : Entity_Id) return Target_Rep_Record; |
| 10426 |
pragma Inline (Create_Package_Rep); |
| 10427 |
-- Create the representation of package Pack_Id |
| 10428 |
|
| 10429 |
function Create_Protected_Entry_Rep |
| 10430 |
(PE_Id : Entity_Id) return Target_Rep_Record; |
| 10431 |
pragma Inline (Create_Protected_Entry_Rep); |
| 10432 |
-- Create the representation of protected entry PE_Id |
| 10433 |
|
| 10434 |
function Create_Protected_Subprogram_Rep |
| 10435 |
(PS_Id : Entity_Id) return Target_Rep_Record; |
| 10436 |
pragma Inline (Create_Protected_Subprogram_Rep); |
| 10437 |
-- Create the representation of protected subprogram PS_Id |
| 10438 |
|
| 10439 |
function Create_Refined_State_Pragma_Rep |
| 10440 |
(Prag : Node_Id) return Scenario_Rep_Record; |
| 10441 |
pragma Inline (Create_Refined_State_Pragma_Rep); |
| 10442 |
-- Create the representation of Refined_State pragma Prag |
| 10443 |
|
| 10444 |
function Create_Scenario_Rep |
| 10445 |
(N : Node_Id; |
| 10446 |
In_State : Processing_In_State) return Scenario_Rep_Record; |
| 10447 |
pragma Inline (Create_Scenario_Rep); |
| 10448 |
-- Top level dispatcher. Create the representation of elaboration |
| 10449 |
-- scenario N. In_State is the current state of the Processing phase. |
| 10450 |
|
| 10451 |
function Create_Subprogram_Rep |
| 10452 |
(Subp_Id : Entity_Id) return Target_Rep_Record; |
| 10453 |
pragma Inline (Create_Subprogram_Rep); |
| 10454 |
-- Create the representation of entry, operator, or subprogram Subp_Id |
| 10455 |
|
| 10456 |
function Create_Target_Rep |
| 10457 |
(Id : Entity_Id; |
| 10458 |
In_State : Processing_In_State) return Target_Rep_Record; |
| 10459 |
pragma Inline (Create_Target_Rep); |
| 10460 |
-- Top level dispatcher. Create the representation of elaboration target |
| 10461 |
-- Id. In_State is the current state of the Processing phase. |
| 10462 |
|
| 10463 |
function Create_Task_Entry_Rep |
| 10464 |
(TE_Id : Entity_Id) return Target_Rep_Record; |
| 10465 |
pragma Inline (Create_Task_Entry_Rep); |
| 10466 |
-- Create the representation of task entry TE_Id |
| 10467 |
|
| 10468 |
function Create_Task_Rep (Task_Typ : Entity_Id) return Target_Rep_Record; |
| 10469 |
pragma Inline (Create_Task_Rep); |
| 10470 |
-- Create the representation of task type Typ |
| 10471 |
|
| 10472 |
function Create_Variable_Assignment_Rep |
| 10473 |
(Asmt : Node_Id) return Scenario_Rep_Record; |
| 10474 |
pragma Inline (Create_Variable_Assignment_Rep); |
| 10475 |
-- Create the representation of variable assignment Asmt |
| 10476 |
|
| 10477 |
function Create_Variable_Reference_Rep |
| 10478 |
(Ref : Node_Id) return Scenario_Rep_Record; |
| 10479 |
pragma Inline (Create_Variable_Reference_Rep); |
| 10480 |
-- Create the representation of variable reference Ref |
| 10481 |
|
| 10482 |
function Create_Variable_Rep |
| 10483 |
(Var_Id : Entity_Id) return Target_Rep_Record; |
| 10484 |
pragma Inline (Create_Variable_Rep); |
| 10485 |
-- Create the representation of variable Var_Id |
| 10486 |
|
| 10487 |
----------------------- |
| 10488 |
-- Local subprograms -- |
| 10489 |
----------------------- |
| 10490 |
|
| 10491 |
function Ghost_Mode_Of_Entity |
| 10492 |
(Id : Entity_Id) return Extended_Ghost_Mode; |
| 10493 |
pragma Inline (Ghost_Mode_Of_Entity); |
| 10494 |
-- Obtain the extended Ghost mode of arbitrary entity Id |
| 10495 |
|
| 10496 |
function Ghost_Mode_Of_Node (N : Node_Id) return Extended_Ghost_Mode; |
| 10497 |
pragma Inline (Ghost_Mode_Of_Node); |
| 10498 |
-- Obtain the extended Ghost mode of arbitrary node N |
| 10499 |
|
| 10500 |
function Present (S_Id : Scenario_Rep_Id) return Boolean; |
| 10501 |
pragma Inline (Present); |
| 10502 |
-- Determine whether scenario representation S_Id exists |
| 10503 |
|
| 10504 |
function Present (T_Id : Target_Rep_Id) return Boolean; |
| 10505 |
pragma Inline (Present); |
| 10506 |
-- Determine whether target representation T_Id exists |
| 10507 |
|
| 10508 |
function SPARK_Mode_Of_Entity |
| 10509 |
(Id : Entity_Id) return Extended_SPARK_Mode; |
| 10510 |
pragma Inline (SPARK_Mode_Of_Entity); |
| 10511 |
-- Obtain the extended SPARK mode of arbitrary entity Id |
| 10512 |
|
| 10513 |
function SPARK_Mode_Of_Node (N : Node_Id) return Extended_SPARK_Mode; |
| 10514 |
pragma Inline (SPARK_Mode_Of_Node); |
| 10515 |
-- Obtain the extended SPARK mode of arbitrary node N |
| 10516 |
|
| 10517 |
function To_Ghost_Mode |
| 10518 |
(Ignored_Status : Boolean) return Extended_Ghost_Mode; |
| 10519 |
pragma Inline (To_Ghost_Mode); |
| 10520 |
-- Convert a Ghost mode indicated by Ignored_Status into its extended |
| 10521 |
-- equivalent. |
| 10522 |
|
| 10523 |
function To_SPARK_Mode (On_Status : Boolean) return Extended_SPARK_Mode; |
| 10524 |
pragma Inline (To_SPARK_Mode); |
| 10525 |
-- Convert a SPARK mode indicated by On_Status into its extended |
| 10526 |
-- equivalent. |
| 10527 |
|
| 10528 |
function Version (T_Id : Target_Rep_Id) return Representation_Kind; |
| 10529 |
pragma Inline (Version); |
| 10530 |
-- Obtain the version of target representation T_Id |
| 10531 |
|
| 10532 |
---------------------------- |
| 10533 |
-- Activated_Task_Objects -- |
| 10534 |
---------------------------- |
| 10535 |
|
| 10536 |
function Activated_Task_Objects |
| 10537 |
(S_Id : Scenario_Rep_Id) return NE_List.Doubly_Linked_List |
| 10538 |
is |
| 10539 |
pragma Assert (Present (S_Id)); |
| 10540 |
pragma Assert (Kind (S_Id) = Task_Activation_Scenario); |
| 10541 |
|
| 10542 |
begin |
| 10543 |
return Scenario_Reps.Table (S_Id).List_1; |
| 10544 |
end Activated_Task_Objects; |
| 10545 |
|
| 10546 |
------------------------- |
| 10547 |
-- Activated_Task_Type -- |
| 10548 |
------------------------- |
| 10549 |
|
| 10550 |
function Activated_Task_Type |
| 10551 |
(S_Id : Scenario_Rep_Id) return Entity_Id |
| 10552 |
is |
| 10553 |
pragma Assert (Present (S_Id)); |
| 10554 |
pragma Assert (Kind (S_Id) = Task_Activation_Scenario); |
| 10555 |
|
| 10556 |
begin |
| 10557 |
return Scenario_Reps.Table (S_Id).Field_1; |
| 10558 |
end Activated_Task_Type; |
| 10559 |
|
| 10560 |
------------------------------ |
| 10561 |
-- Barrier_Body_Declaration -- |
| 10562 |
------------------------------ |
| 10563 |
|
| 10564 |
function Barrier_Body_Declaration |
| 10565 |
(T_Id : Target_Rep_Id) return Node_Id |
| 10566 |
is |
| 10567 |
pragma Assert (Present (T_Id)); |
| 10568 |
pragma Assert (Kind (T_Id) = Subprogram_Target); |
| 10569 |
|
| 10570 |
begin |
| 10571 |
return Target_Reps.Table (T_Id).Field_1; |
| 10572 |
end Barrier_Body_Declaration; |
| 10573 |
|
| 10574 |
---------------------- |
| 10575 |
-- Body_Declaration -- |
| 10576 |
---------------------- |
| 10577 |
|
| 10578 |
function Body_Declaration (T_Id : Target_Rep_Id) return Node_Id is |
| 10579 |
pragma Assert (Present (T_Id)); |
| 10580 |
begin |
| 10581 |
return Target_Reps.Table (T_Id).Body_Decl; |
| 10582 |
end Body_Declaration; |
| 10583 |
|
| 10584 |
----------------------------- |
| 10585 |
-- Create_Access_Taken_Rep -- |
| 10586 |
----------------------------- |
| 10587 |
|
| 10588 |
function Create_Access_Taken_Rep |
| 10589 |
(Attr : Node_Id) return Scenario_Rep_Record |
| 10590 |
is |
| 10591 |
Rec : Scenario_Rep_Record; |
| 10592 |
|
| 10593 |
begin |
| 10594 |
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Attr); |
| 10595 |
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Attr); |
| 10596 |
Rec.GM := Is_Checked_Or_Not_Specified; |
| 10597 |
Rec.SM := SPARK_Mode_Of_Node (Attr); |
| 10598 |
Rec.Kind := Access_Taken_Scenario; |
| 10599 |
Rec.Target := Canonical_Subprogram (Entity (Prefix (Attr))); |
| 10600 |
|
| 10601 |
return Rec; |
| 10602 |
end Create_Access_Taken_Rep; |
| 10603 |
|
| 10604 |
---------------------------------------- |
| 10605 |
-- Create_Call_Or_Task_Activation_Rep -- |
| 10606 |
---------------------------------------- |
| 10607 |
|
| 10608 |
function Create_Call_Or_Task_Activation_Rep |
| 10609 |
(Call : Node_Id) return Scenario_Rep_Record |
| 10610 |
is |
| 10611 |
Subp_Id : constant Entity_Id := Canonical_Subprogram (Target (Call)); |
| 10612 |
Kind : Scenario_Kind; |
| 10613 |
Rec : Scenario_Rep_Record; |
| 10614 |
|
| 10615 |
begin |
| 10616 |
if Is_Activation_Proc (Subp_Id) then |
| 10617 |
Kind := Task_Activation_Scenario; |
| 10618 |
else |
| 10619 |
Kind := Call_Scenario; |
| 10620 |
end if; |
| 10621 |
|
| 10622 |
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Call); |
| 10623 |
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Call); |
| 10624 |
Rec.GM := Ghost_Mode_Of_Node (Call); |
| 10625 |
Rec.SM := SPARK_Mode_Of_Node (Call); |
| 10626 |
Rec.Kind := Kind; |
| 10627 |
Rec.Target := Subp_Id; |
| 10628 |
|
| 10629 |
-- Scenario-specific attributes |
| 10630 |
|
| 10631 |
Rec.Flag_1 := Is_Dispatching_Call (Call); -- Dispatching_Call |
| 10632 |
|
| 10633 |
return Rec; |
| 10634 |
end Create_Call_Or_Task_Activation_Rep; |
| 10635 |
|
| 10636 |
----------------------------- |
| 10637 |
-- Create_Derived_Type_Rep -- |
| 10638 |
----------------------------- |
| 10639 |
|
| 10640 |
function Create_Derived_Type_Rep |
| 10641 |
(Typ_Decl : Node_Id) return Scenario_Rep_Record |
| 10642 |
is |
| 10643 |
Typ : constant Entity_Id := Defining_Entity (Typ_Decl); |
| 10644 |
Rec : Scenario_Rep_Record; |
| 10645 |
|
| 10646 |
begin |
| 10647 |
Rec.Elab_Checks_OK := False; -- not relevant |
| 10648 |
Rec.Elab_Warnings_OK := False; -- not relevant |
| 10649 |
Rec.GM := Ghost_Mode_Of_Entity (Typ); |
| 10650 |
Rec.SM := SPARK_Mode_Of_Entity (Typ); |
| 10651 |
Rec.Kind := Derived_Type_Scenario; |
| 10652 |
Rec.Target := Typ; |
| 10653 |
|
| 10654 |
return Rec; |
| 10655 |
end Create_Derived_Type_Rep; |
| 10656 |
|
| 10657 |
------------------------ |
| 10658 |
-- Create_Generic_Rep -- |
| 10659 |
------------------------ |
| 10660 |
|
| 10661 |
function Create_Generic_Rep |
| 10662 |
(Gen_Id : Entity_Id) return Target_Rep_Record |
| 10663 |
is |
| 10664 |
Rec : Target_Rep_Record; |
| 10665 |
|
| 10666 |
begin |
| 10667 |
Rec.Kind := Generic_Target; |
| 10668 |
|
| 10669 |
Spec_And_Body_From_Entity |
| 10670 |
(Id => Gen_Id, |
| 10671 |
Body_Decl => Rec.Body_Decl, |
| 10672 |
Spec_Decl => Rec.Spec_Decl); |
| 10673 |
|
| 10674 |
return Rec; |
| 10675 |
end Create_Generic_Rep; |
| 10676 |
|
| 10677 |
------------------------------ |
| 10678 |
-- Create_Instantiation_Rep -- |
| 10679 |
------------------------------ |
| 10680 |
|
| 10681 |
function Create_Instantiation_Rep |
| 10682 |
(Inst : Node_Id) return Scenario_Rep_Record |
| 10683 |
is |
| 10684 |
Rec : Scenario_Rep_Record; |
| 10685 |
|
| 10686 |
begin |
| 10687 |
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Inst); |
| 10688 |
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Inst); |
| 10689 |
Rec.GM := Ghost_Mode_Of_Node (Inst); |
| 10690 |
Rec.SM := SPARK_Mode_Of_Node (Inst); |
| 10691 |
Rec.Kind := Instantiation_Scenario; |
| 10692 |
Rec.Target := Instantiated_Generic (Inst); |
| 10693 |
|
| 10694 |
return Rec; |
| 10695 |
end Create_Instantiation_Rep; |
| 10696 |
|
| 10697 |
------------------------ |
| 10698 |
-- Create_Package_Rep -- |
| 10699 |
------------------------ |
| 10700 |
|
| 10701 |
function Create_Package_Rep |
| 10702 |
(Pack_Id : Entity_Id) return Target_Rep_Record |
| 10703 |
is |
| 10704 |
Rec : Target_Rep_Record; |
| 10705 |
|
| 10706 |
begin |
| 10707 |
Rec.Kind := Package_Target; |
| 10708 |
|
| 10709 |
Spec_And_Body_From_Entity |
| 10710 |
(Id => Pack_Id, |
| 10711 |
Body_Decl => Rec.Body_Decl, |
| 10712 |
Spec_Decl => Rec.Spec_Decl); |
| 10713 |
|
| 10714 |
return Rec; |
| 10715 |
end Create_Package_Rep; |
| 10716 |
|
| 10717 |
-------------------------------- |
| 10718 |
-- Create_Protected_Entry_Rep -- |
| 10719 |
-------------------------------- |
| 10720 |
|
| 10721 |
function Create_Protected_Entry_Rep |
| 10722 |
(PE_Id : Entity_Id) return Target_Rep_Record |
| 10723 |
is |
| 10724 |
Prot_Id : constant Entity_Id := Protected_Body_Subprogram (PE_Id); |
| 10725 |
|
| 10726 |
Barf_Id : Entity_Id; |
| 10727 |
Dummy : Node_Id; |
| 10728 |
Rec : Target_Rep_Record; |
| 10729 |
Spec_Id : Entity_Id; |
| 10730 |
|
| 10731 |
begin |
| 10732 |
-- When the entry [family] has already been expanded, it carries both |
| 10733 |
-- the procedure which emulates the behavior of the entry [family] as |
| 10734 |
-- well as the barrier function. |
| 10735 |
|
| 10736 |
if Present (Prot_Id) then |
| 10737 |
Barf_Id := Barrier_Function (PE_Id); |
| 10738 |
Spec_Id := Prot_Id; |
| 10739 |
|
| 10740 |
-- Otherwise no expansion took place |
| 10741 |
|
| 10742 |
else |
| 10743 |
Barf_Id := Empty; |
| 10744 |
Spec_Id := PE_Id; |
| 10745 |
end if; |
| 10746 |
|
| 10747 |
Rec.Kind := Subprogram_Target; |
| 10748 |
|
| 10749 |
Spec_And_Body_From_Entity |
| 10750 |
(Id => Spec_Id, |
| 10751 |
Body_Decl => Rec.Body_Decl, |
| 10752 |
Spec_Decl => Rec.Spec_Decl); |
| 10753 |
|
| 10754 |
-- Target-specific attributes |
| 10755 |
|
| 10756 |
if Present (Barf_Id) then |
| 10757 |
Spec_And_Body_From_Entity |
| 10758 |
(Id => Barf_Id, |
| 10759 |
Body_Decl => Rec.Field_1, -- Barrier_Body_Declaration |
| 10760 |
Spec_Decl => Dummy); |
| 10761 |
end if; |
| 10762 |
|
| 10763 |
return Rec; |
| 10764 |
end Create_Protected_Entry_Rep; |
| 10765 |
|
| 10766 |
------------------------------------- |
| 10767 |
-- Create_Protected_Subprogram_Rep -- |
| 10768 |
------------------------------------- |
| 10769 |
|
| 10770 |
function Create_Protected_Subprogram_Rep |
| 10771 |
(PS_Id : Entity_Id) return Target_Rep_Record |
| 10772 |
is |
| 10773 |
Prot_Id : constant Entity_Id := Protected_Body_Subprogram (PS_Id); |
| 10774 |
Rec : Target_Rep_Record; |
| 10775 |
Spec_Id : Entity_Id; |
| 10776 |
|
| 10777 |
begin |
| 10778 |
-- When the protected subprogram has already been expanded, it |
| 10779 |
-- carries the subprogram which seizes the lock and invokes the |
| 10780 |
-- original statements. |
| 10781 |
|
| 10782 |
if Present (Prot_Id) then |
| 10783 |
Spec_Id := Prot_Id; |
| 10784 |
|
| 10785 |
-- Otherwise no expansion took place |
| 10786 |
|
| 10787 |
else |
| 10788 |
Spec_Id := PS_Id; |
| 10789 |
end if; |
| 10790 |
|
| 10791 |
Rec.Kind := Subprogram_Target; |
| 10792 |
|
| 10793 |
Spec_And_Body_From_Entity |
| 10794 |
(Id => Spec_Id, |
| 10795 |
Body_Decl => Rec.Body_Decl, |
| 10796 |
Spec_Decl => Rec.Spec_Decl); |
| 10797 |
|
| 10798 |
return Rec; |
| 10799 |
end Create_Protected_Subprogram_Rep; |
| 10800 |
|
| 10801 |
------------------------------------- |
| 10802 |
-- Create_Refined_State_Pragma_Rep -- |
| 10803 |
------------------------------------- |
| 10804 |
|
| 10805 |
function Create_Refined_State_Pragma_Rep |
| 10806 |
(Prag : Node_Id) return Scenario_Rep_Record |
| 10807 |
is |
| 10808 |
Rec : Scenario_Rep_Record; |
| 10809 |
|
| 10810 |
begin |
| 10811 |
Rec.Elab_Checks_OK := False; -- not relevant |
| 10812 |
Rec.Elab_Warnings_OK := False; -- not relevant |
| 10813 |
Rec.GM := |
| 10814 |
To_Ghost_Mode (Is_Ignored_Ghost_Pragma (Prag)); |
| 10815 |
Rec.SM := Is_Off_Or_Not_Specified; |
| 10816 |
Rec.Kind := Refined_State_Pragma_Scenario; |
| 10817 |
Rec.Target := Empty; |
| 10818 |
|
| 10819 |
return Rec; |
| 10820 |
end Create_Refined_State_Pragma_Rep; |
| 10821 |
|
| 10822 |
------------------------- |
| 10823 |
-- Create_Scenario_Rep -- |
| 10824 |
------------------------- |
| 10825 |
|
| 10826 |
function Create_Scenario_Rep |
| 10827 |
(N : Node_Id; |
| 10828 |
In_State : Processing_In_State) return Scenario_Rep_Record |
| 10829 |
is |
| 10830 |
pragma Unreferenced (In_State); |
| 10831 |
|
| 10832 |
Rec : Scenario_Rep_Record; |
| 10833 |
|
| 10834 |
begin |
| 10835 |
if Is_Suitable_Access_Taken (N) then |
| 10836 |
Rec := Create_Access_Taken_Rep (N); |
| 10837 |
|
| 10838 |
elsif Is_Suitable_Call (N) then |
| 10839 |
Rec := Create_Call_Or_Task_Activation_Rep (N); |
| 10840 |
|
| 10841 |
elsif Is_Suitable_Instantiation (N) then |
| 10842 |
Rec := Create_Instantiation_Rep (N); |
| 10843 |
|
| 10844 |
elsif Is_Suitable_SPARK_Derived_Type (N) then |
| 10845 |
Rec := Create_Derived_Type_Rep (N); |
| 10846 |
|
| 10847 |
elsif Is_Suitable_SPARK_Refined_State_Pragma (N) then |
| 10848 |
Rec := Create_Refined_State_Pragma_Rep (N); |
| 10849 |
|
| 10850 |
elsif Is_Suitable_Variable_Assignment (N) then |
| 10851 |
Rec := Create_Variable_Assignment_Rep (N); |
| 10852 |
|
| 10853 |
elsif Is_Suitable_Variable_Reference (N) then |
| 10854 |
Rec := Create_Variable_Reference_Rep (N); |
| 10855 |
|
| 10856 |
else |
| 10857 |
pragma Assert (False); |
| 10858 |
return Rec; |
| 10859 |
end if; |
| 10860 |
|
| 10861 |
-- Common scenario attributes |
| 10862 |
|
| 10863 |
Rec.Level := Find_Enclosing_Level (N); |
| 10864 |
|
| 10865 |
return Rec; |
| 10866 |
end Create_Scenario_Rep; |
| 10867 |
|
| 10868 |
--------------------------- |
| 10869 |
-- Create_Subprogram_Rep -- |
| 10870 |
--------------------------- |
| 10871 |
|
| 10872 |
function Create_Subprogram_Rep |
| 10873 |
(Subp_Id : Entity_Id) return Target_Rep_Record |
| 10874 |
is |
| 10875 |
Rec : Target_Rep_Record; |
| 10876 |
Spec_Id : Entity_Id; |
| 10877 |
|
| 10878 |
begin |
| 10879 |
Spec_Id := Subp_Id; |
| 10880 |
Rec.Kind := Subprogram_Target; |
| 10881 |
|
| 10882 |
Spec_And_Body_From_Entity |
| 10883 |
(Id => Spec_Id, |
| 10884 |
Body_Decl => Rec.Body_Decl, |
| 10885 |
Spec_Decl => Rec.Spec_Decl); |
| 10886 |
|
| 10887 |
return Rec; |
| 10888 |
end Create_Subprogram_Rep; |
| 10889 |
|
| 10890 |
----------------------- |
| 10891 |
-- Create_Target_Rep -- |
| 10892 |
----------------------- |
| 10893 |
|
| 10894 |
function Create_Target_Rep |
| 10895 |
(Id : Entity_Id; |
| 10896 |
In_State : Processing_In_State) return Target_Rep_Record |
| 10897 |
is |
| 10898 |
Rec : Target_Rep_Record; |
| 10899 |
|
| 10900 |
begin |
| 10901 |
if Is_Generic_Unit (Id) then |
| 10902 |
Rec := Create_Generic_Rep (Id); |
| 10903 |
|
| 10904 |
elsif Is_Protected_Entry (Id) then |
| 10905 |
Rec := Create_Protected_Entry_Rep (Id); |
| 10906 |
|
| 10907 |
elsif Is_Protected_Subp (Id) then |
| 10908 |
Rec := Create_Protected_Subprogram_Rep (Id); |
| 10909 |
|
| 10910 |
elsif Is_Task_Entry (Id) then |
| 10911 |
Rec := Create_Task_Entry_Rep (Id); |
| 10912 |
|
| 10913 |
elsif Is_Task_Type (Id) then |
| 10914 |
Rec := Create_Task_Rep (Id); |
| 10915 |
|
| 10916 |
elsif Ekind (Id) in E_Constant | E_Variable then |
| 10917 |
Rec := Create_Variable_Rep (Id); |
| 10918 |
|
| 10919 |
elsif Ekind (Id) in E_Entry | E_Function | E_Operator | E_Procedure |
| 10920 |
then |
| 10921 |
Rec := Create_Subprogram_Rep (Id); |
| 10922 |
|
| 10923 |
elsif Ekind (Id) = E_Package then |
| 10924 |
Rec := Create_Package_Rep (Id); |
| 10925 |
|
| 10926 |
else |
| 10927 |
pragma Assert (False); |
| 10928 |
return Rec; |
| 10929 |
end if; |
| 10930 |
|
| 10931 |
-- Common target attributes |
| 10932 |
|
| 10933 |
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Id (Id); |
| 10934 |
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Id (Id); |
| 10935 |
Rec.GM := Ghost_Mode_Of_Entity (Id); |
| 10936 |
Rec.SM := SPARK_Mode_Of_Entity (Id); |
| 10937 |
Rec.Unit := Find_Top_Unit (Id); |
| 10938 |
Rec.Version := In_State.Representation; |
| 10939 |
|
| 10940 |
return Rec; |
| 10941 |
end Create_Target_Rep; |
| 10942 |
|
| 10943 |
--------------------------- |
| 10944 |
-- Create_Task_Entry_Rep -- |
| 10945 |
--------------------------- |
| 10946 |
|
| 10947 |
function Create_Task_Entry_Rep |
| 10948 |
(TE_Id : Entity_Id) return Target_Rep_Record |
| 10949 |
is |
| 10950 |
Task_Typ : constant Entity_Id := Non_Private_View (Scope (TE_Id)); |
| 10951 |
Task_Body_Id : constant Entity_Id := Task_Body_Procedure (Task_Typ); |
| 10952 |
|
| 10953 |
Rec : Target_Rep_Record; |
| 10954 |
Spec_Id : Entity_Id; |
| 10955 |
|
| 10956 |
begin |
| 10957 |
-- The task type has already been expanded, it carries the procedure |
| 10958 |
-- which emulates the behavior of the task body. |
| 10959 |
|
| 10960 |
if Present (Task_Body_Id) then |
| 10961 |
Spec_Id := Task_Body_Id; |
| 10962 |
|
| 10963 |
-- Otherwise no expansion took place |
| 10964 |
|
| 10965 |
else |
| 10966 |
Spec_Id := TE_Id; |
| 10967 |
end if; |
| 10968 |
|
| 10969 |
Rec.Kind := Subprogram_Target; |
| 10970 |
|
| 10971 |
Spec_And_Body_From_Entity |
| 10972 |
(Id => Spec_Id, |
| 10973 |
Body_Decl => Rec.Body_Decl, |
| 10974 |
Spec_Decl => Rec.Spec_Decl); |
| 10975 |
|
| 10976 |
return Rec; |
| 10977 |
end Create_Task_Entry_Rep; |
| 10978 |
|
| 10979 |
--------------------- |
| 10980 |
-- Create_Task_Rep -- |
| 10981 |
--------------------- |
| 10982 |
|
| 10983 |
function Create_Task_Rep |
| 10984 |
(Task_Typ : Entity_Id) return Target_Rep_Record |
| 10985 |
is |
| 10986 |
Task_Body_Id : constant Entity_Id := Task_Body_Procedure (Task_Typ); |
| 10987 |
|
| 10988 |
Rec : Target_Rep_Record; |
| 10989 |
Spec_Id : Entity_Id; |
| 10990 |
|
| 10991 |
begin |
| 10992 |
-- The task type has already been expanded, it carries the procedure |
| 10993 |
-- which emulates the behavior of the task body. |
| 10994 |
|
| 10995 |
if Present (Task_Body_Id) then |
| 10996 |
Spec_Id := Task_Body_Id; |
| 10997 |
|
| 10998 |
-- Otherwise no expansion took place |
| 10999 |
|
| 11000 |
else |
| 11001 |
Spec_Id := Task_Typ; |
| 11002 |
end if; |
| 11003 |
|
| 11004 |
Rec.Kind := Task_Target; |
| 11005 |
|
| 11006 |
Spec_And_Body_From_Entity |
| 11007 |
(Id => Spec_Id, |
| 11008 |
Body_Decl => Rec.Body_Decl, |
| 11009 |
Spec_Decl => Rec.Spec_Decl); |
| 11010 |
|
| 11011 |
return Rec; |
| 11012 |
end Create_Task_Rep; |
| 11013 |
|
| 11014 |
------------------------------------ |
| 11015 |
-- Create_Variable_Assignment_Rep -- |
| 11016 |
------------------------------------ |
| 11017 |
|
| 11018 |
function Create_Variable_Assignment_Rep |
| 11019 |
(Asmt : Node_Id) return Scenario_Rep_Record |
| 11020 |
is |
| 11021 |
Var_Id : constant Entity_Id := Entity (Assignment_Target (Asmt)); |
| 11022 |
Rec : Scenario_Rep_Record; |
| 11023 |
|
| 11024 |
begin |
| 11025 |
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Asmt); |
| 11026 |
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Id (Var_Id); |
| 11027 |
Rec.GM := Ghost_Mode_Of_Node (Asmt); |
| 11028 |
Rec.SM := SPARK_Mode_Of_Node (Asmt); |
| 11029 |
Rec.Kind := Variable_Assignment_Scenario; |
| 11030 |
Rec.Target := Var_Id; |
| 11031 |
|
| 11032 |
return Rec; |
| 11033 |
end Create_Variable_Assignment_Rep; |
| 11034 |
|
| 11035 |
----------------------------------- |
| 11036 |
-- Create_Variable_Reference_Rep -- |
| 11037 |
----------------------------------- |
| 11038 |
|
| 11039 |
function Create_Variable_Reference_Rep |
| 11040 |
(Ref : Node_Id) return Scenario_Rep_Record |
| 11041 |
is |
| 11042 |
Rec : Scenario_Rep_Record; |
| 11043 |
|
| 11044 |
begin |
| 11045 |
Rec.Elab_Checks_OK := Is_Elaboration_Checks_OK_Node (Ref); |
| 11046 |
Rec.Elab_Warnings_OK := Is_Elaboration_Warnings_OK_Node (Ref); |
| 11047 |
Rec.GM := Ghost_Mode_Of_Node (Ref); |
| 11048 |
Rec.SM := SPARK_Mode_Of_Node (Ref); |
| 11049 |
Rec.Kind := Variable_Reference_Scenario; |
| 11050 |
Rec.Target := Target (Ref); |
| 11051 |
|
| 11052 |
-- Scenario-specific attributes |
| 11053 |
|
| 11054 |
Rec.Flag_1 := Is_Read (Ref); -- Is_Read_Reference |
| 11055 |
|
| 11056 |
return Rec; |
| 11057 |
end Create_Variable_Reference_Rep; |
| 11058 |
|
| 11059 |
------------------------- |
| 11060 |
-- Create_Variable_Rep -- |
| 11061 |
------------------------- |
| 11062 |
|
| 11063 |
function Create_Variable_Rep |
| 11064 |
(Var_Id : Entity_Id) return Target_Rep_Record |
| 11065 |
is |
| 11066 |
Rec : Target_Rep_Record; |
| 11067 |
|
| 11068 |
begin |
| 11069 |
Rec.Kind := Variable_Target; |
| 11070 |
|
| 11071 |
-- Target-specific attributes |
| 11072 |
|
| 11073 |
Rec.Field_1 := Declaration_Node (Var_Id); -- Variable_Declaration |
| 11074 |
|
| 11075 |
return Rec; |
| 11076 |
end Create_Variable_Rep; |
| 11077 |
|
| 11078 |
------------- |
| 11079 |
-- Destroy -- |
| 11080 |
------------- |
| 11081 |
|
| 11082 |
procedure Destroy (S_Id : in out Scenario_Rep_Id) is |
| 11083 |
pragma Unreferenced (S_Id); |
| 11084 |
begin |
| 11085 |
null; |
| 11086 |
end Destroy; |
| 11087 |
|
| 11088 |
------------- |
| 11089 |
-- Destroy -- |
| 11090 |
------------- |
| 11091 |
|
| 11092 |
procedure Destroy (T_Id : in out Target_Rep_Id) is |
| 11093 |
pragma Unreferenced (T_Id); |
| 11094 |
begin |
| 11095 |
null; |
| 11096 |
end Destroy; |
| 11097 |
|
| 11098 |
-------------------------------- |
| 11099 |
-- Disable_Elaboration_Checks -- |
| 11100 |
-------------------------------- |
| 11101 |
|
| 11102 |
procedure Disable_Elaboration_Checks (S_Id : Scenario_Rep_Id) is |
| 11103 |
pragma Assert (Present (S_Id)); |
| 11104 |
begin |
| 11105 |
Scenario_Reps.Table (S_Id).Elab_Checks_OK := False; |
| 11106 |
end Disable_Elaboration_Checks; |
| 11107 |
|
| 11108 |
-------------------------------- |
| 11109 |
-- Disable_Elaboration_Checks -- |
| 11110 |
-------------------------------- |
| 11111 |
|
| 11112 |
procedure Disable_Elaboration_Checks (T_Id : Target_Rep_Id) is |
| 11113 |
pragma Assert (Present (T_Id)); |
| 11114 |
begin |
| 11115 |
Target_Reps.Table (T_Id).Elab_Checks_OK := False; |
| 11116 |
end Disable_Elaboration_Checks; |
| 11117 |
|
| 11118 |
--------------------------- |
| 11119 |
-- Elaboration_Checks_OK -- |
| 11120 |
--------------------------- |
| 11121 |
|
| 11122 |
function Elaboration_Checks_OK (S_Id : Scenario_Rep_Id) return Boolean is |
| 11123 |
pragma Assert (Present (S_Id)); |
| 11124 |
begin |
| 11125 |
return Scenario_Reps.Table (S_Id).Elab_Checks_OK; |
| 11126 |
end Elaboration_Checks_OK; |
| 11127 |
|
| 11128 |
--------------------------- |
| 11129 |
-- Elaboration_Checks_OK -- |
| 11130 |
--------------------------- |
| 11131 |
|
| 11132 |
function Elaboration_Checks_OK (T_Id : Target_Rep_Id) return Boolean is |
| 11133 |
pragma Assert (Present (T_Id)); |
| 11134 |
begin |
| 11135 |
return Target_Reps.Table (T_Id).Elab_Checks_OK; |
| 11136 |
end Elaboration_Checks_OK; |
| 11137 |
|
| 11138 |
----------------------------- |
| 11139 |
-- Elaboration_Warnings_OK -- |
| 11140 |
----------------------------- |
| 11141 |
|
| 11142 |
function Elaboration_Warnings_OK |
| 11143 |
(S_Id : Scenario_Rep_Id) return Boolean |
| 11144 |
is |
| 11145 |
pragma Assert (Present (S_Id)); |
| 11146 |
begin |
| 11147 |
return Scenario_Reps.Table (S_Id).Elab_Warnings_OK; |
| 11148 |
end Elaboration_Warnings_OK; |
| 11149 |
|
| 11150 |
----------------------------- |
| 11151 |
-- Elaboration_Warnings_OK -- |
| 11152 |
----------------------------- |
| 11153 |
|
| 11154 |
function Elaboration_Warnings_OK (T_Id : Target_Rep_Id) return Boolean is |
| 11155 |
pragma Assert (Present (T_Id)); |
| 11156 |
begin |
| 11157 |
return Target_Reps.Table (T_Id).Elab_Warnings_OK; |
| 11158 |
end Elaboration_Warnings_OK; |
| 11159 |
|
| 11160 |
-------------------------------------- |
| 11161 |
-- Finalize_Internal_Representation -- |
| 11162 |
-------------------------------------- |
| 11163 |
|
| 11164 |
procedure Finalize_Internal_Representation is |
| 11165 |
begin |
| 11166 |
ETT_Map.Destroy (Entity_To_Target_Map); |
| 11167 |
NTS_Map.Destroy (Node_To_Scenario_Map); |
| 11168 |
end Finalize_Internal_Representation; |
| 11169 |
|
| 11170 |
------------------- |
| 11171 |
-- Ghost_Mode_Of -- |
| 11172 |
------------------- |
| 11173 |
|
| 11174 |
function Ghost_Mode_Of |
| 11175 |
(S_Id : Scenario_Rep_Id) return Extended_Ghost_Mode |
| 11176 |
is |
| 11177 |
pragma Assert (Present (S_Id)); |
| 11178 |
begin |
| 11179 |
return Scenario_Reps.Table (S_Id).GM; |
| 11180 |
end Ghost_Mode_Of; |
| 11181 |
|
| 11182 |
------------------- |
| 11183 |
-- Ghost_Mode_Of -- |
| 11184 |
------------------- |
| 11185 |
|
| 11186 |
function Ghost_Mode_Of |
| 11187 |
(T_Id : Target_Rep_Id) return Extended_Ghost_Mode |
| 11188 |
is |
| 11189 |
pragma Assert (Present (T_Id)); |
| 11190 |
begin |
| 11191 |
return Target_Reps.Table (T_Id).GM; |
| 11192 |
end Ghost_Mode_Of; |
| 11193 |
|
| 11194 |
-------------------------- |
| 11195 |
-- Ghost_Mode_Of_Entity -- |
| 11196 |
-------------------------- |
| 11197 |
|
| 11198 |
function Ghost_Mode_Of_Entity |
| 11199 |
(Id : Entity_Id) return Extended_Ghost_Mode |
| 11200 |
is |
| 11201 |
begin |
| 11202 |
return To_Ghost_Mode (Is_Ignored_Ghost_Entity (Id)); |
| 11203 |
end Ghost_Mode_Of_Entity; |
| 11204 |
|
| 11205 |
------------------------ |
| 11206 |
-- Ghost_Mode_Of_Node -- |
| 11207 |
------------------------ |
| 11208 |
|
| 11209 |
function Ghost_Mode_Of_Node (N : Node_Id) return Extended_Ghost_Mode is |
| 11210 |
begin |
| 11211 |
return To_Ghost_Mode (Is_Ignored_Ghost_Node (N)); |
| 11212 |
end Ghost_Mode_Of_Node; |
| 11213 |
|
| 11214 |
---------------------------------------- |
| 11215 |
-- Initialize_Internal_Representation -- |
| 11216 |
---------------------------------------- |
| 11217 |
|
| 11218 |
procedure Initialize_Internal_Representation is |
| 11219 |
begin |
| 11220 |
Entity_To_Target_Map := ETT_Map.Create (500); |
| 11221 |
Node_To_Scenario_Map := NTS_Map.Create (500); |
| 11222 |
end Initialize_Internal_Representation; |
| 11223 |
|
| 11224 |
------------------------- |
| 11225 |
-- Is_Dispatching_Call -- |
| 11226 |
------------------------- |
| 11227 |
|
| 11228 |
function Is_Dispatching_Call (S_Id : Scenario_Rep_Id) return Boolean is |
| 11229 |
pragma Assert (Present (S_Id)); |
| 11230 |
pragma Assert (Kind (S_Id) = Call_Scenario); |
| 11231 |
|
| 11232 |
begin |
| 11233 |
return Scenario_Reps.Table (S_Id).Flag_1; |
| 11234 |
end Is_Dispatching_Call; |
| 11235 |
|
| 11236 |
----------------------- |
| 11237 |
-- Is_Read_Reference -- |
| 11238 |
----------------------- |
| 11239 |
|
| 11240 |
function Is_Read_Reference (S_Id : Scenario_Rep_Id) return Boolean is |
| 11241 |
pragma Assert (Present (S_Id)); |
| 11242 |
pragma Assert (Kind (S_Id) = Variable_Reference_Scenario); |
| 11243 |
|
| 11244 |
begin |
| 11245 |
return Scenario_Reps.Table (S_Id).Flag_1; |
| 11246 |
end Is_Read_Reference; |
| 11247 |
|
| 11248 |
---------- |
| 11249 |
-- Kind -- |
| 11250 |
---------- |
| 11251 |
|
| 11252 |
function Kind (S_Id : Scenario_Rep_Id) return Scenario_Kind is |
| 11253 |
pragma Assert (Present (S_Id)); |
| 11254 |
begin |
| 11255 |
return Scenario_Reps.Table (S_Id).Kind; |
| 11256 |
end Kind; |
| 11257 |
|
| 11258 |
---------- |
| 11259 |
-- Kind -- |
| 11260 |
---------- |
| 11261 |
|
| 11262 |
function Kind (T_Id : Target_Rep_Id) return Target_Kind is |
| 11263 |
pragma Assert (Present (T_Id)); |
| 11264 |
begin |
| 11265 |
return Target_Reps.Table (T_Id).Kind; |
| 11266 |
end Kind; |
| 11267 |
|
| 11268 |
----------- |
| 11269 |
-- Level -- |
| 11270 |
----------- |
| 11271 |
|
| 11272 |
function Level (S_Id : Scenario_Rep_Id) return Enclosing_Level_Kind is |
| 11273 |
pragma Assert (Present (S_Id)); |
| 11274 |
begin |
| 11275 |
return Scenario_Reps.Table (S_Id).Level; |
| 11276 |
end Level; |
| 11277 |
|
| 11278 |
------------- |
| 11279 |
-- Present -- |
| 11280 |
------------- |
| 11281 |
|
| 11282 |
function Present (S_Id : Scenario_Rep_Id) return Boolean is |
| 11283 |
begin |
| 11284 |
return S_Id /= No_Scenario_Rep; |
| 11285 |
end Present; |
| 11286 |
|
| 11287 |
------------- |
| 11288 |
-- Present -- |
| 11289 |
------------- |
| 11290 |
|
| 11291 |
function Present (T_Id : Target_Rep_Id) return Boolean is |
| 11292 |
begin |
| 11293 |
return T_Id /= No_Target_Rep; |
| 11294 |
end Present; |
| 11295 |
|
| 11296 |
-------------------------------- |
| 11297 |
-- Scenario_Representation_Of -- |
| 11298 |
-------------------------------- |
| 11299 |
|
| 11300 |
function Scenario_Representation_Of |
| 11301 |
(N : Node_Id; |
| 11302 |
In_State : Processing_In_State) return Scenario_Rep_Id |
| 11303 |
is |
| 11304 |
S_Id : Scenario_Rep_Id; |
| 11305 |
|
| 11306 |
begin |
| 11307 |
S_Id := NTS_Map.Get (Node_To_Scenario_Map, N); |
| 11308 |
|
| 11309 |
-- The elaboration scenario lacks a representation. This indicates |
| 11310 |
-- that the scenario is encountered for the first time. Create the |
| 11311 |
-- representation of it. |
| 11312 |
|
| 11313 |
if not Present (S_Id) then |
| 11314 |
Scenario_Reps.Append (Create_Scenario_Rep (N, In_State)); |
| 11315 |
S_Id := Scenario_Reps.Last; |
| 11316 |
|
| 11317 |
-- Associate the internal representation with the elaboration |
| 11318 |
-- scenario. |
| 11319 |
|
| 11320 |
NTS_Map.Put (Node_To_Scenario_Map, N, S_Id); |
| 11321 |
end if; |
| 11322 |
|
| 11323 |
pragma Assert (Present (S_Id)); |
| 11324 |
|
| 11325 |
return S_Id; |
| 11326 |
end Scenario_Representation_Of; |
| 11327 |
|
| 11328 |
-------------------------------- |
| 11329 |
-- Set_Activated_Task_Objects -- |
| 11330 |
-------------------------------- |
| 11331 |
|
| 11332 |
procedure Set_Activated_Task_Objects |
| 11333 |
(S_Id : Scenario_Rep_Id; |
| 11334 |
Task_Objs : NE_List.Doubly_Linked_List) |
| 11335 |
is |
| 11336 |
pragma Assert (Present (S_Id)); |
| 11337 |
pragma Assert (Kind (S_Id) = Task_Activation_Scenario); |
| 11338 |
|
| 11339 |
begin |
| 11340 |
Scenario_Reps.Table (S_Id).List_1 := Task_Objs; |
| 11341 |
end Set_Activated_Task_Objects; |
| 11342 |
|
| 11343 |
----------------------------- |
| 11344 |
-- Set_Activated_Task_Type -- |
| 11345 |
----------------------------- |
| 11346 |
|
| 11347 |
procedure Set_Activated_Task_Type |
| 11348 |
(S_Id : Scenario_Rep_Id; |
| 11349 |
Task_Typ : Entity_Id) |
| 11350 |
is |
| 11351 |
pragma Assert (Present (S_Id)); |
| 11352 |
pragma Assert (Kind (S_Id) = Task_Activation_Scenario); |
| 11353 |
|
| 11354 |
begin |
| 11355 |
Scenario_Reps.Table (S_Id).Field_1 := Task_Typ; |
| 11356 |
end Set_Activated_Task_Type; |
| 11357 |
|
| 11358 |
------------------- |
| 11359 |
-- SPARK_Mode_Of -- |
| 11360 |
------------------- |
| 11361 |
|
| 11362 |
function SPARK_Mode_Of |
| 11363 |
(S_Id : Scenario_Rep_Id) return Extended_SPARK_Mode |
| 11364 |
is |
| 11365 |
pragma Assert (Present (S_Id)); |
| 11366 |
begin |
| 11367 |
return Scenario_Reps.Table (S_Id).SM; |
| 11368 |
end SPARK_Mode_Of; |
| 11369 |
|
| 11370 |
------------------- |
| 11371 |
-- SPARK_Mode_Of -- |
| 11372 |
------------------- |
| 11373 |
|
| 11374 |
function SPARK_Mode_Of |
| 11375 |
(T_Id : Target_Rep_Id) return Extended_SPARK_Mode |
| 11376 |
is |
| 11377 |
pragma Assert (Present (T_Id)); |
| 11378 |
begin |
| 11379 |
return Target_Reps.Table (T_Id).SM; |
| 11380 |
end SPARK_Mode_Of; |
| 11381 |
|
| 11382 |
-------------------------- |
| 11383 |
-- SPARK_Mode_Of_Entity -- |
| 11384 |
-------------------------- |
| 11385 |
|
| 11386 |
function SPARK_Mode_Of_Entity |
| 11387 |
(Id : Entity_Id) return Extended_SPARK_Mode |
| 11388 |
is |
| 11389 |
Prag : constant Node_Id := SPARK_Pragma (Id); |
| 11390 |
|
| 11391 |
begin |
| 11392 |
return |
| 11393 |
To_SPARK_Mode |
| 11394 |
(Present (Prag) |
| 11395 |
and then Get_SPARK_Mode_From_Annotation (Prag) = On); |
| 11396 |
end SPARK_Mode_Of_Entity; |
| 11397 |
|
| 11398 |
------------------------ |
| 11399 |
-- SPARK_Mode_Of_Node -- |
| 11400 |
------------------------ |
| 11401 |
|
| 11402 |
function SPARK_Mode_Of_Node (N : Node_Id) return Extended_SPARK_Mode is |
| 11403 |
begin |
| 11404 |
return To_SPARK_Mode (Is_SPARK_Mode_On_Node (N)); |
| 11405 |
end SPARK_Mode_Of_Node; |
| 11406 |
|
| 11407 |
---------------------- |
| 11408 |
-- Spec_Declaration -- |
| 11409 |
---------------------- |
| 11410 |
|
| 11411 |
function Spec_Declaration (T_Id : Target_Rep_Id) return Node_Id is |
| 11412 |
pragma Assert (Present (T_Id)); |
| 11413 |
begin |
| 11414 |
return Target_Reps.Table (T_Id).Spec_Decl; |
| 11415 |
end Spec_Declaration; |
| 11416 |
|
| 11417 |
------------ |
| 11418 |
-- Target -- |
| 11419 |
------------ |
| 11420 |
|
| 11421 |
function Target (S_Id : Scenario_Rep_Id) return Entity_Id is |
| 11422 |
pragma Assert (Present (S_Id)); |
| 11423 |
begin |
| 11424 |
return Scenario_Reps.Table (S_Id).Target; |
| 11425 |
end Target; |
| 11426 |
|
| 11427 |
------------------------------ |
| 11428 |
-- Target_Representation_Of -- |
| 11429 |
------------------------------ |
| 11430 |
|
| 11431 |
function Target_Representation_Of |
| 11432 |
(Id : Entity_Id; |
| 11433 |
In_State : Processing_In_State) return Target_Rep_Id |
| 11434 |
is |
| 11435 |
T_Id : Target_Rep_Id; |
| 11436 |
|
| 11437 |
begin |
| 11438 |
T_Id := ETT_Map.Get (Entity_To_Target_Map, Id); |
| 11439 |
|
| 11440 |
-- The elaboration target lacks an internal representation. This |
| 11441 |
-- indicates that the target is encountered for the first time. |
| 11442 |
-- Create the internal representation of it. |
| 11443 |
|
| 11444 |
if not Present (T_Id) then |
| 11445 |
Target_Reps.Append (Create_Target_Rep (Id, In_State)); |
| 11446 |
T_Id := Target_Reps.Last; |
| 11447 |
|
| 11448 |
-- Associate the internal representation with the elaboration |
| 11449 |
-- target. |
| 11450 |
|
| 11451 |
ETT_Map.Put (Entity_To_Target_Map, Id, T_Id); |
| 11452 |
|
| 11453 |
-- The Processing phase is working with a partially analyzed tree, |
| 11454 |
-- where various attributes become available as analysis continues. |
| 11455 |
-- This case arrises in the context of guaranteed ABE processing. |
| 11456 |
-- Update the existing representation by including new attributes. |
| 11457 |
|
| 11458 |
elsif In_State.Representation = Inconsistent_Representation then |
| 11459 |
Target_Reps.Table (T_Id) := Create_Target_Rep (Id, In_State); |
| 11460 |
|
| 11461 |
-- Otherwise the Processing phase imposes a particular representation |
| 11462 |
-- version which is not satisfied by the target. This case arrises |
| 11463 |
-- when the Processing phase switches from guaranteed ABE checks and |
| 11464 |
-- diagnostics to some other mode of operation. Update the existing |
| 11465 |
-- representation to include all attributes. |
| 11466 |
|
| 11467 |
elsif In_State.Representation /= Version (T_Id) then |
| 11468 |
Target_Reps.Table (T_Id) := Create_Target_Rep (Id, In_State); |
| 11469 |
end if; |
| 11470 |
|
| 11471 |
pragma Assert (Present (T_Id)); |
| 11472 |
|
| 11473 |
return T_Id; |
| 11474 |
end Target_Representation_Of; |
| 11475 |
|
| 11476 |
------------------- |
| 11477 |
-- To_Ghost_Mode -- |
| 11478 |
------------------- |
| 11479 |
|
| 11480 |
function To_Ghost_Mode |
| 11481 |
(Ignored_Status : Boolean) return Extended_Ghost_Mode |
| 11482 |
is |
| 11483 |
begin |
| 11484 |
if Ignored_Status then |
| 11485 |
return Is_Ignored; |
| 11486 |
else |
| 11487 |
return Is_Checked_Or_Not_Specified; |
| 11488 |
end if; |
| 11489 |
end To_Ghost_Mode; |
| 11490 |
|
| 11491 |
------------------- |
| 11492 |
-- To_SPARK_Mode -- |
| 11493 |
------------------- |
| 11494 |
|
| 11495 |
function To_SPARK_Mode |
| 11496 |
(On_Status : Boolean) return Extended_SPARK_Mode |
| 11497 |
is |
| 11498 |
begin |
| 11499 |
if On_Status then |
| 11500 |
return Is_On; |
| 11501 |
else |
| 11502 |
return Is_Off_Or_Not_Specified; |
| 11503 |
end if; |
| 11504 |
end To_SPARK_Mode; |
| 11505 |
|
| 11506 |
---------- |
| 11507 |
-- Unit -- |
| 11508 |
---------- |
| 11509 |
|
| 11510 |
function Unit (T_Id : Target_Rep_Id) return Entity_Id is |
| 11511 |
pragma Assert (Present (T_Id)); |
| 11512 |
begin |
| 11513 |
return Target_Reps.Table (T_Id).Unit; |
| 11514 |
end Unit; |
| 11515 |
|
| 11516 |
-------------------------- |
| 11517 |
-- Variable_Declaration -- |
| 11518 |
-------------------------- |
| 11519 |
|
| 11520 |
function Variable_Declaration (T_Id : Target_Rep_Id) return Node_Id is |
| 11521 |
pragma Assert (Present (T_Id)); |
| 11522 |
pragma Assert (Kind (T_Id) = Variable_Target); |
| 11523 |
|
| 11524 |
begin |
| 11525 |
return Target_Reps.Table (T_Id).Field_1; |
| 11526 |
end Variable_Declaration; |
| 11527 |
|
| 11528 |
------------- |
| 11529 |
-- Version -- |
| 11530 |
------------- |
| 11531 |
|
| 11532 |
function Version (T_Id : Target_Rep_Id) return Representation_Kind is |
| 11533 |
pragma Assert (Present (T_Id)); |
| 11534 |
begin |
| 11535 |
return Target_Reps.Table (T_Id).Version; |
| 11536 |
end Version; |
| 11537 |
end Internal_Representation; |
| 11538 |
|
| 11539 |
---------------------- |
| 11540 |
-- Invocation_Graph -- |
| 11541 |
---------------------- |
| 11542 |
|
| 11543 |
package body Invocation_Graph is |
| 11544 |
|
| 11545 |
----------- |
| 11546 |
-- Types -- |
| 11547 |
----------- |
| 11548 |
|
| 11549 |
-- The following type represents simplified version of an invocation |
| 11550 |
-- relation. |
| 11551 |
|
| 11552 |
type Invoker_Target_Relation is record |
| 11553 |
Invoker : Entity_Id := Empty; |
| 11554 |
Target : Entity_Id := Empty; |
| 11555 |
end record; |
| 11556 |
|
| 11557 |
-- The following variables define the entities of the dummy elaboration |
| 11558 |
-- procedures used as origins of library level paths. |
| 11559 |
|
| 11560 |
Elab_Body_Id : Entity_Id := Empty; |
| 11561 |
Elab_Spec_Id : Entity_Id := Empty; |
| 11562 |
|
| 11563 |
--------------------- |
| 11564 |
-- Data structures -- |
| 11565 |
--------------------- |
| 11566 |
|
| 11567 |
-- The following set contains all declared invocation constructs. It |
| 11568 |
-- ensures that the same construct is not declared multiple times in |
| 11569 |
-- the ALI file of the main unit. |
| 11570 |
|
| 11571 |
Saved_Constructs_Set : NE_Set.Membership_Set := NE_Set.Nil; |
| 11572 |
|
| 11573 |
function Hash (Key : Invoker_Target_Relation) return Bucket_Range_Type; |
| 11574 |
-- Obtain the hash value of pair Key |
| 11575 |
|
| 11576 |
package IR_Set is new Membership_Sets |
| 11577 |
(Element_Type => Invoker_Target_Relation, |
| 11578 |
"=" => "=", |
| 11579 |
Hash => Hash); |
| 11580 |
|
| 11581 |
-- The following set contains all recorded simple invocation relations. |
| 11582 |
-- It ensures that multiple relations involving the same invoker and |
| 11583 |
-- target do not appear in the ALI file of the main unit. |
| 11584 |
|
| 11585 |
Saved_Relations_Set : IR_Set.Membership_Set := IR_Set.Nil; |
| 11586 |
|
| 11587 |
-------------- |
| 11588 |
-- Builders -- |
| 11589 |
-------------- |
| 11590 |
|
| 11591 |
function Signature_Of (Id : Entity_Id) return Invocation_Signature_Id; |
| 11592 |
pragma Inline (Signature_Of); |
| 11593 |
-- Obtain the invication signature id of arbitrary entity Id |
| 11594 |
|
| 11595 |
----------------------- |
| 11596 |
-- Local subprograms -- |
| 11597 |
----------------------- |
| 11598 |
|
| 11599 |
procedure Build_Elaborate_Body_Procedure; |
| 11600 |
pragma Inline (Build_Elaborate_Body_Procedure); |
| 11601 |
-- Create a dummy elaborate body procedure and store its entity in |
| 11602 |
-- Elab_Body_Id. |
| 11603 |
|
| 11604 |
procedure Build_Elaborate_Procedure |
| 11605 |
(Proc_Id : out Entity_Id; |
| 11606 |
Proc_Nam : Name_Id; |
| 11607 |
Loc : Source_Ptr); |
| 11608 |
pragma Inline (Build_Elaborate_Procedure); |
| 11609 |
-- Create a dummy elaborate procedure with name Proc_Nam and source |
| 11610 |
-- location Loc. The entity is returned in Proc_Id. |
| 11611 |
|
| 11612 |
procedure Build_Elaborate_Spec_Procedure; |
| 11613 |
pragma Inline (Build_Elaborate_Spec_Procedure); |
| 11614 |
-- Create a dummy elaborate spec procedure and store its entity in |
| 11615 |
-- Elab_Spec_Id. |
| 11616 |
|
| 11617 |
function Build_Subprogram_Invocation |
| 11618 |
(Subp_Id : Entity_Id) return Node_Id; |
| 11619 |
pragma Inline (Build_Subprogram_Invocation); |
| 11620 |
-- Create a dummy call marker that invokes subprogram Subp_Id |
| 11621 |
|
| 11622 |
function Build_Task_Activation |
| 11623 |
(Task_Typ : Entity_Id; |
| 11624 |
In_State : Processing_In_State) return Node_Id; |
| 11625 |
pragma Inline (Build_Task_Activation); |
| 11626 |
-- Create a dummy call marker that activates an anonymous task object of |
| 11627 |
-- type Task_Typ. |
| 11628 |
|
| 11629 |
procedure Declare_Invocation_Construct |
| 11630 |
(Constr_Id : Entity_Id; |
| 11631 |
In_State : Processing_In_State); |
| 11632 |
pragma Inline (Declare_Invocation_Construct); |
| 11633 |
-- Declare invocation construct Constr_Id by creating a declaration for |
| 11634 |
-- it in the ALI file of the main unit. In_State is the current state of |
| 11635 |
-- the Processing phase. |
| 11636 |
|
| 11637 |
function Invocation_Graph_Recording_OK return Boolean; |
| 11638 |
pragma Inline (Invocation_Graph_Recording_OK); |
| 11639 |
-- Determine whether the invocation graph can be recorded |
| 11640 |
|
| 11641 |
function Is_Invocation_Scenario (N : Node_Id) return Boolean; |
| 11642 |
pragma Inline (Is_Invocation_Scenario); |
| 11643 |
-- Determine whether node N is a suitable scenario for invocation graph |
| 11644 |
-- recording purposes. |
| 11645 |
|
| 11646 |
function Is_Invocation_Target (Id : Entity_Id) return Boolean; |
| 11647 |
pragma Inline (Is_Invocation_Target); |
| 11648 |
-- Determine whether arbitrary entity Id denotes an invocation target |
| 11649 |
|
| 11650 |
function Is_Saved_Construct (Constr : Entity_Id) return Boolean; |
| 11651 |
pragma Inline (Is_Saved_Construct); |
| 11652 |
-- Determine whether invocation construct Constr has already been |
| 11653 |
-- declared in the ALI file of the main unit. |
| 11654 |
|
| 11655 |
function Is_Saved_Relation |
| 11656 |
(Rel : Invoker_Target_Relation) return Boolean; |
| 11657 |
pragma Inline (Is_Saved_Relation); |
| 11658 |
-- Determine whether simple invocation relation Rel has already been |
| 11659 |
-- recorded in the ALI file of the main unit. |
| 11660 |
|
| 11661 |
procedure Process_Declarations |
| 11662 |
(Decls : List_Id; |
| 11663 |
In_State : Processing_In_State); |
| 11664 |
pragma Inline (Process_Declarations); |
| 11665 |
-- Process declaration list Decls by processing all invocation scenarios |
| 11666 |
-- within it. |
| 11667 |
|
| 11668 |
procedure Process_Freeze_Node |
| 11669 |
(Fnode : Node_Id; |
| 11670 |
In_State : Processing_In_State); |
| 11671 |
pragma Inline (Process_Freeze_Node); |
| 11672 |
-- Process freeze node Fnode by processing all invocation scenarios in |
| 11673 |
-- its Actions list. |
| 11674 |
|
| 11675 |
procedure Process_Invocation_Activation |
| 11676 |
(Call : Node_Id; |
| 11677 |
Call_Rep : Scenario_Rep_Id; |
| 11678 |
Obj_Id : Entity_Id; |
| 11679 |
Obj_Rep : Target_Rep_Id; |
| 11680 |
Task_Typ : Entity_Id; |
| 11681 |
Task_Rep : Target_Rep_Id; |
| 11682 |
In_State : Processing_In_State); |
| 11683 |
pragma Inline (Process_Invocation_Activation); |
| 11684 |
-- Process activation call Call which activates object Obj_Id of task |
| 11685 |
-- type Task_Typ by processing all invocation scenarios within the task |
| 11686 |
-- body. Call_Rep is the representation of the call. Obj_Rep denotes the |
| 11687 |
-- representation of the object. Task_Rep is the representation of the |
| 11688 |
-- task type. In_State is the current state of the Processing phase. |
| 11689 |
|
| 11690 |
procedure Process_Invocation_Body_Scenarios; |
| 11691 |
pragma Inline (Process_Invocation_Body_Scenarios); |
| 11692 |
-- Process all library level body scenarios |
| 11693 |
|
| 11694 |
procedure Process_Invocation_Call |
| 11695 |
(Call : Node_Id; |
| 11696 |
Call_Rep : Scenario_Rep_Id; |
| 11697 |
In_State : Processing_In_State); |
| 11698 |
pragma Inline (Process_Invocation_Call); |
| 11699 |
-- Process invocation call scenario Call with representation Call_Rep. |
| 11700 |
-- In_State is the current state of the Processing phase. |
| 11701 |
|
| 11702 |
procedure Process_Invocation_Instantiation |
| 11703 |
(Inst : Node_Id; |
| 11704 |
Inst_Rep : Scenario_Rep_Id; |
| 11705 |
In_State : Processing_In_State); |
| 11706 |
pragma Inline (Process_Invocation_Instantiation); |
| 11707 |
-- Process invocation instantiation scenario Inst with representation |
| 11708 |
-- Inst_Rep. In_State is the current state of the Processing phase. |
| 11709 |
|
| 11710 |
procedure Process_Invocation_Scenario |
| 11711 |
(N : Node_Id; |
| 11712 |
In_State : Processing_In_State); |
| 11713 |
pragma Inline (Process_Invocation_Scenario); |
| 11714 |
-- Process single invocation scenario N. In_State is the current state |
| 11715 |
-- of the Processing phase. |
| 11716 |
|
| 11717 |
procedure Process_Invocation_Scenarios |
| 11718 |
(Iter : in out NE_Set.Iterator; |
| 11719 |
In_State : Processing_In_State); |
| 11720 |
pragma Inline (Process_Invocation_Scenarios); |
| 11721 |
-- Process all invocation scenarios obtained via iterator Iter. In_State |
| 11722 |
-- is the current state of the Processing phase. |
| 11723 |
|
| 11724 |
procedure Process_Invocation_Spec_Scenarios; |
| 11725 |
pragma Inline (Process_Invocation_Spec_Scenarios); |
| 11726 |
-- Process all library level spec scenarios |
| 11727 |
|
| 11728 |
procedure Process_Main_Unit; |
| 11729 |
pragma Inline (Process_Main_Unit); |
| 11730 |
-- Process all invocation scenarios within the main unit |
| 11731 |
|
| 11732 |
procedure Process_Package_Declaration |
| 11733 |
(Pack_Decl : Node_Id; |
| 11734 |
In_State : Processing_In_State); |
| 11735 |
pragma Inline (Process_Package_Declaration); |
| 11736 |
-- Process package declaration Pack_Decl by processing all invocation |
| 11737 |
-- scenarios in its visible and private declarations. If the main unit |
| 11738 |
-- contains a generic, the declarations of the body are also examined. |
| 11739 |
-- In_State is the current state of the Processing phase. |
| 11740 |
|
| 11741 |
procedure Process_Protected_Type_Declaration |
| 11742 |
(Prot_Decl : Node_Id; |
| 11743 |
In_State : Processing_In_State); |
| 11744 |
pragma Inline (Process_Protected_Type_Declaration); |
| 11745 |
-- Process the declarations of protected type Prot_Decl. In_State is the |
| 11746 |
-- current state of the Processing phase. |
| 11747 |
|
| 11748 |
procedure Process_Subprogram_Declaration |
| 11749 |
(Subp_Decl : Node_Id; |
| 11750 |
In_State : Processing_In_State); |
| 11751 |
pragma Inline (Process_Subprogram_Declaration); |
| 11752 |
-- Process subprogram declaration Subp_Decl by processing all invocation |
| 11753 |
-- scenarios within its body. In_State denotes the current state of the |
| 11754 |
-- Processing phase. |
| 11755 |
|
| 11756 |
procedure Process_Subprogram_Instantiation |
| 11757 |
(Inst : Node_Id; |
| 11758 |
In_State : Processing_In_State); |
| 11759 |
pragma Inline (Process_Subprogram_Instantiation); |
| 11760 |
-- Process subprogram instantiation Inst. In_State is the current state |
| 11761 |
-- of the Processing phase. |
| 11762 |
|
| 11763 |
procedure Process_Task_Type_Declaration |
| 11764 |
(Task_Decl : Node_Id; |
| 11765 |
In_State : Processing_In_State); |
| 11766 |
pragma Inline (Process_Task_Type_Declaration); |
| 11767 |
-- Process task declaration Task_Decl by processing all invocation |
| 11768 |
-- scenarios within its body. In_State is the current state of the |
| 11769 |
-- Processing phase. |
| 11770 |
|
| 11771 |
procedure Record_Full_Invocation_Path (In_State : Processing_In_State); |
| 11772 |
pragma Inline (Record_Full_Invocation_Path); |
| 11773 |
-- Record all relations between scenario pairs found in the stack of |
| 11774 |
-- active scenarios. In_State is the current state of the Processing |
| 11775 |
-- phase. |
| 11776 |
|
| 11777 |
procedure Record_Invocation_Graph_Encoding; |
| 11778 |
pragma Inline (Record_Invocation_Graph_Encoding); |
| 11779 |
-- Record the encoding format used to capture information related to |
| 11780 |
-- invocation constructs and relations. |
| 11781 |
|
| 11782 |
procedure Record_Invocation_Path (In_State : Processing_In_State); |
| 11783 |
pragma Inline (Record_Invocation_Path); |
| 11784 |
-- Record the invocation relations found within the path represented in |
| 11785 |
-- the active scenario stack. In_State denotes the current state of the |
| 11786 |
-- Processing phase. |
| 11787 |
|
| 11788 |
procedure Record_Simple_Invocation_Path (In_State : Processing_In_State); |
| 11789 |
pragma Inline (Record_Simple_Invocation_Path); |
| 11790 |
-- Record a single relation from the start to the end of the stack of |
| 11791 |
-- active scenarios. In_State is the current state of the Processing |
| 11792 |
-- phase. |
| 11793 |
|
| 11794 |
procedure Record_Invocation_Relation |
| 11795 |
(Invk_Id : Entity_Id; |
| 11796 |
Targ_Id : Entity_Id; |
| 11797 |
In_State : Processing_In_State); |
| 11798 |
pragma Inline (Record_Invocation_Relation); |
| 11799 |
-- Record an invocation relation with invoker Invk_Id and target Targ_Id |
| 11800 |
-- by creating an entry for it in the ALI file of the main unit. Formal |
| 11801 |
-- In_State denotes the current state of the Processing phase. |
| 11802 |
|
| 11803 |
procedure Set_Is_Saved_Construct (Constr : Entity_Id); |
| 11804 |
pragma Inline (Set_Is_Saved_Construct); |
| 11805 |
-- Mark invocation construct Constr as declared in the ALI file of the |
| 11806 |
-- main unit. |
| 11807 |
|
| 11808 |
procedure Set_Is_Saved_Relation (Rel : Invoker_Target_Relation); |
| 11809 |
pragma Inline (Set_Is_Saved_Relation); |
| 11810 |
-- Mark simple invocation relation Rel as recorded in the ALI file of |
| 11811 |
-- the main unit. |
| 11812 |
|
| 11813 |
function Target_Of |
| 11814 |
(Pos : Active_Scenario_Pos; |
| 11815 |
In_State : Processing_In_State) return Entity_Id; |
| 11816 |
pragma Inline (Target_Of); |
| 11817 |
-- Given position within the active scenario stack Pos, obtain the |
| 11818 |
-- target of the indicated scenario. In_State is the current state |
| 11819 |
-- of the Processing phase. |
| 11820 |
|
| 11821 |
procedure Traverse_Invocation_Body |
| 11822 |
(N : Node_Id; |
| 11823 |
In_State : Processing_In_State); |
| 11824 |
pragma Inline (Traverse_Invocation_Body); |
| 11825 |
-- Traverse subprogram body N looking for suitable invocation scenarios |
| 11826 |
-- that need to be processed for invocation graph recording purposes. |
| 11827 |
-- In_State is the current state of the Processing phase. |
| 11828 |
|
| 11829 |
procedure Write_Invocation_Path (In_State : Processing_In_State); |
| 11830 |
pragma Inline (Write_Invocation_Path); |
| 11831 |
-- Write out a path represented by the active scenario on the stack to |
| 11832 |
-- standard output. In_State denotes the current state of the Processing |
| 11833 |
-- phase. |
| 11834 |
|
| 11835 |
------------------------------------ |
| 11836 |
-- Build_Elaborate_Body_Procedure -- |
| 11837 |
------------------------------------ |
| 11838 |
|
| 11839 |
procedure Build_Elaborate_Body_Procedure is |
| 11840 |
Body_Decl : Node_Id; |
| 11841 |
Spec_Decl : Node_Id; |
| 11842 |
|
| 11843 |
begin |
| 11844 |
-- Nothing to do when a previous call already created the procedure |
| 11845 |
|
| 11846 |
if Present (Elab_Body_Id) then |
| 11847 |
return; |
| 11848 |
end if; |
| 11849 |
|
| 11850 |
Spec_And_Body_From_Entity |
| 11851 |
(Id => Main_Unit_Entity, |
| 11852 |
Body_Decl => Body_Decl, |
| 11853 |
Spec_Decl => Spec_Decl); |
| 11854 |
|
| 11855 |
pragma Assert (Present (Body_Decl)); |
| 11856 |
|
| 11857 |
Build_Elaborate_Procedure |
| 11858 |
(Proc_Id => Elab_Body_Id, |
| 11859 |
Proc_Nam => Name_B, |
| 11860 |
Loc => Sloc (Body_Decl)); |
| 11861 |
end Build_Elaborate_Body_Procedure; |
| 11862 |
|
| 11863 |
------------------------------- |
| 11864 |
-- Build_Elaborate_Procedure -- |
| 11865 |
------------------------------- |
| 11866 |
|
| 11867 |
procedure Build_Elaborate_Procedure |
| 11868 |
(Proc_Id : out Entity_Id; |
| 11869 |
Proc_Nam : Name_Id; |
| 11870 |
Loc : Source_Ptr) |
| 11871 |
is |
| 11872 |
Proc_Decl : Node_Id; |
| 11873 |
pragma Unreferenced (Proc_Decl); |
| 11874 |
|
| 11875 |
begin |
| 11876 |
Proc_Id := Make_Defining_Identifier (Loc, Proc_Nam); |
| 11877 |
|
| 11878 |
-- Partially decorate the elaboration procedure because it will not |
| 11879 |
-- be insertred into the tree and analyzed. |
| 11880 |
|
| 11881 |
Mutate_Ekind (Proc_Id, E_Procedure); |
| 11882 |
Set_Etype (Proc_Id, Standard_Void_Type); |
| 11883 |
Set_Scope (Proc_Id, Unique_Entity (Main_Unit_Entity)); |
| 11884 |
|
| 11885 |
-- Create a dummy declaration for the elaboration procedure. The |
| 11886 |
-- declaration does not need to be syntactically legal, but must |
| 11887 |
-- carry an accurate source location. |
| 11888 |
|
| 11889 |
Proc_Decl := |
| 11890 |
Make_Subprogram_Body (Loc, |
| 11891 |
Specification => |
| 11892 |
Make_Procedure_Specification (Loc, |
| 11893 |
Defining_Unit_Name => Proc_Id), |
| 11894 |
Declarations => No_List, |
| 11895 |
Handled_Statement_Sequence => Empty); |
| 11896 |
end Build_Elaborate_Procedure; |
| 11897 |
|
| 11898 |
------------------------------------ |
| 11899 |
-- Build_Elaborate_Spec_Procedure -- |
| 11900 |
------------------------------------ |
| 11901 |
|
| 11902 |
procedure Build_Elaborate_Spec_Procedure is |
| 11903 |
Body_Decl : Node_Id; |
| 11904 |
Spec_Decl : Node_Id; |
| 11905 |
|
| 11906 |
begin |
| 11907 |
-- Nothing to do when a previous call already created the procedure |
| 11908 |
|
| 11909 |
if Present (Elab_Spec_Id) then |
| 11910 |
return; |
| 11911 |
end if; |
| 11912 |
|
| 11913 |
Spec_And_Body_From_Entity |
| 11914 |
(Id => Main_Unit_Entity, |
| 11915 |
Body_Decl => Body_Decl, |
| 11916 |
Spec_Decl => Spec_Decl); |
| 11917 |
|
| 11918 |
pragma Assert (Present (Spec_Decl)); |
| 11919 |
|
| 11920 |
Build_Elaborate_Procedure |
| 11921 |
(Proc_Id => Elab_Spec_Id, |
| 11922 |
Proc_Nam => Name_S, |
| 11923 |
Loc => Sloc (Spec_Decl)); |
| 11924 |
end Build_Elaborate_Spec_Procedure; |
| 11925 |
|
| 11926 |
--------------------------------- |
| 11927 |
-- Build_Subprogram_Invocation -- |
| 11928 |
--------------------------------- |
| 11929 |
|
| 11930 |
function Build_Subprogram_Invocation |
| 11931 |
(Subp_Id : Entity_Id) return Node_Id |
| 11932 |
is |
| 11933 |
Marker : constant Node_Id := Make_Call_Marker (Sloc (Subp_Id)); |
| 11934 |
Subp_Decl : constant Node_Id := Unit_Declaration_Node (Subp_Id); |
| 11935 |
|
| 11936 |
begin |
| 11937 |
-- Create a dummy call marker which invokes the subprogram |
| 11938 |
|
| 11939 |
Set_Is_Declaration_Level_Node (Marker, False); |
| 11940 |
Set_Is_Dispatching_Call (Marker, False); |
| 11941 |
Set_Is_Elaboration_Checks_OK_Node (Marker, False); |
| 11942 |
Set_Is_Elaboration_Warnings_OK_Node (Marker, False); |
| 11943 |
Set_Is_Ignored_Ghost_Node (Marker, False); |
| 11944 |
Set_Is_Preelaborable_Call (Marker, False); |
| 11945 |
Set_Is_Source_Call (Marker, False); |
| 11946 |
Set_Is_SPARK_Mode_On_Node (Marker, False); |
| 11947 |
|
| 11948 |
-- Invoke the uniform canonical entity of the subprogram |
| 11949 |
|
| 11950 |
Set_Target (Marker, Canonical_Subprogram (Subp_Id)); |
| 11951 |
|
| 11952 |
-- Partially insert the marker into the tree |
| 11953 |
|
| 11954 |
Set_Parent (Marker, Parent (Subp_Decl)); |
| 11955 |
|
| 11956 |
return Marker; |
| 11957 |
end Build_Subprogram_Invocation; |
| 11958 |
|
| 11959 |
--------------------------- |
| 11960 |
-- Build_Task_Activation -- |
| 11961 |
--------------------------- |
| 11962 |
|
| 11963 |
function Build_Task_Activation |
| 11964 |
(Task_Typ : Entity_Id; |
| 11965 |
In_State : Processing_In_State) return Node_Id |
| 11966 |
is |
| 11967 |
Loc : constant Source_Ptr := Sloc (Task_Typ); |
| 11968 |
Marker : constant Node_Id := Make_Call_Marker (Loc); |
| 11969 |
Task_Decl : constant Node_Id := Unit_Declaration_Node (Task_Typ); |
| 11970 |
|
| 11971 |
Activ_Id : Entity_Id; |
| 11972 |
Marker_Rep_Id : Scenario_Rep_Id; |
| 11973 |
Task_Obj : Entity_Id; |
| 11974 |
Task_Objs : NE_List.Doubly_Linked_List; |
| 11975 |
|
| 11976 |
begin |
| 11977 |
-- Create a dummy call marker which activates some tasks |
| 11978 |
|
| 11979 |
Set_Is_Declaration_Level_Node (Marker, False); |
| 11980 |
Set_Is_Dispatching_Call (Marker, False); |
| 11981 |
Set_Is_Elaboration_Checks_OK_Node (Marker, False); |
| 11982 |
Set_Is_Elaboration_Warnings_OK_Node (Marker, False); |
| 11983 |
Set_Is_Ignored_Ghost_Node (Marker, False); |
| 11984 |
Set_Is_Preelaborable_Call (Marker, False); |
| 11985 |
Set_Is_Source_Call (Marker, False); |
| 11986 |
Set_Is_SPARK_Mode_On_Node (Marker, False); |
| 11987 |
|
| 11988 |
-- Invoke the appropriate version of Activate_Tasks |
| 11989 |
|
| 11990 |
if Restricted_Profile then |
| 11991 |
Activ_Id := RTE (RE_Activate_Restricted_Tasks); |
| 11992 |
else |
| 11993 |
Activ_Id := RTE (RE_Activate_Tasks); |
| 11994 |
end if; |
| 11995 |
|
| 11996 |
Set_Target (Marker, Activ_Id); |
| 11997 |
|
| 11998 |
-- Partially insert the marker into the tree |
| 11999 |
|
| 12000 |
Set_Parent (Marker, Parent (Task_Decl)); |
| 12001 |
|
| 12002 |
-- Create a dummy task object. Partially decorate the object because |
| 12003 |
-- it will not be inserted into the tree and analyzed. |
| 12004 |
|
| 12005 |
Task_Obj := Make_Temporary (Loc, 'T'); |
| 12006 |
Mutate_Ekind (Task_Obj, E_Variable); |
| 12007 |
Set_Etype (Task_Obj, Task_Typ); |
| 12008 |
|
| 12009 |
-- Associate the dummy task object with the activation call |
| 12010 |
|
| 12011 |
Task_Objs := NE_List.Create; |
| 12012 |
NE_List.Append (Task_Objs, Task_Obj); |
| 12013 |
|
| 12014 |
Marker_Rep_Id := Scenario_Representation_Of (Marker, In_State); |
| 12015 |
Set_Activated_Task_Objects (Marker_Rep_Id, Task_Objs); |
| 12016 |
Set_Activated_Task_Type (Marker_Rep_Id, Task_Typ); |
| 12017 |
|
| 12018 |
return Marker; |
| 12019 |
end Build_Task_Activation; |
| 12020 |
|
| 12021 |
---------------------------------- |
| 12022 |
-- Declare_Invocation_Construct -- |
| 12023 |
---------------------------------- |
| 12024 |
|
| 12025 |
procedure Declare_Invocation_Construct |
| 12026 |
(Constr_Id : Entity_Id; |
| 12027 |
In_State : Processing_In_State) |
| 12028 |
is |
| 12029 |
function Body_Placement_Of |
| 12030 |
(Id : Entity_Id) return Declaration_Placement_Kind; |
| 12031 |
pragma Inline (Body_Placement_Of); |
| 12032 |
-- Obtain the placement of arbitrary entity Id's body |
| 12033 |
|
| 12034 |
function Declaration_Placement_Of_Node |
| 12035 |
(N : Node_Id) return Declaration_Placement_Kind; |
| 12036 |
pragma Inline (Declaration_Placement_Of_Node); |
| 12037 |
-- Obtain the placement of arbitrary node N |
| 12038 |
|
| 12039 |
function Kind_Of (Id : Entity_Id) return Invocation_Construct_Kind; |
| 12040 |
pragma Inline (Kind_Of); |
| 12041 |
-- Obtain the invocation construct kind of arbitrary entity Id |
| 12042 |
|
| 12043 |
function Spec_Placement_Of |
| 12044 |
(Id : Entity_Id) return Declaration_Placement_Kind; |
| 12045 |
pragma Inline (Spec_Placement_Of); |
| 12046 |
-- Obtain the placement of arbitrary entity Id's spec |
| 12047 |
|
| 12048 |
----------------------- |
| 12049 |
-- Body_Placement_Of -- |
| 12050 |
----------------------- |
| 12051 |
|
| 12052 |
function Body_Placement_Of |
| 12053 |
(Id : Entity_Id) return Declaration_Placement_Kind |
| 12054 |
is |
| 12055 |
Id_Rep : constant Target_Rep_Id := |
| 12056 |
Target_Representation_Of (Id, In_State); |
| 12057 |
Body_Decl : constant Node_Id := Body_Declaration (Id_Rep); |
| 12058 |
Spec_Decl : constant Node_Id := Spec_Declaration (Id_Rep); |
| 12059 |
|
| 12060 |
begin |
| 12061 |
-- The entity has a body |
| 12062 |
|
| 12063 |
if Present (Body_Decl) then |
| 12064 |
return Declaration_Placement_Of_Node (Body_Decl); |
| 12065 |
|
| 12066 |
-- Otherwise the entity must have a spec |
| 12067 |
|
| 12068 |
else |
| 12069 |
pragma Assert (Present (Spec_Decl)); |
| 12070 |
return Declaration_Placement_Of_Node (Spec_Decl); |
| 12071 |
end if; |
| 12072 |
end Body_Placement_Of; |
| 12073 |
|
| 12074 |
----------------------------------- |
| 12075 |
-- Declaration_Placement_Of_Node -- |
| 12076 |
----------------------------------- |
| 12077 |
|
| 12078 |
function Declaration_Placement_Of_Node |
| 12079 |
(N : Node_Id) return Declaration_Placement_Kind |
| 12080 |
is |
| 12081 |
Main_Unit_Id : constant Entity_Id := Main_Unit_Entity; |
| 12082 |
N_Unit_Id : constant Entity_Id := Find_Top_Unit (N); |
| 12083 |
|
| 12084 |
begin |
| 12085 |
-- The node is in the main unit, its placement depends on the main |
| 12086 |
-- unit kind. |
| 12087 |
|
| 12088 |
if N_Unit_Id = Main_Unit_Id then |
| 12089 |
|
| 12090 |
-- The main unit is a body |
| 12091 |
|
| 12092 |
if Ekind (Main_Unit_Id) in E_Package_Body | E_Subprogram_Body |
| 12093 |
then |
| 12094 |
return In_Body; |
| 12095 |
|
| 12096 |
-- The main unit is a stand-alone subprogram body |
| 12097 |
|
| 12098 |
elsif Ekind (Main_Unit_Id) in E_Function | E_Procedure |
| 12099 |
and then Nkind (Unit_Declaration_Node (Main_Unit_Id)) = |
| 12100 |
N_Subprogram_Body |
| 12101 |
then |
| 12102 |
return In_Body; |
| 12103 |
|
| 12104 |
-- Otherwise the main unit is a spec |
| 12105 |
|
| 12106 |
else |
| 12107 |
return In_Spec; |
| 12108 |
end if; |
| 12109 |
|
| 12110 |
-- Otherwise the node is in the complementary unit of the main |
| 12111 |
-- unit. The main unit is a body, the node is in the spec. |
| 12112 |
|
| 12113 |
elsif Ekind (Main_Unit_Id) in E_Package_Body | E_Subprogram_Body |
| 12114 |
then |
| 12115 |
return In_Spec; |
| 12116 |
|
| 12117 |
-- The main unit is a spec, the node is in the body |
| 12118 |
|
| 12119 |
else |
| 12120 |
return In_Body; |
| 12121 |
end if; |
| 12122 |
end Declaration_Placement_Of_Node; |
| 12123 |
|
| 12124 |
------------- |
| 12125 |
-- Kind_Of -- |
| 12126 |
------------- |
| 12127 |
|
| 12128 |
function Kind_Of (Id : Entity_Id) return Invocation_Construct_Kind is |
| 12129 |
begin |
| 12130 |
if Id = Elab_Body_Id then |
| 12131 |
return Elaborate_Body_Procedure; |
| 12132 |
|
| 12133 |
elsif Id = Elab_Spec_Id then |
| 12134 |
return Elaborate_Spec_Procedure; |
| 12135 |
|
| 12136 |
else |
| 12137 |
return Regular_Construct; |
| 12138 |
end if; |
| 12139 |
end Kind_Of; |
| 12140 |
|
| 12141 |
----------------------- |
| 12142 |
-- Spec_Placement_Of -- |
| 12143 |
----------------------- |
| 12144 |
|
| 12145 |
function Spec_Placement_Of |
| 12146 |
(Id : Entity_Id) return Declaration_Placement_Kind |
| 12147 |
is |
| 12148 |
Id_Rep : constant Target_Rep_Id := |
| 12149 |
Target_Representation_Of (Id, In_State); |
| 12150 |
Body_Decl : constant Node_Id := Body_Declaration (Id_Rep); |
| 12151 |
Spec_Decl : constant Node_Id := Spec_Declaration (Id_Rep); |
| 12152 |
|
| 12153 |
begin |
| 12154 |
-- The entity has a spec |
| 12155 |
|
| 12156 |
if Present (Spec_Decl) then |
| 12157 |
return Declaration_Placement_Of_Node (Spec_Decl); |
| 12158 |
|
| 12159 |
-- Otherwise the entity must have a body |
| 12160 |
|
| 12161 |
else |
| 12162 |
pragma Assert (Present (Body_Decl)); |
| 12163 |
return Declaration_Placement_Of_Node (Body_Decl); |
| 12164 |
end if; |
| 12165 |
end Spec_Placement_Of; |
| 12166 |
|
| 12167 |
-- Start of processing for Declare_Invocation_Construct |
| 12168 |
|
| 12169 |
begin |
| 12170 |
-- Nothing to do when the construct has already been declared in the |
| 12171 |
-- ALI file. |
| 12172 |
|
| 12173 |
if Is_Saved_Construct (Constr_Id) then |
| 12174 |
return; |
| 12175 |
end if; |
| 12176 |
|
| 12177 |
-- Mark the construct as declared in the ALI file |
| 12178 |
|
| 12179 |
Set_Is_Saved_Construct (Constr_Id); |
| 12180 |
|
| 12181 |
-- Add the construct in the ALI file |
| 12182 |
|
| 12183 |
Add_Invocation_Construct |
| 12184 |
(Body_Placement => Body_Placement_Of (Constr_Id), |
| 12185 |
Kind => Kind_Of (Constr_Id), |
| 12186 |
Signature => Signature_Of (Constr_Id), |
| 12187 |
Spec_Placement => Spec_Placement_Of (Constr_Id), |
| 12188 |
Update_Units => False); |
| 12189 |
end Declare_Invocation_Construct; |
| 12190 |
|
| 12191 |
------------------------------- |
| 12192 |
-- Finalize_Invocation_Graph -- |
| 12193 |
------------------------------- |
| 12194 |
|
| 12195 |
procedure Finalize_Invocation_Graph is |
| 12196 |
begin |
| 12197 |
NE_Set.Destroy (Saved_Constructs_Set); |
| 12198 |
IR_Set.Destroy (Saved_Relations_Set); |
| 12199 |
end Finalize_Invocation_Graph; |
| 12200 |
|
| 12201 |
---------- |
| 12202 |
-- Hash -- |
| 12203 |
---------- |
| 12204 |
|
| 12205 |
function Hash (Key : Invoker_Target_Relation) return Bucket_Range_Type is |
| 12206 |
pragma Assert (Present (Key.Invoker)); |
| 12207 |
pragma Assert (Present (Key.Target)); |
| 12208 |
|
| 12209 |
begin |
| 12210 |
return |
| 12211 |
Hash_Two_Keys |
| 12212 |
(Bucket_Range_Type (Key.Invoker), |
| 12213 |
Bucket_Range_Type (Key.Target)); |
| 12214 |
end Hash; |
| 12215 |
|
| 12216 |
--------------------------------- |
| 12217 |
-- Initialize_Invocation_Graph -- |
| 12218 |
--------------------------------- |
| 12219 |
|
| 12220 |
procedure Initialize_Invocation_Graph is |
| 12221 |
begin |
| 12222 |
Saved_Constructs_Set := NE_Set.Create (100); |
| 12223 |
Saved_Relations_Set := IR_Set.Create (200); |
| 12224 |
end Initialize_Invocation_Graph; |
| 12225 |
|
| 12226 |
----------------------------------- |
| 12227 |
-- Invocation_Graph_Recording_OK -- |
| 12228 |
----------------------------------- |
| 12229 |
|
| 12230 |
function Invocation_Graph_Recording_OK return Boolean is |
| 12231 |
Main_Cunit : constant Node_Id := Cunit (Main_Unit); |
| 12232 |
|
| 12233 |
begin |
| 12234 |
-- Nothing to do when compiling for GNATprove because the invocation |
| 12235 |
-- graph is not needed. |
| 12236 |
|
| 12237 |
if GNATprove_Mode then |
| 12238 |
return False; |
| 12239 |
|
| 12240 |
-- Nothing to do when the compilation will not produce an ALI file |
| 12241 |
|
| 12242 |
elsif Serious_Errors_Detected > 0 then |
| 12243 |
return False; |
| 12244 |
|
| 12245 |
-- Nothing to do when the main unit requires a body. Processing the |
| 12246 |
-- completing body will create the ALI file for the unit and record |
| 12247 |
-- the invocation graph. |
| 12248 |
|
| 12249 |
elsif Body_Required (Main_Cunit) then |
| 12250 |
return False; |
| 12251 |
end if; |
| 12252 |
|
| 12253 |
return True; |
| 12254 |
end Invocation_Graph_Recording_OK; |
| 12255 |
|
| 12256 |
---------------------------- |
| 12257 |
-- Is_Invocation_Scenario -- |
| 12258 |
---------------------------- |
| 12259 |
|
| 12260 |
function Is_Invocation_Scenario (N : Node_Id) return Boolean is |
| 12261 |
begin |
| 12262 |
return |
| 12263 |
Is_Suitable_Access_Taken (N) |
| 12264 |
or else Is_Suitable_Call (N) |
| 12265 |
or else Is_Suitable_Instantiation (N); |
| 12266 |
end Is_Invocation_Scenario; |
| 12267 |
|
| 12268 |
-------------------------- |
| 12269 |
-- Is_Invocation_Target -- |
| 12270 |
-------------------------- |
| 12271 |
|
| 12272 |
function Is_Invocation_Target (Id : Entity_Id) return Boolean is |
| 12273 |
begin |
| 12274 |
-- To qualify, the entity must either come from source, or denote an |
| 12275 |
-- Ada, bridge, or SPARK target. |
| 12276 |
|
| 12277 |
return |
| 12278 |
Comes_From_Source (Id) |
| 12279 |
or else Is_Ada_Semantic_Target (Id) |
| 12280 |
or else Is_Bridge_Target (Id) |
| 12281 |
or else Is_SPARK_Semantic_Target (Id); |
| 12282 |
end Is_Invocation_Target; |
| 12283 |
|
| 12284 |
------------------------ |
| 12285 |
-- Is_Saved_Construct -- |
| 12286 |
------------------------ |
| 12287 |
|
| 12288 |
function Is_Saved_Construct (Constr : Entity_Id) return Boolean is |
| 12289 |
pragma Assert (Present (Constr)); |
| 12290 |
begin |
| 12291 |
return NE_Set.Contains (Saved_Constructs_Set, Constr); |
| 12292 |
end Is_Saved_Construct; |
| 12293 |
|
| 12294 |
----------------------- |
| 12295 |
-- Is_Saved_Relation -- |
| 12296 |
----------------------- |
| 12297 |
|
| 12298 |
function Is_Saved_Relation |
| 12299 |
(Rel : Invoker_Target_Relation) return Boolean |
| 12300 |
is |
| 12301 |
pragma Assert (Present (Rel.Invoker)); |
| 12302 |
pragma Assert (Present (Rel.Target)); |
| 12303 |
|
| 12304 |
begin |
| 12305 |
return IR_Set.Contains (Saved_Relations_Set, Rel); |
| 12306 |
end Is_Saved_Relation; |
| 12307 |
|
| 12308 |
-------------------------- |
| 12309 |
-- Process_Declarations -- |
| 12310 |
-------------------------- |
| 12311 |
|
| 12312 |
procedure Process_Declarations |
| 12313 |
(Decls : List_Id; |
| 12314 |
In_State : Processing_In_State) |
| 12315 |
is |
| 12316 |
Decl : Node_Id; |
| 12317 |
|
| 12318 |
begin |
| 12319 |
Decl := First (Decls); |
| 12320 |
while Present (Decl) loop |
| 12321 |
|
| 12322 |
-- Freeze node |
| 12323 |
|
| 12324 |
if Nkind (Decl) = N_Freeze_Entity then |
| 12325 |
Process_Freeze_Node |
| 12326 |
(Fnode => Decl, |
| 12327 |
In_State => In_State); |
| 12328 |
|
| 12329 |
-- Package (nested) |
| 12330 |
|
| 12331 |
elsif Nkind (Decl) = N_Package_Declaration then |
| 12332 |
Process_Package_Declaration |
| 12333 |
(Pack_Decl => Decl, |
| 12334 |
In_State => In_State); |
| 12335 |
|
| 12336 |
-- Protected type |
| 12337 |
|
| 12338 |
elsif Nkind (Decl) in N_Protected_Type_Declaration |
| 12339 |
| N_Single_Protected_Declaration |
| 12340 |
then |
| 12341 |
Process_Protected_Type_Declaration |
| 12342 |
(Prot_Decl => Decl, |
| 12343 |
In_State => In_State); |
| 12344 |
|
| 12345 |
-- Subprogram or entry |
| 12346 |
|
| 12347 |
elsif Nkind (Decl) in N_Entry_Declaration |
| 12348 |
| N_Subprogram_Declaration |
| 12349 |
then |
| 12350 |
Process_Subprogram_Declaration |
| 12351 |
(Subp_Decl => Decl, |
| 12352 |
In_State => In_State); |
| 12353 |
|
| 12354 |
-- Subprogram body (stand alone) |
| 12355 |
|
| 12356 |
elsif Nkind (Decl) = N_Subprogram_Body |
| 12357 |
and then No (Corresponding_Spec (Decl)) |
| 12358 |
then |
| 12359 |
Process_Subprogram_Declaration |
| 12360 |
(Subp_Decl => Decl, |
| 12361 |
In_State => In_State); |
| 12362 |
|
| 12363 |
-- Subprogram instantiation |
| 12364 |
|
| 12365 |
elsif Nkind (Decl) in N_Subprogram_Instantiation then |
| 12366 |
Process_Subprogram_Instantiation |
| 12367 |
(Inst => Decl, |
| 12368 |
In_State => In_State); |
| 12369 |
|
| 12370 |
-- Task type |
| 12371 |
|
| 12372 |
elsif Nkind (Decl) in N_Single_Task_Declaration |
| 12373 |
| N_Task_Type_Declaration |
| 12374 |
then |
| 12375 |
Process_Task_Type_Declaration |
| 12376 |
(Task_Decl => Decl, |
| 12377 |
In_State => In_State); |
| 12378 |
|
| 12379 |
-- Task type (derived) |
| 12380 |
|
| 12381 |
elsif Nkind (Decl) = N_Full_Type_Declaration |
| 12382 |
and then Is_Task_Type (Defining_Entity (Decl)) |
| 12383 |
then |
| 12384 |
Process_Task_Type_Declaration |
| 12385 |
(Task_Decl => Decl, |
| 12386 |
In_State => In_State); |
| 12387 |
end if; |
| 12388 |
|
| 12389 |
Next (Decl); |
| 12390 |
end loop; |
| 12391 |
end Process_Declarations; |
| 12392 |
|
| 12393 |
------------------------- |
| 12394 |
-- Process_Freeze_Node -- |
| 12395 |
------------------------- |
| 12396 |
|
| 12397 |
procedure Process_Freeze_Node |
| 12398 |
(Fnode : Node_Id; |
| 12399 |
In_State : Processing_In_State) |
| 12400 |
is |
| 12401 |
begin |
| 12402 |
Process_Declarations |
| 12403 |
(Decls => Actions (Fnode), |
| 12404 |
In_State => In_State); |
| 12405 |
end Process_Freeze_Node; |
| 12406 |
|
| 12407 |
----------------------------------- |
| 12408 |
-- Process_Invocation_Activation -- |
| 12409 |
----------------------------------- |
| 12410 |
|
| 12411 |
procedure Process_Invocation_Activation |
| 12412 |
(Call : Node_Id; |
| 12413 |
Call_Rep : Scenario_Rep_Id; |
| 12414 |
Obj_Id : Entity_Id; |
| 12415 |
Obj_Rep : Target_Rep_Id; |
| 12416 |
Task_Typ : Entity_Id; |
| 12417 |
Task_Rep : Target_Rep_Id; |
| 12418 |
In_State : Processing_In_State) |
| 12419 |
is |
| 12420 |
pragma Unreferenced (Call); |
| 12421 |
pragma Unreferenced (Call_Rep); |
| 12422 |
pragma Unreferenced (Obj_Id); |
| 12423 |
pragma Unreferenced (Obj_Rep); |
| 12424 |
|
| 12425 |
begin |
| 12426 |
-- Nothing to do when the task type appears within an internal unit |
| 12427 |
|
| 12428 |
if In_Internal_Unit (Task_Typ) then |
| 12429 |
return; |
| 12430 |
end if; |
| 12431 |
|
| 12432 |
-- The task type being activated is within the main unit. Extend the |
| 12433 |
-- DFS traversal into its body. |
| 12434 |
|
| 12435 |
if In_Extended_Main_Code_Unit (Task_Typ) then |
| 12436 |
Traverse_Invocation_Body |
| 12437 |
(N => Body_Declaration (Task_Rep), |
| 12438 |
In_State => In_State); |
| 12439 |
|
| 12440 |
-- The task type being activated resides within an external unit |
| 12441 |
-- |
| 12442 |
-- Main unit External unit |
| 12443 |
-- +-----------+ +-------------+ |
| 12444 |
-- | | | | |
| 12445 |
-- | Start ------------> Task_Typ | |
| 12446 |
-- | | | | |
| 12447 |
-- +-----------+ +-------------+ |
| 12448 |
-- |
| 12449 |
-- Record the invocation path which originates from Start and reaches |
| 12450 |
-- the task type. |
| 12451 |
|
| 12452 |
else |
| 12453 |
Record_Invocation_Path (In_State); |
| 12454 |
end if; |
| 12455 |
end Process_Invocation_Activation; |
| 12456 |
|
| 12457 |
--------------------------------------- |
| 12458 |
-- Process_Invocation_Body_Scenarios -- |
| 12459 |
--------------------------------------- |
| 12460 |
|
| 12461 |
procedure Process_Invocation_Body_Scenarios is |
| 12462 |
Iter : NE_Set.Iterator := Iterate_Library_Body_Scenarios; |
| 12463 |
begin |
| 12464 |
Process_Invocation_Scenarios |
| 12465 |
(Iter => Iter, |
| 12466 |
In_State => Invocation_Body_State); |
| 12467 |
end Process_Invocation_Body_Scenarios; |
| 12468 |
|
| 12469 |
----------------------------- |
| 12470 |
-- Process_Invocation_Call -- |
| 12471 |
----------------------------- |
| 12472 |
|
| 12473 |
procedure Process_Invocation_Call |
| 12474 |
(Call : Node_Id; |
| 12475 |
Call_Rep : Scenario_Rep_Id; |
| 12476 |
In_State : Processing_In_State) |
| 12477 |
is |
| 12478 |
pragma Unreferenced (Call); |
| 12479 |
|
| 12480 |
Subp_Id : constant Entity_Id := Target (Call_Rep); |
| 12481 |
Subp_Rep : constant Target_Rep_Id := |
| 12482 |
Target_Representation_Of (Subp_Id, In_State); |
| 12483 |
|
| 12484 |
begin |
| 12485 |
-- Nothing to do when the subprogram appears within an internal unit |
| 12486 |
|
| 12487 |
if In_Internal_Unit (Subp_Id) then |
| 12488 |
return; |
| 12489 |
|
| 12490 |
-- Nothing to do for an abstract subprogram because it has no body to |
| 12491 |
-- examine. |
| 12492 |
|
| 12493 |
elsif Ekind (Subp_Id) in E_Function | E_Procedure |
| 12494 |
and then Is_Abstract_Subprogram (Subp_Id) |
| 12495 |
then |
| 12496 |
return; |
| 12497 |
|
| 12498 |
-- Nothin to do for a formal subprogram because it has no body to |
| 12499 |
-- examine. |
| 12500 |
|
| 12501 |
elsif Is_Formal_Subprogram (Subp_Id) then |
| 12502 |
return; |
| 12503 |
end if; |
| 12504 |
|
| 12505 |
-- The subprogram being called is within the main unit. Extend the |
| 12506 |
-- DFS traversal into its barrier function and body. |
| 12507 |
|
| 12508 |
if In_Extended_Main_Code_Unit (Subp_Id) then |
| 12509 |
if Ekind (Subp_Id) in E_Entry | E_Entry_Family | E_Procedure then |
| 12510 |
Traverse_Invocation_Body |
| 12511 |
(N => Barrier_Body_Declaration (Subp_Rep), |
| 12512 |
In_State => In_State); |
| 12513 |
end if; |
| 12514 |
|
| 12515 |
Traverse_Invocation_Body |
| 12516 |
(N => Body_Declaration (Subp_Rep), |
| 12517 |
In_State => In_State); |
| 12518 |
|
| 12519 |
-- The subprogram being called resides within an external unit |
| 12520 |
-- |
| 12521 |
-- Main unit External unit |
| 12522 |
-- +-----------+ +-------------+ |
| 12523 |
-- | | | | |
| 12524 |
-- | Start ------------> Subp_Id | |
| 12525 |
-- | | | | |
| 12526 |
-- +-----------+ +-------------+ |
| 12527 |
-- |
| 12528 |
-- Record the invocation path which originates from Start and reaches |
| 12529 |
-- the subprogram. |
| 12530 |
|
| 12531 |
else |
| 12532 |
Record_Invocation_Path (In_State); |
| 12533 |
end if; |
| 12534 |
end Process_Invocation_Call; |
| 12535 |
|
| 12536 |
-------------------------------------- |
| 12537 |
-- Process_Invocation_Instantiation -- |
| 12538 |
-------------------------------------- |
| 12539 |
|
| 12540 |
procedure Process_Invocation_Instantiation |
| 12541 |
(Inst : Node_Id; |
| 12542 |
Inst_Rep : Scenario_Rep_Id; |
| 12543 |
In_State : Processing_In_State) |
| 12544 |
is |
| 12545 |
pragma Unreferenced (Inst); |
| 12546 |
|
| 12547 |
Gen_Id : constant Entity_Id := Target (Inst_Rep); |
| 12548 |
|
| 12549 |
begin |
| 12550 |
-- Nothing to do when the generic appears within an internal unit |
| 12551 |
|
| 12552 |
if In_Internal_Unit (Gen_Id) then |
| 12553 |
return; |
| 12554 |
end if; |
| 12555 |
|
| 12556 |
-- The generic being instantiated resides within an external unit |
| 12557 |
-- |
| 12558 |
-- Main unit External unit |
| 12559 |
-- +-----------+ +-------------+ |
| 12560 |
-- | | | | |
| 12561 |
-- | Start ------------> Generic | |
| 12562 |
-- | | | | |
| 12563 |
-- +-----------+ +-------------+ |
| 12564 |
-- |
| 12565 |
-- Record the invocation path which originates from Start and reaches |
| 12566 |
-- the generic. |
| 12567 |
|
| 12568 |
if not In_Extended_Main_Code_Unit (Gen_Id) then |
| 12569 |
Record_Invocation_Path (In_State); |
| 12570 |
end if; |
| 12571 |
end Process_Invocation_Instantiation; |
| 12572 |
|
| 12573 |
--------------------------------- |
| 12574 |
-- Process_Invocation_Scenario -- |
| 12575 |
--------------------------------- |
| 12576 |
|
| 12577 |
procedure Process_Invocation_Scenario |
| 12578 |
(N : Node_Id; |
| 12579 |
In_State : Processing_In_State) |
| 12580 |
is |
| 12581 |
Scen : constant Node_Id := Scenario (N); |
| 12582 |
Scen_Rep : Scenario_Rep_Id; |
| 12583 |
|
| 12584 |
begin |
| 12585 |
-- Add the current scenario to the stack of active scenarios |
| 12586 |
|
| 12587 |
Push_Active_Scenario (Scen); |
| 12588 |
|
| 12589 |
-- Call or task activation |
| 12590 |
|
| 12591 |
if Is_Suitable_Call (Scen) then |
| 12592 |
Scen_Rep := Scenario_Representation_Of (Scen, In_State); |
| 12593 |
|
| 12594 |
-- Routine Build_Call_Marker creates call markers regardless of |
| 12595 |
-- whether the call occurs within the main unit or not. This way |
| 12596 |
-- the serialization of internal names is kept consistent. Only |
| 12597 |
-- call markers found within the main unit must be processed. |
| 12598 |
|
| 12599 |
if In_Main_Context (Scen) then |
| 12600 |
Scen_Rep := Scenario_Representation_Of (Scen, In_State); |
| 12601 |
|
| 12602 |
if Kind (Scen_Rep) = Call_Scenario then |
| 12603 |
Process_Invocation_Call |
| 12604 |
(Call => Scen, |
| 12605 |
Call_Rep => Scen_Rep, |
| 12606 |
In_State => In_State); |
| 12607 |
|
| 12608 |
else |
| 12609 |
pragma Assert (Kind (Scen_Rep) = Task_Activation_Scenario); |
| 12610 |
|
| 12611 |
Process_Activation |
| 12612 |
(Call => Scen, |
| 12613 |
Call_Rep => Scen_Rep, |
| 12614 |
Processor => Process_Invocation_Activation'Access, |
| 12615 |
In_State => In_State); |
| 12616 |
end if; |
| 12617 |
end if; |
| 12618 |
|
| 12619 |
-- Instantiation |
| 12620 |
|
| 12621 |
elsif Is_Suitable_Instantiation (Scen) then |
| 12622 |
Process_Invocation_Instantiation |
| 12623 |
(Inst => Scen, |
| 12624 |
Inst_Rep => Scenario_Representation_Of (Scen, In_State), |
| 12625 |
In_State => In_State); |
| 12626 |
end if; |
| 12627 |
|
| 12628 |
-- Remove the current scenario from the stack of active scenarios |
| 12629 |
-- once all invocation constructs and paths have been saved. |
| 12630 |
|
| 12631 |
Pop_Active_Scenario (Scen); |
| 12632 |
end Process_Invocation_Scenario; |
| 12633 |
|
| 12634 |
---------------------------------- |
| 12635 |
-- Process_Invocation_Scenarios -- |
| 12636 |
---------------------------------- |
| 12637 |
|
| 12638 |
procedure Process_Invocation_Scenarios |
| 12639 |
(Iter : in out NE_Set.Iterator; |
| 12640 |
In_State : Processing_In_State) |
| 12641 |
is |
| 12642 |
N : Node_Id; |
| 12643 |
|
| 12644 |
begin |
| 12645 |
while NE_Set.Has_Next (Iter) loop |
| 12646 |
NE_Set.Next (Iter, N); |
| 12647 |
|
| 12648 |
-- Reset the traversed status of all subprogram bodies because the |
| 12649 |
-- current invocation scenario acts as a new DFS traversal root. |
| 12650 |
|
| 12651 |
Reset_Traversed_Bodies; |
| 12652 |
|
| 12653 |
Process_Invocation_Scenario (N, In_State); |
| 12654 |
end loop; |
| 12655 |
end Process_Invocation_Scenarios; |
| 12656 |
|
| 12657 |
--------------------------------------- |
| 12658 |
-- Process_Invocation_Spec_Scenarios -- |
| 12659 |
--------------------------------------- |
| 12660 |
|
| 12661 |
procedure Process_Invocation_Spec_Scenarios is |
| 12662 |
Iter : NE_Set.Iterator := Iterate_Library_Spec_Scenarios; |
| 12663 |
begin |
| 12664 |
Process_Invocation_Scenarios |
| 12665 |
(Iter => Iter, |
| 12666 |
In_State => Invocation_Spec_State); |
| 12667 |
end Process_Invocation_Spec_Scenarios; |
| 12668 |
|
| 12669 |
----------------------- |
| 12670 |
-- Process_Main_Unit -- |
| 12671 |
----------------------- |
| 12672 |
|
| 12673 |
procedure Process_Main_Unit is |
| 12674 |
Unit_Decl : constant Node_Id := Unit (Cunit (Main_Unit)); |
| 12675 |
Spec_Id : Entity_Id; |
| 12676 |
|
| 12677 |
begin |
| 12678 |
-- The main unit is a [generic] package body |
| 12679 |
|
| 12680 |
if Nkind (Unit_Decl) = N_Package_Body then |
| 12681 |
Spec_Id := Corresponding_Spec (Unit_Decl); |
| 12682 |
pragma Assert (Present (Spec_Id)); |
| 12683 |
|
| 12684 |
Process_Package_Declaration |
| 12685 |
(Pack_Decl => Unit_Declaration_Node (Spec_Id), |
| 12686 |
In_State => Invocation_Construct_State); |
| 12687 |
|
| 12688 |
-- The main unit is a [generic] package declaration |
| 12689 |
|
| 12690 |
elsif Nkind (Unit_Decl) = N_Package_Declaration then |
| 12691 |
Process_Package_Declaration |
| 12692 |
(Pack_Decl => Unit_Decl, |
| 12693 |
In_State => Invocation_Construct_State); |
| 12694 |
|
| 12695 |
-- The main unit is a [generic] subprogram body |
| 12696 |
|
| 12697 |
elsif Nkind (Unit_Decl) = N_Subprogram_Body then |
| 12698 |
Spec_Id := Corresponding_Spec (Unit_Decl); |
| 12699 |
|
| 12700 |
-- The body completes a previous declaration |
| 12701 |
|
| 12702 |
if Present (Spec_Id) then |
| 12703 |
Process_Subprogram_Declaration |
| 12704 |
(Subp_Decl => Unit_Declaration_Node (Spec_Id), |
| 12705 |
In_State => Invocation_Construct_State); |
| 12706 |
|
| 12707 |
-- Otherwise the body is stand-alone |
| 12708 |
|
| 12709 |
else |
| 12710 |
Process_Subprogram_Declaration |
| 12711 |
(Subp_Decl => Unit_Decl, |
| 12712 |
In_State => Invocation_Construct_State); |
| 12713 |
end if; |
| 12714 |
|
| 12715 |
-- The main unit is a subprogram instantiation |
| 12716 |
|
| 12717 |
elsif Nkind (Unit_Decl) in N_Subprogram_Instantiation then |
| 12718 |
Process_Subprogram_Instantiation |
| 12719 |
(Inst => Unit_Decl, |
| 12720 |
In_State => Invocation_Construct_State); |
| 12721 |
|
| 12722 |
-- The main unit is an imported subprogram declaration |
| 12723 |
|
| 12724 |
elsif Nkind (Unit_Decl) = N_Subprogram_Declaration then |
| 12725 |
Process_Subprogram_Declaration |
| 12726 |
(Subp_Decl => Unit_Decl, |
| 12727 |
In_State => Invocation_Construct_State); |
| 12728 |
end if; |
| 12729 |
end Process_Main_Unit; |
| 12730 |
|
| 12731 |
--------------------------------- |
| 12732 |
-- Process_Package_Declaration -- |
| 12733 |
--------------------------------- |
| 12734 |
|
| 12735 |
procedure Process_Package_Declaration |
| 12736 |
(Pack_Decl : Node_Id; |
| 12737 |
In_State : Processing_In_State) |
| 12738 |
is |
| 12739 |
Body_Id : constant Entity_Id := Corresponding_Body (Pack_Decl); |
| 12740 |
Spec : constant Node_Id := Specification (Pack_Decl); |
| 12741 |
Spec_Id : constant Entity_Id := Defining_Entity (Pack_Decl); |
| 12742 |
|
| 12743 |
begin |
| 12744 |
-- Add a declaration for the generic package in the ALI of the main |
| 12745 |
-- unit in case a client unit instantiates it. |
| 12746 |
|
| 12747 |
if Ekind (Spec_Id) = E_Generic_Package then |
| 12748 |
Declare_Invocation_Construct |
| 12749 |
(Constr_Id => Spec_Id, |
| 12750 |
In_State => In_State); |
| 12751 |
|
| 12752 |
-- Otherwise inspect the visible and private declarations of the |
| 12753 |
-- package for invocation constructs. |
| 12754 |
|
| 12755 |
else |
| 12756 |
Process_Declarations |
| 12757 |
(Decls => Visible_Declarations (Spec), |
| 12758 |
In_State => In_State); |
| 12759 |
|
| 12760 |
Process_Declarations |
| 12761 |
(Decls => Private_Declarations (Spec), |
| 12762 |
In_State => In_State); |
| 12763 |
|
| 12764 |
-- The package body containst at least one generic unit or an |
| 12765 |
-- inlinable subprogram. Such constructs may grant clients of |
| 12766 |
-- the main unit access to the private enclosing contexts of |
| 12767 |
-- the constructs. Process the main unit body to discover and |
| 12768 |
-- encode relevant invocation constructs and relations that |
| 12769 |
-- may ultimately reach an external unit. |
| 12770 |
|
| 12771 |
if Present (Body_Id) |
| 12772 |
and then Save_Invocation_Graph_Of_Body (Cunit (Main_Unit)) |
| 12773 |
then |
| 12774 |
Process_Declarations |
| 12775 |
(Decls => Declarations (Unit_Declaration_Node (Body_Id)), |
| 12776 |
In_State => In_State); |
| 12777 |
end if; |
| 12778 |
end if; |
| 12779 |
end Process_Package_Declaration; |
| 12780 |
|
| 12781 |
---------------------------------------- |
| 12782 |
-- Process_Protected_Type_Declaration -- |
| 12783 |
---------------------------------------- |
| 12784 |
|
| 12785 |
procedure Process_Protected_Type_Declaration |
| 12786 |
(Prot_Decl : Node_Id; |
| 12787 |
In_State : Processing_In_State) |
| 12788 |
is |
| 12789 |
Prot_Def : constant Node_Id := Protected_Definition (Prot_Decl); |
| 12790 |
|
| 12791 |
begin |
| 12792 |
if Present (Prot_Def) then |
| 12793 |
Process_Declarations |
| 12794 |
(Decls => Visible_Declarations (Prot_Def), |
| 12795 |
In_State => In_State); |
| 12796 |
end if; |
| 12797 |
end Process_Protected_Type_Declaration; |
| 12798 |
|
| 12799 |
------------------------------------ |
| 12800 |
-- Process_Subprogram_Declaration -- |
| 12801 |
------------------------------------ |
| 12802 |
|
| 12803 |
procedure Process_Subprogram_Declaration |
| 12804 |
(Subp_Decl : Node_Id; |
| 12805 |
In_State : Processing_In_State) |
| 12806 |
is |
| 12807 |
Subp_Id : constant Entity_Id := Defining_Entity (Subp_Decl); |
| 12808 |
|
| 12809 |
begin |
| 12810 |
-- Nothing to do when the subprogram is not an invocation target |
| 12811 |
|
| 12812 |
if not Is_Invocation_Target (Subp_Id) then |
| 12813 |
return; |
| 12814 |
end if; |
| 12815 |
|
| 12816 |
-- Add a declaration for the subprogram in the ALI file of the main |
| 12817 |
-- unit in case a client unit calls or instantiates it. |
| 12818 |
|
| 12819 |
Declare_Invocation_Construct |
| 12820 |
(Constr_Id => Subp_Id, |
| 12821 |
In_State => In_State); |
| 12822 |
|
| 12823 |
-- Do not process subprograms without a body because they do not |
| 12824 |
-- contain any invocation scenarios. |
| 12825 |
|
| 12826 |
if Is_Bodiless_Subprogram (Subp_Id) then |
| 12827 |
null; |
| 12828 |
|
| 12829 |
-- Do not process generic subprograms because generics must not be |
| 12830 |
-- examined. |
| 12831 |
|
| 12832 |
elsif Is_Generic_Subprogram (Subp_Id) then |
| 12833 |
null; |
| 12834 |
|
| 12835 |
-- Otherwise create a dummy scenario which calls the subprogram to |
| 12836 |
-- act as a root for a DFS traversal. |
| 12837 |
|
| 12838 |
else |
| 12839 |
-- Reset the traversed status of all subprogram bodies because the |
| 12840 |
-- subprogram acts as a new DFS traversal root. |
| 12841 |
|
| 12842 |
Reset_Traversed_Bodies; |
| 12843 |
|
| 12844 |
Process_Invocation_Scenario |
| 12845 |
(N => Build_Subprogram_Invocation (Subp_Id), |
| 12846 |
In_State => In_State); |
| 12847 |
end if; |
| 12848 |
end Process_Subprogram_Declaration; |
| 12849 |
|
| 12850 |
-------------------------------------- |
| 12851 |
-- Process_Subprogram_Instantiation -- |
| 12852 |
-------------------------------------- |
| 12853 |
|
| 12854 |
procedure Process_Subprogram_Instantiation |
| 12855 |
(Inst : Node_Id; |
| 12856 |
In_State : Processing_In_State) |
| 12857 |
is |
| 12858 |
begin |
| 12859 |
-- Add a declaration for the instantiation in the ALI file of the |
| 12860 |
-- main unit in case a client unit calls it. |
| 12861 |
|
| 12862 |
Declare_Invocation_Construct |
| 12863 |
(Constr_Id => Defining_Entity (Inst), |
| 12864 |
In_State => In_State); |
| 12865 |
end Process_Subprogram_Instantiation; |
| 12866 |
|
| 12867 |
----------------------------------- |
| 12868 |
-- Process_Task_Type_Declaration -- |
| 12869 |
----------------------------------- |
| 12870 |
|
| 12871 |
procedure Process_Task_Type_Declaration |
| 12872 |
(Task_Decl : Node_Id; |
| 12873 |
In_State : Processing_In_State) |
| 12874 |
is |
| 12875 |
Task_Typ : constant Entity_Id := Defining_Entity (Task_Decl); |
| 12876 |
Task_Def : Node_Id; |
| 12877 |
|
| 12878 |
begin |
| 12879 |
-- Add a declaration for the task type the ALI file of the main unit |
| 12880 |
-- in case a client unit creates a task object and activates it. |
| 12881 |
|
| 12882 |
Declare_Invocation_Construct |
| 12883 |
(Constr_Id => Task_Typ, |
| 12884 |
In_State => In_State); |
| 12885 |
|
| 12886 |
-- Process the entries of the task type because they represent valid |
| 12887 |
-- entry points into the task body. |
| 12888 |
|
| 12889 |
if Nkind (Task_Decl) in N_Single_Task_Declaration |
| 12890 |
| N_Task_Type_Declaration |
| 12891 |
then |
| 12892 |
Task_Def := Task_Definition (Task_Decl); |
| 12893 |
|
| 12894 |
if Present (Task_Def) then |
| 12895 |
Process_Declarations |
| 12896 |
(Decls => Visible_Declarations (Task_Def), |
| 12897 |
In_State => In_State); |
| 12898 |
end if; |
| 12899 |
end if; |
| 12900 |
|
| 12901 |
-- Reset the traversed status of all subprogram bodies because the |
| 12902 |
-- task type acts as a new DFS traversal root. |
| 12903 |
|
| 12904 |
Reset_Traversed_Bodies; |
| 12905 |
|
| 12906 |
-- Create a dummy scenario which activates an anonymous object of the |
| 12907 |
-- task type to acts as a root of a DFS traversal. |
| 12908 |
|
| 12909 |
Process_Invocation_Scenario |
| 12910 |
(N => Build_Task_Activation (Task_Typ, In_State), |
| 12911 |
In_State => In_State); |
| 12912 |
end Process_Task_Type_Declaration; |
| 12913 |
|
| 12914 |
--------------------------------- |
| 12915 |
-- Record_Full_Invocation_Path -- |
| 12916 |
--------------------------------- |
| 12917 |
|
| 12918 |
procedure Record_Full_Invocation_Path (In_State : Processing_In_State) is |
| 12919 |
package Scenarios renames Active_Scenario_Stack; |
| 12920 |
|
| 12921 |
begin |
| 12922 |
-- The path originates from the elaboration of the body. Add an extra |
| 12923 |
-- relation from the elaboration body procedure to the first active |
| 12924 |
-- scenario. |
| 12925 |
|
| 12926 |
if In_State.Processing = Invocation_Body_Processing then |
| 12927 |
Build_Elaborate_Body_Procedure; |
| 12928 |
|
| 12929 |
Record_Invocation_Relation |
| 12930 |
(Invk_Id => Elab_Body_Id, |
| 12931 |
Targ_Id => Target_Of (Scenarios.First, In_State), |
| 12932 |
In_State => In_State); |
| 12933 |
|
| 12934 |
-- The path originates from the elaboration of the spec. Add an extra |
| 12935 |
-- relation from the elaboration spec procedure to the first active |
| 12936 |
-- scenario. |
| 12937 |
|
| 12938 |
elsif In_State.Processing = Invocation_Spec_Processing then |
| 12939 |
Build_Elaborate_Spec_Procedure; |
| 12940 |
|
| 12941 |
Record_Invocation_Relation |
| 12942 |
(Invk_Id => Elab_Spec_Id, |
| 12943 |
Targ_Id => Target_Of (Scenarios.First, In_State), |
| 12944 |
In_State => In_State); |
| 12945 |
end if; |
| 12946 |
|
| 12947 |
-- Record individual relations formed by pairs of scenarios |
| 12948 |
|
| 12949 |
for Index in Scenarios.First .. Scenarios.Last - 1 loop |
| 12950 |
Record_Invocation_Relation |
| 12951 |
(Invk_Id => Target_Of (Index, In_State), |
| 12952 |
Targ_Id => Target_Of (Index + 1, In_State), |
| 12953 |
In_State => In_State); |
| 12954 |
end loop; |
| 12955 |
end Record_Full_Invocation_Path; |
| 12956 |
|
| 12957 |
----------------------------- |
| 12958 |
-- Record_Invocation_Graph -- |
| 12959 |
----------------------------- |
| 12960 |
|
| 12961 |
procedure Record_Invocation_Graph is |
| 12962 |
begin |
| 12963 |
-- Nothing to do when the invocation graph is not recorded |
| 12964 |
|
| 12965 |
if not Invocation_Graph_Recording_OK then |
| 12966 |
return; |
| 12967 |
end if; |
| 12968 |
|
| 12969 |
-- Save the encoding format used to capture information about the |
| 12970 |
-- invocation constructs and relations in the ALI file of the main |
| 12971 |
-- unit. |
| 12972 |
|
| 12973 |
Record_Invocation_Graph_Encoding; |
| 12974 |
|
| 12975 |
-- Examine all library level invocation scenarios and perform DFS |
| 12976 |
-- traversals from each one. Encode a path in the ALI file of the |
| 12977 |
-- main unit if it reaches into an external unit. |
| 12978 |
|
| 12979 |
Process_Invocation_Body_Scenarios; |
| 12980 |
Process_Invocation_Spec_Scenarios; |
| 12981 |
|
| 12982 |
-- Examine all invocation constructs within the spec and body of the |
| 12983 |
-- main unit and perform DFS traversals from each one. Encode a path |
| 12984 |
-- in the ALI file of the main unit if it reaches into an external |
| 12985 |
-- unit. |
| 12986 |
|
| 12987 |
Process_Main_Unit; |
| 12988 |
end Record_Invocation_Graph; |
| 12989 |
|
| 12990 |
-------------------------------------- |
| 12991 |
-- Record_Invocation_Graph_Encoding -- |
| 12992 |
-------------------------------------- |
| 12993 |
|
| 12994 |
procedure Record_Invocation_Graph_Encoding is |
| 12995 |
Kind : Invocation_Graph_Encoding_Kind := No_Encoding; |
| 12996 |
|
| 12997 |
begin |
| 12998 |
-- Switch -gnatd_F (encode full invocation paths in ALI files) is in |
| 12999 |
-- effect. |
| 13000 |
|
| 13001 |
if Debug_Flag_Underscore_FF then |
| 13002 |
Kind := Full_Path_Encoding; |
| 13003 |
else |
| 13004 |
Kind := Endpoints_Encoding; |
| 13005 |
end if; |
| 13006 |
|
| 13007 |
-- Save the encoding format in the ALI file of the main unit |
| 13008 |
|
| 13009 |
Set_Invocation_Graph_Encoding |
| 13010 |
(Kind => Kind, |
| 13011 |
Update_Units => False); |
| 13012 |
end Record_Invocation_Graph_Encoding; |
| 13013 |
|
| 13014 |
---------------------------- |
| 13015 |
-- Record_Invocation_Path -- |
| 13016 |
---------------------------- |
| 13017 |
|
| 13018 |
procedure Record_Invocation_Path (In_State : Processing_In_State) is |
| 13019 |
package Scenarios renames Active_Scenario_Stack; |
| 13020 |
|
| 13021 |
begin |
| 13022 |
-- Save a path when the active scenario stack contains at least one |
| 13023 |
-- invocation scenario. |
| 13024 |
|
| 13025 |
if Scenarios.Last - Scenarios.First < 0 then |
| 13026 |
return; |
| 13027 |
end if; |
| 13028 |
|
| 13029 |
-- Register all relations in the path when switch -gnatd_F (encode |
| 13030 |
-- full invocation paths in ALI files) is in effect. |
| 13031 |
|
| 13032 |
if Debug_Flag_Underscore_FF then |
| 13033 |
Record_Full_Invocation_Path (In_State); |
| 13034 |
|
| 13035 |
-- Otherwise register a single relation |
| 13036 |
|
| 13037 |
else |
| 13038 |
Record_Simple_Invocation_Path (In_State); |
| 13039 |
end if; |
| 13040 |
|
| 13041 |
Write_Invocation_Path (In_State); |
| 13042 |
end Record_Invocation_Path; |
| 13043 |
|
| 13044 |
-------------------------------- |
| 13045 |
-- Record_Invocation_Relation -- |
| 13046 |
-------------------------------- |
| 13047 |
|
| 13048 |
procedure Record_Invocation_Relation |
| 13049 |
(Invk_Id : Entity_Id; |
| 13050 |
Targ_Id : Entity_Id; |
| 13051 |
In_State : Processing_In_State) |
| 13052 |
is |
| 13053 |
pragma Assert (Present (Invk_Id)); |
| 13054 |
pragma Assert (Present (Targ_Id)); |
| 13055 |
|
| 13056 |
procedure Get_Invocation_Attributes |
| 13057 |
(Extra : out Entity_Id; |
| 13058 |
Kind : out Invocation_Kind); |
| 13059 |
pragma Inline (Get_Invocation_Attributes); |
| 13060 |
-- Return the additional entity used in error diagnostics in Extra |
| 13061 |
-- and the invocation kind in Kind which pertain to the invocation |
| 13062 |
-- relation with invoker Invk_Id and target Targ_Id. |
| 13063 |
|
| 13064 |
------------------------------- |
| 13065 |
-- Get_Invocation_Attributes -- |
| 13066 |
------------------------------- |
| 13067 |
|
| 13068 |
procedure Get_Invocation_Attributes |
| 13069 |
(Extra : out Entity_Id; |
| 13070 |
Kind : out Invocation_Kind) |
| 13071 |
is |
| 13072 |
begin |
| 13073 |
-- Accept within a task body |
| 13074 |
|
| 13075 |
if Is_Accept_Alternative_Proc (Targ_Id) then |
| 13076 |
Extra := Receiving_Entry (Targ_Id); |
| 13077 |
Kind := Accept_Alternative; |
| 13078 |
|
| 13079 |
-- Activation of a task object |
| 13080 |
|
| 13081 |
elsif Is_Activation_Proc (Targ_Id) |
| 13082 |
or else Is_Task_Type (Targ_Id) |
| 13083 |
then |
| 13084 |
Extra := Empty; |
| 13085 |
Kind := Task_Activation; |
| 13086 |
|
| 13087 |
-- Controlled adjustment actions |
| 13088 |
|
| 13089 |
elsif Is_Controlled_Procedure (Targ_Id, Name_Adjust) then |
| 13090 |
Extra := First_Formal_Type (Targ_Id); |
| 13091 |
Kind := Controlled_Adjustment; |
| 13092 |
|
| 13093 |
-- Controlled finalization actions |
| 13094 |
|
| 13095 |
elsif Is_Controlled_Procedure (Targ_Id, Name_Finalize) |
| 13096 |
or else Is_Finalizer (Targ_Id) |
| 13097 |
then |
| 13098 |
Extra := First_Formal_Type (Targ_Id); |
| 13099 |
Kind := Controlled_Finalization; |
| 13100 |
|
| 13101 |
-- Controlled initialization actions |
| 13102 |
|
| 13103 |
elsif Is_Controlled_Procedure (Targ_Id, Name_Initialize) then |
| 13104 |
Extra := First_Formal_Type (Targ_Id); |
| 13105 |
Kind := Controlled_Initialization; |
| 13106 |
|
| 13107 |
-- Default_Initial_Condition verification |
| 13108 |
|
| 13109 |
elsif Is_Default_Initial_Condition_Proc (Targ_Id) then |
| 13110 |
Extra := First_Formal_Type (Targ_Id); |
| 13111 |
Kind := Default_Initial_Condition_Verification; |
| 13112 |
|
| 13113 |
-- Initialization of object |
| 13114 |
|
| 13115 |
elsif Is_Init_Proc (Targ_Id) then |
| 13116 |
Extra := First_Formal_Type (Targ_Id); |
| 13117 |
Kind := Type_Initialization; |
| 13118 |
|
| 13119 |
-- Initial_Condition verification |
| 13120 |
|
| 13121 |
elsif Is_Initial_Condition_Proc (Targ_Id) then |
| 13122 |
Extra := First_Formal_Type (Targ_Id); |
| 13123 |
Kind := Initial_Condition_Verification; |
| 13124 |
|
| 13125 |
-- Instantiation |
| 13126 |
|
| 13127 |
elsif Is_Generic_Unit (Targ_Id) then |
| 13128 |
Extra := Empty; |
| 13129 |
Kind := Instantiation; |
| 13130 |
|
| 13131 |
-- Internal controlled adjustment actions |
| 13132 |
|
| 13133 |
elsif Is_TSS (Targ_Id, TSS_Deep_Adjust) then |
| 13134 |
Extra := First_Formal_Type (Targ_Id); |
| 13135 |
Kind := Internal_Controlled_Adjustment; |
| 13136 |
|
| 13137 |
-- Internal controlled finalization actions |
| 13138 |
|
| 13139 |
elsif Is_TSS (Targ_Id, TSS_Deep_Finalize) then |
| 13140 |
Extra := First_Formal_Type (Targ_Id); |
| 13141 |
Kind := Internal_Controlled_Finalization; |
| 13142 |
|
| 13143 |
-- Internal controlled initialization actions |
| 13144 |
|
| 13145 |
elsif Is_TSS (Targ_Id, TSS_Deep_Initialize) then |
| 13146 |
Extra := First_Formal_Type (Targ_Id); |
| 13147 |
Kind := Internal_Controlled_Initialization; |
| 13148 |
|
| 13149 |
-- Invariant verification |
| 13150 |
|
| 13151 |
elsif Is_Invariant_Proc (Targ_Id) |
| 13152 |
or else Is_Partial_Invariant_Proc (Targ_Id) |
| 13153 |
then |
| 13154 |
Extra := First_Formal_Type (Targ_Id); |
| 13155 |
Kind := Invariant_Verification; |
| 13156 |
|
| 13157 |
-- Protected entry call |
| 13158 |
|
| 13159 |
elsif Is_Protected_Entry (Targ_Id) then |
| 13160 |
Extra := Empty; |
| 13161 |
Kind := Protected_Entry_Call; |
| 13162 |
|
| 13163 |
-- Protected subprogram call |
| 13164 |
|
| 13165 |
elsif Is_Protected_Subp (Targ_Id) then |
| 13166 |
Extra := Empty; |
| 13167 |
Kind := Protected_Subprogram_Call; |
| 13168 |
|
| 13169 |
-- Task entry call |
| 13170 |
|
| 13171 |
elsif Is_Task_Entry (Targ_Id) then |
| 13172 |
Extra := Empty; |
| 13173 |
Kind := Task_Entry_Call; |
| 13174 |
|
| 13175 |
-- Entry, operator, or subprogram call. This case must come last |
| 13176 |
-- because most invocations above are variations of this case. |
| 13177 |
|
| 13178 |
elsif Ekind (Targ_Id) in |
| 13179 |
E_Entry | E_Function | E_Operator | E_Procedure |
| 13180 |
then |
| 13181 |
Extra := Empty; |
| 13182 |
Kind := Call; |
| 13183 |
|
| 13184 |
else |
| 13185 |
pragma Assert (False); |
| 13186 |
Extra := Empty; |
| 13187 |
Kind := No_Invocation; |
| 13188 |
end if; |
| 13189 |
end Get_Invocation_Attributes; |
| 13190 |
|
| 13191 |
-- Local variables |
| 13192 |
|
| 13193 |
Extra : Entity_Id; |
| 13194 |
Extra_Nam : Name_Id; |
| 13195 |
Kind : Invocation_Kind; |
| 13196 |
Rel : Invoker_Target_Relation; |
| 13197 |
|
| 13198 |
-- Start of processing for Record_Invocation_Relation |
| 13199 |
|
| 13200 |
begin |
| 13201 |
Rel.Invoker := Invk_Id; |
| 13202 |
Rel.Target := Targ_Id; |
| 13203 |
|
| 13204 |
-- Nothing to do when the invocation relation has already been |
| 13205 |
-- recorded in ALI file of the main unit. |
| 13206 |
|
| 13207 |
if Is_Saved_Relation (Rel) then |
| 13208 |
return; |
| 13209 |
end if; |
| 13210 |
|
| 13211 |
-- Mark the relation as recorded in the ALI file |
| 13212 |
|
| 13213 |
Set_Is_Saved_Relation (Rel); |
| 13214 |
|
| 13215 |
-- Declare the invoker in the ALI file |
| 13216 |
|
| 13217 |
Declare_Invocation_Construct |
| 13218 |
(Constr_Id => Invk_Id, |
| 13219 |
In_State => In_State); |
| 13220 |
|
| 13221 |
-- Obtain the invocation-specific attributes of the relation |
| 13222 |
|
| 13223 |
Get_Invocation_Attributes (Extra, Kind); |
| 13224 |
|
| 13225 |
-- Certain invocations lack an extra entity used in error diagnostics |
| 13226 |
|
| 13227 |
if Present (Extra) then |
| 13228 |
Extra_Nam := Chars (Extra); |
| 13229 |
else |
| 13230 |
Extra_Nam := No_Name; |
| 13231 |
end if; |
| 13232 |
|
| 13233 |
-- Add the relation in the ALI file |
| 13234 |
|
| 13235 |
Add_Invocation_Relation |
| 13236 |
(Extra => Extra_Nam, |
| 13237 |
Invoker => Signature_Of (Invk_Id), |
| 13238 |
Kind => Kind, |
| 13239 |
Target => Signature_Of (Targ_Id), |
| 13240 |
Update_Units => False); |
| 13241 |
end Record_Invocation_Relation; |
| 13242 |
|
| 13243 |
----------------------------------- |
| 13244 |
-- Record_Simple_Invocation_Path -- |
| 13245 |
----------------------------------- |
| 13246 |
|
| 13247 |
procedure Record_Simple_Invocation_Path |
| 13248 |
(In_State : Processing_In_State) |
| 13249 |
is |
| 13250 |
package Scenarios renames Active_Scenario_Stack; |
| 13251 |
|
| 13252 |
Last_Targ : constant Entity_Id := |
| 13253 |
Target_Of (Scenarios.Last, In_State); |
| 13254 |
First_Targ : Entity_Id; |
| 13255 |
|
| 13256 |
begin |
| 13257 |
-- The path originates from the elaboration of the body. Add an extra |
| 13258 |
-- relation from the elaboration body procedure to the first active |
| 13259 |
-- scenario. |
| 13260 |
|
| 13261 |
if In_State.Processing = Invocation_Body_Processing then |
| 13262 |
Build_Elaborate_Body_Procedure; |
| 13263 |
First_Targ := Elab_Body_Id; |
| 13264 |
|
| 13265 |
-- The path originates from the elaboration of the spec. Add an extra |
| 13266 |
-- relation from the elaboration spec procedure to the first active |
| 13267 |
-- scenario. |
| 13268 |
|
| 13269 |
elsif In_State.Processing = Invocation_Spec_Processing then |
| 13270 |
Build_Elaborate_Spec_Procedure; |
| 13271 |
First_Targ := Elab_Spec_Id; |
| 13272 |
|
| 13273 |
else |
| 13274 |
First_Targ := Target_Of (Scenarios.First, In_State); |
| 13275 |
end if; |
| 13276 |
|
| 13277 |
-- Record a single relation from the first to the last scenario |
| 13278 |
|
| 13279 |
if First_Targ /= Last_Targ then |
| 13280 |
Record_Invocation_Relation |
| 13281 |
(Invk_Id => First_Targ, |
| 13282 |
Targ_Id => Last_Targ, |
| 13283 |
In_State => In_State); |
| 13284 |
end if; |
| 13285 |
end Record_Simple_Invocation_Path; |
| 13286 |
|
| 13287 |
---------------------------- |
| 13288 |
-- Set_Is_Saved_Construct -- |
| 13289 |
---------------------------- |
| 13290 |
|
| 13291 |
procedure Set_Is_Saved_Construct (Constr : Entity_Id) is |
| 13292 |
pragma Assert (Present (Constr)); |
| 13293 |
|
| 13294 |
begin |
| 13295 |
NE_Set.Insert (Saved_Constructs_Set, Constr); |
| 13296 |
end Set_Is_Saved_Construct; |
| 13297 |
|
| 13298 |
--------------------------- |
| 13299 |
-- Set_Is_Saved_Relation -- |
| 13300 |
--------------------------- |
| 13301 |
|
| 13302 |
procedure Set_Is_Saved_Relation (Rel : Invoker_Target_Relation) is |
| 13303 |
begin |
| 13304 |
IR_Set.Insert (Saved_Relations_Set, Rel); |
| 13305 |
end Set_Is_Saved_Relation; |
| 13306 |
|
| 13307 |
------------------ |
| 13308 |
-- Signature_Of -- |
| 13309 |
------------------ |
| 13310 |
|
| 13311 |
function Signature_Of (Id : Entity_Id) return Invocation_Signature_Id is |
| 13312 |
Loc : constant Source_Ptr := Sloc (Id); |
| 13313 |
|
| 13314 |
function Instantiation_Locations return Name_Id; |
| 13315 |
pragma Inline (Instantiation_Locations); |
| 13316 |
-- Create a concatenation of all lines and colums of each instance |
| 13317 |
-- where source location Loc appears. Return No_Name if no instances |
| 13318 |
-- exist. |
| 13319 |
|
| 13320 |
function Qualified_Scope return Name_Id; |
| 13321 |
pragma Inline (Qualified_Scope); |
| 13322 |
-- Obtain the qualified name of Id's scope |
| 13323 |
|
| 13324 |
----------------------------- |
| 13325 |
-- Instantiation_Locations -- |
| 13326 |
----------------------------- |
| 13327 |
|
| 13328 |
function Instantiation_Locations return Name_Id is |
| 13329 |
Buffer : Bounded_String (2052); |
| 13330 |
Inst : Source_Ptr; |
| 13331 |
Loc_Nam : Name_Id; |
| 13332 |
SFI : Source_File_Index; |
| 13333 |
|
| 13334 |
begin |
| 13335 |
SFI := Get_Source_File_Index (Loc); |
| 13336 |
Inst := Instantiation (SFI); |
| 13337 |
|
| 13338 |
-- The location is within an instance. Construct a concatenation |
| 13339 |
-- of all lines and colums of each individual instance using the |
| 13340 |
-- following format: |
| 13341 |
-- |
| 13342 |
-- line1_column1_line2_column2_ ... _lineN_columnN |
| 13343 |
|
| 13344 |
if Inst /= No_Location then |
| 13345 |
loop |
| 13346 |
Append (Buffer, Nat (Get_Logical_Line_Number (Inst))); |
| 13347 |
Append (Buffer, '_'); |
| 13348 |
Append (Buffer, Nat (Get_Column_Number (Inst))); |
| 13349 |
|
| 13350 |
SFI := Get_Source_File_Index (Inst); |
| 13351 |
Inst := Instantiation (SFI); |
| 13352 |
|
| 13353 |
exit when Inst = No_Location; |
| 13354 |
|
| 13355 |
Append (Buffer, '_'); |
| 13356 |
end loop; |
| 13357 |
|
| 13358 |
Loc_Nam := Name_Find (Buffer); |
| 13359 |
return Loc_Nam; |
| 13360 |
|
| 13361 |
-- Otherwise there no instances are involved |
| 13362 |
|
| 13363 |
else |
| 13364 |
return No_Name; |
| 13365 |
end if; |
| 13366 |
end Instantiation_Locations; |
| 13367 |
|
| 13368 |
--------------------- |
| 13369 |
-- Qualified_Scope -- |
| 13370 |
--------------------- |
| 13371 |
|
| 13372 |
function Qualified_Scope return Name_Id is |
| 13373 |
Scop : Entity_Id; |
| 13374 |
|
| 13375 |
begin |
| 13376 |
Scop := Scope (Id); |
| 13377 |
|
| 13378 |
-- The entity appears within an anonymous concurrent type created |
| 13379 |
-- for a single protected or task type declaration. Use the entity |
| 13380 |
-- of the anonymous object as it represents the original scope. |
| 13381 |
|
| 13382 |
if Is_Concurrent_Type (Scop) |
| 13383 |
and then Present (Anonymous_Object (Scop)) |
| 13384 |
then |
| 13385 |
Scop := Anonymous_Object (Scop); |
| 13386 |
end if; |
| 13387 |
|
| 13388 |
return Get_Qualified_Name (Scop); |
| 13389 |
end Qualified_Scope; |
| 13390 |
|
| 13391 |
-- Start of processing for Signature_Of |
| 13392 |
|
| 13393 |
begin |
| 13394 |
return |
| 13395 |
Invocation_Signature_Of |
| 13396 |
(Column => Nat (Get_Column_Number (Loc)), |
| 13397 |
Line => Nat (Get_Logical_Line_Number (Loc)), |
| 13398 |
Locations => Instantiation_Locations, |
| 13399 |
Name => Chars (Id), |
| 13400 |
Scope => Qualified_Scope); |
| 13401 |
end Signature_Of; |
| 13402 |
|
| 13403 |
--------------- |
| 13404 |
-- Target_Of -- |
| 13405 |
--------------- |
| 13406 |
|
| 13407 |
function Target_Of |
| 13408 |
(Pos : Active_Scenario_Pos; |
| 13409 |
In_State : Processing_In_State) return Entity_Id |
| 13410 |
is |
| 13411 |
package Scenarios renames Active_Scenario_Stack; |
| 13412 |
|
| 13413 |
-- Ensure that the position is within the bounds of the active |
| 13414 |
-- scenario stack. |
| 13415 |
|
| 13416 |
pragma Assert (Scenarios.First <= Pos); |
| 13417 |
pragma Assert (Pos <= Scenarios.Last); |
| 13418 |
|
| 13419 |
Scen_Rep : constant Scenario_Rep_Id := |
| 13420 |
Scenario_Representation_Of |
| 13421 |
(Scenarios.Table (Pos), In_State); |
| 13422 |
|
| 13423 |
begin |
| 13424 |
-- The true target of an activation call is the current task type |
| 13425 |
-- rather than routine Activate_Tasks. |
| 13426 |
|
| 13427 |
if Kind (Scen_Rep) = Task_Activation_Scenario then |
| 13428 |
return Activated_Task_Type (Scen_Rep); |
| 13429 |
else |
| 13430 |
return Target (Scen_Rep); |
| 13431 |
end if; |
| 13432 |
end Target_Of; |
| 13433 |
|
| 13434 |
------------------------------ |
| 13435 |
-- Traverse_Invocation_Body -- |
| 13436 |
------------------------------ |
| 13437 |
|
| 13438 |
procedure Traverse_Invocation_Body |
| 13439 |
(N : Node_Id; |
| 13440 |
In_State : Processing_In_State) |
| 13441 |
is |
| 13442 |
begin |
| 13443 |
Traverse_Body |
| 13444 |
(N => N, |
| 13445 |
Requires_Processing => Is_Invocation_Scenario'Access, |
| 13446 |
Processor => Process_Invocation_Scenario'Access, |
| 13447 |
In_State => In_State); |
| 13448 |
end Traverse_Invocation_Body; |
| 13449 |
|
| 13450 |
--------------------------- |
| 13451 |
-- Write_Invocation_Path -- |
| 13452 |
--------------------------- |
| 13453 |
|
| 13454 |
procedure Write_Invocation_Path (In_State : Processing_In_State) is |
| 13455 |
procedure Write_Target (Targ_Id : Entity_Id; Is_First : Boolean); |
| 13456 |
pragma Inline (Write_Target); |
| 13457 |
-- Write out invocation target Targ_Id to standard output. Flag |
| 13458 |
-- Is_First should be set when the target is first in a path. |
| 13459 |
|
| 13460 |
------------- |
| 13461 |
-- Targ_Id -- |
| 13462 |
------------- |
| 13463 |
|
| 13464 |
procedure Write_Target (Targ_Id : Entity_Id; Is_First : Boolean) is |
| 13465 |
begin |
| 13466 |
if not Is_First then |
| 13467 |
Write_Str (" --> "); |
| 13468 |
end if; |
| 13469 |
|
| 13470 |
Write_Name (Get_Qualified_Name (Targ_Id)); |
| 13471 |
Write_Eol; |
| 13472 |
end Write_Target; |
| 13473 |
|
| 13474 |
-- Local variables |
| 13475 |
|
| 13476 |
package Scenarios renames Active_Scenario_Stack; |
| 13477 |
|
| 13478 |
First_Seen : Boolean := False; |
| 13479 |
|
| 13480 |
-- Start of processing for Write_Invocation_Path |
| 13481 |
|
| 13482 |
begin |
| 13483 |
-- Nothing to do when flag -gnatd_T (output trace information on |
| 13484 |
-- invocation path recording) is not in effect. |
| 13485 |
|
| 13486 |
if not Debug_Flag_Underscore_TT then |
| 13487 |
return; |
| 13488 |
end if; |
| 13489 |
|
| 13490 |
-- The path originates from the elaboration of the body. Write the |
| 13491 |
-- elaboration body procedure. |
| 13492 |
|
| 13493 |
if In_State.Processing = Invocation_Body_Processing then |
| 13494 |
Write_Target (Elab_Body_Id, True); |
| 13495 |
First_Seen := True; |
| 13496 |
|
| 13497 |
-- The path originates from the elaboration of the spec. Write the |
| 13498 |
-- elaboration spec procedure. |
| 13499 |
|
| 13500 |
elsif In_State.Processing = Invocation_Spec_Processing then |
| 13501 |
Write_Target (Elab_Spec_Id, True); |
| 13502 |
First_Seen := True; |
| 13503 |
end if; |
| 13504 |
|
| 13505 |
-- Write each individual target invoked by its corresponding scenario |
| 13506 |
-- on the active scenario stack. |
| 13507 |
|
| 13508 |
for Index in Scenarios.First .. Scenarios.Last loop |
| 13509 |
Write_Target |
| 13510 |
(Targ_Id => Target_Of (Index, In_State), |
| 13511 |
Is_First => Index = Scenarios.First and then not First_Seen); |
| 13512 |
end loop; |
| 13513 |
|
| 13514 |
Write_Eol; |
| 13515 |
end Write_Invocation_Path; |
| 13516 |
end Invocation_Graph; |
| 13517 |
|
| 13518 |
------------------------ |
| 13519 |
-- Is_Safe_Activation -- |
| 13520 |
------------------------ |
| 13521 |
|
| 13522 |
function Is_Safe_Activation |
| 13523 |
(Call : Node_Id; |
| 13524 |
Task_Rep : Target_Rep_Id) return Boolean |
| 13525 |
is |
| 13526 |
begin |
| 13527 |
-- The activation of a task coming from an external instance cannot |
| 13528 |
-- cause an ABE because the generic was already instantiated. Note |
| 13529 |
-- that the instantiation itself may lead to an ABE. |
| 13530 |
|
| 13531 |
return |
| 13532 |
In_External_Instance |
| 13533 |
(N => Call, |
| 13534 |
Target_Decl => Spec_Declaration (Task_Rep)); |
| 13535 |
end Is_Safe_Activation; |
| 13536 |
|
| 13537 |
------------------ |
| 13538 |
-- Is_Safe_Call -- |
| 13539 |
------------------ |
| 13540 |
|
| 13541 |
function Is_Safe_Call |
| 13542 |
(Call : Node_Id; |
| 13543 |
Subp_Id : Entity_Id; |
| 13544 |
Subp_Rep : Target_Rep_Id) return Boolean |
| 13545 |
is |
| 13546 |
Body_Decl : constant Node_Id := Body_Declaration (Subp_Rep); |
| 13547 |
Spec_Decl : constant Node_Id := Spec_Declaration (Subp_Rep); |
| 13548 |
|
| 13549 |
begin |
| 13550 |
-- The target is either an abstract subprogram, formal subprogram, or |
| 13551 |
-- imported, in which case it does not have a body at compile or bind |
| 13552 |
-- time. Assume that the call is ABE-safe. |
| 13553 |
|
| 13554 |
if Is_Bodiless_Subprogram (Subp_Id) then |
| 13555 |
return True; |
| 13556 |
|
| 13557 |
-- The target is an instantiation of a generic subprogram. The call |
| 13558 |
-- cannot cause an ABE because the generic was already instantiated. |
| 13559 |
-- Note that the instantiation itself may lead to an ABE. |
| 13560 |
|
| 13561 |
elsif Is_Generic_Instance (Subp_Id) then |
| 13562 |
return True; |
| 13563 |
|
| 13564 |
-- The invocation of a target coming from an external instance cannot |
| 13565 |
-- cause an ABE because the generic was already instantiated. Note that |
| 13566 |
-- the instantiation itself may lead to an ABE. |
| 13567 |
|
| 13568 |
elsif In_External_Instance |
| 13569 |
(N => Call, |
| 13570 |
Target_Decl => Spec_Decl) |
| 13571 |
then |
| 13572 |
return True; |
| 13573 |
|
| 13574 |
-- The target is a subprogram body without a previous declaration. The |
| 13575 |
-- call cannot cause an ABE because the body has already been seen. |
| 13576 |
|
| 13577 |
elsif Nkind (Spec_Decl) = N_Subprogram_Body |
| 13578 |
and then No (Corresponding_Spec (Spec_Decl)) |
| 13579 |
then |
| 13580 |
return True; |
| 13581 |
|
| 13582 |
-- The target is a subprogram body stub without a prior declaration. |
| 13583 |
-- The call cannot cause an ABE because the proper body substitutes |
| 13584 |
-- the stub. |
| 13585 |
|
| 13586 |
elsif Nkind (Spec_Decl) = N_Subprogram_Body_Stub |
| 13587 |
and then No (Corresponding_Spec_Of_Stub (Spec_Decl)) |
| 13588 |
then |
| 13589 |
return True; |
| 13590 |
|
| 13591 |
-- A call to an expression function that is not a completion cannot |
| 13592 |
-- cause an ABE because it has no prior declaration; this remains |
| 13593 |
-- true even if the FE transforms the callee into something else. |
| 13594 |
|
| 13595 |
elsif Nkind (Original_Node (Spec_Decl)) = N_Expression_Function then |
| 13596 |
return True; |
| 13597 |
|
| 13598 |
-- Subprogram bodies which wrap attribute references used as actuals |
| 13599 |
-- in instantiations are always ABE-safe. These bodies are artifacts |
| 13600 |
-- of expansion. |
| 13601 |
|
| 13602 |
elsif Present (Body_Decl) |
| 13603 |
and then Nkind (Body_Decl) = N_Subprogram_Body |
| 13604 |
and then Was_Attribute_Reference (Body_Decl) |
| 13605 |
then |
| 13606 |
return True; |
| 13607 |
end if; |
| 13608 |
|
| 13609 |
return False; |
| 13610 |
end Is_Safe_Call; |
| 13611 |
|
| 13612 |
--------------------------- |
| 13613 |
-- Is_Safe_Instantiation -- |
| 13614 |
--------------------------- |
| 13615 |
|
| 13616 |
function Is_Safe_Instantiation |
| 13617 |
(Inst : Node_Id; |
| 13618 |
Gen_Id : Entity_Id; |
| 13619 |
Gen_Rep : Target_Rep_Id) return Boolean |
| 13620 |
is |
| 13621 |
Spec_Decl : constant Node_Id := Spec_Declaration (Gen_Rep); |
| 13622 |
|
| 13623 |
begin |
| 13624 |
-- The generic is an intrinsic subprogram in which case it does not |
| 13625 |
-- have a body at compile or bind time. Assume that the instantiation |
| 13626 |
-- is ABE-safe. |
| 13627 |
|
| 13628 |
if Is_Bodiless_Subprogram (Gen_Id) then |
| 13629 |
return True; |
| 13630 |
|
| 13631 |
-- The instantiation of an external nested generic cannot cause an ABE |
| 13632 |
-- if the outer generic was already instantiated. Note that the instance |
| 13633 |
-- of the outer generic may lead to an ABE. |
| 13634 |
|
| 13635 |
elsif In_External_Instance |
| 13636 |
(N => Inst, |
| 13637 |
Target_Decl => Spec_Decl) |
| 13638 |
then |
| 13639 |
return True; |
| 13640 |
|
| 13641 |
-- The generic is a package. The instantiation cannot cause an ABE when |
| 13642 |
-- the package has no body. |
| 13643 |
|
| 13644 |
elsif Ekind (Gen_Id) = E_Generic_Package |
| 13645 |
and then not Has_Body (Spec_Decl) |
| 13646 |
then |
| 13647 |
return True; |
| 13648 |
end if; |
| 13649 |
|
| 13650 |
return False; |
| 13651 |
end Is_Safe_Instantiation; |
| 13652 |
|
| 13653 |
------------------ |
| 13654 |
-- Is_Same_Unit -- |
| 13655 |
------------------ |
| 13656 |
|
| 13657 |
function Is_Same_Unit |
| 13658 |
(Unit_1 : Entity_Id; |
| 13659 |
Unit_2 : Entity_Id) return Boolean |
| 13660 |
is |
| 13661 |
begin |
| 13662 |
return Unit_Entity (Unit_1) = Unit_Entity (Unit_2); |
| 13663 |
end Is_Same_Unit; |
| 13664 |
|
| 13665 |
------------------------------- |
| 13666 |
-- Kill_Elaboration_Scenario -- |
| 13667 |
------------------------------- |
| 13668 |
|
| 13669 |
procedure Kill_Elaboration_Scenario (N : Node_Id) is |
| 13670 |
begin |
| 13671 |
-- Nothing to do when switch -gnatH (legacy elaboration checking mode |
| 13672 |
-- enabled) is in effect because the legacy ABE lechanism does not need |
| 13673 |
-- to carry out this action. |
| 13674 |
|
| 13675 |
if Legacy_Elaboration_Checks then |
| 13676 |
return; |
| 13677 |
|
| 13678 |
-- Nothing to do when the elaboration phase of the compiler is not |
| 13679 |
-- active. |
| 13680 |
|
| 13681 |
elsif not Elaboration_Phase_Active then |
| 13682 |
return; |
| 13683 |
end if; |
| 13684 |
|
| 13685 |
-- Eliminate a recorded scenario when it appears within dead code |
| 13686 |
-- because it will not be executed at elaboration time. |
| 13687 |
|
| 13688 |
if Is_Scenario (N) then |
| 13689 |
Delete_Scenario (N); |
| 13690 |
end if; |
| 13691 |
end Kill_Elaboration_Scenario; |
| 13692 |
|
| 13693 |
---------------------- |
| 13694 |
-- Main_Unit_Entity -- |
| 13695 |
---------------------- |
| 13696 |
|
| 13697 |
function Main_Unit_Entity return Entity_Id is |
| 13698 |
begin |
| 13699 |
-- Note that Cunit_Entity (Main_Unit) is not reliable in the presence of |
| 13700 |
-- generic bodies and may return an outdated entity. |
| 13701 |
|
| 13702 |
return Defining_Entity (Unit (Cunit (Main_Unit))); |
| 13703 |
end Main_Unit_Entity; |
| 13704 |
|
| 13705 |
---------------------- |
| 13706 |
-- Non_Private_View -- |
| 13707 |
---------------------- |
| 13708 |
|
| 13709 |
function Non_Private_View (Typ : Entity_Id) return Entity_Id is |
| 13710 |
begin |
| 13711 |
if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then |
| 13712 |
return Full_View (Typ); |
| 13713 |
else |
| 13714 |
return Typ; |
| 13715 |
end if; |
| 13716 |
end Non_Private_View; |
| 13717 |
|
| 13718 |
--------------------------------- |
| 13719 |
-- Record_Elaboration_Scenario -- |
| 13720 |
--------------------------------- |
| 13721 |
|
| 13722 |
procedure Record_Elaboration_Scenario (N : Node_Id) is |
| 13723 |
procedure Check_Preelaborated_Call |
| 13724 |
(Call : Node_Id; |
| 13725 |
Call_Lvl : Enclosing_Level_Kind); |
| 13726 |
pragma Inline (Check_Preelaborated_Call); |
| 13727 |
-- Verify that entry, operator, or subprogram call Call with enclosing |
| 13728 |
-- level Call_Lvl does not appear at the library level of preelaborated |
| 13729 |
-- unit. |
| 13730 |
|
| 13731 |
function Find_Code_Unit (Nod : Node_Or_Entity_Id) return Entity_Id; |
| 13732 |
pragma Inline (Find_Code_Unit); |
| 13733 |
-- Return the code unit which contains arbitrary node or entity Nod. |
| 13734 |
-- This is the unit of the file which physically contains the related |
| 13735 |
-- construct denoted by Nod except when Nod is within an instantiation. |
| 13736 |
-- In that case the unit is that of the top-level instantiation. |
| 13737 |
|
| 13738 |
function In_Preelaborated_Context (Nod : Node_Id) return Boolean; |
| 13739 |
pragma Inline (In_Preelaborated_Context); |
| 13740 |
-- Determine whether arbitrary node Nod appears within a preelaborated |
| 13741 |
-- context. |
| 13742 |
|
| 13743 |
procedure Record_Access_Taken |
| 13744 |
(Attr : Node_Id; |
| 13745 |
Attr_Lvl : Enclosing_Level_Kind); |
| 13746 |
pragma Inline (Record_Access_Taken); |
| 13747 |
-- Record 'Access scenario Attr with enclosing level Attr_Lvl |
| 13748 |
|
| 13749 |
procedure Record_Call_Or_Task_Activation |
| 13750 |
(Call : Node_Id; |
| 13751 |
Call_Lvl : Enclosing_Level_Kind); |
| 13752 |
pragma Inline (Record_Call_Or_Task_Activation); |
| 13753 |
-- Record call scenario Call with enclosing level Call_Lvl |
| 13754 |
|
| 13755 |
procedure Record_Instantiation |
| 13756 |
(Inst : Node_Id; |
| 13757 |
Inst_Lvl : Enclosing_Level_Kind); |
| 13758 |
pragma Inline (Record_Instantiation); |
| 13759 |
-- Record instantiation scenario Inst with enclosing level Inst_Lvl |
| 13760 |
|
| 13761 |
procedure Record_Variable_Assignment |
| 13762 |
(Asmt : Node_Id; |
| 13763 |
Asmt_Lvl : Enclosing_Level_Kind); |
| 13764 |
pragma Inline (Record_Variable_Assignment); |
| 13765 |
-- Record variable assignment scenario Asmt with enclosing level |
| 13766 |
-- Asmt_Lvl. |
| 13767 |
|
| 13768 |
procedure Record_Variable_Reference |
| 13769 |
(Ref : Node_Id; |
| 13770 |
Ref_Lvl : Enclosing_Level_Kind); |
| 13771 |
pragma Inline (Record_Variable_Reference); |
| 13772 |
-- Record variable reference scenario Ref with enclosing level Ref_Lvl |
| 13773 |
|
| 13774 |
------------------------------ |
| 13775 |
-- Check_Preelaborated_Call -- |
| 13776 |
------------------------------ |
| 13777 |
|
| 13778 |
procedure Check_Preelaborated_Call |
| 13779 |
(Call : Node_Id; |
| 13780 |
Call_Lvl : Enclosing_Level_Kind) |
| 13781 |
is |
| 13782 |
begin |
| 13783 |
-- Nothing to do when the call is internally generated because it is |
| 13784 |
-- assumed that it will never violate preelaboration. |
| 13785 |
|
| 13786 |
if not Is_Source_Call (Call) then |
| 13787 |
return; |
| 13788 |
|
| 13789 |
-- Nothing to do when the call is preelaborable by definition |
| 13790 |
|
| 13791 |
elsif Is_Preelaborable_Call (Call) then |
| 13792 |
return; |
| 13793 |
|
| 13794 |
-- Library-level calls are always considered because they are part of |
| 13795 |
-- the associated unit's elaboration actions. |
| 13796 |
|
| 13797 |
elsif Call_Lvl in Library_Level then |
| 13798 |
null; |
| 13799 |
|
| 13800 |
-- Calls at the library level of a generic package body have to be |
| 13801 |
-- checked because they would render an instantiation illegal if the |
| 13802 |
-- template is marked as preelaborated. Note that this does not apply |
| 13803 |
-- to calls at the library level of a generic package spec. |
| 13804 |
|
| 13805 |
elsif Call_Lvl = Generic_Body_Level then |
| 13806 |
null; |
| 13807 |
|
| 13808 |
-- Otherwise the call does not appear at the proper level and must |
| 13809 |
-- not be considered for this check. |
| 13810 |
|
| 13811 |
else |
| 13812 |
return; |
| 13813 |
end if; |
| 13814 |
|
| 13815 |
-- If the call appears within a preelaborated unit, give an error |
| 13816 |
|
| 13817 |
if In_Preelaborated_Context (Call) then |
| 13818 |
Error_Preelaborated_Call (Call); |
| 13819 |
end if; |
| 13820 |
end Check_Preelaborated_Call; |
| 13821 |
|
| 13822 |
-------------------- |
| 13823 |
-- Find_Code_Unit -- |
| 13824 |
-------------------- |
| 13825 |
|
| 13826 |
function Find_Code_Unit (Nod : Node_Or_Entity_Id) return Entity_Id is |
| 13827 |
begin |
| 13828 |
return Find_Unit_Entity (Unit (Cunit (Get_Code_Unit (Nod)))); |
| 13829 |
end Find_Code_Unit; |
| 13830 |
|
| 13831 |
------------------------------ |
| 13832 |
-- In_Preelaborated_Context -- |
| 13833 |
------------------------------ |
| 13834 |
|
| 13835 |
function In_Preelaborated_Context (Nod : Node_Id) return Boolean is |
| 13836 |
Body_Id : constant Entity_Id := Find_Code_Unit (Nod); |
| 13837 |
Spec_Id : constant Entity_Id := Unique_Entity (Body_Id); |
| 13838 |
|
| 13839 |
begin |
| 13840 |
-- The node appears within a package body whose corresponding spec is |
| 13841 |
-- subject to pragma Remote_Call_Interface or Remote_Types. This does |
| 13842 |
-- not result in a preelaborated context because the package body may |
| 13843 |
-- be on another machine. |
| 13844 |
|
| 13845 |
if Ekind (Body_Id) = E_Package_Body |
| 13846 |
and then Is_Package_Or_Generic_Package (Spec_Id) |
| 13847 |
and then (Is_Remote_Call_Interface (Spec_Id) |
| 13848 |
or else Is_Remote_Types (Spec_Id)) |
| 13849 |
then |
| 13850 |
return False; |
| 13851 |
|
| 13852 |
-- Otherwise the node appears within a preelaborated context when the |
| 13853 |
-- associated unit is preelaborated. |
| 13854 |
|
| 13855 |
else |
| 13856 |
return Is_Preelaborated_Unit (Spec_Id); |
| 13857 |
end if; |
| 13858 |
end In_Preelaborated_Context; |
| 13859 |
|
| 13860 |
------------------------- |
| 13861 |
-- Record_Access_Taken -- |
| 13862 |
------------------------- |
| 13863 |
|
| 13864 |
procedure Record_Access_Taken |
| 13865 |
(Attr : Node_Id; |
| 13866 |
Attr_Lvl : Enclosing_Level_Kind) |
| 13867 |
is |
| 13868 |
begin |
| 13869 |
-- Signal any enclosing local exception handlers that the 'Access may |
| 13870 |
-- raise Program_Error due to a failed ABE check when switch -gnatd.o |
| 13871 |
-- (conservative elaboration order for indirect calls) is in effect. |
| 13872 |
-- Marking the exception handlers ensures proper expansion by both |
| 13873 |
-- the front and back end restriction when No_Exception_Propagation |
| 13874 |
-- is in effect. |
| 13875 |
|
| 13876 |
if Debug_Flag_Dot_O then |
| 13877 |
Possible_Local_Raise (Attr, Standard_Program_Error); |
| 13878 |
end if; |
| 13879 |
|
| 13880 |
-- Add 'Access to the appropriate set |
| 13881 |
|
| 13882 |
if Attr_Lvl = Library_Body_Level then |
| 13883 |
Add_Library_Body_Scenario (Attr); |
| 13884 |
|
| 13885 |
elsif Attr_Lvl = Library_Spec_Level |
| 13886 |
or else Attr_Lvl = Instantiation_Level |
| 13887 |
then |
| 13888 |
Add_Library_Spec_Scenario (Attr); |
| 13889 |
end if; |
| 13890 |
|
| 13891 |
-- 'Access requires a conditional ABE check when the dynamic model is |
| 13892 |
-- in effect. |
| 13893 |
|
| 13894 |
Add_Dynamic_ABE_Check_Scenario (Attr); |
| 13895 |
end Record_Access_Taken; |
| 13896 |
|
| 13897 |
------------------------------------ |
| 13898 |
-- Record_Call_Or_Task_Activation -- |
| 13899 |
------------------------------------ |
| 13900 |
|
| 13901 |
procedure Record_Call_Or_Task_Activation |
| 13902 |
(Call : Node_Id; |
| 13903 |
Call_Lvl : Enclosing_Level_Kind) |
| 13904 |
is |
| 13905 |
begin |
| 13906 |
-- Signal any enclosing local exception handlers that the call may |
| 13907 |
-- raise Program_Error due to failed ABE check. Marking the exception |
| 13908 |
-- handlers ensures proper expansion by both the front and back end |
| 13909 |
-- restriction when No_Exception_Propagation is in effect. |
| 13910 |
|
| 13911 |
Possible_Local_Raise (Call, Standard_Program_Error); |
| 13912 |
|
| 13913 |
-- Perform early detection of guaranteed ABEs in order to suppress |
| 13914 |
-- the instantiation of generic bodies because gigi cannot handle |
| 13915 |
-- certain types of premature instantiations. |
| 13916 |
|
| 13917 |
Process_Guaranteed_ABE |
| 13918 |
(N => Call, |
| 13919 |
In_State => Guaranteed_ABE_State); |
| 13920 |
|
| 13921 |
-- Add the call or task activation to the appropriate set |
| 13922 |
|
| 13923 |
if Call_Lvl = Declaration_Level then |
| 13924 |
Add_Declaration_Scenario (Call); |
| 13925 |
|
| 13926 |
elsif Call_Lvl = Library_Body_Level then |
| 13927 |
Add_Library_Body_Scenario (Call); |
| 13928 |
|
| 13929 |
elsif Call_Lvl = Library_Spec_Level |
| 13930 |
or else Call_Lvl = Instantiation_Level |
| 13931 |
then |
| 13932 |
Add_Library_Spec_Scenario (Call); |
| 13933 |
end if; |
| 13934 |
|
| 13935 |
-- A call or a task activation requires a conditional ABE check when |
| 13936 |
-- the dynamic model is in effect. |
| 13937 |
|
| 13938 |
Add_Dynamic_ABE_Check_Scenario (Call); |
| 13939 |
end Record_Call_Or_Task_Activation; |
| 13940 |
|
| 13941 |
-------------------------- |
| 13942 |
-- Record_Instantiation -- |
| 13943 |
-------------------------- |
| 13944 |
|
| 13945 |
procedure Record_Instantiation |
| 13946 |
(Inst : Node_Id; |
| 13947 |
Inst_Lvl : Enclosing_Level_Kind) |
| 13948 |
is |
| 13949 |
begin |
| 13950 |
-- Signal enclosing local exception handlers that instantiation may |
| 13951 |
-- raise Program_Error due to failed ABE check. Marking the exception |
| 13952 |
-- handlers ensures proper expansion by both the front and back end |
| 13953 |
-- restriction when No_Exception_Propagation is in effect. |
| 13954 |
|
| 13955 |
Possible_Local_Raise (Inst, Standard_Program_Error); |
| 13956 |
|
| 13957 |
-- Perform early detection of guaranteed ABEs in order to suppress |
| 13958 |
-- the instantiation of generic bodies because gigi cannot handle |
| 13959 |
-- certain types of premature instantiations. |
| 13960 |
|
| 13961 |
Process_Guaranteed_ABE |
| 13962 |
(N => Inst, |
| 13963 |
In_State => Guaranteed_ABE_State); |
| 13964 |
|
| 13965 |
-- Add the instantiation to the appropriate set |
| 13966 |
|
| 13967 |
if Inst_Lvl = Declaration_Level then |
| 13968 |
Add_Declaration_Scenario (Inst); |
| 13969 |
|
| 13970 |
elsif Inst_Lvl = Library_Body_Level then |
| 13971 |
Add_Library_Body_Scenario (Inst); |
| 13972 |
|
| 13973 |
elsif Inst_Lvl = Library_Spec_Level |
| 13974 |
or else Inst_Lvl = Instantiation_Level |
| 13975 |
then |
| 13976 |
Add_Library_Spec_Scenario (Inst); |
| 13977 |
end if; |
| 13978 |
|
| 13979 |
-- Instantiations of generics subject to SPARK_Mode On require |
| 13980 |
-- elaboration-related checks even though the instantiations may |
| 13981 |
-- not appear within elaboration code. |
| 13982 |
|
| 13983 |
if Is_Suitable_SPARK_Instantiation (Inst) then |
| 13984 |
Add_SPARK_Scenario (Inst); |
| 13985 |
end if; |
| 13986 |
|
| 13987 |
-- An instantiation requires a conditional ABE check when the dynamic |
| 13988 |
-- model is in effect. |
| 13989 |
|
| 13990 |
Add_Dynamic_ABE_Check_Scenario (Inst); |
| 13991 |
end Record_Instantiation; |
| 13992 |
|
| 13993 |
-------------------------------- |
| 13994 |
-- Record_Variable_Assignment -- |
| 13995 |
-------------------------------- |
| 13996 |
|
| 13997 |
procedure Record_Variable_Assignment |
| 13998 |
(Asmt : Node_Id; |
| 13999 |
Asmt_Lvl : Enclosing_Level_Kind) |
| 14000 |
is |
| 14001 |
begin |
| 14002 |
-- Add the variable assignment to the appropriate set |
| 14003 |
|
| 14004 |
if Asmt_Lvl = Library_Body_Level then |
| 14005 |
Add_Library_Body_Scenario (Asmt); |
| 14006 |
|
| 14007 |
elsif Asmt_Lvl = Library_Spec_Level |
| 14008 |
or else Asmt_Lvl = Instantiation_Level |
| 14009 |
then |
| 14010 |
Add_Library_Spec_Scenario (Asmt); |
| 14011 |
end if; |
| 14012 |
end Record_Variable_Assignment; |
| 14013 |
|
| 14014 |
------------------------------- |
| 14015 |
-- Record_Variable_Reference -- |
| 14016 |
------------------------------- |
| 14017 |
|
| 14018 |
procedure Record_Variable_Reference |
| 14019 |
(Ref : Node_Id; |
| 14020 |
Ref_Lvl : Enclosing_Level_Kind) |
| 14021 |
is |
| 14022 |
begin |
| 14023 |
-- Add the variable reference to the appropriate set |
| 14024 |
|
| 14025 |
if Ref_Lvl = Library_Body_Level then |
| 14026 |
Add_Library_Body_Scenario (Ref); |
| 14027 |
|
| 14028 |
elsif Ref_Lvl = Library_Spec_Level |
| 14029 |
or else Ref_Lvl = Instantiation_Level |
| 14030 |
then |
| 14031 |
Add_Library_Spec_Scenario (Ref); |
| 14032 |
end if; |
| 14033 |
end Record_Variable_Reference; |
| 14034 |
|
| 14035 |
-- Local variables |
| 14036 |
|
| 14037 |
Scen : constant Node_Id := Scenario (N); |
| 14038 |
Scen_Lvl : Enclosing_Level_Kind; |
| 14039 |
|
| 14040 |
-- Start of processing for Record_Elaboration_Scenario |
| 14041 |
|
| 14042 |
begin |
| 14043 |
-- Nothing to do when switch -gnatH (legacy elaboration checking mode |
| 14044 |
-- enabled) is in effect because the legacy ABE mechanism does not need |
| 14045 |
-- to carry out this action. |
| 14046 |
|
| 14047 |
if Legacy_Elaboration_Checks then |
| 14048 |
return; |
| 14049 |
|
| 14050 |
-- Nothing to do when the scenario is being preanalyzed |
| 14051 |
|
| 14052 |
elsif Preanalysis_Active then |
| 14053 |
return; |
| 14054 |
|
| 14055 |
-- Nothing to do when the elaboration phase of the compiler is not |
| 14056 |
-- active. |
| 14057 |
|
| 14058 |
elsif not Elaboration_Phase_Active then |
| 14059 |
return; |
| 14060 |
end if; |
| 14061 |
|
| 14062 |
Scen_Lvl := Find_Enclosing_Level (Scen); |
| 14063 |
|
| 14064 |
-- Ensure that a library-level call does not appear in a preelaborated |
| 14065 |
-- unit. The check must come before ignoring scenarios within external |
| 14066 |
-- units or inside generics because calls in those context must also be |
| 14067 |
-- verified. |
| 14068 |
|
| 14069 |
if Is_Suitable_Call (Scen) then |
| 14070 |
Check_Preelaborated_Call (Scen, Scen_Lvl); |
| 14071 |
end if; |
| 14072 |
|
| 14073 |
-- Nothing to do when the scenario does not appear within the main unit |
| 14074 |
|
| 14075 |
if not In_Main_Context (Scen) then |
| 14076 |
return; |
| 14077 |
|
| 14078 |
-- Nothing to do when the scenario appears within a generic |
| 14079 |
|
| 14080 |
elsif Inside_A_Generic then |
| 14081 |
return; |
| 14082 |
|
| 14083 |
-- 'Access |
| 14084 |
|
| 14085 |
elsif Is_Suitable_Access_Taken (Scen) then |
| 14086 |
Record_Access_Taken |
| 14087 |
(Attr => Scen, |
| 14088 |
Attr_Lvl => Scen_Lvl); |
| 14089 |
|
| 14090 |
-- Call or task activation |
| 14091 |
|
| 14092 |
elsif Is_Suitable_Call (Scen) then |
| 14093 |
Record_Call_Or_Task_Activation |
| 14094 |
(Call => Scen, |
| 14095 |
Call_Lvl => Scen_Lvl); |
| 14096 |
|
| 14097 |
-- Derived type declaration |
| 14098 |
|
| 14099 |
elsif Is_Suitable_SPARK_Derived_Type (Scen) then |
| 14100 |
Add_SPARK_Scenario (Scen); |
| 14101 |
|
| 14102 |
-- Instantiation |
| 14103 |
|
| 14104 |
elsif Is_Suitable_Instantiation (Scen) then |
| 14105 |
Record_Instantiation |
| 14106 |
(Inst => Scen, |
| 14107 |
Inst_Lvl => Scen_Lvl); |
| 14108 |
|
| 14109 |
-- Refined_State pragma |
| 14110 |
|
| 14111 |
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then |
| 14112 |
Add_SPARK_Scenario (Scen); |
| 14113 |
|
| 14114 |
-- Variable assignment |
| 14115 |
|
| 14116 |
elsif Is_Suitable_Variable_Assignment (Scen) then |
| 14117 |
Record_Variable_Assignment |
| 14118 |
(Asmt => Scen, |
| 14119 |
Asmt_Lvl => Scen_Lvl); |
| 14120 |
|
| 14121 |
-- Variable reference |
| 14122 |
|
| 14123 |
elsif Is_Suitable_Variable_Reference (Scen) then |
| 14124 |
Record_Variable_Reference |
| 14125 |
(Ref => Scen, |
| 14126 |
Ref_Lvl => Scen_Lvl); |
| 14127 |
end if; |
| 14128 |
end Record_Elaboration_Scenario; |
| 14129 |
|
| 14130 |
-------------- |
| 14131 |
-- Scenario -- |
| 14132 |
-------------- |
| 14133 |
|
| 14134 |
function Scenario (N : Node_Id) return Node_Id is |
| 14135 |
Orig_N : constant Node_Id := Original_Node (N); |
| 14136 |
|
| 14137 |
begin |
| 14138 |
-- An expanded instantiation is rewritten into a spec-body pair where |
| 14139 |
-- N denotes the spec. In this case the original instantiation is the |
| 14140 |
-- proper elaboration scenario. |
| 14141 |
|
| 14142 |
if Nkind (Orig_N) in N_Generic_Instantiation then |
| 14143 |
return Orig_N; |
| 14144 |
|
| 14145 |
-- Otherwise the scenario is already in its proper form |
| 14146 |
|
| 14147 |
else |
| 14148 |
return N; |
| 14149 |
end if; |
| 14150 |
end Scenario; |
| 14151 |
|
| 14152 |
---------------------- |
| 14153 |
-- Scenario_Storage -- |
| 14154 |
---------------------- |
| 14155 |
|
| 14156 |
package body Scenario_Storage is |
| 14157 |
|
| 14158 |
--------------------- |
| 14159 |
-- Data structures -- |
| 14160 |
--------------------- |
| 14161 |
|
| 14162 |
-- The following sets store all scenarios |
| 14163 |
|
| 14164 |
Declaration_Scenarios : NE_Set.Membership_Set := NE_Set.Nil; |
| 14165 |
Dynamic_ABE_Check_Scenarios : NE_Set.Membership_Set := NE_Set.Nil; |
| 14166 |
Library_Body_Scenarios : NE_Set.Membership_Set := NE_Set.Nil; |
| 14167 |
Library_Spec_Scenarios : NE_Set.Membership_Set := NE_Set.Nil; |
| 14168 |
SPARK_Scenarios : NE_Set.Membership_Set := NE_Set.Nil; |
| 14169 |
|
| 14170 |
------------------------------- |
| 14171 |
-- Finalize_Scenario_Storage -- |
| 14172 |
------------------------------- |
| 14173 |
|
| 14174 |
procedure Finalize_Scenario_Storage is |
| 14175 |
begin |
| 14176 |
NE_Set.Destroy (Declaration_Scenarios); |
| 14177 |
NE_Set.Destroy (Dynamic_ABE_Check_Scenarios); |
| 14178 |
NE_Set.Destroy (Library_Body_Scenarios); |
| 14179 |
NE_Set.Destroy (Library_Spec_Scenarios); |
| 14180 |
NE_Set.Destroy (SPARK_Scenarios); |
| 14181 |
end Finalize_Scenario_Storage; |
| 14182 |
|
| 14183 |
--------------------------------- |
| 14184 |
-- Initialize_Scenario_Storage -- |
| 14185 |
--------------------------------- |
| 14186 |
|
| 14187 |
procedure Initialize_Scenario_Storage is |
| 14188 |
begin |
| 14189 |
Declaration_Scenarios := NE_Set.Create (1000); |
| 14190 |
Dynamic_ABE_Check_Scenarios := NE_Set.Create (500); |
| 14191 |
Library_Body_Scenarios := NE_Set.Create (1000); |
| 14192 |
Library_Spec_Scenarios := NE_Set.Create (1000); |
| 14193 |
SPARK_Scenarios := NE_Set.Create (100); |
| 14194 |
end Initialize_Scenario_Storage; |
| 14195 |
|
| 14196 |
------------------------------ |
| 14197 |
-- Add_Declaration_Scenario -- |
| 14198 |
------------------------------ |
| 14199 |
|
| 14200 |
procedure Add_Declaration_Scenario (N : Node_Id) is |
| 14201 |
pragma Assert (Present (N)); |
| 14202 |
begin |
| 14203 |
NE_Set.Insert (Declaration_Scenarios, N); |
| 14204 |
end Add_Declaration_Scenario; |
| 14205 |
|
| 14206 |
------------------------------------ |
| 14207 |
-- Add_Dynamic_ABE_Check_Scenario -- |
| 14208 |
------------------------------------ |
| 14209 |
|
| 14210 |
procedure Add_Dynamic_ABE_Check_Scenario (N : Node_Id) is |
| 14211 |
pragma Assert (Present (N)); |
| 14212 |
|
| 14213 |
begin |
| 14214 |
if not Check_Or_Failure_Generation_OK then |
| 14215 |
return; |
| 14216 |
|
| 14217 |
-- Nothing to do if the dynamic model is not in effect |
| 14218 |
|
| 14219 |
elsif not Dynamic_Elaboration_Checks then |
| 14220 |
return; |
| 14221 |
end if; |
| 14222 |
|
| 14223 |
NE_Set.Insert (Dynamic_ABE_Check_Scenarios, N); |
| 14224 |
end Add_Dynamic_ABE_Check_Scenario; |
| 14225 |
|
| 14226 |
------------------------------- |
| 14227 |
-- Add_Library_Body_Scenario -- |
| 14228 |
------------------------------- |
| 14229 |
|
| 14230 |
procedure Add_Library_Body_Scenario (N : Node_Id) is |
| 14231 |
pragma Assert (Present (N)); |
| 14232 |
begin |
| 14233 |
NE_Set.Insert (Library_Body_Scenarios, N); |
| 14234 |
end Add_Library_Body_Scenario; |
| 14235 |
|
| 14236 |
------------------------------- |
| 14237 |
-- Add_Library_Spec_Scenario -- |
| 14238 |
------------------------------- |
| 14239 |
|
| 14240 |
procedure Add_Library_Spec_Scenario (N : Node_Id) is |
| 14241 |
pragma Assert (Present (N)); |
| 14242 |
begin |
| 14243 |
NE_Set.Insert (Library_Spec_Scenarios, N); |
| 14244 |
end Add_Library_Spec_Scenario; |
| 14245 |
|
| 14246 |
------------------------ |
| 14247 |
-- Add_SPARK_Scenario -- |
| 14248 |
------------------------ |
| 14249 |
|
| 14250 |
procedure Add_SPARK_Scenario (N : Node_Id) is |
| 14251 |
pragma Assert (Present (N)); |
| 14252 |
begin |
| 14253 |
NE_Set.Insert (SPARK_Scenarios, N); |
| 14254 |
end Add_SPARK_Scenario; |
| 14255 |
|
| 14256 |
--------------------- |
| 14257 |
-- Delete_Scenario -- |
| 14258 |
--------------------- |
| 14259 |
|
| 14260 |
procedure Delete_Scenario (N : Node_Id) is |
| 14261 |
pragma Assert (Present (N)); |
| 14262 |
|
| 14263 |
begin |
| 14264 |
-- Delete the scenario from whichever set it belongs to |
| 14265 |
|
| 14266 |
NE_Set.Delete (Declaration_Scenarios, N); |
| 14267 |
NE_Set.Delete (Dynamic_ABE_Check_Scenarios, N); |
| 14268 |
NE_Set.Delete (Library_Body_Scenarios, N); |
| 14269 |
NE_Set.Delete (Library_Spec_Scenarios, N); |
| 14270 |
NE_Set.Delete (SPARK_Scenarios, N); |
| 14271 |
end Delete_Scenario; |
| 14272 |
|
| 14273 |
----------------------------------- |
| 14274 |
-- Iterate_Declaration_Scenarios -- |
| 14275 |
----------------------------------- |
| 14276 |
|
| 14277 |
function Iterate_Declaration_Scenarios return NE_Set.Iterator is |
| 14278 |
begin |
| 14279 |
return NE_Set.Iterate (Declaration_Scenarios); |
| 14280 |
end Iterate_Declaration_Scenarios; |
| 14281 |
|
| 14282 |
----------------------------------------- |
| 14283 |
-- Iterate_Dynamic_ABE_Check_Scenarios -- |
| 14284 |
----------------------------------------- |
| 14285 |
|
| 14286 |
function Iterate_Dynamic_ABE_Check_Scenarios return NE_Set.Iterator is |
| 14287 |
begin |
| 14288 |
return NE_Set.Iterate (Dynamic_ABE_Check_Scenarios); |
| 14289 |
end Iterate_Dynamic_ABE_Check_Scenarios; |
| 14290 |
|
| 14291 |
------------------------------------ |
| 14292 |
-- Iterate_Library_Body_Scenarios -- |
| 14293 |
------------------------------------ |
| 14294 |
|
| 14295 |
function Iterate_Library_Body_Scenarios return NE_Set.Iterator is |
| 14296 |
begin |
| 14297 |
return NE_Set.Iterate (Library_Body_Scenarios); |
| 14298 |
end Iterate_Library_Body_Scenarios; |
| 14299 |
|
| 14300 |
------------------------------------ |
| 14301 |
-- Iterate_Library_Spec_Scenarios -- |
| 14302 |
------------------------------------ |
| 14303 |
|
| 14304 |
function Iterate_Library_Spec_Scenarios return NE_Set.Iterator is |
| 14305 |
begin |
| 14306 |
return NE_Set.Iterate (Library_Spec_Scenarios); |
| 14307 |
end Iterate_Library_Spec_Scenarios; |
| 14308 |
|
| 14309 |
----------------------------- |
| 14310 |
-- Iterate_SPARK_Scenarios -- |
| 14311 |
----------------------------- |
| 14312 |
|
| 14313 |
function Iterate_SPARK_Scenarios return NE_Set.Iterator is |
| 14314 |
begin |
| 14315 |
return NE_Set.Iterate (SPARK_Scenarios); |
| 14316 |
end Iterate_SPARK_Scenarios; |
| 14317 |
|
| 14318 |
---------------------- |
| 14319 |
-- Replace_Scenario -- |
| 14320 |
---------------------- |
| 14321 |
|
| 14322 |
procedure Replace_Scenario (Old_N : Node_Id; New_N : Node_Id) is |
| 14323 |
procedure Replace_Scenario_In (Scenarios : NE_Set.Membership_Set); |
| 14324 |
-- Determine whether scenario Old_N is present in set Scenarios, and |
| 14325 |
-- if this is the case it, replace it with New_N. |
| 14326 |
|
| 14327 |
------------------------- |
| 14328 |
-- Replace_Scenario_In -- |
| 14329 |
------------------------- |
| 14330 |
|
| 14331 |
procedure Replace_Scenario_In (Scenarios : NE_Set.Membership_Set) is |
| 14332 |
begin |
| 14333 |
-- The set is intentionally checked for existance because node |
| 14334 |
-- rewriting may occur after Sem_Elab has verified all scenarios |
| 14335 |
-- and data structures have been destroyed. |
| 14336 |
|
| 14337 |
if NE_Set.Present (Scenarios) |
| 14338 |
and then NE_Set.Contains (Scenarios, Old_N) |
| 14339 |
then |
| 14340 |
NE_Set.Delete (Scenarios, Old_N); |
| 14341 |
NE_Set.Insert (Scenarios, New_N); |
| 14342 |
end if; |
| 14343 |
end Replace_Scenario_In; |
| 14344 |
|
| 14345 |
-- Start of processing for Replace_Scenario |
| 14346 |
|
| 14347 |
begin |
| 14348 |
Replace_Scenario_In (Declaration_Scenarios); |
| 14349 |
Replace_Scenario_In (Dynamic_ABE_Check_Scenarios); |
| 14350 |
Replace_Scenario_In (Library_Body_Scenarios); |
| 14351 |
Replace_Scenario_In (Library_Spec_Scenarios); |
| 14352 |
Replace_Scenario_In (SPARK_Scenarios); |
| 14353 |
end Replace_Scenario; |
| 14354 |
end Scenario_Storage; |
| 14355 |
|
| 14356 |
--------------- |
| 14357 |
-- Semantics -- |
| 14358 |
--------------- |
| 14359 |
|
| 14360 |
package body Semantics is |
| 14361 |
|
| 14362 |
-------------------------------- |
| 14363 |
-- Is_Accept_Alternative_Proc -- |
| 14364 |
-------------------------------- |
| 14365 |
|
| 14366 |
function Is_Accept_Alternative_Proc (Id : Entity_Id) return Boolean is |
| 14367 |
begin |
| 14368 |
-- To qualify, the entity must denote a procedure with a receiving |
| 14369 |
-- entry. |
| 14370 |
|
| 14371 |
return |
| 14372 |
Ekind (Id) = E_Procedure and then Present (Receiving_Entry (Id)); |
| 14373 |
end Is_Accept_Alternative_Proc; |
| 14374 |
|
| 14375 |
------------------------ |
| 14376 |
-- Is_Activation_Proc -- |
| 14377 |
------------------------ |
| 14378 |
|
| 14379 |
function Is_Activation_Proc (Id : Entity_Id) return Boolean is |
| 14380 |
begin |
| 14381 |
-- To qualify, the entity must denote one of the runtime procedures |
| 14382 |
-- in charge of task activation. |
| 14383 |
|
| 14384 |
if Ekind (Id) = E_Procedure then |
| 14385 |
if Restricted_Profile then |
| 14386 |
return Is_RTE (Id, RE_Activate_Restricted_Tasks); |
| 14387 |
else |
| 14388 |
return Is_RTE (Id, RE_Activate_Tasks); |
| 14389 |
end if; |
| 14390 |
end if; |
| 14391 |
|
| 14392 |
return False; |
| 14393 |
end Is_Activation_Proc; |
| 14394 |
|
| 14395 |
---------------------------- |
| 14396 |
-- Is_Ada_Semantic_Target -- |
| 14397 |
---------------------------- |
| 14398 |
|
| 14399 |
function Is_Ada_Semantic_Target (Id : Entity_Id) return Boolean is |
| 14400 |
begin |
| 14401 |
return |
| 14402 |
Is_Activation_Proc (Id) |
| 14403 |
or else Is_Controlled_Procedure (Id, Name_Adjust) |
| 14404 |
or else Is_Controlled_Procedure (Id, Name_Finalize) |
| 14405 |
or else Is_Controlled_Procedure (Id, Name_Initialize) |
| 14406 |
or else Is_Init_Proc (Id) |
| 14407 |
or else Is_Invariant_Proc (Id) |
| 14408 |
or else Is_Protected_Entry (Id) |
| 14409 |
or else Is_Protected_Subp (Id) |
| 14410 |
or else Is_Protected_Body_Subp (Id) |
| 14411 |
or else Is_Subprogram_Inst (Id) |
| 14412 |
or else Is_Task_Entry (Id); |
| 14413 |
end Is_Ada_Semantic_Target; |
| 14414 |
|
| 14415 |
-------------------------------- |
| 14416 |
-- Is_Assertion_Pragma_Target -- |
| 14417 |
-------------------------------- |
| 14418 |
|
| 14419 |
function Is_Assertion_Pragma_Target (Id : Entity_Id) return Boolean is |
| 14420 |
begin |
| 14421 |
return |
| 14422 |
Is_Default_Initial_Condition_Proc (Id) |
| 14423 |
or else Is_Initial_Condition_Proc (Id) |
| 14424 |
or else Is_Invariant_Proc (Id) |
| 14425 |
or else Is_Partial_Invariant_Proc (Id); |
| 14426 |
end Is_Assertion_Pragma_Target; |
| 14427 |
|
| 14428 |
---------------------------- |
| 14429 |
-- Is_Bodiless_Subprogram -- |
| 14430 |
---------------------------- |
| 14431 |
|
| 14432 |
function Is_Bodiless_Subprogram (Subp_Id : Entity_Id) return Boolean is |
| 14433 |
begin |
| 14434 |
-- An abstract subprogram does not have a body |
| 14435 |
|
| 14436 |
if Ekind (Subp_Id) in E_Function | E_Operator | E_Procedure |
| 14437 |
and then Is_Abstract_Subprogram (Subp_Id) |
| 14438 |
then |
| 14439 |
return True; |
| 14440 |
|
| 14441 |
-- A formal subprogram does not have a body |
| 14442 |
|
| 14443 |
elsif Is_Formal_Subprogram (Subp_Id) then |
| 14444 |
return True; |
| 14445 |
|
| 14446 |
-- An imported subprogram may have a body, however it is not known at |
| 14447 |
-- compile or bind time where the body resides and whether it will be |
| 14448 |
-- elaborated on time. |
| 14449 |
|
| 14450 |
elsif Is_Imported (Subp_Id) then |
| 14451 |
return True; |
| 14452 |
end if; |
| 14453 |
|
| 14454 |
return False; |
| 14455 |
end Is_Bodiless_Subprogram; |
| 14456 |
|
| 14457 |
---------------------- |
| 14458 |
-- Is_Bridge_Target -- |
| 14459 |
---------------------- |
| 14460 |
|
| 14461 |
function Is_Bridge_Target (Id : Entity_Id) return Boolean is |
| 14462 |
begin |
| 14463 |
return |
| 14464 |
Is_Accept_Alternative_Proc (Id) |
| 14465 |
or else Is_Finalizer (Id) |
| 14466 |
or else Is_Partial_Invariant_Proc (Id) |
| 14467 |
or else Is_TSS (Id, TSS_Deep_Adjust) |
| 14468 |
or else Is_TSS (Id, TSS_Deep_Finalize) |
| 14469 |
or else Is_TSS (Id, TSS_Deep_Initialize); |
| 14470 |
end Is_Bridge_Target; |
| 14471 |
|
| 14472 |
--------------------------------------- |
| 14473 |
-- Is_Default_Initial_Condition_Proc -- |
| 14474 |
--------------------------------------- |
| 14475 |
|
| 14476 |
function Is_Default_Initial_Condition_Proc |
| 14477 |
(Id : Entity_Id) return Boolean |
| 14478 |
is |
| 14479 |
begin |
| 14480 |
-- To qualify, the entity must denote a Default_Initial_Condition |
| 14481 |
-- procedure. |
| 14482 |
|
| 14483 |
return Ekind (Id) = E_Procedure and then Is_DIC_Procedure (Id); |
| 14484 |
end Is_Default_Initial_Condition_Proc; |
| 14485 |
|
| 14486 |
------------------------------- |
| 14487 |
-- Is_Initial_Condition_Proc -- |
| 14488 |
------------------------------- |
| 14489 |
|
| 14490 |
function Is_Initial_Condition_Proc (Id : Entity_Id) return Boolean is |
| 14491 |
begin |
| 14492 |
-- To qualify, the entity must denote an Initial_Condition procedure |
| 14493 |
|
| 14494 |
return |
| 14495 |
Ekind (Id) = E_Procedure |
| 14496 |
and then Is_Initial_Condition_Procedure (Id); |
| 14497 |
end Is_Initial_Condition_Proc; |
| 14498 |
|
| 14499 |
-------------------- |
| 14500 |
-- Is_Initialized -- |
| 14501 |
-------------------- |
| 14502 |
|
| 14503 |
function Is_Initialized (Obj_Decl : Node_Id) return Boolean is |
| 14504 |
begin |
| 14505 |
-- To qualify, the object declaration must have an expression |
| 14506 |
|
| 14507 |
return |
| 14508 |
Present (Expression (Obj_Decl)) |
| 14509 |
or else Has_Init_Expression (Obj_Decl); |
| 14510 |
end Is_Initialized; |
| 14511 |
|
| 14512 |
----------------------- |
| 14513 |
-- Is_Invariant_Proc -- |
| 14514 |
----------------------- |
| 14515 |
|
| 14516 |
function Is_Invariant_Proc (Id : Entity_Id) return Boolean is |
| 14517 |
begin |
| 14518 |
-- To qualify, the entity must denote the "full" invariant procedure |
| 14519 |
|
| 14520 |
return Ekind (Id) = E_Procedure and then Is_Invariant_Procedure (Id); |
| 14521 |
end Is_Invariant_Proc; |
| 14522 |
|
| 14523 |
--------------------------------------- |
| 14524 |
-- Is_Non_Library_Level_Encapsulator -- |
| 14525 |
--------------------------------------- |
| 14526 |
|
| 14527 |
function Is_Non_Library_Level_Encapsulator |
| 14528 |
(N : Node_Id) return Boolean |
| 14529 |
is |
| 14530 |
begin |
| 14531 |
case Nkind (N) is |
| 14532 |
when N_Abstract_Subprogram_Declaration |
| 14533 |
| N_Aspect_Specification |
| 14534 |
| N_Component_Declaration |
| 14535 |
| N_Entry_Body |
| 14536 |
| N_Entry_Declaration |
| 14537 |
| N_Expression_Function |
| 14538 |
| N_Formal_Abstract_Subprogram_Declaration |
| 14539 |
| N_Formal_Concrete_Subprogram_Declaration |
| 14540 |
| N_Formal_Object_Declaration |
| 14541 |
| N_Formal_Package_Declaration |
| 14542 |
| N_Formal_Type_Declaration |
| 14543 |
| N_Generic_Association |
| 14544 |
| N_Implicit_Label_Declaration |
| 14545 |
| N_Incomplete_Type_Declaration |
| 14546 |
| N_Private_Extension_Declaration |
| 14547 |
| N_Private_Type_Declaration |
| 14548 |
| N_Protected_Body |
| 14549 |
| N_Protected_Type_Declaration |
| 14550 |
| N_Single_Protected_Declaration |
| 14551 |
| N_Single_Task_Declaration |
| 14552 |
| N_Subprogram_Body |
| 14553 |
| N_Subprogram_Declaration |
| 14554 |
| N_Task_Body |
| 14555 |
| N_Task_Type_Declaration |
| 14556 |
=> |
| 14557 |
return True; |
| 14558 |
|
| 14559 |
when others => |
| 14560 |
return Is_Generic_Declaration_Or_Body (N); |
| 14561 |
end case; |
| 14562 |
end Is_Non_Library_Level_Encapsulator; |
| 14563 |
|
| 14564 |
------------------------------- |
| 14565 |
-- Is_Partial_Invariant_Proc -- |
| 14566 |
------------------------------- |
| 14567 |
|
| 14568 |
function Is_Partial_Invariant_Proc (Id : Entity_Id) return Boolean is |
| 14569 |
begin |
| 14570 |
-- To qualify, the entity must denote the "partial" invariant |
| 14571 |
-- procedure. |
| 14572 |
|
| 14573 |
return |
| 14574 |
Ekind (Id) = E_Procedure |
| 14575 |
and then Is_Partial_Invariant_Procedure (Id); |
| 14576 |
end Is_Partial_Invariant_Proc; |
| 14577 |
|
| 14578 |
--------------------------- |
| 14579 |
-- Is_Preelaborated_Unit -- |
| 14580 |
--------------------------- |
| 14581 |
|
| 14582 |
function Is_Preelaborated_Unit (Id : Entity_Id) return Boolean is |
| 14583 |
begin |
| 14584 |
return |
| 14585 |
Is_Preelaborated (Id) |
| 14586 |
or else Is_Pure (Id) |
| 14587 |
or else Is_Remote_Call_Interface (Id) |
| 14588 |
or else Is_Remote_Types (Id) |
| 14589 |
or else Is_Shared_Passive (Id); |
| 14590 |
end Is_Preelaborated_Unit; |
| 14591 |
|
| 14592 |
------------------------ |
| 14593 |
-- Is_Protected_Entry -- |
| 14594 |
------------------------ |
| 14595 |
|
| 14596 |
function Is_Protected_Entry (Id : Entity_Id) return Boolean is |
| 14597 |
begin |
| 14598 |
-- To qualify, the entity must denote an entry defined in a protected |
| 14599 |
-- type. |
| 14600 |
|
| 14601 |
return |
| 14602 |
Is_Entry (Id) |
| 14603 |
and then Is_Protected_Type (Non_Private_View (Scope (Id))); |
| 14604 |
end Is_Protected_Entry; |
| 14605 |
|
| 14606 |
----------------------- |
| 14607 |
-- Is_Protected_Subp -- |
| 14608 |
----------------------- |
| 14609 |
|
| 14610 |
function Is_Protected_Subp (Id : Entity_Id) return Boolean is |
| 14611 |
begin |
| 14612 |
-- To qualify, the entity must denote a subprogram defined within a |
| 14613 |
-- protected type. |
| 14614 |
|
| 14615 |
return |
| 14616 |
Ekind (Id) in E_Function | E_Procedure |
| 14617 |
and then Is_Protected_Type (Non_Private_View (Scope (Id))); |
| 14618 |
end Is_Protected_Subp; |
| 14619 |
|
| 14620 |
---------------------------- |
| 14621 |
-- Is_Protected_Body_Subp -- |
| 14622 |
---------------------------- |
| 14623 |
|
| 14624 |
function Is_Protected_Body_Subp (Id : Entity_Id) return Boolean is |
| 14625 |
begin |
| 14626 |
-- To qualify, the entity must denote a subprogram with attribute |
| 14627 |
-- Protected_Subprogram set. |
| 14628 |
|
| 14629 |
return |
| 14630 |
Ekind (Id) in E_Function | E_Procedure |
| 14631 |
and then Present (Protected_Subprogram (Id)); |
| 14632 |
end Is_Protected_Body_Subp; |
| 14633 |
|
| 14634 |
----------------- |
| 14635 |
-- Is_Scenario -- |
| 14636 |
----------------- |
| 14637 |
|
| 14638 |
function Is_Scenario (N : Node_Id) return Boolean is |
| 14639 |
begin |
| 14640 |
case Nkind (N) is |
| 14641 |
when N_Assignment_Statement |
| 14642 |
| N_Attribute_Reference |
| 14643 |
| N_Call_Marker |
| 14644 |
| N_Entry_Call_Statement |
| 14645 |
| N_Expanded_Name |
| 14646 |
| N_Function_Call |
| 14647 |
| N_Function_Instantiation |
| 14648 |
| N_Identifier |
| 14649 |
| N_Package_Instantiation |
| 14650 |
| N_Procedure_Call_Statement |
| 14651 |
| N_Procedure_Instantiation |
| 14652 |
| N_Requeue_Statement |
| 14653 |
=> |
| 14654 |
return True; |
| 14655 |
|
| 14656 |
when others => |
| 14657 |
return False; |
| 14658 |
end case; |
| 14659 |
end Is_Scenario; |
| 14660 |
|
| 14661 |
------------------------------ |
| 14662 |
-- Is_SPARK_Semantic_Target -- |
| 14663 |
------------------------------ |
| 14664 |
|
| 14665 |
function Is_SPARK_Semantic_Target (Id : Entity_Id) return Boolean is |
| 14666 |
begin |
| 14667 |
return |
| 14668 |
Is_Default_Initial_Condition_Proc (Id) |
| 14669 |
or else Is_Initial_Condition_Proc (Id); |
| 14670 |
end Is_SPARK_Semantic_Target; |
| 14671 |
|
| 14672 |
------------------------ |
| 14673 |
-- Is_Subprogram_Inst -- |
| 14674 |
------------------------ |
| 14675 |
|
| 14676 |
function Is_Subprogram_Inst (Id : Entity_Id) return Boolean is |
| 14677 |
begin |
| 14678 |
-- To qualify, the entity must denote a function or a procedure which |
| 14679 |
-- is hidden within an anonymous package, and is a generic instance. |
| 14680 |
|
| 14681 |
return |
| 14682 |
Ekind (Id) in E_Function | E_Procedure |
| 14683 |
and then Is_Hidden (Id) |
| 14684 |
and then Is_Generic_Instance (Id); |
| 14685 |
end Is_Subprogram_Inst; |
| 14686 |
|
| 14687 |
------------------------------ |
| 14688 |
-- Is_Suitable_Access_Taken -- |
| 14689 |
------------------------------ |
| 14690 |
|
| 14691 |
function Is_Suitable_Access_Taken (N : Node_Id) return Boolean is |
| 14692 |
Nam : Name_Id; |
| 14693 |
Pref : Node_Id; |
| 14694 |
Subp_Id : Entity_Id; |
| 14695 |
|
| 14696 |
begin |
| 14697 |
-- Nothing to do when switch -gnatd.U (ignore 'Access) is in effect |
| 14698 |
|
| 14699 |
if Debug_Flag_Dot_UU then |
| 14700 |
return False; |
| 14701 |
|
| 14702 |
-- Nothing to do when the scenario is not an attribute reference |
| 14703 |
|
| 14704 |
elsif Nkind (N) /= N_Attribute_Reference then |
| 14705 |
return False; |
| 14706 |
|
| 14707 |
-- Nothing to do for internally-generated attributes because they are |
| 14708 |
-- assumed to be ABE safe. |
| 14709 |
|
| 14710 |
elsif not Comes_From_Source (N) then |
| 14711 |
return False; |
| 14712 |
end if; |
| 14713 |
|
| 14714 |
Nam := Attribute_Name (N); |
| 14715 |
Pref := Prefix (N); |
| 14716 |
|
| 14717 |
-- Sanitize the prefix of the attribute |
| 14718 |
|
| 14719 |
if not Is_Entity_Name (Pref) then |
| 14720 |
return False; |
| 14721 |
|
| 14722 |
elsif No (Entity (Pref)) then |
| 14723 |
return False; |
| 14724 |
end if; |
| 14725 |
|
| 14726 |
Subp_Id := Entity (Pref); |
| 14727 |
|
| 14728 |
if not Is_Subprogram_Or_Entry (Subp_Id) then |
| 14729 |
return False; |
| 14730 |
end if; |
| 14731 |
|
| 14732 |
-- Traverse a possible chain of renamings to obtain the original |
| 14733 |
-- entry or subprogram which the prefix may rename. |
| 14734 |
|
| 14735 |
Subp_Id := Get_Renamed_Entity (Subp_Id); |
| 14736 |
|
| 14737 |
-- To qualify, the attribute must meet the following prerequisites: |
| 14738 |
|
| 14739 |
return |
| 14740 |
|
| 14741 |
-- The prefix must denote a source entry, operator, or subprogram |
| 14742 |
-- which is not imported. |
| 14743 |
|
| 14744 |
Comes_From_Source (Subp_Id) |
| 14745 |
and then Is_Subprogram_Or_Entry (Subp_Id) |
| 14746 |
and then not Is_Bodiless_Subprogram (Subp_Id) |
| 14747 |
|
| 14748 |
-- The attribute name must be one of the 'Access forms. Note that |
| 14749 |
-- 'Unchecked_Access cannot apply to a subprogram. |
| 14750 |
|
| 14751 |
and then Nam in Name_Access | Name_Unrestricted_Access; |
| 14752 |
end Is_Suitable_Access_Taken; |
| 14753 |
|
| 14754 |
---------------------- |
| 14755 |
-- Is_Suitable_Call -- |
| 14756 |
---------------------- |
| 14757 |
|
| 14758 |
function Is_Suitable_Call (N : Node_Id) return Boolean is |
| 14759 |
begin |
| 14760 |
-- Entry and subprogram calls are intentionally ignored because they |
| 14761 |
-- may undergo expansion depending on the compilation mode, previous |
| 14762 |
-- errors, generic context, etc. Call markers play the role of calls |
| 14763 |
-- and provide a uniform foundation for ABE processing. |
| 14764 |
|
| 14765 |
return Nkind (N) = N_Call_Marker; |
| 14766 |
end Is_Suitable_Call; |
| 14767 |
|
| 14768 |
------------------------------- |
| 14769 |
-- Is_Suitable_Instantiation -- |
| 14770 |
------------------------------- |
| 14771 |
|
| 14772 |
function Is_Suitable_Instantiation (N : Node_Id) return Boolean is |
| 14773 |
Inst : constant Node_Id := Scenario (N); |
| 14774 |
|
| 14775 |
begin |
| 14776 |
-- To qualify, the instantiation must come from source |
| 14777 |
|
| 14778 |
return |
| 14779 |
Comes_From_Source (Inst) |
| 14780 |
and then Nkind (Inst) in N_Generic_Instantiation; |
| 14781 |
end Is_Suitable_Instantiation; |
| 14782 |
|
| 14783 |
------------------------------------ |
| 14784 |
-- Is_Suitable_SPARK_Derived_Type -- |
| 14785 |
------------------------------------ |
| 14786 |
|
| 14787 |
function Is_Suitable_SPARK_Derived_Type (N : Node_Id) return Boolean is |
| 14788 |
Prag : Node_Id; |
| 14789 |
Typ : Entity_Id; |
| 14790 |
|
| 14791 |
begin |
| 14792 |
-- To qualify, the type declaration must denote a derived tagged type |
| 14793 |
-- with primitive operations, subject to pragma SPARK_Mode On. |
| 14794 |
|
| 14795 |
if Nkind (N) = N_Full_Type_Declaration |
| 14796 |
and then Nkind (Type_Definition (N)) = N_Derived_Type_Definition |
| 14797 |
then |
| 14798 |
Typ := Defining_Entity (N); |
| 14799 |
Prag := SPARK_Pragma (Typ); |
| 14800 |
|
| 14801 |
return |
| 14802 |
Is_Tagged_Type (Typ) |
| 14803 |
and then Has_Primitive_Operations (Typ) |
| 14804 |
and then Present (Prag) |
| 14805 |
and then Get_SPARK_Mode_From_Annotation (Prag) = On; |
| 14806 |
end if; |
| 14807 |
|
| 14808 |
return False; |
| 14809 |
end Is_Suitable_SPARK_Derived_Type; |
| 14810 |
|
| 14811 |
------------------------------------- |
| 14812 |
-- Is_Suitable_SPARK_Instantiation -- |
| 14813 |
------------------------------------- |
| 14814 |
|
| 14815 |
function Is_Suitable_SPARK_Instantiation (N : Node_Id) return Boolean is |
| 14816 |
Inst : constant Node_Id := Scenario (N); |
| 14817 |
|
| 14818 |
Gen_Id : Entity_Id; |
| 14819 |
Prag : Node_Id; |
| 14820 |
|
| 14821 |
begin |
| 14822 |
-- To qualify, both the instantiation and the generic must be subject |
| 14823 |
-- to SPARK_Mode On. |
| 14824 |
|
| 14825 |
if Is_Suitable_Instantiation (N) then |
| 14826 |
Gen_Id := Instantiated_Generic (Inst); |
| 14827 |
Prag := SPARK_Pragma (Gen_Id); |
| 14828 |
|
| 14829 |
return |
| 14830 |
Is_SPARK_Mode_On_Node (Inst) |
| 14831 |
and then Present (Prag) |
| 14832 |
and then Get_SPARK_Mode_From_Annotation (Prag) = On; |
| 14833 |
end if; |
| 14834 |
|
| 14835 |
return False; |
| 14836 |
end Is_Suitable_SPARK_Instantiation; |
| 14837 |
|
| 14838 |
-------------------------------------------- |
| 14839 |
-- Is_Suitable_SPARK_Refined_State_Pragma -- |
| 14840 |
-------------------------------------------- |
| 14841 |
|
| 14842 |
function Is_Suitable_SPARK_Refined_State_Pragma |
| 14843 |
(N : Node_Id) return Boolean |
| 14844 |
is |
| 14845 |
begin |
| 14846 |
-- To qualfy, the pragma must denote Refined_State |
| 14847 |
|
| 14848 |
return |
| 14849 |
Nkind (N) = N_Pragma |
| 14850 |
and then Pragma_Name (N) = Name_Refined_State; |
| 14851 |
end Is_Suitable_SPARK_Refined_State_Pragma; |
| 14852 |
|
| 14853 |
------------------------------------- |
| 14854 |
-- Is_Suitable_Variable_Assignment -- |
| 14855 |
------------------------------------- |
| 14856 |
|
| 14857 |
function Is_Suitable_Variable_Assignment (N : Node_Id) return Boolean is |
| 14858 |
N_Unit : Node_Id; |
| 14859 |
N_Unit_Id : Entity_Id; |
| 14860 |
Nam : Node_Id; |
| 14861 |
Var_Decl : Node_Id; |
| 14862 |
Var_Id : Entity_Id; |
| 14863 |
Var_Unit : Node_Id; |
| 14864 |
Var_Unit_Id : Entity_Id; |
| 14865 |
|
| 14866 |
begin |
| 14867 |
-- Nothing to do when the scenario is not an assignment |
| 14868 |
|
| 14869 |
if Nkind (N) /= N_Assignment_Statement then |
| 14870 |
return False; |
| 14871 |
|
| 14872 |
-- Nothing to do for internally-generated assignments because they |
| 14873 |
-- are assumed to be ABE safe. |
| 14874 |
|
| 14875 |
elsif not Comes_From_Source (N) then |
| 14876 |
return False; |
| 14877 |
|
| 14878 |
-- Assignments are ignored in GNAT mode on the assumption that |
| 14879 |
-- they are ABE-safe. This behavior parallels that of the old |
| 14880 |
-- ABE mechanism. |
| 14881 |
|
| 14882 |
elsif GNAT_Mode then |
| 14883 |
return False; |
| 14884 |
end if; |
| 14885 |
|
| 14886 |
Nam := Assignment_Target (N); |
| 14887 |
|
| 14888 |
-- Sanitize the left hand side of the assignment |
| 14889 |
|
| 14890 |
if not Is_Entity_Name (Nam) then |
| 14891 |
return False; |
| 14892 |
|
| 14893 |
elsif No (Entity (Nam)) then |
| 14894 |
return False; |
| 14895 |
end if; |
| 14896 |
|
| 14897 |
Var_Id := Entity (Nam); |
| 14898 |
|
| 14899 |
-- Sanitize the variable |
| 14900 |
|
| 14901 |
if Var_Id = Any_Id then |
| 14902 |
return False; |
| 14903 |
|
| 14904 |
elsif Ekind (Var_Id) /= E_Variable then |
| 14905 |
return False; |
| 14906 |
end if; |
| 14907 |
|
| 14908 |
Var_Decl := Declaration_Node (Var_Id); |
| 14909 |
|
| 14910 |
if Nkind (Var_Decl) /= N_Object_Declaration then |
| 14911 |
return False; |
| 14912 |
end if; |
| 14913 |
|
| 14914 |
N_Unit_Id := Find_Top_Unit (N); |
| 14915 |
N_Unit := Unit_Declaration_Node (N_Unit_Id); |
| 14916 |
|
| 14917 |
Var_Unit_Id := Find_Top_Unit (Var_Decl); |
| 14918 |
Var_Unit := Unit_Declaration_Node (Var_Unit_Id); |
| 14919 |
|
| 14920 |
-- To qualify, the assignment must meet the following prerequisites: |
| 14921 |
|
| 14922 |
return |
| 14923 |
Comes_From_Source (Var_Id) |
| 14924 |
|
| 14925 |
-- The variable must be declared in the spec of compilation unit |
| 14926 |
-- U. |
| 14927 |
|
| 14928 |
and then Nkind (Var_Unit) = N_Package_Declaration |
| 14929 |
and then Find_Enclosing_Level (Var_Decl) = Library_Spec_Level |
| 14930 |
|
| 14931 |
-- The assignment must occur in the body of compilation unit U |
| 14932 |
|
| 14933 |
and then Nkind (N_Unit) = N_Package_Body |
| 14934 |
and then Present (Corresponding_Body (Var_Unit)) |
| 14935 |
and then Corresponding_Body (Var_Unit) = N_Unit_Id; |
| 14936 |
end Is_Suitable_Variable_Assignment; |
| 14937 |
|
| 14938 |
------------------------------------ |
| 14939 |
-- Is_Suitable_Variable_Reference -- |
| 14940 |
------------------------------------ |
| 14941 |
|
| 14942 |
function Is_Suitable_Variable_Reference (N : Node_Id) return Boolean is |
| 14943 |
begin |
| 14944 |
-- Expanded names and identifiers are intentionally ignored because |
| 14945 |
-- they be folded, optimized away, etc. Variable references markers |
| 14946 |
-- play the role of variable references and provide a uniform |
| 14947 |
-- foundation for ABE processing. |
| 14948 |
|
| 14949 |
return Nkind (N) = N_Variable_Reference_Marker; |
| 14950 |
end Is_Suitable_Variable_Reference; |
| 14951 |
|
| 14952 |
------------------- |
| 14953 |
-- Is_Task_Entry -- |
| 14954 |
------------------- |
| 14955 |
|
| 14956 |
function Is_Task_Entry (Id : Entity_Id) return Boolean is |
| 14957 |
begin |
| 14958 |
-- To qualify, the entity must denote an entry defined in a task type |
| 14959 |
|
| 14960 |
return |
| 14961 |
Is_Entry (Id) and then Is_Task_Type (Non_Private_View (Scope (Id))); |
| 14962 |
end Is_Task_Entry; |
| 14963 |
|
| 14964 |
------------------------ |
| 14965 |
-- Is_Up_Level_Target -- |
| 14966 |
------------------------ |
| 14967 |
|
| 14968 |
function Is_Up_Level_Target |
| 14969 |
(Targ_Decl : Node_Id; |
| 14970 |
In_State : Processing_In_State) return Boolean |
| 14971 |
is |
| 14972 |
Root : constant Node_Id := Root_Scenario; |
| 14973 |
Root_Rep : constant Scenario_Rep_Id := |
| 14974 |
Scenario_Representation_Of (Root, In_State); |
| 14975 |
|
| 14976 |
begin |
| 14977 |
-- The root appears within the declaratons of a block statement, |
| 14978 |
-- entry body, subprogram body, or task body ignoring enclosing |
| 14979 |
-- packages. The root is always within the main unit. |
| 14980 |
|
| 14981 |
if not In_State.Suppress_Up_Level_Targets |
| 14982 |
and then Level (Root_Rep) = Declaration_Level |
| 14983 |
then |
| 14984 |
-- The target is within the main unit. It acts as an up-level |
| 14985 |
-- target when it appears within a context which encloses the |
| 14986 |
-- root. |
| 14987 |
-- |
| 14988 |
-- package body Main_Unit is |
| 14989 |
-- function Func ...; -- target |
| 14990 |
-- |
| 14991 |
-- procedure Proc is |
| 14992 |
-- X : ... := Func; -- root scenario |
| 14993 |
|
| 14994 |
if In_Extended_Main_Code_Unit (Targ_Decl) then |
| 14995 |
return not In_Same_Context (Root, Targ_Decl, Nested_OK => True); |
| 14996 |
|
| 14997 |
-- Otherwise the target is external to the main unit which makes |
| 14998 |
-- it an up-level target. |
| 14999 |
|
| 15000 |
else |
| 15001 |
return True; |
| 15002 |
end if; |
| 15003 |
end if; |
| 15004 |
|
| 15005 |
return False; |
| 15006 |
end Is_Up_Level_Target; |
| 15007 |
end Semantics; |
| 15008 |
|
| 15009 |
--------------------------- |
| 15010 |
-- Set_Elaboration_Phase -- |
| 15011 |
--------------------------- |
| 15012 |
|
| 15013 |
procedure Set_Elaboration_Phase (Status : Elaboration_Phase_Status) is |
| 15014 |
begin |
| 15015 |
Elaboration_Phase := Status; |
| 15016 |
end Set_Elaboration_Phase; |
| 15017 |
|
| 15018 |
--------------------- |
| 15019 |
-- SPARK_Processor -- |
| 15020 |
--------------------- |
| 15021 |
|
| 15022 |
package body SPARK_Processor is |
| 15023 |
|
| 15024 |
----------------------- |
| 15025 |
-- Local subprograms -- |
| 15026 |
----------------------- |
| 15027 |
|
| 15028 |
procedure Process_SPARK_Derived_Type |
| 15029 |
(Typ_Decl : Node_Id; |
| 15030 |
Typ_Rep : Scenario_Rep_Id; |
| 15031 |
In_State : Processing_In_State); |
| 15032 |
pragma Inline (Process_SPARK_Derived_Type); |
| 15033 |
-- Verify that the freeze node of a derived type denoted by declaration |
| 15034 |
-- Typ_Decl is within the early call region of each overriding primitive |
| 15035 |
-- body that belongs to the derived type (SPARK RM 7.7(8)). Typ_Rep is |
| 15036 |
-- the representation of the type. In_State denotes the current state of |
| 15037 |
-- the Processing phase. |
| 15038 |
|
| 15039 |
procedure Process_SPARK_Instantiation |
| 15040 |
(Inst : Node_Id; |
| 15041 |
Inst_Rep : Scenario_Rep_Id; |
| 15042 |
In_State : Processing_In_State); |
| 15043 |
pragma Inline (Process_SPARK_Instantiation); |
| 15044 |
-- Verify that instantiation Inst does not precede the generic body it |
| 15045 |
-- instantiates (SPARK RM 7.7(6)). Inst_Rep is the representation of the |
| 15046 |
-- instantiation. In_State is the current state of the Processing phase. |
| 15047 |
|
| 15048 |
procedure Process_SPARK_Refined_State_Pragma |
| 15049 |
(Prag : Node_Id; |
| 15050 |
Prag_Rep : Scenario_Rep_Id; |
| 15051 |
In_State : Processing_In_State); |
| 15052 |
pragma Inline (Process_SPARK_Refined_State_Pragma); |
| 15053 |
-- Verify that each constituent of Refined_State pragma Prag which |
| 15054 |
-- belongs to abstract state mentioned in pragma Initializes has prior |
| 15055 |
-- elaboration with respect to the main unit (SPARK RM 7.7.1(7)). |
| 15056 |
-- Prag_Rep is the representation of the pragma. In_State denotes the |
| 15057 |
-- current state of the Processing phase. |
| 15058 |
|
| 15059 |
procedure Process_SPARK_Scenario |
| 15060 |
(N : Node_Id; |
| 15061 |
In_State : Processing_In_State); |
| 15062 |
pragma Inline (Process_SPARK_Scenario); |
| 15063 |
-- Top-level dispatcher for verifying SPARK scenarios which are not |
| 15064 |
-- always executable during elaboration but still need elaboration- |
| 15065 |
-- related checks. In_State is the current state of the Processing |
| 15066 |
-- phase. |
| 15067 |
|
| 15068 |
--------------------------------- |
| 15069 |
-- Check_SPARK_Model_In_Effect -- |
| 15070 |
--------------------------------- |
| 15071 |
|
| 15072 |
SPARK_Model_Warning_Posted : Boolean := False; |
| 15073 |
-- This flag prevents the same SPARK model-related warning from being |
| 15074 |
-- emitted multiple times. |
| 15075 |
|
| 15076 |
procedure Check_SPARK_Model_In_Effect is |
| 15077 |
Spec_Id : constant Entity_Id := Unique_Entity (Main_Unit_Entity); |
| 15078 |
|
| 15079 |
begin |
| 15080 |
-- Do not emit the warning multiple times as this creates useless |
| 15081 |
-- noise. |
| 15082 |
|
| 15083 |
if SPARK_Model_Warning_Posted then |
| 15084 |
null; |
| 15085 |
|
| 15086 |
-- SPARK rule verification requires the "strict" static model |
| 15087 |
|
| 15088 |
elsif Static_Elaboration_Checks |
| 15089 |
and not Relaxed_Elaboration_Checks |
| 15090 |
then |
| 15091 |
null; |
| 15092 |
|
| 15093 |
-- Any other combination of models does not guarantee the absence of |
| 15094 |
-- ABE problems for SPARK rule verification purposes. Note that there |
| 15095 |
-- is no need to check for the presence of the legacy ABE mechanism |
| 15096 |
-- because the legacy code has its own dedicated processing for SPARK |
| 15097 |
-- rules. |
| 15098 |
|
| 15099 |
else |
| 15100 |
SPARK_Model_Warning_Posted := True; |
| 15101 |
|
| 15102 |
Error_Msg_N |
| 15103 |
("??SPARK elaboration checks require static elaboration model", |
| 15104 |
Spec_Id); |
| 15105 |
|
| 15106 |
if Dynamic_Elaboration_Checks then |
| 15107 |
Error_Msg_N |
| 15108 |
("\dynamic elaboration model is in effect", Spec_Id); |
| 15109 |
|
| 15110 |
else |
| 15111 |
pragma Assert (Relaxed_Elaboration_Checks); |
| 15112 |
Error_Msg_N |
| 15113 |
("\relaxed elaboration model is in effect", Spec_Id); |
| 15114 |
end if; |
| 15115 |
end if; |
| 15116 |
end Check_SPARK_Model_In_Effect; |
| 15117 |
|
| 15118 |
--------------------------- |
| 15119 |
-- Check_SPARK_Scenarios -- |
| 15120 |
--------------------------- |
| 15121 |
|
| 15122 |
procedure Check_SPARK_Scenarios is |
| 15123 |
Iter : NE_Set.Iterator; |
| 15124 |
N : Node_Id; |
| 15125 |
|
| 15126 |
begin |
| 15127 |
Iter := Iterate_SPARK_Scenarios; |
| 15128 |
while NE_Set.Has_Next (Iter) loop |
| 15129 |
NE_Set.Next (Iter, N); |
| 15130 |
|
| 15131 |
Process_SPARK_Scenario |
| 15132 |
(N => N, |
| 15133 |
In_State => SPARK_State); |
| 15134 |
end loop; |
| 15135 |
end Check_SPARK_Scenarios; |
| 15136 |
|
| 15137 |
-------------------------------- |
| 15138 |
-- Process_SPARK_Derived_Type -- |
| 15139 |
-------------------------------- |
| 15140 |
|
| 15141 |
procedure Process_SPARK_Derived_Type |
| 15142 |
(Typ_Decl : Node_Id; |
| 15143 |
Typ_Rep : Scenario_Rep_Id; |
| 15144 |
In_State : Processing_In_State) |
| 15145 |
is |
| 15146 |
pragma Unreferenced (In_State); |
| 15147 |
|
| 15148 |
Typ : constant Entity_Id := Target (Typ_Rep); |
| 15149 |
|
| 15150 |
Stop_Check : exception; |
| 15151 |
-- This exception is raised when the freeze node violates the |
| 15152 |
-- placement rules. |
| 15153 |
|
| 15154 |
procedure Check_Overriding_Primitive |
| 15155 |
(Prim : Entity_Id; |
| 15156 |
FNode : Node_Id); |
| 15157 |
pragma Inline (Check_Overriding_Primitive); |
| 15158 |
-- Verify that freeze node FNode is within the early call region of |
| 15159 |
-- overriding primitive Prim's body. |
| 15160 |
|
| 15161 |
function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr; |
| 15162 |
pragma Inline (Freeze_Node_Location); |
| 15163 |
-- Return a more accurate source location associated with freeze node |
| 15164 |
-- FNode. |
| 15165 |
|
| 15166 |
function Precedes_Source_Construct (N : Node_Id) return Boolean; |
| 15167 |
pragma Inline (Precedes_Source_Construct); |
| 15168 |
-- Determine whether arbitrary node N appears prior to some source |
| 15169 |
-- construct. |
| 15170 |
|
| 15171 |
procedure Suggest_Elaborate_Body |
| 15172 |
(N : Node_Id; |
| 15173 |
Body_Decl : Node_Id; |
| 15174 |
Error_Nod : Node_Id); |
| 15175 |
pragma Inline (Suggest_Elaborate_Body); |
| 15176 |
-- Suggest the use of pragma Elaborate_Body when the pragma will |
| 15177 |
-- allow for node N to appear within the early call region of |
| 15178 |
-- subprogram body Body_Decl. The suggestion is attached to |
| 15179 |
-- Error_Nod as a continuation error. |
| 15180 |
|
| 15181 |
-------------------------------- |
| 15182 |
-- Check_Overriding_Primitive -- |
| 15183 |
-------------------------------- |
| 15184 |
|
| 15185 |
procedure Check_Overriding_Primitive |
| 15186 |
(Prim : Entity_Id; |
| 15187 |
FNode : Node_Id) |
| 15188 |
is |
| 15189 |
Prim_Decl : constant Node_Id := Unit_Declaration_Node (Prim); |
| 15190 |
Body_Decl : Node_Id; |
| 15191 |
Body_Id : Entity_Id; |
| 15192 |
Region : Node_Id; |
| 15193 |
|
| 15194 |
begin |
| 15195 |
-- Nothing to do for predefined primitives because they are |
| 15196 |
-- artifacts of tagged type expansion and cannot override source |
| 15197 |
-- primitives. Nothing to do as well for inherited primitives, as |
| 15198 |
-- the check concerns overriding ones. Finally, nothing to do for |
| 15199 |
-- abstract subprograms, because they have no body that could be |
| 15200 |
-- examined. |
| 15201 |
|
| 15202 |
if Is_Predefined_Dispatching_Operation (Prim) |
| 15203 |
or else not Is_Overriding_Subprogram (Prim) |
| 15204 |
or else Is_Abstract_Subprogram (Prim) |
| 15205 |
then |
| 15206 |
return; |
| 15207 |
end if; |
| 15208 |
|
| 15209 |
Body_Id := Corresponding_Body (Prim_Decl); |
| 15210 |
|
| 15211 |
-- Nothing to do when the primitive does not have a corresponding |
| 15212 |
-- body. This can happen when the unit with the bodies is not the |
| 15213 |
-- main unit subjected to ABE checks. |
| 15214 |
|
| 15215 |
if No (Body_Id) then |
| 15216 |
return; |
| 15217 |
|
| 15218 |
-- The primitive overrides a parent or progenitor primitive |
| 15219 |
|
| 15220 |
elsif Present (Overridden_Operation (Prim)) then |
| 15221 |
|
| 15222 |
-- Nothing to do when overriding an interface primitive happens |
| 15223 |
-- by inheriting a non-interface primitive as the check would |
| 15224 |
-- be done on the parent primitive. |
| 15225 |
|
| 15226 |
if Present (Alias (Prim)) then |
| 15227 |
return; |
| 15228 |
end if; |
| 15229 |
|
| 15230 |
-- Nothing to do when the primitive is not overriding. The body of |
| 15231 |
-- such a primitive cannot be targeted by a dispatching call which |
| 15232 |
-- is executable during elaboration, and cannot cause an ABE. |
| 15233 |
|
| 15234 |
else |
| 15235 |
return; |
| 15236 |
end if; |
| 15237 |
|
| 15238 |
Body_Decl := Unit_Declaration_Node (Body_Id); |
| 15239 |
Region := Find_Early_Call_Region (Body_Decl); |
| 15240 |
|
| 15241 |
-- The freeze node appears prior to the early call region of the |
| 15242 |
-- primitive body. |
| 15243 |
|
| 15244 |
-- IMPORTANT: This check must always be performed even when |
| 15245 |
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not |
| 15246 |
-- specified because the static model cannot guarantee the absence |
| 15247 |
-- of ABEs in the presence of dispatching calls. |
| 15248 |
|
| 15249 |
if Earlier_In_Extended_Unit (FNode, Region) then |
| 15250 |
Error_Msg_Node_2 := Prim; |
| 15251 |
Error_Msg_Code := GEC_Type_Early_Call_Region; |
| 15252 |
Error_Msg_NE |
| 15253 |
("first freezing point of type & must appear within early " |
| 15254 |
& "call region of primitive body '[[]']", |
| 15255 |
Typ_Decl, Typ); |
| 15256 |
|
| 15257 |
Error_Msg_Sloc := Sloc (Region); |
| 15258 |
Error_Msg_N ("\region starts #", Typ_Decl); |
| 15259 |
|
| 15260 |
Error_Msg_Sloc := Sloc (Body_Decl); |
| 15261 |
Error_Msg_N ("\region ends #", Typ_Decl); |
| 15262 |
|
| 15263 |
Error_Msg_Sloc := Freeze_Node_Location (FNode); |
| 15264 |
Error_Msg_N ("\first freezing point #", Typ_Decl); |
| 15265 |
|
| 15266 |
-- If applicable, suggest the use of pragma Elaborate_Body in |
| 15267 |
-- the associated package spec. |
| 15268 |
|
| 15269 |
Suggest_Elaborate_Body |
| 15270 |
(N => FNode, |
| 15271 |
Body_Decl => Body_Decl, |
| 15272 |
Error_Nod => Typ_Decl); |
| 15273 |
|
| 15274 |
raise Stop_Check; |
| 15275 |
end if; |
| 15276 |
end Check_Overriding_Primitive; |
| 15277 |
|
| 15278 |
-------------------------- |
| 15279 |
-- Freeze_Node_Location -- |
| 15280 |
-------------------------- |
| 15281 |
|
| 15282 |
function Freeze_Node_Location (FNode : Node_Id) return Source_Ptr is |
| 15283 |
Context : constant Node_Id := Parent (FNode); |
| 15284 |
Loc : constant Source_Ptr := Sloc (FNode); |
| 15285 |
|
| 15286 |
Prv_Decls : List_Id; |
| 15287 |
Vis_Decls : List_Id; |
| 15288 |
|
| 15289 |
begin |
| 15290 |
-- In general, the source location of the freeze node is as close |
| 15291 |
-- as possible to the real freeze point, except when the freeze |
| 15292 |
-- node is at the "bottom" of a package spec. |
| 15293 |
|
| 15294 |
if Nkind (Context) = N_Package_Specification then |
| 15295 |
Prv_Decls := Private_Declarations (Context); |
| 15296 |
Vis_Decls := Visible_Declarations (Context); |
| 15297 |
|
| 15298 |
-- The freeze node appears in the private declarations of the |
| 15299 |
-- package. |
| 15300 |
|
| 15301 |
if Present (Prv_Decls) |
| 15302 |
and then List_Containing (FNode) = Prv_Decls |
| 15303 |
then |
| 15304 |
null; |
| 15305 |
|
| 15306 |
-- The freeze node appears in the visible declarations of the |
| 15307 |
-- package and there are no private declarations. |
| 15308 |
|
| 15309 |
elsif Present (Vis_Decls) |
| 15310 |
and then List_Containing (FNode) = Vis_Decls |
| 15311 |
and then Is_Empty_List (Prv_Decls) |
| 15312 |
then |
| 15313 |
null; |
| 15314 |
|
| 15315 |
-- Otherwise the freeze node is not in the "last" declarative |
| 15316 |
-- list of the package. Use the existing source location of the |
| 15317 |
-- freeze node. |
| 15318 |
|
| 15319 |
else |
| 15320 |
return Loc; |
| 15321 |
end if; |
| 15322 |
|
| 15323 |
-- The freeze node appears at the "bottom" of the package when |
| 15324 |
-- it is in the "last" declarative list and is either the last |
| 15325 |
-- in the list or is followed by internal constructs only. In |
| 15326 |
-- that case the more appropriate source location is that of |
| 15327 |
-- the package end label. |
| 15328 |
|
| 15329 |
if not Precedes_Source_Construct (FNode) then |
| 15330 |
return Sloc (End_Label (Context)); |
| 15331 |
end if; |
| 15332 |
end if; |
| 15333 |
|
| 15334 |
return Loc; |
| 15335 |
end Freeze_Node_Location; |
| 15336 |
|
| 15337 |
------------------------------- |
| 15338 |
-- Precedes_Source_Construct -- |
| 15339 |
------------------------------- |
| 15340 |
|
| 15341 |
function Precedes_Source_Construct (N : Node_Id) return Boolean is |
| 15342 |
Decl : Node_Id; |
| 15343 |
|
| 15344 |
begin |
| 15345 |
Decl := Next (N); |
| 15346 |
while Present (Decl) loop |
| 15347 |
if Comes_From_Source (Decl) then |
| 15348 |
return True; |
| 15349 |
|
| 15350 |
-- A generated body for a source expression function is treated |
| 15351 |
-- as a source construct. |
| 15352 |
|
| 15353 |
elsif Nkind (Decl) = N_Subprogram_Body |
| 15354 |
and then Was_Expression_Function (Decl) |
| 15355 |
and then Comes_From_Source (Original_Node (Decl)) |
| 15356 |
then |
| 15357 |
return True; |
| 15358 |
end if; |
| 15359 |
|
| 15360 |
Next (Decl); |
| 15361 |
end loop; |
| 15362 |
|
| 15363 |
return False; |
| 15364 |
end Precedes_Source_Construct; |
| 15365 |
|
| 15366 |
---------------------------- |
| 15367 |
-- Suggest_Elaborate_Body -- |
| 15368 |
---------------------------- |
| 15369 |
|
| 15370 |
procedure Suggest_Elaborate_Body |
| 15371 |
(N : Node_Id; |
| 15372 |
Body_Decl : Node_Id; |
| 15373 |
Error_Nod : Node_Id) |
| 15374 |
is |
| 15375 |
Unit_Id : constant Node_Id := Unit (Cunit (Main_Unit)); |
| 15376 |
Region : Node_Id; |
| 15377 |
|
| 15378 |
begin |
| 15379 |
-- The suggestion applies only when the subprogram body resides in |
| 15380 |
-- a compilation package body, and a pragma Elaborate_Body would |
| 15381 |
-- allow for the node to appear in the early call region of the |
| 15382 |
-- subprogram body. This implies that all code from the subprogram |
| 15383 |
-- body up to the node is preelaborable. |
| 15384 |
|
| 15385 |
if Nkind (Unit_Id) = N_Package_Body then |
| 15386 |
|
| 15387 |
-- Find the start of the early call region again assuming that |
| 15388 |
-- the package spec has pragma Elaborate_Body. Note that the |
| 15389 |
-- internal data structures are intentionally not updated |
| 15390 |
-- because this is a speculative search. |
| 15391 |
|
| 15392 |
Region := |
| 15393 |
Find_Early_Call_Region |
| 15394 |
(Body_Decl => Body_Decl, |
| 15395 |
Assume_Elab_Body => True, |
| 15396 |
Skip_Memoization => True); |
| 15397 |
|
| 15398 |
-- If the node appears within the early call region, assuming |
| 15399 |
-- that the package spec carries pragma Elaborate_Body, then it |
| 15400 |
-- is safe to suggest the pragma. |
| 15401 |
|
| 15402 |
if Earlier_In_Extended_Unit (Region, N) then |
| 15403 |
Error_Msg_Name_1 := Name_Elaborate_Body; |
| 15404 |
Error_Msg_NE |
| 15405 |
("\consider adding pragma % in spec of unit &", |
| 15406 |
Error_Nod, Defining_Entity (Unit_Id)); |
| 15407 |
end if; |
| 15408 |
end if; |
| 15409 |
end Suggest_Elaborate_Body; |
| 15410 |
|
| 15411 |
-- Local variables |
| 15412 |
|
| 15413 |
FNode : constant Node_Id := Freeze_Node (Typ); |
| 15414 |
Prims : constant Elist_Id := Direct_Primitive_Operations (Typ); |
| 15415 |
|
| 15416 |
Prim_Elmt : Elmt_Id; |
| 15417 |
|
| 15418 |
-- Start of processing for Process_SPARK_Derived_Type |
| 15419 |
|
| 15420 |
begin |
| 15421 |
-- A type should have its freeze node set by the time SPARK scenarios |
| 15422 |
-- are being verified. |
| 15423 |
|
| 15424 |
pragma Assert (Present (FNode)); |
| 15425 |
|
| 15426 |
-- Verify that the freeze node of the derived type is within the |
| 15427 |
-- early call region of each overriding primitive body |
| 15428 |
-- (SPARK RM 7.7(8)). |
| 15429 |
|
| 15430 |
if Present (Prims) then |
| 15431 |
Prim_Elmt := First_Elmt (Prims); |
| 15432 |
while Present (Prim_Elmt) loop |
| 15433 |
Check_Overriding_Primitive |
| 15434 |
(Prim => Node (Prim_Elmt), |
| 15435 |
FNode => FNode); |
| 15436 |
|
| 15437 |
Next_Elmt (Prim_Elmt); |
| 15438 |
end loop; |
| 15439 |
end if; |
| 15440 |
|
| 15441 |
exception |
| 15442 |
when Stop_Check => |
| 15443 |
null; |
| 15444 |
end Process_SPARK_Derived_Type; |
| 15445 |
|
| 15446 |
--------------------------------- |
| 15447 |
-- Process_SPARK_Instantiation -- |
| 15448 |
--------------------------------- |
| 15449 |
|
| 15450 |
procedure Process_SPARK_Instantiation |
| 15451 |
(Inst : Node_Id; |
| 15452 |
Inst_Rep : Scenario_Rep_Id; |
| 15453 |
In_State : Processing_In_State) |
| 15454 |
is |
| 15455 |
Gen_Id : constant Entity_Id := Target (Inst_Rep); |
| 15456 |
Gen_Rep : constant Target_Rep_Id := |
| 15457 |
Target_Representation_Of (Gen_Id, In_State); |
| 15458 |
Body_Decl : constant Node_Id := Body_Declaration (Gen_Rep); |
| 15459 |
|
| 15460 |
begin |
| 15461 |
-- The instantiation and the generic body are both in the main unit |
| 15462 |
|
| 15463 |
if Present (Body_Decl) |
| 15464 |
and then In_Extended_Main_Code_Unit (Body_Decl) |
| 15465 |
|
| 15466 |
-- If the instantiation appears prior to the generic body, then the |
| 15467 |
-- instantiation is illegal (SPARK RM 7.7(6)). |
| 15468 |
|
| 15469 |
-- IMPORTANT: This check must always be performed even when |
| 15470 |
-- -gnatd.v (enforce SPARK elaboration rules in SPARK code) is not |
| 15471 |
-- specified because the rule prevents use-before-declaration of |
| 15472 |
-- objects that may precede the generic body. |
| 15473 |
|
| 15474 |
and then Earlier_In_Extended_Unit (Inst, Body_Decl) |
| 15475 |
then |
| 15476 |
Error_Msg_NE |
| 15477 |
("cannot instantiate & before body seen", Inst, Gen_Id); |
| 15478 |
end if; |
| 15479 |
end Process_SPARK_Instantiation; |
| 15480 |
|
| 15481 |
---------------------------- |
| 15482 |
-- Process_SPARK_Scenario -- |
| 15483 |
---------------------------- |
| 15484 |
|
| 15485 |
procedure Process_SPARK_Scenario |
| 15486 |
(N : Node_Id; |
| 15487 |
In_State : Processing_In_State) |
| 15488 |
is |
| 15489 |
Scen : constant Node_Id := Scenario (N); |
| 15490 |
|
| 15491 |
begin |
| 15492 |
-- Ensure that a suitable elaboration model is in effect for SPARK |
| 15493 |
-- rule verification. |
| 15494 |
|
| 15495 |
Check_SPARK_Model_In_Effect; |
| 15496 |
|
| 15497 |
-- Add the current scenario to the stack of active scenarios |
| 15498 |
|
| 15499 |
Push_Active_Scenario (Scen); |
| 15500 |
|
| 15501 |
-- Derived type |
| 15502 |
|
| 15503 |
if Is_Suitable_SPARK_Derived_Type (Scen) then |
| 15504 |
Process_SPARK_Derived_Type |
| 15505 |
(Typ_Decl => Scen, |
| 15506 |
Typ_Rep => Scenario_Representation_Of (Scen, In_State), |
| 15507 |
In_State => In_State); |
| 15508 |
|
| 15509 |
-- Instantiation |
| 15510 |
|
| 15511 |
elsif Is_Suitable_SPARK_Instantiation (Scen) then |
| 15512 |
Process_SPARK_Instantiation |
| 15513 |
(Inst => Scen, |
| 15514 |
Inst_Rep => Scenario_Representation_Of (Scen, In_State), |
| 15515 |
In_State => In_State); |
| 15516 |
|
| 15517 |
-- Refined_State pragma |
| 15518 |
|
| 15519 |
elsif Is_Suitable_SPARK_Refined_State_Pragma (Scen) then |
| 15520 |
Process_SPARK_Refined_State_Pragma |
| 15521 |
(Prag => Scen, |
| 15522 |
Prag_Rep => Scenario_Representation_Of (Scen, In_State), |
| 15523 |
In_State => In_State); |
| 15524 |
end if; |
| 15525 |
|
| 15526 |
-- Remove the current scenario from the stack of active scenarios |
| 15527 |
-- once all ABE diagnostics and checks have been performed. |
| 15528 |
|
| 15529 |
Pop_Active_Scenario (Scen); |
| 15530 |
end Process_SPARK_Scenario; |
| 15531 |
|
| 15532 |
---------------------------------------- |
| 15533 |
-- Process_SPARK_Refined_State_Pragma -- |
| 15534 |
---------------------------------------- |
| 15535 |
|
| 15536 |
procedure Process_SPARK_Refined_State_Pragma |
| 15537 |
(Prag : Node_Id; |
| 15538 |
Prag_Rep : Scenario_Rep_Id; |
| 15539 |
In_State : Processing_In_State) |
| 15540 |
is |
| 15541 |
pragma Unreferenced (Prag_Rep); |
| 15542 |
|
| 15543 |
procedure Check_SPARK_Constituent (Constit_Id : Entity_Id); |
| 15544 |
pragma Inline (Check_SPARK_Constituent); |
| 15545 |
-- Ensure that a single constituent Constit_Id is elaborated prior to |
| 15546 |
-- the main unit. |
| 15547 |
|
| 15548 |
procedure Check_SPARK_Constituents (Constits : Elist_Id); |
| 15549 |
pragma Inline (Check_SPARK_Constituents); |
| 15550 |
-- Ensure that all constituents found in list Constits are elaborated |
| 15551 |
-- prior to the main unit. |
| 15552 |
|
| 15553 |
procedure Check_SPARK_Initialized_State (State : Node_Id); |
| 15554 |
pragma Inline (Check_SPARK_Initialized_State); |
| 15555 |
-- Ensure that the constituents of single abstract state State are |
| 15556 |
-- elaborated prior to the main unit. |
| 15557 |
|
| 15558 |
procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id); |
| 15559 |
pragma Inline (Check_SPARK_Initialized_States); |
| 15560 |
-- Ensure that the constituents of all abstract states which appear |
| 15561 |
-- in the Initializes pragma of package Pack_Id are elaborated prior |
| 15562 |
-- to the main unit. |
| 15563 |
|
| 15564 |
----------------------------- |
| 15565 |
-- Check_SPARK_Constituent -- |
| 15566 |
----------------------------- |
| 15567 |
|
| 15568 |
procedure Check_SPARK_Constituent (Constit_Id : Entity_Id) is |
| 15569 |
SM_Prag : Node_Id; |
| 15570 |
|
| 15571 |
begin |
| 15572 |
-- Nothing to do for "null" constituents |
| 15573 |
|
| 15574 |
if Nkind (Constit_Id) = N_Null then |
| 15575 |
return; |
| 15576 |
|
| 15577 |
-- Nothing to do for illegal constituents |
| 15578 |
|
| 15579 |
elsif Error_Posted (Constit_Id) then |
| 15580 |
return; |
| 15581 |
end if; |
| 15582 |
|
| 15583 |
SM_Prag := SPARK_Pragma (Constit_Id); |
| 15584 |
|
| 15585 |
-- The check applies only when the constituent is subject to |
| 15586 |
-- pragma SPARK_Mode On. |
| 15587 |
|
| 15588 |
if Present (SM_Prag) |
| 15589 |
and then Get_SPARK_Mode_From_Annotation (SM_Prag) = On |
| 15590 |
then |
| 15591 |
-- An external constituent of an abstract state which appears |
| 15592 |
-- in the Initializes pragma of a package spec imposes an |
| 15593 |
-- Elaborate requirement on the context of the main unit. |
| 15594 |
-- Determine whether the context has a pragma strong enough to |
| 15595 |
-- meet the requirement. |
| 15596 |
|
| 15597 |
-- IMPORTANT: This check is performed only when -gnatd.v |
| 15598 |
-- (enforce SPARK elaboration rules in SPARK code) is in effect |
| 15599 |
-- because the static model can ensure the prior elaboration of |
| 15600 |
-- the unit which contains a constituent by installing implicit |
| 15601 |
-- Elaborate pragma. |
| 15602 |
|
| 15603 |
if Debug_Flag_Dot_V then |
| 15604 |
Meet_Elaboration_Requirement |
| 15605 |
(N => Prag, |
| 15606 |
Targ_Id => Constit_Id, |
| 15607 |
Req_Nam => Name_Elaborate, |
| 15608 |
In_State => In_State); |
| 15609 |
|
| 15610 |
-- Otherwise ensure that the unit with the external constituent |
| 15611 |
-- is elaborated prior to the main unit. |
| 15612 |
|
| 15613 |
else |
| 15614 |
Ensure_Prior_Elaboration |
| 15615 |
(N => Prag, |
| 15616 |
Unit_Id => Find_Top_Unit (Constit_Id), |
| 15617 |
Prag_Nam => Name_Elaborate, |
| 15618 |
In_State => In_State); |
| 15619 |
end if; |
| 15620 |
end if; |
| 15621 |
end Check_SPARK_Constituent; |
| 15622 |
|
| 15623 |
------------------------------ |
| 15624 |
-- Check_SPARK_Constituents -- |
| 15625 |
------------------------------ |
| 15626 |
|
| 15627 |
procedure Check_SPARK_Constituents (Constits : Elist_Id) is |
| 15628 |
Constit_Elmt : Elmt_Id; |
| 15629 |
|
| 15630 |
begin |
| 15631 |
if Present (Constits) then |
| 15632 |
Constit_Elmt := First_Elmt (Constits); |
| 15633 |
while Present (Constit_Elmt) loop |
| 15634 |
Check_SPARK_Constituent (Node (Constit_Elmt)); |
| 15635 |
Next_Elmt (Constit_Elmt); |
| 15636 |
end loop; |
| 15637 |
end if; |
| 15638 |
end Check_SPARK_Constituents; |
| 15639 |
|
| 15640 |
----------------------------------- |
| 15641 |
-- Check_SPARK_Initialized_State -- |
| 15642 |
----------------------------------- |
| 15643 |
|
| 15644 |
procedure Check_SPARK_Initialized_State (State : Node_Id) is |
| 15645 |
SM_Prag : Node_Id; |
| 15646 |
State_Id : Entity_Id; |
| 15647 |
|
| 15648 |
begin |
| 15649 |
-- Nothing to do for "null" initialization items |
| 15650 |
|
| 15651 |
if Nkind (State) = N_Null then |
| 15652 |
return; |
| 15653 |
|
| 15654 |
-- Nothing to do for illegal states |
| 15655 |
|
| 15656 |
elsif Error_Posted (State) then |
| 15657 |
return; |
| 15658 |
end if; |
| 15659 |
|
| 15660 |
State_Id := Entity_Of (State); |
| 15661 |
|
| 15662 |
-- Sanitize the state |
| 15663 |
|
| 15664 |
if No (State_Id) then |
| 15665 |
return; |
| 15666 |
|
| 15667 |
elsif Error_Posted (State_Id) then |
| 15668 |
return; |
| 15669 |
|
| 15670 |
elsif Ekind (State_Id) /= E_Abstract_State then |
| 15671 |
return; |
| 15672 |
end if; |
| 15673 |
|
| 15674 |
-- The check is performed only when the abstract state is subject |
| 15675 |
-- to SPARK_Mode On. |
| 15676 |
|
| 15677 |
SM_Prag := SPARK_Pragma (State_Id); |
| 15678 |
|
| 15679 |
if Present (SM_Prag) |
| 15680 |
and then Get_SPARK_Mode_From_Annotation (SM_Prag) = On |
| 15681 |
then |
| 15682 |
Check_SPARK_Constituents (Refinement_Constituents (State_Id)); |
| 15683 |
end if; |
| 15684 |
end Check_SPARK_Initialized_State; |
| 15685 |
|
| 15686 |
------------------------------------ |
| 15687 |
-- Check_SPARK_Initialized_States -- |
| 15688 |
------------------------------------ |
| 15689 |
|
| 15690 |
procedure Check_SPARK_Initialized_States (Pack_Id : Entity_Id) is |
| 15691 |
Init_Prag : constant Node_Id := |
| 15692 |
Get_Pragma (Pack_Id, Pragma_Initializes); |
| 15693 |
|
| 15694 |
Init : Node_Id; |
| 15695 |
Inits : Node_Id; |
| 15696 |
|
| 15697 |
begin |
| 15698 |
if Present (Init_Prag) then |
| 15699 |
Inits := Expression (Get_Argument (Init_Prag, Pack_Id)); |
| 15700 |
|
| 15701 |
-- Avoid processing a "null" initialization list. The only |
| 15702 |
-- other alternative is an aggregate. |
| 15703 |
|
| 15704 |
if Nkind (Inits) = N_Aggregate then |
| 15705 |
|
| 15706 |
-- The initialization items appear in list form: |
| 15707 |
-- |
| 15708 |
-- (state1, state2) |
| 15709 |
|
| 15710 |
if Present (Expressions (Inits)) then |
| 15711 |
Init := First (Expressions (Inits)); |
| 15712 |
while Present (Init) loop |
| 15713 |
Check_SPARK_Initialized_State (Init); |
| 15714 |
Next (Init); |
| 15715 |
end loop; |
| 15716 |
end if; |
| 15717 |
|
| 15718 |
-- The initialization items appear in associated form: |
| 15719 |
-- |
| 15720 |
-- (state1 => item1, |
| 15721 |
-- state2 => (item2, item3)) |
| 15722 |
|
| 15723 |
if Present (Component_Associations (Inits)) then |
| 15724 |
Init := First (Component_Associations (Inits)); |
| 15725 |
while Present (Init) loop |
| 15726 |
Check_SPARK_Initialized_State (Init); |
| 15727 |
Next (Init); |
| 15728 |
end loop; |
| 15729 |
end if; |
| 15730 |
end if; |
| 15731 |
end if; |
| 15732 |
end Check_SPARK_Initialized_States; |
| 15733 |
|
| 15734 |
-- Local variables |
| 15735 |
|
| 15736 |
Pack_Body : constant Node_Id := Find_Related_Package_Or_Body (Prag); |
| 15737 |
|
| 15738 |
-- Start of processing for Process_SPARK_Refined_State_Pragma |
| 15739 |
|
| 15740 |
begin |
| 15741 |
-- Pragma Refined_State must be associated with a package body |
| 15742 |
|
| 15743 |
pragma Assert |
| 15744 |
(Present (Pack_Body) and then Nkind (Pack_Body) = N_Package_Body); |
| 15745 |
|
| 15746 |
-- Verify that each external contitunent of an abstract state |
| 15747 |
-- mentioned in pragma Initializes is properly elaborated. |
| 15748 |
|
| 15749 |
Check_SPARK_Initialized_States (Unique_Defining_Entity (Pack_Body)); |
| 15750 |
end Process_SPARK_Refined_State_Pragma; |
| 15751 |
end SPARK_Processor; |
| 15752 |
|
| 15753 |
------------------------------- |
| 15754 |
-- Spec_And_Body_From_Entity -- |
| 15755 |
------------------------------- |
| 15756 |
|
| 15757 |
procedure Spec_And_Body_From_Entity |
| 15758 |
(Id : Entity_Id; |
| 15759 |
Spec_Decl : out Node_Id; |
| 15760 |
Body_Decl : out Node_Id) |
| 15761 |
is |
| 15762 |
begin |
| 15763 |
Spec_And_Body_From_Node |
| 15764 |
(N => Unit_Declaration_Node (Id), |
| 15765 |
Spec_Decl => Spec_Decl, |
| 15766 |
Body_Decl => Body_Decl); |
| 15767 |
end Spec_And_Body_From_Entity; |
| 15768 |
|
| 15769 |
----------------------------- |
| 15770 |
-- Spec_And_Body_From_Node -- |
| 15771 |
----------------------------- |
| 15772 |
|
| 15773 |
procedure Spec_And_Body_From_Node |
| 15774 |
(N : Node_Id; |
| 15775 |
Spec_Decl : out Node_Id; |
| 15776 |
Body_Decl : out Node_Id) |
| 15777 |
is |
| 15778 |
Body_Id : Entity_Id; |
| 15779 |
Spec_Id : Entity_Id; |
| 15780 |
|
| 15781 |
begin |
| 15782 |
-- Assume that the construct lacks spec and body |
| 15783 |
|
| 15784 |
Body_Decl := Empty; |
| 15785 |
Spec_Decl := Empty; |
| 15786 |
|
| 15787 |
-- Bodies |
| 15788 |
|
| 15789 |
if Nkind (N) in N_Package_Body |
| 15790 |
| N_Protected_Body |
| 15791 |
| N_Subprogram_Body |
| 15792 |
| N_Task_Body |
| 15793 |
then |
| 15794 |
Spec_Id := Corresponding_Spec (N); |
| 15795 |
|
| 15796 |
-- The body completes a previous declaration |
| 15797 |
|
| 15798 |
if Present (Spec_Id) then |
| 15799 |
Spec_Decl := Unit_Declaration_Node (Spec_Id); |
| 15800 |
|
| 15801 |
-- Otherwise the body acts as the initial declaration, and is both a |
| 15802 |
-- spec and body. There is no need to look for an optional body. |
| 15803 |
|
| 15804 |
else |
| 15805 |
Body_Decl := N; |
| 15806 |
Spec_Decl := N; |
| 15807 |
return; |
| 15808 |
end if; |
| 15809 |
|
| 15810 |
-- Declarations |
| 15811 |
|
| 15812 |
elsif Nkind (N) in N_Entry_Declaration |
| 15813 |
| N_Generic_Package_Declaration |
| 15814 |
| N_Generic_Subprogram_Declaration |
| 15815 |
| N_Package_Declaration |
| 15816 |
| N_Protected_Type_Declaration |
| 15817 |
| N_Subprogram_Declaration |
| 15818 |
| N_Task_Type_Declaration |
| 15819 |
then |
| 15820 |
Spec_Decl := N; |
| 15821 |
|
| 15822 |
-- Expression function |
| 15823 |
|
| 15824 |
elsif Nkind (N) = N_Expression_Function then |
| 15825 |
Spec_Id := Corresponding_Spec (N); |
| 15826 |
pragma Assert (Present (Spec_Id)); |
| 15827 |
|
| 15828 |
Spec_Decl := Unit_Declaration_Node (Spec_Id); |
| 15829 |
|
| 15830 |
-- Instantiations |
| 15831 |
|
| 15832 |
elsif Nkind (N) in N_Generic_Instantiation then |
| 15833 |
Spec_Decl := Instance_Spec (N); |
| 15834 |
pragma Assert (Present (Spec_Decl)); |
| 15835 |
|
| 15836 |
-- Stubs |
| 15837 |
|
| 15838 |
elsif Nkind (N) in N_Body_Stub then |
| 15839 |
Spec_Id := Corresponding_Spec_Of_Stub (N); |
| 15840 |
|
| 15841 |
-- The stub completes a previous declaration |
| 15842 |
|
| 15843 |
if Present (Spec_Id) then |
| 15844 |
Spec_Decl := Unit_Declaration_Node (Spec_Id); |
| 15845 |
|
| 15846 |
-- Otherwise the stub acts as a spec |
| 15847 |
|
| 15848 |
else |
| 15849 |
Spec_Decl := N; |
| 15850 |
end if; |
| 15851 |
end if; |
| 15852 |
|
| 15853 |
-- Obtain an optional or mandatory body |
| 15854 |
|
| 15855 |
if Present (Spec_Decl) then |
| 15856 |
Body_Id := Corresponding_Body (Spec_Decl); |
| 15857 |
|
| 15858 |
if Present (Body_Id) then |
| 15859 |
Body_Decl := Unit_Declaration_Node (Body_Id); |
| 15860 |
end if; |
| 15861 |
end if; |
| 15862 |
end Spec_And_Body_From_Node; |
| 15863 |
|
| 15864 |
------------------------------- |
| 15865 |
-- Static_Elaboration_Checks -- |
| 15866 |
------------------------------- |
| 15867 |
|
| 15868 |
function Static_Elaboration_Checks return Boolean is |
| 15869 |
begin |
| 15870 |
return not Dynamic_Elaboration_Checks; |
| 15871 |
end Static_Elaboration_Checks; |
| 15872 |
|
| 15873 |
----------------- |
| 15874 |
-- Unit_Entity -- |
| 15875 |
----------------- |
| 15876 |
|
| 15877 |
function Unit_Entity (Unit_Id : Entity_Id) return Entity_Id is |
| 15878 |
function Is_Subunit (Id : Entity_Id) return Boolean; |
| 15879 |
pragma Inline (Is_Subunit); |
| 15880 |
-- Determine whether the entity of an initial declaration denotes a |
| 15881 |
-- subunit. |
| 15882 |
|
| 15883 |
---------------- |
| 15884 |
-- Is_Subunit -- |
| 15885 |
---------------- |
| 15886 |
|
| 15887 |
function Is_Subunit (Id : Entity_Id) return Boolean is |
| 15888 |
Decl : constant Node_Id := Unit_Declaration_Node (Id); |
| 15889 |
|
| 15890 |
begin |
| 15891 |
return |
| 15892 |
Nkind (Decl) in N_Generic_Package_Declaration |
| 15893 |
| N_Generic_Subprogram_Declaration |
| 15894 |
| N_Package_Declaration |
| 15895 |
| N_Protected_Type_Declaration |
| 15896 |
| N_Subprogram_Declaration |
| 15897 |
| N_Task_Type_Declaration |
| 15898 |
and then Present (Corresponding_Body (Decl)) |
| 15899 |
and then Nkind (Parent (Unit_Declaration_Node |
| 15900 |
(Corresponding_Body (Decl)))) = N_Subunit; |
| 15901 |
end Is_Subunit; |
| 15902 |
|
| 15903 |
-- Local variables |
| 15904 |
|
| 15905 |
Id : Entity_Id; |
| 15906 |
|
| 15907 |
-- Start of processing for Unit_Entity |
| 15908 |
|
| 15909 |
begin |
| 15910 |
Id := Unique_Entity (Unit_Id); |
| 15911 |
|
| 15912 |
-- Skip all subunits found in the scope chain which ends at the input |
| 15913 |
-- unit. |
| 15914 |
|
| 15915 |
while Is_Subunit (Id) loop |
| 15916 |
Id := Scope (Id); |
| 15917 |
end loop; |
| 15918 |
|
| 15919 |
return Id; |
| 15920 |
end Unit_Entity; |
| 15921 |
|
| 15922 |
--------------------------------- |
| 15923 |
-- Update_Elaboration_Scenario -- |
| 15924 |
--------------------------------- |
| 15925 |
|
| 15926 |
procedure Update_Elaboration_Scenario (New_N : Node_Id; Old_N : Node_Id) is |
| 15927 |
begin |
| 15928 |
-- Nothing to do when the elaboration phase of the compiler is not |
| 15929 |
-- active. |
| 15930 |
|
| 15931 |
if not Elaboration_Phase_Active then |
| 15932 |
return; |
| 15933 |
|
| 15934 |
-- Nothing to do when the old and new scenarios are one and the same |
| 15935 |
|
| 15936 |
elsif Old_N = New_N then |
| 15937 |
return; |
| 15938 |
end if; |
| 15939 |
|
| 15940 |
-- A scenario is being transformed by Atree.Rewrite. Update all relevant |
| 15941 |
-- internal data structures to reflect this change. This ensures that a |
| 15942 |
-- potential run-time conditional ABE check or a guaranteed ABE failure |
| 15943 |
-- is inserted at the proper place in the tree. |
| 15944 |
|
| 15945 |
if Is_Scenario (Old_N) then |
| 15946 |
Replace_Scenario (Old_N, New_N); |
| 15947 |
end if; |
| 15948 |
end Update_Elaboration_Scenario; |
| 15949 |
|
| 15950 |
--------------------------------------------------------------------------- |
| 15951 |
-- -- |
| 15952 |
-- 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 -- |
| 15953 |
-- -- |
| 15954 |
-- M E C H A N I S M -- |
| 15955 |
-- -- |
| 15956 |
--------------------------------------------------------------------------- |
| 15957 |
|
| 15958 |
-- This section contains the implementation of the pre-18.x legacy ABE |
| 15959 |
-- mechanism. The mechanism can be activated using switch -gnatH (legacy |
| 15960 |
-- elaboration checking mode enabled). |
| 15961 |
|
| 15962 |
----------------------------- |
| 15963 |
-- Description of Approach -- |
| 15964 |
----------------------------- |
| 15965 |
|
| 15966 |
-- Every non-static call that is encountered by Sem_Res results in a call |
| 15967 |
-- to Check_Elab_Call, with N being the call node, and Outer set to its |
| 15968 |
-- default value of True. In addition X'Access is treated like a call |
| 15969 |
-- for the access-to-procedure case, and in SPARK mode only we also |
| 15970 |
-- check variable references. |
| 15971 |
|
| 15972 |
-- The goal of Check_Elab_Call is to determine whether or not the reference |
| 15973 |
-- in question can generate an access before elaboration error (raising |
| 15974 |
-- Program_Error) either by directly calling a subprogram whose body |
| 15975 |
-- has not yet been elaborated, or indirectly, by calling a subprogram |
| 15976 |
-- whose body has been elaborated, but which contains a call to such a |
| 15977 |
-- subprogram. |
| 15978 |
|
| 15979 |
-- In addition, in SPARK mode, we are checking for a variable reference in |
| 15980 |
-- another package, which requires an explicit Elaborate_All pragma. |
| 15981 |
|
| 15982 |
-- The only references that we need to look at the outer level are |
| 15983 |
-- references that occur in elaboration code. There are two cases. The |
| 15984 |
-- reference can be at the outer level of elaboration code, or it can |
| 15985 |
-- be within another unit, e.g. the elaboration code of a subprogram. |
| 15986 |
|
| 15987 |
-- In the case of an elaboration call at the outer level, we must trace |
| 15988 |
-- all calls to outer level routines either within the current unit or to |
| 15989 |
-- other units that are with'ed. For calls within the current unit, we can |
| 15990 |
-- determine if the body has been elaborated or not, and if it has not, |
| 15991 |
-- then a warning is generated. |
| 15992 |
|
| 15993 |
-- Note that there are two subcases. If the original call directly calls a |
| 15994 |
-- subprogram whose body has not been elaborated, then we know that an ABE |
| 15995 |
-- will take place, and we replace the call by a raise of Program_Error. |
| 15996 |
-- If the call is indirect, then we don't know that the PE will be raised, |
| 15997 |
-- since the call might be guarded by a conditional. In this case we set |
| 15998 |
-- Do_Elab_Check on the call so that a dynamic check is generated, and |
| 15999 |
-- output a warning. |
| 16000 |
|
| 16001 |
-- For calls to a subprogram in a with'ed unit or a 'Access or variable |
| 16002 |
-- reference (SPARK mode case), we require that a pragma Elaborate_All |
| 16003 |
-- or pragma Elaborate be present, or that the referenced unit have a |
| 16004 |
-- pragma Preelaborate, pragma Pure, or pragma Elaborate_Body. If none |
| 16005 |
-- of these conditions is met, then a warning is generated that a pragma |
| 16006 |
-- Elaborate_All may be needed (error in the SPARK case), or an implicit |
| 16007 |
-- pragma is generated. |
| 16008 |
|
| 16009 |
-- For the case of an elaboration call at some inner level, we are |
| 16010 |
-- interested in tracing only calls to subprograms at the same level, i.e. |
| 16011 |
-- those that can be called during elaboration. Any calls to outer level |
| 16012 |
-- routines cannot cause ABE's as a result of the original call (there |
| 16013 |
-- might be an outer level call to the subprogram from outside that causes |
| 16014 |
-- the ABE, but that gets analyzed separately). |
| 16015 |
|
| 16016 |
-- Note that we never trace calls to inner level subprograms, since these |
| 16017 |
-- cannot result in ABE's unless there is an elaboration problem at a lower |
| 16018 |
-- level, which will be separately detected. |
| 16019 |
|
| 16020 |
-- Note on pragma Elaborate. The checking here assumes that a pragma |
| 16021 |
-- Elaborate on a with'ed unit guarantees that subprograms within the unit |
| 16022 |
-- can be called without causing an ABE. This is not in fact the case since |
| 16023 |
-- pragma Elaborate does not guarantee the transitive coverage guaranteed |
| 16024 |
-- by Elaborate_All. However, we decide to trust the user in this case. |
| 16025 |
|
| 16026 |
-------------------------------------- |
| 16027 |
-- Instantiation Elaboration Errors -- |
| 16028 |
-------------------------------------- |
| 16029 |
|
| 16030 |
-- A special case arises when an instantiation appears in a context that is |
| 16031 |
-- known to be before the body is elaborated, e.g. |
| 16032 |
|
| 16033 |
-- generic package x is ... |
| 16034 |
-- ... |
| 16035 |
-- package xx is new x; |
| 16036 |
-- ... |
| 16037 |
-- package body x is ... |
| 16038 |
|
| 16039 |
-- In this situation it is certain that an elaboration error will occur, |
| 16040 |
-- and an unconditional raise Program_Error statement is inserted before |
| 16041 |
-- the instantiation, and a warning generated. |
| 16042 |
|
| 16043 |
-- The problem is that in this case we have no place to put the body of |
| 16044 |
-- the instantiation. We can't put it in the normal place, because it is |
| 16045 |
-- too early, and will cause errors to occur as a result of referencing |
| 16046 |
-- entities before they are declared. |
| 16047 |
|
| 16048 |
-- Our approach in this case is simply to avoid creating the body of the |
| 16049 |
-- instantiation in such a case. The instantiation spec is modified to |
| 16050 |
-- include dummy bodies for all subprograms, so that the resulting code |
| 16051 |
-- does not contain subprogram specs with no corresponding bodies. |
| 16052 |
|
| 16053 |
-- The following table records the recursive call chain for output in the |
| 16054 |
-- Output routine. Each entry records the call node and the entity of the |
| 16055 |
-- called routine. The number of entries in the table (i.e. the value of |
| 16056 |
-- Elab_Call.Last) indicates the current depth of recursion and is used to |
| 16057 |
-- identify the outer level. |
| 16058 |
|
| 16059 |
type Elab_Call_Element is record |
| 16060 |
Cloc : Source_Ptr; |
| 16061 |
Ent : Entity_Id; |
| 16062 |
end record; |
| 16063 |
|
| 16064 |
package Elab_Call is new Table.Table |
| 16065 |
(Table_Component_Type => Elab_Call_Element, |
| 16066 |
Table_Index_Type => Int, |
| 16067 |
Table_Low_Bound => 1, |
| 16068 |
Table_Initial => 50, |
| 16069 |
Table_Increment => 100, |
| 16070 |
Table_Name => "Elab_Call"); |
| 16071 |
|
| 16072 |
-- The following table records all calls that have been processed starting |
| 16073 |
-- from an outer level call. The table prevents both infinite recursion and |
| 16074 |
-- useless reanalysis of calls within the same context. The use of context |
| 16075 |
-- is important because it allows for proper checks in more complex code: |
| 16076 |
|
| 16077 |
-- if ... then |
| 16078 |
-- Call; -- requires a check |
| 16079 |
-- Call; -- does not need a check thanks to the table |
| 16080 |
-- elsif ... then |
| 16081 |
-- Call; -- requires a check, different context |
| 16082 |
-- end if; |
| 16083 |
|
| 16084 |
-- Call; -- requires a check, different context |
| 16085 |
|
| 16086 |
type Visited_Element is record |
| 16087 |
Subp_Id : Entity_Id; |
| 16088 |
-- The entity of the subprogram being called |
| 16089 |
|
| 16090 |
Context : Node_Id; |
| 16091 |
-- The context where the call to the subprogram occurs |
| 16092 |
end record; |
| 16093 |
|
| 16094 |
package Elab_Visited is new Table.Table |
| 16095 |
(Table_Component_Type => Visited_Element, |
| 16096 |
Table_Index_Type => Int, |
| 16097 |
Table_Low_Bound => 1, |
| 16098 |
Table_Initial => 200, |
| 16099 |
Table_Increment => 100, |
| 16100 |
Table_Name => "Elab_Visited"); |
| 16101 |
|
| 16102 |
-- The following table records delayed calls which must be examined after |
| 16103 |
-- all generic bodies have been instantiated. |
| 16104 |
|
| 16105 |
type Delay_Element is record |
| 16106 |
N : Node_Id; |
| 16107 |
-- The parameter N from the call to Check_Internal_Call. Note that this |
| 16108 |
-- node may get rewritten over the delay period by expansion in the call |
| 16109 |
-- case (but not in the instantiation case). |
| 16110 |
|
| 16111 |
E : Entity_Id; |
| 16112 |
-- The parameter E from the call to Check_Internal_Call |
| 16113 |
|
| 16114 |
Orig_Ent : Entity_Id; |
| 16115 |
-- The parameter Orig_Ent from the call to Check_Internal_Call |
| 16116 |
|
| 16117 |
Curscop : Entity_Id; |
| 16118 |
-- The current scope of the call. This is restored when we complete the |
| 16119 |
-- delayed call, so that we do this in the right scope. |
| 16120 |
|
| 16121 |
Outer_Scope : Entity_Id; |
| 16122 |
-- Save scope of outer level call |
| 16123 |
|
| 16124 |
From_Elab_Code : Boolean; |
| 16125 |
-- Save indication of whether this call is from elaboration code |
| 16126 |
|
| 16127 |
In_Task_Activation : Boolean; |
| 16128 |
-- Save indication of whether this call is from a task body. Tasks are |
| 16129 |
-- activated at the "begin", which is after all local procedure bodies, |
| 16130 |
-- so calls to those procedures can't fail, even if they occur after the |
| 16131 |
-- task body. |
| 16132 |
|
| 16133 |
From_SPARK_Code : Boolean; |
| 16134 |
-- Save indication of whether this call is under SPARK_Mode => On |
| 16135 |
end record; |
| 16136 |
|
| 16137 |
package Delay_Check is new Table.Table |
| 16138 |
(Table_Component_Type => Delay_Element, |
| 16139 |
Table_Index_Type => Int, |
| 16140 |
Table_Low_Bound => 1, |
| 16141 |
Table_Initial => 1000, |
| 16142 |
Table_Increment => 100, |
| 16143 |
Table_Name => "Delay_Check"); |
| 16144 |
|
| 16145 |
C_Scope : Entity_Id; |
| 16146 |
-- Top-level scope of current scope. Compute this only once at the outer |
| 16147 |
-- level, i.e. for a call to Check_Elab_Call from outside this unit. |
| 16148 |
|
| 16149 |
Outer_Level_Sloc : Source_Ptr; |
| 16150 |
-- Save Sloc value for outer level call node for comparisons of source |
| 16151 |
-- locations. A body is too late if it appears after the *outer* level |
| 16152 |
-- call, not the particular call that is being analyzed. |
| 16153 |
|
| 16154 |
From_Elab_Code : Boolean; |
| 16155 |
-- This flag shows whether the outer level call currently being examined |
| 16156 |
-- is or is not in elaboration code. We are only interested in calls to |
| 16157 |
-- routines in other units if this flag is True. |
| 16158 |
|
| 16159 |
In_Task_Activation : Boolean := False; |
| 16160 |
-- This flag indicates whether we are performing elaboration checks on task |
| 16161 |
-- bodies, at the point of activation. If true, we do not raise |
| 16162 |
-- Program_Error for calls to local procedures, because all local bodies |
| 16163 |
-- are known to be elaborated. However, we still need to trace such calls, |
| 16164 |
-- because a local procedure could call a procedure in another package, |
| 16165 |
-- so we might need an implicit Elaborate_All. |
| 16166 |
|
| 16167 |
Delaying_Elab_Checks : Boolean := True; |
| 16168 |
-- This is set True till the compilation is complete, including the |
| 16169 |
-- insertion of all instance bodies. Then when Check_Elab_Calls is called, |
| 16170 |
-- the delay table is used to make the delayed calls and this flag is reset |
| 16171 |
-- to False, so that the calls are processed. |
| 16172 |
|
| 16173 |
----------------------- |
| 16174 |
-- Local Subprograms -- |
| 16175 |
----------------------- |
| 16176 |
|
| 16177 |
-- Note: Outer_Scope in all following specs represents the scope of |
| 16178 |
-- interest of the outer level call. If it is set to Standard_Standard, |
| 16179 |
-- then it means the outer level call was at elaboration level, and that |
| 16180 |
-- thus all calls are of interest. If it was set to some other scope, |
| 16181 |
-- then the original call was an inner call, and we are not interested |
| 16182 |
-- in calls that go outside this scope. |
| 16183 |
|
| 16184 |
procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id); |
| 16185 |
-- Analysis of construct N shows that we should set Elaborate_All_Desirable |
| 16186 |
-- for the WITH clause for unit U (which will always be present). A special |
| 16187 |
-- case is when N is a function or procedure instantiation, in which case |
| 16188 |
-- it is sufficient to set Elaborate_Desirable, since in this case there is |
| 16189 |
-- no possibility of transitive elaboration issues. |
| 16190 |
|
| 16191 |
procedure Check_A_Call |
| 16192 |
(N : Node_Id; |
| 16193 |
E : Entity_Id; |
| 16194 |
Outer_Scope : Entity_Id; |
| 16195 |
Inter_Unit_Only : Boolean; |
| 16196 |
Generate_Warnings : Boolean := True; |
| 16197 |
In_Init_Proc : Boolean := False); |
| 16198 |
-- This is the internal recursive routine that is called to check for |
| 16199 |
-- possible elaboration error. The argument N is a subprogram call or |
| 16200 |
-- generic instantiation, or 'Access attribute reference to be checked, and |
| 16201 |
-- E is the entity of the called subprogram, or instantiated generic unit, |
| 16202 |
-- or subprogram referenced by 'Access. |
| 16203 |
-- |
| 16204 |
-- In SPARK mode, N can also be a variable reference, since in SPARK this |
| 16205 |
-- also triggers a requirement for Elaborate_All, and in this case E is the |
| 16206 |
-- entity being referenced. |
| 16207 |
-- |
| 16208 |
-- Outer_Scope is the outer level scope for the original reference. |
| 16209 |
-- Inter_Unit_Only is set if the call is only to be checked in the |
| 16210 |
-- case where it is to another unit (and skipped if within a unit). |
| 16211 |
-- Generate_Warnings is set to False to suppress warning messages about |
| 16212 |
-- missing pragma Elaborate_All's. These messages are not wanted for |
| 16213 |
-- inner calls in the dynamic model. Note that an instance of the Access |
| 16214 |
-- attribute applied to a subprogram also generates a call to this |
| 16215 |
-- procedure (since the referenced subprogram may be called later |
| 16216 |
-- indirectly). Flag In_Init_Proc should be set whenever the current |
| 16217 |
-- context is a type init proc. |
| 16218 |
-- |
| 16219 |
-- Note: this might better be called Check_A_Reference to recognize the |
| 16220 |
-- variable case for SPARK, but we prefer to retain the historical name |
| 16221 |
-- since in practice this is mostly about checking calls for the possible |
| 16222 |
-- occurrence of an access-before-elaboration exception. |
| 16223 |
|
| 16224 |
procedure Check_Bad_Instantiation (N : Node_Id); |
| 16225 |
-- N is a node for an instantiation (if called with any other node kind, |
| 16226 |
-- Check_Bad_Instantiation ignores the call). This subprogram checks for |
| 16227 |
-- the special case of a generic instantiation of a generic spec in the |
| 16228 |
-- same declarative part as the instantiation where a body is present and |
| 16229 |
-- has not yet been seen. This is an obvious error, but needs to be checked |
| 16230 |
-- specially at the time of the instantiation, since it is a case where we |
| 16231 |
-- cannot insert the body anywhere. If this case is detected, warnings are |
| 16232 |
-- generated, and a raise of Program_Error is inserted. In addition any |
| 16233 |
-- subprograms in the generic spec are stubbed, and the Bad_Instantiation |
| 16234 |
-- flag is set on the instantiation node. The caller in Sem_Ch12 uses this |
| 16235 |
-- flag as an indication that no attempt should be made to insert an |
| 16236 |
-- instance body. |
| 16237 |
|
| 16238 |
procedure Check_Internal_Call |
| 16239 |
(N : Node_Id; |
| 16240 |
E : Entity_Id; |
| 16241 |
Outer_Scope : Entity_Id; |
| 16242 |
Orig_Ent : Entity_Id); |
| 16243 |
-- N is a function call or procedure statement call node and E is the |
| 16244 |
-- entity of the called function, which is within the current compilation |
| 16245 |
-- unit (where subunits count as part of the parent). This call checks if |
| 16246 |
-- this call, or any call within any accessed body could cause an ABE, and |
| 16247 |
-- if so, outputs a warning. Orig_Ent differs from E only in the case of |
| 16248 |
-- renamings, and points to the original name of the entity. This is used |
| 16249 |
-- for error messages. Outer_Scope is the outer level scope for the |
| 16250 |
-- original call. |
| 16251 |
|
| 16252 |
procedure Check_Internal_Call_Continue |
| 16253 |
(N : Node_Id; |
| 16254 |
E : Entity_Id; |
| 16255 |
Outer_Scope : Entity_Id; |
| 16256 |
Orig_Ent : Entity_Id); |
| 16257 |
-- The processing for Check_Internal_Call is divided up into two phases, |
| 16258 |
-- and this represents the second phase. The second phase is delayed if |
| 16259 |
-- Delaying_Elab_Checks is set to True. In this delayed case, the first |
| 16260 |
-- phase makes an entry in the Delay_Check table, which is processed when |
| 16261 |
-- Check_Elab_Calls is called. N, E and Orig_Ent are as for the call to |
| 16262 |
-- Check_Internal_Call. Outer_Scope is the outer level scope for the |
| 16263 |
-- original call. |
| 16264 |
|
| 16265 |
function Get_Referenced_Ent (N : Node_Id) return Entity_Id; |
| 16266 |
-- N is either a function or procedure call or an access attribute that |
| 16267 |
-- references a subprogram. This call retrieves the relevant entity. If |
| 16268 |
-- this is a call to a protected subprogram, the entity is a selected |
| 16269 |
-- component. The callable entity may be absent, in which case Empty is |
| 16270 |
-- returned. This happens with non-analyzed calls in nested generics. |
| 16271 |
-- |
| 16272 |
-- If SPARK_Mode is On, then N can also be a reference to an E_Variable |
| 16273 |
-- entity, in which case, the value returned is simply this entity. |
| 16274 |
|
| 16275 |
function Has_Generic_Body (N : Node_Id) return Boolean; |
| 16276 |
-- N is a generic package instantiation node, and this routine determines |
| 16277 |
-- if this package spec does in fact have a generic body. If so, then |
| 16278 |
-- True is returned, otherwise False. Note that this is not at all the |
| 16279 |
-- same as checking if the unit requires a body, since it deals with |
| 16280 |
-- the case of optional bodies accurately (i.e. if a body is optional, |
| 16281 |
-- then it looks to see if a body is actually present). Note: this |
| 16282 |
-- function can only do a fully correct job if in generating code mode |
| 16283 |
-- where all bodies have to be present. If we are operating in semantics |
| 16284 |
-- check only mode, then in some cases of optional bodies, a result of |
| 16285 |
-- False may incorrectly be given. In practice this simply means that |
| 16286 |
-- some cases of warnings for incorrect order of elaboration will only |
| 16287 |
-- be given when generating code, which is not a big problem (and is |
| 16288 |
-- inevitable, given the optional body semantics of Ada). |
| 16289 |
|
| 16290 |
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty); |
| 16291 |
-- Given code for an elaboration check (or unconditional raise if the check |
| 16292 |
-- is not needed), inserts the code in the appropriate place. N is the call |
| 16293 |
-- or instantiation node for which the check code is required. C is the |
| 16294 |
-- test whose failure triggers the raise. |
| 16295 |
|
| 16296 |
function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean; |
| 16297 |
-- Returns True if node N is a call to a generic formal subprogram |
| 16298 |
|
| 16299 |
function Is_Finalization_Procedure (Id : Entity_Id) return Boolean; |
| 16300 |
-- Determine whether entity Id denotes a [Deep_]Finalize procedure |
| 16301 |
|
| 16302 |
procedure Output_Calls |
| 16303 |
(N : Node_Id; |
| 16304 |
Check_Elab_Flag : Boolean); |
| 16305 |
-- Outputs chain of calls stored in the Elab_Call table. The caller has |
| 16306 |
-- already generated the main warning message, so the warnings generated |
| 16307 |
-- are all continuation messages. The argument is the call node at which |
| 16308 |
-- the messages are to be placed. When Check_Elab_Flag is set, calls are |
| 16309 |
-- enumerated only when flag Elab_Warning is set for the dynamic case or |
| 16310 |
-- when flag Elab_Info_Messages is set for the static case. |
| 16311 |
|
| 16312 |
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean; |
| 16313 |
-- Given two scopes, determine whether they are the same scope from an |
| 16314 |
-- elaboration point of view, i.e. packages and blocks are ignored. |
| 16315 |
|
| 16316 |
procedure Set_C_Scope; |
| 16317 |
-- On entry C_Scope is set to some scope. On return, C_Scope is reset |
| 16318 |
-- to be the enclosing compilation unit of this scope. |
| 16319 |
|
| 16320 |
procedure Set_Elaboration_Constraint |
| 16321 |
(Call : Node_Id; |
| 16322 |
Subp : Entity_Id; |
| 16323 |
Scop : Entity_Id); |
| 16324 |
-- The current unit U may depend semantically on some unit P that is not |
| 16325 |
-- in the current context. If there is an elaboration call that reaches P, |
| 16326 |
-- we need to indicate that P requires an Elaborate_All, but this is not |
| 16327 |
-- effective in U's ali file, if there is no with_clause for P. In this |
| 16328 |
-- case we add the Elaborate_All on the unit Q that directly or indirectly |
| 16329 |
-- makes P available. This can happen in two cases: |
| 16330 |
-- |
| 16331 |
-- a) Q declares a subtype of a type declared in P, and the call is an |
| 16332 |
-- initialization call for an object of that subtype. |
| 16333 |
-- |
| 16334 |
-- b) Q declares an object of some tagged type whose root type is |
| 16335 |
-- declared in P, and the initialization call uses object notation on |
| 16336 |
-- that object to reach a primitive operation or a classwide operation |
| 16337 |
-- declared in P. |
| 16338 |
-- |
| 16339 |
-- If P appears in the context of U, the current processing is correct. |
| 16340 |
-- Otherwise we must identify these two cases to retrieve Q and place the |
| 16341 |
-- Elaborate_All_Desirable on it. |
| 16342 |
|
| 16343 |
function Spec_Entity (E : Entity_Id) return Entity_Id; |
| 16344 |
-- Given a compilation unit entity, if it is a spec entity, it is returned |
| 16345 |
-- unchanged. If it is a body entity, then the spec for the corresponding |
| 16346 |
-- spec is returned |
| 16347 |
|
| 16348 |
function Within (E1, E2 : Entity_Id) return Boolean; |
| 16349 |
-- Given two scopes E1 and E2, returns True if E1 is equal to E2, or is one |
| 16350 |
-- of its contained scopes, False otherwise. |
| 16351 |
|
| 16352 |
function Within_Elaborate_All |
| 16353 |
(Unit : Unit_Number_Type; |
| 16354 |
E : Entity_Id) return Boolean; |
| 16355 |
-- Return True if we are within the scope of an Elaborate_All for E, or if |
| 16356 |
-- we are within the scope of an Elaborate_All for some other unit U, and U |
| 16357 |
-- with's E. This prevents spurious warnings when the called entity is |
| 16358 |
-- renamed within U, or in case of generic instances. |
| 16359 |
|
| 16360 |
-------------------------------------- |
| 16361 |
-- Activate_Elaborate_All_Desirable -- |
| 16362 |
-------------------------------------- |
| 16363 |
|
| 16364 |
procedure Activate_Elaborate_All_Desirable (N : Node_Id; U : Entity_Id) is |
| 16365 |
UN : constant Unit_Number_Type := Get_Code_Unit (N); |
| 16366 |
CU : constant Node_Id := Cunit (UN); |
| 16367 |
UE : constant Entity_Id := Cunit_Entity (UN); |
| 16368 |
Unm : constant Unit_Name_Type := Unit_Name (UN); |
| 16369 |
CI : constant List_Id := Context_Items (CU); |
| 16370 |
Itm : Node_Id; |
| 16371 |
Ent : Entity_Id; |
| 16372 |
|
| 16373 |
procedure Add_To_Context_And_Mark (Itm : Node_Id); |
| 16374 |
-- This procedure is called when the elaborate indication must be |
| 16375 |
-- applied to a unit not in the context of the referencing unit. The |
| 16376 |
-- unit gets added to the context as an implicit with. |
| 16377 |
-- Note that we can be with-ing (for example) a package body, which |
| 16378 |
-- is not the case for normal with clauses. |
| 16379 |
|
| 16380 |
function In_Withs_Of (UEs : Entity_Id) return Boolean; |
| 16381 |
-- UEs is the spec entity of a unit. If the unit to be marked is |
| 16382 |
-- in the context item list of this unit spec, then the call returns |
| 16383 |
-- True and Itm is left set to point to the relevant N_With_Clause node. |
| 16384 |
|
| 16385 |
procedure Set_Elab_Flag (Itm : Node_Id); |
| 16386 |
-- Sets Elaborate_[All_]Desirable as appropriate on Itm |
| 16387 |
|
| 16388 |
----------------------------- |
| 16389 |
-- Add_To_Context_And_Mark -- |
| 16390 |
----------------------------- |
| 16391 |
|
| 16392 |
procedure Add_To_Context_And_Mark (Itm : Node_Id) is |
| 16393 |
CW : constant Node_Id := |
| 16394 |
Make_With_Clause (Sloc (Itm), |
| 16395 |
Name => Name (Itm)); |
| 16396 |
|
| 16397 |
begin |
| 16398 |
Set_Is_Implicit_With (CW); |
| 16399 |
Set_Withed_Lib_Unit (CW, Withed_Lib_Unit (Itm)); |
| 16400 |
|
| 16401 |
-- Set elaborate all desirable on copy and then append the copy to |
| 16402 |
-- the list of body with's and we are done. |
| 16403 |
|
| 16404 |
Set_Elab_Flag (CW); |
| 16405 |
Append_To (CI, CW); |
| 16406 |
end Add_To_Context_And_Mark; |
| 16407 |
|
| 16408 |
----------------- |
| 16409 |
-- In_Withs_Of -- |
| 16410 |
----------------- |
| 16411 |
|
| 16412 |
function In_Withs_Of (UEs : Entity_Id) return Boolean is |
| 16413 |
UNs : constant Unit_Number_Type := Get_Source_Unit (UEs); |
| 16414 |
CUs : constant Node_Id := Cunit (UNs); |
| 16415 |
CIs : constant List_Id := Context_Items (CUs); |
| 16416 |
|
| 16417 |
begin |
| 16418 |
Itm := First (CIs); |
| 16419 |
while Present (Itm) loop |
| 16420 |
if Nkind (Itm) = N_With_Clause then |
| 16421 |
Ent := |
| 16422 |
Cunit_Entity (Get_Cunit_Unit_Number (Withed_Lib_Unit (Itm))); |
| 16423 |
|
| 16424 |
if U = Ent then |
| 16425 |
return True; |
| 16426 |
end if; |
| 16427 |
end if; |
| 16428 |
|
| 16429 |
Next (Itm); |
| 16430 |
end loop; |
| 16431 |
|
| 16432 |
return False; |
| 16433 |
end In_Withs_Of; |
| 16434 |
|
| 16435 |
------------------- |
| 16436 |
-- Set_Elab_Flag -- |
| 16437 |
------------------- |
| 16438 |
|
| 16439 |
procedure Set_Elab_Flag (Itm : Node_Id) is |
| 16440 |
begin |
| 16441 |
if Nkind (N) in N_Subprogram_Instantiation then |
| 16442 |
Set_Elaborate_Desirable (Itm); |
| 16443 |
else |
| 16444 |
Set_Elaborate_All_Desirable (Itm); |
| 16445 |
end if; |
| 16446 |
end Set_Elab_Flag; |
| 16447 |
|
| 16448 |
-- Start of processing for Activate_Elaborate_All_Desirable |
| 16449 |
|
| 16450 |
begin |
| 16451 |
-- Do not set binder indication if expansion is disabled, as when |
| 16452 |
-- compiling a generic unit. |
| 16453 |
|
| 16454 |
if not Expander_Active then |
| 16455 |
return; |
| 16456 |
end if; |
| 16457 |
|
| 16458 |
-- If an instance of a generic package contains a controlled object (so |
| 16459 |
-- we're calling Initialize at elaboration time), and the instance is in |
| 16460 |
-- a package body P that says "with P;", then we need to return without |
| 16461 |
-- adding "pragma Elaborate_All (P);" to P. |
| 16462 |
|
| 16463 |
if U = Main_Unit_Entity then |
| 16464 |
return; |
| 16465 |
end if; |
| 16466 |
|
| 16467 |
Itm := First (CI); |
| 16468 |
while Present (Itm) loop |
| 16469 |
if Nkind (Itm) = N_With_Clause then |
| 16470 |
Ent := |
| 16471 |
Cunit_Entity (Get_Cunit_Unit_Number (Withed_Lib_Unit (Itm))); |
| 16472 |
|
| 16473 |
-- If we find it, then mark elaborate all desirable and return |
| 16474 |
|
| 16475 |
if U = Ent then |
| 16476 |
Set_Elab_Flag (Itm); |
| 16477 |
return; |
| 16478 |
end if; |
| 16479 |
end if; |
| 16480 |
|
| 16481 |
Next (Itm); |
| 16482 |
end loop; |
| 16483 |
|
| 16484 |
-- If we fall through then the with clause is not present in the |
| 16485 |
-- current unit. One legitimate possibility is that the with clause |
| 16486 |
-- is present in the spec when we are a body. |
| 16487 |
|
| 16488 |
if Is_Body_Name (Unm) |
| 16489 |
and then In_Withs_Of (Spec_Entity (UE)) |
| 16490 |
then |
| 16491 |
Add_To_Context_And_Mark (Itm); |
| 16492 |
return; |
| 16493 |
end if; |
| 16494 |
|
| 16495 |
-- Similarly, we may be in the spec or body of a child unit, where |
| 16496 |
-- the unit in question is with'ed by some ancestor of the child unit. |
| 16497 |
|
| 16498 |
if Is_Child_Name (Unm) then |
| 16499 |
declare |
| 16500 |
Pkg : Entity_Id; |
| 16501 |
|
| 16502 |
begin |
| 16503 |
Pkg := UE; |
| 16504 |
loop |
| 16505 |
Pkg := Scope (Pkg); |
| 16506 |
exit when Pkg = Standard_Standard; |
| 16507 |
|
| 16508 |
if In_Withs_Of (Pkg) then |
| 16509 |
Add_To_Context_And_Mark (Itm); |
| 16510 |
return; |
| 16511 |
end if; |
| 16512 |
end loop; |
| 16513 |
end; |
| 16514 |
end if; |
| 16515 |
|
| 16516 |
-- Here if we do not find with clause on spec or body. We just ignore |
| 16517 |
-- this case; it means that the elaboration involves some other unit |
| 16518 |
-- than the unit being compiled, and will be caught elsewhere. |
| 16519 |
end Activate_Elaborate_All_Desirable; |
| 16520 |
|
| 16521 |
------------------ |
| 16522 |
-- Check_A_Call -- |
| 16523 |
------------------ |
| 16524 |
|
| 16525 |
procedure Check_A_Call |
| 16526 |
(N : Node_Id; |
| 16527 |
E : Entity_Id; |
| 16528 |
Outer_Scope : Entity_Id; |
| 16529 |
Inter_Unit_Only : Boolean; |
| 16530 |
Generate_Warnings : Boolean := True; |
| 16531 |
In_Init_Proc : Boolean := False) |
| 16532 |
is |
| 16533 |
Access_Case : constant Boolean := Nkind (N) = N_Attribute_Reference; |
| 16534 |
-- Indicates if we have Access attribute case |
| 16535 |
|
| 16536 |
function Call_To_Instance_From_Outside (Id : Entity_Id) return Boolean; |
| 16537 |
-- True if we're calling an instance of a generic subprogram, or a |
| 16538 |
-- subprogram in an instance of a generic package, and the call is |
| 16539 |
-- outside that instance. |
| 16540 |
|
| 16541 |
procedure Elab_Warning |
| 16542 |
(Msg_D : String; |
| 16543 |
Msg_S : String; |
| 16544 |
Ent : Node_Or_Entity_Id); |
| 16545 |
-- Generate a call to Error_Msg_NE with parameters Msg_D or Msg_S (for |
| 16546 |
-- dynamic or static elaboration model), N and Ent. Msg_D is a real |
| 16547 |
-- warning (output if Msg_D is non-null and Elab_Warnings is set), |
| 16548 |
-- Msg_S is an info message (output if Elab_Info_Messages is set). |
| 16549 |
|
| 16550 |
function Find_W_Scope return Entity_Id; |
| 16551 |
-- Find top-level scope for called entity (not following renamings |
| 16552 |
-- or derivations). This is where the Elaborate_All will go if it is |
| 16553 |
-- needed. We start with the called entity, except in the case of an |
| 16554 |
-- initialization procedure outside the current package, where the init |
| 16555 |
-- proc is in the root package, and we start from the entity of the name |
| 16556 |
-- in the call. |
| 16557 |
|
| 16558 |
----------------------------------- |
| 16559 |
-- Call_To_Instance_From_Outside -- |
| 16560 |
----------------------------------- |
| 16561 |
|
| 16562 |
function Call_To_Instance_From_Outside (Id : Entity_Id) return Boolean is |
| 16563 |
Scop : Entity_Id := Id; |
| 16564 |
|
| 16565 |
begin |
| 16566 |
loop |
| 16567 |
if Scop = Standard_Standard then |
| 16568 |
return False; |
| 16569 |
end if; |
| 16570 |
|
| 16571 |
if Is_Generic_Instance (Scop) then |
| 16572 |
return not In_Open_Scopes (Scop); |
| 16573 |
end if; |
| 16574 |
|
| 16575 |
Scop := Scope (Scop); |
| 16576 |
end loop; |
| 16577 |
end Call_To_Instance_From_Outside; |
| 16578 |
|
| 16579 |
------------------ |
| 16580 |
-- Elab_Warning -- |
| 16581 |
------------------ |
| 16582 |
|
| 16583 |
procedure Elab_Warning |
| 16584 |
(Msg_D : String; |
| 16585 |
Msg_S : String; |
| 16586 |
Ent : Node_Or_Entity_Id) |
| 16587 |
is |
| 16588 |
begin |
| 16589 |
-- Dynamic elaboration checks, real warning |
| 16590 |
|
| 16591 |
if Dynamic_Elaboration_Checks then |
| 16592 |
if not Access_Case then |
| 16593 |
if Msg_D /= "" and then Elab_Warnings then |
| 16594 |
Error_Msg_NE (Msg_D, N, Ent); |
| 16595 |
end if; |
| 16596 |
|
| 16597 |
-- In the access case emit first warning message as well, |
| 16598 |
-- otherwise list of calls will appear as errors. |
| 16599 |
|
| 16600 |
elsif Elab_Warnings then |
| 16601 |
Error_Msg_NE (Msg_S, N, Ent); |
| 16602 |
end if; |
| 16603 |
|
| 16604 |
-- Static elaboration checks, info message |
| 16605 |
|
| 16606 |
else |
| 16607 |
if Elab_Info_Messages then |
| 16608 |
Error_Msg_NE (Msg_S, N, Ent); |
| 16609 |
end if; |
| 16610 |
end if; |
| 16611 |
end Elab_Warning; |
| 16612 |
|
| 16613 |
------------------ |
| 16614 |
-- Find_W_Scope -- |
| 16615 |
------------------ |
| 16616 |
|
| 16617 |
function Find_W_Scope return Entity_Id is |
| 16618 |
Refed_Ent : constant Entity_Id := Get_Referenced_Ent (N); |
| 16619 |
W_Scope : Entity_Id; |
| 16620 |
|
| 16621 |
begin |
| 16622 |
if Is_Init_Proc (Refed_Ent) |
| 16623 |
and then not In_Same_Extended_Unit (N, Refed_Ent) |
| 16624 |
then |
| 16625 |
W_Scope := Scope (Refed_Ent); |
| 16626 |
else |
| 16627 |
W_Scope := E; |
| 16628 |
end if; |
| 16629 |
|
| 16630 |
-- Now loop through scopes to get to the enclosing compilation unit |
| 16631 |
|
| 16632 |
while not Is_Compilation_Unit (W_Scope) loop |
| 16633 |
W_Scope := Scope (W_Scope); |
| 16634 |
end loop; |
| 16635 |
|
| 16636 |
return W_Scope; |
| 16637 |
end Find_W_Scope; |
| 16638 |
|
| 16639 |
-- Local variables |
| 16640 |
|
| 16641 |
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation; |
| 16642 |
-- Indicates if we have instantiation case |
| 16643 |
|
| 16644 |
Loc : constant Source_Ptr := Sloc (N); |
| 16645 |
|
| 16646 |
Variable_Case : constant Boolean := |
| 16647 |
Nkind (N) in N_Has_Entity |
| 16648 |
and then Present (Entity (N)) |
| 16649 |
and then Ekind (Entity (N)) = E_Variable; |
| 16650 |
-- Indicates if we have variable reference case |
| 16651 |
|
| 16652 |
W_Scope : constant Entity_Id := Find_W_Scope; |
| 16653 |
-- Top-level scope of directly called entity for subprogram. This |
| 16654 |
-- differs from E_Scope in the case where renamings or derivations |
| 16655 |
-- are involved, since it does not follow these links. W_Scope is |
| 16656 |
-- generally in a visible unit, and it is this scope that may require |
| 16657 |
-- an Elaborate_All. However, there are some cases (initialization |
| 16658 |
-- calls and calls involving object notation) where W_Scope might not |
| 16659 |
-- be in the context of the current unit, and there is an intermediate |
| 16660 |
-- package that is, in which case the Elaborate_All has to be placed |
| 16661 |
-- on this intermediate package. These special cases are handled in |
| 16662 |
-- Set_Elaboration_Constraint. |
| 16663 |
|
| 16664 |
Ent : Entity_Id; |
| 16665 |
Callee_Unit_Internal : Boolean; |
| 16666 |
Caller_Unit_Internal : Boolean; |
| 16667 |
Decl : Node_Id; |
| 16668 |
Inst_Callee : Source_Ptr; |
| 16669 |
Inst_Caller : Source_Ptr; |
| 16670 |
Unit_Callee : Unit_Number_Type; |
| 16671 |
Unit_Caller : Unit_Number_Type; |
| 16672 |
|
| 16673 |
Body_Acts_As_Spec : Boolean; |
| 16674 |
-- Set to true if call is to body acting as spec (no separate spec) |
| 16675 |
|
| 16676 |
Cunit_SC : Boolean := False; |
| 16677 |
-- Set to suppress dynamic elaboration checks where one of the |
| 16678 |
-- enclosing scopes has Elaboration_Checks_Suppressed set, or else |
| 16679 |
-- if a pragma Elaborate[_All] applies to that scope, in which case |
| 16680 |
-- warnings on the scope are also suppressed. For the internal case, |
| 16681 |
-- we ignore this flag. |
| 16682 |
|
| 16683 |
E_Scope : Entity_Id; |
| 16684 |
-- Top-level scope of entity for called subprogram. This value includes |
| 16685 |
-- following renamings and derivations, so this scope can be in a |
| 16686 |
-- non-visible unit. This is the scope that is to be investigated to |
| 16687 |
-- see whether an elaboration check is required. |
| 16688 |
|
| 16689 |
Is_DIC : Boolean; |
| 16690 |
-- Flag set when the subprogram being invoked is the procedure generated |
| 16691 |
-- for pragma Default_Initial_Condition. |
| 16692 |
|
| 16693 |
SPARK_Elab_Errors : Boolean; |
| 16694 |
-- Flag set when an entity is called or a variable is read during SPARK |
| 16695 |
-- dynamic elaboration. |
| 16696 |
|
| 16697 |
-- Start of processing for Check_A_Call |
| 16698 |
|
| 16699 |
begin |
| 16700 |
-- If the call is known to be within a local Suppress Elaboration |
| 16701 |
-- pragma, nothing to check. This can happen in task bodies. But |
| 16702 |
-- we ignore this for a call to a generic formal. |
| 16703 |
|
| 16704 |
if Nkind (N) in N_Subprogram_Call |
| 16705 |
and then No_Elaboration_Check (N) |
| 16706 |
and then not Is_Call_Of_Generic_Formal (N) |
| 16707 |
then |
| 16708 |
return; |
| 16709 |
|
| 16710 |
-- If this is a rewrite of a Valid_Scalars attribute, then nothing to |
| 16711 |
-- check, we don't mind in this case if the call occurs before the body |
| 16712 |
-- since this is all generated code. |
| 16713 |
|
| 16714 |
elsif Nkind (Original_Node (N)) = N_Attribute_Reference |
| 16715 |
and then Attribute_Name (Original_Node (N)) = Name_Valid_Scalars |
| 16716 |
then |
| 16717 |
return; |
| 16718 |
|
| 16719 |
-- Intrinsics such as instances of Unchecked_Deallocation do not have |
| 16720 |
-- any body, so elaboration checking is not needed, and would be wrong. |
| 16721 |
|
| 16722 |
elsif Is_Intrinsic_Subprogram (E) then |
| 16723 |
return; |
| 16724 |
|
| 16725 |
-- Do not consider references to internal variables for SPARK semantics |
| 16726 |
|
| 16727 |
elsif Variable_Case and then not Comes_From_Source (E) then |
| 16728 |
return; |
| 16729 |
end if; |
| 16730 |
|
| 16731 |
-- Proceed with check |
| 16732 |
|
| 16733 |
Ent := E; |
| 16734 |
|
| 16735 |
-- For a variable reference, just set Body_Acts_As_Spec to False |
| 16736 |
|
| 16737 |
if Variable_Case then |
| 16738 |
Body_Acts_As_Spec := False; |
| 16739 |
|
| 16740 |
-- Additional checks for all other cases |
| 16741 |
|
| 16742 |
else |
| 16743 |
-- Go to parent for derived subprogram, or to original subprogram in |
| 16744 |
-- the case of a renaming (Alias covers both these cases). |
| 16745 |
|
| 16746 |
loop |
| 16747 |
if (Suppress_Elaboration_Warnings (Ent) |
| 16748 |
or else Elaboration_Checks_Suppressed (Ent)) |
| 16749 |
and then (Inst_Case or else No (Alias (Ent))) |
| 16750 |
then |
| 16751 |
return; |
| 16752 |
end if; |
| 16753 |
|
| 16754 |
-- Nothing to do for imported entities |
| 16755 |
|
| 16756 |
if Is_Imported (Ent) then |
| 16757 |
return; |
| 16758 |
end if; |
| 16759 |
|
| 16760 |
exit when Inst_Case or else No (Alias (Ent)); |
| 16761 |
Ent := Alias (Ent); |
| 16762 |
end loop; |
| 16763 |
|
| 16764 |
Decl := Unit_Declaration_Node (Ent); |
| 16765 |
|
| 16766 |
if Nkind (Decl) = N_Subprogram_Body then |
| 16767 |
Body_Acts_As_Spec := True; |
| 16768 |
|
| 16769 |
elsif Nkind (Decl) in |
| 16770 |
N_Subprogram_Declaration | N_Subprogram_Body_Stub |
| 16771 |
or else Inst_Case |
| 16772 |
then |
| 16773 |
Body_Acts_As_Spec := False; |
| 16774 |
|
| 16775 |
-- If we have none of an instantiation, subprogram body or subprogram |
| 16776 |
-- declaration, or in the SPARK case, a variable reference, then |
| 16777 |
-- it is not a case that we want to check. (One case is a call to a |
| 16778 |
-- generic formal subprogram, where we do not want the check in the |
| 16779 |
-- template). |
| 16780 |
|
| 16781 |
else |
| 16782 |
return; |
| 16783 |
end if; |
| 16784 |
end if; |
| 16785 |
|
| 16786 |
E_Scope := Ent; |
| 16787 |
loop |
| 16788 |
if Elaboration_Checks_Suppressed (E_Scope) |
| 16789 |
or else Suppress_Elaboration_Warnings (E_Scope) |
| 16790 |
then |
| 16791 |
Cunit_SC := True; |
| 16792 |
end if; |
| 16793 |
|
| 16794 |
-- Exit when we get to compilation unit, not counting subunits |
| 16795 |
|
| 16796 |
exit when Is_Compilation_Unit (E_Scope) |
| 16797 |
and then (Is_Child_Unit (E_Scope) |
| 16798 |
or else Scope (E_Scope) = Standard_Standard); |
| 16799 |
|
| 16800 |
pragma Assert (E_Scope /= Standard_Standard); |
| 16801 |
|
| 16802 |
-- Move up a scope looking for compilation unit |
| 16803 |
|
| 16804 |
E_Scope := Scope (E_Scope); |
| 16805 |
end loop; |
| 16806 |
|
| 16807 |
-- No checks needed for pure or preelaborated compilation units |
| 16808 |
|
| 16809 |
if Is_Pure (E_Scope) or else Is_Preelaborated (E_Scope) then |
| 16810 |
return; |
| 16811 |
end if; |
| 16812 |
|
| 16813 |
-- If the generic entity is within a deeper instance than we are, then |
| 16814 |
-- either the instantiation to which we refer itself caused an ABE, in |
| 16815 |
-- which case that will be handled separately, or else we know that the |
| 16816 |
-- body we need appears as needed at the point of the instantiation. |
| 16817 |
-- However, this assumption is only valid if we are in static mode. |
| 16818 |
|
| 16819 |
if not Dynamic_Elaboration_Checks |
| 16820 |
and then |
| 16821 |
Instantiation_Depth (Sloc (Ent)) > Instantiation_Depth (Sloc (N)) |
| 16822 |
then |
| 16823 |
return; |
| 16824 |
end if; |
| 16825 |
|
| 16826 |
-- Do not give a warning for a package with no body |
| 16827 |
|
| 16828 |
if Ekind (Ent) = E_Generic_Package and then not Has_Generic_Body (N) then |
| 16829 |
return; |
| 16830 |
end if; |
| 16831 |
|
| 16832 |
-- Case of entity is in same unit as call or instantiation. In the |
| 16833 |
-- instantiation case, W_Scope may be different from E_Scope; we want |
| 16834 |
-- the unit in which the instantiation occurs, since we're analyzing |
| 16835 |
-- based on the expansion. |
| 16836 |
|
| 16837 |
if W_Scope = C_Scope then |
| 16838 |
if not Inter_Unit_Only then |
| 16839 |
Check_Internal_Call (N, Ent, Outer_Scope, E); |
| 16840 |
end if; |
| 16841 |
|
| 16842 |
return; |
| 16843 |
end if; |
| 16844 |
|
| 16845 |
-- Case of entity is not in current unit (i.e. with'ed unit case) |
| 16846 |
|
| 16847 |
-- We are only interested in such calls if the outer call was from |
| 16848 |
-- elaboration code, or if we are in Dynamic_Elaboration_Checks mode. |
| 16849 |
|
| 16850 |
if not From_Elab_Code and then not Dynamic_Elaboration_Checks then |
| 16851 |
return; |
| 16852 |
end if; |
| 16853 |
|
| 16854 |
-- Nothing to do if some scope said that no checks were required |
| 16855 |
|
| 16856 |
if Cunit_SC then |
| 16857 |
return; |
| 16858 |
end if; |
| 16859 |
|
| 16860 |
-- Nothing to do for a generic instance, because a call to an instance |
| 16861 |
-- cannot fail the elaboration check, because the body of the instance |
| 16862 |
-- is always elaborated immediately after the spec. |
| 16863 |
|
| 16864 |
if Call_To_Instance_From_Outside (Ent) then |
| 16865 |
return; |
| 16866 |
end if; |
| 16867 |
|
| 16868 |
-- Nothing to do if subprogram with no separate spec. However, a call |
| 16869 |
-- to Deep_Initialize may result in a call to a user-defined Initialize |
| 16870 |
-- procedure, which imposes a body dependency. This happens only if the |
| 16871 |
-- type is controlled and the Initialize procedure is not inherited. |
| 16872 |
|
| 16873 |
if Body_Acts_As_Spec then |
| 16874 |
if Is_TSS (Ent, TSS_Deep_Initialize) then |
| 16875 |
declare |
| 16876 |
Typ : constant Entity_Id := Etype (First_Formal (Ent)); |
| 16877 |
Init : Entity_Id; |
| 16878 |
|
| 16879 |
begin |
| 16880 |
if not Is_Controlled (Typ) then |
| 16881 |
return; |
| 16882 |
else |
| 16883 |
Init := Find_Controlled_Prim_Op (Typ, Name_Initialize); |
| 16884 |
|
| 16885 |
if Comes_From_Source (Init) then |
| 16886 |
Ent := Init; |
| 16887 |
else |
| 16888 |
return; |
| 16889 |
end if; |
| 16890 |
end if; |
| 16891 |
end; |
| 16892 |
|
| 16893 |
else |
| 16894 |
return; |
| 16895 |
end if; |
| 16896 |
end if; |
| 16897 |
|
| 16898 |
-- Check cases of internal units |
| 16899 |
|
| 16900 |
Callee_Unit_Internal := In_Internal_Unit (E_Scope); |
| 16901 |
|
| 16902 |
-- Do not give a warning if the with'ed unit is internal and this is |
| 16903 |
-- the generic instantiation case (this saves a lot of hassle dealing |
| 16904 |
-- with the Text_IO special child units) |
| 16905 |
|
| 16906 |
if Callee_Unit_Internal and Inst_Case then |
| 16907 |
return; |
| 16908 |
end if; |
| 16909 |
|
| 16910 |
if C_Scope = Standard_Standard then |
| 16911 |
Caller_Unit_Internal := False; |
| 16912 |
else |
| 16913 |
Caller_Unit_Internal := In_Internal_Unit (C_Scope); |
| 16914 |
end if; |
| 16915 |
|
| 16916 |
-- Do not give a warning if the with'ed unit is internal and the caller |
| 16917 |
-- is not internal (since the binder always elaborates internal units |
| 16918 |
-- first). |
| 16919 |
|
| 16920 |
if Callee_Unit_Internal and not Caller_Unit_Internal then |
| 16921 |
return; |
| 16922 |
end if; |
| 16923 |
|
| 16924 |
-- For now, if debug flag -gnatdE is not set, do no checking for one |
| 16925 |
-- internal unit withing another. This fixes the problem with the sgi |
| 16926 |
-- build and storage errors. To be resolved later ??? |
| 16927 |
|
| 16928 |
if (Callee_Unit_Internal and Caller_Unit_Internal) |
| 16929 |
and not Debug_Flag_EE |
| 16930 |
then |
| 16931 |
return; |
| 16932 |
end if; |
| 16933 |
|
| 16934 |
if Is_TSS (E, TSS_Deep_Initialize) then |
| 16935 |
Ent := E; |
| 16936 |
end if; |
| 16937 |
|
| 16938 |
-- If the call is in an instance, and the called entity is not |
| 16939 |
-- defined in the same instance, then the elaboration issue focuses |
| 16940 |
-- around the unit containing the template, it is this unit that |
| 16941 |
-- requires an Elaborate_All. |
| 16942 |
|
| 16943 |
-- However, if we are doing dynamic elaboration, we need to chase the |
| 16944 |
-- call in the usual manner. |
| 16945 |
|
| 16946 |
-- We also need to chase the call in the usual manner if it is a call |
| 16947 |
-- to a generic formal parameter, since that case was not handled as |
| 16948 |
-- part of the processing of the template. |
| 16949 |
|
| 16950 |
Inst_Caller := Instantiation (Get_Source_File_Index (Sloc (N))); |
| 16951 |
Inst_Callee := Instantiation (Get_Source_File_Index (Sloc (Ent))); |
| 16952 |
|
| 16953 |
if Inst_Caller = No_Location then |
| 16954 |
Unit_Caller := No_Unit; |
| 16955 |
else |
| 16956 |
Unit_Caller := Get_Source_Unit (N); |
| 16957 |
end if; |
| 16958 |
|
| 16959 |
if Inst_Callee = No_Location then |
| 16960 |
Unit_Callee := No_Unit; |
| 16961 |
else |
| 16962 |
Unit_Callee := Get_Source_Unit (Ent); |
| 16963 |
end if; |
| 16964 |
|
| 16965 |
if Unit_Caller /= No_Unit |
| 16966 |
and then Unit_Callee /= Unit_Caller |
| 16967 |
and then not Dynamic_Elaboration_Checks |
| 16968 |
and then not Is_Call_Of_Generic_Formal (N) |
| 16969 |
then |
| 16970 |
E_Scope := Spec_Entity (Cunit_Entity (Unit_Caller)); |
| 16971 |
|
| 16972 |
-- If we don't get a spec entity, just ignore call. Not quite |
| 16973 |
-- clear why this check is necessary. ??? |
| 16974 |
|
| 16975 |
if No (E_Scope) then |
| 16976 |
return; |
| 16977 |
end if; |
| 16978 |
|
| 16979 |
-- Otherwise step to enclosing compilation unit |
| 16980 |
|
| 16981 |
while not Is_Compilation_Unit (E_Scope) loop |
| 16982 |
E_Scope := Scope (E_Scope); |
| 16983 |
end loop; |
| 16984 |
|
| 16985 |
-- For the case where N is not an instance, and is not a call within |
| 16986 |
-- instance to other than a generic formal, we recompute E_Scope |
| 16987 |
-- for the error message, since we do NOT want to go to the unit |
| 16988 |
-- that has the ultimate declaration in the case of renaming and |
| 16989 |
-- derivation and we also want to go to the generic unit in the |
| 16990 |
-- case of an instance, and no further. |
| 16991 |
|
| 16992 |
else |
| 16993 |
-- Loop to carefully follow renamings and derivations one step |
| 16994 |
-- outside the current unit, but not further. |
| 16995 |
|
| 16996 |
if not (Inst_Case or Variable_Case) |
| 16997 |
and then Present (Alias (Ent)) |
| 16998 |
then |
| 16999 |
E_Scope := Alias (Ent); |
| 17000 |
else |
| 17001 |
E_Scope := Ent; |
| 17002 |
end if; |
| 17003 |
|
| 17004 |
loop |
| 17005 |
while not Is_Compilation_Unit (E_Scope) loop |
| 17006 |
E_Scope := Scope (E_Scope); |
| 17007 |
end loop; |
| 17008 |
|
| 17009 |
-- If E_Scope is the same as C_Scope, it means that there |
| 17010 |
-- definitely was a local renaming or derivation, and we |
| 17011 |
-- are not yet out of the current unit. |
| 17012 |
|
| 17013 |
exit when E_Scope /= C_Scope; |
| 17014 |
Ent := Alias (Ent); |
| 17015 |
E_Scope := Ent; |
| 17016 |
|
| 17017 |
-- If no alias, there could be a previous error, but not if we've |
| 17018 |
-- already reached the outermost level (Standard). |
| 17019 |
|
| 17020 |
if No (Ent) then |
| 17021 |
return; |
| 17022 |
end if; |
| 17023 |
end loop; |
| 17024 |
end if; |
| 17025 |
|
| 17026 |
if Within_Elaborate_All (Current_Sem_Unit, E_Scope) then |
| 17027 |
return; |
| 17028 |
end if; |
| 17029 |
|
| 17030 |
-- Determine whether the Default_Initial_Condition procedure of some |
| 17031 |
-- type is being invoked. |
| 17032 |
|
| 17033 |
Is_DIC := Ekind (Ent) = E_Procedure and then Is_DIC_Procedure (Ent); |
| 17034 |
|
| 17035 |
-- Checks related to Default_Initial_Condition fall under the SPARK |
| 17036 |
-- umbrella because this is a SPARK-specific annotation. |
| 17037 |
|
| 17038 |
SPARK_Elab_Errors := |
| 17039 |
SPARK_Mode = On and (Is_DIC or Dynamic_Elaboration_Checks); |
| 17040 |
|
| 17041 |
-- Now check if an Elaborate_All (or dynamic check) is needed |
| 17042 |
|
| 17043 |
if (Elab_Info_Messages or Elab_Warnings or SPARK_Elab_Errors) |
| 17044 |
and then Generate_Warnings |
| 17045 |
and then not Suppress_Elaboration_Warnings (Ent) |
| 17046 |
and then not Elaboration_Checks_Suppressed (Ent) |
| 17047 |
and then not Suppress_Elaboration_Warnings (E_Scope) |
| 17048 |
and then not Elaboration_Checks_Suppressed (E_Scope) |
| 17049 |
then |
| 17050 |
-- Instantiation case |
| 17051 |
|
| 17052 |
if Inst_Case then |
| 17053 |
if Comes_From_Source (Ent) and then SPARK_Elab_Errors then |
| 17054 |
Error_Msg_NE |
| 17055 |
("instantiation of & during elaboration in SPARK", N, Ent); |
| 17056 |
else |
| 17057 |
Elab_Warning |
| 17058 |
("instantiation of & may raise Program_Error?l?", |
| 17059 |
"info: instantiation of & during elaboration?$?", Ent); |
| 17060 |
end if; |
| 17061 |
|
| 17062 |
-- Indirect call case, info message only in static elaboration |
| 17063 |
-- case, because the attribute reference itself cannot raise an |
| 17064 |
-- exception. Note that SPARK does not permit indirect calls. |
| 17065 |
|
| 17066 |
elsif Access_Case then |
| 17067 |
Elab_Warning ("", "info: access to & during elaboration?$?", Ent); |
| 17068 |
|
| 17069 |
-- Variable reference in SPARK mode |
| 17070 |
|
| 17071 |
elsif Variable_Case then |
| 17072 |
if Comes_From_Source (Ent) and then SPARK_Elab_Errors then |
| 17073 |
Error_Msg_NE |
| 17074 |
("reference to & during elaboration in SPARK", N, Ent); |
| 17075 |
end if; |
| 17076 |
|
| 17077 |
-- Subprogram call case |
| 17078 |
|
| 17079 |
else |
| 17080 |
if Nkind (Name (N)) in N_Has_Entity |
| 17081 |
and then Is_Init_Proc (Entity (Name (N))) |
| 17082 |
and then Comes_From_Source (Ent) |
| 17083 |
then |
| 17084 |
Elab_Warning |
| 17085 |
("implicit call to & may raise Program_Error?l?", |
| 17086 |
"info: implicit call to & during elaboration?$?", |
| 17087 |
Ent); |
| 17088 |
|
| 17089 |
elsif SPARK_Elab_Errors then |
| 17090 |
|
| 17091 |
-- Emit a specialized error message when the elaboration of an |
| 17092 |
-- object of a private type evaluates the expression of pragma |
| 17093 |
-- Default_Initial_Condition. This prevents the internal name |
| 17094 |
-- of the procedure from appearing in the error message. |
| 17095 |
|
| 17096 |
if Is_DIC then |
| 17097 |
Error_Msg_N |
| 17098 |
("call to Default_Initial_Condition during elaboration in " |
| 17099 |
& "SPARK", N); |
| 17100 |
else |
| 17101 |
Error_Msg_NE |
| 17102 |
("call to & during elaboration in SPARK", N, Ent); |
| 17103 |
end if; |
| 17104 |
|
| 17105 |
else |
| 17106 |
Elab_Warning |
| 17107 |
("call to & may raise Program_Error?l?", |
| 17108 |
"info: call to & during elaboration?$?", |
| 17109 |
Ent); |
| 17110 |
end if; |
| 17111 |
end if; |
| 17112 |
|
| 17113 |
Error_Msg_Qual_Level := Nat'Last; |
| 17114 |
|
| 17115 |
-- Case of Elaborate_All not present and required, for SPARK this |
| 17116 |
-- is an error, so give an error message. |
| 17117 |
|
| 17118 |
if SPARK_Elab_Errors then |
| 17119 |
Error_Msg_NE -- CODEFIX |
| 17120 |
("\Elaborate_All pragma required for&", N, W_Scope); |
| 17121 |
|
| 17122 |
-- Otherwise we generate an implicit pragma. For a subprogram |
| 17123 |
-- instantiation, Elaborate is good enough, since no transitive |
| 17124 |
-- call is possible at elaboration time in this case. |
| 17125 |
|
| 17126 |
elsif Nkind (N) in N_Subprogram_Instantiation then |
| 17127 |
Elab_Warning |
| 17128 |
("\missing pragma Elaborate for&?l?", |
| 17129 |
"\implicit pragma Elaborate for& generated?$?", |
| 17130 |
W_Scope); |
| 17131 |
|
| 17132 |
-- For all other cases, we need an implicit Elaborate_All |
| 17133 |
|
| 17134 |
else |
| 17135 |
Elab_Warning |
| 17136 |
("\missing pragma Elaborate_All for&?l?", |
| 17137 |
"\implicit pragma Elaborate_All for & generated?$?", |
| 17138 |
W_Scope); |
| 17139 |
end if; |
| 17140 |
|
| 17141 |
Error_Msg_Qual_Level := 0; |
| 17142 |
|
| 17143 |
-- Take into account the flags related to elaboration warning |
| 17144 |
-- messages when enumerating the various calls involved. This |
| 17145 |
-- ensures the proper pairing of the main warning and the |
| 17146 |
-- clarification messages generated by Output_Calls. |
| 17147 |
|
| 17148 |
Output_Calls (N, Check_Elab_Flag => True); |
| 17149 |
|
| 17150 |
-- Set flag to prevent further warnings for same unit unless in |
| 17151 |
-- All_Errors_Mode. |
| 17152 |
|
| 17153 |
if not All_Errors_Mode and not Dynamic_Elaboration_Checks then |
| 17154 |
Set_Suppress_Elaboration_Warnings (W_Scope); |
| 17155 |
end if; |
| 17156 |
end if; |
| 17157 |
|
| 17158 |
-- Check for runtime elaboration check required |
| 17159 |
|
| 17160 |
if Dynamic_Elaboration_Checks then |
| 17161 |
if not Elaboration_Checks_Suppressed (Ent) |
| 17162 |
and then not Elaboration_Checks_Suppressed (W_Scope) |
| 17163 |
and then not Elaboration_Checks_Suppressed (E_Scope) |
| 17164 |
and then not Cunit_SC |
| 17165 |
then |
| 17166 |
-- Runtime elaboration check required. Generate check of the |
| 17167 |
-- elaboration Boolean for the unit containing the entity. |
| 17168 |
|
| 17169 |
-- Note that for this case, we do check the real unit (the one |
| 17170 |
-- from following renamings, since that is the issue). |
| 17171 |
|
| 17172 |
-- Could this possibly miss a useless but required PE??? |
| 17173 |
|
| 17174 |
Insert_Elab_Check (N, |
| 17175 |
Make_Attribute_Reference (Loc, |
| 17176 |
Attribute_Name => Name_Elaborated, |
| 17177 |
Prefix => |
| 17178 |
New_Occurrence_Of (Spec_Entity (E_Scope), Loc))); |
| 17179 |
|
| 17180 |
-- Prevent duplicate elaboration checks on the same call, which |
| 17181 |
-- can happen if the body enclosing the call appears itself in a |
| 17182 |
-- call whose elaboration check is delayed. |
| 17183 |
|
| 17184 |
if Nkind (N) in N_Subprogram_Call then |
| 17185 |
Set_No_Elaboration_Check (N); |
| 17186 |
end if; |
| 17187 |
end if; |
| 17188 |
|
| 17189 |
-- Case of static elaboration model |
| 17190 |
|
| 17191 |
else |
| 17192 |
-- Do not do anything if elaboration checks suppressed. Note that |
| 17193 |
-- we check Ent here, not E, since we want the real entity for the |
| 17194 |
-- body to see if checks are suppressed for it, not the dummy |
| 17195 |
-- entry for renamings or derivations. |
| 17196 |
|
| 17197 |
if Elaboration_Checks_Suppressed (Ent) |
| 17198 |
or else Elaboration_Checks_Suppressed (E_Scope) |
| 17199 |
or else Elaboration_Checks_Suppressed (W_Scope) |
| 17200 |
then |
| 17201 |
null; |
| 17202 |
|
| 17203 |
-- Do not generate an Elaborate_All for finalization routines |
| 17204 |
-- that perform partial clean up as part of initialization. |
| 17205 |
|
| 17206 |
elsif In_Init_Proc and then Is_Finalization_Procedure (Ent) then |
| 17207 |
null; |
| 17208 |
|
| 17209 |
-- Here we need to generate an implicit elaborate all |
| 17210 |
|
| 17211 |
else |
| 17212 |
-- Generate Elaborate_All warning unless suppressed |
| 17213 |
|
| 17214 |
if (Elab_Info_Messages and Generate_Warnings and not Inst_Case) |
| 17215 |
and then not Suppress_Elaboration_Warnings (Ent) |
| 17216 |
and then not Suppress_Elaboration_Warnings (E_Scope) |
| 17217 |
and then not Suppress_Elaboration_Warnings (W_Scope) |
| 17218 |
then |
| 17219 |
Error_Msg_Node_2 := W_Scope; |
| 17220 |
Error_Msg_NE |
| 17221 |
("info: call to& in elaboration code requires pragma " |
| 17222 |
& "Elaborate_All on&?$?", N, E); |
| 17223 |
end if; |
| 17224 |
|
| 17225 |
-- Set indication for binder to generate Elaborate_All |
| 17226 |
|
| 17227 |
Set_Elaboration_Constraint (N, E, W_Scope); |
| 17228 |
end if; |
| 17229 |
end if; |
| 17230 |
end Check_A_Call; |
| 17231 |
|
| 17232 |
----------------------------- |
| 17233 |
-- Check_Bad_Instantiation -- |
| 17234 |
----------------------------- |
| 17235 |
|
| 17236 |
procedure Check_Bad_Instantiation (N : Node_Id) is |
| 17237 |
Ent : Entity_Id; |
| 17238 |
|
| 17239 |
begin |
| 17240 |
-- Nothing to do if we do not have an instantiation (happens in some |
| 17241 |
-- error cases, and also in the formal package declaration case) |
| 17242 |
|
| 17243 |
if Nkind (N) not in N_Generic_Instantiation then |
| 17244 |
return; |
| 17245 |
|
| 17246 |
-- Nothing to do if serious errors detected (avoid cascaded errors) |
| 17247 |
|
| 17248 |
elsif Serious_Errors_Detected /= 0 then |
| 17249 |
return; |
| 17250 |
|
| 17251 |
-- Nothing to do if not in full analysis mode |
| 17252 |
|
| 17253 |
elsif not Full_Analysis then |
| 17254 |
return; |
| 17255 |
|
| 17256 |
-- Nothing to do if inside a generic template |
| 17257 |
|
| 17258 |
elsif Inside_A_Generic then |
| 17259 |
return; |
| 17260 |
|
| 17261 |
-- Nothing to do if a library level instantiation |
| 17262 |
|
| 17263 |
elsif Nkind (Parent (N)) = N_Compilation_Unit then |
| 17264 |
return; |
| 17265 |
|
| 17266 |
-- Nothing to do if we are compiling a proper body for semantic |
| 17267 |
-- purposes only. The generic body may be in another proper body. |
| 17268 |
|
| 17269 |
elsif |
| 17270 |
Nkind (Parent (Unit_Declaration_Node (Main_Unit_Entity))) = N_Subunit |
| 17271 |
then |
| 17272 |
return; |
| 17273 |
end if; |
| 17274 |
|
| 17275 |
Ent := Get_Generic_Entity (N); |
| 17276 |
|
| 17277 |
-- The case we are interested in is when the generic spec is in the |
| 17278 |
-- current declarative part |
| 17279 |
|
| 17280 |
if not Same_Elaboration_Scope (Current_Scope, Scope (Ent)) |
| 17281 |
or else not In_Same_Extended_Unit (N, Ent) |
| 17282 |
then |
| 17283 |
return; |
| 17284 |
end if; |
| 17285 |
|
| 17286 |
-- If the generic entity is within a deeper instance than we are, then |
| 17287 |
-- either the instantiation to which we refer itself caused an ABE, in |
| 17288 |
-- which case that will be handled separately. Otherwise, we know that |
| 17289 |
-- the body we need appears as needed at the point of the instantiation. |
| 17290 |
-- If they are both at the same level but not within the same instance |
| 17291 |
-- then the body of the generic will be in the earlier instance. |
| 17292 |
|
| 17293 |
declare |
| 17294 |
D1 : constant Nat := Instantiation_Depth (Sloc (Ent)); |
| 17295 |
D2 : constant Nat := Instantiation_Depth (Sloc (N)); |
| 17296 |
|
| 17297 |
begin |
| 17298 |
if D1 > D2 then |
| 17299 |
return; |
| 17300 |
|
| 17301 |
elsif D1 = D2 |
| 17302 |
and then Is_Generic_Instance (Scope (Ent)) |
| 17303 |
and then not In_Open_Scopes (Scope (Ent)) |
| 17304 |
then |
| 17305 |
return; |
| 17306 |
end if; |
| 17307 |
end; |
| 17308 |
|
| 17309 |
-- Now we can proceed, if the entity being called has a completion, |
| 17310 |
-- then we are definitely OK, since we have already seen the body. |
| 17311 |
|
| 17312 |
if Has_Completion (Ent) then |
| 17313 |
return; |
| 17314 |
end if; |
| 17315 |
|
| 17316 |
-- If there is no body, then nothing to do |
| 17317 |
|
| 17318 |
if not Has_Generic_Body (N) then |
| 17319 |
return; |
| 17320 |
end if; |
| 17321 |
|
| 17322 |
-- Here we definitely have a bad instantiation |
| 17323 |
|
| 17324 |
Error_Msg_Warn := SPARK_Mode /= On; |
| 17325 |
Error_Msg_NE ("cannot instantiate& before body seen<<", N, Ent); |
| 17326 |
Error_Msg_N ("\Program_Error [<<", N); |
| 17327 |
|
| 17328 |
Insert_Elab_Check (N); |
| 17329 |
Set_Is_Known_Guaranteed_ABE (N); |
| 17330 |
end Check_Bad_Instantiation; |
| 17331 |
|
| 17332 |
--------------------- |
| 17333 |
-- Check_Elab_Call -- |
| 17334 |
--------------------- |
| 17335 |
|
| 17336 |
procedure Check_Elab_Call |
| 17337 |
(N : Node_Id; |
| 17338 |
Outer_Scope : Entity_Id := Empty; |
| 17339 |
In_Init_Proc : Boolean := False) |
| 17340 |
is |
| 17341 |
Ent : Entity_Id; |
| 17342 |
P : Node_Id; |
| 17343 |
|
| 17344 |
begin |
| 17345 |
pragma Assert (Legacy_Elaboration_Checks); |
| 17346 |
|
| 17347 |
-- If the reference is not in the main unit, there is nothing to check. |
| 17348 |
-- Elaboration call from units in the context of the main unit will lead |
| 17349 |
-- to semantic dependencies when those units are compiled. |
| 17350 |
|
| 17351 |
if not In_Extended_Main_Code_Unit (N) then |
| 17352 |
return; |
| 17353 |
end if; |
| 17354 |
|
| 17355 |
-- For an entry call, check relevant restriction |
| 17356 |
|
| 17357 |
if Nkind (N) = N_Entry_Call_Statement |
| 17358 |
and then not In_Subprogram_Or_Concurrent_Unit |
| 17359 |
then |
| 17360 |
Check_Restriction (No_Entry_Calls_In_Elaboration_Code, N); |
| 17361 |
|
| 17362 |
-- Nothing to do if this is not an expected type of reference (happens |
| 17363 |
-- in some error conditions, and in some cases where rewriting occurs). |
| 17364 |
|
| 17365 |
elsif Nkind (N) not in N_Subprogram_Call |
| 17366 |
and then Nkind (N) /= N_Attribute_Reference |
| 17367 |
and then (SPARK_Mode /= On |
| 17368 |
or else Nkind (N) not in N_Has_Entity |
| 17369 |
or else No (Entity (N)) |
| 17370 |
or else Ekind (Entity (N)) /= E_Variable) |
| 17371 |
then |
| 17372 |
return; |
| 17373 |
|
| 17374 |
-- Nothing to do if this is a call already rewritten for elab checking. |
| 17375 |
-- Such calls appear as the targets of If_Expressions. |
| 17376 |
|
| 17377 |
-- This check MUST be wrong, it catches far too much |
| 17378 |
|
| 17379 |
elsif Nkind (Parent (N)) = N_If_Expression then |
| 17380 |
return; |
| 17381 |
|
| 17382 |
-- Nothing to do if inside a generic template |
| 17383 |
|
| 17384 |
elsif Inside_A_Generic |
| 17385 |
and then No (Enclosing_Generic_Body (N)) |
| 17386 |
then |
| 17387 |
return; |
| 17388 |
|
| 17389 |
-- Nothing to do if call is being preanalyzed, as when within a |
| 17390 |
-- pre/postcondition, a predicate, or an invariant. |
| 17391 |
|
| 17392 |
elsif Preanalysis_Active then |
| 17393 |
return; |
| 17394 |
end if; |
| 17395 |
|
| 17396 |
-- Nothing to do if this is a call to a postcondition, which is always |
| 17397 |
-- within a subprogram body, even though the current scope may be the |
| 17398 |
-- enclosing scope of the subprogram. |
| 17399 |
|
| 17400 |
if Nkind (N) = N_Procedure_Call_Statement |
| 17401 |
and then Is_Entity_Name (Name (N)) |
| 17402 |
and then Chars (Entity (Name (N))) = Name_uWrapped_Statements |
| 17403 |
then |
| 17404 |
return; |
| 17405 |
end if; |
| 17406 |
|
| 17407 |
-- Here we have a reference at elaboration time that must be checked |
| 17408 |
|
| 17409 |
if Debug_Flag_Underscore_LL then |
| 17410 |
Write_Str (" Check_Elab_Ref: "); |
| 17411 |
|
| 17412 |
if Nkind (N) = N_Attribute_Reference then |
| 17413 |
if not Is_Entity_Name (Prefix (N)) then |
| 17414 |
Write_Str ("<<not entity name>>"); |
| 17415 |
else |
| 17416 |
Write_Name (Chars (Entity (Prefix (N)))); |
| 17417 |
end if; |
| 17418 |
|
| 17419 |
Write_Str ("'Access"); |
| 17420 |
|
| 17421 |
elsif No (Name (N)) or else not Is_Entity_Name (Name (N)) then |
| 17422 |
Write_Str ("<<not entity name>> "); |
| 17423 |
|
| 17424 |
else |
| 17425 |
Write_Name (Chars (Entity (Name (N)))); |
| 17426 |
end if; |
| 17427 |
|
| 17428 |
Write_Str (" reference at "); |
| 17429 |
Write_Location (Sloc (N)); |
| 17430 |
Write_Eol; |
| 17431 |
end if; |
| 17432 |
|
| 17433 |
-- Climb up the tree to make sure we are not inside default expression |
| 17434 |
-- of a parameter specification or a record component, since in both |
| 17435 |
-- these cases, we will be doing the actual reference later, not now, |
| 17436 |
-- and it is at the time of the actual reference (statically speaking) |
| 17437 |
-- that we must do our static check, not at the time of its initial |
| 17438 |
-- analysis). |
| 17439 |
|
| 17440 |
-- However, we have to check references within component definitions |
| 17441 |
-- (e.g. a function call that determines an array component bound), |
| 17442 |
-- so we terminate the loop in that case. |
| 17443 |
|
| 17444 |
P := Parent (N); |
| 17445 |
while Present (P) loop |
| 17446 |
if Nkind (P) in N_Parameter_Specification | N_Component_Declaration |
| 17447 |
then |
| 17448 |
return; |
| 17449 |
|
| 17450 |
-- The reference occurs within the constraint of a component, |
| 17451 |
-- so it must be checked. |
| 17452 |
|
| 17453 |
elsif Nkind (P) = N_Component_Definition then |
| 17454 |
exit; |
| 17455 |
|
| 17456 |
else |
| 17457 |
P := Parent (P); |
| 17458 |
end if; |
| 17459 |
end loop; |
| 17460 |
|
| 17461 |
-- Stuff that happens only at the outer level |
| 17462 |
|
| 17463 |
if No (Outer_Scope) then |
| 17464 |
Elab_Visited.Set_Last (0); |
| 17465 |
|
| 17466 |
-- Nothing to do if current scope is Standard (this is a bit odd, but |
| 17467 |
-- it happens in the case of generic instantiations). |
| 17468 |
|
| 17469 |
C_Scope := Current_Scope; |
| 17470 |
|
| 17471 |
if C_Scope = Standard_Standard then |
| 17472 |
return; |
| 17473 |
end if; |
| 17474 |
|
| 17475 |
-- First case, we are in elaboration code |
| 17476 |
|
| 17477 |
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit; |
| 17478 |
|
| 17479 |
if From_Elab_Code then |
| 17480 |
|
| 17481 |
-- Complain if ref that comes from source in preelaborated unit |
| 17482 |
-- and we are not inside a subprogram (i.e. we are in elab code). |
| 17483 |
|
| 17484 |
-- Ada 2022 (AI12-0175): Calls to certain functions that are |
| 17485 |
-- essentially unchecked conversions are preelaborable. |
| 17486 |
|
| 17487 |
if Comes_From_Source (N) |
| 17488 |
and then In_Preelaborated_Unit |
| 17489 |
and then not In_Inlined_Body |
| 17490 |
and then Nkind (N) /= N_Attribute_Reference |
| 17491 |
and then not (Ada_Version >= Ada_2022 |
| 17492 |
and then Is_Preelaborable_Construct (N)) |
| 17493 |
then |
| 17494 |
Error_Preelaborated_Call (N); |
| 17495 |
return; |
| 17496 |
end if; |
| 17497 |
|
| 17498 |
-- Second case, we are inside a subprogram or concurrent unit, which |
| 17499 |
-- means we are not in elaboration code. |
| 17500 |
|
| 17501 |
else |
| 17502 |
-- In this case, the issue is whether we are inside the |
| 17503 |
-- declarative part of the unit in which we live, or inside its |
| 17504 |
-- statements. In the latter case, there is no issue of ABE calls |
| 17505 |
-- at this level (a call from outside to the unit in which we live |
| 17506 |
-- might cause an ABE, but that will be detected when we analyze |
| 17507 |
-- that outer level call, as it recurses into the called unit). |
| 17508 |
|
| 17509 |
-- Climb up the tree, doing this test, and also testing for being |
| 17510 |
-- inside a default expression, which, as discussed above, is not |
| 17511 |
-- checked at this stage. |
| 17512 |
|
| 17513 |
declare |
| 17514 |
P : Node_Id; |
| 17515 |
L : List_Id; |
| 17516 |
|
| 17517 |
begin |
| 17518 |
P := N; |
| 17519 |
loop |
| 17520 |
-- If we find a parentless subtree, it seems safe to assume |
| 17521 |
-- that we are not in a declarative part and that no |
| 17522 |
-- checking is required. |
| 17523 |
|
| 17524 |
if No (P) then |
| 17525 |
return; |
| 17526 |
end if; |
| 17527 |
|
| 17528 |
if Is_List_Member (P) then |
| 17529 |
L := List_Containing (P); |
| 17530 |
P := Parent (L); |
| 17531 |
else |
| 17532 |
L := No_List; |
| 17533 |
P := Parent (P); |
| 17534 |
end if; |
| 17535 |
|
| 17536 |
exit when Nkind (P) = N_Subunit; |
| 17537 |
|
| 17538 |
-- Filter out case of default expressions, where we do not |
| 17539 |
-- do the check at this stage. |
| 17540 |
|
| 17541 |
if Nkind (P) in |
| 17542 |
N_Parameter_Specification | N_Component_Declaration |
| 17543 |
then |
| 17544 |
return; |
| 17545 |
end if; |
| 17546 |
|
| 17547 |
-- A protected body has no elaboration code and contains |
| 17548 |
-- only other bodies. |
| 17549 |
|
| 17550 |
if Nkind (P) = N_Protected_Body then |
| 17551 |
return; |
| 17552 |
|
| 17553 |
elsif Nkind (P) in N_Subprogram_Body |
| 17554 |
| N_Task_Body |
| 17555 |
| N_Block_Statement |
| 17556 |
| N_Entry_Body |
| 17557 |
then |
| 17558 |
if L = Declarations (P) then |
| 17559 |
exit; |
| 17560 |
|
| 17561 |
-- We are not in elaboration code, but we are doing |
| 17562 |
-- dynamic elaboration checks, in this case, we still |
| 17563 |
-- need to do the reference, since the subprogram we are |
| 17564 |
-- in could be called from another unit, also in dynamic |
| 17565 |
-- elaboration check mode, at elaboration time. |
| 17566 |
|
| 17567 |
elsif Dynamic_Elaboration_Checks then |
| 17568 |
|
| 17569 |
-- We provide a debug flag to disable this check. That |
| 17570 |
-- way we have an easy work around for regressions |
| 17571 |
-- that are caused by this new check. This debug flag |
| 17572 |
-- can be removed later. |
| 17573 |
|
| 17574 |
if Debug_Flag_DD then |
| 17575 |
return; |
| 17576 |
end if; |
| 17577 |
|
| 17578 |
-- Do the check in this case |
| 17579 |
|
| 17580 |
exit; |
| 17581 |
|
| 17582 |
elsif Nkind (P) = N_Task_Body then |
| 17583 |
|
| 17584 |
-- The check is deferred until Check_Task_Activation |
| 17585 |
-- but we need to capture local suppress pragmas |
| 17586 |
-- that may inhibit checks on this call. |
| 17587 |
|
| 17588 |
Ent := Get_Referenced_Ent (N); |
| 17589 |
|
| 17590 |
if No (Ent) then |
| 17591 |
return; |
| 17592 |
|
| 17593 |
elsif Elaboration_Checks_Suppressed (Current_Scope) |
| 17594 |
or else Elaboration_Checks_Suppressed (Ent) |
| 17595 |
or else Elaboration_Checks_Suppressed (Scope (Ent)) |
| 17596 |
then |
| 17597 |
if Nkind (N) in N_Subprogram_Call then |
| 17598 |
Set_No_Elaboration_Check (N); |
| 17599 |
end if; |
| 17600 |
end if; |
| 17601 |
|
| 17602 |
return; |
| 17603 |
|
| 17604 |
-- Static model, call is not in elaboration code, we |
| 17605 |
-- never need to worry, because in the static model the |
| 17606 |
-- top-level caller always takes care of things. |
| 17607 |
|
| 17608 |
else |
| 17609 |
return; |
| 17610 |
end if; |
| 17611 |
end if; |
| 17612 |
end loop; |
| 17613 |
end; |
| 17614 |
end if; |
| 17615 |
end if; |
| 17616 |
|
| 17617 |
Ent := Get_Referenced_Ent (N); |
| 17618 |
|
| 17619 |
if No (Ent) then |
| 17620 |
return; |
| 17621 |
end if; |
| 17622 |
|
| 17623 |
-- Determine whether a prior call to the same subprogram was already |
| 17624 |
-- examined within the same context. If this is the case, then there is |
| 17625 |
-- no need to proceed with the various warnings and checks because the |
| 17626 |
-- work was already done for the previous call. |
| 17627 |
|
| 17628 |
declare |
| 17629 |
Self : constant Visited_Element := |
| 17630 |
(Subp_Id => Ent, Context => Parent (N)); |
| 17631 |
|
| 17632 |
begin |
| 17633 |
for Index in 1 .. Elab_Visited.Last loop |
| 17634 |
if Self = Elab_Visited.Table (Index) then |
| 17635 |
return; |
| 17636 |
end if; |
| 17637 |
end loop; |
| 17638 |
end; |
| 17639 |
|
| 17640 |
-- See if we need to analyze this reference. We analyze it if either of |
| 17641 |
-- the following conditions is met: |
| 17642 |
|
| 17643 |
-- It is an inner level call (since in this case it was triggered |
| 17644 |
-- by an outer level call from elaboration code), but only if the |
| 17645 |
-- call is within the scope of the original outer level call. |
| 17646 |
|
| 17647 |
-- It is an outer level reference from elaboration code, or a call to |
| 17648 |
-- an entity is in the same elaboration scope. |
| 17649 |
|
| 17650 |
-- And in these cases, we will check both inter-unit calls and |
| 17651 |
-- intra-unit (within a single unit) calls. |
| 17652 |
|
| 17653 |
C_Scope := Current_Scope; |
| 17654 |
|
| 17655 |
-- If not outer level reference, then we follow it if it is within the |
| 17656 |
-- original scope of the outer reference. |
| 17657 |
|
| 17658 |
if Present (Outer_Scope) |
| 17659 |
and then Within (Scope (Ent), Outer_Scope) |
| 17660 |
then |
| 17661 |
Set_C_Scope; |
| 17662 |
Check_A_Call |
| 17663 |
(N => N, |
| 17664 |
E => Ent, |
| 17665 |
Outer_Scope => Outer_Scope, |
| 17666 |
Inter_Unit_Only => False, |
| 17667 |
In_Init_Proc => In_Init_Proc); |
| 17668 |
|
| 17669 |
-- Nothing to do if elaboration checks suppressed for this scope. |
| 17670 |
-- However, an interesting exception, the fact that elaboration checks |
| 17671 |
-- are suppressed within an instance (because we can trace the body when |
| 17672 |
-- we process the template) does not extend to calls to generic formal |
| 17673 |
-- subprograms. |
| 17674 |
|
| 17675 |
elsif Elaboration_Checks_Suppressed (Current_Scope) |
| 17676 |
and then not Is_Call_Of_Generic_Formal (N) |
| 17677 |
then |
| 17678 |
null; |
| 17679 |
|
| 17680 |
elsif From_Elab_Code then |
| 17681 |
Set_C_Scope; |
| 17682 |
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False); |
| 17683 |
|
| 17684 |
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then |
| 17685 |
Set_C_Scope; |
| 17686 |
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False); |
| 17687 |
|
| 17688 |
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode |
| 17689 |
-- is set, then we will do the check, but only in the inter-unit case |
| 17690 |
-- (this is to accommodate unguarded elaboration calls from other units |
| 17691 |
-- in which this same mode is set). We don't want warnings in this case, |
| 17692 |
-- it would generate warnings having nothing to do with elaboration. |
| 17693 |
|
| 17694 |
elsif Dynamic_Elaboration_Checks then |
| 17695 |
Set_C_Scope; |
| 17696 |
Check_A_Call |
| 17697 |
(N, |
| 17698 |
Ent, |
| 17699 |
Standard_Standard, |
| 17700 |
Inter_Unit_Only => True, |
| 17701 |
Generate_Warnings => False); |
| 17702 |
|
| 17703 |
-- Otherwise nothing to do |
| 17704 |
|
| 17705 |
else |
| 17706 |
return; |
| 17707 |
end if; |
| 17708 |
|
| 17709 |
-- A call to an Init_Proc in elaboration code may bring additional |
| 17710 |
-- dependencies, if some of the record components thereof have |
| 17711 |
-- initializations that are function calls that come from source. We |
| 17712 |
-- treat the current node as a call to each of these functions, to check |
| 17713 |
-- their elaboration impact. |
| 17714 |
|
| 17715 |
if Is_Init_Proc (Ent) and then From_Elab_Code then |
| 17716 |
Process_Init_Proc : declare |
| 17717 |
Unit_Decl : constant Node_Id := Unit_Declaration_Node (Ent); |
| 17718 |
|
| 17719 |
function Check_Init_Call (Nod : Node_Id) return Traverse_Result; |
| 17720 |
-- Find subprogram calls within body of Init_Proc for Traverse |
| 17721 |
-- instantiation below. |
| 17722 |
|
| 17723 |
procedure Traverse_Body is new Traverse_Proc (Check_Init_Call); |
| 17724 |
-- Traversal procedure to find all calls with body of Init_Proc |
| 17725 |
|
| 17726 |
--------------------- |
| 17727 |
-- Check_Init_Call -- |
| 17728 |
--------------------- |
| 17729 |
|
| 17730 |
function Check_Init_Call (Nod : Node_Id) return Traverse_Result is |
| 17731 |
Func : Entity_Id; |
| 17732 |
|
| 17733 |
begin |
| 17734 |
if Nkind (Nod) in N_Subprogram_Call |
| 17735 |
and then Is_Entity_Name (Name (Nod)) |
| 17736 |
then |
| 17737 |
Func := Entity (Name (Nod)); |
| 17738 |
|
| 17739 |
if Comes_From_Source (Func) then |
| 17740 |
Check_A_Call |
| 17741 |
(N, Func, Standard_Standard, Inter_Unit_Only => True); |
| 17742 |
end if; |
| 17743 |
|
| 17744 |
return OK; |
| 17745 |
|
| 17746 |
else |
| 17747 |
return OK; |
| 17748 |
end if; |
| 17749 |
end Check_Init_Call; |
| 17750 |
|
| 17751 |
-- Start of processing for Process_Init_Proc |
| 17752 |
|
| 17753 |
begin |
| 17754 |
if Nkind (Unit_Decl) = N_Subprogram_Body then |
| 17755 |
Traverse_Body (Handled_Statement_Sequence (Unit_Decl)); |
| 17756 |
end if; |
| 17757 |
end Process_Init_Proc; |
| 17758 |
end if; |
| 17759 |
end Check_Elab_Call; |
| 17760 |
|
| 17761 |
----------------------- |
| 17762 |
-- Check_Elab_Assign -- |
| 17763 |
----------------------- |
| 17764 |
|
| 17765 |
procedure Check_Elab_Assign (N : Node_Id) is |
| 17766 |
Ent : Entity_Id; |
| 17767 |
Scop : Entity_Id; |
| 17768 |
|
| 17769 |
Pkg_Spec : Entity_Id; |
| 17770 |
Pkg_Body : Entity_Id; |
| 17771 |
|
| 17772 |
begin |
| 17773 |
pragma Assert (Legacy_Elaboration_Checks); |
| 17774 |
|
| 17775 |
-- For record or array component, check prefix. If it is an access type, |
| 17776 |
-- then there is nothing to do (we do not know what is being assigned), |
| 17777 |
-- but otherwise this is an assignment to the prefix. |
| 17778 |
|
| 17779 |
if Nkind (N) in N_Indexed_Component | N_Selected_Component | N_Slice then |
| 17780 |
if not Is_Access_Type (Etype (Prefix (N))) then |
| 17781 |
Check_Elab_Assign (Prefix (N)); |
| 17782 |
end if; |
| 17783 |
|
| 17784 |
return; |
| 17785 |
end if; |
| 17786 |
|
| 17787 |
-- For type conversion, check expression |
| 17788 |
|
| 17789 |
if Nkind (N) = N_Type_Conversion then |
| 17790 |
Check_Elab_Assign (Expression (N)); |
| 17791 |
return; |
| 17792 |
end if; |
| 17793 |
|
| 17794 |
-- Nothing to do if this is not an entity reference otherwise get entity |
| 17795 |
|
| 17796 |
if Is_Entity_Name (N) then |
| 17797 |
Ent := Entity (N); |
| 17798 |
else |
| 17799 |
return; |
| 17800 |
end if; |
| 17801 |
|
| 17802 |
-- What we are looking for is a reference in the body of a package that |
| 17803 |
-- modifies a variable declared in the visible part of the package spec. |
| 17804 |
|
| 17805 |
if Present (Ent) |
| 17806 |
and then Comes_From_Source (N) |
| 17807 |
and then not Suppress_Elaboration_Warnings (Ent) |
| 17808 |
and then Ekind (Ent) = E_Variable |
| 17809 |
and then not In_Private_Part (Ent) |
| 17810 |
and then Is_Library_Level_Entity (Ent) |
| 17811 |
then |
| 17812 |
Scop := Current_Scope; |
| 17813 |
loop |
| 17814 |
if No (Scop) or else Scop = Standard_Standard then |
| 17815 |
return; |
| 17816 |
elsif Ekind (Scop) = E_Package |
| 17817 |
and then Is_Compilation_Unit (Scop) |
| 17818 |
then |
| 17819 |
exit; |
| 17820 |
else |
| 17821 |
Scop := Scope (Scop); |
| 17822 |
end if; |
| 17823 |
end loop; |
| 17824 |
|
| 17825 |
-- Here Scop points to the containing library package |
| 17826 |
|
| 17827 |
Pkg_Spec := Scop; |
| 17828 |
Pkg_Body := Body_Entity (Pkg_Spec); |
| 17829 |
|
| 17830 |
-- All OK if the package has an Elaborate_Body pragma |
| 17831 |
|
| 17832 |
if Has_Pragma_Elaborate_Body (Scop) then |
| 17833 |
return; |
| 17834 |
end if; |
| 17835 |
|
| 17836 |
-- OK if entity being modified is not in containing package spec |
| 17837 |
|
| 17838 |
if not In_Same_Source_Unit (Scop, Ent) then |
| 17839 |
return; |
| 17840 |
end if; |
| 17841 |
|
| 17842 |
-- All OK if entity appears in generic package or generic instance. |
| 17843 |
-- We just get too messed up trying to give proper warnings in the |
| 17844 |
-- presence of generics. Better no message than a junk one. |
| 17845 |
|
| 17846 |
Scop := Scope (Ent); |
| 17847 |
while Present (Scop) and then Scop /= Pkg_Spec loop |
| 17848 |
if Ekind (Scop) = E_Generic_Package then |
| 17849 |
return; |
| 17850 |
elsif Ekind (Scop) = E_Package |
| 17851 |
and then Is_Generic_Instance (Scop) |
| 17852 |
then |
| 17853 |
return; |
| 17854 |
end if; |
| 17855 |
|
| 17856 |
Scop := Scope (Scop); |
| 17857 |
end loop; |
| 17858 |
|
| 17859 |
-- All OK if in task, don't issue warnings there |
| 17860 |
|
| 17861 |
if In_Task_Activation then |
| 17862 |
return; |
| 17863 |
end if; |
| 17864 |
|
| 17865 |
-- OK if no package body |
| 17866 |
|
| 17867 |
if No (Pkg_Body) then |
| 17868 |
return; |
| 17869 |
end if; |
| 17870 |
|
| 17871 |
-- OK if reference is not in package body |
| 17872 |
|
| 17873 |
if not In_Same_Source_Unit (Pkg_Body, N) then |
| 17874 |
return; |
| 17875 |
end if; |
| 17876 |
|
| 17877 |
-- OK if package body has no handled statement sequence |
| 17878 |
|
| 17879 |
declare |
| 17880 |
HSS : constant Node_Id := |
| 17881 |
Handled_Statement_Sequence (Declaration_Node (Pkg_Body)); |
| 17882 |
begin |
| 17883 |
if No (HSS) or else not Comes_From_Source (HSS) then |
| 17884 |
return; |
| 17885 |
end if; |
| 17886 |
end; |
| 17887 |
|
| 17888 |
-- We definitely have a case of a modification of an entity in |
| 17889 |
-- the package spec from the elaboration code of the package body. |
| 17890 |
-- We may not give the warning (because there are some additional |
| 17891 |
-- checks to avoid too many false positives), but it would be a good |
| 17892 |
-- idea for the binder to try to keep the body elaboration close to |
| 17893 |
-- the spec elaboration. |
| 17894 |
|
| 17895 |
Set_Elaborate_Body_Desirable (Pkg_Spec); |
| 17896 |
|
| 17897 |
-- All OK in gnat mode (we know what we are doing) |
| 17898 |
|
| 17899 |
if GNAT_Mode then |
| 17900 |
return; |
| 17901 |
end if; |
| 17902 |
|
| 17903 |
-- All OK if all warnings suppressed |
| 17904 |
|
| 17905 |
if Warning_Mode = Suppress then |
| 17906 |
return; |
| 17907 |
end if; |
| 17908 |
|
| 17909 |
-- All OK if elaboration checks suppressed for entity |
| 17910 |
|
| 17911 |
if Checks_May_Be_Suppressed (Ent) |
| 17912 |
and then Is_Check_Suppressed (Ent, Elaboration_Check) |
| 17913 |
then |
| 17914 |
return; |
| 17915 |
end if; |
| 17916 |
|
| 17917 |
-- OK if the entity is initialized. Note that the No_Initialization |
| 17918 |
-- flag usually means that the initialization has been rewritten into |
| 17919 |
-- assignments, but that still counts for us. |
| 17920 |
|
| 17921 |
declare |
| 17922 |
Decl : constant Node_Id := Declaration_Node (Ent); |
| 17923 |
begin |
| 17924 |
if Nkind (Decl) = N_Object_Declaration |
| 17925 |
and then (Present (Expression (Decl)) |
| 17926 |
or else No_Initialization (Decl)) |
| 17927 |
then |
| 17928 |
return; |
| 17929 |
end if; |
| 17930 |
end; |
| 17931 |
|
| 17932 |
-- Here is where we give the warning |
| 17933 |
|
| 17934 |
-- All OK if warnings suppressed on the entity |
| 17935 |
|
| 17936 |
if not Has_Warnings_Off (Ent) then |
| 17937 |
Error_Msg_Sloc := Sloc (Ent); |
| 17938 |
|
| 17939 |
Error_Msg_NE |
| 17940 |
("??& can be accessed by clients before this initialization", |
| 17941 |
N, Ent); |
| 17942 |
Error_Msg_NE |
| 17943 |
("\??add Elaborate_Body to spec to ensure & is initialized", |
| 17944 |
N, Ent); |
| 17945 |
end if; |
| 17946 |
|
| 17947 |
if not All_Errors_Mode then |
| 17948 |
Set_Suppress_Elaboration_Warnings (Ent); |
| 17949 |
end if; |
| 17950 |
end if; |
| 17951 |
end Check_Elab_Assign; |
| 17952 |
|
| 17953 |
---------------------- |
| 17954 |
-- Check_Elab_Calls -- |
| 17955 |
---------------------- |
| 17956 |
|
| 17957 |
-- WARNING: This routine manages SPARK regions |
| 17958 |
|
| 17959 |
procedure Check_Elab_Calls is |
| 17960 |
Saved_SM : SPARK_Mode_Type; |
| 17961 |
Saved_SMP : Node_Id; |
| 17962 |
|
| 17963 |
begin |
| 17964 |
pragma Assert (Legacy_Elaboration_Checks); |
| 17965 |
|
| 17966 |
-- If expansion is disabled, do not generate any checks, unless we |
| 17967 |
-- are in GNATprove mode, so that errors are issued in GNATprove for |
| 17968 |
-- violations of static elaboration rules in SPARK code. Also skip |
| 17969 |
-- checks if any subunits are missing because in either case we lack the |
| 17970 |
-- full information that we need, and no object file will be created in |
| 17971 |
-- any case. |
| 17972 |
|
| 17973 |
if (not Expander_Active and not GNATprove_Mode) |
| 17974 |
or else Is_Generic_Unit (Cunit_Entity (Main_Unit)) |
| 17975 |
or else Subunits_Missing |
| 17976 |
then |
| 17977 |
return; |
| 17978 |
end if; |
| 17979 |
|
| 17980 |
-- Skip delayed calls if we had any errors |
| 17981 |
|
| 17982 |
if Serious_Errors_Detected = 0 then |
| 17983 |
Delaying_Elab_Checks := False; |
| 17984 |
Expander_Mode_Save_And_Set (True); |
| 17985 |
|
| 17986 |
for J in Delay_Check.First .. Delay_Check.Last loop |
| 17987 |
Push_Scope (Delay_Check.Table (J).Curscop); |
| 17988 |
From_Elab_Code := Delay_Check.Table (J).From_Elab_Code; |
| 17989 |
In_Task_Activation := Delay_Check.Table (J).In_Task_Activation; |
| 17990 |
|
| 17991 |
Saved_SM := SPARK_Mode; |
| 17992 |
Saved_SMP := SPARK_Mode_Pragma; |
| 17993 |
|
| 17994 |
-- Set appropriate value of SPARK_Mode |
| 17995 |
|
| 17996 |
if Delay_Check.Table (J).From_SPARK_Code then |
| 17997 |
SPARK_Mode := On; |
| 17998 |
end if; |
| 17999 |
|
| 18000 |
Check_Internal_Call_Continue |
| 18001 |
(N => Delay_Check.Table (J).N, |
| 18002 |
E => Delay_Check.Table (J).E, |
| 18003 |
Outer_Scope => Delay_Check.Table (J).Outer_Scope, |
| 18004 |
Orig_Ent => Delay_Check.Table (J).Orig_Ent); |
| 18005 |
|
| 18006 |
Restore_SPARK_Mode (Saved_SM, Saved_SMP); |
| 18007 |
Pop_Scope; |
| 18008 |
end loop; |
| 18009 |
|
| 18010 |
-- Set Delaying_Elab_Checks back on for next main compilation |
| 18011 |
|
| 18012 |
Expander_Mode_Restore; |
| 18013 |
Delaying_Elab_Checks := True; |
| 18014 |
end if; |
| 18015 |
end Check_Elab_Calls; |
| 18016 |
|
| 18017 |
------------------------------ |
| 18018 |
-- Check_Elab_Instantiation -- |
| 18019 |
------------------------------ |
| 18020 |
|
| 18021 |
procedure Check_Elab_Instantiation |
| 18022 |
(N : Node_Id; |
| 18023 |
Outer_Scope : Entity_Id := Empty) |
| 18024 |
is |
| 18025 |
Ent : Entity_Id; |
| 18026 |
|
| 18027 |
begin |
| 18028 |
pragma Assert (Legacy_Elaboration_Checks); |
| 18029 |
|
| 18030 |
-- Check for and deal with bad instantiation case. There is some |
| 18031 |
-- duplicated code here, but we will worry about this later ??? |
| 18032 |
|
| 18033 |
Check_Bad_Instantiation (N); |
| 18034 |
|
| 18035 |
if Is_Known_Guaranteed_ABE (N) then |
| 18036 |
return; |
| 18037 |
end if; |
| 18038 |
|
| 18039 |
-- Nothing to do if we do not have an instantiation (happens in some |
| 18040 |
-- error cases, and also in the formal package declaration case) |
| 18041 |
|
| 18042 |
if Nkind (N) not in N_Generic_Instantiation then |
| 18043 |
return; |
| 18044 |
end if; |
| 18045 |
|
| 18046 |
-- Nothing to do if inside a generic template |
| 18047 |
|
| 18048 |
if Inside_A_Generic then |
| 18049 |
return; |
| 18050 |
end if; |
| 18051 |
|
| 18052 |
-- Nothing to do if the instantiation is not in the main unit |
| 18053 |
|
| 18054 |
if not In_Extended_Main_Code_Unit (N) then |
| 18055 |
return; |
| 18056 |
end if; |
| 18057 |
|
| 18058 |
Ent := Get_Generic_Entity (N); |
| 18059 |
From_Elab_Code := not In_Subprogram_Or_Concurrent_Unit; |
| 18060 |
|
| 18061 |
-- See if we need to analyze this instantiation. We analyze it if |
| 18062 |
-- either of the following conditions is met: |
| 18063 |
|
| 18064 |
-- It is an inner level instantiation (since in this case it was |
| 18065 |
-- triggered by an outer level call from elaboration code), but |
| 18066 |
-- only if the instantiation is within the scope of the original |
| 18067 |
-- outer level call. |
| 18068 |
|
| 18069 |
-- It is an outer level instantiation from elaboration code, or the |
| 18070 |
-- instantiated entity is in the same elaboration scope. |
| 18071 |
|
| 18072 |
-- And in these cases, we will check both the inter-unit case and |
| 18073 |
-- the intra-unit (within a single unit) case. |
| 18074 |
|
| 18075 |
C_Scope := Current_Scope; |
| 18076 |
|
| 18077 |
if Present (Outer_Scope) and then Within (Scope (Ent), Outer_Scope) then |
| 18078 |
Set_C_Scope; |
| 18079 |
Check_A_Call (N, Ent, Outer_Scope, Inter_Unit_Only => False); |
| 18080 |
|
| 18081 |
elsif From_Elab_Code then |
| 18082 |
Set_C_Scope; |
| 18083 |
Check_A_Call (N, Ent, Standard_Standard, Inter_Unit_Only => False); |
| 18084 |
|
| 18085 |
elsif Same_Elaboration_Scope (C_Scope, Scope (Ent)) then |
| 18086 |
Set_C_Scope; |
| 18087 |
Check_A_Call (N, Ent, Scope (Ent), Inter_Unit_Only => False); |
| 18088 |
|
| 18089 |
-- If none of those cases holds, but Dynamic_Elaboration_Checks mode is |
| 18090 |
-- set, then we will do the check, but only in the inter-unit case (this |
| 18091 |
-- is to accommodate unguarded elaboration calls from other units in |
| 18092 |
-- which this same mode is set). We inhibit warnings in this case, since |
| 18093 |
-- this instantiation is not occurring in elaboration code. |
| 18094 |
|
| 18095 |
elsif Dynamic_Elaboration_Checks then |
| 18096 |
Set_C_Scope; |
| 18097 |
Check_A_Call |
| 18098 |
(N, |
| 18099 |
Ent, |
| 18100 |
Standard_Standard, |
| 18101 |
Inter_Unit_Only => True, |
| 18102 |
Generate_Warnings => False); |
| 18103 |
|
| 18104 |
else |
| 18105 |
return; |
| 18106 |
end if; |
| 18107 |
end Check_Elab_Instantiation; |
| 18108 |
|
| 18109 |
------------------------- |
| 18110 |
-- Check_Internal_Call -- |
| 18111 |
------------------------- |
| 18112 |
|
| 18113 |
procedure Check_Internal_Call |
| 18114 |
(N : Node_Id; |
| 18115 |
E : Entity_Id; |
| 18116 |
Outer_Scope : Entity_Id; |
| 18117 |
Orig_Ent : Entity_Id) |
| 18118 |
is |
| 18119 |
function Within_Initial_Condition (Call : Node_Id) return Boolean; |
| 18120 |
-- Determine whether call Call occurs within pragma Initial_Condition or |
| 18121 |
-- pragma Check with check_kind set to Initial_Condition. |
| 18122 |
|
| 18123 |
------------------------------ |
| 18124 |
-- Within_Initial_Condition -- |
| 18125 |
------------------------------ |
| 18126 |
|
| 18127 |
function Within_Initial_Condition (Call : Node_Id) return Boolean is |
| 18128 |
Args : List_Id; |
| 18129 |
Nam : Name_Id; |
| 18130 |
Par : Node_Id; |
| 18131 |
|
| 18132 |
begin |
| 18133 |
-- Traverse the parent chain looking for an enclosing pragma |
| 18134 |
|
| 18135 |
Par := Call; |
| 18136 |
while Present (Par) loop |
| 18137 |
if Nkind (Par) = N_Pragma then |
| 18138 |
Nam := Pragma_Name (Par); |
| 18139 |
|
| 18140 |
-- Pragma Initial_Condition appears in its alternative from as |
| 18141 |
-- Check (Initial_Condition, ...). |
| 18142 |
|
| 18143 |
if Nam = Name_Check then |
| 18144 |
Args := Pragma_Argument_Associations (Par); |
| 18145 |
|
| 18146 |
-- Pragma Check should have at least two arguments |
| 18147 |
|
| 18148 |
pragma Assert (Present (Args)); |
| 18149 |
|
| 18150 |
return |
| 18151 |
Chars (Expression (First (Args))) = Name_Initial_Condition; |
| 18152 |
|
| 18153 |
-- Direct match |
| 18154 |
|
| 18155 |
elsif Nam = Name_Initial_Condition then |
| 18156 |
return True; |
| 18157 |
|
| 18158 |
-- Since pragmas are never nested within other pragmas, stop |
| 18159 |
-- the traversal. |
| 18160 |
|
| 18161 |
else |
| 18162 |
return False; |
| 18163 |
end if; |
| 18164 |
|
| 18165 |
-- Prevent the search from going too far |
| 18166 |
|
| 18167 |
elsif Is_Body_Or_Package_Declaration (Par) then |
| 18168 |
exit; |
| 18169 |
end if; |
| 18170 |
|
| 18171 |
Par := Parent (Par); |
| 18172 |
|
| 18173 |
-- If assertions are not enabled, the check pragma is rewritten |
| 18174 |
-- as an if_statement in sem_prag, to generate various warnings |
| 18175 |
-- on boolean expressions. Retrieve the original pragma. |
| 18176 |
|
| 18177 |
if Nkind (Original_Node (Par)) = N_Pragma then |
| 18178 |
Par := Original_Node (Par); |
| 18179 |
end if; |
| 18180 |
end loop; |
| 18181 |
|
| 18182 |
return False; |
| 18183 |
end Within_Initial_Condition; |
| 18184 |
|
| 18185 |
-- Local variables |
| 18186 |
|
| 18187 |
Inst_Case : constant Boolean := Nkind (N) in N_Generic_Instantiation; |
| 18188 |
|
| 18189 |
-- Start of processing for Check_Internal_Call |
| 18190 |
|
| 18191 |
begin |
| 18192 |
-- For P'Access, we want to warn if the -gnatw.f switch is set, and the |
| 18193 |
-- node comes from source. |
| 18194 |
|
| 18195 |
if Nkind (N) = N_Attribute_Reference |
| 18196 |
and then ((not Warn_On_Elab_Access and then not Debug_Flag_Dot_O) |
| 18197 |
or else not Comes_From_Source (N)) |
| 18198 |
then |
| 18199 |
return; |
| 18200 |
|
| 18201 |
-- If not function or procedure call, instantiation, or 'Access, then |
| 18202 |
-- ignore call (this happens in some error cases and rewriting cases). |
| 18203 |
|
| 18204 |
elsif Nkind (N) not in N_Attribute_Reference |
| 18205 |
| N_Function_Call |
| 18206 |
| N_Procedure_Call_Statement |
| 18207 |
and then not Inst_Case |
| 18208 |
then |
| 18209 |
return; |
| 18210 |
|
| 18211 |
-- Nothing to do if this is a call or instantiation that has already |
| 18212 |
-- been found to be a sure ABE. |
| 18213 |
|
| 18214 |
elsif Nkind (N) /= N_Attribute_Reference |
| 18215 |
and then Is_Known_Guaranteed_ABE (N) |
| 18216 |
then |
| 18217 |
return; |
| 18218 |
|
| 18219 |
-- Nothing to do if errors already detected (avoid cascaded errors) |
| 18220 |
|
| 18221 |
elsif Serious_Errors_Detected /= 0 then |
| 18222 |
return; |
| 18223 |
|
| 18224 |
-- Nothing to do if not in full analysis mode |
| 18225 |
|
| 18226 |
elsif not Full_Analysis then |
| 18227 |
return; |
| 18228 |
|
| 18229 |
-- Nothing to do if analyzing in special spec-expression mode, since the |
| 18230 |
-- call is not actually being made at this time. |
| 18231 |
|
| 18232 |
elsif In_Spec_Expression then |
| 18233 |
return; |
| 18234 |
|
| 18235 |
-- Nothing to do for call to intrinsic subprogram |
| 18236 |
|
| 18237 |
elsif Is_Intrinsic_Subprogram (E) then |
| 18238 |
return; |
| 18239 |
|
| 18240 |
-- Nothing to do if call is within a generic unit |
| 18241 |
|
| 18242 |
elsif Inside_A_Generic then |
| 18243 |
return; |
| 18244 |
|
| 18245 |
-- Nothing to do when the call appears within pragma Initial_Condition. |
| 18246 |
-- The pragma is part of the elaboration statements of a package body |
| 18247 |
-- and may only call external subprograms or subprograms whose body is |
| 18248 |
-- already available. |
| 18249 |
|
| 18250 |
elsif Within_Initial_Condition (N) then |
| 18251 |
return; |
| 18252 |
end if; |
| 18253 |
|
| 18254 |
-- Delay this call if we are still delaying calls |
| 18255 |
|
| 18256 |
if Delaying_Elab_Checks then |
| 18257 |
Delay_Check.Append |
| 18258 |
((N => N, |
| 18259 |
E => E, |
| 18260 |
Orig_Ent => Orig_Ent, |
| 18261 |
Curscop => Current_Scope, |
| 18262 |
Outer_Scope => Outer_Scope, |
| 18263 |
From_Elab_Code => From_Elab_Code, |
| 18264 |
In_Task_Activation => In_Task_Activation, |
| 18265 |
From_SPARK_Code => SPARK_Mode = On)); |
| 18266 |
return; |
| 18267 |
|
| 18268 |
-- Otherwise, call phase 2 continuation right now |
| 18269 |
|
| 18270 |
else |
| 18271 |
Check_Internal_Call_Continue (N, E, Outer_Scope, Orig_Ent); |
| 18272 |
end if; |
| 18273 |
end Check_Internal_Call; |
| 18274 |
|
| 18275 |
---------------------------------- |
| 18276 |
-- Check_Internal_Call_Continue -- |
| 18277 |
---------------------------------- |
| 18278 |
|
| 18279 |
procedure Check_Internal_Call_Continue |
| 18280 |
(N : Node_Id; |
| 18281 |
E : Entity_Id; |
| 18282 |
Outer_Scope : Entity_Id; |
| 18283 |
Orig_Ent : Entity_Id) |
| 18284 |
is |
| 18285 |
function Find_Elab_Reference (N : Node_Id) return Traverse_Result; |
| 18286 |
-- Function applied to each node as we traverse the body. Checks for |
| 18287 |
-- call or entity reference that needs checking, and if so checks it. |
| 18288 |
-- Always returns OK, so entire tree is traversed, except that as |
| 18289 |
-- described below subprogram bodies are skipped for now. |
| 18290 |
|
| 18291 |
procedure Traverse is new Atree.Traverse_Proc (Find_Elab_Reference); |
| 18292 |
-- Traverse procedure using above Find_Elab_Reference function |
| 18293 |
|
| 18294 |
------------------------- |
| 18295 |
-- Find_Elab_Reference -- |
| 18296 |
------------------------- |
| 18297 |
|
| 18298 |
function Find_Elab_Reference (N : Node_Id) return Traverse_Result is |
| 18299 |
Actual : Node_Id; |
| 18300 |
|
| 18301 |
begin |
| 18302 |
-- If user has specified that there are no entry calls in elaboration |
| 18303 |
-- code, do not trace past an accept statement, because the rendez- |
| 18304 |
-- vous will happen after elaboration. |
| 18305 |
|
| 18306 |
if Nkind (Original_Node (N)) in |
| 18307 |
N_Accept_Statement | N_Selective_Accept |
| 18308 |
and then Restriction_Active (No_Entry_Calls_In_Elaboration_Code) |
| 18309 |
then |
| 18310 |
return Abandon; |
| 18311 |
|
| 18312 |
-- If we have a function call, check it |
| 18313 |
|
| 18314 |
elsif Nkind (N) = N_Function_Call then |
| 18315 |
Check_Elab_Call (N, Outer_Scope); |
| 18316 |
return OK; |
| 18317 |
|
| 18318 |
-- If we have a procedure call, check the call, and also check |
| 18319 |
-- arguments that are assignments (OUT or IN OUT mode formals). |
| 18320 |
|
| 18321 |
elsif Nkind (N) = N_Procedure_Call_Statement then |
| 18322 |
Check_Elab_Call (N, Outer_Scope, In_Init_Proc => Is_Init_Proc (E)); |
| 18323 |
|
| 18324 |
Actual := First_Actual (N); |
| 18325 |
while Present (Actual) loop |
| 18326 |
if Known_To_Be_Assigned (Actual) then |
| 18327 |
Check_Elab_Assign (Actual); |
| 18328 |
end if; |
| 18329 |
|
| 18330 |
Next_Actual (Actual); |
| 18331 |
end loop; |
| 18332 |
|
| 18333 |
return OK; |
| 18334 |
|
| 18335 |
-- If we have an access attribute for a subprogram, check it. |
| 18336 |
-- Suppress this behavior under debug flag. |
| 18337 |
|
| 18338 |
elsif not Debug_Flag_Dot_UU |
| 18339 |
and then Nkind (N) = N_Attribute_Reference |
| 18340 |
and then |
| 18341 |
Attribute_Name (N) in Name_Access | Name_Unrestricted_Access |
| 18342 |
and then Is_Entity_Name (Prefix (N)) |
| 18343 |
and then Is_Subprogram (Entity (Prefix (N))) |
| 18344 |
then |
| 18345 |
Check_Elab_Call (N, Outer_Scope); |
| 18346 |
return OK; |
| 18347 |
|
| 18348 |
-- In SPARK mode, if we have an entity reference to a variable, then |
| 18349 |
-- check it. For now we consider any reference. |
| 18350 |
|
| 18351 |
elsif SPARK_Mode = On |
| 18352 |
and then Nkind (N) in N_Has_Entity |
| 18353 |
and then Present (Entity (N)) |
| 18354 |
and then Ekind (Entity (N)) = E_Variable |
| 18355 |
then |
| 18356 |
Check_Elab_Call (N, Outer_Scope); |
| 18357 |
return OK; |
| 18358 |
|
| 18359 |
-- If we have a generic instantiation, check it |
| 18360 |
|
| 18361 |
elsif Nkind (N) in N_Generic_Instantiation then |
| 18362 |
Check_Elab_Instantiation (N, Outer_Scope); |
| 18363 |
return OK; |
| 18364 |
|
| 18365 |
-- Skip subprogram bodies that come from source (wait for call to |
| 18366 |
-- analyze these). The reason for the come from source test is to |
| 18367 |
-- avoid catching task bodies. |
| 18368 |
|
| 18369 |
-- For task bodies, we should really avoid these too, waiting for the |
| 18370 |
-- task activation, but that's too much trouble to catch for now, so |
| 18371 |
-- we go in unconditionally. This is not so terrible, it means the |
| 18372 |
-- error backtrace is not quite complete, and we are too eager to |
| 18373 |
-- scan bodies of tasks that are unused, but this is hardly very |
| 18374 |
-- significant. |
| 18375 |
|
| 18376 |
elsif Nkind (N) = N_Subprogram_Body |
| 18377 |
and then Comes_From_Source (N) |
| 18378 |
then |
| 18379 |
return Skip; |
| 18380 |
|
| 18381 |
elsif Nkind (N) = N_Assignment_Statement |
| 18382 |
and then Comes_From_Source (N) |
| 18383 |
then |
| 18384 |
Check_Elab_Assign (Name (N)); |
| 18385 |
return OK; |
| 18386 |
|
| 18387 |
else |
| 18388 |
return OK; |
| 18389 |
end if; |
| 18390 |
end Find_Elab_Reference; |
| 18391 |
|
| 18392 |
Inst_Case : constant Boolean := Is_Generic_Unit (E); |
| 18393 |
Loc : constant Source_Ptr := Sloc (N); |
| 18394 |
|
| 18395 |
Ebody : Entity_Id; |
| 18396 |
Sbody : Node_Id; |
| 18397 |
|
| 18398 |
-- Start of processing for Check_Internal_Call_Continue |
| 18399 |
|
| 18400 |
begin |
| 18401 |
-- Save outer level call if at outer level |
| 18402 |
|
| 18403 |
if Elab_Call.Last = 0 then |
| 18404 |
Outer_Level_Sloc := Loc; |
| 18405 |
end if; |
| 18406 |
|
| 18407 |
-- If the call is to a function that renames a literal, no check needed |
| 18408 |
|
| 18409 |
if Ekind (E) = E_Enumeration_Literal then |
| 18410 |
return; |
| 18411 |
end if; |
| 18412 |
|
| 18413 |
-- Register the subprogram as examined within this particular context. |
| 18414 |
-- This ensures that calls to the same subprogram but in different |
| 18415 |
-- contexts receive warnings and checks of their own since the calls |
| 18416 |
-- may be reached through different flow paths. |
| 18417 |
|
| 18418 |
Elab_Visited.Append ((Subp_Id => E, Context => Parent (N))); |
| 18419 |
|
| 18420 |
Sbody := Unit_Declaration_Node (E); |
| 18421 |
|
| 18422 |
if Nkind (Sbody) not in N_Subprogram_Body | N_Package_Body then |
| 18423 |
Ebody := Corresponding_Body (Sbody); |
| 18424 |
|
| 18425 |
if No (Ebody) then |
| 18426 |
return; |
| 18427 |
else |
| 18428 |
Sbody := Unit_Declaration_Node (Ebody); |
| 18429 |
end if; |
| 18430 |
end if; |
| 18431 |
|
| 18432 |
-- If the body appears after the outer level call or instantiation then |
| 18433 |
-- we have an error case handled below. |
| 18434 |
|
| 18435 |
if Earlier_In_Extended_Unit (Outer_Level_Sloc, Sloc (Sbody)) |
| 18436 |
and then not In_Task_Activation |
| 18437 |
then |
| 18438 |
null; |
| 18439 |
|
| 18440 |
-- If we have the instantiation case we are done, since we now know that |
| 18441 |
-- the body of the generic appeared earlier. |
| 18442 |
|
| 18443 |
elsif Inst_Case then |
| 18444 |
return; |
| 18445 |
|
| 18446 |
-- Otherwise we have a call, so we trace through the called body to see |
| 18447 |
-- if it has any problems. |
| 18448 |
|
| 18449 |
else |
| 18450 |
pragma Assert (Nkind (Sbody) = N_Subprogram_Body); |
| 18451 |
|
| 18452 |
Elab_Call.Append ((Cloc => Loc, Ent => E)); |
| 18453 |
|
| 18454 |
if Debug_Flag_Underscore_LL then |
| 18455 |
Write_Str ("Elab_Call.Last = "); |
| 18456 |
Write_Int (Int (Elab_Call.Last)); |
| 18457 |
Write_Str (" Ent = "); |
| 18458 |
Write_Name (Chars (E)); |
| 18459 |
Write_Str (" at "); |
| 18460 |
Write_Location (Sloc (N)); |
| 18461 |
Write_Eol; |
| 18462 |
end if; |
| 18463 |
|
| 18464 |
-- Now traverse declarations and statements of subprogram body. Note |
| 18465 |
-- that we cannot simply Traverse (Sbody), since traverse does not |
| 18466 |
-- normally visit subprogram bodies. |
| 18467 |
|
| 18468 |
declare |
| 18469 |
Decl : Node_Id; |
| 18470 |
begin |
| 18471 |
Decl := First (Declarations (Sbody)); |
| 18472 |
while Present (Decl) loop |
| 18473 |
Traverse (Decl); |
| 18474 |
Next (Decl); |
| 18475 |
end loop; |
| 18476 |
end; |
| 18477 |
|
| 18478 |
Traverse (Handled_Statement_Sequence (Sbody)); |
| 18479 |
|
| 18480 |
Elab_Call.Decrement_Last; |
| 18481 |
return; |
| 18482 |
end if; |
| 18483 |
|
| 18484 |
-- Here is the case of calling a subprogram where the body has not yet |
| 18485 |
-- been encountered. A warning message is needed, except if this is the |
| 18486 |
-- case of appearing within an aspect specification that results in |
| 18487 |
-- a check call, we do not really have such a situation, so no warning |
| 18488 |
-- is needed (e.g. the case of a precondition, where the call appears |
| 18489 |
-- textually before the body, but in actual fact is moved to the |
| 18490 |
-- appropriate subprogram body and so does not need a check). |
| 18491 |
|
| 18492 |
declare |
| 18493 |
P : Node_Id; |
| 18494 |
O : Node_Id; |
| 18495 |
|
| 18496 |
begin |
| 18497 |
P := Parent (N); |
| 18498 |
loop |
| 18499 |
-- Keep looking at parents if we are still in the subexpression |
| 18500 |
|
| 18501 |
if Nkind (P) in N_Subexpr then |
| 18502 |
P := Parent (P); |
| 18503 |
|
| 18504 |
-- Here P is the parent of the expression, check for special case |
| 18505 |
|
| 18506 |
else |
| 18507 |
O := Original_Node (P); |
| 18508 |
|
| 18509 |
-- Definitely not the special case if orig node is not a pragma |
| 18510 |
|
| 18511 |
exit when Nkind (O) /= N_Pragma; |
| 18512 |
|
| 18513 |
-- Check we have an If statement or a null statement (happens |
| 18514 |
-- when the If has been expanded to be True). |
| 18515 |
|
| 18516 |
exit when Nkind (P) not in N_If_Statement | N_Null_Statement; |
| 18517 |
|
| 18518 |
-- Our special case will be indicated either by the pragma |
| 18519 |
-- coming from an aspect ... |
| 18520 |
|
| 18521 |
if Present (Corresponding_Aspect (O)) then |
| 18522 |
return; |
| 18523 |
|
| 18524 |
-- Or, in the case of an initial condition, specifically by a |
| 18525 |
-- Check pragma specifying an Initial_Condition check. |
| 18526 |
|
| 18527 |
elsif Pragma_Name (O) = Name_Check |
| 18528 |
and then |
| 18529 |
Chars |
| 18530 |
(Expression (First (Pragma_Argument_Associations (O)))) = |
| 18531 |
Name_Initial_Condition |
| 18532 |
then |
| 18533 |
return; |
| 18534 |
|
| 18535 |
-- For anything else, we have an error |
| 18536 |
|
| 18537 |
else |
| 18538 |
exit; |
| 18539 |
end if; |
| 18540 |
end if; |
| 18541 |
end loop; |
| 18542 |
end; |
| 18543 |
|
| 18544 |
-- Not that special case, warning and dynamic check is required |
| 18545 |
|
| 18546 |
-- If we have nothing in the call stack, then this is at the outer |
| 18547 |
-- level, and the ABE is bound to occur, unless it's a 'Access, or |
| 18548 |
-- it's a renaming. |
| 18549 |
|
| 18550 |
if Elab_Call.Last = 0 then |
| 18551 |
Error_Msg_Warn := SPARK_Mode /= On; |
| 18552 |
|
| 18553 |
declare |
| 18554 |
Insert_Check : Boolean := True; |
| 18555 |
-- This flag is set to True if an elaboration check should be |
| 18556 |
-- inserted. |
| 18557 |
|
| 18558 |
begin |
| 18559 |
if In_Task_Activation then |
| 18560 |
Insert_Check := False; |
| 18561 |
|
| 18562 |
elsif Inst_Case then |
| 18563 |
Error_Msg_NE |
| 18564 |
("cannot instantiate& before body seen<<", N, Orig_Ent); |
| 18565 |
|
| 18566 |
elsif Nkind (N) = N_Attribute_Reference then |
| 18567 |
Error_Msg_NE |
| 18568 |
("Access attribute of & before body seen<<", N, Orig_Ent); |
| 18569 |
Error_Msg_N |
| 18570 |
("\possible Program_Error on later references<<", N); |
| 18571 |
Insert_Check := False; |
| 18572 |
|
| 18573 |
elsif Nkind (Unit_Declaration_Node (Orig_Ent)) /= |
| 18574 |
N_Subprogram_Renaming_Declaration |
| 18575 |
or else Is_Generic_Actual_Subprogram (Orig_Ent) |
| 18576 |
then |
| 18577 |
Error_Msg_NE |
| 18578 |
("cannot call& before body seen<<", N, Orig_Ent); |
| 18579 |
else |
| 18580 |
Insert_Check := False; |
| 18581 |
end if; |
| 18582 |
|
| 18583 |
if Insert_Check then |
| 18584 |
Error_Msg_N ("\Program_Error [<<", N); |
| 18585 |
Insert_Elab_Check (N); |
| 18586 |
end if; |
| 18587 |
end; |
| 18588 |
|
| 18589 |
-- Call is not at outer level |
| 18590 |
|
| 18591 |
else |
| 18592 |
-- Do not generate elaboration checks in GNATprove mode because the |
| 18593 |
-- elaboration counter and the check are both forms of expansion. |
| 18594 |
|
| 18595 |
if GNATprove_Mode then |
| 18596 |
null; |
| 18597 |
|
| 18598 |
-- Generate an elaboration check |
| 18599 |
|
| 18600 |
elsif not Elaboration_Checks_Suppressed (E) then |
| 18601 |
Set_Elaboration_Entity_Required (E); |
| 18602 |
|
| 18603 |
-- Create a declaration of the elaboration entity, and insert it |
| 18604 |
-- prior to the subprogram or the generic unit, within the same |
| 18605 |
-- scope. Since the subprogram may be overloaded, create a unique |
| 18606 |
-- entity. |
| 18607 |
|
| 18608 |
if No (Elaboration_Entity (E)) then |
| 18609 |
declare |
| 18610 |
Loce : constant Source_Ptr := Sloc (E); |
| 18611 |
Ent : constant Entity_Id := |
| 18612 |
Make_Defining_Identifier (Loc, |
| 18613 |
New_External_Name (Chars (E), 'E', -1)); |
| 18614 |
|
| 18615 |
begin |
| 18616 |
Set_Elaboration_Entity (E, Ent); |
| 18617 |
Push_Scope (Scope (E)); |
| 18618 |
|
| 18619 |
Insert_Action (Declaration_Node (E), |
| 18620 |
Make_Object_Declaration (Loce, |
| 18621 |
Defining_Identifier => Ent, |
| 18622 |
Object_Definition => |
| 18623 |
New_Occurrence_Of (Standard_Short_Integer, Loce), |
| 18624 |
Expression => |
| 18625 |
Make_Integer_Literal (Loc, Uint_0))); |
| 18626 |
|
| 18627 |
-- Set elaboration flag at the point of the body |
| 18628 |
|
| 18629 |
Set_Elaboration_Flag (Sbody, E); |
| 18630 |
|
| 18631 |
-- Kill current value indication. This is necessary because |
| 18632 |
-- the tests of this flag are inserted out of sequence and |
| 18633 |
-- must not pick up bogus indications of the wrong constant |
| 18634 |
-- value. Also, this is never a true constant, since one way |
| 18635 |
-- or another, it gets reset. |
| 18636 |
|
| 18637 |
Set_Current_Value (Ent, Empty); |
| 18638 |
Set_Last_Assignment (Ent, Empty); |
| 18639 |
Set_Is_True_Constant (Ent, False); |
| 18640 |
Pop_Scope; |
| 18641 |
end; |
| 18642 |
end if; |
| 18643 |
|
| 18644 |
-- Generate: |
| 18645 |
-- if Enn = 0 then |
| 18646 |
-- raise Program_Error with "access before elaboration"; |
| 18647 |
-- end if; |
| 18648 |
|
| 18649 |
Insert_Elab_Check (N, |
| 18650 |
Make_Attribute_Reference (Loc, |
| 18651 |
Attribute_Name => Name_Elaborated, |
| 18652 |
Prefix => New_Occurrence_Of (E, Loc))); |
| 18653 |
end if; |
| 18654 |
|
| 18655 |
-- Generate the warning |
| 18656 |
|
| 18657 |
if not Suppress_Elaboration_Warnings (E) |
| 18658 |
and then not Elaboration_Checks_Suppressed (E) |
| 18659 |
|
| 18660 |
-- Suppress this warning if we have a function call that occurred |
| 18661 |
-- within an assertion expression, since we can get false warnings |
| 18662 |
-- in this case, due to the out of order handling in this case. |
| 18663 |
|
| 18664 |
and then |
| 18665 |
(Nkind (Original_Node (N)) /= N_Function_Call |
| 18666 |
or else not In_Assertion_Expression_Pragma (Original_Node (N))) |
| 18667 |
then |
| 18668 |
Error_Msg_Warn := SPARK_Mode /= On; |
| 18669 |
|
| 18670 |
if Inst_Case then |
| 18671 |
Error_Msg_NE |
| 18672 |
("instantiation of& may occur before body is seen<l<", |
| 18673 |
N, Orig_Ent); |
| 18674 |
else |
| 18675 |
-- A rather specific check: for Adjust/Finalize/Initialize, if |
| 18676 |
-- the type has Warnings_Off set, suppress the warning. |
| 18677 |
|
| 18678 |
if Is_Controlled_Procedure (E, Name_Adjust) |
| 18679 |
or else Is_Controlled_Procedure (E, Name_Finalize) |
| 18680 |
or else Is_Controlled_Procedure (E, Name_Initialize) |
| 18681 |
then |
| 18682 |
declare |
| 18683 |
T : constant Entity_Id := Etype (First_Formal (E)); |
| 18684 |
|
| 18685 |
begin |
| 18686 |
if Has_Warnings_Off (T) |
| 18687 |
or else (Ekind (T) = E_Private_Type |
| 18688 |
and then Has_Warnings_Off (Full_View (T))) |
| 18689 |
then |
| 18690 |
goto Output; |
| 18691 |
end if; |
| 18692 |
end; |
| 18693 |
end if; |
| 18694 |
|
| 18695 |
-- Go ahead and give warning if not this special case |
| 18696 |
|
| 18697 |
Error_Msg_NE |
| 18698 |
("call to& may occur before body is seen<l<", N, Orig_Ent); |
| 18699 |
end if; |
| 18700 |
|
| 18701 |
Error_Msg_N ("\Program_Error ]<l<", N); |
| 18702 |
|
| 18703 |
-- There is no need to query the elaboration warning message flags |
| 18704 |
-- because the main message is an error, not a warning, therefore |
| 18705 |
-- all the clarification messages produces by Output_Calls must be |
| 18706 |
-- emitted unconditionally. |
| 18707 |
|
| 18708 |
<<Output>> |
| 18709 |
|
| 18710 |
Output_Calls (N, Check_Elab_Flag => False); |
| 18711 |
end if; |
| 18712 |
end if; |
| 18713 |
end Check_Internal_Call_Continue; |
| 18714 |
|
| 18715 |
--------------------------- |
| 18716 |
-- Check_Task_Activation -- |
| 18717 |
--------------------------- |
| 18718 |
|
| 18719 |
procedure Check_Task_Activation (N : Node_Id) is |
| 18720 |
Loc : constant Source_Ptr := Sloc (N); |
| 18721 |
Inter_Procs : constant Elist_Id := New_Elmt_List; |
| 18722 |
Intra_Procs : constant Elist_Id := New_Elmt_List; |
| 18723 |
Ent : Entity_Id; |
| 18724 |
P : Entity_Id; |
| 18725 |
Task_Scope : Entity_Id; |
| 18726 |
Cunit_SC : Boolean := False; |
| 18727 |
Decl : Node_Id; |
| 18728 |
Elmt : Elmt_Id; |
| 18729 |
Enclosing : Entity_Id; |
| 18730 |
|
| 18731 |
procedure Add_Task_Proc (Typ : Entity_Id); |
| 18732 |
-- Add to Task_Procs the task body procedure(s) of task types in Typ. |
| 18733 |
-- For record types, this procedure recurses over component types. |
| 18734 |
|
| 18735 |
procedure Collect_Tasks (Decls : List_Id); |
| 18736 |
-- Collect the types of the tasks that are to be activated in the given |
| 18737 |
-- list of declarations, in order to perform elaboration checks on the |
| 18738 |
-- corresponding task procedures that are called implicitly here. |
| 18739 |
|
| 18740 |
function Outer_Unit (E : Entity_Id) return Entity_Id; |
| 18741 |
-- find enclosing compilation unit of Entity, ignoring subunits, or |
| 18742 |
-- else enclosing subprogram. If E is not a package, there is no need |
| 18743 |
-- for inter-unit elaboration checks. |
| 18744 |
|
| 18745 |
------------------- |
| 18746 |
-- Add_Task_Proc -- |
| 18747 |
------------------- |
| 18748 |
|
| 18749 |
procedure Add_Task_Proc (Typ : Entity_Id) is |
| 18750 |
Comp : Entity_Id; |
| 18751 |
Proc : Entity_Id := Empty; |
| 18752 |
|
| 18753 |
begin |
| 18754 |
if Is_Task_Type (Typ) then |
| 18755 |
Proc := Get_Task_Body_Procedure (Typ); |
| 18756 |
|
| 18757 |
elsif Is_Array_Type (Typ) |
| 18758 |
and then Has_Task (Base_Type (Typ)) |
| 18759 |
then |
| 18760 |
Add_Task_Proc (Component_Type (Typ)); |
| 18761 |
|
| 18762 |
elsif Is_Record_Type (Typ) |
| 18763 |
and then Has_Task (Base_Type (Typ)) |
| 18764 |
then |
| 18765 |
Comp := First_Component (Typ); |
| 18766 |
while Present (Comp) loop |
| 18767 |
Add_Task_Proc (Etype (Comp)); |
| 18768 |
Next_Component (Comp); |
| 18769 |
end loop; |
| 18770 |
end if; |
| 18771 |
|
| 18772 |
-- If the task type is another unit, we will perform the usual |
| 18773 |
-- elaboration check on its enclosing unit. If the type is in the |
| 18774 |
-- same unit, we can trace the task body as for an internal call, |
| 18775 |
-- but we only need to examine other external calls, because at |
| 18776 |
-- the point the task is activated, internal subprogram bodies |
| 18777 |
-- will have been elaborated already. We keep separate lists for |
| 18778 |
-- each kind of task. |
| 18779 |
|
| 18780 |
-- Skip this test if errors have occurred, since in this case |
| 18781 |
-- we can get false indications. |
| 18782 |
|
| 18783 |
if Serious_Errors_Detected /= 0 then |
| 18784 |
return; |
| 18785 |
end if; |
| 18786 |
|
| 18787 |
if Present (Proc) then |
| 18788 |
if Outer_Unit (Scope (Proc)) = Enclosing then |
| 18789 |
|
| 18790 |
if No (Corresponding_Body (Unit_Declaration_Node (Proc))) |
| 18791 |
and then |
| 18792 |
(not Is_Generic_Instance (Scope (Proc)) |
| 18793 |
or else Scope (Proc) = Scope (Defining_Identifier (Decl))) |
| 18794 |
then |
| 18795 |
Error_Msg_Warn := SPARK_Mode /= On; |
| 18796 |
Error_Msg_N |
| 18797 |
("task will be activated before elaboration of its body<<", |
| 18798 |
Decl); |
| 18799 |
Error_Msg_N ("\Program_Error [<<", Decl); |
| 18800 |
|
| 18801 |
elsif Present |
| 18802 |
(Corresponding_Body (Unit_Declaration_Node (Proc))) |
| 18803 |
then |
| 18804 |
Append_Elmt (Proc, Intra_Procs); |
| 18805 |
end if; |
| 18806 |
|
| 18807 |
else |
| 18808 |
-- No need for multiple entries of the same type |
| 18809 |
|
| 18810 |
Elmt := First_Elmt (Inter_Procs); |
| 18811 |
while Present (Elmt) loop |
| 18812 |
if Node (Elmt) = Proc then |
| 18813 |
return; |
| 18814 |
end if; |
| 18815 |
|
| 18816 |
Next_Elmt (Elmt); |
| 18817 |
end loop; |
| 18818 |
|
| 18819 |
Append_Elmt (Proc, Inter_Procs); |
| 18820 |
end if; |
| 18821 |
end if; |
| 18822 |
end Add_Task_Proc; |
| 18823 |
|
| 18824 |
------------------- |
| 18825 |
-- Collect_Tasks -- |
| 18826 |
------------------- |
| 18827 |
|
| 18828 |
procedure Collect_Tasks (Decls : List_Id) is |
| 18829 |
begin |
| 18830 |
Decl := First (Decls); |
| 18831 |
while Present (Decl) loop |
| 18832 |
if Nkind (Decl) = N_Object_Declaration |
| 18833 |
and then Has_Task (Etype (Defining_Identifier (Decl))) |
| 18834 |
then |
| 18835 |
Add_Task_Proc (Etype (Defining_Identifier (Decl))); |
| 18836 |
end if; |
| 18837 |
|
| 18838 |
Next (Decl); |
| 18839 |
end loop; |
| 18840 |
end Collect_Tasks; |
| 18841 |
|
| 18842 |
---------------- |
| 18843 |
-- Outer_Unit -- |
| 18844 |
---------------- |
| 18845 |
|
| 18846 |
function Outer_Unit (E : Entity_Id) return Entity_Id is |
| 18847 |
Outer : Entity_Id; |
| 18848 |
|
| 18849 |
begin |
| 18850 |
Outer := E; |
| 18851 |
while Present (Outer) loop |
| 18852 |
if Elaboration_Checks_Suppressed (Outer) then |
| 18853 |
Cunit_SC := True; |
| 18854 |
end if; |
| 18855 |
|
| 18856 |
exit when Is_Child_Unit (Outer) |
| 18857 |
or else Scope (Outer) = Standard_Standard |
| 18858 |
or else Ekind (Outer) /= E_Package; |
| 18859 |
Outer := Scope (Outer); |
| 18860 |
end loop; |
| 18861 |
|
| 18862 |
return Outer; |
| 18863 |
end Outer_Unit; |
| 18864 |
|
| 18865 |
-- Start of processing for Check_Task_Activation |
| 18866 |
|
| 18867 |
begin |
| 18868 |
pragma Assert (Legacy_Elaboration_Checks); |
| 18869 |
|
| 18870 |
Enclosing := Outer_Unit (Current_Scope); |
| 18871 |
|
| 18872 |
-- Find all tasks declared in the current unit |
| 18873 |
|
| 18874 |
if Nkind (N) = N_Package_Body then |
| 18875 |
P := Unit_Declaration_Node (Corresponding_Spec (N)); |
| 18876 |
|
| 18877 |
Collect_Tasks (Declarations (N)); |
| 18878 |
Collect_Tasks (Visible_Declarations (Specification (P))); |
| 18879 |
Collect_Tasks (Private_Declarations (Specification (P))); |
| 18880 |
|
| 18881 |
elsif Nkind (N) = N_Package_Declaration then |
| 18882 |
Collect_Tasks (Visible_Declarations (Specification (N))); |
| 18883 |
Collect_Tasks (Private_Declarations (Specification (N))); |
| 18884 |
|
| 18885 |
else |
| 18886 |
Collect_Tasks (Declarations (N)); |
| 18887 |
end if; |
| 18888 |
|
| 18889 |
-- We only perform detailed checks in all tasks that are library level |
| 18890 |
-- entities. If the master is a subprogram or task, activation will |
| 18891 |
-- depend on the activation of the master itself. |
| 18892 |
|
| 18893 |
-- Should dynamic checks be added in the more general case??? |
| 18894 |
|
| 18895 |
if Ekind (Enclosing) /= E_Package then |
| 18896 |
return; |
| 18897 |
end if; |
| 18898 |
|
| 18899 |
-- For task types defined in other units, we want the unit containing |
| 18900 |
-- the task body to be elaborated before the current one. |
| 18901 |
|
| 18902 |
Elmt := First_Elmt (Inter_Procs); |
| 18903 |
while Present (Elmt) loop |
| 18904 |
Ent := Node (Elmt); |
| 18905 |
Task_Scope := Outer_Unit (Scope (Ent)); |
| 18906 |
|
| 18907 |
if not Is_Compilation_Unit (Task_Scope) then |
| 18908 |
null; |
| 18909 |
|
| 18910 |
elsif Suppress_Elaboration_Warnings (Task_Scope) |
| 18911 |
or else Elaboration_Checks_Suppressed (Task_Scope) |
| 18912 |
then |
| 18913 |
null; |
| 18914 |
|
| 18915 |
elsif Dynamic_Elaboration_Checks then |
| 18916 |
if not Elaboration_Checks_Suppressed (Ent) |
| 18917 |
and then not Cunit_SC |
| 18918 |
and then not Restriction_Active |
| 18919 |
(No_Entry_Calls_In_Elaboration_Code) |
| 18920 |
then |
| 18921 |
-- Runtime elaboration check required. Generate check of the |
| 18922 |
-- elaboration counter for the unit containing the entity. |
| 18923 |
|
| 18924 |
Insert_Elab_Check (N, |
| 18925 |
Make_Attribute_Reference (Loc, |
| 18926 |
Prefix => |
| 18927 |
New_Occurrence_Of (Spec_Entity (Task_Scope), Loc), |
| 18928 |
Attribute_Name => Name_Elaborated)); |
| 18929 |
end if; |
| 18930 |
|
| 18931 |
else |
| 18932 |
-- Force the binder to elaborate other unit first |
| 18933 |
|
| 18934 |
if Elab_Info_Messages |
| 18935 |
and then not Suppress_Elaboration_Warnings (Ent) |
| 18936 |
and then not Elaboration_Checks_Suppressed (Ent) |
| 18937 |
and then not Suppress_Elaboration_Warnings (Task_Scope) |
| 18938 |
and then not Elaboration_Checks_Suppressed (Task_Scope) |
| 18939 |
then |
| 18940 |
Error_Msg_Node_2 := Task_Scope; |
| 18941 |
Error_Msg_NE |
| 18942 |
("info: activation of an instance of task type & requires " |
| 18943 |
& "pragma Elaborate_All on &?$?", N, Ent); |
| 18944 |
end if; |
| 18945 |
|
| 18946 |
Activate_Elaborate_All_Desirable (N, Task_Scope); |
| 18947 |
Set_Suppress_Elaboration_Warnings (Task_Scope); |
| 18948 |
end if; |
| 18949 |
|
| 18950 |
Next_Elmt (Elmt); |
| 18951 |
end loop; |
| 18952 |
|
| 18953 |
-- For tasks declared in the current unit, trace other calls within the |
| 18954 |
-- task procedure bodies, which are available. |
| 18955 |
|
| 18956 |
if not Debug_Flag_Dot_Y then |
| 18957 |
In_Task_Activation := True; |
| 18958 |
|
| 18959 |
Elmt := First_Elmt (Intra_Procs); |
| 18960 |
while Present (Elmt) loop |
| 18961 |
Ent := Node (Elmt); |
| 18962 |
Check_Internal_Call_Continue (N, Ent, Enclosing, Ent); |
| 18963 |
Next_Elmt (Elmt); |
| 18964 |
end loop; |
| 18965 |
|
| 18966 |
In_Task_Activation := False; |
| 18967 |
end if; |
| 18968 |
end Check_Task_Activation; |
| 18969 |
|
| 18970 |
------------------------ |
| 18971 |
-- Get_Referenced_Ent -- |
| 18972 |
------------------------ |
| 18973 |
|
| 18974 |
function Get_Referenced_Ent (N : Node_Id) return Entity_Id is |
| 18975 |
Nam : Node_Id; |
| 18976 |
|
| 18977 |
begin |
| 18978 |
if Nkind (N) in N_Has_Entity |
| 18979 |
and then Present (Entity (N)) |
| 18980 |
and then Ekind (Entity (N)) = E_Variable |
| 18981 |
then |
| 18982 |
return Entity (N); |
| 18983 |
end if; |
| 18984 |
|
| 18985 |
if Nkind (N) = N_Attribute_Reference then |
| 18986 |
Nam := Prefix (N); |
| 18987 |
else |
| 18988 |
Nam := Name (N); |
| 18989 |
end if; |
| 18990 |
|
| 18991 |
if No (Nam) then |
| 18992 |
return Empty; |
| 18993 |
elsif Nkind (Nam) = N_Selected_Component then |
| 18994 |
return Entity (Selector_Name (Nam)); |
| 18995 |
elsif not Is_Entity_Name (Nam) then |
| 18996 |
return Empty; |
| 18997 |
else |
| 18998 |
return Entity (Nam); |
| 18999 |
end if; |
| 19000 |
end Get_Referenced_Ent; |
| 19001 |
|
| 19002 |
---------------------- |
| 19003 |
-- Has_Generic_Body -- |
| 19004 |
---------------------- |
| 19005 |
|
| 19006 |
function Has_Generic_Body (N : Node_Id) return Boolean is |
| 19007 |
Ent : constant Entity_Id := Get_Generic_Entity (N); |
| 19008 |
Decl : constant Node_Id := Unit_Declaration_Node (Ent); |
| 19009 |
Scop : Entity_Id; |
| 19010 |
|
| 19011 |
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id; |
| 19012 |
-- Determine if the list of nodes headed by N and linked by Next |
| 19013 |
-- contains a package body for the package spec entity E, and if so |
| 19014 |
-- return the package body. If not, then returns Empty. |
| 19015 |
|
| 19016 |
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id; |
| 19017 |
-- This procedure is called load the unit whose name is given by Nam. |
| 19018 |
-- This unit is being loaded to see whether it contains an optional |
| 19019 |
-- generic body. The returned value is the loaded unit, which is always |
| 19020 |
-- a package body (only package bodies can contain other entities in the |
| 19021 |
-- sense in which Has_Generic_Body is interested). We only attempt to |
| 19022 |
-- load bodies if we are generating code. If we are in semantics check |
| 19023 |
-- only mode, then it would be wrong to load bodies that are not |
| 19024 |
-- required from a semantic point of view, so in this case we return |
| 19025 |
-- Empty. The result is that the caller may incorrectly decide that a |
| 19026 |
-- generic spec does not have a body when in fact it does, but the only |
| 19027 |
-- harm in this is that some warnings on elaboration problems may be |
| 19028 |
-- lost in semantic checks only mode, which is not big loss. We also |
| 19029 |
-- return Empty if we go for a body and it is not there. |
| 19030 |
|
| 19031 |
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id; |
| 19032 |
-- PE is the entity for a package spec. This function locates the |
| 19033 |
-- corresponding package body, returning Empty if none is found. The |
| 19034 |
-- package body returned is fully parsed but may not yet be analyzed, |
| 19035 |
-- so only syntactic fields should be referenced. |
| 19036 |
|
| 19037 |
------------------ |
| 19038 |
-- Find_Body_In -- |
| 19039 |
------------------ |
| 19040 |
|
| 19041 |
function Find_Body_In (E : Entity_Id; N : Node_Id) return Node_Id is |
| 19042 |
Nod : Node_Id; |
| 19043 |
|
| 19044 |
begin |
| 19045 |
Nod := N; |
| 19046 |
while Present (Nod) loop |
| 19047 |
|
| 19048 |
-- If we found the package body we are looking for, return it |
| 19049 |
|
| 19050 |
if Nkind (Nod) = N_Package_Body |
| 19051 |
and then Chars (Defining_Unit_Name (Nod)) = Chars (E) |
| 19052 |
then |
| 19053 |
return Nod; |
| 19054 |
|
| 19055 |
-- If we found the stub for the body, go after the subunit, |
| 19056 |
-- loading it if necessary. |
| 19057 |
|
| 19058 |
elsif Nkind (Nod) = N_Package_Body_Stub |
| 19059 |
and then Chars (Defining_Identifier (Nod)) = Chars (E) |
| 19060 |
then |
| 19061 |
if Present (Stub_Subunit (Nod)) then |
| 19062 |
return Unit (Stub_Subunit (Nod)); |
| 19063 |
|
| 19064 |
else |
| 19065 |
return Load_Package_Body (Get_Unit_Name (Nod)); |
| 19066 |
end if; |
| 19067 |
|
| 19068 |
-- If neither package body nor stub, keep looking on chain |
| 19069 |
|
| 19070 |
else |
| 19071 |
Next (Nod); |
| 19072 |
end if; |
| 19073 |
end loop; |
| 19074 |
|
| 19075 |
return Empty; |
| 19076 |
end Find_Body_In; |
| 19077 |
|
| 19078 |
----------------------- |
| 19079 |
-- Load_Package_Body -- |
| 19080 |
----------------------- |
| 19081 |
|
| 19082 |
function Load_Package_Body (Nam : Unit_Name_Type) return Node_Id is |
| 19083 |
U : Unit_Number_Type; |
| 19084 |
|
| 19085 |
begin |
| 19086 |
if Operating_Mode /= Generate_Code then |
| 19087 |
return Empty; |
| 19088 |
else |
| 19089 |
U := |
| 19090 |
Load_Unit |
| 19091 |
(Load_Name => Nam, |
| 19092 |
Required => False, |
| 19093 |
Subunit => False, |
| 19094 |
Error_Node => N); |
| 19095 |
|
| 19096 |
if U = No_Unit then |
| 19097 |
return Empty; |
| 19098 |
else |
| 19099 |
return Unit (Cunit (U)); |
| 19100 |
end if; |
| 19101 |
end if; |
| 19102 |
end Load_Package_Body; |
| 19103 |
|
| 19104 |
------------------------------- |
| 19105 |
-- Locate_Corresponding_Body -- |
| 19106 |
------------------------------- |
| 19107 |
|
| 19108 |
function Locate_Corresponding_Body (PE : Entity_Id) return Node_Id is |
| 19109 |
Spec : constant Node_Id := Declaration_Node (PE); |
| 19110 |
Decl : constant Node_Id := Parent (Spec); |
| 19111 |
Scop : constant Entity_Id := Scope (PE); |
| 19112 |
PBody : Node_Id; |
| 19113 |
|
| 19114 |
begin |
| 19115 |
if Is_Library_Level_Entity (PE) then |
| 19116 |
|
| 19117 |
-- If package is a library unit that requires a body, we have no |
| 19118 |
-- choice but to go after that body because it might contain an |
| 19119 |
-- optional body for the original generic package. |
| 19120 |
|
| 19121 |
if Unit_Requires_Body (PE) then |
| 19122 |
|
| 19123 |
-- Load the body. Note that we are a little careful here to use |
| 19124 |
-- Spec to get the unit number, rather than PE or Decl, since |
| 19125 |
-- in the case where the package is itself a library level |
| 19126 |
-- instantiation, Spec will properly reference the generic |
| 19127 |
-- template, which is what we really want. |
| 19128 |
|
| 19129 |
return |
| 19130 |
Load_Package_Body |
| 19131 |
(Get_Body_Name (Unit_Name (Get_Source_Unit (Spec)))); |
| 19132 |
|
| 19133 |
-- But if the package is a library unit that does NOT require |
| 19134 |
-- a body, then no body is permitted, so we are sure that there |
| 19135 |
-- is no body for the original generic package. |
| 19136 |
|
| 19137 |
else |
| 19138 |
return Empty; |
| 19139 |
end if; |
| 19140 |
|
| 19141 |
-- Otherwise look and see if we are embedded in a further package |
| 19142 |
|
| 19143 |
elsif Is_Package_Or_Generic_Package (Scop) then |
| 19144 |
|
| 19145 |
-- If so, get the body of the enclosing package, and look in |
| 19146 |
-- its package body for the package body we are looking for. |
| 19147 |
|
| 19148 |
PBody := Locate_Corresponding_Body (Scop); |
| 19149 |
|
| 19150 |
if No (PBody) then |
| 19151 |
return Empty; |
| 19152 |
else |
| 19153 |
return Find_Body_In (PE, First (Declarations (PBody))); |
| 19154 |
end if; |
| 19155 |
|
| 19156 |
-- If we are not embedded in a further package, then the body |
| 19157 |
-- must be in the same declarative part as we are. |
| 19158 |
|
| 19159 |
else |
| 19160 |
return Find_Body_In (PE, Next (Decl)); |
| 19161 |
end if; |
| 19162 |
end Locate_Corresponding_Body; |
| 19163 |
|
| 19164 |
-- Start of processing for Has_Generic_Body |
| 19165 |
|
| 19166 |
begin |
| 19167 |
if Present (Corresponding_Body (Decl)) then |
| 19168 |
return True; |
| 19169 |
|
| 19170 |
elsif Unit_Requires_Body (Ent) then |
| 19171 |
return True; |
| 19172 |
|
| 19173 |
-- Compilation units cannot have optional bodies |
| 19174 |
|
| 19175 |
elsif Is_Compilation_Unit (Ent) then |
| 19176 |
return False; |
| 19177 |
|
| 19178 |
-- Otherwise look at what scope we are in |
| 19179 |
|
| 19180 |
else |
| 19181 |
Scop := Scope (Ent); |
| 19182 |
|
| 19183 |
-- Case of entity is in other than a package spec, in this case |
| 19184 |
-- the body, if present, must be in the same declarative part. |
| 19185 |
|
| 19186 |
if not Is_Package_Or_Generic_Package (Scop) then |
| 19187 |
declare |
| 19188 |
P : Node_Id; |
| 19189 |
|
| 19190 |
begin |
| 19191 |
-- Declaration node may get us a spec, so if so, go to |
| 19192 |
-- the parent declaration. |
| 19193 |
|
| 19194 |
P := Declaration_Node (Ent); |
| 19195 |
while not Is_List_Member (P) loop |
| 19196 |
P := Parent (P); |
| 19197 |
end loop; |
| 19198 |
|
| 19199 |
return Present (Find_Body_In (Ent, Next (P))); |
| 19200 |
end; |
| 19201 |
|
| 19202 |
-- If the entity is in a package spec, then we have to locate |
| 19203 |
-- the corresponding package body, and look there. |
| 19204 |
|
| 19205 |
else |
| 19206 |
declare |
| 19207 |
PBody : constant Node_Id := Locate_Corresponding_Body (Scop); |
| 19208 |
|
| 19209 |
begin |
| 19210 |
if No (PBody) then |
| 19211 |
return False; |
| 19212 |
else |
| 19213 |
return |
| 19214 |
Present |
| 19215 |
(Find_Body_In (Ent, (First (Declarations (PBody))))); |
| 19216 |
end if; |
| 19217 |
end; |
| 19218 |
end if; |
| 19219 |
end if; |
| 19220 |
end Has_Generic_Body; |
| 19221 |
|
| 19222 |
----------------------- |
| 19223 |
-- Insert_Elab_Check -- |
| 19224 |
----------------------- |
| 19225 |
|
| 19226 |
procedure Insert_Elab_Check (N : Node_Id; C : Node_Id := Empty) is |
| 19227 |
Nod : Node_Id; |
| 19228 |
Loc : constant Source_Ptr := Sloc (N); |
| 19229 |
|
| 19230 |
Chk : Node_Id; |
| 19231 |
-- The check (N_Raise_Program_Error) node to be inserted |
| 19232 |
|
| 19233 |
begin |
| 19234 |
-- If expansion is disabled, do not generate any checks. Also |
| 19235 |
-- skip checks if any subunits are missing because in either |
| 19236 |
-- case we lack the full information that we need, and no object |
| 19237 |
-- file will be created in any case. |
| 19238 |
|
| 19239 |
if not Expander_Active or else Subunits_Missing then |
| 19240 |
return; |
| 19241 |
end if; |
| 19242 |
|
| 19243 |
-- If we have a generic instantiation, where Instance_Spec is set, |
| 19244 |
-- then this field points to a generic instance spec that has |
| 19245 |
-- been inserted before the instantiation node itself, so that |
| 19246 |
-- is where we want to insert a check. |
| 19247 |
|
| 19248 |
if Nkind (N) in N_Generic_Instantiation |
| 19249 |
and then Present (Instance_Spec (N)) |
| 19250 |
then |
| 19251 |
Nod := Instance_Spec (N); |
| 19252 |
else |
| 19253 |
Nod := N; |
| 19254 |
end if; |
| 19255 |
|
| 19256 |
-- Build check node, possibly with condition |
| 19257 |
|
| 19258 |
Chk := |
| 19259 |
Make_Raise_Program_Error (Loc, Reason => PE_Access_Before_Elaboration); |
| 19260 |
|
| 19261 |
if Present (C) then |
| 19262 |
Set_Condition (Chk, Make_Op_Not (Loc, Right_Opnd => C)); |
| 19263 |
end if; |
| 19264 |
|
| 19265 |
-- If we are inserting at the top level, insert in Aux_Decls |
| 19266 |
|
| 19267 |
if Nkind (Parent (Nod)) = N_Compilation_Unit then |
| 19268 |
declare |
| 19269 |
ADN : constant Node_Id := Aux_Decls_Node (Parent (Nod)); |
| 19270 |
|
| 19271 |
begin |
| 19272 |
if No (Declarations (ADN)) then |
| 19273 |
Set_Declarations (ADN, New_List (Chk)); |
| 19274 |
else |
| 19275 |
Append_To (Declarations (ADN), Chk); |
| 19276 |
end if; |
| 19277 |
|
| 19278 |
Analyze (Chk); |
| 19279 |
end; |
| 19280 |
|
| 19281 |
-- Otherwise just insert as an action on the node in question |
| 19282 |
|
| 19283 |
else |
| 19284 |
Insert_Action (Nod, Chk); |
| 19285 |
end if; |
| 19286 |
end Insert_Elab_Check; |
| 19287 |
|
| 19288 |
------------------------------- |
| 19289 |
-- Is_Call_Of_Generic_Formal -- |
| 19290 |
------------------------------- |
| 19291 |
|
| 19292 |
function Is_Call_Of_Generic_Formal (N : Node_Id) return Boolean is |
| 19293 |
begin |
| 19294 |
return Nkind (N) in N_Subprogram_Call |
| 19295 |
|
| 19296 |
-- Always return False if debug flag -gnatd.G is set |
| 19297 |
|
| 19298 |
and then not Debug_Flag_Dot_GG |
| 19299 |
|
| 19300 |
-- For now, we detect this by looking for the strange identifier |
| 19301 |
-- node, whose Chars reflect the name of the generic formal, but |
| 19302 |
-- the Chars of the Entity references the generic actual. |
| 19303 |
|
| 19304 |
and then Nkind (Name (N)) = N_Identifier |
| 19305 |
and then Chars (Name (N)) /= Chars (Entity (Name (N))); |
| 19306 |
end Is_Call_Of_Generic_Formal; |
| 19307 |
|
| 19308 |
----------------------------- |
| 19309 |
-- Is_Controlled_Procedure -- |
| 19310 |
----------------------------- |
| 19311 |
|
| 19312 |
function Is_Controlled_Procedure |
| 19313 |
(Id : Entity_Id; |
| 19314 |
Nam : Name_Id) return Boolean |
| 19315 |
is |
| 19316 |
begin |
| 19317 |
-- To qualify, the subprogram must denote a source procedure with |
| 19318 |
-- name Adjust, Finalize, or Initialize where the sole formal is |
| 19319 |
-- in out and controlled. |
| 19320 |
|
| 19321 |
if Comes_From_Source (Id) and then Ekind (Id) = E_Procedure then |
| 19322 |
declare |
| 19323 |
Formal_Id : constant Entity_Id := First_Formal (Id); |
| 19324 |
|
| 19325 |
begin |
| 19326 |
return |
| 19327 |
Present (Formal_Id) |
| 19328 |
and then Ekind (Formal_Id) = E_In_Out_Parameter |
| 19329 |
and then Is_Controlled (Etype (Formal_Id)) |
| 19330 |
and then No (Next_Formal (Formal_Id)) |
| 19331 |
and then Chars (Id) = |
| 19332 |
Name_Of_Controlled_Prim_Op (Etype (Formal_Id), Nam); |
| 19333 |
end; |
| 19334 |
end if; |
| 19335 |
|
| 19336 |
return False; |
| 19337 |
end Is_Controlled_Procedure; |
| 19338 |
|
| 19339 |
------------------------------- |
| 19340 |
-- Is_Finalization_Procedure -- |
| 19341 |
------------------------------- |
| 19342 |
|
| 19343 |
function Is_Finalization_Procedure (Id : Entity_Id) return Boolean is |
| 19344 |
begin |
| 19345 |
-- Check whether Id is a procedure with at least one parameter |
| 19346 |
|
| 19347 |
if Ekind (Id) = E_Procedure and then Present (First_Formal (Id)) then |
| 19348 |
declare |
| 19349 |
Typ : constant Entity_Id := Etype (First_Formal (Id)); |
| 19350 |
Deep_Fin : Entity_Id := Empty; |
| 19351 |
Fin : Entity_Id := Empty; |
| 19352 |
|
| 19353 |
begin |
| 19354 |
-- If the type of the first formal does not require finalization |
| 19355 |
-- actions, then this is definitely not [Deep_]Finalize. |
| 19356 |
|
| 19357 |
if not Needs_Finalization (Typ) then |
| 19358 |
return False; |
| 19359 |
end if; |
| 19360 |
|
| 19361 |
-- At this point we have the following scenario: |
| 19362 |
|
| 19363 |
-- procedure Name (Param1 : [in] [out] Ctrl[; Param2 : ...]); |
| 19364 |
|
| 19365 |
-- Recover the two possible versions of [Deep_]Finalize using the |
| 19366 |
-- type of the first parameter and compare with the input. |
| 19367 |
|
| 19368 |
Deep_Fin := TSS (Typ, TSS_Deep_Finalize); |
| 19369 |
|
| 19370 |
if Is_Controlled (Typ) then |
| 19371 |
Fin := Find_Controlled_Prim_Op (Typ, Name_Finalize); |
| 19372 |
end if; |
| 19373 |
|
| 19374 |
return (Present (Deep_Fin) and then Id = Deep_Fin) |
| 19375 |
or else (Present (Fin) and then Id = Fin); |
| 19376 |
end; |
| 19377 |
end if; |
| 19378 |
|
| 19379 |
return False; |
| 19380 |
end Is_Finalization_Procedure; |
| 19381 |
|
| 19382 |
------------------ |
| 19383 |
-- Output_Calls -- |
| 19384 |
------------------ |
| 19385 |
|
| 19386 |
procedure Output_Calls |
| 19387 |
(N : Node_Id; |
| 19388 |
Check_Elab_Flag : Boolean) |
| 19389 |
is |
| 19390 |
function Emit (Flag : Boolean) return Boolean; |
| 19391 |
-- Determine whether to emit an error message based on the combination |
| 19392 |
-- of flags Check_Elab_Flag and Flag. |
| 19393 |
|
| 19394 |
function Is_Printable_Error_Name return Boolean; |
| 19395 |
-- An internal function, used to determine if a name, stored in the |
| 19396 |
-- Name_Buffer, is either a non-internal name, or is an internal name |
| 19397 |
-- that is printable by the error message circuits (i.e. it has a single |
| 19398 |
-- upper case letter at the end). |
| 19399 |
|
| 19400 |
---------- |
| 19401 |
-- Emit -- |
| 19402 |
---------- |
| 19403 |
|
| 19404 |
function Emit (Flag : Boolean) return Boolean is |
| 19405 |
begin |
| 19406 |
if Check_Elab_Flag then |
| 19407 |
return Flag; |
| 19408 |
else |
| 19409 |
return True; |
| 19410 |
end if; |
| 19411 |
end Emit; |
| 19412 |
|
| 19413 |
----------------------------- |
| 19414 |
-- Is_Printable_Error_Name -- |
| 19415 |
----------------------------- |
| 19416 |
|
| 19417 |
function Is_Printable_Error_Name return Boolean is |
| 19418 |
begin |
| 19419 |
if not Is_Internal_Name then |
| 19420 |
return True; |
| 19421 |
|
| 19422 |
elsif Name_Len = 1 then |
| 19423 |
return False; |
| 19424 |
|
| 19425 |
else |
| 19426 |
Name_Len := Name_Len - 1; |
| 19427 |
return not Is_Internal_Name; |
| 19428 |
end if; |
| 19429 |
end Is_Printable_Error_Name; |
| 19430 |
|
| 19431 |
-- Local variables |
| 19432 |
|
| 19433 |
Ent : Entity_Id; |
| 19434 |
|
| 19435 |
-- Start of processing for Output_Calls |
| 19436 |
|
| 19437 |
begin |
| 19438 |
for J in reverse 1 .. Elab_Call.Last loop |
| 19439 |
Error_Msg_Sloc := Elab_Call.Table (J).Cloc; |
| 19440 |
|
| 19441 |
Ent := Elab_Call.Table (J).Ent; |
| 19442 |
Get_Name_String (Chars (Ent)); |
| 19443 |
|
| 19444 |
-- Dynamic elaboration model, warnings controlled by -gnatwl |
| 19445 |
|
| 19446 |
if Dynamic_Elaboration_Checks then |
| 19447 |
if Emit (Elab_Warnings) then |
| 19448 |
if Is_Generic_Unit (Ent) then |
| 19449 |
Error_Msg_NE ("\\?l?& instantiated #", N, Ent); |
| 19450 |
elsif Is_Init_Proc (Ent) then |
| 19451 |
Error_Msg_N ("\\?l?initialization procedure called #", N); |
| 19452 |
elsif Is_Printable_Error_Name then |
| 19453 |
Error_Msg_NE ("\\?l?& called #", N, Ent); |
| 19454 |
else |
| 19455 |
Error_Msg_N ("\\?l?called #", N); |
| 19456 |
end if; |
| 19457 |
end if; |
| 19458 |
|
| 19459 |
-- Static elaboration model, info messages controlled by -gnatel |
| 19460 |
|
| 19461 |
else |
| 19462 |
if Emit (Elab_Info_Messages) then |
| 19463 |
if Is_Generic_Unit (Ent) then |
| 19464 |
Error_Msg_NE ("\\?$?& instantiated #", N, Ent); |
| 19465 |
elsif Is_Init_Proc (Ent) then |
| 19466 |
Error_Msg_N ("\\?$?initialization procedure called #", N); |
| 19467 |
elsif Is_Printable_Error_Name then |
| 19468 |
Error_Msg_NE ("\\?$?& called #", N, Ent); |
| 19469 |
else |
| 19470 |
Error_Msg_N ("\\?$?called #", N); |
| 19471 |
end if; |
| 19472 |
end if; |
| 19473 |
end if; |
| 19474 |
end loop; |
| 19475 |
end Output_Calls; |
| 19476 |
|
| 19477 |
---------------------------- |
| 19478 |
-- Same_Elaboration_Scope -- |
| 19479 |
---------------------------- |
| 19480 |
|
| 19481 |
function Same_Elaboration_Scope (Scop1, Scop2 : Entity_Id) return Boolean is |
| 19482 |
S1 : Entity_Id; |
| 19483 |
S2 : Entity_Id; |
| 19484 |
|
| 19485 |
begin |
| 19486 |
-- Find elaboration scope for Scop1 |
| 19487 |
-- This is either a subprogram or a compilation unit. |
| 19488 |
|
| 19489 |
S1 := Scop1; |
| 19490 |
while S1 /= Standard_Standard |
| 19491 |
and then not Is_Compilation_Unit (S1) |
| 19492 |
and then Ekind (S1) in E_Package | E_Protected_Type | E_Block |
| 19493 |
loop |
| 19494 |
S1 := Scope (S1); |
| 19495 |
end loop; |
| 19496 |
|
| 19497 |
-- Find elaboration scope for Scop2 |
| 19498 |
|
| 19499 |
S2 := Scop2; |
| 19500 |
while S2 /= Standard_Standard |
| 19501 |
and then not Is_Compilation_Unit (S2) |
| 19502 |
and then Ekind (S2) in E_Package | E_Protected_Type | E_Block |
| 19503 |
loop |
| 19504 |
S2 := Scope (S2); |
| 19505 |
end loop; |
| 19506 |
|
| 19507 |
return S1 = S2; |
| 19508 |
end Same_Elaboration_Scope; |
| 19509 |
|
| 19510 |
----------------- |
| 19511 |
-- Set_C_Scope -- |
| 19512 |
----------------- |
| 19513 |
|
| 19514 |
procedure Set_C_Scope is |
| 19515 |
begin |
| 19516 |
while not Is_Compilation_Unit (C_Scope) loop |
| 19517 |
C_Scope := Scope (C_Scope); |
| 19518 |
end loop; |
| 19519 |
end Set_C_Scope; |
| 19520 |
|
| 19521 |
-------------------------------- |
| 19522 |
-- Set_Elaboration_Constraint -- |
| 19523 |
-------------------------------- |
| 19524 |
|
| 19525 |
procedure Set_Elaboration_Constraint |
| 19526 |
(Call : Node_Id; |
| 19527 |
Subp : Entity_Id; |
| 19528 |
Scop : Entity_Id) |
| 19529 |
is |
| 19530 |
Elab_Unit : Entity_Id; |
| 19531 |
|
| 19532 |
-- Check whether this is a call to an Initialize subprogram for a |
| 19533 |
-- controlled type. Note that Call can also be a 'Access attribute |
| 19534 |
-- reference, which now generates an elaboration check. |
| 19535 |
|
| 19536 |
Init_Call : constant Boolean := |
| 19537 |
Nkind (Call) = N_Procedure_Call_Statement |
| 19538 |
and then Is_Controlled_Procedure (Subp, Name_Initialize); |
| 19539 |
|
| 19540 |
begin |
| 19541 |
-- If the unit is mentioned in a with_clause of the current unit, it is |
| 19542 |
-- visible, and we can set the elaboration flag. |
| 19543 |
|
| 19544 |
if Is_Immediately_Visible (Scop) |
| 19545 |
or else (Is_Child_Unit (Scop) and then Is_Visible_Lib_Unit (Scop)) |
| 19546 |
then |
| 19547 |
Activate_Elaborate_All_Desirable (Call, Scop); |
| 19548 |
Set_Suppress_Elaboration_Warnings (Scop); |
| 19549 |
return; |
| 19550 |
end if; |
| 19551 |
|
| 19552 |
-- If this is not an initialization call or a call using object notation |
| 19553 |
-- we know that the unit of the called entity is in the context, and we |
| 19554 |
-- can set the flag as well. The unit need not be visible if the call |
| 19555 |
-- occurs within an instantiation. |
| 19556 |
|
| 19557 |
if Is_Init_Proc (Subp) |
| 19558 |
or else Init_Call |
| 19559 |
or else Nkind (Original_Node (Call)) = N_Selected_Component |
| 19560 |
then |
| 19561 |
null; -- detailed processing follows. |
| 19562 |
|
| 19563 |
else |
| 19564 |
Activate_Elaborate_All_Desirable (Call, Scop); |
| 19565 |
Set_Suppress_Elaboration_Warnings (Scop); |
| 19566 |
return; |
| 19567 |
end if; |
| 19568 |
|
| 19569 |
-- If the unit is not in the context, there must be an intermediate unit |
| 19570 |
-- that is, on which we need to place to elaboration flag. This happens |
| 19571 |
-- with init proc calls. |
| 19572 |
|
| 19573 |
if Is_Init_Proc (Subp) or else Init_Call then |
| 19574 |
|
| 19575 |
-- The initialization call is on an object whose type is not declared |
| 19576 |
-- in the same scope as the subprogram. The type of the object must |
| 19577 |
-- be a subtype of the type of operation. This object is the first |
| 19578 |
-- actual in the call. |
| 19579 |
|
| 19580 |
declare |
| 19581 |
Typ : constant Entity_Id := |
| 19582 |
Etype (First (Parameter_Associations (Call))); |
| 19583 |
begin |
| 19584 |
Elab_Unit := Scope (Typ); |
| 19585 |
while Present (Elab_Unit) |
| 19586 |
and then not Is_Compilation_Unit (Elab_Unit) |
| 19587 |
loop |
| 19588 |
Elab_Unit := Scope (Elab_Unit); |
| 19589 |
end loop; |
| 19590 |
end; |
| 19591 |
|
| 19592 |
-- If original node uses selected component notation, the prefix is |
| 19593 |
-- visible and determines the scope that must be elaborated. After |
| 19594 |
-- rewriting, the prefix is the first actual in the call. |
| 19595 |
|
| 19596 |
elsif Nkind (Original_Node (Call)) = N_Selected_Component then |
| 19597 |
Elab_Unit := Scope (Etype (First (Parameter_Associations (Call)))); |
| 19598 |
|
| 19599 |
-- Not one of special cases above |
| 19600 |
|
| 19601 |
else |
| 19602 |
-- Using previously computed scope. If the elaboration check is |
| 19603 |
-- done after analysis, the scope is not visible any longer, but |
| 19604 |
-- must still be in the context. |
| 19605 |
|
| 19606 |
Elab_Unit := Scop; |
| 19607 |
end if; |
| 19608 |
|
| 19609 |
Activate_Elaborate_All_Desirable (Call, Elab_Unit); |
| 19610 |
Set_Suppress_Elaboration_Warnings (Elab_Unit); |
| 19611 |
end Set_Elaboration_Constraint; |
| 19612 |
|
| 19613 |
----------------- |
| 19614 |
-- Spec_Entity -- |
| 19615 |
----------------- |
| 19616 |
|
| 19617 |
function Spec_Entity (E : Entity_Id) return Entity_Id is |
| 19618 |
Decl : Node_Id; |
| 19619 |
|
| 19620 |
begin |
| 19621 |
-- Check for case of body entity |
| 19622 |
-- Why is the check for E_Void needed??? |
| 19623 |
|
| 19624 |
if Ekind (E) in E_Void | E_Subprogram_Body | E_Package_Body then |
| 19625 |
Decl := E; |
| 19626 |
|
| 19627 |
loop |
| 19628 |
Decl := Parent (Decl); |
| 19629 |
exit when Nkind (Decl) in N_Proper_Body; |
| 19630 |
end loop; |
| 19631 |
|
| 19632 |
return Corresponding_Spec (Decl); |
| 19633 |
|
| 19634 |
else |
| 19635 |
return E; |
| 19636 |
end if; |
| 19637 |
end Spec_Entity; |
| 19638 |
|
| 19639 |
------------ |
| 19640 |
-- Within -- |
| 19641 |
------------ |
| 19642 |
|
| 19643 |
function Within (E1, E2 : Entity_Id) return Boolean is |
| 19644 |
Scop : Entity_Id; |
| 19645 |
begin |
| 19646 |
Scop := E1; |
| 19647 |
loop |
| 19648 |
if Scop = E2 then |
| 19649 |
return True; |
| 19650 |
elsif Scop = Standard_Standard then |
| 19651 |
return False; |
| 19652 |
else |
| 19653 |
Scop := Scope (Scop); |
| 19654 |
end if; |
| 19655 |
end loop; |
| 19656 |
end Within; |
| 19657 |
|
| 19658 |
-------------------------- |
| 19659 |
-- Within_Elaborate_All -- |
| 19660 |
-------------------------- |
| 19661 |
|
| 19662 |
function Within_Elaborate_All |
| 19663 |
(Unit : Unit_Number_Type; |
| 19664 |
E : Entity_Id) return Boolean |
| 19665 |
is |
| 19666 |
type Unit_Number_Set is array (Main_Unit .. Last_Unit) of Boolean; |
| 19667 |
pragma Pack (Unit_Number_Set); |
| 19668 |
|
| 19669 |
Seen : Unit_Number_Set := (others => False); |
| 19670 |
-- Seen (X) is True after we have seen unit X in the walk. This is used |
| 19671 |
-- to prevent processing the same unit more than once. |
| 19672 |
|
| 19673 |
Result : Boolean := False; |
| 19674 |
|
| 19675 |
procedure Helper (Unit : Unit_Number_Type); |
| 19676 |
-- This helper procedure does all the work for Within_Elaborate_All. It |
| 19677 |
-- walks the dependency graph, and sets Result to True if it finds an |
| 19678 |
-- appropriate Elaborate_All. |
| 19679 |
|
| 19680 |
------------ |
| 19681 |
-- Helper -- |
| 19682 |
------------ |
| 19683 |
|
| 19684 |
procedure Helper (Unit : Unit_Number_Type) is |
| 19685 |
CU : constant Node_Id := Cunit (Unit); |
| 19686 |
|
| 19687 |
Item : Node_Id; |
| 19688 |
Item2 : Node_Id; |
| 19689 |
Elab_Id : Entity_Id; |
| 19690 |
Par : Node_Id; |
| 19691 |
|
| 19692 |
begin |
| 19693 |
if Seen (Unit) then |
| 19694 |
return; |
| 19695 |
else |
| 19696 |
Seen (Unit) := True; |
| 19697 |
end if; |
| 19698 |
|
| 19699 |
-- First, check for Elaborate_Alls on this unit |
| 19700 |
|
| 19701 |
Item := First (Context_Items (CU)); |
| 19702 |
while Present (Item) loop |
| 19703 |
if Nkind (Item) = N_Pragma |
| 19704 |
and then Pragma_Name (Item) = Name_Elaborate_All |
| 19705 |
then |
| 19706 |
-- Return if some previous error on the pragma itself. The |
| 19707 |
-- pragma may be unanalyzed, because of a previous error, or |
| 19708 |
-- if it is the context of a subunit, inherited by its parent. |
| 19709 |
|
| 19710 |
if Error_Posted (Item) or else not Analyzed (Item) then |
| 19711 |
return; |
| 19712 |
end if; |
| 19713 |
|
| 19714 |
Elab_Id := |
| 19715 |
Entity |
| 19716 |
(Expression (First (Pragma_Argument_Associations (Item)))); |
| 19717 |
|
| 19718 |
if E = Elab_Id then |
| 19719 |
Result := True; |
| 19720 |
return; |
| 19721 |
end if; |
| 19722 |
|
| 19723 |
Par := Parent (Unit_Declaration_Node (Elab_Id)); |
| 19724 |
|
| 19725 |
Item2 := First (Context_Items (Par)); |
| 19726 |
while Present (Item2) loop |
| 19727 |
if Nkind (Item2) = N_With_Clause |
| 19728 |
and then Entity (Name (Item2)) = E |
| 19729 |
and then not Limited_Present (Item2) |
| 19730 |
then |
| 19731 |
Result := True; |
| 19732 |
return; |
| 19733 |
end if; |
| 19734 |
|
| 19735 |
Next (Item2); |
| 19736 |
end loop; |
| 19737 |
end if; |
| 19738 |
|
| 19739 |
Next (Item); |
| 19740 |
end loop; |
| 19741 |
|
| 19742 |
-- Second, recurse on with's. We could do this as part of the above |
| 19743 |
-- loop, but it's probably more efficient to have two loops, because |
| 19744 |
-- the relevant Elaborate_All is likely to be on the initial unit. In |
| 19745 |
-- other words, we're walking the with's breadth-first. This part is |
| 19746 |
-- only necessary in the dynamic elaboration model. |
| 19747 |
|
| 19748 |
if Dynamic_Elaboration_Checks then |
| 19749 |
Item := First (Context_Items (CU)); |
| 19750 |
while Present (Item) loop |
| 19751 |
if Nkind (Item) = N_With_Clause |
| 19752 |
and then not Limited_Present (Item) |
| 19753 |
then |
| 19754 |
-- Note: the following call to Get_Cunit_Unit_Number does a |
| 19755 |
-- linear search, which could be slow, but it's OK because |
| 19756 |
-- we're about to give a warning anyway. Also, there might |
| 19757 |
-- be hundreds of units, but not millions. If it turns out |
| 19758 |
-- to be a problem, we could store the Get_Cunit_Unit_Number |
| 19759 |
-- in each N_Compilation_Unit node, but that would involve |
| 19760 |
-- rearranging N_Compilation_Unit_Aux to make room. |
| 19761 |
|
| 19762 |
Helper (Get_Cunit_Unit_Number (Withed_Lib_Unit (Item))); |
| 19763 |
|
| 19764 |
if Result then |
| 19765 |
return; |
| 19766 |
end if; |
| 19767 |
end if; |
| 19768 |
|
| 19769 |
Next (Item); |
| 19770 |
end loop; |
| 19771 |
end if; |
| 19772 |
end Helper; |
| 19773 |
|
| 19774 |
-- Start of processing for Within_Elaborate_All |
| 19775 |
|
| 19776 |
begin |
| 19777 |
Helper (Unit); |
| 19778 |
return Result; |
| 19779 |
end Within_Elaborate_All; |
| 19780 |
|
| 19781 |
end Sem_Elab; |