1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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
225 (Buf
: in out Bounded_String
;
228 Ptr
: Source_Ptr
:= Loc
;
231 -- Loop through instantiations
234 Append
(Buf
, Reference_Name
(Get_Source_File_Index
(Ptr
)));
236 Append
(Buf
, Nat
(Get_Logical_Line_Number
(Ptr
)));
238 Ptr
:= Instantiation_Location
(Ptr
);
239 exit when Ptr
= No_Location
;
240 Append
(Buf
, " instantiated at ");
242 end Build_Location_String
;
244 function Build_Location_String
(Loc
: Source_Ptr
) return String is
245 Buf
: Bounded_String
;
247 Build_Location_String
(Buf
, Loc
);
249 end Build_Location_String
;
255 procedure Check_For_BOM
is
258 Tst
: String (1 .. 5);
263 C
:= Source
(Scan_Ptr
+ Source_Ptr
(J
) - 1);
265 -- Definitely no BOM if EOF character marks either end of file, or
266 -- an illegal non-BOM character if not at the end of file.
275 Read_BOM
(Tst
, Len
, BOM
, False);
279 Scan_Ptr
:= Scan_Ptr
+ Source_Ptr
(Len
);
280 Wide_Character_Encoding_Method
:= WCEM_UTF8
;
281 Upper_Half_Encoding
:= True;
287 Write_Line
("UTF-16 encoding format not recognized");
289 raise Unrecoverable_Error
;
295 Write_Line
("UTF-32 encoding format not recognized");
297 raise Unrecoverable_Error
;
307 ---------------------------------
308 -- Comes_From_Inherited_Pragma --
309 ---------------------------------
311 function Comes_From_Inherited_Pragma
(S
: Source_Ptr
) return Boolean is
312 SIE
: Source_File_Record
renames
313 Source_File
.Table
(Get_Source_File_Index
(S
));
315 return SIE
.Inherited_Pragma
;
316 end Comes_From_Inherited_Pragma
;
318 -----------------------------
319 -- Comes_From_Inlined_Body --
320 -----------------------------
322 function Comes_From_Inlined_Body
(S
: Source_Ptr
) return Boolean is
323 SIE
: Source_File_Record
renames
324 Source_File
.Table
(Get_Source_File_Index
(S
));
326 return SIE
.Inlined_Body
;
327 end Comes_From_Inlined_Body
;
329 -----------------------
330 -- Get_Column_Number --
331 -----------------------
333 function Get_Column_Number
(P
: Source_Ptr
) return Column_Number
is
336 Sindex
: Source_File_Index
;
337 Src
: Source_Buffer_Ptr
;
340 -- If the input source pointer is not a meaningful value then return
341 -- at once with column number 1. This can happen for a file not found
342 -- condition for a file loaded indirectly by RTE, and also perhaps on
343 -- some unknown internal error conditions. In either case we certainly
344 -- don't want to blow up.
350 Sindex
:= Get_Source_File_Index
(P
);
351 Src
:= Source_File
.Table
(Sindex
).Source_Text
;
357 C
:= (C
- 1) / 8 * 8 + (8 + 1);
360 -- Deal with wide character case, but don't include brackets
361 -- notation in this circuit, since we know that this will
362 -- display unencoded (no one encodes brackets notation).
364 elsif Src
(S
) /= '[' and then Is_Start_Of_Wide_Char
(Src
, S
) then
368 -- Normal (non-wide) character case or brackets sequence
378 end Get_Column_Number
;
380 -----------------------------
381 -- Get_Logical_Line_Number --
382 -----------------------------
384 function Get_Logical_Line_Number
385 (P
: Source_Ptr
) return Logical_Line_Number
387 SFR
: Source_File_Record
388 renames Source_File
.Table
(Get_Source_File_Index
(P
));
390 L
: constant Physical_Line_Number
:= Get_Physical_Line_Number
(P
);
393 if SFR
.Num_SRef_Pragmas
= 0 then
394 return Logical_Line_Number
(L
);
396 return SFR
.Logical_Lines_Table
(L
);
398 end Get_Logical_Line_Number
;
400 ---------------------------------
401 -- Get_Logical_Line_Number_Img --
402 ---------------------------------
404 function Get_Logical_Line_Number_Img
405 (P
: Source_Ptr
) return String
409 Add_Nat_To_Name_Buffer
(Nat
(Get_Logical_Line_Number
(P
)));
410 return Name_Buffer
(1 .. Name_Len
);
411 end Get_Logical_Line_Number_Img
;
413 ------------------------------
414 -- Get_Physical_Line_Number --
415 ------------------------------
417 function Get_Physical_Line_Number
418 (P
: Source_Ptr
) return Physical_Line_Number
420 Sfile
: Source_File_Index
;
421 Table
: Lines_Table_Ptr
;
422 Lo
: Physical_Line_Number
;
423 Hi
: Physical_Line_Number
;
424 Mid
: Physical_Line_Number
;
428 -- If the input source pointer is not a meaningful value then return
429 -- at once with line number 1. This can happen for a file not found
430 -- condition for a file loaded indirectly by RTE, and also perhaps on
431 -- some unknown internal error conditions. In either case we certainly
432 -- don't want to blow up.
437 -- Otherwise we can do the binary search
440 Sfile
:= Get_Source_File_Index
(P
);
441 Loc
:= P
+ Source_File
.Table
(Sfile
).Sloc_Adjust
;
442 Table
:= Source_File
.Table
(Sfile
).Lines_Table
;
444 Hi
:= Source_File
.Table
(Sfile
).Last_Source_Line
;
447 Mid
:= (Lo
+ Hi
) / 2;
449 if Loc
< Table
(Mid
) then
452 else -- Loc >= Table (Mid)
455 Loc
< Table
(Mid
+ 1)
466 end Get_Physical_Line_Number
;
468 ---------------------------
469 -- Get_Source_File_Index --
470 ---------------------------
472 function Get_Source_File_Index
(S
: Source_Ptr
) return Source_File_Index
is
474 return Source_File_Index_Table
(Int
(S
) / Source_Align
);
475 end Get_Source_File_Index
;
481 procedure Initialize
is
483 Source_gnat_adc
:= No_Source_File
;
484 First_Time_Around
:= True;
489 Instances
.Append
(No_Location
);
490 pragma Assert
(Instances
.Last
= No_Instance_Id
);
497 function Instantiation
(S
: SFI
) return Source_Ptr
is
498 SIE
: Source_File_Record
renames Source_File
.Table
(S
);
500 if SIE
.Inlined_Body
or SIE
.Inherited_Pragma
then
501 return SIE
.Inlined_Call
;
503 return Instances
.Table
(SIE
.Instance
);
507 -------------------------
508 -- Instantiation_Depth --
509 -------------------------
511 function Instantiation_Depth
(S
: Source_Ptr
) return Nat
is
512 Sind
: Source_File_Index
;
521 Sind
:= Get_Source_File_Index
(Sval
);
522 Sval
:= Instantiation
(Sind
);
523 exit when Sval
= No_Location
;
528 end Instantiation_Depth
;
530 ----------------------------
531 -- Instantiation_Location --
532 ----------------------------
534 function Instantiation_Location
(S
: Source_Ptr
) return Source_Ptr
is
536 return Instantiation
(Get_Source_File_Index
(S
));
537 end Instantiation_Location
;
539 --------------------------
540 -- Iterate_On_Instances --
541 --------------------------
543 procedure Iterate_On_Instances
is
545 for J
in 1 .. Instances
.Last
loop
546 Process
(J
, Instances
.Table
(J
));
548 end Iterate_On_Instances
;
550 ----------------------
551 -- Last_Source_File --
552 ----------------------
554 function Last_Source_File
return Source_File_Index
is
556 return Source_File
.Last
;
557 end Last_Source_File
;
563 function Line_Start
(P
: Source_Ptr
) return Source_Ptr
is
564 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
565 Src
: constant Source_Buffer_Ptr
:=
566 Source_File
.Table
(Sindex
).Source_Text
;
567 Sfirst
: constant Source_Ptr
:=
568 Source_File
.Table
(Sindex
).Source_First
;
574 and then Src
(S
- 1) /= CR
575 and then Src
(S
- 1) /= LF
584 (L
: Physical_Line_Number
;
585 S
: Source_File_Index
) return Source_Ptr
588 return Source_File
.Table
(S
).Lines_Table
(L
);
597 Source_File
.Locked
:= True;
601 ----------------------
602 -- Num_Source_Files --
603 ----------------------
605 function Num_Source_Files
return Nat
is
607 return Int
(Source_File
.Last
) - Int
(Source_File
.First
) + 1;
608 end Num_Source_Files
;
610 ----------------------
611 -- Num_Source_Lines --
612 ----------------------
614 function Num_Source_Lines
(S
: Source_File_Index
) return Nat
is
616 return Nat
(Source_File
.Table
(S
).Last_Source_Line
);
617 end Num_Source_Lines
;
619 -----------------------
620 -- Original_Location --
621 -----------------------
623 function Original_Location
(S
: Source_Ptr
) return Source_Ptr
is
624 Sindex
: Source_File_Index
;
625 Tindex
: Source_File_Index
;
628 if S
<= No_Location
then
632 Sindex
:= Get_Source_File_Index
(S
);
634 if Instantiation
(Sindex
) = No_Location
then
638 Tindex
:= Template
(Sindex
);
639 while Instantiation
(Tindex
) /= No_Location
loop
640 Tindex
:= Template
(Tindex
);
643 return S
- Source_First
(Sindex
) + Source_First
(Tindex
);
646 end Original_Location
;
648 -------------------------
649 -- Physical_To_Logical --
650 -------------------------
652 function Physical_To_Logical
653 (Line
: Physical_Line_Number
;
654 S
: Source_File_Index
) return Logical_Line_Number
656 SFR
: Source_File_Record
renames Source_File
.Table
(S
);
659 if SFR
.Num_SRef_Pragmas
= 0 then
660 return Logical_Line_Number
(Line
);
662 return SFR
.Logical_Lines_Table
(Line
);
664 end Physical_To_Logical
;
666 --------------------------------
667 -- Register_Source_Ref_Pragma --
668 --------------------------------
670 procedure Register_Source_Ref_Pragma
671 (File_Name
: File_Name_Type
;
672 Stripped_File_Name
: File_Name_Type
;
674 Line_After_Pragma
: Physical_Line_Number
)
676 subtype size_t
is Memory
.size_t
;
678 SFR
: Source_File_Record
renames Source_File
.Table
(Current_Source_File
);
680 ML
: Logical_Line_Number
;
683 if File_Name
/= No_File
then
684 SFR
.Reference_Name
:= Stripped_File_Name
;
685 SFR
.Full_Ref_Name
:= File_Name
;
687 if not Debug_Generated_Code
then
688 SFR
.Debug_Source_Name
:= Stripped_File_Name
;
689 SFR
.Full_Debug_Name
:= File_Name
;
692 SFR
.Num_SRef_Pragmas
:= SFR
.Num_SRef_Pragmas
+ 1;
695 if SFR
.Num_SRef_Pragmas
= 1 then
696 SFR
.First_Mapped_Line
:= Logical_Line_Number
(Mapped_Line
);
699 if SFR
.Logical_Lines_Table
= null then
700 SFR
.Logical_Lines_Table
:= To_Pointer
702 (size_t
(SFR
.Lines_Table_Max
*
703 Logical_Lines_Table_Type
'Component_Size /
707 SFR
.Logical_Lines_Table
(Line_After_Pragma
- 1) := No_Line_Number
;
709 ML
:= Logical_Line_Number
(Mapped_Line
);
710 for J
in Line_After_Pragma
.. SFR
.Last_Source_Line
loop
711 SFR
.Logical_Lines_Table
(J
) := ML
;
714 end Register_Source_Ref_Pragma
;
716 ---------------------------------
717 -- Set_Source_File_Index_Table --
718 ---------------------------------
720 procedure Set_Source_File_Index_Table
(Xnew
: Source_File_Index
) is
723 SL
: constant Source_Ptr
:= Source_File
.Table
(Xnew
).Source_Last
;
725 SP
:= Source_File
.Table
(Xnew
).Source_First
;
726 pragma Assert
(SP
mod Source_Align
= 0);
727 Ind
:= Int
(SP
) / Source_Align
;
729 Source_File_Index_Table
(Ind
) := Xnew
;
730 SP
:= SP
+ Source_Align
;
733 end Set_Source_File_Index_Table
;
735 ---------------------------
736 -- Skip_Line_Terminators --
737 ---------------------------
739 procedure Skip_Line_Terminators
740 (P
: in out Source_Ptr
;
741 Physical
: out Boolean)
743 Chr
: constant Character := Source
(P
);
747 if Source
(P
+ 1) = LF
then
756 elsif Chr
= FF
or else Chr
= VT
then
761 -- Otherwise we have a wide character
764 Skip_Wide
(Source
, P
);
767 -- Fall through in the physical line terminator case. First deal with
768 -- making a possible entry into the lines table if one is needed.
770 -- Note: we are dealing with a real source file here, this cannot be
771 -- the instantiation case, so we need not worry about Sloc adjustment.
774 S
: Source_File_Record
775 renames Source_File
.Table
(Current_Source_File
);
780 -- Make entry in lines table if not already made (in some scan backup
781 -- cases, we will be rescanning previously scanned source, so the
782 -- entry may have already been made on the previous forward scan).
785 and then P
> S
.Lines_Table
(S
.Last_Source_Line
)
787 Add_Line_Tables_Entry
(S
, P
);
790 end Skip_Line_Terminators
;
796 procedure Sloc_Range
(N
: Node_Id
; Min
, Max
: out Source_Ptr
) is
798 function Process
(N
: Node_Id
) return Traverse_Result
;
799 -- Process function for traversing the node tree
801 procedure Traverse
is new Traverse_Proc
(Process
);
807 function Process
(N
: Node_Id
) return Traverse_Result
is
808 Orig
: constant Node_Id
:= Original_Node
(N
);
811 if Sloc
(Orig
) < Min
then
812 if Sloc
(Orig
) > No_Location
then
816 elsif Sloc
(Orig
) > Max
then
817 if Sloc
(Orig
) > No_Location
then
825 -- Start of processing for Sloc_Range
837 function Source_Offset
(S
: Source_Ptr
) return Nat
is
838 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(S
);
839 Sfirst
: constant Source_Ptr
:=
840 Source_File
.Table
(Sindex
).Source_First
;
842 return Nat
(S
- Sfirst
);
845 ------------------------
846 -- Top_Level_Location --
847 ------------------------
849 function Top_Level_Location
(S
: Source_Ptr
) return Source_Ptr
is
857 Newloc
:= Instantiation_Location
(Oldloc
);
858 exit when Newloc
= No_Location
;
862 end Top_Level_Location
;
868 procedure Tree_Read
is
870 -- First we must free any old source buffer pointers
872 if not First_Time_Around
then
873 for J
in Source_File
.First
.. Source_File
.Last
loop
875 S
: Source_File_Record
renames Source_File
.Table
(J
);
877 procedure Free_Ptr
is new Unchecked_Deallocation
878 (Big_Source_Buffer
, Source_Buffer_Ptr
);
880 pragma Warnings
(Off
);
881 -- This unchecked conversion is aliasing safe, since it is not
882 -- used to create improperly aliased pointer values.
884 function To_Source_Buffer_Ptr
is new
885 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
887 pragma Warnings
(On
);
889 Tmp1
: Source_Buffer_Ptr
;
892 if S
.Instance
/= No_Instance_Id
then
896 -- Free the buffer, we use Free here, because we used malloc
897 -- or realloc directly to allocate the tables. That is
898 -- because we were playing the big array trick.
900 -- We have to recreate a proper pointer to the actual array
901 -- from the zero origin pointer stored in the source table.
905 (S
.Source_Text
(S
.Source_First
)'Address);
908 if S
.Lines_Table
/= null then
909 Memory
.Free
(To_Address
(S
.Lines_Table
));
910 S
.Lines_Table
:= null;
913 if S
.Logical_Lines_Table
/= null then
914 Memory
.Free
(To_Address
(S
.Logical_Lines_Table
));
915 S
.Logical_Lines_Table
:= null;
922 -- Read in source file table and instance table
924 Source_File
.Tree_Read
;
927 -- The pointers we read in there for the source buffer and lines table
928 -- pointers are junk. We now read in the actual data that is referenced
929 -- by these two fields.
931 for J
in Source_File
.First
.. Source_File
.Last
loop
933 S
: Source_File_Record
renames Source_File
.Table
(J
);
936 -- For the instantiation case, we do not read in any data. Instead
937 -- we share the data for the generic template entry. Since the
938 -- template always occurs first, we can safely refer to its data.
940 if S
.Instance
/= No_Instance_Id
then
942 ST
: Source_File_Record
renames
943 Source_File
.Table
(S
.Template
);
946 -- The lines tables are copied from the template entry
949 Source_File
.Table
(S
.Template
).Lines_Table
;
950 S
.Logical_Lines_Table
:=
951 Source_File
.Table
(S
.Template
).Logical_Lines_Table
;
953 -- In the case of the source table pointer, we share the
954 -- same data as the generic template, but the virtual origin
955 -- is adjusted. For example, if the first subscript of the
956 -- template is 100, and that of the instantiation is 200,
957 -- then the instantiation pointer is obtained by subtracting
958 -- 100 from the template pointer.
961 pragma Suppress
(All_Checks
);
963 pragma Warnings
(Off
);
964 -- This unchecked conversion is aliasing safe since it
965 -- not used to create improperly aliased pointer values.
967 function To_Source_Buffer_Ptr
is new
968 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
970 pragma Warnings
(On
);
976 (ST
.Source_First
- S
.Source_First
)'Address);
980 -- Normal case (non-instantiation)
983 First_Time_Around
:= False;
984 S
.Lines_Table
:= null;
985 S
.Logical_Lines_Table
:= null;
986 Alloc_Line_Tables
(S
, Int
(S
.Last_Source_Line
));
988 for J
in 1 .. S
.Last_Source_Line
loop
989 Tree_Read_Int
(Int
(S
.Lines_Table
(J
)));
992 if S
.Num_SRef_Pragmas
/= 0 then
993 for J
in 1 .. S
.Last_Source_Line
loop
994 Tree_Read_Int
(Int
(S
.Logical_Lines_Table
(J
)));
998 -- Allocate source buffer and read in the data and then set the
999 -- virtual origin to point to the logical zero'th element. This
1000 -- address must be computed with subscript checks turned off.
1003 subtype B
is Text_Buffer
(S
.Source_First
.. S
.Source_Last
);
1004 type Text_Buffer_Ptr
is access B
;
1005 T
: Text_Buffer_Ptr
;
1007 pragma Suppress
(All_Checks
);
1009 pragma Warnings
(Off
);
1010 -- This unchecked conversion is aliasing safe, since it is
1011 -- never used to create improperly aliased pointer values.
1013 function To_Source_Buffer_Ptr
is new
1014 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
1016 pragma Warnings
(On
);
1021 Tree_Read_Data
(T
(S
.Source_First
)'Address,
1022 Int
(S
.Source_Last
) - Int
(S
.Source_First
) + 1);
1024 S
.Source_Text
:= To_Source_Buffer_Ptr
(T
(0)'Address);
1029 Set_Source_File_Index_Table
(J
);
1037 procedure Tree_Write
is
1039 Source_File
.Tree_Write
;
1040 Instances
.Tree_Write
;
1042 -- The pointers we wrote out there for the source buffer and lines
1043 -- table pointers are junk, we now write out the actual data that
1044 -- is referenced by these two fields.
1046 for J
in Source_File
.First
.. Source_File
.Last
loop
1048 S
: Source_File_Record
renames Source_File
.Table
(J
);
1051 -- For instantiations, there is nothing to do, since the data is
1052 -- shared with the generic template. When the tree is read, the
1053 -- pointers must be set, but no extra data needs to be written.
1055 if S
.Instance
/= No_Instance_Id
then
1058 -- For the normal case, write out the data of the tables
1063 for J
in 1 .. S
.Last_Source_Line
loop
1064 Tree_Write_Int
(Int
(S
.Lines_Table
(J
)));
1067 -- Logical lines table if present
1069 if S
.Num_SRef_Pragmas
/= 0 then
1070 for J
in 1 .. S
.Last_Source_Line
loop
1071 Tree_Write_Int
(Int
(S
.Logical_Lines_Table
(J
)));
1078 (S
.Source_Text
(S
.Source_First
)'Address,
1079 Int
(S
.Source_Last
) - Int
(S
.Source_First
) + 1);
1085 --------------------
1086 -- Write_Location --
1087 --------------------
1089 procedure Write_Location
(P
: Source_Ptr
) is
1091 if P
= No_Location
then
1092 Write_Str
("<no location>");
1094 elsif P
<= Standard_Location
then
1095 Write_Str
("<standard location>");
1099 SI
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
1102 Write_Name
(Debug_Source_Name
(SI
));
1104 Write_Int
(Int
(Get_Logical_Line_Number
(P
)));
1106 Write_Int
(Int
(Get_Column_Number
(P
)));
1108 if Instantiation
(SI
) /= No_Location
then
1110 Write_Location
(Instantiation
(SI
));
1117 ----------------------
1118 -- Write_Time_Stamp --
1119 ----------------------
1121 procedure Write_Time_Stamp
(S
: Source_File_Index
) is
1122 T
: constant Time_Stamp_Type
:= Time_Stamp
(S
);
1135 Write_Char
(T
(P
+ 1));
1136 Write_Char
(T
(P
+ 2));
1139 Write_Char
(T
(P
+ 3));
1140 Write_Char
(T
(P
+ 4));
1143 Write_Char
(T
(P
+ 5));
1144 Write_Char
(T
(P
+ 6));
1147 Write_Char
(T
(P
+ 7));
1148 Write_Char
(T
(P
+ 8));
1151 Write_Char
(T
(P
+ 9));
1152 Write_Char
(T
(P
+ 10));
1155 Write_Char
(T
(P
+ 11));
1156 Write_Char
(T
(P
+ 12));
1157 end Write_Time_Stamp
;
1159 ----------------------------------------------
1160 -- Access Subprograms for Source File Table --
1161 ----------------------------------------------
1163 function Debug_Source_Name
(S
: SFI
) return File_Name_Type
is
1165 return Source_File
.Table
(S
).Debug_Source_Name
;
1166 end Debug_Source_Name
;
1168 function Instance
(S
: SFI
) return Instance_Id
is
1170 return Source_File
.Table
(S
).Instance
;
1173 function File_Name
(S
: SFI
) return File_Name_Type
is
1175 return Source_File
.Table
(S
).File_Name
;
1178 function File_Type
(S
: SFI
) return Type_Of_File
is
1180 return Source_File
.Table
(S
).File_Type
;
1183 function First_Mapped_Line
(S
: SFI
) return Logical_Line_Number
is
1185 return Source_File
.Table
(S
).First_Mapped_Line
;
1186 end First_Mapped_Line
;
1188 function Full_Debug_Name
(S
: SFI
) return File_Name_Type
is
1190 return Source_File
.Table
(S
).Full_Debug_Name
;
1191 end Full_Debug_Name
;
1193 function Full_File_Name
(S
: SFI
) return File_Name_Type
is
1195 return Source_File
.Table
(S
).Full_File_Name
;
1198 function Full_Ref_Name
(S
: SFI
) return File_Name_Type
is
1200 return Source_File
.Table
(S
).Full_Ref_Name
;
1203 function Identifier_Casing
(S
: SFI
) return Casing_Type
is
1205 return Source_File
.Table
(S
).Identifier_Casing
;
1206 end Identifier_Casing
;
1208 function Inherited_Pragma
(S
: SFI
) return Boolean is
1210 return Source_File
.Table
(S
).Inherited_Pragma
;
1211 end Inherited_Pragma
;
1213 function Inlined_Body
(S
: SFI
) return Boolean is
1215 return Source_File
.Table
(S
).Inlined_Body
;
1218 function Inlined_Call
(S
: SFI
) return Source_Ptr
is
1220 return Source_File
.Table
(S
).Inlined_Call
;
1223 function Keyword_Casing
(S
: SFI
) return Casing_Type
is
1225 return Source_File
.Table
(S
).Keyword_Casing
;
1228 function Last_Source_Line
(S
: SFI
) return Physical_Line_Number
is
1230 return Source_File
.Table
(S
).Last_Source_Line
;
1231 end Last_Source_Line
;
1233 function License
(S
: SFI
) return License_Type
is
1235 return Source_File
.Table
(S
).License
;
1238 function Num_SRef_Pragmas
(S
: SFI
) return Nat
is
1240 return Source_File
.Table
(S
).Num_SRef_Pragmas
;
1241 end Num_SRef_Pragmas
;
1243 function Reference_Name
(S
: SFI
) return File_Name_Type
is
1245 return Source_File
.Table
(S
).Reference_Name
;
1248 function Source_Checksum
(S
: SFI
) return Word
is
1250 return Source_File
.Table
(S
).Source_Checksum
;
1251 end Source_Checksum
;
1253 function Source_First
(S
: SFI
) return Source_Ptr
is
1255 if S
= Internal_Source_File
then
1256 return Internal_Source
'First;
1258 return Source_File
.Table
(S
).Source_First
;
1262 function Source_Last
(S
: SFI
) return Source_Ptr
is
1264 if S
= Internal_Source_File
then
1265 return Internal_Source
'Last;
1267 return Source_File
.Table
(S
).Source_Last
;
1271 function Source_Text
(S
: SFI
) return Source_Buffer_Ptr
is
1273 if S
= Internal_Source_File
then
1274 return Internal_Source_Ptr
;
1276 return Source_File
.Table
(S
).Source_Text
;
1280 function Template
(S
: SFI
) return SFI
is
1282 return Source_File
.Table
(S
).Template
;
1285 function Time_Stamp
(S
: SFI
) return Time_Stamp_Type
is
1287 return Source_File
.Table
(S
).Time_Stamp
;
1290 function Unit
(S
: SFI
) return Unit_Number_Type
is
1292 return Source_File
.Table
(S
).Unit
;
1295 ------------------------------------------
1296 -- Set Procedures for Source File Table --
1297 ------------------------------------------
1299 procedure Set_Identifier_Casing
(S
: SFI
; C
: Casing_Type
) is
1301 Source_File
.Table
(S
).Identifier_Casing
:= C
;
1302 end Set_Identifier_Casing
;
1304 procedure Set_Keyword_Casing
(S
: SFI
; C
: Casing_Type
) is
1306 Source_File
.Table
(S
).Keyword_Casing
:= C
;
1307 end Set_Keyword_Casing
;
1309 procedure Set_License
(S
: SFI
; L
: License_Type
) is
1311 Source_File
.Table
(S
).License
:= L
;
1314 procedure Set_Unit
(S
: SFI
; U
: Unit_Number_Type
) is
1316 Source_File
.Table
(S
).Unit
:= U
;
1319 ----------------------
1320 -- Trim_Lines_Table --
1321 ----------------------
1323 procedure Trim_Lines_Table
(S
: Source_File_Index
) is
1324 Max
: constant Nat
:= Nat
(Source_File
.Table
(S
).Last_Source_Line
);
1327 -- Release allocated storage that is no longer needed
1329 Source_File
.Table
(S
).Lines_Table
:= To_Pointer
1331 (To_Address
(Source_File
.Table
(S
).Lines_Table
),
1333 (Max
* (Lines_Table_Type
'Component_Size / System
.Storage_Unit
))));
1334 Source_File
.Table
(S
).Lines_Table_Max
:= Physical_Line_Number
(Max
);
1335 end Trim_Lines_Table
;
1343 Source_File
.Locked
:= False;
1344 Source_File
.Release
;
1351 procedure wl
(P
: Source_Ptr
) is