* gcc.c (getenv_spec_function): New function.
[official-gcc.git] / gcc / ada / lib.adb
blob069474f508d9341a24c8f70503c4774d49548b7a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 pragma Style_Checks (All_Checks);
35 -- Subprogram ordering not enforced in this unit
36 -- (because of some logical groupings).
38 with Atree; use Atree;
39 with Einfo; use Einfo;
40 with Fname; use Fname;
41 with Namet; use Namet;
42 with Output; use Output;
43 with Sinfo; use Sinfo;
44 with Sinput; use Sinput;
45 with Stand; use Stand;
46 with Stringt; use Stringt;
47 with Tree_IO; use Tree_IO;
48 with Uname; use Uname;
50 package body Lib is
52 Switch_Storing_Enabled : Boolean := True;
53 -- Set to False by Disable_Switch_Storing
55 -----------------------
56 -- Local Subprograms --
57 -----------------------
59 type SEU_Result is (
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
70 (S : Source_Ptr;
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
80 begin
81 return Units.Table (U).Cunit;
82 end Cunit;
84 function Cunit_Entity (U : Unit_Number_Type) return Entity_Id is
85 begin
86 return Units.Table (U).Cunit_Entity;
87 end Cunit_Entity;
89 function Dependency_Num (U : Unit_Number_Type) return Nat is
90 begin
91 return Units.Table (U).Dependency_Num;
92 end Dependency_Num;
94 function Dynamic_Elab (U : Unit_Number_Type) return Boolean is
95 begin
96 return Units.Table (U).Dynamic_Elab;
97 end Dynamic_Elab;
99 function Error_Location (U : Unit_Number_Type) return Source_Ptr is
100 begin
101 return Units.Table (U).Error_Location;
102 end Error_Location;
104 function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type is
105 begin
106 return Units.Table (U).Expected_Unit;
107 end Expected_Unit;
109 function Fatal_Error (U : Unit_Number_Type) return Boolean is
110 begin
111 return Units.Table (U).Fatal_Error;
112 end Fatal_Error;
114 function Generate_Code (U : Unit_Number_Type) return Boolean is
115 begin
116 return Units.Table (U).Generate_Code;
117 end Generate_Code;
119 function Has_RACW (U : Unit_Number_Type) return Boolean is
120 begin
121 return Units.Table (U).Has_RACW;
122 end Has_RACW;
124 function Ident_String (U : Unit_Number_Type) return Node_Id is
125 begin
126 return Units.Table (U).Ident_String;
127 end Ident_String;
129 function Loading (U : Unit_Number_Type) return Boolean is
130 begin
131 return Units.Table (U).Loading;
132 end Loading;
134 function Main_Priority (U : Unit_Number_Type) return Int is
135 begin
136 return Units.Table (U).Main_Priority;
137 end Main_Priority;
139 function Munit_Index (U : Unit_Number_Type) return Nat is
140 begin
141 return Units.Table (U).Munit_Index;
142 end Munit_Index;
144 function Source_Index (U : Unit_Number_Type) return Source_File_Index is
145 begin
146 return Units.Table (U).Source_Index;
147 end Source_Index;
149 function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type is
150 begin
151 return Units.Table (U).Unit_File_Name;
152 end Unit_File_Name;
154 function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type is
155 begin
156 return Units.Table (U).Unit_Name;
157 end Unit_Name;
159 ------------------------------------------
160 -- Subprograms to Set Unit Table Fields --
161 ------------------------------------------
163 procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id) is
164 begin
165 Units.Table (U).Cunit := N;
166 end Set_Cunit;
168 procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id) is
169 begin
170 Units.Table (U).Cunit_Entity := E;
171 Set_Is_Compilation_Unit (E);
172 end Set_Cunit_Entity;
174 procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True) is
175 begin
176 Units.Table (U).Dynamic_Elab := B;
177 end Set_Dynamic_Elab;
179 procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr) is
180 begin
181 Units.Table (U).Error_Location := W;
182 end Set_Error_Location;
184 procedure Set_Fatal_Error (U : Unit_Number_Type; B : Boolean := True) is
185 begin
186 Units.Table (U).Fatal_Error := B;
187 end Set_Fatal_Error;
189 procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True) is
190 begin
191 Units.Table (U).Generate_Code := B;
192 end Set_Generate_Code;
194 procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True) is
195 begin
196 Units.Table (U).Has_RACW := B;
197 end Set_Has_RACW;
199 procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id) is
200 begin
201 Units.Table (U).Ident_String := N;
202 end Set_Ident_String;
204 procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True) is
205 begin
206 Units.Table (U).Loading := B;
207 end Set_Loading;
209 procedure Set_Main_Priority (U : Unit_Number_Type; P : Int) is
210 begin
211 Units.Table (U).Main_Priority := P;
212 end Set_Main_Priority;
214 procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
215 begin
216 Units.Table (U).Unit_Name := N;
217 end Set_Unit_Name;
219 ------------------------------
220 -- Check_Same_Extended_Unit --
221 ------------------------------
223 function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result is
224 Sloc1 : Source_Ptr;
225 Sloc2 : Source_Ptr;
226 Sind1 : Source_File_Index;
227 Sind2 : Source_File_Index;
228 Inst1 : Source_Ptr;
229 Inst2 : Source_Ptr;
230 Unum1 : Unit_Number_Type;
231 Unum2 : Unit_Number_Type;
232 Unit1 : Node_Id;
233 Unit2 : Node_Id;
234 Depth1 : Nat;
235 Depth2 : Nat;
237 begin
238 if S1 = No_Location or else S2 = No_Location then
239 return No;
241 elsif S1 = Standard_Location then
242 if S2 = Standard_Location then
243 return Yes_Same;
244 else
245 return No;
246 end if;
248 elsif S2 = Standard_Location then
249 return No;
250 end if;
252 Sloc1 := S1;
253 Sloc2 := S2;
254 Unum1 := Get_Code_Unit (Sloc1);
255 Unum2 := Get_Code_Unit (Sloc2);
257 loop
258 Sind1 := Get_Source_File_Index (Sloc1);
259 Sind2 := Get_Source_File_Index (Sloc2);
261 if Sind1 = Sind2 then
262 if Sloc1 < Sloc2 then
263 return Yes_Before;
264 elsif Sloc1 > Sloc2 then
265 return Yes_After;
266 else
267 return Yes_Same;
268 end if;
269 end if;
271 -- OK, the two nodes are in separate source elements, but this is not
272 -- decisive, because of the issue of subunits and instantiations.
274 -- First we deal with subunits, since if the subunit is in an
275 -- instantiation, we know that the parent is in the corresponding
276 -- instantiation, since that is the only way we can have a subunit
277 -- that is part of an instantiation.
279 Unit1 := Unit (Cunit (Unum1));
280 Unit2 := Unit (Cunit (Unum2));
282 if Nkind (Unit1) = N_Subunit
283 and then Present (Corresponding_Stub (Unit1))
284 then
285 -- Both in subunits. They could have a common ancestor. If they
286 -- do, then the deeper one must have a longer unit name. Replace
287 -- the deeper one with its corresponding stub, in order to find
288 -- nearest common ancestor, if any.
290 if Nkind (Unit2) = N_Subunit
291 and then Present (Corresponding_Stub (Unit2))
292 then
293 if Length_Of_Name (Unit_Name (Unum1)) <
294 Length_Of_Name (Unit_Name (Unum2))
295 then
296 Sloc2 := Sloc (Corresponding_Stub (Unit2));
297 Unum2 := Get_Source_Unit (Sloc2);
298 goto Continue;
300 else
301 Sloc1 := Sloc (Corresponding_Stub (Unit1));
302 Unum1 := Get_Source_Unit (Sloc1);
303 goto Continue;
304 end if;
306 -- Nod1 in subunit, Nod2 not
308 else
309 Sloc1 := Sloc (Corresponding_Stub (Unit1));
310 Unum1 := Get_Source_Unit (Sloc1);
311 goto Continue;
312 end if;
314 -- Nod2 in subunit, Nod1 not
316 elsif Nkind (Unit2) = N_Subunit
317 and then Present (Corresponding_Stub (Unit2))
318 then
319 Sloc2 := Sloc (Corresponding_Stub (Unit2));
320 Unum2 := Get_Source_Unit (Sloc2);
321 goto Continue;
322 end if;
324 -- At this stage we know that neither is a subunit, so we deal
325 -- with instantiations, since we culd have a common ancestor
327 Inst1 := Instantiation (Sind1);
328 Inst2 := Instantiation (Sind2);
330 if Inst1 /= No_Location then
332 -- Both are instantiations
334 if Inst2 /= No_Location then
336 Depth1 := Instantiation_Depth (Sloc1);
337 Depth2 := Instantiation_Depth (Sloc2);
339 if Depth1 < Depth2 then
340 Sloc2 := Inst2;
341 Unum2 := Get_Source_Unit (Sloc2);
342 goto Continue;
344 elsif Depth1 > Depth2 then
345 Sloc1 := Inst1;
346 Unum1 := Get_Source_Unit (Sloc1);
347 goto Continue;
349 else
350 Sloc1 := Inst1;
351 Sloc2 := Inst2;
352 Unum1 := Get_Source_Unit (Sloc1);
353 Unum2 := Get_Source_Unit (Sloc2);
354 goto Continue;
355 end if;
357 -- Only first node is in instantiation
359 else
360 Sloc1 := Inst1;
361 Unum1 := Get_Source_Unit (Sloc1);
362 goto Continue;
363 end if;
365 -- Only second node is instantiation
367 elsif Inst2 /= No_Location then
368 Sloc2 := Inst2;
369 Unum2 := Get_Source_Unit (Sloc2);
370 goto Continue;
371 end if;
373 -- No instantiations involved, so we are not in the same unit
374 -- However, there is one case still to check, namely the case
375 -- where one location is in the spec, and the other in the
376 -- corresponding body (the spec location is earlier).
378 if Nkind (Unit1) = N_Subprogram_Body
379 or else
380 Nkind (Unit1) = N_Package_Body
381 then
382 if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
383 return Yes_After;
384 end if;
386 elsif Nkind (Unit2) = N_Subprogram_Body
387 or else
388 Nkind (Unit2) = N_Package_Body
389 then
390 if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
391 return Yes_Before;
392 end if;
393 end if;
395 -- If that special case does not occur, then we are certain that
396 -- the two locations are really in separate units.
398 return No;
400 <<Continue>>
401 null;
402 end loop;
403 end Check_Same_Extended_Unit;
405 -------------------------------
406 -- Compilation_Switches_Last --
407 -------------------------------
409 function Compilation_Switches_Last return Nat is
410 begin
411 return Compilation_Switches.Last;
412 end Compilation_Switches_Last;
414 procedure Disable_Switch_Storing is
415 begin
416 Switch_Storing_Enabled := False;
417 end Disable_Switch_Storing;
419 ------------------------------
420 -- Earlier_In_Extended_Unit --
421 ------------------------------
423 function Earlier_In_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
424 begin
425 return Check_Same_Extended_Unit (S1, S2) = Yes_Before;
426 end Earlier_In_Extended_Unit;
428 ----------------------------
429 -- Entity_Is_In_Main_Unit --
430 ----------------------------
432 function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean is
433 S : Entity_Id;
435 begin
436 S := Scope (E);
438 while S /= Standard_Standard loop
439 if S = Main_Unit_Entity then
440 return True;
441 elsif Ekind (S) = E_Package and then Is_Child_Unit (S) then
442 return False;
443 else
444 S := Scope (S);
445 end if;
446 end loop;
448 return False;
449 end Entity_Is_In_Main_Unit;
451 ---------------------------------
452 -- Generic_Separately_Compiled --
453 ---------------------------------
455 function Generic_Separately_Compiled (E : Entity_Id) return Boolean is
456 begin
457 -- We do not generate object files for internal generics, because
458 -- the only thing they would contain is the elaboration boolean, and
459 -- we are careful to elaborate all predefined units first anyway, so
460 -- this boolean is not needed.
462 if Is_Internal_File_Name
463 (Fname => Unit_File_Name (Get_Source_Unit (E)),
464 Renamings_Included => True)
465 then
466 return False;
468 -- All other generic units do generate object files
470 else
471 return True;
472 end if;
473 end Generic_Separately_Compiled;
475 function Generic_Separately_Compiled
476 (Sfile : File_Name_Type) return Boolean
478 begin
479 -- Exactly the same as previous function, but works directly on a file
480 -- name.
482 if Is_Internal_File_Name
483 (Fname => Sfile,
484 Renamings_Included => True)
485 then
486 return False;
488 -- All other generic units do generate object files
490 else
491 return True;
492 end if;
493 end Generic_Separately_Compiled;
495 -----------------------------
496 -- Get_Code_Or_Source_Unit --
497 -----------------------------
499 function Get_Code_Or_Source_Unit
500 (S : Source_Ptr;
501 Unwind_Instances : Boolean) return Unit_Number_Type
503 begin
504 -- Search table unless we have No_Location, which can happen if the
505 -- relevant location has not been set yet. Happens for example when
506 -- we obtain Sloc (Cunit (Main_Unit)) before it is set.
508 if S /= No_Location then
509 declare
510 Source_File : Source_File_Index;
511 Source_Unit : Unit_Number_Type;
513 begin
514 Source_File := Get_Source_File_Index (S);
516 if Unwind_Instances then
517 while Template (Source_File) /= No_Source_File loop
518 Source_File := Template (Source_File);
519 end loop;
520 end if;
522 Source_Unit := Unit (Source_File);
524 if Source_Unit /= No_Unit then
525 return Source_Unit;
526 end if;
527 end;
528 end if;
530 -- If S was No_Location, or was not in the table, we must be in the main
531 -- source unit (and the value has not been placed in the table yet),
532 -- or in one of the configuration pragma files.
534 return Main_Unit;
535 end Get_Code_Or_Source_Unit;
537 -------------------
538 -- Get_Code_Unit --
539 -------------------
541 function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
542 begin
543 return Get_Code_Or_Source_Unit (Top_Level_Location (S),
544 Unwind_Instances => False);
545 end Get_Code_Unit;
547 function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
548 begin
549 return Get_Code_Unit (Sloc (N));
550 end Get_Code_Unit;
552 ----------------------------
553 -- Get_Compilation_Switch --
554 ----------------------------
556 function Get_Compilation_Switch (N : Pos) return String_Ptr is
557 begin
558 if N <= Compilation_Switches.Last then
559 return Compilation_Switches.Table (N);
561 else
562 return null;
563 end if;
564 end Get_Compilation_Switch;
566 ----------------------------------
567 -- Get_Cunit_Entity_Unit_Number --
568 ----------------------------------
570 function Get_Cunit_Entity_Unit_Number
571 (E : Entity_Id) return Unit_Number_Type
573 begin
574 for U in Units.First .. Units.Last loop
575 if Cunit_Entity (U) = E then
576 return U;
577 end if;
578 end loop;
580 -- If not in the table, must be the main source unit, and we just
581 -- have not got it put into the table yet.
583 return Main_Unit;
584 end Get_Cunit_Entity_Unit_Number;
586 ---------------------------
587 -- Get_Cunit_Unit_Number --
588 ---------------------------
590 function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type is
591 begin
592 for U in Units.First .. Units.Last loop
593 if Cunit (U) = N then
594 return U;
595 end if;
596 end loop;
598 -- If not in the table, must be the main source unit, and we just
599 -- have not got it put into the table yet.
601 return Main_Unit;
602 end Get_Cunit_Unit_Number;
604 ---------------------
605 -- Get_Source_Unit --
606 ---------------------
608 function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type is
609 begin
610 return Get_Code_Or_Source_Unit (S, Unwind_Instances => True);
611 end Get_Source_Unit;
613 function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
614 begin
615 return Get_Source_Unit (Sloc (N));
616 end Get_Source_Unit;
618 --------------------------------
619 -- In_Extended_Main_Code_Unit --
620 --------------------------------
622 function In_Extended_Main_Code_Unit
623 (N : Node_Or_Entity_Id) return Boolean
625 begin
626 if Sloc (N) = Standard_Location then
627 return True;
629 elsif Sloc (N) = No_Location then
630 return False;
632 -- Special case Itypes to test the Sloc of the associated node. The
633 -- reason we do this is for possible calls from gigi after -gnatD
634 -- processing is complete in sprint. This processing updates the
635 -- sloc fields of all nodes in the tree, but itypes are not in the
636 -- tree so their slocs do not get updated.
638 elsif Nkind (N) = N_Defining_Identifier
639 and then Is_Itype (N)
640 then
641 return In_Extended_Main_Code_Unit (Associated_Node_For_Itype (N));
643 -- Otherwise see if we are in the main unit
645 elsif Get_Code_Unit (Sloc (N)) = Get_Code_Unit (Cunit (Main_Unit)) then
646 return True;
648 -- Node may be in spec (or subunit etc) of main unit
650 else
651 return
652 In_Same_Extended_Unit (N, Cunit (Main_Unit));
653 end if;
654 end In_Extended_Main_Code_Unit;
656 function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean is
657 begin
658 if Loc = Standard_Location then
659 return True;
661 elsif Loc = No_Location then
662 return False;
664 -- Otherwise see if we are in the main unit
666 elsif Get_Code_Unit (Loc) = Get_Code_Unit (Cunit (Main_Unit)) then
667 return True;
669 -- Location may be in spec (or subunit etc) of main unit
671 else
672 return
673 In_Same_Extended_Unit (Loc, Sloc (Cunit (Main_Unit)));
674 end if;
675 end In_Extended_Main_Code_Unit;
677 ----------------------------------
678 -- In_Extended_Main_Source_Unit --
679 ----------------------------------
681 function In_Extended_Main_Source_Unit
682 (N : Node_Or_Entity_Id) return Boolean
684 Nloc : constant Source_Ptr := Sloc (N);
685 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
687 begin
688 -- If Mloc is not set, it means we are still parsing the main unit,
689 -- so everything so far is in the extended main source unit.
691 if Mloc = No_Location then
692 return True;
694 -- Special value cases
696 elsif Nloc = Standard_Location then
697 return True;
699 elsif Nloc = No_Location then
700 return False;
702 -- Special case Itypes to test the Sloc of the associated node. The
703 -- reason we do this is for possible calls from gigi after -gnatD
704 -- processing is complete in sprint. This processing updates the
705 -- sloc fields of all nodes in the tree, but itypes are not in the
706 -- tree so their slocs do not get updated.
708 elsif Nkind (N) = N_Defining_Identifier
709 and then Is_Itype (N)
710 then
711 return In_Extended_Main_Source_Unit (Associated_Node_For_Itype (N));
713 -- Otherwise compare original locations to see if in same unit
715 else
716 return
717 In_Same_Extended_Unit
718 (Original_Location (Nloc), Original_Location (Mloc));
719 end if;
720 end In_Extended_Main_Source_Unit;
722 function In_Extended_Main_Source_Unit
723 (Loc : Source_Ptr) return Boolean
725 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
727 begin
728 -- If Mloc is not set, it means we are still parsing the main unit,
729 -- so everything so far is in the extended main source unit.
731 if Mloc = No_Location then
732 return True;
734 -- Special value cases
736 elsif Loc = Standard_Location then
737 return True;
739 elsif Loc = No_Location then
740 return False;
742 -- Otherwise compare original locations to see if in same unit
744 else
745 return
746 In_Same_Extended_Unit
747 (Original_Location (Loc), Original_Location (Mloc));
748 end if;
749 end In_Extended_Main_Source_Unit;
751 ------------------------
752 -- In_Predefined_Unit --
753 ------------------------
755 function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean is
756 begin
757 return In_Predefined_Unit (Sloc (N));
758 end In_Predefined_Unit;
760 function In_Predefined_Unit (S : Source_Ptr) return Boolean is
761 Unit : constant Unit_Number_Type := Get_Source_Unit (S);
762 File : constant File_Name_Type := Unit_File_Name (Unit);
763 begin
764 return Is_Predefined_File_Name (File);
765 end In_Predefined_Unit;
767 -----------------------
768 -- In_Same_Code_Unit --
769 -----------------------
771 function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
772 S1 : constant Source_Ptr := Sloc (N1);
773 S2 : constant Source_Ptr := Sloc (N2);
775 begin
776 if S1 = No_Location or else S2 = No_Location then
777 return False;
779 elsif S1 = Standard_Location then
780 return S2 = Standard_Location;
782 elsif S2 = Standard_Location then
783 return False;
784 end if;
786 return Get_Code_Unit (N1) = Get_Code_Unit (N2);
787 end In_Same_Code_Unit;
789 ---------------------------
790 -- In_Same_Extended_Unit --
791 ---------------------------
793 function In_Same_Extended_Unit
794 (N1, N2 : Node_Or_Entity_Id) return Boolean
796 begin
797 return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
798 end In_Same_Extended_Unit;
800 function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
801 begin
802 return Check_Same_Extended_Unit (S1, S2) /= No;
803 end In_Same_Extended_Unit;
805 -------------------------
806 -- In_Same_Source_Unit --
807 -------------------------
809 function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
810 S1 : constant Source_Ptr := Sloc (N1);
811 S2 : constant Source_Ptr := Sloc (N2);
813 begin
814 if S1 = No_Location or else S2 = No_Location then
815 return False;
817 elsif S1 = Standard_Location then
818 return S2 = Standard_Location;
820 elsif S2 = Standard_Location then
821 return False;
822 end if;
824 return Get_Source_Unit (N1) = Get_Source_Unit (N2);
825 end In_Same_Source_Unit;
827 -----------------------------
828 -- Increment_Serial_Number --
829 -----------------------------
831 function Increment_Serial_Number return Nat is
832 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
833 begin
834 TSN := TSN + 1;
835 return TSN;
836 end Increment_Serial_Number;
838 ----------------
839 -- Initialize --
840 ----------------
842 procedure Initialize is
843 begin
844 Linker_Option_Lines.Init;
845 Load_Stack.Init;
846 Units.Init;
847 Compilation_Switches.Init;
848 end Initialize;
850 ---------------
851 -- Is_Loaded --
852 ---------------
854 function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
855 begin
856 for Unum in Units.First .. Units.Last loop
857 if Uname = Unit_Name (Unum) then
858 return True;
859 end if;
860 end loop;
862 return False;
863 end Is_Loaded;
865 ---------------
866 -- Last_Unit --
867 ---------------
869 function Last_Unit return Unit_Number_Type is
870 begin
871 return Units.Last;
872 end Last_Unit;
874 ----------
875 -- List --
876 ----------
878 procedure List (File_Names_Only : Boolean := False) is separate;
880 ----------
881 -- Lock --
882 ----------
884 procedure Lock is
885 begin
886 Linker_Option_Lines.Locked := True;
887 Load_Stack.Locked := True;
888 Units.Locked := True;
889 Linker_Option_Lines.Release;
890 Load_Stack.Release;
891 Units.Release;
892 end Lock;
894 ---------------
895 -- Num_Units --
896 ---------------
898 function Num_Units return Nat is
899 begin
900 return Int (Units.Last) - Int (Main_Unit) + 1;
901 end Num_Units;
903 -----------------
904 -- Remove_Unit --
905 -----------------
907 procedure Remove_Unit (U : Unit_Number_Type) is
908 begin
909 if U = Units.Last then
910 Units.Decrement_Last;
911 end if;
912 end Remove_Unit;
914 ----------------------------------
915 -- Replace_Linker_Option_String --
916 ----------------------------------
918 procedure Replace_Linker_Option_String
919 (S : String_Id; Match_String : String)
921 begin
922 if Match_String'Length > 0 then
923 for J in 1 .. Linker_Option_Lines.Last loop
924 String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
926 if Match_String = Name_Buffer (1 .. Match_String'Length) then
927 Linker_Option_Lines.Table (J).Option := S;
928 return;
929 end if;
930 end loop;
931 end if;
933 Store_Linker_Option_String (S);
934 end Replace_Linker_Option_String;
936 ----------
937 -- Sort --
938 ----------
940 procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
942 ------------------------------
943 -- Store_Compilation_Switch --
944 ------------------------------
946 procedure Store_Compilation_Switch (Switch : String) is
947 begin
948 if Switch_Storing_Enabled then
949 Compilation_Switches.Increment_Last;
950 Compilation_Switches.Table (Compilation_Switches.Last) :=
951 new String'(Switch);
953 -- Fix up --RTS flag which has been transformed by the gcc driver
954 -- into -fRTS
956 if Switch'Last >= Switch'First + 4
957 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
958 then
959 Compilation_Switches.Table
960 (Compilation_Switches.Last) (Switch'First + 1) := '-';
961 end if;
962 end if;
963 end Store_Compilation_Switch;
965 --------------------------------
966 -- Store_Linker_Option_String --
967 --------------------------------
969 procedure Store_Linker_Option_String (S : String_Id) is
970 begin
971 Linker_Option_Lines.Increment_Last;
972 Linker_Option_Lines.Table (Linker_Option_Lines.Last) :=
973 (Option => S, Unit => Current_Sem_Unit);
974 end Store_Linker_Option_String;
976 -------------------------------
977 -- Synchronize_Serial_Number --
978 -------------------------------
980 procedure Synchronize_Serial_Number is
981 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
982 begin
983 TSN := TSN + 1;
984 end Synchronize_Serial_Number;
986 ---------------
987 -- Tree_Read --
988 ---------------
990 procedure Tree_Read is
991 N : Nat;
992 S : String_Ptr;
994 begin
995 Units.Tree_Read;
997 -- Read Compilation_Switches table
999 Tree_Read_Int (N);
1000 Compilation_Switches.Set_Last (N);
1002 for J in 1 .. N loop
1003 Tree_Read_Str (S);
1004 Compilation_Switches.Table (J) := S;
1005 end loop;
1006 end Tree_Read;
1008 ----------------
1009 -- Tree_Write --
1010 ----------------
1012 procedure Tree_Write is
1013 begin
1014 Units.Tree_Write;
1016 -- Write Compilation_Switches table
1018 Tree_Write_Int (Compilation_Switches.Last);
1020 for J in 1 .. Compilation_Switches.Last loop
1021 Tree_Write_Str (Compilation_Switches.Table (J));
1022 end loop;
1023 end Tree_Write;
1025 -----------------
1026 -- Version_Get --
1027 -----------------
1029 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1030 begin
1031 return Get_Hex_String (Units.Table (U).Version);
1032 end Version_Get;
1034 ------------------------
1035 -- Version_Referenced --
1036 ------------------------
1038 procedure Version_Referenced (S : String_Id) is
1039 begin
1040 Version_Ref.Append (S);
1041 end Version_Referenced;
1043 end Lib;