libstdc++: Qualify calls in <bits/stl_uninitialized.h> to prevent ADL
[official-gcc.git] / gcc / ada / errout.adb
blob1d82386099ceda78b488432477d768f44213f83e
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
2502 -- Print message kind
2504 Write_Str ("{""kind"":");
2506 if Errors.Table (E).Warn and then not Errors.Table (E).Warn_Err then
2507 Write_Str ("""warning""");
2508 elsif Errors.Table (E).Info or else Errors.Table (E).Check then
2509 Write_Str ("""note""");
2510 else
2511 Write_Str ("""error""");
2512 end if;
2514 -- Print message location
2516 Write_Str (",""locations"":[");
2517 Write_JSON_Span (Errors.Table (E));
2519 if Errors.Table (E).Optr.Ptr /= Errors.Table (E).Sptr.Ptr then
2520 Write_Str (",{""caret"":");
2521 Write_JSON_Location (Errors.Table (E).Optr.Ptr);
2522 Write_Str ("}");
2523 end if;
2525 Write_Str ("]");
2527 -- Print message option, if there is one
2528 if Option /= "" then
2529 Write_Str (",""option"":""" & Option & """");
2530 end if;
2532 -- Print message content
2534 Write_Str (",""message"":""");
2535 Write_JSON_Escaped_String (Errors.Table (E).Text);
2536 Write_Str ("""");
2538 E := E + 1;
2540 if Print_Continuations and then Is_Continuation (E) then
2542 Write_Str (",""children"": [");
2543 Output_JSON_Message (E);
2544 E := E + 1;
2546 while Is_Continuation (E) loop
2547 Write_Str (", ");
2548 Output_JSON_Message (E);
2549 E := E + 1;
2550 end loop;
2552 Write_Str ("]");
2554 end if;
2556 Write_Str ("}");
2557 end Output_JSON_Message;
2559 ---------------------
2560 -- Output_Messages --
2561 ---------------------
2563 procedure Output_Messages is
2565 -- Local subprograms
2567 procedure Write_Error_Summary;
2568 -- Write error summary
2570 procedure Write_Header (Sfile : Source_File_Index);
2571 -- Write header line (compiling or checking given file)
2573 procedure Write_Max_Errors;
2574 -- Write message if max errors reached
2576 procedure Write_Source_Code_Lines
2577 (Span : Source_Span;
2578 SGR_Span : String);
2579 -- Write the source code line corresponding to Span, as follows when
2580 -- Span in on one line:
2582 -- line | actual code line here with Span somewhere
2583 -- | ~~~~~^~~~
2585 -- where the caret on the line points to location Span.Ptr, and the
2586 -- range Span.First..Span.Last is underlined.
2588 -- or when the span is over multiple lines:
2590 -- line | beginning of the Span on this line
2591 -- ... | ...
2592 -- line>| actual code line here with Span.Ptr somewhere
2593 -- ... | ...
2594 -- line | end of the Span on this line
2596 -- or when the span is a simple location, as follows:
2598 -- line | actual code line here with Span somewhere
2599 -- | ^ here
2601 -- where the caret on the line points to location Span.Ptr
2603 -- SGR_Span is the SGR string to start the section of code in the span,
2604 -- that should be closed with SGR_Reset.
2606 -------------------------
2607 -- Write_Error_Summary --
2608 -------------------------
2610 procedure Write_Error_Summary is
2611 begin
2612 -- Extra blank line if error messages or source listing were output
2614 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
2615 then
2616 Write_Eol;
2617 end if;
2619 -- Message giving number of lines read and number of errors detected.
2620 -- This normally goes to Standard_Output. The exception is when brief
2621 -- mode is not set, verbose mode (or full list mode) is set, and
2622 -- there are errors. In this case we send the message to standard
2623 -- error to make sure that *something* appears on standard error
2624 -- in an error situation.
2626 if Total_Errors_Detected + Warnings_Detected /= 0
2627 and then not Brief_Output
2628 and then (Verbose_Mode or Full_List)
2629 then
2630 Set_Standard_Error;
2631 end if;
2633 -- Message giving total number of lines. Don't give this message if
2634 -- the Main_Source line is unknown (this happens in error situations,
2635 -- e.g. when integrated preprocessing fails).
2637 if Main_Source_File > No_Source_File then
2638 Write_Str (" ");
2639 Write_Int (Num_Source_Lines (Main_Source_File));
2641 if Num_Source_Lines (Main_Source_File) = 1 then
2642 Write_Str (" line: ");
2643 else
2644 Write_Str (" lines: ");
2645 end if;
2646 end if;
2648 if Total_Errors_Detected = 0 then
2649 Write_Str ("No errors");
2651 elsif Total_Errors_Detected = 1 then
2652 Write_Str ("1 error");
2654 else
2655 Write_Int (Total_Errors_Detected);
2656 Write_Str (" errors");
2657 end if;
2659 -- We now need to output warnings. When using -gnatwe, all warnings
2660 -- should be treated as errors, except for warnings originating from
2661 -- the use of the Compile_Time_Warning pragma. Another situation
2662 -- where a warning might be treated as an error is when the source
2663 -- code contains a Warning_As_Error pragma.
2664 -- When warnings are treated as errors, we still log them as
2665 -- warnings, but we add a message denoting how many of these warnings
2666 -- are also errors.
2668 declare
2669 Warnings_Count : constant Int := Warnings_Detected;
2671 Compile_Time_Warnings : Int;
2672 -- Number of warnings that come from a Compile_Time_Warning
2673 -- pragma.
2675 Non_Compile_Time_Warnings : Int;
2676 -- Number of warnings that do not come from a Compile_Time_Warning
2677 -- pragmas.
2679 begin
2680 if Warnings_Count > 0 then
2681 Write_Str (", ");
2682 Write_Int (Warnings_Count);
2683 Write_Str (" warning");
2685 if Warnings_Count > 1 then
2686 Write_Char ('s');
2687 end if;
2689 Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
2690 Non_Compile_Time_Warnings :=
2691 Warnings_Count - Compile_Time_Warnings;
2693 if Warning_Mode = Treat_As_Error
2694 and then Non_Compile_Time_Warnings > 0
2695 then
2696 Write_Str (" (");
2698 if Compile_Time_Warnings > 0 then
2699 Write_Int (Non_Compile_Time_Warnings);
2700 Write_Str (" ");
2701 end if;
2703 Write_Str ("treated as error");
2705 if Non_Compile_Time_Warnings > 1 then
2706 Write_Char ('s');
2707 end if;
2709 Write_Char (')');
2711 elsif Warnings_Treated_As_Errors > 0 then
2712 Write_Str (" (");
2714 if Warnings_Treated_As_Errors /= Warnings_Count then
2715 Write_Int (Warnings_Treated_As_Errors);
2716 Write_Str (" ");
2717 end if;
2719 Write_Str ("treated as error");
2721 if Warnings_Treated_As_Errors > 1 then
2722 Write_Str ("s");
2723 end if;
2725 Write_Str (")");
2726 end if;
2727 end if;
2728 end;
2730 if Info_Messages /= 0 then
2731 Write_Str (", ");
2732 Write_Int (Info_Messages);
2733 Write_Str (" info message");
2735 if Info_Messages > 1 then
2736 Write_Char ('s');
2737 end if;
2738 end if;
2740 Write_Eol;
2741 Set_Standard_Output;
2742 end Write_Error_Summary;
2744 ------------------
2745 -- Write_Header --
2746 ------------------
2748 procedure Write_Header (Sfile : Source_File_Index) is
2749 begin
2750 if Verbose_Mode or Full_List then
2751 if Original_Operating_Mode = Generate_Code then
2752 Write_Str ("Compiling: ");
2753 else
2754 Write_Str ("Checking: ");
2755 end if;
2757 Write_Name (Full_File_Name (Sfile));
2759 if not Debug_Flag_7 then
2760 Write_Eol;
2761 Write_Str ("Source file time stamp: ");
2762 Write_Time_Stamp (Sfile);
2763 Write_Eol;
2764 Write_Str ("Compiled at: " & Compilation_Time);
2765 end if;
2767 Write_Eol;
2768 end if;
2769 end Write_Header;
2771 ----------------------
2772 -- Write_Max_Errors --
2773 ----------------------
2775 procedure Write_Max_Errors is
2776 begin
2777 if Maximum_Messages /= 0 then
2778 if Warnings_Detected >= Maximum_Messages then
2779 Set_Standard_Error;
2780 Write_Line ("maximum number of warnings output");
2781 Write_Line ("any further warnings suppressed");
2782 Set_Standard_Output;
2783 end if;
2785 -- If too many errors print message
2787 if Total_Errors_Detected >= Maximum_Messages then
2788 Set_Standard_Error;
2789 Write_Line ("fatal error: maximum number of errors detected");
2790 Set_Standard_Output;
2791 end if;
2792 end if;
2793 end Write_Max_Errors;
2795 -----------------------------
2796 -- Write_Source_Code_Lines --
2797 -----------------------------
2799 procedure Write_Source_Code_Lines
2800 (Span : Source_Span;
2801 SGR_Span : String)
2803 function Get_Line_End
2804 (Buf : Source_Buffer_Ptr;
2805 Loc : Source_Ptr) return Source_Ptr;
2806 -- Get the source location for the end of the line in Buf for Loc. If
2807 -- Loc is past the end of Buf already, return Buf'Last.
2809 function Get_Line_Start
2810 (Buf : Source_Buffer_Ptr;
2811 Loc : Source_Ptr) return Source_Ptr;
2812 -- Get the source location for the start of the line in Buf for Loc
2814 function Image (X : Positive; Width : Positive) return String;
2815 -- Output number X over Width characters, with whitespace padding.
2816 -- Only output the low-order Width digits of X, if X is larger than
2817 -- Width digits.
2819 procedure Write_Buffer
2820 (Buf : Source_Buffer_Ptr;
2821 First : Source_Ptr;
2822 Last : Source_Ptr);
2823 -- Output the characters from First to Last position in Buf, using
2824 -- Write_Buffer_Char.
2826 procedure Write_Buffer_Char
2827 (Buf : Source_Buffer_Ptr;
2828 Loc : Source_Ptr);
2829 -- Output the characters at position Loc in Buf, translating ASCII.HT
2830 -- in a suitable number of spaces so that the output is not modified
2831 -- by starting in a different column that 1.
2833 procedure Write_Line_Marker
2834 (Num : Pos;
2835 Mark : Boolean;
2836 Width : Positive);
2837 -- Output the line number Num over Width characters, with possibly
2838 -- a Mark to denote the line with the main location when reporting
2839 -- a span over multiple lines.
2841 ------------------
2842 -- Get_Line_End --
2843 ------------------
2845 function Get_Line_End
2846 (Buf : Source_Buffer_Ptr;
2847 Loc : Source_Ptr) return Source_Ptr
2849 Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
2850 begin
2851 while Cur_Loc < Buf'Last
2852 and then Buf (Cur_Loc) /= ASCII.LF
2853 loop
2854 Cur_Loc := Cur_Loc + 1;
2855 end loop;
2857 return Cur_Loc;
2858 end Get_Line_End;
2860 --------------------
2861 -- Get_Line_Start --
2862 --------------------
2864 function Get_Line_Start
2865 (Buf : Source_Buffer_Ptr;
2866 Loc : Source_Ptr) return Source_Ptr
2868 Cur_Loc : Source_Ptr := Loc;
2869 begin
2870 while Cur_Loc > Buf'First
2871 and then Buf (Cur_Loc - 1) /= ASCII.LF
2872 loop
2873 Cur_Loc := Cur_Loc - 1;
2874 end loop;
2876 return Cur_Loc;
2877 end Get_Line_Start;
2879 -----------
2880 -- Image --
2881 -----------
2883 function Image (X : Positive; Width : Positive) return String is
2884 Str : String (1 .. Width);
2885 Curr : Natural := X;
2886 begin
2887 for J in reverse 1 .. Width loop
2888 if Curr > 0 then
2889 Str (J) := Character'Val (Character'Pos ('0') + Curr mod 10);
2890 Curr := Curr / 10;
2891 else
2892 Str (J) := ' ';
2893 end if;
2894 end loop;
2896 return Str;
2897 end Image;
2899 ------------------
2900 -- Write_Buffer --
2901 ------------------
2903 procedure Write_Buffer
2904 (Buf : Source_Buffer_Ptr;
2905 First : Source_Ptr;
2906 Last : Source_Ptr)
2908 begin
2909 for Loc in First .. Last loop
2910 Write_Buffer_Char (Buf, Loc);
2911 end loop;
2912 end Write_Buffer;
2914 -----------------------
2915 -- Write_Buffer_Char --
2916 -----------------------
2918 procedure Write_Buffer_Char
2919 (Buf : Source_Buffer_Ptr;
2920 Loc : Source_Ptr)
2922 begin
2923 -- If the character ASCII.HT is not the last one in the file,
2924 -- output as many spaces as the character represents in the
2925 -- original source file.
2927 if Buf (Loc) = ASCII.HT
2928 and then Loc < Buf'Last
2929 then
2930 for X in Get_Column_Number (Loc) ..
2931 Get_Column_Number (Loc + 1) - 1
2932 loop
2933 Write_Char (' ');
2934 end loop;
2936 -- Otherwise output the character itself
2938 else
2939 Write_Char (Buf (Loc));
2940 end if;
2941 end Write_Buffer_Char;
2943 -----------------------
2944 -- Write_Line_Marker --
2945 -----------------------
2947 procedure Write_Line_Marker
2948 (Num : Pos;
2949 Mark : Boolean;
2950 Width : Positive)
2952 begin
2953 Write_Str (Image (Positive (Num), Width => Width));
2954 Write_Str ((if Mark then ">" else " ") & "|");
2955 end Write_Line_Marker;
2957 -- Local variables
2959 Loc : constant Source_Ptr := Span.Ptr;
2960 Line : constant Pos := Pos (Get_Physical_Line_Number (Loc));
2962 Col : constant Natural := Natural (Get_Column_Number (Loc));
2964 Fst : constant Source_Ptr := Span.First;
2965 Line_Fst : constant Pos :=
2966 Pos (Get_Physical_Line_Number (Fst));
2967 Col_Fst : constant Natural :=
2968 Natural (Get_Column_Number (Fst));
2969 Lst : constant Source_Ptr := Span.Last;
2970 Line_Lst : constant Pos :=
2971 Pos (Get_Physical_Line_Number (Lst));
2972 Col_Lst : constant Natural :=
2973 Natural (Get_Column_Number (Lst));
2975 Width : constant := 5;
2976 Buf : Source_Buffer_Ptr;
2977 Cur_Loc : Source_Ptr := Fst;
2978 Cur_Line : Pos := Line_Fst;
2980 -- Start of processing for Write_Source_Code_Lines
2982 begin
2983 if Loc >= First_Source_Ptr then
2984 Buf := Source_Text (Get_Source_File_Index (Loc));
2986 -- First line of the span with actual source code. We retrieve
2987 -- the beginning of the line instead of relying on Col_Fst, as
2988 -- ASCII.HT characters change column numbers by possibly more
2989 -- than one.
2991 Write_Line_Marker
2992 (Cur_Line,
2993 Line_Fst /= Line_Lst and then Cur_Line = Line,
2994 Width);
2995 Write_Buffer (Buf, Get_Line_Start (Buf, Cur_Loc), Cur_Loc - 1);
2997 -- Output the first/caret/last lines of the span, as well as
2998 -- lines that are directly above/below the caret if they complete
2999 -- the gap with first/last lines, otherwise use ... to denote
3000 -- intermediate lines.
3002 -- If the span is on one line and not a simple source location,
3003 -- color it appropriately.
3005 if Line_Fst = Line_Lst
3006 and then Col_Fst /= Col_Lst
3007 then
3008 Write_Str (SGR_Span);
3009 end if;
3011 declare
3012 function Do_Write_Line (Cur_Line : Pos) return Boolean is
3013 (Cur_Line in Line_Fst | Line | Line_Lst
3014 or else
3015 (Cur_Line = Line_Fst + 1 and then Cur_Line = Line - 1)
3016 or else
3017 (Cur_Line = Line + 1 and then Cur_Line = Line_Lst - 1));
3018 begin
3019 while Cur_Loc <= Buf'Last
3020 and then Cur_Loc <= Lst
3021 loop
3022 if Do_Write_Line (Cur_Line) then
3023 Write_Buffer_Char (Buf, Cur_Loc);
3024 end if;
3026 if Buf (Cur_Loc) = ASCII.LF then
3027 Cur_Line := Cur_Line + 1;
3029 -- Output ... for skipped lines
3031 if (Cur_Line = Line
3032 and then not Do_Write_Line (Cur_Line - 1))
3033 or else
3034 (Cur_Line = Line + 1
3035 and then not Do_Write_Line (Cur_Line))
3036 then
3037 Write_Str ((1 .. Width - 3 => ' ') & "... | ...");
3038 Write_Eol;
3039 end if;
3041 -- Display the line marker if the line should be
3042 -- displayed.
3044 if Do_Write_Line (Cur_Line) then
3045 Write_Line_Marker
3046 (Cur_Line,
3047 Line_Fst /= Line_Lst and then Cur_Line = Line,
3048 Width);
3049 end if;
3050 end if;
3052 Cur_Loc := Cur_Loc + 1;
3053 end loop;
3054 end;
3056 if Line_Fst = Line_Lst
3057 and then Col_Fst /= Col_Lst
3058 then
3059 Write_Str (SGR_Reset);
3060 end if;
3062 -- Output the rest of the last line of the span
3064 Write_Buffer (Buf, Cur_Loc, Get_Line_End (Buf, Cur_Loc));
3066 -- If the span is on one line, output a second line with caret
3067 -- sign pointing to location Loc
3069 if Line_Fst = Line_Lst then
3070 Write_Str (String'(1 .. Width => ' '));
3071 Write_Str (" |");
3072 Write_Str (String'(1 .. Col_Fst - 1 => ' '));
3074 Write_Str (SGR_Span);
3076 Write_Str (String'(Col_Fst .. Col - 1 => '~'));
3077 Write_Str ("^");
3078 Write_Str (String'(Col + 1 .. Col_Lst => '~'));
3080 -- If the span is really just a location, add the word "here"
3081 -- to clarify this is the location for the message.
3083 if Col_Fst = Col_Lst then
3084 Write_Str (" here");
3085 end if;
3087 Write_Str (SGR_Reset);
3089 Write_Eol;
3090 end if;
3091 end if;
3092 end Write_Source_Code_Lines;
3094 -- Local variables
3096 E : Error_Msg_Id;
3097 Err_Flag : Boolean;
3098 Use_Prefix : Boolean;
3100 -- Start of processing for Output_Messages
3102 begin
3103 -- Error if Finalize has not been called
3105 if not Finalize_Called then
3106 raise Program_Error;
3107 end if;
3109 -- Reset current error source file if the main unit has a pragma
3110 -- Source_Reference. This ensures outputting the proper name of
3111 -- the source file in this situation.
3113 if Main_Source_File <= No_Source_File
3114 or else Num_SRef_Pragmas (Main_Source_File) /= 0
3115 then
3116 Current_Error_Source_File := No_Source_File;
3117 end if;
3119 if Opt.JSON_Output then
3120 Set_Standard_Error;
3122 E := First_Error_Msg;
3124 -- Find first printable message
3126 while E /= No_Error_Msg and then Errors.Table (E).Deleted loop
3127 E := Errors.Table (E).Next;
3128 end loop;
3130 Write_Char ('[');
3132 if E /= No_Error_Msg then
3134 Output_JSON_Message (E);
3136 E := Errors.Table (E).Next;
3138 while E /= No_Error_Msg loop
3140 -- Skip deleted messages.
3141 -- Also skip continuation messages, as they have already been
3142 -- printed along the message they're attached to.
3144 if not Errors.Table (E).Deleted
3145 and then not Errors.Table (E).Msg_Cont
3146 then
3147 Write_Char (',');
3148 Output_JSON_Message (E);
3149 end if;
3151 E := Errors.Table (E).Next;
3152 end loop;
3153 end if;
3155 Write_Char (']');
3157 Set_Standard_Output;
3159 -- Brief Error mode
3161 elsif Brief_Output or (not Full_List and not Verbose_Mode) then
3162 Set_Standard_Error;
3164 E := First_Error_Msg;
3165 while E /= No_Error_Msg loop
3167 -- If -gnatdF is used, separate main messages from previous
3168 -- messages with a newline (unless it is an info message) and
3169 -- make continuation messages follow the main message with only
3170 -- an indentation of two space characters, without repeating
3171 -- file:line:col: prefix.
3173 Use_Prefix :=
3174 not (Debug_Flag_FF and then Errors.Table (E).Msg_Cont);
3176 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
3178 if Debug_Flag_FF then
3179 if Errors.Table (E).Msg_Cont then
3180 Write_Str (" ");
3181 elsif not Errors.Table (E).Info then
3182 Write_Eol;
3183 end if;
3184 end if;
3186 if Use_Prefix then
3187 Write_Str (SGR_Locus);
3189 if Full_Path_Name_For_Brief_Errors then
3190 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
3191 else
3192 Write_Name (Reference_Name (Errors.Table (E).Sfile));
3193 end if;
3195 Write_Char (':');
3196 Write_Int (Int (Physical_To_Logical
3197 (Errors.Table (E).Line,
3198 Errors.Table (E).Sfile)));
3199 Write_Char (':');
3201 if Errors.Table (E).Col < 10 then
3202 Write_Char ('0');
3203 end if;
3205 Write_Int (Int (Errors.Table (E).Col));
3206 Write_Str (": ");
3208 Write_Str (SGR_Reset);
3209 end if;
3211 Output_Msg_Text (E);
3212 Write_Eol;
3214 -- If -gnatdF is used, write the source code line corresponding
3215 -- to the location of the main message (unless it is an info
3216 -- message). Also write the source code line corresponding to
3217 -- an insertion location inside continuation messages.
3219 if Debug_Flag_FF
3220 and then not Errors.Table (E).Info
3221 then
3222 if Errors.Table (E).Msg_Cont then
3223 declare
3224 Loc : constant Source_Ptr :=
3225 Errors.Table (E).Insertion_Sloc;
3226 begin
3227 if Loc /= No_Location then
3228 Write_Source_Code_Lines
3229 (To_Span (Loc), SGR_Span => SGR_Note);
3230 end if;
3231 end;
3233 else
3234 declare
3235 SGR_Span : constant String :=
3236 (if Errors.Table (E).Info then SGR_Note
3237 elsif Errors.Table (E).Warn
3238 and then not Errors.Table (E).Warn_Err
3239 then SGR_Warning
3240 else SGR_Error);
3241 begin
3242 Write_Source_Code_Lines
3243 (Errors.Table (E).Optr, SGR_Span);
3244 end;
3245 end if;
3246 end if;
3247 end if;
3249 E := Errors.Table (E).Next;
3250 end loop;
3252 Set_Standard_Output;
3253 end if;
3255 -- Full source listing case
3257 if Full_List then
3258 List_Pragmas_Index := 1;
3259 List_Pragmas_Mode := True;
3260 E := First_Error_Msg;
3262 -- Normal case, to stdout (copyright notice already output)
3264 if Full_List_File_Name = null then
3265 if not Debug_Flag_7 then
3266 Write_Eol;
3267 end if;
3269 -- Output to file
3271 else
3272 Create_List_File_Access.all (Full_List_File_Name.all);
3273 Set_Special_Output (Write_List_Info_Access.all'Access);
3275 -- Write copyright notice to file
3277 if not Debug_Flag_7 then
3278 Write_Str ("GNAT ");
3279 Write_Str (Gnat_Version_String);
3280 Write_Eol;
3281 Write_Str ("Copyright 1992-" &
3282 Current_Year &
3283 ", Free Software Foundation, Inc.");
3284 Write_Eol;
3285 end if;
3286 end if;
3288 -- First list extended main source file units with errors
3290 for U in Main_Unit .. Last_Unit loop
3291 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
3293 -- If debug flag d.m is set, only the main source is listed
3295 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
3297 -- If the unit of the entity does not come from source, it is
3298 -- an implicit subprogram declaration for a child subprogram.
3299 -- Do not emit errors for it, they are listed with the body.
3301 and then
3302 (No (Cunit_Entity (U))
3303 or else Comes_From_Source (Cunit_Entity (U))
3304 or else not Is_Subprogram (Cunit_Entity (U)))
3306 -- If the compilation unit associated with this unit does not
3307 -- come from source, it means it is an instantiation that should
3308 -- not be included in the source listing.
3310 and then Comes_From_Source (Cunit (U))
3311 then
3312 declare
3313 Sfile : constant Source_File_Index := Source_Index (U);
3315 begin
3316 Write_Eol;
3318 -- Only write the header if Sfile is known
3320 if Sfile > No_Source_File then
3321 Write_Header (Sfile);
3322 Write_Eol;
3323 end if;
3325 -- Normally, we don't want an "error messages from file"
3326 -- message when listing the entire file, so we set the
3327 -- current source file as the current error source file.
3328 -- However, the old style of doing things was to list this
3329 -- message if pragma Source_Reference is present, even for
3330 -- the main unit. Since the purpose of the -gnatd.m switch
3331 -- is to duplicate the old behavior, we skip the reset if
3332 -- this debug flag is set.
3334 if not Debug_Flag_Dot_M then
3335 Current_Error_Source_File := Sfile;
3336 end if;
3338 -- Only output the listing if Sfile is known, to avoid
3339 -- crashing the compiler.
3341 if Sfile > No_Source_File then
3342 for N in 1 .. Last_Source_Line (Sfile) loop
3343 while E /= No_Error_Msg
3344 and then Errors.Table (E).Deleted
3345 loop
3346 E := Errors.Table (E).Next;
3347 end loop;
3349 Err_Flag :=
3350 E /= No_Error_Msg
3351 and then Errors.Table (E).Line = N
3352 and then Errors.Table (E).Sfile = Sfile;
3354 Output_Source_Line (N, Sfile, Err_Flag);
3356 if Err_Flag then
3357 Output_Error_Msgs (E);
3359 if not Debug_Flag_2 then
3360 Write_Eol;
3361 end if;
3362 end if;
3363 end loop;
3364 end if;
3365 end;
3366 end if;
3367 end loop;
3369 -- Then output errors, if any, for subsidiary units not in the
3370 -- main extended unit.
3372 -- Note: if debug flag d.m set, include errors for any units other
3373 -- than the main unit in the extended source unit (e.g. spec and
3374 -- subunits for a body).
3376 while E /= No_Error_Msg
3377 and then (not In_Extended_Main_Source_Unit
3378 (Errors.Table (E).Sptr.Ptr)
3379 or else
3380 (Debug_Flag_Dot_M
3381 and then Get_Source_Unit
3382 (Errors.Table (E).Sptr.Ptr) /= Main_Unit))
3383 loop
3384 if Errors.Table (E).Deleted then
3385 E := Errors.Table (E).Next;
3387 else
3388 Write_Eol;
3389 Output_Source_Line
3390 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3391 Output_Error_Msgs (E);
3392 end if;
3393 end loop;
3395 -- If output to file, write extra copy of error summary to the
3396 -- output file, and then close it.
3398 if Full_List_File_Name /= null then
3399 Write_Error_Summary;
3400 Write_Max_Errors;
3401 Close_List_File_Access.all;
3402 Cancel_Special_Output;
3403 end if;
3404 end if;
3406 -- Verbose mode (error lines only with error flags). Normally this is
3407 -- ignored in full list mode, unless we are listing to a file, in which
3408 -- case we still generate -gnatv output to standard output.
3410 if Verbose_Mode
3411 and then (not Full_List or else Full_List_File_Name /= null)
3412 then
3413 Write_Eol;
3415 -- Output the header only when Main_Source_File is known
3417 if Main_Source_File > No_Source_File then
3418 Write_Header (Main_Source_File);
3419 end if;
3421 E := First_Error_Msg;
3423 -- Loop through error lines
3425 while E /= No_Error_Msg loop
3426 if Errors.Table (E).Deleted then
3427 E := Errors.Table (E).Next;
3428 else
3429 Write_Eol;
3430 Output_Source_Line
3431 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3432 Output_Error_Msgs (E);
3433 end if;
3434 end loop;
3435 end if;
3437 -- Output error summary if verbose or full list mode
3439 if Verbose_Mode or else Full_List then
3440 Write_Error_Summary;
3441 end if;
3443 if not Opt.JSON_Output then
3444 Write_Max_Errors;
3445 end if;
3447 if Warning_Mode = Treat_As_Error then
3448 declare
3449 Compile_Time_Pragma_Warnings : constant Nat :=
3450 Count_Compile_Time_Pragma_Warnings;
3451 Total : constant Int := Total_Errors_Detected + Warnings_Detected
3452 - Compile_Time_Pragma_Warnings;
3453 -- We need to protect against a negative Total here, because
3454 -- if a pragma Compile_Time_Warning occurs in dead code, it
3455 -- gets counted in Compile_Time_Pragma_Warnings but not in
3456 -- Warnings_Detected.
3457 begin
3458 Total_Errors_Detected := Int'Max (Total, 0);
3459 Warnings_Detected := Compile_Time_Pragma_Warnings;
3460 end;
3461 end if;
3462 end Output_Messages;
3464 ------------------------
3465 -- Output_Source_Line --
3466 ------------------------
3468 procedure Output_Source_Line
3469 (L : Physical_Line_Number;
3470 Sfile : Source_File_Index;
3471 Errs : Boolean)
3473 S : Source_Ptr;
3474 C : Character;
3476 Line_Number_Output : Boolean := False;
3477 -- Set True once line number is output
3479 Empty_Line : Boolean := True;
3480 -- Set False if line includes at least one character
3482 begin
3483 if Sfile /= Current_Error_Source_File then
3484 Write_Str ("==============Error messages for ");
3486 case Sinput.File_Type (Sfile) is
3487 when Sinput.Src =>
3488 Write_Str ("source");
3490 when Sinput.Config =>
3491 Write_Str ("configuration pragmas");
3493 when Sinput.Def =>
3494 Write_Str ("symbol definition");
3496 when Sinput.Preproc =>
3497 Write_Str ("preprocessing data");
3498 end case;
3500 Write_Str (" file: ");
3501 Write_Name (Full_File_Name (Sfile));
3502 Write_Eol;
3504 if Num_SRef_Pragmas (Sfile) > 0 then
3505 Write_Str ("--------------Line numbers from file: ");
3506 Write_Name (Full_Ref_Name (Sfile));
3507 Write_Str (" (starting at line ");
3508 Write_Int (Int (First_Mapped_Line (Sfile)));
3509 Write_Char (')');
3510 Write_Eol;
3511 end if;
3513 Current_Error_Source_File := Sfile;
3514 end if;
3516 if Errs or List_Pragmas_Mode then
3517 Output_Line_Number (Physical_To_Logical (L, Sfile));
3518 Line_Number_Output := True;
3519 end if;
3521 S := Line_Start (L, Sfile);
3523 loop
3524 C := Source_Text (Sfile) (S);
3525 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
3527 -- Deal with matching entry in List_Pragmas table
3529 if Full_List
3530 and then List_Pragmas_Index <= List_Pragmas.Last
3531 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
3532 then
3533 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
3534 when Page =>
3535 Write_Char (C);
3537 -- Ignore if on line with errors so that error flags
3538 -- get properly listed with the error line .
3540 if not Errs then
3541 Write_Char (ASCII.FF);
3542 end if;
3544 when List_On =>
3545 List_Pragmas_Mode := True;
3547 if not Line_Number_Output then
3548 Output_Line_Number (Physical_To_Logical (L, Sfile));
3549 Line_Number_Output := True;
3550 end if;
3552 Write_Char (C);
3554 when List_Off =>
3555 Write_Char (C);
3556 List_Pragmas_Mode := False;
3557 end case;
3559 List_Pragmas_Index := List_Pragmas_Index + 1;
3561 -- Normal case (no matching entry in List_Pragmas table)
3563 else
3564 if Errs or List_Pragmas_Mode then
3565 Write_Char (C);
3566 end if;
3567 end if;
3569 Empty_Line := False;
3570 S := S + 1;
3571 end loop;
3573 -- If we have output a source line, then add the line terminator, with
3574 -- training spaces preserved (so we output the line exactly as input).
3576 if Line_Number_Output then
3577 if Empty_Line then
3578 Write_Eol;
3579 else
3580 Write_Eol_Keep_Blanks;
3581 end if;
3582 end if;
3583 end Output_Source_Line;
3585 --------------------
3586 -- Paren_Required --
3587 --------------------
3589 function Paren_Required (N : Node_Id) return Boolean is
3590 begin
3591 -- In a qualifed_expression the expression part needs to be enclosed in
3592 -- parentheses.
3594 if Nkind (Parent (N)) = N_Qualified_Expression then
3595 return N = Expression (Parent (N));
3597 else
3598 return False;
3599 end if;
3600 end Paren_Required;
3602 -----------------------------
3603 -- Remove_Warning_Messages --
3604 -----------------------------
3606 procedure Remove_Warning_Messages (N : Node_Id) is
3608 function Check_For_Warning (N : Node_Id) return Traverse_Result;
3609 -- This function checks one node for a possible warning message
3611 procedure Check_All_Warnings is new Traverse_Proc (Check_For_Warning);
3612 -- This defines the traversal operation
3614 -----------------------
3615 -- Check_For_Warning --
3616 -----------------------
3618 function Check_For_Warning (N : Node_Id) return Traverse_Result is
3619 Loc : constant Source_Ptr := Sloc (N);
3620 E : Error_Msg_Id;
3622 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
3623 -- Returns True for a message that is to be removed. Also adjusts
3624 -- warning count appropriately.
3626 -------------------
3627 -- To_Be_Removed --
3628 -------------------
3630 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
3631 begin
3632 if E /= No_Error_Msg
3634 -- Don't remove if location does not match
3636 and then Errors.Table (E).Optr.Ptr = Loc
3638 -- Don't remove if not warning/info message. Note that we do
3639 -- not remove style messages here. They are warning messages
3640 -- but not ones we want removed in this context.
3642 and then (Errors.Table (E).Warn
3643 or else
3644 Errors.Table (E).Warn_Runtime_Raise)
3646 -- Don't remove unconditional messages
3648 and then not Errors.Table (E).Uncond
3649 then
3650 if Errors.Table (E).Warn then
3651 Warnings_Detected := Warnings_Detected - 1;
3652 end if;
3654 -- When warning about a runtime exception has been escalated
3655 -- into error, the starting message has increased the total
3656 -- errors counter, so here we decrease this counter.
3658 if Errors.Table (E).Warn_Runtime_Raise
3659 and then not Errors.Table (E).Msg_Cont
3660 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
3661 then
3662 Total_Errors_Detected := Total_Errors_Detected - 1;
3663 end if;
3665 return True;
3667 -- No removal required
3669 else
3670 return False;
3671 end if;
3672 end To_Be_Removed;
3674 -- Start of processing for Check_For_Warnings
3676 begin
3677 while To_Be_Removed (First_Error_Msg) loop
3678 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
3679 end loop;
3681 if First_Error_Msg = No_Error_Msg then
3682 Last_Error_Msg := No_Error_Msg;
3683 end if;
3685 E := First_Error_Msg;
3686 while E /= No_Error_Msg loop
3687 while To_Be_Removed (Errors.Table (E).Next) loop
3688 Errors.Table (E).Next :=
3689 Errors.Table (Errors.Table (E).Next).Next;
3691 if Errors.Table (E).Next = No_Error_Msg then
3692 Last_Error_Msg := E;
3693 end if;
3694 end loop;
3696 E := Errors.Table (E).Next;
3697 end loop;
3699 -- Warnings may have been posted on subexpressions of original tree
3701 if Nkind (N) = N_Raise_Constraint_Error
3702 and then Is_Rewrite_Substitution (N)
3703 and then No (Condition (N))
3704 then
3705 Check_All_Warnings (Original_Node (N));
3706 end if;
3708 return OK;
3709 end Check_For_Warning;
3711 -- Start of processing for Remove_Warning_Messages
3713 begin
3714 if Warnings_Detected /= 0 then
3715 Check_All_Warnings (N);
3716 end if;
3717 end Remove_Warning_Messages;
3719 procedure Remove_Warning_Messages (L : List_Id) is
3720 Stat : Node_Id;
3721 begin
3722 Stat := First (L);
3723 while Present (Stat) loop
3724 Remove_Warning_Messages (Stat);
3725 Next (Stat);
3726 end loop;
3727 end Remove_Warning_Messages;
3729 ----------------------
3730 -- Adjust_Name_Case --
3731 ----------------------
3733 procedure Adjust_Name_Case
3734 (Buf : in out Bounded_String;
3735 Loc : Source_Ptr)
3737 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
3738 Sbuffer : Source_Buffer_Ptr;
3739 Ref_Ptr : Integer;
3740 Src_Ptr : Source_Ptr;
3742 begin
3743 -- We have an all lower case name from Namet, and now we want to set
3744 -- the appropriate case. If possible we copy the actual casing from
3745 -- the source. If not we use standard identifier casing.
3747 Ref_Ptr := 1;
3748 Src_Ptr := Loc;
3750 -- For standard locations, always use mixed case
3752 if Loc <= No_Location then
3753 Set_Casing (Buf, Mixed_Case);
3755 else
3756 -- Determine if the reference we are dealing with corresponds to text
3757 -- at the point of the error reference. This will often be the case
3758 -- for simple identifier references, and is the case where we can
3759 -- copy the casing from the source.
3761 Sbuffer := Source_Text (Src_Ind);
3763 while Ref_Ptr <= Buf.Length loop
3764 exit when
3765 Fold_Lower (Sbuffer (Src_Ptr)) /=
3766 Fold_Lower (Buf.Chars (Ref_Ptr));
3767 Ref_Ptr := Ref_Ptr + 1;
3768 Src_Ptr := Src_Ptr + 1;
3769 end loop;
3771 -- If we get through the loop without a mismatch, then output the
3772 -- name the way it is cased in the source program.
3774 if Ref_Ptr > Buf.Length then
3775 Src_Ptr := Loc;
3777 for J in 1 .. Buf.Length loop
3778 Buf.Chars (J) := Sbuffer (Src_Ptr);
3779 Src_Ptr := Src_Ptr + 1;
3780 end loop;
3782 -- Otherwise set the casing using the default identifier casing
3784 else
3785 Set_Casing (Buf, Identifier_Casing (Src_Ind));
3786 end if;
3787 end if;
3788 end Adjust_Name_Case;
3790 ---------------------------
3791 -- Set_Identifier_Casing --
3792 ---------------------------
3794 procedure Set_Identifier_Casing
3795 (Identifier_Name : System.Address;
3796 File_Name : System.Address)
3798 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
3799 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
3800 Flen : Natural;
3802 Desired_Case : Casing_Type := Mixed_Case;
3803 -- Casing required for result. Default value of Mixed_Case is used if
3804 -- for some reason we cannot find the right file name in the table.
3806 begin
3807 -- Get length of file name
3809 Flen := 0;
3810 while File (Flen + 1) /= ASCII.NUL loop
3811 Flen := Flen + 1;
3812 end loop;
3814 -- Loop through file names to find matching one. This is a bit slow, but
3815 -- we only do it in error situations so it is not so terrible. Note that
3816 -- if the loop does not exit, then the desired case will be left set to
3817 -- Mixed_Case, this can happen if the name was not in canonical form.
3819 for J in 1 .. Last_Source_File loop
3820 Get_Name_String (Full_Debug_Name (J));
3822 if Name_Len = Flen
3823 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
3824 then
3825 Desired_Case := Identifier_Casing (J);
3826 exit;
3827 end if;
3828 end loop;
3830 -- Copy identifier as given to Name_Buffer
3832 for J in Name_Buffer'Range loop
3833 Name_Buffer (J) := Ident (J);
3835 if Name_Buffer (J) = ASCII.NUL then
3836 Name_Len := J - 1;
3837 exit;
3838 end if;
3839 end loop;
3841 Set_Casing (Desired_Case);
3842 end Set_Identifier_Casing;
3844 -----------------------
3845 -- Set_Ignore_Errors --
3846 -----------------------
3848 procedure Set_Ignore_Errors (To : Boolean) is
3849 begin
3850 Errors_Must_Be_Ignored := To;
3851 end Set_Ignore_Errors;
3853 ------------------------------
3854 -- Set_Msg_Insertion_Column --
3855 ------------------------------
3857 procedure Set_Msg_Insertion_Column is
3858 begin
3859 if RM_Column_Check then
3860 Set_Msg_Str (" in column ");
3861 Set_Msg_Int (Int (Error_Msg_Col) + 1);
3862 end if;
3863 end Set_Msg_Insertion_Column;
3865 ----------------------------
3866 -- Set_Msg_Insertion_Node --
3867 ----------------------------
3869 procedure Set_Msg_Insertion_Node is
3870 K : Node_Kind;
3872 begin
3873 Suppress_Message :=
3874 Error_Msg_Node_1 = Error
3875 or else Error_Msg_Node_1 = Any_Type;
3877 if Error_Msg_Node_1 = Empty then
3878 Set_Msg_Blank_Conditional;
3879 Set_Msg_Str ("<empty>");
3881 elsif Error_Msg_Node_1 = Error then
3882 Set_Msg_Blank;
3883 Set_Msg_Str ("<error>");
3885 elsif Error_Msg_Node_1 = Standard_Void_Type then
3886 Set_Msg_Blank;
3887 Set_Msg_Str ("procedure name");
3889 elsif Nkind (Error_Msg_Node_1) in N_Entity
3890 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
3891 then
3892 Set_Msg_Blank;
3893 Set_Msg_Str ("access to subprogram");
3895 else
3896 Set_Msg_Blank_Conditional;
3898 -- Output name
3900 K := Nkind (Error_Msg_Node_1);
3902 -- If we have operator case, skip quotes since name of operator
3903 -- itself will supply the required quotations. An operator can be an
3904 -- applied use in an expression or an explicit operator symbol, or an
3905 -- identifier whose name indicates it is an operator.
3907 if K in N_Op
3908 or else K = N_Operator_Symbol
3909 or else K = N_Defining_Operator_Symbol
3910 or else ((K = N_Identifier or else K = N_Defining_Identifier)
3911 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
3912 then
3913 Set_Msg_Node (Error_Msg_Node_1);
3915 -- Normal case, not an operator, surround with quotes
3917 else
3918 Set_Msg_Quote;
3919 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
3920 Set_Msg_Node (Error_Msg_Node_1);
3921 Set_Msg_Quote;
3922 end if;
3923 end if;
3925 -- The following assignment ensures that further ampersand insertion
3926 -- characters will correspond to the Error_Msg_Node_# parameter.
3928 Error_Msg_Node_1 := Error_Msg_Node_2;
3929 Error_Msg_Node_2 := Error_Msg_Node_3;
3930 Error_Msg_Node_3 := Error_Msg_Node_4;
3931 Error_Msg_Node_4 := Error_Msg_Node_5;
3932 Error_Msg_Node_5 := Error_Msg_Node_6;
3933 end Set_Msg_Insertion_Node;
3935 --------------------------------------
3936 -- Set_Msg_Insertion_Type_Reference --
3937 --------------------------------------
3939 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
3940 Ent : Entity_Id;
3942 begin
3943 Set_Msg_Blank;
3945 if Error_Msg_Node_1 = Standard_Void_Type then
3946 Set_Msg_Str ("package or procedure name");
3947 return;
3949 elsif Error_Msg_Node_1 = Standard_Exception_Type then
3950 Set_Msg_Str ("exception name");
3951 return;
3953 elsif Error_Msg_Node_1 = Any_Array
3954 or else Error_Msg_Node_1 = Any_Boolean
3955 or else Error_Msg_Node_1 = Any_Character
3956 or else Error_Msg_Node_1 = Any_Composite
3957 or else Error_Msg_Node_1 = Any_Discrete
3958 or else Error_Msg_Node_1 = Any_Fixed
3959 or else Error_Msg_Node_1 = Any_Integer
3960 or else Error_Msg_Node_1 = Any_Modular
3961 or else Error_Msg_Node_1 = Any_Numeric
3962 or else Error_Msg_Node_1 = Any_Real
3963 or else Error_Msg_Node_1 = Any_Scalar
3964 or else Error_Msg_Node_1 = Any_String
3965 then
3966 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
3967 Set_Msg_Name_Buffer;
3968 return;
3970 elsif Error_Msg_Node_1 = Universal_Integer then
3971 Set_Msg_Str ("type universal integer");
3972 return;
3974 elsif Error_Msg_Node_1 = Universal_Real then
3975 Set_Msg_Str ("type universal real");
3976 return;
3978 elsif Error_Msg_Node_1 = Universal_Fixed then
3979 Set_Msg_Str ("type universal fixed");
3980 return;
3982 elsif Error_Msg_Node_1 = Universal_Access then
3983 Set_Msg_Str ("type universal access");
3984 return;
3985 end if;
3987 -- Special case of anonymous array
3989 if Nkind (Error_Msg_Node_1) in N_Entity
3990 and then Is_Array_Type (Error_Msg_Node_1)
3991 and then Present (Related_Array_Object (Error_Msg_Node_1))
3992 then
3993 Set_Msg_Str ("type of ");
3994 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
3995 Set_Msg_Str (" declared");
3996 Set_Msg_Insertion_Line_Number
3997 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
3998 return;
3999 end if;
4001 -- If we fall through, it is not a special case, so first output
4002 -- the name of the type, preceded by private for a private type
4004 if Is_Private_Type (Error_Msg_Node_1) then
4005 Set_Msg_Str ("private type ");
4006 else
4007 Set_Msg_Str ("type ");
4008 end if;
4010 Ent := Error_Msg_Node_1;
4012 if Is_Internal_Name (Chars (Ent)) then
4013 Unwind_Internal_Type (Ent);
4014 end if;
4016 -- Types in Standard are displayed as "Standard.name"
4018 if Sloc (Ent) <= Standard_Location then
4019 Set_Msg_Quote;
4020 Set_Msg_Str ("Standard.");
4021 Set_Msg_Node (Ent);
4022 Add_Class;
4023 Set_Msg_Quote;
4025 -- Types in other language defined units are displayed as
4026 -- "package-name.type-name"
4028 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
4029 Get_Unqualified_Decoded_Name_String
4030 (Unit_Name (Get_Source_Unit (Ent)));
4031 Name_Len := Name_Len - 2;
4032 Set_Msg_Blank_Conditional;
4033 Set_Msg_Quote;
4034 Set_Casing (Mixed_Case);
4035 Set_Msg_Name_Buffer;
4036 Set_Msg_Char ('.');
4037 Set_Casing (Mixed_Case);
4038 Set_Msg_Node (Ent);
4039 Add_Class;
4040 Set_Msg_Quote;
4042 -- All other types display as "type name" defined at line xxx
4043 -- possibly qualified if qualification is requested.
4045 else
4046 Set_Msg_Quote;
4047 Set_Qualification (Error_Msg_Qual_Level, Ent);
4048 Set_Msg_Node (Ent);
4049 Add_Class;
4051 -- If we did not print a name (e.g. in the case of an anonymous
4052 -- subprogram type), there is no name to print, so remove quotes.
4054 if Buffer_Ends_With ('"') then
4055 Buffer_Remove ('"');
4056 else
4057 Set_Msg_Quote;
4058 end if;
4059 end if;
4061 -- If the original type did not come from a predefined file, add the
4062 -- location where the type was defined.
4064 if Sloc (Error_Msg_Node_1) > Standard_Location
4065 and then
4066 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
4067 then
4068 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
4069 Set_Msg_Str (" defined");
4070 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
4072 -- If it did come from a predefined file, deal with the case where
4073 -- this was a file with a generic instantiation from elsewhere.
4075 else
4076 if Sloc (Error_Msg_Node_1) > Standard_Location then
4077 declare
4078 Iloc : constant Source_Ptr :=
4079 Instantiation_Location (Sloc (Error_Msg_Node_1));
4081 begin
4082 if Iloc /= No_Location
4083 and then not Suppress_Instance_Location
4084 then
4085 Set_Msg_Str (" from instance");
4086 Set_Msg_Insertion_Line_Number (Iloc, Flag);
4087 end if;
4088 end;
4089 end if;
4090 end if;
4091 end Set_Msg_Insertion_Type_Reference;
4093 ---------------------------------
4094 -- Set_Msg_Insertion_Unit_Name --
4095 ---------------------------------
4097 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
4098 begin
4099 if Error_Msg_Unit_1 = No_Unit_Name then
4100 null;
4102 elsif Error_Msg_Unit_1 = Error_Unit_Name then
4103 Set_Msg_Blank;
4104 Set_Msg_Str ("<error>");
4106 else
4107 Get_Unit_Name_String (Global_Name_Buffer, Error_Msg_Unit_1, Suffix);
4108 Set_Msg_Blank;
4109 Set_Msg_Quote;
4110 Set_Msg_Name_Buffer;
4111 Set_Msg_Quote;
4112 end if;
4114 -- The following assignment ensures that a second percent insertion
4115 -- character will correspond to the Error_Msg_Unit_2 parameter.
4117 Error_Msg_Unit_1 := Error_Msg_Unit_2;
4118 end Set_Msg_Insertion_Unit_Name;
4120 ------------------
4121 -- Set_Msg_Node --
4122 ------------------
4124 procedure Set_Msg_Node (Node : Node_Id) is
4125 Loc : Source_Ptr;
4126 Ent : Entity_Id;
4127 Nam : Name_Id;
4129 begin
4130 case Nkind (Node) is
4131 when N_Designator =>
4132 Set_Msg_Node (Name (Node));
4133 Set_Msg_Char ('.');
4134 Set_Msg_Node (Identifier (Node));
4135 return;
4137 when N_Defining_Program_Unit_Name =>
4138 Set_Msg_Node (Name (Node));
4139 Set_Msg_Char ('.');
4140 Set_Msg_Node (Defining_Identifier (Node));
4141 return;
4143 when N_Expanded_Name
4144 | N_Selected_Component
4146 Set_Msg_Node (Prefix (Node));
4147 Set_Msg_Char ('.');
4148 Set_Msg_Node (Selector_Name (Node));
4149 return;
4151 when others =>
4152 null;
4153 end case;
4155 -- The only remaining possibilities are identifiers, defining
4156 -- identifiers, pragmas, and pragma argument associations.
4158 if Nkind (Node) = N_Pragma then
4159 Nam := Pragma_Name (Node);
4160 Loc := Sloc (Node);
4162 -- The other cases have Chars fields
4164 -- First deal with internal names, which generally represent something
4165 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4166 -- something with a Chars field that is not an internal name, use that.
4168 elsif Is_Internal_Name (Chars (Node))
4169 and then Nkind (Original_Node (Node)) in N_Has_Chars
4170 and then not Is_Internal_Name (Chars (Original_Node (Node)))
4171 then
4172 Nam := Chars (Original_Node (Node));
4173 Loc := Sloc (Original_Node (Node));
4175 -- Another shot for internal names, in the case of internal type names,
4176 -- we try to find a reasonable representation for the external name.
4178 elsif Is_Internal_Name (Chars (Node))
4179 and then
4180 ((Is_Entity_Name (Node)
4181 and then Present (Entity (Node))
4182 and then Is_Type (Entity (Node)))
4183 or else
4184 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
4185 then
4186 if Nkind (Node) = N_Identifier then
4187 Ent := Entity (Node);
4188 else
4189 Ent := Node;
4190 end if;
4192 Loc := Sloc (Ent);
4194 -- If the type is the designated type of an access_to_subprogram,
4195 -- then there is no name to provide in the call.
4197 if Ekind (Ent) = E_Subprogram_Type then
4198 return;
4200 -- Otherwise, we will be able to find some kind of name to output
4202 else
4203 Unwind_Internal_Type (Ent);
4204 Nam := Chars (Ent);
4205 end if;
4207 -- If not internal name, or if we could not find a reasonable possible
4208 -- substitution for the internal name, just use name in Chars field.
4210 else
4211 Nam := Chars (Node);
4212 Loc := Sloc (Node);
4213 end if;
4215 -- At this stage, the name to output is in Nam
4217 Get_Unqualified_Decoded_Name_String (Nam);
4219 -- Remove trailing upper case letters from the name (useful for
4220 -- dealing with some cases of internal names).
4222 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
4223 Name_Len := Name_Len - 1;
4224 end loop;
4226 -- If we have any of the names from standard that start with the
4227 -- characters "any " (e.g. Any_Type), then kill the message since
4228 -- almost certainly it is a junk cascaded message.
4230 if Name_Len > 4
4231 and then Name_Buffer (1 .. 4) = "any "
4232 then
4233 Kill_Message := True;
4234 end if;
4236 -- If we still have an internal name, kill the message (will only
4237 -- work if we already had errors!)
4239 if Is_Internal_Name then
4240 Kill_Message := True;
4241 end if;
4242 -- Remaining step is to adjust casing and possibly add 'Class
4244 Adjust_Name_Case (Global_Name_Buffer, Loc);
4245 Set_Msg_Name_Buffer;
4246 Add_Class;
4247 end Set_Msg_Node;
4249 ------------------
4250 -- Set_Msg_Text --
4251 ------------------
4253 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
4254 C : Character; -- Current character
4255 P : Natural; -- Current index;
4257 procedure Skip_Msg_Insertion_Warning (C : Character);
4258 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4259 -- sequences using < instead of ?). The caller has already bumped
4260 -- the pointer past the initial ? or < and C is set to this initial
4261 -- character (? or <). This procedure skips past the rest of the
4262 -- sequence. We do not need to set Msg_Insertion_Char, since this
4263 -- was already done during the message prescan.
4264 -- No validity check is performed as the insertion sequence is
4265 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4266 -- erroutc.adb for the validity checks.
4268 --------------------------------
4269 -- Skip_Msg_Insertion_Warning --
4270 --------------------------------
4272 procedure Skip_Msg_Insertion_Warning (C : Character) is
4273 begin
4274 if P <= Text'Last and then Text (P) = C then
4275 P := P + 1;
4277 elsif P < Text'Last and then Text (P + 1) = C
4278 and then Text (P) in 'a' .. 'z' | 'A' .. 'Z' |
4279 '0' .. '9' | '*' | '$'
4280 then
4281 P := P + 2;
4283 elsif P + 1 < Text'Last and then Text (P + 2) = C
4284 and then Text (P) in '.' | '_'
4285 and then Text (P + 1) in 'a' .. 'z'
4286 then
4287 P := P + 3;
4288 end if;
4289 end Skip_Msg_Insertion_Warning;
4291 -- Start of processing for Set_Msg_Text
4293 begin
4294 Manual_Quote_Mode := False;
4295 Msglen := 0;
4296 Flag_Source := Get_Source_File_Index (Flag);
4298 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4299 -- will be used (Info field in error message object) to put back the
4300 -- string when it is printed. We need to do this, or we get confused
4301 -- with instantiation continuations.
4303 if Text'Length > 6
4304 and then Text (Text'First .. Text'First + 5) = "info: "
4305 then
4306 P := Text'First + 6;
4307 else
4308 P := Text'First;
4309 end if;
4311 -- Loop through characters of message
4313 while P <= Text'Last loop
4314 C := Text (P);
4315 P := P + 1;
4317 -- Check for insertion character or sequence
4319 case C is
4320 when '%' =>
4321 if P <= Text'Last and then Text (P) = '%' then
4322 P := P + 1;
4323 Set_Msg_Insertion_Name_Literal;
4324 else
4325 Set_Msg_Insertion_Name;
4326 end if;
4328 when '$' =>
4329 if P <= Text'Last and then Text (P) = '$' then
4330 P := P + 1;
4331 Set_Msg_Insertion_Unit_Name (Suffix => False);
4332 else
4333 Set_Msg_Insertion_Unit_Name;
4334 end if;
4336 when '{' =>
4337 Set_Msg_Insertion_File_Name;
4339 when '}' =>
4340 Set_Msg_Insertion_Type_Reference (Flag);
4342 when '*' =>
4343 Set_Msg_Insertion_Reserved_Name;
4345 when '&' =>
4346 Set_Msg_Insertion_Node;
4348 when '#' =>
4349 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
4351 when '\' =>
4352 Continuation := True;
4354 if P <= Text'Last and then Text (P) = '\' then
4355 Continuation_New_Line := True;
4356 P := P + 1;
4357 end if;
4359 when '@' =>
4360 Set_Msg_Insertion_Column;
4362 when '>' =>
4363 Set_Msg_Insertion_Run_Time_Name;
4365 when '^' =>
4366 Set_Msg_Insertion_Uint;
4368 when '`' =>
4369 Manual_Quote_Mode := not Manual_Quote_Mode;
4370 Set_Msg_Char ('"');
4372 when '!' =>
4373 null; -- already dealt with
4375 when '?' =>
4376 Skip_Msg_Insertion_Warning ('?');
4378 when '<' =>
4379 Skip_Msg_Insertion_Warning ('<');
4381 when '|' =>
4382 null; -- already dealt with
4384 when ''' =>
4385 Set_Msg_Char (Text (P));
4386 P := P + 1;
4388 when '~' =>
4389 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
4391 -- Upper case letter
4393 when 'A' .. 'Z' =>
4395 -- Start of reserved word if two or more
4397 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
4398 P := P - 1;
4399 Set_Msg_Insertion_Reserved_Word (Text, P);
4401 -- Single upper case letter is just inserted
4403 else
4404 Set_Msg_Char (C);
4405 end if;
4407 -- '[' (will be/would have been raised at run time)
4409 when '[' =>
4411 -- "[]" (insertion of error code)
4413 if P <= Text'Last and then Text (P) = ']' then
4414 P := P + 1;
4415 Set_Msg_Insertion_Code;
4417 else
4418 -- Switch the message from a warning to an error if the flag
4419 -- -gnatwE is specified to treat run-time exception warnings
4420 -- as errors.
4422 if Is_Warning_Msg
4423 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
4424 then
4425 Is_Warning_Msg := False;
4426 Is_Runtime_Raise := True;
4427 end if;
4429 if Is_Warning_Msg then
4430 Set_Msg_Str ("will be raised at run time");
4431 else
4432 Set_Msg_Str ("would have been raised at run time");
4433 end if;
4434 end if;
4436 -- ']' (may be/might have been raised at run time)
4438 when ']' =>
4439 if Is_Warning_Msg then
4440 Set_Msg_Str ("may be raised at run time");
4441 else
4442 Set_Msg_Str ("might have been raised at run time");
4443 end if;
4445 -- Normal character with no special treatment
4447 when others =>
4448 Set_Msg_Char (C);
4449 end case;
4450 end loop;
4451 end Set_Msg_Text;
4453 ----------------
4454 -- Set_Posted --
4455 ----------------
4457 procedure Set_Posted (N : Node_Id) is
4458 P : Node_Id;
4460 begin
4461 if Is_Serious_Error then
4463 -- We always set Error_Posted on the node itself
4465 Set_Error_Posted (N);
4467 -- If it is a subexpression, then set Error_Posted on parents up to
4468 -- and including the first non-subexpression construct. This helps
4469 -- avoid cascaded error messages within a single expression.
4471 P := N;
4472 loop
4473 P := Parent (P);
4474 exit when No (P);
4475 Set_Error_Posted (P);
4476 exit when Nkind (P) not in N_Subexpr;
4477 end loop;
4479 if Nkind (P) in N_Pragma_Argument_Association
4480 | N_Component_Association
4481 | N_Discriminant_Association
4482 | N_Generic_Association
4483 | N_Parameter_Association
4484 then
4485 Set_Error_Posted (Parent (P));
4486 end if;
4488 -- A special check, if we just posted an error on an attribute
4489 -- definition clause, then also set the entity involved as posted.
4490 -- For example, this stops complaining about the alignment after
4491 -- complaining about the size, which is likely to be useless.
4493 if Nkind (P) = N_Attribute_Definition_Clause then
4494 if Is_Entity_Name (Name (P)) then
4495 Set_Error_Posted (Entity (Name (P)));
4496 end if;
4497 end if;
4498 end if;
4499 end Set_Posted;
4501 -----------------------
4502 -- Set_Qualification --
4503 -----------------------
4505 procedure Set_Qualification (N : Nat; E : Entity_Id) is
4506 begin
4507 if N /= 0 and then Scope (E) /= Standard_Standard then
4508 Set_Qualification (N - 1, Scope (E));
4509 Set_Msg_Node (Scope (E));
4510 Set_Msg_Char ('.');
4511 end if;
4512 end Set_Qualification;
4514 -------------------------------------
4515 -- Should_Ignore_Pragma_SPARK_Mode --
4516 -------------------------------------
4518 function Should_Ignore_Pragma_SPARK_Mode return Boolean is
4519 begin
4520 return Get_Name_Table_Boolean3 (Name_SPARK_Mode);
4521 end Should_Ignore_Pragma_SPARK_Mode;
4523 ------------------------
4524 -- Special_Msg_Delete --
4525 ------------------------
4527 -- Is it really right to have all this specialized knowledge in errout?
4529 function Special_Msg_Delete
4530 (Msg : String;
4531 N : Node_Or_Entity_Id;
4532 E : Node_Or_Entity_Id) return Boolean
4534 begin
4535 -- Never delete messages in -gnatdO mode
4537 if Debug_Flag_OO then
4538 return False;
4540 -- Processing for "Size too small" messages
4542 elsif Is_Size_Too_Small_Message (Msg) then
4544 -- Suppress "size too small" errors in CodePeer mode, since code may
4545 -- be analyzed in a different configuration than the one used for
4546 -- compilation. Even when the configurations match, this message
4547 -- may be issued on correct code, because pragma Pack is ignored
4548 -- in CodePeer mode.
4550 if CodePeer_Mode then
4551 return True;
4553 -- When a size is wrong for a frozen type there is no explicit size
4554 -- clause, and other errors have occurred, suppress the message,
4555 -- since it is likely that this size error is a cascaded result of
4556 -- other errors. The reason we eliminate unfrozen types is that
4557 -- messages issued before the freeze type are for sure OK.
4559 elsif Nkind (N) in N_Entity
4560 and then Is_Frozen (E)
4561 and then Serious_Errors_Detected > 0
4562 and then Nkind (N) /= N_Component_Clause
4563 and then Nkind (Parent (N)) /= N_Component_Clause
4564 and then
4565 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
4566 and then
4567 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
4568 and then
4569 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
4570 then
4571 return True;
4572 end if;
4573 end if;
4575 -- All special tests complete, so go ahead with message
4577 return False;
4578 end Special_Msg_Delete;
4580 -----------------
4581 -- SPARK_Msg_N --
4582 -----------------
4584 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
4585 begin
4586 -- If SPARK_Mode is Off, we do not report SPARK legality errors to give
4587 -- the flexibility to opt out of SPARK checking completely. We do the
4588 -- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
4589 -- for tools to ignore SPARK checking even on SPARK code.
4591 if SPARK_Mode /= Off
4592 and then not Should_Ignore_Pragma_SPARK_Mode
4593 then
4594 Error_Msg_N (Msg, N);
4595 end if;
4596 end SPARK_Msg_N;
4598 ------------------
4599 -- SPARK_Msg_NE --
4600 ------------------
4602 procedure SPARK_Msg_NE
4603 (Msg : String;
4604 N : Node_Or_Entity_Id;
4605 E : Node_Or_Entity_Id)
4607 begin
4608 if SPARK_Mode /= Off
4609 and then not Should_Ignore_Pragma_SPARK_Mode
4610 then
4611 Error_Msg_NE (Msg, N, E);
4612 end if;
4613 end SPARK_Msg_NE;
4615 --------------------------
4616 -- Unwind_Internal_Type --
4617 --------------------------
4619 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
4620 Derived : Boolean := False;
4621 Mchar : Character;
4622 Old_Ent : Entity_Id;
4624 begin
4625 -- Undo placement of a quote, since we will put it back later
4627 Mchar := Msg_Buffer (Msglen);
4629 if Mchar = '"' then
4630 Msglen := Msglen - 1;
4631 end if;
4633 -- The loop here deals with recursive types, we are trying to find a
4634 -- related entity that is not an implicit type. Note that the check with
4635 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4636 -- "type derived from" message more than once in the case where we climb
4637 -- up multiple levels.
4639 Find : loop
4640 Old_Ent := Ent;
4642 -- Implicit access type, use directly designated type In Ada 2005,
4643 -- the designated type may be an anonymous access to subprogram, in
4644 -- which case we can only point to its definition.
4646 if Is_Access_Type (Ent) then
4647 if Ekind (Ent) = E_Access_Subprogram_Type
4648 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
4649 or else Is_Access_Protected_Subprogram_Type (Ent)
4650 then
4651 Ent := Directly_Designated_Type (Ent);
4653 if not Comes_From_Source (Ent) then
4654 if Buffer_Ends_With ("type ") then
4655 Buffer_Remove ("type ");
4656 end if;
4657 end if;
4659 if Ekind (Ent) = E_Function then
4660 Set_Msg_Str ("access to function ");
4661 elsif Ekind (Ent) = E_Procedure then
4662 Set_Msg_Str ("access to procedure ");
4663 else
4664 Set_Msg_Str ("access to subprogram");
4665 end if;
4667 exit Find;
4669 -- Type is access to object, named or anonymous
4671 else
4672 Set_Msg_Str ("access to ");
4673 Ent := Directly_Designated_Type (Ent);
4674 end if;
4676 -- Classwide type
4678 elsif Is_Class_Wide_Type (Ent) then
4679 Class_Flag := True;
4680 Ent := Root_Type (Ent);
4682 -- Use base type if this is a subtype
4684 elsif Ent /= Base_Type (Ent) then
4685 Buffer_Remove ("type ");
4687 -- Avoid duplication "subtype of subtype of", and also replace
4688 -- "derived from subtype of" simply by "derived from"
4690 if not Buffer_Ends_With ("subtype of ")
4691 and then not Buffer_Ends_With ("derived from ")
4692 then
4693 Set_Msg_Str ("subtype of ");
4694 end if;
4696 Ent := Base_Type (Ent);
4698 -- If this is a base type with a first named subtype, use the first
4699 -- named subtype instead. This is not quite accurate in all cases,
4700 -- but it makes too much noise to be accurate and add 'Base in all
4701 -- cases. Note that we only do this is the first named subtype is not
4702 -- itself an internal name. This avoids the obvious loop (subtype ->
4703 -- basetype -> subtype) which would otherwise occur).
4705 else
4706 declare
4707 FST : constant Entity_Id := First_Subtype (Ent);
4709 begin
4710 if not Is_Internal_Name (Chars (FST)) then
4711 Ent := FST;
4712 exit Find;
4714 -- Otherwise use root type
4716 else
4717 if not Derived then
4718 Buffer_Remove ("type ");
4720 -- Test for "subtype of type derived from" which seems
4721 -- excessive and is replaced by "type derived from".
4723 Buffer_Remove ("subtype of");
4725 -- Avoid duplicated "type derived from type derived from"
4727 if not Buffer_Ends_With ("type derived from ") then
4728 Set_Msg_Str ("type derived from ");
4729 end if;
4731 Derived := True;
4732 end if;
4733 end if;
4734 end;
4736 Ent := Etype (Ent);
4737 end if;
4739 -- If we are stuck in a loop, get out and settle for the internal
4740 -- name after all. In this case we set to kill the message if it is
4741 -- not the first error message (we really try hard not to show the
4742 -- dirty laundry of the implementation to the poor user).
4744 if Ent = Old_Ent then
4745 Kill_Message := True;
4746 exit Find;
4747 end if;
4749 -- Get out if we finally found a non-internal name to use
4751 exit Find when not Is_Internal_Name (Chars (Ent));
4752 end loop Find;
4754 if Mchar = '"' then
4755 Set_Msg_Char ('"');
4756 end if;
4757 end Unwind_Internal_Type;
4759 --------------------
4760 -- Warn_Insertion --
4761 --------------------
4763 function Warn_Insertion return String is
4764 begin
4765 if Warning_Msg_Char = "? " then
4766 return "??";
4767 elsif Warning_Msg_Char = " " then
4768 return "?";
4769 elsif Warning_Msg_Char (2) = ' ' then
4770 return '?' & Warning_Msg_Char (1) & '?';
4771 else
4772 return '?' & Warning_Msg_Char & '?';
4773 end if;
4774 end Warn_Insertion;
4776 end Errout;