gcc/
[official-gcc.git] / gcc / ada / erroutc.ads
blobf23f4df588f9c78d773ae71defe302bcd5befbd6
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-2014, 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 ?
64 -- or contains < and Error_Msg_Warn is True.
66 Is_Info_Msg : Boolean := False;
67 -- Set True to indicate that the current message starts with the characters
68 -- "info: " and is to be treated as an information message. This string
69 -- will be prepended to the message and all its continuations.
71 Warning_Msg_Char : Character;
72 -- Warning character, valid only if Is_Warning_Msg is True
73 -- ' ' -- ? or < appeared on its own in message
74 -- '?' -- ?? or << appeared in message
75 -- 'x' -- ?x? or <x< appeared in message (x = a .. z)
76 -- 'X' -- ?X? or <X< appeared in message (X = A .. Z)
77 -- '*' -- ?*? or <*< appeared in message
78 -- '$' -- ?$? or <$< appeared in message
79 -- In the case of the < sequences, this is set only if the message is
80 -- actually a warning, i.e. if Error_Msg_Warn is True
82 Is_Style_Msg : Boolean := False;
83 -- Set True to indicate if the current message is a style message
84 -- (i.e. a message whose text starts with the characters "(style)").
86 Kill_Message : Boolean := False;
87 -- A flag used to kill weird messages (e.g. those containing uninterpreted
88 -- implicit type references) if we have already seen at least one message
89 -- already. The idea is that we hope the weird message is a junk cascaded
90 -- message that should be suppressed.
92 Last_Killed : Boolean := False;
93 -- Set True if the most recently posted non-continuation message was
94 -- killed. This is used to determine the processing of any continuation
95 -- messages that follow.
97 List_Pragmas_Index : Int := 0;
98 -- Index into List_Pragmas table
100 List_Pragmas_Mode : Boolean := False;
101 -- Starts True, gets set False by pragma List (Off), True by List (On)
103 Manual_Quote_Mode : Boolean := False;
104 -- Set True in manual quotation mode
106 Max_Msg_Length : constant := 1024 + 2 * Int (Column_Number'Last);
107 -- Maximum length of error message. The addition of 2 * Column_Number'Last
108 -- ensures that two insertion tokens of maximum length can be accommodated.
109 -- The value of 1024 is an arbitrary value that should be more than long
110 -- enough to accommodate any reasonable message (and for that matter, some
111 -- pretty unreasonable messages).
113 Msg_Buffer : String (1 .. Max_Msg_Length);
114 -- Buffer used to prepare error messages
116 Msglen : Integer := 0;
117 -- Number of characters currently stored in the message buffer
119 Suppress_Message : Boolean;
120 -- A flag used to suppress certain obviously redundant messages (i.e.
121 -- those referring to a node whose type is Any_Type). This suppression
122 -- is effective only if All_Errors_Mode is off.
124 Suppress_Instance_Location : Boolean := False;
125 -- Normally, if a # location in a message references a location within
126 -- a generic template, then a note is added giving the location of the
127 -- instantiation. If this variable is set True, then this note is not
128 -- output. This is used for internal processing for the case of an
129 -- illegal instantiation. See Error_Msg routine for further details.
131 ----------------------------
132 -- Message ID Definitions --
133 ----------------------------
135 type Error_Msg_Id is new Int;
136 -- A type used to represent specific error messages. Used by the clients
137 -- of this package only in the context of the Get_Error_Id and
138 -- Change_Error_Text subprograms.
140 No_Error_Msg : constant Error_Msg_Id := 0;
141 -- A constant which is different from any value returned by Get_Error_Id.
142 -- Typically used by a client to indicate absence of a saved Id value.
144 Cur_Msg : Error_Msg_Id := No_Error_Msg;
145 -- Id of most recently posted error message
147 function Get_Msg_Id return Error_Msg_Id;
148 -- Returns the Id of the message most recently posted using one of the
149 -- Error_Msg routines.
151 function Get_Location (E : Error_Msg_Id) return Source_Ptr;
152 -- Returns the flag location of the error message with the given id E
154 -----------------------------------
155 -- Error Message Data Structures --
156 -----------------------------------
158 -- The error messages are stored as a linked list of error message objects
159 -- sorted into ascending order by the source location (Sloc). Each object
160 -- records the text of the message and its source location.
162 -- The following record type and table are used to represent error
163 -- messages, with one entry in the table being allocated for each message.
165 type Error_Msg_Object is record
166 Text : String_Ptr;
167 -- Text of error message, fully expanded with all insertions
169 Next : Error_Msg_Id;
170 -- Pointer to next message in error chain. A value of No_Error_Msg
171 -- indicates the end of the chain.
173 Prev : Error_Msg_Id;
174 -- Pointer to previous message in error chain. Only set during the
175 -- Finalize procedure. A value of No_Error_Msg indicates the first
176 -- message in the chain.
178 Sfile : Source_File_Index;
179 -- Source table index of source file. In the case of an error that
180 -- refers to a template, always references the original template
181 -- not an instantiation copy.
183 Sptr : Source_Ptr;
184 -- Flag pointer. In the case of an error that refers to a template,
185 -- always references the original template, not an instantiation copy.
186 -- This value is the actual place in the source that the error message
187 -- will be posted. Note that an error placed on an instantiation will
188 -- have Sptr pointing to the instantiation point.
190 Optr : Source_Ptr;
191 -- Flag location used in the call to post the error. This is normally
192 -- the same as Sptr, except when an error is posted on a particular
193 -- instantiation of a generic. In such a case, Sptr will point to
194 -- the original source location of the instantiation itself, but
195 -- Optr will point to the template location (more accurately to the
196 -- template copy in the instantiation copy corresponding to the
197 -- instantiation referenced by Sptr).
199 Line : Physical_Line_Number;
200 -- Line number for error message
202 Col : Column_Number;
203 -- Column number for error message
205 Warn : Boolean;
206 -- True if warning message
208 Info : Boolean;
209 -- True if info message
211 Warn_Err : Boolean;
212 -- True if this is a warning message which is to be treated as an error
213 -- as a result of a match with a Warning_As_Error pragma.
215 Warn_Chr : Character;
216 -- Warning character (note: set even if Warning_Doc_Switch is False)
217 -- ' ' -- ? or < appeared on its own in message
218 -- '?' -- ?? or << appeared in message
219 -- 'x' -- ?x? or <x< appeared in message (x = a .. z)
220 -- 'X' -- ?X? or <X< appeared in message (X = A .. Z)
221 -- '*' -- ?*? or <*< appeared in message
222 -- '$' -- ?$? or <$< appeared in message
223 -- In the case of the < sequences, this is set only if the message is
224 -- actually a warning, i.e. if Error_Msg_Warn is True
226 Style : Boolean;
227 -- True if style message (starts with "(style)")
229 Serious : Boolean;
230 -- True if serious error message (not a warning and no | character)
232 Uncond : Boolean;
233 -- True if unconditional message (i.e. insertion character ! appeared)
235 Msg_Cont : Boolean;
236 -- This is used for logical messages that are composed of multiple
237 -- individual messages. For messages that are not part of such a
238 -- group, or that are the first message in such a group. Msg_Cont
239 -- is set to False. For subsequent messages in a group, Msg_Cont
240 -- is set to True. This is used to make sure that such a group of
241 -- messages is either suppressed or retained as a group (e.g. in
242 -- the circuit that deletes identical messages).
244 Deleted : Boolean;
245 -- If this flag is set, the message is not printed. This is used
246 -- in the circuit for deleting duplicate/redundant error messages.
247 end record;
249 package Errors is new Table.Table (
250 Table_Component_Type => Error_Msg_Object,
251 Table_Index_Type => Error_Msg_Id,
252 Table_Low_Bound => 1,
253 Table_Initial => 200,
254 Table_Increment => 200,
255 Table_Name => "Error");
257 First_Error_Msg : Error_Msg_Id;
258 -- The list of error messages, i.e. the first entry on the list of error
259 -- messages. This is not the same as the physically first entry in the
260 -- error message table, since messages are not always inserted in sequence.
262 Last_Error_Msg : Error_Msg_Id;
263 -- The last entry on the list of error messages. Note: this is not the same
264 -- as the physically last entry in the error message table, since messages
265 -- are not always inserted in sequence.
267 --------------------------
268 -- Warning Mode Control --
269 --------------------------
271 -- Pragma Warnings allows warnings to be turned off for a specified region
272 -- of code, and the following tables are the data structures used to keep
273 -- track of these regions.
275 -- The first table is used for the basic command line control, and for the
276 -- forms of Warning with a single ON or OFF parameter.
278 -- It contains pairs of source locations, the first being the start
279 -- location for a warnings off region, and the second being the end
280 -- location. When a pragma Warnings (Off) is encountered, a new entry is
281 -- established extending from the location of the pragma to the end of the
282 -- current source file. A subsequent pragma Warnings (On) adjusts the end
283 -- point of this entry appropriately.
285 -- If all warnings are suppressed by command switch, then there is a dummy
286 -- entry (put there by Errout.Initialize) at the start of the table which
287 -- covers all possible Source_Ptr values. Note that the source pointer
288 -- values in this table always reference the original template, not an
289 -- instantiation copy, in the generic case.
291 -- Reason is the reason from the pragma Warnings (Off,..) or the null
292 -- string if no reason parameter is given.
294 type Warnings_Entry is record
295 Start : Source_Ptr;
296 Stop : Source_Ptr;
297 Reason : String_Id;
298 end record;
300 package Warnings is new Table.Table (
301 Table_Component_Type => Warnings_Entry,
302 Table_Index_Type => Natural,
303 Table_Low_Bound => 1,
304 Table_Initial => 100,
305 Table_Increment => 200,
306 Table_Name => "Warnings");
308 -- The second table is used for the specific forms of the pragma, where
309 -- the first argument is ON or OFF, and the second parameter is a string
310 -- which is the pattern to match for suppressing a warning.
312 type Specific_Warning_Entry is record
313 Start : Source_Ptr;
314 Stop : Source_Ptr;
315 -- Starting and ending source pointers for the range. These are always
316 -- from the same source file.
318 Reason : String_Id;
319 -- Reason string from pragma Warnings, or null string if none
321 Msg : String_Ptr;
322 -- Message from pragma Warnings (Off, string)
324 Open : Boolean;
325 -- Set to True if OFF has been encountered with no matching ON
327 Used : Boolean;
328 -- Set to True if entry has been used to suppress a warning
330 Config : Boolean;
331 -- True if pragma is configuration pragma (in which case no matching Off
332 -- pragma is required, and it is not required that a specific warning be
333 -- suppressed).
334 end record;
336 package Specific_Warnings is new Table.Table (
337 Table_Component_Type => Specific_Warning_Entry,
338 Table_Index_Type => Natural,
339 Table_Low_Bound => 1,
340 Table_Initial => 100,
341 Table_Increment => 200,
342 Table_Name => "Specific_Warnings");
344 -- Note on handling configuration case versus specific case. A complication
345 -- arises from this example:
347 -- pragma Warnings (Off, "not referenced*");
348 -- procedure Mumble (X : Integer) is
349 -- pragma Warnings (On, "not referenced*");
350 -- begin
351 -- null;
352 -- end Mumble;
354 -- The trouble is that the first pragma is technically a configuration
355 -- pragma, and yet it is clearly being used in the context of thinking of
356 -- it as a specific case. To deal with this, what we do is that the On
357 -- entry can match a configuration pragma from the same file, and if we
358 -- find such an On entry, we cancel the indication of it being the
359 -- configuration case. This seems to handle all cases we run into ok.
361 -----------------
362 -- Subprograms --
363 -----------------
365 procedure Add_Class;
366 -- Add 'Class to buffer for class wide type case (Class_Flag set)
368 function Buffer_Ends_With (C : Character) return Boolean;
369 -- Tests if message buffer ends with given character
371 function Buffer_Ends_With (S : String) return Boolean;
372 -- Tests if message buffer ends with given string preceded by a space
374 procedure Buffer_Remove (C : Character);
375 -- Remove given character fron end of buffer if it is present
377 procedure Buffer_Remove (S : String);
378 -- Removes given string from end of buffer if it is present at end of
379 -- buffer, and preceded by a space.
381 function Compilation_Errors return Boolean;
382 -- Returns true if errors have been detected, or warnings in -gnatwe
383 -- (treat warnings as errors) mode.
385 procedure dmsg (Id : Error_Msg_Id);
386 -- Debugging routine to dump an error message
388 procedure Debug_Output (N : Node_Id);
389 -- Called from Error_Msg_N and Error_Msg_NE to generate line of debug
390 -- output giving node number (of node N) if the debug X switch is set.
392 procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id);
393 -- This function is passed the Id values of two error messages. If either
394 -- M1 or M2 is a continuation message, or is already deleted, the call is
395 -- ignored. Otherwise a check is made to see if M1 and M2 are duplicated or
396 -- redundant. If so, the message to be deleted and all its continuations
397 -- are marked with the Deleted flag set to True.
399 function Get_Warning_Tag (Id : Error_Msg_Id) return String;
400 -- Given an error message ID, return tag showing warning message class, or
401 -- the null string if this option is not enabled or this is not a warning.
403 procedure Output_Error_Msgs (E : in out Error_Msg_Id);
404 -- Output source line, error flag, and text of stored error message and all
405 -- subsequent messages for the same line and unit. On return E is set to be
406 -- one higher than the last message output.
408 procedure Output_Line_Number (L : Logical_Line_Number);
409 -- Output a line number as six digits (with leading zeroes suppressed),
410 -- followed by a period and a blank (note that this is 8 characters which
411 -- means that tabs in the source line will not get messed up). Line numbers
412 -- that match or are less than the last Source_Reference pragma are listed
413 -- as all blanks, avoiding output of junk line numbers.
415 procedure Output_Msg_Text (E : Error_Msg_Id);
416 -- Outputs characters of text in the text of the error message E. Note that
417 -- no end of line is output, the caller is responsible for adding the end
418 -- of line. If Error_Msg_Line_Length is non-zero, this is the routine that
419 -- splits the line generating multiple lines of output, and in this case
420 -- the last line has no terminating end of line character.
422 procedure Prescan_Message (Msg : String);
423 -- Scans message text and sets the following variables:
425 -- Is_Warning_Msg is set True if Msg is a warning message (contains a
426 -- question mark character), and False otherwise.
428 -- Is_Style_Msg is set True if Msg is a style message (starts with
429 -- "(style)") and False otherwise.
431 -- Is_Info_Msg is set True if Msg is an information message (starts
432 -- with "info: ". Such messages must contain a ? sequence since they
433 -- are also considered to be warning messages, and get a tag.
435 -- Is_Serious_Error is set to True unless the message is a warning or
436 -- style message or contains the character | (non-serious error).
438 -- Is_Unconditional_Msg is set True if the message contains the character
439 -- ! and is otherwise set False.
441 -- Has_Double_Exclam is set True if the message contains the sequence !!
442 -- and is otherwise set False.
444 -- We need to know right away these aspects of a message, since we will
445 -- test these values before doing the full error scan.
447 -- Note that the call has no effect for continuation messages (those whose
448 -- first character is '\'), and all variables are left unchanged.
450 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr);
451 -- All error messages whose location is in the range From .. To (not
452 -- including the end points) will be deleted from the error listing.
454 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean;
455 -- See if two messages have the same text. Returns true if the text of the
456 -- two messages is identical, or if one of them is the same as the other
457 -- with an appended "instance at xxx" tag.
459 procedure Set_Msg_Blank;
460 -- Sets a single blank in the message if the preceding character is a
461 -- non-blank character other than a left parenthesis or minus. Has no
462 -- effect if manual quote mode is turned on.
464 procedure Set_Msg_Blank_Conditional;
465 -- Sets a single blank in the message if the preceding character is a
466 -- non-blank character other than a left parenthesis or quote. Has no
467 -- effect if manual quote mode is turned on.
469 procedure Set_Msg_Char (C : Character);
470 -- Add a single character to the current message. This routine does not
471 -- check for special insertion characters (they are just treated as text
472 -- characters if they occur).
474 procedure Set_Msg_Insertion_File_Name;
475 -- Handle file name insertion (left brace insertion character)
477 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr);
478 -- Handle line number insertion (# insertion character). Loc is the
479 -- location to be referenced, and Flag is the location at which the
480 -- flag is posted (used to determine whether to add "in file xxx")
482 procedure Set_Msg_Insertion_Name_Literal;
484 procedure Set_Msg_Insertion_Name;
485 -- Handle name insertion (% insertion character)
487 procedure Set_Msg_Insertion_Reserved_Name;
488 -- Handle insertion of reserved word name (* insertion character)
490 procedure Set_Msg_Insertion_Reserved_Word
491 (Text : String;
492 J : in out Integer);
493 -- Handle reserved word insertion (upper case letters). The Text argument
494 -- is the current error message input text, and J is an index which on
495 -- entry points to the first character of the reserved word, and on exit
496 -- points past the last character of the reserved word. Note that RM and
497 -- SPARK are treated specially and not considered to be keywords.
499 procedure Set_Msg_Insertion_Run_Time_Name;
500 -- If package System contains a definition for Run_Time_Name (see package
501 -- Targparm for details), then this procedure will insert a message of
502 -- the form (name) into the current error message, with name set in mixed
503 -- case (upper case after any spaces). If no run time name is defined,
504 -- then this routine has no effect).
506 procedure Set_Msg_Insertion_Uint;
507 -- Handle Uint insertion (^ insertion character)
509 procedure Set_Msg_Int (Line : Int);
510 -- Set the decimal representation of the argument in the error message
511 -- buffer with no leading zeroes output.
513 procedure Set_Msg_Name_Buffer;
514 -- Output name from Name_Buffer, with surrounding quotes unless manual
515 -- quotation mode is in effect.
517 procedure Set_Msg_Quote;
518 -- Set quote if in normal quote mode, nothing if in manual quote mode
520 procedure Set_Msg_Str (Text : String);
521 -- Add a sequence of characters to the current message. This routine does
522 -- not check for special insertion characters (they are just treated as
523 -- text characters if they occur).
525 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id);
526 -- Given a message id, move to next message id, but skip any deleted
527 -- messages, so that this results in E on output being the first non-
528 -- deleted message following the input value of E, or No_Error_Msg if
529 -- the input value of E was either already No_Error_Msg, or was the
530 -- last non-deleted message.
532 procedure Set_Specific_Warning_Off
533 (Loc : Source_Ptr;
534 Msg : String;
535 Reason : String_Id;
536 Config : Boolean;
537 Used : Boolean := False);
538 -- This is called in response to the two argument form of pragma Warnings
539 -- where the first argument is OFF, and the second argument is a string
540 -- which identifies a specific warning to be suppressed. The first argument
541 -- is the start of the suppression range, and the second argument is the
542 -- string from the pragma. Loc is the location of the pragma (which is the
543 -- start of the range to suppress). Reason is the reason string from the
544 -- pragma, or the null string if no reason is given. Config is True for the
545 -- configuration pragma case (where there is no requirement for a matching
546 -- OFF pragma). Used is set True to disable the check that the warning
547 -- actually has has the effect of suppressing a warning.
549 procedure Set_Specific_Warning_On
550 (Loc : Source_Ptr;
551 Msg : String;
552 Err : out Boolean);
553 -- This is called in response to the two argument form of pragma Warnings
554 -- where the first argument is ON, and the second argument is a string
555 -- which identifies a specific warning to be suppressed. The first argument
556 -- is the end of the suppression range, and the second argument is the
557 -- string from the pragma. Err is set to True on return to report the error
558 -- of no matching Warnings Off pragma preceding this one.
560 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id);
561 -- Called in response to a pragma Warnings (Off) to record the source
562 -- location from which warnings are to be turned off. Reason is the
563 -- Reason from the pragma, or the null string if none is given.
565 procedure Set_Warnings_Mode_On (Loc : Source_Ptr);
566 -- Called in response to a pragma Warnings (On) to record the source
567 -- location from which warnings are to be turned back on.
569 function Warnings_Suppressed (Loc : Source_Ptr) return String_Id;
570 -- Determines if given location is covered by a warnings off suppression
571 -- range in the warnings table (or is suppressed by compilation option,
572 -- which generates a warning range for the whole source file). This routine
573 -- only deals with the general ON/OFF case, not specific warnings. The
574 -- returned result is No_String if warnings are not suppressed. If warnings
575 -- are suppressed for the given location, then then corresponding Reason
576 -- parameter from the pragma is returned (or the null string if no Reason
577 -- parameter was present).
579 function Warning_Specifically_Suppressed
580 (Loc : Source_Ptr;
581 Msg : String_Ptr;
582 Tag : String := "") return String_Id;
583 -- Determines if given message to be posted at given location is suppressed
584 -- by specific ON/OFF Warnings pragmas specifying this particular message.
585 -- If the warning is not suppressed then No_String is returned, otherwise
586 -- the corresponding warning string is returned (or the null string if no
587 -- Warning argument was present in the pragma). Tag is the error message
588 -- tag for the message in question or the null string if there is no tag.
590 -- Note: we have a null default for Tag to deal with calls from an old
591 -- branch of gnat2why, which does not know about tags in the calls but
592 -- which uses the latest version of erroutc.
594 function Warning_Treated_As_Error (Msg : String) return Boolean;
595 -- Returns True if the warning message Msg matches any of the strings
596 -- given by Warning_As_Error pragmas, as stored in the Warnings_As_Errors
597 -- table by Set_Warning_As_Error.
599 type Error_Msg_Proc is
600 access procedure (Msg : String; Flag_Location : Source_Ptr);
601 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc);
602 -- Checks that specific warnings are consistent (for non-configuration
603 -- case, properly closed, and used). The argument is a pointer to the
604 -- Error_Msg procedure to be called if any inconsistencies are detected.
606 end Erroutc;