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. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 pragma Style_Checks (All_Checks);
33 -- Subprogram ordering not enforced in this unit
34 -- (because of some logical groupings).
36 with Atree; use Atree;
37 with Csets; use Csets;
38 with Einfo; use Einfo;
39 with Nlists; use Nlists;
41 with Output; use Output;
42 with Sinfo; use Sinfo;
43 with Sinput; use Sinput;
44 with Stand; use Stand;
45 with Stringt; use Stringt;
46 with Tree_IO; use Tree_IO;
47 with Uname; use Uname;
48 with Widechar; use Widechar;
52 Switch_Storing_Enabled : Boolean := True;
53 -- Controlled by Enable_Switch_Storing/Disable_Switch_Storing
55 -----------------------
56 -- Local Subprograms --
57 -----------------------
60 Yes_Before, -- S1 is in same extended unit as S2 and appears before it
61 Yes_Same, -- S1 is in same extended unit as S2, Slocs are the same
62 Yes_After, -- S1 is in same extended unit as S2, and appears after it
63 No); -- S2 is not in same extended unit as S2
65 function Check_Same_Extended_Unit
67 S2 : Source_Ptr) return SEU_Result;
68 -- Used by In_Same_Extended_Unit and Earlier_In_Extended_Unit. Returns
69 -- value as described above.
71 function Get_Code_Or_Source_Unit
73 Unwind_Instances : Boolean;
74 Unwind_Subunits : Boolean) return Unit_Number_Type;
75 -- Common processing for routines Get_Code_Unit, Get_Source_Unit, and
76 -- Get_Top_Level_Code_Unit. Unwind_Instances is True when the unit for the
77 -- top-level instantiation should be returned instead of the unit for the
78 -- template, in the case of an instantiation. Unwind_Subunits is True when
79 -- the corresponding top-level unit should be returned instead of a
80 -- subunit, in the case of a subunit.
82 --------------------------------------------
83 -- Access Functions for Unit Table Fields --
84 --------------------------------------------
86 function Cunit (U : Unit_Number_Type) return Node_Id is
88 return Units.Table (U).Cunit;
91 function Cunit_Entity (U : Unit_Number_Type) return Entity_Id is
93 return Units.Table (U).Cunit_Entity;
96 function Dependency_Num (U : Unit_Number_Type) return Nat is
98 return Units.Table (U).Dependency_Num;
101 function Dynamic_Elab (U : Unit_Number_Type) return Boolean is
103 return Units.Table (U).Dynamic_Elab;
106 function Error_Location (U : Unit_Number_Type) return Source_Ptr is
108 return Units.Table (U).Error_Location;
111 function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type is
113 return Units.Table (U).Expected_Unit;
116 function Fatal_Error (U : Unit_Number_Type) return Fatal_Type is
118 return Units.Table (U).Fatal_Error;
121 function Generate_Code (U : Unit_Number_Type) return Boolean is
123 return Units.Table (U).Generate_Code;
126 function Has_RACW (U : Unit_Number_Type) return Boolean is
128 return Units.Table (U).Has_RACW;
131 function Is_Predefined_Renaming (U : Unit_Number_Type) return Boolean is
133 return Units.Table (U).Is_Predefined_Renaming;
134 end Is_Predefined_Renaming;
136 function Is_Internal_Unit (U : Unit_Number_Type) return Boolean is
138 return Units.Table (U).Is_Internal_Unit;
139 end Is_Internal_Unit;
141 function Is_Predefined_Unit (U : Unit_Number_Type) return Boolean is
143 return Units.Table (U).Is_Predefined_Unit;
144 end Is_Predefined_Unit;
146 function Ident_String (U : Unit_Number_Type) return Node_Id is
148 return Units.Table (U).Ident_String;
151 function Loading (U : Unit_Number_Type) return Boolean is
153 return Units.Table (U).Loading;
156 function Main_CPU (U : Unit_Number_Type) return Int is
158 return Units.Table (U).Main_CPU;
161 function Main_Priority (U : Unit_Number_Type) return Int is
163 return Units.Table (U).Main_Priority;
166 function Munit_Index (U : Unit_Number_Type) return Nat is
168 return Units.Table (U).Munit_Index;
171 function No_Elab_Code_All (U : Unit_Number_Type) return Boolean is
173 return Units.Table (U).No_Elab_Code_All;
174 end No_Elab_Code_All;
176 function OA_Setting (U : Unit_Number_Type) return Character is
178 return Units.Table (U).OA_Setting;
181 function Primary_Stack_Count (U : Unit_Number_Type) return Int is
183 return Units.Table (U).Primary_Stack_Count;
184 end Primary_Stack_Count;
186 function Sec_Stack_Count (U : Unit_Number_Type) return Int is
188 return Units.Table (U).Sec_Stack_Count;
191 function Source_Index (U : Unit_Number_Type) return Source_File_Index is
193 return Units.Table (U).Source_Index;
196 function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type is
198 return Units.Table (U).Unit_File_Name;
201 function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type is
203 return Units.Table (U).Unit_Name;
206 ------------------------------------------
207 -- Subprograms to Set Unit Table Fields --
208 ------------------------------------------
210 procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id) is
212 Units.Table (U).Cunit := N;
215 procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id) is
217 Units.Table (U).Cunit_Entity := E;
218 Set_Is_Compilation_Unit (E);
219 end Set_Cunit_Entity;
221 procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True) is
223 Units.Table (U).Dynamic_Elab := B;
224 end Set_Dynamic_Elab;
226 procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr) is
228 Units.Table (U).Error_Location := W;
229 end Set_Error_Location;
231 procedure Set_Fatal_Error (U : Unit_Number_Type; V : Fatal_Type) is
233 Units.Table (U).Fatal_Error := V;
236 procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True) is
238 Units.Table (U).Generate_Code := B;
239 end Set_Generate_Code;
241 procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True) is
243 Units.Table (U).Has_RACW := B;
246 procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id) is
248 Units.Table (U).Ident_String := N;
249 end Set_Ident_String;
251 procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True) is
253 Units.Table (U).Loading := B;
256 procedure Set_Main_CPU (U : Unit_Number_Type; P : Int) is
258 Units.Table (U).Main_CPU := P;
261 procedure Set_Main_Priority (U : Unit_Number_Type; P : Int) is
263 Units.Table (U).Main_Priority := P;
264 end Set_Main_Priority;
266 procedure Set_No_Elab_Code_All
267 (U : Unit_Number_Type;
271 Units.Table (U).No_Elab_Code_All := B;
272 end Set_No_Elab_Code_All;
274 procedure Set_OA_Setting (U : Unit_Number_Type; C : Character) is
276 Units.Table (U).OA_Setting := C;
279 procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
280 Old_N : constant Unit_Name_Type := Units.Table (U).Unit_Name;
283 -- First unregister the old name, if any
285 if Old_N /= No_Unit_Name and then Unit_Names.Get (Old_N) = U then
286 Unit_Names.Set (Old_N, No_Unit);
289 -- Then set the new name
291 Units.Table (U).Unit_Name := N;
293 -- Finally register the new name
295 if Unit_Names.Get (N) = No_Unit then
296 Unit_Names.Set (N, U);
300 ------------------------------
301 -- Check_Same_Extended_Unit --
302 ------------------------------
304 function Check_Same_Extended_Unit
306 S2 : Source_Ptr) return SEU_Result
308 Max_Iterations : constant Nat := Maximum_Instantiations * 2;
309 -- Limit to prevent a potential infinite loop
316 Sind1 : Source_File_Index;
317 Sind2 : Source_File_Index;
322 Unum1 : Unit_Number_Type;
323 Unum2 : Unit_Number_Type;
326 if S1 = No_Location or else S2 = No_Location then
329 elsif S1 = Standard_Location then
330 if S2 = Standard_Location then
336 elsif S2 = Standard_Location then
343 Unum1 := Get_Source_Unit (Sloc1);
344 Unum2 := Get_Source_Unit (Sloc2);
347 -- Step 1: Check whether the two locations are in the same source
350 Sind1 := Get_Source_File_Index (Sloc1);
351 Sind2 := Get_Source_File_Index (Sloc2);
353 if Sind1 = Sind2 then
354 if Sloc1 < Sloc2 then
356 elsif Sloc1 > Sloc2 then
363 -- Step 2: Check subunits. If a subunit is instantiated, follow the
364 -- instantiation chain rather than the stub chain.
366 Unit1 := Unit (Cunit (Unum1));
367 Unit2 := Unit (Cunit (Unum2));
368 Inst1 := Instantiation (Sind1);
369 Inst2 := Instantiation (Sind2);
371 if Nkind (Unit1) = N_Subunit
372 and then Present (Corresponding_Stub (Unit1))
373 and then Inst1 = No_Location
375 if Nkind (Unit2) = N_Subunit
376 and then Present (Corresponding_Stub (Unit2))
377 and then Inst2 = No_Location
379 -- Both locations refer to subunits which may have a common
380 -- ancestor. If they do, the deeper subunit must have a longer
381 -- unit name. Replace the deeper one with its corresponding
382 -- stub in order to find the nearest ancestor.
384 if Length_Of_Name (Unit_Name (Unum1)) <
385 Length_Of_Name (Unit_Name (Unum2))
387 Sloc2 := Sloc (Corresponding_Stub (Unit2));
388 Unum2 := Get_Source_Unit (Sloc2);
392 Sloc1 := Sloc (Corresponding_Stub (Unit1));
393 Unum1 := Get_Source_Unit (Sloc1);
397 -- Sloc1 in subunit, Sloc2 not
400 Sloc1 := Sloc (Corresponding_Stub (Unit1));
401 Unum1 := Get_Source_Unit (Sloc1);
405 -- Sloc2 in subunit, Sloc1 not
407 elsif Nkind (Unit2) = N_Subunit
408 and then Present (Corresponding_Stub (Unit2))
409 and then Inst2 = No_Location
411 Sloc2 := Sloc (Corresponding_Stub (Unit2));
412 Unum2 := Get_Source_Unit (Sloc2);
416 -- Step 3: Check instances. The two locations may yield a common
419 if Inst1 /= No_Location then
420 if Inst2 /= No_Location then
422 -- Both locations denote instantiations
424 Depth1 := Instantiation_Depth (Sloc1);
425 Depth2 := Instantiation_Depth (Sloc2);
427 if Depth1 < Depth2 then
429 Unum2 := Get_Source_Unit (Sloc2);
432 elsif Depth1 > Depth2 then
434 Unum1 := Get_Source_Unit (Sloc1);
440 Unum1 := Get_Source_Unit (Sloc1);
441 Unum2 := Get_Source_Unit (Sloc2);
445 -- Sloc1 is an instantiation
449 Unum1 := Get_Source_Unit (Sloc1);
453 -- Sloc2 is an instantiation
455 elsif Inst2 /= No_Location then
457 Unum2 := Get_Source_Unit (Sloc2);
461 -- Step 4: One location in the spec, the other in the corresponding
462 -- body of the same unit. The location in the spec is considered
465 if Nkind (Unit1) = N_Subprogram_Body
467 Nkind (Unit1) = N_Package_Body
469 if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
473 elsif Nkind (Unit2) = N_Subprogram_Body
475 Nkind (Unit2) = N_Package_Body
477 if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
482 -- At this point it is certain that the two locations denote two
483 -- entirely separate units.
488 Counter := Counter + 1;
490 -- Prevent looping forever
492 if Counter > Max_Iterations then
494 -- ??? Not quite right, but return a value to be able to generate
495 -- SCIL files and hope for the best.
497 if CodePeer_Mode then
504 end Check_Same_Extended_Unit;
506 -------------------------------
507 -- Compilation_Switches_Last --
508 -------------------------------
510 function Compilation_Switches_Last return Nat is
512 return Compilation_Switches.Last;
513 end Compilation_Switches_Last;
515 ---------------------------
516 -- Enable_Switch_Storing --
517 ---------------------------
519 procedure Enable_Switch_Storing is
521 Switch_Storing_Enabled := True;
522 end Enable_Switch_Storing;
524 ----------------------------
525 -- Disable_Switch_Storing --
526 ----------------------------
528 procedure Disable_Switch_Storing is
530 Switch_Storing_Enabled := False;
531 end Disable_Switch_Storing;
533 ------------------------------
534 -- Earlier_In_Extended_Unit --
535 ------------------------------
537 function Earlier_In_Extended_Unit
539 S2 : Source_Ptr) return Boolean
542 return Check_Same_Extended_Unit (S1, S2) = Yes_Before;
543 end Earlier_In_Extended_Unit;
545 function Earlier_In_Extended_Unit
546 (N1 : Node_Or_Entity_Id;
547 N2 : Node_Or_Entity_Id) return Boolean
550 return Earlier_In_Extended_Unit (Sloc (N1), Sloc (N2));
551 end Earlier_In_Extended_Unit;
553 -----------------------
554 -- Exact_Source_Name --
555 -----------------------
557 function Exact_Source_Name (Loc : Source_Ptr) return String is
558 U : constant Unit_Number_Type := Get_Source_Unit (Loc);
559 Buf : constant Source_Buffer_Ptr := Source_Text (Source_Index (U));
560 Orig : constant Source_Ptr := Original_Location (Loc);
565 pragma Warnings (Off, WC);
566 pragma Warnings (Off, Err);
569 -- Entity is character literal
571 if Buf (Orig) = ''' then
572 return String (Buf (Orig .. Orig + 2));
574 -- Entity is operator symbol
576 elsif Buf (Orig) = '"' or else Buf (Orig) = '%' then
581 exit when Buf (P) = Buf (Orig);
584 return String (Buf (Orig .. P));
586 -- Entity is identifier
592 if Is_Start_Of_Wide_Char (Buf, P) then
593 Scan_Wide (Buf, P, WC, Err);
594 elsif not Identifier_Char (Buf (P)) then
601 -- Write out the identifier by copying the exact source characters
602 -- used in its declaration. Note that this means wide characters will
603 -- be in their original encoded form.
605 return String (Buf (Orig .. P - 1));
607 end Exact_Source_Name;
609 ----------------------------
610 -- Entity_Is_In_Main_Unit --
611 ----------------------------
613 function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean is
619 while S /= Standard_Standard loop
620 if S = Main_Unit_Entity then
622 elsif Ekind (S) = E_Package and then Is_Child_Unit (S) then
630 end Entity_Is_In_Main_Unit;
632 --------------------------
633 -- Generic_May_Lack_ALI --
634 --------------------------
636 function Generic_May_Lack_ALI (Unum : Unit_Number_Type) return Boolean is
638 -- We allow internal generic units to be used without having a
639 -- corresponding ALI files to help bootstrapping with older compilers
640 -- that did not support generating ALIs for such generics. It is safe
641 -- to do so because the only thing the generated code would contain
642 -- is the elaboration boolean, and we are careful to elaborate all
643 -- predefined units first anyway.
645 return Is_Internal_Unit (Unum);
646 end Generic_May_Lack_ALI;
648 -----------------------------
649 -- Get_Code_Or_Source_Unit --
650 -----------------------------
652 function Get_Code_Or_Source_Unit
654 Unwind_Instances : Boolean;
655 Unwind_Subunits : Boolean) return Unit_Number_Type
658 -- Search table unless we have No_Location, which can happen if the
659 -- relevant location has not been set yet. Happens for example when
660 -- we obtain Sloc (Cunit (Main_Unit)) before it is set.
662 if S /= No_Location then
664 Source_File : Source_File_Index;
665 Source_Unit : Unit_Number_Type;
669 Source_File := Get_Source_File_Index (S);
671 if Unwind_Instances then
672 while Template (Source_File) > No_Source_File loop
673 Source_File := Template (Source_File);
677 Source_Unit := Unit (Source_File);
679 if Unwind_Subunits then
680 Unit_Node := Unit (Cunit (Source_Unit));
682 while Nkind (Unit_Node) = N_Subunit
683 and then Present (Corresponding_Stub (Unit_Node))
686 Get_Code_Or_Source_Unit
687 (Sloc (Corresponding_Stub (Unit_Node)),
688 Unwind_Instances => Unwind_Instances,
689 Unwind_Subunits => Unwind_Subunits);
690 Unit_Node := Unit (Cunit (Source_Unit));
694 if Source_Unit /= No_Unit then
700 -- If S was No_Location, or was not in the table, we must be in the main
701 -- source unit (and the value has not been placed in the table yet),
702 -- or in one of the configuration pragma files.
705 end Get_Code_Or_Source_Unit;
711 function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
714 Get_Code_Or_Source_Unit
715 (Top_Level_Location (S),
716 Unwind_Instances => False,
717 Unwind_Subunits => False);
720 function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
722 return Get_Code_Unit (Sloc (N));
725 ----------------------------
726 -- Get_Compilation_Switch --
727 ----------------------------
729 function Get_Compilation_Switch (N : Pos) return String_Ptr is
731 if N <= Compilation_Switches.Last then
732 return Compilation_Switches.Table (N);
736 end Get_Compilation_Switch;
738 ----------------------------------
739 -- Get_Cunit_Entity_Unit_Number --
740 ----------------------------------
742 function Get_Cunit_Entity_Unit_Number
743 (E : Entity_Id) return Unit_Number_Type
746 for U in Units.First .. Units.Last loop
747 if Cunit_Entity (U) = E then
752 -- If not in the table, must be the main source unit, and we just
753 -- have not got it put into the table yet.
756 end Get_Cunit_Entity_Unit_Number;
758 ---------------------------
759 -- Get_Cunit_Unit_Number --
760 ---------------------------
762 function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type is
764 for U in Units.First .. Units.Last loop
765 if Cunit (U) = N then
770 -- If not in the table, must be a spec created for a main unit that is a
771 -- child subprogram body which we have not inserted into the table yet.
773 if N = Library_Unit (Cunit (Main_Unit)) then
776 -- If it is anything else, something is seriously wrong, and we really
777 -- don't want to proceed, even if assertions are off, so we explicitly
778 -- raise an exception in this case to terminate compilation.
783 end Get_Cunit_Unit_Number;
785 ---------------------
786 -- Get_Source_Unit --
787 ---------------------
789 function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type is
792 Get_Code_Or_Source_Unit
794 Unwind_Instances => True,
795 Unwind_Subunits => False);
798 function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
800 return Get_Source_Unit (Sloc (N));
803 -----------------------------
804 -- Get_Top_Level_Code_Unit --
805 -----------------------------
807 function Get_Top_Level_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
810 Get_Code_Or_Source_Unit
811 (Top_Level_Location (S),
812 Unwind_Instances => False,
813 Unwind_Subunits => True);
814 end Get_Top_Level_Code_Unit;
816 function Get_Top_Level_Code_Unit
817 (N : Node_Or_Entity_Id) return Unit_Number_Type is
819 return Get_Top_Level_Code_Unit (Sloc (N));
820 end Get_Top_Level_Code_Unit;
822 --------------------------------
823 -- In_Extended_Main_Code_Unit --
824 --------------------------------
826 function In_Extended_Main_Code_Unit
827 (N : Node_Or_Entity_Id) return Boolean
830 if Sloc (N) = Standard_Location then
833 elsif Sloc (N) = No_Location then
836 -- Special case Itypes to test the Sloc of the associated node. The
837 -- reason we do this is for possible calls from gigi after -gnatD
838 -- processing is complete in sprint. This processing updates the
839 -- sloc fields of all nodes in the tree, but itypes are not in the
840 -- tree so their slocs do not get updated.
842 elsif Nkind (N) = N_Defining_Identifier
843 and then Is_Itype (N)
845 return In_Extended_Main_Code_Unit (Associated_Node_For_Itype (N));
847 -- Otherwise see if we are in the main unit
849 elsif Get_Code_Unit (Sloc (N)) = Get_Code_Unit (Cunit (Main_Unit)) then
852 -- Node may be in spec (or subunit etc) of main unit
855 return In_Same_Extended_Unit (N, Cunit (Main_Unit));
857 end In_Extended_Main_Code_Unit;
859 function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean is
861 if Loc = Standard_Location then
864 elsif Loc = No_Location then
867 -- Otherwise see if we are in the main unit
869 elsif Get_Code_Unit (Loc) = Get_Code_Unit (Cunit (Main_Unit)) then
872 -- Location may be in spec (or subunit etc) of main unit
875 return In_Same_Extended_Unit (Loc, Sloc (Cunit (Main_Unit)));
877 end In_Extended_Main_Code_Unit;
879 ----------------------------------
880 -- In_Extended_Main_Source_Unit --
881 ----------------------------------
883 function In_Extended_Main_Source_Unit
884 (N : Node_Or_Entity_Id) return Boolean
886 Nloc : constant Source_Ptr := Sloc (N);
887 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
890 -- If parsing, then use the global flag to indicate result
892 if Compiler_State = Parsing then
893 return Parsing_Main_Extended_Source;
895 -- Special value cases
897 elsif Nloc = Standard_Location then
900 elsif Nloc = No_Location then
903 -- Special case Itypes to test the Sloc of the associated node. The
904 -- reason we do this is for possible calls from gigi after -gnatD
905 -- processing is complete in sprint. This processing updates the
906 -- sloc fields of all nodes in the tree, but itypes are not in the
907 -- tree so their slocs do not get updated.
909 elsif Nkind (N) = N_Defining_Identifier
910 and then Is_Itype (N)
912 return In_Extended_Main_Source_Unit (Associated_Node_For_Itype (N));
914 -- Otherwise compare original locations to see if in same unit
918 In_Same_Extended_Unit
919 (Original_Location (Nloc), Original_Location (Mloc));
921 end In_Extended_Main_Source_Unit;
923 function In_Extended_Main_Source_Unit
924 (Loc : Source_Ptr) return Boolean
926 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
929 -- If parsing, then use the global flag to indicate result
931 if Compiler_State = Parsing then
932 return Parsing_Main_Extended_Source;
934 -- Special value cases
936 elsif Loc = Standard_Location then
939 elsif Loc = No_Location then
942 -- Otherwise compare original locations to see if in same unit
946 In_Same_Extended_Unit
947 (Original_Location (Loc), Original_Location (Mloc));
949 end In_Extended_Main_Source_Unit;
951 ----------------------
952 -- In_Internal_Unit --
953 ----------------------
955 function In_Internal_Unit (N : Node_Or_Entity_Id) return Boolean is
957 return In_Internal_Unit (Sloc (N));
958 end In_Internal_Unit;
960 function In_Internal_Unit (S : Source_Ptr) return Boolean is
961 Unit : constant Unit_Number_Type := Get_Source_Unit (S);
963 return Is_Internal_Unit (Unit);
964 end In_Internal_Unit;
966 ----------------------------
967 -- In_Predefined_Renaming --
968 ----------------------------
970 function In_Predefined_Renaming (N : Node_Or_Entity_Id) return Boolean is
972 return In_Predefined_Renaming (Sloc (N));
973 end In_Predefined_Renaming;
975 function In_Predefined_Renaming (S : Source_Ptr) return Boolean is
976 Unit : constant Unit_Number_Type := Get_Source_Unit (S);
978 return Is_Predefined_Renaming (Unit);
979 end In_Predefined_Renaming;
981 ------------------------
982 -- In_Predefined_Unit --
983 ------------------------
985 function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean is
987 return In_Predefined_Unit (Sloc (N));
988 end In_Predefined_Unit;
990 function In_Predefined_Unit (S : Source_Ptr) return Boolean is
991 Unit : constant Unit_Number_Type := Get_Source_Unit (S);
993 return Is_Predefined_Unit (Unit);
994 end In_Predefined_Unit;
996 -----------------------
997 -- In_Same_Code_Unit --
998 -----------------------
1000 function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
1001 S1 : constant Source_Ptr := Sloc (N1);
1002 S2 : constant Source_Ptr := Sloc (N2);
1005 if S1 = No_Location or else S2 = No_Location then
1008 elsif S1 = Standard_Location then
1009 return S2 = Standard_Location;
1011 elsif S2 = Standard_Location then
1015 return Get_Code_Unit (N1) = Get_Code_Unit (N2);
1016 end In_Same_Code_Unit;
1018 ---------------------------
1019 -- In_Same_Extended_Unit --
1020 ---------------------------
1022 function In_Same_Extended_Unit
1023 (N1, N2 : Node_Or_Entity_Id) return Boolean
1026 return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
1027 end In_Same_Extended_Unit;
1029 function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
1031 return Check_Same_Extended_Unit (S1, S2) /= No;
1032 end In_Same_Extended_Unit;
1034 -------------------------
1035 -- In_Same_Source_Unit --
1036 -------------------------
1038 function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
1039 S1 : constant Source_Ptr := Sloc (N1);
1040 S2 : constant Source_Ptr := Sloc (N2);
1043 if S1 = No_Location or else S2 = No_Location then
1046 elsif S1 = Standard_Location then
1047 return S2 = Standard_Location;
1049 elsif S2 = Standard_Location then
1053 return Get_Source_Unit (N1) = Get_Source_Unit (N2);
1054 end In_Same_Source_Unit;
1056 -----------------------------------
1057 -- Increment_Primary_Stack_Count --
1058 -----------------------------------
1060 procedure Increment_Primary_Stack_Count (Increment : Int) is
1061 PSC : Int renames Units.Table (Current_Sem_Unit).Primary_Stack_Count;
1063 PSC := PSC + Increment;
1064 end Increment_Primary_Stack_Count;
1066 -------------------------------
1067 -- Increment_Sec_Stack_Count --
1068 -------------------------------
1070 procedure Increment_Sec_Stack_Count (Increment : Int) is
1071 SSC : Int renames Units.Table (Current_Sem_Unit).Sec_Stack_Count;
1073 SSC := SSC + Increment;
1074 end Increment_Sec_Stack_Count;
1076 -----------------------------
1077 -- Increment_Serial_Number --
1078 -----------------------------
1080 function Increment_Serial_Number return Nat is
1081 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
1085 end Increment_Serial_Number;
1087 ----------------------
1088 -- Init_Unit_Name --
1089 ----------------------
1091 procedure Init_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
1093 Units.Table (U).Unit_Name := N;
1094 Unit_Names.Set (N, U);
1101 procedure Initialize is
1103 Linker_Option_Lines.Init;
1107 Compilation_Switches.Init;
1114 function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
1116 return Unit_Names.Get (Uname) /= No_Unit;
1123 function Last_Unit return Unit_Number_Type is
1132 procedure List (File_Names_Only : Boolean := False) is separate;
1140 Linker_Option_Lines.Release;
1141 Linker_Option_Lines.Locked := True;
1143 Load_Stack.Locked := True;
1145 Units.Locked := True;
1152 function Num_Units return Nat is
1154 return Int (Units.Last) - Int (Main_Unit) + 1;
1161 procedure Remove_Unit (U : Unit_Number_Type) is
1163 if U = Units.Last then
1164 Unit_Names.Set (Unit_Name (U), No_Unit);
1165 Units.Decrement_Last;
1169 ----------------------------------
1170 -- Replace_Linker_Option_String --
1171 ----------------------------------
1173 procedure Replace_Linker_Option_String
1174 (S : String_Id; Match_String : String)
1177 if Match_String'Length > 0 then
1178 for J in 1 .. Linker_Option_Lines.Last loop
1179 String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
1181 if Match_String = Name_Buffer (1 .. Match_String'Length) then
1182 Linker_Option_Lines.Table (J).Option := S;
1188 Store_Linker_Option_String (S);
1189 end Replace_Linker_Option_String;
1195 procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
1197 ------------------------------
1198 -- Store_Compilation_Switch --
1199 ------------------------------
1201 procedure Store_Compilation_Switch (Switch : String) is
1203 if Switch_Storing_Enabled then
1204 Compilation_Switches.Increment_Last;
1205 Compilation_Switches.Table (Compilation_Switches.Last) :=
1206 new String'(Switch);
1208 -- Fix up --RTS flag which has been transformed by the gcc driver
1211 if Switch'Last >= Switch'First + 4
1212 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
1214 Compilation_Switches.Table
1215 (Compilation_Switches.Last) (Switch'First + 1) := '-';
1218 end Store_Compilation_Switch;
1220 --------------------------------
1221 -- Store_Linker_Option_String --
1222 --------------------------------
1224 procedure Store_Linker_Option_String (S : String_Id) is
1226 Linker_Option_Lines.Append ((Option => S, Unit => Current_Sem_Unit));
1227 end Store_Linker_Option_String;
1233 procedure Store_Note (N : Node_Id) is
1234 Sfile : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1237 -- Notes for a generic are emitted when processing the template, never
1240 if In_Extended_Main_Code_Unit (N)
1241 and then Instance (Sfile) = No_Instance_Id
1247 -------------------------------
1248 -- Synchronize_Serial_Number --
1249 -------------------------------
1251 procedure Synchronize_Serial_Number is
1252 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
1255 end Synchronize_Serial_Number;
1261 procedure Tree_Read is
1268 -- Read Compilation_Switches table. First release the memory occupied
1269 -- by the previously loaded switches.
1271 for J in Compilation_Switches.First .. Compilation_Switches.Last loop
1272 Free (Compilation_Switches.Table (J));
1276 Compilation_Switches.Set_Last (N);
1278 for J in 1 .. N loop
1280 Compilation_Switches.Table (J) := S;
1288 procedure Tree_Write is
1292 -- Write Compilation_Switches table
1294 Tree_Write_Int (Compilation_Switches.Last);
1296 for J in 1 .. Compilation_Switches.Last loop
1297 Tree_Write_Str (Compilation_Switches.Table (J));
1301 --------------------
1302 -- Unit_Name_Hash --
1303 --------------------
1305 function Unit_Name_Hash (Id : Unit_Name_Type) return Unit_Name_Header_Num is
1307 return Unit_Name_Header_Num (Id mod Unit_Name_Table_Size);
1316 Linker_Option_Lines.Locked := False;
1317 Load_Stack.Locked := False;
1318 Units.Locked := False;
1325 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1327 return Get_Hex_String (Units.Table (U).Version);
1330 ------------------------
1331 -- Version_Referenced --
1332 ------------------------
1334 procedure Version_Referenced (S : String_Id) is
1336 Version_Ref.Append (S);
1337 end Version_Referenced;
1339 ---------------------
1340 -- Write_Unit_Info --
1341 ---------------------
1343 procedure Write_Unit_Info
1344 (Unit_Num : Unit_Number_Type;
1346 Prefix : String := "";
1347 Withs : Boolean := False)
1351 Write_Unit_Name (Unit_Name (Unit_Num));
1352 Write_Str (", unit ");
1353 Write_Int (Int (Unit_Num));
1355 Write_Int (Int (Item));
1357 Write_Str (Node_Kind'Image (Nkind (Item)));
1359 if Is_Rewrite_Substitution (Item) then
1360 Write_Str (", orig = ");
1361 Write_Int (Int (Original_Node (Item)));
1363 Write_Str (Node_Kind'Image (Nkind (Original_Node (Item))));
1368 -- Skip the rest if we're not supposed to print the withs
1375 Context_Item : Node_Id;
1378 Context_Item := First (Context_Items (Cunit (Unit_Num)));
1379 while Present (Context_Item)
1380 and then (Nkind (Context_Item) /= N_With_Clause
1381 or else Limited_Present (Context_Item))
1383 Context_Item := Next (Context_Item);
1386 if Present (Context_Item) then
1388 Write_Line ("withs:");
1391 while Present (Context_Item) loop
1392 if Nkind (Context_Item) = N_With_Clause
1393 and then not Limited_Present (Context_Item)
1395 pragma Assert (Present (Library_Unit (Context_Item)));
1398 (Get_Cunit_Unit_Number (Library_Unit (Context_Item))));
1400 if Implicit_With (Context_Item) then
1401 Write_Str (" -- implicit");
1407 Context_Item := Next (Context_Item);
1411 Write_Line ("end withs");
1415 end Write_Unit_Info;