* tree-cfg.c (tree_find_edge_insert_loc): Handle naked RETURN_EXPR.
[official-gcc.git] / gcc / ada / errout.adb
blob5da299a419e7aa294f0a224e96eead9a85fd3143
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-2005 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
21 -- --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 -- --
25 ------------------------------------------------------------------------------
27 -- Warning! Error messages can be generated during Gigi processing by direct
28 -- calls to error message routines, so it is essential that the processing
29 -- in this body be consistent with the requirements for the Gigi processing
30 -- environment, and that in particular, no disallowed table expansion is
31 -- allowed to occur.
33 with Atree; use Atree;
34 with Casing; use Casing;
35 with Csets; use Csets;
36 with Debug; use Debug;
37 with Einfo; use Einfo;
38 with Erroutc; use Erroutc;
39 with Fname; use Fname;
40 with Hostparm; use Hostparm;
41 with Lib; use Lib;
42 with Namet; use Namet;
43 with Opt; use Opt;
44 with Nlists; use Nlists;
45 with Output; use Output;
46 with Scans; use Scans;
47 with Sinput; use Sinput;
48 with Sinfo; use Sinfo;
49 with Snames; use Snames;
50 with Stand; use Stand;
51 with Style;
52 with Uname; use Uname;
54 with Unchecked_Conversion;
56 package body Errout is
58 Errors_Must_Be_Ignored : Boolean := False;
59 -- Set to True by procedure Set_Ignore_Errors (True), when calls to
60 -- error message procedures should be ignored (when parsing irrelevant
61 -- text in sources being preprocessed).
63 Warn_On_Instance : Boolean;
64 -- Flag set true for warning message to be posted on instance
66 ------------------------------------
67 -- Table of Non-Instance Messages --
68 ------------------------------------
70 -- This table contains an entry for every error message processed by the
71 -- Error_Msg routine that is not posted on generic (or inlined) instance.
72 -- As explained in further detail in the Error_Msg procedure body, this
73 -- table is used to avoid posting redundant messages on instances.
75 type NIM_Record is record
76 Msg : String_Ptr;
77 Loc : Source_Ptr;
78 end record;
79 -- Type used to store text and location of one message
81 package Non_Instance_Msgs is new Table.Table (
82 Table_Component_Type => NIM_Record,
83 Table_Index_Type => Int,
84 Table_Low_Bound => 1,
85 Table_Initial => 100,
86 Table_Increment => 100,
87 Table_Name => "Non_Instance_Msgs");
89 -----------------------
90 -- Local Subprograms --
91 -----------------------
93 procedure Error_Msg_Internal
94 (Msg : String;
95 Sptr : Source_Ptr;
96 Optr : Source_Ptr;
97 Msg_Cont : Boolean);
98 -- This is the low level routine used to post messages after dealing with
99 -- the issue of messages placed on instantiations (which get broken up
100 -- into separate calls in Error_Msg). Sptr is the location on which the
101 -- flag will be placed in the output. In the case where the flag is on
102 -- the template, this points directly to the template, not to one of the
103 -- instantiation copies of the template. Optr is the original location
104 -- used to flag the error, and this may indeed point to an instantiation
105 -- copy. So typically we can see Optr pointing to the template location
106 -- in an instantiation copy when Sptr points to the source location of
107 -- the actual instantiation (i.e the line with the new). Msg_Cont is
108 -- set true if this is a continuation message.
110 function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
111 -- Determines if warnings should be suppressed for the given node
113 function OK_Node (N : Node_Id) return Boolean;
114 -- Determines if a node is an OK node to place an error message on (return
115 -- True) or if the error message should be suppressed (return False). A
116 -- message is suppressed if the node already has an error posted on it,
117 -- or if it refers to an Etype that has an error posted on it, or if
118 -- it references an Entity that has an error posted on it.
120 procedure Output_Source_Line
121 (L : Physical_Line_Number;
122 Sfile : Source_File_Index;
123 Errs : Boolean);
124 -- Outputs text of source line L, in file S, together with preceding line
125 -- number, as described above for Output_Line_Number. The Errs parameter
126 -- indicates if there are errors attached to the line, which forces
127 -- listing on, even in the presence of pragma List (Off).
129 procedure Set_Msg_Insertion_Column;
130 -- Handle column number insertion (@ insertion character)
132 procedure Set_Msg_Insertion_Node;
133 -- Handle node (name from node) insertion (& insertion character)
135 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
136 -- Handle type reference (right brace insertion character). Flag is the
137 -- location of the flag, which is provided for the internal call to
138 -- Set_Msg_Insertion_Line_Number,
140 procedure Set_Msg_Insertion_Unit_Name;
141 -- Handle unit name insertion ($ insertion character)
143 procedure Set_Msg_Node (Node : Node_Id);
144 -- Add the sequence of characters for the name associated with the
145 -- given node to the current message.
147 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
148 -- Add a sequence of characters to the current message. The characters may
149 -- be one of the special insertion characters (see documentation in spec).
150 -- Flag is the location at which the error is to be posted, which is used
151 -- to determine whether or not the # insertion needs a file name. The
152 -- variables Msg_Buffer, Msglen, Is_Style_Msg, Is_Warning_Msg, and
153 -- Is_Unconditional_Msg are set on return.
155 procedure Set_Posted (N : Node_Id);
156 -- Sets the Error_Posted flag on the given node, and all its parents
157 -- that are subexpressions and then on the parent non-subexpression
158 -- construct that contains the original expression (this reduces the
159 -- number of cascaded messages). Note that this call only has an effect
160 -- for a serious error. For a non-serious error, it has no effect.
162 procedure Set_Qualification (N : Nat; E : Entity_Id);
163 -- Outputs up to N levels of qualification for the given entity. For
164 -- example, the entity A.B.C.D will output B.C. if N = 2.
166 function Special_Msg_Delete
167 (Msg : String;
168 N : Node_Or_Entity_Id;
169 E : Node_Or_Entity_Id) return Boolean;
170 -- This function is called from Error_Msg_NEL, passing the message Msg,
171 -- node N on which the error is to be posted, and the entity or node E
172 -- to be used for an & insertion in the message if any. The job of this
173 -- procedure is to test for certain cascaded messages that we would like
174 -- to suppress. If the message is to be suppressed then we return True.
175 -- If the message should be generated (the normal case) False is returned.
177 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
178 -- This procedure is given an entity id for an internal type, i.e.
179 -- a type with an internal name. It unwinds the type to try to get
180 -- to something reasonably printable, generating prefixes like
181 -- "subtype of", "access to", etc along the way in the buffer. The
182 -- value in Ent on return is the final name to be printed. Hopefully
183 -- this is not an internal name, but in some internal name cases, it
184 -- is an internal name, and has to be printed anyway (although in this
185 -- case the message has been killed if possible). The global variable
186 -- Class_Flag is set to True if the resulting entity should have
187 -- 'Class appended to its name (see Add_Class procedure), and is
188 -- otherwise unchanged.
190 procedure VMS_Convert;
191 -- This procedure has no effect if called when the host is not OpenVMS.
192 -- If the host is indeed OpenVMS, then the error message stored in
193 -- Msg_Buffer is scanned for appearences of switch names which need
194 -- converting to corresponding VMS qualifer names. See Gnames/Vnames
195 -- table in Errout spec for precise definition of the conversion that
196 -- is performed by this routine in OpenVMS mode.
198 -----------------------
199 -- Change_Error_Text --
200 -----------------------
202 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
203 Save_Next : Error_Msg_Id;
204 Err_Id : Error_Msg_Id := Error_Id;
206 begin
207 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr);
208 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
210 -- If in immediate error message mode, output modified error message now
211 -- This is just a bit tricky, because we want to output just a single
212 -- message, and the messages we modified is already linked in. We solve
213 -- this by temporarily resetting its forward pointer to empty.
215 if Debug_Flag_OO then
216 Save_Next := Errors.Table (Error_Id).Next;
217 Errors.Table (Error_Id).Next := No_Error_Msg;
218 Write_Eol;
219 Output_Source_Line
220 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
221 Output_Error_Msgs (Err_Id);
222 Errors.Table (Error_Id).Next := Save_Next;
223 end if;
224 end Change_Error_Text;
226 ---------------
227 -- Error_Msg --
228 ---------------
230 -- Error_Msg posts a flag at the given location, except that if the
231 -- Flag_Location points within a generic template and corresponds
232 -- to an instantiation of this generic template, then the actual
233 -- message will be posted on the generic instantiation, along with
234 -- additional messages referencing the generic declaration.
236 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
237 Sindex : Source_File_Index;
238 -- Source index for flag location
240 Orig_Loc : Source_Ptr;
241 -- Original location of Flag_Location (i.e. location in original
242 -- template in instantiation case, otherwise unchanged).
244 begin
245 -- It is a fatal error to issue an error message when scanning from
246 -- the internal source buffer (see Sinput for further documentation)
248 pragma Assert (Sinput.Source /= Internal_Source_Ptr);
250 -- Return if all errors are to be ignored
252 if Errors_Must_Be_Ignored then
253 return;
254 end if;
256 -- If we already have messages, and we are trying to place a message
257 -- at No_Location or in package Standard, then just ignore the attempt
258 -- since we assume that what is happening is some cascaded junk. Note
259 -- that this is safe in the sense that proceeding will surely bomb.
261 if Flag_Location < First_Source_Ptr
262 and then Total_Errors_Detected > 0
263 then
264 return;
265 end if;
267 -- Start procesing of new message
269 Sindex := Get_Source_File_Index (Flag_Location);
270 Test_Style_Warning_Serious_Msg (Msg);
271 Orig_Loc := Original_Location (Flag_Location);
273 -- If the current location is in an instantiation, the issue arises
274 -- of whether to post the message on the template or the instantiation.
276 -- The way we decide is to see if we have posted the same message
277 -- on the template when we compiled the template (the template is
278 -- always compiled before any instantiations). For this purpose,
279 -- we use a separate table of messages. The reason we do this is
280 -- twofold:
282 -- First, the messages can get changed by various processing
283 -- including the insertion of tokens etc, making it hard to
284 -- do the comparison.
286 -- Second, we will suppress a warning on a template if it is
287 -- not in the current extended source unit. That's reasonable
288 -- and means we don't want the warning on the instantiation
289 -- here either, but it does mean that the main error table
290 -- would not in any case include the message.
292 if Flag_Location = Orig_Loc then
293 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
294 Warn_On_Instance := False;
296 -- Here we have an instance message
298 else
299 -- Delete if debug flag off, and this message duplicates a
300 -- message already posted on the corresponding template
302 if not Debug_Flag_GG then
303 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
304 if Msg = Non_Instance_Msgs.Table (J).Msg.all
305 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
306 then
307 return;
308 end if;
309 end loop;
310 end if;
312 -- No duplicate, so error/warning will be posted on instance
314 Warn_On_Instance := Is_Warning_Msg;
315 end if;
317 -- Ignore warning message that is suppressed. Note that style
318 -- checks are not considered warning messages for this purpose
320 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) then
321 return;
322 end if;
324 -- The idea at this stage is that we have two kinds of messages
326 -- First, we have those messages that are to be placed as requested at
327 -- Flag_Location. This includes messages that have nothing to do with
328 -- generics, and also messages placed on generic templates that reflect
329 -- an error in the template itself. For such messages we simply call
330 -- Error_Msg_Internal to place the message in the requested location.
332 if Instantiation (Sindex) = No_Location then
333 Error_Msg_Internal (Msg, Flag_Location, Flag_Location, False);
334 return;
335 end if;
337 -- If we are trying to flag an error in an instantiation, we may have
338 -- a generic contract violation. What we generate in this case is:
340 -- instantiation error at ...
341 -- original error message
343 -- or
345 -- warning: in instantiation at
346 -- warning: original warning message
348 -- All these messages are posted at the location of the top level
349 -- instantiation. If there are nested instantiations, then the
350 -- instantiation error message can be repeated, pointing to each
351 -- of the relevant instantiations.
353 -- Note: the instantiation mechanism is also shared for inlining
354 -- of subprogram bodies when front end inlining is done. In this
355 -- case the messages have the form:
357 -- in inlined body at ...
358 -- original error message
360 -- or
362 -- warning: in inlined body at
363 -- warning: original warning message
365 -- OK, this is the case where we have an instantiation error, and
366 -- we need to generate the error on the instantiation, rather than
367 -- on the template.
369 declare
370 Actual_Error_Loc : Source_Ptr;
371 -- Location of outer level instantiation in instantiation case, or
372 -- just a copy of Flag_Location in the normal case. This is the
373 -- location where all error messages will actually be posted.
375 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
376 -- Save possible location set for caller's message. We need to
377 -- use Error_Msg_Sloc for the location of the instantiation error
378 -- but we have to preserve a possible original value.
380 X : Source_File_Index;
382 Msg_Cont_Status : Boolean;
383 -- Used to label continuation lines in instantiation case with
384 -- proper Msg_Cont status.
386 begin
387 -- Loop to find highest level instantiation, where all error
388 -- messages will be placed.
390 X := Sindex;
391 loop
392 Actual_Error_Loc := Instantiation (X);
393 X := Get_Source_File_Index (Actual_Error_Loc);
394 exit when Instantiation (X) = No_Location;
395 end loop;
397 -- Since we are generating the messages at the instantiation
398 -- point in any case, we do not want the references to the
399 -- bad lines in the instance to be annotated with the location
400 -- of the instantiation.
402 Suppress_Instance_Location := True;
403 Msg_Cont_Status := False;
405 -- Loop to generate instantiation messages
407 Error_Msg_Sloc := Flag_Location;
408 X := Get_Source_File_Index (Flag_Location);
410 while Instantiation (X) /= No_Location loop
412 -- Suppress instantiation message on continuation lines
414 if Msg (Msg'First) /= '\' then
416 -- Case of inlined body
418 if Inlined_Body (X) then
419 if Is_Warning_Msg then
420 Error_Msg_Internal
421 ("?in inlined body #",
422 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
424 else
425 Error_Msg_Internal
426 ("error in inlined body #",
427 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
428 end if;
430 -- Case of generic instantiation
432 else
433 if Is_Warning_Msg then
434 Error_Msg_Internal
435 ("?in instantiation #",
436 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
438 else
439 Error_Msg_Internal
440 ("instantiation error #",
441 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
442 end if;
443 end if;
444 end if;
446 Error_Msg_Sloc := Instantiation (X);
447 X := Get_Source_File_Index (Error_Msg_Sloc);
448 Msg_Cont_Status := True;
449 end loop;
451 Suppress_Instance_Location := False;
452 Error_Msg_Sloc := Save_Error_Msg_Sloc;
454 -- Here we output the original message on the outer instantiation
456 Error_Msg_Internal
457 (Msg, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
458 end;
459 end Error_Msg;
461 ------------------
462 -- Error_Msg_AP --
463 ------------------
465 procedure Error_Msg_AP (Msg : String) is
466 S1 : Source_Ptr;
467 C : Character;
469 begin
470 -- If we had saved the Scan_Ptr value after scanning the previous
471 -- token, then we would have exactly the right place for putting
472 -- the flag immediately at hand. However, that would add at least
473 -- two instructions to a Scan call *just* to service the possibility
474 -- of an Error_Msg_AP call. So instead we reconstruct that value.
476 -- We have two possibilities, start with Prev_Token_Ptr and skip over
477 -- the current token, which is made harder by the possibility that this
478 -- token may be in error, or start with Token_Ptr and work backwards.
479 -- We used to take the second approach, but it's hard because of
480 -- comments, and harder still because things that look like comments
481 -- can appear inside strings. So now we take the first approach.
483 -- Note: in the case where there is no previous token, Prev_Token_Ptr
484 -- is set to Source_First, which is a reasonable position for the
485 -- error flag in this situation.
487 S1 := Prev_Token_Ptr;
488 C := Source (S1);
490 -- If the previous token is a string literal, we need a special approach
491 -- since there may be white space inside the literal and we don't want
492 -- to stop on that white space.
494 -- Note: since this is an error recovery issue anyway, it is not worth
495 -- worrying about special UTF_32 line terminator characters here.
497 if Prev_Token = Tok_String_Literal then
498 loop
499 S1 := S1 + 1;
501 if Source (S1) = C then
502 S1 := S1 + 1;
503 exit when Source (S1) /= C;
504 elsif Source (S1) in Line_Terminator then
505 exit;
506 end if;
507 end loop;
509 -- Character literal also needs special handling
511 elsif Prev_Token = Tok_Char_Literal then
512 S1 := S1 + 3;
514 -- Otherwise we search forward for the end of the current token, marked
515 -- by a line terminator, white space, a comment symbol or if we bump
516 -- into the following token (i.e. the current token).
518 -- Again, it is not worth worrying about UTF_32 special line terminator
519 -- characters in this context, since this is only for error recovery.
521 else
522 while Source (S1) not in Line_Terminator
523 and then Source (S1) /= ' '
524 and then Source (S1) /= ASCII.HT
525 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
526 and then S1 /= Token_Ptr
527 loop
528 S1 := S1 + 1;
529 end loop;
530 end if;
532 -- S1 is now set to the location for the flag
534 Error_Msg (Msg, S1);
535 end Error_Msg_AP;
537 ------------------
538 -- Error_Msg_BC --
539 ------------------
541 procedure Error_Msg_BC (Msg : String) is
542 begin
543 -- If we are at end of file, post the flag after the previous token
545 if Token = Tok_EOF then
546 Error_Msg_AP (Msg);
548 -- If we are at start of file, post the flag at the current token
550 elsif Token_Ptr = Source_First (Current_Source_File) then
551 Error_Msg_SC (Msg);
553 -- If the character before the current token is a space or a horizontal
554 -- tab, then we place the flag on this character (in the case of a tab
555 -- we would really like to place it in the "last" character of the tab
556 -- space, but that it too much trouble to worry about).
558 elsif Source (Token_Ptr - 1) = ' '
559 or else Source (Token_Ptr - 1) = ASCII.HT
560 then
561 Error_Msg (Msg, Token_Ptr - 1);
563 -- If there is no space or tab before the current token, then there is
564 -- no room to place the flag before the token, so we place it on the
565 -- token instead (this happens for example at the start of a line).
567 else
568 Error_Msg (Msg, Token_Ptr);
569 end if;
570 end Error_Msg_BC;
572 -------------------
573 -- Error_Msg_CRT --
574 -------------------
576 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
577 CNRT : constant String := " not allowed in no run time mode";
578 CCRT : constant String := " not supported by configuration>";
580 S : String (1 .. Feature'Length + 1 + CCRT'Length);
581 L : Natural;
583 begin
584 S (1) := '|';
585 S (2 .. Feature'Length + 1) := Feature;
586 L := Feature'Length + 2;
588 if No_Run_Time_Mode then
589 S (L .. L + CNRT'Length - 1) := CNRT;
590 L := L + CNRT'Length - 1;
592 else pragma Assert (Configurable_Run_Time_Mode);
593 S (L .. L + CCRT'Length - 1) := CCRT;
594 L := L + CCRT'Length - 1;
595 end if;
597 Error_Msg_N (S (1 .. L), N);
598 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
599 end Error_Msg_CRT;
601 -----------------
602 -- Error_Msg_F --
603 -----------------
605 procedure Error_Msg_F (Msg : String; N : Node_Id) is
606 begin
607 Error_Msg_NEL (Msg, N, N, Sloc (First_Node (N)));
608 end Error_Msg_F;
610 ------------------
611 -- Error_Msg_FE --
612 ------------------
614 procedure Error_Msg_FE
615 (Msg : String;
616 N : Node_Id;
617 E : Node_Or_Entity_Id)
619 begin
620 Error_Msg_NEL (Msg, N, E, Sloc (First_Node (N)));
621 end Error_Msg_FE;
623 ------------------------
624 -- Error_Msg_Internal --
625 ------------------------
627 procedure Error_Msg_Internal
628 (Msg : String;
629 Sptr : Source_Ptr;
630 Optr : Source_Ptr;
631 Msg_Cont : Boolean)
633 Next_Msg : Error_Msg_Id;
634 -- Pointer to next message at insertion point
636 Prev_Msg : Error_Msg_Id;
637 -- Pointer to previous message at insertion point
639 Temp_Msg : Error_Msg_Id;
641 procedure Handle_Serious_Error;
642 -- Internal procedure to do all error message handling for a serious
643 -- error message, other than bumping the error counts and arranging
644 -- for the message to be output.
646 --------------------------
647 -- Handle_Serious_Error --
648 --------------------------
650 procedure Handle_Serious_Error is
651 begin
652 -- Turn off code generation if not done already
654 if Operating_Mode = Generate_Code then
655 Operating_Mode := Check_Semantics;
656 Expander_Active := False;
657 end if;
659 -- Set the fatal error flag in the unit table unless we are
660 -- in Try_Semantics mode. This stops the semantics from being
661 -- performed if we find a serious error. This is skipped if we
662 -- are currently dealing with the configuration pragma file.
664 if not Try_Semantics
665 and then Current_Source_Unit /= No_Unit
666 then
667 Set_Fatal_Error (Get_Source_Unit (Sptr));
668 end if;
669 end Handle_Serious_Error;
671 -- Start of processing for Error_Msg_Internal
673 begin
674 if Raise_Exception_On_Error /= 0 then
675 raise Error_Msg_Exception;
676 end if;
678 Continuation := Msg_Cont;
679 Suppress_Message := False;
680 Kill_Message := False;
681 Set_Msg_Text (Msg, Sptr);
683 -- Kill continuation if parent message killed
685 if Continuation and Last_Killed then
686 return;
687 end if;
689 -- Return without doing anything if message is suppressed
691 if Suppress_Message
692 and not All_Errors_Mode
693 and not (Msg (Msg'Last) = '!')
694 then
695 if not Continuation then
696 Last_Killed := True;
697 end if;
699 return;
700 end if;
702 -- Return without doing anything if message is killed and this
703 -- is not the first error message. The philosophy is that if we
704 -- get a weird error message and we already have had a message,
705 -- then we hope the weird message is a junk cascaded message
707 if Kill_Message
708 and then not All_Errors_Mode
709 and then Total_Errors_Detected /= 0
710 then
711 if not Continuation then
712 Last_Killed := True;
713 end if;
715 return;
716 end if;
718 -- Special check for warning message to see if it should be output
720 if Is_Warning_Msg then
722 -- Immediate return if warning message and warnings are suppressed
724 if Warnings_Suppressed (Optr)
725 or else Warnings_Suppressed (Sptr)
726 then
727 Cur_Msg := No_Error_Msg;
728 return;
729 end if;
731 -- If the flag location is in the main extended source unit
732 -- then for sure we want the warning since it definitely belongs
734 if In_Extended_Main_Source_Unit (Sptr) then
735 null;
737 -- If the flag location is not in the main extended source
738 -- unit then we want to eliminate the warning.
740 elsif In_Extended_Main_Code_Unit (Sptr)
741 and then Warn_On_Instance
742 then
743 null;
745 -- Keep warning if debug flag G set
747 elsif Debug_Flag_GG then
748 null;
750 -- Here is where we delete a warning from a with'ed unit
752 else
753 Cur_Msg := No_Error_Msg;
754 return;
755 end if;
756 end if;
758 -- If message is to be ignored in special ignore message mode, this is
759 -- where we do this special processing, bypassing message output.
761 if Ignore_Errors_Enable > 0 then
762 if Is_Serious_Error then
763 Handle_Serious_Error;
764 end if;
766 return;
767 end if;
769 -- Otherwise build error message object for new message
771 Errors.Increment_Last;
772 Cur_Msg := Errors.Last;
773 Errors.Table (Cur_Msg).Text := new String'(Msg_Buffer (1 .. Msglen));
774 Errors.Table (Cur_Msg).Next := No_Error_Msg;
775 Errors.Table (Cur_Msg).Sptr := Sptr;
776 Errors.Table (Cur_Msg).Optr := Optr;
777 Errors.Table (Cur_Msg).Sfile := Get_Source_File_Index (Sptr);
778 Errors.Table (Cur_Msg).Line := Get_Physical_Line_Number (Sptr);
779 Errors.Table (Cur_Msg).Col := Get_Column_Number (Sptr);
780 Errors.Table (Cur_Msg).Warn := Is_Warning_Msg;
781 Errors.Table (Cur_Msg).Style := Is_Style_Msg;
782 Errors.Table (Cur_Msg).Serious := Is_Serious_Error;
783 Errors.Table (Cur_Msg).Uncond := Is_Unconditional_Msg;
784 Errors.Table (Cur_Msg).Msg_Cont := Continuation;
785 Errors.Table (Cur_Msg).Deleted := False;
787 -- If immediate errors mode set, output error message now. Also output
788 -- now if the -d1 debug flag is set (so node number message comes out
789 -- just before actual error message)
791 if Debug_Flag_OO or else Debug_Flag_1 then
792 Write_Eol;
793 Output_Source_Line (Errors.Table (Cur_Msg).Line,
794 Errors.Table (Cur_Msg).Sfile, True);
795 Temp_Msg := Cur_Msg;
796 Output_Error_Msgs (Temp_Msg);
798 -- If not in immediate errors mode, then we insert the message in the
799 -- error chain for later output by Finalize. The messages are sorted
800 -- first by unit (main unit comes first), and within a unit by source
801 -- location (earlier flag location first in the chain).
803 else
804 -- First a quick check, does this belong at the very end of the
805 -- chain of error messages. This saves a lot of time in the
806 -- normal case if there are lots of messages.
808 if Last_Error_Msg /= No_Error_Msg
809 and then Errors.Table (Cur_Msg).Sfile =
810 Errors.Table (Last_Error_Msg).Sfile
811 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
812 or else
813 (Sptr = Errors.Table (Last_Error_Msg).Sptr
814 and then
815 Optr > Errors.Table (Last_Error_Msg).Optr))
816 then
817 Prev_Msg := Last_Error_Msg;
818 Next_Msg := No_Error_Msg;
820 -- Otherwise do a full sequential search for the insertion point
822 else
823 Prev_Msg := No_Error_Msg;
824 Next_Msg := First_Error_Msg;
825 while Next_Msg /= No_Error_Msg loop
826 exit when
827 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
829 if Errors.Table (Cur_Msg).Sfile =
830 Errors.Table (Next_Msg).Sfile
831 then
832 exit when Sptr < Errors.Table (Next_Msg).Sptr
833 or else
834 (Sptr = Errors.Table (Next_Msg).Sptr
835 and then
836 Optr < Errors.Table (Next_Msg).Optr);
837 end if;
839 Prev_Msg := Next_Msg;
840 Next_Msg := Errors.Table (Next_Msg).Next;
841 end loop;
842 end if;
844 -- Now we insert the new message in the error chain. The insertion
845 -- point for the message is after Prev_Msg and before Next_Msg.
847 -- The possible insertion point for the new message is after Prev_Msg
848 -- and before Next_Msg. However, this is where we do a special check
849 -- for redundant parsing messages, defined as messages posted on the
850 -- same line. The idea here is that probably such messages are junk
851 -- from the parser recovering. In full errors mode, we don't do this
852 -- deletion, but otherwise such messages are discarded at this stage.
854 if Prev_Msg /= No_Error_Msg
855 and then Errors.Table (Prev_Msg).Line =
856 Errors.Table (Cur_Msg).Line
857 and then Errors.Table (Prev_Msg).Sfile =
858 Errors.Table (Cur_Msg).Sfile
859 and then Compiler_State = Parsing
860 and then not All_Errors_Mode
861 then
862 -- Don't delete unconditional messages and at this stage,
863 -- don't delete continuation lines (we attempted to delete
864 -- those earlier if the parent message was deleted.
866 if not Errors.Table (Cur_Msg).Uncond
867 and then not Continuation
868 then
869 -- Don't delete if prev msg is warning and new msg is
870 -- an error. This is because we don't want a real error
871 -- masked by a warning. In all other cases (that is parse
872 -- errors for the same line that are not unconditional)
873 -- we do delete the message. This helps to avoid
874 -- junk extra messages from cascaded parsing errors
876 if not (Errors.Table (Prev_Msg).Warn
878 Errors.Table (Prev_Msg).Style)
879 or else
880 (Errors.Table (Cur_Msg).Warn
882 Errors.Table (Cur_Msg).Style)
883 then
884 -- All tests passed, delete the message by simply
885 -- returning without any further processing.
887 if not Continuation then
888 Last_Killed := True;
889 end if;
891 return;
892 end if;
893 end if;
894 end if;
896 -- Come here if message is to be inserted in the error chain
898 if not Continuation then
899 Last_Killed := False;
900 end if;
902 if Prev_Msg = No_Error_Msg then
903 First_Error_Msg := Cur_Msg;
904 else
905 Errors.Table (Prev_Msg).Next := Cur_Msg;
906 end if;
908 Errors.Table (Cur_Msg).Next := Next_Msg;
910 if Next_Msg = No_Error_Msg then
911 Last_Error_Msg := Cur_Msg;
912 end if;
913 end if;
915 -- Bump appropriate statistics count
917 if Errors.Table (Cur_Msg).Warn
918 or else Errors.Table (Cur_Msg).Style
919 then
920 Warnings_Detected := Warnings_Detected + 1;
921 else
922 Total_Errors_Detected := Total_Errors_Detected + 1;
924 if Errors.Table (Cur_Msg).Serious then
925 Serious_Errors_Detected := Serious_Errors_Detected + 1;
926 Handle_Serious_Error;
927 end if;
928 end if;
930 -- Terminate if max errors reached
932 if Total_Errors_Detected + Warnings_Detected = Maximum_Errors then
933 raise Unrecoverable_Error;
934 end if;
936 end Error_Msg_Internal;
938 -----------------
939 -- Error_Msg_N --
940 -----------------
942 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
943 begin
944 Error_Msg_NEL (Msg, N, N, Sloc (N));
945 end Error_Msg_N;
947 ------------------
948 -- Error_Msg_NE --
949 ------------------
951 procedure Error_Msg_NE
952 (Msg : String;
953 N : Node_Or_Entity_Id;
954 E : Node_Or_Entity_Id)
956 begin
957 Error_Msg_NEL (Msg, N, E, Sloc (N));
958 end Error_Msg_NE;
960 -------------------
961 -- Error_Msg_NEL --
962 -------------------
964 procedure Error_Msg_NEL
965 (Msg : String;
966 N : Node_Or_Entity_Id;
967 E : Node_Or_Entity_Id;
968 Flag_Location : Source_Ptr)
970 begin
971 if Special_Msg_Delete (Msg, N, E) then
972 return;
973 end if;
975 Test_Style_Warning_Serious_Msg (Msg);
977 -- Special handling for warning messages
979 if Is_Warning_Msg then
981 -- Suppress if no warnings set for either entity or node
983 if No_Warnings (N) or else No_Warnings (E) then
984 return;
985 end if;
987 -- Suppress if inside loop that is known to be null
989 declare
990 P : Node_Id;
992 begin
993 P := Parent (N);
994 while Present (P) loop
995 if Nkind (P) = N_Loop_Statement and then Is_Null_Loop (P) then
996 return;
997 end if;
999 P := Parent (P);
1000 end loop;
1001 end;
1002 end if;
1004 -- Test for message to be output
1006 if All_Errors_Mode
1007 or else Msg (Msg'Last) = '!'
1008 or else OK_Node (N)
1009 or else (Msg (Msg'First) = '\' and not Last_Killed)
1010 then
1011 Debug_Output (N);
1012 Error_Msg_Node_1 := E;
1013 Error_Msg (Msg, Flag_Location);
1015 else
1016 Last_Killed := True;
1017 end if;
1019 if not Is_Warning_Msg and then not Is_Style_Msg then
1020 Set_Posted (N);
1021 end if;
1022 end Error_Msg_NEL;
1024 ------------------
1025 -- Error_Msg_NW --
1026 ------------------
1028 procedure Error_Msg_NW
1029 (Eflag : Boolean;
1030 Msg : String;
1031 N : Node_Or_Entity_Id)
1033 begin
1034 if Eflag
1035 and then In_Extended_Main_Source_Unit (N)
1036 and then Comes_From_Source (N)
1037 then
1038 Error_Msg_NEL (Msg, N, N, Sloc (N));
1039 end if;
1040 end Error_Msg_NW;
1042 -----------------
1043 -- Error_Msg_S --
1044 -----------------
1046 procedure Error_Msg_S (Msg : String) is
1047 begin
1048 Error_Msg (Msg, Scan_Ptr);
1049 end Error_Msg_S;
1051 ------------------
1052 -- Error_Msg_SC --
1053 ------------------
1055 procedure Error_Msg_SC (Msg : String) is
1056 begin
1057 -- If we are at end of file, post the flag after the previous token
1059 if Token = Tok_EOF then
1060 Error_Msg_AP (Msg);
1062 -- For all other cases the message is posted at the current token
1063 -- pointer position
1065 else
1066 Error_Msg (Msg, Token_Ptr);
1067 end if;
1068 end Error_Msg_SC;
1070 ------------------
1071 -- Error_Msg_SP --
1072 ------------------
1074 procedure Error_Msg_SP (Msg : String) is
1075 begin
1076 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1077 -- is set to Source_First, which is a reasonable position for the
1078 -- error flag in this situation
1080 Error_Msg (Msg, Prev_Token_Ptr);
1081 end Error_Msg_SP;
1083 --------------
1084 -- Finalize --
1085 --------------
1087 procedure Finalize is
1088 Cur : Error_Msg_Id;
1089 Nxt : Error_Msg_Id;
1090 E, F : Error_Msg_Id;
1091 Err_Flag : Boolean;
1093 begin
1094 -- Reset current error source file if the main unit has a pragma
1095 -- Source_Reference. This ensures outputting the proper name of
1096 -- the source file in this situation.
1098 if Main_Source_File = No_Source_File or else
1099 Num_SRef_Pragmas (Main_Source_File) /= 0
1100 then
1101 Current_Error_Source_File := No_Source_File;
1102 end if;
1104 -- Eliminate any duplicated error messages from the list. This is
1105 -- done after the fact to avoid problems with Change_Error_Text.
1107 Cur := First_Error_Msg;
1108 while Cur /= No_Error_Msg loop
1109 Nxt := Errors.Table (Cur).Next;
1111 F := Nxt;
1112 while F /= No_Error_Msg
1113 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1114 loop
1115 Check_Duplicate_Message (Cur, F);
1116 F := Errors.Table (F).Next;
1117 end loop;
1119 Cur := Nxt;
1120 end loop;
1122 -- Brief Error mode
1124 if Brief_Output or (not Full_List and not Verbose_Mode) then
1125 E := First_Error_Msg;
1126 Set_Standard_Error;
1128 while E /= No_Error_Msg loop
1129 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1130 if Full_Path_Name_For_Brief_Errors then
1131 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1132 else
1133 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1134 end if;
1136 Write_Char (':');
1137 Write_Int (Int (Physical_To_Logical
1138 (Errors.Table (E).Line,
1139 Errors.Table (E).Sfile)));
1140 Write_Char (':');
1142 if Errors.Table (E).Col < 10 then
1143 Write_Char ('0');
1144 end if;
1146 Write_Int (Int (Errors.Table (E).Col));
1147 Write_Str (": ");
1148 Output_Msg_Text (E);
1149 Write_Eol;
1150 end if;
1152 E := Errors.Table (E).Next;
1153 end loop;
1155 Set_Standard_Output;
1156 end if;
1158 -- Full source listing case
1160 if Full_List then
1161 List_Pragmas_Index := 1;
1162 List_Pragmas_Mode := True;
1163 E := First_Error_Msg;
1164 Write_Eol;
1166 -- First list initial main source file with its error messages
1168 for N in 1 .. Last_Source_Line (Main_Source_File) loop
1169 Err_Flag :=
1170 E /= No_Error_Msg
1171 and then Errors.Table (E).Line = N
1172 and then Errors.Table (E).Sfile = Main_Source_File;
1174 Output_Source_Line (N, Main_Source_File, Err_Flag);
1176 if Err_Flag then
1177 Output_Error_Msgs (E);
1179 if not Debug_Flag_2 then
1180 Write_Eol;
1181 end if;
1182 end if;
1184 end loop;
1186 -- Then output errors, if any, for subsidiary units
1188 while E /= No_Error_Msg
1189 and then Errors.Table (E).Sfile /= Main_Source_File
1190 loop
1191 Write_Eol;
1192 Output_Source_Line
1193 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1194 Output_Error_Msgs (E);
1195 end loop;
1196 end if;
1198 -- Verbose mode (error lines only with error flags)
1200 if Verbose_Mode and not Full_List then
1201 E := First_Error_Msg;
1203 -- Loop through error lines
1205 while E /= No_Error_Msg loop
1206 Write_Eol;
1207 Output_Source_Line
1208 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1209 Output_Error_Msgs (E);
1210 end loop;
1211 end if;
1213 -- Output error summary if verbose or full list mode
1215 if Verbose_Mode or else Full_List then
1217 -- Extra blank line if error messages or source listing were output
1219 if Total_Errors_Detected + Warnings_Detected > 0
1220 or else Full_List
1221 then
1222 Write_Eol;
1223 end if;
1225 -- Message giving number of lines read and number of errors detected.
1226 -- This normally goes to Standard_Output. The exception is when brief
1227 -- mode is not set, verbose mode (or full list mode) is set, and
1228 -- there are errors. In this case we send the message to standard
1229 -- error to make sure that *something* appears on standard error in
1230 -- an error situation.
1232 -- Formerly, only the "# errors" suffix was sent to stderr, whereas
1233 -- "# lines:" appeared on stdout. This caused problems on VMS when
1234 -- the stdout buffer was flushed, giving an extra line feed after
1235 -- the prefix.
1237 if Total_Errors_Detected + Warnings_Detected /= 0
1238 and then not Brief_Output
1239 and then (Verbose_Mode or Full_List)
1240 then
1241 Set_Standard_Error;
1242 end if;
1244 -- Message giving total number of lines
1246 Write_Str (" ");
1247 Write_Int (Num_Source_Lines (Main_Source_File));
1249 if Num_Source_Lines (Main_Source_File) = 1 then
1250 Write_Str (" line: ");
1251 else
1252 Write_Str (" lines: ");
1253 end if;
1255 if Total_Errors_Detected = 0 then
1256 Write_Str ("No errors");
1258 elsif Total_Errors_Detected = 1 then
1259 Write_Str ("1 error");
1261 else
1262 Write_Int (Total_Errors_Detected);
1263 Write_Str (" errors");
1264 end if;
1266 if Warnings_Detected /= 0 then
1267 Write_Str (", ");
1268 Write_Int (Warnings_Detected);
1269 Write_Str (" warning");
1271 if Warnings_Detected /= 1 then
1272 Write_Char ('s');
1273 end if;
1275 if Warning_Mode = Treat_As_Error then
1276 Write_Str (" (treated as error");
1278 if Warnings_Detected /= 1 then
1279 Write_Char ('s');
1280 end if;
1282 Write_Char (')');
1283 end if;
1284 end if;
1286 Write_Eol;
1287 Set_Standard_Output;
1288 end if;
1290 if Maximum_Errors /= 0
1291 and then Total_Errors_Detected + Warnings_Detected = Maximum_Errors
1292 then
1293 Set_Standard_Error;
1294 Write_Str ("fatal error: maximum errors reached");
1295 Write_Eol;
1296 Set_Standard_Output;
1297 end if;
1299 if Warning_Mode = Treat_As_Error then
1300 Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected;
1301 Warnings_Detected := 0;
1302 end if;
1303 end Finalize;
1305 ----------------
1306 -- First_Node --
1307 ----------------
1309 function First_Node (C : Node_Id) return Node_Id is
1310 L : constant Source_Ptr := Sloc (C);
1311 Sfile : constant Source_File_Index := Get_Source_File_Index (L);
1312 Earliest : Node_Id;
1313 Eloc : Source_Ptr;
1314 Discard : Traverse_Result;
1316 pragma Warnings (Off, Discard);
1318 function Test_Earlier (N : Node_Id) return Traverse_Result;
1319 -- Function applied to every node in the construct
1321 function Search_Tree_First is new Traverse_Func (Test_Earlier);
1322 -- Create traversal function
1324 ------------------
1325 -- Test_Earlier --
1326 ------------------
1328 function Test_Earlier (N : Node_Id) return Traverse_Result is
1329 Loc : constant Source_Ptr := Sloc (N);
1331 begin
1332 -- Check for earlier. The tests for being in the same file ensures
1333 -- against strange cases of foreign code somehow being present. We
1334 -- don't want wild placement of messages if that happens, so it is
1335 -- best to just ignore this situation.
1337 if Loc < Eloc
1338 and then Get_Source_File_Index (Loc) = Sfile
1339 then
1340 Earliest := N;
1341 Eloc := Loc;
1342 end if;
1344 return OK_Orig;
1345 end Test_Earlier;
1347 -- Start of processing for First_Node
1349 begin
1350 Earliest := Original_Node (C);
1351 Eloc := Sloc (Earliest);
1352 Discard := Search_Tree_First (Original_Node (C));
1353 return Earliest;
1354 end First_Node;
1356 ----------------
1357 -- First_Sloc --
1358 ----------------
1360 function First_Sloc (N : Node_Id) return Source_Ptr is
1361 SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1362 SF : constant Source_Ptr := Source_First (SI);
1363 F : Node_Id;
1364 S : Source_Ptr;
1366 begin
1367 F := First_Node (N);
1368 S := Sloc (F);
1370 -- The following circuit is a bit subtle. When we have parenthesized
1371 -- expressions, then the Sloc will not record the location of the
1372 -- paren, but we would like to post the flag on the paren. So what
1373 -- we do is to crawl up the tree from the First_Node, adjusting the
1374 -- Sloc value for any parentheses we know are present. Yes, we know
1375 -- this circuit is not 100% reliable (e.g. because we don't record
1376 -- all possible paren level valoues), but this is only for an error
1377 -- message so it is good enough.
1379 Node_Loop : loop
1380 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1382 -- We don't look more than 12 characters behind the current
1383 -- location, and in any case not past the front of the source.
1385 Search_Loop : for K in 1 .. 12 loop
1386 exit Search_Loop when S = SF;
1388 if Source_Text (SI) (S - 1) = '(' then
1389 S := S - 1;
1390 exit Search_Loop;
1392 elsif Source_Text (SI) (S - 1) <= ' ' then
1393 S := S - 1;
1395 else
1396 exit Search_Loop;
1397 end if;
1398 end loop Search_Loop;
1399 end loop Paren_Loop;
1401 exit Node_Loop when F = N;
1402 F := Parent (F);
1403 exit Node_Loop when Nkind (F) not in N_Subexpr;
1404 end loop Node_Loop;
1406 return S;
1407 end First_Sloc;
1409 ----------------
1410 -- Initialize --
1411 ----------------
1413 procedure Initialize is
1414 begin
1415 Errors.Init;
1416 First_Error_Msg := No_Error_Msg;
1417 Last_Error_Msg := No_Error_Msg;
1418 Serious_Errors_Detected := 0;
1419 Total_Errors_Detected := 0;
1420 Warnings_Detected := 0;
1421 Cur_Msg := No_Error_Msg;
1422 List_Pragmas.Init;
1424 -- Initialize warnings table, if all warnings are suppressed, supply
1425 -- an initial dummy entry covering all possible source locations.
1427 Warnings.Init;
1429 if Warning_Mode = Suppress then
1430 Warnings.Increment_Last;
1431 Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
1432 Warnings.Table (Warnings.Last).Stop := Source_Ptr'Last;
1433 end if;
1435 -- Set the error nodes to Empty to avoid uninitialized variable
1436 -- references for saves/restores/moves.
1438 Error_Msg_Node_1 := Empty;
1439 Error_Msg_Node_2 := Empty;
1440 end Initialize;
1442 -----------------
1443 -- No_Warnings --
1444 -----------------
1446 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1447 begin
1448 if Error_Posted (N) then
1449 return True;
1451 elsif Nkind (N) in N_Entity and then Warnings_Off (N) then
1452 return True;
1454 elsif Is_Entity_Name (N)
1455 and then Present (Entity (N))
1456 and then Warnings_Off (Entity (N))
1457 then
1458 return True;
1460 else
1461 return False;
1462 end if;
1463 end No_Warnings;
1465 -------------
1466 -- OK_Node --
1467 -------------
1469 function OK_Node (N : Node_Id) return Boolean is
1470 K : constant Node_Kind := Nkind (N);
1472 begin
1473 if Error_Posted (N) then
1474 return False;
1476 elsif K in N_Has_Etype
1477 and then Present (Etype (N))
1478 and then Error_Posted (Etype (N))
1479 then
1480 return False;
1482 elsif (K in N_Op
1483 or else K = N_Attribute_Reference
1484 or else K = N_Character_Literal
1485 or else K = N_Expanded_Name
1486 or else K = N_Identifier
1487 or else K = N_Operator_Symbol)
1488 and then Present (Entity (N))
1489 and then Error_Posted (Entity (N))
1490 then
1491 return False;
1492 else
1493 return True;
1494 end if;
1495 end OK_Node;
1497 ------------------------
1498 -- Output_Source_Line --
1499 ------------------------
1501 procedure Output_Source_Line
1502 (L : Physical_Line_Number;
1503 Sfile : Source_File_Index;
1504 Errs : Boolean)
1506 S : Source_Ptr;
1507 C : Character;
1509 Line_Number_Output : Boolean := False;
1510 -- Set True once line number is output
1512 begin
1513 if Sfile /= Current_Error_Source_File then
1514 Write_Str ("==============Error messages for ");
1516 case Sinput.File_Type (Sfile) is
1517 when Sinput.Src =>
1518 Write_Str ("source");
1520 when Sinput.Config =>
1521 Write_Str ("configuration pragmas");
1523 when Sinput.Def =>
1524 Write_Str ("symbol definition");
1526 when Sinput.Preproc =>
1527 Write_Str ("preprocessing data");
1528 end case;
1530 Write_Str (" file: ");
1531 Write_Name (Full_File_Name (Sfile));
1532 Write_Eol;
1534 if Num_SRef_Pragmas (Sfile) > 0 then
1535 Write_Str ("--------------Line numbers from file: ");
1536 Write_Name (Full_Ref_Name (Sfile));
1537 Write_Str (" (starting at line ");
1538 Write_Int (Int (First_Mapped_Line (Sfile)));
1539 Write_Char (')');
1540 Write_Eol;
1541 end if;
1543 Current_Error_Source_File := Sfile;
1544 end if;
1546 if Errs or List_Pragmas_Mode then
1547 Output_Line_Number (Physical_To_Logical (L, Sfile));
1548 Line_Number_Output := True;
1549 end if;
1551 S := Line_Start (L, Sfile);
1553 loop
1554 C := Source_Text (Sfile) (S);
1555 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
1557 -- Deal with matching entry in List_Pragmas table
1559 if Full_List
1560 and then List_Pragmas_Index <= List_Pragmas.Last
1561 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
1562 then
1563 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
1564 when Page =>
1565 Write_Char (C);
1567 -- Ignore if on line with errors so that error flags
1568 -- get properly listed with the error line .
1570 if not Errs then
1571 Write_Char (ASCII.FF);
1572 end if;
1574 when List_On =>
1575 List_Pragmas_Mode := True;
1577 if not Line_Number_Output then
1578 Output_Line_Number (Physical_To_Logical (L, Sfile));
1579 Line_Number_Output := True;
1580 end if;
1582 Write_Char (C);
1584 when List_Off =>
1585 Write_Char (C);
1586 List_Pragmas_Mode := False;
1587 end case;
1589 List_Pragmas_Index := List_Pragmas_Index + 1;
1591 -- Normal case (no matching entry in List_Pragmas table)
1593 else
1594 if Errs or List_Pragmas_Mode then
1595 Write_Char (C);
1596 end if;
1597 end if;
1599 S := S + 1;
1600 end loop;
1602 if Line_Number_Output then
1603 Write_Eol;
1604 end if;
1605 end Output_Source_Line;
1607 -----------------------------
1608 -- Remove_Warning_Messages --
1609 -----------------------------
1611 procedure Remove_Warning_Messages (N : Node_Id) is
1613 function Check_For_Warning (N : Node_Id) return Traverse_Result;
1614 -- This function checks one node for a possible warning message
1616 function Check_All_Warnings is new
1617 Traverse_Func (Check_For_Warning);
1618 -- This defines the traversal operation
1620 -----------------------
1621 -- Check_For_Warning --
1622 -----------------------
1624 function Check_For_Warning (N : Node_Id) return Traverse_Result is
1625 Loc : constant Source_Ptr := Sloc (N);
1626 E : Error_Msg_Id;
1628 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
1629 -- Returns True for a message that is to be removed. Also adjusts
1630 -- warning count appropriately.
1632 -------------------
1633 -- To_Be_Removed --
1634 -------------------
1636 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
1637 begin
1638 if E /= No_Error_Msg
1639 and then Errors.Table (E).Optr = Loc
1640 and then (Errors.Table (E).Warn or Errors.Table (E).Style)
1641 then
1642 Warnings_Detected := Warnings_Detected - 1;
1643 return True;
1644 else
1645 return False;
1646 end if;
1647 end To_Be_Removed;
1649 -- Start of processing for Check_For_Warnings
1651 begin
1652 while To_Be_Removed (First_Error_Msg) loop
1653 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
1654 end loop;
1656 if First_Error_Msg = No_Error_Msg then
1657 Last_Error_Msg := No_Error_Msg;
1658 end if;
1660 E := First_Error_Msg;
1661 while E /= No_Error_Msg loop
1662 while To_Be_Removed (Errors.Table (E).Next) loop
1663 Errors.Table (E).Next :=
1664 Errors.Table (Errors.Table (E).Next).Next;
1666 if Errors.Table (E).Next = No_Error_Msg then
1667 Last_Error_Msg := E;
1668 end if;
1669 end loop;
1671 E := Errors.Table (E).Next;
1672 end loop;
1674 if Nkind (N) = N_Raise_Constraint_Error
1675 and then Original_Node (N) /= N
1676 and then No (Condition (N))
1677 then
1678 -- Warnings may have been posted on subexpressions of
1679 -- the original tree. We place the original node back
1680 -- on the tree to remove those warnings, whose sloc
1681 -- do not match those of any node in the current tree.
1682 -- Given that we are in unreachable code, this modification
1683 -- to the tree is harmless.
1685 declare
1686 Status : Traverse_Result;
1688 begin
1689 if Is_List_Member (N) then
1690 Set_Condition (N, Original_Node (N));
1691 Status := Check_All_Warnings (Condition (N));
1692 else
1693 Rewrite (N, Original_Node (N));
1694 Status := Check_All_Warnings (N);
1695 end if;
1697 return Status;
1698 end;
1700 else
1701 return OK;
1702 end if;
1703 end Check_For_Warning;
1705 -- Start of processing for Remove_Warning_Messages
1707 begin
1708 if Warnings_Detected /= 0 then
1709 declare
1710 Discard : Traverse_Result;
1711 pragma Warnings (Off, Discard);
1713 begin
1714 Discard := Check_All_Warnings (N);
1715 end;
1716 end if;
1717 end Remove_Warning_Messages;
1719 procedure Remove_Warning_Messages (L : List_Id) is
1720 Stat : Node_Id;
1721 begin
1722 if Is_Non_Empty_List (L) then
1723 Stat := First (L);
1725 while Present (Stat) loop
1726 Remove_Warning_Messages (Stat);
1727 Next (Stat);
1728 end loop;
1729 end if;
1730 end Remove_Warning_Messages;
1732 ---------------------------
1733 -- Set_Identifier_Casing --
1734 ---------------------------
1736 procedure Set_Identifier_Casing
1737 (Identifier_Name : System.Address;
1738 File_Name : System.Address)
1740 type Big_String is array (Positive) of Character;
1741 type Big_String_Ptr is access all Big_String;
1743 function To_Big_String_Ptr is new Unchecked_Conversion
1744 (System.Address, Big_String_Ptr);
1746 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
1747 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
1748 Flen : Natural;
1750 Desired_Case : Casing_Type := Mixed_Case;
1751 -- Casing required for result. Default value of Mixed_Case is used if
1752 -- for some reason we cannot find the right file name in the table.
1754 begin
1755 -- Get length of file name
1757 Flen := 0;
1758 while File (Flen + 1) /= ASCII.NUL loop
1759 Flen := Flen + 1;
1760 end loop;
1762 -- Loop through file names to find matching one. This is a bit slow,
1763 -- but we only do it in error situations so it is not so terrible.
1764 -- Note that if the loop does not exit, then the desired case will
1765 -- be left set to Mixed_Case, this can happen if the name was not
1766 -- in canonical form, and gets canonicalized on VMS. Possibly we
1767 -- could fix this by unconditinally canonicalizing these names ???
1769 for J in 1 .. Last_Source_File loop
1770 Get_Name_String (Full_Debug_Name (J));
1772 if Name_Len = Flen
1773 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
1774 then
1775 Desired_Case := Identifier_Casing (J);
1776 exit;
1777 end if;
1778 end loop;
1780 -- Copy identifier as given to Name_Buffer
1782 for J in Name_Buffer'Range loop
1783 Name_Buffer (J) := Ident (J);
1785 if Name_Buffer (J) = ASCII.Nul then
1786 Name_Len := J - 1;
1787 exit;
1788 end if;
1789 end loop;
1791 Set_Casing (Desired_Case);
1792 end Set_Identifier_Casing;
1794 -----------------------
1795 -- Set_Ignore_Errors --
1796 -----------------------
1798 procedure Set_Ignore_Errors (To : Boolean) is
1799 begin
1800 Errors_Must_Be_Ignored := To;
1801 end Set_Ignore_Errors;
1803 ------------------------------
1804 -- Set_Msg_Insertion_Column --
1805 ------------------------------
1807 procedure Set_Msg_Insertion_Column is
1808 begin
1809 if Style.RM_Column_Check then
1810 Set_Msg_Str (" in column ");
1811 Set_Msg_Int (Int (Error_Msg_Col) + 1);
1812 end if;
1813 end Set_Msg_Insertion_Column;
1815 ----------------------------
1816 -- Set_Msg_Insertion_Node --
1817 ----------------------------
1819 procedure Set_Msg_Insertion_Node is
1820 K : Node_Kind;
1822 begin
1823 Suppress_Message :=
1824 Error_Msg_Node_1 = Error
1825 or else Error_Msg_Node_1 = Any_Type;
1827 if Error_Msg_Node_1 = Empty then
1828 Set_Msg_Blank_Conditional;
1829 Set_Msg_Str ("<empty>");
1831 elsif Error_Msg_Node_1 = Error then
1832 Set_Msg_Blank;
1833 Set_Msg_Str ("<error>");
1835 elsif Error_Msg_Node_1 = Standard_Void_Type then
1836 Set_Msg_Blank;
1837 Set_Msg_Str ("procedure name");
1839 else
1840 Set_Msg_Blank_Conditional;
1842 -- Output name
1844 K := Nkind (Error_Msg_Node_1);
1846 -- If we have operator case, skip quotes since name of operator
1847 -- itself will supply the required quotations. An operator can be
1848 -- an applied use in an expression or an explicit operator symbol,
1849 -- or an identifier whose name indicates it is an operator.
1851 if K in N_Op
1852 or else K = N_Operator_Symbol
1853 or else K = N_Defining_Operator_Symbol
1854 or else ((K = N_Identifier or else K = N_Defining_Identifier)
1855 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
1856 then
1857 Set_Msg_Node (Error_Msg_Node_1);
1859 -- Normal case, not an operator, surround with quotes
1861 else
1862 Set_Msg_Quote;
1863 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
1864 Set_Msg_Node (Error_Msg_Node_1);
1865 Set_Msg_Quote;
1866 end if;
1867 end if;
1869 -- The following assignment ensures that a second ampersand insertion
1870 -- character will correspond to the Error_Msg_Node_2 parameter.
1872 Error_Msg_Node_1 := Error_Msg_Node_2;
1873 end Set_Msg_Insertion_Node;
1875 --------------------------------------
1876 -- Set_Msg_Insertion_Type_Reference --
1877 --------------------------------------
1879 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
1880 Ent : Entity_Id;
1882 begin
1883 Set_Msg_Blank;
1885 if Error_Msg_Node_1 = Standard_Void_Type then
1886 Set_Msg_Str ("package or procedure name");
1887 return;
1889 elsif Error_Msg_Node_1 = Standard_Exception_Type then
1890 Set_Msg_Str ("exception name");
1891 return;
1893 elsif Error_Msg_Node_1 = Any_Access
1894 or else Error_Msg_Node_1 = Any_Array
1895 or else Error_Msg_Node_1 = Any_Boolean
1896 or else Error_Msg_Node_1 = Any_Character
1897 or else Error_Msg_Node_1 = Any_Composite
1898 or else Error_Msg_Node_1 = Any_Discrete
1899 or else Error_Msg_Node_1 = Any_Fixed
1900 or else Error_Msg_Node_1 = Any_Integer
1901 or else Error_Msg_Node_1 = Any_Modular
1902 or else Error_Msg_Node_1 = Any_Numeric
1903 or else Error_Msg_Node_1 = Any_Real
1904 or else Error_Msg_Node_1 = Any_Scalar
1905 or else Error_Msg_Node_1 = Any_String
1906 then
1907 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
1908 Set_Msg_Name_Buffer;
1909 return;
1911 elsif Error_Msg_Node_1 = Universal_Real then
1912 Set_Msg_Str ("type universal real");
1913 return;
1915 elsif Error_Msg_Node_1 = Universal_Integer then
1916 Set_Msg_Str ("type universal integer");
1917 return;
1919 elsif Error_Msg_Node_1 = Universal_Fixed then
1920 Set_Msg_Str ("type universal fixed");
1921 return;
1922 end if;
1924 -- Special case of anonymous array
1926 if Nkind (Error_Msg_Node_1) in N_Entity
1927 and then Is_Array_Type (Error_Msg_Node_1)
1928 and then Present (Related_Array_Object (Error_Msg_Node_1))
1929 then
1930 Set_Msg_Str ("type of ");
1931 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
1932 Set_Msg_Str (" declared");
1933 Set_Msg_Insertion_Line_Number
1934 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
1935 return;
1936 end if;
1938 -- If we fall through, it is not a special case, so first output
1939 -- the name of the type, preceded by private for a private type
1941 if Is_Private_Type (Error_Msg_Node_1) then
1942 Set_Msg_Str ("private type ");
1943 else
1944 Set_Msg_Str ("type ");
1945 end if;
1947 Ent := Error_Msg_Node_1;
1949 if Is_Internal_Name (Chars (Ent)) then
1950 Unwind_Internal_Type (Ent);
1951 end if;
1953 -- Types in Standard are displayed as "Standard.name"
1955 if Sloc (Ent) <= Standard_Location then
1956 Set_Msg_Quote;
1957 Set_Msg_Str ("Standard.");
1958 Set_Msg_Node (Ent);
1959 Add_Class;
1960 Set_Msg_Quote;
1962 -- Types in other language defined units are displayed as
1963 -- "package-name.type-name"
1965 elsif
1966 Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Ent)))
1967 then
1968 Get_Unqualified_Decoded_Name_String
1969 (Unit_Name (Get_Source_Unit (Ent)));
1970 Name_Len := Name_Len - 2;
1971 Set_Msg_Quote;
1972 Set_Casing (Mixed_Case);
1973 Set_Msg_Name_Buffer;
1974 Set_Msg_Char ('.');
1975 Set_Casing (Mixed_Case);
1976 Set_Msg_Node (Ent);
1977 Add_Class;
1978 Set_Msg_Quote;
1980 -- All other types display as "type name" defined at line xxx
1981 -- possibly qualified if qualification is requested.
1983 else
1984 Set_Msg_Quote;
1985 Set_Qualification (Error_Msg_Qual_Level, Ent);
1986 Set_Msg_Node (Ent);
1987 Add_Class;
1988 Set_Msg_Quote;
1989 end if;
1991 -- If the original type did not come from a predefined
1992 -- file, add the location where the type was defined.
1994 if Sloc (Error_Msg_Node_1) > Standard_Location
1995 and then
1996 not Is_Predefined_File_Name
1997 (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)))
1998 then
1999 Set_Msg_Str (" defined");
2000 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
2002 -- If it did come from a predefined file, deal with the case where
2003 -- this was a file with a generic instantiation from elsewhere.
2005 else
2006 if Sloc (Error_Msg_Node_1) > Standard_Location then
2007 declare
2008 Iloc : constant Source_Ptr :=
2009 Instantiation_Location (Sloc (Error_Msg_Node_1));
2011 begin
2012 if Iloc /= No_Location
2013 and then not Suppress_Instance_Location
2014 then
2015 Set_Msg_Str (" from instance");
2016 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2017 end if;
2018 end;
2019 end if;
2020 end if;
2021 end Set_Msg_Insertion_Type_Reference;
2023 ---------------------------------
2024 -- Set_Msg_Insertion_Unit_Name --
2025 ---------------------------------
2027 procedure Set_Msg_Insertion_Unit_Name is
2028 begin
2029 if Error_Msg_Unit_1 = No_Name then
2030 null;
2032 elsif Error_Msg_Unit_1 = Error_Name then
2033 Set_Msg_Blank;
2034 Set_Msg_Str ("<error>");
2036 else
2037 Get_Unit_Name_String (Error_Msg_Unit_1);
2038 Set_Msg_Blank;
2039 Set_Msg_Quote;
2040 Set_Msg_Name_Buffer;
2041 Set_Msg_Quote;
2042 end if;
2044 -- The following assignment ensures that a second percent insertion
2045 -- character will correspond to the Error_Msg_Unit_2 parameter.
2047 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2048 end Set_Msg_Insertion_Unit_Name;
2050 ------------------
2051 -- Set_Msg_Node --
2052 ------------------
2054 procedure Set_Msg_Node (Node : Node_Id) is
2055 Ent : Entity_Id;
2056 Nam : Name_Id;
2058 begin
2059 if Nkind (Node) = N_Designator then
2060 Set_Msg_Node (Name (Node));
2061 Set_Msg_Char ('.');
2062 Set_Msg_Node (Identifier (Node));
2063 return;
2065 elsif Nkind (Node) = N_Defining_Program_Unit_Name then
2066 Set_Msg_Node (Name (Node));
2067 Set_Msg_Char ('.');
2068 Set_Msg_Node (Defining_Identifier (Node));
2069 return;
2071 elsif Nkind (Node) = N_Selected_Component then
2072 Set_Msg_Node (Prefix (Node));
2073 Set_Msg_Char ('.');
2074 Set_Msg_Node (Selector_Name (Node));
2075 return;
2076 end if;
2078 -- The only remaining possibilities are identifiers, defining
2079 -- identifiers, pragmas, and pragma argument associations, i.e.
2080 -- nodes that have a Chars field.
2082 -- Internal names generally represent something gone wrong. An exception
2083 -- is the case of internal type names, where we try to find a reasonable
2084 -- external representation for the external name
2086 if Is_Internal_Name (Chars (Node))
2087 and then
2088 ((Is_Entity_Name (Node)
2089 and then Present (Entity (Node))
2090 and then Is_Type (Entity (Node)))
2091 or else
2092 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2093 then
2094 if Nkind (Node) = N_Identifier then
2095 Ent := Entity (Node);
2096 else
2097 Ent := Node;
2098 end if;
2100 Unwind_Internal_Type (Ent);
2101 Nam := Chars (Ent);
2103 else
2104 Nam := Chars (Node);
2105 end if;
2107 -- At this stage, the name to output is in Nam
2109 Get_Unqualified_Decoded_Name_String (Nam);
2111 -- Remove trailing upper case letters from the name (useful for
2112 -- dealing with some cases of internal names.
2114 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
2115 Name_Len := Name_Len - 1;
2116 end loop;
2118 -- If we have any of the names from standard that start with the
2119 -- characters "any " (e.g. Any_Type), then kill the message since
2120 -- almost certainly it is a junk cascaded message.
2122 if Name_Len > 4
2123 and then Name_Buffer (1 .. 4) = "any "
2124 then
2125 Kill_Message := True;
2126 end if;
2128 -- Now we have to set the proper case. If we have a source location
2129 -- then do a check to see if the name in the source is the same name
2130 -- as the name in the Names table, except for possible differences
2131 -- in case, which is the case when we can copy from the source.
2133 declare
2134 Src_Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
2135 Sbuffer : Source_Buffer_Ptr;
2136 Ref_Ptr : Integer;
2137 Src_Ptr : Source_Ptr;
2139 begin
2140 Ref_Ptr := 1;
2141 Src_Ptr := Src_Loc;
2143 -- For standard locations, always use mixed case
2145 if Src_Loc <= No_Location
2146 or else Sloc (Node) <= No_Location
2147 then
2148 Set_Casing (Mixed_Case);
2150 else
2151 -- Determine if the reference we are dealing with corresponds
2152 -- to text at the point of the error reference. This will often
2153 -- be the case for simple identifier references, and is the case
2154 -- where we can copy the spelling from the source.
2156 Sbuffer := Source_Text (Get_Source_File_Index (Src_Loc));
2158 while Ref_Ptr <= Name_Len loop
2159 exit when
2160 Fold_Lower (Sbuffer (Src_Ptr)) /=
2161 Fold_Lower (Name_Buffer (Ref_Ptr));
2162 Ref_Ptr := Ref_Ptr + 1;
2163 Src_Ptr := Src_Ptr + 1;
2164 end loop;
2166 -- If we get through the loop without a mismatch, then output
2167 -- the name the way it is spelled in the source program
2169 if Ref_Ptr > Name_Len then
2170 Src_Ptr := Src_Loc;
2172 for J in 1 .. Name_Len loop
2173 Name_Buffer (J) := Sbuffer (Src_Ptr);
2174 Src_Ptr := Src_Ptr + 1;
2175 end loop;
2177 -- Otherwise set the casing using the default identifier casing
2179 else
2180 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
2181 end if;
2182 end if;
2183 end;
2185 Set_Msg_Name_Buffer;
2186 Add_Class;
2187 end Set_Msg_Node;
2189 ------------------
2190 -- Set_Msg_Text --
2191 ------------------
2193 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2194 C : Character; -- Current character
2195 P : Natural; -- Current index;
2197 begin
2198 Manual_Quote_Mode := False;
2199 Is_Unconditional_Msg := False;
2200 Msglen := 0;
2201 Flag_Source := Get_Source_File_Index (Flag);
2202 P := Text'First;
2204 while P <= Text'Last loop
2205 C := Text (P);
2206 P := P + 1;
2208 -- Check for insertion character
2210 case C is
2211 when '%' =>
2212 Set_Msg_Insertion_Name;
2214 when '$' =>
2215 Set_Msg_Insertion_Unit_Name;
2217 when '{' =>
2218 Set_Msg_Insertion_File_Name;
2220 when '}' =>
2221 Set_Msg_Insertion_Type_Reference (Flag);
2223 when '*' =>
2224 Set_Msg_Insertion_Reserved_Name;
2226 when '&' =>
2227 Set_Msg_Insertion_Node;
2229 when '#' =>
2230 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
2232 when '\' =>
2233 Continuation := True;
2235 when '@' =>
2236 Set_Msg_Insertion_Column;
2238 when '>' =>
2239 Set_Msg_Insertion_Run_Time_Name;
2241 when '^' =>
2242 Set_Msg_Insertion_Uint;
2244 when '`' =>
2245 Manual_Quote_Mode := not Manual_Quote_Mode;
2246 Set_Msg_Char ('"');
2248 when '!' =>
2249 Is_Unconditional_Msg := True;
2251 when '?' =>
2252 null; -- already dealt with
2254 when '<' =>
2255 null; -- already dealt with
2257 when '|' =>
2258 null; -- already dealt with
2260 when ''' =>
2261 Set_Msg_Char (Text (P));
2262 P := P + 1;
2264 -- Upper case letter
2266 when 'A' .. 'Z' =>
2268 -- Start of reserved word if two or more
2270 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
2271 P := P - 1;
2272 Set_Msg_Insertion_Reserved_Word (Text, P);
2274 -- Single upper case letter is just inserted
2276 else
2277 Set_Msg_Char (C);
2278 end if;
2280 -- Normal character with no special treatment
2282 when others =>
2283 Set_Msg_Char (C);
2284 end case;
2285 end loop;
2287 VMS_Convert;
2288 end Set_Msg_Text;
2290 ----------------
2291 -- Set_Posted --
2292 ----------------
2294 procedure Set_Posted (N : Node_Id) is
2295 P : Node_Id;
2297 begin
2298 if Is_Serious_Error then
2300 -- We always set Error_Posted on the node itself
2302 Set_Error_Posted (N);
2304 -- If it is a subexpression, then set Error_Posted on parents
2305 -- up to and including the first non-subexpression construct. This
2306 -- helps avoid cascaded error messages within a single expression.
2308 P := N;
2309 loop
2310 P := Parent (P);
2311 exit when No (P);
2312 Set_Error_Posted (P);
2313 exit when Nkind (P) not in N_Subexpr;
2314 end loop;
2316 -- A special check, if we just posted an error on an attribute
2317 -- definition clause, then also set the entity involved as posted.
2318 -- For example, this stops complaining about the alignment after
2319 -- complaining about the size, which is likely to be useless.
2321 if Nkind (P) = N_Attribute_Definition_Clause then
2322 if Is_Entity_Name (Name (P)) then
2323 Set_Error_Posted (Entity (Name (P)));
2324 end if;
2325 end if;
2326 end if;
2327 end Set_Posted;
2329 -----------------------
2330 -- Set_Qualification --
2331 -----------------------
2333 procedure Set_Qualification (N : Nat; E : Entity_Id) is
2334 begin
2335 if N /= 0 and then Scope (E) /= Standard_Standard then
2336 Set_Qualification (N - 1, Scope (E));
2337 Set_Msg_Node (Scope (E));
2338 Set_Msg_Char ('.');
2339 end if;
2340 end Set_Qualification;
2342 ------------------------
2343 -- Special_Msg_Delete --
2344 ------------------------
2346 function Special_Msg_Delete
2347 (Msg : String;
2348 N : Node_Or_Entity_Id;
2349 E : Node_Or_Entity_Id) return Boolean
2351 begin
2352 -- Never delete messages in -gnatdO mode
2354 if Debug_Flag_OO then
2355 return False;
2357 -- When an atomic object refers to a non-atomic type in the same
2358 -- scope, we implicitly make the type atomic. In the non-error
2359 -- case this is surely safe (and in fact prevents an error from
2360 -- occurring if the type is not atomic by default). But if the
2361 -- object cannot be made atomic, then we introduce an extra junk
2362 -- message by this manipulation, which we get rid of here.
2364 -- We identify this case by the fact that it references a type for
2365 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
2367 elsif Msg = "atomic access to & cannot be guaranteed"
2368 and then Is_Type (E)
2369 and then Is_Atomic (E)
2370 and then No (Get_Rep_Pragma (E, Name_Atomic))
2371 then
2372 return True;
2374 -- When a size is wrong for a frozen type there is no explicit
2375 -- size clause, and other errors have occurred, suppress the
2376 -- message, since it is likely that this size error is a cascaded
2377 -- result of other errors. The reason we eliminate unfrozen types
2378 -- is that messages issued before the freeze type are for sure OK.
2380 elsif Msg = "size for& too small, minimum allowed is ^"
2381 and then Is_Frozen (E)
2382 and then Serious_Errors_Detected > 0
2383 and then Nkind (N) /= N_Component_Clause
2384 and then Nkind (Parent (N)) /= N_Component_Clause
2385 and then
2386 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
2387 and then
2388 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
2389 and then
2390 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
2391 then
2392 return True;
2394 -- All special tests complete, so go ahead with message
2396 else
2397 return False;
2398 end if;
2399 end Special_Msg_Delete;
2401 --------------------------
2402 -- Unwind_Internal_Type --
2403 --------------------------
2405 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
2406 Derived : Boolean := False;
2407 Mchar : Character;
2408 Old_Ent : Entity_Id;
2410 begin
2411 -- Undo placement of a quote, since we will put it back later
2413 Mchar := Msg_Buffer (Msglen);
2415 if Mchar = '"' then
2416 Msglen := Msglen - 1;
2417 end if;
2419 -- The loop here deals with recursive types, we are trying to
2420 -- find a related entity that is not an implicit type. Note
2421 -- that the check with Old_Ent stops us from getting "stuck".
2422 -- Also, we don't output the "type derived from" message more
2423 -- than once in the case where we climb up multiple levels.
2425 loop
2426 Old_Ent := Ent;
2428 -- Implicit access type, use directly designated type
2430 if Is_Access_Type (Ent) then
2431 Set_Msg_Str ("access to ");
2432 Ent := Directly_Designated_Type (Ent);
2434 -- Classwide type
2436 elsif Is_Class_Wide_Type (Ent) then
2437 Class_Flag := True;
2438 Ent := Root_Type (Ent);
2440 -- Use base type if this is a subtype
2442 elsif Ent /= Base_Type (Ent) then
2443 Buffer_Remove ("type ");
2445 -- Avoid duplication "subtype of subtype of", and also replace
2446 -- "derived from subtype of" simply by "derived from"
2448 if not Buffer_Ends_With ("subtype of ")
2449 and then not Buffer_Ends_With ("derived from ")
2450 then
2451 Set_Msg_Str ("subtype of ");
2452 end if;
2454 Ent := Base_Type (Ent);
2456 -- If this is a base type with a first named subtype, use the
2457 -- first named subtype instead. This is not quite accurate in
2458 -- all cases, but it makes too much noise to be accurate and
2459 -- add 'Base in all cases. Note that we only do this is the
2460 -- first named subtype is not itself an internal name. This
2461 -- avoids the obvious loop (subtype->basetype->subtype) which
2462 -- would otherwise occur!)
2464 elsif Present (Freeze_Node (Ent))
2465 and then Present (First_Subtype_Link (Freeze_Node (Ent)))
2466 and then
2467 not Is_Internal_Name
2468 (Chars (First_Subtype_Link (Freeze_Node (Ent))))
2469 then
2470 Ent := First_Subtype_Link (Freeze_Node (Ent));
2472 -- Otherwise use root type
2474 else
2475 if not Derived then
2476 Buffer_Remove ("type ");
2478 -- Test for "subtype of type derived from" which seems
2479 -- excessive and is replaced by simply "type derived from"
2481 Buffer_Remove ("subtype of");
2483 -- Avoid duplication "type derived from type derived from"
2485 if not Buffer_Ends_With ("type derived from ") then
2486 Set_Msg_Str ("type derived from ");
2487 end if;
2489 Derived := True;
2490 end if;
2492 Ent := Etype (Ent);
2493 end if;
2495 -- If we are stuck in a loop, get out and settle for the internal
2496 -- name after all. In this case we set to kill the message if it
2497 -- is not the first error message (we really try hard not to show
2498 -- the dirty laundry of the implementation to the poor user!)
2500 if Ent = Old_Ent then
2501 Kill_Message := True;
2502 exit;
2503 end if;
2505 -- Get out if we finally found a non-internal name to use
2507 exit when not Is_Internal_Name (Chars (Ent));
2508 end loop;
2510 if Mchar = '"' then
2511 Set_Msg_Char ('"');
2512 end if;
2513 end Unwind_Internal_Type;
2515 -----------------
2516 -- VMS_Convert --
2517 -----------------
2519 procedure VMS_Convert is
2520 P : Natural;
2521 L : Natural;
2522 N : Natural;
2524 begin
2525 if not OpenVMS then
2526 return;
2527 end if;
2529 P := Msg_Buffer'First;
2530 loop
2531 if P >= Msglen then
2532 return;
2533 end if;
2535 if Msg_Buffer (P) = '-' then
2536 for G in Gnames'Range loop
2537 L := Gnames (G)'Length;
2539 -- See if we have "-ggg switch", where ggg is Gnames entry
2541 if P + L + 7 <= Msglen
2542 and then Msg_Buffer (P + 1 .. P + L) = Gnames (G).all
2543 and then Msg_Buffer (P + L + 1 .. P + L + 7) = " switch"
2544 then
2545 -- Replace by "/vvv qualifier", where vvv is Vnames entry
2547 N := Vnames (G)'Length;
2548 Msg_Buffer (P + N + 11 .. Msglen + N - L + 3) :=
2549 Msg_Buffer (P + L + 8 .. Msglen);
2550 Msg_Buffer (P) := '/';
2551 Msg_Buffer (P + 1 .. P + N) := Vnames (G).all;
2552 Msg_Buffer (P + N + 1 .. P + N + 10) := " qualifier";
2553 P := P + N + 10;
2554 Msglen := Msglen + N - L + 3;
2555 exit;
2556 end if;
2557 end loop;
2558 end if;
2560 P := P + 1;
2561 end loop;
2562 end VMS_Convert;
2564 end Errout;