File : errout.ads


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