2013-11-13 Jan-Benedict Glaw <jbglaw@lug-owl.de>
[official-gcc.git] / gcc / ada / erroutc.ads
blob647e58bafdd4ea6b3da85fff7aadf676256c0141
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-2013, 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. Initialized 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 Has_Double_Exclam : Boolean := False;
51 -- Set true to indicate that the current message contains the insertion
52 -- sequence !! (force warnings even in non-main unit source files).
54 Is_Serious_Error : Boolean := False;
55 -- Set True for a serious error (i.e. any message that is not a warning
56 -- or style message, and that does not contain a | insertion character).
58 Is_Unconditional_Msg : Boolean := False;
59 -- Set True to indicate that the current message contains the insertion
60 -- character ! and is thus to be treated as an unconditional message.
62 Is_Warning_Msg : Boolean := False;
63 -- Set True to indicate if current message is warning message (contains ?)
65 Warning_Msg_Char : Character;
66 -- Warning character, valid only if Is_Warning_Msg is True
67 -- ' ' -- ? appeared on its own in message
68 -- '?' -- ?? appeared in message
69 -- 'x' -- ?x? appeared in message
70 -- 'X' -- ?x? appeared in message (X is upper case of x)
72 Is_Style_Msg : Boolean := False;
73 -- Set True to indicate if the current message is a style message
74 -- (i.e. a message whose text starts with the characters "(style)").
76 Kill_Message : Boolean := False;
77 -- A flag used to kill weird messages (e.g. those containing uninterpreted
78 -- implicit type references) if we have already seen at least one message
79 -- already. The idea is that we hope the weird message is a junk cascaded
80 -- message that should be suppressed.
82 Last_Killed : Boolean := False;
83 -- Set True if the most recently posted non-continuation message was
84 -- killed. This is used to determine the processing of any continuation
85 -- messages that follow.
87 List_Pragmas_Index : Int := 0;
88 -- Index into List_Pragmas table
90 List_Pragmas_Mode : Boolean := False;
91 -- Starts True, gets set False by pragma List (Off), True by List (On)
93 Manual_Quote_Mode : Boolean := False;
94 -- Set True in manual quotation mode
96 Max_Msg_Length : constant := 1024 + 2 * Int (Column_Number'Last);
97 -- Maximum length of error message. The addition of 2 * Column_Number'Last
98 -- ensures that two insertion tokens of maximum length can be accommodated.
99 -- The value of 1024 is an arbitrary value that should be more than long
100 -- enough to accommodate any reasonable message (and for that matter, some
101 -- pretty unreasonable messages!)
103 Msg_Buffer : String (1 .. Max_Msg_Length);
104 -- Buffer used to prepare error messages
106 Msglen : Integer := 0;
107 -- Number of characters currently stored in the message buffer
109 Suppress_Message : Boolean;
110 -- A flag used to suppress certain obviously redundant messages (i.e.
111 -- those referring to a node whose type is Any_Type). This suppression
112 -- is effective only if All_Errors_Mode is off.
114 Suppress_Instance_Location : Boolean := False;
115 -- Normally, if a # location in a message references a location within
116 -- a generic template, then a note is added giving the location of the
117 -- instantiation. If this variable is set True, then this note is not
118 -- output. This is used for internal processing for the case of an
119 -- illegal instantiation. See Error_Msg routine for further details.
121 ----------------------------
122 -- Message ID Definitions --
123 ----------------------------
125 type Error_Msg_Id is new Int;
126 -- A type used to represent specific error messages. Used by the clients
127 -- of this package only in the context of the Get_Error_Id and
128 -- Change_Error_Text subprograms.
130 No_Error_Msg : constant Error_Msg_Id := 0;
131 -- A constant which is different from any value returned by Get_Error_Id.
132 -- Typically used by a client to indicate absence of a saved Id value.
134 Cur_Msg : Error_Msg_Id := No_Error_Msg;
135 -- Id of most recently posted error message
137 function Get_Msg_Id return Error_Msg_Id;
138 -- Returns the Id of the message most recently posted using one of the
139 -- Error_Msg routines.
141 function Get_Location (E : Error_Msg_Id) return Source_Ptr;
142 -- Returns the flag location of the error message with the given id E
144 -----------------------------------
145 -- Error Message Data Structures --
146 -----------------------------------
148 -- The error messages are stored as a linked list of error message objects
149 -- sorted into ascending order by the source location (Sloc). Each object
150 -- records the text of the message and its source location.
152 -- The following record type and table are used to represent error
153 -- messages, with one entry in the table being allocated for each message.
155 type Error_Msg_Object is record
156 Text : String_Ptr;
157 -- Text of error message, fully expanded with all insertions
159 Next : Error_Msg_Id;
160 -- Pointer to next message in error chain. A value of No_Error_Msg
161 -- indicates the end of the chain.
163 Prev : Error_Msg_Id;
164 -- Pointer to previous message in error chain. Only set during the
165 -- Finalize procedure. A value of No_Error_Msg indicates the first
166 -- message in the chain.
168 Sfile : Source_File_Index;
169 -- Source table index of source file. In the case of an error that
170 -- refers to a template, always references the original template
171 -- not an instantiation copy.
173 Sptr : Source_Ptr;
174 -- Flag pointer. In the case of an error that refers to a template,
175 -- always references the original template, not an instantiation copy.
176 -- This value is the actual place in the source that the error message
177 -- will be posted. Note that an error placed on an instantiation will
178 -- have Sptr pointing to the instantiation point.
180 Optr : Source_Ptr;
181 -- Flag location used in the call to post the error. This is normally
182 -- the same as Sptr, except when an error is posted on a particular
183 -- instantiation of a generic. In such a case, Sptr will point to
184 -- the original source location of the instantiation itself, but
185 -- Optr will point to the template location (more accurately to the
186 -- template copy in the instantiation copy corresponding to the
187 -- instantiation referenced by Sptr).
189 Line : Physical_Line_Number;
190 -- Line number for error message
192 Col : Column_Number;
193 -- Column number for error message
195 Warn : Boolean;
196 -- True if warning message (i.e. insertion character ? appeared)
198 Warn_Chr : Character;
199 -- Warning character, valid only if Warn is True
200 -- ' ' -- ? appeared on its own in message
201 -- '?' -- ?? appeared in message
202 -- 'x' -- ?x? appeared in message
203 -- 'X' -- ?x? appeared in message (X is upper case of x)
205 Style : Boolean;
206 -- True if style message (starts with "(style)")
208 Serious : Boolean;
209 -- True if serious error message (not a warning and no | character)
211 Uncond : Boolean;
212 -- True if unconditional message (i.e. insertion character ! appeared)
214 Msg_Cont : Boolean;
215 -- This is used for logical messages that are composed of multiple
216 -- individual messages. For messages that are not part of such a
217 -- group, or that are the first message in such a group. Msg_Cont
218 -- is set to False. For subsequent messages in a group, Msg_Cont
219 -- is set to True. This is used to make sure that such a group of
220 -- messages is either suppressed or retained as a group (e.g. in
221 -- the circuit that deletes identical messages).
223 Deleted : Boolean;
224 -- If this flag is set, the message is not printed. This is used
225 -- in the circuit for deleting duplicate/redundant error messages.
226 end record;
228 package Errors is new Table.Table (
229 Table_Component_Type => Error_Msg_Object,
230 Table_Index_Type => Error_Msg_Id,
231 Table_Low_Bound => 1,
232 Table_Initial => 200,
233 Table_Increment => 200,
234 Table_Name => "Error");
236 First_Error_Msg : Error_Msg_Id;
237 -- The list of error messages, i.e. the first entry on the list of error
238 -- messages. This is not the same as the physically first entry in the
239 -- error message table, since messages are not always inserted in sequence.
241 Last_Error_Msg : Error_Msg_Id;
242 -- The last entry on the list of error messages. Note: this is not the same
243 -- as the physically last entry in the error message table, since messages
244 -- are not always inserted in sequence.
246 --------------------------
247 -- Warning Mode Control --
248 --------------------------
250 -- Pragma Warnings allows warnings to be turned off for a specified region
251 -- of code, and the following tables are the data structures used to keep
252 -- track of these regions.
254 -- The first table is used for the basic command line control, and for the
255 -- forms of Warning with a single ON or OFF parameter.
257 -- It contains pairs of source locations, the first being the start
258 -- location for a warnings off region, and the second being the end
259 -- location. When a pragma Warnings (Off) is encountered, a new entry is
260 -- established extending from the location of the pragma to the end of the
261 -- current source file. A subsequent pragma Warnings (On) adjusts the end
262 -- point of this entry appropriately.
264 -- If all warnings are suppressed by command switch, then there is a dummy
265 -- entry (put there by Errout.Initialize) at the start of the table which
266 -- covers all possible Source_Ptr values. Note that the source pointer
267 -- values in this table always reference the original template, not an
268 -- instantiation copy, in the generic case.
270 type Warnings_Entry is record
271 Start : Source_Ptr;
272 Stop : Source_Ptr;
273 end record;
275 package Warnings is new Table.Table (
276 Table_Component_Type => Warnings_Entry,
277 Table_Index_Type => Natural,
278 Table_Low_Bound => 1,
279 Table_Initial => 100,
280 Table_Increment => 200,
281 Table_Name => "Warnings");
283 -- The second table is used for the specific forms of the pragma, where
284 -- the first argument is ON or OFF, and the second parameter is a string
285 -- which is the entire message to suppress, or a prefix of it.
287 type Specific_Warning_Entry is record
288 Start : Source_Ptr;
289 Stop : Source_Ptr;
290 -- Starting and ending source pointers for the range. These are always
291 -- from the same source file.
293 Msg : String_Ptr;
294 -- Message from pragma Warnings (Off, string)
296 Open : Boolean;
297 -- Set to True if OFF has been encountered with no matching ON
299 Used : Boolean;
300 -- Set to True if entry has been used to suppress a warning
302 Config : Boolean;
303 -- True if pragma is configuration pragma (in which case no matching Off
304 -- pragma is required, and it is not required that a specific warning be
305 -- suppressed).
306 end record;
308 package Specific_Warnings is new Table.Table (
309 Table_Component_Type => Specific_Warning_Entry,
310 Table_Index_Type => Natural,
311 Table_Low_Bound => 1,
312 Table_Initial => 100,
313 Table_Increment => 200,
314 Table_Name => "Specific_Warnings");
316 -- Note on handling configuration case versus specific case. A complication
317 -- arises from this example:
319 -- pragma Warnings (Off, "not referenced*");
320 -- procedure Mumble (X : Integer) is
321 -- pragma Warnings (On, "not referenced*");
322 -- begin
323 -- null;
324 -- end Mumble;
326 -- The trouble is that the first pragma is technically a configuration
327 -- pragma, and yet it is clearly being used in the context of thinking of
328 -- it as a specific case. To deal with this, what we do is that the On
329 -- entry can match a configuration pragma from the same file, and if we
330 -- find such an On entry, we cancel the indication of it being the
331 -- configuration case. This seems to handle all cases we run into ok.
333 -----------------
334 -- Subprograms --
335 -----------------
337 procedure Add_Class;
338 -- Add 'Class to buffer for class wide type case (Class_Flag set)
340 function Buffer_Ends_With (S : String) return Boolean;
341 -- Tests if message buffer ends with given string preceded by a space
343 procedure Buffer_Remove (S : String);
344 -- Removes given string from end of buffer if it is present
345 -- at end of buffer, and preceded by a space.
347 function Compilation_Errors return Boolean;
348 -- Returns true if errors have been detected, or warnings in -gnatwe
349 -- (treat warnings as errors) mode.
351 procedure dmsg (Id : Error_Msg_Id);
352 -- Debugging routine to dump an error message
354 procedure Debug_Output (N : Node_Id);
355 -- Called from Error_Msg_N and Error_Msg_NE to generate line of debug
356 -- output giving node number (of node N) if the debug X switch is set.
358 procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id);
359 -- This function is passed the Id values of two error messages. If either
360 -- M1 or M2 is a continuation message, or is already deleted, the call is
361 -- ignored. Otherwise a check is made to see if M1 and M2 are duplicated or
362 -- redundant. If so, the message to be deleted and all its continuations
363 -- are marked with the Deleted flag set to True.
365 procedure Output_Error_Msgs (E : in out Error_Msg_Id);
366 -- Output source line, error flag, and text of stored error message and all
367 -- subsequent messages for the same line and unit. On return E is set to be
368 -- one higher than the last message output.
370 procedure Output_Line_Number (L : Logical_Line_Number);
371 -- Output a line number as six digits (with leading zeroes suppressed),
372 -- followed by a period and a blank (note that this is 8 characters which
373 -- means that tabs in the source line will not get messed up). Line numbers
374 -- that match or are less than the last Source_Reference pragma are listed
375 -- as all blanks, avoiding output of junk line numbers.
377 procedure Output_Msg_Text (E : Error_Msg_Id);
378 -- Outputs characters of text in the text of the error message E. Note that
379 -- no end of line is output, the caller is responsible for adding the end
380 -- of line. If Error_Msg_Line_Length is non-zero, this is the routine that
381 -- splits the line generating multiple lines of output, and in this case
382 -- the last line has no terminating end of line character.
384 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr);
385 -- All error messages whose location is in the range From .. To (not
386 -- including the end points) will be deleted from the error listing.
388 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean;
389 -- See if two messages have the same text. Returns true if the text of the
390 -- two messages is identical, or if one of them is the same as the other
391 -- with an appended "instance at xxx" tag.
393 procedure Set_Msg_Blank;
394 -- Sets a single blank in the message if the preceding character is a
395 -- non-blank character other than a left parenthesis or minus. Has no
396 -- effect if manual quote mode is turned on.
398 procedure Set_Msg_Blank_Conditional;
399 -- Sets a single blank in the message if the preceding character is a
400 -- non-blank character other than a left parenthesis or quote. Has no
401 -- effect if manual quote mode is turned on.
403 procedure Set_Msg_Char (C : Character);
404 -- Add a single character to the current message. This routine does not
405 -- check for special insertion characters (they are just treated as text
406 -- characters if they occur).
408 procedure Set_Msg_Insertion_File_Name;
409 -- Handle file name insertion (left brace insertion character)
411 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr);
412 -- Handle line number insertion (# insertion character). Loc is the
413 -- location to be referenced, and Flag is the location at which the
414 -- flag is posted (used to determine whether to add "in file xxx")
416 procedure Set_Msg_Insertion_Name_Literal;
418 procedure Set_Msg_Insertion_Name;
419 -- Handle name insertion (% insertion character)
421 procedure Set_Msg_Insertion_Reserved_Name;
422 -- Handle insertion of reserved word name (* insertion character)
424 procedure Set_Msg_Insertion_Reserved_Word
425 (Text : String;
426 J : in out Integer);
427 -- Handle reserved word insertion (upper case letters). The Text argument
428 -- is the current error message input text, and J is an index which on
429 -- entry points to the first character of the reserved word, and on exit
430 -- points past the last character of the reserved word. Note that RM and
431 -- SPARK are treated specially and not considered to be keywords.
433 procedure Set_Msg_Insertion_Run_Time_Name;
434 -- If package System contains a definition for Run_Time_Name (see package
435 -- Targparm for details), then this procedure will insert a message of
436 -- the form (name) into the current error message, with name set in mixed
437 -- case (upper case after any spaces). If no run time name is defined,
438 -- then this routine has no effect).
440 procedure Set_Msg_Insertion_Uint;
441 -- Handle Uint insertion (^ insertion character)
443 procedure Set_Msg_Int (Line : Int);
444 -- Set the decimal representation of the argument in the error message
445 -- buffer with no leading zeroes output.
447 procedure Set_Msg_Name_Buffer;
448 -- Output name from Name_Buffer, with surrounding quotes unless manual
449 -- quotation mode is in effect.
451 procedure Set_Msg_Quote;
452 -- Set quote if in normal quote mode, nothing if in manual quote mode
454 procedure Set_Msg_Str (Text : String);
455 -- Add a sequence of characters to the current message. This routine does
456 -- not check for special insertion characters (they are just treated as
457 -- text characters if they occur).
459 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id);
460 -- Given a message id, move to next message id, but skip any deleted
461 -- messages, so that this results in E on output being the first non-
462 -- deleted message following the input value of E, or No_Error_Msg if
463 -- the input value of E was either already No_Error_Msg, or was the
464 -- last non-deleted message.
466 procedure Set_Specific_Warning_Off
467 (Loc : Source_Ptr;
468 Msg : String;
469 Config : Boolean;
470 Used : Boolean := False);
471 -- This is called in response to the two argument form of pragma Warnings
472 -- where the first argument is OFF, and the second argument is a string
473 -- which identifies a specific warning to be suppressed. The first argument
474 -- is the start of the suppression range, and the second argument is the
475 -- string from the pragma. Loc is the location of the pragma (which is the
476 -- start of the range to suppress). Config is True for the configuration
477 -- pragma case (where there is no requirement for a matching OFF pragma).
478 -- Used is set True to disable the check that the warning actually has
479 -- has the effect of suppressing a warning.
481 procedure Set_Specific_Warning_On
482 (Loc : Source_Ptr;
483 Msg : String;
484 Err : out Boolean);
485 -- This is called in response to the two argument form of pragma Warnings
486 -- where the first argument is ON, and the second argument is a string
487 -- which identifies a specific warning to be suppressed. The first argument
488 -- is the end of the suppression range, and the second argument is the
489 -- string from the pragma. Err is set to True on return to report the error
490 -- of no matching Warnings Off pragma preceding this one.
492 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr);
493 -- Called in response to a pragma Warnings (Off) to record the source
494 -- location from which warnings are to be turned off.
496 procedure Set_Warnings_Mode_On (Loc : Source_Ptr);
497 -- Called in response to a pragma Warnings (On) to record the source
498 -- location from which warnings are to be turned back on.
500 procedure Test_Style_Warning_Serious_Unconditional_Msg (Msg : String);
501 -- Scans message text and sets the following variables:
503 -- Is_Warning_Msg is set True if Msg is a warning message (contains a
504 -- question mark character), and False otherwise.
506 -- Is_Style_Msg is set True if Msg is a style message (starts with
507 -- "(style)") and False otherwise.
509 -- Is_Serious_Error is set to True unless the message is a warning or
510 -- style message or contains the character | (non-serious error).
512 -- Is_Unconditional_Msg is set True if the message contains the character
513 -- ! and is otherwise set False.
515 -- Has_Double_Exclam is set True if the message contains the sequence !!
516 -- and is otherwise set False.
518 -- Note that the call has no effect for continuation messages (those whose
519 -- first character is '\'), and all variables are left unchanged.
521 function Warnings_Suppressed (Loc : Source_Ptr) return Boolean;
522 -- Determines if given location is covered by a warnings off suppression
523 -- range in the warnings table (or is suppressed by compilation option,
524 -- which generates a warning range for the whole source file). This routine
525 -- only deals with the general ON/OFF case, not specific warnings. True
526 -- is also returned if warnings are globally suppressed.
528 function Warning_Specifically_Suppressed
529 (Loc : Source_Ptr;
530 Msg : String_Ptr) return Boolean;
531 -- Determines if given message to be posted at given location is suppressed
532 -- by specific ON/OFF Warnings pragmas specifying this particular message.
534 type Error_Msg_Proc is
535 access procedure (Msg : String; Flag_Location : Source_Ptr);
536 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc);
537 -- Checks that specific warnings are consistent (for non-configuration
538 -- case, properly closed, and used). The argument is a pointer to the
539 -- Error_Msg procedure to be called if any inconsistencies are detected.
541 end Erroutc;