annotate gcc/ada/libgnat/s-wchcon.ads @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 ------------------------------------------------------------------------------
kono
parents:
diff changeset
2 -- --
kono
parents:
diff changeset
3 -- GNAT COMPILER COMPONENTS --
kono
parents:
diff changeset
4 -- --
kono
parents:
diff changeset
5 -- S Y S T E M . W C H _ C O N --
kono
parents:
diff changeset
6 -- --
kono
parents:
diff changeset
7 -- S p e c --
kono
parents:
diff changeset
8 -- --
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
111
kono
parents:
diff changeset
10 -- --
kono
parents:
diff changeset
11 -- GNAT is free software; you can redistribute it and/or modify it under --
kono
parents:
diff changeset
12 -- terms of the GNU General Public License as published by the Free Soft- --
kono
parents:
diff changeset
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
kono
parents:
diff changeset
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
kono
parents:
diff changeset
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
kono
parents:
diff changeset
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
kono
parents:
diff changeset
17 -- --
kono
parents:
diff changeset
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
kono
parents:
diff changeset
19 -- additional permissions described in the GCC Runtime Library Exception, --
kono
parents:
diff changeset
20 -- version 3.1, as published by the Free Software Foundation. --
kono
parents:
diff changeset
21 -- --
kono
parents:
diff changeset
22 -- You should have received a copy of the GNU General Public License and --
kono
parents:
diff changeset
23 -- a copy of the GCC Runtime Library Exception along with this program; --
kono
parents:
diff changeset
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
kono
parents:
diff changeset
25 -- <http://www.gnu.org/licenses/>. --
kono
parents:
diff changeset
26 -- --
kono
parents:
diff changeset
27 -- GNAT was originally developed by the GNAT team at New York University. --
kono
parents:
diff changeset
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
kono
parents:
diff changeset
29 -- --
kono
parents:
diff changeset
30 ------------------------------------------------------------------------------
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 -- This package defines the codes used to identify the encoding method for
kono
parents:
diff changeset
33 -- wide characters in string and character constants. This is needed both
kono
parents:
diff changeset
34 -- at compile time and at runtime (for the wide character runtime routines)
kono
parents:
diff changeset
35
kono
parents:
diff changeset
36 -- This unit may be used directly from an application program by providing
kono
parents:
diff changeset
37 -- an appropriate WITH, and the interface can be expected to remain stable.
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 pragma Compiler_Unit_Warning;
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 package System.WCh_Con is
kono
parents:
diff changeset
42 pragma Pure;
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 -------------------------------------
kono
parents:
diff changeset
45 -- Wide_Character Encoding Methods --
kono
parents:
diff changeset
46 -------------------------------------
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 -- A wide character encoding method is a method for uniquely representing
kono
parents:
diff changeset
49 -- a Wide_Character or Wide_Wide_Character value using a one or more
kono
parents:
diff changeset
50 -- Character values. Three types of encoding method are supported by GNAT:
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 -- An escape encoding method uses ESC as the first character of the
kono
parents:
diff changeset
53 -- sequence, and subsequent characters determine the wide character
kono
parents:
diff changeset
54 -- value that is represented. Any character other than ESC stands
kono
parents:
diff changeset
55 -- for itself as a single byte (i.e. any character in Latin-1, other
kono
parents:
diff changeset
56 -- than ESC itself, is represented as a single character: itself).
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 -- An upper half encoding method uses a character in the upper half
kono
parents:
diff changeset
59 -- range (i.e. in the range 16#80# .. 16#FF#) as the first byte of
kono
parents:
diff changeset
60 -- a wide character encoding sequence. Subsequent characters are
kono
parents:
diff changeset
61 -- used to determine the wide character value that is represented.
kono
parents:
diff changeset
62 -- Any character in the lower half (16#00# .. 16#7F#) represents
kono
parents:
diff changeset
63 -- itself as a single character.
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 -- The brackets notation, where a wide character is represented by the
kono
parents:
diff changeset
66 -- sequence ["xx"] or ["xxxx"] or ["xxxxxx"] where xx are hexadecimal
kono
parents:
diff changeset
67 -- characters. Note that currently this is the only encoding that
kono
parents:
diff changeset
68 -- supports the full UTF-32 range.
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 -- Note that GNAT does not currently support escape-in, escape-out
kono
parents:
diff changeset
71 -- encoding methods, where an escape sequence is used to set a mode
kono
parents:
diff changeset
72 -- used to recognize subsequent characters. All encoding methods use
kono
parents:
diff changeset
73 -- individual character-by-character encodings, so that a sequence of
kono
parents:
diff changeset
74 -- wide characters is represented by a sequence of encodings.
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 -- To add new encoding methods, the following steps are required:
kono
parents:
diff changeset
77
kono
parents:
diff changeset
78 -- 1. Define a code for a new value of type WC_Encoding_Method
kono
parents:
diff changeset
79 -- 2. Adjust the definition of WC_Encoding_Method accordingly
kono
parents:
diff changeset
80 -- 3. Provide appropriate conversion routines in System.WCh_Cnv
kono
parents:
diff changeset
81 -- 4. Adjust definition of WC_Longest_Sequence if necessary
kono
parents:
diff changeset
82 -- 5. Add an entry in WC_Encoding_Letters for the new method
kono
parents:
diff changeset
83 -- 6. Add proper code to s-wchstw.adb, s-wchwts.adb, s-widwch.adb
kono
parents:
diff changeset
84 -- 7. Update documentation (remember section on form strings)
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 -- Note that the WC_Encoding_Method values must be kept ordered so that
kono
parents:
diff changeset
87 -- the definitions of the subtypes WC_Upper_Half_Encoding_Method and
kono
parents:
diff changeset
88 -- WC_ESC_Encoding_Method are still correct.
kono
parents:
diff changeset
89
kono
parents:
diff changeset
90 ---------------------------------
kono
parents:
diff changeset
91 -- Encoding Method Definitions --
kono
parents:
diff changeset
92 ---------------------------------
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 type WC_Encoding_Method is range 1 .. 6;
kono
parents:
diff changeset
95 -- Type covering the range of values used to represent wide character
kono
parents:
diff changeset
96 -- encoding methods. An enumeration type might be a little neater, but
kono
parents:
diff changeset
97 -- more trouble than it's worth, given the need to pass these values
kono
parents:
diff changeset
98 -- from the compiler to the backend, and to record them in the ALI file.
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 WCEM_Hex : constant WC_Encoding_Method := 1;
kono
parents:
diff changeset
101 -- The wide character with code 16#abcd# is represented by the escape
kono
parents:
diff changeset
102 -- sequence ESC a b c d (five characters, where abcd are ASCII hex
kono
parents:
diff changeset
103 -- characters, using upper case for letters). This method is easy
kono
parents:
diff changeset
104 -- to deal with in external environments that do not support wide
kono
parents:
diff changeset
105 -- characters, and covers the whole 16-bit BMP. Codes larger than
kono
parents:
diff changeset
106 -- 16#FFFF# are not representable using this encoding method.
kono
parents:
diff changeset
107
kono
parents:
diff changeset
108 WCEM_Upper : constant WC_Encoding_Method := 2;
kono
parents:
diff changeset
109 -- The wide character with encoding 16#abcd#, where the upper bit is on
kono
parents:
diff changeset
110 -- (i.e. a is in the range 8-F) is represented as two bytes 16#ab# and
kono
parents:
diff changeset
111 -- 16#cd#. The second byte may never be a format control character, but
kono
parents:
diff changeset
112 -- is not required to be in the upper half. This method can be also used
kono
parents:
diff changeset
113 -- for shift-JIS or EUC where the internal coding matches the external
kono
parents:
diff changeset
114 -- coding. Codes larger than 16#FFFF# are not representable using this
kono
parents:
diff changeset
115 -- encoding method.
kono
parents:
diff changeset
116
kono
parents:
diff changeset
117 WCEM_Shift_JIS : constant WC_Encoding_Method := 3;
kono
parents:
diff changeset
118 -- A wide character is represented by a two character sequence 16#ab#
kono
parents:
diff changeset
119 -- and 16#cd#, with the restrictions described for upper half encoding
kono
parents:
diff changeset
120 -- as described above. The internal character code is the corresponding
kono
parents:
diff changeset
121 -- JIS character according to the standard algorithm for Shift-JIS
kono
parents:
diff changeset
122 -- conversion. See the body of package System.JIS_Conversions for
kono
parents:
diff changeset
123 -- further details. Codes larger than 16#FFFF are not representable
kono
parents:
diff changeset
124 -- using this encoding method.
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 WCEM_EUC : constant WC_Encoding_Method := 4;
kono
parents:
diff changeset
127 -- A wide character is represented by a two character sequence 16#ab# and
kono
parents:
diff changeset
128 -- 16#cd#, with both characters being in the upper half set. The internal
kono
parents:
diff changeset
129 -- character code is the corresponding JIS character according to the EUC
kono
parents:
diff changeset
130 -- encoding algorithm. See the body of package System.JIS_Conversions for
kono
parents:
diff changeset
131 -- further details. Codes larger than 16#FFFF# are not representable using
kono
parents:
diff changeset
132 -- this encoding method.
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 WCEM_UTF8 : constant WC_Encoding_Method := 5;
kono
parents:
diff changeset
135 -- An ISO 10646-1 BMP/Unicode wide character is represented in UCS
kono
parents:
diff changeset
136 -- Transformation Format 8 (UTF-8), as defined in Annex R of ISO
kono
parents:
diff changeset
137 -- 10646-1/Am.2. Depending on the character value, a Unicode character
kono
parents:
diff changeset
138 -- is represented as the one to six byte sequence.
kono
parents:
diff changeset
139 --
kono
parents:
diff changeset
140 -- 16#0000_0000#-16#0000_007f#: 2#0xxxxxxx#
kono
parents:
diff changeset
141 -- 16#0000_0080#-16#0000_07ff#: 2#110xxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
142 -- 16#0000_0800#-16#0000_ffff#: 2#1110xxxx# 2#10xxxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
143 -- 16#0001_0000#-16#001F_FFFF#: 2#11110xxx# 2#10xxxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
144 -- 2#10xxxxxx#
kono
parents:
diff changeset
145 -- 16#0020_0000#-16#03FF_FFFF#: 2#111110xx# 2#10xxxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
146 -- 2#10xxxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
147 -- 16#0400_0000#-16#7FFF_FFFF#: 2#1111110x# 2#10xxxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
148 -- 2#10xxxxxx# 2#10xxxxxx# 2#10xxxxxx#
kono
parents:
diff changeset
149 --
kono
parents:
diff changeset
150 -- where the xxx bits correspond to the left-padded bits of the
kono
parents:
diff changeset
151 -- 16-bit character value. Note that all lower half ASCII characters
kono
parents:
diff changeset
152 -- are represented as ASCII bytes and all upper half characters and
kono
parents:
diff changeset
153 -- other wide characters are represented as sequences of upper-half. This
kono
parents:
diff changeset
154 -- encoding method can represent the entire range of Wide_Wide_Character.
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 WCEM_Brackets : constant WC_Encoding_Method := 6;
kono
parents:
diff changeset
157 -- A wide character is represented using one of the following sequences:
kono
parents:
diff changeset
158 --
kono
parents:
diff changeset
159 -- ["xx"]
kono
parents:
diff changeset
160 -- ["xxxx"]
kono
parents:
diff changeset
161 -- ["xxxxxx"]
kono
parents:
diff changeset
162 -- ["xxxxxxxx"]
kono
parents:
diff changeset
163 --
kono
parents:
diff changeset
164 -- where xx are hexadecimal digits representing the character code. This
kono
parents:
diff changeset
165 -- encoding method can represent the entire range of Wide_Wide_Character
kono
parents:
diff changeset
166 -- but in the general case results in ambiguous representations (there is
kono
parents:
diff changeset
167 -- no ambiguity in Ada sources, since the above sequences are illegal Ada).
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 WC_Encoding_Letters : constant array (WC_Encoding_Method) of Character :=
kono
parents:
diff changeset
170 (WCEM_Hex => 'h',
kono
parents:
diff changeset
171 WCEM_Upper => 'u',
kono
parents:
diff changeset
172 WCEM_Shift_JIS => 's',
kono
parents:
diff changeset
173 WCEM_EUC => 'e',
kono
parents:
diff changeset
174 WCEM_UTF8 => '8',
kono
parents:
diff changeset
175 WCEM_Brackets => 'b');
kono
parents:
diff changeset
176 -- Letters used for selection of wide character encoding method in the
kono
parents:
diff changeset
177 -- compiler options (-gnatW? switch) and for Wide_Text_IO (WCEM parameter
kono
parents:
diff changeset
178 -- in the form string).
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 subtype WC_ESC_Encoding_Method is
kono
parents:
diff changeset
181 WC_Encoding_Method range WCEM_Hex .. WCEM_Hex;
kono
parents:
diff changeset
182 -- Encoding methods using an ESC character at the start of the sequence
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 subtype WC_Upper_Half_Encoding_Method is
kono
parents:
diff changeset
185 WC_Encoding_Method range WCEM_Upper .. WCEM_UTF8;
kono
parents:
diff changeset
186 -- Encoding methods using an upper half character (16#80#..16#FF) at
kono
parents:
diff changeset
187 -- the start of the sequence.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 WC_Longest_Sequence : constant := 12;
kono
parents:
diff changeset
190 -- The longest number of characters that can be used for a wide character
kono
parents:
diff changeset
191 -- or wide wide character sequence for any of the active encoding methods.
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 WC_Longest_Sequences : constant array (WC_Encoding_Method) of Natural :=
kono
parents:
diff changeset
194 (WCEM_Hex => 5,
kono
parents:
diff changeset
195 WCEM_Upper => 2,
kono
parents:
diff changeset
196 WCEM_Shift_JIS => 2,
kono
parents:
diff changeset
197 WCEM_EUC => 2,
kono
parents:
diff changeset
198 WCEM_UTF8 => 6,
kono
parents:
diff changeset
199 WCEM_Brackets => 12);
kono
parents:
diff changeset
200 -- The longest number of characters that can be used for a wide character
kono
parents:
diff changeset
201 -- or wide wide character sequence using the given encoding method.
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 function Get_WC_Encoding_Method (C : Character) return WC_Encoding_Method;
kono
parents:
diff changeset
204 -- Given a character C, returns corresponding encoding method (see array
kono
parents:
diff changeset
205 -- WC_Encoding_Letters above). Raises Constraint_Error if not in list.
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 function Get_WC_Encoding_Method (S : String) return WC_Encoding_Method;
kono
parents:
diff changeset
208 -- Given a lower case string that is one of hex, upper, shift_jis, euc,
kono
parents:
diff changeset
209 -- utf8, brackets, return the corresponding encoding method. Raises
kono
parents:
diff changeset
210 -- Constraint_Error if not in list.
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 function Is_Start_Of_Encoding
kono
parents:
diff changeset
213 (C : Character;
kono
parents:
diff changeset
214 EM : WC_Encoding_Method) return Boolean;
kono
parents:
diff changeset
215 pragma Inline (Is_Start_Of_Encoding);
kono
parents:
diff changeset
216 -- Returns True if the Character C is the start of a multi-character
kono
parents:
diff changeset
217 -- encoding sequence for the given encoding method EM. If EM is set to
kono
parents:
diff changeset
218 -- WCEM_Brackets, this function always returns False.
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 end System.WCh_Con;