[testsuite] [i386] work around fails with --enable-frame-pointer
[official-gcc.git] / gcc / ada / errout.adb
blobd28a410f47b7dc7db700e4fccbd5a37f69ab66c2
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-2024, 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 Should_Ignore_Pragma_SPARK_Mode return Boolean;
189 -- Return whether pragma Ignore_Pragma (SPARK_Mode) was specified. This is
190 -- similar to Sem_Util.Should_Ignore_Pragma_Par but located here to avoid
191 -- problematic dependency on Sem_Util.
193 function Special_Msg_Delete
194 (Msg : String;
195 N : Node_Or_Entity_Id;
196 E : Node_Or_Entity_Id) return Boolean;
197 -- This function is called from Error_Msg_NEL, passing the message Msg,
198 -- node N on which the error is to be posted, and the entity or node E
199 -- to be used for an & insertion in the message if any. The job of this
200 -- procedure is to test for certain cascaded messages that we would like
201 -- to suppress. If the message is to be suppressed then we return True.
202 -- If the message should be generated (the normal case) False is returned.
204 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
205 -- This procedure is given an entity id for an internal type, i.e. a type
206 -- with an internal name. It unwinds the type to try to get to something
207 -- reasonably printable, generating prefixes like "subtype of", "access
208 -- to", etc along the way in the buffer. The value in Ent on return is the
209 -- final name to be printed. Hopefully this is not an internal name, but in
210 -- some internal name cases, it is an internal name, and has to be printed
211 -- anyway (although in this case the message has been killed if possible).
212 -- The global variable Class_Flag is set to True if the resulting entity
213 -- should have 'Class appended to its name (see Add_Class procedure), and
214 -- is otherwise unchanged.
216 function Warn_Insertion return String;
217 -- This is called for warning messages only (so Warning_Msg_Char is set)
218 -- and returns a corresponding string to use at the beginning of generated
219 -- auxiliary messages, such as "in instantiation at ...".
220 -- "?" returns "??"
221 -- " " returns "?"
222 -- other trimmed, prefixed and suffixed with "?".
224 -----------------------
225 -- Change_Error_Text --
226 -----------------------
228 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
229 Save_Next : Error_Msg_Id;
230 Err_Id : Error_Msg_Id := Error_Id;
232 begin
233 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr.Ptr);
234 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
236 -- If in immediate error message mode, output modified error message now
237 -- This is just a bit tricky, because we want to output just a single
238 -- message, and the messages we modified is already linked in. We solve
239 -- this by temporarily resetting its forward pointer to empty.
241 if Debug_Flag_OO then
242 Save_Next := Errors.Table (Error_Id).Next;
243 Errors.Table (Error_Id).Next := No_Error_Msg;
244 Write_Eol;
245 Output_Source_Line
246 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
247 Output_Error_Msgs (Err_Id);
248 Errors.Table (Error_Id).Next := Save_Next;
249 end if;
250 end Change_Error_Text;
252 ------------------------
253 -- Compilation_Errors --
254 ------------------------
256 function Compilation_Errors return Boolean is
257 begin
258 if not Finalize_Called then
259 raise Program_Error;
260 else
261 return Erroutc.Compilation_Errors;
262 end if;
263 end Compilation_Errors;
265 --------------------------------------
266 -- Delete_Warning_And_Continuations --
267 --------------------------------------
269 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
270 Id : Error_Msg_Id;
272 begin
273 pragma Assert (not Errors.Table (Msg).Msg_Cont);
275 Id := Msg;
276 loop
277 declare
278 M : Error_Msg_Object renames Errors.Table (Id);
280 begin
281 if not M.Deleted then
282 M.Deleted := True;
283 Warnings_Detected := Warnings_Detected - 1;
285 if M.Info then
286 Warning_Info_Messages := Warning_Info_Messages - 1;
287 end if;
289 if M.Warn_Err then
290 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
291 end if;
292 end if;
294 Id := M.Next;
295 exit when Id = No_Error_Msg;
296 exit when not Errors.Table (Id).Msg_Cont;
297 end;
298 end loop;
299 end Delete_Warning_And_Continuations;
301 ---------------
302 -- Error_Msg --
303 ---------------
305 -- Error_Msg posts a flag at the given location, except that if the
306 -- Flag_Location/Flag_Span points within a generic template and corresponds
307 -- to an instantiation of this generic template, then the actual message
308 -- will be posted on the generic instantiation, along with additional
309 -- messages referencing the generic declaration.
311 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
312 begin
313 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
314 end Error_Msg;
316 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
317 begin
318 Error_Msg (Msg, Flag_Span, Current_Node);
319 end Error_Msg;
321 procedure Error_Msg
322 (Msg : String;
323 Flag_Location : Source_Ptr;
324 Is_Compile_Time_Pragma : Boolean)
326 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
327 begin
328 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
329 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
330 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
331 end Error_Msg;
333 procedure Error_Msg
334 (Msg : String;
335 Flag_Location : Source_Ptr;
336 N : Node_Id)
338 begin
339 Error_Msg (Msg, To_Span (Flag_Location), N);
340 end Error_Msg;
342 procedure Error_Msg
343 (Msg : String;
344 Flag_Span : Source_Span;
345 N : Node_Id)
347 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
349 Sindex : Source_File_Index;
350 -- Source index for flag location
352 Orig_Loc : Source_Ptr;
353 -- Original location of Flag_Location (i.e. location in original
354 -- template in instantiation case, otherwise unchanged).
356 begin
357 -- Return if all errors are to be ignored
359 if Get_Ignore_Errors then
360 return;
361 end if;
363 -- If we already have messages, and we are trying to place a message at
364 -- No_Location, then just ignore the attempt since we assume that what
365 -- is happening is some cascaded junk. Note that this is safe in the
366 -- sense that proceeding will surely bomb. We will also bomb if the flag
367 -- location is No_Location and we don't have any messages so far, but
368 -- that is a real bug and a legitimate bomb, so we go ahead.
370 if Flag_Location = No_Location
371 and then Total_Errors_Detected > 0
372 then
373 return;
374 end if;
376 -- Start of processing for new message
378 Sindex := Get_Source_File_Index (Flag_Location);
379 Prescan_Message (Msg);
380 Orig_Loc := Original_Location (Flag_Location);
382 -- If the current location is in an instantiation, the issue arises of
383 -- whether to post the message on the template or the instantiation.
385 -- The way we decide is to see if we have posted the same message on
386 -- the template when we compiled the template (the template is always
387 -- compiled before any instantiations). For this purpose, we use a
388 -- separate table of messages. The reason we do this is twofold:
390 -- First, the messages can get changed by various processing
391 -- including the insertion of tokens etc, making it hard to
392 -- do the comparison.
394 -- Second, we will suppress a warning on a template if it is not in
395 -- the current extended source unit. That's reasonable and means we
396 -- don't want the warning on the instantiation here either, but it
397 -- does mean that the main error table would not in any case include
398 -- the message.
400 if Flag_Location = Orig_Loc then
401 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
402 Warn_On_Instance := False;
404 -- Here we have an instance message
406 else
407 -- Delete if debug flag off, and this message duplicates a message
408 -- already posted on the corresponding template
410 if not Debug_Flag_GG then
411 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
412 if Msg = Non_Instance_Msgs.Table (J).Msg.all
413 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
414 then
415 return;
416 end if;
417 end loop;
418 end if;
420 -- No duplicate, so error/warning will be posted on instance
422 Warn_On_Instance := Is_Warning_Msg;
423 end if;
425 -- Ignore warning message that is suppressed for this location. Note
426 -- that style checks are not considered warning messages for this
427 -- purpose.
429 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String
430 then
431 return;
433 -- For style messages, check too many messages so far
435 elsif Is_Style_Msg
436 and then Maximum_Messages /= 0
437 and then Warnings_Detected >= Maximum_Messages
438 then
439 return;
441 -- Suppress warnings inside a loop that is known to be null or is
442 -- probably null (i.e. when loop executes only if invalid values
443 -- present). In either case warnings in the loop are likely to be junk.
445 elsif Is_Warning_Msg and then Present (N) then
447 declare
448 P : Node_Id;
450 begin
451 P := Parent (N);
452 while Present (P) loop
453 if Nkind (P) = N_Loop_Statement
454 and then Suppress_Loop_Warnings (P)
455 then
456 return;
457 end if;
459 P := Parent (P);
460 end loop;
461 end;
462 end if;
464 -- The idea at this stage is that we have two kinds of messages
466 -- First, we have those messages that are to be placed as requested at
467 -- Flag_Location. This includes messages that have nothing to do with
468 -- generics, and also messages placed on generic templates that reflect
469 -- an error in the template itself. For such messages we simply call
470 -- Error_Msg_Internal to place the message in the requested location.
472 if Instantiation (Sindex) = No_Location then
473 Error_Msg_Internal (Msg, Flag_Span, Flag_Span, False, N);
474 return;
475 end if;
477 -- If we are trying to flag an error in an instantiation, we may have
478 -- a generic contract violation. What we generate in this case is:
480 -- instantiation error at ...
481 -- original error message
483 -- or
485 -- warning: in instantiation at ...
486 -- warning: original warning message
488 -- or
490 -- info: in instantiation at ...
491 -- info: original info message
493 -- All these messages are posted at the location of the top level
494 -- instantiation. If there are nested instantiations, then the
495 -- instantiation error message can be repeated, pointing to each
496 -- of the relevant instantiations.
498 -- Note: the instantiation mechanism is also shared for inlining of
499 -- subprogram bodies when front end inlining is done. In this case the
500 -- messages have the form:
502 -- in inlined body at ...
503 -- original error message
505 -- or
507 -- warning: in inlined body at ...
508 -- warning: original warning message
510 -- or
512 -- info: in inlined body at ...
513 -- info: original info message
515 -- OK, here we have an instantiation error, and we need to generate the
516 -- error on the instantiation, rather than on the template.
518 declare
519 Actual_Error_Loc : Source_Ptr;
520 -- Location of outer level instantiation in instantiation case, or
521 -- just a copy of Flag_Location in the normal case. This is the
522 -- location where all error messages will actually be posted.
524 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
525 -- Save possible location set for caller's message. We need to use
526 -- Error_Msg_Sloc for the location of the instantiation error but we
527 -- have to preserve a possible original value.
529 X : Source_File_Index;
531 Msg_Cont_Status : Boolean;
532 -- Used to label continuation lines in instantiation case with
533 -- proper Msg_Cont status.
535 begin
536 -- Loop to find highest level instantiation, where all error
537 -- messages will be placed.
539 X := Sindex;
540 loop
541 Actual_Error_Loc := Instantiation (X);
542 X := Get_Source_File_Index (Actual_Error_Loc);
543 exit when Instantiation (X) = No_Location;
544 end loop;
546 -- Since we are generating the messages at the instantiation point in
547 -- any case, we do not want the references to the bad lines in the
548 -- instance to be annotated with the location of the instantiation.
550 Suppress_Instance_Location := True;
551 Msg_Cont_Status := False;
553 -- Loop to generate instantiation messages
555 Error_Msg_Sloc := Flag_Location;
556 X := Get_Source_File_Index (Flag_Location);
557 while Instantiation (X) /= No_Location loop
559 -- Suppress instantiation message on continuation lines
561 if Msg (Msg'First) /= '\' then
563 -- Case of inlined body
565 if Inlined_Body (X) then
566 if Is_Info_Msg then
567 Error_Msg_Internal
568 (Msg => "info: in inlined body #",
569 Span => To_Span (Actual_Error_Loc),
570 Opan => Flag_Span,
571 Msg_Cont => Msg_Cont_Status,
572 Node => N);
574 elsif Is_Warning_Msg then
575 Error_Msg_Internal
576 (Msg => Warn_Insertion & "in inlined body #",
577 Span => To_Span (Actual_Error_Loc),
578 Opan => Flag_Span,
579 Msg_Cont => Msg_Cont_Status,
580 Node => N);
582 elsif Is_Style_Msg then
583 Error_Msg_Internal
584 (Msg => "style: in inlined body #",
585 Span => To_Span (Actual_Error_Loc),
586 Opan => Flag_Span,
587 Msg_Cont => Msg_Cont_Status,
588 Node => N);
590 else
591 Error_Msg_Internal
592 (Msg => "error in inlined body #",
593 Span => To_Span (Actual_Error_Loc),
594 Opan => Flag_Span,
595 Msg_Cont => Msg_Cont_Status,
596 Node => N);
597 end if;
599 -- Case of generic instantiation
601 else
602 if Is_Info_Msg then
603 Error_Msg_Internal
604 (Msg => "info: in instantiation #",
605 Span => To_Span (Actual_Error_Loc),
606 Opan => Flag_Span,
607 Msg_Cont => Msg_Cont_Status,
608 Node => N);
610 elsif Is_Warning_Msg then
611 Error_Msg_Internal
612 (Msg => Warn_Insertion & "in instantiation #",
613 Span => To_Span (Actual_Error_Loc),
614 Opan => Flag_Span,
615 Msg_Cont => Msg_Cont_Status,
616 Node => N);
618 elsif Is_Style_Msg then
619 Error_Msg_Internal
620 (Msg => "style: in instantiation #",
621 Span => To_Span (Actual_Error_Loc),
622 Opan => Flag_Span,
623 Msg_Cont => Msg_Cont_Status,
624 Node => N);
626 else
627 Error_Msg_Internal
628 (Msg => "instantiation error #",
629 Span => To_Span (Actual_Error_Loc),
630 Opan => Flag_Span,
631 Msg_Cont => Msg_Cont_Status,
632 Node => N);
633 end if;
634 end if;
635 end if;
637 Error_Msg_Sloc := Instantiation (X);
638 X := Get_Source_File_Index (Error_Msg_Sloc);
639 Msg_Cont_Status := True;
640 end loop;
642 Suppress_Instance_Location := False;
643 Error_Msg_Sloc := Save_Error_Msg_Sloc;
645 -- Here we output the original message on the outer instantiation
647 Error_Msg_Internal
648 (Msg => Msg,
649 Span => To_Span (Actual_Error_Loc),
650 Opan => Flag_Span,
651 Msg_Cont => Msg_Cont_Status,
652 Node => N);
653 end;
654 end Error_Msg;
656 ----------------------------------
657 -- Error_Msg_Ada_2005_Extension --
658 ----------------------------------
660 procedure Error_Msg_Ada_2005_Extension (Extension : String) is
661 Loc : constant Source_Ptr := Token_Ptr;
662 begin
663 if Ada_Version < Ada_2005 then
664 Error_Msg (Extension & " is an Ada 2005 extension", Loc);
666 if No (Ada_Version_Pragma) then
667 Error_Msg ("\unit must be compiled with -gnat05 switch", Loc);
668 else
669 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
670 Error_Msg ("\incompatible with Ada version set#", Loc);
671 end if;
672 end if;
673 end Error_Msg_Ada_2005_Extension;
675 --------------------------------
676 -- Error_Msg_Ada_2012_Feature --
677 --------------------------------
679 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
680 begin
681 if Ada_Version < Ada_2012 then
682 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
684 if No (Ada_Version_Pragma) then
685 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
686 else
687 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
688 Error_Msg ("\incompatible with Ada version set#", Loc);
689 end if;
690 end if;
691 end Error_Msg_Ada_2012_Feature;
693 --------------------------------
694 -- Error_Msg_Ada_2022_Feature --
695 --------------------------------
697 procedure Error_Msg_Ada_2022_Feature (Feature : String; Loc : Source_Ptr) is
698 begin
699 if Ada_Version < Ada_2022 then
700 Error_Msg (Feature & " is an Ada 2022 feature", Loc);
702 if No (Ada_Version_Pragma) then
703 Error_Msg ("\unit must be compiled with -gnat2022 switch", Loc);
704 else
705 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
706 Error_Msg ("\incompatible with Ada version set#", Loc);
707 end if;
708 end if;
709 end Error_Msg_Ada_2022_Feature;
711 ------------------
712 -- Error_Msg_AP --
713 ------------------
715 procedure Error_Msg_AP (Msg : String) is
716 S1 : Source_Ptr;
717 C : Character;
719 begin
720 -- If we had saved the Scan_Ptr value after scanning the previous
721 -- token, then we would have exactly the right place for putting
722 -- the flag immediately at hand. However, that would add at least
723 -- two instructions to a Scan call *just* to service the possibility
724 -- of an Error_Msg_AP call. So instead we reconstruct that value.
726 -- We have two possibilities, start with Prev_Token_Ptr and skip over
727 -- the current token, which is made harder by the possibility that this
728 -- token may be in error, or start with Token_Ptr and work backwards.
729 -- We used to take the second approach, but it's hard because of
730 -- comments, and harder still because things that look like comments
731 -- can appear inside strings. So now we take the first approach.
733 -- Note: in the case where there is no previous token, Prev_Token_Ptr
734 -- is set to Source_First, which is a reasonable position for the
735 -- error flag in this situation.
737 S1 := Prev_Token_Ptr;
738 C := Source (S1);
740 -- If the previous token is a string literal, we need a special approach
741 -- since there may be white space inside the literal and we don't want
742 -- to stop on that white space.
744 -- Note: since this is an error recovery issue anyway, it is not worth
745 -- worrying about special UTF_32 line terminator characters here.
747 if Prev_Token = Tok_String_Literal then
748 loop
749 S1 := S1 + 1;
751 if Source (S1) = C then
752 S1 := S1 + 1;
753 exit when Source (S1) /= C;
754 elsif Source (S1) in Line_Terminator then
755 exit;
756 end if;
757 end loop;
759 -- Character literal also needs special handling
761 elsif Prev_Token = Tok_Char_Literal then
762 S1 := S1 + 3;
764 -- Otherwise we search forward for the end of the current token, marked
765 -- by a line terminator, white space, a comment symbol or if we bump
766 -- into the following token (i.e. the current token).
768 -- Again, it is not worth worrying about UTF_32 special line terminator
769 -- characters in this context, since this is only for error recovery.
771 else
772 while Source (S1) not in Line_Terminator
773 and then Source (S1) /= ' '
774 and then Source (S1) /= ASCII.HT
775 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
776 and then S1 /= Token_Ptr
777 loop
778 S1 := S1 + 1;
779 end loop;
780 end if;
782 -- S1 is now set to the location for the flag
784 Error_Msg (Msg, S1);
785 end Error_Msg_AP;
787 ------------------
788 -- Error_Msg_BC --
789 ------------------
791 procedure Error_Msg_BC (Msg : String) is
792 begin
793 -- If we are at end of file, post the flag after the previous token
795 if Token = Tok_EOF then
796 Error_Msg_AP (Msg);
798 -- If we are at start of file, post the flag at the current token
800 elsif Token_Ptr = Source_First (Current_Source_File) then
801 Error_Msg_SC (Msg);
803 -- If the character before the current token is a space or a horizontal
804 -- tab, then we place the flag on this character (in the case of a tab
805 -- we would really like to place it in the "last" character of the tab
806 -- space, but that it too much trouble to worry about).
808 elsif Source (Token_Ptr - 1) = ' '
809 or else Source (Token_Ptr - 1) = ASCII.HT
810 then
811 Error_Msg (Msg, Token_Ptr - 1);
813 -- If there is no space or tab before the current token, then there is
814 -- no room to place the flag before the token, so we place it on the
815 -- token instead (this happens for example at the start of a line).
817 else
818 Error_Msg (Msg, Token_Ptr);
819 end if;
820 end Error_Msg_BC;
822 -------------------
823 -- Error_Msg_CRT --
824 -------------------
826 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
827 begin
828 if No_Run_Time_Mode then
829 Error_Msg_N ('|' & Feature & " not allowed in no run time mode", N);
831 else pragma Assert (Configurable_Run_Time_Mode);
832 Error_Msg_N ('|' & Feature & " not supported by configuration>", N);
833 end if;
835 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
836 end Error_Msg_CRT;
838 ------------------
839 -- Error_Msg_PT --
840 ------------------
842 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
843 begin
844 Error_Msg_N
845 ("illegal overriding of subprogram inherited from interface", E);
847 Error_Msg_Sloc := Sloc (Iface_Prim);
849 if Ekind (E) = E_Function then
850 Error_Msg_N
851 ("\first formal of & declared # must be of mode `IN` "
852 & "or access-to-constant", E);
853 else
854 Error_Msg_N
855 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
856 & "or access-to-variable", E);
857 end if;
858 end Error_Msg_PT;
860 -----------------
861 -- Error_Msg_F --
862 -----------------
864 procedure Error_Msg_F (Msg : String; N : Node_Id) is
865 Fst, Lst : Node_Id;
866 begin
867 First_And_Last_Nodes (N, Fst, Lst);
868 Error_Msg_NEL (Msg, N, N,
869 To_Span (Ptr => Sloc (Fst),
870 First => First_Sloc (Fst),
871 Last => Last_Sloc (Lst)));
872 end Error_Msg_F;
874 ------------------
875 -- Error_Msg_FE --
876 ------------------
878 procedure Error_Msg_FE
879 (Msg : String;
880 N : Node_Id;
881 E : Node_Or_Entity_Id)
883 Fst, Lst : Node_Id;
884 begin
885 First_And_Last_Nodes (N, Fst, Lst);
886 Error_Msg_NEL (Msg, N, E,
887 To_Span (Ptr => Sloc (Fst),
888 First => First_Sloc (Fst),
889 Last => Last_Sloc (Lst)));
890 end Error_Msg_FE;
892 ------------------------------
893 -- Error_Msg_GNAT_Extension --
894 ------------------------------
896 procedure Error_Msg_GNAT_Extension
897 (Extension : String;
898 Loc : Source_Ptr;
899 Is_Core_Extension : Boolean := False)
901 begin
902 if (if Is_Core_Extension
903 then Core_Extensions_Allowed
904 else All_Extensions_Allowed)
905 then
906 return;
907 end if;
909 Error_Msg (Extension & " is a 'G'N'A'T-specific extension", Loc);
911 if No (Ada_Version_Pragma) then
912 if Is_Core_Extension then
913 Error_Msg
914 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
915 "or use pragma Extensions_Allowed (On) '[or All']", Loc);
916 else
917 Error_Msg
918 ("\unit must be compiled with -gnatX0 " &
919 "or use pragma Extensions_Allowed (All)", Loc);
920 end if;
921 else
922 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
923 Error_Msg ("\incompatible with Ada version set#", Loc);
924 if Is_Core_Extension then
925 Error_Msg
926 ("\must use pragma Extensions_Allowed (On) '[or All']", Loc);
927 else
928 Error_Msg
929 ("\must use pragma Extensions_Allowed (All)", Loc);
930 end if;
931 end if;
932 end Error_Msg_GNAT_Extension;
934 ------------------------
935 -- Error_Msg_Internal --
936 ------------------------
938 procedure Error_Msg_Internal
939 (Msg : String;
940 Span : Source_Span;
941 Opan : Source_Span;
942 Msg_Cont : Boolean;
943 Node : Node_Id)
945 Sptr : constant Source_Ptr := Span.Ptr;
946 Optr : constant Source_Ptr := Opan.Ptr;
948 Next_Msg : Error_Msg_Id;
949 -- Pointer to next message at insertion point
951 Prev_Msg : Error_Msg_Id;
952 -- Pointer to previous message at insertion point
954 Temp_Msg : Error_Msg_Id;
956 Warn_Err : Boolean;
957 -- Set if warning to be treated as error
959 procedure Handle_Serious_Error;
960 -- Internal procedure to do all error message handling for a serious
961 -- error message, other than bumping the error counts and arranging
962 -- for the message to be output.
964 --------------------------
965 -- Handle_Serious_Error --
966 --------------------------
968 procedure Handle_Serious_Error is
969 begin
970 -- Turn off code generation if not done already
972 if Operating_Mode = Generate_Code then
973 Operating_Mode := Check_Semantics;
974 Expander_Active := False;
975 end if;
977 -- Set the fatal error flag in the unit table unless we are in
978 -- Try_Semantics mode (in which case we set ignored mode if not
979 -- currently set. This stops the semantics from being performed
980 -- if we find a serious error. This is skipped if we are currently
981 -- dealing with the configuration pragma file.
983 if Current_Source_Unit /= No_Unit then
984 declare
985 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
986 begin
987 if Try_Semantics then
988 if Fatal_Error (U) = None then
989 Set_Fatal_Error (U, Error_Ignored);
990 end if;
991 else
992 Set_Fatal_Error (U, Error_Detected);
993 end if;
994 end;
995 end if;
997 -- Disable warnings on unused use clauses and the like. Otherwise, an
998 -- error might hide a reference to an entity in a used package, so
999 -- after fixing the error, the use clause no longer looks like it was
1000 -- unused.
1002 Warnsw.Check_Unreferenced := False;
1003 Warnsw.Check_Unreferenced_Formals := False;
1004 end Handle_Serious_Error;
1006 -- Start of processing for Error_Msg_Internal
1008 begin
1009 -- Detect common mistake of prefixing or suffixing the message with a
1010 -- space character.
1012 pragma Assert (Msg (Msg'First) /= ' ' and then Msg (Msg'Last) /= ' ');
1014 if Raise_Exception_On_Error /= 0 then
1015 raise Error_Msg_Exception;
1016 end if;
1018 Continuation := Msg_Cont;
1019 Continuation_New_Line := False;
1020 Suppress_Message := False;
1021 Kill_Message := False;
1022 Set_Msg_Text (Msg, Sptr);
1024 -- Kill continuation if parent message killed
1026 if Continuation and Last_Killed then
1027 return;
1028 end if;
1030 -- Return without doing anything if message is suppressed
1032 if Suppress_Message
1033 and then not All_Errors_Mode
1034 and then not Is_Warning_Msg
1035 and then not Is_Unconditional_Msg
1036 then
1037 if not Continuation then
1038 Last_Killed := True;
1039 end if;
1041 return;
1042 end if;
1044 -- Return without doing anything if message is killed and this is not
1045 -- the first error message. The philosophy is that if we get a weird
1046 -- error message and we already have had a message, then we hope the
1047 -- weird message is a junk cascaded message
1049 if Kill_Message
1050 and then not All_Errors_Mode
1051 and then Total_Errors_Detected /= 0
1052 then
1053 if not Continuation then
1054 Last_Killed := True;
1055 end if;
1057 return;
1058 end if;
1060 -- Special check for warning message to see if it should be output
1062 if Is_Warning_Msg then
1064 -- Immediate return if warning message and warnings are suppressed
1066 if Warnings_Suppressed (Optr) /= No_String
1067 or else
1068 Warnings_Suppressed (Sptr) /= No_String
1069 then
1070 Cur_Msg := No_Error_Msg;
1071 return;
1072 end if;
1074 -- If the flag location is in the main extended source unit then for
1075 -- sure we want the warning since it definitely belongs
1077 if In_Extended_Main_Source_Unit (Sptr) then
1078 null;
1080 -- If the main unit has not been read yet. The warning must be on
1081 -- a configuration file: gnat.adc or user-defined. This means we
1082 -- are not parsing the main unit yet, so skip following checks.
1084 elsif No (Cunit (Main_Unit)) then
1085 null;
1087 -- If the flag location is not in the extended main source unit, then
1088 -- we want to eliminate the warning, unless it is in the extended
1089 -- main code unit and we want warnings on the instance.
1091 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
1092 null;
1094 -- Keep warning if debug flag G set
1096 elsif Debug_Flag_GG then
1097 null;
1099 -- Keep warning if message text contains !!
1101 elsif Has_Double_Exclam then
1102 null;
1104 -- Here is where we delete a warning from a with'ed unit
1106 else
1107 Cur_Msg := No_Error_Msg;
1109 if not Continuation then
1110 Last_Killed := True;
1111 end if;
1113 return;
1114 end if;
1115 end if;
1117 -- If message is to be ignored in special ignore message mode, this is
1118 -- where we do this special processing, bypassing message output.
1120 if Ignore_Errors_Enable > 0 then
1121 if Is_Serious_Error then
1122 Handle_Serious_Error;
1123 end if;
1125 return;
1126 end if;
1128 -- If error message line length set, and this is a continuation message
1129 -- then all we do is to append the text to the text of the last message
1130 -- with a comma space separator (eliminating a possible (style) or
1131 -- info prefix).
1133 if Error_Msg_Line_Length /= 0 and then Continuation then
1134 Cur_Msg := Errors.Last;
1136 declare
1137 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
1138 Newm : String (1 .. Oldm'Last + 2 + Msglen);
1139 Newl : Natural;
1140 M : Natural;
1142 begin
1143 -- First copy old message to new one and free it
1145 Newm (Oldm'Range) := Oldm.all;
1146 Newl := Oldm'Length;
1147 Free (Oldm);
1149 -- Remove (style) or info: at start of message
1151 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
1152 M := 9;
1154 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
1155 M := 7;
1157 else
1158 M := 1;
1159 end if;
1161 -- Now deal with separation between messages. Normally this is
1162 -- simply comma space, but there are some special cases.
1164 -- If continuation new line, then put actual NL character in msg
1166 if Continuation_New_Line then
1167 Newl := Newl + 1;
1168 Newm (Newl) := ASCII.LF;
1170 -- If continuation message is enclosed in parentheses, then
1171 -- special treatment (don't need a comma, and we want to combine
1172 -- successive parenthetical remarks into a single one with
1173 -- separating commas).
1175 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
1177 -- Case where existing message ends in right paren, remove
1178 -- and separate parenthetical remarks with a comma.
1180 if Newm (Newl) = ')' then
1181 Newm (Newl) := ',';
1182 Msg_Buffer (M) := ' ';
1184 -- Case where we are adding new parenthetical comment
1186 else
1187 Newl := Newl + 1;
1188 Newm (Newl) := ' ';
1189 end if;
1191 -- Case where continuation not in parens and no new line
1193 else
1194 Newm (Newl + 1 .. Newl + 2) := ", ";
1195 Newl := Newl + 2;
1196 end if;
1198 -- Append new message
1200 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1201 Msg_Buffer (M .. Msglen);
1202 Newl := Newl + Msglen - M + 1;
1203 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1205 -- Update warning msg flag and message doc char if needed
1207 if Is_Warning_Msg then
1208 if not Errors.Table (Cur_Msg).Warn then
1209 Errors.Table (Cur_Msg).Warn := True;
1210 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1212 elsif Warning_Msg_Char /= " " then
1213 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1214 end if;
1215 end if;
1216 end;
1218 return;
1219 end if;
1221 -- Here we build a new error object
1223 Errors.Append
1224 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1225 Next => No_Error_Msg,
1226 Prev => No_Error_Msg,
1227 Sptr => Span,
1228 Optr => Opan,
1229 Insertion_Sloc => (if Has_Insertion_Line then Error_Msg_Sloc
1230 else No_Location),
1231 Sfile => Get_Source_File_Index (Sptr),
1232 Line => Get_Physical_Line_Number (Sptr),
1233 Col => Get_Column_Number (Sptr),
1234 Compile_Time_Pragma => Is_Compile_Time_Msg,
1235 Warn => Is_Warning_Msg,
1236 Info => Is_Info_Msg,
1237 Check => Is_Check_Msg,
1238 Warn_Err => False, -- reset below
1239 Warn_Chr => Warning_Msg_Char,
1240 Warn_Runtime_Raise => Is_Runtime_Raise,
1241 Style => Is_Style_Msg,
1242 Serious => Is_Serious_Error,
1243 Uncond => Is_Unconditional_Msg,
1244 Msg_Cont => Continuation,
1245 Deleted => False,
1246 Node => Node));
1247 Cur_Msg := Errors.Last;
1249 -- Test if warning to be treated as error
1251 Warn_Err :=
1252 (Is_Warning_Msg or Is_Style_Msg)
1253 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1254 or else
1255 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
1257 -- Propagate Warn_Err to this message and preceding continuations.
1258 -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
1259 -- current continued message could have been escalated from warning to
1260 -- error.
1262 for J in reverse 1 .. Errors.Last loop
1263 Errors.Table (J).Warn_Err := Warn_Err;
1264 Errors.Table (J).Warn := Is_Warning_Msg;
1265 Errors.Table (J).Warn_Runtime_Raise := Is_Runtime_Raise;
1266 exit when not Errors.Table (J).Msg_Cont;
1267 end loop;
1269 -- If immediate errors mode set, output error message now. Also output
1270 -- now if the -d1 debug flag is set (so node number message comes out
1271 -- just before actual error message)
1273 if Debug_Flag_OO or else Debug_Flag_1 then
1274 Write_Eol;
1275 Output_Source_Line
1276 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1277 Temp_Msg := Cur_Msg;
1278 Output_Error_Msgs (Temp_Msg);
1280 -- If not in immediate errors mode, then we insert the message in the
1281 -- error chain for later output by Finalize. The messages are sorted
1282 -- first by unit (main unit comes first), and within a unit by source
1283 -- location (earlier flag location first in the chain).
1285 else
1286 -- First a quick check, does this belong at the very end of the chain
1287 -- of error messages. This saves a lot of time in the normal case if
1288 -- there are lots of messages.
1290 if Last_Error_Msg /= No_Error_Msg
1291 and then Errors.Table (Cur_Msg).Sfile =
1292 Errors.Table (Last_Error_Msg).Sfile
1293 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr.Ptr
1294 or else
1295 (Sptr = Errors.Table (Last_Error_Msg).Sptr.Ptr
1296 and then
1297 Optr > Errors.Table (Last_Error_Msg).Optr.Ptr))
1298 then
1299 Prev_Msg := Last_Error_Msg;
1300 Next_Msg := No_Error_Msg;
1302 -- Otherwise do a full sequential search for the insertion point
1304 else
1305 Prev_Msg := No_Error_Msg;
1306 Next_Msg := First_Error_Msg;
1307 while Next_Msg /= No_Error_Msg loop
1308 exit when
1309 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1311 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1312 then
1313 exit when Sptr < Errors.Table (Next_Msg).Sptr.Ptr
1314 or else (Sptr = Errors.Table (Next_Msg).Sptr.Ptr
1315 and then
1316 Optr < Errors.Table (Next_Msg).Optr.Ptr);
1317 end if;
1319 Prev_Msg := Next_Msg;
1320 Next_Msg := Errors.Table (Next_Msg).Next;
1321 end loop;
1322 end if;
1324 -- Now we insert the new message in the error chain.
1326 -- The possible insertion point for the new message is after Prev_Msg
1327 -- and before Next_Msg. However, this is where we do a special check
1328 -- for redundant parsing messages, defined as messages posted on the
1329 -- same line. The idea here is that probably such messages are junk
1330 -- from the parser recovering. In full errors mode, we don't do this
1331 -- deletion, but otherwise such messages are discarded at this stage.
1333 if Prev_Msg /= No_Error_Msg
1334 and then Errors.Table (Prev_Msg).Line =
1335 Errors.Table (Cur_Msg).Line
1336 and then Errors.Table (Prev_Msg).Sfile =
1337 Errors.Table (Cur_Msg).Sfile
1338 and then Compiler_State = Parsing
1339 and then not All_Errors_Mode
1340 then
1341 -- Don't delete unconditional messages and at this stage, don't
1342 -- delete continuation lines; we attempted to delete those earlier
1343 -- if the parent message was deleted.
1345 if not Errors.Table (Cur_Msg).Uncond
1346 and then not Continuation
1347 then
1348 -- Don't delete if prev msg is warning and new msg is an error.
1349 -- This is because we don't want a real error masked by a
1350 -- warning. In all other cases (that is parse errors for the
1351 -- same line that are not unconditional) we do delete the
1352 -- message. This helps to avoid junk extra messages from
1353 -- cascaded parsing errors
1355 if not (Errors.Table (Prev_Msg).Warn
1356 or else
1357 Errors.Table (Prev_Msg).Style)
1358 or else
1359 (Errors.Table (Cur_Msg).Warn
1360 or else
1361 Errors.Table (Cur_Msg).Style)
1362 then
1363 -- All tests passed, delete the message by simply returning
1364 -- without any further processing.
1366 pragma Assert (not Continuation);
1368 Last_Killed := True;
1369 return;
1370 end if;
1371 end if;
1372 end if;
1374 -- Come here if message is to be inserted in the error chain
1376 if not Continuation then
1377 Last_Killed := False;
1378 end if;
1380 if Prev_Msg = No_Error_Msg then
1381 First_Error_Msg := Cur_Msg;
1382 else
1383 Errors.Table (Prev_Msg).Next := Cur_Msg;
1384 end if;
1386 Errors.Table (Cur_Msg).Next := Next_Msg;
1388 if Next_Msg = No_Error_Msg then
1389 Last_Error_Msg := Cur_Msg;
1390 end if;
1391 end if;
1393 -- Bump appropriate statistics counts
1395 if Errors.Table (Cur_Msg).Info then
1397 -- Could be (usually is) both "info" and "warning"
1399 if Errors.Table (Cur_Msg).Warn then
1400 Warning_Info_Messages := Warning_Info_Messages + 1;
1401 Warnings_Detected := Warnings_Detected + 1;
1402 else
1403 Report_Info_Messages := Report_Info_Messages + 1;
1404 end if;
1406 elsif Errors.Table (Cur_Msg).Warn
1407 or else Errors.Table (Cur_Msg).Style
1408 then
1409 Warnings_Detected := Warnings_Detected + 1;
1411 elsif Errors.Table (Cur_Msg).Check then
1412 Check_Messages := Check_Messages + 1;
1414 else
1415 Total_Errors_Detected := Total_Errors_Detected + 1;
1417 if Errors.Table (Cur_Msg).Serious then
1418 Serious_Errors_Detected := Serious_Errors_Detected + 1;
1419 Handle_Serious_Error;
1421 -- If not serious error, set Fatal_Error to indicate ignored error
1423 else
1424 declare
1425 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1426 begin
1427 if Fatal_Error (U) = None then
1428 Set_Fatal_Error (U, Error_Ignored);
1429 end if;
1430 end;
1431 end if;
1432 end if;
1434 -- Record warning message issued
1436 if Errors.Table (Cur_Msg).Warn
1437 and then not Errors.Table (Cur_Msg).Msg_Cont
1438 then
1439 Warning_Msg := Cur_Msg;
1440 end if;
1442 -- If too many warnings turn off warnings
1444 if Maximum_Messages /= 0 then
1445 if Warnings_Detected = Maximum_Messages then
1446 Warning_Mode := Suppress;
1447 end if;
1449 -- If too many errors abandon compilation
1451 if Total_Errors_Detected = Maximum_Messages then
1452 raise Unrecoverable_Error;
1453 end if;
1454 end if;
1456 if Has_Error_Code then
1457 declare
1458 Msg : constant String :=
1459 "\launch ""gnatprove --explain=[]"" for more information";
1460 begin
1461 Has_Double_Exclam := False;
1462 Has_Error_Code := False;
1463 Has_Insertion_Line := False;
1465 Error_Msg_Internal
1466 (Msg => Msg,
1467 Span => Span,
1468 Opan => Opan,
1469 Msg_Cont => True,
1470 Node => Node);
1471 end;
1472 end if;
1473 end Error_Msg_Internal;
1475 -----------------
1476 -- Error_Msg_N --
1477 -----------------
1479 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1480 Fst, Lst : Node_Id;
1481 begin
1482 First_And_Last_Nodes (N, Fst, Lst);
1483 Error_Msg_NEL (Msg, N, N,
1484 To_Span (Ptr => Sloc (N),
1485 First => First_Sloc (Fst),
1486 Last => Last_Sloc (Lst)));
1487 end Error_Msg_N;
1489 ------------------
1490 -- Error_Msg_NE --
1491 ------------------
1493 procedure Error_Msg_NE
1494 (Msg : String;
1495 N : Node_Or_Entity_Id;
1496 E : Node_Or_Entity_Id)
1498 Fst, Lst : Node_Id;
1499 begin
1500 First_And_Last_Nodes (N, Fst, Lst);
1501 Error_Msg_NEL (Msg, N, E,
1502 To_Span (Ptr => Sloc (N),
1503 First => First_Sloc (Fst),
1504 Last => Last_Sloc (Lst)));
1505 end Error_Msg_NE;
1507 -------------------
1508 -- Error_Msg_NEL --
1509 -------------------
1511 procedure Error_Msg_NEL
1512 (Msg : String;
1513 N : Node_Or_Entity_Id;
1514 E : Node_Or_Entity_Id;
1515 Flag_Location : Source_Ptr)
1517 Fst, Lst : Node_Id;
1518 begin
1519 First_And_Last_Nodes (N, Fst, Lst);
1520 Error_Msg_NEL
1521 (Msg, N, E,
1522 To_Span (Ptr => Flag_Location,
1523 First => Source_Ptr'Min (Flag_Location, First_Sloc (Fst)),
1524 Last => Source_Ptr'Max (Flag_Location, Last_Sloc (Lst))));
1525 end Error_Msg_NEL;
1527 procedure Error_Msg_NEL
1528 (Msg : String;
1529 N : Node_Or_Entity_Id;
1530 E : Node_Or_Entity_Id;
1531 Flag_Span : Source_Span)
1533 begin
1534 if Special_Msg_Delete (Msg, N, E) then
1535 return;
1536 end if;
1538 Prescan_Message (Msg);
1540 -- Special handling for warning messages
1542 if Is_Warning_Msg then
1544 -- Suppress if no warnings set for either entity or node
1546 if No_Warnings (N) or else No_Warnings (E) then
1548 -- Disable any continuation messages as well
1550 Last_Killed := True;
1551 return;
1552 end if;
1553 end if;
1555 -- Test for message to be output
1557 if All_Errors_Mode
1558 or else Is_Unconditional_Msg
1559 or else Is_Warning_Msg
1560 or else OK_Node (N)
1561 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1562 then
1563 Debug_Output (N);
1564 Error_Msg_Node_1 := E;
1565 Error_Msg (Msg, Flag_Span, N);
1567 else
1568 Last_Killed := True;
1569 end if;
1571 if not Get_Ignore_Errors then
1572 Set_Posted (N);
1573 end if;
1574 end Error_Msg_NEL;
1576 ------------------
1577 -- Error_Msg_NW --
1578 ------------------
1580 procedure Error_Msg_NW
1581 (Eflag : Boolean;
1582 Msg : String;
1583 N : Node_Or_Entity_Id)
1585 Fst, Lst : Node_Id;
1586 begin
1587 if Eflag
1588 and then In_Extended_Main_Source_Unit (N)
1589 and then Comes_From_Source (N)
1590 then
1591 First_And_Last_Nodes (N, Fst, Lst);
1592 Error_Msg_NEL (Msg, N, N,
1593 To_Span (Ptr => Sloc (N),
1594 First => First_Sloc (Fst),
1595 Last => Last_Sloc (Lst)));
1596 end if;
1597 end Error_Msg_NW;
1599 -----------------
1600 -- Error_Msg_S --
1601 -----------------
1603 procedure Error_Msg_S (Msg : String) is
1604 begin
1605 Error_Msg (Msg, Scan_Ptr);
1606 end Error_Msg_S;
1608 ------------------
1609 -- Error_Msg_SC --
1610 ------------------
1612 procedure Error_Msg_SC (Msg : String) is
1613 begin
1614 -- If we are at end of file, post the flag after the previous token
1616 if Token = Tok_EOF then
1617 Error_Msg_AP (Msg);
1619 -- For all other cases the message is posted at the current token
1620 -- pointer position
1622 else
1623 Error_Msg (Msg, Token_Ptr);
1624 end if;
1625 end Error_Msg_SC;
1627 ------------------
1628 -- Error_Msg_SP --
1629 ------------------
1631 procedure Error_Msg_SP (Msg : String) is
1632 begin
1633 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1634 -- is set to Source_First, which is a reasonable position for the
1635 -- error flag in this situation
1637 Error_Msg (Msg, Prev_Token_Ptr);
1638 end Error_Msg_SP;
1640 --------------
1641 -- Finalize --
1642 --------------
1644 procedure Finalize (Last_Call : Boolean) is
1645 Cur : Error_Msg_Id;
1646 Nxt : Error_Msg_Id;
1647 F : Error_Msg_Id;
1649 procedure Delete_Warning (E : Error_Msg_Id);
1650 -- Delete a warning msg if not already deleted and adjust warning count
1652 --------------------
1653 -- Delete_Warning --
1654 --------------------
1656 procedure Delete_Warning (E : Error_Msg_Id) is
1657 begin
1658 if not Errors.Table (E).Deleted then
1659 Errors.Table (E).Deleted := True;
1660 Warnings_Detected := Warnings_Detected - 1;
1662 if Errors.Table (E).Info then
1663 Warning_Info_Messages := Warning_Info_Messages - 1;
1664 end if;
1665 end if;
1666 end Delete_Warning;
1668 -- Start of processing for Finalize
1670 begin
1671 -- Set Prev pointers
1673 Cur := First_Error_Msg;
1674 while Cur /= No_Error_Msg loop
1675 Nxt := Errors.Table (Cur).Next;
1676 exit when Nxt = No_Error_Msg;
1677 Errors.Table (Nxt).Prev := Cur;
1678 Cur := Nxt;
1679 end loop;
1681 -- Eliminate any duplicated error messages from the list. This is
1682 -- done after the fact to avoid problems with Change_Error_Text.
1684 Cur := First_Error_Msg;
1685 while Cur /= No_Error_Msg loop
1686 Nxt := Errors.Table (Cur).Next;
1688 F := Nxt;
1689 while F /= No_Error_Msg
1690 and then Errors.Table (F).Sptr.Ptr = Errors.Table (Cur).Sptr.Ptr
1691 loop
1692 Check_Duplicate_Message (Cur, F);
1693 F := Errors.Table (F).Next;
1694 end loop;
1696 Cur := Nxt;
1697 end loop;
1699 -- Mark any messages suppressed by specific warnings as Deleted
1701 Cur := First_Error_Msg;
1702 while Cur /= No_Error_Msg loop
1703 declare
1704 CE : Error_Msg_Object renames Errors.Table (Cur);
1705 Tag : constant String := Get_Warning_Tag (Cur);
1707 begin
1708 if (CE.Warn and not CE.Deleted)
1709 and then
1710 (Warning_Specifically_Suppressed (CE.Sptr.Ptr, CE.Text, Tag)
1711 /= No_String
1712 or else
1713 Warning_Specifically_Suppressed (CE.Optr.Ptr, CE.Text, Tag)
1714 /= No_String)
1715 then
1716 Delete_Warning (Cur);
1718 -- If this is a continuation, delete previous parts of message
1720 F := Cur;
1721 while Errors.Table (F).Msg_Cont loop
1722 F := Errors.Table (F).Prev;
1723 exit when F = No_Error_Msg;
1724 Delete_Warning (F);
1725 end loop;
1727 -- Delete any following continuations
1729 F := Cur;
1730 loop
1731 F := Errors.Table (F).Next;
1732 exit when F = No_Error_Msg;
1733 exit when not Errors.Table (F).Msg_Cont;
1734 Delete_Warning (F);
1735 end loop;
1736 end if;
1737 end;
1739 Cur := Errors.Table (Cur).Next;
1740 end loop;
1742 Finalize_Called := True;
1744 -- Check consistency of specific warnings (may add warnings). We only
1745 -- do this on the last call, after all possible warnings are posted.
1747 if Last_Call then
1748 Validate_Specific_Warnings (Error_Msg'Access);
1749 end if;
1750 end Finalize;
1752 ----------------
1753 -- First_Node --
1754 ----------------
1756 function First_Node (C : Node_Id) return Node_Id is
1757 Fst, Lst : Node_Id;
1758 begin
1759 First_And_Last_Nodes (C, Fst, Lst);
1760 return Fst;
1761 end First_Node;
1763 --------------------------
1764 -- First_And_Last_Nodes --
1765 --------------------------
1767 procedure First_And_Last_Nodes
1768 (C : Node_Id;
1769 First_Node, Last_Node : out Node_Id)
1771 Orig : constant Node_Id := Original_Node (C);
1772 Loc : constant Source_Ptr := Sloc (Orig);
1773 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1774 Earliest : Node_Id;
1775 Latest : Node_Id;
1776 Eloc : Source_Ptr;
1777 Lloc : Source_Ptr;
1779 function Test_First_And_Last (N : Node_Id) return Traverse_Result;
1780 -- Function applied to every node in the construct
1782 procedure Search_Tree_First_And_Last is new
1783 Traverse_Proc (Test_First_And_Last);
1784 -- Create traversal procedure
1786 -------------------------
1787 -- Test_First_And_Last --
1788 -------------------------
1790 function Test_First_And_Last (N : Node_Id) return Traverse_Result is
1791 Norig : constant Node_Id := Original_Node (N);
1792 Loc : constant Source_Ptr := Sloc (Norig);
1794 begin
1795 -- ??? For assignments that require accessiblity checks, e.g.:
1797 -- Y := Func (123);
1799 -- the function call gets an extra actual parameter association with
1800 -- Sloc of the assigned name "Y":
1802 -- Y := Func (123, A8b => 2);
1804 -- We can simply ignore those extra actual parameters when
1805 -- determining the Sloc range of the "Func (123)" expression.
1807 if Nkind (N) = N_Parameter_Association
1808 and then Is_Accessibility_Actual (N)
1809 then
1810 return Skip;
1811 end if;
1813 -- Check for earlier
1815 if Loc < Eloc
1817 -- Ignore nodes with no useful location information
1819 and then Loc /= Standard_Location
1820 and then Loc /= No_Location
1822 -- Ignore nodes from a different file. This ensures against cases
1823 -- of strange foreign code somehow being present. We don't want
1824 -- wild placement of messages if that happens.
1826 and then Get_Source_File_Index (Loc) = Sfile
1827 then
1828 Earliest := Norig;
1829 Eloc := Loc;
1830 end if;
1832 -- Check for later
1834 if Loc > Lloc
1836 -- Ignore nodes with no useful location information
1838 and then Loc /= Standard_Location
1839 and then Loc /= No_Location
1841 -- Ignore nodes from a different file. This ensures against cases
1842 -- of strange foreign code somehow being present. We don't want
1843 -- wild placement of messages if that happens.
1845 and then Get_Source_File_Index (Loc) = Sfile
1846 then
1847 Latest := Norig;
1848 Lloc := Loc;
1849 end if;
1851 return OK_Orig;
1852 end Test_First_And_Last;
1854 -- Start of processing for First_And_Last_Nodes
1856 begin
1857 if Nkind (Orig) in N_Subexpr
1858 | N_Declaration
1859 | N_Access_To_Subprogram_Definition
1860 | N_Generic_Instantiation
1861 | N_Later_Decl_Item
1862 | N_Use_Package_Clause
1863 | N_Array_Type_Definition
1864 | N_Renaming_Declaration
1865 | N_Generic_Renaming_Declaration
1866 | N_Assignment_Statement
1867 | N_Raise_Statement
1868 | N_Simple_Return_Statement
1869 | N_Exit_Statement
1870 | N_Pragma
1871 | N_Use_Type_Clause
1872 | N_With_Clause
1873 | N_Attribute_Definition_Clause
1874 | N_Subtype_Indication
1875 then
1876 Earliest := Orig;
1877 Eloc := Loc;
1878 Latest := Orig;
1879 Lloc := Loc;
1880 Search_Tree_First_And_Last (Orig);
1881 First_Node := Earliest;
1882 Last_Node := Latest;
1884 else
1885 First_Node := Orig;
1886 Last_Node := Orig;
1887 end if;
1888 end First_And_Last_Nodes;
1890 ----------------
1891 -- First_Sloc --
1892 ----------------
1894 function First_Sloc (N : Node_Id) return Source_Ptr is
1895 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1896 SF : constant Source_Ptr := Source_First (SI);
1897 SL : constant Source_Ptr := Source_Last (SI);
1898 Src : constant Source_Buffer_Ptr := Source_Text (SI);
1899 F : Node_Id;
1900 S : Source_Ptr;
1902 begin
1903 F := First_Node (N);
1904 S := Sloc (F);
1906 if S not in SF .. SL then
1907 return S;
1908 end if;
1910 -- The following circuit is a bit subtle. When we have parenthesized
1911 -- expressions, then the Sloc will not record the location of the paren,
1912 -- but we would like to post the flag on the paren. So what we do is to
1913 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1914 -- any parentheses we know are present. Yes, we know this circuit is not
1915 -- 100% reliable (e.g. because we don't record all possible paren level
1916 -- values), but this is only for an error message so it is good enough.
1918 Node_Loop : loop
1919 -- Include parentheses around the top node, except when they are
1920 -- required by the syntax of the parent node.
1922 exit Node_Loop when F = N
1923 and then Paren_Required (N);
1925 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1927 -- We don't look more than 12 characters behind the current
1928 -- location, and in any case not past the front of the source.
1930 Search_Loop : for K in 1 .. 12 loop
1931 exit Search_Loop when S = SF;
1933 if Src (S - 1) = '(' then
1934 S := S - 1;
1935 exit Search_Loop;
1937 elsif Src (S - 1) <= ' ' then
1938 S := S - 1;
1940 else
1941 exit Search_Loop;
1942 end if;
1943 end loop Search_Loop;
1944 end loop Paren_Loop;
1946 exit Node_Loop when F = N;
1947 F := Parent (F);
1948 exit Node_Loop when Nkind (F) not in N_Subexpr;
1949 end loop Node_Loop;
1951 return S;
1952 end First_Sloc;
1954 -----------------------
1955 -- Get_Ignore_Errors --
1956 -----------------------
1958 function Get_Ignore_Errors return Boolean is
1959 begin
1960 return Errors_Must_Be_Ignored;
1961 end Get_Ignore_Errors;
1963 ----------------
1964 -- Initialize --
1965 ----------------
1967 procedure Initialize is
1968 begin
1969 Errors.Init;
1970 First_Error_Msg := No_Error_Msg;
1971 Last_Error_Msg := No_Error_Msg;
1972 Serious_Errors_Detected := 0;
1973 Total_Errors_Detected := 0;
1974 Cur_Msg := No_Error_Msg;
1975 List_Pragmas.Init;
1977 -- Reset counts for warnings
1979 Warnings_Treated_As_Errors := 0;
1980 Warnings_Detected := 0;
1981 Warning_Info_Messages := 0;
1982 Warnings_As_Errors_Count := 0;
1984 -- Initialize warnings tables
1986 Warnings.Init;
1987 Specific_Warnings.Init;
1988 end Initialize;
1990 -------------------------------
1991 -- Is_Size_Too_Small_Message --
1992 -------------------------------
1994 function Is_Size_Too_Small_Message (S : String) return Boolean is
1995 Size_For : constant String := "size for";
1996 pragma Assert (Size_Too_Small_Message (1 .. Size_For'Last) = Size_For);
1997 -- Assert that Size_Too_Small_Message starts with Size_For
1998 begin
1999 return S'Length >= Size_For'Length
2000 and then S (S'First .. S'First + Size_For'Length - 1) = Size_For;
2001 -- True if S starts with Size_For
2002 end Is_Size_Too_Small_Message;
2004 ---------------
2005 -- Last_Node --
2006 ---------------
2008 function Last_Node (C : Node_Id) return Node_Id is
2009 Fst, Lst : Node_Id;
2010 begin
2011 First_And_Last_Nodes (C, Fst, Lst);
2012 return Lst;
2013 end Last_Node;
2015 ---------------
2016 -- Last_Sloc --
2017 ---------------
2019 function Last_Sloc (N : Node_Id) return Source_Ptr is
2020 procedure Skip_Char (S : in out Source_Ptr);
2021 -- Skip one character of the source buffer at location S
2023 ---------------
2024 -- Skip_Char --
2025 ---------------
2027 procedure Skip_Char (S : in out Source_Ptr) is
2028 begin
2029 S := S + 1;
2030 end Skip_Char;
2032 -- Local variables
2034 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
2035 SF : constant Source_Ptr := Source_First (SI);
2036 SL : constant Source_Ptr := Source_Last (SI);
2037 Src : constant Source_Buffer_Ptr := Source_Text (SI);
2038 F : Node_Id;
2039 S : Source_Ptr;
2041 -- Start of processing for Last_Sloc
2043 begin
2044 F := Last_Node (N);
2045 S := Sloc (F);
2047 if S not in SF .. SL then
2048 return S;
2049 end if;
2051 -- For string and character literals simply forward the sloc by their
2052 -- length including the closing quotes. Perhaps we should do something
2053 -- special for multibyte characters, but this code is only used to emit
2054 -- error messages, so it is not worth the effort.
2056 case Nkind (F) is
2057 when N_String_Literal =>
2058 return S + Source_Ptr (String_Length (Strval (F))) + 1;
2060 when N_Character_Literal =>
2061 return S + 2;
2063 -- Skip past integer literals, both decimal and based, integer and
2064 -- real. We can't greedily accept all allowed character, because
2065 -- we would consme too many of them in expressions like "123+ABC"
2066 -- or "123..456", so we follow quite precisely the Ada grammar and
2067 -- consume different characters depending on the context.
2069 when N_Integer_Literal =>
2071 -- Skip past the initial numeral, which either leads the decimal
2072 -- literal or is the base of a based literal.
2074 while S < SL
2075 and then Src (S + 1) in '0' .. '9' | '_'
2076 loop
2077 Skip_Char (S);
2078 end loop;
2080 -- Skip past #based_numeral#, if present
2082 if S < SL
2083 and then Src (S + 1) = '#'
2084 then
2085 Skip_Char (S);
2087 while S < SL
2088 and then
2089 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2090 loop
2091 Skip_Char (S);
2092 end loop;
2094 if S < SL
2095 and then Src (S + 1) = '#'
2096 then
2097 Skip_Char (S);
2098 end if;
2099 end if;
2101 -- Skip past exponent, if present
2103 if S < SL
2104 and then Src (S + 1) in 'e' | 'E'
2105 then
2106 Skip_Char (S);
2108 -- For positive exponents the plus sign is optional, but we
2109 -- can simply skip past both plus and minus.
2111 if S < SL
2112 and then Src (S + 1) in '+' | '-'
2113 then
2114 Skip_Char (S);
2115 end if;
2117 -- Skip past the numeral part
2119 while S < SL
2120 and then Src (S + 1) in '0' .. '9' | '_'
2121 loop
2122 Skip_Char (S);
2123 end loop;
2124 end if;
2126 when N_Real_Literal =>
2127 -- Skip past the initial numeral, which either leads the decimal
2128 -- literal or is the base of a based literal.
2130 while S < SL
2131 and then Src (S + 1) in '0' .. '9' | '_'
2132 loop
2133 Skip_Char (S);
2134 end loop;
2136 if S < SL then
2138 -- Skip the dot and continue with a decimal literal
2140 if Src (S + 1) = '.' then
2141 Skip_Char (S);
2143 while S < SL
2144 and then Src (S + 1) in '0' .. '9' | '_'
2145 loop
2146 Skip_Char (S);
2147 end loop;
2149 -- Skip the hash and continue with a based literal
2151 elsif Src (S + 1) = '#' then
2152 Skip_Char (S);
2154 while S < SL
2155 and then
2156 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2157 loop
2158 Skip_Char (S);
2159 end loop;
2161 if S < SL
2162 and then Src (S + 1) = '.'
2163 then
2164 Skip_Char (S);
2165 end if;
2167 while S < SL
2168 and then
2169 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2170 loop
2171 Skip_Char (S);
2172 end loop;
2174 if S < SL
2175 and then Src (S + 1) = '#'
2176 then
2177 Skip_Char (S);
2178 end if;
2179 end if;
2180 end if;
2182 -- Skip past exponent, if present
2184 if S < SL
2185 and then Src (S + 1) in 'e' | 'E'
2186 then
2187 Skip_Char (S);
2188 -- For positive exponents the plus sign is optional, but we
2189 -- can simply skip past both plus and minus.
2191 if Src (S + 1) in '+' | '-' then
2192 Skip_Char (S);
2193 end if;
2195 -- Skip past the numeral part
2197 while S < SL
2198 and then Src (S + 1) in '0' .. '9' | '_'
2199 loop
2200 Skip_Char (S);
2201 end loop;
2202 end if;
2204 -- For other nodes simply skip past a keyword/identifier
2206 when others =>
2207 while S in SF .. SL - 1
2208 and then Src (S + 1)
2210 '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_'
2211 loop
2212 Skip_Char (S);
2213 end loop;
2214 end case;
2216 -- The following circuit attempts at crawling up the tree from the
2217 -- Last_Node, adjusting the Sloc value for any parentheses we know
2218 -- are present, similarly to what is done in First_Sloc.
2220 Node_Loop : loop
2221 -- Include parentheses around the top node, except when they are
2222 -- required by the syntax of the parent node.
2224 exit Node_Loop when F = N
2225 and then Paren_Required (N);
2227 Paren_Loop : for J in 1 .. Paren_Count (F) loop
2229 -- We don't look more than 12 characters after the current
2230 -- location
2232 Search_Loop : for K in 1 .. 12 loop
2233 exit Node_Loop when S = SL;
2235 if Src (S + 1) = ')' then
2236 S := S + 1;
2237 exit Search_Loop;
2239 elsif Src (S + 1) <= ' ' then
2240 S := S + 1;
2242 else
2243 exit Search_Loop;
2244 end if;
2245 end loop Search_Loop;
2246 end loop Paren_Loop;
2248 exit Node_Loop when F = N;
2249 F := Parent (F);
2250 exit Node_Loop when Nkind (F) not in N_Subexpr;
2251 end loop Node_Loop;
2253 -- Remove any trailing space
2255 while S in SF + 1 .. SL
2256 and then Src (S) = ' '
2257 loop
2258 S := S - 1;
2259 end loop;
2261 return S;
2262 end Last_Sloc;
2264 -----------------
2265 -- No_Warnings --
2266 -----------------
2268 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
2269 begin
2270 if Error_Posted (N) then
2271 return True;
2273 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
2274 return True;
2276 elsif Is_Entity_Name (N)
2277 and then Present (Entity (N))
2278 and then Has_Warnings_Off (Entity (N))
2279 then
2280 return True;
2282 else
2283 return False;
2284 end if;
2285 end No_Warnings;
2287 -------------
2288 -- OK_Node --
2289 -------------
2291 function OK_Node (N : Node_Id) return Boolean is
2292 K : constant Node_Kind := Nkind (N);
2294 begin
2295 if Error_Posted (N) then
2296 return False;
2298 elsif K in N_Has_Etype
2299 and then Present (Etype (N))
2300 and then Error_Posted (Etype (N))
2301 then
2302 return False;
2304 elsif (K in N_Op
2305 or else K = N_Attribute_Reference
2306 or else K = N_Character_Literal
2307 or else K = N_Expanded_Name
2308 or else K = N_Identifier
2309 or else K = N_Operator_Symbol)
2310 and then Present (Entity (N))
2311 and then Error_Posted (Entity (N))
2312 then
2313 return False;
2314 else
2315 return True;
2316 end if;
2317 end OK_Node;
2319 -------------------------
2320 -- Output_JSON_Message --
2321 -------------------------
2323 procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
2325 function Is_Continuation (E : Error_Msg_Id) return Boolean;
2326 -- Return True if E is a continuation message.
2328 procedure Write_JSON_Escaped_String (Str : String_Ptr);
2329 procedure Write_JSON_Escaped_String (Str : String);
2330 -- Write each character of Str, taking care of preceding each quote and
2331 -- backslash with a backslash. Note that this escaping differs from what
2332 -- GCC does.
2334 -- Indeed, the JSON specification mandates encoding wide characters
2335 -- either as their direct UTF-8 representation or as their escaped
2336 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2337 -- we choose to use the UTF-8 representation instead.
2339 procedure Write_JSON_Location (Sptr : Source_Ptr);
2340 -- Write Sptr as a JSON location, an object containing a file attribute,
2341 -- a line number and a column number.
2343 procedure Write_JSON_Span (Error : Error_Msg_Object);
2344 -- Write Error as a JSON span, an object containing a "caret" attribute
2345 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2346 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2347 -- locations under the names "start" and "finish".
2348 -- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional,
2349 -- non-standard, attribute named "subprogram" will be added, allowing
2350 -- precisely identifying the subprogram surrounding the span.
2352 -----------------------
2353 -- Is_Continuation --
2354 -----------------------
2356 function Is_Continuation (E : Error_Msg_Id) return Boolean is
2357 begin
2358 return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
2359 end Is_Continuation;
2361 -------------------------------
2362 -- Write_JSON_Escaped_String --
2363 -------------------------------
2365 procedure Write_JSON_Escaped_String (Str : String) is
2366 begin
2367 for C of Str loop
2368 if C = '"' or else C = '\' then
2369 Write_Char ('\');
2370 end if;
2372 Write_Char (C);
2373 end loop;
2374 end Write_JSON_Escaped_String;
2376 -------------------------------
2377 -- Write_JSON_Escaped_String --
2378 -------------------------------
2380 procedure Write_JSON_Escaped_String (Str : String_Ptr) is
2381 begin
2382 Write_JSON_Escaped_String (Str.all);
2383 end Write_JSON_Escaped_String;
2385 -------------------------
2386 -- Write_JSON_Location --
2387 -------------------------
2389 procedure Write_JSON_Location (Sptr : Source_Ptr) is
2390 Name : constant File_Name_Type :=
2391 Full_Ref_Name (Get_Source_File_Index (Sptr));
2392 begin
2393 Write_Str ("{""file"":""");
2394 if Full_Path_Name_For_Brief_Errors then
2395 Write_JSON_Escaped_String
2396 (System.OS_Lib.Normalize_Pathname (Get_Name_String (Name)));
2397 else
2398 Write_Name (Name);
2399 end if;
2400 Write_Str (""",""line"":");
2401 Write_Int (Pos (Get_Physical_Line_Number (Sptr)));
2402 Write_Str (", ""column"":");
2403 Write_Int (Nat (Get_Column_Number (Sptr)));
2404 Write_Str ("}");
2405 end Write_JSON_Location;
2407 ---------------------
2408 -- Write_JSON_Span --
2409 ---------------------
2411 procedure Write_JSON_Span (Error : Error_Msg_Object) is
2412 Span : constant Source_Span := Error.Sptr;
2413 begin
2414 Write_Str ("{""caret"":");
2415 Write_JSON_Location (Span.Ptr);
2417 if Span.Ptr /= Span.First then
2418 Write_Str (",""start"":");
2419 Write_JSON_Location (Span.First);
2420 end if;
2422 if Span.Ptr /= Span.Last then
2423 Write_Str (",""finish"":");
2424 Write_JSON_Location (Span.Last);
2425 end if;
2427 if Include_Subprogram_In_Messages then
2428 Write_Str (",""subprogram"":""");
2429 Write_JSON_Escaped_String (Subprogram_Name_Ptr (Error.Node));
2430 Write_Str ("""");
2431 end if;
2433 Write_Str ("}");
2434 end Write_JSON_Span;
2436 -- Local Variables
2438 E : Error_Msg_Id := Error_Id;
2440 Print_Continuations : constant Boolean := not Is_Continuation (E);
2441 -- Do not print continuations messages as children of the current
2442 -- message if the current message is a continuation message.
2444 Option : constant String := Get_Warning_Option (E);
2445 -- The option that triggered this message.
2447 -- Start of processing for Output_JSON_Message
2449 begin
2451 -- Print message kind
2453 Write_Str ("{""kind"":");
2455 if Errors.Table (E).Warn and then not Errors.Table (E).Warn_Err then
2456 Write_Str ("""warning""");
2457 elsif Errors.Table (E).Info or else Errors.Table (E).Check then
2458 Write_Str ("""note""");
2459 else
2460 Write_Str ("""error""");
2461 end if;
2463 -- Print message location
2465 Write_Str (",""locations"":[");
2466 Write_JSON_Span (Errors.Table (E));
2468 if Errors.Table (E).Optr.Ptr /= Errors.Table (E).Sptr.Ptr then
2469 Write_Str (",{""caret"":");
2470 Write_JSON_Location (Errors.Table (E).Optr.Ptr);
2471 Write_Str ("}");
2472 end if;
2474 Write_Str ("]");
2476 -- Print message option, if there is one
2477 if Option /= "" then
2478 Write_Str (",""option"":""" & Option & """");
2479 end if;
2481 -- Print message content
2483 Write_Str (",""message"":""");
2484 Write_JSON_Escaped_String (Errors.Table (E).Text);
2485 Write_Str ("""");
2487 E := E + 1;
2489 if Print_Continuations and then Is_Continuation (E) then
2491 Write_Str (",""children"": [");
2492 Output_JSON_Message (E);
2493 E := E + 1;
2495 while Is_Continuation (E) loop
2496 Write_Str (", ");
2497 Output_JSON_Message (E);
2498 E := E + 1;
2499 end loop;
2501 Write_Str ("]");
2503 end if;
2505 Write_Str ("}");
2506 end Output_JSON_Message;
2508 ---------------------
2509 -- Output_Messages --
2510 ---------------------
2512 procedure Output_Messages is
2514 -- Local subprograms
2516 procedure Write_Error_Summary;
2517 -- Write error summary
2519 procedure Write_Header (Sfile : Source_File_Index);
2520 -- Write header line (compiling or checking given file)
2522 procedure Write_Max_Errors;
2523 -- Write message if max errors reached
2525 procedure Write_Source_Code_Lines
2526 (Span : Source_Span;
2527 SGR_Span : String);
2528 -- Write the source code line corresponding to Span, as follows when
2529 -- Span in on one line:
2531 -- line | actual code line here with Span somewhere
2532 -- | ~~~~~^~~~
2534 -- where the caret on the line points to location Span.Ptr, and the
2535 -- range Span.First..Span.Last is underlined.
2537 -- or when the span is over multiple lines:
2539 -- line | beginning of the Span on this line
2540 -- ... | ...
2541 -- line>| actual code line here with Span.Ptr somewhere
2542 -- ... | ...
2543 -- line | end of the Span on this line
2545 -- or when the span is a simple location, as follows:
2547 -- line | actual code line here with Span somewhere
2548 -- | ^ here
2550 -- where the caret on the line points to location Span.Ptr
2552 -- SGR_Span is the SGR string to start the section of code in the span,
2553 -- that should be closed with SGR_Reset.
2555 -------------------------
2556 -- Write_Error_Summary --
2557 -------------------------
2559 procedure Write_Error_Summary is
2560 begin
2561 -- Extra blank line if error messages or source listing were output
2563 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
2564 then
2565 Write_Eol;
2566 end if;
2568 -- Message giving number of lines read and number of errors detected.
2569 -- This normally goes to Standard_Output. The exception is when brief
2570 -- mode is not set, verbose mode (or full list mode) is set, and
2571 -- there are errors. In this case we send the message to standard
2572 -- error to make sure that *something* appears on standard error
2573 -- in an error situation.
2575 if Total_Errors_Detected + Warnings_Detected /= 0
2576 and then not Brief_Output
2577 and then (Verbose_Mode or Full_List)
2578 then
2579 Set_Standard_Error;
2580 end if;
2582 -- Message giving total number of lines. Don't give this message if
2583 -- the Main_Source line is unknown (this happens in error situations,
2584 -- e.g. when integrated preprocessing fails).
2586 if Main_Source_File > No_Source_File then
2587 Write_Str (" ");
2588 Write_Int (Num_Source_Lines (Main_Source_File));
2590 if Num_Source_Lines (Main_Source_File) = 1 then
2591 Write_Str (" line: ");
2592 else
2593 Write_Str (" lines: ");
2594 end if;
2595 end if;
2597 if Total_Errors_Detected = 0 then
2598 Write_Str ("No errors");
2600 elsif Total_Errors_Detected = 1 then
2601 Write_Str ("1 error");
2603 else
2604 Write_Int (Total_Errors_Detected);
2605 Write_Str (" errors");
2606 end if;
2608 -- We now need to output warnings. When using -gnatwe, all warnings
2609 -- should be treated as errors, except for warnings originating from
2610 -- the use of the Compile_Time_Warning pragma. Another situation
2611 -- where a warning might be treated as an error is when the source
2612 -- code contains a Warning_As_Error pragma.
2613 -- When warnings are treated as errors, we still log them as
2614 -- warnings, but we add a message denoting how many of these warnings
2615 -- are also errors.
2617 declare
2618 Warnings_Count : constant Int :=
2619 Warnings_Detected - Warning_Info_Messages;
2621 Compile_Time_Warnings : Int;
2622 -- Number of warnings that come from a Compile_Time_Warning
2623 -- pragma.
2625 Non_Compile_Time_Warnings : Int;
2626 -- Number of warnings that do not come from a Compile_Time_Warning
2627 -- pragmas.
2629 begin
2630 if Warnings_Count > 0 then
2631 Write_Str (", ");
2632 Write_Int (Warnings_Count);
2633 Write_Str (" warning");
2635 if Warnings_Count > 1 then
2636 Write_Char ('s');
2637 end if;
2639 Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
2640 Non_Compile_Time_Warnings :=
2641 Warnings_Count - Compile_Time_Warnings;
2643 if Warning_Mode = Treat_As_Error
2644 and then Non_Compile_Time_Warnings > 0
2645 then
2646 Write_Str (" (");
2648 if Compile_Time_Warnings > 0 then
2649 Write_Int (Non_Compile_Time_Warnings);
2650 Write_Str (" ");
2651 end if;
2653 Write_Str ("treated as error");
2655 if Non_Compile_Time_Warnings > 1 then
2656 Write_Char ('s');
2657 end if;
2659 Write_Char (')');
2661 elsif Warnings_Treated_As_Errors > 0 then
2662 Write_Str (" (");
2664 if Warnings_Treated_As_Errors /= Warnings_Count then
2665 Write_Int (Warnings_Treated_As_Errors);
2666 Write_Str (" ");
2667 end if;
2669 Write_Str ("treated as error");
2671 if Warnings_Treated_As_Errors > 1 then
2672 Write_Str ("s");
2673 end if;
2675 Write_Str (")");
2676 end if;
2677 end if;
2678 end;
2680 if Warning_Info_Messages + Report_Info_Messages /= 0 then
2681 Write_Str (", ");
2682 Write_Int (Warning_Info_Messages + Report_Info_Messages);
2683 Write_Str (" info message");
2685 if Warning_Info_Messages + Report_Info_Messages > 1 then
2686 Write_Char ('s');
2687 end if;
2688 end if;
2690 Write_Eol;
2691 Set_Standard_Output;
2692 end Write_Error_Summary;
2694 ------------------
2695 -- Write_Header --
2696 ------------------
2698 procedure Write_Header (Sfile : Source_File_Index) is
2699 begin
2700 if Verbose_Mode or Full_List then
2701 if Original_Operating_Mode = Generate_Code then
2702 Write_Str ("Compiling: ");
2703 else
2704 Write_Str ("Checking: ");
2705 end if;
2707 Write_Name (Full_File_Name (Sfile));
2709 if not Debug_Flag_7 then
2710 Write_Eol;
2711 Write_Str ("Source file time stamp: ");
2712 Write_Time_Stamp (Sfile);
2713 Write_Eol;
2714 Write_Str ("Compiled at: " & Compilation_Time);
2715 end if;
2717 Write_Eol;
2718 end if;
2719 end Write_Header;
2721 ----------------------
2722 -- Write_Max_Errors --
2723 ----------------------
2725 procedure Write_Max_Errors is
2726 begin
2727 if Maximum_Messages /= 0 then
2728 if Warnings_Detected >= Maximum_Messages then
2729 Set_Standard_Error;
2730 Write_Line ("maximum number of warnings output");
2731 Write_Line ("any further warnings suppressed");
2732 Set_Standard_Output;
2733 end if;
2735 -- If too many errors print message
2737 if Total_Errors_Detected >= Maximum_Messages then
2738 Set_Standard_Error;
2739 Write_Line ("fatal error: maximum number of errors detected");
2740 Set_Standard_Output;
2741 end if;
2742 end if;
2743 end Write_Max_Errors;
2745 -----------------------------
2746 -- Write_Source_Code_Lines --
2747 -----------------------------
2749 procedure Write_Source_Code_Lines
2750 (Span : Source_Span;
2751 SGR_Span : String)
2753 function Get_Line_End
2754 (Buf : Source_Buffer_Ptr;
2755 Loc : Source_Ptr) return Source_Ptr;
2756 -- Get the source location for the end of the line in Buf for Loc. If
2757 -- Loc is past the end of Buf already, return Buf'Last.
2759 function Get_Line_Start
2760 (Buf : Source_Buffer_Ptr;
2761 Loc : Source_Ptr) return Source_Ptr;
2762 -- Get the source location for the start of the line in Buf for Loc
2764 function Image (X : Positive; Width : Positive) return String;
2765 -- Output number X over Width characters, with whitespace padding.
2766 -- Only output the low-order Width digits of X, if X is larger than
2767 -- Width digits.
2769 procedure Write_Buffer
2770 (Buf : Source_Buffer_Ptr;
2771 First : Source_Ptr;
2772 Last : Source_Ptr);
2773 -- Output the characters from First to Last position in Buf, using
2774 -- Write_Buffer_Char.
2776 procedure Write_Buffer_Char
2777 (Buf : Source_Buffer_Ptr;
2778 Loc : Source_Ptr);
2779 -- Output the characters at position Loc in Buf, translating ASCII.HT
2780 -- in a suitable number of spaces so that the output is not modified
2781 -- by starting in a different column that 1.
2783 procedure Write_Line_Marker
2784 (Num : Pos;
2785 Mark : Boolean;
2786 Width : Positive);
2787 -- Output the line number Num over Width characters, with possibly
2788 -- a Mark to denote the line with the main location when reporting
2789 -- a span over multiple lines.
2791 ------------------
2792 -- Get_Line_End --
2793 ------------------
2795 function Get_Line_End
2796 (Buf : Source_Buffer_Ptr;
2797 Loc : Source_Ptr) return Source_Ptr
2799 Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
2800 begin
2801 while Cur_Loc < Buf'Last
2802 and then Buf (Cur_Loc) /= ASCII.LF
2803 loop
2804 Cur_Loc := Cur_Loc + 1;
2805 end loop;
2807 return Cur_Loc;
2808 end Get_Line_End;
2810 --------------------
2811 -- Get_Line_Start --
2812 --------------------
2814 function Get_Line_Start
2815 (Buf : Source_Buffer_Ptr;
2816 Loc : Source_Ptr) return Source_Ptr
2818 Cur_Loc : Source_Ptr := Loc;
2819 begin
2820 while Cur_Loc > Buf'First
2821 and then Buf (Cur_Loc - 1) /= ASCII.LF
2822 loop
2823 Cur_Loc := Cur_Loc - 1;
2824 end loop;
2826 return Cur_Loc;
2827 end Get_Line_Start;
2829 -----------
2830 -- Image --
2831 -----------
2833 function Image (X : Positive; Width : Positive) return String is
2834 Str : String (1 .. Width);
2835 Curr : Natural := X;
2836 begin
2837 for J in reverse 1 .. Width loop
2838 if Curr > 0 then
2839 Str (J) := Character'Val (Character'Pos ('0') + Curr mod 10);
2840 Curr := Curr / 10;
2841 else
2842 Str (J) := ' ';
2843 end if;
2844 end loop;
2846 return Str;
2847 end Image;
2849 ------------------
2850 -- Write_Buffer --
2851 ------------------
2853 procedure Write_Buffer
2854 (Buf : Source_Buffer_Ptr;
2855 First : Source_Ptr;
2856 Last : Source_Ptr)
2858 begin
2859 for Loc in First .. Last loop
2860 Write_Buffer_Char (Buf, Loc);
2861 end loop;
2862 end Write_Buffer;
2864 -----------------------
2865 -- Write_Buffer_Char --
2866 -----------------------
2868 procedure Write_Buffer_Char
2869 (Buf : Source_Buffer_Ptr;
2870 Loc : Source_Ptr)
2872 begin
2873 -- If the character ASCII.HT is not the last one in the file,
2874 -- output as many spaces as the character represents in the
2875 -- original source file.
2877 if Buf (Loc) = ASCII.HT
2878 and then Loc < Buf'Last
2879 then
2880 for X in Get_Column_Number (Loc) ..
2881 Get_Column_Number (Loc + 1) - 1
2882 loop
2883 Write_Char (' ');
2884 end loop;
2886 -- Otherwise output the character itself
2888 else
2889 Write_Char (Buf (Loc));
2890 end if;
2891 end Write_Buffer_Char;
2893 -----------------------
2894 -- Write_Line_Marker --
2895 -----------------------
2897 procedure Write_Line_Marker
2898 (Num : Pos;
2899 Mark : Boolean;
2900 Width : Positive)
2902 begin
2903 Write_Str (Image (Positive (Num), Width => Width));
2904 Write_Str ((if Mark then ">" else " ") & "|");
2905 end Write_Line_Marker;
2907 -- Local variables
2909 Loc : constant Source_Ptr := Span.Ptr;
2910 Line : constant Pos := Pos (Get_Physical_Line_Number (Loc));
2912 Col : constant Natural := Natural (Get_Column_Number (Loc));
2914 Fst : constant Source_Ptr := Span.First;
2915 Line_Fst : constant Pos :=
2916 Pos (Get_Physical_Line_Number (Fst));
2917 Col_Fst : constant Natural :=
2918 Natural (Get_Column_Number (Fst));
2919 Lst : constant Source_Ptr := Span.Last;
2920 Line_Lst : constant Pos :=
2921 Pos (Get_Physical_Line_Number (Lst));
2922 Col_Lst : constant Natural :=
2923 Natural (Get_Column_Number (Lst));
2925 Width : constant := 5;
2926 Buf : Source_Buffer_Ptr;
2927 Cur_Loc : Source_Ptr := Fst;
2928 Cur_Line : Pos := Line_Fst;
2930 -- Start of processing for Write_Source_Code_Lines
2932 begin
2933 if Loc >= First_Source_Ptr then
2934 Buf := Source_Text (Get_Source_File_Index (Loc));
2936 -- First line of the span with actual source code. We retrieve
2937 -- the beginning of the line instead of relying on Col_Fst, as
2938 -- ASCII.HT characters change column numbers by possibly more
2939 -- than one.
2941 Write_Line_Marker
2942 (Cur_Line,
2943 Line_Fst /= Line_Lst and then Cur_Line = Line,
2944 Width);
2945 Write_Buffer (Buf, Get_Line_Start (Buf, Cur_Loc), Cur_Loc - 1);
2947 -- Output the first/caret/last lines of the span, as well as
2948 -- lines that are directly above/below the caret if they complete
2949 -- the gap with first/last lines, otherwise use ... to denote
2950 -- intermediate lines.
2952 -- If the span is on one line and not a simple source location,
2953 -- color it appropriately.
2955 if Line_Fst = Line_Lst
2956 and then Col_Fst /= Col_Lst
2957 then
2958 Write_Str (SGR_Span);
2959 end if;
2961 declare
2962 function Do_Write_Line (Cur_Line : Pos) return Boolean is
2963 (Cur_Line in Line_Fst | Line | Line_Lst
2964 or else
2965 (Cur_Line = Line_Fst + 1 and then Cur_Line = Line - 1)
2966 or else
2967 (Cur_Line = Line + 1 and then Cur_Line = Line_Lst - 1));
2968 begin
2969 while Cur_Loc <= Buf'Last
2970 and then Cur_Loc <= Lst
2971 loop
2972 if Do_Write_Line (Cur_Line) then
2973 Write_Buffer_Char (Buf, Cur_Loc);
2974 end if;
2976 if Buf (Cur_Loc) = ASCII.LF then
2977 Cur_Line := Cur_Line + 1;
2979 -- Output ... for skipped lines
2981 if (Cur_Line = Line
2982 and then not Do_Write_Line (Cur_Line - 1))
2983 or else
2984 (Cur_Line = Line + 1
2985 and then not Do_Write_Line (Cur_Line))
2986 then
2987 Write_Str ((1 .. Width - 3 => ' ') & "... | ...");
2988 Write_Eol;
2989 end if;
2991 -- Display the line marker if the line should be
2992 -- displayed.
2994 if Do_Write_Line (Cur_Line) then
2995 Write_Line_Marker
2996 (Cur_Line,
2997 Line_Fst /= Line_Lst and then Cur_Line = Line,
2998 Width);
2999 end if;
3000 end if;
3002 Cur_Loc := Cur_Loc + 1;
3003 end loop;
3004 end;
3006 if Line_Fst = Line_Lst
3007 and then Col_Fst /= Col_Lst
3008 then
3009 Write_Str (SGR_Reset);
3010 end if;
3012 -- Output the rest of the last line of the span
3014 Write_Buffer (Buf, Cur_Loc, Get_Line_End (Buf, Cur_Loc));
3016 -- If the span is on one line, output a second line with caret
3017 -- sign pointing to location Loc
3019 if Line_Fst = Line_Lst then
3020 Write_Str (String'(1 .. Width => ' '));
3021 Write_Str (" |");
3022 Write_Str (String'(1 .. Col_Fst - 1 => ' '));
3024 Write_Str (SGR_Span);
3026 Write_Str (String'(Col_Fst .. Col - 1 => '~'));
3027 Write_Str ("^");
3028 Write_Str (String'(Col + 1 .. Col_Lst => '~'));
3030 -- If the span is really just a location, add the word "here"
3031 -- to clarify this is the location for the message.
3033 if Col_Fst = Col_Lst then
3034 Write_Str (" here");
3035 end if;
3037 Write_Str (SGR_Reset);
3039 Write_Eol;
3040 end if;
3041 end if;
3042 end Write_Source_Code_Lines;
3044 -- Local variables
3046 E : Error_Msg_Id;
3047 Err_Flag : Boolean;
3048 Use_Prefix : Boolean;
3050 -- Start of processing for Output_Messages
3052 begin
3053 -- Error if Finalize has not been called
3055 if not Finalize_Called then
3056 raise Program_Error;
3057 end if;
3059 -- Reset current error source file if the main unit has a pragma
3060 -- Source_Reference. This ensures outputting the proper name of
3061 -- the source file in this situation.
3063 if Main_Source_File <= No_Source_File
3064 or else Num_SRef_Pragmas (Main_Source_File) /= 0
3065 then
3066 Current_Error_Source_File := No_Source_File;
3067 end if;
3069 if Opt.JSON_Output then
3070 Set_Standard_Error;
3072 E := First_Error_Msg;
3074 -- Find first printable message
3076 while E /= No_Error_Msg and then Errors.Table (E).Deleted loop
3077 E := Errors.Table (E).Next;
3078 end loop;
3080 Write_Char ('[');
3082 if E /= No_Error_Msg then
3084 Output_JSON_Message (E);
3086 E := Errors.Table (E).Next;
3088 while E /= No_Error_Msg loop
3090 -- Skip deleted messages.
3091 -- Also skip continuation messages, as they have already been
3092 -- printed along the message they're attached to.
3094 if not Errors.Table (E).Deleted
3095 and then not Errors.Table (E).Msg_Cont
3096 then
3097 Write_Char (',');
3098 Output_JSON_Message (E);
3099 end if;
3101 E := Errors.Table (E).Next;
3102 end loop;
3103 end if;
3105 Write_Char (']');
3107 Set_Standard_Output;
3109 -- Brief Error mode
3111 elsif Brief_Output or (not Full_List and not Verbose_Mode) then
3112 Set_Standard_Error;
3114 E := First_Error_Msg;
3115 while E /= No_Error_Msg loop
3117 -- If -gnatdF is used, separate main messages from previous
3118 -- messages with a newline (unless it is an info message) and
3119 -- make continuation messages follow the main message with only
3120 -- an indentation of two space characters, without repeating
3121 -- file:line:col: prefix.
3123 Use_Prefix :=
3124 not (Debug_Flag_FF and then Errors.Table (E).Msg_Cont);
3126 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
3128 if Debug_Flag_FF then
3129 if Errors.Table (E).Msg_Cont then
3130 Write_Str (" ");
3131 elsif not Errors.Table (E).Info then
3132 Write_Eol;
3133 end if;
3134 end if;
3136 if Use_Prefix then
3137 Write_Str (SGR_Locus);
3139 if Full_Path_Name_For_Brief_Errors then
3140 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
3141 else
3142 Write_Name (Reference_Name (Errors.Table (E).Sfile));
3143 end if;
3145 Write_Char (':');
3146 Write_Int (Int (Physical_To_Logical
3147 (Errors.Table (E).Line,
3148 Errors.Table (E).Sfile)));
3149 Write_Char (':');
3151 if Errors.Table (E).Col < 10 then
3152 Write_Char ('0');
3153 end if;
3155 Write_Int (Int (Errors.Table (E).Col));
3156 Write_Str (": ");
3158 Write_Str (SGR_Reset);
3159 end if;
3161 Output_Msg_Text (E);
3162 Write_Eol;
3164 -- If -gnatdF is used, write the source code line corresponding
3165 -- to the location of the main message (unless it is an info
3166 -- message). Also write the source code line corresponding to
3167 -- an insertion location inside continuation messages.
3169 if Debug_Flag_FF
3170 and then not Errors.Table (E).Info
3171 then
3172 if Errors.Table (E).Msg_Cont then
3173 declare
3174 Loc : constant Source_Ptr :=
3175 Errors.Table (E).Insertion_Sloc;
3176 begin
3177 if Loc /= No_Location then
3178 Write_Source_Code_Lines
3179 (To_Span (Loc), SGR_Span => SGR_Note);
3180 end if;
3181 end;
3183 else
3184 declare
3185 SGR_Span : constant String :=
3186 (if Errors.Table (E).Info then SGR_Note
3187 elsif Errors.Table (E).Warn
3188 and then not Errors.Table (E).Warn_Err
3189 then SGR_Warning
3190 else SGR_Error);
3191 begin
3192 Write_Source_Code_Lines
3193 (Errors.Table (E).Optr, SGR_Span);
3194 end;
3195 end if;
3196 end if;
3197 end if;
3199 E := Errors.Table (E).Next;
3200 end loop;
3202 Set_Standard_Output;
3203 end if;
3205 -- Full source listing case
3207 if Full_List then
3208 List_Pragmas_Index := 1;
3209 List_Pragmas_Mode := True;
3210 E := First_Error_Msg;
3212 -- Normal case, to stdout (copyright notice already output)
3214 if Full_List_File_Name = null then
3215 if not Debug_Flag_7 then
3216 Write_Eol;
3217 end if;
3219 -- Output to file
3221 else
3222 Create_List_File_Access.all (Full_List_File_Name.all);
3223 Set_Special_Output (Write_List_Info_Access.all'Access);
3225 -- Write copyright notice to file
3227 if not Debug_Flag_7 then
3228 Write_Str ("GNAT ");
3229 Write_Str (Gnat_Version_String);
3230 Write_Eol;
3231 Write_Str ("Copyright 1992-" &
3232 Current_Year &
3233 ", Free Software Foundation, Inc.");
3234 Write_Eol;
3235 end if;
3236 end if;
3238 -- First list extended main source file units with errors
3240 for U in Main_Unit .. Last_Unit loop
3241 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
3243 -- If debug flag d.m is set, only the main source is listed
3245 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
3247 -- If the unit of the entity does not come from source, it is
3248 -- an implicit subprogram declaration for a child subprogram.
3249 -- Do not emit errors for it, they are listed with the body.
3251 and then
3252 (No (Cunit_Entity (U))
3253 or else Comes_From_Source (Cunit_Entity (U))
3254 or else not Is_Subprogram (Cunit_Entity (U)))
3256 -- If the compilation unit associated with this unit does not
3257 -- come from source, it means it is an instantiation that should
3258 -- not be included in the source listing.
3260 and then Comes_From_Source (Cunit (U))
3261 then
3262 declare
3263 Sfile : constant Source_File_Index := Source_Index (U);
3265 begin
3266 Write_Eol;
3268 -- Only write the header if Sfile is known
3270 if Sfile > No_Source_File then
3271 Write_Header (Sfile);
3272 Write_Eol;
3273 end if;
3275 -- Normally, we don't want an "error messages from file"
3276 -- message when listing the entire file, so we set the
3277 -- current source file as the current error source file.
3278 -- However, the old style of doing things was to list this
3279 -- message if pragma Source_Reference is present, even for
3280 -- the main unit. Since the purpose of the -gnatd.m switch
3281 -- is to duplicate the old behavior, we skip the reset if
3282 -- this debug flag is set.
3284 if not Debug_Flag_Dot_M then
3285 Current_Error_Source_File := Sfile;
3286 end if;
3288 -- Only output the listing if Sfile is known, to avoid
3289 -- crashing the compiler.
3291 if Sfile > No_Source_File then
3292 for N in 1 .. Last_Source_Line (Sfile) loop
3293 while E /= No_Error_Msg
3294 and then Errors.Table (E).Deleted
3295 loop
3296 E := Errors.Table (E).Next;
3297 end loop;
3299 Err_Flag :=
3300 E /= No_Error_Msg
3301 and then Errors.Table (E).Line = N
3302 and then Errors.Table (E).Sfile = Sfile;
3304 Output_Source_Line (N, Sfile, Err_Flag);
3306 if Err_Flag then
3307 Output_Error_Msgs (E);
3309 if not Debug_Flag_2 then
3310 Write_Eol;
3311 end if;
3312 end if;
3313 end loop;
3314 end if;
3315 end;
3316 end if;
3317 end loop;
3319 -- Then output errors, if any, for subsidiary units not in the
3320 -- main extended unit.
3322 -- Note: if debug flag d.m set, include errors for any units other
3323 -- than the main unit in the extended source unit (e.g. spec and
3324 -- subunits for a body).
3326 while E /= No_Error_Msg
3327 and then (not In_Extended_Main_Source_Unit
3328 (Errors.Table (E).Sptr.Ptr)
3329 or else
3330 (Debug_Flag_Dot_M
3331 and then Get_Source_Unit
3332 (Errors.Table (E).Sptr.Ptr) /= Main_Unit))
3333 loop
3334 if Errors.Table (E).Deleted then
3335 E := Errors.Table (E).Next;
3337 else
3338 Write_Eol;
3339 Output_Source_Line
3340 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3341 Output_Error_Msgs (E);
3342 end if;
3343 end loop;
3345 -- If output to file, write extra copy of error summary to the
3346 -- output file, and then close it.
3348 if Full_List_File_Name /= null then
3349 Write_Error_Summary;
3350 Write_Max_Errors;
3351 Close_List_File_Access.all;
3352 Cancel_Special_Output;
3353 end if;
3354 end if;
3356 -- Verbose mode (error lines only with error flags). Normally this is
3357 -- ignored in full list mode, unless we are listing to a file, in which
3358 -- case we still generate -gnatv output to standard output.
3360 if Verbose_Mode
3361 and then (not Full_List or else Full_List_File_Name /= null)
3362 then
3363 Write_Eol;
3365 -- Output the header only when Main_Source_File is known
3367 if Main_Source_File > No_Source_File then
3368 Write_Header (Main_Source_File);
3369 end if;
3371 E := First_Error_Msg;
3373 -- Loop through error lines
3375 while E /= No_Error_Msg loop
3376 if Errors.Table (E).Deleted then
3377 E := Errors.Table (E).Next;
3378 else
3379 Write_Eol;
3380 Output_Source_Line
3381 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3382 Output_Error_Msgs (E);
3383 end if;
3384 end loop;
3385 end if;
3387 -- Output error summary if verbose or full list mode
3389 if Verbose_Mode or else Full_List then
3390 Write_Error_Summary;
3391 end if;
3393 if not Opt.JSON_Output then
3394 Write_Max_Errors;
3395 end if;
3397 -- Even though Warning_Info_Messages are a subclass of warnings, they
3398 -- must not be treated as errors when -gnatwe is in effect.
3400 if Warning_Mode = Treat_As_Error then
3401 declare
3402 Compile_Time_Pragma_Warnings : constant Int :=
3403 Count_Compile_Time_Pragma_Warnings;
3404 begin
3405 Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected
3406 - Warning_Info_Messages - Compile_Time_Pragma_Warnings;
3407 Warnings_Detected :=
3408 Warning_Info_Messages + Compile_Time_Pragma_Warnings;
3409 end;
3410 end if;
3411 end Output_Messages;
3413 ------------------------
3414 -- Output_Source_Line --
3415 ------------------------
3417 procedure Output_Source_Line
3418 (L : Physical_Line_Number;
3419 Sfile : Source_File_Index;
3420 Errs : Boolean)
3422 S : Source_Ptr;
3423 C : Character;
3425 Line_Number_Output : Boolean := False;
3426 -- Set True once line number is output
3428 Empty_Line : Boolean := True;
3429 -- Set False if line includes at least one character
3431 begin
3432 if Sfile /= Current_Error_Source_File then
3433 Write_Str ("==============Error messages for ");
3435 case Sinput.File_Type (Sfile) is
3436 when Sinput.Src =>
3437 Write_Str ("source");
3439 when Sinput.Config =>
3440 Write_Str ("configuration pragmas");
3442 when Sinput.Def =>
3443 Write_Str ("symbol definition");
3445 when Sinput.Preproc =>
3446 Write_Str ("preprocessing data");
3447 end case;
3449 Write_Str (" file: ");
3450 Write_Name (Full_File_Name (Sfile));
3451 Write_Eol;
3453 if Num_SRef_Pragmas (Sfile) > 0 then
3454 Write_Str ("--------------Line numbers from file: ");
3455 Write_Name (Full_Ref_Name (Sfile));
3456 Write_Str (" (starting at line ");
3457 Write_Int (Int (First_Mapped_Line (Sfile)));
3458 Write_Char (')');
3459 Write_Eol;
3460 end if;
3462 Current_Error_Source_File := Sfile;
3463 end if;
3465 if Errs or List_Pragmas_Mode then
3466 Output_Line_Number (Physical_To_Logical (L, Sfile));
3467 Line_Number_Output := True;
3468 end if;
3470 S := Line_Start (L, Sfile);
3472 loop
3473 C := Source_Text (Sfile) (S);
3474 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
3476 -- Deal with matching entry in List_Pragmas table
3478 if Full_List
3479 and then List_Pragmas_Index <= List_Pragmas.Last
3480 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
3481 then
3482 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
3483 when Page =>
3484 Write_Char (C);
3486 -- Ignore if on line with errors so that error flags
3487 -- get properly listed with the error line .
3489 if not Errs then
3490 Write_Char (ASCII.FF);
3491 end if;
3493 when List_On =>
3494 List_Pragmas_Mode := True;
3496 if not Line_Number_Output then
3497 Output_Line_Number (Physical_To_Logical (L, Sfile));
3498 Line_Number_Output := True;
3499 end if;
3501 Write_Char (C);
3503 when List_Off =>
3504 Write_Char (C);
3505 List_Pragmas_Mode := False;
3506 end case;
3508 List_Pragmas_Index := List_Pragmas_Index + 1;
3510 -- Normal case (no matching entry in List_Pragmas table)
3512 else
3513 if Errs or List_Pragmas_Mode then
3514 Write_Char (C);
3515 end if;
3516 end if;
3518 Empty_Line := False;
3519 S := S + 1;
3520 end loop;
3522 -- If we have output a source line, then add the line terminator, with
3523 -- training spaces preserved (so we output the line exactly as input).
3525 if Line_Number_Output then
3526 if Empty_Line then
3527 Write_Eol;
3528 else
3529 Write_Eol_Keep_Blanks;
3530 end if;
3531 end if;
3532 end Output_Source_Line;
3534 --------------------
3535 -- Paren_Required --
3536 --------------------
3538 function Paren_Required (N : Node_Id) return Boolean is
3539 begin
3540 -- In a qualifed_expression the expression part needs to be enclosed in
3541 -- parentheses.
3543 if Nkind (Parent (N)) = N_Qualified_Expression then
3544 return N = Expression (Parent (N));
3546 else
3547 return False;
3548 end if;
3549 end Paren_Required;
3551 -----------------------------
3552 -- Remove_Warning_Messages --
3553 -----------------------------
3555 procedure Remove_Warning_Messages (N : Node_Id) is
3557 function Check_For_Warning (N : Node_Id) return Traverse_Result;
3558 -- This function checks one node for a possible warning message
3560 procedure Check_All_Warnings is new Traverse_Proc (Check_For_Warning);
3561 -- This defines the traversal operation
3563 -----------------------
3564 -- Check_For_Warning --
3565 -----------------------
3567 function Check_For_Warning (N : Node_Id) return Traverse_Result is
3568 Loc : constant Source_Ptr := Sloc (N);
3569 E : Error_Msg_Id;
3571 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
3572 -- Returns True for a message that is to be removed. Also adjusts
3573 -- warning count appropriately.
3575 -------------------
3576 -- To_Be_Removed --
3577 -------------------
3579 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
3580 begin
3581 if E /= No_Error_Msg
3583 -- Don't remove if location does not match
3585 and then Errors.Table (E).Optr.Ptr = Loc
3587 -- Don't remove if not warning/info message. Note that we do
3588 -- not remove style messages here. They are warning messages
3589 -- but not ones we want removed in this context.
3591 and then (Errors.Table (E).Warn
3592 or else
3593 Errors.Table (E).Warn_Runtime_Raise)
3595 -- Don't remove unconditional messages
3597 and then not Errors.Table (E).Uncond
3598 then
3599 if Errors.Table (E).Warn then
3600 Warnings_Detected := Warnings_Detected - 1;
3601 end if;
3603 if Errors.Table (E).Info then
3604 Warning_Info_Messages := Warning_Info_Messages - 1;
3605 end if;
3607 -- When warning about a runtime exception has been escalated
3608 -- into error, the starting message has increased the total
3609 -- errors counter, so here we decrease this counter.
3611 if Errors.Table (E).Warn_Runtime_Raise
3612 and then not Errors.Table (E).Msg_Cont
3613 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
3614 then
3615 Total_Errors_Detected := Total_Errors_Detected - 1;
3616 end if;
3618 return True;
3620 -- No removal required
3622 else
3623 return False;
3624 end if;
3625 end To_Be_Removed;
3627 -- Start of processing for Check_For_Warnings
3629 begin
3630 while To_Be_Removed (First_Error_Msg) loop
3631 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
3632 end loop;
3634 if First_Error_Msg = No_Error_Msg then
3635 Last_Error_Msg := No_Error_Msg;
3636 end if;
3638 E := First_Error_Msg;
3639 while E /= No_Error_Msg loop
3640 while To_Be_Removed (Errors.Table (E).Next) loop
3641 Errors.Table (E).Next :=
3642 Errors.Table (Errors.Table (E).Next).Next;
3644 if Errors.Table (E).Next = No_Error_Msg then
3645 Last_Error_Msg := E;
3646 end if;
3647 end loop;
3649 E := Errors.Table (E).Next;
3650 end loop;
3652 -- Warnings may have been posted on subexpressions of original tree
3654 if Nkind (N) = N_Raise_Constraint_Error
3655 and then Is_Rewrite_Substitution (N)
3656 and then No (Condition (N))
3657 then
3658 Check_All_Warnings (Original_Node (N));
3659 end if;
3661 return OK;
3662 end Check_For_Warning;
3664 -- Start of processing for Remove_Warning_Messages
3666 begin
3667 if Warnings_Detected /= 0 then
3668 Check_All_Warnings (N);
3669 end if;
3670 end Remove_Warning_Messages;
3672 procedure Remove_Warning_Messages (L : List_Id) is
3673 Stat : Node_Id;
3674 begin
3675 Stat := First (L);
3676 while Present (Stat) loop
3677 Remove_Warning_Messages (Stat);
3678 Next (Stat);
3679 end loop;
3680 end Remove_Warning_Messages;
3682 ----------------------
3683 -- Adjust_Name_Case --
3684 ----------------------
3686 procedure Adjust_Name_Case
3687 (Buf : in out Bounded_String;
3688 Loc : Source_Ptr)
3690 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
3691 Sbuffer : Source_Buffer_Ptr;
3692 Ref_Ptr : Integer;
3693 Src_Ptr : Source_Ptr;
3695 begin
3696 -- We have an all lower case name from Namet, and now we want to set
3697 -- the appropriate case. If possible we copy the actual casing from
3698 -- the source. If not we use standard identifier casing.
3700 Ref_Ptr := 1;
3701 Src_Ptr := Loc;
3703 -- For standard locations, always use mixed case
3705 if Loc <= No_Location then
3706 Set_Casing (Buf, Mixed_Case);
3708 else
3709 -- Determine if the reference we are dealing with corresponds to text
3710 -- at the point of the error reference. This will often be the case
3711 -- for simple identifier references, and is the case where we can
3712 -- copy the casing from the source.
3714 Sbuffer := Source_Text (Src_Ind);
3716 while Ref_Ptr <= Buf.Length loop
3717 exit when
3718 Fold_Lower (Sbuffer (Src_Ptr)) /=
3719 Fold_Lower (Buf.Chars (Ref_Ptr));
3720 Ref_Ptr := Ref_Ptr + 1;
3721 Src_Ptr := Src_Ptr + 1;
3722 end loop;
3724 -- If we get through the loop without a mismatch, then output the
3725 -- name the way it is cased in the source program.
3727 if Ref_Ptr > Buf.Length then
3728 Src_Ptr := Loc;
3730 for J in 1 .. Buf.Length loop
3731 Buf.Chars (J) := Sbuffer (Src_Ptr);
3732 Src_Ptr := Src_Ptr + 1;
3733 end loop;
3735 -- Otherwise set the casing using the default identifier casing
3737 else
3738 Set_Casing (Buf, Identifier_Casing (Src_Ind));
3739 end if;
3740 end if;
3741 end Adjust_Name_Case;
3743 ---------------------------
3744 -- Set_Identifier_Casing --
3745 ---------------------------
3747 procedure Set_Identifier_Casing
3748 (Identifier_Name : System.Address;
3749 File_Name : System.Address)
3751 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
3752 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
3753 Flen : Natural;
3755 Desired_Case : Casing_Type := Mixed_Case;
3756 -- Casing required for result. Default value of Mixed_Case is used if
3757 -- for some reason we cannot find the right file name in the table.
3759 begin
3760 -- Get length of file name
3762 Flen := 0;
3763 while File (Flen + 1) /= ASCII.NUL loop
3764 Flen := Flen + 1;
3765 end loop;
3767 -- Loop through file names to find matching one. This is a bit slow, but
3768 -- we only do it in error situations so it is not so terrible. Note that
3769 -- if the loop does not exit, then the desired case will be left set to
3770 -- Mixed_Case, this can happen if the name was not in canonical form.
3772 for J in 1 .. Last_Source_File loop
3773 Get_Name_String (Full_Debug_Name (J));
3775 if Name_Len = Flen
3776 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
3777 then
3778 Desired_Case := Identifier_Casing (J);
3779 exit;
3780 end if;
3781 end loop;
3783 -- Copy identifier as given to Name_Buffer
3785 for J in Name_Buffer'Range loop
3786 Name_Buffer (J) := Ident (J);
3788 if Name_Buffer (J) = ASCII.NUL then
3789 Name_Len := J - 1;
3790 exit;
3791 end if;
3792 end loop;
3794 Set_Casing (Desired_Case);
3795 end Set_Identifier_Casing;
3797 -----------------------
3798 -- Set_Ignore_Errors --
3799 -----------------------
3801 procedure Set_Ignore_Errors (To : Boolean) is
3802 begin
3803 Errors_Must_Be_Ignored := To;
3804 end Set_Ignore_Errors;
3806 ------------------------------
3807 -- Set_Msg_Insertion_Column --
3808 ------------------------------
3810 procedure Set_Msg_Insertion_Column is
3811 begin
3812 if RM_Column_Check then
3813 Set_Msg_Str (" in column ");
3814 Set_Msg_Int (Int (Error_Msg_Col) + 1);
3815 end if;
3816 end Set_Msg_Insertion_Column;
3818 ----------------------------
3819 -- Set_Msg_Insertion_Node --
3820 ----------------------------
3822 procedure Set_Msg_Insertion_Node is
3823 K : Node_Kind;
3825 begin
3826 Suppress_Message :=
3827 Error_Msg_Node_1 = Error
3828 or else Error_Msg_Node_1 = Any_Type;
3830 if Error_Msg_Node_1 = Empty then
3831 Set_Msg_Blank_Conditional;
3832 Set_Msg_Str ("<empty>");
3834 elsif Error_Msg_Node_1 = Error then
3835 Set_Msg_Blank;
3836 Set_Msg_Str ("<error>");
3838 elsif Error_Msg_Node_1 = Standard_Void_Type then
3839 Set_Msg_Blank;
3840 Set_Msg_Str ("procedure name");
3842 elsif Nkind (Error_Msg_Node_1) in N_Entity
3843 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
3844 then
3845 Set_Msg_Blank;
3846 Set_Msg_Str ("access to subprogram");
3848 else
3849 Set_Msg_Blank_Conditional;
3851 -- Output name
3853 K := Nkind (Error_Msg_Node_1);
3855 -- If we have operator case, skip quotes since name of operator
3856 -- itself will supply the required quotations. An operator can be an
3857 -- applied use in an expression or an explicit operator symbol, or an
3858 -- identifier whose name indicates it is an operator.
3860 if K in N_Op
3861 or else K = N_Operator_Symbol
3862 or else K = N_Defining_Operator_Symbol
3863 or else ((K = N_Identifier or else K = N_Defining_Identifier)
3864 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
3865 then
3866 Set_Msg_Node (Error_Msg_Node_1);
3868 -- Normal case, not an operator, surround with quotes
3870 else
3871 Set_Msg_Quote;
3872 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
3873 Set_Msg_Node (Error_Msg_Node_1);
3874 Set_Msg_Quote;
3875 end if;
3876 end if;
3878 -- The following assignment ensures that further ampersand insertion
3879 -- characters will correspond to the Error_Msg_Node_# parameter.
3881 Error_Msg_Node_1 := Error_Msg_Node_2;
3882 Error_Msg_Node_2 := Error_Msg_Node_3;
3883 Error_Msg_Node_3 := Error_Msg_Node_4;
3884 Error_Msg_Node_4 := Error_Msg_Node_5;
3885 Error_Msg_Node_5 := Error_Msg_Node_6;
3886 end Set_Msg_Insertion_Node;
3888 --------------------------------------
3889 -- Set_Msg_Insertion_Type_Reference --
3890 --------------------------------------
3892 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
3893 Ent : Entity_Id;
3895 begin
3896 Set_Msg_Blank;
3898 if Error_Msg_Node_1 = Standard_Void_Type then
3899 Set_Msg_Str ("package or procedure name");
3900 return;
3902 elsif Error_Msg_Node_1 = Standard_Exception_Type then
3903 Set_Msg_Str ("exception name");
3904 return;
3906 elsif Error_Msg_Node_1 = Any_Array
3907 or else Error_Msg_Node_1 = Any_Boolean
3908 or else Error_Msg_Node_1 = Any_Character
3909 or else Error_Msg_Node_1 = Any_Composite
3910 or else Error_Msg_Node_1 = Any_Discrete
3911 or else Error_Msg_Node_1 = Any_Fixed
3912 or else Error_Msg_Node_1 = Any_Integer
3913 or else Error_Msg_Node_1 = Any_Modular
3914 or else Error_Msg_Node_1 = Any_Numeric
3915 or else Error_Msg_Node_1 = Any_Real
3916 or else Error_Msg_Node_1 = Any_Scalar
3917 or else Error_Msg_Node_1 = Any_String
3918 then
3919 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
3920 Set_Msg_Name_Buffer;
3921 return;
3923 elsif Error_Msg_Node_1 = Universal_Integer then
3924 Set_Msg_Str ("type universal integer");
3925 return;
3927 elsif Error_Msg_Node_1 = Universal_Real then
3928 Set_Msg_Str ("type universal real");
3929 return;
3931 elsif Error_Msg_Node_1 = Universal_Fixed then
3932 Set_Msg_Str ("type universal fixed");
3933 return;
3935 elsif Error_Msg_Node_1 = Universal_Access then
3936 Set_Msg_Str ("type universal access");
3937 return;
3938 end if;
3940 -- Special case of anonymous array
3942 if Nkind (Error_Msg_Node_1) in N_Entity
3943 and then Is_Array_Type (Error_Msg_Node_1)
3944 and then Present (Related_Array_Object (Error_Msg_Node_1))
3945 then
3946 Set_Msg_Str ("type of ");
3947 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
3948 Set_Msg_Str (" declared");
3949 Set_Msg_Insertion_Line_Number
3950 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
3951 return;
3952 end if;
3954 -- If we fall through, it is not a special case, so first output
3955 -- the name of the type, preceded by private for a private type
3957 if Is_Private_Type (Error_Msg_Node_1) then
3958 Set_Msg_Str ("private type ");
3959 else
3960 Set_Msg_Str ("type ");
3961 end if;
3963 Ent := Error_Msg_Node_1;
3965 if Is_Internal_Name (Chars (Ent)) then
3966 Unwind_Internal_Type (Ent);
3967 end if;
3969 -- Types in Standard are displayed as "Standard.name"
3971 if Sloc (Ent) <= Standard_Location then
3972 Set_Msg_Quote;
3973 Set_Msg_Str ("Standard.");
3974 Set_Msg_Node (Ent);
3975 Add_Class;
3976 Set_Msg_Quote;
3978 -- Types in other language defined units are displayed as
3979 -- "package-name.type-name"
3981 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
3982 Get_Unqualified_Decoded_Name_String
3983 (Unit_Name (Get_Source_Unit (Ent)));
3984 Name_Len := Name_Len - 2;
3985 Set_Msg_Blank_Conditional;
3986 Set_Msg_Quote;
3987 Set_Casing (Mixed_Case);
3988 Set_Msg_Name_Buffer;
3989 Set_Msg_Char ('.');
3990 Set_Casing (Mixed_Case);
3991 Set_Msg_Node (Ent);
3992 Add_Class;
3993 Set_Msg_Quote;
3995 -- All other types display as "type name" defined at line xxx
3996 -- possibly qualified if qualification is requested.
3998 else
3999 Set_Msg_Quote;
4000 Set_Qualification (Error_Msg_Qual_Level, Ent);
4001 Set_Msg_Node (Ent);
4002 Add_Class;
4004 -- If we did not print a name (e.g. in the case of an anonymous
4005 -- subprogram type), there is no name to print, so remove quotes.
4007 if Buffer_Ends_With ('"') then
4008 Buffer_Remove ('"');
4009 else
4010 Set_Msg_Quote;
4011 end if;
4012 end if;
4014 -- If the original type did not come from a predefined file, add the
4015 -- location where the type was defined.
4017 if Sloc (Error_Msg_Node_1) > Standard_Location
4018 and then
4019 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
4020 then
4021 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
4022 Set_Msg_Str (" defined");
4023 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
4025 -- If it did come from a predefined file, deal with the case where
4026 -- this was a file with a generic instantiation from elsewhere.
4028 else
4029 if Sloc (Error_Msg_Node_1) > Standard_Location then
4030 declare
4031 Iloc : constant Source_Ptr :=
4032 Instantiation_Location (Sloc (Error_Msg_Node_1));
4034 begin
4035 if Iloc /= No_Location
4036 and then not Suppress_Instance_Location
4037 then
4038 Set_Msg_Str (" from instance");
4039 Set_Msg_Insertion_Line_Number (Iloc, Flag);
4040 end if;
4041 end;
4042 end if;
4043 end if;
4044 end Set_Msg_Insertion_Type_Reference;
4046 ---------------------------------
4047 -- Set_Msg_Insertion_Unit_Name --
4048 ---------------------------------
4050 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
4051 begin
4052 if Error_Msg_Unit_1 = No_Unit_Name then
4053 null;
4055 elsif Error_Msg_Unit_1 = Error_Unit_Name then
4056 Set_Msg_Blank;
4057 Set_Msg_Str ("<error>");
4059 else
4060 Get_Unit_Name_String (Global_Name_Buffer, Error_Msg_Unit_1, Suffix);
4061 Set_Msg_Blank;
4062 Set_Msg_Quote;
4063 Set_Msg_Name_Buffer;
4064 Set_Msg_Quote;
4065 end if;
4067 -- The following assignment ensures that a second percent insertion
4068 -- character will correspond to the Error_Msg_Unit_2 parameter.
4070 Error_Msg_Unit_1 := Error_Msg_Unit_2;
4071 end Set_Msg_Insertion_Unit_Name;
4073 ------------------
4074 -- Set_Msg_Node --
4075 ------------------
4077 procedure Set_Msg_Node (Node : Node_Id) is
4078 Loc : Source_Ptr;
4079 Ent : Entity_Id;
4080 Nam : Name_Id;
4082 begin
4083 case Nkind (Node) is
4084 when N_Designator =>
4085 Set_Msg_Node (Name (Node));
4086 Set_Msg_Char ('.');
4087 Set_Msg_Node (Identifier (Node));
4088 return;
4090 when N_Defining_Program_Unit_Name =>
4091 Set_Msg_Node (Name (Node));
4092 Set_Msg_Char ('.');
4093 Set_Msg_Node (Defining_Identifier (Node));
4094 return;
4096 when N_Expanded_Name
4097 | N_Selected_Component
4099 Set_Msg_Node (Prefix (Node));
4100 Set_Msg_Char ('.');
4101 Set_Msg_Node (Selector_Name (Node));
4102 return;
4104 when others =>
4105 null;
4106 end case;
4108 -- The only remaining possibilities are identifiers, defining
4109 -- identifiers, pragmas, and pragma argument associations.
4111 if Nkind (Node) = N_Pragma then
4112 Nam := Pragma_Name (Node);
4113 Loc := Sloc (Node);
4115 -- The other cases have Chars fields
4117 -- First deal with internal names, which generally represent something
4118 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4119 -- something with a Chars field that is not an internal name, use that.
4121 elsif Is_Internal_Name (Chars (Node))
4122 and then Nkind (Original_Node (Node)) in N_Has_Chars
4123 and then not Is_Internal_Name (Chars (Original_Node (Node)))
4124 then
4125 Nam := Chars (Original_Node (Node));
4126 Loc := Sloc (Original_Node (Node));
4128 -- Another shot for internal names, in the case of internal type names,
4129 -- we try to find a reasonable representation for the external name.
4131 elsif Is_Internal_Name (Chars (Node))
4132 and then
4133 ((Is_Entity_Name (Node)
4134 and then Present (Entity (Node))
4135 and then Is_Type (Entity (Node)))
4136 or else
4137 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
4138 then
4139 if Nkind (Node) = N_Identifier then
4140 Ent := Entity (Node);
4141 else
4142 Ent := Node;
4143 end if;
4145 Loc := Sloc (Ent);
4147 -- If the type is the designated type of an access_to_subprogram,
4148 -- then there is no name to provide in the call.
4150 if Ekind (Ent) = E_Subprogram_Type then
4151 return;
4153 -- Otherwise, we will be able to find some kind of name to output
4155 else
4156 Unwind_Internal_Type (Ent);
4157 Nam := Chars (Ent);
4158 end if;
4160 -- If not internal name, or if we could not find a reasonable possible
4161 -- substitution for the internal name, just use name in Chars field.
4163 else
4164 Nam := Chars (Node);
4165 Loc := Sloc (Node);
4166 end if;
4168 -- At this stage, the name to output is in Nam
4170 Get_Unqualified_Decoded_Name_String (Nam);
4172 -- Remove trailing upper case letters from the name (useful for
4173 -- dealing with some cases of internal names).
4175 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
4176 Name_Len := Name_Len - 1;
4177 end loop;
4179 -- If we have any of the names from standard that start with the
4180 -- characters "any " (e.g. Any_Type), then kill the message since
4181 -- almost certainly it is a junk cascaded message.
4183 if Name_Len > 4
4184 and then Name_Buffer (1 .. 4) = "any "
4185 then
4186 Kill_Message := True;
4187 end if;
4189 -- If we still have an internal name, kill the message (will only
4190 -- work if we already had errors!)
4192 if Is_Internal_Name then
4193 Kill_Message := True;
4194 end if;
4195 -- Remaining step is to adjust casing and possibly add 'Class
4197 Adjust_Name_Case (Global_Name_Buffer, Loc);
4198 Set_Msg_Name_Buffer;
4199 Add_Class;
4200 end Set_Msg_Node;
4202 ------------------
4203 -- Set_Msg_Text --
4204 ------------------
4206 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
4207 C : Character; -- Current character
4208 P : Natural; -- Current index;
4210 procedure Skip_Msg_Insertion_Warning (C : Character);
4211 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4212 -- sequences using < instead of ?). The caller has already bumped
4213 -- the pointer past the initial ? or < and C is set to this initial
4214 -- character (? or <). This procedure skips past the rest of the
4215 -- sequence. We do not need to set Msg_Insertion_Char, since this
4216 -- was already done during the message prescan.
4217 -- No validity check is performed as the insertion sequence is
4218 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4219 -- erroutc.adb for the validity checks.
4221 --------------------------------
4222 -- Skip_Msg_Insertion_Warning --
4223 --------------------------------
4225 procedure Skip_Msg_Insertion_Warning (C : Character) is
4226 begin
4227 if P <= Text'Last and then Text (P) = C then
4228 P := P + 1;
4230 elsif P < Text'Last and then Text (P + 1) = C
4231 and then Text (P) in 'a' .. 'z' | 'A' .. 'Z' |
4232 '0' .. '9' | '*' | '$'
4233 then
4234 P := P + 2;
4236 elsif P + 1 < Text'Last and then Text (P + 2) = C
4237 and then Text (P) in '.' | '_'
4238 and then Text (P + 1) in 'a' .. 'z'
4239 then
4240 P := P + 3;
4241 end if;
4242 end Skip_Msg_Insertion_Warning;
4244 -- Start of processing for Set_Msg_Text
4246 begin
4247 Manual_Quote_Mode := False;
4248 Msglen := 0;
4249 Flag_Source := Get_Source_File_Index (Flag);
4251 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4252 -- will be used (Info field in error message object) to put back the
4253 -- string when it is printed. We need to do this, or we get confused
4254 -- with instantiation continuations.
4256 if Text'Length > 6
4257 and then Text (Text'First .. Text'First + 5) = "info: "
4258 then
4259 P := Text'First + 6;
4260 else
4261 P := Text'First;
4262 end if;
4264 -- Loop through characters of message
4266 while P <= Text'Last loop
4267 C := Text (P);
4268 P := P + 1;
4270 -- Check for insertion character or sequence
4272 case C is
4273 when '%' =>
4274 if P <= Text'Last and then Text (P) = '%' then
4275 P := P + 1;
4276 Set_Msg_Insertion_Name_Literal;
4277 else
4278 Set_Msg_Insertion_Name;
4279 end if;
4281 when '$' =>
4282 if P <= Text'Last and then Text (P) = '$' then
4283 P := P + 1;
4284 Set_Msg_Insertion_Unit_Name (Suffix => False);
4285 else
4286 Set_Msg_Insertion_Unit_Name;
4287 end if;
4289 when '{' =>
4290 Set_Msg_Insertion_File_Name;
4292 when '}' =>
4293 Set_Msg_Insertion_Type_Reference (Flag);
4295 when '*' =>
4296 Set_Msg_Insertion_Reserved_Name;
4298 when '&' =>
4299 Set_Msg_Insertion_Node;
4301 when '#' =>
4302 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
4304 when '\' =>
4305 Continuation := True;
4307 if P <= Text'Last and then Text (P) = '\' then
4308 Continuation_New_Line := True;
4309 P := P + 1;
4310 end if;
4312 when '@' =>
4313 Set_Msg_Insertion_Column;
4315 when '>' =>
4316 Set_Msg_Insertion_Run_Time_Name;
4318 when '^' =>
4319 Set_Msg_Insertion_Uint;
4321 when '`' =>
4322 Manual_Quote_Mode := not Manual_Quote_Mode;
4323 Set_Msg_Char ('"');
4325 when '!' =>
4326 null; -- already dealt with
4328 when '?' =>
4329 Skip_Msg_Insertion_Warning ('?');
4331 when '<' =>
4332 Skip_Msg_Insertion_Warning ('<');
4334 when '|' =>
4335 null; -- already dealt with
4337 when ''' =>
4338 Set_Msg_Char (Text (P));
4339 P := P + 1;
4341 when '~' =>
4342 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
4344 -- Upper case letter
4346 when 'A' .. 'Z' =>
4348 -- Start of reserved word if two or more
4350 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
4351 P := P - 1;
4352 Set_Msg_Insertion_Reserved_Word (Text, P);
4354 -- Single upper case letter is just inserted
4356 else
4357 Set_Msg_Char (C);
4358 end if;
4360 -- '[' (will be/would have been raised at run time)
4362 when '[' =>
4364 -- "[]" (insertion of error code)
4366 if P <= Text'Last and then Text (P) = ']' then
4367 P := P + 1;
4368 Set_Msg_Insertion_Code;
4370 else
4371 -- Switch the message from a warning to an error if the flag
4372 -- -gnatwE is specified to treat run-time exception warnings
4373 -- as errors.
4375 if Is_Warning_Msg
4376 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
4377 then
4378 Is_Warning_Msg := False;
4379 Is_Runtime_Raise := True;
4380 end if;
4382 if Is_Warning_Msg then
4383 Set_Msg_Str ("will be raised at run time");
4384 else
4385 Set_Msg_Str ("would have been raised at run time");
4386 end if;
4387 end if;
4389 -- ']' (may be/might have been raised at run time)
4391 when ']' =>
4392 if Is_Warning_Msg then
4393 Set_Msg_Str ("may be raised at run time");
4394 else
4395 Set_Msg_Str ("might have been raised at run time");
4396 end if;
4398 -- Normal character with no special treatment
4400 when others =>
4401 Set_Msg_Char (C);
4402 end case;
4403 end loop;
4404 end Set_Msg_Text;
4406 ----------------
4407 -- Set_Posted --
4408 ----------------
4410 procedure Set_Posted (N : Node_Id) is
4411 P : Node_Id;
4413 begin
4414 if Is_Serious_Error then
4416 -- We always set Error_Posted on the node itself
4418 Set_Error_Posted (N);
4420 -- If it is a subexpression, then set Error_Posted on parents up to
4421 -- and including the first non-subexpression construct. This helps
4422 -- avoid cascaded error messages within a single expression.
4424 P := N;
4425 loop
4426 P := Parent (P);
4427 exit when No (P);
4428 Set_Error_Posted (P);
4429 exit when Nkind (P) not in N_Subexpr;
4430 end loop;
4432 if Nkind (P) in N_Pragma_Argument_Association
4433 | N_Component_Association
4434 | N_Discriminant_Association
4435 | N_Generic_Association
4436 | N_Parameter_Association
4437 then
4438 Set_Error_Posted (Parent (P));
4439 end if;
4441 -- A special check, if we just posted an error on an attribute
4442 -- definition clause, then also set the entity involved as posted.
4443 -- For example, this stops complaining about the alignment after
4444 -- complaining about the size, which is likely to be useless.
4446 if Nkind (P) = N_Attribute_Definition_Clause then
4447 if Is_Entity_Name (Name (P)) then
4448 Set_Error_Posted (Entity (Name (P)));
4449 end if;
4450 end if;
4451 end if;
4452 end Set_Posted;
4454 -----------------------
4455 -- Set_Qualification --
4456 -----------------------
4458 procedure Set_Qualification (N : Nat; E : Entity_Id) is
4459 begin
4460 if N /= 0 and then Scope (E) /= Standard_Standard then
4461 Set_Qualification (N - 1, Scope (E));
4462 Set_Msg_Node (Scope (E));
4463 Set_Msg_Char ('.');
4464 end if;
4465 end Set_Qualification;
4467 -------------------------------------
4468 -- Should_Ignore_Pragma_SPARK_Mode --
4469 -------------------------------------
4471 function Should_Ignore_Pragma_SPARK_Mode return Boolean is
4472 begin
4473 return Get_Name_Table_Boolean3 (Name_SPARK_Mode);
4474 end Should_Ignore_Pragma_SPARK_Mode;
4476 ------------------------
4477 -- Special_Msg_Delete --
4478 ------------------------
4480 -- Is it really right to have all this specialized knowledge in errout?
4482 function Special_Msg_Delete
4483 (Msg : String;
4484 N : Node_Or_Entity_Id;
4485 E : Node_Or_Entity_Id) return Boolean
4487 begin
4488 -- Never delete messages in -gnatdO mode
4490 if Debug_Flag_OO then
4491 return False;
4493 -- Processing for "Size too small" messages
4495 elsif Is_Size_Too_Small_Message (Msg) then
4497 -- Suppress "size too small" errors in CodePeer mode, since code may
4498 -- be analyzed in a different configuration than the one used for
4499 -- compilation. Even when the configurations match, this message
4500 -- may be issued on correct code, because pragma Pack is ignored
4501 -- in CodePeer mode.
4503 if CodePeer_Mode then
4504 return True;
4506 -- When a size is wrong for a frozen type there is no explicit size
4507 -- clause, and other errors have occurred, suppress the message,
4508 -- since it is likely that this size error is a cascaded result of
4509 -- other errors. The reason we eliminate unfrozen types is that
4510 -- messages issued before the freeze type are for sure OK.
4512 elsif Nkind (N) in N_Entity
4513 and then Is_Frozen (E)
4514 and then Serious_Errors_Detected > 0
4515 and then Nkind (N) /= N_Component_Clause
4516 and then Nkind (Parent (N)) /= N_Component_Clause
4517 and then
4518 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
4519 and then
4520 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
4521 and then
4522 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
4523 then
4524 return True;
4525 end if;
4526 end if;
4528 -- All special tests complete, so go ahead with message
4530 return False;
4531 end Special_Msg_Delete;
4533 -----------------
4534 -- SPARK_Msg_N --
4535 -----------------
4537 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
4538 begin
4539 -- If SPARK_Mode is Off, we do not report SPARK legality errors to give
4540 -- the flexibility to opt out of SPARK checking completely. We do the
4541 -- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
4542 -- for tools to ignore SPARK checking even on SPARK code.
4544 if SPARK_Mode /= Off
4545 and then not Should_Ignore_Pragma_SPARK_Mode
4546 then
4547 Error_Msg_N (Msg, N);
4548 end if;
4549 end SPARK_Msg_N;
4551 ------------------
4552 -- SPARK_Msg_NE --
4553 ------------------
4555 procedure SPARK_Msg_NE
4556 (Msg : String;
4557 N : Node_Or_Entity_Id;
4558 E : Node_Or_Entity_Id)
4560 begin
4561 if SPARK_Mode /= Off
4562 and then not Should_Ignore_Pragma_SPARK_Mode
4563 then
4564 Error_Msg_NE (Msg, N, E);
4565 end if;
4566 end SPARK_Msg_NE;
4568 --------------------------
4569 -- Unwind_Internal_Type --
4570 --------------------------
4572 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
4573 Derived : Boolean := False;
4574 Mchar : Character;
4575 Old_Ent : Entity_Id;
4577 begin
4578 -- Undo placement of a quote, since we will put it back later
4580 Mchar := Msg_Buffer (Msglen);
4582 if Mchar = '"' then
4583 Msglen := Msglen - 1;
4584 end if;
4586 -- The loop here deals with recursive types, we are trying to find a
4587 -- related entity that is not an implicit type. Note that the check with
4588 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4589 -- "type derived from" message more than once in the case where we climb
4590 -- up multiple levels.
4592 Find : loop
4593 Old_Ent := Ent;
4595 -- Implicit access type, use directly designated type In Ada 2005,
4596 -- the designated type may be an anonymous access to subprogram, in
4597 -- which case we can only point to its definition.
4599 if Is_Access_Type (Ent) then
4600 if Ekind (Ent) = E_Access_Subprogram_Type
4601 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
4602 or else Is_Access_Protected_Subprogram_Type (Ent)
4603 then
4604 Ent := Directly_Designated_Type (Ent);
4606 if not Comes_From_Source (Ent) then
4607 if Buffer_Ends_With ("type ") then
4608 Buffer_Remove ("type ");
4609 end if;
4610 end if;
4612 if Ekind (Ent) = E_Function then
4613 Set_Msg_Str ("access to function ");
4614 elsif Ekind (Ent) = E_Procedure then
4615 Set_Msg_Str ("access to procedure ");
4616 else
4617 Set_Msg_Str ("access to subprogram");
4618 end if;
4620 exit Find;
4622 -- Type is access to object, named or anonymous
4624 else
4625 Set_Msg_Str ("access to ");
4626 Ent := Directly_Designated_Type (Ent);
4627 end if;
4629 -- Classwide type
4631 elsif Is_Class_Wide_Type (Ent) then
4632 Class_Flag := True;
4633 Ent := Root_Type (Ent);
4635 -- Use base type if this is a subtype
4637 elsif Ent /= Base_Type (Ent) then
4638 Buffer_Remove ("type ");
4640 -- Avoid duplication "subtype of subtype of", and also replace
4641 -- "derived from subtype of" simply by "derived from"
4643 if not Buffer_Ends_With ("subtype of ")
4644 and then not Buffer_Ends_With ("derived from ")
4645 then
4646 Set_Msg_Str ("subtype of ");
4647 end if;
4649 Ent := Base_Type (Ent);
4651 -- If this is a base type with a first named subtype, use the first
4652 -- named subtype instead. This is not quite accurate in all cases,
4653 -- but it makes too much noise to be accurate and add 'Base in all
4654 -- cases. Note that we only do this is the first named subtype is not
4655 -- itself an internal name. This avoids the obvious loop (subtype ->
4656 -- basetype -> subtype) which would otherwise occur).
4658 else
4659 declare
4660 FST : constant Entity_Id := First_Subtype (Ent);
4662 begin
4663 if not Is_Internal_Name (Chars (FST)) then
4664 Ent := FST;
4665 exit Find;
4667 -- Otherwise use root type
4669 else
4670 if not Derived then
4671 Buffer_Remove ("type ");
4673 -- Test for "subtype of type derived from" which seems
4674 -- excessive and is replaced by "type derived from".
4676 Buffer_Remove ("subtype of");
4678 -- Avoid duplicated "type derived from type derived from"
4680 if not Buffer_Ends_With ("type derived from ") then
4681 Set_Msg_Str ("type derived from ");
4682 end if;
4684 Derived := True;
4685 end if;
4686 end if;
4687 end;
4689 Ent := Etype (Ent);
4690 end if;
4692 -- If we are stuck in a loop, get out and settle for the internal
4693 -- name after all. In this case we set to kill the message if it is
4694 -- not the first error message (we really try hard not to show the
4695 -- dirty laundry of the implementation to the poor user).
4697 if Ent = Old_Ent then
4698 Kill_Message := True;
4699 exit Find;
4700 end if;
4702 -- Get out if we finally found a non-internal name to use
4704 exit Find when not Is_Internal_Name (Chars (Ent));
4705 end loop Find;
4707 if Mchar = '"' then
4708 Set_Msg_Char ('"');
4709 end if;
4710 end Unwind_Internal_Type;
4712 --------------------
4713 -- Warn_Insertion --
4714 --------------------
4716 function Warn_Insertion return String is
4717 begin
4718 if Warning_Msg_Char = "? " then
4719 return "??";
4720 elsif Warning_Msg_Char = " " then
4721 return "?";
4722 elsif Warning_Msg_Char (2) = ' ' then
4723 return '?' & Warning_Msg_Char (1) & '?';
4724 else
4725 return '?' & Warning_Msg_Char & '?';
4726 end if;
4727 end Warn_Insertion;
4729 end Errout;