* configure.ac: Don't test for [build] __cxa_atexit when building a
[official-gcc.git] / gcc / ada / stylesw.adb
blob8c2aa58d08ebd15629420314ffeaa6cf86cb83eb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S T Y L E S W --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2004, 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 ------------------------------------------------------------------------------
27 with Opt; use Opt;
29 package body Stylesw is
31 -------------------------------
32 -- Reset_Style_Check_Options --
33 -------------------------------
35 procedure Reset_Style_Check_Options is
36 begin
37 Style_Check_Indentation := 0;
38 Style_Check_Attribute_Casing := False;
39 Style_Check_Blanks_At_End := False;
40 Style_Check_Comments := False;
41 Style_Check_End_Labels := False;
42 Style_Check_Form_Feeds := False;
43 Style_Check_Horizontal_Tabs := False;
44 Style_Check_If_Then_Layout := False;
45 Style_Check_Keyword_Casing := False;
46 Style_Check_Layout := False;
47 Style_Check_Max_Line_Length := False;
48 Style_Check_Max_Nesting_Level := False;
49 Style_Check_Pragma_Casing := False;
50 Style_Check_References := False;
51 Style_Check_Specs := False;
52 Style_Check_Standard := False;
53 Style_Check_Subprogram_Order := False;
54 Style_Check_Tokens := False;
55 end Reset_Style_Check_Options;
57 ------------------------------
58 -- Save_Style_Check_Options --
59 ------------------------------
61 procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
62 P : Natural := 0;
64 procedure Add (C : Character; S : Boolean);
65 -- Add given character C to string if switch S is true
67 procedure Add_Nat (N : Nat);
68 -- Add given natural number to string
70 ---------
71 -- Add --
72 ---------
74 procedure Add (C : Character; S : Boolean) is
75 begin
76 if S then
77 P := P + 1;
78 Options (P) := C;
79 end if;
80 end Add;
82 -------------
83 -- Add_Nat --
84 -------------
86 procedure Add_Nat (N : Nat) is
87 begin
88 if N > 9 then
89 Add_Nat (N / 10);
90 end if;
92 P := P + 1;
93 Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
94 end Add_Nat;
96 -- Start of processing for Save_Style_Check_Options
98 begin
99 for K in Options'Range loop
100 Options (K) := ' ';
101 end loop;
103 Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
104 Style_Check_Indentation /= 0);
106 Add ('a', Style_Check_Attribute_Casing);
107 Add ('b', Style_Check_Blanks_At_End);
108 Add ('c', Style_Check_Comments);
109 Add ('e', Style_Check_End_Labels);
110 Add ('f', Style_Check_Form_Feeds);
111 Add ('h', Style_Check_Horizontal_Tabs);
112 Add ('i', Style_Check_If_Then_Layout);
113 Add ('k', Style_Check_Keyword_Casing);
114 Add ('l', Style_Check_Layout);
115 Add ('n', Style_Check_Standard);
116 Add ('o', Style_Check_Subprogram_Order);
117 Add ('p', Style_Check_Pragma_Casing);
118 Add ('r', Style_Check_References);
119 Add ('s', Style_Check_Specs);
120 Add ('t', Style_Check_Tokens);
122 if Style_Check_Max_Line_Length then
123 P := P + 1;
124 Options (P) := 'M';
125 Add_Nat (Style_Max_Line_Length);
126 end if;
128 if Style_Check_Max_Nesting_Level then
129 P := P + 1;
130 Options (P) := 'L';
131 Add_Nat (Style_Max_Nesting_Level);
132 end if;
134 pragma Assert (P <= Options'Last);
136 while P < Options'Last loop
137 P := P + 1;
138 Options (P) := ' ';
139 end loop;
140 end Save_Style_Check_Options;
142 -------------------------------------
143 -- Set_Default_Style_Check_Options --
144 -------------------------------------
146 procedure Set_Default_Style_Check_Options is
147 begin
148 Reset_Style_Check_Options;
149 Set_Style_Check_Options ("3abcefhiklmnprst");
150 end Set_Default_Style_Check_Options;
152 -----------------------------
153 -- Set_Style_Check_Options --
154 -----------------------------
156 -- Version used when no error checking is required
158 procedure Set_Style_Check_Options (Options : String) is
159 OK : Boolean;
160 EC : Natural;
161 begin
162 Set_Style_Check_Options (Options, OK, EC);
163 end Set_Style_Check_Options;
165 -- Normal version with error checking
167 procedure Set_Style_Check_Options
168 (Options : String;
169 OK : out Boolean;
170 Err_Col : out Natural)
172 J : Natural;
173 C : Character;
175 begin
176 J := Options'First;
177 while J <= Options'Last loop
178 C := Options (J);
179 J := J + 1;
181 case C is
182 when '1' .. '9' =>
183 Style_Check_Indentation
184 := Character'Pos (C) - Character'Pos ('0');
186 when 'a' =>
187 Style_Check_Attribute_Casing := True;
189 when 'b' =>
190 Style_Check_Blanks_At_End := True;
192 when 'c' =>
193 Style_Check_Comments := True;
195 when 'e' =>
196 Style_Check_End_Labels := True;
198 when 'f' =>
199 Style_Check_Form_Feeds := True;
201 when 'h' =>
202 Style_Check_Horizontal_Tabs := True;
204 when 'i' =>
205 Style_Check_If_Then_Layout := True;
207 when 'k' =>
208 Style_Check_Keyword_Casing := True;
210 when 'l' =>
211 Style_Check_Layout := True;
213 when 'L' =>
214 Style_Max_Nesting_Level := 0;
216 if J > Options'Last
217 or else Options (J) not in '0' .. '9'
218 then
219 OK := False;
220 Err_Col := J;
221 return;
222 end if;
224 loop
225 Style_Max_Nesting_Level :=
226 Style_Max_Nesting_Level * 10 +
227 Character'Pos (Options (J)) - Character'Pos ('0');
229 if Style_Max_Nesting_Level > 999 then
230 OK := False;
231 Err_Col := J;
232 return;
233 end if;
235 J := J + 1;
236 exit when J > Options'Last
237 or else Options (J) not in '0' .. '9';
238 end loop;
240 Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
242 when 'm' =>
243 Style_Check_Max_Line_Length := True;
244 Style_Max_Line_Length := 79;
246 when 'n' =>
247 Style_Check_Standard := True;
249 when 'N' =>
250 Reset_Style_Check_Options;
252 when 'M' =>
253 Style_Max_Line_Length := 0;
255 if J > Options'Last
256 or else Options (J) not in '0' .. '9'
257 then
258 OK := False;
259 Err_Col := J;
260 return;
261 end if;
263 loop
264 Style_Max_Line_Length :=
265 Style_Max_Line_Length * 10 +
266 Character'Pos (Options (J)) - Character'Pos ('0');
268 if Style_Max_Line_Length > Int (Column_Number'Last) then
269 OK := False;
270 Err_Col := J;
271 return;
272 end if;
274 J := J + 1;
275 exit when J > Options'Last
276 or else Options (J) not in '0' .. '9';
277 end loop;
279 Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
281 when 'o' =>
282 Style_Check_Subprogram_Order := True;
284 when 'p' =>
285 Style_Check_Pragma_Casing := True;
287 when 'r' =>
288 Style_Check_References := True;
290 when 's' =>
291 Style_Check_Specs := True;
293 when 't' =>
294 Style_Check_Tokens := True;
296 when ' ' =>
297 null;
299 when others =>
300 OK := False;
301 Err_Col := J - 1;
302 return;
303 end case;
304 end loop;
306 Style_Check := True;
307 OK := True;
308 Err_Col := Options'Last + 1;
309 end Set_Style_Check_Options;
311 end Stylesw;