1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2008, 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 3, 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 COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package contains the style switches used for setting style options.
27 -- The only clients of this package are the body of Style and the body of
28 -- Switches. All other style checking issues are handled using the public
29 -- interfaces in the spec of Style.
31 with Types; use Types;
35 --------------------------
36 -- Style Check Switches --
37 --------------------------
39 -- These flags are used to control the details of the style checking
40 -- options. The default values shown here correspond to no style checking.
42 -- If any of these values is set to a non-default value, then
43 -- Opt.Style_Check is set True to active calls to this package.
45 -- The actual mechanism for setting these switches to other than default
46 -- values is via the Set_Style_Check_Option procedure or through a call to
47 -- Set_Default_Style_Check_Options. They should not be set directly in any
50 Style_Check_Array_Attribute_Index : Boolean := False;
51 -- This can be set True by using -gnatg or -gnatyA switches. If it is True
52 -- then index numbers for array attributes (like Length) are required to
53 -- be absent for one-dimensional arrays and present for multi-dimensional
54 -- array attribute references.
56 Style_Check_Attribute_Casing : Boolean := False;
57 -- This can be set True by using the -gnatg or -gnatya switches. If it is
58 -- True, then attribute names (including keywords such as digits used as
59 -- attribute names) must be in mixed case.
61 Style_Check_Blanks_At_End : Boolean := False;
62 -- This can be set True by using the -gnatg or -gnatyb switches. If it is
63 -- True, then spaces at the end of lines are not permitted.
65 Style_Check_Blank_Lines : Boolean := False;
66 -- This can be set True by using the -gnatg or -gnatyu switches. If it is
67 -- True, then multiple blank lines are not permitted, and there may not be
68 -- a blank line at the end of the file.
70 Style_Check_Comments : Boolean := False;
71 -- This can be set True by using the -gnatg or -gnatyc switches. If it is
72 -- True, then comments are style checked as follows:
74 -- All comments must be at the start of the line, or the first minus must
75 -- be preceded by at least one space.
77 -- For a comment that is not at the start of a line, the only requirement
78 -- is that a space follow the comment characters.
80 -- For a comment that is at the start of the line, one of the following
81 -- conditions must hold:
83 -- The comment characters are the only non-blank characters on the line
85 -- The comment characters are followed by an exclamation point (the
86 -- sequence --! is used by gnatprep for marking deleted lines).
88 -- The comment characters are followed by two space characters
90 -- The line consists entirely of minus signs
92 -- The comment characters are followed by a single space, and the last
93 -- two characters on the line are also comment characters.
95 -- Note: the reason for the last two conditions is to allow "boxed"
96 -- comments where only a single space separates the comment characters.
98 Style_Check_DOS_Line_Terminator : Boolean := False;
99 -- This can be set true by using the -gnatg or -gnatyd switches. If it
100 -- is True, then the line terminator must be a single LF, without an
101 -- associated CR (e.g. DOS line terminator sequence CR/LF not allowed).
103 Style_Check_End_Labels : Boolean := False;
104 -- This can be set True by using the -gnatg or -gnatye switches. If it is
105 -- True, then optional END labels must always be present.
107 Style_Check_Form_Feeds : Boolean := False;
108 -- This can be set True by using the -gnatg or -gnatyf switches. If it is
109 -- True, then form feeds and vertical tabs are not allowed in the source
112 Style_Check_Horizontal_Tabs : Boolean := False;
113 -- This can be set True by using the -gnatg or -gnatyh switches. If it is
114 -- True, then horizontal tabs are not allowed in source text.
116 Style_Check_If_Then_Layout : Boolean := False;
117 -- This can be set True by using the -gnatg or -gnatyi switches. If it is
118 -- True, then a THEN keyword may not appear on the line that immediately
119 -- follows the line containing the corresponding IF.
121 -- This permits one of two styles for IF-THEN layout. Either the IF and
122 -- THEN keywords are on the same line, where the condition is short enough,
123 -- or the conditions are continued over to the lines following the IF and
124 -- the THEN stands on its own. For example:
139 Style_Check_Indentation : Column_Number range 0 .. 9 := 0;
140 -- This can be set non-zero by using the -gnatg or -gnatyn (n a digit)
141 -- switches. If it is non-zero it activates indentation checking with the
142 -- indicated indentation value. A value of zero turns off checking. The
143 -- requirement is that any new statement, line comment, declaration or
144 -- keyword such as END, start on a column that is a multiple of the
145 -- indentation value.
147 Style_Check_Keyword_Casing : Boolean := False;
148 -- This can be set True by using the -gnatg or -gnatyk switches. If it is
149 -- True, then keywords are required to be in all lower case. This rule does
150 -- not apply to keywords such as digits appearing as an attribute name.
152 Style_Check_Layout : Boolean := False;
153 -- This can be set True by using the -gnatg or -gnatyl switches. If it is
154 -- True, it activates checks that constructs are indented as suggested by
155 -- the examples in the RM syntax, e.g. that the ELSE keyword must line up
156 -- with the IF keyword.
158 Style_Check_Max_Line_Length : Boolean := False;
159 -- This can be set True by using the -gnatg or -gnatym/M switches.
160 -- If it is True, it activates checking for a maximum line length of
161 -- Style_Max_Line_Length characters.
163 Style_Check_Max_Nesting_Level : Boolean := False;
164 -- This can be set True by using -gnatyLnnn with a value other than zero
165 -- (a value of zero resets it to False). If True, it activates checking
166 -- the maximum nesting level against Style_Max_Nesting_Level.
168 Style_Check_Missing_Overriding : Boolean := False;
169 -- This can be set True by using the -gnatyO switch. If it is True, then
170 -- "[not] overriding" is required in subprogram declarations and bodies
171 -- where appropriate.
173 Style_Check_Mode_In : Boolean := False;
174 -- This can be set True by using -gnatyI. If True, it activates checking
175 -- that mode IN is not used on its own (since it is the default).
177 Style_Check_Order_Subprograms : Boolean := False;
178 -- This can be set True by using the -gnatg or -gnatyo switch. If it is
179 -- True, then names of subprogram bodies must be in alphabetical order
180 -- (not taking casing into account).
182 Style_Check_Pragma_Casing : Boolean := False;
183 -- This can be set True by using the -gnatg or -gnatyp switches. If it is
184 -- True, then pragma names must use mixed case.
186 Style_Check_References : Boolean := False;
187 -- This can be set True by using the -gnatg or -gnatyr switches. If it is
188 -- True, then all references to declared identifiers are checked. The
189 -- requirement is that casing of the reference be the same as the casing
190 -- of the corresponding declaration.
192 Style_Check_Separate_Stmt_Lines : Boolean := False;
193 -- This can be set True by using the -gnatg or -gnatyS switches. If it is
194 -- TRUE, then for the case of keywords THEN (not preceded by AND) or ELSE
195 -- (not preceded by OR) which introduce a conditionally executed statement
196 -- sequence, there must be no tokens on the same line as the keyword, so
197 -- that coverage testing can clearly identify execution of the statement
198 -- sequence. A comment is permitted, as is THEN ABORT or a PRAGMA keyword
199 -- after ELSE (a common style to specify the condition for the ELSE).
201 Style_Check_Specs : Boolean := False;
202 -- This can be set True by using the -gnatg or -gnatys switches. If it is
203 -- True, then separate specs are required to be present for all procedures
204 -- except parameterless library level procedures. The exception means that
205 -- typical main programs do not require separate specs.
207 Style_Check_Standard : Boolean := False;
208 -- This can be set True by using the -gnatg or -gnatyn switches. If it is
209 -- True, then any references to names in Standard have to be in mixed case
210 -- mode (e.g. Integer, Boolean).
212 Style_Check_Tokens : Boolean := False;
213 -- This can be set True by using the -gnatg or -gnatyt switches. If it is
214 -- True, then the style check that requires canonical spacing between
215 -- various punctuation tokens as follows:
217 -- ABS and NOT must be followed by a space
219 -- => must be surrounded by spaces
221 -- <> must be preceded by a space or left paren
223 -- Binary operators other than ** must be surrounded by spaces.
225 -- There is no restriction on the layout of the ** binary operator.
227 -- Colon must be surrounded by spaces
229 -- Colon-equal (assignment) must be surrounded by spaces
231 -- Comma must be the first non-blank character on the line, or be
232 -- immediately preceded by a non-blank character, and must be followed
235 -- A space must precede a left paren following a digit or letter, and a
236 -- right paren must not be followed by a space (it can be at the end of
239 -- A right paren must either be the first non-blank character on a line,
240 -- or it must be preceded by a non-blank character.
242 -- A semicolon must not be preceded by a blank, and must not be followed
243 -- by a non-blank character.
245 -- A unary plus or minus may not be followed by a space
247 -- A vertical bar must be surrounded by spaces
249 -- Note that a requirement that a token be preceded by a space is met by
250 -- placing the token at the start of the line, and similarly a requirement
251 -- that a token be followed by a space is met by placing the token at
252 -- the end of the line. Note that in the case where horizontal tabs are
253 -- permitted, a horizontal tab is acceptable for meeting the requirement
256 Style_Check_Xtra_Parens : Boolean := False;
257 -- This can be set True by using the -gnatg or -gnatyx switch. If true,
258 -- then it is not allowed to enclose entire conditional expressions in
259 -- parentheses (C style).
261 Style_Max_Line_Length : Int := 0;
262 -- Value used to check maximum line length. Gets reset as a result of use
263 -- of -gnatym or -gnatyMnnn switches (or by use of -gnatg). This value is
264 -- only read if Style_Check_Max_Line_Length is True.
266 Style_Max_Nesting_Level : Int := 0;
267 -- Value used to check maximum nesting level. Gets reset as a result
268 -- of use of the -gnatyLnnn switch. This value is only read if
269 -- Style_Check_Max_Nesting_Level is True.
275 procedure Set_Default_Style_Check_Options;
276 -- This procedure is called to set the default style checking options in
277 -- response to a -gnaty switch with no suboptions or from -gnatyy.
279 procedure Set_GNAT_Style_Check_Options;
280 -- This procedure is called to set the default style checking options for
281 -- GNAT units (as set by -gnatg or -gnatyg).
283 Style_Msg_Buf : String (1 .. 80);
284 Style_Msg_Len : Natural;
287 procedure Set_Style_Check_Options
290 Err_Col : out Natural);
291 -- This procedure is called to set the style check options that correspond
292 -- to the characters in the given Options string. If all options are valid,
293 -- they are set in an additive manner: any previous options are retained
294 -- unless overridden, unless a minus is encountered, and then subsequent
295 -- style switches are subtracted from the current set.
297 -- If all options given are valid, then OK is True, Err_Col is set to
298 -- Options'Last + 1, and Style_Msg_Buf/Style_Msg_Len are unchanged.
300 -- If an invalid character is found, then OK is False on exit, and Err_Col
301 -- is the index in options of the bad character. In this case Style_Msg_Len
302 -- is set and Style_Msg_Buf (1 .. Style_Msg_Len) has a detailed message
303 -- describing the error.
305 procedure Set_Style_Check_Options (Options : String);
306 -- Like the above procedure, but used when the Options string is known to
307 -- be valid. This is for example appropriate for calls where the string ==
308 -- was obtained by Save_Style_Check_Options.
310 procedure Reset_Style_Check_Options;
311 -- Sets all style check options to off
313 subtype Style_Check_Options is String (1 .. 64);
314 -- Long enough string to hold all options from Save call below
316 procedure Save_Style_Check_Options (Options : out Style_Check_Options);
317 -- Sets Options to represent current selection of options. This set can be
318 -- restored by first calling Reset_Style_Check_Options, and then calling
319 -- Set_Style_Check_Options with the Options string.