1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package contains the routines to output error messages. They are
27 -- basically system independent, however in some environments, e.g. when the
28 -- parser is embedded into an editor, it may be appropriate to replace the
29 -- implementation of this package.
33 with Namet; use Namet;
35 with Types; use Types;
36 with Uintp; use Uintp;
42 Current_Error_Source_File : Source_File_Index
43 renames Err_Vars.Current_Error_Source_File;
44 -- Id of current messages. Used to post file name when unit changes. This
45 -- is initialized to Main_Source_File at the start of a compilation, which
46 -- means that no file names will be output unless there are errors in
47 -- units other than the main unit. However, if the main unit has a pragma
48 -- Source_Reference line, then this is initialized to No_Source_File, to
49 -- force an initial reference to the real source file name.
51 Raise_Exception_On_Error : Nat renames Err_Vars.Raise_Exception_On_Error;
52 -- If this value is non-zero, then any attempt to generate an error
53 -- message raises the exception Error_Msg_Exception, and the error message
54 -- is not output. This is used for defending against junk resulting from
55 -- illegalities, and also for substitution of more appropriate error
56 -- messages from higher semantic levels. It is a counter so that the
57 -- increment/decrement protocol nests neatly.
59 Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception;
60 -- Exception raised if Raise_Exception_On_Error is true
62 Warning_Doc_Switch : Boolean renames Err_Vars.Warning_Doc_Switch;
63 -- If this is set True, then the ??/?x?/?X? sequences in error messages
64 -- are active (see errout.ads for details). If this switch is False, then
65 -- these sequences are ignored (i.e. simply equivalent to a single ?). The
66 -- -gnatw.d switch sets this flag True, -gnatw.D sets this flag False.
68 -----------------------------------
69 -- Suppression of Error Messages --
70 -----------------------------------
72 -- In an effort to reduce the impact of redundant error messages, the
73 -- error output routines in this package normally suppress certain
74 -- classes of messages as follows:
76 -- 1. Identical messages placed at the same point in the text. Such
77 -- duplicate error message result for example from rescanning
78 -- sections of the text that contain lexical errors. Only one of
79 -- such a set of duplicate messages is output, and the rest are
82 -- 2. If more than one parser message is generated for a single source
83 -- line, then only the first message is output, the remaining
84 -- messages on the same line are suppressed.
86 -- 3. If a message is posted on a node for which a message has been
87 -- previously posted, then only the first message is retained. The
88 -- Error_Posted flag is used to detect such multiple postings. Note
89 -- that this only applies to semantic messages, since otherwise
90 -- for parser messages, this would be a special case of case 2.
92 -- 4. If a message is posted on a node whose Etype or Entity
93 -- fields reference entities on which an error message has
94 -- already been placed, as indicated by the Error_Posted flag
95 -- being set on these entities, then the message is suppressed.
97 -- 5. If a message attempts to insert an Error node, or a direct
98 -- reference to the Any_Type node, then the message is suppressed.
100 -- 6. Note that cases 2-5 only apply to error messages, not warning
101 -- messages. Warning messages are only suppressed for case 1, and
102 -- when they come from other than the main extended unit.
104 -- This normal suppression action may be overridden in cases 2-5 (but not
105 -- in case 1) by setting All_Errors mode, or by setting the special
106 -- unconditional message insertion character (!) at the end of the message
107 -- text as described below.
109 ---------------------------------------------------------
110 -- Error Message Text and Message Insertion Characters --
111 ---------------------------------------------------------
113 -- Error message text strings are composed of lower case letters, digits
114 -- and the special characters space, comma, period, colon and semicolon,
115 -- apostrophe and parentheses. Special insertion characters can also
116 -- appear which cause the error message circuit to modify the given
117 -- string as follows:
119 -- Insertion character % (Percent: insert name from Names table)
120 -- The character % is replaced by the text for the name specified by
121 -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes the
122 -- name if it is preceded by a non-blank character other than left
123 -- parenthesis. The name is enclosed in quotes unless manual quotation
124 -- mode is set. If the Name_Id is set to No_Name, then no insertion
125 -- occurs; if the Name_Id is set to Error_Name, then the string
126 -- <error> is inserted. A second and third % may appear in a single
127 -- message, similarly replaced by the names which are specified by the
128 -- Name_Id values stored in Error_Msg_Name_2 and Error_Msg_Name_3. The
129 -- names are decoded and cased according to the current identifier
130 -- casing mode. Note: if a unit name ending with %b or %s is passed
131 -- for this kind of insertion, this suffix is simply stripped. Use a
132 -- unit name insertion ($) to process the suffix.
134 -- Insertion character %% (Double percent: insert literal name)
135 -- The character sequence %% acts as described above for %, except
136 -- that the name is simply obtained with Get_Name_String and is not
137 -- decoded or cased, it is inserted literally from the names table.
138 -- A trailing %b or %s is not treated specially.
140 -- Insertion character $ (Dollar: insert unit name from Names table)
141 -- The character $ is treated similarly to %, except that the name is
142 -- obtained from the Unit_Name_Type value in Error_Msg_Unit_1 and
143 -- Error_Msg_Unit_2, as provided by Get_Unit_Name_String in package
144 -- Uname. Note that this name includes the postfix (spec) or (body)
145 -- strings. If this postfix is not required, use the normal %
146 -- insertion for the unit name.
148 -- Insertion character { (Left brace: insert file name from names table)
149 -- The character { is treated similarly to %, except that the input
150 -- value is a File_Name_Type value stored in Error_Msg_File_1 or
151 -- Error_Msg_File_2 or Error_Msg_File_3. The value is output literally,
152 -- enclosed in quotes as for %, but the case is not modified, the
153 -- insertion is the exact string stored in the names table without
154 -- adjusting the casing.
156 -- Insertion character * (Asterisk, insert reserved word name)
157 -- The insertion character * is treated exactly like % except that the
158 -- resulting name is cased according to the default conventions for
159 -- reserved words (see package Scans).
161 -- Insertion character & (Ampersand: insert name from node)
162 -- The insertion character & is treated similarly to %, except that
163 -- the name is taken from the Chars field of the given node, and may
164 -- refer to a child unit name, or a selected component. The casing is,
165 -- if possible, taken from the original source reference, which is
166 -- obtained from the Sloc field of the given node or nodes. If no Sloc
167 -- is available (happens e.g. for nodes in package Standard), then the
168 -- default case (see Scans spec) is used. The nodes to be used are
169 -- stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion occurs
170 -- for the Empty node, and the Error node results in the insertion of
171 -- the characters <error>. In addition, if the special global variable
172 -- Error_Msg_Qual_Level is non-zero, then the reference will include
173 -- up to the given number of levels of qualification, using the scope
176 -- Insertion character # (Pound: insert line number reference)
177 -- The character # is replaced by the string indicating the source
178 -- position stored in Error_Msg_Sloc. There are three cases:
180 -- for package Standard: in package Standard
181 -- for locations in current file: at line nnn:ccc
182 -- for locations in other files: at filename:nnn:ccc
184 -- By convention, the # insertion character is only used at the end of
185 -- an error message, so the above strings only appear as the last
186 -- characters of an error message. The only exceptions to this rule
187 -- are that an RM reference may follow in the form (RM .....) and a
188 -- right parenthesis may immediately follow the #. In the case of
189 -- continued messages, # can only appear at the end of a group of
190 -- continuation messages, except that \\ messages which always start
191 -- a new line end the sequence from the point of view of this rule.
192 -- The idea is that for any use of -gnatj, it will still be the case
193 -- that a location reference appears only at the end of a line.
195 -- Note: the output of the string "at " is suppressed if the string
196 -- " from" or " from " immediately precedes the insertion character #.
197 -- Certain messages read better with from than at.
199 -- Insertion character } (Right brace: insert type reference)
200 -- The character } is replaced by a string describing the type
201 -- referenced by the entity whose Id is stored in Error_Msg_Node_1.
202 -- the string gives the name or description of the type, and also
203 -- where appropriate the location of its declaration. Special cases
204 -- like "some integer type" are handled appropriately. Only one } is
205 -- allowed in a message, since there is not enough room for two (the
206 -- insertion can be quite long, including a file name) In addition, if
207 -- the special global variable Error_Msg_Qual_Level is non-zero, then
208 -- the reference will include up to the given number of levels of
209 -- qualification, using the scope chain.
211 -- Insertion character @ (At: insert column number reference)
212 -- The character @ is replaced by null if the RM_Column_Check mode is
213 -- off (False). If the switch is on (True), then @ is replaced by the
214 -- text string " in column nnn" where nnn is the decimal
215 -- representation of the column number stored in Error_Msg_Col plus
216 -- one (the plus one is because the number is stored 0-origin and
217 -- displayed 1-origin).
219 -- Insertion character ^ (Caret: insert integer value)
220 -- The character ^ is replaced by the decimal conversion of the Uint
221 -- value stored in Error_Msg_Uint_1, with a possible leading minus.
222 -- A second ^ may occur in the message, in which case it is replaced
223 -- by the decimal conversion of the Uint value in Error_Msg_Uint_2.
225 -- Insertion character > (Right bracket, run time name)
226 -- The character > is replaced by a string of the form (name) if
227 -- Targparm scanned out a Run_Time_Name (see package Targparm for
228 -- details). The name is enclosed in parentheses and output in mixed
229 -- case mode (upper case after any space in the name). If no run time
230 -- name is defined, this insertion character has no effect.
232 -- Insertion character ! (Exclamation: unconditional message)
233 -- The character ! appearing as the last character of a message makes
234 -- the message unconditional which means that it is output even if it
235 -- would normally be suppressed. See section above for a description
236 -- of the cases in which messages are normally suppressed. Note that
237 -- in the case of warnings, the meaning is that the warning should not
238 -- be removed in dead code (that's the only time that the use of !
239 -- has any effect for a warning).
241 -- Note: the presence of ! is ignored in continuation messages (i.e.
242 -- messages starting with the \ insertion character). The effect of the
243 -- use of ! in a parent message automatically applies to all of its
244 -- continuation messages (since we clearly don't want any case in which
245 -- continuations are separated from the parent message. It is allowable
246 -- to put ! in continuation messages, and the usual style is to include
247 -- it, since it makes it clear that the continuation is part of an
248 -- unconditional message.
250 -- Insertion character !! (Double exclamation: unconditional warning)
251 -- Normally warning messages issued in other than the main unit are
252 -- suppressed. If the message ends with !! then this suppression is
253 -- avoided. This is currently used by the Compile_Time_Warning pragma
254 -- to ensure the message for a with'ed unit is output, and for warnings
255 -- on ineffective back-end inlining, which is detected in units that
256 -- contain subprograms to be inlined in the main program.
258 -- Insertion character ? (Question: warning message)
259 -- The character ? appearing anywhere in a message makes the message
260 -- warning instead of a normal error message, and the text of the
261 -- message will be preceded by "warning:" in the normal case. The
262 -- handling of warnings if further controlled by the Warning_Mode
263 -- option (-w switch), see package Opt for further details, and also by
264 -- the current setting from pragma Warnings. This pragma applies only
265 -- to warnings issued from the semantic phase (not the parser), but
266 -- currently all relevant warnings are posted by the semantic phase
267 -- anyway. Messages starting with (style) are also treated as warning
270 -- Note: when a warning message is output, the text of the message is
271 -- preceded by "warning: " in the normal case. An exception to this
272 -- rule occurs when the text of the message starts with "info: " in
273 -- which case this string is not prepended. This allows callers to
274 -- label certain warnings as informational messages, rather than as
275 -- warning messages requiring some action.
277 -- Note: the presence of ? is ignored in continuation messages (i.e.
278 -- messages starting with the \ insertion character). The warning
279 -- status of continuations is determined only by the parent message
280 -- which is being continued. It is allowable to put ? in continuation
281 -- messages, and the usual style is to include it, since it makes it
282 -- clear that the continuation is part of a warning message.
284 -- Insertion character ?? (two question marks)
285 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string
286 -- "[enabled by default]" at the end of the warning message. In the
287 -- case of continuations, use this in each continuation message.
289 -- Insertion character ?x? (warning with switch)
290 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string
291 -- "[-gnatwx]" at the end of the warning message. x is a lower case
292 -- letter. In the case of continuations, use this on each continuation
295 -- Insertion character ?X? (warning with dot switch)
296 -- Like ?, but if the flag Warn_Doc_Switch is True, adds the string
297 -- "[-gnatw.x]" at the end of the warning message. X is an upper case
298 -- letter corresponding to the lower case letter x in the message. In
299 -- the case of continuations, use this on each continuation
302 -- Insertion character < (Less Than: conditional warning message)
303 -- The character < appearing anywhere in a message is used for a
304 -- conditional error message. If Error_Msg_Warn is True, then the
305 -- effect is the same as ? described above. If Error_Msg_Warn is
306 -- False, then there is no effect.
308 -- Insertion character A-Z (Upper case letter: Ada reserved word)
309 -- If two or more upper case letters appear in the message, they are
310 -- taken as an Ada reserved word, and are converted to the default
311 -- case for reserved words (see Scans package spec). Surrounding
312 -- quotes are added unless manual quotation mode is currently set.
314 -- Insertion character ` (Backquote: set manual quotation mode)
315 -- The backquote character always appears in pairs. Each backquote of
316 -- the pair is replaced by a double quote character. In addition, any
317 -- reserved keywords, or name insertions between these backquotes are
318 -- not surrounded by the usual automatic double quotes. See the
319 -- section below on manual quotation mode for further details.
321 -- Insertion character ' (Quote: literal character)
322 -- Precedes a character which is placed literally into the message.
323 -- Used to insert characters into messages that are one of the
324 -- insertion characters defined here. Also useful in inserting
325 -- sequences of upper case letters which are not to be treated as
328 -- Insertion character \ (Backslash: continuation message)
329 -- Indicates that the message is a continuation of a message
330 -- previously posted. This is used to ensure that such groups of
331 -- messages are treated as a unit. The \ character must be the first
332 -- character of the message text.
334 -- Insertion character \\ (Two backslashes, continuation with new line)
335 -- This differs from \ only in -gnatjnn mode (Error_Message_Line_Length
336 -- set non-zero). This sequence forces a new line to start even when
337 -- continuations are being gathered into a single message.
339 -- Insertion character | (Vertical bar: non-serious error)
340 -- By default, error messages (other than warning messages) are
341 -- considered to be fatal error messages which prevent expansion or
342 -- generation of code in the presence of the -gnatQ switch. If the
343 -- insertion character | appears, the message is considered to be
344 -- non-serious, and does not cause Serious_Errors_Detected to be
345 -- incremented (so expansion is not prevented by such a msg).
347 -- Insertion character ~ (Tilde: insert string)
348 -- Indicates that Error_Msg_String (1 .. Error_Msg_Strlen) is to be
349 -- inserted to replace the ~ character. The string is inserted in the
350 -- literal form it appears, without any action on special characters.
352 ----------------------------------------
353 -- Specialization of Messages for VMS --
354 ----------------------------------------
356 -- Some messages mention gcc-style switch names. When using an OpenVMS
357 -- host, such switch names must be converted to their corresponding VMS
358 -- qualifer. The following table controls this translation. In each case
359 -- the original message must contain the string "-xxx switch", where xxx
360 -- is the Gname? entry from below, and this string will be replaced by
361 -- "/yyy qualifier", where yyy is the corresponding Vname? entry.
363 Gname1 : aliased constant String := "fno-strict-aliasing";
364 Vname1 : aliased constant String := "OPTIMIZE=NO_STRICT_ALIASING";
366 Gname2 : aliased constant String := "gnatX";
367 Vname2 : aliased constant String := "EXTENSIONS_ALLOWED";
369 Gname3 : aliased constant String := "gnatW";
370 Vname3 : aliased constant String := "WIDE_CHARACTER_ENCODING";
372 Gname4 : aliased constant String := "gnatf";
373 Vname4 : aliased constant String := "REPORT_ERRORS=FULL";
375 Gname5 : aliased constant String := "gnat05";
376 Vname5 : aliased constant String := "05";
378 Gname6 : aliased constant String := "gnat2005";
379 Vname6 : aliased constant String := "2005";
381 Gname7 : aliased constant String := "gnat12";
382 Vname7 : aliased constant String := "12";
384 Gname8 : aliased constant String := "gnat2012";
385 Vname8 : aliased constant String := "2012";
387 Gname9 : aliased constant String := "gnateinn";
388 Vname9 : aliased constant String := "MAX_INSTANTIATIONS=nn";
390 type Cstring_Ptr is access constant String;
392 Gnames : array (Nat range <>) of Cstring_Ptr :=
403 Vnames : array (Nat range <>) of Cstring_Ptr :=
414 -----------------------------------------------------
415 -- Global Values Used for Error Message Insertions --
416 -----------------------------------------------------
418 -- The following global variables are essentially additional parameters
419 -- passed to the error message routine for insertion sequences described
420 -- above. The reason these are passed globally is that the insertion
421 -- mechanism is essentially an untyped one in which the appropriate
422 -- variables are set depending on the specific insertion characters used.
424 -- Note that is mandatory that the caller ensure that global variables
425 -- are set before the Error_Msg call, otherwise the result is undefined.
427 Error_Msg_Col : Column_Number renames Err_Vars.Error_Msg_Col;
428 -- Column for @ insertion character in message
430 Error_Msg_Uint_1 : Uint renames Err_Vars.Error_Msg_Uint_1;
431 Error_Msg_Uint_2 : Uint renames Err_Vars.Error_Msg_Uint_2;
432 -- Uint values for ^ insertion characters in message
434 Error_Msg_Sloc : Source_Ptr renames Err_Vars.Error_Msg_Sloc;
435 -- Source location for # insertion character in message
437 Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1;
438 Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2;
439 Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3;
440 -- Name_Id values for % insertion characters in message
442 Error_Msg_File_1 : File_Name_Type renames Err_Vars.Error_Msg_File_1;
443 Error_Msg_File_2 : File_Name_Type renames Err_Vars.Error_Msg_File_2;
444 Error_Msg_File_3 : File_Name_Type renames Err_Vars.Error_Msg_File_3;
445 -- File_Name_Type values for { insertion characters in message
447 Error_Msg_Unit_1 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_1;
448 Error_Msg_Unit_2 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_2;
449 -- Unit_Name_Type values for $ insertion characters in message
451 Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1;
452 Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2;
453 -- Node_Id values for & insertion characters in message
455 Error_Msg_Qual_Level : Int renames Err_Vars.Error_Msg_Qual_Level;
456 -- Number of levels of qualification required for type name (see the
457 -- description of the } insertion character). Note that this value does
458 -- note get reset by any Error_Msg call, so the caller is responsible
461 Error_Msg_Warn : Boolean renames Err_Vars.Error_Msg_Warn;
462 -- Used if current message contains a < insertion character to indicate
463 -- if the current message is a warning message. Must be set appropriately
464 -- before any call to Error_Msg_xxx with a < insertion character present.
465 -- Setting is irrelevant if no < insertion character is present.
467 Error_Msg_String : String renames Err_Vars.Error_Msg_String;
468 Error_Msg_Strlen : Natural renames Err_Vars.Error_Msg_Strlen;
469 -- Used if current message contains a ~ insertion character to indicate
470 -- insertion of the string Error_Msg_String (1 .. Error_Msg_Strlen).
472 -----------------------------------------------------
473 -- Format of Messages and Manual Quotation Control --
474 -----------------------------------------------------
476 -- Messages are generally all in lower case, except for inserted names
477 -- and appear in one of the following three forms:
482 -- The prefixes error and warning are supplied automatically (depending
483 -- on the use of the ? insertion character), and the call to the error
484 -- message routine supplies the text. The "error: " prefix is omitted
485 -- in brief error message formats.
487 -- Reserved Ada keywords in the message are in the default keyword case
488 -- (determined from the given source program), surrounded by quotation
489 -- marks. This is achieved by spelling the reserved word in upper case
490 -- letters, which is recognized as a request for insertion of quotation
491 -- marks by the error text processor. Thus for example:
493 -- Error_Msg_AP ("IS expected");
495 -- would result in the output of one of the following:
497 -- error: "is" expected
498 -- error: "IS" expected
499 -- error: "Is" expected
501 -- the choice between these being made by looking at the casing convention
502 -- used for keywords (actually the first compilation unit keyword) in the
505 -- Note: a special exception is that RM is never treated as a keyword
506 -- but instead is copied literally into the message, this avoids the
507 -- need for writing 'R'M for all reference manual quotes. A similar
508 -- exception is applied to the occurrence of the string Alfa used in
509 -- error messages about the Alfa subset of Ada.
511 -- In the case of names, the default mode for the error text processor
512 -- is to surround the name by quotation marks automatically. The case
513 -- used for the identifier names is taken from the source program where
514 -- possible, and otherwise is the default casing convention taken from
515 -- the source file usage.
517 -- In some cases, better control over the placement of quote marks is
518 -- required. This is achieved using manual quotation mode. In this mode,
519 -- one or more insertion sequences is surrounded by backquote characters.
520 -- The backquote characters are output as double quote marks, and normal
521 -- automatic insertion of quotes is suppressed between the double quotes.
524 -- Error_Msg_AP ("`END &;` expected");
526 -- generates a message like
528 -- error: "end Open_Scope;" expected
530 -- where the node specifying the name Open_Scope has been stored in
531 -- Error_Msg_Node_1 prior to the call. The great majority of error
532 -- messages operates in normal quotation mode.
534 -- Note: the normal automatic insertion of spaces before insertion
535 -- sequences (such as those that come from & and %) is suppressed in
536 -- manual quotation mode, so blanks, if needed as in the above example,
537 -- must be explicitly present.
539 ----------------------------
540 -- Message ID Definitions --
541 ----------------------------
543 subtype Error_Msg_Id is Erroutc.Error_Msg_Id;
544 function "=" (Left, Right : Error_Msg_Id) return Boolean
546 -- A type used to represent specific error messages. Used by the clients
547 -- of this package only in the context of the Get_Error_Id and
548 -- Change_Error_Text subprograms.
550 No_Error_Msg : constant Error_Msg_Id := Erroutc.No_Error_Msg;
551 -- A constant which is different from any value returned by Get_Error_Id.
552 -- Typically used by a client to indicate absense of a saved Id value.
554 function Get_Msg_Id return Error_Msg_Id renames Erroutc.Get_Msg_Id;
555 -- Returns the Id of the message most recently posted using one of the
556 -- Error_Msg routines.
558 function Get_Location (E : Error_Msg_Id) return Source_Ptr
559 renames Erroutc.Get_Location;
560 -- Returns the flag location of the error message with the given id E
562 ------------------------
563 -- List Pragmas Table --
564 ------------------------
566 -- When a pragma Page or pragma List is encountered by the parser, an
567 -- entry is made in the following table. This table is then used to
568 -- control the full listing if one is being generated. Note that the
569 -- reason we do the processing in the parser is so that we get proper
570 -- listing control even in syntax check only mode.
572 type List_Pragma_Type is (List_On, List_Off, Page);
574 type List_Pragma_Record is record
575 Ptyp : List_Pragma_Type;
579 -- Note: Ploc points to the terminating semicolon in the List_Off and Page
580 -- cases, and to the pragma keyword for List_On. In the case of a pragma
581 -- List_Off, a List_On entry is also made in the table, pointing to the
582 -- pragma keyword. This ensures that, as required, a List (Off) pragma is
583 -- listed even in list off mode.
585 package List_Pragmas is new Table.Table (
586 Table_Component_Type => List_Pragma_Record,
587 Table_Index_Type => Int,
588 Table_Low_Bound => 1,
590 Table_Increment => 200,
591 Table_Name => "List_Pragmas");
593 ---------------------------
594 -- Ignore_Errors Feature --
595 ---------------------------
597 -- In certain cases, notably for optional subunits, the compiler operates
598 -- in a mode where errors are to be ignored, and the whole unit is to be
599 -- considered as not present. To implement this we provide the following
600 -- flag to enable special handling, where error messages are suppressed,
601 -- but the Fatal_Error flag will still be set in the normal manner.
603 Ignore_Errors_Enable : Nat := 0;
604 -- Triggering switch. If non-zero, then ignore errors mode is activated.
605 -- This is a counter to allow convenient nesting of enable/disable.
607 -----------------------
608 -- CODEFIX Facility --
609 -----------------------
611 -- The GPS and GNATBench IDE's have a codefix facility that allows for
612 -- automatic correction of a subset of the errors and warnings issued
613 -- by the compiler. This is done by recognizing the text of specific
614 -- messages using appropriate matching patterns.
616 -- The text of such messages should not be altered without coordinating
617 -- with the codefix code. All such messages are marked by a specific
618 -- style of comments, as shown by the following example:
620 -- Error_Msg_N -- CODEFIX
623 -- Any message marked with this -- CODEFIX comment should not be modified
624 -- without appropriate coordination.
626 ------------------------------
627 -- Error Output Subprograms --
628 ------------------------------
630 procedure Initialize;
631 -- Initializes for output of error messages. Must be called for each
632 -- source file before using any of the other routines in the package.
634 procedure Finalize (Last_Call : Boolean);
635 -- Finalize processing of error message list. Includes processing for
636 -- duplicated error messages, and other similar final adjustment of the
637 -- list of error messages. Note that this procedure must be called before
638 -- calling Compilation_Errors to determine if there were any errors. It
639 -- is perfectly fine to call Finalize more than once, providing that the
640 -- parameter Last_Call is set False for every call except the last call.
642 -- This multiple call capability is used to do some processing that may
643 -- generate messages. Call Finalize to eliminate duplicates and remove
644 -- deleted warnings. Test for compilation errors using Compilation_Errors,
645 -- then generate some more errors/warnings, call Finalize again to make
646 -- sure that all duplicates in these new messages are dealt with, then
647 -- finally call Output_Messages to output the final list of messages. The
648 -- argument Last_Call must be set False on all calls except the last call,
649 -- and must be set True on the last call (a value of True activates some
650 -- processing that must only be done after all messages are posted).
652 procedure Output_Messages;
653 -- Output list of messages, including messages giving number of detected
654 -- errors and warnings.
656 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
657 -- Output a message at specified location. Can be called from the parser
658 -- or the semantic analyzer.
660 procedure Error_Msg_S (Msg : String);
661 -- Output a message at current scan pointer location. This routine can be
662 -- called only from the parser, since it references Scan_Ptr.
664 procedure Error_Msg_AP (Msg : String);
665 -- Output a message just after the previous token. This routine can be
666 -- called only from the parser, since it references Prev_Token_Ptr.
668 procedure Error_Msg_BC (Msg : String);
669 -- Output a message just before the current token. Note that the important
670 -- difference between this and the previous routine is that the BC case
671 -- posts a flag on the current line, whereas AP can post a flag at the
672 -- end of the preceding line. This routine can be called only from the
673 -- parser, since it references Token_Ptr.
675 procedure Error_Msg_SC (Msg : String);
676 -- Output a message at the start of the current token, unless we are at
677 -- the end of file, in which case we always output the message after the
678 -- last real token in the file. This routine can be called only from the
679 -- parser, since it references Token_Ptr.
681 procedure Error_Msg_SP (Msg : String);
682 -- Output a message at the start of the previous token. This routine can
683 -- be called only from the parser, since it references Prev_Token_Ptr.
685 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id);
686 -- Output a message at the Sloc of the given node. This routine can be
687 -- called from the parser or the semantic analyzer, although the call from
688 -- the latter is much more common (and is the most usual way of generating
689 -- error messages from the analyzer). The message text may contain a
690 -- single & insertion, which will reference the given node. The message is
691 -- suppressed if the node N already has a message posted, or if it is a
692 -- warning and N is an entity node for which warnings are suppressed.
694 procedure Error_Msg_F (Msg : String; N : Node_Id);
695 -- Similar to Error_Msg_N except that the message is placed on the first
696 -- node of the construct N (First_Node (N)).
698 procedure Error_Msg_NE
700 N : Node_Or_Entity_Id;
701 E : Node_Or_Entity_Id);
702 -- Output a message at the Sloc of the given node N, with an insertion of
703 -- the name from the given entity node E. This is used by the semantic
704 -- routines, where this is a common error message situation. The Msg text
705 -- will contain a & or } as usual to mark the insertion point. This
706 -- routine can be called from the parser or the analyzer.
708 procedure Error_Msg_FE
711 E : Node_Or_Entity_Id);
712 -- Same as Error_Msg_NE, except that the message is placed on the first
713 -- node of the construct N (First_Node (N)).
715 procedure Error_Msg_NEL
717 N : Node_Or_Entity_Id;
718 E : Node_Or_Entity_Id;
719 Flag_Location : Source_Ptr);
720 -- Exactly the same as Error_Msg_NE, except that the flag is placed at
721 -- the specified Flag_Location instead of at Sloc (N).
723 procedure Error_Msg_NW
726 N : Node_Or_Entity_Id);
727 -- This routine is used for posting a message conditionally. The message
728 -- is posted (with the same effect as Error_Msg_N (Msg, N) if and only
729 -- if Eflag is True and if the node N is within the main extended source
730 -- unit and comes from source. Typically this is a warning mode flag.
731 -- This routine can only be called during semantic analysis. It may not
732 -- be called during parsing.
734 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String);
735 -- The error message text of the message identified by Id is replaced by
736 -- the given text. This text may contain insertion characters in the
737 -- usual manner, and need not be the same length as the original text.
739 function First_Node (C : Node_Id) return Node_Id;
740 -- Given a construct C, finds the first node in the construct, i.e. the
741 -- one with the lowest Sloc value. This is useful in placing error msgs.
743 function First_Sloc (N : Node_Id) return Source_Ptr;
744 -- Given the node for an expression, return a source pointer value that
745 -- points to the start of the first token in the expression. In the case
746 -- where the expression is parenthesized, an attempt is made to include
747 -- the parentheses (i.e. to return the location of the initial paren).
749 function Get_Ignore_Errors return Boolean;
750 -- Return True if all error calls are ignored.
752 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr)
753 renames Erroutc.Purge_Messages;
754 -- All error messages whose location is in the range From .. To (not
755 -- including the end points) will be deleted from the error listing.
757 procedure Remove_Warning_Messages (N : Node_Id);
758 -- Remove any warning messages corresponding to the Sloc of N or any
759 -- of its descendent nodes. No effect if no such warnings. Note that
760 -- style messages (identified by the fact that they start with "(style)"
761 -- are not removed by this call. Basically the idea behind this procedure
762 -- is to remove warnings about execution conditions from known dead code.
764 procedure Remove_Warning_Messages (L : List_Id);
765 -- Remove warnings on all elements of a list (Calls Remove_Warning_Messages
766 -- on each element of the list, see above).
768 procedure Set_Ignore_Errors (To : Boolean);
769 -- Following a call to this procedure with To=True, all error calls are
770 -- ignored. A call with To=False restores the default treatment in which
771 -- error calls are treated as usual (and as described in this spec).
773 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr)
774 renames Erroutc.Set_Warnings_Mode_Off;
775 -- Called in response to a pragma Warnings (Off) to record the source
776 -- location from which warnings are to be turned off.
778 procedure Set_Warnings_Mode_On (Loc : Source_Ptr)
779 renames Erroutc.Set_Warnings_Mode_On;
780 -- Called in response to a pragma Warnings (On) to record the source
781 -- location from which warnings are to be turned back on.
783 procedure Set_Specific_Warning_Off
787 Used : Boolean := False)
788 renames Erroutc.Set_Specific_Warning_Off;
789 -- This is called in response to the two argument form of pragma Warnings
790 -- where the first argument is OFF, and the second argument is the prefix
791 -- of a specific warning to be suppressed. The first argument is the start
792 -- of the suppression range, and the second argument is the string from
795 procedure Set_Specific_Warning_On
799 renames Erroutc.Set_Specific_Warning_On;
800 -- This is called in response to the two argument form of pragma Warnings
801 -- where the first argument is ON, and the second argument is the prefix
802 -- of a specific warning to be suppressed. The first argument is the end
803 -- of the suppression range, and the second argument is the string from
804 -- the pragma. Err is set to True on return to report the error of no
805 -- matching Warnings Off pragma preceding this one.
807 function Compilation_Errors return Boolean;
808 -- Returns true if errors have been detected, or warnings in -gnatwe
809 -- (treat warnings as errors) mode. Note that it is mandatory to call
810 -- Finalize before calling this routine.
812 procedure Error_Msg_CRT (Feature : String; N : Node_Id);
813 -- Posts a non-fatal message on node N saying that the feature identified
814 -- by the Feature argument is not supported in either configurable
815 -- run-time mode or no run-time mode (as appropriate). In the former case,
816 -- the name of the library is output if available.
818 procedure Error_Msg_PT (Typ : Node_Id; Subp : Node_Id);
819 -- Posts an error on the protected type declaration Typ indicating wrong
820 -- mode of the first formal of protected type primitive Subp.
822 procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg;
823 -- Debugging routine to dump an error message
825 ------------------------------------
826 -- Utility Interface for Back End --
827 ------------------------------------
829 -- The following subprograms can be used by the back end for the purposes
830 -- of concocting error messages that are not output via Errout, e.g. the
831 -- messages generated by the gcc back end.
833 procedure Set_Identifier_Casing
834 (Identifier_Name : System.Address;
835 File_Name : System.Address);
836 -- The identifier is a null terminated string that represents the name of
837 -- an identifier appearing in the source program. File_Name is a null
838 -- terminated string giving the corresponding file name for the identifier
839 -- as obtained from the front end by the use of Full_Debug_Name to the
840 -- source file referenced by the corresponding source location value. On
841 -- return, the name is in Name_Buffer, null terminated with Name_Len set.
842 -- This name is the identifier name as passed, cased according to the
843 -- default identifier casing for the given file.