OSDN Git Service

2004-09-09 Vincent Celier <celier@gnat.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / impunit.adb
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-2004 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 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 with Lib;   use Lib;
28 with Namet; use Namet;
29 with Opt;   use Opt;
30
31 package body Impunit is
32
33    subtype File_Name_8 is String (1 .. 8);
34    type File_List is array (Nat range <>) of File_Name_8;
35
36    --  The following is a giant string containing the concenated names
37    --  of all non-implementation internal files, i.e. the complete list
38    --  of files for internal units which a program may legitimately WITH.
39
40    --  Note that this list should match the list of units documented in
41    --  the "GNAT Library" section of the GNAT Reference Manual.
42
43    Non_Imp_File_Names : constant File_List := (
44
45    -----------------------------------------------
46    -- Ada Hierarchy Units from Reference Manual --
47    -----------------------------------------------
48
49      "a-astaco",    -- Ada.Asynchronous_Task_Control
50      "a-calend",    -- Ada.Calendar
51      "a-chahan",    -- Ada.Characters.Handling
52      "a-charac",    -- Ada.Characters
53      "a-chlat1",    -- Ada.Characters.Latin_1
54      "a-comlin",    -- Ada.Command_Line
55      "a-decima",    -- Ada.Decimal
56      "a-direct",    -- Ada.Directories
57      "a-direio",    -- Ada.Direct_IO
58      "a-dynpri",    -- Ada.Dynamic_Priorities
59      "a-except",    -- Ada.Exceptions
60      "a-finali",    -- Ada.Finalization
61      "a-flteio",    -- Ada.Float_Text_IO
62      "a-fwteio",    -- Ada.Float_Wide_Text_IO
63      "a-inteio",    -- Ada.Integer_Text_IO
64      "a-interr",    -- Ada.Interrupts
65      "a-intnam",    -- Ada.Interrupts.Names
66      "a-ioexce",    -- Ada.IO_Exceptions
67      "a-iwteio",    -- Ada.Integer_Wide_Text_IO
68      "a-ncelfu",    -- Ada.Numerics.Complex_Elementary_Functions
69      "a-ngcefu",    -- Ada.Numerics.Generic_Complex_Elementary_Functions
70      "a-ngcoty",    -- Ada.Numerics.Generic_Complex_Types
71      "a-ngelfu",    -- Ada.Numerics.Generic_Elementary_Functions
72      "a-nucoty",    -- Ada.Numerics.Complex_Types
73      "a-nudira",    -- Ada.Numerics.Discrete_Random
74      "a-nuelfu",    -- Ada.Numerics.Elementary_Functions
75      "a-nuflra",    -- Ada.Numerics.Float_Random
76      "a-numeri",    -- Ada.Numerics
77      "a-reatim",    -- Ada.Real_Time
78      "a-sequio",    -- Ada.Sequential_IO
79      "a-stmaco",    -- Ada.Strings.Maps.Constants
80      "a-storio",    -- Ada.Storage_IO
81      "a-strbou",    -- Ada.Strings.Bounded
82      "a-stream",    -- Ada.Streams
83      "a-strfix",    -- Ada.Strings.Fixed
84      "a-string",    -- Ada.Strings
85      "a-strmap",    -- Ada.Strings.Maps
86      "a-strunb",    -- Ada.Strings.Unbounded
87      "a-ststio",    -- Ada.Streams.Stream_IO
88      "a-stwibo",    -- Ada.Strings.Wide_Bounded
89      "a-stwifi",    -- Ada.Strings.Wide_Fixed
90      "a-stwima",    -- Ada.Strings.Wide_Maps
91      "a-stwiun",    -- Ada.Strings.Wide_Unbounded
92      "a-swmwco",    -- Ada.Strings.Wide_Maps.Wide_Constants
93      "a-sytaco",    -- Ada.Synchronous_Task_Control
94      "a-tags  ",    -- Ada.Tags
95      "a-tasatt",    -- Ada.Task_Attributes
96      "a-taside",    -- Ada.Task_Identification
97      "a-teioed",    -- Ada.Text_IO.Editing
98      "a-textio",    -- Ada.Text_IO
99      "a-ticoio",    -- Ada.Text_IO.Complex_IO
100      "a-titest",    -- Ada.Text_IO.Text_Streams
101      "a-unccon",    -- Ada.Unchecked_Conversion
102      "a-uncdea",    -- Ada.Unchecked_Deallocation
103      "a-witeio",    -- Ada.Wide_Text_IO
104      "a-wtcoio",    -- Ada.Wide_Text_IO.Complex_IO
105      "a-wtedit",    -- Ada.Wide_Text_IO.Editing
106      "a-wttest",    -- Ada.Wide_Text_IO.Text_Streams
107
108    -------------------------------------------------
109    -- RM Required Additions to Ada for GNAT Types --
110    -------------------------------------------------
111
112      "a-lfteio",    -- Ada.Long_Float_Text_IO
113      "a-lfwtio",    -- Ada.Long_Float_Wide_Text_IO
114      "a-liteio",    -- Ada.Long_Integer_Text_IO
115      "a-liwtio",    -- Ada.Long_Integer_Wide_Text_IO
116      "a-llftio",    -- Ada.Long_Long_Float_Text_IO
117      "a-llfwti",    -- Ada.Long_Long_Float_Wide_Text_IO
118      "a-llitio",    -- Ada.Long_Long_Integer_Text_IO
119      "a-lliwti",    -- Ada.Long_Long_Integer_Wide_Text_IO
120      "a-nlcefu",    -- Ada.Long_Complex_Elementary_Functions
121      "a-nlcoty",    -- Ada.Numerics.Long_Complex_Types
122      "a-nlelfu",    -- Ada.Numerics.Long_Elementary_Functions
123      "a-nllcef",    -- Ada.Long_Long_Complex_Elementary_Functions
124      "a-nllefu",    -- Ada.Numerics.Long_Long_Elementary_Functions
125      "a-nllcty",    -- Ada.Numerics.Long_Long_Complex_Types
126      "a-nscefu",    -- Ada.Short_Complex_Elementary_Functions
127      "a-nscoty",    -- Ada.Numerics.Short_Complex_Types
128      "a-nselfu",    -- Ada.Numerics.Short_Elementary_Functions
129      "a-sfteio",    -- Ada.Short_Float_Text_IO
130      "a-sfwtio",    -- Ada.Short_Float_Wide_Text_IO
131      "a-siteio",    -- Ada.Short_Integer_Text_IO
132      "a-siwtio",    -- Ada.Short_Integer_Wide_Text_IO
133      "a-ssitio",    -- Ada.Short_Short_Integer_Text_IO
134      "a-ssiwti",    -- Ada.Short_Short_Integer_Wide_Text_IO
135
136    -----------------------------------
137    -- GNAT Defined Additions to Ada --
138    -----------------------------------
139
140      "a-chlat9",    -- Ada.Characters.Latin_9
141      "a-colien",    -- Ada.Command_Line.Environment
142      "a-colire",    -- Ada.Command_Line.Remove
143      "a-cwila1",    -- Ada.Characters.Wide_Latin_1
144      "a-cwila9",    -- Ada.Characters.Wide_Latin_9
145      "a-diocst",    -- Ada.Direct_IO.C_Streams
146      "a-einuoc",    -- Ada.Exceptions.Is_Null_Occurrence
147      "a-exctra",    -- Ada.Exceptions.Traceback
148      "a-siocst",    -- Ada.Sequential_IO.C_Streams
149      "a-ssicst",    -- Ada.Streams.Stream_IO.C_Streams
150      "a-suteio",    -- Ada.Strings.Unbounded.Text_IO
151      "a-swuwti",    -- Ada.Strings.Wide_Unbounded.Wide_Text_IO
152      "a-taidim",    -- Ada.Task_Identification.Image
153      "a-tiocst",    -- Ada.Text_IO.C_Streams
154      "a-wtcstr",    -- Ada.Wide_Text_IO.C_Streams
155
156    ---------------------------
157    -- GNAT Special IO Units --
158    ---------------------------
159
160    --  As further explained elsewhere (see Sem_Ch10), the internal
161    --  packages of Text_IO and Wide_Text_IO are actually implemented
162    --  as separate children, but this fact is intended to be hidden
163    --  from the user completely. Any attempt to WITH one of these
164    --  units will be diagnosed as an error later on, but for now we
165    --  do not consider these internal implementation units (if we did,
166    --  then we would get a junk warning which would be confusing and
167    --  unecessary, given that we generate a clear error message).
168
169      "a-tideio",    -- Ada.Text_IO.Decimal_IO
170      "a-tienio",    -- Ada.Text_IO.Enumeration_IO
171      "a-tifiio",    -- Ada.Text_IO.Fixed_IO
172      "a-tiflio",    -- Ada.Text_IO.Float_IO
173      "a-tiinio",    -- Ada.Text_IO.Integer_IO
174      "a-tiinio",    -- Ada.Text_IO.Integer_IO
175      "a-timoio",    -- Ada.Text_IO.Modular_IO
176      "a-wtdeio",    -- Ada.Wide_Text_IO.Decimal_IO
177      "a-wtenio",    -- Ada.Wide_Text_IO.Enumeration_IO
178      "a-wtfiio",    -- Ada.Wide_Text_IO.Fixed_IO
179      "a-wtflio",    -- Ada.Wide_Text_IO.Float_IO
180      "a-wtinio",    -- Ada.Wide_Text_IO.Integer_IO
181      "a-wtmoio",    -- Ada.Wide_Text_IO.Modular_IO
182
183    ------------------------
184    -- GNAT Library Units --
185    ------------------------
186
187      "g-arrspl",    -- GNAT.Array_Split
188      "g-awk   ",    -- GNAT.AWK
189      "g-boubuf",    -- GNAT.Bounded_Buffers
190      "g-boumai",    -- GNAT.Bounded_Mailboxes
191      "g-bubsor",    -- GNAT.Bubble_Sort
192      "g-busora",    -- GNAT.Bubble_Sort_A
193      "g-busorg",    -- GNAT.Bubble_Sort_G
194      "g-calend",    -- GNAT.Calendar
195      "g-casuti",    -- GNAT.Case_Util
196      "g-catiio",    -- GNAT.Calendar.Time_IO
197      "g-cgi   ",    -- GNAT.CGI
198      "g-cgicoo",    -- GNAT.CGI.Cookie
199      "g-cgideb",    -- GNAT.CGI.Debug
200      "g-comlin",    -- GNAT.Command_Line
201      "g-comver",    -- GNAT.Compiler_Version
202      "g-crc32 ",    -- GNAT.CRC32
203      "g-ctrl_c",    -- GNAT.Ctrl_C
204      "g-curexc",    -- GNAT.Current_Exception
205      "g-debpoo",    -- GNAT.Debug_Pools
206      "g-debuti",    -- GNAT.Debug_Utilities
207      "g-diopit",    -- GNAT.Directory_Operations.Iteration
208      "g-dirope",    -- GNAT.Directory_Operations
209      "g-dynhta",    -- GNAT.Dynamic_HTables
210      "g-dyntab",    -- GNAT.Dynamic_Tables
211      "g-excact",    -- GNAT.Exception_Actions
212      "g-except",    -- GNAT.Exceptions
213      "g-exctra",    -- GNAT.Exception_Traces
214      "g-expect",    -- GNAT.Expect
215      "g-flocon",    -- GNAT.Float_Control
216      "g-heasor",    -- GNAT.Heap_Sort
217      "g-hesora",    -- GNAT.Heap_Sort_A
218      "g-hesorg",    -- GNAT.Heap_Sort_G
219      "g-htable",    -- GNAT.Htable
220      "g-io    ",    -- GNAT.IO
221      "g-io_aux",    -- GNAT.IO_Aux
222      "g-locfil",    -- GNAT.Lock_Files
223      "g-md5   ",    -- GNAT.MD5
224      "g-memdum",    -- GNAT.Memory_Dump
225      "g-moreex",    -- GNAT.Most_Recent_Exception
226      "g-os_lib",    -- GNAT.Os_Lib
227      "g-pehage",    -- GNAT.Perfect_Hash_Generators
228      "g-regexp",    -- GNAT.Regexp
229      "g-regist",    -- GNAT.Registry
230      "g-regpat",    -- GNAT.Regpat
231      "g-semaph",    -- GNAT.Semaphores
232      "g-sestin",    -- GNAT.Secondary_Stack_Info
233      "g-signal",    -- GNAT.Signals
234      "g-socket",    -- GNAT.Sockets
235      "g-souinf",    -- GNAT.Source_Info
236      "g-speche",    -- GNAT.Spell_Checker
237      "g-spipat",    -- GNAT.Spitbol.Patterns
238      "g-spitbo",    -- GNAT.Spitbol
239      "g-sptabo",    -- GNAT.Spitbol.Table_Boolean
240      "g-sptain",    -- GNAT.Spitbol.Table_Integer
241      "g-sptavs",    -- GNAT.Spitbol.Table_Vstring
242      "g-string",    -- GNAT.Strings
243      "g-strspl",    -- GNAT.String_Split
244      "g-table ",    -- GNAT.Table
245      "g-tasloc",    -- GNAT.Task_Lock
246      "g-thread",    -- GNAT.Threads
247      "g-traceb",    -- GNAT.Traceback
248      "g-trasym",    -- GNAT.Traceback.Symbolic
249      "g-wistsp",    -- GNAT.Wide_String_Split
250
251    -----------------------------------------------------
252    -- Interface Hierarchy Units from Reference Manual --
253    -----------------------------------------------------
254
255      "i-c     ",    -- Interfaces.C
256      "i-cobol ",    -- Interfaces.Cobol
257      "i-cpoint",    -- Interfaces.C.Pointers
258      "i-cstrin",    -- Interfaces.C.Strings
259      "i-fortra",    -- Interfaces.Fortran
260
261    ------------------------------------------
262    -- GNAT Defined Additions to Interfaces --
263    ------------------------------------------
264
265      "i-cexten",    -- Interfaces.C.Extensions
266      "i-cpp   ",    -- Interfaces.CPP
267      "i-cstrea",    -- Interfaces.C.Streams
268      "i-jalaob",    -- Interfaces.Java.Lang.Object
269      "i-jalasy",    -- Interfaces.Java.Lang.System
270      "i-jalath",    -- Interfaces.Java.Lang.Thread
271      "i-java  ",    -- Interfaces.Java
272      "i-javlan",    -- Interfaces.Java.Lang
273      "i-os2err",    -- Interfaces.Os2lib.Errors
274      "i-os2lib",    -- Interfaces.Os2lib
275      "i-os2syn",    -- Interfaces.Os2lib.Synchronization
276      "i-os2thr",    -- Interfaces.Os2lib.Threads
277      "i-pacdec",    -- Interfaces.Packed_Decimal
278      "i-vthrea",    -- Interfaces.Vthreads
279      "i-vxwoio",    -- Interfaces.VxWorks.IO
280      "i-vxwork",    -- Interfaces.VxWorks
281
282    --------------------------------------------------
283    -- System Hierarchy Units from Reference Manual --
284    --------------------------------------------------
285
286      "s-atacco",    -- System.Address_To_Access_Conversions
287      "s-maccod",    -- System.Machine_Code
288      "s-rpc   ",    -- System.Rpc
289      "s-stoele",    -- System.Storage_Elements
290      "s-stopoo",    -- System.Storage_Pools
291
292    --------------------------------------
293    -- GNAT Defined Additions to System --
294    --------------------------------------
295
296      "s-addima",    -- System.Address_Image
297      "s-assert",    -- System.Assertions
298      "s-memory",    -- System.Memory
299      "s-parint",    -- System.Partition_Interface
300      "s-restri",    -- System.Restrictions
301      "s-rident",    -- System.Rident
302      "s-tasinf",    -- System.Task_Info
303      "s-wchcnv",    -- System.Wch_Cnv
304      "s-wchcon");   -- System.Wch_Con
305
306    -------------------------
307    -- Implementation_Unit --
308    -------------------------
309
310    function Implementation_Unit (U : Unit_Number_Type) return Boolean is
311       Fname : constant File_Name_Type := Unit_File_Name (U);
312
313    begin
314       --  All units are OK in GNAT mode
315
316       if GNAT_Mode then
317          return False;
318       end if;
319
320       --  If length of file name is greater than 12, definitely OK!
321       --  The value 12 here is an 8 char name with extension .ads.
322
323       if Length_Of_Name (Fname) > 12 then
324          return False;
325       end if;
326
327       --  Otherwise test file name
328
329       Get_Name_String (Fname);
330
331       --  Definitely OK if file name does not start with a- g- s- i-
332
333       if Name_Len < 3
334         or else Name_Buffer (2) /= '-'
335         or else (Name_Buffer (1) /= 'a'
336                    and then
337                  Name_Buffer (1) /= 'g'
338                    and then
339                  Name_Buffer (1) /= 'i'
340                    and then
341                  Name_Buffer (1) /= 's')
342       then
343          return False;
344       end if;
345
346       --  Definitely OK if file name does not end in .ads. This can
347       --  happen when non-standard file names are being used.
348
349       if Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads" then
350          return False;
351       end if;
352
353       --  Otherwise normalize file name to 8 characters
354
355       Name_Len := Name_Len - 4;
356       while Name_Len < 8 loop
357          Name_Len := Name_Len + 1;
358          Name_Buffer (Name_Len) := ' ';
359       end loop;
360
361       --  Definitely OK if name is in list
362
363       for J in Non_Imp_File_Names'Range loop
364          if Name_Buffer (1 .. 8) = Non_Imp_File_Names (J) then
365             return False;
366          end if;
367       end loop;
368
369       --  Only remaining special possibilities are children of
370       --  System.RPC and System.Garlic and special files of the
371       --  form System.Aux...
372
373       Get_Name_String (Unit_Name (U));
374
375       if Name_Len > 12
376         and then Name_Buffer (1 .. 11) = "system.rpc."
377       then
378          return False;
379       end if;
380
381       if Name_Len > 15
382         and then Name_Buffer (1 .. 14) = "system.garlic."
383       then
384          return False;
385       end if;
386
387       if Name_Len > 11
388         and then Name_Buffer (1 .. 10) = "system.aux"
389       then
390          return False;
391       end if;
392
393       --  All tests failed, this is definitely an implementation unit
394
395       return True;
396
397    end Implementation_Unit;
398
399 end Impunit;