Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / ada / lib.adb
blob893c4cfbbb22ae6f5ef87684b0865bfb8d1f8019
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- L I B --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2010, 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 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. --
17 -- --
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. --
21 -- --
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/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
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 Einfo; use Einfo;
38 with Fname; use Fname;
39 with Output; use Output;
40 with Sinfo; use Sinfo;
41 with Sinput; use Sinput;
42 with Stand; use Stand;
43 with Stringt; use Stringt;
44 with Tree_IO; use Tree_IO;
45 with Uname; use Uname;
47 package body Lib is
49 Switch_Storing_Enabled : Boolean := True;
50 -- Controlled by Enable_Switch_Storing/Disable_Switch_Storing
52 -----------------------
53 -- Local Subprograms --
54 -----------------------
56 type SEU_Result is (
57 Yes_Before, -- S1 is in same extended unit as S2 and appears before it
58 Yes_Same, -- S1 is in same extended unit as S2, Slocs are the same
59 Yes_After, -- S1 is in same extended unit as S2, and appears after it
60 No); -- S2 is not in same extended unit as S2
62 function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result;
63 -- Used by In_Same_Extended_Unit and Earlier_In_Extended_Unit. Returns
64 -- value as described above.
66 function Get_Code_Or_Source_Unit
67 (S : Source_Ptr;
68 Unwind_Instances : Boolean) return Unit_Number_Type;
69 -- Common code for Get_Code_Unit (get unit of instantiation for location)
70 -- and Get_Source_Unit (get unit of template for location).
72 --------------------------------------------
73 -- Access Functions for Unit Table Fields --
74 --------------------------------------------
76 function Cunit (U : Unit_Number_Type) return Node_Id is
77 begin
78 return Units.Table (U).Cunit;
79 end Cunit;
81 function Cunit_Entity (U : Unit_Number_Type) return Entity_Id is
82 begin
83 return Units.Table (U).Cunit_Entity;
84 end Cunit_Entity;
86 function Dependency_Num (U : Unit_Number_Type) return Nat is
87 begin
88 return Units.Table (U).Dependency_Num;
89 end Dependency_Num;
91 function Dynamic_Elab (U : Unit_Number_Type) return Boolean is
92 begin
93 return Units.Table (U).Dynamic_Elab;
94 end Dynamic_Elab;
96 function Error_Location (U : Unit_Number_Type) return Source_Ptr is
97 begin
98 return Units.Table (U).Error_Location;
99 end Error_Location;
101 function Expected_Unit (U : Unit_Number_Type) return Unit_Name_Type is
102 begin
103 return Units.Table (U).Expected_Unit;
104 end Expected_Unit;
106 function Fatal_Error (U : Unit_Number_Type) return Boolean is
107 begin
108 return Units.Table (U).Fatal_Error;
109 end Fatal_Error;
111 function Generate_Code (U : Unit_Number_Type) return Boolean is
112 begin
113 return Units.Table (U).Generate_Code;
114 end Generate_Code;
116 function Has_RACW (U : Unit_Number_Type) return Boolean is
117 begin
118 return Units.Table (U).Has_RACW;
119 end Has_RACW;
121 function Is_Compiler_Unit (U : Unit_Number_Type) return Boolean is
122 begin
123 return Units.Table (U).Is_Compiler_Unit;
124 end Is_Compiler_Unit;
126 function Ident_String (U : Unit_Number_Type) return Node_Id is
127 begin
128 return Units.Table (U).Ident_String;
129 end Ident_String;
131 function Loading (U : Unit_Number_Type) return Boolean is
132 begin
133 return Units.Table (U).Loading;
134 end Loading;
136 function Main_Priority (U : Unit_Number_Type) return Int is
137 begin
138 return Units.Table (U).Main_Priority;
139 end Main_Priority;
141 function Munit_Index (U : Unit_Number_Type) return Nat is
142 begin
143 return Units.Table (U).Munit_Index;
144 end Munit_Index;
146 function OA_Setting (U : Unit_Number_Type) return Character is
147 begin
148 return Units.Table (U).OA_Setting;
149 end OA_Setting;
151 function Source_Index (U : Unit_Number_Type) return Source_File_Index is
152 begin
153 return Units.Table (U).Source_Index;
154 end Source_Index;
156 function Unit_File_Name (U : Unit_Number_Type) return File_Name_Type is
157 begin
158 return Units.Table (U).Unit_File_Name;
159 end Unit_File_Name;
161 function Unit_Name (U : Unit_Number_Type) return Unit_Name_Type is
162 begin
163 return Units.Table (U).Unit_Name;
164 end Unit_Name;
166 ------------------------------------------
167 -- Subprograms to Set Unit Table Fields --
168 ------------------------------------------
170 procedure Set_Cunit (U : Unit_Number_Type; N : Node_Id) is
171 begin
172 Units.Table (U).Cunit := N;
173 end Set_Cunit;
175 procedure Set_Cunit_Entity (U : Unit_Number_Type; E : Entity_Id) is
176 begin
177 Units.Table (U).Cunit_Entity := E;
178 Set_Is_Compilation_Unit (E);
179 end Set_Cunit_Entity;
181 procedure Set_Dynamic_Elab (U : Unit_Number_Type; B : Boolean := True) is
182 begin
183 Units.Table (U).Dynamic_Elab := B;
184 end Set_Dynamic_Elab;
186 procedure Set_Error_Location (U : Unit_Number_Type; W : Source_Ptr) is
187 begin
188 Units.Table (U).Error_Location := W;
189 end Set_Error_Location;
191 procedure Set_Fatal_Error (U : Unit_Number_Type; B : Boolean := True) is
192 begin
193 Units.Table (U).Fatal_Error := B;
194 end Set_Fatal_Error;
196 procedure Set_Generate_Code (U : Unit_Number_Type; B : Boolean := True) is
197 begin
198 Units.Table (U).Generate_Code := B;
199 end Set_Generate_Code;
201 procedure Set_Has_RACW (U : Unit_Number_Type; B : Boolean := True) is
202 begin
203 Units.Table (U).Has_RACW := B;
204 end Set_Has_RACW;
206 procedure Set_Is_Compiler_Unit
207 (U : Unit_Number_Type;
208 B : Boolean := True)
210 begin
211 Units.Table (U).Is_Compiler_Unit := B;
212 end Set_Is_Compiler_Unit;
214 procedure Set_Ident_String (U : Unit_Number_Type; N : Node_Id) is
215 begin
216 Units.Table (U).Ident_String := N;
217 end Set_Ident_String;
219 procedure Set_Loading (U : Unit_Number_Type; B : Boolean := True) is
220 begin
221 Units.Table (U).Loading := B;
222 end Set_Loading;
224 procedure Set_Main_Priority (U : Unit_Number_Type; P : Int) is
225 begin
226 Units.Table (U).Main_Priority := P;
227 end Set_Main_Priority;
229 procedure Set_OA_Setting (U : Unit_Number_Type; C : Character) is
230 begin
231 Units.Table (U).OA_Setting := C;
232 end Set_OA_Setting;
234 procedure Set_Unit_Name (U : Unit_Number_Type; N : Unit_Name_Type) is
235 begin
236 Units.Table (U).Unit_Name := N;
237 end Set_Unit_Name;
239 ------------------------------
240 -- Check_Same_Extended_Unit --
241 ------------------------------
243 function Check_Same_Extended_Unit (S1, S2 : Source_Ptr) return SEU_Result is
244 Sloc1 : Source_Ptr;
245 Sloc2 : Source_Ptr;
246 Sind1 : Source_File_Index;
247 Sind2 : Source_File_Index;
248 Inst1 : Source_Ptr;
249 Inst2 : Source_Ptr;
250 Unum1 : Unit_Number_Type;
251 Unum2 : Unit_Number_Type;
252 Unit1 : Node_Id;
253 Unit2 : Node_Id;
254 Depth1 : Nat;
255 Depth2 : Nat;
257 begin
258 if S1 = No_Location or else S2 = No_Location then
259 return No;
261 elsif S1 = Standard_Location then
262 if S2 = Standard_Location then
263 return Yes_Same;
264 else
265 return No;
266 end if;
268 elsif S2 = Standard_Location then
269 return No;
270 end if;
272 Sloc1 := S1;
273 Sloc2 := S2;
274 Unum1 := Get_Code_Unit (Sloc1);
275 Unum2 := Get_Code_Unit (Sloc2);
277 loop
278 Sind1 := Get_Source_File_Index (Sloc1);
279 Sind2 := Get_Source_File_Index (Sloc2);
281 if Sind1 = Sind2 then
282 if Sloc1 < Sloc2 then
283 return Yes_Before;
284 elsif Sloc1 > Sloc2 then
285 return Yes_After;
286 else
287 return Yes_Same;
288 end if;
289 end if;
291 -- OK, the two nodes are in separate source elements, but this is not
292 -- decisive, because of the issue of subunits and instantiations.
294 -- First we deal with subunits, since if the subunit is in an
295 -- instantiation, we know that the parent is in the corresponding
296 -- instantiation, since that is the only way we can have a subunit
297 -- that is part of an instantiation.
299 Unit1 := Unit (Cunit (Unum1));
300 Unit2 := Unit (Cunit (Unum2));
302 if Nkind (Unit1) = N_Subunit
303 and then Present (Corresponding_Stub (Unit1))
304 then
305 -- Both in subunits. They could have a common ancestor. If they
306 -- do, then the deeper one must have a longer unit name. Replace
307 -- the deeper one with its corresponding stub, in order to find
308 -- nearest common ancestor, if any.
310 if Nkind (Unit2) = N_Subunit
311 and then Present (Corresponding_Stub (Unit2))
312 then
313 if Length_Of_Name (Unit_Name (Unum1)) <
314 Length_Of_Name (Unit_Name (Unum2))
315 then
316 Sloc2 := Sloc (Corresponding_Stub (Unit2));
317 Unum2 := Get_Source_Unit (Sloc2);
318 goto Continue;
320 else
321 Sloc1 := Sloc (Corresponding_Stub (Unit1));
322 Unum1 := Get_Source_Unit (Sloc1);
323 goto Continue;
324 end if;
326 -- Nod1 in subunit, Nod2 not
328 else
329 Sloc1 := Sloc (Corresponding_Stub (Unit1));
330 Unum1 := Get_Source_Unit (Sloc1);
331 goto Continue;
332 end if;
334 -- Nod2 in subunit, Nod1 not
336 elsif Nkind (Unit2) = N_Subunit
337 and then Present (Corresponding_Stub (Unit2))
338 then
339 Sloc2 := Sloc (Corresponding_Stub (Unit2));
340 Unum2 := Get_Source_Unit (Sloc2);
341 goto Continue;
342 end if;
344 -- At this stage we know that neither is a subunit, so we deal
345 -- with instantiations, since we could have a common ancestor
347 Inst1 := Instantiation (Sind1);
348 Inst2 := Instantiation (Sind2);
350 if Inst1 /= No_Location then
352 -- Both are instantiations
354 if Inst2 /= No_Location then
356 Depth1 := Instantiation_Depth (Sloc1);
357 Depth2 := Instantiation_Depth (Sloc2);
359 if Depth1 < Depth2 then
360 Sloc2 := Inst2;
361 Unum2 := Get_Source_Unit (Sloc2);
362 goto Continue;
364 elsif Depth1 > Depth2 then
365 Sloc1 := Inst1;
366 Unum1 := Get_Source_Unit (Sloc1);
367 goto Continue;
369 else
370 Sloc1 := Inst1;
371 Sloc2 := Inst2;
372 Unum1 := Get_Source_Unit (Sloc1);
373 Unum2 := Get_Source_Unit (Sloc2);
374 goto Continue;
375 end if;
377 -- Only first node is in instantiation
379 else
380 Sloc1 := Inst1;
381 Unum1 := Get_Source_Unit (Sloc1);
382 goto Continue;
383 end if;
385 -- Only second node is instantiation
387 elsif Inst2 /= No_Location then
388 Sloc2 := Inst2;
389 Unum2 := Get_Source_Unit (Sloc2);
390 goto Continue;
391 end if;
393 -- No instantiations involved, so we are not in the same unit
394 -- However, there is one case still to check, namely the case
395 -- where one location is in the spec, and the other in the
396 -- corresponding body (the spec location is earlier).
398 if Nkind (Unit1) = N_Subprogram_Body
399 or else
400 Nkind (Unit1) = N_Package_Body
401 then
402 if Library_Unit (Cunit (Unum1)) = Cunit (Unum2) then
403 return Yes_After;
404 end if;
406 elsif Nkind (Unit2) = N_Subprogram_Body
407 or else
408 Nkind (Unit2) = N_Package_Body
409 then
410 if Library_Unit (Cunit (Unum2)) = Cunit (Unum1) then
411 return Yes_Before;
412 end if;
413 end if;
415 -- If that special case does not occur, then we are certain that
416 -- the two locations are really in separate units.
418 return No;
420 <<Continue>>
421 null;
422 end loop;
423 end Check_Same_Extended_Unit;
425 -------------------------------
426 -- Compilation_Switches_Last --
427 -------------------------------
429 function Compilation_Switches_Last return Nat is
430 begin
431 return Compilation_Switches.Last;
432 end Compilation_Switches_Last;
434 ---------------------------
435 -- Enable_Switch_Storing --
436 ---------------------------
438 procedure Enable_Switch_Storing is
439 begin
440 Switch_Storing_Enabled := True;
441 end Enable_Switch_Storing;
443 ----------------------------
444 -- Disable_Switch_Storing --
445 ----------------------------
447 procedure Disable_Switch_Storing is
448 begin
449 Switch_Storing_Enabled := False;
450 end Disable_Switch_Storing;
452 ------------------------------
453 -- Earlier_In_Extended_Unit --
454 ------------------------------
456 function Earlier_In_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
457 begin
458 return Check_Same_Extended_Unit (S1, S2) = Yes_Before;
459 end Earlier_In_Extended_Unit;
461 ----------------------------
462 -- Entity_Is_In_Main_Unit --
463 ----------------------------
465 function Entity_Is_In_Main_Unit (E : Entity_Id) return Boolean is
466 S : Entity_Id;
468 begin
469 S := Scope (E);
471 while S /= Standard_Standard loop
472 if S = Main_Unit_Entity then
473 return True;
474 elsif Ekind (S) = E_Package and then Is_Child_Unit (S) then
475 return False;
476 else
477 S := Scope (S);
478 end if;
479 end loop;
481 return False;
482 end Entity_Is_In_Main_Unit;
484 --------------------------
485 -- Generic_May_Lack_ALI --
486 --------------------------
488 function Generic_May_Lack_ALI (Sfile : File_Name_Type) return Boolean is
489 begin
490 -- We allow internal generic units to be used without having a
491 -- corresponding ALI files to help bootstrapping with older compilers
492 -- that did not support generating ALIs for such generics. It is safe
493 -- to do so because the only thing the generated code would contain
494 -- is the elaboration boolean, and we are careful to elaborate all
495 -- predefined units first anyway.
497 return Is_Internal_File_Name
498 (Fname => Sfile,
499 Renamings_Included => True);
500 end Generic_May_Lack_ALI;
502 -----------------------------
503 -- Get_Code_Or_Source_Unit --
504 -----------------------------
506 function Get_Code_Or_Source_Unit
507 (S : Source_Ptr;
508 Unwind_Instances : Boolean) return Unit_Number_Type
510 begin
511 -- Search table unless we have No_Location, which can happen if the
512 -- relevant location has not been set yet. Happens for example when
513 -- we obtain Sloc (Cunit (Main_Unit)) before it is set.
515 if S /= No_Location then
516 declare
517 Source_File : Source_File_Index;
518 Source_Unit : Unit_Number_Type;
520 begin
521 Source_File := Get_Source_File_Index (S);
523 if Unwind_Instances then
524 while Template (Source_File) /= No_Source_File loop
525 Source_File := Template (Source_File);
526 end loop;
527 end if;
529 Source_Unit := Unit (Source_File);
531 if Source_Unit /= No_Unit then
532 return Source_Unit;
533 end if;
534 end;
535 end if;
537 -- If S was No_Location, or was not in the table, we must be in the main
538 -- source unit (and the value has not been placed in the table yet),
539 -- or in one of the configuration pragma files.
541 return Main_Unit;
542 end Get_Code_Or_Source_Unit;
544 -------------------
545 -- Get_Code_Unit --
546 -------------------
548 function Get_Code_Unit (S : Source_Ptr) return Unit_Number_Type is
549 begin
550 return Get_Code_Or_Source_Unit (Top_Level_Location (S),
551 Unwind_Instances => False);
552 end Get_Code_Unit;
554 function Get_Code_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
555 begin
556 return Get_Code_Unit (Sloc (N));
557 end Get_Code_Unit;
559 ----------------------------
560 -- Get_Compilation_Switch --
561 ----------------------------
563 function Get_Compilation_Switch (N : Pos) return String_Ptr is
564 begin
565 if N <= Compilation_Switches.Last then
566 return Compilation_Switches.Table (N);
568 else
569 return null;
570 end if;
571 end Get_Compilation_Switch;
573 ----------------------------------
574 -- Get_Cunit_Entity_Unit_Number --
575 ----------------------------------
577 function Get_Cunit_Entity_Unit_Number
578 (E : Entity_Id) return Unit_Number_Type
580 begin
581 for U in Units.First .. Units.Last loop
582 if Cunit_Entity (U) = E then
583 return U;
584 end if;
585 end loop;
587 -- If not in the table, must be the main source unit, and we just
588 -- have not got it put into the table yet.
590 return Main_Unit;
591 end Get_Cunit_Entity_Unit_Number;
593 ---------------------------
594 -- Get_Cunit_Unit_Number --
595 ---------------------------
597 function Get_Cunit_Unit_Number (N : Node_Id) return Unit_Number_Type is
598 begin
599 for U in Units.First .. Units.Last loop
600 if Cunit (U) = N then
601 return U;
602 end if;
603 end loop;
605 -- If not in the table, must be a spec created for a main unit that is a
606 -- child subprogram body which we have not inserted into the table yet.
608 if N = Library_Unit (Cunit (Main_Unit)) then
609 return Main_Unit;
611 -- If it is anything else, something is seriously wrong, and we really
612 -- don't want to proceed, even if assertions are off, so we explicitly
613 -- raise an exception in this case to terminate compilation.
615 else
616 raise Program_Error;
617 end if;
618 end Get_Cunit_Unit_Number;
620 ---------------------
621 -- Get_Source_Unit --
622 ---------------------
624 function Get_Source_Unit (S : Source_Ptr) return Unit_Number_Type is
625 begin
626 return Get_Code_Or_Source_Unit (S, Unwind_Instances => True);
627 end Get_Source_Unit;
629 function Get_Source_Unit (N : Node_Or_Entity_Id) return Unit_Number_Type is
630 begin
631 return Get_Source_Unit (Sloc (N));
632 end Get_Source_Unit;
634 --------------------------------
635 -- In_Extended_Main_Code_Unit --
636 --------------------------------
638 function In_Extended_Main_Code_Unit
639 (N : Node_Or_Entity_Id) return Boolean
641 begin
642 if Sloc (N) = Standard_Location then
643 return True;
645 elsif Sloc (N) = No_Location then
646 return False;
648 -- Special case Itypes to test the Sloc of the associated node. The
649 -- reason we do this is for possible calls from gigi after -gnatD
650 -- processing is complete in sprint. This processing updates the
651 -- sloc fields of all nodes in the tree, but itypes are not in the
652 -- tree so their slocs do not get updated.
654 elsif Nkind (N) = N_Defining_Identifier
655 and then Is_Itype (N)
656 then
657 return In_Extended_Main_Code_Unit (Associated_Node_For_Itype (N));
659 -- Otherwise see if we are in the main unit
661 elsif Get_Code_Unit (Sloc (N)) = Get_Code_Unit (Cunit (Main_Unit)) then
662 return True;
664 -- Node may be in spec (or subunit etc) of main unit
666 else
667 return
668 In_Same_Extended_Unit (N, Cunit (Main_Unit));
669 end if;
670 end In_Extended_Main_Code_Unit;
672 function In_Extended_Main_Code_Unit (Loc : Source_Ptr) return Boolean is
673 begin
674 if Loc = Standard_Location then
675 return True;
677 elsif Loc = No_Location then
678 return False;
680 -- Otherwise see if we are in the main unit
682 elsif Get_Code_Unit (Loc) = Get_Code_Unit (Cunit (Main_Unit)) then
683 return True;
685 -- Location may be in spec (or subunit etc) of main unit
687 else
688 return
689 In_Same_Extended_Unit (Loc, Sloc (Cunit (Main_Unit)));
690 end if;
691 end In_Extended_Main_Code_Unit;
693 ----------------------------------
694 -- In_Extended_Main_Source_Unit --
695 ----------------------------------
697 function In_Extended_Main_Source_Unit
698 (N : Node_Or_Entity_Id) return Boolean
700 Nloc : constant Source_Ptr := Sloc (N);
701 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
703 begin
704 -- If parsing, then use the global flag to indicate result
706 if Compiler_State = Parsing then
707 return Parsing_Main_Extended_Source;
709 -- Special value cases
711 elsif Nloc = Standard_Location then
712 return True;
714 elsif Nloc = No_Location then
715 return False;
717 -- Special case Itypes to test the Sloc of the associated node. The
718 -- reason we do this is for possible calls from gigi after -gnatD
719 -- processing is complete in sprint. This processing updates the
720 -- sloc fields of all nodes in the tree, but itypes are not in the
721 -- tree so their slocs do not get updated.
723 elsif Nkind (N) = N_Defining_Identifier
724 and then Is_Itype (N)
725 then
726 return In_Extended_Main_Source_Unit (Associated_Node_For_Itype (N));
728 -- Otherwise compare original locations to see if in same unit
730 else
731 return
732 In_Same_Extended_Unit
733 (Original_Location (Nloc), Original_Location (Mloc));
734 end if;
735 end In_Extended_Main_Source_Unit;
737 function In_Extended_Main_Source_Unit
738 (Loc : Source_Ptr) return Boolean
740 Mloc : constant Source_Ptr := Sloc (Cunit (Main_Unit));
742 begin
743 -- If parsing, then use the global flag to indicate result
745 if Compiler_State = Parsing then
746 return Parsing_Main_Extended_Source;
748 -- Special value cases
750 elsif Loc = Standard_Location then
751 return True;
753 elsif Loc = No_Location then
754 return False;
756 -- Otherwise compare original locations to see if in same unit
758 else
759 return
760 In_Same_Extended_Unit
761 (Original_Location (Loc), Original_Location (Mloc));
762 end if;
763 end In_Extended_Main_Source_Unit;
765 ------------------------
766 -- In_Predefined_Unit --
767 ------------------------
769 function In_Predefined_Unit (N : Node_Or_Entity_Id) return Boolean is
770 begin
771 return In_Predefined_Unit (Sloc (N));
772 end In_Predefined_Unit;
774 function In_Predefined_Unit (S : Source_Ptr) return Boolean is
775 Unit : constant Unit_Number_Type := Get_Source_Unit (S);
776 File : constant File_Name_Type := Unit_File_Name (Unit);
777 begin
778 return Is_Predefined_File_Name (File);
779 end In_Predefined_Unit;
781 -----------------------
782 -- In_Same_Code_Unit --
783 -----------------------
785 function In_Same_Code_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
786 S1 : constant Source_Ptr := Sloc (N1);
787 S2 : constant Source_Ptr := Sloc (N2);
789 begin
790 if S1 = No_Location or else S2 = No_Location then
791 return False;
793 elsif S1 = Standard_Location then
794 return S2 = Standard_Location;
796 elsif S2 = Standard_Location then
797 return False;
798 end if;
800 return Get_Code_Unit (N1) = Get_Code_Unit (N2);
801 end In_Same_Code_Unit;
803 ---------------------------
804 -- In_Same_Extended_Unit --
805 ---------------------------
807 function In_Same_Extended_Unit
808 (N1, N2 : Node_Or_Entity_Id) return Boolean
810 begin
811 return Check_Same_Extended_Unit (Sloc (N1), Sloc (N2)) /= No;
812 end In_Same_Extended_Unit;
814 function In_Same_Extended_Unit (S1, S2 : Source_Ptr) return Boolean is
815 begin
816 return Check_Same_Extended_Unit (S1, S2) /= No;
817 end In_Same_Extended_Unit;
819 -------------------------
820 -- In_Same_Source_Unit --
821 -------------------------
823 function In_Same_Source_Unit (N1, N2 : Node_Or_Entity_Id) return Boolean is
824 S1 : constant Source_Ptr := Sloc (N1);
825 S2 : constant Source_Ptr := Sloc (N2);
827 begin
828 if S1 = No_Location or else S2 = No_Location then
829 return False;
831 elsif S1 = Standard_Location then
832 return S2 = Standard_Location;
834 elsif S2 = Standard_Location then
835 return False;
836 end if;
838 return Get_Source_Unit (N1) = Get_Source_Unit (N2);
839 end In_Same_Source_Unit;
841 -----------------------------
842 -- Increment_Serial_Number --
843 -----------------------------
845 function Increment_Serial_Number return Nat is
846 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
847 begin
848 TSN := TSN + 1;
849 return TSN;
850 end Increment_Serial_Number;
852 ----------------
853 -- Initialize --
854 ----------------
856 procedure Initialize is
857 begin
858 Linker_Option_Lines.Init;
859 Notes.Init;
860 Load_Stack.Init;
861 Units.Init;
862 Compilation_Switches.Init;
863 end Initialize;
865 ---------------
866 -- Is_Loaded --
867 ---------------
869 function Is_Loaded (Uname : Unit_Name_Type) return Boolean is
870 begin
871 for Unum in Units.First .. Units.Last loop
872 if Uname = Unit_Name (Unum) then
873 return True;
874 end if;
875 end loop;
877 return False;
878 end Is_Loaded;
880 ---------------
881 -- Last_Unit --
882 ---------------
884 function Last_Unit return Unit_Number_Type is
885 begin
886 return Units.Last;
887 end Last_Unit;
889 ----------
890 -- List --
891 ----------
893 procedure List (File_Names_Only : Boolean := False) is separate;
895 ----------
896 -- Lock --
897 ----------
899 procedure Lock is
900 begin
901 Linker_Option_Lines.Locked := True;
902 Load_Stack.Locked := True;
903 Units.Locked := True;
904 Linker_Option_Lines.Release;
905 Load_Stack.Release;
906 Units.Release;
907 end Lock;
909 ---------------
910 -- Num_Units --
911 ---------------
913 function Num_Units return Nat is
914 begin
915 return Int (Units.Last) - Int (Main_Unit) + 1;
916 end Num_Units;
918 -----------------
919 -- Remove_Unit --
920 -----------------
922 procedure Remove_Unit (U : Unit_Number_Type) is
923 begin
924 if U = Units.Last then
925 Units.Decrement_Last;
926 end if;
927 end Remove_Unit;
929 ----------------------------------
930 -- Replace_Linker_Option_String --
931 ----------------------------------
933 procedure Replace_Linker_Option_String
934 (S : String_Id; Match_String : String)
936 begin
937 if Match_String'Length > 0 then
938 for J in 1 .. Linker_Option_Lines.Last loop
939 String_To_Name_Buffer (Linker_Option_Lines.Table (J).Option);
941 if Match_String = Name_Buffer (1 .. Match_String'Length) then
942 Linker_Option_Lines.Table (J).Option := S;
943 return;
944 end if;
945 end loop;
946 end if;
948 Store_Linker_Option_String (S);
949 end Replace_Linker_Option_String;
951 ----------
952 -- Sort --
953 ----------
955 procedure Sort (Tbl : in out Unit_Ref_Table) is separate;
957 ------------------------------
958 -- Store_Compilation_Switch --
959 ------------------------------
961 procedure Store_Compilation_Switch (Switch : String) is
962 begin
963 if Switch_Storing_Enabled then
964 Compilation_Switches.Increment_Last;
965 Compilation_Switches.Table (Compilation_Switches.Last) :=
966 new String'(Switch);
968 -- Fix up --RTS flag which has been transformed by the gcc driver
969 -- into -fRTS
971 if Switch'Last >= Switch'First + 4
972 and then Switch (Switch'First .. Switch'First + 4) = "-fRTS"
973 then
974 Compilation_Switches.Table
975 (Compilation_Switches.Last) (Switch'First + 1) := '-';
976 end if;
977 end if;
978 end Store_Compilation_Switch;
980 --------------------------------
981 -- Store_Linker_Option_String --
982 --------------------------------
984 procedure Store_Linker_Option_String (S : String_Id) is
985 begin
986 Linker_Option_Lines.Append ((Option => S, Unit => Current_Sem_Unit));
987 end Store_Linker_Option_String;
989 ----------------
990 -- Store_Note --
991 ----------------
993 procedure Store_Note (N : Node_Id) is
994 begin
995 Notes.Append ((Pragma_Node => N, Unit => Current_Sem_Unit));
996 end Store_Note;
998 -------------------------------
999 -- Synchronize_Serial_Number --
1000 -------------------------------
1002 procedure Synchronize_Serial_Number is
1003 TSN : Int renames Units.Table (Current_Sem_Unit).Serial_Number;
1004 begin
1005 TSN := TSN + 1;
1006 end Synchronize_Serial_Number;
1008 ---------------
1009 -- Tree_Read --
1010 ---------------
1012 procedure Tree_Read is
1013 N : Nat;
1014 S : String_Ptr;
1016 begin
1017 Units.Tree_Read;
1019 -- Read Compilation_Switches table. First release the memory occupied
1020 -- by the previously loaded switches.
1022 for J in Compilation_Switches.First .. Compilation_Switches.Last loop
1023 Free (Compilation_Switches.Table (J));
1024 end loop;
1026 Tree_Read_Int (N);
1027 Compilation_Switches.Set_Last (N);
1029 for J in 1 .. N loop
1030 Tree_Read_Str (S);
1031 Compilation_Switches.Table (J) := S;
1032 end loop;
1033 end Tree_Read;
1035 ----------------
1036 -- Tree_Write --
1037 ----------------
1039 procedure Tree_Write is
1040 begin
1041 Units.Tree_Write;
1043 -- Write Compilation_Switches table
1045 Tree_Write_Int (Compilation_Switches.Last);
1047 for J in 1 .. Compilation_Switches.Last loop
1048 Tree_Write_Str (Compilation_Switches.Table (J));
1049 end loop;
1050 end Tree_Write;
1052 ------------
1053 -- Unlock --
1054 ------------
1056 procedure Unlock is
1057 begin
1058 Linker_Option_Lines.Locked := False;
1059 Load_Stack.Locked := False;
1060 Units.Locked := False;
1061 end Unlock;
1063 -----------------
1064 -- Version_Get --
1065 -----------------
1067 function Version_Get (U : Unit_Number_Type) return Word_Hex_String is
1068 begin
1069 return Get_Hex_String (Units.Table (U).Version);
1070 end Version_Get;
1072 ------------------------
1073 -- Version_Referenced --
1074 ------------------------
1076 procedure Version_Referenced (S : String_Id) is
1077 begin
1078 Version_Ref.Append (S);
1079 end Version_Referenced;
1081 end Lib;