1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2011, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Butil; use Butil;
27 with Debug; use Debug;
28 with Fname; use Fname;
30 with Osint; use Osint;
31 with Output; use Output;
36 -- Make control characters visible
38 -- The following variable records which characters currently are
39 -- used as line type markers in the ALI file. This is used in
40 -- Scan_ALI to detect (or skip) invalid lines.
42 Known_ALI_Lines : constant array (Character range 'A' .. 'Z') of Boolean :=
43 ('V' => True, -- version
44 'M' => True, -- main program
45 'A' => True, -- argument
46 'P' => True, -- program
47 'R' => True, -- restriction
48 'I' => True, -- interrupt
51 'L' => True, -- linker option
53 'E' => True, -- external
54 'D' => True, -- dependency
56 'S' => True, -- specific dispatching
57 'Y' => True, -- limited_with
58 'C' => True, -- SCO information
59 'F' => True, -- Alfa information
66 procedure Initialize_ALI is
68 -- When (re)initializing ALI data structures the ALI user expects to
69 -- get a fresh set of data structures. Thus we first need to erase the
70 -- marks put in the name table by the previous set of ALI routine calls.
71 -- These two loops are empty and harmless the first time in.
73 for J in ALIs.First .. ALIs.Last loop
74 Set_Name_Table_Info (ALIs.Table (J).Afile, 0);
77 for J in Units.First .. Units.Last loop
78 Set_Name_Table_Info (Units.Table (J).Uname, 0);
81 -- Free argument table strings
83 for J in Args.First .. Args.Last loop
84 Free (Args.Table (J));
87 -- Initialize all tables
101 -- Add dummy zero'th item in Linker_Options and Notes for sort calls
103 Linker_Options.Increment_Last;
104 Notes.Increment_Last;
106 -- Initialize global variables recording cumulative options in all
107 -- ALI files that are read for a given processing run in gnatbind.
109 Dynamic_Elaboration_Checks_Specified := False;
110 Float_Format_Specified := ' ';
111 Locking_Policy_Specified := ' ';
112 No_Normalize_Scalars_Specified := False;
113 No_Object_Specified := False;
114 Normalize_Scalars_Specified := False;
115 Queuing_Policy_Specified := ' ';
116 Static_Elaboration_Model_Used := False;
117 Task_Dispatching_Policy_Specified := ' ';
118 Unreserve_All_Interrupts_Specified := False;
119 Zero_Cost_Exceptions_Specified := False;
131 Read_Xref : Boolean := False;
132 Read_Lines : String := "";
133 Ignore_Lines : String := "X";
134 Ignore_Errors : Boolean := False;
135 Directly_Scanned : Boolean := False) return ALI_Id
137 P : Text_Ptr := T'First;
138 Line : Logical_Line_Number := 1;
144 Ignore : array (Character range 'A' .. 'Z') of Boolean;
145 -- Ignore (X) is set to True if lines starting with X are to
146 -- be ignored by Scan_ALI and skipped, and False if the lines
147 -- are to be read and processed.
149 Bad_ALI_Format : exception;
150 -- Exception raised by Fatal_Error if Err is True
152 function At_Eol return Boolean;
153 -- Test if at end of line
155 function At_End_Of_Field return Boolean;
156 -- Test if at end of line, or if at blank or horizontal tab
158 procedure Check_At_End_Of_Field;
159 -- Check if we are at end of field, fatal error if not
161 procedure Checkc (C : Character);
162 -- Check next character is C. If so bump past it, if not fatal error
164 procedure Check_Unknown_Line;
165 -- If Ignore_Errors mode, then checks C to make sure that it is not
166 -- an unknown ALI line type characters, and if so, skips lines
167 -- until the first character of the line is one of these characters,
168 -- at which point it does a Getc to put that character in C. The
169 -- call has no effect if C is already an appropriate character.
170 -- If not in Ignore_Errors mode, a fatal error is signalled if the
171 -- line is unknown. Note that if C is an EOL on entry, the line is
172 -- skipped (it is assumed that blank lines are never significant).
173 -- If C is EOF on entry, the call has no effect (it is assumed that
174 -- the caller will properly handle this case).
176 procedure Fatal_Error;
177 -- Generate fatal error message for badly formatted ALI file if
178 -- Err is false, or raise Bad_ALI_Format if Err is True.
180 procedure Fatal_Error_Ignore;
181 pragma Inline (Fatal_Error_Ignore);
182 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
184 function Getc return Character;
185 -- Get next character, bumping P past the character obtained
187 function Get_File_Name (Lower : Boolean := False) return File_Name_Type;
188 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
189 -- with length in Name_Len, as well as returning a File_Name_Type value.
190 -- If lower is false, the case is unchanged, if Lower is True then the
191 -- result is forced to all lower case for systems where file names are
192 -- not case sensitive. This ensures that gnatbind works correctly
193 -- regardless of the case of the file name on all systems. The scan
194 -- is terminated by a end of line, space or horizontal tab. Any other
195 -- special characters are included in the returned name.
198 (Ignore_Spaces : Boolean := False;
199 Ignore_Special : Boolean := False) return Name_Id;
200 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
201 -- length in Name_Len, as well as being returned in Name_Id form).
202 -- If Lower is set to True then the Name_Buffer will be converted to
203 -- all lower case, for systems where file names are not case sensitive.
204 -- This ensures that gnatbind works correctly regardless of the case
205 -- of the file name on all systems. The termination condition depends
206 -- on the settings of Ignore_Spaces and Ignore_Special:
208 -- If Ignore_Spaces is False (normal case), then scan is terminated
209 -- by the normal end of field condition (EOL, space, horizontal tab)
211 -- If Ignore_Special is False (normal case), the scan is terminated by
212 -- a typeref bracket or an equal sign except for the special case of
213 -- an operator name starting with a double quote which is terminated
214 -- by another double quote.
216 -- It is an error to set both Ignore_Spaces and Ignore_Special to True.
217 -- This function handles wide characters properly.
219 function Get_Nat return Nat;
220 -- Skip blanks, then scan out an unsigned integer value in Nat range
221 -- raises ALI_Reading_Error if the encoutered type is not natural.
223 function Get_Stamp return Time_Stamp_Type;
224 -- Skip blanks, then scan out a time stamp
226 function Get_Unit_Name return Unit_Name_Type;
227 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
228 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
229 -- The case is unchanged and terminated by a normal end of field.
231 function Nextc return Character;
232 -- Return current character without modifying pointer P
234 procedure Get_Typeref
235 (Current_File_Num : Sdep_Id;
237 File_Num : out Sdep_Id;
239 Ref_Type : out Character;
241 Standard_Entity : out Name_Id);
242 -- Parse the definition of a typeref (<...>, {...} or (...))
245 -- Skip past spaces, then skip past end of line (fatal error if not
246 -- at end of line). Also skips past any following blank lines.
249 -- Skip rest of current line and any following blank lines
251 procedure Skip_Space;
252 -- Skip past white space (blanks or horizontal tab)
255 -- Skip past next character, does not affect value in C. This call
256 -- is like calling Getc and ignoring the returned result.
258 ---------------------
259 -- At_End_Of_Field --
260 ---------------------
262 function At_End_Of_Field return Boolean is
271 function At_Eol return Boolean is
273 return Nextc = EOF or else Nextc = CR or else Nextc = LF;
276 ---------------------------
277 -- Check_At_End_Of_Field --
278 ---------------------------
280 procedure Check_At_End_Of_Field is
282 if not At_End_Of_Field then
283 if Ignore_Errors then
284 while Nextc > ' ' loop
291 end Check_At_End_Of_Field;
293 ------------------------
294 -- Check_Unknown_Line --
295 ------------------------
297 procedure Check_Unknown_Line is
299 while C not in 'A' .. 'Z'
300 or else not Known_ALI_Lines (C)
302 if C = CR or else C = LF then
309 elsif Ignore_Errors then
317 end Check_Unknown_Line;
323 procedure Checkc (C : Character) is
327 elsif Ignore_Errors then
338 procedure Fatal_Error is
343 procedure Wchar (C : Character);
344 -- Write a single character, replacing horizontal tab by spaces
346 procedure Wchar (C : Character) is
351 exit when Col mod 8 = 0;
360 -- Start of processing for Fatal_Error
364 raise Bad_ALI_Format;
368 Write_Str ("fatal error: file ");
370 Write_Str (" is incorrectly formatted");
373 Write_Str ("make sure you are using consistent versions " &
375 -- Split the following line so that it can easily be transformed for
376 -- e.g. JVM/.NET back-ends where the compiler has a different name.
382 -- Find start of line
386 and then T (Ptr1 - 1) /= CR
387 and then T (Ptr1 - 1) /= LF
392 Write_Int (Int (Line));
407 and then T (Ptr2) /= CR
408 and then T (Ptr2) /= LF
420 if T (Ptr1) = HT then
432 Exit_Program (E_Fatal);
435 ------------------------
436 -- Fatal_Error_Ignore --
437 ------------------------
439 procedure Fatal_Error_Ignore is
441 if not Ignore_Errors then
444 end Fatal_Error_Ignore;
450 function Get_File_Name
451 (Lower : Boolean := False) return File_Name_Type
456 F := Get_Name (Ignore_Special => True);
458 -- Convert file name to all lower case if file names are not case
459 -- sensitive. This ensures that we handle names in the canonical
460 -- lower case format, regardless of the actual case.
462 if Lower and not File_Names_Case_Sensitive then
463 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
466 return File_Name_Type (F);
475 (Ignore_Spaces : Boolean := False;
476 Ignore_Special : Boolean := False) return Name_Id
483 if Ignore_Errors then
491 Add_Char_To_Name_Buffer (Getc);
493 exit when At_End_Of_Field and then not Ignore_Spaces;
495 if not Ignore_Special then
496 if Name_Buffer (1) = '"' then
497 exit when Name_Len > 1 and then Name_Buffer (Name_Len) = '"';
500 -- Terminate on parens or angle brackets or equal sign
502 exit when Nextc = '(' or else Nextc = ')'
503 or else Nextc = '{' or else Nextc = '}'
504 or else Nextc = '<' or else Nextc = '>'
507 -- Terminate on comma
509 exit when Nextc = ',';
511 -- Terminate if left bracket not part of wide char sequence
512 -- Note that we only recognize brackets notation so far ???
514 exit when Nextc = '[' and then T (P + 1) /= '"';
516 -- Terminate if right bracket not part of wide char sequence
518 exit when Nextc = ']' and then T (P - 1) /= '"';
530 function Get_Unit_Name return Unit_Name_Type is
532 return Unit_Name_Type (Get_Name);
539 function Get_Nat return Nat is
545 -- Check if we are on a number. In the case of bad ALI files, this
548 if not (Nextc in '0' .. '9') then
554 V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
556 exit when At_End_Of_Field;
557 exit when Nextc < '0' or else Nextc > '9';
567 function Get_Stamp return Time_Stamp_Type is
575 if Ignore_Errors then
576 return Dummy_Time_Stamp;
582 -- Following reads old style time stamp missing first two digits
584 if Nextc in '7' .. '9' then
589 -- Normal case of full year in time stamp
595 for J in Start .. T'Last loop
606 procedure Get_Typeref
607 (Current_File_Num : Sdep_Id;
609 File_Num : out Sdep_Id;
611 Ref_Type : out Character;
613 Standard_Entity : out Name_Id)
618 when '<' => Ref := Tref_Derived;
619 when '(' => Ref := Tref_Access;
620 when '{' => Ref := Tref_Type;
621 when others => Ref := Tref_None;
624 -- Case of typeref field present
626 if Ref /= Tref_None then
627 P := P + 1; -- skip opening bracket
629 if Nextc in 'a' .. 'z' then
630 File_Num := No_Sdep_Id;
634 Standard_Entity := Get_Name (Ignore_Spaces => True);
639 File_Num := Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
643 File_Num := Current_File_Num;
649 Standard_Entity := No_Name;
652 -- ??? Temporary workaround for nested generics case:
653 -- 4i4 Directories{1|4I9[4|6[3|3]]}
657 Nested_Brackets : Natural := 0;
663 Nested_Brackets := Nested_Brackets + 1;
665 Nested_Brackets := Nested_Brackets - 1;
667 if Nested_Brackets = 0 then
676 P := P + 1; -- skip closing bracket
679 -- No typeref entry present
682 File_Num := No_Sdep_Id;
686 Standard_Entity := No_Name;
694 function Getc return Character is
708 function Nextc return Character is
717 procedure Skip_Eol is
722 if Ignore_Errors then
723 while not At_Eol loop
731 -- Loop to skip past blank lines (first time through skips this EOL)
733 while Nextc < ' ' and then Nextc /= EOF loop
746 procedure Skip_Line is
748 while not At_Eol loop
759 procedure Skip_Space is
761 while Nextc = ' ' or else Nextc = HT loop
777 -- Start of processing for Scan_ALI
780 First_Sdep_Entry := Sdep.Last + 1;
782 -- Acquire lines to be ignored
785 Ignore := ('U' | 'W' | 'Y' | 'D' | 'X' => False, others => True);
787 -- Read_Lines parameter given
789 elsif Read_Lines /= "" then
790 Ignore := ('U' => False, others => True);
792 for J in Read_Lines'Range loop
793 Ignore (Read_Lines (J)) := False;
796 -- Process Ignore_Lines parameter
799 Ignore := (others => False);
801 for J in Ignore_Lines'Range loop
802 pragma Assert (Ignore_Lines (J) /= 'U');
803 Ignore (Ignore_Lines (J)) := True;
807 -- Setup ALI Table entry with appropriate defaults
811 Set_Name_Table_Info (F, Int (Id));
815 Compile_Errors => False,
816 First_Interrupt_State => Interrupt_States.Last + 1,
817 First_Sdep => No_Sdep_Id,
818 First_Specific_Dispatching => Specific_Dispatching.Last + 1,
819 First_Unit => No_Unit_Id,
821 Last_Interrupt_State => Interrupt_States.Last,
822 Last_Sdep => No_Sdep_Id,
823 Last_Specific_Dispatching => Specific_Dispatching.Last,
824 Last_Unit => No_Unit_Id,
825 Locking_Policy => ' ',
828 Main_Program => None,
830 Normalize_Scalars => False,
831 Ofile_Full_Name => Full_Object_File_Name,
832 Queuing_Policy => ' ',
833 Restrictions => No_Restrictions,
834 SAL_Interface => False,
836 Task_Dispatching_Policy => ' ',
837 Time_Slice_Value => -1,
838 Allocator_In_Body => False,
840 Unit_Exception_Table => False,
841 Ver => (others => ' '),
843 Zero_Cost_Exceptions => False);
845 -- Now we acquire the input lines from the ALI file. Note that the
846 -- convention in the following code is that as we enter each section,
847 -- C is set to contain the first character of the following line.
852 -- Acquire library version
856 -- The V line missing really indicates trouble, most likely it
857 -- means we don't have an ALI file at all, so here we give a
858 -- fatal error even if we are in Ignore_Errors mode.
862 elsif Ignore ('V') then
870 for J in 1 .. Ver_Len_Max loop
873 ALIs.Table (Id).Ver (J) := C;
874 ALIs.Table (Id).Ver_Len := J;
883 -- Acquire main program line if present
896 ALIs.Table (Id).Main_Program := Func;
898 ALIs.Table (Id).Main_Program := Proc;
908 ALIs.Table (Id).Main_Priority := Get_Nat;
916 ALIs.Table (Id).Time_Slice_Value := Get_Nat;
924 ALIs.Table (Id).Allocator_In_Body := True;
932 ALIs.Table (Id).Main_CPU := Get_Nat;
939 ALIs.Table (Id).WC_Encoding := Getc;
948 -- Acquire argument lines
950 First_Arg := Args.Last + 1;
954 exit A_Loop when C /= 'A';
965 while not At_Eol loop
966 Add_Char_To_Name_Buffer (Getc);
969 -- If -fstack-check, record that it occurred
971 if Name_Buffer (1 .. Name_Len) = "-fstack-check" then
972 Stack_Check_Switch_Set := True;
975 -- Store the argument
978 Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
991 if Ignore_Errors then
1003 if Ignore ('P') then
1011 while not At_Eol loop
1016 -- Processing for CE
1020 ALIs.Table (Id).Compile_Errors := True;
1022 -- Processing for DB
1026 Detect_Blocking := True;
1028 -- Processing for FD/FG/FI
1031 Float_Format_Specified := Getc;
1032 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1034 -- Processing for Lx
1037 Locking_Policy_Specified := Getc;
1038 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1040 -- Processing for flags starting with N
1045 -- Processing for NO
1048 ALIs.Table (Id).No_Object := True;
1049 No_Object_Specified := True;
1051 -- Processing for NR
1054 No_Run_Time_Mode := True;
1055 Configurable_Run_Time_Mode := True;
1057 -- Processing for NS
1060 ALIs.Table (Id).Normalize_Scalars := True;
1061 Normalize_Scalars_Specified := True;
1064 -- Invalid switch starting with N
1070 -- Processing for Qx
1073 Queuing_Policy_Specified := Getc;
1074 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1076 -- Processing for flags starting with S
1081 -- Processing for SL
1084 ALIs.Table (Id).SAL_Interface := True;
1086 -- Processing for SS
1089 Opt.Sec_Stack_Used := True;
1091 -- Invalid switch starting with S
1097 -- Processing for Tx
1100 Task_Dispatching_Policy_Specified := Getc;
1101 ALIs.Table (Id).Task_Dispatching_Policy :=
1102 Task_Dispatching_Policy_Specified;
1104 -- Processing for switch starting with U
1109 -- Processing for UA
1112 Unreserve_All_Interrupts_Specified := True;
1114 -- Processing for UX
1117 ALIs.Table (Id).Unit_Exception_Table := True;
1119 -- Invalid switches starting with U
1125 -- Processing for ZX
1131 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1132 Zero_Cost_Exceptions_Specified := True;
1137 -- Invalid parameter
1145 if not NS_Found then
1146 No_Normalize_Scalars_Specified := True;
1155 -- Acquire first restrictions line
1158 if Ignore_Errors then
1170 if Ignore ('R') then
1173 -- Process restrictions line
1176 Scan_Restrictions : declare
1177 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1178 -- Save cumulative restrictions in case we have a fatal error
1180 Bad_R_Line : exception;
1181 -- Signal bad restrictions line (raised on unexpected character)
1187 -- Acquire information for boolean restrictions
1189 for R in All_Boolean_Restrictions loop
1194 ALIs.Table (Id).Restrictions.Violated (R) := True;
1195 Cumulative_Restrictions.Violated (R) := True;
1198 ALIs.Table (Id).Restrictions.Set (R) := True;
1199 Cumulative_Restrictions.Set (R) := True;
1209 -- Acquire information for parameter restrictions
1211 for RP in All_Parameter_Restrictions loop
1213 -- Acquire restrictions pragma information
1220 ALIs.Table (Id).Restrictions.Set (RP) := True;
1223 N : constant Integer := Integer (Get_Nat);
1225 ALIs.Table (Id).Restrictions.Value (RP) := N;
1227 if Cumulative_Restrictions.Set (RP) then
1228 Cumulative_Restrictions.Value (RP) :=
1230 (Cumulative_Restrictions.Value (RP), N);
1232 Cumulative_Restrictions.Set (RP) := True;
1233 Cumulative_Restrictions.Value (RP) := N;
1241 -- Acquire restrictions violations information
1248 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1249 Cumulative_Restrictions.Violated (RP) := True;
1252 N : constant Integer := Integer (Get_Nat);
1253 pragma Unsuppress (Overflow_Check);
1256 ALIs.Table (Id).Restrictions.Count (RP) := N;
1258 if RP in Checked_Max_Parameter_Restrictions then
1259 Cumulative_Restrictions.Count (RP) :=
1261 (Cumulative_Restrictions.Count (RP), N);
1263 Cumulative_Restrictions.Count (RP) :=
1264 Cumulative_Restrictions.Count (RP) + N;
1268 when Constraint_Error =>
1270 -- A constraint error comes from the addition in
1271 -- the else branch. We reset to the maximum and
1272 -- indicate that the real value is now unknown.
1274 Cumulative_Restrictions.Value (RP) := Integer'Last;
1275 Cumulative_Restrictions.Unknown (RP) := True;
1280 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1281 Cumulative_Restrictions.Unknown (RP) := True;
1291 -- Here if error during scanning of restrictions line
1296 -- In Ignore_Errors mode, undo any changes to restrictions
1297 -- from this unit, and continue on.
1299 if Ignore_Errors then
1300 Cumulative_Restrictions := Save_R;
1301 ALIs.Table (Id).Restrictions := No_Restrictions;
1304 -- In normal mode, this is a fatal error
1310 end Scan_Restrictions;
1313 -- Acquire additional restrictions (No_Dependence) lines if present
1317 if Ignore ('R') then
1321 No_Deps.Append ((Id, Get_Name));
1328 -- Acquire 'I' lines if present
1333 if Ignore ('I') then
1339 I_State : Character;
1348 Interrupt_States.Append (
1349 (Interrupt_Id => Int_Num,
1350 Interrupt_State => I_State,
1351 IS_Pragma_Line => Line_No));
1353 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1361 -- Acquire 'S' lines if present
1366 if Ignore ('S') then
1382 First_Prio := Get_Nat;
1383 Last_Prio := Get_Nat;
1386 Specific_Dispatching.Append (
1387 (Dispatching_Policy => Policy,
1388 First_Priority => First_Prio,
1389 Last_Priority => Last_Prio,
1390 PSD_Pragma_Line => Line_No));
1392 ALIs.Table (Id).Last_Specific_Dispatching :=
1393 Specific_Dispatching.Last;
1402 -- Loop to acquire unit entries
1406 exit U_Loop when C /= 'U';
1408 -- Note: as per spec, we never ignore U lines
1412 Units.Increment_Last;
1414 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1415 ALIs.Table (Id).First_Unit := Units.Last;
1419 UL : Unit_Record renames Units.Table (Units.Last);
1422 UL.Uname := Get_Unit_Name;
1423 UL.Predefined := Is_Predefined_Unit;
1424 UL.Internal := Is_Internal_Unit;
1426 UL.Sfile := Get_File_Name (Lower => True);
1428 UL.Preelab := False;
1429 UL.No_Elab := False;
1430 UL.Shared_Passive := False;
1432 UL.Remote_Types := False;
1433 UL.Has_RACW := False;
1434 UL.Init_Scalars := False;
1435 UL.Is_Generic := False;
1436 UL.Icasing := Mixed_Case;
1437 UL.Kcasing := All_Lower_Case;
1438 UL.Dynamic_Elab := False;
1439 UL.Elaborate_Body := False;
1440 UL.Set_Elab_Entity := False;
1441 UL.Version := "00000000";
1442 UL.First_With := Withs.Last + 1;
1443 UL.First_Arg := First_Arg;
1444 UL.Elab_Position := 0;
1445 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1446 UL.Directly_Scanned := Directly_Scanned;
1447 UL.Body_Needed_For_SAL := False;
1448 UL.Elaborate_Body_Desirable := False;
1449 UL.Optimize_Alignment := 'O';
1450 UL.Has_Finalizer := False;
1452 if Debug_Flag_U then
1453 Write_Str (" ----> reading unit ");
1454 Write_Int (Int (Units.Last));
1456 Write_Unit_Name (UL.Uname);
1457 Write_Str (" from file ");
1458 Write_Name (UL.Sfile);
1463 -- Check for duplicated unit in different files
1466 Info : constant Int := Get_Name_Table_Info
1467 (Units.Table (Units.Last).Uname);
1470 and then Units.Table (Units.Last).Sfile /=
1471 Units.Table (Unit_Id (Info)).Sfile
1473 -- If Err is set then ignore duplicate unit name. This is the
1474 -- case of a call from gnatmake, where the situation can arise
1475 -- from substitution of source files. In such situations, the
1476 -- processing in gnatmake will always result in any required
1477 -- recompilations in any case, and if we consider this to be
1478 -- an error we get strange cases (for example when a generic
1479 -- instantiation is replaced by a normal package) where we
1480 -- read the old ali file, decide to recompile, and then decide
1481 -- that the old and new ali files are incompatible.
1486 -- If Err is not set, then this is a fatal error. This is
1487 -- the case of being called from the binder, where we must
1488 -- definitely diagnose this as an error.
1492 Write_Str ("error: duplicate unit name: ");
1495 Write_Str ("error: unit """);
1496 Write_Unit_Name (Units.Table (Units.Last).Uname);
1497 Write_Str (""" found in file """);
1498 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1502 Write_Str ("error: unit """);
1503 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1504 Write_Str (""" found in file """);
1505 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1509 Exit_Program (E_Fatal);
1515 (Units.Table (Units.Last).Uname, Int (Units.Last));
1517 -- Scan out possible version and other parameters
1526 if C in '0' .. '9' or else C in 'a' .. 'f' then
1527 Units.Table (Units.Last).Version (1) := C;
1529 for J in 2 .. 8 loop
1531 Units.Table (Units.Last).Version (J) := C;
1540 Check_At_End_Of_Field;
1541 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1544 Check_At_End_Of_Field;
1545 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1551 -- DE parameter (Dynamic elaboration checks)
1557 Check_At_End_Of_Field;
1558 Units.Table (Units.Last).Dynamic_Elab := True;
1559 Dynamic_Elaboration_Checks_Specified := True;
1570 Units.Table (Units.Last).Elaborate_Body := True;
1572 Units.Table (Units.Last).Set_Elab_Entity := True;
1577 Check_At_End_Of_Field;
1579 -- GE parameter (generic)
1585 Check_At_End_Of_Field;
1586 Units.Table (Units.Last).Is_Generic := True;
1591 -- IL/IS/IU parameters
1597 Units.Table (Units.Last).Icasing := All_Lower_Case;
1599 Units.Table (Units.Last).Init_Scalars := True;
1600 Initialize_Scalars_Used := True;
1602 Units.Table (Units.Last).Icasing := All_Upper_Case;
1607 Check_At_End_Of_Field;
1615 Units.Table (Units.Last).Kcasing := Mixed_Case;
1617 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1622 Check_At_End_Of_Field;
1630 Units.Table (Units.Last).No_Elab := True;
1631 Check_At_End_Of_Field;
1636 -- PF/PR/PU/PK parameters
1642 Units.Table (Units.Last).Has_Finalizer := True;
1644 Units.Table (Units.Last).Preelab := True;
1646 Units.Table (Units.Last).Pure := True;
1648 Units.Table (Units.Last).Unit_Kind := 'p';
1653 Check_At_End_Of_Field;
1655 -- OL/OO/OS/OT parameters
1660 if C = 'L' or else C = 'O' or else C = 'S' or else C = 'T' then
1661 Units.Table (Units.Last).Optimize_Alignment := C;
1666 Check_At_End_Of_Field;
1674 Units.Table (Units.Last).RCI := True;
1676 Units.Table (Units.Last).Remote_Types := True;
1678 Units.Table (Units.Last).Has_RACW := True;
1683 Check_At_End_Of_Field;
1689 Units.Table (Units.Last).Shared_Passive := True;
1691 Units.Table (Units.Last).Unit_Kind := 's';
1696 Check_At_End_Of_Field;
1706 -- Check if static elaboration model used
1708 if not Units.Table (Units.Last).Dynamic_Elab
1709 and then not Units.Table (Units.Last).Internal
1711 Static_Elaboration_Model_Used := True;
1716 -- Scan out With lines for this unit
1720 exit With_Loop when C /= 'W' and then C /= 'Y';
1722 if Ignore ('W') then
1728 Withs.Increment_Last;
1729 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1730 Withs.Table (Withs.Last).Elaborate := False;
1731 Withs.Table (Withs.Last).Elaborate_All := False;
1732 Withs.Table (Withs.Last).Elab_Desirable := False;
1733 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1734 Withs.Table (Withs.Last).SAL_Interface := False;
1735 Withs.Table (Withs.Last).Limited_With := (C = 'Y');
1737 -- Generic case with no object file available
1740 Withs.Table (Withs.Last).Sfile := No_File;
1741 Withs.Table (Withs.Last).Afile := No_File;
1746 Withs.Table (Withs.Last).Sfile := Get_File_Name
1748 Withs.Table (Withs.Last).Afile := Get_File_Name
1751 -- Scan out possible E, EA, ED, and AD parameters
1753 while not At_Eol loop
1759 Check_At_End_Of_Field;
1761 -- Store AD indication unless ignore required
1763 if not Ignore_ED then
1764 Withs.Table (Withs.Last).Elab_All_Desirable :=
1768 elsif Nextc = 'E' then
1771 if At_End_Of_Field then
1772 Withs.Table (Withs.Last).Elaborate := True;
1774 elsif Nextc = 'A' then
1776 Check_At_End_Of_Field;
1777 Withs.Table (Withs.Last).Elaborate_All := True;
1781 Check_At_End_Of_Field;
1783 -- Store ED indication unless ignore required
1785 if not Ignore_ED then
1786 Withs.Table (Withs.Last).Elab_Desirable :=
1803 Units.Table (Units.Last).Last_With := Withs.Last;
1804 Units.Table (Units.Last).Last_Arg := Args.Last;
1806 -- If there are linker options lines present, scan them
1810 Linker_Options_Loop : loop
1812 exit Linker_Options_Loop when C /= 'L';
1814 if Ignore ('L') then
1825 if C < Character'Val (16#20#)
1826 or else C > Character'Val (16#7E#)
1831 C := Character'Val (0);
1838 for J in 1 .. 2 loop
1841 if C in '0' .. '9' then
1844 Character'Pos ('0');
1846 elsif C in 'A' .. 'F' then
1849 Character'Pos ('A') +
1858 Add_Char_To_Name_Buffer (Character'Val (V));
1863 exit when Nextc /= '"';
1867 Add_Char_To_Name_Buffer (C);
1871 Add_Char_To_Name_Buffer (NUL);
1876 end loop Linker_Options_Loop;
1878 -- Store the linker options entry if one was found
1880 if Name_Len /= 0 then
1881 Linker_Options.Increment_Last;
1883 Linker_Options.Table (Linker_Options.Last).Name :=
1886 Linker_Options.Table (Linker_Options.Last).Unit :=
1889 Linker_Options.Table (Linker_Options.Last).Internal_File :=
1890 Is_Internal_File_Name (F);
1892 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1893 Linker_Options.Last;
1896 -- If there are notes present, scan them
1900 exit Notes_Loop when C /= 'N';
1902 if Ignore ('N') then
1908 Notes.Increment_Last;
1909 Notes.Table (Notes.Last).Pragma_Type := Getc;
1910 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
1912 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
1913 Notes.Table (Notes.Last).Unit := Units.Last;
1916 Notes.Table (Notes.Last).Pragma_Args := No_Name;
1922 while not At_Eol loop
1923 Add_Char_To_Name_Buffer (Getc);
1926 Notes.Table (Notes.Last).Pragma_Args := Name_Enter;
1933 end loop Notes_Loop;
1936 -- End loop through units for one ALI file
1938 ALIs.Table (Id).Last_Unit := Units.Last;
1939 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1941 -- Set types of the units (there can be at most 2 of them)
1943 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1944 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1945 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
1948 -- Deal with body only and spec only cases, note that the reason we
1949 -- do our own checking of the name (rather than using Is_Body_Name)
1950 -- is that Uname drags in far too much compiler junk!
1952 Get_Name_String (Units.Table (Units.Last).Uname);
1954 if Name_Buffer (Name_Len) = 'b' then
1955 Units.Table (Units.Last).Utype := Is_Body_Only;
1957 Units.Table (Units.Last).Utype := Is_Spec_Only;
1961 -- Scan out external version references and put in hash table
1965 exit E_Loop when C /= 'E';
1967 if Ignore ('E') then
1983 exit when At_End_Of_Field;
1984 Add_Char_To_Name_Buffer (C);
1987 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1994 -- Scan out source dependency lines for this ALI file
1996 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
2000 exit D_Loop when C /= 'D';
2002 if Ignore ('D') then
2008 Sdep.Increment_Last;
2010 -- In the following call, Lower is not set to True, this is either
2011 -- a bug, or it deserves a special comment as to why this is so???
2013 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
2015 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
2016 Sdep.Table (Sdep.Last).Dummy_Entry :=
2017 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
2019 -- Acquire checksum value
2032 exit when At_Eol or else Ctr = 8;
2034 if Nextc in '0' .. '9' then
2036 Character'Pos (Nextc) - Character'Pos ('0');
2038 elsif Nextc in 'a' .. 'f' then
2040 Character'Pos (Nextc) - Character'Pos ('a') + 10;
2050 if Ctr = 8 and then At_End_Of_Field then
2051 Sdep.Table (Sdep.Last).Checksum := Chk;
2057 -- Acquire subunit and reference file name entries
2059 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
2060 Sdep.Table (Sdep.Last).Rfile :=
2061 Sdep.Table (Sdep.Last).Sfile;
2062 Sdep.Table (Sdep.Last).Start_Line := 1;
2067 -- Here for subunit name
2069 if Nextc not in '0' .. '9' then
2071 while not At_End_Of_Field loop
2072 Add_Char_To_Name_Buffer (Getc);
2075 -- Set the subunit name. Note that we use Name_Find rather
2076 -- than Name_Enter here as the subunit name may already
2077 -- have been put in the name table by the Project Manager.
2079 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
2084 -- Here for reference file name entry
2086 if Nextc in '0' .. '9' then
2087 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2092 while not At_End_Of_Field loop
2093 Add_Char_To_Name_Buffer (Getc);
2096 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2106 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2108 -- We must at this stage be at an Xref line or the end of file
2120 -- If we are ignoring Xref sections we are done (we ignore all
2121 -- remaining lines since only xref related lines follow X).
2123 if Ignore ('X') and then not Debug_Flag_X then
2127 -- Loop through Xref sections
2131 exit X_Loop when C /= 'X';
2133 -- Make new entry in section table
2135 Xref_Section.Increment_Last;
2137 Read_Refs_For_One_File : declare
2138 XS : Xref_Section_Record renames
2139 Xref_Section.Table (Xref_Section.Last);
2141 Current_File_Num : Sdep_Id;
2142 -- Keeps track of the current file number (changed by nn|)
2145 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2146 XS.File_Name := Get_File_Name;
2147 XS.First_Entity := Xref_Entity.Last + 1;
2149 Current_File_Num := XS.File_Num;
2156 -- Loop through Xref entities
2158 while C /= 'X' and then C /= EOF loop
2159 Xref_Entity.Increment_Last;
2161 Read_Refs_For_One_Entity : declare
2162 XE : Xref_Entity_Record renames
2163 Xref_Entity.Table (Xref_Entity.Last);
2166 procedure Read_Instantiation_Reference;
2167 -- Acquire instantiation reference. Caller has checked
2168 -- that current character is '[' and on return the cursor
2169 -- is skipped past the corresponding closing ']'.
2171 ----------------------------------
2172 -- Read_Instantiation_Reference --
2173 ----------------------------------
2175 procedure Read_Instantiation_Reference is
2176 Local_File_Num : Sdep_Id := Current_File_Num;
2179 Xref.Increment_Last;
2182 XR : Xref_Record renames Xref.Table (Xref.Last);
2185 P := P + 1; -- skip [
2190 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2191 Local_File_Num := XR.File_Num;
2196 XR.File_Num := Local_File_Num;
2203 -- Recursive call for next reference
2206 pragma Warnings (Off); -- kill recursion warning
2207 Read_Instantiation_Reference;
2208 pragma Warnings (On);
2211 -- Skip closing bracket after recursive call
2215 end Read_Instantiation_Reference;
2217 -- Start of processing for Read_Refs_For_One_Entity
2226 XE.Visibility := Global;
2228 XE.Visibility := Static;
2230 XE.Visibility := Other;
2233 XE.Entity := Get_Name;
2235 -- Handle the information about generic instantiations
2238 Skipc; -- Opening '['
2241 if Nextc /= '|' then
2242 XE.Iref_File_Num := Current_File_Num;
2246 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2248 XE.Iref_Line := Get_Nat;
2256 XE.Iref_File_Num := No_Sdep_Id;
2260 Current_File_Num := XS.File_Num;
2262 -- Renaming reference is present
2266 XE.Rref_Line := Get_Nat;
2272 XE.Rref_Col := Get_Nat;
2274 -- No renaming reference present
2283 XE.Oref_File_Num := No_Sdep_Id;
2284 XE.Tref_File_Num := No_Sdep_Id;
2285 XE.Tref := Tref_None;
2286 XE.First_Xref := Xref.Last + 1;
2288 -- Loop to check for additional info present
2301 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2302 exit when Ref = Tref_None;
2304 -- Do we have an overriding procedure?
2306 if Ref = Tref_Derived and then Typ = 'p' then
2307 XE.Oref_File_Num := File;
2308 XE.Oref_Line := Line;
2311 -- Arrays never override anything, and <> points to
2312 -- the index types instead
2314 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2316 -- Index types are stored in the list of references
2318 Xref.Increment_Last;
2321 XR : Xref_Record renames Xref.Table (Xref.Last);
2323 XR.File_Num := File;
2325 XR.Rtype := Array_Index_Reference;
2330 -- Interfaces are stored in the list of references,
2331 -- although the parent type itself is stored in XE.
2332 -- The first interface (when there are only
2333 -- interfaces) is stored in XE.Tref*)
2335 elsif Ref = Tref_Derived
2337 and then XE.Tref_File_Num /= No_Sdep_Id
2339 Xref.Increment_Last;
2342 XR : Xref_Record renames Xref.Table (Xref.Last);
2344 XR.File_Num := File;
2346 XR.Rtype := Interface_Reference;
2353 XE.Tref_File_Num := File;
2354 XE.Tref_Line := Line;
2355 XE.Tref_Type := Typ;
2357 XE.Tref_Standard_Entity := Std;
2362 -- Loop through cross-references for this entity
2369 exit when Nextc /= '.';
2373 Xref.Increment_Last;
2376 XR : Xref_Record renames Xref.Table (Xref.Last);
2383 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2384 Current_File_Num := XR.File_Num;
2388 XR.File_Num := Current_File_Num;
2394 -- Imported entities reference as in:
2395 -- 494b<c,__gnat_copy_attribs>25
2399 XR.Imported_Lang := Get_Name;
2401 pragma Assert (Nextc = ',');
2404 XR.Imported_Name := Get_Name;
2406 pragma Assert (Nextc = '>');
2410 XR.Imported_Lang := No_Name;
2411 XR.Imported_Name := No_Name;
2417 Read_Instantiation_Reference;
2422 -- Record last cross-reference
2424 XE.Last_Xref := Xref.Last;
2428 when Bad_ALI_Format =>
2430 -- If ignoring errors, then we skip a line with an
2431 -- unexpected error, and try to continue subsequent
2434 if Ignore_Errors then
2435 Xref_Entity.Decrement_Last;
2439 -- Otherwise, we reraise the fatal exception
2444 end Read_Refs_For_One_Entity;
2447 -- Record last entity
2449 XS.Last_Entity := Xref_Entity.Last;
2451 end Read_Refs_For_One_File;
2456 -- Here after dealing with xref sections
2458 -- Ignore remaining lines, which belong to an additional section of the
2459 -- ALI file not considered here (like SCO or Alfa).
2466 when Bad_ALI_Format =>
2474 function SEq (F1, F2 : String_Ptr) return Boolean is
2476 return F1.all = F2.all;
2483 function SHash (S : String_Ptr) return Vindex is
2488 for J in S.all'Range loop
2489 H := H * 2 + Character'Pos (S (J));
2492 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));