* c-decl.c (duplicate_decls): Conditionalize DECL_SAVED_TREE copy.
[official-gcc.git] / gcc / ada / impunit.adb
blobae10ab2e1d0678dddff2962d7c5ccf42188ac985
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- I M P U N I T --
6 -- --
7 -- B o d y --
8 -- --
9 -- $Revision$
10 -- --
11 -- Copyright (C) 2000-2001 Free Software Foundation, Inc. --
12 -- --
13 -- GNAT is free software; you can redistribute it and/or modify it under --
14 -- terms of the GNU General Public License as published by the Free Soft- --
15 -- ware Foundation; either version 2, or (at your option) any later ver- --
16 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
17 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
18 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
19 -- for more details. You should have received a copy of the GNU General --
20 -- Public License distributed with GNAT; see file COPYING. If not, write --
21 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
22 -- MA 02111-1307, USA. --
23 -- --
24 -- GNAT was originally developed by the GNAT team at New York University. --
25 -- It is now maintained by Ada Core Technologies Inc (http://www.gnat.com). --
26 -- --
27 ------------------------------------------------------------------------------
29 with Lib; use Lib;
30 with Namet; use Namet;
31 with Opt; use Opt;
33 package body Impunit is
35 subtype File_Name_8 is String (1 .. 8);
36 type File_List is array (Nat range <>) of File_Name_8;
38 -- The following is a giant string containing the concenated names
39 -- of all non-implementation internal files, i.e. the complete list
40 -- of files for internal units which a program may legitimately WITH.
42 -- Note that this list should match the list of units documented in
43 -- the "GNAT Library" section of the GNAT Reference Manual.
45 Non_Imp_File_Names : File_List := (
47 -----------------------------------------------
48 -- Ada Hierarchy Units from Reference Manual --
49 -----------------------------------------------
51 "a-astaco", -- Ada.Asynchronous_Task_Control
52 "a-calend", -- Ada.Calendar
53 "a-chahan", -- Ada.Characters.Handling
54 "a-charac", -- Ada.Characters
55 "a-chlat1", -- Ada.Characters.Latin_1
56 "a-comlin", -- Ada.Command_Line
57 "a-decima", -- Ada.Decimal
58 "a-direio", -- Ada.Direct_IO
59 "a-dynpri", -- Ada.Dynamic_Priorities
60 "a-except", -- Ada.Exceptions
61 "a-finali", -- Ada.Finalization
62 "a-flteio", -- Ada.Float_Text_IO
63 "a-fwteio", -- Ada.Float_Wide_Text_IO
64 "a-inteio", -- Ada.Integer_Text_IO
65 "a-interr", -- Ada.Interrupts
66 "a-intnam", -- Ada.Interrupts.Names
67 "a-ioexce", -- Ada.IO_Exceptions
68 "a-iwteio", -- Ada.Integer_Wide_Text_IO
69 "a-ncelfu", -- Ada.Numerics.Complex_Elementary_Functions
70 "a-ngcefu", -- Ada.Numerics.Generic_Complex_Elementary_Functions
71 "a-ngcoty", -- Ada.Numerics.Generic_Complex_Types
72 "a-ngelfu", -- Ada.Numerics.Generic_Elementary_Functions
73 "a-nucoty", -- Ada.Numerics.Complex_Types
74 "a-nudira", -- Ada.Numerics.Discrete_Random
75 "a-nuelfu", -- Ada.Numerics.Elementary_Functions
76 "a-nuflra", -- Ada.Numerics.Float_Random
77 "a-numeri", -- Ada.Numerics
78 "a-reatim", -- Ada.Real_Time
79 "a-sequio", -- Ada.Sequential_IO
80 "a-stmaco", -- Ada.Strings.Maps.Constants
81 "a-storio", -- Ada.Storage_IO
82 "a-strbou", -- Ada.Strings.Bounded
83 "a-stream", -- Ada.Streams
84 "a-strfix", -- Ada.Strings.Fixed
85 "a-string", -- Ada.Strings
86 "a-strmap", -- Ada.Strings.Maps
87 "a-strunb", -- Ada.Strings.Unbounded
88 "a-ststio", -- Ada.Streams.Stream_IO
89 "a-stwibo", -- Ada.Strings.Wide_Bounded
90 "a-stwifi", -- Ada.Strings.Wide_Fixed
91 "a-stwima", -- Ada.Strings.Wide_Maps
92 "a-stwiun", -- Ada.Strings.Wide_Unbounded
93 "a-swmwco", -- Ada.Strings.Wide_Maps.Wide_Constants
94 "a-sytaco", -- Ada.Synchronous_Task_Control
95 "a-tags ", -- Ada.Tags
96 "a-tasatt", -- Ada.Task_Attributes
97 "a-taside", -- Ada.Task_Identification
98 "a-teioed", -- Ada.Text_IO.Editing
99 "a-textio", -- Ada.Text_IO
100 "a-ticoio", -- Ada.Text_IO.Complex_IO
101 "a-titest", -- Ada.Text_IO.Text_Streams
102 "a-unccon", -- Ada.Unchecked_Conversion
103 "a-uncdea", -- Ada.Unchecked_Deallocation
104 "a-witeio", -- Ada.Wide_Text_IO
105 "a-wtcoio", -- Ada.Wide_Text_IO.Complex_IO
106 "a-wtedit", -- Ada.Wide_Text_IO.Editing
107 "a-wttest", -- Ada.Wide_Text_IO.Text_Streams
109 -------------------------------------------------
110 -- RM Required Additions to Ada for GNAT Types --
111 -------------------------------------------------
113 "a-lfteio", -- Ada.Long_Float_Text_IO
114 "a-lfwtio", -- Ada.Long_Float_Wide_Text_IO
115 "a-liteio", -- Ada.Long_Integer_Text_IO
116 "a-liwtio", -- Ada.Long_Integer_Wide_Text_IO
117 "a-llftio", -- Ada.Long_Long_Float_Text_IO
118 "a-llfwti", -- Ada.Long_Long_Float_Wide_Text_IO
119 "a-llitio", -- Ada.Long_Long_Integer_Text_IO
120 "a-lliwti", -- Ada.Long_Long_Integer_Wide_Text_IO
121 "a-nlcefu", -- Ada.Long_Complex_Elementary_Functions
122 "a-nlcoty", -- Ada.Numerics.Long_Complex_Types
123 "a-nlelfu", -- Ada.Numerics.Long_Elementary_Functions
124 "a-nllcef", -- Ada.Long_Long_Complex_Elementary_Functions
125 "a-nllefu", -- Ada.Numerics.Long_Long_Elementary_Functions
126 "a-nltcty", -- Ada.Numerics.Long_Long_Complex_Types
127 "a-nscefu", -- Ada.Short_Complex_Elementary_Functions
128 "a-nscoty", -- Ada.Numerics.Short_Complex_Types
129 "a-nselfu", -- Ada.Numerics.Short_Elementary_Functions
130 "a-sfteio", -- Ada.Short_Float_Text_IO
131 "a-sfwtio", -- Ada.Short_Float_Wide_Text_IO
132 "a-siteio", -- Ada.Short_Integer_Text_IO
133 "a-siwtio", -- Ada.Short_Integer_Wide_Text_IO
134 "a-ssitio", -- Ada.Short_Short_Integer_Text_IO
135 "a-ssiwti", -- Ada.Short_Short_Integer_Wide_Text_IO
137 -----------------------------------
138 -- GNAT Defined Additions to Ada --
139 -----------------------------------
141 "a-colire", -- Ada.Command_Line.Remove
142 "a-cwila1", -- Ada.Characters.Wide_Latin_1
143 "a-diocst", -- Ada.Direct_IO.C_Streams
144 "a-einuoc", -- Ada.Exceptions.Is_Null_Occurrence
145 "a-siocst", -- Ada.Sequential_IO.C_Streams
146 "a-ssicst", -- Ada.Streams.Stream_IO.C_Streams
147 "a-suteio", -- Ada.Strings.Unbounded.Text_IO
148 "a-swuwti", -- Ada.Strings.Wide_Unbounded.Wide_Text_IO
149 "a-taidim", -- Ada.Task_Identification.Image
150 "a-tiocst", -- Ada.Text_IO.C_Streams
151 "a-wtcstr", -- Ada.Wide_Text_IO.C_Streams
153 ---------------------------
154 -- GNAT Special IO Units --
155 ---------------------------
157 -- As further explained elsewhere (see Sem_Ch10), the internal
158 -- packages of Text_IO and Wide_Text_IO are actually implemented
159 -- as separate children, but this fact is intended to be hidden
160 -- from the user completely. Any attempt to WITH one of these
161 -- units will be diagnosed as an error later on, but for now we
162 -- do not consider these internal implementation units (if we did,
163 -- then we would get a junk warning which would be confusing and
164 -- unecessary, given that we generate a clear error message).
166 "a-tideio", -- Ada.Text_IO.Decimal_IO
167 "a-tienio", -- Ada.Text_IO.Enumeration_IO
168 "a-tifiio", -- Ada.Text_IO.Fixed_IO
169 "a-tiflio", -- Ada.Text_IO.Float_IO
170 "a-tiinio", -- Ada.Text_IO.Integer_IO
171 "a-tiinio", -- Ada.Text_IO.Integer_IO
172 "a-timoio", -- Ada.Text_IO.Modular_IO
173 "a-wtdeio", -- Ada.Wide_Text_IO.Decimal_IO
174 "a-wtenio", -- Ada.Wide_Text_IO.Enumeration_IO
175 "a-wtfiio", -- Ada.Wide_Text_IO.Fixed_IO
176 "a-wtflio", -- Ada.Wide_Text_IO.Float_IO
177 "a-wtinio", -- Ada.Wide_Text_IO.Integer_IO
178 "a-wtmoio", -- Ada.Wide_Text_IO.Modular_IO
180 ------------------------
181 -- GNAT Library Units --
182 ------------------------
184 "g-awk ", -- GNAT.AWK
185 "g-busora", -- GNAT.Bubble_Sort_A
186 "g-busorg", -- GNAT.Bubble_Sort_G
187 "g-calend", -- GNAT.Calendar
188 "g-catiio", -- GNAT.Calendar.Time_IO
189 "g-casuti", -- GNAT.Case_Util
190 "g-cgi ", -- GNAT.CGI
191 "g-cgicoo", -- GNAT.CGI.Cookie
192 "g-cgideb", -- GNAT.CGI.Debug
193 "g-comlin", -- GNAT.Command_Line
194 "g-crc32 ", -- GNAT.CRC32
195 "g-curexc", -- GNAT.Current_Exception
196 "g-debpoo", -- GNAT.Debug_Pools
197 "g-debuti", -- GNAT.Debug_Utilities
198 "g-dirope", -- GNAT.Directory_Operations
199 "g-dyntab", -- GNAT.Dynamic_Tables
200 "g-exctra", -- GNAT.Exception_Traces
201 "g-expect", -- GNAT.Expect
202 "g-flocon", -- GNAT.Float_Control
203 "g-htable", -- GNAT.Htable
204 "g-hesora", -- GNAT.Heap_Sort_A
205 "g-hesorg", -- GNAT.Heap_Sort_G
206 "g-io ", -- GNAT.IO
207 "g-io_aux", -- GNAT.IO_Aux
208 "g-locfil", -- GNAT.Lock_Files
209 "g-moreex", -- GNAT.Most_Recent_Exception
210 "g-os_lib", -- GNAT.Os_Lib
211 "g-regexp", -- GNAT.Regexp
212 "g-regist", -- GNAT.Registry
213 "g-regpat", -- GNAT.Regpat
214 "g-socket", -- GNAT.Sockets
215 "g-sptabo", -- GNAT.Spitbol.Table_Boolean
216 "g-sptain", -- GNAT.Spitbol.Table_Integer
217 "g-sptavs", -- GNAT.Spitbol.Table_Vstring
218 "g-souinf", -- GNAT.Source_Info
219 "g-speche", -- GNAT.Spell_Checker
220 "g-spitbo", -- GNAT.Spitbol
221 "g-spipat", -- GNAT.Spitbol.Patterns
222 "g-table ", -- GNAT.Table
223 "g-tasloc", -- GNAT.Task_Lock
224 "g-thread", -- GNAT.Threads
225 "g-traceb", -- GNAT.Traceback
226 "g-trasym", -- GNAT.Traceback.Symbolic
228 -----------------------------------------------------
229 -- Interface Hierarchy Units from Reference Manual --
230 -----------------------------------------------------
232 "i-c ", -- Interfaces.C
233 "i-cobol ", -- Interfaces.Cobol
234 "i-cpoint", -- Interfaces.C.Pointers
235 "i-cstrin", -- Interfaces.C.Strings
236 "i-fortra", -- Interfaces.Fortran
238 ------------------------------------------
239 -- GNAT Defined Additions to Interfaces --
240 ------------------------------------------
242 "i-cexten", -- Interfaces.C.Extensions
243 "i-csthre", -- Interfaces.C.Sthreads
244 "i-cstrea", -- Interfaces.C.Streams
245 "i-cpp ", -- Interfaces.CPP
246 "i-java ", -- Interfaces.Java
247 "i-javlan", -- Interfaces.Java.Lang
248 "i-jalaob", -- Interfaces.Java.Lang.Object
249 "i-jalasy", -- Interfaces.Java.Lang.System
250 "i-jalath", -- Interfaces.Java.Lang.Thread
251 "i-os2err", -- Interfaces.Os2lib.Errors
252 "i-os2lib", -- Interfaces.Os2lib
253 "i-os2syn", -- Interfaces.Os2lib.Synchronization
254 "i-os2thr", -- Interfaces.Os2lib.Threads
255 "i-pacdec", -- Interfaces.Packed_Decimal
256 "i-vxwork", -- Interfaces.Vxworks
258 --------------------------------------------------
259 -- System Hierarchy Units from Reference Manual --
260 --------------------------------------------------
262 "s-atacco", -- System.Address_To_Access_Conversions
263 "s-maccod", -- System.Machine_Code
264 "s-rpc ", -- System.Rpc
265 "s-stoele", -- System.Storage_Elements
266 "s-stopoo", -- System.Storage_Pools
268 --------------------------------------
269 -- GNAT Defined Additions to System --
270 --------------------------------------
272 "s-addima", -- System.Address_Image
273 "s-assert", -- System.Assertions
274 "s-parint", -- System.Partition_Interface
275 "s-tasinf", -- System.Task_Info
276 "s-wchcnv", -- System.Wch_Cnv
277 "s-wchcon"); -- System.Wch_Con
279 -------------------------
280 -- Implementation_Unit --
281 -------------------------
283 function Implementation_Unit (U : Unit_Number_Type) return Boolean is
284 Fname : constant File_Name_Type := Unit_File_Name (U);
286 begin
287 -- All units are OK in GNAT mode
289 if GNAT_Mode then
290 return False;
291 end if;
293 -- If length of file name is greater than 12, definitely OK!
294 -- The value 12 here is an 8 char name with extension .ads.
296 if Length_Of_Name (Fname) > 12 then
297 return False;
298 end if;
300 -- Otherwise test file name
302 Get_Name_String (Fname);
304 -- Definitely OK if file name does not start with a- g- s- i-
306 if Name_Len < 3
307 or else Name_Buffer (2) /= '-'
308 or else (Name_Buffer (1) /= 'a'
309 and then
310 Name_Buffer (1) /= 'g'
311 and then
312 Name_Buffer (1) /= 'i'
313 and then
314 Name_Buffer (1) /= 's')
315 then
316 return False;
317 end if;
319 -- Definitely OK if file name does not end in .ads. This can
320 -- happen when non-standard file names are being used.
322 if Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads" then
323 return False;
324 end if;
326 -- Otherwise normalize file name to 8 characters
328 Name_Len := Name_Len - 4;
329 while Name_Len < 8 loop
330 Name_Len := Name_Len + 1;
331 Name_Buffer (Name_Len) := ' ';
332 end loop;
334 -- Definitely OK if name is in list
336 for J in Non_Imp_File_Names'Range loop
337 if Name_Buffer (1 .. 8) = Non_Imp_File_Names (J) then
338 return False;
339 end if;
340 end loop;
342 -- Only remaining special possibilities are children of
343 -- System.RPC and System.Garlic and special files of the
344 -- form System.Aux...
346 Get_Name_String (Unit_Name (U));
348 if Name_Len > 12
349 and then Name_Buffer (1 .. 11) = "system.rpc."
350 then
351 return False;
352 end if;
354 if Name_Len > 15
355 and then Name_Buffer (1 .. 14) = "system.garlic."
356 then
357 return False;
358 end if;
360 if Name_Len > 11
361 and then Name_Buffer (1 .. 10) = "system.aux"
362 then
363 return False;
364 end if;
366 -- All tests failed, this is definitely an implementation unit
368 return True;
370 end Implementation_Unit;
372 end Impunit;