2003-11-27 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / ada / fname.adb
blobb771772556a0035026145e1cf08edab9b0b45cf1
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F N A M E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2003, 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 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 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
28 -- --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
31 -- --
32 ------------------------------------------------------------------------------
34 with Alloc;
35 with Hostparm; use Hostparm;
36 with Namet; use Namet;
37 with Table;
39 package body Fname is
41 -----------------------------
42 -- Dummy Table Definitions --
43 -----------------------------
45 -- The following table was used in old versions of the compiler. We retain
46 -- the declarations here for compatibility with old tree files. The new
47 -- version of the compiler does not use this table, and will write out a
48 -- dummy empty table for Tree_Write.
50 type SFN_Entry is record
51 U : Unit_Name_Type;
52 F : File_Name_Type;
53 end record;
55 package SFN_Table is new Table.Table (
56 Table_Component_Type => SFN_Entry,
57 Table_Index_Type => Int,
58 Table_Low_Bound => 0,
59 Table_Initial => Alloc.SFN_Table_Initial,
60 Table_Increment => Alloc.SFN_Table_Increment,
61 Table_Name => "Fname_Dummy_Table");
62 ----------------------------
63 -- Get_Expected_Unit_Type --
64 ----------------------------
66 -- We assume that a file name whose last character is a lower case b is
67 -- a body and a file name whose last character is a lower case s is a
68 -- spec. If any other character is found (e.g. when we are in syntax
69 -- checking only mode, where the file name conventions are not set),
70 -- then we return Unknown.
72 function Get_Expected_Unit_Type
73 (Fname : File_Name_Type)
74 return Expected_Unit_Type
76 begin
77 Get_Name_String (Fname);
79 if Name_Buffer (Name_Len) = 'b' then
80 return Expect_Body;
81 elsif Name_Buffer (Name_Len) = 's' then
82 return Expect_Spec;
83 else
84 return Unknown;
85 end if;
86 end Get_Expected_Unit_Type;
88 ---------------------------
89 -- Is_Internal_File_Name --
90 ---------------------------
92 function Is_Internal_File_Name
93 (Fname : File_Name_Type;
94 Renamings_Included : Boolean := True)
95 return Boolean
97 begin
98 if Is_Predefined_File_Name (Fname, Renamings_Included) then
99 return True;
101 -- Once Is_Predefined_File_Name has been called and returns False,
102 -- Name_Buffer contains Fname and Name_Len is set to 8.
104 elsif Name_Buffer (1 .. 2) = "g-"
105 or else Name_Buffer (1 .. 8) = "gnat "
106 then
107 return True;
109 elsif OpenVMS
110 and then
111 (Name_Buffer (1 .. 4) = "dec-"
112 or else Name_Buffer (1 .. 8) = "dec ")
113 then
114 return True;
116 else
117 return False;
118 end if;
119 end Is_Internal_File_Name;
121 -----------------------------
122 -- Is_Predefined_File_Name --
123 -----------------------------
125 -- This should really be a test of unit name, given the possibility of
126 -- pragma Source_File_Name setting arbitrary file names for any files???
128 -- Once Is_Predefined_File_Name has been called and returns False,
129 -- Name_Buffer contains Fname and Name_Len is set to 8. This is used
130 -- only by Is_Internal_File_Name, and is not part of the official
131 -- external interface of this function.
133 function Is_Predefined_File_Name
134 (Fname : File_Name_Type;
135 Renamings_Included : Boolean := True)
136 return Boolean
138 begin
139 Get_Name_String (Fname);
140 return Is_Predefined_File_Name (Renamings_Included);
141 end Is_Predefined_File_Name;
143 function Is_Predefined_File_Name
144 (Renamings_Included : Boolean := True)
145 return Boolean
147 subtype Str8 is String (1 .. 8);
149 Predef_Names : constant array (1 .. 11) of Str8 :=
150 ("ada ", -- Ada
151 "calendar", -- Calendar
152 "interfac", -- Interfaces
153 "system ", -- System
154 "machcode", -- Machine_Code
155 "unchconv", -- Unchecked_Conversion
156 "unchdeal", -- Unchecked_Deallocation
158 -- Remaining entries are only considered if Renamings_Included true
160 "directio", -- Direct_IO
161 "ioexcept", -- IO_Exceptions
162 "sequenio", -- Sequential_IO
163 "text_io "); -- Text_IO
165 Num_Entries : constant Natural :=
166 7 + 4 * Boolean'Pos (Renamings_Included);
168 begin
169 -- Remove extension (if present)
171 if Name_Len > 4 and then Name_Buffer (Name_Len - 3) = '.' then
172 Name_Len := Name_Len - 4;
173 end if;
175 -- Definitely false if longer than 12 characters (8.3)
177 if Name_Len > 8 then
178 return False;
180 -- Definitely predefined if prefix is a- i- or s-
182 elsif Name_Len > 2
183 and then Name_Buffer (2) = '-'
184 and then (Name_Buffer (1) = 'a' or else
185 Name_Buffer (1) = 'i' or else
186 Name_Buffer (1) = 's')
187 then
188 return True;
189 end if;
191 -- Otherwise check against special list, first padding to 8 characters
193 while Name_Len < 8 loop
194 Name_Len := Name_Len + 1;
195 Name_Buffer (Name_Len) := ' ';
196 end loop;
198 for J in 1 .. Num_Entries loop
199 if Name_Buffer (1 .. 8) = Predef_Names (J) then
200 return True;
201 end if;
202 end loop;
204 -- Note: when we return False here, the Name_Buffer contains the
205 -- padded file name. This is not defined for clients of the package,
206 -- but is used by Is_Internal_File_Name.
208 return False;
209 end Is_Predefined_File_Name;
211 ---------------
212 -- Tree_Read --
213 ---------------
215 procedure Tree_Read is
216 begin
217 SFN_Table.Tree_Read;
218 end Tree_Read;
220 ----------------
221 -- Tree_Write --
222 ----------------
224 procedure Tree_Write is
225 begin
226 SFN_Table.Tree_Write;
227 end Tree_Write;
229 end Fname;