PR other/22202
[official-gcc.git] / gcc / ada / stylesw.adb
blob27e9153c9c68e12caffad97932194cf105380dbb
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-2005, 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, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, 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_Blank_Lines := False;
41 Style_Check_Comments := False;
42 Style_Check_DOS_Line_Terminator := False;
43 Style_Check_End_Labels := False;
44 Style_Check_Form_Feeds := False;
45 Style_Check_Horizontal_Tabs := False;
46 Style_Check_If_Then_Layout := False;
47 Style_Check_Keyword_Casing := False;
48 Style_Check_Layout := False;
49 Style_Check_Max_Line_Length := False;
50 Style_Check_Max_Nesting_Level := False;
51 Style_Check_Order_Subprograms := False;
52 Style_Check_Pragma_Casing := False;
53 Style_Check_References := False;
54 Style_Check_Specs := False;
55 Style_Check_Standard := False;
56 Style_Check_Tokens := False;
57 Style_Check_Xtra_Parens := False;
58 end Reset_Style_Check_Options;
60 ------------------------------
61 -- Save_Style_Check_Options --
62 ------------------------------
64 procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
65 P : Natural := 0;
67 procedure Add (C : Character; S : Boolean);
68 -- Add given character C to string if switch S is true
70 procedure Add_Nat (N : Nat);
71 -- Add given natural number to string
73 ---------
74 -- Add --
75 ---------
77 procedure Add (C : Character; S : Boolean) is
78 begin
79 if S then
80 P := P + 1;
81 Options (P) := C;
82 end if;
83 end Add;
85 -------------
86 -- Add_Nat --
87 -------------
89 procedure Add_Nat (N : Nat) is
90 begin
91 if N > 9 then
92 Add_Nat (N / 10);
93 end if;
95 P := P + 1;
96 Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
97 end Add_Nat;
99 -- Start of processing for Save_Style_Check_Options
101 begin
102 for K in Options'Range loop
103 Options (K) := ' ';
104 end loop;
106 Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
107 Style_Check_Indentation /= 0);
109 Add ('a', Style_Check_Attribute_Casing);
110 Add ('b', Style_Check_Blanks_At_End);
111 Add ('c', Style_Check_Comments);
112 Add ('d', Style_Check_DOS_Line_Terminator);
113 Add ('e', Style_Check_End_Labels);
114 Add ('f', Style_Check_Form_Feeds);
115 Add ('h', Style_Check_Horizontal_Tabs);
116 Add ('i', Style_Check_If_Then_Layout);
117 Add ('k', Style_Check_Keyword_Casing);
118 Add ('l', Style_Check_Layout);
119 Add ('n', Style_Check_Standard);
120 Add ('o', Style_Check_Order_Subprograms);
121 Add ('p', Style_Check_Pragma_Casing);
122 Add ('r', Style_Check_References);
123 Add ('s', Style_Check_Specs);
124 Add ('t', Style_Check_Tokens);
125 Add ('u', Style_Check_Blank_Lines);
126 Add ('x', Style_Check_Xtra_Parens);
128 if Style_Check_Max_Line_Length then
129 P := P + 1;
130 Options (P) := 'M';
131 Add_Nat (Style_Max_Line_Length);
132 end if;
134 if Style_Check_Max_Nesting_Level then
135 P := P + 1;
136 Options (P) := 'L';
137 Add_Nat (Style_Max_Nesting_Level);
138 end if;
140 pragma Assert (P <= Options'Last);
142 while P < Options'Last loop
143 P := P + 1;
144 Options (P) := ' ';
145 end loop;
146 end Save_Style_Check_Options;
148 -------------------------------------
149 -- Set_Default_Style_Check_Options --
150 -------------------------------------
152 procedure Set_Default_Style_Check_Options is
153 begin
154 Reset_Style_Check_Options;
155 Set_Style_Check_Options ("3abcefhiklmnprst");
156 end Set_Default_Style_Check_Options;
158 -----------------------------
159 -- Set_Style_Check_Options --
160 -----------------------------
162 -- Version used when no error checking is required
164 procedure Set_Style_Check_Options (Options : String) is
165 OK : Boolean;
166 EC : Natural;
167 begin
168 Set_Style_Check_Options (Options, OK, EC);
169 end Set_Style_Check_Options;
171 -- Normal version with error checking
173 procedure Set_Style_Check_Options
174 (Options : String;
175 OK : out Boolean;
176 Err_Col : out Natural)
178 J : Natural;
179 C : Character;
181 begin
182 J := Options'First;
183 while J <= Options'Last loop
184 C := Options (J);
185 J := J + 1;
187 case C is
188 when '1' .. '9' =>
189 Style_Check_Indentation
190 := Character'Pos (C) - Character'Pos ('0');
192 when 'a' =>
193 Style_Check_Attribute_Casing := True;
195 when 'b' =>
196 Style_Check_Blanks_At_End := True;
198 when 'c' =>
199 Style_Check_Comments := True;
201 when 'd' =>
202 Style_Check_DOS_Line_Terminator := True;
204 when 'e' =>
205 Style_Check_End_Labels := True;
207 when 'f' =>
208 Style_Check_Form_Feeds := True;
210 when 'h' =>
211 Style_Check_Horizontal_Tabs := True;
213 when 'i' =>
214 Style_Check_If_Then_Layout := True;
216 when 'k' =>
217 Style_Check_Keyword_Casing := True;
219 when 'l' =>
220 Style_Check_Layout := True;
222 when 'L' =>
223 Style_Max_Nesting_Level := 0;
225 if J > Options'Last
226 or else Options (J) not in '0' .. '9'
227 then
228 OK := False;
229 Err_Col := J;
230 return;
231 end if;
233 loop
234 Style_Max_Nesting_Level :=
235 Style_Max_Nesting_Level * 10 +
236 Character'Pos (Options (J)) - Character'Pos ('0');
238 if Style_Max_Nesting_Level > 999 then
239 OK := False;
240 Err_Col := J;
241 return;
242 end if;
244 J := J + 1;
245 exit when J > Options'Last
246 or else Options (J) not in '0' .. '9';
247 end loop;
249 Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
251 when 'm' =>
252 Style_Check_Max_Line_Length := True;
253 Style_Max_Line_Length := 79;
255 when 'n' =>
256 Style_Check_Standard := True;
258 when 'N' =>
259 Reset_Style_Check_Options;
261 when 'M' =>
262 Style_Max_Line_Length := 0;
264 if J > Options'Last
265 or else Options (J) not in '0' .. '9'
266 then
267 OK := False;
268 Err_Col := J;
269 return;
270 end if;
272 loop
273 Style_Max_Line_Length :=
274 Style_Max_Line_Length * 10 +
275 Character'Pos (Options (J)) - Character'Pos ('0');
277 if Style_Max_Line_Length > Int (Column_Number'Last) then
278 OK := False;
279 Err_Col := J;
280 return;
281 end if;
283 J := J + 1;
284 exit when J > Options'Last
285 or else Options (J) not in '0' .. '9';
286 end loop;
288 Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
290 when 'o' =>
291 Style_Check_Order_Subprograms := True;
293 when 'p' =>
294 Style_Check_Pragma_Casing := True;
296 when 'r' =>
297 Style_Check_References := True;
299 when 's' =>
300 Style_Check_Specs := True;
302 when 't' =>
303 Style_Check_Tokens := True;
305 when 'u' =>
306 Style_Check_Blank_Lines := True;
308 when 'x' =>
309 Style_Check_Xtra_Parens := True;
311 when ' ' =>
312 null;
314 when others =>
315 OK := False;
316 Err_Col := J - 1;
317 return;
318 end case;
319 end loop;
321 Style_Check := True;
322 OK := True;
323 Err_Col := Options'Last + 1;
324 end Set_Style_Check_Options;
326 end Stylesw;