OSDN Git Service

2007-08-14 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / stylesw.ads
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-2007, 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 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.                                              --
21 --                                                                          --
22 -- GNAT was originally developed  by the GNAT team at  New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc.      --
24 --                                                                          --
25 ------------------------------------------------------------------------------
26
27 --  This package contains the style switches used for setting style options.
28 --  The only clients of this package are the body of Style and the body of
29 --  Switches. All other style checking issues are handled using the public
30 --  interfaces in the spec of Style.
31
32 with Types; use Types;
33
34 package Stylesw is
35
36    --------------------------
37    -- Style Check Switches --
38    --------------------------
39
40    --  These flags are used to control the details of the style checking
41    --  options. The default values shown here correspond to no style checking.
42
43    --  If any of these values is set to a non-default value, then
44    --  Opt.Style_Check is set True to active calls to this package.
45
46    --  The actual mechanism for setting these switches to other than default
47    --  values is via the Set_Style_Check_Option procedure or through a call to
48    --  Set_Default_Style_Check_Options. They should not be set directly in any
49    --  other manner.
50
51    Style_Check_Array_Attribute_Index : Boolean := False;
52    --  This can be set True by using -gnatg or -gnatyA switches. If it is True
53    --  then index numbers for array attributes (like Length) are required to
54    --  be absent for one-dimensional arrays and present for multi-dimensional
55    --  array attribute references.
56
57    Style_Check_Attribute_Casing : Boolean := False;
58    --  This can be set True by using the -gnatg or -gnatya switches. If it is
59    --  True, then attribute names (including keywords such as digits used as
60    --  attribute names) must be in mixed case.
61
62    Style_Check_Blanks_At_End : Boolean := False;
63    --  This can be set True by using the -gnatg or -gnatyb switches. If it is
64    --  True, then spaces at the end of lines are not permitted.
65
66    Style_Check_Blank_Lines : Boolean := False;
67    --  This can be set True by using the -gnatg or -gnatyu switches. If it is
68    --  True, then multiple blank lines are not permitted, and there may not be
69    --  a blank line at the end of the file.
70
71    Style_Check_Comments : Boolean := False;
72    --  This can be set True by using the -gnatg or -gnatyc switches. If it is
73    --  True, then comments are style checked as follows:
74    --
75    --    All comments must be at the start of the line, or the first minus must
76    --    be preceded by at least one space.
77    --
78    --    For a comment that is not at the start of a line, the only requirement
79    --    is that a space follow the comment characters.
80    --
81    --    For a coment that is at the start of the line, one of the following
82    --    conditions must hold:
83    --
84    --      The comment characters are the only non-blank characters on the line
85    --
86    --      The comment characters are followed by an exclamation point (the
87    --      sequence --! is used by gnatprep for marking deleted lines).
88    --
89    --      The comment characters are followed by two space characters
90    --
91    --      The line consists entirely of minus signs
92    --
93    --      The comment characters are followed by a single space, and the last
94    --      two characters on the line are also comment characters.
95    --
96    --  Note: the reason for the last two conditions is to allow "boxed"
97    --  comments where only a single space separates the comment characters.
98
99    Style_Check_DOS_Line_Terminator : Boolean := False;
100    --  This can be set true by using the -gnatg or -gnatyd switches. If it
101    --  is True, then the line terminator must be a single LF, without an
102    --  associated CR (e.g. DOS line terminator sequence CR/LF not allowed).
103
104    Style_Check_End_Labels : Boolean := False;
105    --  This can be set True by using the -gnatg or -gnatye switches. If it is
106    --  True, then optional END labels must always be present.
107
108    Style_Check_Form_Feeds : Boolean := False;
109    --  This can be set True by using the -gnatg or -gnatyf switches. If it is
110    --  True, then form feeds and vertical tabs are not allowed in the source
111    --  text.
112
113    Style_Check_Horizontal_Tabs : Boolean := False;
114    --  This can be set True by using the -gnatg or -gnatyh switches. If it is
115    --  True, then horizontal tabs are not allowed in source text.
116
117    Style_Check_If_Then_Layout : Boolean := False;
118    --  This can be set True by using the -gnatg or -gnatyi switches. If it is
119    --  True, then a THEN keyword may not appear on the line that immediately
120    --  follows the line containing the corresponding IF.
121    --
122    --  This permits one of two styles for IF-THEN layout. Either the IF and
123    --  THEN keywords are on the same line, where the condition is short enough,
124    --  or the conditions are continued over to the lines following the IF and
125    --  the THEN stands on its own. For example:
126    --
127    --    if X > Y then
128    --
129    --    if X > Y
130    --      and then Y < Z
131    --    then
132    --
133    --  are allowed, but
134    --
135    --    if X > Y
136    --    then
137    --
138    --  is not allowed.
139
140    Style_Check_Indentation : Column_Number range 0 .. 9 := 0;
141    --  This can be set non-zero by using the -gnatg or -gnatyn (n a digit)
142    --  switches. If it is non-zero it activates indentation checking with the
143    --  indicated indentation value. A value of zero turns off checking. The
144    --  requirement is that any new statement, line comment, declaration or
145    --  keyword such as END, start on a column that is a multiple of the
146    --  indentiation value.
147
148    Style_Check_Keyword_Casing : Boolean := False;
149    --  This can be set True by using the -gnatg or -gnatyk switches. If it is
150    --  True, then keywords are required to be in all lower case. This rule does
151    --  not apply to keywords such as digits appearing as an attribute name.
152
153    Style_Check_Layout : Boolean := False;
154    --  This can be set True by using the -gnatg or -gnatyl switches. If it is
155    --  True, it activates checks that constructs are indented as suggested by
156    --  the examples in the RM syntax, e.g. that the ELSE keyword must line up
157    --  with the IF keyword.
158
159    Style_Check_Max_Line_Length : Boolean := False;
160    --  This can be set True by using the -gnatg or -gnatym/M switches. If
161    --  it is True, it activates checking for a maximum line length of
162    --  Style_Max_Line_Length characters.
163
164    Style_Check_Max_Nesting_Level : Boolean := False;
165    --  This can be set True by using -gnatyLnnn with a value other than zero
166    --  (a value of zero resets it to False). If True, it activates checking
167    --  the maximum nesting level against Style_Max_Nesting_Level.
168
169    Style_Check_Mode_In : Boolean := False;
170    --  This can be set True by using -gnatyI. If True, it activates checking
171    --  that mode IN is not used on its own (since it is the default).
172
173    Style_Check_Order_Subprograms : Boolean := False;
174    --  This can be set True by using the -gnatg or -gnatyo switch. If it is
175    --  True, then names of subprogram bodies must be in alphabetical order
176    --  (not taking casing into account).
177
178    Style_Check_Pragma_Casing : Boolean := False;
179    --  This can be set True by using the -gnatg or -gnatyp switches. If it is
180    --  True, then pragma names must use mixed case.
181
182    Style_Check_References : Boolean := False;
183    --  This can be set True by using the -gnatg or -gnatyr switches. If it is
184    --  True, then all references to declared identifiers are checked. The
185    --  requirement is that casing of the reference be the same as the casing
186    --  of the corresponding declaration.
187
188    Style_Check_Separate_Stmt_Lines : Boolean := False;
189    --  This can be set True by using the -gnatg or -gnatyS switches. If it is
190    --  TRUE, then for the case of keywords THEN (not preceded by AND) or ELSE
191    --  (not preceded by OR) which introduce a conditionally executed statement
192    --  sequence, there must be no tokens on the same line as the keyword, so
193    --  that coverage testing can clearly identify execution of the statement
194    --  sequence. A comment is permitted, as is THEN ABORT or a PRAGMA keyword
195    --  after ELSE (a common style to specify the condition for the ELSE).
196
197    Style_Check_Specs : Boolean := False;
198    --  This can be set True by using the -gnatg or -gnatys switches. If it is
199    --  True, then separate specs are required to be present for all procedures
200    --  except parameterless library level procedures. The exception means that
201    --  typical main programs do not require separate specs.
202
203    Style_Check_Standard : Boolean := False;
204    --  This can be set True by using the -gnatg or -gnatyn switches. If it is
205    --  True, then any references to names in Standard have to be in mixed case
206    --  mode (e.g. Integer, Boolean).
207
208    Style_Check_Tokens : Boolean := False;
209    --  This can be set True by using the -gnatg or -gnatyt switches. If it is
210    --  True, then the style check that requires canonical spacing between
211    --  various punctuation tokens as follows:
212    --
213    --    ABS and NOT must be followed by a space
214    --
215    --    => must be surrounded by spaces
216    --
217    --    <> must be preceded by a space or left paren
218    --
219    --    Binary operators other than ** must be surrounded by spaces.
220    --
221    --    There is no restriction on the layout of the ** binary operator.
222    --
223    --    Colon must be surrounded by spaces
224    --
225    --    Colon-equal (assignment) must be surrounded by spaces
226    --
227    --    Comma must be the first non-blank character on the line, or be
228    --    immediately preceded by a non-blank character, and must be followed
229    --    by a blank.
230    --
231    --    A space must precede a left paren following a digit or letter, and a
232    --    right paren must not be followed by a space (it can be at the end of
233    --    the line).
234    --
235    --    A right paren must either be the first non-blank character on a line,
236    --    or it must be preceded by a non-blank character.
237    --
238    --    A semicolon must not be preceded by a blank, and must not be followed
239    --    by a non-blank character.
240    --
241    --    A unary plus or minus may not be followed by a space
242    --
243    --    A vertical bar must be surrounded by spaces
244    --
245    --  Note that a requirement that a token be preceded by a space is met by
246    --  placing the token at the start of the line, and similarly a requirement
247    --  that a token be followed by a space is met by placing the token at
248    --  the end of the line. Note that in the case where horizontal tabs are
249    --  permitted, a horizontal tab is acceptable for meeting the requirement
250    --  for a space.
251
252    Style_Check_Xtra_Parens : Boolean := False;
253    --  This can be set True by using the -gnatg or -gnatyx switch. If true,
254    --  then it is not allowed to enclose entire conditional expressions in
255    --  parentheses (C style).
256
257    Style_Max_Line_Length : Int := 0;
258    --  Value used to check maximum line length. Gets reset as a result of use
259    --  of -gnatym or -gnatyMnnn switches (or by use of -gnatg). This value is
260    --  only read if Style_Check_Max_Line_Length is True.
261
262    Style_Max_Nesting_Level : Int := 0;
263    --  Value used to check maximum nesting level. Gets reset as a result
264    --  of use of the -gnatyLnnn switch. This value is only read if
265    --  Style_Check_Max_Nesting_Level is True.
266
267    -----------------
268    -- Subprograms --
269    -----------------
270
271    procedure Set_Default_Style_Check_Options;
272    --  This procedure is called to set the default style checking options in
273    --  response to a -gnaty switch with no suboptions.
274
275    procedure Set_GNAT_Style_Check_Options;
276    --  This procedure is called to set the default style checking options for
277    --  GNAT units (as set by -gnatg or -gnatyg).
278
279    Style_Msg_Buf : String (1 .. 80);
280    Style_Msg_Len : Natural;
281    --  Used to return
282
283    procedure Set_Style_Check_Options
284      (Options  : String;
285       OK       : out Boolean;
286       Err_Col  : out Natural);
287    --  This procedure is called to set the style check options that correspond
288    --  to the characters in the given Options string. If all options are valid,
289    --  they are set in an additive manner: any previous options are retained
290    --  unless overridden.
291    --
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.
294    --
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.
299
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 appopriate for calls where the string ==
303    --  was obtained by Save_Style_Check_Options.
304
305    procedure Reset_Style_Check_Options;
306    --  Sets all style check options to off
307
308    subtype Style_Check_Options is String (1 .. 64);
309    --  Long enough string to hold all options from Save call below
310
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.
315
316 end Stylesw;