* expr.c (gfc_copy_shape_excluding): Change && to ||.
[official-gcc.git] / gcc / ada / stylesw.adb
blob1b3ea5ff40cbe61b4634326198d3f5691cebd330
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_Order_Subprograms := False;
50 Style_Check_Pragma_Casing := False;
51 Style_Check_References := False;
52 Style_Check_Specs := False;
53 Style_Check_Standard := False;
54 Style_Check_Tokens := False;
55 Style_Check_Xtra_Parens := False;
56 end Reset_Style_Check_Options;
58 ------------------------------
59 -- Save_Style_Check_Options --
60 ------------------------------
62 procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
63 P : Natural := 0;
65 procedure Add (C : Character; S : Boolean);
66 -- Add given character C to string if switch S is true
68 procedure Add_Nat (N : Nat);
69 -- Add given natural number to string
71 ---------
72 -- Add --
73 ---------
75 procedure Add (C : Character; S : Boolean) is
76 begin
77 if S then
78 P := P + 1;
79 Options (P) := C;
80 end if;
81 end Add;
83 -------------
84 -- Add_Nat --
85 -------------
87 procedure Add_Nat (N : Nat) is
88 begin
89 if N > 9 then
90 Add_Nat (N / 10);
91 end if;
93 P := P + 1;
94 Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
95 end Add_Nat;
97 -- Start of processing for Save_Style_Check_Options
99 begin
100 for K in Options'Range loop
101 Options (K) := ' ';
102 end loop;
104 Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
105 Style_Check_Indentation /= 0);
107 Add ('a', Style_Check_Attribute_Casing);
108 Add ('b', Style_Check_Blanks_At_End);
109 Add ('c', Style_Check_Comments);
110 Add ('e', Style_Check_End_Labels);
111 Add ('f', Style_Check_Form_Feeds);
112 Add ('h', Style_Check_Horizontal_Tabs);
113 Add ('i', Style_Check_If_Then_Layout);
114 Add ('k', Style_Check_Keyword_Casing);
115 Add ('l', Style_Check_Layout);
116 Add ('n', Style_Check_Standard);
117 Add ('o', Style_Check_Order_Subprograms);
118 Add ('p', Style_Check_Pragma_Casing);
119 Add ('r', Style_Check_References);
120 Add ('s', Style_Check_Specs);
121 Add ('t', Style_Check_Tokens);
122 Add ('x', Style_Check_Xtra_Parens);
124 if Style_Check_Max_Line_Length then
125 P := P + 1;
126 Options (P) := 'M';
127 Add_Nat (Style_Max_Line_Length);
128 end if;
130 if Style_Check_Max_Nesting_Level then
131 P := P + 1;
132 Options (P) := 'L';
133 Add_Nat (Style_Max_Nesting_Level);
134 end if;
136 pragma Assert (P <= Options'Last);
138 while P < Options'Last loop
139 P := P + 1;
140 Options (P) := ' ';
141 end loop;
142 end Save_Style_Check_Options;
144 -------------------------------------
145 -- Set_Default_Style_Check_Options --
146 -------------------------------------
148 procedure Set_Default_Style_Check_Options is
149 begin
150 Reset_Style_Check_Options;
151 Set_Style_Check_Options ("3abcefhiklmnprst");
152 end Set_Default_Style_Check_Options;
154 -----------------------------
155 -- Set_Style_Check_Options --
156 -----------------------------
158 -- Version used when no error checking is required
160 procedure Set_Style_Check_Options (Options : String) is
161 OK : Boolean;
162 EC : Natural;
163 begin
164 Set_Style_Check_Options (Options, OK, EC);
165 end Set_Style_Check_Options;
167 -- Normal version with error checking
169 procedure Set_Style_Check_Options
170 (Options : String;
171 OK : out Boolean;
172 Err_Col : out Natural)
174 J : Natural;
175 C : Character;
177 begin
178 J := Options'First;
179 while J <= Options'Last loop
180 C := Options (J);
181 J := J + 1;
183 case C is
184 when '1' .. '9' =>
185 Style_Check_Indentation
186 := Character'Pos (C) - Character'Pos ('0');
188 when 'a' =>
189 Style_Check_Attribute_Casing := True;
191 when 'b' =>
192 Style_Check_Blanks_At_End := True;
194 when 'c' =>
195 Style_Check_Comments := True;
197 when 'e' =>
198 Style_Check_End_Labels := True;
200 when 'f' =>
201 Style_Check_Form_Feeds := True;
203 when 'h' =>
204 Style_Check_Horizontal_Tabs := True;
206 when 'i' =>
207 Style_Check_If_Then_Layout := True;
209 when 'k' =>
210 Style_Check_Keyword_Casing := True;
212 when 'l' =>
213 Style_Check_Layout := True;
215 when 'L' =>
216 Style_Max_Nesting_Level := 0;
218 if J > Options'Last
219 or else Options (J) not in '0' .. '9'
220 then
221 OK := False;
222 Err_Col := J;
223 return;
224 end if;
226 loop
227 Style_Max_Nesting_Level :=
228 Style_Max_Nesting_Level * 10 +
229 Character'Pos (Options (J)) - Character'Pos ('0');
231 if Style_Max_Nesting_Level > 999 then
232 OK := False;
233 Err_Col := J;
234 return;
235 end if;
237 J := J + 1;
238 exit when J > Options'Last
239 or else Options (J) not in '0' .. '9';
240 end loop;
242 Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
244 when 'm' =>
245 Style_Check_Max_Line_Length := True;
246 Style_Max_Line_Length := 79;
248 when 'n' =>
249 Style_Check_Standard := True;
251 when 'N' =>
252 Reset_Style_Check_Options;
254 when 'M' =>
255 Style_Max_Line_Length := 0;
257 if J > Options'Last
258 or else Options (J) not in '0' .. '9'
259 then
260 OK := False;
261 Err_Col := J;
262 return;
263 end if;
265 loop
266 Style_Max_Line_Length :=
267 Style_Max_Line_Length * 10 +
268 Character'Pos (Options (J)) - Character'Pos ('0');
270 if Style_Max_Line_Length > Int (Column_Number'Last) then
271 OK := False;
272 Err_Col := J;
273 return;
274 end if;
276 J := J + 1;
277 exit when J > Options'Last
278 or else Options (J) not in '0' .. '9';
279 end loop;
281 Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
283 when 'o' =>
284 Style_Check_Order_Subprograms := True;
286 when 'p' =>
287 Style_Check_Pragma_Casing := True;
289 when 'r' =>
290 Style_Check_References := True;
292 when 's' =>
293 Style_Check_Specs := True;
295 when 't' =>
296 Style_Check_Tokens := True;
298 when 'x' =>
299 Style_Check_Xtra_Parens := True;
301 when ' ' =>
302 null;
304 when others =>
305 OK := False;
306 Err_Col := J - 1;
307 return;
308 end case;
309 end loop;
311 Style_Check := True;
312 OK := True;
313 Err_Col := Options'Last + 1;
314 end Set_Style_Check_Options;
316 end Stylesw;