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-2015, 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 is the node of an attribute definition clause. An error message 291 -- (warning) will be issued if a restriction (warning) was previously set 292 -- 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 procedure Check_SPARK_05_Restriction 311 (Msg : String; 312 N : Node_Id; 313 Force : Boolean := False); 314 -- Node N represents a construct not allowed in SPARK_05 mode. If this is 315 -- a source node, or if the restriction is forced (Force = True), and 316 -- the SPARK_05 restriction is set, then an error is issued on N. Msg 317 -- is appended to the restriction failure message. 318 319 procedure Check_SPARK_05_Restriction (Msg1, Msg2 : String; N : Node_Id); 320 -- Same as Check_SPARK_05_Restriction except there is a continuation 321 -- message Msg2 following the initial message Msg1. 322 323 procedure Check_No_Implicit_Aliasing (Obj : Node_Id); 324 -- Obj is a node for which Is_Aliased_View is True, which is being used in 325 -- a context (e.g. 'Access) where no implicit aliasing is allowed if the 326 -- restriction No_Implicit_Aliasing is set. This procedure checks for the 327 -- case where the restriction is active and Obj does not meet the required 328 -- rules for avoiding implicit aliases, and issues a restriction message. 329 330 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id); 331 -- Tests to see if dynamic code generation (dynamically generated 332 -- trampolines, in particular) is allowed by the current restrictions 333 -- settings. This function is called by Gigi when it needs to generate code 334 -- that generates a trampoline. If not allowed, an error message is posted 335 -- on the node given as argument. 336 337 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id); 338 -- Equivalent to Check_Restriction (No_Implicit_Heap_Allocations, N). 339 -- Provided for easy use by back end, which has to check this restriction. 340 341 procedure Check_No_Implicit_Task_Alloc (N : Node_Id); 342 -- Equivalent to Check_Restriction (No_Implicit_Task_Allocations, N). 343 -- Provided for easy use by back end, which has to check this restriction. 344 345 procedure Check_No_Implicit_Protected_Alloc (N : Node_Id); 346 -- Equivalent to: 347 -- Check_Restriction (No_Implicit_Protected_Object_Allocations, N) 348 -- Provided for easy use by back end, which has to check this restriction. 349 350 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id); 351 -- This routine checks if the entity E is one of the obsolescent entries 352 -- in Ada.Characters.Handling in Ada 2005 and No_Obsolescent_Features 353 -- restriction is active. If so an appropriate message is given. N is 354 -- the node on which the message is to be placed. It's a bit kludgy to 355 -- have this highly specialized routine rather than some wonderful general 356 -- mechanism (e.g. a special pragma) to handle this case, but there are 357 -- only six cases, and it is not worth the effort to do something general. 358 359 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id); 360 -- This procedure checks if the No_Wide_Character restriction is active, 361 -- and if so, if N Comes_From_Source, and the root type of E is one of 362 -- [Wide_]Wide_Character or [Wide_]Wide_String, then the restriction 363 -- violation is recorded, and an appropriate message given. 364 365 function Get_Restriction_Id 366 (N : Name_Id) return Restriction_Id; 367 -- Given an identifier name, determines if it is a valid restriction 368 -- identifier, and if so returns the corresponding Restriction_Id value, 369 -- otherwise returns Not_A_Restriction_Id. 370 371 function OK_No_Dependence_Unit_Name (N : Node_Id) return Boolean; 372 -- Used in checking No_Dependence argument of pragma Restrictions or 373 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns 374 -- True if N has the proper form for a unit name, False otherwise. 375 376 function OK_No_Use_Of_Entity_Name (N : Node_Id) return Boolean; 377 -- Used in checking No_Use_Of_Entity argument of pragma Restrictions or 378 -- pragma Restrictions_Warning, or attribute Restriction_Set. Returns 379 -- True if N has the proper form for an entity name, False otherwise. 380 381 function Is_In_Hidden_Part_In_SPARK (Loc : Source_Ptr) return Boolean; 382 -- Determine if given location is covered by a hidden region range in the 383 -- SPARK hides table. 384 385 function No_Exception_Handlers_Set return Boolean; 386 -- Test to see if current restrictions settings specify that no exception 387 -- handlers are present. This function is called by Gigi when it needs to 388 -- expand an AT END clean up identifier with no exception handler. True 389 -- will be returned if the configurable run-time is activated, and either 390 -- of the restrictions No_Exception_Handlers or No_Exception_Propagation is 391 -- set. In the latter case, the source may contain handlers but they either 392 -- get converted using the local goto transformation or deleted. 393 394 function No_Exception_Propagation_Active return Boolean; 395 -- Test to see if current restrictions settings specify that no 396 -- exception propagation is activated. 397 398 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id; 399 -- Id is a node whose Chars field contains the name of a restriction. 400 -- If it is one of synonyms that we allow for historical purposes (for 401 -- list see System.Rident), then the proper official name is returned. 402 403 function Restriction_Active (R : All_Restrictions) return Boolean; 404 pragma Inline (Restriction_Active); 405 -- Determines if a given restriction is active. This call should only be 406 -- used where the compiled code depends on whether the restriction is 407 -- active. Always use Check_Restriction to record a violation. Note that 408 -- this returns False if we only have a Restriction_Warnings set, since 409 -- restriction warnings should never affect generated code. If you want 410 -- to know if a call to Check_Restriction is needed then use the function 411 -- Restriction_Check_Required instead. 412 413 function Restriction_Check_Required (R : All_Restrictions) return Boolean; 414 pragma Inline (Restriction_Check_Required); 415 -- Determines if either a Restriction_Warnings or Restrictions pragma has 416 -- been given for the specified restriction. If true, then a subsequent 417 -- call to Check_Restriction is required if the restriction is violated. 418 -- This must not be used to guard code generation that depends on whether 419 -- a restriction is active (see Restriction_Active above). Typically it 420 -- is used to avoid complex code to determine if a restriction is violated, 421 -- executing this code only if needed. 422 423 function Restricted_Profile return Boolean; 424 -- Tests if set of restrictions corresponding to Profile (Restricted) is 425 -- currently in effect (set by pragma Profile, or by an appropriate set of 426 -- individual Restrictions pragmas). Returns True only if all the required 427 -- restrictions are set. 428 429 procedure Set_Hidden_Part_In_SPARK (Loc1, Loc2 : Source_Ptr); 430 -- Insert a new hidden region range in the SPARK hides table. The effect 431 -- is to hide any SPARK violation messages which are in the range Loc1 to 432 -- Loc2-1 (i.e. Loc2 is the first location for reenabling checks). 433 434 procedure Set_Profile_Restrictions 435 (P : Profile_Name; 436 N : Node_Id; 437 Warn : Boolean); 438 -- Sets the set of restrictions associated with the given profile name. N 439 -- is the node of the construct to which error messages are to be attached 440 -- as required. Warn is set True for the case of Profile_Warnings where the 441 -- restrictions are set as warnings rather than legality requirements, and 442 -- is also True for Profile if the Treat_Restrictions_As_Warnings flag is 443 -- set. It is false for Profile if this flag is not set. 444 445 procedure Set_Restriction 446 (R : All_Boolean_Restrictions; 447 N : Node_Id); 448 -- N is a node (typically a pragma node) that has the effect of setting 449 -- Boolean restriction R. The restriction is set in Restrictions, and 450 -- also in Main_Restrictions if this is the main unit. 451 452 procedure Set_Restriction 453 (R : All_Parameter_Restrictions; 454 N : Node_Id; 455 V : Integer); 456 -- Similar to the above, except that this is used for the case of a 457 -- parameter restriction, and the corresponding value V is given. 458 459 procedure Set_Restriction_No_Dependence 460 (Unit : Node_Id; 461 Warn : Boolean; 462 Profile : Profile_Name := No_Profile); 463 -- Sets given No_Dependence restriction in table if not there already. Warn 464 -- is True if from Restriction_Warnings, or for Restrictions if the flag 465 -- Treat_Restrictions_As_Warnings is set. False if from Restrictions and 466 -- this flag is not set. Profile is set to a non-default value if the 467 -- No_Dependence restriction comes from a Profile pragma. 468 469 procedure Set_Restriction_No_Specification_Of_Aspect 470 (N : Node_Id; 471 Warning : Boolean); 472 -- N is the node id for an identifier from a pragma Restrictions for the 473 -- No_Specification_Of_Aspect pragma. An error message will be issued if 474 -- the identifier is not a valid aspect name. Warning is set True for the 475 -- case of a Restriction_Warnings pragma specifying this restriction and 476 -- False for a Restrictions pragma specifying this restriction. 477 478 procedure Set_Restriction_No_Specification_Of_Aspect (A_Id : Aspect_Id); 479 -- Version used by Get_Target_Parameters (via Tbuild) 480 481 procedure Set_Restriction_No_Use_Of_Attribute 482 (N : Node_Id; 483 Warning : Boolean); 484 -- N is the node id for the identifier in a pragma Restrictions for 485 -- No_Use_Of_Attribute. Caller has verified that this is a valid attribute 486 -- designator. 487 488 procedure Set_Restriction_No_Use_Of_Attribute (A_Id : Attribute_Id); 489 -- Version used by Get_Target_Parameters (via Tbuild) 490 491 procedure Set_Restriction_No_Use_Of_Entity 492 (Entity : Node_Id; 493 Warn : Boolean; 494 Profile : Profile_Name := No_Profile); 495 -- Sets given No_Use_Of_Entity restriction in table if not there already. 496 -- Warn is True if from Restriction_Warnings, or for Restrictions if the 497 -- flag Treat_Restrictions_As_Warnings is set. False if from Restrictions 498 -- and this flag is not set. Profile is set to a non-default value if the 499 -- No_Dependence restriction comes from a Profile pragma. This procedure 500 -- also takes care of setting the Boolean2 flag of the simple name for 501 -- the entity (to optimize table searches). 502 503 procedure Set_Restriction_No_Use_Of_Pragma 504 (N : Node_Id; 505 Warning : Boolean); 506 -- N is the node id for the identifier in a pragma Restrictions for 507 -- No_Use_Of_Pragma. Caller has verified that this is a valid pragma id. 508 509 procedure Set_Restriction_No_Use_Of_Pragma (A_Id : Pragma_Id); 510 -- Version used in call from Get_Target_Parameters (via Tbuild). 511 512 function Tasking_Allowed return Boolean; 513 pragma Inline (Tasking_Allowed); 514 -- Tests if tasking operations are allowed by the current restrictions 515 -- settings. For tasking to be allowed Max_Tasks must be non-zero. 516 517 ---------------------------------------------- 518 -- Handling of Boolean Compilation Switches -- 519 ---------------------------------------------- 520 521 -- The following declarations are used for proper saving and restoring of 522 -- restrictions for separate compilation units. There are two cases: 523 524 -- For partition-wide restrictions, we just let the restrictions pragmas 525 -- pile up, and we never reset them. We might as well detect what we can 526 -- at compile time. If e.g. a with'ed unit has a restriction for one of 527 -- the partition-wide restrictions, then the binder will enforce it on 528 -- all units in the partition, including the unit with the WITH. Although 529 -- it would not be wrong to leave this till bind time, we might as well 530 -- flag it earlier at compile time. 531 532 -- For non-partition-wide restrictions, we have quite a different state 533 -- of affairs. Here it would be quite wrong to carry a restriction from 534 -- a with'ed unit to another with'ed unit, or from a package spec to the 535 -- package body. This means that we have to reset these non-partition 536 -- wide restrictions at the start of each separate compilation unit. For 537 -- units in the extended main program, we need to reset them all to the 538 -- values set by the configuration pragma file(s). For units not in the 539 -- extended main program, e.g. with'ed units, we might as well reset all 540 -- of these restrictions to off (False). The actual initial values will 541 -- be taken from the config files active when those units are compiled 542 -- as main units. 543 544 type Save_Cunit_Boolean_Restrictions is private; 545 -- Type used for saving and restoring compilation unit restrictions. 546 547 function Cunit_Boolean_Restrictions_Save 548 return Save_Cunit_Boolean_Restrictions; 549 -- This function saves the compilation unit restriction settings, leaving 550 -- them unchanged. This is used e.g. at the start of processing a context 551 -- clause, so that the main unit restrictions can be restored after all 552 -- the with'ed units have been processed. 553 554 procedure Cunit_Boolean_Restrictions_Restore 555 (R : Save_Cunit_Boolean_Restrictions); 556 -- This is the corresponding restore procedure to restore restrictions 557 -- previously saved by Cunit_Boolean_Restrictions_Save. However it does 558 -- not reset No_Elaboration_Code, this stays set if it was set before 559 -- the call, and also if it is set before the call, then the Config 560 -- setting is also updated to include this restriction. This is what 561 -- implements the special handling of No_Elaboration_Code. 562 563 procedure Save_Config_Cunit_Boolean_Restrictions; 564 -- This saves the current compilation unit restrictions in an internal 565 -- variable, and leaves them unchanged. This is called immediately after 566 -- processing the configuration file pragmas, to record the restrictions 567 -- set by these configuration file pragmas. 568 569 procedure Restore_Config_Cunit_Boolean_Restrictions; 570 -- This restores the value saved by the previous call to save config values 571 -- saved by Save_Config_Cunit_Boolean_Restrictions. It is called at the 572 -- start of processing a new unit that is part of the main sources (e.g. 573 -- a package spec when the main unit is a package body). 574 575 procedure Reset_Cunit_Boolean_Restrictions; 576 -- Turns off all non-partition-wide boolean restrictions 577 578 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id); 579 -- Add specified restriction to stored configuration boolean restrictions. 580 -- This is used for handling the special case of No_Elaboration_Code. 581 582private 583 type Save_Cunit_Boolean_Restrictions is 584 array (Cunit_Boolean_Restrictions) of Boolean; 585 -- Type used for saving and restoring compilation unit restrictions. 586 -- See Compilation_Unit_Restrictions_[Save|Restore] subprograms. 587 588end Restrict; 589