[AArch64] Remove use of wider vector modes
[official-gcc.git] / gcc / ada / errout.adb
blob762ccda92858002b9d832c80a8199687b519a97a
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- E R R O U T --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 -- Warning: Error messages can be generated during Gigi processing by direct
27 -- calls to error message routines, so it is essential that the processing
28 -- in this body be consistent with the requirements for the Gigi processing
29 -- environment, and that in particular, no disallowed table expansion is
30 -- allowed to occur.
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Csets; use Csets;
35 with Debug; use Debug;
36 with Einfo; use Einfo;
37 with Erroutc; use Erroutc;
38 with Gnatvsn; use Gnatvsn;
39 with Lib; use Lib;
40 with Opt; use Opt;
41 with Nlists; use Nlists;
42 with Output; use Output;
43 with Scans; use Scans;
44 with Sem_Aux; use Sem_Aux;
45 with Sinput; use Sinput;
46 with Sinfo; use Sinfo;
47 with Snames; use Snames;
48 with Stand; use Stand;
49 with Stylesw; use Stylesw;
50 with Uname; use Uname;
52 package body Errout is
54 Errors_Must_Be_Ignored : Boolean := False;
55 -- Set to True by procedure Set_Ignore_Errors (True), when calls to error
56 -- message procedures should be ignored (when parsing irrelevant text in
57 -- sources being preprocessed).
59 Finalize_Called : Boolean := False;
60 -- Set True if the Finalize routine has been called
62 Record_Compilation_Errors : Boolean := False;
63 -- Record that a compilation error was witnessed during a given phase of
64 -- analysis for gnat2why. This is needed as Warning_Mode is modified twice
65 -- in gnat2why, hence Erroutc.Compilation_Errors can only return a suitable
66 -- value for each phase of analysis separately. This is updated at each
67 -- call to Compilation_Errors.
69 Warn_On_Instance : Boolean;
70 -- Flag set true for warning message to be posted on instance
72 ------------------------------------
73 -- Table of Non-Instance Messages --
74 ------------------------------------
76 -- This table contains an entry for every error message processed by the
77 -- Error_Msg routine that is not posted on generic (or inlined) instance.
78 -- As explained in further detail in the Error_Msg procedure body, this
79 -- table is used to avoid posting redundant messages on instances.
81 type NIM_Record is record
82 Msg : String_Ptr;
83 Loc : Source_Ptr;
84 end record;
85 -- Type used to store text and location of one message
87 package Non_Instance_Msgs is new Table.Table (
88 Table_Component_Type => NIM_Record,
89 Table_Index_Type => Int,
90 Table_Low_Bound => 1,
91 Table_Initial => 100,
92 Table_Increment => 100,
93 Table_Name => "Non_Instance_Msgs");
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 procedure Error_Msg_Internal
100 (Msg : String;
101 Sptr : Source_Ptr;
102 Optr : Source_Ptr;
103 Msg_Cont : Boolean);
104 -- This is the low level routine used to post messages after dealing with
105 -- the issue of messages placed on instantiations (which get broken up
106 -- into separate calls in Error_Msg). Sptr is the location on which the
107 -- flag will be placed in the output. In the case where the flag is on
108 -- the template, this points directly to the template, not to one of the
109 -- instantiation copies of the template. Optr is the original location
110 -- used to flag the error, and this may indeed point to an instantiation
111 -- copy. So typically we can see Optr pointing to the template location
112 -- in an instantiation copy when Sptr points to the source location of
113 -- the actual instantiation (i.e the line with the new). Msg_Cont is
114 -- set true if this is a continuation message.
116 function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
117 -- Determines if warnings should be suppressed for the given node
119 function OK_Node (N : Node_Id) return Boolean;
120 -- Determines if a node is an OK node to place an error message on (return
121 -- True) or if the error message should be suppressed (return False). A
122 -- message is suppressed if the node already has an error posted on it,
123 -- or if it refers to an Etype that has an error posted on it, or if
124 -- it references an Entity that has an error posted on it.
126 procedure Output_Source_Line
127 (L : Physical_Line_Number;
128 Sfile : Source_File_Index;
129 Errs : Boolean);
130 -- Outputs text of source line L, in file S, together with preceding line
131 -- number, as described above for Output_Line_Number. The Errs parameter
132 -- indicates if there are errors attached to the line, which forces
133 -- listing on, even in the presence of pragma List (Off).
135 procedure Set_Msg_Insertion_Column;
136 -- Handle column number insertion (@ insertion character)
138 procedure Set_Msg_Insertion_Node;
139 -- Handle node (name from node) insertion (& insertion character)
141 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
142 -- Handle type reference (right brace insertion character). Flag is the
143 -- location of the flag, which is provided for the internal call to
144 -- Set_Msg_Insertion_Line_Number,
146 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True);
147 -- Handle unit name insertion ($ insertion character). Depending on Boolean
148 -- parameter Suffix, (spec) or (body) is appended after the unit name.
150 procedure Set_Msg_Node (Node : Node_Id);
151 -- Add the sequence of characters for the name associated with the given
152 -- node to the current message. For N_Designator, N_Selected_Component,
153 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
154 -- included as well.
156 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
157 -- Add a sequence of characters to the current message. The characters may
158 -- be one of the special insertion characters (see documentation in spec).
159 -- Flag is the location at which the error is to be posted, which is used
160 -- to determine whether or not the # insertion needs a file name. The
161 -- variables Msg_Buffer are set on return Msglen.
163 procedure Set_Posted (N : Node_Id);
164 -- Sets the Error_Posted flag on the given node, and all its parents that
165 -- are subexpressions and then on the parent non-subexpression construct
166 -- that contains the original expression. If that parent is a named
167 -- association, the flag is further propagated to its parent. This is done
168 -- in order to guard against cascaded errors. Note that this call has an
169 -- effect for a serious error only.
171 procedure Set_Qualification (N : Nat; E : Entity_Id);
172 -- Outputs up to N levels of qualification for the given entity. For
173 -- example, the entity A.B.C.D will output B.C. if N = 2.
175 function Special_Msg_Delete
176 (Msg : String;
177 N : Node_Or_Entity_Id;
178 E : Node_Or_Entity_Id) return Boolean;
179 -- This function is called from Error_Msg_NEL, passing the message Msg,
180 -- node N on which the error is to be posted, and the entity or node E
181 -- to be used for an & insertion in the message if any. The job of this
182 -- procedure is to test for certain cascaded messages that we would like
183 -- to suppress. If the message is to be suppressed then we return True.
184 -- If the message should be generated (the normal case) False is returned.
186 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
187 -- This procedure is given an entity id for an internal type, i.e. a type
188 -- with an internal name. It unwinds the type to try to get to something
189 -- reasonably printable, generating prefixes like "subtype of", "access
190 -- to", etc along the way in the buffer. The value in Ent on return is the
191 -- final name to be printed. Hopefully this is not an internal name, but in
192 -- some internal name cases, it is an internal name, and has to be printed
193 -- anyway (although in this case the message has been killed if possible).
194 -- The global variable Class_Flag is set to True if the resulting entity
195 -- should have 'Class appended to its name (see Add_Class procedure), and
196 -- is otherwise unchanged.
198 function Warn_Insertion return String;
199 -- This is called for warning messages only (so Warning_Msg_Char is set)
200 -- and returns a corresponding string to use at the beginning of generated
201 -- auxiliary messages, such as "in instantiation at ...".
202 -- 'a' .. 'z' returns "?x?"
203 -- 'A' .. 'Z' returns "?X?"
204 -- '*' returns "?*?"
205 -- '$' returns "?$?info: "
206 -- ' ' returns " "
207 -- No other settings are valid
209 -----------------------
210 -- Change_Error_Text --
211 -----------------------
213 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
214 Save_Next : Error_Msg_Id;
215 Err_Id : Error_Msg_Id := Error_Id;
217 begin
218 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr);
219 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
221 -- If in immediate error message mode, output modified error message now
222 -- This is just a bit tricky, because we want to output just a single
223 -- message, and the messages we modified is already linked in. We solve
224 -- this by temporarily resetting its forward pointer to empty.
226 if Debug_Flag_OO then
227 Save_Next := Errors.Table (Error_Id).Next;
228 Errors.Table (Error_Id).Next := No_Error_Msg;
229 Write_Eol;
230 Output_Source_Line
231 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
232 Output_Error_Msgs (Err_Id);
233 Errors.Table (Error_Id).Next := Save_Next;
234 end if;
235 end Change_Error_Text;
237 ------------------------
238 -- Compilation_Errors --
239 ------------------------
241 function Compilation_Errors return Boolean is
242 begin
243 if not Finalize_Called then
244 raise Program_Error;
246 -- Record that a compilation error was witnessed during a given phase of
247 -- analysis for gnat2why. This is needed as Warning_Mode is modified
248 -- twice in gnat2why, hence Erroutc.Compilation_Errors can only return a
249 -- suitable value for each phase of analysis separately.
251 else
252 Record_Compilation_Errors :=
253 Record_Compilation_Errors or else Erroutc.Compilation_Errors;
255 return Record_Compilation_Errors;
256 end if;
257 end Compilation_Errors;
259 --------------------------------------
260 -- Delete_Warning_And_Continuations --
261 --------------------------------------
263 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
264 Id : Error_Msg_Id;
266 begin
267 pragma Assert (not Errors.Table (Msg).Msg_Cont);
269 Id := Msg;
270 loop
271 declare
272 M : Error_Msg_Object renames Errors.Table (Id);
274 begin
275 if not M.Deleted then
276 M.Deleted := True;
277 Warnings_Detected := Warnings_Detected - 1;
279 if M.Info then
280 Warning_Info_Messages := Warning_Info_Messages - 1;
281 end if;
283 if M.Warn_Err then
284 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
285 end if;
286 end if;
288 Id := M.Next;
289 exit when Id = No_Error_Msg;
290 exit when not Errors.Table (Id).Msg_Cont;
291 end;
292 end loop;
293 end Delete_Warning_And_Continuations;
295 ---------------
296 -- Error_Msg --
297 ---------------
299 -- Error_Msg posts a flag at the given location, except that if the
300 -- Flag_Location points within a generic template and corresponds to an
301 -- instantiation of this generic template, then the actual message will be
302 -- posted on the generic instantiation, along with additional messages
303 -- referencing the generic declaration.
305 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
306 Sindex : Source_File_Index;
307 -- Source index for flag location
309 Orig_Loc : Source_Ptr;
310 -- Original location of Flag_Location (i.e. location in original
311 -- template in instantiation case, otherwise unchanged).
313 begin
314 -- Return if all errors are to be ignored
316 if Errors_Must_Be_Ignored then
317 return;
318 end if;
320 -- If we already have messages, and we are trying to place a message at
321 -- No_Location, then just ignore the attempt since we assume that what
322 -- is happening is some cascaded junk. Note that this is safe in the
323 -- sense that proceeding will surely bomb. We will also bomb if the flag
324 -- location is No_Location and we don't have any messages so far, but
325 -- that is a real bug and a legitimate bomb, so we go ahead.
327 if Flag_Location = No_Location
328 and then Total_Errors_Detected > 0
329 then
330 return;
331 end if;
333 -- Start of processing for new message
335 Sindex := Get_Source_File_Index (Flag_Location);
336 Prescan_Message (Msg);
337 Orig_Loc := Original_Location (Flag_Location);
339 -- If the current location is in an instantiation, the issue arises of
340 -- whether to post the message on the template or the instantiation.
342 -- The way we decide is to see if we have posted the same message on
343 -- the template when we compiled the template (the template is always
344 -- compiled before any instantiations). For this purpose, we use a
345 -- separate table of messages. The reason we do this is twofold:
347 -- First, the messages can get changed by various processing
348 -- including the insertion of tokens etc, making it hard to
349 -- do the comparison.
351 -- Second, we will suppress a warning on a template if it is not in
352 -- the current extended source unit. That's reasonable and means we
353 -- don't want the warning on the instantiation here either, but it
354 -- does mean that the main error table would not in any case include
355 -- the message.
357 if Flag_Location = Orig_Loc then
358 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
359 Warn_On_Instance := False;
361 -- Here we have an instance message
363 else
364 -- Delete if debug flag off, and this message duplicates a message
365 -- already posted on the corresponding template
367 if not Debug_Flag_GG then
368 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
369 if Msg = Non_Instance_Msgs.Table (J).Msg.all
370 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
371 then
372 return;
373 end if;
374 end loop;
375 end if;
377 -- No duplicate, so error/warning will be posted on instance
379 Warn_On_Instance := Is_Warning_Msg;
380 end if;
382 -- Ignore warning message that is suppressed for this location. Note
383 -- that style checks are not considered warning messages for this
384 -- purpose.
386 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String
387 then
388 return;
390 -- For style messages, check too many messages so far
392 elsif Is_Style_Msg
393 and then Maximum_Messages /= 0
394 and then Warnings_Detected >= Maximum_Messages
395 then
396 return;
397 end if;
399 -- The idea at this stage is that we have two kinds of messages
401 -- First, we have those messages that are to be placed as requested at
402 -- Flag_Location. This includes messages that have nothing to do with
403 -- generics, and also messages placed on generic templates that reflect
404 -- an error in the template itself. For such messages we simply call
405 -- Error_Msg_Internal to place the message in the requested location.
407 if Instantiation (Sindex) = No_Location then
408 Error_Msg_Internal (Msg, Flag_Location, Flag_Location, False);
409 return;
410 end if;
412 -- If we are trying to flag an error in an instantiation, we may have
413 -- a generic contract violation. What we generate in this case is:
415 -- instantiation error at ...
416 -- original error message
418 -- or
420 -- warning: in instantiation at ...
421 -- warning: original warning message
423 -- or
425 -- info: in instantiation at ...
426 -- info: original info message
428 -- All these messages are posted at the location of the top level
429 -- instantiation. If there are nested instantiations, then the
430 -- instantiation error message can be repeated, pointing to each
431 -- of the relevant instantiations.
433 -- Note: the instantiation mechanism is also shared for inlining of
434 -- subprogram bodies when front end inlining is done. In this case the
435 -- messages have the form:
437 -- in inlined body at ...
438 -- original error message
440 -- or
442 -- warning: in inlined body at ...
443 -- warning: original warning message
445 -- or
447 -- info: in inlined body at ...
448 -- info: original info message
450 -- OK, here we have an instantiation error, and we need to generate the
451 -- error on the instantiation, rather than on the template.
453 declare
454 Actual_Error_Loc : Source_Ptr;
455 -- Location of outer level instantiation in instantiation case, or
456 -- just a copy of Flag_Location in the normal case. This is the
457 -- location where all error messages will actually be posted.
459 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
460 -- Save possible location set for caller's message. We need to use
461 -- Error_Msg_Sloc for the location of the instantiation error but we
462 -- have to preserve a possible original value.
464 X : Source_File_Index;
466 Msg_Cont_Status : Boolean;
467 -- Used to label continuation lines in instantiation case with
468 -- proper Msg_Cont status.
470 begin
471 -- Loop to find highest level instantiation, where all error
472 -- messages will be placed.
474 X := Sindex;
475 loop
476 Actual_Error_Loc := Instantiation (X);
477 X := Get_Source_File_Index (Actual_Error_Loc);
478 exit when Instantiation (X) = No_Location;
479 end loop;
481 -- Since we are generating the messages at the instantiation point in
482 -- any case, we do not want the references to the bad lines in the
483 -- instance to be annotated with the location of the instantiation.
485 Suppress_Instance_Location := True;
486 Msg_Cont_Status := False;
488 -- Loop to generate instantiation messages
490 Error_Msg_Sloc := Flag_Location;
491 X := Get_Source_File_Index (Flag_Location);
492 while Instantiation (X) /= No_Location loop
494 -- Suppress instantiation message on continuation lines
496 if Msg (Msg'First) /= '\' then
498 -- Case of inlined body
500 if Inlined_Body (X) then
501 if Is_Info_Msg then
502 Error_Msg_Internal
503 ("info: in inlined body #",
504 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
506 elsif Is_Warning_Msg or Is_Style_Msg then
507 Error_Msg_Internal
508 (Warn_Insertion & "in inlined body #",
509 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
511 else
512 Error_Msg_Internal
513 ("error in inlined body #",
514 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
515 end if;
517 -- Case of generic instantiation
519 else
520 if Is_Info_Msg then
521 Error_Msg_Internal
522 ("info: in instantiation #",
523 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
525 elsif Is_Warning_Msg or else Is_Style_Msg then
526 Error_Msg_Internal
527 (Warn_Insertion & "in instantiation #",
528 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
530 else
531 Error_Msg_Internal
532 ("instantiation error #",
533 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
534 end if;
535 end if;
536 end if;
538 Error_Msg_Sloc := Instantiation (X);
539 X := Get_Source_File_Index (Error_Msg_Sloc);
540 Msg_Cont_Status := True;
541 end loop;
543 Suppress_Instance_Location := False;
544 Error_Msg_Sloc := Save_Error_Msg_Sloc;
546 -- Here we output the original message on the outer instantiation
548 Error_Msg_Internal
549 (Msg, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
550 end;
551 end Error_Msg;
553 --------------------------------
554 -- Error_Msg_Ada_2012_Feature --
555 --------------------------------
557 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
558 begin
559 if Ada_Version < Ada_2012 then
560 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
562 if No (Ada_Version_Pragma) then
563 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
564 else
565 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
566 Error_Msg ("\incompatible with Ada version set#", Loc);
567 end if;
568 end if;
569 end Error_Msg_Ada_2012_Feature;
571 ------------------
572 -- Error_Msg_AP --
573 ------------------
575 procedure Error_Msg_AP (Msg : String) is
576 S1 : Source_Ptr;
577 C : Character;
579 begin
580 -- If we had saved the Scan_Ptr value after scanning the previous
581 -- token, then we would have exactly the right place for putting
582 -- the flag immediately at hand. However, that would add at least
583 -- two instructions to a Scan call *just* to service the possibility
584 -- of an Error_Msg_AP call. So instead we reconstruct that value.
586 -- We have two possibilities, start with Prev_Token_Ptr and skip over
587 -- the current token, which is made harder by the possibility that this
588 -- token may be in error, or start with Token_Ptr and work backwards.
589 -- We used to take the second approach, but it's hard because of
590 -- comments, and harder still because things that look like comments
591 -- can appear inside strings. So now we take the first approach.
593 -- Note: in the case where there is no previous token, Prev_Token_Ptr
594 -- is set to Source_First, which is a reasonable position for the
595 -- error flag in this situation.
597 S1 := Prev_Token_Ptr;
598 C := Source (S1);
600 -- If the previous token is a string literal, we need a special approach
601 -- since there may be white space inside the literal and we don't want
602 -- to stop on that white space.
604 -- Note: since this is an error recovery issue anyway, it is not worth
605 -- worrying about special UTF_32 line terminator characters here.
607 if Prev_Token = Tok_String_Literal then
608 loop
609 S1 := S1 + 1;
611 if Source (S1) = C then
612 S1 := S1 + 1;
613 exit when Source (S1) /= C;
614 elsif Source (S1) in Line_Terminator then
615 exit;
616 end if;
617 end loop;
619 -- Character literal also needs special handling
621 elsif Prev_Token = Tok_Char_Literal then
622 S1 := S1 + 3;
624 -- Otherwise we search forward for the end of the current token, marked
625 -- by a line terminator, white space, a comment symbol or if we bump
626 -- into the following token (i.e. the current token).
628 -- Again, it is not worth worrying about UTF_32 special line terminator
629 -- characters in this context, since this is only for error recovery.
631 else
632 while Source (S1) not in Line_Terminator
633 and then Source (S1) /= ' '
634 and then Source (S1) /= ASCII.HT
635 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
636 and then S1 /= Token_Ptr
637 loop
638 S1 := S1 + 1;
639 end loop;
640 end if;
642 -- S1 is now set to the location for the flag
644 Error_Msg (Msg, S1);
645 end Error_Msg_AP;
647 ------------------
648 -- Error_Msg_BC --
649 ------------------
651 procedure Error_Msg_BC (Msg : String) is
652 begin
653 -- If we are at end of file, post the flag after the previous token
655 if Token = Tok_EOF then
656 Error_Msg_AP (Msg);
658 -- If we are at start of file, post the flag at the current token
660 elsif Token_Ptr = Source_First (Current_Source_File) then
661 Error_Msg_SC (Msg);
663 -- If the character before the current token is a space or a horizontal
664 -- tab, then we place the flag on this character (in the case of a tab
665 -- we would really like to place it in the "last" character of the tab
666 -- space, but that it too much trouble to worry about).
668 elsif Source (Token_Ptr - 1) = ' '
669 or else Source (Token_Ptr - 1) = ASCII.HT
670 then
671 Error_Msg (Msg, Token_Ptr - 1);
673 -- If there is no space or tab before the current token, then there is
674 -- no room to place the flag before the token, so we place it on the
675 -- token instead (this happens for example at the start of a line).
677 else
678 Error_Msg (Msg, Token_Ptr);
679 end if;
680 end Error_Msg_BC;
682 -------------------
683 -- Error_Msg_CRT --
684 -------------------
686 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
687 CNRT : constant String := " not allowed in no run time mode";
688 CCRT : constant String := " not supported by configuration>";
690 S : String (1 .. Feature'Length + 1 + CCRT'Length);
691 L : Natural;
693 begin
694 S (1) := '|';
695 S (2 .. Feature'Length + 1) := Feature;
696 L := Feature'Length + 2;
698 if No_Run_Time_Mode then
699 S (L .. L + CNRT'Length - 1) := CNRT;
700 L := L + CNRT'Length - 1;
702 else pragma Assert (Configurable_Run_Time_Mode);
703 S (L .. L + CCRT'Length - 1) := CCRT;
704 L := L + CCRT'Length - 1;
705 end if;
707 Error_Msg_N (S (1 .. L), N);
708 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
709 end Error_Msg_CRT;
711 ------------------
712 -- Error_Msg_PT --
713 ------------------
715 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
716 begin
717 Error_Msg_N
718 ("illegal overriding of subprogram inherited from interface", E);
720 Error_Msg_Sloc := Sloc (Iface_Prim);
722 if Ekind (E) = E_Function then
723 Error_Msg_N
724 ("\first formal of & declared # must be of mode `IN` "
725 & "or access-to-constant", E);
726 else
727 Error_Msg_N
728 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
729 & "or access-to-variable", E);
730 end if;
731 end Error_Msg_PT;
733 -----------------
734 -- Error_Msg_F --
735 -----------------
737 procedure Error_Msg_F (Msg : String; N : Node_Id) is
738 begin
739 Error_Msg_NEL (Msg, N, N, Sloc (First_Node (N)));
740 end Error_Msg_F;
742 ------------------
743 -- Error_Msg_FE --
744 ------------------
746 procedure Error_Msg_FE
747 (Msg : String;
748 N : Node_Id;
749 E : Node_Or_Entity_Id)
751 begin
752 Error_Msg_NEL (Msg, N, E, Sloc (First_Node (N)));
753 end Error_Msg_FE;
755 ------------------------
756 -- Error_Msg_Internal --
757 ------------------------
759 procedure Error_Msg_Internal
760 (Msg : String;
761 Sptr : Source_Ptr;
762 Optr : Source_Ptr;
763 Msg_Cont : Boolean)
765 Next_Msg : Error_Msg_Id;
766 -- Pointer to next message at insertion point
768 Prev_Msg : Error_Msg_Id;
769 -- Pointer to previous message at insertion point
771 Temp_Msg : Error_Msg_Id;
773 Warn_Err : Boolean;
774 -- Set if warning to be treated as error
776 procedure Handle_Serious_Error;
777 -- Internal procedure to do all error message handling for a serious
778 -- error message, other than bumping the error counts and arranging
779 -- for the message to be output.
781 --------------------------
782 -- Handle_Serious_Error --
783 --------------------------
785 procedure Handle_Serious_Error is
786 begin
787 -- Turn off code generation if not done already
789 if Operating_Mode = Generate_Code then
790 Operating_Mode := Check_Semantics;
791 Expander_Active := False;
792 end if;
794 -- Set the fatal error flag in the unit table unless we are in
795 -- Try_Semantics mode (in which case we set ignored mode if not
796 -- currently set. This stops the semantics from being performed
797 -- if we find a serious error. This is skipped if we are currently
798 -- dealing with the configuration pragma file.
800 if Current_Source_Unit /= No_Unit then
801 declare
802 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
803 begin
804 if Try_Semantics then
805 if Fatal_Error (U) = None then
806 Set_Fatal_Error (U, Error_Ignored);
807 end if;
808 else
809 Set_Fatal_Error (U, Error_Detected);
810 end if;
811 end;
812 end if;
813 end Handle_Serious_Error;
815 -- Start of processing for Error_Msg_Internal
817 begin
818 if Raise_Exception_On_Error /= 0 then
819 raise Error_Msg_Exception;
820 end if;
822 Continuation := Msg_Cont;
823 Continuation_New_Line := False;
824 Suppress_Message := False;
825 Kill_Message := False;
826 Set_Msg_Text (Msg, Sptr);
828 -- Kill continuation if parent message killed
830 if Continuation and Last_Killed then
831 return;
832 end if;
834 -- Return without doing anything if message is suppressed
836 if Suppress_Message
837 and then not All_Errors_Mode
838 and then not Is_Warning_Msg
839 and then not Is_Unconditional_Msg
840 then
841 if not Continuation then
842 Last_Killed := True;
843 end if;
845 return;
846 end if;
848 -- Return without doing anything if message is killed and this is not
849 -- the first error message. The philosophy is that if we get a weird
850 -- error message and we already have had a message, then we hope the
851 -- weird message is a junk cascaded message
853 if Kill_Message
854 and then not All_Errors_Mode
855 and then Total_Errors_Detected /= 0
856 then
857 if not Continuation then
858 Last_Killed := True;
859 end if;
861 return;
862 end if;
864 -- Special check for warning message to see if it should be output
866 if Is_Warning_Msg then
868 -- Immediate return if warning message and warnings are suppressed
870 if Warnings_Suppressed (Optr) /= No_String
871 or else
872 Warnings_Suppressed (Sptr) /= No_String
873 then
874 Cur_Msg := No_Error_Msg;
875 return;
876 end if;
878 -- If the flag location is in the main extended source unit then for
879 -- sure we want the warning since it definitely belongs
881 if In_Extended_Main_Source_Unit (Sptr) then
882 null;
884 -- If the main unit has not been read yet. the warning must be on
885 -- a configuration file: gnat.adc or user-defined. This means we
886 -- are not parsing the main unit yet, so skip following checks.
888 elsif No (Cunit (Main_Unit)) then
889 null;
891 -- If the flag location is not in the main extended source unit, then
892 -- we want to eliminate the warning, unless it is in the extended
893 -- main code unit and we want warnings on the instance.
895 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
896 null;
898 -- Keep warning if debug flag G set
900 elsif Debug_Flag_GG then
901 null;
903 -- Keep warning if message text contains !!
905 elsif Has_Double_Exclam then
906 null;
908 -- Here is where we delete a warning from a with'ed unit
910 else
911 Cur_Msg := No_Error_Msg;
913 if not Continuation then
914 Last_Killed := True;
915 end if;
917 return;
918 end if;
919 end if;
921 -- If message is to be ignored in special ignore message mode, this is
922 -- where we do this special processing, bypassing message output.
924 if Ignore_Errors_Enable > 0 then
925 if Is_Serious_Error then
926 Handle_Serious_Error;
927 end if;
929 return;
930 end if;
932 -- If error message line length set, and this is a continuation message
933 -- then all we do is to append the text to the text of the last message
934 -- with a comma space separator (eliminating a possible (style) or
935 -- info prefix).
937 if Error_Msg_Line_Length /= 0 and then Continuation then
938 Cur_Msg := Errors.Last;
940 declare
941 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
942 Newm : String (1 .. Oldm'Last + 2 + Msglen);
943 Newl : Natural;
944 M : Natural;
946 begin
947 -- First copy old message to new one and free it
949 Newm (Oldm'Range) := Oldm.all;
950 Newl := Oldm'Length;
951 Free (Oldm);
953 -- Remove (style) or info: at start of message
955 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
956 M := 9;
958 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
959 M := 7;
961 else
962 M := 1;
963 end if;
965 -- Now deal with separation between messages. Normally this is
966 -- simply comma space, but there are some special cases.
968 -- If continuation new line, then put actual NL character in msg
970 if Continuation_New_Line then
971 Newl := Newl + 1;
972 Newm (Newl) := ASCII.LF;
974 -- If continuation message is enclosed in parentheses, then
975 -- special treatment (don't need a comma, and we want to combine
976 -- successive parenthetical remarks into a single one with
977 -- separating commas).
979 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
981 -- Case where existing message ends in right paren, remove
982 -- and separate parenthetical remarks with a comma.
984 if Newm (Newl) = ')' then
985 Newm (Newl) := ',';
986 Msg_Buffer (M) := ' ';
988 -- Case where we are adding new parenthetical comment
990 else
991 Newl := Newl + 1;
992 Newm (Newl) := ' ';
993 end if;
995 -- Case where continuation not in parens and no new line
997 else
998 Newm (Newl + 1 .. Newl + 2) := ", ";
999 Newl := Newl + 2;
1000 end if;
1002 -- Append new message
1004 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1005 Msg_Buffer (M .. Msglen);
1006 Newl := Newl + Msglen - M + 1;
1007 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1009 -- Update warning msg flag and message doc char if needed
1011 if Is_Warning_Msg then
1012 if not Errors.Table (Cur_Msg).Warn then
1013 Errors.Table (Cur_Msg).Warn := True;
1014 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1016 elsif Warning_Msg_Char /= ' ' then
1017 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1018 end if;
1019 end if;
1020 end;
1022 return;
1023 end if;
1025 -- Here we build a new error object
1027 Errors.Append
1028 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1029 Next => No_Error_Msg,
1030 Prev => No_Error_Msg,
1031 Sptr => Sptr,
1032 Optr => Optr,
1033 Sfile => Get_Source_File_Index (Sptr),
1034 Line => Get_Physical_Line_Number (Sptr),
1035 Col => Get_Column_Number (Sptr),
1036 Warn => Is_Warning_Msg,
1037 Info => Is_Info_Msg,
1038 Check => Is_Check_Msg,
1039 Warn_Err => False, -- reset below
1040 Warn_Chr => Warning_Msg_Char,
1041 Style => Is_Style_Msg,
1042 Serious => Is_Serious_Error,
1043 Uncond => Is_Unconditional_Msg,
1044 Msg_Cont => Continuation,
1045 Deleted => False));
1046 Cur_Msg := Errors.Last;
1048 -- Test if warning to be treated as error
1050 Warn_Err :=
1051 Is_Warning_Msg
1052 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1053 or else
1054 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
1056 -- Propagate Warn_Err to this message and preceding continuations
1058 for J in reverse 1 .. Errors.Last loop
1059 Errors.Table (J).Warn_Err := Warn_Err;
1060 exit when not Errors.Table (J).Msg_Cont;
1061 end loop;
1063 -- If immediate errors mode set, output error message now. Also output
1064 -- now if the -d1 debug flag is set (so node number message comes out
1065 -- just before actual error message)
1067 if Debug_Flag_OO or else Debug_Flag_1 then
1068 Write_Eol;
1069 Output_Source_Line
1070 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1071 Temp_Msg := Cur_Msg;
1072 Output_Error_Msgs (Temp_Msg);
1074 -- If not in immediate errors mode, then we insert the message in the
1075 -- error chain for later output by Finalize. The messages are sorted
1076 -- first by unit (main unit comes first), and within a unit by source
1077 -- location (earlier flag location first in the chain).
1079 else
1080 -- First a quick check, does this belong at the very end of the chain
1081 -- of error messages. This saves a lot of time in the normal case if
1082 -- there are lots of messages.
1084 if Last_Error_Msg /= No_Error_Msg
1085 and then Errors.Table (Cur_Msg).Sfile =
1086 Errors.Table (Last_Error_Msg).Sfile
1087 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
1088 or else
1089 (Sptr = Errors.Table (Last_Error_Msg).Sptr
1090 and then
1091 Optr > Errors.Table (Last_Error_Msg).Optr))
1092 then
1093 Prev_Msg := Last_Error_Msg;
1094 Next_Msg := No_Error_Msg;
1096 -- Otherwise do a full sequential search for the insertion point
1098 else
1099 Prev_Msg := No_Error_Msg;
1100 Next_Msg := First_Error_Msg;
1101 while Next_Msg /= No_Error_Msg loop
1102 exit when
1103 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1105 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1106 then
1107 exit when Sptr < Errors.Table (Next_Msg).Sptr
1108 or else (Sptr = Errors.Table (Next_Msg).Sptr
1109 and then Optr < Errors.Table (Next_Msg).Optr);
1110 end if;
1112 Prev_Msg := Next_Msg;
1113 Next_Msg := Errors.Table (Next_Msg).Next;
1114 end loop;
1115 end if;
1117 -- Now we insert the new message in the error chain.
1119 -- The possible insertion point for the new message is after Prev_Msg
1120 -- and before Next_Msg. However, this is where we do a special check
1121 -- for redundant parsing messages, defined as messages posted on the
1122 -- same line. The idea here is that probably such messages are junk
1123 -- from the parser recovering. In full errors mode, we don't do this
1124 -- deletion, but otherwise such messages are discarded at this stage.
1126 if Prev_Msg /= No_Error_Msg
1127 and then Errors.Table (Prev_Msg).Line =
1128 Errors.Table (Cur_Msg).Line
1129 and then Errors.Table (Prev_Msg).Sfile =
1130 Errors.Table (Cur_Msg).Sfile
1131 and then Compiler_State = Parsing
1132 and then not All_Errors_Mode
1133 then
1134 -- Don't delete unconditional messages and at this stage, don't
1135 -- delete continuation lines; we attempted to delete those earlier
1136 -- if the parent message was deleted.
1138 if not Errors.Table (Cur_Msg).Uncond
1139 and then not Continuation
1140 then
1141 -- Don't delete if prev msg is warning and new msg is an error.
1142 -- This is because we don't want a real error masked by a
1143 -- warning. In all other cases (that is parse errors for the
1144 -- same line that are not unconditional) we do delete the
1145 -- message. This helps to avoid junk extra messages from
1146 -- cascaded parsing errors
1148 if not (Errors.Table (Prev_Msg).Warn
1149 or else
1150 Errors.Table (Prev_Msg).Style)
1151 or else
1152 (Errors.Table (Cur_Msg).Warn
1153 or else
1154 Errors.Table (Cur_Msg).Style)
1155 then
1156 -- All tests passed, delete the message by simply returning
1157 -- without any further processing.
1159 pragma Assert (not Continuation);
1161 Last_Killed := True;
1162 return;
1163 end if;
1164 end if;
1165 end if;
1167 -- Come here if message is to be inserted in the error chain
1169 if not Continuation then
1170 Last_Killed := False;
1171 end if;
1173 if Prev_Msg = No_Error_Msg then
1174 First_Error_Msg := Cur_Msg;
1175 else
1176 Errors.Table (Prev_Msg).Next := Cur_Msg;
1177 end if;
1179 Errors.Table (Cur_Msg).Next := Next_Msg;
1181 if Next_Msg = No_Error_Msg then
1182 Last_Error_Msg := Cur_Msg;
1183 end if;
1184 end if;
1186 -- Bump appropriate statistics counts
1188 if Errors.Table (Cur_Msg).Info then
1190 -- Could be (usually is) both "info" and "warning"
1192 if Errors.Table (Cur_Msg).Warn then
1193 Warning_Info_Messages := Warning_Info_Messages + 1;
1194 Warnings_Detected := Warnings_Detected + 1;
1195 else
1196 Report_Info_Messages := Report_Info_Messages + 1;
1197 end if;
1199 elsif Errors.Table (Cur_Msg).Warn
1200 or else Errors.Table (Cur_Msg).Style
1201 then
1202 Warnings_Detected := Warnings_Detected + 1;
1204 elsif Errors.Table (Cur_Msg).Check then
1205 Check_Messages := Check_Messages + 1;
1207 else
1208 Total_Errors_Detected := Total_Errors_Detected + 1;
1210 if Errors.Table (Cur_Msg).Serious then
1211 Serious_Errors_Detected := Serious_Errors_Detected + 1;
1212 Handle_Serious_Error;
1214 -- If not serious error, set Fatal_Error to indicate ignored error
1216 else
1217 declare
1218 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1219 begin
1220 if Fatal_Error (U) = None then
1221 Set_Fatal_Error (U, Error_Ignored);
1222 end if;
1223 end;
1224 end if;
1225 end if;
1227 -- Record warning message issued
1229 if Errors.Table (Cur_Msg).Warn
1230 and then not Errors.Table (Cur_Msg).Msg_Cont
1231 then
1232 Warning_Msg := Cur_Msg;
1233 end if;
1235 -- If too many warnings turn off warnings
1237 if Maximum_Messages /= 0 then
1238 if Warnings_Detected = Maximum_Messages then
1239 Warning_Mode := Suppress;
1240 end if;
1242 -- If too many errors abandon compilation
1244 if Total_Errors_Detected = Maximum_Messages then
1245 raise Unrecoverable_Error;
1246 end if;
1247 end if;
1248 end Error_Msg_Internal;
1250 -----------------
1251 -- Error_Msg_N --
1252 -----------------
1254 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1255 begin
1256 Error_Msg_NEL (Msg, N, N, Sloc (N));
1257 end Error_Msg_N;
1259 ------------------
1260 -- Error_Msg_NE --
1261 ------------------
1263 procedure Error_Msg_NE
1264 (Msg : String;
1265 N : Node_Or_Entity_Id;
1266 E : Node_Or_Entity_Id)
1268 begin
1269 Error_Msg_NEL (Msg, N, E, Sloc (N));
1270 end Error_Msg_NE;
1272 -------------------
1273 -- Error_Msg_NEL --
1274 -------------------
1276 procedure Error_Msg_NEL
1277 (Msg : String;
1278 N : Node_Or_Entity_Id;
1279 E : Node_Or_Entity_Id;
1280 Flag_Location : Source_Ptr)
1282 begin
1283 if Special_Msg_Delete (Msg, N, E) then
1284 return;
1285 end if;
1287 Prescan_Message (Msg);
1289 -- Special handling for warning messages
1291 if Is_Warning_Msg then
1293 -- Suppress if no warnings set for either entity or node
1295 if No_Warnings (N) or else No_Warnings (E) then
1297 -- Disable any continuation messages as well
1299 Last_Killed := True;
1300 return;
1301 end if;
1303 -- Suppress if inside loop that is known to be null or is probably
1304 -- null (case where loop executes only if invalid values present).
1305 -- In either case warnings in the loop are likely to be junk.
1307 declare
1308 P : Node_Id;
1310 begin
1311 P := Parent (N);
1312 while Present (P) loop
1313 if Nkind (P) = N_Loop_Statement
1314 and then Suppress_Loop_Warnings (P)
1315 then
1316 return;
1317 end if;
1319 P := Parent (P);
1320 end loop;
1321 end;
1322 end if;
1324 -- Test for message to be output
1326 if All_Errors_Mode
1327 or else Is_Unconditional_Msg
1328 or else Is_Warning_Msg
1329 or else OK_Node (N)
1330 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1331 then
1332 Debug_Output (N);
1333 Error_Msg_Node_1 := E;
1334 Error_Msg (Msg, Flag_Location);
1336 else
1337 Last_Killed := True;
1338 end if;
1340 Set_Posted (N);
1341 end Error_Msg_NEL;
1343 ------------------
1344 -- Error_Msg_NW --
1345 ------------------
1347 procedure Error_Msg_NW
1348 (Eflag : Boolean;
1349 Msg : String;
1350 N : Node_Or_Entity_Id)
1352 begin
1353 if Eflag
1354 and then In_Extended_Main_Source_Unit (N)
1355 and then Comes_From_Source (N)
1356 then
1357 Error_Msg_NEL (Msg, N, N, Sloc (N));
1358 end if;
1359 end Error_Msg_NW;
1361 -----------------
1362 -- Error_Msg_S --
1363 -----------------
1365 procedure Error_Msg_S (Msg : String) is
1366 begin
1367 Error_Msg (Msg, Scan_Ptr);
1368 end Error_Msg_S;
1370 ------------------
1371 -- Error_Msg_SC --
1372 ------------------
1374 procedure Error_Msg_SC (Msg : String) is
1375 begin
1376 -- If we are at end of file, post the flag after the previous token
1378 if Token = Tok_EOF then
1379 Error_Msg_AP (Msg);
1381 -- For all other cases the message is posted at the current token
1382 -- pointer position
1384 else
1385 Error_Msg (Msg, Token_Ptr);
1386 end if;
1387 end Error_Msg_SC;
1389 ------------------
1390 -- Error_Msg_SP --
1391 ------------------
1393 procedure Error_Msg_SP (Msg : String) is
1394 begin
1395 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1396 -- is set to Source_First, which is a reasonable position for the
1397 -- error flag in this situation
1399 Error_Msg (Msg, Prev_Token_Ptr);
1400 end Error_Msg_SP;
1402 --------------
1403 -- Finalize --
1404 --------------
1406 procedure Finalize (Last_Call : Boolean) is
1407 Cur : Error_Msg_Id;
1408 Nxt : Error_Msg_Id;
1409 F : Error_Msg_Id;
1411 procedure Delete_Warning (E : Error_Msg_Id);
1412 -- Delete a warning msg if not already deleted and adjust warning count
1414 --------------------
1415 -- Delete_Warning --
1416 --------------------
1418 procedure Delete_Warning (E : Error_Msg_Id) is
1419 begin
1420 if not Errors.Table (E).Deleted then
1421 Errors.Table (E).Deleted := True;
1422 Warnings_Detected := Warnings_Detected - 1;
1424 if Errors.Table (E).Info then
1425 Warning_Info_Messages := Warning_Info_Messages - 1;
1426 end if;
1428 if Errors.Table (E).Warn_Err then
1429 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
1430 end if;
1431 end if;
1432 end Delete_Warning;
1434 -- Start of processing for Finalize
1436 begin
1437 -- Set Prev pointers
1439 Cur := First_Error_Msg;
1440 while Cur /= No_Error_Msg loop
1441 Nxt := Errors.Table (Cur).Next;
1442 exit when Nxt = No_Error_Msg;
1443 Errors.Table (Nxt).Prev := Cur;
1444 Cur := Nxt;
1445 end loop;
1447 -- Eliminate any duplicated error messages from the list. This is
1448 -- done after the fact to avoid problems with Change_Error_Text.
1450 Cur := First_Error_Msg;
1451 while Cur /= No_Error_Msg loop
1452 Nxt := Errors.Table (Cur).Next;
1454 F := Nxt;
1455 while F /= No_Error_Msg
1456 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1457 loop
1458 Check_Duplicate_Message (Cur, F);
1459 F := Errors.Table (F).Next;
1460 end loop;
1462 Cur := Nxt;
1463 end loop;
1465 -- Mark any messages suppressed by specific warnings as Deleted
1467 Cur := First_Error_Msg;
1468 while Cur /= No_Error_Msg loop
1469 declare
1470 CE : Error_Msg_Object renames Errors.Table (Cur);
1471 Tag : constant String := Get_Warning_Tag (Cur);
1473 begin
1474 if (CE.Warn and not CE.Deleted)
1475 and then
1476 (Warning_Specifically_Suppressed (CE.Sptr, CE.Text, Tag) /=
1477 No_String
1478 or else
1479 Warning_Specifically_Suppressed (CE.Optr, CE.Text, Tag) /=
1480 No_String)
1481 then
1482 Delete_Warning (Cur);
1484 -- If this is a continuation, delete previous parts of message
1486 F := Cur;
1487 while Errors.Table (F).Msg_Cont loop
1488 F := Errors.Table (F).Prev;
1489 exit when F = No_Error_Msg;
1490 Delete_Warning (F);
1491 end loop;
1493 -- Delete any following continuations
1495 F := Cur;
1496 loop
1497 F := Errors.Table (F).Next;
1498 exit when F = No_Error_Msg;
1499 exit when not Errors.Table (F).Msg_Cont;
1500 Delete_Warning (F);
1501 end loop;
1502 end if;
1503 end;
1505 Cur := Errors.Table (Cur).Next;
1506 end loop;
1508 Finalize_Called := True;
1510 -- Check consistency of specific warnings (may add warnings). We only
1511 -- do this on the last call, after all possible warnings are posted.
1513 if Last_Call then
1514 Validate_Specific_Warnings (Error_Msg'Access);
1515 end if;
1516 end Finalize;
1518 ----------------
1519 -- First_Node --
1520 ----------------
1522 function First_Node (C : Node_Id) return Node_Id is
1523 Orig : constant Node_Id := Original_Node (C);
1524 Loc : constant Source_Ptr := Sloc (Orig);
1525 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1526 Earliest : Node_Id;
1527 Eloc : Source_Ptr;
1529 function Test_Earlier (N : Node_Id) return Traverse_Result;
1530 -- Function applied to every node in the construct
1532 procedure Search_Tree_First is new Traverse_Proc (Test_Earlier);
1533 -- Create traversal procedure
1535 ------------------
1536 -- Test_Earlier --
1537 ------------------
1539 function Test_Earlier (N : Node_Id) return Traverse_Result is
1540 Norig : constant Node_Id := Original_Node (N);
1541 Loc : constant Source_Ptr := Sloc (Norig);
1543 begin
1544 -- Check for earlier
1546 if Loc < Eloc
1548 -- Ignore nodes with no useful location information
1550 and then Loc /= Standard_Location
1551 and then Loc /= No_Location
1553 -- Ignore nodes from a different file. This ensures against cases
1554 -- of strange foreign code somehow being present. We don't want
1555 -- wild placement of messages if that happens.
1557 and then Get_Source_File_Index (Loc) = Sfile
1558 then
1559 Earliest := Norig;
1560 Eloc := Loc;
1561 end if;
1563 return OK_Orig;
1564 end Test_Earlier;
1566 -- Start of processing for First_Node
1568 begin
1569 if Nkind (Orig) in N_Subexpr then
1570 Earliest := Orig;
1571 Eloc := Loc;
1572 Search_Tree_First (Orig);
1573 return Earliest;
1575 else
1576 return Orig;
1577 end if;
1578 end First_Node;
1580 ----------------
1581 -- First_Sloc --
1582 ----------------
1584 function First_Sloc (N : Node_Id) return Source_Ptr is
1585 SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1586 SF : constant Source_Ptr := Source_First (SI);
1587 F : Node_Id;
1588 S : Source_Ptr;
1590 begin
1591 F := First_Node (N);
1592 S := Sloc (F);
1594 -- The following circuit is a bit subtle. When we have parenthesized
1595 -- expressions, then the Sloc will not record the location of the paren,
1596 -- but we would like to post the flag on the paren. So what we do is to
1597 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1598 -- any parentheses we know are present. Yes, we know this circuit is not
1599 -- 100% reliable (e.g. because we don't record all possible paren level
1600 -- values), but this is only for an error message so it is good enough.
1602 Node_Loop : loop
1603 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1605 -- We don't look more than 12 characters behind the current
1606 -- location, and in any case not past the front of the source.
1608 Search_Loop : for K in 1 .. 12 loop
1609 exit Search_Loop when S = SF;
1611 if Source_Text (SI) (S - 1) = '(' then
1612 S := S - 1;
1613 exit Search_Loop;
1615 elsif Source_Text (SI) (S - 1) <= ' ' then
1616 S := S - 1;
1618 else
1619 exit Search_Loop;
1620 end if;
1621 end loop Search_Loop;
1622 end loop Paren_Loop;
1624 exit Node_Loop when F = N;
1625 F := Parent (F);
1626 exit Node_Loop when Nkind (F) not in N_Subexpr;
1627 end loop Node_Loop;
1629 return S;
1630 end First_Sloc;
1632 -----------------------
1633 -- Get_Ignore_Errors --
1634 -----------------------
1636 function Get_Ignore_Errors return Boolean is
1637 begin
1638 return Errors_Must_Be_Ignored;
1639 end Get_Ignore_Errors;
1641 ----------------
1642 -- Initialize --
1643 ----------------
1645 procedure Initialize is
1646 begin
1647 Errors.Init;
1648 First_Error_Msg := No_Error_Msg;
1649 Last_Error_Msg := No_Error_Msg;
1650 Serious_Errors_Detected := 0;
1651 Total_Errors_Detected := 0;
1652 Cur_Msg := No_Error_Msg;
1653 List_Pragmas.Init;
1655 -- Reset counts for warnings
1657 Reset_Warnings;
1659 -- Initialize warnings tables
1661 Warnings.Init;
1662 Specific_Warnings.Init;
1663 end Initialize;
1665 -----------------
1666 -- No_Warnings --
1667 -----------------
1669 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1670 begin
1671 if Error_Posted (N) then
1672 return True;
1674 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
1675 return True;
1677 elsif Is_Entity_Name (N)
1678 and then Present (Entity (N))
1679 and then Has_Warnings_Off (Entity (N))
1680 then
1681 return True;
1683 else
1684 return False;
1685 end if;
1686 end No_Warnings;
1688 -------------
1689 -- OK_Node --
1690 -------------
1692 function OK_Node (N : Node_Id) return Boolean is
1693 K : constant Node_Kind := Nkind (N);
1695 begin
1696 if Error_Posted (N) then
1697 return False;
1699 elsif K in N_Has_Etype
1700 and then Present (Etype (N))
1701 and then Error_Posted (Etype (N))
1702 then
1703 return False;
1705 elsif (K in N_Op
1706 or else K = N_Attribute_Reference
1707 or else K = N_Character_Literal
1708 or else K = N_Expanded_Name
1709 or else K = N_Identifier
1710 or else K = N_Operator_Symbol)
1711 and then Present (Entity (N))
1712 and then Error_Posted (Entity (N))
1713 then
1714 return False;
1715 else
1716 return True;
1717 end if;
1718 end OK_Node;
1720 ---------------------
1721 -- Output_Messages --
1722 ---------------------
1724 procedure Output_Messages is
1725 E : Error_Msg_Id;
1726 Err_Flag : Boolean;
1728 procedure Write_Error_Summary;
1729 -- Write error summary
1731 procedure Write_Header (Sfile : Source_File_Index);
1732 -- Write header line (compiling or checking given file)
1734 procedure Write_Max_Errors;
1735 -- Write message if max errors reached
1737 -------------------------
1738 -- Write_Error_Summary --
1739 -------------------------
1741 procedure Write_Error_Summary is
1742 begin
1743 -- Extra blank line if error messages or source listing were output
1745 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
1746 then
1747 Write_Eol;
1748 end if;
1750 -- Message giving number of lines read and number of errors detected.
1751 -- This normally goes to Standard_Output. The exception is when brief
1752 -- mode is not set, verbose mode (or full list mode) is set, and
1753 -- there are errors. In this case we send the message to standard
1754 -- error to make sure that *something* appears on standard error
1755 -- in an error situation.
1757 if Total_Errors_Detected + Warnings_Detected /= 0
1758 and then not Brief_Output
1759 and then (Verbose_Mode or Full_List)
1760 then
1761 Set_Standard_Error;
1762 end if;
1764 -- Message giving total number of lines. Don't give this message if
1765 -- the Main_Source line is unknown (this happens in error situations,
1766 -- e.g. when integrated preprocessing fails).
1768 if Main_Source_File /= No_Source_File then
1769 Write_Str (" ");
1770 Write_Int (Num_Source_Lines (Main_Source_File));
1772 if Num_Source_Lines (Main_Source_File) = 1 then
1773 Write_Str (" line: ");
1774 else
1775 Write_Str (" lines: ");
1776 end if;
1777 end if;
1779 if Total_Errors_Detected = 0 then
1780 Write_Str ("No errors");
1782 elsif Total_Errors_Detected = 1 then
1783 Write_Str ("1 error");
1785 else
1786 Write_Int (Total_Errors_Detected);
1787 Write_Str (" errors");
1788 end if;
1790 if Warnings_Detected - Warning_Info_Messages /= 0 then
1791 Write_Str (", ");
1792 Write_Int (Warnings_Detected);
1793 Write_Str (" warning");
1795 if Warnings_Detected - Warning_Info_Messages /= 1 then
1796 Write_Char ('s');
1797 end if;
1799 if Warning_Mode = Treat_As_Error then
1800 Write_Str (" (treated as error");
1802 if Warnings_Detected /= 1 then
1803 Write_Char ('s');
1804 end if;
1806 Write_Char (')');
1808 elsif Warnings_Treated_As_Errors /= 0 then
1809 Write_Str (" (");
1810 Write_Int (Warnings_Treated_As_Errors);
1811 Write_Str (" treated as errors)");
1812 end if;
1813 end if;
1815 if Warning_Info_Messages + Report_Info_Messages /= 0 then
1816 Write_Str (", ");
1817 Write_Int (Warning_Info_Messages + Report_Info_Messages);
1818 Write_Str (" info message");
1820 if Warning_Info_Messages + Report_Info_Messages > 1 then
1821 Write_Char ('s');
1822 end if;
1823 end if;
1825 Write_Eol;
1826 Set_Standard_Output;
1827 end Write_Error_Summary;
1829 ------------------
1830 -- Write_Header --
1831 ------------------
1833 procedure Write_Header (Sfile : Source_File_Index) is
1834 begin
1835 if Verbose_Mode or Full_List then
1836 if Original_Operating_Mode = Generate_Code then
1837 Write_Str ("Compiling: ");
1838 else
1839 Write_Str ("Checking: ");
1840 end if;
1842 Write_Name (Full_File_Name (Sfile));
1844 if not Debug_Flag_7 then
1845 Write_Eol;
1846 Write_Str ("Source file time stamp: ");
1847 Write_Time_Stamp (Sfile);
1848 Write_Eol;
1849 Write_Str ("Compiled at: " & Compilation_Time);
1850 end if;
1852 Write_Eol;
1853 end if;
1854 end Write_Header;
1856 ----------------------
1857 -- Write_Max_Errors --
1858 ----------------------
1860 procedure Write_Max_Errors is
1861 begin
1862 if Maximum_Messages /= 0 then
1863 if Warnings_Detected >= Maximum_Messages then
1864 Set_Standard_Error;
1865 Write_Line ("maximum number of warnings output");
1866 Write_Line ("any further warnings suppressed");
1867 Set_Standard_Output;
1868 end if;
1870 -- If too many errors print message
1872 if Total_Errors_Detected >= Maximum_Messages then
1873 Set_Standard_Error;
1874 Write_Line ("fatal error: maximum number of errors detected");
1875 Set_Standard_Output;
1876 end if;
1877 end if;
1878 end Write_Max_Errors;
1880 -- Start of processing for Output_Messages
1882 begin
1883 -- Error if Finalize has not been called
1885 if not Finalize_Called then
1886 raise Program_Error;
1887 end if;
1889 -- Reset current error source file if the main unit has a pragma
1890 -- Source_Reference. This ensures outputting the proper name of
1891 -- the source file in this situation.
1893 if Main_Source_File = No_Source_File
1894 or else Num_SRef_Pragmas (Main_Source_File) /= 0
1895 then
1896 Current_Error_Source_File := No_Source_File;
1897 end if;
1899 -- Brief Error mode
1901 if Brief_Output or (not Full_List and not Verbose_Mode) then
1902 Set_Standard_Error;
1904 E := First_Error_Msg;
1905 while E /= No_Error_Msg loop
1906 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1907 if Full_Path_Name_For_Brief_Errors then
1908 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1909 else
1910 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1911 end if;
1913 Write_Char (':');
1914 Write_Int (Int (Physical_To_Logical
1915 (Errors.Table (E).Line,
1916 Errors.Table (E).Sfile)));
1917 Write_Char (':');
1919 if Errors.Table (E).Col < 10 then
1920 Write_Char ('0');
1921 end if;
1923 Write_Int (Int (Errors.Table (E).Col));
1924 Write_Str (": ");
1925 Output_Msg_Text (E);
1926 Write_Eol;
1927 end if;
1929 E := Errors.Table (E).Next;
1930 end loop;
1932 Set_Standard_Output;
1933 end if;
1935 -- Full source listing case
1937 if Full_List then
1938 List_Pragmas_Index := 1;
1939 List_Pragmas_Mode := True;
1940 E := First_Error_Msg;
1942 -- Normal case, to stdout (copyright notice already output)
1944 if Full_List_File_Name = null then
1945 if not Debug_Flag_7 then
1946 Write_Eol;
1947 end if;
1949 -- Output to file
1951 else
1952 Create_List_File_Access.all (Full_List_File_Name.all);
1953 Set_Special_Output (Write_List_Info_Access.all'Access);
1955 -- Write copyright notice to file
1957 if not Debug_Flag_7 then
1958 Write_Str ("GNAT ");
1959 Write_Str (Gnat_Version_String);
1960 Write_Eol;
1961 Write_Str ("Copyright 1992-" &
1962 Current_Year &
1963 ", Free Software Foundation, Inc.");
1964 Write_Eol;
1965 end if;
1966 end if;
1968 -- First list extended main source file units with errors
1970 for U in Main_Unit .. Last_Unit loop
1971 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
1973 -- If debug flag d.m is set, only the main source is listed
1975 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
1977 -- If the unit of the entity does not come from source, it is
1978 -- an implicit subprogram declaration for a child subprogram.
1979 -- Do not emit errors for it, they are listed with the body.
1981 and then
1982 (No (Cunit_Entity (U))
1983 or else Comes_From_Source (Cunit_Entity (U))
1984 or else not Is_Subprogram (Cunit_Entity (U)))
1986 -- If the compilation unit associated with this unit does not
1987 -- come from source, it means it is an instantiation that should
1988 -- not be included in the source listing.
1990 and then Comes_From_Source (Cunit (U))
1991 then
1992 declare
1993 Sfile : constant Source_File_Index := Source_Index (U);
1995 begin
1996 Write_Eol;
1998 -- Only write the header if Sfile is known
2000 if Sfile /= No_Source_File then
2001 Write_Header (Sfile);
2002 Write_Eol;
2003 end if;
2005 -- Normally, we don't want an "error messages from file"
2006 -- message when listing the entire file, so we set the
2007 -- current source file as the current error source file.
2008 -- However, the old style of doing things was to list this
2009 -- message if pragma Source_Reference is present, even for
2010 -- the main unit. Since the purpose of the -gnatd.m switch
2011 -- is to duplicate the old behavior, we skip the reset if
2012 -- this debug flag is set.
2014 if not Debug_Flag_Dot_M then
2015 Current_Error_Source_File := Sfile;
2016 end if;
2018 -- Only output the listing if Sfile is known, to avoid
2019 -- crashing the compiler.
2021 if Sfile /= No_Source_File then
2022 for N in 1 .. Last_Source_Line (Sfile) loop
2023 while E /= No_Error_Msg
2024 and then Errors.Table (E).Deleted
2025 loop
2026 E := Errors.Table (E).Next;
2027 end loop;
2029 Err_Flag :=
2030 E /= No_Error_Msg
2031 and then Errors.Table (E).Line = N
2032 and then Errors.Table (E).Sfile = Sfile;
2034 Output_Source_Line (N, Sfile, Err_Flag);
2036 if Err_Flag then
2037 Output_Error_Msgs (E);
2039 if not Debug_Flag_2 then
2040 Write_Eol;
2041 end if;
2042 end if;
2043 end loop;
2044 end if;
2045 end;
2046 end if;
2047 end loop;
2049 -- Then output errors, if any, for subsidiary units not in the
2050 -- main extended unit.
2052 -- Note: if debug flag d.m set, include errors for any units other
2053 -- than the main unit in the extended source unit (e.g. spec and
2054 -- subunits for a body).
2056 while E /= No_Error_Msg
2057 and then (not In_Extended_Main_Source_Unit (Errors.Table (E).Sptr)
2058 or else
2059 (Debug_Flag_Dot_M
2060 and then Get_Source_Unit
2061 (Errors.Table (E).Sptr) /= Main_Unit))
2062 loop
2063 if Errors.Table (E).Deleted then
2064 E := Errors.Table (E).Next;
2066 else
2067 Write_Eol;
2068 Output_Source_Line
2069 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
2070 Output_Error_Msgs (E);
2071 end if;
2072 end loop;
2074 -- If output to file, write extra copy of error summary to the
2075 -- output file, and then close it.
2077 if Full_List_File_Name /= null then
2078 Write_Error_Summary;
2079 Write_Max_Errors;
2080 Close_List_File_Access.all;
2081 Cancel_Special_Output;
2082 end if;
2083 end if;
2085 -- Verbose mode (error lines only with error flags). Normally this is
2086 -- ignored in full list mode, unless we are listing to a file, in which
2087 -- case we still generate -gnatv output to standard output.
2089 if Verbose_Mode
2090 and then (not Full_List or else Full_List_File_Name /= null)
2091 then
2092 Write_Eol;
2094 -- Output the header only when Main_Source_File is known
2096 if Main_Source_File /= No_Source_File then
2097 Write_Header (Main_Source_File);
2098 end if;
2100 E := First_Error_Msg;
2102 -- Loop through error lines
2104 while E /= No_Error_Msg loop
2105 if Errors.Table (E).Deleted then
2106 E := Errors.Table (E).Next;
2107 else
2108 Write_Eol;
2109 Output_Source_Line
2110 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
2111 Output_Error_Msgs (E);
2112 end if;
2113 end loop;
2114 end if;
2116 -- Output error summary if verbose or full list mode
2118 if Verbose_Mode or else Full_List then
2119 Write_Error_Summary;
2120 end if;
2122 Write_Max_Errors;
2124 -- Even though Warning_Info_Messages are a subclass of warnings, they
2125 -- must not be treated as errors when -gnatwe is in effect.
2127 if Warning_Mode = Treat_As_Error then
2128 Total_Errors_Detected :=
2129 Total_Errors_Detected + Warnings_Detected - Warning_Info_Messages;
2130 Warnings_Detected := Warning_Info_Messages;
2131 end if;
2132 end Output_Messages;
2134 ------------------------
2135 -- Output_Source_Line --
2136 ------------------------
2138 procedure Output_Source_Line
2139 (L : Physical_Line_Number;
2140 Sfile : Source_File_Index;
2141 Errs : Boolean)
2143 S : Source_Ptr;
2144 C : Character;
2146 Line_Number_Output : Boolean := False;
2147 -- Set True once line number is output
2149 Empty_Line : Boolean := True;
2150 -- Set False if line includes at least one character
2152 begin
2153 if Sfile /= Current_Error_Source_File then
2154 Write_Str ("==============Error messages for ");
2156 case Sinput.File_Type (Sfile) is
2157 when Sinput.Src =>
2158 Write_Str ("source");
2160 when Sinput.Config =>
2161 Write_Str ("configuration pragmas");
2163 when Sinput.Def =>
2164 Write_Str ("symbol definition");
2166 when Sinput.Preproc =>
2167 Write_Str ("preprocessing data");
2168 end case;
2170 Write_Str (" file: ");
2171 Write_Name (Full_File_Name (Sfile));
2172 Write_Eol;
2174 if Num_SRef_Pragmas (Sfile) > 0 then
2175 Write_Str ("--------------Line numbers from file: ");
2176 Write_Name (Full_Ref_Name (Sfile));
2177 Write_Str (" (starting at line ");
2178 Write_Int (Int (First_Mapped_Line (Sfile)));
2179 Write_Char (')');
2180 Write_Eol;
2181 end if;
2183 Current_Error_Source_File := Sfile;
2184 end if;
2186 if Errs or List_Pragmas_Mode then
2187 Output_Line_Number (Physical_To_Logical (L, Sfile));
2188 Line_Number_Output := True;
2189 end if;
2191 S := Line_Start (L, Sfile);
2193 loop
2194 C := Source_Text (Sfile) (S);
2195 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
2197 -- Deal with matching entry in List_Pragmas table
2199 if Full_List
2200 and then List_Pragmas_Index <= List_Pragmas.Last
2201 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
2202 then
2203 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
2204 when Page =>
2205 Write_Char (C);
2207 -- Ignore if on line with errors so that error flags
2208 -- get properly listed with the error line .
2210 if not Errs then
2211 Write_Char (ASCII.FF);
2212 end if;
2214 when List_On =>
2215 List_Pragmas_Mode := True;
2217 if not Line_Number_Output then
2218 Output_Line_Number (Physical_To_Logical (L, Sfile));
2219 Line_Number_Output := True;
2220 end if;
2222 Write_Char (C);
2224 when List_Off =>
2225 Write_Char (C);
2226 List_Pragmas_Mode := False;
2227 end case;
2229 List_Pragmas_Index := List_Pragmas_Index + 1;
2231 -- Normal case (no matching entry in List_Pragmas table)
2233 else
2234 if Errs or List_Pragmas_Mode then
2235 Write_Char (C);
2236 end if;
2237 end if;
2239 Empty_Line := False;
2240 S := S + 1;
2241 end loop;
2243 -- If we have output a source line, then add the line terminator, with
2244 -- training spaces preserved (so we output the line exactly as input).
2246 if Line_Number_Output then
2247 if Empty_Line then
2248 Write_Eol;
2249 else
2250 Write_Eol_Keep_Blanks;
2251 end if;
2252 end if;
2253 end Output_Source_Line;
2255 -----------------------------
2256 -- Remove_Warning_Messages --
2257 -----------------------------
2259 procedure Remove_Warning_Messages (N : Node_Id) is
2261 function Check_For_Warning (N : Node_Id) return Traverse_Result;
2262 -- This function checks one node for a possible warning message
2264 function Check_All_Warnings is new Traverse_Func (Check_For_Warning);
2265 -- This defines the traversal operation
2267 -----------------------
2268 -- Check_For_Warning --
2269 -----------------------
2271 function Check_For_Warning (N : Node_Id) return Traverse_Result is
2272 Loc : constant Source_Ptr := Sloc (N);
2273 E : Error_Msg_Id;
2275 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
2276 -- Returns True for a message that is to be removed. Also adjusts
2277 -- warning count appropriately.
2279 -------------------
2280 -- To_Be_Removed --
2281 -------------------
2283 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
2284 begin
2285 if E /= No_Error_Msg
2287 -- Don't remove if location does not match
2289 and then Errors.Table (E).Optr = Loc
2291 -- Don't remove if not warning/info message. Note that we do
2292 -- not remove style messages here. They are warning messages
2293 -- but not ones we want removed in this context.
2295 and then Errors.Table (E).Warn
2297 -- Don't remove unconditional messages
2299 and then not Errors.Table (E).Uncond
2300 then
2301 Warnings_Detected := Warnings_Detected - 1;
2303 if Errors.Table (E).Info then
2304 Warning_Info_Messages := Warning_Info_Messages - 1;
2305 end if;
2307 return True;
2309 -- No removal required
2311 else
2312 return False;
2313 end if;
2314 end To_Be_Removed;
2316 -- Start of processing for Check_For_Warnings
2318 begin
2319 while To_Be_Removed (First_Error_Msg) loop
2320 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
2321 end loop;
2323 if First_Error_Msg = No_Error_Msg then
2324 Last_Error_Msg := No_Error_Msg;
2325 end if;
2327 E := First_Error_Msg;
2328 while E /= No_Error_Msg loop
2329 while To_Be_Removed (Errors.Table (E).Next) loop
2330 Errors.Table (E).Next :=
2331 Errors.Table (Errors.Table (E).Next).Next;
2333 if Errors.Table (E).Next = No_Error_Msg then
2334 Last_Error_Msg := E;
2335 end if;
2336 end loop;
2338 E := Errors.Table (E).Next;
2339 end loop;
2341 if Nkind (N) = N_Raise_Constraint_Error
2342 and then Original_Node (N) /= N
2343 and then No (Condition (N))
2344 then
2345 -- Warnings may have been posted on subexpressions of the original
2346 -- tree. We place the original node back on the tree to remove
2347 -- those warnings, whose sloc do not match those of any node in
2348 -- the current tree. Given that we are in unreachable code, this
2349 -- modification to the tree is harmless.
2351 declare
2352 Status : Traverse_Final_Result;
2354 begin
2355 if Is_List_Member (N) then
2356 Set_Condition (N, Original_Node (N));
2357 Status := Check_All_Warnings (Condition (N));
2358 else
2359 Rewrite (N, Original_Node (N));
2360 Status := Check_All_Warnings (N);
2361 end if;
2363 return Status;
2364 end;
2366 else
2367 return OK;
2368 end if;
2369 end Check_For_Warning;
2371 -- Start of processing for Remove_Warning_Messages
2373 begin
2374 if Warnings_Detected /= 0 then
2375 declare
2376 Discard : Traverse_Final_Result;
2377 pragma Warnings (Off, Discard);
2379 begin
2380 Discard := Check_All_Warnings (N);
2381 end;
2382 end if;
2383 end Remove_Warning_Messages;
2385 procedure Remove_Warning_Messages (L : List_Id) is
2386 Stat : Node_Id;
2387 begin
2388 if Is_Non_Empty_List (L) then
2389 Stat := First (L);
2390 while Present (Stat) loop
2391 Remove_Warning_Messages (Stat);
2392 Next (Stat);
2393 end loop;
2394 end if;
2395 end Remove_Warning_Messages;
2397 --------------------
2398 -- Reset_Warnings --
2399 --------------------
2401 procedure Reset_Warnings is
2402 begin
2403 Warnings_Treated_As_Errors := 0;
2404 Warnings_Detected := 0;
2405 Warning_Info_Messages := 0;
2406 Warnings_As_Errors_Count := 0;
2407 end Reset_Warnings;
2409 ----------------------
2410 -- Adjust_Name_Case --
2411 ----------------------
2413 procedure Adjust_Name_Case
2414 (Buf : in out Bounded_String;
2415 Loc : Source_Ptr)
2417 begin
2418 -- We have an all lower case name from Namet, and now we want to set
2419 -- the appropriate case. If possible we copy the actual casing from
2420 -- the source. If not we use standard identifier casing.
2422 declare
2423 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
2424 Sbuffer : Source_Buffer_Ptr;
2425 Ref_Ptr : Integer;
2426 Src_Ptr : Source_Ptr;
2428 begin
2429 Ref_Ptr := 1;
2430 Src_Ptr := Loc;
2432 -- For standard locations, always use mixed case
2434 if Loc <= No_Location then
2435 Set_Casing (Mixed_Case);
2437 else
2438 -- Determine if the reference we are dealing with corresponds to
2439 -- text at the point of the error reference. This will often be
2440 -- the case for simple identifier references, and is the case
2441 -- where we can copy the casing from the source.
2443 Sbuffer := Source_Text (Src_Ind);
2445 while Ref_Ptr <= Buf.Length loop
2446 exit when
2447 Fold_Lower (Sbuffer (Src_Ptr)) /=
2448 Fold_Lower (Buf.Chars (Ref_Ptr));
2449 Ref_Ptr := Ref_Ptr + 1;
2450 Src_Ptr := Src_Ptr + 1;
2451 end loop;
2453 -- If we get through the loop without a mismatch, then output the
2454 -- name the way it is cased in the source program
2456 if Ref_Ptr > Buf.Length then
2457 Src_Ptr := Loc;
2459 for J in 1 .. Buf.Length loop
2460 Buf.Chars (J) := Sbuffer (Src_Ptr);
2461 Src_Ptr := Src_Ptr + 1;
2462 end loop;
2464 -- Otherwise set the casing using the default identifier casing
2466 else
2467 Set_Casing (Buf, Identifier_Casing (Src_Ind));
2468 end if;
2469 end if;
2470 end;
2471 end Adjust_Name_Case;
2473 procedure Adjust_Name_Case (Loc : Source_Ptr) is
2474 begin
2475 Adjust_Name_Case (Global_Name_Buffer, Loc);
2476 end Adjust_Name_Case;
2478 ---------------------------
2479 -- Set_Identifier_Casing --
2480 ---------------------------
2482 procedure Set_Identifier_Casing
2483 (Identifier_Name : System.Address;
2484 File_Name : System.Address)
2486 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
2487 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
2488 Flen : Natural;
2490 Desired_Case : Casing_Type := Mixed_Case;
2491 -- Casing required for result. Default value of Mixed_Case is used if
2492 -- for some reason we cannot find the right file name in the table.
2494 begin
2495 -- Get length of file name
2497 Flen := 0;
2498 while File (Flen + 1) /= ASCII.NUL loop
2499 Flen := Flen + 1;
2500 end loop;
2502 -- Loop through file names to find matching one. This is a bit slow, but
2503 -- we only do it in error situations so it is not so terrible. Note that
2504 -- if the loop does not exit, then the desired case will be left set to
2505 -- Mixed_Case, this can happen if the name was not in canonical form.
2507 for J in 1 .. Last_Source_File loop
2508 Get_Name_String (Full_Debug_Name (J));
2510 if Name_Len = Flen
2511 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
2512 then
2513 Desired_Case := Identifier_Casing (J);
2514 exit;
2515 end if;
2516 end loop;
2518 -- Copy identifier as given to Name_Buffer
2520 for J in Name_Buffer'Range loop
2521 Name_Buffer (J) := Ident (J);
2523 if Name_Buffer (J) = ASCII.NUL then
2524 Name_Len := J - 1;
2525 exit;
2526 end if;
2527 end loop;
2529 Set_Casing (Desired_Case);
2530 end Set_Identifier_Casing;
2532 -----------------------
2533 -- Set_Ignore_Errors --
2534 -----------------------
2536 procedure Set_Ignore_Errors (To : Boolean) is
2537 begin
2538 Errors_Must_Be_Ignored := To;
2539 end Set_Ignore_Errors;
2541 ------------------------------
2542 -- Set_Msg_Insertion_Column --
2543 ------------------------------
2545 procedure Set_Msg_Insertion_Column is
2546 begin
2547 if RM_Column_Check then
2548 Set_Msg_Str (" in column ");
2549 Set_Msg_Int (Int (Error_Msg_Col) + 1);
2550 end if;
2551 end Set_Msg_Insertion_Column;
2553 ----------------------------
2554 -- Set_Msg_Insertion_Node --
2555 ----------------------------
2557 procedure Set_Msg_Insertion_Node is
2558 K : Node_Kind;
2560 begin
2561 Suppress_Message :=
2562 Error_Msg_Node_1 = Error
2563 or else Error_Msg_Node_1 = Any_Type;
2565 if Error_Msg_Node_1 = Empty then
2566 Set_Msg_Blank_Conditional;
2567 Set_Msg_Str ("<empty>");
2569 elsif Error_Msg_Node_1 = Error then
2570 Set_Msg_Blank;
2571 Set_Msg_Str ("<error>");
2573 elsif Error_Msg_Node_1 = Standard_Void_Type then
2574 Set_Msg_Blank;
2575 Set_Msg_Str ("procedure name");
2577 elsif Nkind (Error_Msg_Node_1) in N_Entity
2578 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
2579 then
2580 Set_Msg_Blank;
2581 Set_Msg_Str ("access to subprogram");
2583 else
2584 Set_Msg_Blank_Conditional;
2586 -- Output name
2588 K := Nkind (Error_Msg_Node_1);
2590 -- If we have operator case, skip quotes since name of operator
2591 -- itself will supply the required quotations. An operator can be an
2592 -- applied use in an expression or an explicit operator symbol, or an
2593 -- identifier whose name indicates it is an operator.
2595 if K in N_Op
2596 or else K = N_Operator_Symbol
2597 or else K = N_Defining_Operator_Symbol
2598 or else ((K = N_Identifier or else K = N_Defining_Identifier)
2599 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
2600 then
2601 Set_Msg_Node (Error_Msg_Node_1);
2603 -- Normal case, not an operator, surround with quotes
2605 else
2606 Set_Msg_Quote;
2607 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
2608 Set_Msg_Node (Error_Msg_Node_1);
2609 Set_Msg_Quote;
2610 end if;
2611 end if;
2613 -- The following assignment ensures that a second ampersand insertion
2614 -- character will correspond to the Error_Msg_Node_2 parameter. We
2615 -- suppress possible validity checks in case operating in -gnatVa mode,
2616 -- and Error_Msg_Node_2 is not needed and has not been set.
2618 declare
2619 pragma Suppress (Range_Check);
2620 begin
2621 Error_Msg_Node_1 := Error_Msg_Node_2;
2622 end;
2623 end Set_Msg_Insertion_Node;
2625 --------------------------------------
2626 -- Set_Msg_Insertion_Type_Reference --
2627 --------------------------------------
2629 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
2630 Ent : Entity_Id;
2632 begin
2633 Set_Msg_Blank;
2635 if Error_Msg_Node_1 = Standard_Void_Type then
2636 Set_Msg_Str ("package or procedure name");
2637 return;
2639 elsif Error_Msg_Node_1 = Standard_Exception_Type then
2640 Set_Msg_Str ("exception name");
2641 return;
2643 elsif Error_Msg_Node_1 = Any_Access
2644 or else Error_Msg_Node_1 = Any_Array
2645 or else Error_Msg_Node_1 = Any_Boolean
2646 or else Error_Msg_Node_1 = Any_Character
2647 or else Error_Msg_Node_1 = Any_Composite
2648 or else Error_Msg_Node_1 = Any_Discrete
2649 or else Error_Msg_Node_1 = Any_Fixed
2650 or else Error_Msg_Node_1 = Any_Integer
2651 or else Error_Msg_Node_1 = Any_Modular
2652 or else Error_Msg_Node_1 = Any_Numeric
2653 or else Error_Msg_Node_1 = Any_Real
2654 or else Error_Msg_Node_1 = Any_Scalar
2655 or else Error_Msg_Node_1 = Any_String
2656 then
2657 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
2658 Set_Msg_Name_Buffer;
2659 return;
2661 elsif Error_Msg_Node_1 = Universal_Real then
2662 Set_Msg_Str ("type universal real");
2663 return;
2665 elsif Error_Msg_Node_1 = Universal_Integer then
2666 Set_Msg_Str ("type universal integer");
2667 return;
2669 elsif Error_Msg_Node_1 = Universal_Fixed then
2670 Set_Msg_Str ("type universal fixed");
2671 return;
2672 end if;
2674 -- Special case of anonymous array
2676 if Nkind (Error_Msg_Node_1) in N_Entity
2677 and then Is_Array_Type (Error_Msg_Node_1)
2678 and then Present (Related_Array_Object (Error_Msg_Node_1))
2679 then
2680 Set_Msg_Str ("type of ");
2681 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
2682 Set_Msg_Str (" declared");
2683 Set_Msg_Insertion_Line_Number
2684 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
2685 return;
2686 end if;
2688 -- If we fall through, it is not a special case, so first output
2689 -- the name of the type, preceded by private for a private type
2691 if Is_Private_Type (Error_Msg_Node_1) then
2692 Set_Msg_Str ("private type ");
2693 else
2694 Set_Msg_Str ("type ");
2695 end if;
2697 Ent := Error_Msg_Node_1;
2699 if Is_Internal_Name (Chars (Ent)) then
2700 Unwind_Internal_Type (Ent);
2701 end if;
2703 -- Types in Standard are displayed as "Standard.name"
2705 if Sloc (Ent) <= Standard_Location then
2706 Set_Msg_Quote;
2707 Set_Msg_Str ("Standard.");
2708 Set_Msg_Node (Ent);
2709 Add_Class;
2710 Set_Msg_Quote;
2712 -- Types in other language defined units are displayed as
2713 -- "package-name.type-name"
2715 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
2716 Get_Unqualified_Decoded_Name_String
2717 (Unit_Name (Get_Source_Unit (Ent)));
2718 Name_Len := Name_Len - 2;
2719 Set_Msg_Blank_Conditional;
2720 Set_Msg_Quote;
2721 Set_Casing (Mixed_Case);
2722 Set_Msg_Name_Buffer;
2723 Set_Msg_Char ('.');
2724 Set_Casing (Mixed_Case);
2725 Set_Msg_Node (Ent);
2726 Add_Class;
2727 Set_Msg_Quote;
2729 -- All other types display as "type name" defined at line xxx
2730 -- possibly qualified if qualification is requested.
2732 else
2733 Set_Msg_Quote;
2734 Set_Qualification (Error_Msg_Qual_Level, Ent);
2735 Set_Msg_Node (Ent);
2736 Add_Class;
2738 -- If we did not print a name (e.g. in the case of an anonymous
2739 -- subprogram type), there is no name to print, so remove quotes.
2741 if Buffer_Ends_With ('"') then
2742 Buffer_Remove ('"');
2743 else
2744 Set_Msg_Quote;
2745 end if;
2746 end if;
2748 -- If the original type did not come from a predefined file, add the
2749 -- location where the type was defined.
2751 if Sloc (Error_Msg_Node_1) > Standard_Location
2752 and then
2753 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
2754 then
2755 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
2756 Set_Msg_Str (" defined");
2757 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
2759 -- If it did come from a predefined file, deal with the case where
2760 -- this was a file with a generic instantiation from elsewhere.
2762 else
2763 if Sloc (Error_Msg_Node_1) > Standard_Location then
2764 declare
2765 Iloc : constant Source_Ptr :=
2766 Instantiation_Location (Sloc (Error_Msg_Node_1));
2768 begin
2769 if Iloc /= No_Location
2770 and then not Suppress_Instance_Location
2771 then
2772 Set_Msg_Str (" from instance");
2773 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2774 end if;
2775 end;
2776 end if;
2777 end if;
2778 end Set_Msg_Insertion_Type_Reference;
2780 ---------------------------------
2781 -- Set_Msg_Insertion_Unit_Name --
2782 ---------------------------------
2784 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
2785 begin
2786 if Error_Msg_Unit_1 = No_Unit_Name then
2787 null;
2789 elsif Error_Msg_Unit_1 = Error_Unit_Name then
2790 Set_Msg_Blank;
2791 Set_Msg_Str ("<error>");
2793 else
2794 Get_Unit_Name_String (Error_Msg_Unit_1, Suffix);
2795 Set_Msg_Blank;
2796 Set_Msg_Quote;
2797 Set_Msg_Name_Buffer;
2798 Set_Msg_Quote;
2799 end if;
2801 -- The following assignment ensures that a second percent insertion
2802 -- character will correspond to the Error_Msg_Unit_2 parameter. We
2803 -- suppress possible validity checks in case operating in -gnatVa mode,
2804 -- and Error_Msg_Unit_2 is not needed and has not been set.
2806 declare
2807 pragma Suppress (Range_Check);
2808 begin
2809 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2810 end;
2811 end Set_Msg_Insertion_Unit_Name;
2813 ------------------
2814 -- Set_Msg_Node --
2815 ------------------
2817 procedure Set_Msg_Node (Node : Node_Id) is
2818 Loc : Source_Ptr;
2819 Ent : Entity_Id;
2820 Nam : Name_Id;
2822 begin
2823 case Nkind (Node) is
2824 when N_Designator =>
2825 Set_Msg_Node (Name (Node));
2826 Set_Msg_Char ('.');
2827 Set_Msg_Node (Identifier (Node));
2828 return;
2830 when N_Defining_Program_Unit_Name =>
2831 Set_Msg_Node (Name (Node));
2832 Set_Msg_Char ('.');
2833 Set_Msg_Node (Defining_Identifier (Node));
2834 return;
2836 when N_Expanded_Name
2837 | N_Selected_Component
2839 Set_Msg_Node (Prefix (Node));
2840 Set_Msg_Char ('.');
2841 Set_Msg_Node (Selector_Name (Node));
2842 return;
2844 when others =>
2845 null;
2846 end case;
2848 -- The only remaining possibilities are identifiers, defining
2849 -- identifiers, pragmas, and pragma argument associations.
2851 if Nkind (Node) = N_Pragma then
2852 Nam := Pragma_Name (Node);
2853 Loc := Sloc (Node);
2855 -- The other cases have Chars fields
2857 -- First deal with internal names, which generally represent something
2858 -- gone wrong. First attempt: if this is a rewritten node that rewrites
2859 -- something with a Chars field that is not an internal name, use that.
2861 elsif Is_Internal_Name (Chars (Node))
2862 and then Nkind (Original_Node (Node)) in N_Has_Chars
2863 and then not Is_Internal_Name (Chars (Original_Node (Node)))
2864 then
2865 Nam := Chars (Original_Node (Node));
2866 Loc := Sloc (Original_Node (Node));
2868 -- Another shot for internal names, in the case of internal type names,
2869 -- we try to find a reasonable representation for the external name.
2871 elsif Is_Internal_Name (Chars (Node))
2872 and then
2873 ((Is_Entity_Name (Node)
2874 and then Present (Entity (Node))
2875 and then Is_Type (Entity (Node)))
2876 or else
2877 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2878 then
2879 if Nkind (Node) = N_Identifier then
2880 Ent := Entity (Node);
2881 else
2882 Ent := Node;
2883 end if;
2885 Loc := Sloc (Ent);
2887 -- If the type is the designated type of an access_to_subprogram,
2888 -- then there is no name to provide in the call.
2890 if Ekind (Ent) = E_Subprogram_Type then
2891 return;
2893 -- Otherwise, we will be able to find some kind of name to output
2895 else
2896 Unwind_Internal_Type (Ent);
2897 Nam := Chars (Ent);
2898 end if;
2900 -- If not internal name, or if we could not find a reasonable possible
2901 -- substitution for the internal name, just use name in Chars field.
2903 else
2904 Nam := Chars (Node);
2905 Loc := Sloc (Node);
2906 end if;
2908 -- At this stage, the name to output is in Nam
2910 Get_Unqualified_Decoded_Name_String (Nam);
2912 -- Remove trailing upper case letters from the name (useful for
2913 -- dealing with some cases of internal names).
2915 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
2916 Name_Len := Name_Len - 1;
2917 end loop;
2919 -- If we have any of the names from standard that start with the
2920 -- characters "any " (e.g. Any_Type), then kill the message since
2921 -- almost certainly it is a junk cascaded message.
2923 if Name_Len > 4
2924 and then Name_Buffer (1 .. 4) = "any "
2925 then
2926 Kill_Message := True;
2927 end if;
2929 -- If we still have an internal name, kill the message (will only
2930 -- work if we already had errors!)
2932 if Is_Internal_Name then
2933 Kill_Message := True;
2934 end if;
2935 -- Remaining step is to adjust casing and possibly add 'Class
2937 Adjust_Name_Case (Global_Name_Buffer, Loc);
2938 Set_Msg_Name_Buffer;
2939 Add_Class;
2940 end Set_Msg_Node;
2942 ------------------
2943 -- Set_Msg_Text --
2944 ------------------
2946 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2947 C : Character; -- Current character
2948 P : Natural; -- Current index;
2950 procedure Skip_Msg_Insertion_Warning (C : Character);
2951 -- Deal with ? ?? ?x? ?X? ?*? ?$? insertion sequences (and the same
2952 -- sequences using < instead of ?). The caller has already bumped
2953 -- the pointer past the initial ? or < and C is set to this initial
2954 -- character (? or <). This procedure skips past the rest of the
2955 -- sequence. We do not need to set Msg_Insertion_Char, since this
2956 -- was already done during the message prescan.
2958 --------------------------------
2959 -- Skip_Msg_Insertion_Warning --
2960 --------------------------------
2962 procedure Skip_Msg_Insertion_Warning (C : Character) is
2963 begin
2964 if P <= Text'Last and then Text (P) = C then
2965 P := P + 1;
2967 elsif P + 1 <= Text'Last
2968 and then (Text (P) in 'a' .. 'z'
2969 or else
2970 Text (P) in 'A' .. 'Z'
2971 or else
2972 Text (P) = '*'
2973 or else
2974 Text (P) = '$')
2975 and then Text (P + 1) = C
2976 then
2977 P := P + 2;
2978 end if;
2979 end Skip_Msg_Insertion_Warning;
2981 -- Start of processing for Set_Msg_Text
2983 begin
2984 Manual_Quote_Mode := False;
2985 Msglen := 0;
2986 Flag_Source := Get_Source_File_Index (Flag);
2988 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
2989 -- will be used (Info field in error message object) to put back the
2990 -- string when it is printed. We need to do this, or we get confused
2991 -- with instantiation continuations.
2993 if Text'Length > 6
2994 and then Text (Text'First .. Text'First + 5) = "info: "
2995 then
2996 P := Text'First + 6;
2997 else
2998 P := Text'First;
2999 end if;
3001 -- Loop through characters of message
3003 while P <= Text'Last loop
3004 C := Text (P);
3005 P := P + 1;
3007 -- Check for insertion character or sequence
3009 case C is
3010 when '%' =>
3011 if P <= Text'Last and then Text (P) = '%' then
3012 P := P + 1;
3013 Set_Msg_Insertion_Name_Literal;
3014 else
3015 Set_Msg_Insertion_Name;
3016 end if;
3018 when '$' =>
3019 if P <= Text'Last and then Text (P) = '$' then
3020 P := P + 1;
3021 Set_Msg_Insertion_Unit_Name (Suffix => False);
3022 else
3023 Set_Msg_Insertion_Unit_Name;
3024 end if;
3026 when '{' =>
3027 Set_Msg_Insertion_File_Name;
3029 when '}' =>
3030 Set_Msg_Insertion_Type_Reference (Flag);
3032 when '*' =>
3033 Set_Msg_Insertion_Reserved_Name;
3035 when '&' =>
3036 Set_Msg_Insertion_Node;
3038 when '#' =>
3039 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
3041 when '\' =>
3042 Continuation := True;
3044 if P <= Text'Last and then Text (P) = '\' then
3045 Continuation_New_Line := True;
3046 P := P + 1;
3047 end if;
3049 when '@' =>
3050 Set_Msg_Insertion_Column;
3052 when '>' =>
3053 Set_Msg_Insertion_Run_Time_Name;
3055 when '^' =>
3056 Set_Msg_Insertion_Uint;
3058 when '`' =>
3059 Manual_Quote_Mode := not Manual_Quote_Mode;
3060 Set_Msg_Char ('"');
3062 when '!' =>
3063 null; -- already dealt with
3065 when '?' =>
3066 Skip_Msg_Insertion_Warning ('?');
3068 when '<' =>
3069 Skip_Msg_Insertion_Warning ('<');
3071 when '|' =>
3072 null; -- already dealt with
3074 when ''' =>
3075 Set_Msg_Char (Text (P));
3076 P := P + 1;
3078 when '~' =>
3079 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
3081 -- Upper case letter
3083 when 'A' .. 'Z' =>
3085 -- Start of reserved word if two or more
3087 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
3088 P := P - 1;
3089 Set_Msg_Insertion_Reserved_Word (Text, P);
3091 -- Single upper case letter is just inserted
3093 else
3094 Set_Msg_Char (C);
3095 end if;
3097 -- '[' (will be/would have been raised at run time)
3099 when '[' =>
3101 -- Switch the message from a warning to an error if the flag
3102 -- -gnatwE is specified to treat run-time exception warnings
3103 -- as errors.
3105 if Is_Warning_Msg
3106 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
3107 then
3108 Is_Warning_Msg := False;
3109 end if;
3111 if Is_Warning_Msg then
3112 Set_Msg_Str ("will be raised at run time");
3113 else
3114 Set_Msg_Str ("would have been raised at run time");
3115 end if;
3117 -- ']' (may be/might have been raised at run time)
3119 when ']' =>
3120 if Is_Warning_Msg then
3121 Set_Msg_Str ("may be raised at run time");
3122 else
3123 Set_Msg_Str ("might have been raised at run time");
3124 end if;
3126 -- Normal character with no special treatment
3128 when others =>
3129 Set_Msg_Char (C);
3130 end case;
3131 end loop;
3132 end Set_Msg_Text;
3134 ----------------
3135 -- Set_Posted --
3136 ----------------
3138 procedure Set_Posted (N : Node_Id) is
3139 P : Node_Id;
3141 begin
3142 if Is_Serious_Error then
3144 -- We always set Error_Posted on the node itself
3146 Set_Error_Posted (N);
3148 -- If it is a subexpression, then set Error_Posted on parents up to
3149 -- and including the first non-subexpression construct. This helps
3150 -- avoid cascaded error messages within a single expression.
3152 P := N;
3153 loop
3154 P := Parent (P);
3155 exit when No (P);
3156 Set_Error_Posted (P);
3157 exit when Nkind (P) not in N_Subexpr;
3158 end loop;
3160 if Nkind_In (P, N_Pragma_Argument_Association,
3161 N_Component_Association,
3162 N_Discriminant_Association,
3163 N_Generic_Association,
3164 N_Parameter_Association)
3165 then
3166 Set_Error_Posted (Parent (P));
3167 end if;
3169 -- A special check, if we just posted an error on an attribute
3170 -- definition clause, then also set the entity involved as posted.
3171 -- For example, this stops complaining about the alignment after
3172 -- complaining about the size, which is likely to be useless.
3174 if Nkind (P) = N_Attribute_Definition_Clause then
3175 if Is_Entity_Name (Name (P)) then
3176 Set_Error_Posted (Entity (Name (P)));
3177 end if;
3178 end if;
3179 end if;
3180 end Set_Posted;
3182 -----------------------
3183 -- Set_Qualification --
3184 -----------------------
3186 procedure Set_Qualification (N : Nat; E : Entity_Id) is
3187 begin
3188 if N /= 0 and then Scope (E) /= Standard_Standard then
3189 Set_Qualification (N - 1, Scope (E));
3190 Set_Msg_Node (Scope (E));
3191 Set_Msg_Char ('.');
3192 end if;
3193 end Set_Qualification;
3195 ------------------------
3196 -- Special_Msg_Delete --
3197 ------------------------
3199 -- Is it really right to have all this specialized knowledge in errout?
3201 function Special_Msg_Delete
3202 (Msg : String;
3203 N : Node_Or_Entity_Id;
3204 E : Node_Or_Entity_Id) return Boolean
3206 begin
3207 -- Never delete messages in -gnatdO mode
3209 if Debug_Flag_OO then
3210 return False;
3212 -- Processing for "atomic access cannot be guaranteed"
3214 elsif Msg = "atomic access to & cannot be guaranteed" then
3216 -- When an atomic object refers to a non-atomic type in the same
3217 -- scope, we implicitly make the type atomic. In the non-error case
3218 -- this is surely safe (and in fact prevents an error from occurring
3219 -- if the type is not atomic by default). But if the object cannot be
3220 -- made atomic, then we introduce an extra junk message by this
3221 -- manipulation, which we get rid of here.
3223 -- We identify this case by the fact that it references a type for
3224 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
3226 if Is_Type (E)
3227 and then Is_Atomic (E)
3228 and then No (Get_Rep_Pragma (E, Name_Atomic))
3229 then
3230 return True;
3231 end if;
3233 -- Similar processing for "volatile full access cannot be guaranteed"
3235 elsif Msg = "volatile full access to & cannot be guaranteed" then
3236 if Is_Type (E)
3237 and then Is_Volatile_Full_Access (E)
3238 and then No (Get_Rep_Pragma (E, Name_Volatile_Full_Access))
3239 then
3240 return True;
3241 end if;
3243 -- Processing for "Size too small" messages
3245 elsif Msg = "size for& too small, minimum allowed is ^" then
3247 -- Suppress "size too small" errors in CodePeer mode, since code may
3248 -- be analyzed in a different configuration than the one used for
3249 -- compilation. Even when the configurations match, this message
3250 -- may be issued on correct code, because pragma Pack is ignored
3251 -- in CodePeer mode.
3253 if CodePeer_Mode then
3254 return True;
3256 -- When a size is wrong for a frozen type there is no explicit size
3257 -- clause, and other errors have occurred, suppress the message,
3258 -- since it is likely that this size error is a cascaded result of
3259 -- other errors. The reason we eliminate unfrozen types is that
3260 -- messages issued before the freeze type are for sure OK.
3262 elsif Is_Frozen (E)
3263 and then Serious_Errors_Detected > 0
3264 and then Nkind (N) /= N_Component_Clause
3265 and then Nkind (Parent (N)) /= N_Component_Clause
3266 and then
3267 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
3268 and then
3269 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
3270 and then
3271 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
3272 then
3273 return True;
3274 end if;
3275 end if;
3277 -- All special tests complete, so go ahead with message
3279 return False;
3280 end Special_Msg_Delete;
3282 -----------------
3283 -- SPARK_Msg_N --
3284 -----------------
3286 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
3287 begin
3288 if SPARK_Mode /= Off then
3289 Error_Msg_N (Msg, N);
3290 end if;
3291 end SPARK_Msg_N;
3293 ------------------
3294 -- SPARK_Msg_NE --
3295 ------------------
3297 procedure SPARK_Msg_NE
3298 (Msg : String;
3299 N : Node_Or_Entity_Id;
3300 E : Node_Or_Entity_Id)
3302 begin
3303 if SPARK_Mode /= Off then
3304 Error_Msg_NE (Msg, N, E);
3305 end if;
3306 end SPARK_Msg_NE;
3308 --------------------------
3309 -- Unwind_Internal_Type --
3310 --------------------------
3312 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
3313 Derived : Boolean := False;
3314 Mchar : Character;
3315 Old_Ent : Entity_Id;
3317 begin
3318 -- Undo placement of a quote, since we will put it back later
3320 Mchar := Msg_Buffer (Msglen);
3322 if Mchar = '"' then
3323 Msglen := Msglen - 1;
3324 end if;
3326 -- The loop here deals with recursive types, we are trying to find a
3327 -- related entity that is not an implicit type. Note that the check with
3328 -- Old_Ent stops us from getting "stuck". Also, we don't output the
3329 -- "type derived from" message more than once in the case where we climb
3330 -- up multiple levels.
3332 Find : loop
3333 Old_Ent := Ent;
3335 -- Implicit access type, use directly designated type In Ada 2005,
3336 -- the designated type may be an anonymous access to subprogram, in
3337 -- which case we can only point to its definition.
3339 if Is_Access_Type (Ent) then
3340 if Ekind (Ent) = E_Access_Subprogram_Type
3341 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
3342 or else Is_Access_Protected_Subprogram_Type (Ent)
3343 then
3344 Ent := Directly_Designated_Type (Ent);
3346 if not Comes_From_Source (Ent) then
3347 if Buffer_Ends_With ("type ") then
3348 Buffer_Remove ("type ");
3349 end if;
3350 end if;
3352 if Ekind (Ent) = E_Function then
3353 Set_Msg_Str ("access to function ");
3354 elsif Ekind (Ent) = E_Procedure then
3355 Set_Msg_Str ("access to procedure ");
3356 else
3357 Set_Msg_Str ("access to subprogram");
3358 end if;
3360 exit Find;
3362 -- Type is access to object, named or anonymous
3364 else
3365 Set_Msg_Str ("access to ");
3366 Ent := Directly_Designated_Type (Ent);
3367 end if;
3369 -- Classwide type
3371 elsif Is_Class_Wide_Type (Ent) then
3372 Class_Flag := True;
3373 Ent := Root_Type (Ent);
3375 -- Use base type if this is a subtype
3377 elsif Ent /= Base_Type (Ent) then
3378 Buffer_Remove ("type ");
3380 -- Avoid duplication "subtype of subtype of", and also replace
3381 -- "derived from subtype of" simply by "derived from"
3383 if not Buffer_Ends_With ("subtype of ")
3384 and then not Buffer_Ends_With ("derived from ")
3385 then
3386 Set_Msg_Str ("subtype of ");
3387 end if;
3389 Ent := Base_Type (Ent);
3391 -- If this is a base type with a first named subtype, use the first
3392 -- named subtype instead. This is not quite accurate in all cases,
3393 -- but it makes too much noise to be accurate and add 'Base in all
3394 -- cases. Note that we only do this is the first named subtype is not
3395 -- itself an internal name. This avoids the obvious loop (subtype ->
3396 -- basetype -> subtype) which would otherwise occur).
3398 else
3399 declare
3400 FST : constant Entity_Id := First_Subtype (Ent);
3402 begin
3403 if not Is_Internal_Name (Chars (FST)) then
3404 Ent := FST;
3405 exit Find;
3407 -- Otherwise use root type
3409 else
3410 if not Derived then
3411 Buffer_Remove ("type ");
3413 -- Test for "subtype of type derived from" which seems
3414 -- excessive and is replaced by "type derived from".
3416 Buffer_Remove ("subtype of");
3418 -- Avoid duplicated "type derived from type derived from"
3420 if not Buffer_Ends_With ("type derived from ") then
3421 Set_Msg_Str ("type derived from ");
3422 end if;
3424 Derived := True;
3425 end if;
3426 end if;
3427 end;
3429 Ent := Etype (Ent);
3430 end if;
3432 -- If we are stuck in a loop, get out and settle for the internal
3433 -- name after all. In this case we set to kill the message if it is
3434 -- not the first error message (we really try hard not to show the
3435 -- dirty laundry of the implementation to the poor user).
3437 if Ent = Old_Ent then
3438 Kill_Message := True;
3439 exit Find;
3440 end if;
3442 -- Get out if we finally found a non-internal name to use
3444 exit Find when not Is_Internal_Name (Chars (Ent));
3445 end loop Find;
3447 if Mchar = '"' then
3448 Set_Msg_Char ('"');
3449 end if;
3450 end Unwind_Internal_Type;
3452 --------------------
3453 -- Warn_Insertion --
3454 --------------------
3456 function Warn_Insertion return String is
3457 begin
3458 case Warning_Msg_Char is
3459 when '?' =>
3460 return "??";
3462 when 'a' .. 'z' | 'A' .. 'Z' | '*' | '$' =>
3463 return '?' & Warning_Msg_Char & '?';
3465 when ' ' =>
3466 return "?";
3468 when others =>
3469 raise Program_Error;
3470 end case;
3471 end Warn_Insertion;
3473 end Errout;