1------------------------------------------------------------------------------ 2-- -- 3-- GNAT COMPILER COMPONENTS -- 4-- -- 5-- E R R O U T -- 6-- -- 7-- S p e c -- 8-- -- 9-- Copyright (C) 1992-2018, 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 the routines to output error messages. They are 27-- basically system independent, however in some environments, e.g. when the 28-- parser is embedded into an editor, it may be appropriate to replace the 29-- implementation of this package. 30 31with Err_Vars; 32with Erroutc; 33with Namet; use Namet; 34with Table; 35with Types; use Types; 36with Uintp; use Uintp; 37 38with System; 39 40package Errout is 41 42 Current_Error_Source_File : Source_File_Index 43 renames Err_Vars.Current_Error_Source_File; 44 -- Id of current messages. Used to post file name when unit changes. This 45 -- is initialized to Main_Source_File at the start of a compilation, which 46 -- means that no file names will be output unless there are errors in 47 -- units other than the main unit. However, if the main unit has a pragma 48 -- Source_Reference line, then this is initialized to No_Source_File, to 49 -- force an initial reference to the real source file name. 50 51 Raise_Exception_On_Error : Nat renames Err_Vars.Raise_Exception_On_Error; 52 -- If this value is non-zero, then any attempt to generate an error 53 -- message raises the exception Error_Msg_Exception, and the error message 54 -- is not output. This is used for defending against junk resulting from 55 -- illegalities, and also for substitution of more appropriate error 56 -- messages from higher semantic levels. It is a counter so that the 57 -- increment/decrement protocol nests neatly. 58 59 Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception; 60 -- Exception raised if Raise_Exception_On_Error is true 61 62 Warning_Doc_Switch : Boolean renames Err_Vars.Warning_Doc_Switch; 63 -- If this is set True, then the ??/?*?/?$?/?x?/?X? insertion sequences in 64 -- error messages generate appropriate tags for the output error messages. 65 -- If this switch is False, then these sequences are still recognized (for 66 -- the purposes of implementing the pattern matching in pragmas Warnings 67 -- (Off,..) and Warning_As_Pragma(...) but do not result in adding the 68 -- error message tag. The -gnatw.d switch sets this flag True, -gnatw.D 69 -- sets this flag False. 70 71 Current_Node : Node_Id := Empty; 72 -- Used by Error_Msg as a default Node_Id. 73 -- Relevant only when Opt.Include_Subprogram_In_Messages is set. 74 75 ----------------------------------- 76 -- Suppression of Error Messages -- 77 ----------------------------------- 78 79 -- In an effort to reduce the impact of redundant error messages, the 80 -- error output routines in this package normally suppress certain 81 -- classes of messages as follows: 82 83 -- 1. Identical messages placed at the same point in the text. Such 84 -- duplicate error message result for example from rescanning 85 -- sections of the text that contain lexical errors. Only one of 86 -- such a set of duplicate messages is output, and the rest are 87 -- suppressed. 88 89 -- 2. If more than one parser message is generated for a single source 90 -- line, then only the first message is output, the remaining 91 -- messages on the same line are suppressed. 92 93 -- 3. If a message is posted on a node for which a message has been 94 -- previously posted, then only the first message is retained. The 95 -- Error_Posted flag is used to detect such multiple postings. Note 96 -- that this only applies to semantic messages, since otherwise 97 -- for parser messages, this would be a special case of case 2. 98 99 -- 4. If a message is posted on a node whose Etype or Entity 100 -- fields reference entities on which an error message has 101 -- already been placed, as indicated by the Error_Posted flag 102 -- being set on these entities, then the message is suppressed. 103 104 -- 5. If a message attempts to insert an Error node, or a direct 105 -- reference to the Any_Type node, then the message is suppressed. 106 107 -- 6. Note that cases 2-5 only apply to error messages, not warning 108 -- messages. Warning messages are only suppressed for case 1, and 109 -- when they come from other than the main extended unit. 110 111 -- 7. If an error or warning references an internal name, and we have 112 -- already placed an error (not warning) message at that location, 113 -- then we assume this is cascaded junk and delete the message. 114 115 -- This normal suppression action may be overridden in cases 2-5 (but not 116 -- in case 1 or 7 by setting All_Errors mode, or by setting the special 117 -- unconditional message insertion character (!) as described below. 118 119 --------------------------------------------------------- 120 -- Error Message Text and Message Insertion Characters -- 121 --------------------------------------------------------- 122 123 -- Error message text strings are composed of lower case letters, digits 124 -- and the special characters space, comma, period, colon and semicolon, 125 -- apostrophe and parentheses. Special insertion characters can also 126 -- appear which cause the error message circuit to modify the given 127 -- string as follows: 128 129 -- Insertion character % (Percent: insert name from Names table) 130 -- The character % is replaced by the text for the name specified by 131 -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes the 132 -- name if it is preceded by a non-blank character other than left 133 -- parenthesis. The name is enclosed in quotes unless manual quotation 134 -- mode is set. If the Name_Id is set to No_Name, then no insertion 135 -- occurs; if the Name_Id is set to Error_Name, then the string 136 -- <error> is inserted. A second and third % may appear in a single 137 -- message, similarly replaced by the names which are specified by the 138 -- Name_Id values stored in Error_Msg_Name_2 and Error_Msg_Name_3. The 139 -- names are decoded and cased according to the current identifier 140 -- casing mode. Note: if a unit name ending with %b or %s is passed 141 -- for this kind of insertion, this suffix is simply stripped. Use a 142 -- unit name insertion ($) to process the suffix. 143 -- 144 -- Note: the special names _xxx (xxx = Pre/Post/Invariant) are changed 145 -- to insert the string xxx'Class into the message. 146 147 -- Insertion character %% (Double percent: insert literal name) 148 -- The character sequence %% acts as described above for %, except 149 -- that the name is simply obtained with Get_Name_String and is not 150 -- decoded or cased, it is inserted literally from the names table. 151 -- A trailing %b or %s is not treated specially. 152 -- 153 -- Note: the special names _xxx (xxx = Pre/Post/Invariant) are changed 154 -- to insert the string xxx'Class into the message. 155 156 -- Insertion character $ (Dollar: insert unit name from Names table) 157 -- The character $ is treated similarly to %, except that the name is 158 -- obtained from the Unit_Name_Type value in Error_Msg_Unit_1 and 159 -- Error_Msg_Unit_2, as provided by Get_Unit_Name_String in package 160 -- Uname. Note that this name includes the postfix (spec) or (body) 161 -- strings. If this postfix is not required, use the normal % insertion 162 -- for the unit name. 163 164 -- Insertion character { (Left brace: insert file name from names table) 165 -- The character { is treated similarly to %, except that the input 166 -- value is a File_Name_Type value stored in Error_Msg_File_1 or 167 -- Error_Msg_File_2 or Error_Msg_File_3. The value is output literally, 168 -- enclosed in quotes as for %, but the case is not modified, the 169 -- insertion is the exact string stored in the names table without 170 -- adjusting the casing. 171 172 -- Insertion character * (Asterisk: insert reserved word name) 173 -- The insertion character * is treated exactly like % except that the 174 -- resulting name is cased according to the default conventions for 175 -- reserved words (see package Scans). 176 177 -- Insertion character & (Ampersand: insert name from node) 178 -- The insertion character & is treated similarly to %, except that 179 -- the name is taken from the Chars field of the given node, and may 180 -- refer to a child unit name, or a selected component. The casing is, 181 -- if possible, taken from the original source reference, which is 182 -- obtained from the Sloc field of the given node or nodes. If no Sloc 183 -- is available (happens e.g. for nodes in package Standard), then the 184 -- default case (see Scans spec) is used. The nodes to be used are 185 -- stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion occurs 186 -- for the Empty node, and the Error node results in the insertion of 187 -- the characters <error>. In addition, if the special global variable 188 -- Error_Msg_Qual_Level is non-zero, then the reference will include 189 -- up to the given number of levels of qualification, using the scope 190 -- chain. 191 -- 192 -- Note: the special names _xxx (xxx = Pre/Post/Invariant) are changed 193 -- to insert the string xxx'Class into the message. 194 195 -- Insertion character # (Pound: insert line number reference) 196 -- The character # is replaced by the string indicating the source 197 -- position stored in Error_Msg_Sloc. There are three cases: 198 -- 199 -- for package Standard: in package Standard 200 -- for locations in current file: at line nnn:ccc 201 -- for locations in other files: at filename:nnn:ccc 202 -- 203 -- By convention, the # insertion character is only used at the end of 204 -- an error message, so the above strings only appear as the last 205 -- characters of an error message. The only exceptions to this rule 206 -- are that an RM reference may follow in the form (RM .....) and a 207 -- right parenthesis may immediately follow the #. In the case of 208 -- continued messages, # can only appear at the end of a group of 209 -- continuation messages, except that \\ messages which always start 210 -- a new line end the sequence from the point of view of this rule. 211 -- The idea is that for any use of -gnatj, it will still be the case 212 -- that a location reference appears only at the end of a line. 213 214 -- Note: the output of the string "at " is suppressed if the string 215 -- " from" or " from " immediately precedes the insertion character #. 216 -- Certain messages read better with from than at. 217 218 -- Insertion character } (Right brace: insert type reference) 219 -- The character } is replaced by a string describing the type 220 -- referenced by the entity whose Id is stored in Error_Msg_Node_1. 221 -- The string gives the name or description of the type, and also 222 -- where appropriate the location of its declaration. Special cases 223 -- like "some integer type" are handled appropriately. Only one } is 224 -- allowed in a message, since there is not enough room for two (the 225 -- insertion can be quite long, including a file name). In addition, if 226 -- the special global variable Error_Msg_Qual_Level is non-zero, then 227 -- the reference will include up to the given number of levels of 228 -- qualification, using the scope chain. 229 230 -- Insertion character @ (At: insert column number reference) 231 -- The character @ is replaced by null if the RM_Column_Check mode is 232 -- off (False). If the switch is on (True), then @ is replaced by the 233 -- text string " in column nnn" where nnn is the decimal 234 -- representation of the column number stored in Error_Msg_Col plus 235 -- one (the plus one is because the number is stored 0-origin and 236 -- displayed 1-origin). 237 238 -- Insertion character ^ (Caret: insert integer value) 239 -- The character ^ is replaced by the decimal conversion of the Uint 240 -- value stored in Error_Msg_Uint_1, with a possible leading minus. 241 -- A second ^ may occur in the message, in which case it is replaced 242 -- by the decimal conversion of the Uint value in Error_Msg_Uint_2. 243 244 -- Insertion character > (Greater Than: run time name) 245 -- The character > is replaced by a string of the form (name) if 246 -- Targparm scanned out a Run_Time_Name (see package Targparm for 247 -- details). The name is enclosed in parentheses and output in mixed 248 -- case mode (upper case after any space in the name). If no run time 249 -- name is defined, this insertion character has no effect. 250 251 -- Insertion character ! (Exclamation: unconditional message) 252 -- The character ! appearing anywhere in the text of a message makes 253 -- the message unconditional which means that it is output even if it 254 -- would normally be suppressed. See section above for a description 255 -- of the cases in which messages are normally suppressed. Note that 256 -- in the case of warnings, the meaning is that the warning should not 257 -- be removed in dead code (that's the only time that the use of ! 258 -- has any effect for a warning). 259 -- 260 -- Note: the presence of ! is ignored in continuation messages (i.e. 261 -- messages starting with the \ insertion character). The effect of the 262 -- use of ! in a parent message automatically applies to all of its 263 -- continuation messages (since we clearly don't want any case in which 264 -- continuations are separated from the main message). It is allowable 265 -- to put ! in continuation messages, and the usual style is to include 266 -- it, since it makes it clear that the continuation is part of an 267 -- unconditional message. 268 269 -- Insertion character !! (Double exclamation: unconditional warning) 270 -- Normally warning messages issued in other than the main unit are 271 -- suppressed. If the message contains !! then this suppression is 272 -- avoided. This is currently used by the Compile_Time_Warning pragma 273 -- to ensure the message for a with'ed unit is output, and for warnings 274 -- on ineffective back-end inlining, which is detected in units that 275 -- contain subprograms to be inlined in the main program. It is also 276 -- used by the Compiler_Unit_Warning pragma for similar reasons. 277 278 -- Insertion character ? (Question: warning message) 279 -- The character ? appearing anywhere in a message makes the message 280 -- warning instead of a normal error message, and the text of the 281 -- message will be preceded by "warning:" in the normal case. The 282 -- handling of warnings if further controlled by the Warning_Mode 283 -- option (-w switch), see package Opt for further details, and also by 284 -- the current setting from pragma Warnings. This pragma applies only 285 -- to warnings issued from the semantic phase (not the parser), but 286 -- currently all relevant warnings are posted by the semantic phase 287 -- anyway. Messages starting with (style) are also treated as warning 288 -- messages. 289 -- 290 -- Note: when a warning message is output, the text of the message is 291 -- preceded by "warning: " in the normal case. An exception to this 292 -- rule occurs when the text of the message starts with "info: " in 293 -- which case this string is not prepended. This allows callers to 294 -- label certain warnings as informational messages, rather than as 295 -- warning messages requiring some action. 296 -- 297 -- Note: the presence of ? is ignored in continuation messages (i.e. 298 -- messages starting with the \ insertion character). The warning 299 -- status of continuations is determined only by the parent message 300 -- which is being continued. It is allowable to put ? in continuation 301 -- messages, and the usual style is to include it, since it makes it 302 -- clear that the continuation is part of a warning message, but it is 303 -- not necessary to go through any computational effort to include it. 304 -- 305 -- Note: this usage is obsolete, use ?? ?*? ?$? ?x? ?X? to specify 306 -- the string to be added when Warn_Doc_Switch is set to True. If this 307 -- switch is True, then for simple ? messages it has no effect. This 308 -- simple form is to ease transition and will be removed later. 309 310 -- Insertion character ?? (Two question marks: default warning) 311 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string 312 -- "[enabled by default]" at the end of the warning message. For 313 -- continuations, use this in each continuation message. 314 315 -- Insertion character ?x? (warning with switch) 316 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string 317 -- "[-gnatwx]" at the end of the warning message. x is a lower case 318 -- letter. For continuations, use this on each continuation message. 319 320 -- Insertion character ?X? (warning with dot switch) 321 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string 322 -- "[-gnatw.x]" at the end of the warning message. X is an upper case 323 -- letter corresponding to the lower case letter x in the message. 324 -- For continuations, use this on each continuation message. 325 326 -- Insertion character ?*? (restriction warning) 327 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string 328 -- "[restriction warning]" at the end of the warning message. For 329 -- continuations, use this on each continuation message. 330 331 -- Insertion character ?$? (elaboration informational messages) 332 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string 333 -- "[-gnatel]" at the end of the info message. This is used for the 334 -- messages generated by the switch -gnatel. For continuations, use 335 -- this on each continuation message. 336 337 -- Insertion character < (Less Than: conditional warning message) 338 -- The character < appearing anywhere in a message is used for a 339 -- conditional error message. If Error_Msg_Warn is True, then the 340 -- effect is the same as ? described above, and in particular << <X< 341 -- <x< <$< <*< have the effect of ?? ?X? ?x? ?$? ?*? respectively. If 342 -- Error_Msg_Warn is False, then the < << or <X< sequence is ignored 343 -- and the message is treated as a error rather than a warning. 344 345 -- Insertion character A-Z (Upper case letter: Ada reserved word) 346 -- If two or more upper case letters appear in the message, they are 347 -- taken as an Ada reserved word, and are converted to the default 348 -- case for reserved words (see Scans package spec). Surrounding 349 -- quotes are added unless manual quotation mode is currently set. 350 -- RM and SPARK are special exceptions, they are never treated as 351 -- keywords, and just appear verbatim, with no surrounding quotes. 352 -- As a special case, 'R'M is used instead of RM (which is not treated 353 -- as a keyword) to indicate when the reference to the RM is possibly 354 -- not useful anymore, and could possibly be replaced by a comment 355 -- in the source. 356 357 -- Insertion character ` (Backquote: set manual quotation mode) 358 -- The backquote character always appears in pairs. Each backquote of 359 -- the pair is replaced by a double quote character. In addition, any 360 -- reserved keywords, or name insertions between these backquotes are 361 -- not surrounded by the usual automatic double quotes. See the 362 -- section below on manual quotation mode for further details. 363 364 -- Insertion character ' (Quote: literal character) 365 -- Precedes a character which is placed literally into the message. 366 -- Used to insert characters into messages that are one of the 367 -- insertion characters defined here. Also used for insertion of 368 -- upper case letter sequences not to be treated as keywords. 369 370 -- Insertion character \ (Backslash: continuation message) 371 -- Indicates that the message is a continuation of a message 372 -- previously posted. This is used to ensure that such groups of 373 -- messages are treated as a unit. The \ character must be the first 374 -- character of the message text. 375 376 -- Insertion character \\ (Two backslashes: continuation with new line) 377 -- This differs from \ only in -gnatjnn mode (Error_Message_Line_Length 378 -- set non-zero). This sequence forces a new line to start even when 379 -- continuations are being gathered into a single message. 380 381 -- Insertion character | (Vertical bar: non-serious error) 382 -- By default, error messages (other than warning messages) are 383 -- considered to be fatal error messages which prevent expansion or 384 -- generation of code in the presence of the -gnatQ switch. If the 385 -- insertion character | appears, the message is considered to be 386 -- non-serious, and does not cause Serious_Errors_Detected to be 387 -- incremented (so expansion is not prevented by such a msg). This 388 -- insertion character is ignored in continuation messages. 389 390 -- Insertion character ~ (Tilde: insert string) 391 -- Indicates that Error_Msg_String (1 .. Error_Msg_Strlen) is to be 392 -- inserted to replace the ~ character. The string is inserted in the 393 -- literal form it appears, without any action on special characters. 394 395 -- Insertion character [ (Left bracket: will/would be raised at run time) 396 -- This is used in messages about exceptions being raised at run-time. 397 -- If the current message is a warning message, then if the code is 398 -- executed, the exception will be raised, and [ inserts: 399 -- 400 -- will be raised at run time 401 -- 402 -- If the current message is an error message, then it is an error 403 -- because the exception would have been raised and [ inserts: 404 -- 405 -- would have been raised at run time 406 -- 407 -- Typically the message contains a < insertion which means that the 408 -- message is a warning or error depending on Error_Msg_Warn. This is 409 -- most typically used in the context of messages which are normally 410 -- warnings, but are errors in GNATprove mode, corresponding to the 411 -- permission in the definition of SPARK that allows an implementation 412 -- to reject a program as illegal if a situation arises in which the 413 -- compiler can determine that it is certain that a run-time check 414 -- would have fail if the statement was executed. 415 416 -- Insertion character ] (Right bracket: may/might be raised at run time) 417 -- This is like [ except that the insertion messages say may/might, 418 -- instead of will/would. 419 420 -- Insertion sequence "(style)" (style message) 421 -- This appears only at the start of the message (and not any of its 422 -- continuations, if any), and indicates that the message is a style 423 -- message. Style messages are also considered to be warnings, but 424 -- they do not get a tag. 425 426 -- Insertion sequence "info: " (informational message) 427 -- This appears only at the start of the message (and not any of its 428 -- continuations, if any), and indicates that the message is an info 429 -- message. The message will be output with this prefix, and if there 430 -- are continuations that are not printed using the -gnatj switch they 431 -- will also have this prefix. Informational messages are usually also 432 -- warnings, but they don't have to be. 433 434 -- Insertion sequence "low: " or "medium: " or "high: " (check message) 435 -- This appears only at the start of the message (and not any of its 436 -- continuations, if any), and indicates that the message is a check 437 -- message. The message will be output with this prefix. Check 438 -- messages are not fatal (so are like info messages in that respect) 439 -- and are not controlled by pragma Warnings. 440 441 ----------------------------------------------------- 442 -- Global Values Used for Error Message Insertions -- 443 ----------------------------------------------------- 444 445 -- The following global variables are essentially additional parameters 446 -- passed to the error message routine for insertion sequences described 447 -- above. The reason these are passed globally is that the insertion 448 -- mechanism is essentially an untyped one in which the appropriate 449 -- variables are set depending on the specific insertion characters used. 450 451 -- Note that is mandatory that the caller ensure that global variables 452 -- are set before the Error_Msg call, otherwise the result is undefined. 453 454 Error_Msg_Col : Column_Number renames Err_Vars.Error_Msg_Col; 455 -- Column for @ insertion character in message 456 457 Error_Msg_Uint_1 : Uint renames Err_Vars.Error_Msg_Uint_1; 458 Error_Msg_Uint_2 : Uint renames Err_Vars.Error_Msg_Uint_2; 459 -- Uint values for ^ insertion characters in message 460 461 Error_Msg_Sloc : Source_Ptr renames Err_Vars.Error_Msg_Sloc; 462 -- Source location for # insertion character in message 463 464 Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1; 465 Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2; 466 Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3; 467 -- Name_Id values for % insertion characters in message 468 469 Error_Msg_File_1 : File_Name_Type renames Err_Vars.Error_Msg_File_1; 470 Error_Msg_File_2 : File_Name_Type renames Err_Vars.Error_Msg_File_2; 471 Error_Msg_File_3 : File_Name_Type renames Err_Vars.Error_Msg_File_3; 472 -- File_Name_Type values for { insertion characters in message 473 474 Error_Msg_Unit_1 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_1; 475 Error_Msg_Unit_2 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_2; 476 -- Unit_Name_Type values for $ insertion characters in message 477 478 Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1; 479 Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2; 480 -- Node_Id values for & insertion characters in message 481 482 Error_Msg_Qual_Level : Nat renames Err_Vars.Error_Msg_Qual_Level; 483 -- Number of levels of qualification required for type name (see the 484 -- description of the } insertion character). Note that this value does 485 -- not get reset by any Error_Msg call, so the caller is responsible 486 -- for resetting it. 487 488 Error_Msg_Warn : Boolean renames Err_Vars.Error_Msg_Warn; 489 -- Used if current message contains a < insertion character to indicate 490 -- if the current message is a warning message. Must be set appropriately 491 -- before any call to Error_Msg_xxx with a < insertion character present. 492 -- Setting is irrelevant if no < insertion character is present. 493 494 Error_Msg_String : String renames Err_Vars.Error_Msg_String; 495 Error_Msg_Strlen : Natural renames Err_Vars.Error_Msg_Strlen; 496 -- Used if current message contains a ~ insertion character to indicate 497 -- insertion of the string Error_Msg_String (1 .. Error_Msg_Strlen). 498 499 ----------------------------------------------------- 500 -- Format of Messages and Manual Quotation Control -- 501 ----------------------------------------------------- 502 503 -- Messages are generally all in lower case, except for inserted names 504 -- and appear in one of the following three forms: 505 506 -- error: text 507 -- warning: text 508 509 -- The prefixes error and warning are supplied automatically (depending 510 -- on the use of the ? insertion character), and the call to the error 511 -- message routine supplies the text. The "error: " prefix is omitted 512 -- in brief error message formats. 513 514 -- Reserved Ada keywords in the message are in the default keyword case 515 -- (determined from the given source program), surrounded by quotation 516 -- marks. This is achieved by spelling the reserved word in upper case 517 -- letters, which is recognized as a request for insertion of quotation 518 -- marks by the error text processor. Thus for example: 519 520 -- Error_Msg_AP ("IS expected"); 521 522 -- would result in the output of one of the following: 523 524 -- error: "is" expected 525 -- error: "IS" expected 526 -- error: "Is" expected 527 528 -- the choice between these being made by looking at the casing convention 529 -- used for keywords (actually the first compilation unit keyword) in the 530 -- source file. 531 532 -- Note: a special exception is that RM is never treated as a keyword 533 -- but instead is copied literally into the message, this avoids the 534 -- need for writing 'R'M for all reference manual quotes. A similar 535 -- exception is applied to the occurrence of the string SPARK used in 536 -- error messages about the SPARK subset of Ada. 537 538 -- In the case of names, the default mode for the error text processor 539 -- is to surround the name by quotation marks automatically. The case 540 -- used for the identifier names is taken from the source program where 541 -- possible, and otherwise is the default casing convention taken from 542 -- the source file usage. 543 544 -- In some cases, better control over the placement of quote marks is 545 -- required. This is achieved using manual quotation mode. In this mode, 546 -- one or more insertion sequences is surrounded by backquote characters. 547 -- The backquote characters are output as double quote marks, and normal 548 -- automatic insertion of quotes is suppressed between the double quotes. 549 -- For example: 550 551 -- Error_Msg_AP ("`END &;` expected"); 552 553 -- generates a message like 554 555 -- error: "end Open_Scope;" expected 556 557 -- where the node specifying the name Open_Scope has been stored in 558 -- Error_Msg_Node_1 prior to the call. The great majority of error 559 -- messages operates in normal quotation mode. 560 561 -- Note: the normal automatic insertion of spaces before insertion 562 -- sequences (such as those that come from & and %) is suppressed in 563 -- manual quotation mode, so blanks, if needed as in the above example, 564 -- must be explicitly present. 565 566 ---------------------------- 567 -- Message ID Definitions -- 568 ---------------------------- 569 570 subtype Error_Msg_Id is Erroutc.Error_Msg_Id; 571 function "=" (Left, Right : Error_Msg_Id) return Boolean 572 renames Erroutc."="; 573 -- A type used to represent specific error messages. Used by the clients 574 -- of this package only in the context of the Get_Error_Id and 575 -- Change_Error_Text subprograms. 576 577 No_Error_Msg : constant Error_Msg_Id := Erroutc.No_Error_Msg; 578 -- A constant which is different from any value returned by Get_Error_Id. 579 -- Typically used by a client to indicate absense of a saved Id value. 580 581 Warning_Msg : Error_Msg_Id := No_Error_Msg; 582 -- This is set if a warning message is generated to the ID of the resulting 583 -- message. Continuation messages have no effect. It is legitimate for the 584 -- client to set this to No_Error_Msg and then test it to see if a warning 585 -- message has been issued. 586 587 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id); 588 -- Deletes the given warning message and all its continuations. This is 589 -- typically used in conjunction with reading the value of Warning_Msg. 590 591 function Get_Msg_Id return Error_Msg_Id renames Erroutc.Get_Msg_Id; 592 -- Returns the Id of the message most recently posted using one of the 593 -- Error_Msg routines. 594 595 function Get_Location (E : Error_Msg_Id) return Source_Ptr 596 renames Erroutc.Get_Location; 597 -- Returns the flag location of the error message with the given id E 598 599 ------------------------ 600 -- List Pragmas Table -- 601 ------------------------ 602 603 -- When a pragma Page or pragma List is encountered by the parser, an 604 -- entry is made in the following table. This table is then used to 605 -- control the full listing if one is being generated. Note that the 606 -- reason we do the processing in the parser is so that we get proper 607 -- listing control even in syntax check only mode. 608 609 type List_Pragma_Type is (List_On, List_Off, Page); 610 611 type List_Pragma_Record is record 612 Ptyp : List_Pragma_Type; 613 Ploc : Source_Ptr; 614 end record; 615 616 -- Note: Ploc points to the terminating semicolon in the List_Off and Page 617 -- cases, and to the pragma keyword for List_On. In the case of a pragma 618 -- List_Off, a List_On entry is also made in the table, pointing to the 619 -- pragma keyword. This ensures that, as required, a List (Off) pragma is 620 -- listed even in list off mode. 621 622 package List_Pragmas is new Table.Table ( 623 Table_Component_Type => List_Pragma_Record, 624 Table_Index_Type => Int, 625 Table_Low_Bound => 1, 626 Table_Initial => 50, 627 Table_Increment => 200, 628 Table_Name => "List_Pragmas"); 629 630 --------------------------- 631 -- Ignore_Errors Feature -- 632 --------------------------- 633 634 -- In certain cases, notably for optional subunits, the compiler operates 635 -- in a mode where errors are to be ignored, and the whole unit is to be 636 -- considered as not present. To implement this we provide the following 637 -- flag to enable special handling, where error messages are suppressed, 638 -- but the Fatal_Error flag will still be set in the normal manner. 639 640 Ignore_Errors_Enable : Nat := 0; 641 -- Triggering switch. If non-zero, then ignore errors mode is activated. 642 -- This is a counter to allow convenient nesting of enable/disable. 643 644 ----------------------- 645 -- CODEFIX Facility -- 646 ----------------------- 647 648 -- The GPS and GNATBench IDE's have a codefix facility that allows for 649 -- automatic correction of a subset of the errors and warnings issued 650 -- by the compiler. This is done by recognizing the text of specific 651 -- messages using appropriate matching patterns. 652 653 -- The text of such messages should not be altered without coordinating 654 -- with the codefix code. All such messages are marked by a specific 655 -- style of comments, as shown by the following example: 656 657 -- Error_Msg_N -- CODEFIX 658 -- (parameters ....) 659 660 -- Any message marked with this -- CODEFIX comment should not be modified 661 -- without appropriate coordination. 662 663 ------------------------------ 664 -- Error Output Subprograms -- 665 ------------------------------ 666 667 procedure Initialize; 668 -- Initializes for output of error messages. Must be called for each 669 -- source file before using any of the other routines in the package. 670 671 procedure Finalize (Last_Call : Boolean); 672 -- Finalize processing of error message list. Includes processing for 673 -- duplicated error messages, and other similar final adjustment of the 674 -- list of error messages. Note that this procedure must be called before 675 -- calling Compilation_Errors to determine if there were any errors. It 676 -- is perfectly fine to call Finalize more than once, providing that the 677 -- parameter Last_Call is set False for every call except the last call. 678 679 -- This multiple call capability is used to do some processing that may 680 -- generate messages. Call Finalize to eliminate duplicates and remove 681 -- deleted warnings. Test for compilation errors using Compilation_Errors, 682 -- then generate some more errors/warnings, call Finalize again to make 683 -- sure that all duplicates in these new messages are dealt with, then 684 -- finally call Output_Messages to output the final list of messages. The 685 -- argument Last_Call must be set False on all calls except the last call, 686 -- and must be set True on the last call (a value of True activates some 687 -- processing that must only be done after all messages are posted). 688 689 procedure Output_Messages; 690 -- Output list of messages, including messages giving number of detected 691 -- errors and warnings. 692 693 procedure Error_Msg 694 (Msg : String; Flag_Location : Source_Ptr); 695 procedure Error_Msg 696 (Msg : String; Flag_Location : Source_Ptr; N : Node_Id); 697 -- Output a message at specified location. Can be called from the parser 698 -- or the semantic analyzer. If N is set, points to the relevant node for 699 -- this message. 700 701 procedure Error_Msg_S (Msg : String); 702 -- Output a message at current scan pointer location. This routine can be 703 -- called only from the parser, since it references Scan_Ptr. 704 705 procedure Error_Msg_AP (Msg : String); 706 -- Output a message just after the previous token. This routine can be 707 -- called only from the parser, since it references Prev_Token_Ptr. 708 709 procedure Error_Msg_BC (Msg : String); 710 -- Output a message just before the current token. Note that the important 711 -- difference between this and the previous routine is that the BC case 712 -- posts a flag on the current line, whereas AP can post a flag at the 713 -- end of the preceding line. This routine can be called only from the 714 -- parser, since it references Token_Ptr. 715 716 procedure Error_Msg_SC (Msg : String); 717 -- Output a message at the start of the current token, unless we are at 718 -- the end of file, in which case we always output the message after the 719 -- last real token in the file. This routine can be called only from the 720 -- parser, since it references Token_Ptr. 721 722 procedure Error_Msg_SP (Msg : String); 723 -- Output a message at the start of the previous token. This routine can 724 -- be called only from the parser, since it references Prev_Token_Ptr. 725 726 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id); 727 -- Output a message at the Sloc of the given node. This routine can be 728 -- called from the parser or the semantic analyzer, although the call from 729 -- the latter is much more common (and is the most usual way of generating 730 -- error messages from the analyzer). The message text may contain a 731 -- single & insertion, which will reference the given node. The message is 732 -- suppressed if the node N already has a message posted, or if it is a 733 -- warning and N is an entity node for which warnings are suppressed. 734 735 procedure Error_Msg_F (Msg : String; N : Node_Id); 736 -- Similar to Error_Msg_N except that the message is placed on the first 737 -- node of the construct N (First_Node (N)). Note that this procedure uses 738 -- Original_Node to look at the original source tree, since that's what we 739 -- want for placing an error message flag in the right place. 740 741 procedure Error_Msg_NE 742 (Msg : String; 743 N : Node_Or_Entity_Id; 744 E : Node_Or_Entity_Id); 745 -- Output a message at the Sloc of the given node N, with an insertion of 746 -- the name from the given entity node E. This is used by the semantic 747 -- routines, where this is a common error message situation. The Msg text 748 -- will contain a & or } as usual to mark the insertion point. This 749 -- routine can be called from the parser or the analyzer. 750 751 procedure Error_Msg_FE 752 (Msg : String; 753 N : Node_Id; 754 E : Node_Or_Entity_Id); 755 -- Same as Error_Msg_NE, except that the message is placed on the first 756 -- node of the construct N (First_Node (N)). 757 758 procedure Error_Msg_NEL 759 (Msg : String; 760 N : Node_Or_Entity_Id; 761 E : Node_Or_Entity_Id; 762 Flag_Location : Source_Ptr); 763 -- Exactly the same as Error_Msg_NE, except that the flag is placed at 764 -- the specified Flag_Location instead of at Sloc (N). 765 766 procedure Error_Msg_NW 767 (Eflag : Boolean; 768 Msg : String; 769 N : Node_Or_Entity_Id); 770 -- This routine is used for posting a message conditionally. The message 771 -- is posted (with the same effect as Error_Msg_N (Msg, N) if and only 772 -- if Eflag is True and if the node N is within the main extended source 773 -- unit and comes from source. Typically this is a warning mode flag. 774 -- This routine can only be called during semantic analysis. It may not 775 -- be called during parsing. 776 777 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String); 778 -- The error message text of the message identified by Id is replaced by 779 -- the given text. This text may contain insertion characters in the 780 -- usual manner, and need not be the same length as the original text. 781 782 function First_Node (C : Node_Id) return Node_Id; 783 -- Given a construct C, finds the first node in the construct, i.e. the one 784 -- with the lowest Sloc value. This is useful in placing error msgs. Note 785 -- that this procedure uses Original_Node to look at the original source 786 -- tree, since that's what we want for placing an error message flag in 787 -- the right place. 788 789 function First_Sloc (N : Node_Id) return Source_Ptr; 790 -- Given the node for an expression, return a source pointer value that 791 -- points to the start of the first token in the expression. In the case 792 -- where the expression is parenthesized, an attempt is made to include 793 -- the parentheses (i.e. to return the location of the initial paren). 794 795 function Get_Ignore_Errors return Boolean; 796 -- Return True if all error calls are ignored. 797 798 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) 799 renames Erroutc.Purge_Messages; 800 -- All error messages whose location is in the range From .. To (not 801 -- including the end points) will be deleted from the error listing. 802 803 procedure Remove_Warning_Messages (N : Node_Id); 804 -- Remove any warning messages corresponding to the Sloc of N or any 805 -- of its descendant nodes. No effect if no such warnings. Note that 806 -- style messages (identified by the fact that they start with "(style)") 807 -- are not removed by this call. Basically the idea behind this procedure 808 -- is to remove warnings about execution conditions from known dead code. 809 810 procedure Remove_Warning_Messages (L : List_Id); 811 -- Remove warnings on all elements of a list (Calls Remove_Warning_Messages 812 -- on each element of the list, see above). 813 814 procedure Reset_Warnings; 815 -- Reset the counts related to warnings. This is used both to initialize 816 -- these counts and to reset them after each phase of analysis for a given 817 -- value of Opt.Warning_Mode in gnat2why. 818 819 procedure Set_Ignore_Errors (To : Boolean); 820 -- Following a call to this procedure with To=True, all error calls are 821 -- ignored. A call with To=False restores the default treatment in which 822 -- error calls are treated as usual (and as described in this spec). 823 824 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id) 825 renames Erroutc.Set_Warnings_Mode_Off; 826 -- Called in response to a pragma Warnings (Off) to record the source 827 -- location from which warnings are to be turned off. Reason is the 828 -- Reason from the pragma, or the null string if none is given. 829 830 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) 831 renames Erroutc.Set_Warnings_Mode_On; 832 -- Called in response to a pragma Warnings (On) to record the source 833 -- location from which warnings are to be turned back on. 834 835 procedure Set_Specific_Warning_Off 836 (Loc : Source_Ptr; 837 Msg : String; 838 Reason : String_Id; 839 Config : Boolean; 840 Used : Boolean := False) 841 renames Erroutc.Set_Specific_Warning_Off; 842 -- This is called in response to the two argument form of pragma Warnings 843 -- where the first argument is OFF, and the second argument is a string 844 -- which identifies a specific warning to be suppressed. The first argument 845 -- is the start of the suppression range, and the second argument is the 846 -- string from the pragma. Loc is the location of the pragma (which is the 847 -- start of the range to suppress). Reason is the reason string from the 848 -- pragma, or the null string if no reason is given. Config is True for the 849 -- configuration pragma case (where there is no requirement for a matching 850 -- OFF pragma). Used is set True to disable the check that the warning 851 -- actually has the effect of suppressing a warning. 852 853 procedure Set_Specific_Warning_On 854 (Loc : Source_Ptr; 855 Msg : String; 856 Err : out Boolean) 857 renames Erroutc.Set_Specific_Warning_On; 858 -- This is called in response to the two argument form of pragma Warnings 859 -- where the first argument is ON, and the second argument is the prefix 860 -- of a specific warning to be suppressed. The first argument is the end 861 -- of the suppression range, and the second argument is the string from 862 -- the pragma. Err is set to True on return to report the error of no 863 -- matching Warnings Off pragma preceding this one. 864 865 function Compilation_Errors return Boolean; 866 -- Returns True if errors have been detected, or warnings in -gnatwe (treat 867 -- warnings as errors) mode. Note that it is mandatory to call Finalize 868 -- before calling this routine. To account for changes to Warning_Mode in 869 -- gnat2why between phases, the past or current presence of an error is 870 -- recorded in a global variable at each call. 871 872 procedure Error_Msg_CRT (Feature : String; N : Node_Id); 873 -- Posts a non-fatal message on node N saying that the feature identified 874 -- by the Feature argument is not supported in either configurable 875 -- run-time mode or no run-time mode (as appropriate). In the former case, 876 -- the name of the library is output if available. 877 878 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id); 879 -- Posts an error on protected type entry or subprogram E (referencing its 880 -- overridden interface primitive Iface_Prim) indicating wrong mode of the 881 -- first formal (RM 9.4(11.9/3)). 882 883 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr); 884 -- If not operating in Ada 2012 mode, posts errors complaining that Feature 885 -- is only supported in Ada 2012, with appropriate suggestions to fix this. 886 -- Loc is the location at which the flag is to be posted. Feature, which 887 -- appears at the start of the first generated message, may contain error 888 -- message insertion characters in the normal manner, and in particular 889 -- may start with | to flag a non-serious error. 890 891 procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg; 892 -- Debugging routine to dump an error message 893 894 ------------------------------------ 895 -- SPARK Error Output Subprograms -- 896 ------------------------------------ 897 898 -- The following routines are intended to report semantic errors in SPARK 899 -- constructs subject to aspect/pragma SPARK_Mode. Note that syntax errors 900 -- must be reported using the Error_Msg_XXX routines. This allows for the 901 -- partial analysis of SPARK features when they are disabled via SPARK_Mode 902 -- set to "off". 903 904 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id); 905 pragma Inline (SPARK_Msg_N); 906 -- Same as Error_Msg_N, but the error is suppressed if SPARK_Mode is Off. 907 -- The routine is inlined because it acts as a simple wrapper. 908 909 procedure SPARK_Msg_NE 910 (Msg : String; 911 N : Node_Or_Entity_Id; 912 E : Node_Or_Entity_Id); 913 pragma Inline (SPARK_Msg_NE); 914 -- Same as Error_Msg_NE, but the error is suppressed if SPARK_Mode is Off. 915 -- The routine is inlined because it acts as a simple wrapper. 916 917 ------------------------------------------ 918 -- Utility Interface for Casing Control -- 919 ------------------------------------------ 920 921 procedure Adjust_Name_Case 922 (Buf : in out Bounded_String; 923 Loc : Source_Ptr); 924 -- Given a name stored in Buf, set proper casing. Loc is an associated 925 -- source position, and if we can find a match between the name in Buf and 926 -- the name at that source location, we copy the casing from the source, 927 -- otherwise we set appropriate default casing. 928 929 procedure Adjust_Name_Case (Loc : Source_Ptr); 930 -- Uses Buf => Global_Name_Buffer. There are no calls to this in the 931 -- compiler, but it is called in SPARK 2014. 932 933 procedure Set_Identifier_Casing 934 (Identifier_Name : System.Address; 935 File_Name : System.Address); 936 -- This subprogram can be used by the back end for the purposes of 937 -- concocting error messages that are not output via Errout, e.g. 938 -- the messages generated by the gcc back end. 939 -- 940 -- The identifier is a null terminated string that represents the name of 941 -- an identifier appearing in the source program. File_Name is a null 942 -- terminated string giving the corresponding file name for the identifier 943 -- as obtained from the front end by the use of Full_Debug_Name to the 944 -- source file referenced by the corresponding source location value. On 945 -- return, the name is in Name_Buffer, null terminated with Name_Len set. 946 -- This name is the identifier name as passed, cased according to the 947 -- default identifier casing for the given file. 948 949end Errout; 950