]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/ada/stylesw.ads
[Ada] Bump copyright year
[thirdparty/gcc.git] / gcc / ada / stylesw.ads
CommitLineData
996ae0b0
RK
1------------------------------------------------------------------------------
2-- --
3-- GNAT COMPILER COMPONENTS --
4-- --
5-- S T Y L E S W --
6-- --
7-- S p e c --
8-- --
4b490c1e 9-- Copyright (C) 1992-2020, Free Software Foundation, Inc. --
996ae0b0
RK
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- --
b5c84c3c 13-- ware Foundation; either version 3, or (at your option) any later ver- --
996ae0b0
RK
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 --
b5c84c3c
RD
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. --
996ae0b0
RK
20-- --
21-- GNAT was originally developed by the GNAT team at New York University. --
71ff80dc 22-- Extensive contributions were provided by Ada Core Technologies Inc. --
996ae0b0
RK
23-- --
24------------------------------------------------------------------------------
25
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.
30
31with Types; use Types;
32
33package Stylesw is
34
35 --------------------------
36 -- Style Check Switches --
37 --------------------------
38
39 -- These flags are used to control the details of the style checking
835d23b2 40 -- options. The default values shown here correspond to no style checking.
996ae0b0 41
835d23b2 42 -- If any of these values is set to a non-default value, then
90878b12 43 -- Opt.Style_Check is set True to activate calls to this package.
835d23b2
RD
44
45 -- The actual mechanism for setting these switches to other than default
90878b12 46 -- values is via the Set_Style_Check_Options procedure or through a call to
835d23b2
RD
47 -- Set_Default_Style_Check_Options. They should not be set directly in any
48 -- other manner.
996ae0b0 49
a9a5b8ac 50 Style_Check_Array_Attribute_Index : Boolean := False;
5a1ccfb1
AC
51 -- This can be set True by using the -gnatyA switch. If it is True then
52 -- index numbers for array attributes (like Length) are required to be
53 -- absent for one-dimensional arrays and present for multi-dimensional
a9a5b8ac
RD
54 -- array attribute references.
55
996ae0b0 56 Style_Check_Attribute_Casing : Boolean := False;
5a1ccfb1
AC
57 -- This can be set True by using the -gnatya switch. If it is True, then
58 -- attribute names (including keywords such as digits used as attribute
59 -- names) must be in mixed case.
996ae0b0
RK
60
61 Style_Check_Blanks_At_End : Boolean := False;
5a1ccfb1
AC
62 -- This can be set True by using the -gnatyb switch. If it is True, then
63 -- spaces at the end of lines are not permitted.
996ae0b0 64
357ac4df 65 Style_Check_Blank_Lines : Boolean := False;
5a1ccfb1
AC
66 -- This can be set True by using the -gnatyu switch. If it is True, then
67 -- multiple blank lines are not permitted, and there may not be a blank
68 -- line at the end of the file.
357ac4df 69
a36c1c3e
RD
70 Style_Check_Boolean_And_Or : Boolean := False;
71 -- This can be set True by using the -gnatyB switch. If it is True, then
72 -- the use of AND THEN/OR ELSE rather than AND/OR is required except for
73 -- the following cases:
74 --
75 -- a) Both operands are simple Boolean constants or variables
76 -- b) Both operands are of a modular type
77 -- c) Both operands are of an array type
78
996ae0b0 79 Style_Check_Comments : Boolean := False;
5a1ccfb1
AC
80 -- This can be set True by using the -gnatyc switch. If it is True, then
81 -- comments are style checked as follows:
996ae0b0 82 --
835d23b2
RD
83 -- All comments must be at the start of the line, or the first minus must
84 -- be preceded by at least one space.
996ae0b0 85 --
835d23b2
RD
86 -- For a comment that is not at the start of a line, the only requirement
87 -- is that a space follow the comment characters.
996ae0b0 88 --
3354f96d 89 -- For a comment that is at the start of the line, one of the following
835d23b2 90 -- conditions must hold:
996ae0b0
RK
91 --
92 -- The comment characters are the only non-blank characters on the line
93 --
94 -- The comment characters are followed by an exclamation point (the
95 -- sequence --! is used by gnatprep for marking deleted lines).
96 --
a2773bd3
AC
97 -- The comment characters are followed by two space characters if
98 -- Comment_Spacing = 2, else by one character if Comment_Spacing = 1.
996ae0b0
RK
99 --
100 -- The line consists entirely of minus signs
101 --
835d23b2
RD
102 -- The comment characters are followed by a single space, and the last
103 -- two characters on the line are also comment characters.
996ae0b0
RK
104 --
105 -- Note: the reason for the last two conditions is to allow "boxed"
106 -- comments where only a single space separates the comment characters.
107
a2773bd3
AC
108 Style_Check_Comments_Spacing : Nat range 1 .. 2;
109 -- Spacing required for comments, valid only if Style_Check_Comments true.
110
debe0ab6 111 Style_Check_DOS_Line_Terminator : Boolean := False;
5a1ccfb1
AC
112 -- This can be set true by using the -gnatyd switch. If it is True, then
113 -- the line terminator must be a single LF, without an associated CR (e.g.
114 -- DOS line terminator sequence CR/LF not allowed).
debe0ab6 115
c4487c3b
BD
116 Style_Check_Mixed_Case_Decls : Boolean := False;
117 -- This can be set True by using the -gnatyD switch. If it is True, then
118 -- declared identifiers must be in Mixed_Case.
119
996ae0b0 120 Style_Check_End_Labels : Boolean := False;
5a1ccfb1
AC
121 -- This can be set True by using the -gnatye switch. If it is True, then
122 -- optional END labels must always be present.
996ae0b0
RK
123
124 Style_Check_Form_Feeds : Boolean := False;
5a1ccfb1
AC
125 -- This can be set True by using the -gnatyf switch. If it is True, then
126 -- form feeds and vertical tabs are not allowed in the source text.
996ae0b0
RK
127
128 Style_Check_Horizontal_Tabs : Boolean := False;
5a1ccfb1
AC
129 -- This can be set True by using the -gnatyh switch. If it is True, then
130 -- horizontal tabs are not allowed in source text.
996ae0b0
RK
131
132 Style_Check_If_Then_Layout : Boolean := False;
5a1ccfb1 133 -- This can be set True by using the -gnatyi switch. If it is True, then a
0b7f0f0e
AC
134 -- THEN keyword must either appear on the same line as the IF, or on a line
135 -- all on its own.
996ae0b0 136 --
835d23b2
RD
137 -- This permits one of two styles for IF-THEN layout. Either the IF and
138 -- THEN keywords are on the same line, where the condition is short enough,
139 -- or the conditions are continued over to the lines following the IF and
140 -- the THEN stands on its own. For example:
996ae0b0
RK
141 --
142 -- if X > Y then
143 --
144 -- if X > Y
145 -- and then Y < Z
146 -- then
147 --
0b7f0f0e
AC
148 -- if X > Y and then Z > 0
149 -- then
150 --
996ae0b0
RK
151 -- are allowed, but
152 --
153 -- if X > Y
0b7f0f0e 154 -- and then B > C then
996ae0b0
RK
155 --
156 -- is not allowed.
157
158 Style_Check_Indentation : Column_Number range 0 .. 9 := 0;
54bb89ca 159 -- This can be set non-zero by using the -gnaty? (? a digit) switch. If
5a1ccfb1
AC
160 -- it is non-zero it activates indentation checking with the indicated
161 -- indentation value. A value of zero turns off checking. The requirement
162 -- is that any new statement, line comment, declaration or keyword such
163 -- as END, start on a column that is a multiple of the indentation value.
996ae0b0
RK
164
165 Style_Check_Keyword_Casing : Boolean := False;
5a1ccfb1
AC
166 -- This can be set True by using the -gnatyk switch. If it is True, then
167 -- keywords are required to be in all lower case. This rule does not apply
168 -- to keywords such as digits appearing as an attribute name.
835d23b2
RD
169
170 Style_Check_Layout : Boolean := False;
5a1ccfb1
AC
171 -- This can be set True by using the -gnatyl switch. If it is True, it
172 -- activates checks that constructs are indented as suggested by the
173 -- examples in the RM syntax, e.g. that the ELSE keyword must line up
835d23b2 174 -- with the IF keyword.
996ae0b0
RK
175
176 Style_Check_Max_Line_Length : Boolean := False;
5a1ccfb1
AC
177 -- This can be set True by using the -gnatym/M switches. If it is True, it
178 -- activates checking for a maximum line length of Style_Max_Line_Length
179 -- characters.
996ae0b0 180
0da2c8ac 181 Style_Check_Max_Nesting_Level : Boolean := False;
835d23b2
RD
182 -- This can be set True by using -gnatyLnnn with a value other than zero
183 -- (a value of zero resets it to False). If True, it activates checking
184 -- the maximum nesting level against Style_Max_Nesting_Level.
0da2c8ac 185
235f4375
AC
186 Style_Check_Missing_Overriding : Boolean := False;
187 -- This can be set True by using the -gnatyO switch. If it is True, then
273adcdf
AC
188 -- "overriding" is required in subprogram declarations and bodies where
189 -- appropriate. Note that "not overriding" is never required.
235f4375 190
4f73f89c
RD
191 Style_Check_Mode_In : Boolean := False;
192 -- This can be set True by using -gnatyI. If True, it activates checking
193 -- that mode IN is not used on its own (since it is the default).
194
bc202b70 195 Style_Check_Order_Subprograms : Boolean := False;
5a1ccfb1
AC
196 -- This can be set True by using the -gnatyo switch. If it is True, then
197 -- names of subprogram bodies must be in alphabetical order (not taking
198 -- casing into account).
bc202b70 199
996ae0b0 200 Style_Check_Pragma_Casing : Boolean := False;
5a1ccfb1
AC
201 -- This can be set True by using the -gnatyp switch. If it is True, then
202 -- pragma names must use mixed case.
996ae0b0
RK
203
204 Style_Check_References : Boolean := False;
5a1ccfb1
AC
205 -- This can be set True by using the -gnatyr switch. If it is True, then
206 -- all references to declared identifiers are checked. The requirement
207 -- is that casing of the reference be the same as the casing of the
208 -- corresponding declaration.
835d23b2
RD
209
210 Style_Check_Separate_Stmt_Lines : Boolean := False;
5a1ccfb1
AC
211 -- This can be set True by using the -gnatyS switch. If it is TRUE,
212 -- then for the case of keywords THEN (not preceded by AND) or ELSE (not
213 -- preceded by OR) which introduce a conditionally executed statement
835d23b2
RD
214 -- sequence, there must be no tokens on the same line as the keyword, so
215 -- that coverage testing can clearly identify execution of the statement
216 -- sequence. A comment is permitted, as is THEN ABORT or a PRAGMA keyword
217 -- after ELSE (a common style to specify the condition for the ELSE).
996ae0b0
RK
218
219 Style_Check_Specs : Boolean := False;
5a1ccfb1
AC
220 -- This can be set True by using the -gnatys switches. If it is True, then
221 -- separate specs are required to be present for all procedures except
222 -- parameterless library level procedures. The exception means that typical
223 -- main programs do not require separate specs.
996ae0b0
RK
224
225 Style_Check_Standard : Boolean := False;
5a1ccfb1 226 -- This can be set True by using the -gnatyn switch. If it is True, then
54bb89ca
AC
227 -- any references to names in Standard have to be cased in a manner that
228 -- is consistent with the Ada RM (usually Mixed case, as in Long_Integer)
229 -- but there are some exceptions (e.g. NUL, ASCII).
996ae0b0
RK
230
231 Style_Check_Tokens : Boolean := False;
5a1ccfb1
AC
232 -- This can be set True by using the -gnatyt switch. If it is True, then
233 -- the style check that requires canonical spacing between various
234 -- punctuation tokens as follows:
996ae0b0
RK
235 --
236 -- ABS and NOT must be followed by a space
237 --
238 -- => must be surrounded by spaces
239 --
240 -- <> must be preceded by a space or left paren
241 --
242 -- Binary operators other than ** must be surrounded by spaces.
835d23b2 243 --
996ae0b0
RK
244 -- There is no restriction on the layout of the ** binary operator.
245 --
246 -- Colon must be surrounded by spaces
247 --
248 -- Colon-equal (assignment) must be surrounded by spaces
249 --
250 -- Comma must be the first non-blank character on the line, or be
251 -- immediately preceded by a non-blank character, and must be followed
252 -- by a blank.
253 --
835d23b2
RD
254 -- A space must precede a left paren following a digit or letter, and a
255 -- right paren must not be followed by a space (it can be at the end of
256 -- the line).
996ae0b0 257 --
835d23b2
RD
258 -- A right paren must either be the first non-blank character on a line,
259 -- or it must be preceded by a non-blank character.
996ae0b0 260 --
835d23b2
RD
261 -- A semicolon must not be preceded by a blank, and must not be followed
262 -- by a non-blank character.
996ae0b0
RK
263 --
264 -- A unary plus or minus may not be followed by a space
265 --
9a6dc470
RD
266 -- There must be one blank (and no other white space) between NOT and IN
267 --
996ae0b0
RK
268 -- A vertical bar must be surrounded by spaces
269 --
835d23b2
RD
270 -- Note that a requirement that a token be preceded by a space is met by
271 -- placing the token at the start of the line, and similarly a requirement
272 -- that a token be followed by a space is met by placing the token at
273 -- the end of the line. Note that in the case where horizontal tabs are
274 -- permitted, a horizontal tab is acceptable for meeting the requirement
275 -- for a space.
996ae0b0 276
bc202b70 277 Style_Check_Xtra_Parens : Boolean := False;
5a1ccfb1 278 -- This can be set True by using the -gnatyx switch. If true, then it is
9b16cb57
RD
279 -- not allowed to enclose entire expressions in tests in parentheses
280 -- (C style), e.g. if (x = y) then ... is not allowed.
996ae0b0 281
16e764a7 282 Style_Max_Line_Length : Nat := 0;
5a1ccfb1
AC
283 -- Value used to check maximum line length. Gets reset as a result of
284 -- use of -gnatym or -gnatyMnnn switches. This value is only read if
285 -- Style_Check_Max_Line_Length is True.
0da2c8ac 286
16e764a7 287 Style_Max_Nesting_Level : Nat := 0;
0da2c8ac
AC
288 -- Value used to check maximum nesting level. Gets reset as a result
289 -- of use of the -gnatyLnnn switch. This value is only read if
290 -- Style_Check_Max_Nesting_Level is True.
996ae0b0
RK
291
292 -----------------
293 -- Subprograms --
294 -----------------
295
c75c4293
AC
296 function RM_Column_Check return Boolean;
297 -- Determines whether style checking is active and the RM column check
298 -- mode is set requiring checking of RM format layout.
299
996ae0b0 300 procedure Set_Default_Style_Check_Options;
835d23b2 301 -- This procedure is called to set the default style checking options in
30179374 302 -- response to a -gnaty switch with no suboptions or from -gnatyy.
996ae0b0 303
94a198aa 304 procedure Set_GNAT_Style_Check_Options;
835d23b2
RD
305 -- This procedure is called to set the default style checking options for
306 -- GNAT units (as set by -gnatg or -gnatyg).
94a198aa 307
23d0d17f
TQ
308 Style_Msg_Buf : String (1 .. 80);
309 Style_Msg_Len : Natural;
310 -- Used to return
311
996ae0b0
RK
312 procedure Set_Style_Check_Options
313 (Options : String;
314 OK : out Boolean;
315 Err_Col : out Natural);
23d0d17f
TQ
316 -- This procedure is called to set the style check options that correspond
317 -- to the characters in the given Options string. If all options are valid,
318 -- they are set in an additive manner: any previous options are retained
30179374
RD
319 -- unless overridden, unless a minus is encountered, and then subsequent
320 -- style switches are subtracted from the current set.
23d0d17f
TQ
321 --
322 -- If all options given are valid, then OK is True, Err_Col is set to
323 -- Options'Last + 1, and Style_Msg_Buf/Style_Msg_Len are unchanged.
324 --
325 -- If an invalid character is found, then OK is False on exit, and Err_Col
326 -- is the index in options of the bad character. In this case Style_Msg_Len
327 -- is set and Style_Msg_Buf (1 .. Style_Msg_Len) has a detailed message
328 -- describing the error.
996ae0b0
RK
329
330 procedure Set_Style_Check_Options (Options : String);
23d0d17f 331 -- Like the above procedure, but used when the Options string is known to
90878b12
AC
332 -- be valid. This is for example appropriate for calls where the string was
333 -- obtained by Save_Style_Check_Options.
996ae0b0
RK
334
335 procedure Reset_Style_Check_Options;
336 -- Sets all style check options to off
337
0da2c8ac 338 subtype Style_Check_Options is String (1 .. 64);
996ae0b0
RK
339 -- Long enough string to hold all options from Save call below
340
341 procedure Save_Style_Check_Options (Options : out Style_Check_Options);
835d23b2
RD
342 -- Sets Options to represent current selection of options. This set can be
343 -- restored by first calling Reset_Style_Check_Options, and then calling
344 -- Set_Style_Check_Options with the Options string.
996ae0b0
RK
345
346end Stylesw;