testsuite: Add dg-require-effective-target scheduling for some tests that set -fsched...
[official-gcc.git] / gcc / ada / errout.adb
blobc8d87f0f9bb04adc4238e5a6366f79e9065f13ee
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 -- This is the low-level routine used to post messages after dealing with
105 -- the issue of messages placed on instantiations (which get broken up
106 -- into separate calls in Error_Msg). Span is the location on which the
107 -- flag will be placed in the output. In the case where the flag is on
108 -- the template, this points directly to the template, not to one of the
109 -- instantiation copies of the template. Opan is the original location
110 -- used to flag the error, and this may indeed point to an instantiation
111 -- copy. So typically we can see Opan pointing to the template location
112 -- in an instantiation copy when Span points to the source location of
113 -- the actual instantiation (i.e the line with the new). Msg_Cont is
114 -- set true if this is a continuation message.
116 function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
117 -- Determines if warnings should be suppressed for the given node
119 function OK_Node (N : Node_Id) return Boolean;
120 -- Determines if a node is an OK node to place an error message on (return
121 -- True) or if the error message should be suppressed (return False). A
122 -- message is suppressed if the node already has an error posted on it,
123 -- or if it refers to an Etype that has an error posted on it, or if
124 -- it references an Entity that has an error posted on it.
126 procedure Output_JSON_Message (Error_Id : Error_Msg_Id);
127 -- Output error message Error_Id and any subsequent continuation message
128 -- using a JSON format similar to the one GCC uses when passed
129 -- -fdiagnostics-format=json.
131 procedure Output_Source_Line
132 (L : Physical_Line_Number;
133 Sfile : Source_File_Index;
134 Errs : Boolean);
135 -- Outputs text of source line L, in file S, together with preceding line
136 -- number, as described above for Output_Line_Number. The Errs parameter
137 -- indicates if there are errors attached to the line, which forces
138 -- listing on, even in the presence of pragma List (Off).
140 function Paren_Required (N : Node_Id) return Boolean;
141 -- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
142 -- around node N are required by the Ada syntax, e.g. when N is an
143 -- expression of a qualified expression.
145 procedure Set_Msg_Insertion_Column;
146 -- Handle column number insertion (@ insertion character)
148 procedure Set_Msg_Insertion_Node;
149 -- Handle node (name from node) insertion (& insertion character)
151 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
152 -- Handle type reference (right brace insertion character). Flag is the
153 -- location of the flag, which is provided for the internal call to
154 -- Set_Msg_Insertion_Line_Number,
156 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True);
157 -- Handle unit name insertion ($ insertion character). Depending on Boolean
158 -- parameter Suffix, (spec) or (body) is appended after the unit name.
160 procedure Set_Msg_Node (Node : Node_Id);
161 -- Add the sequence of characters for the name associated with the given
162 -- node to the current message. For N_Designator, N_Selected_Component,
163 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
164 -- included as well.
166 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
167 -- Add a sequence of characters to the current message. The characters may
168 -- be one of the special insertion characters (see documentation in spec).
169 -- Flag is the location at which the error is to be posted, which is used
170 -- to determine whether or not the # insertion needs a file name. The
171 -- variables Msg_Buffer are set on return Msglen.
173 procedure Set_Posted (N : Node_Id);
174 -- Sets the Error_Posted flag on the given node, and all its parents that
175 -- are subexpressions and then on the parent non-subexpression construct
176 -- that contains the original expression. If that parent is a named
177 -- association, the flag is further propagated to its parent. This is done
178 -- in order to guard against cascaded errors. Note that this call has an
179 -- effect for a serious error only.
181 procedure Set_Qualification (N : Nat; E : Entity_Id);
182 -- Outputs up to N levels of qualification for the given entity. For
183 -- example, the entity A.B.C.D will output B.C. if N = 2.
185 function Should_Ignore_Pragma_SPARK_Mode return Boolean;
186 -- Return whether pragma Ignore_Pragma (SPARK_Mode) was specified. This is
187 -- similar to Sem_Util.Should_Ignore_Pragma_Par but located here to avoid
188 -- problematic dependency on Sem_Util.
190 function Special_Msg_Delete
191 (Msg : String;
192 N : Node_Or_Entity_Id;
193 E : Node_Or_Entity_Id) return Boolean;
194 -- This function is called from Error_Msg_NEL, passing the message Msg,
195 -- node N on which the error is to be posted, and the entity or node E
196 -- to be used for an & insertion in the message if any. The job of this
197 -- procedure is to test for certain cascaded messages that we would like
198 -- to suppress. If the message is to be suppressed then we return True.
199 -- If the message should be generated (the normal case) False is returned.
201 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
202 -- This procedure is given an entity id for an internal type, i.e. a type
203 -- with an internal name. It unwinds the type to try to get to something
204 -- reasonably printable, generating prefixes like "subtype of", "access
205 -- to", etc along the way in the buffer. The value in Ent on return is the
206 -- final name to be printed. Hopefully this is not an internal name, but in
207 -- some internal name cases, it is an internal name, and has to be printed
208 -- anyway (although in this case the message has been killed if possible).
209 -- The global variable Class_Flag is set to True if the resulting entity
210 -- should have 'Class appended to its name (see Add_Class procedure), and
211 -- is otherwise unchanged.
213 procedure Validate_Specific_Warnings;
214 -- Checks that specific warnings are consistent (for non-configuration
215 -- case, properly closed, and used).
217 function Warn_Insertion return String;
218 -- This is called for warning messages only (so Warning_Msg_Char is set)
219 -- and returns a corresponding string to use at the beginning of generated
220 -- auxiliary messages, such as "in instantiation at ...".
221 -- "?" returns "??"
222 -- " " returns "?"
223 -- other trimmed, prefixed and suffixed with "?".
225 -----------------------
226 -- Change_Error_Text --
227 -----------------------
229 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
230 Save_Next : Error_Msg_Id;
231 Err_Id : Error_Msg_Id := Error_Id;
233 begin
234 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr.Ptr);
235 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
237 -- If in immediate error message mode, output modified error message now
238 -- This is just a bit tricky, because we want to output just a single
239 -- message, and the messages we modified is already linked in. We solve
240 -- this by temporarily resetting its forward pointer to empty.
242 if Debug_Flag_OO then
243 Save_Next := Errors.Table (Error_Id).Next;
244 Errors.Table (Error_Id).Next := No_Error_Msg;
245 Write_Eol;
246 Output_Source_Line
247 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
248 Output_Error_Msgs (Err_Id);
249 Errors.Table (Error_Id).Next := Save_Next;
250 end if;
251 end Change_Error_Text;
253 ------------------------
254 -- Compilation_Errors --
255 ------------------------
257 function Compilation_Errors return Boolean is
258 begin
259 if not Finalize_Called then
260 raise Program_Error;
261 else
262 return Erroutc.Compilation_Errors;
263 end if;
264 end Compilation_Errors;
266 --------------------------------------
267 -- Delete_Warning_And_Continuations --
268 --------------------------------------
270 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
271 Id : Error_Msg_Id;
273 begin
274 pragma Assert (not Errors.Table (Msg).Msg_Cont);
276 Id := Msg;
277 loop
278 declare
279 M : Error_Msg_Object renames Errors.Table (Id);
281 begin
282 if not M.Deleted then
283 M.Deleted := True;
284 Warnings_Detected := Warnings_Detected - 1;
286 if M.Warn_Err then
287 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
288 end if;
289 end if;
291 Id := M.Next;
292 exit when Id = No_Error_Msg;
293 exit when not Errors.Table (Id).Msg_Cont;
294 end;
295 end loop;
296 end Delete_Warning_And_Continuations;
298 ---------------
299 -- Error_Msg --
300 ---------------
302 -- Error_Msg posts a flag at the given location, except that if the
303 -- Flag_Location/Flag_Span points within a generic template and corresponds
304 -- to an instantiation of this generic template, then the actual message
305 -- will be posted on the generic instantiation, along with additional
306 -- messages referencing the generic declaration.
308 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
309 begin
310 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
311 end Error_Msg;
313 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
314 begin
315 Error_Msg (Msg, Flag_Span, Current_Node);
316 end Error_Msg;
318 procedure Error_Msg
319 (Msg : String;
320 Flag_Location : Source_Ptr;
321 N : Node_Id;
322 Is_Compile_Time_Pragma : Boolean)
324 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
325 begin
326 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
327 Error_Msg (Msg, To_Span (Flag_Location), N);
328 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
329 end Error_Msg;
331 procedure Error_Msg
332 (Msg : String;
333 Flag_Location : Source_Ptr;
334 N : Node_Id)
336 begin
337 Error_Msg (Msg, To_Span (Flag_Location), N);
338 end Error_Msg;
340 procedure Error_Msg
341 (Msg : String;
342 Flag_Span : Source_Span;
343 N : Node_Id)
345 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
347 Sindex : Source_File_Index;
348 -- Source index for flag location
350 Orig_Loc : Source_Ptr;
351 -- Original location of Flag_Location (i.e. location in original
352 -- template in instantiation case, otherwise unchanged).
354 begin
355 -- Return if all errors are to be ignored
357 if Get_Ignore_Errors then
358 return;
359 end if;
361 -- If we already have messages, and we are trying to place a message at
362 -- No_Location, then just ignore the attempt since we assume that what
363 -- is happening is some cascaded junk. Note that this is safe in the
364 -- sense that proceeding will surely bomb. We will also bomb if the flag
365 -- location is No_Location and we don't have any messages so far, but
366 -- that is a real bug and a legitimate bomb, so we go ahead.
368 if Flag_Location = No_Location
369 and then Total_Errors_Detected > 0
370 then
371 return;
372 end if;
374 -- Start of processing for new message
376 Sindex := Get_Source_File_Index (Flag_Location);
377 Prescan_Message (Msg);
378 Orig_Loc := Original_Location (Flag_Location);
380 -- If the current location is in an instantiation, the issue arises of
381 -- whether to post the message on the template or the instantiation.
383 -- The way we decide is to see if we have posted the same message on
384 -- the template when we compiled the template (the template is always
385 -- compiled before any instantiations). For this purpose, we use a
386 -- separate table of messages. The reason we do this is twofold:
388 -- First, the messages can get changed by various processing
389 -- including the insertion of tokens etc, making it hard to
390 -- do the comparison.
392 -- Second, we will suppress a warning on a template if it is not in
393 -- the current extended source unit. That's reasonable and means we
394 -- don't want the warning on the instantiation here either, but it
395 -- does mean that the main error table would not in any case include
396 -- the message.
398 if Flag_Location = Orig_Loc then
399 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
400 Warn_On_Instance := False;
402 -- Here we have an instance message
404 else
405 -- Delete if debug flag off, and this message duplicates a message
406 -- already posted on the corresponding template
408 if not Debug_Flag_GG then
409 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
410 if Msg = Non_Instance_Msgs.Table (J).Msg.all
411 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
412 then
413 return;
414 end if;
415 end loop;
416 end if;
418 -- No duplicate, so error/warning will be posted on instance
420 Warn_On_Instance := Is_Warning_Msg;
421 end if;
423 -- Ignore warning message that is suppressed for this location. Note
424 -- that style checks are not considered warning messages for this
425 -- purpose.
427 if Is_Warning_Msg
428 and then Warnings_Suppressed (Orig_Loc) /= No_String
429 then
430 return;
432 -- For style messages, check too many messages so far
434 elsif Is_Style_Msg
435 and then Maximum_Messages /= 0
436 and then Warnings_Detected >= Maximum_Messages
437 then
438 return;
440 -- Suppress warnings inside a loop that is known to be null or is
441 -- probably null (i.e. when loop executes only if invalid values
442 -- present). In either case warnings in the loop are likely to be junk.
444 elsif Is_Warning_Msg and then Present (N) then
446 declare
447 P : Node_Id;
449 begin
450 P := Parent (N);
451 while Present (P) loop
452 if Nkind (P) = N_Loop_Statement
453 and then Suppress_Loop_Warnings (P)
454 then
455 return;
456 end if;
458 P := Parent (P);
459 end loop;
460 end;
461 end if;
463 -- The idea at this stage is that we have two kinds of messages
465 -- First, we have those messages that are to be placed as requested at
466 -- Flag_Location. This includes messages that have nothing to do with
467 -- generics, and also messages placed on generic templates that reflect
468 -- an error in the template itself. For such messages we simply call
469 -- Error_Msg_Internal to place the message in the requested location.
471 if Instantiation (Sindex) = No_Location then
472 Error_Msg_Internal (Msg, Flag_Span, Flag_Span, False);
473 return;
474 end if;
476 -- If we are trying to flag an error in an instantiation, we may have
477 -- a generic contract violation. What we generate in this case is:
479 -- instantiation error at ...
480 -- original error message
482 -- or
484 -- warning: in instantiation at ...
485 -- warning: original warning message
487 -- or
489 -- info: in instantiation at ...
490 -- info: original info message
492 -- All these messages are posted at the location of the top level
493 -- instantiation. If there are nested instantiations, then the
494 -- instantiation error message can be repeated, pointing to each
495 -- of the relevant instantiations.
497 -- Note: the instantiation mechanism is also shared for inlining of
498 -- subprogram bodies when front end inlining is done. In this case the
499 -- messages have the form:
501 -- in inlined body at ...
502 -- original error message
504 -- or
506 -- warning: in inlined body at ...
507 -- warning: original warning message
509 -- or
511 -- info: in inlined body at ...
512 -- info: original info message
514 -- OK, here we have an instantiation error, and we need to generate the
515 -- error on the instantiation, rather than on the template.
517 declare
518 Actual_Error_Loc : Source_Ptr;
519 -- Location of outer level instantiation in instantiation case, or
520 -- just a copy of Flag_Location in the normal case. This is the
521 -- location where all error messages will actually be posted.
523 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
524 -- Save possible location set for caller's message. We need to use
525 -- Error_Msg_Sloc for the location of the instantiation error but we
526 -- have to preserve a possible original value.
528 X : Source_File_Index;
530 Msg_Cont_Status : Boolean;
531 -- Used to label continuation lines in instantiation case with
532 -- proper Msg_Cont status.
534 begin
535 -- Loop to find highest level instantiation, where all error
536 -- messages will be placed.
538 X := Sindex;
539 loop
540 Actual_Error_Loc := Instantiation (X);
541 X := Get_Source_File_Index (Actual_Error_Loc);
542 exit when Instantiation (X) = No_Location;
543 end loop;
545 -- Since we are generating the messages at the instantiation point in
546 -- any case, we do not want the references to the bad lines in the
547 -- instance to be annotated with the location of the instantiation.
549 Suppress_Instance_Location := True;
550 Msg_Cont_Status := False;
552 -- Loop to generate instantiation messages
554 Error_Msg_Sloc := Flag_Location;
555 X := Get_Source_File_Index (Flag_Location);
556 while Instantiation (X) /= No_Location loop
558 -- Suppress instantiation message on continuation lines
560 if Msg (Msg'First) /= '\' then
562 -- Case of inlined body
564 if Inlined_Body (X) then
565 if Is_Info_Msg then
566 Error_Msg_Internal
567 (Msg => "info: in inlined body #",
568 Span => To_Span (Actual_Error_Loc),
569 Opan => Flag_Span,
570 Msg_Cont => Msg_Cont_Status);
572 elsif Is_Warning_Msg then
573 Error_Msg_Internal
574 (Msg => Warn_Insertion & "in inlined body #",
575 Span => To_Span (Actual_Error_Loc),
576 Opan => Flag_Span,
577 Msg_Cont => Msg_Cont_Status);
579 elsif Is_Style_Msg then
580 Error_Msg_Internal
581 (Msg => "style: in inlined body #",
582 Span => To_Span (Actual_Error_Loc),
583 Opan => Flag_Span,
584 Msg_Cont => Msg_Cont_Status);
586 else
587 Error_Msg_Internal
588 (Msg => "error in inlined body #",
589 Span => To_Span (Actual_Error_Loc),
590 Opan => Flag_Span,
591 Msg_Cont => Msg_Cont_Status);
592 end if;
594 -- Case of generic instantiation
596 else
597 if Is_Info_Msg then
598 Error_Msg_Internal
599 (Msg => "info: in instantiation #",
600 Span => To_Span (Actual_Error_Loc),
601 Opan => Flag_Span,
602 Msg_Cont => Msg_Cont_Status);
604 elsif Is_Warning_Msg then
605 Error_Msg_Internal
606 (Msg => Warn_Insertion & "in instantiation #",
607 Span => To_Span (Actual_Error_Loc),
608 Opan => Flag_Span,
609 Msg_Cont => Msg_Cont_Status);
611 elsif Is_Style_Msg then
612 Error_Msg_Internal
613 (Msg => "style: in instantiation #",
614 Span => To_Span (Actual_Error_Loc),
615 Opan => Flag_Span,
616 Msg_Cont => Msg_Cont_Status);
618 else
619 Error_Msg_Internal
620 (Msg => "instantiation error #",
621 Span => To_Span (Actual_Error_Loc),
622 Opan => Flag_Span,
623 Msg_Cont => Msg_Cont_Status);
624 end if;
625 end if;
626 end if;
628 Error_Msg_Sloc := Instantiation (X);
629 X := Get_Source_File_Index (Error_Msg_Sloc);
630 Msg_Cont_Status := True;
631 end loop;
633 Suppress_Instance_Location := False;
634 Error_Msg_Sloc := Save_Error_Msg_Sloc;
636 -- Here we output the original message on the outer instantiation
638 Error_Msg_Internal
639 (Msg => Msg,
640 Span => To_Span (Actual_Error_Loc),
641 Opan => Flag_Span,
642 Msg_Cont => Msg_Cont_Status);
643 end;
644 end Error_Msg;
646 ----------------------------------
647 -- Error_Msg_Ada_2005_Extension --
648 ----------------------------------
650 procedure Error_Msg_Ada_2005_Extension (Extension : String) is
651 Loc : constant Source_Ptr := Token_Ptr;
652 begin
653 if Ada_Version < Ada_2005 then
654 Error_Msg (Extension & " is an Ada 2005 extension", Loc);
656 if No (Ada_Version_Pragma) then
657 Error_Msg ("\unit must be compiled with -gnat05 switch", Loc);
658 else
659 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
660 Error_Msg ("\incompatible with Ada version set#", Loc);
661 end if;
662 end if;
663 end Error_Msg_Ada_2005_Extension;
665 --------------------------------
666 -- Error_Msg_Ada_2012_Feature --
667 --------------------------------
669 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
670 begin
671 if Ada_Version < Ada_2012 then
672 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
674 if No (Ada_Version_Pragma) then
675 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
676 else
677 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
678 Error_Msg ("\incompatible with Ada version set#", Loc);
679 end if;
680 end if;
681 end Error_Msg_Ada_2012_Feature;
683 --------------------------------
684 -- Error_Msg_Ada_2022_Feature --
685 --------------------------------
687 procedure Error_Msg_Ada_2022_Feature (Feature : String; Loc : Source_Ptr) is
688 begin
689 if Ada_Version < Ada_2022 then
690 Error_Msg (Feature & " is an Ada 2022 feature", Loc);
692 if No (Ada_Version_Pragma) then
693 Error_Msg ("\unit must be compiled with -gnat2022 switch", Loc);
694 else
695 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
696 Error_Msg ("\incompatible with Ada version set#", Loc);
697 end if;
698 end if;
699 end Error_Msg_Ada_2022_Feature;
701 ------------------
702 -- Error_Msg_AP --
703 ------------------
705 procedure Error_Msg_AP (Msg : String) is
706 S1 : Source_Ptr;
707 C : Character;
709 begin
710 -- If we had saved the Scan_Ptr value after scanning the previous
711 -- token, then we would have exactly the right place for putting
712 -- the flag immediately at hand. However, that would add at least
713 -- two instructions to a Scan call *just* to service the possibility
714 -- of an Error_Msg_AP call. So instead we reconstruct that value.
716 -- We have two possibilities, start with Prev_Token_Ptr and skip over
717 -- the current token, which is made harder by the possibility that this
718 -- token may be in error, or start with Token_Ptr and work backwards.
719 -- We used to take the second approach, but it's hard because of
720 -- comments, and harder still because things that look like comments
721 -- can appear inside strings. So now we take the first approach.
723 -- Note: in the case where there is no previous token, Prev_Token_Ptr
724 -- is set to Source_First, which is a reasonable position for the
725 -- error flag in this situation.
727 S1 := Prev_Token_Ptr;
728 C := Source (S1);
730 -- If the previous token is a string literal, we need a special approach
731 -- since there may be white space inside the literal and we don't want
732 -- to stop on that white space.
734 -- Note: since this is an error recovery issue anyway, it is not worth
735 -- worrying about special UTF_32 line terminator characters here.
737 if Prev_Token = Tok_String_Literal then
738 loop
739 S1 := S1 + 1;
741 if Source (S1) = C then
742 S1 := S1 + 1;
743 exit when Source (S1) /= C;
744 elsif Source (S1) in Line_Terminator then
745 exit;
746 end if;
747 end loop;
749 -- Character literal also needs special handling
751 elsif Prev_Token = Tok_Char_Literal then
752 S1 := S1 + 3;
754 -- Otherwise we search forward for the end of the current token, marked
755 -- by a line terminator, white space, a comment symbol or if we bump
756 -- into the following token (i.e. the current token).
758 -- Again, it is not worth worrying about UTF_32 special line terminator
759 -- characters in this context, since this is only for error recovery.
761 else
762 while Source (S1) not in Line_Terminator
763 and then Source (S1) /= ' '
764 and then Source (S1) /= ASCII.HT
765 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
766 and then S1 /= Token_Ptr
767 loop
768 S1 := S1 + 1;
769 end loop;
770 end if;
772 -- S1 is now set to the location for the flag
774 Error_Msg (Msg, S1);
775 end Error_Msg_AP;
777 ------------------
778 -- Error_Msg_BC --
779 ------------------
781 procedure Error_Msg_BC (Msg : String) is
782 begin
783 -- If we are at end of file, post the flag after the previous token
785 if Token = Tok_EOF then
786 Error_Msg_AP (Msg);
788 -- If we are at start of file, post the flag at the current token
790 elsif Token_Ptr = Source_First (Current_Source_File) then
791 Error_Msg_SC (Msg);
793 -- If the character before the current token is a space or a horizontal
794 -- tab, then we place the flag on this character (in the case of a tab
795 -- we would really like to place it in the "last" character of the tab
796 -- space, but that it too much trouble to worry about).
798 elsif Source (Token_Ptr - 1) = ' '
799 or else Source (Token_Ptr - 1) = ASCII.HT
800 then
801 Error_Msg (Msg, Token_Ptr - 1);
803 -- If there is no space or tab before the current token, then there is
804 -- no room to place the flag before the token, so we place it on the
805 -- token instead (this happens for example at the start of a line).
807 else
808 Error_Msg (Msg, Token_Ptr);
809 end if;
810 end Error_Msg_BC;
812 -------------------
813 -- Error_Msg_CRT --
814 -------------------
816 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
817 begin
818 if No_Run_Time_Mode then
819 Error_Msg_N ('|' & Feature & " not allowed in no run time mode", N);
821 else pragma Assert (Configurable_Run_Time_Mode);
822 Error_Msg_N ('|' & Feature & " not supported by configuration>", N);
823 end if;
825 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
826 end Error_Msg_CRT;
828 ------------------
829 -- Error_Msg_PT --
830 ------------------
832 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
833 begin
834 Error_Msg_N
835 ("illegal overriding of subprogram inherited from interface", E);
837 Error_Msg_Sloc := Sloc (Iface_Prim);
839 if Ekind (E) = E_Function then
840 Error_Msg_N
841 ("\first formal of & declared # must be of mode `IN` "
842 & "or access-to-constant", E);
843 else
844 Error_Msg_N
845 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
846 & "or access-to-variable", E);
847 end if;
848 end Error_Msg_PT;
850 -----------------
851 -- Error_Msg_F --
852 -----------------
854 procedure Error_Msg_F (Msg : String; N : Node_Id) is
855 Fst, Lst : Node_Id;
856 begin
857 First_And_Last_Nodes (N, Fst, Lst);
858 Error_Msg_NEL (Msg, N, N,
859 To_Span (Ptr => Sloc (Fst),
860 First => First_Sloc (Fst),
861 Last => Last_Sloc (Lst)));
862 end Error_Msg_F;
864 ------------------
865 -- Error_Msg_FE --
866 ------------------
868 procedure Error_Msg_FE
869 (Msg : String;
870 N : Node_Id;
871 E : Node_Or_Entity_Id)
873 Fst, Lst : Node_Id;
874 begin
875 First_And_Last_Nodes (N, Fst, Lst);
876 Error_Msg_NEL (Msg, N, E,
877 To_Span (Ptr => Sloc (Fst),
878 First => First_Sloc (Fst),
879 Last => Last_Sloc (Lst)));
880 end Error_Msg_FE;
882 ------------------------------
883 -- Error_Msg_GNAT_Extension --
884 ------------------------------
886 procedure Error_Msg_GNAT_Extension
887 (Extension : String;
888 Loc : Source_Ptr;
889 Is_Core_Extension : Boolean := False)
891 begin
892 if (if Is_Core_Extension
893 then Core_Extensions_Allowed
894 else All_Extensions_Allowed)
895 then
896 return;
897 end if;
899 Error_Msg (Extension & " is a 'G'N'A'T-specific extension", Loc);
901 if No (Ada_Version_Pragma) then
902 if Is_Core_Extension then
903 Error_Msg
904 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
905 "or use pragma Extensions_Allowed (On) '[or All_Extensions']",
906 Loc);
907 else
908 Error_Msg
909 ("\unit must be compiled with -gnatX0 " &
910 "or use pragma Extensions_Allowed (All_Extensions)", Loc);
911 end if;
912 else
913 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
914 Error_Msg ("\incompatible with Ada version set#", Loc);
915 if Is_Core_Extension then
916 Error_Msg
917 ("\must use pragma Extensions_Allowed (On)" &
918 " '[or All_Extensions']", Loc);
919 else
920 Error_Msg
921 ("\must use pragma Extensions_Allowed (All_Extensions)", Loc);
922 end if;
923 end if;
924 end Error_Msg_GNAT_Extension;
926 ------------------------
927 -- Error_Msg_Internal --
928 ------------------------
930 procedure Error_Msg_Internal
931 (Msg : String;
932 Span : Source_Span;
933 Opan : Source_Span;
934 Msg_Cont : Boolean)
936 Sptr : constant Source_Ptr := Span.Ptr;
937 Optr : constant Source_Ptr := Opan.Ptr;
939 Next_Msg : Error_Msg_Id;
940 -- Pointer to next message at insertion point
942 Prev_Msg : Error_Msg_Id;
943 -- Pointer to previous message at insertion point
945 Temp_Msg : Error_Msg_Id;
947 Warn_Err : Boolean;
948 -- Set if warning to be treated as error
950 procedure Handle_Serious_Error;
951 -- Internal procedure to do all error message handling for a serious
952 -- error message, other than bumping the error counts and arranging
953 -- for the message to be output.
955 --------------------------
956 -- Handle_Serious_Error --
957 --------------------------
959 procedure Handle_Serious_Error is
960 begin
961 -- Turn off code generation if not done already
963 if Operating_Mode = Generate_Code then
964 Operating_Mode := Check_Semantics;
965 Expander_Active := False;
966 end if;
968 -- Set the fatal error flag in the unit table unless we are in
969 -- Try_Semantics mode (in which case we set ignored mode if not
970 -- currently set. This stops the semantics from being performed
971 -- if we find a serious error. This is skipped if we are currently
972 -- dealing with the configuration pragma file.
974 if Current_Source_Unit /= No_Unit then
975 declare
976 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
977 begin
978 if Try_Semantics then
979 if Fatal_Error (U) = None then
980 Set_Fatal_Error (U, Error_Ignored);
981 end if;
982 else
983 Set_Fatal_Error (U, Error_Detected);
984 end if;
985 end;
986 end if;
988 -- Disable warnings on unused use clauses and the like. Otherwise, an
989 -- error might hide a reference to an entity in a used package, so
990 -- after fixing the error, the use clause no longer looks like it was
991 -- unused.
993 Warnsw.Check_Unreferenced := False;
994 Warnsw.Check_Unreferenced_Formals := False;
995 end Handle_Serious_Error;
997 -- Start of processing for Error_Msg_Internal
999 begin
1000 -- Detect common mistake of prefixing or suffixing the message with a
1001 -- space character.
1003 pragma Assert (Msg (Msg'First) /= ' ' and then Msg (Msg'Last) /= ' ');
1005 if Raise_Exception_On_Error /= 0 then
1006 raise Error_Msg_Exception;
1007 end if;
1009 Continuation := Msg_Cont;
1010 Continuation_New_Line := False;
1011 Suppress_Message := False;
1012 Kill_Message := False;
1013 Set_Msg_Text (Msg, Sptr);
1015 -- Kill continuation if parent message killed
1017 if Continuation and Last_Killed then
1018 return;
1019 end if;
1021 -- Return without doing anything if message is suppressed
1023 if Suppress_Message
1024 and then not All_Errors_Mode
1025 and then not Is_Warning_Msg
1026 and then not Is_Unconditional_Msg
1027 then
1028 if not Continuation then
1029 Last_Killed := True;
1030 end if;
1032 return;
1033 end if;
1035 -- Return without doing anything if message is killed and this is not
1036 -- the first error message. The philosophy is that if we get a weird
1037 -- error message and we already have had a message, then we hope the
1038 -- weird message is a junk cascaded message
1040 if Kill_Message
1041 and then not All_Errors_Mode
1042 and then Total_Errors_Detected /= 0
1043 then
1044 if not Continuation then
1045 Last_Killed := True;
1046 end if;
1048 return;
1049 end if;
1051 if Is_Info_Msg then
1053 -- Immediate return if info messages are suppressed
1055 if Info_Suppressed then
1056 Cur_Msg := No_Error_Msg;
1057 return;
1058 end if;
1060 -- If the flag location is in the main extended source unit then for
1061 -- sure we want the message since it definitely belongs.
1063 if In_Extended_Main_Source_Unit (Sptr) then
1064 null;
1066 -- Keep info message if message text contains !!
1068 elsif Has_Double_Exclam then
1069 null;
1071 -- Here is where we delete a message from a with'ed unit
1073 else
1074 Cur_Msg := No_Error_Msg;
1076 if not Continuation then
1077 Last_Killed := True;
1078 end if;
1080 return;
1081 end if;
1083 end if;
1085 -- Special check for warning message to see if it should be output
1087 if Is_Warning_Msg then
1089 -- Immediate return if warning message and warnings are suppressed
1091 if Warnings_Suppressed (Optr) /= No_String
1092 or else
1093 Warnings_Suppressed (Sptr) /= No_String
1094 then
1095 Cur_Msg := No_Error_Msg;
1096 return;
1097 end if;
1099 -- If the flag location is in the main extended source unit then for
1100 -- sure we want the warning since it definitely belongs.
1102 if In_Extended_Main_Source_Unit (Sptr) then
1103 null;
1105 -- If the main unit has not been read yet. The warning must be on
1106 -- a configuration file: gnat.adc or user-defined. This means we
1107 -- are not parsing the main unit yet, so skip following checks.
1109 elsif No (Cunit (Main_Unit)) then
1110 null;
1112 -- If the flag location is not in the extended main source unit, then
1113 -- we want to eliminate the warning, unless it is in the extended
1114 -- main code unit and we want warnings on the instance.
1116 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
1117 null;
1119 -- Keep warning if debug flag G set
1121 elsif Debug_Flag_GG then
1122 null;
1124 -- Keep warning if message text contains !!
1126 elsif Has_Double_Exclam then
1127 null;
1129 -- Here is where we delete a warning from a with'ed unit
1131 else
1132 Cur_Msg := No_Error_Msg;
1134 if not Continuation then
1135 Last_Killed := True;
1136 end if;
1138 return;
1139 end if;
1140 end if;
1142 -- If message is to be ignored in special ignore message mode, this is
1143 -- where we do this special processing, bypassing message output.
1145 if Ignore_Errors_Enable > 0 then
1146 if Is_Serious_Error then
1147 Handle_Serious_Error;
1148 end if;
1150 return;
1151 end if;
1153 -- If error message line length set, and this is a continuation message
1154 -- then all we do is to append the text to the text of the last message
1155 -- with a comma space separator (eliminating a possible (style) or
1156 -- info prefix).
1158 if Error_Msg_Line_Length /= 0 and then Continuation then
1159 Cur_Msg := Errors.Last;
1161 declare
1162 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
1163 Newm : String (1 .. Oldm'Last + 2 + Msglen);
1164 Newl : Natural;
1165 M : Natural;
1167 begin
1168 -- First copy old message to new one and free it
1170 Newm (Oldm'Range) := Oldm.all;
1171 Newl := Oldm'Length;
1172 Free (Oldm);
1174 -- Remove (style) or info: at start of message
1176 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
1177 M := 9;
1179 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
1180 M := 7;
1182 else
1183 M := 1;
1184 end if;
1186 -- Now deal with separation between messages. Normally this is
1187 -- simply comma space, but there are some special cases.
1189 -- If continuation new line, then put actual NL character in msg
1191 if Continuation_New_Line then
1192 Newl := Newl + 1;
1193 Newm (Newl) := ASCII.LF;
1195 -- If continuation message is enclosed in parentheses, then
1196 -- special treatment (don't need a comma, and we want to combine
1197 -- successive parenthetical remarks into a single one with
1198 -- separating commas).
1200 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
1202 -- Case where existing message ends in right paren, remove
1203 -- and separate parenthetical remarks with a comma.
1205 if Newm (Newl) = ')' then
1206 Newm (Newl) := ',';
1207 Msg_Buffer (M) := ' ';
1209 -- Case where we are adding new parenthetical comment
1211 else
1212 Newl := Newl + 1;
1213 Newm (Newl) := ' ';
1214 end if;
1216 -- Case where continuation not in parens and no new line
1218 else
1219 Newm (Newl + 1 .. Newl + 2) := ", ";
1220 Newl := Newl + 2;
1221 end if;
1223 -- Append new message
1225 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1226 Msg_Buffer (M .. Msglen);
1227 Newl := Newl + Msglen - M + 1;
1228 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1230 -- Update warning msg flag and message doc char if needed
1232 if Is_Warning_Msg then
1233 if not Errors.Table (Cur_Msg).Warn then
1234 Errors.Table (Cur_Msg).Warn := True;
1235 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1237 elsif Warning_Msg_Char /= " " then
1238 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1239 end if;
1240 end if;
1241 end;
1243 return;
1244 end if;
1246 -- Warning, Style and Info attributes are mutually exclusive
1248 pragma Assert (Boolean'Pos (Is_Warning_Msg) + Boolean'Pos (Is_Info_Msg) +
1249 Boolean'Pos (Is_Style_Msg) <= 1);
1251 -- Here we build a new error object
1253 Errors.Append
1254 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1255 Next => No_Error_Msg,
1256 Prev => No_Error_Msg,
1257 Sptr => Span,
1258 Optr => Opan,
1259 Insertion_Sloc => (if Has_Insertion_Line then Error_Msg_Sloc
1260 else No_Location),
1261 Sfile => Get_Source_File_Index (Sptr),
1262 Line => Get_Physical_Line_Number (Sptr),
1263 Col => Get_Column_Number (Sptr),
1264 Compile_Time_Pragma => Is_Compile_Time_Msg,
1265 Warn => Is_Warning_Msg,
1266 Info => Is_Info_Msg,
1267 Check => Is_Check_Msg,
1268 Warn_Err => False, -- reset below
1269 Warn_Chr => Warning_Msg_Char,
1270 Warn_Runtime_Raise => Is_Runtime_Raise,
1271 Style => Is_Style_Msg,
1272 Serious => Is_Serious_Error,
1273 Uncond => Is_Unconditional_Msg,
1274 Msg_Cont => Continuation,
1275 Deleted => False));
1276 Cur_Msg := Errors.Last;
1278 -- Test if warning to be treated as error
1280 Warn_Err :=
1281 (Is_Warning_Msg or Is_Style_Msg)
1282 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1283 or else
1284 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
1286 -- Propagate Warn_Err to this message and preceding continuations.
1287 -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
1288 -- current continued message could have been escalated from warning to
1289 -- error.
1291 for J in reverse 1 .. Errors.Last loop
1292 Errors.Table (J).Warn_Err := Warn_Err;
1293 Errors.Table (J).Warn := Is_Warning_Msg;
1294 Errors.Table (J).Warn_Runtime_Raise := Is_Runtime_Raise;
1295 exit when not Errors.Table (J).Msg_Cont;
1296 end loop;
1298 -- If immediate errors mode set, output error message now. Also output
1299 -- now if the -d1 debug flag is set (so node number message comes out
1300 -- just before actual error message)
1302 if Debug_Flag_OO or else Debug_Flag_1 then
1303 Write_Eol;
1304 Output_Source_Line
1305 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1306 Temp_Msg := Cur_Msg;
1307 Output_Error_Msgs (Temp_Msg);
1309 -- If not in immediate errors mode, then we insert the message in the
1310 -- error chain for later output by Finalize. The messages are sorted
1311 -- first by unit (main unit comes first), and within a unit by source
1312 -- location (earlier flag location first in the chain).
1314 else
1315 -- First a quick check, does this belong at the very end of the chain
1316 -- of error messages. This saves a lot of time in the normal case if
1317 -- there are lots of messages.
1319 if Last_Error_Msg /= No_Error_Msg
1320 and then Errors.Table (Cur_Msg).Sfile =
1321 Errors.Table (Last_Error_Msg).Sfile
1322 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr.Ptr
1323 or else
1324 (Sptr = Errors.Table (Last_Error_Msg).Sptr.Ptr
1325 and then
1326 Optr > Errors.Table (Last_Error_Msg).Optr.Ptr))
1327 then
1328 Prev_Msg := Last_Error_Msg;
1329 Next_Msg := No_Error_Msg;
1331 -- Otherwise do a full sequential search for the insertion point
1333 else
1334 Prev_Msg := No_Error_Msg;
1335 Next_Msg := First_Error_Msg;
1336 while Next_Msg /= No_Error_Msg loop
1337 exit when
1338 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1340 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1341 then
1342 exit when Sptr < Errors.Table (Next_Msg).Sptr.Ptr
1343 or else (Sptr = Errors.Table (Next_Msg).Sptr.Ptr
1344 and then
1345 Optr < Errors.Table (Next_Msg).Optr.Ptr);
1346 end if;
1348 Prev_Msg := Next_Msg;
1349 Next_Msg := Errors.Table (Next_Msg).Next;
1350 end loop;
1351 end if;
1353 -- Now we insert the new message in the error chain.
1355 -- The possible insertion point for the new message is after Prev_Msg
1356 -- and before Next_Msg. However, this is where we do a special check
1357 -- for redundant parsing messages, defined as messages posted on the
1358 -- same line. The idea here is that probably such messages are junk
1359 -- from the parser recovering. In full errors mode, we don't do this
1360 -- deletion, but otherwise such messages are discarded at this stage.
1362 if Prev_Msg /= No_Error_Msg
1363 and then Errors.Table (Prev_Msg).Line =
1364 Errors.Table (Cur_Msg).Line
1365 and then Errors.Table (Prev_Msg).Sfile =
1366 Errors.Table (Cur_Msg).Sfile
1367 and then Compiler_State = Parsing
1368 and then not All_Errors_Mode
1369 then
1370 -- Don't delete unconditional messages and at this stage, don't
1371 -- delete continuation lines; we attempted to delete those earlier
1372 -- if the parent message was deleted.
1374 if not Errors.Table (Cur_Msg).Uncond
1375 and then not Continuation
1376 then
1377 -- Don't delete if prev msg is warning and new msg is an error.
1378 -- This is because we don't want a real error masked by a
1379 -- warning. In all other cases (that is parse errors for the
1380 -- same line that are not unconditional) we do delete the
1381 -- message. This helps to avoid junk extra messages from
1382 -- cascaded parsing errors
1384 if not (Errors.Table (Prev_Msg).Warn
1385 or else
1386 Errors.Table (Prev_Msg).Style)
1387 or else
1388 (Errors.Table (Cur_Msg).Warn
1389 or else
1390 Errors.Table (Cur_Msg).Style)
1391 then
1392 -- All tests passed, delete the message by simply returning
1393 -- without any further processing.
1395 pragma Assert (not Continuation);
1397 Last_Killed := True;
1398 return;
1399 end if;
1400 end if;
1401 end if;
1403 -- Come here if message is to be inserted in the error chain
1405 if not Continuation then
1406 Last_Killed := False;
1407 end if;
1409 if Prev_Msg = No_Error_Msg then
1410 First_Error_Msg := Cur_Msg;
1411 else
1412 Errors.Table (Prev_Msg).Next := Cur_Msg;
1413 end if;
1415 Errors.Table (Cur_Msg).Next := Next_Msg;
1417 if Next_Msg = No_Error_Msg then
1418 Last_Error_Msg := Cur_Msg;
1419 end if;
1420 end if;
1422 -- Bump appropriate statistics counts
1424 if Errors.Table (Cur_Msg).Info then
1425 Info_Messages := Info_Messages + 1;
1427 elsif Errors.Table (Cur_Msg).Warn
1428 or else Errors.Table (Cur_Msg).Style
1429 then
1430 Warnings_Detected := Warnings_Detected + 1;
1432 elsif Errors.Table (Cur_Msg).Check then
1433 Check_Messages := Check_Messages + 1;
1435 else
1436 Total_Errors_Detected := Total_Errors_Detected + 1;
1438 if Errors.Table (Cur_Msg).Serious then
1439 Serious_Errors_Detected := Serious_Errors_Detected + 1;
1440 Handle_Serious_Error;
1442 -- If not serious error, set Fatal_Error to indicate ignored error
1444 else
1445 declare
1446 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1447 begin
1448 if Fatal_Error (U) = None then
1449 Set_Fatal_Error (U, Error_Ignored);
1450 end if;
1451 end;
1452 end if;
1453 end if;
1455 -- Record warning message issued
1457 if Errors.Table (Cur_Msg).Warn
1458 and then not Errors.Table (Cur_Msg).Msg_Cont
1459 then
1460 Warning_Msg := Cur_Msg;
1461 end if;
1463 -- If too many warnings turn off warnings
1465 if Maximum_Messages /= 0 then
1466 if Warnings_Detected = Maximum_Messages then
1467 Warning_Mode := Suppress;
1468 end if;
1470 -- If too many errors abandon compilation
1472 if Total_Errors_Detected = Maximum_Messages then
1473 raise Unrecoverable_Error;
1474 end if;
1475 end if;
1477 if Has_Error_Code then
1478 declare
1479 Msg : constant String :=
1480 "\launch ""gnatprove --explain=[]"" for more information";
1481 begin
1482 Has_Double_Exclam := False;
1483 Has_Error_Code := False;
1484 Has_Insertion_Line := False;
1486 Error_Msg_Internal
1487 (Msg => Msg,
1488 Span => Span,
1489 Opan => Opan,
1490 Msg_Cont => True);
1491 end;
1492 end if;
1493 end Error_Msg_Internal;
1495 -----------------
1496 -- Error_Msg_N --
1497 -----------------
1499 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1500 Fst, Lst : Node_Id;
1501 begin
1502 First_And_Last_Nodes (N, Fst, Lst);
1503 Error_Msg_NEL (Msg, N, N,
1504 To_Span (Ptr => Sloc (N),
1505 First => First_Sloc (Fst),
1506 Last => Last_Sloc (Lst)));
1507 end Error_Msg_N;
1509 ------------------
1510 -- Error_Msg_NE --
1511 ------------------
1513 procedure Error_Msg_NE
1514 (Msg : String;
1515 N : Node_Or_Entity_Id;
1516 E : Node_Or_Entity_Id)
1518 Fst, Lst : Node_Id;
1519 begin
1520 First_And_Last_Nodes (N, Fst, Lst);
1521 Error_Msg_NEL (Msg, N, E,
1522 To_Span (Ptr => Sloc (N),
1523 First => First_Sloc (Fst),
1524 Last => Last_Sloc (Lst)));
1525 end Error_Msg_NE;
1527 -------------------
1528 -- Error_Msg_NEL --
1529 -------------------
1531 procedure Error_Msg_NEL
1532 (Msg : String;
1533 N : Node_Or_Entity_Id;
1534 E : Node_Or_Entity_Id;
1535 Flag_Location : Source_Ptr)
1537 Fst, Lst : Node_Id;
1538 begin
1539 First_And_Last_Nodes (N, Fst, Lst);
1540 Error_Msg_NEL
1541 (Msg, N, E,
1542 To_Span (Ptr => Flag_Location,
1543 First => Source_Ptr'Min (Flag_Location, First_Sloc (Fst)),
1544 Last => Source_Ptr'Max (Flag_Location, Last_Sloc (Lst))));
1545 end Error_Msg_NEL;
1547 procedure Error_Msg_NEL
1548 (Msg : String;
1549 N : Node_Or_Entity_Id;
1550 E : Node_Or_Entity_Id;
1551 Flag_Span : Source_Span)
1553 begin
1554 if Special_Msg_Delete (Msg, N, E) then
1555 return;
1556 end if;
1558 Prescan_Message (Msg);
1560 -- Special handling for warning messages
1562 if Is_Warning_Msg then
1564 -- Suppress if no warnings set for either entity or node
1566 if No_Warnings (N) or else No_Warnings (E) then
1568 -- Disable any continuation messages as well
1570 Last_Killed := True;
1571 return;
1572 end if;
1573 end if;
1575 -- Test for message to be output
1577 if All_Errors_Mode
1578 or else Is_Unconditional_Msg
1579 or else Is_Warning_Msg
1580 or else OK_Node (N)
1581 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1582 then
1583 Debug_Output (N);
1584 Error_Msg_Node_1 := E;
1585 Error_Msg (Msg, Flag_Span, N);
1587 else
1588 Last_Killed := True;
1589 end if;
1591 if not Get_Ignore_Errors then
1592 Set_Posted (N);
1593 end if;
1594 end Error_Msg_NEL;
1596 ------------------
1597 -- Error_Msg_NW --
1598 ------------------
1600 procedure Error_Msg_NW
1601 (Eflag : Boolean;
1602 Msg : String;
1603 N : Node_Or_Entity_Id)
1605 Fst, Lst : Node_Id;
1606 begin
1607 if Eflag
1608 and then In_Extended_Main_Source_Unit (N)
1609 and then Comes_From_Source (N)
1610 then
1611 First_And_Last_Nodes (N, Fst, Lst);
1612 Error_Msg_NEL (Msg, N, N,
1613 To_Span (Ptr => Sloc (N),
1614 First => First_Sloc (Fst),
1615 Last => Last_Sloc (Lst)));
1616 end if;
1617 end Error_Msg_NW;
1619 -----------------
1620 -- Error_Msg_S --
1621 -----------------
1623 procedure Error_Msg_S (Msg : String) is
1624 begin
1625 Error_Msg (Msg, Scan_Ptr);
1626 end Error_Msg_S;
1628 ------------------
1629 -- Error_Msg_SC --
1630 ------------------
1632 procedure Error_Msg_SC (Msg : String) is
1633 begin
1634 -- If we are at end of file, post the flag after the previous token
1636 if Token = Tok_EOF then
1637 Error_Msg_AP (Msg);
1639 -- For all other cases the message is posted at the current token
1640 -- pointer position
1642 else
1643 Error_Msg (Msg, Token_Ptr);
1644 end if;
1645 end Error_Msg_SC;
1647 ------------------
1648 -- Error_Msg_SP --
1649 ------------------
1651 procedure Error_Msg_SP (Msg : String) is
1652 begin
1653 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1654 -- is set to Source_First, which is a reasonable position for the
1655 -- error flag in this situation
1657 Error_Msg (Msg, Prev_Token_Ptr);
1658 end Error_Msg_SP;
1660 --------------
1661 -- Finalize --
1662 --------------
1664 procedure Finalize (Last_Call : Boolean) is
1665 Cur : Error_Msg_Id;
1666 Nxt : Error_Msg_Id;
1667 F : Error_Msg_Id;
1669 procedure Delete_Warning (E : Error_Msg_Id);
1670 -- Delete a warning msg if not already deleted and adjust warning count
1672 --------------------
1673 -- Delete_Warning --
1674 --------------------
1676 procedure Delete_Warning (E : Error_Msg_Id) is
1677 begin
1678 if not Errors.Table (E).Deleted then
1679 Errors.Table (E).Deleted := True;
1680 Warnings_Detected := Warnings_Detected - 1;
1681 end if;
1682 end Delete_Warning;
1684 -- Start of processing for Finalize
1686 begin
1687 -- Set Prev pointers
1689 Cur := First_Error_Msg;
1690 while Cur /= No_Error_Msg loop
1691 Nxt := Errors.Table (Cur).Next;
1692 exit when Nxt = No_Error_Msg;
1693 Errors.Table (Nxt).Prev := Cur;
1694 Cur := Nxt;
1695 end loop;
1697 -- Eliminate any duplicated error messages from the list. This is
1698 -- done after the fact to avoid problems with Change_Error_Text.
1700 Cur := First_Error_Msg;
1701 while Cur /= No_Error_Msg loop
1702 Nxt := Errors.Table (Cur).Next;
1704 F := Nxt;
1705 while F /= No_Error_Msg
1706 and then Errors.Table (F).Sptr.Ptr = Errors.Table (Cur).Sptr.Ptr
1707 loop
1708 Check_Duplicate_Message (Cur, F);
1709 F := Errors.Table (F).Next;
1710 end loop;
1712 Cur := Nxt;
1713 end loop;
1715 -- Mark any messages suppressed by specific warnings as Deleted
1717 Cur := First_Error_Msg;
1718 while Cur /= No_Error_Msg loop
1719 declare
1720 CE : Error_Msg_Object renames Errors.Table (Cur);
1721 Tag : constant String := Get_Warning_Tag (Cur);
1723 begin
1724 if CE.Warn
1725 and then not CE.Deleted
1726 and then
1727 (Warning_Specifically_Suppressed (CE.Sptr.Ptr, CE.Text, Tag)
1728 /= No_String
1729 or else
1730 Warning_Specifically_Suppressed (CE.Optr.Ptr, CE.Text, Tag)
1731 /= No_String)
1732 then
1733 Delete_Warning (Cur);
1735 -- If this is a continuation, delete previous parts of message
1737 F := Cur;
1738 while Errors.Table (F).Msg_Cont loop
1739 F := Errors.Table (F).Prev;
1740 exit when F = No_Error_Msg;
1741 Delete_Warning (F);
1742 end loop;
1744 -- Delete any following continuations
1746 F := Cur;
1747 loop
1748 F := Errors.Table (F).Next;
1749 exit when F = No_Error_Msg;
1750 exit when not Errors.Table (F).Msg_Cont;
1751 Delete_Warning (F);
1752 end loop;
1753 end if;
1754 end;
1756 Cur := Errors.Table (Cur).Next;
1757 end loop;
1759 Finalize_Called := True;
1761 -- Check consistency of specific warnings (may add warnings). We only
1762 -- do this on the last call, after all possible warnings are posted.
1764 if Last_Call then
1765 Validate_Specific_Warnings;
1766 end if;
1767 end Finalize;
1769 ----------------
1770 -- First_Node --
1771 ----------------
1773 function First_Node (C : Node_Id) return Node_Id is
1774 Fst, Lst : Node_Id;
1775 begin
1776 First_And_Last_Nodes (C, Fst, Lst);
1777 return Fst;
1778 end First_Node;
1780 --------------------------
1781 -- First_And_Last_Nodes --
1782 --------------------------
1784 procedure First_And_Last_Nodes
1785 (C : Node_Id;
1786 First_Node, Last_Node : out Node_Id)
1788 Orig : constant Node_Id := Original_Node (C);
1789 Loc : constant Source_Ptr := Sloc (Orig);
1790 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1791 Earliest : Node_Id;
1792 Latest : Node_Id;
1793 Eloc : Source_Ptr;
1794 Lloc : Source_Ptr;
1796 function Test_First_And_Last (N : Node_Id) return Traverse_Result;
1797 -- Function applied to every node in the construct
1799 procedure Search_Tree_First_And_Last is new
1800 Traverse_Proc (Test_First_And_Last);
1801 -- Create traversal procedure
1803 -------------------------
1804 -- Test_First_And_Last --
1805 -------------------------
1807 function Test_First_And_Last (N : Node_Id) return Traverse_Result is
1808 Norig : constant Node_Id := Original_Node (N);
1809 Loc : constant Source_Ptr := Sloc (Norig);
1811 begin
1812 -- ??? For assignments that require accessiblity checks, e.g.:
1814 -- Y := Func (123);
1816 -- the function call gets an extra actual parameter association with
1817 -- Sloc of the assigned name "Y":
1819 -- Y := Func (123, A8b => 2);
1821 -- We can simply ignore those extra actual parameters when
1822 -- determining the Sloc range of the "Func (123)" expression.
1824 if Nkind (N) = N_Parameter_Association
1825 and then Is_Accessibility_Actual (N)
1826 then
1827 return Skip;
1828 end if;
1830 -- Check for earlier
1832 if Loc < Eloc
1834 -- Ignore nodes with no useful location information
1836 and then Loc /= Standard_Location
1837 and then Loc /= No_Location
1839 -- Ignore nodes from a different file. This ensures against cases
1840 -- of strange foreign code somehow being present. We don't want
1841 -- wild placement of messages if that happens.
1843 and then Get_Source_File_Index (Loc) = Sfile
1844 then
1845 Earliest := Norig;
1846 Eloc := Loc;
1847 end if;
1849 -- Check for later
1851 if Loc > Lloc
1853 -- Ignore nodes with no useful location information
1855 and then Loc /= Standard_Location
1856 and then Loc /= No_Location
1858 -- Ignore nodes from a different file. This ensures against cases
1859 -- of strange foreign code somehow being present. We don't want
1860 -- wild placement of messages if that happens.
1862 and then Get_Source_File_Index (Loc) = Sfile
1863 then
1864 Latest := Norig;
1865 Lloc := Loc;
1866 end if;
1868 return OK_Orig;
1869 end Test_First_And_Last;
1871 -- Start of processing for First_And_Last_Nodes
1873 begin
1874 if Nkind (Orig) in N_Subexpr
1875 | N_Declaration
1876 | N_Access_To_Subprogram_Definition
1877 | N_Generic_Instantiation
1878 | N_Later_Decl_Item
1879 | N_Use_Package_Clause
1880 | N_Array_Type_Definition
1881 | N_Renaming_Declaration
1882 | N_Generic_Renaming_Declaration
1883 | N_Assignment_Statement
1884 | N_Raise_Statement
1885 | N_Simple_Return_Statement
1886 | N_Exit_Statement
1887 | N_Pragma
1888 | N_Use_Type_Clause
1889 | N_With_Clause
1890 | N_Attribute_Definition_Clause
1891 | N_Subtype_Indication
1892 then
1893 Earliest := Orig;
1894 Eloc := Loc;
1895 Latest := Orig;
1896 Lloc := Loc;
1897 Search_Tree_First_And_Last (Orig);
1898 First_Node := Earliest;
1899 Last_Node := Latest;
1901 else
1902 First_Node := Orig;
1903 Last_Node := Orig;
1904 end if;
1905 end First_And_Last_Nodes;
1907 ----------------
1908 -- First_Sloc --
1909 ----------------
1911 function First_Sloc (N : Node_Id) return Source_Ptr is
1912 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1913 SF : constant Source_Ptr := Source_First (SI);
1914 SL : constant Source_Ptr := Source_Last (SI);
1915 Src : constant Source_Buffer_Ptr := Source_Text (SI);
1916 F : Node_Id;
1917 S : Source_Ptr;
1919 begin
1920 F := First_Node (N);
1921 S := Sloc (F);
1923 if S not in SF .. SL then
1924 return S;
1925 end if;
1927 -- The following circuit is a bit subtle. When we have parenthesized
1928 -- expressions, then the Sloc will not record the location of the paren,
1929 -- but we would like to post the flag on the paren. So what we do is to
1930 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1931 -- any parentheses we know are present. Yes, we know this circuit is not
1932 -- 100% reliable (e.g. because we don't record all possible paren level
1933 -- values), but this is only for an error message so it is good enough.
1935 Node_Loop : loop
1936 -- Include parentheses around the top node, except when they are
1937 -- required by the syntax of the parent node.
1939 exit Node_Loop when F = N
1940 and then Paren_Required (N);
1942 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1944 -- We don't look more than 12 characters behind the current
1945 -- location, and in any case not past the front of the source.
1947 Search_Loop : for K in 1 .. 12 loop
1948 exit Search_Loop when S = SF;
1950 if Src (S - 1) = '(' then
1951 S := S - 1;
1952 exit Search_Loop;
1954 elsif Src (S - 1) <= ' ' then
1955 S := S - 1;
1957 else
1958 exit Search_Loop;
1959 end if;
1960 end loop Search_Loop;
1961 end loop Paren_Loop;
1963 exit Node_Loop when F = N;
1964 F := Parent (F);
1965 exit Node_Loop when Nkind (F) not in N_Subexpr;
1966 end loop Node_Loop;
1968 return S;
1969 end First_Sloc;
1971 -----------------------
1972 -- Get_Ignore_Errors --
1973 -----------------------
1975 function Get_Ignore_Errors return Boolean is
1976 begin
1977 return Errors_Must_Be_Ignored;
1978 end Get_Ignore_Errors;
1980 ----------------
1981 -- Initialize --
1982 ----------------
1984 procedure Initialize is
1985 begin
1986 Errors.Init;
1987 First_Error_Msg := No_Error_Msg;
1988 Last_Error_Msg := No_Error_Msg;
1989 Serious_Errors_Detected := 0;
1990 Total_Errors_Detected := 0;
1991 Cur_Msg := No_Error_Msg;
1992 List_Pragmas.Init;
1994 -- Reset counts for warnings
1996 Warnings_Treated_As_Errors := 0;
1997 Warnings_Detected := 0;
1998 Warnings_As_Errors_Count := 0;
2000 -- Initialize warnings tables
2002 Warnings.Init;
2003 Specific_Warnings.Init;
2004 end Initialize;
2006 -------------------------------
2007 -- Is_Size_Too_Small_Message --
2008 -------------------------------
2010 function Is_Size_Too_Small_Message (S : String) return Boolean is
2011 Size_For : constant String := "size for";
2012 pragma Assert (Size_Too_Small_Message (1 .. Size_For'Last) = Size_For);
2013 -- Assert that Size_Too_Small_Message starts with Size_For
2014 begin
2015 return S'Length >= Size_For'Length
2016 and then S (S'First .. S'First + Size_For'Length - 1) = Size_For;
2017 -- True if S starts with Size_For
2018 end Is_Size_Too_Small_Message;
2020 --------------------------------
2021 -- Validate_Specific_Warnings --
2022 --------------------------------
2024 procedure Validate_Specific_Warnings is
2025 begin
2026 if not Warnsw.Warn_On_Warnings_Off then
2027 return;
2028 end if;
2030 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
2031 declare
2032 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
2034 begin
2035 if not SWE.Config then
2037 -- Warn for unmatched Warnings (Off, ...)
2039 if SWE.Open then
2040 Error_Msg
2041 ("?.w?pragma Warnings Off with no matching Warnings On",
2042 SWE.Start);
2044 -- Warn for ineffective Warnings (Off, ..)
2046 elsif not SWE.Used
2048 -- Do not issue this warning for -Wxxx messages since the
2049 -- back-end doesn't report the information. Note that there
2050 -- is always an asterisk at the start of every message.
2052 and then not
2053 (SWE.Msg'Length > 3 and then SWE.Msg (2 .. 3) = "-W")
2054 then
2055 Error_Msg
2056 ("?.w?no warning suppressed by this pragma",
2057 SWE.Start);
2058 end if;
2059 end if;
2060 end;
2061 end loop;
2062 end Validate_Specific_Warnings;
2064 ---------------
2065 -- Last_Node --
2066 ---------------
2068 function Last_Node (C : Node_Id) return Node_Id is
2069 Fst, Lst : Node_Id;
2070 begin
2071 First_And_Last_Nodes (C, Fst, Lst);
2072 return Lst;
2073 end Last_Node;
2075 ---------------
2076 -- Last_Sloc --
2077 ---------------
2079 function Last_Sloc (N : Node_Id) return Source_Ptr is
2080 procedure Skip_Char (S : in out Source_Ptr);
2081 -- Skip one character of the source buffer at location S
2083 ---------------
2084 -- Skip_Char --
2085 ---------------
2087 procedure Skip_Char (S : in out Source_Ptr) is
2088 begin
2089 S := S + 1;
2090 end Skip_Char;
2092 -- Local variables
2094 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
2095 SF : constant Source_Ptr := Source_First (SI);
2096 SL : constant Source_Ptr := Source_Last (SI);
2097 Src : constant Source_Buffer_Ptr := Source_Text (SI);
2098 F : Node_Id;
2099 S : Source_Ptr;
2101 -- Start of processing for Last_Sloc
2103 begin
2104 F := Last_Node (N);
2105 S := Sloc (F);
2107 if S not in SF .. SL then
2108 return S;
2109 end if;
2111 -- For string and character literals simply forward the sloc by their
2112 -- length including the closing quotes. Perhaps we should do something
2113 -- special for multibyte characters, but this code is only used to emit
2114 -- error messages, so it is not worth the effort.
2116 case Nkind (F) is
2117 when N_String_Literal =>
2118 return S + Source_Ptr (String_Length (Strval (F))) + 1;
2120 when N_Character_Literal =>
2121 return S + 2;
2123 -- Skip past integer literals, both decimal and based, integer and
2124 -- real. We can't greedily accept all allowed character, because
2125 -- we would consme too many of them in expressions like "123+ABC"
2126 -- or "123..456", so we follow quite precisely the Ada grammar and
2127 -- consume different characters depending on the context.
2129 when N_Integer_Literal =>
2131 -- Skip past the initial numeral, which either leads the decimal
2132 -- literal or is the base of a based literal.
2134 while S < SL
2135 and then Src (S + 1) in '0' .. '9' | '_'
2136 loop
2137 Skip_Char (S);
2138 end loop;
2140 -- Skip past #based_numeral#, if present
2142 if S < SL
2143 and then Src (S + 1) = '#'
2144 then
2145 Skip_Char (S);
2147 while S < SL
2148 and then
2149 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2150 loop
2151 Skip_Char (S);
2152 end loop;
2154 if S < SL
2155 and then Src (S + 1) = '#'
2156 then
2157 Skip_Char (S);
2158 end if;
2159 end if;
2161 -- Skip past exponent, if present
2163 if S < SL
2164 and then Src (S + 1) in 'e' | 'E'
2165 then
2166 Skip_Char (S);
2168 -- For positive exponents the plus sign is optional, but we
2169 -- can simply skip past both plus and minus.
2171 if S < SL
2172 and then Src (S + 1) in '+' | '-'
2173 then
2174 Skip_Char (S);
2175 end if;
2177 -- Skip past the numeral part
2179 while S < SL
2180 and then Src (S + 1) in '0' .. '9' | '_'
2181 loop
2182 Skip_Char (S);
2183 end loop;
2184 end if;
2186 when N_Real_Literal =>
2187 -- Skip past the initial numeral, which either leads the decimal
2188 -- literal or is the base of a based literal.
2190 while S < SL
2191 and then Src (S + 1) in '0' .. '9' | '_'
2192 loop
2193 Skip_Char (S);
2194 end loop;
2196 if S < SL then
2198 -- Skip the dot and continue with a decimal literal
2200 if Src (S + 1) = '.' then
2201 Skip_Char (S);
2203 while S < SL
2204 and then Src (S + 1) in '0' .. '9' | '_'
2205 loop
2206 Skip_Char (S);
2207 end loop;
2209 -- Skip the hash and continue with a based literal
2211 elsif Src (S + 1) = '#' then
2212 Skip_Char (S);
2214 while S < SL
2215 and then
2216 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2217 loop
2218 Skip_Char (S);
2219 end loop;
2221 if S < SL
2222 and then Src (S + 1) = '.'
2223 then
2224 Skip_Char (S);
2225 end if;
2227 while S < SL
2228 and then
2229 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2230 loop
2231 Skip_Char (S);
2232 end loop;
2234 if S < SL
2235 and then Src (S + 1) = '#'
2236 then
2237 Skip_Char (S);
2238 end if;
2239 end if;
2240 end if;
2242 -- Skip past exponent, if present
2244 if S < SL
2245 and then Src (S + 1) in 'e' | 'E'
2246 then
2247 Skip_Char (S);
2248 -- For positive exponents the plus sign is optional, but we
2249 -- can simply skip past both plus and minus.
2251 if Src (S + 1) in '+' | '-' then
2252 Skip_Char (S);
2253 end if;
2255 -- Skip past the numeral part
2257 while S < SL
2258 and then Src (S + 1) in '0' .. '9' | '_'
2259 loop
2260 Skip_Char (S);
2261 end loop;
2262 end if;
2264 -- For other nodes simply skip past a keyword/identifier
2266 when others =>
2267 while S in SF .. SL - 1
2268 and then Src (S + 1)
2270 '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_'
2271 loop
2272 Skip_Char (S);
2273 end loop;
2274 end case;
2276 -- The following circuit attempts at crawling up the tree from the
2277 -- Last_Node, adjusting the Sloc value for any parentheses we know
2278 -- are present, similarly to what is done in First_Sloc.
2280 Node_Loop : loop
2281 -- Include parentheses around the top node, except when they are
2282 -- required by the syntax of the parent node.
2284 exit Node_Loop when F = N
2285 and then Paren_Required (N);
2287 Paren_Loop : for J in 1 .. Paren_Count (F) loop
2289 -- We don't look more than 12 characters after the current
2290 -- location
2292 Search_Loop : for K in 1 .. 12 loop
2293 exit Node_Loop when S = SL;
2295 if Src (S + 1) = ')' then
2296 S := S + 1;
2297 exit Search_Loop;
2299 elsif Src (S + 1) <= ' ' then
2300 S := S + 1;
2302 else
2303 exit Search_Loop;
2304 end if;
2305 end loop Search_Loop;
2306 end loop Paren_Loop;
2308 exit Node_Loop when F = N;
2309 F := Parent (F);
2310 exit Node_Loop when Nkind (F) not in N_Subexpr;
2311 end loop Node_Loop;
2313 -- Remove any trailing space
2315 while S in SF + 1 .. SL
2316 and then Src (S) = ' '
2317 loop
2318 S := S - 1;
2319 end loop;
2321 return S;
2322 end Last_Sloc;
2324 -----------------
2325 -- No_Warnings --
2326 -----------------
2328 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
2329 begin
2330 if Error_Posted (N) then
2331 return True;
2333 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
2334 return True;
2336 elsif Is_Entity_Name (N)
2337 and then Present (Entity (N))
2338 and then Has_Warnings_Off (Entity (N))
2339 then
2340 return True;
2342 else
2343 return False;
2344 end if;
2345 end No_Warnings;
2347 -------------
2348 -- OK_Node --
2349 -------------
2351 function OK_Node (N : Node_Id) return Boolean is
2352 K : constant Node_Kind := Nkind (N);
2354 begin
2355 if Error_Posted (N) then
2356 return False;
2358 elsif K in N_Has_Etype
2359 and then Present (Etype (N))
2360 and then Error_Posted (Etype (N))
2361 then
2362 return False;
2364 elsif (K in N_Op
2365 or else K = N_Attribute_Reference
2366 or else K = N_Character_Literal
2367 or else K = N_Expanded_Name
2368 or else K = N_Identifier
2369 or else K = N_Operator_Symbol)
2370 and then Present (Entity (N))
2371 and then Error_Posted (Entity (N))
2372 then
2373 return False;
2374 else
2375 return True;
2376 end if;
2377 end OK_Node;
2379 -------------------------
2380 -- Output_JSON_Message --
2381 -------------------------
2383 procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
2385 function Is_Continuation (E : Error_Msg_Id) return Boolean;
2386 -- Return True if E is a continuation message.
2388 procedure Write_JSON_Escaped_String (Str : String_Ptr);
2389 procedure Write_JSON_Escaped_String (Str : String);
2390 -- Write each character of Str, taking care of preceding each quote and
2391 -- backslash with a backslash. Note that this escaping differs from what
2392 -- GCC does.
2394 -- Indeed, the JSON specification mandates encoding wide characters
2395 -- either as their direct UTF-8 representation or as their escaped
2396 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2397 -- we choose to use the UTF-8 representation instead.
2399 procedure Write_JSON_Location (Sptr : Source_Ptr);
2400 -- Write Sptr as a JSON location, an object containing a file attribute,
2401 -- a line number and a column number.
2403 procedure Write_JSON_Span (Error : Error_Msg_Object);
2404 -- Write Error as a JSON span, an object containing a "caret" attribute
2405 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2406 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2407 -- locations under the names "start" and "finish".
2409 -----------------------
2410 -- Is_Continuation --
2411 -----------------------
2413 function Is_Continuation (E : Error_Msg_Id) return Boolean is
2414 begin
2415 return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
2416 end Is_Continuation;
2418 -------------------------------
2419 -- Write_JSON_Escaped_String --
2420 -------------------------------
2422 procedure Write_JSON_Escaped_String (Str : String) is
2423 begin
2424 for C of Str loop
2425 if C = '"' or else C = '\' then
2426 Write_Char ('\');
2427 end if;
2429 Write_Char (C);
2430 end loop;
2431 end Write_JSON_Escaped_String;
2433 -------------------------------
2434 -- Write_JSON_Escaped_String --
2435 -------------------------------
2437 procedure Write_JSON_Escaped_String (Str : String_Ptr) is
2438 begin
2439 Write_JSON_Escaped_String (Str.all);
2440 end Write_JSON_Escaped_String;
2442 -------------------------
2443 -- Write_JSON_Location --
2444 -------------------------
2446 procedure Write_JSON_Location (Sptr : Source_Ptr) is
2447 Name : constant File_Name_Type :=
2448 Full_Ref_Name (Get_Source_File_Index (Sptr));
2449 begin
2450 Write_Str ("{""file"":""");
2451 if Full_Path_Name_For_Brief_Errors then
2452 Write_JSON_Escaped_String
2453 (System.OS_Lib.Normalize_Pathname (Get_Name_String (Name)));
2454 else
2455 Write_Name (Name);
2456 end if;
2457 Write_Str (""",""line"":");
2458 Write_Int (Pos (Get_Physical_Line_Number (Sptr)));
2459 Write_Str (", ""column"":");
2460 Write_Int (Nat (Get_Column_Number (Sptr)));
2461 Write_Str ("}");
2462 end Write_JSON_Location;
2464 ---------------------
2465 -- Write_JSON_Span --
2466 ---------------------
2468 procedure Write_JSON_Span (Error : Error_Msg_Object) is
2469 Span : constant Source_Span := Error.Sptr;
2470 begin
2471 Write_Str ("{""caret"":");
2472 Write_JSON_Location (Span.Ptr);
2474 if Span.Ptr /= Span.First then
2475 Write_Str (",""start"":");
2476 Write_JSON_Location (Span.First);
2477 end if;
2479 if Span.Ptr /= Span.Last then
2480 Write_Str (",""finish"":");
2481 Write_JSON_Location (Span.Last);
2482 end if;
2484 Write_Str ("}");
2485 end Write_JSON_Span;
2487 -- Local Variables
2489 E : Error_Msg_Id := Error_Id;
2491 Print_Continuations : constant Boolean := not Is_Continuation (E);
2492 -- Do not print continuations messages as children of the current
2493 -- message if the current message is a continuation message.
2495 Option : constant String := Get_Warning_Option (E);
2496 -- The option that triggered this message.
2498 -- Start of processing for Output_JSON_Message
2500 begin
2501 -- Print message kind
2503 Write_Str ("{""kind"":");
2505 if Errors.Table (E).Warn and then not Errors.Table (E).Warn_Err then
2506 Write_Str ("""warning""");
2507 elsif Errors.Table (E).Info or else Errors.Table (E).Check then
2508 Write_Str ("""note""");
2509 else
2510 Write_Str ("""error""");
2511 end if;
2513 -- Print message location
2515 Write_Str (",""locations"":[");
2516 Write_JSON_Span (Errors.Table (E));
2518 if Errors.Table (E).Optr.Ptr /= Errors.Table (E).Sptr.Ptr then
2519 Write_Str (",{""caret"":");
2520 Write_JSON_Location (Errors.Table (E).Optr.Ptr);
2521 Write_Str ("}");
2522 end if;
2524 Write_Str ("]");
2526 -- Print message option, if there is one
2527 if Option /= "" then
2528 Write_Str (",""option"":""" & Option & """");
2529 end if;
2531 -- Print message content
2533 Write_Str (",""message"":""");
2534 Write_JSON_Escaped_String (Errors.Table (E).Text);
2535 Write_Str ("""");
2537 E := E + 1;
2539 if Print_Continuations and then Is_Continuation (E) then
2541 Write_Str (",""children"": [");
2542 Output_JSON_Message (E);
2543 E := E + 1;
2545 while Is_Continuation (E) loop
2546 Write_Str (", ");
2547 Output_JSON_Message (E);
2548 E := E + 1;
2549 end loop;
2551 Write_Str ("]");
2553 end if;
2555 Write_Str ("}");
2556 end Output_JSON_Message;
2558 ---------------------
2559 -- Output_Messages --
2560 ---------------------
2562 procedure Output_Messages is
2564 -- Local subprograms
2566 procedure Write_Error_Summary;
2567 -- Write error summary
2569 procedure Write_Header (Sfile : Source_File_Index);
2570 -- Write header line (compiling or checking given file)
2572 procedure Write_Max_Errors;
2573 -- Write message if max errors reached
2575 procedure Write_Source_Code_Lines
2576 (Span : Source_Span;
2577 SGR_Span : String);
2578 -- Write the source code line corresponding to Span, as follows when
2579 -- Span in on one line:
2581 -- line | actual code line here with Span somewhere
2582 -- | ~~~~~^~~~
2584 -- where the caret on the line points to location Span.Ptr, and the
2585 -- range Span.First..Span.Last is underlined.
2587 -- or when the span is over multiple lines:
2589 -- line | beginning of the Span on this line
2590 -- ... | ...
2591 -- line>| actual code line here with Span.Ptr somewhere
2592 -- ... | ...
2593 -- line | end of the Span on this line
2595 -- or when the span is a simple location, as follows:
2597 -- line | actual code line here with Span somewhere
2598 -- | ^ here
2600 -- where the caret on the line points to location Span.Ptr
2602 -- SGR_Span is the SGR string to start the section of code in the span,
2603 -- that should be closed with SGR_Reset.
2605 -------------------------
2606 -- Write_Error_Summary --
2607 -------------------------
2609 procedure Write_Error_Summary is
2610 begin
2611 -- Extra blank line if error messages or source listing were output
2613 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
2614 then
2615 Write_Eol;
2616 end if;
2618 -- Message giving number of lines read and number of errors detected.
2619 -- This normally goes to Standard_Output. The exception is when brief
2620 -- mode is not set, verbose mode (or full list mode) is set, and
2621 -- there are errors. In this case we send the message to standard
2622 -- error to make sure that *something* appears on standard error
2623 -- in an error situation.
2625 if Total_Errors_Detected + Warnings_Detected /= 0
2626 and then not Brief_Output
2627 and then (Verbose_Mode or Full_List)
2628 then
2629 Set_Standard_Error;
2630 end if;
2632 -- Message giving total number of lines. Don't give this message if
2633 -- the Main_Source line is unknown (this happens in error situations,
2634 -- e.g. when integrated preprocessing fails).
2636 if Main_Source_File > No_Source_File then
2637 Write_Str (" ");
2638 Write_Int (Num_Source_Lines (Main_Source_File));
2640 if Num_Source_Lines (Main_Source_File) = 1 then
2641 Write_Str (" line: ");
2642 else
2643 Write_Str (" lines: ");
2644 end if;
2645 end if;
2647 if Total_Errors_Detected = 0 then
2648 Write_Str ("No errors");
2650 elsif Total_Errors_Detected = 1 then
2651 Write_Str ("1 error");
2653 else
2654 Write_Int (Total_Errors_Detected);
2655 Write_Str (" errors");
2656 end if;
2658 -- We now need to output warnings. When using -gnatwe, all warnings
2659 -- should be treated as errors, except for warnings originating from
2660 -- the use of the Compile_Time_Warning pragma. Another situation
2661 -- where a warning might be treated as an error is when the source
2662 -- code contains a Warning_As_Error pragma.
2663 -- When warnings are treated as errors, we still log them as
2664 -- warnings, but we add a message denoting how many of these warnings
2665 -- are also errors.
2667 declare
2668 Warnings_Count : constant Int := Warnings_Detected;
2670 Compile_Time_Warnings : Int;
2671 -- Number of warnings that come from a Compile_Time_Warning
2672 -- pragma.
2674 Non_Compile_Time_Warnings : Int;
2675 -- Number of warnings that do not come from a Compile_Time_Warning
2676 -- pragmas.
2678 begin
2679 if Warnings_Count > 0 then
2680 Write_Str (", ");
2681 Write_Int (Warnings_Count);
2682 Write_Str (" warning");
2684 if Warnings_Count > 1 then
2685 Write_Char ('s');
2686 end if;
2688 Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
2689 Non_Compile_Time_Warnings :=
2690 Warnings_Count - Compile_Time_Warnings;
2692 if Warning_Mode = Treat_As_Error
2693 and then Non_Compile_Time_Warnings > 0
2694 then
2695 Write_Str (" (");
2697 if Compile_Time_Warnings > 0 then
2698 Write_Int (Non_Compile_Time_Warnings);
2699 Write_Str (" ");
2700 end if;
2702 Write_Str ("treated as error");
2704 if Non_Compile_Time_Warnings > 1 then
2705 Write_Char ('s');
2706 end if;
2708 Write_Char (')');
2710 elsif Warnings_Treated_As_Errors > 0 then
2711 Write_Str (" (");
2713 if Warnings_Treated_As_Errors /= Warnings_Count then
2714 Write_Int (Warnings_Treated_As_Errors);
2715 Write_Str (" ");
2716 end if;
2718 Write_Str ("treated as error");
2720 if Warnings_Treated_As_Errors > 1 then
2721 Write_Str ("s");
2722 end if;
2724 Write_Str (")");
2725 end if;
2726 end if;
2727 end;
2729 if Info_Messages /= 0 then
2730 Write_Str (", ");
2731 Write_Int (Info_Messages);
2732 Write_Str (" info message");
2734 if Info_Messages > 1 then
2735 Write_Char ('s');
2736 end if;
2737 end if;
2739 Write_Eol;
2740 Set_Standard_Output;
2741 end Write_Error_Summary;
2743 ------------------
2744 -- Write_Header --
2745 ------------------
2747 procedure Write_Header (Sfile : Source_File_Index) is
2748 begin
2749 if Verbose_Mode or Full_List then
2750 if Original_Operating_Mode = Generate_Code then
2751 Write_Str ("Compiling: ");
2752 else
2753 Write_Str ("Checking: ");
2754 end if;
2756 Write_Name (Full_File_Name (Sfile));
2758 if not Debug_Flag_7 then
2759 Write_Eol;
2760 Write_Str ("Source file time stamp: ");
2761 Write_Time_Stamp (Sfile);
2762 Write_Eol;
2763 Write_Str ("Compiled at: " & Compilation_Time);
2764 end if;
2766 Write_Eol;
2767 end if;
2768 end Write_Header;
2770 ----------------------
2771 -- Write_Max_Errors --
2772 ----------------------
2774 procedure Write_Max_Errors is
2775 begin
2776 if Maximum_Messages /= 0 then
2777 if Warnings_Detected >= Maximum_Messages then
2778 Set_Standard_Error;
2779 Write_Line ("maximum number of warnings output");
2780 Write_Line ("any further warnings suppressed");
2781 Set_Standard_Output;
2782 end if;
2784 -- If too many errors print message
2786 if Total_Errors_Detected >= Maximum_Messages then
2787 Set_Standard_Error;
2788 Write_Line ("fatal error: maximum number of errors detected");
2789 Set_Standard_Output;
2790 end if;
2791 end if;
2792 end Write_Max_Errors;
2794 -----------------------------
2795 -- Write_Source_Code_Lines --
2796 -----------------------------
2798 procedure Write_Source_Code_Lines
2799 (Span : Source_Span;
2800 SGR_Span : String)
2802 function Get_Line_End
2803 (Buf : Source_Buffer_Ptr;
2804 Loc : Source_Ptr) return Source_Ptr;
2805 -- Get the source location for the end of the line in Buf for Loc. If
2806 -- Loc is past the end of Buf already, return Buf'Last.
2808 function Get_Line_Start
2809 (Buf : Source_Buffer_Ptr;
2810 Loc : Source_Ptr) return Source_Ptr;
2811 -- Get the source location for the start of the line in Buf for Loc
2813 function Image (X : Positive; Width : Positive) return String;
2814 -- Output number X over Width characters, with whitespace padding.
2815 -- Only output the low-order Width digits of X, if X is larger than
2816 -- Width digits.
2818 procedure Write_Buffer
2819 (Buf : Source_Buffer_Ptr;
2820 First : Source_Ptr;
2821 Last : Source_Ptr);
2822 -- Output the characters from First to Last position in Buf, using
2823 -- Write_Buffer_Char.
2825 procedure Write_Buffer_Char
2826 (Buf : Source_Buffer_Ptr;
2827 Loc : Source_Ptr);
2828 -- Output the characters at position Loc in Buf, translating ASCII.HT
2829 -- in a suitable number of spaces so that the output is not modified
2830 -- by starting in a different column that 1.
2832 procedure Write_Line_Marker
2833 (Num : Pos;
2834 Mark : Boolean;
2835 Width : Positive);
2836 -- Output the line number Num over Width characters, with possibly
2837 -- a Mark to denote the line with the main location when reporting
2838 -- a span over multiple lines.
2840 ------------------
2841 -- Get_Line_End --
2842 ------------------
2844 function Get_Line_End
2845 (Buf : Source_Buffer_Ptr;
2846 Loc : Source_Ptr) return Source_Ptr
2848 Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
2849 begin
2850 while Cur_Loc < Buf'Last
2851 and then Buf (Cur_Loc) /= ASCII.LF
2852 loop
2853 Cur_Loc := Cur_Loc + 1;
2854 end loop;
2856 return Cur_Loc;
2857 end Get_Line_End;
2859 --------------------
2860 -- Get_Line_Start --
2861 --------------------
2863 function Get_Line_Start
2864 (Buf : Source_Buffer_Ptr;
2865 Loc : Source_Ptr) return Source_Ptr
2867 Cur_Loc : Source_Ptr := Loc;
2868 begin
2869 while Cur_Loc > Buf'First
2870 and then Buf (Cur_Loc - 1) /= ASCII.LF
2871 loop
2872 Cur_Loc := Cur_Loc - 1;
2873 end loop;
2875 return Cur_Loc;
2876 end Get_Line_Start;
2878 -----------
2879 -- Image --
2880 -----------
2882 function Image (X : Positive; Width : Positive) return String is
2883 Str : String (1 .. Width);
2884 Curr : Natural := X;
2885 begin
2886 for J in reverse 1 .. Width loop
2887 if Curr > 0 then
2888 Str (J) := Character'Val (Character'Pos ('0') + Curr mod 10);
2889 Curr := Curr / 10;
2890 else
2891 Str (J) := ' ';
2892 end if;
2893 end loop;
2895 return Str;
2896 end Image;
2898 ------------------
2899 -- Write_Buffer --
2900 ------------------
2902 procedure Write_Buffer
2903 (Buf : Source_Buffer_Ptr;
2904 First : Source_Ptr;
2905 Last : Source_Ptr)
2907 begin
2908 for Loc in First .. Last loop
2909 Write_Buffer_Char (Buf, Loc);
2910 end loop;
2911 end Write_Buffer;
2913 -----------------------
2914 -- Write_Buffer_Char --
2915 -----------------------
2917 procedure Write_Buffer_Char
2918 (Buf : Source_Buffer_Ptr;
2919 Loc : Source_Ptr)
2921 begin
2922 -- If the character ASCII.HT is not the last one in the file,
2923 -- output as many spaces as the character represents in the
2924 -- original source file.
2926 if Buf (Loc) = ASCII.HT
2927 and then Loc < Buf'Last
2928 then
2929 for X in Get_Column_Number (Loc) ..
2930 Get_Column_Number (Loc + 1) - 1
2931 loop
2932 Write_Char (' ');
2933 end loop;
2935 -- Otherwise output the character itself
2937 else
2938 Write_Char (Buf (Loc));
2939 end if;
2940 end Write_Buffer_Char;
2942 -----------------------
2943 -- Write_Line_Marker --
2944 -----------------------
2946 procedure Write_Line_Marker
2947 (Num : Pos;
2948 Mark : Boolean;
2949 Width : Positive)
2951 begin
2952 Write_Str (Image (Positive (Num), Width => Width));
2953 Write_Str ((if Mark then ">" else " ") & "|");
2954 end Write_Line_Marker;
2956 -- Local variables
2958 Loc : constant Source_Ptr := Span.Ptr;
2959 Line : constant Pos := Pos (Get_Physical_Line_Number (Loc));
2961 Col : constant Natural := Natural (Get_Column_Number (Loc));
2963 Fst : constant Source_Ptr := Span.First;
2964 Line_Fst : constant Pos :=
2965 Pos (Get_Physical_Line_Number (Fst));
2966 Col_Fst : constant Natural :=
2967 Natural (Get_Column_Number (Fst));
2968 Lst : constant Source_Ptr := Span.Last;
2969 Line_Lst : constant Pos :=
2970 Pos (Get_Physical_Line_Number (Lst));
2971 Col_Lst : constant Natural :=
2972 Natural (Get_Column_Number (Lst));
2974 Width : constant := 5;
2975 Buf : Source_Buffer_Ptr;
2976 Cur_Loc : Source_Ptr := Fst;
2977 Cur_Line : Pos := Line_Fst;
2979 -- Start of processing for Write_Source_Code_Lines
2981 begin
2982 if Loc >= First_Source_Ptr then
2983 Buf := Source_Text (Get_Source_File_Index (Loc));
2985 -- First line of the span with actual source code. We retrieve
2986 -- the beginning of the line instead of relying on Col_Fst, as
2987 -- ASCII.HT characters change column numbers by possibly more
2988 -- than one.
2990 Write_Line_Marker
2991 (Cur_Line,
2992 Line_Fst /= Line_Lst and then Cur_Line = Line,
2993 Width);
2994 Write_Buffer (Buf, Get_Line_Start (Buf, Cur_Loc), Cur_Loc - 1);
2996 -- Output the first/caret/last lines of the span, as well as
2997 -- lines that are directly above/below the caret if they complete
2998 -- the gap with first/last lines, otherwise use ... to denote
2999 -- intermediate lines.
3001 -- If the span is on one line and not a simple source location,
3002 -- color it appropriately.
3004 if Line_Fst = Line_Lst
3005 and then Col_Fst /= Col_Lst
3006 then
3007 Write_Str (SGR_Span);
3008 end if;
3010 declare
3011 function Do_Write_Line (Cur_Line : Pos) return Boolean is
3012 (Cur_Line in Line_Fst | Line | Line_Lst
3013 or else
3014 (Cur_Line = Line_Fst + 1 and then Cur_Line = Line - 1)
3015 or else
3016 (Cur_Line = Line + 1 and then Cur_Line = Line_Lst - 1));
3017 begin
3018 while Cur_Loc <= Buf'Last
3019 and then Cur_Loc <= Lst
3020 loop
3021 if Do_Write_Line (Cur_Line) then
3022 Write_Buffer_Char (Buf, Cur_Loc);
3023 end if;
3025 if Buf (Cur_Loc) = ASCII.LF then
3026 Cur_Line := Cur_Line + 1;
3028 -- Output ... for skipped lines
3030 if (Cur_Line = Line
3031 and then not Do_Write_Line (Cur_Line - 1))
3032 or else
3033 (Cur_Line = Line + 1
3034 and then not Do_Write_Line (Cur_Line))
3035 then
3036 Write_Str ((1 .. Width - 3 => ' ') & "... | ...");
3037 Write_Eol;
3038 end if;
3040 -- Display the line marker if the line should be
3041 -- displayed.
3043 if Do_Write_Line (Cur_Line) then
3044 Write_Line_Marker
3045 (Cur_Line,
3046 Line_Fst /= Line_Lst and then Cur_Line = Line,
3047 Width);
3048 end if;
3049 end if;
3051 Cur_Loc := Cur_Loc + 1;
3052 end loop;
3053 end;
3055 if Line_Fst = Line_Lst
3056 and then Col_Fst /= Col_Lst
3057 then
3058 Write_Str (SGR_Reset);
3059 end if;
3061 -- Output the rest of the last line of the span
3063 Write_Buffer (Buf, Cur_Loc, Get_Line_End (Buf, Cur_Loc));
3065 -- If the span is on one line, output a second line with caret
3066 -- sign pointing to location Loc
3068 if Line_Fst = Line_Lst then
3069 Write_Str (String'(1 .. Width => ' '));
3070 Write_Str (" |");
3071 Write_Str (String'(1 .. Col_Fst - 1 => ' '));
3073 Write_Str (SGR_Span);
3075 Write_Str (String'(Col_Fst .. Col - 1 => '~'));
3076 Write_Str ("^");
3077 Write_Str (String'(Col + 1 .. Col_Lst => '~'));
3079 -- If the span is really just a location, add the word "here"
3080 -- to clarify this is the location for the message.
3082 if Col_Fst = Col_Lst then
3083 Write_Str (" here");
3084 end if;
3086 Write_Str (SGR_Reset);
3088 Write_Eol;
3089 end if;
3090 end if;
3091 end Write_Source_Code_Lines;
3093 -- Local variables
3095 E : Error_Msg_Id;
3096 Err_Flag : Boolean;
3097 Use_Prefix : Boolean;
3099 -- Start of processing for Output_Messages
3101 begin
3102 -- Error if Finalize has not been called
3104 if not Finalize_Called then
3105 raise Program_Error;
3106 end if;
3108 -- Reset current error source file if the main unit has a pragma
3109 -- Source_Reference. This ensures outputting the proper name of
3110 -- the source file in this situation.
3112 if Main_Source_File <= No_Source_File
3113 or else Num_SRef_Pragmas (Main_Source_File) /= 0
3114 then
3115 Current_Error_Source_File := No_Source_File;
3116 end if;
3118 if Opt.JSON_Output then
3119 Set_Standard_Error;
3121 E := First_Error_Msg;
3123 -- Find first printable message
3125 while E /= No_Error_Msg and then Errors.Table (E).Deleted loop
3126 E := Errors.Table (E).Next;
3127 end loop;
3129 Write_Char ('[');
3131 if E /= No_Error_Msg then
3133 Output_JSON_Message (E);
3135 E := Errors.Table (E).Next;
3137 while E /= No_Error_Msg loop
3139 -- Skip deleted messages.
3140 -- Also skip continuation messages, as they have already been
3141 -- printed along the message they're attached to.
3143 if not Errors.Table (E).Deleted
3144 and then not Errors.Table (E).Msg_Cont
3145 then
3146 Write_Char (',');
3147 Output_JSON_Message (E);
3148 end if;
3150 E := Errors.Table (E).Next;
3151 end loop;
3152 end if;
3154 Write_Char (']');
3156 Set_Standard_Output;
3158 -- Brief Error mode
3160 elsif Brief_Output or (not Full_List and not Verbose_Mode) then
3161 Set_Standard_Error;
3163 E := First_Error_Msg;
3164 while E /= No_Error_Msg loop
3166 -- If -gnatdF is used, separate main messages from previous
3167 -- messages with a newline (unless it is an info message) and
3168 -- make continuation messages follow the main message with only
3169 -- an indentation of two space characters, without repeating
3170 -- file:line:col: prefix.
3172 Use_Prefix :=
3173 not (Debug_Flag_FF and then Errors.Table (E).Msg_Cont);
3175 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
3177 if Debug_Flag_FF then
3178 if Errors.Table (E).Msg_Cont then
3179 Write_Str (" ");
3180 elsif not Errors.Table (E).Info then
3181 Write_Eol;
3182 end if;
3183 end if;
3185 if Use_Prefix then
3186 Write_Str (SGR_Locus);
3188 if Full_Path_Name_For_Brief_Errors then
3189 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
3190 else
3191 Write_Name (Reference_Name (Errors.Table (E).Sfile));
3192 end if;
3194 Write_Char (':');
3195 Write_Int (Int (Physical_To_Logical
3196 (Errors.Table (E).Line,
3197 Errors.Table (E).Sfile)));
3198 Write_Char (':');
3200 if Errors.Table (E).Col < 10 then
3201 Write_Char ('0');
3202 end if;
3204 Write_Int (Int (Errors.Table (E).Col));
3205 Write_Str (": ");
3207 Write_Str (SGR_Reset);
3208 end if;
3210 Output_Msg_Text (E);
3211 Write_Eol;
3213 -- If -gnatdF is used, write the source code line corresponding
3214 -- to the location of the main message (unless it is an info
3215 -- message). Also write the source code line corresponding to
3216 -- an insertion location inside continuation messages.
3218 if Debug_Flag_FF
3219 and then not Errors.Table (E).Info
3220 then
3221 if Errors.Table (E).Msg_Cont then
3222 declare
3223 Loc : constant Source_Ptr :=
3224 Errors.Table (E).Insertion_Sloc;
3225 begin
3226 if Loc /= No_Location then
3227 Write_Source_Code_Lines
3228 (To_Span (Loc), SGR_Span => SGR_Note);
3229 end if;
3230 end;
3232 else
3233 declare
3234 SGR_Span : constant String :=
3235 (if Errors.Table (E).Info then SGR_Note
3236 elsif Errors.Table (E).Warn
3237 and then not Errors.Table (E).Warn_Err
3238 then SGR_Warning
3239 else SGR_Error);
3240 begin
3241 Write_Source_Code_Lines
3242 (Errors.Table (E).Optr, SGR_Span);
3243 end;
3244 end if;
3245 end if;
3246 end if;
3248 E := Errors.Table (E).Next;
3249 end loop;
3251 Set_Standard_Output;
3252 end if;
3254 -- Full source listing case
3256 if Full_List then
3257 List_Pragmas_Index := 1;
3258 List_Pragmas_Mode := True;
3259 E := First_Error_Msg;
3261 -- Normal case, to stdout (copyright notice already output)
3263 if Full_List_File_Name = null then
3264 if not Debug_Flag_7 then
3265 Write_Eol;
3266 end if;
3268 -- Output to file
3270 else
3271 Create_List_File_Access.all (Full_List_File_Name.all);
3272 Set_Special_Output (Write_List_Info_Access.all'Access);
3274 -- Write copyright notice to file
3276 if not Debug_Flag_7 then
3277 Write_Str ("GNAT ");
3278 Write_Str (Gnat_Version_String);
3279 Write_Eol;
3280 Write_Str ("Copyright 1992-" &
3281 Current_Year &
3282 ", Free Software Foundation, Inc.");
3283 Write_Eol;
3284 end if;
3285 end if;
3287 -- First list extended main source file units with errors
3289 for U in Main_Unit .. Last_Unit loop
3290 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
3292 -- If debug flag d.m is set, only the main source is listed
3294 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
3296 -- If the unit of the entity does not come from source, it is
3297 -- an implicit subprogram declaration for a child subprogram.
3298 -- Do not emit errors for it, they are listed with the body.
3300 and then
3301 (No (Cunit_Entity (U))
3302 or else Comes_From_Source (Cunit_Entity (U))
3303 or else not Is_Subprogram (Cunit_Entity (U)))
3305 -- If the compilation unit associated with this unit does not
3306 -- come from source, it means it is an instantiation that should
3307 -- not be included in the source listing.
3309 and then Comes_From_Source (Cunit (U))
3310 then
3311 declare
3312 Sfile : constant Source_File_Index := Source_Index (U);
3314 begin
3315 Write_Eol;
3317 -- Only write the header if Sfile is known
3319 if Sfile > No_Source_File then
3320 Write_Header (Sfile);
3321 Write_Eol;
3322 end if;
3324 -- Normally, we don't want an "error messages from file"
3325 -- message when listing the entire file, so we set the
3326 -- current source file as the current error source file.
3327 -- However, the old style of doing things was to list this
3328 -- message if pragma Source_Reference is present, even for
3329 -- the main unit. Since the purpose of the -gnatd.m switch
3330 -- is to duplicate the old behavior, we skip the reset if
3331 -- this debug flag is set.
3333 if not Debug_Flag_Dot_M then
3334 Current_Error_Source_File := Sfile;
3335 end if;
3337 -- Only output the listing if Sfile is known, to avoid
3338 -- crashing the compiler.
3340 if Sfile > No_Source_File then
3341 for N in 1 .. Last_Source_Line (Sfile) loop
3342 while E /= No_Error_Msg
3343 and then Errors.Table (E).Deleted
3344 loop
3345 E := Errors.Table (E).Next;
3346 end loop;
3348 Err_Flag :=
3349 E /= No_Error_Msg
3350 and then Errors.Table (E).Line = N
3351 and then Errors.Table (E).Sfile = Sfile;
3353 Output_Source_Line (N, Sfile, Err_Flag);
3355 if Err_Flag then
3356 Output_Error_Msgs (E);
3358 if not Debug_Flag_2 then
3359 Write_Eol;
3360 end if;
3361 end if;
3362 end loop;
3363 end if;
3364 end;
3365 end if;
3366 end loop;
3368 -- Then output errors, if any, for subsidiary units not in the
3369 -- main extended unit.
3371 -- Note: if debug flag d.m set, include errors for any units other
3372 -- than the main unit in the extended source unit (e.g. spec and
3373 -- subunits for a body).
3375 while E /= No_Error_Msg
3376 and then (not In_Extended_Main_Source_Unit
3377 (Errors.Table (E).Sptr.Ptr)
3378 or else
3379 (Debug_Flag_Dot_M
3380 and then Get_Source_Unit
3381 (Errors.Table (E).Sptr.Ptr) /= Main_Unit))
3382 loop
3383 if Errors.Table (E).Deleted then
3384 E := Errors.Table (E).Next;
3386 else
3387 Write_Eol;
3388 Output_Source_Line
3389 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3390 Output_Error_Msgs (E);
3391 end if;
3392 end loop;
3394 -- If output to file, write extra copy of error summary to the
3395 -- output file, and then close it.
3397 if Full_List_File_Name /= null then
3398 Write_Error_Summary;
3399 Write_Max_Errors;
3400 Close_List_File_Access.all;
3401 Cancel_Special_Output;
3402 end if;
3403 end if;
3405 -- Verbose mode (error lines only with error flags). Normally this is
3406 -- ignored in full list mode, unless we are listing to a file, in which
3407 -- case we still generate -gnatv output to standard output.
3409 if Verbose_Mode
3410 and then (not Full_List or else Full_List_File_Name /= null)
3411 then
3412 Write_Eol;
3414 -- Output the header only when Main_Source_File is known
3416 if Main_Source_File > No_Source_File then
3417 Write_Header (Main_Source_File);
3418 end if;
3420 E := First_Error_Msg;
3422 -- Loop through error lines
3424 while E /= No_Error_Msg loop
3425 if Errors.Table (E).Deleted then
3426 E := Errors.Table (E).Next;
3427 else
3428 Write_Eol;
3429 Output_Source_Line
3430 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3431 Output_Error_Msgs (E);
3432 end if;
3433 end loop;
3434 end if;
3436 -- Output error summary if verbose or full list mode
3438 if Verbose_Mode or else Full_List then
3439 Write_Error_Summary;
3440 end if;
3442 if not Opt.JSON_Output then
3443 Write_Max_Errors;
3444 end if;
3446 if Warning_Mode = Treat_As_Error then
3447 declare
3448 Compile_Time_Pragma_Warnings : constant Nat :=
3449 Count_Compile_Time_Pragma_Warnings;
3450 Total : constant Int := Total_Errors_Detected + Warnings_Detected
3451 - Compile_Time_Pragma_Warnings;
3452 -- We need to protect against a negative Total here, because
3453 -- if a pragma Compile_Time_Warning occurs in dead code, it
3454 -- gets counted in Compile_Time_Pragma_Warnings but not in
3455 -- Warnings_Detected.
3456 begin
3457 Total_Errors_Detected := Int'Max (Total, 0);
3458 Warnings_Detected := Compile_Time_Pragma_Warnings;
3459 end;
3460 end if;
3461 end Output_Messages;
3463 ------------------------
3464 -- Output_Source_Line --
3465 ------------------------
3467 procedure Output_Source_Line
3468 (L : Physical_Line_Number;
3469 Sfile : Source_File_Index;
3470 Errs : Boolean)
3472 S : Source_Ptr;
3473 C : Character;
3475 Line_Number_Output : Boolean := False;
3476 -- Set True once line number is output
3478 Empty_Line : Boolean := True;
3479 -- Set False if line includes at least one character
3481 begin
3482 if Sfile /= Current_Error_Source_File then
3483 Write_Str ("==============Error messages for ");
3485 case Sinput.File_Type (Sfile) is
3486 when Sinput.Src =>
3487 Write_Str ("source");
3489 when Sinput.Config =>
3490 Write_Str ("configuration pragmas");
3492 when Sinput.Def =>
3493 Write_Str ("symbol definition");
3495 when Sinput.Preproc =>
3496 Write_Str ("preprocessing data");
3497 end case;
3499 Write_Str (" file: ");
3500 Write_Name (Full_File_Name (Sfile));
3501 Write_Eol;
3503 if Num_SRef_Pragmas (Sfile) > 0 then
3504 Write_Str ("--------------Line numbers from file: ");
3505 Write_Name (Full_Ref_Name (Sfile));
3506 Write_Str (" (starting at line ");
3507 Write_Int (Int (First_Mapped_Line (Sfile)));
3508 Write_Char (')');
3509 Write_Eol;
3510 end if;
3512 Current_Error_Source_File := Sfile;
3513 end if;
3515 if Errs or List_Pragmas_Mode then
3516 Output_Line_Number (Physical_To_Logical (L, Sfile));
3517 Line_Number_Output := True;
3518 end if;
3520 S := Line_Start (L, Sfile);
3522 loop
3523 C := Source_Text (Sfile) (S);
3524 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
3526 -- Deal with matching entry in List_Pragmas table
3528 if Full_List
3529 and then List_Pragmas_Index <= List_Pragmas.Last
3530 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
3531 then
3532 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
3533 when Page =>
3534 Write_Char (C);
3536 -- Ignore if on line with errors so that error flags
3537 -- get properly listed with the error line .
3539 if not Errs then
3540 Write_Char (ASCII.FF);
3541 end if;
3543 when List_On =>
3544 List_Pragmas_Mode := True;
3546 if not Line_Number_Output then
3547 Output_Line_Number (Physical_To_Logical (L, Sfile));
3548 Line_Number_Output := True;
3549 end if;
3551 Write_Char (C);
3553 when List_Off =>
3554 Write_Char (C);
3555 List_Pragmas_Mode := False;
3556 end case;
3558 List_Pragmas_Index := List_Pragmas_Index + 1;
3560 -- Normal case (no matching entry in List_Pragmas table)
3562 else
3563 if Errs or List_Pragmas_Mode then
3564 Write_Char (C);
3565 end if;
3566 end if;
3568 Empty_Line := False;
3569 S := S + 1;
3570 end loop;
3572 -- If we have output a source line, then add the line terminator, with
3573 -- training spaces preserved (so we output the line exactly as input).
3575 if Line_Number_Output then
3576 if Empty_Line then
3577 Write_Eol;
3578 else
3579 Write_Eol_Keep_Blanks;
3580 end if;
3581 end if;
3582 end Output_Source_Line;
3584 --------------------
3585 -- Paren_Required --
3586 --------------------
3588 function Paren_Required (N : Node_Id) return Boolean is
3589 begin
3590 -- In a qualifed_expression the expression part needs to be enclosed in
3591 -- parentheses.
3593 if Nkind (Parent (N)) = N_Qualified_Expression then
3594 return N = Expression (Parent (N));
3596 else
3597 return False;
3598 end if;
3599 end Paren_Required;
3601 -----------------------------
3602 -- Remove_Warning_Messages --
3603 -----------------------------
3605 procedure Remove_Warning_Messages (N : Node_Id) is
3607 function Check_For_Warning (N : Node_Id) return Traverse_Result;
3608 -- This function checks one node for a possible warning message
3610 procedure Check_All_Warnings is new Traverse_Proc (Check_For_Warning);
3611 -- This defines the traversal operation
3613 -----------------------
3614 -- Check_For_Warning --
3615 -----------------------
3617 function Check_For_Warning (N : Node_Id) return Traverse_Result is
3618 Loc : constant Source_Ptr := Sloc (N);
3619 E : Error_Msg_Id;
3621 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
3622 -- Returns True for a message that is to be removed. Also adjusts
3623 -- warning count appropriately.
3625 -------------------
3626 -- To_Be_Removed --
3627 -------------------
3629 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
3630 begin
3631 if E /= No_Error_Msg
3633 -- Don't remove if location does not match
3635 and then Errors.Table (E).Optr.Ptr = Loc
3637 -- Don't remove if not warning/info message. Note that we do
3638 -- not remove style messages here. They are warning messages
3639 -- but not ones we want removed in this context.
3641 and then (Errors.Table (E).Warn
3642 or else
3643 Errors.Table (E).Warn_Runtime_Raise)
3645 -- Don't remove unconditional messages
3647 and then not Errors.Table (E).Uncond
3648 then
3649 if Errors.Table (E).Warn then
3650 Warnings_Detected := Warnings_Detected - 1;
3651 end if;
3653 -- When warning about a runtime exception has been escalated
3654 -- into error, the starting message has increased the total
3655 -- errors counter, so here we decrease this counter.
3657 if Errors.Table (E).Warn_Runtime_Raise
3658 and then not Errors.Table (E).Msg_Cont
3659 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
3660 then
3661 Total_Errors_Detected := Total_Errors_Detected - 1;
3662 end if;
3664 return True;
3666 -- No removal required
3668 else
3669 return False;
3670 end if;
3671 end To_Be_Removed;
3673 -- Start of processing for Check_For_Warnings
3675 begin
3676 while To_Be_Removed (First_Error_Msg) loop
3677 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
3678 end loop;
3680 if First_Error_Msg = No_Error_Msg then
3681 Last_Error_Msg := No_Error_Msg;
3682 end if;
3684 E := First_Error_Msg;
3685 while E /= No_Error_Msg loop
3686 while To_Be_Removed (Errors.Table (E).Next) loop
3687 Errors.Table (E).Next :=
3688 Errors.Table (Errors.Table (E).Next).Next;
3690 if Errors.Table (E).Next = No_Error_Msg then
3691 Last_Error_Msg := E;
3692 end if;
3693 end loop;
3695 E := Errors.Table (E).Next;
3696 end loop;
3698 -- Warnings may have been posted on subexpressions of original tree
3700 if Nkind (N) = N_Raise_Constraint_Error
3701 and then Is_Rewrite_Substitution (N)
3702 and then No (Condition (N))
3703 then
3704 Check_All_Warnings (Original_Node (N));
3705 end if;
3707 return OK;
3708 end Check_For_Warning;
3710 -- Start of processing for Remove_Warning_Messages
3712 begin
3713 if Warnings_Detected /= 0 then
3714 Check_All_Warnings (N);
3715 end if;
3716 end Remove_Warning_Messages;
3718 procedure Remove_Warning_Messages (L : List_Id) is
3719 Stat : Node_Id;
3720 begin
3721 Stat := First (L);
3722 while Present (Stat) loop
3723 Remove_Warning_Messages (Stat);
3724 Next (Stat);
3725 end loop;
3726 end Remove_Warning_Messages;
3728 ----------------------
3729 -- Adjust_Name_Case --
3730 ----------------------
3732 procedure Adjust_Name_Case
3733 (Buf : in out Bounded_String;
3734 Loc : Source_Ptr)
3736 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
3737 Sbuffer : Source_Buffer_Ptr;
3738 Ref_Ptr : Integer;
3739 Src_Ptr : Source_Ptr;
3741 begin
3742 -- We have an all lower case name from Namet, and now we want to set
3743 -- the appropriate case. If possible we copy the actual casing from
3744 -- the source. If not we use standard identifier casing.
3746 Ref_Ptr := 1;
3747 Src_Ptr := Loc;
3749 -- For standard locations, always use mixed case
3751 if Loc <= No_Location then
3752 Set_Casing (Buf, Mixed_Case);
3754 else
3755 -- Determine if the reference we are dealing with corresponds to text
3756 -- at the point of the error reference. This will often be the case
3757 -- for simple identifier references, and is the case where we can
3758 -- copy the casing from the source.
3760 Sbuffer := Source_Text (Src_Ind);
3762 while Ref_Ptr <= Buf.Length loop
3763 exit when
3764 Fold_Lower (Sbuffer (Src_Ptr)) /=
3765 Fold_Lower (Buf.Chars (Ref_Ptr));
3766 Ref_Ptr := Ref_Ptr + 1;
3767 Src_Ptr := Src_Ptr + 1;
3768 end loop;
3770 -- If we get through the loop without a mismatch, then output the
3771 -- name the way it is cased in the source program.
3773 if Ref_Ptr > Buf.Length then
3774 Src_Ptr := Loc;
3776 for J in 1 .. Buf.Length loop
3777 Buf.Chars (J) := Sbuffer (Src_Ptr);
3778 Src_Ptr := Src_Ptr + 1;
3779 end loop;
3781 -- Otherwise set the casing using the default identifier casing
3783 else
3784 Set_Casing (Buf, Identifier_Casing (Src_Ind));
3785 end if;
3786 end if;
3787 end Adjust_Name_Case;
3789 ---------------------------
3790 -- Set_Identifier_Casing --
3791 ---------------------------
3793 procedure Set_Identifier_Casing
3794 (Identifier_Name : System.Address;
3795 File_Name : System.Address)
3797 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
3798 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
3799 Flen : Natural;
3801 Desired_Case : Casing_Type := Mixed_Case;
3802 -- Casing required for result. Default value of Mixed_Case is used if
3803 -- for some reason we cannot find the right file name in the table.
3805 begin
3806 -- Get length of file name
3808 Flen := 0;
3809 while File (Flen + 1) /= ASCII.NUL loop
3810 Flen := Flen + 1;
3811 end loop;
3813 -- Loop through file names to find matching one. This is a bit slow, but
3814 -- we only do it in error situations so it is not so terrible. Note that
3815 -- if the loop does not exit, then the desired case will be left set to
3816 -- Mixed_Case, this can happen if the name was not in canonical form.
3818 for J in 1 .. Last_Source_File loop
3819 Get_Name_String (Full_Debug_Name (J));
3821 if Name_Len = Flen
3822 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
3823 then
3824 Desired_Case := Identifier_Casing (J);
3825 exit;
3826 end if;
3827 end loop;
3829 -- Copy identifier as given to Name_Buffer
3831 for J in Name_Buffer'Range loop
3832 Name_Buffer (J) := Ident (J);
3834 if Name_Buffer (J) = ASCII.NUL then
3835 Name_Len := J - 1;
3836 exit;
3837 end if;
3838 end loop;
3840 Set_Casing (Desired_Case);
3841 end Set_Identifier_Casing;
3843 -----------------------
3844 -- Set_Ignore_Errors --
3845 -----------------------
3847 procedure Set_Ignore_Errors (To : Boolean) is
3848 begin
3849 Errors_Must_Be_Ignored := To;
3850 end Set_Ignore_Errors;
3852 ------------------------------
3853 -- Set_Msg_Insertion_Column --
3854 ------------------------------
3856 procedure Set_Msg_Insertion_Column is
3857 begin
3858 if RM_Column_Check then
3859 Set_Msg_Str (" in column ");
3860 Set_Msg_Int (Int (Error_Msg_Col) + 1);
3861 end if;
3862 end Set_Msg_Insertion_Column;
3864 ----------------------------
3865 -- Set_Msg_Insertion_Node --
3866 ----------------------------
3868 procedure Set_Msg_Insertion_Node is
3869 pragma Assert (Present (Error_Msg_Node_1));
3870 K : Node_Kind;
3872 begin
3873 Suppress_Message := Error_Msg_Node_1 in Error | Any_Type;
3875 if Error_Msg_Node_1 = Error then
3876 Set_Msg_Blank;
3877 Set_Msg_Str ("<error>");
3879 elsif Error_Msg_Node_1 = Standard_Void_Type then
3880 Set_Msg_Blank;
3881 Set_Msg_Str ("procedure name");
3883 elsif Nkind (Error_Msg_Node_1) in N_Entity
3884 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
3885 then
3886 Set_Msg_Blank;
3887 Set_Msg_Str ("access to subprogram");
3889 else
3890 Set_Msg_Blank_Conditional;
3892 -- Output name
3894 K := Nkind (Error_Msg_Node_1);
3896 -- Skip quotes in the operator case, because the operator will supply
3897 -- the required quotes.
3899 if K in N_Op | N_Operator_Symbol | N_Defining_Operator_Symbol
3900 or else (K in N_Identifier | N_Defining_Identifier
3901 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
3902 then
3903 Set_Msg_Node (Error_Msg_Node_1);
3905 -- Normal case, not an operator, surround with quotes
3907 else
3908 Set_Msg_Quote;
3909 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
3910 Set_Msg_Node (Error_Msg_Node_1);
3911 Set_Msg_Quote;
3912 end if;
3913 end if;
3915 -- The following assignment ensures that further ampersand insertion
3916 -- characters will correspond to the Error_Msg_Node_# parameter.
3918 Error_Msg_Node_1 := Error_Msg_Node_2;
3919 Error_Msg_Node_2 := Error_Msg_Node_3;
3920 Error_Msg_Node_3 := Error_Msg_Node_4;
3921 Error_Msg_Node_4 := Error_Msg_Node_5;
3922 Error_Msg_Node_5 := Error_Msg_Node_6;
3923 end Set_Msg_Insertion_Node;
3925 --------------------------------------
3926 -- Set_Msg_Insertion_Type_Reference --
3927 --------------------------------------
3929 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
3930 Ent : Entity_Id;
3932 begin
3933 Set_Msg_Blank;
3935 if Error_Msg_Node_1 = Standard_Void_Type then
3936 Set_Msg_Str ("package or procedure name");
3937 return;
3939 elsif Error_Msg_Node_1 = Standard_Exception_Type then
3940 Set_Msg_Str ("exception name");
3941 return;
3943 elsif Error_Msg_Node_1 = Any_Array
3944 or else Error_Msg_Node_1 = Any_Boolean
3945 or else Error_Msg_Node_1 = Any_Character
3946 or else Error_Msg_Node_1 = Any_Composite
3947 or else Error_Msg_Node_1 = Any_Discrete
3948 or else Error_Msg_Node_1 = Any_Fixed
3949 or else Error_Msg_Node_1 = Any_Integer
3950 or else Error_Msg_Node_1 = Any_Modular
3951 or else Error_Msg_Node_1 = Any_Numeric
3952 or else Error_Msg_Node_1 = Any_Real
3953 or else Error_Msg_Node_1 = Any_Scalar
3954 or else Error_Msg_Node_1 = Any_String
3955 then
3956 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
3957 Set_Msg_Name_Buffer;
3958 return;
3960 elsif Error_Msg_Node_1 = Universal_Integer then
3961 Set_Msg_Str ("type universal integer");
3962 return;
3964 elsif Error_Msg_Node_1 = Universal_Real then
3965 Set_Msg_Str ("type universal real");
3966 return;
3968 elsif Error_Msg_Node_1 = Universal_Fixed then
3969 Set_Msg_Str ("type universal fixed");
3970 return;
3972 elsif Error_Msg_Node_1 = Universal_Access then
3973 Set_Msg_Str ("type universal access");
3974 return;
3975 end if;
3977 -- Special case of anonymous array
3979 if Nkind (Error_Msg_Node_1) in N_Entity
3980 and then Is_Array_Type (Error_Msg_Node_1)
3981 and then Present (Related_Array_Object (Error_Msg_Node_1))
3982 then
3983 Set_Msg_Str ("type of ");
3984 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
3985 Set_Msg_Str (" declared");
3986 Set_Msg_Insertion_Line_Number
3987 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
3988 return;
3989 end if;
3991 -- If we fall through, it is not a special case, so first output
3992 -- the name of the type, preceded by private for a private type
3994 if Is_Private_Type (Error_Msg_Node_1) then
3995 Set_Msg_Str ("private type ");
3996 else
3997 Set_Msg_Str ("type ");
3998 end if;
4000 Ent := Error_Msg_Node_1;
4002 if Is_Internal_Name (Chars (Ent)) then
4003 Unwind_Internal_Type (Ent);
4004 end if;
4006 -- Types in Standard are displayed as "Standard.name"
4008 if Sloc (Ent) <= Standard_Location then
4009 Set_Msg_Quote;
4010 Set_Msg_Str ("Standard.");
4011 Set_Msg_Node (Ent);
4012 Add_Class;
4013 Set_Msg_Quote;
4015 -- Types in other language defined units are displayed as
4016 -- "package-name.type-name"
4018 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
4019 Get_Unqualified_Decoded_Name_String
4020 (Unit_Name (Get_Source_Unit (Ent)));
4021 Name_Len := Name_Len - 2;
4022 Set_Msg_Blank_Conditional;
4023 Set_Msg_Quote;
4024 Set_Casing (Mixed_Case);
4025 Set_Msg_Name_Buffer;
4026 Set_Msg_Char ('.');
4027 Set_Casing (Mixed_Case);
4028 Set_Msg_Node (Ent);
4029 Add_Class;
4030 Set_Msg_Quote;
4032 -- All other types display as "type name" defined at line xxx
4033 -- possibly qualified if qualification is requested.
4035 else
4036 Set_Msg_Quote;
4037 Set_Qualification (Error_Msg_Qual_Level, Ent);
4038 Set_Msg_Node (Ent);
4039 Add_Class;
4041 -- If we did not print a name (e.g. in the case of an anonymous
4042 -- subprogram type), there is no name to print, so remove quotes.
4044 if Buffer_Ends_With ('"') then
4045 Buffer_Remove ('"');
4046 else
4047 Set_Msg_Quote;
4048 end if;
4049 end if;
4051 -- If the original type did not come from a predefined file, add the
4052 -- location where the type was defined.
4054 if Sloc (Error_Msg_Node_1) > Standard_Location
4055 and then
4056 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
4057 then
4058 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
4059 Set_Msg_Str (" defined");
4060 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
4062 -- If it did come from a predefined file, deal with the case where
4063 -- this was a file with a generic instantiation from elsewhere.
4065 else
4066 if Sloc (Error_Msg_Node_1) > Standard_Location then
4067 declare
4068 Iloc : constant Source_Ptr :=
4069 Instantiation_Location (Sloc (Error_Msg_Node_1));
4071 begin
4072 if Iloc /= No_Location
4073 and then not Suppress_Instance_Location
4074 then
4075 Set_Msg_Str (" from instance");
4076 Set_Msg_Insertion_Line_Number (Iloc, Flag);
4077 end if;
4078 end;
4079 end if;
4080 end if;
4081 end Set_Msg_Insertion_Type_Reference;
4083 ---------------------------------
4084 -- Set_Msg_Insertion_Unit_Name --
4085 ---------------------------------
4087 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
4088 begin
4089 if Error_Msg_Unit_1 = No_Unit_Name then
4090 null;
4092 elsif Error_Msg_Unit_1 = Error_Unit_Name then
4093 Set_Msg_Blank;
4094 Set_Msg_Str ("<error>");
4096 else
4097 Get_Unit_Name_String (Global_Name_Buffer, Error_Msg_Unit_1, Suffix);
4098 Set_Msg_Blank;
4099 Set_Msg_Quote;
4100 Set_Msg_Name_Buffer;
4101 Set_Msg_Quote;
4102 end if;
4104 -- The following assignment ensures that a second percent insertion
4105 -- character will correspond to the Error_Msg_Unit_2 parameter.
4107 Error_Msg_Unit_1 := Error_Msg_Unit_2;
4108 end Set_Msg_Insertion_Unit_Name;
4110 ------------------
4111 -- Set_Msg_Node --
4112 ------------------
4114 procedure Set_Msg_Node (Node : Node_Id) is
4115 Loc : Source_Ptr;
4116 Ent : Entity_Id;
4117 Nam : Name_Id;
4119 begin
4120 case Nkind (Node) is
4121 when N_Designator =>
4122 Set_Msg_Node (Name (Node));
4123 Set_Msg_Char ('.');
4124 Set_Msg_Node (Identifier (Node));
4125 return;
4127 when N_Defining_Program_Unit_Name =>
4128 Set_Msg_Node (Name (Node));
4129 Set_Msg_Char ('.');
4130 Set_Msg_Node (Defining_Identifier (Node));
4131 return;
4133 when N_Expanded_Name
4134 | N_Selected_Component
4136 Set_Msg_Node (Prefix (Node));
4137 Set_Msg_Char ('.');
4138 Set_Msg_Node (Selector_Name (Node));
4139 return;
4141 when others =>
4142 null;
4143 end case;
4145 -- The only remaining possibilities are identifiers, defining
4146 -- identifiers, pragmas, and pragma argument associations.
4148 if Nkind (Node) = N_Pragma then
4149 Nam := Pragma_Name (Node);
4150 Loc := Sloc (Node);
4152 -- The other cases have Chars fields
4154 -- First deal with internal names, which generally represent something
4155 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4156 -- something with a Chars field that is not an internal name, use that.
4158 elsif Is_Internal_Name (Chars (Node))
4159 and then Nkind (Original_Node (Node)) in N_Has_Chars
4160 and then not Is_Internal_Name (Chars (Original_Node (Node)))
4161 then
4162 Nam := Chars (Original_Node (Node));
4163 Loc := Sloc (Original_Node (Node));
4165 -- Another shot for internal names, in the case of internal type names,
4166 -- we try to find a reasonable representation for the external name.
4168 elsif Is_Internal_Name (Chars (Node))
4169 and then
4170 ((Is_Entity_Name (Node)
4171 and then Present (Entity (Node))
4172 and then Is_Type (Entity (Node)))
4173 or else
4174 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
4175 then
4176 if Nkind (Node) = N_Identifier then
4177 Ent := Entity (Node);
4178 else
4179 Ent := Node;
4180 end if;
4182 Loc := Sloc (Ent);
4184 -- If the type is the designated type of an access_to_subprogram,
4185 -- then there is no name to provide in the call.
4187 if Ekind (Ent) = E_Subprogram_Type then
4188 return;
4190 -- Otherwise, we will be able to find some kind of name to output
4192 else
4193 Unwind_Internal_Type (Ent);
4194 Nam := Chars (Ent);
4195 end if;
4197 -- If not internal name, or if we could not find a reasonable possible
4198 -- substitution for the internal name, just use name in Chars field.
4200 else
4201 Nam := Chars (Node);
4202 Loc := Sloc (Node);
4203 end if;
4205 -- At this stage, the name to output is in Nam
4207 Get_Unqualified_Decoded_Name_String (Nam);
4209 -- Remove trailing upper case letters from the name (useful for
4210 -- dealing with some cases of internal names).
4212 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
4213 Name_Len := Name_Len - 1;
4214 end loop;
4216 -- If we have any of the names from standard that start with the
4217 -- characters "any " (e.g. Any_Type), then kill the message since
4218 -- almost certainly it is a junk cascaded message.
4220 if Name_Len > 4
4221 and then Name_Buffer (1 .. 4) = "any "
4222 then
4223 Kill_Message := True;
4224 end if;
4226 -- If we still have an internal name, kill the message (will only
4227 -- work if we already had errors!)
4229 if Is_Internal_Name then
4230 Kill_Message := True;
4231 end if;
4232 -- Remaining step is to adjust casing and possibly add 'Class
4234 Adjust_Name_Case (Global_Name_Buffer, Loc);
4235 Set_Msg_Name_Buffer;
4236 Add_Class;
4237 end Set_Msg_Node;
4239 ------------------
4240 -- Set_Msg_Text --
4241 ------------------
4243 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
4244 C : Character; -- Current character
4245 P : Natural; -- Current index;
4247 procedure Skip_Msg_Insertion_Warning (C : Character);
4248 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4249 -- sequences using < instead of ?). The caller has already bumped
4250 -- the pointer past the initial ? or < and C is set to this initial
4251 -- character (? or <). This procedure skips past the rest of the
4252 -- sequence. We do not need to set Msg_Insertion_Char, since this
4253 -- was already done during the message prescan.
4254 -- No validity check is performed as the insertion sequence is
4255 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4256 -- erroutc.adb for the validity checks.
4258 --------------------------------
4259 -- Skip_Msg_Insertion_Warning --
4260 --------------------------------
4262 procedure Skip_Msg_Insertion_Warning (C : Character) is
4263 begin
4264 if P <= Text'Last and then Text (P) = C then
4265 P := P + 1;
4267 elsif P < Text'Last and then Text (P + 1) = C
4268 and then Text (P) in 'a' .. 'z' | 'A' .. 'Z' |
4269 '0' .. '9' | '*' | '$'
4270 then
4271 P := P + 2;
4273 elsif P + 1 < Text'Last and then Text (P + 2) = C
4274 and then Text (P) in '.' | '_'
4275 and then Text (P + 1) in 'a' .. 'z'
4276 then
4277 P := P + 3;
4278 end if;
4279 end Skip_Msg_Insertion_Warning;
4281 -- Start of processing for Set_Msg_Text
4283 begin
4284 Manual_Quote_Mode := False;
4285 Msglen := 0;
4286 Flag_Source := Get_Source_File_Index (Flag);
4288 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4289 -- will be used (Info field in error message object) to put back the
4290 -- string when it is printed. We need to do this, or we get confused
4291 -- with instantiation continuations.
4293 if Text'Length > 6
4294 and then Text (Text'First .. Text'First + 5) = "info: "
4295 then
4296 P := Text'First + 6;
4297 else
4298 P := Text'First;
4299 end if;
4301 -- Loop through characters of message
4303 while P <= Text'Last loop
4304 C := Text (P);
4305 P := P + 1;
4307 -- Check for insertion character or sequence
4309 case C is
4310 when '%' =>
4311 if P <= Text'Last and then Text (P) = '%' then
4312 P := P + 1;
4313 Set_Msg_Insertion_Name_Literal;
4314 else
4315 Set_Msg_Insertion_Name;
4316 end if;
4318 when '$' =>
4319 if P <= Text'Last and then Text (P) = '$' then
4320 P := P + 1;
4321 Set_Msg_Insertion_Unit_Name (Suffix => False);
4322 else
4323 Set_Msg_Insertion_Unit_Name;
4324 end if;
4326 when '{' =>
4327 Set_Msg_Insertion_File_Name;
4329 when '}' =>
4330 Set_Msg_Insertion_Type_Reference (Flag);
4332 when '*' =>
4333 Set_Msg_Insertion_Reserved_Name;
4335 when '&' =>
4336 Set_Msg_Insertion_Node;
4338 when '#' =>
4339 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
4341 when '\' =>
4342 Continuation := True;
4344 if P <= Text'Last and then Text (P) = '\' then
4345 Continuation_New_Line := True;
4346 P := P + 1;
4347 end if;
4349 when '@' =>
4350 Set_Msg_Insertion_Column;
4352 when '>' =>
4353 Set_Msg_Insertion_Run_Time_Name;
4355 when '^' =>
4356 Set_Msg_Insertion_Uint;
4358 when '`' =>
4359 Manual_Quote_Mode := not Manual_Quote_Mode;
4360 Set_Msg_Char ('"');
4362 when '!' =>
4363 null; -- already dealt with
4365 when '?' =>
4366 Skip_Msg_Insertion_Warning ('?');
4368 when '<' =>
4369 Skip_Msg_Insertion_Warning ('<');
4371 when '|' =>
4372 null; -- already dealt with
4374 when ''' =>
4375 Set_Msg_Char (Text (P));
4376 P := P + 1;
4378 when '~' =>
4379 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
4381 -- Upper case letter
4383 when 'A' .. 'Z' =>
4385 -- Start of reserved word if two or more
4387 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
4388 P := P - 1;
4389 Set_Msg_Insertion_Reserved_Word (Text, P);
4391 -- Single upper case letter is just inserted
4393 else
4394 Set_Msg_Char (C);
4395 end if;
4397 -- '[' (will be/would have been raised at run time)
4399 when '[' =>
4401 -- "[]" (insertion of error code)
4403 if P <= Text'Last and then Text (P) = ']' then
4404 P := P + 1;
4405 Set_Msg_Insertion_Code;
4407 else
4408 -- Switch the message from a warning to an error if the flag
4409 -- -gnatwE is specified to treat run-time exception warnings
4410 -- as errors.
4412 if Is_Warning_Msg
4413 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
4414 then
4415 Is_Warning_Msg := False;
4416 Is_Runtime_Raise := True;
4417 end if;
4419 if Is_Warning_Msg then
4420 Set_Msg_Str ("will be raised at run time");
4421 else
4422 Set_Msg_Str ("would have been raised at run time");
4423 end if;
4424 end if;
4426 -- ']' (may be/might have been raised at run time)
4428 when ']' =>
4429 if Is_Warning_Msg then
4430 Set_Msg_Str ("may be raised at run time");
4431 else
4432 Set_Msg_Str ("might have been raised at run time");
4433 end if;
4435 -- Normal character with no special treatment
4437 when others =>
4438 Set_Msg_Char (C);
4439 end case;
4440 end loop;
4441 end Set_Msg_Text;
4443 ----------------
4444 -- Set_Posted --
4445 ----------------
4447 procedure Set_Posted (N : Node_Id) is
4448 P : Node_Id;
4450 begin
4451 if Is_Serious_Error then
4453 -- We always set Error_Posted on the node itself
4455 Set_Error_Posted (N);
4457 -- If it is a subexpression, then set Error_Posted on parents up to
4458 -- and including the first non-subexpression construct. This helps
4459 -- avoid cascaded error messages within a single expression.
4461 P := N;
4462 loop
4463 P := Parent (P);
4464 exit when No (P);
4465 Set_Error_Posted (P);
4466 exit when Nkind (P) not in N_Subexpr;
4467 end loop;
4469 if Nkind (P) in N_Pragma_Argument_Association
4470 | N_Component_Association
4471 | N_Discriminant_Association
4472 | N_Generic_Association
4473 | N_Parameter_Association
4474 then
4475 Set_Error_Posted (Parent (P));
4476 end if;
4478 -- A special check, if we just posted an error on an attribute
4479 -- definition clause, then also set the entity involved as posted.
4480 -- For example, this stops complaining about the alignment after
4481 -- complaining about the size, which is likely to be useless.
4483 if Nkind (P) = N_Attribute_Definition_Clause then
4484 if Is_Entity_Name (Name (P)) then
4485 Set_Error_Posted (Entity (Name (P)));
4486 end if;
4487 end if;
4488 end if;
4489 end Set_Posted;
4491 -----------------------
4492 -- Set_Qualification --
4493 -----------------------
4495 procedure Set_Qualification (N : Nat; E : Entity_Id) is
4496 begin
4497 if N /= 0 and then Scope (E) /= Standard_Standard then
4498 Set_Qualification (N - 1, Scope (E));
4499 Set_Msg_Node (Scope (E));
4500 Set_Msg_Char ('.');
4501 end if;
4502 end Set_Qualification;
4504 -------------------------------------
4505 -- Should_Ignore_Pragma_SPARK_Mode --
4506 -------------------------------------
4508 function Should_Ignore_Pragma_SPARK_Mode return Boolean is
4509 begin
4510 return Get_Name_Table_Boolean3 (Name_SPARK_Mode);
4511 end Should_Ignore_Pragma_SPARK_Mode;
4513 ------------------------
4514 -- Special_Msg_Delete --
4515 ------------------------
4517 -- Is it really right to have all this specialized knowledge in errout?
4519 function Special_Msg_Delete
4520 (Msg : String;
4521 N : Node_Or_Entity_Id;
4522 E : Node_Or_Entity_Id) return Boolean
4524 begin
4525 -- Never delete messages in -gnatdO mode
4527 if Debug_Flag_OO then
4528 return False;
4530 -- Processing for "Size too small" messages
4532 elsif Is_Size_Too_Small_Message (Msg) then
4534 -- Suppress "size too small" errors in CodePeer mode, since code may
4535 -- be analyzed in a different configuration than the one used for
4536 -- compilation. Even when the configurations match, this message
4537 -- may be issued on correct code, because pragma Pack is ignored
4538 -- in CodePeer mode.
4540 if CodePeer_Mode then
4541 return True;
4543 -- When a size is wrong for a frozen type there is no explicit size
4544 -- clause, and other errors have occurred, suppress the message,
4545 -- since it is likely that this size error is a cascaded result of
4546 -- other errors. The reason we eliminate unfrozen types is that
4547 -- messages issued before the freeze type are for sure OK.
4549 elsif Nkind (N) in N_Entity
4550 and then Is_Frozen (E)
4551 and then Serious_Errors_Detected > 0
4552 and then Nkind (N) /= N_Component_Clause
4553 and then Nkind (Parent (N)) /= N_Component_Clause
4554 and then
4555 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
4556 and then
4557 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
4558 and then
4559 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
4560 then
4561 return True;
4562 end if;
4563 end if;
4565 -- All special tests complete, so go ahead with message
4567 return False;
4568 end Special_Msg_Delete;
4570 -----------------
4571 -- SPARK_Msg_N --
4572 -----------------
4574 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
4575 begin
4576 -- If SPARK_Mode is Off, we do not report SPARK legality errors to give
4577 -- the flexibility to opt out of SPARK checking completely. We do the
4578 -- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
4579 -- for tools to ignore SPARK checking even on SPARK code.
4581 if SPARK_Mode /= Off
4582 and then not Should_Ignore_Pragma_SPARK_Mode
4583 then
4584 Error_Msg_N (Msg, N);
4585 end if;
4586 end SPARK_Msg_N;
4588 ------------------
4589 -- SPARK_Msg_NE --
4590 ------------------
4592 procedure SPARK_Msg_NE
4593 (Msg : String;
4594 N : Node_Or_Entity_Id;
4595 E : Node_Or_Entity_Id)
4597 begin
4598 if SPARK_Mode /= Off
4599 and then not Should_Ignore_Pragma_SPARK_Mode
4600 then
4601 Error_Msg_NE (Msg, N, E);
4602 end if;
4603 end SPARK_Msg_NE;
4605 --------------------------
4606 -- Unwind_Internal_Type --
4607 --------------------------
4609 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
4610 Derived : Boolean := False;
4611 Mchar : Character;
4612 Old_Ent : Entity_Id;
4614 begin
4615 -- Undo placement of a quote, since we will put it back later
4617 Mchar := Msg_Buffer (Msglen);
4619 if Mchar = '"' then
4620 Msglen := Msglen - 1;
4621 end if;
4623 -- The loop here deals with recursive types, we are trying to find a
4624 -- related entity that is not an implicit type. Note that the check with
4625 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4626 -- "type derived from" message more than once in the case where we climb
4627 -- up multiple levels.
4629 Find : loop
4630 Old_Ent := Ent;
4632 -- Implicit access type, use directly designated type In Ada 2005,
4633 -- the designated type may be an anonymous access to subprogram, in
4634 -- which case we can only point to its definition.
4636 if Is_Access_Type (Ent) then
4637 if Ekind (Ent) = E_Access_Subprogram_Type
4638 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
4639 or else Is_Access_Protected_Subprogram_Type (Ent)
4640 then
4641 Ent := Directly_Designated_Type (Ent);
4643 if not Comes_From_Source (Ent) then
4644 if Buffer_Ends_With ("type ") then
4645 Buffer_Remove ("type ");
4646 end if;
4647 end if;
4649 if Ekind (Ent) = E_Function then
4650 Set_Msg_Str ("access to function ");
4651 elsif Ekind (Ent) = E_Procedure then
4652 Set_Msg_Str ("access to procedure ");
4653 else
4654 Set_Msg_Str ("access to subprogram");
4655 end if;
4657 exit Find;
4659 -- Type is access to object, named or anonymous
4661 else
4662 Set_Msg_Str ("access to ");
4663 Ent := Directly_Designated_Type (Ent);
4664 end if;
4666 -- Classwide type
4668 elsif Is_Class_Wide_Type (Ent) then
4669 Class_Flag := True;
4670 Ent := Root_Type (Ent);
4672 -- Use base type if this is a subtype
4674 elsif Ent /= Base_Type (Ent) then
4675 Buffer_Remove ("type ");
4677 -- Avoid duplication "subtype of subtype of", and also replace
4678 -- "derived from subtype of" simply by "derived from"
4680 if not Buffer_Ends_With ("subtype of ")
4681 and then not Buffer_Ends_With ("derived from ")
4682 then
4683 Set_Msg_Str ("subtype of ");
4684 end if;
4686 Ent := Base_Type (Ent);
4688 -- If this is a base type with a first named subtype, use the first
4689 -- named subtype instead. This is not quite accurate in all cases,
4690 -- but it makes too much noise to be accurate and add 'Base in all
4691 -- cases. Note that we only do this is the first named subtype is not
4692 -- itself an internal name. This avoids the obvious loop (subtype ->
4693 -- basetype -> subtype) which would otherwise occur).
4695 else
4696 declare
4697 FST : constant Entity_Id := First_Subtype (Ent);
4699 begin
4700 if not Is_Internal_Name (Chars (FST)) then
4701 Ent := FST;
4702 exit Find;
4704 -- Otherwise use root type
4706 else
4707 if not Derived then
4708 Buffer_Remove ("type ");
4710 -- Test for "subtype of type derived from" which seems
4711 -- excessive and is replaced by "type derived from".
4713 Buffer_Remove ("subtype of");
4715 -- Avoid duplicated "type derived from type derived from"
4717 if not Buffer_Ends_With ("type derived from ") then
4718 Set_Msg_Str ("type derived from ");
4719 end if;
4721 Derived := True;
4722 end if;
4723 end if;
4724 end;
4726 Ent := Etype (Ent);
4727 end if;
4729 -- If we are stuck in a loop, get out and settle for the internal
4730 -- name after all. In this case we set to kill the message if it is
4731 -- not the first error message (we really try hard not to show the
4732 -- dirty laundry of the implementation to the poor user).
4734 if Ent = Old_Ent then
4735 Kill_Message := True;
4736 exit Find;
4737 end if;
4739 -- Get out if we finally found a non-internal name to use
4741 exit Find when not Is_Internal_Name (Chars (Ent));
4742 end loop Find;
4744 if Mchar = '"' then
4745 Set_Msg_Char ('"');
4746 end if;
4747 end Unwind_Internal_Type;
4749 --------------------
4750 -- Warn_Insertion --
4751 --------------------
4753 function Warn_Insertion return String is
4754 begin
4755 if Warning_Msg_Char = "? " then
4756 return "??";
4757 elsif Warning_Msg_Char = " " then
4758 return "?";
4759 elsif Warning_Msg_Char (2) = ' ' then
4760 return '?' & Warning_Msg_Char (1) & '?';
4761 else
4762 return '?' & Warning_Msg_Char & '?';
4763 end if;
4764 end Warn_Insertion;
4766 end Errout;