Merge from the pain train
[official-gcc.git] / gcc / ada / errout.adb
blob6ddda3f0d45b6916d2be9d3700bfc35c05530354
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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Uintp; use Uintp;
53 with Uname; use Uname;
55 with Unchecked_Conversion;
57 package body Errout is
59 Errors_Must_Be_Ignored : Boolean := False;
60 -- Set to True by procedure Set_Ignore_Errors (True), when calls to
61 -- error message procedures should be ignored (when parsing irrelevant
62 -- text in sources being preprocessed).
64 Warn_On_Instance : Boolean;
65 -- Flag set true for warning message to be posted on instance
67 ------------------------------------
68 -- Table of Non-Instance Messages --
69 ------------------------------------
71 -- This table contains an entry for every error message processed by the
72 -- Error_Msg routine that is not posted on generic (or inlined) instance.
73 -- As explained in further detail in the Error_Msg procedure body, this
74 -- table is used to avoid posting redundant messages on instances.
76 type NIM_Record is record
77 Msg : String_Ptr;
78 Loc : Source_Ptr;
79 end record;
80 -- Type used to store text and location of one message
82 package Non_Instance_Msgs is new Table.Table (
83 Table_Component_Type => NIM_Record,
84 Table_Index_Type => Int,
85 Table_Low_Bound => 1,
86 Table_Initial => 100,
87 Table_Increment => 100,
88 Table_Name => "Non_Instance_Msgs");
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Error_Msg_Internal
95 (Msg : String;
96 Sptr : Source_Ptr;
97 Optr : Source_Ptr;
98 Msg_Cont : Boolean);
99 -- This is the low level routine used to post messages after dealing with
100 -- the issue of messages placed on instantiations (which get broken up
101 -- into separate calls in Error_Msg). Sptr is the location on which the
102 -- flag will be placed in the output. In the case where the flag is on
103 -- the template, this points directly to the template, not to one of the
104 -- instantiation copies of the template. Optr is the original location
105 -- used to flag the error, and this may indeed point to an instantiation
106 -- copy. So typically we can see Optr pointing to the template location
107 -- in an instantiation copy when Sptr points to the source location of
108 -- the actual instantiation (i.e the line with the new). Msg_Cont is
109 -- set true if this is a continuation message.
111 function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
112 -- Determines if warnings should be suppressed for the given node
114 function OK_Node (N : Node_Id) return Boolean;
115 -- Determines if a node is an OK node to place an error message on (return
116 -- True) or if the error message should be suppressed (return False). A
117 -- message is suppressed if the node already has an error posted on it,
118 -- or if it refers to an Etype that has an error posted on it, or if
119 -- it references an Entity that has an error posted on it.
121 procedure Output_Source_Line
122 (L : Physical_Line_Number;
123 Sfile : Source_File_Index;
124 Errs : Boolean);
125 -- Outputs text of source line L, in file S, together with preceding line
126 -- number, as described above for Output_Line_Number. The Errs parameter
127 -- indicates if there are errors attached to the line, which forces
128 -- listing on, even in the presence of pragma List (Off).
130 procedure Set_Msg_Insertion_Column;
131 -- Handle column number insertion (@ insertion character)
133 procedure Set_Msg_Insertion_Node;
134 -- Handle node (name from node) insertion (& insertion character)
136 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
137 -- Handle type reference (right brace insertion character). Flag is the
138 -- location of the flag, which is provided for the internal call to
139 -- Set_Msg_Insertion_Line_Number,
141 procedure Set_Msg_Insertion_Unit_Name;
142 -- Handle unit name insertion ($ insertion character)
144 procedure Set_Msg_Node (Node : Node_Id);
145 -- Add the sequence of characters for the name associated with the
146 -- given node to the current message.
148 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
149 -- Add a sequence of characters to the current message. The characters may
150 -- be one of the special insertion characters (see documentation in spec).
151 -- Flag is the location at which the error is to be posted, which is used
152 -- to determine whether or not the # insertion needs a file name. The
153 -- variables Msg_Buffer, Msglen, Is_Style_Msg, Is_Warning_Msg, and
154 -- Is_Unconditional_Msg are set on return.
156 procedure Set_Posted (N : Node_Id);
157 -- Sets the Error_Posted flag on the given node, and all its parents
158 -- that are subexpressions and then on the parent non-subexpression
159 -- construct that contains the original expression (this reduces the
160 -- number of cascaded messages). Note that this call only has an effect
161 -- for a serious error. For a non-serious error, it has no effect.
163 procedure Set_Qualification (N : Nat; E : Entity_Id);
164 -- Outputs up to N levels of qualification for the given entity. For
165 -- example, the entity A.B.C.D will output B.C. if N = 2.
167 function Special_Msg_Delete
168 (Msg : String;
169 N : Node_Or_Entity_Id;
170 E : Node_Or_Entity_Id) return Boolean;
171 -- This function is called from Error_Msg_NEL, passing the message Msg,
172 -- node N on which the error is to be posted, and the entity or node E
173 -- to be used for an & insertion in the message if any. The job of this
174 -- procedure is to test for certain cascaded messages that we would like
175 -- to suppress. If the message is to be suppressed then we return True.
176 -- If the message should be generated (the normal case) False is returned.
178 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
179 -- This procedure is given an entity id for an internal type, i.e.
180 -- a type with an internal name. It unwinds the type to try to get
181 -- to something reasonably printable, generating prefixes like
182 -- "subtype of", "access to", etc along the way in the buffer. The
183 -- value in Ent on return is the final name to be printed. Hopefully
184 -- this is not an internal name, but in some internal name cases, it
185 -- is an internal name, and has to be printed anyway (although in this
186 -- case the message has been killed if possible). The global variable
187 -- Class_Flag is set to True if the resulting entity should have
188 -- 'Class appended to its name (see Add_Class procedure), and is
189 -- otherwise unchanged.
191 procedure VMS_Convert;
192 -- This procedure has no effect if called when the host is not OpenVMS.
193 -- If the host is indeed OpenVMS, then the error message stored in
194 -- Msg_Buffer is scanned for appearences of switch names which need
195 -- converting to corresponding VMS qualifer names. See Gnames/Vnames
196 -- table in Errout spec for precise definition of the conversion that
197 -- is performed by this routine in OpenVMS mode.
199 -----------------------
200 -- Change_Error_Text --
201 -----------------------
203 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
204 Save_Next : Error_Msg_Id;
205 Err_Id : Error_Msg_Id := Error_Id;
207 begin
208 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr);
209 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
211 -- If in immediate error message mode, output modified error message now
212 -- This is just a bit tricky, because we want to output just a single
213 -- message, and the messages we modified is already linked in. We solve
214 -- this by temporarily resetting its forward pointer to empty.
216 if Debug_Flag_OO then
217 Save_Next := Errors.Table (Error_Id).Next;
218 Errors.Table (Error_Id).Next := No_Error_Msg;
219 Write_Eol;
220 Output_Source_Line
221 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
222 Output_Error_Msgs (Err_Id);
223 Errors.Table (Error_Id).Next := Save_Next;
224 end if;
225 end Change_Error_Text;
227 ---------------
228 -- Error_Msg --
229 ---------------
231 -- Error_Msg posts a flag at the given location, except that if the
232 -- Flag_Location points within a generic template and corresponds
233 -- to an instantiation of this generic template, then the actual
234 -- message will be posted on the generic instantiation, along with
235 -- additional messages referencing the generic declaration.
237 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
238 Sindex : Source_File_Index;
239 -- Source index for flag location
241 Orig_Loc : Source_Ptr;
242 -- Original location of Flag_Location (i.e. location in original
243 -- template in instantiation case, otherwise unchanged).
245 begin
246 -- It is a fatal error to issue an error message when scanning from
247 -- the internal source buffer (see Sinput for further documentation)
249 pragma Assert (Sinput.Source /= Internal_Source_Ptr);
251 -- Return if all errors are to be ignored
253 if Errors_Must_Be_Ignored then
254 return;
255 end if;
257 -- If we already have messages, and we are trying to place a message
258 -- at No_Location or in package Standard, then just ignore the attempt
259 -- since we assume that what is happening is some cascaded junk. Note
260 -- that this is safe in the sense that proceeding will surely bomb.
262 if Flag_Location < First_Source_Ptr
263 and then Total_Errors_Detected > 0
264 then
265 return;
266 end if;
268 -- Start procesing of new message
270 Sindex := Get_Source_File_Index (Flag_Location);
271 Test_Style_Warning_Serious_Msg (Msg);
272 Orig_Loc := Original_Location (Flag_Location);
274 -- If the current location is in an instantiation, the issue arises
275 -- of whether to post the message on the template or the instantiation.
277 -- The way we decide is to see if we have posted the same message
278 -- on the template when we compiled the template (the template is
279 -- always compiled before any instantiations). For this purpose,
280 -- we use a separate table of messages. The reason we do this is
281 -- twofold:
283 -- First, the messages can get changed by various processing
284 -- including the insertion of tokens etc, making it hard to
285 -- do the comparison.
287 -- Second, we will suppress a warning on a template if it is
288 -- not in the current extended source unit. That's reasonable
289 -- and means we don't want the warning on the instantiation
290 -- here either, but it does mean that the main error table
291 -- would not in any case include the message.
293 if Flag_Location = Orig_Loc then
294 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
295 Warn_On_Instance := False;
297 -- Here we have an instance message
299 else
300 -- Delete if debug flag off, and this message duplicates a
301 -- message already posted on the corresponding template
303 if not Debug_Flag_GG then
304 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
305 if Msg = Non_Instance_Msgs.Table (J).Msg.all
306 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
307 then
308 return;
309 end if;
310 end loop;
311 end if;
313 -- No duplicate, so error/warning will be posted on instance
315 Warn_On_Instance := Is_Warning_Msg;
316 end if;
318 -- Ignore warning message that is suppressed. Note that style
319 -- checks are not considered warning messages for this purpose
321 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) then
322 return;
323 end if;
325 -- The idea at this stage is that we have two kinds of messages.
327 -- First, we have those that are to be placed as requested at
328 -- Flag_Location. This includes messages that have nothing to
329 -- do with generics, and also messages placed on generic templates
330 -- that reflect an error in the template itself. For such messages
331 -- we simply call Error_Msg_Internal to place the message in the
332 -- requested location.
334 if Instantiation (Sindex) = No_Location then
335 Error_Msg_Internal (Msg, Flag_Location, Flag_Location, False);
336 return;
337 end if;
339 -- If we are trying to flag an error in an instantiation, we may have
340 -- a generic contract violation. What we generate in this case is:
342 -- instantiation error at ...
343 -- original error message
345 -- or
347 -- warning: in instantiation at
348 -- warning: original warning message
350 -- All these messages are posted at the location of the top level
351 -- instantiation. If there are nested instantiations, then the
352 -- instantiation error message can be repeated, pointing to each
353 -- of the relevant instantiations.
355 -- Note: the instantiation mechanism is also shared for inlining
356 -- of subprogram bodies when front end inlining is done. In this
357 -- case the messages have the form:
359 -- in inlined body at ...
360 -- original error message
362 -- or
364 -- warning: in inlined body at
365 -- warning: original warning message
367 -- OK, this is the case where we have an instantiation error, and
368 -- we need to generate the error on the instantiation, rather than
369 -- on the template.
371 declare
372 Actual_Error_Loc : Source_Ptr;
373 -- Location of outer level instantiation in instantiation case, or
374 -- just a copy of Flag_Location in the normal case. This is the
375 -- location where all error messages will actually be posted.
377 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
378 -- Save possible location set for caller's message. We need to
379 -- use Error_Msg_Sloc for the location of the instantiation error
380 -- but we have to preserve a possible original value.
382 X : Source_File_Index;
384 Msg_Cont_Status : Boolean;
385 -- Used to label continuation lines in instantiation case with
386 -- proper Msg_Cont status.
388 begin
389 -- Loop to find highest level instantiation, where all error
390 -- messages will be placed.
392 X := Sindex;
393 loop
394 Actual_Error_Loc := Instantiation (X);
395 X := Get_Source_File_Index (Actual_Error_Loc);
396 exit when Instantiation (X) = No_Location;
397 end loop;
399 -- Since we are generating the messages at the instantiation
400 -- point in any case, we do not want the references to the
401 -- bad lines in the instance to be annotated with the location
402 -- of the instantiation.
404 Suppress_Instance_Location := True;
405 Msg_Cont_Status := False;
407 -- Loop to generate instantiation messages
409 Error_Msg_Sloc := Flag_Location;
410 X := Get_Source_File_Index (Flag_Location);
412 while Instantiation (X) /= No_Location loop
414 -- Suppress instantiation message on continuation lines
416 if Msg (Msg'First) /= '\' then
418 -- Case of inlined body
420 if Inlined_Body (X) then
421 if Is_Warning_Msg then
422 Error_Msg_Internal
423 ("?in inlined body #",
424 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
426 else
427 Error_Msg_Internal
428 ("error in inlined body #",
429 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
430 end if;
432 -- Case of generic instantiation
434 else
435 if Is_Warning_Msg then
436 Error_Msg_Internal
437 ("?in instantiation #",
438 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
440 else
441 Error_Msg_Internal
442 ("instantiation error #",
443 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
444 end if;
445 end if;
446 end if;
448 Error_Msg_Sloc := Instantiation (X);
449 X := Get_Source_File_Index (Error_Msg_Sloc);
450 Msg_Cont_Status := True;
451 end loop;
453 Suppress_Instance_Location := False;
454 Error_Msg_Sloc := Save_Error_Msg_Sloc;
456 -- Here we output the original message on the outer instantiation
458 Error_Msg_Internal
459 (Msg, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
460 end;
461 end Error_Msg;
463 ------------------
464 -- Error_Msg_AP --
465 ------------------
467 procedure Error_Msg_AP (Msg : String) is
468 S1 : Source_Ptr;
469 C : Character;
471 begin
472 -- If we had saved the Scan_Ptr value after scanning the previous
473 -- token, then we would have exactly the right place for putting
474 -- the flag immediately at hand. However, that would add at least
475 -- two instructions to a Scan call *just* to service the possibility
476 -- of an Error_Msg_AP call. So instead we reconstruct that value.
478 -- We have two possibilities, start with Prev_Token_Ptr and skip over
479 -- the current token, which is made harder by the possibility that this
480 -- token may be in error, or start with Token_Ptr and work backwards.
481 -- We used to take the second approach, but it's hard because of
482 -- comments, and harder still because things that look like comments
483 -- can appear inside strings. So now we take the first approach.
485 -- Note: in the case where there is no previous token, Prev_Token_Ptr
486 -- is set to Source_First, which is a reasonable position for the
487 -- error flag in this situation.
489 S1 := Prev_Token_Ptr;
490 C := Source (S1);
492 -- If the previous token is a string literal, we need a special approach
493 -- since there may be white space inside the literal and we don't want
494 -- to stop on that white space.
496 if Prev_Token = Tok_String_Literal then
497 loop
498 S1 := S1 + 1;
500 if Source (S1) = C then
501 S1 := S1 + 1;
502 exit when Source (S1) /= C;
503 elsif Source (S1) in Line_Terminator then
504 exit;
505 end if;
506 end loop;
508 -- Character literal also needs special handling
510 elsif Prev_Token = Tok_Char_Literal then
511 S1 := S1 + 3;
513 -- Otherwise we search forward for the end of the current token, marked
514 -- by a line terminator, white space, a comment symbol or if we bump
515 -- into the following token (i.e. the current token)
517 else
518 while Source (S1) not in Line_Terminator
519 and then Source (S1) /= ' '
520 and then Source (S1) /= ASCII.HT
521 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
522 and then S1 /= Token_Ptr
523 loop
524 S1 := S1 + 1;
525 end loop;
526 end if;
528 -- S1 is now set to the location for the flag
530 Error_Msg (Msg, S1);
532 end Error_Msg_AP;
534 ------------------
535 -- Error_Msg_BC --
536 ------------------
538 procedure Error_Msg_BC (Msg : String) is
539 begin
540 -- If we are at end of file, post the flag after the previous token
542 if Token = Tok_EOF then
543 Error_Msg_AP (Msg);
545 -- If we are at start of file, post the flag at the current token
547 elsif Token_Ptr = Source_First (Current_Source_File) then
548 Error_Msg_SC (Msg);
550 -- If the character before the current token is a space or a horizontal
551 -- tab, then we place the flag on this character (in the case of a tab
552 -- we would really like to place it in the "last" character of the tab
553 -- space, but that it too much trouble to worry about).
555 elsif Source (Token_Ptr - 1) = ' '
556 or else Source (Token_Ptr - 1) = ASCII.HT
557 then
558 Error_Msg (Msg, Token_Ptr - 1);
560 -- If there is no space or tab before the current token, then there is
561 -- no room to place the flag before the token, so we place it on the
562 -- token instead (this happens for example at the start of a line).
564 else
565 Error_Msg (Msg, Token_Ptr);
566 end if;
567 end Error_Msg_BC;
569 -------------------
570 -- Error_Msg_CRT --
571 -------------------
573 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
574 CNRT : constant String := " not allowed in no run time mode";
575 CCRT : constant String := " not supported by configuration>";
577 S : String (1 .. Feature'Length + 1 + CCRT'Length);
578 L : Natural;
581 begin
582 S (1) := '|';
583 S (2 .. Feature'Length + 1) := Feature;
584 L := Feature'Length + 2;
586 if No_Run_Time_Mode then
587 S (L .. L + CNRT'Length - 1) := CNRT;
588 L := L + CNRT'Length - 1;
590 else pragma Assert (Configurable_Run_Time_Mode);
591 S (L .. L + CCRT'Length - 1) := CCRT;
592 L := L + CCRT'Length - 1;
593 end if;
595 Error_Msg_N (S (1 .. L), N);
596 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
597 end Error_Msg_CRT;
599 -----------------
600 -- Error_Msg_F --
601 -----------------
603 procedure Error_Msg_F (Msg : String; N : Node_Id) is
604 begin
605 Error_Msg_NEL (Msg, N, N, First_Sloc (N));
606 end Error_Msg_F;
608 ------------------
609 -- Error_Msg_FE --
610 ------------------
612 procedure Error_Msg_FE
613 (Msg : String;
614 N : Node_Id;
615 E : Node_Or_Entity_Id)
617 begin
618 Error_Msg_NEL (Msg, N, E, Sloc (First_Node (N)));
619 end Error_Msg_FE;
621 ------------------------
622 -- Error_Msg_Internal --
623 ------------------------
625 procedure Error_Msg_Internal
626 (Msg : String;
627 Sptr : Source_Ptr;
628 Optr : Source_Ptr;
629 Msg_Cont : Boolean)
631 Next_Msg : Error_Msg_Id;
632 -- Pointer to next message at insertion point
634 Prev_Msg : Error_Msg_Id;
635 -- Pointer to previous message at insertion point
637 Temp_Msg : Error_Msg_Id;
639 procedure Handle_Serious_Error;
640 -- Internal procedure to do all error message handling for a serious
641 -- error message, other than bumping the error counts and arranging
642 -- for the message to be output.
644 --------------------------
645 -- Handle_Serious_Error --
646 --------------------------
648 procedure Handle_Serious_Error is
649 begin
650 -- Turn off code generation if not done already
652 if Operating_Mode = Generate_Code then
653 Operating_Mode := Check_Semantics;
654 Expander_Active := False;
655 end if;
657 -- Set the fatal error flag in the unit table unless we are
658 -- in Try_Semantics mode. This stops the semantics from being
659 -- performed if we find a serious error. This is skipped if we
660 -- are currently dealing with the configuration pragma file.
662 if not Try_Semantics
663 and then Current_Source_Unit /= No_Unit
664 then
665 Set_Fatal_Error (Get_Source_Unit (Sptr));
666 end if;
667 end Handle_Serious_Error;
669 -- Start of processing for Error_Msg_Internal
671 begin
672 if Raise_Exception_On_Error /= 0 then
673 raise Error_Msg_Exception;
674 end if;
676 Continuation := Msg_Cont;
677 Suppress_Message := False;
678 Kill_Message := False;
679 Set_Msg_Text (Msg, Sptr);
681 -- Kill continuation if parent message killed
683 if Continuation and Last_Killed then
684 return;
685 end if;
687 -- Return without doing anything if message is suppressed
689 if Suppress_Message
690 and not All_Errors_Mode
691 and not (Msg (Msg'Last) = '!')
692 then
693 if not Continuation then
694 Last_Killed := True;
695 end if;
697 return;
698 end if;
700 -- Return without doing anything if message is killed and this
701 -- is not the first error message. The philosophy is that if we
702 -- get a weird error message and we already have had a message,
703 -- then we hope the weird message is a junk cascaded message
705 if Kill_Message
706 and then not All_Errors_Mode
707 and then Total_Errors_Detected /= 0
708 then
709 if not Continuation then
710 Last_Killed := True;
711 end if;
713 return;
714 end if;
716 -- Special check for warning message to see if it should be output
718 if Is_Warning_Msg then
720 -- Immediate return if warning message and warnings are suppressed
722 if Warnings_Suppressed (Optr)
723 or else Warnings_Suppressed (Sptr)
724 then
725 Cur_Msg := No_Error_Msg;
726 return;
727 end if;
729 -- If the flag location is in the main extended source unit
730 -- then for sure we want the warning since it definitely belongs
732 if In_Extended_Main_Source_Unit (Sptr) then
733 null;
735 -- If the flag location is not in the main extended source
736 -- unit then we want to eliminate the warning.
738 elsif In_Extended_Main_Code_Unit (Sptr)
739 and then Warn_On_Instance
740 then
741 null;
743 -- Keep warning if debug flag G set
745 elsif Debug_Flag_GG then
746 null;
748 -- Here is where we delete a warning from a with'ed unit
750 else
751 Cur_Msg := No_Error_Msg;
752 return;
753 end if;
754 end if;
756 -- If message is to be ignored in special ignore message mode, this is
757 -- where we do this special processing, bypassing message output.
759 if Ignore_Errors_Enable > 0 then
760 if Is_Serious_Error then
761 Handle_Serious_Error;
762 end if;
764 return;
765 end if;
767 -- Otherwise build error message object for new message
769 Errors.Increment_Last;
770 Cur_Msg := Errors.Last;
771 Errors.Table (Cur_Msg).Text := new String'(Msg_Buffer (1 .. Msglen));
772 Errors.Table (Cur_Msg).Next := No_Error_Msg;
773 Errors.Table (Cur_Msg).Sptr := Sptr;
774 Errors.Table (Cur_Msg).Optr := Optr;
775 Errors.Table (Cur_Msg).Sfile := Get_Source_File_Index (Sptr);
776 Errors.Table (Cur_Msg).Line := Get_Physical_Line_Number (Sptr);
777 Errors.Table (Cur_Msg).Col := Get_Column_Number (Sptr);
778 Errors.Table (Cur_Msg).Warn := Is_Warning_Msg;
779 Errors.Table (Cur_Msg).Style := Is_Style_Msg;
780 Errors.Table (Cur_Msg).Serious := Is_Serious_Error;
781 Errors.Table (Cur_Msg).Uncond := Is_Unconditional_Msg;
782 Errors.Table (Cur_Msg).Msg_Cont := Continuation;
783 Errors.Table (Cur_Msg).Deleted := False;
785 -- If immediate errors mode set, output error message now. Also output
786 -- now if the -d1 debug flag is set (so node number message comes out
787 -- just before actual error message)
789 if Debug_Flag_OO or else Debug_Flag_1 then
790 Write_Eol;
791 Output_Source_Line (Errors.Table (Cur_Msg).Line,
792 Errors.Table (Cur_Msg).Sfile, True);
793 Temp_Msg := Cur_Msg;
794 Output_Error_Msgs (Temp_Msg);
796 -- If not in immediate errors mode, then we insert the message in the
797 -- error chain for later output by Finalize. The messages are sorted
798 -- first by unit (main unit comes first), and within a unit by source
799 -- location (earlier flag location first in the chain).
801 else
802 -- First a quick check, does this belong at the very end of the
803 -- chain of error messages. This saves a lot of time in the
804 -- normal case if there are lots of messages.
806 if Last_Error_Msg /= No_Error_Msg
807 and then Errors.Table (Cur_Msg).Sfile =
808 Errors.Table (Last_Error_Msg).Sfile
809 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
810 or else
811 (Sptr = Errors.Table (Last_Error_Msg).Sptr
812 and then
813 Optr > Errors.Table (Last_Error_Msg).Optr))
814 then
815 Prev_Msg := Last_Error_Msg;
816 Next_Msg := No_Error_Msg;
818 -- Otherwise do a full sequential search for the insertion point
820 else
821 Prev_Msg := No_Error_Msg;
822 Next_Msg := First_Error_Msg;
823 while Next_Msg /= No_Error_Msg loop
824 exit when
825 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
827 if Errors.Table (Cur_Msg).Sfile =
828 Errors.Table (Next_Msg).Sfile
829 then
830 exit when Sptr < Errors.Table (Next_Msg).Sptr
831 or else
832 (Sptr = Errors.Table (Next_Msg).Sptr
833 and then
834 Optr < Errors.Table (Next_Msg).Optr);
835 end if;
837 Prev_Msg := Next_Msg;
838 Next_Msg := Errors.Table (Next_Msg).Next;
839 end loop;
840 end if;
842 -- Now we insert the new message in the error chain. The insertion
843 -- point for the message is after Prev_Msg and before Next_Msg.
845 -- The possible insertion point for the new message is after Prev_Msg
846 -- and before Next_Msg. However, this is where we do a special check
847 -- for redundant parsing messages, defined as messages posted on the
848 -- same line. The idea here is that probably such messages are junk
849 -- from the parser recovering. In full errors mode, we don't do this
850 -- deletion, but otherwise such messages are discarded at this stage.
852 if Prev_Msg /= No_Error_Msg
853 and then Errors.Table (Prev_Msg).Line =
854 Errors.Table (Cur_Msg).Line
855 and then Errors.Table (Prev_Msg).Sfile =
856 Errors.Table (Cur_Msg).Sfile
857 and then Compiler_State = Parsing
858 and then not All_Errors_Mode
859 then
860 -- Don't delete unconditional messages and at this stage,
861 -- don't delete continuation lines (we attempted to delete
862 -- those earlier if the parent message was deleted.
864 if not Errors.Table (Cur_Msg).Uncond
865 and then not Continuation
866 then
867 -- Don't delete if prev msg is warning and new msg is
868 -- an error. This is because we don't want a real error
869 -- masked by a warning. In all other cases (that is parse
870 -- errors for the same line that are not unconditional)
871 -- we do delete the message. This helps to avoid
872 -- junk extra messages from cascaded parsing errors
874 if not (Errors.Table (Prev_Msg).Warn
876 Errors.Table (Prev_Msg).Style)
877 or else
878 (Errors.Table (Cur_Msg).Warn
880 Errors.Table (Cur_Msg).Style)
881 then
882 -- All tests passed, delete the message by simply
883 -- returning without any further processing.
885 if not Continuation then
886 Last_Killed := True;
887 end if;
889 return;
890 end if;
891 end if;
892 end if;
894 -- Come here if message is to be inserted in the error chain
896 if not Continuation then
897 Last_Killed := False;
898 end if;
900 if Prev_Msg = No_Error_Msg then
901 First_Error_Msg := Cur_Msg;
902 else
903 Errors.Table (Prev_Msg).Next := Cur_Msg;
904 end if;
906 Errors.Table (Cur_Msg).Next := Next_Msg;
908 if Next_Msg = No_Error_Msg then
909 Last_Error_Msg := Cur_Msg;
910 end if;
911 end if;
913 -- Bump appropriate statistics count
915 if Errors.Table (Cur_Msg).Warn
916 or else Errors.Table (Cur_Msg).Style
917 then
918 Warnings_Detected := Warnings_Detected + 1;
919 else
920 Total_Errors_Detected := Total_Errors_Detected + 1;
922 if Errors.Table (Cur_Msg).Serious then
923 Serious_Errors_Detected := Serious_Errors_Detected + 1;
924 Handle_Serious_Error;
925 end if;
926 end if;
928 -- Terminate if max errors reached
930 if Total_Errors_Detected + Warnings_Detected = Maximum_Errors then
931 raise Unrecoverable_Error;
932 end if;
934 end Error_Msg_Internal;
936 -----------------
937 -- Error_Msg_N --
938 -----------------
940 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
941 begin
942 Error_Msg_NEL (Msg, N, N, Sloc (N));
943 end Error_Msg_N;
945 ------------------
946 -- Error_Msg_NE --
947 ------------------
949 procedure Error_Msg_NE
950 (Msg : String;
951 N : Node_Or_Entity_Id;
952 E : Node_Or_Entity_Id)
954 begin
955 Error_Msg_NEL (Msg, N, E, Sloc (N));
956 end Error_Msg_NE;
958 -------------------
959 -- Error_Msg_NEL --
960 -------------------
962 procedure Error_Msg_NEL
963 (Msg : String;
964 N : Node_Or_Entity_Id;
965 E : Node_Or_Entity_Id;
966 Flag_Location : Source_Ptr)
968 begin
969 if Special_Msg_Delete (Msg, N, E) then
970 return;
971 end if;
973 Test_Style_Warning_Serious_Msg (Msg);
975 -- Special handling for warning messages
977 if Is_Warning_Msg then
979 -- Suppress if no warnings set for either entity or node
981 if No_Warnings (N) or else No_Warnings (E) then
982 return;
983 end if;
985 -- Suppress if inside loop that is known to be null
987 declare
988 P : Node_Id;
990 begin
991 P := Parent (N);
992 while Present (P) loop
993 if Nkind (P) = N_Loop_Statement and then Is_Null_Loop (P) then
994 return;
995 end if;
997 P := Parent (P);
998 end loop;
999 end;
1000 end if;
1002 -- Test for message to be output
1004 if All_Errors_Mode
1005 or else Msg (Msg'Last) = '!'
1006 or else OK_Node (N)
1007 or else (Msg (Msg'First) = '\' and not Last_Killed)
1008 then
1009 Debug_Output (N);
1010 Error_Msg_Node_1 := E;
1011 Error_Msg (Msg, Flag_Location);
1013 else
1014 Last_Killed := True;
1015 end if;
1017 if not Is_Warning_Msg and then not Is_Style_Msg then
1018 Set_Posted (N);
1019 end if;
1020 end Error_Msg_NEL;
1022 ------------------
1023 -- Error_Msg_NW --
1024 ------------------
1026 procedure Error_Msg_NW
1027 (Eflag : Boolean;
1028 Msg : String;
1029 N : Node_Or_Entity_Id)
1031 begin
1032 if Eflag and then In_Extended_Main_Source_Unit (N) then
1033 Error_Msg_NEL (Msg, N, N, Sloc (N));
1034 end if;
1035 end Error_Msg_NW;
1037 -----------------
1038 -- Error_Msg_S --
1039 -----------------
1041 procedure Error_Msg_S (Msg : String) is
1042 begin
1043 Error_Msg (Msg, Scan_Ptr);
1044 end Error_Msg_S;
1046 ------------------
1047 -- Error_Msg_SC --
1048 ------------------
1050 procedure Error_Msg_SC (Msg : String) is
1051 begin
1052 -- If we are at end of file, post the flag after the previous token
1054 if Token = Tok_EOF then
1055 Error_Msg_AP (Msg);
1057 -- For all other cases the message is posted at the current token
1058 -- pointer position
1060 else
1061 Error_Msg (Msg, Token_Ptr);
1062 end if;
1063 end Error_Msg_SC;
1065 ------------------
1066 -- Error_Msg_SP --
1067 ------------------
1069 procedure Error_Msg_SP (Msg : String) is
1070 begin
1071 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1072 -- is set to Source_First, which is a reasonable position for the
1073 -- error flag in this situation
1075 Error_Msg (Msg, Prev_Token_Ptr);
1076 end Error_Msg_SP;
1078 --------------
1079 -- Finalize --
1080 --------------
1082 procedure Finalize is
1083 Cur : Error_Msg_Id;
1084 Nxt : Error_Msg_Id;
1085 E, F : Error_Msg_Id;
1086 Err_Flag : Boolean;
1088 begin
1089 -- Reset current error source file if the main unit has a pragma
1090 -- Source_Reference. This ensures outputting the proper name of
1091 -- the source file in this situation.
1093 if Main_Source_File = No_Source_File or else
1094 Num_SRef_Pragmas (Main_Source_File) /= 0
1095 then
1096 Current_Error_Source_File := No_Source_File;
1097 end if;
1099 -- Eliminate any duplicated error messages from the list. This is
1100 -- done after the fact to avoid problems with Change_Error_Text.
1102 Cur := First_Error_Msg;
1103 while Cur /= No_Error_Msg loop
1104 Nxt := Errors.Table (Cur).Next;
1106 F := Nxt;
1107 while F /= No_Error_Msg
1108 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1109 loop
1110 Check_Duplicate_Message (Cur, F);
1111 F := Errors.Table (F).Next;
1112 end loop;
1114 Cur := Nxt;
1115 end loop;
1117 -- Brief Error mode
1119 if Brief_Output or (not Full_List and not Verbose_Mode) then
1120 E := First_Error_Msg;
1121 Set_Standard_Error;
1123 while E /= No_Error_Msg loop
1124 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1125 if Full_Path_Name_For_Brief_Errors then
1126 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1127 else
1128 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1129 end if;
1131 Write_Char (':');
1132 Write_Int (Int (Physical_To_Logical
1133 (Errors.Table (E).Line,
1134 Errors.Table (E).Sfile)));
1135 Write_Char (':');
1137 if Errors.Table (E).Col < 10 then
1138 Write_Char ('0');
1139 end if;
1141 Write_Int (Int (Errors.Table (E).Col));
1142 Write_Str (": ");
1143 Output_Msg_Text (E);
1144 Write_Eol;
1145 end if;
1147 E := Errors.Table (E).Next;
1148 end loop;
1150 Set_Standard_Output;
1151 end if;
1153 -- Full source listing case
1155 if Full_List then
1156 List_Pragmas_Index := 1;
1157 List_Pragmas_Mode := True;
1158 E := First_Error_Msg;
1159 Write_Eol;
1161 -- First list initial main source file with its error messages
1163 for N in 1 .. Last_Source_Line (Main_Source_File) loop
1164 Err_Flag :=
1165 E /= No_Error_Msg
1166 and then Errors.Table (E).Line = N
1167 and then Errors.Table (E).Sfile = Main_Source_File;
1169 Output_Source_Line (N, Main_Source_File, Err_Flag);
1171 if Err_Flag then
1172 Output_Error_Msgs (E);
1174 if not Debug_Flag_2 then
1175 Write_Eol;
1176 end if;
1177 end if;
1179 end loop;
1181 -- Then output errors, if any, for subsidiary units
1183 while E /= No_Error_Msg
1184 and then Errors.Table (E).Sfile /= Main_Source_File
1185 loop
1186 Write_Eol;
1187 Output_Source_Line
1188 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1189 Output_Error_Msgs (E);
1190 end loop;
1191 end if;
1193 -- Verbose mode (error lines only with error flags)
1195 if Verbose_Mode and not Full_List then
1196 E := First_Error_Msg;
1198 -- Loop through error lines
1200 while E /= No_Error_Msg loop
1201 Write_Eol;
1202 Output_Source_Line
1203 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1204 Output_Error_Msgs (E);
1205 end loop;
1206 end if;
1208 -- Output error summary if verbose or full list mode
1210 if Verbose_Mode or else Full_List then
1212 -- Extra blank line if error messages or source listing were output
1214 if Total_Errors_Detected + Warnings_Detected > 0
1215 or else Full_List
1216 then
1217 Write_Eol;
1218 end if;
1220 -- Message giving number of lines read and number of errors detected.
1221 -- This normally goes to Standard_Output. The exception is when brief
1222 -- mode is not set, verbose mode (or full list mode) is set, and
1223 -- there are errors. In this case we send the message to standard
1224 -- error to make sure that *something* appears on standard error in
1225 -- an error situation.
1227 -- Formerly, only the "# errors" suffix was sent to stderr, whereas
1228 -- "# lines:" appeared on stdout. This caused problems on VMS when
1229 -- the stdout buffer was flushed, giving an extra line feed after
1230 -- the prefix.
1232 if Total_Errors_Detected + Warnings_Detected /= 0
1233 and then not Brief_Output
1234 and then (Verbose_Mode or Full_List)
1235 then
1236 Set_Standard_Error;
1237 end if;
1239 -- Message giving total number of lines
1241 Write_Str (" ");
1242 Write_Int (Num_Source_Lines (Main_Source_File));
1244 if Num_Source_Lines (Main_Source_File) = 1 then
1245 Write_Str (" line: ");
1246 else
1247 Write_Str (" lines: ");
1248 end if;
1250 if Total_Errors_Detected = 0 then
1251 Write_Str ("No errors");
1253 elsif Total_Errors_Detected = 1 then
1254 Write_Str ("1 error");
1256 else
1257 Write_Int (Total_Errors_Detected);
1258 Write_Str (" errors");
1259 end if;
1261 if Warnings_Detected /= 0 then
1262 Write_Str (", ");
1263 Write_Int (Warnings_Detected);
1264 Write_Str (" warning");
1266 if Warnings_Detected /= 1 then
1267 Write_Char ('s');
1268 end if;
1270 if Warning_Mode = Treat_As_Error then
1271 Write_Str (" (treated as error");
1273 if Warnings_Detected /= 1 then
1274 Write_Char ('s');
1275 end if;
1277 Write_Char (')');
1278 end if;
1279 end if;
1281 Write_Eol;
1282 Set_Standard_Output;
1283 end if;
1285 if Maximum_Errors /= 0
1286 and then Total_Errors_Detected + Warnings_Detected = Maximum_Errors
1287 then
1288 Set_Standard_Error;
1289 Write_Str ("fatal error: maximum errors reached");
1290 Write_Eol;
1291 Set_Standard_Output;
1292 end if;
1294 if Warning_Mode = Treat_As_Error then
1295 Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected;
1296 Warnings_Detected := 0;
1297 end if;
1298 end Finalize;
1300 ----------------
1301 -- First_Node --
1302 ----------------
1304 function First_Node (C : Node_Id) return Node_Id is
1305 L : constant Source_Ptr := Sloc (C);
1306 Sfile : constant Source_File_Index := Get_Source_File_Index (L);
1307 Earliest : Node_Id;
1308 Eloc : Source_Ptr;
1309 Discard : Traverse_Result;
1311 pragma Warnings (Off, Discard);
1313 function Test_Earlier (N : Node_Id) return Traverse_Result;
1314 -- Function applied to every node in the construct
1316 function Search_Tree_First is new Traverse_Func (Test_Earlier);
1317 -- Create traversal function
1319 ------------------
1320 -- Test_Earlier --
1321 ------------------
1323 function Test_Earlier (N : Node_Id) return Traverse_Result is
1324 Loc : constant Source_Ptr := Sloc (N);
1326 begin
1327 -- Check for earlier. The tests for being in the same file ensures
1328 -- against strange cases of foreign code somehow being present. We
1329 -- don't want wild placement of messages if that happens, so it is
1330 -- best to just ignore this situation.
1332 if Loc < Eloc
1333 and then Get_Source_File_Index (Loc) = Sfile
1334 then
1335 Earliest := N;
1336 Eloc := Loc;
1337 end if;
1339 return OK_Orig;
1340 end Test_Earlier;
1342 -- Start of processing for First_Node
1344 begin
1345 Earliest := Original_Node (C);
1346 Eloc := Sloc (Earliest);
1347 Discard := Search_Tree_First (Original_Node (C));
1348 return Earliest;
1349 end First_Node;
1351 ----------------
1352 -- First_Sloc --
1353 ----------------
1355 function First_Sloc (N : Node_Id) return Source_Ptr is
1356 SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1357 SF : constant Source_Ptr := Source_First (SI);
1358 F : Node_Id;
1359 S : Source_Ptr;
1361 begin
1362 F := First_Node (N);
1363 S := Sloc (F);
1365 -- The following circuit is a bit subtle. When we have parenthesized
1366 -- expressions, then the Sloc will not record the location of the
1367 -- paren, but we would like to post the flag on the paren. So what
1368 -- we do is to crawl up the tree from the First_Node, adjusting the
1369 -- Sloc value for any parentheses we know are present. Yes, we know
1370 -- this circuit is not 100% reliable (e.g. because we don't record
1371 -- all possible paren level valoues), but this is only for an error
1372 -- message so it is good enough.
1374 Node_Loop : loop
1375 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1377 -- We don't look more than 12 characters behind the current
1378 -- location, and in any case not past the front of the source.
1380 Search_Loop : for K in 1 .. 12 loop
1381 exit Search_Loop when S = SF;
1383 if Source_Text (SI) (S - 1) = '(' then
1384 S := S - 1;
1385 exit Search_Loop;
1387 elsif Source_Text (SI) (S - 1) <= ' ' then
1388 S := S - 1;
1390 else
1391 exit Search_Loop;
1392 end if;
1393 end loop Search_Loop;
1394 end loop Paren_Loop;
1396 exit Node_Loop when F = N;
1397 F := Parent (F);
1398 exit Node_Loop when Nkind (F) not in N_Subexpr;
1399 end loop Node_Loop;
1401 return S;
1402 end First_Sloc;
1404 ----------------
1405 -- Initialize --
1406 ----------------
1408 procedure Initialize is
1409 begin
1410 Errors.Init;
1411 First_Error_Msg := No_Error_Msg;
1412 Last_Error_Msg := No_Error_Msg;
1413 Serious_Errors_Detected := 0;
1414 Total_Errors_Detected := 0;
1415 Warnings_Detected := 0;
1416 Cur_Msg := No_Error_Msg;
1417 List_Pragmas.Init;
1419 -- Initialize warnings table, if all warnings are suppressed, supply
1420 -- an initial dummy entry covering all possible source locations.
1422 Warnings.Init;
1424 if Warning_Mode = Suppress then
1425 Warnings.Increment_Last;
1426 Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
1427 Warnings.Table (Warnings.Last).Stop := Source_Ptr'Last;
1428 end if;
1430 -- Set the error nodes to Empty to avoid uninitialized variable
1431 -- references for saves/restores/moves.
1433 Error_Msg_Node_1 := Empty;
1434 Error_Msg_Node_2 := Empty;
1435 end Initialize;
1437 -----------------
1438 -- No_Warnings --
1439 -----------------
1441 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1442 begin
1443 if Error_Posted (N) then
1444 return True;
1446 elsif Nkind (N) in N_Entity and then Warnings_Off (N) then
1447 return True;
1449 elsif Is_Entity_Name (N)
1450 and then Present (Entity (N))
1451 and then Warnings_Off (Entity (N))
1452 then
1453 return True;
1455 else
1456 return False;
1457 end if;
1458 end No_Warnings;
1460 -------------
1461 -- OK_Node --
1462 -------------
1464 function OK_Node (N : Node_Id) return Boolean is
1465 K : constant Node_Kind := Nkind (N);
1467 begin
1468 if Error_Posted (N) then
1469 return False;
1471 elsif K in N_Has_Etype
1472 and then Present (Etype (N))
1473 and then Error_Posted (Etype (N))
1474 then
1475 return False;
1477 elsif (K in N_Op
1478 or else K = N_Attribute_Reference
1479 or else K = N_Character_Literal
1480 or else K = N_Expanded_Name
1481 or else K = N_Identifier
1482 or else K = N_Operator_Symbol)
1483 and then Present (Entity (N))
1484 and then Error_Posted (Entity (N))
1485 then
1486 return False;
1487 else
1488 return True;
1489 end if;
1490 end OK_Node;
1492 ------------------------
1493 -- Output_Source_Line --
1494 ------------------------
1496 procedure Output_Source_Line
1497 (L : Physical_Line_Number;
1498 Sfile : Source_File_Index;
1499 Errs : Boolean)
1501 S : Source_Ptr;
1502 C : Character;
1504 Line_Number_Output : Boolean := False;
1505 -- Set True once line number is output
1507 begin
1508 if Sfile /= Current_Error_Source_File then
1509 Write_Str ("==============Error messages for ");
1511 case Sinput.File_Type (Sfile) is
1512 when Sinput.Src =>
1513 Write_Str ("source");
1515 when Sinput.Config =>
1516 Write_Str ("configuration pragmas");
1518 when Sinput.Def =>
1519 Write_Str ("symbol definition");
1521 when Sinput.Preproc =>
1522 Write_Str ("preprocessing data");
1523 end case;
1525 Write_Str (" file: ");
1526 Write_Name (Full_File_Name (Sfile));
1527 Write_Eol;
1529 if Num_SRef_Pragmas (Sfile) > 0 then
1530 Write_Str ("--------------Line numbers from file: ");
1531 Write_Name (Full_Ref_Name (Sfile));
1532 Write_Str (" (starting at line ");
1533 Write_Int (Int (First_Mapped_Line (Sfile)));
1534 Write_Char (')');
1535 Write_Eol;
1536 end if;
1538 Current_Error_Source_File := Sfile;
1539 end if;
1541 if Errs or List_Pragmas_Mode then
1542 Output_Line_Number (Physical_To_Logical (L, Sfile));
1543 Line_Number_Output := True;
1544 end if;
1546 S := Line_Start (L, Sfile);
1548 loop
1549 C := Source_Text (Sfile) (S);
1550 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
1552 -- Deal with matching entry in List_Pragmas table
1554 if Full_List
1555 and then List_Pragmas_Index <= List_Pragmas.Last
1556 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
1557 then
1558 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
1559 when Page =>
1560 Write_Char (C);
1562 -- Ignore if on line with errors so that error flags
1563 -- get properly listed with the error line .
1565 if not Errs then
1566 Write_Char (ASCII.FF);
1567 end if;
1569 when List_On =>
1570 List_Pragmas_Mode := True;
1572 if not Line_Number_Output then
1573 Output_Line_Number (Physical_To_Logical (L, Sfile));
1574 Line_Number_Output := True;
1575 end if;
1577 Write_Char (C);
1579 when List_Off =>
1580 Write_Char (C);
1581 List_Pragmas_Mode := False;
1582 end case;
1584 List_Pragmas_Index := List_Pragmas_Index + 1;
1586 -- Normal case (no matching entry in List_Pragmas table)
1588 else
1589 if Errs or List_Pragmas_Mode then
1590 Write_Char (C);
1591 end if;
1592 end if;
1594 S := S + 1;
1595 end loop;
1597 if Line_Number_Output then
1598 Write_Eol;
1599 end if;
1600 end Output_Source_Line;
1602 -----------------------------
1603 -- Remove_Warning_Messages --
1604 -----------------------------
1606 procedure Remove_Warning_Messages (N : Node_Id) is
1608 function Check_For_Warning (N : Node_Id) return Traverse_Result;
1609 -- This function checks one node for a possible warning message.
1611 function Check_All_Warnings is new
1612 Traverse_Func (Check_For_Warning);
1613 -- This defines the traversal operation
1615 -----------------------
1616 -- Check_For_Warning --
1617 -----------------------
1619 function Check_For_Warning (N : Node_Id) return Traverse_Result is
1620 Loc : constant Source_Ptr := Sloc (N);
1621 E : Error_Msg_Id;
1623 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
1624 -- Returns True for a message that is to be removed. Also adjusts
1625 -- warning count appropriately.
1627 -------------------
1628 -- To_Be_Removed --
1629 -------------------
1631 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
1632 begin
1633 if E /= No_Error_Msg
1634 and then Errors.Table (E).Optr = Loc
1635 and then (Errors.Table (E).Warn or Errors.Table (E).Style)
1636 then
1637 Warnings_Detected := Warnings_Detected - 1;
1638 return True;
1639 else
1640 return False;
1641 end if;
1642 end To_Be_Removed;
1644 -- Start of processing for Check_For_Warnings
1646 begin
1647 while To_Be_Removed (First_Error_Msg) loop
1648 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
1649 end loop;
1651 if First_Error_Msg = No_Error_Msg then
1652 Last_Error_Msg := No_Error_Msg;
1653 end if;
1655 E := First_Error_Msg;
1656 while E /= No_Error_Msg loop
1657 while To_Be_Removed (Errors.Table (E).Next) loop
1658 Errors.Table (E).Next :=
1659 Errors.Table (Errors.Table (E).Next).Next;
1661 if Errors.Table (E).Next = No_Error_Msg then
1662 Last_Error_Msg := E;
1663 end if;
1664 end loop;
1666 E := Errors.Table (E).Next;
1667 end loop;
1669 if Nkind (N) = N_Raise_Constraint_Error
1670 and then Original_Node (N) /= N
1671 and then No (Condition (N))
1672 then
1673 -- Warnings may have been posted on subexpressions of
1674 -- the original tree. We place the original node back
1675 -- on the tree to remove those warnings, whose sloc
1676 -- do not match those of any node in the current tree.
1677 -- Given that we are in unreachable code, this modification
1678 -- to the tree is harmless.
1680 declare
1681 Status : Traverse_Result;
1683 begin
1684 if Is_List_Member (N) then
1685 Set_Condition (N, Original_Node (N));
1686 Status := Check_All_Warnings (Condition (N));
1687 else
1688 Rewrite (N, Original_Node (N));
1689 Status := Check_All_Warnings (N);
1690 end if;
1692 return Status;
1693 end;
1695 else
1696 return OK;
1697 end if;
1698 end Check_For_Warning;
1700 -- Start of processing for Remove_Warning_Messages
1702 begin
1703 if Warnings_Detected /= 0 then
1704 declare
1705 Discard : Traverse_Result;
1706 pragma Warnings (Off, Discard);
1708 begin
1709 Discard := Check_All_Warnings (N);
1710 end;
1711 end if;
1712 end Remove_Warning_Messages;
1714 procedure Remove_Warning_Messages (L : List_Id) is
1715 Stat : Node_Id;
1716 begin
1717 if Is_Non_Empty_List (L) then
1718 Stat := First (L);
1720 while Present (Stat) loop
1721 Remove_Warning_Messages (Stat);
1722 Next (Stat);
1723 end loop;
1724 end if;
1725 end Remove_Warning_Messages;
1727 ---------------------------
1728 -- Set_Identifier_Casing --
1729 ---------------------------
1731 procedure Set_Identifier_Casing
1732 (Identifier_Name : System.Address;
1733 File_Name : System.Address)
1735 type Big_String is array (Positive) of Character;
1736 type Big_String_Ptr is access all Big_String;
1738 function To_Big_String_Ptr is new Unchecked_Conversion
1739 (System.Address, Big_String_Ptr);
1741 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
1742 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
1743 Flen : Natural;
1745 Desired_Case : Casing_Type := Mixed_Case;
1746 -- Casing required for result. Default value of Mixed_Case is used if
1747 -- for some reason we cannot find the right file name in the table.
1750 begin
1751 -- Get length of file name
1753 Flen := 0;
1754 while File (Flen + 1) /= ASCII.NUL loop
1755 Flen := Flen + 1;
1756 end loop;
1758 -- Loop through file names to find matching one. This is a bit slow,
1759 -- but we only do it in error situations so it is not so terrible.
1760 -- Note that if the loop does not exit, then the desired case will
1761 -- be left set to Mixed_Case, this can happen if the name was not
1762 -- in canonical form, and gets canonicalized on VMS. Possibly we
1763 -- could fix this by unconditinally canonicalizing these names ???
1765 for J in 1 .. Last_Source_File loop
1766 Get_Name_String (Full_Debug_Name (J));
1768 if Name_Len = Flen
1769 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
1770 then
1771 Desired_Case := Identifier_Casing (J);
1772 exit;
1773 end if;
1774 end loop;
1776 -- Copy identifier as given to Name_Buffer
1778 for J in Name_Buffer'Range loop
1779 Name_Buffer (J) := Ident (J);
1781 if Name_Buffer (J) = ASCII.Nul then
1782 Name_Len := J - 1;
1783 exit;
1784 end if;
1785 end loop;
1787 Set_Casing (Desired_Case);
1788 end Set_Identifier_Casing;
1790 -----------------------
1791 -- Set_Ignore_Errors --
1792 -----------------------
1794 procedure Set_Ignore_Errors (To : Boolean) is
1795 begin
1796 Errors_Must_Be_Ignored := To;
1797 end Set_Ignore_Errors;
1799 ------------------------------
1800 -- Set_Msg_Insertion_Column --
1801 ------------------------------
1803 procedure Set_Msg_Insertion_Column is
1804 begin
1805 if Style.RM_Column_Check then
1806 Set_Msg_Str (" in column ");
1807 Set_Msg_Int (Int (Error_Msg_Col) + 1);
1808 end if;
1809 end Set_Msg_Insertion_Column;
1811 ----------------------------
1812 -- Set_Msg_Insertion_Node --
1813 ----------------------------
1815 procedure Set_Msg_Insertion_Node is
1816 K : Node_Kind;
1818 begin
1819 Suppress_Message :=
1820 Error_Msg_Node_1 = Error
1821 or else Error_Msg_Node_1 = Any_Type;
1823 if Error_Msg_Node_1 = Empty then
1824 Set_Msg_Blank_Conditional;
1825 Set_Msg_Str ("<empty>");
1827 elsif Error_Msg_Node_1 = Error then
1828 Set_Msg_Blank;
1829 Set_Msg_Str ("<error>");
1831 elsif Error_Msg_Node_1 = Standard_Void_Type then
1832 Set_Msg_Blank;
1833 Set_Msg_Str ("procedure name");
1835 else
1836 Set_Msg_Blank_Conditional;
1838 -- Output name
1840 K := Nkind (Error_Msg_Node_1);
1842 -- If we have operator case, skip quotes since name of operator
1843 -- itself will supply the required quotations. An operator can be
1844 -- an applied use in an expression or an explicit operator symbol,
1845 -- or an identifier whose name indicates it is an operator.
1847 if K in N_Op
1848 or else K = N_Operator_Symbol
1849 or else K = N_Defining_Operator_Symbol
1850 or else ((K = N_Identifier or else K = N_Defining_Identifier)
1851 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
1852 then
1853 Set_Msg_Node (Error_Msg_Node_1);
1855 -- Normal case, not an operator, surround with quotes
1857 else
1858 Set_Msg_Quote;
1859 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
1860 Set_Msg_Node (Error_Msg_Node_1);
1861 Set_Msg_Quote;
1862 end if;
1863 end if;
1865 -- The following assignment ensures that a second ampersand insertion
1866 -- character will correspond to the Error_Msg_Node_2 parameter.
1868 Error_Msg_Node_1 := Error_Msg_Node_2;
1869 end Set_Msg_Insertion_Node;
1871 --------------------------------------
1872 -- Set_Msg_Insertion_Type_Reference --
1873 --------------------------------------
1875 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
1876 Ent : Entity_Id;
1878 begin
1879 Set_Msg_Blank;
1881 if Error_Msg_Node_1 = Standard_Void_Type then
1882 Set_Msg_Str ("package or procedure name");
1883 return;
1885 elsif Error_Msg_Node_1 = Standard_Exception_Type then
1886 Set_Msg_Str ("exception name");
1887 return;
1889 elsif Error_Msg_Node_1 = Any_Access
1890 or else Error_Msg_Node_1 = Any_Array
1891 or else Error_Msg_Node_1 = Any_Boolean
1892 or else Error_Msg_Node_1 = Any_Character
1893 or else Error_Msg_Node_1 = Any_Composite
1894 or else Error_Msg_Node_1 = Any_Discrete
1895 or else Error_Msg_Node_1 = Any_Fixed
1896 or else Error_Msg_Node_1 = Any_Integer
1897 or else Error_Msg_Node_1 = Any_Modular
1898 or else Error_Msg_Node_1 = Any_Numeric
1899 or else Error_Msg_Node_1 = Any_Real
1900 or else Error_Msg_Node_1 = Any_Scalar
1901 or else Error_Msg_Node_1 = Any_String
1902 then
1903 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
1904 Set_Msg_Name_Buffer;
1905 return;
1907 elsif Error_Msg_Node_1 = Universal_Real then
1908 Set_Msg_Str ("type universal real");
1909 return;
1911 elsif Error_Msg_Node_1 = Universal_Integer then
1912 Set_Msg_Str ("type universal integer");
1913 return;
1915 elsif Error_Msg_Node_1 = Universal_Fixed then
1916 Set_Msg_Str ("type universal fixed");
1917 return;
1918 end if;
1920 -- Special case of anonymous array
1922 if Nkind (Error_Msg_Node_1) in N_Entity
1923 and then Is_Array_Type (Error_Msg_Node_1)
1924 and then Present (Related_Array_Object (Error_Msg_Node_1))
1925 then
1926 Set_Msg_Str ("type of ");
1927 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
1928 Set_Msg_Str (" declared");
1929 Set_Msg_Insertion_Line_Number
1930 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
1931 return;
1932 end if;
1934 -- If we fall through, it is not a special case, so first output
1935 -- the name of the type, preceded by private for a private type
1937 if Is_Private_Type (Error_Msg_Node_1) then
1938 Set_Msg_Str ("private type ");
1939 else
1940 Set_Msg_Str ("type ");
1941 end if;
1943 Ent := Error_Msg_Node_1;
1945 if Is_Internal_Name (Chars (Ent)) then
1946 Unwind_Internal_Type (Ent);
1947 end if;
1949 -- Types in Standard are displayed as "Standard.name"
1951 if Sloc (Ent) <= Standard_Location then
1952 Set_Msg_Quote;
1953 Set_Msg_Str ("Standard.");
1954 Set_Msg_Node (Ent);
1955 Add_Class;
1956 Set_Msg_Quote;
1958 -- Types in other language defined units are displayed as
1959 -- "package-name.type-name"
1961 elsif
1962 Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Ent)))
1963 then
1964 Get_Unqualified_Decoded_Name_String
1965 (Unit_Name (Get_Source_Unit (Ent)));
1966 Name_Len := Name_Len - 2;
1967 Set_Msg_Quote;
1968 Set_Casing (Mixed_Case);
1969 Set_Msg_Name_Buffer;
1970 Set_Msg_Char ('.');
1971 Set_Casing (Mixed_Case);
1972 Set_Msg_Node (Ent);
1973 Add_Class;
1974 Set_Msg_Quote;
1976 -- All other types display as "type name" defined at line xxx
1977 -- possibly qualified if qualification is requested.
1979 else
1980 Set_Msg_Quote;
1981 Set_Qualification (Error_Msg_Qual_Level, Ent);
1982 Set_Msg_Node (Ent);
1983 Add_Class;
1984 Set_Msg_Quote;
1985 end if;
1987 -- If the original type did not come from a predefined
1988 -- file, add the location where the type was defined.
1990 if Sloc (Error_Msg_Node_1) > Standard_Location
1991 and then
1992 not Is_Predefined_File_Name
1993 (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)))
1994 then
1995 Set_Msg_Str (" defined");
1996 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
1998 -- If it did come from a predefined file, deal with the case where
1999 -- this was a file with a generic instantiation from elsewhere.
2001 else
2002 if Sloc (Error_Msg_Node_1) > Standard_Location then
2003 declare
2004 Iloc : constant Source_Ptr :=
2005 Instantiation_Location (Sloc (Error_Msg_Node_1));
2007 begin
2008 if Iloc /= No_Location
2009 and then not Suppress_Instance_Location
2010 then
2011 Set_Msg_Str (" from instance");
2012 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2013 end if;
2014 end;
2015 end if;
2016 end if;
2017 end Set_Msg_Insertion_Type_Reference;
2019 ---------------------------------
2020 -- Set_Msg_Insertion_Unit_Name --
2021 ---------------------------------
2023 procedure Set_Msg_Insertion_Unit_Name is
2024 begin
2025 if Error_Msg_Unit_1 = No_Name then
2026 null;
2028 elsif Error_Msg_Unit_1 = Error_Name then
2029 Set_Msg_Blank;
2030 Set_Msg_Str ("<error>");
2032 else
2033 Get_Unit_Name_String (Error_Msg_Unit_1);
2034 Set_Msg_Blank;
2035 Set_Msg_Quote;
2036 Set_Msg_Name_Buffer;
2037 Set_Msg_Quote;
2038 end if;
2040 -- The following assignment ensures that a second percent insertion
2041 -- character will correspond to the Error_Msg_Unit_2 parameter.
2043 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2044 end Set_Msg_Insertion_Unit_Name;
2046 ------------------
2047 -- Set_Msg_Node --
2048 ------------------
2050 procedure Set_Msg_Node (Node : Node_Id) is
2051 Ent : Entity_Id;
2052 Nam : Name_Id;
2054 begin
2055 if Nkind (Node) = N_Designator then
2056 Set_Msg_Node (Name (Node));
2057 Set_Msg_Char ('.');
2058 Set_Msg_Node (Identifier (Node));
2059 return;
2061 elsif Nkind (Node) = N_Defining_Program_Unit_Name then
2062 Set_Msg_Node (Name (Node));
2063 Set_Msg_Char ('.');
2064 Set_Msg_Node (Defining_Identifier (Node));
2065 return;
2067 elsif Nkind (Node) = N_Selected_Component then
2068 Set_Msg_Node (Prefix (Node));
2069 Set_Msg_Char ('.');
2070 Set_Msg_Node (Selector_Name (Node));
2071 return;
2072 end if;
2074 -- The only remaining possibilities are identifiers, defining
2075 -- identifiers, pragmas, and pragma argument associations, i.e.
2076 -- nodes that have a Chars field.
2078 -- Internal names generally represent something gone wrong. An exception
2079 -- is the case of internal type names, where we try to find a reasonable
2080 -- external representation for the external name
2082 if Is_Internal_Name (Chars (Node))
2083 and then
2084 ((Is_Entity_Name (Node)
2085 and then Present (Entity (Node))
2086 and then Is_Type (Entity (Node)))
2087 or else
2088 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2089 then
2090 if Nkind (Node) = N_Identifier then
2091 Ent := Entity (Node);
2092 else
2093 Ent := Node;
2094 end if;
2096 Unwind_Internal_Type (Ent);
2097 Nam := Chars (Ent);
2099 else
2100 Nam := Chars (Node);
2101 end if;
2103 -- At this stage, the name to output is in Nam
2105 Get_Unqualified_Decoded_Name_String (Nam);
2107 -- Remove trailing upper case letters from the name (useful for
2108 -- dealing with some cases of internal names.
2110 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
2111 Name_Len := Name_Len - 1;
2112 end loop;
2114 -- If we have any of the names from standard that start with the
2115 -- characters "any " (e.g. Any_Type), then kill the message since
2116 -- almost certainly it is a junk cascaded message.
2118 if Name_Len > 4
2119 and then Name_Buffer (1 .. 4) = "any "
2120 then
2121 Kill_Message := True;
2122 end if;
2124 -- Now we have to set the proper case. If we have a source location
2125 -- then do a check to see if the name in the source is the same name
2126 -- as the name in the Names table, except for possible differences
2127 -- in case, which is the case when we can copy from the source.
2129 declare
2130 Src_Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
2131 Sbuffer : Source_Buffer_Ptr;
2132 Ref_Ptr : Integer;
2133 Src_Ptr : Source_Ptr;
2135 begin
2136 Ref_Ptr := 1;
2137 Src_Ptr := Src_Loc;
2139 -- For standard locations, always use mixed case
2141 if Src_Loc <= No_Location
2142 or else Sloc (Node) <= No_Location
2143 then
2144 Set_Casing (Mixed_Case);
2146 else
2147 -- Determine if the reference we are dealing with corresponds
2148 -- to text at the point of the error reference. This will often
2149 -- be the case for simple identifier references, and is the case
2150 -- where we can copy the spelling from the source.
2152 Sbuffer := Source_Text (Get_Source_File_Index (Src_Loc));
2154 while Ref_Ptr <= Name_Len loop
2155 exit when
2156 Fold_Lower (Sbuffer (Src_Ptr)) /=
2157 Fold_Lower (Name_Buffer (Ref_Ptr));
2158 Ref_Ptr := Ref_Ptr + 1;
2159 Src_Ptr := Src_Ptr + 1;
2160 end loop;
2162 -- If we get through the loop without a mismatch, then output
2163 -- the name the way it is spelled in the source program
2165 if Ref_Ptr > Name_Len then
2166 Src_Ptr := Src_Loc;
2168 for J in 1 .. Name_Len loop
2169 Name_Buffer (J) := Sbuffer (Src_Ptr);
2170 Src_Ptr := Src_Ptr + 1;
2171 end loop;
2173 -- Otherwise set the casing using the default identifier casing
2175 else
2176 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
2177 end if;
2178 end if;
2179 end;
2181 Set_Msg_Name_Buffer;
2182 Add_Class;
2183 end Set_Msg_Node;
2185 ------------------
2186 -- Set_Msg_Text --
2187 ------------------
2189 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2190 C : Character; -- Current character
2191 P : Natural; -- Current index;
2193 begin
2194 Manual_Quote_Mode := False;
2195 Is_Unconditional_Msg := False;
2196 Msglen := 0;
2197 Flag_Source := Get_Source_File_Index (Flag);
2198 P := Text'First;
2200 while P <= Text'Last loop
2201 C := Text (P);
2202 P := P + 1;
2204 -- Check for insertion character
2206 case C is
2207 when '%' =>
2208 Set_Msg_Insertion_Name;
2210 when '$' =>
2211 Set_Msg_Insertion_Unit_Name;
2213 when '{' =>
2214 Set_Msg_Insertion_File_Name;
2216 when '}' =>
2217 Set_Msg_Insertion_Type_Reference (Flag);
2219 when '*' =>
2220 Set_Msg_Insertion_Reserved_Name;
2222 when '&' =>
2223 Set_Msg_Insertion_Node;
2225 when '#' =>
2226 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
2228 when '\' =>
2229 Continuation := True;
2231 when '@' =>
2232 Set_Msg_Insertion_Column;
2234 when '>' =>
2235 Set_Msg_Insertion_Run_Time_Name;
2238 when '^' =>
2239 Set_Msg_Insertion_Uint;
2241 when '`' =>
2242 Manual_Quote_Mode := not Manual_Quote_Mode;
2243 Set_Msg_Char ('"');
2245 when '!' =>
2246 Is_Unconditional_Msg := True;
2248 when '?' =>
2249 null; -- already dealt with
2251 when '|' =>
2252 null; -- already dealt with
2254 when ''' =>
2255 Set_Msg_Char (Text (P));
2256 P := P + 1;
2258 -- Upper case letter
2260 when 'A' .. 'Z' =>
2262 -- Start of reserved word if two or more
2264 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
2265 P := P - 1;
2266 Set_Msg_Insertion_Reserved_Word (Text, P);
2268 -- Single upper case letter is just inserted
2270 else
2271 Set_Msg_Char (C);
2272 end if;
2274 -- Normal character with no special treatment
2276 when others =>
2277 Set_Msg_Char (C);
2278 end case;
2279 end loop;
2281 VMS_Convert;
2282 end Set_Msg_Text;
2284 ----------------
2285 -- Set_Posted --
2286 ----------------
2288 procedure Set_Posted (N : Node_Id) is
2289 P : Node_Id;
2291 begin
2292 if Is_Serious_Error then
2294 -- We always set Error_Posted on the node itself
2296 Set_Error_Posted (N);
2298 -- If it is a subexpression, then set Error_Posted on parents
2299 -- up to and including the first non-subexpression construct. This
2300 -- helps avoid cascaded error messages within a single expression.
2302 P := N;
2303 loop
2304 P := Parent (P);
2305 exit when No (P);
2306 Set_Error_Posted (P);
2307 exit when Nkind (P) not in N_Subexpr;
2308 end loop;
2310 -- A special check, if we just posted an error on an attribute
2311 -- definition clause, then also set the entity involved as posted.
2312 -- For example, this stops complaining about the alignment after
2313 -- complaining about the size, which is likely to be useless.
2315 if Nkind (P) = N_Attribute_Definition_Clause then
2316 if Is_Entity_Name (Name (P)) then
2317 Set_Error_Posted (Entity (Name (P)));
2318 end if;
2319 end if;
2320 end if;
2321 end Set_Posted;
2323 -----------------------
2324 -- Set_Qualification --
2325 -----------------------
2327 procedure Set_Qualification (N : Nat; E : Entity_Id) is
2328 begin
2329 if N /= 0 and then Scope (E) /= Standard_Standard then
2330 Set_Qualification (N - 1, Scope (E));
2331 Set_Msg_Node (Scope (E));
2332 Set_Msg_Char ('.');
2333 end if;
2334 end Set_Qualification;
2336 ------------------------
2337 -- Special_Msg_Delete --
2338 ------------------------
2340 function Special_Msg_Delete
2341 (Msg : String;
2342 N : Node_Or_Entity_Id;
2343 E : Node_Or_Entity_Id) return Boolean
2345 begin
2346 -- Never delete messages in -gnatdO mode
2348 if Debug_Flag_OO then
2349 return False;
2351 -- When an atomic object refers to a non-atomic type in the same
2352 -- scope, we implicitly make the type atomic. In the non-error
2353 -- case this is surely safe (and in fact prevents an error from
2354 -- occurring if the type is not atomic by default). But if the
2355 -- object cannot be made atomic, then we introduce an extra junk
2356 -- message by this manipulation, which we get rid of here.
2358 -- We identify this case by the fact that it references a type for
2359 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
2361 elsif Msg = "atomic access to & cannot be guaranteed"
2362 and then Is_Type (E)
2363 and then Is_Atomic (E)
2364 and then No (Get_Rep_Pragma (E, Name_Atomic))
2365 then
2366 return True;
2368 -- When a size is wrong for a frozen type there is no explicit
2369 -- size clause, and other errors have occurred, suppress the
2370 -- message, since it is likely that this size error is a cascaded
2371 -- result of other errors. The reason we eliminate unfrozen types
2372 -- is that messages issued before the freeze type are for sure OK.
2374 elsif Msg = "size for& too small, minimum allowed is ^"
2375 and then Is_Frozen (E)
2376 and then Serious_Errors_Detected > 0
2377 and then Nkind (N) /= N_Component_Clause
2378 and then Nkind (Parent (N)) /= N_Component_Clause
2379 and then
2380 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
2381 and then
2382 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
2383 and then
2384 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
2385 then
2386 return True;
2388 -- All special tests complete, so go ahead with message
2390 else
2391 return False;
2392 end if;
2393 end Special_Msg_Delete;
2395 --------------------------
2396 -- Unwind_Internal_Type --
2397 --------------------------
2399 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
2400 Derived : Boolean := False;
2401 Mchar : Character;
2402 Old_Ent : Entity_Id;
2404 begin
2405 -- Undo placement of a quote, since we will put it back later
2407 Mchar := Msg_Buffer (Msglen);
2409 if Mchar = '"' then
2410 Msglen := Msglen - 1;
2411 end if;
2413 -- The loop here deals with recursive types, we are trying to
2414 -- find a related entity that is not an implicit type. Note
2415 -- that the check with Old_Ent stops us from getting "stuck".
2416 -- Also, we don't output the "type derived from" message more
2417 -- than once in the case where we climb up multiple levels.
2419 loop
2420 Old_Ent := Ent;
2422 -- Implicit access type, use directly designated type
2424 if Is_Access_Type (Ent) then
2425 Set_Msg_Str ("access to ");
2426 Ent := Directly_Designated_Type (Ent);
2428 -- Classwide type
2430 elsif Is_Class_Wide_Type (Ent) then
2431 Class_Flag := True;
2432 Ent := Root_Type (Ent);
2434 -- Use base type if this is a subtype
2436 elsif Ent /= Base_Type (Ent) then
2437 Buffer_Remove ("type ");
2439 -- Avoid duplication "subtype of subtype of", and also replace
2440 -- "derived from subtype of" simply by "derived from"
2442 if not Buffer_Ends_With ("subtype of ")
2443 and then not Buffer_Ends_With ("derived from ")
2444 then
2445 Set_Msg_Str ("subtype of ");
2446 end if;
2448 Ent := Base_Type (Ent);
2450 -- If this is a base type with a first named subtype, use the
2451 -- first named subtype instead. This is not quite accurate in
2452 -- all cases, but it makes too much noise to be accurate and
2453 -- add 'Base in all cases. Note that we only do this is the
2454 -- first named subtype is not itself an internal name. This
2455 -- avoids the obvious loop (subtype->basetype->subtype) which
2456 -- would otherwise occur!)
2458 elsif Present (Freeze_Node (Ent))
2459 and then Present (First_Subtype_Link (Freeze_Node (Ent)))
2460 and then
2461 not Is_Internal_Name
2462 (Chars (First_Subtype_Link (Freeze_Node (Ent))))
2463 then
2464 Ent := First_Subtype_Link (Freeze_Node (Ent));
2466 -- Otherwise use root type
2468 else
2469 if not Derived then
2470 Buffer_Remove ("type ");
2472 -- Test for "subtype of type derived from" which seems
2473 -- excessive and is replaced by simply "type derived from"
2475 Buffer_Remove ("subtype of");
2477 -- Avoid duplication "type derived from type derived from"
2479 if not Buffer_Ends_With ("type derived from ") then
2480 Set_Msg_Str ("type derived from ");
2481 end if;
2483 Derived := True;
2484 end if;
2486 Ent := Etype (Ent);
2487 end if;
2489 -- If we are stuck in a loop, get out and settle for the internal
2490 -- name after all. In this case we set to kill the message if it
2491 -- is not the first error message (we really try hard not to show
2492 -- the dirty laundry of the implementation to the poor user!)
2494 if Ent = Old_Ent then
2495 Kill_Message := True;
2496 exit;
2497 end if;
2499 -- Get out if we finally found a non-internal name to use
2501 exit when not Is_Internal_Name (Chars (Ent));
2502 end loop;
2504 if Mchar = '"' then
2505 Set_Msg_Char ('"');
2506 end if;
2507 end Unwind_Internal_Type;
2509 -----------------
2510 -- VMS_Convert --
2511 -----------------
2513 procedure VMS_Convert is
2514 P : Natural;
2515 L : Natural;
2516 N : Natural;
2518 begin
2519 if not OpenVMS then
2520 return;
2521 end if;
2523 P := Msg_Buffer'First;
2524 loop
2525 if P >= Msglen then
2526 return;
2527 end if;
2529 if Msg_Buffer (P) = '-' then
2530 for G in Gnames'Range loop
2531 L := Gnames (G)'Length;
2533 -- See if we have "-ggg switch", where ggg is Gnames entry
2535 if P + L + 7 <= Msglen
2536 and then Msg_Buffer (P + 1 .. P + L) = Gnames (G).all
2537 and then Msg_Buffer (P + L + 1 .. P + L + 7) = " switch"
2538 then
2539 -- Replace by "/vvv qualifier", where vvv is Vnames entry
2541 N := Vnames (G)'Length;
2542 Msg_Buffer (P + N + 11 .. Msglen + N - L + 3) :=
2543 Msg_Buffer (P + L + 8 .. Msglen);
2544 Msg_Buffer (P) := '/';
2545 Msg_Buffer (P + 1 .. P + N) := Vnames (G).all;
2546 Msg_Buffer (P + N + 1 .. P + N + 10) := " qualifier";
2547 P := P + N + 10;
2548 Msglen := Msglen + N - L + 3;
2549 exit;
2550 end if;
2551 end loop;
2552 end if;
2554 P := P + 1;
2555 end loop;
2556 end VMS_Convert;
2558 end Errout;