1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2020, 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 Atree
; use Atree
;
27 with Casing
; use Casing
;
28 with Einfo
; use Einfo
;
29 with Errout
; use Errout
;
30 with Debug
; use Debug
;
31 with Fname
; use Fname
;
32 with Fname
.UF
; use Fname
.UF
;
35 with Sinfo
; use Sinfo
;
36 with Sinput
; use Sinput
;
37 with Stand
; use Stand
;
38 with Targparm
; use Targparm
;
39 with Uname
; use Uname
;
41 package body Restrict
is
43 Global_Restriction_No_Tasking
: Boolean := False;
44 -- Set to True when No_Tasking is set in the run-time package System
45 -- or in a configuration pragmas file (for example, gnat.adc).
47 --------------------------------
48 -- Package Local Declarations --
49 --------------------------------
51 Config_Cunit_Boolean_Restrictions
: Save_Cunit_Boolean_Restrictions
;
52 -- Save compilation unit restrictions set by config pragma files
54 Restricted_Profile_Result
: Boolean := False;
55 -- This switch memoizes the result of Restricted_Profile function calls for
56 -- improved efficiency. Valid only if Restricted_Profile_Cached is True.
57 -- Note: if this switch is ever set True, it is never turned off again.
59 Restricted_Profile_Cached
: Boolean := False;
60 -- This flag is set to True if the Restricted_Profile_Result contains the
61 -- correct cached result of Restricted_Profile calls.
63 No_Specification_Of_Aspects
: array (Aspect_Id
) of Source_Ptr
:=
64 (others => No_Location
);
65 -- Entries in this array are set to point to a previously occuring pragma
66 -- that activates a No_Specification_Of_Aspect check.
68 No_Specification_Of_Aspect_Warning
: array (Aspect_Id
) of Boolean :=
70 -- An entry in this array is set False in reponse to a previous call to
71 -- Set_No_Speficiation_Of_Aspect for pragmas in the main unit that
72 -- specify Warning as False. Once set False, an entry is never reset.
74 No_Specification_Of_Aspect_Set
: Boolean := False;
75 -- Set True if any entry of No_Specifcation_Of_Aspects has been set True.
76 -- Once set True, this is never turned off again.
78 No_Use_Of_Attribute
: array (Attribute_Id
) of Source_Ptr
:=
79 (others => No_Location
);
81 No_Use_Of_Attribute_Warning
: array (Attribute_Id
) of Boolean :=
84 No_Use_Of_Attribute_Set
: Boolean := False;
85 -- Indicates that No_Use_Of_Attribute was set at least once
87 No_Use_Of_Pragma
: array (Pragma_Id
) of Source_Ptr
:=
88 (others => No_Location
);
89 -- Source location of pragma No_Use_Of_Pragma for given pragma, a value
90 -- of System_Location indicates occurrence in system.ads.
92 No_Use_Of_Pragma_Warning
: array (Pragma_Id
) of Boolean :=
95 No_Use_Of_Pragma_Set
: Boolean := False;
96 -- Indicates that No_Use_Of_Pragma was set at least once
98 -----------------------
99 -- Local Subprograms --
100 -----------------------
102 procedure Restriction_Msg
(R
: Restriction_Id
; N
: Node_Id
);
103 -- Called if a violation of restriction R at node N is found. This routine
104 -- outputs the appropriate message or messages taking care of warning vs
105 -- real violation, serious vs non-serious, implicit vs explicit, the second
106 -- message giving the profile name if needed, and the location information.
108 function Same_Entity
(E1
, E2
: Node_Id
) return Boolean;
109 -- Returns True iff E1 and E2 represent the same entity. Used for handling
110 -- of No_Use_Of_Entity => fully_qualified_ENTITY restriction case.
112 function Same_Unit
(U1
, U2
: Node_Id
) return Boolean;
113 -- Returns True iff U1 and U2 represent the same library unit. Used for
114 -- handling of No_Dependence => Unit restriction case.
116 function Suppress_Restriction_Message
(N
: Node_Id
) return Boolean;
117 -- N is the node for a possible restriction violation message, but the
118 -- message is to be suppressed if this is an internal file and this file is
119 -- not the main unit. Returns True if message is to be suppressed.
125 function Abort_Allowed
return Boolean is
127 if Restrictions
.Set
(No_Abort_Statements
)
128 and then Restrictions
.Set
(Max_Asynchronous_Select_Nesting
)
129 and then Restrictions
.Value
(Max_Asynchronous_Select_Nesting
) = 0
137 ----------------------------------------
138 -- Add_To_Config_Boolean_Restrictions --
139 ----------------------------------------
141 procedure Add_To_Config_Boolean_Restrictions
(R
: Restriction_Id
) is
143 Config_Cunit_Boolean_Restrictions
(R
) := True;
144 end Add_To_Config_Boolean_Restrictions
;
145 -- Add specified restriction to stored configuration boolean restrictions.
146 -- This is used for handling the special case of No_Elaboration_Code.
148 -------------------------
149 -- Check_Compiler_Unit --
150 -------------------------
152 procedure Check_Compiler_Unit
(Feature
: String; N
: Node_Id
) is
154 if Compiler_Unit
then
155 Error_Msg_N
(Feature
& " not allowed in compiler unit!!??", N
);
157 end Check_Compiler_Unit
;
159 procedure Check_Compiler_Unit
(Feature
: String; Loc
: Source_Ptr
) is
161 if Compiler_Unit
then
162 Error_Msg
(Feature
& " not allowed in compiler unit!!??", Loc
);
164 end Check_Compiler_Unit
;
166 ------------------------------------
167 -- Check_Elaboration_Code_Allowed --
168 ------------------------------------
170 procedure Check_Elaboration_Code_Allowed
(N
: Node_Id
) is
172 Check_Restriction
(No_Elaboration_Code
, N
);
173 end Check_Elaboration_Code_Allowed
;
175 -----------------------------------------
176 -- Check_Implicit_Dynamic_Code_Allowed --
177 -----------------------------------------
179 procedure Check_Implicit_Dynamic_Code_Allowed
(N
: Node_Id
) is
181 Check_Restriction
(No_Implicit_Dynamic_Code
, N
);
182 end Check_Implicit_Dynamic_Code_Allowed
;
184 --------------------------------
185 -- Check_No_Implicit_Aliasing --
186 --------------------------------
188 procedure Check_No_Implicit_Aliasing
(Obj
: Node_Id
) is
192 -- If restriction not active, nothing to check
194 if not Restriction_Active
(No_Implicit_Aliasing
) then
198 -- If we have an entity name, check entity
200 if Is_Entity_Name
(Obj
) then
203 -- Restriction applies to entities that are objects
205 if Is_Object
(E
) then
206 if Is_Aliased
(E
) then
209 elsif Present
(Renamed_Object
(E
)) then
210 Check_No_Implicit_Aliasing
(Renamed_Object
(E
));
214 -- If we don't have an object, then it's OK
220 -- For selected component, check selector
222 elsif Nkind
(Obj
) = N_Selected_Component
then
223 Check_No_Implicit_Aliasing
(Selector_Name
(Obj
));
226 -- Indexed component is OK if aliased components
228 elsif Nkind
(Obj
) = N_Indexed_Component
then
229 if Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
231 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
232 and then Has_Aliased_Components
233 (Designated_Type
(Etype
(Prefix
(Obj
)))))
238 -- For type conversion, check converted expression
240 elsif Nkind
(Obj
) in N_Unchecked_Type_Conversion | N_Type_Conversion
then
241 Check_No_Implicit_Aliasing
(Expression
(Obj
));
244 -- Explicit dereference is always OK
246 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
250 -- If we fall through, then we have an aliased view that does not meet
251 -- the rules for being explicitly aliased, so issue restriction msg.
253 Check_Restriction
(No_Implicit_Aliasing
, Obj
);
254 end Check_No_Implicit_Aliasing
;
256 ----------------------------------
257 -- Check_No_Implicit_Heap_Alloc --
258 ----------------------------------
260 procedure Check_No_Implicit_Heap_Alloc
(N
: Node_Id
) is
262 Check_Restriction
(No_Implicit_Heap_Allocations
, N
);
263 end Check_No_Implicit_Heap_Alloc
;
265 ----------------------------------
266 -- Check_No_Implicit_Task_Alloc --
267 ----------------------------------
269 procedure Check_No_Implicit_Task_Alloc
(N
: Node_Id
) is
271 Check_Restriction
(No_Implicit_Task_Allocations
, N
);
272 end Check_No_Implicit_Task_Alloc
;
274 ---------------------------------------
275 -- Check_No_Implicit_Protected_Alloc --
276 ---------------------------------------
278 procedure Check_No_Implicit_Protected_Alloc
(N
: Node_Id
) is
280 Check_Restriction
(No_Implicit_Protected_Object_Allocations
, N
);
281 end Check_No_Implicit_Protected_Alloc
;
283 -----------------------------------
284 -- Check_Obsolescent_2005_Entity --
285 -----------------------------------
287 procedure Check_Obsolescent_2005_Entity
(E
: Entity_Id
; N
: Node_Id
) is
288 function Chars_Is
(E
: Entity_Id
; S
: String) return Boolean;
289 -- Return True iff Chars (E) matches S (given in lower case)
295 function Chars_Is
(E
: Entity_Id
; S
: String) return Boolean is
296 Nam
: constant Name_Id
:= Chars
(E
);
298 if Length_Of_Name
(Nam
) /= S
'Length then
301 return Get_Name_String
(Nam
) = S
;
305 -- Start of processing for Check_Obsolescent_2005_Entity
308 if Restriction_Check_Required
(No_Obsolescent_Features
)
309 and then Ada_Version
>= Ada_2005
310 and then Chars_Is
(Scope
(E
), "handling")
311 and then Chars_Is
(Scope
(Scope
(E
)), "characters")
312 and then Chars_Is
(Scope
(Scope
(Scope
(E
))), "ada")
313 and then Scope
(Scope
(Scope
(Scope
(E
)))) = Standard_Standard
315 if Chars_Is
(E
, "is_character") or else
316 Chars_Is
(E
, "is_string") or else
317 Chars_Is
(E
, "to_character") or else
318 Chars_Is
(E
, "to_string") or else
319 Chars_Is
(E
, "to_wide_character") or else
320 Chars_Is
(E
, "to_wide_string")
322 Check_Restriction
(No_Obsolescent_Features
, N
);
325 end Check_Obsolescent_2005_Entity
;
327 ---------------------------
328 -- Check_Restricted_Unit --
329 ---------------------------
331 procedure Check_Restricted_Unit
(U
: Unit_Name_Type
; N
: Node_Id
) is
333 if Suppress_Restriction_Message
(N
) then
336 elsif Is_Spec_Name
(U
) then
338 Fnam
: constant File_Name_Type
:=
339 Get_File_Name
(U
, Subunit
=> False);
344 Get_Name_String
(Fnam
);
346 -- Nothing to do if name not at least 5 characters long ending
347 -- in .ads or .adb extension, which we strip.
350 or else (Name_Buffer
(Name_Len
- 3 .. Name_Len
) /= ".ads"
352 Name_Buffer
(Name_Len
- 3 .. Name_Len
) /= ".adb")
357 -- Strip extension and pad to eight characters
359 Name_Len
:= Name_Len
- 4;
360 Add_Str_To_Name_Buffer
((Name_Len
+ 1 .. 8 => ' '));
362 -- If predefined unit, check the list of restricted units
364 if Is_Predefined_File_Name
(Fnam
) then
365 for J
in Unit_Array
'Range loop
367 and then Name_Buffer
(1 .. 8) = Unit_Array
(J
).Filenm
369 Check_Restriction
(Unit_Array
(J
).Res_Id
, N
);
373 -- If not predefined unit, then one special check still
374 -- remains. GNAT.Current_Exception is not allowed if we have
375 -- restriction No_Exception_Propagation active.
378 if Name_Buffer
(1 .. 8) = "g-curexc" then
379 Check_Restriction
(No_Exception_Propagation
, N
);
384 end Check_Restricted_Unit
;
386 -----------------------
387 -- Check_Restriction --
388 -----------------------
390 procedure Check_Restriction
393 V
: Uint
:= Uint_Minus_1
)
395 Msg_Issued
: Boolean;
396 pragma Unreferenced
(Msg_Issued
);
398 Check_Restriction
(Msg_Issued
, R
, N
, V
);
399 end Check_Restriction
;
401 procedure Check_Restriction
402 (Msg_Issued
: out Boolean;
405 V
: Uint
:= Uint_Minus_1
)
408 -- V converted to integer form. If V is greater than Integer'Last,
409 -- it is reset to minus 1 (unknown value).
411 procedure Update_Restrictions
(Info
: in out Restrictions_Info
);
412 -- Update violation information in Info.Violated and Info.Count
414 -------------------------
415 -- Update_Restrictions --
416 -------------------------
418 procedure Update_Restrictions
(Info
: in out Restrictions_Info
) is
420 -- If not violated, set as violated now
422 if not Info
.Violated
(R
) then
423 Info
.Violated
(R
) := True;
425 if R
in All_Parameter_Restrictions
then
427 Info
.Unknown
(R
) := True;
431 Info
.Count
(R
) := VV
;
435 -- Otherwise if violated already and a parameter restriction,
436 -- update count by maximizing or summing depending on restriction.
438 elsif R
in All_Parameter_Restrictions
then
440 -- If new value is unknown, result is unknown
443 Info
.Unknown
(R
) := True;
445 -- If checked by maximization, nothing to do because the
446 -- check is per-object.
448 elsif R
in Checked_Max_Parameter_Restrictions
then
451 -- If checked by adding, do add, checking for overflow
453 elsif R
in Checked_Add_Parameter_Restrictions
then
455 pragma Unsuppress
(Overflow_Check
);
457 Info
.Count
(R
) := Info
.Count
(R
) + VV
;
459 when Constraint_Error
=>
460 Info
.Count
(R
) := Integer'Last;
461 Info
.Unknown
(R
) := True;
464 -- Should not be able to come here, known counts should only
465 -- occur for restrictions that are Checked_max or Checked_Sum.
471 end Update_Restrictions
;
473 -- Start of processing for Check_Restriction
478 -- In CodePeer mode, we do not want to check for any restriction, or set
479 -- additional restrictions other than those already set in gnat1drv.adb
480 -- so that we have consistency between each compilation.
482 -- In GNATprove mode restrictions are checked, except for
483 -- No_Initialize_Scalars, which is implicitly set in gnat1drv.adb.
486 or else (GNATprove_Mode
and then R
= No_Initialize_Scalars
)
491 if UI_Is_In_Int_Range
(V
) then
492 VV
:= Integer (UI_To_Int
(V
));
497 -- Count can only be specified in the checked val parameter case
499 pragma Assert
(VV
< 0 or else R
in Checked_Val_Parameter_Restrictions
);
501 -- Nothing to do if value of zero specified for parameter restriction
507 -- Update current restrictions
509 Update_Restrictions
(Restrictions
);
511 -- If in main extended unit, update main restrictions as well. Note
512 -- that as usual we check for Main_Unit explicitly to deal with the
513 -- case of configuration pragma files.
515 if Current_Sem_Unit
= Main_Unit
516 or else In_Extended_Main_Source_Unit
(N
)
518 Update_Restrictions
(Main_Restrictions
);
521 -- Nothing to do if restriction message suppressed
523 if Suppress_Restriction_Message
(N
) then
526 -- If restriction not set, nothing to do
528 elsif not Restrictions
.Set
(R
) then
531 -- Don't complain about No_Obsolescent_Features in an instance, since we
532 -- will complain on the template, which is much better. Are there other
533 -- cases like this ??? Do we need a more general mechanism ???
535 elsif R
= No_Obsolescent_Features
536 and then Instantiation_Location
(Sloc
(N
)) /= No_Location
540 -- Here if restriction set, check for violation (this is a Boolean
541 -- restriction, or a parameter restriction with a value of zero and an
542 -- unknown count, or a parameter restriction with a known value that
543 -- exceeds the restriction count).
545 elsif R
in All_Boolean_Restrictions
546 or else (Restrictions
.Unknown
(R
)
547 and then Restrictions
.Value
(R
) = 0)
548 or else Restrictions
.Count
(R
) > Restrictions
.Value
(R
)
551 Restriction_Msg
(R
, N
);
554 -- For Max_Entries and the like, do not carry forward the violation
555 -- count because it does not affect later declarations.
557 if R
in Checked_Max_Parameter_Restrictions
then
558 Restrictions
.Count
(R
) := 0;
559 Restrictions
.Violated
(R
) := False;
561 end Check_Restriction
;
563 -------------------------------------
564 -- Check_Restriction_No_Dependence --
565 -------------------------------------
567 procedure Check_Restriction_No_Dependence
(U
: Node_Id
; Err
: Node_Id
) is
571 -- Ignore call if node U is not in the main source unit. This avoids
572 -- cascaded errors, e.g. when Ada.Containers units with other units.
573 -- However, allow Standard_Location here, since this catches some cases
574 -- of constructs that get converted to run-time calls.
576 if not In_Extended_Main_Source_Unit
(U
)
577 and then Sloc
(U
) /= Standard_Location
582 -- Loop through entries in No_Dependence table to check each one in turn
584 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
585 DU
:= No_Dependences
.Table
(J
).Unit
;
587 if Same_Unit
(U
, DU
) then
588 Error_Msg_Sloc
:= Sloc
(DU
);
589 Error_Msg_Node_1
:= DU
;
591 if No_Dependences
.Table
(J
).Warn
then
593 ("?*?violation of restriction `No_Dependence '='> &`#",
597 ("|violation of restriction `No_Dependence '='> &`#",
604 end Check_Restriction_No_Dependence
;
606 --------------------------------------------------
607 -- Check_Restriction_No_Specification_Of_Aspect --
608 --------------------------------------------------
610 procedure Check_Restriction_No_Specification_Of_Aspect
(N
: Node_Id
) is
615 -- Ignore call if no instances of this restriction set
617 if not No_Specification_Of_Aspect_Set
then
621 -- Ignore call if node N is not in the main source unit, since we only
622 -- give messages for the main unit. This avoids giving messages for
623 -- aspects that are specified in withed units.
625 if not In_Extended_Main_Source_Unit
(N
) then
629 if Nkind
(N
) = N_Pragma
then
630 Id
:= Pragma_Identifier
(N
);
631 elsif Nkind
(N
) = N_Attribute_Definition_Clause
then
634 Id
:= Identifier
(N
);
637 A_Id
:= Get_Aspect_Id
(Chars
(Id
));
638 pragma Assert
(A_Id
/= No_Aspect
);
640 Error_Msg_Sloc
:= No_Specification_Of_Aspects
(A_Id
);
642 if Error_Msg_Sloc
/= No_Location
then
643 Error_Msg_Node_1
:= Id
;
644 Error_Msg_Warn
:= No_Specification_Of_Aspect_Warning
(A_Id
);
646 ("<*<violation of restriction `No_Specification_Of_Aspect '='> &`#",
649 end Check_Restriction_No_Specification_Of_Aspect
;
651 -------------------------------------------
652 -- Check_Restriction_No_Use_Of_Attribute --
653 --------------------------------------------
655 procedure Check_Restriction_No_Use_Of_Attribute
(N
: Node_Id
) is
656 Attr_Id
: Attribute_Id
;
660 -- Nothing to do if the attribute is not in the main source unit, since
661 -- we only give messages for the main unit. This avoids giving messages
662 -- for attributes that are specified in withed units.
664 if not In_Extended_Main_Source_Unit
(N
) then
667 -- Nothing to do if not checking No_Use_Of_Attribute
669 elsif not No_Use_Of_Attribute_Set
then
672 -- Do not consider internally generated attributes because this leads to
675 elsif not Comes_From_Source
(N
) then
679 if Nkind
(N
) = N_Attribute_Definition_Clause
then
680 Attr_Nam
:= Chars
(N
);
682 pragma Assert
(Nkind
(N
) = N_Attribute_Reference
);
683 Attr_Nam
:= Attribute_Name
(N
);
686 Attr_Id
:= Get_Attribute_Id
(Attr_Nam
);
687 Error_Msg_Sloc
:= No_Use_Of_Attribute
(Attr_Id
);
689 if Error_Msg_Sloc
/= No_Location
then
690 Error_Msg_Name_1
:= Attr_Nam
;
691 Error_Msg_Warn
:= No_Use_Of_Attribute_Warning
(Attr_Id
);
693 ("<*<violation of restriction `No_Use_Of_Attribute '='> %` #", N
);
695 end Check_Restriction_No_Use_Of_Attribute
;
697 ----------------------------------------
698 -- Check_Restriction_No_Use_Of_Entity --
699 ----------------------------------------
701 procedure Check_Restriction_No_Use_Of_Entity
(N
: Node_Id
) is
703 -- Error defence (not clearly necessary, but better safe)
705 if No
(Entity
(N
)) then
709 -- If simple name of entity not flagged with Boolean2 flag, then there
710 -- cannot be a matching entry in the table, so skip the search.
712 if Get_Name_Table_Boolean2
(Chars
(Entity
(N
))) = False then
716 -- Restriction is only recognized within a configuration pragma file,
717 -- or within a unit of the main extended program. Note: the test for
718 -- Main_Unit is needed to properly include the case of configuration
721 if Current_Sem_Unit
/= Main_Unit
722 and then not In_Extended_Main_Source_Unit
(N
)
727 -- Here we must search the table
729 for J
in No_Use_Of_Entity
.First
.. No_Use_Of_Entity
.Last
loop
731 NE_Ent
: NE_Entry
renames No_Use_Of_Entity
.Table
(J
);
737 Expr
:= NE_Ent
.Entity
;
739 -- Here if at outer level of entity name in reference (handle
740 -- also the direct use of Text_IO in the pragma). For example:
741 -- pragma Restrictions (No_Use_Of_Entity => Text_IO.Put);
743 if Scope
(Ent
) = Standard_Standard
744 or else (Nkind
(Expr
) = N_Identifier
745 and then Chars
(Ent
) = Name_Text_IO
746 and then Chars
(Scope
(Ent
)) = Name_Ada
747 and then Scope
(Scope
(Ent
)) = Standard_Standard
)
749 if Nkind
(Expr
) in N_Identifier | N_Operator_Symbol
750 and then Chars
(Ent
) = Chars
(Expr
)
752 Error_Msg_Node_1
:= N
;
753 Error_Msg_Warn
:= NE_Ent
.Warn
;
754 Error_Msg_Sloc
:= Sloc
(NE_Ent
.Entity
);
756 ("<*<reference to & violates restriction "
757 & "No_Use_Of_Entity #", N
);
764 -- Here if at outer level of entity name in table
766 elsif Nkind
(Expr
) in N_Identifier | N_Operator_Symbol
then
769 -- Here if neither at the outer level
772 pragma Assert
(Nkind
(Expr
) = N_Selected_Component
);
773 exit when Chars
(Selector_Name
(Expr
)) /= Chars
(Ent
);
780 exit when not Is_Internal_Name
(Chars
(Ent
));
783 Expr
:= Prefix
(Expr
);
787 end Check_Restriction_No_Use_Of_Entity
;
789 ----------------------------------------
790 -- Check_Restriction_No_Use_Of_Pragma --
791 ----------------------------------------
793 procedure Check_Restriction_No_Use_Of_Pragma
(N
: Node_Id
) is
794 Id
: constant Node_Id
:= Pragma_Identifier
(N
);
795 P_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Chars
(Id
));
798 -- Nothing to do if the pragma is not in the main source unit, since we
799 -- only give messages for the main unit. This avoids giving messages for
800 -- pragmas that are specified in withed units.
802 if not In_Extended_Main_Source_Unit
(N
) then
805 -- Nothing to do if not checking No_Use_Of_Pragma
807 elsif not No_Use_Of_Pragma_Set
then
810 -- Do not consider internally generated pragmas because this leads to
813 elsif not Comes_From_Source
(N
) then
817 Error_Msg_Sloc
:= No_Use_Of_Pragma
(P_Id
);
819 if Error_Msg_Sloc
/= No_Location
then
820 Error_Msg_Warn
:= No_Use_Of_Pragma_Warning
(P_Id
);
822 ("<*<violation of restriction `No_Use_Of_Pragma '='> &` #", Id
);
824 end Check_Restriction_No_Use_Of_Pragma
;
826 --------------------------------------
827 -- Check_Wide_Character_Restriction --
828 --------------------------------------
830 procedure Check_Wide_Character_Restriction
(E
: Entity_Id
; N
: Node_Id
) is
832 if Restriction_Check_Required
(No_Wide_Characters
)
833 and then Comes_From_Source
(N
)
836 T
: constant Entity_Id
:= Root_Type
(E
);
838 if T
= Standard_Wide_Character
or else
839 T
= Standard_Wide_String
or else
840 T
= Standard_Wide_Wide_Character
or else
841 T
= Standard_Wide_Wide_String
843 Check_Restriction
(No_Wide_Characters
, N
);
847 end Check_Wide_Character_Restriction
;
849 ----------------------------------------
850 -- Cunit_Boolean_Restrictions_Restore --
851 ----------------------------------------
853 procedure Cunit_Boolean_Restrictions_Restore
854 (R
: Save_Cunit_Boolean_Restrictions
)
857 for J
in Cunit_Boolean_Restrictions
loop
858 Restrictions
.Set
(J
) := R
(J
);
861 -- If No_Elaboration_Code set in configuration restrictions, and we
862 -- in the main extended source, then set it here now. This is part of
863 -- the special processing for No_Elaboration_Code.
865 if In_Extended_Main_Source_Unit
(Cunit_Entity
(Current_Sem_Unit
))
866 and then Config_Cunit_Boolean_Restrictions
(No_Elaboration_Code
)
868 Restrictions
.Set
(No_Elaboration_Code
) := True;
870 end Cunit_Boolean_Restrictions_Restore
;
872 -------------------------------------
873 -- Cunit_Boolean_Restrictions_Save --
874 -------------------------------------
876 function Cunit_Boolean_Restrictions_Save
877 return Save_Cunit_Boolean_Restrictions
879 R
: Save_Cunit_Boolean_Restrictions
;
882 for J
in Cunit_Boolean_Restrictions
loop
883 R
(J
) := Restrictions
.Set
(J
);
887 end Cunit_Boolean_Restrictions_Save
;
889 ------------------------
890 -- Get_Restriction_Id --
891 ------------------------
893 function Get_Restriction_Id
894 (N
: Name_Id
) return Restriction_Id
898 Set_Casing
(All_Upper_Case
);
900 for J
in All_Restrictions
loop
902 S
: constant String := Restriction_Id
'Image (J
);
904 if S
= Name_Buffer
(1 .. Name_Len
) then
910 return Not_A_Restriction_Id
;
911 end Get_Restriction_Id
;
913 -----------------------
914 -- Global_No_Tasking --
915 -----------------------
917 function Global_No_Tasking
return Boolean is
919 return Global_Restriction_No_Tasking
920 or else Targparm
.Restrictions_On_Target
.Set
(No_Tasking
);
921 end Global_No_Tasking
;
923 -------------------------------
924 -- No_Exception_Handlers_Set --
925 -------------------------------
927 function No_Exception_Handlers_Set
return Boolean is
929 return (No_Run_Time_Mode
or else Configurable_Run_Time_Mode
)
930 and then (Restrictions
.Set
(No_Exception_Handlers
)
932 Restrictions
.Set
(No_Exception_Propagation
));
933 end No_Exception_Handlers_Set
;
935 -------------------------------------
936 -- No_Exception_Propagation_Active --
937 -------------------------------------
939 function No_Exception_Propagation_Active
return Boolean is
941 return (No_Run_Time_Mode
942 or else Configurable_Run_Time_Mode
943 or else Debug_Flag_Dot_G
)
944 and then Restriction_Active
(No_Exception_Propagation
);
945 end No_Exception_Propagation_Active
;
947 --------------------------------
948 -- OK_No_Dependence_Unit_Name --
949 --------------------------------
951 function OK_No_Dependence_Unit_Name
(N
: Node_Id
) return Boolean is
953 if Nkind
(N
) = N_Selected_Component
then
955 OK_No_Dependence_Unit_Name
(Prefix
(N
))
957 OK_No_Dependence_Unit_Name
(Selector_Name
(N
));
959 elsif Nkind
(N
) = N_Identifier
then
963 Error_Msg_N
("wrong form for unit name for No_Dependence", N
);
966 end OK_No_Dependence_Unit_Name
;
968 ------------------------------
969 -- OK_No_Use_Of_Entity_Name --
970 ------------------------------
972 function OK_No_Use_Of_Entity_Name
(N
: Node_Id
) return Boolean is
974 if Nkind
(N
) = N_Selected_Component
then
976 OK_No_Use_Of_Entity_Name
(Prefix
(N
))
978 OK_No_Use_Of_Entity_Name
(Selector_Name
(N
));
980 elsif Nkind
(N
) in N_Identifier | N_Operator_Symbol
then
984 Error_Msg_N
("wrong form for entity name for No_Use_Of_Entity", N
);
987 end OK_No_Use_Of_Entity_Name
;
989 ----------------------------------
990 -- Process_Restriction_Synonyms --
991 ----------------------------------
993 -- Note: body of this function must be coordinated with list of renaming
994 -- declarations in System.Rident.
996 function Process_Restriction_Synonyms
(N
: Node_Id
) return Name_Id
is
997 Old_Name
: constant Name_Id
:= Chars
(N
);
1002 when Name_Boolean_Entry_Barriers
=>
1003 New_Name
:= Name_Simple_Barriers
;
1005 when Name_Max_Entry_Queue_Depth
=>
1006 New_Name
:= Name_Max_Entry_Queue_Length
;
1008 when Name_No_Dynamic_Interrupts
=>
1009 New_Name
:= Name_No_Dynamic_Attachment
;
1011 when Name_No_Requeue
=>
1012 New_Name
:= Name_No_Requeue_Statements
;
1014 when Name_No_Task_Attributes
=>
1015 New_Name
:= Name_No_Task_Attributes_Package
;
1021 -- Output warning if we are warning on obsolescent features.
1023 if Warn_On_Obsolescent_Feature
then
1024 Error_Msg_Name_1
:= Old_Name
;
1025 Error_Msg_N
("restriction identifier % is obsolescent?j?", N
);
1026 Error_Msg_Name_1
:= New_Name
;
1027 Error_Msg_N
("|use restriction identifier % instead?j?", N
);
1031 end Process_Restriction_Synonyms
;
1033 --------------------------------------
1034 -- Reset_Cunit_Boolean_Restrictions --
1035 --------------------------------------
1037 procedure Reset_Cunit_Boolean_Restrictions
is
1039 for J
in Cunit_Boolean_Restrictions
loop
1040 Restrictions
.Set
(J
) := False;
1042 end Reset_Cunit_Boolean_Restrictions
;
1044 -----------------------------------------------
1045 -- Restore_Config_Cunit_Boolean_Restrictions --
1046 -----------------------------------------------
1048 procedure Restore_Config_Cunit_Boolean_Restrictions
is
1050 Cunit_Boolean_Restrictions_Restore
(Config_Cunit_Boolean_Restrictions
);
1051 end Restore_Config_Cunit_Boolean_Restrictions
;
1053 ------------------------
1054 -- Restricted_Profile --
1055 ------------------------
1057 function Restricted_Profile
return Boolean is
1059 if Restricted_Profile_Cached
then
1060 return Restricted_Profile_Result
;
1063 Restricted_Profile_Result
:= True;
1064 Restricted_Profile_Cached
:= True;
1067 R
: Restriction_Flags
renames
1068 Profile_Info
(Restricted_Tasking
).Set
;
1069 V
: Restriction_Values
renames
1070 Profile_Info
(Restricted_Tasking
).Value
;
1072 for J
in R
'Range loop
1074 and then (Restrictions
.Set
(J
) = False
1075 or else Restriction_Warnings
(J
)
1077 (J
in All_Parameter_Restrictions
1078 and then Restrictions
.Value
(J
) > V
(J
)))
1080 Restricted_Profile_Result
:= False;
1085 return Restricted_Profile_Result
;
1088 end Restricted_Profile
;
1090 ------------------------
1091 -- Restriction_Active --
1092 ------------------------
1094 function Restriction_Active
(R
: All_Restrictions
) return Boolean is
1096 return Restrictions
.Set
(R
) and then not Restriction_Warnings
(R
);
1097 end Restriction_Active
;
1099 --------------------------------
1100 -- Restriction_Check_Required --
1101 --------------------------------
1103 function Restriction_Check_Required
(R
: All_Restrictions
) return Boolean is
1105 return Restrictions
.Set
(R
);
1106 end Restriction_Check_Required
;
1108 ---------------------
1109 -- Restriction_Msg --
1110 ---------------------
1112 procedure Restriction_Msg
(R
: Restriction_Id
; N
: Node_Id
) is
1113 Msg
: String (1 .. 100);
1116 procedure Add_Char
(C
: Character);
1117 -- Append given character to Msg, bumping Len
1119 procedure Add_Str
(S
: String);
1120 -- Append given string to Msg, bumping Len appropriately
1122 procedure Id_Case
(S
: String; Quotes
: Boolean := True);
1123 -- Given a string S, case it according to current identifier casing, and
1124 -- store in Error_Msg_String. Then append `~` to the message buffer
1125 -- to output the string unchanged surrounded in quotes. The quotes
1126 -- are suppressed if Quotes = False.
1132 procedure Add_Char
(C
: Character) is
1142 procedure Add_Str
(S
: String) is
1144 Msg
(Len
+ 1 .. Len
+ S
'Length) := S
;
1145 Len
:= Len
+ S
'Length;
1152 procedure Id_Case
(S
: String; Quotes
: Boolean := True) is
1154 Name_Buffer
(1 .. S
'Last) := S
;
1155 Name_Len
:= S
'Length;
1156 Set_Casing
(Identifier_Casing
(Get_Source_File_Index
(Sloc
(N
))));
1157 Error_Msg_Strlen
:= Name_Len
;
1158 Error_Msg_String
(1 .. Name_Len
) := Name_Buffer
(1 .. Name_Len
);
1167 -- Start of processing for Restriction_Msg
1170 -- Set warning message if warning
1172 if Restriction_Warnings
(R
) then
1175 -- If real violation (not warning), then mark it as non-serious unless
1176 -- it is a violation of No_Finalization in which case we leave it as a
1177 -- serious message, since otherwise we get crashes during attempts to
1178 -- expand stuff that is not properly formed due to assumptions made
1179 -- about no finalization being present.
1181 elsif R
/= No_Finalization
then
1185 Error_Msg_Sloc
:= Restrictions_Loc
(R
);
1187 -- Set main message, adding implicit if no source location
1189 if Error_Msg_Sloc
> No_Location
1190 or else Error_Msg_Sloc
= System_Location
1192 Add_Str
("violation of restriction ");
1194 Add_Str
("violation of implicit restriction ");
1195 Error_Msg_Sloc
:= No_Location
;
1198 -- Case of parameterized restriction
1200 if R
in All_Parameter_Restrictions
then
1202 Id_Case
(Restriction_Id
'Image (R
), Quotes
=> False);
1204 Error_Msg_Uint_1
:= UI_From_Int
(Int
(Restrictions
.Value
(R
)));
1206 -- Case of boolean restriction
1209 Id_Case
(Restriction_Id
'Image (R
));
1212 -- Case of no secondary profile continuation message
1214 if Restriction_Profile_Name
(R
) = No_Profile
then
1215 if Error_Msg_Sloc
/= No_Location
then
1220 Error_Msg_N
(Msg
(1 .. Len
), N
);
1222 -- Case of secondary profile continuation message present
1226 Error_Msg_N
(Msg
(1 .. Len
), N
);
1231 -- Set as warning if warning case
1233 if Restriction_Warnings
(R
) then
1239 Add_Str
("from profile ");
1240 Id_Case
(Profile_Name
'Image (Restriction_Profile_Name
(R
)));
1242 -- Add location if we have one
1244 if Error_Msg_Sloc
/= No_Location
then
1248 -- Output unconditional message and we are done
1251 Error_Msg_N
(Msg
(1 .. Len
), N
);
1253 end Restriction_Msg
;
1259 function Same_Entity
(E1
, E2
: Node_Id
) return Boolean is
1261 if Nkind
(E1
) in N_Identifier | N_Operator_Symbol
1263 Nkind
(E2
) in N_Identifier | N_Operator_Symbol
1265 return Chars
(E1
) = Chars
(E2
);
1267 elsif Nkind
(E1
) in N_Selected_Component | N_Expanded_Name
1269 Nkind
(E2
) in N_Selected_Component | N_Expanded_Name
1271 return Same_Unit
(Prefix
(E1
), Prefix
(E2
))
1273 Same_Unit
(Selector_Name
(E1
), Selector_Name
(E2
));
1283 function Same_Unit
(U1
, U2
: Node_Id
) return Boolean is
1285 if Nkind
(U1
) = N_Identifier
and then Nkind
(U2
) = N_Identifier
then
1286 return Chars
(U1
) = Chars
(U2
);
1288 elsif Nkind
(U1
) in N_Selected_Component | N_Expanded_Name
1290 Nkind
(U2
) in N_Selected_Component | N_Expanded_Name
1292 return Same_Unit
(Prefix
(U1
), Prefix
(U2
))
1294 Same_Unit
(Selector_Name
(U1
), Selector_Name
(U2
));
1300 --------------------------------------------
1301 -- Save_Config_Cunit_Boolean_Restrictions --
1302 --------------------------------------------
1304 procedure Save_Config_Cunit_Boolean_Restrictions
is
1306 Config_Cunit_Boolean_Restrictions
:= Cunit_Boolean_Restrictions_Save
;
1307 end Save_Config_Cunit_Boolean_Restrictions
;
1309 ------------------------------
1310 -- Set_Profile_Restrictions --
1311 ------------------------------
1313 procedure Set_Profile_Restrictions
1318 R
: Restriction_Flags
renames Profile_Info
(P
).Set
;
1319 V
: Restriction_Values
renames Profile_Info
(P
).Value
;
1322 for J
in R
'Range loop
1325 Already_Restricted
: constant Boolean := Restriction_Active
(J
);
1328 -- Set the restriction
1330 if J
in All_Boolean_Restrictions
then
1331 Set_Restriction
(J
, N
);
1333 Set_Restriction
(J
, N
, V
(J
));
1336 -- Record that this came from a Profile[_Warnings] restriction
1338 Restriction_Profile_Name
(J
) := P
;
1340 -- Set warning flag, except that we do not set the warning
1341 -- flag if the restriction was already active and this is
1342 -- the warning case. That avoids a warning overriding a real
1343 -- restriction, which should never happen.
1345 if not (Warn
and Already_Restricted
) then
1346 Restriction_Warnings
(J
) := Warn
;
1351 end Set_Profile_Restrictions
;
1353 ---------------------
1354 -- Set_Restriction --
1355 ---------------------
1357 procedure Set_Restriction
1358 (R
: All_Boolean_Restrictions
;
1362 Restrictions
.Set
(R
) := True;
1364 if Restricted_Profile_Cached
and Restricted_Profile_Result
then
1367 Restricted_Profile_Cached
:= False;
1370 -- Set location, but preserve location of system restriction for nice
1371 -- error msg with run time name.
1373 if Restrictions_Loc
(R
) /= System_Location
then
1374 Restrictions_Loc
(R
) := Sloc
(N
);
1377 -- Note restriction came from restriction pragma, not profile
1379 Restriction_Profile_Name
(R
) := No_Profile
;
1381 -- Record the restriction if we are in the main unit, or in the extended
1382 -- main unit. The reason that we test separately for Main_Unit is that
1383 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1384 -- gnat.adc do not appear to be in the extended main source unit (they
1385 -- probably should do ???)
1387 if Current_Sem_Unit
= Main_Unit
1388 or else In_Extended_Main_Source_Unit
(N
)
1390 if not Restriction_Warnings
(R
) then
1391 Main_Restrictions
.Set
(R
) := True;
1394 end Set_Restriction
;
1396 procedure Set_Restriction
1397 (R
: All_Parameter_Restrictions
;
1402 if Restricted_Profile_Cached
and Restricted_Profile_Result
then
1405 Restricted_Profile_Cached
:= False;
1408 if Restrictions
.Set
(R
) then
1409 if V
< Restrictions
.Value
(R
) then
1410 Restrictions
.Value
(R
) := V
;
1411 Restrictions_Loc
(R
) := Sloc
(N
);
1415 Restrictions
.Set
(R
) := True;
1416 Restrictions
.Value
(R
) := V
;
1417 Restrictions_Loc
(R
) := Sloc
(N
);
1420 -- Record the restriction if we are in the main unit, or in the extended
1421 -- main unit. The reason that we test separately for Main_Unit is that
1422 -- gnat.adc is processed with Current_Sem_Unit = Main_Unit, but nodes in
1423 -- gnat.adc do not appear to be the extended main source unit (they
1424 -- probably should do ???)
1426 if Current_Sem_Unit
= Main_Unit
1427 or else In_Extended_Main_Source_Unit
(N
)
1429 if Main_Restrictions
.Set
(R
) then
1430 if V
< Main_Restrictions
.Value
(R
) then
1431 Main_Restrictions
.Value
(R
) := V
;
1434 elsif not Restriction_Warnings
(R
) then
1435 Main_Restrictions
.Set
(R
) := True;
1436 Main_Restrictions
.Value
(R
) := V
;
1440 -- Note restriction came from restriction pragma, not profile
1442 Restriction_Profile_Name
(R
) := No_Profile
;
1443 end Set_Restriction
;
1445 procedure Set_Restriction
1446 (R
: All_Restrictions
;
1449 V
: Integer := Integer'First)
1451 Set
: Boolean := True;
1453 if Warn
and then Restriction_Active
(R
) then
1458 if R
in All_Boolean_Restrictions
then
1459 Set_Restriction
(R
, N
);
1461 Set_Restriction
(R
, N
, V
);
1464 Restriction_Warnings
(R
) := Warn
;
1466 end Set_Restriction
;
1468 -----------------------------------
1469 -- Set_Restriction_No_Dependence --
1470 -----------------------------------
1472 procedure Set_Restriction_No_Dependence
1475 Profile
: Profile_Name
:= No_Profile
)
1478 -- Loop to check for duplicate entry
1480 for J
in No_Dependences
.First
.. No_Dependences
.Last
loop
1482 -- Case of entry already in table
1484 if Same_Unit
(Unit
, No_Dependences
.Table
(J
).Unit
) then
1486 -- Error has precedence over warning
1489 No_Dependences
.Table
(J
).Warn
:= False;
1496 -- Entry is not currently in table
1498 No_Dependences
.Append
((Unit
, Warn
, Profile
));
1499 end Set_Restriction_No_Dependence
;
1501 --------------------------------------
1502 -- Set_Restriction_No_Use_Of_Entity --
1503 --------------------------------------
1505 procedure Set_Restriction_No_Use_Of_Entity
1508 Profile
: Profile_Name
:= No_Profile
)
1513 -- Loop to check for duplicate entry
1515 for J
in No_Use_Of_Entity
.First
.. No_Use_Of_Entity
.Last
loop
1517 -- Case of entry already in table
1519 if Same_Entity
(Entity
, No_Use_Of_Entity
.Table
(J
).Entity
) then
1521 -- Error has precedence over warning
1524 No_Use_Of_Entity
.Table
(J
).Warn
:= False;
1531 -- Entry is not currently in table
1533 No_Use_Of_Entity
.Append
((Entity
, Warn
, Profile
));
1535 -- Now we need to find the direct name and set Boolean2 flag
1537 if Nkind
(Entity
) in N_Identifier | N_Operator_Symbol
then
1541 pragma Assert
(Nkind
(Entity
) = N_Selected_Component
);
1542 Nam
:= Selector_Name
(Entity
);
1543 pragma Assert
(Nkind
(Nam
) in N_Identifier | N_Operator_Symbol
);
1546 Set_Name_Table_Boolean2
(Chars
(Nam
), True);
1547 end Set_Restriction_No_Use_Of_Entity
;
1549 ------------------------------------------------
1550 -- Set_Restriction_No_Specification_Of_Aspect --
1551 ------------------------------------------------
1553 procedure Set_Restriction_No_Specification_Of_Aspect
1557 A_Id
: constant Aspect_Id_Exclude_No_Aspect
:= Get_Aspect_Id
(Chars
(N
));
1560 No_Specification_Of_Aspect_Set
:= True;
1561 No_Specification_Of_Aspects
(A_Id
) := Sloc
(N
);
1562 No_Specification_Of_Aspect_Warning
(A_Id
) := Warn
;
1563 end Set_Restriction_No_Specification_Of_Aspect
;
1565 procedure Set_Restriction_No_Specification_Of_Aspect
(A_Id
: Aspect_Id
) is
1567 No_Specification_Of_Aspect_Set
:= True;
1568 No_Specification_Of_Aspects
(A_Id
) := System_Location
;
1569 No_Specification_Of_Aspect_Warning
(A_Id
) := False;
1570 end Set_Restriction_No_Specification_Of_Aspect
;
1572 -----------------------------------------
1573 -- Set_Restriction_No_Use_Of_Attribute --
1574 -----------------------------------------
1576 procedure Set_Restriction_No_Use_Of_Attribute
1580 A_Id
: constant Attribute_Id
:= Get_Attribute_Id
(Chars
(N
));
1583 No_Use_Of_Attribute_Set
:= True;
1584 No_Use_Of_Attribute
(A_Id
) := Sloc
(N
);
1585 No_Use_Of_Attribute_Warning
(A_Id
) := Warn
;
1586 end Set_Restriction_No_Use_Of_Attribute
;
1588 procedure Set_Restriction_No_Use_Of_Attribute
(A_Id
: Attribute_Id
) is
1590 No_Use_Of_Attribute_Set
:= True;
1591 No_Use_Of_Attribute
(A_Id
) := System_Location
;
1592 No_Use_Of_Attribute_Warning
(A_Id
) := False;
1593 end Set_Restriction_No_Use_Of_Attribute
;
1595 --------------------------------------
1596 -- Set_Restriction_No_Use_Of_Pragma --
1597 --------------------------------------
1599 procedure Set_Restriction_No_Use_Of_Pragma
1603 A_Id
: constant Pragma_Id
:= Get_Pragma_Id
(Chars
(N
));
1606 No_Use_Of_Pragma_Set
:= True;
1607 No_Use_Of_Pragma
(A_Id
) := Sloc
(N
);
1608 No_Use_Of_Pragma_Warning
(A_Id
) := Warn
;
1609 end Set_Restriction_No_Use_Of_Pragma
;
1611 procedure Set_Restriction_No_Use_Of_Pragma
(A_Id
: Pragma_Id
) is
1613 No_Use_Of_Pragma_Set
:= True;
1614 No_Use_Of_Pragma
(A_Id
) := System_Location
;
1615 No_Use_Of_Pragma_Warning
(A_Id
) := False;
1616 end Set_Restriction_No_Use_Of_Pragma
;
1618 ---------------------------
1619 -- Set_Global_No_Tasking --
1620 ---------------------------
1622 procedure Set_Global_No_Tasking
is
1624 Global_Restriction_No_Tasking
:= True;
1625 end Set_Global_No_Tasking
;
1627 ----------------------------------
1628 -- Suppress_Restriction_Message --
1629 ----------------------------------
1631 function Suppress_Restriction_Message
(N
: Node_Id
) return Boolean is
1633 -- We only output messages for the extended main source unit
1635 if In_Extended_Main_Source_Unit
(N
) then
1638 -- If loaded by rtsfind, then suppress message
1640 elsif Sloc
(N
) <= No_Location
then
1643 -- Otherwise suppress message if internal file
1646 return In_Internal_Unit
(N
);
1648 end Suppress_Restriction_Message
;
1650 ---------------------
1651 -- Tasking_Allowed --
1652 ---------------------
1654 function Tasking_Allowed
return Boolean is
1656 return not Restrictions
.Set
(No_Tasking
)
1657 and then (not Restrictions
.Set
(Max_Tasks
)
1658 or else Restrictions
.Value
(Max_Tasks
) > 0)
1659 and then not No_Run_Time_Mode
;
1660 end Tasking_Allowed
;