1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, Free Software Foundation, Inc. --
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. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package collects all the routines used for style checking, as
28 -- activated by the relevant command line option. These are gathered in a
29 -- separate package so that they can more easily be customized. Calls to
30 -- these subprograms are only made if Opt.Style_Check is set True.
35 with Types; use Types;
39 package Style_Inst is new Styleg
44 -- Instantiation of Styleg for all subprograms that do not depend directly
45 -- depend on the GNAT tree.
47 package Style_C_Inst is new Style_Inst.C
49 -- Instantiation of Styleg.C for the subprograms that depend directly
52 -- All subroutines below are renames of subroutines in the two
53 -- instantiations above.
55 procedure Body_With_No_Spec (N : Node_Id)
56 renames Style_C_Inst.Body_With_No_Spec;
57 -- Called where N is a subprogram body node for a subprogram body
58 -- for which no spec was given, i.e. a body acting as its own spec.
60 procedure Check_Abs_Not
61 renames Style_Inst.Check_Abs_Not;
62 -- Called after scanning an ABS or NOT operator to check spacing
64 procedure Check_Apostrophe
65 renames Style_Inst.Check_Apostrophe;
66 -- Called after scanning an apostrophe to check spacing
68 procedure Check_Array_Attribute_Index
72 renames Style_C_Inst.Check_Array_Attribute_Index;
73 -- Called for an array attribute specifying an index number. N is the
74 -- node for the attribute, and E1 is the index expression (Empty if none
75 -- present). If E1 is present, it is known to be a static integer. D is
76 -- the number of dimensions of the array.
79 renames Style_Inst.Check_Arrow;
80 -- Called after scanning out an arrow to check spacing
82 procedure Check_Attribute_Name (Reserved : Boolean)
83 renames Style_Inst.Check_Attribute_Name;
84 -- The current token is an attribute designator. Check that it is
85 -- capitalized in an appropriate manner. Reserved is set if the attribute
86 -- designator is a reserved word (access, digits, delta or range) to allow
87 -- differing rules for the two cases.
90 renames Style_Inst.Check_Box;
91 -- Called after scanning out a box to check spacing
93 procedure Check_Binary_Operator
94 renames Style_Inst.Check_Binary_Operator;
95 -- Called after scanning out a binary operator other than a plus, minus
96 -- or exponentiation operator. Intended for checking spacing rules.
98 procedure Check_Exponentiation_Operator
99 renames Style_Inst.Check_Exponentiation_Operator;
100 -- Called after scanning out an exponentiation operator. Intended for
101 -- checking spacing rules.
103 procedure Check_Colon
104 renames Style_Inst.Check_Colon;
105 -- Called after scanning out colon to check spacing
107 procedure Check_Colon_Equal
108 renames Style_Inst.Check_Colon_Equal;
109 -- Called after scanning out colon equal to check spacing
111 procedure Check_Comma
112 renames Style_Inst.Check_Comma;
113 -- Called after scanning out comma to check spacing
115 procedure Check_Comment
116 renames Style_Inst.Check_Comment;
117 -- Called with Scan_Ptr pointing to the first minus sign of a comment.
118 -- Intended for checking any specific rules for comment placement/format.
120 procedure Check_Dot_Dot
121 renames Style_Inst.Check_Dot_Dot;
122 -- Called after scanning out dot dot to check spacing
125 renames Style_Inst.Check_EOF;
126 -- Called after scanning out end of file mark
129 renames Style_Inst.Check_HT;
130 -- Called with Scan_Ptr pointing to a horizontal tab character
132 procedure Check_Identifier
133 (Ref : Node_Or_Entity_Id;
134 Def : Node_Or_Entity_Id)
135 renames Style_C_Inst.Check_Identifier;
136 -- Check style of identifier occurrence. Ref is an N_Identifier node whose
137 -- spelling is to be checked against the Chars spelling in identifier node
138 -- Def (which may be either an N_Identifier, or N_Defining_Identifier node)
140 procedure Check_Indentation
141 renames Style_Inst.Check_Indentation;
142 -- Called at the start of a new statement or declaration, with Token_Ptr
143 -- pointing to the first token of the statement or declaration. The check
144 -- is that the starting column is appropriate to the indentation rules if
145 -- Token_Ptr is the first token on the line.
147 procedure Check_Left_Paren
148 renames Style_Inst.Check_Left_Paren;
149 -- Called after scanning out a left parenthesis to check spacing
151 procedure Check_Line_Terminator (Len : Int)
152 renames Style_Inst.Check_Line_Terminator;
153 -- Called with Scan_Ptr pointing to the first line terminator terminating
154 -- the current line, used to check for appropriate line terminator and to
155 -- check the line length (Len is the length of the current line). Note that
156 -- the terminator may be the EOF character.
158 procedure Check_Pragma_Name
159 renames Style_Inst.Check_Pragma_Name;
160 -- The current token is a pragma identifier. Check that it is spelled
161 -- properly (i.e. with an appropriate casing convention).
163 procedure Check_Right_Paren
164 renames Style_Inst.Check_Right_Paren;
165 -- Called after scanning out a right parenthesis to check spacing
167 procedure Check_Semicolon
168 renames Style_Inst.Check_Semicolon;
169 -- Called after scanning out a semicolon to check spacing
171 procedure Check_Then (If_Loc : Source_Ptr)
172 renames Style_Inst.Check_Then;
173 -- Called to check that THEN and IF keywords are appropriately positioned.
174 -- The parameters show the first characters of the two keywords. This
175 -- procedure is called only if THEN appears at the start of a line with
176 -- Token_Ptr pointing to the THEN keyword.
178 procedure Check_Unary_Plus_Or_Minus
179 renames Style_Inst.Check_Unary_Plus_Or_Minus;
180 -- Called after scanning a unary plus or minus to check spacing
182 procedure Check_Vertical_Bar
183 renames Style_Inst.Check_Vertical_Bar;
184 -- Called after scanning a vertical bar to check spacing
186 procedure Check_Xtra_Parens (Loc : Source_Ptr)
187 renames Style_Inst.Check_Xtra_Parens;
188 -- Called after scanning a conditional expression that has at least one
189 -- level of parentheses around the entire expression.
191 function Mode_In_Check return Boolean
192 renames Style_Inst.Mode_In_Check;
193 -- Determines whether style checking is active and the Mode_In_Check is
194 -- set, forbidding the explicit use of mode IN.
196 procedure No_End_Name (Name : Node_Id)
197 renames Style_Inst.No_End_Name;
198 -- Called if an END is encountered where a name is allowed but not present.
199 -- The parameter is the node whose name is the name that is permitted in
200 -- the END line, and the scan pointer is positioned so that if an error
201 -- message is to be generated in this situation, it should be generated
202 -- using Error_Msg_SP.
204 procedure No_Exit_Name (Name : Node_Id)
205 renames Style_Inst.No_Exit_Name;
206 -- Called when exiting a named loop, but a name is not present on the EXIT.
207 -- The parameter is the node whose name should have followed EXIT, and the
208 -- scan pointer is positioned so that if an error message is to be
209 -- generated, it should be generated using Error_Msg_SP.
211 procedure Non_Lower_Case_Keyword
212 renames Style_Inst.Non_Lower_Case_Keyword;
213 -- Called if a reserved keyword is scanned which is not spelled in all
214 -- lower case letters. On entry Token_Ptr points to the keyword token.
215 -- This is not used for keywords appearing as attribute designators,
216 -- where instead Check_Attribute_Name (True) is called.
218 function RM_Column_Check return Boolean
219 renames Style_Inst.RM_Column_Check;
220 -- Determines whether style checking is active and the RM column check
221 -- mode is set requiring checking of RM format layout.
223 procedure Subprogram_Not_In_Alpha_Order (Name : Node_Id)
224 renames Style_C_Inst.Subprogram_Not_In_Alpha_Order;
225 -- Called if Name is the name of a subprogram body in a package body
226 -- that is not in alphabetical order.