1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2005, 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 ------------------------------------------------------------------------------
29 package body Stylesw
is
31 -------------------------------
32 -- Reset_Style_Check_Options --
33 -------------------------------
35 procedure Reset_Style_Check_Options
is
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
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
77 procedure Add
(C
: Character; S
: Boolean) is
89 procedure Add_Nat
(N
: Nat
) is
96 Options
(P
) := Character'Val (Character'Pos ('0') + N
mod 10);
99 -- Start of processing for Save_Style_Check_Options
102 for K
in Options
'Range 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
131 Add_Nat
(Style_Max_Line_Length
);
134 if Style_Check_Max_Nesting_Level
then
137 Add_Nat
(Style_Max_Nesting_Level
);
140 pragma Assert
(P
<= Options
'Last);
142 while P
< Options
'Last loop
146 end Save_Style_Check_Options
;
148 -------------------------------------
149 -- Set_Default_Style_Check_Options --
150 -------------------------------------
152 procedure Set_Default_Style_Check_Options
is
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
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
176 Err_Col
: out Natural)
183 while J
<= Options
'Last loop
189 Style_Check_Indentation
190 := Character'Pos (C
) - Character'Pos ('0');
193 Style_Check_Attribute_Casing
:= True;
196 Style_Check_Blanks_At_End
:= True;
199 Style_Check_Comments
:= True;
202 Style_Check_DOS_Line_Terminator
:= True;
205 Style_Check_End_Labels
:= True;
208 Style_Check_Form_Feeds
:= True;
211 Style_Check_Horizontal_Tabs
:= True;
214 Style_Check_If_Then_Layout
:= True;
217 Style_Check_Keyword_Casing
:= True;
220 Style_Check_Layout
:= True;
223 Style_Max_Nesting_Level
:= 0;
226 or else Options
(J
) not in '0' .. '9'
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
245 exit when J
> Options
'Last
246 or else Options
(J
) not in '0' .. '9';
249 Style_Check_Max_Nesting_Level
:= Style_Max_Nesting_Level
/= 0;
252 Style_Check_Max_Line_Length
:= True;
253 Style_Max_Line_Length
:= 79;
256 Style_Check_Standard
:= True;
259 Reset_Style_Check_Options
;
262 Style_Max_Line_Length
:= 0;
265 or else Options
(J
) not in '0' .. '9'
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
284 exit when J
> Options
'Last
285 or else Options
(J
) not in '0' .. '9';
288 Style_Check_Max_Line_Length
:= Style_Max_Line_Length
/= 0;
291 Style_Check_Order_Subprograms
:= True;
294 Style_Check_Pragma_Casing
:= True;
297 Style_Check_References
:= True;
300 Style_Check_Specs
:= True;
303 Style_Check_Tokens
:= True;
306 Style_Check_Blank_Lines
:= True;
309 Style_Check_Xtra_Parens
:= True;
323 Err_Col
:= Options
'Last + 1;
324 end Set_Style_Check_Options
;