| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- E R R O U T C -- |
| 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 package contains global variables and routines common to error |
| 27 |
-- reporting packages, including Errout and Prj.Err. |
| 28 |
|
| 29 |
with Table; |
| 30 |
with Types; use Types; |
| 31 |
|
| 32 |
package Erroutc is |
| 33 |
|
| 34 |
type Error_Msg_Type is |
| 35 |
(Error, -- Default value |
| 36 |
Non_Serious_Error, |
| 37 |
-- An error message that is not considered fatal an the analys of |
| 38 |
-- the source file can resume. |
| 39 |
Warning, |
| 40 |
Style, -- A special kind of warning only triggered by a style check |
| 41 |
Info, |
| 42 |
Low_Check, -- A type of GNATProve Check messages |
| 43 |
Medium_Check, -- A type of GNATProve Check messages |
| 44 |
High_Check -- A type of GNATProve Check messages |
| 45 |
); |
| 46 |
|
| 47 |
Class_Flag : Boolean := False; |
| 48 |
-- This flag is set True when outputting a reference to a class-wide |
| 49 |
-- type, and is used by Add_Class to insert 'Class at the proper point |
| 50 |
|
| 51 |
Continuation : Boolean := False; |
| 52 |
-- Indicates if current message is a continuation. Initialized from the |
| 53 |
-- Msg_Cont parameter in Error_Msg_Internal and then set True if a \ |
| 54 |
-- insertion character is encountered. |
| 55 |
|
| 56 |
Continuation_New_Line : Boolean := False; |
| 57 |
-- Indicates if current message was a continuation line marked with \\ to |
| 58 |
-- force a new line. Set True if \\ encountered. |
| 59 |
|
| 60 |
Flag_Source : Source_File_Index; |
| 61 |
-- Source file index for source file where error is being posted |
| 62 |
|
| 63 |
Has_Double_Exclam : Boolean := False; |
| 64 |
-- Set true to indicate that the current message contains the insertion |
| 65 |
-- sequence !! (force warnings even in non-main unit source files). |
| 66 |
|
| 67 |
Has_Error_Code : Boolean := False; |
| 68 |
-- Set true to indicate that the current message contains the insertion |
| 69 |
-- sequence [] (insert error code). |
| 70 |
|
| 71 |
Has_Insertion_Line : Boolean := False; |
| 72 |
-- Set True to indicate that the current message contains the insertion |
| 73 |
-- character # (insert line number reference). |
| 74 |
|
| 75 |
Is_Compile_Time_Msg : Boolean := False; |
| 76 |
-- Set true to indicate that the current message originates from a |
| 77 |
-- Compile_Time_Warning or Compile_Time_Error pragma. |
| 78 |
|
| 79 |
Is_Unconditional_Msg : Boolean := False; |
| 80 |
-- Set True to indicate that the current message contains the insertion |
| 81 |
-- character ! and is thus to be treated as an unconditional message. |
| 82 |
|
| 83 |
Is_Runtime_Raise : Boolean := False; |
| 84 |
-- Set to True to indicate that the current message is a warning about a |
| 85 |
-- constraint error that will be raised at runtime (contains [ and switch |
| 86 |
-- -gnatwE was given).. |
| 87 |
|
| 88 |
Error_Msg_Kind : Error_Msg_Type := Error; |
| 89 |
|
| 90 |
Warning_Msg_Char : String (1 .. 2); |
| 91 |
-- Diagnostics switch: |
| 92 |
-- " " -- ? or < appeared on its own in message |
| 93 |
-- "? " -- ?? or << appeared in message |
| 94 |
-- "x " -- ?x? or <x< appeared in message |
| 95 |
-- -- (x = a .. z | A .. Z | * | $) |
| 96 |
-- ".x" -- ?.x? appeared in message (x = a .. z | A .. Z) |
| 97 |
-- "_x" -- ?_x? appeared in message (x = a .. z | A .. Z) |
| 98 |
-- In the case of the < sequences, this is set only if the message is |
| 99 |
-- actually a warning, i.e. if Error_Msg_Warn is True |
| 100 |
|
| 101 |
Kill_Message : Boolean := False; |
| 102 |
-- A flag used to kill weird messages (e.g. those containing uninterpreted |
| 103 |
-- implicit type references) if we have already seen at least one message |
| 104 |
-- already. The idea is that we hope the weird message is a junk cascaded |
| 105 |
-- message that should be suppressed. |
| 106 |
|
| 107 |
Last_Killed : Boolean := False; |
| 108 |
-- Set True if the most recently posted non-continuation message was |
| 109 |
-- killed. This is used to determine the processing of any continuation |
| 110 |
-- messages that follow. |
| 111 |
|
| 112 |
List_Pragmas_Index : Int := 0; |
| 113 |
-- Index into List_Pragmas table |
| 114 |
|
| 115 |
List_Pragmas_Mode : Boolean := False; |
| 116 |
-- Starts True, gets set False by pragma List (Off), True by List (On) |
| 117 |
|
| 118 |
Manual_Quote_Mode : Boolean := False; |
| 119 |
-- Set True in manual quotation mode |
| 120 |
|
| 121 |
Max_Msg_Length : constant := 1024 + 2 * Int (Column_Number'Last); |
| 122 |
-- Maximum length of error message. The addition of 2 * Column_Number'Last |
| 123 |
-- ensures that two insertion tokens of maximum length can be accommodated. |
| 124 |
-- The value of 1024 is an arbitrary value that should be more than long |
| 125 |
-- enough to accommodate any reasonable message (and for that matter, some |
| 126 |
-- pretty unreasonable messages). |
| 127 |
|
| 128 |
Msg_Buffer : String (1 .. Max_Msg_Length); |
| 129 |
-- Buffer used to prepare error messages |
| 130 |
|
| 131 |
Msglen : Integer := 0; |
| 132 |
-- Number of characters currently stored in the message buffer |
| 133 |
|
| 134 |
Suppress_Message : Boolean; |
| 135 |
-- A flag used to suppress certain obviously redundant messages (i.e. |
| 136 |
-- those referring to a node whose type is Any_Type). This suppression |
| 137 |
-- is effective only if All_Errors_Mode is off. |
| 138 |
|
| 139 |
Suppress_Instance_Location : Boolean := False; |
| 140 |
-- Normally, if a # location in a message references a location within |
| 141 |
-- a generic template, then a note is added giving the location of the |
| 142 |
-- instantiation. If this variable is set True, then this note is not |
| 143 |
-- output. This is used for internal processing for the case of an |
| 144 |
-- illegal instantiation. See Error_Msg routine for further details. |
| 145 |
|
| 146 |
---------------------------- |
| 147 |
-- Message ID Definitions -- |
| 148 |
---------------------------- |
| 149 |
|
| 150 |
type Error_Msg_Id is new Int; |
| 151 |
-- A type used to represent specific error messages. Used by the clients |
| 152 |
-- of this package only in the context of the Get_Error_Id and |
| 153 |
-- Change_Error_Text subprograms. |
| 154 |
|
| 155 |
No_Error_Msg : constant Error_Msg_Id := 0; |
| 156 |
-- A constant which is different from any value returned by Get_Error_Id. |
| 157 |
-- Typically used by a client to indicate absence of a saved Id value. |
| 158 |
|
| 159 |
Cur_Msg : Error_Msg_Id := No_Error_Msg; |
| 160 |
-- Id of most recently posted error message |
| 161 |
|
| 162 |
function Get_Msg_Id return Error_Msg_Id; |
| 163 |
-- Returns the Id of the message most recently posted using one of the |
| 164 |
-- Error_Msg routines. |
| 165 |
|
| 166 |
function Get_Location (E : Error_Msg_Id) return Source_Ptr; |
| 167 |
-- Returns the flag location of the error message with the given id E |
| 168 |
|
| 169 |
----------------------------------- |
| 170 |
-- Error Message Data Structures -- |
| 171 |
----------------------------------- |
| 172 |
|
| 173 |
-- The error messages are stored as a linked list of error message objects |
| 174 |
-- sorted into ascending order by the source location (Sloc). Each object |
| 175 |
-- records the text of the message and its source location. |
| 176 |
|
| 177 |
-- The following record type and table are used to represent error |
| 178 |
-- messages, with one entry in the table being allocated for each message. |
| 179 |
|
| 180 |
type Error_Msg_Object is record |
| 181 |
Text : String_Ptr; |
| 182 |
-- Text of error message, fully expanded with all insertions |
| 183 |
|
| 184 |
Next : Error_Msg_Id; |
| 185 |
-- Pointer to next message in error chain. A value of No_Error_Msg |
| 186 |
-- indicates the end of the chain. |
| 187 |
|
| 188 |
Prev : Error_Msg_Id; |
| 189 |
-- Pointer to previous message in error chain. Only set during the |
| 190 |
-- Finalize procedure. A value of No_Error_Msg indicates the first |
| 191 |
-- message in the chain. |
| 192 |
|
| 193 |
Sfile : Source_File_Index; |
| 194 |
-- Source table index of source file. In the case of an error that |
| 195 |
-- refers to a template, always references the original template |
| 196 |
-- not an instantiation copy. |
| 197 |
|
| 198 |
Sptr : Source_Span; |
| 199 |
-- Flag pointer. In the case of an error that refers to a template, |
| 200 |
-- always references the original template, not an instantiation copy. |
| 201 |
-- This value is the actual place in the source that the error message |
| 202 |
-- will be posted. Note that an error placed on an instantiation will |
| 203 |
-- have Sptr pointing to the instantiation point. |
| 204 |
|
| 205 |
Optr : Source_Span; |
| 206 |
-- Flag location used in the call to post the error. This is the same as |
| 207 |
-- Sptr, except when an error is posted on a particular instantiation of |
| 208 |
-- a generic. In such a case, Sptr will point to the original source |
| 209 |
-- location of the instantiation itself, but Optr will point to the |
| 210 |
-- template location (more accurately to the template copy in the |
| 211 |
-- instantiation copy corresponding to the instantiation referenced by |
| 212 |
-- Sptr). |
| 213 |
|
| 214 |
Insertion_Sloc : Source_Ptr; |
| 215 |
-- Location in message for insertion character # when used |
| 216 |
|
| 217 |
Line : Physical_Line_Number; |
| 218 |
-- Line number for error message |
| 219 |
|
| 220 |
Col : Column_Number; |
| 221 |
-- Column number for error message |
| 222 |
|
| 223 |
Compile_Time_Pragma : Boolean; |
| 224 |
-- True if the message originates from a Compile_Time_Warning or |
| 225 |
-- Compile_Time_Error pragma |
| 226 |
|
| 227 |
Warn_Err : Boolean; |
| 228 |
-- True if this is a warning message which is to be treated as an error |
| 229 |
-- as a result of a match with a Warning_As_Error pragma. |
| 230 |
|
| 231 |
Warn_Chr : String (1 .. 2); |
| 232 |
-- See Warning_Msg_Char |
| 233 |
|
| 234 |
Uncond : Boolean; |
| 235 |
-- True if unconditional message (i.e. insertion character ! appeared) |
| 236 |
|
| 237 |
Msg_Cont : Boolean; |
| 238 |
-- This is used for logical messages that are composed of multiple |
| 239 |
-- individual messages. For messages that are not part of such a |
| 240 |
-- group, or that are the first message in such a group. Msg_Cont |
| 241 |
-- is set to False. For subsequent messages in a group, Msg_Cont |
| 242 |
-- is set to True. This is used to make sure that such a group of |
| 243 |
-- messages is either suppressed or retained as a group (e.g. in |
| 244 |
-- the circuit that deletes identical messages). |
| 245 |
|
| 246 |
Deleted : Boolean; |
| 247 |
-- If this flag is set, the message is not printed. This is used |
| 248 |
-- in the circuit for deleting duplicate/redundant error messages. |
| 249 |
|
| 250 |
Kind : Error_Msg_Type; |
| 251 |
end record; |
| 252 |
|
| 253 |
package Errors is new Table.Table ( |
| 254 |
Table_Component_Type => Error_Msg_Object, |
| 255 |
Table_Index_Type => Error_Msg_Id, |
| 256 |
Table_Low_Bound => 1, |
| 257 |
Table_Initial => 200, |
| 258 |
Table_Increment => 200, |
| 259 |
Table_Name => "Error"); |
| 260 |
|
| 261 |
First_Error_Msg : Error_Msg_Id; |
| 262 |
-- The list of error messages, i.e. the first entry on the list of error |
| 263 |
-- messages. This is not the same as the physically first entry in the |
| 264 |
-- error message table, since messages are not always inserted in sequence. |
| 265 |
|
| 266 |
Last_Error_Msg : Error_Msg_Id; |
| 267 |
-- The last entry on the list of error messages. Note: this is not the same |
| 268 |
-- as the physically last entry in the error message table, since messages |
| 269 |
-- are not always inserted in sequence. |
| 270 |
|
| 271 |
-------------------------- |
| 272 |
-- Warning Mode Control -- |
| 273 |
-------------------------- |
| 274 |
|
| 275 |
-- Pragma Warnings allows warnings to be turned off for a specified region |
| 276 |
-- of code, and the following tables are the data structures used to keep |
| 277 |
-- track of these regions. |
| 278 |
|
| 279 |
-- The first table is used for the basic command line control, and for the |
| 280 |
-- forms of Warning with a single ON or OFF parameter. |
| 281 |
|
| 282 |
-- It contains pairs of source locations, the first being the start |
| 283 |
-- location for a warnings off region, and the second being the end |
| 284 |
-- location. When a pragma Warnings (Off) is encountered, a new entry is |
| 285 |
-- established extending from the location of the pragma to the end of the |
| 286 |
-- current source file. A subsequent pragma Warnings (On) adjusts the end |
| 287 |
-- point of this entry appropriately. |
| 288 |
|
| 289 |
-- If all warnings are suppressed by command switch, then there is a dummy |
| 290 |
-- entry (put there by Errout.Initialize) at the start of the table which |
| 291 |
-- covers all possible Source_Ptr values. Note that the source pointer |
| 292 |
-- values in this table always reference the original template, not an |
| 293 |
-- instantiation copy, in the generic case. |
| 294 |
|
| 295 |
-- Reason is the reason from the pragma Warnings (Off,..) or the null |
| 296 |
-- string if no reason parameter is given. |
| 297 |
|
| 298 |
type Warnings_Entry is record |
| 299 |
Start : Source_Ptr; |
| 300 |
Stop : Source_Ptr; |
| 301 |
Reason : String_Id; |
| 302 |
end record; |
| 303 |
|
| 304 |
package Warnings is new Table.Table ( |
| 305 |
Table_Component_Type => Warnings_Entry, |
| 306 |
Table_Index_Type => Natural, |
| 307 |
Table_Low_Bound => 1, |
| 308 |
Table_Initial => 100, |
| 309 |
Table_Increment => 200, |
| 310 |
Table_Name => "Warnings"); |
| 311 |
|
| 312 |
-- The second table is used for the specific forms of the pragma, where |
| 313 |
-- the first argument is ON or OFF, and the second parameter is a string |
| 314 |
-- which is the pattern to match for suppressing a warning. |
| 315 |
|
| 316 |
type Specific_Warning_Entry is record |
| 317 |
Start : Source_Ptr; |
| 318 |
Stop : Source_Ptr; |
| 319 |
-- Starting and ending source pointers for the range. These are always |
| 320 |
-- from the same source file. |
| 321 |
|
| 322 |
Reason : String_Id; |
| 323 |
-- Reason string from pragma Warnings, or null string if none |
| 324 |
|
| 325 |
Msg : String_Ptr; |
| 326 |
-- Message from pragma Warnings (Off, string) |
| 327 |
|
| 328 |
Open : Boolean; |
| 329 |
-- Set to True if OFF has been encountered with no matching ON |
| 330 |
|
| 331 |
Used : Boolean; |
| 332 |
-- Set to True if entry has been used to suppress a warning |
| 333 |
|
| 334 |
Config : Boolean; |
| 335 |
-- True if pragma is configuration pragma (in which case no matching Off |
| 336 |
-- pragma is required, and it is not required that a specific warning be |
| 337 |
-- suppressed). |
| 338 |
end record; |
| 339 |
|
| 340 |
package Specific_Warnings is new Table.Table ( |
| 341 |
Table_Component_Type => Specific_Warning_Entry, |
| 342 |
Table_Index_Type => Natural, |
| 343 |
Table_Low_Bound => 1, |
| 344 |
Table_Initial => 100, |
| 345 |
Table_Increment => 200, |
| 346 |
Table_Name => "Specific_Warnings"); |
| 347 |
|
| 348 |
-- Note on handling configuration case versus specific case. A complication |
| 349 |
-- arises from this example: |
| 350 |
|
| 351 |
-- pragma Warnings (Off, "not referenced*"); |
| 352 |
-- procedure Mumble (X : Integer) is |
| 353 |
-- pragma Warnings (On, "not referenced*"); |
| 354 |
-- begin |
| 355 |
-- null; |
| 356 |
-- end Mumble; |
| 357 |
|
| 358 |
-- The trouble is that the first pragma is technically a configuration |
| 359 |
-- pragma, and yet it is clearly being used in the context of thinking of |
| 360 |
-- it as a specific case. To deal with this, what we do is that the On |
| 361 |
-- entry can match a configuration pragma from the same file, and if we |
| 362 |
-- find such an On entry, we cancel the indication of it being the |
| 363 |
-- configuration case. This seems to handle all cases we run into ok. |
| 364 |
|
| 365 |
------------------- |
| 366 |
-- Color Control -- |
| 367 |
------------------- |
| 368 |
|
| 369 |
Use_SGR_Control : Boolean := False; |
| 370 |
-- Set to True for enabling colored output. This should only be done when |
| 371 |
-- outputting messages to a terminal that supports it. |
| 372 |
|
| 373 |
-- Colors in messages output to a terminal are controlled using SGR |
| 374 |
-- (Select Graphic Rendition). |
| 375 |
|
| 376 |
Color_Separator : constant String := ";"; |
| 377 |
Color_None : constant String := "00"; |
| 378 |
Color_Bold : constant String := "01"; |
| 379 |
Color_Underscore : constant String := "04"; |
| 380 |
Color_Blink : constant String := "05"; |
| 381 |
Color_Reverse : constant String := "07"; |
| 382 |
Color_Fg_Black : constant String := "30"; |
| 383 |
Color_Fg_Red : constant String := "31"; |
| 384 |
Color_Fg_Green : constant String := "32"; |
| 385 |
Color_Fg_Yellow : constant String := "33"; |
| 386 |
Color_Fg_Blue : constant String := "34"; |
| 387 |
Color_Fg_Magenta : constant String := "35"; |
| 388 |
Color_Fg_Cyan : constant String := "36"; |
| 389 |
Color_Fg_White : constant String := "37"; |
| 390 |
Color_Bg_Black : constant String := "40"; |
| 391 |
Color_Bg_Red : constant String := "41"; |
| 392 |
Color_Bg_Green : constant String := "42"; |
| 393 |
Color_Bg_Yellow : constant String := "43"; |
| 394 |
Color_Bg_Blue : constant String := "44"; |
| 395 |
Color_Bg_Magenta : constant String := "45"; |
| 396 |
Color_Bg_Cyan : constant String := "46"; |
| 397 |
Color_Bg_White : constant String := "47"; |
| 398 |
|
| 399 |
SGR_Start : constant String := ASCII.ESC & "["; |
| 400 |
SGR_End : constant String := "m" & ASCII.ESC & "[K"; |
| 401 |
|
| 402 |
function SGR_Seq (Str : String) return String is |
| 403 |
(if Use_SGR_Control then SGR_Start & Str & SGR_End else ""); |
| 404 |
-- Return the SGR control string for the commands in Str. It returns the |
| 405 |
-- empty string if Use_SGR_Control is False, so that we can insert this |
| 406 |
-- string unconditionally. |
| 407 |
|
| 408 |
function SGR_Reset return String is (SGR_Seq ("")); |
| 409 |
-- This ends the current section of colored output |
| 410 |
|
| 411 |
-- We're using the same colors as gcc/g++ for errors/warnings/notes/locus. |
| 412 |
-- More colors are defined in gcc/g++ for other features of diagnostic |
| 413 |
-- messages (e.g. inline types, fixit) and could be used in GNAT in the |
| 414 |
-- future. The following functions start a section of colored output. |
| 415 |
|
| 416 |
function SGR_Error return String is |
| 417 |
(SGR_Seq (Color_Bold & Color_Separator & Color_Fg_Red)); |
| 418 |
function SGR_Warning return String is |
| 419 |
(SGR_Seq (Color_Bold & Color_Separator & Color_Fg_Magenta)); |
| 420 |
function SGR_Note return String is |
| 421 |
(SGR_Seq (Color_Bold & Color_Separator & Color_Fg_Cyan)); |
| 422 |
function SGR_Locus return String is |
| 423 |
(SGR_Seq (Color_Bold)); |
| 424 |
|
| 425 |
----------------- |
| 426 |
-- Subprograms -- |
| 427 |
----------------- |
| 428 |
|
| 429 |
procedure Add_Class; |
| 430 |
-- Add 'Class to buffer for class wide type case (Class_Flag set) |
| 431 |
|
| 432 |
function Buffer_Ends_With (C : Character) return Boolean; |
| 433 |
-- Tests if message buffer ends with given character |
| 434 |
|
| 435 |
function Buffer_Ends_With (S : String) return Boolean; |
| 436 |
-- Tests if message buffer ends with given string preceded by a space |
| 437 |
|
| 438 |
procedure Buffer_Remove (C : Character); |
| 439 |
-- Remove given character from end of buffer if it is present |
| 440 |
|
| 441 |
procedure Buffer_Remove (S : String); |
| 442 |
-- Removes given string from end of buffer if it is present at end of |
| 443 |
-- buffer, and preceded by a space. |
| 444 |
|
| 445 |
function Compilation_Errors return Boolean; |
| 446 |
-- Returns true if errors have been detected, or warnings in -gnatwe |
| 447 |
-- (treat warnings as errors) mode. |
| 448 |
|
| 449 |
procedure dmsg (Id : Error_Msg_Id); |
| 450 |
-- Debugging routine to dump an error message |
| 451 |
|
| 452 |
procedure Decrease_Error_Msg_Count (E : Error_Msg_Object); |
| 453 |
|
| 454 |
procedure Debug_Output (N : Node_Id); |
| 455 |
-- Called from Error_Msg_N and Error_Msg_NE to generate line of debug |
| 456 |
-- output giving node number (of node N) if the debug X switch is set. |
| 457 |
|
| 458 |
procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id); |
| 459 |
-- This function is passed the Id values of two error messages. If either |
| 460 |
-- M1 or M2 is a continuation message, or is already deleted, the call is |
| 461 |
-- ignored. Otherwise a check is made to see if M1 and M2 are duplicated or |
| 462 |
-- redundant. If so, the message to be deleted and all its continuations |
| 463 |
-- are marked with the Deleted flag set to True. |
| 464 |
|
| 465 |
function Count_Compile_Time_Pragma_Warnings return Int; |
| 466 |
-- Returns the number of warnings in the Errors table that were triggered |
| 467 |
-- by a Compile_Time_Warning pragma. |
| 468 |
|
| 469 |
function Get_Warning_Option (Id : Error_Msg_Id) return String; |
| 470 |
-- Returns the warning switch causing this warning message or an empty |
| 471 |
-- string is there is none.. |
| 472 |
|
| 473 |
function Get_Warning_Tag (Id : Error_Msg_Id) return String; |
| 474 |
-- Given an error message ID, return tag showing warning message class, or |
| 475 |
-- the null string if this option is not enabled or this is not a warning. |
| 476 |
|
| 477 |
procedure Increase_Error_Msg_Count (E : Error_Msg_Object); |
| 478 |
-- Increase the error count for the given kind of error message |
| 479 |
|
| 480 |
function Is_Redundant_Error_Message |
| 481 |
(Prev_Msg : Error_Msg_Id; Cur_Msg : Error_Msg_Id) return Boolean; |
| 482 |
-- Check if the Cur_Msg can be removed if it was issued at the same line as |
| 483 |
-- the Prev_Msg. |
| 484 |
|
| 485 |
function Matches (S : String; P : String) return Boolean; |
| 486 |
-- Returns true if the String S matches the pattern P, which can contain |
| 487 |
-- wildcard chars (*). The entire pattern must match the entire string. |
| 488 |
-- Case is ignored in the comparison (so X matches x). |
| 489 |
|
| 490 |
procedure Output_Error_Msgs (E : in out Error_Msg_Id); |
| 491 |
-- Output source line, error flag, and text of stored error message and all |
| 492 |
-- subsequent messages for the same line and unit. On return E is set to be |
| 493 |
-- one higher than the last message output. |
| 494 |
|
| 495 |
procedure Output_Line_Number (L : Logical_Line_Number); |
| 496 |
-- Output a line number as six digits (with leading zeroes suppressed), |
| 497 |
-- followed by a period and a blank (note that this is 8 characters which |
| 498 |
-- means that tabs in the source line will not get messed up). Line numbers |
| 499 |
-- that match or are less than the last Source_Reference pragma are listed |
| 500 |
-- as all blanks, avoiding output of junk line numbers. |
| 501 |
|
| 502 |
procedure Output_Msg_Location (E : Error_Msg_Id); |
| 503 |
-- Write the location of the error message in the following format: |
| 504 |
-- |
| 505 |
-- <File_Name>:<Line>:<Col>: |
| 506 |
-- |
| 507 |
-- If Full_Path_Name_For_Brief_Errors then full path of the file is used. |
| 508 |
|
| 509 |
procedure Output_Msg_Text (E : Error_Msg_Id); |
| 510 |
-- Outputs characters of text in the text of the error message E. Note that |
| 511 |
-- no end of line is output, the caller is responsible for adding the end |
| 512 |
-- of line. If Error_Msg_Line_Length is non-zero, this is the routine that |
| 513 |
-- splits the line generating multiple lines of output, and in this case |
| 514 |
-- the last line has no terminating end of line character. |
| 515 |
|
| 516 |
procedure Output_Text_Within (Txt : String_Ptr; Line_Length : Nat); |
| 517 |
-- Output the text in Txt, splitting it into lines of at most the size of |
| 518 |
-- Line_Length. |
| 519 |
|
| 520 |
procedure Prescan_Message (Msg : String); |
| 521 |
-- Scans message text and sets the following variables: |
| 522 |
-- |
| 523 |
-- Is_Unconditional_Msg is set True if the message contains the character |
| 524 |
-- ! and is otherwise set False. |
| 525 |
-- |
| 526 |
-- Has_Double_Exclam is set True if the message contains the sequence !! |
| 527 |
-- and is otherwise set False. |
| 528 |
-- |
| 529 |
-- Has_Error_Code is set True if the message contains the sequence [] |
| 530 |
-- and is otherwise set False. |
| 531 |
-- |
| 532 |
-- Has_Insertion_Line is set True if the message contains the character # |
| 533 |
-- and is otherwise set False. |
| 534 |
-- |
| 535 |
-- Error_Msg_Kind is set to one of the following values: |
| 536 |
-- * Style - if the message starts with "(style)" |
| 537 |
-- * Info - if the message starts with "info: " |
| 538 |
-- * Warning - if the message contains a "?" and they |
| 539 |
-- are neither Info or Style messages. |
| 540 |
-- * Low_Check - if the message starts with "low: " |
| 541 |
-- * Medium_Check - if the message starts with "medium: " |
| 542 |
-- * High_Check - if the message starts with "high: " |
| 543 |
-- * Non_Serious_Error - if the message contains "|" |
| 544 |
-- * Error - otherwise |
| 545 |
-- |
| 546 |
-- We need to know right away these aspects of a message, since we will |
| 547 |
-- test these values before doing the full error scan. |
| 548 |
-- |
| 549 |
-- Note that the call has no effect for continuation messages (those whose |
| 550 |
-- first character is '\') except for the Has_Insertion_Line setting. |
| 551 |
|
| 552 |
procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr); |
| 553 |
-- All error messages whose location is in the range From .. To (not |
| 554 |
-- including the end points) will be deleted from the error listing. |
| 555 |
|
| 556 |
function Same_Error (M1, M2 : Error_Msg_Id) return Boolean; |
| 557 |
-- See if two messages have the same text. Returns true if the text of the |
| 558 |
-- two messages is identical, or if one of them is the same as the other |
| 559 |
-- with an appended "instance at xxx" tag. |
| 560 |
|
| 561 |
procedure Set_Msg_Blank; |
| 562 |
-- Sets a single blank in the message if the preceding character is a |
| 563 |
-- non-blank character other than a left parenthesis or minus. Has no |
| 564 |
-- effect if manual quote mode is turned on. |
| 565 |
|
| 566 |
procedure Set_Msg_Blank_Conditional; |
| 567 |
-- Sets a single blank in the message if the preceding character is a |
| 568 |
-- non-blank character other than a left parenthesis or quote. Has no |
| 569 |
-- effect if manual quote mode is turned on. |
| 570 |
|
| 571 |
procedure Set_Msg_Char (C : Character); |
| 572 |
-- Add a single character to the current message. This routine does not |
| 573 |
-- check for special insertion characters (they are just treated as text |
| 574 |
-- characters if they occur). |
| 575 |
|
| 576 |
procedure Set_Msg_Insertion_Code; |
| 577 |
-- Handle error code insertion ([] insertion character) |
| 578 |
|
| 579 |
procedure Set_Msg_Insertion_Column; |
| 580 |
-- Handle column number insertion (@ insertion character) |
| 581 |
|
| 582 |
procedure Set_Msg_Insertion_File_Name; |
| 583 |
-- Handle file name insertion (left brace insertion character) |
| 584 |
|
| 585 |
procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr); |
| 586 |
-- Handle line number insertion (# insertion character). Loc is the |
| 587 |
-- location to be referenced, and Flag is the location at which the |
| 588 |
-- flag is posted (used to determine whether to add "in file xxx") |
| 589 |
|
| 590 |
procedure Set_Msg_Insertion_Name_Literal; |
| 591 |
|
| 592 |
procedure Set_Msg_Insertion_Name; |
| 593 |
-- Handle name insertion (% insertion character) |
| 594 |
|
| 595 |
procedure Set_Msg_Insertion_Reserved_Name; |
| 596 |
-- Handle insertion of reserved word name (* insertion character) |
| 597 |
|
| 598 |
procedure Set_Msg_Insertion_Reserved_Word |
| 599 |
(Text : String; |
| 600 |
J : in out Integer); |
| 601 |
-- Handle reserved word insertion (upper case letters). The Text argument |
| 602 |
-- is the current error message input text, and J is an index which on |
| 603 |
-- entry points to the first character of the reserved word, and on exit |
| 604 |
-- points past the last character of the reserved word. Note that RM and |
| 605 |
-- SPARK are treated specially and not considered to be keywords. |
| 606 |
|
| 607 |
procedure Set_Msg_Insertion_Run_Time_Name; |
| 608 |
-- If package System contains a definition for Run_Time_Name (see package |
| 609 |
-- Targparm for details), then this procedure will insert a message of |
| 610 |
-- the form (name) into the current error message, with name set in mixed |
| 611 |
-- case (upper case after any spaces). If no run time name is defined, |
| 612 |
-- then this routine has no effect). |
| 613 |
|
| 614 |
procedure Set_Msg_Insertion_Uint; |
| 615 |
-- Handle Uint insertion (^ insertion character) |
| 616 |
|
| 617 |
procedure Set_Msg_Int (Line : Int); |
| 618 |
-- Set the decimal representation of the argument in the error message |
| 619 |
-- buffer with no leading zeroes output. |
| 620 |
|
| 621 |
procedure Set_Msg_Name_Buffer; |
| 622 |
-- Output name from Namet.Global_Name_Buffer, with surrounding quotes |
| 623 |
-- unless manual quotation mode is in effect. |
| 624 |
|
| 625 |
procedure Set_Msg_Quote; |
| 626 |
-- Set quote if in normal quote mode, nothing if in manual quote mode |
| 627 |
|
| 628 |
procedure Set_Msg_Str (Text : String); |
| 629 |
-- Add a sequence of characters to the current message. This routine does |
| 630 |
-- not check for special insertion characters (they are just treated as |
| 631 |
-- text characters if they occur). It does perform the transformation of |
| 632 |
-- the special strings _xxx (xxx = Pre/Post/Type_Invariant) to xxx'Class. |
| 633 |
|
| 634 |
procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id); |
| 635 |
-- Given a message id, move to next message id, but skip any deleted |
| 636 |
-- messages, so that this results in E on output being the first non- |
| 637 |
-- deleted message following the input value of E, or No_Error_Msg if |
| 638 |
-- the input value of E was either already No_Error_Msg, or was the |
| 639 |
-- last non-deleted message. |
| 640 |
|
| 641 |
procedure Set_Specific_Warning_Off |
| 642 |
(Node : Node_Id; |
| 643 |
Msg : String; |
| 644 |
Reason : String_Id; |
| 645 |
Config : Boolean; |
| 646 |
Used : Boolean := False); |
| 647 |
-- This is called in response to the two argument form of pragma Warnings |
| 648 |
-- where the first argument is OFF, and the second argument is a string |
| 649 |
-- which identifies a specific warning to be suppressed. The first argument |
| 650 |
-- is the corresponding N_Pragma node, and the second argument is the |
| 651 |
-- string from the pragma. Sloc (Node) is the start of the range to |
| 652 |
-- suppress. Reason is the reason string from the pragma, or the null |
| 653 |
-- string if no reason is given. Config is True for the configuration |
| 654 |
-- pragma case (where there is no requirement for a matching OFF pragma). |
| 655 |
-- Used is set True to disable the check that the warning actually has the |
| 656 |
-- effect of suppressing a warning. |
| 657 |
|
| 658 |
procedure Set_Specific_Warning_On |
| 659 |
(Loc : Source_Ptr; |
| 660 |
Msg : String; |
| 661 |
Err : out Boolean); |
| 662 |
-- This is called in response to the two argument form of pragma Warnings |
| 663 |
-- where the first argument is ON, and the second argument is a string |
| 664 |
-- which identifies a specific warning to be suppressed. The first argument |
| 665 |
-- is the end of the suppression range, and the second argument is the |
| 666 |
-- string from the pragma. Err is set to True on return to report the error |
| 667 |
-- of no matching Warnings Off pragma preceding this one. |
| 668 |
|
| 669 |
procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id); |
| 670 |
-- Called in response to a pragma Warnings (Off) to record the source |
| 671 |
-- location from which warnings are to be turned off. Reason is the |
| 672 |
-- Reason from the pragma, or the null string if none is given. |
| 673 |
|
| 674 |
procedure Set_Warnings_Mode_On (Loc : Source_Ptr); |
| 675 |
-- Called in response to a pragma Warnings (On) to record the source |
| 676 |
-- location from which warnings are to be turned back on. |
| 677 |
|
| 678 |
function Warnings_Suppressed (Loc : Source_Ptr) return String_Id; |
| 679 |
-- Determines if given location is covered by a warnings off suppression |
| 680 |
-- range in the warnings table (or is suppressed by compilation option, |
| 681 |
-- which generates a warning range for the whole source file). This routine |
| 682 |
-- only deals with the general ON/OFF case, not specific warnings. The |
| 683 |
-- returned result is No_String if warnings are not suppressed. If warnings |
| 684 |
-- are suppressed for the given location, then corresponding Reason |
| 685 |
-- parameter from the pragma is returned (or the null string if no Reason |
| 686 |
-- parameter was present). |
| 687 |
|
| 688 |
function Warning_Specifically_Suppressed |
| 689 |
(Loc : Source_Ptr; |
| 690 |
Msg : String_Ptr; |
| 691 |
Tag : String := "") return String_Id; |
| 692 |
-- Determines if given message to be posted at given location is suppressed |
| 693 |
-- by specific ON/OFF Warnings pragmas specifying this particular message. |
| 694 |
-- If the warning is not suppressed then No_String is returned, otherwise |
| 695 |
-- the corresponding warning string is returned (or the null string if no |
| 696 |
-- Warning argument was present in the pragma). Tag is the error message |
| 697 |
-- tag for the message in question or the null string if there is no tag. |
| 698 |
-- |
| 699 |
-- Note: we have a null default for Tag to deal with calls from an old |
| 700 |
-- branch of gnat2why, which does not know about tags in the calls but |
| 701 |
-- which uses the latest version of erroutc. |
| 702 |
|
| 703 |
function Warning_Treated_As_Error (Msg : String) return Boolean; |
| 704 |
-- Returns True if the warning message Msg matches any of the strings |
| 705 |
-- given by Warning_As_Error pragmas, as stored in the Warnings_As_Errors |
| 706 |
-- table. |
| 707 |
|
| 708 |
procedure Write_Error_Summary; |
| 709 |
-- Write error summary |
| 710 |
|
| 711 |
end Erroutc; |