Debian Codegraph @

gcc/ada/errout.adb

raw
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-2025, 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 Diagnostics.Converter; use Diagnostics.Converter;
37 with Einfo; use Einfo;
38 with Einfo.Entities; use Einfo.Entities;
39 with Einfo.Utils; use Einfo.Utils;
40 with Erroutc; use Erroutc;
41 with Gnatvsn; use Gnatvsn;
42 with Lib; use Lib;
43 with Opt; use Opt;
44 with Nlists; use Nlists;
45 with Output; use Output;
46 with Scans; use Scans;
47 with Sem_Aux; use Sem_Aux;
48 with Sinput; use Sinput;
49 with Sinfo; use Sinfo;
50 with Sinfo.Nodes; use Sinfo.Nodes;
51 with Sinfo.Utils; use Sinfo.Utils;
52 with Snames; use Snames;
53 with Stand; use Stand;
54 with Stringt; use Stringt;
55 with System.OS_Lib;
56 with Uname; use Uname;
57 with Warnsw;
58
59 package body Errout is
60
61 Errors_Must_Be_Ignored : Boolean := False;
62 -- Set to True by procedure Set_Ignore_Errors (True), when calls to error
63 -- message procedures should be ignored (when parsing irrelevant text in
64 -- sources being preprocessed).
65
66 Finalize_Called : Boolean := False;
67 -- Set True if the Finalize routine has been called
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 Span : Source_Span;
102 Opan : Source_Span;
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). Span 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. Opan 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 Opan pointing to the template location
112 -- in an instantiation copy when Span 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_JSON_Message (Error_Id : Error_Msg_Id);
127 -- Output error message Error_Id and any subsequent continuation message
128 -- using a JSON format similar to the one GCC uses when passed
129 -- -fdiagnostics-format=json.
130
131 procedure Output_Source_Line
132 (L : Physical_Line_Number;
133 Sfile : Source_File_Index;
134 Errs : Boolean);
135 -- Outputs text of source line L, in file S, together with preceding line
136 -- number, as described above for Output_Line_Number. The Errs parameter
137 -- indicates if there are errors attached to the line, which forces
138 -- listing on, even in the presence of pragma List (Off).
139
140 function Paren_Required (N : Node_Id) return Boolean;
141 -- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
142 -- around node N are required by the Ada syntax, e.g. when N is an
143 -- expression of a qualified expression.
144
145 procedure Set_Msg_Insertion_Node;
146 -- Handle node (name from node) insertion (& insertion character)
147
148 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
149 -- Handle type reference (right brace insertion character). Flag is the
150 -- location of the flag, which is provided for the internal call to
151 -- Set_Msg_Insertion_Line_Number,
152
153 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True);
154 -- Handle unit name insertion ($ insertion character). Depending on Boolean
155 -- parameter Suffix, (spec) or (body) is appended after the unit name.
156
157 procedure Set_Msg_Node (Node : Node_Id);
158 -- Add the sequence of characters for the name associated with the given
159 -- node to the current message. For N_Designator, N_Selected_Component,
160 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
161 -- included as well.
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 Should_Ignore_Pragma_SPARK_Mode return Boolean;
176 -- Return whether pragma Ignore_Pragma (SPARK_Mode) was specified. This is
177 -- similar to Sem_Util.Should_Ignore_Pragma_Par but located here to avoid
178 -- problematic dependency on Sem_Util.
179
180 function Special_Msg_Delete
181 (Msg : String;
182 N : Node_Or_Entity_Id;
183 E : Node_Or_Entity_Id) return Boolean;
184 -- This function is called from Error_Msg_NEL, passing the message Msg,
185 -- node N on which the error is to be posted, and the entity or node E
186 -- to be used for an & insertion in the message if any. The job of this
187 -- procedure is to test for certain cascaded messages that we would like
188 -- to suppress. If the message is to be suppressed then we return True.
189 -- If the message should be generated (the normal case) False is returned.
190
191 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
192 -- This procedure is given an entity id for an internal type, i.e. a type
193 -- with an internal name. It unwinds the type to try to get to something
194 -- reasonably printable, generating prefixes like "subtype of", "access
195 -- to", etc along the way in the buffer. The value in Ent on return is the
196 -- final name to be printed. Hopefully this is not an internal name, but in
197 -- some internal name cases, it is an internal name, and has to be printed
198 -- anyway (although in this case the message has been killed if possible).
199 -- The global variable Class_Flag is set to True if the resulting entity
200 -- should have 'Class appended to its name (see Add_Class procedure), and
201 -- is otherwise unchanged.
202
203 procedure Validate_Specific_Warnings;
204 -- Checks that specific warnings are consistent (for non-configuration
205 -- case, properly closed, and used).
206
207 function Warn_Insertion return String;
208 -- This is called for warning messages only (so Warning_Msg_Char is set)
209 -- and returns a corresponding string to use at the beginning of generated
210 -- auxiliary messages, such as "in instantiation at ...".
211 -- "?" returns "??"
212 -- " " returns "?"
213 -- other trimmed, prefixed and suffixed with "?".
214
215 -----------------------
216 -- Change_Error_Text --
217 -----------------------
218
219 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
220 Save_Next : Error_Msg_Id;
221 Err_Id : Error_Msg_Id := Error_Id;
222
223 begin
224 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr.Ptr);
225 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
226
227 -- If in immediate error message mode, output modified error message now
228 -- This is just a bit tricky, because we want to output just a single
229 -- message, and the messages we modified is already linked in. We solve
230 -- this by temporarily resetting its forward pointer to empty.
231
232 if Debug_Flag_OO then
233 Save_Next := Errors.Table (Error_Id).Next;
234 Errors.Table (Error_Id).Next := No_Error_Msg;
235 Write_Eol;
236 Output_Source_Line
237 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
238 Output_Error_Msgs (Err_Id);
239 Errors.Table (Error_Id).Next := Save_Next;
240 end if;
241 end Change_Error_Text;
242
243 ------------------------
244 -- Compilation_Errors --
245 ------------------------
246
247 function Compilation_Errors return Boolean is
248 begin
249 if not Finalize_Called then
250 raise Program_Error;
251 else
252 return Erroutc.Compilation_Errors;
253 end if;
254 end Compilation_Errors;
255
256 --------------------------------------
257 -- Delete_Warning_And_Continuations --
258 --------------------------------------
259
260 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
261 Id : Error_Msg_Id;
262
263 begin
264 pragma Assert (not Errors.Table (Msg).Msg_Cont);
265
266 Id := Msg;
267 loop
268 declare
269 M : Error_Msg_Object renames Errors.Table (Id);
270
271 begin
272 if not M.Deleted then
273 M.Deleted := True;
274 Warnings_Detected := Warnings_Detected - 1;
275
276 if M.Warn_Err then
277 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
278 end if;
279 end if;
280
281 Id := M.Next;
282 exit when Id = No_Error_Msg;
283 exit when not Errors.Table (Id).Msg_Cont;
284 end;
285 end loop;
286 end Delete_Warning_And_Continuations;
287
288 ---------------
289 -- Error_Msg --
290 ---------------
291
292 -- Error_Msg posts a flag at the given location, except that if the
293 -- Flag_Location/Flag_Span points within a generic template and corresponds
294 -- to an instantiation of this generic template, then the actual message
295 -- will be posted on the generic instantiation, along with additional
296 -- messages referencing the generic declaration.
297
298 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
299 begin
300 Error_Msg (Msg, To_Span (Flag_Location), Empty);
301 end Error_Msg;
302
303 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
304 begin
305 Error_Msg (Msg, Flag_Span, Empty);
306 end Error_Msg;
307
308 procedure Error_Msg
309 (Msg : String;
310 Flag_Location : Source_Ptr;
311 N : Node_Id;
312 Is_Compile_Time_Pragma : Boolean)
313 is
314 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
315 begin
316 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
317 Error_Msg (Msg, To_Span (Flag_Location), N);
318 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
319 end Error_Msg;
320
321 procedure Error_Msg
322 (Msg : String;
323 Flag_Location : Source_Ptr;
324 N : Node_Id)
325 is
326 begin
327 Error_Msg (Msg, To_Span (Flag_Location), N);
328 end Error_Msg;
329
330 procedure Error_Msg
331 (Msg : String;
332 Flag_Span : Source_Span;
333 N : Node_Id)
334 is
335 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
336
337 Sindex : Source_File_Index;
338 -- Source index for flag location
339
340 Orig_Loc : Source_Ptr;
341 -- Original location of Flag_Location (i.e. location in original
342 -- template in instantiation case, otherwise unchanged).
343
344 begin
345 -- Return if all errors are to be ignored
346
347 if Get_Ignore_Errors then
348 return;
349 end if;
350
351 -- If we already have messages, and we are trying to place a message at
352 -- No_Location, then just ignore the attempt since we assume that what
353 -- is happening is some cascaded junk. Note that this is safe in the
354 -- sense that proceeding will surely bomb. We will also bomb if the flag
355 -- location is No_Location and we don't have any messages so far, but
356 -- that is a real bug and a legitimate bomb, so we go ahead.
357
358 if Flag_Location = No_Location
359 and then Total_Errors_Detected > 0
360 then
361 return;
362 end if;
363
364 -- Start of processing for new message
365
366 Sindex := Get_Source_File_Index (Flag_Location);
367 Prescan_Message (Msg);
368 Orig_Loc := Original_Location (Flag_Location);
369
370 -- If the current location is in an instantiation, the issue arises of
371 -- whether to post the message on the template or the instantiation.
372
373 -- The way we decide is to see if we have posted the same message on
374 -- the template when we compiled the template (the template is always
375 -- compiled before any instantiations). For this purpose, we use a
376 -- separate table of messages. The reason we do this is twofold:
377
378 -- First, the messages can get changed by various processing
379 -- including the insertion of tokens etc, making it hard to
380 -- do the comparison.
381
382 -- Second, we will suppress a warning on a template if it is not in
383 -- the current extended source unit. That's reasonable and means we
384 -- don't want the warning on the instantiation here either, but it
385 -- does mean that the main error table would not in any case include
386 -- the message.
387
388 if Flag_Location = Orig_Loc then
389 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
390 Warn_On_Instance := False;
391
392 -- Here we have an instance message
393
394 else
395 -- Delete if debug flag off, and this message duplicates a message
396 -- already posted on the corresponding template
397
398 if not Debug_Flag_GG then
399 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
400 if Msg = Non_Instance_Msgs.Table (J).Msg.all
401 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
402 then
403 return;
404 end if;
405 end loop;
406 end if;
407
408 -- No duplicate, so error/warning will be posted on instance
409
410 Warn_On_Instance := Error_Msg_Kind = Warning;
411 end if;
412
413 -- Ignore warning message that is suppressed for this location. Note
414 -- that style checks are not considered warning messages for this
415 -- purpose.
416
417 if Error_Msg_Kind = Warning
418 and then Warnings_Suppressed (Orig_Loc) /= No_String
419 then
420 return;
421
422 -- For style messages, check too many messages so far
423
424 elsif Error_Msg_Kind = Style
425 and then Maximum_Messages /= 0
426 and then Warnings_Detected >= Maximum_Messages
427 then
428 return;
429
430 -- Suppress warnings inside a loop that is known to be null or is
431 -- probably null (i.e. when loop executes only if invalid values
432 -- present). In either case warnings in the loop are likely to be junk.
433
434 elsif Error_Msg_Kind = Warning and then Present (N) then
435
436 declare
437 P : Node_Id;
438
439 begin
440 P := Parent (N);
441 while Present (P) loop
442 if Nkind (P) = N_Loop_Statement
443 and then Suppress_Loop_Warnings (P)
444 then
445 return;
446 end if;
447
448 P := Parent (P);
449 end loop;
450 end;
451 end if;
452
453 -- The idea at this stage is that we have two kinds of messages
454
455 -- First, we have those messages that are to be placed as requested at
456 -- Flag_Location. This includes messages that have nothing to do with
457 -- generics, and also messages placed on generic templates that reflect
458 -- an error in the template itself. For such messages we simply call
459 -- Error_Msg_Internal to place the message in the requested location.
460
461 if Instantiation (Sindex) = No_Location then
462 Error_Msg_Internal (Msg, Flag_Span, Flag_Span, False);
463 return;
464 end if;
465
466 -- If we are trying to flag an error in an instantiation, we may have
467 -- a generic contract violation. What we generate in this case is:
468
469 -- instantiation error at ...
470 -- original error message
471
472 -- or
473
474 -- warning: in instantiation at ...
475 -- warning: original warning message
476
477 -- or
478
479 -- info: in instantiation at ...
480 -- info: original info message
481
482 -- All these messages are posted at the location of the top level
483 -- instantiation. If there are nested instantiations, then the
484 -- instantiation error message can be repeated, pointing to each
485 -- of the relevant instantiations.
486
487 -- Note: the instantiation mechanism is also shared for inlining of
488 -- subprogram bodies when front end inlining is done. In this case the
489 -- messages have the form:
490
491 -- in inlined body at ...
492 -- original error message
493
494 -- or
495
496 -- warning: in inlined body at ...
497 -- warning: original warning message
498
499 -- or
500
501 -- info: in inlined body at ...
502 -- info: original info message
503
504 -- OK, here we have an instantiation error, and we need to generate the
505 -- error on the instantiation, rather than on the template.
506
507 declare
508 Actual_Error_Loc : Source_Ptr;
509 -- Location of outer level instantiation in instantiation case, or
510 -- just a copy of Flag_Location in the normal case. This is the
511 -- location where all error messages will actually be posted.
512
513 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
514 -- Save possible location set for caller's message. We need to use
515 -- Error_Msg_Sloc for the location of the instantiation error but we
516 -- have to preserve a possible original value.
517
518 X : Source_File_Index;
519
520 Msg_Cont_Status : Boolean;
521 -- Used to label continuation lines in instantiation case with
522 -- proper Msg_Cont status.
523
524 begin
525 -- Loop to find highest level instantiation, where all error
526 -- messages will be placed.
527
528 X := Sindex;
529 loop
530 Actual_Error_Loc := Instantiation (X);
531 X := Get_Source_File_Index (Actual_Error_Loc);
532 exit when Instantiation (X) = No_Location;
533 end loop;
534
535 -- Since we are generating the messages at the instantiation point in
536 -- any case, we do not want the references to the bad lines in the
537 -- instance to be annotated with the location of the instantiation.
538
539 Suppress_Instance_Location := True;
540 Msg_Cont_Status := False;
541
542 -- Loop to generate instantiation messages
543
544 Error_Msg_Sloc := Flag_Location;
545 X := Get_Source_File_Index (Flag_Location);
546 while Instantiation (X) /= No_Location loop
547
548 -- Suppress instantiation message on continuation lines
549
550 if Msg (Msg'First) /= '\' then
551
552 -- Case of inlined body
553
554 if Inlined_Body (X) then
555 if Error_Msg_Kind = Info then
556 Error_Msg_Internal
557 (Msg => "info: in inlined body #",
558 Span => To_Span (Actual_Error_Loc),
559 Opan => Flag_Span,
560 Msg_Cont => Msg_Cont_Status);
561
562 elsif Error_Msg_Kind = Warning then
563 Error_Msg_Internal
564 (Msg => Warn_Insertion & "in inlined body #",
565 Span => To_Span (Actual_Error_Loc),
566 Opan => Flag_Span,
567 Msg_Cont => Msg_Cont_Status);
568
569 elsif Error_Msg_Kind = Style then
570 Error_Msg_Internal
571 (Msg => "style: in inlined body #",
572 Span => To_Span (Actual_Error_Loc),
573 Opan => Flag_Span,
574 Msg_Cont => Msg_Cont_Status);
575
576 else
577 Error_Msg_Internal
578 (Msg => "error in inlined body #",
579 Span => To_Span (Actual_Error_Loc),
580 Opan => Flag_Span,
581 Msg_Cont => Msg_Cont_Status);
582 end if;
583
584 -- Case of generic instantiation
585
586 else
587 if Error_Msg_Kind = Info then
588 Error_Msg_Internal
589 (Msg => "info: in instantiation #",
590 Span => To_Span (Actual_Error_Loc),
591 Opan => Flag_Span,
592 Msg_Cont => Msg_Cont_Status);
593
594 elsif Error_Msg_Kind = Warning then
595 Error_Msg_Internal
596 (Msg => Warn_Insertion & "in instantiation #",
597 Span => To_Span (Actual_Error_Loc),
598 Opan => Flag_Span,
599 Msg_Cont => Msg_Cont_Status);
600
601 elsif Error_Msg_Kind = Style then
602 Error_Msg_Internal
603 (Msg => "style: in instantiation #",
604 Span => To_Span (Actual_Error_Loc),
605 Opan => Flag_Span,
606 Msg_Cont => Msg_Cont_Status);
607
608 else
609 Error_Msg_Internal
610 (Msg => "instantiation error #",
611 Span => To_Span (Actual_Error_Loc),
612 Opan => Flag_Span,
613 Msg_Cont => Msg_Cont_Status);
614 end if;
615 end if;
616 end if;
617
618 Error_Msg_Sloc := Instantiation (X);
619 X := Get_Source_File_Index (Error_Msg_Sloc);
620 Msg_Cont_Status := True;
621 end loop;
622
623 Suppress_Instance_Location := False;
624 Error_Msg_Sloc := Save_Error_Msg_Sloc;
625
626 -- Here we output the original message on the outer instantiation
627
628 Error_Msg_Internal
629 (Msg => Msg,
630 Span => To_Span (Actual_Error_Loc),
631 Opan => Flag_Span,
632 Msg_Cont => Msg_Cont_Status);
633 end;
634 end Error_Msg;
635
636 ----------------------------------
637 -- Error_Msg_Ada_2005_Extension --
638 ----------------------------------
639
640 procedure Error_Msg_Ada_2005_Extension (Extension : String) is
641 Loc : constant Source_Ptr := Token_Ptr;
642 begin
643 if Ada_Version < Ada_2005 then
644 Error_Msg (Extension & " is an Ada 2005 extension", Loc);
645
646 if No (Ada_Version_Pragma) then
647 Error_Msg ("\unit must be compiled with -gnat05 switch", Loc);
648 else
649 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
650 Error_Msg ("\incompatible with Ada version set#", Loc);
651 end if;
652 end if;
653 end Error_Msg_Ada_2005_Extension;
654
655 --------------------------------
656 -- Error_Msg_Ada_2012_Feature --
657 --------------------------------
658
659 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
660 begin
661 if Ada_Version < Ada_2012 then
662 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
663
664 if No (Ada_Version_Pragma) then
665 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
666 else
667 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
668 Error_Msg ("\incompatible with Ada version set#", Loc);
669 end if;
670 end if;
671 end Error_Msg_Ada_2012_Feature;
672
673 --------------------------------
674 -- Error_Msg_Ada_2022_Feature --
675 --------------------------------
676
677 procedure Error_Msg_Ada_2022_Feature (Feature : String; Loc : Source_Ptr) is
678 begin
679 if Ada_Version < Ada_2022 then
680 Error_Msg (Feature & " is an Ada 2022 feature", Loc);
681
682 if No (Ada_Version_Pragma) then
683 Error_Msg ("\unit must be compiled with -gnat2022 switch", Loc);
684 else
685 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
686 Error_Msg ("\incompatible with Ada version set#", Loc);
687 end if;
688 end if;
689 end Error_Msg_Ada_2022_Feature;
690
691 ------------------
692 -- Error_Msg_AP --
693 ------------------
694
695 procedure Error_Msg_AP (Msg : String) is
696 S1 : Source_Ptr;
697 C : Character;
698
699 begin
700 -- If we had saved the Scan_Ptr value after scanning the previous
701 -- token, then we would have exactly the right place for putting
702 -- the flag immediately at hand. However, that would add at least
703 -- two instructions to a Scan call *just* to service the possibility
704 -- of an Error_Msg_AP call. So instead we reconstruct that value.
705
706 -- We have two possibilities, start with Prev_Token_Ptr and skip over
707 -- the current token, which is made harder by the possibility that this
708 -- token may be in error, or start with Token_Ptr and work backwards.
709 -- We used to take the second approach, but it's hard because of
710 -- comments, and harder still because things that look like comments
711 -- can appear inside strings. So now we take the first approach.
712
713 -- Note: in the case where there is no previous token, Prev_Token_Ptr
714 -- is set to Source_First, which is a reasonable position for the
715 -- error flag in this situation.
716
717 S1 := Prev_Token_Ptr;
718 C := Source (S1);
719
720 -- If the previous token is a string literal, we need a special approach
721 -- since there may be white space inside the literal and we don't want
722 -- to stop on that white space.
723
724 -- Note: since this is an error recovery issue anyway, it is not worth
725 -- worrying about special UTF_32 line terminator characters here.
726
727 if Prev_Token = Tok_String_Literal then
728 loop
729 S1 := S1 + 1;
730
731 if Source (S1) = C then
732 S1 := S1 + 1;
733 exit when Source (S1) /= C;
734 elsif Source (S1) in Line_Terminator then
735 exit;
736 end if;
737 end loop;
738
739 -- Character literal also needs special handling
740
741 elsif Prev_Token = Tok_Char_Literal then
742 S1 := S1 + 3;
743
744 -- Otherwise we search forward for the end of the current token, marked
745 -- by a line terminator, white space, a comment symbol or if we bump
746 -- into the following token (i.e. the current token).
747
748 -- Again, it is not worth worrying about UTF_32 special line terminator
749 -- characters in this context, since this is only for error recovery.
750
751 else
752 while Source (S1) not in Line_Terminator
753 and then Source (S1) /= ' '
754 and then Source (S1) /= ASCII.HT
755 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
756 and then S1 /= Token_Ptr
757 loop
758 S1 := S1 + 1;
759 end loop;
760 end if;
761
762 -- S1 is now set to the location for the flag
763
764 Error_Msg (Msg, S1);
765 end Error_Msg_AP;
766
767 ------------------
768 -- Error_Msg_BC --
769 ------------------
770
771 procedure Error_Msg_BC (Msg : String) is
772 begin
773 -- If we are at end of file, post the flag after the previous token
774
775 if Token = Tok_EOF then
776 Error_Msg_AP (Msg);
777
778 -- If we are at start of file, post the flag at the current token
779
780 elsif Token_Ptr = Source_First (Current_Source_File) then
781 Error_Msg_SC (Msg);
782
783 -- If the character before the current token is a space or a horizontal
784 -- tab, then we place the flag on this character (in the case of a tab
785 -- we would really like to place it in the "last" character of the tab
786 -- space, but that it too much trouble to worry about).
787
788 elsif Source (Token_Ptr - 1) = ' '
789 or else Source (Token_Ptr - 1) = ASCII.HT
790 then
791 Error_Msg (Msg, Token_Ptr - 1);
792
793 -- If there is no space or tab before the current token, then there is
794 -- no room to place the flag before the token, so we place it on the
795 -- token instead (this happens for example at the start of a line).
796
797 else
798 Error_Msg (Msg, Token_Ptr);
799 end if;
800 end Error_Msg_BC;
801
802 -------------------
803 -- Error_Msg_CRT --
804 -------------------
805
806 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
807 begin
808 if No_Run_Time_Mode then
809 Error_Msg_N ('|' & Feature & " not allowed in no run time mode", N);
810
811 else pragma Assert (Configurable_Run_Time_Mode);
812 Error_Msg_N ('|' & Feature & " not supported by configuration>", N);
813 end if;
814
815 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
816 end Error_Msg_CRT;
817
818 ------------------
819 -- Error_Msg_PT --
820 ------------------
821
822 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
823 begin
824 Error_Msg_N
825 ("illegal overriding of subprogram inherited from interface", E);
826
827 Error_Msg_Sloc := Sloc (Iface_Prim);
828
829 if Ekind (E) = E_Function then
830 Error_Msg_N
831 ("\first formal of & declared # must be of mode `IN` "
832 & "or access-to-constant", E);
833 else
834 Error_Msg_N
835 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
836 & "or access-to-variable", E);
837 end if;
838 end Error_Msg_PT;
839
840 -----------------
841 -- Error_Msg_F --
842 -----------------
843
844 procedure Error_Msg_F (Msg : String; N : Node_Id) is
845 Fst, Lst : Node_Id;
846 begin
847 First_And_Last_Nodes (N, Fst, Lst);
848 Error_Msg_NEL (Msg, N, N,
849 To_Span (Ptr => Sloc (Fst),
850 First => First_Sloc (Fst),
851 Last => Last_Sloc (Lst)));
852 end Error_Msg_F;
853
854 ------------------
855 -- Error_Msg_FE --
856 ------------------
857
858 procedure Error_Msg_FE
859 (Msg : String;
860 N : Node_Id;
861 E : Node_Or_Entity_Id)
862 is
863 Fst, Lst : Node_Id;
864 begin
865 First_And_Last_Nodes (N, Fst, Lst);
866 Error_Msg_NEL (Msg, N, E,
867 To_Span (Ptr => Sloc (Fst),
868 First => First_Sloc (Fst),
869 Last => Last_Sloc (Lst)));
870 end Error_Msg_FE;
871
872 ------------------------------
873 -- Error_Msg_GNAT_Extension --
874 ------------------------------
875
876 procedure Error_Msg_GNAT_Extension
877 (Extension : String;
878 Loc : Source_Ptr;
879 Is_Core_Extension : Boolean := False)
880 is
881 begin
882 if (if Is_Core_Extension
883 then Core_Extensions_Allowed
884 else All_Extensions_Allowed)
885 then
886 return;
887 end if;
888
889 Error_Msg (Extension & " is a 'G'N'A'T-specific extension", Loc);
890
891 if No (Ada_Version_Pragma) then
892 if Is_Core_Extension then
893 Error_Msg
894 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
895 "or use pragma Extensions_Allowed (On) '[or All_Extensions']",
896 Loc);
897 else
898 Error_Msg
899 ("\unit must be compiled with -gnatX0 " &
900 "or use pragma Extensions_Allowed (All_Extensions)", Loc);
901 end if;
902 else
903 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
904 Error_Msg ("\incompatible with Ada version set#", Loc);
905 if Is_Core_Extension then
906 Error_Msg
907 ("\must use pragma Extensions_Allowed (On)" &
908 " '[or All_Extensions']", Loc);
909 else
910 Error_Msg
911 ("\must use pragma Extensions_Allowed (All_Extensions)", Loc);
912 end if;
913 end if;
914 end Error_Msg_GNAT_Extension;
915
916 ------------------------
917 -- Error_Msg_Internal --
918 ------------------------
919
920 procedure Error_Msg_Internal
921 (Msg : String;
922 Span : Source_Span;
923 Opan : Source_Span;
924 Msg_Cont : Boolean)
925 is
926 Sptr : constant Source_Ptr := Span.Ptr;
927 Optr : constant Source_Ptr := Opan.Ptr;
928
929 Next_Msg : Error_Msg_Id;
930 -- Pointer to next message at insertion point
931
932 Prev_Msg : Error_Msg_Id;
933 -- Pointer to previous message at insertion point
934
935 Temp_Msg : Error_Msg_Id;
936
937 Warn_Err : Boolean;
938 -- Set if warning to be treated as error
939
940 procedure Handle_Serious_Error;
941 -- Internal procedure to do all error message handling for a serious
942 -- error message, other than bumping the error counts and arranging
943 -- for the message to be output.
944
945 --------------------------
946 -- Handle_Serious_Error --
947 --------------------------
948
949 procedure Handle_Serious_Error is
950 begin
951 -- Turn off code generation if not done already
952
953 if Operating_Mode = Generate_Code then
954 Operating_Mode := Check_Semantics;
955 Expander_Active := False;
956 end if;
957
958 -- Set the fatal error flag in the unit table unless we are in
959 -- Try_Semantics mode (in which case we set ignored mode if not
960 -- currently set. This stops the semantics from being performed
961 -- if we find a serious error. This is skipped if we are currently
962 -- dealing with the configuration pragma file.
963
964 if Current_Source_Unit /= No_Unit then
965 declare
966 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
967 begin
968 if Try_Semantics then
969 if Fatal_Error (U) = None then
970 Set_Fatal_Error (U, Error_Ignored);
971 end if;
972 else
973 Set_Fatal_Error (U, Error_Detected);
974 end if;
975 end;
976 end if;
977
978 -- Disable warnings on unused use clauses and the like. Otherwise, an
979 -- error might hide a reference to an entity in a used package, so
980 -- after fixing the error, the use clause no longer looks like it was
981 -- unused.
982
983 Warnsw.Check_Unreferenced := False;
984 Warnsw.Check_Unreferenced_Formals := False;
985 end Handle_Serious_Error;
986
987 -- Start of processing for Error_Msg_Internal
988
989 begin
990 -- Detect common mistake of prefixing or suffixing the message with a
991 -- space character.
992
993 pragma Assert (Msg (Msg'First) /= ' ' and then Msg (Msg'Last) /= ' ');
994
995 Continuation := Msg_Cont;
996 Continuation_New_Line := False;
997 Suppress_Message := False;
998 Kill_Message := False;
999 Set_Msg_Text (Msg, Sptr);
1000
1001 -- Kill continuation if parent message killed
1002
1003 if Continuation and Last_Killed then
1004 return;
1005 end if;
1006
1007 -- Return without doing anything if message is suppressed
1008
1009 if Suppress_Message
1010 and then not All_Errors_Mode
1011 and then Error_Msg_Kind /= Warning
1012 and then not Is_Unconditional_Msg
1013 then
1014 if not Continuation then
1015 Last_Killed := True;
1016 end if;
1017
1018 return;
1019 end if;
1020
1021 -- Return without doing anything if message is killed and this is not
1022 -- the first error message. The philosophy is that if we get a weird
1023 -- error message and we already have had a message, then we hope the
1024 -- weird message is a junk cascaded message
1025
1026 if Kill_Message
1027 and then not All_Errors_Mode
1028 and then Total_Errors_Detected /= 0
1029 then
1030 if not Continuation then
1031 Last_Killed := True;
1032 end if;
1033
1034 return;
1035 end if;
1036
1037 if Error_Msg_Kind = Info then
1038
1039 -- Immediate return if info messages are suppressed
1040
1041 if Info_Suppressed then
1042 Cur_Msg := No_Error_Msg;
1043 return;
1044 end if;
1045
1046 -- If the flag location is in the main extended source unit then for
1047 -- sure we want the message since it definitely belongs.
1048
1049 if In_Extended_Main_Source_Unit (Sptr) then
1050 null;
1051
1052 -- Keep info message if message text contains !!
1053
1054 elsif Has_Double_Exclam then
1055 null;
1056
1057 -- Here is where we delete a message from a with'ed unit
1058
1059 else
1060 Cur_Msg := No_Error_Msg;
1061
1062 if not Continuation then
1063 Last_Killed := True;
1064 end if;
1065
1066 return;
1067 end if;
1068
1069 -- Special check for warning message to see if it should be output
1070
1071 elsif Error_Msg_Kind = Warning then
1072
1073 -- Immediate return if warning message and warnings are suppressed
1074
1075 if Warnings_Suppressed (Optr) /= No_String
1076 or else Warnings_Suppressed (Sptr) /= No_String
1077 then
1078 Cur_Msg := No_Error_Msg;
1079 return;
1080 end if;
1081
1082 -- If the flag location is in the main extended source unit then for
1083 -- sure we want the warning since it definitely belongs.
1084
1085 if In_Extended_Main_Source_Unit (Sptr) then
1086 null;
1087
1088 -- If the main unit has not been read yet. The warning must be on
1089 -- a configuration file: gnat.adc or user-defined. This means we
1090 -- are not parsing the main unit yet, so skip following checks.
1091
1092 elsif No (Cunit (Main_Unit)) then
1093 null;
1094
1095 -- If the flag location is not in the extended main source unit, then
1096 -- we want to eliminate the warning, unless it is in the extended
1097 -- main code unit and we want warnings on the instance.
1098
1099 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
1100 null;
1101
1102 -- Keep warning if debug flag G set
1103
1104 elsif Debug_Flag_GG then
1105 null;
1106
1107 -- Keep warning if message text contains !!
1108
1109 elsif Has_Double_Exclam then
1110 null;
1111
1112 -- Here is where we delete a warning from a with'ed unit
1113
1114 else
1115 Cur_Msg := No_Error_Msg;
1116
1117 if not Continuation then
1118 Last_Killed := True;
1119 end if;
1120
1121 return;
1122 end if;
1123 end if;
1124
1125 -- If message is to be ignored in special ignore message mode, this is
1126 -- where we do this special processing, bypassing message output.
1127
1128 if Ignore_Errors_Enable > 0 then
1129 if Error_Msg_Kind = Erroutc.Error then
1130 Handle_Serious_Error;
1131 end if;
1132
1133 return;
1134 end if;
1135
1136 -- If error message line length set, and this is a continuation message
1137 -- then all we do is to append the text to the text of the last message
1138 -- with a comma space separator (eliminating a possible (style) or
1139 -- info prefix).
1140
1141 if Error_Msg_Line_Length /= 0 and then Continuation then
1142 Cur_Msg := Errors.Last;
1143
1144 declare
1145 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
1146 Newm : String (1 .. Oldm'Last + 2 + Msglen);
1147 Newl : Natural;
1148 M : Natural;
1149
1150 begin
1151 -- First copy old message to new one and free it
1152
1153 Newm (Oldm'Range) := Oldm.all;
1154 Newl := Oldm'Length;
1155 Free (Oldm);
1156
1157 -- Remove (style) or info: at start of message
1158
1159 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
1160 M := 9;
1161
1162 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
1163 M := 7;
1164
1165 else
1166 M := 1;
1167 end if;
1168
1169 -- Now deal with separation between messages. Normally this is
1170 -- simply comma space, but there are some special cases.
1171
1172 -- If continuation new line, then put actual NL character in msg
1173
1174 if Continuation_New_Line then
1175 Newl := Newl + 1;
1176 Newm (Newl) := ASCII.LF;
1177
1178 -- If continuation message is enclosed in parentheses, then
1179 -- special treatment (don't need a comma, and we want to combine
1180 -- successive parenthetical remarks into a single one with
1181 -- separating commas).
1182
1183 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
1184
1185 -- Case where existing message ends in right paren, remove
1186 -- and separate parenthetical remarks with a comma.
1187
1188 if Newm (Newl) = ')' then
1189 Newm (Newl) := ',';
1190 Msg_Buffer (M) := ' ';
1191
1192 -- Case where we are adding new parenthetical comment
1193
1194 else
1195 Newl := Newl + 1;
1196 Newm (Newl) := ' ';
1197 end if;
1198
1199 -- Case where continuation not in parens and no new line
1200
1201 else
1202 Newm (Newl + 1 .. Newl + 2) := ", ";
1203 Newl := Newl + 2;
1204 end if;
1205
1206 -- Append new message
1207
1208 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1209 Msg_Buffer (M .. Msglen);
1210 Newl := Newl + Msglen - M + 1;
1211 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1212
1213 -- Update warning msg flag and message doc char if needed
1214
1215 if Error_Msg_Kind = Warning then
1216 if Errors.Table (Cur_Msg).Kind /= Warning then
1217 Errors.Table (Cur_Msg).Kind := Warning;
1218 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1219
1220 elsif Warning_Msg_Char /= " " then
1221 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1222 end if;
1223 end if;
1224 end;
1225
1226 return;
1227 end if;
1228
1229 -- Here we build a new error object
1230
1231 Errors.Append
1232 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1233 Next => No_Error_Msg,
1234 Prev => No_Error_Msg,
1235 Sptr => Span,
1236 Optr => Opan,
1237 Insertion_Sloc =>
1238 (if Has_Insertion_Line then Error_Msg_Sloc else No_Location),
1239 Sfile => Get_Source_File_Index (Sptr),
1240 Line => Get_Physical_Line_Number (Sptr),
1241 Col => Get_Column_Number (Sptr),
1242 Compile_Time_Pragma => Is_Compile_Time_Msg,
1243 Warn_Err => False, -- reset below
1244 Warn_Chr => Warning_Msg_Char,
1245 Uncond => Is_Unconditional_Msg,
1246 Msg_Cont => Continuation,
1247 Deleted => False,
1248 Kind => Error_Msg_Kind));
1249 Cur_Msg := Errors.Last;
1250
1251 -- Test if warning to be treated as error
1252
1253 Warn_Err :=
1254 Error_Msg_Kind in Warning | Style
1255 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1256 or else Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg))
1257 or else Is_Runtime_Raise);
1258
1259 -- Propagate Warn_Err to this message and preceding continuations.
1260
1261 for J in reverse 1 .. Errors.Last loop
1262 Errors.Table (J).Warn_Err := Warn_Err;
1263
1264 exit when not Errors.Table (J).Msg_Cont;
1265 end loop;
1266
1267 -- If immediate errors mode set, output error message now. Also output
1268 -- now if the -d1 debug flag is set (so node number message comes out
1269 -- just before actual error message)
1270
1271 if Debug_Flag_OO or else Debug_Flag_1 then
1272 Write_Eol;
1273 Output_Source_Line
1274 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1275 Temp_Msg := Cur_Msg;
1276 Output_Error_Msgs (Temp_Msg);
1277
1278 -- If not in immediate errors mode, then we insert the message in the
1279 -- error chain for later output by Finalize. The messages are sorted
1280 -- first by unit (main unit comes first), and within a unit by source
1281 -- location (earlier flag location first in the chain).
1282
1283 else
1284 -- First a quick check, does this belong at the very end of the chain
1285 -- of error messages. This saves a lot of time in the normal case if
1286 -- there are lots of messages.
1287
1288 if Last_Error_Msg /= No_Error_Msg
1289 and then Errors.Table (Cur_Msg).Sfile
1290 = Errors.Table (Last_Error_Msg).Sfile
1291 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr.Ptr
1292 or else (Sptr = Errors.Table (Last_Error_Msg).Sptr.Ptr
1293 and then Optr
1294 > Errors.Table (Last_Error_Msg)
1295 .Optr
1296 .Ptr))
1297 then
1298 Prev_Msg := Last_Error_Msg;
1299 Next_Msg := No_Error_Msg;
1300
1301 -- Otherwise do a full sequential search for the insertion point
1302
1303 else
1304 Prev_Msg := No_Error_Msg;
1305 Next_Msg := First_Error_Msg;
1306 while Next_Msg /= No_Error_Msg loop
1307 exit when
1308 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1309
1310 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1311 then
1312 exit when
1313 Sptr < Errors.Table (Next_Msg).Sptr.Ptr
1314 or else (Sptr = Errors.Table (Next_Msg).Sptr.Ptr
1315 and then Optr < Errors.Table (Next_Msg).Optr.Ptr);
1316 end if;
1317
1318 Prev_Msg := Next_Msg;
1319 Next_Msg := Errors.Table (Next_Msg).Next;
1320 end loop;
1321 end if;
1322
1323 -- Now we insert the new message in the error chain.
1324
1325 -- The possible insertion point for the new message is after Prev_Msg
1326 -- and before Next_Msg. However, this is where we do a special check
1327 -- for redundant parsing messages, defined as messages posted on the
1328 -- same line. The idea here is that probably such messages are junk
1329 -- from the parser recovering. In full errors mode, we don't do this
1330 -- deletion, but otherwise such messages are discarded at this stage.
1331
1332 if Compiler_State = Parsing
1333 and then not All_Errors_Mode
1334 and then Is_Redundant_Error_Message (Prev_Msg, Cur_Msg)
1335 then
1336 pragma Assert (not Continuation);
1337
1338 Last_Killed := True;
1339 return;
1340 end if;
1341
1342 -- Come here if message is to be inserted in the error chain
1343
1344 if not Continuation then
1345 Last_Killed := False;
1346 end if;
1347
1348 if Prev_Msg = No_Error_Msg then
1349 First_Error_Msg := Cur_Msg;
1350 else
1351 Errors.Table (Prev_Msg).Next := Cur_Msg;
1352 end if;
1353
1354 Errors.Table (Cur_Msg).Next := Next_Msg;
1355
1356 if Next_Msg = No_Error_Msg then
1357 Last_Error_Msg := Cur_Msg;
1358 end if;
1359 end if;
1360
1361 Increase_Error_Msg_Count (Errors.Table (Cur_Msg));
1362
1363 if Errors.Table (Cur_Msg).Kind = Erroutc.Error then
1364 Handle_Serious_Error;
1365
1366 -- If not serious error, set Fatal_Error to indicate ignored error
1367
1368 elsif Errors.Table (Cur_Msg).Kind = Non_Serious_Error then
1369 declare
1370 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1371 begin
1372 if Fatal_Error (U) = None then
1373 Set_Fatal_Error (U, Error_Ignored);
1374 end if;
1375 end;
1376 end if;
1377
1378 -- Record warning message issued
1379
1380 if Errors.Table (Cur_Msg).Kind = Warning
1381 and then not Errors.Table (Cur_Msg).Msg_Cont
1382 then
1383 Warning_Msg := Cur_Msg;
1384 end if;
1385
1386 -- If too many warnings turn off warnings
1387
1388 if Maximum_Messages /= 0 then
1389 if Warnings_Detected = Maximum_Messages then
1390 Warning_Mode := Suppress;
1391 end if;
1392
1393 -- If too many errors abandon compilation
1394
1395 if Total_Errors_Detected = Maximum_Messages then
1396 raise Unrecoverable_Error;
1397 end if;
1398 end if;
1399
1400 if Has_Error_Code then
1401 declare
1402 Msg : constant String :=
1403 "\launch ""gnatprove --explain=[]"" for more information";
1404 begin
1405 Has_Double_Exclam := False;
1406 Has_Error_Code := False;
1407 Has_Insertion_Line := False;
1408
1409 Error_Msg_Internal
1410 (Msg => Msg, Span => Span, Opan => Opan, Msg_Cont => True);
1411 end;
1412 end if;
1413 end Error_Msg_Internal;
1414
1415 -----------------
1416 -- Error_Msg_N --
1417 -----------------
1418
1419 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1420 Fst, Lst : Node_Id;
1421 begin
1422 First_And_Last_Nodes (N, Fst, Lst);
1423 Error_Msg_NEL (Msg, N, N,
1424 To_Span (Ptr => Sloc (N),
1425 First => First_Sloc (Fst),
1426 Last => Last_Sloc (Lst)));
1427 end Error_Msg_N;
1428
1429 ------------------
1430 -- Error_Msg_NE --
1431 ------------------
1432
1433 procedure Error_Msg_NE
1434 (Msg : String;
1435 N : Node_Or_Entity_Id;
1436 E : Node_Or_Entity_Id)
1437 is
1438 Fst, Lst : Node_Id;
1439 begin
1440 First_And_Last_Nodes (N, Fst, Lst);
1441 Error_Msg_NEL (Msg, N, E,
1442 To_Span (Ptr => Sloc (N),
1443 First => First_Sloc (Fst),
1444 Last => Last_Sloc (Lst)));
1445 end Error_Msg_NE;
1446
1447 -------------------
1448 -- Error_Msg_NEL --
1449 -------------------
1450
1451 procedure Error_Msg_NEL
1452 (Msg : String;
1453 N : Node_Or_Entity_Id;
1454 E : Node_Or_Entity_Id;
1455 Flag_Location : Source_Ptr)
1456 is
1457 Fst, Lst : Node_Id;
1458 begin
1459 First_And_Last_Nodes (N, Fst, Lst);
1460 Error_Msg_NEL
1461 (Msg, N, E,
1462 To_Span (Ptr => Flag_Location,
1463 First => Source_Ptr'Min (Flag_Location, First_Sloc (Fst)),
1464 Last => Source_Ptr'Max (Flag_Location, Last_Sloc (Lst))));
1465 end Error_Msg_NEL;
1466
1467 procedure Error_Msg_NEL
1468 (Msg : String;
1469 N : Node_Or_Entity_Id;
1470 E : Node_Or_Entity_Id;
1471 Flag_Span : Source_Span)
1472 is
1473 begin
1474 if Special_Msg_Delete (Msg, N, E) then
1475 return;
1476 end if;
1477
1478 Prescan_Message (Msg);
1479
1480 -- Special handling for warning messages
1481
1482 if Error_Msg_Kind = Warning then
1483
1484 -- Suppress if no warnings set for either entity or node
1485
1486 if No_Warnings (N) or else No_Warnings (E) then
1487
1488 -- Disable any continuation messages as well
1489
1490 Last_Killed := True;
1491 return;
1492 end if;
1493 end if;
1494
1495 -- Test for message to be output
1496
1497 if All_Errors_Mode
1498 or else Is_Unconditional_Msg
1499 or else Error_Msg_Kind = Warning
1500 or else OK_Node (N)
1501 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1502 then
1503 Debug_Output (N);
1504 Error_Msg_Node_1 := E;
1505 Error_Msg (Msg, Flag_Span, N);
1506
1507 else
1508 Last_Killed := True;
1509 end if;
1510
1511 if not Get_Ignore_Errors then
1512 Set_Posted (N);
1513 end if;
1514 end Error_Msg_NEL;
1515
1516 ------------------
1517 -- Error_Msg_NW --
1518 ------------------
1519
1520 procedure Error_Msg_NW
1521 (Eflag : Boolean;
1522 Msg : String;
1523 N : Node_Or_Entity_Id)
1524 is
1525 Fst, Lst : Node_Id;
1526 begin
1527 if Eflag
1528 and then In_Extended_Main_Source_Unit (N)
1529 and then Comes_From_Source (N)
1530 then
1531 First_And_Last_Nodes (N, Fst, Lst);
1532 Error_Msg_NEL (Msg, N, N,
1533 To_Span (Ptr => Sloc (N),
1534 First => First_Sloc (Fst),
1535 Last => Last_Sloc (Lst)));
1536 end if;
1537 end Error_Msg_NW;
1538
1539 -----------------
1540 -- Error_Msg_S --
1541 -----------------
1542
1543 procedure Error_Msg_S (Msg : String) is
1544 begin
1545 Error_Msg (Msg, Scan_Ptr);
1546 end Error_Msg_S;
1547
1548 ------------------
1549 -- Error_Msg_SC --
1550 ------------------
1551
1552 procedure Error_Msg_SC (Msg : String) is
1553 begin
1554 -- If we are at end of file, post the flag after the previous token
1555
1556 if Token = Tok_EOF then
1557 Error_Msg_AP (Msg);
1558
1559 -- For all other cases the message is posted at the current token
1560 -- pointer position
1561
1562 else
1563 Error_Msg (Msg, Token_Ptr);
1564 end if;
1565 end Error_Msg_SC;
1566
1567 ------------------
1568 -- Error_Msg_SP --
1569 ------------------
1570
1571 procedure Error_Msg_SP (Msg : String) is
1572 begin
1573 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1574 -- is set to Source_First, which is a reasonable position for the
1575 -- error flag in this situation
1576
1577 Error_Msg (Msg, Prev_Token_Ptr);
1578 end Error_Msg_SP;
1579
1580 --------------
1581 -- Finalize --
1582 --------------
1583
1584 procedure Finalize (Last_Call : Boolean) is
1585 Cur : Error_Msg_Id;
1586 Nxt : Error_Msg_Id;
1587 F : Error_Msg_Id;
1588
1589 procedure Delete_Warning (E : Error_Msg_Id);
1590 -- Delete a warning msg if not already deleted and adjust warning count
1591
1592 --------------------
1593 -- Delete_Warning --
1594 --------------------
1595
1596 procedure Delete_Warning (E : Error_Msg_Id) is
1597 begin
1598 if not Errors.Table (E).Deleted then
1599 Errors.Table (E).Deleted := True;
1600 Warnings_Detected := Warnings_Detected - 1;
1601 end if;
1602 end Delete_Warning;
1603
1604 -- Start of processing for Finalize
1605
1606 begin
1607 -- Set Prev pointers
1608
1609 Cur := First_Error_Msg;
1610 while Cur /= No_Error_Msg loop
1611 Nxt := Errors.Table (Cur).Next;
1612 exit when Nxt = No_Error_Msg;
1613 Errors.Table (Nxt).Prev := Cur;
1614 Cur := Nxt;
1615 end loop;
1616
1617 -- Eliminate any duplicated error messages from the list. This is
1618 -- done after the fact to avoid problems with Change_Error_Text.
1619
1620 Cur := First_Error_Msg;
1621 while Cur /= No_Error_Msg loop
1622 Nxt := Errors.Table (Cur).Next;
1623
1624 F := Nxt;
1625 while F /= No_Error_Msg
1626 and then Errors.Table (F).Sptr.Ptr = Errors.Table (Cur).Sptr.Ptr
1627 loop
1628 Check_Duplicate_Message (Cur, F);
1629 F := Errors.Table (F).Next;
1630 end loop;
1631
1632 Cur := Nxt;
1633 end loop;
1634
1635 -- Mark any messages suppressed by specific warnings as Deleted
1636
1637 Cur := First_Error_Msg;
1638 while Cur /= No_Error_Msg loop
1639 declare
1640 CE : Error_Msg_Object renames Errors.Table (Cur);
1641 Tag : constant String := Get_Warning_Tag (Cur);
1642
1643 begin
1644 if CE.Kind = Warning
1645 and then not CE.Deleted
1646 and then
1647 (Warning_Specifically_Suppressed (CE.Sptr.Ptr, CE.Text, Tag)
1648 /= No_String
1649 or else
1650 Warning_Specifically_Suppressed (CE.Optr.Ptr, CE.Text, Tag)
1651 /= No_String)
1652 then
1653 Delete_Warning (Cur);
1654
1655 -- If this is a continuation, delete previous parts of message
1656
1657 F := Cur;
1658 while Errors.Table (F).Msg_Cont loop
1659 F := Errors.Table (F).Prev;
1660 exit when F = No_Error_Msg;
1661 Delete_Warning (F);
1662 end loop;
1663
1664 -- Delete any following continuations
1665
1666 F := Cur;
1667 loop
1668 F := Errors.Table (F).Next;
1669 exit when F = No_Error_Msg;
1670 exit when not Errors.Table (F).Msg_Cont;
1671 Delete_Warning (F);
1672 end loop;
1673 end if;
1674 end;
1675
1676 Cur := Errors.Table (Cur).Next;
1677 end loop;
1678
1679 Finalize_Called := True;
1680
1681 -- Check consistency of specific warnings (may add warnings). We only
1682 -- do this on the last call, after all possible warnings are posted.
1683
1684 if Last_Call then
1685 Validate_Specific_Warnings;
1686 end if;
1687 end Finalize;
1688
1689 ----------------
1690 -- First_Node --
1691 ----------------
1692
1693 function First_Node (C : Node_Id) return Node_Id is
1694 Fst, Lst : Node_Id;
1695 begin
1696 First_And_Last_Nodes (C, Fst, Lst);
1697 return Fst;
1698 end First_Node;
1699
1700 --------------------------
1701 -- First_And_Last_Nodes --
1702 --------------------------
1703
1704 procedure First_And_Last_Nodes
1705 (C : Node_Id;
1706 First_Node, Last_Node : out Node_Id)
1707 is
1708 Orig : constant Node_Id := Original_Node (C);
1709 Loc : constant Source_Ptr := Sloc (Orig);
1710 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1711 Earliest : Node_Id;
1712 Latest : Node_Id;
1713 Eloc : Source_Ptr;
1714 Lloc : Source_Ptr;
1715
1716 function Test_First_And_Last (N : Node_Id) return Traverse_Result;
1717 -- Function applied to every node in the construct
1718
1719 procedure Search_Tree_First_And_Last is new
1720 Traverse_Proc (Test_First_And_Last);
1721 -- Create traversal procedure
1722
1723 -------------------------
1724 -- Test_First_And_Last --
1725 -------------------------
1726
1727 function Test_First_And_Last (N : Node_Id) return Traverse_Result is
1728 Norig : constant Node_Id := Original_Node (N);
1729 Loc : constant Source_Ptr := Sloc (Norig);
1730
1731 begin
1732 -- ??? For assignments that require accessiblity checks, e.g.:
1733 --
1734 -- Y := Func (123);
1735 --
1736 -- the function call gets an extra actual parameter association with
1737 -- Sloc of the assigned name "Y":
1738 --
1739 -- Y := Func (123, A8b => 2);
1740 --
1741 -- We can simply ignore those extra actual parameters when
1742 -- determining the Sloc range of the "Func (123)" expression.
1743
1744 if Nkind (N) = N_Parameter_Association
1745 and then Is_Accessibility_Actual (N)
1746 then
1747 return Skip;
1748 end if;
1749
1750 -- Check for earlier
1751
1752 if Loc < Eloc
1753
1754 -- Ignore nodes with no useful location information
1755
1756 and then Loc /= Standard_Location
1757 and then Loc /= No_Location
1758
1759 -- Ignore nodes from a different file. This ensures against cases
1760 -- of strange foreign code somehow being present. We don't want
1761 -- wild placement of messages if that happens.
1762
1763 and then Get_Source_File_Index (Loc) = Sfile
1764 then
1765 Earliest := Norig;
1766 Eloc := Loc;
1767 end if;
1768
1769 -- Check for later
1770
1771 if Loc > Lloc
1772
1773 -- Ignore nodes with no useful location information
1774
1775 and then Loc /= Standard_Location
1776 and then Loc /= No_Location
1777
1778 -- Ignore nodes from a different file. This ensures against cases
1779 -- of strange foreign code somehow being present. We don't want
1780 -- wild placement of messages if that happens.
1781
1782 and then Get_Source_File_Index (Loc) = Sfile
1783 then
1784 Latest := Norig;
1785 Lloc := Loc;
1786 end if;
1787
1788 return OK_Orig;
1789 end Test_First_And_Last;
1790
1791 -- Start of processing for First_And_Last_Nodes
1792
1793 begin
1794 if Nkind (Orig) in N_Subexpr
1795 | N_Declaration
1796 | N_Access_To_Subprogram_Definition
1797 | N_Generic_Instantiation
1798 | N_Component_Association
1799 | N_Iterated_Component_Association
1800 | N_Later_Decl_Item
1801 | N_Use_Package_Clause
1802 | N_Array_Type_Definition
1803 | N_Renaming_Declaration
1804 | N_Generic_Renaming_Declaration
1805 | N_Assignment_Statement
1806 | N_Raise_Statement
1807 | N_Simple_Return_Statement
1808 | N_Exit_Statement
1809 | N_Pragma
1810 | N_Use_Type_Clause
1811 | N_With_Clause
1812 | N_Attribute_Definition_Clause
1813 | N_Subtype_Indication
1814 then
1815 Earliest := Orig;
1816 Eloc := Loc;
1817 Latest := Orig;
1818 Lloc := Loc;
1819 Search_Tree_First_And_Last (Orig);
1820 First_Node := Earliest;
1821 Last_Node := Latest;
1822
1823 else
1824 First_Node := Orig;
1825 Last_Node := Orig;
1826 end if;
1827 end First_And_Last_Nodes;
1828
1829 ----------------
1830 -- First_Sloc --
1831 ----------------
1832
1833 function First_Sloc (N : Node_Id) return Source_Ptr is
1834 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
1835 SF : constant Source_Ptr := Source_First (SI);
1836 SL : constant Source_Ptr := Source_Last (SI);
1837 Src : constant Source_Buffer_Ptr := Source_Text (SI);
1838 F : Node_Id;
1839 S : Source_Ptr;
1840
1841 begin
1842 F := First_Node (N);
1843 S := Sloc (F);
1844
1845 if S not in SF .. SL then
1846 return S;
1847 end if;
1848
1849 -- The following circuit is a bit subtle. When we have parenthesized
1850 -- expressions, then the Sloc will not record the location of the paren,
1851 -- but we would like to post the flag on the paren. So what we do is to
1852 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1853 -- any parentheses we know are present. Yes, we know this circuit is not
1854 -- 100% reliable (e.g. because we don't record all possible paren level
1855 -- values), but this is only for an error message so it is good enough.
1856
1857 Node_Loop : loop
1858 -- Include parentheses around the top node, except when they are
1859 -- required by the syntax of the parent node.
1860
1861 exit Node_Loop when F = N
1862 and then Paren_Required (N);
1863
1864 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1865
1866 -- We don't look more than 12 characters behind the current
1867 -- location, and in any case not past the front of the source.
1868
1869 Search_Loop : for K in 1 .. 12 loop
1870 exit Search_Loop when S = SF;
1871
1872 if Src (S - 1) = '(' then
1873 S := S - 1;
1874 exit Search_Loop;
1875
1876 elsif Src (S - 1) <= ' ' then
1877 S := S - 1;
1878
1879 else
1880 exit Search_Loop;
1881 end if;
1882 end loop Search_Loop;
1883 end loop Paren_Loop;
1884
1885 exit Node_Loop when F = N;
1886 F := Parent (F);
1887 exit Node_Loop when Nkind (F) not in N_Subexpr;
1888 end loop Node_Loop;
1889
1890 return S;
1891 end First_Sloc;
1892
1893 -----------------------
1894 -- Get_Ignore_Errors --
1895 -----------------------
1896
1897 function Get_Ignore_Errors return Boolean is
1898 begin
1899 return Errors_Must_Be_Ignored;
1900 end Get_Ignore_Errors;
1901
1902 ----------------
1903 -- Initialize --
1904 ----------------
1905
1906 procedure Initialize is
1907 begin
1908 Errors.Init;
1909 First_Error_Msg := No_Error_Msg;
1910 Last_Error_Msg := No_Error_Msg;
1911 Serious_Errors_Detected := 0;
1912 Total_Errors_Detected := 0;
1913 Cur_Msg := No_Error_Msg;
1914 List_Pragmas.Init;
1915
1916 -- Reset counts for warnings
1917
1918 Warnings_Treated_As_Errors := 0;
1919 Warnings_Detected := 0;
1920 Warnings_As_Errors_Count := 0;
1921
1922 -- Initialize warnings tables
1923
1924 Warnings.Init;
1925 Specific_Warnings.Init;
1926 end Initialize;
1927
1928 -------------------------------
1929 -- Is_Size_Too_Small_Message --
1930 -------------------------------
1931
1932 function Is_Size_Too_Small_Message (S : String) return Boolean is
1933 Size_For : constant String := "size for";
1934 pragma Assert (Size_Too_Small_Message (1 .. Size_For'Last) = Size_For);
1935 -- Assert that Size_Too_Small_Message starts with Size_For
1936 begin
1937 return S'Length >= Size_For'Length
1938 and then S (S'First .. S'First + Size_For'Length - 1) = Size_For;
1939 -- True if S starts with Size_For
1940 end Is_Size_Too_Small_Message;
1941
1942 --------------------------------
1943 -- Validate_Specific_Warnings --
1944 --------------------------------
1945
1946 procedure Validate_Specific_Warnings is
1947 begin
1948 if not Warnsw.Warn_On_Warnings_Off then
1949 return;
1950 end if;
1951
1952 for J in Specific_Warnings.First .. Specific_Warnings.Last loop
1953 declare
1954 SWE : Specific_Warning_Entry renames Specific_Warnings.Table (J);
1955
1956 begin
1957 if not SWE.Config then
1958
1959 -- Warn for unmatched Warnings (Off, ...)
1960
1961 if SWE.Open then
1962 Error_Msg
1963 ("?.w?pragma Warnings Off with no matching Warnings On",
1964 SWE.Start);
1965
1966 -- Warn for ineffective Warnings (Off, ..)
1967
1968 elsif not SWE.Used
1969
1970 -- Do not issue this warning for -Wxxx messages since the
1971 -- back-end doesn't report the information. Note that there
1972 -- is always an asterisk at the start of every message.
1973
1974 and then not
1975 (SWE.Msg'Length > 3 and then SWE.Msg (2 .. 3) = "-W")
1976 then
1977 Error_Msg
1978 ("?.w?no warning suppressed by this pragma",
1979 SWE.Start);
1980 end if;
1981 end if;
1982 end;
1983 end loop;
1984 end Validate_Specific_Warnings;
1985
1986 ---------------
1987 -- Last_Node --
1988 ---------------
1989
1990 function Last_Node (C : Node_Id) return Node_Id is
1991 Fst, Lst : Node_Id;
1992 begin
1993 First_And_Last_Nodes (C, Fst, Lst);
1994 return Lst;
1995 end Last_Node;
1996
1997 ---------------
1998 -- Last_Sloc --
1999 ---------------
2000
2001 function Last_Sloc (N : Node_Id) return Source_Ptr is
2002 procedure Skip_Char (S : in out Source_Ptr);
2003 -- Skip one character of the source buffer at location S
2004
2005 ---------------
2006 -- Skip_Char --
2007 ---------------
2008
2009 procedure Skip_Char (S : in out Source_Ptr) is
2010 begin
2011 S := S + 1;
2012 end Skip_Char;
2013
2014 -- Local variables
2015
2016 SI : constant Source_File_Index := Get_Source_File_Index (Sloc (N));
2017 SF : constant Source_Ptr := Source_First (SI);
2018 SL : constant Source_Ptr := Source_Last (SI);
2019 Src : constant Source_Buffer_Ptr := Source_Text (SI);
2020 F : Node_Id;
2021 S : Source_Ptr;
2022
2023 -- Start of processing for Last_Sloc
2024
2025 begin
2026 F := Last_Node (N);
2027 S := Sloc (F);
2028
2029 if S not in SF .. SL then
2030 return S;
2031 end if;
2032
2033 -- For string and character literals simply forward the sloc by their
2034 -- length including the closing quotes. Perhaps we should do something
2035 -- special for multibyte characters, but this code is only used to emit
2036 -- error messages, so it is not worth the effort.
2037
2038 case Nkind (F) is
2039 when N_String_Literal =>
2040 return S + Source_Ptr (String_Length (Strval (F))) + 1;
2041
2042 when N_Character_Literal =>
2043 return S + 2;
2044
2045 -- Skip past integer literals, both decimal and based, integer and
2046 -- real. We can't greedily accept all allowed character, because
2047 -- we would consme too many of them in expressions like "123+ABC"
2048 -- or "123..456", so we follow quite precisely the Ada grammar and
2049 -- consume different characters depending on the context.
2050
2051 when N_Integer_Literal =>
2052
2053 -- Skip past the initial numeral, which either leads the decimal
2054 -- literal or is the base of a based literal.
2055
2056 while S < SL
2057 and then Src (S + 1) in '0' .. '9' | '_'
2058 loop
2059 Skip_Char (S);
2060 end loop;
2061
2062 -- Skip past #based_numeral#, if present
2063
2064 if S < SL
2065 and then Src (S + 1) = '#'
2066 then
2067 Skip_Char (S);
2068
2069 while S < SL
2070 and then
2071 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2072 loop
2073 Skip_Char (S);
2074 end loop;
2075
2076 if S < SL
2077 and then Src (S + 1) = '#'
2078 then
2079 Skip_Char (S);
2080 end if;
2081 end if;
2082
2083 -- Skip past exponent, if present
2084
2085 if S < SL
2086 and then Src (S + 1) in 'e' | 'E'
2087 then
2088 Skip_Char (S);
2089
2090 -- For positive exponents the plus sign is optional, but we
2091 -- can simply skip past both plus and minus.
2092
2093 if S < SL
2094 and then Src (S + 1) in '+' | '-'
2095 then
2096 Skip_Char (S);
2097 end if;
2098
2099 -- Skip past the numeral part
2100
2101 while S < SL
2102 and then Src (S + 1) in '0' .. '9' | '_'
2103 loop
2104 Skip_Char (S);
2105 end loop;
2106 end if;
2107
2108 when N_Real_Literal =>
2109 -- Skip past the initial numeral, which either leads the decimal
2110 -- literal or is the base of a based literal.
2111
2112 while S < SL
2113 and then Src (S + 1) in '0' .. '9' | '_'
2114 loop
2115 Skip_Char (S);
2116 end loop;
2117
2118 if S < SL then
2119
2120 -- Skip the dot and continue with a decimal literal
2121
2122 if Src (S + 1) = '.' then
2123 Skip_Char (S);
2124
2125 while S < SL
2126 and then Src (S + 1) in '0' .. '9' | '_'
2127 loop
2128 Skip_Char (S);
2129 end loop;
2130
2131 -- Skip the hash and continue with a based literal
2132
2133 elsif Src (S + 1) = '#' then
2134 Skip_Char (S);
2135
2136 while S < SL
2137 and then
2138 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2139 loop
2140 Skip_Char (S);
2141 end loop;
2142
2143 if S < SL
2144 and then Src (S + 1) = '.'
2145 then
2146 Skip_Char (S);
2147 end if;
2148
2149 while S < SL
2150 and then
2151 Src (S + 1) in '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' | '_'
2152 loop
2153 Skip_Char (S);
2154 end loop;
2155
2156 if S < SL
2157 and then Src (S + 1) = '#'
2158 then
2159 Skip_Char (S);
2160 end if;
2161 end if;
2162 end if;
2163
2164 -- Skip past exponent, if present
2165
2166 if S < SL
2167 and then Src (S + 1) in 'e' | 'E'
2168 then
2169 Skip_Char (S);
2170 -- For positive exponents the plus sign is optional, but we
2171 -- can simply skip past both plus and minus.
2172
2173 if Src (S + 1) in '+' | '-' then
2174 Skip_Char (S);
2175 end if;
2176
2177 -- Skip past the numeral part
2178
2179 while S < SL
2180 and then Src (S + 1) in '0' .. '9' | '_'
2181 loop
2182 Skip_Char (S);
2183 end loop;
2184 end if;
2185
2186 -- For other nodes simply skip past a keyword/identifier
2187
2188 when others =>
2189 while S in SF .. SL - 1
2190 and then Src (S + 1)
2191 in
2192 '0' .. '9' | 'a' .. 'z' | 'A' .. 'Z' | '_'
2193 loop
2194 Skip_Char (S);
2195 end loop;
2196 end case;
2197
2198 -- The following circuit attempts at crawling up the tree from the
2199 -- Last_Node, adjusting the Sloc value for any parentheses we know
2200 -- are present, similarly to what is done in First_Sloc.
2201
2202 Node_Loop : loop
2203 -- Include parentheses around the top node, except when they are
2204 -- required by the syntax of the parent node.
2205
2206 exit Node_Loop when F = N
2207 and then Paren_Required (N);
2208
2209 Paren_Loop : for J in 1 .. Paren_Count (F) loop
2210
2211 -- We don't look more than 12 characters after the current
2212 -- location
2213
2214 Search_Loop : for K in 1 .. 12 loop
2215 exit Node_Loop when S = SL;
2216
2217 if Src (S + 1) = ')' then
2218 S := S + 1;
2219 exit Search_Loop;
2220
2221 elsif Src (S + 1) <= ' ' then
2222 S := S + 1;
2223
2224 else
2225 exit Search_Loop;
2226 end if;
2227 end loop Search_Loop;
2228 end loop Paren_Loop;
2229
2230 exit Node_Loop when F = N;
2231 F := Parent (F);
2232 exit Node_Loop when Nkind (F) not in N_Subexpr;
2233 end loop Node_Loop;
2234
2235 -- Remove any trailing space
2236
2237 while S in SF + 1 .. SL
2238 and then Src (S) = ' '
2239 loop
2240 S := S - 1;
2241 end loop;
2242
2243 return S;
2244 end Last_Sloc;
2245
2246 -----------------
2247 -- No_Warnings --
2248 -----------------
2249
2250 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
2251 begin
2252 if Error_Posted (N) then
2253 return True;
2254
2255 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
2256 return True;
2257
2258 elsif Is_Entity_Name (N)
2259 and then Present (Entity (N))
2260 and then Has_Warnings_Off (Entity (N))
2261 then
2262 return True;
2263
2264 else
2265 return False;
2266 end if;
2267 end No_Warnings;
2268
2269 -------------
2270 -- OK_Node --
2271 -------------
2272
2273 function OK_Node (N : Node_Id) return Boolean is
2274 K : constant Node_Kind := Nkind (N);
2275
2276 begin
2277 if Error_Posted (N) then
2278 return False;
2279
2280 elsif K in N_Has_Etype
2281 and then Present (Etype (N))
2282 and then Error_Posted (Etype (N))
2283 then
2284 return False;
2285
2286 elsif (K in N_Op
2287 or else K = N_Attribute_Reference
2288 or else K = N_Character_Literal
2289 or else K = N_Expanded_Name
2290 or else K = N_Identifier
2291 or else K = N_Operator_Symbol)
2292 and then Present (Entity (N))
2293 and then Error_Posted (Entity (N))
2294 then
2295 return False;
2296 else
2297 return True;
2298 end if;
2299 end OK_Node;
2300
2301 -------------------------
2302 -- Output_JSON_Message --
2303 -------------------------
2304
2305 procedure Output_JSON_Message (Error_Id : Error_Msg_Id) is
2306
2307 function Is_Continuation (E : Error_Msg_Id) return Boolean;
2308 -- Return True if E is a continuation message.
2309
2310 procedure Write_JSON_Escaped_String (Str : String_Ptr);
2311 procedure Write_JSON_Escaped_String (Str : String);
2312 -- Write each character of Str, taking care of preceding each quote and
2313 -- backslash with a backslash. Note that this escaping differs from what
2314 -- GCC does.
2315 --
2316 -- Indeed, the JSON specification mandates encoding wide characters
2317 -- either as their direct UTF-8 representation or as their escaped
2318 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2319 -- we choose to use the UTF-8 representation instead.
2320
2321 procedure Write_JSON_Location (Sptr : Source_Ptr);
2322 -- Write Sptr as a JSON location, an object containing a file attribute,
2323 -- a line number and a column number.
2324
2325 procedure Write_JSON_Span (Error : Error_Msg_Object);
2326 -- Write Error as a JSON span, an object containing a "caret" attribute
2327 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2328 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2329 -- locations under the names "start" and "finish".
2330
2331 -----------------------
2332 -- Is_Continuation --
2333 -----------------------
2334
2335 function Is_Continuation (E : Error_Msg_Id) return Boolean is
2336 begin
2337 return E <= Last_Error_Msg and then Errors.Table (E).Msg_Cont;
2338 end Is_Continuation;
2339
2340 -------------------------------
2341 -- Write_JSON_Escaped_String --
2342 -------------------------------
2343
2344 procedure Write_JSON_Escaped_String (Str : String) is
2345 begin
2346 for C of Str loop
2347 if C = '"' or else C = '\' then
2348 Write_Char ('\');
2349 end if;
2350
2351 Write_Char (C);
2352 end loop;
2353 end Write_JSON_Escaped_String;
2354
2355 -------------------------------
2356 -- Write_JSON_Escaped_String --
2357 -------------------------------
2358
2359 procedure Write_JSON_Escaped_String (Str : String_Ptr) is
2360 begin
2361 Write_JSON_Escaped_String (Str.all);
2362 end Write_JSON_Escaped_String;
2363
2364 -------------------------
2365 -- Write_JSON_Location --
2366 -------------------------
2367
2368 procedure Write_JSON_Location (Sptr : Source_Ptr) is
2369 Name : constant File_Name_Type :=
2370 Full_Ref_Name (Get_Source_File_Index (Sptr));
2371 begin
2372 Write_Str ("{""file"":""");
2373 if Full_Path_Name_For_Brief_Errors then
2374 Write_JSON_Escaped_String
2375 (System.OS_Lib.Normalize_Pathname
2376 (Get_Name_String (Name), Resolve_Links => False));
2377 else
2378 Write_Name (Name);
2379 end if;
2380 Write_Str (""",""line"":");
2381 Write_Int (Pos (Get_Physical_Line_Number (Sptr)));
2382 Write_Str (", ""column"":");
2383 Write_Int (Nat (Get_Column_Number (Sptr)));
2384 Write_Str ("}");
2385 end Write_JSON_Location;
2386
2387 ---------------------
2388 -- Write_JSON_Span --
2389 ---------------------
2390
2391 procedure Write_JSON_Span (Error : Error_Msg_Object) is
2392 Span : constant Source_Span := Error.Sptr;
2393 begin
2394 Write_Str ("{""caret"":");
2395 Write_JSON_Location (Span.Ptr);
2396
2397 if Span.Ptr /= Span.First then
2398 Write_Str (",""start"":");
2399 Write_JSON_Location (Span.First);
2400 end if;
2401
2402 if Span.Ptr /= Span.Last then
2403 Write_Str (",""finish"":");
2404 Write_JSON_Location (Span.Last);
2405 end if;
2406
2407 Write_Str ("}");
2408 end Write_JSON_Span;
2409
2410 -- Local Variables
2411
2412 E : Error_Msg_Id := Error_Id;
2413
2414 Print_Continuations : constant Boolean := not Is_Continuation (E);
2415 -- Do not print continuations messages as children of the current
2416 -- message if the current message is a continuation message.
2417
2418 Option : constant String := Get_Warning_Option (E);
2419 -- The option that triggered this message.
2420
2421 -- Start of processing for Output_JSON_Message
2422
2423 begin
2424 -- Print message kind
2425
2426 Write_Str ("{""kind"":");
2427
2428 if Errors.Table (E).Kind = Warning and then not Errors.Table (E).Warn_Err
2429 then
2430 Write_Str ("""warning""");
2431 elsif Errors.Table (E).Kind in
2432 Info
2433 | High_Check
2434 | Medium_Check
2435 | Low_Check
2436 then
2437 Write_Str ("""note""");
2438 else
2439 Write_Str ("""error""");
2440 end if;
2441
2442 -- Print message location
2443
2444 Write_Str (",""locations"":[");
2445 Write_JSON_Span (Errors.Table (E));
2446
2447 if Errors.Table (E).Optr.Ptr /= Errors.Table (E).Sptr.Ptr then
2448 Write_Str (",{""caret"":");
2449 Write_JSON_Location (Errors.Table (E).Optr.Ptr);
2450 Write_Str ("}");
2451 end if;
2452
2453 Write_Str ("]");
2454
2455 -- Print message option, if there is one
2456 if Option /= "" then
2457 Write_Str (",""option"":""" & Option & """");
2458 end if;
2459
2460 -- Print message content
2461
2462 Write_Str (",""message"":""");
2463 Write_JSON_Escaped_String (Errors.Table (E).Text);
2464 Write_Str ("""");
2465
2466 E := E + 1;
2467
2468 if Print_Continuations and then Is_Continuation (E) then
2469
2470 Write_Str (",""children"": [");
2471 Output_JSON_Message (E);
2472 E := E + 1;
2473
2474 while Is_Continuation (E) loop
2475 Write_Str (", ");
2476 Output_JSON_Message (E);
2477 E := E + 1;
2478 end loop;
2479
2480 Write_Str ("]");
2481
2482 end if;
2483
2484 Write_Str ("}");
2485 end Output_JSON_Message;
2486
2487 ---------------------
2488 -- Output_Messages --
2489 ---------------------
2490
2491 procedure Output_Messages is
2492
2493 -- Local subprograms
2494
2495 procedure Emit_Error_Msgs;
2496 -- Emit all error messages in the table use the pretty printed format if
2497 -- -gnatdF is used otherwise use the brief format.
2498
2499 procedure Write_Header (Sfile : Source_File_Index);
2500 -- Write header line (compiling or checking given file)
2501
2502 procedure Write_Max_Errors;
2503 -- Write message if max errors reached
2504
2505 procedure Write_Source_Code_Lines
2506 (Span : Source_Span;
2507 SGR_Span : String);
2508 -- Write the source code line corresponding to Span, as follows when
2509 -- Span in on one line:
2510 --
2511 -- line | actual code line here with Span somewhere
2512 -- | ~~~~~^~~~
2513 --
2514 -- where the caret on the line points to location Span.Ptr, and the
2515 -- range Span.First..Span.Last is underlined.
2516 --
2517 -- or when the span is over multiple lines:
2518 --
2519 -- line | beginning of the Span on this line
2520 -- ... | ...
2521 -- line>| actual code line here with Span.Ptr somewhere
2522 -- ... | ...
2523 -- line | end of the Span on this line
2524 --
2525 -- or when the span is a simple location, as follows:
2526 --
2527 -- line | actual code line here with Span somewhere
2528 -- | ^ here
2529 --
2530 -- where the caret on the line points to location Span.Ptr
2531 --
2532 -- SGR_Span is the SGR string to start the section of code in the span,
2533 -- that should be closed with SGR_Reset.
2534
2535 --------------------
2536 -- Emit_Error_Msgs --
2537 ---------------------
2538
2539 procedure Emit_Error_Msgs is
2540 Use_Prefix : Boolean;
2541 E : Error_Msg_Id;
2542 begin
2543 Set_Standard_Error;
2544
2545 E := First_Error_Msg;
2546 while E /= No_Error_Msg loop
2547
2548 -- If -gnatdF is used, separate main messages from previous
2549 -- messages with a newline (unless it is an info message) and
2550 -- make continuation messages follow the main message with only
2551 -- an indentation of two space characters, without repeating
2552 -- file:line:col: prefix.
2553
2554 Use_Prefix :=
2555 not (Debug_Flag_FF and then Errors.Table (E).Msg_Cont);
2556
2557 if not Errors.Table (E).Deleted then
2558
2559 if Debug_Flag_FF then
2560 if Errors.Table (E).Msg_Cont then
2561 Write_Str (" ");
2562 elsif Errors.Table (E).Kind /= Info then
2563 Write_Eol;
2564 end if;
2565 end if;
2566
2567 if Use_Prefix then
2568 Output_Msg_Location (E);
2569 end if;
2570
2571 Output_Msg_Text (E);
2572 Write_Eol;
2573
2574 -- If -gnatdF is used, write the source code line
2575 -- corresponding to the location of the main message (unless
2576 -- it is an info message). Also write the source code line
2577 -- corresponding to an insertion location inside
2578 -- continuation messages.
2579
2580 if Debug_Flag_FF
2581 and then Errors.Table (E).Kind /= Info
2582 then
2583 if Errors.Table (E).Msg_Cont then
2584 declare
2585 Loc : constant Source_Ptr :=
2586 Errors.Table (E).Insertion_Sloc;
2587 begin
2588 if Loc /= No_Location then
2589 Write_Source_Code_Lines
2590 (To_Span (Loc), SGR_Span => SGR_Note);
2591 end if;
2592 end;
2593
2594 else
2595 declare
2596 SGR_Span : constant String :=
2597 (if Errors.Table (E).Kind = Info then SGR_Note
2598 elsif Errors.Table (E).Kind = Warning
2599 and then not Errors.Table (E).Warn_Err
2600 then SGR_Warning
2601 else SGR_Error);
2602 begin
2603 Write_Source_Code_Lines
2604 (Errors.Table (E).Optr, SGR_Span);
2605 end;
2606 end if;
2607 end if;
2608 end if;
2609
2610 E := Errors.Table (E).Next;
2611 end loop;
2612
2613 Set_Standard_Output;
2614 end Emit_Error_Msgs;
2615
2616 ------------------
2617 -- Write_Header --
2618 ------------------
2619
2620 procedure Write_Header (Sfile : Source_File_Index) is
2621 begin
2622 if Verbose_Mode or Full_List then
2623 if Original_Operating_Mode = Generate_Code then
2624 Write_Str ("Compiling: ");
2625 else
2626 Write_Str ("Checking: ");
2627 end if;
2628
2629 Write_Name (Full_File_Name (Sfile));
2630
2631 if not Debug_Flag_7 then
2632 Write_Eol;
2633 Write_Str ("Source file time stamp: ");
2634 Write_Time_Stamp (Sfile);
2635 Write_Eol;
2636 Write_Str ("Compiled at: " & Compilation_Time);
2637 end if;
2638
2639 Write_Eol;
2640 end if;
2641 end Write_Header;
2642
2643 ----------------------
2644 -- Write_Max_Errors --
2645 ----------------------
2646
2647 procedure Write_Max_Errors is
2648 begin
2649 if Maximum_Messages /= 0 then
2650 if Warnings_Detected >= Maximum_Messages then
2651 Set_Standard_Error;
2652 Write_Line ("maximum number of warnings output");
2653 Write_Line ("any further warnings suppressed");
2654 Set_Standard_Output;
2655 end if;
2656
2657 -- If too many errors print message
2658
2659 if Total_Errors_Detected >= Maximum_Messages then
2660 Set_Standard_Error;
2661 Write_Line ("fatal error: maximum number of errors detected");
2662 Set_Standard_Output;
2663 end if;
2664 end if;
2665 end Write_Max_Errors;
2666
2667 -----------------------------
2668 -- Write_Source_Code_Lines --
2669 -----------------------------
2670
2671 procedure Write_Source_Code_Lines
2672 (Span : Source_Span;
2673 SGR_Span : String)
2674 is
2675 function Get_Line_End
2676 (Buf : Source_Buffer_Ptr;
2677 Loc : Source_Ptr) return Source_Ptr;
2678 -- Get the source location for the end of the line in Buf for Loc. If
2679 -- Loc is past the end of Buf already, return Buf'Last.
2680
2681 function Get_Line_Start
2682 (Buf : Source_Buffer_Ptr;
2683 Loc : Source_Ptr) return Source_Ptr;
2684 -- Get the source location for the start of the line in Buf for Loc
2685
2686 function Image (X : Positive; Width : Positive) return String;
2687 -- Output number X over Width characters, with whitespace padding.
2688 -- Only output the low-order Width digits of X, if X is larger than
2689 -- Width digits.
2690
2691 procedure Write_Buffer
2692 (Buf : Source_Buffer_Ptr;
2693 First : Source_Ptr;
2694 Last : Source_Ptr);
2695 -- Output the characters from First to Last position in Buf, using
2696 -- Write_Buffer_Char.
2697
2698 procedure Write_Buffer_Char
2699 (Buf : Source_Buffer_Ptr;
2700 Loc : Source_Ptr);
2701 -- Output the characters at position Loc in Buf, translating ASCII.HT
2702 -- in a suitable number of spaces so that the output is not modified
2703 -- by starting in a different column that 1.
2704
2705 procedure Write_Line_Marker
2706 (Num : Pos;
2707 Mark : Boolean;
2708 Width : Positive);
2709 -- Output the line number Num over Width characters, with possibly
2710 -- a Mark to denote the line with the main location when reporting
2711 -- a span over multiple lines.
2712
2713 ------------------
2714 -- Get_Line_End --
2715 ------------------
2716
2717 function Get_Line_End
2718 (Buf : Source_Buffer_Ptr;
2719 Loc : Source_Ptr) return Source_Ptr
2720 is
2721 Cur_Loc : Source_Ptr := Source_Ptr'Min (Loc, Buf'Last);
2722 begin
2723 while Cur_Loc < Buf'Last
2724 and then Buf (Cur_Loc) /= ASCII.LF
2725 loop
2726 Cur_Loc := Cur_Loc + 1;
2727 end loop;
2728
2729 return Cur_Loc;
2730 end Get_Line_End;
2731
2732 --------------------
2733 -- Get_Line_Start --
2734 --------------------
2735
2736 function Get_Line_Start
2737 (Buf : Source_Buffer_Ptr;
2738 Loc : Source_Ptr) return Source_Ptr
2739 is
2740 Cur_Loc : Source_Ptr := Loc;
2741 begin
2742 while Cur_Loc > Buf'First
2743 and then Buf (Cur_Loc - 1) /= ASCII.LF
2744 loop
2745 Cur_Loc := Cur_Loc - 1;
2746 end loop;
2747
2748 return Cur_Loc;
2749 end Get_Line_Start;
2750
2751 -----------
2752 -- Image --
2753 -----------
2754
2755 function Image (X : Positive; Width : Positive) return String is
2756 Str : String (1 .. Width);
2757 Curr : Natural := X;
2758 begin
2759 for J in reverse 1 .. Width loop
2760 if Curr > 0 then
2761 Str (J) := Character'Val (Character'Pos ('0') + Curr mod 10);
2762 Curr := Curr / 10;
2763 else
2764 Str (J) := ' ';
2765 end if;
2766 end loop;
2767
2768 return Str;
2769 end Image;
2770
2771 ------------------
2772 -- Write_Buffer --
2773 ------------------
2774
2775 procedure Write_Buffer
2776 (Buf : Source_Buffer_Ptr;
2777 First : Source_Ptr;
2778 Last : Source_Ptr)
2779 is
2780 begin
2781 for Loc in First .. Last loop
2782 Write_Buffer_Char (Buf, Loc);
2783 end loop;
2784 end Write_Buffer;
2785
2786 -----------------------
2787 -- Write_Buffer_Char --
2788 -----------------------
2789
2790 procedure Write_Buffer_Char
2791 (Buf : Source_Buffer_Ptr;
2792 Loc : Source_Ptr)
2793 is
2794 begin
2795 -- If the character ASCII.HT is not the last one in the file,
2796 -- output as many spaces as the character represents in the
2797 -- original source file.
2798
2799 if Buf (Loc) = ASCII.HT
2800 and then Loc < Buf'Last
2801 then
2802 for X in Get_Column_Number (Loc) ..
2803 Get_Column_Number (Loc + 1) - 1
2804 loop
2805 Write_Char (' ');
2806 end loop;
2807
2808 -- Otherwise output the character itself
2809
2810 else
2811 Write_Char (Buf (Loc));
2812 end if;
2813 end Write_Buffer_Char;
2814
2815 -----------------------
2816 -- Write_Line_Marker --
2817 -----------------------
2818
2819 procedure Write_Line_Marker
2820 (Num : Pos;
2821 Mark : Boolean;
2822 Width : Positive)
2823 is
2824 begin
2825 Write_Str (Image (Positive (Num), Width => Width));
2826 Write_Str ((if Mark then ">" else " ") & "|");
2827 end Write_Line_Marker;
2828
2829 -- Local variables
2830
2831 Loc : constant Source_Ptr := Span.Ptr;
2832 Line : constant Pos := Pos (Get_Physical_Line_Number (Loc));
2833
2834 Col : constant Natural := Natural (Get_Column_Number (Loc));
2835
2836 Fst : constant Source_Ptr := Span.First;
2837 Line_Fst : constant Pos :=
2838 Pos (Get_Physical_Line_Number (Fst));
2839 Col_Fst : constant Natural :=
2840 Natural (Get_Column_Number (Fst));
2841 Lst : constant Source_Ptr := Span.Last;
2842 Line_Lst : constant Pos :=
2843 Pos (Get_Physical_Line_Number (Lst));
2844 Col_Lst : constant Natural :=
2845 Natural (Get_Column_Number (Lst));
2846
2847 Width : constant := 5;
2848 Buf : Source_Buffer_Ptr;
2849 Cur_Loc : Source_Ptr := Fst;
2850 Cur_Line : Pos := Line_Fst;
2851
2852 -- Start of processing for Write_Source_Code_Lines
2853
2854 begin
2855 if Loc >= First_Source_Ptr then
2856 Buf := Source_Text (Get_Source_File_Index (Loc));
2857
2858 -- First line of the span with actual source code. We retrieve
2859 -- the beginning of the line instead of relying on Col_Fst, as
2860 -- ASCII.HT characters change column numbers by possibly more
2861 -- than one.
2862
2863 Write_Line_Marker
2864 (Cur_Line,
2865 Line_Fst /= Line_Lst and then Cur_Line = Line,
2866 Width);
2867 Write_Buffer (Buf, Get_Line_Start (Buf, Cur_Loc), Cur_Loc - 1);
2868
2869 -- Output the first/caret/last lines of the span, as well as
2870 -- lines that are directly above/below the caret if they complete
2871 -- the gap with first/last lines, otherwise use ... to denote
2872 -- intermediate lines.
2873
2874 -- If the span is on one line and not a simple source location,
2875 -- color it appropriately.
2876
2877 if Line_Fst = Line_Lst
2878 and then Col_Fst /= Col_Lst
2879 then
2880 Write_Str (SGR_Span);
2881 end if;
2882
2883 declare
2884 function Do_Write_Line (Cur_Line : Pos) return Boolean is
2885 (Cur_Line in Line_Fst | Line | Line_Lst
2886 or else
2887 (Cur_Line = Line_Fst + 1 and then Cur_Line = Line - 1)
2888 or else
2889 (Cur_Line = Line + 1 and then Cur_Line = Line_Lst - 1));
2890 begin
2891 while Cur_Loc <= Buf'Last
2892 and then Cur_Loc <= Lst
2893 loop
2894 if Do_Write_Line (Cur_Line) then
2895 Write_Buffer_Char (Buf, Cur_Loc);
2896 end if;
2897
2898 if Buf (Cur_Loc) = ASCII.LF then
2899 Cur_Line := Cur_Line + 1;
2900
2901 -- Output ... for skipped lines
2902
2903 if (Cur_Line = Line
2904 and then not Do_Write_Line (Cur_Line - 1))
2905 or else
2906 (Cur_Line = Line + 1
2907 and then not Do_Write_Line (Cur_Line))
2908 then
2909 Write_Str ((1 .. Width - 3 => ' ') & "... | ...");
2910 Write_Eol;
2911 end if;
2912
2913 -- Display the line marker if the line should be
2914 -- displayed.
2915
2916 if Do_Write_Line (Cur_Line) then
2917 Write_Line_Marker
2918 (Cur_Line,
2919 Line_Fst /= Line_Lst and then Cur_Line = Line,
2920 Width);
2921 end if;
2922 end if;
2923
2924 Cur_Loc := Cur_Loc + 1;
2925 end loop;
2926 end;
2927
2928 if Line_Fst = Line_Lst
2929 and then Col_Fst /= Col_Lst
2930 then
2931 Write_Str (SGR_Reset);
2932 end if;
2933
2934 -- Output the rest of the last line of the span
2935
2936 Write_Buffer (Buf, Cur_Loc, Get_Line_End (Buf, Cur_Loc));
2937
2938 -- If the span is on one line, output a second line with caret
2939 -- sign pointing to location Loc
2940
2941 if Line_Fst = Line_Lst then
2942 Write_Str (String'(1 .. Width => ' '));
2943 Write_Str (" |");
2944 Write_Str (String'(1 .. Col_Fst - 1 => ' '));
2945
2946 Write_Str (SGR_Span);
2947
2948 Write_Str (String'(Col_Fst .. Col - 1 => '~'));
2949 Write_Str ("^");
2950 Write_Str (String'(Col + 1 .. Col_Lst => '~'));
2951
2952 -- If the span is really just a location, add the word "here"
2953 -- to clarify this is the location for the message.
2954
2955 if Col_Fst = Col_Lst then
2956 Write_Str (" here");
2957 end if;
2958
2959 Write_Str (SGR_Reset);
2960
2961 Write_Eol;
2962 end if;
2963 end if;
2964 end Write_Source_Code_Lines;
2965
2966 -- Local variables
2967
2968 E : Error_Msg_Id;
2969 Err_Flag : Boolean;
2970
2971 -- Start of processing for Output_Messages
2972
2973 begin
2974 -- Error if Finalize has not been called
2975
2976 if not Finalize_Called then
2977 raise Program_Error;
2978 end if;
2979
2980 -- Reset current error source file if the main unit has a pragma
2981 -- Source_Reference. This ensures outputting the proper name of
2982 -- the source file in this situation.
2983
2984 if Main_Source_File <= No_Source_File
2985 or else Num_SRef_Pragmas (Main_Source_File) /= 0
2986 then
2987 Current_Error_Source_File := No_Source_File;
2988 end if;
2989
2990 if Opt.JSON_Output then
2991 Set_Standard_Error;
2992
2993 E := First_Error_Msg;
2994
2995 -- Find first printable message
2996
2997 while E /= No_Error_Msg and then Errors.Table (E).Deleted loop
2998 E := Errors.Table (E).Next;
2999 end loop;
3000
3001 Write_Char ('[');
3002
3003 if E /= No_Error_Msg then
3004
3005 Output_JSON_Message (E);
3006
3007 E := Errors.Table (E).Next;
3008
3009 while E /= No_Error_Msg loop
3010
3011 -- Skip deleted messages.
3012 -- Also skip continuation messages, as they have already been
3013 -- printed along the message they're attached to.
3014
3015 if not Errors.Table (E).Deleted
3016 and then not Errors.Table (E).Msg_Cont
3017 then
3018 Write_Char (',');
3019 Output_JSON_Message (E);
3020 end if;
3021
3022 E := Errors.Table (E).Next;
3023 end loop;
3024 end if;
3025
3026 Write_Char (']');
3027
3028 Set_Standard_Output;
3029
3030 -- Do not print any messages if all messages are killed -gnatdK
3031
3032 elsif Debug_Flag_KK then
3033
3034 null;
3035
3036 -- Brief Error mode
3037
3038 elsif Brief_Output or (not Full_List and not Verbose_Mode) then
3039
3040 -- Use updated diagnostic mechanism
3041
3042 if Debug_Flag_Underscore_DD then
3043 Convert_Errors_To_Diagnostics;
3044
3045 Emit_Diagnostics;
3046 else
3047 Emit_Error_Msgs;
3048 end if;
3049 end if;
3050
3051 -- Full source listing case
3052
3053 if Full_List then
3054 List_Pragmas_Index := 1;
3055 List_Pragmas_Mode := True;
3056 E := First_Error_Msg;
3057
3058 -- Normal case, to stdout (copyright notice already output)
3059
3060 if Full_List_File_Name = null then
3061 if not Debug_Flag_7 then
3062 Write_Eol;
3063 end if;
3064
3065 -- Output to file
3066
3067 else
3068 Create_List_File_Access.all (Full_List_File_Name.all);
3069 Set_Special_Output (Write_List_Info_Access.all'Access);
3070
3071 -- Write copyright notice to file
3072
3073 if not Debug_Flag_7 then
3074 Write_Str ("GNAT ");
3075 Write_Str (Gnat_Version_String);
3076 Write_Eol;
3077 Write_Str ("Copyright 1992-" &
3078 Current_Year &
3079 ", Free Software Foundation, Inc.");
3080 Write_Eol;
3081 end if;
3082 end if;
3083
3084 -- First list extended main source file units with errors
3085
3086 for U in Main_Unit .. Last_Unit loop
3087 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
3088
3089 -- If debug flag d.m is set, only the main source is listed
3090
3091 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
3092
3093 -- If the unit of the entity does not come from source, it is
3094 -- an implicit subprogram declaration for a child subprogram.
3095 -- Do not emit errors for it, they are listed with the body.
3096
3097 and then
3098 (No (Cunit_Entity (U))
3099 or else Comes_From_Source (Cunit_Entity (U))
3100 or else not Is_Subprogram (Cunit_Entity (U)))
3101
3102 -- If the compilation unit associated with this unit does not
3103 -- come from source, it means it is an instantiation that should
3104 -- not be included in the source listing.
3105
3106 and then Comes_From_Source (Cunit (U))
3107 then
3108 declare
3109 Sfile : constant Source_File_Index := Source_Index (U);
3110
3111 begin
3112 Write_Eol;
3113
3114 -- Only write the header if Sfile is known
3115
3116 if Sfile > No_Source_File then
3117 Write_Header (Sfile);
3118 Write_Eol;
3119 end if;
3120
3121 -- Normally, we don't want an "error messages from file"
3122 -- message when listing the entire file, so we set the
3123 -- current source file as the current error source file.
3124 -- However, the old style of doing things was to list this
3125 -- message if pragma Source_Reference is present, even for
3126 -- the main unit. Since the purpose of the -gnatd.m switch
3127 -- is to duplicate the old behavior, we skip the reset if
3128 -- this debug flag is set.
3129
3130 if not Debug_Flag_Dot_M then
3131 Current_Error_Source_File := Sfile;
3132 end if;
3133
3134 -- Only output the listing if Sfile is known, to avoid
3135 -- crashing the compiler.
3136
3137 if Sfile > No_Source_File then
3138 for N in 1 .. Last_Source_Line (Sfile) loop
3139 while E /= No_Error_Msg
3140 and then Errors.Table (E).Deleted
3141 loop
3142 E := Errors.Table (E).Next;
3143 end loop;
3144
3145 Err_Flag :=
3146 E /= No_Error_Msg
3147 and then Errors.Table (E).Line = N
3148 and then Errors.Table (E).Sfile = Sfile;
3149
3150 Output_Source_Line (N, Sfile, Err_Flag);
3151
3152 if Err_Flag then
3153 Output_Error_Msgs (E);
3154
3155 if not Debug_Flag_2 then
3156 Write_Eol;
3157 end if;
3158 end if;
3159 end loop;
3160 end if;
3161 end;
3162 end if;
3163 end loop;
3164
3165 -- Then output errors, if any, for subsidiary units not in the
3166 -- main extended unit.
3167
3168 -- Note: if debug flag d.m set, include errors for any units other
3169 -- than the main unit in the extended source unit (e.g. spec and
3170 -- subunits for a body).
3171
3172 while E /= No_Error_Msg
3173 and then (not In_Extended_Main_Source_Unit
3174 (Errors.Table (E).Sptr.Ptr)
3175 or else
3176 (Debug_Flag_Dot_M
3177 and then Get_Source_Unit
3178 (Errors.Table (E).Sptr.Ptr) /= Main_Unit))
3179 loop
3180 if Errors.Table (E).Deleted then
3181 E := Errors.Table (E).Next;
3182
3183 else
3184 Write_Eol;
3185 Output_Source_Line
3186 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3187 Output_Error_Msgs (E);
3188 end if;
3189 end loop;
3190
3191 -- If output to file, write extra copy of error summary to the
3192 -- output file, and then close it.
3193
3194 if Full_List_File_Name /= null then
3195 Write_Error_Summary;
3196 Write_Max_Errors;
3197 Close_List_File_Access.all;
3198 Cancel_Special_Output;
3199 end if;
3200 end if;
3201
3202 -- Verbose mode (error lines only with error flags). Normally this is
3203 -- ignored in full list mode, unless we are listing to a file, in which
3204 -- case we still generate -gnatv output to standard output.
3205
3206 if Verbose_Mode
3207 and then (not Full_List or else Full_List_File_Name /= null)
3208 then
3209 Write_Eol;
3210
3211 -- Output the header only when Main_Source_File is known
3212
3213 if Main_Source_File > No_Source_File then
3214 Write_Header (Main_Source_File);
3215 end if;
3216
3217 E := First_Error_Msg;
3218
3219 -- Loop through error lines
3220
3221 while E /= No_Error_Msg loop
3222 if Errors.Table (E).Deleted then
3223 E := Errors.Table (E).Next;
3224 else
3225 Write_Eol;
3226 Output_Source_Line
3227 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
3228 Output_Error_Msgs (E);
3229 end if;
3230 end loop;
3231 end if;
3232
3233 -- Output error summary if verbose or full list mode
3234
3235 if Verbose_Mode or else Full_List then
3236 Write_Error_Summary;
3237 end if;
3238
3239 if not Opt.JSON_Output then
3240 Write_Max_Errors;
3241 end if;
3242
3243 if Warning_Mode = Treat_As_Error then
3244 declare
3245 Compile_Time_Pragma_Warnings : constant Nat :=
3246 Count_Compile_Time_Pragma_Warnings;
3247 Total : constant Int := Total_Errors_Detected + Warnings_Detected
3248 - Compile_Time_Pragma_Warnings;
3249 -- We need to protect against a negative Total here, because
3250 -- if a pragma Compile_Time_Warning occurs in dead code, it
3251 -- gets counted in Compile_Time_Pragma_Warnings but not in
3252 -- Warnings_Detected.
3253 begin
3254 Total_Errors_Detected := Int'Max (Total, 0);
3255 Warnings_Detected := Compile_Time_Pragma_Warnings;
3256 end;
3257 end if;
3258 end Output_Messages;
3259
3260 ------------------------
3261 -- Output_Source_Line --
3262 ------------------------
3263
3264 procedure Output_Source_Line
3265 (L : Physical_Line_Number;
3266 Sfile : Source_File_Index;
3267 Errs : Boolean)
3268 is
3269 S : Source_Ptr;
3270 C : Character;
3271
3272 Line_Number_Output : Boolean := False;
3273 -- Set True once line number is output
3274
3275 Empty_Line : Boolean := True;
3276 -- Set False if line includes at least one character
3277
3278 begin
3279 if Sfile /= Current_Error_Source_File then
3280 Write_Str ("==============Error messages for ");
3281
3282 case Sinput.File_Type (Sfile) is
3283 when Sinput.Src =>
3284 Write_Str ("source");
3285
3286 when Sinput.Config =>
3287 Write_Str ("configuration pragmas");
3288
3289 when Sinput.Def =>
3290 Write_Str ("symbol definition");
3291
3292 when Sinput.Preproc =>
3293 Write_Str ("preprocessing data");
3294 end case;
3295
3296 Write_Str (" file: ");
3297 Write_Name (Full_File_Name (Sfile));
3298 Write_Eol;
3299
3300 if Num_SRef_Pragmas (Sfile) > 0 then
3301 Write_Str ("--------------Line numbers from file: ");
3302 Write_Name (Full_Ref_Name (Sfile));
3303 Write_Str (" (starting at line ");
3304 Write_Int (Int (First_Mapped_Line (Sfile)));
3305 Write_Char (')');
3306 Write_Eol;
3307 end if;
3308
3309 Current_Error_Source_File := Sfile;
3310 end if;
3311
3312 if Errs or List_Pragmas_Mode then
3313 Output_Line_Number (Physical_To_Logical (L, Sfile));
3314 Line_Number_Output := True;
3315 end if;
3316
3317 S := Line_Start (L, Sfile);
3318
3319 loop
3320 C := Source_Text (Sfile) (S);
3321 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
3322
3323 -- Deal with matching entry in List_Pragmas table
3324
3325 if Full_List
3326 and then List_Pragmas_Index in
3327 List_Pragmas.First .. List_Pragmas.Last
3328 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
3329 then
3330 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
3331 when Page =>
3332 Write_Char (C);
3333
3334 -- Ignore if on line with errors so that error flags
3335 -- get properly listed with the error line .
3336
3337 if not Errs then
3338 Write_Char (ASCII.FF);
3339 end if;
3340
3341 when List_On =>
3342 List_Pragmas_Mode := True;
3343
3344 if not Line_Number_Output then
3345 Output_Line_Number (Physical_To_Logical (L, Sfile));
3346 Line_Number_Output := True;
3347 end if;
3348
3349 Write_Char (C);
3350
3351 when List_Off =>
3352 Write_Char (C);
3353 List_Pragmas_Mode := False;
3354 end case;
3355
3356 List_Pragmas_Index := List_Pragmas_Index + 1;
3357
3358 -- Normal case (no matching entry in List_Pragmas table)
3359
3360 else
3361 if Errs or List_Pragmas_Mode then
3362 Write_Char (C);
3363 end if;
3364 end if;
3365
3366 Empty_Line := False;
3367 S := S + 1;
3368 end loop;
3369
3370 -- If we have output a source line, then add the line terminator, with
3371 -- training spaces preserved (so we output the line exactly as input).
3372
3373 if Line_Number_Output then
3374 if Empty_Line then
3375 Write_Eol;
3376 else
3377 Write_Eol_Keep_Blanks;
3378 end if;
3379 end if;
3380 end Output_Source_Line;
3381
3382 --------------------
3383 -- Paren_Required --
3384 --------------------
3385
3386 function Paren_Required (N : Node_Id) return Boolean is
3387 begin
3388 -- In a qualifed_expression the expression part needs to be enclosed in
3389 -- parentheses.
3390
3391 if Nkind (Parent (N)) = N_Qualified_Expression then
3392 return N = Expression (Parent (N));
3393
3394 else
3395 return False;
3396 end if;
3397 end Paren_Required;
3398
3399 -----------------------------
3400 -- Remove_Warning_Messages --
3401 -----------------------------
3402
3403 procedure Remove_Warning_Messages (N : Node_Id) is
3404
3405 function Check_For_Warning (N : Node_Id) return Traverse_Result;
3406 -- This function checks one node for a possible warning message
3407
3408 procedure Check_All_Warnings is new Traverse_Proc (Check_For_Warning);
3409 -- This defines the traversal operation
3410
3411 -----------------------
3412 -- Check_For_Warning --
3413 -----------------------
3414
3415 function Check_For_Warning (N : Node_Id) return Traverse_Result is
3416 Loc : constant Source_Ptr := Sloc (N);
3417 E : Error_Msg_Id;
3418
3419 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
3420 -- Returns True for a message that is to be removed. Also adjusts
3421 -- warning count appropriately.
3422
3423 -------------------
3424 -- To_Be_Removed --
3425 -------------------
3426
3427 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
3428 begin
3429 if E /= No_Error_Msg
3430
3431 -- Don't remove if location does not match
3432
3433 and then Errors.Table (E).Optr.Ptr = Loc
3434
3435 -- Don't remove if not warning/info message. Note that we do
3436 -- not remove style messages here. They are warning messages
3437 -- but not ones we want removed in this context.
3438
3439 and then Errors.Table (E).Kind = Warning
3440
3441 -- Don't remove unconditional messages
3442
3443 and then not Errors.Table (E).Uncond
3444 then
3445 Warnings_Detected := Warnings_Detected - 1;
3446
3447 return True;
3448
3449 -- No removal required
3450
3451 else
3452 return False;
3453 end if;
3454 end To_Be_Removed;
3455
3456 -- Start of processing for Check_For_Warnings
3457
3458 begin
3459 while To_Be_Removed (First_Error_Msg) loop
3460 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
3461 end loop;
3462
3463 if First_Error_Msg = No_Error_Msg then
3464 Last_Error_Msg := No_Error_Msg;
3465 end if;
3466
3467 E := First_Error_Msg;
3468 while E /= No_Error_Msg loop
3469 while To_Be_Removed (Errors.Table (E).Next) loop
3470 Errors.Table (E).Next :=
3471 Errors.Table (Errors.Table (E).Next).Next;
3472
3473 if Errors.Table (E).Next = No_Error_Msg then
3474 Last_Error_Msg := E;
3475 end if;
3476 end loop;
3477
3478 E := Errors.Table (E).Next;
3479 end loop;
3480
3481 -- Warnings may have been posted on subexpressions of original tree
3482
3483 if Nkind (N) = N_Raise_Constraint_Error
3484 and then Is_Rewrite_Substitution (N)
3485 and then No (Condition (N))
3486 then
3487 Check_All_Warnings (Original_Node (N));
3488 end if;
3489
3490 return OK;
3491 end Check_For_Warning;
3492
3493 -- Start of processing for Remove_Warning_Messages
3494
3495 begin
3496 if Warnings_Detected /= 0 then
3497 Check_All_Warnings (N);
3498 end if;
3499 end Remove_Warning_Messages;
3500
3501 procedure Remove_Warning_Messages (L : List_Id) is
3502 Stat : Node_Id;
3503 begin
3504 Stat := First (L);
3505 while Present (Stat) loop
3506 Remove_Warning_Messages (Stat);
3507 Next (Stat);
3508 end loop;
3509 end Remove_Warning_Messages;
3510
3511 ----------------------
3512 -- Adjust_Name_Case --
3513 ----------------------
3514
3515 procedure Adjust_Name_Case
3516 (Buf : in out Bounded_String;
3517 Loc : Source_Ptr)
3518 is
3519 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
3520 Sbuffer : Source_Buffer_Ptr;
3521 Ref_Ptr : Integer;
3522 Src_Ptr : Source_Ptr;
3523
3524 begin
3525 -- We have an all lower case name from Namet, and now we want to set
3526 -- the appropriate case. If possible we copy the actual casing from
3527 -- the source. If not we use standard identifier casing.
3528
3529 Ref_Ptr := 1;
3530 Src_Ptr := Loc;
3531
3532 -- For standard locations, always use mixed case
3533
3534 if Loc <= No_Location then
3535 Set_Casing (Buf, Mixed_Case);
3536
3537 else
3538 -- Determine if the reference we are dealing with corresponds to text
3539 -- at the point of the error reference. This will often be the case
3540 -- for simple identifier references, and is the case where we can
3541 -- copy the casing from the source.
3542
3543 Sbuffer := Source_Text (Src_Ind);
3544
3545 while Ref_Ptr <= Buf.Length loop
3546 exit when
3547 Fold_Lower (Sbuffer (Src_Ptr)) /=
3548 Fold_Lower (Buf.Chars (Ref_Ptr));
3549 Ref_Ptr := Ref_Ptr + 1;
3550 Src_Ptr := Src_Ptr + 1;
3551 end loop;
3552
3553 -- If we get through the loop without a mismatch, then output the
3554 -- name the way it is cased in the source program.
3555
3556 if Ref_Ptr > Buf.Length then
3557 Src_Ptr := Loc;
3558
3559 for J in 1 .. Buf.Length loop
3560 Buf.Chars (J) := Sbuffer (Src_Ptr);
3561 Src_Ptr := Src_Ptr + 1;
3562 end loop;
3563
3564 -- Otherwise set the casing using the default identifier casing
3565
3566 else
3567 Set_Casing (Buf, Identifier_Casing (Src_Ind));
3568 end if;
3569 end if;
3570 end Adjust_Name_Case;
3571
3572 ---------------------------
3573 -- Set_Identifier_Casing --
3574 ---------------------------
3575
3576 procedure Set_Identifier_Casing
3577 (Identifier_Name : System.Address;
3578 File_Name : System.Address)
3579 is
3580 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
3581 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
3582 Flen : Natural;
3583
3584 Desired_Case : Casing_Type := Mixed_Case;
3585 -- Casing required for result. Default value of Mixed_Case is used if
3586 -- for some reason we cannot find the right file name in the table.
3587
3588 begin
3589 -- Get length of file name
3590
3591 Flen := 0;
3592 while File (Flen + 1) /= ASCII.NUL loop
3593 Flen := Flen + 1;
3594 end loop;
3595
3596 -- Loop through file names to find matching one. This is a bit slow, but
3597 -- we only do it in error situations so it is not so terrible. Note that
3598 -- if the loop does not exit, then the desired case will be left set to
3599 -- Mixed_Case, this can happen if the name was not in canonical form.
3600
3601 for J in 1 .. Last_Source_File loop
3602 Get_Name_String (Full_Debug_Name (J));
3603
3604 if Name_Len = Flen
3605 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
3606 then
3607 Desired_Case := Identifier_Casing (J);
3608 exit;
3609 end if;
3610 end loop;
3611
3612 -- Copy identifier as given to Name_Buffer
3613
3614 for J in Name_Buffer'Range loop
3615 Name_Buffer (J) := Ident (J);
3616
3617 if Name_Buffer (J) = ASCII.NUL then
3618 Name_Len := J - 1;
3619 exit;
3620 end if;
3621 end loop;
3622
3623 Set_Casing (Desired_Case);
3624 end Set_Identifier_Casing;
3625
3626 -----------------------
3627 -- Set_Ignore_Errors --
3628 -----------------------
3629
3630 procedure Set_Ignore_Errors (To : Boolean) is
3631 begin
3632 Errors_Must_Be_Ignored := To;
3633 end Set_Ignore_Errors;
3634
3635 ----------------------------
3636 -- Set_Msg_Insertion_Node --
3637 ----------------------------
3638
3639 procedure Set_Msg_Insertion_Node is
3640 pragma Assert (Present (Error_Msg_Node_1));
3641 K : Node_Kind;
3642
3643 begin
3644 Suppress_Message := Error_Msg_Node_1 in Types.Error | Any_Type;
3645
3646 if Error_Msg_Node_1 = Types.Error then
3647 Set_Msg_Blank;
3648 Set_Msg_Str ("<error>");
3649
3650 elsif Error_Msg_Node_1 = Standard_Void_Type then
3651 Set_Msg_Blank;
3652 Set_Msg_Str ("procedure name");
3653
3654 elsif Nkind (Error_Msg_Node_1) in N_Entity
3655 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
3656 then
3657 Set_Msg_Blank;
3658 Set_Msg_Str ("access to subprogram");
3659
3660 else
3661 Set_Msg_Blank_Conditional;
3662
3663 -- Output name
3664
3665 K := Nkind (Error_Msg_Node_1);
3666
3667 -- Skip quotes in the operator case, because the operator will supply
3668 -- the required quotes.
3669
3670 if K in N_Op | N_Operator_Symbol | N_Defining_Operator_Symbol
3671 or else (K in N_Identifier | N_Defining_Identifier
3672 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
3673 then
3674 Set_Msg_Node (Error_Msg_Node_1);
3675
3676 -- Normal case, not an operator, surround with quotes
3677
3678 else
3679 Set_Msg_Quote;
3680 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
3681 Set_Msg_Node (Error_Msg_Node_1);
3682 Set_Msg_Quote;
3683 end if;
3684 end if;
3685
3686 -- The following assignment ensures that further ampersand insertion
3687 -- characters will correspond to the Error_Msg_Node_# parameter.
3688
3689 Error_Msg_Node_1 := Error_Msg_Node_2;
3690 Error_Msg_Node_2 := Error_Msg_Node_3;
3691 Error_Msg_Node_3 := Error_Msg_Node_4;
3692 Error_Msg_Node_4 := Error_Msg_Node_5;
3693 Error_Msg_Node_5 := Error_Msg_Node_6;
3694 end Set_Msg_Insertion_Node;
3695
3696 --------------------------------------
3697 -- Set_Msg_Insertion_Type_Reference --
3698 --------------------------------------
3699
3700 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
3701 Ent : Entity_Id;
3702
3703 begin
3704 Set_Msg_Blank;
3705
3706 if Error_Msg_Node_1 = Standard_Void_Type then
3707 Set_Msg_Str ("package or procedure name");
3708 return;
3709
3710 elsif Error_Msg_Node_1 = Standard_Exception_Type then
3711 Set_Msg_Str ("exception name");
3712 return;
3713
3714 elsif Error_Msg_Node_1 = Any_Array
3715 or else Error_Msg_Node_1 = Any_Boolean
3716 or else Error_Msg_Node_1 = Any_Character
3717 or else Error_Msg_Node_1 = Any_Composite
3718 or else Error_Msg_Node_1 = Any_Discrete
3719 or else Error_Msg_Node_1 = Any_Fixed
3720 or else Error_Msg_Node_1 = Any_Integer
3721 or else Error_Msg_Node_1 = Any_Modular
3722 or else Error_Msg_Node_1 = Any_Numeric
3723 or else Error_Msg_Node_1 = Any_Real
3724 or else Error_Msg_Node_1 = Any_Scalar
3725 or else Error_Msg_Node_1 = Any_String
3726 then
3727 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
3728 Set_Msg_Name_Buffer;
3729 return;
3730
3731 elsif Error_Msg_Node_1 = Universal_Integer then
3732 Set_Msg_Str ("type universal integer");
3733 return;
3734
3735 elsif Error_Msg_Node_1 = Universal_Real then
3736 Set_Msg_Str ("type universal real");
3737 return;
3738
3739 elsif Error_Msg_Node_1 = Universal_Fixed then
3740 Set_Msg_Str ("type universal fixed");
3741 return;
3742
3743 elsif Error_Msg_Node_1 = Universal_Access then
3744 Set_Msg_Str ("type universal access");
3745 return;
3746 end if;
3747
3748 -- Special case of anonymous array
3749
3750 if Nkind (Error_Msg_Node_1) in N_Entity
3751 and then Is_Array_Type (Error_Msg_Node_1)
3752 and then Present (Related_Array_Object (Error_Msg_Node_1))
3753 then
3754 Set_Msg_Str ("type of ");
3755 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
3756 Set_Msg_Str (" declared");
3757 Set_Msg_Insertion_Line_Number
3758 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
3759 return;
3760 end if;
3761
3762 -- If we fall through, it is not a special case, so first output
3763 -- the name of the type, preceded by private for a private type
3764
3765 if Is_Private_Type (Error_Msg_Node_1) then
3766 Set_Msg_Str ("private type ");
3767 else
3768 Set_Msg_Str ("type ");
3769 end if;
3770
3771 Ent := Error_Msg_Node_1;
3772
3773 if Is_Internal_Name (Chars (Ent)) then
3774 Unwind_Internal_Type (Ent);
3775 end if;
3776
3777 -- Types in Standard are displayed as "Standard.name"
3778
3779 if Sloc (Ent) <= Standard_Location then
3780 Set_Msg_Quote;
3781 Set_Msg_Str ("Standard.");
3782 Set_Msg_Node (Ent);
3783 Add_Class;
3784 Set_Msg_Quote;
3785
3786 -- Types in other language defined units are displayed as
3787 -- "package-name.type-name"
3788
3789 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
3790 Get_Unqualified_Decoded_Name_String
3791 (Unit_Name (Get_Source_Unit (Ent)));
3792 Name_Len := Name_Len - 2;
3793 Set_Msg_Blank_Conditional;
3794 Set_Msg_Quote;
3795 Set_Casing (Mixed_Case);
3796 Set_Msg_Name_Buffer;
3797 Set_Msg_Char ('.');
3798 Set_Casing (Mixed_Case);
3799 Set_Msg_Node (Ent);
3800 Add_Class;
3801 Set_Msg_Quote;
3802
3803 -- All other types display as "type name" defined at line xxx
3804 -- possibly qualified if qualification is requested.
3805
3806 else
3807 Set_Msg_Quote;
3808 Set_Qualification (Error_Msg_Qual_Level, Ent);
3809 Set_Msg_Node (Ent);
3810 Add_Class;
3811
3812 -- If we did not print a name (e.g. in the case of an anonymous
3813 -- subprogram type), there is no name to print, so remove quotes.
3814
3815 if Buffer_Ends_With ('"') then
3816 Buffer_Remove ('"');
3817 else
3818 Set_Msg_Quote;
3819 end if;
3820 end if;
3821
3822 -- If the original type did not come from a predefined file, add the
3823 -- location where the type was defined.
3824
3825 if Sloc (Error_Msg_Node_1) > Standard_Location
3826 and then
3827 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
3828 then
3829 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
3830 Set_Msg_Str (" defined");
3831 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
3832
3833 -- If it did come from a predefined file, deal with the case where
3834 -- this was a file with a generic instantiation from elsewhere.
3835
3836 else
3837 if Sloc (Error_Msg_Node_1) > Standard_Location then
3838 declare
3839 Iloc : constant Source_Ptr :=
3840 Instantiation_Location (Sloc (Error_Msg_Node_1));
3841
3842 begin
3843 if Iloc /= No_Location
3844 and then not Suppress_Instance_Location
3845 then
3846 Set_Msg_Str (" from instance");
3847 Set_Msg_Insertion_Line_Number (Iloc, Flag);
3848 end if;
3849 end;
3850 end if;
3851 end if;
3852 end Set_Msg_Insertion_Type_Reference;
3853
3854 ---------------------------------
3855 -- Set_Msg_Insertion_Unit_Name --
3856 ---------------------------------
3857
3858 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
3859 begin
3860 if Error_Msg_Unit_1 = No_Unit_Name then
3861 null;
3862
3863 elsif Error_Msg_Unit_1 = Error_Unit_Name then
3864 Set_Msg_Blank;
3865 Set_Msg_Str ("<error>");
3866
3867 else
3868 Get_Unit_Name_String (Global_Name_Buffer, Error_Msg_Unit_1, Suffix);
3869 Set_Msg_Blank;
3870 Set_Msg_Quote;
3871 Set_Msg_Name_Buffer;
3872 Set_Msg_Quote;
3873 end if;
3874
3875 -- The following assignment ensures that a second percent insertion
3876 -- character will correspond to the Error_Msg_Unit_2 parameter.
3877
3878 Error_Msg_Unit_1 := Error_Msg_Unit_2;
3879 end Set_Msg_Insertion_Unit_Name;
3880
3881 ------------------
3882 -- Set_Msg_Node --
3883 ------------------
3884
3885 procedure Set_Msg_Node (Node : Node_Id) is
3886 Loc : Source_Ptr;
3887 Ent : Entity_Id;
3888 Nam : Name_Id;
3889
3890 begin
3891 case Nkind (Node) is
3892 when N_Designator =>
3893 Set_Msg_Node (Name (Node));
3894 Set_Msg_Char ('.');
3895 Set_Msg_Node (Identifier (Node));
3896 return;
3897
3898 when N_Defining_Program_Unit_Name =>
3899 Set_Msg_Node (Name (Node));
3900 Set_Msg_Char ('.');
3901 Set_Msg_Node (Defining_Identifier (Node));
3902 return;
3903
3904 when N_Expanded_Name
3905 | N_Selected_Component
3906 =>
3907 Set_Msg_Node (Prefix (Node));
3908 Set_Msg_Char ('.');
3909 Set_Msg_Node (Selector_Name (Node));
3910 return;
3911
3912 when others =>
3913 null;
3914 end case;
3915
3916 -- The only remaining possibilities are identifiers, defining
3917 -- identifiers, pragmas, and pragma argument associations.
3918
3919 if Nkind (Node) = N_Pragma then
3920 Nam := Pragma_Name (Node);
3921 Loc := Sloc (Node);
3922
3923 -- The other cases have Chars fields
3924
3925 -- First deal with internal names, which generally represent something
3926 -- gone wrong. First attempt: if this is a rewritten node that rewrites
3927 -- something with a Chars field that is not an internal name, use that.
3928
3929 elsif Is_Internal_Name (Chars (Node))
3930 and then Nkind (Original_Node (Node)) in N_Has_Chars
3931 and then not Is_Internal_Name (Chars (Original_Node (Node)))
3932 then
3933 Nam := Chars (Original_Node (Node));
3934 Loc := Sloc (Original_Node (Node));
3935
3936 -- Another shot for internal names, in the case of internal type names,
3937 -- we try to find a reasonable representation for the external name.
3938
3939 elsif Is_Internal_Name (Chars (Node))
3940 and then
3941 ((Is_Entity_Name (Node)
3942 and then Present (Entity (Node))
3943 and then Is_Type (Entity (Node)))
3944 or else
3945 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
3946 then
3947 if Nkind (Node) = N_Identifier then
3948 Ent := Entity (Node);
3949 else
3950 Ent := Node;
3951 end if;
3952
3953 Loc := Sloc (Ent);
3954
3955 -- If the type is the designated type of an access_to_subprogram,
3956 -- then there is no name to provide in the call.
3957
3958 if Ekind (Ent) = E_Subprogram_Type then
3959 return;
3960
3961 -- Otherwise, we will be able to find some kind of name to output
3962
3963 else
3964 Unwind_Internal_Type (Ent);
3965 Nam := Chars (Ent);
3966 end if;
3967
3968 -- If not internal name, or if we could not find a reasonable possible
3969 -- substitution for the internal name, just use name in Chars field.
3970
3971 else
3972 Nam := Chars (Node);
3973 Loc := Sloc (Node);
3974 end if;
3975
3976 -- At this stage, the name to output is in Nam
3977
3978 Get_Unqualified_Decoded_Name_String (Nam);
3979
3980 -- Remove trailing upper case letters from the name (useful for
3981 -- dealing with some cases of internal names).
3982
3983 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
3984 Name_Len := Name_Len - 1;
3985 end loop;
3986
3987 -- If we have any of the names from standard that start with the
3988 -- characters "any " (e.g. Any_Type), then kill the message since
3989 -- almost certainly it is a junk cascaded message.
3990
3991 if Name_Len > 4
3992 and then Name_Buffer (1 .. 4) = "any "
3993 then
3994 Kill_Message := True;
3995 end if;
3996
3997 -- If we still have an internal name, kill the message (will only
3998 -- work if we already had errors!)
3999
4000 if Is_Internal_Name then
4001 Kill_Message := True;
4002 end if;
4003 -- Remaining step is to adjust casing and possibly add 'Class
4004
4005 Adjust_Name_Case (Global_Name_Buffer, Loc);
4006 Set_Msg_Name_Buffer;
4007 Add_Class;
4008 end Set_Msg_Node;
4009
4010 ------------------
4011 -- Set_Msg_Text --
4012 ------------------
4013
4014 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
4015 C : Character; -- Current character
4016 P : Natural; -- Current index;
4017
4018 procedure Skip_Msg_Insertion_Warning (C : Character);
4019 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4020 -- sequences using < instead of ?). The caller has already bumped
4021 -- the pointer past the initial ? or < and C is set to this initial
4022 -- character (? or <). This procedure skips past the rest of the
4023 -- sequence. We do not need to set Msg_Insertion_Char, since this
4024 -- was already done during the message prescan.
4025 -- No validity check is performed as the insertion sequence is
4026 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4027 -- erroutc.adb for the validity checks.
4028
4029 --------------------------------
4030 -- Skip_Msg_Insertion_Warning --
4031 --------------------------------
4032
4033 procedure Skip_Msg_Insertion_Warning (C : Character) is
4034 begin
4035 if P <= Text'Last and then Text (P) = C then
4036 P := P + 1;
4037
4038 elsif P < Text'Last and then Text (P + 1) = C
4039 and then Text (P) in 'a' .. 'z' | 'A' .. 'Z' |
4040 '0' .. '9' | '*' | '$'
4041 then
4042 P := P + 2;
4043
4044 elsif P + 1 < Text'Last and then Text (P + 2) = C
4045 and then Text (P) in '.' | '_'
4046 and then Text (P + 1) in 'a' .. 'z'
4047 then
4048 P := P + 3;
4049 end if;
4050 end Skip_Msg_Insertion_Warning;
4051
4052 -- Start of processing for Set_Msg_Text
4053
4054 begin
4055 Manual_Quote_Mode := False;
4056 Msglen := 0;
4057 Flag_Source := Get_Source_File_Index (Flag);
4058
4059 -- Skip info: at start, we have recorded this in Error_Msg_Kind, and
4060 -- this will be used (Info field in error message object) to put back
4061 -- the string when it is printed. We need to do this, or we get confused
4062 -- with instantiation continuations.
4063
4064 if Text'Length > 6
4065 and then Text (Text'First .. Text'First + 5) = "info: "
4066 then
4067 P := Text'First + 6;
4068 else
4069 P := Text'First;
4070 end if;
4071
4072 -- Loop through characters of message
4073
4074 while P <= Text'Last loop
4075 C := Text (P);
4076 P := P + 1;
4077
4078 -- Check for insertion character or sequence
4079
4080 case C is
4081 when '%' =>
4082 if P <= Text'Last and then Text (P) = '%' then
4083 P := P + 1;
4084 Set_Msg_Insertion_Name_Literal;
4085 else
4086 Set_Msg_Insertion_Name;
4087 end if;
4088
4089 when '$' =>
4090 if P <= Text'Last and then Text (P) = '$' then
4091 P := P + 1;
4092 Set_Msg_Insertion_Unit_Name (Suffix => False);
4093 else
4094 Set_Msg_Insertion_Unit_Name;
4095 end if;
4096
4097 when '{' =>
4098 Set_Msg_Insertion_File_Name;
4099
4100 when '}' =>
4101 Set_Msg_Insertion_Type_Reference (Flag);
4102
4103 when '*' =>
4104 Set_Msg_Insertion_Reserved_Name;
4105
4106 when '&' =>
4107 Set_Msg_Insertion_Node;
4108
4109 when '#' =>
4110 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
4111
4112 when '\' =>
4113 Continuation := True;
4114
4115 if P <= Text'Last and then Text (P) = '\' then
4116 Continuation_New_Line := True;
4117 P := P + 1;
4118 end if;
4119
4120 when '@' =>
4121 Set_Msg_Insertion_Column;
4122
4123 when '>' =>
4124 Set_Msg_Insertion_Run_Time_Name;
4125
4126 when '^' =>
4127 Set_Msg_Insertion_Uint;
4128
4129 when '`' =>
4130 Manual_Quote_Mode := not Manual_Quote_Mode;
4131 Set_Msg_Char ('"');
4132
4133 when '!' =>
4134 null; -- already dealt with
4135
4136 when '?' =>
4137 Skip_Msg_Insertion_Warning ('?');
4138
4139 when '<' =>
4140 Skip_Msg_Insertion_Warning ('<');
4141
4142 when '|' =>
4143 null; -- already dealt with
4144
4145 when ''' =>
4146 Set_Msg_Char (Text (P));
4147 P := P + 1;
4148
4149 when '~' =>
4150 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
4151
4152 -- Upper case letter
4153
4154 when 'A' .. 'Z' =>
4155
4156 -- Start of reserved word if two or more
4157
4158 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
4159 P := P - 1;
4160 Set_Msg_Insertion_Reserved_Word (Text, P);
4161
4162 -- Single upper case letter is just inserted
4163
4164 else
4165 Set_Msg_Char (C);
4166 end if;
4167
4168 -- '[' (will be/would have been raised at run time)
4169
4170 when '[' =>
4171
4172 -- "[]" (insertion of error code)
4173
4174 if P <= Text'Last and then Text (P) = ']' then
4175 P := P + 1;
4176 Set_Msg_Insertion_Code;
4177
4178 else
4179 -- Switch the message from a warning to an error if the flag
4180 -- -gnatwE is specified to treat run-time exception warnings
4181 -- as non-serious errors.
4182
4183 if Error_Msg_Kind = Warning
4184 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
4185 then
4186 Is_Runtime_Raise := True;
4187 end if;
4188
4189 if Error_Msg_Kind = Warning then
4190 Set_Msg_Str ("will be raised at run time");
4191 else
4192 Set_Msg_Str ("would have been raised at run time");
4193 end if;
4194 end if;
4195
4196 -- ']' (may be/might have been raised at run time)
4197
4198 when ']' =>
4199 if Error_Msg_Kind = Warning then
4200 Set_Msg_Str ("may be raised at run time");
4201 else
4202 Set_Msg_Str ("might have been raised at run time");
4203 end if;
4204
4205 -- Normal character with no special treatment
4206
4207 when others =>
4208 Set_Msg_Char (C);
4209 end case;
4210 end loop;
4211 end Set_Msg_Text;
4212
4213 ----------------
4214 -- Set_Posted --
4215 ----------------
4216
4217 procedure Set_Posted (N : Node_Id) is
4218 P : Node_Id;
4219
4220 begin
4221 if Error_Msg_Kind = Erroutc.Error then
4222
4223 -- We always set Error_Posted on the node itself
4224
4225 Set_Error_Posted (N);
4226
4227 -- If it is a subexpression, then set Error_Posted on parents up to
4228 -- and including the first non-subexpression construct. This helps
4229 -- avoid cascaded error messages within a single expression.
4230
4231 P := N;
4232 loop
4233 P := Parent (P);
4234 exit when No (P);
4235 Set_Error_Posted (P);
4236 exit when Nkind (P) not in N_Subexpr;
4237 end loop;
4238
4239 if Nkind (P) in N_Pragma_Argument_Association
4240 | N_Component_Association
4241 | N_Discriminant_Association
4242 | N_Generic_Association
4243 | N_Parameter_Association
4244 then
4245 Set_Error_Posted (Parent (P));
4246 end if;
4247
4248 -- A special check, if we just posted an error on an attribute
4249 -- definition clause, then also set the entity involved as posted.
4250 -- For example, this stops complaining about the alignment after
4251 -- complaining about the size, which is likely to be useless.
4252
4253 if Nkind (P) = N_Attribute_Definition_Clause then
4254 if Is_Entity_Name (Name (P)) then
4255 Set_Error_Posted (Entity (Name (P)));
4256 end if;
4257 end if;
4258 end if;
4259 end Set_Posted;
4260
4261 -----------------------
4262 -- Set_Qualification --
4263 -----------------------
4264
4265 procedure Set_Qualification (N : Nat; E : Entity_Id) is
4266 begin
4267 if N /= 0 and then Scope (E) /= Standard_Standard then
4268 Set_Qualification (N - 1, Scope (E));
4269 Set_Msg_Node (Scope (E));
4270 Set_Msg_Char ('.');
4271 end if;
4272 end Set_Qualification;
4273
4274 -------------------------------------
4275 -- Should_Ignore_Pragma_SPARK_Mode --
4276 -------------------------------------
4277
4278 function Should_Ignore_Pragma_SPARK_Mode return Boolean is
4279 begin
4280 return Get_Name_Table_Boolean3 (Name_SPARK_Mode);
4281 end Should_Ignore_Pragma_SPARK_Mode;
4282
4283 ------------------------
4284 -- Special_Msg_Delete --
4285 ------------------------
4286
4287 -- Is it really right to have all this specialized knowledge in errout?
4288
4289 function Special_Msg_Delete
4290 (Msg : String;
4291 N : Node_Or_Entity_Id;
4292 E : Node_Or_Entity_Id) return Boolean
4293 is
4294 begin
4295 -- Never delete messages in -gnatdO mode
4296
4297 if Debug_Flag_OO then
4298 return False;
4299
4300 -- Processing for "Size too small" messages
4301
4302 elsif Is_Size_Too_Small_Message (Msg) then
4303
4304 -- Suppress "size too small" errors in CodePeer mode, since code may
4305 -- be analyzed in a different configuration than the one used for
4306 -- compilation. Even when the configurations match, this message
4307 -- may be issued on correct code, because pragma Pack is ignored
4308 -- in CodePeer mode.
4309
4310 if CodePeer_Mode then
4311 return True;
4312
4313 -- When a size is wrong for a frozen type there is no explicit size
4314 -- clause, and other errors have occurred, suppress the message,
4315 -- since it is likely that this size error is a cascaded result of
4316 -- other errors. The reason we eliminate unfrozen types is that
4317 -- messages issued before the freeze type are for sure OK.
4318
4319 elsif Nkind (N) in N_Entity
4320 and then Is_Frozen (E)
4321 and then Serious_Errors_Detected > 0
4322 and then Nkind (N) /= N_Component_Clause
4323 and then Nkind (Parent (N)) /= N_Component_Clause
4324 and then
4325 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
4326 and then
4327 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
4328 and then
4329 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
4330 then
4331 return True;
4332 end if;
4333 end if;
4334
4335 -- All special tests complete, so go ahead with message
4336
4337 return False;
4338 end Special_Msg_Delete;
4339
4340 -----------------
4341 -- SPARK_Msg_N --
4342 -----------------
4343
4344 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
4345 begin
4346 -- If SPARK_Mode is Off, we do not report SPARK legality errors to give
4347 -- the flexibility to opt out of SPARK checking completely. We do the
4348 -- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
4349 -- for tools to ignore SPARK checking even on SPARK code.
4350
4351 if SPARK_Mode /= Off
4352 and then not Should_Ignore_Pragma_SPARK_Mode
4353 then
4354 Error_Msg_N (Msg, N);
4355 end if;
4356 end SPARK_Msg_N;
4357
4358 ------------------
4359 -- SPARK_Msg_NE --
4360 ------------------
4361
4362 procedure SPARK_Msg_NE
4363 (Msg : String;
4364 N : Node_Or_Entity_Id;
4365 E : Node_Or_Entity_Id)
4366 is
4367 begin
4368 if SPARK_Mode /= Off
4369 and then not Should_Ignore_Pragma_SPARK_Mode
4370 then
4371 Error_Msg_NE (Msg, N, E);
4372 end if;
4373 end SPARK_Msg_NE;
4374
4375 --------------------------
4376 -- Unwind_Internal_Type --
4377 --------------------------
4378
4379 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
4380 Derived : Boolean := False;
4381 Mchar : Character;
4382 Old_Ent : Entity_Id;
4383
4384 begin
4385 -- Undo placement of a quote, since we will put it back later
4386
4387 Mchar := Msg_Buffer (Msglen);
4388
4389 if Mchar = '"' then
4390 Msglen := Msglen - 1;
4391 end if;
4392
4393 -- The loop here deals with recursive types, we are trying to find a
4394 -- related entity that is not an implicit type. Note that the check with
4395 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4396 -- "type derived from" message more than once in the case where we climb
4397 -- up multiple levels.
4398
4399 Find : loop
4400 Old_Ent := Ent;
4401
4402 -- Implicit access type, use directly designated type In Ada 2005,
4403 -- the designated type may be an anonymous access to subprogram, in
4404 -- which case we can only point to its definition.
4405
4406 if Is_Access_Type (Ent) then
4407 if Ekind (Ent) = E_Access_Subprogram_Type
4408 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
4409 or else Is_Access_Protected_Subprogram_Type (Ent)
4410 then
4411 Ent := Directly_Designated_Type (Ent);
4412
4413 if not Comes_From_Source (Ent) then
4414 if Buffer_Ends_With ("type ") then
4415 Buffer_Remove ("type ");
4416 end if;
4417 end if;
4418
4419 if Ekind (Ent) = E_Function then
4420 Set_Msg_Str ("access to function ");
4421 elsif Ekind (Ent) = E_Procedure then
4422 Set_Msg_Str ("access to procedure ");
4423 else
4424 Set_Msg_Str ("access to subprogram");
4425 end if;
4426
4427 exit Find;
4428
4429 -- Type is access to object, named or anonymous
4430
4431 else
4432 Set_Msg_Str ("access to ");
4433 Ent := Directly_Designated_Type (Ent);
4434 end if;
4435
4436 -- Classwide type
4437
4438 elsif Is_Class_Wide_Type (Ent) then
4439 Class_Flag := True;
4440 Ent := Root_Type (Ent);
4441
4442 -- Use base type if this is a subtype
4443
4444 elsif Ent /= Base_Type (Ent) then
4445 Buffer_Remove ("type ");
4446
4447 -- Avoid duplication "subtype of subtype of", and also replace
4448 -- "derived from subtype of" simply by "derived from"
4449
4450 if not Buffer_Ends_With ("subtype of ")
4451 and then not Buffer_Ends_With ("derived from ")
4452 then
4453 Set_Msg_Str ("subtype of ");
4454 end if;
4455
4456 Ent := Base_Type (Ent);
4457
4458 -- If this is a base type with a first named subtype, use the first
4459 -- named subtype instead. This is not quite accurate in all cases,
4460 -- but it makes too much noise to be accurate and add 'Base in all
4461 -- cases. Note that we only do this is the first named subtype is not
4462 -- itself an internal name. This avoids the obvious loop (subtype ->
4463 -- basetype -> subtype) which would otherwise occur).
4464
4465 else
4466 declare
4467 FST : constant Entity_Id := First_Subtype (Ent);
4468
4469 begin
4470 if not Is_Internal_Name (Chars (FST)) then
4471 Ent := FST;
4472 exit Find;
4473
4474 -- Otherwise use root type
4475
4476 else
4477 if not Derived then
4478 Buffer_Remove ("type ");
4479
4480 -- Test for "subtype of type derived from" which seems
4481 -- excessive and is replaced by "type derived from".
4482
4483 Buffer_Remove ("subtype of");
4484
4485 -- Avoid duplicated "type derived from type derived from"
4486
4487 if not Buffer_Ends_With ("type derived from ") then
4488 Set_Msg_Str ("type derived from ");
4489 end if;
4490
4491 Derived := True;
4492 end if;
4493 end if;
4494 end;
4495
4496 Ent := Etype (Ent);
4497 end if;
4498
4499 -- If we are stuck in a loop, get out and settle for the internal
4500 -- name after all. In this case we set to kill the message if it is
4501 -- not the first error message (we really try hard not to show the
4502 -- dirty laundry of the implementation to the poor user).
4503
4504 if Ent = Old_Ent then
4505 Kill_Message := True;
4506 exit Find;
4507 end if;
4508
4509 -- Get out if we finally found a non-internal name to use
4510
4511 exit Find when not Is_Internal_Name (Chars (Ent));
4512 end loop Find;
4513
4514 if Mchar = '"' then
4515 Set_Msg_Char ('"');
4516 end if;
4517 end Unwind_Internal_Type;
4518
4519 --------------------
4520 -- Warn_Insertion --
4521 --------------------
4522
4523 function Warn_Insertion return String is
4524 begin
4525 if Warning_Msg_Char = "? " then
4526 return "??";
4527 elsif Warning_Msg_Char = " " then
4528 return "?";
4529 elsif Warning_Msg_Char (2) = ' ' then
4530 return '?' & Warning_Msg_Char (1) & '?';
4531 else
4532 return '?' & Warning_Msg_Char & '?';
4533 end if;
4534 end Warn_Insertion;
4535
4536 end Errout;