1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2018, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
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
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
;
40 with Output
; use Output
;
41 with Sinput
; use Sinput
;
42 with Snames
; use Snames
;
43 with Stringt
; use Stringt
;
45 with Uintp
; use Uintp
;
46 with Widechar
; use Widechar
;
48 package body Erroutc
is
50 -----------------------
51 -- Local Subprograms --
52 -----------------------
54 function Matches
(S
: String; P
: String) return Boolean;
55 -- Returns true if the String S patches the pattern P, which can contain
56 -- wild card chars (*). The entire pattern must match the entire string.
57 -- Case is ignored in the comparison (so X matches x).
63 procedure Add_Class
is
68 Get_Name_String
(Name_Class
);
69 Set_Casing
(Identifier_Casing
(Flag_Source
));
74 ----------------------
75 -- Buffer_Ends_With --
76 ----------------------
78 function Buffer_Ends_With
(C
: Character) return Boolean is
80 return Msglen
> 0 and then Msg_Buffer
(Msglen
) = C
;
83 function Buffer_Ends_With
(S
: String) return Boolean is
84 Len
: constant Natural := S
'Length;
87 and then Msg_Buffer
(Msglen
- Len
) = ' '
88 and then Msg_Buffer
(Msglen
- Len
+ 1 .. Msglen
) = S
;
95 procedure Buffer_Remove
(C
: Character) is
97 if Buffer_Ends_With
(C
) then
102 procedure Buffer_Remove
(S
: String) is
104 if Buffer_Ends_With
(S
) then
105 Msglen
:= Msglen
- S
'Length;
109 -----------------------------
110 -- Check_Duplicate_Message --
111 -----------------------------
113 procedure Check_Duplicate_Message
(M1
, M2
: Error_Msg_Id
) is
114 L1
, L2
: Error_Msg_Id
;
115 N1
, N2
: Error_Msg_Id
;
117 procedure Delete_Msg
(Delete
, Keep
: Error_Msg_Id
);
118 -- Called to delete message Delete, keeping message Keep. Marks msg
119 -- Delete and all its continuations with deleted flag set to True.
120 -- Also makes sure that for the error messages that are retained the
121 -- preferred message is the one retained (we prefer the shorter one in
122 -- the case where one has an Instance tag). Note that we always know
123 -- that Keep has at least as many continuations as Delete (since we
124 -- always delete the shorter sequence).
130 procedure Delete_Msg
(Delete
, Keep
: Error_Msg_Id
) is
138 Errors
.Table
(D
).Deleted
:= True;
140 -- Adjust error message count
142 if Errors
.Table
(D
).Info
then
144 if Errors
.Table
(D
).Warn
then
145 Warning_Info_Messages
:= Warning_Info_Messages
- 1;
146 Warnings_Detected
:= Warnings_Detected
- 1;
148 Report_Info_Messages
:= Report_Info_Messages
- 1;
151 elsif Errors
.Table
(D
).Warn
or else Errors
.Table
(D
).Style
then
152 Warnings_Detected
:= Warnings_Detected
- 1;
154 -- Note: we do not need to decrement Warnings_Treated_As_Errors
155 -- because this only gets incremented if we actually output the
156 -- message, which we won't do if we are deleting it here!
158 elsif Errors
.Table
(D
).Check
then
159 Check_Messages
:= Check_Messages
- 1;
162 Total_Errors_Detected
:= Total_Errors_Detected
- 1;
164 if Errors
.Table
(D
).Serious
then
165 Serious_Errors_Detected
:= Serious_Errors_Detected
- 1;
169 -- Substitute shorter of the two error messages
171 if Errors
.Table
(K
).Text
'Length > Errors
.Table
(D
).Text
'Length then
172 Errors
.Table
(K
).Text
:= Errors
.Table
(D
).Text
;
175 D
:= Errors
.Table
(D
).Next
;
176 K
:= Errors
.Table
(K
).Next
;
178 if D
= No_Error_Msg
or else not Errors
.Table
(D
).Msg_Cont
then
184 -- Start of processing for Check_Duplicate_Message
187 -- Both messages must be non-continuation messages and not deleted
189 if Errors
.Table
(M1
).Msg_Cont
190 or else Errors
.Table
(M2
).Msg_Cont
191 or else Errors
.Table
(M1
).Deleted
192 or else Errors
.Table
(M2
).Deleted
197 -- Definitely not equal if message text does not match
199 if not Same_Error
(M1
, M2
) then
203 -- Same text. See if all continuations are also identical
209 N1
:= Errors
.Table
(L1
).Next
;
210 N2
:= Errors
.Table
(L2
).Next
;
212 -- If M1 continuations have run out, we delete M1, either the
213 -- messages have the same number of continuations, or M2 has
214 -- more and we prefer the one with more anyway.
216 if N1
= No_Error_Msg
or else not Errors
.Table
(N1
).Msg_Cont
then
220 -- If M2 continuations have run out, we delete M2
222 elsif N2
= No_Error_Msg
or else not Errors
.Table
(N2
).Msg_Cont
then
226 -- Otherwise see if continuations are the same, if not, keep both
227 -- sequences, a curious case, but better to keep everything.
229 elsif not Same_Error
(N1
, N2
) then
232 -- If continuations are the same, continue scan
239 end Check_Duplicate_Message
;
241 ------------------------
242 -- Compilation_Errors --
243 ------------------------
245 function Compilation_Errors
return Boolean is
248 Total_Errors_Detected
/= 0
249 or else (Warnings_Detected
- Warning_Info_Messages
/= 0
250 and then Warning_Mode
= Treat_As_Error
)
251 or else Warnings_Treated_As_Errors
/= 0;
252 end Compilation_Errors
;
258 procedure Debug_Output
(N
: Node_Id
) is
261 Write_Str
("*** following error message posted on node id = #");
272 procedure dmsg
(Id
: Error_Msg_Id
) is
273 E
: Error_Msg_Object
renames Errors
.Table
(Id
);
276 w
("Dumping error message, Id = ", Int
(Id
));
277 w
(" Text = ", E
.Text
.all);
278 w
(" Next = ", Int
(E
.Next
));
279 w
(" Prev = ", Int
(E
.Prev
));
280 w
(" Sfile = ", Int
(E
.Sfile
));
284 Write_Location
(E
.Sptr
);
289 Write_Location
(E
.Optr
);
292 w
(" Line = ", Int
(E
.Line
));
293 w
(" Col = ", Int
(E
.Col
));
294 w
(" Warn = ", E
.Warn
);
295 w
(" Warn_Err = ", E
.Warn_Err
);
296 w
(" Warn_Chr = '" & E
.Warn_Chr
& ''');
297 w
(" Style = ", E
.Style
);
298 w
(" Serious = ", E
.Serious
);
299 w
(" Uncond = ", E
.Uncond
);
300 w
(" Msg_Cont = ", E
.Msg_Cont
);
301 w
(" Deleted = ", E
.Deleted
);
302 w
(" Node = ", Int
(E
.Node
));
311 function Get_Location
(E
: Error_Msg_Id
) return Source_Ptr
is
313 return Errors
.Table
(E
).Sptr
;
320 function Get_Msg_Id
return Error_Msg_Id
is
325 ---------------------
326 -- Get_Warning_Tag --
327 ---------------------
329 function Get_Warning_Tag
(Id
: Error_Msg_Id
) return String is
330 Warn
: constant Boolean := Errors
.Table
(Id
).Warn
;
331 Warn_Chr
: constant Character := Errors
.Table
(Id
).Warn_Chr
;
333 if Warn
and then Warn_Chr
/= ' ' then
334 if Warn_Chr
= '?' then
335 return "[enabled by default]";
336 elsif Warn_Chr
= '*' then
337 return "[restriction warning]";
338 elsif Warn_Chr
= '$' then
340 elsif Warn_Chr
in 'a' .. 'z' then
341 return "[-gnatw" & Warn_Chr
& ']';
342 else pragma Assert
(Warn_Chr
in 'A' .. 'Z');
343 return "[-gnatw." & Fold_Lower
(Warn_Chr
) & ']';
354 function Matches
(S
: String; P
: String) return Boolean is
355 Slast
: constant Natural := S
'Last;
356 PLast
: constant Natural := P
'Last;
358 SPtr
: Natural := S
'First;
359 PPtr
: Natural := P
'First;
362 -- Loop advancing through characters of string and pattern
367 -- Return True if pattern is a single asterisk
369 if PPtr
= PLast
and then P
(PPtr
) = '*' then
372 -- Return True if both pattern and string exhausted
374 elsif PPtr
> PLast
and then SPtr
> Slast
then
377 -- Return False, if one exhausted and not the other
379 elsif PPtr
> PLast
or else SPtr
> Slast
then
382 -- Case where pattern starts with asterisk
384 elsif P
(PPtr
) = '*' then
386 -- Try all possible starting positions in S for match with the
387 -- remaining characters of the pattern. This is the recursive
388 -- call that implements the scanner backup.
390 for J
in SPtr
.. Slast
loop
391 if Matches
(S
(J
.. Slast
), P
(PPtr
+ 1 .. PLast
)) then
398 -- Dealt with end of string and *, advance if we have a match
400 elsif Fold_Lower
(S
(SPtr
)) = Fold_Lower
(P
(PPtr
)) then
404 -- If first characters do not match, that's decisive
412 -----------------------
413 -- Output_Error_Msgs --
414 -----------------------
416 procedure Output_Error_Msgs
(E
: in out Error_Msg_Id
) is
422 Mult_Flags
: Boolean := False;
427 -- Skip deleted messages at start
429 if Errors
.Table
(S
).Deleted
then
430 Set_Next_Non_Deleted_Msg
(S
);
433 -- Figure out if we will place more than one error flag on this line
436 while T
/= No_Error_Msg
437 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
438 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
440 if Errors
.Table
(T
).Sptr
> Errors
.Table
(E
).Sptr
then
444 Set_Next_Non_Deleted_Msg
(T
);
447 -- Output the error flags. The circuit here makes sure that the tab
448 -- characters in the original line are properly accounted for. The
449 -- eight blanks at the start are to match the line number.
451 if not Debug_Flag_2
then
453 P
:= Line_Start
(Errors
.Table
(E
).Sptr
);
456 -- Loop through error messages for this line to place flags
459 while T
/= No_Error_Msg
460 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
461 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
464 Src
: Source_Buffer_Ptr
465 renames Source_Text
(Errors
.Table
(T
).Sfile
);
468 -- Loop to output blanks till current flag position
470 while P
< Errors
.Table
(T
).Sptr
loop
472 -- Horizontal tab case, just echo the tab
474 if Src
(P
) = ASCII
.HT
then
475 Write_Char
(ASCII
.HT
);
478 -- Deal with wide character case, but don't include brackets
479 -- notation in this circuit, since we know that this will
480 -- display unencoded (no one encodes brackets notation).
483 and then Is_Start_Of_Wide_Char
(Src
, P
)
488 -- Normal non-wide character case (or bracket)
496 -- Output flag (unless already output, this happens if more
497 -- than one error message occurs at the same flag position).
499 if P
= Errors
.Table
(T
).Sptr
then
500 if (Flag_Num
= 1 and then not Mult_Flags
)
506 (Character'Val (Character'Pos ('0') + Flag_Num
));
509 -- Skip past the corresponding source text character
511 -- Horizontal tab case, we output a flag at the tab position
512 -- so now we output a tab to match up with the text.
514 if Src
(P
) = ASCII
.HT
then
515 Write_Char
(ASCII
.HT
);
518 -- Skip wide character other than left bracket
521 and then Is_Start_Of_Wide_Char
(Src
, P
)
525 -- Skip normal non-wide character case (or bracket)
533 Set_Next_Non_Deleted_Msg
(T
);
534 Flag_Num
:= Flag_Num
+ 1;
540 -- Now output the error messages
543 while T
/= No_Error_Msg
544 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
545 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
551 while Column
< 74 loop
559 Set_Next_Non_Deleted_Msg
(T
);
563 end Output_Error_Msgs
;
565 ------------------------
566 -- Output_Line_Number --
567 ------------------------
569 procedure Output_Line_Number
(L
: Logical_Line_Number
) is
570 D
: Int
; -- next digit
571 C
: Character; -- next character
572 Z
: Boolean; -- flag for zero suppress
573 N
, M
: Int
; -- temporaries
576 if L
= No_Line_Number
then
597 C
:= Character'Val (D
+ 48);
605 end Output_Line_Number
;
607 ---------------------
608 -- Output_Msg_Text --
609 ---------------------
611 procedure Output_Msg_Text
(E
: Error_Msg_Id
) is
612 Offs
: constant Nat
:= Column
- 1;
613 -- Offset to start of message, used for continuations
616 -- Maximum characters to output on next line
619 -- Maximum total length of lines
621 Text
: constant String_Ptr
:= Errors
.Table
(E
).Text
;
628 Tag
: constant String := Get_Warning_Tag
(E
);
633 -- Postfix warning tag to message if needed
635 if Tag
/= "" and then Warning_Doc_Switch
then
636 if Include_Subprogram_In_Messages
then
639 (Subprogram_Name_Ptr (Errors.Table (E).Node) &
640 ": " & Text.all & ' ' & Tag);
642 Txt := new String'(Text
.all & ' ' & Tag
);
645 elsif Include_Subprogram_In_Messages
646 and then (Errors
.Table
(E
).Warn
or else Errors
.Table
(E
).Style
)
650 (Subprogram_Name_Ptr (Errors.Table (E).Node) &
656 -- Deal with warning case
658 if Errors.Table (E).Warn or else Errors.Table (E).Info then
660 -- For info messages, prefix message with "info: "
662 if Errors.Table (E).Info then
663 Txt := new String'("info: " & Txt
.all);
665 -- Warning treated as error
667 elsif Errors
.Table
(E
).Warn_Err
then
669 -- We prefix with "error:" rather than warning: and postfix
670 -- [warning-as-error] at the end.
672 Warnings_Treated_As_Errors
:= Warnings_Treated_As_Errors
+ 1;
673 Txt
:= new String'("error: " & Txt.all & " [warning-as-error]");
675 -- Normal case, prefix with "warning: "
678 Txt := new String'("warning: " & Txt
.all);
681 -- No prefix needed for style message, "(style)" is there already
683 elsif Errors
.Table
(E
).Style
then
686 -- No prefix needed for check message, severity is there already
688 elsif Errors
.Table
(E
).Check
then
691 -- All other cases, add "error: " if unique error tag set
693 elsif Opt
.Unique_Error_Tag
then
694 Txt
:= new String'("error: " & Txt.all);
697 -- Set error message line length and length of message
699 if Error_Msg_Line_Length = 0 then
702 Length := Error_Msg_Line_Length;
705 Max := Integer (Length - Column + 1);
708 -- Here we have to split the message up into multiple lines
712 -- Make sure we do not have ludicrously small line
714 Max := Integer'Max (Max, 20);
716 -- If remaining text fits, output it respecting LF and we are done
718 if Len - Ptr < Max then
719 for J in Ptr .. Len loop
720 if Txt (J) = ASCII.LF then
724 Write_Char (Txt (J));
735 -- First scan forward looking for a hard end of line
737 for Scan in Ptr .. Ptr + Max - 1 loop
738 if Txt (Scan) = ASCII.LF then
745 -- Otherwise scan backwards looking for a space
747 for Scan in reverse Ptr .. Ptr + Max - 1 loop
748 if Txt (Scan) = ' ' then
755 -- If we fall through, no space, so split line arbitrarily
757 Split := Ptr + Max - 1;
762 if Start <= Split then
763 Write_Line (Txt (Start .. Split));
767 Max := Integer (Length - Column + 1);
772 ---------------------
773 -- Prescan_Message --
774 ---------------------
776 procedure Prescan_Message (Msg : String) is
780 -- Nothing to do for continuation line
782 if Msg (Msg'First) = '\
' then
786 -- Set initial values of globals (may be changed during scan)
788 Is_Serious_Error := True;
789 Is_Unconditional_Msg := False;
790 Is_Warning_Msg := False;
791 Has_Double_Exclam := False;
793 -- Check style message
796 Msg'Length > 7 and then Msg (Msg'First .. Msg'First + 6) = "(style)";
798 -- Check info message
801 Msg'Length > 6 and then Msg (Msg'First .. Msg'First + 5) = "info: ";
803 -- Check check message
806 (Msg'Length > 8 and then Msg (Msg'First .. Msg'First + 7) = "medium: ")
808 (Msg'Length > 6 and then Msg (Msg'First .. Msg'First + 5) = "high: ")
810 (Msg'Length > 5 and then Msg (Msg'First .. Msg'First + 4) = "low: ");
812 -- Loop through message looking for relevant insertion sequences
815 while J <= Msg'Last loop
817 -- If we have a quote, don't look at following character
819 if Msg (J) = ''' then
822 -- Warning message (? or < insertion sequence)
824 elsif Msg (J) = '?
' or else Msg (J) = '<' then
825 Is_Warning_Msg := Msg (J) = '?
' or else Error_Msg_Warn;
826 Warning_Msg_Char := ' ';
829 if Is_Warning_Msg then
831 C : constant Character := Msg (J - 1);
833 if J <= Msg'Last then
835 Warning_Msg_Char := '?
';
838 elsif J < Msg'Last and then Msg (J + 1) = C
839 and then (Msg (J) in 'a
' .. 'z
' or else
840 Msg (J) in 'A
' .. 'Z
' or else
841 Msg (J) = '*' or else
844 Warning_Msg_Char := Msg (J);
851 -- Bomb if untagged warning message. This code can be uncommented
852 -- for debugging when looking for untagged warning messages.
854 -- if Is_Warning_Msg and then Warning_Msg_Char = ' ' then
855 -- raise Program_Error;
858 -- Unconditional message (! insertion)
860 elsif Msg (J) = '!' then
861 Is_Unconditional_Msg := True;
864 if J <= Msg'Last and then Msg (J) = '!' then
865 Has_Double_Exclam := True;
869 -- Non-serious error (| insertion)
871 elsif Msg (J) = '|
' then
872 Is_Serious_Error := False;
880 if Is_Info_Msg or Is_Warning_Msg or Is_Style_Msg or Is_Check_Msg then
881 Is_Serious_Error := False;
889 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) is
892 function To_Be_Purged (E : Error_Msg_Id) return Boolean;
893 -- Returns True for a message that is to be purged. Also adjusts
894 -- error counts appropriately.
900 function To_Be_Purged (E : Error_Msg_Id) return Boolean is
903 and then Errors.Table (E).Sptr > From
904 and then Errors.Table (E).Sptr < To
906 if Errors.Table (E).Warn or else Errors.Table (E).Style then
907 Warnings_Detected := Warnings_Detected - 1;
910 Total_Errors_Detected := Total_Errors_Detected - 1;
912 if Errors.Table (E).Serious then
913 Serious_Errors_Detected := Serious_Errors_Detected - 1;
924 -- Start of processing for Purge_Messages
927 while To_Be_Purged (First_Error_Msg) loop
928 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
931 E := First_Error_Msg;
932 while E /= No_Error_Msg loop
933 while To_Be_Purged (Errors.Table (E).Next) loop
934 Errors.Table (E).Next :=
935 Errors.Table (Errors.Table (E).Next).Next;
938 E := Errors.Table (E).Next;
946 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean is
947 Msg1 : constant String_Ptr := Errors.Table (M1).Text;
948 Msg2 : constant String_Ptr := Errors.Table (M2).Text;
950 Msg2_Len : constant Integer := Msg2'Length;
951 Msg1_Len : constant Integer := Msg1'Length;
957 (Msg1_Len - 10 > Msg2_Len
959 Msg2.all = Msg1.all (1 .. Msg2_Len)
961 Msg1 (Msg2_Len + 1 .. Msg2_Len + 10) = ", instance")
963 (Msg2_Len - 10 > Msg1_Len
965 Msg1.all = Msg2.all (1 .. Msg1_Len)
967 Msg2 (Msg1_Len + 1 .. Msg1_Len + 10) = ", instance");
974 procedure Set_Msg_Blank is
977 and then Msg_Buffer (Msglen) /= ' '
978 and then Msg_Buffer (Msglen) /= '('
979 and then Msg_Buffer (Msglen) /= '-'
980 and then not Manual_Quote_Mode
986 -------------------------------
987 -- Set_Msg_Blank_Conditional --
988 -------------------------------
990 procedure Set_Msg_Blank_Conditional is
993 and then Msg_Buffer (Msglen) /= ' '
994 and then Msg_Buffer (Msglen) /= '('
995 and then Msg_Buffer (Msglen) /= '"'
996 and then not Manual_Quote_Mode
1000 end Set_Msg_Blank_Conditional;
1006 procedure Set_Msg_Char (C : Character) is
1009 -- The check for message buffer overflow is needed to deal with cases
1010 -- where insertions get too long (in particular a child unit name can
1013 if Msglen < Max_Msg_Length then
1014 Msglen := Msglen + 1;
1015 Msg_Buffer (Msglen) := C;
1019 ---------------------------------
1020 -- Set_Msg_Insertion_File_Name --
1021 ---------------------------------
1023 procedure Set_Msg_Insertion_File_Name is
1025 if Error_Msg_File_1 = No_File then
1028 elsif Error_Msg_File_1 = Error_File_Name then
1030 Set_Msg_Str ("<error
>");
1034 Get_Name_String (Error_Msg_File_1);
1036 Set_Msg_Name_Buffer;
1040 -- The following assignments ensure that the second and third {
1041 -- insertion characters will correspond to the Error_Msg_File_2 and
1042 -- Error_Msg_File_3 values and We suppress possible validity checks in
1043 -- case operating in -gnatVa mode, and Error_Msg_File_2 or
1044 -- Error_Msg_File_3 is not needed and has not been set.
1047 pragma Suppress (Range_Check);
1049 Error_Msg_File_1 := Error_Msg_File_2;
1050 Error_Msg_File_2 := Error_Msg_File_3;
1052 end Set_Msg_Insertion_File_Name;
1054 -----------------------------------
1055 -- Set_Msg_Insertion_Line_Number --
1056 -----------------------------------
1058 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
1059 Sindex_Loc : Source_File_Index;
1060 Sindex_Flag : Source_File_Index;
1061 Fname : File_Name_Type;
1065 -- Outputs "at " unless last characters in buffer are " from
". Certain
1066 -- messages read better with from than at.
1075 or else Msg_Buffer (Msglen - 5 .. Msglen) /= " from
"
1077 Set_Msg_Str ("at ");
1081 -- Start of processing for Set_Msg_Insertion_Line_Number
1086 if Loc = No_Location then
1088 Set_Msg_Str ("unknown location
");
1090 elsif Loc = System_Location then
1091 Set_Msg_Str ("in package System
");
1092 Set_Msg_Insertion_Run_Time_Name;
1094 elsif Loc = Standard_Location then
1095 Set_Msg_Str ("in package Standard
");
1097 elsif Loc = Standard_ASCII_Location then
1098 Set_Msg_Str ("in package Standard
.ASCII
");
1101 -- Add "at file
-name
:" if reference is to other than the source
1102 -- file in which the error message is placed. Note that we check
1103 -- full file names, rather than just the source indexes, to
1104 -- deal with generic instantiations from the current file.
1106 Sindex_Loc := Get_Source_File_Index (Loc);
1107 Sindex_Flag := Get_Source_File_Index (Flag);
1109 if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
1111 Fname := Reference_Name (Get_Source_File_Index (Loc));
1112 Int_File := Is_Internal_File_Name (Fname);
1113 Get_Name_String (Fname);
1114 Set_Msg_Name_Buffer;
1116 if not (Int_File and Debug_Flag_Dot_K) then
1118 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1121 -- If in current file, add text "at line
"
1125 Set_Msg_Str ("line
");
1127 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1130 -- Deal with the instantiation case. We may have a reference to,
1131 -- e.g. a type, that is declared within a generic template, and
1132 -- what we are really referring to is the occurrence in an instance.
1133 -- In this case, the line number of the instantiation is also of
1134 -- interest, and we add a notation:
1136 -- , instance at xxx
1138 -- where xxx is a line number output using this same routine (and
1139 -- the recursion can go further if the instantiation is itself in
1140 -- a generic template).
1142 -- The flag location passed to us in this situation is indeed the
1143 -- line number within the template, but as described in Sinput.L
1144 -- (file sinput-l.ads, section "Handling
Generic Instantiations
")
1145 -- we can retrieve the location of the instantiation itself from
1146 -- this flag location value.
1148 -- Note: this processing is suppressed if Suppress_Instance_Location
1149 -- is set True. This is used to prevent redundant annotations of the
1150 -- location of the instantiation in the case where we are placing
1151 -- the messages on the instantiation in any case.
1153 if Instantiation (Sindex_Loc) /= No_Location
1154 and then not Suppress_Instance_Location
1156 Set_Msg_Str (", instance
");
1157 Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
1160 end Set_Msg_Insertion_Line_Number;
1162 ----------------------------
1163 -- Set_Msg_Insertion_Name --
1164 ----------------------------
1166 procedure Set_Msg_Insertion_Name is
1168 if Error_Msg_Name_1 = No_Name then
1171 elsif Error_Msg_Name_1 = Error_Name then
1173 Set_Msg_Str ("<error
>");
1176 Set_Msg_Blank_Conditional;
1177 Get_Unqualified_Decoded_Name_String (Error_Msg_Name_1);
1179 -- Remove %s or %b at end. These come from unit names. If the
1180 -- caller wanted the (unit) or (body), then they would have used
1181 -- the $ insertion character. Certainly no error message should
1182 -- ever have %b or %s explicitly occurring.
1185 and then Name_Buffer (Name_Len - 1) = '%'
1186 and then (Name_Buffer (Name_Len) = 'b'
1188 Name_Buffer (Name_Len) = 's')
1190 Name_Len := Name_Len - 2;
1193 -- Remove upper case letter at end, again, we should not be getting
1194 -- such names, and what we hope is that the remainder makes sense.
1196 if Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' then
1197 Name_Len := Name_Len - 1;
1200 -- If operator name or character literal name, just print it as is
1201 -- Also print as is if it ends in a right paren (case of x'val(nnn))
1203 if Name_Buffer (1) = '"'
1204 or else Name_Buffer (1) = '''
1205 or else Name_Buffer (Name_Len) = ')'
1207 Set_Msg_Name_Buffer;
1209 -- Else output with surrounding quotes in proper casing mode
1212 Set_Casing (Identifier_Casing (Flag_Source));
1214 Set_Msg_Name_Buffer;
1219 -- The following assignments ensure that the second and third percent
1220 -- insertion characters will correspond to the Error_Msg_Name_2 and
1221 -- Error_Msg_Name_3 as required. We suppress possible validity checks in
1222 -- case operating in -gnatVa mode, and Error_Msg_Name_1/2 is not needed
1223 -- and has not been set.
1226 pragma Suppress (Range_Check);
1228 Error_Msg_Name_1 := Error_Msg_Name_2;
1229 Error_Msg_Name_2 := Error_Msg_Name_3;
1231 end Set_Msg_Insertion_Name;
1233 ------------------------------------
1234 -- Set_Msg_Insertion_Name_Literal --
1235 ------------------------------------
1237 procedure Set_Msg_Insertion_Name_Literal is
1239 if Error_Msg_Name_1 = No_Name then
1242 elsif Error_Msg_Name_1 = Error_Name then
1244 Set_Msg_Str ("<error>");
1248 Get_Name_String (Error_Msg_Name_1);
1250 Set_Msg_Name_Buffer;
1254 -- The following assignments ensure that the second and third % or %%
1255 -- insertion characters will correspond to the Error_Msg_Name_2 and
1256 -- Error_Msg_Name_3 values and We suppress possible validity checks in
1257 -- case operating in -gnatVa mode, and Error_Msg_Name_2 or
1258 -- Error_Msg_Name_3 is not needed and has not been set.
1261 pragma Suppress (Range_Check);
1263 Error_Msg_Name_1 := Error_Msg_Name_2;
1264 Error_Msg_Name_2 := Error_Msg_Name_3;
1266 end Set_Msg_Insertion_Name_Literal;
1268 -------------------------------------
1269 -- Set_Msg_Insertion_Reserved_Name --
1270 -------------------------------------
1272 procedure Set_Msg_Insertion_Reserved_Name is
1274 Set_Msg_Blank_Conditional;
1275 Get_Name_String (Error_Msg_Name_1);
1277 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1278 Set_Msg_Name_Buffer;
1280 end Set_Msg_Insertion_Reserved_Name;
1282 -------------------------------------
1283 -- Set_Msg_Insertion_Reserved_Word --
1284 -------------------------------------
1286 procedure Set_Msg_Insertion_Reserved_Word
1291 Set_Msg_Blank_Conditional;
1294 while J <= Text'Last and then Text (J) in 'A
' .. 'Z
' loop
1295 Add_Char_To_Name_Buffer (Text (J));
1299 -- Here is where we make the special exception for RM
1301 if Name_Len = 2 and then Name_Buffer (1 .. 2) = "RM" then
1302 Set_Msg_Name_Buffer;
1304 -- We make a similar exception for SPARK
1306 elsif Name_Len = 5 and then Name_Buffer (1 .. 5) = "SPARK" then
1307 Set_Msg_Name_Buffer;
1309 -- Neither RM nor SPARK: case appropriately and add surrounding quotes
1312 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1314 Set_Msg_Name_Buffer;
1317 end Set_Msg_Insertion_Reserved_Word;
1319 -------------------------------------
1320 -- Set_Msg_Insertion_Run_Time_Name --
1321 -------------------------------------
1323 procedure Set_Msg_Insertion_Run_Time_Name is
1325 if Targparm.Run_Time_Name_On_Target /= No_Name then
1326 Set_Msg_Blank_Conditional;
1328 Get_Name_String (Targparm.Run_Time_Name_On_Target);
1329 Set_Casing (Mixed_Case);
1330 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1333 end Set_Msg_Insertion_Run_Time_Name;
1335 ----------------------------
1336 -- Set_Msg_Insertion_Uint --
1337 ----------------------------
1339 procedure Set_Msg_Insertion_Uint is
1342 UI_Image (Error_Msg_Uint_1);
1344 for J in 1 .. UI_Image_Length loop
1345 Set_Msg_Char (UI_Image_Buffer (J));
1348 -- The following assignment ensures that a second caret insertion
1349 -- character will correspond to the Error_Msg_Uint_2 parameter. We
1350 -- suppress possible validity checks in case operating in -gnatVa mode,
1351 -- and Error_Msg_Uint_2 is not needed and has not been set.
1354 pragma Suppress (Range_Check);
1356 Error_Msg_Uint_1 := Error_Msg_Uint_2;
1358 end Set_Msg_Insertion_Uint;
1364 procedure Set_Msg_Int (Line : Int) is
1367 Set_Msg_Int (Line / 10);
1370 Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
1373 -------------------------
1374 -- Set_Msg_Name_Buffer --
1375 -------------------------
1377 procedure Set_Msg_Name_Buffer is
1379 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1380 end Set_Msg_Name_Buffer;
1386 procedure Set_Msg_Quote is
1388 if not Manual_Quote_Mode then
1397 procedure Set_Msg_Str (Text : String) is
1399 -- Do replacement for special x'Class aspect names
1401 if Text = "_Pre
" then
1402 Set_Msg_Str ("Pre
'Class");
1404 elsif Text = "_Post
" then
1405 Set_Msg_Str ("Post
'Class");
1407 elsif Text = "_Type_Invariant
" then
1408 Set_Msg_Str ("Type_Invariant
'Class");
1410 elsif Text = "_pre
" then
1411 Set_Msg_Str ("pre
'class");
1413 elsif Text = "_post
" then
1414 Set_Msg_Str ("post
'class");
1416 elsif Text = "_type_invariant
" then
1417 Set_Msg_Str ("type_invariant
'class");
1419 elsif Text = "_PRE
" then
1420 Set_Msg_Str ("PRE
'CLASS");
1422 elsif Text = "_POST
" then
1423 Set_Msg_Str ("POST
'CLASS");
1425 elsif Text = "_TYPE_INVARIANT
" then
1426 Set_Msg_Str ("TYPE_INVARIANT
'CLASS");
1428 -- Normal case with no replacement
1431 for J in Text'Range loop
1432 Set_Msg_Char (Text (J));
1437 ------------------------------
1438 -- Set_Next_Non_Deleted_Msg --
1439 ------------------------------
1441 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id) is
1443 if E = No_Error_Msg then
1448 E := Errors.Table (E).Next;
1449 exit when E = No_Error_Msg or else not Errors.Table (E).Deleted;
1452 end Set_Next_Non_Deleted_Msg;
1454 ------------------------------
1455 -- Set_Specific_Warning_Off --
1456 ------------------------------
1458 procedure Set_Specific_Warning_Off
1463 Used : Boolean := False)
1466 Specific_Warnings.Append
1468 Msg => new String'(Msg),
1469 Stop => Source_Last (Get_Source_File_Index (Loc)),
1474 end Set_Specific_Warning_Off;
1476 -----------------------------
1477 -- Set_Specific_Warning_On --
1478 -----------------------------
1480 procedure Set_Specific_Warning_On
1486 for J in 1 .. Specific_Warnings.Last loop
1488 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1491 if Msg = SWE.Msg.all
1492 and then Loc > SWE.Start
1494 and then Get_Source_File_Index (SWE.Start) =
1495 Get_Source_File_Index (Loc)
1501 -- If a config pragma is specifically cancelled, consider
1502 -- that it is no longer active as a configuration pragma.
1504 SWE.Config := False;
1511 end Set_Specific_Warning_On;
1513 ---------------------------
1514 -- Set_Warnings_Mode_Off --
1515 ---------------------------
1517 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id) is
1519 -- Don't bother with entries from instantiation copies, since we will
1520 -- already have a copy in the template, which is what matters.
1522 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1526 -- If all warnings are suppressed by command line switch, this can
1527 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1528 -- Warnings to be stored for the formal verification backend.
1530 if Warning_Mode = Suppress
1531 and then not GNATprove_Mode
1536 -- If last entry in table already covers us, this is a redundant pragma
1537 -- Warnings (Off) and can be ignored.
1539 if Warnings.Last >= Warnings.First
1540 and then Warnings.Table (Warnings.Last).Start <= Loc
1541 and then Loc <= Warnings.Table (Warnings.Last).Stop
1546 -- If none of those special conditions holds, establish a new entry,
1547 -- extending from the location of the pragma to the end of the current
1548 -- source file. This ending point will be adjusted by a subsequent
1549 -- corresponding pragma Warnings (On).
1553 Stop => Source_Last (Get_Source_File_Index (Loc)),
1555 end Set_Warnings_Mode_Off;
1557 --------------------------
1558 -- Set_Warnings_Mode_On --
1559 --------------------------
1561 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
1563 -- Don't bother with entries from instantiation copies, since we will
1564 -- already have a copy in the template, which is what matters.
1566 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1570 -- If all warnings are suppressed by command line switch, this can
1571 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1572 -- Warnings to be stored for the formal verification backend.
1574 if Warning_Mode = Suppress
1575 and then not GNATprove_Mode
1580 -- If the last entry in the warnings table covers this pragma, then
1581 -- we adjust the end point appropriately.
1583 if Warnings.Last >= Warnings.First
1584 and then Warnings.Table (Warnings.Last).Start <= Loc
1585 and then Loc <= Warnings.Table (Warnings.Last).Stop
1587 Warnings.Table (Warnings.Last).Stop := Loc;
1589 end Set_Warnings_Mode_On;
1591 --------------------------------
1592 -- Validate_Specific_Warnings --
1593 --------------------------------
1595 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc) is
1597 if not Warn_On_Warnings_Off then
1601 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1603 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1606 if not SWE.Config then
1608 -- Warn for unmatched Warnings (Off, ...)
1612 ("?W?
pragma Warnings Off
with no matching Warnings On
",
1615 -- Warn for ineffective Warnings (Off, ..)
1619 -- Do not issue this warning for -Wxxx messages since the
1620 -- back-end doesn't report the information. Note that there
1621 -- is always an asterisk at the start of every message.
1624 (SWE.Msg'Length > 3 and then SWE.Msg (2 .. 3) = "-W
")
1627 ("?W?no warning suppressed by this
pragma", SWE.Start);
1632 end Validate_Specific_Warnings;
1634 -------------------------------------
1635 -- Warning_Specifically_Suppressed --
1636 -------------------------------------
1638 function Warning_Specifically_Suppressed
1641 Tag : String := "") return String_Id
1644 -- Loop through specific warning suppression entries
1646 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1648 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1651 -- Pragma applies if it is a configuration pragma, or if the
1652 -- location is in range of a specific non-configuration pragma.
1655 or else (SWE.Start <= Loc and then Loc <= SWE.Stop)
1657 if Matches (Msg.all, SWE.Msg.all)
1658 or else Matches (Tag, SWE.Msg.all)
1668 end Warning_Specifically_Suppressed;
1670 ------------------------------
1671 -- Warning_Treated_As_Error --
1672 ------------------------------
1674 function Warning_Treated_As_Error (Msg : String) return Boolean is
1676 for J in 1 .. Warnings_As_Errors_Count loop
1677 if Matches (Msg, Warnings_As_Errors (J).all) then
1683 end Warning_Treated_As_Error;
1685 -------------------------
1686 -- Warnings_Suppressed --
1687 -------------------------
1689 function Warnings_Suppressed (Loc : Source_Ptr) return String_Id is
1691 -- Loop through table of ON/OFF warnings
1693 for J in Warnings.First .. Warnings.Last loop
1694 if Warnings.Table (J).Start <= Loc
1695 and then Loc <= Warnings.Table (J).Stop
1697 return Warnings.Table (J).Reason;
1701 if Warning_Mode = Suppress then
1702 return Null_String_Id;
1706 end Warnings_Suppressed;