OSDN Git Service

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