1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Boolean 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_Allocator
(U
: Unit_Number_Type
) return Boolean is
121 return Units
.Table
(U
).Has_Allocator
;
124 function Has_RACW
(U
: Unit_Number_Type
) return Boolean is
126 return Units
.Table
(U
).Has_RACW
;
129 function Is_Compiler_Unit
(U
: Unit_Number_Type
) return Boolean is
131 return Units
.Table
(U
).Is_Compiler_Unit
;
132 end Is_Compiler_Unit
;
134 function Ident_String
(U
: Unit_Number_Type
) return Node_Id
is
136 return Units
.Table
(U
).Ident_String
;
139 function Loading
(U
: Unit_Number_Type
) return Boolean is
141 return Units
.Table
(U
).Loading
;
144 function Main_CPU
(U
: Unit_Number_Type
) return Int
is
146 return Units
.Table
(U
).Main_CPU
;
149 function Main_Priority
(U
: Unit_Number_Type
) return Int
is
151 return Units
.Table
(U
).Main_Priority
;
154 function Munit_Index
(U
: Unit_Number_Type
) return Nat
is
156 return Units
.Table
(U
).Munit_Index
;
159 function OA_Setting
(U
: Unit_Number_Type
) return Character is
161 return Units
.Table
(U
).OA_Setting
;
164 function Source_Index
(U
: Unit_Number_Type
) return Source_File_Index
is
166 return Units
.Table
(U
).Source_Index
;
169 function SPARK_Mode_Pragma
(U
: Unit_Number_Type
) return Node_Id
is
171 return Units
.Table
(U
).SPARK_Mode_Pragma
;
172 end SPARK_Mode_Pragma
;
174 function Unit_File_Name
(U
: Unit_Number_Type
) return File_Name_Type
is
176 return Units
.Table
(U
).Unit_File_Name
;
179 function Unit_Name
(U
: Unit_Number_Type
) return Unit_Name_Type
is
181 return Units
.Table
(U
).Unit_Name
;
184 ------------------------------------------
185 -- Subprograms to Set Unit Table Fields --
186 ------------------------------------------
188 procedure Set_Cunit
(U
: Unit_Number_Type
; N
: Node_Id
) is
190 Units
.Table
(U
).Cunit
:= N
;
193 procedure Set_Cunit_Entity
(U
: Unit_Number_Type
; E
: Entity_Id
) is
195 Units
.Table
(U
).Cunit_Entity
:= E
;
196 Set_Is_Compilation_Unit
(E
);
197 end Set_Cunit_Entity
;
199 procedure Set_Dynamic_Elab
(U
: Unit_Number_Type
; B
: Boolean := True) is
201 Units
.Table
(U
).Dynamic_Elab
:= B
;
202 end Set_Dynamic_Elab
;
204 procedure Set_Error_Location
(U
: Unit_Number_Type
; W
: Source_Ptr
) is
206 Units
.Table
(U
).Error_Location
:= W
;
207 end Set_Error_Location
;
209 procedure Set_Fatal_Error
(U
: Unit_Number_Type
; B
: Boolean := True) is
211 Units
.Table
(U
).Fatal_Error
:= B
;
214 procedure Set_Generate_Code
(U
: Unit_Number_Type
; B
: Boolean := True) is
216 Units
.Table
(U
).Generate_Code
:= B
;
217 end Set_Generate_Code
;
219 procedure Set_Has_Allocator
(U
: Unit_Number_Type
; B
: Boolean := True) is
221 Units
.Table
(U
).Has_Allocator
:= B
;
222 end Set_Has_Allocator
;
224 procedure Set_Has_RACW
(U
: Unit_Number_Type
; B
: Boolean := True) is
226 Units
.Table
(U
).Has_RACW
:= B
;
229 procedure Set_Is_Compiler_Unit
230 (U
: Unit_Number_Type
;
234 Units
.Table
(U
).Is_Compiler_Unit
:= B
;
235 end Set_Is_Compiler_Unit
;
237 procedure Set_Ident_String
(U
: Unit_Number_Type
; N
: Node_Id
) is
239 Units
.Table
(U
).Ident_String
:= N
;
240 end Set_Ident_String
;
242 procedure Set_Loading
(U
: Unit_Number_Type
; B
: Boolean := True) is
244 Units
.Table
(U
).Loading
:= B
;
247 procedure Set_Main_CPU
(U
: Unit_Number_Type
; P
: Int
) is
249 Units
.Table
(U
).Main_CPU
:= P
;
252 procedure Set_Main_Priority
(U
: Unit_Number_Type
; P
: Int
) is
254 Units
.Table
(U
).Main_Priority
:= P
;
255 end Set_Main_Priority
;
257 procedure Set_OA_Setting
(U
: Unit_Number_Type
; C
: Character) is
259 Units
.Table
(U
).OA_Setting
:= C
;
262 procedure Set_SPARK_Mode_Pragma
(U
: Unit_Number_Type
; N
: Node_Id
) is
264 Units
.Table
(U
).SPARK_Mode_Pragma
:= N
;
265 end Set_SPARK_Mode_Pragma
;
267 procedure Set_Unit_Name
(U
: Unit_Number_Type
; N
: Unit_Name_Type
) is
269 Units
.Table
(U
).Unit_Name
:= N
;
272 ------------------------------
273 -- Check_Same_Extended_Unit --
274 ------------------------------
276 function Check_Same_Extended_Unit
(S1
, S2
: Source_Ptr
) return SEU_Result
is
279 Sind1
: Source_File_Index
;
280 Sind2
: Source_File_Index
;
283 Unum1
: Unit_Number_Type
;
284 Unum2
: Unit_Number_Type
;
291 if S1
= No_Location
or else S2
= No_Location
then
294 elsif S1
= Standard_Location
then
295 if S2
= Standard_Location
then
301 elsif S2
= Standard_Location
then
308 Unum1
:= Get_Source_Unit
(Sloc1
);
309 Unum2
:= Get_Source_Unit
(Sloc2
);
312 -- Step 1: Check whether the two locations are in the same source
315 Sind1
:= Get_Source_File_Index
(Sloc1
);
316 Sind2
:= Get_Source_File_Index
(Sloc2
);
318 if Sind1
= Sind2
then
319 if Sloc1
< Sloc2
then
321 elsif Sloc1
> Sloc2
then
328 -- Step 2: Check subunits. If a subunit is instantiated, follow the
329 -- instantiation chain rather than the stub chain.
331 Unit1
:= Unit
(Cunit
(Unum1
));
332 Unit2
:= Unit
(Cunit
(Unum2
));
333 Inst1
:= Instantiation
(Sind1
);
334 Inst2
:= Instantiation
(Sind2
);
336 if Nkind
(Unit1
) = N_Subunit
337 and then Present
(Corresponding_Stub
(Unit1
))
338 and then Inst1
= No_Location
340 if Nkind
(Unit2
) = N_Subunit
341 and then Present
(Corresponding_Stub
(Unit2
))
342 and then Inst2
= No_Location
344 -- Both locations refer to subunits which may have a common
345 -- ancestor. If they do, the deeper subunit must have a longer
346 -- unit name. Replace the deeper one with its corresponding
347 -- stub in order to find the nearest ancestor.
349 if Length_Of_Name
(Unit_Name
(Unum1
)) <
350 Length_Of_Name
(Unit_Name
(Unum2
))
352 Sloc2
:= Sloc
(Corresponding_Stub
(Unit2
));
353 Unum2
:= Get_Source_Unit
(Sloc2
);
357 Sloc1
:= Sloc
(Corresponding_Stub
(Unit1
));
358 Unum1
:= Get_Source_Unit
(Sloc1
);
362 -- Sloc1 in subunit, Sloc2 not
365 Sloc1
:= Sloc
(Corresponding_Stub
(Unit1
));
366 Unum1
:= Get_Source_Unit
(Sloc1
);
370 -- Sloc2 in subunit, Sloc1 not
372 elsif Nkind
(Unit2
) = N_Subunit
373 and then Present
(Corresponding_Stub
(Unit2
))
374 and then Inst2
= No_Location
376 Sloc2
:= Sloc
(Corresponding_Stub
(Unit2
));
377 Unum2
:= Get_Source_Unit
(Sloc2
);
381 -- Step 3: Check instances. The two locations may yield a common
384 if Inst1
/= No_Location
then
385 if Inst2
/= No_Location
then
387 -- Both locations denote instantiations
389 Depth1
:= Instantiation_Depth
(Sloc1
);
390 Depth2
:= Instantiation_Depth
(Sloc2
);
392 if Depth1
< Depth2
then
394 Unum2
:= Get_Source_Unit
(Sloc2
);
397 elsif Depth1
> Depth2
then
399 Unum1
:= Get_Source_Unit
(Sloc1
);
405 Unum1
:= Get_Source_Unit
(Sloc1
);
406 Unum2
:= Get_Source_Unit
(Sloc2
);
410 -- Sloc1 is an instantiation
414 Unum1
:= Get_Source_Unit
(Sloc1
);
418 -- Sloc2 is an instantiation
420 elsif Inst2
/= No_Location
then
422 Unum2
:= Get_Source_Unit
(Sloc2
);
426 -- Step 4: One location in the spec, the other in the corresponding
427 -- body of the same unit. The location in the spec is considered
430 if Nkind
(Unit1
) = N_Subprogram_Body
432 Nkind
(Unit1
) = N_Package_Body
434 if Library_Unit
(Cunit
(Unum1
)) = Cunit
(Unum2
) then
438 elsif Nkind
(Unit2
) = N_Subprogram_Body
440 Nkind
(Unit2
) = N_Package_Body
442 if Library_Unit
(Cunit
(Unum2
)) = Cunit
(Unum1
) then
447 -- At this point it is certain that the two locations denote two
448 -- entirely separate units.
455 end Check_Same_Extended_Unit
;
457 -------------------------------
458 -- Compilation_Switches_Last --
459 -------------------------------
461 function Compilation_Switches_Last
return Nat
is
463 return Compilation_Switches
.Last
;
464 end Compilation_Switches_Last
;
466 ---------------------------
467 -- Enable_Switch_Storing --
468 ---------------------------
470 procedure Enable_Switch_Storing
is
472 Switch_Storing_Enabled
:= True;
473 end Enable_Switch_Storing
;
475 ----------------------------
476 -- Disable_Switch_Storing --
477 ----------------------------
479 procedure Disable_Switch_Storing
is
481 Switch_Storing_Enabled
:= False;
482 end Disable_Switch_Storing
;
484 ------------------------------
485 -- Earlier_In_Extended_Unit --
486 ------------------------------
488 function Earlier_In_Extended_Unit
(S1
, S2
: Source_Ptr
) return Boolean is
490 return Check_Same_Extended_Unit
(S1
, S2
) = Yes_Before
;
491 end Earlier_In_Extended_Unit
;
493 -----------------------
494 -- Exact_Source_Name --
495 -----------------------
497 function Exact_Source_Name
(Loc
: Source_Ptr
) return String is
498 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
499 Buf
: constant Source_Buffer_Ptr
:= Source_Text
(Source_Index
(U
));
500 Orig
: constant Source_Ptr
:= Original_Location
(Loc
);
505 pragma Warnings
(Off
, WC
);
506 pragma Warnings
(Off
, Err
);
509 -- Entity is character literal
511 if Buf
(Orig
) = ''' then
512 return String (Buf
(Orig
.. Orig
+ 2));
514 -- Entity is operator symbol
516 elsif Buf
(Orig
) = '"' or else Buf
(Orig
) = '%' then
521 exit when Buf
(P
) = Buf
(Orig
);
524 return String (Buf
(Orig
.. P
));
526 -- Entity is identifier
532 if Is_Start_Of_Wide_Char
(Buf
, P
) then
533 Scan_Wide
(Buf
, P
, WC
, Err
);
534 elsif not Identifier_Char
(Buf
(P
)) then
541 -- Write out the identifier by copying the exact source characters
542 -- used in its declaration. Note that this means wide characters will
543 -- be in their original encoded form.
545 return String (Buf
(Orig
.. P
- 1));
547 end Exact_Source_Name
;
549 ----------------------------
550 -- Entity_Is_In_Main_Unit --
551 ----------------------------
553 function Entity_Is_In_Main_Unit
(E
: Entity_Id
) return Boolean is
559 while S
/= Standard_Standard
loop
560 if S
= Main_Unit_Entity
then
562 elsif Ekind
(S
) = E_Package
and then Is_Child_Unit
(S
) then
570 end Entity_Is_In_Main_Unit
;
572 --------------------------
573 -- Generic_May_Lack_ALI --
574 --------------------------
576 function Generic_May_Lack_ALI
(Sfile
: File_Name_Type
) return Boolean is
578 -- We allow internal generic units to be used without having a
579 -- corresponding ALI files to help bootstrapping with older compilers
580 -- that did not support generating ALIs for such generics. It is safe
581 -- to do so because the only thing the generated code would contain
582 -- is the elaboration boolean, and we are careful to elaborate all
583 -- predefined units first anyway.
585 return Is_Internal_File_Name
587 Renamings_Included
=> True);
588 end Generic_May_Lack_ALI
;
590 -----------------------------
591 -- Get_Code_Or_Source_Unit --
592 -----------------------------
594 function Get_Code_Or_Source_Unit
596 Unwind_Instances
: Boolean) return Unit_Number_Type
599 -- Search table unless we have No_Location, which can happen if the
600 -- relevant location has not been set yet. Happens for example when
601 -- we obtain Sloc (Cunit (Main_Unit)) before it is set.
603 if S
/= No_Location
then
605 Source_File
: Source_File_Index
;
606 Source_Unit
: Unit_Number_Type
;
609 Source_File
:= Get_Source_File_Index
(S
);
611 if Unwind_Instances
then
612 while Template
(Source_File
) /= No_Source_File
loop
613 Source_File
:= Template
(Source_File
);
617 Source_Unit
:= Unit
(Source_File
);
619 if Source_Unit
/= No_Unit
then
625 -- If S was No_Location, or was not in the table, we must be in the main
626 -- source unit (and the value has not been placed in the table yet),
627 -- or in one of the configuration pragma files.
630 end Get_Code_Or_Source_Unit
;
636 function Get_Code_Unit
(S
: Source_Ptr
) return Unit_Number_Type
is
638 return Get_Code_Or_Source_Unit
(Top_Level_Location
(S
),
639 Unwind_Instances
=> False);
642 function Get_Code_Unit
(N
: Node_Or_Entity_Id
) return Unit_Number_Type
is
644 return Get_Code_Unit
(Sloc
(N
));
647 ----------------------------
648 -- Get_Compilation_Switch --
649 ----------------------------
651 function Get_Compilation_Switch
(N
: Pos
) return String_Ptr
is
653 if N
<= Compilation_Switches
.Last
then
654 return Compilation_Switches
.Table
(N
);
659 end Get_Compilation_Switch
;
661 ----------------------------------
662 -- Get_Cunit_Entity_Unit_Number --
663 ----------------------------------
665 function Get_Cunit_Entity_Unit_Number
666 (E
: Entity_Id
) return Unit_Number_Type
669 for U
in Units
.First
.. Units
.Last
loop
670 if Cunit_Entity
(U
) = E
then
675 -- If not in the table, must be the main source unit, and we just
676 -- have not got it put into the table yet.
679 end Get_Cunit_Entity_Unit_Number
;
681 ---------------------------
682 -- Get_Cunit_Unit_Number --
683 ---------------------------
685 function Get_Cunit_Unit_Number
(N
: Node_Id
) return Unit_Number_Type
is
687 for U
in Units
.First
.. Units
.Last
loop
688 if Cunit
(U
) = N
then
693 -- If not in the table, must be a spec created for a main unit that is a
694 -- child subprogram body which we have not inserted into the table yet.
696 if N
= Library_Unit
(Cunit
(Main_Unit
)) then
699 -- If it is anything else, something is seriously wrong, and we really
700 -- don't want to proceed, even if assertions are off, so we explicitly
701 -- raise an exception in this case to terminate compilation.
706 end Get_Cunit_Unit_Number
;
708 ---------------------
709 -- Get_Source_Unit --
710 ---------------------
712 function Get_Source_Unit
(S
: Source_Ptr
) return Unit_Number_Type
is
714 return Get_Code_Or_Source_Unit
(S
, Unwind_Instances
=> True);
717 function Get_Source_Unit
(N
: Node_Or_Entity_Id
) return Unit_Number_Type
is
719 return Get_Source_Unit
(Sloc
(N
));
722 --------------------------------
723 -- In_Extended_Main_Code_Unit --
724 --------------------------------
726 function In_Extended_Main_Code_Unit
727 (N
: Node_Or_Entity_Id
) return Boolean
730 if Sloc
(N
) = Standard_Location
then
733 elsif Sloc
(N
) = No_Location
then
736 -- Special case Itypes to test the Sloc of the associated node. The
737 -- reason we do this is for possible calls from gigi after -gnatD
738 -- processing is complete in sprint. This processing updates the
739 -- sloc fields of all nodes in the tree, but itypes are not in the
740 -- tree so their slocs do not get updated.
742 elsif Nkind
(N
) = N_Defining_Identifier
743 and then Is_Itype
(N
)
745 return In_Extended_Main_Code_Unit
(Associated_Node_For_Itype
(N
));
747 -- Otherwise see if we are in the main unit
749 elsif Get_Code_Unit
(Sloc
(N
)) = Get_Code_Unit
(Cunit
(Main_Unit
)) then
752 -- Node may be in spec (or subunit etc) of main unit
756 In_Same_Extended_Unit
(N
, Cunit
(Main_Unit
));
758 end In_Extended_Main_Code_Unit
;
760 function In_Extended_Main_Code_Unit
(Loc
: Source_Ptr
) return Boolean is
762 if Loc
= Standard_Location
then
765 elsif Loc
= No_Location
then
768 -- Otherwise see if we are in the main unit
770 elsif Get_Code_Unit
(Loc
) = Get_Code_Unit
(Cunit
(Main_Unit
)) then
773 -- Location may be in spec (or subunit etc) of main unit
777 In_Same_Extended_Unit
(Loc
, Sloc
(Cunit
(Main_Unit
)));
779 end In_Extended_Main_Code_Unit
;
781 ----------------------------------
782 -- In_Extended_Main_Source_Unit --
783 ----------------------------------
785 function In_Extended_Main_Source_Unit
786 (N
: Node_Or_Entity_Id
) return Boolean
788 Nloc
: constant Source_Ptr
:= Sloc
(N
);
789 Mloc
: constant Source_Ptr
:= Sloc
(Cunit
(Main_Unit
));
792 -- If parsing, then use the global flag to indicate result
794 if Compiler_State
= Parsing
then
795 return Parsing_Main_Extended_Source
;
797 -- Special value cases
799 elsif Nloc
= Standard_Location
then
802 elsif Nloc
= No_Location
then
805 -- Special case Itypes to test the Sloc of the associated node. The
806 -- reason we do this is for possible calls from gigi after -gnatD
807 -- processing is complete in sprint. This processing updates the
808 -- sloc fields of all nodes in the tree, but itypes are not in the
809 -- tree so their slocs do not get updated.
811 elsif Nkind
(N
) = N_Defining_Identifier
812 and then Is_Itype
(N
)
814 return In_Extended_Main_Source_Unit
(Associated_Node_For_Itype
(N
));
816 -- Otherwise compare original locations to see if in same unit
820 In_Same_Extended_Unit
821 (Original_Location
(Nloc
), Original_Location
(Mloc
));
823 end In_Extended_Main_Source_Unit
;
825 function In_Extended_Main_Source_Unit
826 (Loc
: Source_Ptr
) return Boolean
828 Mloc
: constant Source_Ptr
:= Sloc
(Cunit
(Main_Unit
));
831 -- If parsing, then use the global flag to indicate result
833 if Compiler_State
= Parsing
then
834 return Parsing_Main_Extended_Source
;
836 -- Special value cases
838 elsif Loc
= Standard_Location
then
841 elsif Loc
= No_Location
then
844 -- Otherwise compare original locations to see if in same unit
848 In_Same_Extended_Unit
849 (Original_Location
(Loc
), Original_Location
(Mloc
));
851 end In_Extended_Main_Source_Unit
;
853 ------------------------
854 -- In_Predefined_Unit --
855 ------------------------
857 function In_Predefined_Unit
(N
: Node_Or_Entity_Id
) return Boolean is
859 return In_Predefined_Unit
(Sloc
(N
));
860 end In_Predefined_Unit
;
862 function In_Predefined_Unit
(S
: Source_Ptr
) return Boolean is
863 Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(S
);
864 File
: constant File_Name_Type
:= Unit_File_Name
(Unit
);
866 return Is_Predefined_File_Name
(File
);
867 end In_Predefined_Unit
;
869 -----------------------
870 -- In_Same_Code_Unit --
871 -----------------------
873 function In_Same_Code_Unit
(N1
, N2
: Node_Or_Entity_Id
) return Boolean is
874 S1
: constant Source_Ptr
:= Sloc
(N1
);
875 S2
: constant Source_Ptr
:= Sloc
(N2
);
878 if S1
= No_Location
or else S2
= No_Location
then
881 elsif S1
= Standard_Location
then
882 return S2
= Standard_Location
;
884 elsif S2
= Standard_Location
then
888 return Get_Code_Unit
(N1
) = Get_Code_Unit
(N2
);
889 end In_Same_Code_Unit
;
891 ---------------------------
892 -- In_Same_Extended_Unit --
893 ---------------------------
895 function In_Same_Extended_Unit
896 (N1
, N2
: Node_Or_Entity_Id
) return Boolean
899 return Check_Same_Extended_Unit
(Sloc
(N1
), Sloc
(N2
)) /= No
;
900 end In_Same_Extended_Unit
;
902 function In_Same_Extended_Unit
(S1
, S2
: Source_Ptr
) return Boolean is
904 return Check_Same_Extended_Unit
(S1
, S2
) /= No
;
905 end In_Same_Extended_Unit
;
907 -------------------------
908 -- In_Same_Source_Unit --
909 -------------------------
911 function In_Same_Source_Unit
(N1
, N2
: Node_Or_Entity_Id
) return Boolean is
912 S1
: constant Source_Ptr
:= Sloc
(N1
);
913 S2
: constant Source_Ptr
:= Sloc
(N2
);
916 if S1
= No_Location
or else S2
= No_Location
then
919 elsif S1
= Standard_Location
then
920 return S2
= Standard_Location
;
922 elsif S2
= Standard_Location
then
926 return Get_Source_Unit
(N1
) = Get_Source_Unit
(N2
);
927 end In_Same_Source_Unit
;
929 -----------------------------
930 -- Increment_Serial_Number --
931 -----------------------------
933 function Increment_Serial_Number
return Nat
is
934 TSN
: Int
renames Units
.Table
(Current_Sem_Unit
).Serial_Number
;
938 end Increment_Serial_Number
;
944 procedure Initialize
is
946 Linker_Option_Lines
.Init
;
950 Compilation_Switches
.Init
;
957 function Is_Loaded
(Uname
: Unit_Name_Type
) return Boolean is
959 for Unum
in Units
.First
.. Units
.Last
loop
960 if Uname
= Unit_Name
(Unum
) then
972 function Last_Unit
return Unit_Number_Type
is
981 procedure List
(File_Names_Only
: Boolean := False) is separate;
989 Linker_Option_Lines
.Locked
:= True;
990 Load_Stack
.Locked
:= True;
991 Units
.Locked
:= True;
992 Linker_Option_Lines
.Release
;
1001 function Num_Units
return Nat
is
1003 return Int
(Units
.Last
) - Int
(Main_Unit
) + 1;
1010 procedure Remove_Unit
(U
: Unit_Number_Type
) is
1012 if U
= Units
.Last
then
1013 Units
.Decrement_Last
;
1017 ----------------------------------
1018 -- Replace_Linker_Option_String --
1019 ----------------------------------
1021 procedure Replace_Linker_Option_String
1022 (S
: String_Id
; Match_String
: String)
1025 if Match_String
'Length > 0 then
1026 for J
in 1 .. Linker_Option_Lines
.Last
loop
1027 String_To_Name_Buffer
(Linker_Option_Lines
.Table
(J
).Option
);
1029 if Match_String
= Name_Buffer
(1 .. Match_String
'Length) then
1030 Linker_Option_Lines
.Table
(J
).Option
:= S
;
1036 Store_Linker_Option_String
(S
);
1037 end Replace_Linker_Option_String
;
1043 procedure Sort
(Tbl
: in out Unit_Ref_Table
) is separate;
1045 ------------------------------
1046 -- Store_Compilation_Switch --
1047 ------------------------------
1049 procedure Store_Compilation_Switch
(Switch
: String) is
1051 if Switch_Storing_Enabled
then
1052 Compilation_Switches
.Increment_Last
;
1053 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
1054 new String'(Switch);
1056 -- Fix up --RTS flag which has been transformed by the gcc driver
1059 if Switch'Last >= Switch'First + 4
1060 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
1062 Compilation_Switches.Table
1063 (Compilation_Switches.Last) (Switch'First + 1) := '-';
1066 end Store_Compilation_Switch;
1068 --------------------------------
1069 -- Store_Linker_Option_String --
1070 --------------------------------
1072 procedure Store_Linker_Option_String (S : String_Id) is
1074 Linker_Option_Lines.Append ((Option => S, Unit => Current_Sem_Unit));
1075 end Store_Linker_Option_String;
1081 procedure Store_Note (N : Node_Id) is
1083 Notes.Append ((Pragma_Node => N, Unit => Current_Sem_Unit));
1086 -------------------------------
1087 -- Synchronize_Serial_Number --
1088 -------------------------------
1090 procedure Synchronize_Serial_Number is
1091 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
1094 end Synchronize_Serial_Number;
1100 procedure Tree_Read is
1107 -- Read Compilation_Switches table. First release the memory occupied
1108 -- by the previously loaded switches.
1110 for J in Compilation_Switches.First .. Compilation_Switches.Last loop
1111 Free (Compilation_Switches.Table (J));
1115 Compilation_Switches.Set_Last (N);
1117 for J in 1 .. N loop
1119 Compilation_Switches.Table (J) := S;
1127 procedure Tree_Write is
1131 -- Write Compilation_Switches table
1133 Tree_Write_Int (Compilation_Switches.Last);
1135 for J in 1 .. Compilation_Switches.Last loop
1136 Tree_Write_Str (Compilation_Switches.Table (J));
1146 Linker_Option_Lines.Locked := False;
1147 Load_Stack.Locked := False;
1148 Units.Locked := False;
1155 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1157 return Get_Hex_String (Units.Table (U).Version);
1160 ------------------------
1161 -- Version_Referenced --
1162 ------------------------
1164 procedure Version_Referenced (S : String_Id) is
1166 Version_Ref.Append (S);
1167 end Version_Referenced;
1169 ---------------------
1170 -- Write_Unit_Info --
1171 ---------------------
1173 procedure Write_Unit_Info
1174 (Unit_Num : Unit_Number_Type;
1176 Prefix : String := "";
1177 Withs : Boolean := False)
1181 Write_Unit_Name (Unit_Name (Unit_Num));
1182 Write_Str (", unit ");
1183 Write_Int (Int (Unit_Num));
1185 Write_Int (Int (Item));
1187 Write_Str (Node_Kind'Image (Nkind (Item)));
1189 if Item /= Original_Node (Item) then
1190 Write_Str (", orig = ");
1191 Write_Int (Int (Original_Node (Item)));
1193 Write_Str (Node_Kind'Image (Nkind (Original_Node (Item))));
1198 -- Skip the rest if we're not supposed to print the withs
1205 Context_Item : Node_Id;
1208 Context_Item := First (Context_Items (Cunit (Unit_Num)));
1209 while Present (Context_Item)
1210 and then (Nkind (Context_Item) /= N_With_Clause
1211 or else Limited_Present (Context_Item))
1213 Context_Item := Next (Context_Item);
1216 if Present (Context_Item) then
1218 Write_Line ("withs:");
1221 while Present (Context_Item) loop
1222 if Nkind (Context_Item) = N_With_Clause
1223 and then not Limited_Present (Context_Item)
1225 pragma Assert (Present (Library_Unit (Context_Item)));
1228 (Get_Cunit_Unit_Number (Library_Unit (Context_Item))));
1230 if Implicit_With (Context_Item) then
1231 Write_Str (" -- implicit");
1237 Context_Item := Next (Context_Item);
1241 Write_Line ("end withs");
1245 end Write_Unit_Info;