1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2013, 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 Targparm; use Targparm;
43 with Uintp; use Uintp;
45 package body Erroutc is
51 procedure Add_Class is
56 Get_Name_String (Name_Class);
57 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
62 ----------------------
63 -- Buffer_Ends_With --
64 ----------------------
66 function Buffer_Ends_With (S : String) return Boolean is
67 Len : constant Natural := S'Length;
71 and then Msg_Buffer (Msglen - Len) = ' '
72 and then Msg_Buffer (Msglen - Len + 1 .. Msglen) = S;
79 procedure Buffer_Remove (S : String) is
81 if Buffer_Ends_With (S) then
82 Msglen := Msglen - S'Length;
86 -----------------------------
87 -- Check_Duplicate_Message --
88 -----------------------------
90 procedure Check_Duplicate_Message (M1, M2 : Error_Msg_Id) is
91 L1, L2 : Error_Msg_Id;
92 N1, N2 : Error_Msg_Id;
94 procedure Delete_Msg (Delete, Keep : Error_Msg_Id);
95 -- Called to delete message Delete, keeping message Keep. Marks
96 -- all messages of Delete with deleted flag set to True, and also
97 -- makes sure that for the error messages that are retained the
98 -- preferred message is the one retained (we prefer the shorter
99 -- one in the case where one has an Instance tag). Note that we
100 -- always know that Keep has at least as many continuations as
101 -- Delete (since we always delete the shorter sequence).
107 procedure Delete_Msg (Delete, Keep : Error_Msg_Id) is
115 Errors.Table (D).Deleted := True;
117 -- Adjust error message count
119 if Errors.Table (D).Warn or else Errors.Table (D).Style then
120 Warnings_Detected := Warnings_Detected - 1;
123 Total_Errors_Detected := Total_Errors_Detected - 1;
125 if Errors.Table (D).Serious then
126 Serious_Errors_Detected := Serious_Errors_Detected - 1;
130 -- Substitute shorter of the two error messages
132 if Errors.Table (K).Text'Length > Errors.Table (D).Text'Length then
133 Errors.Table (K).Text := Errors.Table (D).Text;
136 D := Errors.Table (D).Next;
137 K := Errors.Table (K).Next;
139 if D = No_Error_Msg or else not Errors.Table (D).Msg_Cont then
145 -- Start of processing for Check_Duplicate_Message
148 -- Both messages must be non-continuation messages and not deleted
150 if Errors.Table (M1).Msg_Cont
151 or else Errors.Table (M2).Msg_Cont
152 or else Errors.Table (M1).Deleted
153 or else Errors.Table (M2).Deleted
158 -- Definitely not equal if message text does not match
160 if not Same_Error (M1, M2) then
164 -- Same text. See if all continuations are also identical
170 N1 := Errors.Table (L1).Next;
171 N2 := Errors.Table (L2).Next;
173 -- If M1 continuations have run out, we delete M1, either the
174 -- messages have the same number of continuations, or M2 has
175 -- more and we prefer the one with more anyway.
177 if N1 = No_Error_Msg or else not Errors.Table (N1).Msg_Cont then
181 -- If M2 continuations have run out, we delete M2
183 elsif N2 = No_Error_Msg or else not Errors.Table (N2).Msg_Cont then
187 -- Otherwise see if continuations are the same, if not, keep both
188 -- sequences, a curious case, but better to keep everything!
190 elsif not Same_Error (N1, N2) then
193 -- If continuations are the same, continue scan
200 end Check_Duplicate_Message;
202 ------------------------
203 -- Compilation_Errors --
204 ------------------------
206 function Compilation_Errors return Boolean is
208 return Total_Errors_Detected /= 0
209 or else (Warnings_Detected /= 0
210 and then Warning_Mode = Treat_As_Error);
211 end Compilation_Errors;
217 procedure Debug_Output (N : Node_Id) is
220 Write_Str ("*** following error message posted on node id = #");
231 procedure dmsg (Id : Error_Msg_Id) is
232 E : Error_Msg_Object renames Errors.Table (Id);
235 w ("Dumping error message, Id = ", Int (Id));
236 w (" Text = ", E.Text.all);
237 w (" Next = ", Int (E.Next));
238 w (" Sfile = ", Int (E.Sfile));
242 Write_Location (E.Sptr);
247 Write_Location (E.Optr);
250 w (" Line = ", Int (E.Line));
251 w (" Col = ", Int (E.Col));
252 w (" Warn = ", E.Warn);
253 w (" Style = ", E.Style);
254 w (" Serious = ", E.Serious);
255 w (" Uncond = ", E.Uncond);
256 w (" Msg_Cont = ", E.Msg_Cont);
257 w (" Deleted = ", E.Deleted);
266 function Get_Location (E : Error_Msg_Id) return Source_Ptr is
268 return Errors.Table (E).Sptr;
275 function Get_Msg_Id return Error_Msg_Id is
280 -----------------------
281 -- Output_Error_Msgs --
282 -----------------------
284 procedure Output_Error_Msgs (E : in out Error_Msg_Id) is
290 Mult_Flags : Boolean := False;
295 -- Skip deleted messages at start
297 if Errors.Table (S).Deleted then
298 Set_Next_Non_Deleted_Msg (S);
301 -- Figure out if we will place more than one error flag on this line
304 while T /= No_Error_Msg
305 and then Errors.Table (T).Line = Errors.Table (E).Line
306 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
308 if Errors.Table (T).Sptr > Errors.Table (E).Sptr then
312 Set_Next_Non_Deleted_Msg (T);
315 -- Output the error flags. The circuit here makes sure that the tab
316 -- characters in the original line are properly accounted for. The
317 -- eight blanks at the start are to match the line number.
319 if not Debug_Flag_2 then
321 P := Line_Start (Errors.Table (E).Sptr);
324 -- Loop through error messages for this line to place flags
327 while T /= No_Error_Msg
328 and then Errors.Table (T).Line = Errors.Table (E).Line
329 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
331 -- Loop to output blanks till current flag position
333 while P < Errors.Table (T).Sptr loop
334 if Source_Text (Errors.Table (T).Sfile) (P) = ASCII.HT then
335 Write_Char (ASCII.HT);
343 -- Output flag (unless already output, this happens if more
344 -- than one error message occurs at the same flag position).
346 if P = Errors.Table (T).Sptr then
347 if (Flag_Num = 1 and then not Mult_Flags)
352 Write_Char (Character'Val (Character'Pos ('0') + Flag_Num));
358 Set_Next_Non_Deleted_Msg (T);
359 Flag_Num := Flag_Num + 1;
365 -- Now output the error messages
368 while T /= No_Error_Msg
369 and then Errors.Table (T).Line = Errors.Table (E).Line
370 and then Errors.Table (T).Sfile = Errors.Table (E).Sfile
376 while Column < 74 loop
384 Set_Next_Non_Deleted_Msg (T);
388 end Output_Error_Msgs;
390 ------------------------
391 -- Output_Line_Number --
392 ------------------------
394 procedure Output_Line_Number (L : Logical_Line_Number) is
395 D : Int; -- next digit
396 C : Character; -- next character
397 Z : Boolean; -- flag for zero suppress
398 N, M : Int; -- temporaries
401 if L = No_Line_Number then
422 C := Character'Val (D + 48);
430 end Output_Line_Number;
432 ---------------------
433 -- Output_Msg_Text --
434 ---------------------
436 procedure Output_Msg_Text (E : Error_Msg_Id) is
437 Offs : constant Nat := Column - 1;
438 -- Offset to start of message, used for continuations
441 -- Maximum characters to output on next line
444 -- Maximum total length of lines
446 Text : constant String_Ptr := Errors.Table (E).Text;
447 Warn : constant Boolean := Errors.Table (E).Warn;
448 Warn_Chr : constant Character := Errors.Table (E).Warn_Chr;
449 Warn_Tag : String_Ptr;
454 function Get_VMS_Warn_String (W : Character) return String;
455 -- On VMS, given a warning character W, returns VMS command string
456 -- that corresponds to that warning character
458 -------------------------
459 -- Get_VMS_Warn_String --
460 -------------------------
462 function Get_VMS_Warn_String (W : Character) return String is
464 -- Start and end of VMS_QUALIFIER below
467 -- Scans through string
469 -- The following is a copy of the S_GCC_Warn string from the package
470 -- VMS_Data. If we made that package part of the compiler sources
471 -- we could just with it and avoid the duplication ???
473 V : constant String := "/WARNINGS=" &
475 "!-gnatws,!-gnatwe " &
488 "FAILING_ASSERTIONS " &
490 "NO_FAILING_ASSERTIONS " &
492 "BAD_FIXED_VALUES " &
494 "NO_BAD_FIXED_VALUES " &
496 "BIASED_REPRESENTATION " &
498 "NO_BIASED_REPRESENTATION " &
504 "MISSING_COMPONENT_CLAUSES " &
506 "NOMISSING_COMPONENT_CLAUSES " &
508 "IMPLICIT_DEREFERENCE " &
510 "NO_IMPLICIT_DEREFERENCE " &
518 "UNREFERENCED_FORMALS " &
520 "NOUNREFERENCED_FORMALS " &
522 "UNRECOGNIZED_PRAGMAS " &
524 "NOUNRECOGNIZED_PRAGMAS " &
536 "NOIMPLEMENTATION " &
542 "CONSTANT_VARIABLES " &
544 "NOCONSTANT_VARIABLES " &
546 "STANDARD_REDEFINITION " &
548 "NOSTANDARD_REDEFINITION " &
556 "NOMODIFIED_UNREF " &
558 "SUSPICIOUS_MODULUS " &
560 "NOSUSPICIOUS_MODULUS " &
570 "NOOUT_PARAM_UNREF " &
572 "INEFFECTIVE_INLINE " &
574 "NOINEFFECTIVE_INLINE " &
580 "NOPARAMETER_ORDER " &
582 "NOMISSING_PARENS " &
590 "NOOBJECT_RENAMES " &
596 "NOOVERRIDING_SIZE " &
608 "UNORDERED_ENUMERATIONS " &
610 "NOUNORDERED_ENUMERATIONS " &
612 "VARIABLES_UNINITIALIZED " &
614 "NOVARIABLES_UNINITIALIZED " &
616 "REVERSE_BIT_ORDER " &
618 "NOREVERSE_BIT_ORDER " &
620 "LOWBOUND_ASSUMED " &
622 "NOLOWBOUND_ASSUMED " &
624 "WARNINGS_OFF_PRAGMAS " &
626 "NO_WARNINGS_OFF_PRAGMAS " &
628 "IMPORT_EXPORT_PRAGMAS " &
630 "NOIMPORT_EXPORT_PRAGMAS " &
632 "LOCAL_RAISE_HANDLING " &
634 "NOLOCAL_RAISE_HANDLING " &
636 "ADA_2005_COMPATIBILITY " &
638 "NOADA_2005_COMPATIBILITY " &
640 "UNCHECKED_CONVERSIONS " &
642 "NOUNCHECKED_CONVERSIONS " &
645 -- Start of processing for Get_VMS_Warn_String
648 -- This function works by inspecting the string S_GCC_Warn in the
649 -- package VMS_Data. We are looking for
651 -- space VMS_QUALIFIER space -gnatwq
653 -- where q is the lower case letter W if W is lower case, and the
654 -- two character string .W if W is upper case. If we find a match
655 -- we return VMS_QUALIFIER, otherwise we return empty (this should
656 -- be an error, but no point in bombing over something so trivial).
660 -- Loop through entries in S_GCC_Warn
663 -- Scan to next blank
666 if P >= V'Last - 1 then
670 exit when V (P) = ' ' and then V (P + 1) in 'A' .. 'Z';
677 -- Scan to blank at end of VMS_QUALIFIER
684 exit when V (P) = ' ';
690 -- See if this entry matches, and if so, return it
692 if V (P + 1 .. P + 6) = "-gnatw"
694 ((W in 'a' .. 'z' and then V (P + 7) = W)
696 (V (P + 7) = '.' and then Fold_Upper (V (P + 8)) = W))
701 end Get_VMS_Warn_String;
703 -- Start of processing for Output_Msg_Text
706 -- Add warning doc tag if needed
708 if Warn and then Warn_Chr /= ' ' then
709 if Warn_Chr = '?' then
710 Warn_Tag := new String'(" [enabled by default]");
712 elsif OpenVMS_On_Target then
714 Qual : constant String := Get_VMS_Warn_String (Warn_Chr);
717 Warn_Tag := new String'(Qual);
719 Warn_Tag := new String'(" [" & Qual & ']');
723 elsif Warn_Chr in 'a' .. 'z' then
724 Warn_Tag := new String'(" [-gnatw" & Warn_Chr & ']');
726 else pragma Assert (Warn_Chr in 'A' .. 'Z');
727 Warn_Tag := new String'(" [-gnatw." & Fold_Lower (Warn_Chr) & ']');
731 Warn_Tag := new String'("");
734 -- Set error message line length
736 if Error_Msg_Line_Length = 0 then
739 Length := Error_Msg_Line_Length;
742 Max := Integer (Length - Column + 1);
745 Txt : constant String := Text.all & Warn_Tag.all;
746 Len : constant Natural := Txt'Length;
749 -- For warning, add "warning: " unless msg starts with "info: "
751 if Errors.Table (E).Warn then
753 or else Txt (Txt'First .. Txt'First + 5) /= "info: "
755 Write_Str ("warning: ");
759 -- No prefix needed for style message, "(style)" is there already
761 elsif Errors.Table (E).Style then
764 -- All other cases, add "error: "
766 elsif Opt.Unique_Error_Tag then
767 Write_Str ("error: ");
771 -- Here we have to split the message up into multiple lines
775 -- Make sure we do not have ludicrously small line
777 Max := Integer'Max (Max, 20);
779 -- If remaining text fits, output it respecting LF and we are done
781 if Len - Ptr < Max then
782 for J in Ptr .. Len loop
783 if Txt (J) = ASCII.LF then
787 Write_Char (Txt (J));
798 -- First scan forward looking for a hard end of line
800 for Scan in Ptr .. Ptr + Max - 1 loop
801 if Txt (Scan) = ASCII.LF then
808 -- Otherwise scan backwards looking for a space
810 for Scan in reverse Ptr .. Ptr + Max - 1 loop
811 if Txt (Scan) = ' ' then
818 -- If we fall through, no space, so split line arbitrarily
820 Split := Ptr + Max - 1;
825 if Start <= Split then
826 Write_Line (Txt (Start .. Split));
830 Max := Integer (Length - Column + 1);
839 procedure Purge_Messages (From : Source_Ptr; To : Source_Ptr) is
842 function To_Be_Purged (E : Error_Msg_Id) return Boolean;
843 -- Returns True for a message that is to be purged. Also adjusts
844 -- error counts appropriately.
850 function To_Be_Purged (E : Error_Msg_Id) return Boolean is
853 and then Errors.Table (E).Sptr > From
854 and then Errors.Table (E).Sptr < To
856 if Errors.Table (E).Warn or else Errors.Table (E).Style then
857 Warnings_Detected := Warnings_Detected - 1;
860 Total_Errors_Detected := Total_Errors_Detected - 1;
862 if Errors.Table (E).Serious then
863 Serious_Errors_Detected := Serious_Errors_Detected - 1;
874 -- Start of processing for Purge_Messages
877 while To_Be_Purged (First_Error_Msg) loop
878 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
881 E := First_Error_Msg;
882 while E /= No_Error_Msg loop
883 while To_Be_Purged (Errors.Table (E).Next) loop
884 Errors.Table (E).Next :=
885 Errors.Table (Errors.Table (E).Next).Next;
888 E := Errors.Table (E).Next;
896 function Same_Error (M1, M2 : Error_Msg_Id) return Boolean is
897 Msg1 : constant String_Ptr := Errors.Table (M1).Text;
898 Msg2 : constant String_Ptr := Errors.Table (M2).Text;
900 Msg2_Len : constant Integer := Msg2'Length;
901 Msg1_Len : constant Integer := Msg1'Length;
907 (Msg1_Len - 10 > Msg2_Len
909 Msg2.all = Msg1.all (1 .. Msg2_Len)
911 Msg1 (Msg2_Len + 1 .. Msg2_Len + 10) = ", instance")
913 (Msg2_Len - 10 > Msg1_Len
915 Msg1.all = Msg2.all (1 .. Msg1_Len)
917 Msg2 (Msg1_Len + 1 .. Msg1_Len + 10) = ", instance");
924 procedure Set_Msg_Blank is
927 and then Msg_Buffer (Msglen) /= ' '
928 and then Msg_Buffer (Msglen) /= '('
929 and then Msg_Buffer (Msglen) /= '-'
930 and then not Manual_Quote_Mode
936 -------------------------------
937 -- Set_Msg_Blank_Conditional --
938 -------------------------------
940 procedure Set_Msg_Blank_Conditional is
943 and then Msg_Buffer (Msglen) /= ' '
944 and then Msg_Buffer (Msglen) /= '('
945 and then Msg_Buffer (Msglen) /= '"'
946 and then not Manual_Quote_Mode
950 end Set_Msg_Blank_Conditional;
956 procedure Set_Msg_Char (C : Character) is
959 -- The check for message buffer overflow is needed to deal with cases
960 -- where insertions get too long (in particular a child unit name can
963 if Msglen < Max_Msg_Length then
964 Msglen := Msglen + 1;
965 Msg_Buffer (Msglen) := C;
969 ---------------------------------
970 -- Set_Msg_Insertion_File_Name --
971 ---------------------------------
973 procedure Set_Msg_Insertion_File_Name is
975 if Error_Msg_File_1 = No_File then
978 elsif Error_Msg_File_1 = Error_File_Name then
980 Set_Msg_Str ("<error>");
984 Get_Name_String (Error_Msg_File_1);
990 -- The following assignments ensure that the second and third {
991 -- insertion characters will correspond to the Error_Msg_File_2 and
992 -- Error_Msg_File_3 values and We suppress possible validity checks in
993 -- case operating in -gnatVa mode, and Error_Msg_File_2 or
994 -- Error_Msg_File_3 is not needed and has not been set.
997 pragma Suppress (Range_Check);
999 Error_Msg_File_1 := Error_Msg_File_2;
1000 Error_Msg_File_2 := Error_Msg_File_3;
1002 end Set_Msg_Insertion_File_Name;
1004 -----------------------------------
1005 -- Set_Msg_Insertion_Line_Number --
1006 -----------------------------------
1008 procedure Set_Msg_Insertion_Line_Number (Loc, Flag : Source_Ptr) is
1009 Sindex_Loc : Source_File_Index;
1010 Sindex_Flag : Source_File_Index;
1013 -- Outputs "at " unless last characters in buffer are " from ". Certain
1014 -- messages read better with from than at.
1023 or else Msg_Buffer (Msglen - 5 .. Msglen) /= " from "
1025 Set_Msg_Str ("at ");
1029 -- Start of processing for Set_Msg_Insertion_Line_Number
1034 if Loc = No_Location then
1036 Set_Msg_Str ("unknown location");
1038 elsif Loc = System_Location then
1039 Set_Msg_Str ("in package System");
1040 Set_Msg_Insertion_Run_Time_Name;
1042 elsif Loc = Standard_Location then
1043 Set_Msg_Str ("in package Standard");
1045 elsif Loc = Standard_ASCII_Location then
1046 Set_Msg_Str ("in package Standard.ASCII");
1049 -- Add "at file-name:" if reference is to other than the source
1050 -- file in which the error message is placed. Note that we check
1051 -- full file names, rather than just the source indexes, to
1052 -- deal with generic instantiations from the current file.
1054 Sindex_Loc := Get_Source_File_Index (Loc);
1055 Sindex_Flag := Get_Source_File_Index (Flag);
1057 if Full_File_Name (Sindex_Loc) /= Full_File_Name (Sindex_Flag) then
1060 (Reference_Name (Get_Source_File_Index (Loc)));
1061 Set_Msg_Name_Buffer;
1064 -- If in current file, add text "at line "
1068 Set_Msg_Str ("line ");
1071 -- Output line number for reference
1073 Set_Msg_Int (Int (Get_Logical_Line_Number (Loc)));
1075 -- Deal with the instantiation case. We may have a reference to,
1076 -- e.g. a type, that is declared within a generic template, and
1077 -- what we are really referring to is the occurrence in an instance.
1078 -- In this case, the line number of the instantiation is also of
1079 -- interest, and we add a notation:
1081 -- , instance at xxx
1083 -- where xxx is a line number output using this same routine (and
1084 -- the recursion can go further if the instantiation is itself in
1085 -- a generic template).
1087 -- The flag location passed to us in this situation is indeed the
1088 -- line number within the template, but as described in Sinput.L
1089 -- (file sinput-l.ads, section "Handling Generic Instantiations")
1090 -- we can retrieve the location of the instantiation itself from
1091 -- this flag location value.
1093 -- Note: this processing is suppressed if Suppress_Instance_Location
1094 -- is set True. This is used to prevent redundant annotations of the
1095 -- location of the instantiation in the case where we are placing
1096 -- the messages on the instantiation in any case.
1098 if Instantiation (Sindex_Loc) /= No_Location
1099 and then not Suppress_Instance_Location
1101 Set_Msg_Str (", instance ");
1102 Set_Msg_Insertion_Line_Number (Instantiation (Sindex_Loc), Flag);
1105 end Set_Msg_Insertion_Line_Number;
1107 ----------------------------
1108 -- Set_Msg_Insertion_Name --
1109 ----------------------------
1111 procedure Set_Msg_Insertion_Name is
1113 if Error_Msg_Name_1 = No_Name then
1116 elsif Error_Msg_Name_1 = Error_Name then
1118 Set_Msg_Str ("<error>");
1121 Set_Msg_Blank_Conditional;
1122 Get_Unqualified_Decoded_Name_String (Error_Msg_Name_1);
1124 -- Remove %s or %b at end. These come from unit names. If the
1125 -- caller wanted the (unit) or (body), then they would have used
1126 -- the $ insertion character. Certainly no error message should
1127 -- ever have %b or %s explicitly occurring.
1130 and then Name_Buffer (Name_Len - 1) = '%'
1131 and then (Name_Buffer (Name_Len) = 'b'
1133 Name_Buffer (Name_Len) = 's')
1135 Name_Len := Name_Len - 2;
1138 -- Remove upper case letter at end, again, we should not be getting
1139 -- such names, and what we hope is that the remainder makes sense.
1141 if Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' then
1142 Name_Len := Name_Len - 1;
1145 -- If operator name or character literal name, just print it as is
1146 -- Also print as is if it ends in a right paren (case of x'val(nnn))
1148 if Name_Buffer (1) = '"'
1149 or else Name_Buffer (1) = '''
1150 or else Name_Buffer (Name_Len) = ')'
1152 Set_Msg_Name_Buffer;
1154 -- Else output with surrounding quotes in proper casing mode
1157 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
1159 Set_Msg_Name_Buffer;
1164 -- The following assignments ensure that the second and third percent
1165 -- insertion characters will correspond to the Error_Msg_Name_2 and
1166 -- Error_Msg_Name_3 as required. We suppress possible validity checks in
1167 -- case operating in -gnatVa mode, and Error_Msg_Name_1/2 is not needed
1168 -- and has not been set.
1171 pragma Suppress (Range_Check);
1173 Error_Msg_Name_1 := Error_Msg_Name_2;
1174 Error_Msg_Name_2 := Error_Msg_Name_3;
1176 end Set_Msg_Insertion_Name;
1178 ------------------------------------
1179 -- Set_Msg_Insertion_Name_Literal --
1180 ------------------------------------
1182 procedure Set_Msg_Insertion_Name_Literal is
1184 if Error_Msg_Name_1 = No_Name then
1187 elsif Error_Msg_Name_1 = Error_Name then
1189 Set_Msg_Str ("<error>");
1193 Get_Name_String (Error_Msg_Name_1);
1195 Set_Msg_Name_Buffer;
1199 -- The following assignments ensure that the second and third % or %%
1200 -- insertion characters will correspond to the Error_Msg_Name_2 and
1201 -- Error_Msg_Name_3 values and We suppress possible validity checks in
1202 -- case operating in -gnatVa mode, and Error_Msg_Name_2 or
1203 -- Error_Msg_Name_3 is not needed and has not been set.
1206 pragma Suppress (Range_Check);
1208 Error_Msg_Name_1 := Error_Msg_Name_2;
1209 Error_Msg_Name_2 := Error_Msg_Name_3;
1211 end Set_Msg_Insertion_Name_Literal;
1213 -------------------------------------
1214 -- Set_Msg_Insertion_Reserved_Name --
1215 -------------------------------------
1217 procedure Set_Msg_Insertion_Reserved_Name is
1219 Set_Msg_Blank_Conditional;
1220 Get_Name_String (Error_Msg_Name_1);
1222 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1223 Set_Msg_Name_Buffer;
1225 end Set_Msg_Insertion_Reserved_Name;
1227 -------------------------------------
1228 -- Set_Msg_Insertion_Reserved_Word --
1229 -------------------------------------
1231 procedure Set_Msg_Insertion_Reserved_Word
1236 Set_Msg_Blank_Conditional;
1239 while J <= Text'Last and then Text (J) in 'A' .. 'Z' loop
1240 Add_Char_To_Name_Buffer (Text (J));
1244 -- Here is where we make the special exception for RM
1246 if Name_Len = 2 and then Name_Buffer (1 .. 2) = "RM" then
1247 Set_Msg_Name_Buffer;
1249 -- We make a similar exception for SPARK
1251 elsif Name_Len = 5 and then Name_Buffer (1 .. 5) = "SPARK" then
1252 Set_Msg_Name_Buffer;
1254 -- Neither RM nor SPARK: case appropriately and add surrounding quotes
1257 Set_Casing (Keyword_Casing (Flag_Source), All_Lower_Case);
1259 Set_Msg_Name_Buffer;
1262 end Set_Msg_Insertion_Reserved_Word;
1264 -------------------------------------
1265 -- Set_Msg_Insertion_Run_Time_Name --
1266 -------------------------------------
1268 procedure Set_Msg_Insertion_Run_Time_Name is
1270 if Targparm.Run_Time_Name_On_Target /= No_Name then
1271 Set_Msg_Blank_Conditional;
1273 Get_Name_String (Targparm.Run_Time_Name_On_Target);
1274 Set_Casing (Mixed_Case);
1275 Set_Msg_Str (Name_Buffer (1 .. Name_Len));
1278 end Set_Msg_Insertion_Run_Time_Name;
1280 ----------------------------
1281 -- Set_Msg_Insertion_Uint --
1282 ----------------------------
1284 procedure Set_Msg_Insertion_Uint is
1287 UI_Image (Error_Msg_Uint_1);
1289 for J in 1 .. UI_Image_Length loop
1290 Set_Msg_Char (UI_Image_Buffer (J));
1293 -- The following assignment ensures that a second caret insertion
1294 -- character will correspond to the Error_Msg_Uint_2 parameter. We
1295 -- suppress possible validity checks in case operating in -gnatVa mode,
1296 -- and Error_Msg_Uint_2 is not needed and has not been set.
1299 pragma Suppress (Range_Check);
1301 Error_Msg_Uint_1 := Error_Msg_Uint_2;
1303 end Set_Msg_Insertion_Uint;
1309 procedure Set_Msg_Int (Line : Int) is
1312 Set_Msg_Int (Line / 10);
1315 Set_Msg_Char (Character'Val (Character'Pos ('0') + (Line rem 10)));
1318 -------------------------
1319 -- Set_Msg_Name_Buffer --
1320 -------------------------
1322 procedure Set_Msg_Name_Buffer is
1324 for J in 1 .. Name_Len loop
1325 Set_Msg_Char (Name_Buffer (J));
1327 end Set_Msg_Name_Buffer;
1333 procedure Set_Msg_Quote is
1335 if not Manual_Quote_Mode then
1344 procedure Set_Msg_Str (Text : String) is
1346 for J in Text'Range loop
1347 Set_Msg_Char (Text (J));
1351 ------------------------------
1352 -- Set_Next_Non_Deleted_Msg --
1353 ------------------------------
1355 procedure Set_Next_Non_Deleted_Msg (E : in out Error_Msg_Id) is
1357 if E = No_Error_Msg then
1362 E := Errors.Table (E).Next;
1363 exit when E = No_Error_Msg or else not Errors.Table (E).Deleted;
1366 end Set_Next_Non_Deleted_Msg;
1368 ------------------------------
1369 -- Set_Specific_Warning_Off --
1370 ------------------------------
1372 procedure Set_Specific_Warning_Off
1376 Used : Boolean := False)
1379 Specific_Warnings.Append
1381 Msg => new String'(Msg),
1382 Stop => Source_Last (Current_Source_File),
1386 end Set_Specific_Warning_Off;
1388 -----------------------------
1389 -- Set_Specific_Warning_On --
1390 -----------------------------
1392 procedure Set_Specific_Warning_On
1398 for J in 1 .. Specific_Warnings.Last loop
1400 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1402 if Msg = SWE.Msg.all
1403 and then Loc > SWE.Start
1405 and then Get_Source_File_Index (SWE.Start) =
1406 Get_Source_File_Index (Loc)
1412 -- If a config pragma is specifically cancelled, consider
1413 -- that it is no longer active as a configuration pragma.
1415 SWE.Config := False;
1422 end Set_Specific_Warning_On;
1424 ---------------------------
1425 -- Set_Warnings_Mode_Off --
1426 ---------------------------
1428 procedure Set_Warnings_Mode_Off (Loc : Source_Ptr) is
1430 -- Don't bother with entries from instantiation copies, since we will
1431 -- already have a copy in the template, which is what matters.
1433 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1437 -- If last entry in table already covers us, this is a redundant pragma
1438 -- Warnings (Off) and can be ignored. This also handles the case where
1439 -- all warnings are suppressed by command line switch.
1441 if Warnings.Last >= Warnings.First
1442 and then Warnings.Table (Warnings.Last).Start <= Loc
1443 and then Loc <= Warnings.Table (Warnings.Last).Stop
1447 -- Otherwise establish a new entry, extending from the location of the
1448 -- pragma to the end of the current source file. This ending point will
1449 -- be adjusted by a subsequent pragma Warnings (On).
1452 Warnings.Increment_Last;
1453 Warnings.Table (Warnings.Last).Start := Loc;
1454 Warnings.Table (Warnings.Last).Stop :=
1455 Source_Last (Current_Source_File);
1457 end Set_Warnings_Mode_Off;
1459 --------------------------
1460 -- Set_Warnings_Mode_On --
1461 --------------------------
1463 procedure Set_Warnings_Mode_On (Loc : Source_Ptr) is
1465 -- Don't bother with entries from instantiation copies, since we will
1466 -- already have a copy in the template, which is what matters.
1468 if Instantiation (Get_Source_File_Index (Loc)) /= No_Location then
1472 -- Nothing to do unless command line switch to suppress all warnings
1473 -- is off, and the last entry in the warnings table covers this
1474 -- pragma Warnings (On), in which case adjust the end point.
1476 if (Warnings.Last >= Warnings.First
1477 and then Warnings.Table (Warnings.Last).Start <= Loc
1478 and then Loc <= Warnings.Table (Warnings.Last).Stop)
1479 and then Warning_Mode /= Suppress
1481 Warnings.Table (Warnings.Last).Stop := Loc;
1483 end Set_Warnings_Mode_On;
1485 ------------------------------------
1486 -- Test_Style_Warning_Serious_Msg --
1487 ------------------------------------
1489 procedure Test_Style_Warning_Serious_Unconditional_Msg (Msg : String) is
1491 -- Nothing to do for continuation line
1493 if Msg (Msg'First) = '\' then
1497 -- Set initial values of globals (may be changed during scan)
1499 Is_Serious_Error := True;
1500 Is_Unconditional_Msg := False;
1501 Is_Warning_Msg := False;
1502 Has_Double_Exclam := False;
1505 (Msg'Length > 7 and then Msg (Msg'First .. Msg'First + 6) = "(style)");
1507 for J in Msg'Range loop
1509 and then (J = Msg'First or else Msg (J - 1) /= ''')
1511 Is_Warning_Msg := True;
1512 Warning_Msg_Char := ' ';
1515 and then (J = Msg'First or else Msg (J - 1) /= ''')
1517 Is_Unconditional_Msg := True;
1518 Warning_Msg_Char := ' ';
1520 if J < Msg'Last and then Msg (J + 1) = '!' then
1521 Has_Double_Exclam := True;
1525 and then (J = Msg'First or else Msg (J - 1) /= ''')
1527 Is_Warning_Msg := Error_Msg_Warn;
1528 Warning_Msg_Char := ' ';
1531 and then (J = Msg'First or else Msg (J - 1) /= ''')
1533 Is_Serious_Error := False;
1537 if Is_Warning_Msg or Is_Style_Msg then
1538 Is_Serious_Error := False;
1540 end Test_Style_Warning_Serious_Unconditional_Msg;
1542 --------------------------------
1543 -- Validate_Specific_Warnings --
1544 --------------------------------
1546 procedure Validate_Specific_Warnings (Eproc : Error_Msg_Proc) is
1548 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1550 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1553 if not SWE.Config then
1555 -- Warn for unmatched Warnings (Off, ...)
1559 ("?pragma Warnings Off with no matching Warnings On",
1562 -- Warn for ineffective Warnings (Off, ..)
1566 -- Do not issue this warning for -Wxxx messages since the
1567 -- back-end doesn't report the information.
1570 (SWE.Msg'Length > 2 and then SWE.Msg (1 .. 2) = "-W")
1573 ("?no warning suppressed by this pragma", SWE.Start);
1578 end Validate_Specific_Warnings;
1580 -------------------------------------
1581 -- Warning_Specifically_Suppressed --
1582 -------------------------------------
1584 function Warning_Specifically_Suppressed
1586 Msg : String_Ptr) return Boolean
1588 function Matches (S : String; P : String) return Boolean;
1589 -- Returns true if the String S patches the pattern P, which can contain
1590 -- wild card chars (*). The entire pattern must match the entire string.
1596 function Matches (S : String; P : String) return Boolean is
1597 Slast : constant Natural := S'Last;
1598 PLast : constant Natural := P'Last;
1600 SPtr : Natural := S'First;
1601 PPtr : Natural := P'First;
1604 -- Loop advancing through characters of string and pattern
1609 -- Return True if pattern is a single asterisk
1611 if PPtr = PLast and then P (PPtr) = '*' then
1614 -- Return True if both pattern and string exhausted
1616 elsif PPtr > PLast and then SPtr > Slast then
1619 -- Return False, if one exhausted and not the other
1621 elsif PPtr > PLast or else SPtr > Slast then
1624 -- Case where pattern starts with asterisk
1626 elsif P (PPtr) = '*' then
1628 -- Try all possible starting positions in S for match with
1629 -- the remaining characters of the pattern. This is the
1630 -- recursive call that implements the scanner backup.
1632 for J in SPtr .. Slast loop
1633 if Matches (S (J .. Slast), P (PPtr + 1 .. PLast)) then
1640 -- Dealt with end of string and *, advance if we have a match
1642 elsif S (SPtr) = P (PPtr) then
1646 -- If first characters do not match, that's decisive
1654 -- Start of processing for Warning_Specifically_Suppressed
1657 -- Loop through specific warning suppression entries
1659 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1661 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1664 -- Pragma applies if it is a configuration pragma, or if the
1665 -- location is in range of a specific non-configuration pragma.
1668 or else (SWE.Start <= Loc and then Loc <= SWE.Stop)
1670 if Matches (Msg.all, SWE.Msg.all) then
1679 end Warning_Specifically_Suppressed;
1681 -------------------------
1682 -- Warnings_Suppressed --
1683 -------------------------
1685 function Warnings_Suppressed (Loc : Source_Ptr) return Boolean is
1687 if Warning_Mode = Suppress then
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
1702 end Warnings_Suppressed;