1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Fname; use Fname;
40 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 (S1, S2 : Source_Ptr) return SEU_Result;
66 -- Used by In_Same_Extended_Unit and Earlier_In_Extended_Unit. Returns
67 -- value as described above.
69 function Get_Code_Or_Source_Unit
71 Unwind_Instances : Boolean) return Unit_Number_Type;
72 -- Common code for Get_Code_Unit (get unit of instantiation for location)
73 -- and Get_Source_Unit (get unit of template for location).
75 --------------------------------------------
76 -- Access Functions for Unit Table Fields --
77 --------------------------------------------
79 function Cunit (U : Unit_Number_Type) return Node_Id is
81 return Units.Table (U).Cunit;
84 function Cunit_Entity (U : Unit_Number_Type) return Entity_Id is
86 return Units.Table (U).Cunit_Entity;
89 function Dependency_Num (U : Unit_Number_Type) return Nat is
91 return Units.Table (U).Dependency_Num;
94 function Dynamic_Elab (U : Unit_Number_Type) return Boolean is
96 return Units.Table (U).Dynamic_Elab;
99 function Error_Location (U : Unit_Number_Type) return Source_Ptr is
101 return Units.Table (U).Error_Location;
104 function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type is
106 return Units.Table (U).Expected_Unit;
109 function Fatal_Error (U : Unit_Number_Type) return Fatal_Type is
111 return Units.Table (U).Fatal_Error;
114 function Generate_Code (U : Unit_Number_Type) return Boolean is
116 return Units.Table (U).Generate_Code;
119 function Has_RACW (U : Unit_Number_Type) return Boolean is
121 return Units.Table (U).Has_RACW;
124 function Ident_String (U : Unit_Number_Type) return Node_Id is
126 return Units.Table (U).Ident_String;
129 function Loading (U : Unit_Number_Type) return Boolean is
131 return Units.Table (U).Loading;
134 function Main_CPU (U : Unit_Number_Type) return Int is
136 return Units.Table (U).Main_CPU;
139 function Main_Priority (U : Unit_Number_Type) return Int is
141 return Units.Table (U).Main_Priority;
144 function Munit_Index (U : Unit_Number_Type) return Nat is
146 return Units.Table (U).Munit_Index;
149 function No_Elab_Code_All (U : Unit_Number_Type) return Boolean is
151 return Units.Table (U).No_Elab_Code_All;
152 end No_Elab_Code_All;
154 function OA_Setting (U : Unit_Number_Type) return Character is
156 return Units.Table (U).OA_Setting;
159 function Source_Index (U : Unit_Number_Type) return Source_File_Index is
161 return Units.Table (U).Source_Index;
164 function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type is
166 return Units.Table (U).Unit_File_Name;
169 function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type is
171 return Units.Table (U).Unit_Name;
174 ------------------------------------------
175 -- Subprograms to Set Unit Table Fields --
176 ------------------------------------------
178 procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id) is
180 Units.Table (U).Cunit := N;
183 procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id) is
185 Units.Table (U).Cunit_Entity := E;
186 Set_Is_Compilation_Unit (E);
187 end Set_Cunit_Entity;
189 procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True) is
191 Units.Table (U).Dynamic_Elab := B;
192 end Set_Dynamic_Elab;
194 procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr) is
196 Units.Table (U).Error_Location := W;
197 end Set_Error_Location;
199 procedure Set_Fatal_Error (U : Unit_Number_Type; V : Fatal_Type) is
201 Units.Table (U).Fatal_Error := V;
204 procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True) is
206 Units.Table (U).Generate_Code := B;
207 end Set_Generate_Code;
209 procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True) is
211 Units.Table (U).Has_RACW := B;
214 procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id) is
216 Units.Table (U).Ident_String := N;
217 end Set_Ident_String;
219 procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True) is
221 Units.Table (U).Loading := B;
224 procedure Set_Main_CPU (U : Unit_Number_Type; P : Int) is
226 Units.Table (U).Main_CPU := P;
229 procedure Set_Main_Priority (U : Unit_Number_Type; P : Int) is
231 Units.Table (U).Main_Priority := P;
232 end Set_Main_Priority;
234 procedure Set_No_Elab_Code_All
235 (U : Unit_Number_Type;
239 Units.Table (U).No_Elab_Code_All := B;
240 end Set_No_Elab_Code_All;
242 procedure Set_OA_Setting (U : Unit_Number_Type; C : Character) is
244 Units.Table (U).OA_Setting := C;
247 procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
249 Units.Table (U).Unit_Name := N;
252 ------------------------------
253 -- Check_Same_Extended_Unit --
254 ------------------------------
256 function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result is
259 Sind1 : Source_File_Index;
260 Sind2 : Source_File_Index;
263 Unum1 : Unit_Number_Type;
264 Unum2 : Unit_Number_Type;
271 if S1 = No_Location or else S2 = No_Location then
274 elsif S1 = Standard_Location then
275 if S2 = Standard_Location then
281 elsif S2 = Standard_Location then
288 Unum1 := Get_Source_Unit (Sloc1);
289 Unum2 := Get_Source_Unit (Sloc2);
292 -- Step 1: Check whether the two locations are in the same source
295 Sind1 := Get_Source_File_Index (Sloc1);
296 Sind2 := Get_Source_File_Index (Sloc2);
298 if Sind1 = Sind2 then
299 if Sloc1 < Sloc2 then
301 elsif Sloc1 > Sloc2 then
308 -- Step 2: Check subunits. If a subunit is instantiated, follow the
309 -- instantiation chain rather than the stub chain.
311 Unit1 := Unit (Cunit (Unum1));
312 Unit2 := Unit (Cunit (Unum2));
313 Inst1 := Instantiation (Sind1);
314 Inst2 := Instantiation (Sind2);
316 if Nkind (Unit1) = N_Subunit
317 and then Present (Corresponding_Stub (Unit1))
318 and then Inst1 = No_Location
320 if Nkind (Unit2) = N_Subunit
321 and then Present (Corresponding_Stub (Unit2))
322 and then Inst2 = No_Location
324 -- Both locations refer to subunits which may have a common
325 -- ancestor. If they do, the deeper subunit must have a longer
326 -- unit name. Replace the deeper one with its corresponding
327 -- stub in order to find the nearest ancestor.
329 if Length_Of_Name (Unit_Name (Unum1)) <
330 Length_Of_Name (Unit_Name (Unum2))
332 Sloc2 := Sloc (Corresponding_Stub (Unit2));
333 Unum2 := Get_Source_Unit (Sloc2);
337 Sloc1 := Sloc (Corresponding_Stub (Unit1));
338 Unum1 := Get_Source_Unit (Sloc1);
342 -- Sloc1 in subunit, Sloc2 not
345 Sloc1 := Sloc (Corresponding_Stub (Unit1));
346 Unum1 := Get_Source_Unit (Sloc1);
350 -- Sloc2 in subunit, Sloc1 not
352 elsif Nkind (Unit2) = N_Subunit
353 and then Present (Corresponding_Stub (Unit2))
354 and then Inst2 = No_Location
356 Sloc2 := Sloc (Corresponding_Stub (Unit2));
357 Unum2 := Get_Source_Unit (Sloc2);
361 -- Step 3: Check instances. The two locations may yield a common
364 if Inst1 /= No_Location then
365 if Inst2 /= No_Location then
367 -- Both locations denote instantiations
369 Depth1 := Instantiation_Depth (Sloc1);
370 Depth2 := Instantiation_Depth (Sloc2);
372 if Depth1 < Depth2 then
374 Unum2 := Get_Source_Unit (Sloc2);
377 elsif Depth1 > Depth2 then
379 Unum1 := Get_Source_Unit (Sloc1);
385 Unum1 := Get_Source_Unit (Sloc1);
386 Unum2 := Get_Source_Unit (Sloc2);
390 -- Sloc1 is an instantiation
394 Unum1 := Get_Source_Unit (Sloc1);
398 -- Sloc2 is an instantiation
400 elsif Inst2 /= No_Location then
402 Unum2 := Get_Source_Unit (Sloc2);
406 -- Step 4: One location in the spec, the other in the corresponding
407 -- body of the same unit. The location in the spec is considered
410 if Nkind (Unit1) = N_Subprogram_Body
412 Nkind (Unit1) = N_Package_Body
414 if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
418 elsif Nkind (Unit2) = N_Subprogram_Body
420 Nkind (Unit2) = N_Package_Body
422 if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
427 -- At this point it is certain that the two locations denote two
428 -- entirely separate units.
435 end Check_Same_Extended_Unit;
437 -------------------------------
438 -- Compilation_Switches_Last --
439 -------------------------------
441 function Compilation_Switches_Last return Nat is
443 return Compilation_Switches.Last;
444 end Compilation_Switches_Last;
446 ---------------------------
447 -- Enable_Switch_Storing --
448 ---------------------------
450 procedure Enable_Switch_Storing is
452 Switch_Storing_Enabled := True;
453 end Enable_Switch_Storing;
455 ----------------------------
456 -- Disable_Switch_Storing --
457 ----------------------------
459 procedure Disable_Switch_Storing is
461 Switch_Storing_Enabled := False;
462 end Disable_Switch_Storing;
464 ------------------------------
465 -- Earlier_In_Extended_Unit --
466 ------------------------------
468 function Earlier_In_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
470 return Check_Same_Extended_Unit (S1, S2) = Yes_Before;
471 end Earlier_In_Extended_Unit;
473 -----------------------
474 -- Exact_Source_Name --
475 -----------------------
477 function Exact_Source_Name (Loc : Source_Ptr) return String is
478 U : constant Unit_Number_Type := Get_Source_Unit (Loc);
479 Buf : constant Source_Buffer_Ptr := Source_Text (Source_Index (U));
480 Orig : constant Source_Ptr := Original_Location (Loc);
485 pragma Warnings (Off, WC);
486 pragma Warnings (Off, Err);
489 -- Entity is character literal
491 if Buf (Orig) = ''' then
492 return String (Buf (Orig .. Orig + 2));
494 -- Entity is operator symbol
496 elsif Buf (Orig) = '"' or else Buf (Orig) = '%' then
501 exit when Buf (P) = Buf (Orig);
504 return String (Buf (Orig .. P));
506 -- Entity is identifier
512 if Is_Start_Of_Wide_Char (Buf, P) then
513 Scan_Wide (Buf, P, WC, Err);
514 elsif not Identifier_Char (Buf (P)) then
521 -- Write out the identifier by copying the exact source characters
522 -- used in its declaration. Note that this means wide characters will
523 -- be in their original encoded form.
525 return String (Buf (Orig .. P - 1));
527 end Exact_Source_Name;
529 ----------------------------
530 -- Entity_Is_In_Main_Unit --
531 ----------------------------
533 function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean is
539 while S /= Standard_Standard loop
540 if S = Main_Unit_Entity then
542 elsif Ekind (S) = E_Package and then Is_Child_Unit (S) then
550 end Entity_Is_In_Main_Unit;
552 --------------------------
553 -- Generic_May_Lack_ALI --
554 --------------------------
556 function Generic_May_Lack_ALI (Sfile : File_Name_Type) return Boolean is
558 -- We allow internal generic units to be used without having a
559 -- corresponding ALI files to help bootstrapping with older compilers
560 -- that did not support generating ALIs for such generics. It is safe
561 -- to do so because the only thing the generated code would contain
562 -- is the elaboration boolean, and we are careful to elaborate all
563 -- predefined units first anyway.
565 return Is_Internal_File_Name
567 Renamings_Included => True);
568 end Generic_May_Lack_ALI;
570 -----------------------------
571 -- Get_Code_Or_Source_Unit --
572 -----------------------------
574 function Get_Code_Or_Source_Unit
576 Unwind_Instances : Boolean) return Unit_Number_Type
579 -- Search table unless we have No_Location, which can happen if the
580 -- relevant location has not been set yet. Happens for example when
581 -- we obtain Sloc (Cunit (Main_Unit)) before it is set.
583 if S /= No_Location then
585 Source_File : Source_File_Index;
586 Source_Unit : Unit_Number_Type;
589 Source_File := Get_Source_File_Index (S);
591 if Unwind_Instances then
592 while Template (Source_File) /= No_Source_File loop
593 Source_File := Template (Source_File);
597 Source_Unit := Unit (Source_File);
599 if Source_Unit /= No_Unit then
605 -- If S was No_Location, or was not in the table, we must be in the main
606 -- source unit (and the value has not been placed in the table yet),
607 -- or in one of the configuration pragma files.
610 end Get_Code_Or_Source_Unit;
616 function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
618 return Get_Code_Or_Source_Unit (Top_Level_Location (S),
619 Unwind_Instances => False);
622 function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
624 return Get_Code_Unit (Sloc (N));
627 ----------------------------
628 -- Get_Compilation_Switch --
629 ----------------------------
631 function Get_Compilation_Switch (N : Pos) return String_Ptr is
633 if N <= Compilation_Switches.Last then
634 return Compilation_Switches.Table (N);
639 end Get_Compilation_Switch;
641 ----------------------------------
642 -- Get_Cunit_Entity_Unit_Number --
643 ----------------------------------
645 function Get_Cunit_Entity_Unit_Number
646 (E : Entity_Id) return Unit_Number_Type
649 for U in Units.First .. Units.Last loop
650 if Cunit_Entity (U) = E then
655 -- If not in the table, must be the main source unit, and we just
656 -- have not got it put into the table yet.
659 end Get_Cunit_Entity_Unit_Number;
661 ---------------------------
662 -- Get_Cunit_Unit_Number --
663 ---------------------------
665 function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type is
667 for U in Units.First .. Units.Last loop
668 if Cunit (U) = N then
673 -- If not in the table, must be a spec created for a main unit that is a
674 -- child subprogram body which we have not inserted into the table yet.
676 if N = Library_Unit (Cunit (Main_Unit)) then
679 -- If it is anything else, something is seriously wrong, and we really
680 -- don't want to proceed, even if assertions are off, so we explicitly
681 -- raise an exception in this case to terminate compilation.
686 end Get_Cunit_Unit_Number;
688 ---------------------
689 -- Get_Source_Unit --
690 ---------------------
692 function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type is
694 return Get_Code_Or_Source_Unit (S, Unwind_Instances => True);
697 function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
699 return Get_Source_Unit (Sloc (N));
702 --------------------------------
703 -- In_Extended_Main_Code_Unit --
704 --------------------------------
706 function In_Extended_Main_Code_Unit
707 (N : Node_Or_Entity_Id) return Boolean
710 if Sloc (N) = Standard_Location then
713 elsif Sloc (N) = No_Location then
716 -- Special case Itypes to test the Sloc of the associated node. The
717 -- reason we do this is for possible calls from gigi after -gnatD
718 -- processing is complete in sprint. This processing updates the
719 -- sloc fields of all nodes in the tree, but itypes are not in the
720 -- tree so their slocs do not get updated.
722 elsif Nkind (N) = N_Defining_Identifier
723 and then Is_Itype (N)
725 return In_Extended_Main_Code_Unit (Associated_Node_For_Itype (N));
727 -- Otherwise see if we are in the main unit
729 elsif Get_Code_Unit (Sloc (N)) = Get_Code_Unit (Cunit (Main_Unit)) then
732 -- Node may be in spec (or subunit etc) of main unit
736 In_Same_Extended_Unit (N, Cunit (Main_Unit));
738 end In_Extended_Main_Code_Unit;
740 function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean is
742 if Loc = Standard_Location then
745 elsif Loc = No_Location then
748 -- Otherwise see if we are in the main unit
750 elsif Get_Code_Unit (Loc) = Get_Code_Unit (Cunit (Main_Unit)) then
753 -- Location may be in spec (or subunit etc) of main unit
757 In_Same_Extended_Unit (Loc, Sloc (Cunit (Main_Unit)));
759 end In_Extended_Main_Code_Unit;
761 ----------------------------------
762 -- In_Extended_Main_Source_Unit --
763 ----------------------------------
765 function In_Extended_Main_Source_Unit
766 (N : Node_Or_Entity_Id) return Boolean
768 Nloc : constant Source_Ptr := Sloc (N);
769 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
772 -- If parsing, then use the global flag to indicate result
774 if Compiler_State = Parsing then
775 return Parsing_Main_Extended_Source;
777 -- Special value cases
779 elsif Nloc = Standard_Location then
782 elsif Nloc = No_Location then
785 -- Special case Itypes to test the Sloc of the associated node. The
786 -- reason we do this is for possible calls from gigi after -gnatD
787 -- processing is complete in sprint. This processing updates the
788 -- sloc fields of all nodes in the tree, but itypes are not in the
789 -- tree so their slocs do not get updated.
791 elsif Nkind (N) = N_Defining_Identifier
792 and then Is_Itype (N)
794 return In_Extended_Main_Source_Unit (Associated_Node_For_Itype (N));
796 -- Otherwise compare original locations to see if in same unit
800 In_Same_Extended_Unit
801 (Original_Location (Nloc), Original_Location (Mloc));
803 end In_Extended_Main_Source_Unit;
805 function In_Extended_Main_Source_Unit
806 (Loc : Source_Ptr) return Boolean
808 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
811 -- If parsing, then use the global flag to indicate result
813 if Compiler_State = Parsing then
814 return Parsing_Main_Extended_Source;
816 -- Special value cases
818 elsif Loc = Standard_Location then
821 elsif Loc = No_Location then
824 -- Otherwise compare original locations to see if in same unit
828 In_Same_Extended_Unit
829 (Original_Location (Loc), Original_Location (Mloc));
831 end In_Extended_Main_Source_Unit;
833 ------------------------
834 -- In_Predefined_Unit --
835 ------------------------
837 function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean is
839 return In_Predefined_Unit (Sloc (N));
840 end In_Predefined_Unit;
842 function In_Predefined_Unit (S : Source_Ptr) return Boolean is
843 Unit : constant Unit_Number_Type := Get_Source_Unit (S);
844 File : constant File_Name_Type := Unit_File_Name (Unit);
846 return Is_Predefined_File_Name (File);
847 end In_Predefined_Unit;
849 -----------------------
850 -- In_Same_Code_Unit --
851 -----------------------
853 function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
854 S1 : constant Source_Ptr := Sloc (N1);
855 S2 : constant Source_Ptr := Sloc (N2);
858 if S1 = No_Location or else S2 = No_Location then
861 elsif S1 = Standard_Location then
862 return S2 = Standard_Location;
864 elsif S2 = Standard_Location then
868 return Get_Code_Unit (N1) = Get_Code_Unit (N2);
869 end In_Same_Code_Unit;
871 ---------------------------
872 -- In_Same_Extended_Unit --
873 ---------------------------
875 function In_Same_Extended_Unit
876 (N1, N2 : Node_Or_Entity_Id) return Boolean
879 return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
880 end In_Same_Extended_Unit;
882 function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
884 return Check_Same_Extended_Unit (S1, S2) /= No;
885 end In_Same_Extended_Unit;
887 -------------------------
888 -- In_Same_Source_Unit --
889 -------------------------
891 function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
892 S1 : constant Source_Ptr := Sloc (N1);
893 S2 : constant Source_Ptr := Sloc (N2);
896 if S1 = No_Location or else S2 = No_Location then
899 elsif S1 = Standard_Location then
900 return S2 = Standard_Location;
902 elsif S2 = Standard_Location then
906 return Get_Source_Unit (N1) = Get_Source_Unit (N2);
907 end In_Same_Source_Unit;
909 -----------------------------
910 -- Increment_Serial_Number --
911 -----------------------------
913 function Increment_Serial_Number return Nat is
914 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
918 end Increment_Serial_Number;
924 procedure Initialize is
926 Linker_Option_Lines.Init;
930 Compilation_Switches.Init;
937 function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
939 for Unum in Units.First .. Units.Last loop
940 if Uname = Unit_Name (Unum) then
952 function Last_Unit return Unit_Number_Type is
961 procedure List (File_Names_Only : Boolean := False) is separate;
969 Linker_Option_Lines.Locked := True;
970 Load_Stack.Locked := True;
971 Units.Locked := True;
972 Linker_Option_Lines.Release;
981 function Num_Units return Nat is
983 return Int (Units.Last) - Int (Main_Unit) + 1;
990 procedure Remove_Unit (U : Unit_Number_Type) is
992 if U = Units.Last then
993 Units.Decrement_Last;
997 ----------------------------------
998 -- Replace_Linker_Option_String --
999 ----------------------------------
1001 procedure Replace_Linker_Option_String
1002 (S : String_Id; Match_String : String)
1005 if Match_String'Length > 0 then
1006 for J in 1 .. Linker_Option_Lines.Last loop
1007 String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
1009 if Match_String = Name_Buffer (1 .. Match_String'Length) then
1010 Linker_Option_Lines.Table (J).Option := S;
1016 Store_Linker_Option_String (S);
1017 end Replace_Linker_Option_String;
1023 procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
1025 ------------------------------
1026 -- Store_Compilation_Switch --
1027 ------------------------------
1029 procedure Store_Compilation_Switch (Switch : String) is
1031 if Switch_Storing_Enabled then
1032 Compilation_Switches.Increment_Last;
1033 Compilation_Switches.Table (Compilation_Switches.Last) :=
1034 new String'(Switch);
1036 -- Fix up --RTS flag which has been transformed by the gcc driver
1039 if Switch'Last >= Switch'First + 4
1040 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
1042 Compilation_Switches.Table
1043 (Compilation_Switches.Last) (Switch'First + 1) := '-';
1046 end Store_Compilation_Switch;
1048 --------------------------------
1049 -- Store_Linker_Option_String --
1050 --------------------------------
1052 procedure Store_Linker_Option_String (S : String_Id) is
1054 Linker_Option_Lines.Append ((Option => S, Unit => Current_Sem_Unit));
1055 end Store_Linker_Option_String;
1061 procedure Store_Note (N : Node_Id) is
1062 Sfile : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1065 -- Notes for a generic are emitted when processing the template, never
1068 if In_Extended_Main_Code_Unit (N)
1069 and then Instance (Sfile) = No_Instance_Id
1075 -------------------------------
1076 -- Synchronize_Serial_Number --
1077 -------------------------------
1079 procedure Synchronize_Serial_Number is
1080 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
1083 end Synchronize_Serial_Number;
1089 procedure Tree_Read is
1096 -- Read Compilation_Switches table. First release the memory occupied
1097 -- by the previously loaded switches.
1099 for J in Compilation_Switches.First .. Compilation_Switches.Last loop
1100 Free (Compilation_Switches.Table (J));
1104 Compilation_Switches.Set_Last (N);
1106 for J in 1 .. N loop
1108 Compilation_Switches.Table (J) := S;
1116 procedure Tree_Write is
1120 -- Write Compilation_Switches table
1122 Tree_Write_Int (Compilation_Switches.Last);
1124 for J in 1 .. Compilation_Switches.Last loop
1125 Tree_Write_Str (Compilation_Switches.Table (J));
1135 Linker_Option_Lines.Locked := False;
1136 Load_Stack.Locked := False;
1137 Units.Locked := False;
1144 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1146 return Get_Hex_String (Units.Table (U).Version);
1149 ------------------------
1150 -- Version_Referenced --
1151 ------------------------
1153 procedure Version_Referenced (S : String_Id) is
1155 Version_Ref.Append (S);
1156 end Version_Referenced;
1158 ---------------------
1159 -- Write_Unit_Info --
1160 ---------------------
1162 procedure Write_Unit_Info
1163 (Unit_Num : Unit_Number_Type;
1165 Prefix : String := "";
1166 Withs : Boolean := False)
1170 Write_Unit_Name (Unit_Name (Unit_Num));
1171 Write_Str (", unit ");
1172 Write_Int (Int (Unit_Num));
1174 Write_Int (Int (Item));
1176 Write_Str (Node_Kind'Image (Nkind (Item)));
1178 if Item /= Original_Node (Item) then
1179 Write_Str (", orig = ");
1180 Write_Int (Int (Original_Node (Item)));
1182 Write_Str (Node_Kind'Image (Nkind (Original_Node (Item))));
1187 -- Skip the rest if we're not supposed to print the withs
1194 Context_Item : Node_Id;
1197 Context_Item := First (Context_Items (Cunit (Unit_Num)));
1198 while Present (Context_Item)
1199 and then (Nkind (Context_Item) /= N_With_Clause
1200 or else Limited_Present (Context_Item))
1202 Context_Item := Next (Context_Item);
1205 if Present (Context_Item) then
1207 Write_Line ("withs:");
1210 while Present (Context_Item) loop
1211 if Nkind (Context_Item) = N_With_Clause
1212 and then not Limited_Present (Context_Item)
1214 pragma Assert (Present (Library_Unit (Context_Item)));
1217 (Get_Cunit_Unit_Number (Library_Unit (Context_Item))));
1219 if Implicit_With (Context_Item) then
1220 Write_Str (" -- implicit");
1226 Context_Item := Next (Context_Item);
1230 Write_Line ("end withs");
1234 end Write_Unit_Info;