PR c++/54038
[official-gcc.git] / gcc / ada / ali.adb
blob86ad184de2bbc8598296afa7822725a713f8ed98
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- A L I --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2012, 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 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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Butil; use Butil;
27 with Debug; use Debug;
28 with Fname; use Fname;
29 with Opt; use Opt;
30 with Osint; use Osint;
31 with Output; use Output;
33 package body ALI is
35 use ASCII;
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
49 'U' => True, -- unit
50 'W' => True, -- with
51 'L' => True, -- linker option
52 'N' => True, -- notes
53 'E' => True, -- external
54 'D' => True, -- dependency
55 'X' => True, -- xref
56 'S' => True, -- specific dispatching
57 'Y' => True, -- limited_with
58 'Z' => True, -- implicit with from instantiation
59 'C' => True, -- SCO information
60 'F' => True, -- Alfa information
61 others => False);
63 --------------------
64 -- Initialize_ALI --
65 --------------------
67 procedure Initialize_ALI is
68 begin
69 -- When (re)initializing ALI data structures the ALI user expects to
70 -- get a fresh set of data structures. Thus we first need to erase the
71 -- marks put in the name table by the previous set of ALI routine calls.
72 -- These two loops are empty and harmless the first time in.
74 for J in ALIs.First .. ALIs.Last loop
75 Set_Name_Table_Info (ALIs.Table (J).Afile, 0);
76 end loop;
78 for J in Units.First .. Units.Last loop
79 Set_Name_Table_Info (Units.Table (J).Uname, 0);
80 end loop;
82 -- Free argument table strings
84 for J in Args.First .. Args.Last loop
85 Free (Args.Table (J));
86 end loop;
88 -- Initialize all tables
90 ALIs.Init;
91 No_Deps.Init;
92 Units.Init;
93 Withs.Init;
94 Sdep.Init;
95 Linker_Options.Init;
96 Notes.Init;
97 Xref_Section.Init;
98 Xref_Entity.Init;
99 Xref.Init;
100 Version_Ref.Reset;
102 -- Add dummy zero'th item in Linker_Options and Notes for sort calls
104 Linker_Options.Increment_Last;
105 Notes.Increment_Last;
107 -- Initialize global variables recording cumulative options in all
108 -- ALI files that are read for a given processing run in gnatbind.
110 Dynamic_Elaboration_Checks_Specified := False;
111 Float_Format_Specified := ' ';
112 Locking_Policy_Specified := ' ';
113 No_Normalize_Scalars_Specified := False;
114 No_Object_Specified := False;
115 Normalize_Scalars_Specified := False;
116 Queuing_Policy_Specified := ' ';
117 Static_Elaboration_Model_Used := False;
118 Task_Dispatching_Policy_Specified := ' ';
119 Unreserve_All_Interrupts_Specified := False;
120 Zero_Cost_Exceptions_Specified := False;
121 end Initialize_ALI;
123 --------------
124 -- Scan_ALI --
125 --------------
127 function Scan_ALI
128 (F : File_Name_Type;
129 T : Text_Buffer_Ptr;
130 Ignore_ED : Boolean;
131 Err : Boolean;
132 Read_Xref : Boolean := False;
133 Read_Lines : String := "";
134 Ignore_Lines : String := "X";
135 Ignore_Errors : Boolean := False;
136 Directly_Scanned : Boolean := False) return ALI_Id
138 P : Text_Ptr := T'First;
139 Line : Logical_Line_Number := 1;
140 Id : ALI_Id;
141 C : Character;
142 NS_Found : Boolean;
143 First_Arg : Arg_Id;
145 Ignore : array (Character range 'A' .. 'Z') of Boolean;
146 -- Ignore (X) is set to True if lines starting with X are to
147 -- be ignored by Scan_ALI and skipped, and False if the lines
148 -- are to be read and processed.
150 Bad_ALI_Format : exception;
151 -- Exception raised by Fatal_Error if Err is True
153 function At_Eol return Boolean;
154 -- Test if at end of line
156 function At_End_Of_Field return Boolean;
157 -- Test if at end of line, or if at blank or horizontal tab
159 procedure Check_At_End_Of_Field;
160 -- Check if we are at end of field, fatal error if not
162 procedure Checkc (C : Character);
163 -- Check next character is C. If so bump past it, if not fatal error
165 procedure Check_Unknown_Line;
166 -- If Ignore_Errors mode, then checks C to make sure that it is not
167 -- an unknown ALI line type characters, and if so, skips lines
168 -- until the first character of the line is one of these characters,
169 -- at which point it does a Getc to put that character in C. The
170 -- call has no effect if C is already an appropriate character.
171 -- If not in Ignore_Errors mode, a fatal error is signalled if the
172 -- line is unknown. Note that if C is an EOL on entry, the line is
173 -- skipped (it is assumed that blank lines are never significant).
174 -- If C is EOF on entry, the call has no effect (it is assumed that
175 -- the caller will properly handle this case).
177 procedure Fatal_Error;
178 -- Generate fatal error message for badly formatted ALI file if
179 -- Err is false, or raise Bad_ALI_Format if Err is True.
181 procedure Fatal_Error_Ignore;
182 pragma Inline (Fatal_Error_Ignore);
183 -- In Ignore_Errors mode, has no effect, otherwise same as Fatal_Error
185 function Getc return Character;
186 -- Get next character, bumping P past the character obtained
188 function Get_File_Name (Lower : Boolean := False) return File_Name_Type;
189 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
190 -- with length in Name_Len, as well as returning a File_Name_Type value.
191 -- If lower is false, the case is unchanged, if Lower is True then the
192 -- result is forced to all lower case for systems where file names are
193 -- not case sensitive. This ensures that gnatbind works correctly
194 -- regardless of the case of the file name on all systems. The scan
195 -- is terminated by a end of line, space or horizontal tab. Any other
196 -- special characters are included in the returned name.
198 function Get_Name
199 (Ignore_Spaces : Boolean := False;
200 Ignore_Special : Boolean := False) return Name_Id;
201 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
202 -- length in Name_Len, as well as being returned in Name_Id form).
203 -- If Lower is set to True then the Name_Buffer will be converted to
204 -- all lower case, for systems where file names are not case sensitive.
205 -- This ensures that gnatbind works correctly regardless of the case
206 -- of the file name on all systems. The termination condition depends
207 -- on the settings of Ignore_Spaces and Ignore_Special:
209 -- If Ignore_Spaces is False (normal case), then scan is terminated
210 -- by the normal end of field condition (EOL, space, horizontal tab)
212 -- If Ignore_Special is False (normal case), the scan is terminated by
213 -- a typeref bracket or an equal sign except for the special case of
214 -- an operator name starting with a double quote which is terminated
215 -- by another double quote.
217 -- It is an error to set both Ignore_Spaces and Ignore_Special to True.
218 -- This function handles wide characters properly.
220 function Get_Nat return Nat;
221 -- Skip blanks, then scan out an unsigned integer value in Nat range
222 -- raises ALI_Reading_Error if the encoutered type is not natural.
224 function Get_Stamp return Time_Stamp_Type;
225 -- Skip blanks, then scan out a time stamp
227 function Get_Unit_Name return Unit_Name_Type;
228 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
229 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
230 -- The case is unchanged and terminated by a normal end of field.
232 function Nextc return Character;
233 -- Return current character without modifying pointer P
235 procedure Get_Typeref
236 (Current_File_Num : Sdep_Id;
237 Ref : out Tref_Kind;
238 File_Num : out Sdep_Id;
239 Line : out Nat;
240 Ref_Type : out Character;
241 Col : out Nat;
242 Standard_Entity : out Name_Id);
243 -- Parse the definition of a typeref (<...>, {...} or (...))
245 procedure Skip_Eol;
246 -- Skip past spaces, then skip past end of line (fatal error if not
247 -- at end of line). Also skips past any following blank lines.
249 procedure Skip_Line;
250 -- Skip rest of current line and any following blank lines
252 procedure Skip_Space;
253 -- Skip past white space (blanks or horizontal tab)
255 procedure Skipc;
256 -- Skip past next character, does not affect value in C. This call
257 -- is like calling Getc and ignoring the returned result.
259 ---------------------
260 -- At_End_Of_Field --
261 ---------------------
263 function At_End_Of_Field return Boolean is
264 begin
265 return Nextc <= ' ';
266 end At_End_Of_Field;
268 ------------
269 -- At_Eol --
270 ------------
272 function At_Eol return Boolean is
273 begin
274 return Nextc = EOF or else Nextc = CR or else Nextc = LF;
275 end At_Eol;
277 ---------------------------
278 -- Check_At_End_Of_Field --
279 ---------------------------
281 procedure Check_At_End_Of_Field is
282 begin
283 if not At_End_Of_Field then
284 if Ignore_Errors then
285 while Nextc > ' ' loop
286 P := P + 1;
287 end loop;
288 else
289 Fatal_Error;
290 end if;
291 end if;
292 end Check_At_End_Of_Field;
294 ------------------------
295 -- Check_Unknown_Line --
296 ------------------------
298 procedure Check_Unknown_Line is
299 begin
300 while C not in 'A' .. 'Z'
301 or else not Known_ALI_Lines (C)
302 loop
303 if C = CR or else C = LF then
304 Skip_Line;
305 C := Nextc;
307 elsif C = EOF then
308 return;
310 elsif Ignore_Errors then
311 Skip_Line;
312 C := Getc;
314 else
315 Fatal_Error;
316 end if;
317 end loop;
318 end Check_Unknown_Line;
320 ------------
321 -- Checkc --
322 ------------
324 procedure Checkc (C : Character) is
325 begin
326 if Nextc = C then
327 P := P + 1;
328 elsif Ignore_Errors then
329 P := P + 1;
330 else
331 Fatal_Error;
332 end if;
333 end Checkc;
335 -----------------
336 -- Fatal_Error --
337 -----------------
339 procedure Fatal_Error is
340 Ptr1 : Text_Ptr;
341 Ptr2 : Text_Ptr;
342 Col : Int;
344 procedure Wchar (C : Character);
345 -- Write a single character, replacing horizontal tab by spaces
347 procedure Wchar (C : Character) is
348 begin
349 if C = HT then
350 loop
351 Wchar (' ');
352 exit when Col mod 8 = 0;
353 end loop;
355 else
356 Write_Char (C);
357 Col := Col + 1;
358 end if;
359 end Wchar;
361 -- Start of processing for Fatal_Error
363 begin
364 if Err then
365 raise Bad_ALI_Format;
366 end if;
368 Set_Standard_Error;
369 Write_Str ("fatal error: file ");
370 Write_Name (F);
371 Write_Str (" is incorrectly formatted");
372 Write_Eol;
374 Write_Str ("make sure you are using consistent versions " &
376 -- Split the following line so that it can easily be transformed for
377 -- e.g. JVM/.NET back-ends where the compiler has a different name.
379 "of gcc/gnatbind");
381 Write_Eol;
383 -- Find start of line
385 Ptr1 := P;
386 while Ptr1 > T'First
387 and then T (Ptr1 - 1) /= CR
388 and then T (Ptr1 - 1) /= LF
389 loop
390 Ptr1 := Ptr1 - 1;
391 end loop;
393 Write_Int (Int (Line));
394 Write_Str (". ");
396 if Line < 100 then
397 Write_Char (' ');
398 end if;
400 if Line < 10 then
401 Write_Char (' ');
402 end if;
404 Col := 0;
405 Ptr2 := Ptr1;
407 while Ptr2 < T'Last
408 and then T (Ptr2) /= CR
409 and then T (Ptr2) /= LF
410 loop
411 Wchar (T (Ptr2));
412 Ptr2 := Ptr2 + 1;
413 end loop;
415 Write_Eol;
417 Write_Str (" ");
418 Col := 0;
420 while Ptr1 < P loop
421 if T (Ptr1) = HT then
422 Wchar (HT);
423 else
424 Wchar (' ');
425 end if;
427 Ptr1 := Ptr1 + 1;
428 end loop;
430 Wchar ('|');
431 Write_Eol;
433 Exit_Program (E_Fatal);
434 end Fatal_Error;
436 ------------------------
437 -- Fatal_Error_Ignore --
438 ------------------------
440 procedure Fatal_Error_Ignore is
441 begin
442 if not Ignore_Errors then
443 Fatal_Error;
444 end if;
445 end Fatal_Error_Ignore;
447 -------------------
448 -- Get_File_Name --
449 -------------------
451 function Get_File_Name
452 (Lower : Boolean := False) return File_Name_Type
454 F : Name_Id;
456 begin
457 F := Get_Name (Ignore_Special => True);
459 -- Convert file name to all lower case if file names are not case
460 -- sensitive. This ensures that we handle names in the canonical
461 -- lower case format, regardless of the actual case.
463 if Lower and not File_Names_Case_Sensitive then
464 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
465 return Name_Find;
466 else
467 return File_Name_Type (F);
468 end if;
469 end Get_File_Name;
471 --------------
472 -- Get_Name --
473 --------------
475 function Get_Name
476 (Ignore_Spaces : Boolean := False;
477 Ignore_Special : Boolean := False) return Name_Id
479 begin
480 Name_Len := 0;
481 Skip_Space;
483 if At_Eol then
484 if Ignore_Errors then
485 return Error_Name;
486 else
487 Fatal_Error;
488 end if;
489 end if;
491 loop
492 Add_Char_To_Name_Buffer (Getc);
494 exit when At_End_Of_Field and then not Ignore_Spaces;
496 if not Ignore_Special then
497 if Name_Buffer (1) = '"' then
498 exit when Name_Len > 1 and then Name_Buffer (Name_Len) = '"';
500 else
501 -- Terminate on parens or angle brackets or equal sign
503 exit when Nextc = '(' or else Nextc = ')'
504 or else Nextc = '{' or else Nextc = '}'
505 or else Nextc = '<' or else Nextc = '>'
506 or else Nextc = '=';
508 -- Terminate on comma
510 exit when Nextc = ',';
512 -- Terminate if left bracket not part of wide char sequence
513 -- Note that we only recognize brackets notation so far ???
515 exit when Nextc = '[' and then T (P + 1) /= '"';
517 -- Terminate if right bracket not part of wide char sequence
519 exit when Nextc = ']' and then T (P - 1) /= '"';
520 end if;
521 end if;
522 end loop;
524 return Name_Find;
525 end Get_Name;
527 -------------------
528 -- Get_Unit_Name --
529 -------------------
531 function Get_Unit_Name return Unit_Name_Type is
532 begin
533 return Unit_Name_Type (Get_Name);
534 end Get_Unit_Name;
536 -------------
537 -- Get_Nat --
538 -------------
540 function Get_Nat return Nat is
541 V : Nat;
543 begin
544 Skip_Space;
546 -- Check if we are on a number. In the case of bad ALI files, this
547 -- may not be true.
549 if not (Nextc in '0' .. '9') then
550 Fatal_Error;
551 end if;
553 V := 0;
554 loop
555 V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
557 exit when At_End_Of_Field;
558 exit when Nextc < '0' or else Nextc > '9';
559 end loop;
561 return V;
562 end Get_Nat;
564 ---------------
565 -- Get_Stamp --
566 ---------------
568 function Get_Stamp return Time_Stamp_Type is
569 T : Time_Stamp_Type;
570 Start : Integer;
572 begin
573 Skip_Space;
575 if At_Eol then
576 if Ignore_Errors then
577 return Dummy_Time_Stamp;
578 else
579 Fatal_Error;
580 end if;
581 end if;
583 -- Following reads old style time stamp missing first two digits
585 if Nextc in '7' .. '9' then
586 T (1) := '1';
587 T (2) := '9';
588 Start := 3;
590 -- Normal case of full year in time stamp
592 else
593 Start := 1;
594 end if;
596 for J in Start .. T'Last loop
597 T (J) := Getc;
598 end loop;
600 return T;
601 end Get_Stamp;
603 -----------------
604 -- Get_Typeref --
605 -----------------
607 procedure Get_Typeref
608 (Current_File_Num : Sdep_Id;
609 Ref : out Tref_Kind;
610 File_Num : out Sdep_Id;
611 Line : out Nat;
612 Ref_Type : out Character;
613 Col : out Nat;
614 Standard_Entity : out Name_Id)
616 N : Nat;
617 begin
618 case Nextc is
619 when '<' => Ref := Tref_Derived;
620 when '(' => Ref := Tref_Access;
621 when '{' => Ref := Tref_Type;
622 when others => Ref := Tref_None;
623 end case;
625 -- Case of typeref field present
627 if Ref /= Tref_None then
628 P := P + 1; -- skip opening bracket
630 if Nextc in 'a' .. 'z' then
631 File_Num := No_Sdep_Id;
632 Line := 0;
633 Ref_Type := ' ';
634 Col := 0;
635 Standard_Entity := Get_Name (Ignore_Spaces => True);
636 else
637 N := Get_Nat;
639 if Nextc = '|' then
640 File_Num := Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
641 P := P + 1;
642 N := Get_Nat;
643 else
644 File_Num := Current_File_Num;
645 end if;
647 Line := N;
648 Ref_Type := Getc;
649 Col := Get_Nat;
650 Standard_Entity := No_Name;
651 end if;
653 -- ??? Temporary workaround for nested generics case:
654 -- 4i4 Directories{1|4I9[4|6[3|3]]}
655 -- See C918-002
657 declare
658 Nested_Brackets : Natural := 0;
660 begin
661 loop
662 case Nextc is
663 when '[' =>
664 Nested_Brackets := Nested_Brackets + 1;
665 when ']' =>
666 Nested_Brackets := Nested_Brackets - 1;
667 when others =>
668 if Nested_Brackets = 0 then
669 exit;
670 end if;
671 end case;
673 Skipc;
674 end loop;
675 end;
677 P := P + 1; -- skip closing bracket
678 Skip_Space;
680 -- No typeref entry present
682 else
683 File_Num := No_Sdep_Id;
684 Line := 0;
685 Ref_Type := ' ';
686 Col := 0;
687 Standard_Entity := No_Name;
688 end if;
689 end Get_Typeref;
691 ----------
692 -- Getc --
693 ----------
695 function Getc return Character is
696 begin
697 if P = T'Last then
698 return EOF;
699 else
700 P := P + 1;
701 return T (P - 1);
702 end if;
703 end Getc;
705 -----------
706 -- Nextc --
707 -----------
709 function Nextc return Character is
710 begin
711 return T (P);
712 end Nextc;
714 --------------
715 -- Skip_Eol --
716 --------------
718 procedure Skip_Eol is
719 begin
720 Skip_Space;
722 if not At_Eol then
723 if Ignore_Errors then
724 while not At_Eol loop
725 P := P + 1;
726 end loop;
727 else
728 Fatal_Error;
729 end if;
730 end if;
732 -- Loop to skip past blank lines (first time through skips this EOL)
734 while Nextc < ' ' and then Nextc /= EOF loop
735 if Nextc = LF then
736 Line := Line + 1;
737 end if;
739 P := P + 1;
740 end loop;
741 end Skip_Eol;
743 ---------------
744 -- Skip_Line --
745 ---------------
747 procedure Skip_Line is
748 begin
749 while not At_Eol loop
750 P := P + 1;
751 end loop;
753 Skip_Eol;
754 end Skip_Line;
756 ----------------
757 -- Skip_Space --
758 ----------------
760 procedure Skip_Space is
761 begin
762 while Nextc = ' ' or else Nextc = HT loop
763 P := P + 1;
764 end loop;
765 end Skip_Space;
767 -----------
768 -- Skipc --
769 -----------
771 procedure Skipc is
772 begin
773 if P /= T'Last then
774 P := P + 1;
775 end if;
776 end Skipc;
778 -- Start of processing for Scan_ALI
780 begin
781 First_Sdep_Entry := Sdep.Last + 1;
783 -- Acquire lines to be ignored
785 if Read_Xref then
786 Ignore :=
787 ('U' | 'W' | 'Y' | 'Z' | 'D' | 'X' => False, others => True);
789 -- Read_Lines parameter given
791 elsif Read_Lines /= "" then
792 Ignore := ('U' => False, others => True);
794 for J in Read_Lines'Range loop
795 Ignore (Read_Lines (J)) := False;
796 end loop;
798 -- Process Ignore_Lines parameter
800 else
801 Ignore := (others => False);
803 for J in Ignore_Lines'Range loop
804 pragma Assert (Ignore_Lines (J) /= 'U');
805 Ignore (Ignore_Lines (J)) := True;
806 end loop;
807 end if;
809 -- Setup ALI Table entry with appropriate defaults
811 ALIs.Increment_Last;
812 Id := ALIs.Last;
813 Set_Name_Table_Info (F, Int (Id));
815 ALIs.Table (Id) := (
816 Afile => F,
817 Compile_Errors => False,
818 First_Interrupt_State => Interrupt_States.Last + 1,
819 First_Sdep => No_Sdep_Id,
820 First_Specific_Dispatching => Specific_Dispatching.Last + 1,
821 First_Unit => No_Unit_Id,
822 Float_Format => 'I',
823 Last_Interrupt_State => Interrupt_States.Last,
824 Last_Sdep => No_Sdep_Id,
825 Last_Specific_Dispatching => Specific_Dispatching.Last,
826 Last_Unit => No_Unit_Id,
827 Locking_Policy => ' ',
828 Main_Priority => -1,
829 Main_CPU => -1,
830 Main_Program => None,
831 No_Object => False,
832 Normalize_Scalars => False,
833 Ofile_Full_Name => Full_Object_File_Name,
834 Queuing_Policy => ' ',
835 Restrictions => No_Restrictions,
836 SAL_Interface => False,
837 Sfile => No_File,
838 Task_Dispatching_Policy => ' ',
839 Time_Slice_Value => -1,
840 Allocator_In_Body => False,
841 WC_Encoding => 'b',
842 Unit_Exception_Table => False,
843 Ver => (others => ' '),
844 Ver_Len => 0,
845 Zero_Cost_Exceptions => False);
847 -- Now we acquire the input lines from the ALI file. Note that the
848 -- convention in the following code is that as we enter each section,
849 -- C is set to contain the first character of the following line.
851 C := Getc;
852 Check_Unknown_Line;
854 -- Acquire library version
856 if C /= 'V' then
858 -- The V line missing really indicates trouble, most likely it
859 -- means we don't have an ALI file at all, so here we give a
860 -- fatal error even if we are in Ignore_Errors mode.
862 Fatal_Error;
864 elsif Ignore ('V') then
865 Skip_Line;
867 else
868 Checkc (' ');
869 Skip_Space;
870 Checkc ('"');
872 for J in 1 .. Ver_Len_Max loop
873 C := Getc;
874 exit when C = '"';
875 ALIs.Table (Id).Ver (J) := C;
876 ALIs.Table (Id).Ver_Len := J;
877 end loop;
879 Skip_Eol;
880 end if;
882 C := Getc;
883 Check_Unknown_Line;
885 -- Acquire main program line if present
887 if C = 'M' then
888 if Ignore ('M') then
889 Skip_Line;
891 else
892 Checkc (' ');
893 Skip_Space;
895 C := Getc;
897 if C = 'F' then
898 ALIs.Table (Id).Main_Program := Func;
899 elsif C = 'P' then
900 ALIs.Table (Id).Main_Program := Proc;
901 else
902 P := P - 1;
903 Fatal_Error;
904 end if;
906 Skip_Space;
908 if not At_Eol then
909 if Nextc < 'A' then
910 ALIs.Table (Id).Main_Priority := Get_Nat;
911 end if;
913 Skip_Space;
915 if Nextc = 'T' then
916 P := P + 1;
917 Checkc ('=');
918 ALIs.Table (Id).Time_Slice_Value := Get_Nat;
919 end if;
921 Skip_Space;
923 if Nextc = 'A' then
924 P := P + 1;
925 Checkc ('B');
926 ALIs.Table (Id).Allocator_In_Body := True;
927 end if;
929 Skip_Space;
931 if Nextc = 'C' then
932 P := P + 1;
933 Checkc ('=');
934 ALIs.Table (Id).Main_CPU := Get_Nat;
935 end if;
937 Skip_Space;
939 Checkc ('W');
940 Checkc ('=');
941 ALIs.Table (Id).WC_Encoding := Getc;
942 end if;
944 Skip_Eol;
945 end if;
947 C := Getc;
948 end if;
950 -- Acquire argument lines
952 First_Arg := Args.Last + 1;
954 A_Loop : loop
955 Check_Unknown_Line;
956 exit A_Loop when C /= 'A';
958 if Ignore ('A') then
959 Skip_Line;
961 else
962 Checkc (' ');
964 -- Scan out argument
966 Name_Len := 0;
967 while not At_Eol loop
968 Add_Char_To_Name_Buffer (Getc);
969 end loop;
971 -- If -fstack-check, record that it occurred
973 if Name_Buffer (1 .. Name_Len) = "-fstack-check" then
974 Stack_Check_Switch_Set := True;
975 end if;
977 -- Store the argument
979 Args.Increment_Last;
980 Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
982 Skip_Eol;
983 end if;
985 C := Getc;
986 end loop A_Loop;
988 -- Acquire P line
990 Check_Unknown_Line;
992 while C /= 'P' loop
993 if Ignore_Errors then
994 if C = EOF then
995 Fatal_Error;
996 else
997 Skip_Line;
998 C := Nextc;
999 end if;
1000 else
1001 Fatal_Error;
1002 end if;
1003 end loop;
1005 if Ignore ('P') then
1006 Skip_Line;
1008 -- Process P line
1010 else
1011 NS_Found := False;
1013 while not At_Eol loop
1014 Checkc (' ');
1015 Skip_Space;
1016 C := Getc;
1018 -- Processing for CE
1020 if C = 'C' then
1021 Checkc ('E');
1022 ALIs.Table (Id).Compile_Errors := True;
1024 -- Processing for DB
1026 elsif C = 'D' then
1027 Checkc ('B');
1028 Detect_Blocking := True;
1030 -- Processing for FD/FG/FI
1032 elsif C = 'F' then
1033 Float_Format_Specified := Getc;
1034 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1036 -- Processing for Lx
1038 elsif C = 'L' then
1039 Locking_Policy_Specified := Getc;
1040 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1042 -- Processing for flags starting with N
1044 elsif C = 'N' then
1045 C := Getc;
1047 -- Processing for NO
1049 if C = 'O' then
1050 ALIs.Table (Id).No_Object := True;
1051 No_Object_Specified := True;
1053 -- Processing for NR
1055 elsif C = 'R' then
1056 No_Run_Time_Mode := True;
1057 Configurable_Run_Time_Mode := True;
1059 -- Processing for NS
1061 elsif C = 'S' then
1062 ALIs.Table (Id).Normalize_Scalars := True;
1063 Normalize_Scalars_Specified := True;
1064 NS_Found := True;
1066 -- Invalid switch starting with N
1068 else
1069 Fatal_Error_Ignore;
1070 end if;
1072 -- Processing for Qx
1074 elsif C = 'Q' then
1075 Queuing_Policy_Specified := Getc;
1076 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1078 -- Processing for flags starting with S
1080 elsif C = 'S' then
1081 C := Getc;
1083 -- Processing for SL
1085 if C = 'L' then
1086 ALIs.Table (Id).SAL_Interface := True;
1088 -- Processing for SS
1090 elsif C = 'S' then
1091 Opt.Sec_Stack_Used := True;
1093 -- Invalid switch starting with S
1095 else
1096 Fatal_Error_Ignore;
1097 end if;
1099 -- Processing for Tx
1101 elsif C = 'T' then
1102 Task_Dispatching_Policy_Specified := Getc;
1103 ALIs.Table (Id).Task_Dispatching_Policy :=
1104 Task_Dispatching_Policy_Specified;
1106 -- Processing for switch starting with U
1108 elsif C = 'U' then
1109 C := Getc;
1111 -- Processing for UA
1113 if C = 'A' then
1114 Unreserve_All_Interrupts_Specified := True;
1116 -- Processing for UX
1118 elsif C = 'X' then
1119 ALIs.Table (Id).Unit_Exception_Table := True;
1121 -- Invalid switches starting with U
1123 else
1124 Fatal_Error_Ignore;
1125 end if;
1127 -- Processing for ZX
1129 elsif C = 'Z' then
1130 C := Getc;
1132 if C = 'X' then
1133 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1134 Zero_Cost_Exceptions_Specified := True;
1135 else
1136 Fatal_Error_Ignore;
1137 end if;
1139 -- Invalid parameter
1141 else
1142 C := Getc;
1143 Fatal_Error_Ignore;
1144 end if;
1145 end loop;
1147 if not NS_Found then
1148 No_Normalize_Scalars_Specified := True;
1149 end if;
1151 Skip_Eol;
1152 end if;
1154 C := Getc;
1155 Check_Unknown_Line;
1157 -- Loop to skip to first restrictions line
1159 while C /= 'R' loop
1160 if Ignore_Errors then
1161 if C = EOF then
1162 Fatal_Error;
1163 else
1164 Skip_Line;
1165 C := Nextc;
1166 end if;
1167 else
1168 Fatal_Error;
1169 end if;
1170 end loop;
1172 -- Ignore all 'R' lines if that is required
1174 if Ignore ('R') then
1175 while C = 'R' loop
1176 Skip_Line;
1177 C := Getc;
1178 end loop;
1180 -- Here we process the restrictions lines (other than unit name cases)
1182 else
1183 Scan_Restrictions : declare
1184 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1185 -- Save cumulative restrictions in case we have a fatal error
1187 Bad_R_Line : exception;
1188 -- Signal bad restrictions line (raised on unexpected character)
1190 Typ : Character;
1191 R : Restriction_Id;
1192 N : Natural;
1194 begin
1195 -- Named restriction case
1197 if Nextc = 'N' then
1198 Skip_Line;
1199 C := Getc;
1201 -- Loop through RR and RV lines
1203 while C = 'R' and then Nextc /= ' ' loop
1204 Typ := Getc;
1205 Checkc (' ');
1207 -- Acquire restriction name
1209 Name_Len := 0;
1210 while not At_Eol and then Nextc /= '=' loop
1211 Name_Len := Name_Len + 1;
1212 Name_Buffer (Name_Len) := Getc;
1213 end loop;
1215 -- Now search list of restrictions to find match
1217 declare
1218 RN : String renames Name_Buffer (1 .. Name_Len);
1220 begin
1221 R := Restriction_Id'First;
1222 while R < Not_A_Restriction_Id loop
1223 if Restriction_Id'Image (R) = RN then
1224 goto R_Found;
1225 end if;
1227 R := Restriction_Id'Succ (R);
1228 end loop;
1230 -- We don't recognize the restriction. This might be
1231 -- thought of as an error, and it really is, but we
1232 -- want to allow building with inconsistent versions
1233 -- of the binder and ali files (see comments at the
1234 -- start of package System.Rident), so we just ignore
1235 -- this situation.
1237 goto Done_With_Restriction_Line;
1238 end;
1240 <<R_Found>>
1242 case R is
1244 -- Boolean restriction case
1246 when All_Boolean_Restrictions =>
1247 case Typ is
1248 when 'V' =>
1249 ALIs.Table (Id).Restrictions.Violated (R) :=
1250 True;
1251 Cumulative_Restrictions.Violated (R) := True;
1253 when 'R' =>
1254 ALIs.Table (Id).Restrictions.Set (R) := True;
1255 Cumulative_Restrictions.Set (R) := True;
1257 when others =>
1258 raise Bad_R_Line;
1259 end case;
1261 -- Parameter restriction case
1263 when All_Parameter_Restrictions =>
1264 if At_Eol or else Nextc /= '=' then
1265 raise Bad_R_Line;
1266 else
1267 Skipc;
1268 end if;
1270 N := Natural (Get_Nat);
1272 case Typ is
1274 -- Restriction set
1276 when 'R' =>
1277 ALIs.Table (Id).Restrictions.Set (R) := True;
1278 ALIs.Table (Id).Restrictions.Value (R) := N;
1280 if Cumulative_Restrictions.Set (R) then
1281 Cumulative_Restrictions.Value (R) :=
1282 Integer'Min
1283 (Cumulative_Restrictions.Value (R), N);
1284 else
1285 Cumulative_Restrictions.Set (R) := True;
1286 Cumulative_Restrictions.Value (R) := N;
1287 end if;
1289 -- Restriction violated
1291 when 'V' =>
1292 ALIs.Table (Id).Restrictions.Violated (R) :=
1293 True;
1294 Cumulative_Restrictions.Violated (R) := True;
1295 ALIs.Table (Id).Restrictions.Count (R) := N;
1297 -- Checked Max_Parameter case
1299 if R in Checked_Max_Parameter_Restrictions then
1300 Cumulative_Restrictions.Count (R) :=
1301 Integer'Max
1302 (Cumulative_Restrictions.Count (R), N);
1304 -- Other checked parameter cases
1306 else
1307 declare
1308 pragma Unsuppress (Overflow_Check);
1310 begin
1311 Cumulative_Restrictions.Count (R) :=
1312 Cumulative_Restrictions.Count (R) + N;
1314 exception
1315 when Constraint_Error =>
1317 -- A constraint error comes from the
1318 -- additionh. We reset to the maximum
1319 -- and indicate that the real value is
1320 -- now unknown.
1322 Cumulative_Restrictions.Value (R) :=
1323 Integer'Last;
1324 Cumulative_Restrictions.Unknown (R) :=
1325 True;
1326 end;
1327 end if;
1329 -- Deal with + case
1331 if Nextc = '+' then
1332 Skipc;
1333 ALIs.Table (Id).Restrictions.Unknown (R) :=
1334 True;
1335 Cumulative_Restrictions.Unknown (R) := True;
1336 end if;
1338 -- Other than 'R' or 'V'
1340 when others =>
1341 raise Bad_R_Line;
1342 end case;
1344 if not At_Eol then
1345 raise Bad_R_Line;
1346 end if;
1348 -- Bizarre error case NOT_A_RESTRICTION
1350 when Not_A_Restriction_Id =>
1351 raise Bad_R_Line;
1352 end case;
1354 if not At_Eol then
1355 raise Bad_R_Line;
1356 end if;
1358 <<Done_With_Restriction_Line>>
1359 Skip_Line;
1360 C := Getc;
1361 end loop;
1363 -- Positional restriction case
1365 else
1366 Checkc (' ');
1367 Skip_Space;
1369 -- Acquire information for boolean restrictions
1371 for R in All_Boolean_Restrictions loop
1372 C := Getc;
1374 case C is
1375 when 'v' =>
1376 ALIs.Table (Id).Restrictions.Violated (R) := True;
1377 Cumulative_Restrictions.Violated (R) := True;
1379 when 'r' =>
1380 ALIs.Table (Id).Restrictions.Set (R) := True;
1381 Cumulative_Restrictions.Set (R) := True;
1383 when 'n' =>
1384 null;
1386 when others =>
1387 raise Bad_R_Line;
1388 end case;
1389 end loop;
1391 -- Acquire information for parameter restrictions
1393 for RP in All_Parameter_Restrictions loop
1394 case Getc is
1395 when 'n' =>
1396 null;
1398 when 'r' =>
1399 ALIs.Table (Id).Restrictions.Set (RP) := True;
1401 declare
1402 N : constant Integer := Integer (Get_Nat);
1403 begin
1404 ALIs.Table (Id).Restrictions.Value (RP) := N;
1406 if Cumulative_Restrictions.Set (RP) then
1407 Cumulative_Restrictions.Value (RP) :=
1408 Integer'Min
1409 (Cumulative_Restrictions.Value (RP), N);
1410 else
1411 Cumulative_Restrictions.Set (RP) := True;
1412 Cumulative_Restrictions.Value (RP) := N;
1413 end if;
1414 end;
1416 when others =>
1417 raise Bad_R_Line;
1418 end case;
1420 -- Acquire restrictions violations information
1422 case Getc is
1424 when 'n' =>
1425 null;
1427 when 'v' =>
1428 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1429 Cumulative_Restrictions.Violated (RP) := True;
1431 declare
1432 N : constant Integer := Integer (Get_Nat);
1434 begin
1435 ALIs.Table (Id).Restrictions.Count (RP) := N;
1437 if RP in Checked_Max_Parameter_Restrictions then
1438 Cumulative_Restrictions.Count (RP) :=
1439 Integer'Max
1440 (Cumulative_Restrictions.Count (RP), N);
1442 else
1443 declare
1444 pragma Unsuppress (Overflow_Check);
1446 begin
1447 Cumulative_Restrictions.Count (RP) :=
1448 Cumulative_Restrictions.Count (RP) + N;
1450 exception
1451 when Constraint_Error =>
1453 -- A constraint error comes from the add. We
1454 -- reset to the maximum and indicate that the
1455 -- real value is now unknown.
1457 Cumulative_Restrictions.Value (RP) :=
1458 Integer'Last;
1459 Cumulative_Restrictions.Unknown (RP) := True;
1460 end;
1461 end if;
1463 if Nextc = '+' then
1464 Skipc;
1465 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1466 Cumulative_Restrictions.Unknown (RP) := True;
1467 end if;
1468 end;
1470 when others =>
1471 raise Bad_R_Line;
1472 end case;
1473 end loop;
1475 if not At_Eol then
1476 raise Bad_R_Line;
1477 else
1478 Skip_Line;
1479 C := Getc;
1480 end if;
1481 end if;
1483 -- Here if error during scanning of restrictions line
1485 exception
1486 when Bad_R_Line =>
1488 -- In Ignore_Errors mode, undo any changes to restrictions
1489 -- from this unit, and continue on, skipping remaining R
1490 -- lines for this unit.
1492 if Ignore_Errors then
1493 Cumulative_Restrictions := Save_R;
1494 ALIs.Table (Id).Restrictions := No_Restrictions;
1496 loop
1497 Skip_Eol;
1498 C := Getc;
1499 exit when C /= 'R';
1500 end loop;
1502 -- In normal mode, this is a fatal error
1504 else
1505 Fatal_Error;
1506 end if;
1507 end Scan_Restrictions;
1508 end if;
1510 -- Acquire additional restrictions (No_Dependence) lines if present
1512 while C = 'R' loop
1513 if Ignore ('R') then
1514 Skip_Line;
1515 else
1516 Skip_Space;
1517 No_Deps.Append ((Id, Get_Name));
1518 Skip_Eol;
1519 end if;
1521 C := Getc;
1522 end loop;
1524 -- Acquire 'I' lines if present
1526 Check_Unknown_Line;
1528 while C = 'I' loop
1529 if Ignore ('I') then
1530 Skip_Line;
1532 else
1533 declare
1534 Int_Num : Nat;
1535 I_State : Character;
1536 Line_No : Nat;
1538 begin
1539 Int_Num := Get_Nat;
1540 Skip_Space;
1541 I_State := Getc;
1542 Line_No := Get_Nat;
1544 Interrupt_States.Append (
1545 (Interrupt_Id => Int_Num,
1546 Interrupt_State => I_State,
1547 IS_Pragma_Line => Line_No));
1549 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1550 Skip_Eol;
1551 end;
1552 end if;
1554 C := Getc;
1555 end loop;
1557 -- Acquire 'S' lines if present
1559 Check_Unknown_Line;
1561 while C = 'S' loop
1562 if Ignore ('S') then
1563 Skip_Line;
1565 else
1566 declare
1567 Policy : Character;
1568 First_Prio : Nat;
1569 Last_Prio : Nat;
1570 Line_No : Nat;
1572 begin
1573 Checkc (' ');
1574 Skip_Space;
1576 Policy := Getc;
1577 Skip_Space;
1578 First_Prio := Get_Nat;
1579 Last_Prio := Get_Nat;
1580 Line_No := Get_Nat;
1582 Specific_Dispatching.Append (
1583 (Dispatching_Policy => Policy,
1584 First_Priority => First_Prio,
1585 Last_Priority => Last_Prio,
1586 PSD_Pragma_Line => Line_No));
1588 ALIs.Table (Id).Last_Specific_Dispatching :=
1589 Specific_Dispatching.Last;
1591 Skip_Eol;
1592 end;
1593 end if;
1595 C := Getc;
1596 end loop;
1598 -- Loop to acquire unit entries
1600 U_Loop : loop
1601 Check_Unknown_Line;
1602 exit U_Loop when C /= 'U';
1604 -- Note: as per spec, we never ignore U lines
1606 Checkc (' ');
1607 Skip_Space;
1608 Units.Increment_Last;
1610 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1611 ALIs.Table (Id).First_Unit := Units.Last;
1612 end if;
1614 declare
1615 UL : Unit_Record renames Units.Table (Units.Last);
1617 begin
1618 UL.Uname := Get_Unit_Name;
1619 UL.Predefined := Is_Predefined_Unit;
1620 UL.Internal := Is_Internal_Unit;
1621 UL.My_ALI := Id;
1622 UL.Sfile := Get_File_Name (Lower => True);
1623 UL.Pure := False;
1624 UL.Preelab := False;
1625 UL.No_Elab := False;
1626 UL.Shared_Passive := False;
1627 UL.RCI := False;
1628 UL.Remote_Types := False;
1629 UL.Has_RACW := False;
1630 UL.Init_Scalars := False;
1631 UL.Is_Generic := False;
1632 UL.Icasing := Mixed_Case;
1633 UL.Kcasing := All_Lower_Case;
1634 UL.Dynamic_Elab := False;
1635 UL.Elaborate_Body := False;
1636 UL.Set_Elab_Entity := False;
1637 UL.Version := "00000000";
1638 UL.First_With := Withs.Last + 1;
1639 UL.First_Arg := First_Arg;
1640 UL.Elab_Position := 0;
1641 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1642 UL.Directly_Scanned := Directly_Scanned;
1643 UL.Body_Needed_For_SAL := False;
1644 UL.Elaborate_Body_Desirable := False;
1645 UL.Optimize_Alignment := 'O';
1646 UL.Has_Finalizer := False;
1648 if Debug_Flag_U then
1649 Write_Str (" ----> reading unit ");
1650 Write_Int (Int (Units.Last));
1651 Write_Str (" ");
1652 Write_Unit_Name (UL.Uname);
1653 Write_Str (" from file ");
1654 Write_Name (UL.Sfile);
1655 Write_Eol;
1656 end if;
1657 end;
1659 -- Check for duplicated unit in different files
1661 declare
1662 Info : constant Int := Get_Name_Table_Info
1663 (Units.Table (Units.Last).Uname);
1664 begin
1665 if Info /= 0
1666 and then Units.Table (Units.Last).Sfile /=
1667 Units.Table (Unit_Id (Info)).Sfile
1668 then
1669 -- If Err is set then ignore duplicate unit name. This is the
1670 -- case of a call from gnatmake, where the situation can arise
1671 -- from substitution of source files. In such situations, the
1672 -- processing in gnatmake will always result in any required
1673 -- recompilations in any case, and if we consider this to be
1674 -- an error we get strange cases (for example when a generic
1675 -- instantiation is replaced by a normal package) where we
1676 -- read the old ali file, decide to recompile, and then decide
1677 -- that the old and new ali files are incompatible.
1679 if Err then
1680 null;
1682 -- If Err is not set, then this is a fatal error. This is
1683 -- the case of being called from the binder, where we must
1684 -- definitely diagnose this as an error.
1686 else
1687 Set_Standard_Error;
1688 Write_Str ("error: duplicate unit name: ");
1689 Write_Eol;
1691 Write_Str ("error: unit """);
1692 Write_Unit_Name (Units.Table (Units.Last).Uname);
1693 Write_Str (""" found in file """);
1694 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1695 Write_Char ('"');
1696 Write_Eol;
1698 Write_Str ("error: unit """);
1699 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1700 Write_Str (""" found in file """);
1701 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1702 Write_Char ('"');
1703 Write_Eol;
1705 Exit_Program (E_Fatal);
1706 end if;
1707 end if;
1708 end;
1710 Set_Name_Table_Info
1711 (Units.Table (Units.Last).Uname, Int (Units.Last));
1713 -- Scan out possible version and other parameters
1715 loop
1716 Skip_Space;
1717 exit when At_Eol;
1718 C := Getc;
1720 -- Version field
1722 if C in '0' .. '9' or else C in 'a' .. 'f' then
1723 Units.Table (Units.Last).Version (1) := C;
1725 for J in 2 .. 8 loop
1726 C := Getc;
1727 Units.Table (Units.Last).Version (J) := C;
1728 end loop;
1730 -- BD/BN parameters
1732 elsif C = 'B' then
1733 C := Getc;
1735 if C = 'D' then
1736 Check_At_End_Of_Field;
1737 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1739 elsif C = 'N' then
1740 Check_At_End_Of_Field;
1741 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1743 else
1744 Fatal_Error_Ignore;
1745 end if;
1747 -- DE parameter (Dynamic elaboration checks)
1749 elsif C = 'D' then
1750 C := Getc;
1752 if C = 'E' then
1753 Check_At_End_Of_Field;
1754 Units.Table (Units.Last).Dynamic_Elab := True;
1755 Dynamic_Elaboration_Checks_Specified := True;
1756 else
1757 Fatal_Error_Ignore;
1758 end if;
1760 -- EB/EE parameters
1762 elsif C = 'E' then
1763 C := Getc;
1765 if C = 'B' then
1766 Units.Table (Units.Last).Elaborate_Body := True;
1767 elsif C = 'E' then
1768 Units.Table (Units.Last).Set_Elab_Entity := True;
1769 else
1770 Fatal_Error_Ignore;
1771 end if;
1773 Check_At_End_Of_Field;
1775 -- GE parameter (generic)
1777 elsif C = 'G' then
1778 C := Getc;
1780 if C = 'E' then
1781 Check_At_End_Of_Field;
1782 Units.Table (Units.Last).Is_Generic := True;
1783 else
1784 Fatal_Error_Ignore;
1785 end if;
1787 -- IL/IS/IU parameters
1789 elsif C = 'I' then
1790 C := Getc;
1792 if C = 'L' then
1793 Units.Table (Units.Last).Icasing := All_Lower_Case;
1794 elsif C = 'S' then
1795 Units.Table (Units.Last).Init_Scalars := True;
1796 Initialize_Scalars_Used := True;
1797 elsif C = 'U' then
1798 Units.Table (Units.Last).Icasing := All_Upper_Case;
1799 else
1800 Fatal_Error_Ignore;
1801 end if;
1803 Check_At_End_Of_Field;
1805 -- KM/KU parameters
1807 elsif C = 'K' then
1808 C := Getc;
1810 if C = 'M' then
1811 Units.Table (Units.Last).Kcasing := Mixed_Case;
1812 elsif C = 'U' then
1813 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1814 else
1815 Fatal_Error_Ignore;
1816 end if;
1818 Check_At_End_Of_Field;
1820 -- NE parameter
1822 elsif C = 'N' then
1823 C := Getc;
1825 if C = 'E' then
1826 Units.Table (Units.Last).No_Elab := True;
1827 Check_At_End_Of_Field;
1828 else
1829 Fatal_Error_Ignore;
1830 end if;
1832 -- PF/PR/PU/PK parameters
1834 elsif C = 'P' then
1835 C := Getc;
1837 if C = 'F' then
1838 Units.Table (Units.Last).Has_Finalizer := True;
1839 elsif C = 'R' then
1840 Units.Table (Units.Last).Preelab := True;
1841 elsif C = 'U' then
1842 Units.Table (Units.Last).Pure := True;
1843 elsif C = 'K' then
1844 Units.Table (Units.Last).Unit_Kind := 'p';
1845 else
1846 Fatal_Error_Ignore;
1847 end if;
1849 Check_At_End_Of_Field;
1851 -- OL/OO/OS/OT parameters
1853 elsif C = 'O' then
1854 C := Getc;
1856 if C = 'L' or else C = 'O' or else C = 'S' or else C = 'T' then
1857 Units.Table (Units.Last).Optimize_Alignment := C;
1858 else
1859 Fatal_Error_Ignore;
1860 end if;
1862 Check_At_End_Of_Field;
1864 -- RC/RT parameters
1866 elsif C = 'R' then
1867 C := Getc;
1869 if C = 'C' then
1870 Units.Table (Units.Last).RCI := True;
1871 elsif C = 'T' then
1872 Units.Table (Units.Last).Remote_Types := True;
1873 elsif C = 'A' then
1874 Units.Table (Units.Last).Has_RACW := True;
1875 else
1876 Fatal_Error_Ignore;
1877 end if;
1879 Check_At_End_Of_Field;
1881 elsif C = 'S' then
1882 C := Getc;
1884 if C = 'P' then
1885 Units.Table (Units.Last).Shared_Passive := True;
1886 elsif C = 'U' then
1887 Units.Table (Units.Last).Unit_Kind := 's';
1888 else
1889 Fatal_Error_Ignore;
1890 end if;
1892 Check_At_End_Of_Field;
1894 else
1895 C := Getc;
1896 Fatal_Error_Ignore;
1897 end if;
1898 end loop;
1900 Skip_Eol;
1902 -- Check if static elaboration model used
1904 if not Units.Table (Units.Last).Dynamic_Elab
1905 and then not Units.Table (Units.Last).Internal
1906 then
1907 Static_Elaboration_Model_Used := True;
1908 end if;
1910 C := Getc;
1912 -- Scan out With lines for this unit
1914 With_Loop : loop
1915 Check_Unknown_Line;
1916 exit With_Loop when C /= 'W' and then C /= 'Y' and then C /= 'Z';
1918 if Ignore ('W') then
1919 Skip_Line;
1921 else
1922 Checkc (' ');
1923 Skip_Space;
1924 Withs.Increment_Last;
1925 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1926 Withs.Table (Withs.Last).Elaborate := False;
1927 Withs.Table (Withs.Last).Elaborate_All := False;
1928 Withs.Table (Withs.Last).Elab_Desirable := False;
1929 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1930 Withs.Table (Withs.Last).SAL_Interface := False;
1931 Withs.Table (Withs.Last).Limited_With := (C = 'Y');
1932 Withs.Table (Withs.Last).Implicit_With_From_Instantiation
1933 := (C = 'Z');
1935 -- Generic case with no object file available
1937 if At_Eol then
1938 Withs.Table (Withs.Last).Sfile := No_File;
1939 Withs.Table (Withs.Last).Afile := No_File;
1941 -- Normal case
1943 else
1944 Withs.Table (Withs.Last).Sfile := Get_File_Name
1945 (Lower => True);
1946 Withs.Table (Withs.Last).Afile := Get_File_Name
1947 (Lower => True);
1949 -- Scan out possible E, EA, ED, and AD parameters
1951 while not At_Eol loop
1952 Skip_Space;
1954 if Nextc = 'A' then
1955 P := P + 1;
1956 Checkc ('D');
1957 Check_At_End_Of_Field;
1959 -- Store AD indication unless ignore required
1961 if not Ignore_ED then
1962 Withs.Table (Withs.Last).Elab_All_Desirable :=
1963 True;
1964 end if;
1966 elsif Nextc = 'E' then
1967 P := P + 1;
1969 if At_End_Of_Field then
1970 Withs.Table (Withs.Last).Elaborate := True;
1972 elsif Nextc = 'A' then
1973 P := P + 1;
1974 Check_At_End_Of_Field;
1975 Withs.Table (Withs.Last).Elaborate_All := True;
1977 else
1978 Checkc ('D');
1979 Check_At_End_Of_Field;
1981 -- Store ED indication unless ignore required
1983 if not Ignore_ED then
1984 Withs.Table (Withs.Last).Elab_Desirable :=
1985 True;
1986 end if;
1987 end if;
1989 else
1990 Fatal_Error;
1991 end if;
1992 end loop;
1993 end if;
1995 Skip_Eol;
1996 end if;
1998 C := Getc;
1999 end loop With_Loop;
2001 Units.Table (Units.Last).Last_With := Withs.Last;
2002 Units.Table (Units.Last).Last_Arg := Args.Last;
2004 -- If there are linker options lines present, scan them
2006 Name_Len := 0;
2008 Linker_Options_Loop : loop
2009 Check_Unknown_Line;
2010 exit Linker_Options_Loop when C /= 'L';
2012 if Ignore ('L') then
2013 Skip_Line;
2015 else
2016 Checkc (' ');
2017 Skip_Space;
2018 Checkc ('"');
2020 loop
2021 C := Getc;
2023 if C < Character'Val (16#20#)
2024 or else C > Character'Val (16#7E#)
2025 then
2026 Fatal_Error_Ignore;
2028 elsif C = '{' then
2029 C := Character'Val (0);
2031 declare
2032 V : Natural;
2034 begin
2035 V := 0;
2036 for J in 1 .. 2 loop
2037 C := Getc;
2039 if C in '0' .. '9' then
2040 V := V * 16 +
2041 Character'Pos (C) -
2042 Character'Pos ('0');
2044 elsif C in 'A' .. 'F' then
2045 V := V * 16 +
2046 Character'Pos (C) -
2047 Character'Pos ('A') +
2050 else
2051 Fatal_Error_Ignore;
2052 end if;
2053 end loop;
2055 Checkc ('}');
2056 Add_Char_To_Name_Buffer (Character'Val (V));
2057 end;
2059 else
2060 if C = '"' then
2061 exit when Nextc /= '"';
2062 C := Getc;
2063 end if;
2065 Add_Char_To_Name_Buffer (C);
2066 end if;
2067 end loop;
2069 Add_Char_To_Name_Buffer (NUL);
2070 Skip_Eol;
2071 end if;
2073 C := Getc;
2074 end loop Linker_Options_Loop;
2076 -- Store the linker options entry if one was found
2078 if Name_Len /= 0 then
2079 Linker_Options.Increment_Last;
2081 Linker_Options.Table (Linker_Options.Last).Name :=
2082 Name_Enter;
2084 Linker_Options.Table (Linker_Options.Last).Unit :=
2085 Units.Last;
2087 Linker_Options.Table (Linker_Options.Last).Internal_File :=
2088 Is_Internal_File_Name (F);
2090 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
2091 Linker_Options.Last;
2092 end if;
2094 -- If there are notes present, scan them
2096 Notes_Loop : loop
2097 Check_Unknown_Line;
2098 exit Notes_Loop when C /= 'N';
2100 if Ignore ('N') then
2101 Skip_Line;
2103 else
2104 Checkc (' ');
2106 Notes.Increment_Last;
2107 Notes.Table (Notes.Last).Pragma_Type := Getc;
2108 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
2109 Checkc (':');
2110 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
2111 Notes.Table (Notes.Last).Unit := Units.Last;
2113 if At_Eol then
2114 Notes.Table (Notes.Last).Pragma_Args := No_Name;
2116 else
2117 Checkc (' ');
2119 Name_Len := 0;
2120 while not At_Eol loop
2121 Add_Char_To_Name_Buffer (Getc);
2122 end loop;
2124 Notes.Table (Notes.Last).Pragma_Args := Name_Enter;
2125 end if;
2127 Skip_Eol;
2128 end if;
2130 C := Getc;
2131 end loop Notes_Loop;
2132 end loop U_Loop;
2134 -- End loop through units for one ALI file
2136 ALIs.Table (Id).Last_Unit := Units.Last;
2137 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
2139 -- Set types of the units (there can be at most 2 of them)
2141 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
2142 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
2143 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
2145 else
2146 -- Deal with body only and spec only cases, note that the reason we
2147 -- do our own checking of the name (rather than using Is_Body_Name)
2148 -- is that Uname drags in far too much compiler junk!
2150 Get_Name_String (Units.Table (Units.Last).Uname);
2152 if Name_Buffer (Name_Len) = 'b' then
2153 Units.Table (Units.Last).Utype := Is_Body_Only;
2154 else
2155 Units.Table (Units.Last).Utype := Is_Spec_Only;
2156 end if;
2157 end if;
2159 -- Scan out external version references and put in hash table
2161 E_Loop : loop
2162 Check_Unknown_Line;
2163 exit E_Loop when C /= 'E';
2165 if Ignore ('E') then
2166 Skip_Line;
2168 else
2169 Checkc (' ');
2170 Skip_Space;
2172 Name_Len := 0;
2173 Name_Len := 0;
2174 loop
2175 C := Getc;
2177 if C < ' ' then
2178 Fatal_Error;
2179 end if;
2181 exit when At_End_Of_Field;
2182 Add_Char_To_Name_Buffer (C);
2183 end loop;
2185 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
2186 Skip_Eol;
2187 end if;
2189 C := Getc;
2190 end loop E_Loop;
2192 -- Scan out source dependency lines for this ALI file
2194 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
2196 D_Loop : loop
2197 Check_Unknown_Line;
2198 exit D_Loop when C /= 'D';
2200 if Ignore ('D') then
2201 Skip_Line;
2203 else
2204 Checkc (' ');
2205 Skip_Space;
2206 Sdep.Increment_Last;
2208 -- In the following call, Lower is not set to True, this is either
2209 -- a bug, or it deserves a special comment as to why this is so???
2211 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
2213 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
2214 Sdep.Table (Sdep.Last).Dummy_Entry :=
2215 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
2217 -- Acquire checksum value
2219 Skip_Space;
2221 declare
2222 Ctr : Natural;
2223 Chk : Word;
2225 begin
2226 Ctr := 0;
2227 Chk := 0;
2229 loop
2230 exit when At_Eol or else Ctr = 8;
2232 if Nextc in '0' .. '9' then
2233 Chk := Chk * 16 +
2234 Character'Pos (Nextc) - Character'Pos ('0');
2236 elsif Nextc in 'a' .. 'f' then
2237 Chk := Chk * 16 +
2238 Character'Pos (Nextc) - Character'Pos ('a') + 10;
2240 else
2241 exit;
2242 end if;
2244 Ctr := Ctr + 1;
2245 P := P + 1;
2246 end loop;
2248 if Ctr = 8 and then At_End_Of_Field then
2249 Sdep.Table (Sdep.Last).Checksum := Chk;
2250 else
2251 Fatal_Error;
2252 end if;
2253 end;
2255 -- Acquire subunit and reference file name entries
2257 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
2258 Sdep.Table (Sdep.Last).Rfile :=
2259 Sdep.Table (Sdep.Last).Sfile;
2260 Sdep.Table (Sdep.Last).Start_Line := 1;
2262 if not At_Eol then
2263 Skip_Space;
2265 -- Here for subunit name
2267 if Nextc not in '0' .. '9' then
2268 Name_Len := 0;
2269 while not At_End_Of_Field loop
2270 Add_Char_To_Name_Buffer (Getc);
2271 end loop;
2273 -- Set the subunit name. Note that we use Name_Find rather
2274 -- than Name_Enter here as the subunit name may already
2275 -- have been put in the name table by the Project Manager.
2277 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
2279 Skip_Space;
2280 end if;
2282 -- Here for reference file name entry
2284 if Nextc in '0' .. '9' then
2285 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2286 Checkc (':');
2288 Name_Len := 0;
2290 while not At_End_Of_Field loop
2291 Add_Char_To_Name_Buffer (Getc);
2292 end loop;
2294 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2295 end if;
2296 end if;
2298 Skip_Eol;
2299 end if;
2301 C := Getc;
2302 end loop D_Loop;
2304 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2306 -- We must at this stage be at an Xref line or the end of file
2308 if C = EOF then
2309 return Id;
2310 end if;
2312 Check_Unknown_Line;
2314 if C /= 'X' then
2315 Fatal_Error;
2316 end if;
2318 -- If we are ignoring Xref sections we are done (we ignore all
2319 -- remaining lines since only xref related lines follow X).
2321 if Ignore ('X') and then not Debug_Flag_X then
2322 return Id;
2323 end if;
2325 -- Loop through Xref sections
2327 X_Loop : loop
2328 Check_Unknown_Line;
2329 exit X_Loop when C /= 'X';
2331 -- Make new entry in section table
2333 Xref_Section.Increment_Last;
2335 Read_Refs_For_One_File : declare
2336 XS : Xref_Section_Record renames
2337 Xref_Section.Table (Xref_Section.Last);
2339 Current_File_Num : Sdep_Id;
2340 -- Keeps track of the current file number (changed by nn|)
2342 begin
2343 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2344 XS.File_Name := Get_File_Name;
2345 XS.First_Entity := Xref_Entity.Last + 1;
2347 Current_File_Num := XS.File_Num;
2349 Skip_Space;
2351 Skip_Eol;
2352 C := Nextc;
2354 -- Loop through Xref entities
2356 while C /= 'X' and then C /= EOF loop
2357 Xref_Entity.Increment_Last;
2359 Read_Refs_For_One_Entity : declare
2360 XE : Xref_Entity_Record renames
2361 Xref_Entity.Table (Xref_Entity.Last);
2362 N : Nat;
2364 procedure Read_Instantiation_Reference;
2365 -- Acquire instantiation reference. Caller has checked
2366 -- that current character is '[' and on return the cursor
2367 -- is skipped past the corresponding closing ']'.
2369 ----------------------------------
2370 -- Read_Instantiation_Reference --
2371 ----------------------------------
2373 procedure Read_Instantiation_Reference is
2374 Local_File_Num : Sdep_Id := Current_File_Num;
2376 begin
2377 Xref.Increment_Last;
2379 declare
2380 XR : Xref_Record renames Xref.Table (Xref.Last);
2382 begin
2383 P := P + 1; -- skip [
2384 N := Get_Nat;
2386 if Nextc = '|' then
2387 XR.File_Num :=
2388 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2389 Local_File_Num := XR.File_Num;
2390 P := P + 1;
2391 N := Get_Nat;
2393 else
2394 XR.File_Num := Local_File_Num;
2395 end if;
2397 XR.Line := N;
2398 XR.Rtype := ' ';
2399 XR.Col := 0;
2401 -- Recursive call for next reference
2403 if Nextc = '[' then
2404 pragma Warnings (Off); -- kill recursion warning
2405 Read_Instantiation_Reference;
2406 pragma Warnings (On);
2407 end if;
2409 -- Skip closing bracket after recursive call
2411 P := P + 1;
2412 end;
2413 end Read_Instantiation_Reference;
2415 -- Start of processing for Read_Refs_For_One_Entity
2417 begin
2418 XE.Line := Get_Nat;
2419 XE.Etype := Getc;
2420 XE.Col := Get_Nat;
2422 case Getc is
2423 when '*' =>
2424 XE.Visibility := Global;
2425 when '+' =>
2426 XE.Visibility := Static;
2427 when others =>
2428 XE.Visibility := Other;
2429 end case;
2431 XE.Entity := Get_Name;
2433 -- Handle the information about generic instantiations
2435 if Nextc = '[' then
2436 Skipc; -- Opening '['
2437 N := Get_Nat;
2439 if Nextc /= '|' then
2440 XE.Iref_File_Num := Current_File_Num;
2441 XE.Iref_Line := N;
2442 else
2443 XE.Iref_File_Num :=
2444 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2445 Skipc;
2446 XE.Iref_Line := Get_Nat;
2447 end if;
2449 if Getc /= ']' then
2450 Fatal_Error;
2451 end if;
2453 else
2454 XE.Iref_File_Num := No_Sdep_Id;
2455 XE.Iref_Line := 0;
2456 end if;
2458 Current_File_Num := XS.File_Num;
2460 -- Renaming reference is present
2462 if Nextc = '=' then
2463 P := P + 1;
2464 XE.Rref_Line := Get_Nat;
2466 if Getc /= ':' then
2467 Fatal_Error;
2468 end if;
2470 XE.Rref_Col := Get_Nat;
2472 -- No renaming reference present
2474 else
2475 XE.Rref_Line := 0;
2476 XE.Rref_Col := 0;
2477 end if;
2479 Skip_Space;
2481 XE.Oref_File_Num := No_Sdep_Id;
2482 XE.Tref_File_Num := No_Sdep_Id;
2483 XE.Tref := Tref_None;
2484 XE.First_Xref := Xref.Last + 1;
2486 -- Loop to check for additional info present
2488 loop
2489 declare
2490 Ref : Tref_Kind;
2491 File : Sdep_Id;
2492 Line : Nat;
2493 Typ : Character;
2494 Col : Nat;
2495 Std : Name_Id;
2497 begin
2498 Get_Typeref
2499 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2500 exit when Ref = Tref_None;
2502 -- Do we have an overriding procedure?
2504 if Ref = Tref_Derived and then Typ = 'p' then
2505 XE.Oref_File_Num := File;
2506 XE.Oref_Line := Line;
2507 XE.Oref_Col := Col;
2509 -- Arrays never override anything, and <> points to
2510 -- the index types instead
2512 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2514 -- Index types are stored in the list of references
2516 Xref.Increment_Last;
2518 declare
2519 XR : Xref_Record renames Xref.Table (Xref.Last);
2520 begin
2521 XR.File_Num := File;
2522 XR.Line := Line;
2523 XR.Rtype := Array_Index_Reference;
2524 XR.Col := Col;
2525 XR.Name := Std;
2526 end;
2528 -- Interfaces are stored in the list of references,
2529 -- although the parent type itself is stored in XE.
2530 -- The first interface (when there are only
2531 -- interfaces) is stored in XE.Tref*)
2533 elsif Ref = Tref_Derived
2534 and then Typ = 'R'
2535 and then XE.Tref_File_Num /= No_Sdep_Id
2536 then
2537 Xref.Increment_Last;
2539 declare
2540 XR : Xref_Record renames Xref.Table (Xref.Last);
2541 begin
2542 XR.File_Num := File;
2543 XR.Line := Line;
2544 XR.Rtype := Interface_Reference;
2545 XR.Col := Col;
2546 XR.Name := Std;
2547 end;
2549 else
2550 XE.Tref := Ref;
2551 XE.Tref_File_Num := File;
2552 XE.Tref_Line := Line;
2553 XE.Tref_Type := Typ;
2554 XE.Tref_Col := Col;
2555 XE.Tref_Standard_Entity := Std;
2556 end if;
2557 end;
2558 end loop;
2560 -- Loop through cross-references for this entity
2562 loop
2563 Skip_Space;
2565 if At_Eol then
2566 Skip_Eol;
2567 exit when Nextc /= '.';
2568 P := P + 1;
2569 end if;
2571 Xref.Increment_Last;
2573 declare
2574 XR : Xref_Record renames Xref.Table (Xref.Last);
2576 begin
2577 N := Get_Nat;
2579 if Nextc = '|' then
2580 XR.File_Num :=
2581 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2582 Current_File_Num := XR.File_Num;
2583 P := P + 1;
2584 N := Get_Nat;
2585 else
2586 XR.File_Num := Current_File_Num;
2587 end if;
2589 XR.Line := N;
2590 XR.Rtype := Getc;
2592 -- Imported entities reference as in:
2593 -- 494b<c,__gnat_copy_attribs>25
2595 if Nextc = '<' then
2596 Skipc;
2597 XR.Imported_Lang := Get_Name;
2599 pragma Assert (Nextc = ',');
2600 Skipc;
2602 XR.Imported_Name := Get_Name;
2604 pragma Assert (Nextc = '>');
2605 Skipc;
2607 else
2608 XR.Imported_Lang := No_Name;
2609 XR.Imported_Name := No_Name;
2610 end if;
2612 XR.Col := Get_Nat;
2614 if Nextc = '[' then
2615 Read_Instantiation_Reference;
2616 end if;
2617 end;
2618 end loop;
2620 -- Record last cross-reference
2622 XE.Last_Xref := Xref.Last;
2623 C := Nextc;
2625 exception
2626 when Bad_ALI_Format =>
2628 -- If ignoring errors, then we skip a line with an
2629 -- unexpected error, and try to continue subsequent
2630 -- xref lines.
2632 if Ignore_Errors then
2633 Xref_Entity.Decrement_Last;
2634 Skip_Line;
2635 C := Nextc;
2637 -- Otherwise, we reraise the fatal exception
2639 else
2640 raise;
2641 end if;
2642 end Read_Refs_For_One_Entity;
2643 end loop;
2645 -- Record last entity
2647 XS.Last_Entity := Xref_Entity.Last;
2649 end Read_Refs_For_One_File;
2651 C := Getc;
2652 end loop X_Loop;
2654 -- Here after dealing with xref sections
2656 -- Ignore remaining lines, which belong to an additional section of the
2657 -- ALI file not considered here (like SCO or Alfa).
2659 Check_Unknown_Line;
2661 return Id;
2663 exception
2664 when Bad_ALI_Format =>
2665 return No_ALI_Id;
2666 end Scan_ALI;
2668 ---------
2669 -- SEq --
2670 ---------
2672 function SEq (F1, F2 : String_Ptr) return Boolean is
2673 begin
2674 return F1.all = F2.all;
2675 end SEq;
2677 -----------
2678 -- SHash --
2679 -----------
2681 function SHash (S : String_Ptr) return Vindex is
2682 H : Word;
2684 begin
2685 H := 0;
2686 for J in S.all'Range loop
2687 H := H * 2 + Character'Pos (S (J));
2688 end loop;
2690 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));
2691 end SHash;
2693 end ALI;