comparison gcc/ada/lib-writ.adb @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
4 -- -- 4 -- --
5 -- L I B . W R I T -- 5 -- L I B . W R I T --
6 -- -- 6 -- --
7 -- B o d y -- 7 -- B o d y --
8 -- -- 8 -- --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. -- 9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
10 -- -- 10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under -- 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- -- 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- -- 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- -- 14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
213 213
214 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean; 214 Elab_All_Des_Flags : array (Units.First .. Last_Unit) of Boolean;
215 -- Array of flags to show which units have Elaborate_All_Desirable set 215 -- Array of flags to show which units have Elaborate_All_Desirable set
216 216
217 type Yes_No is (Unknown, Yes, No); 217 type Yes_No is (Unknown, Yes, No);
218 Implicit_With : array (Units.First .. Last_Unit) of Yes_No; 218 Has_Implicit_With : array (Units.First .. Last_Unit) of Yes_No;
219 -- Indicates if an implicit with has been given for the unit. Yes if 219 -- Indicates if an implicit with has been given for the unit. Yes if
220 -- certainly present, no if certainly absent, unkonwn if not known. 220 -- certainly present, No if certainly absent, Unknown if not known.
221 221
222 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2)); 222 Sdep_Table : Unit_Ref_Table (1 .. Pos (Last_Unit - Units.First + 2));
223 -- Sorted table of source dependencies. One extra entry in case we 223 -- Sorted table of source dependencies. One extra entry in case we
224 -- have to add a dummy entry for System. 224 -- have to add a dummy entry for System.
225 225
226 Num_Sdep : Nat := 0; 226 Num_Sdep : Nat := 0;
227 -- Number of active entries in Sdep_Table 227 -- Number of active entries in Sdep_Table
228 228
229 flag_compare_debug : Int;
230 pragma Import (C, flag_compare_debug);
231 -- Import from toplev.c
232
233 ----------------------- 229 -----------------------
234 -- Local Subprograms -- 230 -- Local Subprograms --
235 ----------------------- 231 -----------------------
236 232
237 procedure Collect_Withs (Cunit : Node_Id); 233 procedure Collect_Withs (Cunit : Node_Id);
238 -- Collect with lines for entries in the context clause of the 234 -- Collect with lines for entries in the context clause of the given
239 -- given compilation unit, Cunit. 235 -- compilation unit, Cunit.
240 236
241 procedure Update_Tables_From_ALI_File; 237 procedure Update_Tables_From_ALI_File;
242 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists 238 -- Given an up to date ALI file (see Up_To_Date_ALI_file_Exists
243 -- function), update tables from the ALI information, including 239 -- function), update tables from the ALI information, including
244 -- specifically the Compilation_Switches table. 240 -- specifically the Compilation_Switches table.
259 ------------------- 255 -------------------
260 -- Collect_Withs -- 256 -- Collect_Withs --
261 ------------------- 257 -------------------
262 258
263 procedure Collect_Withs (Cunit : Node_Id) is 259 procedure Collect_Withs (Cunit : Node_Id) is
260 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean;
261 pragma Inline (Is_Implicit_With_Clause);
262 -- Determine whether a with clause denoted by Clause is implicit
263
264 -----------------------------
265 -- Is_Implicit_With_Clause --
266 -----------------------------
267
268 function Is_Implicit_With_Clause (Clause : Node_Id) return Boolean is
269 begin
270 -- With clauses created for ancestor units are marked as internal,
271 -- however, they emulate the semantics in Ada RM 10.1.2 (6/2),
272 -- where
273 --
274 -- with A.B;
275 --
276 -- is almost equivalent to
277 --
278 -- with A;
279 -- with A.B;
280 --
281 -- For ALI encoding purposes, they are considered to be explicit.
282 -- Note that the clauses cannot be marked as explicit because they
283 -- will be subjected to various checks related to with clauses and
284 -- possibly cause false positives.
285
286 if Parent_With (Clause) then
287 return False;
288
289 else
290 return Implicit_With (Clause);
291 end if;
292 end Is_Implicit_With_Clause;
293
294 -- Local variables
295
264 Item : Node_Id; 296 Item : Node_Id;
265 Unum : Unit_Number_Type; 297 Unum : Unit_Number_Type;
298
299 -- Start of processing for Collect_Withs
266 300
267 begin 301 begin
268 Item := First (Context_Items (Cunit)); 302 Item := First (Context_Items (Cunit));
269 while Present (Item) loop 303 while Present (Item) loop
270 304
298 332
299 else 333 else
300 Set_From_Limited_With (Cunit_Entity (Unum)); 334 Set_From_Limited_With (Cunit_Entity (Unum));
301 end if; 335 end if;
302 336
303 if Implicit_With (Unum) /= Yes then 337 if Is_Implicit_With_Clause (Item) then
304 if Implicit_With_From_Instantiation (Item) then 338
305 Implicit_With (Unum) := Yes; 339 -- A previous explicit with clause withs the unit. Retain
340 -- this classification, as it reflects the source relations
341 -- between units.
342
343 if Has_Implicit_With (Unum) = No then
344 null;
345
346 -- Otherwise this is either the first time any clause withs
347 -- the unit, or the unit is already implicitly withed.
348
306 else 349 else
307 Implicit_With (Unum) := No; 350 Has_Implicit_With (Unum) := Yes;
308 end if; 351 end if;
352
353 -- Otherwise the current with clause is explicit. Such clauses
354 -- take precedence over existing implicit clauses because they
355 -- reflect the source relations between unit.
356
357 else
358 Has_Implicit_With (Unum) := No;
309 end if; 359 end if;
310 end if; 360 end if;
311 361
312 Next (Item); 362 Next (Item);
313 end loop; 363 end loop;
571 With_Flags (J) := False; 621 With_Flags (J) := False;
572 Elab_Flags (J) := False; 622 Elab_Flags (J) := False;
573 Elab_All_Flags (J) := False; 623 Elab_All_Flags (J) := False;
574 Elab_Des_Flags (J) := False; 624 Elab_Des_Flags (J) := False;
575 Elab_All_Des_Flags (J) := False; 625 Elab_All_Des_Flags (J) := False;
576 Implicit_With (J) := Unknown; 626 Has_Implicit_With (J) := Unknown;
577 end loop; 627 end loop;
578 628
579 Collect_Withs (Unode); 629 Collect_Withs (Unode);
580 630
581 -- For a body, we must also check for any subunits which belong to 631 -- For a body, we must also check for any subunits which belong to
688 Note_Unit := Main_Unit; 738 Note_Unit := Main_Unit;
689 else 739 else
690 Note_Unit := U; 740 Note_Unit := U;
691 end if; 741 end if;
692 742
693 if Note_Unit = Unit_Num then 743 -- No action needed for pragmas removed by the expander (for
744 -- example, pragmas of ignored ghost entities).
745
746 if Nkind (N) = N_Null_Statement then
747 pragma Assert (Nkind (Original_Node (N)) = N_Pragma);
748 null;
749
750 elsif Note_Unit = Unit_Num then
694 Write_Info_Initiate ('N'); 751 Write_Info_Initiate ('N');
695 Write_Info_Char (' '); 752 Write_Info_Char (' ');
696 753
697 case Pragma_Name_Unmapped (N) is 754 case Pragma_Name (N) is
698 when Name_Annotate => 755 when Name_Annotate =>
699 C := 'A'; 756 C := 'A';
700 when Name_Comment => 757 when Name_Comment =>
701 C := 'C'; 758 C := 'C';
702 when Name_Ident => 759 when Name_Ident =>
788 (Nam : in out File_Name_Type; 845 (Nam : in out File_Name_Type;
789 Idx : Nat); 846 Idx : Nat);
790 -- Write source file name Nam and ALI file name for unit index Idx. 847 -- Write source file name Nam and ALI file name for unit index Idx.
791 -- Possibly change Nam to lowercase (generating a new file name). 848 -- Possibly change Nam to lowercase (generating a new file name).
792 849
793 -------------------------- 850 ---------------------------
794 -- Write_With_File_Name -- 851 -- Write_With_File_Names --
795 -------------------------- 852 ---------------------------
796 853
797 procedure Write_With_File_Names 854 procedure Write_With_File_Names
798 (Nam : in out File_Name_Type; 855 (Nam : in out File_Name_Type;
799 Idx : Nat) 856 Idx : Nat)
800 is 857 is
851 908
852 Cunit := Units.Table (Unum).Cunit; 909 Cunit := Units.Table (Unum).Cunit;
853 Uname := Units.Table (Unum).Unit_Name; 910 Uname := Units.Table (Unum).Unit_Name;
854 Fname := Units.Table (Unum).Unit_File_Name; 911 Fname := Units.Table (Unum).Unit_File_Name;
855 912
856 if Implicit_With (Unum) = Yes then 913 -- Limited with clauses must be processed first because they are
857 Write_Info_Initiate ('Z'); 914 -- the most specific among the three kinds.
858 915
859 elsif Ekind (Cunit_Entity (Unum)) = E_Package 916 if Ekind (Cunit_Entity (Unum)) = E_Package
860 and then From_Limited_With (Cunit_Entity (Unum)) 917 and then From_Limited_With (Cunit_Entity (Unum))
861 then 918 then
862 Write_Info_Initiate ('Y'); 919 Write_Info_Initiate ('Y');
920
921 elsif Has_Implicit_With (Unum) = Yes then
922 Write_Info_Initiate ('Z');
863 923
864 else 924 else
865 Write_Info_Initiate ('W'); 925 Write_Info_Initiate ('W');
866 end if; 926 end if;
867 927
891 or else GNATprove_Mode 951 or else GNATprove_Mode
892 then 952 then
893 Write_Info_Tab (25); 953 Write_Info_Tab (25);
894 954
895 if Is_Spec_Name (Uname) then 955 if Is_Spec_Name (Uname) then
896 Body_Fname := 956
897 Get_File_Name 957 -- In GNATprove mode we must write the spec of a unit which
898 (Get_Body_Name (Uname), 958 -- requires a body if that body is not found. This will
899 Subunit => False, May_Fail => True); 959 -- allow partial analysis on incomplete sources. Also, in
900 960 -- the case of a unit that is a remote call interface, the
901 Body_Index := 961 -- bodies of packages may not exist but still may form a
902 Get_Unit_Index 962 -- valid program - so we handle that here as well.
903 (Get_Body_Name (Uname)); 963
904 964 if GNATprove_Mode
905 if Body_Fname = No_File then 965 or else Is_Remote_Call_Interface (Cunit_Entity (Unum))
906 Body_Fname := Get_File_Name (Uname, Subunit => False); 966 then
907 Body_Index := Get_Unit_Index (Uname); 967 Body_Fname :=
968 Get_File_Name
969 (Uname => Get_Body_Name (Uname),
970 Subunit => False,
971 May_Fail => True);
972
973 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
974
975 if Body_Fname = No_File then
976 Body_Fname := Get_File_Name (Uname, Subunit => False);
977 Body_Index := Get_Unit_Index (Uname);
978 end if;
979
980 -- In the normal path we don't allow failure in fetching the
981 -- name of the desired body unit so that it may be properly
982 -- referenced in the output ali - even if it is missing.
983
984 else
985 Body_Fname :=
986 Get_File_Name
987 (Uname => Get_Body_Name (Uname),
988 Subunit => False,
989 May_Fail => False);
990
991 Body_Index := Get_Unit_Index (Get_Body_Name (Uname));
908 end if; 992 end if;
909
910 else 993 else
911 Body_Fname := Get_File_Name (Uname, Subunit => False); 994 Body_Fname := Get_File_Name (Uname, Subunit => False);
912 Body_Index := Get_Unit_Index (Uname); 995 Body_Index := Get_Unit_Index (Uname);
913 end if; 996 end if;
914 997
990 1073
991 begin 1074 begin
992 -- We never write an ALI file if the original operating mode was 1075 -- We never write an ALI file if the original operating mode was
993 -- syntax-only (-gnats switch used in compiler invocation line) 1076 -- syntax-only (-gnats switch used in compiler invocation line)
994 1077
995 if Original_Operating_Mode = Check_Syntax 1078 if Original_Operating_Mode = Check_Syntax then
996 or flag_compare_debug /= 0
997 then
998 return; 1079 return;
999 end if; 1080 end if;
1000 1081
1001 -- Generation of ALI files may be disabled, e.g. for formal verification 1082 -- Generation of ALI files may be disabled, e.g. for formal verification
1002 -- back-end. 1083 -- back-end.
1480 Write_Info_Char (' '); 1561 Write_Info_Char (' ');
1481 1562
1482 -- Normal case of a unit entry with a source index 1563 -- Normal case of a unit entry with a source index
1483 1564
1484 if Sind > No_Source_File then 1565 if Sind > No_Source_File then
1485 Fname := File_Name (Sind); 1566 -- We never want directory information in ALI files
1486 1567 -- ???But back out this change temporarily until
1487 -- Ensure that on platforms where the file names are not case 1568 -- gprbuild is fixed.
1488 -- sensitive, the recorded file name is in lower case. 1569
1570 if False then
1571 Fname := Strip_Directory (File_Name (Sind));
1572 else
1573 Fname := File_Name (Sind);
1574 end if;
1575
1576 -- Ensure that on platforms where the file names are not
1577 -- case sensitive, the recorded file name is in lower case.
1489 1578
1490 if not File_Names_Case_Sensitive then 1579 if not File_Names_Case_Sensitive then
1491 Get_Name_String (Fname); 1580 Get_Name_String (Fname);
1492 To_Lower (Name_Buffer (1 .. Name_Len)); 1581 To_Lower (Name_Buffer (1 .. Name_Len));
1493 Fname := Name_Find; 1582 Fname := Name_Find;
1565 if Generate_SCO then 1654 if Generate_SCO then
1566 SCO_Record_Filtered; 1655 SCO_Record_Filtered;
1567 SCO_Output; 1656 SCO_Output;
1568 end if; 1657 end if;
1569 1658
1570 -- Output SPARK cross-reference information if needed
1571
1572 if Opt.Xref_Active and then GNATprove_Mode then
1573 SPARK_Specific.Collect_SPARK_Xrefs (Sdep_Table => Sdep_Table,
1574 Num_Sdep => Num_Sdep);
1575 SPARK_Specific.Output_SPARK_Xrefs;
1576 end if;
1577
1578 -- Output final blank line and we are done. This final blank line is 1659 -- Output final blank line and we are done. This final blank line is
1579 -- probably junk, but we don't feel like making an incompatible change. 1660 -- probably junk, but we don't feel like making an incompatible change.
1580 1661
1581 Write_Info_Terminate; 1662 Write_Info_Terminate;
1582 Close_Output_Library_Info; 1663 Close_Output_Library_Info;