annotate gcc/ada/sinput.ads @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S I N P U T --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
9 -- Copyright (C) 1992-2019, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package contains the input routines used for reading the
kono
parents:
diff changeset
33 -- input source file. The actual I/O routines are in OS_Interface,
kono
parents:
diff changeset
34 -- with this module containing only the system independent processing.
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- General Note: throughout the compiler, we use the term line or source
kono
parents:
diff changeset
37 -- line to refer to a physical line in the source, terminated by the end of
kono
parents:
diff changeset
38 -- physical line sequence.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 -- There are two distinct concepts of line terminator in GNAT
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 -- A logical line terminator is what corresponds to the "end of a line" as
kono
parents:
diff changeset
43 -- described in RM 2.2 (13). Any of the characters FF, LF, CR or VT or any
kono
parents:
diff changeset
44 -- wide character that is a Line or Paragraph Separator acts as an end of
kono
parents:
diff changeset
45 -- logical line in this sense, and it is essentially irrelevant whether one
kono
parents:
diff changeset
46 -- or more appears in sequence (since if a sequence of such characters is
kono
parents:
diff changeset
47 -- regarded as separate ends of line, then the intervening logical lines
kono
parents:
diff changeset
48 -- are null in any case).
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 -- A physical line terminator is a sequence of format effectors that is
kono
parents:
diff changeset
51 -- treated as ending a physical line. Physical lines have no Ada semantic
kono
parents:
diff changeset
52 -- significance, but they are significant for error reporting purposes,
kono
parents:
diff changeset
53 -- since errors are identified by line and column location.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 -- In GNAT, a physical line is ended by any of the sequences LF, CR/LF, or
kono
parents:
diff changeset
56 -- CR. LF is used in typical Unix systems, CR/LF in DOS systems, and CR
kono
parents:
diff changeset
57 -- alone in System 7. In addition, we recognize any of these sequences in
kono
parents:
diff changeset
58 -- any of the operating systems, for better behavior in treating foreign
kono
parents:
diff changeset
59 -- files (e.g. a Unix file with LF terminators transferred to a DOS system).
kono
parents:
diff changeset
60 -- Finally, wide character codes in categories Separator, Line and Separator,
kono
parents:
diff changeset
61 -- Paragraph are considered to be physical line terminators.
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 with Alloc;
kono
parents:
diff changeset
64 with Casing; use Casing;
kono
parents:
diff changeset
65 with Namet; use Namet;
kono
parents:
diff changeset
66 with System;
kono
parents:
diff changeset
67 with Table;
kono
parents:
diff changeset
68 with Types; use Types;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 package Sinput is
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 type Type_Of_File is (
kono
parents:
diff changeset
73 -- Indicates type of file being read
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 Src,
kono
parents:
diff changeset
76 -- Normal Ada source file
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 Config,
kono
parents:
diff changeset
79 -- Configuration pragma file
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 Def,
kono
parents:
diff changeset
82 -- Preprocessing definition file
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 Preproc);
kono
parents:
diff changeset
85 -- Source file with preprocessing commands to be preprocessed
kono
parents:
diff changeset
86
kono
parents:
diff changeset
87 type Instance_Id is new Nat;
kono
parents:
diff changeset
88 No_Instance_Id : constant Instance_Id;
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 ----------------------------
kono
parents:
diff changeset
91 -- Source License Control --
kono
parents:
diff changeset
92 ----------------------------
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 -- The following type indicates the license state of a source if it
kono
parents:
diff changeset
95 -- is known.
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 type License_Type is
kono
parents:
diff changeset
98 (Unknown,
kono
parents:
diff changeset
99 -- Licensing status of this source unit is unknown
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 Restricted,
kono
parents:
diff changeset
102 -- This is a non-GPL'ed unit that is restricted from depending
kono
parents:
diff changeset
103 -- on GPL'ed units (e.g. proprietary code is in this category)
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 GPL,
kono
parents:
diff changeset
106 -- This file is licensed under the unmodified GPL. It is not allowed
kono
parents:
diff changeset
107 -- to depend on Non_GPL units, and Non_GPL units may not depend on
kono
parents:
diff changeset
108 -- this source unit.
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 Modified_GPL,
kono
parents:
diff changeset
111 -- This file is licensed under the GNAT modified GPL (see header of
kono
parents:
diff changeset
112 -- This file for wording of the modification). It may depend on other
kono
parents:
diff changeset
113 -- Modified_GPL units or on unrestricted units.
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 Unrestricted);
kono
parents:
diff changeset
116 -- The license on this file is permitted to depend on any other
kono
parents:
diff changeset
117 -- units, or have other units depend on it, without violating the
kono
parents:
diff changeset
118 -- license of this unit. Examples are public domain units, and
kono
parents:
diff changeset
119 -- units defined in the RM).
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 -- The above license status is checked when the appropriate check is
kono
parents:
diff changeset
122 -- activated and one source depends on another, and the licensing state
kono
parents:
diff changeset
123 -- of both files is known:
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 -- The prohibited combinations are:
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 -- Restricted file may not depend on GPL file
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 -- GPL file may not depend on Restricted file
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 -- Modified GPL file may not depend on Restricted file
kono
parents:
diff changeset
132 -- Modified_GPL file may not depend on GPL file
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 -- The reason for the last restriction here is that a client depending
kono
parents:
diff changeset
135 -- on a modified GPL file must be sure that the license condition is
kono
parents:
diff changeset
136 -- correct considered transitively.
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 -- The licensing status is determined either by the presence of a
kono
parents:
diff changeset
139 -- specific pragma License, or by scanning the header for a predefined
kono
parents:
diff changeset
140 -- statement, or any file if compiling in -gnatg mode.
kono
parents:
diff changeset
141
kono
parents:
diff changeset
142 -----------------------
kono
parents:
diff changeset
143 -- Source File Table --
kono
parents:
diff changeset
144 -----------------------
kono
parents:
diff changeset
145
kono
parents:
diff changeset
146 -- The source file table has an entry for each source file read in for
kono
parents:
diff changeset
147 -- this run of the compiler. This table is (default) initialized when
kono
parents:
diff changeset
148 -- the compiler is loaded, and simply accumulates entries as compilation
kono
parents:
diff changeset
149 -- proceeds and various routines in Sinput and its child packages are
kono
parents:
diff changeset
150 -- called to load required source files.
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 -- Virtual entries are also created for generic templates when they are
kono
parents:
diff changeset
153 -- instantiated, as described in a separate section later on.
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 -- In the case where there are multiple main units (e.g. in the case of
kono
parents:
diff changeset
156 -- the cross-reference tool), this table is not reset between these units,
kono
parents:
diff changeset
157 -- so that a given source file is only read once if it is used by two
kono
parents:
diff changeset
158 -- separate main units.
kono
parents:
diff changeset
159
kono
parents:
diff changeset
160 -- The entries in the table are accessed using a Source_File_Index that
kono
parents:
diff changeset
161 -- ranges from 1 to Last_Source_File. Each entry has the following fields.
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 -- Note: fields marked read-only are set by Sinput or one of its child
kono
parents:
diff changeset
164 -- packages when a source file table entry is created, and cannot be
kono
parents:
diff changeset
165 -- subsequently modified, or alternatively are set only by very special
kono
parents:
diff changeset
166 -- circumstances, documented in the comments.
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 -- File_Name : File_Name_Type (read-only)
kono
parents:
diff changeset
169 -- Name of the source file (simple name with no directory information)
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 -- Full_File_Name : File_Name_Type (read-only)
kono
parents:
diff changeset
172 -- Full file name (full name with directory info), used for generation
kono
parents:
diff changeset
173 -- of error messages, etc.
kono
parents:
diff changeset
174
kono
parents:
diff changeset
175 -- File_Type : Type_Of_File (read-only)
kono
parents:
diff changeset
176 -- Indicates type of file (source file, configuration pragmas file,
kono
parents:
diff changeset
177 -- preprocessor definition file, preprocessor input file).
kono
parents:
diff changeset
178
kono
parents:
diff changeset
179 -- Reference_Name : File_Name_Type (read-only)
kono
parents:
diff changeset
180 -- Name to be used for source file references in error messages where
kono
parents:
diff changeset
181 -- only the simple name of the file is required. Identical to File_Name
kono
parents:
diff changeset
182 -- unless pragma Source_Reference is used to change it. Only processing
kono
parents:
diff changeset
183 -- for the Source_Reference pragma circuit may set this field.
kono
parents:
diff changeset
184
kono
parents:
diff changeset
185 -- Full_Ref_Name : File_Name_Type (read-only)
kono
parents:
diff changeset
186 -- Name to be used for source file references in error messages where
kono
parents:
diff changeset
187 -- the full name of the file is required. Identical to Full_File_Name
kono
parents:
diff changeset
188 -- unless pragma Source_Reference is used to change it. Only processing
kono
parents:
diff changeset
189 -- for the Source_Reference pragma may set this field.
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 -- Debug_Source_Name : File_Name_Type (read-only)
kono
parents:
diff changeset
192 -- Name to be used for source file references in debugging information
kono
parents:
diff changeset
193 -- where only the simple name of the file is required. Identical to
kono
parents:
diff changeset
194 -- Reference_Name unless the -gnatD (debug source file) switch is used.
kono
parents:
diff changeset
195 -- Only processing in Sprint that generates this file is permitted to
kono
parents:
diff changeset
196 -- set this field.
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 -- Full_Debug_Name : File_Name_Type (read-only)
kono
parents:
diff changeset
199 -- Name to be used for source file references in debugging information
kono
parents:
diff changeset
200 -- where the full name of the file is required. This is identical to
kono
parents:
diff changeset
201 -- Full_Ref_Name unless the -gnatD (debug source file) switch is used.
kono
parents:
diff changeset
202 -- Only processing in Sprint that generates this file is permitted to
kono
parents:
diff changeset
203 -- set this field.
kono
parents:
diff changeset
204
kono
parents:
diff changeset
205 -- Instance : Instance_Id (read-only)
kono
parents:
diff changeset
206 -- For entries corresponding to a generic instantiation, unique
kono
parents:
diff changeset
207 -- identifier denoting the full chain of nested instantiations. Set to
kono
parents:
diff changeset
208 -- No_Instance_Id for the case of a normal, non-instantiation entry.
kono
parents:
diff changeset
209 -- See below for details on the handling of generic instantiations.
kono
parents:
diff changeset
210
kono
parents:
diff changeset
211 -- License : License_Type;
kono
parents:
diff changeset
212 -- License status of source file
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 -- Num_SRef_Pragmas : Nat;
kono
parents:
diff changeset
215 -- Number of source reference pragmas present in source file
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 -- First_Mapped_Line : Logical_Line_Number;
kono
parents:
diff changeset
218 -- This field stores logical line number of the first line in the
kono
parents:
diff changeset
219 -- file that is not a Source_Reference pragma. If no source reference
kono
parents:
diff changeset
220 -- pragmas are used, then the value is set to No_Line_Number.
kono
parents:
diff changeset
221
kono
parents:
diff changeset
222 -- Source_Text : Source_Buffer_Ptr (read-only)
kono
parents:
diff changeset
223 -- Text of source file. Every source file has a distinct set of
kono
parents:
diff changeset
224 -- nonoverlapping bounds, so it is possible to determine which
kono
parents:
diff changeset
225 -- file is referenced from a given subscript (Source_Ptr) value.
kono
parents:
diff changeset
226
kono
parents:
diff changeset
227 -- Source_First : Source_Ptr; (read-only)
kono
parents:
diff changeset
228 -- This is always equal to Source_Text'First, except during
kono
parents:
diff changeset
229 -- construction of a debug output file (*.dg), when Source_Text = null,
kono
parents:
diff changeset
230 -- and Source_First is the size so far. Likewise for Last.
kono
parents:
diff changeset
231
kono
parents:
diff changeset
232 -- Source_Last : Source_Ptr; (read-only)
kono
parents:
diff changeset
233 -- Same idea as Source_Last, but for Last
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 -- Time_Stamp : Time_Stamp_Type; (read-only)
kono
parents:
diff changeset
236 -- Time stamp of the source file
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 -- Source_Checksum : Word;
kono
parents:
diff changeset
239 -- Computed checksum for contents of source file. See separate section
kono
parents:
diff changeset
240 -- later on in this spec for a description of the checksum algorithm.
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 -- Last_Source_Line : Physical_Line_Number;
kono
parents:
diff changeset
243 -- Physical line number of last source line. While a file is being
kono
parents:
diff changeset
244 -- read, this refers to the last line scanned. Once a file has been
kono
parents:
diff changeset
245 -- completely scanned, it is the number of the last line in the file,
kono
parents:
diff changeset
246 -- and hence also gives the number of source lines in the file.
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 -- Keyword_Casing : Casing_Type;
kono
parents:
diff changeset
249 -- Casing style used in file for keyword casing. This is initialized
kono
parents:
diff changeset
250 -- to Unknown, and then set from the first occurrence of a keyword.
kono
parents:
diff changeset
251 -- This value is used only for formatting of error messages.
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 -- Identifier_Casing : Casing_Type;
kono
parents:
diff changeset
254 -- Casing style used in file for identifier casing. This is initialized
kono
parents:
diff changeset
255 -- to Unknown, and then set from an identifier in the program as soon as
kono
parents:
diff changeset
256 -- one is found whose casing is sufficiently clear to make a decision.
kono
parents:
diff changeset
257 -- This value is used for formatting of error messages, and also is used
kono
parents:
diff changeset
258 -- in the detection of keywords misused as identifiers.
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 -- Inlined_Call : Source_Ptr;
kono
parents:
diff changeset
261 -- Source file location of the subprogram call if this source file entry
kono
parents:
diff changeset
262 -- represents an inlined body or an inherited pragma. Set to No_Location
kono
parents:
diff changeset
263 -- otherwise. This field is read-only for clients.
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 -- Inlined_Body : Boolean;
kono
parents:
diff changeset
266 -- This can only be set True if Instantiation has a value other than
kono
parents:
diff changeset
267 -- No_Location. If true it indicates that the instantiation is actually
kono
parents:
diff changeset
268 -- an instance of an inlined body.
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 -- Inherited_Pragma : Boolean;
kono
parents:
diff changeset
271 -- This can only be set True if Instantiation has a value other than
kono
parents:
diff changeset
272 -- No_Location. If true it indicates that the instantiation is actually
kono
parents:
diff changeset
273 -- an inherited class-wide pre- or postcondition.
kono
parents:
diff changeset
274
kono
parents:
diff changeset
275 -- Template : Source_File_Index; (read-only)
kono
parents:
diff changeset
276 -- Source file index of the source file containing the template if this
kono
parents:
diff changeset
277 -- is a generic instantiation. Set to No_Source_File for the normal case
kono
parents:
diff changeset
278 -- of a non-instantiation entry. See Sinput-L for details.
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 -- Unit : Unit_Number_Type;
kono
parents:
diff changeset
281 -- Identifies the unit contained in this source file. Set by
kono
parents:
diff changeset
282 -- Initialize_Scanner, must not be subsequently altered.
kono
parents:
diff changeset
283
kono
parents:
diff changeset
284 -- The source file table is accessed by clients using the following
kono
parents:
diff changeset
285 -- subprogram interface:
kono
parents:
diff changeset
286
kono
parents:
diff changeset
287 subtype SFI is Source_File_Index;
kono
parents:
diff changeset
288
kono
parents:
diff changeset
289 System_Source_File_Index : SFI;
kono
parents:
diff changeset
290 -- The file system.ads is always read by the compiler to determine the
kono
parents:
diff changeset
291 -- settings of the target parameters in the private part of System. This
kono
parents:
diff changeset
292 -- variable records the source file index of system.ads. Typically this
kono
parents:
diff changeset
293 -- will be 1 since system.ads is read first.
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 function Debug_Source_Name (S : SFI) return File_Name_Type;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
296 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
297
111
kono
parents:
diff changeset
298 function File_Name (S : SFI) return File_Name_Type;
kono
parents:
diff changeset
299 function File_Type (S : SFI) return Type_Of_File;
kono
parents:
diff changeset
300 function First_Mapped_Line (S : SFI) return Logical_Line_Number;
kono
parents:
diff changeset
301 function Full_Debug_Name (S : SFI) return File_Name_Type;
kono
parents:
diff changeset
302 function Full_File_Name (S : SFI) return File_Name_Type;
kono
parents:
diff changeset
303 function Full_Ref_Name (S : SFI) return File_Name_Type;
kono
parents:
diff changeset
304 function Identifier_Casing (S : SFI) return Casing_Type;
kono
parents:
diff changeset
305 function Inlined_Body (S : SFI) return Boolean;
kono
parents:
diff changeset
306 function Inherited_Pragma (S : SFI) return Boolean;
kono
parents:
diff changeset
307 function Inlined_Call (S : SFI) return Source_Ptr;
kono
parents:
diff changeset
308 function Instance (S : SFI) return Instance_Id;
kono
parents:
diff changeset
309 function Keyword_Casing (S : SFI) return Casing_Type;
kono
parents:
diff changeset
310 function Last_Source_Line (S : SFI) return Physical_Line_Number;
kono
parents:
diff changeset
311 function License (S : SFI) return License_Type;
kono
parents:
diff changeset
312 function Num_SRef_Pragmas (S : SFI) return Nat;
kono
parents:
diff changeset
313 function Reference_Name (S : SFI) return File_Name_Type;
kono
parents:
diff changeset
314 function Source_Checksum (S : SFI) return Word;
kono
parents:
diff changeset
315 function Source_First (S : SFI) return Source_Ptr;
kono
parents:
diff changeset
316 function Source_Last (S : SFI) return Source_Ptr;
kono
parents:
diff changeset
317 function Source_Text (S : SFI) return Source_Buffer_Ptr;
kono
parents:
diff changeset
318 function Template (S : SFI) return Source_File_Index;
kono
parents:
diff changeset
319 function Unit (S : SFI) return Unit_Number_Type;
kono
parents:
diff changeset
320 function Time_Stamp (S : SFI) return Time_Stamp_Type;
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 procedure Set_Keyword_Casing (S : SFI; C : Casing_Type);
kono
parents:
diff changeset
323 procedure Set_Identifier_Casing (S : SFI; C : Casing_Type);
kono
parents:
diff changeset
324 procedure Set_License (S : SFI; L : License_Type);
kono
parents:
diff changeset
325 procedure Set_Unit (S : SFI; U : Unit_Number_Type);
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 function Last_Source_File return Source_File_Index;
kono
parents:
diff changeset
328 -- Index of last source file table entry
kono
parents:
diff changeset
329
kono
parents:
diff changeset
330 function Num_Source_Files return Nat;
kono
parents:
diff changeset
331 -- Number of source file table entries
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 procedure Initialize;
kono
parents:
diff changeset
334 -- Initialize internal tables
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 procedure Lock;
kono
parents:
diff changeset
337 -- Lock internal tables
kono
parents:
diff changeset
338
kono
parents:
diff changeset
339 procedure Unlock;
kono
parents:
diff changeset
340 -- Unlock internal tables
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 Main_Source_File : Source_File_Index := No_Source_File;
kono
parents:
diff changeset
343 -- This is set to the source file index of the main unit
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 -----------------------
kono
parents:
diff changeset
346 -- Checksum Handling --
kono
parents:
diff changeset
347 -----------------------
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 -- As a source file is scanned, a checksum is computed by taking all the
kono
parents:
diff changeset
350 -- non-blank characters in the file, excluding comment characters, the
kono
parents:
diff changeset
351 -- minus-minus sequence starting a comment, and all control characters
kono
parents:
diff changeset
352 -- except ESC.
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 -- The checksum algorithm used is the standard CRC-32 algorithm, as
kono
parents:
diff changeset
355 -- implemented by System.CRC32, except that we do not bother with the
kono
parents:
diff changeset
356 -- final XOR with all 1 bits.
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 -- This algorithm ensures that the checksum includes all semantically
kono
parents:
diff changeset
359 -- significant aspects of the program represented by the source file,
kono
parents:
diff changeset
360 -- but is insensitive to layout, presence or contents of comments, wide
kono
parents:
diff changeset
361 -- character representation method, or casing conventions outside strings.
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 -- Scans.Checksum is initialized appropriately at the start of scanning
kono
parents:
diff changeset
364 -- a file, and copied into the Source_Checksum field of the file table
kono
parents:
diff changeset
365 -- entry when the end of file is encountered.
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 -------------------------------------
kono
parents:
diff changeset
368 -- Handling Generic Instantiations --
kono
parents:
diff changeset
369 -------------------------------------
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 -- As described in Sem_Ch12, a generic instantiation involves making a
kono
parents:
diff changeset
372 -- copy of the tree of the generic template. The source locations in
kono
parents:
diff changeset
373 -- this tree directly reference the source of the template. However, it
kono
parents:
diff changeset
374 -- is also possible to find the location of the instantiation.
kono
parents:
diff changeset
375
kono
parents:
diff changeset
376 -- This is achieved as follows. When an instantiation occurs, a new entry
kono
parents:
diff changeset
377 -- is made in the source file table. The Source_Text of the instantiation
kono
parents:
diff changeset
378 -- points to the same Source_Buffer as the Source_Text of the template, but
kono
parents:
diff changeset
379 -- with different bounds. The separate range of Sloc values avoids
kono
parents:
diff changeset
380 -- confusion, and means that the Sloc values can still be used to uniquely
kono
parents:
diff changeset
381 -- identify the source file table entry. See Set_Dope below for the
kono
parents:
diff changeset
382 -- low-level trickery that allows two different pointers to point at the
kono
parents:
diff changeset
383 -- same array, but with different bounds.
kono
parents:
diff changeset
384
kono
parents:
diff changeset
385 -- The Instantiation_Id field of this source file index entry, set
kono
parents:
diff changeset
386 -- to No_Instance_Id for normal entries, instead contains a value that
kono
parents:
diff changeset
387 -- uniquely identifies a particular instantiation, and the associated
kono
parents:
diff changeset
388 -- entry in the Instances table. The source location of the instantiation
kono
parents:
diff changeset
389 -- can be retrieved using function Instantiation below. In the case of
kono
parents:
diff changeset
390 -- nested instantiations, the Instances table can be used to trace the
kono
parents:
diff changeset
391 -- complete chain of nested instantiations.
kono
parents:
diff changeset
392
kono
parents:
diff changeset
393 -- Two routines are used to build the special instance entries in the
kono
parents:
diff changeset
394 -- source file table. Create_Instantiation_Source is first called to build
kono
parents:
diff changeset
395 -- the virtual source table entry for the instantiation, and then the
kono
parents:
diff changeset
396 -- Sloc values in the copy are adjusted using Adjust_Instantiation_Sloc.
kono
parents:
diff changeset
397 -- See child unit Sinput.L for details on these two routines.
kono
parents:
diff changeset
398
kono
parents:
diff changeset
399 generic
kono
parents:
diff changeset
400 with procedure Process (Id : Instance_Id; Inst_Sloc : Source_Ptr);
kono
parents:
diff changeset
401 procedure Iterate_On_Instances;
kono
parents:
diff changeset
402 -- Execute Process for each entry in the instance table
kono
parents:
diff changeset
403
kono
parents:
diff changeset
404 function Instantiation (S : SFI) return Source_Ptr;
kono
parents:
diff changeset
405 -- For a source file entry that represents an inlined body, source location
kono
parents:
diff changeset
406 -- of the inlined call. For a source file entry that represents an
kono
parents:
diff changeset
407 -- inherited pragma, source location of the declaration to which the
kono
parents:
diff changeset
408 -- overriding subprogram for the inherited pragma is attached. Otherwise,
kono
parents:
diff changeset
409 -- for a source file entry that represents a generic instantiation, source
kono
parents:
diff changeset
410 -- location of the instantiation. Returns No_Location in all other cases.
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 -----------------
kono
parents:
diff changeset
413 -- Global Data --
kono
parents:
diff changeset
414 -----------------
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 Current_Source_File : Source_File_Index := No_Source_File;
kono
parents:
diff changeset
417 -- Source_File table index of source file currently being scanned.
kono
parents:
diff changeset
418 -- Initialized so that some tools (such as gprbuild) can be built with
kono
parents:
diff changeset
419 -- -gnatVa and pragma Initialize_Scalars without problems.
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 Current_Source_Unit : Unit_Number_Type;
kono
parents:
diff changeset
422 -- Unit number of source file currently being scanned. The special value
kono
parents:
diff changeset
423 -- of No_Unit indicates that the configuration pragma file is currently
kono
parents:
diff changeset
424 -- being scanned (this has no entry in the unit table).
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 Source_gnat_adc : Source_File_Index := No_Source_File;
kono
parents:
diff changeset
427 -- This is set if a gnat.adc file is present to reference this file
kono
parents:
diff changeset
428
kono
parents:
diff changeset
429 Source : Source_Buffer_Ptr;
kono
parents:
diff changeset
430 -- Current source (copy of Source_File.Table (Current_Source_Unit).Source)
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 -----------------------------------------
kono
parents:
diff changeset
433 -- Handling of Source Line Terminators --
kono
parents:
diff changeset
434 -----------------------------------------
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 -- In this section we discuss in detail the issue of terminators used to
kono
parents:
diff changeset
437 -- terminate source lines. The RM says that one or more format effectors
kono
parents:
diff changeset
438 -- (other than horizontal tab) end a source line, and defines the set of
kono
parents:
diff changeset
439 -- such format effectors, but does not talk about exactly how they are
kono
parents:
diff changeset
440 -- represented in the source program (since in general the RM is not in
kono
parents:
diff changeset
441 -- the business of specifying source program formats).
kono
parents:
diff changeset
442
kono
parents:
diff changeset
443 -- The type Types.Line_Terminator is defined as a subtype of Character
kono
parents:
diff changeset
444 -- that includes CR/LF/VT/FF. The most common line enders in practice
kono
parents:
diff changeset
445 -- are CR (some MAC systems), LF (Unix systems), and CR/LF (DOS/Windows
kono
parents:
diff changeset
446 -- systems). Any of these sequences is recognized as ending a physical
kono
parents:
diff changeset
447 -- source line, and if multiple such terminators appear (e.g. LF/LF),
kono
parents:
diff changeset
448 -- then we consider we have an extra blank line.
kono
parents:
diff changeset
449
kono
parents:
diff changeset
450 -- VT and FF are recognized as terminating source lines, but they are
kono
parents:
diff changeset
451 -- considered to end a logical line instead of a physical line, so that
kono
parents:
diff changeset
452 -- the line numbering ignores such terminators. The use of VT and FF is
kono
parents:
diff changeset
453 -- mandated by the standard, and correctly handled in a conforming manner
kono
parents:
diff changeset
454 -- by GNAT, but their use is not recommended.
kono
parents:
diff changeset
455
kono
parents:
diff changeset
456 -- In addition to the set of characters defined by the type in Types, in
kono
parents:
diff changeset
457 -- wide character encoding, then the codes returning True for a call to
kono
parents:
diff changeset
458 -- System.UTF_32.Is_UTF_32_Line_Terminator are also recognized as ending a
kono
parents:
diff changeset
459 -- source line. This includes the standard codes defined above in addition
kono
parents:
diff changeset
460 -- to NEL (NEXT LINE), LINE SEPARATOR and PARAGRAPH SEPARATOR. Again, as in
kono
parents:
diff changeset
461 -- the case of VT and FF, the standard requires we recognize these as line
kono
parents:
diff changeset
462 -- terminators, but we consider them to be logical line terminators. The
kono
parents:
diff changeset
463 -- only physical line terminators recognized are the standard ones (CR,
kono
parents:
diff changeset
464 -- LF, or CR/LF).
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 -- However, we do not recognize the NEL (16#85#) character as having the
kono
parents:
diff changeset
467 -- significance of an end of line character when operating in normal 8-bit
kono
parents:
diff changeset
468 -- Latin-n input mode for the compiler. Instead the rule in this mode is
kono
parents:
diff changeset
469 -- that all upper half control codes (16#80# .. 16#9F#) are illegal if they
kono
parents:
diff changeset
470 -- occur in program text, and are ignored if they appear in comments.
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472 -- First, note that this behavior is fully conforming with the standard.
kono
parents:
diff changeset
473 -- The standard has nothing whatever to say about source representation
kono
parents:
diff changeset
474 -- and implementations are completely free to make there own rules. In
kono
parents:
diff changeset
475 -- this case, in 8-bit mode, GNAT decides that the 16#0085# character is
kono
parents:
diff changeset
476 -- not a representation of the NEL character, even though it looks like it.
kono
parents:
diff changeset
477 -- If you have NEL's in your program, which you expect to be treated as
kono
parents:
diff changeset
478 -- end of line characters, you must use a wide character encoding such as
kono
parents:
diff changeset
479 -- UTF-8 for this code to be recognized.
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 -- Second, an explanation of why we take this slightly surprising choice.
kono
parents:
diff changeset
482 -- We have never encountered anyone actually using the NEL character to
kono
parents:
diff changeset
483 -- end lines. One user raised the issue as a result of some experiments,
kono
parents:
diff changeset
484 -- but no one has ever submitted a program encoded this way, in any of
kono
parents:
diff changeset
485 -- the possible encodings. It seems that even when using wide character
kono
parents:
diff changeset
486 -- codes extensively, the normal approach is to use standard line enders
kono
parents:
diff changeset
487 -- (LF or CR/LF). So the failure to recognize NEL in this mode seems to
kono
parents:
diff changeset
488 -- have no practical downside.
kono
parents:
diff changeset
489
kono
parents:
diff changeset
490 -- Moreover, what we have seen in a significant number of programs from
kono
parents:
diff changeset
491 -- multiple sources is the practice of writing all program text in lower
kono
parents:
diff changeset
492 -- half (ASCII) form, but using UTF-8 encoded wide characters freely in
kono
parents:
diff changeset
493 -- comments, where the comments are terminated by normal line endings
kono
parents:
diff changeset
494 -- (LF or CR/LF). The comments do not contain NEL codes, but they can and
kono
parents:
diff changeset
495 -- do contain other UTF-8 encoding sequences where one of the bytes is the
kono
parents:
diff changeset
496 -- NEL code. Now such programs can of course be compiled in UTF-8 mode,
kono
parents:
diff changeset
497 -- but in practice they also compile fine in standard 8-bit mode without
kono
parents:
diff changeset
498 -- specifying a character encoding. Since this is common practice, it would
kono
parents:
diff changeset
499 -- be a significant upwards incompatibility to recognize NEL in 8-bit mode.
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 -----------------
kono
parents:
diff changeset
502 -- Subprograms --
kono
parents:
diff changeset
503 -----------------
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 procedure Backup_Line (P : in out Source_Ptr);
kono
parents:
diff changeset
506 -- Back up the argument pointer to the start of the previous line. On
kono
parents:
diff changeset
507 -- entry, P points to the start of a physical line in the source buffer.
kono
parents:
diff changeset
508 -- On return, P is updated to point to the start of the previous line.
kono
parents:
diff changeset
509 -- The caller has checked that a Line_Terminator character precedes P so
kono
parents:
diff changeset
510 -- that there definitely is a previous line in the source buffer.
kono
parents:
diff changeset
511
kono
parents:
diff changeset
512 procedure Build_Location_String
kono
parents:
diff changeset
513 (Buf : in out Bounded_String;
kono
parents:
diff changeset
514 Loc : Source_Ptr);
kono
parents:
diff changeset
515 -- This function builds a string literal of the form "name:line", where
kono
parents:
diff changeset
516 -- name is the file name corresponding to Loc, and line is the line number.
kono
parents:
diff changeset
517 -- If instantiations are involved, additional suffixes of the same form are
kono
parents:
diff changeset
518 -- appended after the separating string " instantiated at ". The returned
kono
parents:
diff changeset
519 -- string is appended to Buf.
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 function Build_Location_String (Loc : Source_Ptr) return String;
kono
parents:
diff changeset
522 -- Functional form returning a String
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524 procedure Check_For_BOM;
kono
parents:
diff changeset
525 -- Check if the current source starts with a BOM. Scan_Ptr needs to be at
kono
parents:
diff changeset
526 -- the start of the current source. If the current source starts with a
kono
parents:
diff changeset
527 -- recognized BOM, then some flags such as Wide_Character_Encoding_Method
kono
parents:
diff changeset
528 -- are set accordingly, and the Scan_Ptr on return points past this BOM.
kono
parents:
diff changeset
529 -- An error message is output and Unrecoverable_Error raised if an
kono
parents:
diff changeset
530 -- unrecognized BOM is detected. The call has no effect if no BOM is found.
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 function Get_Column_Number (P : Source_Ptr) return Column_Number;
kono
parents:
diff changeset
533 -- The ones-origin column number of the specified Source_Ptr value is
kono
parents:
diff changeset
534 -- determined and returned. Tab characters if present are assumed to
kono
parents:
diff changeset
535 -- represent the standard 1,9,17.. spacing pattern.
kono
parents:
diff changeset
536
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
537 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
538
111
kono
parents:
diff changeset
539 function Get_Logical_Line_Number
kono
parents:
diff changeset
540 (P : Source_Ptr) return Logical_Line_Number;
kono
parents:
diff changeset
541 -- The line number of the specified source position is obtained by
kono
parents:
diff changeset
542 -- doing a binary search on the source positions in the lines table
kono
parents:
diff changeset
543 -- for the unit containing the given source position. The returned
kono
parents:
diff changeset
544 -- value is the logical line number, already adjusted for the effect
kono
parents:
diff changeset
545 -- of source reference pragmas. If P refers to the line of a source
kono
parents:
diff changeset
546 -- reference pragma itself, then No_Line is returned. If no source
kono
parents:
diff changeset
547 -- reference pragmas have been encountered, the value returned is
kono
parents:
diff changeset
548 -- the same as the physical line number.
kono
parents:
diff changeset
549
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
550 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
551
111
kono
parents:
diff changeset
552 function Get_Logical_Line_Number_Img
kono
parents:
diff changeset
553 (P : Source_Ptr) return String;
kono
parents:
diff changeset
554 -- Same as above function, but returns the line number as a string of
kono
parents:
diff changeset
555 -- decimal digits, with no leading space. Destroys Name_Buffer.
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 function Get_Physical_Line_Number
kono
parents:
diff changeset
558 (P : Source_Ptr) return Physical_Line_Number;
kono
parents:
diff changeset
559 -- The line number of the specified source position is obtained by
kono
parents:
diff changeset
560 -- doing a binary search on the source positions in the lines table
kono
parents:
diff changeset
561 -- for the unit containing the given source position. The returned
kono
parents:
diff changeset
562 -- value is the physical line number in the source being compiled.
kono
parents:
diff changeset
563
kono
parents:
diff changeset
564 function Get_Source_File_Index (S : Source_Ptr) return Source_File_Index;
kono
parents:
diff changeset
565 pragma Inline (Get_Source_File_Index);
kono
parents:
diff changeset
566 -- Return file table index of file identified by given source pointer
kono
parents:
diff changeset
567 -- value. This call must always succeed, since any valid source pointer
kono
parents:
diff changeset
568 -- value belongs to some previously loaded source file.
kono
parents:
diff changeset
569
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
570 -- WARNING: There is a matching C declaration of this subprogram in fe.h
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
571
111
kono
parents:
diff changeset
572 function Instantiation_Depth (S : Source_Ptr) return Nat;
kono
parents:
diff changeset
573 -- Determine instantiation depth for given Sloc value. A value of
kono
parents:
diff changeset
574 -- zero means that the given Sloc is not in an instantiation.
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 function Line_Start (P : Source_Ptr) return Source_Ptr;
kono
parents:
diff changeset
577 -- Finds the source position of the start of the line containing the
kono
parents:
diff changeset
578 -- given source location.
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 function Line_Start
kono
parents:
diff changeset
581 (L : Physical_Line_Number;
kono
parents:
diff changeset
582 S : Source_File_Index) return Source_Ptr;
kono
parents:
diff changeset
583 -- Finds the source position of the start of the given line in the
kono
parents:
diff changeset
584 -- given source file, using a physical line number to identify the line.
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 function Num_Source_Lines (S : Source_File_Index) return Nat;
kono
parents:
diff changeset
587 -- Returns the number of source lines (this is equivalent to reading
kono
parents:
diff changeset
588 -- the value of Last_Source_Line, but returns Nat rather than a
kono
parents:
diff changeset
589 -- physical line number).
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 procedure Register_Source_Ref_Pragma
kono
parents:
diff changeset
592 (File_Name : File_Name_Type;
kono
parents:
diff changeset
593 Stripped_File_Name : File_Name_Type;
kono
parents:
diff changeset
594 Mapped_Line : Nat;
kono
parents:
diff changeset
595 Line_After_Pragma : Physical_Line_Number);
kono
parents:
diff changeset
596 -- Register a source reference pragma, the parameter File_Name is the
kono
parents:
diff changeset
597 -- file name from the pragma, and Stripped_File_Name is this name with
kono
parents:
diff changeset
598 -- the directory information stripped. Both these parameters are set
kono
parents:
diff changeset
599 -- to No_Name if no file name parameter was given in the pragma.
kono
parents:
diff changeset
600 -- (which can only happen for the second and subsequent pragmas).
kono
parents:
diff changeset
601 -- Mapped_Line is the line number parameter from the pragma, and
kono
parents:
diff changeset
602 -- Line_After_Pragma is the physical line number of the line that
kono
parents:
diff changeset
603 -- follows the line containing the Source_Reference pragma.
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 function Original_Location (S : Source_Ptr) return Source_Ptr;
kono
parents:
diff changeset
606 -- Given a source pointer S, returns the corresponding source pointer
kono
parents:
diff changeset
607 -- value ignoring instantiation copies. For locations that do not
kono
parents:
diff changeset
608 -- correspond to instantiation copies of templates, the argument is
kono
parents:
diff changeset
609 -- returned unchanged. For locations that do correspond to copies of
kono
parents:
diff changeset
610 -- templates from instantiations, the location within the original
kono
parents:
diff changeset
611 -- template is returned. This is useful in canonicalizing locations.
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 function Instantiation_Location (S : Source_Ptr) return Source_Ptr;
kono
parents:
diff changeset
614 pragma Inline (Instantiation_Location);
kono
parents:
diff changeset
615 -- Given a source pointer S, returns the corresponding source pointer
kono
parents:
diff changeset
616 -- value of the instantiation if this location is within an instance.
kono
parents:
diff changeset
617 -- If S is not within an instance, then this returns No_Location.
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 function Comes_From_Inlined_Body (S : Source_Ptr) return Boolean;
kono
parents:
diff changeset
620 pragma Inline (Comes_From_Inlined_Body);
kono
parents:
diff changeset
621 -- Given a source pointer S, returns whether it comes from an inlined body.
kono
parents:
diff changeset
622 -- This allows distinguishing these source pointers from those that come
kono
parents:
diff changeset
623 -- from instantiation of generics, since Instantiation_Location returns a
kono
parents:
diff changeset
624 -- valid location in both cases.
kono
parents:
diff changeset
625
kono
parents:
diff changeset
626 function Comes_From_Inherited_Pragma (S : Source_Ptr) return Boolean;
kono
parents:
diff changeset
627 pragma Inline (Comes_From_Inherited_Pragma);
kono
parents:
diff changeset
628 -- Given a source pointer S, returns whether it comes from an inherited
kono
parents:
diff changeset
629 -- pragma. This allows distinguishing these source pointers from those
kono
parents:
diff changeset
630 -- that come from instantiation of generics, since Instantiation_Location
kono
parents:
diff changeset
631 -- returns a valid location in both cases.
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 function Top_Level_Location (S : Source_Ptr) return Source_Ptr;
kono
parents:
diff changeset
634 -- Given a source pointer S, returns the argument unchanged if it is
kono
parents:
diff changeset
635 -- not in an instantiation. If S is in an instantiation, then it returns
kono
parents:
diff changeset
636 -- the location of the top level instantiation, i.e. the outer level
kono
parents:
diff changeset
637 -- instantiation in the nested case.
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 function Physical_To_Logical
kono
parents:
diff changeset
640 (Line : Physical_Line_Number;
kono
parents:
diff changeset
641 S : Source_File_Index) return Logical_Line_Number;
kono
parents:
diff changeset
642 -- Given a physical line number in source file whose source index is S,
kono
parents:
diff changeset
643 -- return the corresponding logical line number. If the physical line
kono
parents:
diff changeset
644 -- number is one containing a Source_Reference pragma, the result will
kono
parents:
diff changeset
645 -- be No_Line_Number.
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 procedure Skip_Line_Terminators
kono
parents:
diff changeset
648 (P : in out Source_Ptr;
kono
parents:
diff changeset
649 Physical : out Boolean);
kono
parents:
diff changeset
650 -- On entry, P points to a line terminator that has been encountered,
kono
parents:
diff changeset
651 -- which is one of FF,LF,VT,CR or a wide character sequence whose value is
kono
parents:
diff changeset
652 -- in category Separator,Line or Separator,Paragraph. P points just past
kono
parents:
diff changeset
653 -- the character that was scanned. The purpose of this routine is to
kono
parents:
diff changeset
654 -- distinguish physical and logical line endings. A physical line ending
kono
parents:
diff changeset
655 -- is one of:
kono
parents:
diff changeset
656 --
kono
parents:
diff changeset
657 -- CR on its own (MAC System 7)
kono
parents:
diff changeset
658 -- LF on its own (Unix and unix-like systems)
kono
parents:
diff changeset
659 -- CR/LF (DOS, Windows)
kono
parents:
diff changeset
660 -- Wide character in Separator,Line or Separator,Paragraph category
kono
parents:
diff changeset
661 --
kono
parents:
diff changeset
662 -- Note: we no longer recognize LF/CR (which we did in some earlier
kono
parents:
diff changeset
663 -- versions of GNAT. The reason for this is that this sequence is not
kono
parents:
diff changeset
664 -- used and recognizing it generated confusion. For example given the
kono
parents:
diff changeset
665 -- sequence LF/CR/LF we were interpreting that as (LF/CR) ending the
kono
parents:
diff changeset
666 -- first line and a blank line ending with CR following, but it is
kono
parents:
diff changeset
667 -- clearly better to interpret this as LF, with a blank line terminated
kono
parents:
diff changeset
668 -- by CR/LF, given that LF and CR/LF are both in common use, but no
kono
parents:
diff changeset
669 -- system we know of uses LF/CR.
kono
parents:
diff changeset
670 --
kono
parents:
diff changeset
671 -- A logical line ending (that is not a physical line ending) is one of:
kono
parents:
diff changeset
672 --
kono
parents:
diff changeset
673 -- VT on its own
kono
parents:
diff changeset
674 -- FF on its own
kono
parents:
diff changeset
675 --
kono
parents:
diff changeset
676 -- On return, P is bumped past the line ending sequence (one of the above
kono
parents:
diff changeset
677 -- seven possibilities). Physical is set to True to indicate that a
kono
parents:
diff changeset
678 -- physical end of line was encountered, in which case this routine also
kono
parents:
diff changeset
679 -- makes sure that the lines table for the current source file has an
kono
parents:
diff changeset
680 -- appropriate entry for the start of the new physical line.
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 procedure Sloc_Range (N : Node_Id; Min, Max : out Source_Ptr);
kono
parents:
diff changeset
683 -- Given a node, returns the minimum and maximum source locations of any
kono
parents:
diff changeset
684 -- node in the syntactic subtree for the node. This is not quite the same
kono
parents:
diff changeset
685 -- as the locations of the first and last token in the node construct
kono
parents:
diff changeset
686 -- because parentheses at the outer level do not have a recorded Sloc.
kono
parents:
diff changeset
687 --
kono
parents:
diff changeset
688 -- Note: At each step of the tree traversal, we make sure to go back to
kono
parents:
diff changeset
689 -- the Original_Node, since this function is concerned about original
kono
parents:
diff changeset
690 -- (source) locations.
kono
parents:
diff changeset
691 --
kono
parents:
diff changeset
692 -- Note: if the tree for the expression contains no "real" Sloc values,
kono
parents:
diff changeset
693 -- i.e. values > No_Location, then both Min and Max are set to
kono
parents:
diff changeset
694 -- Sloc (Original_Node (N)).
kono
parents:
diff changeset
695
kono
parents:
diff changeset
696 function Source_Offset (S : Source_Ptr) return Nat;
kono
parents:
diff changeset
697 -- Returns the zero-origin offset of the given source location from the
kono
parents:
diff changeset
698 -- start of its corresponding unit. This is used for creating canonical
kono
parents:
diff changeset
699 -- names in some situations.
kono
parents:
diff changeset
700
kono
parents:
diff changeset
701 procedure Write_Location (P : Source_Ptr);
kono
parents:
diff changeset
702 -- Writes out a string of the form fff:nn:cc, where fff, nn, cc are the
kono
parents:
diff changeset
703 -- file name, line number and column corresponding to the given source
kono
parents:
diff changeset
704 -- location. No_Location and Standard_Location appear as the strings
kono
parents:
diff changeset
705 -- <no location> and <standard location>. If the location is within an
kono
parents:
diff changeset
706 -- instantiation, then the instance location is appended, enclosed in
kono
parents:
diff changeset
707 -- square brackets (which can nest if necessary). Note that this routine
kono
parents:
diff changeset
708 -- is used only for internal compiler debugging output purposes (which
kono
parents:
diff changeset
709 -- is why the somewhat cryptic use of brackets is acceptable).
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 procedure wl (P : Source_Ptr);
kono
parents:
diff changeset
712 pragma Export (Ada, wl);
kono
parents:
diff changeset
713 -- Equivalent to Write_Location (P); Write_Eol; for calls from GDB
kono
parents:
diff changeset
714
kono
parents:
diff changeset
715 procedure Write_Time_Stamp (S : Source_File_Index);
kono
parents:
diff changeset
716 -- Writes time stamp of specified file in YY-MM-DD HH:MM.SS format
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 procedure Tree_Read;
kono
parents:
diff changeset
719 -- Initializes internal tables from current tree file using the relevant
kono
parents:
diff changeset
720 -- Table.Tree_Read routines.
kono
parents:
diff changeset
721
kono
parents:
diff changeset
722 procedure Tree_Write;
kono
parents:
diff changeset
723 -- Writes out internal tables to current tree file using the relevant
kono
parents:
diff changeset
724 -- Table.Tree_Write routines.
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 procedure Clear_Source_File_Table;
kono
parents:
diff changeset
727 -- This procedure frees memory allocated in the Source_File table (in the
kono
parents:
diff changeset
728 -- private). It should only be used when it is guaranteed that all source
kono
parents:
diff changeset
729 -- files that have been loaded so far will not be accessed before being
kono
parents:
diff changeset
730 -- reloaded. It is intended for tools that parse several times sources,
kono
parents:
diff changeset
731 -- to avoid memory leaks.
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 private
kono
parents:
diff changeset
734 pragma Inline (File_Name);
kono
parents:
diff changeset
735 pragma Inline (Full_File_Name);
kono
parents:
diff changeset
736 pragma Inline (File_Type);
kono
parents:
diff changeset
737 pragma Inline (Reference_Name);
kono
parents:
diff changeset
738 pragma Inline (Full_Ref_Name);
kono
parents:
diff changeset
739 pragma Inline (Debug_Source_Name);
kono
parents:
diff changeset
740 pragma Inline (Full_Debug_Name);
kono
parents:
diff changeset
741 pragma Inline (Instance);
kono
parents:
diff changeset
742 pragma Inline (License);
kono
parents:
diff changeset
743 pragma Inline (Num_SRef_Pragmas);
kono
parents:
diff changeset
744 pragma Inline (First_Mapped_Line);
kono
parents:
diff changeset
745 pragma Inline (Source_Text);
kono
parents:
diff changeset
746 pragma Inline (Source_First);
kono
parents:
diff changeset
747 pragma Inline (Source_Last);
kono
parents:
diff changeset
748 pragma Inline (Time_Stamp);
kono
parents:
diff changeset
749 pragma Inline (Source_Checksum);
kono
parents:
diff changeset
750 pragma Inline (Last_Source_Line);
kono
parents:
diff changeset
751 pragma Inline (Keyword_Casing);
kono
parents:
diff changeset
752 pragma Inline (Identifier_Casing);
kono
parents:
diff changeset
753 pragma Inline (Inlined_Call);
kono
parents:
diff changeset
754 pragma Inline (Inlined_Body);
kono
parents:
diff changeset
755 pragma Inline (Inherited_Pragma);
kono
parents:
diff changeset
756 pragma Inline (Template);
kono
parents:
diff changeset
757 pragma Inline (Unit);
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 pragma Inline (Set_Keyword_Casing);
kono
parents:
diff changeset
760 pragma Inline (Set_Identifier_Casing);
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 pragma Inline (Last_Source_File);
kono
parents:
diff changeset
763 pragma Inline (Num_Source_Files);
kono
parents:
diff changeset
764 pragma Inline (Num_Source_Lines);
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 pragma Inline (Line_Start);
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 No_Instance_Id : constant Instance_Id := 0;
kono
parents:
diff changeset
769
kono
parents:
diff changeset
770 -------------------------
kono
parents:
diff changeset
771 -- Source_Lines Tables --
kono
parents:
diff changeset
772 -------------------------
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 type Lines_Table_Type is
kono
parents:
diff changeset
775 array (Physical_Line_Number) of Source_Ptr;
kono
parents:
diff changeset
776 -- Type used for lines table. The entries are indexed by physical line
kono
parents:
diff changeset
777 -- numbers. The values are the starting Source_Ptr values for the start
kono
parents:
diff changeset
778 -- of the corresponding physical line. Note that we make this a bogus
kono
parents:
diff changeset
779 -- big array, sized as required, so that we avoid the use of fat pointers.
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 type Lines_Table_Ptr is access all Lines_Table_Type;
kono
parents:
diff changeset
782 -- Type used for pointers to line tables
kono
parents:
diff changeset
783
kono
parents:
diff changeset
784 type Logical_Lines_Table_Type is
kono
parents:
diff changeset
785 array (Physical_Line_Number) of Logical_Line_Number;
kono
parents:
diff changeset
786 -- Type used for logical lines table. This table is used if a source
kono
parents:
diff changeset
787 -- reference pragma is present. It is indexed by physical line numbers,
kono
parents:
diff changeset
788 -- and contains the corresponding logical line numbers. An entry that
kono
parents:
diff changeset
789 -- corresponds to a source reference pragma is set to No_Line_Number.
kono
parents:
diff changeset
790 -- Note that we make this a bogus big array, sized as required, so that
kono
parents:
diff changeset
791 -- we avoid the use of fat pointers.
kono
parents:
diff changeset
792
kono
parents:
diff changeset
793 type Logical_Lines_Table_Ptr is access all Logical_Lines_Table_Type;
kono
parents:
diff changeset
794 -- Type used for pointers to logical line tables
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 -----------------------
kono
parents:
diff changeset
797 -- Source_File Table --
kono
parents:
diff changeset
798 -----------------------
kono
parents:
diff changeset
799
kono
parents:
diff changeset
800 -- See earlier descriptions for meanings of public fields
kono
parents:
diff changeset
801
kono
parents:
diff changeset
802 type Source_File_Record is record
kono
parents:
diff changeset
803 File_Name : File_Name_Type;
kono
parents:
diff changeset
804 Reference_Name : File_Name_Type;
kono
parents:
diff changeset
805 Debug_Source_Name : File_Name_Type;
kono
parents:
diff changeset
806 Full_Debug_Name : File_Name_Type;
kono
parents:
diff changeset
807 Full_File_Name : File_Name_Type;
kono
parents:
diff changeset
808 Full_Ref_Name : File_Name_Type;
kono
parents:
diff changeset
809 Instance : Instance_Id;
kono
parents:
diff changeset
810 Num_SRef_Pragmas : Nat;
kono
parents:
diff changeset
811 First_Mapped_Line : Logical_Line_Number;
kono
parents:
diff changeset
812 Source_Text : Source_Buffer_Ptr;
kono
parents:
diff changeset
813 Source_First : Source_Ptr;
kono
parents:
diff changeset
814 Source_Last : Source_Ptr;
kono
parents:
diff changeset
815 Source_Checksum : Word;
kono
parents:
diff changeset
816 Last_Source_Line : Physical_Line_Number;
kono
parents:
diff changeset
817 Template : Source_File_Index;
kono
parents:
diff changeset
818 Unit : Unit_Number_Type;
kono
parents:
diff changeset
819 Time_Stamp : Time_Stamp_Type;
kono
parents:
diff changeset
820 File_Type : Type_Of_File;
kono
parents:
diff changeset
821 Inlined_Call : Source_Ptr;
kono
parents:
diff changeset
822 Inlined_Body : Boolean;
kono
parents:
diff changeset
823 Inherited_Pragma : Boolean;
kono
parents:
diff changeset
824 License : License_Type;
kono
parents:
diff changeset
825 Keyword_Casing : Casing_Type;
kono
parents:
diff changeset
826 Identifier_Casing : Casing_Type;
kono
parents:
diff changeset
827
kono
parents:
diff changeset
828 -- The following fields are for internal use only (i.e. only in the
kono
parents:
diff changeset
829 -- body of Sinput or its children, with no direct access by clients).
kono
parents:
diff changeset
830
kono
parents:
diff changeset
831 Sloc_Adjust : Source_Ptr;
kono
parents:
diff changeset
832 -- A value to be added to Sloc values for this file to reference the
kono
parents:
diff changeset
833 -- corresponding lines table. This is zero for the non-instantiation
kono
parents:
diff changeset
834 -- case, and set so that the addition references the ultimate template
kono
parents:
diff changeset
835 -- for the instantiation case. See Sinput-L for further details.
kono
parents:
diff changeset
836
kono
parents:
diff changeset
837 Lines_Table : Lines_Table_Ptr;
kono
parents:
diff changeset
838 -- Pointer to lines table for this source. Updated as additional
kono
parents:
diff changeset
839 -- lines are accessed using the Skip_Line_Terminators procedure.
kono
parents:
diff changeset
840 -- Note: the lines table for an instantiation entry refers to the
kono
parents:
diff changeset
841 -- original line numbers of the template see Sinput-L for details.
kono
parents:
diff changeset
842
kono
parents:
diff changeset
843 Logical_Lines_Table : Logical_Lines_Table_Ptr;
kono
parents:
diff changeset
844 -- Pointer to logical lines table for this source. Non-null only if
kono
parents:
diff changeset
845 -- a source reference pragma has been processed. Updated as lines
kono
parents:
diff changeset
846 -- are accessed using the Skip_Line_Terminators procedure.
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 Lines_Table_Max : Physical_Line_Number;
kono
parents:
diff changeset
849 -- Maximum subscript values for currently allocated Lines_Table
kono
parents:
diff changeset
850 -- and (if present) the allocated Logical_Lines_Table. The value
kono
parents:
diff changeset
851 -- Max_Source_Line gives the maximum used value, this gives the
kono
parents:
diff changeset
852 -- maximum allocated value.
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 Index : Source_File_Index := 123456789; -- for debugging
kono
parents:
diff changeset
855 end record;
kono
parents:
diff changeset
856
kono
parents:
diff changeset
857 -- The following representation clause ensures that the above record
kono
parents:
diff changeset
858 -- has no holes. We do this so that when instances of this record are
kono
parents:
diff changeset
859 -- written by Tree_Gen, we do not write uninitialized values to the file.
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 AS : constant Pos := Standard'Address_Size;
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 for Source_File_Record use record
kono
parents:
diff changeset
864 File_Name at 0 range 0 .. 31;
kono
parents:
diff changeset
865 Reference_Name at 4 range 0 .. 31;
kono
parents:
diff changeset
866 Debug_Source_Name at 8 range 0 .. 31;
kono
parents:
diff changeset
867 Full_Debug_Name at 12 range 0 .. 31;
kono
parents:
diff changeset
868 Full_File_Name at 16 range 0 .. 31;
kono
parents:
diff changeset
869 Full_Ref_Name at 20 range 0 .. 31;
kono
parents:
diff changeset
870 Instance at 48 range 0 .. 31;
kono
parents:
diff changeset
871 Num_SRef_Pragmas at 24 range 0 .. 31;
kono
parents:
diff changeset
872 First_Mapped_Line at 28 range 0 .. 31;
kono
parents:
diff changeset
873 Source_First at 32 range 0 .. 31;
kono
parents:
diff changeset
874 Source_Last at 36 range 0 .. 31;
kono
parents:
diff changeset
875 Source_Checksum at 40 range 0 .. 31;
kono
parents:
diff changeset
876 Last_Source_Line at 44 range 0 .. 31;
kono
parents:
diff changeset
877 Template at 52 range 0 .. 31;
kono
parents:
diff changeset
878 Unit at 56 range 0 .. 31;
kono
parents:
diff changeset
879 Time_Stamp at 60 range 0 .. 8 * Time_Stamp_Length - 1;
kono
parents:
diff changeset
880 File_Type at 74 range 0 .. 7;
kono
parents:
diff changeset
881 Inlined_Call at 88 range 0 .. 31;
kono
parents:
diff changeset
882 Inlined_Body at 75 range 0 .. 0;
kono
parents:
diff changeset
883 Inherited_Pragma at 75 range 1 .. 1;
kono
parents:
diff changeset
884 License at 76 range 0 .. 7;
kono
parents:
diff changeset
885 Keyword_Casing at 77 range 0 .. 7;
kono
parents:
diff changeset
886 Identifier_Casing at 78 range 0 .. 15;
kono
parents:
diff changeset
887 Sloc_Adjust at 80 range 0 .. 31;
kono
parents:
diff changeset
888 Lines_Table_Max at 84 range 0 .. 31;
kono
parents:
diff changeset
889 Index at 92 range 0 .. 31;
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 -- The following fields are pointers, so we have to specialize their
kono
parents:
diff changeset
892 -- lengths using pointer size, obtained above as Standard'Address_Size.
kono
parents:
diff changeset
893 -- Note that Source_Text is a fat pointer, so it has size = AS*2.
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 Source_Text at 96 range 0 .. AS * 2 - 1;
kono
parents:
diff changeset
896 Lines_Table at 96 range AS * 2 .. AS * 3 - 1;
kono
parents:
diff changeset
897 Logical_Lines_Table at 96 range AS * 3 .. AS * 4 - 1;
kono
parents:
diff changeset
898 end record; -- Source_File_Record
kono
parents:
diff changeset
899
kono
parents:
diff changeset
900 for Source_File_Record'Size use 96 * 8 + AS * 4;
kono
parents:
diff changeset
901 -- This ensures that we did not leave out any fields
kono
parents:
diff changeset
902
kono
parents:
diff changeset
903 package Source_File is new Table.Table
kono
parents:
diff changeset
904 (Table_Component_Type => Source_File_Record,
kono
parents:
diff changeset
905 Table_Index_Type => Source_File_Index,
kono
parents:
diff changeset
906 Table_Low_Bound => 1,
kono
parents:
diff changeset
907 Table_Initial => Alloc.Source_File_Initial,
kono
parents:
diff changeset
908 Table_Increment => Alloc.Source_File_Increment,
kono
parents:
diff changeset
909 Table_Name => "Source_File");
kono
parents:
diff changeset
910
kono
parents:
diff changeset
911 -- Auxiliary table containing source location of instantiations. Index 0
kono
parents:
diff changeset
912 -- is used for code that does not come from an instance.
kono
parents:
diff changeset
913
kono
parents:
diff changeset
914 package Instances is new Table.Table
kono
parents:
diff changeset
915 (Table_Component_Type => Source_Ptr,
kono
parents:
diff changeset
916 Table_Index_Type => Instance_Id,
kono
parents:
diff changeset
917 Table_Low_Bound => 0,
kono
parents:
diff changeset
918 Table_Initial => Alloc.Source_File_Initial,
kono
parents:
diff changeset
919 Table_Increment => Alloc.Source_File_Increment,
kono
parents:
diff changeset
920 Table_Name => "Instances");
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922 -----------------
kono
parents:
diff changeset
923 -- Subprograms --
kono
parents:
diff changeset
924 -----------------
kono
parents:
diff changeset
925
kono
parents:
diff changeset
926 procedure Alloc_Line_Tables
kono
parents:
diff changeset
927 (S : in out Source_File_Record;
kono
parents:
diff changeset
928 New_Max : Nat);
kono
parents:
diff changeset
929 -- Allocate or reallocate the lines table for the given source file so
kono
parents:
diff changeset
930 -- that it can accommodate at least New_Max lines. Also allocates or
kono
parents:
diff changeset
931 -- reallocates logical lines table if source ref pragmas are present.
kono
parents:
diff changeset
932
kono
parents:
diff changeset
933 procedure Add_Line_Tables_Entry
kono
parents:
diff changeset
934 (S : in out Source_File_Record;
kono
parents:
diff changeset
935 P : Source_Ptr);
kono
parents:
diff changeset
936 -- Increment line table size by one (reallocating the lines table if
kono
parents:
diff changeset
937 -- needed) and set the new entry to contain the value P. Also bumps
kono
parents:
diff changeset
938 -- the Source_Line_Count field. If source reference pragmas are
kono
parents:
diff changeset
939 -- present, also increments logical lines table size by one, and
kono
parents:
diff changeset
940 -- sets new entry.
kono
parents:
diff changeset
941
kono
parents:
diff changeset
942 procedure Trim_Lines_Table (S : Source_File_Index);
kono
parents:
diff changeset
943 -- Set lines table size for entry S in the source file table to
kono
parents:
diff changeset
944 -- correspond to the current value of Num_Source_Lines, releasing
kono
parents:
diff changeset
945 -- any unused storage. This is used by Sinput.L and Sinput.D.
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947 procedure Set_Source_File_Index_Table (Xnew : Source_File_Index);
kono
parents:
diff changeset
948 -- Sets entries in the Source_File_Index_Table for the newly created
kono
parents:
diff changeset
949 -- Source_File table entry whose index is Xnew. The Source_First and
kono
parents:
diff changeset
950 -- Source_Last fields of this entry must be set before the call.
kono
parents:
diff changeset
951 -- See package body for details.
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 type Dope_Rec is record
kono
parents:
diff changeset
954 First, Last : Source_Ptr'Base;
kono
parents:
diff changeset
955 end record;
kono
parents:
diff changeset
956 Dope_Rec_Size : constant := 2 * Source_Ptr'Base'Size;
kono
parents:
diff changeset
957 for Dope_Rec'Size use Dope_Rec_Size;
kono
parents:
diff changeset
958 for Dope_Rec'Alignment use Dope_Rec_Size / 8;
kono
parents:
diff changeset
959 type Dope_Ptr is access all Dope_Rec;
kono
parents:
diff changeset
960
kono
parents:
diff changeset
961 procedure Set_Dope
kono
parents:
diff changeset
962 (Src : System.Address; New_Dope : Dope_Ptr);
kono
parents:
diff changeset
963 -- Src is the address of a variable of type Source_Buffer_Ptr, which is a
kono
parents:
diff changeset
964 -- fat pointer. This sets the dope part of the fat pointer to point to the
kono
parents:
diff changeset
965 -- specified New_Dope. This low-level processing is used to make the
kono
parents:
diff changeset
966 -- Source_Text of an instance point to the same text as the template, but
kono
parents:
diff changeset
967 -- with different bounds.
kono
parents:
diff changeset
968
kono
parents:
diff changeset
969 procedure Free_Dope (Src : System.Address);
kono
parents:
diff changeset
970 -- Calls Unchecked_Deallocation on the dope part of the fat pointer Src
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 procedure Free_Source_Buffer (Src : in out Source_Buffer_Ptr);
kono
parents:
diff changeset
973 -- Deallocates the source buffer
kono
parents:
diff changeset
974
kono
parents:
diff changeset
975 end Sinput;