OSDN Git Service

* 1aexcept.adb, 1aexcept.ads, 1ic.ads, 1ssecsta.adb,
[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-2002 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 : 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-direio",    -- Ada.Direct_IO
57      "a-dynpri",    -- Ada.Dynamic_Priorities
58      "a-except",    -- Ada.Exceptions
59      "a-finali",    -- Ada.Finalization
60      "a-flteio",    -- Ada.Float_Text_IO
61      "a-fwteio",    -- Ada.Float_Wide_Text_IO
62      "a-inteio",    -- Ada.Integer_Text_IO
63      "a-interr",    -- Ada.Interrupts
64      "a-intnam",    -- Ada.Interrupts.Names
65      "a-ioexce",    -- Ada.IO_Exceptions
66      "a-iwteio",    -- Ada.Integer_Wide_Text_IO
67      "a-ncelfu",    -- Ada.Numerics.Complex_Elementary_Functions
68      "a-ngcefu",    -- Ada.Numerics.Generic_Complex_Elementary_Functions
69      "a-ngcoty",    -- Ada.Numerics.Generic_Complex_Types
70      "a-ngelfu",    -- Ada.Numerics.Generic_Elementary_Functions
71      "a-nucoty",    -- Ada.Numerics.Complex_Types
72      "a-nudira",    -- Ada.Numerics.Discrete_Random
73      "a-nuelfu",    -- Ada.Numerics.Elementary_Functions
74      "a-nuflra",    -- Ada.Numerics.Float_Random
75      "a-numeri",    -- Ada.Numerics
76      "a-reatim",    -- Ada.Real_Time
77      "a-sequio",    -- Ada.Sequential_IO
78      "a-stmaco",    -- Ada.Strings.Maps.Constants
79      "a-storio",    -- Ada.Storage_IO
80      "a-strbou",    -- Ada.Strings.Bounded
81      "a-stream",    -- Ada.Streams
82      "a-strfix",    -- Ada.Strings.Fixed
83      "a-string",    -- Ada.Strings
84      "a-strmap",    -- Ada.Strings.Maps
85      "a-strunb",    -- Ada.Strings.Unbounded
86      "a-ststio",    -- Ada.Streams.Stream_IO
87      "a-stwibo",    -- Ada.Strings.Wide_Bounded
88      "a-stwifi",    -- Ada.Strings.Wide_Fixed
89      "a-stwima",    -- Ada.Strings.Wide_Maps
90      "a-stwiun",    -- Ada.Strings.Wide_Unbounded
91      "a-swmwco",    -- Ada.Strings.Wide_Maps.Wide_Constants
92      "a-sytaco",    -- Ada.Synchronous_Task_Control
93      "a-tags  ",    -- Ada.Tags
94      "a-tasatt",    -- Ada.Task_Attributes
95      "a-taside",    -- Ada.Task_Identification
96      "a-teioed",    -- Ada.Text_IO.Editing
97      "a-textio",    -- Ada.Text_IO
98      "a-ticoio",    -- Ada.Text_IO.Complex_IO
99      "a-titest",    -- Ada.Text_IO.Text_Streams
100      "a-unccon",    -- Ada.Unchecked_Conversion
101      "a-uncdea",    -- Ada.Unchecked_Deallocation
102      "a-witeio",    -- Ada.Wide_Text_IO
103      "a-wtcoio",    -- Ada.Wide_Text_IO.Complex_IO
104      "a-wtedit",    -- Ada.Wide_Text_IO.Editing
105      "a-wttest",    -- Ada.Wide_Text_IO.Text_Streams
106
107    -------------------------------------------------
108    -- RM Required Additions to Ada for GNAT Types --
109    -------------------------------------------------
110
111      "a-lfteio",    -- Ada.Long_Float_Text_IO
112      "a-lfwtio",    -- Ada.Long_Float_Wide_Text_IO
113      "a-liteio",    -- Ada.Long_Integer_Text_IO
114      "a-liwtio",    -- Ada.Long_Integer_Wide_Text_IO
115      "a-llftio",    -- Ada.Long_Long_Float_Text_IO
116      "a-llfwti",    -- Ada.Long_Long_Float_Wide_Text_IO
117      "a-llitio",    -- Ada.Long_Long_Integer_Text_IO
118      "a-lliwti",    -- Ada.Long_Long_Integer_Wide_Text_IO
119      "a-nlcefu",    -- Ada.Long_Complex_Elementary_Functions
120      "a-nlcoty",    -- Ada.Numerics.Long_Complex_Types
121      "a-nlelfu",    -- Ada.Numerics.Long_Elementary_Functions
122      "a-nllcef",    -- Ada.Long_Long_Complex_Elementary_Functions
123      "a-nllefu",    -- Ada.Numerics.Long_Long_Elementary_Functions
124      "a-nltcty",    -- Ada.Numerics.Long_Long_Complex_Types
125      "a-nscefu",    -- Ada.Short_Complex_Elementary_Functions
126      "a-nscoty",    -- Ada.Numerics.Short_Complex_Types
127      "a-nselfu",    -- Ada.Numerics.Short_Elementary_Functions
128      "a-sfteio",    -- Ada.Short_Float_Text_IO
129      "a-sfwtio",    -- Ada.Short_Float_Wide_Text_IO
130      "a-siteio",    -- Ada.Short_Integer_Text_IO
131      "a-siwtio",    -- Ada.Short_Integer_Wide_Text_IO
132      "a-ssitio",    -- Ada.Short_Short_Integer_Text_IO
133      "a-ssiwti",    -- Ada.Short_Short_Integer_Wide_Text_IO
134
135    -----------------------------------
136    -- GNAT Defined Additions to Ada --
137    -----------------------------------
138
139      "a-chlat9",    -- Ada.Characters.Latin_9
140      "a-colire",    -- Ada.Command_Line.Remove
141      "a-cwila1",    -- Ada.Characters.Wide_Latin_1
142      "a-cwila9",    -- Ada.Characters.Wide_Latin_9
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
152
153    ---------------------------
154    -- GNAT Special IO Units --
155    ---------------------------
156
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).
165
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
179
180    ------------------------
181    -- GNAT Library Units --
182    ------------------------
183
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-diopit",    -- GNAT.Directory_Operations.Iteration
199      "g-dirope",    -- GNAT.Directory_Operations
200      "g-dyntab",    -- GNAT.Dynamic_Tables
201      "g-exctra",    -- GNAT.Exception_Traces
202      "g-expect",    -- GNAT.Expect
203      "g-flocon",    -- GNAT.Float_Control
204      "g-htable",    -- GNAT.Htable
205      "g-hesora",    -- GNAT.Heap_Sort_A
206      "g-hesorg",    -- GNAT.Heap_Sort_G
207      "g-io    ",    -- GNAT.IO
208      "g-io_aux",    -- GNAT.IO_Aux
209      "g-locfil",    -- GNAT.Lock_Files
210      "g-md5   ",    -- GNAT.MD5
211      "g-moreex",    -- GNAT.Most_Recent_Exception
212      "g-os_lib",    -- GNAT.Os_Lib
213      "g-regexp",    -- GNAT.Regexp
214      "g-regist",    -- GNAT.Registry
215      "g-regpat",    -- GNAT.Regpat
216      "g-socket",    -- GNAT.Sockets
217      "g-sptabo",    -- GNAT.Spitbol.Table_Boolean
218      "g-sptain",    -- GNAT.Spitbol.Table_Integer
219      "g-sptavs",    -- GNAT.Spitbol.Table_Vstring
220      "g-souinf",    -- GNAT.Source_Info
221      "g-speche",    -- GNAT.Spell_Checker
222      "g-spitbo",    -- GNAT.Spitbol
223      "g-spipat",    -- GNAT.Spitbol.Patterns
224      "g-table ",    -- GNAT.Table
225      "g-tasloc",    -- GNAT.Task_Lock
226      "g-thread",    -- GNAT.Threads
227      "g-traceb",    -- GNAT.Traceback
228      "g-trasym",    -- GNAT.Traceback.Symbolic
229
230    -----------------------------------------------------
231    -- Interface Hierarchy Units from Reference Manual --
232    -----------------------------------------------------
233
234      "i-c     ",    -- Interfaces.C
235      "i-cobol ",    -- Interfaces.Cobol
236      "i-cpoint",    -- Interfaces.C.Pointers
237      "i-cstrin",    -- Interfaces.C.Strings
238      "i-fortra",    -- Interfaces.Fortran
239
240    ------------------------------------------
241    -- GNAT Defined Additions to Interfaces --
242    ------------------------------------------
243
244      "i-cexten",    -- Interfaces.C.Extensions
245      "i-csthre",    -- Interfaces.C.Sthreads
246      "i-cstrea",    -- Interfaces.C.Streams
247      "i-cpp   ",    -- Interfaces.CPP
248      "i-java  ",    -- Interfaces.Java
249      "i-javlan",    -- Interfaces.Java.Lang
250      "i-jalaob",    -- Interfaces.Java.Lang.Object
251      "i-jalasy",    -- Interfaces.Java.Lang.System
252      "i-jalath",    -- Interfaces.Java.Lang.Thread
253      "i-os2err",    -- Interfaces.Os2lib.Errors
254      "i-os2lib",    -- Interfaces.Os2lib
255      "i-os2syn",    -- Interfaces.Os2lib.Synchronization
256      "i-os2thr",    -- Interfaces.Os2lib.Threads
257      "i-pacdec",    -- Interfaces.Packed_Decimal
258      "i-vxwork",    -- Interfaces.VxWorks
259      "i-vxwoio",    -- Interfaces.VxWorks.IO
260
261    --------------------------------------------------
262    -- System Hierarchy Units from Reference Manual --
263    --------------------------------------------------
264
265      "s-atacco",    -- System.Address_To_Access_Conversions
266      "s-maccod",    -- System.Machine_Code
267      "s-rpc   ",    -- System.Rpc
268      "s-stoele",    -- System.Storage_Elements
269      "s-stopoo",    -- System.Storage_Pools
270
271    --------------------------------------
272    -- GNAT Defined Additions to System --
273    --------------------------------------
274
275      "s-addima",    -- System.Address_Image
276      "s-assert",    -- System.Assertions
277      "s-parint",    -- System.Partition_Interface
278      "s-tasinf",    -- System.Task_Info
279      "s-wchcnv",    -- System.Wch_Cnv
280      "s-wchcon");   -- System.Wch_Con
281
282    -------------------------
283    -- Implementation_Unit --
284    -------------------------
285
286    function Implementation_Unit (U : Unit_Number_Type) return Boolean is
287       Fname : constant File_Name_Type := Unit_File_Name (U);
288
289    begin
290       --  All units are OK in GNAT mode
291
292       if GNAT_Mode then
293          return False;
294       end if;
295
296       --  If length of file name is greater than 12, definitely OK!
297       --  The value 12 here is an 8 char name with extension .ads.
298
299       if Length_Of_Name (Fname) > 12 then
300          return False;
301       end if;
302
303       --  Otherwise test file name
304
305       Get_Name_String (Fname);
306
307       --  Definitely OK if file name does not start with a- g- s- i-
308
309       if Name_Len < 3
310         or else Name_Buffer (2) /= '-'
311         or else (Name_Buffer (1) /= 'a'
312                    and then
313                  Name_Buffer (1) /= 'g'
314                    and then
315                  Name_Buffer (1) /= 'i'
316                    and then
317                  Name_Buffer (1) /= 's')
318       then
319          return False;
320       end if;
321
322       --  Definitely OK if file name does not end in .ads. This can
323       --  happen when non-standard file names are being used.
324
325       if Name_Buffer (Name_Len - 3 .. Name_Len) /= ".ads" then
326          return False;
327       end if;
328
329       --  Otherwise normalize file name to 8 characters
330
331       Name_Len := Name_Len - 4;
332       while Name_Len < 8 loop
333          Name_Len := Name_Len + 1;
334          Name_Buffer (Name_Len) := ' ';
335       end loop;
336
337       --  Definitely OK if name is in list
338
339       for J in Non_Imp_File_Names'Range loop
340          if Name_Buffer (1 .. 8) = Non_Imp_File_Names (J) then
341             return False;
342          end if;
343       end loop;
344
345       --  Only remaining special possibilities are children of
346       --  System.RPC and System.Garlic and special files of the
347       --  form System.Aux...
348
349       Get_Name_String (Unit_Name (U));
350
351       if Name_Len > 12
352         and then Name_Buffer (1 .. 11) = "system.rpc."
353       then
354          return False;
355       end if;
356
357       if Name_Len > 15
358         and then Name_Buffer (1 .. 14) = "system.garlic."
359       then
360          return False;
361       end if;
362
363       if Name_Len > 11
364         and then Name_Buffer (1 .. 10) = "system.aux"
365       then
366          return False;
367       end if;
368
369       --  All tests failed, this is definitely an implementation unit
370
371       return True;
372
373    end Implementation_Unit;
374
375 end Impunit;