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 function At_EOL
return Boolean;
43 -- Skips any spaces, then checks if we are the end of a line. If so,
44 -- returns True (but does not skip over the EOL sequence). If not,
45 -- then returns False.
47 procedure Check
(C
: Character);
48 -- Checks that file is positioned at given character, and if so skips past
49 -- it, If not, raises Data_Error.
51 function Get_Int
return Int
;
52 -- On entry the file is positioned to a digit. On return, the file is
53 -- positioned past the last digit, and the returned result is the decimal
54 -- value read. Data_Error is raised for overflow (value greater than
55 -- Int'Last), or if the initial character is not a digit.
57 procedure Get_Sloc_Range
(Loc1
, Loc2
: out Source_Location
);
58 -- Skips initial spaces, then reads a source location range in the form
59 -- line:col-line:col and places the two source locations in Loc1 and Loc2.
60 -- Raises Data_Error if format does not match this requirement.
63 -- Called with the current character about to be read being LF or CR. Skips
64 -- past CR/LF characters until either a non-CR/LF character is found, or
65 -- the end of file is encountered.
67 procedure Skip_Spaces
;
68 -- Skips zero or more spaces at the current position, leaving the file
69 -- positioned at the first non-blank character (or Types.EOF).
75 function At_EOL
return Boolean is
78 return Nextc
= CR
or else Nextc
= LF
;
85 procedure Check
(C
: Character) is
98 function Get_Int
return Int
is
106 if C
not in '0' .. '9' then
110 -- Loop to read digits of integer value
114 pragma Unsuppress
(Overflow_Check
);
116 Val
:= Val
* 10 + (Character'Pos (C
) - Character'Pos ('0'));
122 exit when C
not in '0' .. '9';
128 when Constraint_Error
=>
136 procedure Get_Sloc_Range
(Loc1
, Loc2
: out Source_Location
) is
137 pragma Unsuppress
(Range_Check
);
142 Loc1
.Line
:= Logical_Line_Number
(Get_Int
);
144 Loc1
.Col
:= Column_Number
(Get_Int
);
148 Loc2
.Line
:= Logical_Line_Number
(Get_Int
);
150 Loc2
.Col
:= Column_Number
(Get_Int
);
153 when Constraint_Error
=>
161 procedure Skip_EOL
is
168 exit when C
/= LF
and then C
/= CR
;
173 exit when C
/= LF
and then C
/= CR
;
182 procedure Skip_Spaces
is
184 while Nextc
= ' ' loop
189 -- Start of processing for Get_Scos
194 -- Loop through lines of SCO information
196 while Nextc
= 'C' loop
201 -- Make sure first line is a header line
203 if SCO_Unit_Table
.Last
= 0 and then C
/= ' ' then
207 -- Otherwise dispatch on type of line
215 -- Complete previous entry if any
217 if SCO_Unit_Table
.Last
/= 0 then
218 SCO_Unit_Table
.Table
(SCO_Unit_Table
.Last
).To
:=
222 -- Scan out dependency number and file name
225 Ptr
: String_Ptr
:= new String (1 .. 32768);
235 while Nextc
> ' ' loop
240 -- Make new unit table entry (will fill in To later)
242 SCO_Unit_Table
.Append
(
243 (File_Name
=> new String'(Ptr.all (1 .. N)),
245 From => SCO_Table.Last + 1,
265 if Typ in '1' .. '9' then
271 Get_Sloc_Range (Loc1, Loc2);
287 when 'I
' | 'E
' | 'P
' | 'W
' | 'X
' =>
292 -- Case of simple condition
294 if C = 'c
' or else C = 't
' or else C = 'f
' then
296 Get_Sloc_Range (Loc1, Loc2);
304 -- Complex expression
307 Add_SCO (C1 => Dtyp, Last => False);
309 -- Loop through terms in complex expression
311 while C /= CR and then C /= LF loop
312 if C = 'c
' or else C = 't
' or else C = 'f
' then
315 Get_Sloc_Range (Loc1, Loc2);
322 elsif C = '!' or else
328 Add_SCO (C1 => C, Last => False);
340 -- Reset Last indication to True for last entry
342 SCO_Table.Table (SCO_Table.Last).Last := True;
352 -- Here with all SCO's stored, complete last SCO Unit table entry
354 SCO_Unit_Table.Table (SCO_Unit_Table.Last).To := SCO_Table.Last;