1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, 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
64 procedure Initialize_ALI is
66 -- When (re)initializing ALI data structures the ALI user expects to
67 -- get a fresh set of data structures. Thus we first need to erase the
68 -- marks put in the name table by the previous set of ALI routine calls.
69 -- These two loops are empty and harmless the first time in.
71 for J in ALIs.First .. ALIs.Last loop
72 Set_Name_Table_Info (ALIs.Table (J).Afile, 0);
75 for J in Units.First .. Units.Last loop
76 Set_Name_Table_Info (Units.Table (J).Uname, 0);
79 -- Free argument table strings
81 for J in Args.First .. Args.Last loop
82 Free (Args.Table (J));
85 -- Initialize all tables
99 -- Add dummy zero'th item in Linker_Options and Notes for sort calls
101 Linker_Options.Increment_Last;
102 Notes.Increment_Last;
104 -- Initialize global variables recording cumulative options in all
105 -- ALI files that are read for a given processing run in gnatbind.
107 Dynamic_Elaboration_Checks_Specified := False;
108 Float_Format_Specified := ' ';
109 Locking_Policy_Specified := ' ';
110 No_Normalize_Scalars_Specified := False;
111 No_Object_Specified := False;
112 Normalize_Scalars_Specified := False;
113 Queuing_Policy_Specified := ' ';
114 Static_Elaboration_Model_Used := False;
115 Task_Dispatching_Policy_Specified := ' ';
116 Unreserve_All_Interrupts_Specified := False;
117 Zero_Cost_Exceptions_Specified := False;
129 Read_Xref : Boolean := False;
130 Read_Lines : String := "";
131 Ignore_Lines : String := "X";
132 Ignore_Errors : Boolean := False;
133 Directly_Scanned : Boolean := False) return ALI_Id
135 P : Text_Ptr := T'First;
136 Line : Logical_Line_Number := 1;
142 Ignore : array (Character range 'A' .. 'Z') of Boolean;
143 -- Ignore (X) is set to True if lines starting with X are to
144 -- be ignored by Scan_ALI and skipped, and False if the lines
145 -- are to be read and processed.
147 Bad_ALI_Format : exception;
148 -- Exception raised by Fatal_Error if Err is True
150 function At_Eol return Boolean;
151 -- Test if at end of line
153 function At_End_Of_Field return Boolean;
154 -- Test if at end of line, or if at blank or horizontal tab
156 procedure Check_At_End_Of_Field;
157 -- Check if we are at end of field, fatal error if not
159 procedure Checkc (C : Character);
160 -- Check next character is C. If so bump past it, if not fatal error
162 procedure Check_Unknown_Line;
163 -- If Ignore_Errors mode, then checks C to make sure that it is not
164 -- an unknown ALI line type characters, and if so, skips lines
165 -- until the first character of the line is one of these characters,
166 -- at which point it does a Getc to put that character in C. The
167 -- call has no effect if C is already an appropriate character.
168 -- If not in Ignore_Errors mode, a fatal error is signalled if the
169 -- line is unknown. Note that if C is an EOL on entry, the line is
170 -- skipped (it is assumed that blank lines are never significant).
171 -- If C is EOF on entry, the call has no effect (it is assumed that
172 -- the caller will properly handle this case).
174 procedure Fatal_Error;
175 -- Generate fatal error message for badly formatted ALI file if
176 -- Err is false, or raise Bad_ALI_Format if Err is True.
178 procedure Fatal_Error_Ignore;
179 pragma Inline (Fatal_Error_Ignore);
180 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
182 function Getc return Character;
183 -- Get next character, bumping P past the character obtained
185 function Get_File_Name (Lower : Boolean := False) return File_Name_Type;
186 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
187 -- with length in Name_Len, as well as returning a File_Name_Type value.
188 -- If lower is false, the case is unchanged, if Lower is True then the
189 -- result is forced to all lower case for systems where file names are
190 -- not case sensitive. This ensures that gnatbind works correctly
191 -- regardless of the case of the file name on all systems. The scan
192 -- is terminated by a end of line, space or horizontal tab. Any other
193 -- special characters are included in the returned name.
196 (Ignore_Spaces : Boolean := False;
197 Ignore_Special : Boolean := False) return Name_Id;
198 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
199 -- length in Name_Len, as well as being returned in Name_Id form).
200 -- If Lower is set to True then the Name_Buffer will be converted to
201 -- all lower case, for systems where file names are not case sensitive.
202 -- This ensures that gnatbind works correctly regardless of the case
203 -- of the file name on all systems. The termination condition depends
204 -- on the settings of Ignore_Spaces and Ignore_Special:
206 -- If Ignore_Spaces is False (normal case), then scan is terminated
207 -- by the normal end of field condition (EOL, space, horizontal tab)
209 -- If Ignore_Special is False (normal case), the scan is terminated by
210 -- a typeref bracket or an equal sign except for the special case of
211 -- an operator name starting with a double quote which is terminated
212 -- by another double quote.
214 -- It is an error to set both Ignore_Spaces and Ignore_Special to True.
215 -- This function handles wide characters properly.
217 function Get_Nat return Nat;
218 -- Skip blanks, then scan out an unsigned integer value in Nat range
219 -- raises ALI_Reading_Error if the encoutered type is not natural.
221 function Get_Stamp return Time_Stamp_Type;
222 -- Skip blanks, then scan out a time stamp
224 function Get_Unit_Name return Unit_Name_Type;
225 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
226 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
227 -- The case is unchanged and terminated by a normal end of field.
229 function Nextc return Character;
230 -- Return current character without modifying pointer P
232 procedure Get_Typeref
233 (Current_File_Num : Sdep_Id;
235 File_Num : out Sdep_Id;
237 Ref_Type : out Character;
239 Standard_Entity : out Name_Id);
240 -- Parse the definition of a typeref (<...>, {...} or (...))
243 -- Skip past spaces, then skip past end of line (fatal error if not
244 -- at end of line). Also skips past any following blank lines.
247 -- Skip rest of current line and any following blank lines
249 procedure Skip_Space;
250 -- Skip past white space (blanks or horizontal tab)
253 -- Skip past next character, does not affect value in C. This call
254 -- is like calling Getc and ignoring the returned result.
256 ---------------------
257 -- At_End_Of_Field --
258 ---------------------
260 function At_End_Of_Field return Boolean is
269 function At_Eol return Boolean is
271 return Nextc = EOF or else Nextc = CR or else Nextc = LF;
274 ---------------------------
275 -- Check_At_End_Of_Field --
276 ---------------------------
278 procedure Check_At_End_Of_Field is
280 if not At_End_Of_Field then
281 if Ignore_Errors then
282 while Nextc > ' ' loop
289 end Check_At_End_Of_Field;
291 ------------------------
292 -- Check_Unknown_Line --
293 ------------------------
295 procedure Check_Unknown_Line is
297 while C not in 'A' .. 'Z'
298 or else not Known_ALI_Lines (C)
300 if C = CR or else C = LF then
307 elsif Ignore_Errors then
315 end Check_Unknown_Line;
321 procedure Checkc (C : Character) is
325 elsif Ignore_Errors then
336 procedure Fatal_Error is
341 procedure Wchar (C : Character);
342 -- Write a single character, replacing horizontal tab by spaces
344 procedure Wchar (C : Character) is
349 exit when Col mod 8 = 0;
358 -- Start of processing for Fatal_Error
362 raise Bad_ALI_Format;
366 Write_Str ("fatal error: file ");
368 Write_Str (" is incorrectly formatted");
371 Write_Str ("make sure you are using consistent versions " &
373 -- Split the following line so that it can easily be transformed for
374 -- e.g. JVM/.NET back-ends where the compiler has a different name.
380 -- Find start of line
384 and then T (Ptr1 - 1) /= CR
385 and then T (Ptr1 - 1) /= LF
390 Write_Int (Int (Line));
405 and then T (Ptr2) /= CR
406 and then T (Ptr2) /= LF
418 if T (Ptr1) = HT then
430 Exit_Program (E_Fatal);
433 ------------------------
434 -- Fatal_Error_Ignore --
435 ------------------------
437 procedure Fatal_Error_Ignore is
439 if not Ignore_Errors then
442 end Fatal_Error_Ignore;
448 function Get_File_Name
449 (Lower : Boolean := False) return File_Name_Type
454 F := Get_Name (Ignore_Special => True);
456 -- Convert file name to all lower case if file names are not case
457 -- sensitive. This ensures that we handle names in the canonical
458 -- lower case format, regardless of the actual case.
460 if Lower and not File_Names_Case_Sensitive then
461 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
464 return File_Name_Type (F);
473 (Ignore_Spaces : Boolean := False;
474 Ignore_Special : Boolean := False) return Name_Id
481 if Ignore_Errors then
489 Add_Char_To_Name_Buffer (Getc);
491 exit when At_End_Of_Field and then not Ignore_Spaces;
493 if not Ignore_Special then
494 if Name_Buffer (1) = '"' then
495 exit when Name_Len > 1 and then Name_Buffer (Name_Len) = '"';
498 -- Terminate on parens or angle brackets or equal sign
500 exit when Nextc = '(' or else Nextc = ')'
501 or else Nextc = '{' or else Nextc = '}'
502 or else Nextc = '<' or else Nextc = '>'
505 -- Terminate if left bracket not part of wide char sequence
506 -- Note that we only recognize brackets notation so far ???
508 exit when Nextc = '[' and then T (P + 1) /= '"';
510 -- Terminate if right bracket not part of wide char sequence
512 exit when Nextc = ']' and then T (P - 1) /= '"';
524 function Get_Unit_Name return Unit_Name_Type is
526 return Unit_Name_Type (Get_Name);
533 function Get_Nat return Nat is
539 -- Check if we are on a number. In the case of bad ALI files, this
542 if not (Nextc in '0' .. '9') then
548 V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
550 exit when At_End_Of_Field;
551 exit when Nextc < '0' or else Nextc > '9';
561 function Get_Stamp return Time_Stamp_Type is
569 if Ignore_Errors then
570 return Dummy_Time_Stamp;
576 -- Following reads old style time stamp missing first two digits
578 if Nextc in '7' .. '9' then
583 -- Normal case of full year in time stamp
589 for J in Start .. T'Last loop
600 procedure Get_Typeref
601 (Current_File_Num : Sdep_Id;
603 File_Num : out Sdep_Id;
605 Ref_Type : out Character;
607 Standard_Entity : out Name_Id)
612 when '<' => Ref := Tref_Derived;
613 when '(' => Ref := Tref_Access;
614 when '{' => Ref := Tref_Type;
615 when others => Ref := Tref_None;
618 -- Case of typeref field present
620 if Ref /= Tref_None then
621 P := P + 1; -- skip opening bracket
623 if Nextc in 'a' .. 'z' then
624 File_Num := No_Sdep_Id;
628 Standard_Entity := Get_Name (Ignore_Spaces => True);
633 File_Num := Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
637 File_Num := Current_File_Num;
643 Standard_Entity := No_Name;
646 -- ??? Temporary workaround for nested generics case:
647 -- 4i4 Directories{1|4I9[4|6[3|3]]}
651 Nested_Brackets : Natural := 0;
657 Nested_Brackets := Nested_Brackets + 1;
659 Nested_Brackets := Nested_Brackets - 1;
661 if Nested_Brackets = 0 then
670 P := P + 1; -- skip closing bracket
673 -- No typeref entry present
676 File_Num := No_Sdep_Id;
680 Standard_Entity := No_Name;
688 function Getc return Character is
702 function Nextc return Character is
711 procedure Skip_Eol is
716 if Ignore_Errors then
717 while not At_Eol loop
725 -- Loop to skip past blank lines (first time through skips this EOL)
727 while Nextc < ' ' and then Nextc /= EOF loop
740 procedure Skip_Line is
742 while not At_Eol loop
753 procedure Skip_Space is
755 while Nextc = ' ' or else Nextc = HT loop
771 -- Start of processing for Scan_ALI
774 First_Sdep_Entry := Sdep.Last + 1;
776 -- Acquire lines to be ignored
779 Ignore := ('U' | 'W' | 'Y' | 'D' | 'X' => False, others => True);
781 -- Read_Lines parameter given
783 elsif Read_Lines /= "" then
784 Ignore := ('U' => False, others => True);
786 for J in Read_Lines'Range loop
787 Ignore (Read_Lines (J)) := False;
790 -- Process Ignore_Lines parameter
793 Ignore := (others => False);
795 for J in Ignore_Lines'Range loop
796 pragma Assert (Ignore_Lines (J) /= 'U');
797 Ignore (Ignore_Lines (J)) := True;
801 -- Setup ALI Table entry with appropriate defaults
805 Set_Name_Table_Info (F, Int (Id));
809 Compile_Errors => False,
810 First_Interrupt_State => Interrupt_States.Last + 1,
811 First_Sdep => No_Sdep_Id,
812 First_Specific_Dispatching => Specific_Dispatching.Last + 1,
813 First_Unit => No_Unit_Id,
815 Last_Interrupt_State => Interrupt_States.Last,
816 Last_Sdep => No_Sdep_Id,
817 Last_Specific_Dispatching => Specific_Dispatching.Last,
818 Last_Unit => No_Unit_Id,
819 Locking_Policy => ' ',
821 Main_Program => None,
823 Normalize_Scalars => False,
824 Ofile_Full_Name => Full_Object_File_Name,
825 Queuing_Policy => ' ',
826 Restrictions => No_Restrictions,
827 SAL_Interface => False,
829 Task_Dispatching_Policy => ' ',
830 Time_Slice_Value => -1,
832 Unit_Exception_Table => False,
833 Ver => (others => ' '),
835 Zero_Cost_Exceptions => False);
837 -- Now we acquire the input lines from the ALI file. Note that the
838 -- convention in the following code is that as we enter each section,
839 -- C is set to contain the first character of the following line.
844 -- Acquire library version
848 -- The V line missing really indicates trouble, most likely it
849 -- means we don't have an ALI file at all, so here we give a
850 -- fatal error even if we are in Ignore_Errors mode.
854 elsif Ignore ('V') then
862 for J in 1 .. Ver_Len_Max loop
865 ALIs.Table (Id).Ver (J) := C;
866 ALIs.Table (Id).Ver_Len := J;
875 -- Acquire main program line if present
888 ALIs.Table (Id).Main_Program := Func;
890 ALIs.Table (Id).Main_Program := Proc;
900 ALIs.Table (Id).Main_Priority := Get_Nat;
908 ALIs.Table (Id).Time_Slice_Value := Get_Nat;
915 ALIs.Table (Id).WC_Encoding := Getc;
924 -- Acquire argument lines
926 First_Arg := Args.Last + 1;
930 exit A_Loop when C /= 'A';
941 while not At_Eol loop
942 Add_Char_To_Name_Buffer (Getc);
945 -- If -fstack-check, record that it occurred
947 if Name_Buffer (1 .. Name_Len) = "-fstack-check" then
948 Stack_Check_Switch_Set := True;
951 -- Store the argument
954 Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
967 if Ignore_Errors then
987 while not At_Eol loop
996 ALIs.Table (Id).Compile_Errors := True;
1002 Detect_Blocking := True;
1004 -- Processing for FD/FG/FI
1007 Float_Format_Specified := Getc;
1008 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1010 -- Processing for Lx
1013 Locking_Policy_Specified := Getc;
1014 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1016 -- Processing for flags starting with N
1021 -- Processing for NO
1024 ALIs.Table (Id).No_Object := True;
1025 No_Object_Specified := True;
1027 -- Processing for NR
1030 No_Run_Time_Mode := True;
1031 Configurable_Run_Time_Mode := True;
1033 -- Processing for NS
1036 ALIs.Table (Id).Normalize_Scalars := True;
1037 Normalize_Scalars_Specified := True;
1040 -- Invalid switch starting with N
1046 -- Processing for Qx
1049 Queuing_Policy_Specified := Getc;
1050 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1052 -- Processing for flags starting with S
1057 -- Processing for SL
1060 ALIs.Table (Id).SAL_Interface := True;
1062 -- Processing for SS
1065 Opt.Sec_Stack_Used := True;
1067 -- Invalid switch starting with S
1073 -- Processing for Tx
1076 Task_Dispatching_Policy_Specified := Getc;
1077 ALIs.Table (Id).Task_Dispatching_Policy :=
1078 Task_Dispatching_Policy_Specified;
1080 -- Processing for switch starting with U
1085 -- Processing for UA
1088 Unreserve_All_Interrupts_Specified := True;
1090 -- Processing for UX
1093 ALIs.Table (Id).Unit_Exception_Table := True;
1095 -- Invalid switches starting with U
1101 -- Processing for ZX
1107 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1108 Zero_Cost_Exceptions_Specified := True;
1113 -- Invalid parameter
1121 if not NS_Found then
1122 No_Normalize_Scalars_Specified := True;
1131 -- Acquire first restrictions line
1134 if Ignore_Errors then
1146 if Ignore ('R') then
1149 -- Process restrictions line
1152 Scan_Restrictions : declare
1153 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1154 -- Save cumulative restrictions in case we have a fatal error
1156 Bad_R_Line : exception;
1157 -- Signal bad restrictions line (raised on unexpected character)
1163 -- Acquire information for boolean restrictions
1165 for R in All_Boolean_Restrictions loop
1170 ALIs.Table (Id).Restrictions.Violated (R) := True;
1171 Cumulative_Restrictions.Violated (R) := True;
1174 ALIs.Table (Id).Restrictions.Set (R) := True;
1175 Cumulative_Restrictions.Set (R) := True;
1185 -- Acquire information for parameter restrictions
1187 for RP in All_Parameter_Restrictions loop
1189 -- Acquire restrictions pragma information
1196 ALIs.Table (Id).Restrictions.Set (RP) := True;
1199 N : constant Integer := Integer (Get_Nat);
1201 ALIs.Table (Id).Restrictions.Value (RP) := N;
1203 if Cumulative_Restrictions.Set (RP) then
1204 Cumulative_Restrictions.Value (RP) :=
1206 (Cumulative_Restrictions.Value (RP), N);
1208 Cumulative_Restrictions.Set (RP) := True;
1209 Cumulative_Restrictions.Value (RP) := N;
1217 -- Acquire restrictions violations information
1224 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1225 Cumulative_Restrictions.Violated (RP) := True;
1228 N : constant Integer := Integer (Get_Nat);
1229 pragma Unsuppress (Overflow_Check);
1232 ALIs.Table (Id).Restrictions.Count (RP) := N;
1234 if RP in Checked_Max_Parameter_Restrictions then
1235 Cumulative_Restrictions.Count (RP) :=
1237 (Cumulative_Restrictions.Count (RP), N);
1239 Cumulative_Restrictions.Count (RP) :=
1240 Cumulative_Restrictions.Count (RP) + N;
1244 when Constraint_Error =>
1246 -- A constraint error comes from the addition in
1247 -- the else branch. We reset to the maximum and
1248 -- indicate that the real value is now unknown.
1250 Cumulative_Restrictions.Value (RP) := Integer'Last;
1251 Cumulative_Restrictions.Unknown (RP) := True;
1256 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1257 Cumulative_Restrictions.Unknown (RP) := True;
1267 -- Here if error during scanning of restrictions line
1272 -- In Ignore_Errors mode, undo any changes to restrictions
1273 -- from this unit, and continue on.
1275 if Ignore_Errors then
1276 Cumulative_Restrictions := Save_R;
1277 ALIs.Table (Id).Restrictions := No_Restrictions;
1280 -- In normal mode, this is a fatal error
1286 end Scan_Restrictions;
1289 -- Acquire additional restrictions (No_Dependence) lines if present
1293 if Ignore ('R') then
1297 No_Deps.Append ((Id, Get_Name));
1304 -- Acquire 'I' lines if present
1309 if Ignore ('I') then
1315 I_State : Character;
1324 Interrupt_States.Append (
1325 (Interrupt_Id => Int_Num,
1326 Interrupt_State => I_State,
1327 IS_Pragma_Line => Line_No));
1329 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1337 -- Acquire 'S' lines if present
1342 if Ignore ('S') then
1358 First_Prio := Get_Nat;
1359 Last_Prio := Get_Nat;
1362 Specific_Dispatching.Append (
1363 (Dispatching_Policy => Policy,
1364 First_Priority => First_Prio,
1365 Last_Priority => Last_Prio,
1366 PSD_Pragma_Line => Line_No));
1368 ALIs.Table (Id).Last_Specific_Dispatching :=
1369 Specific_Dispatching.Last;
1378 -- Loop to acquire unit entries
1382 exit U_Loop when C /= 'U';
1384 -- Note: as per spec, we never ignore U lines
1388 Units.Increment_Last;
1390 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1391 ALIs.Table (Id).First_Unit := Units.Last;
1395 UL : Unit_Record renames Units.Table (Units.Last);
1398 UL.Uname := Get_Unit_Name;
1399 UL.Predefined := Is_Predefined_Unit;
1400 UL.Internal := Is_Internal_Unit;
1402 UL.Sfile := Get_File_Name (Lower => True);
1404 UL.Preelab := False;
1405 UL.No_Elab := False;
1406 UL.Shared_Passive := False;
1408 UL.Remote_Types := False;
1409 UL.Has_RACW := False;
1410 UL.Init_Scalars := False;
1411 UL.Is_Generic := False;
1412 UL.Icasing := Mixed_Case;
1413 UL.Kcasing := All_Lower_Case;
1414 UL.Dynamic_Elab := False;
1415 UL.Elaborate_Body := False;
1416 UL.Set_Elab_Entity := False;
1417 UL.Version := "00000000";
1418 UL.First_With := Withs.Last + 1;
1419 UL.First_Arg := First_Arg;
1420 UL.Elab_Position := 0;
1421 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1422 UL.Directly_Scanned := Directly_Scanned;
1423 UL.Body_Needed_For_SAL := False;
1424 UL.Elaborate_Body_Desirable := False;
1425 UL.Optimize_Alignment := 'O';
1427 if Debug_Flag_U then
1428 Write_Str (" ----> reading unit ");
1429 Write_Int (Int (Units.Last));
1431 Write_Unit_Name (UL.Uname);
1432 Write_Str (" from file ");
1433 Write_Name (UL.Sfile);
1438 -- Check for duplicated unit in different files
1441 Info : constant Int := Get_Name_Table_Info
1442 (Units.Table (Units.Last).Uname);
1445 and then Units.Table (Units.Last).Sfile /=
1446 Units.Table (Unit_Id (Info)).Sfile
1448 -- If Err is set then ignore duplicate unit name. This is the
1449 -- case of a call from gnatmake, where the situation can arise
1450 -- from substitution of source files. In such situations, the
1451 -- processing in gnatmake will always result in any required
1452 -- recompilations in any case, and if we consider this to be
1453 -- an error we get strange cases (for example when a generic
1454 -- instantiation is replaced by a normal package) where we
1455 -- read the old ali file, decide to recompile, and then decide
1456 -- that the old and new ali files are incompatible.
1461 -- If Err is not set, then this is a fatal error. This is
1462 -- the case of being called from the binder, where we must
1463 -- definitely diagnose this as an error.
1467 Write_Str ("error: duplicate unit name: ");
1470 Write_Str ("error: unit """);
1471 Write_Unit_Name (Units.Table (Units.Last).Uname);
1472 Write_Str (""" found in file """);
1473 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1477 Write_Str ("error: unit """);
1478 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1479 Write_Str (""" found in file """);
1480 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1484 Exit_Program (E_Fatal);
1490 (Units.Table (Units.Last).Uname, Int (Units.Last));
1492 -- Scan out possible version and other parameters
1501 if C in '0' .. '9' or else C in 'a' .. 'f' then
1502 Units.Table (Units.Last).Version (1) := C;
1504 for J in 2 .. 8 loop
1506 Units.Table (Units.Last).Version (J) := C;
1515 Check_At_End_Of_Field;
1516 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1519 Check_At_End_Of_Field;
1520 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1526 -- DE parameter (Dynamic elaboration checks)
1532 Check_At_End_Of_Field;
1533 Units.Table (Units.Last).Dynamic_Elab := True;
1534 Dynamic_Elaboration_Checks_Specified := True;
1545 Units.Table (Units.Last).Elaborate_Body := True;
1547 Units.Table (Units.Last).Set_Elab_Entity := True;
1552 Check_At_End_Of_Field;
1554 -- GE parameter (generic)
1560 Check_At_End_Of_Field;
1561 Units.Table (Units.Last).Is_Generic := True;
1566 -- IL/IS/IU parameters
1572 Units.Table (Units.Last).Icasing := All_Lower_Case;
1574 Units.Table (Units.Last).Init_Scalars := True;
1575 Initialize_Scalars_Used := True;
1577 Units.Table (Units.Last).Icasing := All_Upper_Case;
1582 Check_At_End_Of_Field;
1590 Units.Table (Units.Last).Kcasing := Mixed_Case;
1592 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1597 Check_At_End_Of_Field;
1605 Units.Table (Units.Last).No_Elab := True;
1606 Check_At_End_Of_Field;
1611 -- PR/PU/PK parameters
1617 Units.Table (Units.Last).Preelab := True;
1619 Units.Table (Units.Last).Pure := True;
1621 Units.Table (Units.Last).Unit_Kind := 'p';
1626 Check_At_End_Of_Field;
1628 -- OL/OO/OS/OT parameters
1633 if C = 'L' or else C = 'O' or else C = 'S' or else C = 'T' then
1634 Units.Table (Units.Last).Optimize_Alignment := C;
1639 Check_At_End_Of_Field;
1647 Units.Table (Units.Last).RCI := True;
1649 Units.Table (Units.Last).Remote_Types := True;
1651 Units.Table (Units.Last).Has_RACW := True;
1656 Check_At_End_Of_Field;
1662 Units.Table (Units.Last).Shared_Passive := True;
1664 Units.Table (Units.Last).Unit_Kind := 's';
1669 Check_At_End_Of_Field;
1679 -- Check if static elaboration model used
1681 if not Units.Table (Units.Last).Dynamic_Elab
1682 and then not Units.Table (Units.Last).Internal
1684 Static_Elaboration_Model_Used := True;
1689 -- Scan out With lines for this unit
1693 exit With_Loop when C /= 'W' and then C /= 'Y';
1695 if Ignore ('W') then
1701 Withs.Increment_Last;
1702 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1703 Withs.Table (Withs.Last).Elaborate := False;
1704 Withs.Table (Withs.Last).Elaborate_All := False;
1705 Withs.Table (Withs.Last).Elab_Desirable := False;
1706 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1707 Withs.Table (Withs.Last).SAL_Interface := False;
1708 Withs.Table (Withs.Last).Limited_With := (C = 'Y');
1710 -- Generic case with no object file available
1713 Withs.Table (Withs.Last).Sfile := No_File;
1714 Withs.Table (Withs.Last).Afile := No_File;
1719 Withs.Table (Withs.Last).Sfile := Get_File_Name
1721 Withs.Table (Withs.Last).Afile := Get_File_Name
1724 -- Scan out possible E, EA, ED, and AD parameters
1726 while not At_Eol loop
1732 Check_At_End_Of_Field;
1734 -- Store AD indication unless ignore required
1736 if not Ignore_ED then
1737 Withs.Table (Withs.Last).Elab_All_Desirable :=
1741 elsif Nextc = 'E' then
1744 if At_End_Of_Field then
1745 Withs.Table (Withs.Last).Elaborate := True;
1747 elsif Nextc = 'A' then
1749 Check_At_End_Of_Field;
1750 Withs.Table (Withs.Last).Elaborate_All := True;
1754 Check_At_End_Of_Field;
1756 -- Store ED indication unless ignore required
1758 if not Ignore_ED then
1759 Withs.Table (Withs.Last).Elab_Desirable :=
1776 Units.Table (Units.Last).Last_With := Withs.Last;
1777 Units.Table (Units.Last).Last_Arg := Args.Last;
1779 -- If there are linker options lines present, scan them
1783 Linker_Options_Loop : loop
1785 exit Linker_Options_Loop when C /= 'L';
1787 if Ignore ('L') then
1798 if C < Character'Val (16#20#)
1799 or else C > Character'Val (16#7E#)
1804 C := Character'Val (0);
1811 for J in 1 .. 2 loop
1814 if C in '0' .. '9' then
1817 Character'Pos ('0');
1819 elsif C in 'A' .. 'F' then
1822 Character'Pos ('A') +
1831 Add_Char_To_Name_Buffer (Character'Val (V));
1836 exit when Nextc /= '"';
1840 Add_Char_To_Name_Buffer (C);
1844 Add_Char_To_Name_Buffer (NUL);
1849 end loop Linker_Options_Loop;
1851 -- Store the linker options entry if one was found
1853 if Name_Len /= 0 then
1854 Linker_Options.Increment_Last;
1856 Linker_Options.Table (Linker_Options.Last).Name :=
1859 Linker_Options.Table (Linker_Options.Last).Unit :=
1862 Linker_Options.Table (Linker_Options.Last).Internal_File :=
1863 Is_Internal_File_Name (F);
1865 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1866 Linker_Options.Last;
1869 -- If there are notes present, scan them
1873 exit Notes_Loop when C /= 'N';
1875 if Ignore ('N') then
1881 Notes.Increment_Last;
1882 Notes.Table (Notes.Last).Pragma_Type := Getc;
1883 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
1885 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
1886 Notes.Table (Notes.Last).Unit := Units.Last;
1889 Notes.Table (Notes.Last).Pragma_Args := No_Name;
1895 while not At_Eol loop
1896 Add_Char_To_Name_Buffer (Getc);
1899 Notes.Table (Notes.Last).Pragma_Args := Name_Enter;
1906 end loop Notes_Loop;
1909 -- End loop through units for one ALI file
1911 ALIs.Table (Id).Last_Unit := Units.Last;
1912 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1914 -- Set types of the units (there can be at most 2 of them)
1916 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1917 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1918 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
1921 -- Deal with body only and spec only cases, note that the reason we
1922 -- do our own checking of the name (rather than using Is_Body_Name)
1923 -- is that Uname drags in far too much compiler junk!
1925 Get_Name_String (Units.Table (Units.Last).Uname);
1927 if Name_Buffer (Name_Len) = 'b' then
1928 Units.Table (Units.Last).Utype := Is_Body_Only;
1930 Units.Table (Units.Last).Utype := Is_Spec_Only;
1934 -- Scan out external version references and put in hash table
1938 exit E_Loop when C /= 'E';
1940 if Ignore ('E') then
1956 exit when At_End_Of_Field;
1957 Add_Char_To_Name_Buffer (C);
1960 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1967 -- Scan out source dependency lines for this ALI file
1969 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
1973 exit D_Loop when C /= 'D';
1975 if Ignore ('D') then
1981 Sdep.Increment_Last;
1983 -- In the following call, Lower is not set to True, this is either
1984 -- a bug, or it deserves a special comment as to why this is so???
1986 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
1988 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
1989 Sdep.Table (Sdep.Last).Dummy_Entry :=
1990 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
1992 -- Acquire checksum value
2005 exit when At_Eol or else Ctr = 8;
2007 if Nextc in '0' .. '9' then
2009 Character'Pos (Nextc) - Character'Pos ('0');
2011 elsif Nextc in 'a' .. 'f' then
2013 Character'Pos (Nextc) - Character'Pos ('a') + 10;
2023 if Ctr = 8 and then At_End_Of_Field then
2024 Sdep.Table (Sdep.Last).Checksum := Chk;
2030 -- Acquire subunit and reference file name entries
2032 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
2033 Sdep.Table (Sdep.Last).Rfile :=
2034 Sdep.Table (Sdep.Last).Sfile;
2035 Sdep.Table (Sdep.Last).Start_Line := 1;
2040 -- Here for subunit name
2042 if Nextc not in '0' .. '9' then
2044 while not At_End_Of_Field loop
2045 Add_Char_To_Name_Buffer (Getc);
2048 -- Set the subunit name. Note that we use Name_Find rather
2049 -- than Name_Enter here as the subunit name may already
2050 -- have been put in the name table by the Project Manager.
2052 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
2057 -- Here for reference file name entry
2059 if Nextc in '0' .. '9' then
2060 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2065 while not At_End_Of_Field loop
2066 Add_Char_To_Name_Buffer (Getc);
2069 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2079 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2081 -- We must at this stage be at an Xref line or the end of file
2093 -- If we are ignoring Xref sections we are done (we ignore all
2094 -- remaining lines since only xref related lines follow X).
2096 if Ignore ('X') and then not Debug_Flag_X then
2100 -- Loop through Xref sections
2104 exit X_Loop when C /= 'X';
2106 -- Make new entry in section table
2108 Xref_Section.Increment_Last;
2110 Read_Refs_For_One_File : declare
2111 XS : Xref_Section_Record renames
2112 Xref_Section.Table (Xref_Section.Last);
2114 Current_File_Num : Sdep_Id;
2115 -- Keeps track of the current file number (changed by nn|)
2118 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2119 XS.File_Name := Get_File_Name;
2120 XS.First_Entity := Xref_Entity.Last + 1;
2122 Current_File_Num := XS.File_Num;
2129 -- Loop through Xref entities
2131 while C /= 'X' and then C /= EOF loop
2132 Xref_Entity.Increment_Last;
2134 Read_Refs_For_One_Entity : declare
2135 XE : Xref_Entity_Record renames
2136 Xref_Entity.Table (Xref_Entity.Last);
2139 procedure Read_Instantiation_Reference;
2140 -- Acquire instantiation reference. Caller has checked
2141 -- that current character is '[' and on return the cursor
2142 -- is skipped past the corresponding closing ']'.
2144 ----------------------------------
2145 -- Read_Instantiation_Reference --
2146 ----------------------------------
2148 procedure Read_Instantiation_Reference is
2149 Local_File_Num : Sdep_Id := Current_File_Num;
2152 Xref.Increment_Last;
2155 XR : Xref_Record renames Xref.Table (Xref.Last);
2158 P := P + 1; -- skip [
2163 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2164 Local_File_Num := XR.File_Num;
2169 XR.File_Num := Local_File_Num;
2176 -- Recursive call for next reference
2179 pragma Warnings (Off); -- kill recursion warning
2180 Read_Instantiation_Reference;
2181 pragma Warnings (On);
2184 -- Skip closing bracket after recursive call
2188 end Read_Instantiation_Reference;
2190 -- Start of processing for Read_Refs_For_One_Entity
2196 XE.Lib := (Getc = '*');
2197 XE.Entity := Get_Name;
2199 -- Handle the information about generic instantiations
2202 Skipc; -- Opening '['
2205 if Nextc /= '|' then
2206 XE.Iref_File_Num := Current_File_Num;
2210 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2212 XE.Iref_Line := Get_Nat;
2220 XE.Iref_File_Num := No_Sdep_Id;
2224 Current_File_Num := XS.File_Num;
2226 -- Renaming reference is present
2230 XE.Rref_Line := Get_Nat;
2236 XE.Rref_Col := Get_Nat;
2238 -- No renaming reference present
2247 XE.Oref_File_Num := No_Sdep_Id;
2248 XE.Tref_File_Num := No_Sdep_Id;
2249 XE.Tref := Tref_None;
2250 XE.First_Xref := Xref.Last + 1;
2252 -- Loop to check for additional info present
2265 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2266 exit when Ref = Tref_None;
2268 -- Do we have an overriding procedure?
2270 if Ref = Tref_Derived and then Typ = 'p' then
2271 XE.Oref_File_Num := File;
2272 XE.Oref_Line := Line;
2275 -- Arrays never override anything, and <> points to
2276 -- the index types instead
2278 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2280 -- Index types are stored in the list of references
2282 Xref.Increment_Last;
2285 XR : Xref_Record renames Xref.Table (Xref.Last);
2287 XR.File_Num := File;
2289 XR.Rtype := Array_Index_Reference;
2294 -- Interfaces are stored in the list of references,
2295 -- although the parent type itself is stored in XE.
2296 -- The first interface (when there are only
2297 -- interfaces) is stored in XE.Tref*)
2299 elsif Ref = Tref_Derived
2301 and then XE.Tref_File_Num /= No_Sdep_Id
2303 Xref.Increment_Last;
2306 XR : Xref_Record renames Xref.Table (Xref.Last);
2308 XR.File_Num := File;
2310 XR.Rtype := Interface_Reference;
2317 XE.Tref_File_Num := File;
2318 XE.Tref_Line := Line;
2319 XE.Tref_Type := Typ;
2321 XE.Tref_Standard_Entity := Std;
2326 -- Loop through cross-references for this entity
2333 exit when Nextc /= '.';
2337 Xref.Increment_Last;
2340 XR : Xref_Record renames Xref.Table (Xref.Last);
2347 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2348 Current_File_Num := XR.File_Num;
2352 XR.File_Num := Current_File_Num;
2358 -- Imported entities reference as in:
2359 -- 494b<c,__gnat_copy_attribs>25
2360 -- ??? Simply skipped for now
2363 while Getc /= '>' loop
2371 Read_Instantiation_Reference;
2376 -- Record last cross-reference
2378 XE.Last_Xref := Xref.Last;
2382 when Bad_ALI_Format =>
2384 -- If ignoring errors, then we skip a line with an
2385 -- unexpected error, and try to continue subsequent
2388 if Ignore_Errors then
2389 Xref_Entity.Decrement_Last;
2393 -- Otherwise, we reraise the fatal exception
2398 end Read_Refs_For_One_Entity;
2401 -- Record last entity
2403 XS.Last_Entity := Xref_Entity.Last;
2405 end Read_Refs_For_One_File;
2410 -- Here after dealing with xref sections
2412 if C /= EOF and then C /= 'X' then
2419 when Bad_ALI_Format =>
2427 function SEq (F1, F2 : String_Ptr) return Boolean is
2429 return F1.all = F2.all;
2436 function SHash (S : String_Ptr) return Vindex is
2441 for J in S.all'Range loop
2442 H := H * 2 + Character'Pos (S (J));
2445 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));