[multiple changes]
[gcc.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-2011, 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 ------------------------------------------------------------------------------
25
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;
32
33 package body ALI is
34
35 use ASCII;
36 -- Make control characters visible
37
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.
41
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 'C' => True, -- SCO information
59 'F' => True, -- Alfa information
60 others => False);
61
62 --------------------
63 -- Initialize_ALI --
64 --------------------
65
66 procedure Initialize_ALI is
67 begin
68 -- When (re)initializing ALI data structures the ALI user expects to
69 -- get a fresh set of data structures. Thus we first need to erase the
70 -- marks put in the name table by the previous set of ALI routine calls.
71 -- These two loops are empty and harmless the first time in.
72
73 for J in ALIs.First .. ALIs.Last loop
74 Set_Name_Table_Info (ALIs.Table (J).Afile, 0);
75 end loop;
76
77 for J in Units.First .. Units.Last loop
78 Set_Name_Table_Info (Units.Table (J).Uname, 0);
79 end loop;
80
81 -- Free argument table strings
82
83 for J in Args.First .. Args.Last loop
84 Free (Args.Table (J));
85 end loop;
86
87 -- Initialize all tables
88
89 ALIs.Init;
90 No_Deps.Init;
91 Units.Init;
92 Withs.Init;
93 Sdep.Init;
94 Linker_Options.Init;
95 Notes.Init;
96 Xref_Section.Init;
97 Xref_Entity.Init;
98 Xref.Init;
99 Version_Ref.Reset;
100
101 -- Add dummy zero'th item in Linker_Options and Notes for sort calls
102
103 Linker_Options.Increment_Last;
104 Notes.Increment_Last;
105
106 -- Initialize global variables recording cumulative options in all
107 -- ALI files that are read for a given processing run in gnatbind.
108
109 Dynamic_Elaboration_Checks_Specified := False;
110 Float_Format_Specified := ' ';
111 Locking_Policy_Specified := ' ';
112 No_Normalize_Scalars_Specified := False;
113 No_Object_Specified := False;
114 Normalize_Scalars_Specified := False;
115 Queuing_Policy_Specified := ' ';
116 Static_Elaboration_Model_Used := False;
117 Task_Dispatching_Policy_Specified := ' ';
118 Unreserve_All_Interrupts_Specified := False;
119 Zero_Cost_Exceptions_Specified := False;
120 end Initialize_ALI;
121
122 --------------
123 -- Scan_ALI --
124 --------------
125
126 function Scan_ALI
127 (F : File_Name_Type;
128 T : Text_Buffer_Ptr;
129 Ignore_ED : Boolean;
130 Err : Boolean;
131 Read_Xref : Boolean := False;
132 Read_Lines : String := "";
133 Ignore_Lines : String := "X";
134 Ignore_Errors : Boolean := False;
135 Directly_Scanned : Boolean := False) return ALI_Id
136 is
137 P : Text_Ptr := T'First;
138 Line : Logical_Line_Number := 1;
139 Id : ALI_Id;
140 C : Character;
141 NS_Found : Boolean;
142 First_Arg : Arg_Id;
143
144 Ignore : array (Character range 'A' .. 'Z') of Boolean;
145 -- Ignore (X) is set to True if lines starting with X are to
146 -- be ignored by Scan_ALI and skipped, and False if the lines
147 -- are to be read and processed.
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_File_Name (Lower : Boolean := False) return File_Name_Type;
188 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
189 -- with length in Name_Len, as well as returning a File_Name_Type value.
190 -- If lower is false, the case is unchanged, if Lower is True then the
191 -- result is forced to all lower case for systems where file names are
192 -- not case sensitive. This ensures that gnatbind works correctly
193 -- regardless of the case of the file name on all systems. The scan
194 -- is terminated by a end of line, space or horizontal tab. Any other
195 -- special characters are included in the returned name.
196
197 function Get_Name
198 (Ignore_Spaces : Boolean := False;
199 Ignore_Special : Boolean := False) return Name_Id;
200 -- Skip blanks, then scan out a name (name is left in Name_Buffer with
201 -- length in Name_Len, as well as being returned in Name_Id form).
202 -- If Lower is set to True then the Name_Buffer will be converted to
203 -- all lower case, for systems where file names are not case sensitive.
204 -- This ensures that gnatbind works correctly regardless of the case
205 -- of the file name on all systems. The termination condition depends
206 -- on the settings of Ignore_Spaces and Ignore_Special:
207 --
208 -- If Ignore_Spaces is False (normal case), then scan is terminated
209 -- by the normal end of field condition (EOL, space, horizontal tab)
210 --
211 -- If Ignore_Special is False (normal case), the scan is terminated by
212 -- a typeref bracket or an equal sign except for the special case of
213 -- an operator name starting with a double quote which is terminated
214 -- by another double quote.
215 --
216 -- It is an error to set both Ignore_Spaces and Ignore_Special to True.
217 -- This function handles wide characters properly.
218
219 function Get_Nat return Nat;
220 -- Skip blanks, then scan out an unsigned integer value in Nat range
221 -- raises ALI_Reading_Error if the encoutered type is not natural.
222
223 function Get_Stamp return Time_Stamp_Type;
224 -- Skip blanks, then scan out a time stamp
225
226 function Get_Unit_Name return Unit_Name_Type;
227 -- Skip blanks, then scan out a file name (name is left in Name_Buffer
228 -- with length in Name_Len, as well as returning a Unit_Name_Type value.
229 -- The case is unchanged and terminated by a normal end of field.
230
231 function Nextc return Character;
232 -- Return current character without modifying pointer P
233
234 procedure Get_Typeref
235 (Current_File_Num : Sdep_Id;
236 Ref : out Tref_Kind;
237 File_Num : out Sdep_Id;
238 Line : out Nat;
239 Ref_Type : out Character;
240 Col : out Nat;
241 Standard_Entity : out Name_Id);
242 -- Parse the definition of a typeref (<...>, {...} or (...))
243
244 procedure Skip_Eol;
245 -- Skip past spaces, then skip past end of line (fatal error if not
246 -- at end of line). Also skips past any following blank lines.
247
248 procedure Skip_Line;
249 -- Skip rest of current line and any following blank lines
250
251 procedure Skip_Space;
252 -- Skip past white space (blanks or horizontal tab)
253
254 procedure Skipc;
255 -- Skip past next character, does not affect value in C. This call
256 -- is like calling Getc and ignoring the returned result.
257
258 ---------------------
259 -- At_End_Of_Field --
260 ---------------------
261
262 function At_End_Of_Field return Boolean is
263 begin
264 return Nextc <= ' ';
265 end At_End_Of_Field;
266
267 ------------
268 -- At_Eol --
269 ------------
270
271 function At_Eol return Boolean is
272 begin
273 return Nextc = EOF or else Nextc = CR or else Nextc = LF;
274 end At_Eol;
275
276 ---------------------------
277 -- Check_At_End_Of_Field --
278 ---------------------------
279
280 procedure Check_At_End_Of_Field is
281 begin
282 if not At_End_Of_Field then
283 if Ignore_Errors then
284 while Nextc > ' ' loop
285 P := P + 1;
286 end loop;
287 else
288 Fatal_Error;
289 end if;
290 end if;
291 end Check_At_End_Of_Field;
292
293 ------------------------
294 -- Check_Unknown_Line --
295 ------------------------
296
297 procedure Check_Unknown_Line is
298 begin
299 while C not in 'A' .. 'Z'
300 or else not Known_ALI_Lines (C)
301 loop
302 if C = CR or else C = LF then
303 Skip_Line;
304 C := Nextc;
305
306 elsif C = EOF then
307 return;
308
309 elsif Ignore_Errors then
310 Skip_Line;
311 C := Getc;
312
313 else
314 Fatal_Error;
315 end if;
316 end loop;
317 end Check_Unknown_Line;
318
319 ------------
320 -- Checkc --
321 ------------
322
323 procedure Checkc (C : Character) is
324 begin
325 if Nextc = C then
326 P := P + 1;
327 elsif Ignore_Errors then
328 P := P + 1;
329 else
330 Fatal_Error;
331 end if;
332 end Checkc;
333
334 -----------------
335 -- Fatal_Error --
336 -----------------
337
338 procedure Fatal_Error is
339 Ptr1 : Text_Ptr;
340 Ptr2 : Text_Ptr;
341 Col : Int;
342
343 procedure Wchar (C : Character);
344 -- Write a single character, replacing horizontal tab by spaces
345
346 procedure Wchar (C : Character) is
347 begin
348 if C = HT then
349 loop
350 Wchar (' ');
351 exit when Col mod 8 = 0;
352 end loop;
353
354 else
355 Write_Char (C);
356 Col := Col + 1;
357 end if;
358 end Wchar;
359
360 -- Start of processing for Fatal_Error
361
362 begin
363 if Err then
364 raise Bad_ALI_Format;
365 end if;
366
367 Set_Standard_Error;
368 Write_Str ("fatal error: file ");
369 Write_Name (F);
370 Write_Str (" is incorrectly formatted");
371 Write_Eol;
372
373 Write_Str ("make sure you are using consistent versions " &
374
375 -- Split the following line so that it can easily be transformed for
376 -- e.g. JVM/.NET back-ends where the compiler has a different name.
377
378 "of gcc/gnatbind");
379
380 Write_Eol;
381
382 -- Find start of line
383
384 Ptr1 := P;
385 while Ptr1 > T'First
386 and then T (Ptr1 - 1) /= CR
387 and then T (Ptr1 - 1) /= LF
388 loop
389 Ptr1 := Ptr1 - 1;
390 end loop;
391
392 Write_Int (Int (Line));
393 Write_Str (". ");
394
395 if Line < 100 then
396 Write_Char (' ');
397 end if;
398
399 if Line < 10 then
400 Write_Char (' ');
401 end if;
402
403 Col := 0;
404 Ptr2 := Ptr1;
405
406 while Ptr2 < T'Last
407 and then T (Ptr2) /= CR
408 and then T (Ptr2) /= LF
409 loop
410 Wchar (T (Ptr2));
411 Ptr2 := Ptr2 + 1;
412 end loop;
413
414 Write_Eol;
415
416 Write_Str (" ");
417 Col := 0;
418
419 while Ptr1 < P loop
420 if T (Ptr1) = HT then
421 Wchar (HT);
422 else
423 Wchar (' ');
424 end if;
425
426 Ptr1 := Ptr1 + 1;
427 end loop;
428
429 Wchar ('|');
430 Write_Eol;
431
432 Exit_Program (E_Fatal);
433 end Fatal_Error;
434
435 ------------------------
436 -- Fatal_Error_Ignore --
437 ------------------------
438
439 procedure Fatal_Error_Ignore is
440 begin
441 if not Ignore_Errors then
442 Fatal_Error;
443 end if;
444 end Fatal_Error_Ignore;
445
446 -------------------
447 -- Get_File_Name --
448 -------------------
449
450 function Get_File_Name
451 (Lower : Boolean := False) return File_Name_Type
452 is
453 F : Name_Id;
454
455 begin
456 F := Get_Name (Ignore_Special => True);
457
458 -- Convert file name to all lower case if file names are not case
459 -- sensitive. This ensures that we handle names in the canonical
460 -- lower case format, regardless of the actual case.
461
462 if Lower and not File_Names_Case_Sensitive then
463 Canonical_Case_File_Name (Name_Buffer (1 .. Name_Len));
464 return Name_Find;
465 else
466 return File_Name_Type (F);
467 end if;
468 end Get_File_Name;
469
470 --------------
471 -- Get_Name --
472 --------------
473
474 function Get_Name
475 (Ignore_Spaces : Boolean := False;
476 Ignore_Special : Boolean := False) return Name_Id
477 is
478 begin
479 Name_Len := 0;
480 Skip_Space;
481
482 if At_Eol then
483 if Ignore_Errors then
484 return Error_Name;
485 else
486 Fatal_Error;
487 end if;
488 end if;
489
490 loop
491 Add_Char_To_Name_Buffer (Getc);
492
493 exit when At_End_Of_Field and then not Ignore_Spaces;
494
495 if not Ignore_Special then
496 if Name_Buffer (1) = '"' then
497 exit when Name_Len > 1 and then Name_Buffer (Name_Len) = '"';
498
499 else
500 -- Terminate on parens or angle brackets or equal sign
501
502 exit when Nextc = '(' or else Nextc = ')'
503 or else Nextc = '{' or else Nextc = '}'
504 or else Nextc = '<' or else Nextc = '>'
505 or else Nextc = '=';
506
507 -- Terminate if left bracket not part of wide char sequence
508 -- Note that we only recognize brackets notation so far ???
509
510 exit when Nextc = '[' and then T (P + 1) /= '"';
511
512 -- Terminate if right bracket not part of wide char sequence
513
514 exit when Nextc = ']' and then T (P - 1) /= '"';
515 end if;
516 end if;
517 end loop;
518
519 return Name_Find;
520 end Get_Name;
521
522 -------------------
523 -- Get_Unit_Name --
524 -------------------
525
526 function Get_Unit_Name return Unit_Name_Type is
527 begin
528 return Unit_Name_Type (Get_Name);
529 end Get_Unit_Name;
530
531 -------------
532 -- Get_Nat --
533 -------------
534
535 function Get_Nat return Nat is
536 V : Nat;
537
538 begin
539 Skip_Space;
540
541 -- Check if we are on a number. In the case of bad ALI files, this
542 -- may not be true.
543
544 if not (Nextc in '0' .. '9') then
545 Fatal_Error;
546 end if;
547
548 V := 0;
549 loop
550 V := V * 10 + (Character'Pos (Getc) - Character'Pos ('0'));
551
552 exit when At_End_Of_Field;
553 exit when Nextc < '0' or else Nextc > '9';
554 end loop;
555
556 return V;
557 end Get_Nat;
558
559 ---------------
560 -- Get_Stamp --
561 ---------------
562
563 function Get_Stamp return Time_Stamp_Type is
564 T : Time_Stamp_Type;
565 Start : Integer;
566
567 begin
568 Skip_Space;
569
570 if At_Eol then
571 if Ignore_Errors then
572 return Dummy_Time_Stamp;
573 else
574 Fatal_Error;
575 end if;
576 end if;
577
578 -- Following reads old style time stamp missing first two digits
579
580 if Nextc in '7' .. '9' then
581 T (1) := '1';
582 T (2) := '9';
583 Start := 3;
584
585 -- Normal case of full year in time stamp
586
587 else
588 Start := 1;
589 end if;
590
591 for J in Start .. T'Last loop
592 T (J) := Getc;
593 end loop;
594
595 return T;
596 end Get_Stamp;
597
598 -----------------
599 -- Get_Typeref --
600 -----------------
601
602 procedure Get_Typeref
603 (Current_File_Num : Sdep_Id;
604 Ref : out Tref_Kind;
605 File_Num : out Sdep_Id;
606 Line : out Nat;
607 Ref_Type : out Character;
608 Col : out Nat;
609 Standard_Entity : out Name_Id)
610 is
611 N : Nat;
612 begin
613 case Nextc is
614 when '<' => Ref := Tref_Derived;
615 when '(' => Ref := Tref_Access;
616 when '{' => Ref := Tref_Type;
617 when others => Ref := Tref_None;
618 end case;
619
620 -- Case of typeref field present
621
622 if Ref /= Tref_None then
623 P := P + 1; -- skip opening bracket
624
625 if Nextc in 'a' .. 'z' then
626 File_Num := No_Sdep_Id;
627 Line := 0;
628 Ref_Type := ' ';
629 Col := 0;
630 Standard_Entity := Get_Name (Ignore_Spaces => True);
631 else
632 N := Get_Nat;
633
634 if Nextc = '|' then
635 File_Num := Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
636 P := P + 1;
637 N := Get_Nat;
638 else
639 File_Num := Current_File_Num;
640 end if;
641
642 Line := N;
643 Ref_Type := Getc;
644 Col := Get_Nat;
645 Standard_Entity := No_Name;
646 end if;
647
648 -- ??? Temporary workaround for nested generics case:
649 -- 4i4 Directories{1|4I9[4|6[3|3]]}
650 -- See C918-002
651
652 declare
653 Nested_Brackets : Natural := 0;
654
655 begin
656 loop
657 case Nextc is
658 when '[' =>
659 Nested_Brackets := Nested_Brackets + 1;
660 when ']' =>
661 Nested_Brackets := Nested_Brackets - 1;
662 when others =>
663 if Nested_Brackets = 0 then
664 exit;
665 end if;
666 end case;
667
668 Skipc;
669 end loop;
670 end;
671
672 P := P + 1; -- skip closing bracket
673 Skip_Space;
674
675 -- No typeref entry present
676
677 else
678 File_Num := No_Sdep_Id;
679 Line := 0;
680 Ref_Type := ' ';
681 Col := 0;
682 Standard_Entity := No_Name;
683 end if;
684 end Get_Typeref;
685
686 ----------
687 -- Getc --
688 ----------
689
690 function Getc return Character is
691 begin
692 if P = T'Last then
693 return EOF;
694 else
695 P := P + 1;
696 return T (P - 1);
697 end if;
698 end Getc;
699
700 -----------
701 -- Nextc --
702 -----------
703
704 function Nextc return Character is
705 begin
706 return T (P);
707 end Nextc;
708
709 --------------
710 -- Skip_Eol --
711 --------------
712
713 procedure Skip_Eol is
714 begin
715 Skip_Space;
716
717 if not At_Eol then
718 if Ignore_Errors then
719 while not At_Eol loop
720 P := P + 1;
721 end loop;
722 else
723 Fatal_Error;
724 end if;
725 end if;
726
727 -- Loop to skip past blank lines (first time through skips this EOL)
728
729 while Nextc < ' ' and then Nextc /= EOF loop
730 if Nextc = LF then
731 Line := Line + 1;
732 end if;
733
734 P := P + 1;
735 end loop;
736 end Skip_Eol;
737
738 ---------------
739 -- Skip_Line --
740 ---------------
741
742 procedure Skip_Line is
743 begin
744 while not At_Eol loop
745 P := P + 1;
746 end loop;
747
748 Skip_Eol;
749 end Skip_Line;
750
751 ----------------
752 -- Skip_Space --
753 ----------------
754
755 procedure Skip_Space is
756 begin
757 while Nextc = ' ' or else Nextc = HT loop
758 P := P + 1;
759 end loop;
760 end Skip_Space;
761
762 -----------
763 -- Skipc --
764 -----------
765
766 procedure Skipc is
767 begin
768 if P /= T'Last then
769 P := P + 1;
770 end if;
771 end Skipc;
772
773 -- Start of processing for Scan_ALI
774
775 begin
776 First_Sdep_Entry := Sdep.Last + 1;
777
778 -- Acquire lines to be ignored
779
780 if Read_Xref then
781 Ignore := ('U' | 'W' | 'Y' | 'D' | 'X' => False, others => True);
782
783 -- Read_Lines parameter given
784
785 elsif Read_Lines /= "" then
786 Ignore := ('U' => False, others => True);
787
788 for J in Read_Lines'Range loop
789 Ignore (Read_Lines (J)) := False;
790 end loop;
791
792 -- Process Ignore_Lines parameter
793
794 else
795 Ignore := (others => False);
796
797 for J in Ignore_Lines'Range loop
798 pragma Assert (Ignore_Lines (J) /= 'U');
799 Ignore (Ignore_Lines (J)) := True;
800 end loop;
801 end if;
802
803 -- Setup ALI Table entry with appropriate defaults
804
805 ALIs.Increment_Last;
806 Id := ALIs.Last;
807 Set_Name_Table_Info (F, Int (Id));
808
809 ALIs.Table (Id) := (
810 Afile => F,
811 Compile_Errors => False,
812 First_Interrupt_State => Interrupt_States.Last + 1,
813 First_Sdep => No_Sdep_Id,
814 First_Specific_Dispatching => Specific_Dispatching.Last + 1,
815 First_Unit => No_Unit_Id,
816 Float_Format => 'I',
817 Last_Interrupt_State => Interrupt_States.Last,
818 Last_Sdep => No_Sdep_Id,
819 Last_Specific_Dispatching => Specific_Dispatching.Last,
820 Last_Unit => No_Unit_Id,
821 Locking_Policy => ' ',
822 Main_Priority => -1,
823 Main_CPU => -1,
824 Main_Program => None,
825 No_Object => False,
826 Normalize_Scalars => False,
827 Ofile_Full_Name => Full_Object_File_Name,
828 Queuing_Policy => ' ',
829 Restrictions => No_Restrictions,
830 SAL_Interface => False,
831 Sfile => No_File,
832 Task_Dispatching_Policy => ' ',
833 Time_Slice_Value => -1,
834 Allocator_In_Body => False,
835 WC_Encoding => 'b',
836 Unit_Exception_Table => False,
837 Ver => (others => ' '),
838 Ver_Len => 0,
839 Zero_Cost_Exceptions => False);
840
841 -- Now we acquire the input lines from the ALI file. Note that the
842 -- convention in the following code is that as we enter each section,
843 -- C is set to contain the first character of the following line.
844
845 C := Getc;
846 Check_Unknown_Line;
847
848 -- Acquire library version
849
850 if C /= 'V' then
851
852 -- The V line missing really indicates trouble, most likely it
853 -- means we don't have an ALI file at all, so here we give a
854 -- fatal error even if we are in Ignore_Errors mode.
855
856 Fatal_Error;
857
858 elsif Ignore ('V') then
859 Skip_Line;
860
861 else
862 Checkc (' ');
863 Skip_Space;
864 Checkc ('"');
865
866 for J in 1 .. Ver_Len_Max loop
867 C := Getc;
868 exit when C = '"';
869 ALIs.Table (Id).Ver (J) := C;
870 ALIs.Table (Id).Ver_Len := J;
871 end loop;
872
873 Skip_Eol;
874 end if;
875
876 C := Getc;
877 Check_Unknown_Line;
878
879 -- Acquire main program line if present
880
881 if C = 'M' then
882 if Ignore ('M') then
883 Skip_Line;
884
885 else
886 Checkc (' ');
887 Skip_Space;
888
889 C := Getc;
890
891 if C = 'F' then
892 ALIs.Table (Id).Main_Program := Func;
893 elsif C = 'P' then
894 ALIs.Table (Id).Main_Program := Proc;
895 else
896 P := P - 1;
897 Fatal_Error;
898 end if;
899
900 Skip_Space;
901
902 if not At_Eol then
903 if Nextc < 'A' then
904 ALIs.Table (Id).Main_Priority := Get_Nat;
905 end if;
906
907 Skip_Space;
908
909 if Nextc = 'T' then
910 P := P + 1;
911 Checkc ('=');
912 ALIs.Table (Id).Time_Slice_Value := Get_Nat;
913 end if;
914
915 Skip_Space;
916
917 if Nextc = 'A' then
918 P := P + 1;
919 Checkc ('B');
920 ALIs.Table (Id).Allocator_In_Body := True;
921 end if;
922
923 Skip_Space;
924
925 if Nextc = 'C' then
926 P := P + 1;
927 Checkc ('=');
928 ALIs.Table (Id).Main_CPU := Get_Nat;
929 end if;
930
931 Skip_Space;
932
933 Checkc ('W');
934 Checkc ('=');
935 ALIs.Table (Id).WC_Encoding := Getc;
936 end if;
937
938 Skip_Eol;
939 end if;
940
941 C := Getc;
942 end if;
943
944 -- Acquire argument lines
945
946 First_Arg := Args.Last + 1;
947
948 A_Loop : loop
949 Check_Unknown_Line;
950 exit A_Loop when C /= 'A';
951
952 if Ignore ('A') then
953 Skip_Line;
954
955 else
956 Checkc (' ');
957
958 -- Scan out argument
959
960 Name_Len := 0;
961 while not At_Eol loop
962 Add_Char_To_Name_Buffer (Getc);
963 end loop;
964
965 -- If -fstack-check, record that it occurred
966
967 if Name_Buffer (1 .. Name_Len) = "-fstack-check" then
968 Stack_Check_Switch_Set := True;
969 end if;
970
971 -- Store the argument
972
973 Args.Increment_Last;
974 Args.Table (Args.Last) := new String'(Name_Buffer (1 .. Name_Len));
975
976 Skip_Eol;
977 end if;
978
979 C := Getc;
980 end loop A_Loop;
981
982 -- Acquire P line
983
984 Check_Unknown_Line;
985
986 while C /= 'P' loop
987 if Ignore_Errors then
988 if C = EOF then
989 Fatal_Error;
990 else
991 Skip_Line;
992 C := Nextc;
993 end if;
994 else
995 Fatal_Error;
996 end if;
997 end loop;
998
999 if Ignore ('P') then
1000 Skip_Line;
1001
1002 -- Process P line
1003
1004 else
1005 NS_Found := False;
1006
1007 while not At_Eol loop
1008 Checkc (' ');
1009 Skip_Space;
1010 C := Getc;
1011
1012 -- Processing for CE
1013
1014 if C = 'C' then
1015 Checkc ('E');
1016 ALIs.Table (Id).Compile_Errors := True;
1017
1018 -- Processing for DB
1019
1020 elsif C = 'D' then
1021 Checkc ('B');
1022 Detect_Blocking := True;
1023
1024 -- Processing for FD/FG/FI
1025
1026 elsif C = 'F' then
1027 Float_Format_Specified := Getc;
1028 ALIs.Table (Id).Float_Format := Float_Format_Specified;
1029
1030 -- Processing for Lx
1031
1032 elsif C = 'L' then
1033 Locking_Policy_Specified := Getc;
1034 ALIs.Table (Id).Locking_Policy := Locking_Policy_Specified;
1035
1036 -- Processing for flags starting with N
1037
1038 elsif C = 'N' then
1039 C := Getc;
1040
1041 -- Processing for NO
1042
1043 if C = 'O' then
1044 ALIs.Table (Id).No_Object := True;
1045 No_Object_Specified := True;
1046
1047 -- Processing for NR
1048
1049 elsif C = 'R' then
1050 No_Run_Time_Mode := True;
1051 Configurable_Run_Time_Mode := True;
1052
1053 -- Processing for NS
1054
1055 elsif C = 'S' then
1056 ALIs.Table (Id).Normalize_Scalars := True;
1057 Normalize_Scalars_Specified := True;
1058 NS_Found := True;
1059
1060 -- Invalid switch starting with N
1061
1062 else
1063 Fatal_Error_Ignore;
1064 end if;
1065
1066 -- Processing for Qx
1067
1068 elsif C = 'Q' then
1069 Queuing_Policy_Specified := Getc;
1070 ALIs.Table (Id).Queuing_Policy := Queuing_Policy_Specified;
1071
1072 -- Processing for flags starting with S
1073
1074 elsif C = 'S' then
1075 C := Getc;
1076
1077 -- Processing for SL
1078
1079 if C = 'L' then
1080 ALIs.Table (Id).SAL_Interface := True;
1081
1082 -- Processing for SS
1083
1084 elsif C = 'S' then
1085 Opt.Sec_Stack_Used := True;
1086
1087 -- Invalid switch starting with S
1088
1089 else
1090 Fatal_Error_Ignore;
1091 end if;
1092
1093 -- Processing for Tx
1094
1095 elsif C = 'T' then
1096 Task_Dispatching_Policy_Specified := Getc;
1097 ALIs.Table (Id).Task_Dispatching_Policy :=
1098 Task_Dispatching_Policy_Specified;
1099
1100 -- Processing for switch starting with U
1101
1102 elsif C = 'U' then
1103 C := Getc;
1104
1105 -- Processing for UA
1106
1107 if C = 'A' then
1108 Unreserve_All_Interrupts_Specified := True;
1109
1110 -- Processing for UX
1111
1112 elsif C = 'X' then
1113 ALIs.Table (Id).Unit_Exception_Table := True;
1114
1115 -- Invalid switches starting with U
1116
1117 else
1118 Fatal_Error_Ignore;
1119 end if;
1120
1121 -- Processing for ZX
1122
1123 elsif C = 'Z' then
1124 C := Getc;
1125
1126 if C = 'X' then
1127 ALIs.Table (Id).Zero_Cost_Exceptions := True;
1128 Zero_Cost_Exceptions_Specified := True;
1129 else
1130 Fatal_Error_Ignore;
1131 end if;
1132
1133 -- Invalid parameter
1134
1135 else
1136 C := Getc;
1137 Fatal_Error_Ignore;
1138 end if;
1139 end loop;
1140
1141 if not NS_Found then
1142 No_Normalize_Scalars_Specified := True;
1143 end if;
1144
1145 Skip_Eol;
1146 end if;
1147
1148 C := Getc;
1149 Check_Unknown_Line;
1150
1151 -- Acquire first restrictions line
1152
1153 while C /= 'R' loop
1154 if Ignore_Errors then
1155 if C = EOF then
1156 Fatal_Error;
1157 else
1158 Skip_Line;
1159 C := Nextc;
1160 end if;
1161 else
1162 Fatal_Error;
1163 end if;
1164 end loop;
1165
1166 if Ignore ('R') then
1167 Skip_Line;
1168
1169 -- Process restrictions line
1170
1171 else
1172 Scan_Restrictions : declare
1173 Save_R : constant Restrictions_Info := Cumulative_Restrictions;
1174 -- Save cumulative restrictions in case we have a fatal error
1175
1176 Bad_R_Line : exception;
1177 -- Signal bad restrictions line (raised on unexpected character)
1178
1179 begin
1180 Checkc (' ');
1181 Skip_Space;
1182
1183 -- Acquire information for boolean restrictions
1184
1185 for R in All_Boolean_Restrictions loop
1186 C := Getc;
1187
1188 case C is
1189 when 'v' =>
1190 ALIs.Table (Id).Restrictions.Violated (R) := True;
1191 Cumulative_Restrictions.Violated (R) := True;
1192
1193 when 'r' =>
1194 ALIs.Table (Id).Restrictions.Set (R) := True;
1195 Cumulative_Restrictions.Set (R) := True;
1196
1197 when 'n' =>
1198 null;
1199
1200 when others =>
1201 raise Bad_R_Line;
1202 end case;
1203 end loop;
1204
1205 -- Acquire information for parameter restrictions
1206
1207 for RP in All_Parameter_Restrictions loop
1208
1209 -- Acquire restrictions pragma information
1210
1211 case Getc is
1212 when 'n' =>
1213 null;
1214
1215 when 'r' =>
1216 ALIs.Table (Id).Restrictions.Set (RP) := True;
1217
1218 declare
1219 N : constant Integer := Integer (Get_Nat);
1220 begin
1221 ALIs.Table (Id).Restrictions.Value (RP) := N;
1222
1223 if Cumulative_Restrictions.Set (RP) then
1224 Cumulative_Restrictions.Value (RP) :=
1225 Integer'Min
1226 (Cumulative_Restrictions.Value (RP), N);
1227 else
1228 Cumulative_Restrictions.Set (RP) := True;
1229 Cumulative_Restrictions.Value (RP) := N;
1230 end if;
1231 end;
1232
1233 when others =>
1234 raise Bad_R_Line;
1235 end case;
1236
1237 -- Acquire restrictions violations information
1238
1239 case Getc is
1240 when 'n' =>
1241 null;
1242
1243 when 'v' =>
1244 ALIs.Table (Id).Restrictions.Violated (RP) := True;
1245 Cumulative_Restrictions.Violated (RP) := True;
1246
1247 declare
1248 N : constant Integer := Integer (Get_Nat);
1249 pragma Unsuppress (Overflow_Check);
1250
1251 begin
1252 ALIs.Table (Id).Restrictions.Count (RP) := N;
1253
1254 if RP in Checked_Max_Parameter_Restrictions then
1255 Cumulative_Restrictions.Count (RP) :=
1256 Integer'Max
1257 (Cumulative_Restrictions.Count (RP), N);
1258 else
1259 Cumulative_Restrictions.Count (RP) :=
1260 Cumulative_Restrictions.Count (RP) + N;
1261 end if;
1262
1263 exception
1264 when Constraint_Error =>
1265
1266 -- A constraint error comes from the addition in
1267 -- the else branch. We reset to the maximum and
1268 -- indicate that the real value is now unknown.
1269
1270 Cumulative_Restrictions.Value (RP) := Integer'Last;
1271 Cumulative_Restrictions.Unknown (RP) := True;
1272 end;
1273
1274 if Nextc = '+' then
1275 Skipc;
1276 ALIs.Table (Id).Restrictions.Unknown (RP) := True;
1277 Cumulative_Restrictions.Unknown (RP) := True;
1278 end if;
1279
1280 when others =>
1281 raise Bad_R_Line;
1282 end case;
1283 end loop;
1284
1285 Skip_Eol;
1286
1287 -- Here if error during scanning of restrictions line
1288
1289 exception
1290 when Bad_R_Line =>
1291
1292 -- In Ignore_Errors mode, undo any changes to restrictions
1293 -- from this unit, and continue on.
1294
1295 if Ignore_Errors then
1296 Cumulative_Restrictions := Save_R;
1297 ALIs.Table (Id).Restrictions := No_Restrictions;
1298 Skip_Eol;
1299
1300 -- In normal mode, this is a fatal error
1301
1302 else
1303 Fatal_Error;
1304 end if;
1305
1306 end Scan_Restrictions;
1307 end if;
1308
1309 -- Acquire additional restrictions (No_Dependence) lines if present
1310
1311 C := Getc;
1312 while C = 'R' loop
1313 if Ignore ('R') then
1314 Skip_Line;
1315 else
1316 Skip_Space;
1317 No_Deps.Append ((Id, Get_Name));
1318 Skip_Eol;
1319 end if;
1320
1321 C := Getc;
1322 end loop;
1323
1324 -- Acquire 'I' lines if present
1325
1326 Check_Unknown_Line;
1327
1328 while C = 'I' loop
1329 if Ignore ('I') then
1330 Skip_Line;
1331
1332 else
1333 declare
1334 Int_Num : Nat;
1335 I_State : Character;
1336 Line_No : Nat;
1337
1338 begin
1339 Int_Num := Get_Nat;
1340 Skip_Space;
1341 I_State := Getc;
1342 Line_No := Get_Nat;
1343
1344 Interrupt_States.Append (
1345 (Interrupt_Id => Int_Num,
1346 Interrupt_State => I_State,
1347 IS_Pragma_Line => Line_No));
1348
1349 ALIs.Table (Id).Last_Interrupt_State := Interrupt_States.Last;
1350 Skip_Eol;
1351 end;
1352 end if;
1353
1354 C := Getc;
1355 end loop;
1356
1357 -- Acquire 'S' lines if present
1358
1359 Check_Unknown_Line;
1360
1361 while C = 'S' loop
1362 if Ignore ('S') then
1363 Skip_Line;
1364
1365 else
1366 declare
1367 Policy : Character;
1368 First_Prio : Nat;
1369 Last_Prio : Nat;
1370 Line_No : Nat;
1371
1372 begin
1373 Checkc (' ');
1374 Skip_Space;
1375
1376 Policy := Getc;
1377 Skip_Space;
1378 First_Prio := Get_Nat;
1379 Last_Prio := Get_Nat;
1380 Line_No := Get_Nat;
1381
1382 Specific_Dispatching.Append (
1383 (Dispatching_Policy => Policy,
1384 First_Priority => First_Prio,
1385 Last_Priority => Last_Prio,
1386 PSD_Pragma_Line => Line_No));
1387
1388 ALIs.Table (Id).Last_Specific_Dispatching :=
1389 Specific_Dispatching.Last;
1390
1391 Skip_Eol;
1392 end;
1393 end if;
1394
1395 C := Getc;
1396 end loop;
1397
1398 -- Loop to acquire unit entries
1399
1400 U_Loop : loop
1401 Check_Unknown_Line;
1402 exit U_Loop when C /= 'U';
1403
1404 -- Note: as per spec, we never ignore U lines
1405
1406 Checkc (' ');
1407 Skip_Space;
1408 Units.Increment_Last;
1409
1410 if ALIs.Table (Id).First_Unit = No_Unit_Id then
1411 ALIs.Table (Id).First_Unit := Units.Last;
1412 end if;
1413
1414 declare
1415 UL : Unit_Record renames Units.Table (Units.Last);
1416
1417 begin
1418 UL.Uname := Get_Unit_Name;
1419 UL.Predefined := Is_Predefined_Unit;
1420 UL.Internal := Is_Internal_Unit;
1421 UL.My_ALI := Id;
1422 UL.Sfile := Get_File_Name (Lower => True);
1423 UL.Pure := False;
1424 UL.Preelab := False;
1425 UL.No_Elab := False;
1426 UL.Shared_Passive := False;
1427 UL.RCI := False;
1428 UL.Remote_Types := False;
1429 UL.Has_RACW := False;
1430 UL.Init_Scalars := False;
1431 UL.Is_Generic := False;
1432 UL.Icasing := Mixed_Case;
1433 UL.Kcasing := All_Lower_Case;
1434 UL.Dynamic_Elab := False;
1435 UL.Elaborate_Body := False;
1436 UL.Set_Elab_Entity := False;
1437 UL.Version := "00000000";
1438 UL.First_With := Withs.Last + 1;
1439 UL.First_Arg := First_Arg;
1440 UL.Elab_Position := 0;
1441 UL.SAL_Interface := ALIs.Table (Id).SAL_Interface;
1442 UL.Directly_Scanned := Directly_Scanned;
1443 UL.Body_Needed_For_SAL := False;
1444 UL.Elaborate_Body_Desirable := False;
1445 UL.Optimize_Alignment := 'O';
1446 UL.Has_Finalizer := False;
1447
1448 if Debug_Flag_U then
1449 Write_Str (" ----> reading unit ");
1450 Write_Int (Int (Units.Last));
1451 Write_Str (" ");
1452 Write_Unit_Name (UL.Uname);
1453 Write_Str (" from file ");
1454 Write_Name (UL.Sfile);
1455 Write_Eol;
1456 end if;
1457 end;
1458
1459 -- Check for duplicated unit in different files
1460
1461 declare
1462 Info : constant Int := Get_Name_Table_Info
1463 (Units.Table (Units.Last).Uname);
1464 begin
1465 if Info /= 0
1466 and then Units.Table (Units.Last).Sfile /=
1467 Units.Table (Unit_Id (Info)).Sfile
1468 then
1469 -- If Err is set then ignore duplicate unit name. This is the
1470 -- case of a call from gnatmake, where the situation can arise
1471 -- from substitution of source files. In such situations, the
1472 -- processing in gnatmake will always result in any required
1473 -- recompilations in any case, and if we consider this to be
1474 -- an error we get strange cases (for example when a generic
1475 -- instantiation is replaced by a normal package) where we
1476 -- read the old ali file, decide to recompile, and then decide
1477 -- that the old and new ali files are incompatible.
1478
1479 if Err then
1480 null;
1481
1482 -- If Err is not set, then this is a fatal error. This is
1483 -- the case of being called from the binder, where we must
1484 -- definitely diagnose this as an error.
1485
1486 else
1487 Set_Standard_Error;
1488 Write_Str ("error: duplicate unit name: ");
1489 Write_Eol;
1490
1491 Write_Str ("error: unit """);
1492 Write_Unit_Name (Units.Table (Units.Last).Uname);
1493 Write_Str (""" found in file """);
1494 Write_Name_Decoded (Units.Table (Units.Last).Sfile);
1495 Write_Char ('"');
1496 Write_Eol;
1497
1498 Write_Str ("error: unit """);
1499 Write_Unit_Name (Units.Table (Unit_Id (Info)).Uname);
1500 Write_Str (""" found in file """);
1501 Write_Name_Decoded (Units.Table (Unit_Id (Info)).Sfile);
1502 Write_Char ('"');
1503 Write_Eol;
1504
1505 Exit_Program (E_Fatal);
1506 end if;
1507 end if;
1508 end;
1509
1510 Set_Name_Table_Info
1511 (Units.Table (Units.Last).Uname, Int (Units.Last));
1512
1513 -- Scan out possible version and other parameters
1514
1515 loop
1516 Skip_Space;
1517 exit when At_Eol;
1518 C := Getc;
1519
1520 -- Version field
1521
1522 if C in '0' .. '9' or else C in 'a' .. 'f' then
1523 Units.Table (Units.Last).Version (1) := C;
1524
1525 for J in 2 .. 8 loop
1526 C := Getc;
1527 Units.Table (Units.Last).Version (J) := C;
1528 end loop;
1529
1530 -- BD/BN parameters
1531
1532 elsif C = 'B' then
1533 C := Getc;
1534
1535 if C = 'D' then
1536 Check_At_End_Of_Field;
1537 Units.Table (Units.Last).Elaborate_Body_Desirable := True;
1538
1539 elsif C = 'N' then
1540 Check_At_End_Of_Field;
1541 Units.Table (Units.Last).Body_Needed_For_SAL := True;
1542
1543 else
1544 Fatal_Error_Ignore;
1545 end if;
1546
1547 -- DE parameter (Dynamic elaboration checks)
1548
1549 elsif C = 'D' then
1550 C := Getc;
1551
1552 if C = 'E' then
1553 Check_At_End_Of_Field;
1554 Units.Table (Units.Last).Dynamic_Elab := True;
1555 Dynamic_Elaboration_Checks_Specified := True;
1556 else
1557 Fatal_Error_Ignore;
1558 end if;
1559
1560 -- EB/EE parameters
1561
1562 elsif C = 'E' then
1563 C := Getc;
1564
1565 if C = 'B' then
1566 Units.Table (Units.Last).Elaborate_Body := True;
1567 elsif C = 'E' then
1568 Units.Table (Units.Last).Set_Elab_Entity := True;
1569 else
1570 Fatal_Error_Ignore;
1571 end if;
1572
1573 Check_At_End_Of_Field;
1574
1575 -- GE parameter (generic)
1576
1577 elsif C = 'G' then
1578 C := Getc;
1579
1580 if C = 'E' then
1581 Check_At_End_Of_Field;
1582 Units.Table (Units.Last).Is_Generic := True;
1583 else
1584 Fatal_Error_Ignore;
1585 end if;
1586
1587 -- IL/IS/IU parameters
1588
1589 elsif C = 'I' then
1590 C := Getc;
1591
1592 if C = 'L' then
1593 Units.Table (Units.Last).Icasing := All_Lower_Case;
1594 elsif C = 'S' then
1595 Units.Table (Units.Last).Init_Scalars := True;
1596 Initialize_Scalars_Used := True;
1597 elsif C = 'U' then
1598 Units.Table (Units.Last).Icasing := All_Upper_Case;
1599 else
1600 Fatal_Error_Ignore;
1601 end if;
1602
1603 Check_At_End_Of_Field;
1604
1605 -- KM/KU parameters
1606
1607 elsif C = 'K' then
1608 C := Getc;
1609
1610 if C = 'M' then
1611 Units.Table (Units.Last).Kcasing := Mixed_Case;
1612 elsif C = 'U' then
1613 Units.Table (Units.Last).Kcasing := All_Upper_Case;
1614 else
1615 Fatal_Error_Ignore;
1616 end if;
1617
1618 Check_At_End_Of_Field;
1619
1620 -- NE parameter
1621
1622 elsif C = 'N' then
1623 C := Getc;
1624
1625 if C = 'E' then
1626 Units.Table (Units.Last).No_Elab := True;
1627 Check_At_End_Of_Field;
1628 else
1629 Fatal_Error_Ignore;
1630 end if;
1631
1632 -- PF/PR/PU/PK parameters
1633
1634 elsif C = 'P' then
1635 C := Getc;
1636
1637 if C = 'F' then
1638 Units.Table (Units.Last).Has_Finalizer := True;
1639 elsif C = 'R' then
1640 Units.Table (Units.Last).Preelab := True;
1641 elsif C = 'U' then
1642 Units.Table (Units.Last).Pure := True;
1643 elsif C = 'K' then
1644 Units.Table (Units.Last).Unit_Kind := 'p';
1645 else
1646 Fatal_Error_Ignore;
1647 end if;
1648
1649 Check_At_End_Of_Field;
1650
1651 -- OL/OO/OS/OT parameters
1652
1653 elsif C = 'O' then
1654 C := Getc;
1655
1656 if C = 'L' or else C = 'O' or else C = 'S' or else C = 'T' then
1657 Units.Table (Units.Last).Optimize_Alignment := C;
1658 else
1659 Fatal_Error_Ignore;
1660 end if;
1661
1662 Check_At_End_Of_Field;
1663
1664 -- RC/RT parameters
1665
1666 elsif C = 'R' then
1667 C := Getc;
1668
1669 if C = 'C' then
1670 Units.Table (Units.Last).RCI := True;
1671 elsif C = 'T' then
1672 Units.Table (Units.Last).Remote_Types := True;
1673 elsif C = 'A' then
1674 Units.Table (Units.Last).Has_RACW := True;
1675 else
1676 Fatal_Error_Ignore;
1677 end if;
1678
1679 Check_At_End_Of_Field;
1680
1681 elsif C = 'S' then
1682 C := Getc;
1683
1684 if C = 'P' then
1685 Units.Table (Units.Last).Shared_Passive := True;
1686 elsif C = 'U' then
1687 Units.Table (Units.Last).Unit_Kind := 's';
1688 else
1689 Fatal_Error_Ignore;
1690 end if;
1691
1692 Check_At_End_Of_Field;
1693
1694 else
1695 C := Getc;
1696 Fatal_Error_Ignore;
1697 end if;
1698 end loop;
1699
1700 Skip_Eol;
1701
1702 -- Check if static elaboration model used
1703
1704 if not Units.Table (Units.Last).Dynamic_Elab
1705 and then not Units.Table (Units.Last).Internal
1706 then
1707 Static_Elaboration_Model_Used := True;
1708 end if;
1709
1710 C := Getc;
1711
1712 -- Scan out With lines for this unit
1713
1714 With_Loop : loop
1715 Check_Unknown_Line;
1716 exit With_Loop when C /= 'W' and then C /= 'Y';
1717
1718 if Ignore ('W') then
1719 Skip_Line;
1720
1721 else
1722 Checkc (' ');
1723 Skip_Space;
1724 Withs.Increment_Last;
1725 Withs.Table (Withs.Last).Uname := Get_Unit_Name;
1726 Withs.Table (Withs.Last).Elaborate := False;
1727 Withs.Table (Withs.Last).Elaborate_All := False;
1728 Withs.Table (Withs.Last).Elab_Desirable := False;
1729 Withs.Table (Withs.Last).Elab_All_Desirable := False;
1730 Withs.Table (Withs.Last).SAL_Interface := False;
1731 Withs.Table (Withs.Last).Limited_With := (C = 'Y');
1732
1733 -- Generic case with no object file available
1734
1735 if At_Eol then
1736 Withs.Table (Withs.Last).Sfile := No_File;
1737 Withs.Table (Withs.Last).Afile := No_File;
1738
1739 -- Normal case
1740
1741 else
1742 Withs.Table (Withs.Last).Sfile := Get_File_Name
1743 (Lower => True);
1744 Withs.Table (Withs.Last).Afile := Get_File_Name
1745 (Lower => True);
1746
1747 -- Scan out possible E, EA, ED, and AD parameters
1748
1749 while not At_Eol loop
1750 Skip_Space;
1751
1752 if Nextc = 'A' then
1753 P := P + 1;
1754 Checkc ('D');
1755 Check_At_End_Of_Field;
1756
1757 -- Store AD indication unless ignore required
1758
1759 if not Ignore_ED then
1760 Withs.Table (Withs.Last).Elab_All_Desirable :=
1761 True;
1762 end if;
1763
1764 elsif Nextc = 'E' then
1765 P := P + 1;
1766
1767 if At_End_Of_Field then
1768 Withs.Table (Withs.Last).Elaborate := True;
1769
1770 elsif Nextc = 'A' then
1771 P := P + 1;
1772 Check_At_End_Of_Field;
1773 Withs.Table (Withs.Last).Elaborate_All := True;
1774
1775 else
1776 Checkc ('D');
1777 Check_At_End_Of_Field;
1778
1779 -- Store ED indication unless ignore required
1780
1781 if not Ignore_ED then
1782 Withs.Table (Withs.Last).Elab_Desirable :=
1783 True;
1784 end if;
1785 end if;
1786
1787 else
1788 Fatal_Error;
1789 end if;
1790 end loop;
1791 end if;
1792
1793 Skip_Eol;
1794 end if;
1795
1796 C := Getc;
1797 end loop With_Loop;
1798
1799 Units.Table (Units.Last).Last_With := Withs.Last;
1800 Units.Table (Units.Last).Last_Arg := Args.Last;
1801
1802 -- If there are linker options lines present, scan them
1803
1804 Name_Len := 0;
1805
1806 Linker_Options_Loop : loop
1807 Check_Unknown_Line;
1808 exit Linker_Options_Loop when C /= 'L';
1809
1810 if Ignore ('L') then
1811 Skip_Line;
1812
1813 else
1814 Checkc (' ');
1815 Skip_Space;
1816 Checkc ('"');
1817
1818 loop
1819 C := Getc;
1820
1821 if C < Character'Val (16#20#)
1822 or else C > Character'Val (16#7E#)
1823 then
1824 Fatal_Error_Ignore;
1825
1826 elsif C = '{' then
1827 C := Character'Val (0);
1828
1829 declare
1830 V : Natural;
1831
1832 begin
1833 V := 0;
1834 for J in 1 .. 2 loop
1835 C := Getc;
1836
1837 if C in '0' .. '9' then
1838 V := V * 16 +
1839 Character'Pos (C) -
1840 Character'Pos ('0');
1841
1842 elsif C in 'A' .. 'F' then
1843 V := V * 16 +
1844 Character'Pos (C) -
1845 Character'Pos ('A') +
1846 10;
1847
1848 else
1849 Fatal_Error_Ignore;
1850 end if;
1851 end loop;
1852
1853 Checkc ('}');
1854 Add_Char_To_Name_Buffer (Character'Val (V));
1855 end;
1856
1857 else
1858 if C = '"' then
1859 exit when Nextc /= '"';
1860 C := Getc;
1861 end if;
1862
1863 Add_Char_To_Name_Buffer (C);
1864 end if;
1865 end loop;
1866
1867 Add_Char_To_Name_Buffer (NUL);
1868 Skip_Eol;
1869 end if;
1870
1871 C := Getc;
1872 end loop Linker_Options_Loop;
1873
1874 -- Store the linker options entry if one was found
1875
1876 if Name_Len /= 0 then
1877 Linker_Options.Increment_Last;
1878
1879 Linker_Options.Table (Linker_Options.Last).Name :=
1880 Name_Enter;
1881
1882 Linker_Options.Table (Linker_Options.Last).Unit :=
1883 Units.Last;
1884
1885 Linker_Options.Table (Linker_Options.Last).Internal_File :=
1886 Is_Internal_File_Name (F);
1887
1888 Linker_Options.Table (Linker_Options.Last).Original_Pos :=
1889 Linker_Options.Last;
1890 end if;
1891
1892 -- If there are notes present, scan them
1893
1894 Notes_Loop : loop
1895 Check_Unknown_Line;
1896 exit Notes_Loop when C /= 'N';
1897
1898 if Ignore ('N') then
1899 Skip_Line;
1900
1901 else
1902 Checkc (' ');
1903
1904 Notes.Increment_Last;
1905 Notes.Table (Notes.Last).Pragma_Type := Getc;
1906 Notes.Table (Notes.Last).Pragma_Line := Get_Nat;
1907 Checkc (':');
1908 Notes.Table (Notes.Last).Pragma_Col := Get_Nat;
1909 Notes.Table (Notes.Last).Unit := Units.Last;
1910
1911 if At_Eol then
1912 Notes.Table (Notes.Last).Pragma_Args := No_Name;
1913
1914 else
1915 Checkc (' ');
1916
1917 Name_Len := 0;
1918 while not At_Eol loop
1919 Add_Char_To_Name_Buffer (Getc);
1920 end loop;
1921
1922 Notes.Table (Notes.Last).Pragma_Args := Name_Enter;
1923 end if;
1924
1925 Skip_Eol;
1926 end if;
1927
1928 C := Getc;
1929 end loop Notes_Loop;
1930 end loop U_Loop;
1931
1932 -- End loop through units for one ALI file
1933
1934 ALIs.Table (Id).Last_Unit := Units.Last;
1935 ALIs.Table (Id).Sfile := Units.Table (ALIs.Table (Id).First_Unit).Sfile;
1936
1937 -- Set types of the units (there can be at most 2 of them)
1938
1939 if ALIs.Table (Id).First_Unit /= ALIs.Table (Id).Last_Unit then
1940 Units.Table (ALIs.Table (Id).First_Unit).Utype := Is_Body;
1941 Units.Table (ALIs.Table (Id).Last_Unit).Utype := Is_Spec;
1942
1943 else
1944 -- Deal with body only and spec only cases, note that the reason we
1945 -- do our own checking of the name (rather than using Is_Body_Name)
1946 -- is that Uname drags in far too much compiler junk!
1947
1948 Get_Name_String (Units.Table (Units.Last).Uname);
1949
1950 if Name_Buffer (Name_Len) = 'b' then
1951 Units.Table (Units.Last).Utype := Is_Body_Only;
1952 else
1953 Units.Table (Units.Last).Utype := Is_Spec_Only;
1954 end if;
1955 end if;
1956
1957 -- Scan out external version references and put in hash table
1958
1959 E_Loop : loop
1960 Check_Unknown_Line;
1961 exit E_Loop when C /= 'E';
1962
1963 if Ignore ('E') then
1964 Skip_Line;
1965
1966 else
1967 Checkc (' ');
1968 Skip_Space;
1969
1970 Name_Len := 0;
1971 Name_Len := 0;
1972 loop
1973 C := Getc;
1974
1975 if C < ' ' then
1976 Fatal_Error;
1977 end if;
1978
1979 exit when At_End_Of_Field;
1980 Add_Char_To_Name_Buffer (C);
1981 end loop;
1982
1983 Version_Ref.Set (new String'(Name_Buffer (1 .. Name_Len)), True);
1984 Skip_Eol;
1985 end if;
1986
1987 C := Getc;
1988 end loop E_Loop;
1989
1990 -- Scan out source dependency lines for this ALI file
1991
1992 ALIs.Table (Id).First_Sdep := Sdep.Last + 1;
1993
1994 D_Loop : loop
1995 Check_Unknown_Line;
1996 exit D_Loop when C /= 'D';
1997
1998 if Ignore ('D') then
1999 Skip_Line;
2000
2001 else
2002 Checkc (' ');
2003 Skip_Space;
2004 Sdep.Increment_Last;
2005
2006 -- In the following call, Lower is not set to True, this is either
2007 -- a bug, or it deserves a special comment as to why this is so???
2008
2009 Sdep.Table (Sdep.Last).Sfile := Get_File_Name;
2010
2011 Sdep.Table (Sdep.Last).Stamp := Get_Stamp;
2012 Sdep.Table (Sdep.Last).Dummy_Entry :=
2013 (Sdep.Table (Sdep.Last).Stamp = Dummy_Time_Stamp);
2014
2015 -- Acquire checksum value
2016
2017 Skip_Space;
2018
2019 declare
2020 Ctr : Natural;
2021 Chk : Word;
2022
2023 begin
2024 Ctr := 0;
2025 Chk := 0;
2026
2027 loop
2028 exit when At_Eol or else Ctr = 8;
2029
2030 if Nextc in '0' .. '9' then
2031 Chk := Chk * 16 +
2032 Character'Pos (Nextc) - Character'Pos ('0');
2033
2034 elsif Nextc in 'a' .. 'f' then
2035 Chk := Chk * 16 +
2036 Character'Pos (Nextc) - Character'Pos ('a') + 10;
2037
2038 else
2039 exit;
2040 end if;
2041
2042 Ctr := Ctr + 1;
2043 P := P + 1;
2044 end loop;
2045
2046 if Ctr = 8 and then At_End_Of_Field then
2047 Sdep.Table (Sdep.Last).Checksum := Chk;
2048 else
2049 Fatal_Error;
2050 end if;
2051 end;
2052
2053 -- Acquire subunit and reference file name entries
2054
2055 Sdep.Table (Sdep.Last).Subunit_Name := No_Name;
2056 Sdep.Table (Sdep.Last).Rfile :=
2057 Sdep.Table (Sdep.Last).Sfile;
2058 Sdep.Table (Sdep.Last).Start_Line := 1;
2059
2060 if not At_Eol then
2061 Skip_Space;
2062
2063 -- Here for subunit name
2064
2065 if Nextc not in '0' .. '9' then
2066 Name_Len := 0;
2067 while not At_End_Of_Field loop
2068 Add_Char_To_Name_Buffer (Getc);
2069 end loop;
2070
2071 -- Set the subunit name. Note that we use Name_Find rather
2072 -- than Name_Enter here as the subunit name may already
2073 -- have been put in the name table by the Project Manager.
2074
2075 Sdep.Table (Sdep.Last).Subunit_Name := Name_Find;
2076
2077 Skip_Space;
2078 end if;
2079
2080 -- Here for reference file name entry
2081
2082 if Nextc in '0' .. '9' then
2083 Sdep.Table (Sdep.Last).Start_Line := Get_Nat;
2084 Checkc (':');
2085
2086 Name_Len := 0;
2087
2088 while not At_End_Of_Field loop
2089 Add_Char_To_Name_Buffer (Getc);
2090 end loop;
2091
2092 Sdep.Table (Sdep.Last).Rfile := Name_Enter;
2093 end if;
2094 end if;
2095
2096 Skip_Eol;
2097 end if;
2098
2099 C := Getc;
2100 end loop D_Loop;
2101
2102 ALIs.Table (Id).Last_Sdep := Sdep.Last;
2103
2104 -- We must at this stage be at an Xref line or the end of file
2105
2106 if C = EOF then
2107 return Id;
2108 end if;
2109
2110 Check_Unknown_Line;
2111
2112 if C /= 'X' then
2113 Fatal_Error;
2114 end if;
2115
2116 -- If we are ignoring Xref sections we are done (we ignore all
2117 -- remaining lines since only xref related lines follow X).
2118
2119 if Ignore ('X') and then not Debug_Flag_X then
2120 return Id;
2121 end if;
2122
2123 -- Loop through Xref sections
2124
2125 X_Loop : loop
2126 Check_Unknown_Line;
2127 exit X_Loop when C /= 'X';
2128
2129 -- Make new entry in section table
2130
2131 Xref_Section.Increment_Last;
2132
2133 Read_Refs_For_One_File : declare
2134 XS : Xref_Section_Record renames
2135 Xref_Section.Table (Xref_Section.Last);
2136
2137 Current_File_Num : Sdep_Id;
2138 -- Keeps track of the current file number (changed by nn|)
2139
2140 begin
2141 XS.File_Num := Sdep_Id (Get_Nat + Nat (First_Sdep_Entry) - 1);
2142 XS.File_Name := Get_File_Name;
2143 XS.First_Entity := Xref_Entity.Last + 1;
2144
2145 Current_File_Num := XS.File_Num;
2146
2147 Skip_Space;
2148
2149 Skip_Eol;
2150 C := Nextc;
2151
2152 -- Loop through Xref entities
2153
2154 while C /= 'X' and then C /= EOF loop
2155 Xref_Entity.Increment_Last;
2156
2157 Read_Refs_For_One_Entity : declare
2158 XE : Xref_Entity_Record renames
2159 Xref_Entity.Table (Xref_Entity.Last);
2160 N : Nat;
2161
2162 procedure Read_Instantiation_Reference;
2163 -- Acquire instantiation reference. Caller has checked
2164 -- that current character is '[' and on return the cursor
2165 -- is skipped past the corresponding closing ']'.
2166
2167 ----------------------------------
2168 -- Read_Instantiation_Reference --
2169 ----------------------------------
2170
2171 procedure Read_Instantiation_Reference is
2172 Local_File_Num : Sdep_Id := Current_File_Num;
2173
2174 begin
2175 Xref.Increment_Last;
2176
2177 declare
2178 XR : Xref_Record renames Xref.Table (Xref.Last);
2179
2180 begin
2181 P := P + 1; -- skip [
2182 N := Get_Nat;
2183
2184 if Nextc = '|' then
2185 XR.File_Num :=
2186 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2187 Local_File_Num := XR.File_Num;
2188 P := P + 1;
2189 N := Get_Nat;
2190
2191 else
2192 XR.File_Num := Local_File_Num;
2193 end if;
2194
2195 XR.Line := N;
2196 XR.Rtype := ' ';
2197 XR.Col := 0;
2198
2199 -- Recursive call for next reference
2200
2201 if Nextc = '[' then
2202 pragma Warnings (Off); -- kill recursion warning
2203 Read_Instantiation_Reference;
2204 pragma Warnings (On);
2205 end if;
2206
2207 -- Skip closing bracket after recursive call
2208
2209 P := P + 1;
2210 end;
2211 end Read_Instantiation_Reference;
2212
2213 -- Start of processing for Read_Refs_For_One_Entity
2214
2215 begin
2216 XE.Line := Get_Nat;
2217 XE.Etype := Getc;
2218 XE.Col := Get_Nat;
2219
2220 case Getc is
2221 when '*' =>
2222 XE.Visibility := Global;
2223 when '+' =>
2224 XE.Visibility := Static;
2225 when others =>
2226 XE.Visibility := Other;
2227 end case;
2228
2229 XE.Entity := Get_Name;
2230
2231 -- Handle the information about generic instantiations
2232
2233 if Nextc = '[' then
2234 Skipc; -- Opening '['
2235 N := Get_Nat;
2236
2237 if Nextc /= '|' then
2238 XE.Iref_File_Num := Current_File_Num;
2239 XE.Iref_Line := N;
2240 else
2241 XE.Iref_File_Num :=
2242 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2243 Skipc;
2244 XE.Iref_Line := Get_Nat;
2245 end if;
2246
2247 if Getc /= ']' then
2248 Fatal_Error;
2249 end if;
2250
2251 else
2252 XE.Iref_File_Num := No_Sdep_Id;
2253 XE.Iref_Line := 0;
2254 end if;
2255
2256 Current_File_Num := XS.File_Num;
2257
2258 -- Renaming reference is present
2259
2260 if Nextc = '=' then
2261 P := P + 1;
2262 XE.Rref_Line := Get_Nat;
2263
2264 if Getc /= ':' then
2265 Fatal_Error;
2266 end if;
2267
2268 XE.Rref_Col := Get_Nat;
2269
2270 -- No renaming reference present
2271
2272 else
2273 XE.Rref_Line := 0;
2274 XE.Rref_Col := 0;
2275 end if;
2276
2277 Skip_Space;
2278
2279 XE.Oref_File_Num := No_Sdep_Id;
2280 XE.Tref_File_Num := No_Sdep_Id;
2281 XE.Tref := Tref_None;
2282 XE.First_Xref := Xref.Last + 1;
2283
2284 -- Loop to check for additional info present
2285
2286 loop
2287 declare
2288 Ref : Tref_Kind;
2289 File : Sdep_Id;
2290 Line : Nat;
2291 Typ : Character;
2292 Col : Nat;
2293 Std : Name_Id;
2294
2295 begin
2296 Get_Typeref
2297 (Current_File_Num, Ref, File, Line, Typ, Col, Std);
2298 exit when Ref = Tref_None;
2299
2300 -- Do we have an overriding procedure?
2301
2302 if Ref = Tref_Derived and then Typ = 'p' then
2303 XE.Oref_File_Num := File;
2304 XE.Oref_Line := Line;
2305 XE.Oref_Col := Col;
2306
2307 -- Arrays never override anything, and <> points to
2308 -- the index types instead
2309
2310 elsif Ref = Tref_Derived and then XE.Etype = 'A' then
2311
2312 -- Index types are stored in the list of references
2313
2314 Xref.Increment_Last;
2315
2316 declare
2317 XR : Xref_Record renames Xref.Table (Xref.Last);
2318 begin
2319 XR.File_Num := File;
2320 XR.Line := Line;
2321 XR.Rtype := Array_Index_Reference;
2322 XR.Col := Col;
2323 XR.Name := Std;
2324 end;
2325
2326 -- Interfaces are stored in the list of references,
2327 -- although the parent type itself is stored in XE.
2328 -- The first interface (when there are only
2329 -- interfaces) is stored in XE.Tref*)
2330
2331 elsif Ref = Tref_Derived
2332 and then Typ = 'R'
2333 and then XE.Tref_File_Num /= No_Sdep_Id
2334 then
2335 Xref.Increment_Last;
2336
2337 declare
2338 XR : Xref_Record renames Xref.Table (Xref.Last);
2339 begin
2340 XR.File_Num := File;
2341 XR.Line := Line;
2342 XR.Rtype := Interface_Reference;
2343 XR.Col := Col;
2344 XR.Name := Std;
2345 end;
2346
2347 else
2348 XE.Tref := Ref;
2349 XE.Tref_File_Num := File;
2350 XE.Tref_Line := Line;
2351 XE.Tref_Type := Typ;
2352 XE.Tref_Col := Col;
2353 XE.Tref_Standard_Entity := Std;
2354 end if;
2355 end;
2356 end loop;
2357
2358 -- Loop through cross-references for this entity
2359
2360 loop
2361 Skip_Space;
2362
2363 if At_Eol then
2364 Skip_Eol;
2365 exit when Nextc /= '.';
2366 P := P + 1;
2367 end if;
2368
2369 Xref.Increment_Last;
2370
2371 declare
2372 XR : Xref_Record renames Xref.Table (Xref.Last);
2373
2374 begin
2375 N := Get_Nat;
2376
2377 if Nextc = '|' then
2378 XR.File_Num :=
2379 Sdep_Id (N + Nat (First_Sdep_Entry) - 1);
2380 Current_File_Num := XR.File_Num;
2381 P := P + 1;
2382 N := Get_Nat;
2383 else
2384 XR.File_Num := Current_File_Num;
2385 end if;
2386
2387 XR.Line := N;
2388 XR.Rtype := Getc;
2389
2390 -- Imported entities reference as in:
2391 -- 494b<c,__gnat_copy_attribs>25
2392 -- ??? Simply skipped for now
2393
2394 if Nextc = '<' then
2395 while Getc /= '>' loop
2396 null;
2397 end loop;
2398 end if;
2399
2400 XR.Col := Get_Nat;
2401
2402 if Nextc = '[' then
2403 Read_Instantiation_Reference;
2404 end if;
2405 end;
2406 end loop;
2407
2408 -- Record last cross-reference
2409
2410 XE.Last_Xref := Xref.Last;
2411 C := Nextc;
2412
2413 exception
2414 when Bad_ALI_Format =>
2415
2416 -- If ignoring errors, then we skip a line with an
2417 -- unexpected error, and try to continue subsequent
2418 -- xref lines.
2419
2420 if Ignore_Errors then
2421 Xref_Entity.Decrement_Last;
2422 Skip_Line;
2423 C := Nextc;
2424
2425 -- Otherwise, we reraise the fatal exception
2426
2427 else
2428 raise;
2429 end if;
2430 end Read_Refs_For_One_Entity;
2431 end loop;
2432
2433 -- Record last entity
2434
2435 XS.Last_Entity := Xref_Entity.Last;
2436
2437 end Read_Refs_For_One_File;
2438
2439 C := Getc;
2440 end loop X_Loop;
2441
2442 -- Here after dealing with xref sections
2443
2444 -- Ignore remaining lines, which belong to an additional section of the
2445 -- ALI file not considered here (like SCO or Alfa).
2446
2447 Check_Unknown_Line;
2448
2449 return Id;
2450
2451 exception
2452 when Bad_ALI_Format =>
2453 return No_ALI_Id;
2454 end Scan_ALI;
2455
2456 ---------
2457 -- SEq --
2458 ---------
2459
2460 function SEq (F1, F2 : String_Ptr) return Boolean is
2461 begin
2462 return F1.all = F2.all;
2463 end SEq;
2464
2465 -----------
2466 -- SHash --
2467 -----------
2468
2469 function SHash (S : String_Ptr) return Vindex is
2470 H : Word;
2471
2472 begin
2473 H := 0;
2474 for J in S.all'Range loop
2475 H := H * 2 + Character'Pos (S (J));
2476 end loop;
2477
2478 return Vindex (Vindex'First + Vindex (H mod Vindex'Range_Length));
2479 end SHash;
2480
2481 end ALI;