1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2009-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
27 -- This unit is not part of the compiler proper, it is used in tools that
28 -- read SCO information from ALI files (Xcov and sco_test). Ada 2005
29 -- constructs may therefore be used freely (and are indeed).
31 with Namet
; use Namet
;
33 with Types
; use Types
;
35 with Ada
.IO_Exceptions
; use Ada
.IO_Exceptions
;
40 Loc1
: Source_Location
;
41 Loc2
: Source_Location
;
48 function At_EOL
return Boolean;
49 -- Skips any spaces, then checks if we are the end of a line. If so,
50 -- returns True (but does not skip over the EOL sequence). If not,
51 -- then returns False.
53 procedure Check
(C
: Character);
54 -- Checks that file is positioned at given character, and if so skips past
55 -- it, If not, raises Data_Error.
57 function Get_Int
return Int
;
58 -- On entry the file is positioned to a digit. On return, the file is
59 -- positioned past the last digit, and the returned result is the decimal
60 -- value read. Data_Error is raised for overflow (value greater than
61 -- Int'Last), or if the initial character is not a digit.
63 procedure Get_Source_Location
(Loc
: out Source_Location
);
64 -- Reads a source location in the form line:col and places the source
65 -- location in Loc. Raises Data_Error if the format does not match this
66 -- requirement. Note that initial spaces are not skipped.
68 procedure Get_Source_Location_Range
(Loc1
, Loc2
: out Source_Location
);
69 -- Skips initial spaces, then reads a source location range in the form
70 -- line:col-line:col and places the two source locations in Loc1 and Loc2.
71 -- Raises Data_Error if format does not match this requirement.
74 -- Called with the current character about to be read being LF or CR. Skips
75 -- past CR/LF characters until either a non-CR/LF character is found, or
76 -- the end of file is encountered.
78 procedure Skip_Spaces
;
79 -- Skips zero or more spaces at the current position, leaving the file
80 -- positioned at the first non-blank character (or Types.EOF).
86 function At_EOL
return Boolean is
89 return Nextc
= CR
or else Nextc
= LF
;
96 procedure Check
(C
: Character) is
109 function Get_Int
return Int
is
117 if C
not in '0' .. '9' then
121 -- Loop to read digits of integer value
125 pragma Unsuppress
(Overflow_Check
);
127 Val
:= Val
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
133 exit when C
not in '0' .. '9';
139 when Constraint_Error
=>
143 -------------------------
144 -- Get_Source_Location --
145 -------------------------
147 procedure Get_Source_Location
(Loc
: out Source_Location
) is
148 pragma Unsuppress
(Range_Check
);
150 Loc
.Line
:= Logical_Line_Number
(Get_Int
);
152 Loc
.Col
:= Column_Number
(Get_Int
);
154 when Constraint_Error
=>
156 end Get_Source_Location
;
158 -------------------------------
159 -- Get_Source_Location_Range --
160 -------------------------------
162 procedure Get_Source_Location_Range
(Loc1
, Loc2
: out Source_Location
) is
165 Get_Source_Location
(Loc1
);
167 Get_Source_Location
(Loc2
);
168 end Get_Source_Location_Range
;
174 procedure Skip_EOL
is
181 exit when C
/= LF
and then C
/= CR
;
189 procedure Skip_Spaces
is
191 while Nextc
= ' ' loop
196 Buf
: String (1 .. 32_768
);
198 -- Scratch buffer, and index into it
202 -- Start of processing for Get_SCOs
207 -- Loop through lines of SCO information
209 while Nextc
= 'C' loop
214 -- Make sure first line is a header line
216 if SCO_Unit_Table
.Last
= 0 and then C
/= ' ' then
220 -- Otherwise dispatch on type of line
224 -- Header or instance table entry
228 -- Complete previous entry if any
230 if SCO_Unit_Table
.Last
/= 0 then
231 SCO_Unit_Table
.Table
(SCO_Unit_Table
.Last
).To
:=
239 -- Instance table entry
243 Inum
: SCO_Instance_Index
;
248 Inum
:= SCO_Instance_Index
(Get_Int
);
249 SCO_Instance_Table
.Increment_Last
;
250 pragma Assert
(SCO_Instance_Table
.Last
= Inum
);
254 SIE
: SCO_Instance_Table_Entry
255 renames SCO_Instance_Table
.Table
(Inum
);
257 SIE
.Inst_Dep_Num
:= Get_Int
;
259 pragma Assert
(C
= '|');
260 Get_Source_Location
(SIE
.Inst_Loc
);
263 SIE
.Enclosing_Instance
:= 0;
266 SIE
.Enclosing_Instance
:=
267 SCO_Instance_Index
(Get_Int
);
268 pragma Assert
(SIE
.Enclosing_Instance
in
269 SCO_Instance_Table
.First
270 .. SCO_Instance_Table
.Last
);
278 -- Scan out dependency number and file name
285 while Nextc
> ' ' loop
290 -- Make new unit table entry (will fill in To later)
292 SCO_Unit_Table
.Append
(
293 (File_Name
=> new String'(Buf (1 .. N)),
296 From => SCO_Table.Last + 1,
313 -- If continuation, reset Last indication in last entry stored
314 -- for previous CS or cs line.
317 SCO_Table.Table (SCO_Table.Last).Last := False;
320 -- Initialize to scan items on one line
324 -- Loop through items on one line
333 -- Dominance marker may be present only at entry point
335 pragma Assert (Key = 'S
');
341 -- Sanity check on dominance marker type indication
343 pragma Assert (Typ in 'A
' .. 'Z
');
350 if Typ = 'P
' or else Typ = 'p
' then
351 if Nextc not in '1' .. '9' then
354 Name_Len := Name_Len + 1;
355 Name_Buffer (Name_Len) := Getc;
356 exit when Nextc = ':';
366 if Key = '>' and then Typ /= 'E
' then
367 Get_Source_Location (Loc1);
368 Loc2 := No_Source_Location;
370 Get_Source_Location_Range (Loc1, Loc2);
379 Pragma_Sloc => No_Location,
380 Pragma_Aspect_Name => Nam));
392 when 'E
' | 'G
' | 'I
' | 'P
' | 'W
' | 'X
' | 'A
' =>
397 while Nextc /= ' ' loop
398 Name_Len := Name_Len + 1;
399 Name_Buffer (Name_Len) := Getc;
413 Loc : Source_Location;
416 -- Acquire location information
419 Loc := No_Source_Location;
421 Get_Source_Location (Loc);
428 To => No_Source_Location,
430 Pragma_Aspect_Name => Nam,
434 -- Loop through terms in complex expression
437 while C /= CR and then C /= LF loop
438 if C = 'c
' or else C = 't
' or else C = 'f
' then
441 Get_Source_Location_Range (Loc1, Loc2);
449 elsif C = '!' or else
456 Loc : Source_Location;
458 Get_Source_Location (Loc);
469 elsif C = 'T
' or else C = 'F
' then
471 -- Chaining indicator: skip for now???
474 Loc1, Loc2 : Source_Location;
475 pragma Unreferenced (Loc1, Loc2);
478 Get_Source_Location_Range (Loc1, Loc2);
488 -- Reset Last indication to True for last entry
490 SCO_Table.Table (SCO_Table.Last).Last := True;
492 -- No other SCO lines are possible
501 -- Here with all SCO's stored, complete last SCO Unit table entry
503 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To := SCO_Table.Last;