]>
Commit | Line | Data |
---|---|---|
38cbfe40 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- O S I N T -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
fbf5a39b | 9 | -- Copyright (C) 1992-2003 Free Software Foundation, Inc. -- |
38cbfe40 RK |
10 | -- -- |
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 2, 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 COPYING. If not, write -- | |
19 | -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, -- | |
20 | -- MA 02111-1307, USA. -- | |
21 | -- -- | |
22 | -- GNAT was originally developed by the GNAT team at New York University. -- | |
71ff80dc | 23 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
38cbfe40 RK |
24 | -- -- |
25 | ------------------------------------------------------------------------------ | |
26 | ||
27 | -- This package contains the low level, operating system routines used in | |
28 | -- the GNAT compiler and binder for command line processing and file input | |
07fc65c4 | 29 | -- output. |
38cbfe40 RK |
30 | |
31 | with GNAT.OS_Lib; use GNAT.OS_Lib; | |
32 | with System; use System; | |
33 | with Types; use Types; | |
34 | ||
07fc65c4 | 35 | pragma Elaborate (GNAT.OS_Lib); |
38cbfe40 | 36 | |
07fc65c4 | 37 | package Osint is |
38cbfe40 | 38 | |
fbf5a39b AC |
39 | Ada_Include_Path : constant String := "ADA_INCLUDE_PATH"; |
40 | Ada_Objects_Path : constant String := "ADA_OBJECTS_PATH"; | |
41 | Project_Include_Path_File : constant String := "ADA_PRJ_INCLUDE_FILE"; | |
42 | Project_Objects_Path_File : constant String := "ADA_PRJ_OBJECTS_FILE"; | |
43 | ||
44 | procedure Initialize; | |
45 | -- Initialize internal tables | |
46 | ||
38cbfe40 RK |
47 | function Normalize_Directory_Name (Directory : String) return String_Ptr; |
48 | -- Verify and normalize a directory name. If directory name is invalid, | |
49 | -- this will return an empty string. Otherwise it will insure a trailing | |
50 | -- slash and make other normalizations. | |
51 | ||
fbf5a39b | 52 | type File_Type is (Source, Library, Config, Definition, Preprocessing_Data); |
38cbfe40 RK |
53 | |
54 | function Find_File | |
55 | (N : File_Name_Type; | |
56 | T : File_Type) | |
57 | return File_Name_Type; | |
07fc65c4 GB |
58 | -- Finds a source, library or config file depending on the value |
59 | -- of T following the directory search order rules unless N is the | |
60 | -- name of the file just read with Next_Main_File and already | |
61 | -- contains directiory information, in which case just look in the | |
62 | -- Primary_Directory. Returns File_Name_Type of the full file name | |
63 | -- if found, No_File if file not found. Note that for the special | |
64 | -- case of gnat.adc, only the compilation environment directory is | |
65 | -- searched, i.e. the directory where the ali and object files are | |
66 | -- written. Another special case is when Debug_Generated_Code is | |
67 | -- set and the file name ends on ".dg", in which case we look for | |
68 | -- the generated file only in the current directory, since that is | |
69 | -- where it is always built. | |
38cbfe40 RK |
70 | |
71 | function Get_File_Names_Case_Sensitive return Int; | |
72 | pragma Import (C, Get_File_Names_Case_Sensitive, | |
07fc65c4 | 73 | "__gnat_get_file_names_case_sensitive"); |
38cbfe40 | 74 | File_Names_Case_Sensitive : constant Boolean := |
07fc65c4 | 75 | Get_File_Names_Case_Sensitive /= 0; |
38cbfe40 RK |
76 | -- Set to indicate whether the operating system convention is for file |
77 | -- names to be case sensitive (e.g., in Unix, set True), or non case | |
78 | -- sensitive (e.g., in OS/2, set False). | |
79 | ||
80 | procedure Canonical_Case_File_Name (S : in out String); | |
81 | -- Given a file name, converts it to canonical case form. For systems | |
82 | -- where file names are case sensitive, this procedure has no effect. | |
83 | -- If file names are not case sensitive (i.e. for example if you have | |
84 | -- the file "xyz.adb", you can refer to it as XYZ.adb or XyZ.AdB), then | |
85 | -- this call converts the given string to canonical all lower case form, | |
86 | -- so that two file names compare equal if they refer to the same file. | |
87 | ||
88 | function Number_Of_Files return Int; | |
89 | -- gives the total number of filenames found on the command line. | |
90 | ||
91 | procedure Add_File (File_Name : String); | |
92 | -- Called by the subprogram processing the command line for each | |
93 | -- file name found. | |
94 | ||
38cbfe40 RK |
95 | procedure Find_Program_Name; |
96 | -- Put simple name of current program being run (excluding the directory | |
97 | -- path) in Name_Buffer, with the length in Name_Len. | |
98 | ||
99 | function Program_Name (Nam : String) return String_Access; | |
100 | -- In the native compilation case, Create a string containing Nam. In | |
101 | -- the cross compilation case, looks at the prefix of the current | |
102 | -- program being run and prepend it to Nam. For instance if the program | |
103 | -- being run is <target>-gnatmake and Nam is "gcc", the returned value | |
104 | -- will be a pointer to "<target>-gcc". This function clobbers | |
105 | -- Name_Buffer and Name_Len. | |
106 | ||
107 | procedure Write_Program_Name; | |
07fc65c4 GB |
108 | -- Writes name of program as invoked to the current output |
109 | -- (normally standard output). | |
38cbfe40 RK |
110 | |
111 | procedure Fail (S1 : String; S2 : String := ""; S3 : String := ""); | |
07fc65c4 | 112 | pragma No_Return (Fail); |
44d6a706 | 113 | -- Outputs error messages S1 & S2 & S3 preceded by the name of the |
07fc65c4 GB |
114 | -- executing program and exits with E_Fatal. The output goes to |
115 | -- standard error, except if special output is in effect (see Output). | |
38cbfe40 RK |
116 | |
117 | function Is_Directory_Separator (C : Character) return Boolean; | |
118 | -- Returns True if C is a directory separator | |
119 | ||
120 | function Get_Directory (Name : File_Name_Type) return File_Name_Type; | |
121 | -- Get the prefix directory name (if any) from Name. The last separator | |
07fc65c4 GB |
122 | -- is preserved. Return the normalized current directory if there is no |
123 | -- directory part in the name. | |
38cbfe40 RK |
124 | |
125 | function Is_Readonly_Library (File : File_Name_Type) return Boolean; | |
126 | -- Check if this library file is a read-only file. | |
127 | ||
128 | function Strip_Directory (Name : File_Name_Type) return File_Name_Type; | |
129 | -- Strips the prefix directory name (if any) from Name. Returns the | |
07fc65c4 | 130 | -- stripped name. Name cannot end with a directory separator. |
38cbfe40 RK |
131 | |
132 | function Strip_Suffix (Name : File_Name_Type) return File_Name_Type; | |
07fc65c4 | 133 | -- Strips the suffix (the last '.' and whatever comes after it) from Name. |
38cbfe40 RK |
134 | -- Returns the stripped name. |
135 | ||
136 | function Executable_Name (Name : File_Name_Type) return File_Name_Type; | |
137 | -- Given a file name it adds the appropriate suffix at the end so that | |
138 | -- it becomes the name of the executable on the system at end. For | |
139 | -- instance under DOS it adds the ".exe" suffix, whereas under UNIX no | |
140 | -- suffix is added. | |
141 | ||
142 | function File_Stamp (Name : File_Name_Type) return Time_Stamp_Type; | |
143 | -- Returns the time stamp of file Name. Name should include relative | |
144 | -- path information in order to locate it. If the source file cannot be | |
145 | -- opened, or Name = No_File, and all blank time stamp is returned (this is | |
146 | -- not an error situation). | |
147 | ||
38cbfe40 RK |
148 | type String_Access_List is array (Positive range <>) of String_Access; |
149 | -- Deferenced type used to return a list of file specs in | |
150 | -- To_Canonical_File_List. | |
151 | ||
152 | type String_Access_List_Access is access all String_Access_List; | |
07fc65c4 | 153 | -- Type used to return a String_Access_List without dragging in secondary |
38cbfe40 RK |
154 | -- stack. |
155 | ||
156 | function To_Canonical_File_List | |
07fc65c4 GB |
157 | (Wildcard_Host_File : String; |
158 | Only_Dirs : Boolean) | |
159 | return String_Access_List_Access; | |
38cbfe40 RK |
160 | -- Expand a wildcard host syntax file or directory specification (e.g. on |
161 | -- a VMS host, any file or directory spec that contains: | |
162 | -- "*", or "%", or "...") | |
163 | -- and return a list of valid Unix syntax file or directory specs. | |
164 | -- If Only_Dirs is True, then only return directories. | |
165 | ||
166 | function To_Canonical_Dir_Spec | |
167 | (Host_Dir : String; | |
168 | Prefix_Style : Boolean) | |
07fc65c4 | 169 | return String_Access; |
38cbfe40 RK |
170 | -- Convert a host syntax directory specification (e.g. on a VMS host: |
171 | -- "SYS$DEVICE:[DIR]") to canonical (Unix) syntax (e.g. "/sys$device/dir"). | |
172 | -- If Prefix_Style then make it a valid file specification prefix. | |
173 | -- A file specification prefix is a directory specification that | |
174 | -- can be appended with a simple file specification to yield a valid | |
175 | -- absolute or relative path to a file. On a conversion to Unix syntax | |
176 | -- this simply means the spec has a trailing slash ("/"). | |
177 | ||
178 | function To_Canonical_File_Spec | |
179 | (Host_File : String) | |
07fc65c4 | 180 | return String_Access; |
38cbfe40 RK |
181 | -- Convert a host syntax file specification (e.g. on a VMS host: |
182 | -- "SYS$DEVICE:[DIR]FILE.EXT;69 to canonical (Unix) syntax (e.g. | |
183 | -- "/sys$device/dir/file.ext.69"). | |
184 | ||
185 | function To_Canonical_Path_Spec | |
186 | (Host_Path : String) | |
07fc65c4 | 187 | return String_Access; |
38cbfe40 RK |
188 | -- Convert a host syntax Path specification (e.g. on a VMS host: |
189 | -- "SYS$DEVICE:[BAR],DISK$USER:[FOO] to canonical (Unix) syntax (e.g. | |
190 | -- "/sys$device/foo:disk$user/foo"). | |
191 | ||
192 | function To_Host_Dir_Spec | |
193 | (Canonical_Dir : String; | |
194 | Prefix_Style : Boolean) | |
07fc65c4 | 195 | return String_Access; |
38cbfe40 RK |
196 | -- Convert a canonical syntax directory specification to host syntax. |
197 | -- The Prefix_Style flag is currently ignored but should be set to | |
198 | -- False. | |
199 | ||
200 | function To_Host_File_Spec | |
201 | (Canonical_File : String) | |
07fc65c4 | 202 | return String_Access; |
38cbfe40 RK |
203 | -- Convert a canonical syntax file specification to host syntax. |
204 | ||
205 | ------------------------- | |
206 | -- Search Dir Routines -- | |
207 | ------------------------- | |
208 | ||
209 | procedure Add_Default_Search_Dirs; | |
210 | -- This routine adds the default search dirs indicated by the | |
211 | -- environment variables and sdefault package. | |
212 | ||
213 | procedure Add_Lib_Search_Dir (Dir : String); | |
214 | -- Add Dir at the end of the library file search path | |
215 | ||
216 | procedure Add_Src_Search_Dir (Dir : String); | |
217 | -- Add Dir at the end of the source file search path | |
218 | ||
219 | procedure Get_Next_Dir_In_Path_Init | |
220 | (Search_Path : String_Access); | |
221 | function Get_Next_Dir_In_Path | |
222 | (Search_Path : String_Access) | |
223 | return String_Access; | |
224 | -- These subprograms are used to parse out the directory names in a | |
225 | -- search path specified by a Search_Path argument. The procedure | |
226 | -- initializes an internal pointer to point to the initial directory | |
44d6a706 | 227 | -- name, and calls to the function return successive directory names, |
38cbfe40 RK |
228 | -- with a null pointer marking the end of the list. |
229 | ||
07fc65c4 GB |
230 | type Search_File_Type is (Include, Objects); |
231 | ||
232 | procedure Add_Search_Dirs | |
233 | (Search_Path : String_Ptr; | |
234 | Path_Type : Search_File_Type); | |
235 | -- These procedure adds all the search directories that are in Search_Path | |
236 | -- in the proper file search path (library or source) | |
237 | ||
38cbfe40 RK |
238 | function Get_Primary_Src_Search_Directory return String_Ptr; |
239 | -- Retrieved the primary directory (directory containing the main source | |
07fc65c4 | 240 | -- file for Gnatmake. |
38cbfe40 RK |
241 | |
242 | function Nb_Dir_In_Src_Search_Path return Natural; | |
243 | function Dir_In_Src_Search_Path (Position : Natural) return String_Ptr; | |
244 | -- Functions to access the directory names in the source search path | |
245 | ||
246 | function Nb_Dir_In_Obj_Search_Path return Natural; | |
247 | function Dir_In_Obj_Search_Path (Position : Natural) return String_Ptr; | |
248 | -- Functions to access the directory names in the Object search path | |
249 | ||
07fc65c4 GB |
250 | Include_Search_File : constant String_Access := |
251 | new String'("ada_source_path"); | |
252 | Objects_Search_File : constant String_Access := | |
253 | new String'("ada_object_path"); | |
254 | -- Names of the files containg the default include or objects search | |
255 | -- directories. These files, located in Sdefault.Search_Dir_Prefix, do | |
256 | -- not necessarily exist. | |
38cbfe40 RK |
257 | |
258 | function Read_Default_Search_Dirs | |
07fc65c4 GB |
259 | (Search_Dir_Prefix : String_Access; |
260 | Search_File : String_Access; | |
38cbfe40 | 261 | Search_Dir_Default_Name : String_Access) |
07fc65c4 | 262 | return String_Access; |
38cbfe40 RK |
263 | -- Read and return the default search directories from the file located |
264 | -- in Search_Dir_Prefix (as modified by update_path) and named Search_File. | |
265 | -- If no such file exists or an error occurs then instead return the | |
266 | -- Search_Dir_Default_Name (as modified by update_path). | |
267 | ||
07fc65c4 GB |
268 | function Get_RTS_Search_Dir |
269 | (Search_Dir : String; | |
270 | File_Type : Search_File_Type) | |
271 | return String_Ptr; | |
272 | -- This function retrieves the paths to the search (resp. lib) dirs and | |
273 | -- return them. The search dir can be absolute or relative. If the search | |
274 | -- dir contains Include_Search_File (resp. Object_Search_File), then this | |
275 | -- function reads and returns the default search directories from the file. | |
276 | -- Otherwise, if the directory is absolute, it will try to find 'adalib' | |
277 | -- (resp. 'adainclude'). If found, null is returned. If the directory is | |
278 | -- relative, the following directories for the directories 'adalib' and | |
279 | -- 'adainclude' will be scanned: | |
280 | -- | |
281 | -- - current directory (from which the tool has been spawned) | |
282 | -- - $GNAT_ROOT/gcc/gcc-lib/$targ/$vers/ | |
283 | -- - $GNAT_ROOT/gcc/gcc-lib/$targ/$vers/rts- | |
284 | -- | |
285 | -- The scan will stop as soon as the directory being searched for (adalib | |
286 | -- or adainclude) is found. If the scan fails, null is returned. | |
287 | ||
38cbfe40 RK |
288 | ----------------------- |
289 | -- Source File Input -- | |
290 | ----------------------- | |
291 | ||
292 | -- Source file input routines are used by the compiler to read the main | |
293 | -- source files and the subsidiary source files (e.g. with'ed units), and | |
294 | -- also by the binder to check presence/time stamps of sources. | |
295 | ||
38cbfe40 RK |
296 | procedure Read_Source_File |
297 | (N : File_Name_Type; | |
298 | Lo : Source_Ptr; | |
299 | Hi : out Source_Ptr; | |
300 | Src : out Source_Buffer_Ptr; | |
301 | T : File_Type := Source); | |
302 | -- Allocates a Source_Buffer of appropriate length and then reads the | |
303 | -- entire contents of the source file N into the buffer. The address of | |
304 | -- the allocated buffer is returned in Src. | |
305 | -- | |
306 | -- Each line of text is terminated by one of the sequences: | |
307 | -- | |
308 | -- CR | |
309 | -- CR/LF | |
310 | -- LF/CR | |
311 | -- LF | |
312 | ||
313 | -- The source is terminated by an EOF (16#1A#) character, which is | |
314 | -- the last charcater of the returned source bufer (note that any | |
315 | -- EOF characters in positions other than the last source character | |
316 | -- are treated as representing blanks). | |
317 | -- | |
318 | -- The logical lower bound of the source buffer is the input value of Lo, | |
319 | -- and on exit Hi is set to the logical upper bound of the source buffer. | |
320 | -- Note that the returned value in Src points to an array with a physical | |
321 | -- lower bound of zero. This virtual origin addressing approach means that | |
322 | -- a constrained array pointer can be used with a low bound of zero which | |
323 | -- results in more efficient code. | |
324 | -- | |
325 | -- If the given file cannot be opened, then the action depends on whether | |
326 | -- this file is the current main unit (i.e. its name matches the name | |
327 | -- returned by the most recent call to Next_Main_Source). If so, then the | |
328 | -- failure to find the file is a fatal error, an error message is output, | |
329 | -- and program execution is terminated. Otherwise (for the case of a | |
330 | -- subsidiary source loaded directly or indirectly using with), a file | |
331 | -- not found condition causes null to be set as the result value. | |
332 | -- | |
333 | -- Note that the name passed to this function is the simple file name, | |
334 | -- without any directory information. The implementation is responsible | |
335 | -- for searching for the file in the appropriate directories. | |
336 | -- | |
337 | -- Note the special case that if the file name is gnat.adc, then the | |
338 | -- search for the file is done ONLY in the directory corresponding to | |
339 | -- the current compilation environment, i.e. in the same directory | |
340 | -- where the ali and object files will be written. | |
341 | ||
342 | function Full_Source_Name return File_Name_Type; | |
343 | function Current_Source_File_Stamp return Time_Stamp_Type; | |
344 | -- Returns the full name/time stamp of the source file most recently read | |
345 | -- using Read_Source_File. Calling this routine entails no source file | |
346 | -- directory lookup penalty. | |
347 | ||
348 | function Full_Source_Name (N : File_Name_Type) return File_Name_Type; | |
349 | function Source_File_Stamp (N : File_Name_Type) return Time_Stamp_Type; | |
350 | -- Returns the full name/time stamp of the source file whose simple name | |
351 | -- is N which should not include path information. Note that if the file | |
352 | -- cannot be located No_File is returned for the first routine and an | |
353 | -- all blank time stamp is returned for the second (this is not an error | |
354 | -- situation). The full name includes the appropriate directory | |
355 | -- information. The source file directory lookup penalty is incurred | |
356 | -- every single time the routines are called unless you have previously | |
357 | -- called Source_File_Data (Cache => True). See below. | |
358 | ||
359 | function Matching_Full_Source_Name | |
360 | (N : File_Name_Type; | |
361 | T : Time_Stamp_Type) | |
362 | return File_Name_Type; | |
363 | -- Same semantics than Full_Source_Name but will search on the source | |
364 | -- path until a source file with time stamp matching T is found. If | |
365 | -- none is found returns No_File. | |
366 | ||
367 | procedure Source_File_Data (Cache : Boolean); | |
368 | -- By default source file data (full source file name and time stamp) | |
369 | -- are looked up every time a call to Full_Source_Name (N) or | |
370 | -- Source_File_Stamp (N) is made. This may be undesirable in certain | |
371 | -- applications as this is uselessly slow if source file data does not | |
372 | -- change during program execution. When this procedure is called with | |
373 | -- Cache => True access to source file data does not encurr a penalty if | |
374 | -- this data was previously retrieved. | |
375 | ||
376 | ------------------------------------------- | |
377 | -- Representation of Library Information -- | |
378 | ------------------------------------------- | |
379 | ||
380 | -- Associated with each compiled source file is library information, | |
381 | -- a string of bytes whose exact format is described in the body of | |
382 | -- Lib.Writ. Compiling a source file generates this library information | |
383 | -- for the compiled unit, and access the library information for units | |
384 | -- that were compiled previously on which the unit being compiled depends. | |
385 | ||
386 | -- How this information is stored is up to the implementation of this | |
387 | -- package. At the interface level, this information is simply associated | |
388 | -- with its corresponding source. | |
389 | ||
390 | -- Several different implementations are possible: | |
391 | ||
392 | -- 1. The information could be directly associated with the source file, | |
393 | -- e.g. placed in a resource fork of this file on the Mac, or on | |
394 | -- MS-DOS, written to the source file after the end of file mark. | |
395 | ||
396 | -- 2. The information could be written into the generated object module | |
397 | -- if the system supports the inclusion of arbitrary informational | |
398 | -- byte streams into object files. In this case there must be a naming | |
399 | -- convention that allows object files to be located given the name of | |
400 | -- the corresponding source file. | |
401 | ||
402 | -- 3. The information could be written to a separate file, whose name is | |
403 | -- related to the name of the source file by a fixed convention. | |
404 | ||
638e383e | 405 | -- Which of these three methods is chosen depends on the constraints of the |
38cbfe40 RK |
406 | -- host operating system. The interface described here is independent of |
407 | -- which of these approaches is used. | |
408 | ||
409 | ------------------------------- | |
410 | -- Library Information Input -- | |
411 | ------------------------------- | |
412 | ||
413 | -- These subprograms are used by the binder to read library information | |
414 | -- files, see section above for representation of these files. | |
415 | ||
38cbfe40 RK |
416 | function Read_Library_Info |
417 | (Lib_File : File_Name_Type; | |
418 | Fatal_Err : Boolean := False) | |
419 | return Text_Buffer_Ptr; | |
420 | -- Allocates a Text_Buffer of appropriate length and reads in the entire | |
421 | -- source of the library information from the library information file | |
422 | -- whose name is given by the parameter Name. | |
423 | -- | |
424 | -- See description of Read_Source_File for details on the format of the | |
425 | -- returned text buffer (the format is identical). THe lower bound of | |
426 | -- the Text_Buffer is always zero | |
427 | -- | |
428 | -- If the specified file cannot be opened, then the action depends on | |
429 | -- Fatal_Err. If Fatal_Err is True, an error message is given and the | |
430 | -- compilation is abandoned. Otherwise if Fatal_Err is False, then null | |
431 | -- is returned. Note that the Lib_File is a simple name which does not | |
432 | -- include any directory information. The implementation is responsible | |
433 | -- for searching for the file in appropriate directories. | |
434 | -- | |
435 | -- If Opt.Check_Object_Consistency is set to True then this routine | |
436 | -- checks whether the object file corresponding to the Lib_File is | |
437 | -- consistent with it. The object file is inconsistent if the object | |
438 | -- does not exist or if it has an older time stamp than Lib_File. | |
439 | -- This check is not performed when the Lib_File is "locked" (i.e. | |
440 | -- read/only) because in this case the object file may be buried | |
441 | -- in a library. In case of inconsistencies Read_Library_Info | |
442 | -- behaves as if it did not find Lib_File (namely if Fatal_Err is | |
443 | -- False, null is returned). | |
444 | ||
38cbfe40 RK |
445 | function Full_Library_Info_Name return File_Name_Type; |
446 | function Full_Object_File_Name return File_Name_Type; | |
447 | -- Returns the full name of the library/object file most recently read | |
448 | -- using Read_Library_Info, including appropriate directory information. | |
449 | -- Calling this routine entails no library file directory lookup | |
450 | -- penalty. Note that the object file corresponding to a library file | |
451 | -- is not actually read. Its time stamp is fected when the flag | |
452 | -- Opt.Check_Object_Consistency is set. | |
453 | ||
454 | function Current_Library_File_Stamp return Time_Stamp_Type; | |
455 | function Current_Object_File_Stamp return Time_Stamp_Type; | |
456 | -- The time stamps of the files returned by the previous two routines. | |
457 | -- It is an error to call Current_Object_File_Stamp if | |
458 | -- Opt.Check_Object_Consistency is set to False. | |
459 | ||
460 | function Full_Lib_File_Name (N : File_Name_Type) return File_Name_Type; | |
461 | function Library_File_Stamp (N : File_Name_Type) return Time_Stamp_Type; | |
462 | -- Returns the full name/time stamp of library file N. N should not | |
463 | -- include path information. Note that if the file cannot be located | |
464 | -- No_File is returned for the first routine and an all blank time stamp | |
465 | -- is returned for the second (this is not an error situation). The | |
466 | -- full name includes the appropriate directory information. The library | |
467 | -- file directory lookup penalty is incurred every single time this | |
468 | -- routine is called. | |
469 | ||
38cbfe40 RK |
470 | function Lib_File_Name (Source_File : File_Name_Type) return File_Name_Type; |
471 | -- Given the name of a source file, returns the name of the corresponding | |
472 | -- library information file. This may be the name of the object file, or | |
473 | -- of a separate file used to store the library information. In either case | |
474 | -- the returned result is suitable for use in a call to Read_Library_Info. | |
475 | -- Note: this subprogram is in this section because it is used by the | |
476 | -- compiler to determine the proper library information names to be placed | |
477 | -- in the generated library information file. | |
478 | ||
38cbfe40 RK |
479 | ----------------- |
480 | -- Termination -- | |
481 | ----------------- | |
482 | ||
483 | type Exit_Code_Type is ( | |
484 | E_Success, -- No warnings or errors | |
485 | E_Warnings, -- Compiler warnings generated | |
486 | E_No_Code, -- No code generated | |
487 | E_No_Compile, -- Compilation not needed (smart recompilation) | |
488 | E_Errors, -- Compiler error messages generated | |
489 | E_Fatal, -- Fatal (serious) error, e.g. source file not found | |
490 | E_Abort); -- Internally detected compiler error | |
491 | ||
492 | procedure Exit_Program (Exit_Code : Exit_Code_Type); | |
07fc65c4 | 493 | pragma No_Return (Exit_Program); |
38cbfe40 RK |
494 | -- A call to Exit_Program terminates execution with the given status. |
495 | -- A status of zero indicates normal completion, a non-zero status | |
496 | -- indicates abnormal termination. | |
497 | ||
498 | ------------------------- | |
499 | -- Command Line Access -- | |
500 | ------------------------- | |
501 | ||
502 | -- Direct interface to command line parameters. (We don't want to use | |
503 | -- the predefined command line package because it defines functions | |
504 | -- returning string) | |
505 | ||
506 | function Arg_Count return Natural; | |
507 | pragma Import (C, Arg_Count, "__gnat_arg_count"); | |
508 | -- Get number of arguments (note: optional globbing may be enabled) | |
509 | ||
510 | procedure Fill_Arg (A : System.Address; Arg_Num : Integer); | |
511 | pragma Import (C, Fill_Arg, "__gnat_fill_arg"); | |
512 | -- Store one argument | |
513 | ||
514 | function Len_Arg (Arg_Num : Integer) return Integer; | |
515 | pragma Import (C, Len_Arg, "__gnat_len_arg"); | |
516 | -- Get length of argument | |
517 | ||
07fc65c4 GB |
518 | private |
519 | ||
520 | ALI_Suffix : constant String_Ptr := new String'("ali"); | |
521 | -- The suffix used for the library files (also known as ALI files). | |
522 | ||
523 | Current_Main : File_Name_Type := No_File; | |
524 | -- Used to save a simple file name between calls to Next_Main_Source and | |
525 | -- Read_Source_File. If the file name argument to Read_Source_File is | |
526 | -- No_File, that indicates that the file whose name was returned by the | |
527 | -- last call to Next_Main_Source (and stored here) is to be read. | |
528 | ||
529 | Object_Suffix : constant String := Get_Object_Suffix.all; | |
530 | -- The suffix used for the object files. | |
531 | ||
532 | Output_FD : File_Descriptor; | |
533 | -- The file descriptor for the current library info, tree or binder output | |
534 | ||
535 | Output_File_Name : File_Name_Type; | |
536 | -- File_Name_Type for name of open file whose FD is in Output_FD, the name | |
537 | -- stored does not include the trailing NUL character. | |
538 | ||
539 | Argument_Count : constant Integer := Arg_Count - 1; | |
540 | -- Number of arguments (excluding program name) | |
541 | ||
542 | type File_Name_Array is array (Int range <>) of String_Ptr; | |
543 | type File_Name_Array_Ptr is access File_Name_Array; | |
544 | File_Names : File_Name_Array_Ptr := | |
545 | new File_Name_Array (1 .. Int (Argument_Count) + 2); | |
fbf5a39b AC |
546 | -- As arguments are scanned, file names are stored in this array |
547 | -- The strings do not have terminating NUL files. The array is | |
548 | -- extensible, because when using project files, there may be | |
549 | -- more files than arguments on the command line. | |
07fc65c4 GB |
550 | |
551 | Current_File_Name_Index : Int := 0; | |
552 | -- The index in File_Names of the last file opened by Next_Main_Source | |
553 | -- or Next_Main_Lib_File. The value 0 indicates that no files have been | |
554 | -- opened yet. | |
555 | ||
556 | procedure Create_File_And_Check | |
557 | (Fdesc : out File_Descriptor; | |
558 | Fmode : Mode); | |
559 | -- Create file whose name (NUL terminated) is in Name_Buffer (with the | |
560 | -- length in Name_Len), and place the resulting descriptor in Fdesc. | |
561 | -- Issue message and exit with fatal error if file cannot be created. | |
562 | -- The Fmode parameter is set to either Text or Binary (see description | |
563 | -- of GNAT.OS_Lib.Create_File). | |
564 | ||
565 | type Program_Type is (Compiler, Binder, Make, Gnatls, Unspecified); | |
566 | -- Program currently running | |
567 | procedure Set_Program (P : Program_Type); | |
568 | -- Indicates to the body of Osint the program currently running. | |
569 | -- This procedure is called by the child packages of Osint. | |
570 | -- A check is made that this procedure is not called several times. | |
571 | ||
572 | function More_Files return Boolean; | |
573 | -- Implements More_Source_Files and More_Lib_Files. | |
574 | ||
575 | function Next_Main_File return File_Name_Type; | |
576 | -- Implements Next_Main_Source and Next_Main_Lib_File. | |
577 | ||
578 | function Object_File_Name (N : File_Name_Type) return File_Name_Type; | |
579 | -- Constructs the name of the object file corresponding to library | |
580 | -- file N. If N is a full file name than the returned file name will | |
581 | -- also be a full file name. Note that no lookup in the library file | |
582 | -- directories is done for this file. This routine merely constructs | |
583 | -- the name. | |
584 | ||
585 | procedure Write_Info (Info : String); | |
586 | -- Implementation of Write_Binder_Info, Write_Debug_Info and | |
587 | -- Write_Library_Info (identical) | |
588 | ||
38cbfe40 | 589 | end Osint; |