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