OSDN Git Service

2008-03-26 Javier Miranda <miranda@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / errout.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                         GNAT COMPILER COMPONENTS                         --
4 --                                                                          --
5 --                               E R R O U T                                --
6 --                                                                          --
7 --                                 B o d y                                  --
8 --                                                                          --
9 --          Copyright (C) 1992-2008, 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 ------------------------------------------------------------------------------
25
26 --  Warning! Error messages can be generated during Gigi processing by direct
27 --  calls to error message routines, so it is essential that the processing
28 --  in this body be consistent with the requirements for the Gigi processing
29 --  environment, and that in particular, no disallowed table expansion is
30 --  allowed to occur.
31
32 with Atree;    use Atree;
33 with Casing;   use Casing;
34 with Csets;    use Csets;
35 with Debug;    use Debug;
36 with Einfo;    use Einfo;
37 with Erroutc;  use Erroutc;
38 with Fname;    use Fname;
39 with Gnatvsn;  use Gnatvsn;
40 with Hostparm; use Hostparm;
41 with Lib;      use Lib;
42 with Opt;      use Opt;
43 with Nlists;   use Nlists;
44 with Output;   use Output;
45 with Scans;    use Scans;
46 with Sinput;   use Sinput;
47 with Sinfo;    use Sinfo;
48 with Snames;   use Snames;
49 with Stand;    use Stand;
50 with Style;
51 with Uname;    use Uname;
52
53 with Unchecked_Conversion;
54
55 package body Errout is
56
57    Errors_Must_Be_Ignored : Boolean := False;
58    --  Set to True by procedure Set_Ignore_Errors (True), when calls to
59    --  error message procedures should be ignored (when parsing irrelevant
60    --  text in sources being preprocessed).
61
62    Finalize_Called : Boolean := False;
63    --  Set True if the Finalize routine has been called
64
65    Warn_On_Instance : Boolean;
66    --  Flag set true for warning message to be posted on instance
67
68    ------------------------------------
69    -- Table of Non-Instance Messages --
70    ------------------------------------
71
72    --  This table contains an entry for every error message processed by the
73    --  Error_Msg routine that is not posted on generic (or inlined) instance.
74    --  As explained in further detail in the Error_Msg procedure body, this
75    --  table is used to avoid posting redundant messages on instances.
76
77    type NIM_Record is record
78       Msg : String_Ptr;
79       Loc : Source_Ptr;
80    end record;
81    --  Type used to store text and location of one message
82
83    package Non_Instance_Msgs is new Table.Table (
84      Table_Component_Type => NIM_Record,
85      Table_Index_Type     => Int,
86      Table_Low_Bound      => 1,
87      Table_Initial        => 100,
88      Table_Increment      => 100,
89      Table_Name           => "Non_Instance_Msgs");
90
91    -----------------------
92    -- Local Subprograms --
93    -----------------------
94
95    procedure Error_Msg_Internal
96      (Msg      : String;
97       Sptr     : Source_Ptr;
98       Optr     : Source_Ptr;
99       Msg_Cont : Boolean);
100    --  This is the low level routine used to post messages after dealing with
101    --  the issue of messages placed on instantiations (which get broken up
102    --  into separate calls in Error_Msg). Sptr is the location on which the
103    --  flag will be placed in the output. In the case where the flag is on
104    --  the template, this points directly to the template, not to one of the
105    --  instantiation copies of the template. Optr is the original location
106    --  used to flag the error, and this may indeed point to an instantiation
107    --  copy. So typically we can see Optr pointing to the template location
108    --  in an instantiation copy when Sptr points to the source location of
109    --  the actual instantiation (i.e the line with the new). Msg_Cont is
110    --  set true if this is a continuation message.
111
112    function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
113    --  Determines if warnings should be suppressed for the given node
114
115    function OK_Node (N : Node_Id) return Boolean;
116    --  Determines if a node is an OK node to place an error message on (return
117    --  True) or if the error message should be suppressed (return False). A
118    --  message is suppressed if the node already has an error posted on it,
119    --  or if it refers to an Etype that has an error posted on it, or if
120    --  it references an Entity that has an error posted on it.
121
122    procedure Output_Source_Line
123      (L     : Physical_Line_Number;
124       Sfile : Source_File_Index;
125       Errs  : Boolean);
126    --  Outputs text of source line L, in file S, together with preceding line
127    --  number, as described above for Output_Line_Number. The Errs parameter
128    --  indicates if there are errors attached to the line, which forces
129    --  listing on, even in the presence of pragma List (Off).
130
131    procedure Set_Msg_Insertion_Column;
132    --  Handle column number insertion (@ insertion character)
133
134    procedure Set_Msg_Insertion_Node;
135    --  Handle node (name from node) insertion (& insertion character)
136
137    procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
138    --  Handle type reference (right brace insertion character). Flag is the
139    --  location of the flag, which is provided for the internal call to
140    --  Set_Msg_Insertion_Line_Number,
141
142    procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True);
143    --  Handle unit name insertion ($ insertion character). Depending on Boolean
144    --  parameter Suffix, (spec) or (body) is appended after the unit name.
145
146    procedure Set_Msg_Node (Node : Node_Id);
147    --  Add the sequence of characters for the name associated with the
148    --  given node to the current message.
149
150    procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
151    --  Add a sequence of characters to the current message. The characters may
152    --  be one of the special insertion characters (see documentation in spec).
153    --  Flag is the location at which the error is to be posted, which is used
154    --  to determine whether or not the # insertion needs a file name. The
155    --  variables Msg_Buffer, Msglen, Is_Style_Msg, Is_Warning_Msg, and
156    --  Is_Unconditional_Msg are set on return.
157
158    procedure Set_Posted (N : Node_Id);
159    --  Sets the Error_Posted flag on the given node, and all its parents
160    --  that are subexpressions and then on the parent non-subexpression
161    --  construct that contains the original expression (this reduces the
162    --  number of cascaded messages). Note that this call only has an effect
163    --  for a serious error. For a non-serious error, it has no effect.
164
165    procedure Set_Qualification (N : Nat; E : Entity_Id);
166    --  Outputs up to N levels of qualification for the given entity. For
167    --  example, the entity A.B.C.D will output B.C. if N = 2.
168
169    function Special_Msg_Delete
170      (Msg : String;
171       N   : Node_Or_Entity_Id;
172       E   : Node_Or_Entity_Id) return Boolean;
173    --  This function is called from Error_Msg_NEL, passing the message Msg,
174    --  node N on which the error is to be posted, and the entity or node E
175    --  to be used for an & insertion in the message if any. The job of this
176    --  procedure is to test for certain cascaded messages that we would like
177    --  to suppress. If the message is to be suppressed then we return True.
178    --  If the message should be generated (the normal case) False is returned.
179
180    procedure Unwind_Internal_Type (Ent : in out Entity_Id);
181    --  This procedure is given an entity id for an internal type, i.e.
182    --  a type with an internal name. It unwinds the type to try to get
183    --  to something reasonably printable, generating prefixes like
184    --  "subtype of", "access to", etc along the way in the buffer. The
185    --  value in Ent on return is the final name to be printed. Hopefully
186    --  this is not an internal name, but in some internal name cases, it
187    --  is an internal name, and has to be printed anyway (although in this
188    --  case the message has been killed if possible). The global variable
189    --  Class_Flag is set to True if the resulting entity should have
190    --  'Class appended to its name (see Add_Class procedure), and is
191    --  otherwise unchanged.
192
193    procedure VMS_Convert;
194    --  This procedure has no effect if called when the host is not OpenVMS.
195    --  If the host is indeed OpenVMS, then the error message stored in
196    --  Msg_Buffer is scanned for appearences of switch names which need
197    --  converting to corresponding VMS qualifer names. See Gnames/Vnames
198    --  table in Errout spec for precise definition of the conversion that
199    --  is performed by this routine in OpenVMS mode.
200
201    -----------------------
202    -- Change_Error_Text --
203    -----------------------
204
205    procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
206       Save_Next : Error_Msg_Id;
207       Err_Id    : Error_Msg_Id := Error_Id;
208
209    begin
210       Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr);
211       Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
212
213       --  If in immediate error message mode, output modified error message now
214       --  This is just a bit tricky, because we want to output just a single
215       --  message, and the messages we modified is already linked in. We solve
216       --  this by temporarily resetting its forward pointer to empty.
217
218       if Debug_Flag_OO then
219          Save_Next := Errors.Table (Error_Id).Next;
220          Errors.Table (Error_Id).Next := No_Error_Msg;
221          Write_Eol;
222          Output_Source_Line
223            (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
224          Output_Error_Msgs (Err_Id);
225          Errors.Table (Error_Id).Next := Save_Next;
226       end if;
227    end Change_Error_Text;
228
229    ------------------------
230    -- Compilation_Errors --
231    ------------------------
232
233    function Compilation_Errors return Boolean is
234    begin
235       if not Finalize_Called then
236          raise Program_Error;
237       else
238          return Erroutc.Compilation_Errors;
239       end if;
240    end Compilation_Errors;
241
242    ---------------
243    -- Error_Msg --
244    ---------------
245
246    --  Error_Msg posts a flag at the given location, except that if the
247    --  Flag_Location points within a generic template and corresponds
248    --  to an instantiation of this generic template, then the actual
249    --  message will be posted on the generic instantiation, along with
250    --  additional messages referencing the generic declaration.
251
252    procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
253       Sindex : Source_File_Index;
254       --  Source index for flag location
255
256       Orig_Loc : Source_Ptr;
257       --  Original location of Flag_Location (i.e. location in original
258       --  template in instantiation case, otherwise unchanged).
259
260    begin
261       --  It is a fatal error to issue an error message when scanning from
262       --  the internal source buffer (see Sinput for further documentation)
263
264       pragma Assert (Sinput.Source /= Internal_Source_Ptr);
265
266       --  Return if all errors are to be ignored
267
268       if Errors_Must_Be_Ignored then
269          return;
270       end if;
271
272       --  If we already have messages, and we are trying to place a message
273       --  at No_Location or in package Standard, then just ignore the attempt
274       --  since we assume that what is happening is some cascaded junk. Note
275       --  that this is safe in the sense that proceeding will surely bomb.
276
277       if Flag_Location < First_Source_Ptr
278         and then Total_Errors_Detected > 0
279       then
280          return;
281       end if;
282
283       --  Start processing of new message
284
285       Sindex := Get_Source_File_Index (Flag_Location);
286       Test_Style_Warning_Serious_Msg (Msg);
287       Orig_Loc := Original_Location (Flag_Location);
288
289       --  If the current location is in an instantiation, the issue arises
290       --  of whether to post the message on the template or the instantiation.
291
292       --  The way we decide is to see if we have posted the same message
293       --  on the template when we compiled the template (the template is
294       --  always compiled before any instantiations). For this purpose,
295       --  we use a separate table of messages. The reason we do this is
296       --  twofold:
297
298       --     First, the messages can get changed by various processing
299       --     including the insertion of tokens etc, making it hard to
300       --     do the comparison.
301
302       --     Second, we will suppress a warning on a template if it is
303       --     not in the current extended source unit. That's reasonable
304       --     and means we don't want the warning on the instantiation
305       --     here either, but it does mean that the main error table
306       --     would not in any case include the message.
307
308       if Flag_Location = Orig_Loc then
309          Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
310          Warn_On_Instance := False;
311
312       --  Here we have an instance message
313
314       else
315          --  Delete if debug flag off, and this message duplicates a
316          --  message already posted on the corresponding template
317
318          if not Debug_Flag_GG then
319             for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
320                if Msg = Non_Instance_Msgs.Table (J).Msg.all
321                  and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
322                then
323                   return;
324                end if;
325             end loop;
326          end if;
327
328          --  No duplicate, so error/warning will be posted on instance
329
330          Warn_On_Instance := Is_Warning_Msg;
331       end if;
332
333       --  Ignore warning message that is suppressed. Note that style
334       --  checks are not considered warning messages for this purpose
335
336       if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) then
337          return;
338       end if;
339
340       --  The idea at this stage is that we have two kinds of messages
341
342       --  First, we have those messages that are to be placed as requested at
343       --  Flag_Location. This includes messages that have nothing to do with
344       --  generics, and also messages placed on generic templates that reflect
345       --  an error in the template itself. For such messages we simply call
346       --  Error_Msg_Internal to place the message in the requested location.
347
348       if Instantiation (Sindex) = No_Location then
349          Error_Msg_Internal (Msg, Flag_Location, Flag_Location, False);
350          return;
351       end if;
352
353       --  If we are trying to flag an error in an instantiation, we may have
354       --  a generic contract violation. What we generate in this case is:
355
356       --     instantiation error at ...
357       --     original error message
358
359       --  or
360
361       --     warning: in instantiation at
362       --     warning: original warning message
363
364       --  All these messages are posted at the location of the top level
365       --  instantiation. If there are nested instantiations, then the
366       --  instantiation error message can be repeated, pointing to each
367       --  of the relevant instantiations.
368
369       --  Note: the instantiation mechanism is also shared for inlining
370       --  of subprogram bodies when front end inlining is done. In this
371       --  case the messages have the form:
372
373       --     in inlined body at ...
374       --     original error message
375
376       --  or
377
378       --     warning: in inlined body at
379       --     warning: original warning message
380
381       --  OK, this is the case where we have an instantiation error, and
382       --  we need to generate the error on the instantiation, rather than
383       --  on the template.
384
385       declare
386          Actual_Error_Loc : Source_Ptr;
387          --  Location of outer level instantiation in instantiation case, or
388          --  just a copy of Flag_Location in the normal case. This is the
389          --  location where all error messages will actually be posted.
390
391          Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
392          --  Save possible location set for caller's message. We need to
393          --  use Error_Msg_Sloc for the location of the instantiation error
394          --  but we have to preserve a possible original value.
395
396          X : Source_File_Index;
397
398          Msg_Cont_Status : Boolean;
399          --  Used to label continuation lines in instantiation case with
400          --  proper Msg_Cont status.
401
402       begin
403          --  Loop to find highest level instantiation, where all error
404          --  messages will be placed.
405
406          X := Sindex;
407          loop
408             Actual_Error_Loc := Instantiation (X);
409             X := Get_Source_File_Index (Actual_Error_Loc);
410             exit when Instantiation (X) = No_Location;
411          end loop;
412
413          --  Since we are generating the messages at the instantiation
414          --  point in any case, we do not want the references to the
415          --  bad lines in the instance to be annotated with the location
416          --  of the instantiation.
417
418          Suppress_Instance_Location := True;
419          Msg_Cont_Status := False;
420
421          --  Loop to generate instantiation messages
422
423          Error_Msg_Sloc := Flag_Location;
424          X := Get_Source_File_Index (Flag_Location);
425
426          while Instantiation (X) /= No_Location loop
427
428             --  Suppress instantiation message on continuation lines
429
430             if Msg (Msg'First) /= '\' then
431
432                --  Case of inlined body
433
434                if Inlined_Body (X) then
435                   if Is_Warning_Msg then
436                      Error_Msg_Internal
437                        ("?in inlined body #",
438                         Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
439
440                   else
441                      Error_Msg_Internal
442                        ("error in inlined body #",
443                         Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
444                   end if;
445
446                --  Case of generic instantiation
447
448                else
449                   if Is_Warning_Msg then
450                      Error_Msg_Internal
451                        ("?in instantiation #",
452                         Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
453
454                   else
455                      Error_Msg_Internal
456                        ("instantiation error #",
457                         Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
458                   end if;
459                end if;
460             end if;
461
462             Error_Msg_Sloc := Instantiation (X);
463             X := Get_Source_File_Index (Error_Msg_Sloc);
464             Msg_Cont_Status := True;
465          end loop;
466
467          Suppress_Instance_Location := False;
468          Error_Msg_Sloc := Save_Error_Msg_Sloc;
469
470          --  Here we output the original message on the outer instantiation
471
472          Error_Msg_Internal
473            (Msg, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
474       end;
475    end Error_Msg;
476
477    ------------------
478    -- Error_Msg_AP --
479    ------------------
480
481    procedure Error_Msg_AP (Msg : String) is
482       S1 : Source_Ptr;
483       C  : Character;
484
485    begin
486       --  If we had saved the Scan_Ptr value after scanning the previous
487       --  token, then we would have exactly the right place for putting
488       --  the flag immediately at hand. However, that would add at least
489       --  two instructions to a Scan call *just* to service the possibility
490       --  of an Error_Msg_AP call. So instead we reconstruct that value.
491
492       --  We have two possibilities, start with Prev_Token_Ptr and skip over
493       --  the current token, which is made harder by the possibility that this
494       --  token may be in error, or start with Token_Ptr and work backwards.
495       --  We used to take the second approach, but it's hard because of
496       --  comments, and harder still because things that look like comments
497       --  can appear inside strings. So now we take the first approach.
498
499       --  Note: in the case where there is no previous token, Prev_Token_Ptr
500       --  is set to Source_First, which is a reasonable position for the
501       --  error flag in this situation.
502
503       S1 := Prev_Token_Ptr;
504       C := Source (S1);
505
506       --  If the previous token is a string literal, we need a special approach
507       --  since there may be white space inside the literal and we don't want
508       --  to stop on that white space.
509
510       --  Note: since this is an error recovery issue anyway, it is not worth
511       --  worrying about special UTF_32 line terminator characters here.
512
513       if Prev_Token = Tok_String_Literal then
514          loop
515             S1 := S1 + 1;
516
517             if Source (S1) = C then
518                S1 := S1 + 1;
519                exit when Source (S1) /= C;
520             elsif Source (S1) in Line_Terminator then
521                exit;
522             end if;
523          end loop;
524
525       --  Character literal also needs special handling
526
527       elsif Prev_Token = Tok_Char_Literal then
528          S1 := S1 + 3;
529
530       --  Otherwise we search forward for the end of the current token, marked
531       --  by a line terminator, white space, a comment symbol or if we bump
532       --  into the following token (i.e. the current token).
533
534       --  Again, it is not worth worrying about UTF_32 special line terminator
535       --  characters in this context, since this is only for error recovery.
536
537       else
538          while Source (S1) not in Line_Terminator
539            and then Source (S1) /= ' '
540            and then Source (S1) /= ASCII.HT
541            and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
542            and then S1 /= Token_Ptr
543          loop
544             S1 := S1 + 1;
545          end loop;
546       end if;
547
548       --  S1 is now set to the location for the flag
549
550       Error_Msg (Msg, S1);
551    end Error_Msg_AP;
552
553    ------------------
554    -- Error_Msg_BC --
555    ------------------
556
557    procedure Error_Msg_BC (Msg : String) is
558    begin
559       --  If we are at end of file, post the flag after the previous token
560
561       if Token = Tok_EOF then
562          Error_Msg_AP (Msg);
563
564       --  If we are at start of file, post the flag at the current token
565
566       elsif Token_Ptr = Source_First (Current_Source_File) then
567          Error_Msg_SC (Msg);
568
569       --  If the character before the current token is a space or a horizontal
570       --  tab, then we place the flag on this character (in the case of a tab
571       --  we would really like to place it in the "last" character of the tab
572       --  space, but that it too much trouble to worry about).
573
574       elsif Source (Token_Ptr - 1) = ' '
575          or else Source (Token_Ptr - 1) = ASCII.HT
576       then
577          Error_Msg (Msg, Token_Ptr - 1);
578
579       --  If there is no space or tab before the current token, then there is
580       --  no room to place the flag before the token, so we place it on the
581       --  token instead (this happens for example at the start of a line).
582
583       else
584          Error_Msg (Msg, Token_Ptr);
585       end if;
586    end Error_Msg_BC;
587
588    -------------------
589    -- Error_Msg_CRT --
590    -------------------
591
592    procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
593       CNRT : constant String := " not allowed in no run time mode";
594       CCRT : constant String := " not supported by configuration>";
595
596       S : String (1 .. Feature'Length + 1 + CCRT'Length);
597       L : Natural;
598
599    begin
600       S (1) := '|';
601       S (2 .. Feature'Length + 1) := Feature;
602       L := Feature'Length + 2;
603
604       if No_Run_Time_Mode then
605          S (L .. L + CNRT'Length - 1) := CNRT;
606          L := L + CNRT'Length - 1;
607
608       else pragma Assert (Configurable_Run_Time_Mode);
609          S (L .. L + CCRT'Length - 1) := CCRT;
610          L := L + CCRT'Length - 1;
611       end if;
612
613       Error_Msg_N (S (1 .. L), N);
614       Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
615    end Error_Msg_CRT;
616
617    -----------------
618    -- Error_Msg_F --
619    -----------------
620
621    procedure Error_Msg_F (Msg : String; N : Node_Id) is
622    begin
623       Error_Msg_NEL (Msg, N, N, Sloc (First_Node (N)));
624    end Error_Msg_F;
625
626    ------------------
627    -- Error_Msg_FE --
628    ------------------
629
630    procedure Error_Msg_FE
631      (Msg : String;
632       N   : Node_Id;
633       E   : Node_Or_Entity_Id)
634    is
635    begin
636       Error_Msg_NEL (Msg, N, E, Sloc (First_Node (N)));
637    end Error_Msg_FE;
638
639    ------------------------
640    -- Error_Msg_Internal --
641    ------------------------
642
643    procedure Error_Msg_Internal
644      (Msg      : String;
645       Sptr     : Source_Ptr;
646       Optr     : Source_Ptr;
647       Msg_Cont : Boolean)
648    is
649       Next_Msg : Error_Msg_Id;
650       --  Pointer to next message at insertion point
651
652       Prev_Msg : Error_Msg_Id;
653       --  Pointer to previous message at insertion point
654
655       Temp_Msg : Error_Msg_Id;
656
657       procedure Handle_Serious_Error;
658       --  Internal procedure to do all error message handling for a serious
659       --  error message, other than bumping the error counts and arranging
660       --  for the message to be output.
661
662       --------------------------
663       -- Handle_Serious_Error --
664       --------------------------
665
666       procedure Handle_Serious_Error is
667       begin
668          --  Turn off code generation if not done already
669
670          if Operating_Mode = Generate_Code then
671             Operating_Mode := Check_Semantics;
672             Expander_Active := False;
673          end if;
674
675          --  Set the fatal error flag in the unit table unless we are
676          --  in Try_Semantics mode. This stops the semantics from being
677          --  performed if we find a serious error. This is skipped if we
678          --  are currently dealing with the configuration pragma file.
679
680          if not Try_Semantics
681            and then Current_Source_Unit /= No_Unit
682          then
683             Set_Fatal_Error (Get_Source_Unit (Sptr));
684          end if;
685       end Handle_Serious_Error;
686
687    --  Start of processing for Error_Msg_Internal
688
689    begin
690       if Raise_Exception_On_Error /= 0 then
691          raise Error_Msg_Exception;
692       end if;
693
694       Continuation := Msg_Cont;
695       Continuation_New_Line := False;
696       Suppress_Message := False;
697       Kill_Message := False;
698       Set_Msg_Text (Msg, Sptr);
699
700       --  Kill continuation if parent message killed
701
702       if Continuation and Last_Killed then
703          return;
704       end if;
705
706       --  Return without doing anything if message is suppressed
707
708       if Suppress_Message
709         and not All_Errors_Mode
710         and not (Msg (Msg'Last) = '!')
711         and not Is_Warning_Msg
712       then
713          if not Continuation then
714             Last_Killed := True;
715          end if;
716
717          return;
718       end if;
719
720       --  Return without doing anything if message is killed and this
721       --  is not the first error message. The philosophy is that if we
722       --  get a weird error message and we already have had a message,
723       --  then we hope the weird message is a junk cascaded message
724
725       if Kill_Message
726         and then not All_Errors_Mode
727         and then Total_Errors_Detected /= 0
728       then
729          if not Continuation then
730             Last_Killed := True;
731          end if;
732
733          return;
734       end if;
735
736       --  Special check for warning message to see if it should be output
737
738       if Is_Warning_Msg then
739
740          --  Immediate return if warning message and warnings are suppressed
741
742          if Warnings_Suppressed (Optr)
743            or else Warnings_Suppressed (Sptr)
744          then
745             Cur_Msg := No_Error_Msg;
746             return;
747          end if;
748
749          --  If the flag location is in the main extended source unit
750          --  then for sure we want the warning since it definitely belongs
751
752          if In_Extended_Main_Source_Unit (Sptr) then
753             null;
754
755          --  If the flag location is not in the main extended source unit,
756          --  then we want to eliminate the warning, unless it is in the
757          --  extended main code unit and we want warnings on the instance.
758
759          elsif In_Extended_Main_Code_Unit (Sptr)
760            and then Warn_On_Instance
761          then
762             null;
763
764          --  Keep warning if debug flag G set
765
766          elsif Debug_Flag_GG then
767             null;
768
769          --  Keep warning if message text ends in !!
770
771          elsif Msg (Msg'Last) = '!' and then Msg (Msg'Last - 1) = '!' then
772             null;
773
774          --  Here is where we delete a warning from a with'ed unit
775
776          else
777             Cur_Msg := No_Error_Msg;
778
779             if not Continuation then
780                Last_Killed := True;
781             end if;
782
783             return;
784          end if;
785       end if;
786
787       --  If message is to be ignored in special ignore message mode, this is
788       --  where we do this special processing, bypassing message output.
789
790       if Ignore_Errors_Enable > 0 then
791          if Is_Serious_Error then
792             Handle_Serious_Error;
793          end if;
794
795          return;
796       end if;
797
798       --  If error message line length set, and this is a continuation message
799       --  then all we do is to append the text to the text of the last message
800       --  with a comma space separator.
801
802       if Error_Msg_Line_Length /= 0
803         and then Continuation
804       then
805          Cur_Msg := Errors.Last;
806
807          declare
808             Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
809             Newm : String (1 .. Oldm'Last + 2 + Msglen);
810             Newl : Natural;
811
812          begin
813             --  First copy old message to new one and free it
814
815             Newm (Oldm'Range) := Oldm.all;
816             Newl := Oldm'Length;
817             Free (Oldm);
818
819             --  Now deal with separation between messages. Normally this
820             --  is simply comma space, but there are some special cases.
821
822             --  If continuation new line, then put actual NL character in msg
823
824             if Continuation_New_Line then
825                Newl := Newl + 1;
826                Newm (Newl) := ASCII.LF;
827
828             --  If continuation message is enclosed in parentheses, then
829             --  special treatment (don't need a comma, and we want to combine
830             --  successive parenthetical remarks into a single one with
831             --  separating commas).
832
833             elsif Msg_Buffer (1) = '(' and then Msg_Buffer (Msglen) = ')' then
834
835                --  Case where existing message ends in right paren, remove
836                --  and separate parenthetical remarks with a comma.
837
838                if Newm (Newl) = ')' then
839                   Newm (Newl) := ',';
840                   Msg_Buffer (1) := ' ';
841
842                   --  Case where we are adding new parenthetical comment
843
844                else
845                   Newl := Newl + 1;
846                   Newm (Newl) := ' ';
847                end if;
848
849             --  Case where continuation not in parens and no new line
850
851             else
852                Newm (Newl + 1 .. Newl + 2) := ", ";
853                Newl := Newl + 2;
854             end if;
855
856             --  Append new message
857
858             Newm (Newl + 1 .. Newl + Msglen) := Msg_Buffer (1 .. Msglen);
859             Newl := Newl + Msglen;
860             Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
861          end;
862
863          return;
864       end if;
865
866       --  Otherwise build error message object for new message
867
868       Errors.Increment_Last;
869       Cur_Msg := Errors.Last;
870       Errors.Table (Cur_Msg).Text     := new String'(Msg_Buffer (1 .. Msglen));
871       Errors.Table (Cur_Msg).Next     := No_Error_Msg;
872       Errors.Table (Cur_Msg).Sptr     := Sptr;
873       Errors.Table (Cur_Msg).Optr     := Optr;
874       Errors.Table (Cur_Msg).Sfile    := Get_Source_File_Index (Sptr);
875       Errors.Table (Cur_Msg).Line     := Get_Physical_Line_Number (Sptr);
876       Errors.Table (Cur_Msg).Col      := Get_Column_Number (Sptr);
877       Errors.Table (Cur_Msg).Warn     := Is_Warning_Msg;
878       Errors.Table (Cur_Msg).Style    := Is_Style_Msg;
879       Errors.Table (Cur_Msg).Serious  := Is_Serious_Error;
880       Errors.Table (Cur_Msg).Uncond   := Is_Unconditional_Msg;
881       Errors.Table (Cur_Msg).Msg_Cont := Continuation;
882       Errors.Table (Cur_Msg).Deleted  := False;
883
884       --  If immediate errors mode set, output error message now. Also output
885       --  now if the -d1 debug flag is set (so node number message comes out
886       --  just before actual error message)
887
888       if Debug_Flag_OO or else Debug_Flag_1 then
889          Write_Eol;
890          Output_Source_Line
891            (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
892          Temp_Msg := Cur_Msg;
893          Output_Error_Msgs (Temp_Msg);
894
895       --  If not in immediate errors mode, then we insert the message in the
896       --  error chain for later output by Finalize. The messages are sorted
897       --  first by unit (main unit comes first), and within a unit by source
898       --  location (earlier flag location first in the chain).
899
900       else
901          --  First a quick check, does this belong at the very end of the chain
902          --  of error messages. This saves a lot of time in the normal case if
903          --  there are lots of messages.
904
905          if Last_Error_Msg /= No_Error_Msg
906            and then Errors.Table (Cur_Msg).Sfile =
907                     Errors.Table (Last_Error_Msg).Sfile
908            and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
909                        or else
910                           (Sptr = Errors.Table (Last_Error_Msg).Sptr
911                              and then
912                                Optr > Errors.Table (Last_Error_Msg).Optr))
913          then
914             Prev_Msg := Last_Error_Msg;
915             Next_Msg := No_Error_Msg;
916
917          --  Otherwise do a full sequential search for the insertion point
918
919          else
920             Prev_Msg := No_Error_Msg;
921             Next_Msg := First_Error_Msg;
922             while Next_Msg /= No_Error_Msg loop
923                exit when
924                  Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
925
926                if Errors.Table (Cur_Msg).Sfile =
927                     Errors.Table (Next_Msg).Sfile
928                then
929                   exit when Sptr < Errors.Table (Next_Msg).Sptr
930                               or else
931                                 (Sptr = Errors.Table (Next_Msg).Sptr
932                                    and then
933                                  Optr < Errors.Table (Next_Msg).Optr);
934                end if;
935
936                Prev_Msg := Next_Msg;
937                Next_Msg := Errors.Table (Next_Msg).Next;
938             end loop;
939          end if;
940
941          --  Now we insert the new message in the error chain. The insertion
942          --  point for the message is after Prev_Msg and before Next_Msg.
943
944          --  The possible insertion point for the new message is after Prev_Msg
945          --  and before Next_Msg. However, this is where we do a special check
946          --  for redundant parsing messages, defined as messages posted on the
947          --  same line. The idea here is that probably such messages are junk
948          --  from the parser recovering. In full errors mode, we don't do this
949          --  deletion, but otherwise such messages are discarded at this stage.
950
951          if Prev_Msg /= No_Error_Msg
952            and then Errors.Table (Prev_Msg).Line =
953                                              Errors.Table (Cur_Msg).Line
954            and then Errors.Table (Prev_Msg).Sfile =
955                                              Errors.Table (Cur_Msg).Sfile
956            and then Compiler_State = Parsing
957            and then not All_Errors_Mode
958          then
959             --  Don't delete unconditional messages and at this stage,
960             --  don't delete continuation lines (we attempted to delete
961             --  those earlier if the parent message was deleted.
962
963             if not Errors.Table (Cur_Msg).Uncond
964               and then not Continuation
965             then
966                --  Don't delete if prev msg is warning and new msg is an error.
967                --  This is because we don't want a real error masked by a
968                --  warning. In all other cases (that is parse errors for the
969                --  same line that are not unconditional) we do delete the
970                --  message. This helps to avoid junk extra messages from
971                --  cascaded parsing errors
972
973                if not (Errors.Table (Prev_Msg).Warn
974                          or
975                        Errors.Table (Prev_Msg).Style)
976                  or else
977                       (Errors.Table (Cur_Msg).Warn
978                          or
979                        Errors.Table (Cur_Msg).Style)
980                then
981                   --  All tests passed, delete the message by simply returning
982                   --  without any further processing.
983
984                   if not Continuation then
985                      Last_Killed := True;
986                   end if;
987
988                   return;
989                end if;
990             end if;
991          end if;
992
993          --  Come here if message is to be inserted in the error chain
994
995          if not Continuation then
996             Last_Killed := False;
997          end if;
998
999          if Prev_Msg = No_Error_Msg then
1000             First_Error_Msg := Cur_Msg;
1001          else
1002             Errors.Table (Prev_Msg).Next := Cur_Msg;
1003          end if;
1004
1005          Errors.Table (Cur_Msg).Next := Next_Msg;
1006
1007          if Next_Msg = No_Error_Msg then
1008             Last_Error_Msg := Cur_Msg;
1009          end if;
1010       end if;
1011
1012       --  Bump appropriate statistics count
1013
1014       if Errors.Table (Cur_Msg).Warn
1015         or else Errors.Table (Cur_Msg).Style
1016       then
1017          Warnings_Detected := Warnings_Detected + 1;
1018       else
1019          Total_Errors_Detected := Total_Errors_Detected + 1;
1020
1021          if Errors.Table (Cur_Msg).Serious then
1022             Serious_Errors_Detected := Serious_Errors_Detected + 1;
1023             Handle_Serious_Error;
1024          end if;
1025       end if;
1026
1027       --  Terminate if max errors reached
1028
1029       if Total_Errors_Detected + Warnings_Detected = Maximum_Errors then
1030          raise Unrecoverable_Error;
1031       end if;
1032    end Error_Msg_Internal;
1033
1034    -----------------
1035    -- Error_Msg_N --
1036    -----------------
1037
1038    procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1039    begin
1040       Error_Msg_NEL (Msg, N, N, Sloc (N));
1041    end Error_Msg_N;
1042
1043    ------------------
1044    -- Error_Msg_NE --
1045    ------------------
1046
1047    procedure Error_Msg_NE
1048      (Msg : String;
1049       N   : Node_Or_Entity_Id;
1050       E   : Node_Or_Entity_Id)
1051    is
1052    begin
1053       Error_Msg_NEL (Msg, N, E, Sloc (N));
1054    end Error_Msg_NE;
1055
1056    -------------------
1057    -- Error_Msg_NEL --
1058    -------------------
1059
1060    procedure Error_Msg_NEL
1061      (Msg           : String;
1062       N             : Node_Or_Entity_Id;
1063       E             : Node_Or_Entity_Id;
1064       Flag_Location : Source_Ptr)
1065    is
1066    begin
1067       if Special_Msg_Delete (Msg, N, E) then
1068          return;
1069       end if;
1070
1071       Test_Style_Warning_Serious_Msg (Msg);
1072
1073       --  Special handling for warning messages
1074
1075       if Is_Warning_Msg then
1076
1077          --  Suppress if no warnings set for either entity or node
1078
1079          if No_Warnings (N) or else No_Warnings (E) then
1080             return;
1081          end if;
1082
1083          --  Suppress if inside loop that is known to be null
1084
1085          declare
1086             P : Node_Id;
1087
1088          begin
1089             P := Parent (N);
1090             while Present (P) loop
1091                if Nkind (P) = N_Loop_Statement and then Is_Null_Loop (P) then
1092                   return;
1093                end if;
1094
1095                P := Parent (P);
1096             end loop;
1097          end;
1098       end if;
1099
1100       --  Test for message to be output
1101
1102       if All_Errors_Mode
1103         or else Msg (Msg'Last) = '!'
1104         or else Is_Warning_Msg
1105         or else OK_Node (N)
1106         or else (Msg (Msg'First) = '\' and not Last_Killed)
1107       then
1108          Debug_Output (N);
1109          Error_Msg_Node_1 := E;
1110          Error_Msg (Msg, Flag_Location);
1111
1112       else
1113          Last_Killed := True;
1114       end if;
1115
1116       if not Is_Warning_Msg and then not Is_Style_Msg then
1117          Set_Posted (N);
1118       end if;
1119    end Error_Msg_NEL;
1120
1121    ------------------
1122    -- Error_Msg_NW --
1123    ------------------
1124
1125    procedure Error_Msg_NW
1126      (Eflag : Boolean;
1127       Msg   : String;
1128       N     : Node_Or_Entity_Id)
1129    is
1130    begin
1131       if Eflag
1132         and then In_Extended_Main_Source_Unit (N)
1133         and then Comes_From_Source (N)
1134       then
1135          Error_Msg_NEL (Msg, N, N, Sloc (N));
1136       end if;
1137    end Error_Msg_NW;
1138
1139    -----------------
1140    -- Error_Msg_S --
1141    -----------------
1142
1143    procedure Error_Msg_S (Msg : String) is
1144    begin
1145       Error_Msg (Msg, Scan_Ptr);
1146    end Error_Msg_S;
1147
1148    ------------------
1149    -- Error_Msg_SC --
1150    ------------------
1151
1152    procedure Error_Msg_SC (Msg : String) is
1153    begin
1154       --  If we are at end of file, post the flag after the previous token
1155
1156       if Token = Tok_EOF then
1157          Error_Msg_AP (Msg);
1158
1159       --  For all other cases the message is posted at the current token
1160       --  pointer position
1161
1162       else
1163          Error_Msg (Msg, Token_Ptr);
1164       end if;
1165    end Error_Msg_SC;
1166
1167    ------------------
1168    -- Error_Msg_SP --
1169    ------------------
1170
1171    procedure Error_Msg_SP (Msg : String) is
1172    begin
1173       --  Note: in the case where there is no previous token, Prev_Token_Ptr
1174       --  is set to Source_First, which is a reasonable position for the
1175       --  error flag in this situation
1176
1177       Error_Msg (Msg, Prev_Token_Ptr);
1178    end Error_Msg_SP;
1179
1180    --------------
1181    -- Finalize --
1182    --------------
1183
1184    procedure Finalize (Last_Call : Boolean) is
1185       Cur : Error_Msg_Id;
1186       Nxt : Error_Msg_Id;
1187       F   : Error_Msg_Id;
1188
1189    begin
1190       --  Eliminate any duplicated error messages from the list. This is
1191       --  done after the fact to avoid problems with Change_Error_Text.
1192
1193       Cur := First_Error_Msg;
1194       while Cur /= No_Error_Msg loop
1195          Nxt := Errors.Table (Cur).Next;
1196
1197          F := Nxt;
1198          while F /= No_Error_Msg
1199            and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1200          loop
1201             Check_Duplicate_Message (Cur, F);
1202             F := Errors.Table (F).Next;
1203          end loop;
1204
1205          Cur := Nxt;
1206       end loop;
1207
1208       --  Mark any messages suppressed by specific warnings as Deleted
1209
1210       Cur := First_Error_Msg;
1211       while Cur /= No_Error_Msg loop
1212          if not Errors.Table (Cur).Deleted
1213            and then Warning_Specifically_Suppressed
1214                      (Errors.Table (Cur).Sptr,
1215                       Errors.Table (Cur).Text)
1216          then
1217             Errors.Table (Cur).Deleted := True;
1218             Warnings_Detected := Warnings_Detected - 1;
1219          end if;
1220
1221          Cur := Errors.Table (Cur).Next;
1222       end loop;
1223
1224       Finalize_Called := True;
1225
1226       --  Check consistency of specific warnings (may add warnings). We only
1227       --  do this on the last call, after all possible warnings are posted.
1228
1229       if Last_Call then
1230          Validate_Specific_Warnings (Error_Msg'Access);
1231       end if;
1232    end Finalize;
1233
1234    ----------------
1235    -- First_Node --
1236    ----------------
1237
1238    function First_Node (C : Node_Id) return Node_Id is
1239       L        : constant Source_Ptr        := Sloc (Original_Node (C));
1240       Sfile    : constant Source_File_Index := Get_Source_File_Index (L);
1241       Earliest : Node_Id;
1242       Eloc     : Source_Ptr;
1243
1244       function Test_Earlier (N : Node_Id) return Traverse_Result;
1245       --  Function applied to every node in the construct
1246
1247       procedure Search_Tree_First is new Traverse_Proc (Test_Earlier);
1248       --  Create traversal procedure
1249
1250       ------------------
1251       -- Test_Earlier --
1252       ------------------
1253
1254       function Test_Earlier (N : Node_Id) return Traverse_Result is
1255          Loc : constant Source_Ptr := Sloc (Original_Node (N));
1256
1257       begin
1258          --  Check for earlier. The tests for being in the same file ensures
1259          --  against strange cases of foreign code somehow being present. We
1260          --  don't want wild placement of messages if that happens, so it is
1261          --  best to just ignore this situation.
1262
1263          if Loc < Eloc
1264            and then Get_Source_File_Index (Loc) = Sfile
1265          then
1266             Earliest := Original_Node (N);
1267             Eloc     := Loc;
1268          end if;
1269
1270          return OK_Orig;
1271       end Test_Earlier;
1272
1273    --  Start of processing for First_Node
1274
1275    begin
1276       Earliest := Original_Node (C);
1277       Eloc := Sloc (Earliest);
1278       Search_Tree_First (Original_Node (C));
1279       return Earliest;
1280    end First_Node;
1281
1282    ----------------
1283    -- First_Sloc --
1284    ----------------
1285
1286    function First_Sloc (N : Node_Id) return Source_Ptr is
1287       SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1288       SF : constant Source_Ptr        := Source_First (SI);
1289       F  : Node_Id;
1290       S  : Source_Ptr;
1291
1292    begin
1293       F := First_Node (N);
1294       S := Sloc (F);
1295
1296       --  The following circuit is a bit subtle. When we have parenthesized
1297       --  expressions, then the Sloc will not record the location of the
1298       --  paren, but we would like to post the flag on the paren. So what
1299       --  we do is to crawl up the tree from the First_Node, adjusting the
1300       --  Sloc value for any parentheses we know are present. Yes, we know
1301       --  this circuit is not 100% reliable (e.g. because we don't record
1302       --  all possible paren level values), but this is only for an error
1303       --  message so it is good enough.
1304
1305       Node_Loop : loop
1306          Paren_Loop : for J in 1 .. Paren_Count (F) loop
1307
1308             --  We don't look more than 12 characters behind the current
1309             --  location, and in any case not past the front of the source.
1310
1311             Search_Loop : for K in 1 .. 12 loop
1312                exit Search_Loop when S = SF;
1313
1314                if Source_Text (SI) (S - 1) = '(' then
1315                   S := S - 1;
1316                   exit Search_Loop;
1317
1318                elsif Source_Text (SI) (S - 1) <= ' ' then
1319                   S := S - 1;
1320
1321                else
1322                   exit Search_Loop;
1323                end if;
1324             end loop Search_Loop;
1325          end loop Paren_Loop;
1326
1327          exit Node_Loop when F = N;
1328          F := Parent (F);
1329          exit Node_Loop when Nkind (F) not in N_Subexpr;
1330       end loop Node_Loop;
1331
1332       return S;
1333    end First_Sloc;
1334
1335    ----------------
1336    -- Initialize --
1337    ----------------
1338
1339    procedure Initialize is
1340    begin
1341       Errors.Init;
1342       First_Error_Msg := No_Error_Msg;
1343       Last_Error_Msg := No_Error_Msg;
1344       Serious_Errors_Detected := 0;
1345       Total_Errors_Detected := 0;
1346       Warnings_Detected := 0;
1347       Cur_Msg := No_Error_Msg;
1348       List_Pragmas.Init;
1349
1350       --  Initialize warnings table, if all warnings are suppressed, supply
1351       --  an initial dummy entry covering all possible source locations.
1352
1353       Warnings.Init;
1354       Specific_Warnings.Init;
1355
1356       if Warning_Mode = Suppress then
1357          Warnings.Increment_Last;
1358          Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
1359          Warnings.Table (Warnings.Last).Stop  := Source_Ptr'Last;
1360       end if;
1361    end Initialize;
1362
1363    -----------------
1364    -- No_Warnings --
1365    -----------------
1366
1367    function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1368    begin
1369       if Error_Posted (N) then
1370          return True;
1371
1372       elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
1373          return True;
1374
1375       elsif Is_Entity_Name (N)
1376         and then Present (Entity (N))
1377         and then Has_Warnings_Off (Entity (N))
1378       then
1379          return True;
1380
1381       else
1382          return False;
1383       end if;
1384    end No_Warnings;
1385
1386    -------------
1387    -- OK_Node --
1388    -------------
1389
1390    function OK_Node (N : Node_Id) return Boolean is
1391       K : constant Node_Kind := Nkind (N);
1392
1393    begin
1394       if Error_Posted (N) then
1395          return False;
1396
1397       elsif K in N_Has_Etype
1398         and then Present (Etype (N))
1399         and then Error_Posted (Etype (N))
1400       then
1401          return False;
1402
1403       elsif (K in N_Op
1404               or else K = N_Attribute_Reference
1405               or else K = N_Character_Literal
1406               or else K = N_Expanded_Name
1407               or else K = N_Identifier
1408               or else K = N_Operator_Symbol)
1409         and then Present (Entity (N))
1410         and then Error_Posted (Entity (N))
1411       then
1412          return False;
1413       else
1414          return True;
1415       end if;
1416    end OK_Node;
1417
1418    ---------------------
1419    -- Output_Messages --
1420    ---------------------
1421
1422    procedure Output_Messages is
1423       E        : Error_Msg_Id;
1424       Err_Flag : Boolean;
1425
1426       procedure Write_Error_Summary;
1427       --  Write error summary
1428
1429       procedure Write_Header (Sfile : Source_File_Index);
1430       --  Write header line (compiling or checking given file)
1431
1432       procedure Write_Max_Errors;
1433       --  Write message if max errors reached
1434
1435       -------------------------
1436       -- Write_Error_Summary --
1437       -------------------------
1438
1439       procedure Write_Error_Summary is
1440       begin
1441          --  Extra blank line if error messages or source listing were output
1442
1443          if Total_Errors_Detected + Warnings_Detected > 0
1444            or else Full_List
1445          then
1446             Write_Eol;
1447          end if;
1448
1449          --  Message giving number of lines read and number of errors detected.
1450          --  This normally goes to Standard_Output. The exception is when brief
1451          --  mode is not set, verbose mode (or full list mode) is set, and
1452          --  there are errors. In this case we send the message to standard
1453          --  error to make sure that *something* appears on standard error in
1454          --  an error situation.
1455
1456          --  Formerly, only the "# errors" suffix was sent to stderr, whereas
1457          --  "# lines:" appeared on stdout. This caused problems on VMS when
1458          --  the stdout buffer was flushed, giving an extra line feed after
1459          --  the prefix.
1460
1461          if Total_Errors_Detected + Warnings_Detected /= 0
1462            and then not Brief_Output
1463            and then (Verbose_Mode or Full_List)
1464          then
1465             Set_Standard_Error;
1466          end if;
1467
1468          --  Message giving total number of lines
1469
1470          Write_Str (" ");
1471          Write_Int (Num_Source_Lines (Main_Source_File));
1472
1473          if Num_Source_Lines (Main_Source_File) = 1 then
1474             Write_Str (" line: ");
1475          else
1476             Write_Str (" lines: ");
1477          end if;
1478
1479          if Total_Errors_Detected = 0 then
1480             Write_Str ("No errors");
1481
1482          elsif Total_Errors_Detected = 1 then
1483             Write_Str ("1 error");
1484
1485          else
1486             Write_Int (Total_Errors_Detected);
1487             Write_Str (" errors");
1488          end if;
1489
1490          if Warnings_Detected /= 0 then
1491             Write_Str (", ");
1492             Write_Int (Warnings_Detected);
1493             Write_Str (" warning");
1494
1495             if Warnings_Detected /= 1 then
1496                Write_Char ('s');
1497             end if;
1498
1499             if Warning_Mode = Treat_As_Error then
1500                Write_Str (" (treated as error");
1501
1502                if Warnings_Detected /= 1 then
1503                   Write_Char ('s');
1504                end if;
1505
1506                Write_Char (')');
1507             end if;
1508          end if;
1509
1510          Write_Eol;
1511          Set_Standard_Output;
1512       end Write_Error_Summary;
1513
1514       ------------------
1515       -- Write_Header --
1516       ------------------
1517
1518       procedure Write_Header (Sfile : Source_File_Index) is
1519       begin
1520          if Verbose_Mode or Full_List then
1521             if Original_Operating_Mode = Generate_Code then
1522                Write_Str ("Compiling: ");
1523             else
1524                Write_Str ("Checking: ");
1525             end if;
1526
1527             Write_Name (Full_File_Name (Sfile));
1528
1529             if not Debug_Flag_7 then
1530                Write_Str (" (source file time stamp: ");
1531                Write_Time_Stamp (Sfile);
1532                Write_Char (')');
1533             end if;
1534
1535             Write_Eol;
1536          end if;
1537       end Write_Header;
1538
1539       ----------------------
1540       -- Write_Max_Errors --
1541       ----------------------
1542
1543       procedure Write_Max_Errors is
1544       begin
1545          if Maximum_Errors /= 0
1546            and then Total_Errors_Detected + Warnings_Detected = Maximum_Errors
1547          then
1548             Set_Standard_Error;
1549             Write_Str ("fatal error: maximum errors reached");
1550             Write_Eol;
1551             Set_Standard_Output;
1552          end if;
1553       end Write_Max_Errors;
1554
1555    --  Start of processing for Output_Messages
1556
1557    begin
1558       --  Error if Finalize has not been called
1559
1560       if not Finalize_Called then
1561          raise Program_Error;
1562       end if;
1563
1564       --  Reset current error source file if the main unit has a pragma
1565       --  Source_Reference. This ensures outputting the proper name of
1566       --  the source file in this situation.
1567
1568       if Main_Source_File = No_Source_File
1569         or else Num_SRef_Pragmas (Main_Source_File) /= 0
1570       then
1571          Current_Error_Source_File := No_Source_File;
1572       end if;
1573
1574       --  Brief Error mode
1575
1576       if Brief_Output or (not Full_List and not Verbose_Mode) then
1577          Set_Standard_Error;
1578
1579          E := First_Error_Msg;
1580          while E /= No_Error_Msg loop
1581             if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1582                if Full_Path_Name_For_Brief_Errors then
1583                   Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1584                else
1585                   Write_Name (Reference_Name (Errors.Table (E).Sfile));
1586                end if;
1587
1588                Write_Char (':');
1589                Write_Int (Int (Physical_To_Logical
1590                                 (Errors.Table (E).Line,
1591                                  Errors.Table (E).Sfile)));
1592                Write_Char (':');
1593
1594                if Errors.Table (E).Col < 10 then
1595                   Write_Char ('0');
1596                end if;
1597
1598                Write_Int (Int (Errors.Table (E).Col));
1599                Write_Str (": ");
1600                Output_Msg_Text (E);
1601                Write_Eol;
1602             end if;
1603
1604             E := Errors.Table (E).Next;
1605          end loop;
1606
1607          Set_Standard_Output;
1608       end if;
1609
1610       --  Full source listing case
1611
1612       if Full_List then
1613          List_Pragmas_Index := 1;
1614          List_Pragmas_Mode := True;
1615          E := First_Error_Msg;
1616
1617          --  Normal case, to stdout (copyright notice already output)
1618
1619          if Full_List_File_Name = null then
1620             if not Debug_Flag_7 then
1621                Write_Eol;
1622             end if;
1623
1624          --  Output to file
1625
1626          else
1627             Create_List_File_Access.all (Full_List_File_Name.all);
1628             Set_Special_Output (Write_List_Info_Access.all'Access);
1629
1630             --  Write copyright notice to file
1631
1632             if not Debug_Flag_7 then
1633                Write_Str ("GNAT ");
1634                Write_Str (Gnat_Version_String);
1635                Write_Eol;
1636                Write_Str ("Copyright 1992-" &
1637                           Current_Year &
1638                           ", Free Software Foundation, Inc.");
1639                Write_Eol;
1640             end if;
1641          end if;
1642
1643          --  First list extended main source file units with errors
1644
1645          --  Note: if debug flag d.m is set, only the main source is listed
1646
1647          for U in Main_Unit .. Last_Unit loop
1648             if In_Extended_Main_Source_Unit (Cunit_Entity (U))
1649               and then (U = Main_Unit or else not Debug_Flag_Dot_M)
1650             then
1651                declare
1652                   Sfile : constant Source_File_Index := Source_Index (U);
1653
1654                begin
1655                   Write_Eol;
1656                   Write_Header (Sfile);
1657                   Write_Eol;
1658
1659                   --  Normally, we don't want an "error messages from file"
1660                   --  message when listing the entire file, so we set the
1661                   --  current source file as the current error source file.
1662                   --  However, the old style of doing things was to list this
1663                   --  message if pragma Source_Reference is present, even for
1664                   --  the main unit. Since the purpose of the -gnatd.m switch
1665                   --  is to duplicate the old behavior, we skip the reset if
1666                   --  this debug flag is set.
1667
1668                   if not Debug_Flag_Dot_M then
1669                      Current_Error_Source_File := Sfile;
1670                   end if;
1671
1672                   for N in 1 .. Last_Source_Line (Sfile) loop
1673                      while E /= No_Error_Msg
1674                        and then Errors.Table (E).Deleted
1675                      loop
1676                         E := Errors.Table (E).Next;
1677                      end loop;
1678
1679                      Err_Flag :=
1680                        E /= No_Error_Msg
1681                          and then Errors.Table (E).Line = N
1682                          and then Errors.Table (E).Sfile = Sfile;
1683
1684                      Output_Source_Line (N, Sfile, Err_Flag);
1685
1686                      if Err_Flag then
1687                         Output_Error_Msgs (E);
1688
1689                         if not Debug_Flag_2 then
1690                            Write_Eol;
1691                         end if;
1692                      end if;
1693                   end loop;
1694                end;
1695             end if;
1696          end loop;
1697
1698          --  Then output errors, if any, for subsidiary units not in the
1699          --  main extended unit.
1700
1701          --  Note: if debug flag d.m set, include errors for any units other
1702          --  than the main unit in the extended source unit (e.g. spec and
1703          --  subunits for a body).
1704
1705          while E /= No_Error_Msg
1706            and then (not In_Extended_Main_Source_Unit (Errors.Table (E).Sptr)
1707                        or else
1708                         (Debug_Flag_Dot_M
1709                           and then Get_Source_Unit
1710                                      (Errors.Table (E).Sptr) /= Main_Unit))
1711          loop
1712             if Errors.Table (E).Deleted then
1713                E := Errors.Table (E).Next;
1714
1715             else
1716                Write_Eol;
1717                Output_Source_Line
1718                  (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1719                Output_Error_Msgs (E);
1720             end if;
1721          end loop;
1722
1723          --  If output to file, write extra copy of error summary to the
1724          --  output file, and then close it.
1725
1726          if Full_List_File_Name /= null then
1727             Write_Error_Summary;
1728             Write_Max_Errors;
1729             Close_List_File_Access.all;
1730             Cancel_Special_Output;
1731          end if;
1732       end if;
1733
1734       --  Verbose mode (error lines only with error flags). Normally this is
1735       --  ignored in full list mode, unless we are listing to a file, in which
1736       --  case we still generate -gnatv output to standard output.
1737
1738       if Verbose_Mode
1739         and then (not Full_List or else Full_List_File_Name /= null)
1740       then
1741          Write_Eol;
1742          Write_Header (Main_Source_File);
1743          E := First_Error_Msg;
1744
1745          --  Loop through error lines
1746
1747          while E /= No_Error_Msg loop
1748             if Errors.Table (E).Deleted then
1749                E := Errors.Table (E).Next;
1750             else
1751                Write_Eol;
1752                Output_Source_Line
1753                  (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1754                Output_Error_Msgs (E);
1755             end if;
1756          end loop;
1757       end if;
1758
1759       --  Output error summary if verbose or full list mode
1760
1761       if Verbose_Mode or else Full_List then
1762          Write_Error_Summary;
1763       end if;
1764
1765       Write_Max_Errors;
1766
1767       if Warning_Mode = Treat_As_Error then
1768          Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected;
1769          Warnings_Detected := 0;
1770       end if;
1771    end Output_Messages;
1772
1773    ------------------------
1774    -- Output_Source_Line --
1775    ------------------------
1776
1777    procedure Output_Source_Line
1778      (L     : Physical_Line_Number;
1779       Sfile : Source_File_Index;
1780       Errs  : Boolean)
1781    is
1782       S : Source_Ptr;
1783       C : Character;
1784
1785       Line_Number_Output : Boolean := False;
1786       --  Set True once line number is output
1787
1788       Empty_Line : Boolean := True;
1789       --  Set False if line includes at least one character
1790
1791    begin
1792       if Sfile /= Current_Error_Source_File then
1793          Write_Str ("==============Error messages for ");
1794
1795          case Sinput.File_Type (Sfile) is
1796             when Sinput.Src =>
1797                Write_Str ("source");
1798
1799             when Sinput.Config =>
1800                Write_Str ("configuration pragmas");
1801
1802             when Sinput.Def =>
1803                Write_Str ("symbol definition");
1804
1805             when Sinput.Preproc =>
1806                Write_Str ("preprocessing data");
1807          end case;
1808
1809          Write_Str (" file: ");
1810          Write_Name (Full_File_Name (Sfile));
1811          Write_Eol;
1812
1813          if Num_SRef_Pragmas (Sfile) > 0 then
1814             Write_Str ("--------------Line numbers from file: ");
1815             Write_Name (Full_Ref_Name (Sfile));
1816             Write_Str (" (starting at line ");
1817             Write_Int (Int (First_Mapped_Line (Sfile)));
1818             Write_Char (')');
1819             Write_Eol;
1820          end if;
1821
1822          Current_Error_Source_File := Sfile;
1823       end if;
1824
1825       if Errs or List_Pragmas_Mode then
1826          Output_Line_Number (Physical_To_Logical (L, Sfile));
1827          Line_Number_Output := True;
1828       end if;
1829
1830       S := Line_Start (L, Sfile);
1831
1832       loop
1833          C := Source_Text (Sfile) (S);
1834          exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
1835
1836          --  Deal with matching entry in List_Pragmas table
1837
1838          if Full_List
1839            and then List_Pragmas_Index <= List_Pragmas.Last
1840            and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
1841          then
1842             case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
1843                when Page =>
1844                   Write_Char (C);
1845
1846                   --  Ignore if on line with errors so that error flags
1847                   --  get properly listed with the error line .
1848
1849                   if not Errs then
1850                      Write_Char (ASCII.FF);
1851                   end if;
1852
1853                when List_On =>
1854                   List_Pragmas_Mode := True;
1855
1856                   if not Line_Number_Output then
1857                      Output_Line_Number (Physical_To_Logical (L, Sfile));
1858                      Line_Number_Output := True;
1859                   end if;
1860
1861                   Write_Char (C);
1862
1863                when List_Off =>
1864                   Write_Char (C);
1865                   List_Pragmas_Mode := False;
1866             end case;
1867
1868             List_Pragmas_Index := List_Pragmas_Index + 1;
1869
1870          --  Normal case (no matching entry in List_Pragmas table)
1871
1872          else
1873             if Errs or List_Pragmas_Mode then
1874                Write_Char (C);
1875             end if;
1876          end if;
1877
1878          Empty_Line := False;
1879          S := S + 1;
1880       end loop;
1881
1882       --  If we have output a source line, then add the line terminator, with
1883       --  training spaces preserved (so we output the line exactly as input).
1884
1885       if Line_Number_Output then
1886          if Empty_Line then
1887             Write_Eol;
1888          else
1889             Write_Eol_Keep_Blanks;
1890          end if;
1891       end if;
1892    end Output_Source_Line;
1893
1894    -----------------------------
1895    -- Remove_Warning_Messages --
1896    -----------------------------
1897
1898    procedure Remove_Warning_Messages (N : Node_Id) is
1899
1900       function Check_For_Warning (N : Node_Id) return Traverse_Result;
1901       --  This function checks one node for a possible warning message
1902
1903       function Check_All_Warnings is new Traverse_Func (Check_For_Warning);
1904       --  This defines the traversal operation
1905
1906       -----------------------
1907       -- Check_For_Warning --
1908       -----------------------
1909
1910       function Check_For_Warning (N : Node_Id) return Traverse_Result is
1911          Loc : constant Source_Ptr := Sloc (N);
1912          E   : Error_Msg_Id;
1913
1914          function To_Be_Removed (E : Error_Msg_Id) return Boolean;
1915          --  Returns True for a message that is to be removed. Also adjusts
1916          --  warning count appropriately.
1917
1918          -------------------
1919          -- To_Be_Removed --
1920          -------------------
1921
1922          function To_Be_Removed (E : Error_Msg_Id) return Boolean is
1923          begin
1924             if E /= No_Error_Msg
1925
1926                --  Don't remove if location does not match
1927
1928                and then Errors.Table (E).Optr = Loc
1929
1930                --  Don't remove if not warning message. Note that we do not
1931                --  remove style messages here. They are warning messages but
1932                --  not ones we want removed in this context.
1933
1934                and then Errors.Table (E).Warn
1935
1936                --  Don't remove unconditional messages
1937
1938                and then not Errors.Table (E).Uncond
1939             then
1940                Warnings_Detected := Warnings_Detected - 1;
1941                return True;
1942
1943             --  No removal required
1944
1945             else
1946                return False;
1947             end if;
1948          end To_Be_Removed;
1949
1950       --  Start of processing for Check_For_Warnings
1951
1952       begin
1953          while To_Be_Removed (First_Error_Msg) loop
1954             First_Error_Msg := Errors.Table (First_Error_Msg).Next;
1955          end loop;
1956
1957          if First_Error_Msg = No_Error_Msg then
1958             Last_Error_Msg := No_Error_Msg;
1959          end if;
1960
1961          E := First_Error_Msg;
1962          while E /= No_Error_Msg loop
1963             while To_Be_Removed (Errors.Table (E).Next) loop
1964                Errors.Table (E).Next :=
1965                  Errors.Table (Errors.Table (E).Next).Next;
1966
1967                if Errors.Table (E).Next = No_Error_Msg then
1968                   Last_Error_Msg := E;
1969                end if;
1970             end loop;
1971
1972             E := Errors.Table (E).Next;
1973          end loop;
1974
1975          if Nkind (N) = N_Raise_Constraint_Error
1976            and then Original_Node (N) /= N
1977            and then No (Condition (N))
1978          then
1979             --  Warnings may have been posted on subexpressions of
1980             --  the original tree. We place the original node back
1981             --  on the tree to remove those warnings, whose sloc
1982             --  do not match those of any node in the current tree.
1983             --  Given that we are in unreachable code, this modification
1984             --  to the tree is harmless.
1985
1986             declare
1987                Status : Traverse_Final_Result;
1988
1989             begin
1990                if Is_List_Member (N) then
1991                   Set_Condition (N, Original_Node (N));
1992                   Status := Check_All_Warnings (Condition (N));
1993                else
1994                   Rewrite (N, Original_Node (N));
1995                   Status := Check_All_Warnings (N);
1996                end if;
1997
1998                return Status;
1999             end;
2000
2001          else
2002             return OK;
2003          end if;
2004       end Check_For_Warning;
2005
2006    --  Start of processing for Remove_Warning_Messages
2007
2008    begin
2009       if Warnings_Detected /= 0 then
2010          declare
2011             Discard : Traverse_Final_Result;
2012             pragma Warnings (Off, Discard);
2013
2014          begin
2015             Discard := Check_All_Warnings (N);
2016          end;
2017       end if;
2018    end Remove_Warning_Messages;
2019
2020    procedure Remove_Warning_Messages (L : List_Id) is
2021       Stat : Node_Id;
2022    begin
2023       if Is_Non_Empty_List (L) then
2024          Stat := First (L);
2025
2026          while Present (Stat) loop
2027             Remove_Warning_Messages (Stat);
2028             Next (Stat);
2029          end loop;
2030       end if;
2031    end Remove_Warning_Messages;
2032
2033    ---------------------------
2034    -- Set_Identifier_Casing --
2035    ---------------------------
2036
2037    procedure Set_Identifier_Casing
2038      (Identifier_Name : System.Address;
2039       File_Name       : System.Address)
2040    is
2041       type Big_String is array (Positive) of Character;
2042       type Big_String_Ptr is access all Big_String;
2043
2044       function To_Big_String_Ptr is new Unchecked_Conversion
2045         (System.Address, Big_String_Ptr);
2046
2047       Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
2048       File  : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
2049       Flen  : Natural;
2050
2051       Desired_Case : Casing_Type := Mixed_Case;
2052       --  Casing required for result. Default value of Mixed_Case is used if
2053       --  for some reason we cannot find the right file name in the table.
2054
2055    begin
2056       --  Get length of file name
2057
2058       Flen := 0;
2059       while File (Flen + 1) /= ASCII.NUL loop
2060          Flen := Flen + 1;
2061       end loop;
2062
2063       --  Loop through file names to find matching one. This is a bit slow,
2064       --  but we only do it in error situations so it is not so terrible.
2065       --  Note that if the loop does not exit, then the desired case will
2066       --  be left set to Mixed_Case, this can happen if the name was not
2067       --  in canonical form, and gets canonicalized on VMS. Possibly we
2068       --  could fix this by unconditinally canonicalizing these names ???
2069
2070       for J in 1 .. Last_Source_File loop
2071          Get_Name_String (Full_Debug_Name (J));
2072
2073          if Name_Len = Flen
2074            and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
2075          then
2076             Desired_Case := Identifier_Casing (J);
2077             exit;
2078          end if;
2079       end loop;
2080
2081       --  Copy identifier as given to Name_Buffer
2082
2083       for J in Name_Buffer'Range loop
2084          Name_Buffer (J) := Ident (J);
2085
2086          if Name_Buffer (J) = ASCII.Nul then
2087             Name_Len := J - 1;
2088             exit;
2089          end if;
2090       end loop;
2091
2092       Set_Casing (Desired_Case);
2093    end Set_Identifier_Casing;
2094
2095    -----------------------
2096    -- Set_Ignore_Errors --
2097    -----------------------
2098
2099    procedure Set_Ignore_Errors (To : Boolean) is
2100    begin
2101       Errors_Must_Be_Ignored := To;
2102    end Set_Ignore_Errors;
2103
2104    ------------------------------
2105    -- Set_Msg_Insertion_Column --
2106    ------------------------------
2107
2108    procedure Set_Msg_Insertion_Column is
2109    begin
2110       if Style.RM_Column_Check then
2111          Set_Msg_Str (" in column ");
2112          Set_Msg_Int (Int (Error_Msg_Col) + 1);
2113       end if;
2114    end Set_Msg_Insertion_Column;
2115
2116    ----------------------------
2117    -- Set_Msg_Insertion_Node --
2118    ----------------------------
2119
2120    procedure Set_Msg_Insertion_Node is
2121       K : Node_Kind;
2122
2123    begin
2124       Suppress_Message :=
2125         Error_Msg_Node_1 = Error
2126           or else Error_Msg_Node_1 = Any_Type;
2127
2128       if Error_Msg_Node_1 = Empty then
2129          Set_Msg_Blank_Conditional;
2130          Set_Msg_Str ("<empty>");
2131
2132       elsif Error_Msg_Node_1 = Error then
2133          Set_Msg_Blank;
2134          Set_Msg_Str ("<error>");
2135
2136       elsif Error_Msg_Node_1 = Standard_Void_Type then
2137          Set_Msg_Blank;
2138          Set_Msg_Str ("procedure name");
2139
2140       else
2141          Set_Msg_Blank_Conditional;
2142
2143          --  Output name
2144
2145          K := Nkind (Error_Msg_Node_1);
2146
2147          --  If we have operator case, skip quotes since name of operator
2148          --  itself will supply the required quotations. An operator can be
2149          --  an applied use in an expression or an explicit operator symbol,
2150          --  or an identifier whose name indicates it is an operator.
2151
2152          if K in N_Op
2153            or else K = N_Operator_Symbol
2154            or else K = N_Defining_Operator_Symbol
2155            or else ((K = N_Identifier or else K = N_Defining_Identifier)
2156                        and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
2157          then
2158             Set_Msg_Node (Error_Msg_Node_1);
2159
2160          --  Normal case, not an operator, surround with quotes
2161
2162          else
2163             Set_Msg_Quote;
2164             Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
2165             Set_Msg_Node (Error_Msg_Node_1);
2166             Set_Msg_Quote;
2167          end if;
2168       end if;
2169
2170       --  The following assignment ensures that a second ampersand insertion
2171       --  character will correspond to the Error_Msg_Node_2 parameter. We
2172       --  suppress possible validity checks in case operating in -gnatVa mode,
2173       --  and Error_Msg_Node_2 is not needed and has not been set.
2174
2175       declare
2176          pragma Suppress (Range_Check);
2177       begin
2178          Error_Msg_Node_1 := Error_Msg_Node_2;
2179       end;
2180    end Set_Msg_Insertion_Node;
2181
2182    --------------------------------------
2183    -- Set_Msg_Insertion_Type_Reference --
2184    --------------------------------------
2185
2186    procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
2187       Ent : Entity_Id;
2188
2189    begin
2190       Set_Msg_Blank;
2191
2192       if Error_Msg_Node_1 = Standard_Void_Type then
2193          Set_Msg_Str ("package or procedure name");
2194          return;
2195
2196       elsif Error_Msg_Node_1 = Standard_Exception_Type then
2197          Set_Msg_Str ("exception name");
2198          return;
2199
2200       elsif     Error_Msg_Node_1 = Any_Access
2201         or else Error_Msg_Node_1 = Any_Array
2202         or else Error_Msg_Node_1 = Any_Boolean
2203         or else Error_Msg_Node_1 = Any_Character
2204         or else Error_Msg_Node_1 = Any_Composite
2205         or else Error_Msg_Node_1 = Any_Discrete
2206         or else Error_Msg_Node_1 = Any_Fixed
2207         or else Error_Msg_Node_1 = Any_Integer
2208         or else Error_Msg_Node_1 = Any_Modular
2209         or else Error_Msg_Node_1 = Any_Numeric
2210         or else Error_Msg_Node_1 = Any_Real
2211         or else Error_Msg_Node_1 = Any_Scalar
2212         or else Error_Msg_Node_1 = Any_String
2213       then
2214          Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
2215          Set_Msg_Name_Buffer;
2216          return;
2217
2218       elsif Error_Msg_Node_1 = Universal_Real then
2219          Set_Msg_Str ("type universal real");
2220          return;
2221
2222       elsif Error_Msg_Node_1 = Universal_Integer then
2223          Set_Msg_Str ("type universal integer");
2224          return;
2225
2226       elsif Error_Msg_Node_1 = Universal_Fixed then
2227          Set_Msg_Str ("type universal fixed");
2228          return;
2229       end if;
2230
2231       --  Special case of anonymous array
2232
2233       if Nkind (Error_Msg_Node_1) in N_Entity
2234         and then Is_Array_Type (Error_Msg_Node_1)
2235         and then Present (Related_Array_Object (Error_Msg_Node_1))
2236       then
2237          Set_Msg_Str ("type of ");
2238          Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
2239          Set_Msg_Str (" declared");
2240          Set_Msg_Insertion_Line_Number
2241            (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
2242          return;
2243       end if;
2244
2245       --  If we fall through, it is not a special case, so first output
2246       --  the name of the type, preceded by private for a private type
2247
2248       if Is_Private_Type (Error_Msg_Node_1) then
2249          Set_Msg_Str ("private type ");
2250       else
2251          Set_Msg_Str ("type ");
2252       end if;
2253
2254       Ent := Error_Msg_Node_1;
2255
2256       if Is_Internal_Name (Chars (Ent)) then
2257          Unwind_Internal_Type (Ent);
2258       end if;
2259
2260       --  Types in Standard are displayed as "Standard.name"
2261
2262       if Sloc (Ent) <= Standard_Location then
2263          Set_Msg_Quote;
2264          Set_Msg_Str ("Standard.");
2265          Set_Msg_Node (Ent);
2266          Add_Class;
2267          Set_Msg_Quote;
2268
2269       --  Types in other language defined units are displayed as
2270       --  "package-name.type-name"
2271
2272       elsif
2273         Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Ent)))
2274       then
2275          Get_Unqualified_Decoded_Name_String
2276            (Unit_Name (Get_Source_Unit (Ent)));
2277          Name_Len := Name_Len - 2;
2278          Set_Msg_Quote;
2279          Set_Casing (Mixed_Case);
2280          Set_Msg_Name_Buffer;
2281          Set_Msg_Char ('.');
2282          Set_Casing (Mixed_Case);
2283          Set_Msg_Node (Ent);
2284          Add_Class;
2285          Set_Msg_Quote;
2286
2287       --  All other types display as "type name" defined at line xxx
2288       --  possibly qualified if qualification is requested.
2289
2290       else
2291          Set_Msg_Quote;
2292          Set_Qualification (Error_Msg_Qual_Level, Ent);
2293          Set_Msg_Node (Ent);
2294          Add_Class;
2295
2296          --  If Ent is an anonymous subprogram type, there is no name
2297          --  to print, so remove enclosing quotes.
2298
2299          if Buffer_Ends_With ("""") then
2300             Buffer_Remove ("""");
2301          else
2302             Set_Msg_Quote;
2303          end if;
2304       end if;
2305
2306       --  If the original type did not come from a predefined
2307       --  file, add the location where the type was defined.
2308
2309       if Sloc (Error_Msg_Node_1) > Standard_Location
2310         and then
2311           not Is_Predefined_File_Name
2312                 (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)))
2313       then
2314          Set_Msg_Str (" defined");
2315          Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
2316
2317       --  If it did come from a predefined file, deal with the case where
2318       --  this was a file with a generic instantiation from elsewhere.
2319
2320       else
2321          if Sloc (Error_Msg_Node_1) > Standard_Location then
2322             declare
2323                Iloc : constant Source_Ptr :=
2324                         Instantiation_Location (Sloc (Error_Msg_Node_1));
2325
2326             begin
2327                if Iloc /= No_Location
2328                  and then not Suppress_Instance_Location
2329                then
2330                   Set_Msg_Str (" from instance");
2331                   Set_Msg_Insertion_Line_Number (Iloc, Flag);
2332                end if;
2333             end;
2334          end if;
2335       end if;
2336    end Set_Msg_Insertion_Type_Reference;
2337
2338    ---------------------------------
2339    -- Set_Msg_Insertion_Unit_Name --
2340    ---------------------------------
2341
2342    procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
2343    begin
2344       if Error_Msg_Unit_1 = No_Unit_Name then
2345          null;
2346
2347       elsif Error_Msg_Unit_1 = Error_Unit_Name then
2348          Set_Msg_Blank;
2349          Set_Msg_Str ("<error>");
2350
2351       else
2352          Get_Unit_Name_String (Error_Msg_Unit_1, Suffix);
2353          Set_Msg_Blank;
2354          Set_Msg_Quote;
2355          Set_Msg_Name_Buffer;
2356          Set_Msg_Quote;
2357       end if;
2358
2359       --  The following assignment ensures that a second percent insertion
2360       --  character will correspond to the Error_Msg_Unit_2 parameter. We
2361       --  suppress possible validity checks in case operating in -gnatVa mode,
2362       --  and Error_Msg_Unit_2 is not needed and has not been set.
2363
2364       declare
2365          pragma Suppress (Range_Check);
2366       begin
2367          Error_Msg_Unit_1 := Error_Msg_Unit_2;
2368       end;
2369    end Set_Msg_Insertion_Unit_Name;
2370
2371    ------------------
2372    -- Set_Msg_Node --
2373    ------------------
2374
2375    procedure Set_Msg_Node (Node : Node_Id) is
2376       Ent : Entity_Id;
2377       Nam : Name_Id;
2378
2379    begin
2380       if Nkind (Node) = N_Designator then
2381          Set_Msg_Node (Name (Node));
2382          Set_Msg_Char ('.');
2383          Set_Msg_Node (Identifier (Node));
2384          return;
2385
2386       elsif Nkind (Node) = N_Defining_Program_Unit_Name then
2387          Set_Msg_Node (Name (Node));
2388          Set_Msg_Char ('.');
2389          Set_Msg_Node (Defining_Identifier (Node));
2390          return;
2391
2392       elsif Nkind (Node) = N_Selected_Component then
2393          Set_Msg_Node (Prefix (Node));
2394          Set_Msg_Char ('.');
2395          Set_Msg_Node (Selector_Name (Node));
2396          return;
2397       end if;
2398
2399       --  The only remaining possibilities are identifiers, defining
2400       --  identifiers, pragmas, and pragma argument associations.
2401
2402       if Nkind (Node) = N_Pragma then
2403          Nam := Pragma_Name (Node);
2404
2405       --  The other cases have Chars fields, and we want to test for possible
2406       --  internal names, which generally represent something gone wrong. An
2407       --  exception is the case of internal type names, where we try to find a
2408       --  reasonable external representation for the external name
2409
2410       elsif Is_Internal_Name (Chars (Node))
2411         and then
2412           ((Is_Entity_Name (Node)
2413                           and then Present (Entity (Node))
2414                           and then Is_Type (Entity (Node)))
2415               or else
2416            (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2417       then
2418          if Nkind (Node) = N_Identifier then
2419             Ent := Entity (Node);
2420          else
2421             Ent := Node;
2422          end if;
2423
2424          --  If the type is the designated type of an access_to_subprogram,
2425          --  there is no name to provide in the call.
2426
2427          if Ekind (Ent) = E_Subprogram_Type then
2428             return;
2429          else
2430             Unwind_Internal_Type (Ent);
2431             Nam := Chars (Ent);
2432          end if;
2433
2434       --  If not internal name, just use name in Chars field
2435
2436       else
2437          Nam := Chars (Node);
2438       end if;
2439
2440       --  At this stage, the name to output is in Nam
2441
2442       Get_Unqualified_Decoded_Name_String (Nam);
2443
2444       --  Remove trailing upper case letters from the name (useful for
2445       --  dealing with some cases of internal names.
2446
2447       while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
2448          Name_Len := Name_Len  - 1;
2449       end loop;
2450
2451       --  If we have any of the names from standard that start with the
2452       --  characters "any " (e.g. Any_Type), then kill the message since
2453       --  almost certainly it is a junk cascaded message.
2454
2455       if Name_Len > 4
2456         and then Name_Buffer (1 .. 4) = "any "
2457       then
2458          Kill_Message := True;
2459       end if;
2460
2461       --  Now we have to set the proper case. If we have a source location
2462       --  then do a check to see if the name in the source is the same name
2463       --  as the name in the Names table, except for possible differences
2464       --  in case, which is the case when we can copy from the source.
2465
2466       declare
2467          Src_Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
2468          Sbuffer : Source_Buffer_Ptr;
2469          Ref_Ptr : Integer;
2470          Src_Ptr : Source_Ptr;
2471
2472       begin
2473          Ref_Ptr := 1;
2474          Src_Ptr := Src_Loc;
2475
2476          --  For standard locations, always use mixed case
2477
2478          if Src_Loc <= No_Location
2479            or else Sloc (Node) <= No_Location
2480          then
2481             Set_Casing (Mixed_Case);
2482
2483          else
2484             --  Determine if the reference we are dealing with corresponds
2485             --  to text at the point of the error reference. This will often
2486             --  be the case for simple identifier references, and is the case
2487             --  where we can copy the spelling from the source.
2488
2489             Sbuffer := Source_Text (Get_Source_File_Index (Src_Loc));
2490
2491             while Ref_Ptr <= Name_Len loop
2492                exit when
2493                  Fold_Lower (Sbuffer (Src_Ptr)) /=
2494                  Fold_Lower (Name_Buffer (Ref_Ptr));
2495                Ref_Ptr := Ref_Ptr + 1;
2496                Src_Ptr := Src_Ptr + 1;
2497             end loop;
2498
2499             --  If we get through the loop without a mismatch, then output
2500             --  the name the way it is spelled in the source program
2501
2502             if Ref_Ptr > Name_Len then
2503                Src_Ptr := Src_Loc;
2504
2505                for J in 1 .. Name_Len loop
2506                   Name_Buffer (J) := Sbuffer (Src_Ptr);
2507                   Src_Ptr := Src_Ptr + 1;
2508                end loop;
2509
2510             --  Otherwise set the casing using the default identifier casing
2511
2512             else
2513                Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
2514             end if;
2515          end if;
2516       end;
2517
2518       Set_Msg_Name_Buffer;
2519       Add_Class;
2520    end Set_Msg_Node;
2521
2522    ------------------
2523    -- Set_Msg_Text --
2524    ------------------
2525
2526    procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2527       C : Character;   -- Current character
2528       P : Natural;     -- Current index;
2529
2530    begin
2531       Manual_Quote_Mode := False;
2532       Is_Unconditional_Msg := False;
2533       Msglen := 0;
2534       Flag_Source := Get_Source_File_Index (Flag);
2535       P := Text'First;
2536
2537       while P <= Text'Last loop
2538          C := Text (P);
2539          P := P + 1;
2540
2541          --  Check for insertion character or sequence
2542
2543          case C is
2544             when '%' =>
2545                if P <= Text'Last and then Text (P) = '%' then
2546                   P := P + 1;
2547                   Set_Msg_Insertion_Name_Literal;
2548                else
2549                   Set_Msg_Insertion_Name;
2550                end if;
2551
2552             when '$' =>
2553                if P <= Text'Last and then Text (P) = '$' then
2554                   P := P + 1;
2555                   Set_Msg_Insertion_Unit_Name (Suffix => False);
2556
2557                else
2558                   Set_Msg_Insertion_Unit_Name;
2559                end if;
2560
2561             when '{' =>
2562                Set_Msg_Insertion_File_Name;
2563
2564             when '}' =>
2565                Set_Msg_Insertion_Type_Reference (Flag);
2566
2567             when '*' =>
2568                Set_Msg_Insertion_Reserved_Name;
2569
2570             when '&' =>
2571                Set_Msg_Insertion_Node;
2572
2573             when '#' =>
2574                Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
2575
2576             when '\' =>
2577                Continuation := True;
2578
2579                if Text (P) = '\' then
2580                   Continuation_New_Line := True;
2581                   P := P + 1;
2582                end if;
2583
2584             when '@' =>
2585                Set_Msg_Insertion_Column;
2586
2587             when '>' =>
2588                Set_Msg_Insertion_Run_Time_Name;
2589
2590             when '^' =>
2591                Set_Msg_Insertion_Uint;
2592
2593             when '`' =>
2594                Manual_Quote_Mode := not Manual_Quote_Mode;
2595                Set_Msg_Char ('"');
2596
2597             when '!' =>
2598                Is_Unconditional_Msg := True;
2599
2600             when '?' =>
2601                null; -- already dealt with
2602
2603             when '<' =>
2604                null; -- already dealt with
2605
2606             when '|' =>
2607                null; -- already dealt with
2608
2609             when ''' =>
2610                Set_Msg_Char (Text (P));
2611                P := P + 1;
2612
2613             when '~' =>
2614                Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
2615
2616             --  Upper case letter
2617
2618             when 'A' .. 'Z' =>
2619
2620                --  Start of reserved word if two or more
2621
2622                if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
2623                   P := P - 1;
2624                   Set_Msg_Insertion_Reserved_Word (Text, P);
2625
2626                --  Single upper case letter is just inserted
2627
2628                else
2629                   Set_Msg_Char (C);
2630                end if;
2631
2632             --  Normal character with no special treatment
2633
2634             when others =>
2635                Set_Msg_Char (C);
2636          end case;
2637       end loop;
2638
2639       VMS_Convert;
2640    end Set_Msg_Text;
2641
2642    ----------------
2643    -- Set_Posted --
2644    ----------------
2645
2646    procedure Set_Posted (N : Node_Id) is
2647       P : Node_Id;
2648
2649    begin
2650       if Is_Serious_Error then
2651
2652          --  We always set Error_Posted on the node itself
2653
2654          Set_Error_Posted (N);
2655
2656          --  If it is a subexpression, then set Error_Posted on parents
2657          --  up to and including the first non-subexpression construct. This
2658          --  helps avoid cascaded error messages within a single expression.
2659
2660          P := N;
2661          loop
2662             P := Parent (P);
2663             exit when No (P);
2664             Set_Error_Posted (P);
2665             exit when Nkind (P) not in N_Subexpr;
2666          end loop;
2667
2668          --  A special check, if we just posted an error on an attribute
2669          --  definition clause, then also set the entity involved as posted.
2670          --  For example, this stops complaining about the alignment after
2671          --  complaining about the size, which is likely to be useless.
2672
2673          if Nkind (P) = N_Attribute_Definition_Clause then
2674             if Is_Entity_Name (Name (P)) then
2675                Set_Error_Posted (Entity (Name (P)));
2676             end if;
2677          end if;
2678       end if;
2679    end Set_Posted;
2680
2681    -----------------------
2682    -- Set_Qualification --
2683    -----------------------
2684
2685    procedure Set_Qualification (N : Nat; E : Entity_Id) is
2686    begin
2687       if N /= 0 and then Scope (E) /= Standard_Standard then
2688          Set_Qualification (N - 1, Scope (E));
2689          Set_Msg_Node (Scope (E));
2690          Set_Msg_Char ('.');
2691       end if;
2692    end Set_Qualification;
2693
2694    ------------------------
2695    -- Special_Msg_Delete --
2696    ------------------------
2697
2698    function Special_Msg_Delete
2699      (Msg : String;
2700       N   : Node_Or_Entity_Id;
2701       E   : Node_Or_Entity_Id) return Boolean
2702    is
2703    begin
2704       --  Never delete messages in -gnatdO mode
2705
2706       if Debug_Flag_OO then
2707          return False;
2708
2709       --  When an atomic object refers to a non-atomic type in the same
2710       --  scope, we implicitly make the type atomic. In the non-error
2711       --  case this is surely safe (and in fact prevents an error from
2712       --  occurring if the type is not atomic by default). But if the
2713       --  object cannot be made atomic, then we introduce an extra junk
2714       --  message by this manipulation, which we get rid of here.
2715
2716       --  We identify this case by the fact that it references a type for
2717       --  which Is_Atomic is set, but there is no Atomic pragma setting it.
2718
2719       elsif Msg = "atomic access to & cannot be guaranteed"
2720         and then Is_Type (E)
2721         and then Is_Atomic (E)
2722         and then No (Get_Rep_Pragma (E, Name_Atomic))
2723       then
2724          return True;
2725
2726       --  When a size is wrong for a frozen type there is no explicit
2727       --  size clause, and other errors have occurred, suppress the
2728       --  message, since it is likely that this size error is a cascaded
2729       --  result of other errors. The reason we eliminate unfrozen types
2730       --  is that messages issued before the freeze type are for sure OK.
2731
2732       elsif Msg = "size for& too small, minimum allowed is ^"
2733         and then Is_Frozen (E)
2734         and then Serious_Errors_Detected > 0
2735         and then Nkind (N) /= N_Component_Clause
2736         and then Nkind (Parent (N)) /= N_Component_Clause
2737         and then
2738           No (Get_Attribute_Definition_Clause (E, Attribute_Size))
2739         and then
2740           No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
2741         and then
2742           No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
2743       then
2744          return True;
2745
2746       --  All special tests complete, so go ahead with message
2747
2748       else
2749          return False;
2750       end if;
2751    end Special_Msg_Delete;
2752
2753    --------------------------
2754    -- Unwind_Internal_Type --
2755    --------------------------
2756
2757    procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
2758       Derived : Boolean := False;
2759       Mchar   : Character;
2760       Old_Ent : Entity_Id;
2761
2762    begin
2763       --  Undo placement of a quote, since we will put it back later
2764
2765       Mchar := Msg_Buffer (Msglen);
2766
2767       if Mchar = '"' then
2768          Msglen := Msglen - 1;
2769       end if;
2770
2771       --  The loop here deals with recursive types, we are trying to
2772       --  find a related entity that is not an implicit type. Note
2773       --  that the check with Old_Ent stops us from getting "stuck".
2774       --  Also, we don't output the "type derived from" message more
2775       --  than once in the case where we climb up multiple levels.
2776
2777       loop
2778          Old_Ent := Ent;
2779
2780          --  Implicit access type, use directly designated type
2781          --  In Ada 2005, the designated type may be an anonymous access to
2782          --  subprogram, in which case we can only point to its definition.
2783
2784          if Is_Access_Type (Ent) then
2785             if Ekind (Ent) = E_Access_Subprogram_Type
2786               or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
2787               or else Is_Access_Protected_Subprogram_Type (Ent)
2788             then
2789                Ent := Directly_Designated_Type (Ent);
2790
2791                if not Comes_From_Source (Ent) then
2792                   if Buffer_Ends_With ("type ") then
2793                      Buffer_Remove ("type ");
2794                   end if;
2795
2796                   Set_Msg_Str ("access to subprogram with profile ");
2797
2798                elsif Ekind (Ent) = E_Function then
2799                   Set_Msg_Str ("access to function ");
2800                else
2801                   Set_Msg_Str ("access to procedure ");
2802                end if;
2803                exit;
2804
2805             --  Type is access to object, named or anonymous
2806
2807             else
2808                Set_Msg_Str ("access to ");
2809                Ent := Directly_Designated_Type (Ent);
2810             end if;
2811
2812          --  Classwide type
2813
2814          elsif Is_Class_Wide_Type (Ent) then
2815             Class_Flag := True;
2816             Ent := Root_Type (Ent);
2817
2818          --  Use base type if this is a subtype
2819
2820          elsif Ent /= Base_Type (Ent) then
2821             Buffer_Remove ("type ");
2822
2823             --  Avoid duplication "subtype of subtype of", and also replace
2824             --  "derived from subtype of" simply by "derived from"
2825
2826             if not Buffer_Ends_With ("subtype of ")
2827               and then not Buffer_Ends_With ("derived from ")
2828             then
2829                Set_Msg_Str ("subtype of ");
2830             end if;
2831
2832             Ent := Base_Type (Ent);
2833
2834          --  If this is a base type with a first named subtype, use the
2835          --  first named subtype instead. This is not quite accurate in
2836          --  all cases, but it makes too much noise to be accurate and
2837          --  add 'Base in all cases. Note that we only do this is the
2838          --  first named subtype is not itself an internal name. This
2839          --  avoids the obvious loop (subtype->basetype->subtype) which
2840          --  would otherwise occur!)
2841
2842          elsif Present (Freeze_Node (Ent))
2843            and then Present (First_Subtype_Link (Freeze_Node (Ent)))
2844            and then
2845              not Is_Internal_Name
2846                    (Chars (First_Subtype_Link (Freeze_Node (Ent))))
2847          then
2848             Ent := First_Subtype_Link (Freeze_Node (Ent));
2849
2850          --  Otherwise use root type
2851
2852          else
2853             if not Derived then
2854                Buffer_Remove ("type ");
2855
2856                --  Test for "subtype of type derived from" which seems
2857                --  excessive and is replaced by simply "type derived from"
2858
2859                Buffer_Remove ("subtype of");
2860
2861                --  Avoid duplication "type derived from type derived from"
2862
2863                if not Buffer_Ends_With ("type derived from ") then
2864                   Set_Msg_Str ("type derived from ");
2865                end if;
2866
2867                Derived := True;
2868             end if;
2869
2870             Ent := Etype (Ent);
2871          end if;
2872
2873          --  If we are stuck in a loop, get out and settle for the internal
2874          --  name after all. In this case we set to kill the message if it
2875          --  is not the first error message (we really try hard not to show
2876          --  the dirty laundry of the implementation to the poor user!)
2877
2878          if Ent = Old_Ent then
2879             Kill_Message := True;
2880             exit;
2881          end if;
2882
2883          --  Get out if we finally found a non-internal name to use
2884
2885          exit when not Is_Internal_Name (Chars (Ent));
2886       end loop;
2887
2888       if Mchar = '"' then
2889          Set_Msg_Char ('"');
2890       end if;
2891    end Unwind_Internal_Type;
2892
2893    -----------------
2894    -- VMS_Convert --
2895    -----------------
2896
2897    procedure VMS_Convert is
2898       P : Natural;
2899       L : Natural;
2900       N : Natural;
2901
2902    begin
2903       if not OpenVMS then
2904          return;
2905       end if;
2906
2907       P := Msg_Buffer'First;
2908       loop
2909          if P >= Msglen then
2910             return;
2911          end if;
2912
2913          if Msg_Buffer (P) = '-' then
2914             for G in Gnames'Range loop
2915                L := Gnames (G)'Length;
2916
2917                --  See if we have "-ggg switch", where ggg is Gnames entry
2918
2919                if P + L + 7 <= Msglen
2920                  and then Msg_Buffer (P + 1 .. P + L) = Gnames (G).all
2921                  and then Msg_Buffer (P + L + 1 .. P + L + 7) = " switch"
2922                then
2923                   --  Replace by "/vvv qualifier", where vvv is Vnames entry
2924
2925                   N := Vnames (G)'Length;
2926                   Msg_Buffer (P + N + 11 .. Msglen + N - L + 3) :=
2927                     Msg_Buffer (P + L + 8 .. Msglen);
2928                   Msg_Buffer (P) := '/';
2929                   Msg_Buffer (P + 1 .. P + N) := Vnames (G).all;
2930                   Msg_Buffer (P + N + 1 .. P + N + 10) := " qualifier";
2931                   P := P + N + 10;
2932                   Msglen := Msglen + N - L + 3;
2933                   exit;
2934                end if;
2935             end loop;
2936          end if;
2937
2938          P := P + 1;
2939       end loop;
2940    end VMS_Convert;
2941
2942 end Errout;