1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 pragma Style_Checks
(All_Checks
);
27 -- Subprograms not all in alpha order
29 with Atree
; use Atree
;
30 with Debug
; use Debug
;
32 with Output
; use Output
;
33 with Scans
; use Scans
;
34 with Sinfo
; use Sinfo
;
35 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
36 with Widechar
; use Widechar
;
38 with GNAT
.Byte_Order_Mark
; use GNAT
.Byte_Order_Mark
;
40 with System
.Storage_Elements
;
42 with System
.WCh_Con
; use System
.WCh_Con
;
44 with Ada
.Unchecked_Conversion
;
45 with Ada
.Unchecked_Deallocation
;
47 package body Sinput
is
51 -- Routines to support conversion between types Lines_Table_Ptr,
52 -- Logical_Lines_Table_Ptr and System.Address.
54 pragma Warnings
(Off
);
55 -- These unchecked conversions are aliasing safe, since they are never
56 -- used to construct improperly aliased pointer values.
58 function To_Address
is
59 new Ada
.Unchecked_Conversion
(Lines_Table_Ptr
, Address
);
61 function To_Address
is
62 new Ada
.Unchecked_Conversion
(Logical_Lines_Table_Ptr
, Address
);
64 function To_Pointer
is
65 new Ada
.Unchecked_Conversion
(Address
, Lines_Table_Ptr
);
67 function To_Pointer
is
68 new Ada
.Unchecked_Conversion
(Address
, Logical_Lines_Table_Ptr
);
72 -----------------------------
73 -- Source_File_Index_Table --
74 -----------------------------
76 -- The Get_Source_File_Index function is called very frequently. Earlier
77 -- versions cached a single entry, but then reverted to a serial search,
78 -- and this proved to be a significant source of inefficiency. We then
79 -- switched to using a table with a start point followed by a serial
80 -- search. Now we make sure source buffers are on a reasonable boundary
81 -- (see Types.Source_Align), and we can just use a direct look up in the
84 -- Note that this array is pretty large, but in most operating systems
85 -- it will not be allocated in physical memory unless it is actually used.
87 Source_File_Index_Table
:
88 array (Int
range 0 .. 1 + (Int
'Last / Source_Align
)) of Source_File_Index
;
90 ---------------------------
91 -- Add_Line_Tables_Entry --
92 ---------------------------
94 procedure Add_Line_Tables_Entry
95 (S
: in out Source_File_Record
;
98 LL
: Physical_Line_Number
;
101 -- Reallocate the lines tables if necessary
103 -- Note: the reason we do not use the normal Table package
104 -- mechanism is that we have several of these tables. We could
105 -- use the new GNAT.Dynamic_Tables package and that would probably
106 -- be a good idea ???
108 if S
.Last_Source_Line
= S
.Lines_Table_Max
then
111 Int
(S
.Last_Source_Line
) *
112 ((100 + Alloc
.Lines_Increment
) / 100));
115 Write_Str
("--> Reallocating lines table, size = ");
116 Write_Int
(Int
(S
.Lines_Table_Max
));
121 S
.Last_Source_Line
:= S
.Last_Source_Line
+ 1;
122 LL
:= S
.Last_Source_Line
;
124 S
.Lines_Table
(LL
) := P
;
126 -- Deal with setting new entry in logical lines table if one is
127 -- present. Note that there is always space (because the call to
128 -- Alloc_Line_Tables makes sure both tables are the same length),
130 if S
.Logical_Lines_Table
/= null then
132 -- We can always set the entry from the previous one, because
133 -- the processing for a Source_Reference pragma ensures that
134 -- at least one entry following the pragma is set up correctly.
136 S
.Logical_Lines_Table
(LL
) := S
.Logical_Lines_Table
(LL
- 1) + 1;
138 end Add_Line_Tables_Entry
;
140 -----------------------
141 -- Alloc_Line_Tables --
142 -----------------------
144 procedure Alloc_Line_Tables
145 (S
: in out Source_File_Record
;
148 subtype size_t
is Memory
.size_t
;
150 New_Table
: Lines_Table_Ptr
;
152 New_Logical_Table
: Logical_Lines_Table_Ptr
;
154 New_Size
: constant size_t
:=
155 size_t
(New_Max
* Lines_Table_Type
'Component_Size /
159 if S
.Lines_Table
= null then
160 New_Table
:= To_Pointer
(Memory
.Alloc
(New_Size
));
164 To_Pointer
(Memory
.Realloc
(To_Address
(S
.Lines_Table
), New_Size
));
167 if New_Table
= null then
170 S
.Lines_Table
:= New_Table
;
171 S
.Lines_Table_Max
:= Physical_Line_Number
(New_Max
);
174 if S
.Num_SRef_Pragmas
/= 0 then
175 if S
.Logical_Lines_Table
= null then
176 New_Logical_Table
:= To_Pointer
(Memory
.Alloc
(New_Size
));
178 New_Logical_Table
:= To_Pointer
179 (Memory
.Realloc
(To_Address
(S
.Logical_Lines_Table
), New_Size
));
182 if New_Logical_Table
= null then
185 S
.Logical_Lines_Table
:= New_Logical_Table
;
188 end Alloc_Line_Tables
;
194 procedure Backup_Line
(P
: in out Source_Ptr
) is
195 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
196 Src
: constant Source_Buffer_Ptr
:=
197 Source_File
.Table
(Sindex
).Source_Text
;
198 Sfirst
: constant Source_Ptr
:=
199 Source_File
.Table
(Sindex
).Source_First
;
209 if Src
(P
- 1) = LF
then
214 if Src
(P
- 1) = CR
then
219 -- Now find first character of the previous line
222 and then Src
(P
- 1) /= LF
223 and then Src
(P
- 1) /= CR
229 ---------------------------
230 -- Build_Location_String --
231 ---------------------------
233 procedure Build_Location_String
234 (Buf
: in out Bounded_String
;
237 Ptr
: Source_Ptr
:= Loc
;
240 -- Loop through instantiations
243 Append
(Buf
, Reference_Name
(Get_Source_File_Index
(Ptr
)));
245 Append
(Buf
, Nat
(Get_Logical_Line_Number
(Ptr
)));
247 Ptr
:= Instantiation_Location
(Ptr
);
248 exit when Ptr
= No_Location
;
249 Append
(Buf
, " instantiated at ");
251 end Build_Location_String
;
253 function Build_Location_String
(Loc
: Source_Ptr
) return String is
254 Buf
: Bounded_String
;
256 Build_Location_String
(Buf
, Loc
);
258 end Build_Location_String
;
264 procedure Check_For_BOM
is
267 Tst
: String (1 .. 5);
272 C
:= Source
(Scan_Ptr
+ Source_Ptr
(J
) - 1);
274 -- Definitely no BOM if EOF character marks either end of file, or
275 -- an illegal non-BOM character if not at the end of file.
284 Read_BOM
(Tst
, Len
, BOM
, XML_Support
=> False);
288 Scan_Ptr
:= Scan_Ptr
+ Source_Ptr
(Len
);
289 First_Non_Blank_Location
:= Scan_Ptr
;
290 Current_Line_Start
:= Scan_Ptr
;
291 Wide_Character_Encoding_Method
:= WCEM_UTF8
;
292 Upper_Half_Encoding
:= True;
298 Write_Line
("UTF-16 encoding format not recognized");
300 raise Unrecoverable_Error
;
306 Write_Line
("UTF-32 encoding format not recognized");
308 raise Unrecoverable_Error
;
318 -----------------------------
319 -- Clear_Source_File_Table --
320 -----------------------------
322 procedure Free
is new Ada
.Unchecked_Deallocation
323 (Lines_Table_Type
, Lines_Table_Ptr
);
325 procedure Free
is new Ada
.Unchecked_Deallocation
326 (Logical_Lines_Table_Type
, Logical_Lines_Table_Ptr
);
328 procedure Clear_Source_File_Table
is
330 for X
in 1 .. Source_File
.Last
loop
332 S
: Source_File_Record
renames Source_File
.Table
(X
);
334 if S
.Instance
= No_Instance_Id
then
335 Free_Source_Buffer
(S
.Source_Text
);
337 Free_Dope
(S
.Source_Text
'Address);
338 S
.Source_Text
:= null;
341 Free
(S
.Lines_Table
);
342 Free
(S
.Logical_Lines_Table
);
348 end Clear_Source_File_Table
;
350 ---------------------------------
351 -- Comes_From_Inherited_Pragma --
352 ---------------------------------
354 function Comes_From_Inherited_Pragma
(S
: Source_Ptr
) return Boolean is
355 SIE
: Source_File_Record
renames
356 Source_File
.Table
(Get_Source_File_Index
(S
));
358 return SIE
.Inherited_Pragma
;
359 end Comes_From_Inherited_Pragma
;
361 -----------------------------
362 -- Comes_From_Inlined_Body --
363 -----------------------------
365 function Comes_From_Inlined_Body
(S
: Source_Ptr
) return Boolean is
366 SIE
: Source_File_Record
renames
367 Source_File
.Table
(Get_Source_File_Index
(S
));
369 return SIE
.Inlined_Body
;
370 end Comes_From_Inlined_Body
;
372 ------------------------
373 -- Free_Source_Buffer --
374 ------------------------
376 procedure Free_Source_Buffer
(Src
: in out Source_Buffer_Ptr
) is
377 -- Unchecked_Deallocation doesn't work for access-to-constant; we need
378 -- to first Unchecked_Convert to access-to-variable.
380 function To_Source_Buffer_Ptr_Var
is new
381 Ada
.Unchecked_Conversion
(Source_Buffer_Ptr
, Source_Buffer_Ptr_Var
);
383 Temp
: Source_Buffer_Ptr_Var
:= To_Source_Buffer_Ptr_Var
(Src
);
385 procedure Free_Ptr
is new
386 Ada
.Unchecked_Deallocation
(Source_Buffer
, Source_Buffer_Ptr_Var
);
390 end Free_Source_Buffer
;
392 -----------------------
393 -- Get_Column_Number --
394 -----------------------
396 function Get_Column_Number
(P
: Source_Ptr
) return Column_Number
is
399 Sindex
: Source_File_Index
;
400 Src
: Source_Buffer_Ptr
;
403 -- If the input source pointer is not a meaningful value then return
404 -- at once with column number 1. This can happen for a file not found
405 -- condition for a file loaded indirectly by RTE, and also perhaps on
406 -- some unknown internal error conditions. In either case we certainly
407 -- don't want to blow up.
413 Sindex
:= Get_Source_File_Index
(P
);
414 Src
:= Source_File
.Table
(Sindex
).Source_Text
;
420 C
:= (C
- 1) / 8 * 8 + (8 + 1);
423 -- Deal with wide character case, but don't include brackets
424 -- notation in this circuit, since we know that this will
425 -- display unencoded (no one encodes brackets notation).
427 elsif Src
(S
) /= '[' and then Is_Start_Of_Wide_Char
(Src
, S
) then
431 -- Normal (non-wide) character case or brackets sequence
441 end Get_Column_Number
;
443 -----------------------------
444 -- Get_Logical_Line_Number --
445 -----------------------------
447 function Get_Logical_Line_Number
448 (P
: Source_Ptr
) return Logical_Line_Number
450 SFR
: Source_File_Record
451 renames Source_File
.Table
(Get_Source_File_Index
(P
));
453 L
: constant Physical_Line_Number
:= Get_Physical_Line_Number
(P
);
456 if SFR
.Num_SRef_Pragmas
= 0 then
457 return Logical_Line_Number
(L
);
459 return SFR
.Logical_Lines_Table
(L
);
461 end Get_Logical_Line_Number
;
463 ---------------------------------
464 -- Get_Logical_Line_Number_Img --
465 ---------------------------------
467 function Get_Logical_Line_Number_Img
468 (P
: Source_Ptr
) return String
472 Add_Nat_To_Name_Buffer
(Nat
(Get_Logical_Line_Number
(P
)));
473 return Name_Buffer
(1 .. Name_Len
);
474 end Get_Logical_Line_Number_Img
;
476 ------------------------------
477 -- Get_Physical_Line_Number --
478 ------------------------------
480 function Get_Physical_Line_Number
481 (P
: Source_Ptr
) return Physical_Line_Number
483 Sfile
: Source_File_Index
;
484 Table
: Lines_Table_Ptr
;
485 Lo
: Physical_Line_Number
;
486 Hi
: Physical_Line_Number
;
487 Mid
: Physical_Line_Number
;
491 -- If the input source pointer is not a meaningful value then return
492 -- at once with line number 1. This can happen for a file not found
493 -- condition for a file loaded indirectly by RTE, and also perhaps on
494 -- some unknown internal error conditions. In either case we certainly
495 -- don't want to blow up.
500 -- Otherwise we can do the binary search
503 Sfile
:= Get_Source_File_Index
(P
);
504 Loc
:= P
+ Source_File
.Table
(Sfile
).Sloc_Adjust
;
505 Table
:= Source_File
.Table
(Sfile
).Lines_Table
;
507 Hi
:= Source_File
.Table
(Sfile
).Last_Source_Line
;
510 Mid
:= (Lo
+ Hi
) / 2;
512 if Loc
< Table
(Mid
) then
515 else -- Loc >= Table (Mid)
518 Loc
< Table
(Mid
+ 1)
529 end Get_Physical_Line_Number
;
531 ---------------------------
532 -- Get_Source_File_Index --
533 ---------------------------
535 function Get_Source_File_Index
(S
: Source_Ptr
) return Source_File_Index
is
536 Result
: Source_File_Index
;
538 procedure Assertions
;
539 -- Assert various properties of the result
541 procedure Assertions
is
543 -- ???The old version using zero-origin array indexing without array
544 -- bounds checks returned 1 (i.e. system.ads) for these special
545 -- locations, presumably by accident. We are mimicing that here.
547 Special
: constant Boolean :=
549 or else S
= Standard_Location
550 or else S
= Standard_ASCII_Location
551 or else S
= System_Location
;
553 pragma Assert
(S
> No_Location
xor Special
);
554 pragma Assert
(Result
in Source_File
.First
.. Source_File
.Last
);
556 SFR
: Source_File_Record
renames Source_File
.Table
(Result
);
559 -- SFR.Source_Text = null if and only if this is the SFR for a debug
560 -- output file (*.dg), and that file is under construction. S can be
561 -- slightly past Source_Last in that case because we haven't updated
564 if Null_Source_Buffer_Ptr
(SFR
.Source_Text
) then
565 pragma Assert
(S
>= SFR
.Source_First
); null;
567 pragma Assert
(SFR
.Source_Text
'First = SFR
.Source_First
);
568 pragma Assert
(SFR
.Source_Text
'Last = SFR
.Source_Last
);
571 pragma Assert
(S
in SFR
.Source_First
.. SFR
.Source_Last
);
577 -- Start of processing for Get_Source_File_Index
580 if S
> No_Location
then
581 Result
:= Source_File_Index_Table
(Int
(S
) / Source_Align
);
586 pragma Debug
(Assertions
);
589 end Get_Source_File_Index
;
595 procedure Initialize
is
597 Source_gnat_adc
:= No_Source_File
;
600 Instances
.Append
(No_Location
);
601 pragma Assert
(Instances
.Last
= No_Instance_Id
);
608 function Instantiation
(S
: SFI
) return Source_Ptr
is
609 SIE
: Source_File_Record
renames Source_File
.Table
(S
);
611 if SIE
.Inlined_Body
or SIE
.Inherited_Pragma
then
612 return SIE
.Inlined_Call
;
614 return Instances
.Table
(SIE
.Instance
);
618 -------------------------
619 -- Instantiation_Depth --
620 -------------------------
622 function Instantiation_Depth
(S
: Source_Ptr
) return Nat
is
631 Sval
:= Instantiation_Location
(Sval
);
632 exit when Sval
= No_Location
;
637 end Instantiation_Depth
;
639 ----------------------------
640 -- Instantiation_Location --
641 ----------------------------
643 function Instantiation_Location
(S
: Source_Ptr
) return Source_Ptr
is
645 return Instantiation
(Get_Source_File_Index
(S
));
646 end Instantiation_Location
;
648 --------------------------
649 -- Iterate_On_Instances --
650 --------------------------
652 procedure Iterate_On_Instances
is
654 for J
in 1 .. Instances
.Last
loop
655 Process
(J
, Instances
.Table
(J
));
657 end Iterate_On_Instances
;
659 ----------------------
660 -- Last_Source_File --
661 ----------------------
663 function Last_Source_File
return Source_File_Index
is
665 return Source_File
.Last
;
666 end Last_Source_File
;
672 function Line_Start
(P
: Source_Ptr
) return Source_Ptr
is
673 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
674 Src
: constant Source_Buffer_Ptr
:=
675 Source_File
.Table
(Sindex
).Source_Text
;
676 Sfirst
: constant Source_Ptr
:=
677 Source_File
.Table
(Sindex
).Source_First
;
683 and then Src
(S
- 1) /= CR
684 and then Src
(S
- 1) /= LF
693 (L
: Physical_Line_Number
;
694 S
: Source_File_Index
) return Source_Ptr
697 return Source_File
.Table
(S
).Lines_Table
(L
);
707 Source_File
.Locked
:= True;
710 ----------------------
711 -- Num_Source_Files --
712 ----------------------
714 function Num_Source_Files
return Nat
is
716 return Int
(Source_File
.Last
) - Int
(Source_File
.First
) + 1;
717 end Num_Source_Files
;
719 ----------------------
720 -- Num_Source_Lines --
721 ----------------------
723 function Num_Source_Lines
(S
: Source_File_Index
) return Nat
is
725 return Nat
(Source_File
.Table
(S
).Last_Source_Line
);
726 end Num_Source_Lines
;
728 -----------------------
729 -- Original_Location --
730 -----------------------
732 function Original_Location
(S
: Source_Ptr
) return Source_Ptr
is
733 Sindex
: Source_File_Index
;
734 Tindex
: Source_File_Index
;
737 if S
<= No_Location
then
741 Sindex
:= Get_Source_File_Index
(S
);
743 if Instantiation
(Sindex
) = No_Location
then
747 Tindex
:= Template
(Sindex
);
748 while Instantiation
(Tindex
) /= No_Location
loop
749 Tindex
:= Template
(Tindex
);
752 return S
- Source_First
(Sindex
) + Source_First
(Tindex
);
755 end Original_Location
;
757 -------------------------
758 -- Physical_To_Logical --
759 -------------------------
761 function Physical_To_Logical
762 (Line
: Physical_Line_Number
;
763 S
: Source_File_Index
) return Logical_Line_Number
765 SFR
: Source_File_Record
renames Source_File
.Table
(S
);
768 if SFR
.Num_SRef_Pragmas
= 0 then
769 return Logical_Line_Number
(Line
);
771 return SFR
.Logical_Lines_Table
(Line
);
773 end Physical_To_Logical
;
775 --------------------------------
776 -- Register_Source_Ref_Pragma --
777 --------------------------------
779 procedure Register_Source_Ref_Pragma
780 (File_Name
: File_Name_Type
;
781 Stripped_File_Name
: File_Name_Type
;
783 Line_After_Pragma
: Physical_Line_Number
)
785 subtype size_t
is Memory
.size_t
;
787 SFR
: Source_File_Record
renames Source_File
.Table
(Current_Source_File
);
789 ML
: Logical_Line_Number
;
792 if File_Name
/= No_File
then
793 SFR
.Reference_Name
:= Stripped_File_Name
;
794 SFR
.Full_Ref_Name
:= File_Name
;
796 if not Debug_Generated_Code
then
797 SFR
.Debug_Source_Name
:= Stripped_File_Name
;
798 SFR
.Full_Debug_Name
:= File_Name
;
801 SFR
.Num_SRef_Pragmas
:= SFR
.Num_SRef_Pragmas
+ 1;
804 if SFR
.Num_SRef_Pragmas
= 1 then
805 SFR
.First_Mapped_Line
:= Logical_Line_Number
(Mapped_Line
);
808 if SFR
.Logical_Lines_Table
= null then
809 SFR
.Logical_Lines_Table
:= To_Pointer
811 (size_t
(SFR
.Lines_Table_Max
*
812 Logical_Lines_Table_Type
'Component_Size /
816 SFR
.Logical_Lines_Table
(Line_After_Pragma
- 1) := No_Line_Number
;
818 ML
:= Logical_Line_Number
(Mapped_Line
);
819 for J
in Line_After_Pragma
.. SFR
.Last_Source_Line
loop
820 SFR
.Logical_Lines_Table
(J
) := ML
;
823 end Register_Source_Ref_Pragma
;
825 ---------------------------------
826 -- Set_Source_File_Index_Table --
827 ---------------------------------
829 procedure Set_Source_File_Index_Table
(Xnew
: Source_File_Index
) is
832 SL
: constant Source_Ptr
:= Source_File
.Table
(Xnew
).Source_Last
;
834 SP
:= Source_File
.Table
(Xnew
).Source_First
;
835 pragma Assert
(SP
mod Source_Align
= 0);
836 Ind
:= Int
(SP
) / Source_Align
;
838 Source_File_Index_Table
(Ind
) := Xnew
;
839 SP
:= SP
+ Source_Align
;
842 end Set_Source_File_Index_Table
;
844 ---------------------------
845 -- Skip_Line_Terminators --
846 ---------------------------
848 procedure Skip_Line_Terminators
849 (P
: in out Source_Ptr
;
850 Physical
: out Boolean)
852 Chr
: constant Character := Source
(P
);
856 if Source
(P
+ 1) = LF
then
865 elsif Chr
= FF
or else Chr
= VT
then
870 -- Otherwise we have a wide character
873 Skip_Wide
(Source
, P
);
876 -- Fall through in the physical line terminator case. First deal with
877 -- making a possible entry into the lines table if one is needed.
879 -- Note: we are dealing with a real source file here, this cannot be
880 -- the instantiation case, so we need not worry about Sloc adjustment.
883 S
: Source_File_Record
884 renames Source_File
.Table
(Current_Source_File
);
889 -- Make entry in lines table if not already made (in some scan backup
890 -- cases, we will be rescanning previously scanned source, so the
891 -- entry may have already been made on the previous forward scan).
894 and then P
> S
.Lines_Table
(S
.Last_Source_Line
)
896 Add_Line_Tables_Entry
(S
, P
);
899 end Skip_Line_Terminators
;
906 (Src
: System
.Address
; New_Dope
: Dope_Ptr
)
908 -- A fat pointer is a pair consisting of data pointer and dope pointer,
909 -- in that order. So we want to overwrite the second word.
910 Dope
: System
.Address
;
911 pragma Import
(Ada
, Dope
);
912 use System
.Storage_Elements
;
913 for Dope
'Address use Src
+ System
.Address
'Size / 8;
915 Dope
:= New_Dope
.all'Address;
918 procedure Free_Dope
(Src
: System
.Address
) is
920 pragma Import
(Ada
, Dope
);
921 use System
.Storage_Elements
;
922 for Dope
'Address use Src
+ System
.Address
'Size / 8;
923 procedure Free
is new Ada
.Unchecked_Deallocation
(Dope_Rec
, Dope_Ptr
);
932 procedure Sloc_Range
(N
: Node_Id
; Min
, Max
: out Source_Ptr
) is
934 Indx
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
936 function Process
(N
: Node_Id
) return Traverse_Result
;
937 -- Process function for traversing the node tree
939 procedure Traverse
is new Traverse_Proc
(Process
);
945 function Process
(N
: Node_Id
) return Traverse_Result
is
946 Loc
: constant Source_Ptr
:= Sloc
(Original_Node
(N
));
949 -- Skip nodes that may have been added during expansion and
950 -- that originate in other units, such as code for contracts
951 -- in subprogram bodies.
953 if Get_Source_File_Index
(Loc
) /= Indx
then
957 if Loc
> No_Location
then
968 -- Start of processing for Sloc_Range
980 function Source_Offset
(S
: Source_Ptr
) return Nat
is
981 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(S
);
982 Sfirst
: constant Source_Ptr
:=
983 Source_File
.Table
(Sindex
).Source_First
;
985 return Nat
(S
- Sfirst
);
988 ------------------------
989 -- Top_Level_Location --
990 ------------------------
992 function Top_Level_Location
(S
: Source_Ptr
) return Source_Ptr
is
1000 Newloc
:= Instantiation_Location
(Oldloc
);
1001 exit when Newloc
= No_Location
;
1005 end Top_Level_Location
;
1007 --------------------
1008 -- Write_Location --
1009 --------------------
1011 procedure Write_Location
(P
: Source_Ptr
) is
1013 if P
= No_Location
then
1014 Write_Str
("<no location>");
1016 elsif P
<= Standard_Location
then
1017 Write_Str
("<standard location>");
1021 SI
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
1024 Write_Name_For_Debug
(Debug_Source_Name
(SI
));
1026 Write_Int
(Int
(Get_Logical_Line_Number
(P
)));
1028 Write_Int
(Int
(Get_Column_Number
(P
)));
1030 if Instantiation
(SI
) /= No_Location
then
1032 Write_Location
(Instantiation
(SI
));
1039 ----------------------
1040 -- Write_Time_Stamp --
1041 ----------------------
1043 procedure Write_Time_Stamp
(S
: Source_File_Index
) is
1044 T
: constant Time_Stamp_Type
:= Time_Stamp
(S
);
1057 Write_Char
(T
(P
+ 1));
1058 Write_Char
(T
(P
+ 2));
1061 Write_Char
(T
(P
+ 3));
1062 Write_Char
(T
(P
+ 4));
1065 Write_Char
(T
(P
+ 5));
1066 Write_Char
(T
(P
+ 6));
1069 Write_Char
(T
(P
+ 7));
1070 Write_Char
(T
(P
+ 8));
1073 Write_Char
(T
(P
+ 9));
1074 Write_Char
(T
(P
+ 10));
1077 Write_Char
(T
(P
+ 11));
1078 Write_Char
(T
(P
+ 12));
1079 end Write_Time_Stamp
;
1081 ----------------------------------------------
1082 -- Access Subprograms for Source File Table --
1083 ----------------------------------------------
1085 function Debug_Source_Name
(S
: SFI
) return File_Name_Type
is
1087 return Source_File
.Table
(S
).Debug_Source_Name
;
1088 end Debug_Source_Name
;
1090 function Instance
(S
: SFI
) return Instance_Id
is
1092 return Source_File
.Table
(S
).Instance
;
1095 function File_Name
(S
: SFI
) return File_Name_Type
is
1097 return Source_File
.Table
(S
).File_Name
;
1100 function File_Type
(S
: SFI
) return Type_Of_File
is
1102 return Source_File
.Table
(S
).File_Type
;
1105 function First_Mapped_Line
(S
: SFI
) return Logical_Line_Number
is
1107 return Source_File
.Table
(S
).First_Mapped_Line
;
1108 end First_Mapped_Line
;
1110 function Full_Debug_Name
(S
: SFI
) return File_Name_Type
is
1112 return Source_File
.Table
(S
).Full_Debug_Name
;
1113 end Full_Debug_Name
;
1115 function Full_File_Name
(S
: SFI
) return File_Name_Type
is
1117 return Source_File
.Table
(S
).Full_File_Name
;
1120 function Full_Ref_Name
(S
: SFI
) return File_Name_Type
is
1122 return Source_File
.Table
(S
).Full_Ref_Name
;
1125 function Identifier_Casing
(S
: SFI
) return Casing_Type
is
1127 return Source_File
.Table
(S
).Identifier_Casing
;
1128 end Identifier_Casing
;
1130 function Inherited_Pragma
(S
: SFI
) return Boolean is
1132 return Source_File
.Table
(S
).Inherited_Pragma
;
1133 end Inherited_Pragma
;
1135 function Inlined_Body
(S
: SFI
) return Boolean is
1137 return Source_File
.Table
(S
).Inlined_Body
;
1140 function Inlined_Call
(S
: SFI
) return Source_Ptr
is
1142 return Source_File
.Table
(S
).Inlined_Call
;
1145 function Keyword_Casing
(S
: SFI
) return Casing_Type
is
1147 return Source_File
.Table
(S
).Keyword_Casing
;
1150 function Last_Source_Line
(S
: SFI
) return Physical_Line_Number
is
1152 return Source_File
.Table
(S
).Last_Source_Line
;
1153 end Last_Source_Line
;
1155 function License
(S
: SFI
) return License_Type
is
1157 return Source_File
.Table
(S
).License
;
1160 function Num_SRef_Pragmas
(S
: SFI
) return Nat
is
1162 return Source_File
.Table
(S
).Num_SRef_Pragmas
;
1163 end Num_SRef_Pragmas
;
1165 function Reference_Name
(S
: SFI
) return File_Name_Type
is
1167 return Source_File
.Table
(S
).Reference_Name
;
1170 function Source_Checksum
(S
: SFI
) return Word
is
1172 return Source_File
.Table
(S
).Source_Checksum
;
1173 end Source_Checksum
;
1175 function Source_First
(S
: SFI
) return Source_Ptr
is
1177 return Source_File
.Table
(S
).Source_First
;
1180 function Source_Last
(S
: SFI
) return Source_Ptr
is
1182 return Source_File
.Table
(S
).Source_Last
;
1185 function Source_Text
(S
: SFI
) return Source_Buffer_Ptr
is
1187 return Source_File
.Table
(S
).Source_Text
;
1190 function Template
(S
: SFI
) return SFI
is
1192 return Source_File
.Table
(S
).Template
;
1195 function Time_Stamp
(S
: SFI
) return Time_Stamp_Type
is
1197 return Source_File
.Table
(S
).Time_Stamp
;
1200 function Unit
(S
: SFI
) return Unit_Number_Type
is
1202 return Source_File
.Table
(S
).Unit
;
1205 ------------------------------------------
1206 -- Set Procedures for Source File Table --
1207 ------------------------------------------
1209 procedure Set_Identifier_Casing
(S
: SFI
; C
: Casing_Type
) is
1211 Source_File
.Table
(S
).Identifier_Casing
:= C
;
1212 end Set_Identifier_Casing
;
1214 procedure Set_Keyword_Casing
(S
: SFI
; C
: Casing_Type
) is
1216 Source_File
.Table
(S
).Keyword_Casing
:= C
;
1217 end Set_Keyword_Casing
;
1219 procedure Set_License
(S
: SFI
; L
: License_Type
) is
1221 Source_File
.Table
(S
).License
:= L
;
1224 procedure Set_Unit
(S
: SFI
; U
: Unit_Number_Type
) is
1226 Source_File
.Table
(S
).Unit
:= U
;
1229 ----------------------
1230 -- Trim_Lines_Table --
1231 ----------------------
1233 procedure Trim_Lines_Table
(S
: Source_File_Index
) is
1234 Max
: constant Nat
:= Nat
(Source_File
.Table
(S
).Last_Source_Line
);
1237 -- Release allocated storage that is no longer needed
1239 Source_File
.Table
(S
).Lines_Table
:= To_Pointer
1241 (To_Address
(Source_File
.Table
(S
).Lines_Table
),
1243 (Max
* (Lines_Table_Type
'Component_Size / System
.Storage_Unit
))));
1244 Source_File
.Table
(S
).Lines_Table_Max
:= Physical_Line_Number
(Max
);
1245 end Trim_Lines_Table
;
1253 Source_File
.Locked
:= False;
1254 Source_File
.Release
;
1261 procedure wl
(P
: Source_Ptr
) is