1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005 Free Software Foundation, Inc. --
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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 with Csets
; use Csets
;
35 with Namet
; use Namet
;
37 with Widechar
; use Widechar
;
39 package body Casing
is
41 ----------------------
42 -- Determine_Casing --
43 ----------------------
45 function Determine_Casing
(Ident
: Text_Buffer
) return Casing_Type
is
47 All_Lower
: Boolean := True;
48 -- Set False if upper case letter found
50 All_Upper
: Boolean := True;
51 -- Set False if lower case letter found
53 Mixed
: Boolean := True;
54 -- Set False if exception to mixed case rule found (lower case letter
55 -- at start or after underline, or upper case letter elsewhere).
57 Decisive
: Boolean := False;
58 -- Set True if at least one instance of letter not after underline
60 After_Und
: Boolean := True;
61 -- True at start of string, and after an underline character
64 for S
in Ident
'Range loop
65 if Ident
(S
) = '_' or else Ident
(S
) = '.' then
68 elsif Is_Lower_Case_Letter
(Ident
(S
)) then
78 elsif Is_Upper_Case_Letter
(Ident
(S
)) then
90 -- Now we can figure out the result from the flags we set in that loop
93 return All_Lower_Case
;
95 elsif not Decisive
then
99 return All_Upper_Case
;
107 end Determine_Casing
;
109 ------------------------
110 -- Set_All_Upper_Case --
111 ------------------------
113 procedure Set_All_Upper_Case
is
115 Set_Casing
(All_Upper_Case
);
116 end Set_All_Upper_Case
;
122 procedure Set_Casing
(C
: Casing_Type
; D
: Casing_Type
:= Mixed_Case
) is
125 Actual_Casing
: Casing_Type
;
126 -- Set from C or D as appropriate
128 After_Und
: Boolean := True;
129 -- True at start of string, and after an underline character or after
130 -- any other special character that is not a normal identifier char).
141 while Ptr
<= Name_Len
loop
143 -- Wide character. Note that we do nothing with casing in this case.
144 -- In Ada 2005 mode, required folding of lower case letters happened
145 -- as the identifier was scanned, and we do not attempt any further
146 -- messing with case (note that in any case we do not know how to
147 -- fold upper case to lower case in wide character mode). We also
148 -- do not bother with recognizing punctuation as equivalent to an
149 -- underscore. There is nothing functional at this stage in doing
150 -- the requested casing operation, beyond folding to upper case
151 -- when it is mandatory, which does not involve underscores.
153 if Name_Buffer
(Ptr
) = ASCII
.ESC
154 or else Name_Buffer
(Ptr
) = '['
155 or else (Upper_Half_Encoding
156 and then Name_Buffer
(Ptr
) in Upper_Half_Character
)
158 Skip_Wide
(Name_Buffer
, Ptr
);
161 -- Underscore, or non-identifer character (error case)
163 elsif Name_Buffer
(Ptr
) = '_'
164 or else not Identifier_Char
(Name_Buffer
(Ptr
))
171 elsif Is_Lower_Case_Letter
(Name_Buffer
(Ptr
)) then
172 if Actual_Casing
= All_Upper_Case
173 or else (After_Und
and then Actual_Casing
= Mixed_Case
)
175 Name_Buffer
(Ptr
) := Fold_Upper
(Name_Buffer
(Ptr
));
183 elsif Is_Upper_Case_Letter
(Name_Buffer
(Ptr
)) then
184 if Actual_Casing
= All_Lower_Case
185 or else (not After_Und
and then Actual_Casing
= Mixed_Case
)
187 Name_Buffer
(Ptr
) := Fold_Lower
(Name_Buffer
(Ptr
));
193 -- Other identifier character (must be digit)