1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, 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
281 Units
.Table
(U
).Unit_Name
:= N
;
284 ------------------------------
285 -- Check_Same_Extended_Unit --
286 ------------------------------
288 function Check_Same_Extended_Unit
290 S2
: Source_Ptr
) return SEU_Result
292 Max_Iterations
: constant Nat
:= Maximum_Instantiations
* 2;
293 -- Limit to prevent a potential infinite loop
300 Sind1
: Source_File_Index
;
301 Sind2
: Source_File_Index
;
306 Unum1
: Unit_Number_Type
;
307 Unum2
: Unit_Number_Type
;
310 if S1
= No_Location
or else S2
= No_Location
then
313 elsif S1
= Standard_Location
then
314 if S2
= Standard_Location
then
320 elsif S2
= Standard_Location
then
327 Unum1
:= Get_Source_Unit
(Sloc1
);
328 Unum2
:= Get_Source_Unit
(Sloc2
);
331 -- Step 1: Check whether the two locations are in the same source
334 Sind1
:= Get_Source_File_Index
(Sloc1
);
335 Sind2
:= Get_Source_File_Index
(Sloc2
);
337 if Sind1
= Sind2
then
338 if Sloc1
< Sloc2
then
340 elsif Sloc1
> Sloc2
then
347 -- Step 2: Check subunits. If a subunit is instantiated, follow the
348 -- instantiation chain rather than the stub chain.
350 Unit1
:= Unit
(Cunit
(Unum1
));
351 Unit2
:= Unit
(Cunit
(Unum2
));
352 Inst1
:= Instantiation
(Sind1
);
353 Inst2
:= Instantiation
(Sind2
);
355 if Nkind
(Unit1
) = N_Subunit
356 and then Present
(Corresponding_Stub
(Unit1
))
357 and then Inst1
= No_Location
359 if Nkind
(Unit2
) = N_Subunit
360 and then Present
(Corresponding_Stub
(Unit2
))
361 and then Inst2
= No_Location
363 -- Both locations refer to subunits which may have a common
364 -- ancestor. If they do, the deeper subunit must have a longer
365 -- unit name. Replace the deeper one with its corresponding
366 -- stub in order to find the nearest ancestor.
368 if Length_Of_Name
(Unit_Name
(Unum1
)) <
369 Length_Of_Name
(Unit_Name
(Unum2
))
371 Sloc2
:= Sloc
(Corresponding_Stub
(Unit2
));
372 Unum2
:= Get_Source_Unit
(Sloc2
);
376 Sloc1
:= Sloc
(Corresponding_Stub
(Unit1
));
377 Unum1
:= Get_Source_Unit
(Sloc1
);
381 -- Sloc1 in subunit, Sloc2 not
384 Sloc1
:= Sloc
(Corresponding_Stub
(Unit1
));
385 Unum1
:= Get_Source_Unit
(Sloc1
);
389 -- Sloc2 in subunit, Sloc1 not
391 elsif Nkind
(Unit2
) = N_Subunit
392 and then Present
(Corresponding_Stub
(Unit2
))
393 and then Inst2
= No_Location
395 Sloc2
:= Sloc
(Corresponding_Stub
(Unit2
));
396 Unum2
:= Get_Source_Unit
(Sloc2
);
400 -- Step 3: Check instances. The two locations may yield a common
403 if Inst1
/= No_Location
then
404 if Inst2
/= No_Location
then
406 -- Both locations denote instantiations
408 Depth1
:= Instantiation_Depth
(Sloc1
);
409 Depth2
:= Instantiation_Depth
(Sloc2
);
411 if Depth1
< Depth2
then
413 Unum2
:= Get_Source_Unit
(Sloc2
);
416 elsif Depth1
> Depth2
then
418 Unum1
:= Get_Source_Unit
(Sloc1
);
424 Unum1
:= Get_Source_Unit
(Sloc1
);
425 Unum2
:= Get_Source_Unit
(Sloc2
);
429 -- Sloc1 is an instantiation
433 Unum1
:= Get_Source_Unit
(Sloc1
);
437 -- Sloc2 is an instantiation
439 elsif Inst2
/= No_Location
then
441 Unum2
:= Get_Source_Unit
(Sloc2
);
445 -- Step 4: One location in the spec, the other in the corresponding
446 -- body of the same unit. The location in the spec is considered
449 if Nkind
(Unit1
) = N_Subprogram_Body
451 Nkind
(Unit1
) = N_Package_Body
453 if Library_Unit
(Cunit
(Unum1
)) = Cunit
(Unum2
) then
457 elsif Nkind
(Unit2
) = N_Subprogram_Body
459 Nkind
(Unit2
) = N_Package_Body
461 if Library_Unit
(Cunit
(Unum2
)) = Cunit
(Unum1
) then
466 -- At this point it is certain that the two locations denote two
467 -- entirely separate units.
472 Counter
:= Counter
+ 1;
474 -- Prevent looping forever
476 if Counter
> Max_Iterations
then
478 -- ??? Not quite right, but return a value to be able to generate
479 -- SCIL files and hope for the best.
481 if CodePeer_Mode
then
488 end Check_Same_Extended_Unit
;
490 -------------------------------
491 -- Compilation_Switches_Last --
492 -------------------------------
494 function Compilation_Switches_Last
return Nat
is
496 return Compilation_Switches
.Last
;
497 end Compilation_Switches_Last
;
499 ---------------------------
500 -- Enable_Switch_Storing --
501 ---------------------------
503 procedure Enable_Switch_Storing
is
505 Switch_Storing_Enabled
:= True;
506 end Enable_Switch_Storing
;
508 ----------------------------
509 -- Disable_Switch_Storing --
510 ----------------------------
512 procedure Disable_Switch_Storing
is
514 Switch_Storing_Enabled
:= False;
515 end Disable_Switch_Storing
;
517 ------------------------------
518 -- Earlier_In_Extended_Unit --
519 ------------------------------
521 function Earlier_In_Extended_Unit
523 S2
: Source_Ptr
) return Boolean
526 return Check_Same_Extended_Unit
(S1
, S2
) = Yes_Before
;
527 end Earlier_In_Extended_Unit
;
529 function Earlier_In_Extended_Unit
530 (N1
: Node_Or_Entity_Id
;
531 N2
: Node_Or_Entity_Id
) return Boolean
534 return Earlier_In_Extended_Unit
(Sloc
(N1
), Sloc
(N2
));
535 end Earlier_In_Extended_Unit
;
537 -----------------------
538 -- Exact_Source_Name --
539 -----------------------
541 function Exact_Source_Name
(Loc
: Source_Ptr
) return String is
542 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Loc
);
543 Buf
: constant Source_Buffer_Ptr
:= Source_Text
(Source_Index
(U
));
544 Orig
: constant Source_Ptr
:= Original_Location
(Loc
);
549 pragma Warnings
(Off
, WC
);
550 pragma Warnings
(Off
, Err
);
553 -- Entity is character literal
555 if Buf
(Orig
) = ''' then
556 return String (Buf
(Orig
.. Orig
+ 2));
558 -- Entity is operator symbol
560 elsif Buf
(Orig
) = '"' or else Buf
(Orig
) = '%' then
565 exit when Buf
(P
) = Buf
(Orig
);
568 return String (Buf
(Orig
.. P
));
570 -- Entity is identifier
576 if Is_Start_Of_Wide_Char
(Buf
, P
) then
577 Scan_Wide
(Buf
, P
, WC
, Err
);
578 elsif not Identifier_Char
(Buf
(P
)) then
585 -- Write out the identifier by copying the exact source characters
586 -- used in its declaration. Note that this means wide characters will
587 -- be in their original encoded form.
589 return String (Buf
(Orig
.. P
- 1));
591 end Exact_Source_Name
;
593 ----------------------------
594 -- Entity_Is_In_Main_Unit --
595 ----------------------------
597 function Entity_Is_In_Main_Unit
(E
: Entity_Id
) return Boolean is
603 while S
/= Standard_Standard
loop
604 if S
= Main_Unit_Entity
then
606 elsif Ekind
(S
) = E_Package
and then Is_Child_Unit
(S
) then
614 end Entity_Is_In_Main_Unit
;
616 --------------------------
617 -- Generic_May_Lack_ALI --
618 --------------------------
620 function Generic_May_Lack_ALI
(Unum
: Unit_Number_Type
) return Boolean is
622 -- We allow internal generic units to be used without having a
623 -- corresponding ALI files to help bootstrapping with older compilers
624 -- that did not support generating ALIs for such generics. It is safe
625 -- to do so because the only thing the generated code would contain
626 -- is the elaboration boolean, and we are careful to elaborate all
627 -- predefined units first anyway.
629 return Is_Internal_Unit
(Unum
);
630 end Generic_May_Lack_ALI
;
632 -----------------------------
633 -- Get_Code_Or_Source_Unit --
634 -----------------------------
636 function Get_Code_Or_Source_Unit
638 Unwind_Instances
: Boolean;
639 Unwind_Subunits
: Boolean) return Unit_Number_Type
642 -- Search table unless we have No_Location, which can happen if the
643 -- relevant location has not been set yet. Happens for example when
644 -- we obtain Sloc (Cunit (Main_Unit)) before it is set.
646 if S
/= No_Location
then
648 Source_File
: Source_File_Index
;
649 Source_Unit
: Unit_Number_Type
;
653 Source_File
:= Get_Source_File_Index
(S
);
655 if Unwind_Instances
then
656 while Template
(Source_File
) > No_Source_File
loop
657 Source_File
:= Template
(Source_File
);
661 Source_Unit
:= Unit
(Source_File
);
663 if Unwind_Subunits
then
664 Unit_Node
:= Unit
(Cunit
(Source_Unit
));
666 while Nkind
(Unit_Node
) = N_Subunit
667 and then Present
(Corresponding_Stub
(Unit_Node
))
670 Get_Code_Or_Source_Unit
671 (Sloc
(Corresponding_Stub
(Unit_Node
)),
672 Unwind_Instances
=> Unwind_Instances
,
673 Unwind_Subunits
=> Unwind_Subunits
);
674 Unit_Node
:= Unit
(Cunit
(Source_Unit
));
678 if Source_Unit
/= No_Unit
then
684 -- If S was No_Location, or was not in the table, we must be in the main
685 -- source unit (and the value has not been placed in the table yet),
686 -- or in one of the configuration pragma files.
689 end Get_Code_Or_Source_Unit
;
695 function Get_Code_Unit
(S
: Source_Ptr
) return Unit_Number_Type
is
698 Get_Code_Or_Source_Unit
699 (Top_Level_Location
(S
),
700 Unwind_Instances
=> False,
701 Unwind_Subunits
=> False);
704 function Get_Code_Unit
(N
: Node_Or_Entity_Id
) return Unit_Number_Type
is
706 return Get_Code_Unit
(Sloc
(N
));
709 ----------------------------
710 -- Get_Compilation_Switch --
711 ----------------------------
713 function Get_Compilation_Switch
(N
: Pos
) return String_Ptr
is
715 if N
<= Compilation_Switches
.Last
then
716 return Compilation_Switches
.Table
(N
);
720 end Get_Compilation_Switch
;
722 ----------------------------------
723 -- Get_Cunit_Entity_Unit_Number --
724 ----------------------------------
726 function Get_Cunit_Entity_Unit_Number
727 (E
: Entity_Id
) return Unit_Number_Type
730 for U
in Units
.First
.. Units
.Last
loop
731 if Cunit_Entity
(U
) = E
then
736 -- If not in the table, must be the main source unit, and we just
737 -- have not got it put into the table yet.
740 end Get_Cunit_Entity_Unit_Number
;
742 ---------------------------
743 -- Get_Cunit_Unit_Number --
744 ---------------------------
746 function Get_Cunit_Unit_Number
(N
: Node_Id
) return Unit_Number_Type
is
748 for U
in Units
.First
.. Units
.Last
loop
749 if Cunit
(U
) = N
then
754 -- If not in the table, must be a spec created for a main unit that is a
755 -- child subprogram body which we have not inserted into the table yet.
757 if N
= Library_Unit
(Cunit
(Main_Unit
)) then
760 -- If it is anything else, something is seriously wrong, and we really
761 -- don't want to proceed, even if assertions are off, so we explicitly
762 -- raise an exception in this case to terminate compilation.
767 end Get_Cunit_Unit_Number
;
769 ---------------------
770 -- Get_Source_Unit --
771 ---------------------
773 function Get_Source_Unit
(S
: Source_Ptr
) return Unit_Number_Type
is
776 Get_Code_Or_Source_Unit
778 Unwind_Instances
=> True,
779 Unwind_Subunits
=> False);
782 function Get_Source_Unit
(N
: Node_Or_Entity_Id
) return Unit_Number_Type
is
784 return Get_Source_Unit
(Sloc
(N
));
787 -----------------------------
788 -- Get_Top_Level_Code_Unit --
789 -----------------------------
791 function Get_Top_Level_Code_Unit
(S
: Source_Ptr
) return Unit_Number_Type
is
794 Get_Code_Or_Source_Unit
795 (Top_Level_Location
(S
),
796 Unwind_Instances
=> False,
797 Unwind_Subunits
=> True);
798 end Get_Top_Level_Code_Unit
;
800 function Get_Top_Level_Code_Unit
801 (N
: Node_Or_Entity_Id
) return Unit_Number_Type
is
803 return Get_Top_Level_Code_Unit
(Sloc
(N
));
804 end Get_Top_Level_Code_Unit
;
806 --------------------------------
807 -- In_Extended_Main_Code_Unit --
808 --------------------------------
810 function In_Extended_Main_Code_Unit
811 (N
: Node_Or_Entity_Id
) return Boolean
814 if Sloc
(N
) = Standard_Location
then
817 elsif Sloc
(N
) = No_Location
then
820 -- Special case Itypes to test the Sloc of the associated node. The
821 -- reason we do this is for possible calls from gigi after -gnatD
822 -- processing is complete in sprint. This processing updates the
823 -- sloc fields of all nodes in the tree, but itypes are not in the
824 -- tree so their slocs do not get updated.
826 elsif Nkind
(N
) = N_Defining_Identifier
827 and then Is_Itype
(N
)
829 return In_Extended_Main_Code_Unit
(Associated_Node_For_Itype
(N
));
831 -- Otherwise see if we are in the main unit
833 elsif Get_Code_Unit
(Sloc
(N
)) = Get_Code_Unit
(Cunit
(Main_Unit
)) then
836 -- Node may be in spec (or subunit etc) of main unit
839 return In_Same_Extended_Unit
(N
, Cunit
(Main_Unit
));
841 end In_Extended_Main_Code_Unit
;
843 function In_Extended_Main_Code_Unit
(Loc
: Source_Ptr
) return Boolean is
845 if Loc
= Standard_Location
then
848 elsif Loc
= No_Location
then
851 -- Otherwise see if we are in the main unit
853 elsif Get_Code_Unit
(Loc
) = Get_Code_Unit
(Cunit
(Main_Unit
)) then
856 -- Location may be in spec (or subunit etc) of main unit
859 return In_Same_Extended_Unit
(Loc
, Sloc
(Cunit
(Main_Unit
)));
861 end In_Extended_Main_Code_Unit
;
863 ----------------------------------
864 -- In_Extended_Main_Source_Unit --
865 ----------------------------------
867 function In_Extended_Main_Source_Unit
868 (N
: Node_Or_Entity_Id
) return Boolean
870 Nloc
: constant Source_Ptr
:= Sloc
(N
);
871 Mloc
: constant Source_Ptr
:= Sloc
(Cunit
(Main_Unit
));
874 -- If parsing, then use the global flag to indicate result
876 if Compiler_State
= Parsing
then
877 return Parsing_Main_Extended_Source
;
879 -- Special value cases
881 elsif Nloc
= Standard_Location
then
884 elsif Nloc
= No_Location
then
887 -- Special case Itypes to test the Sloc of the associated node. The
888 -- reason we do this is for possible calls from gigi after -gnatD
889 -- processing is complete in sprint. This processing updates the
890 -- sloc fields of all nodes in the tree, but itypes are not in the
891 -- tree so their slocs do not get updated.
893 elsif Nkind
(N
) = N_Defining_Identifier
894 and then Is_Itype
(N
)
896 return In_Extended_Main_Source_Unit
(Associated_Node_For_Itype
(N
));
898 -- Otherwise compare original locations to see if in same unit
902 In_Same_Extended_Unit
903 (Original_Location
(Nloc
), Original_Location
(Mloc
));
905 end In_Extended_Main_Source_Unit
;
907 function In_Extended_Main_Source_Unit
908 (Loc
: Source_Ptr
) return Boolean
910 Mloc
: constant Source_Ptr
:= Sloc
(Cunit
(Main_Unit
));
913 -- If parsing, then use the global flag to indicate result
915 if Compiler_State
= Parsing
then
916 return Parsing_Main_Extended_Source
;
918 -- Special value cases
920 elsif Loc
= Standard_Location
then
923 elsif Loc
= No_Location
then
926 -- Otherwise compare original locations to see if in same unit
930 In_Same_Extended_Unit
931 (Original_Location
(Loc
), Original_Location
(Mloc
));
933 end In_Extended_Main_Source_Unit
;
935 ----------------------
936 -- In_Internal_Unit --
937 ----------------------
939 function In_Internal_Unit
(N
: Node_Or_Entity_Id
) return Boolean is
941 return In_Internal_Unit
(Sloc
(N
));
942 end In_Internal_Unit
;
944 function In_Internal_Unit
(S
: Source_Ptr
) return Boolean is
945 Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(S
);
947 return Is_Internal_Unit
(Unit
);
948 end In_Internal_Unit
;
950 ----------------------------
951 -- In_Predefined_Renaming --
952 ----------------------------
954 function In_Predefined_Renaming
(N
: Node_Or_Entity_Id
) return Boolean is
956 return In_Predefined_Renaming
(Sloc
(N
));
957 end In_Predefined_Renaming
;
959 function In_Predefined_Renaming
(S
: Source_Ptr
) return Boolean is
960 Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(S
);
962 return Is_Predefined_Renaming
(Unit
);
963 end In_Predefined_Renaming
;
965 ------------------------
966 -- In_Predefined_Unit --
967 ------------------------
969 function In_Predefined_Unit
(N
: Node_Or_Entity_Id
) return Boolean is
971 return In_Predefined_Unit
(Sloc
(N
));
972 end In_Predefined_Unit
;
974 function In_Predefined_Unit
(S
: Source_Ptr
) return Boolean is
975 Unit
: constant Unit_Number_Type
:= Get_Source_Unit
(S
);
977 return Is_Predefined_Unit
(Unit
);
978 end In_Predefined_Unit
;
980 -----------------------
981 -- In_Same_Code_Unit --
982 -----------------------
984 function In_Same_Code_Unit
(N1
, N2
: Node_Or_Entity_Id
) return Boolean is
985 S1
: constant Source_Ptr
:= Sloc
(N1
);
986 S2
: constant Source_Ptr
:= Sloc
(N2
);
989 if S1
= No_Location
or else S2
= No_Location
then
992 elsif S1
= Standard_Location
then
993 return S2
= Standard_Location
;
995 elsif S2
= Standard_Location
then
999 return Get_Code_Unit
(N1
) = Get_Code_Unit
(N2
);
1000 end In_Same_Code_Unit
;
1002 ---------------------------
1003 -- In_Same_Extended_Unit --
1004 ---------------------------
1006 function In_Same_Extended_Unit
1007 (N1
, N2
: Node_Or_Entity_Id
) return Boolean
1010 return Check_Same_Extended_Unit
(Sloc
(N1
), Sloc
(N2
)) /= No
;
1011 end In_Same_Extended_Unit
;
1013 function In_Same_Extended_Unit
(S1
, S2
: Source_Ptr
) return Boolean is
1015 return Check_Same_Extended_Unit
(S1
, S2
) /= No
;
1016 end In_Same_Extended_Unit
;
1018 -------------------------
1019 -- In_Same_Source_Unit --
1020 -------------------------
1022 function In_Same_Source_Unit
(N1
, N2
: Node_Or_Entity_Id
) return Boolean is
1023 S1
: constant Source_Ptr
:= Sloc
(N1
);
1024 S2
: constant Source_Ptr
:= Sloc
(N2
);
1027 if S1
= No_Location
or else S2
= No_Location
then
1030 elsif S1
= Standard_Location
then
1031 return S2
= Standard_Location
;
1033 elsif S2
= Standard_Location
then
1037 return Get_Source_Unit
(N1
) = Get_Source_Unit
(N2
);
1038 end In_Same_Source_Unit
;
1040 -----------------------------------
1041 -- Increment_Primary_Stack_Count --
1042 -----------------------------------
1044 procedure Increment_Primary_Stack_Count
(Increment
: Int
) is
1045 PSC
: Int
renames Units
.Table
(Current_Sem_Unit
).Primary_Stack_Count
;
1047 PSC
:= PSC
+ Increment
;
1048 end Increment_Primary_Stack_Count
;
1050 -------------------------------
1051 -- Increment_Sec_Stack_Count --
1052 -------------------------------
1054 procedure Increment_Sec_Stack_Count
(Increment
: Int
) is
1055 SSC
: Int
renames Units
.Table
(Current_Sem_Unit
).Sec_Stack_Count
;
1057 SSC
:= SSC
+ Increment
;
1058 end Increment_Sec_Stack_Count
;
1060 -----------------------------
1061 -- Increment_Serial_Number --
1062 -----------------------------
1064 function Increment_Serial_Number
return Nat
is
1065 TSN
: Int
renames Units
.Table
(Current_Sem_Unit
).Serial_Number
;
1069 end Increment_Serial_Number
;
1075 procedure Initialize
is
1077 Linker_Option_Lines
.Init
;
1081 Compilation_Switches
.Init
;
1088 function Is_Loaded
(Uname
: Unit_Name_Type
) return Boolean is
1090 for Unum
in Units
.First
.. Units
.Last
loop
1091 if Uname
= Unit_Name
(Unum
) then
1103 function Last_Unit
return Unit_Number_Type
is
1112 procedure List
(File_Names_Only
: Boolean := False) is separate;
1120 Linker_Option_Lines
.Release
;
1121 Linker_Option_Lines
.Locked
:= True;
1123 Load_Stack
.Locked
:= True;
1125 Units
.Locked
:= True;
1132 function Num_Units
return Nat
is
1134 return Int
(Units
.Last
) - Int
(Main_Unit
) + 1;
1141 procedure Remove_Unit
(U
: Unit_Number_Type
) is
1143 if U
= Units
.Last
then
1144 Units
.Decrement_Last
;
1148 ----------------------------------
1149 -- Replace_Linker_Option_String --
1150 ----------------------------------
1152 procedure Replace_Linker_Option_String
1153 (S
: String_Id
; Match_String
: String)
1156 if Match_String
'Length > 0 then
1157 for J
in 1 .. Linker_Option_Lines
.Last
loop
1158 String_To_Name_Buffer
(Linker_Option_Lines
.Table
(J
).Option
);
1160 if Match_String
= Name_Buffer
(1 .. Match_String
'Length) then
1161 Linker_Option_Lines
.Table
(J
).Option
:= S
;
1167 Store_Linker_Option_String
(S
);
1168 end Replace_Linker_Option_String
;
1174 procedure Sort
(Tbl
: in out Unit_Ref_Table
) is separate;
1176 ------------------------------
1177 -- Store_Compilation_Switch --
1178 ------------------------------
1180 procedure Store_Compilation_Switch
(Switch
: String) is
1182 if Switch_Storing_Enabled
then
1183 Compilation_Switches
.Increment_Last
;
1184 Compilation_Switches
.Table
(Compilation_Switches
.Last
) :=
1185 new String'(Switch);
1187 -- Fix up --RTS flag which has been transformed by the gcc driver
1190 if Switch'Last >= Switch'First + 4
1191 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
1193 Compilation_Switches.Table
1194 (Compilation_Switches.Last) (Switch'First + 1) := '-';
1197 end Store_Compilation_Switch;
1199 --------------------------------
1200 -- Store_Linker_Option_String --
1201 --------------------------------
1203 procedure Store_Linker_Option_String (S : String_Id) is
1205 Linker_Option_Lines.Append ((Option => S, Unit => Current_Sem_Unit));
1206 end Store_Linker_Option_String;
1212 procedure Store_Note (N : Node_Id) is
1213 Sfile : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1216 -- Notes for a generic are emitted when processing the template, never
1219 if In_Extended_Main_Code_Unit (N)
1220 and then Instance (Sfile) = No_Instance_Id
1226 -------------------------------
1227 -- Synchronize_Serial_Number --
1228 -------------------------------
1230 procedure Synchronize_Serial_Number is
1231 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
1234 end Synchronize_Serial_Number;
1240 procedure Tree_Read is
1247 -- Read Compilation_Switches table. First release the memory occupied
1248 -- by the previously loaded switches.
1250 for J in Compilation_Switches.First .. Compilation_Switches.Last loop
1251 Free (Compilation_Switches.Table (J));
1255 Compilation_Switches.Set_Last (N);
1257 for J in 1 .. N loop
1259 Compilation_Switches.Table (J) := S;
1267 procedure Tree_Write is
1271 -- Write Compilation_Switches table
1273 Tree_Write_Int (Compilation_Switches.Last);
1275 for J in 1 .. Compilation_Switches.Last loop
1276 Tree_Write_Str (Compilation_Switches.Table (J));
1286 Linker_Option_Lines.Locked := False;
1287 Load_Stack.Locked := False;
1288 Units.Locked := False;
1295 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1297 return Get_Hex_String (Units.Table (U).Version);
1300 ------------------------
1301 -- Version_Referenced --
1302 ------------------------
1304 procedure Version_Referenced (S : String_Id) is
1306 Version_Ref.Append (S);
1307 end Version_Referenced;
1309 ---------------------
1310 -- Write_Unit_Info --
1311 ---------------------
1313 procedure Write_Unit_Info
1314 (Unit_Num : Unit_Number_Type;
1316 Prefix : String := "";
1317 Withs : Boolean := False)
1321 Write_Unit_Name (Unit_Name (Unit_Num));
1322 Write_Str (", unit ");
1323 Write_Int (Int (Unit_Num));
1325 Write_Int (Int (Item));
1327 Write_Str (Node_Kind'Image (Nkind (Item)));
1329 if Item /= Original_Node (Item) then
1330 Write_Str (", orig = ");
1331 Write_Int (Int (Original_Node (Item)));
1333 Write_Str (Node_Kind'Image (Nkind (Original_Node (Item))));
1338 -- Skip the rest if we're not supposed to print the withs
1345 Context_Item : Node_Id;
1348 Context_Item := First (Context_Items (Cunit (Unit_Num)));
1349 while Present (Context_Item)
1350 and then (Nkind (Context_Item) /= N_With_Clause
1351 or else Limited_Present (Context_Item))
1353 Context_Item := Next (Context_Item);
1356 if Present (Context_Item) then
1358 Write_Line ("withs:");
1361 while Present (Context_Item) loop
1362 if Nkind (Context_Item) = N_With_Clause
1363 and then not Limited_Present (Context_Item)
1365 pragma Assert (Present (Library_Unit (Context_Item)));
1368 (Get_Cunit_Unit_Number (Library_Unit (Context_Item))));
1370 if Implicit_With (Context_Item) then
1371 Write_Str (" -- implicit");
1377 Context_Item := Next (Context_Item);
1381 Write_Line ("end withs");
1385 end Write_Unit_Info;