fixing pr42337
[official-gcc.git] / gcc / ada / fname.adb
blob48cb207054c360af91cdd53a79cfdab5a884f856
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F N A M E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2009, 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. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with Alloc;
33 with Hostparm; use Hostparm;
34 with Table;
35 with Types; use Types;
37 package body Fname is
39 -----------------------------
40 -- Dummy Table Definitions --
41 -----------------------------
43 -- The following table was used in old versions of the compiler. We retain
44 -- the declarations here for compatibility with old tree files. The new
45 -- version of the compiler does not use this table, and will write out a
46 -- dummy empty table for Tree_Write.
48 type SFN_Entry is record
49 U : Unit_Name_Type;
50 F : File_Name_Type;
51 end record;
53 package SFN_Table is new Table.Table (
54 Table_Component_Type => SFN_Entry,
55 Table_Index_Type => Int,
56 Table_Low_Bound => 0,
57 Table_Initial => Alloc.SFN_Table_Initial,
58 Table_Increment => Alloc.SFN_Table_Increment,
59 Table_Name => "Fname_Dummy_Table");
61 ---------------------------
62 -- Is_Internal_File_Name --
63 ---------------------------
65 function Is_Internal_File_Name
66 (Fname : File_Name_Type;
67 Renamings_Included : Boolean := True) return Boolean
69 begin
70 if Is_Predefined_File_Name (Fname, Renamings_Included) then
71 return True;
73 -- Once Is_Predefined_File_Name has been called and returns False,
74 -- Name_Buffer contains Fname and Name_Len is set to 8.
76 elsif Name_Buffer (1 .. 2) = "g-"
77 or else Name_Buffer (1 .. 8) = "gnat "
78 then
79 return True;
81 elsif OpenVMS
82 and then
83 (Name_Buffer (1 .. 4) = "dec-"
84 or else Name_Buffer (1 .. 8) = "dec ")
85 then
86 return True;
88 else
89 return False;
90 end if;
91 end Is_Internal_File_Name;
93 -----------------------------
94 -- Is_Predefined_File_Name --
95 -----------------------------
97 -- This should really be a test of unit name, given the possibility of
98 -- pragma Source_File_Name setting arbitrary file names for any files???
100 -- Once Is_Predefined_File_Name has been called and returns False,
101 -- Name_Buffer contains Fname and Name_Len is set to 8. This is used
102 -- only by Is_Internal_File_Name, and is not part of the official
103 -- external interface of this function.
105 function Is_Predefined_File_Name
106 (Fname : File_Name_Type;
107 Renamings_Included : Boolean := True) return Boolean
109 begin
110 Get_Name_String (Fname);
111 return Is_Predefined_File_Name (Renamings_Included);
112 end Is_Predefined_File_Name;
114 function Is_Predefined_File_Name
115 (Renamings_Included : Boolean := True) return Boolean
117 subtype Str8 is String (1 .. 8);
119 Predef_Names : constant array (1 .. 11) of Str8 :=
120 ("ada ", -- Ada
121 "interfac", -- Interfaces
122 "system ", -- System
124 -- Remaining entries are only considered if Renamings_Included true
126 "calendar", -- Calendar
127 "machcode", -- Machine_Code
128 "unchconv", -- Unchecked_Conversion
129 "unchdeal", -- Unchecked_Deallocation
130 "directio", -- Direct_IO
131 "ioexcept", -- IO_Exceptions
132 "sequenio", -- Sequential_IO
133 "text_io "); -- Text_IO
135 Num_Entries : constant Natural :=
136 3 + 8 * Boolean'Pos (Renamings_Included);
138 begin
139 -- Remove extension (if present)
141 if Name_Len > 4 and then Name_Buffer (Name_Len - 3) = '.' then
142 Name_Len := Name_Len - 4;
143 end if;
145 -- Definitely false if longer than 12 characters (8.3)
147 if Name_Len > 8 then
148 return False;
150 -- Definitely predefined if prefix is a- i- or s- followed by letter
152 elsif Name_Len >= 3
153 and then Name_Buffer (2) = '-'
154 and then (Name_Buffer (1) = 'a'
155 or else
156 Name_Buffer (1) = 'i'
157 or else
158 Name_Buffer (1) = 's')
159 and then (Name_Buffer (3) in 'a' .. 'z'
160 or else
161 Name_Buffer (3) in 'A' .. 'Z')
162 then
163 return True;
164 end if;
166 -- Otherwise check against special list, first padding to 8 characters
168 while Name_Len < 8 loop
169 Name_Len := Name_Len + 1;
170 Name_Buffer (Name_Len) := ' ';
171 end loop;
173 for J in 1 .. Num_Entries loop
174 if Name_Buffer (1 .. 8) = Predef_Names (J) then
175 return True;
176 end if;
177 end loop;
179 -- Note: when we return False here, the Name_Buffer contains the
180 -- padded file name. This is not defined for clients of the package,
181 -- but is used by Is_Internal_File_Name.
183 return False;
184 end Is_Predefined_File_Name;
186 ---------------
187 -- Tree_Read --
188 ---------------
190 procedure Tree_Read is
191 begin
192 SFN_Table.Tree_Read;
193 end Tree_Read;
195 ----------------
196 -- Tree_Write --
197 ----------------
199 procedure Tree_Write is
200 begin
201 SFN_Table.Tree_Write;
202 end Tree_Write;
204 end Fname;