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