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 Restricted_Profile_Result : Boolean := False;
45 -- This switch memoizes the result of Restricted_Profile function calls for
46 -- improved efficiency. Valid only if Restricted_Profile_Cached is True.
47 -- Note: if this switch is ever set True, it is never turned off again.
49 Restricted_Profile_Cached : Boolean := False;
50 -- This flag is set to True if the Restricted_Profile_Result contains the
51 -- correct cached result of Restricted_Profile calls.
53 No_Specification_Of_Aspects : array (Aspect_Id) of Source_Ptr :=
54 (others => No_Location);
55 -- Entries in this array are set to point to a previously occuring pragma
56 -- that activates a No_Specification_Of_Aspect check.
58 No_Specification_Of_Aspect_Warning : array (Aspect_Id) of Boolean :=
60 -- An entry in this array is set False in reponse to a previous call to
61 -- Set_No_Speficiation_Of_Aspect for pragmas in the main unit that
62 -- specify Warning as False. Once set False, an entry is never reset.
64 No_Specification_Of_Aspect_Set : Boolean := False;
65 -- Set True if any entry of No_Specifcation_Of_Aspects has been set True.
66 -- Once set True, this is never turned off again.
68 -----------------------
69 -- Local Subprograms --
70 -----------------------
72 procedure Restriction_Msg (R : Restriction_Id; N : Node_Id);
73 -- Called if a violation of restriction R at node N is found. This routine
74 -- outputs the appropriate message or messages taking care of warning vs
75 -- real violation, serious vs non-serious, implicit vs explicit, the second
76 -- message giving the profile name if needed, and the location information.
78 function Same_Unit (U1, U2 : Node_Id) return Boolean;
79 -- Returns True iff U1 and U2 represent the same library unit. Used for
80 -- handling of No_Dependence => Unit restriction case.
82 function Suppress_Restriction_Message (N : Node_Id) return Boolean;
83 -- N is the node for a possible restriction violation message, but the
84 -- message is to be suppressed if this is an internal file and this file is
85 -- not the main unit. Returns True if message is to be suppressed.
91 function Abort_Allowed return Boolean is
93 if Restrictions.Set (No_Abort_Statements)
94 and then Restrictions.Set (Max_Asynchronous_Select_Nesting)
95 and then Restrictions.Value (Max_Asynchronous_Select_Nesting) = 0
103 -------------------------
104 -- Check_Compiler_Unit --
105 -------------------------
107 procedure Check_Compiler_Unit (N : Node_Id) is
109 if Is_Compiler_Unit (Get_Source_Unit (N)) then
110 Error_Msg_N ("use of construct not allowed in compiler", N);
112 end Check_Compiler_Unit;
114 ------------------------------------
115 -- Check_Elaboration_Code_Allowed --
116 ------------------------------------
118 procedure Check_Elaboration_Code_Allowed (N : Node_Id) is
120 Check_Restriction (No_Elaboration_Code, N);
121 end Check_Elaboration_Code_Allowed;
123 -----------------------------
124 -- Check_SPARK_Restriction --
125 -----------------------------
127 procedure Check_SPARK_Restriction
130 Force : Boolean := False)
132 Msg_Issued : Boolean;
133 Save_Error_Msg_Sloc : Source_Ptr;
135 if Force or else Comes_From_Source (Original_Node (N)) then
137 if Restriction_Check_Required (SPARK)
138 and then Is_In_Hidden_Part_In_SPARK (Sloc (N))
143 -- Since the call to Restriction_Msg from Check_Restriction may set
144 -- Error_Msg_Sloc to the location of the pragma restriction, save and
145 -- restore the previous value of the global variable around the call.
147 Save_Error_Msg_Sloc := Error_Msg_Sloc;
148 Check_Restriction (Msg_Issued, SPARK, First_Node (N));
149 Error_Msg_Sloc := Save_Error_Msg_Sloc;
152 Error_Msg_F ("\\| " & Msg, N);
155 end Check_SPARK_Restriction;
157 procedure Check_SPARK_Restriction (Msg1, Msg2 : String; N : Node_Id) is
158 Msg_Issued : Boolean;
159 Save_Error_Msg_Sloc : Source_Ptr;
161 pragma Assert (Msg2'Length /= 0 and then Msg2 (Msg2'First) = '\');
163 if Comes_From_Source (Original_Node (N)) then
165 if Restriction_Check_Required (SPARK)
166 and then Is_In_Hidden_Part_In_SPARK (Sloc (N))
171 -- Since the call to Restriction_Msg from Check_Restriction may set
172 -- Error_Msg_Sloc to the location of the pragma restriction, save and
173 -- restore the previous value of the global variable around the call.
175 Save_Error_Msg_Sloc := Error_Msg_Sloc;
176 Check_Restriction (Msg_Issued, SPARK, First_Node (N));
177 Error_Msg_Sloc := Save_Error_Msg_Sloc;
180 Error_Msg_F ("\\| " & Msg1, N);
181 Error_Msg_F (Msg2, N);
184 end Check_SPARK_Restriction;
186 -----------------------------------------
187 -- Check_Implicit_Dynamic_Code_Allowed --
188 -----------------------------------------
190 procedure Check_Implicit_Dynamic_Code_Allowed (N : Node_Id) is
192 Check_Restriction (No_Implicit_Dynamic_Code, N);
193 end Check_Implicit_Dynamic_Code_Allowed;
195 ----------------------------------
196 -- Check_No_Implicit_Heap_Alloc --
197 ----------------------------------
199 procedure Check_No_Implicit_Heap_Alloc (N : Node_Id) is
201 Check_Restriction (No_Implicit_Heap_Allocations, N);
202 end Check_No_Implicit_Heap_Alloc;
204 -----------------------------------
205 -- Check_Obsolescent_2005_Entity --
206 -----------------------------------
208 procedure Check_Obsolescent_2005_Entity (E : Entity_Id; N : Node_Id) is
209 function Chars_Is (E : Entity_Id; S : String) return Boolean;
210 -- Return True iff Chars (E) matches S (given in lower case)
212 function Chars_Is (E : Entity_Id; S : String) return Boolean is
213 Nam : constant Name_Id := Chars (E);
215 if Length_Of_Name (Nam) /= S'Length then
218 return Get_Name_String (Nam) = S;
222 -- Start of processing for Check_Obsolescent_2005_Entity
225 if Restriction_Check_Required (No_Obsolescent_Features)
226 and then Ada_Version >= Ada_2005
227 and then Chars_Is (Scope (E), "handling")
228 and then Chars_Is (Scope (Scope (E)), "characters")
229 and then Chars_Is (Scope (Scope (Scope (E))), "ada")
230 and then Scope (Scope (Scope (Scope (E)))) = Standard_Standard
232 if Chars_Is (E, "is_character") or else
233 Chars_Is (E, "is_string") or else
234 Chars_Is (E, "to_character") or else
235 Chars_Is (E, "to_string") or else
236 Chars_Is (E, "to_wide_character") or else
237 Chars_Is (E, "to_wide_string")
239 Check_Restriction (No_Obsolescent_Features, N);
242 end Check_Obsolescent_2005_Entity;
244 ---------------------------
245 -- Check_Restricted_Unit --
246 ---------------------------
248 procedure Check_Restricted_Unit (U : Unit_Name_Type; N : Node_Id) is
250 if Suppress_Restriction_Message (N) then
253 elsif Is_Spec_Name (U) then
255 Fnam : constant File_Name_Type :=
256 Get_File_Name (U, Subunit => False);
261 Get_Name_String (Fnam);
263 -- Nothing to do if name not at least 5 characters long ending
264 -- in .ads or .adb extension, which we strip.
267 or else (Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads"
269 Name_Buffer (Name_Len - 3 .. Name_Len) /= ".adb")
274 -- Strip extension and pad to eight characters
276 Name_Len := Name_Len - 4;
277 Add_Str_To_Name_Buffer ((Name_Len + 1 .. 8 => ' '));
279 -- If predefined unit, check the list of restricted units
281 if Is_Predefined_File_Name (Fnam) then
282 for J in Unit_Array'Range loop
284 and then Name_Buffer (1 .. 8) = Unit_Array (J).Filenm
286 Check_Restriction (Unit_Array (J).Res_Id, N);
290 -- If not predefined unit, then one special check still
291 -- remains. GNAT.Current_Exception is not allowed if we have
292 -- restriction No_Exception_Propagation active.
295 if Name_Buffer (1 .. 8) = "g-curexc" then
296 Check_Restriction (No_Exception_Propagation, N);
301 end Check_Restricted_Unit;
303 -----------------------
304 -- Check_Restriction --
305 -----------------------
307 procedure Check_Restriction
310 V : Uint := Uint_Minus_1)
312 Msg_Issued : Boolean;
313 pragma Unreferenced (Msg_Issued);
315 Check_Restriction (Msg_Issued, R, N, V);
316 end Check_Restriction;
318 procedure Check_Restriction
319 (Msg_Issued : out Boolean;
322 V : Uint := Uint_Minus_1)
325 -- V converted to integer form. If V is greater than Integer'Last,
326 -- it is reset to minus 1 (unknown value).
328 procedure Update_Restrictions (Info : in out Restrictions_Info);
329 -- Update violation information in Info.Violated and Info.Count
331 -------------------------
332 -- Update_Restrictions --
333 -------------------------
335 procedure Update_Restrictions (Info : in out Restrictions_Info) is
337 -- If not violated, set as violated now
339 if not Info.Violated (R) then
340 Info.Violated (R) := True;
342 if R in All_Parameter_Restrictions then
344 Info.Unknown (R) := True;
347 Info.Count (R) := VV;
351 -- Otherwise if violated already and a parameter restriction,
352 -- update count by maximizing or summing depending on restriction.
354 elsif R in All_Parameter_Restrictions then
356 -- If new value is unknown, result is unknown
359 Info.Unknown (R) := True;
361 -- If checked by maximization, do maximization
363 elsif R in Checked_Max_Parameter_Restrictions then
364 Info.Count (R) := Integer'Max (Info.Count (R), VV);
366 -- If checked by adding, do add, checking for overflow
368 elsif R in Checked_Add_Parameter_Restrictions then
370 pragma Unsuppress (Overflow_Check);
372 Info.Count (R) := Info.Count (R) + VV;
374 when Constraint_Error =>
375 Info.Count (R) := Integer'Last;
376 Info.Unknown (R) := True;
379 -- Should not be able to come here, known counts should only
380 -- occur for restrictions that are Checked_max or Checked_Sum.
386 end Update_Restrictions;
388 -- Start of processing for Check_Restriction
393 -- In CodePeer and Alfa mode, we do not want to check for any
394 -- restriction, or set additional restrictions other than those already
395 -- set in gnat1drv.adb so that we have consistency between each
398 if CodePeer_Mode or Alfa_Mode then
402 -- In SPARK mode, issue an error for any use of class-wide, even if the
403 -- No_Dispatch restriction is not set.
405 if R = No_Dispatch then
406 Check_SPARK_Restriction ("class-wide is not allowed", N);
409 if UI_Is_In_Int_Range (V) then
410 VV := Integer (UI_To_Int (V));
415 -- Count can only be specified in the checked val parameter case
417 pragma Assert (VV < 0 or else R in Checked_Val_Parameter_Restrictions);
419 -- Nothing to do if value of zero specified for parameter restriction
425 -- Update current restrictions
427 Update_Restrictions (Restrictions);
429 -- If in main extended unit, update main restrictions as well
431 if Current_Sem_Unit = Main_Unit
432 or else In_Extended_Main_Source_Unit (N)
434 Update_Restrictions (Main_Restrictions);
437 -- Nothing to do if restriction message suppressed
439 if Suppress_Restriction_Message (N) then
442 -- If restriction not set, nothing to do
444 elsif not Restrictions.Set (R) then
447 -- Here if restriction set, check for violation (either this is a
448 -- Boolean restriction, or a parameter restriction with a value of
449 -- zero and an unknown count, or a parameter restriction with a
450 -- known value that exceeds the restriction count).
452 elsif R in All_Boolean_Restrictions
453 or else (Restrictions.Unknown (R)
454 and then Restrictions.Value (R) = 0)
455 or else Restrictions.Count (R) > Restrictions.Value (R)
458 Restriction_Msg (R, N);
460 end Check_Restriction;
462 -------------------------------------
463 -- Check_Restriction_No_Dependence --
464 -------------------------------------
466 procedure Check_Restriction_No_Dependence (U : Node_Id; Err : Node_Id) is
470 -- Ignore call if node U is not in the main source unit. This avoids
471 -- cascaded errors, e.g. when Ada.Containers units with other units.
473 if not In_Extended_Main_Source_Unit (U) then
477 -- Loop through entries in No_Dependence table to check each one in turn
479 for J in No_Dependences.First .. No_Dependences.Last loop
480 DU := No_Dependences.Table (J).Unit;
482 if Same_Unit (U, DU) then
483 Error_Msg_Sloc := Sloc (DU);
484 Error_Msg_Node_1 := DU;
486 if No_Dependences.Table (J).Warn then
488 ("?violation of restriction `No_Dependence '='> &`#",
492 ("|violation of restriction `No_Dependence '='> &`#",
499 end Check_Restriction_No_Dependence;
501 --------------------------------------------------
502 -- Check_Restriction_No_Specification_Of_Aspect --
503 --------------------------------------------------
505 procedure Check_Restriction_No_Specification_Of_Aspect (N : Node_Id) is
510 -- Ignore call if no instances of this restriction set
512 if not No_Specification_Of_Aspect_Set then
516 -- Ignore call if node N is not in the main source unit, since we only
517 -- give messages for . This avoids giving messages for aspects that are
518 -- specified in withed units.
520 if not In_Extended_Main_Source_Unit (N) then
524 Id := Identifier (N);
525 A_Id := Get_Aspect_Id (Chars (Id));
526 pragma Assert (A_Id /= No_Aspect);
528 Error_Msg_Sloc := No_Specification_Of_Aspects (A_Id);
530 if Error_Msg_Sloc /= No_Location then
531 Error_Msg_Node_1 := Id;
532 Error_Msg_Warn := No_Specification_Of_Aspect_Warning (A_Id);
534 ("<violation of restriction `No_Specification_Of_Aspect '='> &`#",
537 end Check_Restriction_No_Specification_Of_Aspect;
539 --------------------------------------
540 -- Check_Wide_Character_Restriction --
541 --------------------------------------
543 procedure Check_Wide_Character_Restriction (E : Entity_Id; N : Node_Id) is
545 if Restriction_Check_Required (No_Wide_Characters)
546 and then Comes_From_Source (N)
549 T : constant Entity_Id := Root_Type (E);
551 if T = Standard_Wide_Character or else
552 T = Standard_Wide_String or else
553 T = Standard_Wide_Wide_Character or else
554 T = Standard_Wide_Wide_String
556 Check_Restriction (No_Wide_Characters, N);
560 end Check_Wide_Character_Restriction;
562 ----------------------------------------
563 -- Cunit_Boolean_Restrictions_Restore --
564 ----------------------------------------
566 procedure Cunit_Boolean_Restrictions_Restore
567 (R : Save_Cunit_Boolean_Restrictions)
570 for J in Cunit_Boolean_Restrictions loop
571 Restrictions.Set (J) := R (J);
573 end Cunit_Boolean_Restrictions_Restore;
575 -------------------------------------
576 -- Cunit_Boolean_Restrictions_Save --
577 -------------------------------------
579 function Cunit_Boolean_Restrictions_Save
580 return Save_Cunit_Boolean_Restrictions
582 R : Save_Cunit_Boolean_Restrictions;
585 for J in Cunit_Boolean_Restrictions loop
586 R (J) := Restrictions.Set (J);
587 Restrictions.Set (J) := False;
591 end Cunit_Boolean_Restrictions_Save;
593 ------------------------
594 -- Get_Restriction_Id --
595 ------------------------
597 function Get_Restriction_Id
598 (N : Name_Id) return Restriction_Id
602 Set_Casing (All_Upper_Case);
604 for J in All_Restrictions loop
606 S : constant String := Restriction_Id'Image (J);
608 if S = Name_Buffer (1 .. Name_Len) then
614 return Not_A_Restriction_Id;
615 end Get_Restriction_Id;
617 --------------------------------
618 -- Is_In_Hidden_Part_In_SPARK --
619 --------------------------------
621 function Is_In_Hidden_Part_In_SPARK (Loc : Source_Ptr) return Boolean is
623 -- Loop through table of hidden ranges
625 for J in SPARK_Hides.First .. SPARK_Hides.Last loop
626 if SPARK_Hides.Table (J).Start <= Loc
627 and then Loc < SPARK_Hides.Table (J).Stop
634 end Is_In_Hidden_Part_In_SPARK;
636 -------------------------------
637 -- No_Exception_Handlers_Set --
638 -------------------------------
640 function No_Exception_Handlers_Set return Boolean is
642 return (No_Run_Time_Mode or else Configurable_Run_Time_Mode)
643 and then (Restrictions.Set (No_Exception_Handlers)
645 Restrictions.Set (No_Exception_Propagation));
646 end No_Exception_Handlers_Set;
648 -------------------------------------
649 -- No_Exception_Propagation_Active --
650 -------------------------------------
652 function No_Exception_Propagation_Active return Boolean is
654 return (No_Run_Time_Mode
655 or else Configurable_Run_Time_Mode
656 or else Debug_Flag_Dot_G)
657 and then Restriction_Active (No_Exception_Propagation);
658 end No_Exception_Propagation_Active;
660 ----------------------------------
661 -- Process_Restriction_Synonyms --
662 ----------------------------------
664 -- Note: body of this function must be coordinated with list of
665 -- renaming declarations in System.Rident.
667 function Process_Restriction_Synonyms (N : Node_Id) return Name_Id
669 Old_Name : constant Name_Id := Chars (N);
674 when Name_Boolean_Entry_Barriers =>
675 New_Name := Name_Simple_Barriers;
677 when Name_Max_Entry_Queue_Depth =>
678 New_Name := Name_Max_Entry_Queue_Length;
680 when Name_No_Dynamic_Interrupts =>
681 New_Name := Name_No_Dynamic_Attachment;
683 when Name_No_Requeue =>
684 New_Name := Name_No_Requeue_Statements;
686 when Name_No_Task_Attributes =>
687 New_Name := Name_No_Task_Attributes_Package;
693 if Warn_On_Obsolescent_Feature then
694 Error_Msg_Name_1 := Old_Name;
695 Error_Msg_N ("restriction identifier % is obsolescent?", N);
696 Error_Msg_Name_1 := New_Name;
697 Error_Msg_N ("|use restriction identifier % instead", N);
701 end Process_Restriction_Synonyms;
703 ------------------------
704 -- Restricted_Profile --
705 ------------------------
707 function Restricted_Profile return Boolean is
709 if Restricted_Profile_Cached then
710 return Restricted_Profile_Result;
713 Restricted_Profile_Result := True;
714 Restricted_Profile_Cached := True;
717 R : Restriction_Flags renames Profile_Info (Restricted).Set;
718 V : Restriction_Values renames Profile_Info (Restricted).Value;
720 for J in R'Range loop
722 and then (Restrictions.Set (J) = False
723 or else Restriction_Warnings (J)
725 (J in All_Parameter_Restrictions
726 and then Restrictions.Value (J) > V (J)))
728 Restricted_Profile_Result := False;
733 return Restricted_Profile_Result;
736 end Restricted_Profile;
738 ------------------------
739 -- Restriction_Active --
740 ------------------------
742 function Restriction_Active (R : All_Restrictions) return Boolean is
744 return Restrictions.Set (R) and then not Restriction_Warnings (R);
745 end Restriction_Active;
747 --------------------------------
748 -- Restriction_Check_Required --
749 --------------------------------
751 function Restriction_Check_Required (R : All_Restrictions) return Boolean is
753 return Restrictions.Set (R);
754 end Restriction_Check_Required;
756 ---------------------
757 -- Restriction_Msg --
758 ---------------------
760 procedure Restriction_Msg (R : Restriction_Id; N : Node_Id) is
761 Msg : String (1 .. 100);
764 procedure Add_Char (C : Character);
765 -- Append given character to Msg, bumping Len
767 procedure Add_Str (S : String);
768 -- Append given string to Msg, bumping Len appropriately
770 procedure Id_Case (S : String; Quotes : Boolean := True);
771 -- Given a string S, case it according to current identifier casing,
772 -- except for SPARK (an acronym) which is set all upper case, and store
773 -- in Error_Msg_String. Then append `~` to the message buffer to output
774 -- the string unchanged surrounded in quotes. The quotes are suppressed
775 -- if Quotes = False.
781 procedure Add_Char (C : Character) is
791 procedure Add_Str (S : String) is
793 Msg (Len + 1 .. Len + S'Length) := S;
794 Len := Len + S'Length;
801 procedure Id_Case (S : String; Quotes : Boolean := True) is
803 Name_Buffer (1 .. S'Last) := S;
804 Name_Len := S'Length;
809 Set_Casing (Identifier_Casing (Get_Source_File_Index (Sloc (N))));
812 Error_Msg_Strlen := Name_Len;
813 Error_Msg_String (1 .. Name_Len) := Name_Buffer (1 .. Name_Len);
822 -- Start of processing for Restriction_Msg
825 -- Set warning message if warning
827 if Restriction_Warnings (R) then
830 -- If real violation (not warning), then mark it as non-serious unless
831 -- it is a violation of No_Finalization in which case we leave it as a
832 -- serious message, since otherwise we get crashes during attempts to
833 -- expand stuff that is not properly formed due to assumptions made
834 -- about no finalization being present.
836 elsif R /= No_Finalization then
840 Error_Msg_Sloc := Restrictions_Loc (R);
842 -- Set main message, adding implicit if no source location
844 if Error_Msg_Sloc > No_Location
845 or else Error_Msg_Sloc = System_Location
847 Add_Str ("violation of restriction ");
849 Add_Str ("violation of implicit restriction ");
850 Error_Msg_Sloc := No_Location;
853 -- Case of parameterized restriction
855 if R in All_Parameter_Restrictions then
857 Id_Case (Restriction_Id'Image (R), Quotes => False);
859 Error_Msg_Uint_1 := UI_From_Int (Int (Restrictions.Value (R)));
861 -- Case of boolean restriction
864 Id_Case (Restriction_Id'Image (R));
867 -- Case of no secondary profile continuation message
869 if Restriction_Profile_Name (R) = No_Profile then
870 if Error_Msg_Sloc /= No_Location then
875 Error_Msg_N (Msg (1 .. Len), N);
877 -- Case of secondary profile continuation message present
881 Error_Msg_N (Msg (1 .. Len), N);
886 -- Set as warning if warning case
888 if Restriction_Warnings (R) then
894 Add_Str ("from profile ");
895 Id_Case (Profile_Name'Image (Restriction_Profile_Name (R)));
897 -- Add location if we have one
899 if Error_Msg_Sloc /= No_Location then
903 -- Output unconditional message and we are done
906 Error_Msg_N (Msg (1 .. Len), N);
914 function Same_Unit (U1, U2 : Node_Id) return Boolean is
916 if Nkind (U1) = N_Identifier then
917 return Nkind (U2) = N_Identifier and then Chars (U1) = Chars (U2);
919 elsif Nkind (U2) = N_Identifier then
922 elsif (Nkind (U1) = N_Selected_Component
923 or else Nkind (U1) = N_Expanded_Name)
925 (Nkind (U2) = N_Selected_Component
926 or else Nkind (U2) = N_Expanded_Name)
928 return Same_Unit (Prefix (U1), Prefix (U2))
929 and then Same_Unit (Selector_Name (U1), Selector_Name (U2));
935 ------------------------------
936 -- Set_Hidden_Part_In_SPARK --
937 ------------------------------
939 procedure Set_Hidden_Part_In_SPARK (Loc1, Loc2 : Source_Ptr) is
941 SPARK_Hides.Increment_Last;
942 SPARK_Hides.Table (SPARK_Hides.Last).Start := Loc1;
943 SPARK_Hides.Table (SPARK_Hides.Last).Stop := Loc2;
944 end Set_Hidden_Part_In_SPARK;
946 ------------------------------
947 -- Set_Profile_Restrictions --
948 ------------------------------
950 procedure Set_Profile_Restrictions
955 R : Restriction_Flags renames Profile_Info (P).Set;
956 V : Restriction_Values renames Profile_Info (P).Value;
959 for J in R'Range loop
962 Already_Restricted : constant Boolean := Restriction_Active (J);
965 -- Set the restriction
967 if J in All_Boolean_Restrictions then
968 Set_Restriction (J, N);
970 Set_Restriction (J, N, V (J));
973 -- Record that this came from a Profile[_Warnings] restriction
975 Restriction_Profile_Name (J) := P;
977 -- Set warning flag, except that we do not set the warning
978 -- flag if the restriction was already active and this is
979 -- the warning case. That avoids a warning overriding a real
980 -- restriction, which should never happen.
982 if not (Warn and Already_Restricted) then
983 Restriction_Warnings (J) := Warn;
988 end Set_Profile_Restrictions;
990 ---------------------
991 -- Set_Restriction --
992 ---------------------
994 -- Case of Boolean restriction
996 procedure Set_Restriction
997 (R : All_Boolean_Restrictions;
1001 -- Restriction No_Elaboration_Code must be enforced on a unit by unit
1002 -- basis. Hence, we avoid setting the restriction when processing an
1003 -- unit which is not the main one being compiled (or its corresponding
1004 -- spec). It can happen, for example, when processing an inlined body
1005 -- (the package containing the inlined subprogram is analyzed,
1006 -- including its pragma Restrictions).
1008 -- This seems like a very nasty kludge??? This is not the only per unit
1009 -- restriction why is this treated specially ???
1011 if R = No_Elaboration_Code
1012 and then Current_Sem_Unit /= Main_Unit
1013 and then Cunit (Current_Sem_Unit) /= Library_Unit (Cunit (Main_Unit))
1018 Restrictions.Set (R) := True;
1020 if Restricted_Profile_Cached and Restricted_Profile_Result then
1023 Restricted_Profile_Cached := False;
1026 -- Set location, but preserve location of system restriction for nice
1027 -- error msg with run time name.
1029 if Restrictions_Loc (R) /= System_Location then
1030 Restrictions_Loc (R) := Sloc (N);
1033 -- Note restriction came from restriction pragma, not profile
1035 Restriction_Profile_Name (R) := No_Profile;
1037 -- Record the restriction if we are in the main unit, or in the extended
1038 -- main unit. The reason that we test separately for Main_Unit is that
1039 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1040 -- gnat.adc do not appear to be in the extended main source unit (they
1041 -- probably should do ???)
1043 if Current_Sem_Unit = Main_Unit
1044 or else In_Extended_Main_Source_Unit (N)
1046 if not Restriction_Warnings (R) then
1047 Main_Restrictions.Set (R) := True;
1050 end Set_Restriction;
1052 -- Case of parameter restriction
1054 procedure Set_Restriction
1055 (R : All_Parameter_Restrictions;
1060 if Restricted_Profile_Cached and Restricted_Profile_Result then
1063 Restricted_Profile_Cached := False;
1066 if Restrictions.Set (R) then
1067 if V < Restrictions.Value (R) then
1068 Restrictions.Value (R) := V;
1069 Restrictions_Loc (R) := Sloc (N);
1073 Restrictions.Set (R) := True;
1074 Restrictions.Value (R) := V;
1075 Restrictions_Loc (R) := Sloc (N);
1078 -- Record the restriction if we are in the main unit, or in the extended
1079 -- main unit. The reason that we test separately for Main_Unit is that
1080 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1081 -- gnat.adc do not appear to be the extended main source unit (they
1082 -- probably should do ???)
1084 if Current_Sem_Unit = Main_Unit
1085 or else In_Extended_Main_Source_Unit (N)
1087 if Main_Restrictions.Set (R) then
1088 if V < Main_Restrictions.Value (R) then
1089 Main_Restrictions.Value (R) := V;
1092 elsif not Restriction_Warnings (R) then
1093 Main_Restrictions.Set (R) := True;
1094 Main_Restrictions.Value (R) := V;
1098 -- Note restriction came from restriction pragma, not profile
1100 Restriction_Profile_Name (R) := No_Profile;
1101 end Set_Restriction;
1103 -----------------------------------
1104 -- Set_Restriction_No_Dependence --
1105 -----------------------------------
1107 procedure Set_Restriction_No_Dependence
1110 Profile : Profile_Name := No_Profile)
1113 -- Loop to check for duplicate entry
1115 for J in No_Dependences.First .. No_Dependences.Last loop
1117 -- Case of entry already in table
1119 if Same_Unit (Unit, No_Dependences.Table (J).Unit) then
1121 -- Error has precedence over warning
1124 No_Dependences.Table (J).Warn := False;
1131 -- Entry is not currently in table
1133 No_Dependences.Append ((Unit, Warn, Profile));
1134 end Set_Restriction_No_Dependence;
1136 ------------------------------------------------
1137 -- Set_Restriction_No_Specification_Of_Aspect --
1138 ------------------------------------------------
1140 procedure Set_Restriction_No_Specification_Of_Aspect
1144 A_Id : constant Aspect_Id := Get_Aspect_Id (Chars (N));
1145 pragma Assert (A_Id /= No_Aspect);
1148 No_Specification_Of_Aspects (A_Id) := Sloc (N);
1150 if Warning = False then
1151 No_Specification_Of_Aspect_Warning (A_Id) := False;
1154 No_Specification_Of_Aspect_Set := True;
1155 end Set_Restriction_No_Specification_Of_Aspect;
1157 ----------------------------------
1158 -- Suppress_Restriction_Message --
1159 ----------------------------------
1161 function Suppress_Restriction_Message (N : Node_Id) return Boolean is
1163 -- We only output messages for the extended main source unit
1165 if In_Extended_Main_Source_Unit (N) then
1168 -- If loaded by rtsfind, then suppress message
1170 elsif Sloc (N) <= No_Location then
1173 -- Otherwise suppress message if internal file
1176 return Is_Internal_File_Name (Unit_File_Name (Get_Source_Unit (N)));
1178 end Suppress_Restriction_Message;
1180 ---------------------
1181 -- Tasking_Allowed --
1182 ---------------------
1184 function Tasking_Allowed return Boolean is
1186 return not Restrictions.Set (No_Tasking)
1187 and then (not Restrictions.Set (Max_Tasks)
1188 or else Restrictions.Value (Max_Tasks) > 0);
1189 end Tasking_Allowed;