* sh.h (REG_CLASS_FROM_LETTER): Change to:
[official-gcc.git] / gcc / ada / sinput.adb
blobec9659eb7c815e74d8a526c9d8c01f9a1bba7e64
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S I N P U T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
21 -- --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 pragma Style_Checks (All_Checks);
35 -- Subprograms not all in alpha order
37 with Debug; use Debug;
38 with Namet; use Namet;
39 with Opt; use Opt;
40 with Output; use Output;
41 with Tree_IO; use Tree_IO;
42 with System; use System;
44 with System.Memory;
46 with Unchecked_Conversion;
47 with Unchecked_Deallocation;
49 package body Sinput is
51 use ASCII;
52 -- Make control characters visible
54 First_Time_Around : Boolean := True;
56 -- Routines to support conversion between types Lines_Table_Ptr,
57 -- Logical_Lines_Table_Ptr and System.Address.
59 function To_Address is
60 new Unchecked_Conversion (Lines_Table_Ptr, Address);
62 function To_Address is
63 new Unchecked_Conversion (Logical_Lines_Table_Ptr, Address);
65 function To_Pointer is
66 new Unchecked_Conversion (Address, Lines_Table_Ptr);
68 function To_Pointer is
69 new Unchecked_Conversion (Address, Logical_Lines_Table_Ptr);
71 ---------------------------
72 -- Add_Line_Tables_Entry --
73 ---------------------------
75 procedure Add_Line_Tables_Entry
76 (S : in out Source_File_Record;
77 P : Source_Ptr)
79 LL : Physical_Line_Number;
81 begin
82 -- Reallocate the lines tables if necessary.
84 -- Note: the reason we do not use the normal Table package
85 -- mechanism is that we have several of these tables. We could
86 -- use the new GNAT.Dynamic_Tables package and that would probably
87 -- be a good idea ???
89 if S.Last_Source_Line = S.Lines_Table_Max then
90 Alloc_Line_Tables
91 (S,
92 Int (S.Last_Source_Line) *
93 ((100 + Alloc.Lines_Increment) / 100));
95 if Debug_Flag_D then
96 Write_Str ("--> Reallocating lines table, size = ");
97 Write_Int (Int (S.Lines_Table_Max));
98 Write_Eol;
99 end if;
100 end if;
102 S.Last_Source_Line := S.Last_Source_Line + 1;
103 LL := S.Last_Source_Line;
105 S.Lines_Table (LL) := P;
107 -- Deal with setting new entry in logical lines table if one is
108 -- present. Note that there is always space (because the call to
109 -- Alloc_Line_Tables makes sure both tables are the same length),
111 if S.Logical_Lines_Table /= null then
113 -- We can always set the entry from the previous one, because
114 -- the processing for a Source_Reference pragma ensures that
115 -- at least one entry following the pragma is set up correctly.
117 S.Logical_Lines_Table (LL) := S.Logical_Lines_Table (LL - 1) + 1;
118 end if;
119 end Add_Line_Tables_Entry;
121 -----------------------
122 -- Alloc_Line_Tables --
123 -----------------------
125 procedure Alloc_Line_Tables
126 (S : in out Source_File_Record;
127 New_Max : Nat)
129 subtype size_t is Memory.size_t;
131 New_Table : Lines_Table_Ptr;
133 New_Logical_Table : Logical_Lines_Table_Ptr;
135 New_Size : constant size_t :=
136 size_t (New_Max * Lines_Table_Type'Component_Size /
137 Storage_Unit);
139 begin
140 if S.Lines_Table = null then
141 New_Table := To_Pointer (Memory.Alloc (New_Size));
143 else
144 New_Table :=
145 To_Pointer (Memory.Realloc (To_Address (S.Lines_Table), New_Size));
146 end if;
148 if New_Table = null then
149 raise Storage_Error;
150 else
151 S.Lines_Table := New_Table;
152 S.Lines_Table_Max := Physical_Line_Number (New_Max);
153 end if;
155 if S.Num_SRef_Pragmas /= 0 then
156 if S.Logical_Lines_Table = null then
157 New_Logical_Table := To_Pointer (Memory.Alloc (New_Size));
158 else
159 New_Logical_Table := To_Pointer
160 (Memory.Realloc (To_Address (S.Logical_Lines_Table), New_Size));
161 end if;
163 if New_Logical_Table = null then
164 raise Storage_Error;
165 else
166 S.Logical_Lines_Table := New_Logical_Table;
167 end if;
168 end if;
169 end Alloc_Line_Tables;
171 -----------------
172 -- Backup_Line --
173 -----------------
175 procedure Backup_Line (P : in out Source_Ptr) is
176 Sindex : constant Source_File_Index := Get_Source_File_Index (P);
177 Src : constant Source_Buffer_Ptr :=
178 Source_File.Table (Sindex).Source_Text;
179 Sfirst : constant Source_Ptr :=
180 Source_File.Table (Sindex).Source_First;
182 begin
183 P := P - 1;
185 if P = Sfirst then
186 return;
187 end if;
189 if Src (P) = CR then
190 if Src (P - 1) = LF then
191 P := P - 1;
192 end if;
194 else -- Src (P) = LF
195 if Src (P - 1) = CR then
196 P := P - 1;
197 end if;
198 end if;
200 -- Now find first character of the previous line
202 while P > Sfirst
203 and then Src (P - 1) /= LF
204 and then Src (P - 1) /= CR
205 loop
206 P := P - 1;
207 end loop;
208 end Backup_Line;
210 ---------------------------
211 -- Build_Location_String --
212 ---------------------------
214 procedure Build_Location_String (Loc : Source_Ptr) is
215 Ptr : Source_Ptr;
217 begin
218 Name_Len := 0;
220 -- Loop through instantiations
222 Ptr := Loc;
223 loop
224 Get_Name_String_And_Append
225 (Reference_Name (Get_Source_File_Index (Ptr)));
226 Add_Char_To_Name_Buffer (':');
227 Add_Nat_To_Name_Buffer
228 (Nat (Get_Logical_Line_Number (Ptr)));
230 Ptr := Instantiation_Location (Ptr);
231 exit when Ptr = No_Location;
232 Add_Str_To_Name_Buffer (" instantiated at ");
233 end loop;
235 Name_Buffer (Name_Len + 1) := NUL;
236 return;
237 end Build_Location_String;
239 -----------------------
240 -- Get_Column_Number --
241 -----------------------
243 function Get_Column_Number (P : Source_Ptr) return Column_Number is
244 S : Source_Ptr;
245 C : Column_Number;
246 Sindex : Source_File_Index;
247 Src : Source_Buffer_Ptr;
249 begin
250 -- If the input source pointer is not a meaningful value then return
251 -- at once with column number 1. This can happen for a file not found
252 -- condition for a file loaded indirectly by RTE, and also perhaps on
253 -- some unknown internal error conditions. In either case we certainly
254 -- don't want to blow up.
256 if P < 1 then
257 return 1;
259 else
260 Sindex := Get_Source_File_Index (P);
261 Src := Source_File.Table (Sindex).Source_Text;
262 S := Line_Start (P);
263 C := 1;
265 while S < P loop
266 if Src (S) = HT then
267 C := (C - 1) / 8 * 8 + (8 + 1);
268 else
269 C := C + 1;
270 end if;
272 S := S + 1;
273 end loop;
275 return C;
276 end if;
277 end Get_Column_Number;
279 -----------------------------
280 -- Get_Logical_Line_Number --
281 -----------------------------
283 function Get_Logical_Line_Number
284 (P : Source_Ptr)
285 return Logical_Line_Number
287 SFR : Source_File_Record
288 renames Source_File.Table (Get_Source_File_Index (P));
290 L : constant Physical_Line_Number := Get_Physical_Line_Number (P);
292 begin
293 if SFR.Num_SRef_Pragmas = 0 then
294 return Logical_Line_Number (L);
295 else
296 return SFR.Logical_Lines_Table (L);
297 end if;
298 end Get_Logical_Line_Number;
300 ------------------------------
301 -- Get_Physical_Line_Number --
302 ------------------------------
304 function Get_Physical_Line_Number
305 (P : Source_Ptr)
306 return Physical_Line_Number
308 Sfile : Source_File_Index;
309 Table : Lines_Table_Ptr;
310 Lo : Physical_Line_Number;
311 Hi : Physical_Line_Number;
312 Mid : Physical_Line_Number;
313 Loc : Source_Ptr;
315 begin
316 -- If the input source pointer is not a meaningful value then return
317 -- at once with line number 1. This can happen for a file not found
318 -- condition for a file loaded indirectly by RTE, and also perhaps on
319 -- some unknown internal error conditions. In either case we certainly
320 -- don't want to blow up.
322 if P < 1 then
323 return 1;
325 -- Otherwise we can do the binary search
327 else
328 Sfile := Get_Source_File_Index (P);
329 Loc := P + Source_File.Table (Sfile).Sloc_Adjust;
330 Table := Source_File.Table (Sfile).Lines_Table;
331 Lo := 1;
332 Hi := Source_File.Table (Sfile).Last_Source_Line;
334 loop
335 Mid := (Lo + Hi) / 2;
337 if Loc < Table (Mid) then
338 Hi := Mid - 1;
340 else -- Loc >= Table (Mid)
342 if Mid = Hi or else
343 Loc < Table (Mid + 1)
344 then
345 return Mid;
346 else
347 Lo := Mid + 1;
348 end if;
350 end if;
352 end loop;
353 end if;
354 end Get_Physical_Line_Number;
356 ---------------------------
357 -- Get_Source_File_Index --
358 ---------------------------
360 Source_Cache_First : Source_Ptr := 1;
361 Source_Cache_Last : Source_Ptr := 0;
362 -- Records the First and Last subscript values for the most recently
363 -- referenced entry in the source table, to optimize the common case
364 -- of repeated references to the same entry. The initial values force
365 -- an initial search to set the cache value.
367 Source_Cache_Index : Source_File_Index := No_Source_File;
368 -- Contains the index of the entry corresponding to Source_Cache
370 function Get_Source_File_Index
371 (S : Source_Ptr)
372 return Source_File_Index
374 begin
375 if S in Source_Cache_First .. Source_Cache_Last then
376 return Source_Cache_Index;
378 else
379 for J in 1 .. Source_File.Last loop
380 if S in Source_File.Table (J).Source_First ..
381 Source_File.Table (J).Source_Last
382 then
383 Source_Cache_Index := J;
384 Source_Cache_First :=
385 Source_File.Table (Source_Cache_Index).Source_First;
386 Source_Cache_Last :=
387 Source_File.Table (Source_Cache_Index).Source_Last;
388 return Source_Cache_Index;
389 end if;
390 end loop;
391 end if;
393 -- We must find a matching entry in the above loop!
395 raise Program_Error;
396 end Get_Source_File_Index;
398 ----------------
399 -- Initialize --
400 ----------------
402 procedure Initialize is
403 begin
404 Source_File.Init;
405 end Initialize;
407 -------------------------
408 -- Instantiation_Depth --
409 -------------------------
411 function Instantiation_Depth (S : Source_Ptr) return Nat is
412 Sind : Source_File_Index;
413 Sval : Source_Ptr;
414 Depth : Nat;
416 begin
417 Sval := S;
418 Depth := 0;
420 loop
421 Sind := Get_Source_File_Index (Sval);
422 Sval := Instantiation (Sind);
423 exit when Sval = No_Location;
424 Depth := Depth + 1;
425 end loop;
427 return Depth;
428 end Instantiation_Depth;
430 ----------------------------
431 -- Instantiation_Location --
432 ----------------------------
434 function Instantiation_Location (S : Source_Ptr) return Source_Ptr is
435 begin
436 return Instantiation (Get_Source_File_Index (S));
437 end Instantiation_Location;
439 ----------------------
440 -- Last_Source_File --
441 ----------------------
443 function Last_Source_File return Source_File_Index is
444 begin
445 return Source_File.Last;
446 end Last_Source_File;
448 ----------------
449 -- Line_Start --
450 ----------------
452 function Line_Start (P : Source_Ptr) return Source_Ptr is
453 Sindex : constant Source_File_Index := Get_Source_File_Index (P);
454 Src : constant Source_Buffer_Ptr :=
455 Source_File.Table (Sindex).Source_Text;
456 Sfirst : constant Source_Ptr :=
457 Source_File.Table (Sindex).Source_First;
458 S : Source_Ptr;
460 begin
461 S := P;
463 while S > Sfirst
464 and then Src (S - 1) /= CR
465 and then Src (S - 1) /= LF
466 loop
467 S := S - 1;
468 end loop;
470 return S;
471 end Line_Start;
473 function Line_Start
474 (L : Physical_Line_Number;
475 S : Source_File_Index)
476 return Source_Ptr
478 begin
479 return Source_File.Table (S).Lines_Table (L);
480 end Line_Start;
482 ----------
483 -- Lock --
484 ----------
486 procedure Lock is
487 begin
488 Source_File.Locked := True;
489 Source_File.Release;
490 end Lock;
492 ----------------------
493 -- Num_Source_Files --
494 ----------------------
496 function Num_Source_Files return Nat is
497 begin
498 return Int (Source_File.Last) - Int (Source_File.First) + 1;
499 end Num_Source_Files;
501 ----------------------
502 -- Num_Source_Lines --
503 ----------------------
505 function Num_Source_Lines (S : Source_File_Index) return Nat is
506 begin
507 return Nat (Source_File.Table (S).Last_Source_Line);
508 end Num_Source_Lines;
510 -----------------------
511 -- Original_Location --
512 -----------------------
514 function Original_Location (S : Source_Ptr) return Source_Ptr is
515 Sindex : Source_File_Index;
516 Tindex : Source_File_Index;
518 begin
519 if S <= No_Location then
520 return S;
522 else
523 Sindex := Get_Source_File_Index (S);
525 if Instantiation (Sindex) = No_Location then
526 return S;
528 else
529 Tindex := Template (Sindex);
530 while Instantiation (Tindex) /= No_Location loop
531 Tindex := Template (Tindex);
532 end loop;
534 return S - Source_First (Sindex) + Source_First (Tindex);
535 end if;
536 end if;
537 end Original_Location;
539 -------------------------
540 -- Physical_To_Logical --
541 -------------------------
543 function Physical_To_Logical
544 (Line : Physical_Line_Number;
545 S : Source_File_Index)
546 return Logical_Line_Number
548 SFR : Source_File_Record renames Source_File.Table (S);
550 begin
551 if SFR.Num_SRef_Pragmas = 0 then
552 return Logical_Line_Number (Line);
553 else
554 return SFR.Logical_Lines_Table (Line);
555 end if;
556 end Physical_To_Logical;
558 --------------------------------
559 -- Register_Source_Ref_Pragma --
560 --------------------------------
562 procedure Register_Source_Ref_Pragma
563 (File_Name : Name_Id;
564 Stripped_File_Name : Name_Id;
565 Mapped_Line : Nat;
566 Line_After_Pragma : Physical_Line_Number)
568 subtype size_t is Memory.size_t;
570 SFR : Source_File_Record renames Source_File.Table (Current_Source_File);
572 ML : Logical_Line_Number;
574 begin
575 if File_Name /= No_Name then
576 SFR.Full_Ref_Name := File_Name;
578 if not Debug_Generated_Code then
579 SFR.Debug_Source_Name := File_Name;
580 end if;
582 SFR.Reference_Name := Stripped_File_Name;
583 SFR.Num_SRef_Pragmas := SFR.Num_SRef_Pragmas + 1;
584 end if;
586 if SFR.Num_SRef_Pragmas = 1 then
587 SFR.First_Mapped_Line := Logical_Line_Number (Mapped_Line);
588 end if;
590 if SFR.Logical_Lines_Table = null then
591 SFR.Logical_Lines_Table := To_Pointer
592 (Memory.Alloc
593 (size_t (SFR.Lines_Table_Max *
594 Logical_Lines_Table_Type'Component_Size /
595 Storage_Unit)));
596 end if;
598 SFR.Logical_Lines_Table (Line_After_Pragma - 1) := No_Line_Number;
600 ML := Logical_Line_Number (Mapped_Line);
601 for J in Line_After_Pragma .. SFR.Last_Source_Line loop
602 SFR.Logical_Lines_Table (J) := ML;
603 ML := ML + 1;
604 end loop;
605 end Register_Source_Ref_Pragma;
607 ---------------------------
608 -- Skip_Line_Terminators --
609 ---------------------------
611 -- There are two distinct concepts of line terminator in GNAT
613 -- A logical line terminator is what corresponds to the "end of a line"
614 -- as described in RM 2.2 (13). Any of the characters FF, LF, CR or VT
615 -- acts as an end of logical line in this sense, and it is essentially
616 -- irrelevant whether one or more appears in sequence (since if a
617 -- sequence of such characters is regarded as separate ends of line,
618 -- then the intervening logical lines are null in any case).
620 -- A physical line terminator is a sequence of format effectors that
621 -- is treated as ending a physical line. Physical lines have no Ada
622 -- semantic significance, but they are significant for error reporting
623 -- purposes, since errors are identified by line and column location.
625 -- In GNAT, a physical line is ended by any of the sequences LF, CR/LF,
626 -- CR or LF/CR. LF is used in typical Unix systems, CR/LF in DOS systems,
627 -- and CR alone in System 7. We don't know of any system using LF/CR, but
628 -- it seems reasonable to include this case for consistency. In addition,
629 -- we recognize any of these sequences in any of the operating systems,
630 -- for better behavior in treating foreign files (e.g. a Unix file with
631 -- LF terminators transferred to a DOS system).
633 procedure Skip_Line_Terminators
634 (P : in out Source_Ptr;
635 Physical : out Boolean)
637 begin
638 pragma Assert (Source (P) in Line_Terminator);
640 if Source (P) = CR then
641 if Source (P + 1) = LF then
642 P := P + 2;
643 else
644 P := P + 1;
645 end if;
647 elsif Source (P) = LF then
648 if Source (P + 1) = CR then
649 P := P + 2;
650 else
651 P := P + 1;
652 end if;
654 else -- Source (P) = FF or else Source (P) = VT
655 P := P + 1;
656 Physical := False;
657 return;
658 end if;
660 -- Fall through in the physical line terminator case. First deal with
661 -- making a possible entry into the lines table if one is needed.
663 -- Note: we are dealing with a real source file here, this cannot be
664 -- the instantiation case, so we need not worry about Sloc adjustment.
666 declare
667 S : Source_File_Record
668 renames Source_File.Table (Current_Source_File);
670 begin
671 Physical := True;
673 -- Make entry in lines table if not already made (in some scan backup
674 -- cases, we will be rescanning previously scanned source, so the
675 -- entry may have already been made on the previous forward scan).
677 if Source (P) /= EOF
678 and then P > S.Lines_Table (S.Last_Source_Line)
679 then
680 Add_Line_Tables_Entry (S, P);
681 end if;
682 end;
683 end Skip_Line_Terminators;
685 -------------------
686 -- Source_Offset --
687 -------------------
689 function Source_Offset (S : Source_Ptr) return Nat is
690 Sindex : constant Source_File_Index := Get_Source_File_Index (S);
691 Sfirst : constant Source_Ptr :=
692 Source_File.Table (Sindex).Source_First;
694 begin
695 return Nat (S - Sfirst);
696 end Source_Offset;
698 ------------------------
699 -- Top_Level_Location --
700 ------------------------
702 function Top_Level_Location (S : Source_Ptr) return Source_Ptr is
703 Oldloc : Source_Ptr;
704 Newloc : Source_Ptr;
706 begin
707 Newloc := S;
708 loop
709 Oldloc := Newloc;
710 Newloc := Instantiation_Location (Oldloc);
711 exit when Newloc = No_Location;
712 end loop;
714 return Oldloc;
715 end Top_Level_Location;
717 ---------------
718 -- Tree_Read --
719 ---------------
721 procedure Tree_Read is
722 begin
723 -- First we must free any old source buffer pointers
725 if not First_Time_Around then
726 for J in Source_File.First .. Source_File.Last loop
727 declare
728 S : Source_File_Record renames Source_File.Table (J);
730 procedure Free_Ptr is new Unchecked_Deallocation
731 (Big_Source_Buffer, Source_Buffer_Ptr);
733 function To_Source_Buffer_Ptr is new
734 Unchecked_Conversion (Address, Source_Buffer_Ptr);
736 Tmp1 : Source_Buffer_Ptr;
738 begin
739 if S.Instantiation /= No_Location then
740 null;
742 else
743 -- We have to recreate a proper pointer to the actual array
744 -- from the zero origin pointer stored in the source table.
746 Tmp1 :=
747 To_Source_Buffer_Ptr
748 (S.Source_Text (S.Source_First)'Address);
749 Free_Ptr (Tmp1);
751 -- Note: we are using free here, because we used malloc
752 -- or realloc directly to allocate the tables. That is
753 -- because we were playing the big array trick.
755 if S.Lines_Table /= null then
756 Memory.Free (To_Address (S.Lines_Table));
757 S.Lines_Table := null;
758 end if;
760 if S.Logical_Lines_Table /= null then
761 Memory.Free (To_Address (S.Logical_Lines_Table));
762 S.Logical_Lines_Table := null;
763 end if;
764 end if;
765 end;
766 end loop;
767 end if;
769 -- Reset source cache pointers to force new read
771 Source_Cache_First := 1;
772 Source_Cache_Last := 0;
774 -- Read in source file table
776 Source_File.Tree_Read;
778 -- The pointers we read in there for the source buffer and lines
779 -- table pointers are junk. We now read in the actual data that
780 -- is referenced by these two fields.
782 for J in Source_File.First .. Source_File.Last loop
783 declare
784 S : Source_File_Record renames Source_File.Table (J);
786 begin
787 -- For the instantiation case, we do not read in any data. Instead
788 -- we share the data for the generic template entry. Since the
789 -- template always occurs first, we can safetly refer to its data.
791 if S.Instantiation /= No_Location then
792 declare
793 ST : Source_File_Record renames
794 Source_File.Table (S.Template);
796 begin
797 -- The lines tables are copied from the template entry
799 S.Lines_Table :=
800 Source_File.Table (S.Template).Lines_Table;
801 S.Logical_Lines_Table :=
802 Source_File.Table (S.Template).Logical_Lines_Table;
804 -- In the case of the source table pointer, we share the
805 -- same data as the generic template, but the virtual origin
806 -- is adjusted. For example, if the first subscript of the
807 -- template is 100, and that of the instantiation is 200,
808 -- then the instantiation pointer is obtained by subtracting
809 -- 100 from the template pointer.
811 declare
812 pragma Suppress (All_Checks);
814 function To_Source_Buffer_Ptr is new
815 Unchecked_Conversion (Address, Source_Buffer_Ptr);
817 begin
818 S.Source_Text :=
819 To_Source_Buffer_Ptr
820 (ST.Source_Text
821 (ST.Source_First - S.Source_First)'Address);
822 end;
823 end;
825 -- Normal case (non-instantiation)
827 else
828 First_Time_Around := False;
829 S.Lines_Table := null;
830 S.Logical_Lines_Table := null;
831 Alloc_Line_Tables (S, Int (S.Last_Source_Line));
833 for J in 1 .. S.Last_Source_Line loop
834 Tree_Read_Int (Int (S.Lines_Table (J)));
835 end loop;
837 if S.Num_SRef_Pragmas /= 0 then
838 for J in 1 .. S.Last_Source_Line loop
839 Tree_Read_Int (Int (S.Logical_Lines_Table (J)));
840 end loop;
841 end if;
843 -- Allocate source buffer and read in the data and then set the
844 -- virtual origin to point to the logical zero'th element. This
845 -- address must be computed with subscript checks turned off.
847 declare
848 subtype B is Text_Buffer (S.Source_First .. S.Source_Last);
849 type Text_Buffer_Ptr is access B;
850 T : Text_Buffer_Ptr;
852 pragma Suppress (All_Checks);
854 function To_Source_Buffer_Ptr is new
855 Unchecked_Conversion (Address, Source_Buffer_Ptr);
857 begin
858 T := new B;
860 Tree_Read_Data (T (S.Source_First)'Address,
861 Int (S.Source_Last) - Int (S.Source_First) + 1);
863 S.Source_Text := To_Source_Buffer_Ptr (T (0)'Address);
864 end;
865 end if;
866 end;
867 end loop;
868 end Tree_Read;
870 ----------------
871 -- Tree_Write --
872 ----------------
874 procedure Tree_Write is
875 begin
876 Source_File.Tree_Write;
878 -- The pointers we wrote out there for the source buffer and lines
879 -- table pointers are junk, we now write out the actual data that
880 -- is referenced by these two fields.
882 for J in Source_File.First .. Source_File.Last loop
883 declare
884 S : Source_File_Record renames Source_File.Table (J);
886 begin
887 -- For instantiations, there is nothing to do, since the data is
888 -- shared with the generic template. When the tree is read, the
889 -- pointers must be set, but no extra data needs to be written.
891 if S.Instantiation /= No_Location then
892 null;
894 -- For the normal case, write out the data of the tables
896 else
897 -- Lines table
899 for J in 1 .. S.Last_Source_Line loop
900 Tree_Write_Int (Int (S.Lines_Table (J)));
901 end loop;
903 -- Logical lines table if present
905 if S.Num_SRef_Pragmas /= 0 then
906 for J in 1 .. S.Last_Source_Line loop
907 Tree_Write_Int (Int (S.Logical_Lines_Table (J)));
908 end loop;
909 end if;
911 -- Source buffer
913 Tree_Write_Data
914 (S.Source_Text (S.Source_First)'Address,
915 Int (S.Source_Last) - Int (S.Source_First) + 1);
916 end if;
917 end;
918 end loop;
919 end Tree_Write;
921 --------------------
922 -- Write_Location --
923 --------------------
925 procedure Write_Location (P : Source_Ptr) is
926 begin
927 if P = No_Location then
928 Write_Str ("<no location>");
930 elsif P <= Standard_Location then
931 Write_Str ("<standard location>");
933 else
934 declare
935 SI : constant Source_File_Index := Get_Source_File_Index (P);
937 begin
938 Write_Name (Debug_Source_Name (SI));
939 Write_Char (':');
940 Write_Int (Int (Get_Logical_Line_Number (P)));
941 Write_Char (':');
942 Write_Int (Int (Get_Column_Number (P)));
944 if Instantiation (SI) /= No_Location then
945 Write_Str (" [");
946 Write_Location (Instantiation (SI));
947 Write_Char (']');
948 end if;
949 end;
950 end if;
951 end Write_Location;
953 ----------------------
954 -- Write_Time_Stamp --
955 ----------------------
957 procedure Write_Time_Stamp (S : Source_File_Index) is
958 T : constant Time_Stamp_Type := Time_Stamp (S);
959 P : Natural;
961 begin
962 if T (1) = '9' then
963 Write_Str ("19");
964 P := 0;
965 else
966 Write_Char (T (1));
967 Write_Char (T (2));
968 P := 2;
969 end if;
971 Write_Char (T (P + 1));
972 Write_Char (T (P + 2));
973 Write_Char ('-');
975 Write_Char (T (P + 3));
976 Write_Char (T (P + 4));
977 Write_Char ('-');
979 Write_Char (T (P + 5));
980 Write_Char (T (P + 6));
981 Write_Char (' ');
983 Write_Char (T (P + 7));
984 Write_Char (T (P + 8));
985 Write_Char (':');
987 Write_Char (T (P + 9));
988 Write_Char (T (P + 10));
989 Write_Char (':');
991 Write_Char (T (P + 11));
992 Write_Char (T (P + 12));
993 end Write_Time_Stamp;
995 ----------------------------------------------
996 -- Access Subprograms for Source File Table --
997 ----------------------------------------------
999 function Debug_Source_Name (S : SFI) return File_Name_Type is
1000 begin
1001 return Source_File.Table (S).Debug_Source_Name;
1002 end Debug_Source_Name;
1004 function File_Name (S : SFI) return File_Name_Type is
1005 begin
1006 return Source_File.Table (S).File_Name;
1007 end File_Name;
1009 function First_Mapped_Line (S : SFI) return Logical_Line_Number is
1010 begin
1011 return Source_File.Table (S).First_Mapped_Line;
1012 end First_Mapped_Line;
1014 function Full_File_Name (S : SFI) return File_Name_Type is
1015 begin
1016 return Source_File.Table (S).Full_File_Name;
1017 end Full_File_Name;
1019 function Full_Ref_Name (S : SFI) return File_Name_Type is
1020 begin
1021 return Source_File.Table (S).Full_Ref_Name;
1022 end Full_Ref_Name;
1024 function Identifier_Casing (S : SFI) return Casing_Type is
1025 begin
1026 return Source_File.Table (S).Identifier_Casing;
1027 end Identifier_Casing;
1029 function Instantiation (S : SFI) return Source_Ptr is
1030 begin
1031 return Source_File.Table (S).Instantiation;
1032 end Instantiation;
1034 function Keyword_Casing (S : SFI) return Casing_Type is
1035 begin
1036 return Source_File.Table (S).Keyword_Casing;
1037 end Keyword_Casing;
1039 function Last_Source_Line (S : SFI) return Physical_Line_Number is
1040 begin
1041 return Source_File.Table (S).Last_Source_Line;
1042 end Last_Source_Line;
1044 function License (S : SFI) return License_Type is
1045 begin
1046 return Source_File.Table (S).License;
1047 end License;
1049 function Num_SRef_Pragmas (S : SFI) return Nat is
1050 begin
1051 return Source_File.Table (S).Num_SRef_Pragmas;
1052 end Num_SRef_Pragmas;
1054 function Reference_Name (S : SFI) return File_Name_Type is
1055 begin
1056 return Source_File.Table (S).Reference_Name;
1057 end Reference_Name;
1059 function Source_Checksum (S : SFI) return Word is
1060 begin
1061 return Source_File.Table (S).Source_Checksum;
1062 end Source_Checksum;
1064 function Source_First (S : SFI) return Source_Ptr is
1065 begin
1066 return Source_File.Table (S).Source_First;
1067 end Source_First;
1069 function Source_Last (S : SFI) return Source_Ptr is
1070 begin
1071 return Source_File.Table (S).Source_Last;
1072 end Source_Last;
1074 function Source_Text (S : SFI) return Source_Buffer_Ptr is
1075 begin
1076 return Source_File.Table (S).Source_Text;
1077 end Source_Text;
1079 function Template (S : SFI) return SFI is
1080 begin
1081 return Source_File.Table (S).Template;
1082 end Template;
1084 function Time_Stamp (S : SFI) return Time_Stamp_Type is
1085 begin
1086 return Source_File.Table (S).Time_Stamp;
1087 end Time_Stamp;
1089 ------------------------------------------
1090 -- Set Procedures for Source File Table --
1091 ------------------------------------------
1093 procedure Set_Identifier_Casing (S : SFI; C : Casing_Type) is
1094 begin
1095 Source_File.Table (S).Identifier_Casing := C;
1096 end Set_Identifier_Casing;
1098 procedure Set_Keyword_Casing (S : SFI; C : Casing_Type) is
1099 begin
1100 Source_File.Table (S).Keyword_Casing := C;
1101 end Set_Keyword_Casing;
1103 procedure Set_License (S : SFI; L : License_Type) is
1104 begin
1105 Source_File.Table (S).License := L;
1106 end Set_License;
1108 ----------------------
1109 -- Trim_Lines_Table --
1110 ----------------------
1112 procedure Trim_Lines_Table (S : Source_File_Index) is
1113 Max : constant Nat := Nat (Source_File.Table (S).Last_Source_Line);
1115 begin
1116 -- Release allocated storage that is no longer needed
1118 Source_File.Table (S).Lines_Table := To_Pointer
1119 (Memory.Realloc
1120 (To_Address (Source_File.Table (S).Lines_Table),
1121 Memory.size_t
1122 (Max * (Lines_Table_Type'Component_Size / System.Storage_Unit))));
1123 Source_File.Table (S).Lines_Table_Max := Physical_Line_Number (Max);
1124 end Trim_Lines_Table;
1126 --------
1127 -- wl --
1128 --------
1130 procedure wl (P : Source_Ptr) is
1131 begin
1132 Write_Location (P);
1133 Write_Eol;
1134 end wl;
1136 end Sinput;