| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S I N P U T -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 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. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
pragma Style_Checks (All_Checks); |
| 27 |
-- Subprograms not all in alpha order |
| 28 |
|
| 29 |
with Atree; use Atree; |
| 30 |
with Debug; use Debug; |
| 31 |
with Opt; use Opt; |
| 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; |
| 37 |
|
| 38 |
with GNAT.Byte_Order_Mark; use GNAT.Byte_Order_Mark; |
| 39 |
|
| 40 |
with System.Storage_Elements; |
| 41 |
with System.Memory; |
| 42 |
with System.WCh_Con; use System.WCh_Con; |
| 43 |
|
| 44 |
with Ada.Unchecked_Conversion; |
| 45 |
with Ada.Unchecked_Deallocation; |
| 46 |
|
| 47 |
package body Sinput is |
| 48 |
|
| 49 |
use ASCII, System; |
| 50 |
|
| 51 |
-- Routines to support conversion between types Lines_Table_Ptr, |
| 52 |
-- Logical_Lines_Table_Ptr and System.Address. |
| 53 |
|
| 54 |
pragma Warnings (Off); |
| 55 |
-- These unchecked conversions are aliasing safe, since they are never |
| 56 |
-- used to construct improperly aliased pointer values. |
| 57 |
|
| 58 |
function To_Address is |
| 59 |
new Ada.Unchecked_Conversion (Lines_Table_Ptr, Address); |
| 60 |
|
| 61 |
function To_Address is |
| 62 |
new Ada.Unchecked_Conversion (Logical_Lines_Table_Ptr, Address); |
| 63 |
|
| 64 |
function To_Pointer is |
| 65 |
new Ada.Unchecked_Conversion (Address, Lines_Table_Ptr); |
| 66 |
|
| 67 |
function To_Pointer is |
| 68 |
new Ada.Unchecked_Conversion (Address, Logical_Lines_Table_Ptr); |
| 69 |
|
| 70 |
pragma Warnings (On); |
| 71 |
|
| 72 |
----------------------------- |
| 73 |
-- Source_File_Index_Table -- |
| 74 |
----------------------------- |
| 75 |
|
| 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 |
| 82 |
-- following table. |
| 83 |
|
| 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. |
| 86 |
|
| 87 |
Source_File_Index_Table : |
| 88 |
array (Int range 0 .. 1 + (Int'Last / Source_Align)) of Source_File_Index; |
| 89 |
|
| 90 |
--------------------------- |
| 91 |
-- Add_Line_Tables_Entry -- |
| 92 |
--------------------------- |
| 93 |
|
| 94 |
procedure Add_Line_Tables_Entry |
| 95 |
(S : in out Source_File_Record; |
| 96 |
P : Source_Ptr) |
| 97 |
is |
| 98 |
LL : Physical_Line_Number; |
| 99 |
|
| 100 |
begin |
| 101 |
-- Reallocate the lines tables if necessary |
| 102 |
|
| 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 ??? |
| 107 |
|
| 108 |
if S.Last_Source_Line = S.Lines_Table_Max then |
| 109 |
Alloc_Line_Tables |
| 110 |
(S, |
| 111 |
Int (S.Last_Source_Line) * |
| 112 |
((100 + Alloc.Lines_Increment) / 100)); |
| 113 |
|
| 114 |
if Debug_Flag_D then |
| 115 |
Write_Str ("--> Reallocating lines table, size = "); |
| 116 |
Write_Int (Int (S.Lines_Table_Max)); |
| 117 |
Write_Eol; |
| 118 |
end if; |
| 119 |
end if; |
| 120 |
|
| 121 |
S.Last_Source_Line := S.Last_Source_Line + 1; |
| 122 |
LL := S.Last_Source_Line; |
| 123 |
|
| 124 |
S.Lines_Table (LL) := P; |
| 125 |
|
| 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), |
| 129 |
|
| 130 |
if S.Logical_Lines_Table /= null then |
| 131 |
|
| 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. |
| 135 |
|
| 136 |
S.Logical_Lines_Table (LL) := S.Logical_Lines_Table (LL - 1) + 1; |
| 137 |
end if; |
| 138 |
end Add_Line_Tables_Entry; |
| 139 |
|
| 140 |
----------------------- |
| 141 |
-- Alloc_Line_Tables -- |
| 142 |
----------------------- |
| 143 |
|
| 144 |
procedure Alloc_Line_Tables |
| 145 |
(S : in out Source_File_Record; |
| 146 |
New_Max : Nat) |
| 147 |
is |
| 148 |
subtype size_t is Memory.size_t; |
| 149 |
|
| 150 |
New_Table : Lines_Table_Ptr; |
| 151 |
|
| 152 |
New_Logical_Table : Logical_Lines_Table_Ptr; |
| 153 |
|
| 154 |
New_Size : constant size_t := |
| 155 |
size_t (New_Max * Lines_Table_Type'Component_Size / |
| 156 |
Storage_Unit); |
| 157 |
|
| 158 |
begin |
| 159 |
if S.Lines_Table = null then |
| 160 |
New_Table := To_Pointer (Memory.Alloc (New_Size)); |
| 161 |
|
| 162 |
else |
| 163 |
New_Table := |
| 164 |
To_Pointer (Memory.Realloc (To_Address (S.Lines_Table), New_Size)); |
| 165 |
end if; |
| 166 |
|
| 167 |
if New_Table = null then |
| 168 |
raise Storage_Error; |
| 169 |
else |
| 170 |
S.Lines_Table := New_Table; |
| 171 |
S.Lines_Table_Max := Physical_Line_Number (New_Max); |
| 172 |
end if; |
| 173 |
|
| 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)); |
| 177 |
else |
| 178 |
New_Logical_Table := To_Pointer |
| 179 |
(Memory.Realloc (To_Address (S.Logical_Lines_Table), New_Size)); |
| 180 |
end if; |
| 181 |
|
| 182 |
if New_Logical_Table = null then |
| 183 |
raise Storage_Error; |
| 184 |
else |
| 185 |
S.Logical_Lines_Table := New_Logical_Table; |
| 186 |
end if; |
| 187 |
end if; |
| 188 |
end Alloc_Line_Tables; |
| 189 |
|
| 190 |
----------------- |
| 191 |
-- Backup_Line -- |
| 192 |
----------------- |
| 193 |
|
| 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; |
| 200 |
|
| 201 |
begin |
| 202 |
P := P - 1; |
| 203 |
|
| 204 |
if P = Sfirst then |
| 205 |
return; |
| 206 |
end if; |
| 207 |
|
| 208 |
if Src (P) = CR then |
| 209 |
if Src (P - 1) = LF then |
| 210 |
P := P - 1; |
| 211 |
end if; |
| 212 |
|
| 213 |
else -- Src (P) = LF |
| 214 |
if Src (P - 1) = CR then |
| 215 |
P := P - 1; |
| 216 |
end if; |
| 217 |
end if; |
| 218 |
|
| 219 |
-- Now find first character of the previous line |
| 220 |
|
| 221 |
while P > Sfirst |
| 222 |
and then Src (P - 1) /= LF |
| 223 |
and then Src (P - 1) /= CR |
| 224 |
loop |
| 225 |
P := P - 1; |
| 226 |
end loop; |
| 227 |
end Backup_Line; |
| 228 |
|
| 229 |
--------------------------- |
| 230 |
-- Build_Location_String -- |
| 231 |
--------------------------- |
| 232 |
|
| 233 |
procedure Build_Location_String |
| 234 |
(Buf : in out Bounded_String; |
| 235 |
Loc : Source_Ptr) |
| 236 |
is |
| 237 |
Ptr : Source_Ptr := Loc; |
| 238 |
|
| 239 |
begin |
| 240 |
-- Loop through instantiations |
| 241 |
|
| 242 |
loop |
| 243 |
Append (Buf, Reference_Name (Get_Source_File_Index (Ptr))); |
| 244 |
Append (Buf, ':'); |
| 245 |
Append (Buf, Nat (Get_Logical_Line_Number (Ptr))); |
| 246 |
|
| 247 |
-- For inherited pragmas, the location will be appended to a messsage |
| 248 |
-- that already says "inherited"; also, we are not interested where |
| 249 |
-- the pragma has been inherited. Progress directly to instantiation |
| 250 |
-- locations. |
| 251 |
|
| 252 |
if Comes_From_Inherited_Pragma (Ptr) then |
| 253 |
Ptr := Instantiation_Location (Ptr); |
| 254 |
end if; |
| 255 |
|
| 256 |
Ptr := Instantiation_Location (Ptr); |
| 257 |
exit when Ptr = No_Location; |
| 258 |
|
| 259 |
-- Make sure that we don't mention "instantiated" when in fact the |
| 260 |
-- location comes from other mechanisms. |
| 261 |
|
| 262 |
pragma Assert (not Comes_From_Inherited_Pragma (Ptr)); |
| 263 |
|
| 264 |
if Comes_From_Inlined_Body (Ptr) then |
| 265 |
Append (Buf, " inlined at "); |
| 266 |
else |
| 267 |
Append (Buf, " instantiated at "); |
| 268 |
end if; |
| 269 |
end loop; |
| 270 |
end Build_Location_String; |
| 271 |
|
| 272 |
function Build_Location_String (Loc : Source_Ptr) return String is |
| 273 |
Buf : Bounded_String; |
| 274 |
begin |
| 275 |
Build_Location_String (Buf, Loc); |
| 276 |
return +Buf; |
| 277 |
end Build_Location_String; |
| 278 |
|
| 279 |
--------------------- |
| 280 |
-- C_Source_Buffer -- |
| 281 |
--------------------- |
| 282 |
|
| 283 |
function C_Source_Buffer (S : SFI) return C_Array is |
| 284 |
Length : constant Integer := |
| 285 |
Integer (Source_Last (S) - Source_First (S)); |
| 286 |
|
| 287 |
Text : constant Source_Buffer_Ptr := Source_Text (S); |
| 288 |
|
| 289 |
Pointer : constant access constant Character := |
| 290 |
(if Length = 0 then null else |
| 291 |
Text (Text'First)'Access); |
| 292 |
begin |
| 293 |
return (Pointer, Length); |
| 294 |
end C_Source_Buffer; |
| 295 |
|
| 296 |
------------------- |
| 297 |
-- Check_For_BOM -- |
| 298 |
------------------- |
| 299 |
|
| 300 |
procedure Check_For_BOM is |
| 301 |
BOM : BOM_Kind; |
| 302 |
Len : Natural; |
| 303 |
Tst : String (1 .. 5); |
| 304 |
C : Character; |
| 305 |
|
| 306 |
begin |
| 307 |
for J in 1 .. 5 loop |
| 308 |
C := Source (Scan_Ptr + Source_Ptr (J) - 1); |
| 309 |
|
| 310 |
-- Definitely no BOM if EOF character marks either end of file, or |
| 311 |
-- an illegal non-BOM character if not at the end of file. |
| 312 |
|
| 313 |
if C = EOF then |
| 314 |
return; |
| 315 |
end if; |
| 316 |
|
| 317 |
Tst (J) := C; |
| 318 |
end loop; |
| 319 |
|
| 320 |
Read_BOM (Tst, Len, BOM, XML_Support => False); |
| 321 |
|
| 322 |
case BOM is |
| 323 |
when UTF8_All => |
| 324 |
Scan_Ptr := Scan_Ptr + Source_Ptr (Len); |
| 325 |
First_Non_Blank_Location := Scan_Ptr; |
| 326 |
Current_Line_Start := Scan_Ptr; |
| 327 |
Wide_Character_Encoding_Method := WCEM_UTF8; |
| 328 |
Upper_Half_Encoding := True; |
| 329 |
|
| 330 |
when UTF16_BE |
| 331 |
| UTF16_LE |
| 332 |
=> |
| 333 |
Set_Standard_Error; |
| 334 |
Write_Line ("UTF-16 encoding format not recognized"); |
| 335 |
Set_Standard_Output; |
| 336 |
raise Unrecoverable_Error; |
| 337 |
|
| 338 |
when UTF32_BE |
| 339 |
| UTF32_LE |
| 340 |
=> |
| 341 |
Set_Standard_Error; |
| 342 |
Write_Line ("UTF-32 encoding format not recognized"); |
| 343 |
Set_Standard_Output; |
| 344 |
raise Unrecoverable_Error; |
| 345 |
|
| 346 |
when Unknown => |
| 347 |
null; |
| 348 |
|
| 349 |
when others => |
| 350 |
raise Program_Error; |
| 351 |
end case; |
| 352 |
end Check_For_BOM; |
| 353 |
|
| 354 |
----------------------------- |
| 355 |
-- Clear_Source_File_Table -- |
| 356 |
----------------------------- |
| 357 |
|
| 358 |
procedure Free is new Ada.Unchecked_Deallocation |
| 359 |
(Lines_Table_Type, Lines_Table_Ptr); |
| 360 |
|
| 361 |
procedure Free is new Ada.Unchecked_Deallocation |
| 362 |
(Logical_Lines_Table_Type, Logical_Lines_Table_Ptr); |
| 363 |
|
| 364 |
procedure Clear_Source_File_Table is |
| 365 |
begin |
| 366 |
for X in 1 .. Source_File.Last loop |
| 367 |
declare |
| 368 |
S : Source_File_Record renames Source_File.Table (X); |
| 369 |
begin |
| 370 |
if S.Instance = No_Instance_Id then |
| 371 |
Free_Source_Buffer (S.Source_Text); |
| 372 |
else |
| 373 |
Free_Dope (S.Source_Text'Address); |
| 374 |
S.Source_Text := null; |
| 375 |
end if; |
| 376 |
|
| 377 |
Free (S.Lines_Table); |
| 378 |
Free (S.Logical_Lines_Table); |
| 379 |
end; |
| 380 |
end loop; |
| 381 |
|
| 382 |
Source_File.Free; |
| 383 |
Sinput.Initialize; |
| 384 |
end Clear_Source_File_Table; |
| 385 |
|
| 386 |
--------------------------------- |
| 387 |
-- Comes_From_Inherited_Pragma -- |
| 388 |
--------------------------------- |
| 389 |
|
| 390 |
function Comes_From_Inherited_Pragma (S : Source_Ptr) return Boolean is |
| 391 |
SIE : Source_File_Record renames |
| 392 |
Source_File.Table (Get_Source_File_Index (S)); |
| 393 |
begin |
| 394 |
return SIE.Inherited_Pragma; |
| 395 |
end Comes_From_Inherited_Pragma; |
| 396 |
|
| 397 |
----------------------------- |
| 398 |
-- Comes_From_Inlined_Body -- |
| 399 |
----------------------------- |
| 400 |
|
| 401 |
function Comes_From_Inlined_Body (S : Source_Ptr) return Boolean is |
| 402 |
SIE : Source_File_Record renames |
| 403 |
Source_File.Table (Get_Source_File_Index (S)); |
| 404 |
begin |
| 405 |
return SIE.Inlined_Body; |
| 406 |
end Comes_From_Inlined_Body; |
| 407 |
|
| 408 |
------------------------ |
| 409 |
-- Free_Source_Buffer -- |
| 410 |
------------------------ |
| 411 |
|
| 412 |
procedure Free_Source_Buffer (Src : in out Source_Buffer_Ptr) is |
| 413 |
-- Unchecked_Deallocation doesn't work for access-to-constant; we need |
| 414 |
-- to first Unchecked_Convert to access-to-variable. |
| 415 |
|
| 416 |
function To_Source_Buffer_Ptr_Var is new |
| 417 |
Ada.Unchecked_Conversion (Source_Buffer_Ptr, Source_Buffer_Ptr_Var); |
| 418 |
|
| 419 |
Temp : Source_Buffer_Ptr_Var := To_Source_Buffer_Ptr_Var (Src); |
| 420 |
|
| 421 |
procedure Free_Ptr is new |
| 422 |
Ada.Unchecked_Deallocation (Source_Buffer, Source_Buffer_Ptr_Var); |
| 423 |
begin |
| 424 |
Free_Ptr (Temp); |
| 425 |
Src := null; |
| 426 |
end Free_Source_Buffer; |
| 427 |
|
| 428 |
----------------------- |
| 429 |
-- Get_Column_Number -- |
| 430 |
----------------------- |
| 431 |
|
| 432 |
function Get_Column_Number (P : Source_Ptr) return Column_Number is |
| 433 |
S : Source_Ptr; |
| 434 |
C : Column_Number; |
| 435 |
Sindex : Source_File_Index; |
| 436 |
Src : Source_Buffer_Ptr; |
| 437 |
|
| 438 |
begin |
| 439 |
-- If the input source pointer is not a meaningful value then return |
| 440 |
-- at once with column number 1. This can happen for a file not found |
| 441 |
-- condition for a file loaded indirectly by RTE, and also perhaps on |
| 442 |
-- some unknown internal error conditions. In either case we certainly |
| 443 |
-- don't want to blow up. |
| 444 |
|
| 445 |
if P < 1 then |
| 446 |
return 1; |
| 447 |
|
| 448 |
else |
| 449 |
Sindex := Get_Source_File_Index (P); |
| 450 |
Src := Source_File.Table (Sindex).Source_Text; |
| 451 |
S := Line_Start (P); |
| 452 |
C := 1; |
| 453 |
|
| 454 |
while S < P loop |
| 455 |
if Src (S) = HT then |
| 456 |
C := (C - 1) / 8 * 8 + (8 + 1); |
| 457 |
S := S + 1; |
| 458 |
|
| 459 |
-- Deal with wide character case, but don't include brackets |
| 460 |
-- notation in this circuit, since we know that this will |
| 461 |
-- display unencoded (no one encodes brackets notation). |
| 462 |
|
| 463 |
elsif Src (S) /= '[' and then Is_Start_Of_Wide_Char (Src, S) then |
| 464 |
C := C + 1; |
| 465 |
Skip_Wide (Src, S); |
| 466 |
|
| 467 |
-- Normal (non-wide) character case or brackets sequence |
| 468 |
|
| 469 |
else |
| 470 |
C := C + 1; |
| 471 |
S := S + 1; |
| 472 |
end if; |
| 473 |
end loop; |
| 474 |
|
| 475 |
return C; |
| 476 |
end if; |
| 477 |
end Get_Column_Number; |
| 478 |
|
| 479 |
----------------------------- |
| 480 |
-- Get_Logical_Line_Number -- |
| 481 |
----------------------------- |
| 482 |
|
| 483 |
function Get_Logical_Line_Number |
| 484 |
(P : Source_Ptr) return Logical_Line_Number |
| 485 |
is |
| 486 |
SFR : Source_File_Record |
| 487 |
renames Source_File.Table (Get_Source_File_Index (P)); |
| 488 |
|
| 489 |
L : constant Physical_Line_Number := Get_Physical_Line_Number (P); |
| 490 |
|
| 491 |
begin |
| 492 |
if SFR.Num_SRef_Pragmas = 0 then |
| 493 |
return Logical_Line_Number (L); |
| 494 |
else |
| 495 |
return SFR.Logical_Lines_Table (L); |
| 496 |
end if; |
| 497 |
end Get_Logical_Line_Number; |
| 498 |
|
| 499 |
------------------------------ |
| 500 |
-- Get_Physical_Line_Number -- |
| 501 |
------------------------------ |
| 502 |
|
| 503 |
function Get_Physical_Line_Number |
| 504 |
(P : Source_Ptr) return Physical_Line_Number |
| 505 |
is |
| 506 |
Sfile : Source_File_Index; |
| 507 |
Table : Lines_Table_Ptr; |
| 508 |
Lo : Physical_Line_Number; |
| 509 |
Hi : Physical_Line_Number; |
| 510 |
Mid : Physical_Line_Number; |
| 511 |
Loc : Source_Ptr; |
| 512 |
|
| 513 |
begin |
| 514 |
-- If the input source pointer is not a meaningful value then return |
| 515 |
-- at once with line number 1. This can happen for a file not found |
| 516 |
-- condition for a file loaded indirectly by RTE, and also perhaps on |
| 517 |
-- some unknown internal error conditions. In either case we certainly |
| 518 |
-- don't want to blow up. |
| 519 |
|
| 520 |
if P < 1 then |
| 521 |
return 1; |
| 522 |
|
| 523 |
-- Otherwise we can do the binary search |
| 524 |
|
| 525 |
else |
| 526 |
Sfile := Get_Source_File_Index (P); |
| 527 |
Loc := P + Source_File.Table (Sfile).Sloc_Adjust; |
| 528 |
Table := Source_File.Table (Sfile).Lines_Table; |
| 529 |
Lo := 1; |
| 530 |
Hi := Source_File.Table (Sfile).Last_Source_Line; |
| 531 |
|
| 532 |
loop |
| 533 |
Mid := (Lo + Hi) / 2; |
| 534 |
|
| 535 |
if Loc < Table (Mid) then |
| 536 |
Hi := Mid - 1; |
| 537 |
|
| 538 |
else -- Loc >= Table (Mid) |
| 539 |
|
| 540 |
if Mid = Hi or else |
| 541 |
Loc < Table (Mid + 1) |
| 542 |
then |
| 543 |
return Mid; |
| 544 |
else |
| 545 |
Lo := Mid + 1; |
| 546 |
end if; |
| 547 |
|
| 548 |
end if; |
| 549 |
|
| 550 |
end loop; |
| 551 |
end if; |
| 552 |
end Get_Physical_Line_Number; |
| 553 |
|
| 554 |
--------------------------- |
| 555 |
-- Get_Source_File_Index -- |
| 556 |
--------------------------- |
| 557 |
|
| 558 |
function Get_Source_File_Index (S : Source_Ptr) return Source_File_Index is |
| 559 |
Result : Source_File_Index; |
| 560 |
|
| 561 |
procedure Assertions; |
| 562 |
-- Assert various properties of the result |
| 563 |
|
| 564 |
procedure Assertions is |
| 565 |
|
| 566 |
-- ???The old version using zero-origin array indexing without array |
| 567 |
-- bounds checks returned 1 (i.e. system.ads) for these special |
| 568 |
-- locations, presumably by accident. We are mimicing that here. |
| 569 |
|
| 570 |
Special : constant Boolean := |
| 571 |
S = No_Location |
| 572 |
or else S = Standard_Location |
| 573 |
or else S = Standard_ASCII_Location |
| 574 |
or else S = System_Location; |
| 575 |
|
| 576 |
pragma Assert (S > No_Location xor Special); |
| 577 |
pragma Assert (Result in Source_File.First .. Source_File.Last); |
| 578 |
|
| 579 |
SFR : Source_File_Record renames Source_File.Table (Result); |
| 580 |
|
| 581 |
begin |
| 582 |
-- SFR.Source_Text = null if and only if this is the SFR for a debug |
| 583 |
-- output file (*.dg), and that file is under construction. S can be |
| 584 |
-- slightly past Source_Last in that case because we haven't updated |
| 585 |
-- Source_Last. |
| 586 |
|
| 587 |
if Null_Source_Buffer_Ptr (SFR.Source_Text) then |
| 588 |
pragma Assert (S >= SFR.Source_First); null; |
| 589 |
else |
| 590 |
pragma Assert (SFR.Source_Text'First = SFR.Source_First); |
| 591 |
pragma Assert (SFR.Source_Text'Last = SFR.Source_Last); |
| 592 |
|
| 593 |
if not Special then |
| 594 |
pragma Assert (S in SFR.Source_First .. SFR.Source_Last); |
| 595 |
null; |
| 596 |
end if; |
| 597 |
end if; |
| 598 |
end Assertions; |
| 599 |
|
| 600 |
-- Start of processing for Get_Source_File_Index |
| 601 |
|
| 602 |
begin |
| 603 |
if S > No_Location then |
| 604 |
Result := Source_File_Index_Table (Int (S) / Source_Align); |
| 605 |
else |
| 606 |
Result := 1; |
| 607 |
end if; |
| 608 |
|
| 609 |
pragma Debug (Assertions); |
| 610 |
|
| 611 |
return Result; |
| 612 |
end Get_Source_File_Index; |
| 613 |
|
| 614 |
---------------- |
| 615 |
-- Initialize -- |
| 616 |
---------------- |
| 617 |
|
| 618 |
procedure Initialize is |
| 619 |
begin |
| 620 |
Source_gnat_adc := No_Source_File; |
| 621 |
Source_File.Init; |
| 622 |
Instances.Init; |
| 623 |
Instances.Append (No_Location); |
| 624 |
pragma Assert (Instances.Last = No_Instance_Id); |
| 625 |
end Initialize; |
| 626 |
|
| 627 |
------------------- |
| 628 |
-- Instantiation -- |
| 629 |
------------------- |
| 630 |
|
| 631 |
function Instantiation (S : SFI) return Source_Ptr is |
| 632 |
SIE : Source_File_Record renames Source_File.Table (S); |
| 633 |
begin |
| 634 |
if SIE.Inlined_Body or SIE.Inherited_Pragma then |
| 635 |
return SIE.Inlined_Call; |
| 636 |
else |
| 637 |
return Instances.Table (SIE.Instance); |
| 638 |
end if; |
| 639 |
end Instantiation; |
| 640 |
|
| 641 |
------------------------- |
| 642 |
-- Instantiation_Depth -- |
| 643 |
------------------------- |
| 644 |
|
| 645 |
function Instantiation_Depth (S : Source_Ptr) return Nat is |
| 646 |
Sval : Source_Ptr; |
| 647 |
Depth : Nat; |
| 648 |
|
| 649 |
begin |
| 650 |
Sval := S; |
| 651 |
Depth := 0; |
| 652 |
|
| 653 |
loop |
| 654 |
Sval := Instantiation_Location (Sval); |
| 655 |
exit when Sval = No_Location; |
| 656 |
Depth := Depth + 1; |
| 657 |
end loop; |
| 658 |
|
| 659 |
return Depth; |
| 660 |
end Instantiation_Depth; |
| 661 |
|
| 662 |
---------------------------- |
| 663 |
-- Instantiation_Location -- |
| 664 |
---------------------------- |
| 665 |
|
| 666 |
function Instantiation_Location (S : Source_Ptr) return Source_Ptr is |
| 667 |
begin |
| 668 |
return Instantiation (Get_Source_File_Index (S)); |
| 669 |
end Instantiation_Location; |
| 670 |
|
| 671 |
-------------------------- |
| 672 |
-- Iterate_On_Instances -- |
| 673 |
-------------------------- |
| 674 |
|
| 675 |
procedure Iterate_On_Instances is |
| 676 |
begin |
| 677 |
for J in 1 .. Instances.Last loop |
| 678 |
Process (J, Instances.Table (J)); |
| 679 |
end loop; |
| 680 |
end Iterate_On_Instances; |
| 681 |
|
| 682 |
---------------------- |
| 683 |
-- Last_Source_File -- |
| 684 |
---------------------- |
| 685 |
|
| 686 |
function Last_Source_File return Source_File_Index is |
| 687 |
begin |
| 688 |
return Source_File.Last; |
| 689 |
end Last_Source_File; |
| 690 |
|
| 691 |
---------------- |
| 692 |
-- Line_Start -- |
| 693 |
---------------- |
| 694 |
|
| 695 |
function Line_Start (P : Source_Ptr) return Source_Ptr is |
| 696 |
Sindex : constant Source_File_Index := Get_Source_File_Index (P); |
| 697 |
Src : constant Source_Buffer_Ptr := |
| 698 |
Source_File.Table (Sindex).Source_Text; |
| 699 |
Sfirst : constant Source_Ptr := |
| 700 |
Source_File.Table (Sindex).Source_First; |
| 701 |
S : Source_Ptr; |
| 702 |
|
| 703 |
begin |
| 704 |
S := P; |
| 705 |
while S > Sfirst |
| 706 |
and then Src (S - 1) /= CR |
| 707 |
and then Src (S - 1) /= LF |
| 708 |
loop |
| 709 |
S := S - 1; |
| 710 |
end loop; |
| 711 |
|
| 712 |
return S; |
| 713 |
end Line_Start; |
| 714 |
|
| 715 |
function Line_Start |
| 716 |
(L : Physical_Line_Number; |
| 717 |
S : Source_File_Index) return Source_Ptr |
| 718 |
is |
| 719 |
begin |
| 720 |
return Source_File.Table (S).Lines_Table (L); |
| 721 |
end Line_Start; |
| 722 |
|
| 723 |
---------- |
| 724 |
-- Lock -- |
| 725 |
---------- |
| 726 |
|
| 727 |
procedure Lock is |
| 728 |
begin |
| 729 |
Source_File.Release; |
| 730 |
Source_File.Locked := True; |
| 731 |
end Lock; |
| 732 |
|
| 733 |
---------------------- |
| 734 |
-- Num_Source_Files -- |
| 735 |
---------------------- |
| 736 |
|
| 737 |
function Num_Source_Files return Nat is |
| 738 |
begin |
| 739 |
return Int (Source_File.Last) - Int (Source_File.First) + 1; |
| 740 |
end Num_Source_Files; |
| 741 |
|
| 742 |
---------------------- |
| 743 |
-- Num_Source_Lines -- |
| 744 |
---------------------- |
| 745 |
|
| 746 |
function Num_Source_Lines (S : Source_File_Index) return Nat is |
| 747 |
begin |
| 748 |
return Nat (Source_File.Table (S).Last_Source_Line); |
| 749 |
end Num_Source_Lines; |
| 750 |
|
| 751 |
----------------------- |
| 752 |
-- Original_Location -- |
| 753 |
----------------------- |
| 754 |
|
| 755 |
function Original_Location (S : Source_Ptr) return Source_Ptr is |
| 756 |
Sindex : Source_File_Index; |
| 757 |
Tindex : Source_File_Index; |
| 758 |
|
| 759 |
begin |
| 760 |
if S <= No_Location then |
| 761 |
return S; |
| 762 |
|
| 763 |
else |
| 764 |
Sindex := Get_Source_File_Index (S); |
| 765 |
|
| 766 |
if Instantiation (Sindex) = No_Location then |
| 767 |
return S; |
| 768 |
|
| 769 |
else |
| 770 |
Tindex := Template (Sindex); |
| 771 |
while Instantiation (Tindex) /= No_Location loop |
| 772 |
Tindex := Template (Tindex); |
| 773 |
end loop; |
| 774 |
|
| 775 |
return S - Source_First (Sindex) + Source_First (Tindex); |
| 776 |
end if; |
| 777 |
end if; |
| 778 |
end Original_Location; |
| 779 |
|
| 780 |
------------------------- |
| 781 |
-- Physical_To_Logical -- |
| 782 |
------------------------- |
| 783 |
|
| 784 |
function Physical_To_Logical |
| 785 |
(Line : Physical_Line_Number; |
| 786 |
S : Source_File_Index) return Logical_Line_Number |
| 787 |
is |
| 788 |
SFR : Source_File_Record renames Source_File.Table (S); |
| 789 |
|
| 790 |
begin |
| 791 |
if SFR.Num_SRef_Pragmas = 0 then |
| 792 |
return Logical_Line_Number (Line); |
| 793 |
else |
| 794 |
return SFR.Logical_Lines_Table (Line); |
| 795 |
end if; |
| 796 |
end Physical_To_Logical; |
| 797 |
|
| 798 |
-------------------------------- |
| 799 |
-- Register_Source_Ref_Pragma -- |
| 800 |
-------------------------------- |
| 801 |
|
| 802 |
procedure Register_Source_Ref_Pragma |
| 803 |
(File_Name : File_Name_Type; |
| 804 |
Stripped_File_Name : File_Name_Type; |
| 805 |
Mapped_Line : Nat; |
| 806 |
Line_After_Pragma : Physical_Line_Number) |
| 807 |
is |
| 808 |
subtype size_t is Memory.size_t; |
| 809 |
|
| 810 |
SFR : Source_File_Record renames Source_File.Table (Current_Source_File); |
| 811 |
|
| 812 |
ML : Logical_Line_Number; |
| 813 |
|
| 814 |
begin |
| 815 |
if File_Name /= No_File then |
| 816 |
SFR.Reference_Name := Stripped_File_Name; |
| 817 |
SFR.Full_Ref_Name := File_Name; |
| 818 |
|
| 819 |
if not Debug_Generated_Code then |
| 820 |
SFR.Debug_Source_Name := Stripped_File_Name; |
| 821 |
SFR.Full_Debug_Name := File_Name; |
| 822 |
end if; |
| 823 |
|
| 824 |
SFR.Num_SRef_Pragmas := SFR.Num_SRef_Pragmas + 1; |
| 825 |
end if; |
| 826 |
|
| 827 |
if SFR.Num_SRef_Pragmas = 1 then |
| 828 |
SFR.First_Mapped_Line := Logical_Line_Number (Mapped_Line); |
| 829 |
end if; |
| 830 |
|
| 831 |
if SFR.Logical_Lines_Table = null then |
| 832 |
SFR.Logical_Lines_Table := To_Pointer |
| 833 |
(Memory.Alloc |
| 834 |
(size_t (SFR.Lines_Table_Max * |
| 835 |
Logical_Lines_Table_Type'Component_Size / |
| 836 |
Storage_Unit))); |
| 837 |
end if; |
| 838 |
|
| 839 |
SFR.Logical_Lines_Table (Line_After_Pragma - 1) := No_Line_Number; |
| 840 |
|
| 841 |
ML := Logical_Line_Number (Mapped_Line); |
| 842 |
for J in Line_After_Pragma .. SFR.Last_Source_Line loop |
| 843 |
SFR.Logical_Lines_Table (J) := ML; |
| 844 |
ML := ML + 1; |
| 845 |
end loop; |
| 846 |
end Register_Source_Ref_Pragma; |
| 847 |
|
| 848 |
--------------------------------- |
| 849 |
-- Set_Source_File_Index_Table -- |
| 850 |
--------------------------------- |
| 851 |
|
| 852 |
procedure Set_Source_File_Index_Table (Xnew : Source_File_Index) is |
| 853 |
Ind : Int; |
| 854 |
SP : Source_Ptr; |
| 855 |
SL : constant Source_Ptr := Source_File.Table (Xnew).Source_Last; |
| 856 |
begin |
| 857 |
SP := Source_File.Table (Xnew).Source_First; |
| 858 |
pragma Assert (SP mod Source_Align = 0); |
| 859 |
Ind := Int (SP) / Source_Align; |
| 860 |
while SP <= SL loop |
| 861 |
Source_File_Index_Table (Ind) := Xnew; |
| 862 |
SP := SP + Source_Align; |
| 863 |
Ind := Ind + 1; |
| 864 |
end loop; |
| 865 |
end Set_Source_File_Index_Table; |
| 866 |
|
| 867 |
--------------------------- |
| 868 |
-- Skip_Line_Terminators -- |
| 869 |
--------------------------- |
| 870 |
|
| 871 |
procedure Skip_Line_Terminators |
| 872 |
(P : in out Source_Ptr; |
| 873 |
Physical : out Boolean) |
| 874 |
is |
| 875 |
Chr : constant Character := Source (P); |
| 876 |
|
| 877 |
begin |
| 878 |
if Chr = CR then |
| 879 |
if Source (P + 1) = LF then |
| 880 |
P := P + 2; |
| 881 |
else |
| 882 |
P := P + 1; |
| 883 |
end if; |
| 884 |
|
| 885 |
elsif Chr = LF then |
| 886 |
P := P + 1; |
| 887 |
|
| 888 |
elsif Chr = FF or else Chr = VT then |
| 889 |
P := P + 1; |
| 890 |
Physical := False; |
| 891 |
return; |
| 892 |
|
| 893 |
-- Otherwise we have a wide character |
| 894 |
|
| 895 |
else |
| 896 |
Skip_Wide (Source, P); |
| 897 |
end if; |
| 898 |
|
| 899 |
-- Fall through in the physical line terminator case. First deal with |
| 900 |
-- making a possible entry into the lines table if one is needed. |
| 901 |
|
| 902 |
-- Note: we are dealing with a real source file here, this cannot be |
| 903 |
-- the instantiation case, so we need not worry about Sloc adjustment. |
| 904 |
|
| 905 |
declare |
| 906 |
S : Source_File_Record |
| 907 |
renames Source_File.Table (Current_Source_File); |
| 908 |
|
| 909 |
begin |
| 910 |
Physical := True; |
| 911 |
|
| 912 |
-- Make entry in lines table if not already made (in some scan backup |
| 913 |
-- cases, we will be rescanning previously scanned source, so the |
| 914 |
-- entry may have already been made on the previous forward scan). |
| 915 |
|
| 916 |
if Source (P) /= EOF |
| 917 |
and then P > S.Lines_Table (S.Last_Source_Line) |
| 918 |
then |
| 919 |
Add_Line_Tables_Entry (S, P); |
| 920 |
end if; |
| 921 |
end; |
| 922 |
end Skip_Line_Terminators; |
| 923 |
|
| 924 |
-------------- |
| 925 |
-- Set_Dope -- |
| 926 |
-------------- |
| 927 |
|
| 928 |
procedure Set_Dope |
| 929 |
(Src : System.Address; New_Dope : Dope_Ptr) |
| 930 |
is |
| 931 |
-- A fat pointer is a pair consisting of data pointer and dope pointer, |
| 932 |
-- in that order. So we want to overwrite the second word. |
| 933 |
Dope : System.Address; |
| 934 |
pragma Import (Ada, Dope); |
| 935 |
use System.Storage_Elements; |
| 936 |
for Dope'Address use Src + System.Address'Size / 8; |
| 937 |
begin |
| 938 |
Dope := New_Dope.all'Address; |
| 939 |
end Set_Dope; |
| 940 |
|
| 941 |
procedure Free_Dope (Src : System.Address) is |
| 942 |
Dope : Dope_Ptr; |
| 943 |
pragma Import (Ada, Dope); |
| 944 |
use System.Storage_Elements; |
| 945 |
for Dope'Address use Src + System.Address'Size / 8; |
| 946 |
procedure Free is new Ada.Unchecked_Deallocation (Dope_Rec, Dope_Ptr); |
| 947 |
begin |
| 948 |
Free (Dope); |
| 949 |
end Free_Dope; |
| 950 |
|
| 951 |
---------------- |
| 952 |
-- Sloc_Range -- |
| 953 |
---------------- |
| 954 |
|
| 955 |
procedure Sloc_Range (N : Node_Id; Min, Max : out Source_Ptr) is |
| 956 |
|
| 957 |
Indx : constant Source_File_Index := Get_Source_File_Index (Sloc (N)); |
| 958 |
|
| 959 |
function Process (N : Node_Id) return Traverse_Result; |
| 960 |
-- Process function for traversing the node tree |
| 961 |
|
| 962 |
procedure Traverse is new Traverse_Proc (Process); |
| 963 |
|
| 964 |
------------- |
| 965 |
-- Process -- |
| 966 |
------------- |
| 967 |
|
| 968 |
function Process (N : Node_Id) return Traverse_Result is |
| 969 |
Loc : constant Source_Ptr := Sloc (Original_Node (N)); |
| 970 |
|
| 971 |
begin |
| 972 |
-- Skip nodes that may have been added during expansion and |
| 973 |
-- that originate in other units, such as code for contracts |
| 974 |
-- in subprogram bodies. |
| 975 |
|
| 976 |
if Get_Source_File_Index (Loc) /= Indx then |
| 977 |
return Skip; |
| 978 |
end if; |
| 979 |
|
| 980 |
if Loc > No_Location then |
| 981 |
if Loc < Min then |
| 982 |
Min := Loc; |
| 983 |
elsif Loc > Max then |
| 984 |
Max := Loc; |
| 985 |
end if; |
| 986 |
end if; |
| 987 |
|
| 988 |
return OK_Orig; |
| 989 |
end Process; |
| 990 |
|
| 991 |
-- Start of processing for Sloc_Range |
| 992 |
|
| 993 |
begin |
| 994 |
Min := Sloc (N); |
| 995 |
Max := Min; |
| 996 |
Traverse (N); |
| 997 |
end Sloc_Range; |
| 998 |
|
| 999 |
------------------- |
| 1000 |
-- Source_Offset -- |
| 1001 |
------------------- |
| 1002 |
|
| 1003 |
function Source_Offset (S : Source_Ptr) return Nat is |
| 1004 |
Sindex : constant Source_File_Index := Get_Source_File_Index (S); |
| 1005 |
Sfirst : constant Source_Ptr := |
| 1006 |
Source_File.Table (Sindex).Source_First; |
| 1007 |
begin |
| 1008 |
return Nat (S - Sfirst); |
| 1009 |
end Source_Offset; |
| 1010 |
|
| 1011 |
------------------------ |
| 1012 |
-- Top_Level_Location -- |
| 1013 |
------------------------ |
| 1014 |
|
| 1015 |
function Top_Level_Location (S : Source_Ptr) return Source_Ptr is |
| 1016 |
Oldloc : Source_Ptr; |
| 1017 |
Newloc : Source_Ptr; |
| 1018 |
|
| 1019 |
begin |
| 1020 |
Newloc := S; |
| 1021 |
loop |
| 1022 |
Oldloc := Newloc; |
| 1023 |
Newloc := Instantiation_Location (Oldloc); |
| 1024 |
exit when Newloc = No_Location; |
| 1025 |
end loop; |
| 1026 |
|
| 1027 |
return Oldloc; |
| 1028 |
end Top_Level_Location; |
| 1029 |
|
| 1030 |
-------------------- |
| 1031 |
-- Write_Location -- |
| 1032 |
-------------------- |
| 1033 |
|
| 1034 |
procedure Write_Location (P : Source_Ptr) is |
| 1035 |
begin |
| 1036 |
if P = No_Location then |
| 1037 |
Write_Str ("<no location>"); |
| 1038 |
|
| 1039 |
elsif P <= Standard_Location then |
| 1040 |
Write_Str ("<standard location>"); |
| 1041 |
|
| 1042 |
else |
| 1043 |
declare |
| 1044 |
SI : constant Source_File_Index := Get_Source_File_Index (P); |
| 1045 |
|
| 1046 |
begin |
| 1047 |
Write_Name_For_Debug (Debug_Source_Name (SI)); |
| 1048 |
Write_Char (':'); |
| 1049 |
Write_Int (Int (Get_Logical_Line_Number (P))); |
| 1050 |
Write_Char (':'); |
| 1051 |
Write_Int (Int (Get_Column_Number (P))); |
| 1052 |
|
| 1053 |
if Instantiation (SI) /= No_Location then |
| 1054 |
Write_Str (" ["); |
| 1055 |
Write_Location (Instantiation (SI)); |
| 1056 |
Write_Char (']'); |
| 1057 |
end if; |
| 1058 |
end; |
| 1059 |
end if; |
| 1060 |
end Write_Location; |
| 1061 |
|
| 1062 |
---------------------- |
| 1063 |
-- Write_Time_Stamp -- |
| 1064 |
---------------------- |
| 1065 |
|
| 1066 |
procedure Write_Time_Stamp (S : Source_File_Index) is |
| 1067 |
T : constant Time_Stamp_Type := Time_Stamp (S); |
| 1068 |
P : Natural; |
| 1069 |
|
| 1070 |
begin |
| 1071 |
if T (1) = '9' then |
| 1072 |
Write_Str ("19"); |
| 1073 |
P := 0; |
| 1074 |
else |
| 1075 |
Write_Char (T (1)); |
| 1076 |
Write_Char (T (2)); |
| 1077 |
P := 2; |
| 1078 |
end if; |
| 1079 |
|
| 1080 |
Write_Char (T (P + 1)); |
| 1081 |
Write_Char (T (P + 2)); |
| 1082 |
Write_Char ('-'); |
| 1083 |
|
| 1084 |
Write_Char (T (P + 3)); |
| 1085 |
Write_Char (T (P + 4)); |
| 1086 |
Write_Char ('-'); |
| 1087 |
|
| 1088 |
Write_Char (T (P + 5)); |
| 1089 |
Write_Char (T (P + 6)); |
| 1090 |
Write_Char (' '); |
| 1091 |
|
| 1092 |
Write_Char (T (P + 7)); |
| 1093 |
Write_Char (T (P + 8)); |
| 1094 |
Write_Char (':'); |
| 1095 |
|
| 1096 |
Write_Char (T (P + 9)); |
| 1097 |
Write_Char (T (P + 10)); |
| 1098 |
Write_Char (':'); |
| 1099 |
|
| 1100 |
Write_Char (T (P + 11)); |
| 1101 |
Write_Char (T (P + 12)); |
| 1102 |
end Write_Time_Stamp; |
| 1103 |
|
| 1104 |
---------------------------------------------- |
| 1105 |
-- Access Subprograms for Source File Table -- |
| 1106 |
---------------------------------------------- |
| 1107 |
|
| 1108 |
function Debug_Source_Name (S : SFI) return File_Name_Type is |
| 1109 |
begin |
| 1110 |
return Source_File.Table (S).Debug_Source_Name; |
| 1111 |
end Debug_Source_Name; |
| 1112 |
|
| 1113 |
function Instance (S : SFI) return Instance_Id is |
| 1114 |
begin |
| 1115 |
return Source_File.Table (S).Instance; |
| 1116 |
end Instance; |
| 1117 |
|
| 1118 |
function File_Name (S : SFI) return File_Name_Type is |
| 1119 |
begin |
| 1120 |
return Source_File.Table (S).File_Name; |
| 1121 |
end File_Name; |
| 1122 |
|
| 1123 |
function File_Type (S : SFI) return Type_Of_File is |
| 1124 |
begin |
| 1125 |
return Source_File.Table (S).File_Type; |
| 1126 |
end File_Type; |
| 1127 |
|
| 1128 |
function First_Mapped_Line (S : SFI) return Logical_Line_Number is |
| 1129 |
begin |
| 1130 |
return Source_File.Table (S).First_Mapped_Line; |
| 1131 |
end First_Mapped_Line; |
| 1132 |
|
| 1133 |
function Full_Debug_Name (S : SFI) return File_Name_Type is |
| 1134 |
begin |
| 1135 |
return Source_File.Table (S).Full_Debug_Name; |
| 1136 |
end Full_Debug_Name; |
| 1137 |
|
| 1138 |
function Full_File_Name (S : SFI) return File_Name_Type is |
| 1139 |
begin |
| 1140 |
return Source_File.Table (S).Full_File_Name; |
| 1141 |
end Full_File_Name; |
| 1142 |
|
| 1143 |
function Full_Ref_Name (S : SFI) return File_Name_Type is |
| 1144 |
begin |
| 1145 |
return Source_File.Table (S).Full_Ref_Name; |
| 1146 |
end Full_Ref_Name; |
| 1147 |
|
| 1148 |
function Identifier_Casing (S : SFI) return Casing_Type is |
| 1149 |
begin |
| 1150 |
return Source_File.Table (S).Identifier_Casing; |
| 1151 |
end Identifier_Casing; |
| 1152 |
|
| 1153 |
function Inherited_Pragma (S : SFI) return Boolean is |
| 1154 |
begin |
| 1155 |
return Source_File.Table (S).Inherited_Pragma; |
| 1156 |
end Inherited_Pragma; |
| 1157 |
|
| 1158 |
function Inlined_Body (S : SFI) return Boolean is |
| 1159 |
begin |
| 1160 |
return Source_File.Table (S).Inlined_Body; |
| 1161 |
end Inlined_Body; |
| 1162 |
|
| 1163 |
function Inlined_Call (S : SFI) return Source_Ptr is |
| 1164 |
begin |
| 1165 |
return Source_File.Table (S).Inlined_Call; |
| 1166 |
end Inlined_Call; |
| 1167 |
|
| 1168 |
function Keyword_Casing (S : SFI) return Casing_Type is |
| 1169 |
begin |
| 1170 |
return Source_File.Table (S).Keyword_Casing; |
| 1171 |
end Keyword_Casing; |
| 1172 |
|
| 1173 |
function Last_Source_Line (S : SFI) return Physical_Line_Number is |
| 1174 |
begin |
| 1175 |
return Source_File.Table (S).Last_Source_Line; |
| 1176 |
end Last_Source_Line; |
| 1177 |
|
| 1178 |
function License (S : SFI) return License_Type is |
| 1179 |
begin |
| 1180 |
return Source_File.Table (S).License; |
| 1181 |
end License; |
| 1182 |
|
| 1183 |
function Num_SRef_Pragmas (S : SFI) return Nat is |
| 1184 |
begin |
| 1185 |
return Source_File.Table (S).Num_SRef_Pragmas; |
| 1186 |
end Num_SRef_Pragmas; |
| 1187 |
|
| 1188 |
function Reference_Name (S : SFI) return File_Name_Type is |
| 1189 |
begin |
| 1190 |
return Source_File.Table (S).Reference_Name; |
| 1191 |
end Reference_Name; |
| 1192 |
|
| 1193 |
function Source_Checksum (S : SFI) return Word is |
| 1194 |
begin |
| 1195 |
return Source_File.Table (S).Source_Checksum; |
| 1196 |
end Source_Checksum; |
| 1197 |
|
| 1198 |
function Source_First (S : SFI) return Source_Ptr is |
| 1199 |
begin |
| 1200 |
return Source_File.Table (S).Source_First; |
| 1201 |
end Source_First; |
| 1202 |
|
| 1203 |
function Source_Last (S : SFI) return Source_Ptr is |
| 1204 |
begin |
| 1205 |
return Source_File.Table (S).Source_Last; |
| 1206 |
end Source_Last; |
| 1207 |
|
| 1208 |
function Source_Text (S : SFI) return Source_Buffer_Ptr is |
| 1209 |
begin |
| 1210 |
return Source_File.Table (S).Source_Text; |
| 1211 |
end Source_Text; |
| 1212 |
|
| 1213 |
function Template (S : SFI) return SFI is |
| 1214 |
begin |
| 1215 |
return Source_File.Table (S).Template; |
| 1216 |
end Template; |
| 1217 |
|
| 1218 |
function Time_Stamp (S : SFI) return Time_Stamp_Type is |
| 1219 |
begin |
| 1220 |
return Source_File.Table (S).Time_Stamp; |
| 1221 |
end Time_Stamp; |
| 1222 |
|
| 1223 |
function Unit (S : SFI) return Unit_Number_Type is |
| 1224 |
begin |
| 1225 |
return Source_File.Table (S).Unit; |
| 1226 |
end Unit; |
| 1227 |
|
| 1228 |
------------------------------------------ |
| 1229 |
-- Set Procedures for Source File Table -- |
| 1230 |
------------------------------------------ |
| 1231 |
|
| 1232 |
procedure Set_Identifier_Casing (S : SFI; C : Casing_Type) is |
| 1233 |
begin |
| 1234 |
Source_File.Table (S).Identifier_Casing := C; |
| 1235 |
end Set_Identifier_Casing; |
| 1236 |
|
| 1237 |
procedure Set_Keyword_Casing (S : SFI; C : Casing_Type) is |
| 1238 |
begin |
| 1239 |
Source_File.Table (S).Keyword_Casing := C; |
| 1240 |
end Set_Keyword_Casing; |
| 1241 |
|
| 1242 |
procedure Set_License (S : SFI; L : License_Type) is |
| 1243 |
begin |
| 1244 |
Source_File.Table (S).License := L; |
| 1245 |
end Set_License; |
| 1246 |
|
| 1247 |
procedure Set_Unit (S : SFI; U : Unit_Number_Type) is |
| 1248 |
begin |
| 1249 |
Source_File.Table (S).Unit := U; |
| 1250 |
end Set_Unit; |
| 1251 |
|
| 1252 |
---------------------- |
| 1253 |
-- Trim_Lines_Table -- |
| 1254 |
---------------------- |
| 1255 |
|
| 1256 |
procedure Trim_Lines_Table (S : Source_File_Index) is |
| 1257 |
Max : constant Nat := Nat (Source_File.Table (S).Last_Source_Line); |
| 1258 |
|
| 1259 |
begin |
| 1260 |
-- Release allocated storage that is no longer needed |
| 1261 |
|
| 1262 |
Source_File.Table (S).Lines_Table := To_Pointer |
| 1263 |
(Memory.Realloc |
| 1264 |
(To_Address (Source_File.Table (S).Lines_Table), |
| 1265 |
Memory.size_t |
| 1266 |
(Max * (Lines_Table_Type'Component_Size / System.Storage_Unit)))); |
| 1267 |
Source_File.Table (S).Lines_Table_Max := Physical_Line_Number (Max); |
| 1268 |
end Trim_Lines_Table; |
| 1269 |
|
| 1270 |
------------ |
| 1271 |
-- Unlock -- |
| 1272 |
------------ |
| 1273 |
|
| 1274 |
procedure Unlock is |
| 1275 |
begin |
| 1276 |
Source_File.Locked := False; |
| 1277 |
Source_File.Release; |
| 1278 |
end Unlock; |
| 1279 |
|
| 1280 |
-------- |
| 1281 |
-- wl -- |
| 1282 |
-------- |
| 1283 |
|
| 1284 |
procedure wl (P : Source_Ptr) is |
| 1285 |
begin |
| 1286 |
Write_Location (P); |
| 1287 |
Write_Eol; |
| 1288 |
end wl; |
| 1289 |
|
| 1290 |
end Sinput; |