]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/ada/fname.adb
[Ada] Remove ASIS tree generation
[thirdparty/gcc.git] / gcc / ada / fname.adb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- F N A M E --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2020, 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 ------------------------------------------------------------------------------
31
32 package body Fname is
33
34 function Has_Internal_Extension (Fname : String) return Boolean;
35 pragma Inline (Has_Internal_Extension);
36 -- True if the extension is appropriate for an internal/predefined unit.
37 -- That means ".ads" or ".adb" for source files, and ".ali" for ALI files.
38
39 function Has_Prefix (X, Prefix : String) return Boolean;
40 pragma Inline (Has_Prefix);
41 -- True if Prefix is at the beginning of X. For example,
42 -- Has_Prefix ("a-filename.ads", Prefix => "a-") is True.
43
44 ----------------------------
45 -- Has_Internal_Extension --
46 ----------------------------
47
48 function Has_Internal_Extension (Fname : String) return Boolean is
49 begin
50 if Fname'Length >= 4 then
51 declare
52 S : String renames Fname (Fname'Last - 3 .. Fname'Last);
53 begin
54 return S = ".ads" or else S = ".adb" or else S = ".ali";
55 end;
56 end if;
57 return False;
58 end Has_Internal_Extension;
59
60 ----------------
61 -- Has_Prefix --
62 ----------------
63
64 function Has_Prefix (X, Prefix : String) return Boolean is
65 begin
66 if X'Length >= Prefix'Length then
67 declare
68 S : String renames X (X'First .. X'First + Prefix'Length - 1);
69 begin
70 return S = Prefix;
71 end;
72 end if;
73 return False;
74 end Has_Prefix;
75
76 -----------------------
77 -- Is_GNAT_File_Name --
78 -----------------------
79
80 function Is_GNAT_File_Name (Fname : String) return Boolean is
81 begin
82 -- Check for internal extensions before checking prefixes, so we don't
83 -- think (e.g.) "gnat.adc" is internal.
84
85 if not Has_Internal_Extension (Fname) then
86 return False;
87 end if;
88
89 -- Definitely internal if prefix is g-
90
91 if Has_Prefix (Fname, "g-") then
92 return True;
93 end if;
94
95 -- See the note in Is_Predefined_File_Name for the rationale
96
97 return Fname'Length = 8 and then Has_Prefix (Fname, "gnat");
98 end Is_GNAT_File_Name;
99
100 function Is_GNAT_File_Name (Fname : File_Name_Type) return Boolean is
101 Result : constant Boolean :=
102 Is_GNAT_File_Name (Get_Name_String (Fname));
103 begin
104 return Result;
105 end Is_GNAT_File_Name;
106
107 ---------------------------
108 -- Is_Internal_File_Name --
109 ---------------------------
110
111 function Is_Internal_File_Name
112 (Fname : String;
113 Renamings_Included : Boolean := True) return Boolean
114 is
115 begin
116 if Is_Predefined_File_Name (Fname, Renamings_Included) then
117 return True;
118 end if;
119
120 return Is_GNAT_File_Name (Fname);
121 end Is_Internal_File_Name;
122
123 function Is_Internal_File_Name
124 (Fname : File_Name_Type;
125 Renamings_Included : Boolean := True) return Boolean
126 is
127 Result : constant Boolean :=
128 Is_Internal_File_Name
129 (Get_Name_String (Fname), Renamings_Included);
130 begin
131 return Result;
132 end Is_Internal_File_Name;
133
134 -----------------------------
135 -- Is_Predefined_File_Name --
136 -----------------------------
137
138 function Is_Predefined_File_Name
139 (Fname : String;
140 Renamings_Included : Boolean := True) return Boolean
141 is
142 begin
143 -- Definitely false if longer than 12 characters (8.3)
144 -- except for the Interfaces packages
145
146 if Fname'Length > 12
147 and then Fname (Fname'First .. Fname'First + 1) /= "i-"
148 then
149 return False;
150 end if;
151
152 if not Has_Internal_Extension (Fname) then
153 return False;
154 end if;
155
156 -- Definitely predefined if prefix is a- i- or s-
157
158 if Fname'Length >= 2 then
159 declare
160 S : String renames Fname (Fname'First .. Fname'First + 1);
161 begin
162 if S = "a-" or else S = "i-" or else S = "s-" then
163 return True;
164 end if;
165 end;
166 end if;
167
168 -- We include the "." in the prefixes below, so we don't match (e.g.)
169 -- adamant.ads. So the first line matches "ada.ads", "ada.adb", and
170 -- "ada.ali". But that's not necessary if they have 8 characters.
171
172 if Has_Prefix (Fname, "ada.") -- Ada
173 or else Has_Prefix (Fname, "interfac") -- Interfaces
174 or else Has_Prefix (Fname, "system.a") -- System
175 then
176 return True;
177 end if;
178
179 -- If instructed and the name has 8+ characters, check for renamings
180
181 if Renamings_Included
182 and then Is_Predefined_Renaming_File_Name (Fname)
183 then
184 return True;
185 end if;
186
187 return False;
188 end Is_Predefined_File_Name;
189
190 function Is_Predefined_File_Name
191 (Fname : File_Name_Type;
192 Renamings_Included : Boolean := True) return Boolean
193 is
194 Result : constant Boolean :=
195 Is_Predefined_File_Name
196 (Get_Name_String (Fname), Renamings_Included);
197 begin
198 return Result;
199 end Is_Predefined_File_Name;
200
201 --------------------------------------
202 -- Is_Predefined_Renaming_File_Name --
203 --------------------------------------
204
205 function Is_Predefined_Renaming_File_Name
206 (Fname : String) return Boolean
207 is
208 subtype Str8 is String (1 .. 8);
209
210 Renaming_Names : constant array (1 .. 8) of Str8 :=
211 ("calendar", -- Calendar
212 "machcode", -- Machine_Code
213 "unchconv", -- Unchecked_Conversion
214 "unchdeal", -- Unchecked_Deallocation
215 "directio", -- Direct_IO
216 "ioexcept", -- IO_Exceptions
217 "sequenio", -- Sequential_IO
218 "text_io."); -- Text_IO
219 begin
220 -- Definitely false if longer than 12 characters (8.3)
221
222 if Fname'Length in 8 .. 12 then
223 declare
224 S : String renames Fname (Fname'First .. Fname'First + 7);
225 begin
226 for J in Renaming_Names'Range loop
227 if S = Renaming_Names (J) then
228 return True;
229 end if;
230 end loop;
231 end;
232 end if;
233
234 return False;
235 end Is_Predefined_Renaming_File_Name;
236
237 function Is_Predefined_Renaming_File_Name
238 (Fname : File_Name_Type) return Boolean is
239 Result : constant Boolean :=
240 Is_Predefined_Renaming_File_Name (Get_Name_String (Fname));
241 begin
242 return Result;
243 end Is_Predefined_Renaming_File_Name;
244
245 end Fname;