1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- R E S T R I C T -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1992-2019, 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-- This package deals with the implementation of the Restrictions pragma 27 28with Aspects; use Aspects; 29with Namet; use Namet; 30with Rident; use Rident; 31with Snames; use Snames; 32with Table; 33with Types; use Types; 34with Uintp; use Uintp; 35 36package Restrict is 37 38 Restrictions : Restrictions_Info := No_Restrictions; 39 -- This variable records restrictions found in any units in the main 40 -- extended unit, and in the case of restrictions checked for partition 41 -- consistency, restrictions found in any with'ed units, parent specs 42 -- etc., since we may as well check as much as we can at compile time. 43 -- These variables should not be referenced directly by clients. Instead 44 -- use Check_Restriction to record a violation of a restriction, and 45 -- Restriction_Active to test if a given restriction is active. 46 47 Restrictions_Loc : array (All_Restrictions) of Source_Ptr := 48 (others => No_Location); 49 -- Locations of Restrictions pragmas for error message purposes. 50 -- Valid only if corresponding entry in Restrictions is set. A value 51 -- of No_Location is used for implicit restrictions set by another 52 -- pragma, and a value of System_Location is used for restrictions 53 -- set from package Standard by the processing in Targparm. 54 55 Restriction_Profile_Name : array (All_Restrictions) of Profile_Name; 56 -- Entries in this array are valid only if the corresponding restriction in 57 -- Restrictions is set. The value is the corresponding profile name if the 58 -- restriction was set by a Profile or Profile_Warnings pragma. The value 59 -- is No_Profile in all other cases. 60 61 Main_Restrictions : Restrictions_Info := No_Restrictions; 62 -- This variable records only restrictions found in any units of the 63 -- main extended unit. These are the variables used for ali file output, 64 -- since we want the binder to be able to accurately diagnose inter-unit 65 -- restriction violations. 66 67 Restriction_Warnings : Rident.Restriction_Flags := (others => False); 68 -- If one of these flags is set, then it means that violation of the 69 -- corresponding restriction results only in a warning message, not 70 -- in an error message, and the restriction is not otherwise enforced. 71 -- Note that the flags in Restrictions are set to indicate that the 72 -- restriction is set in this case, but Main_Restrictions is never 73 -- set if Restriction_Warnings is set, so this does not look like a 74 -- restriction to the binder. 75 76 -- The following declarations establish a mapping between restriction 77 -- identifiers, and the names of corresponding restricted library units. 78 79 type Unit_Entry is record 80 Res_Id : Restriction_Id; 81 Filenm : String (1 .. 8); 82 end record; 83 84 Unit_Array : constant array (Positive range <>) of Unit_Entry := ( 85 (No_Asynchronous_Control, "a-astaco"), 86 (No_Calendar, "a-calend"), 87 (No_Calendar, "calendar"), 88 (No_Delay, "a-calend"), 89 (No_Delay, "calendar"), 90 (No_Dynamic_Priorities, "a-dynpri"), 91 (No_Finalization, "a-finali"), 92 (No_IO, "a-direio"), 93 (No_IO, "directio"), 94 (No_IO, "a-sequio"), 95 (No_IO, "sequenio"), 96 (No_IO, "a-ststio"), 97 (No_IO, "a-textio"), 98 (No_IO, "text_io "), 99 (No_IO, "a-witeio"), 100 (No_Task_Attributes_Package, "a-tasatt"), 101 (No_Unchecked_Conversion, "a-unccon"), 102 (No_Unchecked_Conversion, "unchconv"), 103 (No_Unchecked_Deallocation, "a-uncdea"), 104 (No_Unchecked_Deallocation, "unchdeal")); 105 106 -- The following map has True for all GNAT-defined Restrictions. It is used 107 -- to implement pragma Restrictions (No_Implementation_Restrictions) (which 108 -- is why this restriction itself is excluded from the list). 109 110 Implementation_Restriction : constant array (All_Restrictions) of Boolean := 111 (Simple_Barriers => True, 112 No_Calendar => True, 113 No_Default_Initialization => True, 114 No_Direct_Boolean_Operators => True, 115 No_Dispatching_Calls => True, 116 No_Dynamic_Attachment => True, 117 No_Elaboration_Code => True, 118 No_Enumeration_Maps => True, 119 No_Entry_Calls_In_Elaboration_Code => True, 120 No_Entry_Queue => True, 121 No_Exception_Handlers => True, 122 No_Exception_Propagation => True, 123 No_Exception_Registration => True, 124 No_Finalization => True, 125 No_Fixed_IO => True, 126 No_Implementation_Attributes => True, 127 No_Implementation_Pragmas => True, 128 No_Implicit_Conditionals => True, 129 No_Implicit_Aliasing => True, 130 No_Implicit_Dynamic_Code => True, 131 No_Implicit_Loops => True, 132 No_Initialize_Scalars => True, 133 No_Local_Protected_Objects => True, 134 No_Long_Long_Integers => True, 135 No_Multiple_Elaboration => True, 136 No_Protected_Type_Allocators => True, 137 No_Relative_Delay => True, 138 No_Requeue_Statements => True, 139 No_Secondary_Stack => True, 140 No_Select_Statements => True, 141 No_Standard_Storage_Pools => True, 142 No_Stream_Optimizations => True, 143 No_Streams => True, 144 No_Task_Attributes_Package => True, 145 No_Task_Termination => True, 146 No_Tasking => True, 147 No_Wide_Characters => True, 148 Static_Priorities => True, 149 Static_Storage_Size => True, 150 Pure_Barriers => True, 151 SPARK_05 => True, 152 others => False); 153 154 -------------------------- 155 -- No_Dependences Table -- 156 -------------------------- 157 158 -- The following table records entries made by Restrictions pragmas 159 -- that specify a parameter for No_Dependence. Each such pragma makes 160 -- an entry in this table. 161 162 -- Note: we have chosen to implement this restriction in the "syntactic" 163 -- form, where we do not check that the named package is a language defined 164 -- package, but instead we allow arbitrary package names. The discussion of 165 -- this issue is not complete in the ARG, but the sense seems to be leaning 166 -- in this direction, which makes more sense to us, since it is much more 167 -- useful, and much easier to implement. 168 169 type ND_Entry is record 170 Unit : Node_Id; 171 -- The unit parameter from the No_Dependence pragma 172 173 Warn : Boolean; 174 -- True if from Restriction_Warnings, False if from Restrictions 175 176 Profile : Profile_Name; 177 -- Set to name of profile from which No_Dependence entry came, or to 178 -- No_Profile if a pragma Restriction set the No_Dependence entry. 179 end record; 180 181 package No_Dependences is new Table.Table ( 182 Table_Component_Type => ND_Entry, 183 Table_Index_Type => Int, 184 Table_Low_Bound => 0, 185 Table_Initial => 200, 186 Table_Increment => 200, 187 Table_Name => "Name_No_Dependences"); 188 189 ---------------------------- 190 -- No_Use_Of_Entity Table -- 191 ---------------------------- 192 193 -- The following table records entries made by Restrictions pragmas 194 -- that specify a parameter for No_Use_Of_Entity. Each such pragma makes 195 -- an entry in this table. 196 197 -- Note: we have chosen to implement this restriction in the "syntactic" 198 -- form, where we allow arbitrary fully qualified names to be specified. 199 200 type NE_Entry is record 201 Entity : Node_Id; 202 -- The entity parameter from the No_Use_Of_Entity pragma. This is in 203 -- the form of a selected component, since that is the way the parser 204 -- processes it, and we don't further analyze it. 205 206 Warn : Boolean; 207 -- True if from Restriction_Warnings, False if from Restrictions 208 209 Profile : Profile_Name; 210 -- Set to name of profile from which No_Use_Of_Entity entry came, or to 211 -- No_Profile if a pragma Restriction set the No_Use_Of_Entity entry. 212 end record; 213 214 package No_Use_Of_Entity is new Table.Table ( 215 Table_Component_Type => NE_Entry, 216 Table_Index_Type => Int, 217 Table_Low_Bound => 0, 218 Table_Initial => 200, 219 Table_Increment => 200, 220 Table_Name => "Name_No_Use_Of_Entity"); 221 222 -- Note that in addition to making an entry in this table, we also set the 223 -- Boolean2 flag of the Name_Table entry for the simple name of the entity. 224 -- This is used to avoid most useless searches of this table. 225 226 ----------------- 227 -- Subprograms -- 228 ----------------- 229 230 -- Note: several of these subprograms can generate error messages (e.g. 231 -- Check_Restriction). These routines should be called in the analyzer 232 -- rather than the expander, so that the associated error messages are 233 -- correctly generated in semantics only (-gnatc) mode. 234 235 function Abort_Allowed return Boolean; 236 pragma Inline (Abort_Allowed); 237 -- Tests to see if abort is allowed by the current restrictions settings. 238 -- For abort to be allowed, either No_Abort_Statements must be False, 239 -- or Max_Asynchronous_Select_Nesting must be non-zero. 240 241 procedure Check_Compiler_Unit (Feature : String; N : Node_Id); 242 -- If unit N is in a unit that has a pragma Compiler_Unit_Warning, then 243 -- a message is posted on node N noting use of the given feature is not 244 -- permitted in the compiler (bootstrap considerations). 245 246 procedure Check_Compiler_Unit (Feature : String; Loc : Source_Ptr); 247 -- If unit N is in a unit that has a pragma Compiler_Unit_Warning, then a 248 -- message is posted at location Loc noting use of the given feature is not 249 -- permitted in the compiler (bootstrap considerations). 250 251 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id); 252 -- Checks if loading of unit U is prohibited by the setting of some 253 -- restriction (e.g. No_IO restricts the loading of unit Ada.Text_IO). 254 -- If a restriction exists post error message at the given node. 255 256 procedure Check_Restriction 257 (Msg_Issued : out Boolean; 258 R : Restriction_Id; 259 N : Node_Id; 260 V : Uint := Uint_Minus_1); 261 -- Checks that the given restriction is not set, and if it is set, an 262 -- appropriate message is posted on the given node, in which case 263 -- Msg_Issued is set to True (and False otherwise). Also records the 264 -- violation in the appropriate internal arrays. Note that it is mandatory 265 -- to always use this routine to check if a restriction is violated. Such 266 -- checks must never be done directly by the caller, since otherwise 267 -- violations in the absence of restrictions are not properly recorded. The 268 -- value of V is relevant only for parameter restrictions, and in this case 269 -- indicates the exact count for the violation. If the exact count is not 270 -- known, V is left at its default of -1 which indicates an unknown count. 271 272 procedure Check_Restriction 273 (R : Restriction_Id; 274 N : Node_Id; 275 V : Uint := Uint_Minus_1); 276 -- Wrapper on Check_Restriction with Msg_Issued, with the out-parameter 277 -- being ignored here. 278 279 procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id); 280 -- Called when a dependence on a unit is created (either implicitly, or by 281 -- an explicit WITH clause). U is a node for the unit involved, and Err is 282 -- the node to which an error will be attached if necessary. 283 284 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id); 285 -- N is the node id for an N_Aspect_Specification. An error message 286 -- (warning) will be issued if a restriction (warning) was previously set 287 -- for this aspect using Set_No_Specification_Of_Aspect. 288 289 procedure Check_Restriction_No_Use_Of_Attribute (N : Node_Id); 290 -- N denotes an attribute definition clause or an attribute reference. An 291 -- error message (warning) will be issued if a restriction (warning) was 292 -- previously set for this attribute using Set_No_Use_Of_Attribute. 293 294 procedure Check_Restriction_No_Use_Of_Entity (N : Node_Id); 295 -- N is the node id for an entity reference. An error message (warning) 296 -- will be issued if a restriction (warning) was previously set for this 297 -- entity name using Set_No_Use_Of_Entity. 298 299 procedure Check_Restriction_No_Use_Of_Pragma (N : Node_Id); 300 -- N is the node of a pragma. An error message (warning) will be issued 301 -- if a restriction (warning) was previously set for this pragma using 302 -- Set_No_Use_Of_Pragma. 303 304 procedure Check_Elaboration_Code_Allowed (N : Node_Id); 305 -- Tests to see if elaboration code is allowed by the current restrictions 306 -- settings. This function is called by Gigi when it needs to define an 307 -- elaboration routine. If elaboration code is not allowed, an error 308 -- message is posted on the node given as argument. 309 310 -- WARNING: There is a matching C declaration of this subprogram in fe.h 311 312 procedure Check_SPARK_05_Restriction 313 (Msg : String; 314 N : Node_Id; 315 Force : Boolean := False); 316 -- Node N represents a construct not allowed in SPARK_05 mode. If this is 317 -- a source node, or if the restriction is forced (Force = True), and 318 -- the SPARK_05 restriction is set, then an error is issued on N. Msg 319 -- is appended to the restriction failure message. 320 321 procedure Check_SPARK_05_Restriction 322 (Msg1 : String; 323 Msg2 : String; 324 N : Node_Id); 325 -- Same as Check_SPARK_05_Restriction except there is a continuation 326 -- message Msg2 following the initial message Msg1. 327 328 procedure Check_No_Implicit_Aliasing (Obj : Node_Id); 329 -- Obj is a node for which Is_Aliased_View is True, which is being used in 330 -- a context (e.g. 'Access) where no implicit aliasing is allowed if the 331 -- restriction No_Implicit_Aliasing is set. This procedure checks for the 332 -- case where the restriction is active and Obj does not meet the required 333 -- rules for avoiding implicit aliases, and issues a restriction message. 334 335 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id); 336 -- Tests to see if dynamic code generation (dynamically generated 337 -- trampolines, in particular) is allowed by the current restrictions 338 -- settings. This function is called by Gigi when it needs to generate code 339 -- that generates a trampoline. If not allowed, an error message is posted 340 -- on the node given as argument. 341 342 -- WARNING: There is a matching C declaration of this subprogram in fe.h 343 344 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id); 345 -- Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N). 346 -- Provided for easy use by back end, which has to check this restriction. 347 348 -- WARNING: There is a matching C declaration of this subprogram in fe.h 349 350 procedure Check_No_Implicit_Protected_Alloc (N : Node_Id); 351 -- Equivalent to: 352 -- Check_Restriction (No_Implicit_Protected_Object_Allocations, N) 353 -- Provided for easy use by back end, which has to check this restriction. 354 355 -- WARNING: There is a matching C declaration of this subprogram in fe.h 356 357 procedure Check_No_Implicit_Task_Alloc (N : Node_Id); 358 -- Equivalent to Check_Restriction (No_Implicit_Task_Allocations, N). 359 -- Provided for easy use by back end, which has to check this restriction. 360 361 -- WARNING: There is a matching C declaration of this subprogram in fe.h 362 363 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id); 364 -- This routine checks if the entity E is one of the obsolescent entries 365 -- in Ada.Characters.Handling in Ada 2005 and No_Obsolescent_Features 366 -- restriction is active. If so an appropriate message is given. N is 367 -- the node on which the message is to be placed. It's a bit kludgy to 368 -- have this highly specialized routine rather than some wonderful general 369 -- mechanism (e.g. a special pragma) to handle this case, but there are 370 -- only six cases, and it is not worth the effort to do something general. 371 372 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id); 373 -- This procedure checks if the No_Wide_Character restriction is active, 374 -- and if so, if N Comes_From_Source, and the root type of E is one of 375 -- [Wide_]Wide_Character or [Wide_]Wide_String, then the restriction 376 -- violation is recorded, and an appropriate message given. 377 378 function Get_Restriction_Id 379 (N : Name_Id) return Restriction_Id; 380 -- Given an identifier name, determines if it is a valid restriction 381 -- identifier, and if so returns the corresponding Restriction_Id value, 382 -- otherwise returns Not_A_Restriction_Id. 383 384 function OK_No_Dependence_Unit_Name (N : Node_Id) return Boolean; 385 -- Used in checking No_Dependence argument of pragma Restrictions or 386 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns 387 -- True if N has the proper form for a unit name, False otherwise. 388 389 function OK_No_Use_Of_Entity_Name (N : Node_Id) return Boolean; 390 -- Used in checking No_Use_Of_Entity argument of pragma Restrictions or 391 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns 392 -- True if N has the proper form for an entity name, False otherwise. 393 394 function Is_In_Hidden_Part_In_SPARK (Loc : Source_Ptr) return Boolean; 395 -- Determine if given location is covered by a hidden region range in the 396 -- SPARK hides table. 397 398 function No_Exception_Handlers_Set return Boolean; 399 -- Test to see if current restrictions settings specify that no exception 400 -- handlers are present. This function is called by Gigi when it needs to 401 -- expand an AT END clean up identifier with no exception handler. True 402 -- will be returned if the configurable run-time is activated, and either 403 -- of the restrictions No_Exception_Handlers or No_Exception_Propagation is 404 -- set. In the latter case, the source may contain handlers but they either 405 -- get converted using the local goto transformation or deleted. 406 407 -- WARNING: There is a matching C declaration of this subprogram in fe.h 408 409 function No_Exception_Propagation_Active return Boolean; 410 -- Test to see if current restrictions settings specify that no 411 -- exception propagation is activated. 412 413 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id; 414 -- Id is a node whose Chars field contains the name of a restriction. 415 -- If it is one of synonyms that we allow for historical purposes (for 416 -- list see System.Rident), then the proper official name is returned. 417 418 function Restriction_Active (R : All_Restrictions) return Boolean; 419 pragma Inline (Restriction_Active); 420 -- Determines if a given restriction is active. This call should only be 421 -- used where the compiled code depends on whether the restriction is 422 -- active. Always use Check_Restriction to record a violation. Note that 423 -- this returns False if we only have a Restriction_Warnings set, since 424 -- restriction warnings should never affect generated code. If you want 425 -- to know if a call to Check_Restriction is needed then use the function 426 -- Restriction_Check_Required instead. 427 428 function Restriction_Check_Required (R : All_Restrictions) return Boolean; 429 pragma Inline (Restriction_Check_Required); 430 -- Determines if either a Restriction_Warnings or Restrictions pragma has 431 -- been given for the specified restriction. If true, then a subsequent 432 -- call to Check_Restriction is required if the restriction is violated. 433 -- This must not be used to guard code generation that depends on whether 434 -- a restriction is active (see Restriction_Active above). Typically it 435 -- is used to avoid complex code to determine if a restriction is violated, 436 -- executing this code only if needed. 437 438 function Restricted_Profile return Boolean; 439 -- Tests if set of restrictions corresponding to Restricted_Tasking profile 440 -- is currently in effect (set by pragma Profile, or by an appropriate set 441 -- of individual Restrictions pragmas). Returns True only if all the 442 -- required restrictions are set. 443 444 procedure Set_Hidden_Part_In_SPARK (Loc1, Loc2 : Source_Ptr); 445 -- Insert a new hidden region range in the SPARK hides table. The effect 446 -- is to hide any SPARK violation messages which are in the range Loc1 to 447 -- Loc2-1 (i.e. Loc2 is the first location for reenabling checks). 448 449 procedure Set_Profile_Restrictions 450 (P : Profile_Name; 451 N : Node_Id; 452 Warn : Boolean); 453 -- Sets the set of restrictions associated with the given profile name. N 454 -- is the node of the construct to which error messages are to be attached 455 -- as required. Warn is set True for the case of Profile_Warnings where the 456 -- restrictions are set as warnings rather than legality requirements, and 457 -- is also True for Profile if the Treat_Restrictions_As_Warnings flag is 458 -- set. It is false for Profile if this flag is not set. 459 460 procedure Set_Restriction 461 (R : All_Boolean_Restrictions; 462 N : Node_Id); 463 -- N is a node (typically a pragma node) that has the effect of setting 464 -- Boolean restriction R. The restriction is set in Restrictions, and 465 -- also in Main_Restrictions if this is the main unit. 466 467 procedure Set_Restriction 468 (R : All_Parameter_Restrictions; 469 N : Node_Id; 470 V : Integer); 471 -- Similar to the above, except that this is used for the case of a 472 -- parameter restriction, and the corresponding value V is given. 473 474 procedure Set_Restriction_No_Dependence 475 (Unit : Node_Id; 476 Warn : Boolean; 477 Profile : Profile_Name := No_Profile); 478 -- Sets given No_Dependence restriction in table if not there already. Warn 479 -- is True if from Restriction_Warnings, or for Restrictions if the flag 480 -- Treat_Restrictions_As_Warnings is set. False if from Restrictions and 481 -- this flag is not set. Profile is set to a non-default value if the 482 -- No_Dependence restriction comes from a Profile pragma. 483 484 procedure Set_Restriction_No_Specification_Of_Aspect 485 (N : Node_Id; 486 Warning : Boolean); 487 -- N is the node id for an identifier from a pragma Restrictions for the 488 -- No_Specification_Of_Aspect pragma. An error message will be issued if 489 -- the identifier is not a valid aspect name. Warning is set True for the 490 -- case of a Restriction_Warnings pragma specifying this restriction and 491 -- False for a Restrictions pragma specifying this restriction. 492 493 procedure Set_Restriction_No_Specification_Of_Aspect (A_Id : Aspect_Id); 494 -- Version used by Get_Target_Parameters (via Tbuild) 495 496 procedure Set_Restriction_No_Use_Of_Attribute 497 (N : Node_Id; 498 Warning : Boolean); 499 -- N is the node id for the identifier in a pragma Restrictions for 500 -- No_Use_Of_Attribute. Caller has verified that this is a valid attribute 501 -- designator. 502 503 procedure Set_Restriction_No_Use_Of_Attribute (A_Id : Attribute_Id); 504 -- Version used by Get_Target_Parameters (via Tbuild) 505 506 procedure Set_Restriction_No_Use_Of_Entity 507 (Entity : Node_Id; 508 Warning : Boolean; 509 Profile : Profile_Name := No_Profile); 510 -- Sets given No_Use_Of_Entity restriction in table if not there already. 511 -- Warn is True if from Restriction_Warnings, or for Restrictions if the 512 -- flag Treat_Restrictions_As_Warnings is set. False if from Restrictions 513 -- and this flag is not set. Profile is set to a non-default value if the 514 -- No_Dependence restriction comes from a Profile pragma. This procedure 515 -- also takes care of setting the Boolean2 flag of the simple name for 516 -- the entity (to optimize table searches). 517 518 procedure Set_Restriction_No_Use_Of_Pragma 519 (N : Node_Id; 520 Warning : Boolean); 521 -- N is the node id for the identifier in a pragma Restrictions for 522 -- No_Use_Of_Pragma. Caller has verified that this is a valid pragma id. 523 524 procedure Set_Restriction_No_Use_Of_Pragma (A_Id : Pragma_Id); 525 -- Version used in call from Get_Target_Parameters (via Tbuild). 526 527 function Tasking_Allowed return Boolean; 528 pragma Inline (Tasking_Allowed); 529 -- Tests if tasking operations are allowed by the current restrictions 530 -- settings. For tasking to be allowed Max_Tasks must be non-zero. 531 532 ---------------------------------------------- 533 -- Handling of Boolean Compilation Switches -- 534 ---------------------------------------------- 535 536 -- The following declarations are used for proper saving and restoring of 537 -- restrictions for separate compilation units. There are two cases: 538 539 -- For partition-wide restrictions, we just let the restrictions pragmas 540 -- pile up, and we never reset them. We might as well detect what we can 541 -- at compile time. If e.g. a with'ed unit has a restriction for one of 542 -- the partition-wide restrictions, then the binder will enforce it on 543 -- all units in the partition, including the unit with the WITH. Although 544 -- it would not be wrong to leave this till bind time, we might as well 545 -- flag it earlier at compile time. 546 547 -- For non-partition-wide restrictions, we have quite a different state 548 -- of affairs. Here it would be quite wrong to carry a restriction from 549 -- a with'ed unit to another with'ed unit, or from a package spec to the 550 -- package body. This means that we have to reset these non-partition 551 -- wide restrictions at the start of each separate compilation unit. For 552 -- units in the extended main program, we need to reset them all to the 553 -- values set by the configuration pragma file(s). For units not in the 554 -- extended main program, e.g. with'ed units, we might as well reset all 555 -- of these restrictions to off (False). The actual initial values will 556 -- be taken from the config files active when those units are compiled 557 -- as main units. 558 559 type Save_Cunit_Boolean_Restrictions is private; 560 -- Type used for saving and restoring compilation unit restrictions. 561 562 function Cunit_Boolean_Restrictions_Save 563 return Save_Cunit_Boolean_Restrictions; 564 -- This function saves the compilation unit restriction settings, leaving 565 -- them unchanged. This is used e.g. at the start of processing a context 566 -- clause, so that the main unit restrictions can be restored after all 567 -- the with'ed units have been processed. 568 569 procedure Cunit_Boolean_Restrictions_Restore 570 (R : Save_Cunit_Boolean_Restrictions); 571 -- This is the corresponding restore procedure to restore restrictions 572 -- previously saved by Cunit_Boolean_Restrictions_Save. However it does 573 -- not reset No_Elaboration_Code, this stays set if it was set before 574 -- the call, and also if it is set before the call, then the Config 575 -- setting is also updated to include this restriction. This is what 576 -- implements the special handling of No_Elaboration_Code. 577 578 procedure Save_Config_Cunit_Boolean_Restrictions; 579 -- This saves the current compilation unit restrictions in an internal 580 -- variable, and leaves them unchanged. This is called immediately after 581 -- processing the configuration file pragmas, to record the restrictions 582 -- set by these configuration file pragmas. 583 584 procedure Restore_Config_Cunit_Boolean_Restrictions; 585 -- This restores the value saved by the previous call to save config values 586 -- saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the 587 -- start of processing a new unit that is part of the main sources (e.g. 588 -- a package spec when the main unit is a package body). 589 590 procedure Reset_Cunit_Boolean_Restrictions; 591 -- Turns off all non-partition-wide boolean restrictions 592 593 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id); 594 -- Add specified restriction to stored configuration boolean restrictions. 595 -- This is used for handling the special case of No_Elaboration_Code. 596 597private 598 type Save_Cunit_Boolean_Restrictions is 599 array (Cunit_Boolean_Restrictions) of Boolean; 600 -- Type used for saving and restoring compilation unit restrictions. 601 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms. 602 603end Restrict; 604