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