1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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_Attribute_Casing
:= False;
40 Style_Check_Blanks_At_End
:= False;
41 Style_Check_Blank_Lines
:= False;
42 Style_Check_Comments
:= False;
43 Style_Check_DOS_Line_Terminator
:= False;
44 Style_Check_End_Labels
:= False;
45 Style_Check_Form_Feeds
:= False;
46 Style_Check_Horizontal_Tabs
:= False;
47 Style_Check_If_Then_Layout
:= False;
48 Style_Check_Keyword_Casing
:= False;
49 Style_Check_Layout
:= False;
50 Style_Check_Max_Line_Length
:= False;
51 Style_Check_Max_Nesting_Level
:= False;
52 Style_Check_Mode_In
:= False;
53 Style_Check_Order_Subprograms
:= False;
54 Style_Check_Pragma_Casing
:= False;
55 Style_Check_References
:= False;
56 Style_Check_Specs
:= False;
57 Style_Check_Standard
:= False;
58 Style_Check_Tokens
:= False;
59 Style_Check_Xtra_Parens
:= False;
60 end Reset_Style_Check_Options
;
62 ------------------------------
63 -- Save_Style_Check_Options --
64 ------------------------------
66 procedure Save_Style_Check_Options
(Options
: out Style_Check_Options
) is
69 procedure Add
(C
: Character; S
: Boolean);
70 -- Add given character C to string if switch S is true
72 procedure Add_Nat
(N
: Nat
);
73 -- Add given natural number to string
79 procedure Add
(C
: Character; S
: Boolean) is
91 procedure Add_Nat
(N
: Nat
) is
98 Options
(P
) := Character'Val (Character'Pos ('0') + N
mod 10);
101 -- Start of processing for Save_Style_Check_Options
104 for K
in Options
'Range loop
108 Add
(Character'Val (Style_Check_Indentation
+ Character'Pos ('0')),
109 Style_Check_Indentation
/= 0);
111 Add
('a', Style_Check_Attribute_Casing
);
112 Add
('b', Style_Check_Blanks_At_End
);
113 Add
('c', Style_Check_Comments
);
114 Add
('d', Style_Check_DOS_Line_Terminator
);
115 Add
('e', Style_Check_End_Labels
);
116 Add
('f', Style_Check_Form_Feeds
);
117 Add
('h', Style_Check_Horizontal_Tabs
);
118 Add
('i', Style_Check_If_Then_Layout
);
119 Add
('I', Style_Check_Mode_In
);
120 Add
('k', Style_Check_Keyword_Casing
);
121 Add
('l', Style_Check_Layout
);
122 Add
('n', Style_Check_Standard
);
123 Add
('o', Style_Check_Order_Subprograms
);
124 Add
('p', Style_Check_Pragma_Casing
);
125 Add
('r', Style_Check_References
);
126 Add
('s', Style_Check_Specs
);
127 Add
('t', Style_Check_Tokens
);
128 Add
('u', Style_Check_Blank_Lines
);
129 Add
('x', Style_Check_Xtra_Parens
);
131 if Style_Check_Max_Line_Length
then
134 Add_Nat
(Style_Max_Line_Length
);
137 if Style_Check_Max_Nesting_Level
then
140 Add_Nat
(Style_Max_Nesting_Level
);
143 pragma Assert
(P
<= Options
'Last);
145 while P
< Options
'Last loop
149 end Save_Style_Check_Options
;
151 -------------------------------------
152 -- Set_Default_Style_Check_Options --
153 -------------------------------------
155 procedure Set_Default_Style_Check_Options
is
157 Reset_Style_Check_Options
;
158 Set_Style_Check_Options
("3abcefhiklmnprst");
159 end Set_Default_Style_Check_Options
;
161 -----------------------------
162 -- Set_Style_Check_Options --
163 -----------------------------
165 -- Version used when no error checking is required
167 procedure Set_Style_Check_Options
(Options
: String) is
171 Set_Style_Check_Options
(Options
, OK
, EC
);
173 end Set_Style_Check_Options
;
175 -- Normal version with error checking
177 procedure Set_Style_Check_Options
180 Err_Col
: out Natural)
184 procedure Add_Img
(N
: Natural);
185 -- Concatenates image of N at end of Style_Msg_Buf
187 procedure Bad_Style_Switch
(Msg
: String);
188 -- Called if bad style switch found. Msg is mset in Style_Msg_Buf and
189 -- Style_Msg_Len. OK is set False.
195 procedure Add_Img
(N
: Natural) is
201 Style_Msg_Len
:= Style_Msg_Len
+ 1;
202 Style_Msg_Buf
(Style_Msg_Len
) :=
203 Character'Val (N
mod 10 + Character'Pos ('0'));
206 ----------------------
207 -- Bad_Style_Switch --
208 ----------------------
210 procedure Bad_Style_Switch
(Msg
: String) is
213 Style_Msg_Len
:= Msg
'Length;
214 Style_Msg_Buf
(1 .. Style_Msg_Len
) := Msg
;
215 end Bad_Style_Switch
;
217 -- Start of processing for Set_Style_Check_Options
220 Err_Col
:= Options
'First;
221 while Err_Col
<= Options
'Last loop
222 C
:= Options
(Err_Col
);
223 Err_Col
:= Err_Col
+ 1;
227 Style_Check_Indentation
:=
228 Character'Pos (C
) - Character'Pos ('0');
231 Style_Check_Attribute_Casing
:= True;
234 Style_Check_Blanks_At_End
:= True;
237 Style_Check_Comments
:= True;
240 Style_Check_DOS_Line_Terminator
:= True;
243 Style_Check_End_Labels
:= True;
246 Style_Check_Form_Feeds
:= True;
249 Style_Check_Horizontal_Tabs
:= True;
252 Style_Check_If_Then_Layout
:= True;
255 Style_Check_Mode_In
:= True;
258 Style_Check_Keyword_Casing
:= True;
261 Style_Check_Layout
:= True;
264 Style_Max_Nesting_Level
:= 0;
266 if Err_Col
> Options
'Last
267 or else Options
(Err_Col
) not in '0' .. '9'
269 Bad_Style_Switch
("invalid nesting level");
274 Style_Max_Nesting_Level
:=
275 Style_Max_Nesting_Level
* 10 +
276 Character'Pos (Options
(Err_Col
)) - Character'Pos ('0');
278 if Style_Max_Nesting_Level
> 999 then
280 ("max nesting level (999) exceeded in style check");
284 Err_Col
:= Err_Col
+ 1;
285 exit when Err_Col
> Options
'Last
286 or else Options
(Err_Col
) not in '0' .. '9';
289 Style_Check_Max_Nesting_Level
:= Style_Max_Nesting_Level
/= 0;
292 Style_Check_Max_Line_Length
:= True;
293 Style_Max_Line_Length
:= 79;
296 Style_Max_Line_Length
:= 0;
298 if Err_Col
> Options
'Last
299 or else Options
(Err_Col
) not in '0' .. '9'
302 ("invalid line length in style check");
307 Style_Max_Line_Length
:=
308 Style_Max_Line_Length
* 10 +
309 Character'Pos (Options
(Err_Col
)) - Character'Pos ('0');
311 if Style_Max_Line_Length
> Int
(Max_Line_Length
) then
313 Style_Msg_Buf
(1 .. 27) := "max line length allowed is ";
315 Add_Img
(Natural (Max_Line_Length
));
319 Err_Col
:= Err_Col
+ 1;
320 exit when Err_Col
> Options
'Last
321 or else Options
(Err_Col
) not in '0' .. '9';
324 Style_Check_Max_Line_Length
:= Style_Max_Line_Length
/= 0;
327 Style_Check_Standard
:= True;
330 Reset_Style_Check_Options
;
333 Style_Check_Order_Subprograms
:= True;
336 Style_Check_Pragma_Casing
:= True;
339 Style_Check_References
:= True;
342 Style_Check_Specs
:= True;
345 Style_Check_Tokens
:= True;
348 Style_Check_Blank_Lines
:= True;
351 Style_Check_Xtra_Parens
:= True;
357 Err_Col
:= Err_Col
- 1;
358 Style_Msg_Buf
(1 .. 21) := "invalid style switch:";
360 Style_Msg_Buf
(Style_Msg_Len
) := C
;
368 end Set_Style_Check_Options
;