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