]>
Commit | Line | Data |
---|---|---|
70482933 RK |
1 | ------------------------------------------------------------------------------ |
2 | -- -- | |
3 | -- GNAT COMPILER COMPONENTS -- | |
4 | -- -- | |
5 | -- E R R O U T -- | |
6 | -- -- | |
7 | -- S p e c -- | |
8 | -- -- | |
fbf5a39b | 9 | -- Copyright (C) 1992-2003 Free Software Foundation, Inc. -- |
70482933 RK |
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. -- | |
71ff80dc | 23 | -- Extensive contributions were provided by Ada Core Technologies Inc. -- |
70482933 RK |
24 | -- -- |
25 | ------------------------------------------------------------------------------ | |
26 | ||
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. | |
31 | ||
fbf5a39b AC |
32 | with Err_Vars; |
33 | with Erroutc; | |
70482933 RK |
34 | with Table; |
35 | with Types; use Types; | |
36 | with Uintp; use Uintp; | |
37 | ||
fbf5a39b AC |
38 | with System; |
39 | ||
70482933 RK |
40 | package Errout is |
41 | ||
fbf5a39b | 42 | Serious_Errors_Detected : Nat renames Err_Vars.Serious_Errors_Detected; |
07fc65c4 GB |
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 | |
45 | -- switch -gnatQ is set. | |
46 | ||
fbf5a39b | 47 | Total_Errors_Detected : Nat renames Err_Vars.Total_Errors_Detected; |
07fc65c4 GB |
48 | -- Number of errors detected so far. Includes count of serious errors |
49 | -- and non-serious errors, so this value is always greater than or | |
50 | -- equal to the Serious_Errors_Detected value. | |
70482933 | 51 | |
fbf5a39b | 52 | Warnings_Detected : Nat renames Err_Vars.Warnings_Detected; |
70482933 RK |
53 | -- Number of warnings detected |
54 | ||
fbf5a39b AC |
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 | |
60 | -- improper constructs in No_Run_Time mode). | |
61 | ||
70482933 RK |
62 | type Compiler_State_Type is (Parsing, Analyzing); |
63 | Compiler_State : Compiler_State_Type; | |
64 | -- Indicates current state of compilation. This is put in the Errout | |
65 | -- spec because it affects the action of the error message handling. | |
66 | -- In particular, an attempt is made by Errout to suppress cascaded | |
67 | -- error messages in Parsing mode, but not in the other modes. | |
68 | ||
fbf5a39b AC |
69 | Current_Error_Source_File : Source_File_Index |
70 | renames Err_Vars.Current_Error_Source_File; | |
70482933 RK |
71 | -- Id of current messages. Used to post file name when unit changes. This |
72 | -- is initialized to Main_Source_File at the start of a compilation, which | |
73 | -- means that no file names will be output unless there are errors in units | |
74 | -- other than the main unit. However, if the main unit has a pragma | |
75 | -- Source_Reference line, then this is initialized to No_Source_File, | |
76 | -- to force an initial reference to the real source file name. | |
77 | ||
fbf5a39b | 78 | Raise_Exception_On_Error : Nat renames Err_Vars.Raise_Exception_On_Error; |
70482933 RK |
79 | -- If this value is non-zero, then any attempt to generate an error |
80 | -- message raises the exception Error_Msg_Exception, and the error | |
81 | -- message is not output. This is used for defending against junk | |
82 | -- resulting from illegalities, and also for substitution of more | |
83 | -- appropriate error messages from higher semantic levels. It is | |
84 | -- a counter so that the increment/decrement protocol nests neatly. | |
85 | ||
fbf5a39b | 86 | Error_Msg_Exception : exception renames Err_Vars.Error_Msg_Exception; |
70482933 RK |
87 | -- Exception raised if Raise_Exception_On_Error is true |
88 | ||
89 | ----------------------------------- | |
90 | -- Suppression of Error Messages -- | |
91 | ----------------------------------- | |
92 | ||
93 | -- In an effort to reduce the impact of redundant error messages, the | |
94 | -- error output routines in this package normally suppress certain | |
95 | -- classes of messages as follows: | |
96 | ||
97 | -- 1. Identical messages placed at the same point in the text. Such | |
98 | -- duplicate error message result for example from rescanning | |
99 | -- sections of the text that contain lexical errors. Only one of | |
100 | -- such a set of duplicate messages is output, and the rest are | |
101 | -- suppressed. | |
102 | ||
103 | -- 2. If more than one parser message is generated for a single source | |
104 | -- line, then only the first message is output, the remaining | |
105 | -- messages on the same line are suppressed. | |
106 | ||
107 | -- 3. If a message is posted on a node for which a message has been | |
108 | -- previously posted, then only the first message is retained. The | |
109 | -- Error_Posted flag is used to detect such multiple postings. Note | |
110 | -- that this only applies to semantic messages, since otherwise | |
111 | -- for parser messages, this would be a special case of case 2. | |
112 | ||
113 | -- 4. If a message is posted on a node whose Etype or Entity | |
114 | -- fields reference entities on which an error message has | |
115 | -- already been placed, as indicated by the Error_Posted flag | |
116 | -- being set on these entities, then the message is suppressed. | |
117 | ||
118 | -- 5. If a message attempts to insert an Error node, or a direct | |
119 | -- reference to the Any_Type node, then the message is suppressed. | |
120 | ||
121 | -- This normal suppression action may be overridden in cases 2-5 (but not | |
122 | -- in case 1) by setting All_Errors mode, or by setting the special | |
123 | -- unconditional message insertion character (!) at the end of the message | |
124 | -- text as described below. | |
125 | ||
126 | --------------------------------------------------------- | |
127 | -- Error Message Text and Message Insertion Characters -- | |
128 | --------------------------------------------------------- | |
129 | ||
130 | -- Error message text strings are composed of lower case letters, digits | |
131 | -- and the special characters space, comma, period, colon and semicolon, | |
132 | -- apostrophe and parentheses. Special insertion characters can also | |
133 | -- appear which cause the error message circuit to modify the given | |
134 | -- string as follows: | |
135 | ||
136 | -- Insertion character % (Percent: insert name from Names table) | |
137 | -- The character % is replaced by the text for the name specified by | |
138 | -- the Name_Id value stored in Error_Msg_Name_1. A blank precedes | |
139 | -- the name if it is preceded by a non-blank character other than a | |
140 | -- left parenthesis. The name is enclosed in quotes unless manual | |
141 | -- quotation mode is set. If the Name_Id is set to No_Name, then | |
142 | -- no insertion occurs; if the Name_Id is set to Error_Name, then | |
143 | -- the string <error> is inserted. A second and third % may appear | |
144 | -- in a single message, similarly replaced by the names which are | |
145 | -- specified by the Name_Id values stored in Error_Msg_Name_2 and | |
146 | -- Error_Msg_Name_3. The names are decoded and cased according to | |
147 | -- the current identifier casing mode. | |
148 | ||
149 | -- Insertion character $ (Dollar: insert unit name from Names table) | |
150 | -- The character $ is treated similarly to %, except that the name | |
151 | -- is obtained from the Unit_Name_Type value in Error_Msg_Unit_1 | |
152 | -- and Error_Msg_Unit_2, as provided by Get_Unit_Name_String in | |
153 | -- package Uname. Note that this name includes the postfix (spec) | |
154 | -- or (body) strings. If this postfix is not required, use the | |
155 | -- normal % insertion for the unit name. | |
156 | ||
157 | -- Insertion character { (Left brace: insert literally from names table) | |
158 | -- The character { is treated similarly to %, except that the | |
159 | -- name is output literally as stored in the names table without | |
160 | -- adjusting the casing. This can be used for file names and in | |
161 | -- other situations where the name string is to be output unchanged. | |
162 | ||
163 | -- Insertion character * (Asterisk, insert reserved word name) | |
164 | -- The insertion character * is treated exactly like % except that | |
165 | -- the resulting name is cased according to the default conventions | |
166 | -- for reserved words (see package Scans). | |
167 | ||
168 | -- Insertion character & (Ampersand: insert name from node) | |
169 | -- The insertion character & is treated similarly to %, except that | |
170 | -- the name is taken from the Chars field of the given node, and may | |
171 | -- refer to a child unit name, or a selected component. The casing | |
172 | -- is, if possible, taken from the original source reference, which | |
173 | -- is obtained from the Sloc field of the given node or nodes. If no | |
174 | -- Sloc is available (happens e.g. for nodes in package Standard), | |
175 | -- then the default case (see Scans spec) is used. The nodes to be | |
176 | -- used are stored in Error_Msg_Node_1, Error_Msg_Node_2. No insertion | |
177 | -- occurs for the Empty node, and the Error node results in the | |
178 | -- insertion of the characters <error>. In addition, if the special | |
179 | -- global variable Error_Msg_Qual_Level is non-zero, then the | |
180 | -- reference will include up to the given number of levels of | |
181 | -- qualification, using the scope chain. | |
182 | ||
183 | -- Insertion character # (Pound: insert line number reference) | |
184 | -- The character # is replaced by the string indicating the source | |
185 | -- position stored in Error_Msg_Sloc. There are three cases: | |
186 | -- | |
187 | -- for package Standard: in package Standard | |
188 | -- for locations in current file: at line nnn:ccc | |
189 | -- for locations in other files: at filename:nnn:ccc | |
190 | -- | |
191 | -- By convention, the # insertion character is only used at the end | |
192 | -- of an error message, so the above strings only appear as the last | |
193 | -- characters of an error message. | |
194 | ||
195 | -- Insertion character } (Right brace: insert type reference) | |
196 | -- The character } is replaced by a string describing the type | |
197 | -- referenced by the entity whose Id is stored in Error_Msg_Node_1. | |
198 | -- the string gives the name or description of the type, and also | |
199 | -- where appropriate the location of its declaration. Special | |
200 | -- cases like "some integer type" are handled appropriately. Only | |
201 | -- one } is allowed in a message, since there is not enough room | |
202 | -- for two (the insertion can be quite long, including a file name) | |
203 | -- In addition, if the special global variable Error_Msg_Qual_Level | |
204 | -- is non-zero, then the reference will include up to the given | |
205 | -- number of levels of qualification, using the scope chain. | |
206 | ||
207 | -- Insertion character @ (At: insert column number reference) | |
208 | -- The character @ is replaced by null if the RM_Column_Check mode is | |
209 | -- off (False). If the switch is on (True), then @ is replaced by the | |
210 | -- text string " in column nnn" where nnn is the decimal representation | |
211 | -- of the column number stored in Error_Msg_Col plus one (the plus one | |
212 | -- is because the number is stored 0-origin and displayed 1-origin). | |
213 | ||
214 | -- Insertion character ^ (Carret: insert integer value) | |
215 | -- The character ^ is replaced by the decimal conversion of the Uint | |
216 | -- value stored in Error_Msg_Uint_1, with a possible leading minus. | |
217 | -- A second ^ may occur in the message, in which case it is replaced | |
218 | -- by the decimal conversion of the Uint value in Error_Msg_Uint_2. | |
219 | ||
fbf5a39b AC |
220 | -- Insertion character > (Right bracket, run time name) |
221 | -- The character > is replaced by a string of the form (name) if | |
222 | -- Targparm scanned out a Run_Time_Name (see package Targparm for | |
223 | -- details). The name is enclosed in parentheses and output in mixed | |
224 | -- case mode (upper case after any space in the name). If no run time | |
225 | -- name is defined, this insertion character has no effect. | |
226 | ||
70482933 RK |
227 | -- Insertion character ! (Exclamation: unconditional message) |
228 | -- The character ! appearing as the last character of a message makes | |
229 | -- the message unconditional which means that it is output even if it | |
230 | -- would normally be suppressed. See section above for a description | |
231 | -- of the cases in which messages are normally suppressed. | |
232 | ||
233 | -- Insertion character ? (Question: warning message) | |
234 | -- The character ? appearing anywhere in a message makes the message | |
235 | -- a warning instead of a normal error message, and the text of the | |
236 | -- message will be preceded by "Warning:" instead of "Error:" The | |
237 | -- handling of warnings if further controlled by the Warning_Mode | |
238 | -- option (-w switch), see package Opt for further details, and | |
239 | -- also by the current setting from pragma Warnings. This pragma | |
240 | -- applies only to warnings issued from the semantic phase (not | |
241 | -- the parser), but currently all relevant warnings are posted | |
242 | -- by the semantic phase anyway. Messages starting with (style) | |
243 | -- are also treated as warning messages. | |
244 | ||
245 | -- Insertion character A-Z (Upper case letter: Ada reserved word) | |
246 | -- If two or more upper case letters appear in the message, they are | |
247 | -- taken as an Ada reserved word, and are converted to the default | |
248 | -- case for reserved words (see Scans package spec). Surrounding | |
249 | -- quotes are added unless manual quotation mode is currently set. | |
250 | ||
251 | -- Insertion character ` (Backquote: set manual quotation mode) | |
252 | -- The backquote character always appears in pairs. Each backquote | |
253 | -- of the pair is replaced by a double quote character. In addition, | |
254 | -- Any reserved keywords, or name insertions between these backquotes | |
255 | -- are not surrounded by the usual automatic double quotes. See the | |
256 | -- section below on manual quotation mode for further details. | |
257 | ||
258 | -- Insertion character ' (Quote: literal character) | |
259 | -- Precedes a character which is placed literally into the message. | |
260 | -- Used to insert characters into messages that are one of the | |
fbf5a39b AC |
261 | -- insertion characters defined here. Also useful in inserting |
262 | -- sequences of upper case letters (e.g. RM) which are not to be | |
263 | -- treated as keywords. | |
70482933 RK |
264 | |
265 | -- Insertion character \ (Backslash: continuation message) | |
266 | -- Indicates that the message is a continuation of a message | |
267 | -- previously posted. This is used to ensure that such groups | |
268 | -- of messages are treated as a unit. The \ character must be | |
269 | -- the first character of the message text. | |
270 | ||
07fc65c4 GB |
271 | -- Insertion character | (vertical bar, non-serious error) |
272 | -- By default, error messages (other than warning messages) are | |
273 | -- considered to be fatal error messages which prevent expansion | |
274 | -- or generation of code in the presence of the -gnatQ switch. | |
275 | -- If the insertion character | appears, the message is considered | |
276 | -- to be non-serious, and does not cause Serious_Errors_Detected | |
277 | -- to be incremented (so expansion is not prevented by such a msg). | |
278 | ||
70482933 RK |
279 | ----------------------------------------------------- |
280 | -- Global Values Used for Error Message Insertions -- | |
281 | ----------------------------------------------------- | |
282 | ||
283 | -- The following global variables are essentially additional parameters | |
284 | -- passed to the error message routine for insertion sequences described | |
285 | -- above. The reason these are passed globally is that the insertion | |
286 | -- mechanism is essentially an untyped one in which the appropriate | |
287 | -- variables are set dependingon the specific insertion characters used. | |
288 | ||
fbf5a39b | 289 | Error_Msg_Col : Column_Number renames Err_Vars.Error_Msg_Col; |
70482933 RK |
290 | -- Column for @ insertion character in message |
291 | ||
fbf5a39b AC |
292 | Error_Msg_Uint_1 : Uint renames Err_Vars.Error_Msg_Uint_1; |
293 | Error_Msg_Uint_2 : Uint renames Err_Vars.Error_Msg_Uint_2; | |
70482933 RK |
294 | -- Uint values for ^ insertion characters in message |
295 | ||
fbf5a39b | 296 | Error_Msg_Sloc : Source_Ptr renames Err_Vars.Error_Msg_Sloc; |
70482933 RK |
297 | -- Source location for # insertion character in message |
298 | ||
fbf5a39b AC |
299 | Error_Msg_Name_1 : Name_Id renames Err_Vars.Error_Msg_Name_1; |
300 | Error_Msg_Name_2 : Name_Id renames Err_Vars.Error_Msg_Name_2; | |
301 | Error_Msg_Name_3 : Name_Id renames Err_Vars.Error_Msg_Name_3; | |
70482933 RK |
302 | -- Name_Id values for % insertion characters in message |
303 | ||
fbf5a39b AC |
304 | Error_Msg_Unit_1 : Name_Id renames Err_Vars.Error_Msg_Unit_1; |
305 | Error_Msg_Unit_2 : Name_Id renames Err_Vars.Error_Msg_Unit_2; | |
70482933 RK |
306 | -- Name_Id values for $ insertion characters in message |
307 | ||
fbf5a39b AC |
308 | Error_Msg_Node_1 : Node_Id renames Err_Vars.Error_Msg_Node_1; |
309 | Error_Msg_Node_2 : Node_Id renames Err_Vars.Error_Msg_Node_2; | |
70482933 RK |
310 | -- Node_Id values for & insertion characters in message |
311 | ||
fbf5a39b | 312 | Error_Msg_Qual_Level : Int renames Err_Vars.Error_Msg_Qual_Level; |
70482933 RK |
313 | -- Number of levels of qualification required for type name (see the |
314 | -- description of the } insertion character. Note that this value does | |
315 | -- note get reset by any Error_Msg call, so the caller is responsible | |
316 | -- for resetting it. | |
317 | ||
70482933 RK |
318 | ----------------------------------------------------- |
319 | -- Format of Messages and Manual Quotation Control -- | |
320 | ----------------------------------------------------- | |
321 | ||
322 | -- Messages are generally all in lower case, except for inserted names | |
323 | -- and appear in one of the following three forms: | |
324 | ||
325 | -- error: text | |
326 | -- warning: text | |
327 | ||
328 | -- The prefixes error and warning are supplied automatically (depending | |
329 | -- on the use of the ? insertion character), and the call to the error | |
330 | -- message routine supplies the text. The "error: " prefix is omitted | |
331 | -- in brief error message formats. | |
332 | ||
333 | -- Reserved Ada keywords in the message are in the default keyword case | |
334 | -- (determined from the given source program), surrounded by quotation | |
335 | -- marks. This is achieved by spelling the reserved word in upper case | |
336 | -- letters, which is recognized as a request for insertion of quotation | |
337 | -- marks by the error text processor. Thus for example: | |
338 | ||
339 | -- Error_Msg_AP ("IS expected"); | |
340 | ||
341 | -- would result in the output of one of the following: | |
342 | ||
343 | -- error: "is" expected | |
344 | -- error: "IS" expected | |
345 | -- error: "Is" expected | |
346 | ||
347 | -- the choice between these being made by looking at the casing convention | |
348 | -- used for keywords (actually the first compilation unit keyword) in the | |
349 | -- source file. | |
350 | ||
351 | -- In the case of names, the default mode for the error text processor | |
352 | -- is to surround the name by quotation marks automatically. The case | |
353 | -- used for the identifier names is taken from the source program where | |
354 | -- possible, and otherwise is the default casing convention taken from | |
355 | -- the source file usage. | |
356 | ||
357 | -- In some cases, better control over the placement of quote marks is | |
358 | -- required. This is achieved using manual quotation mode. In this mode, | |
359 | -- one or more insertion sequences is surrounded by backquote characters. | |
360 | -- The backquote characters are output as double quote marks, and normal | |
361 | -- automatic insertion of quotes is suppressed between the double quotes. | |
362 | -- For example: | |
363 | ||
364 | -- Error_Msg_AP ("`END &;` expected"); | |
365 | ||
366 | -- generates a message like | |
367 | ||
368 | -- error: "end Open_Scope;" expected | |
369 | ||
370 | -- where the node specifying the name Open_Scope has been stored in | |
371 | -- Error_Msg_Node_1 prior to the call. The great majority of error | |
372 | -- messages operates in normal quotation mode. | |
373 | ||
374 | -- Note: the normal automatic insertion of spaces before insertion | |
375 | -- sequences (such as those that come from & and %) is suppressed in | |
376 | -- manual quotation mode, so blanks, if needed as in the above example, | |
377 | -- must be explicitly present. | |
378 | ||
379 | ---------------------------- | |
380 | -- Message ID Definitions -- | |
381 | ---------------------------- | |
382 | ||
fbf5a39b AC |
383 | subtype Error_Msg_Id is Erroutc.Error_Msg_Id; |
384 | function "=" (Left, Right : Error_Msg_Id) return Boolean | |
385 | renames Erroutc."="; | |
70482933 RK |
386 | -- A type used to represent specific error messages. Used by the clients |
387 | -- of this package only in the context of the Get_Error_Id and | |
388 | -- Change_Error_Text subprograms. | |
389 | ||
fbf5a39b | 390 | No_Error_Msg : constant Error_Msg_Id := Erroutc.No_Error_Msg; |
70482933 RK |
391 | -- A constant which is different from any value returned by Get_Error_Id. |
392 | -- Typically used by a client to indicate absense of a saved Id value. | |
393 | ||
fbf5a39b | 394 | function Get_Msg_Id return Error_Msg_Id renames Erroutc.Get_Msg_Id; |
70482933 RK |
395 | -- Returns the Id of the message most recently posted using one of the |
396 | -- Error_Msg routines. | |
397 | ||
fbf5a39b AC |
398 | function Get_Location (E : Error_Msg_Id) return Source_Ptr |
399 | renames Erroutc.Get_Location; | |
70482933 RK |
400 | -- Returns the flag location of the error message with the given id E. |
401 | ||
402 | ------------------------ | |
403 | -- List Pragmas Table -- | |
404 | ------------------------ | |
405 | ||
406 | -- When a pragma Page or pragma List is encountered by the parser, an | |
407 | -- entry is made in the following table. This table is then used to | |
408 | -- control the full listing if one is being generated. Note that the | |
409 | -- reason we do the processing in the parser is so that we get proper | |
410 | -- listing control even in syntax check only mode. | |
411 | ||
412 | type List_Pragma_Type is (List_On, List_Off, Page); | |
413 | ||
414 | type List_Pragma_Record is record | |
415 | Ptyp : List_Pragma_Type; | |
416 | Ploc : Source_Ptr; | |
417 | end record; | |
418 | ||
419 | -- Note: Ploc points to the terminating semicolon in the List_Off and | |
420 | -- Page cases, and to the pragma keyword for List_On. In the case of | |
421 | -- a pragma List_Off, a List_On entry is also made in the table, | |
422 | -- pointing to the pragma keyword. This ensures that, as required, | |
423 | -- a List (Off) pragma is listed even in list off mode. | |
424 | ||
425 | package List_Pragmas is new Table.Table ( | |
426 | Table_Component_Type => List_Pragma_Record, | |
427 | Table_Index_Type => Int, | |
428 | Table_Low_Bound => 1, | |
429 | Table_Initial => 50, | |
430 | Table_Increment => 200, | |
431 | Table_Name => "List_Pragmas"); | |
432 | ||
433 | --------------------------- | |
434 | -- Ignore_Errors Feature -- | |
435 | --------------------------- | |
436 | ||
437 | -- In certain cases, notably for optional subunits, the compiler operates | |
438 | -- in a mode where errors are to be ignored, and the whole unit is to be | |
439 | -- considered as not present. To implement this we provide the following | |
440 | -- flag to enable special handling, where error messages are suppressed, | |
441 | -- but the Fatal_Error flag will still be set in the normal manner. | |
442 | ||
443 | Ignore_Errors_Enable : Nat := 0; | |
444 | -- Triggering switch. If non-zero, then ignore errors mode is activated. | |
445 | -- This is a counter to allow convenient nesting of enable/disable. | |
446 | ||
447 | ------------------------------ | |
448 | -- Error Output Subprograms -- | |
449 | ------------------------------ | |
450 | ||
451 | procedure Initialize; | |
452 | -- Initializes for output of error messages. Must be called for each | |
453 | -- source file before using any of the other routines in the package. | |
454 | ||
455 | procedure Finalize; | |
456 | -- Finalize processing of error messages for one file and output message | |
457 | -- indicating the number of detected errors. | |
458 | ||
459 | procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr); | |
460 | -- Output a message at specified location. Can be called from the parser | |
461 | -- or the semantic analyzer. | |
462 | ||
463 | procedure Error_Msg_S (Msg : String); | |
464 | -- Output a message at current scan pointer location. This routine can be | |
465 | -- called only from the parser, since it references Scan_Ptr. | |
466 | ||
467 | procedure Error_Msg_AP (Msg : String); | |
468 | -- Output a message just after the previous token. This routine can be | |
469 | -- called only from the parser, since it references Prev_Token_Ptr. | |
470 | ||
471 | procedure Error_Msg_BC (Msg : String); | |
472 | -- Output a message just before the current token. Note that the important | |
473 | -- difference between this and the previous routine is that the BC case | |
474 | -- posts a flag on the current line, whereas AP can post a flag at the | |
475 | -- end of the preceding line. This routine can be called only from the | |
476 | -- parser, since it references Token_Ptr. | |
477 | ||
478 | procedure Error_Msg_SC (Msg : String); | |
479 | -- Output a message at the start of the current token, unless we are at | |
480 | -- the end of file, in which case we always output the message after the | |
481 | -- last real token in the file. This routine can be called only from the | |
482 | -- parser, since it references Token_Ptr. | |
483 | ||
484 | procedure Error_Msg_SP (Msg : String); | |
485 | -- Output a message at the start of the previous token. This routine can | |
486 | -- be called only from the parser, since it references Prev_Token_Ptr. | |
487 | ||
488 | procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id); | |
489 | -- Output a message at the Sloc of the given node. This routine can be | |
490 | -- called from the parser or the semantic analyzer, although the call | |
491 | -- from the latter is much more common (and is the most usual way of | |
492 | -- generating error messages from the analyzer). The message text may | |
493 | -- contain a single & insertion, which will reference the given node. | |
07fc65c4 GB |
494 | -- The message is suppressed if the node N already has a message posted, |
495 | -- or if it is a warning and warnings and N is an entity node for which | |
496 | -- warnings are suppressed. | |
70482933 | 497 | |
fbf5a39b AC |
498 | procedure Error_Msg_F (Msg : String; N : Node_Id); |
499 | -- Similar to Error_Msg_N except that the message is placed on the | |
500 | -- first node of the construct N (First_Node (N)). | |
501 | ||
70482933 RK |
502 | procedure Error_Msg_NE |
503 | (Msg : String; | |
504 | N : Node_Or_Entity_Id; | |
505 | E : Node_Or_Entity_Id); | |
07fc65c4 GB |
506 | -- Output a message at the Sloc of the given node N, with an insertion of |
507 | -- the name from the given entity node E. This is used by the semantic | |
70482933 RK |
508 | -- routines, where this is a common error message situation. The Msg |
509 | -- text will contain a & or } as usual to mark the insertion point. | |
510 | -- This routine can be called from the parser or the analyzer. | |
511 | ||
fbf5a39b AC |
512 | procedure Error_Msg_FE |
513 | (Msg : String; | |
514 | N : Node_Id; | |
515 | E : Node_Or_Entity_Id); | |
516 | -- Same as Error_Msg_NE, except that the message is placed on the first | |
517 | -- node of the construct N (First_Node (N)). | |
518 | ||
07fc65c4 GB |
519 | procedure Error_Msg_NEL |
520 | (Msg : String; | |
521 | N : Node_Or_Entity_Id; | |
522 | E : Node_Or_Entity_Id; | |
523 | Flag_Location : Source_Ptr); | |
524 | -- Exactly the same as Error_Msg_NE, except that the flag is placed at | |
525 | -- the specified Flag_Location instead of at Sloc (N). | |
526 | ||
fbf5a39b AC |
527 | procedure Error_Msg_NW |
528 | (Eflag : Boolean; | |
529 | Msg : String; | |
530 | N : Node_Or_Entity_Id); | |
531 | -- This routine is used for posting a message conditionally. The message | |
532 | -- is posted (with the same effect as Error_Msg_N (Msg, N) if and only | |
533 | -- if Eflag is True and if the node N is within the main extended source | |
534 | -- unit. Typically this is a warning mode flag. | |
535 | ||
70482933 RK |
536 | procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String); |
537 | -- The error message text of the message identified by Id is replaced by | |
538 | -- the given text. This text may contain insertion characters in the | |
539 | -- usual manner, and need not be the same length as the original text. | |
540 | ||
fbf5a39b AC |
541 | function First_Node (C : Node_Id) return Node_Id; |
542 | -- Given a construct C, finds the first node in the construct, i.e. the | |
543 | -- one with the lowest Sloc value. This is useful in placing error msgs. | |
544 | ||
545 | procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) | |
546 | renames Erroutc.Purge_Messages; | |
70482933 RK |
547 | -- All error messages whose location is in the range From .. To (not |
548 | -- including the end points) will be deleted from the error listing. | |
549 | ||
550 | procedure Remove_Warning_Messages (N : Node_Id); | |
551 | -- Remove any warning messages corresponding to the Sloc of N or any | |
552 | -- of its descendent nodes. No effect if no such warnings. | |
553 | ||
fbf5a39b AC |
554 | procedure Remove_Warning_Messages (L : List_Id); |
555 | -- Remove warnings on all elements of a list. | |
556 | ||
557 | procedure Set_Ignore_Errors (To : Boolean); | |
558 | -- Following a call to this procedure with To=True, all error calls are | |
559 | -- ignored. A call with To=False restores the default treatment in which | |
560 | -- error calls are treated as usual (and as described in this spec). | |
561 | ||
562 | procedure Set_Warnings_Mode_Off (Loc : Source_Ptr) | |
563 | renames Erroutc.Set_Warnings_Mode_Off; | |
70482933 RK |
564 | -- Called in response to a pragma Warnings (Off) to record the source |
565 | -- location from which warnings are to be turned off. | |
566 | ||
fbf5a39b AC |
567 | procedure Set_Warnings_Mode_On (Loc : Source_Ptr) |
568 | renames Erroutc.Set_Warnings_Mode_On; | |
70482933 RK |
569 | -- Called in response to a pragma Warnings (On) to record the source |
570 | -- location from which warnings are to be turned back on. | |
571 | ||
fbf5a39b AC |
572 | function Compilation_Errors return Boolean |
573 | renames Erroutc.Compilation_Errors; | |
70482933 RK |
574 | -- Returns true if errors have been detected, or warnings in -gnatwe |
575 | -- (treat warnings as errors) mode. | |
576 | ||
fbf5a39b AC |
577 | procedure Error_Msg_CRT (Feature : String; N : Node_Id); |
578 | -- Posts a non-fatal message on node N saying that the feature | |
579 | -- identified by the Feature argument is not supported in either | |
580 | -- configurable run-time mode or no run-time mode (as appropriate). | |
581 | -- In the former case, the name of the library is output if available. | |
582 | ||
583 | procedure dmsg (Id : Error_Msg_Id) renames Erroutc.dmsg; | |
70482933 RK |
584 | -- Debugging routine to dump an error message |
585 | ||
fbf5a39b AC |
586 | ------------------------------------ |
587 | -- Utility Interface for Back End -- | |
588 | ------------------------------------ | |
589 | ||
590 | -- The following subprograms can be used by the back end for the purposes | |
591 | -- of concocting error messages that are not output via Errout, e.g. the | |
592 | -- messages generated by the gcc back end. | |
593 | ||
594 | procedure Set_Identifier_Casing | |
595 | (Identifier_Name : System.Address; | |
596 | File_Name : System.Address); | |
597 | -- The identifier is a null terminated string that represents the name | |
598 | -- of an identifier appearing in the source program. File_Name is a null | |
599 | -- terminated string giving the corresponding file name for the identifier | |
600 | -- as obtained from the front end by the use of Full_Debug_Name to the | |
601 | -- source file referenced by the corresponding source location value. | |
602 | -- On return, the name is in Name_Buffer, null terminated with Name_Len | |
603 | -- set. This name is the identifier name as passed, cased according to | |
604 | -- the default identifier casing for the given file. | |
605 | ||
70482933 | 606 | end Errout; |