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