1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
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
32 with Atree; use Atree;
33 with Casing; use Casing;
34 with Csets; use Csets;
35 with Debug; use Debug;
36 with Einfo; use Einfo;
37 with Erroutc; use Erroutc;
38 with Gnatvsn; use Gnatvsn;
41 with Nlists; use Nlists;
42 with Output; use Output;
43 with Scans; use Scans;
44 with Sem_Aux; use Sem_Aux;
45 with Sinput; use Sinput;
46 with Sinfo; use Sinfo;
47 with Snames; use Snames;
48 with Stand; use Stand;
49 with Stylesw; use Stylesw;
50 with Uname; use Uname;
52 package body Errout is
54 Errors_Must_Be_Ignored : Boolean := False;
55 -- Set to True by procedure Set_Ignore_Errors (True), when calls to error
56 -- message procedures should be ignored (when parsing irrelevant text in
57 -- sources being preprocessed).
59 Finalize_Called : Boolean := False;
60 -- Set True if the Finalize routine has been called
62 Record_Compilation_Errors : Boolean := False;
63 -- Record that a compilation error was witnessed during a given phase of
64 -- analysis for gnat2why. This is needed as Warning_Mode is modified twice
65 -- in gnat2why, hence Erroutc.Compilation_Errors can only return a suitable
66 -- value for each phase of analysis separately. This is updated at each
67 -- call to Compilation_Errors.
69 Warn_On_Instance : Boolean;
70 -- Flag set true for warning message to be posted on instance
72 ------------------------------------
73 -- Table of Non-Instance Messages --
74 ------------------------------------
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.
81 type NIM_Record is record
85 -- Type used to store text and location of one message
87 package Non_Instance_Msgs is new Table.Table (
88 Table_Component_Type => NIM_Record,
89 Table_Index_Type => Int,
92 Table_Increment => 100,
93 Table_Name => "Non_Instance_Msgs");
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 procedure Error_Msg_Internal
104 -- This is the low level routine used to post messages after dealing with
105 -- the issue of messages placed on instantiations (which get broken up
106 -- into separate calls in Error_Msg). Sptr is the location on which the
107 -- flag will be placed in the output. In the case where the flag is on
108 -- the template, this points directly to the template, not to one of the
109 -- instantiation copies of the template. Optr is the original location
110 -- used to flag the error, and this may indeed point to an instantiation
111 -- copy. So typically we can see Optr pointing to the template location
112 -- in an instantiation copy when Sptr points to the source location of
113 -- the actual instantiation (i.e the line with the new). Msg_Cont is
114 -- set true if this is a continuation message.
116 function No_Warnings (N : Node_Or_Entity_Id) return Boolean;
117 -- Determines if warnings should be suppressed for the given node
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.
126 procedure Output_Source_Line
127 (L : Physical_Line_Number;
128 Sfile : Source_File_Index;
130 -- Outputs text of source line L, in file S, together with preceding line
131 -- number, as described above for Output_Line_Number. The Errs parameter
132 -- indicates if there are errors attached to the line, which forces
133 -- listing on, even in the presence of pragma List (Off).
135 procedure Set_Msg_Insertion_Column;
136 -- Handle column number insertion (@ insertion character)
138 procedure Set_Msg_Insertion_Node;
139 -- Handle node (name from node) insertion (& insertion character)
141 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr);
142 -- Handle type reference (right brace insertion character). Flag is the
143 -- location of the flag, which is provided for the internal call to
144 -- Set_Msg_Insertion_Line_Number,
146 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True);
147 -- Handle unit name insertion ($ insertion character). Depending on Boolean
148 -- parameter Suffix, (spec) or (body) is appended after the unit name.
150 procedure Set_Msg_Node (Node : Node_Id);
151 -- Add the sequence of characters for the name associated with the given
152 -- node to the current message. For N_Designator, N_Selected_Component,
153 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
156 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr);
157 -- Add a sequence of characters to the current message. The characters may
158 -- be one of the special insertion characters (see documentation in spec).
159 -- Flag is the location at which the error is to be posted, which is used
160 -- to determine whether or not the # insertion needs a file name. The
161 -- variables Msg_Buffer are set on return Msglen.
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.
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.
175 function Special_Msg_Delete
177 N : Node_Or_Entity_Id;
178 E : Node_Or_Entity_Id) return Boolean;
179 -- This function is called from Error_Msg_NEL, passing the message Msg,
180 -- node N on which the error is to be posted, and the entity or node E
181 -- to be used for an & insertion in the message if any. The job of this
182 -- procedure is to test for certain cascaded messages that we would like
183 -- to suppress. If the message is to be suppressed then we return True.
184 -- If the message should be generated (the normal case) False is returned.
186 procedure Unwind_Internal_Type (Ent : in out Entity_Id);
187 -- This procedure is given an entity id for an internal type, i.e. a type
188 -- with an internal name. It unwinds the type to try to get to something
189 -- reasonably printable, generating prefixes like "subtype of", "access
190 -- to", etc along the way in the buffer. The value in Ent on return is the
191 -- final name to be printed. Hopefully this is not an internal name, but in
192 -- some internal name cases, it is an internal name, and has to be printed
193 -- anyway (although in this case the message has been killed if possible).
194 -- The global variable Class_Flag is set to True if the resulting entity
195 -- should have 'Class appended to its name (see Add_Class procedure), and
196 -- is otherwise unchanged.
198 function Warn_Insertion return String;
199 -- This is called for warning messages only (so Warning_Msg_Char is set)
200 -- and returns a corresponding string to use at the beginning of generated
201 -- auxiliary messages, such as "in instantiation at ...".
202 -- 'a' .. 'z' returns "?x?"
203 -- 'A' .. 'Z' returns "?X?"
205 -- '$' returns "?$?info: "
207 -- No other settings are valid
209 -----------------------
210 -- Change_Error_Text --
211 -----------------------
213 procedure Change_Error_Text (Error_Id : Error_Msg_Id; New_Msg : String) is
214 Save_Next : Error_Msg_Id;
215 Err_Id : Error_Msg_Id := Error_Id;
218 Set_Msg_Text (New_Msg, Errors.Table (Error_Id).Sptr);
219 Errors.Table (Error_Id).Text := new String'(Msg_Buffer (1 .. Msglen));
221 -- If in immediate error message mode, output modified error message now
222 -- This is just a bit tricky, because we want to output just a single
223 -- message, and the messages we modified is already linked in. We solve
224 -- this by temporarily resetting its forward pointer to empty.
226 if Debug_Flag_OO then
227 Save_Next := Errors.Table (Error_Id).Next;
228 Errors.Table (Error_Id).Next := No_Error_Msg;
231 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
232 Output_Error_Msgs (Err_Id);
233 Errors.Table (Error_Id).Next := Save_Next;
235 end Change_Error_Text;
237 ------------------------
238 -- Compilation_Errors --
239 ------------------------
241 function Compilation_Errors return Boolean is
243 if not Finalize_Called then
246 -- Record that a compilation error was witnessed during a given phase of
247 -- analysis for gnat2why. This is needed as Warning_Mode is modified
248 -- twice in gnat2why, hence Erroutc.Compilation_Errors can only return a
249 -- suitable value for each phase of analysis separately.
252 Record_Compilation_Errors :=
253 Record_Compilation_Errors or else Erroutc.Compilation_Errors;
255 return Record_Compilation_Errors;
257 end Compilation_Errors;
259 --------------------------------------
260 -- Delete_Warning_And_Continuations --
261 --------------------------------------
263 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
267 pragma Assert (not Errors.Table (Msg).Msg_Cont);
272 M : Error_Msg_Object renames Errors.Table (Id);
275 if not M.Deleted then
277 Warnings_Detected := Warnings_Detected - 1;
280 Info_Messages := Info_Messages - 1;
284 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
289 exit when Id = No_Error_Msg;
290 exit when not Errors.Table (Id).Msg_Cont;
293 end Delete_Warning_And_Continuations;
299 -- Error_Msg posts a flag at the given location, except that if the
300 -- Flag_Location points within a generic template and corresponds to an
301 -- instantiation of this generic template, then the actual message will be
302 -- posted on the generic instantiation, along with additional messages
303 -- referencing the generic declaration.
305 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
306 Sindex : Source_File_Index;
307 -- Source index for flag location
309 Orig_Loc : Source_Ptr;
310 -- Original location of Flag_Location (i.e. location in original
311 -- template in instantiation case, otherwise unchanged).
314 -- Return if all errors are to be ignored
316 if Errors_Must_Be_Ignored then
320 -- If we already have messages, and we are trying to place a message at
321 -- No_Location, then just ignore the attempt since we assume that what
322 -- is happening is some cascaded junk. Note that this is safe in the
323 -- sense that proceeding will surely bomb. We will also bomb if the flag
324 -- location is No_Location and we don't have any messages so far, but
325 -- that is a real bug and a legitimate bomb, so we go ahead.
327 if Flag_Location = No_Location
328 and then Total_Errors_Detected > 0
333 -- Start of processing for new message
335 Sindex := Get_Source_File_Index (Flag_Location);
336 Prescan_Message (Msg);
337 Orig_Loc := Original_Location (Flag_Location);
339 -- If the current location is in an instantiation, the issue arises of
340 -- whether to post the message on the template or the instantiation.
342 -- The way we decide is to see if we have posted the same message on
343 -- the template when we compiled the template (the template is always
344 -- compiled before any instantiations). For this purpose, we use a
345 -- separate table of messages. The reason we do this is twofold:
347 -- First, the messages can get changed by various processing
348 -- including the insertion of tokens etc, making it hard to
349 -- do the comparison.
351 -- Second, we will suppress a warning on a template if it is not in
352 -- the current extended source unit. That's reasonable and means we
353 -- don't want the warning on the instantiation here either, but it
354 -- does mean that the main error table would not in any case include
357 if Flag_Location = Orig_Loc then
358 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
359 Warn_On_Instance := False;
361 -- Here we have an instance message
364 -- Delete if debug flag off, and this message duplicates a message
365 -- already posted on the corresponding template
367 if not Debug_Flag_GG then
368 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
369 if Msg = Non_Instance_Msgs.Table (J).Msg.all
370 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
377 -- No duplicate, so error/warning will be posted on instance
379 Warn_On_Instance := Is_Warning_Msg;
382 -- Ignore warning message that is suppressed for this location. Note
383 -- that style checks are not considered warning messages for this
386 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String
390 -- For style messages, check too many messages so far
393 and then Maximum_Messages /= 0
394 and then Warnings_Detected >= Maximum_Messages
399 -- The idea at this stage is that we have two kinds of messages
401 -- First, we have those messages that are to be placed as requested at
402 -- Flag_Location. This includes messages that have nothing to do with
403 -- generics, and also messages placed on generic templates that reflect
404 -- an error in the template itself. For such messages we simply call
405 -- Error_Msg_Internal to place the message in the requested location.
407 if Instantiation (Sindex) = No_Location then
408 Error_Msg_Internal (Msg, Flag_Location, Flag_Location, False);
412 -- If we are trying to flag an error in an instantiation, we may have
413 -- a generic contract violation. What we generate in this case is:
415 -- instantiation error at ...
416 -- original error message
420 -- warning: in instantiation at ...
421 -- warning: original warning message
425 -- info: in instantiation at ...
426 -- info: original info message
428 -- All these messages are posted at the location of the top level
429 -- instantiation. If there are nested instantiations, then the
430 -- instantiation error message can be repeated, pointing to each
431 -- of the relevant instantiations.
433 -- Note: the instantiation mechanism is also shared for inlining of
434 -- subprogram bodies when front end inlining is done. In this case the
435 -- messages have the form:
437 -- in inlined body at ...
438 -- original error message
442 -- warning: in inlined body at ...
443 -- warning: original warning message
447 -- info: in inlined body at ...
448 -- info: original info message
450 -- OK, here we have an instantiation error, and we need to generate the
451 -- error on the instantiation, rather than on the template.
454 Actual_Error_Loc : Source_Ptr;
455 -- Location of outer level instantiation in instantiation case, or
456 -- just a copy of Flag_Location in the normal case. This is the
457 -- location where all error messages will actually be posted.
459 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
460 -- Save possible location set for caller's message. We need to use
461 -- Error_Msg_Sloc for the location of the instantiation error but we
462 -- have to preserve a possible original value.
464 X : Source_File_Index;
466 Msg_Cont_Status : Boolean;
467 -- Used to label continuation lines in instantiation case with
468 -- proper Msg_Cont status.
471 -- Loop to find highest level instantiation, where all error
472 -- messages will be placed.
476 Actual_Error_Loc := Instantiation (X);
477 X := Get_Source_File_Index (Actual_Error_Loc);
478 exit when Instantiation (X) = No_Location;
481 -- Since we are generating the messages at the instantiation point in
482 -- any case, we do not want the references to the bad lines in the
483 -- instance to be annotated with the location of the instantiation.
485 Suppress_Instance_Location := True;
486 Msg_Cont_Status := False;
488 -- Loop to generate instantiation messages
490 Error_Msg_Sloc := Flag_Location;
491 X := Get_Source_File_Index (Flag_Location);
492 while Instantiation (X) /= No_Location loop
494 -- Suppress instantiation message on continuation lines
496 if Msg (Msg'First) /= '\' then
498 -- Case of inlined body
500 if Inlined_Body (X) then
503 ("info: in inlined body #",
504 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
506 elsif Is_Warning_Msg or Is_Style_Msg then
508 (Warn_Insertion & "in inlined body #",
509 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
513 ("error in inlined body #",
514 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
517 -- Case of generic instantiation
522 ("info: in instantiation #",
523 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
525 elsif Is_Warning_Msg or else Is_Style_Msg then
527 (Warn_Insertion & "in instantiation #",
528 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
532 ("instantiation error #",
533 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
538 Error_Msg_Sloc := Instantiation (X);
539 X := Get_Source_File_Index (Error_Msg_Sloc);
540 Msg_Cont_Status := True;
543 Suppress_Instance_Location := False;
544 Error_Msg_Sloc := Save_Error_Msg_Sloc;
546 -- Here we output the original message on the outer instantiation
549 (Msg, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
553 --------------------------------
554 -- Error_Msg_Ada_2012_Feature --
555 --------------------------------
557 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
559 if Ada_Version < Ada_2012 then
560 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
562 if No (Ada_Version_Pragma) then
563 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
565 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
566 Error_Msg ("\incompatible with Ada version set#", Loc);
569 end Error_Msg_Ada_2012_Feature;
575 procedure Error_Msg_AP (Msg : String) is
580 -- If we had saved the Scan_Ptr value after scanning the previous
581 -- token, then we would have exactly the right place for putting
582 -- the flag immediately at hand. However, that would add at least
583 -- two instructions to a Scan call *just* to service the possibility
584 -- of an Error_Msg_AP call. So instead we reconstruct that value.
586 -- We have two possibilities, start with Prev_Token_Ptr and skip over
587 -- the current token, which is made harder by the possibility that this
588 -- token may be in error, or start with Token_Ptr and work backwards.
589 -- We used to take the second approach, but it's hard because of
590 -- comments, and harder still because things that look like comments
591 -- can appear inside strings. So now we take the first approach.
593 -- Note: in the case where there is no previous token, Prev_Token_Ptr
594 -- is set to Source_First, which is a reasonable position for the
595 -- error flag in this situation.
597 S1 := Prev_Token_Ptr;
600 -- If the previous token is a string literal, we need a special approach
601 -- since there may be white space inside the literal and we don't want
602 -- to stop on that white space.
604 -- Note: since this is an error recovery issue anyway, it is not worth
605 -- worrying about special UTF_32 line terminator characters here.
607 if Prev_Token = Tok_String_Literal then
611 if Source (S1) = C then
613 exit when Source (S1) /= C;
614 elsif Source (S1) in Line_Terminator then
619 -- Character literal also needs special handling
621 elsif Prev_Token = Tok_Char_Literal then
624 -- Otherwise we search forward for the end of the current token, marked
625 -- by a line terminator, white space, a comment symbol or if we bump
626 -- into the following token (i.e. the current token).
628 -- Again, it is not worth worrying about UTF_32 special line terminator
629 -- characters in this context, since this is only for error recovery.
632 while Source (S1) not in Line_Terminator
633 and then Source (S1) /= ' '
634 and then Source (S1) /= ASCII.HT
635 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
636 and then S1 /= Token_Ptr
642 -- S1 is now set to the location for the flag
651 procedure Error_Msg_BC (Msg : String) is
653 -- If we are at end of file, post the flag after the previous token
655 if Token = Tok_EOF then
658 -- If we are at start of file, post the flag at the current token
660 elsif Token_Ptr = Source_First (Current_Source_File) then
663 -- If the character before the current token is a space or a horizontal
664 -- tab, then we place the flag on this character (in the case of a tab
665 -- we would really like to place it in the "last" character of the tab
666 -- space, but that it too much trouble to worry about).
668 elsif Source (Token_Ptr - 1) = ' '
669 or else Source (Token_Ptr - 1) = ASCII.HT
671 Error_Msg (Msg, Token_Ptr - 1);
673 -- If there is no space or tab before the current token, then there is
674 -- no room to place the flag before the token, so we place it on the
675 -- token instead (this happens for example at the start of a line).
678 Error_Msg (Msg, Token_Ptr);
686 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
687 CNRT : constant String := " not allowed in no run time mode";
688 CCRT : constant String := " not supported by configuration>";
690 S : String (1 .. Feature'Length + 1 + CCRT'Length);
695 S (2 .. Feature'Length + 1) := Feature;
696 L := Feature'Length + 2;
698 if No_Run_Time_Mode then
699 S (L .. L + CNRT'Length - 1) := CNRT;
700 L := L + CNRT'Length - 1;
702 else pragma Assert (Configurable_Run_Time_Mode);
703 S (L .. L + CCRT'Length - 1) := CCRT;
704 L := L + CCRT'Length - 1;
707 Error_Msg_N (S (1 .. L), N);
708 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
715 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
718 ("illegal overriding of subprogram inherited from interface", E);
720 Error_Msg_Sloc := Sloc (Iface_Prim);
722 if Ekind (E) = E_Function then
724 ("\first formal of & declared # must be of mode `IN` "
725 & "or access-to-constant", E);
728 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
729 & "or access-to-variable", E);
737 procedure Error_Msg_F (Msg : String; N : Node_Id) is
739 Error_Msg_NEL (Msg, N, N, Sloc (First_Node (N)));
746 procedure Error_Msg_FE
749 E : Node_Or_Entity_Id)
752 Error_Msg_NEL (Msg, N, E, Sloc (First_Node (N)));
755 ------------------------
756 -- Error_Msg_Internal --
757 ------------------------
759 procedure Error_Msg_Internal
765 Next_Msg : Error_Msg_Id;
766 -- Pointer to next message at insertion point
768 Prev_Msg : Error_Msg_Id;
769 -- Pointer to previous message at insertion point
771 Temp_Msg : Error_Msg_Id;
774 -- Set if warning to be treated as error
776 procedure Handle_Serious_Error;
777 -- Internal procedure to do all error message handling for a serious
778 -- error message, other than bumping the error counts and arranging
779 -- for the message to be output.
781 --------------------------
782 -- Handle_Serious_Error --
783 --------------------------
785 procedure Handle_Serious_Error is
787 -- Turn off code generation if not done already
789 if Operating_Mode = Generate_Code then
790 Operating_Mode := Check_Semantics;
791 Expander_Active := False;
794 -- Set the fatal error flag in the unit table unless we are in
795 -- Try_Semantics mode (in which case we set ignored mode if not
796 -- currently set. This stops the semantics from being performed
797 -- if we find a serious error. This is skipped if we are currently
798 -- dealing with the configuration pragma file.
800 if Current_Source_Unit /= No_Unit then
802 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
804 if Try_Semantics then
805 if Fatal_Error (U) = None then
806 Set_Fatal_Error (U, Error_Ignored);
809 Set_Fatal_Error (U, Error_Detected);
813 end Handle_Serious_Error;
815 -- Start of processing for Error_Msg_Internal
818 if Raise_Exception_On_Error /= 0 then
819 raise Error_Msg_Exception;
822 Continuation := Msg_Cont;
823 Continuation_New_Line := False;
824 Suppress_Message := False;
825 Kill_Message := False;
826 Set_Msg_Text (Msg, Sptr);
828 -- Kill continuation if parent message killed
830 if Continuation and Last_Killed then
834 -- Return without doing anything if message is suppressed
837 and then not All_Errors_Mode
838 and then not Is_Warning_Msg
839 and then not Is_Unconditional_Msg
841 if not Continuation then
848 -- Return without doing anything if message is killed and this is not
849 -- the first error message. The philosophy is that if we get a weird
850 -- error message and we already have had a message, then we hope the
851 -- weird message is a junk cascaded message
854 and then not All_Errors_Mode
855 and then Total_Errors_Detected /= 0
857 if not Continuation then
864 -- Special check for warning message to see if it should be output
866 if Is_Warning_Msg then
868 -- Immediate return if warning message and warnings are suppressed
870 if Warnings_Suppressed (Optr) /= No_String
872 Warnings_Suppressed (Sptr) /= No_String
874 Cur_Msg := No_Error_Msg;
878 -- If the flag location is in the main extended source unit then for
879 -- sure we want the warning since it definitely belongs
881 if In_Extended_Main_Source_Unit (Sptr) then
884 -- If the main unit has not been read yet. the warning must be on
885 -- a configuration file: gnat.adc or user-defined. This means we
886 -- are not parsing the main unit yet, so skip following checks.
888 elsif No (Cunit (Main_Unit)) then
891 -- If the flag location is not in the main extended source unit, then
892 -- we want to eliminate the warning, unless it is in the extended
893 -- main code unit and we want warnings on the instance.
895 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
898 -- Keep warning if debug flag G set
900 elsif Debug_Flag_GG then
903 -- Keep warning if message text contains !!
905 elsif Has_Double_Exclam then
908 -- Here is where we delete a warning from a with'ed unit
911 Cur_Msg := No_Error_Msg;
913 if not Continuation then
921 -- If message is to be ignored in special ignore message mode, this is
922 -- where we do this special processing, bypassing message output.
924 if Ignore_Errors_Enable > 0 then
925 if Is_Serious_Error then
926 Handle_Serious_Error;
932 -- If error message line length set, and this is a continuation message
933 -- then all we do is to append the text to the text of the last message
934 -- with a comma space separator (eliminating a possible (style) or
937 if Error_Msg_Line_Length /= 0 and then Continuation then
938 Cur_Msg := Errors.Last;
941 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
942 Newm : String (1 .. Oldm'Last + 2 + Msglen);
947 -- First copy old message to new one and free it
949 Newm (Oldm'Range) := Oldm.all;
953 -- Remove (style) or info: at start of message
955 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
958 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
965 -- Now deal with separation between messages. Normally this is
966 -- simply comma space, but there are some special cases.
968 -- If continuation new line, then put actual NL character in msg
970 if Continuation_New_Line then
972 Newm (Newl) := ASCII.LF;
974 -- If continuation message is enclosed in parentheses, then
975 -- special treatment (don't need a comma, and we want to combine
976 -- successive parenthetical remarks into a single one with
977 -- separating commas).
979 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
981 -- Case where existing message ends in right paren, remove
982 -- and separate parenthetical remarks with a comma.
984 if Newm (Newl) = ')' then
986 Msg_Buffer (M) := ' ';
988 -- Case where we are adding new parenthetical comment
995 -- Case where continuation not in parens and no new line
998 Newm (Newl + 1 .. Newl + 2) := ", ";
1002 -- Append new message
1004 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1005 Msg_Buffer (M .. Msglen);
1006 Newl := Newl + Msglen - M + 1;
1007 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1009 -- Update warning msg flag and message doc char if needed
1011 if Is_Warning_Msg then
1012 if not Errors.Table (Cur_Msg).Warn then
1013 Errors.Table (Cur_Msg).Warn := True;
1014 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1016 elsif Warning_Msg_Char /= ' ' then
1017 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1025 -- Here we build a new error object
1028 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1029 Next => No_Error_Msg,
1030 Prev => No_Error_Msg,
1033 Sfile => Get_Source_File_Index (Sptr),
1034 Line => Get_Physical_Line_Number (Sptr),
1035 Col => Get_Column_Number (Sptr),
1036 Warn => Is_Warning_Msg,
1037 Info => Is_Info_Msg,
1038 Check => Is_Check_Msg,
1039 Warn_Err => False, -- reset below
1040 Warn_Chr => Warning_Msg_Char,
1041 Style => Is_Style_Msg,
1042 Serious => Is_Serious_Error,
1043 Uncond => Is_Unconditional_Msg,
1044 Msg_Cont => Continuation,
1046 Cur_Msg := Errors.Last;
1048 -- Test if warning to be treated as error
1052 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1054 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
1056 -- Propagate Warn_Err to this message and preceding continuations
1058 for J in reverse 1 .. Errors.Last loop
1059 Errors.Table (J).Warn_Err := Warn_Err;
1060 exit when not Errors.Table (J).Msg_Cont;
1063 -- If immediate errors mode set, output error message now. Also output
1064 -- now if the -d1 debug flag is set (so node number message comes out
1065 -- just before actual error message)
1067 if Debug_Flag_OO or else Debug_Flag_1 then
1070 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1071 Temp_Msg := Cur_Msg;
1072 Output_Error_Msgs (Temp_Msg);
1074 -- If not in immediate errors mode, then we insert the message in the
1075 -- error chain for later output by Finalize. The messages are sorted
1076 -- first by unit (main unit comes first), and within a unit by source
1077 -- location (earlier flag location first in the chain).
1080 -- First a quick check, does this belong at the very end of the chain
1081 -- of error messages. This saves a lot of time in the normal case if
1082 -- there are lots of messages.
1084 if Last_Error_Msg /= No_Error_Msg
1085 and then Errors.Table (Cur_Msg).Sfile =
1086 Errors.Table (Last_Error_Msg).Sfile
1087 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
1089 (Sptr = Errors.Table (Last_Error_Msg).Sptr
1091 Optr > Errors.Table (Last_Error_Msg).Optr))
1093 Prev_Msg := Last_Error_Msg;
1094 Next_Msg := No_Error_Msg;
1096 -- Otherwise do a full sequential search for the insertion point
1099 Prev_Msg := No_Error_Msg;
1100 Next_Msg := First_Error_Msg;
1101 while Next_Msg /= No_Error_Msg loop
1103 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1105 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1107 exit when Sptr < Errors.Table (Next_Msg).Sptr
1108 or else (Sptr = Errors.Table (Next_Msg).Sptr
1109 and then Optr < Errors.Table (Next_Msg).Optr);
1112 Prev_Msg := Next_Msg;
1113 Next_Msg := Errors.Table (Next_Msg).Next;
1117 -- Now we insert the new message in the error chain.
1119 -- The possible insertion point for the new message is after Prev_Msg
1120 -- and before Next_Msg. However, this is where we do a special check
1121 -- for redundant parsing messages, defined as messages posted on the
1122 -- same line. The idea here is that probably such messages are junk
1123 -- from the parser recovering. In full errors mode, we don't do this
1124 -- deletion, but otherwise such messages are discarded at this stage.
1126 if Prev_Msg /= No_Error_Msg
1127 and then Errors.Table (Prev_Msg).Line =
1128 Errors.Table (Cur_Msg).Line
1129 and then Errors.Table (Prev_Msg).Sfile =
1130 Errors.Table (Cur_Msg).Sfile
1131 and then Compiler_State = Parsing
1132 and then not All_Errors_Mode
1134 -- Don't delete unconditional messages and at this stage, don't
1135 -- delete continuation lines; we attempted to delete those earlier
1136 -- if the parent message was deleted.
1138 if not Errors.Table (Cur_Msg).Uncond
1139 and then not Continuation
1141 -- Don't delete if prev msg is warning and new msg is an error.
1142 -- This is because we don't want a real error masked by a
1143 -- warning. In all other cases (that is parse errors for the
1144 -- same line that are not unconditional) we do delete the
1145 -- message. This helps to avoid junk extra messages from
1146 -- cascaded parsing errors
1148 if not (Errors.Table (Prev_Msg).Warn
1150 Errors.Table (Prev_Msg).Style)
1152 (Errors.Table (Cur_Msg).Warn
1154 Errors.Table (Cur_Msg).Style)
1156 -- All tests passed, delete the message by simply returning
1157 -- without any further processing.
1159 pragma Assert (not Continuation);
1161 Last_Killed := True;
1167 -- Come here if message is to be inserted in the error chain
1169 if not Continuation then
1170 Last_Killed := False;
1173 if Prev_Msg = No_Error_Msg then
1174 First_Error_Msg := Cur_Msg;
1176 Errors.Table (Prev_Msg).Next := Cur_Msg;
1179 Errors.Table (Cur_Msg).Next := Next_Msg;
1181 if Next_Msg = No_Error_Msg then
1182 Last_Error_Msg := Cur_Msg;
1186 -- Bump appropriate statistics counts
1188 if Errors.Table (Cur_Msg).Info then
1189 Info_Messages := Info_Messages + 1;
1191 -- Could be (usually is) both "info" and "warning"
1193 if Errors.Table (Cur_Msg).Warn then
1194 Warnings_Detected := Warnings_Detected + 1;
1197 elsif Errors.Table (Cur_Msg).Warn
1198 or else Errors.Table (Cur_Msg).Style
1200 Warnings_Detected := Warnings_Detected + 1;
1202 elsif Errors.Table (Cur_Msg).Check then
1203 Check_Messages := Check_Messages + 1;
1206 Total_Errors_Detected := Total_Errors_Detected + 1;
1208 if Errors.Table (Cur_Msg).Serious then
1209 Serious_Errors_Detected := Serious_Errors_Detected + 1;
1210 Handle_Serious_Error;
1212 -- If not serious error, set Fatal_Error to indicate ignored error
1216 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1218 if Fatal_Error (U) = None then
1219 Set_Fatal_Error (U, Error_Ignored);
1225 -- Record warning message issued
1227 if Errors.Table (Cur_Msg).Warn
1228 and then not Errors.Table (Cur_Msg).Msg_Cont
1230 Warning_Msg := Cur_Msg;
1233 -- If too many warnings turn off warnings
1235 if Maximum_Messages /= 0 then
1236 if Warnings_Detected = Maximum_Messages then
1237 Warning_Mode := Suppress;
1240 -- If too many errors abandon compilation
1242 if Total_Errors_Detected = Maximum_Messages then
1243 raise Unrecoverable_Error;
1246 end Error_Msg_Internal;
1252 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1254 Error_Msg_NEL (Msg, N, N, Sloc (N));
1261 procedure Error_Msg_NE
1263 N : Node_Or_Entity_Id;
1264 E : Node_Or_Entity_Id)
1267 Error_Msg_NEL (Msg, N, E, Sloc (N));
1274 procedure Error_Msg_NEL
1276 N : Node_Or_Entity_Id;
1277 E : Node_Or_Entity_Id;
1278 Flag_Location : Source_Ptr)
1281 if Special_Msg_Delete (Msg, N, E) then
1285 Prescan_Message (Msg);
1287 -- Special handling for warning messages
1289 if Is_Warning_Msg then
1291 -- Suppress if no warnings set for either entity or node
1293 if No_Warnings (N) or else No_Warnings (E) then
1295 -- Disable any continuation messages as well
1297 Last_Killed := True;
1301 -- Suppress if inside loop that is known to be null or is probably
1302 -- null (case where loop executes only if invalid values present).
1303 -- In either case warnings in the loop are likely to be junk.
1310 while Present (P) loop
1311 if Nkind (P) = N_Loop_Statement
1312 and then Suppress_Loop_Warnings (P)
1322 -- Test for message to be output
1325 or else Is_Unconditional_Msg
1326 or else Is_Warning_Msg
1328 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1331 Error_Msg_Node_1 := E;
1332 Error_Msg (Msg, Flag_Location);
1335 Last_Killed := True;
1345 procedure Error_Msg_NW
1348 N : Node_Or_Entity_Id)
1352 and then In_Extended_Main_Source_Unit (N)
1353 and then Comes_From_Source (N)
1355 Error_Msg_NEL (Msg, N, N, Sloc (N));
1363 procedure Error_Msg_S (Msg : String) is
1365 Error_Msg (Msg, Scan_Ptr);
1372 procedure Error_Msg_SC (Msg : String) is
1374 -- If we are at end of file, post the flag after the previous token
1376 if Token = Tok_EOF then
1379 -- For all other cases the message is posted at the current token
1383 Error_Msg (Msg, Token_Ptr);
1391 procedure Error_Msg_SP (Msg : String) is
1393 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1394 -- is set to Source_First, which is a reasonable position for the
1395 -- error flag in this situation
1397 Error_Msg (Msg, Prev_Token_Ptr);
1404 procedure Finalize (Last_Call : Boolean) is
1409 procedure Delete_Warning (E : Error_Msg_Id);
1410 -- Delete a warning msg if not already deleted and adjust warning count
1412 --------------------
1413 -- Delete_Warning --
1414 --------------------
1416 procedure Delete_Warning (E : Error_Msg_Id) is
1418 if not Errors.Table (E).Deleted then
1419 Errors.Table (E).Deleted := True;
1420 Warnings_Detected := Warnings_Detected - 1;
1422 if Errors.Table (E).Info then
1423 Info_Messages := Info_Messages - 1;
1426 if Errors.Table (E).Warn_Err then
1427 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
1432 -- Start of processing for Finalize
1435 -- Set Prev pointers
1437 Cur := First_Error_Msg;
1438 while Cur /= No_Error_Msg loop
1439 Nxt := Errors.Table (Cur).Next;
1440 exit when Nxt = No_Error_Msg;
1441 Errors.Table (Nxt).Prev := Cur;
1445 -- Eliminate any duplicated error messages from the list. This is
1446 -- done after the fact to avoid problems with Change_Error_Text.
1448 Cur := First_Error_Msg;
1449 while Cur /= No_Error_Msg loop
1450 Nxt := Errors.Table (Cur).Next;
1453 while F /= No_Error_Msg
1454 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1456 Check_Duplicate_Message (Cur, F);
1457 F := Errors.Table (F).Next;
1463 -- Mark any messages suppressed by specific warnings as Deleted
1465 Cur := First_Error_Msg;
1466 while Cur /= No_Error_Msg loop
1468 CE : Error_Msg_Object renames Errors.Table (Cur);
1469 Tag : constant String := Get_Warning_Tag (Cur);
1472 if (CE.Warn and not CE.Deleted)
1474 (Warning_Specifically_Suppressed (CE.Sptr, CE.Text, Tag) /=
1477 Warning_Specifically_Suppressed (CE.Optr, CE.Text, Tag) /=
1480 Delete_Warning (Cur);
1482 -- If this is a continuation, delete previous parts of message
1485 while Errors.Table (F).Msg_Cont loop
1486 F := Errors.Table (F).Prev;
1487 exit when F = No_Error_Msg;
1491 -- Delete any following continuations
1495 F := Errors.Table (F).Next;
1496 exit when F = No_Error_Msg;
1497 exit when not Errors.Table (F).Msg_Cont;
1503 Cur := Errors.Table (Cur).Next;
1506 Finalize_Called := True;
1508 -- Check consistency of specific warnings (may add warnings). We only
1509 -- do this on the last call, after all possible warnings are posted.
1512 Validate_Specific_Warnings (Error_Msg'Access);
1520 function First_Node (C : Node_Id) return Node_Id is
1521 Orig : constant Node_Id := Original_Node (C);
1522 Loc : constant Source_Ptr := Sloc (Orig);
1523 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1527 function Test_Earlier (N : Node_Id) return Traverse_Result;
1528 -- Function applied to every node in the construct
1530 procedure Search_Tree_First is new Traverse_Proc (Test_Earlier);
1531 -- Create traversal procedure
1537 function Test_Earlier (N : Node_Id) return Traverse_Result is
1538 Norig : constant Node_Id := Original_Node (N);
1539 Loc : constant Source_Ptr := Sloc (Norig);
1542 -- Check for earlier
1546 -- Ignore nodes with no useful location information
1548 and then Loc /= Standard_Location
1549 and then Loc /= No_Location
1551 -- Ignore nodes from a different file. This ensures against cases
1552 -- of strange foreign code somehow being present. We don't want
1553 -- wild placement of messages if that happens.
1555 and then Get_Source_File_Index (Loc) = Sfile
1564 -- Start of processing for First_Node
1567 if Nkind (Orig) in N_Subexpr then
1570 Search_Tree_First (Orig);
1582 function First_Sloc (N : Node_Id) return Source_Ptr is
1583 SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1584 SF : constant Source_Ptr := Source_First (SI);
1589 F := First_Node (N);
1592 -- The following circuit is a bit subtle. When we have parenthesized
1593 -- expressions, then the Sloc will not record the location of the paren,
1594 -- but we would like to post the flag on the paren. So what we do is to
1595 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1596 -- any parentheses we know are present. Yes, we know this circuit is not
1597 -- 100% reliable (e.g. because we don't record all possible paren level
1598 -- values), but this is only for an error message so it is good enough.
1601 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1603 -- We don't look more than 12 characters behind the current
1604 -- location, and in any case not past the front of the source.
1606 Search_Loop : for K in 1 .. 12 loop
1607 exit Search_Loop when S = SF;
1609 if Source_Text (SI) (S - 1) = '(' then
1613 elsif Source_Text (SI) (S - 1) <= ' ' then
1619 end loop Search_Loop;
1620 end loop Paren_Loop;
1622 exit Node_Loop when F = N;
1624 exit Node_Loop when Nkind (F) not in N_Subexpr;
1630 -----------------------
1631 -- Get_Ignore_Errors --
1632 -----------------------
1634 function Get_Ignore_Errors return Boolean is
1636 return Errors_Must_Be_Ignored;
1637 end Get_Ignore_Errors;
1643 procedure Initialize is
1646 First_Error_Msg := No_Error_Msg;
1647 Last_Error_Msg := No_Error_Msg;
1648 Serious_Errors_Detected := 0;
1649 Total_Errors_Detected := 0;
1650 Cur_Msg := No_Error_Msg;
1653 -- Reset counts for warnings
1657 -- Initialize warnings tables
1660 Specific_Warnings.Init;
1667 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1669 if Error_Posted (N) then
1672 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
1675 elsif Is_Entity_Name (N)
1676 and then Present (Entity (N))
1677 and then Has_Warnings_Off (Entity (N))
1690 function OK_Node (N : Node_Id) return Boolean is
1691 K : constant Node_Kind := Nkind (N);
1694 if Error_Posted (N) then
1697 elsif K in N_Has_Etype
1698 and then Present (Etype (N))
1699 and then Error_Posted (Etype (N))
1704 or else K = N_Attribute_Reference
1705 or else K = N_Character_Literal
1706 or else K = N_Expanded_Name
1707 or else K = N_Identifier
1708 or else K = N_Operator_Symbol)
1709 and then Present (Entity (N))
1710 and then Error_Posted (Entity (N))
1718 ---------------------
1719 -- Output_Messages --
1720 ---------------------
1722 procedure Output_Messages is
1726 procedure Write_Error_Summary;
1727 -- Write error summary
1729 procedure Write_Header (Sfile : Source_File_Index);
1730 -- Write header line (compiling or checking given file)
1732 procedure Write_Max_Errors;
1733 -- Write message if max errors reached
1735 -------------------------
1736 -- Write_Error_Summary --
1737 -------------------------
1739 procedure Write_Error_Summary is
1741 -- Extra blank line if error messages or source listing were output
1743 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
1748 -- Message giving number of lines read and number of errors detected.
1749 -- This normally goes to Standard_Output. The exception is when brief
1750 -- mode is not set, verbose mode (or full list mode) is set, and
1751 -- there are errors. In this case we send the message to standard
1752 -- error to make sure that *something* appears on standard error
1753 -- in an error situation.
1755 if Total_Errors_Detected + Warnings_Detected /= 0
1756 and then not Brief_Output
1757 and then (Verbose_Mode or Full_List)
1762 -- Message giving total number of lines. Don't give this message if
1763 -- the Main_Source line is unknown (this happens in error situations,
1764 -- e.g. when integrated preprocessing fails).
1766 if Main_Source_File /= No_Source_File then
1768 Write_Int (Num_Source_Lines (Main_Source_File));
1770 if Num_Source_Lines (Main_Source_File) = 1 then
1771 Write_Str (" line: ");
1773 Write_Str (" lines: ");
1777 if Total_Errors_Detected = 0 then
1778 Write_Str ("No errors");
1780 elsif Total_Errors_Detected = 1 then
1781 Write_Str ("1 error");
1784 Write_Int (Total_Errors_Detected);
1785 Write_Str (" errors");
1788 if Warnings_Detected - Info_Messages /= 0 then
1790 Write_Int (Warnings_Detected);
1791 Write_Str (" warning");
1793 if Warnings_Detected - Info_Messages /= 1 then
1797 if Warning_Mode = Treat_As_Error then
1798 Write_Str (" (treated as error");
1800 if Warnings_Detected /= 1 then
1806 elsif Warnings_Treated_As_Errors /= 0 then
1808 Write_Int (Warnings_Treated_As_Errors);
1809 Write_Str (" treated as errors)");
1813 if Info_Messages /= 0 then
1815 Write_Int (Info_Messages);
1816 Write_Str (" info message");
1818 if Info_Messages > 1 then
1824 Set_Standard_Output;
1825 end Write_Error_Summary;
1831 procedure Write_Header (Sfile : Source_File_Index) is
1833 if Verbose_Mode or Full_List then
1834 if Original_Operating_Mode = Generate_Code then
1835 Write_Str ("Compiling: ");
1837 Write_Str ("Checking: ");
1840 Write_Name (Full_File_Name (Sfile));
1842 if not Debug_Flag_7 then
1844 Write_Str ("Source file time stamp: ");
1845 Write_Time_Stamp (Sfile);
1847 Write_Str ("Compiled at: " & Compilation_Time);
1854 ----------------------
1855 -- Write_Max_Errors --
1856 ----------------------
1858 procedure Write_Max_Errors is
1860 if Maximum_Messages /= 0 then
1861 if Warnings_Detected >= Maximum_Messages then
1863 Write_Line ("maximum number of warnings output");
1864 Write_Line ("any further warnings suppressed");
1865 Set_Standard_Output;
1868 -- If too many errors print message
1870 if Total_Errors_Detected >= Maximum_Messages then
1872 Write_Line ("fatal error: maximum number of errors detected");
1873 Set_Standard_Output;
1876 end Write_Max_Errors;
1878 -- Start of processing for Output_Messages
1881 -- Error if Finalize has not been called
1883 if not Finalize_Called then
1884 raise Program_Error;
1887 -- Reset current error source file if the main unit has a pragma
1888 -- Source_Reference. This ensures outputting the proper name of
1889 -- the source file in this situation.
1891 if Main_Source_File = No_Source_File
1892 or else Num_SRef_Pragmas (Main_Source_File) /= 0
1894 Current_Error_Source_File := No_Source_File;
1899 if Brief_Output or (not Full_List and not Verbose_Mode) then
1902 E := First_Error_Msg;
1903 while E /= No_Error_Msg loop
1904 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1905 if Full_Path_Name_For_Brief_Errors then
1906 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1908 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1912 Write_Int (Int (Physical_To_Logical
1913 (Errors.Table (E).Line,
1914 Errors.Table (E).Sfile)));
1917 if Errors.Table (E).Col < 10 then
1921 Write_Int (Int (Errors.Table (E).Col));
1923 Output_Msg_Text (E);
1927 E := Errors.Table (E).Next;
1930 Set_Standard_Output;
1933 -- Full source listing case
1936 List_Pragmas_Index := 1;
1937 List_Pragmas_Mode := True;
1938 E := First_Error_Msg;
1940 -- Normal case, to stdout (copyright notice already output)
1942 if Full_List_File_Name = null then
1943 if not Debug_Flag_7 then
1950 Create_List_File_Access.all (Full_List_File_Name.all);
1951 Set_Special_Output (Write_List_Info_Access.all'Access);
1953 -- Write copyright notice to file
1955 if not Debug_Flag_7 then
1956 Write_Str ("GNAT ");
1957 Write_Str (Gnat_Version_String);
1959 Write_Str ("Copyright 1992-" &
1961 ", Free Software Foundation, Inc.");
1966 -- First list extended main source file units with errors
1968 for U in Main_Unit .. Last_Unit loop
1969 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
1971 -- If debug flag d.m is set, only the main source is listed
1973 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
1975 -- If the unit of the entity does not come from source, it is
1976 -- an implicit subprogram declaration for a child subprogram.
1977 -- Do not emit errors for it, they are listed with the body.
1980 (No (Cunit_Entity (U))
1981 or else Comes_From_Source (Cunit_Entity (U))
1982 or else not Is_Subprogram (Cunit_Entity (U)))
1984 -- If the compilation unit associated with this unit does not
1985 -- come from source, it means it is an instantiation that should
1986 -- not be included in the source listing.
1988 and then Comes_From_Source (Cunit (U))
1991 Sfile : constant Source_File_Index := Source_Index (U);
1996 -- Only write the header if Sfile is known
1998 if Sfile /= No_Source_File then
1999 Write_Header (Sfile);
2003 -- Normally, we don't want an "error messages from file"
2004 -- message when listing the entire file, so we set the
2005 -- current source file as the current error source file.
2006 -- However, the old style of doing things was to list this
2007 -- message if pragma Source_Reference is present, even for
2008 -- the main unit. Since the purpose of the -gnatd.m switch
2009 -- is to duplicate the old behavior, we skip the reset if
2010 -- this debug flag is set.
2012 if not Debug_Flag_Dot_M then
2013 Current_Error_Source_File := Sfile;
2016 -- Only output the listing if Sfile is known, to avoid
2017 -- crashing the compiler.
2019 if Sfile /= No_Source_File then
2020 for N in 1 .. Last_Source_Line (Sfile) loop
2021 while E /= No_Error_Msg
2022 and then Errors.Table (E).Deleted
2024 E := Errors.Table (E).Next;
2029 and then Errors.Table (E).Line = N
2030 and then Errors.Table (E).Sfile = Sfile;
2032 Output_Source_Line (N, Sfile, Err_Flag);
2035 Output_Error_Msgs (E);
2037 if not Debug_Flag_2 then
2047 -- Then output errors, if any, for subsidiary units not in the
2048 -- main extended unit.
2050 -- Note: if debug flag d.m set, include errors for any units other
2051 -- than the main unit in the extended source unit (e.g. spec and
2052 -- subunits for a body).
2054 while E /= No_Error_Msg
2055 and then (not In_Extended_Main_Source_Unit (Errors.Table (E).Sptr)
2058 and then Get_Source_Unit
2059 (Errors.Table (E).Sptr) /= Main_Unit))
2061 if Errors.Table (E).Deleted then
2062 E := Errors.Table (E).Next;
2067 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
2068 Output_Error_Msgs (E);
2072 -- If output to file, write extra copy of error summary to the
2073 -- output file, and then close it.
2075 if Full_List_File_Name /= null then
2076 Write_Error_Summary;
2078 Close_List_File_Access.all;
2079 Cancel_Special_Output;
2083 -- Verbose mode (error lines only with error flags). Normally this is
2084 -- ignored in full list mode, unless we are listing to a file, in which
2085 -- case we still generate -gnatv output to standard output.
2088 and then (not Full_List or else Full_List_File_Name /= null)
2092 -- Output the header only when Main_Source_File is known
2094 if Main_Source_File /= No_Source_File then
2095 Write_Header (Main_Source_File);
2098 E := First_Error_Msg;
2100 -- Loop through error lines
2102 while E /= No_Error_Msg loop
2103 if Errors.Table (E).Deleted then
2104 E := Errors.Table (E).Next;
2108 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
2109 Output_Error_Msgs (E);
2114 -- Output error summary if verbose or full list mode
2116 if Verbose_Mode or else Full_List then
2117 Write_Error_Summary;
2122 if Warning_Mode = Treat_As_Error then
2123 Total_Errors_Detected :=
2124 Total_Errors_Detected + Warnings_Detected;
2125 Warnings_Detected := Info_Messages;
2127 end Output_Messages;
2129 ------------------------
2130 -- Output_Source_Line --
2131 ------------------------
2133 procedure Output_Source_Line
2134 (L : Physical_Line_Number;
2135 Sfile : Source_File_Index;
2141 Line_Number_Output : Boolean := False;
2142 -- Set True once line number is output
2144 Empty_Line : Boolean := True;
2145 -- Set False if line includes at least one character
2148 if Sfile /= Current_Error_Source_File then
2149 Write_Str ("==============Error messages for ");
2151 case Sinput.File_Type (Sfile) is
2153 Write_Str ("source");
2155 when Sinput.Config =>
2156 Write_Str ("configuration pragmas");
2159 Write_Str ("symbol definition");
2161 when Sinput.Preproc =>
2162 Write_Str ("preprocessing data");
2165 Write_Str (" file: ");
2166 Write_Name (Full_File_Name (Sfile));
2169 if Num_SRef_Pragmas (Sfile) > 0 then
2170 Write_Str ("--------------Line numbers from file: ");
2171 Write_Name (Full_Ref_Name (Sfile));
2172 Write_Str (" (starting at line ");
2173 Write_Int (Int (First_Mapped_Line (Sfile)));
2178 Current_Error_Source_File := Sfile;
2181 if Errs or List_Pragmas_Mode then
2182 Output_Line_Number (Physical_To_Logical (L, Sfile));
2183 Line_Number_Output := True;
2186 S := Line_Start (L, Sfile);
2189 C := Source_Text (Sfile) (S);
2190 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
2192 -- Deal with matching entry in List_Pragmas table
2195 and then List_Pragmas_Index <= List_Pragmas.Last
2196 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
2198 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
2202 -- Ignore if on line with errors so that error flags
2203 -- get properly listed with the error line .
2206 Write_Char (ASCII.FF);
2210 List_Pragmas_Mode := True;
2212 if not Line_Number_Output then
2213 Output_Line_Number (Physical_To_Logical (L, Sfile));
2214 Line_Number_Output := True;
2221 List_Pragmas_Mode := False;
2224 List_Pragmas_Index := List_Pragmas_Index + 1;
2226 -- Normal case (no matching entry in List_Pragmas table)
2229 if Errs or List_Pragmas_Mode then
2234 Empty_Line := False;
2238 -- If we have output a source line, then add the line terminator, with
2239 -- training spaces preserved (so we output the line exactly as input).
2241 if Line_Number_Output then
2245 Write_Eol_Keep_Blanks;
2248 end Output_Source_Line;
2250 -----------------------------
2251 -- Remove_Warning_Messages --
2252 -----------------------------
2254 procedure Remove_Warning_Messages (N : Node_Id) is
2256 function Check_For_Warning (N : Node_Id) return Traverse_Result;
2257 -- This function checks one node for a possible warning message
2259 function Check_All_Warnings is new Traverse_Func (Check_For_Warning);
2260 -- This defines the traversal operation
2262 -----------------------
2263 -- Check_For_Warning --
2264 -----------------------
2266 function Check_For_Warning (N : Node_Id) return Traverse_Result is
2267 Loc : constant Source_Ptr := Sloc (N);
2270 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
2271 -- Returns True for a message that is to be removed. Also adjusts
2272 -- warning count appropriately.
2278 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
2280 if E /= No_Error_Msg
2282 -- Don't remove if location does not match
2284 and then Errors.Table (E).Optr = Loc
2286 -- Don't remove if not warning/info message. Note that we do
2287 -- not remove style messages here. They are warning messages
2288 -- but not ones we want removed in this context.
2290 and then Errors.Table (E).Warn
2292 -- Don't remove unconditional messages
2294 and then not Errors.Table (E).Uncond
2296 Warnings_Detected := Warnings_Detected - 1;
2298 if Errors.Table (E).Info then
2299 Info_Messages := Info_Messages - 1;
2304 -- No removal required
2311 -- Start of processing for Check_For_Warnings
2314 while To_Be_Removed (First_Error_Msg) loop
2315 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
2318 if First_Error_Msg = No_Error_Msg then
2319 Last_Error_Msg := No_Error_Msg;
2322 E := First_Error_Msg;
2323 while E /= No_Error_Msg loop
2324 while To_Be_Removed (Errors.Table (E).Next) loop
2325 Errors.Table (E).Next :=
2326 Errors.Table (Errors.Table (E).Next).Next;
2328 if Errors.Table (E).Next = No_Error_Msg then
2329 Last_Error_Msg := E;
2333 E := Errors.Table (E).Next;
2336 if Nkind (N) = N_Raise_Constraint_Error
2337 and then Original_Node (N) /= N
2338 and then No (Condition (N))
2340 -- Warnings may have been posted on subexpressions of the original
2341 -- tree. We place the original node back on the tree to remove
2342 -- those warnings, whose sloc do not match those of any node in
2343 -- the current tree. Given that we are in unreachable code, this
2344 -- modification to the tree is harmless.
2347 Status : Traverse_Final_Result;
2350 if Is_List_Member (N) then
2351 Set_Condition (N, Original_Node (N));
2352 Status := Check_All_Warnings (Condition (N));
2354 Rewrite (N, Original_Node (N));
2355 Status := Check_All_Warnings (N);
2364 end Check_For_Warning;
2366 -- Start of processing for Remove_Warning_Messages
2369 if Warnings_Detected /= 0 then
2371 Discard : Traverse_Final_Result;
2372 pragma Warnings (Off, Discard);
2375 Discard := Check_All_Warnings (N);
2378 end Remove_Warning_Messages;
2380 procedure Remove_Warning_Messages (L : List_Id) is
2383 if Is_Non_Empty_List (L) then
2385 while Present (Stat) loop
2386 Remove_Warning_Messages (Stat);
2390 end Remove_Warning_Messages;
2392 --------------------
2393 -- Reset_Warnings --
2394 --------------------
2396 procedure Reset_Warnings is
2398 Warnings_Treated_As_Errors := 0;
2399 Warnings_Detected := 0;
2401 Warnings_As_Errors_Count := 0;
2404 ----------------------
2405 -- Adjust_Name_Case --
2406 ----------------------
2408 procedure Adjust_Name_Case
2409 (Buf : in out Bounded_String;
2413 -- We have an all lower case name from Namet, and now we want to set
2414 -- the appropriate case. If possible we copy the actual casing from
2415 -- the source. If not we use standard identifier casing.
2418 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
2419 Sbuffer : Source_Buffer_Ptr;
2421 Src_Ptr : Source_Ptr;
2427 -- For standard locations, always use mixed case
2429 if Loc <= No_Location then
2430 Set_Casing (Mixed_Case);
2433 -- Determine if the reference we are dealing with corresponds to
2434 -- text at the point of the error reference. This will often be
2435 -- the case for simple identifier references, and is the case
2436 -- where we can copy the casing from the source.
2438 Sbuffer := Source_Text (Src_Ind);
2440 while Ref_Ptr <= Buf.Length loop
2442 Fold_Lower (Sbuffer (Src_Ptr)) /=
2443 Fold_Lower (Buf.Chars (Ref_Ptr));
2444 Ref_Ptr := Ref_Ptr + 1;
2445 Src_Ptr := Src_Ptr + 1;
2448 -- If we get through the loop without a mismatch, then output the
2449 -- name the way it is cased in the source program
2451 if Ref_Ptr > Buf.Length then
2454 for J in 1 .. Buf.Length loop
2455 Buf.Chars (J) := Sbuffer (Src_Ptr);
2456 Src_Ptr := Src_Ptr + 1;
2459 -- Otherwise set the casing using the default identifier casing
2462 Set_Casing (Buf, Identifier_Casing (Src_Ind));
2466 end Adjust_Name_Case;
2468 procedure Adjust_Name_Case (Loc : Source_Ptr) is
2470 Adjust_Name_Case (Global_Name_Buffer, Loc);
2471 end Adjust_Name_Case;
2473 ---------------------------
2474 -- Set_Identifier_Casing --
2475 ---------------------------
2477 procedure Set_Identifier_Casing
2478 (Identifier_Name : System.Address;
2479 File_Name : System.Address)
2481 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
2482 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
2485 Desired_Case : Casing_Type := Mixed_Case;
2486 -- Casing required for result. Default value of Mixed_Case is used if
2487 -- for some reason we cannot find the right file name in the table.
2490 -- Get length of file name
2493 while File (Flen + 1) /= ASCII.NUL loop
2497 -- Loop through file names to find matching one. This is a bit slow, but
2498 -- we only do it in error situations so it is not so terrible. Note that
2499 -- if the loop does not exit, then the desired case will be left set to
2500 -- Mixed_Case, this can happen if the name was not in canonical form.
2502 for J in 1 .. Last_Source_File loop
2503 Get_Name_String (Full_Debug_Name (J));
2506 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
2508 Desired_Case := Identifier_Casing (J);
2513 -- Copy identifier as given to Name_Buffer
2515 for J in Name_Buffer'Range loop
2516 Name_Buffer (J) := Ident (J);
2518 if Name_Buffer (J) = ASCII.NUL then
2524 Set_Casing (Desired_Case);
2525 end Set_Identifier_Casing;
2527 -----------------------
2528 -- Set_Ignore_Errors --
2529 -----------------------
2531 procedure Set_Ignore_Errors (To : Boolean) is
2533 Errors_Must_Be_Ignored := To;
2534 end Set_Ignore_Errors;
2536 ------------------------------
2537 -- Set_Msg_Insertion_Column --
2538 ------------------------------
2540 procedure Set_Msg_Insertion_Column is
2542 if RM_Column_Check then
2543 Set_Msg_Str (" in column ");
2544 Set_Msg_Int (Int (Error_Msg_Col) + 1);
2546 end Set_Msg_Insertion_Column;
2548 ----------------------------
2549 -- Set_Msg_Insertion_Node --
2550 ----------------------------
2552 procedure Set_Msg_Insertion_Node is
2557 Error_Msg_Node_1 = Error
2558 or else Error_Msg_Node_1 = Any_Type;
2560 if Error_Msg_Node_1 = Empty then
2561 Set_Msg_Blank_Conditional;
2562 Set_Msg_Str ("<empty>");
2564 elsif Error_Msg_Node_1 = Error then
2566 Set_Msg_Str ("<error>");
2568 elsif Error_Msg_Node_1 = Standard_Void_Type then
2570 Set_Msg_Str ("procedure name");
2572 elsif Nkind (Error_Msg_Node_1) in N_Entity
2573 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
2576 Set_Msg_Str ("access to subprogram");
2579 Set_Msg_Blank_Conditional;
2583 K := Nkind (Error_Msg_Node_1);
2585 -- If we have operator case, skip quotes since name of operator
2586 -- itself will supply the required quotations. An operator can be an
2587 -- applied use in an expression or an explicit operator symbol, or an
2588 -- identifier whose name indicates it is an operator.
2591 or else K = N_Operator_Symbol
2592 or else K = N_Defining_Operator_Symbol
2593 or else ((K = N_Identifier or else K = N_Defining_Identifier)
2594 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
2596 Set_Msg_Node (Error_Msg_Node_1);
2598 -- Normal case, not an operator, surround with quotes
2602 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
2603 Set_Msg_Node (Error_Msg_Node_1);
2608 -- The following assignment ensures that a second ampersand insertion
2609 -- character will correspond to the Error_Msg_Node_2 parameter. We
2610 -- suppress possible validity checks in case operating in -gnatVa mode,
2611 -- and Error_Msg_Node_2 is not needed and has not been set.
2614 pragma Suppress (Range_Check);
2616 Error_Msg_Node_1 := Error_Msg_Node_2;
2618 end Set_Msg_Insertion_Node;
2620 --------------------------------------
2621 -- Set_Msg_Insertion_Type_Reference --
2622 --------------------------------------
2624 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
2630 if Error_Msg_Node_1 = Standard_Void_Type then
2631 Set_Msg_Str ("package or procedure name");
2634 elsif Error_Msg_Node_1 = Standard_Exception_Type then
2635 Set_Msg_Str ("exception name");
2638 elsif Error_Msg_Node_1 = Any_Access
2639 or else Error_Msg_Node_1 = Any_Array
2640 or else Error_Msg_Node_1 = Any_Boolean
2641 or else Error_Msg_Node_1 = Any_Character
2642 or else Error_Msg_Node_1 = Any_Composite
2643 or else Error_Msg_Node_1 = Any_Discrete
2644 or else Error_Msg_Node_1 = Any_Fixed
2645 or else Error_Msg_Node_1 = Any_Integer
2646 or else Error_Msg_Node_1 = Any_Modular
2647 or else Error_Msg_Node_1 = Any_Numeric
2648 or else Error_Msg_Node_1 = Any_Real
2649 or else Error_Msg_Node_1 = Any_Scalar
2650 or else Error_Msg_Node_1 = Any_String
2652 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
2653 Set_Msg_Name_Buffer;
2656 elsif Error_Msg_Node_1 = Universal_Real then
2657 Set_Msg_Str ("type universal real");
2660 elsif Error_Msg_Node_1 = Universal_Integer then
2661 Set_Msg_Str ("type universal integer");
2664 elsif Error_Msg_Node_1 = Universal_Fixed then
2665 Set_Msg_Str ("type universal fixed");
2669 -- Special case of anonymous array
2671 if Nkind (Error_Msg_Node_1) in N_Entity
2672 and then Is_Array_Type (Error_Msg_Node_1)
2673 and then Present (Related_Array_Object (Error_Msg_Node_1))
2675 Set_Msg_Str ("type of ");
2676 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
2677 Set_Msg_Str (" declared");
2678 Set_Msg_Insertion_Line_Number
2679 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
2683 -- If we fall through, it is not a special case, so first output
2684 -- the name of the type, preceded by private for a private type
2686 if Is_Private_Type (Error_Msg_Node_1) then
2687 Set_Msg_Str ("private type ");
2689 Set_Msg_Str ("type ");
2692 Ent := Error_Msg_Node_1;
2694 if Is_Internal_Name (Chars (Ent)) then
2695 Unwind_Internal_Type (Ent);
2698 -- Types in Standard are displayed as "Standard.name"
2700 if Sloc (Ent) <= Standard_Location then
2702 Set_Msg_Str ("Standard.");
2707 -- Types in other language defined units are displayed as
2708 -- "package-name.type-name"
2710 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
2711 Get_Unqualified_Decoded_Name_String
2712 (Unit_Name (Get_Source_Unit (Ent)));
2713 Name_Len := Name_Len - 2;
2714 Set_Msg_Blank_Conditional;
2716 Set_Casing (Mixed_Case);
2717 Set_Msg_Name_Buffer;
2719 Set_Casing (Mixed_Case);
2724 -- All other types display as "type name" defined at line xxx
2725 -- possibly qualified if qualification is requested.
2729 Set_Qualification (Error_Msg_Qual_Level, Ent);
2733 -- If we did not print a name (e.g. in the case of an anonymous
2734 -- subprogram type), there is no name to print, so remove quotes.
2736 if Buffer_Ends_With ('"') then
2737 Buffer_Remove ('"');
2743 -- If the original type did not come from a predefined file, add the
2744 -- location where the type was defined.
2746 if Sloc (Error_Msg_Node_1) > Standard_Location
2748 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
2750 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
2751 Set_Msg_Str (" defined");
2752 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
2754 -- If it did come from a predefined file, deal with the case where
2755 -- this was a file with a generic instantiation from elsewhere.
2758 if Sloc (Error_Msg_Node_1) > Standard_Location then
2760 Iloc : constant Source_Ptr :=
2761 Instantiation_Location (Sloc (Error_Msg_Node_1));
2764 if Iloc /= No_Location
2765 and then not Suppress_Instance_Location
2767 Set_Msg_Str (" from instance");
2768 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2773 end Set_Msg_Insertion_Type_Reference;
2775 ---------------------------------
2776 -- Set_Msg_Insertion_Unit_Name --
2777 ---------------------------------
2779 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
2781 if Error_Msg_Unit_1 = No_Unit_Name then
2784 elsif Error_Msg_Unit_1 = Error_Unit_Name then
2786 Set_Msg_Str ("<error>");
2789 Get_Unit_Name_String (Error_Msg_Unit_1, Suffix);
2792 Set_Msg_Name_Buffer;
2796 -- The following assignment ensures that a second percent insertion
2797 -- character will correspond to the Error_Msg_Unit_2 parameter. We
2798 -- suppress possible validity checks in case operating in -gnatVa mode,
2799 -- and Error_Msg_Unit_2 is not needed and has not been set.
2802 pragma Suppress (Range_Check);
2804 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2806 end Set_Msg_Insertion_Unit_Name;
2812 procedure Set_Msg_Node (Node : Node_Id) is
2818 case Nkind (Node) is
2819 when N_Designator =>
2820 Set_Msg_Node (Name (Node));
2822 Set_Msg_Node (Identifier (Node));
2825 when N_Defining_Program_Unit_Name =>
2826 Set_Msg_Node (Name (Node));
2828 Set_Msg_Node (Defining_Identifier (Node));
2831 when N_Expanded_Name
2832 | N_Selected_Component
2834 Set_Msg_Node (Prefix (Node));
2836 Set_Msg_Node (Selector_Name (Node));
2843 -- The only remaining possibilities are identifiers, defining
2844 -- identifiers, pragmas, and pragma argument associations.
2846 if Nkind (Node) = N_Pragma then
2847 Nam := Pragma_Name (Node);
2850 -- The other cases have Chars fields
2852 -- First deal with internal names, which generally represent something
2853 -- gone wrong. First attempt: if this is a rewritten node that rewrites
2854 -- something with a Chars field that is not an internal name, use that.
2856 elsif Is_Internal_Name (Chars (Node))
2857 and then Nkind (Original_Node (Node)) in N_Has_Chars
2858 and then not Is_Internal_Name (Chars (Original_Node (Node)))
2860 Nam := Chars (Original_Node (Node));
2861 Loc := Sloc (Original_Node (Node));
2863 -- Another shot for internal names, in the case of internal type names,
2864 -- we try to find a reasonable representation for the external name.
2866 elsif Is_Internal_Name (Chars (Node))
2868 ((Is_Entity_Name (Node)
2869 and then Present (Entity (Node))
2870 and then Is_Type (Entity (Node)))
2872 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2874 if Nkind (Node) = N_Identifier then
2875 Ent := Entity (Node);
2882 -- If the type is the designated type of an access_to_subprogram,
2883 -- then there is no name to provide in the call.
2885 if Ekind (Ent) = E_Subprogram_Type then
2888 -- Otherwise, we will be able to find some kind of name to output
2891 Unwind_Internal_Type (Ent);
2895 -- If not internal name, or if we could not find a reasonable possible
2896 -- substitution for the internal name, just use name in Chars field.
2899 Nam := Chars (Node);
2903 -- At this stage, the name to output is in Nam
2905 Get_Unqualified_Decoded_Name_String (Nam);
2907 -- Remove trailing upper case letters from the name (useful for
2908 -- dealing with some cases of internal names).
2910 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
2911 Name_Len := Name_Len - 1;
2914 -- If we have any of the names from standard that start with the
2915 -- characters "any " (e.g. Any_Type), then kill the message since
2916 -- almost certainly it is a junk cascaded message.
2919 and then Name_Buffer (1 .. 4) = "any "
2921 Kill_Message := True;
2924 -- If we still have an internal name, kill the message (will only
2925 -- work if we already had errors!)
2927 if Is_Internal_Name then
2928 Kill_Message := True;
2930 -- Remaining step is to adjust casing and possibly add 'Class
2932 Adjust_Name_Case (Global_Name_Buffer, Loc);
2933 Set_Msg_Name_Buffer;
2941 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2942 C : Character; -- Current character
2943 P : Natural; -- Current index;
2945 procedure Skip_Msg_Insertion_Warning (C : Character);
2946 -- Deal with ? ?? ?x? ?X? ?*? ?$? insertion sequences (and the same
2947 -- sequences using < instead of ?). The caller has already bumped
2948 -- the pointer past the initial ? or < and C is set to this initial
2949 -- character (? or <). This procedure skips past the rest of the
2950 -- sequence. We do not need to set Msg_Insertion_Char, since this
2951 -- was already done during the message prescan.
2953 --------------------------------
2954 -- Skip_Msg_Insertion_Warning --
2955 --------------------------------
2957 procedure Skip_Msg_Insertion_Warning (C : Character) is
2959 if P <= Text'Last and then Text (P) = C then
2962 elsif P + 1 <= Text'Last
2963 and then (Text (P) in 'a' .. 'z'
2965 Text (P) in 'A' .. 'Z'
2970 and then Text (P + 1) = C
2974 end Skip_Msg_Insertion_Warning;
2976 -- Start of processing for Set_Msg_Text
2979 Manual_Quote_Mode := False;
2981 Flag_Source := Get_Source_File_Index (Flag);
2983 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
2984 -- will be used (Info field in error message object) to put back the
2985 -- string when it is printed. We need to do this, or we get confused
2986 -- with instantiation continuations.
2989 and then Text (Text'First .. Text'First + 5) = "info: "
2991 P := Text'First + 6;
2996 -- Loop through characters of message
2998 while P <= Text'Last loop
3002 -- Check for insertion character or sequence
3006 if P <= Text'Last and then Text (P) = '%' then
3008 Set_Msg_Insertion_Name_Literal;
3010 Set_Msg_Insertion_Name;
3014 if P <= Text'Last and then Text (P) = '$' then
3016 Set_Msg_Insertion_Unit_Name (Suffix => False);
3018 Set_Msg_Insertion_Unit_Name;
3022 Set_Msg_Insertion_File_Name;
3025 Set_Msg_Insertion_Type_Reference (Flag);
3028 Set_Msg_Insertion_Reserved_Name;
3031 Set_Msg_Insertion_Node;
3034 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
3037 Continuation := True;
3039 if P <= Text'Last and then Text (P) = '\' then
3040 Continuation_New_Line := True;
3045 Set_Msg_Insertion_Column;
3048 Set_Msg_Insertion_Run_Time_Name;
3051 Set_Msg_Insertion_Uint;
3054 Manual_Quote_Mode := not Manual_Quote_Mode;
3058 null; -- already dealt with
3061 Skip_Msg_Insertion_Warning ('?');
3064 Skip_Msg_Insertion_Warning ('<');
3067 null; -- already dealt with
3070 Set_Msg_Char (Text (P));
3074 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
3076 -- Upper case letter
3080 -- Start of reserved word if two or more
3082 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
3084 Set_Msg_Insertion_Reserved_Word (Text, P);
3086 -- Single upper case letter is just inserted
3092 -- '[' (will be/would have been raised at run time)
3095 if Is_Warning_Msg then
3096 Set_Msg_Str ("will be raised at run time");
3098 Set_Msg_Str ("would have been raised at run time");
3101 -- ']' (may be/might have been raised at run time)
3104 if Is_Warning_Msg then
3105 Set_Msg_Str ("may be raised at run time");
3107 Set_Msg_Str ("might have been raised at run time");
3110 -- Normal character with no special treatment
3122 procedure Set_Posted (N : Node_Id) is
3126 if Is_Serious_Error then
3128 -- We always set Error_Posted on the node itself
3130 Set_Error_Posted (N);
3132 -- If it is a subexpression, then set Error_Posted on parents up to
3133 -- and including the first non-subexpression construct. This helps
3134 -- avoid cascaded error messages within a single expression.
3140 Set_Error_Posted (P);
3141 exit when Nkind (P) not in N_Subexpr;
3144 if Nkind_In (P, N_Pragma_Argument_Association,
3145 N_Component_Association,
3146 N_Discriminant_Association,
3147 N_Generic_Association,
3148 N_Parameter_Association)
3150 Set_Error_Posted (Parent (P));
3153 -- A special check, if we just posted an error on an attribute
3154 -- definition clause, then also set the entity involved as posted.
3155 -- For example, this stops complaining about the alignment after
3156 -- complaining about the size, which is likely to be useless.
3158 if Nkind (P) = N_Attribute_Definition_Clause then
3159 if Is_Entity_Name (Name (P)) then
3160 Set_Error_Posted (Entity (Name (P)));
3166 -----------------------
3167 -- Set_Qualification --
3168 -----------------------
3170 procedure Set_Qualification (N : Nat; E : Entity_Id) is
3172 if N /= 0 and then Scope (E) /= Standard_Standard then
3173 Set_Qualification (N - 1, Scope (E));
3174 Set_Msg_Node (Scope (E));
3177 end Set_Qualification;
3179 ------------------------
3180 -- Special_Msg_Delete --
3181 ------------------------
3183 -- Is it really right to have all this specialized knowledge in errout?
3185 function Special_Msg_Delete
3187 N : Node_Or_Entity_Id;
3188 E : Node_Or_Entity_Id) return Boolean
3191 -- Never delete messages in -gnatdO mode
3193 if Debug_Flag_OO then
3196 -- Processing for "atomic access cannot be guaranteed"
3198 elsif Msg = "atomic access to & cannot be guaranteed" then
3200 -- When an atomic object refers to a non-atomic type in the same
3201 -- scope, we implicitly make the type atomic. In the non-error case
3202 -- this is surely safe (and in fact prevents an error from occurring
3203 -- if the type is not atomic by default). But if the object cannot be
3204 -- made atomic, then we introduce an extra junk message by this
3205 -- manipulation, which we get rid of here.
3207 -- We identify this case by the fact that it references a type for
3208 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
3211 and then Is_Atomic (E)
3212 and then No (Get_Rep_Pragma (E, Name_Atomic))
3217 -- Similar processing for "volatile full access cannot be guaranteed"
3219 elsif Msg = "volatile full access to & cannot be guaranteed" then
3221 and then Is_Volatile_Full_Access (E)
3222 and then No (Get_Rep_Pragma (E, Name_Volatile_Full_Access))
3227 -- Processing for "Size too small" messages
3229 elsif Msg = "size for& too small, minimum allowed is ^" then
3231 -- Suppress "size too small" errors in CodePeer mode, since code may
3232 -- be analyzed in a different configuration than the one used for
3233 -- compilation. Even when the configurations match, this message
3234 -- may be issued on correct code, because pragma Pack is ignored
3235 -- in CodePeer mode.
3237 if CodePeer_Mode then
3240 -- When a size is wrong for a frozen type there is no explicit size
3241 -- clause, and other errors have occurred, suppress the message,
3242 -- since it is likely that this size error is a cascaded result of
3243 -- other errors. The reason we eliminate unfrozen types is that
3244 -- messages issued before the freeze type are for sure OK.
3247 and then Serious_Errors_Detected > 0
3248 and then Nkind (N) /= N_Component_Clause
3249 and then Nkind (Parent (N)) /= N_Component_Clause
3251 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
3253 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
3255 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
3261 -- All special tests complete, so go ahead with message
3264 end Special_Msg_Delete;
3270 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
3272 if SPARK_Mode /= Off then
3273 Error_Msg_N (Msg, N);
3281 procedure SPARK_Msg_NE
3283 N : Node_Or_Entity_Id;
3284 E : Node_Or_Entity_Id)
3287 if SPARK_Mode /= Off then
3288 Error_Msg_NE (Msg, N, E);
3292 --------------------------
3293 -- Unwind_Internal_Type --
3294 --------------------------
3296 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
3297 Derived : Boolean := False;
3299 Old_Ent : Entity_Id;
3302 -- Undo placement of a quote, since we will put it back later
3304 Mchar := Msg_Buffer (Msglen);
3307 Msglen := Msglen - 1;
3310 -- The loop here deals with recursive types, we are trying to find a
3311 -- related entity that is not an implicit type. Note that the check with
3312 -- Old_Ent stops us from getting "stuck". Also, we don't output the
3313 -- "type derived from" message more than once in the case where we climb
3314 -- up multiple levels.
3319 -- Implicit access type, use directly designated type In Ada 2005,
3320 -- the designated type may be an anonymous access to subprogram, in
3321 -- which case we can only point to its definition.
3323 if Is_Access_Type (Ent) then
3324 if Ekind (Ent) = E_Access_Subprogram_Type
3325 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
3326 or else Is_Access_Protected_Subprogram_Type (Ent)
3328 Ent := Directly_Designated_Type (Ent);
3330 if not Comes_From_Source (Ent) then
3331 if Buffer_Ends_With ("type ") then
3332 Buffer_Remove ("type ");
3336 if Ekind (Ent) = E_Function then
3337 Set_Msg_Str ("access to function ");
3338 elsif Ekind (Ent) = E_Procedure then
3339 Set_Msg_Str ("access to procedure ");
3341 Set_Msg_Str ("access to subprogram");
3346 -- Type is access to object, named or anonymous
3349 Set_Msg_Str ("access to ");
3350 Ent := Directly_Designated_Type (Ent);
3355 elsif Is_Class_Wide_Type (Ent) then
3357 Ent := Root_Type (Ent);
3359 -- Use base type if this is a subtype
3361 elsif Ent /= Base_Type (Ent) then
3362 Buffer_Remove ("type ");
3364 -- Avoid duplication "subtype of subtype of", and also replace
3365 -- "derived from subtype of" simply by "derived from"
3367 if not Buffer_Ends_With ("subtype of ")
3368 and then not Buffer_Ends_With ("derived from ")
3370 Set_Msg_Str ("subtype of ");
3373 Ent := Base_Type (Ent);
3375 -- If this is a base type with a first named subtype, use the first
3376 -- named subtype instead. This is not quite accurate in all cases,
3377 -- but it makes too much noise to be accurate and add 'Base in all
3378 -- cases. Note that we only do this is the first named subtype is not
3379 -- itself an internal name. This avoids the obvious loop (subtype ->
3380 -- basetype -> subtype) which would otherwise occur).
3384 FST : constant Entity_Id := First_Subtype (Ent);
3387 if not Is_Internal_Name (Chars (FST)) then
3391 -- Otherwise use root type
3395 Buffer_Remove ("type ");
3397 -- Test for "subtype of type derived from" which seems
3398 -- excessive and is replaced by "type derived from".
3400 Buffer_Remove ("subtype of");
3402 -- Avoid duplicated "type derived from type derived from"
3404 if not Buffer_Ends_With ("type derived from ") then
3405 Set_Msg_Str ("type derived from ");
3416 -- If we are stuck in a loop, get out and settle for the internal
3417 -- name after all. In this case we set to kill the message if it is
3418 -- not the first error message (we really try hard not to show the
3419 -- dirty laundry of the implementation to the poor user).
3421 if Ent = Old_Ent then
3422 Kill_Message := True;
3426 -- Get out if we finally found a non-internal name to use
3428 exit Find when not Is_Internal_Name (Chars (Ent));
3434 end Unwind_Internal_Type;
3436 --------------------
3437 -- Warn_Insertion --
3438 --------------------
3440 function Warn_Insertion return String is
3442 case Warning_Msg_Char is
3446 when 'a' .. 'z' | 'A' .. 'Z' | '*' | '$' =>
3447 return '?' & Warning_Msg_Char & '?';
3453 raise Program_Error;