Merged with mainline at revision 128810.
[official-gcc.git] / gcc / ada / erroutc.ads
blob04e1a4a07ca7ffe5d75e8b1bee4ec040b15828bb
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E R R O U T C --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 1992-2007, 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. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- This packages contains global variables and routines common to error
27 -- reporting packages, including Errout and Prj.Err.
29 with Table;
30 with Types; use Types;
32 package Erroutc is
34 Class_Flag : Boolean := False;
35 -- This flag is set True when outputting a reference to a class-wide
36 -- type, and is used by Add_Class to insert 'Class at the proper point
38 Continuation : Boolean := False;
39 -- Indicates if current message is a continuation. Intialized from the
40 -- Msg_Cont parameter in Error_Msg_Internal and then set True if a \
41 -- insertion character is encountered.
43 Continuation_New_Line : Boolean := False;
44 -- Indicates if current message was a continuation line marked with \\ to
45 -- force a new line. Set True if \\ encountered.
47 Flag_Source : Source_File_Index;
48 -- Source file index for source file where error is being posted
50 Is_Warning_Msg : Boolean := False;
51 -- Set True to indicate if current message is warning message
53 Is_Style_Msg : Boolean := False;
54 -- Set True to indicate if the current message is a style message
56 Is_Serious_Error : Boolean := False;
57 -- Set by Set_Msg_Text to indicate if current message is serious error
59 Is_Unconditional_Msg : Boolean := False;
60 -- Set by Set_Msg_Text to indicate if current message is unconditional
62 Kill_Message : Boolean := False;
63 -- A flag used to kill weird messages (e.g. those containing uninterpreted
64 -- implicit type references) if we have already seen at least one message
65 -- already. The idea is that we hope the weird message is a junk cascaded
66 -- message that should be suppressed.
68 Last_Killed : Boolean := False;
69 -- Set True if the most recently posted non-continuation message was
70 -- killed. This is used to determine the processing of any continuation
71 -- messages that follow.
73 List_Pragmas_Index : Int := 0;
74 -- Index into List_Pragmas table
76 List_Pragmas_Mode : Boolean := False;
77 -- Starts True, gets set False by pragma List (Off), True by List (On)
79 Manual_Quote_Mode : Boolean := False;
80 -- Set True in manual quotation mode
82 Max_Msg_Length : constant := 1024 + 2 * Int (Column_Number'Last);
83 -- Maximum length of error message. The addition of 2 * Column_Number'Last
84 -- ensures that two insertion tokens of maximum length can be accomodated.
85 -- The value of 1024 is an arbitrary value that should be more than long
86 -- enough to accomodate any reasonable message (and for that matter, some
87 -- pretty unreasonable messages!)
89 Msg_Buffer : String (1 .. Max_Msg_Length);
90 -- Buffer used to prepare error messages
92 Msglen : Integer := 0;
93 -- Number of characters currently stored in the message buffer
95 Suppress_Message : Boolean;
96 -- A flag used to suppress certain obviously redundant messages (i.e.
97 -- those referring to a node whose type is Any_Type). This suppression
98 -- is effective only if All_Errors_Mode is off.
100 Suppress_Instance_Location : Boolean := False;
101 -- Normally, if a # location in a message references a location within
102 -- a generic template, then a note is added giving the location of the
103 -- instantiation. If this variable is set True, then this note is not
104 -- output. This is used for internal processing for the case of an
105 -- illegal instantiation. See Error_Msg routine for further details.
107 ----------------------------
108 -- Message ID Definitions --
109 ----------------------------
111 type Error_Msg_Id is new Int;
112 -- A type used to represent specific error messages. Used by the clients
113 -- of this package only in the context of the Get_Error_Id and
114 -- Change_Error_Text subprograms.
116 No_Error_Msg : constant Error_Msg_Id := 0;
117 -- A constant which is different from any value returned by Get_Error_Id.
118 -- Typically used by a client to indicate absense of a saved Id value.
120 Cur_Msg : Error_Msg_Id := No_Error_Msg;
121 -- Id of most recently posted error message
123 function Get_Msg_Id return Error_Msg_Id;
124 -- Returns the Id of the message most recently posted using one of the
125 -- Error_Msg routines.
127 function Get_Location (E : Error_Msg_Id) return Source_Ptr;
128 -- Returns the flag location of the error message with the given id E
130 -----------------------------------
131 -- Error Message Data Structures --
132 -----------------------------------
134 -- The error messages are stored as a linked list of error message objects
135 -- sorted into ascending order by the source location (Sloc). Each object
136 -- records the text of the message and its source location.
138 -- The following record type and table are used to represent error
139 -- messages, with one entry in the table being allocated for each message.
141 type Error_Msg_Object is record
142 Text : String_Ptr;
143 -- Text of error message, fully expanded with all insertions
145 Next : Error_Msg_Id;
146 -- Pointer to next message in error chain. A value of No_Error_Msg
147 -- indicates the end of the chain.
149 Sfile : Source_File_Index;
150 -- Source table index of source file. In the case of an error that
151 -- refers to a template, always references the original template
152 -- not an instantiation copy.
154 Sptr : Source_Ptr;
155 -- Flag pointer. In the case of an error that refers to a template,
156 -- always references the original template, not an instantiation copy.
157 -- This value is the actual place in the source that the error message
158 -- will be posted. Note that an error placed on an instantiation will
159 -- have Sptr pointing to the instantiation point.
161 Optr : Source_Ptr;
162 -- Flag location used in the call to post the error. This is normally
163 -- the same as Sptr, except when an error is posted on a particular
164 -- instantiation of a generic. In such a case, Sptr will point to
165 -- the original source location of the instantiation itself, but
166 -- Optr will point to the template location (more accurately to the
167 -- template copy in the instantiation copy corresponding to the
168 -- instantiation referenced by Sptr).
170 Line : Physical_Line_Number;
171 -- Line number for error message
173 Col : Column_Number;
174 -- Column number for error message
176 Warn : Boolean;
177 -- True if warning message (i.e. insertion character ? appeared)
179 Style : Boolean;
180 -- True if style message (starts with "(style)")
182 Serious : Boolean;
183 -- True if serious error message (not a warning and no | character)
185 Uncond : Boolean;
186 -- True if unconditional message (i.e. insertion character ! appeared)
188 Msg_Cont : Boolean;
189 -- This is used for logical messages that are composed of multiple
190 -- individual messages. For messages that are not part of such a
191 -- group, or that are the first message in such a group. Msg_Cont
192 -- is set to False. For subsequent messages in a group, Msg_Cont
193 -- is set to True. This is used to make sure that such a group of
194 -- messages is either suppressed or retained as a group (e.g. in
195 -- the circuit that deletes identical messages).
197 Deleted : Boolean;
198 -- If this flag is set, the message is not printed. This is used
199 -- in the circuit for deleting duplicate/redundant error messages.
200 end record;
202 package Errors is new Table.Table (
203 Table_Component_Type => Error_Msg_Object,
204 Table_Index_Type => Error_Msg_Id,
205 Table_Low_Bound => 1,
206 Table_Initial => 200,
207 Table_Increment => 200,
208 Table_Name => "Error");
210 First_Error_Msg : Error_Msg_Id;
211 -- The list of error messages, i.e. the first entry on the list of error
212 -- messages. This is not the same as the physically first entry in the
213 -- error message table, since messages are not always inserted in sequence.
215 Last_Error_Msg : Error_Msg_Id;
216 -- The last entry on the list of error messages. Note that this is not
217 -- the same as the physically last entry in the error message table, since
218 -- messages are not always inserted in sequence.
220 --------------------------
221 -- Warning Mode Control --
222 --------------------------
224 -- Pragma Warnings allows warnings to be turned off for a specified
225 -- region of code, and the following tables are the data structure used
226 -- to keep track of these regions.
228 -- The first table is used for the basic command line control, and for
229 -- the forms of Warning with a single ON or OFF parameter
231 -- It contains pairs of source locations, the first being the start
232 -- location for a warnings off region, and the second being the end
233 -- location. When a pragma Warnings (Off) is encountered, a new entry
234 -- is established extending from the location of the pragma to the
235 -- end of the current source file. A subsequent pragma Warnings (On)
236 -- adjusts the end point of this entry appropriately.
238 -- If all warnings are suppressed by comamnd switch, then there is a
239 -- dummy entry (put there by Errout.Initialize) at the start of the
240 -- table which covers all possible Source_Ptr values. Note that the
241 -- source pointer values in this table always reference the original
242 -- template, not an instantiation copy, in the generic case.
244 type Warnings_Entry is record
245 Start : Source_Ptr;
246 Stop : Source_Ptr;
247 end record;
249 package Warnings is new Table.Table (
250 Table_Component_Type => Warnings_Entry,
251 Table_Index_Type => Natural,
252 Table_Low_Bound => 1,
253 Table_Initial => 100,
254 Table_Increment => 200,
255 Table_Name => "Warnings");
257 -- The second table is used for the specific forms of the pragma, where
258 -- the first argument is ON or OFF, and the second parameter is a string
259 -- which is the entire message to suppress, or a prefix of it.
261 type Specific_Warning_Entry is record
262 Start : Source_Ptr;
263 Stop : Source_Ptr;
264 -- Starting and ending source pointers for the range. These are always
265 -- from the same source file.
267 Msg : String_Ptr;
268 -- Message from pragma Warnings (Off, string)
270 Pattern : String_Ptr;
271 -- Same as Msg, excluding initial and final asterisks if present. The
272 -- lower bound of this string is always one.
274 Patlen : Natural;
275 -- Length of pattern string (excluding initial/final asterisks)
277 Open : Boolean;
278 -- Set to True if OFF has been encountered with no matching ON
280 Used : Boolean;
281 -- Set to True if entry has been used to suppress a warning
283 Star_Start : Boolean;
284 -- True if given pattern had * at start
286 Star_End : Boolean;
287 -- True if given pattern had * at end
289 Config : Boolean;
290 -- True if pragma is configuration pragma (in which case no matching
291 -- Off pragma is required, and it is not required that a specific
292 -- warning be suppressed).
293 end record;
295 package Specific_Warnings is new Table.Table (
296 Table_Component_Type => Specific_Warning_Entry,
297 Table_Index_Type => Natural,
298 Table_Low_Bound => 1,
299 Table_Initial => 100,
300 Table_Increment => 200,
301 Table_Name => "Specific_Warnings");
303 -- Note on handling configuration case versus specific case. A complication
304 -- arises from this example:
306 -- pragma Warnings (Off, "not referenced*");
307 -- procedure Mumble (X : Integer) is
308 -- pragma Warnings (On, "not referenced*");
309 -- begin
310 -- null;
311 -- end Mumble;
313 -- The trouble is that the first pragma is technically a configuration
314 -- pragma, and yet it is clearly being used in the context of thinking
315 -- of it as a specific case. To deal with this, what we do is that the
316 -- On entry can match a configuration pragma from the same file, and if
317 -- we find such an On entry, we cancel the indication of it being the
318 -- configuration case. This seems to handle all cases we run into ok.
320 -----------------
321 -- Subprograms --
322 -----------------
324 procedure Add_Class;
325 -- Add 'Class to buffer for class wide type case (Class_Flag set)
327 function Buffer_Ends_With (S : String) return Boolean;
328 -- Tests if message buffer ends with given string preceded by a space
330 procedure Buffer_Remove (S : String);
331 -- Removes given string from end of buffer if it is present
332 -- at end of buffer, and preceded by a space.
334 function Compilation_Errors return Boolean;
335 -- Returns true if errors have been detected, or warnings in -gnatwe
336 -- (treat warnings as errors) mode.
338 procedure dmsg (Id : Error_Msg_Id);
339 -- Debugging routine to dump an error message
341 procedure Debug_Output (N : Node_Id);
342 -- Called from Error_Msg_N and Error_Msg_NE to generate line of debug
343 -- output giving node number (of node N) if the debug X switch is set.
345 procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id);
346 -- This function is passed the Id values of two error messages. If
347 -- either M1 or M2 is a continuation message, or is already deleted,
348 -- the call is ignored. Otherwise a check is made to see if M1 and M2
349 -- are duplicated or redundant. If so, the message to be deleted and
350 -- all its continuations are marked with the Deleted flag set to True.
352 procedure Output_Error_Msgs (E : in out Error_Msg_Id);
353 -- Output source line, error flag, and text of stored error message and
354 -- all subsequent messages for the same line and unit. On return E is
355 -- set to be one higher than the last message output.
357 procedure Output_Line_Number (L : Logical_Line_Number);
358 -- Output a line number as six digits (with leading zeroes suppressed),
359 -- followed by a period and a blank (note that this is 8 characters which
360 -- means that tabs in the source line will not get messed up). Line numbers
361 -- that match or are less than the last Source_Reference pragma are listed
362 -- as all blanks, avoiding output of junk line numbers.
364 procedure Output_Msg_Text (E : Error_Msg_Id);
365 -- Outputs characters of text in the text of the error message E. Note that
366 -- no end of line is output, the caller is responsible for adding the end
367 -- of line. If Error_Msg_Line_Length is non-zero, this is the routine that
368 -- splits the line generating multiple lines of output, and in this case
369 -- the last line has no terminating end of line character.
371 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr);
372 -- All error messages whose location is in the range From .. To (not
373 -- including the end points) will be deleted from the error listing.
375 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean;
376 -- See if two messages have the same text. Returns true if the text
377 -- of the two messages is identical, or if one of them is the same
378 -- as the other with an appended "instance at xxx" tag.
380 procedure Set_Msg_Blank;
381 -- Sets a single blank in the message if the preceding character is a
382 -- non-blank character other than a left parenthesis or minus. Has no
383 -- effect if manual quote mode is turned on.
385 procedure Set_Msg_Blank_Conditional;
386 -- Sets a single blank in the message if the preceding character is a
387 -- non-blank character other than a left parenthesis or quote. Has no
388 -- effect if manual quote mode is turned on.
390 procedure Set_Msg_Char (C : Character);
391 -- Add a single character to the current message. This routine does not
392 -- check for special insertion characters (they are just treated as text
393 -- characters if they occur).
395 procedure Set_Msg_Insertion_File_Name;
396 -- Handle file name insertion (left brace insertion character)
398 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr);
399 -- Handle line number insertion (# insertion character). Loc is the
400 -- location to be referenced, and Flag is the location at which the
401 -- flag is posted (used to determine whether to add "in file xxx")
403 procedure Set_Msg_Insertion_Name_Literal;
405 procedure Set_Msg_Insertion_Name;
406 -- Handle name insertion (% insertion character)
408 procedure Set_Msg_Insertion_Reserved_Name;
409 -- Handle insertion of reserved word name (* insertion character)
411 procedure Set_Msg_Insertion_Reserved_Word
412 (Text : String;
413 J : in out Integer);
414 -- Handle reserved word insertion (upper case letters). The Text argument
415 -- is the current error message input text, and J is an index which on
416 -- entry points to the first character of the reserved word, and on exit
417 -- points past the last character of the reserved word.
419 procedure Set_Msg_Insertion_Run_Time_Name;
420 -- If package System contains a definition for Run_Time_Name (see package
421 -- Targparm for details), then this procedure will insert a message of
422 -- the form (name) into the current error message, with name set in mixed
423 -- case (upper case after any spaces). If no run time name is defined,
424 -- then this routine has no effect).
426 procedure Set_Msg_Insertion_Uint;
427 -- Handle Uint insertion (^ insertion character)
429 procedure Set_Msg_Int (Line : Int);
430 -- Set the decimal representation of the argument in the error message
431 -- buffer with no leading zeroes output.
433 procedure Set_Msg_Name_Buffer;
434 -- Output name from Name_Buffer, with surrounding quotes unless manual
435 -- quotation mode is in effect.
437 procedure Set_Msg_Quote;
438 -- Set quote if in normal quote mode, nothing if in manual quote mode
440 procedure Set_Msg_Str (Text : String);
441 -- Add a sequence of characters to the current message. This routine does
442 -- not check for special insertion characters (they are just treated as
443 -- text characters if they occur).
445 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id);
446 -- Given a message id, move to next message id, but skip any deleted
447 -- messages, so that this results in E on output being the first non-
448 -- deleted message following the input value of E, or No_Error_Msg if
449 -- the input value of E was either already No_Error_Msg, or was the
450 -- last non-deleted message.
452 procedure Set_Specific_Warning_Off
453 (Loc : Source_Ptr;
454 Msg : String;
455 Config : Boolean);
456 -- This is called in response to the two argument form of pragma Warnings
457 -- where the first argument is OFF, and the second argument is a string
458 -- which identifies a specific warning to be suppressed. The first argument
459 -- is the start of the suppression range, and the second argument is the
460 -- string from the pragma. Loc is the location of the pragma (which is the
461 -- start of the range to suppress). Config is True for the configuration
462 -- pragma case (where there is no requirement for a matching OFF pragma).
464 procedure Set_Specific_Warning_On
465 (Loc : Source_Ptr;
466 Msg : String;
467 Err : out Boolean);
468 -- This is called in response to the two argument form of pragma Warnings
469 -- where the first argument is ON, and the second argument is a string
470 -- which identifies a specific warning to be suppressed. The first argument
471 -- is the end of the suppression range, and the second argument is the
472 -- string from the pragma. Err is set to True on return to report the error
473 -- of no matching Warnings Off pragma preceding this one.
475 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr);
476 -- Called in response to a pragma Warnings (Off) to record the source
477 -- location from which warnings are to be turned off.
479 procedure Set_Warnings_Mode_On (Loc : Source_Ptr);
480 -- Called in response to a pragma Warnings (On) to record the source
481 -- location from which warnings are to be turned back on.
483 procedure Test_Style_Warning_Serious_Msg (Msg : String);
484 -- Sets Is_Warning_Msg true if Msg is a warning message (contains a
485 -- question mark character), and False otherwise. Sets Is_Style_Msg
486 -- true if Msg is a style message (starts with "(style)"). Sets
487 -- Is_Serious_Error True unless the message is a warning or style
488 -- message or contains the character | indicating a non-serious
489 -- error message. Note that the call has no effect for continuation
490 -- messages (those whose first character is \).
492 function Warnings_Suppressed (Loc : Source_Ptr) return Boolean;
493 -- Determines if given location is covered by a warnings off suppression
494 -- range in the warnings table (or is suppressed by compilation option,
495 -- which generates a warning range for the whole source file). This routine
496 -- only deals with the general ON/OFF case, not specific warnings
498 function Warning_Specifically_Suppressed
499 (Loc : Source_Ptr;
500 Msg : String_Ptr) return Boolean;
501 -- Determines if given message to be posted at given location is suppressed
502 -- by specific ON/OFF Warnings pragmas specifying this particular message.
504 type Error_Msg_Proc is
505 access procedure (Msg : String; Flag_Location : Source_Ptr);
506 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc);
507 -- Checks that specific warnings are consistent (for non-configuration
508 -- case, properly closed, and used). The argument is a pointer to the
509 -- Error_Msg procedure to be called if any inconsistencies are detected.
511 end Erroutc;