2008-05-30 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / ada / stylesw.ads
blob87552d35bc640b3fd12a042b6214768364248f63
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S T Y L E S W --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
10 -- --
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. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
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;
33 package Stylesw is
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
48 -- other manner.
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
110 -- text.
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:
126 -- if X > Y then
128 -- if X > Y
129 -- and then Y < Z
130 -- then
132 -- are allowed, but
134 -- if X > Y
135 -- then
137 -- is not allowed.
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. If
160 -- 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_Mode_In : Boolean := False;
169 -- This can be set True by using -gnatyI. If True, it activates checking
170 -- that mode IN is not used on its own (since it is the default).
172 Style_Check_Order_Subprograms : Boolean := False;
173 -- This can be set True by using the -gnatg or -gnatyo switch. If it is
174 -- True, then names of subprogram bodies must be in alphabetical order
175 -- (not taking casing into account).
177 Style_Check_Pragma_Casing : Boolean := False;
178 -- This can be set True by using the -gnatg or -gnatyp switches. If it is
179 -- True, then pragma names must use mixed case.
181 Style_Check_References : Boolean := False;
182 -- This can be set True by using the -gnatg or -gnatyr switches. If it is
183 -- True, then all references to declared identifiers are checked. The
184 -- requirement is that casing of the reference be the same as the casing
185 -- of the corresponding declaration.
187 Style_Check_Separate_Stmt_Lines : Boolean := False;
188 -- This can be set True by using the -gnatg or -gnatyS switches. If it is
189 -- TRUE, then for the case of keywords THEN (not preceded by AND) or ELSE
190 -- (not preceded by OR) which introduce a conditionally executed statement
191 -- sequence, there must be no tokens on the same line as the keyword, so
192 -- that coverage testing can clearly identify execution of the statement
193 -- sequence. A comment is permitted, as is THEN ABORT or a PRAGMA keyword
194 -- after ELSE (a common style to specify the condition for the ELSE).
196 Style_Check_Specs : Boolean := False;
197 -- This can be set True by using the -gnatg or -gnatys switches. If it is
198 -- True, then separate specs are required to be present for all procedures
199 -- except parameterless library level procedures. The exception means that
200 -- typical main programs do not require separate specs.
202 Style_Check_Standard : Boolean := False;
203 -- This can be set True by using the -gnatg or -gnatyn switches. If it is
204 -- True, then any references to names in Standard have to be in mixed case
205 -- mode (e.g. Integer, Boolean).
207 Style_Check_Tokens : Boolean := False;
208 -- This can be set True by using the -gnatg or -gnatyt switches. If it is
209 -- True, then the style check that requires canonical spacing between
210 -- various punctuation tokens as follows:
212 -- ABS and NOT must be followed by a space
214 -- => must be surrounded by spaces
216 -- <> must be preceded by a space or left paren
218 -- Binary operators other than ** must be surrounded by spaces.
220 -- There is no restriction on the layout of the ** binary operator.
222 -- Colon must be surrounded by spaces
224 -- Colon-equal (assignment) must be surrounded by spaces
226 -- Comma must be the first non-blank character on the line, or be
227 -- immediately preceded by a non-blank character, and must be followed
228 -- by a blank.
230 -- A space must precede a left paren following a digit or letter, and a
231 -- right paren must not be followed by a space (it can be at the end of
232 -- the line).
234 -- A right paren must either be the first non-blank character on a line,
235 -- or it must be preceded by a non-blank character.
237 -- A semicolon must not be preceded by a blank, and must not be followed
238 -- by a non-blank character.
240 -- A unary plus or minus may not be followed by a space
242 -- A vertical bar must be surrounded by spaces
244 -- Note that a requirement that a token be preceded by a space is met by
245 -- placing the token at the start of the line, and similarly a requirement
246 -- that a token be followed by a space is met by placing the token at
247 -- the end of the line. Note that in the case where horizontal tabs are
248 -- permitted, a horizontal tab is acceptable for meeting the requirement
249 -- for a space.
251 Style_Check_Xtra_Parens : Boolean := False;
252 -- This can be set True by using the -gnatg or -gnatyx switch. If true,
253 -- then it is not allowed to enclose entire conditional expressions in
254 -- parentheses (C style).
256 Style_Max_Line_Length : Int := 0;
257 -- Value used to check maximum line length. Gets reset as a result of use
258 -- of -gnatym or -gnatyMnnn switches (or by use of -gnatg). This value is
259 -- only read if Style_Check_Max_Line_Length is True.
261 Style_Max_Nesting_Level : Int := 0;
262 -- Value used to check maximum nesting level. Gets reset as a result
263 -- of use of the -gnatyLnnn switch. This value is only read if
264 -- Style_Check_Max_Nesting_Level is True.
266 -----------------
267 -- Subprograms --
268 -----------------
270 procedure Set_Default_Style_Check_Options;
271 -- This procedure is called to set the default style checking options in
272 -- response to a -gnaty switch with no suboptions or from -gnatyy.
274 procedure Set_GNAT_Style_Check_Options;
275 -- This procedure is called to set the default style checking options for
276 -- GNAT units (as set by -gnatg or -gnatyg).
278 Style_Msg_Buf : String (1 .. 80);
279 Style_Msg_Len : Natural;
280 -- Used to return
282 procedure Set_Style_Check_Options
283 (Options : String;
284 OK : out Boolean;
285 Err_Col : out Natural);
286 -- This procedure is called to set the style check options that correspond
287 -- to the characters in the given Options string. If all options are valid,
288 -- they are set in an additive manner: any previous options are retained
289 -- unless overridden, unless a minus is encountered, and then subsequent
290 -- style switches are subtracted from the current set.
292 -- If all options given are valid, then OK is True, Err_Col is set to
293 -- Options'Last + 1, and Style_Msg_Buf/Style_Msg_Len are unchanged.
295 -- If an invalid character is found, then OK is False on exit, and Err_Col
296 -- is the index in options of the bad character. In this case Style_Msg_Len
297 -- is set and Style_Msg_Buf (1 .. Style_Msg_Len) has a detailed message
298 -- describing the error.
300 procedure Set_Style_Check_Options (Options : String);
301 -- Like the above procedure, but used when the Options string is known to
302 -- be valid. This is for example appropriate for calls where the string ==
303 -- was obtained by Save_Style_Check_Options.
305 procedure Reset_Style_Check_Options;
306 -- Sets all style check options to off
308 subtype Style_Check_Options is String (1 .. 64);
309 -- Long enough string to hold all options from Save call below
311 procedure Save_Style_Check_Options (Options : out Style_Check_Options);
312 -- Sets Options to represent current selection of options. This set can be
313 -- restored by first calling Reset_Style_Check_Options, and then calling
314 -- Set_Style_Check_Options with the Options string.
316 end Stylesw;