1------------------------------------------------------------------------------
2--                                                                          --
3--                         GNAT COMPILER COMPONENTS                         --
4--                                                                          --
5--                              I M P U N I T                               --
6--                                                                          --
7--                                 B o d y                                  --
8--                                                                          --
9--           Copyright (C) 2000-2013, 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------------------------------------------------------------------------------
25
26with Atree;    use Atree;
27with Errout;   use Errout;
28with Sinfo;    use Sinfo;
29with Fname.UF; use Fname.UF;
30with Lib;      use Lib;
31with Namet;    use Namet;
32with Opt;      use Opt;
33with Uname;    use Uname;
34
35--  Note: this package body is used by GPS and GNATBench to supply a list of
36--  entries for help on available library routines.
37
38package body Impunit is
39
40   subtype File_Name_8 is String (1 .. 8);
41
42   type File_Name_Record is record
43      Fname : File_Name_8;
44      --  8 character name of unit
45
46      RMdef : Boolean;
47      --  True if unit is RM defined. False for any unit that is implementation
48      --  defined (and thus not with'able in No_Implementation_Units mode).
49   end record;
50
51   type File_List is array (Nat range <>) of File_Name_Record;
52
53   T : constant Boolean := True;
54   F : constant Boolean := False;
55   --  Short hand for RM_Defined values in lists below
56
57   ------------------
58   -- Ada 95 Units --
59   ------------------
60
61   --  The following is a giant string list containing the names of all non-
62   --  implementation internal files, i.e. the complete list of files for
63   --  internal units which a program may legitimately WITH when operating in
64   --  either Ada 95 or Ada 2005 mode.
65
66   --  Note that this list should match the list of units documented in the
67   --  "GNAT Library" section of the GNAT Reference Manual. A unit listed here
68   --  must either be documented in that section or described in the Ada RM.
69
70   Non_Imp_File_Names_95 : constant File_List := (
71
72   ------------------------------------------------------
73   -- Ada Hierarchy Units from Ada-95 Reference Manual --
74   ------------------------------------------------------
75
76    ("a-astaco", T),  -- Ada.Asynchronous_Task_Control
77    ("a-calend", T),  -- Ada.Calendar
78    ("a-chahan", T),  -- Ada.Characters.Handling
79    ("a-charac", T),  -- Ada.Characters
80    ("a-chlat1", T),  -- Ada.Characters.Latin_1
81    ("a-comlin", T),  -- Ada.Command_Line
82    ("a-decima", T),  -- Ada.Decimal
83    ("a-direio", T),  -- Ada.Direct_IO
84    ("a-dynpri", T),  -- Ada.Dynamic_Priorities
85    ("a-except", T),  -- Ada.Exceptions
86    ("a-finali", T),  -- Ada.Finalization
87    ("a-flteio", T),  -- Ada.Float_Text_IO
88    ("a-fwteio", T),  -- Ada.Float_Wide_Text_IO
89    ("a-inteio", T),  -- Ada.Integer_Text_IO
90    ("a-interr", T),  -- Ada.Interrupts
91    ("a-intnam", T),  -- Ada.Interrupts.Names
92    ("a-ioexce", T),  -- Ada.IO_Exceptions
93    ("a-iwteio", T),  -- Ada.Integer_Wide_Text_IO
94    ("a-ncelfu", T),  -- Ada.Numerics.Complex_Elementary_Functions
95    ("a-ngcefu", T),  -- Ada.Numerics.Generic_Complex_Elementary_Functions
96    ("a-ngcoty", T),  -- Ada.Numerics.Generic_Complex_Types
97    ("a-ngelfu", T),  -- Ada.Numerics.Generic_Elementary_Functions
98    ("a-nucoty", T),  -- Ada.Numerics.Complex_Types
99    ("a-nudira", T),  -- Ada.Numerics.Discrete_Random
100    ("a-nuelfu", T),  -- Ada.Numerics.Elementary_Functions
101    ("a-nuflra", T),  -- Ada.Numerics.Float_Random
102    ("a-numeri", T),  -- Ada.Numerics
103    ("a-reatim", T),  -- Ada.Real_Time
104    ("a-sequio", T),  -- Ada.Sequential_IO
105    ("a-stmaco", T),  -- Ada.Strings.Maps.Constants
106    ("a-storio", T),  -- Ada.Storage_IO
107    ("a-strbou", T),  -- Ada.Strings.Bounded
108    ("a-stream", T),  -- Ada.Streams
109    ("a-strfix", T),  -- Ada.Strings.Fixed
110    ("a-string", T),  -- Ada.Strings
111    ("a-strmap", T),  -- Ada.Strings.Maps
112    ("a-strunb", T),  -- Ada.Strings.Unbounded
113    ("a-ststio", T),  -- Ada.Streams.Stream_IO
114    ("a-stwibo", T),  -- Ada.Strings.Wide_Bounded
115    ("a-stwifi", T),  -- Ada.Strings.Wide_Fixed
116    ("a-stwima", T),  -- Ada.Strings.Wide_Maps
117    ("a-stwiun", T),  -- Ada.Strings.Wide_Unbounded
118    ("a-swmwco", T),  -- Ada.Strings.Wide_Maps.Wide_Constants
119    ("a-sytaco", T),  -- Ada.Synchronous_Task_Control
120    ("a-tags  ", T),  -- Ada.Tags
121    ("a-tasatt", T),  -- Ada.Task_Attributes
122    ("a-taside", T),  -- Ada.Task_Identification
123    ("a-teioed", T),  -- Ada.Text_IO.Editing
124    ("a-textio", T),  -- Ada.Text_IO
125    ("a-ticoio", T),  -- Ada.Text_IO.Complex_IO
126    ("a-titest", T),  -- Ada.Text_IO.Text_Streams
127    ("a-unccon", T),  -- Ada.Unchecked_Conversion
128    ("a-uncdea", T),  -- Ada.Unchecked_Deallocation
129    ("a-witeio", T),  -- Ada.Wide_Text_IO
130    ("a-wtcoio", T),  -- Ada.Wide_Text_IO.Complex_IO
131    ("a-wtedit", T),  -- Ada.Wide_Text_IO.Editing
132    ("a-wttest", T),  -- Ada.Wide_Text_IO.Text_Streams
133
134   -------------------------------------------------
135   -- RM Required Additions to Ada for GNAT Types --
136   -------------------------------------------------
137
138   --  Note: Long versions are considered RM defined, but not the Long Long,
139   --  Short, or Short_Short versions.
140
141    ("a-lfteio", T),  -- Ada.Long_Float_Text_IO
142    ("a-lfwtio", T),  -- Ada.Long_Float_Wide_Text_IO
143    ("a-liteio", T),  -- Ada.Long_Integer_Text_IO
144    ("a-liwtio", T),  -- Ada.Long_Integer_Wide_Text_IO
145    ("a-llftio", T),  -- Ada.Long_Long_Float_Text_IO
146    ("a-llfwti", T),  -- Ada.Long_Long_Float_Wide_Text_IO
147    ("a-llitio", T),  -- Ada.Long_Long_Integer_Text_IO
148    ("a-lliwti", F),  -- Ada.Long_Long_Integer_Wide_Text_IO
149    ("a-nlcefu", F),  -- Ada.Long_Complex_Elementary_Functions
150    ("a-nlcoty", T),  -- Ada.Numerics.Long_Complex_Types
151    ("a-nlelfu", T),  -- Ada.Numerics.Long_Elementary_Functions
152    ("a-nllcef", F),  -- Ada.Long_Long_Complex_Elementary_Functions
153    ("a-nllefu", F),  -- Ada.Numerics.Long_Long_Elementary_Functions
154    ("a-nllcty", F),  -- Ada.Numerics.Long_Long_Complex_Types
155    ("a-nscefu", F),  -- Ada.Short_Complex_Elementary_Functions
156    ("a-nscoty", F),  -- Ada.Numerics.Short_Complex_Types
157    ("a-nselfu", F),  -- Ada.Numerics.Short_Elementary_Functions
158    ("a-sfteio", F),  -- Ada.Short_Float_Text_IO
159    ("a-sfwtio", F),  -- Ada.Short_Float_Wide_Text_IO
160    ("a-siteio", F),  -- Ada.Short_Integer_Text_IO
161    ("a-siwtio", F),  -- Ada.Short_Integer_Wide_Text_IO
162    ("a-ssitio", F),  -- Ada.Short_Short_Integer_Text_IO
163    ("a-ssiwti", F),  -- Ada.Short_Short_Integer_Wide_Text_IO
164
165   -----------------------------------
166   -- GNAT Defined Additions to Ada --
167   -----------------------------------
168
169    ("a-calcon", F),  -- Ada.Calendar.Conversions
170    ("a-chlat9", F),  -- Ada.Characters.Latin_9
171    ("a-clrefi", F),  -- Ada.Command_Line.Response_File
172    ("a-colien", F),  -- Ada.Command_Line.Environment
173    ("a-colire", F),  -- Ada.Command_Line.Remove
174    ("a-cwila1", F),  -- Ada.Characters.Wide_Latin_1
175    ("a-cwila9", F),  -- Ada.Characters.Wide_Latin_9
176    ("a-diocst", F),  -- Ada.Direct_IO.C_Streams
177    ("a-einuoc", F),  -- Ada.Exceptions.Is_Null_Occurrence
178    ("a-elchha", F),  -- Ada.Exceptions.Last_Chance_Handler
179    ("a-exctra", F),  -- Ada.Exceptions.Traceback
180    ("a-siocst", F),  -- Ada.Sequential_IO.C_Streams
181    ("a-ssicst", F),  -- Ada.Streams.Stream_IO.C_Streams
182    ("a-suteio", F),  -- Ada.Strings.Unbounded.Text_IO
183    ("a-swuwti", F),  -- Ada.Strings.Wide_Unbounded.Wide_Text_IO
184    ("a-tiocst", F),  -- Ada.Text_IO.C_Streams
185    ("a-wtcstr", F),  -- Ada.Wide_Text_IO.C_Streams
186
187      --  Note: strictly the next two should be Ada 2005 units, but it seems
188      --  harmless (and useful) to make then available in Ada 95 mode, since
189      --  they only deal with Wide_Character, not Wide_Wide_Character.
190
191    ("a-wichun", F),  -- Ada.Wide_Characters.Unicode
192    ("a-widcha", F),  -- Ada.Wide_Characters
193
194      --  Note: strictly the following should be Ada 2012 units, but it seems
195      --  harmless (and useful) to make then available in Ada 95 mode, since
196      --  they do not deal with Wide_Wide_Character.
197
198    ("a-wichha", F),  -- Ada.Wide_Characters.Handling
199    ("a-stuten", F),  -- Ada.Strings.UTF_Encoding
200    ("a-suenco", F),  -- Ada.Strings.UTF_Encoding.Conversions
201    ("a-suenst", F),  -- Ada.Strings.UTF_Encoding.Strings
202    ("a-suewst", F),  -- Ada.Strings.UTF_Encoding.Wide_Strings
203
204   ---------------------------
205   -- GNAT Special IO Units --
206   ---------------------------
207
208   --  As further explained elsewhere (see Sem_Ch10), the internal packages of
209   --  Text_IO and Wide_Text_IO are actually implemented as separate children,
210   --  but this fact is intended to be hidden from the user completely. Any
211   --  attempt to WITH one of these units will be diagnosed as an error later
212   --  on, but for now we do not consider these internal implementation units
213   --  (if we did, then we would get a junk warning which would be confusing
214   --  and unnecessary, given that we generate a clear error message).
215
216    ("a-tideio", F),  -- Ada.Text_IO.Decimal_IO
217    ("a-tienio", F),  -- Ada.Text_IO.Enumeration_IO
218    ("a-tifiio", F),  -- Ada.Text_IO.Fixed_IO
219    ("a-tiflio", F),  -- Ada.Text_IO.Float_IO
220    ("a-tiinio", F),  -- Ada.Text_IO.Integer_IO
221    ("a-tiinio", F),  -- Ada.Text_IO.Integer_IO
222    ("a-timoio", F),  -- Ada.Text_IO.Modular_IO
223    ("a-wtdeio", F),  -- Ada.Wide_Text_IO.Decimal_IO
224    ("a-wtenio", F),  -- Ada.Wide_Text_IO.Enumeration_IO
225    ("a-wtfiio", F),  -- Ada.Wide_Text_IO.Fixed_IO
226    ("a-wtflio", F),  -- Ada.Wide_Text_IO.Float_IO
227    ("a-wtinio", F),  -- Ada.Wide_Text_IO.Integer_IO
228    ("a-wtmoio", F),  -- Ada.Wide_Text_IO.Modular_IO
229
230   ------------------------
231   -- GNAT Library Units --
232   ------------------------
233
234    ("g-altive", F),  -- GNAT.Altivec
235    ("g-altcon", F),  -- GNAT.Altivec.Conversions
236    ("g-alveop", F),  -- GNAT.Altivec.Vector_Operations
237    ("g-alvety", F),  -- GNAT.Altivec.Vector_Types
238    ("g-alvevi", F),  -- GNAT.Altivec.Vector_Views
239    ("g-arrspl", F),  -- GNAT.Array_Split
240    ("g-awk   ", F),  -- GNAT.AWK
241    ("g-boubuf", F),  -- GNAT.Bounded_Buffers
242    ("g-boumai", F),  -- GNAT.Bounded_Mailboxes
243    ("g-bubsor", F),  -- GNAT.Bubble_Sort
244    ("g-busora", F),  -- GNAT.Bubble_Sort_A
245    ("g-busorg", F),  -- GNAT.Bubble_Sort_G
246    ("g-byorma", F),  -- GNAT.Byte_Order_Mark
247    ("g-bytswa", F),  -- GNAT.Byte_Swapping
248    ("g-calend", F),  -- GNAT.Calendar
249    ("g-catiio", F),  -- GNAT.Calendar.Time_IO
250    ("g-casuti", F),  -- GNAT.Case_Util
251    ("g-cgi   ", F),  -- GNAT.CGI
252    ("g-cgicoo", F),  -- GNAT.CGI.Cookie
253    ("g-cgideb", F),  -- GNAT.CGI.Debug
254    ("g-comlin", F),  -- GNAT.Command_Line
255    ("g-comver", F),  -- GNAT.Compiler_Version
256    ("g-cppexc", F),  -- GNAT.CPP_Exceptions
257    ("g-crc32 ", F),  -- GNAT.CRC32
258    ("g-ctrl_c", F),  -- GNAT.Ctrl_C
259    ("g-curexc", F),  -- GNAT.Current_Exception
260    ("g-debpoo", F),  -- GNAT.Debug_Pools
261    ("g-debuti", F),  -- GNAT.Debug_Utilities
262    ("g-decstr", F),  -- GNAT.Decode_String
263    ("g-deutst", F),  -- GNAT.Decode_UTF8_String
264    ("g-dirope", F),  -- GNAT.Directory_Operations
265    ("g-diopit", F),  -- GNAT.Directory_Operations.Iteration
266    ("g-dynhta", F),  -- GNAT.Dynamic_HTables
267    ("g-dyntab", F),  -- GNAT.Dynamic_Tables
268    ("g-encstr", F),  -- GNAT.Encode_String
269    ("g-enutst", F),  -- GNAT.Encode_UTF8_String
270    ("g-excact", F),  -- GNAT.Exception_Actions
271    ("g-except", F),  -- GNAT.Exceptions
272    ("g-exctra", F),  -- GNAT.Exception_Traces
273    ("g-expect", F),  -- GNAT.Expect
274    ("g-exptty", F),  -- GNAT.Expect.TTY
275    ("g-flocon", F),  -- GNAT.Float_Control
276    ("g-heasor", F),  -- GNAT.Heap_Sort
277    ("g-hesora", F),  -- GNAT.Heap_Sort_A
278    ("g-hesorg", F),  -- GNAT.Heap_Sort_G
279    ("g-htable", F),  -- GNAT.Htable
280    ("g-io    ", F),  -- GNAT.IO
281    ("g-io_aux", F),  -- GNAT.IO_Aux
282    ("g-locfil", F),  -- GNAT.Lock_Files
283    ("g-mbdira", F),  -- GNAT.MBBS_Discrete_Random
284    ("g-mbflra", F),  -- GNAT.MBBS_Float_Random
285    ("g-md5   ", F),  -- GNAT.MD5
286    ("g-memdum", F),  -- GNAT.Memory_Dump
287    ("g-moreex", F),  -- GNAT.Most_Recent_Exception
288    ("g-os_lib", F),  -- GNAT.Os_Lib
289    ("g-pehage", F),  -- GNAT.Perfect_Hash_Generators
290    ("g-rannum", F),  -- GNAT.Random_Numbers
291    ("g-regexp", F),  -- GNAT.Regexp
292    ("g-regist", F),  -- GNAT.Registry
293    ("g-regpat", F),  -- GNAT.Regpat
294    ("g-semaph", F),  -- GNAT.Semaphores
295    ("g-sercom", F),  -- GNAT.Serial_Communications
296    ("g-sestin", F),  -- GNAT.Secondary_Stack_Info
297    ("g-sha1  ", F),  -- GNAT.SHA1
298    ("g-sha224", F),  -- GNAT.SHA224
299    ("g-sha256", F),  -- GNAT.SHA256
300    ("g-sha384", F),  -- GNAT.SHA384
301    ("g-sha512", F),  -- GNAT.SHA512
302    ("g-signal", F),  -- GNAT.Signals
303    ("g-socket", F),  -- GNAT.Sockets
304    ("g-souinf", F),  -- GNAT.Source_Info
305    ("g-speche", F),  -- GNAT.Spell_Checker
306    ("g-spchge", F),  -- GNAT.Spell_Checker_Generic
307    ("g-spitbo", F),  -- GNAT.Spitbol
308    ("g-spipat", F),  -- GNAT.Spitbol.Patterns
309    ("g-sptabo", F),  -- GNAT.Spitbol.Table_Boolean
310    ("g-sptain", F),  -- GNAT.Spitbol.Table_Integer
311    ("g-sptavs", F),  -- GNAT.Spitbol.Table_Vstring
312    ("g-string", F),  -- GNAT.Strings
313    ("g-strspl", F),  -- GNAT.String_Split
314    ("g-sse   ", F),  -- GNAT.SSE
315    ("g-ssvety", F),  -- GNAT.SSE.Vector_Types
316    ("g-table ", F),  -- GNAT.Table
317    ("g-tasloc", F),  -- GNAT.Task_Lock
318    ("g-tastus", F),  -- GNAT.Task_Stack_Usage
319    ("g-thread", F),  -- GNAT.Threads
320    ("g-timsta", F),  -- GNAT.Time_Stamp
321    ("g-traceb", F),  -- GNAT.Traceback
322    ("g-trasym", F),  -- GNAT.Traceback.Symbolic
323    ("g-tty   ", F),  -- GNAT.TTY
324    ("g-utf_32", F),  -- GNAT.UTF_32
325    ("g-u3spch", F),  -- GNAT.UTF_32_Spelling_Checker
326    ("g-wispch", F),  -- GNAT.Wide_Spelling_Checker
327    ("g-wistsp", F),  -- GNAT.Wide_String_Split
328
329   -----------------------------------------------------
330   -- Interface Hierarchy Units from Reference Manual --
331   -----------------------------------------------------
332
333    ("i-c     ", T),  -- Interfaces.C
334    ("i-cobol ", T),  -- Interfaces.Cobol
335    ("i-cpoint", T),  -- Interfaces.C.Pointers
336    ("i-cstrin", T),  -- Interfaces.C.Strings
337    ("i-fortra", T),  -- Interfaces.Fortran
338
339   ------------------------------------------
340   -- GNAT Defined Additions to Interfaces --
341   ------------------------------------------
342
343    ("i-cexten", F),  -- Interfaces.C.Extensions
344    ("i-cil   ", F),  -- Interfaces.CIL
345    ("i-cilobj", F),  -- Interfaces.CIL.Object
346    ("i-cpp   ", F),  -- Interfaces.CPP
347    ("i-cstrea", F),  -- Interfaces.C.Streams
348    ("i-java  ", F),  -- Interfaces.Java
349    ("i-javjni", F),  -- Interfaces.Java.JNI
350    ("i-pacdec", F),  -- Interfaces.Packed_Decimal
351    ("i-vxwoio", F),  -- Interfaces.VxWorks.IO
352    ("i-vxwork", F),  -- Interfaces.VxWorks
353
354   --------------------------------------------------
355   -- System Hierarchy Units from Reference Manual --
356   --------------------------------------------------
357
358    ("s-atacco", T),  -- System.Address_To_Access_Conversions
359    ("s-maccod", T),  -- System.Machine_Code
360    ("s-rpc   ", T),  -- System.Rpc
361    ("s-stoele", T),  -- System.Storage_Elements
362    ("s-stopoo", T),  -- System.Storage_Pools
363
364   --------------------------------------
365   -- GNAT Defined Additions to System --
366   --------------------------------------
367
368    ("s-addima", F),  -- System.Address_Image
369    ("s-assert", F),  -- System.Assertions
370    ("s-diflio", F),  -- System.Dim.Float_IO
371    ("s-diinio", F),  -- System.Dim.Integer_IO
372    ("s-dimkio", F),  -- System.Dim.Mks_IO
373    ("s-dimmks", F),  -- System.Dim.Mks
374    ("s-dmotpr", F),  -- System.Dim.Mks.Other_Prefixes
375    ("s-memory", F),  -- System.Memory
376    ("s-parint", F),  -- System.Partition_Interface
377    ("s-pooglo", F),  -- System.Pool_Global
378    ("s-pooloc", F),  -- System.Pool_Local
379    ("s-restri", F),  -- System.Restrictions
380    ("s-rident", F),  -- System.Rident
381    ("s-ststop", F),  -- System.Strings.Stream_Ops
382    ("s-tasinf", F),  -- System.Task_Info
383    ("s-wchcnv", F),  -- System.Wch_Cnv
384    ("s-wchcon", F),  -- System.Wch_Con
385
386   --  The following are strictly speaking Ada 2012 units, but we are allowed
387   --  to add children to system, so we consider them to be implementation
388   --  defined additions to System in earlier versions of Ada.
389
390    ("s-multip", T),  -- System.Multiprocessors
391    ("s-mudido", T)); -- System.Multiprocessors.Dispatching_Domains
392
393   --------------------
394   -- Ada 2005 Units --
395   --------------------
396
397   --  The following units should be used only in Ada 05 mode
398
399   Non_Imp_File_Names_05 : constant File_List := (
400
401   --------------------------------------------------------
402   -- Ada Hierarchy Units from Ada 2005 Reference Manual --
403   --------------------------------------------------------
404
405    ("a-assert", T),  -- Ada.Assertions
406    ("a-calari", T),  -- Ada.Calendar.Arithmetic
407    ("a-calfor", T),  -- Ada.Calendar.Formatting
408    ("a-catizo", T),  -- Ada.Calendar.Time_Zones
409    ("a-cdlili", T),  -- Ada.Containers.Doubly_Linked_Lists
410    ("a-cgarso", T),  -- Ada.Containers.Generic_Array_Sort
411    ("a-cgcaso", T),  -- Ada.Containers.Generic_Constrained_Array_Sort
412    ("a-chacon", T),  -- Ada.Characters.Conversions
413    ("a-cidlli", T),  -- Ada.Containers.Indefinite_Doubly_Linked_Lists
414    ("a-cihama", T),  -- Ada.Containers.Indefinite_Hashed_Maps
415    ("a-cihase", T),  -- Ada.Containers.Indefinite_Hashed_Sets
416    ("a-ciorma", T),  -- Ada.Containers.Indefinite_Ordered_Maps
417    ("a-ciorse", T),  -- Ada.Containers.Indefinite_Ordered_Sets
418    ("a-cohama", T),  -- Ada.Containers.Hashed_Maps
419    ("a-cohase", T),  -- Ada.Containers.Hashed_Sets
420    ("a-coinve", T),  -- Ada.Containers.Indefinite_Vectors
421    ("a-contai", T),  -- Ada.Containers
422    ("a-convec", T),  -- Ada.Containers.Vectors
423    ("a-coorma", T),  -- Ada.Containers.Ordered_Maps
424    ("a-coorse", T),  -- Ada.Containers.Ordered_Sets
425    ("a-coteio", T),  -- Ada.Complex_Text_IO
426    ("a-direct", T),  -- Ada.Directories
427    ("a-diroro", T),  -- Ada.Dispatching.Round_Robin
428    ("a-disedf", T),  -- Ada.Dispatching.EDF
429    ("a-dispat", T),  -- Ada.Dispatching
430    ("a-envvar", T),  -- Ada.Environment_Variables
431    ("a-etgrbu", T),  -- Ada.Execution_Time.Group_Budgets
432    ("a-exetim", T),  -- Ada.Execution_Time
433    ("a-extiti", T),  -- Ada.Execution_Time.Timers
434    ("a-izteio", T),  -- Ada.Integer_Wide_Wide_Text_IO
435    ("a-rttiev", T),  -- Ada.Real_Time.Timing_Events
436    ("a-ngcoar", T),  -- Ada.Numerics.Generic_Complex_Arrays
437    ("a-ngrear", T),  -- Ada.Numerics.Generic_Real_Arrays
438    ("a-nucoar", T),  -- Ada.Numerics.Complex_Arrays
439    ("a-nurear", T),  -- Ada.Numerics.Real_Arrays
440    ("a-stboha", T),  -- Ada.Strings.Bounded.Hash
441    ("a-stfiha", T),  -- Ada.Strings.Fixed.Hash
442    ("a-strhas", T),  -- Ada.Strings.Hash
443    ("a-stunha", T),  -- Ada.Strings.Unbounded.Hash
444    ("a-stwiha", T),  -- Ada.Strings.Wide_Hash
445    ("a-stzbou", T),  -- Ada.Strings.Wide_Wide_Bounded
446    ("a-stzfix", T),  -- Ada.Strings.Wide_Wide_Fixed
447    ("a-stzhas", T),  -- Ada.Strings.Wide_Wide_Hash
448    ("a-stzmap", T),  -- Ada.Strings.Wide_Wide_Maps
449    ("a-stzunb", T),  -- Ada.Strings.Wide_Wide_Unbounded
450    ("a-swbwha", T),  -- Ada.Strings.Wide_Bounded.Wide_Hash
451    ("a-swfwha", T),  -- Ada.Strings.Wide_Fixed.Wide_Hash
452    ("a-swuwha", T),  -- Ada.Strings.Wide_Unbounded.Wide_Hash
453    ("a-szbzha", T),  -- Ada.Strings.Wide_Wide_Bounded.Wide_Wide_Hash
454    ("a-szfzha", T),  -- Ada.Strings.Wide_Wide_Fixed.Wide_Wide_Hash
455    ("a-szmzco", T),  -- Ada.Strings.Wide_Wide_Maps.Wide_Wide_Constants
456    ("a-szuzha", T),  -- Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Hash
457    ("a-taster", T),  -- Ada.Task_Termination
458    ("a-tgdico", T),  -- Ada.Tags.Generic_Dispatching_Constructor
459    ("a-tiboio", T),  -- Ada.Text_IO.Bounded_IO
460    ("a-tiunio", T),  -- Ada.Text_IO.Unbounded_IO
461    ("a-wichun", T),  -- Ada.Wide_Characters.Unicode
462    ("a-wwboio", T),  -- Ada.Wide_Text_IO.Wide_Bounded_IO
463    ("a-wwunio", T),  -- Ada.Wide_Text_IO.Wide_Unbounded_IO
464    ("a-zchara", T),  -- Ada.Wide_Wide_Characters
465    ("a-zchhan", T),  -- Ada.Wide_Wide_Characters.Handling
466    ("a-ztcoio", T),  -- Ada.Wide_Wide_Text_IO.Complex_IO
467    ("a-ztedit", T),  -- Ada.Wide_Wide_Text_IO.Editing
468    ("a-zttest", T),  -- Ada.Wide_Wide_Text_IO.Text_Streams
469    ("a-ztexio", T),  -- Ada.Wide_Wide_Text_IO
470    ("a-zzboio", T),  -- Ada.Wide_Wide_Text_IO.Wide_Wide_Bounded_IO
471    ("a-zzunio", T),  -- Ada.Wide_Wide_Text_IO.Wide_Wide_Unbounded_IO
472
473   ------------------------------------------------------
474   -- RM Required Additions to Ada 2005 for GNAT Types --
475   ------------------------------------------------------
476
477   --  Note: Long versions are considered RM defined, but not the Long Long,
478   --  Short, or Short_Short versions.
479
480    ("a-lcteio", T),  -- Ada.Long_Complex_Text_IO
481    ("a-lfztio", T),  -- Ada.Long_Float_Wide_Wide_Text_IO
482    ("a-liztio", T),  -- Ada.Long_Integer_Wide_Wide_Text_IO
483    ("a-llctio", T),  -- Ada.Long_Long_Complex_Text_IO
484    ("a-llfzti", T),  -- Ada.Long_Long_Float_Wide_Wide_Text_IO
485    ("a-llizti", T),  -- Ada.Long_Long_Integer_Wide_Wide_Text_IO
486    ("a-nlcoar", T),  -- Ada.Numerics.Long_Complex_Arrays
487    ("a-nllcar", T),  -- Ada.Numerics.Long_Long_Complex_Arrays
488    ("a-nllrar", T),  -- Ada.Numerics.Long_Long_Real_Arrays
489    ("a-nlrear", T),  -- Ada.Numerics.Long_Real_Arrays
490    ("a-scteio", F),  -- Ada.Short_Complex_Text_IO
491    ("a-sfztio", F),  -- Ada.Short_Float_Wide_Wide_Text_IO
492    ("a-siztio", F),  -- Ada.Short_Integer_Wide_Wide_Text_IO
493    ("a-ssizti", F),  -- Ada.Short_Short_Integer_Wide_Wide_Text_IO
494
495   ----------------------------------------
496   -- GNAT Defined Additions to Ada 2005 --
497   ----------------------------------------
498
499    ("a-cgaaso", F),  -- Ada.Containers.Generic_Anonymous_Array_Sort
500    ("a-chzla1", F),  -- Ada.Characters.Wide_Wide_Latin_1
501    ("a-chzla9", F),  -- Ada.Characters.Wide_Wide_Latin_9
502    ("a-ciormu", F),  -- Ada.Containers.Indefinite_Ordered_Multisets
503    ("a-coormu", F),  -- Ada.Containers.Ordered_Multisets
504    ("a-crdlli", F),  -- Ada.Containers.Restricted_Doubly_Linked_Lists
505    ("a-szuzti", F),  -- Ada.Strings.Wide_Wide_Unbounded.Wide_Wide_Text_IO
506    ("a-zchuni", F),  -- Ada.Wide_Wide_Characters.Unicode
507    ("a-ztcstr", F),  -- Ada.Wide_Wide_Text_IO.C_Streams
508
509      --  Note: strictly the following should be Ada 2012 units, but it seems
510      --  harmless (and useful) to make then available in Ada 2005 mode.
511
512    ("a-cogeso", T),  -- Ada.Containers.Generic_Sort
513    ("a-secain", T),  -- Ada.Strings.Equal_Case_Insensitive
514    ("a-shcain", T),  -- Ada.Strings.Hash_Case_Insensitive
515    ("a-slcain", T),  -- Ada.Strings.Less_Case_Insensitive
516    ("a-sfecin", T),  -- Ada.Strings.Fixed.Equal_Case_Insensitive
517    ("a-sfhcin", T),  -- Ada.Strings.Fixed.Hash_Case_Insensitive
518    ("a-sflcin", T),  -- Ada.Strings.Fixed.Less_Case_Insensitive
519    ("a-sbecin", T),  -- Ada.Strings.Bounded.Equal_Case_Insensitive
520    ("a-sbhcin", T),  -- Ada.Strings.Bounded.Hash_Case_Insensitive
521    ("a-sblcin", T),  -- Ada.Strings.Bounded.Less_Case_Insensitive
522    ("a-suecin", T),  -- Ada.Strings.Unbounded.Equal_Case_Insensitive
523    ("a-suhcin", T),  -- Ada.Strings.Unbounded.Hash_Case_Insensitive
524    ("a-sulcin", T),  -- Ada.Strings.Unbounded.Less_Case_Insensitive
525    ("a-suezst", T),  -- Ada.Strings.UTF_Encoding.Wide_Wide_Strings
526
527   ---------------------------
528   -- GNAT Special IO Units --
529   ---------------------------
530
531   --  See Ada 95 section for further information. These packages are for the
532   --  implementation of the Wide_Wide_Text_IO generic packages.
533
534    ("a-ztdeio", F),  -- Ada.Wide_Wide_Text_IO.Decimal_IO
535    ("a-ztenio", F),  -- Ada.Wide_Wide_Text_IO.Enumeration_IO
536    ("a-ztfiio", F),  -- Ada.Wide_Wide_Text_IO.Fixed_IO
537    ("a-ztflio", F),  -- Ada.Wide_Wide_Text_IO.Float_IO
538    ("a-ztinio", F),  -- Ada.Wide_Wide_Text_IO.Integer_IO
539    ("a-ztmoio", F),  -- Ada.Wide_Wide_Text_IO.Modular_IO
540
541   ------------------------
542   -- GNAT Library Units --
543   ------------------------
544
545    ("g-zspche", F),  -- GNAT.Wide_Wide_Spelling_Checker
546    ("g-zstspl", F)); -- GNAT.Wide_Wide_String_Split
547
548   --------------------
549   -- Ada 2012 Units --
550   --------------------
551
552   --  The following units should be used only in Ada 2012 mode
553
554   Non_Imp_File_Names_12 : constant File_List := (
555    ("s-stposu", T),  -- System.Storage_Pools.Subpools
556    ("a-cobove", T),  -- Ada.Containers.Bounded_Vectors
557    ("a-cbdlli", T),  -- Ada.Containers.Bounded_Doubly_Linked_Lists
558    ("a-cborse", T),  -- Ada.Containers.Bounded_Ordered_Sets
559    ("a-cborma", T),  -- Ada.Containers.Bounded_Ordered_Maps
560    ("a-cbhase", T),  -- Ada.Containers.Bounded_Hashed_Sets
561    ("a-cbhama", T),  -- Ada.Containers.Bounded_Hashed_Maps
562    ("a-coinho", T),  -- Ada.Containers.Indefinite_Holders
563    ("a-comutr", T),  -- Ada.Containers.Multiway_Trees
564    ("a-cimutr", T),  -- Ada.Containers.Indefinite_Multiway_Trees
565    ("a-cbmutr", T),  -- Ada.Containers.Bounded_Multiway_Trees
566    ("a-csquin", T),  -- Ada.Containers.Synchronized_Queue_Interfaces
567    ("a-cusyqu", T),  -- Ada.Containers.Unbounded_Synchronized_Queues
568    ("a-cuprqu", T),  -- Ada.Containers.Unbounded_Priority_Queues
569    ("a-cbsyqu", T),  -- Ada.Containers.Bounded_Synchronized_Queues
570    ("a-cbprqu", T),  -- Ada.Containers.Bounded_Priority_Queues
571    ("a-extiin", T),  -- Ada.Execution_Time.Interrupts
572    ("a-iteint", T),  -- Ada.Iterator_Interfaces
573    ("a-locale", T),  -- Ada.Locales
574    ("a-synbar", T),  -- Ada.Synchronous_Barriers
575    ("a-undesu", T),  -- Ada.Unchecked_Deallocate_Subpool
576
577   ----------------------------------------
578   -- GNAT Defined Additions to Ada 2012 --
579   ----------------------------------------
580
581    ("a-cofove", F),  -- Ada.Containers.Formal_Vectors
582    ("a-cfdlli", F),  -- Ada.Containers.Formal_Doubly_Linked_Lists
583    ("a-cforse", F),  -- Ada.Containers.Formal_Ordered_Sets
584    ("a-cforma", F),  -- Ada.Containers.Formal_Ordered_Maps
585    ("a-cfhase", F),  -- Ada.Containers.Formal_Hashed_Sets
586    ("a-cfhama", F)); -- Ada.Containers.Formal_Hashed_Maps
587
588   -----------------------
589   -- Alternative Units --
590   -----------------------
591
592   --  For some implementation units, there is a unit in the GNAT library
593   --  that has identical functionality that is usable. If we have such a
594   --  case we record the appropriate Unit name in Error_Msg_String.
595
596   type Aunit_Record is record
597      Fname : String (1 .. 6);
598      Aname : String_Ptr;
599   end record;
600
601   --  Array of alternative unit names
602
603   Scasuti : aliased String := "GNAT.Case_Util";
604   Scrc32  : aliased String := "GNAT.CRC32";
605   Shtable : aliased String := "GNAT.HTable";
606   Sos_lib : aliased String := "GNAT.OS_Lib";
607   Sregexp : aliased String := "GNAT.Regexp";
608   Sregpat : aliased String := "GNAT.Regpat";
609   Sstring : aliased String := "GNAT.Strings";
610   Sstusta : aliased String := "GNAT.Task_Stack_Usage";
611   Stasloc : aliased String := "GNAT.Task_Lock";
612   Sutf_32 : aliased String := "GNAT.UTF_32";
613
614   --  Array giving mapping
615
616   Map_Array : constant array (1 .. 10) of Aunit_Record := (
617                 ("casuti", Scasuti'Access),
618                 ("crc32 ", Scrc32 'Access),
619                 ("htable", Shtable'Access),
620                 ("os_lib", Sos_lib'Access),
621                 ("regexp", Sregexp'Access),
622                 ("regpat", Sregpat'Access),
623                 ("string", Sstring'Access),
624                 ("stusta", Sstusta'Access),
625                 ("tasloc", Stasloc'Access),
626                 ("utf_32", Sutf_32'Access));
627
628   ----------------------
629   -- Get_Kind_Of_Unit --
630   ----------------------
631
632   function Get_Kind_Of_Unit (U : Unit_Number_Type) return Kind_Of_Unit is
633      Fname : constant File_Name_Type := Unit_File_Name (U);
634
635   begin
636      Error_Msg_Strlen := 0;
637      Get_Name_String (Fname);
638
639      --  Ada/System/Interfaces are all Ada 95 units
640
641      if (Name_Len =  7 and then Name_Buffer (1 ..  7) = "ada.ads")
642           or else
643         (Name_Len = 10 and then Name_Buffer (1 .. 10) = "system.ads")
644           or else
645         (Name_Len = 12 and then Name_Buffer (1 .. 12) = "interfac.ads")
646      then
647         return Ada_95_Unit;
648      end if;
649
650      --  If length of file name is greater than 12, not predefined. The value
651      --  12 here is an 8 char name with extension .ads.
652
653      if Name_Len > 12 then
654         return Not_Predefined_Unit;
655      end if;
656
657      --  Not predefined if file name does not start with a- g- s- i-
658
659      if Name_Len < 3
660        or else Name_Buffer (2) /= '-'
661        or else (Name_Buffer (1) /= 'a'
662                   and then
663                 Name_Buffer (1) /= 'g'
664                   and then
665                 Name_Buffer (1) /= 'i'
666                   and then
667                 Name_Buffer (1) /= 's')
668      then
669         return Not_Predefined_Unit;
670      end if;
671
672      --  To be considered predefined, the file name must end in .ads or .adb.
673      --  File names with other extensions (coming from the use of non-standard
674      --  file naming schemes) can never be predefined.
675
676      --  Note that in the context of a compiler, the .adb case will never
677      --  arise. However it can arise for other tools, e.g. gnatprove uses
678      --  this routine to detect when a construct comes from an instance of
679      --  a generic defined in a predefined unit.
680
681      if Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads"
682           and then
683         Name_Buffer (Name_Len - 3 .. Name_Len) /= ".adb"
684      then
685         return Not_Predefined_Unit;
686      end if;
687
688      --  Otherwise normalize file name to 8 characters
689
690      Name_Len := Name_Len - 4;
691      while Name_Len < 8 loop
692         Name_Len := Name_Len + 1;
693         Name_Buffer (Name_Len) := ' ';
694      end loop;
695
696      --  See if name is in 95 list
697
698      for J in Non_Imp_File_Names_95'Range loop
699         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_95 (J).Fname then
700            return Ada_95_Unit;
701         end if;
702      end loop;
703
704      --  See if name is in 2005 list
705
706      for J in Non_Imp_File_Names_05'Range loop
707         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_05 (J).Fname then
708            return Ada_2005_Unit;
709         end if;
710      end loop;
711
712      --  See if name is in 2012 list
713
714      for J in Non_Imp_File_Names_12'Range loop
715         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_12 (J).Fname then
716            return Ada_2012_Unit;
717         end if;
718      end loop;
719
720      --  Only remaining special possibilities are children of System.RPC and
721      --  System.Garlic and special files of the form System.Aux...
722
723      Get_Name_String (Unit_Name (U));
724
725      if Name_Len > 12
726        and then Name_Buffer (1 .. 11) = "system.rpc."
727      then
728         return Ada_95_Unit;
729      end if;
730
731      if Name_Len > 15
732        and then Name_Buffer (1 .. 14) = "system.garlic."
733      then
734         return Ada_95_Unit;
735      end if;
736
737      if Name_Len > 11
738        and then Name_Buffer (1 .. 10) = "system.aux"
739      then
740         return Ada_95_Unit;
741      end if;
742
743      --  All tests failed, this is definitely an implementation unit. See if
744      --  we have an alternative name.
745
746      Get_Name_String (Fname);
747
748      if Name_Len in 11 .. 12
749        and then Name_Buffer (1 .. 2) = "s-"
750        and then Name_Buffer (Name_Len - 3 .. Name_Len) = ".ads"
751      then
752         for J in Map_Array'Range loop
753            if (Name_Len = 12 and then
754                 Name_Buffer (3 .. 8) = Map_Array (J).Fname)
755              or else
756               (Name_Len = 11 and then
757                 Name_Buffer (3 .. 7) = Map_Array (J).Fname (1 .. 5))
758            then
759               Error_Msg_Strlen := Map_Array (J).Aname'Length;
760               Error_Msg_String (1 .. Error_Msg_Strlen) :=
761                 Map_Array (J).Aname.all;
762            end if;
763         end loop;
764      end if;
765
766      return Implementation_Unit;
767   end Get_Kind_Of_Unit;
768
769   -------------------
770   -- Is_Known_Unit --
771   -------------------
772
773   function Is_Known_Unit (Nam : Node_Id) return Boolean is
774      Unam : Unit_Name_Type;
775      Fnam : File_Name_Type;
776
777   begin
778      --  If selector is not an identifier (e.g. it is a character literal or
779      --  some junk from a previous error), then definitely not a known unit.
780
781      if Nkind (Selector_Name (Nam)) /= N_Identifier then
782         return False;
783      end if;
784
785      --  Otherwise get corresponding file name
786
787      Unam := Get_Unit_Name (Nam);
788      Fnam := Get_File_Name (Unam, Subunit => False);
789      Get_Name_String (Fnam);
790
791      Error_Msg_Strlen := 0;
792
793      --  Ada/System/Interfaces are all Ada 95 units
794
795      if (Name_Len =  7 and then Name_Buffer (1 ..  7) = "ada.ads")
796           or else
797         (Name_Len = 10 and then Name_Buffer (1 .. 10) = "system.ads")
798           or else
799         (Name_Len = 12 and then Name_Buffer (1 .. 12) = "interfac.ads")
800      then
801         return True;
802      end if;
803
804      --  Remove extension from file name
805
806      if Name_Buffer (Name_Len - 3 .. Name_Len) = ".adb"
807           or else
808         Name_Buffer (Name_Len - 3 .. Name_Len) = ".ads"
809      then
810         Name_Len := Name_Len - 4;
811      else
812         return False;
813      end if;
814
815      --  Pad name to 8 characters
816
817      while Name_Len < 8 loop
818         Name_Len := Name_Len + 1;
819         Name_Buffer (Name_Len) := ' ';
820      end loop;
821
822      --  If length more than 8, definitely not a match
823
824      if Name_Len /= 8 then
825         return False;
826      end if;
827
828      --  If length is 8, search our tables
829
830      for J in Non_Imp_File_Names_95'Range loop
831         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_95 (J).Fname then
832            return True;
833         end if;
834      end loop;
835
836      for J in Non_Imp_File_Names_05'Range loop
837         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_05 (J).Fname then
838            return True;
839         end if;
840      end loop;
841
842      for J in Non_Imp_File_Names_12'Range loop
843         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_12 (J).Fname then
844            return True;
845         end if;
846      end loop;
847
848      --  If not found, not known
849
850      return False;
851
852   --  A safety guard, if we get an exception during this processing then it
853   --  is most likely the result of a previous error, or a peculiar case we
854   --  have not thought of. Since this routine is only used for error message
855   --  refinement, we will just return False.
856
857   exception
858      when others =>
859         return False;
860   end Is_Known_Unit;
861
862   ---------------------------
863   -- Not_Impl_Defined_Unit --
864   ---------------------------
865
866   function Not_Impl_Defined_Unit (U : Unit_Number_Type) return Boolean is
867      Fname : constant File_Name_Type := Unit_File_Name (U);
868
869   begin
870      Error_Msg_Strlen := 0;
871      Get_Name_String (Fname);
872
873      --  Ada/System/Interfaces are all RM-defined Ada 95 units
874
875      if (Name_Len =  7 and then Name_Buffer (1 ..  7) = "ada.ads")
876           or else
877         (Name_Len = 10 and then Name_Buffer (1 .. 10) = "system.ads")
878           or else
879         (Name_Len = 12 and then Name_Buffer (1 .. 12) = "interfac.ads")
880      then
881         return True;
882      end if;
883
884      --  If length of file name is greater than 12, then it's a user unit
885      --  and not a GNAT implementation defined unit.
886
887      if Name_Len > 12 then
888         return True;
889      end if;
890
891      --  Implementation defined if unit in the gnat hierarchy
892
893      if (Name_Len = 8 and then Name_Buffer (1 .. 8) = "gnat.ads")
894        or else (Name_Len > 2 and then Name_Buffer (1 .. 2) = "g-")
895      then
896         return False;
897      end if;
898
899      --  Not implementation defined if file name does not start with a- s- i-
900
901      if Name_Len < 3
902        or else Name_Buffer (2) /= '-'
903        or else (Name_Buffer (1) /= 'a'
904                   and then
905                 Name_Buffer (1) /= 'i'
906                   and then
907                 Name_Buffer (1) /= 's')
908      then
909         return True;
910      end if;
911
912      --  Not impl-defined if file name does not end in .ads. This can happen
913      --  when non-standard file names are being used.
914
915      if Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads" then
916         return True;
917      end if;
918
919      --  Otherwise normalize file name to 8 characters
920
921      Name_Len := Name_Len - 4;
922      while Name_Len < 8 loop
923         Name_Len := Name_Len + 1;
924         Name_Buffer (Name_Len) := ' ';
925      end loop;
926
927      --  Check our lists of names, if we find a match, return corresponding
928      --  indication of whether the file is RM defined, respecting the RM
929      --  version in which it is defined.
930
931      for J in Non_Imp_File_Names_95'Range loop
932         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_95 (J).Fname then
933            return Non_Imp_File_Names_95 (J).RMdef;
934         end if;
935      end loop;
936
937      for J in Non_Imp_File_Names_05'Range loop
938         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_05 (J).Fname then
939            return Non_Imp_File_Names_05 (J).RMdef
940              and then Ada_Version >= Ada_2005;
941         end if;
942      end loop;
943
944      for J in Non_Imp_File_Names_12'Range loop
945         if Name_Buffer (1 .. 8) = Non_Imp_File_Names_12 (J).Fname then
946            return Non_Imp_File_Names_95 (J).RMdef
947              and then Ada_Version >= Ada_2012;
948         end if;
949      end loop;
950
951      --  If unit is in System, Ada or Interfaces hierarchies and did not match
952      --  any entry in the list, means it is an internal implementation defined
953      --  unit which the restriction should definition forbid.
954
955      return True;
956   end Not_Impl_Defined_Unit;
957
958end Impunit;
959