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