OSDN Git Service

2007-04-20 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-2006, 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
42    --  checking. If any of these values is set to a non-default value,
43    --  then Opt.Style_Check is set True to active calls to this package.
44
45    --  The actual mechanism for setting these switches to other than
46    --  default values is via the Set_Style_Check_Option procedure or
47    --  through a call to Set_Default_Style_Check_Options. They should
48    --  not be set directly in any other manner.
49
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.
55
56    Style_Check_Attribute_Casing : Boolean := False;
57    --  This can be set True by using the -gnatg or -gnatya switches. If
58    --  it is True, then attribute names (including keywords such as
59    --  digits used as attribute names) must be in mixed case.
60
61    Style_Check_Blanks_At_End : Boolean := False;
62    --  This can be set True by using the -gnatg or -gnatyb switches. If
63    --  it is True, then spaces at the end of lines are not permitted.
64
65    Style_Check_Blank_Lines : Boolean := False;
66    --  This can be set True by using the -gnatg or -gnatyu switches. If
67    --  it is True, then multiple blank lines are not permitted, and there
68    --  may not be a blank line at the end of the file.
69
70    Style_Check_Comments : Boolean := False;
71    --  This can be set True by using the -gnatg or -gnatyc switches. If
72    --  it is True, then comments are style checked as follows:
73    --
74    --    All comments must be at the start of the line, or the first
75    --    minus must be preceded by at least one space.
76    --
77    --    For a comment that is not at the start of a line, the only
78    --    requirement is that a space follow the comment characters.
79    --
80    --    For a coment that is at the start of the line, one of the
81    --    following conditions must hold:
82    --
83    --      The comment characters are the only non-blank characters on the line
84    --
85    --      The comment characters are followed by an exclamation point (the
86    --      sequence --! is used by gnatprep for marking deleted lines).
87    --
88    --      The comment characters are followed by two space characters
89    --
90    --      The line consists entirely of minus signs
91    --
92    --      The comment characters are followed by a single space, and the
93    --      last two characters on the line are also comment characters.
94    --
95    --  Note: the reason for the last two conditions is to allow "boxed"
96    --  comments where only a single space separates the comment characters.
97
98    Style_Check_DOS_Line_Terminator : Boolean := False;
99    --  This can be set true by using the -gnatg or -gnatyd switches. If
100    --  it 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).
102
103    Style_Check_End_Labels : Boolean := False;
104    --  This can be set True by using the -gnatg or -gnatye switches. If
105    --  it is True, then optional END labels must always be present.
106
107    Style_Check_Form_Feeds : Boolean := False;
108    --  This can be set True by using the -gnatg or -gnatyf switches. If
109    --  it is True, then form feeds and vertical tabs are not allowed in
110    --  the source text.
111
112    Style_Check_Horizontal_Tabs : Boolean := False;
113    --  This can be set True by using the -gnatg or -gnatyh switches. If
114    --  it is True, then horizontal tabs are not allowed in source text.
115
116    Style_Check_If_Then_Layout : Boolean := False;
117    --  This can be set True by using the -gnatg or -gnatyi switches. If
118    --  it is True, then a THEN keyword may not appear on the line that
119    --  immediately follows the line containing the corresponding IF.
120    --
121    --  This permits one of two styles for IF-THEN layout. Either the
122    --  IF and THEN keywords are on the same line, where the condition
123    --  is short enough, or the conditions are continued over to the
124    --  lines following the IF and the THEN stands on its own. For
125    --  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
143    --  the indicated indentation value. A value of zero turns off checking.
144    --  The requirement is that any new statement, line comment, declaration
145    --  or 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
150    --  it is True, then keywords are required to be in all lower case.
151    --  This rule does not apply to keywords such as digits appearing as
152    --  an attribute name.
153
154    Style_Check_Max_Line_Length : Boolean := False;
155    --  This can be set True by using the -gnatg or -gnatym/M switches.
156    --  If it is True, it activates checking for a maximum line length of
157    --  Style_Max_Line_Length characters.
158
159    Style_Check_Max_Nesting_Level : Boolean := False;
160    --  This can be set True by using -gnatyLnnn with a value other than
161    --  zero (a value of zero resets it to False). If True, it activates
162    --  checking the maximum nesting level against Style_Max_Nesting_Level.
163
164    Style_Check_Mode_In : Boolean := False;
165    --  This can be set True by using -gnatyI. If True, it activates checking
166    --  that mode IN is not used on its own (since it is the default).
167
168    Style_Check_Order_Subprograms : Boolean := False;
169    --  This can be set True by using the -gnatg or -gnatyo switch. If it
170    --  is True, then names of subprogram bodies must be in alphabetical
171    --  order (not taking casing into account).
172
173    Style_Check_Pragma_Casing : Boolean := False;
174    --  This can be set True by using the -gnatg or -gnatyp switches. If
175    --  it is True, then pragma names must use mixed case.
176
177    Style_Check_Layout : Boolean := False;
178    --  This can be set True by using the -gnatg or -gnatyl switches. If
179    --  it is True, it activates checks that constructs are indented as
180    --  suggested by the examples in the RM syntax, e.g. that the ELSE
181    --  keyword must line up with the IF keyword.
182
183    Style_Check_References : Boolean := False;
184    --  This can be set True by using the -gnatg or -gnatyr switches. If
185    --  it is True, then all references to declared identifiers are
186    --  checked. The requirement is that casing of the reference be the
187    --  same as the casing of the corresponding declaration.
188
189    Style_Check_Specs : Boolean := False;
190    --  This can be set True by using the -gnatg or -gnatys switches. If
191    --  it is True, then separate specs are required to be present for
192    --  all procedures except parameterless library level procedures.
193    --  The exception means that typical main programs do not require
194    --  separate specs.
195
196    Style_Check_Standard : Boolean := False;
197    --  This can be set True by using the -gnatg or -gnatyn switches. If
198    --  it is True, then any references to names in Standard have to be
199    --  in mixed case mode (e.g. Integer, Boolean).
200
201    Style_Check_Tokens : Boolean := False;
202    --  This can be set True by using the -gnatg or -gnatyt switches. If
203    --  it is True, then the style check that requires canonical spacing
204    --  between various punctuation tokens as follows:
205    --
206    --    ABS and NOT must be followed by a space
207    --
208    --    => must be surrounded by spaces
209    --
210    --    <> must be preceded by a space or left paren
211    --
212    --    Binary operators other than ** must be surrounded by spaces.
213    --    There is no restriction on the layout of the ** binary operator.
214    --
215    --    Colon must be surrounded by spaces
216    --
217    --    Colon-equal (assignment) must be surrounded by spaces
218    --
219    --    Comma must be the first non-blank character on the line, or be
220    --    immediately preceded by a non-blank character, and must be followed
221    --    by a blank.
222    --
223    --    A space must precede a left paren following a digit or letter,
224    --    and a right paren must not be followed by a space (it can be
225    --    at the end of the line).
226    --
227    --    A right paren must either be the first non-blank character on
228    --    a line, or it must be preceded by a non-blank character.
229    --
230    --    A semicolon must not be preceded by a blank, and must not be
231    --    followed by a non-blank character.
232    --
233    --    A unary plus or minus may not be followed by a space
234    --
235    --    A vertical bar must be surrounded by spaces
236    --
237    --  Note that a requirement that a token be preceded by a space is
238    --  met by placing the token at the start of the line, and similarly
239    --  a requirement that a token be followed by a space is met by
240    --  placing the token at the end of the line. Note that in the case
241    --  where horizontal tabs are permitted, a horizontal tab is acceptable
242    --  for meeting the requirement for a space.
243
244    Style_Check_Xtra_Parens : Boolean := False;
245    --  This can be set True by using the -gnatg or -gnatyx switch. If true,
246    --  then it is not allowed to enclose entire conditional expressions
247    --  in parentheses (C style).
248
249    Style_Max_Line_Length : Int := 0;
250    --  Value used to check maximum line length. Gets reset as a result of
251    --  use of -gnatym or -gnatyMnnn switches (or by use of -gnatg). This
252    --  value is only read if Style_Check_Max_Line_Length is True.
253
254    Style_Max_Nesting_Level : Int := 0;
255    --  Value used to check maximum nesting level. Gets reset as a result
256    --  of use of the -gnatyLnnn switch. This value is only read if
257    --  Style_Check_Max_Nesting_Level is True.
258
259    -----------------
260    -- Subprograms --
261    -----------------
262
263    procedure Set_Default_Style_Check_Options;
264    --  This procedure is called to set the default style checking options
265    --  in response to a -gnaty switch with no suboptions.
266
267    procedure Set_GNAT_Style_Check_Options;
268    --  This procedure is called to set the default style checking options
269    --  for GNAT units (as set by -gnatg or -gnatyg).
270
271    Style_Msg_Buf : String (1 .. 80);
272    Style_Msg_Len : Natural;
273    --  Used to return
274
275    procedure Set_Style_Check_Options
276      (Options  : String;
277       OK       : out Boolean;
278       Err_Col  : out Natural);
279    --  This procedure is called to set the style check options that correspond
280    --  to the characters in the given Options string. If all options are valid,
281    --  they are set in an additive manner: any previous options are retained
282    --  unless overridden.
283    --
284    --  If all options given are valid, then OK is True, Err_Col is set to
285    --  Options'Last + 1, and Style_Msg_Buf/Style_Msg_Len are unchanged.
286    --
287    --  If an invalid character is found, then OK is False on exit, and Err_Col
288    --  is the index in options of the bad character. In this case Style_Msg_Len
289    --  is set and Style_Msg_Buf (1 .. Style_Msg_Len) has a detailed message
290    --  describing the error.
291
292    procedure Set_Style_Check_Options (Options : String);
293    --  Like the above procedure, but used when the Options string is known to
294    --  be valid. This is for example appopriate for calls where the string ==
295    --  was obtained by Save_Style_Check_Options.
296
297    procedure Reset_Style_Check_Options;
298    --  Sets all style check options to off
299
300    subtype Style_Check_Options is String (1 .. 64);
301    --  Long enough string to hold all options from Save call below
302
303    procedure Save_Style_Check_Options (Options : out Style_Check_Options);
304    --  Sets Options to represent current selection of options. This
305    --  set can be restored by first calling Reset_Style_Check_Options,
306    --  and then calling Set_Style_Check_Options with the Options string.
307
308 end Stylesw;