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. 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 Serious_Errors_Detected : Nat renames Err_Vars.Serious_Errors_Detected;
43 -- This is a count of errors that are serious enough to stop expansion,
44 -- and hence to prevent generation of an object file even if the switch
47 Total_Errors_Detected : Nat renames Err_Vars.Total_Errors_Detected;
48 -- Number of errors detected so far. Includes count of serious errors and
49 -- non-serious errors, so this value is always greater than or equal to
50 -- the Serious_Errors_Detected value.
52 Warnings_Detected : Nat renames Err_Vars.Warnings_Detected;
53 -- Number of warnings detected
55 Configurable_Run_Time_Violations : Nat := 0;
56 -- Count of configurable run time violations so far. This is used to
57 -- suppress certain cascaded error messages when we know that we may not
58 -- have fully expanded some items, due to high integrity violations (i.e.
59 -- the use of constructs not permitted by the library in use, or improper
60 -- constructs in No_Run_Time mode).
62 Current_Error_Source_File : Source_File_Index
63 renames Err_Vars.Current_Error_Source_File;
64 -- Id of current messages. Used to post file name when unit changes. This
65 -- is initialized to Main_Source_File at the start of a compilation, which
66 -- means that no file names will be output unless there are errors in
67 -- units other than the main unit. However, if the main unit has a pragma
68 -- Source_Reference line, then this is initialized to No_Source_File, to
69 -- force an initial reference to the real source file name.
71 Raise_Exception_On_Error : Nat renames Err_Vars.Raise_Exception_On_Error;
72 -- If this value is non-zero, then any attempt to generate an error
73 -- message raises the exception Error_Msg_Exception, and the error message
74 -- is not output. This is used for defending against junk resulting from
75 -- illegalities, and also for substitution of more appropriate error
76 -- messages from higher semantic levels. It is a counter so that the
77 -- increment/decrement protocol nests neatly.
79 Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception;
80 -- Exception raised if Raise_Exception_On_Error is true
82 -----------------------------------
83 -- Suppression of Error Messages --
84 -----------------------------------
86 -- In an effort to reduce the impact of redundant error messages, the
87 -- error output routines in this package normally suppress certain
88 -- classes of messages as follows:
90 -- 1. Identical messages placed at the same point in the text. Such
91 -- duplicate error message result for example from rescanning
92 -- sections of the text that contain lexical errors. Only one of
93 -- such a set of duplicate messages is output, and the rest are
96 -- 2. If more than one parser message is generated for a single source
97 -- line, then only the first message is output, the remaining
98 -- messages on the same line are suppressed.
100 -- 3. If a message is posted on a node for which a message has been
101 -- previously posted, then only the first message is retained. The
102 -- Error_Posted flag is used to detect such multiple postings. Note
103 -- that this only applies to semantic messages, since otherwise
104 -- for parser messages, this would be a special case of case 2.
106 -- 4. If a message is posted on a node whose Etype or Entity
107 -- fields reference entities on which an error message has
108 -- already been placed, as indicated by the Error_Posted flag
109 -- being set on these entities, then the message is suppressed.
111 -- 5. If a message attempts to insert an Error node, or a direct
112 -- reference to the Any_Type node, then the message is suppressed.
114 -- 6. Note that cases 2-5 only apply to error messages, not warning
115 -- messages. Warning messages are only suppressed for case 1, and
116 -- when they come from other than the main extended unit.
118 -- This normal suppression action may be overridden in cases 2-5 (but not
119 -- in case 1) by setting All_Errors mode, or by setting the special
120 -- unconditional message insertion character (!) at the end of the message
121 -- text as described below.
123 ---------------------------------------------------------
124 -- Error Message Text and Message Insertion Characters --
125 ---------------------------------------------------------
127 -- Error message text strings are composed of lower case letters, digits
128 -- and the special characters space, comma, period, colon and semicolon,
129 -- apostrophe and parentheses. Special insertion characters can also
130 -- appear which cause the error message circuit to modify the given
131 -- string as follows:
133 -- Insertion character % (Percent: insert name from Names table)
134 -- The character % is replaced by the text for the name specified by
135 -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes the
136 -- name if it is preceded by a non-blank character other than left
137 -- parenthesis. The name is enclosed in quotes unless manual quotation
138 -- mode is set. If the Name_Id is set to No_Name, then no insertion
139 -- occurs; if the Name_Id is set to Error_Name, then the string
140 -- <error> is inserted. A second and third % may appear in a single
141 -- message, similarly replaced by the names which are specified by the
142 -- Name_Id values stored in Error_Msg_Name_2 and Error_Msg_Name_3. The
143 -- names are decoded and cased according to the current identifier
144 -- casing mode. Note: if a unit name ending with %b or %s is passed
145 -- for this kind of insertion, this suffix is simply stripped. Use a
146 -- unit name insertion ($) to process the suffix.
148 -- Insertion character %% (Double percent: insert literal name)
149 -- The character sequence %% acts as described above for %, except
150 -- that the name is simply obtained with Get_Name_String and is not
151 -- decoded or cased, it is inserted literally from the names table.
152 -- A trailing %b or %s is not treated specially.
154 -- Insertion character $ (Dollar: insert unit name from Names table)
155 -- The character $ is treated similarly to %, except that the name is
156 -- obtained from the Unit_Name_Type value in Error_Msg_Unit_1 and
157 -- Error_Msg_Unit_2, as provided by Get_Unit_Name_String in package
158 -- Uname. Note that this name includes the postfix (spec) or (body)
159 -- strings. If this postfix is not required, use the normal %
160 -- insertion for the unit name.
162 -- Insertion character { (Left brace: insert file name from names table)
163 -- The character { is treated similarly to %, except that the input
164 -- value is a File_Name_Type value stored in Error_Msg_File_1 or
165 -- Error_Msg_File_2 or Error_Msg_File_3. The value is output literally,
166 -- enclosed in quotes as for %, but the case is not modified, the
167 -- insertion is the exact string stored in the names table without
168 -- adjusting the casing.
170 -- Insertion character * (Asterisk, insert reserved word name)
171 -- The insertion character * is treated exactly like % except that the
172 -- resulting name is cased according to the default conventions for
173 -- reserved words (see package Scans).
175 -- Insertion character & (Ampersand: insert name from node)
176 -- The insertion character & is treated similarly to %, except that
177 -- the name is taken from the Chars field of the given node, and may
178 -- refer to a child unit name, or a selected component. The casing is,
179 -- if possible, taken from the original source reference, which is
180 -- obtained from the Sloc field of the given node or nodes. If no Sloc
181 -- is available (happens e.g. for nodes in package Standard), then the
182 -- default case (see Scans spec) is used. The nodes to be used are
183 -- stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion occurs
184 -- for the Empty node, and the Error node results in the insertion of
185 -- the characters <error>. In addition, if the special global variable
186 -- Error_Msg_Qual_Level is non-zero, then the reference will include
187 -- up to the given number of levels of qualification, using the scope
190 -- Insertion character # (Pound: insert line number reference)
191 -- The character # is replaced by the string indicating the source
192 -- position stored in Error_Msg_Sloc. There are three cases:
194 -- for package Standard: in package Standard
195 -- for locations in current file: at line nnn:ccc
196 -- for locations in other files: at filename:nnn:ccc
198 -- By convention, the # insertion character is only used at the end of
199 -- an error message, so the above strings only appear as the last
200 -- characters of an error message. The only exceptions to this rule
201 -- are that an RM reference may follow in the form (RM .....) and a
202 -- right parenthesis may immediately follow the #. In the case of
203 -- continued messages, # can only appear at the end of a group of
204 -- continuation messages, except that \\ messages which always start
205 -- a new line end the sequence from the point of view of this rule.
206 -- The idea is that for any use of -gnatj, it will still be the case
207 -- that a location reference appears only at the end of a line.
209 -- Note: the output of the string "at " is suppressed if the string
210 -- " from" or " from " immediately precedes the insertion character #.
211 -- Certain messages read better with from than at.
213 -- Insertion character } (Right brace: insert type reference)
214 -- The character } is replaced by a string describing the type
215 -- referenced by the entity whose Id is stored in Error_Msg_Node_1.
216 -- the string gives the name or description of the type, and also
217 -- where appropriate the location of its declaration. Special cases
218 -- like "some integer type" are handled appropriately. Only one } is
219 -- allowed in a message, since there is not enough room for two (the
220 -- insertion can be quite long, including a file name) In addition, if
221 -- the special global variable Error_Msg_Qual_Level is non-zero, then
222 -- the reference will include up to the given number of levels of
223 -- qualification, using the scope chain.
225 -- Insertion character @ (At: insert column number reference)
226 -- The character @ is replaced by null if the RM_Column_Check mode is
227 -- off (False). If the switch is on (True), then @ is replaced by the
228 -- text string " in column nnn" where nnn is the decimal
229 -- representation of the column number stored in Error_Msg_Col plus
230 -- one (the plus one is because the number is stored 0-origin and
231 -- displayed 1-origin).
233 -- Insertion character ^ (Carret: insert integer value)
234 -- The character ^ is replaced by the decimal conversion of the Uint
235 -- value stored in Error_Msg_Uint_1, with a possible leading minus.
236 -- A second ^ may occur in the message, in which case it is replaced
237 -- by the decimal conversion of the Uint value in Error_Msg_Uint_2.
239 -- Insertion character > (Right bracket, run time name)
240 -- The character > is replaced by a string of the form (name) if
241 -- Targparm scanned out a Run_Time_Name (see package Targparm for
242 -- details). The name is enclosed in parentheses and output in mixed
243 -- case mode (upper case after any space in the name). If no run time
244 -- name is defined, this insertion character has no effect.
246 -- Insertion character ! (Exclamation: unconditional message)
247 -- The character ! appearing as the last character of a message makes
248 -- the message unconditional which means that it is output even if it
249 -- would normally be suppressed. See section above for a description
250 -- of the cases in which messages are normally suppressed. Note that
251 -- in the case of warnings, the meaning is that the warning should not
252 -- be removed in dead code (that's the only time that the use of !
253 -- has any effect for a warning).
255 -- Note: the presence of ! is ignored in continuation messages (i.e.
256 -- messages starting with the \ insertion character). The effect of the
257 -- use of ! in a parent message automatically applies to all of its
258 -- continuation messages (since we clearly don't want any case in which
259 -- continuations are separated from the parent message. It is allowable
260 -- to put ! in continuation messages, and the usual style is to include
261 -- it, since it makes it clear that the continuation is part of an
262 -- unconditional message.
264 -- Insertion character !! (unconditional warning)
266 -- Normally warning messages issued in other than the main unit are
267 -- suppressed. If the message ends with !! then this suppression is
268 -- avoided. This is currently used by the Compile_Time_Warning pragma
269 -- to ensure the message for a with'ed unit is output, and for warnings
270 -- on ineffective back-end inlining, which is detected in units that
271 -- contain subprograms to be inlined in the main program.
273 -- Insertion character ? (Question: warning message)
274 -- The character ? appearing anywhere in a message makes the message
275 -- warning instead of a normal error message, and the text of the
276 -- message will be preceded by "warning:" in the normal case. The
277 -- handling of warnings if further controlled by the Warning_Mode
278 -- option (-w switch), see package Opt for further details, and also by
279 -- the current setting from pragma Warnings. This pragma applies only
280 -- to warnings issued from the semantic phase (not the parser), but
281 -- currently all relevant warnings are posted by the semantic phase
282 -- anyway. Messages starting with (style) are also treated as warning
285 -- Note: when a warning message is output, the text of the message is
286 -- preceded by "warning: " in the normal case. An exception to this
287 -- rule occurs when the text of the message starts with "info: " in
288 -- which case this string is not prepended. This allows callers to
289 -- label certain warnings as informational messages, rather than as
290 -- warning messages requiring some action.
292 -- Note: the presence of ? is ignored in continuation messages (i.e.
293 -- messages starting with the \ insertion character). The warning
294 -- status of continuations is determined only by the parent message
295 -- which is being continued. It is allowable to put ? in continuation
296 -- messages, and the usual style is to include it, since it makes it
297 -- clear that the continuation is part of a warning message.
299 -- Insertion character < (Less Than: conditional warning message)
300 -- The character < appearing anywhere in a message is used for a
301 -- conditional error message. If Error_Msg_Warn is True, then the
302 -- effect is the same as ? described above. If Error_Msg_Warn is
303 -- False, then there is no effect.
305 -- Insertion character A-Z (Upper case letter: Ada reserved word)
306 -- If two or more upper case letters appear in the message, they are
307 -- taken as an Ada reserved word, and are converted to the default
308 -- case for reserved words (see Scans package spec). Surrounding
309 -- quotes are added unless manual quotation mode is currently set.
311 -- Insertion character ` (Backquote: set manual quotation mode)
312 -- The backquote character always appears in pairs. Each backquote of
313 -- the pair is replaced by a double quote character. In addition, any
314 -- reserved keywords, or name insertions between these backquotes are
315 -- not surrounded by the usual automatic double quotes. See the
316 -- section below on manual quotation mode for further details.
318 -- Insertion character ' (Quote: literal character)
319 -- Precedes a character which is placed literally into the message.
320 -- Used to insert characters into messages that are one of the
321 -- insertion characters defined here. Also useful in inserting
322 -- sequences of upper case letters (e.g. RM) which are not to be
323 -- treated as keywords.
325 -- Insertion character \ (Backslash: continuation message)
326 -- Indicates that the message is a continuation of a message
327 -- previously posted. This is used to ensure that such groups of
328 -- messages are treated as a unit. The \ character must be the first
329 -- character of the message text.
331 -- Insertion character \\ (Two backslashes, continuation with new line)
332 -- This differs from \ only in -gnatjnn mode (Error_Message_Line_Length
333 -- set non-zero). This sequence forces a new line to start even when
334 -- continuations are being gathered into a single message.
336 -- Insertion character | (Vertical bar: non-serious error)
337 -- By default, error messages (other than warning messages) are
338 -- considered to be fatal error messages which prevent expansion or
339 -- generation of code in the presence of the -gnatQ switch. If the
340 -- insertion character | appears, the message is considered to be
341 -- non-serious, and does not cause Serious_Errors_Detected to be
342 -- incremented (so expansion is not prevented by such a msg).
344 -- Insertion character ~ (Tilde: insert string)
345 -- Indicates that Error_Msg_String (1 .. Error_Msg_Strlen) is to be
346 -- inserted to replace the ~ character. The string is inserted in the
347 -- literal form it appears, without any action on special characters.
349 -- Insertion character ~~ (Two tildes: insert language string)
350 -- Indicates that Error_Msg_Lang (1 .. Error_Msg_Langlen) is to be
351 -- inserted to replace the ~~ character. Typically the language string
352 -- will be inserted in parentheses as a prefix of the error message, as
353 -- in "(spark) error msg". The string is inserted in the literal form
354 -- it appears, without any action on special characters. Error_Msg_Lang
355 -- and Error_Msg_Langlen are expected to be set only once before
356 -- parsing starts, so that the caller to an error procedure does not
357 -- need to set them repeatedly.
359 ----------------------------------------
360 -- Specialization of Messages for VMS --
361 ----------------------------------------
363 -- Some messages mention gcc-style switch names. When using an OpenVMS
364 -- host, such switch names must be converted to their corresponding VMS
365 -- qualifer. The following table controls this translation. In each case
366 -- the original message must contain the string "-xxx switch", where xxx
367 -- is the Gname? entry from below, and this string will be replaced by
368 -- "/yyy qualifier", where yyy is the corresponding Vname? entry.
370 Gname1 : aliased constant String := "fno-strict-aliasing";
371 Vname1 : aliased constant String := "OPTIMIZE=NO_STRICT_ALIASING";
373 Gname2 : aliased constant String := "gnatX";
374 Vname2 : aliased constant String := "EXTENSIONS_ALLOWED";
376 Gname3 : aliased constant String := "gnatW";
377 Vname3 : aliased constant String := "WIDE_CHARACTER_ENCODING";
379 Gname4 : aliased constant String := "gnatf";
380 Vname4 : aliased constant String := "REPORT_ERRORS=FULL";
382 Gname5 : aliased constant String := "gnat05";
383 Vname5 : aliased constant String := "05";
385 Gname6 : aliased constant String := "gnat2005";
386 Vname6 : aliased constant String := "2005";
388 Gname7 : aliased constant String := "gnat12";
389 Vname7 : aliased constant String := "12";
391 Gname8 : aliased constant String := "gnat2012";
392 Vname8 : aliased constant String := "2012";
394 type Cstring_Ptr is access constant String;
396 Gnames : array (Nat range <>) of Cstring_Ptr :=
406 Vnames : array (Nat range <>) of Cstring_Ptr :=
416 -----------------------------------------------------
417 -- Global Values Used for Error Message Insertions --
418 -----------------------------------------------------
420 -- The following global variables are essentially additional parameters
421 -- passed to the error message routine for insertion sequences described
422 -- above. The reason these are passed globally is that the insertion
423 -- mechanism is essentially an untyped one in which the appropriate
424 -- variables are set depending on the specific insertion characters used.
426 -- Note that is mandatory that the caller ensure that global variables
427 -- are set before the Error_Msg call, otherwise the result is undefined.
429 Error_Msg_Col : Column_Number renames Err_Vars.Error_Msg_Col;
430 -- Column for @ insertion character in message
432 Error_Msg_Uint_1 : Uint renames Err_Vars.Error_Msg_Uint_1;
433 Error_Msg_Uint_2 : Uint renames Err_Vars.Error_Msg_Uint_2;
434 -- Uint values for ^ insertion characters in message
436 Error_Msg_Sloc : Source_Ptr renames Err_Vars.Error_Msg_Sloc;
437 -- Source location for # insertion character in message
439 Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1;
440 Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2;
441 Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3;
442 -- Name_Id values for % insertion characters in message
444 Error_Msg_File_1 : File_Name_Type renames Err_Vars.Error_Msg_File_1;
445 Error_Msg_File_2 : File_Name_Type renames Err_Vars.Error_Msg_File_2;
446 Error_Msg_File_3 : File_Name_Type renames Err_Vars.Error_Msg_File_3;
447 -- File_Name_Type values for { insertion characters in message
449 Error_Msg_Unit_1 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_1;
450 Error_Msg_Unit_2 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_2;
451 -- Unit_Name_Type values for $ insertion characters in message
453 Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1;
454 Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2;
455 -- Node_Id values for & insertion characters in message
457 Error_Msg_Qual_Level : Int renames Err_Vars.Error_Msg_Qual_Level;
458 -- Number of levels of qualification required for type name (see the
459 -- description of the } insertion character. Note that this value does
460 -- note get reset by any Error_Msg call, so the caller is responsible
463 Error_Msg_Warn : Boolean renames Err_Vars.Error_Msg_Warn;
464 -- Used if current message contains a < insertion character to indicate
465 -- if the current message is a warning message.
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 Error_Msg_Lang : String renames Err_Vars.Error_Msg_Lang;
473 Error_Msg_Langlen : Natural renames Err_Vars.Error_Msg_Langlen;
474 -- Used if current message contains a ~~ insertion character to indicate
475 -- insertion of the string Error_Msg_Lang (1 .. Error_Msg_Langlen).
477 -----------------------------------------------------
478 -- Format of Messages and Manual Quotation Control --
479 -----------------------------------------------------
481 -- Messages are generally all in lower case, except for inserted names
482 -- and appear in one of the following three forms:
487 -- The prefixes error and warning are supplied automatically (depending
488 -- on the use of the ? insertion character), and the call to the error
489 -- message routine supplies the text. The "error: " prefix is omitted
490 -- in brief error message formats.
492 -- Reserved Ada keywords in the message are in the default keyword case
493 -- (determined from the given source program), surrounded by quotation
494 -- marks. This is achieved by spelling the reserved word in upper case
495 -- letters, which is recognized as a request for insertion of quotation
496 -- marks by the error text processor. Thus for example:
498 -- Error_Msg_AP ("IS expected");
500 -- would result in the output of one of the following:
502 -- error: "is" expected
503 -- error: "IS" expected
504 -- error: "Is" expected
506 -- the choice between these being made by looking at the casing convention
507 -- used for keywords (actually the first compilation unit keyword) in the
510 -- Note: a special exception is that RM is never treated as a keyword
511 -- but instead is copied literally into the message, this avoids the
512 -- need for writing 'R'M for all reference manual quotes.
514 -- In the case of names, the default mode for the error text processor
515 -- is to surround the name by quotation marks automatically. The case
516 -- used for the identifier names is taken from the source program where
517 -- possible, and otherwise is the default casing convention taken from
518 -- the source file usage.
520 -- In some cases, better control over the placement of quote marks is
521 -- required. This is achieved using manual quotation mode. In this mode,
522 -- one or more insertion sequences is surrounded by backquote characters.
523 -- The backquote characters are output as double quote marks, and normal
524 -- automatic insertion of quotes is suppressed between the double quotes.
527 -- Error_Msg_AP ("`END &;` expected");
529 -- generates a message like
531 -- error: "end Open_Scope;" expected
533 -- where the node specifying the name Open_Scope has been stored in
534 -- Error_Msg_Node_1 prior to the call. The great majority of error
535 -- messages operates in normal quotation mode.
537 -- Note: the normal automatic insertion of spaces before insertion
538 -- sequences (such as those that come from & and %) is suppressed in
539 -- manual quotation mode, so blanks, if needed as in the above example,
540 -- must be explicitly present.
542 ----------------------------
543 -- Message ID Definitions --
544 ----------------------------
546 subtype Error_Msg_Id is Erroutc.Error_Msg_Id;
547 function "=" (Left, Right : Error_Msg_Id) return Boolean
549 -- A type used to represent specific error messages. Used by the clients
550 -- of this package only in the context of the Get_Error_Id and
551 -- Change_Error_Text subprograms.
553 No_Error_Msg : constant Error_Msg_Id := Erroutc.No_Error_Msg;
554 -- A constant which is different from any value returned by Get_Error_Id.
555 -- Typically used by a client to indicate absense of a saved Id value.
557 function Get_Msg_Id return Error_Msg_Id renames Erroutc.Get_Msg_Id;
558 -- Returns the Id of the message most recently posted using one of the
559 -- Error_Msg routines.
561 function Get_Location (E : Error_Msg_Id) return Source_Ptr
562 renames Erroutc.Get_Location;
563 -- Returns the flag location of the error message with the given id E
565 ------------------------
566 -- List Pragmas Table --
567 ------------------------
569 -- When a pragma Page or pragma List is encountered by the parser, an
570 -- entry is made in the following table. This table is then used to
571 -- control the full listing if one is being generated. Note that the
572 -- reason we do the processing in the parser is so that we get proper
573 -- listing control even in syntax check only mode.
575 type List_Pragma_Type is (List_On, List_Off, Page);
577 type List_Pragma_Record is record
578 Ptyp : List_Pragma_Type;
582 -- Note: Ploc points to the terminating semicolon in the List_Off and Page
583 -- cases, and to the pragma keyword for List_On. In the case of a pragma
584 -- List_Off, a List_On entry is also made in the table, pointing to the
585 -- pragma keyword. This ensures that, as required, a List (Off) pragma is
586 -- listed even in list off mode.
588 package List_Pragmas is new Table.Table (
589 Table_Component_Type => List_Pragma_Record,
590 Table_Index_Type => Int,
591 Table_Low_Bound => 1,
593 Table_Increment => 200,
594 Table_Name => "List_Pragmas");
596 ---------------------------
597 -- Ignore_Errors Feature --
598 ---------------------------
600 -- In certain cases, notably for optional subunits, the compiler operates
601 -- in a mode where errors are to be ignored, and the whole unit is to be
602 -- considered as not present. To implement this we provide the following
603 -- flag to enable special handling, where error messages are suppressed,
604 -- but the Fatal_Error flag will still be set in the normal manner.
606 Ignore_Errors_Enable : Nat := 0;
607 -- Triggering switch. If non-zero, then ignore errors mode is activated.
608 -- This is a counter to allow convenient nesting of enable/disable.
610 -----------------------
611 -- CODEFIX Facility --
612 -----------------------
614 -- The GPS and GNATBench IDE's have a codefix facility that allows for
615 -- automatic correction of a subset of the errors and warnings issued
616 -- by the compiler. This is done by recognizing the text of specific
617 -- messages using appropriate matching patterns.
619 -- The text of such messages should not be altered without coordinating
620 -- with the codefix code. All such messages are marked by a specific
621 -- style of comments, as shown by the following example:
623 -- Error_Msg_N -- CODEFIX
626 -- Any message marked with this -- CODEFIX comment should not be modified
627 -- without appropriate coordination. If new messages are added which may
628 -- be susceptible to automatic codefix action, they are marked using:
630 ------------------------------
631 -- Error Output Subprograms --
632 ------------------------------
634 procedure Initialize;
635 -- Initializes for output of error messages. Must be called for each
636 -- source file before using any of the other routines in the package.
638 procedure Finalize (Last_Call : Boolean);
639 -- Finalize processing of error message list. Includes processing for
640 -- duplicated error messages, and other similar final adjustment of the
641 -- list of error messages. Note that this procedure must be called before
642 -- calling Compilation_Errors to determine if there were any errors. It
643 -- is perfectly fine to call Finalize more than once, providing that the
644 -- parameter Last_Call is set False for every call except the last call.
646 -- This multiple call capability is used to do some processing that may
647 -- generate messages. Call Finalize to eliminate duplicates and remove
648 -- deleted warnings. Test for compilation errors using Compilation_Errors,
649 -- then generate some more errors/warnings, call Finalize again to make
650 -- sure that all duplicates in these new messages are dealt with, then
651 -- finally call Output_Messages to output the final list of messages. The
652 -- argument Last_Call must be set False on all calls except the last call,
653 -- and must be set True on the last call (a value of True activates some
654 -- processing that must only be done after all messages are posted).
656 procedure Output_Messages;
657 -- Output list of messages, including messages giving number of detected
658 -- errors and warnings.
660 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
661 -- Output a message at specified location. Can be called from the parser
662 -- or the semantic analyzer.
664 procedure Error_Msg_S (Msg : String);
665 -- Output a message at current scan pointer location. This routine can be
666 -- called only from the parser, since it references Scan_Ptr.
668 procedure Error_Msg_AP (Msg : String);
669 -- Output a message just after the previous token. This routine can be
670 -- called only from the parser, since it references Prev_Token_Ptr.
672 procedure Error_Msg_BC (Msg : String);
673 -- Output a message just before the current token. Note that the important
674 -- difference between this and the previous routine is that the BC case
675 -- posts a flag on the current line, whereas AP can post a flag at the
676 -- end of the preceding line. This routine can be called only from the
677 -- parser, since it references Token_Ptr.
679 procedure Error_Msg_SC (Msg : String);
680 -- Output a message at the start of the current token, unless we are at
681 -- the end of file, in which case we always output the message after the
682 -- last real token in the file. This routine can be called only from the
683 -- parser, since it references Token_Ptr.
685 procedure Error_Msg_SP (Msg : String);
686 -- Output a message at the start of the previous token. This routine can
687 -- be called only from the parser, since it references Prev_Token_Ptr.
689 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id);
690 -- Output a message at the Sloc of the given node. This routine can be
691 -- called from the parser or the semantic analyzer, although the call from
692 -- the latter is much more common (and is the most usual way of generating
693 -- error messages from the analyzer). The message text may contain a
694 -- single & insertion, which will reference the given node. The message is
695 -- suppressed if the node N already has a message posted, or if it is a
696 -- warning and N is an entity node for which warnings are suppressed.
698 procedure Error_Msg_F (Msg : String; N : Node_Id);
699 -- Similar to Error_Msg_N except that the message is placed on the first
700 -- node of the construct N (First_Node (N)).
702 procedure Error_Msg_NE
704 N : Node_Or_Entity_Id;
705 E : Node_Or_Entity_Id);
706 -- Output a message at the Sloc of the given node N, with an insertion of
707 -- the name from the given entity node E. This is used by the semantic
708 -- routines, where this is a common error message situation. The Msg text
709 -- will contain a & or } as usual to mark the insertion point. This
710 -- routine can be called from the parser or the analyzer.
712 procedure Error_Msg_FE
715 E : Node_Or_Entity_Id);
716 -- Same as Error_Msg_NE, except that the message is placed on the first
717 -- node of the construct N (First_Node (N)).
719 procedure Error_Msg_NEL
721 N : Node_Or_Entity_Id;
722 E : Node_Or_Entity_Id;
723 Flag_Location : Source_Ptr);
724 -- Exactly the same as Error_Msg_NE, except that the flag is placed at
725 -- the specified Flag_Location instead of at Sloc (N).
727 procedure Error_Msg_NW
730 N : Node_Or_Entity_Id);
731 -- This routine is used for posting a message conditionally. The message
732 -- is posted (with the same effect as Error_Msg_N (Msg, N) if and only
733 -- if Eflag is True and if the node N is within the main extended source
734 -- unit and comes from source. Typically this is a warning mode flag.
735 -- This routine can only be called during semantic analysis. It may not
736 -- be called during parsing.
738 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String);
739 -- The error message text of the message identified by Id is replaced by
740 -- the given text. This text may contain insertion characters in the
741 -- usual manner, and need not be the same length as the original text.
743 function First_Node (C : Node_Id) return Node_Id;
744 -- Given a construct C, finds the first node in the construct, i.e. the
745 -- one with the lowest Sloc value. This is useful in placing error msgs.
747 function First_Sloc (N : Node_Id) return Source_Ptr;
748 -- Given the node for an expression, return a source pointer value that
749 -- points to the start of the first token in the expression. In the case
750 -- where the expression is parenthesized, an attempt is made to include
751 -- the parentheses (i.e. to return the location of the initial paren).
753 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr)
754 renames Erroutc.Purge_Messages;
755 -- All error messages whose location is in the range From .. To (not
756 -- including the end points) will be deleted from the error listing.
758 procedure Remove_Warning_Messages (N : Node_Id);
759 -- Remove any warning messages corresponding to the Sloc of N or any
760 -- of its descendent nodes. No effect if no such warnings. Note that
761 -- style messages (identified by the fact that they start with "(style)"
762 -- are not removed by this call. Basically the idea behind this procedure
763 -- is to remove warnings about execution conditions from known dead code.
765 procedure Remove_Warning_Messages (L : List_Id);
766 -- Remove warnings on all elements of a list (Calls Remove_Warning_Messages
767 -- on each element of the list, see above).
769 procedure Set_Error_Msg_Lang (To : String);
770 -- Set Error_Msg_Lang/Error_Msg_Langlen used for insertion character ~~.
771 -- The argument is just the language name, e.g. "spark". The stored string
772 -- is of the form "(langname) ".
774 procedure Set_Ignore_Errors (To : Boolean);
775 -- Following a call to this procedure with To=True, all error calls are
776 -- ignored. A call with To=False restores the default treatment in which
777 -- error calls are treated as usual (and as described in this spec).
779 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr)
780 renames Erroutc.Set_Warnings_Mode_Off;
781 -- Called in response to a pragma Warnings (Off) to record the source
782 -- location from which warnings are to be turned off.
784 procedure Set_Warnings_Mode_On (Loc : Source_Ptr)
785 renames Erroutc.Set_Warnings_Mode_On;
786 -- Called in response to a pragma Warnings (On) to record the source
787 -- location from which warnings are to be turned back on.
789 procedure Set_Specific_Warning_Off
793 renames Erroutc.Set_Specific_Warning_Off;
794 -- This is called in response to the two argument form of pragma Warnings
795 -- where the first argument is OFF, and the second argument is the prefix
796 -- of a specific warning to be suppressed. The first argument is the start
797 -- of the suppression range, and the second argument is the string from
800 procedure Set_Specific_Warning_On
804 renames Erroutc.Set_Specific_Warning_On;
805 -- This is called in response to the two argument form of pragma Warnings
806 -- where the first argument is ON, and the second argument is the prefix
807 -- of a specific warning to be suppressed. The first argument is the end
808 -- of the suppression range, and the second argument is the string from
809 -- the pragma. Err is set to True on return to report the error of no
810 -- matching Warnings Off pragma preceding this one.
812 function Compilation_Errors return Boolean;
813 -- Returns true if errors have been detected, or warnings in -gnatwe
814 -- (treat warnings as errors) mode. Note that it is mandatory to call
815 -- Finalize before calling this routine.
817 procedure Error_Msg_CRT (Feature : String; N : Node_Id);
818 -- Posts a non-fatal message on node N saying that the feature identified
819 -- by the Feature argument is not supported in either configurable
820 -- run-time mode or no run-time mode (as appropriate). In the former case,
821 -- the name of the library is output if available.
823 procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg;
824 -- Debugging routine to dump an error message
826 ------------------------------------
827 -- Utility Interface for Back End --
828 ------------------------------------
830 -- The following subprograms can be used by the back end for the purposes
831 -- of concocting error messages that are not output via Errout, e.g. the
832 -- messages generated by the gcc back end.
834 procedure Set_Identifier_Casing
835 (Identifier_Name : System.Address;
836 File_Name : System.Address);
837 -- The identifier is a null terminated string that represents the name of
838 -- an identifier appearing in the source program. File_Name is a null
839 -- terminated string giving the corresponding file name for the identifier
840 -- as obtained from the front end by the use of Full_Debug_Name to the
841 -- source file referenced by the corresponding source location value. On
842 -- return, the name is in Name_Buffer, null terminated with Name_Len set.
843 -- This name is the identifier name as passed, cased according to the
844 -- default identifier casing for the given file.