Merged trunk at revision 161680 into branch.
[official-gcc.git] / gcc / ada / errout.ads
blob8251126f3410b39deb5884c32abfd4b7bde8c89c
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E R R O U T --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2010, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
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/>. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
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.
32 with Err_Vars;
33 with Erroutc;
34 with Namet; use Namet;
35 with Table;
36 with Types; use Types;
37 with Uintp; use Uintp;
39 with System;
41 package Errout is
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
46 -- -gnatQ is set.
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 type Compiler_State_Type is (Parsing, Analyzing);
64 Compiler_State : Compiler_State_Type;
65 -- Indicates current state of compilation. This is put in the Errout spec
66 -- because it affects the action of the error message handling. In
67 -- particular, an attempt is made by Errout to suppress cascaded error
68 -- messages in Parsing mode, but not in the other modes.
70 Current_Error_Source_File : Source_File_Index
71 renames Err_Vars.Current_Error_Source_File;
72 -- Id of current messages. Used to post file name when unit changes. This
73 -- is initialized to Main_Source_File at the start of a compilation, which
74 -- means that no file names will be output unless there are errors in
75 -- units other than the main unit. However, if the main unit has a pragma
76 -- Source_Reference line, then this is initialized to No_Source_File, to
77 -- force an initial reference to the real source file name.
79 Raise_Exception_On_Error : Nat renames Err_Vars.Raise_Exception_On_Error;
80 -- If this value is non-zero, then any attempt to generate an error
81 -- message raises the exception Error_Msg_Exception, and the error message
82 -- is not output. This is used for defending against junk resulting from
83 -- illegalities, and also for substitution of more appropriate error
84 -- messages from higher semantic levels. It is a counter so that the
85 -- increment/decrement protocol nests neatly.
87 Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception;
88 -- Exception raised if Raise_Exception_On_Error is true
90 -----------------------------------
91 -- Suppression of Error Messages --
92 -----------------------------------
94 -- In an effort to reduce the impact of redundant error messages, the
95 -- error output routines in this package normally suppress certain
96 -- classes of messages as follows:
98 -- 1. Identical messages placed at the same point in the text. Such
99 -- duplicate error message result for example from rescanning
100 -- sections of the text that contain lexical errors. Only one of
101 -- such a set of duplicate messages is output, and the rest are
102 -- suppressed.
104 -- 2. If more than one parser message is generated for a single source
105 -- line, then only the first message is output, the remaining
106 -- messages on the same line are suppressed.
108 -- 3. If a message is posted on a node for which a message has been
109 -- previously posted, then only the first message is retained. The
110 -- Error_Posted flag is used to detect such multiple postings. Note
111 -- that this only applies to semantic messages, since otherwise
112 -- for parser messages, this would be a special case of case 2.
114 -- 4. If a message is posted on a node whose Etype or Entity
115 -- fields reference entities on which an error message has
116 -- already been placed, as indicated by the Error_Posted flag
117 -- being set on these entities, then the message is suppressed.
119 -- 5. If a message attempts to insert an Error node, or a direct
120 -- reference to the Any_Type node, then the message is suppressed.
122 -- 6. Note that cases 2-5 only apply to error messages, not warning
123 -- messages. Warning messages are only suppressed for case 1, and
124 -- when they come from other than the main extended unit.
126 -- This normal suppression action may be overridden in cases 2-5 (but not
127 -- in case 1) by setting All_Errors mode, or by setting the special
128 -- unconditional message insertion character (!) at the end of the message
129 -- text as described below.
131 ---------------------------------------------------------
132 -- Error Message Text and Message Insertion Characters --
133 ---------------------------------------------------------
135 -- Error message text strings are composed of lower case letters, digits
136 -- and the special characters space, comma, period, colon and semicolon,
137 -- apostrophe and parentheses. Special insertion characters can also
138 -- appear which cause the error message circuit to modify the given
139 -- string as follows:
141 -- Insertion character % (Percent: insert name from Names table)
142 -- The character % is replaced by the text for the name specified by
143 -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes the
144 -- name if it is preceded by a non-blank character other than left
145 -- parenthesis. The name is enclosed in quotes unless manual quotation
146 -- mode is set. If the Name_Id is set to No_Name, then no insertion
147 -- occurs; if the Name_Id is set to Error_Name, then the string
148 -- <error> is inserted. A second and third % may appear in a single
149 -- message, similarly replaced by the names which are specified by the
150 -- Name_Id values stored in Error_Msg_Name_2 and Error_Msg_Name_3. The
151 -- names are decoded and cased according to the current identifier
152 -- casing mode. Note: if a unit name ending with %b or %s is passed
153 -- for this kind of insertion, this suffix is simply stripped. Use a
154 -- unit name insertion ($) to process the suffix.
156 -- Insertion character %% (Double percent: insert literal name)
157 -- The character sequence %% acts as described above for %, except
158 -- that the name is simply obtained with Get_Name_String and is not
159 -- decoded or cased, it is inserted literally from the names table.
160 -- A trailing %b or %s is not treated specially.
162 -- Insertion character $ (Dollar: insert unit name from Names table)
163 -- The character $ is treated similarly to %, except that the name is
164 -- obtained from the Unit_Name_Type value in Error_Msg_Unit_1 and
165 -- Error_Msg_Unit_2, as provided by Get_Unit_Name_String in package
166 -- Uname. Note that this name includes the postfix (spec) or (body)
167 -- strings. If this postfix is not required, use the normal %
168 -- insertion for the unit name.
170 -- Insertion character { (Left brace: insert file name from names table)
171 -- The character { is treated similarly to %, except that the input
172 -- value is a File_Name_Type value stored in Error_Msg_File_1 or
173 -- Error_Msg_File_2 or Error_Msg_File_3. The value is output literally,
174 -- enclosed in quotes as for %, but the case is not modified, the
175 -- insertion is the exact string stored in the names table without
176 -- adjusting the casing.
178 -- Insertion character * (Asterisk, insert reserved word name)
179 -- The insertion character * is treated exactly like % except that the
180 -- resulting name is cased according to the default conventions for
181 -- reserved words (see package Scans).
183 -- Insertion character & (Ampersand: insert name from node)
184 -- The insertion character & is treated similarly to %, except that
185 -- the name is taken from the Chars field of the given node, and may
186 -- refer to a child unit name, or a selected component. The casing is,
187 -- if possible, taken from the original source reference, which is
188 -- obtained from the Sloc field of the given node or nodes. If no Sloc
189 -- is available (happens e.g. for nodes in package Standard), then the
190 -- default case (see Scans spec) is used. The nodes to be used are
191 -- stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion occurs
192 -- for the Empty node, and the Error node results in the insertion of
193 -- the characters <error>. In addition, if the special global variable
194 -- Error_Msg_Qual_Level is non-zero, then the reference will include
195 -- up to the given number of levels of qualification, using the scope
196 -- chain.
198 -- Insertion character # (Pound: insert line number reference)
199 -- The character # is replaced by the string indicating the source
200 -- position stored in Error_Msg_Sloc. There are three cases:
202 -- for package Standard: in package Standard
203 -- for locations in current file: at line nnn:ccc
204 -- for locations in other files: at filename:nnn:ccc
206 -- By convention, the # insertion character is only used at the end of
207 -- an error message, so the above strings only appear as the last
208 -- characters of an error message. The only exceptions to this rule
209 -- are that an RM reference may follow in the form (RM .....) and a
210 -- right parenthesis may immediately follow the #. In the case of
211 -- continued messages, # can only appear at the end of a group of
212 -- continuation messsages, except that \\ messages which always start
213 -- a new line end the sequence from the point of view of this rule.
214 -- The idea is that for any use of -gnatj, it will still be the case
215 -- that a location reference appears only at the end of a line.
217 -- Insertion character } (Right brace: insert type reference)
218 -- The character } is replaced by a string describing the type
219 -- referenced by the entity whose Id is stored in Error_Msg_Node_1.
220 -- the string gives the name or description of the type, and also
221 -- where appropriate the location of its declaration. Special cases
222 -- like "some integer type" are handled appropriately. Only one } is
223 -- allowed in a message, since there is not enough room for two (the
224 -- insertion can be quite long, including a file name) In addition, if
225 -- the special global variable Error_Msg_Qual_Level is non-zero, then
226 -- the reference will include up to the given number of levels of
227 -- qualification, using the scope chain.
229 -- Insertion character @ (At: insert column number reference)
230 -- The character @ is replaced by null if the RM_Column_Check mode is
231 -- off (False). If the switch is on (True), then @ is replaced by the
232 -- text string " in column nnn" where nnn is the decimal
233 -- representation of the column number stored in Error_Msg_Col plus
234 -- one (the plus one is because the number is stored 0-origin and
235 -- displayed 1-origin).
237 -- Insertion character ^ (Carret: insert integer value)
238 -- The character ^ is replaced by the decimal conversion of the Uint
239 -- value stored in Error_Msg_Uint_1, with a possible leading minus.
240 -- A second ^ may occur in the message, in which case it is replaced
241 -- by the decimal conversion of the Uint value in Error_Msg_Uint_2.
243 -- Insertion character > (Right bracket, run time name)
244 -- The character > is replaced by a string of the form (name) if
245 -- Targparm scanned out a Run_Time_Name (see package Targparm for
246 -- details). The name is enclosed in parentheses and output in mixed
247 -- case mode (upper case after any space in the name). If no run time
248 -- name is defined, this insertion character has no effect.
250 -- Insertion character ! (Exclamation: unconditional message)
251 -- The character ! appearing as the last character of a message makes
252 -- the message unconditional which means that it is output even if it
253 -- would normally be suppressed. See section above for a description
254 -- of the cases in which messages are normally suppressed. Note that
255 -- in the case of warnings, the meaning is that the warning should not
256 -- be removed in dead code (that's the only time that the use of !
257 -- has any effect for a warning).
259 -- Note: the presence of ! is ignored in continuation messages (i.e.
260 -- messages starting with the \ insertion character). The effect of the
261 -- use of ! in a parent message automatically applies to all of its
262 -- continuation messages (since we clearly don't want any case in which
263 -- continuations are separated from the parent message. It is allowable
264 -- to put ! in continuation messages, and the usual style is to include
265 -- it, since it makes it clear that the continuation is part of an
266 -- unconditional message.
268 -- Insertion character !! (unconditional warning)
270 -- Normally warning messages issued in other than the main unit are
271 -- suppressed. If the message ends with !! then this suppression is
272 -- avoided. This is currently used by the Compile_Time_Warning pragma
273 -- to ensure the message for a with'ed unit is output, and for warnings
274 -- on ineffective back-end inlining, which is detected in units that
275 -- contain subprograms to be inlined in the main program.
277 -- Insertion character ? (Question: warning message)
278 -- The character ? appearing anywhere in a message makes the message
279 -- warning instead of a normal error message, and the text of the
280 -- message will be preceded by "warning:" in the normal case. The
281 -- handling of warnings if further controlled by the Warning_Mode
282 -- option (-w switch), see package Opt for further details, and also by
283 -- the current setting from pragma Warnings. This pragma applies only
284 -- to warnings issued from the semantic phase (not the parser), but
285 -- currently all relevant warnings are posted by the semantic phase
286 -- anyway. Messages starting with (style) are also treated as warning
287 -- messages.
289 -- Note: when a warning message is output, the text of the message is
290 -- preceded by "warning: " in the normal case. An exception to this
291 -- rule occurs when the text of the message starts with "info: " in
292 -- which case this string is not prepended. This allows callers to
293 -- label certain warnings as informational messages, rather than as
294 -- warning messages requiring some action.
296 -- Note: the presence of ? is ignored in continuation messages (i.e.
297 -- messages starting with the \ insertion character). The warning
298 -- status of continuations is determined only by the parent message
299 -- which is being continued. It is allowable to put ? in continuation
300 -- messages, and the usual style is to include it, since it makes it
301 -- clear that the continuation is part of a warning message.
303 -- Insertion character < (Less Than: conditional warning message)
304 -- The character < appearing anywhere in a message is used for a
305 -- conditional error message. If Error_Msg_Warn is True, then the
306 -- effect is the same as ? described above. If Error_Msg_Warn is
307 -- False, then there is no effect.
309 -- Insertion character A-Z (Upper case letter: Ada reserved word)
310 -- If two or more upper case letters appear in the message, they are
311 -- taken as an Ada reserved word, and are converted to the default
312 -- case for reserved words (see Scans package spec). Surrounding
313 -- quotes are added unless manual quotation mode is currently set.
315 -- Insertion character ` (Backquote: set manual quotation mode)
316 -- The backquote character always appears in pairs. Each backquote of
317 -- the pair is replaced by a double quote character. In addition, any
318 -- reserved keywords, or name insertions between these backquotes are
319 -- not surrounded by the usual automatic double quotes. See the
320 -- section below on manual quotation mode for further details.
322 -- Insertion character ' (Quote: literal character)
323 -- Precedes a character which is placed literally into the message.
324 -- Used to insert characters into messages that are one of the
325 -- insertion characters defined here. Also useful in inserting
326 -- sequences of upper case letters (e.g. RM) which are not to be
327 -- treated as keywords.
329 -- Insertion character \ (Backslash: continuation message)
330 -- Indicates that the message is a continuation of a message
331 -- previously posted. This is used to ensure that such groups of
332 -- messages are treated as a unit. The \ character must be the first
333 -- character of the message text.
335 -- Insertion character \\ (Two backslashes, continuation with new line)
336 -- This differs from \ only in -gnatjnn mode (Error_Message_Line_Length
337 -- set non-zero). This sequence forces a new line to start even when
338 -- continuations are being gathered into a single message.
340 -- Insertion character | (Vertical bar: non-serious error)
341 -- By default, error messages (other than warning messages) are
342 -- considered to be fatal error messages which prevent expansion or
343 -- generation of code in the presence of the -gnatQ switch. If the
344 -- insertion character | appears, the message is considered to be
345 -- non-serious, and does not cause Serious_Errors_Detected to be
346 -- incremented (so expansion is not prevented by such a msg).
348 -- Insertion character ~ (Tilde: insert string)
349 -- Indicates that Error_Msg_String (1 .. Error_Msg_Strlen) is to be
350 -- inserted to replace the ~ character. The string is inserted in the
351 -- literal form it appears, without any action on special characters.
353 ----------------------------------------
354 -- Specialization of Messages for VMS --
355 ----------------------------------------
357 -- Some messages mention gcc-style switch names. When using an OpenVMS
358 -- host, such switch names must be converted to their corresponding VMS
359 -- qualifer. The following table controls this translation. In each case
360 -- the original message must contain the string "-xxx switch", where xxx
361 -- is the Gname? entry from below, and this string will be replaced by
362 -- "/yyy qualifier", where yyy is the corresponding Vname? entry.
364 Gname1 : aliased constant String := "fno-strict-aliasing";
365 Vname1 : aliased constant String := "OPTIMIZE=NO_STRICT_ALIASING";
367 Gname2 : aliased constant String := "gnatX";
368 Vname2 : aliased constant String := "EXTENSIONS_ALLOWED";
370 Gname3 : aliased constant String := "gnatW";
371 Vname3 : aliased constant String := "WIDE_CHARACTER_ENCODING";
373 Gname4 : aliased constant String := "gnatf";
374 Vname4 : aliased constant String := "REPORT_ERRORS=FULL";
376 Gname5 : aliased constant String := "gnat05";
377 Vname5 : aliased constant String := "05";
379 Gname6 : aliased constant String := "gnat12";
380 Vname6 : aliased constant String := "12";
382 type Cstring_Ptr is access constant String;
384 Gnames : array (Nat range <>) of Cstring_Ptr :=
385 (Gname1'Access,
386 Gname2'Access,
387 Gname3'Access,
388 Gname4'Access,
389 Gname5'Access,
390 Gname6'Access);
392 Vnames : array (Nat range <>) of Cstring_Ptr :=
393 (Vname1'Access,
394 Vname2'Access,
395 Vname3'Access,
396 Vname4'Access,
397 Vname5'Access,
398 Vname6'Access);
400 -----------------------------------------------------
401 -- Global Values Used for Error Message Insertions --
402 -----------------------------------------------------
404 -- The following global variables are essentially additional parameters
405 -- passed to the error message routine for insertion sequences described
406 -- above. The reason these are passed globally is that the insertion
407 -- mechanism is essentially an untyped one in which the appropriate
408 -- variables are set depending on the specific insertion characters used.
410 -- Note that is mandatory that the caller ensure that global variables
411 -- are set before the Error_Msg call, otherwise the result is undefined.
413 Error_Msg_Col : Column_Number renames Err_Vars.Error_Msg_Col;
414 -- Column for @ insertion character in message
416 Error_Msg_Uint_1 : Uint renames Err_Vars.Error_Msg_Uint_1;
417 Error_Msg_Uint_2 : Uint renames Err_Vars.Error_Msg_Uint_2;
418 -- Uint values for ^ insertion characters in message
420 Error_Msg_Sloc : Source_Ptr renames Err_Vars.Error_Msg_Sloc;
421 -- Source location for # insertion character in message
423 Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1;
424 Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2;
425 Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3;
426 -- Name_Id values for % insertion characters in message
428 Error_Msg_File_1 : File_Name_Type renames Err_Vars.Error_Msg_File_1;
429 Error_Msg_File_2 : File_Name_Type renames Err_Vars.Error_Msg_File_2;
430 Error_Msg_File_3 : File_Name_Type renames Err_Vars.Error_Msg_File_3;
431 -- File_Name_Type values for { insertion characters in message
433 Error_Msg_Unit_1 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_1;
434 Error_Msg_Unit_2 : Unit_Name_Type renames Err_Vars.Error_Msg_Unit_2;
435 -- Unit_Name_Type values for $ insertion characters in message
437 Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1;
438 Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2;
439 -- Node_Id values for & insertion characters in message
441 Error_Msg_Qual_Level : Int renames Err_Vars.Error_Msg_Qual_Level;
442 -- Number of levels of qualification required for type name (see the
443 -- description of the } insertion character. Note that this value does
444 -- note get reset by any Error_Msg call, so the caller is responsible
445 -- for resetting it.
447 Error_Msg_Warn : Boolean renames Err_Vars.Error_Msg_Warn;
448 -- Used if current message contains a < insertion character to indicate
449 -- if the current message is a warning message.
451 Error_Msg_String : String renames Err_Vars.Error_Msg_String;
452 Error_Msg_Strlen : Natural renames Err_Vars.Error_Msg_Strlen;
453 -- Used if current message contains a ~ insertion character to indicate
454 -- insertion of the string Error_Msg_String (1 .. Error_Msg_Strlen).
456 -----------------------------------------------------
457 -- Format of Messages and Manual Quotation Control --
458 -----------------------------------------------------
460 -- Messages are generally all in lower case, except for inserted names
461 -- and appear in one of the following three forms:
463 -- error: text
464 -- warning: text
466 -- The prefixes error and warning are supplied automatically (depending
467 -- on the use of the ? insertion character), and the call to the error
468 -- message routine supplies the text. The "error: " prefix is omitted
469 -- in brief error message formats.
471 -- Reserved Ada keywords in the message are in the default keyword case
472 -- (determined from the given source program), surrounded by quotation
473 -- marks. This is achieved by spelling the reserved word in upper case
474 -- letters, which is recognized as a request for insertion of quotation
475 -- marks by the error text processor. Thus for example:
477 -- Error_Msg_AP ("IS expected");
479 -- would result in the output of one of the following:
481 -- error: "is" expected
482 -- error: "IS" expected
483 -- error: "Is" expected
485 -- the choice between these being made by looking at the casing convention
486 -- used for keywords (actually the first compilation unit keyword) in the
487 -- source file.
489 -- Note: a special exception is that RM is never treated as a keyword
490 -- but instead is copied literally into the message, this avoids the
491 -- need for writing 'R'M for all reference manual quotes.
493 -- In the case of names, the default mode for the error text processor
494 -- is to surround the name by quotation marks automatically. The case
495 -- used for the identifier names is taken from the source program where
496 -- possible, and otherwise is the default casing convention taken from
497 -- the source file usage.
499 -- In some cases, better control over the placement of quote marks is
500 -- required. This is achieved using manual quotation mode. In this mode,
501 -- one or more insertion sequences is surrounded by backquote characters.
502 -- The backquote characters are output as double quote marks, and normal
503 -- automatic insertion of quotes is suppressed between the double quotes.
504 -- For example:
506 -- Error_Msg_AP ("`END &;` expected");
508 -- generates a message like
510 -- error: "end Open_Scope;" expected
512 -- where the node specifying the name Open_Scope has been stored in
513 -- Error_Msg_Node_1 prior to the call. The great majority of error
514 -- messages operates in normal quotation mode.
516 -- Note: the normal automatic insertion of spaces before insertion
517 -- sequences (such as those that come from & and %) is suppressed in
518 -- manual quotation mode, so blanks, if needed as in the above example,
519 -- must be explicitly present.
521 ----------------------------
522 -- Message ID Definitions --
523 ----------------------------
525 subtype Error_Msg_Id is Erroutc.Error_Msg_Id;
526 function "=" (Left, Right : Error_Msg_Id) return Boolean
527 renames Erroutc."=";
528 -- A type used to represent specific error messages. Used by the clients
529 -- of this package only in the context of the Get_Error_Id and
530 -- Change_Error_Text subprograms.
532 No_Error_Msg : constant Error_Msg_Id := Erroutc.No_Error_Msg;
533 -- A constant which is different from any value returned by Get_Error_Id.
534 -- Typically used by a client to indicate absense of a saved Id value.
536 function Get_Msg_Id return Error_Msg_Id renames Erroutc.Get_Msg_Id;
537 -- Returns the Id of the message most recently posted using one of the
538 -- Error_Msg routines.
540 function Get_Location (E : Error_Msg_Id) return Source_Ptr
541 renames Erroutc.Get_Location;
542 -- Returns the flag location of the error message with the given id E
544 ------------------------
545 -- List Pragmas Table --
546 ------------------------
548 -- When a pragma Page or pragma List is encountered by the parser, an
549 -- entry is made in the following table. This table is then used to
550 -- control the full listing if one is being generated. Note that the
551 -- reason we do the processing in the parser is so that we get proper
552 -- listing control even in syntax check only mode.
554 type List_Pragma_Type is (List_On, List_Off, Page);
556 type List_Pragma_Record is record
557 Ptyp : List_Pragma_Type;
558 Ploc : Source_Ptr;
559 end record;
561 -- Note: Ploc points to the terminating semicolon in the List_Off and Page
562 -- cases, and to the pragma keyword for List_On. In the case of a pragma
563 -- List_Off, a List_On entry is also made in the table, pointing to the
564 -- pragma keyword. This ensures that, as required, a List (Off) pragma is
565 -- listed even in list off mode.
567 package List_Pragmas is new Table.Table (
568 Table_Component_Type => List_Pragma_Record,
569 Table_Index_Type => Int,
570 Table_Low_Bound => 1,
571 Table_Initial => 50,
572 Table_Increment => 200,
573 Table_Name => "List_Pragmas");
575 ---------------------------
576 -- Ignore_Errors Feature --
577 ---------------------------
579 -- In certain cases, notably for optional subunits, the compiler operates
580 -- in a mode where errors are to be ignored, and the whole unit is to be
581 -- considered as not present. To implement this we provide the following
582 -- flag to enable special handling, where error messages are suppressed,
583 -- but the Fatal_Error flag will still be set in the normal manner.
585 Ignore_Errors_Enable : Nat := 0;
586 -- Triggering switch. If non-zero, then ignore errors mode is activated.
587 -- This is a counter to allow convenient nesting of enable/disable.
589 -----------------------
590 -- CODEFIX Facility --
591 -----------------------
593 -- The GPS and GNATBench IDE's have a codefix facility that allows for
594 -- automatic correction of a subset of the errors and warnings issued
595 -- by the compiler. This is done by recognizing the text of specific
596 -- messages using appropriate matching patterns.
598 -- The text of such messages should not be altered without coordinating
599 -- with the codefix code. All such messages are marked by a specific
600 -- style of comments, as shown by the following example:
602 -- Error_Msg_N -- CODEFIX
603 -- (parameters ....)
605 -- Any message marked with this -- CODEFIX comment should not be modified
606 -- without appropriate coordination. If new messages are added which may
607 -- be susceptible to automatic codefix action, they are marked using:
609 ------------------------------
610 -- Error Output Subprograms --
611 ------------------------------
613 procedure Initialize;
614 -- Initializes for output of error messages. Must be called for each
615 -- source file before using any of the other routines in the package.
617 procedure Finalize (Last_Call : Boolean);
618 -- Finalize processing of error message list. Includes processing for
619 -- duplicated error messages, and other similar final adjustment of the
620 -- list of error messages. Note that this procedure must be called before
621 -- calling Compilation_Errors to determine if there were any errors. It
622 -- is perfectly fine to call Finalize more than once, providing that the
623 -- parameter Last_Call is set False for every call except the last call.
625 -- This multiple call capability is used to do some processing that may
626 -- generate messages. Call Finalize to eliminate duplicates and remove
627 -- deleted warnings. Test for compilation errors using Compilation_Errors,
628 -- then generate some more errors/warnings, call Finalize again to make
629 -- sure that all duplicates in these new messages are dealt with, then
630 -- finally call Output_Messages to output the final list of messages. The
631 -- argument Last_Call must be set False on all calls except the last call,
632 -- and must be set True on the last call (a value of True activates some
633 -- processing that must only be done after all messages are posted).
635 procedure Output_Messages;
636 -- Output list of messages, including messages giving number of detected
637 -- errors and warnings.
639 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
640 -- Output a message at specified location. Can be called from the parser
641 -- or the semantic analyzer.
643 procedure Error_Msg_S (Msg : String);
644 -- Output a message at current scan pointer location. This routine can be
645 -- called only from the parser, since it references Scan_Ptr.
647 procedure Error_Msg_AP (Msg : String);
648 -- Output a message just after the previous token. This routine can be
649 -- called only from the parser, since it references Prev_Token_Ptr.
651 procedure Error_Msg_BC (Msg : String);
652 -- Output a message just before the current token. Note that the important
653 -- difference between this and the previous routine is that the BC case
654 -- posts a flag on the current line, whereas AP can post a flag at the
655 -- end of the preceding line. This routine can be called only from the
656 -- parser, since it references Token_Ptr.
658 procedure Error_Msg_SC (Msg : String);
659 -- Output a message at the start of the current token, unless we are at
660 -- the end of file, in which case we always output the message after the
661 -- last real token in the file. This routine can be called only from the
662 -- parser, since it references Token_Ptr.
664 procedure Error_Msg_SP (Msg : String);
665 -- Output a message at the start of the previous token. This routine can
666 -- be called only from the parser, since it references Prev_Token_Ptr.
668 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id);
669 -- Output a message at the Sloc of the given node. This routine can be
670 -- called from the parser or the semantic analyzer, although the call from
671 -- the latter is much more common (and is the most usual way of generating
672 -- error messages from the analyzer). The message text may contain a
673 -- single & insertion, which will reference the given node. The message is
674 -- suppressed if the node N already has a message posted, or if it is a
675 -- warning and warnings and N is an entity node for which warnings are
676 -- suppressed.
678 procedure Error_Msg_F (Msg : String; N : Node_Id);
679 -- Similar to Error_Msg_N except that the message is placed on the first
680 -- node of the construct N (First_Node (N)).
682 procedure Error_Msg_NE
683 (Msg : String;
684 N : Node_Or_Entity_Id;
685 E : Node_Or_Entity_Id);
686 -- Output a message at the Sloc of the given node N, with an insertion of
687 -- the name from the given entity node E. This is used by the semantic
688 -- routines, where this is a common error message situation. The Msg text
689 -- will contain a & or } as usual to mark the insertion point. This
690 -- routine can be called from the parser or the analyzer.
692 procedure Error_Msg_FE
693 (Msg : String;
694 N : Node_Id;
695 E : Node_Or_Entity_Id);
696 -- Same as Error_Msg_NE, except that the message is placed on the first
697 -- node of the construct N (First_Node (N)).
699 procedure Error_Msg_NEL
700 (Msg : String;
701 N : Node_Or_Entity_Id;
702 E : Node_Or_Entity_Id;
703 Flag_Location : Source_Ptr);
704 -- Exactly the same as Error_Msg_NE, except that the flag is placed at
705 -- the specified Flag_Location instead of at Sloc (N).
707 procedure Error_Msg_NW
708 (Eflag : Boolean;
709 Msg : String;
710 N : Node_Or_Entity_Id);
711 -- This routine is used for posting a message conditionally. The message
712 -- is posted (with the same effect as Error_Msg_N (Msg, N) if and only
713 -- if Eflag is True and if the node N is within the main extended source
714 -- unit and comes from source. Typically this is a warning mode flag.
715 -- This routine can only be called during semantic analysis. It may not
716 -- be called during parsing.
718 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String);
719 -- The error message text of the message identified by Id is replaced by
720 -- the given text. This text may contain insertion characters in the
721 -- usual manner, and need not be the same length as the original text.
723 function First_Node (C : Node_Id) return Node_Id;
724 -- Given a construct C, finds the first node in the construct, i.e. the
725 -- one with the lowest Sloc value. This is useful in placing error msgs.
727 function First_Sloc (N : Node_Id) return Source_Ptr;
728 -- Given the node for an expression, return a source pointer value that
729 -- points to the start of the first token in the expression. In the case
730 -- where the expression is parenthesized, an attempt is made to include
731 -- the parentheses (i.e. to return the location of the initial paren).
733 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr)
734 renames Erroutc.Purge_Messages;
735 -- All error messages whose location is in the range From .. To (not
736 -- including the end points) will be deleted from the error listing.
738 procedure Remove_Warning_Messages (N : Node_Id);
739 -- Remove any warning messages corresponding to the Sloc of N or any
740 -- of its descendent nodes. No effect if no such warnings. Note that
741 -- style messages (identified by the fact that they start with "(style)"
742 -- are not removed by this call. Basically the idea behind this procedure
743 -- is to remove warnings about execution conditions from known dead code.
745 procedure Remove_Warning_Messages (L : List_Id);
746 -- Remove warnings on all elements of a list (Calls Remove_Warning_Messages
747 -- on each element of the list, see above).
749 procedure Set_Ignore_Errors (To : Boolean);
750 -- Following a call to this procedure with To=True, all error calls are
751 -- ignored. A call with To=False restores the default treatment in which
752 -- error calls are treated as usual (and as described in this spec).
754 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr)
755 renames Erroutc.Set_Warnings_Mode_Off;
756 -- Called in response to a pragma Warnings (Off) to record the source
757 -- location from which warnings are to be turned off.
759 procedure Set_Warnings_Mode_On (Loc : Source_Ptr)
760 renames Erroutc.Set_Warnings_Mode_On;
761 -- Called in response to a pragma Warnings (On) to record the source
762 -- location from which warnings are to be turned back on.
764 procedure Set_Specific_Warning_Off
765 (Loc : Source_Ptr;
766 Msg : String;
767 Config : Boolean)
768 renames Erroutc.Set_Specific_Warning_Off;
769 -- This is called in response to the two argument form of pragma Warnings
770 -- where the first argument is OFF, and the second argument is the prefix
771 -- of a specific warning to be suppressed. The first argument is the start
772 -- of the suppression range, and the second argument is the string from
773 -- the pragma.
775 procedure Set_Specific_Warning_On
776 (Loc : Source_Ptr;
777 Msg : String;
778 Err : out Boolean)
779 renames Erroutc.Set_Specific_Warning_On;
780 -- This is called in response to the two argument form of pragma Warnings
781 -- where the first argument is ON, and the second argument is the prefix
782 -- of a specific warning to be suppressed. The first argument is the end
783 -- of the suppression range, and the second argument is the string from
784 -- the pragma. Err is set to True on return to report the error of no
785 -- matching Warnings Off pragma preceding this one.
787 function Compilation_Errors return Boolean;
788 -- Returns true if errors have been detected, or warnings in -gnatwe
789 -- (treat warnings as errors) mode. Note that it is mandatory to call
790 -- Finalize before calling this routine.
792 procedure Error_Msg_CRT (Feature : String; N : Node_Id);
793 -- Posts a non-fatal message on node N saying that the feature identified
794 -- by the Feature argument is not supported in either configurable
795 -- run-time mode or no run-time mode (as appropriate). In the former case,
796 -- the name of the library is output if available.
798 procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg;
799 -- Debugging routine to dump an error message
801 ------------------------------------
802 -- Utility Interface for Back End --
803 ------------------------------------
805 -- The following subprograms can be used by the back end for the purposes
806 -- of concocting error messages that are not output via Errout, e.g. the
807 -- messages generated by the gcc back end.
809 procedure Set_Identifier_Casing
810 (Identifier_Name : System.Address;
811 File_Name : System.Address);
812 -- The identifier is a null terminated string that represents the name of
813 -- an identifier appearing in the source program. File_Name is a null
814 -- terminated string giving the corresponding file name for the identifier
815 -- as obtained from the front end by the use of Full_Debug_Name to the
816 -- source file referenced by the corresponding source location value. On
817 -- return, the name is in Name_Buffer, null terminated with Name_Len set.
818 -- This name is the identifier name as passed, cased according to the
819 -- default identifier casing for the given file.
821 end Errout;