* config/mips/mips.c (function_arg): Where one part of a
[official-gcc.git] / gcc / ada / lib.adb
blob420f9693b3d9df903159ccb172a76b469fa15b7d
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_Same_Code_Unit --
753 -----------------------
755 function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
756 S1 : constant Source_Ptr := Sloc (N1);
757 S2 : constant Source_Ptr := Sloc (N2);
759 begin
760 if S1 = No_Location or else S2 = No_Location then
761 return False;
763 elsif S1 = Standard_Location then
764 return S2 = Standard_Location;
766 elsif S2 = Standard_Location then
767 return False;
768 end if;
770 return Get_Code_Unit (N1) = Get_Code_Unit (N2);
771 end In_Same_Code_Unit;
773 ---------------------------
774 -- In_Same_Extended_Unit --
775 ---------------------------
777 function In_Same_Extended_Unit
778 (N1, N2 : Node_Or_Entity_Id) return Boolean
780 begin
781 return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
782 end In_Same_Extended_Unit;
784 function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
785 begin
786 return Check_Same_Extended_Unit (S1, S2) /= No;
787 end In_Same_Extended_Unit;
789 -------------------------
790 -- In_Same_Source_Unit --
791 -------------------------
793 function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
794 S1 : constant Source_Ptr := Sloc (N1);
795 S2 : constant Source_Ptr := Sloc (N2);
797 begin
798 if S1 = No_Location or else S2 = No_Location then
799 return False;
801 elsif S1 = Standard_Location then
802 return S2 = Standard_Location;
804 elsif S2 = Standard_Location then
805 return False;
806 end if;
808 return Get_Source_Unit (N1) = Get_Source_Unit (N2);
809 end In_Same_Source_Unit;
811 -----------------------------
812 -- Increment_Serial_Number --
813 -----------------------------
815 function Increment_Serial_Number return Nat is
816 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
817 begin
818 TSN := TSN + 1;
819 return TSN;
820 end Increment_Serial_Number;
822 ----------------
823 -- Initialize --
824 ----------------
826 procedure Initialize is
827 begin
828 Linker_Option_Lines.Init;
829 Load_Stack.Init;
830 Units.Init;
831 Compilation_Switches.Init;
832 end Initialize;
834 ---------------
835 -- Is_Loaded --
836 ---------------
838 function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
839 begin
840 for Unum in Units.First .. Units.Last loop
841 if Uname = Unit_Name (Unum) then
842 return True;
843 end if;
844 end loop;
846 return False;
847 end Is_Loaded;
849 ---------------
850 -- Last_Unit --
851 ---------------
853 function Last_Unit return Unit_Number_Type is
854 begin
855 return Units.Last;
856 end Last_Unit;
858 ----------
859 -- List --
860 ----------
862 procedure List (File_Names_Only : Boolean := False) is separate;
864 ----------
865 -- Lock --
866 ----------
868 procedure Lock is
869 begin
870 Linker_Option_Lines.Locked := True;
871 Load_Stack.Locked := True;
872 Units.Locked := True;
873 Linker_Option_Lines.Release;
874 Load_Stack.Release;
875 Units.Release;
876 end Lock;
878 ---------------
879 -- Num_Units --
880 ---------------
882 function Num_Units return Nat is
883 begin
884 return Int (Units.Last) - Int (Main_Unit) + 1;
885 end Num_Units;
887 -----------------
888 -- Remove_Unit --
889 -----------------
891 procedure Remove_Unit (U : Unit_Number_Type) is
892 begin
893 if U = Units.Last then
894 Units.Decrement_Last;
895 end if;
896 end Remove_Unit;
898 ----------------------------------
899 -- Replace_Linker_Option_String --
900 ----------------------------------
902 procedure Replace_Linker_Option_String
903 (S : String_Id; Match_String : String)
905 begin
906 if Match_String'Length > 0 then
907 for J in 1 .. Linker_Option_Lines.Last loop
908 String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
910 if Match_String = Name_Buffer (1 .. Match_String'Length) then
911 Linker_Option_Lines.Table (J).Option := S;
912 return;
913 end if;
914 end loop;
915 end if;
917 Store_Linker_Option_String (S);
918 end Replace_Linker_Option_String;
920 ----------
921 -- Sort --
922 ----------
924 procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
926 ------------------------------
927 -- Store_Compilation_Switch --
928 ------------------------------
930 procedure Store_Compilation_Switch (Switch : String) is
931 begin
932 if Switch_Storing_Enabled then
933 Compilation_Switches.Increment_Last;
934 Compilation_Switches.Table (Compilation_Switches.Last) :=
935 new String'(Switch);
937 -- Fix up --RTS flag which has been transformed by the gcc driver
938 -- into -fRTS
940 if Switch'Last >= Switch'First + 4
941 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
942 then
943 Compilation_Switches.Table
944 (Compilation_Switches.Last) (Switch'First + 1) := '-';
945 end if;
946 end if;
947 end Store_Compilation_Switch;
949 --------------------------------
950 -- Store_Linker_Option_String --
951 --------------------------------
953 procedure Store_Linker_Option_String (S : String_Id) is
954 begin
955 Linker_Option_Lines.Increment_Last;
956 Linker_Option_Lines.Table (Linker_Option_Lines.Last) :=
957 (Option => S, Unit => Current_Sem_Unit);
958 end Store_Linker_Option_String;
960 -------------------------------
961 -- Synchronize_Serial_Number --
962 -------------------------------
964 procedure Synchronize_Serial_Number is
965 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
966 begin
967 TSN := TSN + 1;
968 end Synchronize_Serial_Number;
970 ---------------
971 -- Tree_Read --
972 ---------------
974 procedure Tree_Read is
975 N : Nat;
976 S : String_Ptr;
978 begin
979 Units.Tree_Read;
981 -- Read Compilation_Switches table
983 Tree_Read_Int (N);
984 Compilation_Switches.Set_Last (N);
986 for J in 1 .. N loop
987 Tree_Read_Str (S);
988 Compilation_Switches.Table (J) := S;
989 end loop;
990 end Tree_Read;
992 ----------------
993 -- Tree_Write --
994 ----------------
996 procedure Tree_Write is
997 begin
998 Units.Tree_Write;
1000 -- Write Compilation_Switches table
1002 Tree_Write_Int (Compilation_Switches.Last);
1004 for J in 1 .. Compilation_Switches.Last loop
1005 Tree_Write_Str (Compilation_Switches.Table (J));
1006 end loop;
1007 end Tree_Write;
1009 -----------------
1010 -- Version_Get --
1011 -----------------
1013 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1014 begin
1015 return Get_Hex_String (Units.Table (U).Version);
1016 end Version_Get;
1018 ------------------------
1019 -- Version_Referenced --
1020 ------------------------
1022 procedure Version_Referenced (S : String_Id) is
1023 begin
1024 Version_Ref.Append (S);
1025 end Version_Referenced;
1027 end Lib;