OSDN Git Service

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