Debian Codegraph @

gcc/ada/erroutc.adb

raw
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E R R O U T C --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2025, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
25
26 -- Warning: Error messages can be generated during Gigi processing by direct
27 -- calls to error message routines, so it is essential that the processing
28 -- in this body be consistent with the requirements for the Gigi processing
29 -- environment, and that in particular, no disallowed table expansion is
30 -- allowed to occur.
31
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Csets; use Csets;
35 with Debug; use Debug;
36 with Err_Vars; use Err_Vars;
37 with Fname; use Fname;
38 with Namet; use Namet;
39 with Opt; use Opt;
40 with Output; use Output;
41 with Sinfo.Nodes;
42 with Sinput; use Sinput;
43 with Snames; use Snames;
44 with Stringt; use Stringt;
45 with Stylesw; use Stylesw;
46 with Targparm;
47 with Uintp; use Uintp;
48 with Widechar; use Widechar;
49 with Warnsw; use Warnsw;
50
51 package body Erroutc is
52
53 -----------------------
54 -- Local Subprograms --
55 -----------------------
56
57 function Sloc_In_Range (Loc, Start, Stop : Source_Ptr) return Boolean;
58 -- Return whether Loc is in the range Start .. Stop, taking instantiation
59 -- locations of Loc into account. This is useful for suppressing warnings
60 -- from generic instantiations by using pragma Warnings around generic
61 -- instances, as needed in GNATprove.
62
63 function Has_Switch_Tag (Id : Error_Msg_Id) return Boolean;
64 function Has_Switch_Tag (E_Msg : Error_Msg_Object) return Boolean;
65 -- Returns True if the E_Msg is Warning, Style or Info and has a non-empty
66 -- Warn_Char.
67
68 ---------------
69 -- Add_Class --
70 ---------------
71
72 procedure Add_Class is
73 begin
74 if Class_Flag then
75 Class_Flag := False;
76 Set_Msg_Char (''');
77 Get_Name_String (Name_Class);
78 Set_Casing (Identifier_Casing (Flag_Source));
79 Set_Msg_Name_Buffer;
80 end if;
81 end Add_Class;
82
83 ----------------------
84 -- Buffer_Ends_With --
85 ----------------------
86
87 function Buffer_Ends_With (C : Character) return Boolean is
88 begin
89 return Msglen > 0 and then Msg_Buffer (Msglen) = C;
90 end Buffer_Ends_With;
91
92 function Buffer_Ends_With (S : String) return Boolean is
93 Len : constant Natural := S'Length;
94 begin
95 return Msglen > Len
96 and then Msg_Buffer (Msglen - Len) = ' '
97 and then Msg_Buffer (Msglen - Len + 1 .. Msglen) = S;
98 end Buffer_Ends_With;
99
100 -------------------
101 -- Buffer_Remove --
102 -------------------
103
104 procedure Buffer_Remove (C : Character) is
105 begin
106 if Buffer_Ends_With (C) then
107 Msglen := Msglen - 1;
108 end if;
109 end Buffer_Remove;
110
111 procedure Buffer_Remove (S : String) is
112 begin
113 if Buffer_Ends_With (S) then
114 Msglen := Msglen - S'Length;
115 end if;
116 end Buffer_Remove;
117
118 -----------------------------
119 -- Check_Duplicate_Message --
120 -----------------------------
121
122 procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id) is
123 L1, L2 : Error_Msg_Id;
124 N1, N2 : Error_Msg_Id;
125
126 procedure Delete_Msg (Delete, Keep : Error_Msg_Id);
127 -- Called to delete message Delete, keeping message Keep. Marks msg
128 -- Delete and all its continuations with deleted flag set to True.
129 -- Also makes sure that for the error messages that are retained the
130 -- preferred message is the one retained (we prefer the shorter one in
131 -- the case where one has an Instance tag). Note that we always know
132 -- that Keep has at least as many continuations as Delete (since we
133 -- always delete the shorter sequence).
134
135 ----------------
136 -- Delete_Msg --
137 ----------------
138
139 procedure Delete_Msg (Delete, Keep : Error_Msg_Id) is
140 D, K : Error_Msg_Id;
141
142 begin
143 D := Delete;
144 K := Keep;
145
146 loop
147 Errors.Table (D).Deleted := True;
148
149 Decrease_Error_Msg_Count (Errors.Table (D));
150
151 -- Substitute shorter of the two error messages
152
153 if Errors.Table (K).Text'Length > Errors.Table (D).Text'Length then
154 Errors.Table (K).Text := Errors.Table (D).Text;
155 end if;
156
157 D := Errors.Table (D).Next;
158 K := Errors.Table (K).Next;
159
160 if D = No_Error_Msg or else not Errors.Table (D).Msg_Cont then
161 return;
162 end if;
163 end loop;
164 end Delete_Msg;
165
166 -- Start of processing for Check_Duplicate_Message
167
168 begin
169 -- Both messages must be non-continuation messages and not deleted
170
171 if Errors.Table (M1).Msg_Cont
172 or else Errors.Table (M2).Msg_Cont
173 or else Errors.Table (M1).Deleted
174 or else Errors.Table (M2).Deleted
175 then
176 return;
177 end if;
178
179 -- Definitely not equal if message text does not match
180
181 if not Same_Error (M1, M2) then
182 return;
183 end if;
184
185 -- Same text. See if all continuations are also identical
186
187 L1 := M1;
188 L2 := M2;
189
190 loop
191 N1 := Errors.Table (L1).Next;
192 N2 := Errors.Table (L2).Next;
193
194 -- If M1 continuations have run out, we delete M1, either the
195 -- messages have the same number of continuations, or M2 has
196 -- more and we prefer the one with more anyway.
197
198 if N1 = No_Error_Msg or else not Errors.Table (N1).Msg_Cont then
199 Delete_Msg (M1, M2);
200 return;
201
202 -- If M2 continuations have run out, we delete M2
203
204 elsif N2 = No_Error_Msg or else not Errors.Table (N2).Msg_Cont then
205 Delete_Msg (M2, M1);
206 return;
207
208 -- Otherwise see if continuations are the same, if not, keep both
209 -- sequences, a curious case, but better to keep everything.
210
211 elsif not Same_Error (N1, N2) then
212 return;
213
214 -- If continuations are the same, continue scan
215
216 else
217 L1 := N1;
218 L2 := N2;
219 end if;
220 end loop;
221 end Check_Duplicate_Message;
222
223 ------------------------
224 -- Compilation_Errors --
225 ------------------------
226
227 function Compilation_Errors return Boolean is
228 Warnings_Count : constant Int := Warnings_Detected;
229 begin
230 if Total_Errors_Detected /= 0 then
231 return True;
232
233 elsif Warnings_Treated_As_Errors /= 0 then
234 return True;
235
236 -- We should never treat warnings that originate from a
237 -- Compile_Time_Warning pragma as an error. Warnings_Count is the sum
238 -- of both "normal" and Compile_Time_Warning warnings. This means that
239 -- there are only one or more non-Compile_Time_Warning warnings when
240 -- Warnings_Count is greater than Count_Compile_Time_Pragma_Warnings.
241
242 elsif Warning_Mode = Treat_As_Error
243 and then Warnings_Count > Count_Compile_Time_Pragma_Warnings
244 then
245 return True;
246 end if;
247
248 return False;
249 end Compilation_Errors;
250
251 ----------------------------------------
252 -- Count_Compile_Time_Pragma_Warnings --
253 ----------------------------------------
254
255 function Count_Compile_Time_Pragma_Warnings return Int is
256 Result : Int := 0;
257 begin
258 for J in 1 .. Errors.Last loop
259 begin
260 if Errors.Table (J).Kind = Warning
261 and then Errors.Table (J).Compile_Time_Pragma
262 and then not Errors.Table (J).Deleted
263 then
264 Result := Result + 1;
265 end if;
266 end;
267 end loop;
268 return Result;
269 end Count_Compile_Time_Pragma_Warnings;
270
271 ------------------------------
272 -- Decrease_Error_Msg_Count --
273 ------------------------------
274
275 procedure Decrease_Error_Msg_Count (E : Error_Msg_Object) is
276
277 begin
278 case E.Kind is
279 when Info =>
280 Info_Messages := Info_Messages - 1;
281
282 when Warning | Style =>
283 Warnings_Detected := Warnings_Detected - 1;
284
285 when High_Check | Medium_Check | Low_Check =>
286 Check_Messages := Check_Messages - 1;
287
288 when Error =>
289 Total_Errors_Detected := Total_Errors_Detected - 1;
290 Serious_Errors_Detected := Serious_Errors_Detected - 1;
291
292 when Non_Serious_Error =>
293 Total_Errors_Detected := Total_Errors_Detected - 1;
294 end case;
295 end Decrease_Error_Msg_Count;
296
297 ------------------
298 -- Debug_Output --
299 ------------------
300
301 procedure Debug_Output (N : Node_Id) is
302 begin
303 if Debug_Flag_1 then
304 Write_Str ("*** following error message posted on node id = #");
305 Write_Int (Int (N));
306 Write_Str (" ***");
307 Write_Eol;
308 end if;
309 end Debug_Output;
310
311 ----------
312 -- dmsg --
313 ----------
314
315 procedure dmsg (Id : Error_Msg_Id) is
316 E : Error_Msg_Object renames Errors.Table (Id);
317
318 begin
319 w ("Dumping error message, Id = ", Int (Id));
320 w (" Text = ", E.Text.all);
321 w (" Next = ", Int (E.Next));
322 w (" Prev = ", Int (E.Prev));
323 w (" Sfile = ", Int (E.Sfile));
324
325 Write_Str
326 (" Sptr = ");
327 Write_Location (E.Sptr.Ptr); -- ??? Do not write the full span for now
328 Write_Eol;
329
330 Write_Str
331 (" Optr = ");
332 Write_Location (E.Optr.Ptr);
333 Write_Eol;
334
335 Write_Str
336 (" Insertion_Sloc = ");
337 Write_Location (E.Insertion_Sloc);
338 Write_Eol;
339
340 w (" Line = ", Int (E.Line));
341 w (" Col = ", Int (E.Col));
342 w (" Kind = ", E.Kind'Img);
343 w (" Warn_Err = ", E.Warn_Err);
344 w (" Warn_Chr = '" & E.Warn_Chr & ''');
345 w (" Uncond = ", E.Uncond);
346 w (" Msg_Cont = ", E.Msg_Cont);
347 w (" Deleted = ", E.Deleted);
348
349 Write_Eol;
350 end dmsg;
351
352 ------------------
353 -- Get_Location --
354 ------------------
355
356 function Get_Location (E : Error_Msg_Id) return Source_Ptr is
357 begin
358 return Errors.Table (E).Sptr.Ptr;
359 end Get_Location;
360
361 ----------------
362 -- Get_Msg_Id --
363 ----------------
364
365 function Get_Msg_Id return Error_Msg_Id is
366 begin
367 return Cur_Msg;
368 end Get_Msg_Id;
369
370 ------------------------
371 -- Get_Warning_Option --
372 ------------------------
373
374 function Get_Warning_Option (Id : Error_Msg_Id) return String is
375 Is_Style : constant Boolean := Errors.Table (Id).Kind in Style;
376 Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr;
377
378 begin
379 if Has_Switch_Tag (Errors.Table (Id))
380 and then Warn_Chr (1) /= '?'
381 then
382 if Warn_Chr = "$ " then
383 return "-gnatel";
384 elsif Is_Style then
385 return "-gnaty" & Warn_Chr (1);
386 elsif Warn_Chr (2) = ' ' then
387 return "-gnatw" & Warn_Chr (1);
388 else
389 return "-gnatw" & Warn_Chr;
390 end if;
391 end if;
392
393 return "";
394 end Get_Warning_Option;
395
396 ---------------------
397 -- Get_Warning_Tag --
398 ---------------------
399
400 function Get_Warning_Tag (Id : Error_Msg_Id) return String is
401 Warn_Chr : constant String (1 .. 2) := Errors.Table (Id).Warn_Chr;
402 Option : constant String := Get_Warning_Option (Id);
403
404 begin
405 if Has_Switch_Tag (Id) then
406 if Warn_Chr = "? " then
407 return "[enabled by default]";
408 elsif Warn_Chr = "* " then
409 return "[restriction warning]";
410 elsif Option /= "" then
411 return "[" & Option & "]";
412 end if;
413 end if;
414
415 return "";
416 end Get_Warning_Tag;
417
418 ------------------------------
419 -- Increase_Error_Msg_Count --
420 ------------------------------
421
422 procedure Increase_Error_Msg_Count (E : Error_Msg_Object) is
423
424 begin
425 case E.Kind is
426 when Info =>
427 Info_Messages := Info_Messages + 1;
428
429 when Warning | Style =>
430 Warnings_Detected := Warnings_Detected + 1;
431
432 when High_Check | Medium_Check | Low_Check =>
433 Check_Messages := Check_Messages + 1;
434
435 when Error =>
436 Total_Errors_Detected := Total_Errors_Detected + 1;
437 Serious_Errors_Detected := Serious_Errors_Detected + 1;
438
439 when Non_Serious_Error =>
440 Total_Errors_Detected := Total_Errors_Detected + 1;
441 end case;
442 end Increase_Error_Msg_Count;
443
444 --------------------------------
445 -- Is_Redundant_Error_Message --
446 --------------------------------
447
448 function Is_Redundant_Error_Message
449 (Prev_Msg : Error_Msg_Id; Cur_Msg : Error_Msg_Id) return Boolean is
450
451 begin
452 return
453 Prev_Msg /= No_Error_Msg
454
455 -- Error messages are posted on the same line
456
457 and then Errors.Table (Prev_Msg).Line = Errors.Table (Cur_Msg).Line
458 and then Errors.Table (Prev_Msg).Sfile = Errors.Table (Cur_Msg).Sfile
459
460 -- Do not consider unconditional messages to be redundant right now
461 -- They may be removed later.
462
463 and then not Errors.Table (Cur_Msg).Uncond
464
465 -- Do not consider continuation messages as they are removed with
466 -- their parent later on.
467
468 and then not Errors.Table (Cur_Msg).Msg_Cont
469
470 -- Don't delete if prev msg is warning and new msg is an error.
471 -- This is because we don't want a real error masked by a
472 -- warning. In all other cases (that is parse errors for the
473 -- same line that are not unconditional) we do delete the
474 -- message. This helps to avoid junk extra messages from
475 -- cascaded parsing errors
476
477 and then (Errors.Table (Prev_Msg).Kind not in Warning | Style
478 or else Errors.Table (Cur_Msg).Kind in Warning | Style);
479 end Is_Redundant_Error_Message;
480
481 --------------------
482 -- Has_Switch_Tag --
483 --------------------
484
485 function Has_Switch_Tag (Id : Error_Msg_Id) return Boolean
486 is (Has_Switch_Tag (Errors.Table (Id)));
487
488 function Has_Switch_Tag (E_Msg : Error_Msg_Object) return Boolean is
489 begin
490 return
491 E_Msg.Kind in Warning | Info | Style and then E_Msg.Warn_Chr /= " ";
492 end Has_Switch_Tag;
493
494 -------------
495 -- Matches --
496 -------------
497
498 function Matches (S : String; P : String) return Boolean is
499 Slast : constant Natural := S'Last;
500 PLast : constant Natural := P'Last;
501
502 SPtr : Natural := S'First;
503 PPtr : Natural := P'First;
504
505 begin
506 -- Loop advancing through characters of string and pattern
507
508 SPtr := S'First;
509 PPtr := P'First;
510 loop
511 -- Return True if pattern is a single asterisk
512
513 if PPtr = PLast and then P (PPtr) = '*' then
514 return True;
515
516 -- Return True if both pattern and string exhausted
517
518 elsif PPtr > PLast and then SPtr > Slast then
519 return True;
520
521 -- Return False, if one exhausted and not the other
522
523 elsif PPtr > PLast or else SPtr > Slast then
524 return False;
525
526 -- Case where pattern starts with asterisk
527
528 elsif P (PPtr) = '*' then
529
530 -- Try all possible starting positions in S for match with the
531 -- remaining characters of the pattern. This is the recursive
532 -- call that implements the scanner backup.
533
534 for J in SPtr .. Slast loop
535 if Matches (S (J .. Slast), P (PPtr + 1 .. PLast)) then
536 return True;
537 end if;
538 end loop;
539
540 return False;
541
542 -- Dealt with end of string and *, advance if we have a match
543
544 elsif Fold_Lower (S (SPtr)) = Fold_Lower (P (PPtr)) then
545 SPtr := SPtr + 1;
546 PPtr := PPtr + 1;
547
548 -- If first characters do not match, that's decisive
549
550 else
551 return False;
552 end if;
553 end loop;
554 end Matches;
555
556 -----------------------
557 -- Output_Error_Msgs --
558 -----------------------
559
560 procedure Output_Error_Msgs (E : in out Error_Msg_Id) is
561 P : Source_Ptr;
562 T : Error_Msg_Id;
563 S : Error_Msg_Id;
564
565 Flag_Num : Pos;
566 Mult_Flags : Boolean := False;
567
568 begin
569 S := E;
570
571 -- Skip deleted messages at start
572
573 if Errors.Table (S).Deleted then
574 Set_Next_Non_Deleted_Msg (S);
575 end if;
576
577 -- Figure out if we will place more than one error flag on this line
578
579 T := S;
580 while T /= No_Error_Msg
581 and then Errors.Table (T).Line = Errors.Table (E).Line
582 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
583 loop
584 if Errors.Table (T).Sptr.Ptr > Errors.Table (E).Sptr.Ptr then
585 Mult_Flags := True;
586 end if;
587
588 Set_Next_Non_Deleted_Msg (T);
589 end loop;
590
591 -- Output the error flags. The circuit here makes sure that the tab
592 -- characters in the original line are properly accounted for. The
593 -- eight blanks at the start are to match the line number.
594
595 if not Debug_Flag_2 then
596 Write_Str (" ");
597 P := Line_Start (Errors.Table (E).Sptr.Ptr);
598 Flag_Num := 1;
599
600 -- Loop through error messages for this line to place flags
601
602 T := S;
603 while T /= No_Error_Msg
604 and then Errors.Table (T).Line = Errors.Table (E).Line
605 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
606 loop
607 declare
608 Src : Source_Buffer_Ptr
609 renames Source_Text (Errors.Table (T).Sfile);
610
611 begin
612 -- Loop to output blanks till current flag position
613
614 while P < Errors.Table (T).Sptr.Ptr loop
615
616 -- Horizontal tab case, just echo the tab
617
618 if Src (P) = ASCII.HT then
619 Write_Char (ASCII.HT);
620 P := P + 1;
621
622 -- Deal with wide character case, but don't include brackets
623 -- notation in this circuit, since we know that this will
624 -- display unencoded (no one encodes brackets notation).
625
626 elsif Src (P) /= '['
627 and then Is_Start_Of_Wide_Char (Src, P)
628 then
629 Skip_Wide (Src, P);
630 Write_Char (' ');
631
632 -- Normal non-wide character case (or bracket)
633
634 else
635 P := P + 1;
636 Write_Char (' ');
637 end if;
638 end loop;
639
640 -- Output flag (unless already output, this happens if more
641 -- than one error message occurs at the same flag position).
642
643 if P = Errors.Table (T).Sptr.Ptr then
644 if (Flag_Num = 1 and then not Mult_Flags)
645 or else Flag_Num > 9
646 then
647 Write_Char ('|');
648 else
649 Write_Char
650 (Character'Val (Character'Pos ('0') + Flag_Num));
651 end if;
652
653 -- Skip past the corresponding source text character
654
655 -- Horizontal tab case, we output a flag at the tab position
656 -- so now we output a tab to match up with the text.
657
658 if Src (P) = ASCII.HT then
659 Write_Char (ASCII.HT);
660 P := P + 1;
661
662 -- Skip wide character other than left bracket
663
664 elsif Src (P) /= '['
665 and then Is_Start_Of_Wide_Char (Src, P)
666 then
667 Skip_Wide (Src, P);
668
669 -- Skip normal non-wide character case (or bracket)
670
671 else
672 P := P + 1;
673 end if;
674 end if;
675 end;
676
677 Set_Next_Non_Deleted_Msg (T);
678 Flag_Num := Flag_Num + 1;
679 end loop;
680
681 Write_Eol;
682 end if;
683
684 -- Now output the error messages
685
686 T := S;
687 while T /= No_Error_Msg
688 and then Errors.Table (T).Line = Errors.Table (E).Line
689 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
690 loop
691 Write_Str (" >>> ");
692 Output_Msg_Text (T);
693
694 if Debug_Flag_2 then
695 while Column < 74 loop
696 Write_Char (' ');
697 end loop;
698
699 Write_Str (" <<<");
700 end if;
701
702 Write_Eol;
703 Set_Next_Non_Deleted_Msg (T);
704 end loop;
705
706 E := T;
707 end Output_Error_Msgs;
708
709 ------------------------
710 -- Output_Line_Number --
711 ------------------------
712
713 procedure Output_Line_Number (L : Logical_Line_Number) is
714 D : Int; -- next digit
715 C : Character; -- next character
716 Z : Boolean; -- flag for zero suppress
717 N, M : Int; -- temporaries
718
719 begin
720 if L = No_Line_Number then
721 Write_Str (" ");
722
723 else
724 Z := False;
725 N := Int (L);
726
727 M := 100_000;
728 while M /= 0 loop
729 D := Int (N / M);
730 N := N rem M;
731 M := M / 10;
732
733 if D = 0 then
734 if Z then
735 C := '0';
736 else
737 C := ' ';
738 end if;
739 else
740 Z := True;
741 C := Character'Val (D + 48);
742 end if;
743
744 Write_Char (C);
745 end loop;
746
747 Write_Str (". ");
748 end if;
749 end Output_Line_Number;
750
751 ------------------------
752 -- Output_Text_Within --
753 ------------------------
754
755 procedure Output_Text_Within (Txt : String_Ptr; Line_Length : Nat) is
756 Offs : constant Nat := Column - 1;
757 -- Offset to start of message, used for continuations
758
759 Ptr : Natural;
760
761 Split : Natural;
762 -- Position where a new line was inserted in the original message
763
764 Start : Natural;
765 -- Start of the current line
766
767 Max : Integer := Integer (Line_Length - Column + 1);
768 -- Maximum characters to output on next line
769
770 Text_Length : constant Natural := Txt'Length;
771 -- Length of the message
772
773 begin
774 -- Here we have to split the message up into multiple lines
775
776 Ptr := 1;
777 loop
778 -- Make sure we do not have ludicrously small line
779
780 Max := Integer'Max (Max, 20);
781
782 -- If remaining text fits, output it respecting LF and we are done
783
784 if Text_Length - Ptr < Max then
785 for J in Ptr .. Text_Length loop
786 if Txt (J) = ASCII.LF then
787 Write_Eol;
788 Write_Spaces (Offs);
789 else
790 Write_Char (Txt (J));
791 end if;
792 end loop;
793
794 return;
795
796 -- Line does not fit
797
798 else
799 Start := Ptr;
800
801 -- First scan forward looking for a hard end of line
802
803 for Scan in Ptr .. Ptr + Max - 1 loop
804 if Txt (Scan) = ASCII.LF then
805 Split := Scan - 1;
806 Ptr := Scan + 1;
807 goto Continue;
808 end if;
809 end loop;
810
811 -- Otherwise scan backwards looking for a space
812
813 for Scan in reverse Ptr .. Ptr + Max - 1 loop
814 if Txt (Scan) = ' ' then
815 Split := Scan - 1;
816 Ptr := Scan + 1;
817 goto Continue;
818 end if;
819 end loop;
820
821 -- If we fall through, no space, so split line arbitrarily
822
823 Split := Ptr + Max - 1;
824 Ptr := Split + 1;
825 end if;
826
827 <<Continue>>
828 if Start <= Split then
829 Write_Line (Txt (Start .. Split));
830 Write_Spaces (Offs);
831 end if;
832
833 Max := Integer (Line_Length - Column + 1);
834 end loop;
835 end Output_Text_Within;
836
837 -------------------------
838 -- Output_Msg_Location --
839 -------------------------
840
841 procedure Output_Msg_Location (E : Error_Msg_Id) is
842 E_Obj : constant Error_Msg_Object := Errors.Table (E);
843 begin
844 Write_Str (SGR_Locus);
845
846 if Full_Path_Name_For_Brief_Errors then
847 Write_Name (Full_Ref_Name (E_Obj.Sfile));
848 else
849 Write_Name (Reference_Name (E_Obj.Sfile));
850 end if;
851
852 Write_Char (':');
853 Write_Int (Int (Physical_To_Logical (E_Obj.Line, E_Obj.Sfile)));
854 Write_Char (':');
855
856 if E_Obj.Col < 10 then
857 Write_Char ('0');
858 end if;
859
860 Write_Int (Int (E_Obj.Col));
861 Write_Str (": ");
862
863 Write_Str (SGR_Reset);
864 end Output_Msg_Location;
865
866 ---------------------
867 -- Output_Msg_Text --
868 ---------------------
869
870 procedure Output_Msg_Text (E : Error_Msg_Id) is
871
872 E_Msg : Error_Msg_Object renames Errors.Table (E);
873 Text : constant String_Ptr := E_Msg.Text;
874 Tag : constant String := Get_Warning_Tag (E);
875 Txt : String_Ptr;
876
877 Line_Length : constant Nat :=
878 (if Error_Msg_Line_Length = 0 then Nat'Last
879 else Error_Msg_Line_Length);
880
881 begin
882 -- Postfix warning tag to message if needed
883
884 if Tag /= "" and then Warning_Doc_Switch then
885 Txt := new String'(Text.all & ' ' & Tag);
886 else
887 Txt := Text;
888 end if;
889
890 -- If -gnatdF is used, continuation messages follow the main message
891 -- with only an indentation of two space characters, without repeating
892 -- any prefix.
893
894 if Debug_Flag_FF and then E_Msg.Msg_Cont then
895 null;
896
897 -- For info messages, prefix message with "info: "
898
899 elsif E_Msg.Kind = Info then
900 Txt := new String'(SGR_Note & "info: " & SGR_Reset & Txt.all);
901
902 -- Warning treated as error
903
904 elsif E_Msg.Warn_Err then
905
906 -- We prefix with "error:" rather than warning: and postfix
907 -- [warning-as-error] at the end.
908
909 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors + 1;
910 Txt := new String'(SGR_Error & "error: " & SGR_Reset
911 & Txt.all & " [warning-as-error]");
912
913 -- Normal warning, prefix with "warning: "
914
915 elsif E_Msg.Kind = Warning then
916 Txt := new String'(SGR_Warning & "warning: " & SGR_Reset & Txt.all);
917
918 -- No prefix needed for style message, "(style)" is there already
919
920 elsif E_Msg.Kind = Style then
921 if Txt (Txt'First .. Txt'First + 6) = "(style)" then
922 Txt := new String'(SGR_Warning & "(style)" & SGR_Reset
923 & Txt (Txt'First + 7 .. Txt'Last));
924 end if;
925
926 -- No prefix needed for check message, severity is there already
927
928 elsif E_Msg.Kind in High_Check | Medium_Check | Low_Check then
929
930 -- The message format is "severity: ..."
931 --
932 -- Enclose the severity with an SGR control string if requested
933
934 if Use_SGR_Control then
935 declare
936 Msg : String renames Text.all;
937 Colon : Natural := 0;
938 begin
939 -- Find first colon
940
941 for J in Msg'Range loop
942 if Msg (J) = ':' then
943 Colon := J;
944 exit;
945 end if;
946 end loop;
947
948 pragma Assert (Colon > 0);
949
950 Txt := new String'(SGR_Error
951 & Msg (Msg'First .. Colon)
952 & SGR_Reset
953 & Msg (Colon + 1 .. Msg'Last));
954 end;
955 end if;
956
957 -- All other cases, add "error: " if unique error tag set
958
959 elsif Opt.Unique_Error_Tag then
960 Txt := new String'(SGR_Error & "error: " & SGR_Reset & Txt.all);
961 end if;
962
963 Output_Text_Within (Txt, Line_Length);
964 end Output_Msg_Text;
965
966 ---------------------
967 -- Prescan_Message --
968 ---------------------
969
970 procedure Prescan_Message (Msg : String) is
971 J : Natural;
972
973 function Parse_Message_Class return String;
974 -- Convert the warning insertion sequence to a warning class represented
975 -- as a length-two string padded, if necessary, with spaces.
976 -- Return the Message class and set the iterator J to the character
977 -- following the sequence.
978 -- Raise a Program_Error if the insertion sequence is not valid.
979
980 -------------------------
981 -- Parse_Message_Class --
982 -------------------------
983
984 function Parse_Message_Class return String is
985 C : constant Character := Msg (J - 1);
986 Message_Class : String (1 .. 2) := " ";
987 begin
988 if J <= Msg'Last and then Msg (J) = C then
989 Message_Class := "? ";
990 J := J + 1;
991
992 elsif J < Msg'Last and then Msg (J + 1) = C
993 and then Msg (J) in 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '*' | '$'
994 then
995 Message_Class := Msg (J) & " ";
996 J := J + 2;
997
998 elsif J + 1 < Msg'Last and then Msg (J + 2) = C
999 and then Msg (J) in '.' | '_'
1000 and then Msg (J + 1) in 'a' .. 'z'
1001 then
1002 Message_Class := Msg (J .. J + 1);
1003 J := J + 3;
1004 elsif (J < Msg'Last and then Msg (J + 1) = C) or else
1005 (J + 1 < Msg'Last and then Msg (J + 2) = C)
1006 then
1007 raise Program_Error;
1008 end if;
1009
1010 -- In any other cases, this is not a warning insertion sequence
1011 -- and the default " " value is returned.
1012
1013 return Message_Class;
1014 end Parse_Message_Class;
1015
1016 -- Start of processing for Prescan_Message
1017
1018 begin
1019 -- Continuation lines need to check only for insertion sequences.
1020 -- Other attributes should be inherited from the main message.
1021
1022 if Msg (Msg'First) = '\' then
1023 Has_Insertion_Line := False;
1024
1025 J := Msg'First;
1026
1027 -- If we have a quote, don't look at following character
1028
1029 while J <= Msg'Last loop
1030 if Msg (J) = ''' then
1031 J := J + 2;
1032
1033 -- Insertion line (# insertion)
1034
1035 elsif Msg (J) = '#' then
1036 Has_Insertion_Line := True;
1037 J := J + 1;
1038 else
1039 J := J + 1;
1040 end if;
1041 end loop;
1042
1043 return;
1044
1045 -- Some global variables are not set for continuation messages, as they
1046 -- only make sense for the initial message.
1047
1048 else
1049
1050 -- Set initial values of globals (may be changed during scan)
1051
1052 Error_Msg_Kind := Error;
1053 Is_Unconditional_Msg := False;
1054 Is_Runtime_Raise := False;
1055 Warning_Msg_Char := " ";
1056
1057 -- Check style message
1058
1059 if Msg'Length > 7
1060 and then Msg (Msg'First .. Msg'First + 6) = "(style)"
1061 then
1062 Error_Msg_Kind := Style;
1063
1064 -- Check info message
1065
1066 elsif Msg'Length > 6
1067 and then Msg (Msg'First .. Msg'First + 5) = "info: "
1068 then
1069 Error_Msg_Kind := Info;
1070
1071 -- Check high check message
1072
1073 elsif Msg'Length > 6
1074 and then Msg (Msg'First .. Msg'First + 5) = "high: "
1075 then
1076 Error_Msg_Kind := High_Check;
1077
1078 -- Check medium check message
1079
1080 elsif Msg'Length > 8
1081 and then Msg (Msg'First .. Msg'First + 7) = "medium: "
1082 then
1083 Error_Msg_Kind := Medium_Check;
1084
1085 -- Check low check message
1086
1087 elsif Msg'Length > 5
1088 and then Msg (Msg'First .. Msg'First + 4) = "low: "
1089 then
1090 Error_Msg_Kind := Low_Check;
1091 end if;
1092 end if;
1093
1094 Has_Double_Exclam := False;
1095 Has_Error_Code := False;
1096 Has_Insertion_Line := False;
1097
1098 -- Loop through message looking for relevant insertion sequences
1099
1100 J := Msg'First;
1101 while J <= Msg'Last loop
1102
1103 -- If we have a quote, don't look at following character
1104
1105 if Msg (J) = ''' then
1106 J := J + 2;
1107
1108 -- Warning message (? or < insertion sequence)
1109
1110 elsif Msg (J) = '?' or else Msg (J) = '<' then
1111 if Msg (J) = '?' or else Error_Msg_Warn then
1112
1113 -- Consider Info and Style messages as unique message types.
1114 -- Those messages can have warning insertion characters within
1115 -- them. However they should only be switch specific insertion
1116 -- characters and not the generic ? or ?? warning insertion
1117 -- characters.
1118
1119 if Error_Msg_Kind not in Style | Info then
1120 Error_Msg_Kind := Warning;
1121 end if;
1122
1123 J := J + 1;
1124 Warning_Msg_Char := Parse_Message_Class;
1125
1126 -- Bomb if untagged warning message. This code can be
1127 -- uncommented for debugging when looking for untagged warning
1128 -- messages.
1129
1130 -- pragma Assert (Warning_Msg_Char /= " ");
1131
1132 else
1133 J := J + 1;
1134 end if;
1135
1136 -- Unconditional message (! insertion)
1137
1138 elsif Msg (J) = '!' then
1139 Is_Unconditional_Msg := True;
1140 J := J + 1;
1141
1142 if J <= Msg'Last and then Msg (J) = '!' then
1143 Has_Double_Exclam := True;
1144 J := J + 1;
1145 end if;
1146
1147 -- Insertion line (# insertion)
1148
1149 elsif Msg (J) = '#' then
1150 Has_Insertion_Line := True;
1151 J := J + 1;
1152
1153 -- Non-serious error (| insertion)
1154
1155 elsif Msg (J) = '|' then
1156 Error_Msg_Kind := Non_Serious_Error;
1157 J := J + 1;
1158
1159 -- Error code ([] insertion)
1160
1161 elsif Msg (J) = '['
1162 and then J < Msg'Last
1163 and then Msg (J + 1) = ']'
1164 then
1165 Has_Error_Code := True;
1166 J := J + 2;
1167
1168 else
1169 J := J + 1;
1170 end if;
1171 end loop;
1172 end Prescan_Message;
1173
1174 --------------------
1175 -- Purge_Messages --
1176 --------------------
1177
1178 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) is
1179 E : Error_Msg_Id;
1180
1181 function To_Be_Purged (E : Error_Msg_Id) return Boolean;
1182 -- Returns True for a message that is to be purged. Also adjusts
1183 -- error counts appropriately.
1184
1185 ------------------
1186 -- To_Be_Purged --
1187 ------------------
1188
1189 function To_Be_Purged (E : Error_Msg_Id) return Boolean is
1190 begin
1191 if E /= No_Error_Msg
1192 and then Errors.Table (E).Sptr.Ptr > From
1193 and then Errors.Table (E).Sptr.Ptr < To
1194 then
1195 Decrease_Error_Msg_Count (Errors.Table (E));
1196
1197 return True;
1198
1199 else
1200 return False;
1201 end if;
1202 end To_Be_Purged;
1203
1204 -- Start of processing for Purge_Messages
1205
1206 begin
1207 while To_Be_Purged (First_Error_Msg) loop
1208 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
1209 end loop;
1210
1211 E := First_Error_Msg;
1212 while E /= No_Error_Msg loop
1213 while To_Be_Purged (Errors.Table (E).Next) loop
1214 Errors.Table (E).Next :=
1215 Errors.Table (Errors.Table (E).Next).Next;
1216 end loop;
1217
1218 E := Errors.Table (E).Next;
1219 end loop;
1220 end Purge_Messages;
1221
1222 ----------------
1223 -- Same_Error --
1224 ----------------
1225
1226 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean is
1227 Msg1 : constant String_Ptr := Errors.Table (M1).Text;
1228 Msg2 : constant String_Ptr := Errors.Table (M2).Text;
1229
1230 Msg2_Len : constant Integer := Msg2'Length;
1231 Msg1_Len : constant Integer := Msg1'Length;
1232
1233 begin
1234 return
1235 Msg1.all = Msg2.all
1236 or else
1237 (Msg1_Len - 10 > Msg2_Len
1238 and then
1239 Msg2.all = Msg1.all (1 .. Msg2_Len)
1240 and then
1241 Msg1 (Msg2_Len + 1 .. Msg2_Len + 10) = ", instance")
1242 or else
1243 (Msg2_Len - 10 > Msg1_Len
1244 and then
1245 Msg1.all = Msg2.all (1 .. Msg1_Len)
1246 and then
1247 Msg2 (Msg1_Len + 1 .. Msg1_Len + 10) = ", instance");
1248 end Same_Error;
1249
1250 -------------------
1251 -- Set_Msg_Blank --
1252 -------------------
1253
1254 procedure Set_Msg_Blank is
1255 begin
1256 if Msglen > 0
1257 and then Msg_Buffer (Msglen) /= ' '
1258 and then Msg_Buffer (Msglen) /= '('
1259 and then Msg_Buffer (Msglen) /= '-'
1260 and then not Manual_Quote_Mode
1261 then
1262 Set_Msg_Char (' ');
1263 end if;
1264 end Set_Msg_Blank;
1265
1266 -------------------------------
1267 -- Set_Msg_Blank_Conditional --
1268 -------------------------------
1269
1270 procedure Set_Msg_Blank_Conditional is
1271 begin
1272 if Msglen > 0
1273 and then Msg_Buffer (Msglen) /= ' '
1274 and then Msg_Buffer (Msglen) /= '('
1275 and then Msg_Buffer (Msglen) /= '"'
1276 and then not Manual_Quote_Mode
1277 then
1278 Set_Msg_Char (' ');
1279 end if;
1280 end Set_Msg_Blank_Conditional;
1281
1282 ------------------
1283 -- Set_Msg_Char --
1284 ------------------
1285
1286 procedure Set_Msg_Char (C : Character) is
1287 begin
1288 -- The check for message buffer overflow is needed to deal with cases
1289 -- where insertions get too long (in particular a child unit name can
1290 -- be very long).
1291
1292 if Msglen < Max_Msg_Length then
1293 Msglen := Msglen + 1;
1294 Msg_Buffer (Msglen) := C;
1295 end if;
1296 end Set_Msg_Char;
1297
1298 ----------------------------
1299 -- Set_Msg_Insertion_Code --
1300 ----------------------------
1301
1302 procedure Set_Msg_Insertion_Code is
1303 H : constant array (Nat range 0 .. 9) of Character := "0123456789";
1304 P10 : constant array (Natural range 0 .. 3) of Nat :=
1305 (10 ** 0,
1306 10 ** 1,
1307 10 ** 2,
1308 10 ** 3);
1309
1310 Code_Len : constant Natural :=
1311 (case Error_Msg_Code is
1312 when 0 => 0,
1313 when 1 .. 9 => 1,
1314 when 10 .. 99 => 2,
1315 when 100 .. 999 => 3,
1316 when 1000 .. 9999 => 4);
1317 Code_Rest : Nat := Error_Msg_Code;
1318 Code_Digit : Nat;
1319
1320 begin
1321 Set_Msg_Char ('E');
1322
1323 for J in 1 .. Error_Msg_Code_Digits - Code_Len loop
1324 Set_Msg_Char ('0');
1325 end loop;
1326
1327 for J in 1 .. Code_Len loop
1328 Code_Digit := Code_Rest / P10 (Code_Len - J);
1329 Set_Msg_Char (H (Code_Digit));
1330 Code_Rest := Code_Rest - Code_Digit * P10 (Code_Len - J);
1331 end loop;
1332 end Set_Msg_Insertion_Code;
1333
1334 ------------------------------
1335 -- Set_Msg_Insertion_Column --
1336 ------------------------------
1337
1338 procedure Set_Msg_Insertion_Column is
1339 begin
1340 if RM_Column_Check then
1341 Set_Msg_Str (" in column ");
1342 Set_Msg_Int (Int (Error_Msg_Col) + 1);
1343 end if;
1344 end Set_Msg_Insertion_Column;
1345
1346 ---------------------------------
1347 -- Set_Msg_Insertion_File_Name --
1348 ---------------------------------
1349
1350 procedure Set_Msg_Insertion_File_Name is
1351 begin
1352 if Error_Msg_File_1 = No_File then
1353 null;
1354
1355 elsif Error_Msg_File_1 = Error_File_Name then
1356 Set_Msg_Blank;
1357 Set_Msg_Str ("<error>");
1358
1359 else
1360 Set_Msg_Blank;
1361 Get_Name_String (Error_Msg_File_1);
1362 Set_Msg_Quote;
1363 Set_Msg_Name_Buffer;
1364 Set_Msg_Quote;
1365 end if;
1366
1367 -- The following assignments ensure that the second and third {
1368 -- insertion characters will correspond to the Error_Msg_File_2
1369 -- and Error_Msg_File_3 values.
1370
1371 Error_Msg_File_1 := Error_Msg_File_2;
1372 Error_Msg_File_2 := Error_Msg_File_3;
1373 end Set_Msg_Insertion_File_Name;
1374
1375 -----------------------------------
1376 -- Set_Msg_Insertion_Line_Number --
1377 -----------------------------------
1378
1379 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
1380 Sindex_Loc : Source_File_Index;
1381 Sindex_Flag : Source_File_Index;
1382 Fname : File_Name_Type;
1383 Int_File : Boolean;
1384
1385 procedure Set_At;
1386 -- Outputs "at " unless last characters in buffer are " from ". Certain
1387 -- messages read better with from than at.
1388
1389 ------------
1390 -- Set_At --
1391 ------------
1392
1393 procedure Set_At is
1394 begin
1395 if Msglen < 6
1396 or else Msg_Buffer (Msglen - 5 .. Msglen) /= " from "
1397 then
1398 Set_Msg_Str ("at ");
1399 end if;
1400 end Set_At;
1401
1402 -- Start of processing for Set_Msg_Insertion_Line_Number
1403
1404 begin
1405 Set_Msg_Blank;
1406
1407 if Loc = No_Location then
1408 Set_At;
1409 Set_Msg_Str ("unknown location");
1410
1411 elsif Loc = System_Location then
1412 Set_Msg_Str ("in package System");
1413 Set_Msg_Insertion_Run_Time_Name;
1414
1415 elsif Loc = Standard_Location then
1416 Set_Msg_Str ("in package Standard");
1417
1418 elsif Loc = Standard_ASCII_Location then
1419 Set_Msg_Str ("in package Standard.ASCII");
1420
1421 else
1422 -- Add "at file-name:" if reference is to other than the source
1423 -- file in which the error message is placed. Note that we check
1424 -- full file names, rather than just the source indexes, to
1425 -- deal with generic instantiations from the current file.
1426
1427 Sindex_Loc := Get_Source_File_Index (Loc);
1428 Sindex_Flag := Get_Source_File_Index (Flag);
1429
1430 if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
1431 Set_At;
1432 Fname := Reference_Name (Get_Source_File_Index (Loc));
1433 Int_File := Is_Internal_File_Name (Fname);
1434 Get_Name_String (Fname);
1435 Set_Msg_Name_Buffer;
1436
1437 if not (Int_File and Debug_Flag_Dot_K) then
1438 Set_Msg_Char (':');
1439 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1440 end if;
1441
1442 -- If in current file, add text "at line "
1443
1444 else
1445 Set_At;
1446 Set_Msg_Str ("line ");
1447 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1448 end if;
1449
1450 -- Deal with the instantiation case. We may have a reference to,
1451 -- e.g. a type, that is declared within a generic template, and
1452 -- what we are really referring to is the occurrence in an instance.
1453 -- In this case, the line number of the instantiation is also of
1454 -- interest, and we add a notation:
1455
1456 -- , instance at xxx
1457
1458 -- where xxx is a line number output using this same routine (and
1459 -- the recursion can go further if the instantiation is itself in
1460 -- a generic template).
1461
1462 -- The flag location passed to us in this situation is indeed the
1463 -- line number within the template, but as described in Sinput.L
1464 -- (file sinput-l.ads, section "Handling Generic Instantiations")
1465 -- we can retrieve the location of the instantiation itself from
1466 -- this flag location value.
1467
1468 -- Note: this processing is suppressed if Suppress_Instance_Location
1469 -- is set True. This is used to prevent redundant annotations of the
1470 -- location of the instantiation in the case where we are placing
1471 -- the messages on the instantiation in any case.
1472
1473 if Instantiation (Sindex_Loc) /= No_Location
1474 and then not Suppress_Instance_Location
1475 then
1476 Set_Msg_Str (", instance ");
1477 Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
1478 end if;
1479 end if;
1480 end Set_Msg_Insertion_Line_Number;
1481
1482 ----------------------------
1483 -- Set_Msg_Insertion_Name --
1484 ----------------------------
1485
1486 procedure Set_Msg_Insertion_Name is
1487 begin
1488 if Error_Msg_Name_1 = No_Name then
1489 null;
1490
1491 elsif Error_Msg_Name_1 = Error_Name then
1492 Set_Msg_Blank;
1493 Set_Msg_Str ("<error>");
1494
1495 else
1496 Set_Msg_Blank_Conditional;
1497 Get_Unqualified_Decoded_Name_String (Error_Msg_Name_1);
1498
1499 -- Remove %s or %b at end. These come from unit names. If the
1500 -- caller wanted the (unit) or (body), then they would have used
1501 -- the $ insertion character. Certainly no error message should
1502 -- ever have %b or %s explicitly occurring.
1503
1504 if Name_Len > 2
1505 and then Name_Buffer (Name_Len - 1) = '%'
1506 and then (Name_Buffer (Name_Len) = 'b'
1507 or else
1508 Name_Buffer (Name_Len) = 's')
1509 then
1510 Name_Len := Name_Len - 2;
1511 end if;
1512
1513 -- Remove upper case letter at end, again, we should not be getting
1514 -- such names, and what we hope is that the remainder makes sense.
1515
1516 if Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' then
1517 Name_Len := Name_Len - 1;
1518 end if;
1519
1520 -- If operator name or character literal name, just print it as is.
1521 -- Also print as is if it ends in a right paren (case of x'val(nnn)).
1522
1523 if Name_Buffer (1) = '"'
1524 or else Name_Buffer (1) = '''
1525 or else Name_Buffer (Name_Len) = ')'
1526 then
1527 Set_Msg_Name_Buffer;
1528
1529 -- Else output with surrounding quotes in proper casing mode
1530
1531 else
1532 Set_Casing (Identifier_Casing (Flag_Source));
1533 Set_Msg_Quote;
1534 Set_Msg_Name_Buffer;
1535 Set_Msg_Quote;
1536 end if;
1537 end if;
1538
1539 -- The following assignments ensure that other percent insertion
1540 -- characters will correspond to their appropriate Error_Msg_Name_#
1541 -- values as required.
1542
1543 Error_Msg_Name_1 := Error_Msg_Name_2;
1544 Error_Msg_Name_2 := Error_Msg_Name_3;
1545 Error_Msg_Name_3 := Error_Msg_Name_4;
1546 Error_Msg_Name_4 := Error_Msg_Name_5;
1547 Error_Msg_Name_5 := Error_Msg_Name_6;
1548 end Set_Msg_Insertion_Name;
1549
1550 ------------------------------------
1551 -- Set_Msg_Insertion_Name_Literal --
1552 ------------------------------------
1553
1554 procedure Set_Msg_Insertion_Name_Literal is
1555 begin
1556 if Error_Msg_Name_1 = No_Name then
1557 null;
1558
1559 elsif Error_Msg_Name_1 = Error_Name then
1560 Set_Msg_Blank;
1561 Set_Msg_Str ("<error>");
1562
1563 else
1564 Set_Msg_Blank;
1565 Get_Name_String (Error_Msg_Name_1);
1566 Set_Msg_Quote;
1567 Set_Msg_Name_Buffer;
1568 Set_Msg_Quote;
1569 end if;
1570
1571 -- The following assignments ensure that other percent insertion
1572 -- characters will correspond to their appropriate Error_Msg_Name_#
1573 -- values as required.
1574
1575 Error_Msg_Name_1 := Error_Msg_Name_2;
1576 Error_Msg_Name_2 := Error_Msg_Name_3;
1577 Error_Msg_Name_3 := Error_Msg_Name_4;
1578 Error_Msg_Name_4 := Error_Msg_Name_5;
1579 Error_Msg_Name_5 := Error_Msg_Name_6;
1580 end Set_Msg_Insertion_Name_Literal;
1581
1582 -------------------------------------
1583 -- Set_Msg_Insertion_Reserved_Name --
1584 -------------------------------------
1585
1586 procedure Set_Msg_Insertion_Reserved_Name is
1587 begin
1588 Set_Msg_Blank_Conditional;
1589 Get_Name_String (Error_Msg_Name_1);
1590 Set_Msg_Quote;
1591 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1592 Set_Msg_Name_Buffer;
1593 Set_Msg_Quote;
1594 end Set_Msg_Insertion_Reserved_Name;
1595
1596 -------------------------------------
1597 -- Set_Msg_Insertion_Reserved_Word --
1598 -------------------------------------
1599
1600 procedure Set_Msg_Insertion_Reserved_Word
1601 (Text : String;
1602 J : in out Integer)
1603 is
1604 begin
1605 Set_Msg_Blank_Conditional;
1606 Name_Len := 0;
1607
1608 while J <= Text'Last and then Text (J) in 'A' .. 'Z' loop
1609 Add_Char_To_Name_Buffer (Text (J));
1610 J := J + 1;
1611 end loop;
1612
1613 -- Here is where we make the special exception for RM
1614
1615 if Name_Len = 2 and then Name_Buffer (1 .. 2) = "RM" then
1616 Set_Msg_Name_Buffer;
1617
1618 -- We make a similar exception for CUDA
1619
1620 elsif Name_Len = 4 and then Name_Buffer (1 .. 4) = "CUDA" then
1621 Set_Msg_Name_Buffer;
1622
1623 -- We make a similar exception for SPARK
1624
1625 elsif Name_Len = 5 and then Name_Buffer (1 .. 5) = "SPARK" then
1626 Set_Msg_Name_Buffer;
1627
1628 -- Otherwise, case appropriately and add surrounding quotes
1629
1630 else
1631 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1632 Set_Msg_Quote;
1633 Set_Msg_Name_Buffer;
1634 Set_Msg_Quote;
1635 end if;
1636 end Set_Msg_Insertion_Reserved_Word;
1637
1638 -------------------------------------
1639 -- Set_Msg_Insertion_Run_Time_Name --
1640 -------------------------------------
1641
1642 procedure Set_Msg_Insertion_Run_Time_Name is
1643 begin
1644 if Targparm.Run_Time_Name_On_Target /= No_Name then
1645 Set_Msg_Blank_Conditional;
1646 Set_Msg_Char ('(');
1647 Get_Name_String (Targparm.Run_Time_Name_On_Target);
1648 Set_Casing (Mixed_Case);
1649 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1650 Set_Msg_Char (')');
1651 end if;
1652 end Set_Msg_Insertion_Run_Time_Name;
1653
1654 ----------------------------
1655 -- Set_Msg_Insertion_Uint --
1656 ----------------------------
1657
1658 procedure Set_Msg_Insertion_Uint is
1659 begin
1660 Set_Msg_Blank;
1661 UI_Image (Error_Msg_Uint_1);
1662
1663 for J in 1 .. UI_Image_Length loop
1664 Set_Msg_Char (UI_Image_Buffer (J));
1665 end loop;
1666
1667 -- The following assignment ensures that a second caret insertion
1668 -- character will correspond to the Error_Msg_Uint_2 parameter.
1669
1670 Error_Msg_Uint_1 := Error_Msg_Uint_2;
1671 end Set_Msg_Insertion_Uint;
1672
1673 -----------------
1674 -- Set_Msg_Int --
1675 -----------------
1676
1677 procedure Set_Msg_Int (Line : Int) is
1678 begin
1679 if Line > 9 then
1680 Set_Msg_Int (Line / 10);
1681 end if;
1682
1683 Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
1684 end Set_Msg_Int;
1685
1686 -------------------------
1687 -- Set_Msg_Name_Buffer --
1688 -------------------------
1689
1690 procedure Set_Msg_Name_Buffer is
1691 begin
1692 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1693 Destroy_Global_Name_Buffer;
1694 end Set_Msg_Name_Buffer;
1695
1696 -------------------
1697 -- Set_Msg_Quote --
1698 -------------------
1699
1700 procedure Set_Msg_Quote is
1701 begin
1702 if not Manual_Quote_Mode then
1703 Set_Msg_Char ('"');
1704 end if;
1705 end Set_Msg_Quote;
1706
1707 -----------------
1708 -- Set_Msg_Str --
1709 -----------------
1710
1711 procedure Set_Msg_Str (Text : String) is
1712 begin
1713 -- Do replacement for special x'Class aspect names
1714
1715 if Text = "_Pre" then
1716 Set_Msg_Str ("Pre'Class");
1717
1718 elsif Text = "_Post" then
1719 Set_Msg_Str ("Post'Class");
1720
1721 elsif Text = "_Type_Invariant" then
1722 Set_Msg_Str ("Type_Invariant'Class");
1723
1724 elsif Text = "_pre" then
1725 Set_Msg_Str ("pre'class");
1726
1727 elsif Text = "_post" then
1728 Set_Msg_Str ("post'class");
1729
1730 elsif Text = "_type_invariant" then
1731 Set_Msg_Str ("type_invariant'class");
1732
1733 elsif Text = "_PRE" then
1734 Set_Msg_Str ("PRE'CLASS");
1735
1736 elsif Text = "_POST" then
1737 Set_Msg_Str ("POST'CLASS");
1738
1739 elsif Text = "_TYPE_INVARIANT" then
1740 Set_Msg_Str ("TYPE_INVARIANT'CLASS");
1741
1742 -- Preserve casing for names that include acronyms
1743
1744 elsif Text = "Cpp_Class" then
1745 Set_Msg_Str ("CPP_Class");
1746
1747 elsif Text = "Cpp_Constructor" then
1748 Set_Msg_Str ("CPP_Constructor");
1749
1750 elsif Text = "Cpp_Virtual" then
1751 Set_Msg_Str ("CPP_Virtual");
1752
1753 elsif Text = "Cpp_Vtable" then
1754 Set_Msg_Str ("CPP_Vtable");
1755
1756 elsif Text = "Cuda_Device" then
1757 Set_Msg_Str ("CUDA_Device");
1758
1759 elsif Text = "Cuda_Global" then
1760 Set_Msg_Str ("CUDA_Global");
1761
1762 elsif Text = "Persistent_Bss" then
1763 Set_Msg_Str ("Persistent_BSS");
1764
1765 elsif Text = "Spark_Mode" then
1766 Set_Msg_Str ("SPARK_Mode");
1767
1768 elsif Text = "Use_Vads_Size" then
1769 Set_Msg_Str ("Use_VADS_Size");
1770
1771 elsif Text = "Vads_Size" then
1772 Set_Msg_Str ("VADS_size");
1773
1774 -- Normal case with no replacement
1775
1776 else
1777 for J in Text'Range loop
1778 Set_Msg_Char (Text (J));
1779 end loop;
1780 end if;
1781 end Set_Msg_Str;
1782
1783 ------------------------------
1784 -- Set_Next_Non_Deleted_Msg --
1785 ------------------------------
1786
1787 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id) is
1788 begin
1789 if E = No_Error_Msg then
1790 return;
1791
1792 else
1793 loop
1794 E := Errors.Table (E).Next;
1795 exit when E = No_Error_Msg or else not Errors.Table (E).Deleted;
1796 end loop;
1797 end if;
1798 end Set_Next_Non_Deleted_Msg;
1799
1800 ------------------------------
1801 -- Set_Specific_Warning_Off --
1802 ------------------------------
1803
1804 procedure Set_Specific_Warning_Off
1805 (Node : Node_Id;
1806 Msg : String;
1807 Reason : String_Id;
1808 Config : Boolean;
1809 Used : Boolean := False)
1810 is
1811 Loc : constant Source_Ptr := Sinfo.Nodes.Sloc (Node);
1812 begin
1813 Specific_Warnings.Append
1814 ((Start => Loc,
1815 Msg => new String'(Msg),
1816 Stop => Source_Last (Get_Source_File_Index (Loc)),
1817 Reason => Reason,
1818 Open => True,
1819 Used => Used,
1820 Config => Config));
1821 end Set_Specific_Warning_Off;
1822
1823 -----------------------------
1824 -- Set_Specific_Warning_On --
1825 -----------------------------
1826
1827 procedure Set_Specific_Warning_On
1828 (Loc : Source_Ptr;
1829 Msg : String;
1830 Err : out Boolean)
1831 is
1832 begin
1833 for J in 1 .. Specific_Warnings.Last loop
1834 declare
1835 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1836
1837 begin
1838 if Msg = SWE.Msg.all
1839 and then Loc > SWE.Start
1840 and then SWE.Open
1841 and then Get_Source_File_Index (SWE.Start) =
1842 Get_Source_File_Index (Loc)
1843 then
1844 SWE.Stop := Loc;
1845 SWE.Open := False;
1846 Err := False;
1847
1848 -- If a config pragma is specifically cancelled, consider
1849 -- that it is no longer active as a configuration pragma.
1850
1851 SWE.Config := False;
1852 return;
1853 end if;
1854 end;
1855 end loop;
1856
1857 Err := True;
1858 end Set_Specific_Warning_On;
1859
1860 ---------------------------
1861 -- Set_Warnings_Mode_Off --
1862 ---------------------------
1863
1864 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id) is
1865 begin
1866 -- Don't bother with entries from instantiation copies, since we will
1867 -- already have a copy in the template, which is what matters.
1868
1869 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1870 return;
1871 end if;
1872
1873 -- If all warnings are suppressed by command line switch, this can
1874 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1875 -- Warnings to be stored for the formal verification backend.
1876
1877 if Warning_Mode = Suppress
1878 and then not GNATprove_Mode
1879 then
1880 return;
1881 end if;
1882
1883 -- If last entry in table already covers us, this is a redundant pragma
1884 -- Warnings (Off) and can be ignored.
1885
1886 if Warnings.Last >= Warnings.First
1887 and then Warnings.Table (Warnings.Last).Start <= Loc
1888 and then Loc <= Warnings.Table (Warnings.Last).Stop
1889 then
1890 return;
1891 end if;
1892
1893 -- If none of those special conditions holds, establish a new entry,
1894 -- extending from the location of the pragma to the end of the current
1895 -- source file. This ending point will be adjusted by a subsequent
1896 -- corresponding pragma Warnings (On).
1897
1898 Warnings.Append
1899 ((Start => Loc,
1900 Stop => Source_Last (Get_Source_File_Index (Loc)),
1901 Reason => Reason));
1902 end Set_Warnings_Mode_Off;
1903
1904 --------------------------
1905 -- Set_Warnings_Mode_On --
1906 --------------------------
1907
1908 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
1909 begin
1910 -- Don't bother with entries from instantiation copies, since we will
1911 -- already have a copy in the template, which is what matters.
1912
1913 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1914 return;
1915 end if;
1916
1917 -- If all warnings are suppressed by command line switch, this can
1918 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1919 -- Warnings to be stored for the formal verification backend.
1920
1921 if Warning_Mode = Suppress
1922 and then not GNATprove_Mode
1923 then
1924 return;
1925 end if;
1926
1927 -- If the last entry in the warnings table covers this pragma, then
1928 -- we adjust the end point appropriately.
1929
1930 if Warnings.Last >= Warnings.First
1931 and then Warnings.Table (Warnings.Last).Start <= Loc
1932 and then Loc <= Warnings.Table (Warnings.Last).Stop
1933 then
1934 Warnings.Table (Warnings.Last).Stop := Loc;
1935 end if;
1936 end Set_Warnings_Mode_On;
1937
1938 -------------------
1939 -- Sloc_In_Range --
1940 -------------------
1941
1942 function Sloc_In_Range (Loc, Start, Stop : Source_Ptr) return Boolean is
1943 Cur_Loc : Source_Ptr := Loc;
1944
1945 begin
1946 while Cur_Loc /= No_Location loop
1947 if Start <= Cur_Loc and then Cur_Loc <= Stop then
1948 return True;
1949 end if;
1950
1951 Cur_Loc := Instantiation_Location (Cur_Loc);
1952 end loop;
1953
1954 return False;
1955 end Sloc_In_Range;
1956
1957 -------------------------------------
1958 -- Warning_Specifically_Suppressed --
1959 -------------------------------------
1960
1961 function Warning_Specifically_Suppressed
1962 (Loc : Source_Ptr;
1963 Msg : String_Ptr;
1964 Tag : String := "") return String_Id
1965 is
1966 begin
1967 -- Loop through specific warning suppression entries
1968
1969 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1970 declare
1971 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1972 begin
1973 -- Pragma applies if it is a configuration pragma, or if the
1974 -- location is in range of a specific non-configuration pragma.
1975
1976 if SWE.Config
1977 or else Sloc_In_Range (Loc, SWE.Start, SWE.Stop)
1978 then
1979 if Matches (Msg.all, SWE.Msg.all)
1980 or else Matches (Tag, SWE.Msg.all)
1981 then
1982 SWE.Used := True;
1983 return SWE.Reason;
1984 end if;
1985 end if;
1986 end;
1987 end loop;
1988
1989 return No_String;
1990 end Warning_Specifically_Suppressed;
1991
1992 ------------------------------
1993 -- Warning_Treated_As_Error --
1994 ------------------------------
1995
1996 function Warning_Treated_As_Error (Msg : String) return Boolean is
1997 begin
1998 for J in 1 .. Warnings_As_Errors_Count loop
1999 if Matches (Msg, Warnings_As_Errors (J).all) then
2000 return True;
2001 end if;
2002 end loop;
2003
2004 return False;
2005 end Warning_Treated_As_Error;
2006
2007 -------------------------
2008 -- Warnings_Suppressed --
2009 -------------------------
2010
2011 function Warnings_Suppressed (Loc : Source_Ptr) return String_Id is
2012 begin
2013 -- Loop through table of ON/OFF warnings
2014
2015 for J in Warnings.First .. Warnings.Last loop
2016 if Sloc_In_Range (Loc, Warnings.Table (J).Start,
2017 Warnings.Table (J).Stop)
2018 then
2019 return Warnings.Table (J).Reason;
2020 end if;
2021 end loop;
2022
2023 if Warning_Mode = Suppress then
2024 return Null_String_Id;
2025 else
2026 return No_String;
2027 end if;
2028 end Warnings_Suppressed;
2029
2030 -------------------------
2031 -- Write_Error_Summary --
2032 -------------------------
2033
2034 procedure Write_Error_Summary is
2035 begin
2036 -- Extra blank line if error messages or source listing were output
2037
2038 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
2039 then
2040 Write_Eol;
2041 end if;
2042
2043 -- Message giving number of lines read and number of errors detected.
2044 -- This normally goes to Standard_Output. The exception is when brief
2045 -- mode is not set, verbose mode (or full list mode) is set, and
2046 -- there are errors. In this case we send the message to standard
2047 -- error to make sure that *something* appears on standard error
2048 -- in an error situation.
2049
2050 if Total_Errors_Detected + Warnings_Detected /= 0
2051 and then not Brief_Output
2052 and then (Verbose_Mode or Full_List)
2053 then
2054 Set_Standard_Error;
2055 end if;
2056
2057 -- Message giving total number of lines. Don't give this message if
2058 -- the Main_Source line is unknown (this happens in error situations,
2059 -- e.g. when integrated preprocessing fails).
2060
2061 if Main_Source_File > No_Source_File then
2062 Write_Str (" ");
2063 Write_Int (Num_Source_Lines (Main_Source_File));
2064
2065 if Num_Source_Lines (Main_Source_File) = 1 then
2066 Write_Str (" line: ");
2067 else
2068 Write_Str (" lines: ");
2069 end if;
2070 end if;
2071
2072 if Total_Errors_Detected = 0 then
2073 Write_Str ("No errors");
2074
2075 elsif Total_Errors_Detected = 1 then
2076 Write_Str ("1 error");
2077
2078 else
2079 Write_Int (Total_Errors_Detected);
2080 Write_Str (" errors");
2081 end if;
2082
2083 -- We now need to output warnings. When using -gnatwe, all warnings
2084 -- should be treated as errors, except for warnings originating from
2085 -- the use of the Compile_Time_Warning pragma. Another situation
2086 -- where a warning might be treated as an error is when the source
2087 -- code contains a Warning_As_Error pragma.
2088 -- When warnings are treated as errors, we still log them as
2089 -- warnings, but we add a message denoting how many of these warnings
2090 -- are also errors.
2091
2092 declare
2093 Warnings_Count : constant Int := Warnings_Detected;
2094
2095 Compile_Time_Warnings : Int;
2096 -- Number of warnings that come from a Compile_Time_Warning
2097 -- pragma.
2098
2099 Non_Compile_Time_Warnings : Int;
2100 -- Number of warnings that do not come from a Compile_Time_Warning
2101 -- pragmas.
2102
2103 begin
2104 if Warnings_Count > 0 then
2105 Write_Str (", ");
2106 Write_Int (Warnings_Count);
2107 Write_Str (" warning");
2108
2109 if Warnings_Count > 1 then
2110 Write_Char ('s');
2111 end if;
2112
2113 Compile_Time_Warnings := Count_Compile_Time_Pragma_Warnings;
2114 Non_Compile_Time_Warnings :=
2115 Warnings_Count - Compile_Time_Warnings;
2116
2117 if Warning_Mode = Treat_As_Error
2118 and then Non_Compile_Time_Warnings > 0
2119 then
2120 Write_Str (" (");
2121
2122 if Compile_Time_Warnings > 0 then
2123 Write_Int (Non_Compile_Time_Warnings);
2124 Write_Str (" ");
2125 end if;
2126
2127 Write_Str ("treated as error");
2128
2129 if Non_Compile_Time_Warnings > 1 then
2130 Write_Char ('s');
2131 end if;
2132
2133 Write_Char (')');
2134
2135 elsif Warnings_Treated_As_Errors > 0 then
2136 Write_Str (" (");
2137
2138 if Warnings_Treated_As_Errors /= Warnings_Count then
2139 Write_Int (Warnings_Treated_As_Errors);
2140 Write_Str (" ");
2141 end if;
2142
2143 Write_Str ("treated as error");
2144
2145 if Warnings_Treated_As_Errors > 1 then
2146 Write_Str ("s");
2147 end if;
2148
2149 Write_Str (")");
2150 end if;
2151 end if;
2152 end;
2153
2154 if Info_Messages /= 0 then
2155 Write_Str (", ");
2156 Write_Int (Info_Messages);
2157 Write_Str (" info message");
2158
2159 if Info_Messages > 1 then
2160 Write_Char ('s');
2161 end if;
2162 end if;
2163
2164 Write_Eol;
2165 Set_Standard_Output;
2166 end Write_Error_Summary;
2167
2168 end Erroutc;