* dwarf2out.c (loc_descriptor_from_tree, case CONSTRUCTOR): New case.
[official-gcc.git] / gcc / ada / errout.ads
blob442204819f4bc9dc1f9c738368de817a898e3d02
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-2001 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, USA. --
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
28 -- are basically system independent, however in some environments, e.g.
29 -- when the parser is embedded into an editor, it may be appropriate
30 -- to replace the implementation of this package.
32 with Table;
33 with Types; use Types;
34 with Uintp; use Uintp;
36 package Errout is
38 Serious_Errors_Detected : Nat;
39 -- This is a count of errors that are serious enough to stop expansion,
40 -- and hence to prevent generation of an object file even if the
41 -- switch -gnatQ is set.
43 Total_Errors_Detected : Nat;
44 -- Number of errors detected so far. Includes count of serious errors
45 -- and non-serious errors, so this value is always greater than or
46 -- equal to the Serious_Errors_Detected value.
48 Warnings_Detected : Nat;
49 -- Number of warnings detected
51 type Compiler_State_Type is (Parsing, Analyzing);
52 Compiler_State : Compiler_State_Type;
53 -- Indicates current state of compilation. This is put in the Errout
54 -- spec because it affects the action of the error message handling.
55 -- In particular, an attempt is made by Errout to suppress cascaded
56 -- error messages in Parsing mode, but not in the other modes.
58 Current_Error_Source_File : Source_File_Index;
59 -- Id of current messages. Used to post file name when unit changes. This
60 -- is initialized to Main_Source_File at the start of a compilation, which
61 -- means that no file names will be output unless there are errors in units
62 -- other than the main unit. However, if the main unit has a pragma
63 -- Source_Reference line, then this is initialized to No_Source_File,
64 -- to force an initial reference to the real source file name.
66 Raise_Exception_On_Error : Nat := 0;
67 -- If this value is non-zero, then any attempt to generate an error
68 -- message raises the exception Error_Msg_Exception, and the error
69 -- message is not output. This is used for defending against junk
70 -- resulting from illegalities, and also for substitution of more
71 -- appropriate error messages from higher semantic levels. It is
72 -- a counter so that the increment/decrement protocol nests neatly.
74 Error_Msg_Exception : exception;
75 -- Exception raised if Raise_Exception_On_Error is true
77 -----------------------------------
78 -- Suppression of Error Messages --
79 -----------------------------------
81 -- In an effort to reduce the impact of redundant error messages, the
82 -- error output routines in this package normally suppress certain
83 -- classes of messages as follows:
85 -- 1. Identical messages placed at the same point in the text. Such
86 -- duplicate error message result for example from rescanning
87 -- sections of the text that contain lexical errors. Only one of
88 -- such a set of duplicate messages is output, and the rest are
89 -- suppressed.
91 -- 2. If more than one parser message is generated for a single source
92 -- line, then only the first message is output, the remaining
93 -- messages on the same line are suppressed.
95 -- 3. If a message is posted on a node for which a message has been
96 -- previously posted, then only the first message is retained. The
97 -- Error_Posted flag is used to detect such multiple postings. Note
98 -- that this only applies to semantic messages, since otherwise
99 -- for parser messages, this would be a special case of case 2.
101 -- 4. If a message is posted on a node whose Etype or Entity
102 -- fields reference entities on which an error message has
103 -- already been placed, as indicated by the Error_Posted flag
104 -- being set on these entities, then the message is suppressed.
106 -- 5. If a message attempts to insert an Error node, or a direct
107 -- reference to the Any_Type node, then the message is suppressed.
109 -- This normal suppression action may be overridden in cases 2-5 (but not
110 -- in case 1) by setting All_Errors mode, or by setting the special
111 -- unconditional message insertion character (!) at the end of the message
112 -- text as described below.
114 ---------------------------------------------------------
115 -- Error Message Text and Message Insertion Characters --
116 ---------------------------------------------------------
118 -- Error message text strings are composed of lower case letters, digits
119 -- and the special characters space, comma, period, colon and semicolon,
120 -- apostrophe and parentheses. Special insertion characters can also
121 -- appear which cause the error message circuit to modify the given
122 -- string as follows:
124 -- Insertion character % (Percent: insert name from Names table)
125 -- The character % is replaced by the text for the name specified by
126 -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes
127 -- the name if it is preceded by a non-blank character other than a
128 -- left parenthesis. The name is enclosed in quotes unless manual
129 -- quotation mode is set. If the Name_Id is set to No_Name, then
130 -- no insertion occurs; if the Name_Id is set to Error_Name, then
131 -- the string <error> is inserted. A second and third % may appear
132 -- in a single message, similarly replaced by the names which are
133 -- specified by the Name_Id values stored in Error_Msg_Name_2 and
134 -- Error_Msg_Name_3. The names are decoded and cased according to
135 -- the current identifier casing mode.
137 -- Insertion character $ (Dollar: insert unit name from Names table)
138 -- The character $ is treated similarly to %, except that the name
139 -- is obtained from the Unit_Name_Type value in Error_Msg_Unit_1
140 -- and Error_Msg_Unit_2, as provided by Get_Unit_Name_String in
141 -- package Uname. Note that this name includes the postfix (spec)
142 -- or (body) strings. If this postfix is not required, use the
143 -- normal % insertion for the unit name.
145 -- Insertion character { (Left brace: insert literally from names table)
146 -- The character { is treated similarly to %, except that the
147 -- name is output literally as stored in the names table without
148 -- adjusting the casing. This can be used for file names and in
149 -- other situations where the name string is to be output unchanged.
151 -- Insertion character * (Asterisk, insert reserved word name)
152 -- The insertion character * is treated exactly like % except that
153 -- the resulting name is cased according to the default conventions
154 -- for reserved words (see package Scans).
156 -- Insertion character & (Ampersand: insert name from node)
157 -- The insertion character & is treated similarly to %, except that
158 -- the name is taken from the Chars field of the given node, and may
159 -- refer to a child unit name, or a selected component. The casing
160 -- is, if possible, taken from the original source reference, which
161 -- is obtained from the Sloc field of the given node or nodes. If no
162 -- Sloc is available (happens e.g. for nodes in package Standard),
163 -- then the default case (see Scans spec) is used. The nodes to be
164 -- used are stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion
165 -- occurs for the Empty node, and the Error node results in the
166 -- insertion of the characters <error>. In addition, if the special
167 -- global variable Error_Msg_Qual_Level is non-zero, then the
168 -- reference will include up to the given number of levels of
169 -- qualification, using the scope chain.
171 -- Insertion character # (Pound: insert line number reference)
172 -- The character # is replaced by the string indicating the source
173 -- position stored in Error_Msg_Sloc. There are three cases:
175 -- for package Standard: in package Standard
176 -- for locations in current file: at line nnn:ccc
177 -- for locations in other files: at filename:nnn:ccc
179 -- By convention, the # insertion character is only used at the end
180 -- of an error message, so the above strings only appear as the last
181 -- characters of an error message.
183 -- Insertion character } (Right brace: insert type reference)
184 -- The character } is replaced by a string describing the type
185 -- referenced by the entity whose Id is stored in Error_Msg_Node_1.
186 -- the string gives the name or description of the type, and also
187 -- where appropriate the location of its declaration. Special
188 -- cases like "some integer type" are handled appropriately. Only
189 -- one } is allowed in a message, since there is not enough room
190 -- for two (the insertion can be quite long, including a file name)
191 -- In addition, if the special global variable Error_Msg_Qual_Level
192 -- is non-zero, then the reference will include up to the given
193 -- number of levels of qualification, using the scope chain.
195 -- Insertion character @ (At: insert column number reference)
196 -- The character @ is replaced by null if the RM_Column_Check mode is
197 -- off (False). If the switch is on (True), then @ is replaced by the
198 -- text string " in column nnn" where nnn is the decimal representation
199 -- of the column number stored in Error_Msg_Col plus one (the plus one
200 -- is because the number is stored 0-origin and displayed 1-origin).
202 -- Insertion character ^ (Carret: insert integer value)
203 -- The character ^ is replaced by the decimal conversion of the Uint
204 -- value stored in Error_Msg_Uint_1, with a possible leading minus.
205 -- A second ^ may occur in the message, in which case it is replaced
206 -- by the decimal conversion of the Uint value in Error_Msg_Uint_2.
208 -- Insertion character ! (Exclamation: unconditional message)
209 -- The character ! appearing as the last character of a message makes
210 -- the message unconditional which means that it is output even if it
211 -- would normally be suppressed. See section above for a description
212 -- of the cases in which messages are normally suppressed.
214 -- Insertion character ? (Question: warning message)
215 -- The character ? appearing anywhere in a message makes the message
216 -- a warning instead of a normal error message, and the text of the
217 -- message will be preceded by "Warning:" instead of "Error:" The
218 -- handling of warnings if further controlled by the Warning_Mode
219 -- option (-w switch), see package Opt for further details, and
220 -- also by the current setting from pragma Warnings. This pragma
221 -- applies only to warnings issued from the semantic phase (not
222 -- the parser), but currently all relevant warnings are posted
223 -- by the semantic phase anyway. Messages starting with (style)
224 -- are also treated as warning messages.
226 -- Insertion character A-Z (Upper case letter: Ada reserved word)
227 -- If two or more upper case letters appear in the message, they are
228 -- taken as an Ada reserved word, and are converted to the default
229 -- case for reserved words (see Scans package spec). Surrounding
230 -- quotes are added unless manual quotation mode is currently set.
232 -- Insertion character ` (Backquote: set manual quotation mode)
233 -- The backquote character always appears in pairs. Each backquote
234 -- of the pair is replaced by a double quote character. In addition,
235 -- Any reserved keywords, or name insertions between these backquotes
236 -- are not surrounded by the usual automatic double quotes. See the
237 -- section below on manual quotation mode for further details.
239 -- Insertion character ' (Quote: literal character)
240 -- Precedes a character which is placed literally into the message.
241 -- Used to insert characters into messages that are one of the
242 -- insertion characters defined here.
244 -- Insertion character \ (Backslash: continuation message)
245 -- Indicates that the message is a continuation of a message
246 -- previously posted. This is used to ensure that such groups
247 -- of messages are treated as a unit. The \ character must be
248 -- the first character of the message text.
250 -- Insertion character | (vertical bar, non-serious error)
251 -- By default, error messages (other than warning messages) are
252 -- considered to be fatal error messages which prevent expansion
253 -- or generation of code in the presence of the -gnatQ switch.
254 -- If the insertion character | appears, the message is considered
255 -- to be non-serious, and does not cause Serious_Errors_Detected
256 -- to be incremented (so expansion is not prevented by such a msg).
258 -----------------------------------------------------
259 -- Global Values Used for Error Message Insertions --
260 -----------------------------------------------------
262 -- The following global variables are essentially additional parameters
263 -- passed to the error message routine for insertion sequences described
264 -- above. The reason these are passed globally is that the insertion
265 -- mechanism is essentially an untyped one in which the appropriate
266 -- variables are set dependingon the specific insertion characters used.
268 Error_Msg_Col : Column_Number;
269 -- Column for @ insertion character in message
271 Error_Msg_Uint_1 : Uint;
272 Error_Msg_Uint_2 : Uint;
273 -- Uint values for ^ insertion characters in message
275 Error_Msg_Sloc : Source_Ptr;
276 -- Source location for # insertion character in message
278 Error_Msg_Name_1 : Name_Id;
279 Error_Msg_Name_2 : Name_Id;
280 Error_Msg_Name_3 : Name_Id;
281 -- Name_Id values for % insertion characters in message
283 Error_Msg_Unit_1 : Name_Id;
284 Error_Msg_Unit_2 : Name_Id;
285 -- Name_Id values for $ insertion characters in message
287 Error_Msg_Node_1 : Node_Id;
288 Error_Msg_Node_2 : Node_Id;
289 -- Node_Id values for & insertion characters in message
291 Error_Msg_Qual_Level : Int := 0;
292 -- Number of levels of qualification required for type name (see the
293 -- description of the } insertion character. Note that this value does
294 -- note get reset by any Error_Msg call, so the caller is responsible
295 -- for resetting it.
297 Warn_On_Instance : Boolean := False;
298 -- Normally if a warning is generated in a generic template from the
299 -- analysis of the template, then the warning really belongs in the
300 -- template, and the default value of False for this Boolean achieves
301 -- that effect. If Warn_On_Instance is set True, then the warnings are
302 -- generated on the instantiation (referring to the template) rather
303 -- than on the template itself.
305 -----------------------------------------------------
306 -- Format of Messages and Manual Quotation Control --
307 -----------------------------------------------------
309 -- Messages are generally all in lower case, except for inserted names
310 -- and appear in one of the following three forms:
312 -- error: text
313 -- warning: text
315 -- The prefixes error and warning are supplied automatically (depending
316 -- on the use of the ? insertion character), and the call to the error
317 -- message routine supplies the text. The "error: " prefix is omitted
318 -- in brief error message formats.
320 -- Reserved Ada keywords in the message are in the default keyword case
321 -- (determined from the given source program), surrounded by quotation
322 -- marks. This is achieved by spelling the reserved word in upper case
323 -- letters, which is recognized as a request for insertion of quotation
324 -- marks by the error text processor. Thus for example:
326 -- Error_Msg_AP ("IS expected");
328 -- would result in the output of one of the following:
330 -- error: "is" expected
331 -- error: "IS" expected
332 -- error: "Is" expected
334 -- the choice between these being made by looking at the casing convention
335 -- used for keywords (actually the first compilation unit keyword) in the
336 -- source file.
338 -- In the case of names, the default mode for the error text processor
339 -- is to surround the name by quotation marks automatically. The case
340 -- used for the identifier names is taken from the source program where
341 -- possible, and otherwise is the default casing convention taken from
342 -- the source file usage.
344 -- In some cases, better control over the placement of quote marks is
345 -- required. This is achieved using manual quotation mode. In this mode,
346 -- one or more insertion sequences is surrounded by backquote characters.
347 -- The backquote characters are output as double quote marks, and normal
348 -- automatic insertion of quotes is suppressed between the double quotes.
349 -- For example:
351 -- Error_Msg_AP ("`END &;` expected");
353 -- generates a message like
355 -- error: "end Open_Scope;" expected
357 -- where the node specifying the name Open_Scope has been stored in
358 -- Error_Msg_Node_1 prior to the call. The great majority of error
359 -- messages operates in normal quotation mode.
361 -- Note: the normal automatic insertion of spaces before insertion
362 -- sequences (such as those that come from & and %) is suppressed in
363 -- manual quotation mode, so blanks, if needed as in the above example,
364 -- must be explicitly present.
366 ----------------------------
367 -- Message ID Definitions --
368 ----------------------------
370 type Error_Msg_Id is new Int;
371 -- A type used to represent specific error messages. Used by the clients
372 -- of this package only in the context of the Get_Error_Id and
373 -- Change_Error_Text subprograms.
375 No_Error_Msg : constant Error_Msg_Id := 0;
376 -- A constant which is different from any value returned by Get_Error_Id.
377 -- Typically used by a client to indicate absense of a saved Id value.
379 function Get_Msg_Id return Error_Msg_Id;
380 -- Returns the Id of the message most recently posted using one of the
381 -- Error_Msg routines.
383 function Get_Location (E : Error_Msg_Id) return Source_Ptr;
384 -- Returns the flag location of the error message with the given id E.
386 ------------------------
387 -- List Pragmas Table --
388 ------------------------
390 -- When a pragma Page or pragma List is encountered by the parser, an
391 -- entry is made in the following table. This table is then used to
392 -- control the full listing if one is being generated. Note that the
393 -- reason we do the processing in the parser is so that we get proper
394 -- listing control even in syntax check only mode.
396 type List_Pragma_Type is (List_On, List_Off, Page);
398 type List_Pragma_Record is record
399 Ptyp : List_Pragma_Type;
400 Ploc : Source_Ptr;
401 end record;
403 -- Note: Ploc points to the terminating semicolon in the List_Off and
404 -- Page cases, and to the pragma keyword for List_On. In the case of
405 -- a pragma List_Off, a List_On entry is also made in the table,
406 -- pointing to the pragma keyword. This ensures that, as required,
407 -- a List (Off) pragma is listed even in list off mode.
409 package List_Pragmas is new Table.Table (
410 Table_Component_Type => List_Pragma_Record,
411 Table_Index_Type => Int,
412 Table_Low_Bound => 1,
413 Table_Initial => 50,
414 Table_Increment => 200,
415 Table_Name => "List_Pragmas");
417 ---------------------------
418 -- Ignore_Errors Feature --
419 ---------------------------
421 -- In certain cases, notably for optional subunits, the compiler operates
422 -- in a mode where errors are to be ignored, and the whole unit is to be
423 -- considered as not present. To implement this we provide the following
424 -- flag to enable special handling, where error messages are suppressed,
425 -- but the Fatal_Error flag will still be set in the normal manner.
427 Ignore_Errors_Enable : Nat := 0;
428 -- Triggering switch. If non-zero, then ignore errors mode is activated.
429 -- This is a counter to allow convenient nesting of enable/disable.
431 ------------------------------
432 -- Error Output Subprograms --
433 ------------------------------
435 procedure Initialize;
436 -- Initializes for output of error messages. Must be called for each
437 -- source file before using any of the other routines in the package.
439 procedure Finalize;
440 -- Finalize processing of error messages for one file and output message
441 -- indicating the number of detected errors.
443 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
444 -- Output a message at specified location. Can be called from the parser
445 -- or the semantic analyzer.
447 procedure Error_Msg_S (Msg : String);
448 -- Output a message at current scan pointer location. This routine can be
449 -- called only from the parser, since it references Scan_Ptr.
451 procedure Error_Msg_AP (Msg : String);
452 -- Output a message just after the previous token. This routine can be
453 -- called only from the parser, since it references Prev_Token_Ptr.
455 procedure Error_Msg_BC (Msg : String);
456 -- Output a message just before the current token. Note that the important
457 -- difference between this and the previous routine is that the BC case
458 -- posts a flag on the current line, whereas AP can post a flag at the
459 -- end of the preceding line. This routine can be called only from the
460 -- parser, since it references Token_Ptr.
462 procedure Error_Msg_SC (Msg : String);
463 -- Output a message at the start of the current token, unless we are at
464 -- the end of file, in which case we always output the message after the
465 -- last real token in the file. This routine can be called only from the
466 -- parser, since it references Token_Ptr.
468 procedure Error_Msg_SP (Msg : String);
469 -- Output a message at the start of the previous token. This routine can
470 -- be called only from the parser, since it references Prev_Token_Ptr.
472 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id);
473 -- Output a message at the Sloc of the given node. This routine can be
474 -- called from the parser or the semantic analyzer, although the call
475 -- from the latter is much more common (and is the most usual way of
476 -- generating error messages from the analyzer). The message text may
477 -- contain a single & insertion, which will reference the given node.
478 -- The message is suppressed if the node N already has a message posted,
479 -- or if it is a warning and warnings and N is an entity node for which
480 -- warnings are suppressed.
482 procedure Error_Msg_NE
483 (Msg : String;
484 N : Node_Or_Entity_Id;
485 E : Node_Or_Entity_Id);
486 -- Output a message at the Sloc of the given node N, with an insertion of
487 -- the name from the given entity node E. This is used by the semantic
488 -- routines, where this is a common error message situation. The Msg
489 -- text will contain a & or } as usual to mark the insertion point.
490 -- This routine can be called from the parser or the analyzer.
492 procedure Error_Msg_NEL
493 (Msg : String;
494 N : Node_Or_Entity_Id;
495 E : Node_Or_Entity_Id;
496 Flag_Location : Source_Ptr);
497 -- Exactly the same as Error_Msg_NE, except that the flag is placed at
498 -- the specified Flag_Location instead of at Sloc (N).
500 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String);
501 -- The error message text of the message identified by Id is replaced by
502 -- the given text. This text may contain insertion characters in the
503 -- usual manner, and need not be the same length as the original text.
505 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr);
506 -- All error messages whose location is in the range From .. To (not
507 -- including the end points) will be deleted from the error listing.
509 procedure Remove_Warning_Messages (N : Node_Id);
510 -- Remove any warning messages corresponding to the Sloc of N or any
511 -- of its descendent nodes. No effect if no such warnings.
513 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr);
514 -- Called in response to a pragma Warnings (Off) to record the source
515 -- location from which warnings are to be turned off.
517 procedure Set_Warnings_Mode_On (Loc : Source_Ptr);
518 -- Called in response to a pragma Warnings (On) to record the source
519 -- location from which warnings are to be turned back on.
521 function Compilation_Errors return Boolean;
522 -- Returns true if errors have been detected, or warnings in -gnatwe
523 -- (treat warnings as errors) mode.
525 procedure dmsg (Id : Error_Msg_Id);
526 -- Debugging routine to dump an error message
528 end Errout;