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
52 'E' => True, -- external
53 'D' => True, -- dependency
55 'S' => True, -- specific dispatching
56 'Y' => True, -- limited_with
63 procedure Initialize_ALI
is
65 -- When (re)initializing ALI data structures the ALI user expects to
66 -- get a fresh set of data structures. Thus we first need to erase the
67 -- marks put in the name table by the previous set of ALI routine calls.
68 -- These two loops are empty and harmless the first time in.
70 for J
in ALIs
.First
.. ALIs
.Last
loop
71 Set_Name_Table_Info
(ALIs
.Table
(J
).Afile
, 0);
74 for J
in Units
.First
.. Units
.Last
loop
75 Set_Name_Table_Info
(Units
.Table
(J
).Uname
, 0);
78 -- Free argument table strings
80 for J
in Args
.First
.. Args
.Last
loop
81 Free
(Args
.Table
(J
));
84 -- Initialize all tables
97 -- Add dummy zero'th item in Linker_Options for the sort function
99 Linker_Options
.Increment_Last
;
101 -- Initialize global variables recording cumulative options in all
102 -- ALI files that are read for a given processing run in gnatbind.
104 Dynamic_Elaboration_Checks_Specified
:= False;
105 Float_Format_Specified
:= ' ';
106 Locking_Policy_Specified
:= ' ';
107 No_Normalize_Scalars_Specified
:= False;
108 No_Object_Specified
:= False;
109 Normalize_Scalars_Specified
:= False;
110 Queuing_Policy_Specified
:= ' ';
111 Static_Elaboration_Model_Used
:= False;
112 Task_Dispatching_Policy_Specified
:= ' ';
113 Unreserve_All_Interrupts_Specified
:= False;
114 Zero_Cost_Exceptions_Specified
:= False;
126 Read_Xref
: Boolean := False;
127 Read_Lines
: String := "";
128 Ignore_Lines
: String := "X";
129 Ignore_Errors
: Boolean := False) return ALI_Id
131 P
: Text_Ptr
:= T
'First;
132 Line
: Logical_Line_Number
:= 1;
138 Ignore
: array (Character range 'A' .. 'Z') of Boolean;
139 -- Ignore (X) is set to True if lines starting with X are to
140 -- be ignored by Scan_ALI and skipped, and False if the lines
141 -- are to be read and processed.
143 Bad_ALI_Format
: exception;
144 -- Exception raised by Fatal_Error if Err is True
146 function At_Eol
return Boolean;
147 -- Test if at end of line
149 function At_End_Of_Field
return Boolean;
150 -- Test if at end of line, or if at blank or horizontal tab
152 procedure Check_At_End_Of_Field
;
153 -- Check if we are at end of field, fatal error if not
155 procedure Checkc
(C
: Character);
156 -- Check next character is C. If so bump past it, if not fatal error
158 procedure Check_Unknown_Line
;
159 -- If Ignore_Errors mode, then checks C to make sure that it is not
160 -- an unknown ALI line type characters, and if so, skips lines
161 -- until the first character of the line is one of these characters,
162 -- at which point it does a Getc to put that character in C. The
163 -- call has no effect if C is already an appropriate character.
164 -- If not in Ignore_Errors mode, a fatal error is signalled if the
165 -- line is unknown. Note that if C is an EOL on entry, the line is
166 -- skipped (it is assumed that blank lines are never significant).
167 -- If C is EOF on entry, the call has no effect (it is assumed that
168 -- the caller will properly handle this case).
170 procedure Fatal_Error
;
171 -- Generate fatal error message for badly formatted ALI file if
172 -- Err is false, or raise Bad_ALI_Format if Err is True.
174 procedure Fatal_Error_Ignore
;
175 pragma Inline
(Fatal_Error_Ignore
);
176 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
178 function Getc
return Character;
179 -- Get next character, bumping P past the character obtained
181 function Get_File_Name
(Lower
: Boolean := False) return File_Name_Type
;
182 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
183 -- with length in Name_Len, as well as returning a File_Name_Type value.
184 -- If lower is false, the case is unchanged, if Lower is True then the
185 -- result is forced to all lower case for systems where file names are
186 -- not case sensitive. This ensures that gnatbind works correctly
187 -- regardless of the case of the file name on all systems. The scan
188 -- is terminated by a end of line, space or horizontal tab. Any other
189 -- special characters are included in the returned name.
192 (Ignore_Spaces
: Boolean := False;
193 Ignore_Special
: Boolean := False) return Name_Id
;
194 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
195 -- length in Name_Len, as well as being returned in Name_Id form).
196 -- If Lower is set to True then the Name_Buffer will be converted to
197 -- all lower case, for systems where file names are not case sensitive.
198 -- This ensures that gnatbind works correctly regardless of the case
199 -- of the file name on all systems. The termination condition depends
200 -- on the settings of Ignore_Spaces and Ignore_Special:
202 -- If Ignore_Spaces is False (normal case), then scan is terminated
203 -- by the normal end of field condition (EOL, space, horizontal tab)
205 -- If Ignore_Special is False (normal case), the scan is terminated by
206 -- a typeref bracket or an equal sign except for the special case of
207 -- an operator name starting with a double quite which is terminated
208 -- by another double quote.
210 -- It is an error to set both Ignore_Spaces and Ignore_Special to True.
211 -- This function handles wide characters properly.
213 function Get_Nat
return Nat
;
214 -- Skip blanks, then scan out an unsigned integer value in Nat range
215 -- raises ALI_Reading_Error if the encoutered type is not natural.
217 function Get_Stamp
return Time_Stamp_Type
;
218 -- Skip blanks, then scan out a time stamp
220 function Get_Unit_Name
return Unit_Name_Type
;
221 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
222 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
223 -- The case is unchanged and terminated by a normal end of field.
225 function Nextc
return Character;
226 -- Return current character without modifying pointer P
228 procedure Get_Typeref
229 (Current_File_Num
: Sdep_Id
;
231 File_Num
: out Sdep_Id
;
233 Ref_Type
: out Character;
235 Standard_Entity
: out Name_Id
);
236 -- Parse the definition of a typeref (<...>, {...} or (...))
239 -- Skip past spaces, then skip past end of line (fatal error if not
240 -- at end of line). Also skips past any following blank lines.
243 -- Skip rest of current line and any following blank lines
245 procedure Skip_Space
;
246 -- Skip past white space (blanks or horizontal tab)
249 -- Skip past next character, does not affect value in C. This call
250 -- is like calling Getc and ignoring the returned result.
252 ---------------------
253 -- At_End_Of_Field --
254 ---------------------
256 function At_End_Of_Field
return Boolean is
265 function At_Eol
return Boolean is
267 return Nextc
= EOF
or else Nextc
= CR
or else Nextc
= LF
;
270 ---------------------------
271 -- Check_At_End_Of_Field --
272 ---------------------------
274 procedure Check_At_End_Of_Field
is
276 if not At_End_Of_Field
then
277 if Ignore_Errors
then
278 while Nextc
> ' ' loop
285 end Check_At_End_Of_Field
;
287 ------------------------
288 -- Check_Unknown_Line --
289 ------------------------
291 procedure Check_Unknown_Line
is
293 while C
not in 'A' .. 'Z'
294 or else not Known_ALI_Lines
(C
)
296 if C
= CR
or else C
= LF
then
303 elsif Ignore_Errors
then
311 end Check_Unknown_Line
;
317 procedure Checkc
(C
: Character) is
321 elsif Ignore_Errors
then
332 procedure Fatal_Error
is
337 procedure Wchar
(C
: Character);
338 -- Write a single character, replacing horizontal tab by spaces
340 procedure Wchar
(C
: Character) is
345 exit when Col
mod 8 = 0;
354 -- Start of processing for Fatal_Error
358 raise Bad_ALI_Format
;
362 Write_Str
("fatal error: file ");
364 Write_Str
(" is incorrectly formatted");
367 Write_Str
("make sure you are using consistent versions " &
369 -- Split the following line so that it can easily be transformed for
370 -- e.g. JVM/.NET back-ends where the compiler has a different name.
376 -- Find start of line
380 and then T
(Ptr1
- 1) /= CR
381 and then T
(Ptr1
- 1) /= LF
386 Write_Int
(Int
(Line
));
401 and then T
(Ptr2
) /= CR
402 and then T
(Ptr2
) /= LF
414 if T
(Ptr1
) = HT
then
426 Exit_Program
(E_Fatal
);
429 ------------------------
430 -- Fatal_Error_Ignore --
431 ------------------------
433 procedure Fatal_Error_Ignore
is
435 if not Ignore_Errors
then
438 end Fatal_Error_Ignore
;
444 function Get_File_Name
445 (Lower
: Boolean := False) return File_Name_Type
450 F
:= Get_Name
(Ignore_Special
=> True);
452 -- Convert file name to all lower case if file names are not case
453 -- sensitive. This ensures that we handle names in the canonical
454 -- lower case format, regardless of the actual case.
456 if Lower
and not File_Names_Case_Sensitive
then
457 Canonical_Case_File_Name
(Name_Buffer
(1 .. Name_Len
));
460 return File_Name_Type
(F
);
469 (Ignore_Spaces
: Boolean := False;
470 Ignore_Special
: Boolean := False) return Name_Id
477 if Ignore_Errors
then
485 Add_Char_To_Name_Buffer
(Getc
);
487 exit when At_End_Of_Field
and then 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 bad 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 else 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' |
'Y' |
'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 Queuing_Policy
=> ' ',
822 Restrictions
=> No_Restrictions
,
823 SAL_Interface
=> False,
825 Task_Dispatching_Policy
=> ' ',
826 Time_Slice_Value
=> -1,
828 Unit_Exception_Table
=> False,
829 Ver
=> (others => ' '),
831 Zero_Cost_Exceptions
=> False);
833 -- Now we acquire the input lines from the ALI file. Note that the
834 -- convention in the following code is that as we enter each section,
835 -- C is set to contain the first character of the following line.
840 -- Acquire library version
844 -- The V line missing really indicates trouble, most likely it
845 -- means we don't have an ALI file at all, so here we give a
846 -- fatal error even if we are in Ignore_Errors mode.
850 elsif Ignore
('V') then
858 for J
in 1 .. Ver_Len_Max
loop
861 ALIs
.Table
(Id
).Ver
(J
) := C
;
862 ALIs
.Table
(Id
).Ver_Len
:= J
;
871 -- Acquire main program line if present
884 ALIs
.Table
(Id
).Main_Program
:= Func
;
886 ALIs
.Table
(Id
).Main_Program
:= Proc
;
896 ALIs
.Table
(Id
).Main_Priority
:= Get_Nat
;
904 ALIs
.Table
(Id
).Time_Slice_Value
:= Get_Nat
;
911 ALIs
.Table
(Id
).WC_Encoding
:= Getc
;
920 -- Acquire argument lines
922 First_Arg
:= Args
.Last
+ 1;
926 exit A_Loop
when C
/= 'A';
937 while not At_Eol
loop
938 Add_Char_To_Name_Buffer
(Getc
);
941 -- If -fstack-check, record that it occurred
943 if Name_Buffer
(1 .. Name_Len
) = "-fstack-check" then
944 Stack_Check_Switch_Set
:= True;
947 -- Store the argument
950 Args
.Table
(Args
.Last
) := new String'(Name_Buffer (1 .. Name_Len));
963 if Ignore_Errors then
983 while not At_Eol loop
992 ALIs.Table (Id).Compile_Errors := True;
998 Detect_Blocking := True;
1000 -- Processing for FD/FG/FI
1003 Float_Format_Specified := Getc;
1004 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1006 -- Processing for Lx
1009 Locking_Policy_Specified := Getc;
1010 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1012 -- Processing for flags starting with N
1017 -- Processing for NO
1020 ALIs.Table (Id).No_Object := True;
1021 No_Object_Specified := True;
1023 -- Processing for NR
1026 No_Run_Time_Mode := True;
1027 Configurable_Run_Time_Mode := True;
1029 -- Processing for NS
1032 ALIs.Table (Id).Normalize_Scalars := True;
1033 Normalize_Scalars_Specified := True;
1036 -- Invalid switch starting with N
1042 -- Processing for Qx
1045 Queuing_Policy_Specified := Getc;
1046 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1048 -- Processing for flags starting with S
1053 -- Processing for SL
1056 ALIs.Table (Id).SAL_Interface := True;
1058 -- Processing for SS
1061 Opt.Sec_Stack_Used := True;
1063 -- Invalid switch starting with S
1069 -- Processing for Tx
1072 Task_Dispatching_Policy_Specified := Getc;
1073 ALIs.Table (Id).Task_Dispatching_Policy :=
1074 Task_Dispatching_Policy_Specified;
1076 -- Processing for switch starting with U
1081 -- Processing for UA
1084 Unreserve_All_Interrupts_Specified := True;
1086 -- Processing for UX
1089 ALIs.Table (Id).Unit_Exception_Table := True;
1091 -- Invalid switches starting with U
1097 -- Processing for ZX
1103 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1104 Zero_Cost_Exceptions_Specified := True;
1109 -- Invalid parameter
1117 if not NS_Found then
1118 No_Normalize_Scalars_Specified := True;
1127 -- Acquire first restrictions line
1130 if Ignore_Errors then
1142 if Ignore ('R
') then
1145 -- Process restrictions line
1148 Scan_Restrictions : declare
1149 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1150 -- Save cumulative restrictions in case we have a fatal error
1152 Bad_R_Line : exception;
1153 -- Signal bad restrictions line (raised on unexpected character)
1159 -- Acquire information for boolean restrictions
1161 for R in All_Boolean_Restrictions loop
1166 ALIs.Table (Id).Restrictions.Violated (R) := True;
1167 Cumulative_Restrictions.Violated (R) := True;
1170 ALIs.Table (Id).Restrictions.Set (R) := True;
1171 Cumulative_Restrictions.Set (R) := True;
1181 -- Acquire information for parameter restrictions
1183 for RP in All_Parameter_Restrictions loop
1185 -- Acquire restrictions pragma information
1192 ALIs.Table (Id).Restrictions.Set (RP) := True;
1195 N : constant Integer := Integer (Get_Nat);
1197 ALIs.Table (Id).Restrictions.Value (RP) := N;
1199 if Cumulative_Restrictions.Set (RP) then
1200 Cumulative_Restrictions.Value (RP) :=
1202 (Cumulative_Restrictions.Value (RP), N);
1204 Cumulative_Restrictions.Set (RP) := True;
1205 Cumulative_Restrictions.Value (RP) := N;
1213 -- Acquire restrictions violations information
1220 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1221 Cumulative_Restrictions.Violated (RP) := True;
1224 N : constant Integer := Integer (Get_Nat);
1225 pragma Unsuppress (Overflow_Check);
1228 ALIs.Table (Id).Restrictions.Count (RP) := N;
1230 if RP in Checked_Max_Parameter_Restrictions then
1231 Cumulative_Restrictions.Count (RP) :=
1233 (Cumulative_Restrictions.Count (RP), N);
1235 Cumulative_Restrictions.Count (RP) :=
1236 Cumulative_Restrictions.Count (RP) + N;
1240 when Constraint_Error =>
1242 -- A constraint error comes from the addition in
1243 -- the else branch. We reset to the maximum and
1244 -- indicate that the real value is now unknown.
1246 Cumulative_Restrictions.Value (RP) := Integer'Last;
1247 Cumulative_Restrictions.Unknown (RP) := True;
1252 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1253 Cumulative_Restrictions.Unknown (RP) := True;
1263 -- Here if error during scanning of restrictions line
1268 -- In Ignore_Errors mode, undo any changes to restrictions
1269 -- from this unit, and continue on.
1271 if Ignore_Errors then
1272 Cumulative_Restrictions := Save_R;
1273 ALIs.Table (Id).Restrictions := No_Restrictions;
1276 -- In normal mode, this is a fatal error
1282 end Scan_Restrictions;
1285 -- Acquire additional restrictions (No_Dependence) lines if present
1289 if Ignore ('R
') then
1293 No_Deps.Append ((Id, Get_Name));
1300 -- Acquire 'I
' lines if present
1305 if Ignore ('I
') then
1311 I_State : Character;
1320 Interrupt_States.Append (
1321 (Interrupt_Id => Int_Num,
1322 Interrupt_State => I_State,
1323 IS_Pragma_Line => Line_No));
1325 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1333 -- Acquire 'S
' lines if present
1338 if Ignore ('S
') then
1354 First_Prio := Get_Nat;
1355 Last_Prio := Get_Nat;
1358 Specific_Dispatching.Append (
1359 (Dispatching_Policy => Policy,
1360 First_Priority => First_Prio,
1361 Last_Priority => Last_Prio,
1362 PSD_Pragma_Line => Line_No));
1364 ALIs.Table (Id).Last_Specific_Dispatching :=
1365 Specific_Dispatching.Last;
1374 -- Loop to acquire unit entries
1378 exit U_Loop when C /= 'U
';
1380 -- Note: as per spec, we never ignore U lines
1384 Units.Increment_Last;
1386 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1387 ALIs.Table (Id).First_Unit := Units.Last;
1391 UL : Unit_Record renames Units.Table (Units.Last);
1394 UL.Uname := Get_Unit_Name;
1395 UL.Predefined := Is_Predefined_Unit;
1396 UL.Internal := Is_Internal_Unit;
1398 UL.Sfile := Get_File_Name (Lower => True);
1400 UL.Preelab := False;
1401 UL.No_Elab := False;
1402 UL.Shared_Passive := False;
1404 UL.Remote_Types := False;
1405 UL.Has_RACW := False;
1406 UL.Init_Scalars := False;
1407 UL.Is_Generic := False;
1408 UL.Icasing := Mixed_Case;
1409 UL.Kcasing := All_Lower_Case;
1410 UL.Dynamic_Elab := False;
1411 UL.Elaborate_Body := False;
1412 UL.Set_Elab_Entity := False;
1413 UL.Version := "00000000";
1414 UL.First_With := Withs.Last + 1;
1415 UL.First_Arg := First_Arg;
1416 UL.Elab_Position := 0;
1417 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1418 UL.Body_Needed_For_SAL := False;
1419 UL.Elaborate_Body_Desirable := False;
1420 UL.Optimize_Alignment := 'O
';
1422 if Debug_Flag_U then
1423 Write_Str (" ----> reading unit ");
1424 Write_Int (Int (Units.Last));
1426 Write_Unit_Name (UL.Uname);
1427 Write_Str (" from file ");
1428 Write_Name (UL.Sfile);
1433 -- Check for duplicated unit in different files
1436 Info : constant Int := Get_Name_Table_Info
1437 (Units.Table (Units.Last).Uname);
1440 and then Units.Table (Units.Last).Sfile /=
1441 Units.Table (Unit_Id (Info)).Sfile
1443 -- If Err is set then ignore duplicate unit name. This is the
1444 -- case of a call from gnatmake, where the situation can arise
1445 -- from substitution of source files. In such situations, the
1446 -- processing in gnatmake will always result in any required
1447 -- recompilations in any case, and if we consider this to be
1448 -- an error we get strange cases (for example when a generic
1449 -- instantiation is replaced by a normal package) where we
1450 -- read the old ali file, decide to recompile, and then decide
1451 -- that the old and new ali files are incompatible.
1456 -- If Err is not set, then this is a fatal error. This is
1457 -- the case of being called from the binder, where we must
1458 -- definitely diagnose this as an error.
1462 Write_Str ("error: duplicate unit name: ");
1465 Write_Str ("error: unit """);
1466 Write_Unit_Name (Units.Table (Units.Last).Uname);
1467 Write_Str (""" found in file """);
1468 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1472 Write_Str ("error
: unit
""");
1473 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1474 Write_Str (""" found
in file
""");
1475 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1479 Exit_Program (E_Fatal);
1485 (Units.Table (Units.Last).Uname, Int (Units.Last));
1487 -- Scan out possible version and other parameters
1496 if C in '0' .. '9' or else C in 'a
' .. 'f
' then
1497 Units.Table (Units.Last).Version (1) := C;
1499 for J in 2 .. 8 loop
1501 Units.Table (Units.Last).Version (J) := C;
1510 Check_At_End_Of_Field;
1511 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1514 Check_At_End_Of_Field;
1515 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1521 -- DE parameter (Dynamic elaboration checks)
1527 Check_At_End_Of_Field;
1528 Units.Table (Units.Last).Dynamic_Elab := True;
1529 Dynamic_Elaboration_Checks_Specified := True;
1540 Units.Table (Units.Last).Elaborate_Body := True;
1542 Units.Table (Units.Last).Set_Elab_Entity := True;
1547 Check_At_End_Of_Field;
1549 -- GE parameter (generic)
1555 Check_At_End_Of_Field;
1556 Units.Table (Units.Last).Is_Generic := True;
1561 -- IL/IS/IU parameters
1567 Units.Table (Units.Last).Icasing := All_Lower_Case;
1569 Units.Table (Units.Last).Init_Scalars := True;
1570 Initialize_Scalars_Used := True;
1572 Units.Table (Units.Last).Icasing := All_Upper_Case;
1577 Check_At_End_Of_Field;
1585 Units.Table (Units.Last).Kcasing := Mixed_Case;
1587 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1592 Check_At_End_Of_Field;
1600 Units.Table (Units.Last).No_Elab := True;
1601 Check_At_End_Of_Field;
1606 -- PR/PU/PK parameters
1612 Units.Table (Units.Last).Preelab := True;
1614 Units.Table (Units.Last).Pure := True;
1616 Units.Table (Units.Last).Unit_Kind := 'p
';
1621 Check_At_End_Of_Field;
1623 -- OL/OO/OS/OT parameters
1628 if C = 'L
' or else C = 'O
' or else C = 'S
' or else C = 'T
' then
1629 Units.Table (Units.Last).Optimize_Alignment := C;
1634 Check_At_End_Of_Field;
1642 Units.Table (Units.Last).RCI := True;
1644 Units.Table (Units.Last).Remote_Types := True;
1646 Units.Table (Units.Last).Has_RACW := True;
1651 Check_At_End_Of_Field;
1657 Units.Table (Units.Last).Shared_Passive := True;
1659 Units.Table (Units.Last).Unit_Kind := 's
';
1664 Check_At_End_Of_Field;
1674 -- Check if static elaboration model used
1676 if not Units.Table (Units.Last).Dynamic_Elab
1677 and then not Units.Table (Units.Last).Internal
1679 Static_Elaboration_Model_Used := True;
1684 -- Scan out With lines for this unit
1688 exit With_Loop when C /= 'W
' and then C /= 'Y
';
1690 if Ignore ('W
') then
1696 Withs.Increment_Last;
1697 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1698 Withs.Table (Withs.Last).Elaborate := False;
1699 Withs.Table (Withs.Last).Elaborate_All := False;
1700 Withs.Table (Withs.Last).Elab_Desirable := False;
1701 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1702 Withs.Table (Withs.Last).SAL_Interface := False;
1703 Withs.Table (Withs.Last).Limited_With := (C = 'Y
');
1705 -- Generic case with no object file available
1708 Withs.Table (Withs.Last).Sfile := No_File;
1709 Withs.Table (Withs.Last).Afile := No_File;
1714 Withs.Table (Withs.Last).Sfile := Get_File_Name
1716 Withs.Table (Withs.Last).Afile := Get_File_Name
1719 -- Scan out possible E, EA, ED, and AD parameters
1721 while not At_Eol loop
1727 Check_At_End_Of_Field;
1729 -- Store AD indication unless ignore required
1731 if not Ignore_ED then
1732 Withs.Table (Withs.Last).Elab_All_Desirable :=
1736 elsif Nextc = 'E
' then
1739 if At_End_Of_Field then
1740 Withs.Table (Withs.Last).Elaborate := True;
1742 elsif Nextc = 'A
' then
1744 Check_At_End_Of_Field;
1745 Withs.Table (Withs.Last).Elaborate_All := True;
1749 Check_At_End_Of_Field;
1751 -- Store ED indication unless ignore required
1753 if not Ignore_ED then
1754 Withs.Table (Withs.Last).Elab_Desirable :=
1771 Units.Table (Units.Last).Last_With := Withs.Last;
1772 Units.Table (Units.Last).Last_Arg := Args.Last;
1774 -- If there are linker options lines present, scan them
1778 Linker_Options_Loop : loop
1780 exit Linker_Options_Loop when C /= 'L
';
1782 if Ignore ('L
') then
1793 if C < Character'Val (16#20#)
1794 or else C > Character'Val (16#7E#)
1799 C := Character'Val (0);
1806 for J in 1 .. 2 loop
1809 if C in '0' .. '9' then
1812 Character'Pos ('0');
1814 elsif C in 'A' .. 'F' then
1817 Character'Pos ('A') +
1826 Add_Char_To_Name_Buffer (Character'Val (V));
1831 exit when Nextc /= '"';
1835 Add_Char_To_Name_Buffer (C);
1839 Add_Char_To_Name_Buffer (NUL);
1844 end loop Linker_Options_Loop;
1846 -- Store the linker options entry if one was found
1848 if Name_Len /= 0 then
1849 Linker_Options.Increment_Last;
1851 Linker_Options.Table (Linker_Options.Last).Name :=
1854 Linker_Options.Table (Linker_Options.Last).Unit :=
1857 Linker_Options.Table (Linker_Options.Last).Internal_File :=
1858 Is_Internal_File_Name (F);
1860 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1861 Linker_Options.Last;
1865 -- End loop through units for one ALI file
1867 ALIs.Table (Id).Last_Unit := Units.Last;
1868 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1870 -- Set types of the units (there can be at most 2 of them)
1872 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1873 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1874 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
1877 -- Deal with body only and spec only cases, note that the reason we
1878 -- do our own checking of the name (rather than using Is_Body_Name)
1879 -- is that Uname drags in far too much compiler junk!
1881 Get_Name_String (Units.Table (Units.Last).Uname);
1883 if Name_Buffer (Name_Len) = 'b' then
1884 Units.Table (Units.Last).Utype := Is_Body_Only;
1886 Units.Table (Units.Last).Utype := Is_Spec_Only;
1890 -- Scan out external version references and put in hash table
1894 exit E_Loop when C /= 'E';
1896 if Ignore ('E') then
1912 exit when At_End_Of_Field;
1913 Add_Char_To_Name_Buffer (C);
1916 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1923 -- Scan out source dependency lines for this ALI file
1925 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
1929 exit D_Loop when C /= 'D';
1931 if Ignore ('D') then
1937 Sdep.Increment_Last;
1939 -- In the following call, Lower is not set to True, this is either
1940 -- a bug, or it deserves a special comment as to why this is so???
1942 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
1944 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
1945 Sdep.Table (Sdep.Last).Dummy_Entry :=
1946 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
1948 -- Acquire checksum value
1961 exit when At_Eol or else Ctr = 8;
1963 if Nextc in '0' .. '9' then
1965 Character'Pos (Nextc) - Character'Pos ('0');
1967 elsif Nextc in 'a' .. 'f' then
1969 Character'Pos (Nextc) - Character'Pos ('a') + 10;
1979 if Ctr = 8 and then At_End_Of_Field then
1980 Sdep.Table (Sdep.Last).Checksum := Chk;
1986 -- Acquire subunit and reference file name entries
1988 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
1989 Sdep.Table (Sdep.Last).Rfile :=
1990 Sdep.Table (Sdep.Last).Sfile;
1991 Sdep.Table (Sdep.Last).Start_Line := 1;
1996 -- Here for subunit name
1998 if Nextc not in '0' .. '9' then
2000 while not At_End_Of_Field loop
2001 Add_Char_To_Name_Buffer (Getc);
2004 -- Set the subunit name. Note that we use Name_Find rather
2005 -- than Name_Enter here as the subunit name may already
2006 -- have been put in the name table by the Project Manager.
2008 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
2013 -- Here for reference file name entry
2015 if Nextc in '0' .. '9' then
2016 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2021 while not At_End_Of_Field loop
2022 Add_Char_To_Name_Buffer (Getc);
2025 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2035 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2037 -- We must at this stage be at an Xref line or the end of file
2049 -- If we are ignoring Xref sections we are done (we ignore all
2050 -- remaining lines since only xref related lines follow X).
2052 if Ignore ('X') and then not Debug_Flag_X then
2056 -- Loop through Xref sections
2060 exit X_Loop when C /= 'X';
2062 -- Make new entry in section table
2064 Xref_Section.Increment_Last;
2066 Read_Refs_For_One_File : declare
2067 XS : Xref_Section_Record renames
2068 Xref_Section.Table (Xref_Section.Last);
2070 Current_File_Num : Sdep_Id;
2071 -- Keeps track of the current file number (changed by nn|)
2074 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2075 XS.File_Name := Get_File_Name;
2076 XS.First_Entity := Xref_Entity.Last + 1;
2078 Current_File_Num := XS.File_Num;
2085 -- Loop through Xref entities
2087 while C /= 'X' and then C /= EOF loop
2088 Xref_Entity.Increment_Last;
2090 Read_Refs_For_One_Entity : declare
2091 XE : Xref_Entity_Record renames
2092 Xref_Entity.Table (Xref_Entity.Last);
2095 procedure Read_Instantiation_Reference;
2096 -- Acquire instantiation reference. Caller has checked
2097 -- that current character is '[' and on return the cursor
2098 -- is skipped past the corresponding closing ']'.
2100 ----------------------------------
2101 -- Read_Instantiation_Reference --
2102 ----------------------------------
2104 procedure Read_Instantiation_Reference is
2105 Local_File_Num : Sdep_Id := Current_File_Num;
2108 Xref.Increment_Last;
2111 XR : Xref_Record renames Xref.Table (Xref.Last);
2114 P := P + 1; -- skip [
2119 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2120 Local_File_Num := XR.File_Num;
2125 XR.File_Num := Local_File_Num;
2132 -- Recursive call for next reference
2135 pragma Warnings (Off); -- kill recursion warning
2136 Read_Instantiation_Reference;
2137 pragma Warnings (On);
2140 -- Skip closing bracket after recursive call
2144 end Read_Instantiation_Reference;
2146 -- Start of processing for Read_Refs_For_One_Entity
2152 XE.Lib := (Getc = '*');
2153 XE.Entity := Get_Name;
2155 -- Handle the information about generic instantiations
2158 Skipc; -- Opening '['
2161 if Nextc /= '|' then
2162 XE.Iref_File_Num := Current_File_Num;
2166 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2168 XE.Iref_Line := Get_Nat;
2176 XE.Iref_File_Num := No_Sdep_Id;
2180 Current_File_Num := XS.File_Num;
2182 -- Renaming reference is present
2186 XE.Rref_Line := Get_Nat;
2192 XE.Rref_Col := Get_Nat;
2194 -- No renaming reference present
2203 XE.Oref_File_Num := No_Sdep_Id;
2204 XE.Tref_File_Num := No_Sdep_Id;
2205 XE.Tref := Tref_None;
2206 XE.First_Xref := Xref.Last + 1;
2208 -- Loop to check for additional info present
2221 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2222 exit when Ref = Tref_None;
2224 -- Do we have an overriding procedure?
2226 if Ref = Tref_Derived and then Typ = 'p' then
2227 XE.Oref_File_Num := File;
2228 XE.Oref_Line := Line;
2231 -- Arrays never override anything, and <> points to
2232 -- the index types instead
2234 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2236 -- Index types are stored in the list of references
2238 Xref.Increment_Last;
2241 XR : Xref_Record renames Xref.Table (Xref.Last);
2243 XR.File_Num := File;
2245 XR.Rtype := Array_Index_Reference;
2250 -- Interfaces are stored in the list of references,
2251 -- although the parent type itself is stored in XE.
2252 -- The first interface (when there are only
2253 -- interfaces) is stored in XE.Tref*)
2255 elsif Ref = Tref_Derived
2257 and then XE.Tref_File_Num /= No_Sdep_Id
2259 Xref.Increment_Last;
2262 XR : Xref_Record renames Xref.Table (Xref.Last);
2264 XR.File_Num := File;
2266 XR.Rtype := Interface_Reference;
2273 XE.Tref_File_Num := File;
2274 XE.Tref_Line := Line;
2275 XE.Tref_Type := Typ;
2277 XE.Tref_Standard_Entity := Std;
2282 -- Loop through cross-references for this entity
2289 exit when Nextc /= '.';
2293 Xref.Increment_Last;
2296 XR : Xref_Record renames Xref.Table (Xref.Last);
2303 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2304 Current_File_Num := XR.File_Num;
2308 XR.File_Num := Current_File_Num;
2314 -- Imported entities reference as in:
2315 -- 494b<c,__gnat_copy_attribs>25
2316 -- ??? Simply skipped for now
2319 while Getc /= '>' loop
2327 Read_Instantiation_Reference;
2332 -- Record last cross-reference
2334 XE.Last_Xref := Xref.Last;
2338 when Bad_ALI_Format =>
2340 -- If ignoring errors, then we skip a line with an
2341 -- unexpected error, and try to continue subsequent
2344 if Ignore_Errors then
2345 Xref_Entity.Decrement_Last;
2349 -- Otherwise, we reraise the fatal exception
2354 end Read_Refs_For_One_Entity;
2357 -- Record last entity
2359 XS.Last_Entity := Xref_Entity.Last;
2361 end Read_Refs_For_One_File;
2366 -- Here after dealing with xref sections
2368 if C /= EOF and then C /= 'X' then
2375 when Bad_ALI_Format =>
2383 function SEq (F1, F2 : String_Ptr) return Boolean is
2385 return F1.all = F2.all;
2392 function SHash (S : String_Ptr) return Vindex is
2397 for J in S.all'Range loop
2398 H := H * 2 + Character'Pos (S (J));
2401 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));