| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- S T Y L E G -- |
| 6 |
-- -- |
| 7 |
-- S p e c -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1992-2025, 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 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
-- This generic package collects the routines used for style checking, as |
| 27 |
-- activated by the relevant command line option. These are gathered in |
| 28 |
-- a separate package so that they can more easily be customized. Calls |
| 29 |
-- to these subprograms are only made if Opt.Style_Check is set True. |
| 30 |
-- Styleg does not depends on the GNAT tree (Atree, Sinfo, ...). |
| 31 |
|
| 32 |
with Types; use Types; |
| 33 |
|
| 34 |
generic |
| 35 |
with procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr); |
| 36 |
-- Output a message at specified location |
| 37 |
|
| 38 |
with procedure Error_Msg_S (Msg : String); |
| 39 |
-- Output a message at current scan pointer location |
| 40 |
|
| 41 |
with procedure Error_Msg_SC (Msg : String); |
| 42 |
-- Output a message at the start of the current token |
| 43 |
|
| 44 |
with procedure Error_Msg_SP (Msg : String); |
| 45 |
-- Output a message at the start of the previous token |
| 46 |
|
| 47 |
package Styleg is |
| 48 |
|
| 49 |
procedure Check_Abs_Not; |
| 50 |
-- Called after scanning an ABS or NOT operator to check spacing |
| 51 |
|
| 52 |
procedure Check_Apostrophe; |
| 53 |
-- Called after scanning an apostrophe to check spacing |
| 54 |
|
| 55 |
procedure Check_Arrow (Inside_Depends : Boolean := False); |
| 56 |
-- Called after scanning out an arrow to check spacing. Inside_Depends is |
| 57 |
-- True if the call is from an argument of the Depends or Refined_Depends |
| 58 |
-- aspect or pragma (where the allowed/required format is =>+). |
| 59 |
|
| 60 |
procedure Check_Attribute_Name (Reserved : Boolean); |
| 61 |
-- The current token is an attribute designator. Check that it |
| 62 |
-- is capitalized in an appropriate manner. Reserved is set if |
| 63 |
-- the attribute designator is a reserved word (access, digits, |
| 64 |
-- delta or range) to allow differing rules for the two cases. |
| 65 |
|
| 66 |
procedure Check_Box; |
| 67 |
-- Called after scanning out a box to check spacing |
| 68 |
|
| 69 |
procedure Check_Binary_Operator; |
| 70 |
-- Called after scanning out a binary operator other than a plus, minus |
| 71 |
-- or exponentiation operator. Intended for checking spacing rules. |
| 72 |
|
| 73 |
procedure Check_Exponentiation_Operator; |
| 74 |
-- Called after scanning out an exponentiation operator. Intended for |
| 75 |
-- checking spacing rules. |
| 76 |
|
| 77 |
procedure Check_Colon; |
| 78 |
-- Called after scanning out colon to check spacing |
| 79 |
|
| 80 |
procedure Check_Colon_Equal; |
| 81 |
-- Called after scanning out colon equal to check spacing |
| 82 |
|
| 83 |
procedure Check_Comma; |
| 84 |
-- Called after scanning out comma to check spacing |
| 85 |
|
| 86 |
procedure Check_Comment; |
| 87 |
-- Called with Scan_Ptr pointing to the first minus sign of a comment. |
| 88 |
-- Intended for checking any specific rules for comment placement/format. |
| 89 |
|
| 90 |
procedure Check_Defining_Identifier_Casing; |
| 91 |
-- The current token is an identifier that will be a defining |
| 92 |
-- identifier. Check that it is mixed case, if the appropriate |
| 93 |
-- switch is set. |
| 94 |
|
| 95 |
procedure Check_Dot_Dot; |
| 96 |
-- Called after scanning out dot dot to check spacing |
| 97 |
|
| 98 |
procedure Check_EOF; |
| 99 |
-- Called after scanning out EOF mark |
| 100 |
|
| 101 |
procedure Check_HT; |
| 102 |
-- Called with Scan_Ptr pointing to a horizontal tab character |
| 103 |
|
| 104 |
procedure Check_Indentation; |
| 105 |
-- Called at the start of a new statement or declaration, with Token_Ptr |
| 106 |
-- pointing to the first token of the statement or declaration. The check |
| 107 |
-- is that the starting column is appropriate to the indentation rules if |
| 108 |
-- Token_Ptr is the first token on the line. |
| 109 |
|
| 110 |
procedure Check_Left_Paren_Square_Bracket; |
| 111 |
-- Called after scanning out a left parenthesis to check spacing. If |
| 112 |
-- Ada_Version >= Ada_2022 then called similarly for a left square bracket. |
| 113 |
|
| 114 |
procedure Check_Line_Max_Length (Len : Nat); |
| 115 |
-- Called with Scan_Ptr pointing to the first line terminator character |
| 116 |
-- terminating the current line. Used to check for appropriate line length. |
| 117 |
-- The parameter Len is the length of the current line. |
| 118 |
|
| 119 |
procedure Check_Line_Terminator (Len : Nat); |
| 120 |
-- Called with Scan_Ptr pointing to the first line terminator terminating |
| 121 |
-- the current line, used to check for appropriate line terminator usage. |
| 122 |
-- The parameter Len is the length of the current line. |
| 123 |
|
| 124 |
procedure Check_Not_In; |
| 125 |
-- Called with Scan_Ptr pointing to an IN token, and Prev_Token_Ptr |
| 126 |
-- pointing to a NOT token. Used to check proper layout of NOT IN. |
| 127 |
|
| 128 |
procedure Check_Pragma_Name; |
| 129 |
-- The current token is a pragma identifier. Check that it is spelled |
| 130 |
-- properly (i.e. with an appropriate casing convention). |
| 131 |
|
| 132 |
procedure Check_Right_Paren; |
| 133 |
-- Called after scanning out a right parenthesis to check spacing |
| 134 |
|
| 135 |
procedure Check_Semicolon; |
| 136 |
-- Called after scanning out a semicolon to check spacing |
| 137 |
|
| 138 |
procedure Check_Then (If_Loc : Source_Ptr); |
| 139 |
-- Called to check that THEN and IF keywords are appropriately positioned. |
| 140 |
-- The parameters show the first characters of the two keywords. This |
| 141 |
-- procedure is called with Token_Ptr pointing to the THEN keyword. |
| 142 |
|
| 143 |
procedure Check_Separate_Stmt_Lines; |
| 144 |
pragma Inline (Check_Separate_Stmt_Lines); |
| 145 |
-- Called after scanning THEN (not preceded by AND) or ELSE (not preceded |
| 146 |
-- by OR). Used to check that no tokens follow on the same line (which |
| 147 |
-- would interfere with coverage testing). Handles case of THEN ABORT as |
| 148 |
-- an exception, as well as PRAGMA after ELSE. |
| 149 |
|
| 150 |
procedure Check_Unary_Plus_Or_Minus (Inside_Depends : Boolean := False); |
| 151 |
-- Called after scanning a unary plus or minus to check spacing. The flag |
| 152 |
-- Inside_Depends is set if we are scanning within a Depends or |
| 153 |
-- Refined_Depends pragma or Aspect, in which case =>+ requires a |
| 154 |
-- following space. |
| 155 |
|
| 156 |
procedure Check_Vertical_Bar; |
| 157 |
-- Called after scanning a vertical bar to check spacing |
| 158 |
|
| 159 |
procedure Check_Xtra_Parens (N : Node_Id); |
| 160 |
-- Called after scanning an entire expression (N) that does not require an |
| 161 |
-- extra level of parentheses. |
| 162 |
|
| 163 |
function Mode_In_Check return Boolean; |
| 164 |
pragma Inline (Mode_In_Check); |
| 165 |
-- Determines whether style checking is active and the Mode_In_Check is |
| 166 |
-- set, forbidding the explicit use of mode IN. |
| 167 |
|
| 168 |
procedure No_End_Name (Name : Node_Id); |
| 169 |
-- Called if an END is encountered where a name is allowed but not present. |
| 170 |
-- The parameter is the node whose name is the name that is permitted in |
| 171 |
-- the END line, and the scan pointer is positioned so that if an error |
| 172 |
-- message is to be generated in this situation, it should be generated |
| 173 |
-- using Error_Msg_SP. |
| 174 |
|
| 175 |
procedure No_Exit_Name (Name : Node_Id); |
| 176 |
-- Called when exiting a named loop, but a name is not present on the EXIT. |
| 177 |
-- The parameter is the node whose name should have followed EXIT, and the |
| 178 |
-- scan pointer is positioned so that if an error message is to be |
| 179 |
-- generated, it should be generated using Error_Msg_SP. |
| 180 |
|
| 181 |
procedure Non_Lower_Case_Keyword; |
| 182 |
-- Called if a reserved keyword is scanned which is not spelled in all |
| 183 |
-- lower case letters. On entry Token_Ptr points to the keyword token. |
| 184 |
-- This is not used for keywords appearing as attribute designators, |
| 185 |
-- where instead Check_Attribute_Name (True) is called. |
| 186 |
|
| 187 |
end Styleg; |