1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
10 -- Copyright (C) 1992-2001, Free Software Foundation, Inc. --
12 -- GNAT is free software; you can redistribute it and/or modify it under --
13 -- terms of the GNU General Public License as published by the Free Soft- --
14 -- ware Foundation; either version 2, or (at your option) any later ver- --
15 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
16 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
17 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
18 -- for more details. You should have received a copy of the GNU General --
19 -- Public License distributed with GNAT; see file COPYING. If not, write --
20 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
21 -- MA 02111-1307, USA. --
23 -- GNAT was originally developed by the GNAT team at New York University. --
24 -- Extensive contributions were provided by Ada Core Technologies Inc. --
26 ------------------------------------------------------------------------------
28 -- This package contains the style switches used for setting style options.
29 -- The only clients of this package are the body of Style and the body of
30 -- Switches. All other style checking issues are handled using the public
31 -- interfaces in the spec of Style.
33 with Types
; use Types
;
37 --------------------------
38 -- Style Check Switches --
39 --------------------------
41 -- These flags are used to control the details of the style checking
42 -- options. The default values shown here correspond to no style
43 -- checking. If any of these values is set to a non-default value,
44 -- then Opt.Style_Check is set True to active calls to this package.
46 -- The actual mechanism for setting these switches to other than
47 -- default values is via the Set_Style_Check_Option procedure or
48 -- through a call to Set_Default_Style_Check_Options. They should
49 -- not be set directly in any other manner.
51 Style_Check_Attribute_Casing
: Boolean := False;
52 -- This can be set True by using the -gnatg or -gnatya switches. If
53 -- it is True, then attribute names (including keywords such as
54 -- digits used as attribute names) must be in mixed case.
56 Style_Check_Blanks_At_End
: Boolean := False;
57 -- This can be set True by using the -gnatg or -gnatyb switches. If
58 -- it is True, then spaces at the end of lines are not permitted.
60 Style_Check_Comments
: Boolean := False;
61 -- This can be set True by using the -gnatg or -gnatyc switches. If
62 -- it is True, then comments are style checked as follows:
64 -- All comments must be at the start of the line, or the first
65 -- minus must be preceded by at least one space.
67 -- For a comment that is not at the start of a line, the only
68 -- requirement is that a space follow the comment characters.
70 -- For a coment that is at the start of the line, one of the
71 -- following conditions must hold:
73 -- The comment characters are the only non-blank characters on the line
75 -- The comment characters are followed by an exclamation point (the
76 -- sequence --! is used by gnatprep for marking deleted lines).
78 -- The comment characters are followed by two space characters
80 -- The line consists entirely of minus signs
82 -- The comment characters are followed by a single space, and the
83 -- last two characters on the line are also comment characters.
85 -- Note: the reason for the last two conditions is to allow "boxed"
86 -- comments where only a single space separates the comment characters.
88 Style_Check_End_Labels
: Boolean := False;
89 -- This can be set True by using the -gnatg or -gnatye switches. If
90 -- it is True, then optional END labels must always be present.
92 Style_Check_Form_Feeds
: Boolean := False;
93 -- This can be set True by using the -gnatg or -gnatyf switches. If
94 -- it is True, then form feeds and vertical tabs are not allowed in
97 Style_Check_Horizontal_Tabs
: Boolean := False;
98 -- This can be set True by using the -gnatg or -gnatyh switches. If
99 -- it is True, then horizontal tabs are not allowed in source text.
101 Style_Check_If_Then_Layout
: Boolean := False;
102 -- This can be set True by using the -gnatg or -gnatyi switches. If
103 -- it is True, then a THEN keyword may not appear on the line that
104 -- immediately follows the line containing the corresponding IF.
106 -- This permits one of two styles for IF-THEN layout. Either the
107 -- IF and THEN keywords are on the same line, where the condition
108 -- is short enough, or the conditions are continued over to the
109 -- lines following the IF and the THEN stands on its own. For
125 Style_Check_Indentation
: Column_Number
range 0 .. 9 := 0;
126 -- This can be set non-zero by using the -gnatg or -gnatyn (n a digit)
127 -- switches. If it is non-zero it activates indentation checking with
128 -- the indicated indentation value. A value of zero turns off checking.
129 -- The requirement is that any new statement, line comment, declaration
130 -- or keyword such as END, start on a column that is a multiple of the
131 -- indentiation value.
133 Style_Check_Keyword_Casing
: Boolean := False;
134 -- This can be set True by using the -gnatg or -gnatyk switches. If
135 -- it is True, then keywords are required to be in all lower case.
136 -- This rule does not apply to keywords such as digits appearing as
137 -- an attribute name.
139 Style_Check_Max_Line_Length
: Boolean := False;
140 -- This can be set True by using the -gnatg or -gnatym switches. If
141 -- it is True, it activates checking for a maximum line length of 79
142 -- characters (chosen to fit in standard 80 column displays that don't
143 -- handle the limiting case of 80 characters cleanly).
145 Style_Check_Pragma_Casing
: Boolean := False;
146 -- This can be set True by using the -gnatg or -gnatyp switches. If
147 -- it is True, then pragma names must use mixed case.
149 Style_Check_Layout
: Boolean := False;
150 -- This can be set True by using the -gnatg or -gnatyl switches. If
151 -- it is True, it activates checks that constructs are indented as
152 -- suggested by the examples in the RM syntax, e.g. that the ELSE
153 -- keyword must line up with the IF keyword.
155 Style_Check_References
: Boolean := False;
156 -- This can be set True by using the -gnatg or -gnatyr switches. If
157 -- it is True, then all references to declared identifiers are
158 -- checked. The requirement is that casing of the reference be the
159 -- same as the casing of the corresponding declaration.
161 Style_Check_Specs
: Boolean := False;
162 -- This can be set True by using the -gnatg or -gnatys switches. If
163 -- it is True, then separate specs are required to be present for
164 -- all procedures except parameterless library level procedures.
165 -- The exception means that typical main programs do not require
168 Style_Check_Standard
: Boolean := False;
169 -- This can be set True by using the -gnatg or -gnatyn switches. If
170 -- it is True, then any references to names in Standard have to be
171 -- in mixed case mode (e.g. Integer, Boolean).
173 Style_Check_Tokens
: Boolean := False;
174 -- This can be set True by using the -gnatg or -gnatyt switches. If
175 -- it is True, then the style check that requires canonical spacing
176 -- between various punctuation tokens as follows:
178 -- ABS and NOT must be followed by a space
180 -- => must be surrounded by spaces
182 -- <> must be preceded by a space or left paren
184 -- Binary operators other than ** must be surrounded by spaces.
185 -- There is no restriction on the layout of the ** binary operator.
187 -- Colon must be surrounded by spaces
189 -- Colon-equal (assignment) must be surrounded by spaces
191 -- Comma must be the first non-blank character on the line, or be
192 -- immediately preceded by a non-blank character, and must be followed
195 -- A space must precede a left paren following a digit or letter,
196 -- and a right paren must not be followed by a space (it can be
197 -- at the end of the line).
199 -- A right paren must either be the first non-blank character on
200 -- a line, or it must be preceded by a non-blank character.
202 -- A semicolon must not be preceded by a blank, and must not be
203 -- followed by a non-blank character.
205 -- A unary plus or minus may not be followed by a space
207 -- A vertical bar must be surrounded by spaces
209 -- Note that a requirement that a token be preceded by a space is
210 -- met by placing the token at the start of the line, and similarly
211 -- a requirement that a token be followed by a space is met by
212 -- placing the token at the end of the line. Note that in the case
213 -- where horizontal tabs are permitted, a horizontal tab is acceptable
214 -- for meeting the requirement for a space.
216 Style_Check_Subprogram_Order
: Boolean := False;
217 -- This can be set True by using the -gnatg or -gnatyo switch. If it
218 -- is True, then names of subprogram bodies must be in alphabetical
219 -- order (not taking casing into account).
221 Style_Max_Line_Length
: Int
:= 79;
222 -- Value used to check maximum line length. Can be reset by a call to
223 -- Set_Max_Line_Length. The value here is the default if no such call.
229 procedure Set_Default_Style_Check_Options
;
230 -- This procedure is called to set the default style checking options
231 -- in response to a -gnatg switch or -gnaty with no suboptions.
233 procedure Set_Style_Check_Options
236 Err_Col
: out Natural);
237 -- This procedure is called to set the style check options that
238 -- correspond to the characters in the given Options string. If
239 -- all options are valid, they are set in an additive manner:
240 -- any previous options are retained unless overridden. If any
241 -- invalid character is found, then OK is False on exit, and
242 -- Err_Col is the index in options of the bad character. If all
243 -- options are valid, OK is True on return, and Err_Col is set
244 -- to Options'Last + 1.
246 procedure Set_Style_Check_Options
(Options
: String);
247 -- Like the above procedure, except that the call is simply ignored if
248 -- there are any error conditions, this is for example appopriate for
249 -- calls where the string is known to be valid, e.g. because it was
250 -- obtained by Save_Style_Check_Options.
252 procedure Reset_Style_Check_Options
;
253 -- Sets all style check options to off
255 subtype Style_Check_Options
is String (1 .. 32);
256 -- Long enough string to hold all options from Save call below
258 procedure Save_Style_Check_Options
(Options
: out Style_Check_Options
);
259 -- Sets Options to represent current selection of options. This
260 -- set can be restored by first calling Reset_Style_Check_Options,
261 -- and then calling Set_Style_Check_Options with the Options string.