Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / casing.adb
blob589cc52b15687c7f6bf8acd751dce1c444a5bfcb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- C A S I N G --
6 -- --
7 -- B o d y --
8 -- --
9 -- --
10 -- Copyright (C) 1992-2001 Free Software Foundation, Inc. --
11 -- --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
22 -- --
23 -- As a special exception, if other files instantiate generics from this --
24 -- unit, or you link this unit with other files to produce an executable, --
25 -- this unit does not by itself cause the resulting executable to be --
26 -- covered by the GNU General Public License. This exception does not --
27 -- however invalidate any other reasons why the executable file might be --
28 -- covered by the GNU Public License. --
29 -- --
30 -- GNAT was originally developed by the GNAT team at New York University. --
31 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 -- --
33 ------------------------------------------------------------------------------
35 with Csets; use Csets;
36 with Namet; use Namet;
37 with Opt; use Opt;
38 with Types; use Types;
39 with Widechar; use Widechar;
41 package body Casing is
43 ----------------------
44 -- Determine_Casing --
45 ----------------------
47 function Determine_Casing (Ident : Text_Buffer) return Casing_Type is
49 All_Lower : Boolean := True;
50 -- Set False if upper case letter found
52 All_Upper : Boolean := True;
53 -- Set False if lower case letter found
55 Mixed : Boolean := True;
56 -- Set False if exception to mixed case rule found (lower case letter
57 -- at start or after underline, or upper case letter elsewhere).
59 Decisive : Boolean := False;
60 -- Set True if at least one instance of letter not after underline
62 After_Und : Boolean := True;
63 -- True at start of string, and after an underline character
65 begin
66 for S in Ident'Range loop
67 if Ident (S) = '_' or else Ident (S) = '.' then
68 After_Und := True;
70 elsif Is_Lower_Case_Letter (Ident (S)) then
71 All_Upper := False;
73 if not After_Und then
74 Decisive := True;
75 else
76 After_Und := False;
77 Mixed := False;
78 end if;
80 elsif Is_Upper_Case_Letter (Ident (S)) then
81 All_Lower := False;
83 if not After_Und then
84 Decisive := True;
85 Mixed := False;
86 else
87 After_Und := False;
88 end if;
89 end if;
90 end loop;
92 -- Now we can figure out the result from the flags we set in that loop
94 if All_Lower then
95 return All_Lower_Case;
97 elsif not Decisive then
98 return Unknown;
100 elsif All_Upper then
101 return All_Upper_Case;
103 elsif Mixed then
104 return Mixed_Case;
106 else
107 return Unknown;
108 end if;
109 end Determine_Casing;
111 ------------------------
112 -- Set_All_Upper_Case --
113 ------------------------
115 procedure Set_All_Upper_Case is
116 begin
117 Set_Casing (All_Upper_Case);
118 end Set_All_Upper_Case;
120 ----------------
121 -- Set_Casing --
122 ----------------
124 procedure Set_Casing (C : Casing_Type; D : Casing_Type := Mixed_Case) is
125 Ptr : Natural;
127 Actual_Casing : Casing_Type;
128 -- Set from C or D as appropriate
130 After_Und : Boolean := True;
131 -- True at start of string, and after an underline character or after
132 -- any other special character that is not a normal identifier char).
134 begin
135 if C /= Unknown then
136 Actual_Casing := C;
137 else
138 Actual_Casing := D;
139 end if;
141 Ptr := 1;
143 while Ptr <= Name_Len loop
144 if Name_Buffer (Ptr) = ASCII.ESC
145 or else Name_Buffer (Ptr) = '['
146 or else (Upper_Half_Encoding
147 and then Name_Buffer (Ptr) in Upper_Half_Character)
148 then
149 Skip_Wide (Name_Buffer, Ptr);
150 After_Und := False;
152 elsif Name_Buffer (Ptr) = '_'
153 or else not Identifier_Char (Name_Buffer (Ptr))
154 then
155 After_Und := True;
156 Ptr := Ptr + 1;
158 elsif Is_Lower_Case_Letter (Name_Buffer (Ptr)) then
159 if Actual_Casing = All_Upper_Case
160 or else (After_Und and then Actual_Casing = Mixed_Case)
161 then
162 Name_Buffer (Ptr) := Fold_Upper (Name_Buffer (Ptr));
163 end if;
165 After_Und := False;
166 Ptr := Ptr + 1;
168 elsif Is_Upper_Case_Letter (Name_Buffer (Ptr)) then
169 if Actual_Casing = All_Lower_Case
170 or else (not After_Und and then Actual_Casing = Mixed_Case)
171 then
172 Name_Buffer (Ptr) := Fold_Lower (Name_Buffer (Ptr));
173 end if;
175 After_Und := False;
176 Ptr := Ptr + 1;
178 else -- all other characters
179 After_Und := False;
180 Ptr := Ptr + 1;
181 end if;
182 end loop;
183 end Set_Casing;
185 end Casing;