annotate gcc/ada/sinput-c.adb @ 143:76e1cf5455ef

add cbc_gc test
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sun, 23 Dec 2018 19:24:05 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S I N P U T . C --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- B o d y --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
kono
parents:
diff changeset
17 -- for more details. You should have received a copy of the GNU General --
kono
parents:
diff changeset
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
kono
parents:
diff changeset
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
kono
parents:
diff changeset
20 -- --
kono
parents:
diff changeset
21 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
23 -- --
kono
parents:
diff changeset
24 ------------------------------------------------------------------------------
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 with Debug; use Debug;
kono
parents:
diff changeset
27 with Opt; use Opt;
kono
parents:
diff changeset
28 with Output; use Output;
kono
parents:
diff changeset
29 with System; use System;
kono
parents:
diff changeset
30
kono
parents:
diff changeset
31 pragma Warnings (Off);
kono
parents:
diff changeset
32 -- This package is used also by gnatcoll
kono
parents:
diff changeset
33 with System.OS_Lib; use System.OS_Lib;
kono
parents:
diff changeset
34 pragma Warnings (On);
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 package body Sinput.C is
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 ---------------
kono
parents:
diff changeset
39 -- Load_File --
kono
parents:
diff changeset
40 ---------------
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 function Load_File (Path : String) return Source_File_Index is
kono
parents:
diff changeset
43 Src : Source_Buffer_Ptr;
kono
parents:
diff changeset
44 X : Source_File_Index;
kono
parents:
diff changeset
45 Lo : Source_Ptr;
kono
parents:
diff changeset
46 Hi : Source_Ptr;
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 Source_File_FD : File_Descriptor;
kono
parents:
diff changeset
49 -- The file descriptor for the current source file. A negative value
kono
parents:
diff changeset
50 -- indicates failure to open the specified source file.
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 Len : Integer;
kono
parents:
diff changeset
53 -- Length of file (assume no more than 2 gigabytes of source)
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 Actual_Len : Integer;
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 Path_Id : File_Name_Type;
kono
parents:
diff changeset
58 File_Id : File_Name_Type;
kono
parents:
diff changeset
59
kono
parents:
diff changeset
60 begin
kono
parents:
diff changeset
61 if Path = "" then
kono
parents:
diff changeset
62 return No_Source_File;
kono
parents:
diff changeset
63 end if;
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 Source_File.Increment_Last;
kono
parents:
diff changeset
66 X := Source_File.Last;
kono
parents:
diff changeset
67
kono
parents:
diff changeset
68 if Debug_Flag_L then
kono
parents:
diff changeset
69 Write_Str ("Sinput.C.Load_File: created source ");
kono
parents:
diff changeset
70 Write_Int (Int (X));
kono
parents:
diff changeset
71 Write_Str (" for ");
kono
parents:
diff changeset
72 Write_Str (Path);
kono
parents:
diff changeset
73 Write_Line ("");
kono
parents:
diff changeset
74 end if;
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 if X = Source_File.First then
kono
parents:
diff changeset
77 Lo := First_Source_Ptr;
kono
parents:
diff changeset
78 else
kono
parents:
diff changeset
79 Lo := ((Source_File.Table (X - 1).Source_Last + Source_Align) /
kono
parents:
diff changeset
80 Source_Align) * Source_Align;
kono
parents:
diff changeset
81 end if;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 Name_Len := Path'Length;
kono
parents:
diff changeset
84 Name_Buffer (1 .. Name_Len) := Path;
kono
parents:
diff changeset
85 Path_Id := Name_Find;
kono
parents:
diff changeset
86 Name_Buffer (Name_Len + 1) := ASCII.NUL;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 -- Open the source FD, note that we open in binary mode, because as
kono
parents:
diff changeset
89 -- documented in the spec, the caller is expected to handle either
kono
parents:
diff changeset
90 -- DOS or Unix mode files, and there is no point in wasting time on
kono
parents:
diff changeset
91 -- text translation when it is not required.
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 Source_File_FD := Open_Read (Name_Buffer'Address, Binary);
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 if Source_File_FD = Invalid_FD then
kono
parents:
diff changeset
96 Source_File.Decrement_Last;
kono
parents:
diff changeset
97 return No_Source_File;
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 end if;
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 Len := Integer (File_Length (Source_File_FD));
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 -- Set Hi so that length is one more than the physical length, allowing
kono
parents:
diff changeset
104 -- for the extra EOF character at the end of the buffer
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 Hi := Lo + Source_Ptr (Len);
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 -- Do the actual read operation
kono
parents:
diff changeset
109
kono
parents:
diff changeset
110 declare
kono
parents:
diff changeset
111 Var_Ptr : constant Source_Buffer_Ptr_Var :=
kono
parents:
diff changeset
112 new Source_Buffer (Lo .. Hi);
kono
parents:
diff changeset
113 -- Allocate source buffer, allowing extra character at end for EOF
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 begin
kono
parents:
diff changeset
116 -- Some systems have file types that require one read per line,
kono
parents:
diff changeset
117 -- so read until we get the Len bytes or until there are no more
kono
parents:
diff changeset
118 -- characters.
kono
parents:
diff changeset
119
kono
parents:
diff changeset
120 Hi := Lo;
kono
parents:
diff changeset
121 loop
kono
parents:
diff changeset
122 Actual_Len := Read (Source_File_FD, Var_Ptr (Hi)'Address, Len);
kono
parents:
diff changeset
123 Hi := Hi + Source_Ptr (Actual_Len);
kono
parents:
diff changeset
124 exit when Actual_Len = Len or else Actual_Len <= 0;
kono
parents:
diff changeset
125 end loop;
kono
parents:
diff changeset
126
kono
parents:
diff changeset
127 Var_Ptr (Hi) := EOF;
kono
parents:
diff changeset
128 Src := Var_Ptr.all'Access;
kono
parents:
diff changeset
129 end;
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 -- Read is complete, close the file and we are done (no need to test
kono
parents:
diff changeset
132 -- status from close, since we have successfully read the file).
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 Close (Source_File_FD);
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 -- Get the file name, without path information
kono
parents:
diff changeset
137
kono
parents:
diff changeset
138 declare
kono
parents:
diff changeset
139 Index : Positive := Path'Last;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 begin
kono
parents:
diff changeset
142 while Index > Path'First loop
kono
parents:
diff changeset
143 exit when Path (Index - 1) = '/';
kono
parents:
diff changeset
144 exit when Path (Index - 1) = Directory_Separator;
kono
parents:
diff changeset
145 Index := Index - 1;
kono
parents:
diff changeset
146 end loop;
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 Name_Len := Path'Last - Index + 1;
kono
parents:
diff changeset
149 Name_Buffer (1 .. Name_Len) := Path (Index .. Path'Last);
kono
parents:
diff changeset
150 File_Id := Name_Find;
kono
parents:
diff changeset
151 end;
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 declare
kono
parents:
diff changeset
154 S : Source_File_Record renames Source_File.Table (X);
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 begin
kono
parents:
diff changeset
157 S := (Debug_Source_Name => File_Id,
kono
parents:
diff changeset
158 File_Name => File_Id,
kono
parents:
diff changeset
159 File_Type => Config,
kono
parents:
diff changeset
160 First_Mapped_Line => No_Line_Number,
kono
parents:
diff changeset
161 Full_Debug_Name => Path_Id,
kono
parents:
diff changeset
162 Full_File_Name => Path_Id,
kono
parents:
diff changeset
163 Full_Ref_Name => Path_Id,
kono
parents:
diff changeset
164 Instance => No_Instance_Id,
kono
parents:
diff changeset
165 Identifier_Casing => Unknown,
kono
parents:
diff changeset
166 Inlined_Call => No_Location,
kono
parents:
diff changeset
167 Inlined_Body => False,
kono
parents:
diff changeset
168 Inherited_Pragma => False,
kono
parents:
diff changeset
169 Keyword_Casing => Unknown,
kono
parents:
diff changeset
170 Last_Source_Line => 1,
kono
parents:
diff changeset
171 License => Unknown,
kono
parents:
diff changeset
172 Lines_Table => null,
kono
parents:
diff changeset
173 Lines_Table_Max => 1,
kono
parents:
diff changeset
174 Logical_Lines_Table => null,
kono
parents:
diff changeset
175 Num_SRef_Pragmas => 0,
kono
parents:
diff changeset
176 Reference_Name => File_Id,
kono
parents:
diff changeset
177 Sloc_Adjust => 0,
kono
parents:
diff changeset
178 Source_Checksum => 0,
kono
parents:
diff changeset
179 Source_First => Lo,
kono
parents:
diff changeset
180 Source_Last => Hi,
kono
parents:
diff changeset
181 Source_Text => Src,
kono
parents:
diff changeset
182 Template => No_Source_File,
kono
parents:
diff changeset
183 Unit => No_Unit,
kono
parents:
diff changeset
184 Time_Stamp => Empty_Time_Stamp,
kono
parents:
diff changeset
185 Index => X);
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 Alloc_Line_Tables (S, Opt.Table_Factor * Alloc.Lines_Initial);
kono
parents:
diff changeset
188 S.Lines_Table (1) := Lo;
kono
parents:
diff changeset
189 end;
kono
parents:
diff changeset
190
kono
parents:
diff changeset
191 Set_Source_File_Index_Table (X);
kono
parents:
diff changeset
192 return X;
kono
parents:
diff changeset
193 end Load_File;
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 end Sinput.C;