Reverting merge from trunk
[official-gcc.git] / gcc / ada / erroutc.adb
blobe2631f84e7f7e272ae2b57817582627df9cb2991
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-2013, 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 Err_Vars; use Err_Vars;
37 with Namet; use Namet;
38 with Opt; use Opt;
39 with Output; use Output;
40 with Sinput; use Sinput;
41 with Snames; use Snames;
42 with Targparm; use Targparm;
43 with Uintp; use Uintp;
45 package body Erroutc is
47 ---------------
48 -- Add_Class --
49 ---------------
51 procedure Add_Class is
52 begin
53 if Class_Flag then
54 Class_Flag := False;
55 Set_Msg_Char (''');
56 Get_Name_String (Name_Class);
57 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
58 Set_Msg_Name_Buffer;
59 end if;
60 end Add_Class;
62 ----------------------
63 -- Buffer_Ends_With --
64 ----------------------
66 function Buffer_Ends_With (S : String) return Boolean is
67 Len : constant Natural := S'Length;
68 begin
69 return
70 Msglen > Len
71 and then Msg_Buffer (Msglen - Len) = ' '
72 and then Msg_Buffer (Msglen - Len + 1 .. Msglen) = S;
73 end Buffer_Ends_With;
75 -------------------
76 -- Buffer_Remove --
77 -------------------
79 procedure Buffer_Remove (S : String) is
80 begin
81 if Buffer_Ends_With (S) then
82 Msglen := Msglen - S'Length;
83 end if;
84 end Buffer_Remove;
86 -----------------------------
87 -- Check_Duplicate_Message --
88 -----------------------------
90 procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id) is
91 L1, L2 : Error_Msg_Id;
92 N1, N2 : Error_Msg_Id;
94 procedure Delete_Msg (Delete, Keep : Error_Msg_Id);
95 -- Called to delete message Delete, keeping message Keep. Marks
96 -- all messages of Delete with deleted flag set to True, and also
97 -- makes sure that for the error messages that are retained the
98 -- preferred message is the one retained (we prefer the shorter
99 -- one in the case where one has an Instance tag). Note that we
100 -- always know that Keep has at least as many continuations as
101 -- Delete (since we always delete the shorter sequence).
103 ----------------
104 -- Delete_Msg --
105 ----------------
107 procedure Delete_Msg (Delete, Keep : Error_Msg_Id) is
108 D, K : Error_Msg_Id;
110 begin
111 D := Delete;
112 K := Keep;
114 loop
115 Errors.Table (D).Deleted := True;
117 -- Adjust error message count
119 if Errors.Table (D).Warn or else Errors.Table (D).Style then
120 Warnings_Detected := Warnings_Detected - 1;
122 else
123 Total_Errors_Detected := Total_Errors_Detected - 1;
125 if Errors.Table (D).Serious then
126 Serious_Errors_Detected := Serious_Errors_Detected - 1;
127 end if;
128 end if;
130 -- Substitute shorter of the two error messages
132 if Errors.Table (K).Text'Length > Errors.Table (D).Text'Length then
133 Errors.Table (K).Text := Errors.Table (D).Text;
134 end if;
136 D := Errors.Table (D).Next;
137 K := Errors.Table (K).Next;
139 if D = No_Error_Msg or else not Errors.Table (D).Msg_Cont then
140 return;
141 end if;
142 end loop;
143 end Delete_Msg;
145 -- Start of processing for Check_Duplicate_Message
147 begin
148 -- Both messages must be non-continuation messages and not deleted
150 if Errors.Table (M1).Msg_Cont
151 or else Errors.Table (M2).Msg_Cont
152 or else Errors.Table (M1).Deleted
153 or else Errors.Table (M2).Deleted
154 then
155 return;
156 end if;
158 -- Definitely not equal if message text does not match
160 if not Same_Error (M1, M2) then
161 return;
162 end if;
164 -- Same text. See if all continuations are also identical
166 L1 := M1;
167 L2 := M2;
169 loop
170 N1 := Errors.Table (L1).Next;
171 N2 := Errors.Table (L2).Next;
173 -- If M1 continuations have run out, we delete M1, either the
174 -- messages have the same number of continuations, or M2 has
175 -- more and we prefer the one with more anyway.
177 if N1 = No_Error_Msg or else not Errors.Table (N1).Msg_Cont then
178 Delete_Msg (M1, M2);
179 return;
181 -- If M2 continuations have run out, we delete M2
183 elsif N2 = No_Error_Msg or else not Errors.Table (N2).Msg_Cont then
184 Delete_Msg (M2, M1);
185 return;
187 -- Otherwise see if continuations are the same, if not, keep both
188 -- sequences, a curious case, but better to keep everything!
190 elsif not Same_Error (N1, N2) then
191 return;
193 -- If continuations are the same, continue scan
195 else
196 L1 := N1;
197 L2 := N2;
198 end if;
199 end loop;
200 end Check_Duplicate_Message;
202 ------------------------
203 -- Compilation_Errors --
204 ------------------------
206 function Compilation_Errors return Boolean is
207 begin
208 return Total_Errors_Detected /= 0
209 or else (Warnings_Detected /= 0
210 and then Warning_Mode = Treat_As_Error);
211 end Compilation_Errors;
213 ------------------
214 -- Debug_Output --
215 ------------------
217 procedure Debug_Output (N : Node_Id) is
218 begin
219 if Debug_Flag_1 then
220 Write_Str ("*** following error message posted on node id = #");
221 Write_Int (Int (N));
222 Write_Str (" ***");
223 Write_Eol;
224 end if;
225 end Debug_Output;
227 ----------
228 -- dmsg --
229 ----------
231 procedure dmsg (Id : Error_Msg_Id) is
232 E : Error_Msg_Object renames Errors.Table (Id);
234 begin
235 w ("Dumping error message, Id = ", Int (Id));
236 w (" Text = ", E.Text.all);
237 w (" Next = ", Int (E.Next));
238 w (" Sfile = ", Int (E.Sfile));
240 Write_Str
241 (" Sptr = ");
242 Write_Location (E.Sptr);
243 Write_Eol;
245 Write_Str
246 (" Optr = ");
247 Write_Location (E.Optr);
248 Write_Eol;
250 w (" Line = ", Int (E.Line));
251 w (" Col = ", Int (E.Col));
252 w (" Warn = ", E.Warn);
253 w (" Style = ", E.Style);
254 w (" Serious = ", E.Serious);
255 w (" Uncond = ", E.Uncond);
256 w (" Msg_Cont = ", E.Msg_Cont);
257 w (" Deleted = ", E.Deleted);
259 Write_Eol;
260 end dmsg;
262 ------------------
263 -- Get_Location --
264 ------------------
266 function Get_Location (E : Error_Msg_Id) return Source_Ptr is
267 begin
268 return Errors.Table (E).Sptr;
269 end Get_Location;
271 ----------------
272 -- Get_Msg_Id --
273 ----------------
275 function Get_Msg_Id return Error_Msg_Id is
276 begin
277 return Cur_Msg;
278 end Get_Msg_Id;
280 -----------------------
281 -- Output_Error_Msgs --
282 -----------------------
284 procedure Output_Error_Msgs (E : in out Error_Msg_Id) is
285 P : Source_Ptr;
286 T : Error_Msg_Id;
287 S : Error_Msg_Id;
289 Flag_Num : Pos;
290 Mult_Flags : Boolean := False;
292 begin
293 S := E;
295 -- Skip deleted messages at start
297 if Errors.Table (S).Deleted then
298 Set_Next_Non_Deleted_Msg (S);
299 end if;
301 -- Figure out if we will place more than one error flag on this line
303 T := S;
304 while T /= No_Error_Msg
305 and then Errors.Table (T).Line = Errors.Table (E).Line
306 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
307 loop
308 if Errors.Table (T).Sptr > Errors.Table (E).Sptr then
309 Mult_Flags := True;
310 end if;
312 Set_Next_Non_Deleted_Msg (T);
313 end loop;
315 -- Output the error flags. The circuit here makes sure that the tab
316 -- characters in the original line are properly accounted for. The
317 -- eight blanks at the start are to match the line number.
319 if not Debug_Flag_2 then
320 Write_Str (" ");
321 P := Line_Start (Errors.Table (E).Sptr);
322 Flag_Num := 1;
324 -- Loop through error messages for this line to place flags
326 T := S;
327 while T /= No_Error_Msg
328 and then Errors.Table (T).Line = Errors.Table (E).Line
329 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
330 loop
331 -- Loop to output blanks till current flag position
333 while P < Errors.Table (T).Sptr loop
334 if Source_Text (Errors.Table (T).Sfile) (P) = ASCII.HT then
335 Write_Char (ASCII.HT);
336 else
337 Write_Char (' ');
338 end if;
340 P := P + 1;
341 end loop;
343 -- Output flag (unless already output, this happens if more
344 -- than one error message occurs at the same flag position).
346 if P = Errors.Table (T).Sptr then
347 if (Flag_Num = 1 and then not Mult_Flags)
348 or else Flag_Num > 9
349 then
350 Write_Char ('|');
351 else
352 Write_Char (Character'Val (Character'Pos ('0') + Flag_Num));
353 end if;
355 P := P + 1;
356 end if;
358 Set_Next_Non_Deleted_Msg (T);
359 Flag_Num := Flag_Num + 1;
360 end loop;
362 Write_Eol;
363 end if;
365 -- Now output the error messages
367 T := S;
368 while T /= No_Error_Msg
369 and then Errors.Table (T).Line = Errors.Table (E).Line
370 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
371 loop
372 Write_Str (" >>> ");
373 Output_Msg_Text (T);
375 if Debug_Flag_2 then
376 while Column < 74 loop
377 Write_Char (' ');
378 end loop;
380 Write_Str (" <<<");
381 end if;
383 Write_Eol;
384 Set_Next_Non_Deleted_Msg (T);
385 end loop;
387 E := T;
388 end Output_Error_Msgs;
390 ------------------------
391 -- Output_Line_Number --
392 ------------------------
394 procedure Output_Line_Number (L : Logical_Line_Number) is
395 D : Int; -- next digit
396 C : Character; -- next character
397 Z : Boolean; -- flag for zero suppress
398 N, M : Int; -- temporaries
400 begin
401 if L = No_Line_Number then
402 Write_Str (" ");
404 else
405 Z := False;
406 N := Int (L);
408 M := 100_000;
409 while M /= 0 loop
410 D := Int (N / M);
411 N := N rem M;
412 M := M / 10;
414 if D = 0 then
415 if Z then
416 C := '0';
417 else
418 C := ' ';
419 end if;
420 else
421 Z := True;
422 C := Character'Val (D + 48);
423 end if;
425 Write_Char (C);
426 end loop;
428 Write_Str (". ");
429 end if;
430 end Output_Line_Number;
432 ---------------------
433 -- Output_Msg_Text --
434 ---------------------
436 procedure Output_Msg_Text (E : Error_Msg_Id) is
437 Offs : constant Nat := Column - 1;
438 -- Offset to start of message, used for continuations
440 Max : Integer;
441 -- Maximum characters to output on next line
443 Length : Nat;
444 -- Maximum total length of lines
446 Text : constant String_Ptr := Errors.Table (E).Text;
447 Warn : constant Boolean := Errors.Table (E).Warn;
448 Warn_Chr : constant Character := Errors.Table (E).Warn_Chr;
449 Warn_Tag : String_Ptr;
450 Ptr : Natural;
451 Split : Natural;
452 Start : Natural;
454 begin
455 -- Add warning doc tag if needed
457 if Warn and then Warn_Chr /= ' ' then
458 if Warn_Chr = '?' then
459 Warn_Tag := new String'(" [enabled by default]");
461 elsif Warn_Chr in 'a' .. 'z' then
462 Warn_Tag := new String'(" [-gnatw" & Warn_Chr & ']');
464 else pragma Assert (Warn_Chr in 'A' .. 'Z');
465 Warn_Tag := new String'(" [-gnatw." & Fold_Lower (Warn_Chr) & ']');
466 end if;
468 else
469 Warn_Tag := new String'("");
470 end if;
472 -- Set error message line length
474 if Error_Msg_Line_Length = 0 then
475 Length := Nat'Last;
476 else
477 Length := Error_Msg_Line_Length;
478 end if;
480 Max := Integer (Length - Column + 1);
482 declare
483 Txt : constant String := Text.all & Warn_Tag.all;
484 Len : constant Natural := Txt'Length;
486 begin
487 -- For warning, add "warning: " unless msg starts with "info: "
489 if Errors.Table (E).Warn then
490 if Len < 6
491 or else Txt (Txt'First .. Txt'First + 5) /= "info: "
492 then
493 Write_Str ("warning: ");
494 Max := Max - 9;
495 end if;
497 -- No prefix needed for style message, "(style)" is there already
499 elsif Errors.Table (E).Style then
500 null;
502 -- All other cases, add "error: "
504 elsif Opt.Unique_Error_Tag then
505 Write_Str ("error: ");
506 Max := Max - 7;
507 end if;
509 -- Here we have to split the message up into multiple lines
511 Ptr := 1;
512 loop
513 -- Make sure we do not have ludicrously small line
515 Max := Integer'Max (Max, 20);
517 -- If remaining text fits, output it respecting LF and we are done
519 if Len - Ptr < Max then
520 for J in Ptr .. Len loop
521 if Txt (J) = ASCII.LF then
522 Write_Eol;
523 Write_Spaces (Offs);
524 else
525 Write_Char (Txt (J));
526 end if;
527 end loop;
529 return;
531 -- Line does not fit
533 else
534 Start := Ptr;
536 -- First scan forward looking for a hard end of line
538 for Scan in Ptr .. Ptr + Max - 1 loop
539 if Txt (Scan) = ASCII.LF then
540 Split := Scan - 1;
541 Ptr := Scan + 1;
542 goto Continue;
543 end if;
544 end loop;
546 -- Otherwise scan backwards looking for a space
548 for Scan in reverse Ptr .. Ptr + Max - 1 loop
549 if Txt (Scan) = ' ' then
550 Split := Scan - 1;
551 Ptr := Scan + 1;
552 goto Continue;
553 end if;
554 end loop;
556 -- If we fall through, no space, so split line arbitrarily
558 Split := Ptr + Max - 1;
559 Ptr := Split + 1;
560 end if;
562 <<Continue>>
563 if Start <= Split then
564 Write_Line (Txt (Start .. Split));
565 Write_Spaces (Offs);
566 end if;
568 Max := Integer (Length - Column + 1);
569 end loop;
570 end;
571 end Output_Msg_Text;
573 --------------------
574 -- Purge_Messages --
575 --------------------
577 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) is
578 E : Error_Msg_Id;
580 function To_Be_Purged (E : Error_Msg_Id) return Boolean;
581 -- Returns True for a message that is to be purged. Also adjusts
582 -- error counts appropriately.
584 ------------------
585 -- To_Be_Purged --
586 ------------------
588 function To_Be_Purged (E : Error_Msg_Id) return Boolean is
589 begin
590 if E /= No_Error_Msg
591 and then Errors.Table (E).Sptr > From
592 and then Errors.Table (E).Sptr < To
593 then
594 if Errors.Table (E).Warn or else Errors.Table (E).Style then
595 Warnings_Detected := Warnings_Detected - 1;
597 else
598 Total_Errors_Detected := Total_Errors_Detected - 1;
600 if Errors.Table (E).Serious then
601 Serious_Errors_Detected := Serious_Errors_Detected - 1;
602 end if;
603 end if;
605 return True;
607 else
608 return False;
609 end if;
610 end To_Be_Purged;
612 -- Start of processing for Purge_Messages
614 begin
615 while To_Be_Purged (First_Error_Msg) loop
616 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
617 end loop;
619 E := First_Error_Msg;
620 while E /= No_Error_Msg loop
621 while To_Be_Purged (Errors.Table (E).Next) loop
622 Errors.Table (E).Next :=
623 Errors.Table (Errors.Table (E).Next).Next;
624 end loop;
626 E := Errors.Table (E).Next;
627 end loop;
628 end Purge_Messages;
630 ----------------
631 -- Same_Error --
632 ----------------
634 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean is
635 Msg1 : constant String_Ptr := Errors.Table (M1).Text;
636 Msg2 : constant String_Ptr := Errors.Table (M2).Text;
638 Msg2_Len : constant Integer := Msg2'Length;
639 Msg1_Len : constant Integer := Msg1'Length;
641 begin
642 return
643 Msg1.all = Msg2.all
644 or else
645 (Msg1_Len - 10 > Msg2_Len
646 and then
647 Msg2.all = Msg1.all (1 .. Msg2_Len)
648 and then
649 Msg1 (Msg2_Len + 1 .. Msg2_Len + 10) = ", instance")
650 or else
651 (Msg2_Len - 10 > Msg1_Len
652 and then
653 Msg1.all = Msg2.all (1 .. Msg1_Len)
654 and then
655 Msg2 (Msg1_Len + 1 .. Msg1_Len + 10) = ", instance");
656 end Same_Error;
658 -------------------
659 -- Set_Msg_Blank --
660 -------------------
662 procedure Set_Msg_Blank is
663 begin
664 if Msglen > 0
665 and then Msg_Buffer (Msglen) /= ' '
666 and then Msg_Buffer (Msglen) /= '('
667 and then Msg_Buffer (Msglen) /= '-'
668 and then not Manual_Quote_Mode
669 then
670 Set_Msg_Char (' ');
671 end if;
672 end Set_Msg_Blank;
674 -------------------------------
675 -- Set_Msg_Blank_Conditional --
676 -------------------------------
678 procedure Set_Msg_Blank_Conditional is
679 begin
680 if Msglen > 0
681 and then Msg_Buffer (Msglen) /= ' '
682 and then Msg_Buffer (Msglen) /= '('
683 and then Msg_Buffer (Msglen) /= '"'
684 and then not Manual_Quote_Mode
685 then
686 Set_Msg_Char (' ');
687 end if;
688 end Set_Msg_Blank_Conditional;
690 ------------------
691 -- Set_Msg_Char --
692 ------------------
694 procedure Set_Msg_Char (C : Character) is
695 begin
697 -- The check for message buffer overflow is needed to deal with cases
698 -- where insertions get too long (in particular a child unit name can
699 -- be very long).
701 if Msglen < Max_Msg_Length then
702 Msglen := Msglen + 1;
703 Msg_Buffer (Msglen) := C;
704 end if;
705 end Set_Msg_Char;
707 ---------------------------------
708 -- Set_Msg_Insertion_File_Name --
709 ---------------------------------
711 procedure Set_Msg_Insertion_File_Name is
712 begin
713 if Error_Msg_File_1 = No_File then
714 null;
716 elsif Error_Msg_File_1 = Error_File_Name then
717 Set_Msg_Blank;
718 Set_Msg_Str ("<error>");
720 else
721 Set_Msg_Blank;
722 Get_Name_String (Error_Msg_File_1);
723 Set_Msg_Quote;
724 Set_Msg_Name_Buffer;
725 Set_Msg_Quote;
726 end if;
728 -- The following assignments ensure that the second and third {
729 -- insertion characters will correspond to the Error_Msg_File_2 and
730 -- Error_Msg_File_3 values and We suppress possible validity checks in
731 -- case operating in -gnatVa mode, and Error_Msg_File_2 or
732 -- Error_Msg_File_3 is not needed and has not been set.
734 declare
735 pragma Suppress (Range_Check);
736 begin
737 Error_Msg_File_1 := Error_Msg_File_2;
738 Error_Msg_File_2 := Error_Msg_File_3;
739 end;
740 end Set_Msg_Insertion_File_Name;
742 -----------------------------------
743 -- Set_Msg_Insertion_Line_Number --
744 -----------------------------------
746 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
747 Sindex_Loc : Source_File_Index;
748 Sindex_Flag : Source_File_Index;
750 procedure Set_At;
751 -- Outputs "at " unless last characters in buffer are " from ". Certain
752 -- messages read better with from than at.
754 ------------
755 -- Set_At --
756 ------------
758 procedure Set_At is
759 begin
760 if Msglen < 6
761 or else Msg_Buffer (Msglen - 5 .. Msglen) /= " from "
762 then
763 Set_Msg_Str ("at ");
764 end if;
765 end Set_At;
767 -- Start of processing for Set_Msg_Insertion_Line_Number
769 begin
770 Set_Msg_Blank;
772 if Loc = No_Location then
773 Set_At;
774 Set_Msg_Str ("unknown location");
776 elsif Loc = System_Location then
777 Set_Msg_Str ("in package System");
778 Set_Msg_Insertion_Run_Time_Name;
780 elsif Loc = Standard_Location then
781 Set_Msg_Str ("in package Standard");
783 elsif Loc = Standard_ASCII_Location then
784 Set_Msg_Str ("in package Standard.ASCII");
786 else
787 -- Add "at file-name:" if reference is to other than the source
788 -- file in which the error message is placed. Note that we check
789 -- full file names, rather than just the source indexes, to
790 -- deal with generic instantiations from the current file.
792 Sindex_Loc := Get_Source_File_Index (Loc);
793 Sindex_Flag := Get_Source_File_Index (Flag);
795 if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
796 Set_At;
797 Get_Name_String
798 (Reference_Name (Get_Source_File_Index (Loc)));
799 Set_Msg_Name_Buffer;
800 Set_Msg_Char (':');
802 -- If in current file, add text "at line "
804 else
805 Set_At;
806 Set_Msg_Str ("line ");
807 end if;
809 -- Output line number for reference
811 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
813 -- Deal with the instantiation case. We may have a reference to,
814 -- e.g. a type, that is declared within a generic template, and
815 -- what we are really referring to is the occurrence in an instance.
816 -- In this case, the line number of the instantiation is also of
817 -- interest, and we add a notation:
819 -- , instance at xxx
821 -- where xxx is a line number output using this same routine (and
822 -- the recursion can go further if the instantiation is itself in
823 -- a generic template).
825 -- The flag location passed to us in this situation is indeed the
826 -- line number within the template, but as described in Sinput.L
827 -- (file sinput-l.ads, section "Handling Generic Instantiations")
828 -- we can retrieve the location of the instantiation itself from
829 -- this flag location value.
831 -- Note: this processing is suppressed if Suppress_Instance_Location
832 -- is set True. This is used to prevent redundant annotations of the
833 -- location of the instantiation in the case where we are placing
834 -- the messages on the instantiation in any case.
836 if Instantiation (Sindex_Loc) /= No_Location
837 and then not Suppress_Instance_Location
838 then
839 Set_Msg_Str (", instance ");
840 Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
841 end if;
842 end if;
843 end Set_Msg_Insertion_Line_Number;
845 ----------------------------
846 -- Set_Msg_Insertion_Name --
847 ----------------------------
849 procedure Set_Msg_Insertion_Name is
850 begin
851 if Error_Msg_Name_1 = No_Name then
852 null;
854 elsif Error_Msg_Name_1 = Error_Name then
855 Set_Msg_Blank;
856 Set_Msg_Str ("<error>");
858 else
859 Set_Msg_Blank_Conditional;
860 Get_Unqualified_Decoded_Name_String (Error_Msg_Name_1);
862 -- Remove %s or %b at end. These come from unit names. If the
863 -- caller wanted the (unit) or (body), then they would have used
864 -- the $ insertion character. Certainly no error message should
865 -- ever have %b or %s explicitly occurring.
867 if Name_Len > 2
868 and then Name_Buffer (Name_Len - 1) = '%'
869 and then (Name_Buffer (Name_Len) = 'b'
870 or else
871 Name_Buffer (Name_Len) = 's')
872 then
873 Name_Len := Name_Len - 2;
874 end if;
876 -- Remove upper case letter at end, again, we should not be getting
877 -- such names, and what we hope is that the remainder makes sense.
879 if Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' then
880 Name_Len := Name_Len - 1;
881 end if;
883 -- If operator name or character literal name, just print it as is
884 -- Also print as is if it ends in a right paren (case of x'val(nnn))
886 if Name_Buffer (1) = '"'
887 or else Name_Buffer (1) = '''
888 or else Name_Buffer (Name_Len) = ')'
889 then
890 Set_Msg_Name_Buffer;
892 -- Else output with surrounding quotes in proper casing mode
894 else
895 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
896 Set_Msg_Quote;
897 Set_Msg_Name_Buffer;
898 Set_Msg_Quote;
899 end if;
900 end if;
902 -- The following assignments ensure that the second and third percent
903 -- insertion characters will correspond to the Error_Msg_Name_2 and
904 -- Error_Msg_Name_3 as required. We suppress possible validity checks in
905 -- case operating in -gnatVa mode, and Error_Msg_Name_1/2 is not needed
906 -- and has not been set.
908 declare
909 pragma Suppress (Range_Check);
910 begin
911 Error_Msg_Name_1 := Error_Msg_Name_2;
912 Error_Msg_Name_2 := Error_Msg_Name_3;
913 end;
914 end Set_Msg_Insertion_Name;
916 ------------------------------------
917 -- Set_Msg_Insertion_Name_Literal --
918 ------------------------------------
920 procedure Set_Msg_Insertion_Name_Literal is
921 begin
922 if Error_Msg_Name_1 = No_Name then
923 null;
925 elsif Error_Msg_Name_1 = Error_Name then
926 Set_Msg_Blank;
927 Set_Msg_Str ("<error>");
929 else
930 Set_Msg_Blank;
931 Get_Name_String (Error_Msg_Name_1);
932 Set_Msg_Quote;
933 Set_Msg_Name_Buffer;
934 Set_Msg_Quote;
935 end if;
937 -- The following assignments ensure that the second and third % or %%
938 -- insertion characters will correspond to the Error_Msg_Name_2 and
939 -- Error_Msg_Name_3 values and We suppress possible validity checks in
940 -- case operating in -gnatVa mode, and Error_Msg_Name_2 or
941 -- Error_Msg_Name_3 is not needed and has not been set.
943 declare
944 pragma Suppress (Range_Check);
945 begin
946 Error_Msg_Name_1 := Error_Msg_Name_2;
947 Error_Msg_Name_2 := Error_Msg_Name_3;
948 end;
949 end Set_Msg_Insertion_Name_Literal;
951 -------------------------------------
952 -- Set_Msg_Insertion_Reserved_Name --
953 -------------------------------------
955 procedure Set_Msg_Insertion_Reserved_Name is
956 begin
957 Set_Msg_Blank_Conditional;
958 Get_Name_String (Error_Msg_Name_1);
959 Set_Msg_Quote;
960 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
961 Set_Msg_Name_Buffer;
962 Set_Msg_Quote;
963 end Set_Msg_Insertion_Reserved_Name;
965 -------------------------------------
966 -- Set_Msg_Insertion_Reserved_Word --
967 -------------------------------------
969 procedure Set_Msg_Insertion_Reserved_Word
970 (Text : String;
971 J : in out Integer)
973 begin
974 Set_Msg_Blank_Conditional;
975 Name_Len := 0;
977 while J <= Text'Last and then Text (J) in 'A' .. 'Z' loop
978 Add_Char_To_Name_Buffer (Text (J));
979 J := J + 1;
980 end loop;
982 -- Here is where we make the special exception for RM
984 if Name_Len = 2 and then Name_Buffer (1 .. 2) = "RM" then
985 Set_Msg_Name_Buffer;
987 -- We make a similar exception for SPARK
989 elsif Name_Len = 5 and then Name_Buffer (1 .. 5) = "SPARK" then
990 Set_Msg_Name_Buffer;
992 -- Neither RM nor SPARK: case appropriately and add surrounding quotes
994 else
995 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
996 Set_Msg_Quote;
997 Set_Msg_Name_Buffer;
998 Set_Msg_Quote;
999 end if;
1000 end Set_Msg_Insertion_Reserved_Word;
1002 -------------------------------------
1003 -- Set_Msg_Insertion_Run_Time_Name --
1004 -------------------------------------
1006 procedure Set_Msg_Insertion_Run_Time_Name is
1007 begin
1008 if Targparm.Run_Time_Name_On_Target /= No_Name then
1009 Set_Msg_Blank_Conditional;
1010 Set_Msg_Char ('(');
1011 Get_Name_String (Targparm.Run_Time_Name_On_Target);
1012 Set_Casing (Mixed_Case);
1013 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1014 Set_Msg_Char (')');
1015 end if;
1016 end Set_Msg_Insertion_Run_Time_Name;
1018 ----------------------------
1019 -- Set_Msg_Insertion_Uint --
1020 ----------------------------
1022 procedure Set_Msg_Insertion_Uint is
1023 begin
1024 Set_Msg_Blank;
1025 UI_Image (Error_Msg_Uint_1);
1027 for J in 1 .. UI_Image_Length loop
1028 Set_Msg_Char (UI_Image_Buffer (J));
1029 end loop;
1031 -- The following assignment ensures that a second caret insertion
1032 -- character will correspond to the Error_Msg_Uint_2 parameter. We
1033 -- suppress possible validity checks in case operating in -gnatVa mode,
1034 -- and Error_Msg_Uint_2 is not needed and has not been set.
1036 declare
1037 pragma Suppress (Range_Check);
1038 begin
1039 Error_Msg_Uint_1 := Error_Msg_Uint_2;
1040 end;
1041 end Set_Msg_Insertion_Uint;
1043 -----------------
1044 -- Set_Msg_Int --
1045 -----------------
1047 procedure Set_Msg_Int (Line : Int) is
1048 begin
1049 if Line > 9 then
1050 Set_Msg_Int (Line / 10);
1051 end if;
1053 Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
1054 end Set_Msg_Int;
1056 -------------------------
1057 -- Set_Msg_Name_Buffer --
1058 -------------------------
1060 procedure Set_Msg_Name_Buffer is
1061 begin
1062 for J in 1 .. Name_Len loop
1063 Set_Msg_Char (Name_Buffer (J));
1064 end loop;
1065 end Set_Msg_Name_Buffer;
1067 -------------------
1068 -- Set_Msg_Quote --
1069 -------------------
1071 procedure Set_Msg_Quote is
1072 begin
1073 if not Manual_Quote_Mode then
1074 Set_Msg_Char ('"');
1075 end if;
1076 end Set_Msg_Quote;
1078 -----------------
1079 -- Set_Msg_Str --
1080 -----------------
1082 procedure Set_Msg_Str (Text : String) is
1083 begin
1084 for J in Text'Range loop
1085 Set_Msg_Char (Text (J));
1086 end loop;
1087 end Set_Msg_Str;
1089 ------------------------------
1090 -- Set_Next_Non_Deleted_Msg --
1091 ------------------------------
1093 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id) is
1094 begin
1095 if E = No_Error_Msg then
1096 return;
1098 else
1099 loop
1100 E := Errors.Table (E).Next;
1101 exit when E = No_Error_Msg or else not Errors.Table (E).Deleted;
1102 end loop;
1103 end if;
1104 end Set_Next_Non_Deleted_Msg;
1106 ------------------------------
1107 -- Set_Specific_Warning_Off --
1108 ------------------------------
1110 procedure Set_Specific_Warning_Off
1111 (Loc : Source_Ptr;
1112 Msg : String;
1113 Config : Boolean;
1114 Used : Boolean := False)
1116 begin
1117 Specific_Warnings.Append
1118 ((Start => Loc,
1119 Msg => new String'(Msg),
1120 Stop => Source_Last (Current_Source_File),
1121 Open => True,
1122 Used => Used,
1123 Config => Config));
1124 end Set_Specific_Warning_Off;
1126 -----------------------------
1127 -- Set_Specific_Warning_On --
1128 -----------------------------
1130 procedure Set_Specific_Warning_On
1131 (Loc : Source_Ptr;
1132 Msg : String;
1133 Err : out Boolean)
1135 begin
1136 for J in 1 .. Specific_Warnings.Last loop
1137 declare
1138 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1139 begin
1140 if Msg = SWE.Msg.all
1141 and then Loc > SWE.Start
1142 and then SWE.Open
1143 and then Get_Source_File_Index (SWE.Start) =
1144 Get_Source_File_Index (Loc)
1145 then
1146 SWE.Stop := Loc;
1147 SWE.Open := False;
1148 Err := False;
1150 -- If a config pragma is specifically cancelled, consider
1151 -- that it is no longer active as a configuration pragma.
1153 SWE.Config := False;
1154 return;
1155 end if;
1156 end;
1157 end loop;
1159 Err := True;
1160 end Set_Specific_Warning_On;
1162 ---------------------------
1163 -- Set_Warnings_Mode_Off --
1164 ---------------------------
1166 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr) is
1167 begin
1168 -- Don't bother with entries from instantiation copies, since we will
1169 -- already have a copy in the template, which is what matters.
1171 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1172 return;
1173 end if;
1175 -- If last entry in table already covers us, this is a redundant pragma
1176 -- Warnings (Off) and can be ignored. This also handles the case where
1177 -- all warnings are suppressed by command line switch.
1179 if Warnings.Last >= Warnings.First
1180 and then Warnings.Table (Warnings.Last).Start <= Loc
1181 and then Loc <= Warnings.Table (Warnings.Last).Stop
1182 then
1183 return;
1185 -- Otherwise establish a new entry, extending from the location of the
1186 -- pragma to the end of the current source file. This ending point will
1187 -- be adjusted by a subsequent pragma Warnings (On).
1189 else
1190 Warnings.Increment_Last;
1191 Warnings.Table (Warnings.Last).Start := Loc;
1192 Warnings.Table (Warnings.Last).Stop :=
1193 Source_Last (Current_Source_File);
1194 end if;
1195 end Set_Warnings_Mode_Off;
1197 --------------------------
1198 -- Set_Warnings_Mode_On --
1199 --------------------------
1201 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
1202 begin
1203 -- Don't bother with entries from instantiation copies, since we will
1204 -- already have a copy in the template, which is what matters.
1206 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1207 return;
1208 end if;
1210 -- Nothing to do unless command line switch to suppress all warnings
1211 -- is off, and the last entry in the warnings table covers this
1212 -- pragma Warnings (On), in which case adjust the end point.
1214 if (Warnings.Last >= Warnings.First
1215 and then Warnings.Table (Warnings.Last).Start <= Loc
1216 and then Loc <= Warnings.Table (Warnings.Last).Stop)
1217 and then Warning_Mode /= Suppress
1218 then
1219 Warnings.Table (Warnings.Last).Stop := Loc;
1220 end if;
1221 end Set_Warnings_Mode_On;
1223 ------------------------------------
1224 -- Test_Style_Warning_Serious_Msg --
1225 ------------------------------------
1227 procedure Test_Style_Warning_Serious_Unconditional_Msg (Msg : String) is
1228 begin
1229 -- Nothing to do for continuation line
1231 if Msg (Msg'First) = '\' then
1232 return;
1233 end if;
1235 -- Set initial values of globals (may be changed during scan)
1237 Is_Serious_Error := True;
1238 Is_Unconditional_Msg := False;
1239 Is_Warning_Msg := False;
1240 Has_Double_Exclam := False;
1242 Is_Style_Msg :=
1243 (Msg'Length > 7 and then Msg (Msg'First .. Msg'First + 6) = "(style)");
1245 for J in Msg'Range loop
1246 if Msg (J) = '?'
1247 and then (J = Msg'First or else Msg (J - 1) /= ''')
1248 then
1249 Is_Warning_Msg := True;
1250 Warning_Msg_Char := ' ';
1252 elsif Msg (J) = '!'
1253 and then (J = Msg'First or else Msg (J - 1) /= ''')
1254 then
1255 Is_Unconditional_Msg := True;
1256 Warning_Msg_Char := ' ';
1258 if J < Msg'Last and then Msg (J + 1) = '!' then
1259 Has_Double_Exclam := True;
1260 end if;
1262 elsif Msg (J) = '<'
1263 and then (J = Msg'First or else Msg (J - 1) /= ''')
1264 then
1265 Is_Warning_Msg := Error_Msg_Warn;
1266 Warning_Msg_Char := ' ';
1268 elsif Msg (J) = '|'
1269 and then (J = Msg'First or else Msg (J - 1) /= ''')
1270 then
1271 Is_Serious_Error := False;
1272 end if;
1273 end loop;
1275 if Is_Warning_Msg or Is_Style_Msg then
1276 Is_Serious_Error := False;
1277 end if;
1278 end Test_Style_Warning_Serious_Unconditional_Msg;
1280 --------------------------------
1281 -- Validate_Specific_Warnings --
1282 --------------------------------
1284 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc) is
1285 begin
1286 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1287 declare
1288 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1290 begin
1291 if not SWE.Config then
1293 -- Warn for unmatched Warnings (Off, ...)
1295 if SWE.Open then
1296 Eproc.all
1297 ("?pragma Warnings Off with no matching Warnings On",
1298 SWE.Start);
1300 -- Warn for ineffective Warnings (Off, ..)
1302 elsif not SWE.Used
1304 -- Do not issue this warning for -Wxxx messages since the
1305 -- back-end doesn't report the information.
1307 and then not
1308 (SWE.Msg'Length > 2 and then SWE.Msg (1 .. 2) = "-W")
1309 then
1310 Eproc.all
1311 ("?no warning suppressed by this pragma", SWE.Start);
1312 end if;
1313 end if;
1314 end;
1315 end loop;
1316 end Validate_Specific_Warnings;
1318 -------------------------------------
1319 -- Warning_Specifically_Suppressed --
1320 -------------------------------------
1322 function Warning_Specifically_Suppressed
1323 (Loc : Source_Ptr;
1324 Msg : String_Ptr) return Boolean
1326 function Matches (S : String; P : String) return Boolean;
1327 -- Returns true if the String S patches the pattern P, which can contain
1328 -- wild card chars (*). The entire pattern must match the entire string.
1330 -------------
1331 -- Matches --
1332 -------------
1334 function Matches (S : String; P : String) return Boolean is
1335 Slast : constant Natural := S'Last;
1336 PLast : constant Natural := P'Last;
1338 SPtr : Natural := S'First;
1339 PPtr : Natural := P'First;
1341 begin
1342 -- Loop advancing through characters of string and pattern
1344 SPtr := S'First;
1345 PPtr := P'First;
1346 loop
1347 -- Return True if pattern is a single asterisk
1349 if PPtr = PLast and then P (PPtr) = '*' then
1350 return True;
1352 -- Return True if both pattern and string exhausted
1354 elsif PPtr > PLast and then SPtr > Slast then
1355 return True;
1357 -- Return False, if one exhausted and not the other
1359 elsif PPtr > PLast or else SPtr > Slast then
1360 return False;
1362 -- Case where pattern starts with asterisk
1364 elsif P (PPtr) = '*' then
1366 -- Try all possible starting positions in S for match with
1367 -- the remaining characters of the pattern. This is the
1368 -- recursive call that implements the scanner backup.
1370 for J in SPtr .. Slast loop
1371 if Matches (S (J .. Slast), P (PPtr + 1 .. PLast)) then
1372 return True;
1373 end if;
1374 end loop;
1376 return False;
1378 -- Dealt with end of string and *, advance if we have a match
1380 elsif S (SPtr) = P (PPtr) then
1381 SPtr := SPtr + 1;
1382 PPtr := PPtr + 1;
1384 -- If first characters do not match, that's decisive
1386 else
1387 return False;
1388 end if;
1389 end loop;
1390 end Matches;
1392 -- Start of processing for Warning_Specifically_Suppressed
1394 begin
1395 -- Loop through specific warning suppression entries
1397 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1398 declare
1399 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1401 begin
1402 -- Pragma applies if it is a configuration pragma, or if the
1403 -- location is in range of a specific non-configuration pragma.
1405 if SWE.Config
1406 or else (SWE.Start <= Loc and then Loc <= SWE.Stop)
1407 then
1408 if Matches (Msg.all, SWE.Msg.all) then
1409 SWE.Used := True;
1410 return True;
1411 end if;
1412 end if;
1413 end;
1414 end loop;
1416 return False;
1417 end Warning_Specifically_Suppressed;
1419 -------------------------
1420 -- Warnings_Suppressed --
1421 -------------------------
1423 function Warnings_Suppressed (Loc : Source_Ptr) return Boolean is
1424 begin
1425 if Warning_Mode = Suppress then
1426 return True;
1427 end if;
1429 -- Loop through table of ON/OFF warnings
1431 for J in Warnings.First .. Warnings.Last loop
1432 if Warnings.Table (J).Start <= Loc
1433 and then Loc <= Warnings.Table (J).Stop
1434 then
1435 return True;
1436 end if;
1437 end loop;
1439 return False;
1440 end Warnings_Suppressed;
1442 end Erroutc;