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