1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2012, 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 Scans
; use Scans
;
40 with Tree_IO
; use Tree_IO
;
41 with Widechar
; use Widechar
;
43 with GNAT
.Byte_Order_Mark
; use GNAT
.Byte_Order_Mark
;
45 with System
; use System
;
47 with System
.WCh_Con
; use System
.WCh_Con
;
49 with Unchecked_Conversion
;
50 with Unchecked_Deallocation
;
52 package body Sinput
is
55 -- Make control characters visible
57 First_Time_Around
: Boolean := True;
58 -- This needs a comment ???
60 -- Routines to support conversion between types Lines_Table_Ptr,
61 -- Logical_Lines_Table_Ptr and System.Address.
63 pragma Warnings
(Off
);
64 -- These unchecked conversions are aliasing safe, since they are never
65 -- used to construct improperly aliased pointer values.
67 function To_Address
is
68 new Unchecked_Conversion
(Lines_Table_Ptr
, Address
);
70 function To_Address
is
71 new Unchecked_Conversion
(Logical_Lines_Table_Ptr
, Address
);
73 function To_Pointer
is
74 new Unchecked_Conversion
(Address
, Lines_Table_Ptr
);
76 function To_Pointer
is
77 new Unchecked_Conversion
(Address
, Logical_Lines_Table_Ptr
);
81 ---------------------------
82 -- Add_Line_Tables_Entry --
83 ---------------------------
85 procedure Add_Line_Tables_Entry
86 (S
: in out Source_File_Record
;
89 LL
: Physical_Line_Number
;
92 -- Reallocate the lines tables if necessary
94 -- Note: the reason we do not use the normal Table package
95 -- mechanism is that we have several of these tables. We could
96 -- use the new GNAT.Dynamic_Tables package and that would probably
99 if S
.Last_Source_Line
= S
.Lines_Table_Max
then
102 Int
(S
.Last_Source_Line
) *
103 ((100 + Alloc
.Lines_Increment
) / 100));
106 Write_Str
("--> Reallocating lines table, size = ");
107 Write_Int
(Int
(S
.Lines_Table_Max
));
112 S
.Last_Source_Line
:= S
.Last_Source_Line
+ 1;
113 LL
:= S
.Last_Source_Line
;
115 S
.Lines_Table
(LL
) := P
;
117 -- Deal with setting new entry in logical lines table if one is
118 -- present. Note that there is always space (because the call to
119 -- Alloc_Line_Tables makes sure both tables are the same length),
121 if S
.Logical_Lines_Table
/= null then
123 -- We can always set the entry from the previous one, because
124 -- the processing for a Source_Reference pragma ensures that
125 -- at least one entry following the pragma is set up correctly.
127 S
.Logical_Lines_Table
(LL
) := S
.Logical_Lines_Table
(LL
- 1) + 1;
129 end Add_Line_Tables_Entry
;
131 -----------------------
132 -- Alloc_Line_Tables --
133 -----------------------
135 procedure Alloc_Line_Tables
136 (S
: in out Source_File_Record
;
139 subtype size_t
is Memory
.size_t
;
141 New_Table
: Lines_Table_Ptr
;
143 New_Logical_Table
: Logical_Lines_Table_Ptr
;
145 New_Size
: constant size_t
:=
146 size_t
(New_Max
* Lines_Table_Type
'Component_Size /
150 if S
.Lines_Table
= null then
151 New_Table
:= To_Pointer
(Memory
.Alloc
(New_Size
));
155 To_Pointer
(Memory
.Realloc
(To_Address
(S
.Lines_Table
), New_Size
));
158 if New_Table
= null then
161 S
.Lines_Table
:= New_Table
;
162 S
.Lines_Table_Max
:= Physical_Line_Number
(New_Max
);
165 if S
.Num_SRef_Pragmas
/= 0 then
166 if S
.Logical_Lines_Table
= null then
167 New_Logical_Table
:= To_Pointer
(Memory
.Alloc
(New_Size
));
169 New_Logical_Table
:= To_Pointer
170 (Memory
.Realloc
(To_Address
(S
.Logical_Lines_Table
), New_Size
));
173 if New_Logical_Table
= null then
176 S
.Logical_Lines_Table
:= New_Logical_Table
;
179 end Alloc_Line_Tables
;
185 procedure Backup_Line
(P
: in out Source_Ptr
) is
186 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
187 Src
: constant Source_Buffer_Ptr
:=
188 Source_File
.Table
(Sindex
).Source_Text
;
189 Sfirst
: constant Source_Ptr
:=
190 Source_File
.Table
(Sindex
).Source_First
;
200 if Src
(P
- 1) = LF
then
205 if Src
(P
- 1) = CR
then
210 -- Now find first character of the previous line
213 and then Src
(P
- 1) /= LF
214 and then Src
(P
- 1) /= CR
220 ---------------------------
221 -- Build_Location_String --
222 ---------------------------
224 procedure Build_Location_String
(Loc
: Source_Ptr
) is
228 -- Loop through instantiations
232 Get_Name_String_And_Append
233 (Reference_Name
(Get_Source_File_Index
(Ptr
)));
234 Add_Char_To_Name_Buffer
(':');
235 Add_Nat_To_Name_Buffer
(Nat
(Get_Logical_Line_Number
(Ptr
)));
237 Ptr
:= Instantiation_Location
(Ptr
);
238 exit when Ptr
= No_Location
;
239 Add_Str_To_Name_Buffer
(" instantiated at ");
242 Name_Buffer
(Name_Len
+ 1) := NUL
;
244 end Build_Location_String
;
246 function Build_Location_String
(Loc
: Source_Ptr
) return String is
249 Build_Location_String
(Loc
);
250 return Name_Buffer
(1 .. Name_Len
);
251 end Build_Location_String
;
257 procedure Check_For_BOM
is
260 Tst
: String (1 .. 5);
264 Tst
(J
) := Source
(Scan_Ptr
+ Source_Ptr
(J
) - 1);
267 Read_BOM
(Tst
, Len
, BOM
, False);
271 Scan_Ptr
:= Scan_Ptr
+ Source_Ptr
(Len
);
272 Wide_Character_Encoding_Method
:= WCEM_UTF8
;
273 Upper_Half_Encoding
:= True;
275 when UTF16_LE | UTF16_BE
=>
277 Write_Line
("UTF-16 encoding format not recognized");
279 raise Unrecoverable_Error
;
281 when UTF32_LE | UTF32_BE
=>
283 Write_Line
("UTF-32 encoding format not recognized");
285 raise Unrecoverable_Error
;
295 -----------------------
296 -- Get_Column_Number --
297 -----------------------
299 function Get_Column_Number
(P
: Source_Ptr
) return Column_Number
is
302 Sindex
: Source_File_Index
;
303 Src
: Source_Buffer_Ptr
;
306 -- If the input source pointer is not a meaningful value then return
307 -- at once with column number 1. This can happen for a file not found
308 -- condition for a file loaded indirectly by RTE, and also perhaps on
309 -- some unknown internal error conditions. In either case we certainly
310 -- don't want to blow up.
316 Sindex
:= Get_Source_File_Index
(P
);
317 Src
:= Source_File
.Table
(Sindex
).Source_Text
;
323 C
:= (C
- 1) / 8 * 8 + (8 + 1);
333 end Get_Column_Number
;
335 -----------------------------
336 -- Get_Logical_Line_Number --
337 -----------------------------
339 function Get_Logical_Line_Number
340 (P
: Source_Ptr
) return Logical_Line_Number
342 SFR
: Source_File_Record
343 renames Source_File
.Table
(Get_Source_File_Index
(P
));
345 L
: constant Physical_Line_Number
:= Get_Physical_Line_Number
(P
);
348 if SFR
.Num_SRef_Pragmas
= 0 then
349 return Logical_Line_Number
(L
);
351 return SFR
.Logical_Lines_Table
(L
);
353 end Get_Logical_Line_Number
;
355 ---------------------------------
356 -- Get_Logical_Line_Number_Img --
357 ---------------------------------
359 function Get_Logical_Line_Number_Img
360 (P
: Source_Ptr
) return String
364 Add_Nat_To_Name_Buffer
(Nat
(Get_Logical_Line_Number
(P
)));
365 return Name_Buffer
(1 .. Name_Len
);
366 end Get_Logical_Line_Number_Img
;
368 ------------------------------
369 -- Get_Physical_Line_Number --
370 ------------------------------
372 function Get_Physical_Line_Number
373 (P
: Source_Ptr
) return Physical_Line_Number
375 Sfile
: Source_File_Index
;
376 Table
: Lines_Table_Ptr
;
377 Lo
: Physical_Line_Number
;
378 Hi
: Physical_Line_Number
;
379 Mid
: Physical_Line_Number
;
383 -- If the input source pointer is not a meaningful value then return
384 -- at once with line number 1. This can happen for a file not found
385 -- condition for a file loaded indirectly by RTE, and also perhaps on
386 -- some unknown internal error conditions. In either case we certainly
387 -- don't want to blow up.
392 -- Otherwise we can do the binary search
395 Sfile
:= Get_Source_File_Index
(P
);
396 Loc
:= P
+ Source_File
.Table
(Sfile
).Sloc_Adjust
;
397 Table
:= Source_File
.Table
(Sfile
).Lines_Table
;
399 Hi
:= Source_File
.Table
(Sfile
).Last_Source_Line
;
402 Mid
:= (Lo
+ Hi
) / 2;
404 if Loc
< Table
(Mid
) then
407 else -- Loc >= Table (Mid)
410 Loc
< Table
(Mid
+ 1)
421 end Get_Physical_Line_Number
;
423 ---------------------------
424 -- Get_Source_File_Index --
425 ---------------------------
427 Source_Cache_First
: Source_Ptr
:= 1;
428 Source_Cache_Last
: Source_Ptr
:= 0;
429 -- Records the First and Last subscript values for the most recently
430 -- referenced entry in the source table, to optimize the common case of
431 -- repeated references to the same entry. The initial values force an
432 -- initial search to set the cache value.
434 Source_Cache_Index
: Source_File_Index
:= No_Source_File
;
435 -- Contains the index of the entry corresponding to Source_Cache
437 function Get_Source_File_Index
(S
: Source_Ptr
) return Source_File_Index
is
439 if S
in Source_Cache_First
.. Source_Cache_Last
then
440 return Source_Cache_Index
;
443 pragma Assert
(Source_File_Index_Table
(Int
(S
) / Chunk_Size
)
446 for J
in Source_File_Index_Table
(Int
(S
) / Chunk_Size
)
449 if S
in Source_File
.Table
(J
).Source_First
..
450 Source_File
.Table
(J
).Source_Last
452 Source_Cache_Index
:= J
;
453 Source_Cache_First
:=
454 Source_File
.Table
(Source_Cache_Index
).Source_First
;
456 Source_File
.Table
(Source_Cache_Index
).Source_Last
;
457 return Source_Cache_Index
;
462 -- We must find a matching entry in the above loop!
465 end Get_Source_File_Index
;
471 procedure Initialize
is
473 Source_Cache_First
:= 1;
474 Source_Cache_Last
:= 0;
475 Source_Cache_Index
:= No_Source_File
;
476 Source_gnat_adc
:= No_Source_File
;
477 First_Time_Around
:= True;
482 Instances
.Append
(No_Location
);
483 pragma Assert
(Instances
.Last
= No_Instance_Id
);
490 function Instantiation
(S
: SFI
) return Source_Ptr
is
491 SIE
: Source_File_Record
renames Source_File
.Table
(S
);
493 if SIE
.Inlined_Body
then
494 return SIE
.Inlined_Call
;
496 return Instances
.Table
(SIE
.Instance
);
500 -------------------------
501 -- Instantiation_Depth --
502 -------------------------
504 function Instantiation_Depth
(S
: Source_Ptr
) return Nat
is
505 Sind
: Source_File_Index
;
514 Sind
:= Get_Source_File_Index
(Sval
);
515 Sval
:= Instantiation
(Sind
);
516 exit when Sval
= No_Location
;
521 end Instantiation_Depth
;
523 ----------------------------
524 -- Instantiation_Location --
525 ----------------------------
527 function Instantiation_Location
(S
: Source_Ptr
) return Source_Ptr
is
529 return Instantiation
(Get_Source_File_Index
(S
));
530 end Instantiation_Location
;
532 --------------------------
533 -- Iterate_On_Instances --
534 --------------------------
536 procedure Iterate_On_Instances
is
538 for J
in 1 .. Instances
.Last
loop
539 Process
(J
, Instances
.Table
(J
));
541 end Iterate_On_Instances
;
543 ----------------------
544 -- Last_Source_File --
545 ----------------------
547 function Last_Source_File
return Source_File_Index
is
549 return Source_File
.Last
;
550 end Last_Source_File
;
556 function Line_Start
(P
: Source_Ptr
) return Source_Ptr
is
557 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
558 Src
: constant Source_Buffer_Ptr
:=
559 Source_File
.Table
(Sindex
).Source_Text
;
560 Sfirst
: constant Source_Ptr
:=
561 Source_File
.Table
(Sindex
).Source_First
;
567 and then Src
(S
- 1) /= CR
568 and then Src
(S
- 1) /= LF
577 (L
: Physical_Line_Number
;
578 S
: Source_File_Index
) return Source_Ptr
581 return Source_File
.Table
(S
).Lines_Table
(L
);
590 Source_File
.Locked
:= True;
594 ----------------------
595 -- Num_Source_Files --
596 ----------------------
598 function Num_Source_Files
return Nat
is
600 return Int
(Source_File
.Last
) - Int
(Source_File
.First
) + 1;
601 end Num_Source_Files
;
603 ----------------------
604 -- Num_Source_Lines --
605 ----------------------
607 function Num_Source_Lines
(S
: Source_File_Index
) return Nat
is
609 return Nat
(Source_File
.Table
(S
).Last_Source_Line
);
610 end Num_Source_Lines
;
612 -----------------------
613 -- Original_Location --
614 -----------------------
616 function Original_Location
(S
: Source_Ptr
) return Source_Ptr
is
617 Sindex
: Source_File_Index
;
618 Tindex
: Source_File_Index
;
621 if S
<= No_Location
then
625 Sindex
:= Get_Source_File_Index
(S
);
627 if Instantiation
(Sindex
) = No_Location
then
631 Tindex
:= Template
(Sindex
);
632 while Instantiation
(Tindex
) /= No_Location
loop
633 Tindex
:= Template
(Tindex
);
636 return S
- Source_First
(Sindex
) + Source_First
(Tindex
);
639 end Original_Location
;
641 -------------------------
642 -- Physical_To_Logical --
643 -------------------------
645 function Physical_To_Logical
646 (Line
: Physical_Line_Number
;
647 S
: Source_File_Index
) return Logical_Line_Number
649 SFR
: Source_File_Record
renames Source_File
.Table
(S
);
652 if SFR
.Num_SRef_Pragmas
= 0 then
653 return Logical_Line_Number
(Line
);
655 return SFR
.Logical_Lines_Table
(Line
);
657 end Physical_To_Logical
;
659 --------------------------------
660 -- Register_Source_Ref_Pragma --
661 --------------------------------
663 procedure Register_Source_Ref_Pragma
664 (File_Name
: File_Name_Type
;
665 Stripped_File_Name
: File_Name_Type
;
667 Line_After_Pragma
: Physical_Line_Number
)
669 subtype size_t
is Memory
.size_t
;
671 SFR
: Source_File_Record
renames Source_File
.Table
(Current_Source_File
);
673 ML
: Logical_Line_Number
;
676 if File_Name
/= No_File
then
677 SFR
.Reference_Name
:= Stripped_File_Name
;
678 SFR
.Full_Ref_Name
:= File_Name
;
680 if not Debug_Generated_Code
then
681 SFR
.Debug_Source_Name
:= Stripped_File_Name
;
682 SFR
.Full_Debug_Name
:= File_Name
;
685 SFR
.Num_SRef_Pragmas
:= SFR
.Num_SRef_Pragmas
+ 1;
688 if SFR
.Num_SRef_Pragmas
= 1 then
689 SFR
.First_Mapped_Line
:= Logical_Line_Number
(Mapped_Line
);
692 if SFR
.Logical_Lines_Table
= null then
693 SFR
.Logical_Lines_Table
:= To_Pointer
695 (size_t
(SFR
.Lines_Table_Max
*
696 Logical_Lines_Table_Type
'Component_Size /
700 SFR
.Logical_Lines_Table
(Line_After_Pragma
- 1) := No_Line_Number
;
702 ML
:= Logical_Line_Number
(Mapped_Line
);
703 for J
in Line_After_Pragma
.. SFR
.Last_Source_Line
loop
704 SFR
.Logical_Lines_Table
(J
) := ML
;
707 end Register_Source_Ref_Pragma
;
709 ---------------------------------
710 -- Set_Source_File_Index_Table --
711 ---------------------------------
713 procedure Set_Source_File_Index_Table
(Xnew
: Source_File_Index
) is
716 SL
: constant Source_Ptr
:= Source_File
.Table
(Xnew
).Source_Last
;
719 SP
:= (Source_File
.Table
(Xnew
).Source_First
+ Chunk_Size
- 1)
720 / Chunk_Size
* Chunk_Size
;
721 Ind
:= Int
(SP
) / Chunk_Size
;
724 Source_File_Index_Table
(Ind
) := Xnew
;
725 SP
:= SP
+ Chunk_Size
;
728 end Set_Source_File_Index_Table
;
730 ---------------------------
731 -- Skip_Line_Terminators --
732 ---------------------------
734 procedure Skip_Line_Terminators
735 (P
: in out Source_Ptr
;
736 Physical
: out Boolean)
738 Chr
: constant Character := Source
(P
);
742 if Source
(P
+ 1) = LF
then
751 elsif Chr
= FF
or else Chr
= VT
then
756 -- Otherwise we have a wide character
759 Skip_Wide
(Source
, P
);
762 -- Fall through in the physical line terminator case. First deal with
763 -- making a possible entry into the lines table if one is needed.
765 -- Note: we are dealing with a real source file here, this cannot be
766 -- the instantiation case, so we need not worry about Sloc adjustment.
769 S
: Source_File_Record
770 renames Source_File
.Table
(Current_Source_File
);
775 -- Make entry in lines table if not already made (in some scan backup
776 -- cases, we will be rescanning previously scanned source, so the
777 -- entry may have already been made on the previous forward scan).
780 and then P
> S
.Lines_Table
(S
.Last_Source_Line
)
782 Add_Line_Tables_Entry
(S
, P
);
785 end Skip_Line_Terminators
;
791 procedure Sloc_Range
(N
: Node_Id
; Min
, Max
: out Source_Ptr
) is
793 function Process
(N
: Node_Id
) return Traverse_Result
;
794 -- Process function for traversing the node tree
796 procedure Traverse
is new Traverse_Proc
(Process
);
802 function Process
(N
: Node_Id
) return Traverse_Result
is
804 if Sloc
(N
) < Min
then
805 if Sloc
(N
) > No_Location
then
808 elsif Sloc
(N
) > Max
then
809 if Sloc
(N
) > No_Location
then
817 -- Start of processing for Sloc_Range
829 function Source_Offset
(S
: Source_Ptr
) return Nat
is
830 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(S
);
831 Sfirst
: constant Source_Ptr
:=
832 Source_File
.Table
(Sindex
).Source_First
;
834 return Nat
(S
- Sfirst
);
837 ------------------------
838 -- Top_Level_Location --
839 ------------------------
841 function Top_Level_Location
(S
: Source_Ptr
) return Source_Ptr
is
849 Newloc
:= Instantiation_Location
(Oldloc
);
850 exit when Newloc
= No_Location
;
854 end Top_Level_Location
;
860 procedure Tree_Read
is
862 -- First we must free any old source buffer pointers
864 if not First_Time_Around
then
865 for J
in Source_File
.First
.. Source_File
.Last
loop
867 S
: Source_File_Record
renames Source_File
.Table
(J
);
869 procedure Free_Ptr
is new Unchecked_Deallocation
870 (Big_Source_Buffer
, Source_Buffer_Ptr
);
872 pragma Warnings
(Off
);
873 -- This unchecked conversion is aliasing safe, since it is not
874 -- used to create improperly aliased pointer values.
876 function To_Source_Buffer_Ptr
is new
877 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
879 pragma Warnings
(On
);
881 Tmp1
: Source_Buffer_Ptr
;
884 if S
.Instance
/= No_Instance_Id
then
888 -- Free the buffer, we use Free here, because we used malloc
889 -- or realloc directly to allocate the tables. That is
890 -- because we were playing the big array trick.
892 -- We have to recreate a proper pointer to the actual array
893 -- from the zero origin pointer stored in the source table.
897 (S
.Source_Text
(S
.Source_First
)'Address);
900 if S
.Lines_Table
/= null then
901 Memory
.Free
(To_Address
(S
.Lines_Table
));
902 S
.Lines_Table
:= null;
905 if S
.Logical_Lines_Table
/= null then
906 Memory
.Free
(To_Address
(S
.Logical_Lines_Table
));
907 S
.Logical_Lines_Table
:= null;
914 -- Reset source cache pointers to force new read
916 Source_Cache_First
:= 1;
917 Source_Cache_Last
:= 0;
919 -- Read in source file table and instance table
921 Source_File
.Tree_Read
;
924 -- The pointers we read in there for the source buffer and lines
925 -- table pointers are junk. We now read in the actual data that
926 -- is referenced by these two fields.
928 for J
in Source_File
.First
.. Source_File
.Last
loop
930 S
: Source_File_Record
renames Source_File
.Table
(J
);
933 -- For the instantiation case, we do not read in any data. Instead
934 -- we share the data for the generic template entry. Since the
935 -- template always occurs first, we can safely refer to its data.
937 if S
.Instance
/= No_Instance_Id
then
939 ST
: Source_File_Record
renames
940 Source_File
.Table
(S
.Template
);
943 -- The lines tables are copied from the template entry
946 Source_File
.Table
(S
.Template
).Lines_Table
;
947 S
.Logical_Lines_Table
:=
948 Source_File
.Table
(S
.Template
).Logical_Lines_Table
;
950 -- In the case of the source table pointer, we share the
951 -- same data as the generic template, but the virtual origin
952 -- is adjusted. For example, if the first subscript of the
953 -- template is 100, and that of the instantiation is 200,
954 -- then the instantiation pointer is obtained by subtracting
955 -- 100 from the template pointer.
958 pragma Suppress
(All_Checks
);
960 pragma Warnings
(Off
);
961 -- This unchecked conversion is aliasing safe since it
962 -- not used to create improperly aliased pointer values.
964 function To_Source_Buffer_Ptr
is new
965 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
967 pragma Warnings
(On
);
973 (ST
.Source_First
- S
.Source_First
)'Address);
977 -- Normal case (non-instantiation)
980 First_Time_Around
:= False;
981 S
.Lines_Table
:= null;
982 S
.Logical_Lines_Table
:= null;
983 Alloc_Line_Tables
(S
, Int
(S
.Last_Source_Line
));
985 for J
in 1 .. S
.Last_Source_Line
loop
986 Tree_Read_Int
(Int
(S
.Lines_Table
(J
)));
989 if S
.Num_SRef_Pragmas
/= 0 then
990 for J
in 1 .. S
.Last_Source_Line
loop
991 Tree_Read_Int
(Int
(S
.Logical_Lines_Table
(J
)));
995 -- Allocate source buffer and read in the data and then set the
996 -- virtual origin to point to the logical zero'th element. This
997 -- address must be computed with subscript checks turned off.
1000 subtype B
is Text_Buffer
(S
.Source_First
.. S
.Source_Last
);
1001 type Text_Buffer_Ptr
is access B
;
1002 T
: Text_Buffer_Ptr
;
1004 pragma Suppress
(All_Checks
);
1006 pragma Warnings
(Off
);
1007 -- This unchecked conversion is aliasing safe, since it is
1008 -- never used to create improperly aliased pointer values.
1010 function To_Source_Buffer_Ptr
is new
1011 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
1013 pragma Warnings
(On
);
1018 Tree_Read_Data
(T
(S
.Source_First
)'Address,
1019 Int
(S
.Source_Last
) - Int
(S
.Source_First
) + 1);
1021 S
.Source_Text
:= To_Source_Buffer_Ptr
(T
(0)'Address);
1026 Set_Source_File_Index_Table
(J
);
1034 procedure Tree_Write
is
1036 Source_File
.Tree_Write
;
1037 Instances
.Tree_Write
;
1039 -- The pointers we wrote out there for the source buffer and lines
1040 -- table pointers are junk, we now write out the actual data that
1041 -- is referenced by these two fields.
1043 for J
in Source_File
.First
.. Source_File
.Last
loop
1045 S
: Source_File_Record
renames Source_File
.Table
(J
);
1048 -- For instantiations, there is nothing to do, since the data is
1049 -- shared with the generic template. When the tree is read, the
1050 -- pointers must be set, but no extra data needs to be written.
1052 if S
.Instance
/= No_Instance_Id
then
1055 -- For the normal case, write out the data of the tables
1060 for J
in 1 .. S
.Last_Source_Line
loop
1061 Tree_Write_Int
(Int
(S
.Lines_Table
(J
)));
1064 -- Logical lines table if present
1066 if S
.Num_SRef_Pragmas
/= 0 then
1067 for J
in 1 .. S
.Last_Source_Line
loop
1068 Tree_Write_Int
(Int
(S
.Logical_Lines_Table
(J
)));
1075 (S
.Source_Text
(S
.Source_First
)'Address,
1076 Int
(S
.Source_Last
) - Int
(S
.Source_First
) + 1);
1082 --------------------
1083 -- Write_Location --
1084 --------------------
1086 procedure Write_Location
(P
: Source_Ptr
) is
1088 if P
= No_Location
then
1089 Write_Str
("<no location>");
1091 elsif P
<= Standard_Location
then
1092 Write_Str
("<standard location>");
1096 SI
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
1099 Write_Name
(Debug_Source_Name
(SI
));
1101 Write_Int
(Int
(Get_Logical_Line_Number
(P
)));
1103 Write_Int
(Int
(Get_Column_Number
(P
)));
1105 if Instantiation
(SI
) /= No_Location
then
1107 Write_Location
(Instantiation
(SI
));
1114 ----------------------
1115 -- Write_Time_Stamp --
1116 ----------------------
1118 procedure Write_Time_Stamp
(S
: Source_File_Index
) is
1119 T
: constant Time_Stamp_Type
:= Time_Stamp
(S
);
1132 Write_Char
(T
(P
+ 1));
1133 Write_Char
(T
(P
+ 2));
1136 Write_Char
(T
(P
+ 3));
1137 Write_Char
(T
(P
+ 4));
1140 Write_Char
(T
(P
+ 5));
1141 Write_Char
(T
(P
+ 6));
1144 Write_Char
(T
(P
+ 7));
1145 Write_Char
(T
(P
+ 8));
1148 Write_Char
(T
(P
+ 9));
1149 Write_Char
(T
(P
+ 10));
1152 Write_Char
(T
(P
+ 11));
1153 Write_Char
(T
(P
+ 12));
1154 end Write_Time_Stamp
;
1156 ----------------------------------------------
1157 -- Access Subprograms for Source File Table --
1158 ----------------------------------------------
1160 function Debug_Source_Name
(S
: SFI
) return File_Name_Type
is
1162 return Source_File
.Table
(S
).Debug_Source_Name
;
1163 end Debug_Source_Name
;
1165 function Instance
(S
: SFI
) return Instance_Id
is
1167 return Source_File
.Table
(S
).Instance
;
1170 function File_Name
(S
: SFI
) return File_Name_Type
is
1172 return Source_File
.Table
(S
).File_Name
;
1175 function File_Type
(S
: SFI
) return Type_Of_File
is
1177 return Source_File
.Table
(S
).File_Type
;
1180 function First_Mapped_Line
(S
: SFI
) return Logical_Line_Number
is
1182 return Source_File
.Table
(S
).First_Mapped_Line
;
1183 end First_Mapped_Line
;
1185 function Full_Debug_Name
(S
: SFI
) return File_Name_Type
is
1187 return Source_File
.Table
(S
).Full_Debug_Name
;
1188 end Full_Debug_Name
;
1190 function Full_File_Name
(S
: SFI
) return File_Name_Type
is
1192 return Source_File
.Table
(S
).Full_File_Name
;
1195 function Full_Ref_Name
(S
: SFI
) return File_Name_Type
is
1197 return Source_File
.Table
(S
).Full_Ref_Name
;
1200 function Identifier_Casing
(S
: SFI
) return Casing_Type
is
1202 return Source_File
.Table
(S
).Identifier_Casing
;
1203 end Identifier_Casing
;
1205 function Inlined_Body
(S
: SFI
) return Boolean is
1207 return Source_File
.Table
(S
).Inlined_Body
;
1210 function Inlined_Call
(S
: SFI
) return Source_Ptr
is
1212 return Source_File
.Table
(S
).Inlined_Call
;
1215 function Keyword_Casing
(S
: SFI
) return Casing_Type
is
1217 return Source_File
.Table
(S
).Keyword_Casing
;
1220 function Last_Source_Line
(S
: SFI
) return Physical_Line_Number
is
1222 return Source_File
.Table
(S
).Last_Source_Line
;
1223 end Last_Source_Line
;
1225 function License
(S
: SFI
) return License_Type
is
1227 return Source_File
.Table
(S
).License
;
1230 function Num_SRef_Pragmas
(S
: SFI
) return Nat
is
1232 return Source_File
.Table
(S
).Num_SRef_Pragmas
;
1233 end Num_SRef_Pragmas
;
1235 function Reference_Name
(S
: SFI
) return File_Name_Type
is
1237 return Source_File
.Table
(S
).Reference_Name
;
1240 function Source_Checksum
(S
: SFI
) return Word
is
1242 return Source_File
.Table
(S
).Source_Checksum
;
1243 end Source_Checksum
;
1245 function Source_First
(S
: SFI
) return Source_Ptr
is
1247 if S
= Internal_Source_File
then
1248 return Internal_Source
'First;
1250 return Source_File
.Table
(S
).Source_First
;
1254 function Source_Last
(S
: SFI
) return Source_Ptr
is
1256 if S
= Internal_Source_File
then
1257 return Internal_Source
'Last;
1259 return Source_File
.Table
(S
).Source_Last
;
1263 function Source_Text
(S
: SFI
) return Source_Buffer_Ptr
is
1265 if S
= Internal_Source_File
then
1266 return Internal_Source_Ptr
;
1268 return Source_File
.Table
(S
).Source_Text
;
1272 function Template
(S
: SFI
) return SFI
is
1274 return Source_File
.Table
(S
).Template
;
1277 function Time_Stamp
(S
: SFI
) return Time_Stamp_Type
is
1279 return Source_File
.Table
(S
).Time_Stamp
;
1282 function Unit
(S
: SFI
) return Unit_Number_Type
is
1284 return Source_File
.Table
(S
).Unit
;
1287 ------------------------------------------
1288 -- Set Procedures for Source File Table --
1289 ------------------------------------------
1291 procedure Set_Identifier_Casing
(S
: SFI
; C
: Casing_Type
) is
1293 Source_File
.Table
(S
).Identifier_Casing
:= C
;
1294 end Set_Identifier_Casing
;
1296 procedure Set_Keyword_Casing
(S
: SFI
; C
: Casing_Type
) is
1298 Source_File
.Table
(S
).Keyword_Casing
:= C
;
1299 end Set_Keyword_Casing
;
1301 procedure Set_License
(S
: SFI
; L
: License_Type
) is
1303 Source_File
.Table
(S
).License
:= L
;
1306 procedure Set_Unit
(S
: SFI
; U
: Unit_Number_Type
) is
1308 Source_File
.Table
(S
).Unit
:= U
;
1311 ----------------------
1312 -- Trim_Lines_Table --
1313 ----------------------
1315 procedure Trim_Lines_Table
(S
: Source_File_Index
) is
1316 Max
: constant Nat
:= Nat
(Source_File
.Table
(S
).Last_Source_Line
);
1319 -- Release allocated storage that is no longer needed
1321 Source_File
.Table
(S
).Lines_Table
:= To_Pointer
1323 (To_Address
(Source_File
.Table
(S
).Lines_Table
),
1325 (Max
* (Lines_Table_Type
'Component_Size / System
.Storage_Unit
))));
1326 Source_File
.Table
(S
).Lines_Table_Max
:= Physical_Line_Number
(Max
);
1327 end Trim_Lines_Table
;
1335 Source_File
.Locked
:= False;
1336 Source_File
.Release
;
1343 procedure wl
(P
: Source_Ptr
) is