8983f78ee1cb9f4b7f9d29ef49422b367427d604
[gcc.git] / gcc / ada / restrict.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- R E S T R I C T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, 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 Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Einfo; use Einfo;
30 with Errout; use Errout;
31 with Debug; use Debug;
32 with Fname; use Fname;
33 with Fname.UF; use Fname.UF;
34 with Lib; use Lib;
35 with Opt; use Opt;
36 with Sinfo; use Sinfo;
37 with Sinput; use Sinput;
38 with Snames; use Snames;
39 with Stand; use Stand;
40 with Uname; use Uname;
41
42 package body Restrict is
43
44 -------------------------------
45 -- SPARK Restriction Control --
46 -------------------------------
47
48 -- SPARK HIDE directives allow the effect of the SPARK_05 restriction to be
49 -- turned off for a specified region of code, and the following tables are
50 -- the data structures used to keep track of these regions.
51
52 -- The table contains pairs of source locations, the first being the start
53 -- location for hidden region, and the second being the end location.
54
55 -- Note that the start location is included in the hidden region, while
56 -- the end location is excluded from it. (It typically corresponds to the
57 -- next token during scanning.)
58
59 type SPARK_Hide_Entry is record
60 Start : Source_Ptr;
61 Stop : Source_Ptr;
62 end record;
63
64 package SPARK_Hides is new Table.Table (
65 Table_Component_Type => SPARK_Hide_Entry,
66 Table_Index_Type => Natural,
67 Table_Low_Bound => 1,
68 Table_Initial => 100,
69 Table_Increment => 200,
70 Table_Name => "SPARK Hides");
71
72 --------------------------------
73 -- Package Local Declarations --
74 --------------------------------
75
76 Config_Cunit_Boolean_Restrictions : Save_Cunit_Boolean_Restrictions;
77 -- Save compilation unit restrictions set by config pragma files
78
79 Restricted_Profile_Result : Boolean := False;
80 -- This switch memoizes the result of Restricted_Profile function calls for
81 -- improved efficiency. Valid only if Restricted_Profile_Cached is True.
82 -- Note: if this switch is ever set True, it is never turned off again.
83
84 Restricted_Profile_Cached : Boolean := False;
85 -- This flag is set to True if the Restricted_Profile_Result contains the
86 -- correct cached result of Restricted_Profile calls.
87
88 No_Specification_Of_Aspects : array (Aspect_Id) of Source_Ptr :=
89 (others => No_Location);
90 -- Entries in this array are set to point to a previously occuring pragma
91 -- that activates a No_Specification_Of_Aspect check.
92
93 No_Specification_Of_Aspect_Warning : array (Aspect_Id) of Boolean :=
94 (others => True);
95 -- An entry in this array is set False in reponse to a previous call to
96 -- Set_No_Speficiation_Of_Aspect for pragmas in the main unit that
97 -- specify Warning as False. Once set False, an entry is never reset.
98
99 No_Specification_Of_Aspect_Set : Boolean := False;
100 -- Set True if any entry of No_Specifcation_Of_Aspects has been set True.
101 -- Once set True, this is never turned off again.
102
103 No_Use_Of_Attribute : array (Attribute_Id) of Source_Ptr :=
104 (others => No_Location);
105
106 No_Use_Of_Attribute_Warning : array (Attribute_Id) of Boolean :=
107 (others => False);
108
109 No_Use_Of_Attribute_Set : Boolean := False;
110 -- Indicates that No_Use_Of_Attribute was set at least once
111
112 No_Use_Of_Pragma : array (Pragma_Id) of Source_Ptr :=
113 (others => No_Location);
114
115 No_Use_Of_Pragma_Warning : array (Pragma_Id) of Boolean :=
116 (others => False);
117
118 No_Use_Of_Pragma_Set : Boolean := False;
119 -- Indicates that No_Use_Of_Pragma was set at least once
120
121 -----------------------
122 -- Local Subprograms --
123 -----------------------
124
125 procedure Restriction_Msg (R : Restriction_Id; N : Node_Id);
126 -- Called if a violation of restriction R at node N is found. This routine
127 -- outputs the appropriate message or messages taking care of warning vs
128 -- real violation, serious vs non-serious, implicit vs explicit, the second
129 -- message giving the profile name if needed, and the location information.
130
131 function Same_Unit (U1, U2 : Node_Id) return Boolean;
132 -- Returns True iff U1 and U2 represent the same library unit. Used for
133 -- handling of No_Dependence => Unit restriction case.
134
135 function Suppress_Restriction_Message (N : Node_Id) return Boolean;
136 -- N is the node for a possible restriction violation message, but the
137 -- message is to be suppressed if this is an internal file and this file is
138 -- not the main unit. Returns True if message is to be suppressed.
139
140 -------------------
141 -- Abort_Allowed --
142 -------------------
143
144 function Abort_Allowed return Boolean is
145 begin
146 if Restrictions.Set (No_Abort_Statements)
147 and then Restrictions.Set (Max_Asynchronous_Select_Nesting)
148 and then Restrictions.Value (Max_Asynchronous_Select_Nesting) = 0
149 then
150 return False;
151 else
152 return True;
153 end if;
154 end Abort_Allowed;
155
156 ----------------------------------------
157 -- Add_To_Config_Boolean_Restrictions --
158 ----------------------------------------
159
160 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id) is
161 begin
162 Config_Cunit_Boolean_Restrictions (R) := True;
163 end Add_To_Config_Boolean_Restrictions;
164 -- Add specified restriction to stored configuration boolean restrictions.
165 -- This is used for handling the special case of No_Elaboration_Code.
166
167 -------------------------
168 -- Check_Compiler_Unit --
169 -------------------------
170
171 procedure Check_Compiler_Unit (Feature : String; N : Node_Id) is
172 begin
173 if Compiler_Unit then
174 Error_Msg_N (Feature & " not allowed in compiler unit!!??", N);
175 end if;
176 end Check_Compiler_Unit;
177
178 procedure Check_Compiler_Unit (Feature : String; Loc : Source_Ptr) is
179 begin
180 if Compiler_Unit then
181 Error_Msg (Feature & " not allowed in compiler unit!!??", Loc);
182 end if;
183 end Check_Compiler_Unit;
184
185 ------------------------------------
186 -- Check_Elaboration_Code_Allowed --
187 ------------------------------------
188
189 procedure Check_Elaboration_Code_Allowed (N : Node_Id) is
190 begin
191 Check_Restriction (No_Elaboration_Code, N);
192 end Check_Elaboration_Code_Allowed;
193
194 --------------------------------
195 -- Check_No_Implicit_Aliasing --
196 --------------------------------
197
198 procedure Check_No_Implicit_Aliasing (Obj : Node_Id) is
199 E : Entity_Id;
200
201 begin
202 -- If restriction not active, nothing to check
203
204 if not Restriction_Active (No_Implicit_Aliasing) then
205 return;
206 end if;
207
208 -- If we have an entity name, check entity
209
210 if Is_Entity_Name (Obj) then
211 E := Entity (Obj);
212
213 -- Restriction applies to entities that are objects
214
215 if Is_Object (E) then
216 if Is_Aliased (E) then
217 return;
218
219 elsif Present (Renamed_Object (E)) then
220 Check_No_Implicit_Aliasing (Renamed_Object (E));
221 return;
222 end if;
223
224 -- If we don't have an object, then it's OK
225
226 else
227 return;
228 end if;
229
230 -- For selected component, check selector
231
232 elsif Nkind (Obj) = N_Selected_Component then
233 Check_No_Implicit_Aliasing (Selector_Name (Obj));
234 return;
235
236 -- Indexed component is OK if aliased components
237
238 elsif Nkind (Obj) = N_Indexed_Component then
239 if Has_Aliased_Components (Etype (Prefix (Obj)))
240 or else
241 (Is_Access_Type (Etype (Prefix (Obj)))
242 and then Has_Aliased_Components
243 (Designated_Type (Etype (Prefix (Obj)))))
244 then
245 return;
246 end if;
247
248 -- For type conversion, check converted expression
249
250 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
251 Check_No_Implicit_Aliasing (Expression (Obj));
252 return;
253
254 -- Explicit dereference is always OK
255
256 elsif Nkind (Obj) = N_Explicit_Dereference then
257 return;
258 end if;
259
260 -- If we fall through, then we have an aliased view that does not meet
261 -- the rules for being explicitly aliased, so issue restriction msg.
262
263 Check_Restriction (No_Implicit_Aliasing, Obj);
264 end Check_No_Implicit_Aliasing;
265
266 -----------------------------------------
267 -- Check_Implicit_Dynamic_Code_Allowed --
268 -----------------------------------------
269
270 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id) is
271 begin
272 Check_Restriction (No_Implicit_Dynamic_Code, N);
273 end Check_Implicit_Dynamic_Code_Allowed;
274
275 ----------------------------------
276 -- Check_No_Implicit_Heap_Alloc --
277 ----------------------------------
278
279 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id) is
280 begin
281 Check_Restriction (No_Implicit_Heap_Allocations, N);
282 end Check_No_Implicit_Heap_Alloc;
283
284 -----------------------------------
285 -- Check_Obsolescent_2005_Entity --
286 -----------------------------------
287
288 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id) is
289 function Chars_Is (E : Entity_Id; S : String) return Boolean;
290 -- Return True iff Chars (E) matches S (given in lower case)
291
292 --------------
293 -- Chars_Is --
294 --------------
295
296 function Chars_Is (E : Entity_Id; S : String) return Boolean is
297 Nam : constant Name_Id := Chars (E);
298 begin
299 if Length_Of_Name (Nam) /= S'Length then
300 return False;
301 else
302 return Get_Name_String (Nam) = S;
303 end if;
304 end Chars_Is;
305
306 -- Start of processing for Check_Obsolescent_2005_Entity
307
308 begin
309 if Restriction_Check_Required (No_Obsolescent_Features)
310 and then Ada_Version >= Ada_2005
311 and then Chars_Is (Scope (E), "handling")
312 and then Chars_Is (Scope (Scope (E)), "characters")
313 and then Chars_Is (Scope (Scope (Scope (E))), "ada")
314 and then Scope (Scope (Scope (Scope (E)))) = Standard_Standard
315 then
316 if Chars_Is (E, "is_character") or else
317 Chars_Is (E, "is_string") or else
318 Chars_Is (E, "to_character") or else
319 Chars_Is (E, "to_string") or else
320 Chars_Is (E, "to_wide_character") or else
321 Chars_Is (E, "to_wide_string")
322 then
323 Check_Restriction (No_Obsolescent_Features, N);
324 end if;
325 end if;
326 end Check_Obsolescent_2005_Entity;
327
328 ---------------------------
329 -- Check_Restricted_Unit --
330 ---------------------------
331
332 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id) is
333 begin
334 if Suppress_Restriction_Message (N) then
335 return;
336
337 elsif Is_Spec_Name (U) then
338 declare
339 Fnam : constant File_Name_Type :=
340 Get_File_Name (U, Subunit => False);
341
342 begin
343 -- Get file name
344
345 Get_Name_String (Fnam);
346
347 -- Nothing to do if name not at least 5 characters long ending
348 -- in .ads or .adb extension, which we strip.
349
350 if Name_Len < 5
351 or else (Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads"
352 and then
353 Name_Buffer (Name_Len - 3 .. Name_Len) /= ".adb")
354 then
355 return;
356 end if;
357
358 -- Strip extension and pad to eight characters
359
360 Name_Len := Name_Len - 4;
361 Add_Str_To_Name_Buffer ((Name_Len + 1 .. 8 => ' '));
362
363 -- If predefined unit, check the list of restricted units
364
365 if Is_Predefined_File_Name (Fnam) then
366 for J in Unit_Array'Range loop
367 if Name_Len = 8
368 and then Name_Buffer (1 .. 8) = Unit_Array (J).Filenm
369 then
370 Check_Restriction (Unit_Array (J).Res_Id, N);
371 end if;
372 end loop;
373
374 -- If not predefined unit, then one special check still
375 -- remains. GNAT.Current_Exception is not allowed if we have
376 -- restriction No_Exception_Propagation active.
377
378 else
379 if Name_Buffer (1 .. 8) = "g-curexc" then
380 Check_Restriction (No_Exception_Propagation, N);
381 end if;
382 end if;
383 end;
384 end if;
385 end Check_Restricted_Unit;
386
387 -----------------------
388 -- Check_Restriction --
389 -----------------------
390
391 procedure Check_Restriction
392 (R : Restriction_Id;
393 N : Node_Id;
394 V : Uint := Uint_Minus_1)
395 is
396 Msg_Issued : Boolean;
397 pragma Unreferenced (Msg_Issued);
398 begin
399 Check_Restriction (Msg_Issued, R, N, V);
400 end Check_Restriction;
401
402 procedure Check_Restriction
403 (Msg_Issued : out Boolean;
404 R : Restriction_Id;
405 N : Node_Id;
406 V : Uint := Uint_Minus_1)
407 is
408 VV : Integer;
409 -- V converted to integer form. If V is greater than Integer'Last,
410 -- it is reset to minus 1 (unknown value).
411
412 procedure Update_Restrictions (Info : in out Restrictions_Info);
413 -- Update violation information in Info.Violated and Info.Count
414
415 -------------------------
416 -- Update_Restrictions --
417 -------------------------
418
419 procedure Update_Restrictions (Info : in out Restrictions_Info) is
420 begin
421 -- If not violated, set as violated now
422
423 if not Info.Violated (R) then
424 Info.Violated (R) := True;
425
426 if R in All_Parameter_Restrictions then
427 if VV < 0 then
428 Info.Unknown (R) := True;
429 Info.Count (R) := 1;
430 else
431 Info.Count (R) := VV;
432 end if;
433 end if;
434
435 -- Otherwise if violated already and a parameter restriction,
436 -- update count by maximizing or summing depending on restriction.
437
438 elsif R in All_Parameter_Restrictions then
439
440 -- If new value is unknown, result is unknown
441
442 if VV < 0 then
443 Info.Unknown (R) := True;
444
445 -- If checked by maximization, do maximization
446
447 elsif R in Checked_Max_Parameter_Restrictions then
448 Info.Count (R) := Integer'Max (Info.Count (R), VV);
449
450 -- If checked by adding, do add, checking for overflow
451
452 elsif R in Checked_Add_Parameter_Restrictions then
453 declare
454 pragma Unsuppress (Overflow_Check);
455 begin
456 Info.Count (R) := Info.Count (R) + VV;
457 exception
458 when Constraint_Error =>
459 Info.Count (R) := Integer'Last;
460 Info.Unknown (R) := True;
461 end;
462
463 -- Should not be able to come here, known counts should only
464 -- occur for restrictions that are Checked_max or Checked_Sum.
465
466 else
467 raise Program_Error;
468 end if;
469 end if;
470 end Update_Restrictions;
471
472 -- Start of processing for Check_Restriction
473
474 begin
475 Msg_Issued := False;
476
477 -- In CodePeer and SPARK mode, we do not want to check for any
478 -- restriction, or set additional restrictions other than those already
479 -- set in gnat1drv.adb so that we have consistency between each
480 -- compilation.
481
482 -- Just checking, SPARK does not allow restrictions to be set ???
483
484 if CodePeer_Mode or GNATprove_Mode then
485 return;
486 end if;
487
488 -- In SPARK mode, issue an error for any use of class-wide, even if the
489 -- No_Dispatch restriction is not set.
490
491 if R = No_Dispatch then
492 Check_SPARK_Restriction ("class-wide is not allowed", N);
493 end if;
494
495 if UI_Is_In_Int_Range (V) then
496 VV := Integer (UI_To_Int (V));
497 else
498 VV := -1;
499 end if;
500
501 -- Count can only be specified in the checked val parameter case
502
503 pragma Assert (VV < 0 or else R in Checked_Val_Parameter_Restrictions);
504
505 -- Nothing to do if value of zero specified for parameter restriction
506
507 if VV = 0 then
508 return;
509 end if;
510
511 -- Update current restrictions
512
513 Update_Restrictions (Restrictions);
514
515 -- If in main extended unit, update main restrictions as well. Note
516 -- that as usual we check for Main_Unit explicitly to deal with the
517 -- case of configuration pragma files.
518
519 if Current_Sem_Unit = Main_Unit
520 or else In_Extended_Main_Source_Unit (N)
521 then
522 Update_Restrictions (Main_Restrictions);
523 end if;
524
525 -- Nothing to do if restriction message suppressed
526
527 if Suppress_Restriction_Message (N) then
528 null;
529
530 -- If restriction not set, nothing to do
531
532 elsif not Restrictions.Set (R) then
533 null;
534
535 -- Don't complain about No_Obsolescent_Features in an instance, since we
536 -- will complain on the template, which is much better. Are there other
537 -- cases like this ??? Do we need a more general mechanism ???
538
539 elsif R = No_Obsolescent_Features
540 and then Instantiation_Location (Sloc (N)) /= No_Location
541 then
542 null;
543
544 -- Here if restriction set, check for violation (this is a Boolean
545 -- restriction, or a parameter restriction with a value of zero and an
546 -- unknown count, or a parameter restriction with a known value that
547 -- exceeds the restriction count).
548
549 elsif R in All_Boolean_Restrictions
550 or else (Restrictions.Unknown (R)
551 and then Restrictions.Value (R) = 0)
552 or else Restrictions.Count (R) > Restrictions.Value (R)
553 then
554 Msg_Issued := True;
555 Restriction_Msg (R, N);
556 end if;
557 end Check_Restriction;
558
559 -------------------------------------
560 -- Check_Restriction_No_Dependence --
561 -------------------------------------
562
563 procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id) is
564 DU : Node_Id;
565
566 begin
567 -- Ignore call if node U is not in the main source unit. This avoids
568 -- cascaded errors, e.g. when Ada.Containers units with other units.
569 -- However, allow Standard_Location here, since this catches some cases
570 -- of constructs that get converted to run-time calls.
571
572 if not In_Extended_Main_Source_Unit (U)
573 and then Sloc (U) /= Standard_Location
574 then
575 return;
576 end if;
577
578 -- Loop through entries in No_Dependence table to check each one in turn
579
580 for J in No_Dependences.First .. No_Dependences.Last loop
581 DU := No_Dependences.Table (J).Unit;
582
583 if Same_Unit (U, DU) then
584 Error_Msg_Sloc := Sloc (DU);
585 Error_Msg_Node_1 := DU;
586
587 if No_Dependences.Table (J).Warn then
588 Error_Msg
589 ("?*?violation of restriction `No_Dependence '='> &`#",
590 Sloc (Err));
591 else
592 Error_Msg
593 ("|violation of restriction `No_Dependence '='> &`#",
594 Sloc (Err));
595 end if;
596
597 return;
598 end if;
599 end loop;
600 end Check_Restriction_No_Dependence;
601
602 --------------------------------------------------
603 -- Check_Restriction_No_Specification_Of_Aspect --
604 --------------------------------------------------
605
606 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id) is
607 A_Id : Aspect_Id;
608 Id : Node_Id;
609
610 begin
611 -- Ignore call if no instances of this restriction set
612
613 if not No_Specification_Of_Aspect_Set then
614 return;
615 end if;
616
617 -- Ignore call if node N is not in the main source unit, since we only
618 -- give messages for the main unit. This avoids giving messages for
619 -- aspects that are specified in withed units.
620
621 if not In_Extended_Main_Source_Unit (N) then
622 return;
623 end if;
624
625 Id := Identifier (N);
626 A_Id := Get_Aspect_Id (Chars (Id));
627 pragma Assert (A_Id /= No_Aspect);
628
629 Error_Msg_Sloc := No_Specification_Of_Aspects (A_Id);
630
631 if Error_Msg_Sloc /= No_Location then
632 Error_Msg_Node_1 := Id;
633 Error_Msg_Warn := No_Specification_Of_Aspect_Warning (A_Id);
634 Error_Msg_N
635 ("<*<violation of restriction `No_Specification_Of_Aspect '='> &`#",
636 Id);
637 end if;
638 end Check_Restriction_No_Specification_Of_Aspect;
639
640 -------------------------------------------
641 -- Check_Restriction_No_Use_Of_Attribute --
642 --------------------------------------------
643
644 procedure Check_Restriction_No_Use_Of_Attribute (N : Node_Id) is
645 Id : constant Name_Id := Chars (N);
646 A_Id : constant Attribute_Id := Get_Attribute_Id (Id);
647
648 begin
649 -- Ignore call if node N is not in the main source unit, since we only
650 -- give messages for the main unit. This avoids giving messages for
651 -- aspects that are specified in withed units.
652
653 if not In_Extended_Main_Source_Unit (N) then
654 return;
655 end if;
656
657 -- If nothing set, nothing to check
658
659 if not No_Use_Of_Attribute_Set then
660 return;
661 end if;
662
663 Error_Msg_Sloc := No_Use_Of_Attribute (A_Id);
664
665 if Error_Msg_Sloc /= No_Location then
666 Error_Msg_Node_1 := N;
667 Error_Msg_Warn := No_Use_Of_Attribute_Warning (A_Id);
668 Error_Msg_N
669 ("<*<violation of restriction `No_Use_Of_Attribute '='> &`#", N);
670 end if;
671 end Check_Restriction_No_Use_Of_Attribute;
672
673 ----------------------------------------
674 -- Check_Restriction_No_Use_Of_Pragma --
675 ----------------------------------------
676
677 procedure Check_Restriction_No_Use_Of_Pragma (N : Node_Id) is
678 Id : constant Node_Id := Pragma_Identifier (N);
679 P_Id : constant Pragma_Id := Get_Pragma_Id (Chars (Id));
680
681 begin
682 -- Ignore call if node N is not in the main source unit, since we only
683 -- give messages for the main unit. This avoids giving messages for
684 -- aspects that are specified in withed units.
685
686 if not In_Extended_Main_Source_Unit (N) then
687 return;
688 end if;
689
690 -- If nothing set, nothing to check
691
692 if not No_Use_Of_Pragma_Set then
693 return;
694 end if;
695
696 Error_Msg_Sloc := No_Use_Of_Pragma (P_Id);
697
698 if Error_Msg_Sloc /= No_Location then
699 Error_Msg_Node_1 := Id;
700 Error_Msg_Warn := No_Use_Of_Pragma_Warning (P_Id);
701 Error_Msg_N
702 ("<*<violation of restriction `No_Use_Of_Pragma '='> &`#", Id);
703 end if;
704 end Check_Restriction_No_Use_Of_Pragma;
705
706 --------------------------------------
707 -- Check_Wide_Character_Restriction --
708 --------------------------------------
709
710 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id) is
711 begin
712 if Restriction_Check_Required (No_Wide_Characters)
713 and then Comes_From_Source (N)
714 then
715 declare
716 T : constant Entity_Id := Root_Type (E);
717 begin
718 if T = Standard_Wide_Character or else
719 T = Standard_Wide_String or else
720 T = Standard_Wide_Wide_Character or else
721 T = Standard_Wide_Wide_String
722 then
723 Check_Restriction (No_Wide_Characters, N);
724 end if;
725 end;
726 end if;
727 end Check_Wide_Character_Restriction;
728
729 ----------------------------------------
730 -- Cunit_Boolean_Restrictions_Restore --
731 ----------------------------------------
732
733 procedure Cunit_Boolean_Restrictions_Restore
734 (R : Save_Cunit_Boolean_Restrictions)
735 is
736 begin
737 for J in Cunit_Boolean_Restrictions loop
738 Restrictions.Set (J) := R (J);
739 end loop;
740
741 -- If No_Elaboration_Code set in configuration restrictions, and we
742 -- in the main extended source, then set it here now. This is part of
743 -- the special processing for No_Elaboration_Code.
744
745 if In_Extended_Main_Source_Unit (Cunit_Entity (Current_Sem_Unit))
746 and then Config_Cunit_Boolean_Restrictions (No_Elaboration_Code)
747 then
748 Restrictions.Set (No_Elaboration_Code) := True;
749 end if;
750 end Cunit_Boolean_Restrictions_Restore;
751
752 -------------------------------------
753 -- Cunit_Boolean_Restrictions_Save --
754 -------------------------------------
755
756 function Cunit_Boolean_Restrictions_Save
757 return Save_Cunit_Boolean_Restrictions
758 is
759 R : Save_Cunit_Boolean_Restrictions;
760
761 begin
762 for J in Cunit_Boolean_Restrictions loop
763 R (J) := Restrictions.Set (J);
764 end loop;
765
766 return R;
767 end Cunit_Boolean_Restrictions_Save;
768
769 ------------------------
770 -- Get_Restriction_Id --
771 ------------------------
772
773 function Get_Restriction_Id
774 (N : Name_Id) return Restriction_Id
775 is
776 begin
777 Get_Name_String (N);
778 Set_Casing (All_Upper_Case);
779
780 for J in All_Restrictions loop
781 declare
782 S : constant String := Restriction_Id'Image (J);
783 begin
784 if S = Name_Buffer (1 .. Name_Len) then
785 return J;
786 end if;
787 end;
788 end loop;
789
790 return Not_A_Restriction_Id;
791 end Get_Restriction_Id;
792
793 --------------------------------
794 -- Is_In_Hidden_Part_In_SPARK --
795 --------------------------------
796
797 function Is_In_Hidden_Part_In_SPARK (Loc : Source_Ptr) return Boolean is
798 begin
799 -- Loop through table of hidden ranges
800
801 for J in SPARK_Hides.First .. SPARK_Hides.Last loop
802 if SPARK_Hides.Table (J).Start <= Loc
803 and then Loc < SPARK_Hides.Table (J).Stop
804 then
805 return True;
806 end if;
807 end loop;
808
809 return False;
810 end Is_In_Hidden_Part_In_SPARK;
811
812 -------------------------------
813 -- No_Exception_Handlers_Set --
814 -------------------------------
815
816 function No_Exception_Handlers_Set return Boolean is
817 begin
818 return (No_Run_Time_Mode or else Configurable_Run_Time_Mode)
819 and then (Restrictions.Set (No_Exception_Handlers)
820 or else
821 Restrictions.Set (No_Exception_Propagation));
822 end No_Exception_Handlers_Set;
823
824 -------------------------------------
825 -- No_Exception_Propagation_Active --
826 -------------------------------------
827
828 function No_Exception_Propagation_Active return Boolean is
829 begin
830 return (No_Run_Time_Mode
831 or else Configurable_Run_Time_Mode
832 or else Debug_Flag_Dot_G)
833 and then Restriction_Active (No_Exception_Propagation);
834 end No_Exception_Propagation_Active;
835
836 --------------------------------
837 -- OK_No_Dependence_Unit_Name --
838 --------------------------------
839
840 function OK_No_Dependence_Unit_Name (N : Node_Id) return Boolean is
841 begin
842 if Nkind (N) = N_Selected_Component then
843 return
844 OK_No_Dependence_Unit_Name (Prefix (N))
845 and then
846 OK_No_Dependence_Unit_Name (Selector_Name (N));
847
848 elsif Nkind (N) = N_Identifier then
849 return True;
850
851 else
852 Error_Msg_N ("wrong form for unit name for No_Dependence", N);
853 return False;
854 end if;
855 end OK_No_Dependence_Unit_Name;
856
857 ----------------------------------
858 -- Process_Restriction_Synonyms --
859 ----------------------------------
860
861 -- Note: body of this function must be coordinated with list of
862 -- renaming declarations in System.Rident.
863
864 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id
865 is
866 Old_Name : constant Name_Id := Chars (N);
867 New_Name : Name_Id;
868
869 begin
870 case Old_Name is
871 when Name_Boolean_Entry_Barriers =>
872 New_Name := Name_Simple_Barriers;
873
874 when Name_Max_Entry_Queue_Depth =>
875 New_Name := Name_Max_Entry_Queue_Length;
876
877 when Name_No_Dynamic_Interrupts =>
878 New_Name := Name_No_Dynamic_Attachment;
879
880 when Name_No_Requeue =>
881 New_Name := Name_No_Requeue_Statements;
882
883 when Name_No_Task_Attributes =>
884 New_Name := Name_No_Task_Attributes_Package;
885
886 -- SPARK is special in that we unconditionally warn
887
888 when Name_SPARK =>
889 Error_Msg_Name_1 := Name_SPARK;
890 Error_Msg_N ("restriction identifier % is obsolescent??", N);
891 Error_Msg_Name_1 := Name_SPARK_05;
892 Error_Msg_N ("|use restriction identifier % instead??", N);
893 return Name_SPARK_05;
894
895 when others =>
896 return Old_Name;
897 end case;
898
899 -- Output warning if we are warning on obsolescent features for all
900 -- cases other than SPARK.
901
902 if Warn_On_Obsolescent_Feature then
903 Error_Msg_Name_1 := Old_Name;
904 Error_Msg_N ("restriction identifier % is obsolescent?j?", N);
905 Error_Msg_Name_1 := New_Name;
906 Error_Msg_N ("|use restriction identifier % instead?j?", N);
907 end if;
908
909 return New_Name;
910 end Process_Restriction_Synonyms;
911
912 --------------------------------------
913 -- Reset_Cunit_Boolean_Restrictions --
914 --------------------------------------
915
916 procedure Reset_Cunit_Boolean_Restrictions is
917 begin
918 for J in Cunit_Boolean_Restrictions loop
919 Restrictions.Set (J) := False;
920 end loop;
921 end Reset_Cunit_Boolean_Restrictions;
922
923 -----------------------------------------------
924 -- Restore_Config_Cunit_Boolean_Restrictions --
925 -----------------------------------------------
926
927 procedure Restore_Config_Cunit_Boolean_Restrictions is
928 begin
929 Cunit_Boolean_Restrictions_Restore (Config_Cunit_Boolean_Restrictions);
930 end Restore_Config_Cunit_Boolean_Restrictions;
931
932 ------------------------
933 -- Restricted_Profile --
934 ------------------------
935
936 function Restricted_Profile return Boolean is
937 begin
938 if Restricted_Profile_Cached then
939 return Restricted_Profile_Result;
940
941 else
942 Restricted_Profile_Result := True;
943 Restricted_Profile_Cached := True;
944
945 declare
946 R : Restriction_Flags renames Profile_Info (Restricted).Set;
947 V : Restriction_Values renames Profile_Info (Restricted).Value;
948 begin
949 for J in R'Range loop
950 if R (J)
951 and then (Restrictions.Set (J) = False
952 or else Restriction_Warnings (J)
953 or else
954 (J in All_Parameter_Restrictions
955 and then Restrictions.Value (J) > V (J)))
956 then
957 Restricted_Profile_Result := False;
958 exit;
959 end if;
960 end loop;
961
962 return Restricted_Profile_Result;
963 end;
964 end if;
965 end Restricted_Profile;
966
967 ------------------------
968 -- Restriction_Active --
969 ------------------------
970
971 function Restriction_Active (R : All_Restrictions) return Boolean is
972 begin
973 return Restrictions.Set (R) and then not Restriction_Warnings (R);
974 end Restriction_Active;
975
976 --------------------------------
977 -- Restriction_Check_Required --
978 --------------------------------
979
980 function Restriction_Check_Required (R : All_Restrictions) return Boolean is
981 begin
982 return Restrictions.Set (R);
983 end Restriction_Check_Required;
984
985 ---------------------
986 -- Restriction_Msg --
987 ---------------------
988
989 procedure Restriction_Msg (R : Restriction_Id; N : Node_Id) is
990 Msg : String (1 .. 100);
991 Len : Natural := 0;
992
993 procedure Add_Char (C : Character);
994 -- Append given character to Msg, bumping Len
995
996 procedure Add_Str (S : String);
997 -- Append given string to Msg, bumping Len appropriately
998
999 procedure Id_Case (S : String; Quotes : Boolean := True);
1000 -- Given a string S, case it according to current identifier casing,
1001 -- except for SPARK_05 (an acronym) which is set all upper case, and
1002 -- store in Error_Msg_String. Then append `~` to the message buffer
1003 -- to output the string unchanged surrounded in quotes. The quotes
1004 -- are suppressed if Quotes = False.
1005
1006 --------------
1007 -- Add_Char --
1008 --------------
1009
1010 procedure Add_Char (C : Character) is
1011 begin
1012 Len := Len + 1;
1013 Msg (Len) := C;
1014 end Add_Char;
1015
1016 -------------
1017 -- Add_Str --
1018 -------------
1019
1020 procedure Add_Str (S : String) is
1021 begin
1022 Msg (Len + 1 .. Len + S'Length) := S;
1023 Len := Len + S'Length;
1024 end Add_Str;
1025
1026 -------------
1027 -- Id_Case --
1028 -------------
1029
1030 procedure Id_Case (S : String; Quotes : Boolean := True) is
1031 begin
1032 Name_Buffer (1 .. S'Last) := S;
1033 Name_Len := S'Length;
1034
1035 if R = SPARK_05 then
1036 Set_All_Upper_Case;
1037 else
1038 Set_Casing (Identifier_Casing (Get_Source_File_Index (Sloc (N))));
1039 end if;
1040
1041 Error_Msg_Strlen := Name_Len;
1042 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
1043
1044 if Quotes then
1045 Add_Str ("`~`");
1046 else
1047 Add_Char ('~');
1048 end if;
1049 end Id_Case;
1050
1051 -- Start of processing for Restriction_Msg
1052
1053 begin
1054 -- Set warning message if warning
1055
1056 if Restriction_Warnings (R) then
1057 Add_Str ("?*?");
1058
1059 -- If real violation (not warning), then mark it as non-serious unless
1060 -- it is a violation of No_Finalization in which case we leave it as a
1061 -- serious message, since otherwise we get crashes during attempts to
1062 -- expand stuff that is not properly formed due to assumptions made
1063 -- about no finalization being present.
1064
1065 elsif R /= No_Finalization then
1066 Add_Char ('|');
1067 end if;
1068
1069 Error_Msg_Sloc := Restrictions_Loc (R);
1070
1071 -- Set main message, adding implicit if no source location
1072
1073 if Error_Msg_Sloc > No_Location
1074 or else Error_Msg_Sloc = System_Location
1075 then
1076 Add_Str ("violation of restriction ");
1077 else
1078 Add_Str ("violation of implicit restriction ");
1079 Error_Msg_Sloc := No_Location;
1080 end if;
1081
1082 -- Case of parameterized restriction
1083
1084 if R in All_Parameter_Restrictions then
1085 Add_Char ('`');
1086 Id_Case (Restriction_Id'Image (R), Quotes => False);
1087 Add_Str (" = ^`");
1088 Error_Msg_Uint_1 := UI_From_Int (Int (Restrictions.Value (R)));
1089
1090 -- Case of boolean restriction
1091
1092 else
1093 Id_Case (Restriction_Id'Image (R));
1094 end if;
1095
1096 -- Case of no secondary profile continuation message
1097
1098 if Restriction_Profile_Name (R) = No_Profile then
1099 if Error_Msg_Sloc /= No_Location then
1100 Add_Char ('#');
1101 end if;
1102
1103 Add_Char ('!');
1104 Error_Msg_N (Msg (1 .. Len), N);
1105
1106 -- Case of secondary profile continuation message present
1107
1108 else
1109 Add_Char ('!');
1110 Error_Msg_N (Msg (1 .. Len), N);
1111
1112 Len := 0;
1113 Add_Char ('\');
1114
1115 -- Set as warning if warning case
1116
1117 if Restriction_Warnings (R) then
1118 Add_Str ("??");
1119 end if;
1120
1121 -- Set main message
1122
1123 Add_Str ("from profile ");
1124 Id_Case (Profile_Name'Image (Restriction_Profile_Name (R)));
1125
1126 -- Add location if we have one
1127
1128 if Error_Msg_Sloc /= No_Location then
1129 Add_Char ('#');
1130 end if;
1131
1132 -- Output unconditional message and we are done
1133
1134 Add_Char ('!');
1135 Error_Msg_N (Msg (1 .. Len), N);
1136 end if;
1137 end Restriction_Msg;
1138
1139 ---------------
1140 -- Same_Unit --
1141 ---------------
1142
1143 function Same_Unit (U1, U2 : Node_Id) return Boolean is
1144 begin
1145 if Nkind (U1) = N_Identifier and then Nkind (U2) = N_Identifier then
1146 return Chars (U1) = Chars (U2);
1147
1148 elsif Nkind_In (U1, N_Selected_Component, N_Expanded_Name)
1149 and then
1150 Nkind_In (U2, N_Selected_Component, N_Expanded_Name)
1151 then
1152 return Same_Unit (Prefix (U1), Prefix (U2))
1153 and then
1154 Same_Unit (Selector_Name (U1), Selector_Name (U2));
1155 else
1156 return False;
1157 end if;
1158 end Same_Unit;
1159
1160 --------------------------------------------
1161 -- Save_Config_Cunit_Boolean_Restrictions --
1162 --------------------------------------------
1163
1164 procedure Save_Config_Cunit_Boolean_Restrictions is
1165 begin
1166 Config_Cunit_Boolean_Restrictions := Cunit_Boolean_Restrictions_Save;
1167 end Save_Config_Cunit_Boolean_Restrictions;
1168
1169 ------------------------------
1170 -- Set_Hidden_Part_In_SPARK --
1171 ------------------------------
1172
1173 procedure Set_Hidden_Part_In_SPARK (Loc1, Loc2 : Source_Ptr) is
1174 begin
1175 SPARK_Hides.Increment_Last;
1176 SPARK_Hides.Table (SPARK_Hides.Last).Start := Loc1;
1177 SPARK_Hides.Table (SPARK_Hides.Last).Stop := Loc2;
1178 end Set_Hidden_Part_In_SPARK;
1179
1180 ------------------------------
1181 -- Set_Profile_Restrictions --
1182 ------------------------------
1183
1184 procedure Set_Profile_Restrictions
1185 (P : Profile_Name;
1186 N : Node_Id;
1187 Warn : Boolean)
1188 is
1189 R : Restriction_Flags renames Profile_Info (P).Set;
1190 V : Restriction_Values renames Profile_Info (P).Value;
1191
1192 begin
1193 for J in R'Range loop
1194 if R (J) then
1195 declare
1196 Already_Restricted : constant Boolean := Restriction_Active (J);
1197
1198 begin
1199 -- Set the restriction
1200
1201 if J in All_Boolean_Restrictions then
1202 Set_Restriction (J, N);
1203 else
1204 Set_Restriction (J, N, V (J));
1205 end if;
1206
1207 -- Record that this came from a Profile[_Warnings] restriction
1208
1209 Restriction_Profile_Name (J) := P;
1210
1211 -- Set warning flag, except that we do not set the warning
1212 -- flag if the restriction was already active and this is
1213 -- the warning case. That avoids a warning overriding a real
1214 -- restriction, which should never happen.
1215
1216 if not (Warn and Already_Restricted) then
1217 Restriction_Warnings (J) := Warn;
1218 end if;
1219 end;
1220 end if;
1221 end loop;
1222 end Set_Profile_Restrictions;
1223
1224 ---------------------
1225 -- Set_Restriction --
1226 ---------------------
1227
1228 -- Case of Boolean restriction
1229
1230 procedure Set_Restriction
1231 (R : All_Boolean_Restrictions;
1232 N : Node_Id)
1233 is
1234 begin
1235 Restrictions.Set (R) := True;
1236
1237 if Restricted_Profile_Cached and Restricted_Profile_Result then
1238 null;
1239 else
1240 Restricted_Profile_Cached := False;
1241 end if;
1242
1243 -- Set location, but preserve location of system restriction for nice
1244 -- error msg with run time name.
1245
1246 if Restrictions_Loc (R) /= System_Location then
1247 Restrictions_Loc (R) := Sloc (N);
1248 end if;
1249
1250 -- Note restriction came from restriction pragma, not profile
1251
1252 Restriction_Profile_Name (R) := No_Profile;
1253
1254 -- Record the restriction if we are in the main unit, or in the extended
1255 -- main unit. The reason that we test separately for Main_Unit is that
1256 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1257 -- gnat.adc do not appear to be in the extended main source unit (they
1258 -- probably should do ???)
1259
1260 if Current_Sem_Unit = Main_Unit
1261 or else In_Extended_Main_Source_Unit (N)
1262 then
1263 if not Restriction_Warnings (R) then
1264 Main_Restrictions.Set (R) := True;
1265 end if;
1266 end if;
1267 end Set_Restriction;
1268
1269 -- Case of parameter restriction
1270
1271 procedure Set_Restriction
1272 (R : All_Parameter_Restrictions;
1273 N : Node_Id;
1274 V : Integer)
1275 is
1276 begin
1277 if Restricted_Profile_Cached and Restricted_Profile_Result then
1278 null;
1279 else
1280 Restricted_Profile_Cached := False;
1281 end if;
1282
1283 if Restrictions.Set (R) then
1284 if V < Restrictions.Value (R) then
1285 Restrictions.Value (R) := V;
1286 Restrictions_Loc (R) := Sloc (N);
1287 end if;
1288
1289 else
1290 Restrictions.Set (R) := True;
1291 Restrictions.Value (R) := V;
1292 Restrictions_Loc (R) := Sloc (N);
1293 end if;
1294
1295 -- Record the restriction if we are in the main unit, or in the extended
1296 -- main unit. The reason that we test separately for Main_Unit is that
1297 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1298 -- gnat.adc do not appear to be the extended main source unit (they
1299 -- probably should do ???)
1300
1301 if Current_Sem_Unit = Main_Unit
1302 or else In_Extended_Main_Source_Unit (N)
1303 then
1304 if Main_Restrictions.Set (R) then
1305 if V < Main_Restrictions.Value (R) then
1306 Main_Restrictions.Value (R) := V;
1307 end if;
1308
1309 elsif not Restriction_Warnings (R) then
1310 Main_Restrictions.Set (R) := True;
1311 Main_Restrictions.Value (R) := V;
1312 end if;
1313 end if;
1314
1315 -- Note restriction came from restriction pragma, not profile
1316
1317 Restriction_Profile_Name (R) := No_Profile;
1318 end Set_Restriction;
1319
1320 -----------------------------------
1321 -- Set_Restriction_No_Dependence --
1322 -----------------------------------
1323
1324 procedure Set_Restriction_No_Dependence
1325 (Unit : Node_Id;
1326 Warn : Boolean;
1327 Profile : Profile_Name := No_Profile)
1328 is
1329 begin
1330 -- Loop to check for duplicate entry
1331
1332 for J in No_Dependences.First .. No_Dependences.Last loop
1333
1334 -- Case of entry already in table
1335
1336 if Same_Unit (Unit, No_Dependences.Table (J).Unit) then
1337
1338 -- Error has precedence over warning
1339
1340 if not Warn then
1341 No_Dependences.Table (J).Warn := False;
1342 end if;
1343
1344 return;
1345 end if;
1346 end loop;
1347
1348 -- Entry is not currently in table
1349
1350 No_Dependences.Append ((Unit, Warn, Profile));
1351 end Set_Restriction_No_Dependence;
1352
1353 ------------------------------------------------
1354 -- Set_Restriction_No_Specification_Of_Aspect --
1355 ------------------------------------------------
1356
1357 procedure Set_Restriction_No_Specification_Of_Aspect
1358 (N : Node_Id;
1359 Warning : Boolean)
1360 is
1361 A_Id : constant Aspect_Id_Exclude_No_Aspect := Get_Aspect_Id (Chars (N));
1362
1363 begin
1364 No_Specification_Of_Aspects (A_Id) := Sloc (N);
1365
1366 if Warning = False then
1367 No_Specification_Of_Aspect_Warning (A_Id) := False;
1368 end if;
1369
1370 No_Specification_Of_Aspect_Set := True;
1371 end Set_Restriction_No_Specification_Of_Aspect;
1372
1373 -----------------------------------------
1374 -- Set_Restriction_No_Use_Of_Attribute --
1375 -----------------------------------------
1376
1377 procedure Set_Restriction_No_Use_Of_Attribute
1378 (N : Node_Id;
1379 Warning : Boolean)
1380 is
1381 A_Id : constant Attribute_Id := Get_Attribute_Id (Chars (N));
1382
1383 begin
1384 No_Use_Of_Attribute_Set := True;
1385 No_Use_Of_Attribute (A_Id) := Sloc (N);
1386
1387 if Warning = False then
1388 No_Use_Of_Attribute_Warning (A_Id) := False;
1389 end if;
1390 end Set_Restriction_No_Use_Of_Attribute;
1391
1392 --------------------------------------
1393 -- Set_Restriction_No_Use_Of_Pragma --
1394 --------------------------------------
1395
1396 procedure Set_Restriction_No_Use_Of_Pragma
1397 (N : Node_Id;
1398 Warning : Boolean)
1399 is
1400 A_Id : constant Pragma_Id := Get_Pragma_Id (Chars (N));
1401
1402 begin
1403 No_Use_Of_Pragma_Set := True;
1404 No_Use_Of_Pragma (A_Id) := Sloc (N);
1405
1406 if Warning = False then
1407 No_Use_Of_Pragma_Warning (A_Id) := False;
1408 end if;
1409 end Set_Restriction_No_Use_Of_Pragma;
1410
1411 -----------------------------
1412 -- Check_SPARK_Restriction --
1413 -----------------------------
1414
1415 procedure Check_SPARK_Restriction
1416 (Msg : String;
1417 N : Node_Id;
1418 Force : Boolean := False)
1419 is
1420 Msg_Issued : Boolean;
1421 Save_Error_Msg_Sloc : Source_Ptr;
1422 Onode : constant Node_Id := Original_Node (N);
1423
1424 begin
1425 -- Output message if Force set
1426
1427 if Force
1428
1429 -- Or if this node comes from source
1430
1431 or else Comes_From_Source (N)
1432
1433 -- Or if this is a range node which rewrites a range attribute and
1434 -- the range attribute comes from source.
1435
1436 or else (Nkind (N) = N_Range
1437 and then Nkind (Onode) = N_Attribute_Reference
1438 and then Attribute_Name (Onode) = Name_Range
1439 and then Comes_From_Source (Onode))
1440
1441 -- Or this is an expression that does not come from source, which is
1442 -- a rewriting of an expression that does come from source.
1443
1444 or else (Nkind (N) in N_Subexpr and then Comes_From_Source (Onode))
1445 then
1446 if Restriction_Check_Required (SPARK_05)
1447 and then Is_In_Hidden_Part_In_SPARK (Sloc (N))
1448 then
1449 return;
1450 end if;
1451
1452 -- Since the call to Restriction_Msg from Check_Restriction may set
1453 -- Error_Msg_Sloc to the location of the pragma restriction, save and
1454 -- restore the previous value of the global variable around the call.
1455
1456 Save_Error_Msg_Sloc := Error_Msg_Sloc;
1457 Check_Restriction (Msg_Issued, SPARK_05, First_Node (N));
1458 Error_Msg_Sloc := Save_Error_Msg_Sloc;
1459
1460 if Msg_Issued then
1461 Error_Msg_F ("\\| " & Msg, N);
1462 end if;
1463 end if;
1464 end Check_SPARK_Restriction;
1465
1466 procedure Check_SPARK_Restriction (Msg1, Msg2 : String; N : Node_Id) is
1467 Msg_Issued : Boolean;
1468 Save_Error_Msg_Sloc : Source_Ptr;
1469
1470 begin
1471 pragma Assert (Msg2'Length /= 0 and then Msg2 (Msg2'First) = '\');
1472
1473 if Comes_From_Source (Original_Node (N)) then
1474 if Restriction_Check_Required (SPARK_05)
1475 and then Is_In_Hidden_Part_In_SPARK (Sloc (N))
1476 then
1477 return;
1478 end if;
1479
1480 -- Since the call to Restriction_Msg from Check_Restriction may set
1481 -- Error_Msg_Sloc to the location of the pragma restriction, save and
1482 -- restore the previous value of the global variable around the call.
1483
1484 Save_Error_Msg_Sloc := Error_Msg_Sloc;
1485 Check_Restriction (Msg_Issued, SPARK_05, First_Node (N));
1486 Error_Msg_Sloc := Save_Error_Msg_Sloc;
1487
1488 if Msg_Issued then
1489 Error_Msg_F ("\\| " & Msg1, N);
1490 Error_Msg_F (Msg2, N);
1491 end if;
1492 end if;
1493 end Check_SPARK_Restriction;
1494
1495 ----------------------------------
1496 -- Suppress_Restriction_Message --
1497 ----------------------------------
1498
1499 function Suppress_Restriction_Message (N : Node_Id) return Boolean is
1500 begin
1501 -- We only output messages for the extended main source unit
1502
1503 if In_Extended_Main_Source_Unit (N) then
1504 return False;
1505
1506 -- If loaded by rtsfind, then suppress message
1507
1508 elsif Sloc (N) <= No_Location then
1509 return True;
1510
1511 -- Otherwise suppress message if internal file
1512
1513 else
1514 return Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)));
1515 end if;
1516 end Suppress_Restriction_Message;
1517
1518 ---------------------
1519 -- Tasking_Allowed --
1520 ---------------------
1521
1522 function Tasking_Allowed return Boolean is
1523 begin
1524 return not Restrictions.Set (No_Tasking)
1525 and then (not Restrictions.Set (Max_Tasks)
1526 or else Restrictions.Value (Max_Tasks) > 0);
1527 end Tasking_Allowed;
1528
1529 end Restrict;