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 if left bracket not part of wide char sequence
508 -- Note that we only recognize brackets notation so far ???
510 exit when Nextc = '[' and then T (P + 1) /= '"';
512 -- Terminate if right bracket not part of wide char sequence
514 exit when Nextc = ']' and then T (P - 1) /= '"';
526 function Get_Unit_Name return Unit_Name_Type is
528 return Unit_Name_Type (Get_Name);
535 function Get_Nat return Nat is
541 -- Check if we are on a number. In the case of bad ALI files, this
544 if not (Nextc in '0' .. '9') then
550 V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
552 exit when At_End_Of_Field;
553 exit when Nextc < '0' or else Nextc > '9';
563 function Get_Stamp return Time_Stamp_Type is
571 if Ignore_Errors then
572 return Dummy_Time_Stamp;
578 -- Following reads old style time stamp missing first two digits
580 if Nextc in '7' .. '9' then
585 -- Normal case of full year in time stamp
591 for J in Start .. T'Last loop
602 procedure Get_Typeref
603 (Current_File_Num : Sdep_Id;
605 File_Num : out Sdep_Id;
607 Ref_Type : out Character;
609 Standard_Entity : out Name_Id)
614 when '<' => Ref := Tref_Derived;
615 when '(' => Ref := Tref_Access;
616 when '{' => Ref := Tref_Type;
617 when others => Ref := Tref_None;
620 -- Case of typeref field present
622 if Ref /= Tref_None then
623 P := P + 1; -- skip opening bracket
625 if Nextc in 'a' .. 'z' then
626 File_Num := No_Sdep_Id;
630 Standard_Entity := Get_Name (Ignore_Spaces => True);
635 File_Num := Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
639 File_Num := Current_File_Num;
645 Standard_Entity := No_Name;
648 -- ??? Temporary workaround for nested generics case:
649 -- 4i4 Directories{1|4I9[4|6[3|3]]}
653 Nested_Brackets : Natural := 0;
659 Nested_Brackets := Nested_Brackets + 1;
661 Nested_Brackets := Nested_Brackets - 1;
663 if Nested_Brackets = 0 then
672 P := P + 1; -- skip closing bracket
675 -- No typeref entry present
678 File_Num := No_Sdep_Id;
682 Standard_Entity := No_Name;
690 function Getc return Character is
704 function Nextc return Character is
713 procedure Skip_Eol is
718 if Ignore_Errors then
719 while not At_Eol loop
727 -- Loop to skip past blank lines (first time through skips this EOL)
729 while Nextc < ' ' and then Nextc /= EOF loop
742 procedure Skip_Line is
744 while not At_Eol loop
755 procedure Skip_Space is
757 while Nextc = ' ' or else Nextc = HT loop
773 -- Start of processing for Scan_ALI
776 First_Sdep_Entry := Sdep.Last + 1;
778 -- Acquire lines to be ignored
781 Ignore := ('U' | 'W' | 'Y' | 'D' | 'X' => False, others => True);
783 -- Read_Lines parameter given
785 elsif Read_Lines /= "" then
786 Ignore := ('U' => False, others => True);
788 for J in Read_Lines'Range loop
789 Ignore (Read_Lines (J)) := False;
792 -- Process Ignore_Lines parameter
795 Ignore := (others => False);
797 for J in Ignore_Lines'Range loop
798 pragma Assert (Ignore_Lines (J) /= 'U');
799 Ignore (Ignore_Lines (J)) := True;
803 -- Setup ALI Table entry with appropriate defaults
807 Set_Name_Table_Info (F, Int (Id));
811 Compile_Errors => False,
812 First_Interrupt_State => Interrupt_States.Last + 1,
813 First_Sdep => No_Sdep_Id,
814 First_Specific_Dispatching => Specific_Dispatching.Last + 1,
815 First_Unit => No_Unit_Id,
817 Last_Interrupt_State => Interrupt_States.Last,
818 Last_Sdep => No_Sdep_Id,
819 Last_Specific_Dispatching => Specific_Dispatching.Last,
820 Last_Unit => No_Unit_Id,
821 Locking_Policy => ' ',
824 Main_Program => None,
826 Normalize_Scalars => False,
827 Ofile_Full_Name => Full_Object_File_Name,
828 Queuing_Policy => ' ',
829 Restrictions => No_Restrictions,
830 SAL_Interface => False,
832 Task_Dispatching_Policy => ' ',
833 Time_Slice_Value => -1,
834 Allocator_In_Body => False,
836 Unit_Exception_Table => False,
837 Ver => (others => ' '),
839 Zero_Cost_Exceptions => False);
841 -- Now we acquire the input lines from the ALI file. Note that the
842 -- convention in the following code is that as we enter each section,
843 -- C is set to contain the first character of the following line.
848 -- Acquire library version
852 -- The V line missing really indicates trouble, most likely it
853 -- means we don't have an ALI file at all, so here we give a
854 -- fatal error even if we are in Ignore_Errors mode.
858 elsif Ignore ('V') then
866 for J in 1 .. Ver_Len_Max loop
869 ALIs.Table (Id).Ver (J) := C;
870 ALIs.Table (Id).Ver_Len := J;
879 -- Acquire main program line if present
892 ALIs.Table (Id).Main_Program := Func;
894 ALIs.Table (Id).Main_Program := Proc;
904 ALIs.Table (Id).Main_Priority := Get_Nat;
912 ALIs.Table (Id).Time_Slice_Value := Get_Nat;
920 ALIs.Table (Id).Allocator_In_Body := True;
928 ALIs.Table (Id).Main_CPU := Get_Nat;
935 ALIs.Table (Id).WC_Encoding := Getc;
944 -- Acquire argument lines
946 First_Arg := Args.Last + 1;
950 exit A_Loop when C /= 'A';
961 while not At_Eol loop
962 Add_Char_To_Name_Buffer (Getc);
965 -- If -fstack-check, record that it occurred
967 if Name_Buffer (1 .. Name_Len) = "-fstack-check" then
968 Stack_Check_Switch_Set := True;
971 -- Store the argument
974 Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
987 if Ignore_Errors then
1007 while not At_Eol loop
1012 -- Processing for CE
1016 ALIs.Table (Id).Compile_Errors := True;
1018 -- Processing for DB
1022 Detect_Blocking := True;
1024 -- Processing for FD/FG/FI
1027 Float_Format_Specified := Getc;
1028 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1030 -- Processing for Lx
1033 Locking_Policy_Specified := Getc;
1034 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1036 -- Processing for flags starting with N
1041 -- Processing for NO
1044 ALIs.Table (Id).No_Object := True;
1045 No_Object_Specified := True;
1047 -- Processing for NR
1050 No_Run_Time_Mode := True;
1051 Configurable_Run_Time_Mode := True;
1053 -- Processing for NS
1056 ALIs.Table (Id).Normalize_Scalars := True;
1057 Normalize_Scalars_Specified := True;
1060 -- Invalid switch starting with N
1066 -- Processing for Qx
1069 Queuing_Policy_Specified := Getc;
1070 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1072 -- Processing for flags starting with S
1077 -- Processing for SL
1080 ALIs.Table (Id).SAL_Interface := True;
1082 -- Processing for SS
1085 Opt.Sec_Stack_Used := True;
1087 -- Invalid switch starting with S
1093 -- Processing for Tx
1096 Task_Dispatching_Policy_Specified := Getc;
1097 ALIs.Table (Id).Task_Dispatching_Policy :=
1098 Task_Dispatching_Policy_Specified;
1100 -- Processing for switch starting with U
1105 -- Processing for UA
1108 Unreserve_All_Interrupts_Specified := True;
1110 -- Processing for UX
1113 ALIs.Table (Id).Unit_Exception_Table := True;
1115 -- Invalid switches starting with U
1121 -- Processing for ZX
1127 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1128 Zero_Cost_Exceptions_Specified := True;
1133 -- Invalid parameter
1141 if not NS_Found then
1142 No_Normalize_Scalars_Specified := True;
1151 -- Acquire first restrictions line
1154 if Ignore_Errors then
1166 if Ignore ('R') then
1169 -- Process restrictions line
1172 Scan_Restrictions : declare
1173 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1174 -- Save cumulative restrictions in case we have a fatal error
1176 Bad_R_Line : exception;
1177 -- Signal bad restrictions line (raised on unexpected character)
1183 -- Acquire information for boolean restrictions
1185 for R in All_Boolean_Restrictions loop
1190 ALIs.Table (Id).Restrictions.Violated (R) := True;
1191 Cumulative_Restrictions.Violated (R) := True;
1194 ALIs.Table (Id).Restrictions.Set (R) := True;
1195 Cumulative_Restrictions.Set (R) := True;
1205 -- Acquire information for parameter restrictions
1207 for RP in All_Parameter_Restrictions loop
1209 -- Acquire restrictions pragma information
1216 ALIs.Table (Id).Restrictions.Set (RP) := True;
1219 N : constant Integer := Integer (Get_Nat);
1221 ALIs.Table (Id).Restrictions.Value (RP) := N;
1223 if Cumulative_Restrictions.Set (RP) then
1224 Cumulative_Restrictions.Value (RP) :=
1226 (Cumulative_Restrictions.Value (RP), N);
1228 Cumulative_Restrictions.Set (RP) := True;
1229 Cumulative_Restrictions.Value (RP) := N;
1237 -- Acquire restrictions violations information
1244 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1245 Cumulative_Restrictions.Violated (RP) := True;
1248 N : constant Integer := Integer (Get_Nat);
1249 pragma Unsuppress (Overflow_Check);
1252 ALIs.Table (Id).Restrictions.Count (RP) := N;
1254 if RP in Checked_Max_Parameter_Restrictions then
1255 Cumulative_Restrictions.Count (RP) :=
1257 (Cumulative_Restrictions.Count (RP), N);
1259 Cumulative_Restrictions.Count (RP) :=
1260 Cumulative_Restrictions.Count (RP) + N;
1264 when Constraint_Error =>
1266 -- A constraint error comes from the addition in
1267 -- the else branch. We reset to the maximum and
1268 -- indicate that the real value is now unknown.
1270 Cumulative_Restrictions.Value (RP) := Integer'Last;
1271 Cumulative_Restrictions.Unknown (RP) := True;
1276 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1277 Cumulative_Restrictions.Unknown (RP) := True;
1287 -- Here if error during scanning of restrictions line
1292 -- In Ignore_Errors mode, undo any changes to restrictions
1293 -- from this unit, and continue on.
1295 if Ignore_Errors then
1296 Cumulative_Restrictions := Save_R;
1297 ALIs.Table (Id).Restrictions := No_Restrictions;
1300 -- In normal mode, this is a fatal error
1306 end Scan_Restrictions;
1309 -- Acquire additional restrictions (No_Dependence) lines if present
1313 if Ignore ('R') then
1317 No_Deps.Append ((Id, Get_Name));
1324 -- Acquire 'I' lines if present
1329 if Ignore ('I') then
1335 I_State : Character;
1344 Interrupt_States.Append (
1345 (Interrupt_Id => Int_Num,
1346 Interrupt_State => I_State,
1347 IS_Pragma_Line => Line_No));
1349 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1357 -- Acquire 'S' lines if present
1362 if Ignore ('S') then
1378 First_Prio := Get_Nat;
1379 Last_Prio := Get_Nat;
1382 Specific_Dispatching.Append (
1383 (Dispatching_Policy => Policy,
1384 First_Priority => First_Prio,
1385 Last_Priority => Last_Prio,
1386 PSD_Pragma_Line => Line_No));
1388 ALIs.Table (Id).Last_Specific_Dispatching :=
1389 Specific_Dispatching.Last;
1398 -- Loop to acquire unit entries
1402 exit U_Loop when C /= 'U';
1404 -- Note: as per spec, we never ignore U lines
1408 Units.Increment_Last;
1410 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1411 ALIs.Table (Id).First_Unit := Units.Last;
1415 UL : Unit_Record renames Units.Table (Units.Last);
1418 UL.Uname := Get_Unit_Name;
1419 UL.Predefined := Is_Predefined_Unit;
1420 UL.Internal := Is_Internal_Unit;
1422 UL.Sfile := Get_File_Name (Lower => True);
1424 UL.Preelab := False;
1425 UL.No_Elab := False;
1426 UL.Shared_Passive := False;
1428 UL.Remote_Types := False;
1429 UL.Has_RACW := False;
1430 UL.Init_Scalars := False;
1431 UL.Is_Generic := False;
1432 UL.Icasing := Mixed_Case;
1433 UL.Kcasing := All_Lower_Case;
1434 UL.Dynamic_Elab := False;
1435 UL.Elaborate_Body := False;
1436 UL.Set_Elab_Entity := False;
1437 UL.Version := "00000000";
1438 UL.First_With := Withs.Last + 1;
1439 UL.First_Arg := First_Arg;
1440 UL.Elab_Position := 0;
1441 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1442 UL.Directly_Scanned := Directly_Scanned;
1443 UL.Body_Needed_For_SAL := False;
1444 UL.Elaborate_Body_Desirable := False;
1445 UL.Optimize_Alignment := 'O';
1446 UL.Has_Finalizer := False;
1448 if Debug_Flag_U then
1449 Write_Str (" ----> reading unit ");
1450 Write_Int (Int (Units.Last));
1452 Write_Unit_Name (UL.Uname);
1453 Write_Str (" from file ");
1454 Write_Name (UL.Sfile);
1459 -- Check for duplicated unit in different files
1462 Info : constant Int := Get_Name_Table_Info
1463 (Units.Table (Units.Last).Uname);
1466 and then Units.Table (Units.Last).Sfile /=
1467 Units.Table (Unit_Id (Info)).Sfile
1469 -- If Err is set then ignore duplicate unit name. This is the
1470 -- case of a call from gnatmake, where the situation can arise
1471 -- from substitution of source files. In such situations, the
1472 -- processing in gnatmake will always result in any required
1473 -- recompilations in any case, and if we consider this to be
1474 -- an error we get strange cases (for example when a generic
1475 -- instantiation is replaced by a normal package) where we
1476 -- read the old ali file, decide to recompile, and then decide
1477 -- that the old and new ali files are incompatible.
1482 -- If Err is not set, then this is a fatal error. This is
1483 -- the case of being called from the binder, where we must
1484 -- definitely diagnose this as an error.
1488 Write_Str ("error: duplicate unit name: ");
1491 Write_Str ("error: unit """);
1492 Write_Unit_Name (Units.Table (Units.Last).Uname);
1493 Write_Str (""" found in file """);
1494 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1498 Write_Str ("error: unit """);
1499 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1500 Write_Str (""" found in file """);
1501 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1505 Exit_Program (E_Fatal);
1511 (Units.Table (Units.Last).Uname, Int (Units.Last));
1513 -- Scan out possible version and other parameters
1522 if C in '0' .. '9' or else C in 'a' .. 'f' then
1523 Units.Table (Units.Last).Version (1) := C;
1525 for J in 2 .. 8 loop
1527 Units.Table (Units.Last).Version (J) := C;
1536 Check_At_End_Of_Field;
1537 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1540 Check_At_End_Of_Field;
1541 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1547 -- DE parameter (Dynamic elaboration checks)
1553 Check_At_End_Of_Field;
1554 Units.Table (Units.Last).Dynamic_Elab := True;
1555 Dynamic_Elaboration_Checks_Specified := True;
1566 Units.Table (Units.Last).Elaborate_Body := True;
1568 Units.Table (Units.Last).Set_Elab_Entity := True;
1573 Check_At_End_Of_Field;
1575 -- GE parameter (generic)
1581 Check_At_End_Of_Field;
1582 Units.Table (Units.Last).Is_Generic := True;
1587 -- IL/IS/IU parameters
1593 Units.Table (Units.Last).Icasing := All_Lower_Case;
1595 Units.Table (Units.Last).Init_Scalars := True;
1596 Initialize_Scalars_Used := True;
1598 Units.Table (Units.Last).Icasing := All_Upper_Case;
1603 Check_At_End_Of_Field;
1611 Units.Table (Units.Last).Kcasing := Mixed_Case;
1613 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1618 Check_At_End_Of_Field;
1626 Units.Table (Units.Last).No_Elab := True;
1627 Check_At_End_Of_Field;
1632 -- PF/PR/PU/PK parameters
1638 Units.Table (Units.Last).Has_Finalizer := True;
1640 Units.Table (Units.Last).Preelab := True;
1642 Units.Table (Units.Last).Pure := True;
1644 Units.Table (Units.Last).Unit_Kind := 'p';
1649 Check_At_End_Of_Field;
1651 -- OL/OO/OS/OT parameters
1656 if C = 'L' or else C = 'O' or else C = 'S' or else C = 'T' then
1657 Units.Table (Units.Last).Optimize_Alignment := C;
1662 Check_At_End_Of_Field;
1670 Units.Table (Units.Last).RCI := True;
1672 Units.Table (Units.Last).Remote_Types := True;
1674 Units.Table (Units.Last).Has_RACW := True;
1679 Check_At_End_Of_Field;
1685 Units.Table (Units.Last).Shared_Passive := True;
1687 Units.Table (Units.Last).Unit_Kind := 's';
1692 Check_At_End_Of_Field;
1702 -- Check if static elaboration model used
1704 if not Units.Table (Units.Last).Dynamic_Elab
1705 and then not Units.Table (Units.Last).Internal
1707 Static_Elaboration_Model_Used := True;
1712 -- Scan out With lines for this unit
1716 exit With_Loop when C /= 'W' and then C /= 'Y';
1718 if Ignore ('W') then
1724 Withs.Increment_Last;
1725 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1726 Withs.Table (Withs.Last).Elaborate := False;
1727 Withs.Table (Withs.Last).Elaborate_All := False;
1728 Withs.Table (Withs.Last).Elab_Desirable := False;
1729 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1730 Withs.Table (Withs.Last).SAL_Interface := False;
1731 Withs.Table (Withs.Last).Limited_With := (C = 'Y');
1733 -- Generic case with no object file available
1736 Withs.Table (Withs.Last).Sfile := No_File;
1737 Withs.Table (Withs.Last).Afile := No_File;
1742 Withs.Table (Withs.Last).Sfile := Get_File_Name
1744 Withs.Table (Withs.Last).Afile := Get_File_Name
1747 -- Scan out possible E, EA, ED, and AD parameters
1749 while not At_Eol loop
1755 Check_At_End_Of_Field;
1757 -- Store AD indication unless ignore required
1759 if not Ignore_ED then
1760 Withs.Table (Withs.Last).Elab_All_Desirable :=
1764 elsif Nextc = 'E' then
1767 if At_End_Of_Field then
1768 Withs.Table (Withs.Last).Elaborate := True;
1770 elsif Nextc = 'A' then
1772 Check_At_End_Of_Field;
1773 Withs.Table (Withs.Last).Elaborate_All := True;
1777 Check_At_End_Of_Field;
1779 -- Store ED indication unless ignore required
1781 if not Ignore_ED then
1782 Withs.Table (Withs.Last).Elab_Desirable :=
1799 Units.Table (Units.Last).Last_With := Withs.Last;
1800 Units.Table (Units.Last).Last_Arg := Args.Last;
1802 -- If there are linker options lines present, scan them
1806 Linker_Options_Loop : loop
1808 exit Linker_Options_Loop when C /= 'L';
1810 if Ignore ('L') then
1821 if C < Character'Val (16#20#)
1822 or else C > Character'Val (16#7E#)
1827 C := Character'Val (0);
1834 for J in 1 .. 2 loop
1837 if C in '0' .. '9' then
1840 Character'Pos ('0');
1842 elsif C in 'A' .. 'F' then
1845 Character'Pos ('A') +
1854 Add_Char_To_Name_Buffer (Character'Val (V));
1859 exit when Nextc /= '"';
1863 Add_Char_To_Name_Buffer (C);
1867 Add_Char_To_Name_Buffer (NUL);
1872 end loop Linker_Options_Loop;
1874 -- Store the linker options entry if one was found
1876 if Name_Len /= 0 then
1877 Linker_Options.Increment_Last;
1879 Linker_Options.Table (Linker_Options.Last).Name :=
1882 Linker_Options.Table (Linker_Options.Last).Unit :=
1885 Linker_Options.Table (Linker_Options.Last).Internal_File :=
1886 Is_Internal_File_Name (F);
1888 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1889 Linker_Options.Last;
1892 -- If there are notes present, scan them
1896 exit Notes_Loop when C /= 'N';
1898 if Ignore ('N') then
1904 Notes.Increment_Last;
1905 Notes.Table (Notes.Last).Pragma_Type := Getc;
1906 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
1908 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
1909 Notes.Table (Notes.Last).Unit := Units.Last;
1912 Notes.Table (Notes.Last).Pragma_Args := No_Name;
1918 while not At_Eol loop
1919 Add_Char_To_Name_Buffer (Getc);
1922 Notes.Table (Notes.Last).Pragma_Args := Name_Enter;
1929 end loop Notes_Loop;
1932 -- End loop through units for one ALI file
1934 ALIs.Table (Id).Last_Unit := Units.Last;
1935 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1937 -- Set types of the units (there can be at most 2 of them)
1939 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1940 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1941 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
1944 -- Deal with body only and spec only cases, note that the reason we
1945 -- do our own checking of the name (rather than using Is_Body_Name)
1946 -- is that Uname drags in far too much compiler junk!
1948 Get_Name_String (Units.Table (Units.Last).Uname);
1950 if Name_Buffer (Name_Len) = 'b' then
1951 Units.Table (Units.Last).Utype := Is_Body_Only;
1953 Units.Table (Units.Last).Utype := Is_Spec_Only;
1957 -- Scan out external version references and put in hash table
1961 exit E_Loop when C /= 'E';
1963 if Ignore ('E') then
1979 exit when At_End_Of_Field;
1980 Add_Char_To_Name_Buffer (C);
1983 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1990 -- Scan out source dependency lines for this ALI file
1992 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
1996 exit D_Loop when C /= 'D';
1998 if Ignore ('D') then
2004 Sdep.Increment_Last;
2006 -- In the following call, Lower is not set to True, this is either
2007 -- a bug, or it deserves a special comment as to why this is so???
2009 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
2011 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
2012 Sdep.Table (Sdep.Last).Dummy_Entry :=
2013 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
2015 -- Acquire checksum value
2028 exit when At_Eol or else Ctr = 8;
2030 if Nextc in '0' .. '9' then
2032 Character'Pos (Nextc) - Character'Pos ('0');
2034 elsif Nextc in 'a' .. 'f' then
2036 Character'Pos (Nextc) - Character'Pos ('a') + 10;
2046 if Ctr = 8 and then At_End_Of_Field then
2047 Sdep.Table (Sdep.Last).Checksum := Chk;
2053 -- Acquire subunit and reference file name entries
2055 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
2056 Sdep.Table (Sdep.Last).Rfile :=
2057 Sdep.Table (Sdep.Last).Sfile;
2058 Sdep.Table (Sdep.Last).Start_Line := 1;
2063 -- Here for subunit name
2065 if Nextc not in '0' .. '9' then
2067 while not At_End_Of_Field loop
2068 Add_Char_To_Name_Buffer (Getc);
2071 -- Set the subunit name. Note that we use Name_Find rather
2072 -- than Name_Enter here as the subunit name may already
2073 -- have been put in the name table by the Project Manager.
2075 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
2080 -- Here for reference file name entry
2082 if Nextc in '0' .. '9' then
2083 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2088 while not At_End_Of_Field loop
2089 Add_Char_To_Name_Buffer (Getc);
2092 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2102 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2104 -- We must at this stage be at an Xref line or the end of file
2116 -- If we are ignoring Xref sections we are done (we ignore all
2117 -- remaining lines since only xref related lines follow X).
2119 if Ignore ('X') and then not Debug_Flag_X then
2123 -- Loop through Xref sections
2127 exit X_Loop when C /= 'X';
2129 -- Make new entry in section table
2131 Xref_Section.Increment_Last;
2133 Read_Refs_For_One_File : declare
2134 XS : Xref_Section_Record renames
2135 Xref_Section.Table (Xref_Section.Last);
2137 Current_File_Num : Sdep_Id;
2138 -- Keeps track of the current file number (changed by nn|)
2141 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2142 XS.File_Name := Get_File_Name;
2143 XS.First_Entity := Xref_Entity.Last + 1;
2145 Current_File_Num := XS.File_Num;
2152 -- Loop through Xref entities
2154 while C /= 'X' and then C /= EOF loop
2155 Xref_Entity.Increment_Last;
2157 Read_Refs_For_One_Entity : declare
2158 XE : Xref_Entity_Record renames
2159 Xref_Entity.Table (Xref_Entity.Last);
2162 procedure Read_Instantiation_Reference;
2163 -- Acquire instantiation reference. Caller has checked
2164 -- that current character is '[' and on return the cursor
2165 -- is skipped past the corresponding closing ']'.
2167 ----------------------------------
2168 -- Read_Instantiation_Reference --
2169 ----------------------------------
2171 procedure Read_Instantiation_Reference is
2172 Local_File_Num : Sdep_Id := Current_File_Num;
2175 Xref.Increment_Last;
2178 XR : Xref_Record renames Xref.Table (Xref.Last);
2181 P := P + 1; -- skip [
2186 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2187 Local_File_Num := XR.File_Num;
2192 XR.File_Num := Local_File_Num;
2199 -- Recursive call for next reference
2202 pragma Warnings (Off); -- kill recursion warning
2203 Read_Instantiation_Reference;
2204 pragma Warnings (On);
2207 -- Skip closing bracket after recursive call
2211 end Read_Instantiation_Reference;
2213 -- Start of processing for Read_Refs_For_One_Entity
2222 XE.Visibility := Global;
2224 XE.Visibility := Static;
2226 XE.Visibility := Other;
2229 XE.Entity := Get_Name;
2231 -- Handle the information about generic instantiations
2234 Skipc; -- Opening '['
2237 if Nextc /= '|' then
2238 XE.Iref_File_Num := Current_File_Num;
2242 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2244 XE.Iref_Line := Get_Nat;
2252 XE.Iref_File_Num := No_Sdep_Id;
2256 Current_File_Num := XS.File_Num;
2258 -- Renaming reference is present
2262 XE.Rref_Line := Get_Nat;
2268 XE.Rref_Col := Get_Nat;
2270 -- No renaming reference present
2279 XE.Oref_File_Num := No_Sdep_Id;
2280 XE.Tref_File_Num := No_Sdep_Id;
2281 XE.Tref := Tref_None;
2282 XE.First_Xref := Xref.Last + 1;
2284 -- Loop to check for additional info present
2297 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2298 exit when Ref = Tref_None;
2300 -- Do we have an overriding procedure?
2302 if Ref = Tref_Derived and then Typ = 'p' then
2303 XE.Oref_File_Num := File;
2304 XE.Oref_Line := Line;
2307 -- Arrays never override anything, and <> points to
2308 -- the index types instead
2310 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2312 -- Index types are stored in the list of references
2314 Xref.Increment_Last;
2317 XR : Xref_Record renames Xref.Table (Xref.Last);
2319 XR.File_Num := File;
2321 XR.Rtype := Array_Index_Reference;
2326 -- Interfaces are stored in the list of references,
2327 -- although the parent type itself is stored in XE.
2328 -- The first interface (when there are only
2329 -- interfaces) is stored in XE.Tref*)
2331 elsif Ref = Tref_Derived
2333 and then XE.Tref_File_Num /= No_Sdep_Id
2335 Xref.Increment_Last;
2338 XR : Xref_Record renames Xref.Table (Xref.Last);
2340 XR.File_Num := File;
2342 XR.Rtype := Interface_Reference;
2349 XE.Tref_File_Num := File;
2350 XE.Tref_Line := Line;
2351 XE.Tref_Type := Typ;
2353 XE.Tref_Standard_Entity := Std;
2358 -- Loop through cross-references for this entity
2365 exit when Nextc /= '.';
2369 Xref.Increment_Last;
2372 XR : Xref_Record renames Xref.Table (Xref.Last);
2379 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2380 Current_File_Num := XR.File_Num;
2384 XR.File_Num := Current_File_Num;
2390 -- Imported entities reference as in:
2391 -- 494b<c,__gnat_copy_attribs>25
2392 -- ??? Simply skipped for now
2395 while Getc /= '>' loop
2403 Read_Instantiation_Reference;
2408 -- Record last cross-reference
2410 XE.Last_Xref := Xref.Last;
2414 when Bad_ALI_Format =>
2416 -- If ignoring errors, then we skip a line with an
2417 -- unexpected error, and try to continue subsequent
2420 if Ignore_Errors then
2421 Xref_Entity.Decrement_Last;
2425 -- Otherwise, we reraise the fatal exception
2430 end Read_Refs_For_One_Entity;
2433 -- Record last entity
2435 XS.Last_Entity := Xref_Entity.Last;
2437 end Read_Refs_For_One_File;
2442 -- Here after dealing with xref sections
2444 -- Ignore remaining lines, which belong to an additional section of the
2445 -- ALI file not considered here (like SCO or Alfa).
2452 when Bad_ALI_Format =>
2460 function SEq (F1, F2 : String_Ptr) return Boolean is
2462 return F1.all = F2.all;
2469 function SHash (S : String_Ptr) return Vindex is
2474 for J in S.all'Range loop
2475 H := H * 2 + Character'Pos (S (J));
2478 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));