1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
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;
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;
42 package body Restrict is
44 Config_Cunit_Boolean_Restrictions : Save_Cunit_Boolean_Restrictions;
45 -- Save compilation unit restrictions set by config pragma files
47 Restricted_Profile_Result : Boolean := False;
48 -- This switch memoizes the result of Restricted_Profile function calls for
49 -- improved efficiency. Valid only if Restricted_Profile_Cached is True.
50 -- Note: if this switch is ever set True, it is never turned off again.
52 Restricted_Profile_Cached : Boolean := False;
53 -- This flag is set to True if the Restricted_Profile_Result contains the
54 -- correct cached result of Restricted_Profile calls.
56 No_Specification_Of_Aspects : array (Aspect_Id) of Source_Ptr :=
57 (others => No_Location);
58 -- Entries in this array are set to point to a previously occuring pragma
59 -- that activates a No_Specification_Of_Aspect check.
61 No_Specification_Of_Aspect_Warning : array (Aspect_Id) of Boolean :=
63 -- An entry in this array is set False in reponse to a previous call to
64 -- Set_No_Speficiation_Of_Aspect for pragmas in the main unit that
65 -- specify Warning as False. Once set False, an entry is never reset.
67 No_Specification_Of_Aspect_Set : Boolean := False;
68 -- Set True if any entry of No_Specifcation_Of_Aspects has been set True.
69 -- Once set True, this is never turned off again.
71 -----------------------
72 -- Local Subprograms --
73 -----------------------
75 procedure Restriction_Msg (R : Restriction_Id; N : Node_Id);
76 -- Called if a violation of restriction R at node N is found. This routine
77 -- outputs the appropriate message or messages taking care of warning vs
78 -- real violation, serious vs non-serious, implicit vs explicit, the second
79 -- message giving the profile name if needed, and the location information.
81 function Same_Unit (U1, U2 : Node_Id) return Boolean;
82 -- Returns True iff U1 and U2 represent the same library unit. Used for
83 -- handling of No_Dependence => Unit restriction case.
85 function Suppress_Restriction_Message (N : Node_Id) return Boolean;
86 -- N is the node for a possible restriction violation message, but the
87 -- message is to be suppressed if this is an internal file and this file is
88 -- not the main unit. Returns True if message is to be suppressed.
94 function Abort_Allowed return Boolean is
96 if Restrictions.Set (No_Abort_Statements)
97 and then Restrictions.Set (Max_Asynchronous_Select_Nesting)
98 and then Restrictions.Value (Max_Asynchronous_Select_Nesting) = 0
106 ----------------------------------------
107 -- Add_To_Config_Boolean_Restrictions --
108 ----------------------------------------
110 procedure Add_To_Config_Boolean_Restrictions (R : Restriction_Id) is
112 Config_Cunit_Boolean_Restrictions (R) := True;
113 end Add_To_Config_Boolean_Restrictions;
114 -- Add specified restriction to stored configuration boolean restrictions.
115 -- This is used for handling the special case of No_Elaboration_Code.
117 -------------------------
118 -- Check_Compiler_Unit --
119 -------------------------
121 procedure Check_Compiler_Unit (N : Node_Id) is
123 if Is_Compiler_Unit (Get_Source_Unit (N)) then
124 Error_Msg_N ("use of construct not allowed in compiler", N);
126 end Check_Compiler_Unit;
128 ------------------------------------
129 -- Check_Elaboration_Code_Allowed --
130 ------------------------------------
132 procedure Check_Elaboration_Code_Allowed (N : Node_Id) is
134 Check_Restriction (No_Elaboration_Code, N);
135 end Check_Elaboration_Code_Allowed;
137 -----------------------------
138 -- Check_SPARK_Restriction --
139 -----------------------------
141 procedure Check_SPARK_Restriction
144 Force : Boolean := False)
146 Msg_Issued : Boolean;
147 Save_Error_Msg_Sloc : Source_Ptr;
149 if Force or else Comes_From_Source (Original_Node (N)) then
151 if Restriction_Check_Required (SPARK)
152 and then Is_In_Hidden_Part_In_SPARK (Sloc (N))
157 -- Since the call to Restriction_Msg from Check_Restriction may set
158 -- Error_Msg_Sloc to the location of the pragma restriction, save and
159 -- restore the previous value of the global variable around the call.
161 Save_Error_Msg_Sloc := Error_Msg_Sloc;
162 Check_Restriction (Msg_Issued, SPARK, First_Node (N));
163 Error_Msg_Sloc := Save_Error_Msg_Sloc;
166 Error_Msg_F ("\\| " & Msg, N);
169 end Check_SPARK_Restriction;
171 procedure Check_SPARK_Restriction (Msg1, Msg2 : String; N : Node_Id) is
172 Msg_Issued : Boolean;
173 Save_Error_Msg_Sloc : Source_Ptr;
175 pragma Assert (Msg2'Length /= 0 and then Msg2 (Msg2'First) = '\');
177 if Comes_From_Source (Original_Node (N)) then
179 if Restriction_Check_Required (SPARK)
180 and then Is_In_Hidden_Part_In_SPARK (Sloc (N))
185 -- Since the call to Restriction_Msg from Check_Restriction may set
186 -- Error_Msg_Sloc to the location of the pragma restriction, save and
187 -- restore the previous value of the global variable around the call.
189 Save_Error_Msg_Sloc := Error_Msg_Sloc;
190 Check_Restriction (Msg_Issued, SPARK, First_Node (N));
191 Error_Msg_Sloc := Save_Error_Msg_Sloc;
194 Error_Msg_F ("\\| " & Msg1, N);
195 Error_Msg_F (Msg2, N);
198 end Check_SPARK_Restriction;
200 --------------------------------
201 -- Check_No_Implicit_Aliasing --
202 --------------------------------
204 procedure Check_No_Implicit_Aliasing (Obj : Node_Id) is
208 -- If restriction not active, nothing to check
210 if not Restriction_Active (No_Implicit_Aliasing) then
214 -- If we have an entity name, check entity
216 if Is_Entity_Name (Obj) then
219 -- Restriction applies to entities that are objects
221 if Is_Object (E) then
222 if Is_Aliased (E) then
225 elsif Present (Renamed_Object (E)) then
226 Check_No_Implicit_Aliasing (Renamed_Object (E));
230 -- If we don't have an object, then it's OK
236 -- For selected component, check selector
238 elsif Nkind (Obj) = N_Selected_Component then
239 Check_No_Implicit_Aliasing (Selector_Name (Obj));
242 -- Indexed component is OK if aliased components
244 elsif Nkind (Obj) = N_Indexed_Component then
245 if Has_Aliased_Components (Etype (Prefix (Obj)))
247 (Is_Access_Type (Etype (Prefix (Obj)))
248 and then Has_Aliased_Components
249 (Designated_Type (Etype (Prefix (Obj)))))
254 -- For type conversion, check converted expression
256 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
257 Check_No_Implicit_Aliasing (Expression (Obj));
260 -- Explicit dereference is always OK
262 elsif Nkind (Obj) = N_Explicit_Dereference then
266 -- If we fall through, then we have an aliased view that does not meet
267 -- the rules for being explicitly aliased, so issue restriction msg.
269 Check_Restriction (No_Implicit_Aliasing, Obj);
270 end Check_No_Implicit_Aliasing;
272 -----------------------------------------
273 -- Check_Implicit_Dynamic_Code_Allowed --
274 -----------------------------------------
276 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id) is
278 Check_Restriction (No_Implicit_Dynamic_Code, N);
279 end Check_Implicit_Dynamic_Code_Allowed;
281 ----------------------------------
282 -- Check_No_Implicit_Heap_Alloc --
283 ----------------------------------
285 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id) is
287 Check_Restriction (No_Implicit_Heap_Allocations, N);
288 end Check_No_Implicit_Heap_Alloc;
290 -----------------------------------
291 -- Check_Obsolescent_2005_Entity --
292 -----------------------------------
294 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id) is
295 function Chars_Is (E : Entity_Id; S : String) return Boolean;
296 -- Return True iff Chars (E) matches S (given in lower case)
298 function Chars_Is (E : Entity_Id; S : String) return Boolean is
299 Nam : constant Name_Id := Chars (E);
301 if Length_Of_Name (Nam) /= S'Length then
304 return Get_Name_String (Nam) = S;
308 -- Start of processing for Check_Obsolescent_2005_Entity
311 if Restriction_Check_Required (No_Obsolescent_Features)
312 and then Ada_Version >= Ada_2005
313 and then Chars_Is (Scope (E), "handling")
314 and then Chars_Is (Scope (Scope (E)), "characters")
315 and then Chars_Is (Scope (Scope (Scope (E))), "ada")
316 and then Scope (Scope (Scope (Scope (E)))) = Standard_Standard
318 if Chars_Is (E, "is_character") or else
319 Chars_Is (E, "is_string") or else
320 Chars_Is (E, "to_character") or else
321 Chars_Is (E, "to_string") or else
322 Chars_Is (E, "to_wide_character") or else
323 Chars_Is (E, "to_wide_string")
325 Check_Restriction (No_Obsolescent_Features, N);
328 end Check_Obsolescent_2005_Entity;
330 ---------------------------
331 -- Check_Restricted_Unit --
332 ---------------------------
334 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id) is
336 if Suppress_Restriction_Message (N) then
339 elsif Is_Spec_Name (U) then
341 Fnam : constant File_Name_Type :=
342 Get_File_Name (U, Subunit => False);
347 Get_Name_String (Fnam);
349 -- Nothing to do if name not at least 5 characters long ending
350 -- in .ads or .adb extension, which we strip.
353 or else (Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads"
355 Name_Buffer (Name_Len - 3 .. Name_Len) /= ".adb")
360 -- Strip extension and pad to eight characters
362 Name_Len := Name_Len - 4;
363 Add_Str_To_Name_Buffer ((Name_Len + 1 .. 8 => ' '));
365 -- If predefined unit, check the list of restricted units
367 if Is_Predefined_File_Name (Fnam) then
368 for J in Unit_Array'Range loop
370 and then Name_Buffer (1 .. 8) = Unit_Array (J).Filenm
372 Check_Restriction (Unit_Array (J).Res_Id, N);
376 -- If not predefined unit, then one special check still
377 -- remains. GNAT.Current_Exception is not allowed if we have
378 -- restriction No_Exception_Propagation active.
381 if Name_Buffer (1 .. 8) = "g-curexc" then
382 Check_Restriction (No_Exception_Propagation, N);
387 end Check_Restricted_Unit;
389 -----------------------
390 -- Check_Restriction --
391 -----------------------
393 procedure Check_Restriction
396 V : Uint := Uint_Minus_1)
398 Msg_Issued : Boolean;
399 pragma Unreferenced (Msg_Issued);
401 Check_Restriction (Msg_Issued, R, N, V);
402 end Check_Restriction;
404 procedure Check_Restriction
405 (Msg_Issued : out Boolean;
408 V : Uint := Uint_Minus_1)
411 -- V converted to integer form. If V is greater than Integer'Last,
412 -- it is reset to minus 1 (unknown value).
414 procedure Update_Restrictions (Info : in out Restrictions_Info);
415 -- Update violation information in Info.Violated and Info.Count
417 -------------------------
418 -- Update_Restrictions --
419 -------------------------
421 procedure Update_Restrictions (Info : in out Restrictions_Info) is
423 -- If not violated, set as violated now
425 if not Info.Violated (R) then
426 Info.Violated (R) := True;
428 if R in All_Parameter_Restrictions then
430 Info.Unknown (R) := True;
433 Info.Count (R) := VV;
437 -- Otherwise if violated already and a parameter restriction,
438 -- update count by maximizing or summing depending on restriction.
440 elsif R in All_Parameter_Restrictions then
442 -- If new value is unknown, result is unknown
445 Info.Unknown (R) := True;
447 -- If checked by maximization, do maximization
449 elsif R in Checked_Max_Parameter_Restrictions then
450 Info.Count (R) := Integer'Max (Info.Count (R), VV);
452 -- If checked by adding, do add, checking for overflow
454 elsif R in Checked_Add_Parameter_Restrictions then
456 pragma Unsuppress (Overflow_Check);
458 Info.Count (R) := Info.Count (R) + VV;
460 when Constraint_Error =>
461 Info.Count (R) := Integer'Last;
462 Info.Unknown (R) := True;
465 -- Should not be able to come here, known counts should only
466 -- occur for restrictions that are Checked_max or Checked_Sum.
472 end Update_Restrictions;
474 -- Start of processing for Check_Restriction
479 -- In CodePeer and Alfa mode, we do not want to check for any
480 -- restriction, or set additional restrictions other than those already
481 -- set in gnat1drv.adb so that we have consistency between each
484 if CodePeer_Mode or Alfa_Mode then
488 -- In SPARK mode, issue an error for any use of class-wide, even if the
489 -- No_Dispatch restriction is not set.
491 if R = No_Dispatch then
492 Check_SPARK_Restriction ("class-wide is not allowed", N);
495 if UI_Is_In_Int_Range (V) then
496 VV := Integer (UI_To_Int (V));
501 -- Count can only be specified in the checked val parameter case
503 pragma Assert (VV < 0 or else R in Checked_Val_Parameter_Restrictions);
505 -- Nothing to do if value of zero specified for parameter restriction
511 -- Update current restrictions
513 Update_Restrictions (Restrictions);
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.
519 if Current_Sem_Unit = Main_Unit
520 or else In_Extended_Main_Source_Unit (N)
522 Update_Restrictions (Main_Restrictions);
525 -- Nothing to do if restriction message suppressed
527 if Suppress_Restriction_Message (N) then
530 -- If restriction not set, nothing to do
532 elsif not Restrictions.Set (R) then
535 -- Here if restriction set, check for violation (either this is a
536 -- Boolean restriction, or a parameter restriction with a value of
537 -- zero and an unknown count, or a parameter restriction with a
538 -- known value that exceeds the restriction count).
540 elsif R in All_Boolean_Restrictions
541 or else (Restrictions.Unknown (R)
542 and then Restrictions.Value (R) = 0)
543 or else Restrictions.Count (R) > Restrictions.Value (R)
546 Restriction_Msg (R, N);
548 end Check_Restriction;
550 -------------------------------------
551 -- Check_Restriction_No_Dependence --
552 -------------------------------------
554 procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id) is
558 -- Ignore call if node U is not in the main source unit. This avoids
559 -- cascaded errors, e.g. when Ada.Containers units with other units.
561 if not In_Extended_Main_Source_Unit (U) then
565 -- Loop through entries in No_Dependence table to check each one in turn
567 for J in No_Dependences.First .. No_Dependences.Last loop
568 DU := No_Dependences.Table (J).Unit;
570 if Same_Unit (U, DU) then
571 Error_Msg_Sloc := Sloc (DU);
572 Error_Msg_Node_1 := DU;
574 if No_Dependences.Table (J).Warn then
576 ("?violation of restriction `No_Dependence '='> &`#",
580 ("|violation of restriction `No_Dependence '='> &`#",
587 end Check_Restriction_No_Dependence;
589 --------------------------------------------------
590 -- Check_Restriction_No_Specification_Of_Aspect --
591 --------------------------------------------------
593 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id) is
598 -- Ignore call if no instances of this restriction set
600 if not No_Specification_Of_Aspect_Set then
604 -- Ignore call if node N is not in the main source unit, since we only
605 -- give messages for . This avoids giving messages for aspects that are
606 -- specified in withed units.
608 if not In_Extended_Main_Source_Unit (N) then
612 Id := Identifier (N);
613 A_Id := Get_Aspect_Id (Chars (Id));
614 pragma Assert (A_Id /= No_Aspect);
616 Error_Msg_Sloc := No_Specification_Of_Aspects (A_Id);
618 if Error_Msg_Sloc /= No_Location then
619 Error_Msg_Node_1 := Id;
620 Error_Msg_Warn := No_Specification_Of_Aspect_Warning (A_Id);
622 ("<violation of restriction `No_Specification_Of_Aspect '='> &`#",
625 end Check_Restriction_No_Specification_Of_Aspect;
627 --------------------------------------
628 -- Check_Wide_Character_Restriction --
629 --------------------------------------
631 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id) is
633 if Restriction_Check_Required (No_Wide_Characters)
634 and then Comes_From_Source (N)
637 T : constant Entity_Id := Root_Type (E);
639 if T = Standard_Wide_Character or else
640 T = Standard_Wide_String or else
641 T = Standard_Wide_Wide_Character or else
642 T = Standard_Wide_Wide_String
644 Check_Restriction (No_Wide_Characters, N);
648 end Check_Wide_Character_Restriction;
650 ----------------------------------------
651 -- Cunit_Boolean_Restrictions_Restore --
652 ----------------------------------------
654 procedure Cunit_Boolean_Restrictions_Restore
655 (R : Save_Cunit_Boolean_Restrictions)
658 for J in Cunit_Boolean_Restrictions loop
659 Restrictions.Set (J) := R (J);
662 -- If No_Elaboration_Code set in configuration restrictions, and we
663 -- in the main extended source, then set it here now. This is part of
664 -- the special processing for No_Elaboration_Code.
666 if In_Extended_Main_Source_Unit (Cunit_Entity (Current_Sem_Unit))
667 and then Config_Cunit_Boolean_Restrictions (No_Elaboration_Code)
669 Restrictions.Set (No_Elaboration_Code) := True;
671 end Cunit_Boolean_Restrictions_Restore;
673 -------------------------------------
674 -- Cunit_Boolean_Restrictions_Save --
675 -------------------------------------
677 function Cunit_Boolean_Restrictions_Save
678 return Save_Cunit_Boolean_Restrictions
680 R : Save_Cunit_Boolean_Restrictions;
683 for J in Cunit_Boolean_Restrictions loop
684 R (J) := Restrictions.Set (J);
688 end Cunit_Boolean_Restrictions_Save;
690 ------------------------
691 -- Get_Restriction_Id --
692 ------------------------
694 function Get_Restriction_Id
695 (N : Name_Id) return Restriction_Id
699 Set_Casing (All_Upper_Case);
701 for J in All_Restrictions loop
703 S : constant String := Restriction_Id'Image (J);
705 if S = Name_Buffer (1 .. Name_Len) then
711 return Not_A_Restriction_Id;
712 end Get_Restriction_Id;
714 --------------------------------
715 -- Is_In_Hidden_Part_In_SPARK --
716 --------------------------------
718 function Is_In_Hidden_Part_In_SPARK (Loc : Source_Ptr) return Boolean is
720 -- Loop through table of hidden ranges
722 for J in SPARK_Hides.First .. SPARK_Hides.Last loop
723 if SPARK_Hides.Table (J).Start <= Loc
724 and then Loc < SPARK_Hides.Table (J).Stop
731 end Is_In_Hidden_Part_In_SPARK;
733 -------------------------------
734 -- No_Exception_Handlers_Set --
735 -------------------------------
737 function No_Exception_Handlers_Set return Boolean is
739 return (No_Run_Time_Mode or else Configurable_Run_Time_Mode)
740 and then (Restrictions.Set (No_Exception_Handlers)
742 Restrictions.Set (No_Exception_Propagation));
743 end No_Exception_Handlers_Set;
745 -------------------------------------
746 -- No_Exception_Propagation_Active --
747 -------------------------------------
749 function No_Exception_Propagation_Active return Boolean is
751 return (No_Run_Time_Mode
752 or else Configurable_Run_Time_Mode
753 or else Debug_Flag_Dot_G)
754 and then Restriction_Active (No_Exception_Propagation);
755 end No_Exception_Propagation_Active;
757 ----------------------------------
758 -- Process_Restriction_Synonyms --
759 ----------------------------------
761 -- Note: body of this function must be coordinated with list of
762 -- renaming declarations in System.Rident.
764 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id
766 Old_Name : constant Name_Id := Chars (N);
771 when Name_Boolean_Entry_Barriers =>
772 New_Name := Name_Simple_Barriers;
774 when Name_Max_Entry_Queue_Depth =>
775 New_Name := Name_Max_Entry_Queue_Length;
777 when Name_No_Dynamic_Interrupts =>
778 New_Name := Name_No_Dynamic_Attachment;
780 when Name_No_Requeue =>
781 New_Name := Name_No_Requeue_Statements;
783 when Name_No_Task_Attributes =>
784 New_Name := Name_No_Task_Attributes_Package;
790 if Warn_On_Obsolescent_Feature then
791 Error_Msg_Name_1 := Old_Name;
792 Error_Msg_N ("restriction identifier % is obsolescent?", N);
793 Error_Msg_Name_1 := New_Name;
794 Error_Msg_N ("|use restriction identifier % instead", N);
798 end Process_Restriction_Synonyms;
800 --------------------------------------
801 -- Reset_Cunit_Boolean_Restrictions --
802 --------------------------------------
804 procedure Reset_Cunit_Boolean_Restrictions is
806 for J in Cunit_Boolean_Restrictions loop
807 Restrictions.Set (J) := False;
809 end Reset_Cunit_Boolean_Restrictions;
811 -----------------------------------------------
812 -- Restore_Config_Cunit_Boolean_Restrictions --
813 -----------------------------------------------
815 procedure Restore_Config_Cunit_Boolean_Restrictions is
817 Cunit_Boolean_Restrictions_Restore (Config_Cunit_Boolean_Restrictions);
818 end Restore_Config_Cunit_Boolean_Restrictions;
820 ------------------------
821 -- Restricted_Profile --
822 ------------------------
824 function Restricted_Profile return Boolean is
826 if Restricted_Profile_Cached then
827 return Restricted_Profile_Result;
830 Restricted_Profile_Result := True;
831 Restricted_Profile_Cached := True;
834 R : Restriction_Flags renames Profile_Info (Restricted).Set;
835 V : Restriction_Values renames Profile_Info (Restricted).Value;
837 for J in R'Range loop
839 and then (Restrictions.Set (J) = False
840 or else Restriction_Warnings (J)
842 (J in All_Parameter_Restrictions
843 and then Restrictions.Value (J) > V (J)))
845 Restricted_Profile_Result := False;
850 return Restricted_Profile_Result;
853 end Restricted_Profile;
855 ------------------------
856 -- Restriction_Active --
857 ------------------------
859 function Restriction_Active (R : All_Restrictions) return Boolean is
861 return Restrictions.Set (R) and then not Restriction_Warnings (R);
862 end Restriction_Active;
864 --------------------------------
865 -- Restriction_Check_Required --
866 --------------------------------
868 function Restriction_Check_Required (R : All_Restrictions) return Boolean is
870 return Restrictions.Set (R);
871 end Restriction_Check_Required;
873 ---------------------
874 -- Restriction_Msg --
875 ---------------------
877 procedure Restriction_Msg (R : Restriction_Id; N : Node_Id) is
878 Msg : String (1 .. 100);
881 procedure Add_Char (C : Character);
882 -- Append given character to Msg, bumping Len
884 procedure Add_Str (S : String);
885 -- Append given string to Msg, bumping Len appropriately
887 procedure Id_Case (S : String; Quotes : Boolean := True);
888 -- Given a string S, case it according to current identifier casing,
889 -- except for SPARK (an acronym) which is set all upper case, and store
890 -- in Error_Msg_String. Then append `~` to the message buffer to output
891 -- the string unchanged surrounded in quotes. The quotes are suppressed
892 -- if Quotes = False.
898 procedure Add_Char (C : Character) is
908 procedure Add_Str (S : String) is
910 Msg (Len + 1 .. Len + S'Length) := S;
911 Len := Len + S'Length;
918 procedure Id_Case (S : String; Quotes : Boolean := True) is
920 Name_Buffer (1 .. S'Last) := S;
921 Name_Len := S'Length;
926 Set_Casing (Identifier_Casing (Get_Source_File_Index (Sloc (N))));
929 Error_Msg_Strlen := Name_Len;
930 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
939 -- Start of processing for Restriction_Msg
942 -- Set warning message if warning
944 if Restriction_Warnings (R) then
947 -- If real violation (not warning), then mark it as non-serious unless
948 -- it is a violation of No_Finalization in which case we leave it as a
949 -- serious message, since otherwise we get crashes during attempts to
950 -- expand stuff that is not properly formed due to assumptions made
951 -- about no finalization being present.
953 elsif R /= No_Finalization then
957 Error_Msg_Sloc := Restrictions_Loc (R);
959 -- Set main message, adding implicit if no source location
961 if Error_Msg_Sloc > No_Location
962 or else Error_Msg_Sloc = System_Location
964 Add_Str ("violation of restriction ");
966 Add_Str ("violation of implicit restriction ");
967 Error_Msg_Sloc := No_Location;
970 -- Case of parameterized restriction
972 if R in All_Parameter_Restrictions then
974 Id_Case (Restriction_Id'Image (R), Quotes => False);
976 Error_Msg_Uint_1 := UI_From_Int (Int (Restrictions.Value (R)));
978 -- Case of boolean restriction
981 Id_Case (Restriction_Id'Image (R));
984 -- Case of no secondary profile continuation message
986 if Restriction_Profile_Name (R) = No_Profile then
987 if Error_Msg_Sloc /= No_Location then
992 Error_Msg_N (Msg (1 .. Len), N);
994 -- Case of secondary profile continuation message present
998 Error_Msg_N (Msg (1 .. Len), N);
1003 -- Set as warning if warning case
1005 if Restriction_Warnings (R) then
1011 Add_Str ("from profile ");
1012 Id_Case (Profile_Name'Image (Restriction_Profile_Name (R)));
1014 -- Add location if we have one
1016 if Error_Msg_Sloc /= No_Location then
1020 -- Output unconditional message and we are done
1023 Error_Msg_N (Msg (1 .. Len), N);
1025 end Restriction_Msg;
1031 function Same_Unit (U1, U2 : Node_Id) return Boolean is
1033 if Nkind (U1) = N_Identifier then
1034 return Nkind (U2) = N_Identifier and then Chars (U1) = Chars (U2);
1036 elsif Nkind (U2) = N_Identifier then
1039 elsif (Nkind (U1) = N_Selected_Component
1040 or else Nkind (U1) = N_Expanded_Name)
1042 (Nkind (U2) = N_Selected_Component
1043 or else Nkind (U2) = N_Expanded_Name)
1045 return Same_Unit (Prefix (U1), Prefix (U2))
1046 and then Same_Unit (Selector_Name (U1), Selector_Name (U2));
1052 --------------------------------------------
1053 -- Save_Config_Cunit_Boolean_Restrictions --
1054 --------------------------------------------
1056 procedure Save_Config_Cunit_Boolean_Restrictions is
1058 Config_Cunit_Boolean_Restrictions := Cunit_Boolean_Restrictions_Save;
1059 end Save_Config_Cunit_Boolean_Restrictions;
1061 ------------------------------
1062 -- Set_Hidden_Part_In_SPARK --
1063 ------------------------------
1065 procedure Set_Hidden_Part_In_SPARK (Loc1, Loc2 : Source_Ptr) is
1067 SPARK_Hides.Increment_Last;
1068 SPARK_Hides.Table (SPARK_Hides.Last).Start := Loc1;
1069 SPARK_Hides.Table (SPARK_Hides.Last).Stop := Loc2;
1070 end Set_Hidden_Part_In_SPARK;
1072 ------------------------------
1073 -- Set_Profile_Restrictions --
1074 ------------------------------
1076 procedure Set_Profile_Restrictions
1081 R : Restriction_Flags renames Profile_Info (P).Set;
1082 V : Restriction_Values renames Profile_Info (P).Value;
1085 for J in R'Range loop
1088 Already_Restricted : constant Boolean := Restriction_Active (J);
1091 -- Set the restriction
1093 if J in All_Boolean_Restrictions then
1094 Set_Restriction (J, N);
1096 Set_Restriction (J, N, V (J));
1099 -- Record that this came from a Profile[_Warnings] restriction
1101 Restriction_Profile_Name (J) := P;
1103 -- Set warning flag, except that we do not set the warning
1104 -- flag if the restriction was already active and this is
1105 -- the warning case. That avoids a warning overriding a real
1106 -- restriction, which should never happen.
1108 if not (Warn and Already_Restricted) then
1109 Restriction_Warnings (J) := Warn;
1114 end Set_Profile_Restrictions;
1116 ---------------------
1117 -- Set_Restriction --
1118 ---------------------
1120 -- Case of Boolean restriction
1122 procedure Set_Restriction
1123 (R : All_Boolean_Restrictions;
1127 Restrictions.Set (R) := True;
1129 if Restricted_Profile_Cached and Restricted_Profile_Result then
1132 Restricted_Profile_Cached := False;
1135 -- Set location, but preserve location of system restriction for nice
1136 -- error msg with run time name.
1138 if Restrictions_Loc (R) /= System_Location then
1139 Restrictions_Loc (R) := Sloc (N);
1142 -- Note restriction came from restriction pragma, not profile
1144 Restriction_Profile_Name (R) := No_Profile;
1146 -- Record the restriction if we are in the main unit, or in the extended
1147 -- main unit. The reason that we test separately for Main_Unit is that
1148 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1149 -- gnat.adc do not appear to be in the extended main source unit (they
1150 -- probably should do ???)
1152 if Current_Sem_Unit = Main_Unit
1153 or else In_Extended_Main_Source_Unit (N)
1155 if not Restriction_Warnings (R) then
1156 Main_Restrictions.Set (R) := True;
1159 end Set_Restriction;
1161 -- Case of parameter restriction
1163 procedure Set_Restriction
1164 (R : All_Parameter_Restrictions;
1169 if Restricted_Profile_Cached and Restricted_Profile_Result then
1172 Restricted_Profile_Cached := False;
1175 if Restrictions.Set (R) then
1176 if V < Restrictions.Value (R) then
1177 Restrictions.Value (R) := V;
1178 Restrictions_Loc (R) := Sloc (N);
1182 Restrictions.Set (R) := True;
1183 Restrictions.Value (R) := V;
1184 Restrictions_Loc (R) := Sloc (N);
1187 -- Record the restriction if we are in the main unit, or in the extended
1188 -- main unit. The reason that we test separately for Main_Unit is that
1189 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1190 -- gnat.adc do not appear to be the extended main source unit (they
1191 -- probably should do ???)
1193 if Current_Sem_Unit = Main_Unit
1194 or else In_Extended_Main_Source_Unit (N)
1196 if Main_Restrictions.Set (R) then
1197 if V < Main_Restrictions.Value (R) then
1198 Main_Restrictions.Value (R) := V;
1201 elsif not Restriction_Warnings (R) then
1202 Main_Restrictions.Set (R) := True;
1203 Main_Restrictions.Value (R) := V;
1207 -- Note restriction came from restriction pragma, not profile
1209 Restriction_Profile_Name (R) := No_Profile;
1210 end Set_Restriction;
1212 -----------------------------------
1213 -- Set_Restriction_No_Dependence --
1214 -----------------------------------
1216 procedure Set_Restriction_No_Dependence
1219 Profile : Profile_Name := No_Profile)
1222 -- Loop to check for duplicate entry
1224 for J in No_Dependences.First .. No_Dependences.Last loop
1226 -- Case of entry already in table
1228 if Same_Unit (Unit, No_Dependences.Table (J).Unit) then
1230 -- Error has precedence over warning
1233 No_Dependences.Table (J).Warn := False;
1240 -- Entry is not currently in table
1242 No_Dependences.Append ((Unit, Warn, Profile));
1243 end Set_Restriction_No_Dependence;
1245 ------------------------------------------------
1246 -- Set_Restriction_No_Specification_Of_Aspect --
1247 ------------------------------------------------
1249 procedure Set_Restriction_No_Specification_Of_Aspect
1253 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (N));
1254 pragma Assert (A_Id /= No_Aspect);
1257 No_Specification_Of_Aspects (A_Id) := Sloc (N);
1259 if Warning = False then
1260 No_Specification_Of_Aspect_Warning (A_Id) := False;
1263 No_Specification_Of_Aspect_Set := True;
1264 end Set_Restriction_No_Specification_Of_Aspect;
1266 ----------------------------------
1267 -- Suppress_Restriction_Message --
1268 ----------------------------------
1270 function Suppress_Restriction_Message (N : Node_Id) return Boolean is
1272 -- We only output messages for the extended main source unit
1274 if In_Extended_Main_Source_Unit (N) then
1277 -- If loaded by rtsfind, then suppress message
1279 elsif Sloc (N) <= No_Location then
1282 -- Otherwise suppress message if internal file
1285 return Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)));
1287 end Suppress_Restriction_Message;
1289 ---------------------
1290 -- Tasking_Allowed --
1291 ---------------------
1293 function Tasking_Allowed return Boolean is
1295 return not Restrictions.Set (No_Tasking)
1296 and then (not Restrictions.Set (Max_Tasks)
1297 or else Restrictions.Value (Max_Tasks) > 0);
1298 end Tasking_Allowed;