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).
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;
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
208 -- Start of processing for Get_SCOs
213 -- Loop through lines of SCO information
215 while Nextc = 'C' loop
220 -- Make sure first line is a header line
222 if SCO_Unit_Table.Last = 0 and then C /= ' ' then
226 -- Otherwise dispatch on type of line
230 -- Header or instance table entry
234 -- Complete previous entry if any
236 if SCO_Unit_Table.Last /= 0 then
237 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To :=
245 -- Instance table entry
249 Inum : SCO_Instance_Index;
254 Inum := SCO_Instance_Index (Get_Int);
255 SCO_Instance_Table.Increment_Last;
256 pragma Assert (SCO_Instance_Table.Last = Inum);
260 SIE : SCO_Instance_Table_Entry
261 renames SCO_Instance_Table.Table (Inum);
263 SIE.Inst_Dep_Num := Get_Int;
265 pragma Assert (C = '|');
266 Get_Source_Location (SIE.Inst_Loc);
269 SIE.Enclosing_Instance := 0;
272 SIE.Enclosing_Instance :=
273 SCO_Instance_Index (Get_Int);
274 pragma Assert (SIE.Enclosing_Instance in
275 SCO_Instance_Table.First
276 .. SCO_Instance_Table.Last);
284 -- Scan out dependency number and file name
291 while Nextc > ' ' loop
296 -- Make new unit table entry (will fill in To later)
298 SCO_Unit_Table.Append (
299 (File_Name => new String'(Buf (1 .. N)),
301 From => SCO_Table.Last + 1,
319 -- If continuation, reset Last indication in last entry stored
320 -- for previous CS or cs line.
323 SCO_Table.Table (SCO_Table.Last).Last := False;
326 -- Initialize to scan items on one line
330 -- Loop through items on one line
339 -- Dominance marker may be present only at entry point
341 pragma Assert (Key = 'S');
347 -- Sanity check on dominance marker type indication
349 pragma Assert (Typ in 'A' .. 'Z');
356 if Typ = 'P' or else Typ = 'p' then
357 if Nextc not in '1' .. '9' then
360 Name_Len := Name_Len + 1;
361 Name_Buffer (Name_Len) := Getc;
362 exit when Nextc = ':';
372 if Key = '>' and then Typ /= 'E' then
373 Get_Source_Location (Loc1);
374 Loc2 := No_Source_Location;
376 Get_Source_Location_Range (Loc1, Loc2);
385 Pragma_Sloc => No_Location,
386 Pragma_Aspect_Name => Nam));
398 when 'E' | 'G' | 'I' | 'P' | 'W' | 'X' | 'A' =>
403 while Nextc /= ' ' loop
404 Name_Len := Name_Len + 1;
405 Name_Buffer (Name_Len) := Getc;
419 Loc : Source_Location;
422 -- Acquire location information
425 Loc := No_Source_Location;
427 Get_Source_Location (Loc);
434 To => No_Source_Location,
436 Pragma_Aspect_Name => Nam,
440 -- Loop through terms in complex expression
443 while C /= CR and then C /= LF loop
444 if C = 'c' or else C = 't' or else C = 'f' then
447 Get_Source_Location_Range (Loc1, Loc2);
455 elsif C = '!' or else
462 Loc : Source_Location;
464 Get_Source_Location (Loc);
475 elsif C = 'T' or else C = 'F' then
477 -- Chaining indicator: skip for now???
480 Loc1, Loc2 : Source_Location;
481 pragma Unreferenced (Loc1, Loc2);
484 Get_Source_Location_Range (Loc1, Loc2);
494 -- Reset Last indication to True for last entry
496 SCO_Table.Table (SCO_Table.Last).Last := True;
498 -- No other SCO lines are possible
507 -- Here with all SCO's stored, complete last SCO Unit table entry
509 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To := SCO_Table.Last;