1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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
;
44 with Targparm
; use Targparm
;
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
);
310 function Get_Location
(E
: Error_Msg_Id
) return Source_Ptr
is
312 return Errors
.Table
(E
).Sptr
;
319 function Get_Msg_Id
return Error_Msg_Id
is
324 ---------------------
325 -- Get_Warning_Tag --
326 ---------------------
328 function Get_Warning_Tag
(Id
: Error_Msg_Id
) return String is
329 Warn
: constant Boolean := Errors
.Table
(Id
).Warn
;
330 Warn_Chr
: constant Character := Errors
.Table
(Id
).Warn_Chr
;
332 if Warn
and then Warn_Chr
/= ' ' then
333 if Warn_Chr
= '?' then
334 return "[enabled by default]";
335 elsif Warn_Chr
= '*' then
336 return "[restriction warning]";
337 elsif Warn_Chr
= '$' then
339 elsif Warn_Chr
in 'a' .. 'z' then
340 return "[-gnatw" & Warn_Chr
& ']';
341 else pragma Assert
(Warn_Chr
in 'A' .. 'Z');
342 return "[-gnatw." & Fold_Lower
(Warn_Chr
) & ']';
353 function Matches
(S
: String; P
: String) return Boolean is
354 Slast
: constant Natural := S
'Last;
355 PLast
: constant Natural := P
'Last;
357 SPtr
: Natural := S
'First;
358 PPtr
: Natural := P
'First;
361 -- Loop advancing through characters of string and pattern
366 -- Return True if pattern is a single asterisk
368 if PPtr
= PLast
and then P
(PPtr
) = '*' then
371 -- Return True if both pattern and string exhausted
373 elsif PPtr
> PLast
and then SPtr
> Slast
then
376 -- Return False, if one exhausted and not the other
378 elsif PPtr
> PLast
or else SPtr
> Slast
then
381 -- Case where pattern starts with asterisk
383 elsif P
(PPtr
) = '*' then
385 -- Try all possible starting positions in S for match with the
386 -- remaining characters of the pattern. This is the recursive
387 -- call that implements the scanner backup.
389 for J
in SPtr
.. Slast
loop
390 if Matches
(S
(J
.. Slast
), P
(PPtr
+ 1 .. PLast
)) then
397 -- Dealt with end of string and *, advance if we have a match
399 elsif Fold_Lower
(S
(SPtr
)) = Fold_Lower
(P
(PPtr
)) then
403 -- If first characters do not match, that's decisive
411 -----------------------
412 -- Output_Error_Msgs --
413 -----------------------
415 procedure Output_Error_Msgs
(E
: in out Error_Msg_Id
) is
421 Mult_Flags
: Boolean := False;
426 -- Skip deleted messages at start
428 if Errors
.Table
(S
).Deleted
then
429 Set_Next_Non_Deleted_Msg
(S
);
432 -- Figure out if we will place more than one error flag on this line
435 while T
/= No_Error_Msg
436 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
437 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
439 if Errors
.Table
(T
).Sptr
> Errors
.Table
(E
).Sptr
then
443 Set_Next_Non_Deleted_Msg
(T
);
446 -- Output the error flags. The circuit here makes sure that the tab
447 -- characters in the original line are properly accounted for. The
448 -- eight blanks at the start are to match the line number.
450 if not Debug_Flag_2
then
452 P
:= Line_Start
(Errors
.Table
(E
).Sptr
);
455 -- Loop through error messages for this line to place flags
458 while T
/= No_Error_Msg
459 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
460 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
463 Src
: Source_Buffer_Ptr
464 renames Source_Text
(Errors
.Table
(T
).Sfile
);
467 -- Loop to output blanks till current flag position
469 while P
< Errors
.Table
(T
).Sptr
loop
471 -- Horizontal tab case, just echo the tab
473 if Src
(P
) = ASCII
.HT
then
474 Write_Char
(ASCII
.HT
);
477 -- Deal with wide character case, but don't include brackets
478 -- notation in this circuit, since we know that this will
479 -- display unencoded (no one encodes brackets notation).
482 and then Is_Start_Of_Wide_Char
(Src
, P
)
487 -- Normal non-wide character case (or bracket)
495 -- Output flag (unless already output, this happens if more
496 -- than one error message occurs at the same flag position).
498 if P
= Errors
.Table
(T
).Sptr
then
499 if (Flag_Num
= 1 and then not Mult_Flags
)
505 (Character'Val (Character'Pos ('0') + Flag_Num
));
508 -- Skip past the corresponding source text character
510 -- Horizontal tab case, we output a flag at the tab position
511 -- so now we output a tab to match up with the text.
513 if Src
(P
) = ASCII
.HT
then
514 Write_Char
(ASCII
.HT
);
517 -- Skip wide character other than left bracket
520 and then Is_Start_Of_Wide_Char
(Src
, P
)
524 -- Skip normal non-wide character case (or bracket)
532 Set_Next_Non_Deleted_Msg
(T
);
533 Flag_Num
:= Flag_Num
+ 1;
539 -- Now output the error messages
542 while T
/= No_Error_Msg
543 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
544 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
550 while Column
< 74 loop
558 Set_Next_Non_Deleted_Msg
(T
);
562 end Output_Error_Msgs
;
564 ------------------------
565 -- Output_Line_Number --
566 ------------------------
568 procedure Output_Line_Number
(L
: Logical_Line_Number
) is
569 D
: Int
; -- next digit
570 C
: Character; -- next character
571 Z
: Boolean; -- flag for zero suppress
572 N
, M
: Int
; -- temporaries
575 if L
= No_Line_Number
then
596 C
:= Character'Val (D
+ 48);
604 end Output_Line_Number
;
606 ---------------------
607 -- Output_Msg_Text --
608 ---------------------
610 procedure Output_Msg_Text
(E
: Error_Msg_Id
) is
611 Offs
: constant Nat
:= Column
- 1;
612 -- Offset to start of message, used for continuations
615 -- Maximum characters to output on next line
618 -- Maximum total length of lines
620 Text
: constant String_Ptr
:= Errors
.Table
(E
).Text
;
627 Tag
: constant String := Get_Warning_Tag
(E
);
632 -- Postfix warning tag to message if needed
634 if Tag
/= "" and then Warning_Doc_Switch
then
635 Txt
:= new String'(Text.all & ' ' & Tag);
640 -- Deal with warning case
642 if Errors.Table (E).Warn or else Errors.Table (E).Info then
644 -- For info messages, prefix message with "info: "
646 if Errors.Table (E).Info then
647 Txt := new String'("info: " & Txt
.all);
649 -- Warning treated as error
651 elsif Errors
.Table
(E
).Warn_Err
then
653 -- We prefix with "error:" rather than warning: and postfix
654 -- [warning-as-error] at the end.
656 Warnings_Treated_As_Errors
:= Warnings_Treated_As_Errors
+ 1;
657 Txt
:= new String'("error: " & Txt.all & " [warning-as-error]");
659 -- Normal case, prefix with "warning: "
662 Txt := new String'("warning: " & Txt
.all);
665 -- No prefix needed for style message, "(style)" is there already
667 elsif Errors
.Table
(E
).Style
then
670 -- No prefix needed for check message, severity is there already
672 elsif Errors
.Table
(E
).Check
then
675 -- All other cases, add "error: " if unique error tag set
677 elsif Opt
.Unique_Error_Tag
then
678 Txt
:= new String'("error: " & Txt.all);
681 -- Set error message line length and length of message
683 if Error_Msg_Line_Length = 0 then
686 Length := Error_Msg_Line_Length;
689 Max := Integer (Length - Column + 1);
692 -- Here we have to split the message up into multiple lines
696 -- Make sure we do not have ludicrously small line
698 Max := Integer'Max (Max, 20);
700 -- If remaining text fits, output it respecting LF and we are done
702 if Len - Ptr < Max then
703 for J in Ptr .. Len loop
704 if Txt (J) = ASCII.LF then
708 Write_Char (Txt (J));
719 -- First scan forward looking for a hard end of line
721 for Scan in Ptr .. Ptr + Max - 1 loop
722 if Txt (Scan) = ASCII.LF then
729 -- Otherwise scan backwards looking for a space
731 for Scan in reverse Ptr .. Ptr + Max - 1 loop
732 if Txt (Scan) = ' ' then
739 -- If we fall through, no space, so split line arbitrarily
741 Split := Ptr + Max - 1;
746 if Start <= Split then
747 Write_Line (Txt (Start .. Split));
751 Max := Integer (Length - Column + 1);
756 ---------------------
757 -- Prescan_Message --
758 ---------------------
760 procedure Prescan_Message (Msg : String) is
764 -- Nothing to do for continuation line
766 if Msg (Msg'First) = '\
' then
770 -- Set initial values of globals (may be changed during scan)
772 Is_Serious_Error := True;
773 Is_Unconditional_Msg := False;
774 Is_Warning_Msg := False;
775 Has_Double_Exclam := False;
777 -- Check style message
780 Msg'Length > 7 and then Msg (Msg'First .. Msg'First + 6) = "(style)";
782 -- Check info message
785 Msg'Length > 6 and then Msg (Msg'First .. Msg'First + 5) = "info: ";
787 -- Check check message
790 (Msg'Length > 8 and then Msg (Msg'First .. Msg'First + 7) = "medium: ")
792 (Msg'Length > 6 and then Msg (Msg'First .. Msg'First + 5) = "high: ")
794 (Msg'Length > 5 and then Msg (Msg'First .. Msg'First + 4) = "low: ");
796 -- Loop through message looking for relevant insertion sequences
799 while J <= Msg'Last loop
801 -- If we have a quote, don't look at following character
803 if Msg (J) = ''' then
806 -- Warning message (? or < insertion sequence)
808 elsif Msg (J) = '?
' or else Msg (J) = '<' then
809 Is_Warning_Msg := Msg (J) = '?
' or else Error_Msg_Warn;
810 Warning_Msg_Char := ' ';
813 if Is_Warning_Msg then
815 C : constant Character := Msg (J - 1);
817 if J <= Msg'Last then
819 Warning_Msg_Char := '?
';
822 elsif J < Msg'Last and then Msg (J + 1) = C
823 and then (Msg (J) in 'a
' .. 'z
' or else
824 Msg (J) in 'A
' .. 'Z
' or else
825 Msg (J) = '*' or else
828 Warning_Msg_Char := Msg (J);
835 -- Bomb if untagged warning message. This code can be uncommented
836 -- for debugging when looking for untagged warning messages.
838 -- if Is_Warning_Msg and then Warning_Msg_Char = ' ' then
839 -- raise Program_Error;
842 -- Unconditional message (! insertion)
844 elsif Msg (J) = '!' then
845 Is_Unconditional_Msg := True;
848 if J <= Msg'Last and then Msg (J) = '!' then
849 Has_Double_Exclam := True;
853 -- Non-serious error (| insertion)
855 elsif Msg (J) = '|
' then
856 Is_Serious_Error := False;
864 if Is_Info_Msg or Is_Warning_Msg or Is_Style_Msg or Is_Check_Msg then
865 Is_Serious_Error := False;
873 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) is
876 function To_Be_Purged (E : Error_Msg_Id) return Boolean;
877 -- Returns True for a message that is to be purged. Also adjusts
878 -- error counts appropriately.
884 function To_Be_Purged (E : Error_Msg_Id) return Boolean is
887 and then Errors.Table (E).Sptr > From
888 and then Errors.Table (E).Sptr < To
890 if Errors.Table (E).Warn or else Errors.Table (E).Style then
891 Warnings_Detected := Warnings_Detected - 1;
894 Total_Errors_Detected := Total_Errors_Detected - 1;
896 if Errors.Table (E).Serious then
897 Serious_Errors_Detected := Serious_Errors_Detected - 1;
908 -- Start of processing for Purge_Messages
911 while To_Be_Purged (First_Error_Msg) loop
912 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
915 E := First_Error_Msg;
916 while E /= No_Error_Msg loop
917 while To_Be_Purged (Errors.Table (E).Next) loop
918 Errors.Table (E).Next :=
919 Errors.Table (Errors.Table (E).Next).Next;
922 E := Errors.Table (E).Next;
930 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean is
931 Msg1 : constant String_Ptr := Errors.Table (M1).Text;
932 Msg2 : constant String_Ptr := Errors.Table (M2).Text;
934 Msg2_Len : constant Integer := Msg2'Length;
935 Msg1_Len : constant Integer := Msg1'Length;
941 (Msg1_Len - 10 > Msg2_Len
943 Msg2.all = Msg1.all (1 .. Msg2_Len)
945 Msg1 (Msg2_Len + 1 .. Msg2_Len + 10) = ", instance")
947 (Msg2_Len - 10 > Msg1_Len
949 Msg1.all = Msg2.all (1 .. Msg1_Len)
951 Msg2 (Msg1_Len + 1 .. Msg1_Len + 10) = ", instance");
958 procedure Set_Msg_Blank is
961 and then Msg_Buffer (Msglen) /= ' '
962 and then Msg_Buffer (Msglen) /= '('
963 and then Msg_Buffer (Msglen) /= '-'
964 and then not Manual_Quote_Mode
970 -------------------------------
971 -- Set_Msg_Blank_Conditional --
972 -------------------------------
974 procedure Set_Msg_Blank_Conditional 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
984 end Set_Msg_Blank_Conditional;
990 procedure Set_Msg_Char (C : Character) is
993 -- The check for message buffer overflow is needed to deal with cases
994 -- where insertions get too long (in particular a child unit name can
997 if Msglen < Max_Msg_Length then
998 Msglen := Msglen + 1;
999 Msg_Buffer (Msglen) := C;
1003 ---------------------------------
1004 -- Set_Msg_Insertion_File_Name --
1005 ---------------------------------
1007 procedure Set_Msg_Insertion_File_Name is
1009 if Error_Msg_File_1 = No_File then
1012 elsif Error_Msg_File_1 = Error_File_Name then
1014 Set_Msg_Str ("<error
>");
1018 Get_Name_String (Error_Msg_File_1);
1020 Set_Msg_Name_Buffer;
1024 -- The following assignments ensure that the second and third {
1025 -- insertion characters will correspond to the Error_Msg_File_2 and
1026 -- Error_Msg_File_3 values and We suppress possible validity checks in
1027 -- case operating in -gnatVa mode, and Error_Msg_File_2 or
1028 -- Error_Msg_File_3 is not needed and has not been set.
1031 pragma Suppress (Range_Check);
1033 Error_Msg_File_1 := Error_Msg_File_2;
1034 Error_Msg_File_2 := Error_Msg_File_3;
1036 end Set_Msg_Insertion_File_Name;
1038 -----------------------------------
1039 -- Set_Msg_Insertion_Line_Number --
1040 -----------------------------------
1042 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
1043 Sindex_Loc : Source_File_Index;
1044 Sindex_Flag : Source_File_Index;
1045 Fname : File_Name_Type;
1049 -- Outputs "at " unless last characters in buffer are " from
". Certain
1050 -- messages read better with from than at.
1059 or else Msg_Buffer (Msglen - 5 .. Msglen) /= " from
"
1061 Set_Msg_Str ("at ");
1065 -- Start of processing for Set_Msg_Insertion_Line_Number
1070 if Loc = No_Location then
1072 Set_Msg_Str ("unknown location
");
1074 elsif Loc = System_Location then
1075 Set_Msg_Str ("in package System
");
1076 Set_Msg_Insertion_Run_Time_Name;
1078 elsif Loc = Standard_Location then
1079 Set_Msg_Str ("in package Standard
");
1081 elsif Loc = Standard_ASCII_Location then
1082 Set_Msg_Str ("in package Standard
.ASCII
");
1085 -- Add "at file
-name
:" if reference is to other than the source
1086 -- file in which the error message is placed. Note that we check
1087 -- full file names, rather than just the source indexes, to
1088 -- deal with generic instantiations from the current file.
1090 Sindex_Loc := Get_Source_File_Index (Loc);
1091 Sindex_Flag := Get_Source_File_Index (Flag);
1093 if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
1095 Fname := Reference_Name (Get_Source_File_Index (Loc));
1096 Int_File := Is_Internal_File_Name (Fname);
1097 Get_Name_String (Fname);
1098 Set_Msg_Name_Buffer;
1100 if not (Int_File and Debug_Flag_Dot_K) then
1102 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1105 -- If in current file, add text "at line
"
1109 Set_Msg_Str ("line
");
1111 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1114 -- Deal with the instantiation case. We may have a reference to,
1115 -- e.g. a type, that is declared within a generic template, and
1116 -- what we are really referring to is the occurrence in an instance.
1117 -- In this case, the line number of the instantiation is also of
1118 -- interest, and we add a notation:
1120 -- , instance at xxx
1122 -- where xxx is a line number output using this same routine (and
1123 -- the recursion can go further if the instantiation is itself in
1124 -- a generic template).
1126 -- The flag location passed to us in this situation is indeed the
1127 -- line number within the template, but as described in Sinput.L
1128 -- (file sinput-l.ads, section "Handling
Generic Instantiations
")
1129 -- we can retrieve the location of the instantiation itself from
1130 -- this flag location value.
1132 -- Note: this processing is suppressed if Suppress_Instance_Location
1133 -- is set True. This is used to prevent redundant annotations of the
1134 -- location of the instantiation in the case where we are placing
1135 -- the messages on the instantiation in any case.
1137 if Instantiation (Sindex_Loc) /= No_Location
1138 and then not Suppress_Instance_Location
1140 Set_Msg_Str (", instance
");
1141 Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
1144 end Set_Msg_Insertion_Line_Number;
1146 ----------------------------
1147 -- Set_Msg_Insertion_Name --
1148 ----------------------------
1150 procedure Set_Msg_Insertion_Name is
1152 if Error_Msg_Name_1 = No_Name then
1155 elsif Error_Msg_Name_1 = Error_Name then
1157 Set_Msg_Str ("<error
>");
1160 Set_Msg_Blank_Conditional;
1161 Get_Unqualified_Decoded_Name_String (Error_Msg_Name_1);
1163 -- Remove %s or %b at end. These come from unit names. If the
1164 -- caller wanted the (unit) or (body), then they would have used
1165 -- the $ insertion character. Certainly no error message should
1166 -- ever have %b or %s explicitly occurring.
1169 and then Name_Buffer (Name_Len - 1) = '%'
1170 and then (Name_Buffer (Name_Len) = 'b'
1172 Name_Buffer (Name_Len) = 's')
1174 Name_Len := Name_Len - 2;
1177 -- Remove upper case letter at end, again, we should not be getting
1178 -- such names, and what we hope is that the remainder makes sense.
1180 if Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' then
1181 Name_Len := Name_Len - 1;
1184 -- If operator name or character literal name, just print it as is
1185 -- Also print as is if it ends in a right paren (case of x'val(nnn))
1187 if Name_Buffer (1) = '"'
1188 or else Name_Buffer (1) = '''
1189 or else Name_Buffer (Name_Len) = ')'
1191 Set_Msg_Name_Buffer;
1193 -- Else output with surrounding quotes in proper casing mode
1196 Set_Casing (Identifier_Casing (Flag_Source));
1198 Set_Msg_Name_Buffer;
1203 -- The following assignments ensure that the second and third percent
1204 -- insertion characters will correspond to the Error_Msg_Name_2 and
1205 -- Error_Msg_Name_3 as required. We suppress possible validity checks in
1206 -- case operating in -gnatVa mode, and Error_Msg_Name_1/2 is not needed
1207 -- and has not been set.
1210 pragma Suppress (Range_Check);
1212 Error_Msg_Name_1 := Error_Msg_Name_2;
1213 Error_Msg_Name_2 := Error_Msg_Name_3;
1215 end Set_Msg_Insertion_Name;
1217 ------------------------------------
1218 -- Set_Msg_Insertion_Name_Literal --
1219 ------------------------------------
1221 procedure Set_Msg_Insertion_Name_Literal is
1223 if Error_Msg_Name_1 = No_Name then
1226 elsif Error_Msg_Name_1 = Error_Name then
1228 Set_Msg_Str ("<error>");
1232 Get_Name_String (Error_Msg_Name_1);
1234 Set_Msg_Name_Buffer;
1238 -- The following assignments ensure that the second and third % or %%
1239 -- insertion characters will correspond to the Error_Msg_Name_2 and
1240 -- Error_Msg_Name_3 values and We suppress possible validity checks in
1241 -- case operating in -gnatVa mode, and Error_Msg_Name_2 or
1242 -- Error_Msg_Name_3 is not needed and has not been set.
1245 pragma Suppress (Range_Check);
1247 Error_Msg_Name_1 := Error_Msg_Name_2;
1248 Error_Msg_Name_2 := Error_Msg_Name_3;
1250 end Set_Msg_Insertion_Name_Literal;
1252 -------------------------------------
1253 -- Set_Msg_Insertion_Reserved_Name --
1254 -------------------------------------
1256 procedure Set_Msg_Insertion_Reserved_Name is
1258 Set_Msg_Blank_Conditional;
1259 Get_Name_String (Error_Msg_Name_1);
1261 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1262 Set_Msg_Name_Buffer;
1264 end Set_Msg_Insertion_Reserved_Name;
1266 -------------------------------------
1267 -- Set_Msg_Insertion_Reserved_Word --
1268 -------------------------------------
1270 procedure Set_Msg_Insertion_Reserved_Word
1275 Set_Msg_Blank_Conditional;
1278 while J <= Text'Last and then Text (J) in 'A
' .. 'Z
' loop
1279 Add_Char_To_Name_Buffer (Text (J));
1283 -- Here is where we make the special exception for RM
1285 if Name_Len = 2 and then Name_Buffer (1 .. 2) = "RM" then
1286 Set_Msg_Name_Buffer;
1288 -- We make a similar exception for SPARK
1290 elsif Name_Len = 5 and then Name_Buffer (1 .. 5) = "SPARK" then
1291 Set_Msg_Name_Buffer;
1293 -- Neither RM nor SPARK: case appropriately and add surrounding quotes
1296 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1298 Set_Msg_Name_Buffer;
1301 end Set_Msg_Insertion_Reserved_Word;
1303 -------------------------------------
1304 -- Set_Msg_Insertion_Run_Time_Name --
1305 -------------------------------------
1307 procedure Set_Msg_Insertion_Run_Time_Name is
1309 if Targparm.Run_Time_Name_On_Target /= No_Name then
1310 Set_Msg_Blank_Conditional;
1312 Get_Name_String (Targparm.Run_Time_Name_On_Target);
1313 Set_Casing (Mixed_Case);
1314 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1317 end Set_Msg_Insertion_Run_Time_Name;
1319 ----------------------------
1320 -- Set_Msg_Insertion_Uint --
1321 ----------------------------
1323 procedure Set_Msg_Insertion_Uint is
1326 UI_Image (Error_Msg_Uint_1);
1328 for J in 1 .. UI_Image_Length loop
1329 Set_Msg_Char (UI_Image_Buffer (J));
1332 -- The following assignment ensures that a second caret insertion
1333 -- character will correspond to the Error_Msg_Uint_2 parameter. We
1334 -- suppress possible validity checks in case operating in -gnatVa mode,
1335 -- and Error_Msg_Uint_2 is not needed and has not been set.
1338 pragma Suppress (Range_Check);
1340 Error_Msg_Uint_1 := Error_Msg_Uint_2;
1342 end Set_Msg_Insertion_Uint;
1348 procedure Set_Msg_Int (Line : Int) is
1351 Set_Msg_Int (Line / 10);
1354 Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
1357 -------------------------
1358 -- Set_Msg_Name_Buffer --
1359 -------------------------
1361 procedure Set_Msg_Name_Buffer is
1363 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1364 end Set_Msg_Name_Buffer;
1370 procedure Set_Msg_Quote is
1372 if not Manual_Quote_Mode then
1381 procedure Set_Msg_Str (Text : String) is
1383 -- Do replacement for special x'Class aspect names
1385 if Text = "_Pre
" then
1386 Set_Msg_Str ("Pre
'Class");
1388 elsif Text = "_Post
" then
1389 Set_Msg_Str ("Post
'Class");
1391 elsif Text = "_Type_Invariant
" then
1392 Set_Msg_Str ("Type_Invariant
'Class");
1394 elsif Text = "_pre
" then
1395 Set_Msg_Str ("pre
'class");
1397 elsif Text = "_post
" then
1398 Set_Msg_Str ("post
'class");
1400 elsif Text = "_type_invariant
" then
1401 Set_Msg_Str ("type_invariant
'class");
1403 elsif Text = "_PRE
" then
1404 Set_Msg_Str ("PRE
'CLASS");
1406 elsif Text = "_POST
" then
1407 Set_Msg_Str ("POST
'CLASS");
1409 elsif Text = "_TYPE_INVARIANT
" then
1410 Set_Msg_Str ("TYPE_INVARIANT
'CLASS");
1412 -- Normal case with no replacement
1415 for J in Text'Range loop
1416 Set_Msg_Char (Text (J));
1421 ------------------------------
1422 -- Set_Next_Non_Deleted_Msg --
1423 ------------------------------
1425 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id) is
1427 if E = No_Error_Msg then
1432 E := Errors.Table (E).Next;
1433 exit when E = No_Error_Msg or else not Errors.Table (E).Deleted;
1436 end Set_Next_Non_Deleted_Msg;
1438 ------------------------------
1439 -- Set_Specific_Warning_Off --
1440 ------------------------------
1442 procedure Set_Specific_Warning_Off
1447 Used : Boolean := False)
1450 Specific_Warnings.Append
1452 Msg => new String'(Msg),
1453 Stop => Source_Last (Get_Source_File_Index (Loc)),
1458 end Set_Specific_Warning_Off;
1460 -----------------------------
1461 -- Set_Specific_Warning_On --
1462 -----------------------------
1464 procedure Set_Specific_Warning_On
1470 for J in 1 .. Specific_Warnings.Last loop
1472 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1475 if Msg = SWE.Msg.all
1476 and then Loc > SWE.Start
1478 and then Get_Source_File_Index (SWE.Start) =
1479 Get_Source_File_Index (Loc)
1485 -- If a config pragma is specifically cancelled, consider
1486 -- that it is no longer active as a configuration pragma.
1488 SWE.Config := False;
1495 end Set_Specific_Warning_On;
1497 ---------------------------
1498 -- Set_Warnings_Mode_Off --
1499 ---------------------------
1501 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id) is
1503 -- Don't bother with entries from instantiation copies, since we will
1504 -- already have a copy in the template, which is what matters.
1506 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1510 -- If all warnings are suppressed by command line switch, this can
1511 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1512 -- Warnings to be stored for the formal verification backend.
1514 if Warning_Mode = Suppress
1515 and then not GNATprove_Mode
1520 -- If last entry in table already covers us, this is a redundant pragma
1521 -- Warnings (Off) and can be ignored.
1523 if Warnings.Last >= Warnings.First
1524 and then Warnings.Table (Warnings.Last).Start <= Loc
1525 and then Loc <= Warnings.Table (Warnings.Last).Stop
1530 -- If none of those special conditions holds, establish a new entry,
1531 -- extending from the location of the pragma to the end of the current
1532 -- source file. This ending point will be adjusted by a subsequent
1533 -- corresponding pragma Warnings (On).
1537 Stop => Source_Last (Get_Source_File_Index (Loc)),
1539 end Set_Warnings_Mode_Off;
1541 --------------------------
1542 -- Set_Warnings_Mode_On --
1543 --------------------------
1545 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
1547 -- Don't bother with entries from instantiation copies, since we will
1548 -- already have a copy in the template, which is what matters.
1550 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1554 -- If all warnings are suppressed by command line switch, this can
1555 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1556 -- Warnings to be stored for the formal verification backend.
1558 if Warning_Mode = Suppress
1559 and then not GNATprove_Mode
1564 -- If the last entry in the warnings table covers this pragma, then
1565 -- we adjust the end point appropriately.
1567 if Warnings.Last >= Warnings.First
1568 and then Warnings.Table (Warnings.Last).Start <= Loc
1569 and then Loc <= Warnings.Table (Warnings.Last).Stop
1571 Warnings.Table (Warnings.Last).Stop := Loc;
1573 end Set_Warnings_Mode_On;
1575 --------------------------------
1576 -- Validate_Specific_Warnings --
1577 --------------------------------
1579 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc) is
1581 if not Warn_On_Warnings_Off then
1585 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1587 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1590 if not SWE.Config then
1592 -- Warn for unmatched Warnings (Off, ...)
1596 ("?W?
pragma Warnings Off
with no matching Warnings On
",
1599 -- Warn for ineffective Warnings (Off, ..)
1603 -- Do not issue this warning for -Wxxx messages since the
1604 -- back-end doesn't report the information. Note that there
1605 -- is always an asterisk at the start of every message.
1608 (SWE.Msg'Length > 3 and then SWE.Msg (2 .. 3) = "-W
")
1611 ("?W?no warning suppressed by this
pragma", SWE.Start);
1616 end Validate_Specific_Warnings;
1618 -------------------------------------
1619 -- Warning_Specifically_Suppressed --
1620 -------------------------------------
1622 function Warning_Specifically_Suppressed
1625 Tag : String := "") return String_Id
1628 -- Loop through specific warning suppression entries
1630 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1632 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1635 -- Pragma applies if it is a configuration pragma, or if the
1636 -- location is in range of a specific non-configuration pragma.
1639 or else (SWE.Start <= Loc and then Loc <= SWE.Stop)
1641 if Matches (Msg.all, SWE.Msg.all)
1642 or else Matches (Tag, SWE.Msg.all)
1652 end Warning_Specifically_Suppressed;
1654 ------------------------------
1655 -- Warning_Treated_As_Error --
1656 ------------------------------
1658 function Warning_Treated_As_Error (Msg : String) return Boolean is
1660 for J in 1 .. Warnings_As_Errors_Count loop
1661 if Matches (Msg, Warnings_As_Errors (J).all) then
1667 end Warning_Treated_As_Error;
1669 -------------------------
1670 -- Warnings_Suppressed --
1671 -------------------------
1673 function Warnings_Suppressed (Loc : Source_Ptr) return String_Id is
1675 -- Loop through table of ON/OFF warnings
1677 for J in Warnings.First .. Warnings.Last loop
1678 if Warnings.Table (J).Start <= Loc
1679 and then Loc <= Warnings.Table (J).Stop
1681 return Warnings.Table (J).Reason;
1685 if Warning_Mode = Suppress then
1686 return Null_String_Id;
1690 end Warnings_Suppressed;