annotate gcc/ada/osint.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
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 -- O S I N T --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
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 -- This package contains the low level, operating system routines used in the
kono
parents:
diff changeset
27 -- compiler and binder for command line processing and file input output.
kono
parents:
diff changeset
28
kono
parents:
diff changeset
29 with Namet; use Namet;
kono
parents:
diff changeset
30 with Types; use Types;
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 with System; use System;
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 pragma Warnings (Off);
kono
parents:
diff changeset
35 -- This package is used also by gnatcoll
kono
parents:
diff changeset
36 with System.OS_Lib; use System.OS_Lib;
kono
parents:
diff changeset
37 pragma Warnings (On);
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 with System.Storage_Elements;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 pragma Elaborate_All (System.OS_Lib);
kono
parents:
diff changeset
42 -- For the call to function Get_Target_Object_Suffix in the private part
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 package Osint is
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 Multi_Unit_Index_Character : constant Character := '~';
kono
parents:
diff changeset
47 -- The character before the index of the unit in a multi-unit source in ALI
kono
parents:
diff changeset
48 -- and object file names.
kono
parents:
diff changeset
49
kono
parents:
diff changeset
50 Ada_Include_Path : constant String := "ADA_INCLUDE_PATH";
kono
parents:
diff changeset
51 Ada_Objects_Path : constant String := "ADA_OBJECTS_PATH";
kono
parents:
diff changeset
52 Project_Include_Path_File : constant String := "ADA_PRJ_INCLUDE_FILE";
kono
parents:
diff changeset
53 Project_Objects_Path_File : constant String := "ADA_PRJ_OBJECTS_FILE";
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 Output_FD : File_Descriptor;
kono
parents:
diff changeset
56 -- File descriptor for current library info, list, tree, C, H, or binder
kono
parents:
diff changeset
57 -- output. Only one of these is open at a time, so we need only one FD.
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 procedure Initialize;
kono
parents:
diff changeset
60 -- Initialize internal tables
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 function Normalize_Directory_Name (Directory : String) return String_Ptr;
kono
parents:
diff changeset
63 -- Verify and normalize a directory name. If directory name is invalid,
kono
parents:
diff changeset
64 -- this will return an empty string. Otherwise it will insure a trailing
kono
parents:
diff changeset
65 -- slash and make other normalizations.
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 type File_Type is (Source, Library, Config, Definition, Preprocessing_Data);
kono
parents:
diff changeset
68
kono
parents:
diff changeset
69 function Find_File
kono
parents:
diff changeset
70 (N : File_Name_Type;
kono
parents:
diff changeset
71 T : File_Type;
kono
parents:
diff changeset
72 Full_Name : Boolean := False) return File_Name_Type;
kono
parents:
diff changeset
73 -- Finds a source, library or config file depending on the value of T
kono
parents:
diff changeset
74 -- following the directory search order rules unless N is the name of the
kono
parents:
diff changeset
75 -- file just read with Next_Main_File and already contains directory
kono
parents:
diff changeset
76 -- information, in which case just look in the Primary_Directory. Returns
kono
parents:
diff changeset
77 -- File_Name_Type of the full file name if found, No_File if file not
kono
parents:
diff changeset
78 -- found. Note that for the special case of gnat.adc, only the compilation
kono
parents:
diff changeset
79 -- environment directory is searched, i.e. the directory where the ali and
kono
parents:
diff changeset
80 -- object files are written. Another special case is Debug_Generated_Code
kono
parents:
diff changeset
81 -- set and the file name ends in ".dg", in which case we look for the
kono
parents:
diff changeset
82 -- generated file only in the current directory, since that is where it is
kono
parents:
diff changeset
83 -- always built.
kono
parents:
diff changeset
84 --
kono
parents:
diff changeset
85 -- In the case of configuration files, full path names are needed for some
kono
parents:
diff changeset
86 -- ASIS queries. The flag Full_Name indicates that the name of the file
kono
parents:
diff changeset
87 -- should be normalized to include a full path.
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 function Get_File_Names_Case_Sensitive return Int;
kono
parents:
diff changeset
90 pragma Import (C, Get_File_Names_Case_Sensitive,
kono
parents:
diff changeset
91 "__gnat_get_file_names_case_sensitive");
kono
parents:
diff changeset
92 File_Names_Case_Sensitive : constant Boolean :=
kono
parents:
diff changeset
93 Get_File_Names_Case_Sensitive /= 0;
kono
parents:
diff changeset
94 -- Set to indicate whether the operating system convention is for file
kono
parents:
diff changeset
95 -- names to be case sensitive (e.g., in Unix, set True), or non case
kono
parents:
diff changeset
96 -- sensitive (e.g., in Windows, set False).
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 procedure Canonical_Case_File_Name (S : in out String);
kono
parents:
diff changeset
99 -- Given a file name, converts it to canonical case form. For systems
kono
parents:
diff changeset
100 -- where file names are case sensitive, this procedure has no effect.
kono
parents:
diff changeset
101 -- If file names are not case sensitive (i.e. for example if you have
kono
parents:
diff changeset
102 -- the file "xyz.adb", you can refer to it as XYZ.adb or XyZ.AdB), then
kono
parents:
diff changeset
103 -- this call converts the given string to canonical all lower case form,
kono
parents:
diff changeset
104 -- so that two file names compare equal if they refer to the same file.
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 function Get_Env_Vars_Case_Sensitive return Int;
kono
parents:
diff changeset
107 pragma Import (C, Get_Env_Vars_Case_Sensitive,
kono
parents:
diff changeset
108 "__gnat_get_env_vars_case_sensitive");
kono
parents:
diff changeset
109 Env_Vars_Case_Sensitive : constant Boolean :=
kono
parents:
diff changeset
110 Get_Env_Vars_Case_Sensitive /= 0;
kono
parents:
diff changeset
111 -- Set to indicate whether the operating system convention is for
kono
parents:
diff changeset
112 -- environment variable names to be case sensitive (e.g., in Unix, set
kono
parents:
diff changeset
113 -- True), or non case sensitive (e.g., in Windows, set False).
kono
parents:
diff changeset
114
kono
parents:
diff changeset
115 procedure Canonical_Case_Env_Var_Name (S : in out String);
kono
parents:
diff changeset
116 -- Given an environment variable name, converts it to canonical case form.
kono
parents:
diff changeset
117 -- For systems where environment variable names are case sensitive, this
kono
parents:
diff changeset
118 -- procedure has no effect. If environment variable names are not case
kono
parents:
diff changeset
119 -- sensitive, then this call converts the given string to canonical all
kono
parents:
diff changeset
120 -- lower case form, so that two environment variable names compare equal if
kono
parents:
diff changeset
121 -- they refer to the same environment variable.
kono
parents:
diff changeset
122
kono
parents:
diff changeset
123 function Number_Of_Files return Nat;
kono
parents:
diff changeset
124 -- Gives the total number of filenames found on the command line
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 No_Index : constant := -1;
kono
parents:
diff changeset
127 -- Value used in Add_File to indicate no index is specified for main
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 procedure Add_File (File_Name : String; Index : Int := No_Index);
kono
parents:
diff changeset
130 -- Called by the subprogram processing the command line for each file name
kono
parents:
diff changeset
131 -- found. The index, when not defaulted to No_Index is the index of the
kono
parents:
diff changeset
132 -- subprogram in its source, zero indicating that the source is not
kono
parents:
diff changeset
133 -- multi-unit.
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 procedure Find_Program_Name;
kono
parents:
diff changeset
136 -- Put simple name of current program being run (excluding the directory
kono
parents:
diff changeset
137 -- path) in Name_Buffer, with the length in Name_Len.
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 function Program_Name (Nam : String; Prog : String) return String_Access;
kono
parents:
diff changeset
140 -- In the native compilation case, Create a string containing Nam. In the
kono
parents:
diff changeset
141 -- cross compilation case, looks at the prefix of the current program being
kono
parents:
diff changeset
142 -- run and prepend it to Nam. For instance if the program being run is
kono
parents:
diff changeset
143 -- <target>-gnatmake and Nam is "gcc", the returned value will be a pointer
kono
parents:
diff changeset
144 -- to "<target>-gcc". In the specific case where AAMP_On_Target is set, the
kono
parents:
diff changeset
145 -- name "gcc" is mapped to "gnaamp", and names of the form "gnat*" are
kono
parents:
diff changeset
146 -- mapped to "gnaamp*". This function clobbers Name_Buffer and Name_Len.
kono
parents:
diff changeset
147 -- Also look at any suffix, e.g. gnatmake-4.1 -> "gcc-4.1". Prog is the
kono
parents:
diff changeset
148 -- default name of the current program being executed, e.g. "gnatmake",
kono
parents:
diff changeset
149 -- "gnatlink".
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 procedure Write_Program_Name;
kono
parents:
diff changeset
152 -- Writes name of program as invoked to the current output (normally
kono
parents:
diff changeset
153 -- standard output).
kono
parents:
diff changeset
154
kono
parents:
diff changeset
155 procedure Fail (S : String);
kono
parents:
diff changeset
156 pragma No_Return (Fail);
kono
parents:
diff changeset
157 -- Outputs error message S preceded by the name of the executing program
kono
parents:
diff changeset
158 -- and exits with E_Fatal. The output goes to standard error, except if
kono
parents:
diff changeset
159 -- special output is in effect (see Output).
kono
parents:
diff changeset
160
kono
parents:
diff changeset
161 function Is_Directory_Separator (C : Character) return Boolean;
kono
parents:
diff changeset
162 -- Returns True if C is a directory separator
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 function Get_Directory (Name : File_Name_Type) return File_Name_Type;
kono
parents:
diff changeset
165 -- Get the prefix directory name (if any) from Name. The last separator
kono
parents:
diff changeset
166 -- is preserved. Return the normalized current directory if there is no
kono
parents:
diff changeset
167 -- directory part in the name.
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 function Is_Readonly_Library (File : File_Name_Type) return Boolean;
kono
parents:
diff changeset
170 -- Check if this library file is a read-only file
kono
parents:
diff changeset
171
kono
parents:
diff changeset
172 function Strip_Directory (Name : File_Name_Type) return File_Name_Type;
kono
parents:
diff changeset
173 -- Strips the prefix directory name (if any) from Name. Returns the
kono
parents:
diff changeset
174 -- stripped name. Name cannot end with a directory separator.
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 function Strip_Suffix (Name : File_Name_Type) return File_Name_Type;
kono
parents:
diff changeset
177 -- Strips the suffix (the last '.' and whatever comes after it) from Name.
kono
parents:
diff changeset
178 -- Returns the stripped name.
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 function Executable_Name
kono
parents:
diff changeset
181 (Name : File_Name_Type;
kono
parents:
diff changeset
182 Only_If_No_Suffix : Boolean := False) return File_Name_Type;
kono
parents:
diff changeset
183 -- Given a file name it adds the appropriate suffix at the end so that
kono
parents:
diff changeset
184 -- it becomes the name of the executable on the system at end. For
kono
parents:
diff changeset
185 -- instance under DOS it adds the ".exe" suffix, whereas under UNIX no
kono
parents:
diff changeset
186 -- suffix is added.
kono
parents:
diff changeset
187
kono
parents:
diff changeset
188 function Executable_Name
kono
parents:
diff changeset
189 (Name : String;
kono
parents:
diff changeset
190 Only_If_No_Suffix : Boolean := False) return String;
kono
parents:
diff changeset
191 -- Same as above, with String parameters
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type;
kono
parents:
diff changeset
194 -- Returns the time stamp of file Name. Name should include relative path
kono
parents:
diff changeset
195 -- information in order to locate it. If the source file cannot be opened,
kono
parents:
diff changeset
196 -- or Name = No_File, and all blank time stamp is returned (this is not an
kono
parents:
diff changeset
197 -- error situation).
kono
parents:
diff changeset
198
kono
parents:
diff changeset
199 function File_Stamp (Name : Path_Name_Type) return Time_Stamp_Type;
kono
parents:
diff changeset
200 -- Same as above for a path name
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 type String_Access_List is array (Positive range <>) of String_Access;
kono
parents:
diff changeset
203 -- Dereferenced type used to return a list of file specs in
kono
parents:
diff changeset
204 -- To_Canonical_File_List.
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 type String_Access_List_Access is access all String_Access_List;
kono
parents:
diff changeset
207 -- Type used to return a String_Access_List without dragging in secondary
kono
parents:
diff changeset
208 -- stack.
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 function To_Canonical_File_List
kono
parents:
diff changeset
211 (Wildcard_Host_File : String;
kono
parents:
diff changeset
212 Only_Dirs : Boolean) return String_Access_List_Access;
kono
parents:
diff changeset
213 -- Expand a wildcard host syntax file or directory specification and return
kono
parents:
diff changeset
214 -- a list of valid Unix syntax file or directory specs. If Only_Dirs is
kono
parents:
diff changeset
215 -- True, then only return directories.
kono
parents:
diff changeset
216
kono
parents:
diff changeset
217 function To_Host_Dir_Spec
kono
parents:
diff changeset
218 (Canonical_Dir : String;
kono
parents:
diff changeset
219 Prefix_Style : Boolean) return String_Access;
kono
parents:
diff changeset
220 -- Convert a canonical syntax directory specification to host syntax. The
kono
parents:
diff changeset
221 -- Prefix_Style flag is currently ignored but should be set to False.
kono
parents:
diff changeset
222 -- Note that the caller must free result.
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 function To_Host_File_Spec
kono
parents:
diff changeset
225 (Canonical_File : String) return String_Access;
kono
parents:
diff changeset
226 -- Convert a canonical syntax file specification to host syntax
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 function Relocate_Path
kono
parents:
diff changeset
229 (Prefix : String;
kono
parents:
diff changeset
230 Path : String) return String_Ptr;
kono
parents:
diff changeset
231 -- Given an absolute path and a prefix, if Path starts with Prefix,
kono
parents:
diff changeset
232 -- replace the Prefix substring with the root installation directory.
kono
parents:
diff changeset
233 -- By default, try to compute the root installation directory by looking
kono
parents:
diff changeset
234 -- at the executable name as it was typed on the command line and, if
kono
parents:
diff changeset
235 -- needed, use the PATH environment variable. If the above computation
kono
parents:
diff changeset
236 -- fails, return Path. This function assumes Prefix'First = Path'First.
kono
parents:
diff changeset
237
kono
parents:
diff changeset
238 function Shared_Lib (Name : String) return String;
kono
parents:
diff changeset
239 -- Returns the runtime shared library in the form -l<name>-<version> where
kono
parents:
diff changeset
240 -- version is the GNAT runtime library option for the platform. For example
kono
parents:
diff changeset
241 -- this routine called with Name set to "gnat" will return "-lgnat-5.02"
kono
parents:
diff changeset
242 -- on UNIX and Windows.
kono
parents:
diff changeset
243
kono
parents:
diff changeset
244 ---------------------
kono
parents:
diff changeset
245 -- File attributes --
kono
parents:
diff changeset
246 ---------------------
kono
parents:
diff changeset
247
kono
parents:
diff changeset
248 -- The following subprograms offer services similar to those found in
kono
parents:
diff changeset
249 -- System.OS_Lib, but with the ability to extra multiple information from
kono
parents:
diff changeset
250 -- a single system call, depending on the system. This can result in fewer
kono
parents:
diff changeset
251 -- system calls when reused.
kono
parents:
diff changeset
252
kono
parents:
diff changeset
253 -- In all these subprograms, the requested value is either read from the
kono
parents:
diff changeset
254 -- File_Attributes parameter (resulting in no system call), or computed
kono
parents:
diff changeset
255 -- from the disk and then cached in the File_Attributes parameter (possibly
kono
parents:
diff changeset
256 -- along with other values).
kono
parents:
diff changeset
257
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
258 File_Attributes_Size : constant Natural := 32;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
259 -- This should be big enough to fit a "struct file_attributes" on any
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
260 -- system. It doesn't cause any malfunction if it is too big (which avoids
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
261 -- the need for either mapping the struct exactly or importing the sizeof
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
262 -- from C, which would result in dynamic code). However, it does waste
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
263 -- space (e.g. when a component of this type appears in a record, if it is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
264 -- unnecessarily large). Note: for runtime units, use System.OS_Constants.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
265 -- SIZEOF_struct_file_attributes instead, which has the exact value.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
266
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
267 type File_Attributes is
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
268 array (1 .. File_Attributes_Size)
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
269 of System.Storage_Elements.Storage_Element;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
270 for File_Attributes'Alignment use Standard'Maximum_Alignment;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
271
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
272 Unknown_Attributes : File_Attributes;
111
kono
parents:
diff changeset
273 -- A cache for various attributes for a file (length, accessibility,...)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
274 -- Will be initialized properly at elaboration (for efficiency later on,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
275 -- avoid function calls every time we want to reset the attributes) prior
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
276 -- to the first usage. We cannot make it constant since the compiler may
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
277 -- put it in a read-only section.
111
kono
parents:
diff changeset
278
kono
parents:
diff changeset
279 function Is_Directory
kono
parents:
diff changeset
280 (Name : C_File_Name;
kono
parents:
diff changeset
281 Attr : access File_Attributes) return Boolean;
kono
parents:
diff changeset
282 function Is_Regular_File
kono
parents:
diff changeset
283 (Name : C_File_Name;
kono
parents:
diff changeset
284 Attr : access File_Attributes) return Boolean;
kono
parents:
diff changeset
285 function Is_Symbolic_Link
kono
parents:
diff changeset
286 (Name : C_File_Name;
kono
parents:
diff changeset
287 Attr : access File_Attributes) return Boolean;
kono
parents:
diff changeset
288 -- Return the type of the file,
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 function File_Length
kono
parents:
diff changeset
291 (Name : C_File_Name;
kono
parents:
diff changeset
292 Attr : access File_Attributes) return Long_Integer;
kono
parents:
diff changeset
293 -- Return the length (number of bytes) of the file
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 function File_Time_Stamp
kono
parents:
diff changeset
296 (Name : C_File_Name;
kono
parents:
diff changeset
297 Attr : access File_Attributes) return OS_Time;
kono
parents:
diff changeset
298 function File_Time_Stamp
kono
parents:
diff changeset
299 (Name : Path_Name_Type;
kono
parents:
diff changeset
300 Attr : access File_Attributes) return Time_Stamp_Type;
kono
parents:
diff changeset
301 -- Return the time stamp of the file
kono
parents:
diff changeset
302
kono
parents:
diff changeset
303 function Is_Readable_File
kono
parents:
diff changeset
304 (Name : C_File_Name;
kono
parents:
diff changeset
305 Attr : access File_Attributes) return Boolean;
kono
parents:
diff changeset
306 function Is_Executable_File
kono
parents:
diff changeset
307 (Name : C_File_Name;
kono
parents:
diff changeset
308 Attr : access File_Attributes) return Boolean;
kono
parents:
diff changeset
309 function Is_Writable_File
kono
parents:
diff changeset
310 (Name : C_File_Name;
kono
parents:
diff changeset
311 Attr : access File_Attributes) return Boolean;
kono
parents:
diff changeset
312 -- Return the access rights for the file
kono
parents:
diff changeset
313
kono
parents:
diff changeset
314 -------------------------
kono
parents:
diff changeset
315 -- Search Dir Routines --
kono
parents:
diff changeset
316 -------------------------
kono
parents:
diff changeset
317
kono
parents:
diff changeset
318 function Include_Dir_Default_Prefix return String;
kono
parents:
diff changeset
319 -- Return the directory of the run-time library sources, as modified
kono
parents:
diff changeset
320 -- by update_path.
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 function Object_Dir_Default_Prefix return String;
kono
parents:
diff changeset
323 -- Return the directory of the run-time library ALI and object files, as
kono
parents:
diff changeset
324 -- modified by update_path.
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 procedure Add_Default_Search_Dirs;
kono
parents:
diff changeset
327 -- This routine adds the default search dirs indicated by the environment
kono
parents:
diff changeset
328 -- variables and sdefault package, as well as the library search dirs set
kono
parents:
diff changeset
329 -- by option -gnateO for GNAT2WHY.
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 procedure Add_Lib_Search_Dir (Dir : String);
kono
parents:
diff changeset
332 -- Add Dir at the end of the library file search path
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 procedure Add_Src_Search_Dir (Dir : String);
kono
parents:
diff changeset
335 -- Add Dir at the end of the source file search path
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 procedure Get_Next_Dir_In_Path_Init
kono
parents:
diff changeset
338 (Search_Path : String_Access);
kono
parents:
diff changeset
339 function Get_Next_Dir_In_Path
kono
parents:
diff changeset
340 (Search_Path : String_Access) return String_Access;
kono
parents:
diff changeset
341 -- These subprograms are used to parse out the directory names in a search
kono
parents:
diff changeset
342 -- path specified by a Search_Path argument. The procedure initializes an
kono
parents:
diff changeset
343 -- internal pointer to point to the initial directory name, and calls to
kono
parents:
diff changeset
344 -- the function return successive directory names, with a null pointer
kono
parents:
diff changeset
345 -- marking the end of the list.
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 type Search_File_Type is (Include, Objects);
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 procedure Add_Search_Dirs
kono
parents:
diff changeset
350 (Search_Path : String_Ptr;
kono
parents:
diff changeset
351 Path_Type : Search_File_Type);
kono
parents:
diff changeset
352 -- These procedure adds all the search directories that are in Search_Path
kono
parents:
diff changeset
353 -- in the proper file search path (library or source)
kono
parents:
diff changeset
354
kono
parents:
diff changeset
355 function Get_Primary_Src_Search_Directory return String_Ptr;
kono
parents:
diff changeset
356 -- Retrieved the primary directory (directory containing the main source
kono
parents:
diff changeset
357 -- file for Gnatmake.
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 function Nb_Dir_In_Src_Search_Path return Natural;
kono
parents:
diff changeset
360 function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr;
kono
parents:
diff changeset
361 -- Functions to access the directory names in the source search path
kono
parents:
diff changeset
362
kono
parents:
diff changeset
363 function Nb_Dir_In_Obj_Search_Path return Natural;
kono
parents:
diff changeset
364 function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr;
kono
parents:
diff changeset
365 -- Functions to access the directory names in the Object search path
kono
parents:
diff changeset
366
kono
parents:
diff changeset
367 Include_Search_File : constant String_Access :=
kono
parents:
diff changeset
368 new String'("ada_source_path");
kono
parents:
diff changeset
369 Objects_Search_File : constant String_Access :=
kono
parents:
diff changeset
370 new String'("ada_object_path");
kono
parents:
diff changeset
371 -- Names of the files containing the default include or objects search
kono
parents:
diff changeset
372 -- directories. These files, located in Sdefault.Search_Dir_Prefix, do
kono
parents:
diff changeset
373 -- not necessarily exist.
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 Exec_Name : String_Ptr;
kono
parents:
diff changeset
376 -- Executable name as typed by the user (used to compute the
kono
parents:
diff changeset
377 -- executable prefix).
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 function Read_Default_Search_Dirs
kono
parents:
diff changeset
380 (Search_Dir_Prefix : String_Access;
kono
parents:
diff changeset
381 Search_File : String_Access;
kono
parents:
diff changeset
382 Search_Dir_Default_Name : String_Access) return String_Access;
kono
parents:
diff changeset
383 -- Read and return the default search directories from the file located
kono
parents:
diff changeset
384 -- in Search_Dir_Prefix (as modified by update_path) and named Search_File.
kono
parents:
diff changeset
385 -- If no such file exists or an error occurs then instead return the
kono
parents:
diff changeset
386 -- Search_Dir_Default_Name (as modified by update_path).
kono
parents:
diff changeset
387
kono
parents:
diff changeset
388 function Get_RTS_Search_Dir
kono
parents:
diff changeset
389 (Search_Dir : String;
kono
parents:
diff changeset
390 File_Type : Search_File_Type) return String_Ptr;
kono
parents:
diff changeset
391 -- This function retrieves the paths to the search (resp. lib) dirs and
kono
parents:
diff changeset
392 -- return them. The search dir can be absolute or relative. If the search
kono
parents:
diff changeset
393 -- dir contains Include_Search_File (resp. Object_Search_File), then this
kono
parents:
diff changeset
394 -- function reads and returns the default search directories from the file.
kono
parents:
diff changeset
395 -- Otherwise, if the directory is absolute, it will try to find 'adalib'
kono
parents:
diff changeset
396 -- (resp. 'adainclude'). If found, null is returned. If the directory is
kono
parents:
diff changeset
397 -- relative, the following directories for the directories 'adalib' and
kono
parents:
diff changeset
398 -- 'adainclude' will be scanned:
kono
parents:
diff changeset
399 --
kono
parents:
diff changeset
400 -- - current directory (from which the tool has been spawned)
kono
parents:
diff changeset
401 -- - $GNAT_ROOT/gcc/gcc-lib/$targ/$vers/
kono
parents:
diff changeset
402 -- - $GNAT_ROOT/gcc/gcc-lib/$targ/$vers/rts-
kono
parents:
diff changeset
403 --
kono
parents:
diff changeset
404 -- The scan will stop as soon as the directory being searched for (adalib
kono
parents:
diff changeset
405 -- or adainclude) is found. If the scan fails, null is returned.
kono
parents:
diff changeset
406
kono
parents:
diff changeset
407 -----------------------
kono
parents:
diff changeset
408 -- Source File Input --
kono
parents:
diff changeset
409 -----------------------
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 -- Source file input routines are used by the compiler to read the main
kono
parents:
diff changeset
412 -- source files and the subsidiary source files (e.g. with'ed units), and
kono
parents:
diff changeset
413 -- also by the binder to check presence/time stamps of sources.
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 procedure Read_Source_File
kono
parents:
diff changeset
416 (N : File_Name_Type;
kono
parents:
diff changeset
417 Lo : Source_Ptr;
kono
parents:
diff changeset
418 Hi : out Source_Ptr;
kono
parents:
diff changeset
419 Src : out Source_Buffer_Ptr;
kono
parents:
diff changeset
420 FD : out File_Descriptor;
kono
parents:
diff changeset
421 T : File_Type := Source);
kono
parents:
diff changeset
422 -- Allocates a Source_Buffer of appropriate length and then reads the
kono
parents:
diff changeset
423 -- entire contents of the source file N into the buffer. The address of
kono
parents:
diff changeset
424 -- the allocated buffer is returned in Src. FD is used for extended error
kono
parents:
diff changeset
425 -- information in the case the read fails.
kono
parents:
diff changeset
426 --
kono
parents:
diff changeset
427 -- Each line of text is terminated by one of the sequences:
kono
parents:
diff changeset
428 --
kono
parents:
diff changeset
429 -- CR
kono
parents:
diff changeset
430 -- CR/LF
kono
parents:
diff changeset
431 -- LF
kono
parents:
diff changeset
432
kono
parents:
diff changeset
433 -- The source is terminated by an EOF (16#1A#) character, which is the last
kono
parents:
diff changeset
434 -- character of the returned source buffer (note that any EOF characters in
kono
parents:
diff changeset
435 -- positions other than the last source character are treated as blanks).
kono
parents:
diff changeset
436 --
kono
parents:
diff changeset
437 -- The logical lower bound of the source buffer is the input value of Lo,
kono
parents:
diff changeset
438 -- and on exit Hi is set to the logical upper bound of the source buffer,
kono
parents:
diff changeset
439 -- which is redundant with Src'Last.
kono
parents:
diff changeset
440 --
kono
parents:
diff changeset
441 -- If the given file cannot be opened, then the action depends on whether
kono
parents:
diff changeset
442 -- this file is the current main unit (i.e. its name matches the name
kono
parents:
diff changeset
443 -- returned by the most recent call to Next_Main_Source). If so, then the
kono
parents:
diff changeset
444 -- failure to find the file is a fatal error, an error message is output,
kono
parents:
diff changeset
445 -- and program execution is terminated. Otherwise (for the case of a
kono
parents:
diff changeset
446 -- subsidiary source loaded directly or indirectly using with), a file
kono
parents:
diff changeset
447 -- not found condition causes null to be set as the result value and a
kono
parents:
diff changeset
448 -- value of No_Source_File (0) to be set as the FD value. In the related
kono
parents:
diff changeset
449 -- case of a file with no read permissions the result is the same except FD
kono
parents:
diff changeset
450 -- is set to No_Access_To_Source_File (-1). Upon success FD is set to a
kono
parents:
diff changeset
451 -- positive Source_File_Index.
kono
parents:
diff changeset
452 --
kono
parents:
diff changeset
453 -- Note that the name passed to this function is the simple file name,
kono
parents:
diff changeset
454 -- without any directory information. The implementation is responsible
kono
parents:
diff changeset
455 -- for searching for the file in the appropriate directories.
kono
parents:
diff changeset
456 --
kono
parents:
diff changeset
457 -- Note the special case that if the file name is gnat.adc, then the search
kono
parents:
diff changeset
458 -- for the file is done ONLY in the directory corresponding to the current
kono
parents:
diff changeset
459 -- compilation environment, i.e. in the same directory where the ali and
kono
parents:
diff changeset
460 -- object files will be written.
kono
parents:
diff changeset
461
kono
parents:
diff changeset
462 function Full_Source_Name return File_Name_Type;
kono
parents:
diff changeset
463 function Current_Source_File_Stamp return Time_Stamp_Type;
kono
parents:
diff changeset
464 -- Returns the full name/time stamp of the source file most recently read
kono
parents:
diff changeset
465 -- using Read_Source_File. Calling this routine entails no source file
kono
parents:
diff changeset
466 -- directory lookup penalty.
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 procedure Full_Source_Name
kono
parents:
diff changeset
469 (N : File_Name_Type;
kono
parents:
diff changeset
470 Full_File : out File_Name_Type;
kono
parents:
diff changeset
471 Attr : access File_Attributes);
kono
parents:
diff changeset
472 function Full_Source_Name (N : File_Name_Type) return File_Name_Type;
kono
parents:
diff changeset
473 function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type;
kono
parents:
diff changeset
474 -- Returns the full name/time stamp of the source file whose simple name
kono
parents:
diff changeset
475 -- is N which should not include path information. Note that if the file
kono
parents:
diff changeset
476 -- cannot be located No_File is returned for the first routine and an all
kono
parents:
diff changeset
477 -- blank time stamp is returned for the second (this is not an error
kono
parents:
diff changeset
478 -- situation). The full name includes appropriate directory information.
kono
parents:
diff changeset
479 -- The source file directory lookup penalty is incurred every single time
kono
parents:
diff changeset
480 -- the routines are called unless you have previously called
kono
parents:
diff changeset
481 -- Source_File_Data (Cache => True). See below.
kono
parents:
diff changeset
482 --
kono
parents:
diff changeset
483 -- The procedural version also returns some file attributes for the ALI
kono
parents:
diff changeset
484 -- file (to save on system calls later on).
kono
parents:
diff changeset
485
kono
parents:
diff changeset
486 function Current_File_Index return Int;
kono
parents:
diff changeset
487 -- Return the index in its source file of the current main unit
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 function Matching_Full_Source_Name
kono
parents:
diff changeset
490 (N : File_Name_Type;
kono
parents:
diff changeset
491 T : Time_Stamp_Type) return File_Name_Type;
kono
parents:
diff changeset
492 -- Same semantics than Full_Source_Name but will search on the source path
kono
parents:
diff changeset
493 -- until a source file with time stamp matching T is found. If none is
kono
parents:
diff changeset
494 -- found returns No_File.
kono
parents:
diff changeset
495
kono
parents:
diff changeset
496 procedure Source_File_Data (Cache : Boolean);
kono
parents:
diff changeset
497 -- By default source file data (full source file name and time stamp)
kono
parents:
diff changeset
498 -- are looked up every time a call to Full_Source_Name (N) or
kono
parents:
diff changeset
499 -- Source_File_Stamp (N) is made. This may be undesirable in certain
kono
parents:
diff changeset
500 -- applications as this is uselessly slow if source file data does not
kono
parents:
diff changeset
501 -- change during program execution. When this procedure is called with
kono
parents:
diff changeset
502 -- Cache => True access to source file data does not incur a penalty if
kono
parents:
diff changeset
503 -- this data was previously retrieved.
kono
parents:
diff changeset
504
kono
parents:
diff changeset
505 procedure Dump_Source_File_Names;
kono
parents:
diff changeset
506 -- Prints out the names of all source files that have been read by
kono
parents:
diff changeset
507 -- Read_Source_File, except those that come from the run-time library
kono
parents:
diff changeset
508 -- (i.e. Include_Dir_Default_Prefix). The text is sent to whatever Output
kono
parents:
diff changeset
509 -- is currently using (e.g. standard output or standard error).
kono
parents:
diff changeset
510
kono
parents:
diff changeset
511 -------------------------------------------
kono
parents:
diff changeset
512 -- Representation of Library Information --
kono
parents:
diff changeset
513 -------------------------------------------
kono
parents:
diff changeset
514
kono
parents:
diff changeset
515 -- Associated with each compiled source file is library information, a
kono
parents:
diff changeset
516 -- string of bytes whose exact format is described in the body of Lib.Writ.
kono
parents:
diff changeset
517 -- Compiling a source file generates this library information for the
kono
parents:
diff changeset
518 -- compiled unit, and access the library information for units that were
kono
parents:
diff changeset
519 -- compiled previously on which the unit being compiled depends.
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 -- How this information is stored is up to the implementation of this
kono
parents:
diff changeset
522 -- package. At the interface level, this information is simply associated
kono
parents:
diff changeset
523 -- with its corresponding source.
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 -- Several different implementations are possible:
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 -- 1. The information could be directly associated with the source file,
kono
parents:
diff changeset
528 -- e.g. placed in a resource fork of this file on the Mac, or on
kono
parents:
diff changeset
529 -- MS-DOS, written to the source file after the end of file mark.
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 -- 2. The information could be written into the generated object module
kono
parents:
diff changeset
532 -- if the system supports the inclusion of arbitrary informational
kono
parents:
diff changeset
533 -- byte streams into object files. In this case there must be a naming
kono
parents:
diff changeset
534 -- convention that allows object files to be located given the name of
kono
parents:
diff changeset
535 -- the corresponding source file.
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 -- 3. The information could be written to a separate file, whose name is
kono
parents:
diff changeset
538 -- related to the name of the source file by a fixed convention.
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 -- Which of these three methods is chosen depends on the constraints of the
kono
parents:
diff changeset
541 -- host operating system. The interface described here is independent of
kono
parents:
diff changeset
542 -- which of these approaches is used. Currently all versions of GNAT use
kono
parents:
diff changeset
543 -- the third approach with a file name of xxx.ali where xxx is the source
kono
parents:
diff changeset
544 -- file name.
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 -------------------------------
kono
parents:
diff changeset
547 -- Library Information Input --
kono
parents:
diff changeset
548 -------------------------------
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 -- These subprograms are used by the binder to read library information
kono
parents:
diff changeset
551 -- files, see section above for representation of these files.
kono
parents:
diff changeset
552
kono
parents:
diff changeset
553 function Read_Library_Info
kono
parents:
diff changeset
554 (Lib_File : File_Name_Type;
kono
parents:
diff changeset
555 Fatal_Err : Boolean := False) return Text_Buffer_Ptr;
kono
parents:
diff changeset
556 -- Allocates a Text_Buffer of appropriate length and reads in the entire
kono
parents:
diff changeset
557 -- source of the library information from the library information file
kono
parents:
diff changeset
558 -- whose name is given by the parameter Name.
kono
parents:
diff changeset
559 --
kono
parents:
diff changeset
560 -- See description of Read_Source_File for details on the format of the
kono
parents:
diff changeset
561 -- returned text buffer (the format is identical). The lower bound of
kono
parents:
diff changeset
562 -- the Text_Buffer is always zero
kono
parents:
diff changeset
563 --
kono
parents:
diff changeset
564 -- If the specified file cannot be opened, then the action depends on
kono
parents:
diff changeset
565 -- Fatal_Err. If Fatal_Err is True, an error message is given and the
kono
parents:
diff changeset
566 -- compilation is abandoned. Otherwise if Fatal_Err is False, then null
kono
parents:
diff changeset
567 -- is returned. Note that the Lib_File is a simple name which does not
kono
parents:
diff changeset
568 -- include any directory information. The implementation is responsible
kono
parents:
diff changeset
569 -- for searching for the file in appropriate directories.
kono
parents:
diff changeset
570 --
kono
parents:
diff changeset
571 -- If Opt.Check_Object_Consistency is set to True then this routine checks
kono
parents:
diff changeset
572 -- whether the object file corresponding to the Lib_File is consistent with
kono
parents:
diff changeset
573 -- it. The object file is inconsistent if the object does not exist or if
kono
parents:
diff changeset
574 -- it has an older time stamp than Lib_File. This check is not performed
kono
parents:
diff changeset
575 -- when the Lib_File is "locked" (i.e. read/only) because in this case the
kono
parents:
diff changeset
576 -- object file may be buried in a library. In case of inconsistencies
kono
parents:
diff changeset
577 -- Read_Library_Info behaves as if it did not find Lib_File (namely if
kono
parents:
diff changeset
578 -- Fatal_Err is False, null is returned).
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580 function Read_Library_Info_From_Full
kono
parents:
diff changeset
581 (Full_Lib_File : File_Name_Type;
kono
parents:
diff changeset
582 Lib_File_Attr : access File_Attributes;
kono
parents:
diff changeset
583 Fatal_Err : Boolean := False) return Text_Buffer_Ptr;
kono
parents:
diff changeset
584 -- Same as Read_Library_Info, except Full_Lib_File must contains the full
kono
parents:
diff changeset
585 -- path to the library file (instead of having Read_Library_Info recompute
kono
parents:
diff changeset
586 -- it).
kono
parents:
diff changeset
587 -- Lib_File_Attr should be an initialized set of attributes for the
kono
parents:
diff changeset
588 -- library file (it can be initialized to Unknown_Attributes, but in
kono
parents:
diff changeset
589 -- general will have been initialized by a previous call to Find_File).
kono
parents:
diff changeset
590
kono
parents:
diff changeset
591 function Full_Library_Info_Name return File_Name_Type;
kono
parents:
diff changeset
592 function Full_Object_File_Name return File_Name_Type;
kono
parents:
diff changeset
593 -- Returns the full name of the library/object file most recently read
kono
parents:
diff changeset
594 -- using Read_Library_Info, including appropriate directory information.
kono
parents:
diff changeset
595 -- Calling this routine entails no library file directory lookup
kono
parents:
diff changeset
596 -- penalty. Note that the object file corresponding to a library file
kono
parents:
diff changeset
597 -- is not actually read. Its time stamp is affected when the flag
kono
parents:
diff changeset
598 -- Opt.Check_Object_Consistency is set.
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 function Current_Library_File_Stamp return Time_Stamp_Type;
kono
parents:
diff changeset
601 function Current_Object_File_Stamp return Time_Stamp_Type;
kono
parents:
diff changeset
602 -- The time stamps of the files returned by the previous two routines.
kono
parents:
diff changeset
603 -- It is an error to call Current_Object_File_Stamp if
kono
parents:
diff changeset
604 -- Opt.Check_Object_Consistency is set to False.
kono
parents:
diff changeset
605
kono
parents:
diff changeset
606 procedure Full_Lib_File_Name
kono
parents:
diff changeset
607 (N : File_Name_Type;
kono
parents:
diff changeset
608 Lib_File : out File_Name_Type;
kono
parents:
diff changeset
609 Attr : out File_Attributes);
kono
parents:
diff changeset
610 function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type;
kono
parents:
diff changeset
611 -- Returns the full name of library file N. N should not include
kono
parents:
diff changeset
612 -- path information. Note that if the file cannot be located No_File is
kono
parents:
diff changeset
613 -- returned for the first routine and an all blank time stamp is returned
kono
parents:
diff changeset
614 -- for the second (this is not an error situation). The full name includes
kono
parents:
diff changeset
615 -- the appropriate directory information. The library file directory lookup
kono
parents:
diff changeset
616 -- penalty is incurred every single time this routine is called.
kono
parents:
diff changeset
617 -- The procedural version also returns some file attributes for the ALI
kono
parents:
diff changeset
618 -- file (to save on system calls later on).
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 function Lib_File_Name
kono
parents:
diff changeset
621 (Source_File : File_Name_Type;
kono
parents:
diff changeset
622 Munit_Index : Nat := 0) return File_Name_Type;
kono
parents:
diff changeset
623 -- Given the name of a source file, returns the name of the corresponding
kono
parents:
diff changeset
624 -- library information file. This may be the name of the object file or of
kono
parents:
diff changeset
625 -- a separate file used to store the library information. In the current
kono
parents:
diff changeset
626 -- implementation, a separate file (the ALI file) is always used. In either
kono
parents:
diff changeset
627 -- case the returned result is suitable for calling Read_Library_Info. The
kono
parents:
diff changeset
628 -- Munit_Index is the unit index in multiple unit per file mode, or zero in
kono
parents:
diff changeset
629 -- normal single unit per file mode (used to add ~nnn suffix). Note: this
kono
parents:
diff changeset
630 -- subprogram is in this section because it is used by the compiler to
kono
parents:
diff changeset
631 -- determine the proper library information names to be placed in the
kono
parents:
diff changeset
632 -- generated library information file.
kono
parents:
diff changeset
633
kono
parents:
diff changeset
634 -----------------
kono
parents:
diff changeset
635 -- Termination --
kono
parents:
diff changeset
636 -----------------
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 Current_Exit_Status : Integer := 0;
kono
parents:
diff changeset
639 -- Exit status that is set with procedure OS_Exit_Through_Exception below
kono
parents:
diff changeset
640 -- and can be used in exception handler for Types.Terminate_Program to call
kono
parents:
diff changeset
641 -- Set_Exit_Status as the last action of the program.
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 procedure OS_Exit_Through_Exception (Status : Integer);
kono
parents:
diff changeset
644 pragma No_Return (OS_Exit_Through_Exception);
kono
parents:
diff changeset
645 -- Set the Current_Exit_Status, then raise Types.Terminate_Program
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 type Exit_Code_Type is (
kono
parents:
diff changeset
648 E_Success, -- No warnings or errors
kono
parents:
diff changeset
649 E_Warnings, -- Compiler warnings generated
kono
parents:
diff changeset
650 E_No_Code, -- No code generated
kono
parents:
diff changeset
651 E_No_Compile, -- Compilation not needed (smart recompilation)
kono
parents:
diff changeset
652 E_Errors, -- Compiler error messages generated
kono
parents:
diff changeset
653 E_Fatal, -- Fatal (serious) error, e.g. source file not found
kono
parents:
diff changeset
654 E_Abort); -- Internally detected compiler error
kono
parents:
diff changeset
655
kono
parents:
diff changeset
656 procedure Exit_Program (Exit_Code : Exit_Code_Type);
kono
parents:
diff changeset
657 pragma No_Return (Exit_Program);
kono
parents:
diff changeset
658 -- A call to Exit_Program terminates execution with the given status. A
kono
parents:
diff changeset
659 -- status of zero indicates normal completion, a non-zero status indicates
kono
parents:
diff changeset
660 -- abnormal termination.
kono
parents:
diff changeset
661
kono
parents:
diff changeset
662 -------------------------
kono
parents:
diff changeset
663 -- Command Line Access --
kono
parents:
diff changeset
664 -------------------------
kono
parents:
diff changeset
665
kono
parents:
diff changeset
666 -- Direct interface to command line parameters. (We don't want to use
kono
parents:
diff changeset
667 -- the predefined command line package because it defines functions
kono
parents:
diff changeset
668 -- returning string)
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 function Arg_Count return Natural;
kono
parents:
diff changeset
671 pragma Import (C, Arg_Count, "__gnat_arg_count");
kono
parents:
diff changeset
672 -- Get number of arguments (note: optional globbing may be enabled)
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 procedure Fill_Arg (A : System.Address; Arg_Num : Integer);
kono
parents:
diff changeset
675 pragma Import (C, Fill_Arg, "__gnat_fill_arg");
kono
parents:
diff changeset
676 -- Store one argument
kono
parents:
diff changeset
677
kono
parents:
diff changeset
678 function Len_Arg (Arg_Num : Integer) return Integer;
kono
parents:
diff changeset
679 pragma Import (C, Len_Arg, "__gnat_len_arg");
kono
parents:
diff changeset
680 -- Get length of argument
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 ALI_Default_Suffix : constant String_Ptr := new String'("ali");
kono
parents:
diff changeset
683 ALI_Suffix : String_Ptr := ALI_Default_Suffix;
kono
parents:
diff changeset
684 -- The suffixes used for the ALI files
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 function Prep_Suffix return String;
kono
parents:
diff changeset
687 -- The suffix used for preprocessed files
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 private
kono
parents:
diff changeset
690
kono
parents:
diff changeset
691 Current_Main : File_Name_Type := No_File;
kono
parents:
diff changeset
692 -- Used to save a simple file name between calls to Next_Main_Source and
kono
parents:
diff changeset
693 -- Read_Source_File. If the file name argument to Read_Source_File is
kono
parents:
diff changeset
694 -- No_File, that indicates that the file whose name was returned by the
kono
parents:
diff changeset
695 -- last call to Next_Main_Source (and stored here) is to be read.
kono
parents:
diff changeset
696
kono
parents:
diff changeset
697 Target_Object_Suffix : constant String := Get_Target_Object_Suffix.all;
kono
parents:
diff changeset
698 -- The suffix used for the target object files
kono
parents:
diff changeset
699
kono
parents:
diff changeset
700 Output_File_Name : File_Name_Type;
kono
parents:
diff changeset
701 -- File_Name_Type for name of open file whose FD is in Output_FD, the name
kono
parents:
diff changeset
702 -- stored does not include the trailing NUL character.
kono
parents:
diff changeset
703
kono
parents:
diff changeset
704 Argument_Count : constant Integer := Arg_Count - 1;
kono
parents:
diff changeset
705 -- Number of arguments (excluding program name)
kono
parents:
diff changeset
706
kono
parents:
diff changeset
707 type File_Name_Array is array (Int range <>) of String_Ptr;
kono
parents:
diff changeset
708 type File_Name_Array_Ptr is access File_Name_Array;
kono
parents:
diff changeset
709 File_Names : File_Name_Array_Ptr :=
kono
parents:
diff changeset
710 new File_Name_Array (1 .. Int (Argument_Count) + 2);
kono
parents:
diff changeset
711 -- As arguments are scanned, file names are stored in this array. The
kono
parents:
diff changeset
712 -- strings do not have terminating NUL files. The array is extensible,
kono
parents:
diff changeset
713 -- because when using project files, there may be more files than
kono
parents:
diff changeset
714 -- arguments on the command line.
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 type File_Index_Array is array (Int range <>) of Int;
kono
parents:
diff changeset
717 type File_Index_Array_Ptr is access File_Index_Array;
kono
parents:
diff changeset
718 File_Indexes : File_Index_Array_Ptr :=
kono
parents:
diff changeset
719 new File_Index_Array (1 .. Int (Argument_Count) + 2);
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 Current_File_Name_Index : Int := 0;
kono
parents:
diff changeset
722 -- The index in File_Names of the last file opened by Next_Main_Source
kono
parents:
diff changeset
723 -- or Next_Main_Lib_File. The value 0 indicates that no files have been
kono
parents:
diff changeset
724 -- opened yet.
kono
parents:
diff changeset
725
kono
parents:
diff changeset
726 procedure Create_File_And_Check
kono
parents:
diff changeset
727 (Fdesc : out File_Descriptor;
kono
parents:
diff changeset
728 Fmode : Mode);
kono
parents:
diff changeset
729 -- Create file whose name (NUL terminated) is in Name_Buffer (with the
kono
parents:
diff changeset
730 -- length in Name_Len), and place the resulting descriptor in Fdesc. Issue
kono
parents:
diff changeset
731 -- message and exit with fatal error if file cannot be created. The Fmode
kono
parents:
diff changeset
732 -- parameter is set to either Text or Binary (for details see description
kono
parents:
diff changeset
733 -- of System.OS_Lib.Create_File).
kono
parents:
diff changeset
734
kono
parents:
diff changeset
735 procedure Open_File_To_Append_And_Check
kono
parents:
diff changeset
736 (Fdesc : out File_Descriptor;
kono
parents:
diff changeset
737 Fmode : Mode);
kono
parents:
diff changeset
738 -- Opens the file whose name (NUL terminated) is in Name_Buffer (with the
kono
parents:
diff changeset
739 -- length in Name_Len), and place the resulting descriptor in Fdesc. Issue
kono
parents:
diff changeset
740 -- message and exit with fatal error if file cannot be opened. The Fmode
kono
parents:
diff changeset
741 -- parameter is set to either Text or Binary (for details see description
kono
parents:
diff changeset
742 -- of System.OS_Lib.Open_Append).
kono
parents:
diff changeset
743
kono
parents:
diff changeset
744 type Program_Type is (Compiler, Binder, Make, Gnatls, Unspecified);
kono
parents:
diff changeset
745 -- Program currently running
kono
parents:
diff changeset
746 procedure Set_Program (P : Program_Type);
kono
parents:
diff changeset
747 -- Indicates to the body of Osint the program currently running. This
kono
parents:
diff changeset
748 -- procedure is called by the child packages of Osint. A check is made
kono
parents:
diff changeset
749 -- that this procedure is not called more than once.
kono
parents:
diff changeset
750
kono
parents:
diff changeset
751 function More_Files return Boolean;
kono
parents:
diff changeset
752 -- Implements More_Source_Files and More_Lib_Files
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 function Next_Main_File return File_Name_Type;
kono
parents:
diff changeset
755 -- Implements Next_Main_Source and Next_Main_Lib_File
kono
parents:
diff changeset
756
kono
parents:
diff changeset
757 function Object_File_Name (N : File_Name_Type) return File_Name_Type;
kono
parents:
diff changeset
758 -- Constructs the name of the object file corresponding to library file N.
kono
parents:
diff changeset
759 -- If N is a full file name than the returned file name will also be a full
kono
parents:
diff changeset
760 -- file name. Note that no lookup in the library file directories is done
kono
parents:
diff changeset
761 -- for this file. This routine merely constructs the name.
kono
parents:
diff changeset
762
kono
parents:
diff changeset
763 procedure Write_Info (Info : String);
kono
parents:
diff changeset
764 -- Implements Write_Binder_Info, Write_Debug_Info, and Write_Library_Info
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 procedure Write_With_Check (A : Address; N : Integer);
kono
parents:
diff changeset
767 -- Writes N bytes from buffer starting at address A to file whose FD is
kono
parents:
diff changeset
768 -- stored in Output_FD, and whose file name is stored as a File_Name_Type
kono
parents:
diff changeset
769 -- in Output_File_Name. A check is made for disk full, and if this is
kono
parents:
diff changeset
770 -- detected, the file being written is deleted, and a fatal error is
kono
parents:
diff changeset
771 -- signalled.
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 end Osint;