1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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
52 'E' => True, -- external
53 'D' => True, -- dependency
55 'S' => True, -- specific dispatching
62 procedure Initialize_ALI is
64 -- When (re)initializing ALI data structures the ALI user expects to
65 -- get a fresh set of data structures. Thus we first need to erase the
66 -- marks put in the name table by the previous set of ALI routine calls.
67 -- These two loops are empty and harmless the first time in.
69 for J in ALIs.First .. ALIs.Last loop
70 Set_Name_Table_Info (ALIs.Table (J).Afile, 0);
73 for J in Units.First .. Units.Last loop
74 Set_Name_Table_Info (Units.Table (J).Uname, 0);
77 -- Free argument table strings
79 for J in Args.First .. Args.Last loop
80 Free (Args.Table (J));
83 -- Initialize all tables
96 -- Add dummy zero'th item in Linker_Options for the sort function
98 Linker_Options.Increment_Last;
100 -- Initialize global variables recording cumulative options in all
101 -- ALI files that are read for a given processing run in gnatbind.
103 Dynamic_Elaboration_Checks_Specified := False;
104 Float_Format_Specified := ' ';
105 Locking_Policy_Specified := ' ';
106 No_Normalize_Scalars_Specified := False;
107 No_Object_Specified := False;
108 Normalize_Scalars_Specified := False;
109 Queuing_Policy_Specified := ' ';
110 Static_Elaboration_Model_Used := False;
111 Task_Dispatching_Policy_Specified := ' ';
112 Unreserve_All_Interrupts_Specified := False;
113 Zero_Cost_Exceptions_Specified := False;
125 Read_Xref : Boolean := False;
126 Read_Lines : String := "";
127 Ignore_Lines : String := "X";
128 Ignore_Errors : Boolean := False) return ALI_Id
130 P : Text_Ptr := T'First;
131 Line : Logical_Line_Number := 1;
137 Ignore : array (Character range 'A' .. 'Z') of Boolean;
138 -- Ignore (X) is set to True if lines starting with X are to
139 -- be ignored by Scan_ALI and skipped, and False if the lines
140 -- are to be read and processed.
142 Bad_ALI_Format : exception;
143 -- Exception raised by Fatal_Error if Err is True
145 function At_Eol return Boolean;
146 -- Test if at end of line
148 function At_End_Of_Field return Boolean;
149 -- Test if at end of line, or if at blank or horizontal tab
151 procedure Check_At_End_Of_Field;
152 -- Check if we are at end of field, fatal error if not
154 procedure Checkc (C : Character);
155 -- Check next character is C. If so bump past it, if not fatal error
157 procedure Check_Unknown_Line;
158 -- If Ignore_Errors mode, then checks C to make sure that it is not
159 -- an unknown ALI line type characters, and if so, skips lines
160 -- until the first character of the line is one of these characters,
161 -- at which point it does a Getc to put that character in C. The
162 -- call has no effect if C is already an appropriate character.
163 -- If not in Ignore_Errors mode, a fatal error is signalled if the
164 -- line is unknown. Note that if C is an EOL on entry, the line is
165 -- skipped (it is assumed that blank lines are never significant).
166 -- If C is EOF on entry, the call has no effect (it is assumed that
167 -- the caller will properly handle this case).
169 procedure Fatal_Error;
170 -- Generate fatal error message for badly formatted ALI file if
171 -- Err is false, or raise Bad_ALI_Format if Err is True.
173 procedure Fatal_Error_Ignore;
174 pragma Inline (Fatal_Error_Ignore);
175 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
177 function Getc return Character;
178 -- Get next character, bumping P past the character obtained
180 function Get_File_Name (Lower : Boolean := False) return File_Name_Type;
181 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
182 -- with length in Name_Len, as well as returning a File_Name_Type value.
183 -- If lower is false, the case is unchanged, if Lower is True then the
184 -- result is forced to all lower case for systems where file names are
185 -- not case sensitive. This ensures that gnatbind works correctly
186 -- regardless of the case of the file name on all systems. The scan
187 -- is terminated by a end of line, space or horizontal tab. Any other
188 -- special characters are included in the returned name.
191 (Ignore_Spaces : Boolean := False;
192 Ignore_Special : Boolean := False)return Name_Id;
193 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
194 -- length in Name_Len, as well as being returned in Name_Id form).
195 -- If Lower is set to True then the Name_Buffer will be converted to
196 -- all lower case, for systems where file names are not case sensitive.
197 -- This ensures that gnatbind works correctly regardless of the case
198 -- of the file name on all systems. The termination condition depends
199 -- on the settings of Ignore_Spaces and Ignore_Special:
201 -- If Ignore_Spaces is False (normal case), then scan is terminated
202 -- by the normal end of field condition (EOL, space, horizontal tab)
204 -- If Ignore_Special is False (normal case), the scan is terminated by
205 -- a typeref bracket or an equal sign except for the special case of
206 -- an operator name starting with a double quite which is terminated
207 -- by another double quote.
209 -- It is an error to set both Ignore_Spaces and Ignore_Special to True.
210 -- This function handles wide characters properly.
212 function Get_Nat return Nat;
213 -- Skip blanks, then scan out an unsigned integer value in Nat range
214 -- raises ALI_Reading_Error if the encoutered type is not natural.
216 function Get_Stamp return Time_Stamp_Type;
217 -- Skip blanks, then scan out a time stamp
219 function Get_Unit_Name return Unit_Name_Type;
220 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
221 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
222 -- The case is unchanged and terminated by a normal end of field.
224 function Nextc return Character;
225 -- Return current character without modifying pointer P
227 procedure Get_Typeref
228 (Current_File_Num : Sdep_Id;
230 File_Num : out Sdep_Id;
232 Ref_Type : out Character;
234 Standard_Entity : out Name_Id);
235 -- Parse the definition of a typeref (<...>, {...} or (...))
238 -- Skip past spaces, then skip past end of line (fatal error if not
239 -- at end of line). Also skips past any following blank lines.
242 -- Skip rest of current line and any following blank lines
244 procedure Skip_Space;
245 -- Skip past white space (blanks or horizontal tab)
248 -- Skip past next character, does not affect value in C. This call
249 -- is like calling Getc and ignoring the returned result.
251 ---------------------
252 -- At_End_Of_Field --
253 ---------------------
255 function At_End_Of_Field return Boolean is
264 function At_Eol return Boolean is
266 return Nextc = EOF or else Nextc = CR or else Nextc = LF;
269 ---------------------------
270 -- Check_At_End_Of_Field --
271 ---------------------------
273 procedure Check_At_End_Of_Field is
275 if not At_End_Of_Field then
276 if Ignore_Errors then
277 while Nextc > ' ' loop
284 end Check_At_End_Of_Field;
286 ------------------------
287 -- Check_Unknown_Line --
288 ------------------------
290 procedure Check_Unknown_Line is
292 while C not in 'A' .. 'Z'
293 or else not Known_ALI_Lines (C)
295 if C = CR or else C = LF then
302 elsif Ignore_Errors then
310 end Check_Unknown_Line;
316 procedure Checkc (C : Character) is
320 elsif Ignore_Errors then
331 procedure Fatal_Error is
336 procedure Wchar (C : Character);
337 -- Write a single character, replacing horizontal tab by spaces
339 procedure Wchar (C : Character) is
344 exit when Col mod 8 = 0;
353 -- Start of processing for Fatal_Error
357 raise Bad_ALI_Format;
361 Write_Str ("fatal error: file ");
363 Write_Str (" is incorrectly formatted");
366 Write_Str ("make sure you are using consistent versions " &
368 -- Split the following line so that it can easily be transformed for
369 -- e.g. JVM/.NET back-ends where the compiler has a different name.
375 -- Find start of line
379 and then T (Ptr1 - 1) /= CR
380 and then T (Ptr1 - 1) /= LF
385 Write_Int (Int (Line));
400 and then T (Ptr2) /= CR
401 and then T (Ptr2) /= LF
413 if T (Ptr1) = HT then
425 Exit_Program (E_Fatal);
428 ------------------------
429 -- Fatal_Error_Ignore --
430 ------------------------
432 procedure Fatal_Error_Ignore is
434 if not Ignore_Errors then
437 end Fatal_Error_Ignore;
443 function Get_File_Name
444 (Lower : Boolean := False) return File_Name_Type
449 F := Get_Name (Ignore_Special => True);
451 -- Convert file name to all lower case if file names are not case
452 -- sensitive. This ensures that we handle names in the canonical
453 -- lower case format, regardless of the actual case.
455 if Lower and not File_Names_Case_Sensitive then
456 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
459 return File_Name_Type (F);
468 (Ignore_Spaces : Boolean := False;
469 Ignore_Special : Boolean := False) return Name_Id
476 if Ignore_Errors then
484 Name_Len := Name_Len + 1;
485 Name_Buffer (Name_Len) := Getc;
487 exit when At_End_Of_Field and not Ignore_Spaces;
489 if not Ignore_Special then
490 if Name_Buffer (1) = '"' then
491 exit when Name_Len > 1 and then Name_Buffer (Name_Len) = '"';
494 -- Terminate on parens or angle brackets or equal sign
496 exit when Nextc = '(' or else Nextc = ')'
497 or else Nextc = '{' or else Nextc = '}'
498 or else Nextc = '<' or else Nextc = '>'
501 -- Terminate if left bracket not part of wide char sequence
502 -- Note that we only recognize brackets notation so far ???
504 exit when Nextc = '[' and then T (P + 1) /= '"';
506 -- Terminate if right bracket not part of wide char sequence
508 exit when Nextc = ']' and then T (P - 1) /= '"';
520 function Get_Unit_Name return Unit_Name_Type is
522 return Unit_Name_Type (Get_Name);
529 function Get_Nat return Nat is
535 -- Check if we are on a number. In the case of bas ALI files, this
538 if not (Nextc in '0' .. '9') then
544 V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
546 exit when At_End_Of_Field;
547 exit when Nextc < '0' or Nextc > '9';
557 function Get_Stamp return Time_Stamp_Type is
565 if Ignore_Errors then
566 return Dummy_Time_Stamp;
572 -- Following reads old style time stamp missing first two digits
574 if Nextc in '7' .. '9' then
579 -- Normal case of full year in time stamp
585 for J in Start .. T'Last loop
596 procedure Get_Typeref
597 (Current_File_Num : Sdep_Id;
599 File_Num : out Sdep_Id;
601 Ref_Type : out Character;
603 Standard_Entity : out Name_Id)
608 when '<' => Ref := Tref_Derived;
609 when '(' => Ref := Tref_Access;
610 when '{' => Ref := Tref_Type;
611 when others => Ref := Tref_None;
614 -- Case of typeref field present
616 if Ref /= Tref_None then
617 P := P + 1; -- skip opening bracket
619 if Nextc in 'a' .. 'z' then
620 File_Num := No_Sdep_Id;
624 Standard_Entity := Get_Name (Ignore_Spaces => True);
629 File_Num := Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
633 File_Num := Current_File_Num;
639 Standard_Entity := No_Name;
642 -- ??? Temporary workaround for nested generics case:
643 -- 4i4 Directories{1|4I9[4|6[3|3]]}
647 Nested_Brackets : Natural := 0;
653 Nested_Brackets := Nested_Brackets + 1;
655 Nested_Brackets := Nested_Brackets - 1;
657 if Nested_Brackets = 0 then
666 P := P + 1; -- skip closing bracket
669 -- No typeref entry present
672 File_Num := No_Sdep_Id;
676 Standard_Entity := No_Name;
684 function Getc return Character is
698 function Nextc return Character is
707 procedure Skip_Eol is
712 if Ignore_Errors then
713 while not At_Eol loop
721 -- Loop to skip past blank lines (first time through skips this EOL)
723 while Nextc < ' ' and then Nextc /= EOF loop
736 procedure Skip_Line is
738 while not At_Eol loop
749 procedure Skip_Space is
751 while Nextc = ' ' or else Nextc = HT loop
767 -- Start of processing for Scan_ALI
770 First_Sdep_Entry := Sdep.Last + 1;
772 -- Acquire lines to be ignored
775 Ignore := ('U' | 'W' | 'D' | 'X' => False, others => True);
777 -- Read_Lines parameter given
779 elsif Read_Lines /= "" then
780 Ignore := ('U' => False, others => True);
782 for J in Read_Lines'Range loop
783 Ignore (Read_Lines (J)) := False;
786 -- Process Ignore_Lines parameter
789 Ignore := (others => False);
791 for J in Ignore_Lines'Range loop
792 pragma Assert (Ignore_Lines (J) /= 'U');
793 Ignore (Ignore_Lines (J)) := True;
797 -- Setup ALI Table entry with appropriate defaults
801 Set_Name_Table_Info (F, Int (Id));
805 Compile_Errors => False,
806 First_Interrupt_State => Interrupt_States.Last + 1,
807 First_Sdep => No_Sdep_Id,
808 First_Specific_Dispatching => Specific_Dispatching.Last + 1,
809 First_Unit => No_Unit_Id,
811 Last_Interrupt_State => Interrupt_States.Last,
812 Last_Sdep => No_Sdep_Id,
813 Last_Specific_Dispatching => Specific_Dispatching.Last,
814 Last_Unit => No_Unit_Id,
815 Locking_Policy => ' ',
817 Main_Program => None,
819 Normalize_Scalars => False,
820 Ofile_Full_Name => Full_Object_File_Name,
821 Optimize_Alignment_Setting => 'O',
822 Queuing_Policy => ' ',
823 Restrictions => No_Restrictions,
824 SAL_Interface => False,
826 Task_Dispatching_Policy => ' ',
827 Time_Slice_Value => -1,
829 Unit_Exception_Table => False,
830 Ver => (others => ' '),
832 Zero_Cost_Exceptions => False);
834 -- Now we acquire the input lines from the ALI file. Note that the
835 -- convention in the following code is that as we enter each section,
836 -- C is set to contain the first character of the following line.
841 -- Acquire library version
845 -- The V line missing really indicates trouble, most likely it
846 -- means we don't have an ALI file at all, so here we give a
847 -- fatal error even if we are in Ignore_Errors mode.
851 elsif Ignore ('V') then
859 for J in 1 .. Ver_Len_Max loop
862 ALIs.Table (Id).Ver (J) := C;
863 ALIs.Table (Id).Ver_Len := J;
872 -- Acquire main program line if present
885 ALIs.Table (Id).Main_Program := Func;
887 ALIs.Table (Id).Main_Program := Proc;
897 ALIs.Table (Id).Main_Priority := Get_Nat;
905 ALIs.Table (Id).Time_Slice_Value := Get_Nat;
912 ALIs.Table (Id).WC_Encoding := Getc;
921 -- Acquire argument lines
923 First_Arg := Args.Last + 1;
927 exit A_Loop when C /= 'A';
938 while not At_Eol loop
939 Name_Len := Name_Len + 1;
940 Name_Buffer (Name_Len) := Getc;
943 -- If -fstack-check, record that it occurred
945 if Name_Buffer (1 .. Name_Len) = "-fstack-check" then
946 Stack_Check_Switch_Set := True;
949 -- Store the argument
952 Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
965 if Ignore_Errors then
985 while not At_Eol loop
994 ALIs.Table (Id).Compile_Errors := True;
1000 Detect_Blocking := True;
1002 -- Processing for FD/FG/FI
1005 Float_Format_Specified := Getc;
1006 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1008 -- Processing for Lx
1011 Locking_Policy_Specified := Getc;
1012 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1014 -- Processing for flags starting with N
1019 -- Processing for NO
1022 ALIs.Table (Id).No_Object := True;
1023 No_Object_Specified := True;
1025 -- Processing for NR
1028 No_Run_Time_Mode := True;
1029 Configurable_Run_Time_Mode := True;
1031 -- Processing for NS
1034 ALIs.Table (Id).Normalize_Scalars := True;
1035 Normalize_Scalars_Specified := True;
1038 -- Invalid switch starting with N
1044 -- Processing for Ox
1047 ALIs.Table (Id).Optimize_Alignment_Setting := Getc;
1049 -- Processing for Qx
1052 Queuing_Policy_Specified := Getc;
1053 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1055 -- Processing for flags starting with S
1060 -- Processing for SL
1063 ALIs.Table (Id).SAL_Interface := True;
1065 -- Processing for SS
1068 Opt.Sec_Stack_Used := True;
1070 -- Invalid switch starting with S
1076 -- Processing for Tx
1079 Task_Dispatching_Policy_Specified := Getc;
1080 ALIs.Table (Id).Task_Dispatching_Policy :=
1081 Task_Dispatching_Policy_Specified;
1083 -- Processing for switch starting with U
1088 -- Processing for UA
1091 Unreserve_All_Interrupts_Specified := True;
1093 -- Processing for UX
1096 ALIs.Table (Id).Unit_Exception_Table := True;
1098 -- Invalid switches starting with U
1104 -- Processing for ZX
1110 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1111 Zero_Cost_Exceptions_Specified := True;
1116 -- Invalid parameter
1124 if not NS_Found then
1125 No_Normalize_Scalars_Specified := True;
1134 -- Acquire first restrictions line
1137 if Ignore_Errors then
1149 if Ignore ('R') then
1152 -- Process restrictions line
1155 Scan_Restrictions : declare
1156 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1157 -- Save cumulative restrictions in case we have a fatal error
1159 Bad_R_Line : exception;
1160 -- Signal bad restrictions line (raised on unexpected character)
1166 -- Acquire information for boolean restrictions
1168 for R in All_Boolean_Restrictions loop
1173 ALIs.Table (Id).Restrictions.Violated (R) := True;
1174 Cumulative_Restrictions.Violated (R) := True;
1177 ALIs.Table (Id).Restrictions.Set (R) := True;
1178 Cumulative_Restrictions.Set (R) := True;
1188 -- Acquire information for parameter restrictions
1190 for RP in All_Parameter_Restrictions loop
1192 -- Acquire restrictions pragma information
1199 ALIs.Table (Id).Restrictions.Set (RP) := True;
1202 N : constant Integer := Integer (Get_Nat);
1204 ALIs.Table (Id).Restrictions.Value (RP) := N;
1206 if Cumulative_Restrictions.Set (RP) then
1207 Cumulative_Restrictions.Value (RP) :=
1209 (Cumulative_Restrictions.Value (RP), N);
1211 Cumulative_Restrictions.Set (RP) := True;
1212 Cumulative_Restrictions.Value (RP) := N;
1220 -- Acquire restrictions violations information
1227 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1228 Cumulative_Restrictions.Violated (RP) := True;
1231 N : constant Integer := Integer (Get_Nat);
1232 pragma Unsuppress (Overflow_Check);
1235 ALIs.Table (Id).Restrictions.Count (RP) := N;
1237 if RP in Checked_Max_Parameter_Restrictions then
1238 Cumulative_Restrictions.Count (RP) :=
1240 (Cumulative_Restrictions.Count (RP), N);
1242 Cumulative_Restrictions.Count (RP) :=
1243 Cumulative_Restrictions.Count (RP) + N;
1247 when Constraint_Error =>
1249 -- A constraint error comes from the addition in
1250 -- the else branch. We reset to the maximum and
1251 -- indicate that the real value is now unknown.
1253 Cumulative_Restrictions.Value (RP) := Integer'Last;
1254 Cumulative_Restrictions.Unknown (RP) := True;
1259 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1260 Cumulative_Restrictions.Unknown (RP) := True;
1270 -- Here if error during scanning of restrictions line
1275 -- In Ignore_Errors mode, undo any changes to restrictions
1276 -- from this unit, and continue on.
1278 if Ignore_Errors then
1279 Cumulative_Restrictions := Save_R;
1280 ALIs.Table (Id).Restrictions := No_Restrictions;
1283 -- In normal mode, this is a fatal error
1289 end Scan_Restrictions;
1292 -- Acquire additional restrictions (No_Dependence) lines if present
1296 if Ignore ('R') then
1300 No_Deps.Append ((Id, Get_Name));
1307 -- Acquire 'I' lines if present
1312 if Ignore ('I') then
1318 I_State : Character;
1327 Interrupt_States.Append (
1328 (Interrupt_Id => Int_Num,
1329 Interrupt_State => I_State,
1330 IS_Pragma_Line => Line_No));
1332 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1340 -- Acquire 'S' lines if present
1345 if Ignore ('S') then
1361 First_Prio := Get_Nat;
1362 Last_Prio := Get_Nat;
1365 Specific_Dispatching.Append (
1366 (Dispatching_Policy => Policy,
1367 First_Priority => First_Prio,
1368 Last_Priority => Last_Prio,
1369 PSD_Pragma_Line => Line_No));
1371 ALIs.Table (Id).Last_Specific_Dispatching :=
1372 Specific_Dispatching.Last;
1381 -- Loop to acquire unit entries
1385 exit U_Loop when C /= 'U';
1387 -- Note: as per spec, we never ignore U lines
1391 Units.Increment_Last;
1393 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1394 ALIs.Table (Id).First_Unit := Units.Last;
1398 UL : Unit_Record renames Units.Table (Units.Last);
1401 UL.Uname := Get_Unit_Name;
1402 UL.Predefined := Is_Predefined_Unit;
1403 UL.Internal := Is_Internal_Unit;
1405 UL.Sfile := Get_File_Name (Lower => True);
1407 UL.Preelab := False;
1408 UL.No_Elab := False;
1409 UL.Shared_Passive := False;
1411 UL.Remote_Types := False;
1412 UL.Has_RACW := False;
1413 UL.Init_Scalars := False;
1414 UL.Is_Generic := False;
1415 UL.Icasing := Mixed_Case;
1416 UL.Kcasing := All_Lower_Case;
1417 UL.Dynamic_Elab := False;
1418 UL.Elaborate_Body := False;
1419 UL.Set_Elab_Entity := False;
1420 UL.Version := "00000000";
1421 UL.First_With := Withs.Last + 1;
1422 UL.First_Arg := First_Arg;
1423 UL.Elab_Position := 0;
1424 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1425 UL.Body_Needed_For_SAL := False;
1426 UL.Elaborate_Body_Desirable := False;
1428 if Debug_Flag_U then
1429 Write_Str (" ----> reading unit ");
1430 Write_Int (Int (Units.Last));
1432 Write_Unit_Name (UL.Uname);
1433 Write_Str (" from file ");
1434 Write_Name (UL.Sfile);
1439 -- Check for duplicated unit in different files
1442 Info : constant Int := Get_Name_Table_Info
1443 (Units.Table (Units.Last).Uname);
1446 and then Units.Table (Units.Last).Sfile /=
1447 Units.Table (Unit_Id (Info)).Sfile
1449 -- If Err is set then ignore duplicate unit name. This is the
1450 -- case of a call from gnatmake, where the situation can arise
1451 -- from substitution of source files. In such situations, the
1452 -- processing in gnatmake will always result in any required
1453 -- recompilations in any case, and if we consider this to be
1454 -- an error we get strange cases (for example when a generic
1455 -- instantiation is replaced by a normal package) where we
1456 -- read the old ali file, decide to recompile, and then decide
1457 -- that the old and new ali files are incompatible.
1462 -- If Err is not set, then this is a fatal error. This is
1463 -- the case of being called from the binder, where we must
1464 -- definitely diagnose this as an error.
1468 Write_Str ("error: duplicate unit name: ");
1471 Write_Str ("error: unit """);
1472 Write_Unit_Name (Units.Table (Units.Last).Uname);
1473 Write_Str (""" found in file """);
1474 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1478 Write_Str ("error: unit """);
1479 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1480 Write_Str (""" found in file """);
1481 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1485 Exit_Program (E_Fatal);
1491 (Units.Table (Units.Last).Uname, Int (Units.Last));
1493 -- Scan out possible version and other parameters
1502 if C in '0' .. '9' or else C in 'a' .. 'f' then
1503 Units.Table (Units.Last).Version (1) := C;
1505 for J in 2 .. 8 loop
1507 Units.Table (Units.Last).Version (J) := C;
1516 Check_At_End_Of_Field;
1517 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1520 Check_At_End_Of_Field;
1521 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1527 -- DE parameter (Dynamic elaboration checks)
1533 Check_At_End_Of_Field;
1534 Units.Table (Units.Last).Dynamic_Elab := True;
1535 Dynamic_Elaboration_Checks_Specified := True;
1546 Units.Table (Units.Last).Elaborate_Body := True;
1548 Units.Table (Units.Last).Set_Elab_Entity := True;
1553 Check_At_End_Of_Field;
1555 -- GE parameter (generic)
1561 Check_At_End_Of_Field;
1562 Units.Table (Units.Last).Is_Generic := True;
1567 -- IL/IS/IU parameters
1573 Units.Table (Units.Last).Icasing := All_Lower_Case;
1575 Units.Table (Units.Last).Init_Scalars := True;
1576 Initialize_Scalars_Used := True;
1578 Units.Table (Units.Last).Icasing := All_Upper_Case;
1583 Check_At_End_Of_Field;
1591 Units.Table (Units.Last).Kcasing := Mixed_Case;
1593 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1598 Check_At_End_Of_Field;
1606 Units.Table (Units.Last).No_Elab := True;
1607 Check_At_End_Of_Field;
1612 -- PR/PU/PK parameters
1618 Units.Table (Units.Last).Preelab := True;
1620 Units.Table (Units.Last).Pure := True;
1622 Units.Table (Units.Last).Unit_Kind := 'p';
1627 Check_At_End_Of_Field;
1635 Units.Table (Units.Last).RCI := True;
1637 Units.Table (Units.Last).Remote_Types := True;
1639 Units.Table (Units.Last).Has_RACW := True;
1644 Check_At_End_Of_Field;
1650 Units.Table (Units.Last).Shared_Passive := True;
1652 Units.Table (Units.Last).Unit_Kind := 's';
1657 Check_At_End_Of_Field;
1667 -- Check if static elaboration model used
1669 if not Units.Table (Units.Last).Dynamic_Elab
1670 and then not Units.Table (Units.Last).Internal
1672 Static_Elaboration_Model_Used := True;
1677 -- Scan out With lines for this unit
1681 exit With_Loop when C /= 'W';
1683 if Ignore ('W') then
1689 Withs.Increment_Last;
1690 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1691 Withs.Table (Withs.Last).Elaborate := False;
1692 Withs.Table (Withs.Last).Elaborate_All := False;
1693 Withs.Table (Withs.Last).Elab_Desirable := False;
1694 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1695 Withs.Table (Withs.Last).SAL_Interface := False;
1697 -- Generic case with no object file available
1700 Withs.Table (Withs.Last).Sfile := No_File;
1701 Withs.Table (Withs.Last).Afile := No_File;
1706 Withs.Table (Withs.Last).Sfile := Get_File_Name
1708 Withs.Table (Withs.Last).Afile := Get_File_Name
1711 -- Scan out possible E, EA, ED, and AD parameters
1713 while not At_Eol loop
1719 Check_At_End_Of_Field;
1721 -- Store AD indication unless ignore required
1723 if not Ignore_ED then
1724 Withs.Table (Withs.Last).Elab_All_Desirable :=
1728 elsif Nextc = 'E' then
1731 if At_End_Of_Field then
1732 Withs.Table (Withs.Last).Elaborate := True;
1734 elsif Nextc = 'A' then
1736 Check_At_End_Of_Field;
1737 Withs.Table (Withs.Last).Elaborate_All := True;
1741 Check_At_End_Of_Field;
1743 -- Store ED indication unless ignore required
1745 if not Ignore_ED then
1746 Withs.Table (Withs.Last).Elab_Desirable :=
1763 Units.Table (Units.Last).Last_With := Withs.Last;
1764 Units.Table (Units.Last).Last_Arg := Args.Last;
1766 -- If there are linker options lines present, scan them
1770 Linker_Options_Loop : loop
1772 exit Linker_Options_Loop when C /= 'L';
1774 if Ignore ('L') then
1785 if C < Character'Val (16#20#)
1786 or else C > Character'Val (16#7E#)
1791 C := Character'Val (0);
1798 for J in 1 .. 2 loop
1801 if C in '0' .. '9' then
1804 Character'Pos ('0');
1806 elsif C in 'A' .. 'F' then
1809 Character'Pos ('A') +
1818 Add_Char_To_Name_Buffer (Character'Val (V));
1823 exit when Nextc /= '"';
1827 Add_Char_To_Name_Buffer (C);
1831 Add_Char_To_Name_Buffer (nul);
1836 end loop Linker_Options_Loop;
1838 -- Store the linker options entry if one was found
1840 if Name_Len /= 0 then
1841 Linker_Options.Increment_Last;
1843 Linker_Options.Table (Linker_Options.Last).Name :=
1846 Linker_Options.Table (Linker_Options.Last).Unit :=
1849 Linker_Options.Table (Linker_Options.Last).Internal_File :=
1850 Is_Internal_File_Name (F);
1852 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1853 Linker_Options.Last;
1857 -- End loop through units for one ALI file
1859 ALIs.Table (Id).Last_Unit := Units.Last;
1860 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1862 -- Set types of the units (there can be at most 2 of them)
1864 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1865 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1866 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
1869 -- Deal with body only and spec only cases, note that the reason we
1870 -- do our own checking of the name (rather than using Is_Body_Name)
1871 -- is that Uname drags in far too much compiler junk!
1873 Get_Name_String (Units.Table (Units.Last).Uname);
1875 if Name_Buffer (Name_Len) = 'b' then
1876 Units.Table (Units.Last).Utype := Is_Body_Only;
1878 Units.Table (Units.Last).Utype := Is_Spec_Only;
1882 -- Scan out external version references and put in hash table
1886 exit E_Loop when C /= 'E';
1888 if Ignore ('E') then
1904 exit when At_End_Of_Field;
1905 Add_Char_To_Name_Buffer (C);
1908 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1915 -- Scan out source dependency lines for this ALI file
1917 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
1921 exit D_Loop when C /= 'D';
1923 if Ignore ('D') then
1929 Sdep.Increment_Last;
1931 -- In the following call, Lower is not set to True, this is either
1932 -- a bug, or it deserves a special comment as to why this is so???
1934 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
1936 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
1937 Sdep.Table (Sdep.Last).Dummy_Entry :=
1938 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
1940 -- Acquire checksum value
1953 exit when At_Eol or else Ctr = 8;
1955 if Nextc in '0' .. '9' then
1957 Character'Pos (Nextc) - Character'Pos ('0');
1959 elsif Nextc in 'a' .. 'f' then
1961 Character'Pos (Nextc) - Character'Pos ('a') + 10;
1971 if Ctr = 8 and then At_End_Of_Field then
1972 Sdep.Table (Sdep.Last).Checksum := Chk;
1978 -- Acquire subunit and reference file name entries
1980 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
1981 Sdep.Table (Sdep.Last).Rfile :=
1982 Sdep.Table (Sdep.Last).Sfile;
1983 Sdep.Table (Sdep.Last).Start_Line := 1;
1988 -- Here for subunit name
1990 if Nextc not in '0' .. '9' then
1993 while not At_End_Of_Field loop
1994 Name_Len := Name_Len + 1;
1995 Name_Buffer (Name_Len) := Getc;
1998 Sdep.Table (Sdep.Last).Subunit_Name := Name_Enter;
2002 -- Here for reference file name entry
2004 if Nextc in '0' .. '9' then
2005 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2010 while not At_End_Of_Field loop
2011 Name_Len := Name_Len + 1;
2012 Name_Buffer (Name_Len) := Getc;
2015 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2025 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2027 -- We must at this stage be at an Xref line or the end of file
2039 -- If we are ignoring Xref sections we are done (we ignore all
2040 -- remaining lines since only xref related lines follow X).
2042 if Ignore ('X') and then not Debug_Flag_X then
2046 -- Loop through Xref sections
2050 exit X_Loop when C /= 'X';
2052 -- Make new entry in section table
2054 Xref_Section.Increment_Last;
2056 Read_Refs_For_One_File : declare
2057 XS : Xref_Section_Record renames
2058 Xref_Section.Table (Xref_Section.Last);
2060 Current_File_Num : Sdep_Id;
2061 -- Keeps track of the current file number (changed by nn|)
2064 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2065 XS.File_Name := Get_File_Name;
2066 XS.First_Entity := Xref_Entity.Last + 1;
2068 Current_File_Num := XS.File_Num;
2075 -- Loop through Xref entities
2077 while C /= 'X' and then C /= EOF loop
2078 Xref_Entity.Increment_Last;
2080 Read_Refs_For_One_Entity : declare
2081 XE : Xref_Entity_Record renames
2082 Xref_Entity.Table (Xref_Entity.Last);
2085 procedure Read_Instantiation_Reference;
2086 -- Acquire instantiation reference. Caller has checked
2087 -- that current character is '[' and on return the cursor
2088 -- is skipped past the corresponding closing ']'.
2090 ----------------------------------
2091 -- Read_Instantiation_Reference --
2092 ----------------------------------
2094 procedure Read_Instantiation_Reference is
2095 Local_File_Num : Sdep_Id := Current_File_Num;
2098 Xref.Increment_Last;
2101 XR : Xref_Record renames Xref.Table (Xref.Last);
2104 P := P + 1; -- skip [
2109 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2110 Local_File_Num := XR.File_Num;
2115 XR.File_Num := Local_File_Num;
2122 -- Recursive call for next reference
2125 pragma Warnings (Off); -- kill recursion warning
2126 Read_Instantiation_Reference;
2127 pragma Warnings (On);
2130 -- Skip closing bracket after recursive call
2134 end Read_Instantiation_Reference;
2136 -- Start of processing for Read_Refs_For_One_Entity
2142 XE.Lib := (Getc = '*');
2143 XE.Entity := Get_Name;
2145 -- Handle the information about generic instantiations
2148 Skipc; -- Opening '['
2151 if Nextc /= '|' then
2152 XE.Iref_File_Num := Current_File_Num;
2156 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2158 XE.Iref_Line := Get_Nat;
2166 XE.Iref_File_Num := No_Sdep_Id;
2170 Current_File_Num := XS.File_Num;
2172 -- Renaming reference is present
2176 XE.Rref_Line := Get_Nat;
2182 XE.Rref_Col := Get_Nat;
2184 -- No renaming reference present
2193 XE.Oref_File_Num := No_Sdep_Id;
2194 XE.Tref_File_Num := No_Sdep_Id;
2195 XE.Tref := Tref_None;
2196 XE.First_Xref := Xref.Last + 1;
2198 -- Loop to check for additional info present
2211 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2212 exit when Ref = Tref_None;
2214 -- Do we have an overriding procedure?
2216 if Ref = Tref_Derived and then Typ = 'p' then
2217 XE.Oref_File_Num := File;
2218 XE.Oref_Line := Line;
2221 -- Arrays never override anything, and <> points to
2222 -- the index types instead
2224 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2226 -- Index types are stored in the list of references
2228 Xref.Increment_Last;
2231 XR : Xref_Record renames Xref.Table (Xref.Last);
2233 XR.File_Num := File;
2235 XR.Rtype := Array_Index_Reference;
2240 -- Interfaces are stored in the list of references,
2241 -- although the parent type itself is stored in XE
2243 elsif Ref = Tref_Derived
2245 and then XE.Tref_File_Num /= No_Sdep_Id
2247 Xref.Increment_Last;
2250 XR : Xref_Record renames Xref.Table (Xref.Last);
2252 XR.File_Num := File;
2254 XR.Rtype := Interface_Reference;
2261 XE.Tref_File_Num := File;
2262 XE.Tref_Line := Line;
2263 XE.Tref_Type := Typ;
2265 XE.Tref_Standard_Entity := Std;
2270 -- Loop through cross-references for this entity
2277 exit when Nextc /= '.';
2281 Xref.Increment_Last;
2284 XR : Xref_Record renames Xref.Table (Xref.Last);
2291 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2292 Current_File_Num := XR.File_Num;
2296 XR.File_Num := Current_File_Num;
2302 -- Imported entities reference as in:
2303 -- 494b<c,__gnat_copy_attribs>25
2304 -- ??? Simply skipped for now
2307 while Getc /= '>' loop
2315 Read_Instantiation_Reference;
2320 -- Record last cross-reference
2322 XE.Last_Xref := Xref.Last;
2326 when Bad_ALI_Format =>
2328 -- If ignoring errors, then we skip a line with an
2329 -- unexpected error, and try to continue subsequent
2332 if Ignore_Errors then
2333 Xref_Entity.Decrement_Last;
2337 -- Otherwise, we reraise the fatal exception
2342 end Read_Refs_For_One_Entity;
2345 -- Record last entity
2347 XS.Last_Entity := Xref_Entity.Last;
2349 end Read_Refs_For_One_File;
2354 -- Here after dealing with xref sections
2356 if C /= EOF and then C /= 'X' then
2363 when Bad_ALI_Format =>
2371 function SEq (F1, F2 : String_Ptr) return Boolean is
2373 return F1.all = F2.all;
2380 function SHash (S : String_Ptr) return Vindex is
2385 for J in S.all'Range loop
2386 H := H * 2 + Character'Pos (S (J));
2389 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));