OSDN Git Service

Add Fariborz to my last change.
[pf3gnuchains/gcc-fork.git] / gcc / ada / sinput.ads
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               S I N P U T                                --
6 --                                                                          --
7 --                                 S p e c                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2004 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 2,  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 COPYING.  If not, write --
19 -- to  the Free Software Foundation,  59 Temple Place - Suite 330,  Boston, --
20 -- MA 02111-1307, USA.                                                      --
21 --                                                                          --
22 -- As a special exception,  if other files  instantiate  generics from this --
23 -- unit, or you link  this unit with other files  to produce an executable, --
24 -- this  unit  does not  by itself cause  the resulting  executable  to  be --
25 -- covered  by the  GNU  General  Public  License.  This exception does not --
26 -- however invalidate  any other reasons why  the executable file  might be --
27 -- covered by the  GNU Public License.                                      --
28 --                                                                          --
29 -- GNAT was originally developed  by the GNAT team at  New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
31 --                                                                          --
32 ------------------------------------------------------------------------------
33
34 --  This package contains the input routines used for reading the
35 --  input source file. The actual I/O routines are in OS_Interface,
36 --  with this module containing only the system independent processing.
37
38 --  General Note: throughout the compiler, we use the term line or source
39 --  line to refer to a physical line in the source, terminated by the end of
40 --  physical line sequence. See Skip_Line_Terminators procedure for a full
41 --  description of the difference between logical and physical lines.
42
43 with Alloc;
44 with Casing; use Casing;
45 with Table;
46 with Types;  use Types;
47
48 package Sinput is
49
50    type Type_Of_File is (
51    --  Indicates type of file being read
52
53       Src,
54       --  Normal Ada source file
55
56       Config,
57       --  Configuration pragma file
58
59       Def,
60       --  Preprocessing definition file
61
62       Preproc);
63       --  Source file with preprocessing commands to be preprocessed
64
65    ----------------------------
66    -- Source License Control --
67    ----------------------------
68
69    --  The following type indicates the license state of a source if it
70    --  is known.
71
72    type License_Type is
73      (Unknown,
74       --  Licensing status of this source unit is unknown
75
76       Restricted,
77       --  This is a non-GPL'ed unit that is restricted from depending
78       --  on GPL'ed units (e.g. proprietary code is in this category)
79
80       GPL,
81       --  This file is licensed under the unmodified GPL. It is not allowed
82       --  to depend on Non_GPL units, and Non_GPL units may not depend on
83       --  this source unit.
84
85       Modified_GPL,
86       --  This file is licensed under the GNAT modified GPL (see header of
87       --  This file for wording of the modification). It may depend on other
88       --  Modified_GPL units or on unrestricted units.
89
90       Unrestricted);
91       --  The license on this file is permitted to depend on any other
92       --  units, or have other units depend on it, without violating the
93       --  license of this unit. Examples are public domain units, and
94       --  units defined in the RM).
95
96    --  The above license status is checked when the appropriate check is
97    --  activated and one source depends on another, and the licensing state
98    --  of both files is known:
99
100    --  The prohibited combinations are:
101
102    --    Restricted file may not depend on GPL file
103
104    --    GPL file may not depend on Restricted file
105
106    --    Modified GPL file may not depend on Restricted file
107    --    Modified_GPL file may not depend on GPL file
108
109    --  The reason for the last restriction here is that a client depending
110    --  on a modified GPL file must be sure that the license condition is
111    --  correct considered transitively.
112
113    --  The licensing status is determined either by the presence of a
114    --  specific pragma License, or by scanning the header for a predefined
115    --  file, or any file if compiling in -gnatg mode.
116
117    -----------------------
118    -- Source File Table --
119    -----------------------
120
121    --  The source file table has an entry for each source file read in for
122    --  this run of the compiler. This table is (default) initialized when
123    --  the compiler is loaded, and simply accumulates entries as compilation
124    --  proceeds and various routines in Sinput and its child packages are
125    --  called to load required source files.
126
127    --  Virtual entries are also created for generic templates when they are
128    --  instantiated, as described in a separate section later on.
129
130    --  In the case where there are multiple main units (e.g. in the case of
131    --  the cross-reference tool), this table is not reset between these units,
132    --  so that a given source file is only read once if it is used by two
133    --  separate main units.
134
135    --  The entries in the table are accessed using a Source_File_Index that
136    --  ranges from 1 to Last_Source_File. Each entry has the following fields
137
138    --  Note: fields marked read-only are set by Sinput or one of its child
139    --  packages when a source file table entry is created, and cannot be
140    --  subsqently modified, or alternatively are set only by very special
141    --  circumstances, documented in the comments.
142
143    --  File_Name : File_Name_Type (read-only)
144    --    Name of the source file (simple name with no directory information)
145
146    --  Full_File_Name : File_Name_Type (read-only)
147    --    Full file name (full name with directory info), used for generation
148    --    of error messages, etc.
149
150    --  File_Type : Type_Of_File (read-only)
151    --    Indicates type of file (source file, configuration pragmas file,
152    --    preprocessor definition file, preprocessor input file).
153
154    --  Reference_Name : File_Name_Type (read-only)
155    --    Name to be used for source file references in error messages where
156    --    only the simple name of the file is required. Identical to File_Name
157    --    unless pragma Source_Reference is used to change it. Only processing
158    --    for the Source_Reference pragma circuit may set this field.
159
160    --  Full_Ref_Name : File_Name_Type (read-only)
161    --    Name to be used for source file references in error messages where
162    --    the full name of the file is required. Identical to Full_File_Name
163    --    unless pragma Source_Reference is used to change it. Only processing
164    --    for the Source_Reference pragma may set this field.
165
166    --  Debug_Source_Name : File_Name_Type (read-only)
167    --    Name to be used for source file references in debugging information
168    --    where only the simple name of the file is required. Identical to
169    --    Reference_Name unless the -gnatD (debug source file) switch is used.
170    --    Only processing in Sprint that generates this file is permitted to
171    --    set this field.
172
173    --  Full_Debug_Name : File_Name_Type (read-only)
174    --    Name to be used for source file references in debugging information
175    --    where the full name of the file is required. This is identical to
176    --    Full_Ref_Name unless the -gnatD (debug source file) switch is used.
177    --    Only processing in Sprint that generates this file is permitted to
178    --    set this field.
179
180    --  License : License_Type;
181    --    License status of source file
182
183    --  Num_SRef_Pragmas : Nat;
184    --    Number of source reference pragmas present in source file
185
186    --  First_Mapped_Line : Logical_Line_Number;
187    --    This field stores logical line number of the first line in the
188    --    file that is not a Source_Reference pragma. If no source reference
189    --    pragmas are used, then the value is set to No_Line_Number.
190
191    --  Source_Text : Source_Buffer_Ptr (read-only)
192    --    Text of source file. Note that every source file has a distinct set
193    --    of non-overlapping logical bounds, so it is possible to determine
194    --    which file is referenced from a given subscript (Source_Ptr) value.
195
196    --  Source_First : Source_Ptr; (read-only)
197    --    Subscript of first character in Source_Text. Note that this cannot
198    --    be obtained as Source_Text'First, because we use virtual origin
199    --    addressing.
200
201    --  Source_Last : Source_Ptr; (read-only)
202    --    Subscript of last character in Source_Text. Note that this cannot
203    --    be obtained as Source_Text'Last, because we use virtual origin
204    --    addressing, so this value is always Source_Ptr'Last.
205
206    --  Time_Stamp : Time_Stamp_Type; (read-only)
207    --    Time stamp of the source file
208
209    --  Source_Checksum : Word;
210    --    Computed checksum for contents of source file. See separate section
211    --    later on in this spec for a description of the checksum algorithm.
212
213    --  Last_Source_Line : Physical_Line_Number;
214    --    Physical line number of last source line. Whlie a file is being
215    --    read, this refers to the last line scanned. Once a file has been
216    --    completely scanned, it is the number of the last line in the file,
217    --    and hence also gives the number of source lines in the file.
218
219    --  Keyword_Casing : Casing_Type;
220    --    Casing style used in file for keyword casing. This is initialized
221    --    to Unknown, and then set from the first occurrence of a keyword.
222    --    This value is used only for formatting of error messages.
223
224    --  Identifier_Casing : Casing_Type;
225    --    Casing style used in file for identifier casing. This is initialized
226    --    to Unknown, and then set from an identifier in the program as soon as
227    --    one is found whose casing is sufficiently clear to make a decision.
228    --    This value is used for formatting of error messages, and also is used
229    --    in the detection of keywords misused as identifiers.
230
231    --  Instantiation : Source_Ptr;
232    --    Source file location of the instantiation if this source file entry
233    --    represents a generic instantiation. Set to No_Location for the case
234    --    of a normal non-instantiation entry. See section below for details.
235    --    This field is read-only for clients.
236
237    --  Inlined_Body : Boolean;
238    --    This can only be set True if Instantiation has a value other than
239    --    No_Location. If true it indicates that the instantiation is actually
240    --    an instance of an inlined body.
241
242    --  Template : Source_File_Index; (read-only)
243    --    Source file index of the source file containing the template if this
244    --    is a generic instantiation. Set to No_Source_File for the normal case
245    --    of a non-instantiation entry. See Sinput-L for details.
246
247    --  The source file table is accessed by clients using the following
248    --  subprogram interface:
249
250    subtype SFI is Source_File_Index;
251
252    System_Source_File_Index : SFI;
253    --  The file system.ads is always read by the compiler to determine the
254    --  settings of the target parameters in the private part of System. This
255    --  variable records the source file index of system.ads. Typically this
256    --  will be 1 since system.ads is read first.
257
258    function Debug_Source_Name (S : SFI) return File_Name_Type;
259    function File_Name         (S : SFI) return File_Name_Type;
260    function File_Type         (S : SFI) return Type_Of_File;
261    function First_Mapped_Line (S : SFI) return Logical_Line_Number;
262    function Full_Debug_Name   (S : SFI) return File_Name_Type;
263    function Full_File_Name    (S : SFI) return File_Name_Type;
264    function Full_Ref_Name     (S : SFI) return File_Name_Type;
265    function Identifier_Casing (S : SFI) return Casing_Type;
266    function Inlined_Body      (S : SFI) return Boolean;
267    function Instantiation     (S : SFI) return Source_Ptr;
268    function Keyword_Casing    (S : SFI) return Casing_Type;
269    function Last_Source_Line  (S : SFI) return Physical_Line_Number;
270    function License           (S : SFI) return License_Type;
271    function Num_SRef_Pragmas  (S : SFI) return Nat;
272    function Reference_Name    (S : SFI) return File_Name_Type;
273    function Source_Checksum   (S : SFI) return Word;
274    function Source_First      (S : SFI) return Source_Ptr;
275    function Source_Last       (S : SFI) return Source_Ptr;
276    function Source_Text       (S : SFI) return Source_Buffer_Ptr;
277    function Template          (S : SFI) return Source_File_Index;
278    function Time_Stamp        (S : SFI) return Time_Stamp_Type;
279
280    procedure Set_Keyword_Casing    (S : SFI; C : Casing_Type);
281    procedure Set_Identifier_Casing (S : SFI; C : Casing_Type);
282    procedure Set_License           (S : SFI; L : License_Type);
283
284    function Last_Source_File return Source_File_Index;
285    --  Index of last source file table entry
286
287    function Num_Source_Files return Nat;
288    --  Number of source file table entries
289
290    procedure Initialize;
291    --  Initialize internal tables
292
293    procedure Lock;
294    --  Lock internal tables
295
296    Main_Source_File : Source_File_Index;
297    --  This is set to the source file index of the main unit
298
299    -----------------------------
300    -- Source_File_Index_Table --
301    -----------------------------
302
303    --  The Get_Source_File_Index function is called very frequently. Earlier
304    --  versions cached a single entry, but then reverted to a serial search,
305    --  and this proved to be a significant source of inefficiency. To get
306    --  around this, we use the following directly indexed array. The space
307    --  of possible input values is a value of type Source_Ptr which is simply
308    --  an Int value. The values in this space are allocated sequentially as
309    --  new units are loaded.
310
311    --  The following table has an entry for each 4K range of possible
312    --  Source_Ptr values. The value in the table is the lowest value
313    --  Source_File_Index whose Source_Ptr range contains value in the
314    --  range.
315
316    --  For example, the entry with index 4 in this table represents Source_Ptr
317    --  values in the range 4*4096 .. 5*4096-1. The Source_File_Index value
318    --  stored would be the lowest numbered source file with at least one byte
319    --  in this range.
320
321    --  The algorithm used in Get_Source_File_Index is simply to access this
322    --  table and then do a serial search starting at the given position. This
323    --  will almost always terminate with one or two checks.
324
325    --  Note that this array is pretty large, but in most operating systems
326    --  it will not be allocated in physical memory unless it is actually used.
327
328    Chunk_Power : constant := 12;
329    Chunk_Size  : constant := 2 ** Chunk_Power;
330    --  Change comments above if value changed. Note that Chunk_Size must
331    --  be a power of 2 (to allow for efficient access to the table).
332
333    Source_File_Index_Table :
334      array (Int range 0 .. Int'Last / Chunk_Size) of Source_File_Index;
335
336    procedure Set_Source_File_Index_Table (Xnew : Source_File_Index);
337    --  Sets entries in the Source_File_Index_Table for the newly created
338    --  Source_File table entry whose index is Xnew. The Source_First and
339    --  Source_Last fields of this entry must be set before the call.
340
341    -----------------------
342    -- Checksum Handling --
343    -----------------------
344
345    --  As a source file is scanned, a checksum is computed by taking all the
346    --  non-blank characters in the file, excluding comment characters, the
347    --  minus-minus sequence starting a comment, and all control characters
348    --  except ESC.
349
350    --  The checksum algorithm used is the standard CRC-32 algorithm, as
351    --  implemented by System.CRC32, except that we do not bother with the
352    --  final XOR with all 1 bits.
353
354    --  This algorithm ensures that the checksum includes all semantically
355    --  significant aspects of the program represented by the source file,
356    --  but is insensitive to layout, presence or contents of comments, wide
357    --  character representation method, or casing conventions outside strings.
358
359    --  Scans.Checksum is initialized appropriately at the start of scanning
360    --  a file, and copied into the Source_Checksum field of the file table
361    --  entry when the end of file is encountered.
362
363    -------------------------------------
364    -- Handling Generic Instantiations --
365    -------------------------------------
366
367    --  As described in Sem_Ch12, a generic instantiation involves making a
368    --  copy of the tree of the generic template. The source locations in
369    --  this tree directly reference the source of the template. However it
370    --  is also possible to find the location of the instantiation.
371
372    --  This is achieved as follows. When an instantiation occurs, a new entry
373    --  is made in the source file table. This entry points to the same source
374    --  text, i.e. the file that contains the instantiation, but has a distinct
375    --  set of Source_Ptr index values. The separate range of Sloc values avoids
376    --  confusion, and means that the Sloc values can still be used to uniquely
377    --  identify the source file table entry. It is possible for both entries
378    --  to point to the same text, because of the virtual origin pointers used
379    --  in the source table.
380
381    --  The Instantiation field of this source file index entry, usually set
382    --  to No_Source_File, instead contains the Sloc of the instantiation. In
383    --  the case of nested instantiations, this Sloc may itself refer to an
384    --  instantiation, so the complete chain can be traced.
385
386    --  Two routines are used to build these special entries in the source
387    --  file table. Create_Instantiation_Source is first called to build
388    --  the virtual source table entry for the instantiation, and then the
389    --  Sloc values in the copy are adjusted using Adjust_Instantiation_Sloc.
390    --  See child unit Sinput.L for details on these two routines.
391
392    -----------------
393    -- Global Data --
394    -----------------
395
396    Current_Source_File : Source_File_Index;
397    --  Source_File table index of source file currently being scanned
398
399    Current_Source_Unit : Unit_Number_Type;
400    --  Unit number of source file currently being scanned. The special value
401    --  of No_Unit indicates that the configuration pragma file is currently
402    --  being scanned (this has no entry in the unit table).
403
404    Source_gnat_adc : Source_File_Index := No_Source_File;
405    --  This is set if a gnat.adc file is present to reference this file
406
407    Source : Source_Buffer_Ptr;
408    --  Current source (copy of Source_File.Table (Current_Source_Unit).Source)
409
410    Internal_Source : aliased Source_Buffer (1 .. 81);
411    --  This buffer is used internally in the compiler when the lexical analyzer
412    --  is used to scan a string from within the compiler. The procedure is to
413    --  establish Internal_Source_Ptr as the value of Source, set the string to
414    --  be scanned, appropriately terminated, in this buffer, and set Scan_Ptr
415    --  to point to the start of the buffer. It is a fatal error if the scanner
416    --  signals an error while scanning a token in this internal buffer.
417
418    Internal_Source_Ptr : constant Source_Buffer_Ptr :=
419                            Internal_Source'Unrestricted_Access;
420    --  Pointer to internal source buffer
421
422    -----------------
423    -- Subprograms --
424    -----------------
425
426    procedure Backup_Line (P : in out Source_Ptr);
427    --  Back up the argument pointer to the start of the previous line. On
428    --  entry, P points to the start of a physical line in the source buffer.
429    --  On return, P is updated to point to the start of the previous line.
430    --  The caller has checked that a Line_Terminator character precedes P so
431    --  that there definitely is a previous line in the source buffer.
432
433    procedure Build_Location_String (Loc : Source_Ptr);
434    --  This function builds a string literal of the form "name:line",
435    --  where name is the file name corresponding to Loc, and line is
436    --  the line number. In the event that instantiations are involved,
437    --  additional suffixes of the same form are appended after the
438    --  separating string " instantiated at ". The returned string is
439    --  stored in Name_Buffer, terminated by ASCII.Nul, with Name_Length
440    --  indicating the length not including the terminating Nul.
441
442    function Get_Column_Number (P : Source_Ptr) return Column_Number;
443    --  The ones-origin column number of the specified Source_Ptr value is
444    --  determined and returned. Tab characters if present are assumed to
445    --  represent the standard 1,9,17.. spacing pattern.
446
447    function Get_Logical_Line_Number
448      (P : Source_Ptr) return Logical_Line_Number;
449    --  The line number of the specified source position is obtained by
450    --  doing a binary search on the source positions in the lines table
451    --  for the unit containing the given source position. The returned
452    --  value is the logical line number, already adjusted for the effect
453    --  of source reference pragmas. If P refers to the line of a source
454    --  reference pragma itself, then No_Line is returned. If no source
455    --  reference pragmas have been encountered, the value returned is
456    --  the same as the physical line number.
457
458    function Get_Physical_Line_Number
459      (P : Source_Ptr) return Physical_Line_Number;
460    --  The line number of the specified source position is obtained by
461    --  doing a binary search on the source positions in the lines table
462    --  for the unit containing the given source position. The returned
463    --  value is the physical line number in the source being compiled.
464
465    function Get_Source_File_Index (S : Source_Ptr) return Source_File_Index;
466    --  Return file table index of file identified by given source pointer
467    --  value. This call must always succeed, since any valid source pointer
468    --  value belongs to some previously loaded source file.
469
470    function Instantiation_Depth (S : Source_Ptr) return Nat;
471    --  Determine instantiation depth for given Sloc value. A value of
472    --  zero means that the given Sloc is not in an instantiation.
473
474    function Line_Start (P : Source_Ptr) return Source_Ptr;
475    --  Finds the source position of the start of the line containing the
476    --  given source location.
477
478    function Line_Start
479      (L : Physical_Line_Number;
480       S : Source_File_Index) return Source_Ptr;
481    --  Finds the source position of the start of the given line in the
482    --  given source file, using a physical line number to identify the line.
483
484    function Num_Source_Lines (S : Source_File_Index) return Nat;
485    --  Returns the number of source lines (this is equivalent to reading
486    --  the value of Last_Source_Line, but returns Nat rathern than a
487    --  physical line number.
488
489    procedure Register_Source_Ref_Pragma
490      (File_Name          : Name_Id;
491       Stripped_File_Name : Name_Id;
492       Mapped_Line        : Nat;
493       Line_After_Pragma  : Physical_Line_Number);
494    --  Register a source reference pragma, the parameter File_Name is the
495    --  file name from the pragma, and Stripped_File_Name is this name with
496    --  the directory information stripped. Both these parameters are set
497    --  to No_Name if no file name parameter was given in the pragma.
498    --  (which can only happen for the second and subsequent pragmas).
499    --  Mapped_Line is the line number parameter from the pragma, and
500    --  Line_After_Pragma is the physical line number of the line that
501    --  follows the line containing the Source_Reference pragma.
502
503    function Original_Location (S : Source_Ptr) return Source_Ptr;
504    --  Given a source pointer S, returns the corresponding source pointer
505    --  value ignoring instantiation copies. For locations that do not
506    --  correspond to instantiation copies of templates, the argument is
507    --  returned unchanged. For locations that do correspond to copies of
508    --  templates from instantiations, the location within the original
509    --  template is returned. This is useful in canonicalizing locations.
510
511    function Instantiation_Location (S : Source_Ptr) return Source_Ptr;
512    pragma Inline (Instantiation_Location);
513    --  Given a source pointer S, returns the corresponding source pointer
514    --  value of the instantiation if this location is within an instance.
515    --  If S is not within an instance, then this returns No_Location.
516
517    function Top_Level_Location (S : Source_Ptr) return Source_Ptr;
518    --  Given a source pointer S, returns the argument unchanged if it is
519    --  not in an instantiation. If S is in an instantiation, then it returns
520    --  the location of the top level instantiation, i.e. the outer level
521    --  instantiation in the nested case.
522
523    function Physical_To_Logical
524      (Line : Physical_Line_Number;
525       S    : Source_File_Index) return Logical_Line_Number;
526    --  Given a physical line number in source file whose source index is S,
527    --  return the corresponding logical line number. If the physical line
528    --  number is one containing a Source_Reference pragma, the result will
529    --  be No_Line_Number.
530
531    procedure Skip_Line_Terminators
532      (P        : in out Source_Ptr;
533       Physical : out Boolean);
534    --  On entry, Source (P) points to the line terminator character that
535    --  terminates a line. The result set in P is the location of the first
536    --  character of the following line (after skipping the sequence of line
537    --  terminator characters terminating the current line). In addition, if
538    --  the terminator sequence ends a physical line (the definition of what
539    --  constitutes a physical line is embodied in the implementation of this
540    --  function), and it is the first time this sequence is encountered, then
541    --  an entry is made in the lines table to record the location for further
542    --  use by functions such as Get_Line_Number. Physical is set to True if
543    --  the line terminator was the end of a physical line.
544
545    function Source_Offset (S : Source_Ptr) return Nat;
546    --  Returns the zero-origin offset of the given source location from the
547    --  start of its corresponding unit. This is used for creating canonical
548    --  names in some situations.
549
550    procedure Write_Location (P : Source_Ptr);
551    --  Writes out a string of the form fff:nn:cc, where fff, nn, cc are the
552    --  file name, line number and column corresponding to the given source
553    --  location. No_Location and Standard_Location appear as the strings
554    --  <no location> and <standard location>. If the location is within an
555    --  instantiation, then the instance location is appended, enclosed in
556    --  square brackets (which can nest if necessary). Note that this routine
557    --  is used only for internal compiler debugging output purposes (which
558    --  is why the somewhat cryptic use of brackets is acceptable).
559
560    procedure wl (P : Source_Ptr);
561    pragma Export (Ada, wl);
562    --  Equivalent to Write_Location (P); Write_Eol; for calls from GDB
563
564    procedure Write_Time_Stamp (S : Source_File_Index);
565    --  Writes time stamp of specified file in YY-MM-DD HH:MM.SS format
566
567    procedure Tree_Write;
568    --  Writes out internal tables to current tree file using Tree_Write
569
570    procedure Tree_Read;
571    --  Initializes internal tables from current tree file using Tree_Read
572
573 private
574    pragma Inline (File_Name);
575    pragma Inline (First_Mapped_Line);
576    pragma Inline (Full_File_Name);
577    pragma Inline (Identifier_Casing);
578    pragma Inline (Instantiation);
579    pragma Inline (Keyword_Casing);
580    pragma Inline (Last_Source_Line);
581    pragma Inline (Last_Source_File);
582    pragma Inline (License);
583    pragma Inline (Num_SRef_Pragmas);
584    pragma Inline (Num_Source_Files);
585    pragma Inline (Num_Source_Lines);
586    pragma Inline (Reference_Name);
587    pragma Inline (Set_Keyword_Casing);
588    pragma Inline (Set_Identifier_Casing);
589    pragma Inline (Source_First);
590    pragma Inline (Source_Last);
591    pragma Inline (Source_Text);
592    pragma Inline (Template);
593    pragma Inline (Time_Stamp);
594
595    -------------------------
596    -- Source_Lines Tables --
597    -------------------------
598
599    type Lines_Table_Type is
600      array (Physical_Line_Number) of Source_Ptr;
601    --  Type used for lines table. The entries are indexed by physical line
602    --  numbers. The values are the starting Source_Ptr values for the start
603    --  of the corresponding physical line. Note that we make this a bogus
604    --  big array, sized as required, so that we avoid the use of fat pointers.
605
606    type Lines_Table_Ptr is access all Lines_Table_Type;
607    --  Type used for pointers to line tables
608
609    type Logical_Lines_Table_Type is
610      array (Physical_Line_Number) of Logical_Line_Number;
611    --  Type used for logical lines table. This table is used if a source
612    --  reference pragma is present. It is indexed by physical line numbers,
613    --  and contains the corresponding logical line numbers. An entry that
614    --  corresponds to a source reference pragma is set to No_Line_Number.
615    --  Note that we make this a bogus big array, sized as required, so that
616    --  we avoid the use of fat pointers.
617
618    type Logical_Lines_Table_Ptr is access all Logical_Lines_Table_Type;
619    --  Type used for pointers to logical line tables.
620
621    -----------------------
622    -- Source_File Table --
623    -----------------------
624
625    --  See earlier descriptions for meanings of public fields
626
627    type Source_File_Record is record
628
629       File_Name         : File_Name_Type;
630       File_Type         : Type_Of_File;
631       Reference_Name    : File_Name_Type;
632       Debug_Source_Name : File_Name_Type;
633       Full_Debug_Name   : File_Name_Type;
634       Full_File_Name    : File_Name_Type;
635       Full_Ref_Name     : File_Name_Type;
636       Inlined_Body      : Boolean;
637       License           : License_Type;
638       Num_SRef_Pragmas  : Nat;
639       First_Mapped_Line : Logical_Line_Number;
640       Source_Text       : Source_Buffer_Ptr;
641       Source_First      : Source_Ptr;
642       Source_Last       : Source_Ptr;
643       Time_Stamp        : Time_Stamp_Type;
644       Source_Checksum   : Word;
645       Last_Source_Line  : Physical_Line_Number;
646       Keyword_Casing    : Casing_Type;
647       Identifier_Casing : Casing_Type;
648       Instantiation     : Source_Ptr;
649       Template          : Source_File_Index;
650
651       --  The following fields are for internal use only (i.e. only in the
652       --  body of Sinput or its children, with no direct access by clients).
653
654       Sloc_Adjust : Source_Ptr;
655       --  A value to be added to Sloc values for this file to reference the
656       --  corresponding lines table. This is zero for the non-instantiation
657       --  case, and set so that the adition references the ultimate template
658       --  for the instantiation case. See Sinput-L for further details.
659
660       Lines_Table : Lines_Table_Ptr;
661       --  Pointer to lines table for this source. Updated as additional
662       --  lines are accessed using the Skip_Line_Terminators procedure.
663       --  Note: the lines table for an instantiation entry refers to the
664       --  original line numbers of the template see Sinput-L for details.
665
666       Logical_Lines_Table : Logical_Lines_Table_Ptr;
667       --  Pointer to logical lines table for this source. Non-null only if
668       --  a source reference pragma has been processed. Updated as lines
669       --  are accessed using the Skip_Line_Terminators procedure.
670
671       Lines_Table_Max : Physical_Line_Number;
672       --  Maximum subscript values for currently allocated Lines_Table
673       --  and (if present) the allocated Logical_Lines_Table. The value
674       --  Max_Source_Line gives the maximum used value, this gives the
675       --  maximum allocated value.
676
677    end record;
678
679    package Source_File is new Table.Table (
680      Table_Component_Type => Source_File_Record,
681      Table_Index_Type     => Source_File_Index,
682      Table_Low_Bound      => 1,
683      Table_Initial        => Alloc.Source_File_Initial,
684      Table_Increment      => Alloc.Source_File_Increment,
685      Table_Name           => "Source_File");
686
687    -----------------
688    -- Subprograms --
689    -----------------
690
691    procedure Alloc_Line_Tables
692      (S       : in out Source_File_Record;
693       New_Max : Nat);
694    --  Allocate or reallocate the lines table for the given source file so
695    --  that it can accommodate at least New_Max lines. Also allocates or
696    --  reallocates logical lines table if source ref pragmas are present.
697
698    procedure Add_Line_Tables_Entry
699      (S : in out Source_File_Record;
700       P : Source_Ptr);
701    --  Increment line table size by one (reallocating the lines table if
702    --  needed) and set the new entry to contain the value P. Also bumps
703    --  the Source_Line_Count field. If source reference pragmas are
704    --  present, also increments logical lines table size by one, and
705    --  sets new entry.
706
707    procedure Trim_Lines_Table (S : Source_File_Index);
708    --  Set lines table size for entry S in the source file table to
709    --  correspond to the current value of Num_Source_Lines, releasing
710    --  any unused storage. This is used by Sinput.L and Sinput.D.
711
712 end Sinput;