1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2009, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
32 pragma Style_Checks (All_Checks);
33 -- Subprograms not all in alpha order
35 with Atree; use Atree;
36 with Debug; use Debug;
38 with Output; use Output;
39 with Tree_IO; use Tree_IO;
40 with Sinfo; use Sinfo;
41 with System; use System;
42 with Widechar; use Widechar;
46 with Unchecked_Conversion;
47 with Unchecked_Deallocation;
49 package body Sinput is
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 pragma Warnings (Off);
60 -- These unchecked conversions are aliasing safe, since they are never
61 -- used to construct improperly aliased pointer values.
63 function To_Address is
64 new Unchecked_Conversion (Lines_Table_Ptr, Address);
66 function To_Address is
67 new Unchecked_Conversion (Logical_Lines_Table_Ptr, Address);
69 function To_Pointer is
70 new Unchecked_Conversion (Address, Lines_Table_Ptr);
72 function To_Pointer is
73 new Unchecked_Conversion (Address, Logical_Lines_Table_Ptr);
77 ---------------------------
78 -- Add_Line_Tables_Entry --
79 ---------------------------
81 procedure Add_Line_Tables_Entry
82 (S : in out Source_File_Record;
85 LL : Physical_Line_Number;
88 -- Reallocate the lines tables if necessary
90 -- Note: the reason we do not use the normal Table package
91 -- mechanism is that we have several of these tables. We could
92 -- use the new GNAT.Dynamic_Tables package and that would probably
95 if S.Last_Source_Line = S.Lines_Table_Max then
98 Int (S.Last_Source_Line) *
99 ((100 + Alloc.Lines_Increment) / 100));
102 Write_Str ("--> Reallocating lines table, size = ");
103 Write_Int (Int (S.Lines_Table_Max));
108 S.Last_Source_Line := S.Last_Source_Line + 1;
109 LL := S.Last_Source_Line;
111 S.Lines_Table (LL) := P;
113 -- Deal with setting new entry in logical lines table if one is
114 -- present. Note that there is always space (because the call to
115 -- Alloc_Line_Tables makes sure both tables are the same length),
117 if S.Logical_Lines_Table /= null then
119 -- We can always set the entry from the previous one, because
120 -- the processing for a Source_Reference pragma ensures that
121 -- at least one entry following the pragma is set up correctly.
123 S.Logical_Lines_Table (LL) := S.Logical_Lines_Table (LL - 1) + 1;
125 end Add_Line_Tables_Entry;
127 -----------------------
128 -- Alloc_Line_Tables --
129 -----------------------
131 procedure Alloc_Line_Tables
132 (S : in out Source_File_Record;
135 subtype size_t is Memory.size_t;
137 New_Table : Lines_Table_Ptr;
139 New_Logical_Table : Logical_Lines_Table_Ptr;
141 New_Size : constant size_t :=
142 size_t (New_Max * Lines_Table_Type'Component_Size /
146 if S.Lines_Table = null then
147 New_Table := To_Pointer (Memory.Alloc (New_Size));
151 To_Pointer (Memory.Realloc (To_Address (S.Lines_Table), New_Size));
154 if New_Table = null then
157 S.Lines_Table := New_Table;
158 S.Lines_Table_Max := Physical_Line_Number (New_Max);
161 if S.Num_SRef_Pragmas /= 0 then
162 if S.Logical_Lines_Table = null then
163 New_Logical_Table := To_Pointer (Memory.Alloc (New_Size));
165 New_Logical_Table := To_Pointer
166 (Memory.Realloc (To_Address (S.Logical_Lines_Table), New_Size));
169 if New_Logical_Table = null then
172 S.Logical_Lines_Table := New_Logical_Table;
175 end Alloc_Line_Tables;
181 procedure Backup_Line (P : in out Source_Ptr) is
182 Sindex : constant Source_File_Index := Get_Source_File_Index (P);
183 Src : constant Source_Buffer_Ptr :=
184 Source_File.Table (Sindex).Source_Text;
185 Sfirst : constant Source_Ptr :=
186 Source_File.Table (Sindex).Source_First;
196 if Src (P - 1) = LF then
201 if Src (P - 1) = CR then
206 -- Now find first character of the previous line
209 and then Src (P - 1) /= LF
210 and then Src (P - 1) /= CR
216 ---------------------------
217 -- Build_Location_String --
218 ---------------------------
220 procedure Build_Location_String (Loc : Source_Ptr) is
224 -- Loop through instantiations
228 Get_Name_String_And_Append
229 (Reference_Name (Get_Source_File_Index (Ptr)));
230 Add_Char_To_Name_Buffer (':');
231 Add_Nat_To_Name_Buffer
232 (Nat (Get_Logical_Line_Number (Ptr)));
234 Ptr := Instantiation_Location (Ptr);
235 exit when Ptr = No_Location;
236 Add_Str_To_Name_Buffer (" instantiated at ");
239 Name_Buffer (Name_Len + 1) := NUL;
241 end Build_Location_String;
243 ---------------------
244 -- Expr_First_Char --
245 ---------------------
247 function Expr_First_Char (Expr : Node_Id) return Source_Ptr is
249 function First_Char (Expr : Node_Id; PC : Nat) return Source_Ptr;
250 -- Internal recursive function used to traverse the expression tree.
251 -- Returns the source pointer corresponding to the first location of
252 -- the subexpression N, followed by backing up the given (PC) number of
253 -- preceding left parentheses.
259 function First_Char (Expr : Node_Id; PC : Nat) return Source_Ptr is
260 N : constant Node_Id := Original_Node (Expr);
261 Count : constant Nat := PC + Paren_Count (N);
262 Kind : constant N_Subexpr := Nkind (N);
272 return First_Char (Left_Opnd (N), Count);
274 when N_Attribute_Reference |
276 N_Explicit_Dereference |
277 N_Indexed_Component |
279 N_Selected_Component |
281 return First_Char (Prefix (N), Count);
283 when N_Function_Call =>
284 return First_Char (Sinfo.Name (N), Count);
286 when N_Qualified_Expression |
288 return First_Char (Subtype_Mark (N), Count);
291 return First_Char (Low_Bound (N), Count);
293 -- Nodes that should not appear in original expression trees
295 when N_Procedure_Call_Statement |
298 N_Unchecked_Expression |
299 N_Unchecked_Type_Conversion |
300 N_Conditional_Expression =>
303 -- Cases where the Sloc points to the start of the tokem, but we
304 -- still need to handle the sequence of left parentheses.
308 N_Character_Literal |
314 N_Extension_Aggregate |
322 -- This is not right, it does not deal with skipping comments
323 -- and probably also has wide character problems ???
327 SFI : constant Source_File_Index :=
328 Get_Source_File_Index (Loc);
329 Src : constant Source_Buffer_Ptr := Source_Text (SFI);
330 Fst : constant Source_Ptr := Source_First (SFI);
333 for J in 1 .. Count loop
337 exit when Src (Loc) >= ' ';
340 exit when Src (Loc) /= '(';
349 -- Start of processing for Expr_First_Char
352 pragma Assert (Nkind (Expr) in N_Subexpr);
353 return First_Char (Expr, 0);
360 function Expr_Last_Char (Expr : Node_Id) return Source_Ptr is
362 function Last_Char (Expr : Node_Id; PC : Nat) return Source_Ptr;
363 -- Internal recursive function used to traverse the expression tree.
364 -- Returns the source pointer corresponding to the last location of
365 -- the subexpression N, followed by ztepping to the last of the given
366 -- number of right parentheses.
372 function Last_Char (Expr : Node_Id; PC : Nat) return Source_Ptr is
373 N : constant Node_Id := Original_Node (Expr);
374 Count : constant Nat := PC + Paren_Count (N);
375 Kind : constant N_Subexpr := Nkind (N);
385 return Last_Char (Right_Opnd (N), Count);
387 when N_Attribute_Reference |
389 N_Explicit_Dereference |
390 N_Indexed_Component |
392 N_Selected_Component |
394 return Last_Char (Prefix (N), Count);
396 when N_Function_Call =>
397 return Last_Char (Sinfo.Name (N), Count);
399 when N_Qualified_Expression |
401 return Last_Char (Subtype_Mark (N), Count);
404 return Last_Char (Low_Bound (N), Count);
406 -- Nodes that should not appear in original expression trees
408 when N_Procedure_Call_Statement |
411 N_Unchecked_Expression |
412 N_Unchecked_Type_Conversion |
413 N_Conditional_Expression =>
416 -- Cases where the Sloc points to the start of the token, but we
417 -- still need to handle the sequence of left parentheses.
421 N_Character_Literal |
427 N_Extension_Aggregate |
433 -- Now we have two tasks, first we are pointing to the start
434 -- of the token below, second, we need to skip parentheses.
436 -- Skipping to the end of a token is not easy, we can't just
437 -- skip to a space, since we may have e.g. X*YAR+Z, and if we
438 -- are finding the end of the subexpression X*YAR, we don't
439 -- want to skip past the +Z. Also we have to worry about
440 -- skipping comments, and about wide characters ???
443 SFI : constant Source_File_Index :=
444 Get_Source_File_Index (Loc);
445 Src : constant Source_Buffer_Ptr := Source_Text (SFI);
446 Lst : constant Source_Ptr := Source_Last (SFI);
449 -- Scan through first blank character, to get to the end
450 -- of this token. As noted above that's not really right???
453 exit when Loc = Lst or else Src (Loc + 1) <= ' ';
457 -- Skip past parens, but this also ignores comments ???
460 for J in 1 .. Count loop
464 exit when Src (Loc) >= ' ';
467 exit when Src (Loc) /= ')';
476 -- Start of processing for Expr_Last_Char
479 pragma Assert (Nkind (Expr) in N_Subexpr);
480 return Last_Char (Expr, 0);
483 -----------------------
484 -- Get_Column_Number --
485 -----------------------
487 function Get_Column_Number (P : Source_Ptr) return Column_Number is
490 Sindex : Source_File_Index;
491 Src : Source_Buffer_Ptr;
494 -- If the input source pointer is not a meaningful value then return
495 -- at once with column number 1. This can happen for a file not found
496 -- condition for a file loaded indirectly by RTE, and also perhaps on
497 -- some unknown internal error conditions. In either case we certainly
498 -- don't want to blow up.
504 Sindex := Get_Source_File_Index (P);
505 Src := Source_File.Table (Sindex).Source_Text;
511 C := (C - 1) / 8 * 8 + (8 + 1);
521 end Get_Column_Number;
523 -----------------------------
524 -- Get_Logical_Line_Number --
525 -----------------------------
527 function Get_Logical_Line_Number
529 return Logical_Line_Number
531 SFR : Source_File_Record
532 renames Source_File.Table (Get_Source_File_Index (P));
534 L : constant Physical_Line_Number := Get_Physical_Line_Number (P);
537 if SFR.Num_SRef_Pragmas = 0 then
538 return Logical_Line_Number (L);
540 return SFR.Logical_Lines_Table (L);
542 end Get_Logical_Line_Number;
544 ------------------------------
545 -- Get_Physical_Line_Number --
546 ------------------------------
548 function Get_Physical_Line_Number
550 return Physical_Line_Number
552 Sfile : Source_File_Index;
553 Table : Lines_Table_Ptr;
554 Lo : Physical_Line_Number;
555 Hi : Physical_Line_Number;
556 Mid : Physical_Line_Number;
560 -- If the input source pointer is not a meaningful value then return
561 -- at once with line number 1. This can happen for a file not found
562 -- condition for a file loaded indirectly by RTE, and also perhaps on
563 -- some unknown internal error conditions. In either case we certainly
564 -- don't want to blow up.
569 -- Otherwise we can do the binary search
572 Sfile := Get_Source_File_Index (P);
573 Loc := P + Source_File.Table (Sfile).Sloc_Adjust;
574 Table := Source_File.Table (Sfile).Lines_Table;
576 Hi := Source_File.Table (Sfile).Last_Source_Line;
579 Mid := (Lo + Hi) / 2;
581 if Loc < Table (Mid) then
584 else -- Loc >= Table (Mid)
587 Loc < Table (Mid + 1)
598 end Get_Physical_Line_Number;
600 ---------------------------
601 -- Get_Source_File_Index --
602 ---------------------------
604 Source_Cache_First : Source_Ptr := 1;
605 Source_Cache_Last : Source_Ptr := 0;
606 -- Records the First and Last subscript values for the most recently
607 -- referenced entry in the source table, to optimize the common case of
608 -- repeated references to the same entry. The initial values force an
609 -- initial search to set the cache value.
611 Source_Cache_Index : Source_File_Index := No_Source_File;
612 -- Contains the index of the entry corresponding to Source_Cache
614 function Get_Source_File_Index (S : Source_Ptr) return Source_File_Index is
616 if S in Source_Cache_First .. Source_Cache_Last then
617 return Source_Cache_Index;
620 pragma Assert (Source_File_Index_Table (Int (S) / Chunk_Size)
623 for J in Source_File_Index_Table (Int (S) / Chunk_Size)
626 if S in Source_File.Table (J).Source_First ..
627 Source_File.Table (J).Source_Last
629 Source_Cache_Index := J;
630 Source_Cache_First :=
631 Source_File.Table (Source_Cache_Index).Source_First;
633 Source_File.Table (Source_Cache_Index).Source_Last;
634 return Source_Cache_Index;
639 -- We must find a matching entry in the above loop!
642 end Get_Source_File_Index;
648 procedure Initialize is
650 Source_Cache_First := 1;
651 Source_Cache_Last := 0;
652 Source_Cache_Index := No_Source_File;
653 Source_gnat_adc := No_Source_File;
654 First_Time_Around := True;
659 -------------------------
660 -- Instantiation_Depth --
661 -------------------------
663 function Instantiation_Depth (S : Source_Ptr) return Nat is
664 Sind : Source_File_Index;
673 Sind := Get_Source_File_Index (Sval);
674 Sval := Instantiation (Sind);
675 exit when Sval = No_Location;
680 end Instantiation_Depth;
682 ----------------------------
683 -- Instantiation_Location --
684 ----------------------------
686 function Instantiation_Location (S : Source_Ptr) return Source_Ptr is
688 return Instantiation (Get_Source_File_Index (S));
689 end Instantiation_Location;
691 ----------------------
692 -- Last_Source_File --
693 ----------------------
695 function Last_Source_File return Source_File_Index is
697 return Source_File.Last;
698 end Last_Source_File;
704 function Line_Start (P : Source_Ptr) return Source_Ptr is
705 Sindex : constant Source_File_Index := Get_Source_File_Index (P);
706 Src : constant Source_Buffer_Ptr :=
707 Source_File.Table (Sindex).Source_Text;
708 Sfirst : constant Source_Ptr :=
709 Source_File.Table (Sindex).Source_First;
716 and then Src (S - 1) /= CR
717 and then Src (S - 1) /= LF
726 (L : Physical_Line_Number;
727 S : Source_File_Index)
731 return Source_File.Table (S).Lines_Table (L);
740 Source_File.Locked := True;
744 ----------------------
745 -- Num_Source_Files --
746 ----------------------
748 function Num_Source_Files return Nat is
750 return Int (Source_File.Last) - Int (Source_File.First) + 1;
751 end Num_Source_Files;
753 ----------------------
754 -- Num_Source_Lines --
755 ----------------------
757 function Num_Source_Lines (S : Source_File_Index) return Nat is
759 return Nat (Source_File.Table (S).Last_Source_Line);
760 end Num_Source_Lines;
762 -----------------------
763 -- Original_Location --
764 -----------------------
766 function Original_Location (S : Source_Ptr) return Source_Ptr is
767 Sindex : Source_File_Index;
768 Tindex : Source_File_Index;
771 if S <= No_Location then
775 Sindex := Get_Source_File_Index (S);
777 if Instantiation (Sindex) = No_Location then
781 Tindex := Template (Sindex);
782 while Instantiation (Tindex) /= No_Location loop
783 Tindex := Template (Tindex);
786 return S - Source_First (Sindex) + Source_First (Tindex);
789 end Original_Location;
791 -------------------------
792 -- Physical_To_Logical --
793 -------------------------
795 function Physical_To_Logical
796 (Line : Physical_Line_Number;
797 S : Source_File_Index)
798 return Logical_Line_Number
800 SFR : Source_File_Record renames Source_File.Table (S);
803 if SFR.Num_SRef_Pragmas = 0 then
804 return Logical_Line_Number (Line);
806 return SFR.Logical_Lines_Table (Line);
808 end Physical_To_Logical;
810 --------------------------------
811 -- Register_Source_Ref_Pragma --
812 --------------------------------
814 procedure Register_Source_Ref_Pragma
815 (File_Name : File_Name_Type;
816 Stripped_File_Name : File_Name_Type;
818 Line_After_Pragma : Physical_Line_Number)
820 subtype size_t is Memory.size_t;
822 SFR : Source_File_Record renames Source_File.Table (Current_Source_File);
824 ML : Logical_Line_Number;
827 if File_Name /= No_File then
828 SFR.Reference_Name := Stripped_File_Name;
829 SFR.Full_Ref_Name := File_Name;
831 if not Debug_Generated_Code then
832 SFR.Debug_Source_Name := Stripped_File_Name;
833 SFR.Full_Debug_Name := File_Name;
836 SFR.Num_SRef_Pragmas := SFR.Num_SRef_Pragmas + 1;
839 if SFR.Num_SRef_Pragmas = 1 then
840 SFR.First_Mapped_Line := Logical_Line_Number (Mapped_Line);
843 if SFR.Logical_Lines_Table = null then
844 SFR.Logical_Lines_Table := To_Pointer
846 (size_t (SFR.Lines_Table_Max *
847 Logical_Lines_Table_Type'Component_Size /
851 SFR.Logical_Lines_Table (Line_After_Pragma - 1) := No_Line_Number;
853 ML := Logical_Line_Number (Mapped_Line);
854 for J in Line_After_Pragma .. SFR.Last_Source_Line loop
855 SFR.Logical_Lines_Table (J) := ML;
858 end Register_Source_Ref_Pragma;
860 ---------------------------------
861 -- Set_Source_File_Index_Table --
862 ---------------------------------
864 procedure Set_Source_File_Index_Table (Xnew : Source_File_Index) is
867 SL : constant Source_Ptr := Source_File.Table (Xnew).Source_Last;
870 SP := (Source_File.Table (Xnew).Source_First + Chunk_Size - 1)
871 / Chunk_Size * Chunk_Size;
872 Ind := Int (SP) / Chunk_Size;
875 Source_File_Index_Table (Ind) := Xnew;
876 SP := SP + Chunk_Size;
879 end Set_Source_File_Index_Table;
881 ---------------------------
882 -- Skip_Line_Terminators --
883 ---------------------------
885 procedure Skip_Line_Terminators
886 (P : in out Source_Ptr;
887 Physical : out Boolean)
889 Chr : constant Character := Source (P);
893 if Source (P + 1) = LF then
902 elsif Chr = FF or else Chr = VT then
907 -- Otherwise we have a wide character
910 Skip_Wide (Source, P);
913 -- Fall through in the physical line terminator case. First deal with
914 -- making a possible entry into the lines table if one is needed.
916 -- Note: we are dealing with a real source file here, this cannot be
917 -- the instantiation case, so we need not worry about Sloc adjustment.
920 S : Source_File_Record
921 renames Source_File.Table (Current_Source_File);
926 -- Make entry in lines table if not already made (in some scan backup
927 -- cases, we will be rescanning previously scanned source, so the
928 -- entry may have already been made on the previous forward scan).
931 and then P > S.Lines_Table (S.Last_Source_Line)
933 Add_Line_Tables_Entry (S, P);
936 end Skip_Line_Terminators;
942 function Source_Offset (S : Source_Ptr) return Nat is
943 Sindex : constant Source_File_Index := Get_Source_File_Index (S);
944 Sfirst : constant Source_Ptr :=
945 Source_File.Table (Sindex).Source_First;
948 return Nat (S - Sfirst);
951 ------------------------
952 -- Top_Level_Location --
953 ------------------------
955 function Top_Level_Location (S : Source_Ptr) return Source_Ptr is
963 Newloc := Instantiation_Location (Oldloc);
964 exit when Newloc = No_Location;
968 end Top_Level_Location;
974 procedure Tree_Read is
976 -- First we must free any old source buffer pointers
978 if not First_Time_Around then
979 for J in Source_File.First .. Source_File.Last loop
981 S : Source_File_Record renames Source_File.Table (J);
983 procedure Free_Ptr is new Unchecked_Deallocation
984 (Big_Source_Buffer, Source_Buffer_Ptr);
986 pragma Warnings (Off);
987 -- This unchecked conversion is aliasing safe, since it is not
988 -- used to create improperly aliased pointer values.
990 function To_Source_Buffer_Ptr is new
991 Unchecked_Conversion (Address, Source_Buffer_Ptr);
993 pragma Warnings (On);
995 Tmp1 : Source_Buffer_Ptr;
998 if S.Instantiation /= No_Location then
1002 -- Free the buffer, we use Free here, because we used malloc
1003 -- or realloc directly to allocate the tables. That is
1004 -- because we were playing the big array trick. We need to
1005 -- suppress the warning for freeing from an empty pool!
1007 -- We have to recreate a proper pointer to the actual array
1008 -- from the zero origin pointer stored in the source table.
1011 To_Source_Buffer_Ptr
1012 (S.Source_Text (S.Source_First)'Address);
1013 pragma Warnings (Off);
1015 pragma Warnings (On);
1017 if S.Lines_Table /= null then
1018 Memory.Free (To_Address (S.Lines_Table));
1019 S.Lines_Table := null;
1022 if S.Logical_Lines_Table /= null then
1023 Memory.Free (To_Address (S.Logical_Lines_Table));
1024 S.Logical_Lines_Table := null;
1031 -- Reset source cache pointers to force new read
1033 Source_Cache_First := 1;
1034 Source_Cache_Last := 0;
1036 -- Read in source file table
1038 Source_File.Tree_Read;
1040 -- The pointers we read in there for the source buffer and lines
1041 -- table pointers are junk. We now read in the actual data that
1042 -- is referenced by these two fields.
1044 for J in Source_File.First .. Source_File.Last loop
1046 S : Source_File_Record renames Source_File.Table (J);
1049 -- For the instantiation case, we do not read in any data. Instead
1050 -- we share the data for the generic template entry. Since the
1051 -- template always occurs first, we can safely refer to its data.
1053 if S.Instantiation /= No_Location then
1055 ST : Source_File_Record renames
1056 Source_File.Table (S.Template);
1059 -- The lines tables are copied from the template entry
1062 Source_File.Table (S.Template).Lines_Table;
1063 S.Logical_Lines_Table :=
1064 Source_File.Table (S.Template).Logical_Lines_Table;
1066 -- In the case of the source table pointer, we share the
1067 -- same data as the generic template, but the virtual origin
1068 -- is adjusted. For example, if the first subscript of the
1069 -- template is 100, and that of the instantiation is 200,
1070 -- then the instantiation pointer is obtained by subtracting
1071 -- 100 from the template pointer.
1074 pragma Suppress (All_Checks);
1076 pragma Warnings (Off);
1077 -- This unchecked conversion is aliasing safe since it
1078 -- not used to create improperly aliased pointer values.
1080 function To_Source_Buffer_Ptr is new
1081 Unchecked_Conversion (Address, Source_Buffer_Ptr);
1083 pragma Warnings (On);
1087 To_Source_Buffer_Ptr
1089 (ST.Source_First - S.Source_First)'Address);
1093 -- Normal case (non-instantiation)
1096 First_Time_Around := False;
1097 S.Lines_Table := null;
1098 S.Logical_Lines_Table := null;
1099 Alloc_Line_Tables (S, Int (S.Last_Source_Line));
1101 for J in 1 .. S.Last_Source_Line loop
1102 Tree_Read_Int (Int (S.Lines_Table (J)));
1105 if S.Num_SRef_Pragmas /= 0 then
1106 for J in 1 .. S.Last_Source_Line loop
1107 Tree_Read_Int (Int (S.Logical_Lines_Table (J)));
1111 -- Allocate source buffer and read in the data and then set the
1112 -- virtual origin to point to the logical zero'th element. This
1113 -- address must be computed with subscript checks turned off.
1116 subtype B is Text_Buffer (S.Source_First .. S.Source_Last);
1117 type Text_Buffer_Ptr is access B;
1118 T : Text_Buffer_Ptr;
1120 pragma Suppress (All_Checks);
1122 pragma Warnings (Off);
1123 -- This unchecked conversion is aliasing safe, since it is
1124 -- never used to create improperly aliased pointer values.
1126 function To_Source_Buffer_Ptr is new
1127 Unchecked_Conversion (Address, Source_Buffer_Ptr);
1129 pragma Warnings (On);
1134 Tree_Read_Data (T (S.Source_First)'Address,
1135 Int (S.Source_Last) - Int (S.Source_First) + 1);
1137 S.Source_Text := To_Source_Buffer_Ptr (T (0)'Address);
1142 Set_Source_File_Index_Table (J);
1150 procedure Tree_Write is
1152 Source_File.Tree_Write;
1154 -- The pointers we wrote out there for the source buffer and lines
1155 -- table pointers are junk, we now write out the actual data that
1156 -- is referenced by these two fields.
1158 for J in Source_File.First .. Source_File.Last loop
1160 S : Source_File_Record renames Source_File.Table (J);
1163 -- For instantiations, there is nothing to do, since the data is
1164 -- shared with the generic template. When the tree is read, the
1165 -- pointers must be set, but no extra data needs to be written.
1167 if S.Instantiation /= No_Location then
1170 -- For the normal case, write out the data of the tables
1175 for J in 1 .. S.Last_Source_Line loop
1176 Tree_Write_Int (Int (S.Lines_Table (J)));
1179 -- Logical lines table if present
1181 if S.Num_SRef_Pragmas /= 0 then
1182 for J in 1 .. S.Last_Source_Line loop
1183 Tree_Write_Int (Int (S.Logical_Lines_Table (J)));
1190 (S.Source_Text (S.Source_First)'Address,
1191 Int (S.Source_Last) - Int (S.Source_First) + 1);
1197 --------------------
1198 -- Write_Location --
1199 --------------------
1201 procedure Write_Location (P : Source_Ptr) is
1203 if P = No_Location then
1204 Write_Str ("<no location>");
1206 elsif P <= Standard_Location then
1207 Write_Str ("<standard location>");
1211 SI : constant Source_File_Index := Get_Source_File_Index (P);
1214 Write_Name (Debug_Source_Name (SI));
1216 Write_Int (Int (Get_Logical_Line_Number (P)));
1218 Write_Int (Int (Get_Column_Number (P)));
1220 if Instantiation (SI) /= No_Location then
1222 Write_Location (Instantiation (SI));
1229 ----------------------
1230 -- Write_Time_Stamp --
1231 ----------------------
1233 procedure Write_Time_Stamp (S : Source_File_Index) is
1234 T : constant Time_Stamp_Type := Time_Stamp (S);
1247 Write_Char (T (P + 1));
1248 Write_Char (T (P + 2));
1251 Write_Char (T (P + 3));
1252 Write_Char (T (P + 4));
1255 Write_Char (T (P + 5));
1256 Write_Char (T (P + 6));
1259 Write_Char (T (P + 7));
1260 Write_Char (T (P + 8));
1263 Write_Char (T (P + 9));
1264 Write_Char (T (P + 10));
1267 Write_Char (T (P + 11));
1268 Write_Char (T (P + 12));
1269 end Write_Time_Stamp;
1271 ----------------------------------------------
1272 -- Access Subprograms for Source File Table --
1273 ----------------------------------------------
1275 function Debug_Source_Name (S : SFI) return File_Name_Type is
1277 return Source_File.Table (S).Debug_Source_Name;
1278 end Debug_Source_Name;
1280 function File_Name (S : SFI) return File_Name_Type is
1282 return Source_File.Table (S).File_Name;
1285 function File_Type (S : SFI) return Type_Of_File is
1287 return Source_File.Table (S).File_Type;
1290 function First_Mapped_Line (S : SFI) return Logical_Line_Number is
1292 return Source_File.Table (S).First_Mapped_Line;
1293 end First_Mapped_Line;
1295 function Full_Debug_Name (S : SFI) return File_Name_Type is
1297 return Source_File.Table (S).Full_Debug_Name;
1298 end Full_Debug_Name;
1300 function Full_File_Name (S : SFI) return File_Name_Type is
1302 return Source_File.Table (S).Full_File_Name;
1305 function Full_Ref_Name (S : SFI) return File_Name_Type is
1307 return Source_File.Table (S).Full_Ref_Name;
1310 function Identifier_Casing (S : SFI) return Casing_Type is
1312 return Source_File.Table (S).Identifier_Casing;
1313 end Identifier_Casing;
1315 function Inlined_Body (S : SFI) return Boolean is
1317 return Source_File.Table (S).Inlined_Body;
1320 function Instantiation (S : SFI) return Source_Ptr is
1322 return Source_File.Table (S).Instantiation;
1325 function Keyword_Casing (S : SFI) return Casing_Type is
1327 return Source_File.Table (S).Keyword_Casing;
1330 function Last_Source_Line (S : SFI) return Physical_Line_Number is
1332 return Source_File.Table (S).Last_Source_Line;
1333 end Last_Source_Line;
1335 function License (S : SFI) return License_Type is
1337 return Source_File.Table (S).License;
1340 function Num_SRef_Pragmas (S : SFI) return Nat is
1342 return Source_File.Table (S).Num_SRef_Pragmas;
1343 end Num_SRef_Pragmas;
1345 function Reference_Name (S : SFI) return File_Name_Type is
1347 return Source_File.Table (S).Reference_Name;
1350 function Source_Checksum (S : SFI) return Word is
1352 return Source_File.Table (S).Source_Checksum;
1353 end Source_Checksum;
1355 function Source_First (S : SFI) return Source_Ptr is
1357 if S = Internal_Source_File then
1358 return Internal_Source'First;
1360 return Source_File.Table (S).Source_First;
1364 function Source_Last (S : SFI) return Source_Ptr is
1366 if S = Internal_Source_File then
1367 return Internal_Source'Last;
1369 return Source_File.Table (S).Source_Last;
1374 function Source_Text (S : SFI) return Source_Buffer_Ptr is
1376 if S = Internal_Source_File then
1377 return Internal_Source_Ptr;
1379 return Source_File.Table (S).Source_Text;
1384 function Template (S : SFI) return SFI is
1386 return Source_File.Table (S).Template;
1389 function Time_Stamp (S : SFI) return Time_Stamp_Type is
1391 return Source_File.Table (S).Time_Stamp;
1394 function Unit (S : SFI) return Unit_Number_Type is
1396 return Source_File.Table (S).Unit;
1399 ------------------------------------------
1400 -- Set Procedures for Source File Table --
1401 ------------------------------------------
1403 procedure Set_Identifier_Casing (S : SFI; C : Casing_Type) is
1405 Source_File.Table (S).Identifier_Casing := C;
1406 end Set_Identifier_Casing;
1408 procedure Set_Keyword_Casing (S : SFI; C : Casing_Type) is
1410 Source_File.Table (S).Keyword_Casing := C;
1411 end Set_Keyword_Casing;
1413 procedure Set_License (S : SFI; L : License_Type) is
1415 Source_File.Table (S).License := L;
1418 procedure Set_Unit (S : SFI; U : Unit_Number_Type) is
1420 Source_File.Table (S).Unit := U;
1423 ----------------------
1424 -- Trim_Lines_Table --
1425 ----------------------
1427 procedure Trim_Lines_Table (S : Source_File_Index) is
1428 Max : constant Nat := Nat (Source_File.Table (S).Last_Source_Line);
1431 -- Release allocated storage that is no longer needed
1433 Source_File.Table (S).Lines_Table := To_Pointer
1435 (To_Address (Source_File.Table (S).Lines_Table),
1437 (Max * (Lines_Table_Type'Component_Size / System.Storage_Unit))));
1438 Source_File.Table (S).Lines_Table_Max := Physical_Line_Number (Max);
1439 end Trim_Lines_Table;
1447 Source_File.Locked := False;
1448 Source_File.Release;
1455 procedure wl (P : Source_Ptr) is