1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2010, 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. --
18 -- You should have received a copy of the GNU General Public License along --
19 -- with this program; see file COPYING3. If not see --
20 -- <http://www.gnu.org/licenses/>. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- This package contains the routines to output error messages. They are
28 -- basically system independent, however in some environments, e.g. when the
29 -- parser is embedded into an editor, it may be appropriate to replace the
30 -- implementation of this package.
34 with Namet; use Namet;
36 with Types; use Types;
37 with Uintp; use Uintp;
43 Serious_Errors_Detected : Nat renames Err_Vars.Serious_Errors_Detected;
44 -- This is a count of errors that are serious enough to stop expansion,
45 -- and hence to prevent generation of an object file even if the switch
48 Total_Errors_Detected : Nat renames Err_Vars.Total_Errors_Detected;
49 -- Number of errors detected so far. Includes count of serious errors and
50 -- non-serious errors, so this value is always greater than or equal to
51 -- the Serious_Errors_Detected value.
53 Warnings_Detected : Nat renames Err_Vars.Warnings_Detected;
54 -- Number of warnings detected
56 Configurable_Run_Time_Violations : Nat := 0;
57 -- Count of configurable run time violations so far. This is used to
58 -- suppress certain cascaded error messages when we know that we may not
59 -- have fully expanded some items, due to high integrity violations (i.e.
60 -- the use of constructs not permitted by the library in use, or improper
61 -- constructs in No_Run_Time mode).
63 Current_Error_Source_File : Source_File_Index
64 renames Err_Vars.Current_Error_Source_File;
65 -- Id of current messages. Used to post file name when unit changes. This
66 -- is initialized to Main_Source_File at the start of a compilation, which
67 -- means that no file names will be output unless there are errors in
68 -- units other than the main unit. However, if the main unit has a pragma
69 -- Source_Reference line, then this is initialized to No_Source_File, to
70 -- force an initial reference to the real source file name.
72 Raise_Exception_On_Error : Nat renames Err_Vars.Raise_Exception_On_Error;
73 -- If this value is non-zero, then any attempt to generate an error
74 -- message raises the exception Error_Msg_Exception, and the error message
75 -- is not output. This is used for defending against junk resulting from
76 -- illegalities, and also for substitution of more appropriate error
77 -- messages from higher semantic levels. It is a counter so that the
78 -- increment/decrement protocol nests neatly.
80 Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception;
81 -- Exception raised if Raise_Exception_On_Error is true
83 -----------------------------------
84 -- Suppression of Error Messages --
85 -----------------------------------
87 -- In an effort to reduce the impact of redundant error messages, the
88 -- error output routines in this package normally suppress certain
89 -- classes of messages as follows:
91 -- 1. Identical messages placed at the same point in the text. Such
92 -- duplicate error message result for example from rescanning
93 -- sections of the text that contain lexical errors. Only one of
94 -- such a set of duplicate messages is output, and the rest are
97 -- 2. If more than one parser message is generated for a single source
98 -- line, then only the first message is output, the remaining
99 -- messages on the same line are suppressed.
101 -- 3. If a message is posted on a node for which a message has been
102 -- previously posted, then only the first message is retained. The
103 -- Error_Posted flag is used to detect such multiple postings. Note
104 -- that this only applies to semantic messages, since otherwise
105 -- for parser messages, this would be a special case of case 2.
107 -- 4. If a message is posted on a node whose Etype or Entity
108 -- fields reference entities on which an error message has
109 -- already been placed, as indicated by the Error_Posted flag
110 -- being set on these entities, then the message is suppressed.
112 -- 5. If a message attempts to insert an Error node, or a direct
113 -- reference to the Any_Type node, then the message is suppressed.
115 -- 6. Note that cases 2-5 only apply to error messages, not warning
116 -- messages. Warning messages are only suppressed for case 1, and
117 -- when they come from other than the main extended unit.
119 -- This normal suppression action may be overridden in cases 2-5 (but not
120 -- in case 1) by setting All_Errors mode, or by setting the special
121 -- unconditional message insertion character (!) at the end of the message
122 -- text as described below.
124 ---------------------------------------------------------
125 -- Error Message Text and Message Insertion Characters --
126 ---------------------------------------------------------
128 -- Error message text strings are composed of lower case letters, digits
129 -- and the special characters space, comma, period, colon and semicolon,
130 -- apostrophe and parentheses. Special insertion characters can also
131 -- appear which cause the error message circuit to modify the given
132 -- string as follows:
134 -- Insertion character % (Percent: insert name from Names table)
135 -- The character % is replaced by the text for the name specified by
136 -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes the
137 -- name if it is preceded by a non-blank character other than left
138 -- parenthesis. The name is enclosed in quotes unless manual quotation
139 -- mode is set. If the Name_Id is set to No_Name, then no insertion
140 -- occurs; if the Name_Id is set to Error_Name, then the string
141 -- <error> is inserted. A second and third % may appear in a single
142 -- message, similarly replaced by the names which are specified by the
143 -- Name_Id values stored in Error_Msg_Name_2 and Error_Msg_Name_3. The
144 -- names are decoded and cased according to the current identifier
145 -- casing mode. Note: if a unit name ending with %b or %s is passed
146 -- for this kind of insertion, this suffix is simply stripped. Use a
147 -- unit name insertion ($) to process the suffix.
149 -- Insertion character %% (Double percent: insert literal name)
150 -- The character sequence %% acts as described above for %, except
151 -- that the name is simply obtained with Get_Name_String and is not
152 -- decoded or cased, it is inserted literally from the names table.
153 -- A trailing %b or %s is not treated specially.
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 %
161 -- insertion 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 -- Insertion character # (Pound: insert line number reference)
192 -- The character # is replaced by the string indicating the source
193 -- position stored in Error_Msg_Sloc. There are three cases:
195 -- for package Standard: in package Standard
196 -- for locations in current file: at line nnn:ccc
197 -- for locations in other files: at filename:nnn:ccc
199 -- By convention, the # insertion character is only used at the end of
200 -- an error message, so the above strings only appear as the last
201 -- characters of an error message. The only exceptions to this rule
202 -- are that an RM reference may follow in the form (RM .....) and a
203 -- right parenthesis may immediately follow the #. In the case of
204 -- continued messages, # can only appear at the end of a group of
205 -- continuation messsages, except that \\ messages which always start
206 -- a new line end the sequence from the point of view of this rule.
207 -- The idea is that for any use of -gnatj, it will still be the case
208 -- that a location reference appears only at the end of a line.
210 -- Insertion character } (Right brace: insert type reference)
211 -- The character } is replaced by a string describing the type
212 -- referenced by the entity whose Id is stored in Error_Msg_Node_1.
213 -- the string gives the name or description of the type, and also
214 -- where appropriate the location of its declaration. Special cases
215 -- like "some integer type" are handled appropriately. Only one } is
216 -- allowed in a message, since there is not enough room for two (the
217 -- insertion can be quite long, including a file name) In addition, if
218 -- the special global variable Error_Msg_Qual_Level is non-zero, then
219 -- the reference will include up to the given number of levels of
220 -- qualification, using the scope chain.
222 -- Insertion character @ (At: insert column number reference)
223 -- The character @ is replaced by null if the RM_Column_Check mode is
224 -- off (False). If the switch is on (True), then @ is replaced by the
225 -- text string " in column nnn" where nnn is the decimal
226 -- representation of the column number stored in Error_Msg_Col plus
227 -- one (the plus one is because the number is stored 0-origin and
228 -- displayed 1-origin).
230 -- Insertion character ^ (Carret: insert integer value)
231 -- The character ^ is replaced by the decimal conversion of the Uint
232 -- value stored in Error_Msg_Uint_1, with a possible leading minus.
233 -- A second ^ may occur in the message, in which case it is replaced
234 -- by the decimal conversion of the Uint value in Error_Msg_Uint_2.
236 -- Insertion character > (Right bracket, run time name)
237 -- The character > is replaced by a string of the form (name) if
238 -- Targparm scanned out a Run_Time_Name (see package Targparm for
239 -- details). The name is enclosed in parentheses and output in mixed
240 -- case mode (upper case after any space in the name). If no run time
241 -- name is defined, this insertion character has no effect.
243 -- Insertion character ! (Exclamation: unconditional message)
244 -- The character ! appearing as the last character of a message makes
245 -- the message unconditional which means that it is output even if it
246 -- would normally be suppressed. See section above for a description
247 -- of the cases in which messages are normally suppressed. Note that
248 -- in the case of warnings, the meaning is that the warning should not
249 -- be removed in dead code (that's the only time that the use of !
250 -- has any effect for a warning).
252 -- Note: the presence of ! is ignored in continuation messages (i.e.
253 -- messages starting with the \ insertion character). The effect of the
254 -- use of ! in a parent message automatically applies to all of its
255 -- continuation messages (since we clearly don't want any case in which
256 -- continuations are separated from the parent message. It is allowable
257 -- to put ! in continuation messages, and the usual style is to include
258 -- it, since it makes it clear that the continuation is part of an
259 -- unconditional message.
261 -- Insertion character !! (unconditional warning)
263 -- Normally warning messages issued in other than the main unit are
264 -- suppressed. If the message ends with !! then this suppression is
265 -- avoided. This is currently used by the Compile_Time_Warning pragma
266 -- to ensure the message for a with'ed unit is output, and for warnings
267 -- on ineffective back-end inlining, which is detected in units that
268 -- contain subprograms to be inlined in the main program.
270 -- Insertion character ? (Question: warning message)
271 -- The character ? appearing anywhere in a message makes the message
272 -- warning instead of a normal error message, and the text of the
273 -- message will be preceded by "warning:" in the normal case. The
274 -- handling of warnings if further controlled by the Warning_Mode
275 -- option (-w switch), see package Opt for further details, and also by
276 -- the current setting from pragma Warnings. This pragma applies only
277 -- to warnings issued from the semantic phase (not the parser), but
278 -- currently all relevant warnings are posted by the semantic phase
279 -- anyway. Messages starting with (style) are also treated as warning
282 -- Note: when a warning message is output, the text of the message is
283 -- preceded by "warning: " in the normal case. An exception to this
284 -- rule occurs when the text of the message starts with "info: " in
285 -- which case this string is not prepended. This allows callers to
286 -- label certain warnings as informational messages, rather than as
287 -- warning messages requiring some action.
289 -- Note: the presence of ? is ignored in continuation messages (i.e.
290 -- messages starting with the \ insertion character). The warning
291 -- status of continuations is determined only by the parent message
292 -- which is being continued. It is allowable to put ? in continuation
293 -- messages, and the usual style is to include it, since it makes it
294 -- clear that the continuation is part of a warning message.
296 -- Insertion character < (Less Than: conditional warning message)
297 -- The character < appearing anywhere in a message is used for a
298 -- conditional error message. If Error_Msg_Warn is True, then the
299 -- effect is the same as ? described above. If Error_Msg_Warn is
300 -- False, then there is no effect.
302 -- Insertion character A-Z (Upper case letter: Ada reserved word)
303 -- If two or more upper case letters appear in the message, they are
304 -- taken as an Ada reserved word, and are converted to the default
305 -- case for reserved words (see Scans package spec). Surrounding
306 -- quotes are added unless manual quotation mode is currently set.
308 -- Insertion character ` (Backquote: set manual quotation mode)
309 -- The backquote character always appears in pairs. Each backquote of
310 -- the pair is replaced by a double quote character. In addition, any
311 -- reserved keywords, or name insertions between these backquotes are
312 -- not surrounded by the usual automatic double quotes. See the
313 -- section below on manual quotation mode for further details.
315 -- Insertion character ' (Quote: literal character)
316 -- Precedes a character which is placed literally into the message.
317 -- Used to insert characters into messages that are one of the
318 -- insertion characters defined here. Also useful in inserting
319 -- sequences of upper case letters (e.g. RM) which are not to be
320 -- treated as keywords.
322 -- Insertion character \ (Backslash: continuation message)
323 -- Indicates that the message is a continuation of a message
324 -- previously posted. This is used to ensure that such groups of
325 -- messages are treated as a unit. The \ character must be the first
326 -- character of the message text.
328 -- Insertion character \\ (Two backslashes, continuation with new line)
329 -- This differs from \ only in -gnatjnn mode (Error_Message_Line_Length
330 -- set non-zero). This sequence forces a new line to start even when
331 -- continuations are being gathered into a single message.
333 -- Insertion character | (Vertical bar: non-serious error)
334 -- By default, error messages (other than warning messages) are
335 -- considered to be fatal error messages which prevent expansion or
336 -- generation of code in the presence of the -gnatQ switch. If the
337 -- insertion character | appears, the message is considered to be
338 -- non-serious, and does not cause Serious_Errors_Detected to be
339 -- incremented (so expansion is not prevented by such a msg).
341 -- Insertion character ~ (Tilde: insert string)
342 -- Indicates that Error_Msg_String (1 .. Error_Msg_Strlen) is to be
343 -- inserted to replace the ~ character. The string is inserted in the
344 -- literal form it appears, without any action on special characters.
346 ----------------------------------------
347 -- Specialization of Messages for VMS --
348 ----------------------------------------
350 -- Some messages mention gcc-style switch names. When using an OpenVMS
351 -- host, such switch names must be converted to their corresponding VMS
352 -- qualifer. The following table controls this translation. In each case
353 -- the original message must contain the string "-xxx switch", where xxx
354 -- is the Gname? entry from below, and this string will be replaced by
355 -- "/yyy qualifier", where yyy is the corresponding Vname? entry.
357 Gname1 : aliased constant String := "fno-strict-aliasing";
358 Vname1 : aliased constant String := "OPTIMIZE=NO_STRICT_ALIASING";
360 Gname2 : aliased constant String := "gnatX";
361 Vname2 : aliased constant String := "EXTENSIONS_ALLOWED";
363 Gname3 : aliased constant String := "gnatW";
364 Vname3 : aliased constant String := "WIDE_CHARACTER_ENCODING";
366 Gname4 : aliased constant String := "gnatf";
367 Vname4 : aliased constant String := "REPORT_ERRORS=FULL";
369 Gname5 : aliased constant String := "gnat05";
370 Vname5 : aliased constant String := "05";
372 Gname6 : aliased constant String := "gnat2005";
373 Vname6 : aliased constant String := "2005";
375 Gname7 : aliased constant String := "gnat12";
376 Vname7 : aliased constant String := "12";
378 Gname8 : aliased constant String := "gnat2012";
379 Vname8 : aliased constant String := "2012";
381 type Cstring_Ptr is access constant String;
383 Gnames : array (Nat range <>) of Cstring_Ptr :=
393 Vnames : array (Nat range <>) of Cstring_Ptr :=
403 -----------------------------------------------------
404 -- Global Values Used for Error Message Insertions --
405 -----------------------------------------------------
407 -- The following global variables are essentially additional parameters
408 -- passed to the error message routine for insertion sequences described
409 -- above. The reason these are passed globally is that the insertion
410 -- mechanism is essentially an untyped one in which the appropriate
411 -- variables are set depending on the specific insertion characters used.
413 -- Note that is mandatory that the caller ensure that global variables
414 -- are set before the Error_Msg call, otherwise the result is undefined.
416 Error_Msg_Col : Column_Number renames Err_Vars.Error_Msg_Col;
417 -- Column for @ insertion character in message
419 Error_Msg_Uint_1 : Uint renames Err_Vars.Error_Msg_Uint_1;
420 Error_Msg_Uint_2 : Uint renames Err_Vars.Error_Msg_Uint_2;
421 -- Uint values for ^ insertion characters in message
423 Error_Msg_Sloc : Source_Ptr renames Err_Vars.Error_Msg_Sloc;
424 -- Source location for # insertion character in message
426 Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1;
427 Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2;
428 Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3;
429 -- Name_Id values for % insertion characters in message
431 Error_Msg_File_1 : File_Name_Type renames Err_Vars.Error_Msg_File_1;
432 Error_Msg_File_2 : File_Name_Type renames Err_Vars.Error_Msg_File_2;
433 Error_Msg_File_3 : File_Name_Type renames Err_Vars.Error_Msg_File_3;
434 -- File_Name_Type values for { insertion characters in message
436 Error_Msg_Unit_1 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_1;
437 Error_Msg_Unit_2 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_2;
438 -- Unit_Name_Type values for $ insertion characters in message
440 Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1;
441 Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2;
442 -- Node_Id values for & insertion characters in message
444 Error_Msg_Qual_Level : Int renames Err_Vars.Error_Msg_Qual_Level;
445 -- Number of levels of qualification required for type name (see the
446 -- description of the } insertion character. Note that this value does
447 -- note get reset by any Error_Msg call, so the caller is responsible
450 Error_Msg_Warn : Boolean renames Err_Vars.Error_Msg_Warn;
451 -- Used if current message contains a < insertion character to indicate
452 -- if the current message is a warning message.
454 Error_Msg_String : String renames Err_Vars.Error_Msg_String;
455 Error_Msg_Strlen : Natural renames Err_Vars.Error_Msg_Strlen;
456 -- Used if current message contains a ~ insertion character to indicate
457 -- insertion of the string Error_Msg_String (1 .. Error_Msg_Strlen).
459 -----------------------------------------------------
460 -- Format of Messages and Manual Quotation Control --
461 -----------------------------------------------------
463 -- Messages are generally all in lower case, except for inserted names
464 -- and appear in one of the following three forms:
469 -- The prefixes error and warning are supplied automatically (depending
470 -- on the use of the ? insertion character), and the call to the error
471 -- message routine supplies the text. The "error: " prefix is omitted
472 -- in brief error message formats.
474 -- Reserved Ada keywords in the message are in the default keyword case
475 -- (determined from the given source program), surrounded by quotation
476 -- marks. This is achieved by spelling the reserved word in upper case
477 -- letters, which is recognized as a request for insertion of quotation
478 -- marks by the error text processor. Thus for example:
480 -- Error_Msg_AP ("IS expected");
482 -- would result in the output of one of the following:
484 -- error: "is" expected
485 -- error: "IS" expected
486 -- error: "Is" expected
488 -- the choice between these being made by looking at the casing convention
489 -- used for keywords (actually the first compilation unit keyword) in the
492 -- Note: a special exception is that RM is never treated as a keyword
493 -- but instead is copied literally into the message, this avoids the
494 -- need for writing 'R'M for all reference manual quotes.
496 -- In the case of names, the default mode for the error text processor
497 -- is to surround the name by quotation marks automatically. The case
498 -- used for the identifier names is taken from the source program where
499 -- possible, and otherwise is the default casing convention taken from
500 -- the source file usage.
502 -- In some cases, better control over the placement of quote marks is
503 -- required. This is achieved using manual quotation mode. In this mode,
504 -- one or more insertion sequences is surrounded by backquote characters.
505 -- The backquote characters are output as double quote marks, and normal
506 -- automatic insertion of quotes is suppressed between the double quotes.
509 -- Error_Msg_AP ("`END &;` expected");
511 -- generates a message like
513 -- error: "end Open_Scope;" expected
515 -- where the node specifying the name Open_Scope has been stored in
516 -- Error_Msg_Node_1 prior to the call. The great majority of error
517 -- messages operates in normal quotation mode.
519 -- Note: the normal automatic insertion of spaces before insertion
520 -- sequences (such as those that come from & and %) is suppressed in
521 -- manual quotation mode, so blanks, if needed as in the above example,
522 -- must be explicitly present.
524 ----------------------------
525 -- Message ID Definitions --
526 ----------------------------
528 subtype Error_Msg_Id is Erroutc.Error_Msg_Id;
529 function "=" (Left, Right : Error_Msg_Id) return Boolean
531 -- A type used to represent specific error messages. Used by the clients
532 -- of this package only in the context of the Get_Error_Id and
533 -- Change_Error_Text subprograms.
535 No_Error_Msg : constant Error_Msg_Id := Erroutc.No_Error_Msg;
536 -- A constant which is different from any value returned by Get_Error_Id.
537 -- Typically used by a client to indicate absense of a saved Id value.
539 function Get_Msg_Id return Error_Msg_Id renames Erroutc.Get_Msg_Id;
540 -- Returns the Id of the message most recently posted using one of the
541 -- Error_Msg routines.
543 function Get_Location (E : Error_Msg_Id) return Source_Ptr
544 renames Erroutc.Get_Location;
545 -- Returns the flag location of the error message with the given id E
547 ------------------------
548 -- List Pragmas Table --
549 ------------------------
551 -- When a pragma Page or pragma List is encountered by the parser, an
552 -- entry is made in the following table. This table is then used to
553 -- control the full listing if one is being generated. Note that the
554 -- reason we do the processing in the parser is so that we get proper
555 -- listing control even in syntax check only mode.
557 type List_Pragma_Type is (List_On, List_Off, Page);
559 type List_Pragma_Record is record
560 Ptyp : List_Pragma_Type;
564 -- Note: Ploc points to the terminating semicolon in the List_Off and Page
565 -- cases, and to the pragma keyword for List_On. In the case of a pragma
566 -- List_Off, a List_On entry is also made in the table, pointing to the
567 -- pragma keyword. This ensures that, as required, a List (Off) pragma is
568 -- listed even in list off mode.
570 package List_Pragmas is new Table.Table (
571 Table_Component_Type => List_Pragma_Record,
572 Table_Index_Type => Int,
573 Table_Low_Bound => 1,
575 Table_Increment => 200,
576 Table_Name => "List_Pragmas");
578 ---------------------------
579 -- Ignore_Errors Feature --
580 ---------------------------
582 -- In certain cases, notably for optional subunits, the compiler operates
583 -- in a mode where errors are to be ignored, and the whole unit is to be
584 -- considered as not present. To implement this we provide the following
585 -- flag to enable special handling, where error messages are suppressed,
586 -- but the Fatal_Error flag will still be set in the normal manner.
588 Ignore_Errors_Enable : Nat := 0;
589 -- Triggering switch. If non-zero, then ignore errors mode is activated.
590 -- This is a counter to allow convenient nesting of enable/disable.
592 -----------------------
593 -- CODEFIX Facility --
594 -----------------------
596 -- The GPS and GNATBench IDE's have a codefix facility that allows for
597 -- automatic correction of a subset of the errors and warnings issued
598 -- by the compiler. This is done by recognizing the text of specific
599 -- messages using appropriate matching patterns.
601 -- The text of such messages should not be altered without coordinating
602 -- with the codefix code. All such messages are marked by a specific
603 -- style of comments, as shown by the following example:
605 -- Error_Msg_N -- CODEFIX
608 -- Any message marked with this -- CODEFIX comment should not be modified
609 -- without appropriate coordination. If new messages are added which may
610 -- be susceptible to automatic codefix action, they are marked using:
612 ------------------------------
613 -- Error Output Subprograms --
614 ------------------------------
616 procedure Initialize;
617 -- Initializes for output of error messages. Must be called for each
618 -- source file before using any of the other routines in the package.
620 procedure Finalize (Last_Call : Boolean);
621 -- Finalize processing of error message list. Includes processing for
622 -- duplicated error messages, and other similar final adjustment of the
623 -- list of error messages. Note that this procedure must be called before
624 -- calling Compilation_Errors to determine if there were any errors. It
625 -- is perfectly fine to call Finalize more than once, providing that the
626 -- parameter Last_Call is set False for every call except the last call.
628 -- This multiple call capability is used to do some processing that may
629 -- generate messages. Call Finalize to eliminate duplicates and remove
630 -- deleted warnings. Test for compilation errors using Compilation_Errors,
631 -- then generate some more errors/warnings, call Finalize again to make
632 -- sure that all duplicates in these new messages are dealt with, then
633 -- finally call Output_Messages to output the final list of messages. The
634 -- argument Last_Call must be set False on all calls except the last call,
635 -- and must be set True on the last call (a value of True activates some
636 -- processing that must only be done after all messages are posted).
638 procedure Output_Messages;
639 -- Output list of messages, including messages giving number of detected
640 -- errors and warnings.
642 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
643 -- Output a message at specified location. Can be called from the parser
644 -- or the semantic analyzer.
646 procedure Error_Msg_S (Msg : String);
647 -- Output a message at current scan pointer location. This routine can be
648 -- called only from the parser, since it references Scan_Ptr.
650 procedure Error_Msg_AP (Msg : String);
651 -- Output a message just after the previous token. This routine can be
652 -- called only from the parser, since it references Prev_Token_Ptr.
654 procedure Error_Msg_BC (Msg : String);
655 -- Output a message just before the current token. Note that the important
656 -- difference between this and the previous routine is that the BC case
657 -- posts a flag on the current line, whereas AP can post a flag at the
658 -- end of the preceding line. This routine can be called only from the
659 -- parser, since it references Token_Ptr.
661 procedure Error_Msg_SC (Msg : String);
662 -- Output a message at the start of the current token, unless we are at
663 -- the end of file, in which case we always output the message after the
664 -- last real token in the file. This routine can be called only from the
665 -- parser, since it references Token_Ptr.
667 procedure Error_Msg_SP (Msg : String);
668 -- Output a message at the start of the previous token. This routine can
669 -- be called only from the parser, since it references Prev_Token_Ptr.
671 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id);
672 -- Output a message at the Sloc of the given node. This routine can be
673 -- called from the parser or the semantic analyzer, although the call from
674 -- the latter is much more common (and is the most usual way of generating
675 -- error messages from the analyzer). The message text may contain a
676 -- single & insertion, which will reference the given node. The message is
677 -- suppressed if the node N already has a message posted, or if it is a
678 -- warning and warnings and N is an entity node for which warnings are
681 procedure Error_Msg_F (Msg : String; N : Node_Id);
682 -- Similar to Error_Msg_N except that the message is placed on the first
683 -- node of the construct N (First_Node (N)).
685 procedure Error_Msg_NE
687 N : Node_Or_Entity_Id;
688 E : Node_Or_Entity_Id);
689 -- Output a message at the Sloc of the given node N, with an insertion of
690 -- the name from the given entity node E. This is used by the semantic
691 -- routines, where this is a common error message situation. The Msg text
692 -- will contain a & or } as usual to mark the insertion point. This
693 -- routine can be called from the parser or the analyzer.
695 procedure Error_Msg_FE
698 E : Node_Or_Entity_Id);
699 -- Same as Error_Msg_NE, except that the message is placed on the first
700 -- node of the construct N (First_Node (N)).
702 procedure Error_Msg_NEL
704 N : Node_Or_Entity_Id;
705 E : Node_Or_Entity_Id;
706 Flag_Location : Source_Ptr);
707 -- Exactly the same as Error_Msg_NE, except that the flag is placed at
708 -- the specified Flag_Location instead of at Sloc (N).
710 procedure Error_Msg_NW
713 N : Node_Or_Entity_Id);
714 -- This routine is used for posting a message conditionally. The message
715 -- is posted (with the same effect as Error_Msg_N (Msg, N) if and only
716 -- if Eflag is True and if the node N is within the main extended source
717 -- unit and comes from source. Typically this is a warning mode flag.
718 -- This routine can only be called during semantic analysis. It may not
719 -- be called during parsing.
721 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String);
722 -- The error message text of the message identified by Id is replaced by
723 -- the given text. This text may contain insertion characters in the
724 -- usual manner, and need not be the same length as the original text.
726 function First_Node (C : Node_Id) return Node_Id;
727 -- Given a construct C, finds the first node in the construct, i.e. the
728 -- one with the lowest Sloc value. This is useful in placing error msgs.
730 function First_Sloc (N : Node_Id) return Source_Ptr;
731 -- Given the node for an expression, return a source pointer value that
732 -- points to the start of the first token in the expression. In the case
733 -- where the expression is parenthesized, an attempt is made to include
734 -- the parentheses (i.e. to return the location of the initial paren).
736 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr)
737 renames Erroutc.Purge_Messages;
738 -- All error messages whose location is in the range From .. To (not
739 -- including the end points) will be deleted from the error listing.
741 procedure Remove_Warning_Messages (N : Node_Id);
742 -- Remove any warning messages corresponding to the Sloc of N or any
743 -- of its descendent nodes. No effect if no such warnings. Note that
744 -- style messages (identified by the fact that they start with "(style)"
745 -- are not removed by this call. Basically the idea behind this procedure
746 -- is to remove warnings about execution conditions from known dead code.
748 procedure Remove_Warning_Messages (L : List_Id);
749 -- Remove warnings on all elements of a list (Calls Remove_Warning_Messages
750 -- on each element of the list, see above).
752 procedure Set_Ignore_Errors (To : Boolean);
753 -- Following a call to this procedure with To=True, all error calls are
754 -- ignored. A call with To=False restores the default treatment in which
755 -- error calls are treated as usual (and as described in this spec).
757 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr)
758 renames Erroutc.Set_Warnings_Mode_Off;
759 -- Called in response to a pragma Warnings (Off) to record the source
760 -- location from which warnings are to be turned off.
762 procedure Set_Warnings_Mode_On (Loc : Source_Ptr)
763 renames Erroutc.Set_Warnings_Mode_On;
764 -- Called in response to a pragma Warnings (On) to record the source
765 -- location from which warnings are to be turned back on.
767 procedure Set_Specific_Warning_Off
771 renames Erroutc.Set_Specific_Warning_Off;
772 -- This is called in response to the two argument form of pragma Warnings
773 -- where the first argument is OFF, and the second argument is the prefix
774 -- of a specific warning to be suppressed. The first argument is the start
775 -- of the suppression range, and the second argument is the string from
778 procedure Set_Specific_Warning_On
782 renames Erroutc.Set_Specific_Warning_On;
783 -- This is called in response to the two argument form of pragma Warnings
784 -- where the first argument is ON, and the second argument is the prefix
785 -- of a specific warning to be suppressed. The first argument is the end
786 -- of the suppression range, and the second argument is the string from
787 -- the pragma. Err is set to True on return to report the error of no
788 -- matching Warnings Off pragma preceding this one.
790 function Compilation_Errors return Boolean;
791 -- Returns true if errors have been detected, or warnings in -gnatwe
792 -- (treat warnings as errors) mode. Note that it is mandatory to call
793 -- Finalize before calling this routine.
795 procedure Error_Msg_CRT (Feature : String; N : Node_Id);
796 -- Posts a non-fatal message on node N saying that the feature identified
797 -- by the Feature argument is not supported in either configurable
798 -- run-time mode or no run-time mode (as appropriate). In the former case,
799 -- the name of the library is output if available.
801 procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg;
802 -- Debugging routine to dump an error message
804 ------------------------------------
805 -- Utility Interface for Back End --
806 ------------------------------------
808 -- The following subprograms can be used by the back end for the purposes
809 -- of concocting error messages that are not output via Errout, e.g. the
810 -- messages generated by the gcc back end.
812 procedure Set_Identifier_Casing
813 (Identifier_Name : System.Address;
814 File_Name : System.Address);
815 -- The identifier is a null terminated string that represents the name of
816 -- an identifier appearing in the source program. File_Name is a null
817 -- terminated string giving the corresponding file name for the identifier
818 -- as obtained from the front end by the use of Full_Debug_Name to the
819 -- source file referenced by the corresponding source location value. On
820 -- return, the name is in Name_Buffer, null terminated with Name_Len set.
821 -- This name is the identifier name as passed, cased according to the
822 -- default identifier casing for the given file.