1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2007, 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 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 with Hostparm; use Hostparm;
30 package body Stylesw is
32 -------------------------------
33 -- Reset_Style_Check_Options --
34 -------------------------------
36 procedure Reset_Style_Check_Options is
38 Style_Check_Indentation := 0;
39 Style_Check_Array_Attribute_Index := False;
40 Style_Check_Attribute_Casing := False;
41 Style_Check_Blanks_At_End := False;
42 Style_Check_Blank_Lines := False;
43 Style_Check_Comments := False;
44 Style_Check_DOS_Line_Terminator := False;
45 Style_Check_End_Labels := False;
46 Style_Check_Form_Feeds := False;
47 Style_Check_Horizontal_Tabs := False;
48 Style_Check_If_Then_Layout := False;
49 Style_Check_Keyword_Casing := False;
50 Style_Check_Layout := False;
51 Style_Check_Max_Line_Length := False;
52 Style_Check_Max_Nesting_Level := False;
53 Style_Check_Mode_In := False;
54 Style_Check_Order_Subprograms := False;
55 Style_Check_Pragma_Casing := False;
56 Style_Check_References := False;
57 Style_Check_Specs := False;
58 Style_Check_Standard := False;
59 Style_Check_Tokens := False;
60 Style_Check_Xtra_Parens := False;
61 end Reset_Style_Check_Options;
63 ------------------------------
64 -- Save_Style_Check_Options --
65 ------------------------------
67 procedure Save_Style_Check_Options (Options : out Style_Check_Options) is
70 procedure Add (C : Character; S : Boolean);
71 -- Add given character C to string if switch S is true
73 procedure Add_Nat (N : Nat);
74 -- Add given natural number to string
80 procedure Add (C : Character; S : Boolean) is
92 procedure Add_Nat (N : Nat) is
99 Options (P) := Character'Val (Character'Pos ('0') + N mod 10);
102 -- Start of processing for Save_Style_Check_Options
105 for K in Options'Range loop
109 Add (Character'Val (Style_Check_Indentation + Character'Pos ('0')),
110 Style_Check_Indentation /= 0);
112 Add ('a', Style_Check_Attribute_Casing);
113 Add ('A', Style_Check_Array_Attribute_Index);
114 Add ('b', Style_Check_Blanks_At_End);
115 Add ('c', Style_Check_Comments);
116 Add ('d', Style_Check_DOS_Line_Terminator);
117 Add ('e', Style_Check_End_Labels);
118 Add ('f', Style_Check_Form_Feeds);
119 Add ('h', Style_Check_Horizontal_Tabs);
120 Add ('i', Style_Check_If_Then_Layout);
121 Add ('I', Style_Check_Mode_In);
122 Add ('k', Style_Check_Keyword_Casing);
123 Add ('l', Style_Check_Layout);
124 Add ('n', Style_Check_Standard);
125 Add ('o', Style_Check_Order_Subprograms);
126 Add ('p', Style_Check_Pragma_Casing);
127 Add ('r', Style_Check_References);
128 Add ('s', Style_Check_Specs);
129 Add ('t', Style_Check_Tokens);
130 Add ('u', Style_Check_Blank_Lines);
131 Add ('x', Style_Check_Xtra_Parens);
133 if Style_Check_Max_Line_Length then
136 Add_Nat (Style_Max_Line_Length);
139 if Style_Check_Max_Nesting_Level then
142 Add_Nat (Style_Max_Nesting_Level);
145 pragma Assert (P <= Options'Last);
147 while P < Options'Last loop
151 end Save_Style_Check_Options;
153 -------------------------------------
154 -- Set_Default_Style_Check_Options --
155 -------------------------------------
157 procedure Set_Default_Style_Check_Options is
159 Reset_Style_Check_Options;
160 Set_Style_Check_Options ("3aAbcefhiklmnprst");
161 end Set_Default_Style_Check_Options;
163 ----------------------------------
164 -- Set_GNAT_Style_Check_Options --
165 ----------------------------------
167 procedure Set_GNAT_Style_Check_Options is
169 Reset_Style_Check_Options;
170 Set_Style_Check_Options ("3aAbcdefhiklmnprstux");
171 end Set_GNAT_Style_Check_Options;
173 -----------------------------
174 -- Set_Style_Check_Options --
175 -----------------------------
177 -- Version used when no error checking is required
179 procedure Set_Style_Check_Options (Options : String) is
183 Set_Style_Check_Options (Options, OK, EC);
185 end Set_Style_Check_Options;
187 -- Normal version with error checking
189 procedure Set_Style_Check_Options
192 Err_Col : out Natural)
196 procedure Add_Img (N : Natural);
197 -- Concatenates image of N at end of Style_Msg_Buf
199 procedure Bad_Style_Switch (Msg : String);
200 -- Called if bad style switch found. Msg is mset in Style_Msg_Buf and
201 -- Style_Msg_Len. OK is set False.
207 procedure Add_Img (N : Natural) is
213 Style_Msg_Len := Style_Msg_Len + 1;
214 Style_Msg_Buf (Style_Msg_Len) :=
215 Character'Val (N mod 10 + Character'Pos ('0'));
218 ----------------------
219 -- Bad_Style_Switch --
220 ----------------------
222 procedure Bad_Style_Switch (Msg : String) is
225 Style_Msg_Len := Msg'Length;
226 Style_Msg_Buf (1 .. Style_Msg_Len) := Msg;
227 end Bad_Style_Switch;
229 -- Start of processing for Set_Style_Check_Options
232 Err_Col := Options'First;
233 while Err_Col <= Options'Last loop
234 C := Options (Err_Col);
235 Err_Col := Err_Col + 1;
239 Style_Check_Indentation :=
240 Character'Pos (C) - Character'Pos ('0');
243 Style_Check_Attribute_Casing := True;
246 Style_Check_Array_Attribute_Index := True;
249 Style_Check_Blanks_At_End := True;
252 Style_Check_Comments := True;
255 Style_Check_DOS_Line_Terminator := True;
258 Style_Check_End_Labels := True;
261 Style_Check_Form_Feeds := True;
264 Set_GNAT_Style_Check_Options;
267 Style_Check_Horizontal_Tabs := True;
270 Style_Check_If_Then_Layout := True;
273 Style_Check_Mode_In := True;
276 Style_Check_Keyword_Casing := True;
279 Style_Check_Layout := True;
282 Style_Max_Nesting_Level := 0;
284 if Err_Col > Options'Last
285 or else Options (Err_Col) not in '0' .. '9'
287 Bad_Style_Switch ("invalid nesting level");
292 Style_Max_Nesting_Level :=
293 Style_Max_Nesting_Level * 10 +
294 Character'Pos (Options (Err_Col)) - Character'Pos ('0');
296 if Style_Max_Nesting_Level > 999 then
298 ("max nesting level (999) exceeded in style check");
302 Err_Col := Err_Col + 1;
303 exit when Err_Col > Options'Last
304 or else Options (Err_Col) not in '0' .. '9';
307 Style_Check_Max_Nesting_Level := Style_Max_Nesting_Level /= 0;
310 Style_Check_Max_Line_Length := True;
311 Style_Max_Line_Length := 79;
314 Style_Max_Line_Length := 0;
316 if Err_Col > Options'Last
317 or else Options (Err_Col) not in '0' .. '9'
320 ("invalid line length in style check");
325 Style_Max_Line_Length :=
326 Style_Max_Line_Length * 10 +
327 Character'Pos (Options (Err_Col)) - Character'Pos ('0');
329 if Style_Max_Line_Length > Int (Max_Line_Length) then
331 Style_Msg_Buf (1 .. 27) := "max line length allowed is ";
333 Add_Img (Natural (Max_Line_Length));
337 Err_Col := Err_Col + 1;
338 exit when Err_Col > Options'Last
339 or else Options (Err_Col) not in '0' .. '9';
342 Style_Check_Max_Line_Length := Style_Max_Line_Length /= 0;
345 Style_Check_Standard := True;
348 Reset_Style_Check_Options;
351 Style_Check_Order_Subprograms := True;
354 Style_Check_Pragma_Casing := True;
357 Style_Check_References := True;
360 Style_Check_Specs := True;
363 Style_Check_Tokens := True;
366 Style_Check_Blank_Lines := True;
369 Style_Check_Xtra_Parens := True;
375 Err_Col := Err_Col - 1;
376 Style_Msg_Buf (1 .. 22) := "invalid style switch: ";
378 Style_Msg_Buf (Style_Msg_Len) := C;
386 end Set_Style_Check_Options;