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 SFI : constant Source_File_Index :=
323 Get_Source_File_Index (Loc);
324 Src : constant Source_Buffer_Ptr := Source_Text (SFI);
325 Fst : constant Source_Ptr := Source_First (SFI);
328 for J in 1 .. Count loop
332 exit when Src (Loc) >= ' ';
335 exit when Src (Loc) /= '(';
344 -- Start of processing for Expr_First_Char
347 pragma Assert (Nkind (Expr) in N_Subexpr);
348 return First_Char (Expr, 0);
355 function Expr_Last_Char (Expr : Node_Id) return Source_Ptr is
357 function Last_Char (Expr : Node_Id; PC : Nat) return Source_Ptr;
358 -- Internal recursive function used to traverse the expression tree.
359 -- Returns the source pointer corresponding to the last location of
360 -- the subexpression N, followed by ztepping to the last of the given
361 -- number of right parentheses.
367 function Last_Char (Expr : Node_Id; PC : Nat) return Source_Ptr is
368 N : constant Node_Id := Original_Node (Expr);
369 Count : constant Nat := PC + Paren_Count (N);
370 Kind : constant N_Subexpr := Nkind (N);
380 return Last_Char (Right_Opnd (N), Count);
382 when N_Attribute_Reference |
384 N_Explicit_Dereference |
385 N_Indexed_Component |
387 N_Selected_Component |
389 return Last_Char (Prefix (N), Count);
391 when N_Function_Call =>
392 return Last_Char (Sinfo.Name (N), Count);
394 when N_Qualified_Expression |
396 return Last_Char (Subtype_Mark (N), Count);
399 return Last_Char (Low_Bound (N), Count);
401 -- Nodes that should not appear in original expression trees
403 when N_Procedure_Call_Statement |
406 N_Unchecked_Expression |
407 N_Unchecked_Type_Conversion |
408 N_Conditional_Expression =>
411 -- Cases where the Sloc points to the start of the tokem, but we
412 -- still need to handle the sequence of left parentheses.
416 N_Character_Literal |
422 N_Extension_Aggregate |
430 SFI : constant Source_File_Index :=
431 Get_Source_File_Index (Loc);
432 Src : constant Source_Buffer_Ptr := Source_Text (SFI);
433 Fst : constant Source_Ptr := Source_Last (SFI);
436 for J in 1 .. Count loop
440 exit when Src (Loc) >= ' ';
443 exit when Src (Loc) /= '(';
452 -- Start of processing for Expr_Last_Char
455 pragma Assert (Nkind (Expr) in N_Subexpr);
456 return Last_Char (Expr, 0);
459 -----------------------
460 -- Get_Column_Number --
461 -----------------------
463 function Get_Column_Number (P : Source_Ptr) return Column_Number is
466 Sindex : Source_File_Index;
467 Src : Source_Buffer_Ptr;
470 -- If the input source pointer is not a meaningful value then return
471 -- at once with column number 1. This can happen for a file not found
472 -- condition for a file loaded indirectly by RTE, and also perhaps on
473 -- some unknown internal error conditions. In either case we certainly
474 -- don't want to blow up.
480 Sindex := Get_Source_File_Index (P);
481 Src := Source_File.Table (Sindex).Source_Text;
487 C := (C - 1) / 8 * 8 + (8 + 1);
497 end Get_Column_Number;
499 -----------------------------
500 -- Get_Logical_Line_Number --
501 -----------------------------
503 function Get_Logical_Line_Number
505 return Logical_Line_Number
507 SFR : Source_File_Record
508 renames Source_File.Table (Get_Source_File_Index (P));
510 L : constant Physical_Line_Number := Get_Physical_Line_Number (P);
513 if SFR.Num_SRef_Pragmas = 0 then
514 return Logical_Line_Number (L);
516 return SFR.Logical_Lines_Table (L);
518 end Get_Logical_Line_Number;
520 ------------------------------
521 -- Get_Physical_Line_Number --
522 ------------------------------
524 function Get_Physical_Line_Number
526 return Physical_Line_Number
528 Sfile : Source_File_Index;
529 Table : Lines_Table_Ptr;
530 Lo : Physical_Line_Number;
531 Hi : Physical_Line_Number;
532 Mid : Physical_Line_Number;
536 -- If the input source pointer is not a meaningful value then return
537 -- at once with line number 1. This can happen for a file not found
538 -- condition for a file loaded indirectly by RTE, and also perhaps on
539 -- some unknown internal error conditions. In either case we certainly
540 -- don't want to blow up.
545 -- Otherwise we can do the binary search
548 Sfile := Get_Source_File_Index (P);
549 Loc := P + Source_File.Table (Sfile).Sloc_Adjust;
550 Table := Source_File.Table (Sfile).Lines_Table;
552 Hi := Source_File.Table (Sfile).Last_Source_Line;
555 Mid := (Lo + Hi) / 2;
557 if Loc < Table (Mid) then
560 else -- Loc >= Table (Mid)
563 Loc < Table (Mid + 1)
574 end Get_Physical_Line_Number;
576 ---------------------------
577 -- Get_Source_File_Index --
578 ---------------------------
580 Source_Cache_First : Source_Ptr := 1;
581 Source_Cache_Last : Source_Ptr := 0;
582 -- Records the First and Last subscript values for the most recently
583 -- referenced entry in the source table, to optimize the common case of
584 -- repeated references to the same entry. The initial values force an
585 -- initial search to set the cache value.
587 Source_Cache_Index : Source_File_Index := No_Source_File;
588 -- Contains the index of the entry corresponding to Source_Cache
590 function Get_Source_File_Index (S : Source_Ptr) return Source_File_Index is
592 if S in Source_Cache_First .. Source_Cache_Last then
593 return Source_Cache_Index;
596 pragma Assert (Source_File_Index_Table (Int (S) / Chunk_Size)
599 for J in Source_File_Index_Table (Int (S) / Chunk_Size)
602 if S in Source_File.Table (J).Source_First ..
603 Source_File.Table (J).Source_Last
605 Source_Cache_Index := J;
606 Source_Cache_First :=
607 Source_File.Table (Source_Cache_Index).Source_First;
609 Source_File.Table (Source_Cache_Index).Source_Last;
610 return Source_Cache_Index;
615 -- We must find a matching entry in the above loop!
618 end Get_Source_File_Index;
624 procedure Initialize is
626 Source_Cache_First := 1;
627 Source_Cache_Last := 0;
628 Source_Cache_Index := No_Source_File;
629 Source_gnat_adc := No_Source_File;
630 First_Time_Around := True;
635 -------------------------
636 -- Instantiation_Depth --
637 -------------------------
639 function Instantiation_Depth (S : Source_Ptr) return Nat is
640 Sind : Source_File_Index;
649 Sind := Get_Source_File_Index (Sval);
650 Sval := Instantiation (Sind);
651 exit when Sval = No_Location;
656 end Instantiation_Depth;
658 ----------------------------
659 -- Instantiation_Location --
660 ----------------------------
662 function Instantiation_Location (S : Source_Ptr) return Source_Ptr is
664 return Instantiation (Get_Source_File_Index (S));
665 end Instantiation_Location;
667 ----------------------
668 -- Last_Source_File --
669 ----------------------
671 function Last_Source_File return Source_File_Index is
673 return Source_File.Last;
674 end Last_Source_File;
680 function Line_Start (P : Source_Ptr) return Source_Ptr is
681 Sindex : constant Source_File_Index := Get_Source_File_Index (P);
682 Src : constant Source_Buffer_Ptr :=
683 Source_File.Table (Sindex).Source_Text;
684 Sfirst : constant Source_Ptr :=
685 Source_File.Table (Sindex).Source_First;
692 and then Src (S - 1) /= CR
693 and then Src (S - 1) /= LF
702 (L : Physical_Line_Number;
703 S : Source_File_Index)
707 return Source_File.Table (S).Lines_Table (L);
716 Source_File.Locked := True;
720 ----------------------
721 -- Num_Source_Files --
722 ----------------------
724 function Num_Source_Files return Nat is
726 return Int (Source_File.Last) - Int (Source_File.First) + 1;
727 end Num_Source_Files;
729 ----------------------
730 -- Num_Source_Lines --
731 ----------------------
733 function Num_Source_Lines (S : Source_File_Index) return Nat is
735 return Nat (Source_File.Table (S).Last_Source_Line);
736 end Num_Source_Lines;
738 -----------------------
739 -- Original_Location --
740 -----------------------
742 function Original_Location (S : Source_Ptr) return Source_Ptr is
743 Sindex : Source_File_Index;
744 Tindex : Source_File_Index;
747 if S <= No_Location then
751 Sindex := Get_Source_File_Index (S);
753 if Instantiation (Sindex) = No_Location then
757 Tindex := Template (Sindex);
758 while Instantiation (Tindex) /= No_Location loop
759 Tindex := Template (Tindex);
762 return S - Source_First (Sindex) + Source_First (Tindex);
765 end Original_Location;
767 -------------------------
768 -- Physical_To_Logical --
769 -------------------------
771 function Physical_To_Logical
772 (Line : Physical_Line_Number;
773 S : Source_File_Index)
774 return Logical_Line_Number
776 SFR : Source_File_Record renames Source_File.Table (S);
779 if SFR.Num_SRef_Pragmas = 0 then
780 return Logical_Line_Number (Line);
782 return SFR.Logical_Lines_Table (Line);
784 end Physical_To_Logical;
786 --------------------------------
787 -- Register_Source_Ref_Pragma --
788 --------------------------------
790 procedure Register_Source_Ref_Pragma
791 (File_Name : File_Name_Type;
792 Stripped_File_Name : File_Name_Type;
794 Line_After_Pragma : Physical_Line_Number)
796 subtype size_t is Memory.size_t;
798 SFR : Source_File_Record renames Source_File.Table (Current_Source_File);
800 ML : Logical_Line_Number;
803 if File_Name /= No_File then
804 SFR.Reference_Name := Stripped_File_Name;
805 SFR.Full_Ref_Name := File_Name;
807 if not Debug_Generated_Code then
808 SFR.Debug_Source_Name := Stripped_File_Name;
809 SFR.Full_Debug_Name := File_Name;
812 SFR.Num_SRef_Pragmas := SFR.Num_SRef_Pragmas + 1;
815 if SFR.Num_SRef_Pragmas = 1 then
816 SFR.First_Mapped_Line := Logical_Line_Number (Mapped_Line);
819 if SFR.Logical_Lines_Table = null then
820 SFR.Logical_Lines_Table := To_Pointer
822 (size_t (SFR.Lines_Table_Max *
823 Logical_Lines_Table_Type'Component_Size /
827 SFR.Logical_Lines_Table (Line_After_Pragma - 1) := No_Line_Number;
829 ML := Logical_Line_Number (Mapped_Line);
830 for J in Line_After_Pragma .. SFR.Last_Source_Line loop
831 SFR.Logical_Lines_Table (J) := ML;
834 end Register_Source_Ref_Pragma;
836 ---------------------------------
837 -- Set_Source_File_Index_Table --
838 ---------------------------------
840 procedure Set_Source_File_Index_Table (Xnew : Source_File_Index) is
843 SL : constant Source_Ptr := Source_File.Table (Xnew).Source_Last;
846 SP := (Source_File.Table (Xnew).Source_First + Chunk_Size - 1)
847 / Chunk_Size * Chunk_Size;
848 Ind := Int (SP) / Chunk_Size;
851 Source_File_Index_Table (Ind) := Xnew;
852 SP := SP + Chunk_Size;
855 end Set_Source_File_Index_Table;
857 ---------------------------
858 -- Skip_Line_Terminators --
859 ---------------------------
861 procedure Skip_Line_Terminators
862 (P : in out Source_Ptr;
863 Physical : out Boolean)
865 Chr : constant Character := Source (P);
869 if Source (P + 1) = LF then
878 elsif Chr = FF or else Chr = VT then
883 -- Otherwise we have a wide character
886 Skip_Wide (Source, P);
889 -- Fall through in the physical line terminator case. First deal with
890 -- making a possible entry into the lines table if one is needed.
892 -- Note: we are dealing with a real source file here, this cannot be
893 -- the instantiation case, so we need not worry about Sloc adjustment.
896 S : Source_File_Record
897 renames Source_File.Table (Current_Source_File);
902 -- Make entry in lines table if not already made (in some scan backup
903 -- cases, we will be rescanning previously scanned source, so the
904 -- entry may have already been made on the previous forward scan).
907 and then P > S.Lines_Table (S.Last_Source_Line)
909 Add_Line_Tables_Entry (S, P);
912 end Skip_Line_Terminators;
918 function Source_Offset (S : Source_Ptr) return Nat is
919 Sindex : constant Source_File_Index := Get_Source_File_Index (S);
920 Sfirst : constant Source_Ptr :=
921 Source_File.Table (Sindex).Source_First;
924 return Nat (S - Sfirst);
927 ------------------------
928 -- Top_Level_Location --
929 ------------------------
931 function Top_Level_Location (S : Source_Ptr) return Source_Ptr is
939 Newloc := Instantiation_Location (Oldloc);
940 exit when Newloc = No_Location;
944 end Top_Level_Location;
950 procedure Tree_Read is
952 -- First we must free any old source buffer pointers
954 if not First_Time_Around then
955 for J in Source_File.First .. Source_File.Last loop
957 S : Source_File_Record renames Source_File.Table (J);
959 procedure Free_Ptr is new Unchecked_Deallocation
960 (Big_Source_Buffer, Source_Buffer_Ptr);
962 pragma Warnings (Off);
963 -- This unchecked conversion is aliasing safe, since it is not
964 -- used to create improperly aliased pointer values.
966 function To_Source_Buffer_Ptr is new
967 Unchecked_Conversion (Address, Source_Buffer_Ptr);
969 pragma Warnings (On);
971 Tmp1 : Source_Buffer_Ptr;
974 if S.Instantiation /= No_Location then
978 -- Free the buffer, we use Free here, because we used malloc
979 -- or realloc directly to allocate the tables. That is
980 -- because we were playing the big array trick. We need to
981 -- suppress the warning for freeing from an empty pool!
983 -- We have to recreate a proper pointer to the actual array
984 -- from the zero origin pointer stored in the source table.
988 (S.Source_Text (S.Source_First)'Address);
989 pragma Warnings (Off);
991 pragma Warnings (On);
993 if S.Lines_Table /= null then
994 Memory.Free (To_Address (S.Lines_Table));
995 S.Lines_Table := null;
998 if S.Logical_Lines_Table /= null then
999 Memory.Free (To_Address (S.Logical_Lines_Table));
1000 S.Logical_Lines_Table := null;
1007 -- Reset source cache pointers to force new read
1009 Source_Cache_First := 1;
1010 Source_Cache_Last := 0;
1012 -- Read in source file table
1014 Source_File.Tree_Read;
1016 -- The pointers we read in there for the source buffer and lines
1017 -- table pointers are junk. We now read in the actual data that
1018 -- is referenced by these two fields.
1020 for J in Source_File.First .. Source_File.Last loop
1022 S : Source_File_Record renames Source_File.Table (J);
1025 -- For the instantiation case, we do not read in any data. Instead
1026 -- we share the data for the generic template entry. Since the
1027 -- template always occurs first, we can safely refer to its data.
1029 if S.Instantiation /= No_Location then
1031 ST : Source_File_Record renames
1032 Source_File.Table (S.Template);
1035 -- The lines tables are copied from the template entry
1038 Source_File.Table (S.Template).Lines_Table;
1039 S.Logical_Lines_Table :=
1040 Source_File.Table (S.Template).Logical_Lines_Table;
1042 -- In the case of the source table pointer, we share the
1043 -- same data as the generic template, but the virtual origin
1044 -- is adjusted. For example, if the first subscript of the
1045 -- template is 100, and that of the instantiation is 200,
1046 -- then the instantiation pointer is obtained by subtracting
1047 -- 100 from the template pointer.
1050 pragma Suppress (All_Checks);
1052 pragma Warnings (Off);
1053 -- This unchecked conversion is aliasing safe since it
1054 -- not used to create improperly aliased pointer values.
1056 function To_Source_Buffer_Ptr is new
1057 Unchecked_Conversion (Address, Source_Buffer_Ptr);
1059 pragma Warnings (On);
1063 To_Source_Buffer_Ptr
1065 (ST.Source_First - S.Source_First)'Address);
1069 -- Normal case (non-instantiation)
1072 First_Time_Around := False;
1073 S.Lines_Table := null;
1074 S.Logical_Lines_Table := null;
1075 Alloc_Line_Tables (S, Int (S.Last_Source_Line));
1077 for J in 1 .. S.Last_Source_Line loop
1078 Tree_Read_Int (Int (S.Lines_Table (J)));
1081 if S.Num_SRef_Pragmas /= 0 then
1082 for J in 1 .. S.Last_Source_Line loop
1083 Tree_Read_Int (Int (S.Logical_Lines_Table (J)));
1087 -- Allocate source buffer and read in the data and then set the
1088 -- virtual origin to point to the logical zero'th element. This
1089 -- address must be computed with subscript checks turned off.
1092 subtype B is Text_Buffer (S.Source_First .. S.Source_Last);
1093 type Text_Buffer_Ptr is access B;
1094 T : Text_Buffer_Ptr;
1096 pragma Suppress (All_Checks);
1098 pragma Warnings (Off);
1099 -- This unchecked conversion is aliasing safe, since it is
1100 -- never used to create improperly aliased pointer values.
1102 function To_Source_Buffer_Ptr is new
1103 Unchecked_Conversion (Address, Source_Buffer_Ptr);
1105 pragma Warnings (On);
1110 Tree_Read_Data (T (S.Source_First)'Address,
1111 Int (S.Source_Last) - Int (S.Source_First) + 1);
1113 S.Source_Text := To_Source_Buffer_Ptr (T (0)'Address);
1118 Set_Source_File_Index_Table (J);
1126 procedure Tree_Write is
1128 Source_File.Tree_Write;
1130 -- The pointers we wrote out there for the source buffer and lines
1131 -- table pointers are junk, we now write out the actual data that
1132 -- is referenced by these two fields.
1134 for J in Source_File.First .. Source_File.Last loop
1136 S : Source_File_Record renames Source_File.Table (J);
1139 -- For instantiations, there is nothing to do, since the data is
1140 -- shared with the generic template. When the tree is read, the
1141 -- pointers must be set, but no extra data needs to be written.
1143 if S.Instantiation /= No_Location then
1146 -- For the normal case, write out the data of the tables
1151 for J in 1 .. S.Last_Source_Line loop
1152 Tree_Write_Int (Int (S.Lines_Table (J)));
1155 -- Logical lines table if present
1157 if S.Num_SRef_Pragmas /= 0 then
1158 for J in 1 .. S.Last_Source_Line loop
1159 Tree_Write_Int (Int (S.Logical_Lines_Table (J)));
1166 (S.Source_Text (S.Source_First)'Address,
1167 Int (S.Source_Last) - Int (S.Source_First) + 1);
1173 --------------------
1174 -- Write_Location --
1175 --------------------
1177 procedure Write_Location (P : Source_Ptr) is
1179 if P = No_Location then
1180 Write_Str ("<no location>");
1182 elsif P <= Standard_Location then
1183 Write_Str ("<standard location>");
1187 SI : constant Source_File_Index := Get_Source_File_Index (P);
1190 Write_Name (Debug_Source_Name (SI));
1192 Write_Int (Int (Get_Logical_Line_Number (P)));
1194 Write_Int (Int (Get_Column_Number (P)));
1196 if Instantiation (SI) /= No_Location then
1198 Write_Location (Instantiation (SI));
1205 ----------------------
1206 -- Write_Time_Stamp --
1207 ----------------------
1209 procedure Write_Time_Stamp (S : Source_File_Index) is
1210 T : constant Time_Stamp_Type := Time_Stamp (S);
1223 Write_Char (T (P + 1));
1224 Write_Char (T (P + 2));
1227 Write_Char (T (P + 3));
1228 Write_Char (T (P + 4));
1231 Write_Char (T (P + 5));
1232 Write_Char (T (P + 6));
1235 Write_Char (T (P + 7));
1236 Write_Char (T (P + 8));
1239 Write_Char (T (P + 9));
1240 Write_Char (T (P + 10));
1243 Write_Char (T (P + 11));
1244 Write_Char (T (P + 12));
1245 end Write_Time_Stamp;
1247 ----------------------------------------------
1248 -- Access Subprograms for Source File Table --
1249 ----------------------------------------------
1251 function Debug_Source_Name (S : SFI) return File_Name_Type is
1253 return Source_File.Table (S).Debug_Source_Name;
1254 end Debug_Source_Name;
1256 function File_Name (S : SFI) return File_Name_Type is
1258 return Source_File.Table (S).File_Name;
1261 function File_Type (S : SFI) return Type_Of_File is
1263 return Source_File.Table (S).File_Type;
1266 function First_Mapped_Line (S : SFI) return Logical_Line_Number is
1268 return Source_File.Table (S).First_Mapped_Line;
1269 end First_Mapped_Line;
1271 function Full_Debug_Name (S : SFI) return File_Name_Type is
1273 return Source_File.Table (S).Full_Debug_Name;
1274 end Full_Debug_Name;
1276 function Full_File_Name (S : SFI) return File_Name_Type is
1278 return Source_File.Table (S).Full_File_Name;
1281 function Full_Ref_Name (S : SFI) return File_Name_Type is
1283 return Source_File.Table (S).Full_Ref_Name;
1286 function Identifier_Casing (S : SFI) return Casing_Type is
1288 return Source_File.Table (S).Identifier_Casing;
1289 end Identifier_Casing;
1291 function Inlined_Body (S : SFI) return Boolean is
1293 return Source_File.Table (S).Inlined_Body;
1296 function Instantiation (S : SFI) return Source_Ptr is
1298 return Source_File.Table (S).Instantiation;
1301 function Keyword_Casing (S : SFI) return Casing_Type is
1303 return Source_File.Table (S).Keyword_Casing;
1306 function Last_Source_Line (S : SFI) return Physical_Line_Number is
1308 return Source_File.Table (S).Last_Source_Line;
1309 end Last_Source_Line;
1311 function License (S : SFI) return License_Type is
1313 return Source_File.Table (S).License;
1316 function Num_SRef_Pragmas (S : SFI) return Nat is
1318 return Source_File.Table (S).Num_SRef_Pragmas;
1319 end Num_SRef_Pragmas;
1321 function Reference_Name (S : SFI) return File_Name_Type is
1323 return Source_File.Table (S).Reference_Name;
1326 function Source_Checksum (S : SFI) return Word is
1328 return Source_File.Table (S).Source_Checksum;
1329 end Source_Checksum;
1331 function Source_First (S : SFI) return Source_Ptr is
1333 if S = Internal_Source_File then
1334 return Internal_Source'First;
1336 return Source_File.Table (S).Source_First;
1340 function Source_Last (S : SFI) return Source_Ptr is
1342 if S = Internal_Source_File then
1343 return Internal_Source'Last;
1345 return Source_File.Table (S).Source_Last;
1350 function Source_Text (S : SFI) return Source_Buffer_Ptr is
1352 if S = Internal_Source_File then
1353 return Internal_Source_Ptr;
1355 return Source_File.Table (S).Source_Text;
1360 function Template (S : SFI) return SFI is
1362 return Source_File.Table (S).Template;
1365 function Time_Stamp (S : SFI) return Time_Stamp_Type is
1367 return Source_File.Table (S).Time_Stamp;
1370 function Unit (S : SFI) return Unit_Number_Type is
1372 return Source_File.Table (S).Unit;
1375 ------------------------------------------
1376 -- Set Procedures for Source File Table --
1377 ------------------------------------------
1379 procedure Set_Identifier_Casing (S : SFI; C : Casing_Type) is
1381 Source_File.Table (S).Identifier_Casing := C;
1382 end Set_Identifier_Casing;
1384 procedure Set_Keyword_Casing (S : SFI; C : Casing_Type) is
1386 Source_File.Table (S).Keyword_Casing := C;
1387 end Set_Keyword_Casing;
1389 procedure Set_License (S : SFI; L : License_Type) is
1391 Source_File.Table (S).License := L;
1394 procedure Set_Unit (S : SFI; U : Unit_Number_Type) is
1396 Source_File.Table (S).Unit := U;
1399 ----------------------
1400 -- Trim_Lines_Table --
1401 ----------------------
1403 procedure Trim_Lines_Table (S : Source_File_Index) is
1404 Max : constant Nat := Nat (Source_File.Table (S).Last_Source_Line);
1407 -- Release allocated storage that is no longer needed
1409 Source_File.Table (S).Lines_Table := To_Pointer
1411 (To_Address (Source_File.Table (S).Lines_Table),
1413 (Max * (Lines_Table_Type'Component_Size / System.Storage_Unit))));
1414 Source_File.Table (S).Lines_Table_Max := Physical_Line_Number (Max);
1415 end Trim_Lines_Table;
1423 Source_File.Locked := False;
1424 Source_File.Release;
1431 procedure wl (P : Source_Ptr) is