1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Namet
; use Namet
;
39 with Output
; use Output
;
40 with Sinput
; use Sinput
;
41 with Snames
; use Snames
;
42 with Stringt
; use Stringt
;
43 with Targparm
; use Targparm
;
44 with Uintp
; use Uintp
;
45 with Widechar
; use Widechar
;
47 package body Erroutc
is
49 -----------------------
50 -- Local Subprograms --
51 -----------------------
53 function Matches
(S
: String; P
: String) return Boolean;
54 -- Returns true if the String S patches the pattern P, which can contain
55 -- wild card chars (*). The entire pattern must match the entire string.
56 -- Case is ignored in the comparison (so X matches x).
62 procedure Add_Class
is
67 Get_Name_String
(Name_Class
);
68 Set_Casing
(Identifier_Casing
(Flag_Source
), Mixed_Case
);
73 ----------------------
74 -- Buffer_Ends_With --
75 ----------------------
77 function Buffer_Ends_With
(C
: Character) return Boolean is
79 return Msglen
> 0 and then Msg_Buffer
(Msglen
) = C
;
82 function Buffer_Ends_With
(S
: String) return Boolean is
83 Len
: constant Natural := S
'Length;
86 and then Msg_Buffer
(Msglen
- Len
) = ' '
87 and then Msg_Buffer
(Msglen
- Len
+ 1 .. Msglen
) = S
;
94 procedure Buffer_Remove
(C
: Character) is
96 if Buffer_Ends_With
(C
) then
101 procedure Buffer_Remove
(S
: String) is
103 if Buffer_Ends_With
(S
) then
104 Msglen
:= Msglen
- S
'Length;
108 -----------------------------
109 -- Check_Duplicate_Message --
110 -----------------------------
112 procedure Check_Duplicate_Message
(M1
, M2
: Error_Msg_Id
) is
113 L1
, L2
: Error_Msg_Id
;
114 N1
, N2
: Error_Msg_Id
;
116 procedure Delete_Msg
(Delete
, Keep
: Error_Msg_Id
);
117 -- Called to delete message Delete, keeping message Keep. Marks msg
118 -- Delete and all its continuations with deleted flag set to True.
119 -- Also makes sure that for the error messages that are retained the
120 -- preferred message is the one retained (we prefer the shorter one in
121 -- the case where one has an Instance tag). Note that we always know
122 -- that Keep has at least as many continuations as Delete (since we
123 -- always delete the shorter sequence).
129 procedure Delete_Msg
(Delete
, Keep
: Error_Msg_Id
) is
137 Errors
.Table
(D
).Deleted
:= True;
139 -- Adjust error message count
141 if Errors
.Table
(D
).Warn
or else Errors
.Table
(D
).Style
then
142 Warnings_Detected
:= Warnings_Detected
- 1;
144 if Errors
.Table
(D
).Info
then
145 Info_Messages
:= Info_Messages
- 1;
148 -- Note: we do not need to decrement Warnings_Treated_As_Errors
149 -- because this only gets incremented if we actually output the
150 -- message, which we won't do if we are deleting it here!
152 elsif Errors
.Table
(D
).Check
then
153 Check_Messages
:= Check_Messages
- 1;
156 Total_Errors_Detected
:= Total_Errors_Detected
- 1;
158 if Errors
.Table
(D
).Serious
then
159 Serious_Errors_Detected
:= Serious_Errors_Detected
- 1;
163 -- Substitute shorter of the two error messages
165 if Errors
.Table
(K
).Text
'Length > Errors
.Table
(D
).Text
'Length then
166 Errors
.Table
(K
).Text
:= Errors
.Table
(D
).Text
;
169 D
:= Errors
.Table
(D
).Next
;
170 K
:= Errors
.Table
(K
).Next
;
172 if D
= No_Error_Msg
or else not Errors
.Table
(D
).Msg_Cont
then
178 -- Start of processing for Check_Duplicate_Message
181 -- Both messages must be non-continuation messages and not deleted
183 if Errors
.Table
(M1
).Msg_Cont
184 or else Errors
.Table
(M2
).Msg_Cont
185 or else Errors
.Table
(M1
).Deleted
186 or else Errors
.Table
(M2
).Deleted
191 -- Definitely not equal if message text does not match
193 if not Same_Error
(M1
, M2
) then
197 -- Same text. See if all continuations are also identical
203 N1
:= Errors
.Table
(L1
).Next
;
204 N2
:= Errors
.Table
(L2
).Next
;
206 -- If M1 continuations have run out, we delete M1, either the
207 -- messages have the same number of continuations, or M2 has
208 -- more and we prefer the one with more anyway.
210 if N1
= No_Error_Msg
or else not Errors
.Table
(N1
).Msg_Cont
then
214 -- If M2 continuations have run out, we delete M2
216 elsif N2
= No_Error_Msg
or else not Errors
.Table
(N2
).Msg_Cont
then
220 -- Otherwise see if continuations are the same, if not, keep both
221 -- sequences, a curious case, but better to keep everything.
223 elsif not Same_Error
(N1
, N2
) then
226 -- If continuations are the same, continue scan
233 end Check_Duplicate_Message
;
235 ------------------------
236 -- Compilation_Errors --
237 ------------------------
239 function Compilation_Errors
return Boolean is
241 return Total_Errors_Detected
/= 0
242 or else (Warnings_Detected
- Info_Messages
/= 0
243 and then Warning_Mode
= Treat_As_Error
)
244 or else Warnings_Treated_As_Errors
/= 0;
245 end Compilation_Errors
;
251 procedure Debug_Output
(N
: Node_Id
) is
254 Write_Str
("*** following error message posted on node id = #");
265 procedure dmsg
(Id
: Error_Msg_Id
) is
266 E
: Error_Msg_Object
renames Errors
.Table
(Id
);
269 w
("Dumping error message, Id = ", Int
(Id
));
270 w
(" Text = ", E
.Text
.all);
271 w
(" Next = ", Int
(E
.Next
));
272 w
(" Prev = ", Int
(E
.Prev
));
273 w
(" Sfile = ", Int
(E
.Sfile
));
277 Write_Location
(E
.Sptr
);
282 Write_Location
(E
.Optr
);
285 w
(" Line = ", Int
(E
.Line
));
286 w
(" Col = ", Int
(E
.Col
));
287 w
(" Warn = ", E
.Warn
);
288 w
(" Warn_Err = ", E
.Warn_Err
);
289 w
(" Warn_Chr = '" & E
.Warn_Chr
& ''');
290 w
(" Style = ", E
.Style
);
291 w
(" Serious = ", E
.Serious
);
292 w
(" Uncond = ", E
.Uncond
);
293 w
(" Msg_Cont = ", E
.Msg_Cont
);
294 w
(" Deleted = ", E
.Deleted
);
303 function Get_Location
(E
: Error_Msg_Id
) return Source_Ptr
is
305 return Errors
.Table
(E
).Sptr
;
312 function Get_Msg_Id
return Error_Msg_Id
is
317 ---------------------
318 -- Get_Warning_Tag --
319 ---------------------
321 function Get_Warning_Tag
(Id
: Error_Msg_Id
) return String is
322 Warn
: constant Boolean := Errors
.Table
(Id
).Warn
;
323 Warn_Chr
: constant Character := Errors
.Table
(Id
).Warn_Chr
;
325 if Warn
and then Warn_Chr
/= ' ' then
326 if Warn_Chr
= '?' then
327 return "[enabled by default]";
328 elsif Warn_Chr
= '*' then
329 return "[restriction warning]";
330 elsif Warn_Chr
= '$' then
332 elsif Warn_Chr
in 'a' .. 'z' then
333 return "[-gnatw" & Warn_Chr
& ']';
334 else pragma Assert
(Warn_Chr
in 'A' .. 'Z');
335 return "[-gnatw." & Fold_Lower
(Warn_Chr
) & ']';
346 function Matches
(S
: String; P
: String) return Boolean is
347 Slast
: constant Natural := S
'Last;
348 PLast
: constant Natural := P
'Last;
350 SPtr
: Natural := S
'First;
351 PPtr
: Natural := P
'First;
354 -- Loop advancing through characters of string and pattern
359 -- Return True if pattern is a single asterisk
361 if PPtr
= PLast
and then P
(PPtr
) = '*' then
364 -- Return True if both pattern and string exhausted
366 elsif PPtr
> PLast
and then SPtr
> Slast
then
369 -- Return False, if one exhausted and not the other
371 elsif PPtr
> PLast
or else SPtr
> Slast
then
374 -- Case where pattern starts with asterisk
376 elsif P
(PPtr
) = '*' then
378 -- Try all possible starting positions in S for match with the
379 -- remaining characters of the pattern. This is the recursive
380 -- call that implements the scanner backup.
382 for J
in SPtr
.. Slast
loop
383 if Matches
(S
(J
.. Slast
), P
(PPtr
+ 1 .. PLast
)) then
390 -- Dealt with end of string and *, advance if we have a match
392 elsif Fold_Lower
(S
(SPtr
)) = Fold_Lower
(P
(PPtr
)) then
396 -- If first characters do not match, that's decisive
404 -----------------------
405 -- Output_Error_Msgs --
406 -----------------------
408 procedure Output_Error_Msgs
(E
: in out Error_Msg_Id
) is
414 Mult_Flags
: Boolean := False;
419 -- Skip deleted messages at start
421 if Errors
.Table
(S
).Deleted
then
422 Set_Next_Non_Deleted_Msg
(S
);
425 -- Figure out if we will place more than one error flag on this line
428 while T
/= No_Error_Msg
429 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
430 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
432 if Errors
.Table
(T
).Sptr
> Errors
.Table
(E
).Sptr
then
436 Set_Next_Non_Deleted_Msg
(T
);
439 -- Output the error flags. The circuit here makes sure that the tab
440 -- characters in the original line are properly accounted for. The
441 -- eight blanks at the start are to match the line number.
443 if not Debug_Flag_2
then
445 P
:= Line_Start
(Errors
.Table
(E
).Sptr
);
448 -- Loop through error messages for this line to place flags
451 while T
/= No_Error_Msg
452 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
453 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
456 Src
: Source_Buffer_Ptr
457 renames Source_Text
(Errors
.Table
(T
).Sfile
);
460 -- Loop to output blanks till current flag position
462 while P
< Errors
.Table
(T
).Sptr
loop
464 -- Horizontal tab case, just echo the tab
466 if Src
(P
) = ASCII
.HT
then
467 Write_Char
(ASCII
.HT
);
470 -- Deal with wide character case, but don't include brackets
471 -- notation in this circuit, since we know that this will
472 -- display unencoded (no one encodes brackets notation).
475 and then Is_Start_Of_Wide_Char
(Src
, P
)
480 -- Normal non-wide character case (or bracket)
488 -- Output flag (unless already output, this happens if more
489 -- than one error message occurs at the same flag position).
491 if P
= Errors
.Table
(T
).Sptr
then
492 if (Flag_Num
= 1 and then not Mult_Flags
)
498 (Character'Val (Character'Pos ('0') + Flag_Num
));
501 -- Skip past the corresponding source text character
503 -- Horizontal tab case, we output a flag at the tab position
504 -- so now we output a tab to match up with the text.
506 if Src
(P
) = ASCII
.HT
then
507 Write_Char
(ASCII
.HT
);
510 -- Skip wide character other than left bracket
513 and then Is_Start_Of_Wide_Char
(Src
, P
)
517 -- Skip normal non-wide character case (or bracket)
525 Set_Next_Non_Deleted_Msg
(T
);
526 Flag_Num
:= Flag_Num
+ 1;
532 -- Now output the error messages
535 while T
/= No_Error_Msg
536 and then Errors
.Table
(T
).Line
= Errors
.Table
(E
).Line
537 and then Errors
.Table
(T
).Sfile
= Errors
.Table
(E
).Sfile
543 while Column
< 74 loop
551 Set_Next_Non_Deleted_Msg
(T
);
555 end Output_Error_Msgs
;
557 ------------------------
558 -- Output_Line_Number --
559 ------------------------
561 procedure Output_Line_Number
(L
: Logical_Line_Number
) is
562 D
: Int
; -- next digit
563 C
: Character; -- next character
564 Z
: Boolean; -- flag for zero suppress
565 N
, M
: Int
; -- temporaries
568 if L
= No_Line_Number
then
589 C
:= Character'Val (D
+ 48);
597 end Output_Line_Number
;
599 ---------------------
600 -- Output_Msg_Text --
601 ---------------------
603 procedure Output_Msg_Text
(E
: Error_Msg_Id
) is
604 Offs
: constant Nat
:= Column
- 1;
605 -- Offset to start of message, used for continuations
608 -- Maximum characters to output on next line
611 -- Maximum total length of lines
613 Text
: constant String_Ptr
:= Errors
.Table
(E
).Text
;
620 Tag
: constant String := Get_Warning_Tag
(E
);
625 -- Postfix warning tag to message if needed
627 if Tag
/= "" and then Warning_Doc_Switch
then
628 Txt
:= new String'(Text.all & ' ' & Tag);
633 -- Deal with warning case
635 if Errors.Table (E).Warn then
637 -- For info messages, prefix message with "info: "
639 if Errors.Table (E).Info then
640 Txt := new String'("info: " & Txt
.all);
642 -- Warning treated as error
644 elsif Errors
.Table
(E
).Warn_Err
then
646 -- We prefix with "error:" rather than warning: and postfix
647 -- [warning-as-error] at the end.
649 Warnings_Treated_As_Errors
:= Warnings_Treated_As_Errors
+ 1;
650 Txt
:= new String'("error: " & Txt.all & " [warning-as-error]");
652 -- Normal case, prefix with "warning: "
655 Txt := new String'("warning: " & Txt
.all);
658 -- No prefix needed for style message, "(style)" is there already
660 elsif Errors
.Table
(E
).Style
then
663 -- No prefix needed for check message, severity is there already
665 elsif Errors
.Table
(E
).Check
then
668 -- All other cases, add "error: " if unique error tag set
670 elsif Opt
.Unique_Error_Tag
then
671 Txt
:= new String'("error: " & Txt.all);
674 -- Set error message line length and length of message
676 if Error_Msg_Line_Length = 0 then
679 Length := Error_Msg_Line_Length;
682 Max := Integer (Length - Column + 1);
685 -- Here we have to split the message up into multiple lines
689 -- Make sure we do not have ludicrously small line
691 Max := Integer'Max (Max, 20);
693 -- If remaining text fits, output it respecting LF and we are done
695 if Len - Ptr < Max then
696 for J in Ptr .. Len loop
697 if Txt (J) = ASCII.LF then
701 Write_Char (Txt (J));
712 -- First scan forward looking for a hard end of line
714 for Scan in Ptr .. Ptr + Max - 1 loop
715 if Txt (Scan) = ASCII.LF then
722 -- Otherwise scan backwards looking for a space
724 for Scan in reverse Ptr .. Ptr + Max - 1 loop
725 if Txt (Scan) = ' ' then
732 -- If we fall through, no space, so split line arbitrarily
734 Split := Ptr + Max - 1;
739 if Start <= Split then
740 Write_Line (Txt (Start .. Split));
744 Max := Integer (Length - Column + 1);
749 ---------------------
750 -- Prescan_Message --
751 ---------------------
753 procedure Prescan_Message (Msg : String) is
757 -- Nothing to do for continuation line
759 if Msg (Msg'First) = '\
' then
763 -- Set initial values of globals (may be changed during scan)
765 Is_Serious_Error := True;
766 Is_Unconditional_Msg := False;
767 Is_Warning_Msg := False;
768 Has_Double_Exclam := False;
770 -- Check style message
773 Msg'Length > 7 and then Msg (Msg'First .. Msg'First + 6) = "(style)";
775 -- Check info message
778 Msg'Length > 6 and then Msg (Msg'First .. Msg'First + 5) = "info: ";
780 -- Check check message
783 (Msg'Length > 8 and then Msg (Msg'First .. Msg'First + 7) = "medium: ")
785 (Msg'Length > 6 and then Msg (Msg'First .. Msg'First + 5) = "high: ")
787 (Msg'Length > 5 and then Msg (Msg'First .. Msg'First + 4) = "low: ");
789 -- Loop through message looking for relevant insertion sequences
792 while J <= Msg'Last loop
794 -- If we have a quote, don't look at following character
796 if Msg (J) = ''' then
799 -- Warning message (? or < insertion sequence)
801 elsif Msg (J) = '?
' or else Msg (J) = '<' then
802 Is_Warning_Msg := Msg (J) = '?
' or else Error_Msg_Warn;
803 Warning_Msg_Char := ' ';
806 if Is_Warning_Msg then
808 C : constant Character := Msg (J - 1);
810 if J <= Msg'Last then
812 Warning_Msg_Char := '?
';
815 elsif J < Msg'Last and then Msg (J + 1) = C
816 and then (Msg (J) in 'a
' .. 'z
' or else
817 Msg (J) in 'A
' .. 'Z
' or else
818 Msg (J) = '*' or else
821 Warning_Msg_Char := Msg (J);
828 -- Bomb if untagged warning message. This code can be uncommented
829 -- for debugging when looking for untagged warning messages.
831 -- if Is_Warning_Msg and then Warning_Msg_Char = ' ' then
832 -- raise Program_Error;
835 -- Unconditional message (! insertion)
837 elsif Msg (J) = '!' then
838 Is_Unconditional_Msg := True;
841 if J <= Msg'Last and then Msg (J) = '!' then
842 Has_Double_Exclam := True;
846 -- Non-serious error (| insertion)
848 elsif Msg (J) = '|
' then
849 Is_Serious_Error := False;
857 if Is_Warning_Msg or Is_Style_Msg or Is_Check_Msg then
858 Is_Serious_Error := False;
866 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) is
869 function To_Be_Purged (E : Error_Msg_Id) return Boolean;
870 -- Returns True for a message that is to be purged. Also adjusts
871 -- error counts appropriately.
877 function To_Be_Purged (E : Error_Msg_Id) return Boolean is
880 and then Errors.Table (E).Sptr > From
881 and then Errors.Table (E).Sptr < To
883 if Errors.Table (E).Warn or else Errors.Table (E).Style then
884 Warnings_Detected := Warnings_Detected - 1;
887 Total_Errors_Detected := Total_Errors_Detected - 1;
889 if Errors.Table (E).Serious then
890 Serious_Errors_Detected := Serious_Errors_Detected - 1;
901 -- Start of processing for Purge_Messages
904 while To_Be_Purged (First_Error_Msg) loop
905 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
908 E := First_Error_Msg;
909 while E /= No_Error_Msg loop
910 while To_Be_Purged (Errors.Table (E).Next) loop
911 Errors.Table (E).Next :=
912 Errors.Table (Errors.Table (E).Next).Next;
915 E := Errors.Table (E).Next;
923 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean is
924 Msg1 : constant String_Ptr := Errors.Table (M1).Text;
925 Msg2 : constant String_Ptr := Errors.Table (M2).Text;
927 Msg2_Len : constant Integer := Msg2'Length;
928 Msg1_Len : constant Integer := Msg1'Length;
934 (Msg1_Len - 10 > Msg2_Len
936 Msg2.all = Msg1.all (1 .. Msg2_Len)
938 Msg1 (Msg2_Len + 1 .. Msg2_Len + 10) = ", instance")
940 (Msg2_Len - 10 > Msg1_Len
942 Msg1.all = Msg2.all (1 .. Msg1_Len)
944 Msg2 (Msg1_Len + 1 .. Msg1_Len + 10) = ", instance");
951 procedure Set_Msg_Blank is
954 and then Msg_Buffer (Msglen) /= ' '
955 and then Msg_Buffer (Msglen) /= '('
956 and then Msg_Buffer (Msglen) /= '-'
957 and then not Manual_Quote_Mode
963 -------------------------------
964 -- Set_Msg_Blank_Conditional --
965 -------------------------------
967 procedure Set_Msg_Blank_Conditional is
970 and then Msg_Buffer (Msglen) /= ' '
971 and then Msg_Buffer (Msglen) /= '('
972 and then Msg_Buffer (Msglen) /= '"'
973 and then not Manual_Quote_Mode
977 end Set_Msg_Blank_Conditional;
983 procedure Set_Msg_Char (C : Character) is
986 -- The check for message buffer overflow is needed to deal with cases
987 -- where insertions get too long (in particular a child unit name can
990 if Msglen < Max_Msg_Length then
991 Msglen := Msglen + 1;
992 Msg_Buffer (Msglen) := C;
996 ---------------------------------
997 -- Set_Msg_Insertion_File_Name --
998 ---------------------------------
1000 procedure Set_Msg_Insertion_File_Name is
1002 if Error_Msg_File_1 = No_File then
1005 elsif Error_Msg_File_1 = Error_File_Name then
1007 Set_Msg_Str ("<error
>");
1011 Get_Name_String (Error_Msg_File_1);
1013 Set_Msg_Name_Buffer;
1017 -- The following assignments ensure that the second and third {
1018 -- insertion characters will correspond to the Error_Msg_File_2 and
1019 -- Error_Msg_File_3 values and We suppress possible validity checks in
1020 -- case operating in -gnatVa mode, and Error_Msg_File_2 or
1021 -- Error_Msg_File_3 is not needed and has not been set.
1024 pragma Suppress (Range_Check);
1026 Error_Msg_File_1 := Error_Msg_File_2;
1027 Error_Msg_File_2 := Error_Msg_File_3;
1029 end Set_Msg_Insertion_File_Name;
1031 -----------------------------------
1032 -- Set_Msg_Insertion_Line_Number --
1033 -----------------------------------
1035 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
1036 Sindex_Loc : Source_File_Index;
1037 Sindex_Flag : Source_File_Index;
1040 -- Outputs "at " unless last characters in buffer are " from
". Certain
1041 -- messages read better with from than at.
1050 or else Msg_Buffer (Msglen - 5 .. Msglen) /= " from
"
1052 Set_Msg_Str ("at ");
1056 -- Start of processing for Set_Msg_Insertion_Line_Number
1061 if Loc = No_Location then
1063 Set_Msg_Str ("unknown location
");
1065 elsif Loc = System_Location then
1066 Set_Msg_Str ("in package System
");
1067 Set_Msg_Insertion_Run_Time_Name;
1069 elsif Loc = Standard_Location then
1070 Set_Msg_Str ("in package Standard
");
1072 elsif Loc = Standard_ASCII_Location then
1073 Set_Msg_Str ("in package Standard
.ASCII
");
1076 -- Add "at file
-name
:" if reference is to other than the source
1077 -- file in which the error message is placed. Note that we check
1078 -- full file names, rather than just the source indexes, to
1079 -- deal with generic instantiations from the current file.
1081 Sindex_Loc := Get_Source_File_Index (Loc);
1082 Sindex_Flag := Get_Source_File_Index (Flag);
1084 if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
1087 (Reference_Name (Get_Source_File_Index (Loc)));
1088 Set_Msg_Name_Buffer;
1091 -- If in current file, add text "at line
"
1095 Set_Msg_Str ("line
");
1098 -- Output line number for reference
1100 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1102 -- Deal with the instantiation case. We may have a reference to,
1103 -- e.g. a type, that is declared within a generic template, and
1104 -- what we are really referring to is the occurrence in an instance.
1105 -- In this case, the line number of the instantiation is also of
1106 -- interest, and we add a notation:
1108 -- , instance at xxx
1110 -- where xxx is a line number output using this same routine (and
1111 -- the recursion can go further if the instantiation is itself in
1112 -- a generic template).
1114 -- The flag location passed to us in this situation is indeed the
1115 -- line number within the template, but as described in Sinput.L
1116 -- (file sinput-l.ads, section "Handling
Generic Instantiations
")
1117 -- we can retrieve the location of the instantiation itself from
1118 -- this flag location value.
1120 -- Note: this processing is suppressed if Suppress_Instance_Location
1121 -- is set True. This is used to prevent redundant annotations of the
1122 -- location of the instantiation in the case where we are placing
1123 -- the messages on the instantiation in any case.
1125 if Instantiation (Sindex_Loc) /= No_Location
1126 and then not Suppress_Instance_Location
1128 Set_Msg_Str (", instance
");
1129 Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
1132 end Set_Msg_Insertion_Line_Number;
1134 ----------------------------
1135 -- Set_Msg_Insertion_Name --
1136 ----------------------------
1138 procedure Set_Msg_Insertion_Name is
1140 if Error_Msg_Name_1 = No_Name then
1143 elsif Error_Msg_Name_1 = Error_Name then
1145 Set_Msg_Str ("<error
>");
1148 Set_Msg_Blank_Conditional;
1149 Get_Unqualified_Decoded_Name_String (Error_Msg_Name_1);
1151 -- Remove %s or %b at end. These come from unit names. If the
1152 -- caller wanted the (unit) or (body), then they would have used
1153 -- the $ insertion character. Certainly no error message should
1154 -- ever have %b or %s explicitly occurring.
1157 and then Name_Buffer (Name_Len - 1) = '%'
1158 and then (Name_Buffer (Name_Len) = 'b'
1160 Name_Buffer (Name_Len) = 's')
1162 Name_Len := Name_Len - 2;
1165 -- Remove upper case letter at end, again, we should not be getting
1166 -- such names, and what we hope is that the remainder makes sense.
1168 if Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' then
1169 Name_Len := Name_Len - 1;
1172 -- If operator name or character literal name, just print it as is
1173 -- Also print as is if it ends in a right paren (case of x'val(nnn))
1175 if Name_Buffer (1) = '"'
1176 or else Name_Buffer (1) = '''
1177 or else Name_Buffer (Name_Len) = ')'
1179 Set_Msg_Name_Buffer;
1181 -- Else output with surrounding quotes in proper casing mode
1184 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
1186 Set_Msg_Name_Buffer;
1191 -- The following assignments ensure that the second and third percent
1192 -- insertion characters will correspond to the Error_Msg_Name_2 and
1193 -- Error_Msg_Name_3 as required. We suppress possible validity checks in
1194 -- case operating in -gnatVa mode, and Error_Msg_Name_1/2 is not needed
1195 -- and has not been set.
1198 pragma Suppress (Range_Check);
1200 Error_Msg_Name_1 := Error_Msg_Name_2;
1201 Error_Msg_Name_2 := Error_Msg_Name_3;
1203 end Set_Msg_Insertion_Name;
1205 ------------------------------------
1206 -- Set_Msg_Insertion_Name_Literal --
1207 ------------------------------------
1209 procedure Set_Msg_Insertion_Name_Literal is
1211 if Error_Msg_Name_1 = No_Name then
1214 elsif Error_Msg_Name_1 = Error_Name then
1216 Set_Msg_Str ("<error>");
1220 Get_Name_String (Error_Msg_Name_1);
1222 Set_Msg_Name_Buffer;
1226 -- The following assignments ensure that the second and third % or %%
1227 -- insertion characters will correspond to the Error_Msg_Name_2 and
1228 -- Error_Msg_Name_3 values and We suppress possible validity checks in
1229 -- case operating in -gnatVa mode, and Error_Msg_Name_2 or
1230 -- Error_Msg_Name_3 is not needed and has not been set.
1233 pragma Suppress (Range_Check);
1235 Error_Msg_Name_1 := Error_Msg_Name_2;
1236 Error_Msg_Name_2 := Error_Msg_Name_3;
1238 end Set_Msg_Insertion_Name_Literal;
1240 -------------------------------------
1241 -- Set_Msg_Insertion_Reserved_Name --
1242 -------------------------------------
1244 procedure Set_Msg_Insertion_Reserved_Name is
1246 Set_Msg_Blank_Conditional;
1247 Get_Name_String (Error_Msg_Name_1);
1249 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1250 Set_Msg_Name_Buffer;
1252 end Set_Msg_Insertion_Reserved_Name;
1254 -------------------------------------
1255 -- Set_Msg_Insertion_Reserved_Word --
1256 -------------------------------------
1258 procedure Set_Msg_Insertion_Reserved_Word
1263 Set_Msg_Blank_Conditional;
1266 while J <= Text'Last and then Text (J) in 'A
' .. 'Z
' loop
1267 Add_Char_To_Name_Buffer (Text (J));
1271 -- Here is where we make the special exception for RM
1273 if Name_Len = 2 and then Name_Buffer (1 .. 2) = "RM" then
1274 Set_Msg_Name_Buffer;
1276 -- We make a similar exception for SPARK
1278 elsif Name_Len = 5 and then Name_Buffer (1 .. 5) = "SPARK" then
1279 Set_Msg_Name_Buffer;
1281 -- Neither RM nor SPARK: case appropriately and add surrounding quotes
1284 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1286 Set_Msg_Name_Buffer;
1289 end Set_Msg_Insertion_Reserved_Word;
1291 -------------------------------------
1292 -- Set_Msg_Insertion_Run_Time_Name --
1293 -------------------------------------
1295 procedure Set_Msg_Insertion_Run_Time_Name is
1297 if Targparm.Run_Time_Name_On_Target /= No_Name then
1298 Set_Msg_Blank_Conditional;
1300 Get_Name_String (Targparm.Run_Time_Name_On_Target);
1301 Set_Casing (Mixed_Case);
1302 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1305 end Set_Msg_Insertion_Run_Time_Name;
1307 ----------------------------
1308 -- Set_Msg_Insertion_Uint --
1309 ----------------------------
1311 procedure Set_Msg_Insertion_Uint is
1314 UI_Image (Error_Msg_Uint_1);
1316 for J in 1 .. UI_Image_Length loop
1317 Set_Msg_Char (UI_Image_Buffer (J));
1320 -- The following assignment ensures that a second caret insertion
1321 -- character will correspond to the Error_Msg_Uint_2 parameter. We
1322 -- suppress possible validity checks in case operating in -gnatVa mode,
1323 -- and Error_Msg_Uint_2 is not needed and has not been set.
1326 pragma Suppress (Range_Check);
1328 Error_Msg_Uint_1 := Error_Msg_Uint_2;
1330 end Set_Msg_Insertion_Uint;
1336 procedure Set_Msg_Int (Line : Int) is
1339 Set_Msg_Int (Line / 10);
1342 Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
1345 -------------------------
1346 -- Set_Msg_Name_Buffer --
1347 -------------------------
1349 procedure Set_Msg_Name_Buffer is
1351 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1352 end Set_Msg_Name_Buffer;
1358 procedure Set_Msg_Quote is
1360 if not Manual_Quote_Mode then
1369 procedure Set_Msg_Str (Text : String) is
1371 -- Do replacement for special x'Class aspect names
1373 if Text = "_Pre
" then
1374 Set_Msg_Str ("Pre
'Class");
1376 elsif Text = "_Post
" then
1377 Set_Msg_Str ("Post
'Class");
1379 elsif Text = "_Type_Invariant
" then
1380 Set_Msg_Str ("Type_Invariant
'Class");
1382 elsif Text = "_pre
" then
1383 Set_Msg_Str ("pre
'class");
1385 elsif Text = "_post
" then
1386 Set_Msg_Str ("post
'class");
1388 elsif Text = "_type_invariant
" then
1389 Set_Msg_Str ("type_invariant
'class");
1391 elsif Text = "_PRE
" then
1392 Set_Msg_Str ("PRE
'CLASS");
1394 elsif Text = "_POST
" then
1395 Set_Msg_Str ("POST
'CLASS");
1397 elsif Text = "_TYPE_INVARIANT
" then
1398 Set_Msg_Str ("TYPE_INVARIANT
'CLASS");
1400 -- Normal case with no replacement
1403 for J in Text'Range loop
1404 Set_Msg_Char (Text (J));
1409 ------------------------------
1410 -- Set_Next_Non_Deleted_Msg --
1411 ------------------------------
1413 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id) is
1415 if E = No_Error_Msg then
1420 E := Errors.Table (E).Next;
1421 exit when E = No_Error_Msg or else not Errors.Table (E).Deleted;
1424 end Set_Next_Non_Deleted_Msg;
1426 ------------------------------
1427 -- Set_Specific_Warning_Off --
1428 ------------------------------
1430 procedure Set_Specific_Warning_Off
1435 Used : Boolean := False)
1438 Specific_Warnings.Append
1440 Msg => new String'(Msg),
1441 Stop => Source_Last (Current_Source_File),
1446 end Set_Specific_Warning_Off;
1448 -----------------------------
1449 -- Set_Specific_Warning_On --
1450 -----------------------------
1452 procedure Set_Specific_Warning_On
1458 for J in 1 .. Specific_Warnings.Last loop
1460 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1463 if Msg = SWE.Msg.all
1464 and then Loc > SWE.Start
1466 and then Get_Source_File_Index (SWE.Start) =
1467 Get_Source_File_Index (Loc)
1473 -- If a config pragma is specifically cancelled, consider
1474 -- that it is no longer active as a configuration pragma.
1476 SWE.Config := False;
1483 end Set_Specific_Warning_On;
1485 ---------------------------
1486 -- Set_Warnings_Mode_Off --
1487 ---------------------------
1489 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr; Reason : String_Id) is
1491 -- Don't bother with entries from instantiation copies, since we will
1492 -- already have a copy in the template, which is what matters.
1494 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1498 -- If all warnings are suppressed by command line switch, this can
1499 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1500 -- Warnings to be stored for the formal verification backend.
1502 if Warning_Mode = Suppress
1503 and then not GNATprove_Mode
1508 -- If last entry in table already covers us, this is a redundant pragma
1509 -- Warnings (Off) and can be ignored.
1511 if Warnings.Last >= Warnings.First
1512 and then Warnings.Table (Warnings.Last).Start <= Loc
1513 and then Loc <= Warnings.Table (Warnings.Last).Stop
1518 -- If none of those special conditions holds, establish a new entry,
1519 -- extending from the location of the pragma to the end of the current
1520 -- source file. This ending point will be adjusted by a subsequent
1521 -- corresponding pragma Warnings (On).
1525 Stop => Source_Last (Current_Source_File),
1527 end Set_Warnings_Mode_Off;
1529 --------------------------
1530 -- Set_Warnings_Mode_On --
1531 --------------------------
1533 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
1535 -- Don't bother with entries from instantiation copies, since we will
1536 -- already have a copy in the template, which is what matters.
1538 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1542 -- If all warnings are suppressed by command line switch, this can
1543 -- be ignored, unless we are in GNATprove_Mode which requires pragma
1544 -- Warnings to be stored for the formal verification backend.
1546 if Warning_Mode = Suppress
1547 and then not GNATprove_Mode
1552 -- If the last entry in the warnings table covers this pragma, then
1553 -- we adjust the end point appropriately.
1555 if Warnings.Last >= Warnings.First
1556 and then Warnings.Table (Warnings.Last).Start <= Loc
1557 and then Loc <= Warnings.Table (Warnings.Last).Stop
1559 Warnings.Table (Warnings.Last).Stop := Loc;
1561 end Set_Warnings_Mode_On;
1563 --------------------------------
1564 -- Validate_Specific_Warnings --
1565 --------------------------------
1567 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc) is
1569 if not Warn_On_Warnings_Off then
1573 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1575 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1578 if not SWE.Config then
1580 -- Warn for unmatched Warnings (Off, ...)
1584 ("?W?
pragma Warnings Off
with no matching Warnings On
",
1587 -- Warn for ineffective Warnings (Off, ..)
1591 -- Do not issue this warning for -Wxxx messages since the
1592 -- back-end doesn't report the information. Note that there
1593 -- is always an asterisk at the start of every message.
1596 (SWE.Msg'Length > 3 and then SWE.Msg (2 .. 3) = "-W
")
1599 ("?W?no warning suppressed by this
pragma", SWE.Start);
1604 end Validate_Specific_Warnings;
1606 -------------------------------------
1607 -- Warning_Specifically_Suppressed --
1608 -------------------------------------
1610 function Warning_Specifically_Suppressed
1613 Tag : String := "") return String_Id
1616 -- Loop through specific warning suppression entries
1618 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1620 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1623 -- Pragma applies if it is a configuration pragma, or if the
1624 -- location is in range of a specific non-configuration pragma.
1627 or else (SWE.Start <= Loc and then Loc <= SWE.Stop)
1629 if Matches (Msg.all, SWE.Msg.all)
1630 or else Matches (Tag, SWE.Msg.all)
1640 end Warning_Specifically_Suppressed;
1642 ------------------------------
1643 -- Warning_Treated_As_Error --
1644 ------------------------------
1646 function Warning_Treated_As_Error (Msg : String) return Boolean is
1648 for J in 1 .. Warnings_As_Errors_Count loop
1649 if Matches (Msg, Warnings_As_Errors (J).all) then
1655 end Warning_Treated_As_Error;
1657 -------------------------
1658 -- Warnings_Suppressed --
1659 -------------------------
1661 function Warnings_Suppressed (Loc : Source_Ptr) return String_Id is
1663 -- Loop through table of ON/OFF warnings
1665 for J in Warnings.First .. Warnings.Last loop
1666 if Warnings.Table (J).Start <= Loc
1667 and then Loc <= Warnings.Table (J).Stop
1669 return Warnings.Table (J).Reason;
1673 if Warning_Mode = Suppress then
1674 return Null_String_Id;
1678 end Warnings_Suppressed;