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