OSDN Git Service

2004-02-12 Olivier Hainque <hainque@act-europe.fr>
[pf3gnuchains/gcc-fork.git] / gcc / ada / ali.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                                  A L I                                   --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004 Free Software Foundation, Inc.          --
10 --                                                                          --
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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Butil;  use Butil;
28 with Debug;  use Debug;
29 with Fname;  use Fname;
30 with Namet;  use Namet;
31 with Opt;    use Opt;
32 with Osint;  use Osint;
33 with Output; use Output;
34
35 package body ALI is
36
37    use ASCII;
38    --  Make control characters visible
39
40    --  The following variable records which characters currently are
41    --  used as line type markers in the ALI file. This is used in
42    --  Scan_ALI to detect (or skip) invalid lines.
43
44    Known_ALI_Lines : constant array (Character range 'A' .. 'Z') of Boolean :=
45      ('V'    => True,   -- version
46       'M'    => True,   -- main program
47       'A'    => True,   -- argument
48       'P'    => True,   -- program
49       'R'    => True,   -- restriction
50       'I'    => True,   -- interrupt
51       'U'    => True,   -- unit
52       'W'    => True,   -- with
53       'L'    => True,   -- linker option
54       'E'    => True,   -- external
55       'D'    => True,   -- dependency
56       'X'    => True,   -- xref
57       others => False);
58
59    --------------------
60    -- Initialize_ALI --
61    --------------------
62
63    procedure Initialize_ALI is
64    begin
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.
69
70       for J in ALIs.First .. ALIs.Last loop
71          Set_Name_Table_Info (ALIs.Table (J).Afile, 0);
72       end loop;
73
74       for J in Units.First .. Units.Last loop
75          Set_Name_Table_Info (Units.Table (J).Uname, 0);
76       end loop;
77
78       --  Free argument table strings
79
80       for J in Args.First .. Args.Last loop
81          Free (Args.Table (J));
82       end loop;
83
84       --  Initialize all tables
85
86       ALIs.Init;
87       Units.Init;
88       Withs.Init;
89       Sdep.Init;
90       Linker_Options.Init;
91       Xref_Section.Init;
92       Xref_Entity.Init;
93       Xref.Init;
94       Version_Ref.Reset;
95
96       --  Add dummy zero'th item in Linker_Options for the sort function
97
98       Linker_Options.Increment_Last;
99
100       --  Initialize global variables recording cumulative options in all
101       --  ALI files that are read for a given processing run in gnatbind.
102
103       Dynamic_Elaboration_Checks_Specified := False;
104       Float_Format_Specified               := ' ';
105       Locking_Policy_Specified             := ' ';
106       No_Normalize_Scalars_Specified       := False;
107       No_Object_Specified                  := False;
108       Normalize_Scalars_Specified          := False;
109       Queuing_Policy_Specified             := ' ';
110       Static_Elaboration_Model_Used        := False;
111       Task_Dispatching_Policy_Specified    := ' ';
112       Unreserve_All_Interrupts_Specified   := False;
113       Zero_Cost_Exceptions_Specified       := False;
114    end Initialize_ALI;
115
116    --------------
117    -- Scan_ALI --
118    --------------
119
120    function Scan_ALI
121      (F             : File_Name_Type;
122       T             : Text_Buffer_Ptr;
123       Ignore_ED     : Boolean;
124       Err           : Boolean;
125       Read_Xref     : Boolean := False;
126       Read_Lines    : String  := "";
127       Ignore_Lines  : String  := "X";
128       Ignore_Errors : Boolean := False) return ALI_Id
129    is
130       P         : Text_Ptr := T'First;
131       Line      : Logical_Line_Number := 1;
132       Id        : ALI_Id;
133       C         : Character;
134       NS_Found  : Boolean;
135       First_Arg : Arg_Id;
136
137       Ignore : array (Character range 'A' .. 'Z') of Boolean;
138       --  Ignore (X) is set to True if lines starting with X are to
139       --  be ignored by Scan_ALI and skipped, and False if the lines
140       --  are to be read and processed.
141
142       Restrictions_Initial : Rident.Restrictions_Info;
143       pragma Warnings (Off, Restrictions_Initial);
144       --  This variable, which should really be a constant (but that's not
145       --  allowed by the language) is used only for initialization, and the
146       --  reason we are declaring it is to get the default initialization
147       --  set for the object.
148
149       Bad_ALI_Format : exception;
150       --  Exception raised by Fatal_Error if Err is True
151
152       function At_Eol return Boolean;
153       --  Test if at end of line
154
155       function At_End_Of_Field return Boolean;
156       --  Test if at end of line, or if at blank or horizontal tab
157
158       procedure Check_At_End_Of_Field;
159       --  Check if we are at end of field, fatal error if not
160
161       procedure Checkc (C : Character);
162       --  Check next character is C. If so bump past it, if not fatal error
163
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).
175
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.
179
180       procedure Fatal_Error_Ignore;
181       pragma Inline (Fatal_Error_Ignore);
182       --  In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
183
184       function Getc return Character;
185       --  Get next character, bumping P past the character obtained
186
187       function Get_Name
188         (Lower         : Boolean := False;
189          Ignore_Spaces : Boolean := False) return Name_Id;
190       --  Skip blanks, then scan out a name (name is left in Name_Buffer with
191       --  length in Name_Len, as well as being returned in Name_Id form).
192       --  If Lower is set to True then the Name_Buffer will be converted to
193       --  all lower case, for systems where file names are not case sensitive.
194       --  This ensures that gnatbind works correctly regardless of the case
195       --  of the file name on all systems. The name is terminated by a either
196       --  white space (when Ignore_Spaces is False) or a typeref bracket or
197       --  an equal sign except for the special case of an operator name
198       --  starting with a double quite which is terminated by another double
199       --  quote.
200
201       function Get_Nat return Nat;
202       --  Skip blanks, then scan out an unsigned integer value in Nat range.
203
204       function Get_Stamp return Time_Stamp_Type;
205       --  Skip blanks, then scan out a time stamp
206
207       function Nextc return Character;
208       --  Return current character without modifying pointer P
209
210       procedure Skip_Eol;
211       --  Skip past spaces, then skip past end of line (fatal error if not
212       --  at end of line). Also skips past any following blank lines.
213
214       procedure Skip_Line;
215       --  Skip rest of current line and any following blank lines.
216
217       procedure Skip_Space;
218       --  Skip past white space (blanks or horizontal tab)
219
220       procedure Skipc;
221       --  Skip past next character, does not affect value in C. This call
222       --  is like calling Getc and ignoring the returned result.
223
224       ---------------------
225       -- At_End_Of_Field --
226       ---------------------
227
228       function At_End_Of_Field return Boolean is
229       begin
230          return Nextc <= ' ';
231       end At_End_Of_Field;
232
233       ------------
234       -- At_Eol --
235       ------------
236
237       function At_Eol return Boolean is
238       begin
239          return Nextc = EOF or else Nextc = CR or else Nextc = LF;
240       end At_Eol;
241
242       ---------------------------
243       -- Check_At_End_Of_Field --
244       ---------------------------
245
246       procedure Check_At_End_Of_Field is
247       begin
248          if not At_End_Of_Field then
249             if Ignore_Errors then
250                while Nextc > ' ' loop
251                   P := P + 1;
252                end loop;
253             else
254                Fatal_Error;
255             end if;
256          end if;
257       end Check_At_End_Of_Field;
258
259       ------------
260       -- Checkc --
261       ------------
262
263       procedure Checkc (C : Character) is
264       begin
265          if Nextc = C then
266             P := P + 1;
267          elsif Ignore_Errors then
268             P := P + 1;
269          else
270             Fatal_Error;
271          end if;
272       end Checkc;
273
274       ------------------------
275       -- Check_Unknown_Line --
276       ------------------------
277
278       procedure Check_Unknown_Line is
279       begin
280          while C not in 'A' .. 'Z'
281            or else not Known_ALI_Lines (C)
282          loop
283             if C = CR or else C = LF then
284                Skip_Line;
285
286             elsif C = EOF then
287                return;
288
289             elsif Ignore_Errors then
290                Skip_Line;
291                C := Getc;
292
293             else
294                Fatal_Error;
295             end if;
296          end loop;
297       end Check_Unknown_Line;
298
299       -----------------
300       -- Fatal_Error --
301       -----------------
302
303       procedure Fatal_Error is
304          Ptr1 : Text_Ptr;
305          Ptr2 : Text_Ptr;
306          Col  : Int;
307
308          procedure Wchar (C : Character);
309          --  Write a single character, replacing horizontal tab by spaces
310
311          procedure Wchar (C : Character) is
312          begin
313             if C = HT then
314                loop
315                   Wchar (' ');
316                   exit when Col mod 8 = 0;
317                end loop;
318
319             else
320                Write_Char (C);
321                Col := Col + 1;
322             end if;
323          end Wchar;
324
325       --  Start of processing for Fatal_Error
326
327       begin
328          if Err then
329             raise Bad_ALI_Format;
330          end if;
331
332          Set_Standard_Error;
333          Write_Str ("fatal error: file ");
334          Write_Name (F);
335          Write_Str (" is incorrectly formatted");
336          Write_Eol;
337          Write_Str
338            ("make sure you are using consistent versions of gcc/gnatbind");
339          Write_Eol;
340
341          --  Find start of line
342
343          Ptr1 := P;
344
345          while Ptr1 > T'First
346            and then T (Ptr1 - 1) /= CR
347            and then T (Ptr1 - 1) /= LF
348          loop
349             Ptr1 := Ptr1 - 1;
350          end loop;
351
352          Write_Int (Int (Line));
353          Write_Str (". ");
354
355          if Line < 100 then
356             Write_Char (' ');
357          end if;
358
359          if Line < 10 then
360             Write_Char (' ');
361          end if;
362
363          Col := 0;
364          Ptr2 := Ptr1;
365
366          while Ptr2 < T'Last
367            and then T (Ptr2) /= CR
368            and then T (Ptr2) /= LF
369          loop
370             Wchar (T (Ptr2));
371             Ptr2 := Ptr2 + 1;
372          end loop;
373
374          Write_Eol;
375
376          Write_Str ("     ");
377          Col := 0;
378
379          while Ptr1 < P loop
380             if T (Ptr1) = HT then
381                Wchar (HT);
382             else
383                Wchar (' ');
384             end if;
385
386             Ptr1 := Ptr1 + 1;
387          end loop;
388
389          Wchar ('|');
390          Write_Eol;
391
392          Exit_Program (E_Fatal);
393       end Fatal_Error;
394
395       ------------------------
396       -- Fatal_Error_Ignore --
397       ------------------------
398
399       procedure Fatal_Error_Ignore is
400       begin
401          if not Ignore_Errors then
402             Fatal_Error;
403          end if;
404       end Fatal_Error_Ignore;
405
406       --------------
407       -- Get_Name --
408       --------------
409
410       function Get_Name
411         (Lower         : Boolean := False;
412          Ignore_Spaces : Boolean := False) return Name_Id
413       is
414       begin
415          Name_Len := 0;
416          Skip_Space;
417
418          if At_Eol then
419             if Ignore_Errors then
420                return Error_Name;
421             else
422                Fatal_Error;
423             end if;
424          end if;
425
426          loop
427             Name_Len := Name_Len + 1;
428             Name_Buffer (Name_Len) := Getc;
429
430             exit when At_End_Of_Field and not Ignore_Spaces;
431
432             if Name_Buffer (1) = '"' then
433                exit when Name_Len > 1 and then Name_Buffer (Name_Len) = '"';
434
435             else
436                exit when (At_End_Of_Field and not Ignore_Spaces)
437                  or else Nextc = '(' or else Nextc = ')'
438                  or else Nextc = '{' or else Nextc = '}'
439                  or else Nextc = '<' or else Nextc = '>'
440                  or else Nextc = '=';
441             end if;
442          end loop;
443
444          --  Convert file name to all lower case if file names are not case
445          --  sensitive. This ensures that we handle names in the canonical
446          --  lower case format, regardless of the actual case.
447
448          if Lower and not File_Names_Case_Sensitive then
449             Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
450          end if;
451
452          return Name_Find;
453       end Get_Name;
454
455       -------------
456       -- Get_Nat --
457       -------------
458
459       function Get_Nat return Nat is
460          V : Nat;
461
462       begin
463          Skip_Space;
464
465          V := 0;
466          loop
467             V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
468             exit when At_End_Of_Field;
469             exit when Nextc < '0' or Nextc > '9';
470          end loop;
471
472          return V;
473       end Get_Nat;
474
475       ---------------
476       -- Get_Stamp --
477       ---------------
478
479       function Get_Stamp return Time_Stamp_Type is
480          T     : Time_Stamp_Type;
481          Start : Integer;
482
483       begin
484          Skip_Space;
485
486          if At_Eol then
487             if Ignore_Errors then
488                return Dummy_Time_Stamp;
489             else
490                Fatal_Error;
491             end if;
492          end if;
493
494          --  Following reads old style time stamp missing first two digits
495
496          if Nextc in '7' .. '9' then
497             T (1) := '1';
498             T (2) := '9';
499             Start := 3;
500
501          --  Normal case of full year in time stamp
502
503          else
504             Start := 1;
505          end if;
506
507          for J in Start .. T'Last loop
508             T (J) := Getc;
509          end loop;
510
511          return T;
512       end Get_Stamp;
513
514       ----------
515       -- Getc --
516       ----------
517
518       function Getc return Character is
519       begin
520          if P = T'Last then
521             return EOF;
522          else
523             P := P + 1;
524             return T (P - 1);
525          end if;
526       end Getc;
527
528       -----------
529       -- Nextc --
530       -----------
531
532       function Nextc return Character is
533       begin
534          return T (P);
535       end Nextc;
536
537       --------------
538       -- Skip_Eol --
539       --------------
540
541       procedure Skip_Eol is
542       begin
543          Skip_Space;
544
545          if not At_Eol then
546             if Ignore_Errors then
547                while not At_Eol loop
548                   P := P + 1;
549                end loop;
550             else
551                Fatal_Error;
552             end if;
553          end if;
554
555          --  Loop to skip past blank lines (first time through skips this EOL)
556
557          while Nextc < ' ' and then Nextc /= EOF loop
558             if Nextc = LF then
559                Line := Line + 1;
560             end if;
561
562             P := P + 1;
563          end loop;
564       end Skip_Eol;
565
566       ---------------
567       -- Skip_Line --
568       ---------------
569
570       procedure Skip_Line is
571       begin
572          while not At_Eol loop
573             P := P + 1;
574          end loop;
575
576          Skip_Eol;
577       end Skip_Line;
578
579       ----------------
580       -- Skip_Space --
581       ----------------
582
583       procedure Skip_Space is
584       begin
585          while Nextc = ' ' or else Nextc = HT loop
586             P := P + 1;
587          end loop;
588       end Skip_Space;
589
590       -----------
591       -- Skipc --
592       -----------
593
594       procedure Skipc is
595       begin
596          if P /= T'Last then
597             P := P + 1;
598          end if;
599       end Skipc;
600
601    --  Start of processing for Scan_ALI
602
603    begin
604       --  Acquire lines to be ignored
605
606       if Read_Xref then
607          Ignore := ('U' | 'W' | 'D' | 'X' => False, others => True);
608
609       --  Read_Lines parameter given
610
611       elsif Read_Lines /= "" then
612          Ignore := ('U' => False, others => True);
613
614          for J in Read_Lines'Range loop
615             Ignore (Read_Lines (J)) := False;
616          end loop;
617
618       --  Process Ignore_Lines parameter
619
620       else
621          Ignore := (others => False);
622
623          for J in Ignore_Lines'Range loop
624             pragma Assert (Ignore_Lines (J) /= 'U');
625             Ignore (Ignore_Lines (J)) := True;
626          end loop;
627       end if;
628
629       --  Setup ALI Table entry with appropriate defaults
630
631       ALIs.Increment_Last;
632       Id := ALIs.Last;
633       Set_Name_Table_Info (F, Int (Id));
634
635       ALIs.Table (Id) := (
636         Afile                      => F,
637         Compile_Errors             => False,
638         First_Interrupt_State      => Interrupt_States.Last + 1,
639         First_Sdep                 => No_Sdep_Id,
640         First_Unit                 => No_Unit_Id,
641         Float_Format               => 'I',
642         Last_Interrupt_State       => Interrupt_States.Last,
643         Last_Sdep                  => No_Sdep_Id,
644         Last_Unit                  => No_Unit_Id,
645         Locking_Policy             => ' ',
646         Main_Priority              => -1,
647         Main_Program               => None,
648         No_Object                  => False,
649         Normalize_Scalars          => False,
650         Ofile_Full_Name            => Full_Object_File_Name,
651         Queuing_Policy             => ' ',
652         Restrictions               => Restrictions_Initial,
653         Sfile                      => No_Name,
654         Task_Dispatching_Policy    => ' ',
655         Time_Slice_Value           => -1,
656         WC_Encoding                => '8',
657         Unit_Exception_Table       => False,
658         Ver                        => (others => ' '),
659         Ver_Len                    => 0,
660         Interface                  => False,
661         Zero_Cost_Exceptions       => False);
662
663       --  Now we acquire the input lines from the ALI file. Note that the
664       --  convention in the following code is that as we enter each section,
665       --  C is set to contain the first character of the following line.
666
667       C := Getc;
668       Check_Unknown_Line;
669
670       --  Acquire library version
671
672       if C /= 'V' then
673
674          --  The V line missing really indicates trouble, most likely it
675          --  means we don't have an ALI file at all, so here we give a
676          --  fatal error even if we are in Ignore_Errors mode.
677
678          Fatal_Error;
679
680       elsif Ignore ('V') then
681          Skip_Line;
682
683       else
684          Checkc (' ');
685          Skip_Space;
686          Checkc ('"');
687
688          for J in 1 .. Ver_Len_Max loop
689             C := Getc;
690             exit when C = '"';
691             ALIs.Table (Id).Ver (J) := C;
692             ALIs.Table (Id).Ver_Len := J;
693          end loop;
694
695          Skip_Eol;
696       end if;
697
698       C := Getc;
699       Check_Unknown_Line;
700
701       --  Acquire main program line if present
702
703       if C = 'M' then
704          if Ignore ('M') then
705             Skip_Line;
706
707          else
708             Checkc (' ');
709             Skip_Space;
710
711             C := Getc;
712
713             if C = 'F' then
714                ALIs.Table (Id).Main_Program := Func;
715             elsif C = 'P' then
716                ALIs.Table (Id).Main_Program := Proc;
717             else
718                P := P - 1;
719                Fatal_Error;
720             end if;
721
722             Skip_Space;
723
724             if not At_Eol then
725                if Nextc < 'A' then
726                   ALIs.Table (Id).Main_Priority := Get_Nat;
727                end if;
728
729                Skip_Space;
730
731                if Nextc = 'T' then
732                   P := P + 1;
733                   Checkc ('=');
734                   ALIs.Table (Id).Time_Slice_Value := Get_Nat;
735                end if;
736
737                Skip_Space;
738
739                Checkc ('W');
740                Checkc ('=');
741                ALIs.Table (Id).WC_Encoding := Getc;
742             end if;
743
744             Skip_Eol;
745          end if;
746
747          C := Getc;
748       end if;
749
750       --  Acquire argument lines
751
752       First_Arg := Args.Last + 1;
753
754       A_Loop : loop
755          Check_Unknown_Line;
756          exit A_Loop when C /= 'A';
757
758          if Ignore ('A') then
759             Skip_Line;
760
761          else
762             Checkc (' ');
763             Name_Len := 0;
764
765             while not At_Eol loop
766                Name_Len := Name_Len + 1;
767                Name_Buffer (Name_Len) := Getc;
768             end loop;
769
770             Args.Increment_Last;
771             Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
772
773             Skip_Eol;
774          end if;
775
776          C := Getc;
777       end loop A_Loop;
778
779       --  Acquire P line
780
781       Check_Unknown_Line;
782
783       while C /= 'P' loop
784          if Ignore_Errors then
785             if C = EOF then
786                Fatal_Error;
787             else
788                Skip_Line;
789             end if;
790          else
791             Fatal_Error;
792          end if;
793       end loop;
794
795       if Ignore ('P') then
796          Skip_Line;
797
798       --  Process P line
799
800       else
801          NS_Found := False;
802
803          while not At_Eol loop
804             Checkc (' ');
805             Skip_Space;
806             C := Getc;
807
808             --  Processing for CE
809
810             if C = 'C' then
811                Checkc ('E');
812                ALIs.Table (Id).Compile_Errors := True;
813
814             --  Processing for FD/FG/FI
815
816             elsif C = 'F' then
817                Float_Format_Specified := Getc;
818                ALIs.Table (Id).Float_Format := Float_Format_Specified;
819
820             --  Processing for Lx
821
822             elsif C = 'L' then
823                Locking_Policy_Specified := Getc;
824                ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
825
826             --  Processing for flags starting with N
827
828             elsif C = 'N' then
829                C := Getc;
830
831                --  Processing for NO
832
833                if C = 'O' then
834                   ALIs.Table (Id).No_Object := True;
835                   No_Object_Specified := True;
836
837                --  Processing for NR
838
839                elsif C = 'R' then
840                   No_Run_Time_Mode           := True;
841                   Configurable_Run_Time_Mode := True;
842
843                --  Processing for NS
844
845                elsif C = 'S' then
846                   ALIs.Table (Id).Normalize_Scalars := True;
847                   Normalize_Scalars_Specified := True;
848                   NS_Found := True;
849
850                --  Invalid switch starting with N
851
852                else
853                   Fatal_Error_Ignore;
854                end if;
855
856             --  Processing for Qx
857
858             elsif C = 'Q' then
859                Queuing_Policy_Specified := Getc;
860                ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
861
862             --  Processing for flags starting with S
863
864             elsif C = 'S' then
865                C := Getc;
866
867                --  Processing for SL
868
869                if C = 'L' then
870                   ALIs.Table (Id).Interface := True;
871
872                --  Processing for SS
873
874                elsif C = 'S' then
875                   Opt.Sec_Stack_Used := True;
876
877                --  Invalid switch starting with S
878
879                else
880                   Fatal_Error_Ignore;
881                end if;
882
883             --  Processing for Tx
884
885             elsif C = 'T' then
886                Task_Dispatching_Policy_Specified := Getc;
887                ALIs.Table (Id).Task_Dispatching_Policy :=
888                  Task_Dispatching_Policy_Specified;
889
890             --  Processing for switch starting with U
891
892             elsif C = 'U' then
893                C := Getc;
894
895                --  Processing for UA
896
897                if C  = 'A' then
898                   Unreserve_All_Interrupts_Specified := True;
899
900                --  Processing for UX
901
902                elsif C = 'X' then
903                   ALIs.Table (Id).Unit_Exception_Table := True;
904
905                --  Invalid switches starting with U
906
907                else
908                   Fatal_Error_Ignore;
909                end if;
910
911             --  Processing for ZX
912
913             elsif C = 'Z' then
914                C := Getc;
915
916                if C = 'X' then
917                   ALIs.Table (Id).Zero_Cost_Exceptions := True;
918                   Zero_Cost_Exceptions_Specified := True;
919                else
920                   Fatal_Error_Ignore;
921                end if;
922
923             --  Invalid parameter
924
925             else
926                C := Getc;
927                Fatal_Error_Ignore;
928             end if;
929          end loop;
930
931          if not NS_Found then
932             No_Normalize_Scalars_Specified := True;
933          end if;
934
935          Skip_Eol;
936       end if;
937
938       C := Getc;
939       Check_Unknown_Line;
940
941       --  Acquire restrictions line
942
943       while C /= 'R' loop
944          if Ignore_Errors then
945             if C = EOF then
946                Fatal_Error;
947             else
948                Skip_Line;
949             end if;
950          else
951             Fatal_Error;
952          end if;
953       end loop;
954
955       if Ignore ('R') then
956          Skip_Line;
957
958       --  Process restrictions line
959
960       else
961          Scan_Restrictions : declare
962             Save_R : constant Restrictions_Info := Cumulative_Restrictions;
963             --  Save cumulative restrictions in case we have a fatal error
964
965             Bad_R_Line : exception;
966             --  Signal bad restrictions line
967
968          begin
969             Checkc (' ');
970             Skip_Space;
971
972             --  Acquire information for boolean restrictions
973
974             for R in All_Boolean_Restrictions loop
975                C := Getc;
976
977                case C is
978                   when 'v' =>
979                      ALIs.Table (Id).Restrictions.Violated (R) := True;
980                      Cumulative_Restrictions.Violated (R) := True;
981
982                   when 'r' =>
983                      ALIs.Table (Id).Restrictions.Set (R) := True;
984                      Cumulative_Restrictions.Set (R) := True;
985
986                   when 'n' =>
987                      null;
988
989                   when others =>
990                      Fatal_Error;
991                end case;
992             end loop;
993
994             --  Acquire information for parameter restrictions
995
996             for RP in All_Parameter_Restrictions loop
997
998                --  Acquire restrictions pragma information
999
1000                case Getc is
1001                   when 'n' =>
1002                      null;
1003
1004                   when 'r' =>
1005                      ALIs.Table (Id).Restrictions.Set (RP) := True;
1006
1007                      declare
1008                         N : constant Integer := Integer (Get_Nat);
1009                      begin
1010                         ALIs.Table (Id).Restrictions.Value (RP) := N;
1011
1012                         if Cumulative_Restrictions.Set (RP) then
1013                            Cumulative_Restrictions.Value (RP) :=
1014                              Integer'Min
1015                                (Cumulative_Restrictions.Value (RP), N);
1016                         else
1017                            Cumulative_Restrictions.Set (RP) := True;
1018                            Cumulative_Restrictions.Value (RP) := N;
1019                         end if;
1020                      end;
1021
1022                   when others =>
1023                      Fatal_Error;
1024                end case;
1025
1026                --  Acquire restrictions violations information
1027
1028                case Getc is
1029                   when 'n' =>
1030                      null;
1031
1032                   when 'v' =>
1033                      ALIs.Table (Id).Restrictions.Violated (RP) := True;
1034                      Cumulative_Restrictions.Violated (RP) := True;
1035
1036                      declare
1037                         N : constant Integer := Integer (Get_Nat);
1038                         pragma Unsuppress (Overflow_Check);
1039
1040                      begin
1041                         ALIs.Table (Id).Restrictions.Count (RP) := N;
1042
1043                         if RP in Checked_Max_Parameter_Restrictions then
1044                            Cumulative_Restrictions.Count (RP) :=
1045                              Integer'Max
1046                                (Cumulative_Restrictions.Count (RP), N);
1047                         else
1048                            Cumulative_Restrictions.Count (RP) :=
1049                              Cumulative_Restrictions.Count (RP) + N;
1050                         end if;
1051
1052                      exception
1053                         when Constraint_Error =>
1054
1055                            --  A constraint error comes from the addition in
1056                            --  the else branch. We reset to the maximum and
1057                            --  indicate that the real value is now unknown.
1058
1059                            Cumulative_Restrictions.Value (RP) := Integer'Last;
1060                            Cumulative_Restrictions.Unknown (RP) := True;
1061                      end;
1062
1063                      if Nextc = '+' then
1064                         Skipc;
1065                         ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1066                         Cumulative_Restrictions.Unknown (RP) := True;
1067                      end if;
1068
1069                   when others =>
1070                      Fatal_Error;
1071                end case;
1072             end loop;
1073
1074             Skip_Eol;
1075
1076          --  Here if error during scanning of restrictions line
1077
1078          exception
1079             when Bad_R_Line =>
1080
1081                --  In Ignore_Errors mode, undo any changes to restrictions
1082                --  from this unit, and continue on.
1083
1084                if Ignore_Errors then
1085                   Cumulative_Restrictions := Save_R;
1086                   ALIs.Table (Id).Restrictions := Restrictions_Initial;
1087
1088                --  In normal mode, this is a fatal error
1089
1090                else
1091                   Fatal_Error;
1092                end if;
1093
1094          end Scan_Restrictions;
1095       end if;
1096
1097       --  Acquire 'I' lines if present
1098
1099       C := Getc;
1100       Check_Unknown_Line;
1101
1102       while C = 'I' loop
1103          if Ignore ('I') then
1104             Skip_Line;
1105
1106          else
1107             declare
1108                Int_Num : Nat;
1109                I_State : Character;
1110                Line_No : Nat;
1111
1112             begin
1113                Int_Num := Get_Nat;
1114                Skip_Space;
1115                I_State := Getc;
1116                Line_No := Get_Nat;
1117
1118                Interrupt_States.Append (
1119                  (Interrupt_Id    => Int_Num,
1120                   Interrupt_State => I_State,
1121                   IS_Pragma_Line  => Line_No));
1122
1123                ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1124                Skip_Eol;
1125             end;
1126          end if;
1127
1128          C := Getc;
1129       end loop;
1130
1131       --  Loop to acquire unit entries
1132
1133       U_Loop : loop
1134          Check_Unknown_Line;
1135          exit U_Loop when C /= 'U';
1136
1137          --  Note: as per spec, we never ignore U lines
1138
1139          Checkc (' ');
1140          Skip_Space;
1141          Units.Increment_Last;
1142
1143          if ALIs.Table (Id).First_Unit = No_Unit_Id then
1144             ALIs.Table (Id).First_Unit := Units.Last;
1145          end if;
1146
1147          Units.Table (Units.Last).Uname           := Get_Name;
1148          Units.Table (Units.Last).Predefined      := Is_Predefined_Unit;
1149          Units.Table (Units.Last).Internal        := Is_Internal_Unit;
1150          Units.Table (Units.Last).My_ALI          := Id;
1151          Units.Table (Units.Last).Sfile           := Get_Name (Lower => True);
1152          Units.Table (Units.Last).Pure            := False;
1153          Units.Table (Units.Last).Preelab         := False;
1154          Units.Table (Units.Last).No_Elab         := False;
1155          Units.Table (Units.Last).Shared_Passive  := False;
1156          Units.Table (Units.Last).RCI             := False;
1157          Units.Table (Units.Last).Remote_Types    := False;
1158          Units.Table (Units.Last).Has_RACW        := False;
1159          Units.Table (Units.Last).Init_Scalars    := False;
1160          Units.Table (Units.Last).Is_Generic      := False;
1161          Units.Table (Units.Last).Icasing         := Mixed_Case;
1162          Units.Table (Units.Last).Kcasing         := All_Lower_Case;
1163          Units.Table (Units.Last).Dynamic_Elab    := False;
1164          Units.Table (Units.Last).Elaborate_Body  := False;
1165          Units.Table (Units.Last).Set_Elab_Entity := False;
1166          Units.Table (Units.Last).Version         := "00000000";
1167          Units.Table (Units.Last).First_With      := Withs.Last + 1;
1168          Units.Table (Units.Last).First_Arg       := First_Arg;
1169          Units.Table (Units.Last).Elab_Position   := 0;
1170          Units.Table (Units.Last).Interface       := ALIs.Table (Id).Interface;
1171
1172          if Debug_Flag_U then
1173             Write_Str (" ----> reading unit ");
1174             Write_Int (Int (Units.Last));
1175             Write_Str ("  ");
1176             Write_Unit_Name (Units.Table (Units.Last).Uname);
1177             Write_Str (" from file ");
1178             Write_Name (Units.Table (Units.Last).Sfile);
1179             Write_Eol;
1180          end if;
1181
1182          --  Check for duplicated unit in different files
1183
1184          declare
1185             Info : constant Int := Get_Name_Table_Info
1186                                      (Units.Table (Units.Last).Uname);
1187          begin
1188             if Info /= 0
1189               and then Units.Table (Units.Last).Sfile /=
1190                        Units.Table (Unit_Id (Info)).Sfile
1191             then
1192                --  If Err is set then ignore duplicate unit name. This is the
1193                --  case of a call from gnatmake, where the situation can arise
1194                --  from substitution of source files. In such situations, the
1195                --  processing in gnatmake will always result in any required
1196                --  recompilations in any case, and if we consider this to be
1197                --  an error we get strange cases (for example when a generic
1198                --  instantiation is replaced by a normal package) where we
1199                --  read the old ali file, decide to recompile, and then decide
1200                --  that the old and new ali files are incompatible.
1201
1202                if Err then
1203                   null;
1204
1205                --  If Err is not set, then this is a fatal error. This is
1206                --  the case of being called from the binder, where we must
1207                --  definitely diagnose this as an error.
1208
1209                else
1210                   Set_Standard_Error;
1211                   Write_Str ("error: duplicate unit name: ");
1212                   Write_Eol;
1213
1214                   Write_Str ("error: unit """);
1215                   Write_Unit_Name (Units.Table (Units.Last).Uname);
1216                   Write_Str (""" found in file """);
1217                   Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1218                   Write_Char ('"');
1219                   Write_Eol;
1220
1221                   Write_Str ("error: unit """);
1222                   Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1223                   Write_Str (""" found in file """);
1224                   Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1225                   Write_Char ('"');
1226                   Write_Eol;
1227
1228                   Exit_Program (E_Fatal);
1229                end if;
1230             end if;
1231          end;
1232
1233          Set_Name_Table_Info
1234            (Units.Table (Units.Last).Uname, Int (Units.Last));
1235
1236          --  Scan out possible version and other parameters
1237
1238          loop
1239             Skip_Space;
1240             exit when At_Eol;
1241             C := Getc;
1242
1243             --  Version field
1244
1245             if C in '0' .. '9' or else C in 'a' .. 'f' then
1246                Units.Table (Units.Last).Version (1) := C;
1247
1248                for J in 2 .. 8 loop
1249                   C := Getc;
1250                   Units.Table (Units.Last).Version (J) := C;
1251                end loop;
1252
1253             --  BN parameter (Body needed)
1254
1255             elsif C = 'B' then
1256                C := Getc;
1257
1258                if C = 'N' then
1259                   Check_At_End_Of_Field;
1260                   Units.Table (Units.Last).Body_Needed_For_SAL := True;
1261                else
1262                   Fatal_Error_Ignore;
1263                end if;
1264
1265
1266             --  DE parameter (Dynamic elaboration checks)
1267
1268             elsif C = 'D' then
1269                C := Getc;
1270
1271                if C = 'E' then
1272                   Check_At_End_Of_Field;
1273                   Units.Table (Units.Last).Dynamic_Elab := True;
1274                   Dynamic_Elaboration_Checks_Specified := True;
1275                else
1276                   Fatal_Error_Ignore;
1277                end if;
1278
1279             --  EB/EE parameters
1280
1281             elsif C = 'E' then
1282                C := Getc;
1283
1284                if C = 'B' then
1285                   Units.Table (Units.Last).Elaborate_Body := True;
1286                elsif C = 'E' then
1287                   Units.Table (Units.Last).Set_Elab_Entity := True;
1288                else
1289                   Fatal_Error_Ignore;
1290                end if;
1291
1292                Check_At_End_Of_Field;
1293
1294             --  GE parameter (generic)
1295
1296             elsif C = 'G' then
1297                C := Getc;
1298
1299                if C = 'E' then
1300                   Check_At_End_Of_Field;
1301                   Units.Table (Units.Last).Is_Generic := True;
1302                else
1303                   Fatal_Error_Ignore;
1304                end if;
1305
1306             --  IL/IS/IU parameters
1307
1308             elsif C = 'I' then
1309                C := Getc;
1310
1311                if C = 'L' then
1312                   Units.Table (Units.Last).Icasing := All_Lower_Case;
1313                elsif C = 'S' then
1314                   Units.Table (Units.Last).Init_Scalars := True;
1315                   Initialize_Scalars_Used := True;
1316                elsif C = 'U' then
1317                   Units.Table (Units.Last).Icasing := All_Upper_Case;
1318                else
1319                   Fatal_Error_Ignore;
1320                end if;
1321
1322                Check_At_End_Of_Field;
1323
1324             --  KM/KU parameters
1325
1326             elsif C = 'K' then
1327                C := Getc;
1328
1329                if C = 'M' then
1330                   Units.Table (Units.Last).Kcasing := Mixed_Case;
1331                elsif C = 'U' then
1332                   Units.Table (Units.Last).Kcasing := All_Upper_Case;
1333                else
1334                   Fatal_Error_Ignore;
1335                end if;
1336
1337                Check_At_End_Of_Field;
1338
1339             --  NE parameter
1340
1341             elsif C = 'N' then
1342                C := Getc;
1343
1344                if C = 'E' then
1345                   Units.Table (Units.Last).No_Elab := True;
1346                   Check_At_End_Of_Field;
1347                else
1348                   Fatal_Error_Ignore;
1349                end if;
1350
1351
1352             --  PR/PU/PK parameters
1353
1354             elsif C = 'P' then
1355                C := Getc;
1356
1357                if C = 'R' then
1358                   Units.Table (Units.Last).Preelab := True;
1359                elsif C = 'U' then
1360                   Units.Table (Units.Last).Pure := True;
1361                elsif C = 'K' then
1362                   Units.Table (Units.Last).Unit_Kind := 'p';
1363                else
1364                   Fatal_Error_Ignore;
1365                end if;
1366
1367                Check_At_End_Of_Field;
1368
1369             --  RC/RT parameters
1370
1371             elsif C = 'R' then
1372                C := Getc;
1373
1374                if C = 'C' then
1375                   Units.Table (Units.Last).RCI := True;
1376                elsif C = 'T' then
1377                   Units.Table (Units.Last).Remote_Types := True;
1378                elsif C = 'A' then
1379                   Units.Table (Units.Last).Has_RACW := True;
1380                else
1381                   Fatal_Error_Ignore;
1382                end if;
1383
1384                Check_At_End_Of_Field;
1385
1386             elsif C = 'S' then
1387                C := Getc;
1388
1389                if C = 'P' then
1390                   Units.Table (Units.Last).Shared_Passive := True;
1391                elsif C = 'U' then
1392                   Units.Table (Units.Last).Unit_Kind := 's';
1393                else
1394                   Fatal_Error_Ignore;
1395                end if;
1396
1397                Check_At_End_Of_Field;
1398
1399             else
1400                C := Getc;
1401                Fatal_Error_Ignore;
1402             end if;
1403          end loop;
1404
1405          Skip_Eol;
1406
1407          --  Check if static elaboration model used
1408
1409          if not Units.Table (Units.Last).Dynamic_Elab
1410            and then not Units.Table (Units.Last).Internal
1411          then
1412             Static_Elaboration_Model_Used := True;
1413          end if;
1414
1415          C := Getc;
1416
1417          --  Scan out With lines for this unit
1418
1419          With_Loop : loop
1420             Check_Unknown_Line;
1421             exit With_Loop when C /= 'W';
1422
1423             if Ignore ('W') then
1424                Skip_Line;
1425
1426             else
1427                Checkc (' ');
1428                Skip_Space;
1429                Withs.Increment_Last;
1430                Withs.Table (Withs.Last).Uname              := Get_Name;
1431                Withs.Table (Withs.Last).Elaborate          := False;
1432                Withs.Table (Withs.Last).Elaborate_All      := False;
1433                Withs.Table (Withs.Last).Elab_All_Desirable := False;
1434                Withs.Table (Withs.Last).Interface          := False;
1435
1436                --  Generic case with no object file available
1437
1438                if At_Eol then
1439                   Withs.Table (Withs.Last).Sfile := No_File;
1440                   Withs.Table (Withs.Last).Afile := No_File;
1441
1442                --  Normal case
1443
1444                else
1445                   Withs.Table (Withs.Last).Sfile := Get_Name (Lower => True);
1446                   Withs.Table (Withs.Last).Afile := Get_Name;
1447
1448                   --  Scan out possible E, EA, and NE parameters
1449
1450                   while not At_Eol loop
1451                      Skip_Space;
1452
1453                      if Nextc = 'E' then
1454                         P := P + 1;
1455
1456                         if At_End_Of_Field then
1457                            Withs.Table (Withs.Last).Elaborate := True;
1458
1459                         elsif Nextc = 'A' then
1460                            P := P + 1;
1461                            Check_At_End_Of_Field;
1462                            Withs.Table (Withs.Last).Elaborate_All := True;
1463
1464                         else
1465                            Checkc ('D');
1466                            Check_At_End_Of_Field;
1467
1468                            --  Store ED indication unless ignore required
1469
1470                            if not Ignore_ED then
1471                               Withs.Table (Withs.Last).Elab_All_Desirable :=
1472                                 True;
1473                            end if;
1474                         end if;
1475                      end if;
1476                   end loop;
1477                end if;
1478
1479                Skip_Eol;
1480             end if;
1481
1482             C := Getc;
1483          end loop With_Loop;
1484
1485          Units.Table (Units.Last).Last_With := Withs.Last;
1486          Units.Table (Units.Last).Last_Arg  := Args.Last;
1487
1488          --  If there are linker options lines present, scan them
1489
1490          Name_Len := 0;
1491
1492          Linker_Options_Loop : loop
1493             Check_Unknown_Line;
1494             exit Linker_Options_Loop when C /= 'L';
1495
1496             if Ignore ('L') then
1497                Skip_Line;
1498
1499             else
1500                Checkc (' ');
1501                Skip_Space;
1502                Checkc ('"');
1503
1504                loop
1505                   C := Getc;
1506
1507                   if C < Character'Val (16#20#)
1508                     or else C > Character'Val (16#7E#)
1509                   then
1510                      Fatal_Error_Ignore;
1511
1512                   elsif C = '{' then
1513                      C := Character'Val (0);
1514
1515                      declare
1516                         V : Natural;
1517
1518                      begin
1519                         V := 0;
1520                         for J in 1 .. 2 loop
1521                            C := Getc;
1522
1523                            if C in '0' .. '9' then
1524                               V := V * 16 +
1525                                      Character'Pos (C) -
1526                                        Character'Pos ('0');
1527
1528                            elsif C in 'A' .. 'F' then
1529                               V := V * 16 +
1530                                      Character'Pos (C) -
1531                                        Character'Pos ('A') +
1532                                          10;
1533
1534                            else
1535                               Fatal_Error_Ignore;
1536                            end if;
1537                         end loop;
1538
1539                         Checkc ('}');
1540                         Add_Char_To_Name_Buffer (Character'Val (V));
1541                      end;
1542
1543                   else
1544                      if C = '"' then
1545                         exit when Nextc /= '"';
1546                         C := Getc;
1547                      end if;
1548
1549                      Add_Char_To_Name_Buffer (C);
1550                   end if;
1551                end loop;
1552
1553                Add_Char_To_Name_Buffer (nul);
1554                Skip_Eol;
1555             end if;
1556
1557             C := Getc;
1558          end loop Linker_Options_Loop;
1559
1560          --  Store the linker options entry if one was found
1561
1562          if Name_Len /= 0 then
1563             Linker_Options.Increment_Last;
1564
1565             Linker_Options.Table (Linker_Options.Last).Name :=
1566               Name_Enter;
1567
1568             Linker_Options.Table (Linker_Options.Last).Unit :=
1569               Units.Last;
1570
1571             Linker_Options.Table (Linker_Options.Last).Internal_File :=
1572               Is_Internal_File_Name (F);
1573
1574             Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1575               Linker_Options.Last;
1576          end if;
1577       end loop U_Loop;
1578
1579       --  End loop through units for one ALI file
1580
1581       ALIs.Table (Id).Last_Unit := Units.Last;
1582       ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1583
1584       --  Set types of the units (there can be at most 2 of them)
1585
1586       if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1587          Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1588          Units.Table (ALIs.Table (Id).Last_Unit).Utype  := Is_Spec;
1589
1590       else
1591          --  Deal with body only and spec only cases, note that the reason we
1592          --  do our own checking of the name (rather than using Is_Body_Name)
1593          --  is that Uname drags in far too much compiler junk!
1594
1595          Get_Name_String (Units.Table (Units.Last).Uname);
1596
1597          if Name_Buffer (Name_Len) = 'b' then
1598             Units.Table (Units.Last).Utype := Is_Body_Only;
1599          else
1600             Units.Table (Units.Last).Utype := Is_Spec_Only;
1601          end if;
1602       end if;
1603
1604       --  Scan out external version references and put in hash table
1605
1606       E_Loop : loop
1607          Check_Unknown_Line;
1608          exit E_Loop when C /= 'E';
1609
1610          if Ignore ('E') then
1611             Skip_Line;
1612
1613          else
1614             Checkc (' ');
1615             Skip_Space;
1616
1617             Name_Len := 0;
1618             Name_Len := 0;
1619             loop
1620                C := Getc;
1621
1622                if C < ' ' then
1623                   Fatal_Error;
1624                end if;
1625
1626                exit when At_End_Of_Field;
1627                Add_Char_To_Name_Buffer (C);
1628             end loop;
1629
1630             Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1631             Skip_Eol;
1632          end if;
1633
1634          C := Getc;
1635       end loop E_Loop;
1636
1637       --  Scan out source dependency lines for this ALI file
1638
1639       ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
1640
1641       D_Loop : loop
1642          Check_Unknown_Line;
1643          exit D_Loop when C /= 'D';
1644
1645          if Ignore ('D') then
1646             Skip_Line;
1647
1648          else
1649             Checkc (' ');
1650             Skip_Space;
1651             Sdep.Increment_Last;
1652             Sdep.Table (Sdep.Last).Sfile := Get_Name (Lower => True);
1653             Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
1654             Sdep.Table (Sdep.Last).Dummy_Entry :=
1655               (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
1656
1657             --  Acquire checksum value
1658
1659             Skip_Space;
1660
1661             declare
1662                Ctr : Natural;
1663                Chk : Word;
1664
1665             begin
1666                Ctr := 0;
1667                Chk := 0;
1668
1669                loop
1670                   exit when At_Eol or else Ctr = 8;
1671
1672                   if Nextc in '0' .. '9' then
1673                      Chk := Chk * 16 +
1674                               Character'Pos (Nextc) - Character'Pos ('0');
1675
1676                   elsif Nextc in 'a' .. 'f' then
1677                      Chk := Chk * 16 +
1678                               Character'Pos (Nextc) - Character'Pos ('a') + 10;
1679
1680                   else
1681                      exit;
1682                   end if;
1683
1684                   Ctr := Ctr + 1;
1685                   P := P + 1;
1686                end loop;
1687
1688                if Ctr = 8 and then At_End_Of_Field then
1689                   Sdep.Table (Sdep.Last).Checksum := Chk;
1690                else
1691                   Fatal_Error;
1692                end if;
1693             end;
1694
1695             --  Acquire subunit and reference file name entries
1696
1697             Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
1698             Sdep.Table (Sdep.Last).Rfile        :=
1699               Sdep.Table (Sdep.Last).Sfile;
1700             Sdep.Table (Sdep.Last).Start_Line   := 1;
1701
1702             if not At_Eol then
1703                Skip_Space;
1704
1705                --  Here for subunit name
1706
1707                if Nextc not in '0' .. '9' then
1708                   Name_Len := 0;
1709
1710                   while not At_End_Of_Field loop
1711                      Name_Len := Name_Len + 1;
1712                      Name_Buffer (Name_Len) := Getc;
1713                   end loop;
1714
1715                   Sdep.Table (Sdep.Last).Subunit_Name := Name_Enter;
1716                   Skip_Space;
1717                end if;
1718
1719                --  Here for reference file name entry
1720
1721                if Nextc in '0' .. '9' then
1722                   Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
1723                   Checkc (':');
1724
1725                   Name_Len := 0;
1726
1727                   while not At_End_Of_Field loop
1728                      Name_Len := Name_Len + 1;
1729                      Name_Buffer (Name_Len) := Getc;
1730                   end loop;
1731
1732                   Sdep.Table (Sdep.Last).Rfile := Name_Enter;
1733                end if;
1734             end if;
1735
1736             Skip_Eol;
1737          end if;
1738
1739          C := Getc;
1740       end loop D_Loop;
1741
1742       ALIs.Table (Id).Last_Sdep := Sdep.Last;
1743
1744       --  We must at this stage be at an Xref line or the end of file
1745
1746       if C = EOF then
1747          return Id;
1748       end if;
1749
1750       Check_Unknown_Line;
1751
1752       if C /= 'X' then
1753          Fatal_Error;
1754       end if;
1755
1756       --  If we are ignoring Xref sections we are done (we ignore all
1757       --  remaining lines since only xref related lines follow X).
1758
1759       if Ignore ('X') and then not Debug_Flag_X then
1760          return Id;
1761       end if;
1762
1763       --  Loop through Xref sections
1764
1765       X_Loop : loop
1766          Check_Unknown_Line;
1767          exit X_Loop when C /= 'X';
1768
1769          --  Make new entry in section table
1770
1771          Xref_Section.Increment_Last;
1772
1773          Read_Refs_For_One_File : declare
1774             XS : Xref_Section_Record renames
1775                    Xref_Section.Table (Xref_Section.Last);
1776
1777             Current_File_Num : Sdep_Id;
1778             --  Keeps track of the current file number (changed by nn|)
1779
1780          begin
1781             XS.File_Num     := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
1782             XS.File_Name    := Get_Name;
1783             XS.First_Entity := Xref_Entity.Last + 1;
1784
1785             Current_File_Num := XS.File_Num;
1786
1787             Skip_Space;
1788
1789             Skip_Eol;
1790             C := Nextc;
1791
1792             --  Loop through Xref entities
1793
1794             while C /= 'X' and then C /= EOF loop
1795                Xref_Entity.Increment_Last;
1796
1797                Read_Refs_For_One_Entity : declare
1798                   XE : Xref_Entity_Record renames
1799                          Xref_Entity.Table (Xref_Entity.Last);
1800                   N  : Nat;
1801
1802                   procedure Read_Instantiation_Reference;
1803                   --  Acquire instantiation reference. Caller has checked
1804                   --  that current character is '[' and on return the cursor
1805                   --  is skipped past the corresponding closing ']'.
1806
1807                   ----------------------------------
1808                   -- Read_Instantiation_Reference --
1809                   ----------------------------------
1810
1811                   procedure Read_Instantiation_Reference is
1812                   begin
1813                      Xref.Increment_Last;
1814
1815                      declare
1816                         XR : Xref_Record renames Xref.Table (Xref.Last);
1817
1818                      begin
1819                         P := P + 1; -- skip [
1820                         N := Get_Nat;
1821
1822                         if Nextc = '|' then
1823                            XR.File_Num :=
1824                              Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
1825                            Current_File_Num := XR.File_Num;
1826                            P := P + 1;
1827                            N := Get_Nat;
1828
1829                         else
1830                            XR.File_Num := Current_File_Num;
1831                         end if;
1832
1833                         XR.Line  := N;
1834                         XR.Rtype := ' ';
1835                         XR.Col   := 0;
1836
1837                         --  Recursive call for next reference
1838
1839                         if Nextc = '[' then
1840                            pragma Warnings (Off); -- kill recursion warning
1841                            Read_Instantiation_Reference;
1842                            pragma Warnings (On);
1843                         end if;
1844
1845                         --  Skip closing bracket after recursive call
1846
1847                         P := P + 1;
1848                      end;
1849                   end Read_Instantiation_Reference;
1850
1851                --  Start of processing for Read_Refs_For_One_Entity
1852
1853                begin
1854                   XE.Line   := Get_Nat;
1855                   XE.Etype  := Getc;
1856                   XE.Col    := Get_Nat;
1857                   XE.Lib    := (Getc = '*');
1858                   XE.Entity := Get_Name;
1859
1860                   Current_File_Num := XS.File_Num;
1861
1862                   --  Renaming reference is present
1863
1864                   if Nextc = '=' then
1865                      P := P + 1;
1866                      XE.Rref_Line := Get_Nat;
1867
1868                      if Getc /= ':' then
1869                         Fatal_Error;
1870                      end if;
1871
1872                      XE.Rref_Col := Get_Nat;
1873
1874                   --  No renaming reference present
1875
1876                   else
1877                      XE.Rref_Line := 0;
1878                      XE.Rref_Col  := 0;
1879                   end if;
1880
1881                   Skip_Space;
1882
1883                   --  See if type reference present
1884
1885                   case Nextc is
1886                      when '<'    => XE.Tref := Tref_Derived;
1887                      when '('    => XE.Tref := Tref_Access;
1888                      when '{'    => XE.Tref := Tref_Type;
1889                      when others => XE.Tref := Tref_None;
1890                   end case;
1891
1892                   --  Case of typeref field present
1893
1894                   if XE.Tref /= Tref_None then
1895                      P := P + 1; -- skip opening bracket
1896
1897                      if Nextc in 'a' .. 'z' then
1898                         XE.Tref_File_Num        := No_Sdep_Id;
1899                         XE.Tref_Line            := 0;
1900                         XE.Tref_Type            := ' ';
1901                         XE.Tref_Col             := 0;
1902                         XE.Tref_Standard_Entity :=
1903                           Get_Name (Ignore_Spaces => True);
1904
1905                      else
1906                         N := Get_Nat;
1907
1908                         if Nextc = '|' then
1909                            XE.Tref_File_Num :=
1910                              Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
1911                            P := P + 1;
1912                            N := Get_Nat;
1913
1914                         else
1915                            XE.Tref_File_Num := Current_File_Num;
1916                         end if;
1917
1918                         XE.Tref_Line            := N;
1919                         XE.Tref_Type            := Getc;
1920                         XE.Tref_Col             := Get_Nat;
1921                         XE.Tref_Standard_Entity := No_Name;
1922                      end if;
1923
1924                      --  ??? Temporary workaround for nested generics case:
1925                      --     4i4 Directories{1|4I9[4|6[3|3]]}
1926                      --  See C918-002
1927
1928                      declare
1929                         Nested_Brackets : Natural := 0;
1930
1931                      begin
1932                         loop
1933                            case Nextc is
1934                               when '['   =>
1935                                  Nested_Brackets := Nested_Brackets + 1;
1936                               when ']' =>
1937                                  Nested_Brackets := Nested_Brackets - 1;
1938                               when others =>
1939                                  if Nested_Brackets = 0 then
1940                                     exit;
1941                                  end if;
1942                            end case;
1943
1944                            Skipc;
1945                         end loop;
1946                      end;
1947
1948                      P := P + 1; -- skip closing bracket
1949                      Skip_Space;
1950
1951                   --  No typeref entry present
1952
1953                   else
1954                      XE.Tref_File_Num        := No_Sdep_Id;
1955                      XE.Tref_Line            := 0;
1956                      XE.Tref_Type            := ' ';
1957                      XE.Tref_Col             := 0;
1958                      XE.Tref_Standard_Entity := No_Name;
1959                   end if;
1960
1961                   XE.First_Xref := Xref.Last + 1;
1962
1963                   --  Loop through cross-references for this entity
1964
1965                   loop
1966                      Skip_Space;
1967
1968                      if At_Eol then
1969                         Skip_Eol;
1970                         exit when Nextc /= '.';
1971                         P := P + 1;
1972                      end if;
1973
1974                      Xref.Increment_Last;
1975
1976                      declare
1977                         XR : Xref_Record renames Xref.Table (Xref.Last);
1978
1979                      begin
1980                         N := Get_Nat;
1981
1982                         if Nextc = '|' then
1983                            XR.File_Num :=
1984                              Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
1985                            Current_File_Num := XR.File_Num;
1986                            P := P + 1;
1987                            N := Get_Nat;
1988                         else
1989                            XR.File_Num := Current_File_Num;
1990                         end if;
1991
1992                         XR.Line  := N;
1993                         XR.Rtype := Getc;
1994
1995                         --  Imported entities reference as in:
1996                         --    494b<c,__gnat_copy_attribs>25
1997                         --  ??? Simply skipped for now
1998
1999                         if Nextc = '<' then
2000                            while Getc /= '>' loop
2001                               null;
2002                            end loop;
2003                         end if;
2004
2005                         XR.Col   := Get_Nat;
2006
2007                         if Nextc = '[' then
2008                            Read_Instantiation_Reference;
2009                         end if;
2010                      end;
2011                   end loop;
2012
2013                   --  Record last cross-reference
2014
2015                   XE.Last_Xref := Xref.Last;
2016                   C := Nextc;
2017                end Read_Refs_For_One_Entity;
2018             end loop;
2019
2020             --  Record last entity
2021
2022             XS.Last_Entity := Xref_Entity.Last;
2023
2024          end Read_Refs_For_One_File;
2025
2026          C := Getc;
2027       end loop X_Loop;
2028
2029       --  Here after dealing with xref sections
2030
2031       if C /= EOF and then C /= 'X' then
2032          Fatal_Error;
2033       end if;
2034
2035       return Id;
2036
2037    exception
2038       when Bad_ALI_Format =>
2039          return No_ALI_Id;
2040
2041    end Scan_ALI;
2042
2043    ---------
2044    -- SEq --
2045    ---------
2046
2047    function SEq (F1, F2 : String_Ptr) return Boolean is
2048    begin
2049       return F1.all = F2.all;
2050    end SEq;
2051
2052    -----------
2053    -- SHash --
2054    -----------
2055
2056    function SHash (S : String_Ptr) return Vindex is
2057       H : Word;
2058
2059    begin
2060       H := 0;
2061       for J in S.all'Range loop
2062          H := H * 2 + Character'Pos (S (J));
2063       end loop;
2064
2065       return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));
2066    end SHash;
2067
2068 end ALI;