1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2009, 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 with Types; use Types;
29 with Ada.IO_Exceptions; use Ada.IO_Exceptions;
34 Loc1 : Source_Location;
35 Loc2 : Source_Location;
42 procedure Check (C : Character);
43 -- Checks that file is positioned at given character, and if so skips past
44 -- it, If not, raises Data_Error.
46 function Get_Int return Int;
47 -- On entry the file is positioned to a digit. On return, the file is
48 -- positioned past the last digit, and the returned result is the decimal
49 -- value read. Data_Error is raised for overflow (value greater than
50 -- Int'Last), or if the initial character is not a digit.
52 procedure Get_Sloc_Range (Loc1, Loc2 : out Source_Location);
53 -- Skips initial spaces, then reads a source location range in the form
54 -- line:col-line:col and places the two source locations in Loc1 and Loc2.
55 -- Raises Data_Error if format does not match this requirement.
58 -- Called with the current character about to be read being LF or CR. Skips
59 -- past CR/LF characters until either a non-CR/LF character is found, or
60 -- the end of file is encountered.
62 procedure Skip_Spaces;
63 -- Skips zero or more spaces at the current position, leaving the file
64 -- positioned at the first non-blank character (or Types.EOF).
70 procedure Check (C : Character) is
83 function Get_Int return Int is
91 if C not in '0' .. '9' then
95 -- Loop to read digits of integer value
99 pragma Unsuppress (Overflow_Check);
101 Val := Val * 10 + (Character'Pos (C) - Character'Pos ('0'));
107 exit when C not in '0' .. '9';
113 when Constraint_Error =>
121 procedure Get_Sloc_Range (Loc1, Loc2 : out Source_Location) is
122 pragma Unsuppress (Range_Check);
127 Loc1.Line := Logical_Line_Number (Get_Int);
129 Loc1.Col := Column_Number (Get_Int);
133 Loc2.Line := Logical_Line_Number (Get_Int);
135 Loc2.Col := Column_Number (Get_Int);
138 when Constraint_Error =>
146 procedure Skip_EOL is
153 exit when C /= LF and then C /= CR;
158 exit when C /= LF and then C /= CR;
167 procedure Skip_Spaces is
169 while Nextc = ' ' loop
174 -- Start of processing for Get_Scos
179 -- Loop through lines of SCO information
181 while Nextc = 'C' loop
186 -- Make sure first line is a header line
188 if SCO_Unit_Table.Last = 0 and then C /= ' ' then
192 -- Otherwise dispatch on type of line
200 -- Complete previous entry if any
202 if SCO_Unit_Table.Last /= 0 then
203 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To :=
207 -- Scan out dependency number and file name
210 Ptr : String_Ptr := new String (1 .. 32768);
220 while Nextc > ' ' loop
225 -- Make new unit table entry (will fill in To later)
227 SCO_Unit_Table.Append (
228 (File_Name => new String'(Ptr.all (1 .. N)),
230 From => SCO_Table.Last + 1,
239 Get_Sloc_Range (Loc1, Loc2);
240 Add_SCO (C1 => 'S', From => Loc1, To => Loc2);
245 Get_Sloc_Range (Loc1, Loc2);
246 Add_SCO (C1 => 'T', From => Loc1, To => Loc2);
250 when 'I' | 'E' | 'W' | 'X' =>
255 -- Case of simple condition
257 if C = 'c' or else C = 't' or else C = 'f' then
259 Get_Sloc_Range (Loc1, Loc2);
267 -- Complex expression
270 Add_SCO (C1 => Dtyp, Last => False);
272 -- Loop through terms in complex expression
274 while C /= CR and then C /= LF loop
275 if C = 'c' or else C = 't' or else C = 'f' then
278 Get_Sloc_Range (Loc1, Loc2);
285 elsif C = '!' or else
291 Add_SCO (C1 => C, Last => False);
303 -- Reset Last indication to True for last entry
305 SCO_Table.Table (SCO_Table.Last).Last := True;
315 -- Here with all SCO's stored, complete last SCO Unit table entry
317 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To := SCO_Table.Last;