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 -------------------------
483 -- Instantiation_Depth --
484 -------------------------
486 function Instantiation_Depth
(S
: Source_Ptr
) return Nat
is
487 Sind
: Source_File_Index
;
496 Sind
:= Get_Source_File_Index
(Sval
);
497 Sval
:= Instantiation
(Sind
);
498 exit when Sval
= No_Location
;
503 end Instantiation_Depth
;
505 ----------------------------
506 -- Instantiation_Location --
507 ----------------------------
509 function Instantiation_Location
(S
: Source_Ptr
) return Source_Ptr
is
511 return Instantiation
(Get_Source_File_Index
(S
));
512 end Instantiation_Location
;
514 ----------------------
515 -- Last_Source_File --
516 ----------------------
518 function Last_Source_File
return Source_File_Index
is
520 return Source_File
.Last
;
521 end Last_Source_File
;
527 function Line_Start
(P
: Source_Ptr
) return Source_Ptr
is
528 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
529 Src
: constant Source_Buffer_Ptr
:=
530 Source_File
.Table
(Sindex
).Source_Text
;
531 Sfirst
: constant Source_Ptr
:=
532 Source_File
.Table
(Sindex
).Source_First
;
538 and then Src
(S
- 1) /= CR
539 and then Src
(S
- 1) /= LF
548 (L
: Physical_Line_Number
;
549 S
: Source_File_Index
) return Source_Ptr
552 return Source_File
.Table
(S
).Lines_Table
(L
);
561 Source_File
.Locked
:= True;
565 ----------------------
566 -- Num_Source_Files --
567 ----------------------
569 function Num_Source_Files
return Nat
is
571 return Int
(Source_File
.Last
) - Int
(Source_File
.First
) + 1;
572 end Num_Source_Files
;
574 ----------------------
575 -- Num_Source_Lines --
576 ----------------------
578 function Num_Source_Lines
(S
: Source_File_Index
) return Nat
is
580 return Nat
(Source_File
.Table
(S
).Last_Source_Line
);
581 end Num_Source_Lines
;
583 -----------------------
584 -- Original_Location --
585 -----------------------
587 function Original_Location
(S
: Source_Ptr
) return Source_Ptr
is
588 Sindex
: Source_File_Index
;
589 Tindex
: Source_File_Index
;
592 if S
<= No_Location
then
596 Sindex
:= Get_Source_File_Index
(S
);
598 if Instantiation
(Sindex
) = No_Location
then
602 Tindex
:= Template
(Sindex
);
603 while Instantiation
(Tindex
) /= No_Location
loop
604 Tindex
:= Template
(Tindex
);
607 return S
- Source_First
(Sindex
) + Source_First
(Tindex
);
610 end Original_Location
;
612 -------------------------
613 -- Physical_To_Logical --
614 -------------------------
616 function Physical_To_Logical
617 (Line
: Physical_Line_Number
;
618 S
: Source_File_Index
) return Logical_Line_Number
620 SFR
: Source_File_Record
renames Source_File
.Table
(S
);
623 if SFR
.Num_SRef_Pragmas
= 0 then
624 return Logical_Line_Number
(Line
);
626 return SFR
.Logical_Lines_Table
(Line
);
628 end Physical_To_Logical
;
630 --------------------------------
631 -- Register_Source_Ref_Pragma --
632 --------------------------------
634 procedure Register_Source_Ref_Pragma
635 (File_Name
: File_Name_Type
;
636 Stripped_File_Name
: File_Name_Type
;
638 Line_After_Pragma
: Physical_Line_Number
)
640 subtype size_t
is Memory
.size_t
;
642 SFR
: Source_File_Record
renames Source_File
.Table
(Current_Source_File
);
644 ML
: Logical_Line_Number
;
647 if File_Name
/= No_File
then
648 SFR
.Reference_Name
:= Stripped_File_Name
;
649 SFR
.Full_Ref_Name
:= File_Name
;
651 if not Debug_Generated_Code
then
652 SFR
.Debug_Source_Name
:= Stripped_File_Name
;
653 SFR
.Full_Debug_Name
:= File_Name
;
656 SFR
.Num_SRef_Pragmas
:= SFR
.Num_SRef_Pragmas
+ 1;
659 if SFR
.Num_SRef_Pragmas
= 1 then
660 SFR
.First_Mapped_Line
:= Logical_Line_Number
(Mapped_Line
);
663 if SFR
.Logical_Lines_Table
= null then
664 SFR
.Logical_Lines_Table
:= To_Pointer
666 (size_t
(SFR
.Lines_Table_Max
*
667 Logical_Lines_Table_Type
'Component_Size /
671 SFR
.Logical_Lines_Table
(Line_After_Pragma
- 1) := No_Line_Number
;
673 ML
:= Logical_Line_Number
(Mapped_Line
);
674 for J
in Line_After_Pragma
.. SFR
.Last_Source_Line
loop
675 SFR
.Logical_Lines_Table
(J
) := ML
;
678 end Register_Source_Ref_Pragma
;
680 ---------------------------------
681 -- Set_Source_File_Index_Table --
682 ---------------------------------
684 procedure Set_Source_File_Index_Table
(Xnew
: Source_File_Index
) is
687 SL
: constant Source_Ptr
:= Source_File
.Table
(Xnew
).Source_Last
;
690 SP
:= (Source_File
.Table
(Xnew
).Source_First
+ Chunk_Size
- 1)
691 / Chunk_Size
* Chunk_Size
;
692 Ind
:= Int
(SP
) / Chunk_Size
;
695 Source_File_Index_Table
(Ind
) := Xnew
;
696 SP
:= SP
+ Chunk_Size
;
699 end Set_Source_File_Index_Table
;
701 ---------------------------
702 -- Skip_Line_Terminators --
703 ---------------------------
705 procedure Skip_Line_Terminators
706 (P
: in out Source_Ptr
;
707 Physical
: out Boolean)
709 Chr
: constant Character := Source
(P
);
713 if Source
(P
+ 1) = LF
then
722 elsif Chr
= FF
or else Chr
= VT
then
727 -- Otherwise we have a wide character
730 Skip_Wide
(Source
, P
);
733 -- Fall through in the physical line terminator case. First deal with
734 -- making a possible entry into the lines table if one is needed.
736 -- Note: we are dealing with a real source file here, this cannot be
737 -- the instantiation case, so we need not worry about Sloc adjustment.
740 S
: Source_File_Record
741 renames Source_File
.Table
(Current_Source_File
);
746 -- Make entry in lines table if not already made (in some scan backup
747 -- cases, we will be rescanning previously scanned source, so the
748 -- entry may have already been made on the previous forward scan).
751 and then P
> S
.Lines_Table
(S
.Last_Source_Line
)
753 Add_Line_Tables_Entry
(S
, P
);
756 end Skip_Line_Terminators
;
762 procedure Sloc_Range
(N
: Node_Id
; Min
, Max
: out Source_Ptr
) is
764 function Process
(N
: Node_Id
) return Traverse_Result
;
765 -- Process function for traversing the node tree
767 procedure Traverse
is new Traverse_Proc
(Process
);
773 function Process
(N
: Node_Id
) return Traverse_Result
is
775 if Sloc
(N
) < Min
then
776 if Sloc
(N
) > No_Location
then
779 elsif Sloc
(N
) > Max
then
780 if Sloc
(N
) > No_Location
then
788 -- Start of processing for Sloc_Range
800 function Source_Offset
(S
: Source_Ptr
) return Nat
is
801 Sindex
: constant Source_File_Index
:= Get_Source_File_Index
(S
);
802 Sfirst
: constant Source_Ptr
:=
803 Source_File
.Table
(Sindex
).Source_First
;
805 return Nat
(S
- Sfirst
);
808 ------------------------
809 -- Top_Level_Location --
810 ------------------------
812 function Top_Level_Location
(S
: Source_Ptr
) return Source_Ptr
is
820 Newloc
:= Instantiation_Location
(Oldloc
);
821 exit when Newloc
= No_Location
;
825 end Top_Level_Location
;
831 procedure Tree_Read
is
833 -- First we must free any old source buffer pointers
835 if not First_Time_Around
then
836 for J
in Source_File
.First
.. Source_File
.Last
loop
838 S
: Source_File_Record
renames Source_File
.Table
(J
);
840 procedure Free_Ptr
is new Unchecked_Deallocation
841 (Big_Source_Buffer
, Source_Buffer_Ptr
);
843 pragma Warnings
(Off
);
844 -- This unchecked conversion is aliasing safe, since it is not
845 -- used to create improperly aliased pointer values.
847 function To_Source_Buffer_Ptr
is new
848 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
850 pragma Warnings
(On
);
852 Tmp1
: Source_Buffer_Ptr
;
855 if S
.Instantiation
/= No_Location
then
859 -- Free the buffer, we use Free here, because we used malloc
860 -- or realloc directly to allocate the tables. That is
861 -- because we were playing the big array trick.
863 -- We have to recreate a proper pointer to the actual array
864 -- from the zero origin pointer stored in the source table.
868 (S
.Source_Text
(S
.Source_First
)'Address);
871 if S
.Lines_Table
/= null then
872 Memory
.Free
(To_Address
(S
.Lines_Table
));
873 S
.Lines_Table
:= null;
876 if S
.Logical_Lines_Table
/= null then
877 Memory
.Free
(To_Address
(S
.Logical_Lines_Table
));
878 S
.Logical_Lines_Table
:= null;
885 -- Reset source cache pointers to force new read
887 Source_Cache_First
:= 1;
888 Source_Cache_Last
:= 0;
890 -- Read in source file table
892 Source_File
.Tree_Read
;
894 -- The pointers we read in there for the source buffer and lines
895 -- table pointers are junk. We now read in the actual data that
896 -- is referenced by these two fields.
898 for J
in Source_File
.First
.. Source_File
.Last
loop
900 S
: Source_File_Record
renames Source_File
.Table
(J
);
903 -- For the instantiation case, we do not read in any data. Instead
904 -- we share the data for the generic template entry. Since the
905 -- template always occurs first, we can safely refer to its data.
907 if S
.Instantiation
/= No_Location
then
909 ST
: Source_File_Record
renames
910 Source_File
.Table
(S
.Template
);
913 -- The lines tables are copied from the template entry
916 Source_File
.Table
(S
.Template
).Lines_Table
;
917 S
.Logical_Lines_Table
:=
918 Source_File
.Table
(S
.Template
).Logical_Lines_Table
;
920 -- In the case of the source table pointer, we share the
921 -- same data as the generic template, but the virtual origin
922 -- is adjusted. For example, if the first subscript of the
923 -- template is 100, and that of the instantiation is 200,
924 -- then the instantiation pointer is obtained by subtracting
925 -- 100 from the template pointer.
928 pragma Suppress
(All_Checks
);
930 pragma Warnings
(Off
);
931 -- This unchecked conversion is aliasing safe since it
932 -- not used to create improperly aliased pointer values.
934 function To_Source_Buffer_Ptr
is new
935 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
937 pragma Warnings
(On
);
943 (ST
.Source_First
- S
.Source_First
)'Address);
947 -- Normal case (non-instantiation)
950 First_Time_Around
:= False;
951 S
.Lines_Table
:= null;
952 S
.Logical_Lines_Table
:= null;
953 Alloc_Line_Tables
(S
, Int
(S
.Last_Source_Line
));
955 for J
in 1 .. S
.Last_Source_Line
loop
956 Tree_Read_Int
(Int
(S
.Lines_Table
(J
)));
959 if S
.Num_SRef_Pragmas
/= 0 then
960 for J
in 1 .. S
.Last_Source_Line
loop
961 Tree_Read_Int
(Int
(S
.Logical_Lines_Table
(J
)));
965 -- Allocate source buffer and read in the data and then set the
966 -- virtual origin to point to the logical zero'th element. This
967 -- address must be computed with subscript checks turned off.
970 subtype B
is Text_Buffer
(S
.Source_First
.. S
.Source_Last
);
971 type Text_Buffer_Ptr
is access B
;
974 pragma Suppress
(All_Checks
);
976 pragma Warnings
(Off
);
977 -- This unchecked conversion is aliasing safe, since it is
978 -- never used to create improperly aliased pointer values.
980 function To_Source_Buffer_Ptr
is new
981 Unchecked_Conversion
(Address
, Source_Buffer_Ptr
);
983 pragma Warnings
(On
);
988 Tree_Read_Data
(T
(S
.Source_First
)'Address,
989 Int
(S
.Source_Last
) - Int
(S
.Source_First
) + 1);
991 S
.Source_Text
:= To_Source_Buffer_Ptr
(T
(0)'Address);
996 Set_Source_File_Index_Table
(J
);
1004 procedure Tree_Write
is
1006 Source_File
.Tree_Write
;
1008 -- The pointers we wrote out there for the source buffer and lines
1009 -- table pointers are junk, we now write out the actual data that
1010 -- is referenced by these two fields.
1012 for J
in Source_File
.First
.. Source_File
.Last
loop
1014 S
: Source_File_Record
renames Source_File
.Table
(J
);
1017 -- For instantiations, there is nothing to do, since the data is
1018 -- shared with the generic template. When the tree is read, the
1019 -- pointers must be set, but no extra data needs to be written.
1021 if S
.Instantiation
/= No_Location
then
1024 -- For the normal case, write out the data of the tables
1029 for J
in 1 .. S
.Last_Source_Line
loop
1030 Tree_Write_Int
(Int
(S
.Lines_Table
(J
)));
1033 -- Logical lines table if present
1035 if S
.Num_SRef_Pragmas
/= 0 then
1036 for J
in 1 .. S
.Last_Source_Line
loop
1037 Tree_Write_Int
(Int
(S
.Logical_Lines_Table
(J
)));
1044 (S
.Source_Text
(S
.Source_First
)'Address,
1045 Int
(S
.Source_Last
) - Int
(S
.Source_First
) + 1);
1051 --------------------
1052 -- Write_Location --
1053 --------------------
1055 procedure Write_Location
(P
: Source_Ptr
) is
1057 if P
= No_Location
then
1058 Write_Str
("<no location>");
1060 elsif P
<= Standard_Location
then
1061 Write_Str
("<standard location>");
1065 SI
: constant Source_File_Index
:= Get_Source_File_Index
(P
);
1068 Write_Name
(Debug_Source_Name
(SI
));
1070 Write_Int
(Int
(Get_Logical_Line_Number
(P
)));
1072 Write_Int
(Int
(Get_Column_Number
(P
)));
1074 if Instantiation
(SI
) /= No_Location
then
1076 Write_Location
(Instantiation
(SI
));
1083 ----------------------
1084 -- Write_Time_Stamp --
1085 ----------------------
1087 procedure Write_Time_Stamp
(S
: Source_File_Index
) is
1088 T
: constant Time_Stamp_Type
:= Time_Stamp
(S
);
1101 Write_Char
(T
(P
+ 1));
1102 Write_Char
(T
(P
+ 2));
1105 Write_Char
(T
(P
+ 3));
1106 Write_Char
(T
(P
+ 4));
1109 Write_Char
(T
(P
+ 5));
1110 Write_Char
(T
(P
+ 6));
1113 Write_Char
(T
(P
+ 7));
1114 Write_Char
(T
(P
+ 8));
1117 Write_Char
(T
(P
+ 9));
1118 Write_Char
(T
(P
+ 10));
1121 Write_Char
(T
(P
+ 11));
1122 Write_Char
(T
(P
+ 12));
1123 end Write_Time_Stamp
;
1125 ----------------------------------------------
1126 -- Access Subprograms for Source File Table --
1127 ----------------------------------------------
1129 function Debug_Source_Name
(S
: SFI
) return File_Name_Type
is
1131 return Source_File
.Table
(S
).Debug_Source_Name
;
1132 end Debug_Source_Name
;
1134 function File_Name
(S
: SFI
) return File_Name_Type
is
1136 return Source_File
.Table
(S
).File_Name
;
1139 function File_Type
(S
: SFI
) return Type_Of_File
is
1141 return Source_File
.Table
(S
).File_Type
;
1144 function First_Mapped_Line
(S
: SFI
) return Logical_Line_Number
is
1146 return Source_File
.Table
(S
).First_Mapped_Line
;
1147 end First_Mapped_Line
;
1149 function Full_Debug_Name
(S
: SFI
) return File_Name_Type
is
1151 return Source_File
.Table
(S
).Full_Debug_Name
;
1152 end Full_Debug_Name
;
1154 function Full_File_Name
(S
: SFI
) return File_Name_Type
is
1156 return Source_File
.Table
(S
).Full_File_Name
;
1159 function Full_Ref_Name
(S
: SFI
) return File_Name_Type
is
1161 return Source_File
.Table
(S
).Full_Ref_Name
;
1164 function Identifier_Casing
(S
: SFI
) return Casing_Type
is
1166 return Source_File
.Table
(S
).Identifier_Casing
;
1167 end Identifier_Casing
;
1169 function Inlined_Body
(S
: SFI
) return Boolean is
1171 return Source_File
.Table
(S
).Inlined_Body
;
1174 function Instantiation
(S
: SFI
) return Source_Ptr
is
1176 return Source_File
.Table
(S
).Instantiation
;
1179 function Keyword_Casing
(S
: SFI
) return Casing_Type
is
1181 return Source_File
.Table
(S
).Keyword_Casing
;
1184 function Last_Source_Line
(S
: SFI
) return Physical_Line_Number
is
1186 return Source_File
.Table
(S
).Last_Source_Line
;
1187 end Last_Source_Line
;
1189 function License
(S
: SFI
) return License_Type
is
1191 return Source_File
.Table
(S
).License
;
1194 function Num_SRef_Pragmas
(S
: SFI
) return Nat
is
1196 return Source_File
.Table
(S
).Num_SRef_Pragmas
;
1197 end Num_SRef_Pragmas
;
1199 function Reference_Name
(S
: SFI
) return File_Name_Type
is
1201 return Source_File
.Table
(S
).Reference_Name
;
1204 function Source_Checksum
(S
: SFI
) return Word
is
1206 return Source_File
.Table
(S
).Source_Checksum
;
1207 end Source_Checksum
;
1209 function Source_First
(S
: SFI
) return Source_Ptr
is
1211 if S
= Internal_Source_File
then
1212 return Internal_Source
'First;
1214 return Source_File
.Table
(S
).Source_First
;
1218 function Source_Last
(S
: SFI
) return Source_Ptr
is
1220 if S
= Internal_Source_File
then
1221 return Internal_Source
'Last;
1223 return Source_File
.Table
(S
).Source_Last
;
1227 function Source_Text
(S
: SFI
) return Source_Buffer_Ptr
is
1229 if S
= Internal_Source_File
then
1230 return Internal_Source_Ptr
;
1232 return Source_File
.Table
(S
).Source_Text
;
1236 function Template
(S
: SFI
) return SFI
is
1238 return Source_File
.Table
(S
).Template
;
1241 function Time_Stamp
(S
: SFI
) return Time_Stamp_Type
is
1243 return Source_File
.Table
(S
).Time_Stamp
;
1246 function Unit
(S
: SFI
) return Unit_Number_Type
is
1248 return Source_File
.Table
(S
).Unit
;
1251 ------------------------------------------
1252 -- Set Procedures for Source File Table --
1253 ------------------------------------------
1255 procedure Set_Identifier_Casing
(S
: SFI
; C
: Casing_Type
) is
1257 Source_File
.Table
(S
).Identifier_Casing
:= C
;
1258 end Set_Identifier_Casing
;
1260 procedure Set_Keyword_Casing
(S
: SFI
; C
: Casing_Type
) is
1262 Source_File
.Table
(S
).Keyword_Casing
:= C
;
1263 end Set_Keyword_Casing
;
1265 procedure Set_License
(S
: SFI
; L
: License_Type
) is
1267 Source_File
.Table
(S
).License
:= L
;
1270 procedure Set_Unit
(S
: SFI
; U
: Unit_Number_Type
) is
1272 Source_File
.Table
(S
).Unit
:= U
;
1275 ----------------------
1276 -- Trim_Lines_Table --
1277 ----------------------
1279 procedure Trim_Lines_Table
(S
: Source_File_Index
) is
1280 Max
: constant Nat
:= Nat
(Source_File
.Table
(S
).Last_Source_Line
);
1283 -- Release allocated storage that is no longer needed
1285 Source_File
.Table
(S
).Lines_Table
:= To_Pointer
1287 (To_Address
(Source_File
.Table
(S
).Lines_Table
),
1289 (Max
* (Lines_Table_Type
'Component_Size / System
.Storage_Unit
))));
1290 Source_File
.Table
(S
).Lines_Table_Max
:= Physical_Line_Number
(Max
);
1291 end Trim_Lines_Table
;
1299 Source_File
.Locked
:= False;
1300 Source_File
.Release
;
1307 procedure wl
(P
: Source_Ptr
) is