MATCH: Improve `A CMP 0 ? A : -A` set of patterns to use bitwise_equal_p.
[official-gcc.git] / gcc / ada / errout.adb
blobac6491cf2991da0a7e742a1398719914cdda252a
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-2023, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- 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.
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 Einfo.Entities; use Einfo.Entities;
38 with Einfo.Utils; use Einfo.Utils;
39 with Erroutc; use Erroutc;
40 with Gnatvsn; use Gnatvsn;
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 Sem_Aux; use Sem_Aux;
47 with Sinput; use Sinput;
48 with Sinfo; use Sinfo;
49 with Sinfo.Nodes; use Sinfo.Nodes;
50 with Sinfo.Utils; use Sinfo.Utils;
51 with Snames; use Snames;
52 with Stand; use Stand;
53 with Stringt; use Stringt;
54 with Stylesw; use Stylesw;
55 with System.OS_Lib;
56 with Uname; use Uname;
57 with Warnsw;
59 package body Errout is
61 Errors_Must_Be_Ignored : Boolean := False;
62 -- Set to True by procedure Set_Ignore_Errors (True), when calls to error
63 -- message procedures should be ignored (when parsing irrelevant text in
64 -- sources being preprocessed).
66 Finalize_Called : Boolean := False;
67 -- Set True if the Finalize routine has been called
69 Warn_On_Instance : Boolean;
70 -- Flag set true for warning message to be posted on instance
72 ------------------------------------
73 -- Table of Non-Instance Messages --
74 ------------------------------------
76 -- This table contains an entry for every error message processed by the
77 -- Error_Msg routine that is not posted on generic (or inlined) instance.
78 -- As explained in further detail in the Error_Msg procedure body, this
79 -- table is used to avoid posting redundant messages on instances.
81 type NIM_Record is record
82 Msg : String_Ptr;
83 Loc : Source_Ptr;
84 end record;
85 -- Type used to store text and location of one message
87 package Non_Instance_Msgs is new Table.Table (
88 Table_Component_Type => NIM_Record,
89 Table_Index_Type => Int,
90 Table_Low_Bound => 1,
91 Table_Initial => 100,
92 Table_Increment => 100,
93 Table_Name => "Non_Instance_Msgs");
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 procedure Error_Msg_Internal
100 (Msg : String;
101 Span : Source_Span;
102 Opan : Source_Span;
103 Msg_Cont : Boolean;
104 Node : Node_Id);
105 -- This is the low-level routine used to post messages after dealing with
106 -- the issue of messages placed on instantiations (which get broken up
107 -- into separate calls in Error_Msg). Span is the location on which the
108 -- flag will be placed in the output. In the case where the flag is on
109 -- the template, this points directly to the template, not to one of the
110 -- instantiation copies of the template. Opan is the original location
111 -- used to flag the error, and this may indeed point to an instantiation
112 -- copy. So typically we can see Opan pointing to the template location
113 -- in an instantiation copy when Span points to the source location of
114 -- the actual instantiation (i.e the line with the new). Msg_Cont is
115 -- set true if this is a continuation message. Node is the relevant
116 -- Node_Id for this message, to be used to compute the enclosing entity if
117 -- Opt.Include_Subprogram_In_Messages is set.
119 function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
120 -- Determines if warnings should be suppressed for the given node
122 function OK_Node (N : Node_Id) return Boolean;
123 -- Determines if a node is an OK node to place an error message on (return
124 -- True) or if the error message should be suppressed (return False). A
125 -- message is suppressed if the node already has an error posted on it,
126 -- or if it refers to an Etype that has an error posted on it, or if
127 -- it references an Entity that has an error posted on it.
129 procedure Output_JSON_Message (Error_Id : Error_Msg_Id);
130 -- Output error message Error_Id and any subsequent continuation message
131 -- using a JSON format similar to the one GCC uses when passed
132 -- -fdiagnostics-format=json.
134 procedure Output_Source_Line
135 (L : Physical_Line_Number;
136 Sfile : Source_File_Index;
137 Errs : Boolean);
138 -- Outputs text of source line L, in file S, together with preceding line
139 -- number, as described above for Output_Line_Number. The Errs parameter
140 -- indicates if there are errors attached to the line, which forces
141 -- listing on, even in the presence of pragma List (Off).
143 function Paren_Required (N : Node_Id) return Boolean;
144 -- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
145 -- around node N are required by the Ada syntax, e.g. when N is an
146 -- expression of a qualified expression.
148 procedure Set_Msg_Insertion_Column;
149 -- Handle column number insertion (@ insertion character)
151 procedure Set_Msg_Insertion_Node;
152 -- Handle node (name from node) insertion (& insertion character)
154 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
155 -- Handle type reference (right brace insertion character). Flag is the
156 -- location of the flag, which is provided for the internal call to
157 -- Set_Msg_Insertion_Line_Number,
159 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True);
160 -- Handle unit name insertion ($ insertion character). Depending on Boolean
161 -- parameter Suffix, (spec) or (body) is appended after the unit name.
163 procedure Set_Msg_Node (Node : Node_Id);
164 -- Add the sequence of characters for the name associated with the given
165 -- node to the current message. For N_Designator, N_Selected_Component,
166 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
167 -- included as well.
169 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
170 -- Add a sequence of characters to the current message. The characters may
171 -- be one of the special insertion characters (see documentation in spec).
172 -- Flag is the location at which the error is to be posted, which is used
173 -- to determine whether or not the # insertion needs a file name. The
174 -- variables Msg_Buffer are set on return Msglen.
176 procedure Set_Posted (N : Node_Id);
177 -- Sets the Error_Posted flag on the given node, and all its parents that
178 -- are subexpressions and then on the parent non-subexpression construct
179 -- that contains the original expression. If that parent is a named
180 -- association, the flag is further propagated to its parent. This is done
181 -- in order to guard against cascaded errors. Note that this call has an
182 -- effect for a serious error only.
184 procedure Set_Qualification (N : Nat; E : Entity_Id);
185 -- Outputs up to N levels of qualification for the given entity. For
186 -- example, the entity A.B.C.D will output B.C. if N = 2.
188 function Special_Msg_Delete
189 (Msg : String;
190 N : Node_Or_Entity_Id;
191 E : Node_Or_Entity_Id) return Boolean;
192 -- This function is called from Error_Msg_NEL, passing the message Msg,
193 -- node N on which the error is to be posted, and the entity or node E
194 -- to be used for an & insertion in the message if any. The job of this
195 -- procedure is to test for certain cascaded messages that we would like
196 -- to suppress. If the message is to be suppressed then we return True.
197 -- If the message should be generated (the normal case) False is returned.
199 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
200 -- This procedure is given an entity id for an internal type, i.e. a type
201 -- with an internal name. It unwinds the type to try to get to something
202 -- reasonably printable, generating prefixes like "subtype of", "access
203 -- to", etc along the way in the buffer. The value in Ent on return is the
204 -- final name to be printed. Hopefully this is not an internal name, but in
205 -- some internal name cases, it is an internal name, and has to be printed
206 -- anyway (although in this case the message has been killed if possible).
207 -- The global variable Class_Flag is set to True if the resulting entity
208 -- should have 'Class appended to its name (see Add_Class procedure), and
209 -- is otherwise unchanged.
211 function Warn_Insertion return String;
212 -- This is called for warning messages only (so Warning_Msg_Char is set)
213 -- and returns a corresponding string to use at the beginning of generated
214 -- auxiliary messages, such as "in instantiation at ...".
215 -- "?" returns "??"
216 -- " " returns "?"
217 -- other trimmed, prefixed and suffixed with "?".
219 -----------------------
220 -- Change_Error_Text --
221 -----------------------
223 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
224 Save_Next : Error_Msg_Id;
225 Err_Id : Error_Msg_Id := Error_Id;
227 begin
228 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr.Ptr);
229 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
231 -- If in immediate error message mode, output modified error message now
232 -- This is just a bit tricky, because we want to output just a single
233 -- message, and the messages we modified is already linked in. We solve
234 -- this by temporarily resetting its forward pointer to empty.
236 if Debug_Flag_OO then
237 Save_Next := Errors.Table (Error_Id).Next;
238 Errors.Table (Error_Id).Next := No_Error_Msg;
239 Write_Eol;
240 Output_Source_Line
241 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
242 Output_Error_Msgs (Err_Id);
243 Errors.Table (Error_Id).Next := Save_Next;
244 end if;
245 end Change_Error_Text;
247 ------------------------
248 -- Compilation_Errors --
249 ------------------------
251 function Compilation_Errors return Boolean is
252 begin
253 if not Finalize_Called then
254 raise Program_Error;
255 else
256 return Erroutc.Compilation_Errors;
257 end if;
258 end Compilation_Errors;
260 --------------------------------------
261 -- Delete_Warning_And_Continuations --
262 --------------------------------------
264 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
265 Id : Error_Msg_Id;
267 begin
268 pragma Assert (not Errors.Table (Msg).Msg_Cont);
270 Id := Msg;
271 loop
272 declare
273 M : Error_Msg_Object renames Errors.Table (Id);
275 begin
276 if not M.Deleted then
277 M.Deleted := True;
278 Warnings_Detected := Warnings_Detected - 1;
280 if M.Info then
281 Warning_Info_Messages := Warning_Info_Messages - 1;
282 end if;
284 if M.Warn_Err then
285 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
286 end if;
287 end if;
289 Id := M.Next;
290 exit when Id = No_Error_Msg;
291 exit when not Errors.Table (Id).Msg_Cont;
292 end;
293 end loop;
294 end Delete_Warning_And_Continuations;
296 ---------------
297 -- Error_Msg --
298 ---------------
300 -- Error_Msg posts a flag at the given location, except that if the
301 -- Flag_Location/Flag_Span points within a generic template and corresponds
302 -- to an instantiation of this generic template, then the actual message
303 -- will be posted on the generic instantiation, along with additional
304 -- messages referencing the generic declaration.
306 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
307 begin
308 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
309 end Error_Msg;
311 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
312 begin
313 Error_Msg (Msg, Flag_Span, Current_Node);
314 end Error_Msg;
316 procedure Error_Msg
317 (Msg : String;
318 Flag_Location : Source_Ptr;
319 Is_Compile_Time_Pragma : Boolean)
321 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
322 begin
323 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
324 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
325 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
326 end Error_Msg;
328 procedure Error_Msg
329 (Msg : String;
330 Flag_Location : Source_Ptr;
331 N : Node_Id)
333 begin
334 Error_Msg (Msg, To_Span (Flag_Location), N);
335 end Error_Msg;
337 procedure Error_Msg
338 (Msg : String;
339 Flag_Span : Source_Span;
340 N : Node_Id)
342 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
344 Sindex : Source_File_Index;
345 -- Source index for flag location
347 Orig_Loc : Source_Ptr;
348 -- Original location of Flag_Location (i.e. location in original
349 -- template in instantiation case, otherwise unchanged).
351 begin
352 -- Return if all errors are to be ignored
354 if Get_Ignore_Errors then
355 return;
356 end if;
358 -- If we already have messages, and we are trying to place a message at
359 -- No_Location, then just ignore the attempt since we assume that what
360 -- is happening is some cascaded junk. Note that this is safe in the
361 -- sense that proceeding will surely bomb. We will also bomb if the flag
362 -- location is No_Location and we don't have any messages so far, but
363 -- that is a real bug and a legitimate bomb, so we go ahead.
365 if Flag_Location = No_Location
366 and then Total_Errors_Detected > 0
367 then
368 return;
369 end if;
371 -- Start of processing for new message
373 Sindex := Get_Source_File_Index (Flag_Location);
374 Prescan_Message (Msg);
375 Orig_Loc := Original_Location (Flag_Location);
377 -- If the current location is in an instantiation, the issue arises of
378 -- whether to post the message on the template or the instantiation.
380 -- The way we decide is to see if we have posted the same message on
381 -- the template when we compiled the template (the template is always
382 -- compiled before any instantiations). For this purpose, we use a
383 -- separate table of messages. The reason we do this is twofold:
385 -- First, the messages can get changed by various processing
386 -- including the insertion of tokens etc, making it hard to
387 -- do the comparison.
389 -- Second, we will suppress a warning on a template if it is not in
390 -- the current extended source unit. That's reasonable and means we
391 -- don't want the warning on the instantiation here either, but it
392 -- does mean that the main error table would not in any case include
393 -- the message.
395 if Flag_Location = Orig_Loc then
396 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
397 Warn_On_Instance := False;
399 -- Here we have an instance message
401 else
402 -- Delete if debug flag off, and this message duplicates a message
403 -- already posted on the corresponding template
405 if not Debug_Flag_GG then
406 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
407 if Msg = Non_Instance_Msgs.Table (J).Msg.all
408 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
409 then
410 return;
411 end if;
412 end loop;
413 end if;
415 -- No duplicate, so error/warning will be posted on instance
417 Warn_On_Instance := Is_Warning_Msg;
418 end if;
420 -- Ignore warning message that is suppressed for this location. Note
421 -- that style checks are not considered warning messages for this
422 -- purpose.
424 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String
425 then
426 return;
428 -- For style messages, check too many messages so far
430 elsif Is_Style_Msg
431 and then Maximum_Messages /= 0
432 and then Warnings_Detected >= Maximum_Messages
433 then
434 return;
436 -- Suppress warnings inside a loop that is known to be null or is
437 -- probably null (i.e. when loop executes only if invalid values
438 -- present). In either case warnings in the loop are likely to be junk.
440 elsif Is_Warning_Msg and then Present (N) then
442 declare
443 P : Node_Id;
445 begin
446 P := Parent (N);
447 while Present (P) loop
448 if Nkind (P) = N_Loop_Statement
449 and then Suppress_Loop_Warnings (P)
450 then
451 return;
452 end if;
454 P := Parent (P);
455 end loop;
456 end;
457 end if;
459 -- The idea at this stage is that we have two kinds of messages
461 -- First, we have those messages that are to be placed as requested at
462 -- Flag_Location. This includes messages that have nothing to do with
463 -- generics, and also messages placed on generic templates that reflect
464 -- an error in the template itself. For such messages we simply call
465 -- Error_Msg_Internal to place the message in the requested location.
467 if Instantiation (Sindex) = No_Location then
468 Error_Msg_Internal (Msg, Flag_Span, Flag_Span, False, N);
469 return;
470 end if;
472 -- If we are trying to flag an error in an instantiation, we may have
473 -- a generic contract violation. What we generate in this case is:
475 -- instantiation error at ...
476 -- original error message
478 -- or
480 -- warning: in instantiation at ...
481 -- warning: original warning message
483 -- or
485 -- info: in instantiation at ...
486 -- info: original info message
488 -- All these messages are posted at the location of the top level
489 -- instantiation. If there are nested instantiations, then the
490 -- instantiation error message can be repeated, pointing to each
491 -- of the relevant instantiations.
493 -- Note: the instantiation mechanism is also shared for inlining of
494 -- subprogram bodies when front end inlining is done. In this case the
495 -- messages have the form:
497 -- in inlined body at ...
498 -- original error message
500 -- or
502 -- warning: in inlined body at ...
503 -- warning: original warning message
505 -- or
507 -- info: in inlined body at ...
508 -- info: original info message
510 -- OK, here we have an instantiation error, and we need to generate the
511 -- error on the instantiation, rather than on the template.
513 declare
514 Actual_Error_Loc : Source_Ptr;
515 -- Location of outer level instantiation in instantiation case, or
516 -- just a copy of Flag_Location in the normal case. This is the
517 -- location where all error messages will actually be posted.
519 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
520 -- Save possible location set for caller's message. We need to use
521 -- Error_Msg_Sloc for the location of the instantiation error but we
522 -- have to preserve a possible original value.
524 X : Source_File_Index;
526 Msg_Cont_Status : Boolean;
527 -- Used to label continuation lines in instantiation case with
528 -- proper Msg_Cont status.
530 begin
531 -- Loop to find highest level instantiation, where all error
532 -- messages will be placed.
534 X := Sindex;
535 loop
536 Actual_Error_Loc := Instantiation (X);
537 X := Get_Source_File_Index (Actual_Error_Loc);
538 exit when Instantiation (X) = No_Location;
539 end loop;
541 -- Since we are generating the messages at the instantiation point in
542 -- any case, we do not want the references to the bad lines in the
543 -- instance to be annotated with the location of the instantiation.
545 Suppress_Instance_Location := True;
546 Msg_Cont_Status := False;
548 -- Loop to generate instantiation messages
550 Error_Msg_Sloc := Flag_Location;
551 X := Get_Source_File_Index (Flag_Location);
552 while Instantiation (X) /= No_Location loop
554 -- Suppress instantiation message on continuation lines
556 if Msg (Msg'First) /= '\' then
558 -- Case of inlined body
560 if Inlined_Body (X) then
561 if Is_Info_Msg then
562 Error_Msg_Internal
563 (Msg => "info: in inlined body #",
564 Span => To_Span (Actual_Error_Loc),
565 Opan => Flag_Span,
566 Msg_Cont => Msg_Cont_Status,
567 Node => N);
569 elsif Is_Warning_Msg then
570 Error_Msg_Internal
571 (Msg => Warn_Insertion & "in inlined body #",
572 Span => To_Span (Actual_Error_Loc),
573 Opan => Flag_Span,
574 Msg_Cont => Msg_Cont_Status,
575 Node => N);
577 elsif Is_Style_Msg then
578 Error_Msg_Internal
579 (Msg => "style: in inlined body #",
580 Span => To_Span (Actual_Error_Loc),
581 Opan => Flag_Span,
582 Msg_Cont => Msg_Cont_Status,
583 Node => N);
585 else
586 Error_Msg_Internal
587 (Msg => "error in inlined body #",
588 Span => To_Span (Actual_Error_Loc),
589 Opan => Flag_Span,
590 Msg_Cont => Msg_Cont_Status,
591 Node => N);
592 end if;
594 -- Case of generic instantiation
596 else
597 if Is_Info_Msg then
598 Error_Msg_Internal
599 (Msg => "info: in instantiation #",
600 Span => To_Span (Actual_Error_Loc),
601 Opan => Flag_Span,
602 Msg_Cont => Msg_Cont_Status,
603 Node => N);
605 elsif Is_Warning_Msg then
606 Error_Msg_Internal
607 (Msg => Warn_Insertion & "in instantiation #",
608 Span => To_Span (Actual_Error_Loc),
609 Opan => Flag_Span,
610 Msg_Cont => Msg_Cont_Status,
611 Node => N);
613 elsif Is_Style_Msg then
614 Error_Msg_Internal
615 (Msg => "style: in instantiation #",
616 Span => To_Span (Actual_Error_Loc),
617 Opan => Flag_Span,
618 Msg_Cont => Msg_Cont_Status,
619 Node => N);
621 else
622 Error_Msg_Internal
623 (Msg => "instantiation error #",
624 Span => To_Span (Actual_Error_Loc),
625 Opan => Flag_Span,
626 Msg_Cont => Msg_Cont_Status,
627 Node => N);
628 end if;
629 end if;
630 end if;
632 Error_Msg_Sloc := Instantiation (X);
633 X := Get_Source_File_Index (Error_Msg_Sloc);
634 Msg_Cont_Status := True;
635 end loop;
637 Suppress_Instance_Location := False;
638 Error_Msg_Sloc := Save_Error_Msg_Sloc;
640 -- Here we output the original message on the outer instantiation
642 Error_Msg_Internal
643 (Msg => Msg,
644 Span => To_Span (Actual_Error_Loc),
645 Opan => Flag_Span,
646 Msg_Cont => Msg_Cont_Status,
647 Node => N);
648 end;
649 end Error_Msg;
651 ----------------------------------
652 -- Error_Msg_Ada_2005_Extension --
653 ----------------------------------
655 procedure Error_Msg_Ada_2005_Extension (Extension : String) is
656 Loc : constant Source_Ptr := Token_Ptr;
657 begin
658 if Ada_Version < Ada_2005 then
659 Error_Msg (Extension & " is an Ada 2005 extension", Loc);
661 if No (Ada_Version_Pragma) then
662 Error_Msg ("\unit must be compiled with -gnat05 switch", Loc);
663 else
664 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
665 Error_Msg ("\incompatible with Ada version set#", Loc);
666 end if;
667 end if;
668 end Error_Msg_Ada_2005_Extension;
670 --------------------------------
671 -- Error_Msg_Ada_2012_Feature --
672 --------------------------------
674 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
675 begin
676 if Ada_Version < Ada_2012 then
677 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
679 if No (Ada_Version_Pragma) then
680 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
681 else
682 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
683 Error_Msg ("\incompatible with Ada version set#", Loc);
684 end if;
685 end if;
686 end Error_Msg_Ada_2012_Feature;
688 --------------------------------
689 -- Error_Msg_Ada_2022_Feature --
690 --------------------------------
692 procedure Error_Msg_Ada_2022_Feature (Feature : String; Loc : Source_Ptr) is
693 begin
694 if Ada_Version < Ada_2022 then
695 Error_Msg (Feature & " is an Ada 2022 feature", Loc);
697 if No (Ada_Version_Pragma) then
698 Error_Msg ("\unit must be compiled with -gnat2022 switch", Loc);
699 else
700 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
701 Error_Msg ("\incompatible with Ada version set#", Loc);
702 end if;
703 end if;
704 end Error_Msg_Ada_2022_Feature;
706 ------------------
707 -- Error_Msg_AP --
708 ------------------
710 procedure Error_Msg_AP (Msg : String) is
711 S1 : Source_Ptr;
712 C : Character;
714 begin
715 -- If we had saved the Scan_Ptr value after scanning the previous
716 -- token, then we would have exactly the right place for putting
717 -- the flag immediately at hand. However, that would add at least
718 -- two instructions to a Scan call *just* to service the possibility
719 -- of an Error_Msg_AP call. So instead we reconstruct that value.
721 -- We have two possibilities, start with Prev_Token_Ptr and skip over
722 -- the current token, which is made harder by the possibility that this
723 -- token may be in error, or start with Token_Ptr and work backwards.
724 -- We used to take the second approach, but it's hard because of
725 -- comments, and harder still because things that look like comments
726 -- can appear inside strings. So now we take the first approach.
728 -- Note: in the case where there is no previous token, Prev_Token_Ptr
729 -- is set to Source_First, which is a reasonable position for the
730 -- error flag in this situation.
732 S1 := Prev_Token_Ptr;
733 C := Source (S1);
735 -- If the previous token is a string literal, we need a special approach
736 -- since there may be white space inside the literal and we don't want
737 -- to stop on that white space.
739 -- Note: since this is an error recovery issue anyway, it is not worth
740 -- worrying about special UTF_32 line terminator characters here.
742 if Prev_Token = Tok_String_Literal then
743 loop
744 S1 := S1 + 1;
746 if Source (S1) = C then
747 S1 := S1 + 1;
748 exit when Source (S1) /= C;
749 elsif Source (S1) in Line_Terminator then
750 exit;
751 end if;
752 end loop;
754 -- Character literal also needs special handling
756 elsif Prev_Token = Tok_Char_Literal then
757 S1 := S1 + 3;
759 -- Otherwise we search forward for the end of the current token, marked
760 -- by a line terminator, white space, a comment symbol or if we bump
761 -- into the following token (i.e. the current token).
763 -- Again, it is not worth worrying about UTF_32 special line terminator
764 -- characters in this context, since this is only for error recovery.
766 else
767 while Source (S1) not in Line_Terminator
768 and then Source (S1) /= ' '
769 and then Source (S1) /= ASCII.HT
770 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
771 and then S1 /= Token_Ptr
772 loop
773 S1 := S1 + 1;
774 end loop;
775 end if;
777 -- S1 is now set to the location for the flag
779 Error_Msg (Msg, S1);
780 end Error_Msg_AP;
782 ------------------
783 -- Error_Msg_BC --
784 ------------------
786 procedure Error_Msg_BC (Msg : String) is
787 begin
788 -- If we are at end of file, post the flag after the previous token
790 if Token = Tok_EOF then
791 Error_Msg_AP (Msg);
793 -- If we are at start of file, post the flag at the current token
795 elsif Token_Ptr = Source_First (Current_Source_File) then
796 Error_Msg_SC (Msg);
798 -- If the character before the current token is a space or a horizontal
799 -- tab, then we place the flag on this character (in the case of a tab
800 -- we would really like to place it in the "last" character of the tab
801 -- space, but that it too much trouble to worry about).
803 elsif Source (Token_Ptr - 1) = ' '
804 or else Source (Token_Ptr - 1) = ASCII.HT
805 then
806 Error_Msg (Msg, Token_Ptr - 1);
808 -- If there is no space or tab before the current token, then there is
809 -- no room to place the flag before the token, so we place it on the
810 -- token instead (this happens for example at the start of a line).
812 else
813 Error_Msg (Msg, Token_Ptr);
814 end if;
815 end Error_Msg_BC;
817 -------------------
818 -- Error_Msg_CRT --
819 -------------------
821 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
822 begin
823 if No_Run_Time_Mode then
824 Error_Msg_N ('|' & Feature & " not allowed in no run time mode", N);
826 else pragma Assert (Configurable_Run_Time_Mode);
827 Error_Msg_N ('|' & Feature & " not supported by configuration>", N);
828 end if;
830 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
831 end Error_Msg_CRT;
833 ------------------
834 -- Error_Msg_PT --
835 ------------------
837 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
838 begin
839 Error_Msg_N
840 ("illegal overriding of subprogram inherited from interface", E);
842 Error_Msg_Sloc := Sloc (Iface_Prim);
844 if Ekind (E) = E_Function then
845 Error_Msg_N
846 ("\first formal of & declared # must be of mode `IN` "
847 & "or access-to-constant", E);
848 else
849 Error_Msg_N
850 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
851 & "or access-to-variable", E);
852 end if;
853 end Error_Msg_PT;
855 -----------------
856 -- Error_Msg_F --
857 -----------------
859 procedure Error_Msg_F (Msg : String; N : Node_Id) is
860 Fst, Lst : Node_Id;
861 begin
862 First_And_Last_Nodes (N, Fst, Lst);
863 Error_Msg_NEL (Msg, N, N,
864 To_Span (Ptr => Sloc (Fst),
865 First => First_Sloc (Fst),
866 Last => Last_Sloc (Lst)));
867 end Error_Msg_F;
869 ------------------
870 -- Error_Msg_FE --
871 ------------------
873 procedure Error_Msg_FE
874 (Msg : String;
875 N : Node_Id;
876 E : Node_Or_Entity_Id)
878 Fst, Lst : Node_Id;
879 begin
880 First_And_Last_Nodes (N, Fst, Lst);
881 Error_Msg_NEL (Msg, N, E,
882 To_Span (Ptr => Sloc (Fst),
883 First => First_Sloc (Fst),
884 Last => Last_Sloc (Lst)));
885 end Error_Msg_FE;
887 ------------------------------
888 -- Error_Msg_GNAT_Extension --
889 ------------------------------
891 procedure Error_Msg_GNAT_Extension
892 (Extension : String;
893 Loc : Source_Ptr;
894 Is_Core_Extension : Boolean := False)
896 begin
897 if (if Is_Core_Extension
898 then Core_Extensions_Allowed
899 else All_Extensions_Allowed)
900 then
901 return;
902 end if;
904 Error_Msg (Extension & " is a 'G'N'A'T-specific extension", Loc);
906 if No (Ada_Version_Pragma) then
907 if Is_Core_Extension then
908 Error_Msg
909 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
910 "or use pragma Extensions_Allowed (On) '[or All']", Loc);
911 else
912 Error_Msg
913 ("\unit must be compiled with -gnatX0 " &
914 "or use pragma Extensions_Allowed (All)", Loc);
915 end if;
916 else
917 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
918 Error_Msg ("\incompatible with Ada version set#", Loc);
919 if Is_Core_Extension then
920 Error_Msg
921 ("\must use pragma Extensions_Allowed (On) '[or All']", Loc);
922 else
923 Error_Msg
924 ("\must use pragma Extensions_Allowed (All)", Loc);
925 end if;
926 end if;
927 end Error_Msg_GNAT_Extension;
929 ------------------------
930 -- Error_Msg_Internal --
931 ------------------------
933 procedure Error_Msg_Internal
934 (Msg : String;
935 Span : Source_Span;
936 Opan : Source_Span;
937 Msg_Cont : Boolean;
938 Node : Node_Id)
940 Sptr : constant Source_Ptr := Span.Ptr;
941 Optr : constant Source_Ptr := Opan.Ptr;
943 Next_Msg : Error_Msg_Id;
944 -- Pointer to next message at insertion point
946 Prev_Msg : Error_Msg_Id;
947 -- Pointer to previous message at insertion point
949 Temp_Msg : Error_Msg_Id;
951 Warn_Err : Boolean;
952 -- Set if warning to be treated as error
954 procedure Handle_Serious_Error;
955 -- Internal procedure to do all error message handling for a serious
956 -- error message, other than bumping the error counts and arranging
957 -- for the message to be output.
959 --------------------------
960 -- Handle_Serious_Error --
961 --------------------------
963 procedure Handle_Serious_Error is
964 begin
965 -- Turn off code generation if not done already
967 if Operating_Mode = Generate_Code then
968 Operating_Mode := Check_Semantics;
969 Expander_Active := False;
970 end if;
972 -- Set the fatal error flag in the unit table unless we are in
973 -- Try_Semantics mode (in which case we set ignored mode if not
974 -- currently set. This stops the semantics from being performed
975 -- if we find a serious error. This is skipped if we are currently
976 -- dealing with the configuration pragma file.
978 if Current_Source_Unit /= No_Unit then
979 declare
980 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
981 begin
982 if Try_Semantics then
983 if Fatal_Error (U) = None then
984 Set_Fatal_Error (U, Error_Ignored);
985 end if;
986 else
987 Set_Fatal_Error (U, Error_Detected);
988 end if;
989 end;
990 end if;
992 -- Disable warnings on unused use clauses and the like. Otherwise, an
993 -- error might hide a reference to an entity in a used package, so
994 -- after fixing the error, the use clause no longer looks like it was
995 -- unused.
997 Warnsw.Check_Unreferenced := False;
998 Warnsw.Check_Unreferenced_Formals := False;
999 end Handle_Serious_Error;
1001 -- Start of processing for Error_Msg_Internal
1003 begin
1004 -- Detect common mistake of prefixing or suffixing the message with a
1005 -- space character.
1007 pragma Assert (Msg (Msg'First) /= ' ' and then Msg (Msg'Last) /= ' ');
1009 if Raise_Exception_On_Error /= 0 then
1010 raise Error_Msg_Exception;
1011 end if;
1013 Continuation := Msg_Cont;
1014 Continuation_New_Line := False;
1015 Suppress_Message := False;
1016 Kill_Message := False;
1017 Set_Msg_Text (Msg, Sptr);
1019 -- Kill continuation if parent message killed
1021 if Continuation and Last_Killed then
1022 return;
1023 end if;
1025 -- Return without doing anything if message is suppressed
1027 if Suppress_Message
1028 and then not All_Errors_Mode
1029 and then not Is_Warning_Msg
1030 and then not Is_Unconditional_Msg
1031 then
1032 if not Continuation then
1033 Last_Killed := True;
1034 end if;
1036 return;
1037 end if;
1039 -- Return without doing anything if message is killed and this is not
1040 -- the first error message. The philosophy is that if we get a weird
1041 -- error message and we already have had a message, then we hope the
1042 -- weird message is a junk cascaded message
1044 if Kill_Message
1045 and then not All_Errors_Mode
1046 and then Total_Errors_Detected /= 0
1047 then
1048 if not Continuation then
1049 Last_Killed := True;
1050 end if;
1052 return;
1053 end if;
1055 -- Special check for warning message to see if it should be output
1057 if Is_Warning_Msg then
1059 -- Immediate return if warning message and warnings are suppressed
1061 if Warnings_Suppressed (Optr) /= No_String
1062 or else
1063 Warnings_Suppressed (Sptr) /= No_String
1064 then
1065 Cur_Msg := No_Error_Msg;
1066 return;
1067 end if;
1069 -- If the flag location is in the main extended source unit then for
1070 -- sure we want the warning since it definitely belongs
1072 if In_Extended_Main_Source_Unit (Sptr) then
1073 null;
1075 -- If the main unit has not been read yet. The warning must be on
1076 -- a configuration file: gnat.adc or user-defined. This means we
1077 -- are not parsing the main unit yet, so skip following checks.
1079 elsif No (Cunit (Main_Unit)) then
1080 null;
1082 -- If the flag location is not in the extended main source unit, then
1083 -- we want to eliminate the warning, unless it is in the extended
1084 -- main code unit and we want warnings on the instance.
1086 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
1087 null;
1089 -- Keep warning if debug flag G set
1091 elsif Debug_Flag_GG then
1092 null;
1094 -- Keep warning if message text contains !!
1096 elsif Has_Double_Exclam then
1097 null;
1099 -- Here is where we delete a warning from a with'ed unit
1101 else
1102 Cur_Msg := No_Error_Msg;
1104 if not Continuation then
1105 Last_Killed := True;
1106 end if;
1108 return;
1109 end if;
1110 end if;
1112 -- If message is to be ignored in special ignore message mode, this is
1113 -- where we do this special processing, bypassing message output.
1115 if Ignore_Errors_Enable > 0 then
1116 if Is_Serious_Error then
1117 Handle_Serious_Error;
1118 end if;
1120 return;
1121 end if;
1123 -- If error message line length set, and this is a continuation message
1124 -- then all we do is to append the text to the text of the last message
1125 -- with a comma space separator (eliminating a possible (style) or
1126 -- info prefix).
1128 if Error_Msg_Line_Length /= 0 and then Continuation then
1129 Cur_Msg := Errors.Last;
1131 declare
1132 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
1133 Newm : String (1 .. Oldm'Last + 2 + Msglen);
1134 Newl : Natural;
1135 M : Natural;
1137 begin
1138 -- First copy old message to new one and free it
1140 Newm (Oldm'Range) := Oldm.all;
1141 Newl := Oldm'Length;
1142 Free (Oldm);
1144 -- Remove (style) or info: at start of message
1146 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
1147 M := 9;
1149 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
1150 M := 7;
1152 else
1153 M := 1;
1154 end if;
1156 -- Now deal with separation between messages. Normally this is
1157 -- simply comma space, but there are some special cases.
1159 -- If continuation new line, then put actual NL character in msg
1161 if Continuation_New_Line then
1162 Newl := Newl + 1;
1163 Newm (Newl) := ASCII.LF;
1165 -- If continuation message is enclosed in parentheses, then
1166 -- special treatment (don't need a comma, and we want to combine
1167 -- successive parenthetical remarks into a single one with
1168 -- separating commas).
1170 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
1172 -- Case where existing message ends in right paren, remove
1173 -- and separate parenthetical remarks with a comma.
1175 if Newm (Newl) = ')' then
1176 Newm (Newl) := ',';
1177 Msg_Buffer (M) := ' ';
1179 -- Case where we are adding new parenthetical comment
1181 else
1182 Newl := Newl + 1;
1183 Newm (Newl) := ' ';
1184 end if;
1186 -- Case where continuation not in parens and no new line
1188 else
1189 Newm (Newl + 1 .. Newl + 2) := ", ";
1190 Newl := Newl + 2;
1191 end if;
1193 -- Append new message
1195 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1196 Msg_Buffer (M .. Msglen);
1197 Newl := Newl + Msglen - M + 1;
1198 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1200 -- Update warning msg flag and message doc char if needed
1202 if Is_Warning_Msg then
1203 if not Errors.Table (Cur_Msg).Warn then
1204 Errors.Table (Cur_Msg).Warn := True;
1205 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1207 elsif Warning_Msg_Char /= " " then
1208 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1209 end if;
1210 end if;
1211 end;
1213 return;
1214 end if;
1216 -- Here we build a new error object
1218 Errors.Append
1219 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1220 Next => No_Error_Msg,
1221 Prev => No_Error_Msg,
1222 Sptr => Span,
1223 Optr => Opan,
1224 Insertion_Sloc => (if Has_Insertion_Line then Error_Msg_Sloc
1225 else No_Location),
1226 Sfile => Get_Source_File_Index (Sptr),
1227 Line => Get_Physical_Line_Number (Sptr),
1228 Col => Get_Column_Number (Sptr),
1229 Compile_Time_Pragma => Is_Compile_Time_Msg,
1230 Warn => Is_Warning_Msg,
1231 Info => Is_Info_Msg,
1232 Check => Is_Check_Msg,
1233 Warn_Err => False, -- reset below
1234 Warn_Chr => Warning_Msg_Char,
1235 Warn_Runtime_Raise => Is_Runtime_Raise,
1236 Style => Is_Style_Msg,
1237 Serious => Is_Serious_Error,
1238 Uncond => Is_Unconditional_Msg,
1239 Msg_Cont => Continuation,
1240 Deleted => False,
1241 Node => Node));
1242 Cur_Msg := Errors.Last;
1244 -- Test if warning to be treated as error
1246 Warn_Err :=
1247 (Is_Warning_Msg or Is_Style_Msg)
1248 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1249 or else
1250 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
1252 -- Propagate Warn_Err to this message and preceding continuations.
1253 -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
1254 -- current continued message could have been escalated from warning to
1255 -- error.
1257 for J in reverse 1 .. Errors.Last loop
1258 Errors.Table (J).Warn_Err := Warn_Err;
1259 Errors.Table (J).Warn := Is_Warning_Msg;
1260 Errors.Table (J).Warn_Runtime_Raise := Is_Runtime_Raise;
1261 exit when not Errors.Table (J).Msg_Cont;
1262 end loop;
1264 -- If immediate errors mode set, output error message now. Also output
1265 -- now if the -d1 debug flag is set (so node number message comes out
1266 -- just before actual error message)
1268 if Debug_Flag_OO or else Debug_Flag_1 then
1269 Write_Eol;
1270 Output_Source_Line
1271 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1272 Temp_Msg := Cur_Msg;
1273 Output_Error_Msgs (Temp_Msg);
1275 -- If not in immediate errors mode, then we insert the message in the
1276 -- error chain for later output by Finalize. The messages are sorted
1277 -- first by unit (main unit comes first), and within a unit by source
1278 -- location (earlier flag location first in the chain).
1280 else
1281 -- First a quick check, does this belong at the very end of the chain
1282 -- of error messages. This saves a lot of time in the normal case if
1283 -- there are lots of messages.
1285 if Last_Error_Msg /= No_Error_Msg
1286 and then Errors.Table (Cur_Msg).Sfile =
1287 Errors.Table (Last_Error_Msg).Sfile
1288 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr.Ptr
1289 or else
1290 (Sptr = Errors.Table (Last_Error_Msg).Sptr.Ptr
1291 and then
1292 Optr > Errors.Table (Last_Error_Msg).Optr.Ptr))
1293 then
1294 Prev_Msg := Last_Error_Msg;
1295 Next_Msg := No_Error_Msg;
1297 -- Otherwise do a full sequential search for the insertion point
1299 else
1300 Prev_Msg := No_Error_Msg;
1301 Next_Msg := First_Error_Msg;
1302 while Next_Msg /= No_Error_Msg loop
1303 exit when
1304 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1306 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1307 then
1308 exit when Sptr < Errors.Table (Next_Msg).Sptr.Ptr
1309 or else (Sptr = Errors.Table (Next_Msg).Sptr.Ptr
1310 and then
1311 Optr < Errors.Table (Next_Msg).Optr.Ptr);
1312 end if;
1314 Prev_Msg := Next_Msg;
1315 Next_Msg := Errors.Table (Next_Msg).Next;
1316 end loop;
1317 end if;
1319 -- Now we insert the new message in the error chain.
1321 -- The possible insertion point for the new message is after Prev_Msg
1322 -- and before Next_Msg. However, this is where we do a special check
1323 -- for redundant parsing messages, defined as messages posted on the
1324 -- same line. The idea here is that probably such messages are junk
1325 -- from the parser recovering. In full errors mode, we don't do this
1326 -- deletion, but otherwise such messages are discarded at this stage.
1328 if Prev_Msg /= No_Error_Msg
1329 and then Errors.Table (Prev_Msg).Line =
1330 Errors.Table (Cur_Msg).Line
1331 and then Errors.Table (Prev_Msg).Sfile =
1332 Errors.Table (Cur_Msg).Sfile
1333 and then Compiler_State = Parsing
1334 and then not All_Errors_Mode
1335 then
1336 -- Don't delete unconditional messages and at this stage, don't
1337 -- delete continuation lines; we attempted to delete those earlier
1338 -- if the parent message was deleted.
1340 if not Errors.Table (Cur_Msg).Uncond
1341 and then not Continuation
1342 then
1343 -- Don't delete if prev msg is warning and new msg is an error.
1344 -- This is because we don't want a real error masked by a
1345 -- warning. In all other cases (that is parse errors for the
1346 -- same line that are not unconditional) we do delete the
1347 -- message. This helps to avoid junk extra messages from
1348 -- cascaded parsing errors
1350 if not (Errors.Table (Prev_Msg).Warn
1351 or else
1352 Errors.Table (Prev_Msg).Style)
1353 or else
1354 (Errors.Table (Cur_Msg).Warn
1355 or else
1356 Errors.Table (Cur_Msg).Style)
1357 then
1358 -- All tests passed, delete the message by simply returning
1359 -- without any further processing.
1361 pragma Assert (not Continuation);
1363 Last_Killed := True;
1364 return;
1365 end if;
1366 end if;
1367 end if;
1369 -- Come here if message is to be inserted in the error chain
1371 if not Continuation then
1372 Last_Killed := False;
1373 end if;
1375 if Prev_Msg = No_Error_Msg then
1376 First_Error_Msg := Cur_Msg;
1377 else
1378 Errors.Table (Prev_Msg).Next := Cur_Msg;
1379 end if;
1381 Errors.Table (Cur_Msg).Next := Next_Msg;
1383 if Next_Msg = No_Error_Msg then
1384 Last_Error_Msg := Cur_Msg;
1385 end if;
1386 end if;
1388 -- Bump appropriate statistics counts
1390 if Errors.Table (Cur_Msg).Info then
1392 -- Could be (usually is) both "info" and "warning"
1394 if Errors.Table (Cur_Msg).Warn then
1395 Warning_Info_Messages := Warning_Info_Messages + 1;
1396 Warnings_Detected := Warnings_Detected + 1;
1397 else
1398 Report_Info_Messages := Report_Info_Messages + 1;
1399 end if;
1401 elsif Errors.Table (Cur_Msg).Warn
1402 or else Errors.Table (Cur_Msg).Style
1403 then
1404 Warnings_Detected := Warnings_Detected + 1;
1406 elsif Errors.Table (Cur_Msg).Check then
1407 Check_Messages := Check_Messages + 1;
1409 else
1410 Total_Errors_Detected := Total_Errors_Detected + 1;
1412 if Errors.Table (Cur_Msg).Serious then
1413 Serious_Errors_Detected := Serious_Errors_Detected + 1;
1414 Handle_Serious_Error;
1416 -- If not serious error, set Fatal_Error to indicate ignored error
1418 else
1419 declare
1420 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1421 begin
1422 if Fatal_Error (U) = None then
1423 Set_Fatal_Error (U, Error_Ignored);
1424 end if;
1425 end;
1426 end if;
1427 end if;
1429 -- Record warning message issued
1431 if Errors.Table (Cur_Msg).Warn
1432 and then not Errors.Table (Cur_Msg).Msg_Cont
1433 then
1434 Warning_Msg := Cur_Msg;
1435 end if;
1437 -- If too many warnings turn off warnings
1439 if Maximum_Messages /= 0 then
1440 if Warnings_Detected = Maximum_Messages then
1441 Warning_Mode := Suppress;
1442 end if;
1444 -- If too many errors abandon compilation
1446 if Total_Errors_Detected = Maximum_Messages then
1447 raise Unrecoverable_Error;
1448 end if;
1449 end if;
1451 if Has_Error_Code then
1452 declare
1453 Msg : constant String :=
1454 "\launch ""gnatprove --explain=[]"" for more information";
1455 begin
1456 Has_Double_Exclam := False;
1457 Has_Error_Code := False;
1458 Has_Insertion_Line := False;
1460 Error_Msg_Internal
1461 (Msg => Msg,
1462 Span => Span,
1463 Opan => Opan,
1464 Msg_Cont => True,
1465 Node => Node);
1466 end;
1467 end if;
1468 end Error_Msg_Internal;
1470 -----------------
1471 -- Error_Msg_N --
1472 -----------------
1474 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1475 Fst, Lst : Node_Id;
1476 begin
1477 First_And_Last_Nodes (N, Fst, Lst);
1478 Error_Msg_NEL (Msg, N, N,
1479 To_Span (Ptr => Sloc (N),
1480 First => First_Sloc (Fst),
1481 Last => Last_Sloc (Lst)));
1482 end Error_Msg_N;
1484 ------------------
1485 -- Error_Msg_NE --
1486 ------------------
1488 procedure Error_Msg_NE
1489 (Msg : String;
1490 N : Node_Or_Entity_Id;
1491 E : Node_Or_Entity_Id)
1493 Fst, Lst : Node_Id;
1494 begin
1495 First_And_Last_Nodes (N, Fst, Lst);
1496 Error_Msg_NEL (Msg, N, E,
1497 To_Span (Ptr => Sloc (N),
1498 First => First_Sloc (Fst),
1499 Last => Last_Sloc (Lst)));
1500 end Error_Msg_NE;
1502 -------------------
1503 -- Error_Msg_NEL --
1504 -------------------
1506 procedure Error_Msg_NEL
1507 (Msg : String;
1508 N : Node_Or_Entity_Id;
1509 E : Node_Or_Entity_Id;
1510 Flag_Location : Source_Ptr)
1512 Fst, Lst : Node_Id;
1513 begin
1514 First_And_Last_Nodes (N, Fst, Lst);
1515 Error_Msg_NEL
1516 (Msg, N, E,
1517 To_Span (Ptr => Flag_Location,
1518 First => Source_Ptr'Min (Flag_Location, First_Sloc (Fst)),
1519 Last => Source_Ptr'Max (Flag_Location, Last_Sloc (Lst))));
1520 end Error_Msg_NEL;
1522 procedure Error_Msg_NEL
1523 (Msg : String;
1524 N : Node_Or_Entity_Id;
1525 E : Node_Or_Entity_Id;
1526 Flag_Span : Source_Span)
1528 begin
1529 if Special_Msg_Delete (Msg, N, E) then
1530 return;
1531 end if;
1533 Prescan_Message (Msg);
1535 -- Special handling for warning messages
1537 if Is_Warning_Msg then
1539 -- Suppress if no warnings set for either entity or node
1541 if No_Warnings (N) or else No_Warnings (E) then
1543 -- Disable any continuation messages as well
1545 Last_Killed := True;
1546 return;
1547 end if;
1548 end if;
1550 -- Test for message to be output
1552 if All_Errors_Mode
1553 or else Is_Unconditional_Msg
1554 or else Is_Warning_Msg
1555 or else OK_Node (N)
1556 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1557 then
1558 Debug_Output (N);
1559 Error_Msg_Node_1 := E;
1560 Error_Msg (Msg, Flag_Span, N);
1562 else
1563 Last_Killed := True;
1564 end if;
1566 if not Get_Ignore_Errors then
1567 Set_Posted (N);
1568 end if;
1569 end Error_Msg_NEL;
1571 ------------------
1572 -- Error_Msg_NW --
1573 ------------------
1575 procedure Error_Msg_NW
1576 (Eflag : Boolean;
1577 Msg : String;
1578 N : Node_Or_Entity_Id)
1580 Fst, Lst : Node_Id;
1581 begin
1582 if Eflag
1583 and then In_Extended_Main_Source_Unit (N)
1584 and then Comes_From_Source (N)
1585 then
1586 First_And_Last_Nodes (N, Fst, Lst);
1587 Error_Msg_NEL (Msg, N, N,
1588 To_Span (Ptr => Sloc (N),
1589 First => First_Sloc (Fst),
1590 Last => Last_Sloc (Lst)));
1591 end if;
1592 end Error_Msg_NW;
1594 -----------------
1595 -- Error_Msg_S --
1596 -----------------
1598 procedure Error_Msg_S (Msg : String) is
1599 begin
1600 Error_Msg (Msg, Scan_Ptr);
1601 end Error_Msg_S;
1603 ------------------
1604 -- Error_Msg_SC --
1605 ------------------
1607 procedure Error_Msg_SC (Msg : String) is
1608 begin
1609 -- If we are at end of file, post the flag after the previous token
1611 if Token = Tok_EOF then
1612 Error_Msg_AP (Msg);
1614 -- For all other cases the message is posted at the current token
1615 -- pointer position
1617 else
1618 Error_Msg (Msg, Token_Ptr);
1619 end if;
1620 end Error_Msg_SC;
1622 ------------------
1623 -- Error_Msg_SP --
1624 ------------------
1626 procedure Error_Msg_SP (Msg : String) is
1627 begin
1628 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1629 -- is set to Source_First, which is a reasonable position for the
1630 -- error flag in this situation
1632 Error_Msg (Msg, Prev_Token_Ptr);
1633 end Error_Msg_SP;
1635 --------------
1636 -- Finalize --
1637 --------------
1639 procedure Finalize (Last_Call : Boolean) is
1640 Cur : Error_Msg_Id;
1641 Nxt : Error_Msg_Id;
1642 F : Error_Msg_Id;
1644 procedure Delete_Warning (E : Error_Msg_Id);
1645 -- Delete a warning msg if not already deleted and adjust warning count
1647 --------------------
1648 -- Delete_Warning --
1649 --------------------
1651 procedure Delete_Warning (E : Error_Msg_Id) is
1652 begin
1653 if not Errors.Table (E).Deleted then
1654 Errors.Table (E).Deleted := True;
1655 Warnings_Detected := Warnings_Detected - 1;
1657 if Errors.Table (E).Info then
1658 Warning_Info_Messages := Warning_Info_Messages - 1;
1659 end if;
1660 end if;
1661 end Delete_Warning;
1663 -- Start of processing for Finalize
1665 begin
1666 -- Set Prev pointers
1668 Cur := First_Error_Msg;
1669 while Cur /= No_Error_Msg loop
1670 Nxt := Errors.Table (Cur).Next;
1671 exit when Nxt = No_Error_Msg;
1672 Errors.Table (Nxt).Prev := Cur;
1673 Cur := Nxt;
1674 end loop;
1676 -- Eliminate any duplicated error messages from the list. This is
1677 -- done after the fact to avoid problems with Change_Error_Text.
1679 Cur := First_Error_Msg;
1680 while Cur /= No_Error_Msg loop
1681 Nxt := Errors.Table (Cur).Next;
1683 F := Nxt;
1684 while F /= No_Error_Msg
1685 and then Errors.Table (F).Sptr.Ptr = Errors.Table (Cur).Sptr.Ptr
1686 loop
1687 Check_Duplicate_Message (Cur, F);
1688 F := Errors.Table (F).Next;
1689 end loop;
1691 Cur := Nxt;
1692 end loop;
1694 -- Mark any messages suppressed by specific warnings as Deleted
1696 Cur := First_Error_Msg;
1697 while Cur /= No_Error_Msg loop
1698 declare
1699 CE : Error_Msg_Object renames Errors.Table (Cur);
1700 Tag : constant String := Get_Warning_Tag (Cur);
1702 begin
1703 if (CE.Warn and not CE.Deleted)
1704 and then
1705 (Warning_Specifically_Suppressed (CE.Sptr.Ptr, CE.Text, Tag)
1706 /= No_String
1707 or else
1708 Warning_Specifically_Suppressed (CE.Optr.Ptr, CE.Text, Tag)
1709 /= No_String)
1710 then
1711 Delete_Warning (Cur);
1713 -- If this is a continuation, delete previous parts of message
1715 F := Cur;
1716 while Errors.Table (F).Msg_Cont loop
1717 F := Errors.Table (F).Prev;
1718 exit when F = No_Error_Msg;
1719 Delete_Warning (F);
1720 end loop;
1722 -- Delete any following continuations
1724 F := Cur;
1725 loop
1726 F := Errors.Table (F).Next;
1727 exit when F = No_Error_Msg;
1728 exit when not Errors.Table (F).Msg_Cont;
1729 Delete_Warning (F);
1730 end loop;
1731 end if;
1732 end;
1734 Cur := Errors.Table (Cur).Next;
1735 end loop;
1737 Finalize_Called := True;
1739 -- Check consistency of specific warnings (may add warnings). We only
1740 -- do this on the last call, after all possible warnings are posted.
1742 if Last_Call then
1743 Validate_Specific_Warnings (Error_Msg'Access);
1744 end if;
1745 end Finalize;
1747 ----------------
1748 -- First_Node --
1749 ----------------
1751 function First_Node (C : Node_Id) return Node_Id is
1752 Fst, Lst : Node_Id;
1753 begin
1754 First_And_Last_Nodes (C, Fst, Lst);
1755 return Fst;
1756 end First_Node;
1758 --------------------------
1759 -- First_And_Last_Nodes --
1760 --------------------------
1762 procedure First_And_Last_Nodes
1763 (C : Node_Id;
1764 First_Node, Last_Node : out Node_Id)
1766 Orig : constant Node_Id := Original_Node (C);
1767 Loc : constant Source_Ptr := Sloc (Orig);
1768 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1769 Earliest : Node_Id;
1770 Latest : Node_Id;
1771 Eloc : Source_Ptr;
1772 Lloc : Source_Ptr;
1774 function Test_First_And_Last (N : Node_Id) return Traverse_Result;
1775 -- Function applied to every node in the construct
1777 procedure Search_Tree_First_And_Last is new
1778 Traverse_Proc (Test_First_And_Last);
1779 -- Create traversal procedure
1781 -------------------------
1782 -- Test_First_And_Last --
1783 -------------------------
1785 function Test_First_And_Last (N : Node_Id) return Traverse_Result is
1786 Norig : constant Node_Id := Original_Node (N);
1787 Loc : constant Source_Ptr := Sloc (Norig);
1789 begin
1790 -- ??? For assignments that require accessiblity checks, e.g.:
1792 -- Y := Func (123);
1794 -- the function call gets an extra actual parameter association with
1795 -- Sloc of the assigned name "Y":
1797 -- Y := Func (123, A8b => 2);
1799 -- We can simply ignore those extra actual parameters when
1800 -- determining the Sloc range of the "Func (123)" expression.
1802 if Nkind (N) = N_Parameter_Association
1803 and then Is_Accessibility_Actual (N)
1804 then
1805 return Skip;
1806 end if;
1808 -- Check for earlier
1810 if Loc < Eloc
1812 -- Ignore nodes with no useful location information
1814 and then Loc /= Standard_Location
1815 and then Loc /= No_Location
1817 -- Ignore nodes from a different file. This ensures against cases
1818 -- of strange foreign code somehow being present. We don't want
1819 -- wild placement of messages if that happens.
1821 and then Get_Source_File_Index (Loc) = Sfile
1822 then
1823 Earliest := Norig;
1824 Eloc := Loc;
1825 end if;
1827 -- Check for later
1829 if Loc > Lloc
1831 -- Ignore nodes with no useful location information
1833 and then Loc /= Standard_Location
1834 and then Loc /= No_Location
1836 -- Ignore nodes from a different file. This ensures against cases
1837 -- of strange foreign code somehow being present. We don't want
1838 -- wild placement of messages if that happens.
1840 and then Get_Source_File_Index (Loc) = Sfile
1841 then
1842 Latest := Norig;
1843 Lloc := Loc;
1844 end if;
1846 return OK_Orig;
1847 end Test_First_And_Last;
1849 -- Start of processing for First_And_Last_Nodes
1851 begin
1852 if Nkind (Orig) in N_Subexpr
1853 | N_Declaration
1854 | N_Access_To_Subprogram_Definition
1855 | N_Generic_Instantiation
1856 | N_Later_Decl_Item
1857 | N_Use_Package_Clause
1858 | N_Array_Type_Definition
1859 | N_Renaming_Declaration
1860 | N_Generic_Renaming_Declaration
1861 | N_Assignment_Statement
1862 | N_Raise_Statement
1863 | N_Simple_Return_Statement
1864 | N_Exit_Statement
1865 | N_Pragma
1866 | N_Use_Type_Clause
1867 | N_With_Clause
1868 | N_Attribute_Definition_Clause
1869 | N_Subtype_Indication
1870 then
1871 Earliest := Orig;
1872 Eloc := Loc;
1873 Latest := Orig;
1874 Lloc := Loc;
1875 Search_Tree_First_And_Last (Orig);
1876 First_Node := Earliest;
1877 Last_Node := Latest;
1879 else
1880 First_Node := Orig;
1881 Last_Node := Orig;
1882 end if;
1883 end First_And_Last_Nodes;
1885 ----------------
1886 -- First_Sloc --
1887 ----------------
1889 function First_Sloc (N : Node_Id) return Source_Ptr is
1890 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1891 SF : constant Source_Ptr := Source_First (SI);
1892 SL : constant Source_Ptr := Source_Last (SI);
1893 Src : constant Source_Buffer_Ptr := Source_Text (SI);
1894 F : Node_Id;
1895 S : Source_Ptr;
1897 begin
1898 F := First_Node (N);
1899 S := Sloc (F);
1901 if S not in SF .. SL then
1902 return S;
1903 end if;
1905 -- The following circuit is a bit subtle. When we have parenthesized
1906 -- expressions, then the Sloc will not record the location of the paren,
1907 -- but we would like to post the flag on the paren. So what we do is to
1908 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1909 -- any parentheses we know are present. Yes, we know this circuit is not
1910 -- 100% reliable (e.g. because we don't record all possible paren level
1911 -- values), but this is only for an error message so it is good enough.
1913 Node_Loop : loop
1914 -- Include parentheses around the top node, except when they are
1915 -- required by the syntax of the parent node.
1917 exit Node_Loop when F = N
1918 and then Paren_Required (N);
1920 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1922 -- We don't look more than 12 characters behind the current
1923 -- location, and in any case not past the front of the source.
1925 Search_Loop : for K in 1 .. 12 loop
1926 exit Search_Loop when S = SF;
1928 if Src (S - 1) = '(' then
1929 S := S - 1;
1930 exit Search_Loop;
1932 elsif Src (S - 1) <= ' ' then
1933 S := S - 1;
1935 else
1936 exit Search_Loop;
1937 end if;
1938 end loop Search_Loop;
1939 end loop Paren_Loop;
1941 exit Node_Loop when F = N;
1942 F := Parent (F);
1943 exit Node_Loop when Nkind (F) not in N_Subexpr;
1944 end loop Node_Loop;
1946 return S;
1947 end First_Sloc;
1949 -----------------------
1950 -- Get_Ignore_Errors --
1951 -----------------------
1953 function Get_Ignore_Errors return Boolean is
1954 begin
1955 return Errors_Must_Be_Ignored;
1956 end Get_Ignore_Errors;
1958 ----------------
1959 -- Initialize --
1960 ----------------
1962 procedure Initialize is
1963 begin
1964 Errors.Init;
1965 First_Error_Msg := No_Error_Msg;
1966 Last_Error_Msg := No_Error_Msg;
1967 Serious_Errors_Detected := 0;
1968 Total_Errors_Detected := 0;
1969 Cur_Msg := No_Error_Msg;
1970 List_Pragmas.Init;
1972 -- Reset counts for warnings
1974 Warnings_Treated_As_Errors := 0;
1975 Warnings_Detected := 0;
1976 Warning_Info_Messages := 0;
1977 Warnings_As_Errors_Count := 0;
1979 -- Initialize warnings tables
1981 Warnings.Init;
1982 Specific_Warnings.Init;
1983 end Initialize;
1985 -------------------------------
1986 -- Is_Size_Too_Small_Message --
1987 -------------------------------
1989 function Is_Size_Too_Small_Message (S : String) return Boolean is
1990 Size_For : constant String := "size for";
1991 pragma Assert (Size_Too_Small_Message (1 .. Size_For'Last) = Size_For);
1992 -- Assert that Size_Too_Small_Message starts with Size_For
1993 begin
1994 return S'Length >= Size_For'Length
1995 and then S (S'First .. S'First + Size_For'Length - 1) = Size_For;
1996 -- True if S starts with Size_For
1997 end Is_Size_Too_Small_Message;
1999 ---------------
2000 -- Last_Node --
2001 ---------------
2003 function Last_Node (C : Node_Id) return Node_Id is
2004 Fst, Lst : Node_Id;
2005 begin
2006 First_And_Last_Nodes (C, Fst, Lst);
2007 return Lst;
2008 end Last_Node;
2010 ---------------
2011 -- Last_Sloc --
2012 ---------------
2014 function Last_Sloc (N : Node_Id) return Source_Ptr is
2015 procedure Skip_Char (S : in out Source_Ptr);
2016 -- Skip one character of the source buffer at location S
2018 ---------------
2019 -- Skip_Char --
2020 ---------------
2022 procedure Skip_Char (S : in out Source_Ptr) is
2023 begin
2024 S := S + 1;
2025 end Skip_Char;
2027 -- Local variables
2029 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
2030 SF : constant Source_Ptr := Source_First (SI);
2031 SL : constant Source_Ptr := Source_Last (SI);
2032 Src : constant Source_Buffer_Ptr := Source_Text (SI);
2033 F : Node_Id;
2034 S : Source_Ptr;
2036 -- Start of processing for Last_Sloc
2038 begin
2039 F := Last_Node (N);
2040 S := Sloc (F);
2042 if S not in SF .. SL then
2043 return S;
2044 end if;
2046 -- For string and character literals simply forward the sloc by their
2047 -- length including the closing quotes. Perhaps we should do something
2048 -- special for multibyte characters, but this code is only used to emit
2049 -- error messages, so it is not worth the effort.
2051 case Nkind (F) is
2052 when N_String_Literal =>
2053 return S + Source_Ptr (String_Length (Strval (F))) + 1;
2055 when N_Character_Literal =>
2056 return S + 2;
2058 -- Skip past integer literals, both decimal and based, integer and
2059 -- real. We can't greedily accept all allowed character, because
2060 -- we would consme too many of them in expressions like "123+ABC"
2061 -- or "123..456", so we follow quite precisely the Ada grammar and
2062 -- consume different characters depending on the context.
2064 when N_Integer_Literal =>
2066 -- Skip past the initial numeral, which either leads the decimal
2067 -- literal or is the base of a based literal.
2069 while S < SL
2070 and then Src (S + 1) in '0' .. '9' | '_'
2071 loop
2072 Skip_Char (S);
2073 end loop;
2075 -- Skip past #based_numeral#, if present
2077 if S < SL
2078 and then Src (S + 1) = '#'
2079 then
2080 Skip_Char (S);
2082 while S < SL
2083 and then
2084 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2085 loop
2086 Skip_Char (S);
2087 end loop;
2089 if S < SL
2090 and then Src (S + 1) = '#'
2091 then
2092 Skip_Char (S);
2093 end if;
2094 end if;
2096 -- Skip past exponent, if present
2098 if S < SL
2099 and then Src (S + 1) in 'e' | 'E'
2100 then
2101 Skip_Char (S);
2103 -- For positive exponents the plus sign is optional, but we
2104 -- can simply skip past both plus and minus.
2106 if S < SL
2107 and then Src (S + 1) in '+' | '-'
2108 then
2109 Skip_Char (S);
2110 end if;
2112 -- Skip past the numeral part
2114 while S < SL
2115 and then Src (S + 1) in '0' .. '9' | '_'
2116 loop
2117 Skip_Char (S);
2118 end loop;
2119 end if;
2121 when N_Real_Literal =>
2122 -- Skip past the initial numeral, which either leads the decimal
2123 -- literal or is the base of a based literal.
2125 while S < SL
2126 and then Src (S + 1) in '0' .. '9' | '_'
2127 loop
2128 Skip_Char (S);
2129 end loop;
2131 if S < SL then
2133 -- Skip the dot and continue with a decimal literal
2135 if Src (S + 1) = '.' then
2136 Skip_Char (S);
2138 while S < SL
2139 and then Src (S + 1) in '0' .. '9' | '_'
2140 loop
2141 Skip_Char (S);
2142 end loop;
2144 -- Skip the hash and continue with a based literal
2146 elsif Src (S + 1) = '#' then
2147 Skip_Char (S);
2149 while S < SL
2150 and then
2151 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2152 loop
2153 Skip_Char (S);
2154 end loop;
2156 if S < SL
2157 and then Src (S + 1) = '.'
2158 then
2159 Skip_Char (S);
2160 end if;
2162 while S < SL
2163 and then
2164 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2165 loop
2166 Skip_Char (S);
2167 end loop;
2169 if S < SL
2170 and then Src (S + 1) = '#'
2171 then
2172 Skip_Char (S);
2173 end if;
2174 end if;
2175 end if;
2177 -- Skip past exponent, if present
2179 if S < SL
2180 and then Src (S + 1) in 'e' | 'E'
2181 then
2182 Skip_Char (S);
2183 -- For positive exponents the plus sign is optional, but we
2184 -- can simply skip past both plus and minus.
2186 if Src (S + 1) in '+' | '-' then
2187 Skip_Char (S);
2188 end if;
2190 -- Skip past the numeral part
2192 while S < SL
2193 and then Src (S + 1) in '0' .. '9' | '_'
2194 loop
2195 Skip_Char (S);
2196 end loop;
2197 end if;
2199 -- For other nodes simply skip past a keyword/identifier
2201 when others =>
2202 while S in SF .. SL - 1
2203 and then Src (S + 1)
2205 '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_'
2206 loop
2207 Skip_Char (S);
2208 end loop;
2209 end case;
2211 -- The following circuit attempts at crawling up the tree from the
2212 -- Last_Node, adjusting the Sloc value for any parentheses we know
2213 -- are present, similarly to what is done in First_Sloc.
2215 Node_Loop : loop
2216 -- Include parentheses around the top node, except when they are
2217 -- required by the syntax of the parent node.
2219 exit Node_Loop when F = N
2220 and then Paren_Required (N);
2222 Paren_Loop : for J in 1 .. Paren_Count (F) loop
2224 -- We don't look more than 12 characters after the current
2225 -- location
2227 Search_Loop : for K in 1 .. 12 loop
2228 exit Node_Loop when S = SL;
2230 if Src (S + 1) = ')' then
2231 S := S + 1;
2232 exit Search_Loop;
2234 elsif Src (S + 1) <= ' ' then
2235 S := S + 1;
2237 else
2238 exit Search_Loop;
2239 end if;
2240 end loop Search_Loop;
2241 end loop Paren_Loop;
2243 exit Node_Loop when F = N;
2244 F := Parent (F);
2245 exit Node_Loop when Nkind (F) not in N_Subexpr;
2246 end loop Node_Loop;
2248 -- Remove any trailing space
2250 while S in SF + 1 .. SL
2251 and then Src (S) = ' '
2252 loop
2253 S := S - 1;
2254 end loop;
2256 return S;
2257 end Last_Sloc;
2259 -----------------
2260 -- No_Warnings --
2261 -----------------
2263 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
2264 begin
2265 if Error_Posted (N) then
2266 return True;
2268 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
2269 return True;
2271 elsif Is_Entity_Name (N)
2272 and then Present (Entity (N))
2273 and then Has_Warnings_Off (Entity (N))
2274 then
2275 return True;
2277 else
2278 return False;
2279 end if;
2280 end No_Warnings;
2282 -------------
2283 -- OK_Node --
2284 -------------
2286 function OK_Node (N : Node_Id) return Boolean is
2287 K : constant Node_Kind := Nkind (N);
2289 begin
2290 if Error_Posted (N) then
2291 return False;
2293 elsif K in N_Has_Etype
2294 and then Present (Etype (N))
2295 and then Error_Posted (Etype (N))
2296 then
2297 return False;
2299 elsif (K in N_Op
2300 or else K = N_Attribute_Reference
2301 or else K = N_Character_Literal
2302 or else K = N_Expanded_Name
2303 or else K = N_Identifier
2304 or else K = N_Operator_Symbol)
2305 and then Present (Entity (N))
2306 and then Error_Posted (Entity (N))
2307 then
2308 return False;
2309 else
2310 return True;
2311 end if;
2312 end OK_Node;
2314 -------------------------
2315 -- Output_JSON_Message --
2316 -------------------------
2318 procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
2320 function Is_Continuation (E : Error_Msg_Id) return Boolean;
2321 -- Return True if E is a continuation message.
2323 procedure Write_JSON_Escaped_String (Str : String_Ptr);
2324 procedure Write_JSON_Escaped_String (Str : String);
2325 -- Write each character of Str, taking care of preceding each quote and
2326 -- backslash with a backslash. Note that this escaping differs from what
2327 -- GCC does.
2329 -- Indeed, the JSON specification mandates encoding wide characters
2330 -- either as their direct UTF-8 representation or as their escaped
2331 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2332 -- we choose to use the UTF-8 representation instead.
2334 procedure Write_JSON_Location (Sptr : Source_Ptr);
2335 -- Write Sptr as a JSON location, an object containing a file attribute,
2336 -- a line number and a column number.
2338 procedure Write_JSON_Span (Error : Error_Msg_Object);
2339 -- Write Error as a JSON span, an object containing a "caret" attribute
2340 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2341 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2342 -- locations under the names "start" and "finish".
2343 -- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional,
2344 -- non-standard, attribute named "subprogram" will be added, allowing
2345 -- precisely identifying the subprogram surrounding the span.
2347 -----------------------
2348 -- Is_Continuation --
2349 -----------------------
2351 function Is_Continuation (E : Error_Msg_Id) return Boolean is
2352 begin
2353 return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
2354 end Is_Continuation;
2356 -------------------------------
2357 -- Write_JSON_Escaped_String --
2358 -------------------------------
2360 procedure Write_JSON_Escaped_String (Str : String) is
2361 begin
2362 for C of Str loop
2363 if C = '"' or else C = '\' then
2364 Write_Char ('\');
2365 end if;
2367 Write_Char (C);
2368 end loop;
2369 end Write_JSON_Escaped_String;
2371 -------------------------------
2372 -- Write_JSON_Escaped_String --
2373 -------------------------------
2375 procedure Write_JSON_Escaped_String (Str : String_Ptr) is
2376 begin
2377 Write_JSON_Escaped_String (Str.all);
2378 end Write_JSON_Escaped_String;
2380 -------------------------
2381 -- Write_JSON_Location --
2382 -------------------------
2384 procedure Write_JSON_Location (Sptr : Source_Ptr) is
2385 Name : constant File_Name_Type :=
2386 Full_Ref_Name (Get_Source_File_Index (Sptr));
2387 begin
2388 Write_Str ("{""file"":""");
2389 if Full_Path_Name_For_Brief_Errors then
2390 Write_JSON_Escaped_String
2391 (System.OS_Lib.Normalize_Pathname (Get_Name_String (Name)));
2392 else
2393 Write_Name (Name);
2394 end if;
2395 Write_Str (""",""line"":");
2396 Write_Int (Pos (Get_Physical_Line_Number (Sptr)));
2397 Write_Str (", ""column"":");
2398 Write_Int (Nat (Get_Column_Number (Sptr)));
2399 Write_Str ("}");
2400 end Write_JSON_Location;
2402 ---------------------
2403 -- Write_JSON_Span --
2404 ---------------------
2406 procedure Write_JSON_Span (Error : Error_Msg_Object) is
2407 Span : constant Source_Span := Error.Sptr;
2408 begin
2409 Write_Str ("{""caret"":");
2410 Write_JSON_Location (Span.Ptr);
2412 if Span.Ptr /= Span.First then
2413 Write_Str (",""start"":");
2414 Write_JSON_Location (Span.First);
2415 end if;
2417 if Span.Ptr /= Span.Last then
2418 Write_Str (",""finish"":");
2419 Write_JSON_Location (Span.Last);
2420 end if;
2422 if Include_Subprogram_In_Messages then
2423 Write_Str (",""subprogram"":""");
2424 Write_JSON_Escaped_String (Subprogram_Name_Ptr (Error.Node));
2425 Write_Str ("""");
2426 end if;
2428 Write_Str ("}");
2429 end Write_JSON_Span;
2431 -- Local Variables
2433 E : Error_Msg_Id := Error_Id;
2435 Print_Continuations : constant Boolean := not Is_Continuation (E);
2436 -- Do not print continuations messages as children of the current
2437 -- message if the current message is a continuation message.
2439 Option : constant String := Get_Warning_Option (E);
2440 -- The option that triggered this message.
2442 -- Start of processing for Output_JSON_Message
2444 begin
2446 -- Print message kind
2448 Write_Str ("{""kind"":");
2450 if Errors.Table (E).Warn and then not Errors.Table (E).Warn_Err then
2451 Write_Str ("""warning""");
2452 elsif Errors.Table (E).Info or else Errors.Table (E).Check then
2453 Write_Str ("""note""");
2454 else
2455 Write_Str ("""error""");
2456 end if;
2458 -- Print message location
2460 Write_Str (",""locations"":[");
2461 Write_JSON_Span (Errors.Table (E));
2463 if Errors.Table (E).Optr.Ptr /= Errors.Table (E).Sptr.Ptr then
2464 Write_Str (",{""caret"":");
2465 Write_JSON_Location (Errors.Table (E).Optr.Ptr);
2466 Write_Str ("}");
2467 end if;
2469 Write_Str ("]");
2471 -- Print message option, if there is one
2472 if Option /= "" then
2473 Write_Str (",""option"":""" & Option & """");
2474 end if;
2476 -- Print message content
2478 Write_Str (",""message"":""");
2479 Write_JSON_Escaped_String (Errors.Table (E).Text);
2480 Write_Str ("""");
2482 E := E + 1;
2484 if Print_Continuations and then Is_Continuation (E) then
2486 Write_Str (",""children"": [");
2487 Output_JSON_Message (E);
2488 E := E + 1;
2490 while Is_Continuation (E) loop
2491 Write_Str (", ");
2492 Output_JSON_Message (E);
2493 E := E + 1;
2494 end loop;
2496 Write_Str ("]");
2498 end if;
2500 Write_Str ("}");
2501 end Output_JSON_Message;
2503 ---------------------
2504 -- Output_Messages --
2505 ---------------------
2507 procedure Output_Messages is
2509 -- Local subprograms
2511 procedure Write_Error_Summary;
2512 -- Write error summary
2514 procedure Write_Header (Sfile : Source_File_Index);
2515 -- Write header line (compiling or checking given file)
2517 procedure Write_Max_Errors;
2518 -- Write message if max errors reached
2520 procedure Write_Source_Code_Lines
2521 (Span : Source_Span;
2522 SGR_Span : String);
2523 -- Write the source code line corresponding to Span, as follows when
2524 -- Span in on one line:
2526 -- line | actual code line here with Span somewhere
2527 -- | ~~~~~^~~~
2529 -- where the caret on the line points to location Span.Ptr, and the
2530 -- range Span.First..Span.Last is underlined.
2532 -- or when the span is over multiple lines:
2534 -- line | beginning of the Span on this line
2535 -- ... | ...
2536 -- line>| actual code line here with Span.Ptr somewhere
2537 -- ... | ...
2538 -- line | end of the Span on this line
2540 -- or when the span is a simple location, as follows:
2542 -- line | actual code line here with Span somewhere
2543 -- | ^ here
2545 -- where the caret on the line points to location Span.Ptr
2547 -- SGR_Span is the SGR string to start the section of code in the span,
2548 -- that should be closed with SGR_Reset.
2550 -------------------------
2551 -- Write_Error_Summary --
2552 -------------------------
2554 procedure Write_Error_Summary is
2555 begin
2556 -- Extra blank line if error messages or source listing were output
2558 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
2559 then
2560 Write_Eol;
2561 end if;
2563 -- Message giving number of lines read and number of errors detected.
2564 -- This normally goes to Standard_Output. The exception is when brief
2565 -- mode is not set, verbose mode (or full list mode) is set, and
2566 -- there are errors. In this case we send the message to standard
2567 -- error to make sure that *something* appears on standard error
2568 -- in an error situation.
2570 if Total_Errors_Detected + Warnings_Detected /= 0
2571 and then not Brief_Output
2572 and then (Verbose_Mode or Full_List)
2573 then
2574 Set_Standard_Error;
2575 end if;
2577 -- Message giving total number of lines. Don't give this message if
2578 -- the Main_Source line is unknown (this happens in error situations,
2579 -- e.g. when integrated preprocessing fails).
2581 if Main_Source_File > No_Source_File then
2582 Write_Str (" ");
2583 Write_Int (Num_Source_Lines (Main_Source_File));
2585 if Num_Source_Lines (Main_Source_File) = 1 then
2586 Write_Str (" line: ");
2587 else
2588 Write_Str (" lines: ");
2589 end if;
2590 end if;
2592 if Total_Errors_Detected = 0 then
2593 Write_Str ("No errors");
2595 elsif Total_Errors_Detected = 1 then
2596 Write_Str ("1 error");
2598 else
2599 Write_Int (Total_Errors_Detected);
2600 Write_Str (" errors");
2601 end if;
2603 -- We now need to output warnings. When using -gnatwe, all warnings
2604 -- should be treated as errors, except for warnings originating from
2605 -- the use of the Compile_Time_Warning pragma. Another situation
2606 -- where a warning might be treated as an error is when the source
2607 -- code contains a Warning_As_Error pragma.
2608 -- When warnings are treated as errors, we still log them as
2609 -- warnings, but we add a message denoting how many of these warnings
2610 -- are also errors.
2612 declare
2613 Warnings_Count : constant Int :=
2614 Warnings_Detected - Warning_Info_Messages;
2616 Compile_Time_Warnings : Int;
2617 -- Number of warnings that come from a Compile_Time_Warning
2618 -- pragma.
2620 Non_Compile_Time_Warnings : Int;
2621 -- Number of warnings that do not come from a Compile_Time_Warning
2622 -- pragmas.
2624 begin
2625 if Warnings_Count > 0 then
2626 Write_Str (", ");
2627 Write_Int (Warnings_Count);
2628 Write_Str (" warning");
2630 if Warnings_Count > 1 then
2631 Write_Char ('s');
2632 end if;
2634 Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
2635 Non_Compile_Time_Warnings :=
2636 Warnings_Count - Compile_Time_Warnings;
2638 if Warning_Mode = Treat_As_Error
2639 and then Non_Compile_Time_Warnings > 0
2640 then
2641 Write_Str (" (");
2643 if Compile_Time_Warnings > 0 then
2644 Write_Int (Non_Compile_Time_Warnings);
2645 Write_Str (" ");
2646 end if;
2648 Write_Str ("treated as error");
2650 if Non_Compile_Time_Warnings > 1 then
2651 Write_Char ('s');
2652 end if;
2654 Write_Char (')');
2656 elsif Warnings_Treated_As_Errors > 0 then
2657 Write_Str (" (");
2659 if Warnings_Treated_As_Errors /= Warnings_Count then
2660 Write_Int (Warnings_Treated_As_Errors);
2661 Write_Str (" ");
2662 end if;
2664 Write_Str ("treated as error");
2666 if Warnings_Treated_As_Errors > 1 then
2667 Write_Str ("s");
2668 end if;
2670 Write_Str (")");
2671 end if;
2672 end if;
2673 end;
2675 if Warning_Info_Messages + Report_Info_Messages /= 0 then
2676 Write_Str (", ");
2677 Write_Int (Warning_Info_Messages + Report_Info_Messages);
2678 Write_Str (" info message");
2680 if Warning_Info_Messages + Report_Info_Messages > 1 then
2681 Write_Char ('s');
2682 end if;
2683 end if;
2685 Write_Eol;
2686 Set_Standard_Output;
2687 end Write_Error_Summary;
2689 ------------------
2690 -- Write_Header --
2691 ------------------
2693 procedure Write_Header (Sfile : Source_File_Index) is
2694 begin
2695 if Verbose_Mode or Full_List then
2696 if Original_Operating_Mode = Generate_Code then
2697 Write_Str ("Compiling: ");
2698 else
2699 Write_Str ("Checking: ");
2700 end if;
2702 Write_Name (Full_File_Name (Sfile));
2704 if not Debug_Flag_7 then
2705 Write_Eol;
2706 Write_Str ("Source file time stamp: ");
2707 Write_Time_Stamp (Sfile);
2708 Write_Eol;
2709 Write_Str ("Compiled at: " & Compilation_Time);
2710 end if;
2712 Write_Eol;
2713 end if;
2714 end Write_Header;
2716 ----------------------
2717 -- Write_Max_Errors --
2718 ----------------------
2720 procedure Write_Max_Errors is
2721 begin
2722 if Maximum_Messages /= 0 then
2723 if Warnings_Detected >= Maximum_Messages then
2724 Set_Standard_Error;
2725 Write_Line ("maximum number of warnings output");
2726 Write_Line ("any further warnings suppressed");
2727 Set_Standard_Output;
2728 end if;
2730 -- If too many errors print message
2732 if Total_Errors_Detected >= Maximum_Messages then
2733 Set_Standard_Error;
2734 Write_Line ("fatal error: maximum number of errors detected");
2735 Set_Standard_Output;
2736 end if;
2737 end if;
2738 end Write_Max_Errors;
2740 -----------------------------
2741 -- Write_Source_Code_Lines --
2742 -----------------------------
2744 procedure Write_Source_Code_Lines
2745 (Span : Source_Span;
2746 SGR_Span : String)
2748 function Get_Line_End
2749 (Buf : Source_Buffer_Ptr;
2750 Loc : Source_Ptr) return Source_Ptr;
2751 -- Get the source location for the end of the line in Buf for Loc. If
2752 -- Loc is past the end of Buf already, return Buf'Last.
2754 function Get_Line_Start
2755 (Buf : Source_Buffer_Ptr;
2756 Loc : Source_Ptr) return Source_Ptr;
2757 -- Get the source location for the start of the line in Buf for Loc
2759 function Image (X : Positive; Width : Positive) return String;
2760 -- Output number X over Width characters, with whitespace padding.
2761 -- Only output the low-order Width digits of X, if X is larger than
2762 -- Width digits.
2764 procedure Write_Buffer
2765 (Buf : Source_Buffer_Ptr;
2766 First : Source_Ptr;
2767 Last : Source_Ptr);
2768 -- Output the characters from First to Last position in Buf, using
2769 -- Write_Buffer_Char.
2771 procedure Write_Buffer_Char
2772 (Buf : Source_Buffer_Ptr;
2773 Loc : Source_Ptr);
2774 -- Output the characters at position Loc in Buf, translating ASCII.HT
2775 -- in a suitable number of spaces so that the output is not modified
2776 -- by starting in a different column that 1.
2778 procedure Write_Line_Marker
2779 (Num : Pos;
2780 Mark : Boolean;
2781 Width : Positive);
2782 -- Output the line number Num over Width characters, with possibly
2783 -- a Mark to denote the line with the main location when reporting
2784 -- a span over multiple lines.
2786 ------------------
2787 -- Get_Line_End --
2788 ------------------
2790 function Get_Line_End
2791 (Buf : Source_Buffer_Ptr;
2792 Loc : Source_Ptr) return Source_Ptr
2794 Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
2795 begin
2796 while Cur_Loc < Buf'Last
2797 and then Buf (Cur_Loc) /= ASCII.LF
2798 loop
2799 Cur_Loc := Cur_Loc + 1;
2800 end loop;
2802 return Cur_Loc;
2803 end Get_Line_End;
2805 --------------------
2806 -- Get_Line_Start --
2807 --------------------
2809 function Get_Line_Start
2810 (Buf : Source_Buffer_Ptr;
2811 Loc : Source_Ptr) return Source_Ptr
2813 Cur_Loc : Source_Ptr := Loc;
2814 begin
2815 while Cur_Loc > Buf'First
2816 and then Buf (Cur_Loc - 1) /= ASCII.LF
2817 loop
2818 Cur_Loc := Cur_Loc - 1;
2819 end loop;
2821 return Cur_Loc;
2822 end Get_Line_Start;
2824 -----------
2825 -- Image --
2826 -----------
2828 function Image (X : Positive; Width : Positive) return String is
2829 Str : String (1 .. Width);
2830 Curr : Natural := X;
2831 begin
2832 for J in reverse 1 .. Width loop
2833 if Curr > 0 then
2834 Str (J) := Character'Val (Character'Pos ('0') + Curr mod 10);
2835 Curr := Curr / 10;
2836 else
2837 Str (J) := ' ';
2838 end if;
2839 end loop;
2841 return Str;
2842 end Image;
2844 ------------------
2845 -- Write_Buffer --
2846 ------------------
2848 procedure Write_Buffer
2849 (Buf : Source_Buffer_Ptr;
2850 First : Source_Ptr;
2851 Last : Source_Ptr)
2853 begin
2854 for Loc in First .. Last loop
2855 Write_Buffer_Char (Buf, Loc);
2856 end loop;
2857 end Write_Buffer;
2859 -----------------------
2860 -- Write_Buffer_Char --
2861 -----------------------
2863 procedure Write_Buffer_Char
2864 (Buf : Source_Buffer_Ptr;
2865 Loc : Source_Ptr)
2867 begin
2868 -- If the character ASCII.HT is not the last one in the file,
2869 -- output as many spaces as the character represents in the
2870 -- original source file.
2872 if Buf (Loc) = ASCII.HT
2873 and then Loc < Buf'Last
2874 then
2875 for X in Get_Column_Number (Loc) ..
2876 Get_Column_Number (Loc + 1) - 1
2877 loop
2878 Write_Char (' ');
2879 end loop;
2881 -- Otherwise output the character itself
2883 else
2884 Write_Char (Buf (Loc));
2885 end if;
2886 end Write_Buffer_Char;
2888 -----------------------
2889 -- Write_Line_Marker --
2890 -----------------------
2892 procedure Write_Line_Marker
2893 (Num : Pos;
2894 Mark : Boolean;
2895 Width : Positive)
2897 begin
2898 Write_Str (Image (Positive (Num), Width => Width));
2899 Write_Str ((if Mark then ">" else " ") & "|");
2900 end Write_Line_Marker;
2902 -- Local variables
2904 Loc : constant Source_Ptr := Span.Ptr;
2905 Line : constant Pos := Pos (Get_Physical_Line_Number (Loc));
2907 Col : constant Natural := Natural (Get_Column_Number (Loc));
2909 Fst : constant Source_Ptr := Span.First;
2910 Line_Fst : constant Pos :=
2911 Pos (Get_Physical_Line_Number (Fst));
2912 Col_Fst : constant Natural :=
2913 Natural (Get_Column_Number (Fst));
2914 Lst : constant Source_Ptr := Span.Last;
2915 Line_Lst : constant Pos :=
2916 Pos (Get_Physical_Line_Number (Lst));
2917 Col_Lst : constant Natural :=
2918 Natural (Get_Column_Number (Lst));
2920 Width : constant := 5;
2921 Buf : Source_Buffer_Ptr;
2922 Cur_Loc : Source_Ptr := Fst;
2923 Cur_Line : Pos := Line_Fst;
2925 -- Start of processing for Write_Source_Code_Lines
2927 begin
2928 if Loc >= First_Source_Ptr then
2929 Buf := Source_Text (Get_Source_File_Index (Loc));
2931 -- First line of the span with actual source code. We retrieve
2932 -- the beginning of the line instead of relying on Col_Fst, as
2933 -- ASCII.HT characters change column numbers by possibly more
2934 -- than one.
2936 Write_Line_Marker
2937 (Cur_Line,
2938 Line_Fst /= Line_Lst and then Cur_Line = Line,
2939 Width);
2940 Write_Buffer (Buf, Get_Line_Start (Buf, Cur_Loc), Cur_Loc - 1);
2942 -- Output the first/caret/last lines of the span, as well as
2943 -- lines that are directly above/below the caret if they complete
2944 -- the gap with first/last lines, otherwise use ... to denote
2945 -- intermediate lines.
2947 -- If the span is on one line and not a simple source location,
2948 -- color it appropriately.
2950 if Line_Fst = Line_Lst
2951 and then Col_Fst /= Col_Lst
2952 then
2953 Write_Str (SGR_Span);
2954 end if;
2956 declare
2957 function Do_Write_Line (Cur_Line : Pos) return Boolean is
2958 (Cur_Line in Line_Fst | Line | Line_Lst
2959 or else
2960 (Cur_Line = Line_Fst + 1 and then Cur_Line = Line - 1)
2961 or else
2962 (Cur_Line = Line + 1 and then Cur_Line = Line_Lst - 1));
2963 begin
2964 while Cur_Loc <= Buf'Last
2965 and then Cur_Loc <= Lst
2966 loop
2967 if Do_Write_Line (Cur_Line) then
2968 Write_Buffer_Char (Buf, Cur_Loc);
2969 end if;
2971 if Buf (Cur_Loc) = ASCII.LF then
2972 Cur_Line := Cur_Line + 1;
2974 -- Output ... for skipped lines
2976 if (Cur_Line = Line
2977 and then not Do_Write_Line (Cur_Line - 1))
2978 or else
2979 (Cur_Line = Line + 1
2980 and then not Do_Write_Line (Cur_Line))
2981 then
2982 Write_Str ((1 .. Width - 3 => ' ') & "... | ...");
2983 Write_Eol;
2984 end if;
2986 -- Display the line marker if the line should be
2987 -- displayed.
2989 if Do_Write_Line (Cur_Line) then
2990 Write_Line_Marker
2991 (Cur_Line,
2992 Line_Fst /= Line_Lst and then Cur_Line = Line,
2993 Width);
2994 end if;
2995 end if;
2997 Cur_Loc := Cur_Loc + 1;
2998 end loop;
2999 end;
3001 if Line_Fst = Line_Lst
3002 and then Col_Fst /= Col_Lst
3003 then
3004 Write_Str (SGR_Reset);
3005 end if;
3007 -- Output the rest of the last line of the span
3009 Write_Buffer (Buf, Cur_Loc, Get_Line_End (Buf, Cur_Loc));
3011 -- If the span is on one line, output a second line with caret
3012 -- sign pointing to location Loc
3014 if Line_Fst = Line_Lst then
3015 Write_Str (String'(1 .. Width => ' '));
3016 Write_Str (" |");
3017 Write_Str (String'(1 .. Col_Fst - 1 => ' '));
3019 Write_Str (SGR_Span);
3021 Write_Str (String'(Col_Fst .. Col - 1 => '~'));
3022 Write_Str ("^");
3023 Write_Str (String'(Col + 1 .. Col_Lst => '~'));
3025 -- If the span is really just a location, add the word "here"
3026 -- to clarify this is the location for the message.
3028 if Col_Fst = Col_Lst then
3029 Write_Str (" here");
3030 end if;
3032 Write_Str (SGR_Reset);
3034 Write_Eol;
3035 end if;
3036 end if;
3037 end Write_Source_Code_Lines;
3039 -- Local variables
3041 E : Error_Msg_Id;
3042 Err_Flag : Boolean;
3043 Use_Prefix : Boolean;
3045 -- Start of processing for Output_Messages
3047 begin
3048 -- Error if Finalize has not been called
3050 if not Finalize_Called then
3051 raise Program_Error;
3052 end if;
3054 -- Reset current error source file if the main unit has a pragma
3055 -- Source_Reference. This ensures outputting the proper name of
3056 -- the source file in this situation.
3058 if Main_Source_File <= No_Source_File
3059 or else Num_SRef_Pragmas (Main_Source_File) /= 0
3060 then
3061 Current_Error_Source_File := No_Source_File;
3062 end if;
3064 if Opt.JSON_Output then
3065 Set_Standard_Error;
3067 E := First_Error_Msg;
3069 -- Find first printable message
3071 while E /= No_Error_Msg and then Errors.Table (E).Deleted loop
3072 E := Errors.Table (E).Next;
3073 end loop;
3075 Write_Char ('[');
3077 if E /= No_Error_Msg then
3079 Output_JSON_Message (E);
3081 E := Errors.Table (E).Next;
3083 while E /= No_Error_Msg loop
3085 -- Skip deleted messages.
3086 -- Also skip continuation messages, as they have already been
3087 -- printed along the message they're attached to.
3089 if not Errors.Table (E).Deleted
3090 and then not Errors.Table (E).Msg_Cont
3091 then
3092 Write_Char (',');
3093 Output_JSON_Message (E);
3094 end if;
3096 E := Errors.Table (E).Next;
3097 end loop;
3098 end if;
3100 Write_Char (']');
3102 Set_Standard_Output;
3104 -- Brief Error mode
3106 elsif Brief_Output or (not Full_List and not Verbose_Mode) then
3107 Set_Standard_Error;
3109 E := First_Error_Msg;
3110 while E /= No_Error_Msg loop
3112 -- If -gnatdF is used, separate main messages from previous
3113 -- messages with a newline (unless it is an info message) and
3114 -- make continuation messages follow the main message with only
3115 -- an indentation of two space characters, without repeating
3116 -- file:line:col: prefix.
3118 Use_Prefix :=
3119 not (Debug_Flag_FF and then Errors.Table (E).Msg_Cont);
3121 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
3123 if Debug_Flag_FF then
3124 if Errors.Table (E).Msg_Cont then
3125 Write_Str (" ");
3126 elsif not Errors.Table (E).Info then
3127 Write_Eol;
3128 end if;
3129 end if;
3131 if Use_Prefix then
3132 Write_Str (SGR_Locus);
3134 if Full_Path_Name_For_Brief_Errors then
3135 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
3136 else
3137 Write_Name (Reference_Name (Errors.Table (E).Sfile));
3138 end if;
3140 Write_Char (':');
3141 Write_Int (Int (Physical_To_Logical
3142 (Errors.Table (E).Line,
3143 Errors.Table (E).Sfile)));
3144 Write_Char (':');
3146 if Errors.Table (E).Col < 10 then
3147 Write_Char ('0');
3148 end if;
3150 Write_Int (Int (Errors.Table (E).Col));
3151 Write_Str (": ");
3153 Write_Str (SGR_Reset);
3154 end if;
3156 Output_Msg_Text (E);
3157 Write_Eol;
3159 -- If -gnatdF is used, write the source code line corresponding
3160 -- to the location of the main message (unless it is an info
3161 -- message). Also write the source code line corresponding to
3162 -- an insertion location inside continuation messages.
3164 if Debug_Flag_FF
3165 and then not Errors.Table (E).Info
3166 then
3167 if Errors.Table (E).Msg_Cont then
3168 declare
3169 Loc : constant Source_Ptr :=
3170 Errors.Table (E).Insertion_Sloc;
3171 begin
3172 if Loc /= No_Location then
3173 Write_Source_Code_Lines
3174 (To_Span (Loc), SGR_Span => SGR_Note);
3175 end if;
3176 end;
3178 else
3179 declare
3180 SGR_Span : constant String :=
3181 (if Errors.Table (E).Info then SGR_Note
3182 elsif Errors.Table (E).Warn
3183 and then not Errors.Table (E).Warn_Err
3184 then SGR_Warning
3185 else SGR_Error);
3186 begin
3187 Write_Source_Code_Lines
3188 (Errors.Table (E).Optr, SGR_Span);
3189 end;
3190 end if;
3191 end if;
3192 end if;
3194 E := Errors.Table (E).Next;
3195 end loop;
3197 Set_Standard_Output;
3198 end if;
3200 -- Full source listing case
3202 if Full_List then
3203 List_Pragmas_Index := 1;
3204 List_Pragmas_Mode := True;
3205 E := First_Error_Msg;
3207 -- Normal case, to stdout (copyright notice already output)
3209 if Full_List_File_Name = null then
3210 if not Debug_Flag_7 then
3211 Write_Eol;
3212 end if;
3214 -- Output to file
3216 else
3217 Create_List_File_Access.all (Full_List_File_Name.all);
3218 Set_Special_Output (Write_List_Info_Access.all'Access);
3220 -- Write copyright notice to file
3222 if not Debug_Flag_7 then
3223 Write_Str ("GNAT ");
3224 Write_Str (Gnat_Version_String);
3225 Write_Eol;
3226 Write_Str ("Copyright 1992-" &
3227 Current_Year &
3228 ", Free Software Foundation, Inc.");
3229 Write_Eol;
3230 end if;
3231 end if;
3233 -- First list extended main source file units with errors
3235 for U in Main_Unit .. Last_Unit loop
3236 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
3238 -- If debug flag d.m is set, only the main source is listed
3240 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
3242 -- If the unit of the entity does not come from source, it is
3243 -- an implicit subprogram declaration for a child subprogram.
3244 -- Do not emit errors for it, they are listed with the body.
3246 and then
3247 (No (Cunit_Entity (U))
3248 or else Comes_From_Source (Cunit_Entity (U))
3249 or else not Is_Subprogram (Cunit_Entity (U)))
3251 -- If the compilation unit associated with this unit does not
3252 -- come from source, it means it is an instantiation that should
3253 -- not be included in the source listing.
3255 and then Comes_From_Source (Cunit (U))
3256 then
3257 declare
3258 Sfile : constant Source_File_Index := Source_Index (U);
3260 begin
3261 Write_Eol;
3263 -- Only write the header if Sfile is known
3265 if Sfile > No_Source_File then
3266 Write_Header (Sfile);
3267 Write_Eol;
3268 end if;
3270 -- Normally, we don't want an "error messages from file"
3271 -- message when listing the entire file, so we set the
3272 -- current source file as the current error source file.
3273 -- However, the old style of doing things was to list this
3274 -- message if pragma Source_Reference is present, even for
3275 -- the main unit. Since the purpose of the -gnatd.m switch
3276 -- is to duplicate the old behavior, we skip the reset if
3277 -- this debug flag is set.
3279 if not Debug_Flag_Dot_M then
3280 Current_Error_Source_File := Sfile;
3281 end if;
3283 -- Only output the listing if Sfile is known, to avoid
3284 -- crashing the compiler.
3286 if Sfile > No_Source_File then
3287 for N in 1 .. Last_Source_Line (Sfile) loop
3288 while E /= No_Error_Msg
3289 and then Errors.Table (E).Deleted
3290 loop
3291 E := Errors.Table (E).Next;
3292 end loop;
3294 Err_Flag :=
3295 E /= No_Error_Msg
3296 and then Errors.Table (E).Line = N
3297 and then Errors.Table (E).Sfile = Sfile;
3299 Output_Source_Line (N, Sfile, Err_Flag);
3301 if Err_Flag then
3302 Output_Error_Msgs (E);
3304 if not Debug_Flag_2 then
3305 Write_Eol;
3306 end if;
3307 end if;
3308 end loop;
3309 end if;
3310 end;
3311 end if;
3312 end loop;
3314 -- Then output errors, if any, for subsidiary units not in the
3315 -- main extended unit.
3317 -- Note: if debug flag d.m set, include errors for any units other
3318 -- than the main unit in the extended source unit (e.g. spec and
3319 -- subunits for a body).
3321 while E /= No_Error_Msg
3322 and then (not In_Extended_Main_Source_Unit
3323 (Errors.Table (E).Sptr.Ptr)
3324 or else
3325 (Debug_Flag_Dot_M
3326 and then Get_Source_Unit
3327 (Errors.Table (E).Sptr.Ptr) /= Main_Unit))
3328 loop
3329 if Errors.Table (E).Deleted then
3330 E := Errors.Table (E).Next;
3332 else
3333 Write_Eol;
3334 Output_Source_Line
3335 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3336 Output_Error_Msgs (E);
3337 end if;
3338 end loop;
3340 -- If output to file, write extra copy of error summary to the
3341 -- output file, and then close it.
3343 if Full_List_File_Name /= null then
3344 Write_Error_Summary;
3345 Write_Max_Errors;
3346 Close_List_File_Access.all;
3347 Cancel_Special_Output;
3348 end if;
3349 end if;
3351 -- Verbose mode (error lines only with error flags). Normally this is
3352 -- ignored in full list mode, unless we are listing to a file, in which
3353 -- case we still generate -gnatv output to standard output.
3355 if Verbose_Mode
3356 and then (not Full_List or else Full_List_File_Name /= null)
3357 then
3358 Write_Eol;
3360 -- Output the header only when Main_Source_File is known
3362 if Main_Source_File > No_Source_File then
3363 Write_Header (Main_Source_File);
3364 end if;
3366 E := First_Error_Msg;
3368 -- Loop through error lines
3370 while E /= No_Error_Msg loop
3371 if Errors.Table (E).Deleted then
3372 E := Errors.Table (E).Next;
3373 else
3374 Write_Eol;
3375 Output_Source_Line
3376 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3377 Output_Error_Msgs (E);
3378 end if;
3379 end loop;
3380 end if;
3382 -- Output error summary if verbose or full list mode
3384 if Verbose_Mode or else Full_List then
3385 Write_Error_Summary;
3386 end if;
3388 if not Opt.JSON_Output then
3389 Write_Max_Errors;
3390 end if;
3392 -- Even though Warning_Info_Messages are a subclass of warnings, they
3393 -- must not be treated as errors when -gnatwe is in effect.
3395 if Warning_Mode = Treat_As_Error then
3396 declare
3397 Compile_Time_Pragma_Warnings : constant Int :=
3398 Count_Compile_Time_Pragma_Warnings;
3399 begin
3400 Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected
3401 - Warning_Info_Messages - Compile_Time_Pragma_Warnings;
3402 Warnings_Detected :=
3403 Warning_Info_Messages + Compile_Time_Pragma_Warnings;
3404 end;
3405 end if;
3406 end Output_Messages;
3408 ------------------------
3409 -- Output_Source_Line --
3410 ------------------------
3412 procedure Output_Source_Line
3413 (L : Physical_Line_Number;
3414 Sfile : Source_File_Index;
3415 Errs : Boolean)
3417 S : Source_Ptr;
3418 C : Character;
3420 Line_Number_Output : Boolean := False;
3421 -- Set True once line number is output
3423 Empty_Line : Boolean := True;
3424 -- Set False if line includes at least one character
3426 begin
3427 if Sfile /= Current_Error_Source_File then
3428 Write_Str ("==============Error messages for ");
3430 case Sinput.File_Type (Sfile) is
3431 when Sinput.Src =>
3432 Write_Str ("source");
3434 when Sinput.Config =>
3435 Write_Str ("configuration pragmas");
3437 when Sinput.Def =>
3438 Write_Str ("symbol definition");
3440 when Sinput.Preproc =>
3441 Write_Str ("preprocessing data");
3442 end case;
3444 Write_Str (" file: ");
3445 Write_Name (Full_File_Name (Sfile));
3446 Write_Eol;
3448 if Num_SRef_Pragmas (Sfile) > 0 then
3449 Write_Str ("--------------Line numbers from file: ");
3450 Write_Name (Full_Ref_Name (Sfile));
3451 Write_Str (" (starting at line ");
3452 Write_Int (Int (First_Mapped_Line (Sfile)));
3453 Write_Char (')');
3454 Write_Eol;
3455 end if;
3457 Current_Error_Source_File := Sfile;
3458 end if;
3460 if Errs or List_Pragmas_Mode then
3461 Output_Line_Number (Physical_To_Logical (L, Sfile));
3462 Line_Number_Output := True;
3463 end if;
3465 S := Line_Start (L, Sfile);
3467 loop
3468 C := Source_Text (Sfile) (S);
3469 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
3471 -- Deal with matching entry in List_Pragmas table
3473 if Full_List
3474 and then List_Pragmas_Index <= List_Pragmas.Last
3475 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
3476 then
3477 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
3478 when Page =>
3479 Write_Char (C);
3481 -- Ignore if on line with errors so that error flags
3482 -- get properly listed with the error line .
3484 if not Errs then
3485 Write_Char (ASCII.FF);
3486 end if;
3488 when List_On =>
3489 List_Pragmas_Mode := True;
3491 if not Line_Number_Output then
3492 Output_Line_Number (Physical_To_Logical (L, Sfile));
3493 Line_Number_Output := True;
3494 end if;
3496 Write_Char (C);
3498 when List_Off =>
3499 Write_Char (C);
3500 List_Pragmas_Mode := False;
3501 end case;
3503 List_Pragmas_Index := List_Pragmas_Index + 1;
3505 -- Normal case (no matching entry in List_Pragmas table)
3507 else
3508 if Errs or List_Pragmas_Mode then
3509 Write_Char (C);
3510 end if;
3511 end if;
3513 Empty_Line := False;
3514 S := S + 1;
3515 end loop;
3517 -- If we have output a source line, then add the line terminator, with
3518 -- training spaces preserved (so we output the line exactly as input).
3520 if Line_Number_Output then
3521 if Empty_Line then
3522 Write_Eol;
3523 else
3524 Write_Eol_Keep_Blanks;
3525 end if;
3526 end if;
3527 end Output_Source_Line;
3529 --------------------
3530 -- Paren_Required --
3531 --------------------
3533 function Paren_Required (N : Node_Id) return Boolean is
3534 begin
3535 -- In a qualifed_expression the expression part needs to be enclosed in
3536 -- parentheses.
3538 if Nkind (Parent (N)) = N_Qualified_Expression then
3539 return N = Expression (Parent (N));
3541 else
3542 return False;
3543 end if;
3544 end Paren_Required;
3546 -----------------------------
3547 -- Remove_Warning_Messages --
3548 -----------------------------
3550 procedure Remove_Warning_Messages (N : Node_Id) is
3552 function Check_For_Warning (N : Node_Id) return Traverse_Result;
3553 -- This function checks one node for a possible warning message
3555 procedure Check_All_Warnings is new Traverse_Proc (Check_For_Warning);
3556 -- This defines the traversal operation
3558 -----------------------
3559 -- Check_For_Warning --
3560 -----------------------
3562 function Check_For_Warning (N : Node_Id) return Traverse_Result is
3563 Loc : constant Source_Ptr := Sloc (N);
3564 E : Error_Msg_Id;
3566 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
3567 -- Returns True for a message that is to be removed. Also adjusts
3568 -- warning count appropriately.
3570 -------------------
3571 -- To_Be_Removed --
3572 -------------------
3574 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
3575 begin
3576 if E /= No_Error_Msg
3578 -- Don't remove if location does not match
3580 and then Errors.Table (E).Optr.Ptr = Loc
3582 -- Don't remove if not warning/info message. Note that we do
3583 -- not remove style messages here. They are warning messages
3584 -- but not ones we want removed in this context.
3586 and then (Errors.Table (E).Warn
3587 or else
3588 Errors.Table (E).Warn_Runtime_Raise)
3590 -- Don't remove unconditional messages
3592 and then not Errors.Table (E).Uncond
3593 then
3594 if Errors.Table (E).Warn then
3595 Warnings_Detected := Warnings_Detected - 1;
3596 end if;
3598 if Errors.Table (E).Info then
3599 Warning_Info_Messages := Warning_Info_Messages - 1;
3600 end if;
3602 -- When warning about a runtime exception has been escalated
3603 -- into error, the starting message has increased the total
3604 -- errors counter, so here we decrease this counter.
3606 if Errors.Table (E).Warn_Runtime_Raise
3607 and then not Errors.Table (E).Msg_Cont
3608 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
3609 then
3610 Total_Errors_Detected := Total_Errors_Detected - 1;
3611 end if;
3613 return True;
3615 -- No removal required
3617 else
3618 return False;
3619 end if;
3620 end To_Be_Removed;
3622 -- Start of processing for Check_For_Warnings
3624 begin
3625 while To_Be_Removed (First_Error_Msg) loop
3626 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
3627 end loop;
3629 if First_Error_Msg = No_Error_Msg then
3630 Last_Error_Msg := No_Error_Msg;
3631 end if;
3633 E := First_Error_Msg;
3634 while E /= No_Error_Msg loop
3635 while To_Be_Removed (Errors.Table (E).Next) loop
3636 Errors.Table (E).Next :=
3637 Errors.Table (Errors.Table (E).Next).Next;
3639 if Errors.Table (E).Next = No_Error_Msg then
3640 Last_Error_Msg := E;
3641 end if;
3642 end loop;
3644 E := Errors.Table (E).Next;
3645 end loop;
3647 -- Warnings may have been posted on subexpressions of original tree
3649 if Nkind (N) = N_Raise_Constraint_Error
3650 and then Is_Rewrite_Substitution (N)
3651 and then No (Condition (N))
3652 then
3653 Check_All_Warnings (Original_Node (N));
3654 end if;
3656 return OK;
3657 end Check_For_Warning;
3659 -- Start of processing for Remove_Warning_Messages
3661 begin
3662 if Warnings_Detected /= 0 then
3663 Check_All_Warnings (N);
3664 end if;
3665 end Remove_Warning_Messages;
3667 procedure Remove_Warning_Messages (L : List_Id) is
3668 Stat : Node_Id;
3669 begin
3670 Stat := First (L);
3671 while Present (Stat) loop
3672 Remove_Warning_Messages (Stat);
3673 Next (Stat);
3674 end loop;
3675 end Remove_Warning_Messages;
3677 ----------------------
3678 -- Adjust_Name_Case --
3679 ----------------------
3681 procedure Adjust_Name_Case
3682 (Buf : in out Bounded_String;
3683 Loc : Source_Ptr)
3685 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
3686 Sbuffer : Source_Buffer_Ptr;
3687 Ref_Ptr : Integer;
3688 Src_Ptr : Source_Ptr;
3690 begin
3691 -- We have an all lower case name from Namet, and now we want to set
3692 -- the appropriate case. If possible we copy the actual casing from
3693 -- the source. If not we use standard identifier casing.
3695 Ref_Ptr := 1;
3696 Src_Ptr := Loc;
3698 -- For standard locations, always use mixed case
3700 if Loc <= No_Location then
3701 Set_Casing (Buf, Mixed_Case);
3703 else
3704 -- Determine if the reference we are dealing with corresponds to text
3705 -- at the point of the error reference. This will often be the case
3706 -- for simple identifier references, and is the case where we can
3707 -- copy the casing from the source.
3709 Sbuffer := Source_Text (Src_Ind);
3711 while Ref_Ptr <= Buf.Length loop
3712 exit when
3713 Fold_Lower (Sbuffer (Src_Ptr)) /=
3714 Fold_Lower (Buf.Chars (Ref_Ptr));
3715 Ref_Ptr := Ref_Ptr + 1;
3716 Src_Ptr := Src_Ptr + 1;
3717 end loop;
3719 -- If we get through the loop without a mismatch, then output the
3720 -- name the way it is cased in the source program.
3722 if Ref_Ptr > Buf.Length then
3723 Src_Ptr := Loc;
3725 for J in 1 .. Buf.Length loop
3726 Buf.Chars (J) := Sbuffer (Src_Ptr);
3727 Src_Ptr := Src_Ptr + 1;
3728 end loop;
3730 -- Otherwise set the casing using the default identifier casing
3732 else
3733 Set_Casing (Buf, Identifier_Casing (Src_Ind));
3734 end if;
3735 end if;
3736 end Adjust_Name_Case;
3738 ---------------------------
3739 -- Set_Identifier_Casing --
3740 ---------------------------
3742 procedure Set_Identifier_Casing
3743 (Identifier_Name : System.Address;
3744 File_Name : System.Address)
3746 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
3747 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
3748 Flen : Natural;
3750 Desired_Case : Casing_Type := Mixed_Case;
3751 -- Casing required for result. Default value of Mixed_Case is used if
3752 -- for some reason we cannot find the right file name in the table.
3754 begin
3755 -- Get length of file name
3757 Flen := 0;
3758 while File (Flen + 1) /= ASCII.NUL loop
3759 Flen := Flen + 1;
3760 end loop;
3762 -- Loop through file names to find matching one. This is a bit slow, but
3763 -- we only do it in error situations so it is not so terrible. Note that
3764 -- if the loop does not exit, then the desired case will be left set to
3765 -- Mixed_Case, this can happen if the name was not in canonical form.
3767 for J in 1 .. Last_Source_File loop
3768 Get_Name_String (Full_Debug_Name (J));
3770 if Name_Len = Flen
3771 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
3772 then
3773 Desired_Case := Identifier_Casing (J);
3774 exit;
3775 end if;
3776 end loop;
3778 -- Copy identifier as given to Name_Buffer
3780 for J in Name_Buffer'Range loop
3781 Name_Buffer (J) := Ident (J);
3783 if Name_Buffer (J) = ASCII.NUL then
3784 Name_Len := J - 1;
3785 exit;
3786 end if;
3787 end loop;
3789 Set_Casing (Desired_Case);
3790 end Set_Identifier_Casing;
3792 -----------------------
3793 -- Set_Ignore_Errors --
3794 -----------------------
3796 procedure Set_Ignore_Errors (To : Boolean) is
3797 begin
3798 Errors_Must_Be_Ignored := To;
3799 end Set_Ignore_Errors;
3801 ------------------------------
3802 -- Set_Msg_Insertion_Column --
3803 ------------------------------
3805 procedure Set_Msg_Insertion_Column is
3806 begin
3807 if RM_Column_Check then
3808 Set_Msg_Str (" in column ");
3809 Set_Msg_Int (Int (Error_Msg_Col) + 1);
3810 end if;
3811 end Set_Msg_Insertion_Column;
3813 ----------------------------
3814 -- Set_Msg_Insertion_Node --
3815 ----------------------------
3817 procedure Set_Msg_Insertion_Node is
3818 K : Node_Kind;
3820 begin
3821 Suppress_Message :=
3822 Error_Msg_Node_1 = Error
3823 or else Error_Msg_Node_1 = Any_Type;
3825 if Error_Msg_Node_1 = Empty then
3826 Set_Msg_Blank_Conditional;
3827 Set_Msg_Str ("<empty>");
3829 elsif Error_Msg_Node_1 = Error then
3830 Set_Msg_Blank;
3831 Set_Msg_Str ("<error>");
3833 elsif Error_Msg_Node_1 = Standard_Void_Type then
3834 Set_Msg_Blank;
3835 Set_Msg_Str ("procedure name");
3837 elsif Nkind (Error_Msg_Node_1) in N_Entity
3838 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
3839 then
3840 Set_Msg_Blank;
3841 Set_Msg_Str ("access to subprogram");
3843 else
3844 Set_Msg_Blank_Conditional;
3846 -- Output name
3848 K := Nkind (Error_Msg_Node_1);
3850 -- If we have operator case, skip quotes since name of operator
3851 -- itself will supply the required quotations. An operator can be an
3852 -- applied use in an expression or an explicit operator symbol, or an
3853 -- identifier whose name indicates it is an operator.
3855 if K in N_Op
3856 or else K = N_Operator_Symbol
3857 or else K = N_Defining_Operator_Symbol
3858 or else ((K = N_Identifier or else K = N_Defining_Identifier)
3859 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
3860 then
3861 Set_Msg_Node (Error_Msg_Node_1);
3863 -- Normal case, not an operator, surround with quotes
3865 else
3866 Set_Msg_Quote;
3867 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
3868 Set_Msg_Node (Error_Msg_Node_1);
3869 Set_Msg_Quote;
3870 end if;
3871 end if;
3873 -- The following assignment ensures that further ampersand insertion
3874 -- characters will correspond to the Error_Msg_Node_# parameter.
3876 Error_Msg_Node_1 := Error_Msg_Node_2;
3877 Error_Msg_Node_2 := Error_Msg_Node_3;
3878 Error_Msg_Node_3 := Error_Msg_Node_4;
3879 Error_Msg_Node_4 := Error_Msg_Node_5;
3880 Error_Msg_Node_5 := Error_Msg_Node_6;
3881 end Set_Msg_Insertion_Node;
3883 --------------------------------------
3884 -- Set_Msg_Insertion_Type_Reference --
3885 --------------------------------------
3887 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
3888 Ent : Entity_Id;
3890 begin
3891 Set_Msg_Blank;
3893 if Error_Msg_Node_1 = Standard_Void_Type then
3894 Set_Msg_Str ("package or procedure name");
3895 return;
3897 elsif Error_Msg_Node_1 = Standard_Exception_Type then
3898 Set_Msg_Str ("exception name");
3899 return;
3901 elsif Error_Msg_Node_1 = Any_Array
3902 or else Error_Msg_Node_1 = Any_Boolean
3903 or else Error_Msg_Node_1 = Any_Character
3904 or else Error_Msg_Node_1 = Any_Composite
3905 or else Error_Msg_Node_1 = Any_Discrete
3906 or else Error_Msg_Node_1 = Any_Fixed
3907 or else Error_Msg_Node_1 = Any_Integer
3908 or else Error_Msg_Node_1 = Any_Modular
3909 or else Error_Msg_Node_1 = Any_Numeric
3910 or else Error_Msg_Node_1 = Any_Real
3911 or else Error_Msg_Node_1 = Any_Scalar
3912 or else Error_Msg_Node_1 = Any_String
3913 then
3914 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
3915 Set_Msg_Name_Buffer;
3916 return;
3918 elsif Error_Msg_Node_1 = Universal_Integer then
3919 Set_Msg_Str ("type universal integer");
3920 return;
3922 elsif Error_Msg_Node_1 = Universal_Real then
3923 Set_Msg_Str ("type universal real");
3924 return;
3926 elsif Error_Msg_Node_1 = Universal_Fixed then
3927 Set_Msg_Str ("type universal fixed");
3928 return;
3930 elsif Error_Msg_Node_1 = Universal_Access then
3931 Set_Msg_Str ("type universal access");
3932 return;
3933 end if;
3935 -- Special case of anonymous array
3937 if Nkind (Error_Msg_Node_1) in N_Entity
3938 and then Is_Array_Type (Error_Msg_Node_1)
3939 and then Present (Related_Array_Object (Error_Msg_Node_1))
3940 then
3941 Set_Msg_Str ("type of ");
3942 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
3943 Set_Msg_Str (" declared");
3944 Set_Msg_Insertion_Line_Number
3945 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
3946 return;
3947 end if;
3949 -- If we fall through, it is not a special case, so first output
3950 -- the name of the type, preceded by private for a private type
3952 if Is_Private_Type (Error_Msg_Node_1) then
3953 Set_Msg_Str ("private type ");
3954 else
3955 Set_Msg_Str ("type ");
3956 end if;
3958 Ent := Error_Msg_Node_1;
3960 if Is_Internal_Name (Chars (Ent)) then
3961 Unwind_Internal_Type (Ent);
3962 end if;
3964 -- Types in Standard are displayed as "Standard.name"
3966 if Sloc (Ent) <= Standard_Location then
3967 Set_Msg_Quote;
3968 Set_Msg_Str ("Standard.");
3969 Set_Msg_Node (Ent);
3970 Add_Class;
3971 Set_Msg_Quote;
3973 -- Types in other language defined units are displayed as
3974 -- "package-name.type-name"
3976 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
3977 Get_Unqualified_Decoded_Name_String
3978 (Unit_Name (Get_Source_Unit (Ent)));
3979 Name_Len := Name_Len - 2;
3980 Set_Msg_Blank_Conditional;
3981 Set_Msg_Quote;
3982 Set_Casing (Mixed_Case);
3983 Set_Msg_Name_Buffer;
3984 Set_Msg_Char ('.');
3985 Set_Casing (Mixed_Case);
3986 Set_Msg_Node (Ent);
3987 Add_Class;
3988 Set_Msg_Quote;
3990 -- All other types display as "type name" defined at line xxx
3991 -- possibly qualified if qualification is requested.
3993 else
3994 Set_Msg_Quote;
3995 Set_Qualification (Error_Msg_Qual_Level, Ent);
3996 Set_Msg_Node (Ent);
3997 Add_Class;
3999 -- If we did not print a name (e.g. in the case of an anonymous
4000 -- subprogram type), there is no name to print, so remove quotes.
4002 if Buffer_Ends_With ('"') then
4003 Buffer_Remove ('"');
4004 else
4005 Set_Msg_Quote;
4006 end if;
4007 end if;
4009 -- If the original type did not come from a predefined file, add the
4010 -- location where the type was defined.
4012 if Sloc (Error_Msg_Node_1) > Standard_Location
4013 and then
4014 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
4015 then
4016 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
4017 Set_Msg_Str (" defined");
4018 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
4020 -- If it did come from a predefined file, deal with the case where
4021 -- this was a file with a generic instantiation from elsewhere.
4023 else
4024 if Sloc (Error_Msg_Node_1) > Standard_Location then
4025 declare
4026 Iloc : constant Source_Ptr :=
4027 Instantiation_Location (Sloc (Error_Msg_Node_1));
4029 begin
4030 if Iloc /= No_Location
4031 and then not Suppress_Instance_Location
4032 then
4033 Set_Msg_Str (" from instance");
4034 Set_Msg_Insertion_Line_Number (Iloc, Flag);
4035 end if;
4036 end;
4037 end if;
4038 end if;
4039 end Set_Msg_Insertion_Type_Reference;
4041 ---------------------------------
4042 -- Set_Msg_Insertion_Unit_Name --
4043 ---------------------------------
4045 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
4046 begin
4047 if Error_Msg_Unit_1 = No_Unit_Name then
4048 null;
4050 elsif Error_Msg_Unit_1 = Error_Unit_Name then
4051 Set_Msg_Blank;
4052 Set_Msg_Str ("<error>");
4054 else
4055 Get_Unit_Name_String (Global_Name_Buffer, Error_Msg_Unit_1, Suffix);
4056 Set_Msg_Blank;
4057 Set_Msg_Quote;
4058 Set_Msg_Name_Buffer;
4059 Set_Msg_Quote;
4060 end if;
4062 -- The following assignment ensures that a second percent insertion
4063 -- character will correspond to the Error_Msg_Unit_2 parameter.
4065 Error_Msg_Unit_1 := Error_Msg_Unit_2;
4066 end Set_Msg_Insertion_Unit_Name;
4068 ------------------
4069 -- Set_Msg_Node --
4070 ------------------
4072 procedure Set_Msg_Node (Node : Node_Id) is
4073 Loc : Source_Ptr;
4074 Ent : Entity_Id;
4075 Nam : Name_Id;
4077 begin
4078 case Nkind (Node) is
4079 when N_Designator =>
4080 Set_Msg_Node (Name (Node));
4081 Set_Msg_Char ('.');
4082 Set_Msg_Node (Identifier (Node));
4083 return;
4085 when N_Defining_Program_Unit_Name =>
4086 Set_Msg_Node (Name (Node));
4087 Set_Msg_Char ('.');
4088 Set_Msg_Node (Defining_Identifier (Node));
4089 return;
4091 when N_Expanded_Name
4092 | N_Selected_Component
4094 Set_Msg_Node (Prefix (Node));
4095 Set_Msg_Char ('.');
4096 Set_Msg_Node (Selector_Name (Node));
4097 return;
4099 when others =>
4100 null;
4101 end case;
4103 -- The only remaining possibilities are identifiers, defining
4104 -- identifiers, pragmas, and pragma argument associations.
4106 if Nkind (Node) = N_Pragma then
4107 Nam := Pragma_Name (Node);
4108 Loc := Sloc (Node);
4110 -- The other cases have Chars fields
4112 -- First deal with internal names, which generally represent something
4113 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4114 -- something with a Chars field that is not an internal name, use that.
4116 elsif Is_Internal_Name (Chars (Node))
4117 and then Nkind (Original_Node (Node)) in N_Has_Chars
4118 and then not Is_Internal_Name (Chars (Original_Node (Node)))
4119 then
4120 Nam := Chars (Original_Node (Node));
4121 Loc := Sloc (Original_Node (Node));
4123 -- Another shot for internal names, in the case of internal type names,
4124 -- we try to find a reasonable representation for the external name.
4126 elsif Is_Internal_Name (Chars (Node))
4127 and then
4128 ((Is_Entity_Name (Node)
4129 and then Present (Entity (Node))
4130 and then Is_Type (Entity (Node)))
4131 or else
4132 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
4133 then
4134 if Nkind (Node) = N_Identifier then
4135 Ent := Entity (Node);
4136 else
4137 Ent := Node;
4138 end if;
4140 Loc := Sloc (Ent);
4142 -- If the type is the designated type of an access_to_subprogram,
4143 -- then there is no name to provide in the call.
4145 if Ekind (Ent) = E_Subprogram_Type then
4146 return;
4148 -- Otherwise, we will be able to find some kind of name to output
4150 else
4151 Unwind_Internal_Type (Ent);
4152 Nam := Chars (Ent);
4153 end if;
4155 -- If not internal name, or if we could not find a reasonable possible
4156 -- substitution for the internal name, just use name in Chars field.
4158 else
4159 Nam := Chars (Node);
4160 Loc := Sloc (Node);
4161 end if;
4163 -- At this stage, the name to output is in Nam
4165 Get_Unqualified_Decoded_Name_String (Nam);
4167 -- Remove trailing upper case letters from the name (useful for
4168 -- dealing with some cases of internal names).
4170 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
4171 Name_Len := Name_Len - 1;
4172 end loop;
4174 -- If we have any of the names from standard that start with the
4175 -- characters "any " (e.g. Any_Type), then kill the message since
4176 -- almost certainly it is a junk cascaded message.
4178 if Name_Len > 4
4179 and then Name_Buffer (1 .. 4) = "any "
4180 then
4181 Kill_Message := True;
4182 end if;
4184 -- If we still have an internal name, kill the message (will only
4185 -- work if we already had errors!)
4187 if Is_Internal_Name then
4188 Kill_Message := True;
4189 end if;
4190 -- Remaining step is to adjust casing and possibly add 'Class
4192 Adjust_Name_Case (Global_Name_Buffer, Loc);
4193 Set_Msg_Name_Buffer;
4194 Add_Class;
4195 end Set_Msg_Node;
4197 ------------------
4198 -- Set_Msg_Text --
4199 ------------------
4201 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
4202 C : Character; -- Current character
4203 P : Natural; -- Current index;
4205 procedure Skip_Msg_Insertion_Warning (C : Character);
4206 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4207 -- sequences using < instead of ?). The caller has already bumped
4208 -- the pointer past the initial ? or < and C is set to this initial
4209 -- character (? or <). This procedure skips past the rest of the
4210 -- sequence. We do not need to set Msg_Insertion_Char, since this
4211 -- was already done during the message prescan.
4212 -- No validity check is performed as the insertion sequence is
4213 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4214 -- erroutc.adb for the validity checks.
4216 --------------------------------
4217 -- Skip_Msg_Insertion_Warning --
4218 --------------------------------
4220 procedure Skip_Msg_Insertion_Warning (C : Character) is
4221 begin
4222 if P <= Text'Last and then Text (P) = C then
4223 P := P + 1;
4225 elsif P < Text'Last and then Text (P + 1) = C
4226 and then Text (P) in 'a' .. 'z' | 'A' .. 'Z' |
4227 '0' .. '9' | '*' | '$'
4228 then
4229 P := P + 2;
4231 elsif P + 1 < Text'Last and then Text (P + 2) = C
4232 and then Text (P) in '.' | '_'
4233 and then Text (P + 1) in 'a' .. 'z'
4234 then
4235 P := P + 3;
4236 end if;
4237 end Skip_Msg_Insertion_Warning;
4239 -- Start of processing for Set_Msg_Text
4241 begin
4242 Manual_Quote_Mode := False;
4243 Msglen := 0;
4244 Flag_Source := Get_Source_File_Index (Flag);
4246 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4247 -- will be used (Info field in error message object) to put back the
4248 -- string when it is printed. We need to do this, or we get confused
4249 -- with instantiation continuations.
4251 if Text'Length > 6
4252 and then Text (Text'First .. Text'First + 5) = "info: "
4253 then
4254 P := Text'First + 6;
4255 else
4256 P := Text'First;
4257 end if;
4259 -- Loop through characters of message
4261 while P <= Text'Last loop
4262 C := Text (P);
4263 P := P + 1;
4265 -- Check for insertion character or sequence
4267 case C is
4268 when '%' =>
4269 if P <= Text'Last and then Text (P) = '%' then
4270 P := P + 1;
4271 Set_Msg_Insertion_Name_Literal;
4272 else
4273 Set_Msg_Insertion_Name;
4274 end if;
4276 when '$' =>
4277 if P <= Text'Last and then Text (P) = '$' then
4278 P := P + 1;
4279 Set_Msg_Insertion_Unit_Name (Suffix => False);
4280 else
4281 Set_Msg_Insertion_Unit_Name;
4282 end if;
4284 when '{' =>
4285 Set_Msg_Insertion_File_Name;
4287 when '}' =>
4288 Set_Msg_Insertion_Type_Reference (Flag);
4290 when '*' =>
4291 Set_Msg_Insertion_Reserved_Name;
4293 when '&' =>
4294 Set_Msg_Insertion_Node;
4296 when '#' =>
4297 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
4299 when '\' =>
4300 Continuation := True;
4302 if P <= Text'Last and then Text (P) = '\' then
4303 Continuation_New_Line := True;
4304 P := P + 1;
4305 end if;
4307 when '@' =>
4308 Set_Msg_Insertion_Column;
4310 when '>' =>
4311 Set_Msg_Insertion_Run_Time_Name;
4313 when '^' =>
4314 Set_Msg_Insertion_Uint;
4316 when '`' =>
4317 Manual_Quote_Mode := not Manual_Quote_Mode;
4318 Set_Msg_Char ('"');
4320 when '!' =>
4321 null; -- already dealt with
4323 when '?' =>
4324 Skip_Msg_Insertion_Warning ('?');
4326 when '<' =>
4327 Skip_Msg_Insertion_Warning ('<');
4329 when '|' =>
4330 null; -- already dealt with
4332 when ''' =>
4333 Set_Msg_Char (Text (P));
4334 P := P + 1;
4336 when '~' =>
4337 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
4339 -- Upper case letter
4341 when 'A' .. 'Z' =>
4343 -- Start of reserved word if two or more
4345 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
4346 P := P - 1;
4347 Set_Msg_Insertion_Reserved_Word (Text, P);
4349 -- Single upper case letter is just inserted
4351 else
4352 Set_Msg_Char (C);
4353 end if;
4355 -- '[' (will be/would have been raised at run time)
4357 when '[' =>
4359 -- "[]" (insertion of error code)
4361 if P <= Text'Last and then Text (P) = ']' then
4362 P := P + 1;
4363 Set_Msg_Insertion_Code;
4365 else
4366 -- Switch the message from a warning to an error if the flag
4367 -- -gnatwE is specified to treat run-time exception warnings
4368 -- as errors.
4370 if Is_Warning_Msg
4371 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
4372 then
4373 Is_Warning_Msg := False;
4374 Is_Runtime_Raise := True;
4375 end if;
4377 if Is_Warning_Msg then
4378 Set_Msg_Str ("will be raised at run time");
4379 else
4380 Set_Msg_Str ("would have been raised at run time");
4381 end if;
4382 end if;
4384 -- ']' (may be/might have been raised at run time)
4386 when ']' =>
4387 if Is_Warning_Msg then
4388 Set_Msg_Str ("may be raised at run time");
4389 else
4390 Set_Msg_Str ("might have been raised at run time");
4391 end if;
4393 -- Normal character with no special treatment
4395 when others =>
4396 Set_Msg_Char (C);
4397 end case;
4398 end loop;
4399 end Set_Msg_Text;
4401 ----------------
4402 -- Set_Posted --
4403 ----------------
4405 procedure Set_Posted (N : Node_Id) is
4406 P : Node_Id;
4408 begin
4409 if Is_Serious_Error then
4411 -- We always set Error_Posted on the node itself
4413 Set_Error_Posted (N);
4415 -- If it is a subexpression, then set Error_Posted on parents up to
4416 -- and including the first non-subexpression construct. This helps
4417 -- avoid cascaded error messages within a single expression.
4419 P := N;
4420 loop
4421 P := Parent (P);
4422 exit when No (P);
4423 Set_Error_Posted (P);
4424 exit when Nkind (P) not in N_Subexpr;
4425 end loop;
4427 if Nkind (P) in N_Pragma_Argument_Association
4428 | N_Component_Association
4429 | N_Discriminant_Association
4430 | N_Generic_Association
4431 | N_Parameter_Association
4432 then
4433 Set_Error_Posted (Parent (P));
4434 end if;
4436 -- A special check, if we just posted an error on an attribute
4437 -- definition clause, then also set the entity involved as posted.
4438 -- For example, this stops complaining about the alignment after
4439 -- complaining about the size, which is likely to be useless.
4441 if Nkind (P) = N_Attribute_Definition_Clause then
4442 if Is_Entity_Name (Name (P)) then
4443 Set_Error_Posted (Entity (Name (P)));
4444 end if;
4445 end if;
4446 end if;
4447 end Set_Posted;
4449 -----------------------
4450 -- Set_Qualification --
4451 -----------------------
4453 procedure Set_Qualification (N : Nat; E : Entity_Id) is
4454 begin
4455 if N /= 0 and then Scope (E) /= Standard_Standard then
4456 Set_Qualification (N - 1, Scope (E));
4457 Set_Msg_Node (Scope (E));
4458 Set_Msg_Char ('.');
4459 end if;
4460 end Set_Qualification;
4462 ------------------------
4463 -- Special_Msg_Delete --
4464 ------------------------
4466 -- Is it really right to have all this specialized knowledge in errout?
4468 function Special_Msg_Delete
4469 (Msg : String;
4470 N : Node_Or_Entity_Id;
4471 E : Node_Or_Entity_Id) return Boolean
4473 begin
4474 -- Never delete messages in -gnatdO mode
4476 if Debug_Flag_OO then
4477 return False;
4479 -- Processing for "Size too small" messages
4481 elsif Is_Size_Too_Small_Message (Msg) then
4483 -- Suppress "size too small" errors in CodePeer mode, since code may
4484 -- be analyzed in a different configuration than the one used for
4485 -- compilation. Even when the configurations match, this message
4486 -- may be issued on correct code, because pragma Pack is ignored
4487 -- in CodePeer mode.
4489 if CodePeer_Mode then
4490 return True;
4492 -- When a size is wrong for a frozen type there is no explicit size
4493 -- clause, and other errors have occurred, suppress the message,
4494 -- since it is likely that this size error is a cascaded result of
4495 -- other errors. The reason we eliminate unfrozen types is that
4496 -- messages issued before the freeze type are for sure OK.
4498 elsif Nkind (N) in N_Entity
4499 and then Is_Frozen (E)
4500 and then Serious_Errors_Detected > 0
4501 and then Nkind (N) /= N_Component_Clause
4502 and then Nkind (Parent (N)) /= N_Component_Clause
4503 and then
4504 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
4505 and then
4506 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
4507 and then
4508 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
4509 then
4510 return True;
4511 end if;
4512 end if;
4514 -- All special tests complete, so go ahead with message
4516 return False;
4517 end Special_Msg_Delete;
4519 -----------------
4520 -- SPARK_Msg_N --
4521 -----------------
4523 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
4524 begin
4525 if SPARK_Mode /= Off then
4526 Error_Msg_N (Msg, N);
4527 end if;
4528 end SPARK_Msg_N;
4530 ------------------
4531 -- SPARK_Msg_NE --
4532 ------------------
4534 procedure SPARK_Msg_NE
4535 (Msg : String;
4536 N : Node_Or_Entity_Id;
4537 E : Node_Or_Entity_Id)
4539 begin
4540 if SPARK_Mode /= Off then
4541 Error_Msg_NE (Msg, N, E);
4542 end if;
4543 end SPARK_Msg_NE;
4545 --------------------------
4546 -- Unwind_Internal_Type --
4547 --------------------------
4549 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
4550 Derived : Boolean := False;
4551 Mchar : Character;
4552 Old_Ent : Entity_Id;
4554 begin
4555 -- Undo placement of a quote, since we will put it back later
4557 Mchar := Msg_Buffer (Msglen);
4559 if Mchar = '"' then
4560 Msglen := Msglen - 1;
4561 end if;
4563 -- The loop here deals with recursive types, we are trying to find a
4564 -- related entity that is not an implicit type. Note that the check with
4565 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4566 -- "type derived from" message more than once in the case where we climb
4567 -- up multiple levels.
4569 Find : loop
4570 Old_Ent := Ent;
4572 -- Implicit access type, use directly designated type In Ada 2005,
4573 -- the designated type may be an anonymous access to subprogram, in
4574 -- which case we can only point to its definition.
4576 if Is_Access_Type (Ent) then
4577 if Ekind (Ent) = E_Access_Subprogram_Type
4578 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
4579 or else Is_Access_Protected_Subprogram_Type (Ent)
4580 then
4581 Ent := Directly_Designated_Type (Ent);
4583 if not Comes_From_Source (Ent) then
4584 if Buffer_Ends_With ("type ") then
4585 Buffer_Remove ("type ");
4586 end if;
4587 end if;
4589 if Ekind (Ent) = E_Function then
4590 Set_Msg_Str ("access to function ");
4591 elsif Ekind (Ent) = E_Procedure then
4592 Set_Msg_Str ("access to procedure ");
4593 else
4594 Set_Msg_Str ("access to subprogram");
4595 end if;
4597 exit Find;
4599 -- Type is access to object, named or anonymous
4601 else
4602 Set_Msg_Str ("access to ");
4603 Ent := Directly_Designated_Type (Ent);
4604 end if;
4606 -- Classwide type
4608 elsif Is_Class_Wide_Type (Ent) then
4609 Class_Flag := True;
4610 Ent := Root_Type (Ent);
4612 -- Use base type if this is a subtype
4614 elsif Ent /= Base_Type (Ent) then
4615 Buffer_Remove ("type ");
4617 -- Avoid duplication "subtype of subtype of", and also replace
4618 -- "derived from subtype of" simply by "derived from"
4620 if not Buffer_Ends_With ("subtype of ")
4621 and then not Buffer_Ends_With ("derived from ")
4622 then
4623 Set_Msg_Str ("subtype of ");
4624 end if;
4626 Ent := Base_Type (Ent);
4628 -- If this is a base type with a first named subtype, use the first
4629 -- named subtype instead. This is not quite accurate in all cases,
4630 -- but it makes too much noise to be accurate and add 'Base in all
4631 -- cases. Note that we only do this is the first named subtype is not
4632 -- itself an internal name. This avoids the obvious loop (subtype ->
4633 -- basetype -> subtype) which would otherwise occur).
4635 else
4636 declare
4637 FST : constant Entity_Id := First_Subtype (Ent);
4639 begin
4640 if not Is_Internal_Name (Chars (FST)) then
4641 Ent := FST;
4642 exit Find;
4644 -- Otherwise use root type
4646 else
4647 if not Derived then
4648 Buffer_Remove ("type ");
4650 -- Test for "subtype of type derived from" which seems
4651 -- excessive and is replaced by "type derived from".
4653 Buffer_Remove ("subtype of");
4655 -- Avoid duplicated "type derived from type derived from"
4657 if not Buffer_Ends_With ("type derived from ") then
4658 Set_Msg_Str ("type derived from ");
4659 end if;
4661 Derived := True;
4662 end if;
4663 end if;
4664 end;
4666 Ent := Etype (Ent);
4667 end if;
4669 -- If we are stuck in a loop, get out and settle for the internal
4670 -- name after all. In this case we set to kill the message if it is
4671 -- not the first error message (we really try hard not to show the
4672 -- dirty laundry of the implementation to the poor user).
4674 if Ent = Old_Ent then
4675 Kill_Message := True;
4676 exit Find;
4677 end if;
4679 -- Get out if we finally found a non-internal name to use
4681 exit Find when not Is_Internal_Name (Chars (Ent));
4682 end loop Find;
4684 if Mchar = '"' then
4685 Set_Msg_Char ('"');
4686 end if;
4687 end Unwind_Internal_Type;
4689 --------------------
4690 -- Warn_Insertion --
4691 --------------------
4693 function Warn_Insertion return String is
4694 begin
4695 if Warning_Msg_Char = "? " then
4696 return "??";
4697 elsif Warning_Msg_Char = " " then
4698 return "?";
4699 elsif Warning_Msg_Char (2) = ' ' then
4700 return '?' & Warning_Msg_Char (1) & '?';
4701 else
4702 return '?' & Warning_Msg_Char & '?';
4703 end if;
4704 end Warn_Insertion;
4706 end Errout;