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