testsuite: 32 bit AIX 2 byte wchar
[official-gcc.git] / gcc / ada / krunch.ads
blob5e8f214080c46884c7c97c62effc8650213361e4
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- K R U N C H --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2023, 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 ------------------------------------------------------------------------------
26 -- This procedure implements file name crunching
28 -- First, the name is divided into segments separated by minus signs and
29 -- underscores, then all minus signs and underscores are eliminated. If
30 -- this leaves the name short enough, we are done.
32 -- If not, then the longest segment is located (left-most if there are
33 -- two of equal length), and shortened by dropping its last character.
34 -- This is repeated until the name is short enough.
36 -- As an example, consider the krunch of our-strings-wide_fixed.adb
37 -- to fit the name into 8 characters as required by DOS:
39 -- our-strings-wide_fixed 22
40 -- our strings wide fixed 19
41 -- our string wide fixed 18
42 -- our strin wide fixed 17
43 -- our stri wide fixed 16
44 -- our stri wide fixe 15
45 -- our str wide fixe 14
46 -- our str wid fixe 13
47 -- our str wid fix 12
48 -- ou str wid fix 11
49 -- ou st wid fix 10
50 -- ou st wi fix 9
51 -- ou st wi fi 8
53 -- Final file name: OUSTWIFX.ADB
55 -- A special rule applies for children of System, Ada, Gnat, and Interfaces.
56 -- In these cases, the following special prefix replacements occur:
58 -- ada- replaced by a-
59 -- gnat- replaced by g-
60 -- interfaces- replaced by i-
61 -- system- replaced by s-
63 -- The rest of the name is krunched in the usual manner described above.
64 -- In addition, these names, as well as the names of the renamed packages
65 -- from the obsolescent features annex, are always krunched to 8 characters
66 -- regardless of the setting of Maxlen.
68 -- As an example of this special rule, consider ada-strings-wide_fixed.adb
69 -- which gets krunched as follows:
71 -- ada-strings-wide_fixed 22
72 -- a- strings wide fixed 18
73 -- a- string wide fixed 17
74 -- a- strin wide fixed 16
75 -- a- stri wide fixed 15
76 -- a- stri wide fixe 14
77 -- a- str wide fixe 13
78 -- a- str wid fixe 12
79 -- a- str wid fix 11
80 -- a- st wid fix 10
81 -- a- st wi fix 9
82 -- a- st wi fi 8
84 -- Final file name: A-STWIFX.ADB
86 -- Since children of units named A, G, I or S might conflict with the names
87 -- of predefined units, the naming rule in that case is that the first hyphen
88 -- is replaced by a tilde sign.
90 -- Note: as described below, this special treatment of predefined library
91 -- unit file names can be inhibited by setting the No_Predef flag.
93 -- Of course there is no guarantee that this algorithm results in uniquely
94 -- crunched names (nor, obviously, is there any algorithm which would do so)
95 -- In fact we run into such a case in the standard library routines with
96 -- children of Wide_Text_IO, so a special rule is applied to deal with this
97 -- clash, namely the prefix ada-wide_text_io- is replaced by a-wt- and then
98 -- the normal crunching rules are applied, so that for example, the unit:
100 -- Ada.Wide_Text_IO.Float_IO
102 -- has the file name
104 -- a-wtflio
106 -- More problems arise with Wide_Wide, so we replace this sequence by
107 -- a z (which is not used much) and also (as in the Wide_Text_IO case),
108 -- we replace the prefix ada.wide_wide_text_io- by a-zt- and then
109 -- the normal crunching rules are applied.
111 -- An additional trick is used for Ada.Long_Long_Long_Integer_*_IO, where
112 -- the Integer word is dropped.
114 -- The units implementing the support of 128-bit types are crunched to 9 and
115 -- System.Compare_Array_* is replaced with System.CA_* before crunching.
117 -- These are the only irregularity required (so far) to keep the file names
118 -- unique in the standard predefined libraries.
120 procedure Krunch
121 (Buffer : in out String;
122 Len : in out Natural;
123 Maxlen : Natural;
124 No_Predef : Boolean);
125 pragma Elaborate_Body (Krunch);
126 -- The full file name is stored in Buffer (1 .. Len) on entry. The file
127 -- name is crunched in place and on return Len is updated, so that the
128 -- resulting krunched name is in Buffer (1 .. Len) where Len <= Maxlen.
129 -- Note that Len may be less than or equal to Maxlen on entry, in which
130 -- case it may be possible that Krunch does not modify Buffer. The fourth
131 -- parameter, No_Predef, is a switch which, if set to True, disables the
132 -- normal special treatment of predefined library unit file names.
134 -- Note: the string Buffer must have a lower bound of 1, and may not
135 -- contain any blanks (in particular, it must not have leading blanks).