1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2009-2012, 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).
32 with Snames; use Snames;
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;
186 exit when C /= LF and then C /= CR;
195 procedure Skip_Spaces is
197 while Nextc = ' ' loop
202 Buf : String (1 .. 32_768);
204 -- Scratch buffer, and index into it
206 -- Start of processing for Get_Scos
211 -- Loop through lines of SCO information
213 while Nextc = 'C' loop
218 -- Make sure first line is a header line
220 if SCO_Unit_Table.Last = 0 and then C /= ' ' then
224 -- Otherwise dispatch on type of line
232 -- Complete previous entry if any
234 if SCO_Unit_Table.Last /= 0 then
235 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To :=
239 -- Scan out dependency number and file name
247 while Nextc > ' ' loop
252 -- Make new unit table entry (will fill in To later)
254 SCO_Unit_Table.Append (
255 (File_Name => new String'(Buf (1 .. N)),
257 From => SCO_Table.Last + 1,
271 -- If continuation, reset Last indication in last entry stored
272 -- for previous CS or cs line.
275 SCO_Table.Table (SCO_Table.Last).Last := False;
278 -- Initialize to scan items on one line
282 -- Loop through items on one line
285 Pid := Unknown_Pragma;
291 -- Dominance marker may be present only at entry point
293 pragma Assert (Key = 'S');
304 if Typ = 'P' or else Typ = 'p' then
305 if Nextc not in '1' .. '9' then
309 exit when Nextc = ':';
317 Pragma_Id'Value ("pragma_" & Buf (1 .. N));
319 when Constraint_Error =>
321 -- Pid remains set to Unknown_Pragma
329 if Key = '>' and then Typ /= 'E' then
330 Get_Source_Location (Loc1);
331 Loc2 := No_Source_Location;
333 Get_Source_Location_Range (Loc1, Loc2);
342 Pragma_Sloc => No_Location,
343 Pragma_Name => Pid));
355 when 'E' | 'G' | 'I' | 'P' | 'W' | 'X' =>
362 Loc : Source_Location;
365 -- Acquire location information
368 Loc := No_Source_Location;
370 Get_Source_Location (Loc);
377 To => No_Source_Location,
382 -- Loop through terms in complex expression
385 while C /= CR and then C /= LF loop
386 if C = 'c' or else C = 't' or else C = 'f' then
389 Get_Source_Location_Range (Loc1, Loc2);
397 elsif C = '!' or else
404 Loc : Source_Location;
406 Get_Source_Location (Loc);
417 elsif C = 'T' or else C = 'F' then
419 -- Chaining indicator: skip for now???
422 Loc1, Loc2 : Source_Location;
423 pragma Unreferenced (Loc1, Loc2);
426 Get_Source_Location_Range (Loc1, Loc2);
436 -- Reset Last indication to True for last entry
438 SCO_Table.Table (SCO_Table.Last).Last := True;
440 -- No other SCO lines are possible
449 -- Here with all SCO's stored, complete last SCO Unit table entry
451 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To := SCO_Table.Last;