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 Warning_Info_Messages := Warning_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).
313 Entity : Bounded_String;
316 -- Return if all errors are to be ignored
318 if Errors_Must_Be_Ignored then
322 -- If we already have messages, and we are trying to place a message at
323 -- No_Location, then just ignore the attempt since we assume that what
324 -- is happening is some cascaded junk. Note that this is safe in the
325 -- sense that proceeding will surely bomb. We will also bomb if the flag
326 -- location is No_Location and we don't have any messages so far, but
327 -- that is a real bug and a legitimate bomb, so we go ahead.
329 if Flag_Location = No_Location
330 and then Total_Errors_Detected > 0
335 -- Start of processing for new message
337 Sindex := Get_Source_File_Index (Flag_Location);
338 Prescan_Message (Msg);
339 Orig_Loc := Original_Location (Flag_Location);
341 if Include_Subprogram_In_Messages then
343 Ent : constant Entity_Id := Current_Subprogram_Ptr.all;
345 if Present (Ent) then
346 Append_Unqualified_Decoded (Entity, Chars (Ent));
348 Append (Entity, "unknown subprogram");
353 -- If the current location is in an instantiation, the issue arises of
354 -- whether to post the message on the template or the instantiation.
356 -- The way we decide is to see if we have posted the same message on
357 -- the template when we compiled the template (the template is always
358 -- compiled before any instantiations). For this purpose, we use a
359 -- separate table of messages. The reason we do this is twofold:
361 -- First, the messages can get changed by various processing
362 -- including the insertion of tokens etc, making it hard to
363 -- do the comparison.
365 -- Second, we will suppress a warning on a template if it is not in
366 -- the current extended source unit. That's reasonable and means we
367 -- don't want the warning on the instantiation here either, but it
368 -- does mean that the main error table would not in any case include
371 if Flag_Location = Orig_Loc then
372 Non_Instance_Msgs.Append ((new String'(Msg), Flag_Location));
373 Warn_On_Instance := False;
375 -- Here we have an instance message
378 -- Delete if debug flag off, and this message duplicates a message
379 -- already posted on the corresponding template
381 if not Debug_Flag_GG then
382 for J in Non_Instance_Msgs.First .. Non_Instance_Msgs.Last loop
383 if Msg = Non_Instance_Msgs.Table (J).Msg.all
384 and then Non_Instance_Msgs.Table (J).Loc = Orig_Loc
391 -- No duplicate, so error/warning will be posted on instance
393 Warn_On_Instance := Is_Warning_Msg;
396 -- Ignore warning message that is suppressed for this location. Note
397 -- that style checks are not considered warning messages for this
400 if Is_Warning_Msg and then Warnings_Suppressed (Orig_Loc) /= No_String
404 -- For style messages, check too many messages so far
407 and then Maximum_Messages /= 0
408 and then Warnings_Detected >= Maximum_Messages
413 -- The idea at this stage is that we have two kinds of messages
415 -- First, we have those messages that are to be placed as requested at
416 -- Flag_Location. This includes messages that have nothing to do with
417 -- generics, and also messages placed on generic templates that reflect
418 -- an error in the template itself. For such messages we simply call
419 -- Error_Msg_Internal to place the message in the requested location.
421 if Instantiation (Sindex) = No_Location then
422 if Include_Subprogram_In_Messages then
423 Append (Entity, ": ");
424 Append (Entity, Msg);
425 Error_Msg_Internal (+Entity, Flag_Location, Flag_Location, False);
427 Error_Msg_Internal (Msg, Flag_Location, Flag_Location, False);
433 -- If we are trying to flag an error in an instantiation, we may have
434 -- a generic contract violation. What we generate in this case is:
436 -- instantiation error at ...
437 -- original error message
441 -- warning: in instantiation at ...
442 -- warning: original warning message
446 -- info: in instantiation at ...
447 -- info: original info message
449 -- All these messages are posted at the location of the top level
450 -- instantiation. If there are nested instantiations, then the
451 -- instantiation error message can be repeated, pointing to each
452 -- of the relevant instantiations.
454 -- Note: the instantiation mechanism is also shared for inlining of
455 -- subprogram bodies when front end inlining is done. In this case the
456 -- messages have the form:
458 -- in inlined body at ...
459 -- original error message
463 -- warning: in inlined body at ...
464 -- warning: original warning message
468 -- info: in inlined body at ...
469 -- info: original info message
471 -- OK, here we have an instantiation error, and we need to generate the
472 -- error on the instantiation, rather than on the template.
475 Actual_Error_Loc : Source_Ptr;
476 -- Location of outer level instantiation in instantiation case, or
477 -- just a copy of Flag_Location in the normal case. This is the
478 -- location where all error messages will actually be posted.
480 Save_Error_Msg_Sloc : constant Source_Ptr := Error_Msg_Sloc;
481 -- Save possible location set for caller's message. We need to use
482 -- Error_Msg_Sloc for the location of the instantiation error but we
483 -- have to preserve a possible original value.
485 X : Source_File_Index;
487 Msg_Cont_Status : Boolean;
488 -- Used to label continuation lines in instantiation case with
489 -- proper Msg_Cont status.
492 -- Loop to find highest level instantiation, where all error
493 -- messages will be placed.
497 Actual_Error_Loc := Instantiation (X);
498 X := Get_Source_File_Index (Actual_Error_Loc);
499 exit when Instantiation (X) = No_Location;
502 -- Since we are generating the messages at the instantiation point in
503 -- any case, we do not want the references to the bad lines in the
504 -- instance to be annotated with the location of the instantiation.
506 Suppress_Instance_Location := True;
507 Msg_Cont_Status := False;
509 -- Loop to generate instantiation messages
511 Error_Msg_Sloc := Flag_Location;
512 X := Get_Source_File_Index (Flag_Location);
513 while Instantiation (X) /= No_Location loop
515 -- Suppress instantiation message on continuation lines
517 if Msg (Msg'First) /= '\' then
519 -- Case of inlined body
521 if Inlined_Body (X) then
524 ("info: in inlined body #",
525 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
527 elsif Is_Warning_Msg then
529 (Warn_Insertion & "in inlined body #",
530 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
532 elsif Is_Style_Msg then
534 ("style: in inlined body #",
535 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
539 ("error in inlined body #",
540 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
543 -- Case of generic instantiation
548 ("info: in instantiation #",
549 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
551 elsif Is_Warning_Msg then
553 (Warn_Insertion & "in instantiation #",
554 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
556 elsif Is_Style_Msg then
558 ("style: in instantiation #",
559 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
563 ("instantiation error #",
564 Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
569 Error_Msg_Sloc := Instantiation (X);
570 X := Get_Source_File_Index (Error_Msg_Sloc);
571 Msg_Cont_Status := True;
574 Suppress_Instance_Location := False;
575 Error_Msg_Sloc := Save_Error_Msg_Sloc;
577 -- Here we output the original message on the outer instantiation
579 if Include_Subprogram_In_Messages then
580 Append (Entity, ": ");
581 Append (Entity, Msg);
583 (+Entity, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
586 (Msg, Actual_Error_Loc, Flag_Location, Msg_Cont_Status);
591 --------------------------------
592 -- Error_Msg_Ada_2012_Feature --
593 --------------------------------
595 procedure Error_Msg_Ada_2012_Feature (Feature : String; Loc : Source_Ptr) is
597 if Ada_Version < Ada_2012 then
598 Error_Msg (Feature & " is an Ada 2012 feature", Loc);
600 if No (Ada_Version_Pragma) then
601 Error_Msg ("\unit must be compiled with -gnat2012 switch", Loc);
603 Error_Msg_Sloc := Sloc (Ada_Version_Pragma);
604 Error_Msg ("\incompatible with Ada version set#", Loc);
607 end Error_Msg_Ada_2012_Feature;
613 procedure Error_Msg_AP (Msg : String) is
618 -- If we had saved the Scan_Ptr value after scanning the previous
619 -- token, then we would have exactly the right place for putting
620 -- the flag immediately at hand. However, that would add at least
621 -- two instructions to a Scan call *just* to service the possibility
622 -- of an Error_Msg_AP call. So instead we reconstruct that value.
624 -- We have two possibilities, start with Prev_Token_Ptr and skip over
625 -- the current token, which is made harder by the possibility that this
626 -- token may be in error, or start with Token_Ptr and work backwards.
627 -- We used to take the second approach, but it's hard because of
628 -- comments, and harder still because things that look like comments
629 -- can appear inside strings. So now we take the first approach.
631 -- Note: in the case where there is no previous token, Prev_Token_Ptr
632 -- is set to Source_First, which is a reasonable position for the
633 -- error flag in this situation.
635 S1 := Prev_Token_Ptr;
638 -- If the previous token is a string literal, we need a special approach
639 -- since there may be white space inside the literal and we don't want
640 -- to stop on that white space.
642 -- Note: since this is an error recovery issue anyway, it is not worth
643 -- worrying about special UTF_32 line terminator characters here.
645 if Prev_Token = Tok_String_Literal then
649 if Source (S1) = C then
651 exit when Source (S1) /= C;
652 elsif Source (S1) in Line_Terminator then
657 -- Character literal also needs special handling
659 elsif Prev_Token = Tok_Char_Literal then
662 -- Otherwise we search forward for the end of the current token, marked
663 -- by a line terminator, white space, a comment symbol or if we bump
664 -- into the following token (i.e. the current token).
666 -- Again, it is not worth worrying about UTF_32 special line terminator
667 -- characters in this context, since this is only for error recovery.
670 while Source (S1) not in Line_Terminator
671 and then Source (S1) /= ' '
672 and then Source (S1) /= ASCII.HT
673 and then (Source (S1) /= '-' or else Source (S1 + 1) /= '-')
674 and then S1 /= Token_Ptr
680 -- S1 is now set to the location for the flag
689 procedure Error_Msg_BC (Msg : String) is
691 -- If we are at end of file, post the flag after the previous token
693 if Token = Tok_EOF then
696 -- If we are at start of file, post the flag at the current token
698 elsif Token_Ptr = Source_First (Current_Source_File) then
701 -- If the character before the current token is a space or a horizontal
702 -- tab, then we place the flag on this character (in the case of a tab
703 -- we would really like to place it in the "last" character of the tab
704 -- space, but that it too much trouble to worry about).
706 elsif Source (Token_Ptr - 1) = ' '
707 or else Source (Token_Ptr - 1) = ASCII.HT
709 Error_Msg (Msg, Token_Ptr - 1);
711 -- If there is no space or tab before the current token, then there is
712 -- no room to place the flag before the token, so we place it on the
713 -- token instead (this happens for example at the start of a line).
716 Error_Msg (Msg, Token_Ptr);
724 procedure Error_Msg_CRT (Feature : String; N : Node_Id) is
725 CNRT : constant String := " not allowed in no run time mode";
726 CCRT : constant String := " not supported by configuration>";
728 S : String (1 .. Feature'Length + 1 + CCRT'Length);
733 S (2 .. Feature'Length + 1) := Feature;
734 L := Feature'Length + 2;
736 if No_Run_Time_Mode then
737 S (L .. L + CNRT'Length - 1) := CNRT;
738 L := L + CNRT'Length - 1;
740 else pragma Assert (Configurable_Run_Time_Mode);
741 S (L .. L + CCRT'Length - 1) := CCRT;
742 L := L + CCRT'Length - 1;
745 Error_Msg_N (S (1 .. L), N);
746 Configurable_Run_Time_Violations := Configurable_Run_Time_Violations + 1;
753 procedure Error_Msg_PT (E : Entity_Id; Iface_Prim : Entity_Id) is
756 ("illegal overriding of subprogram inherited from interface", E);
758 Error_Msg_Sloc := Sloc (Iface_Prim);
760 if Ekind (E) = E_Function then
762 ("\first formal of & declared # must be of mode `IN` "
763 & "or access-to-constant", E);
766 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
767 & "or access-to-variable", E);
775 procedure Error_Msg_F (Msg : String; N : Node_Id) is
777 Error_Msg_NEL (Msg, N, N, Sloc (First_Node (N)));
784 procedure Error_Msg_FE
787 E : Node_Or_Entity_Id)
790 Error_Msg_NEL (Msg, N, E, Sloc (First_Node (N)));
793 ------------------------
794 -- Error_Msg_Internal --
795 ------------------------
797 procedure Error_Msg_Internal
803 Next_Msg : Error_Msg_Id;
804 -- Pointer to next message at insertion point
806 Prev_Msg : Error_Msg_Id;
807 -- Pointer to previous message at insertion point
809 Temp_Msg : Error_Msg_Id;
812 -- Set if warning to be treated as error
814 procedure Handle_Serious_Error;
815 -- Internal procedure to do all error message handling for a serious
816 -- error message, other than bumping the error counts and arranging
817 -- for the message to be output.
819 --------------------------
820 -- Handle_Serious_Error --
821 --------------------------
823 procedure Handle_Serious_Error is
825 -- Turn off code generation if not done already
827 if Operating_Mode = Generate_Code then
828 Operating_Mode := Check_Semantics;
829 Expander_Active := False;
832 -- Set the fatal error flag in the unit table unless we are in
833 -- Try_Semantics mode (in which case we set ignored mode if not
834 -- currently set. This stops the semantics from being performed
835 -- if we find a serious error. This is skipped if we are currently
836 -- dealing with the configuration pragma file.
838 if Current_Source_Unit /= No_Unit then
840 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
842 if Try_Semantics then
843 if Fatal_Error (U) = None then
844 Set_Fatal_Error (U, Error_Ignored);
847 Set_Fatal_Error (U, Error_Detected);
851 end Handle_Serious_Error;
853 -- Start of processing for Error_Msg_Internal
856 if Raise_Exception_On_Error /= 0 then
857 raise Error_Msg_Exception;
860 Continuation := Msg_Cont;
861 Continuation_New_Line := False;
862 Suppress_Message := False;
863 Kill_Message := False;
864 Set_Msg_Text (Msg, Sptr);
866 -- Kill continuation if parent message killed
868 if Continuation and Last_Killed then
872 -- Return without doing anything if message is suppressed
875 and then not All_Errors_Mode
876 and then not Is_Warning_Msg
877 and then not Is_Unconditional_Msg
879 if not Continuation then
886 -- Return without doing anything if message is killed and this is not
887 -- the first error message. The philosophy is that if we get a weird
888 -- error message and we already have had a message, then we hope the
889 -- weird message is a junk cascaded message
892 and then not All_Errors_Mode
893 and then Total_Errors_Detected /= 0
895 if not Continuation then
902 -- Special check for warning message to see if it should be output
904 if Is_Warning_Msg then
906 -- Immediate return if warning message and warnings are suppressed
908 if Warnings_Suppressed (Optr) /= No_String
910 Warnings_Suppressed (Sptr) /= No_String
912 Cur_Msg := No_Error_Msg;
916 -- If the flag location is in the main extended source unit then for
917 -- sure we want the warning since it definitely belongs
919 if In_Extended_Main_Source_Unit (Sptr) then
922 -- If the main unit has not been read yet. the warning must be on
923 -- a configuration file: gnat.adc or user-defined. This means we
924 -- are not parsing the main unit yet, so skip following checks.
926 elsif No (Cunit (Main_Unit)) then
929 -- If the flag location is not in the main extended source unit, then
930 -- we want to eliminate the warning, unless it is in the extended
931 -- main code unit and we want warnings on the instance.
933 elsif In_Extended_Main_Code_Unit (Sptr) and then Warn_On_Instance then
936 -- Keep warning if debug flag G set
938 elsif Debug_Flag_GG then
941 -- Keep warning if message text contains !!
943 elsif Has_Double_Exclam then
946 -- Here is where we delete a warning from a with'ed unit
949 Cur_Msg := No_Error_Msg;
951 if not Continuation then
959 -- If message is to be ignored in special ignore message mode, this is
960 -- where we do this special processing, bypassing message output.
962 if Ignore_Errors_Enable > 0 then
963 if Is_Serious_Error then
964 Handle_Serious_Error;
970 -- If error message line length set, and this is a continuation message
971 -- then all we do is to append the text to the text of the last message
972 -- with a comma space separator (eliminating a possible (style) or
975 if Error_Msg_Line_Length /= 0 and then Continuation then
976 Cur_Msg := Errors.Last;
979 Oldm : String_Ptr := Errors.Table (Cur_Msg).Text;
980 Newm : String (1 .. Oldm'Last + 2 + Msglen);
985 -- First copy old message to new one and free it
987 Newm (Oldm'Range) := Oldm.all;
991 -- Remove (style) or info: at start of message
993 if Msglen > 8 and then Msg_Buffer (1 .. 8) = "(style) " then
996 elsif Msglen > 6 and then Msg_Buffer (1 .. 6) = "info: " then
1003 -- Now deal with separation between messages. Normally this is
1004 -- simply comma space, but there are some special cases.
1006 -- If continuation new line, then put actual NL character in msg
1008 if Continuation_New_Line then
1010 Newm (Newl) := ASCII.LF;
1012 -- If continuation message is enclosed in parentheses, then
1013 -- special treatment (don't need a comma, and we want to combine
1014 -- successive parenthetical remarks into a single one with
1015 -- separating commas).
1017 elsif Msg_Buffer (M) = '(' and then Msg_Buffer (Msglen) = ')' then
1019 -- Case where existing message ends in right paren, remove
1020 -- and separate parenthetical remarks with a comma.
1022 if Newm (Newl) = ')' then
1024 Msg_Buffer (M) := ' ';
1026 -- Case where we are adding new parenthetical comment
1033 -- Case where continuation not in parens and no new line
1036 Newm (Newl + 1 .. Newl + 2) := ", ";
1040 -- Append new message
1042 Newm (Newl + 1 .. Newl + Msglen - M + 1) :=
1043 Msg_Buffer (M .. Msglen);
1044 Newl := Newl + Msglen - M + 1;
1045 Errors.Table (Cur_Msg).Text := new String'(Newm (1 .. Newl));
1047 -- Update warning msg flag and message doc char if needed
1049 if Is_Warning_Msg then
1050 if not Errors.Table (Cur_Msg).Warn then
1051 Errors.Table (Cur_Msg).Warn := True;
1052 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1054 elsif Warning_Msg_Char /= ' ' then
1055 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1063 -- Here we build a new error object
1066 ((Text => new String'(Msg_Buffer (1 .. Msglen)),
1067 Next => No_Error_Msg,
1068 Prev => No_Error_Msg,
1071 Sfile => Get_Source_File_Index (Sptr),
1072 Line => Get_Physical_Line_Number (Sptr),
1073 Col => Get_Column_Number (Sptr),
1074 Warn => Is_Warning_Msg,
1075 Info => Is_Info_Msg,
1076 Check => Is_Check_Msg,
1077 Warn_Err => False, -- reset below
1078 Warn_Chr => Warning_Msg_Char,
1079 Style => Is_Style_Msg,
1080 Serious => Is_Serious_Error,
1081 Uncond => Is_Unconditional_Msg,
1082 Msg_Cont => Continuation,
1084 Cur_Msg := Errors.Last;
1086 -- Test if warning to be treated as error
1090 and then (Warning_Treated_As_Error (Msg_Buffer (1 .. Msglen))
1092 Warning_Treated_As_Error (Get_Warning_Tag (Cur_Msg)));
1094 -- Propagate Warn_Err to this message and preceding continuations
1096 for J in reverse 1 .. Errors.Last loop
1097 Errors.Table (J).Warn_Err := Warn_Err;
1098 exit when not Errors.Table (J).Msg_Cont;
1101 -- If immediate errors mode set, output error message now. Also output
1102 -- now if the -d1 debug flag is set (so node number message comes out
1103 -- just before actual error message)
1105 if Debug_Flag_OO or else Debug_Flag_1 then
1108 (Errors.Table (Cur_Msg).Line, Errors.Table (Cur_Msg).Sfile, True);
1109 Temp_Msg := Cur_Msg;
1110 Output_Error_Msgs (Temp_Msg);
1112 -- If not in immediate errors mode, then we insert the message in the
1113 -- error chain for later output by Finalize. The messages are sorted
1114 -- first by unit (main unit comes first), and within a unit by source
1115 -- location (earlier flag location first in the chain).
1118 -- First a quick check, does this belong at the very end of the chain
1119 -- of error messages. This saves a lot of time in the normal case if
1120 -- there are lots of messages.
1122 if Last_Error_Msg /= No_Error_Msg
1123 and then Errors.Table (Cur_Msg).Sfile =
1124 Errors.Table (Last_Error_Msg).Sfile
1125 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
1127 (Sptr = Errors.Table (Last_Error_Msg).Sptr
1129 Optr > Errors.Table (Last_Error_Msg).Optr))
1131 Prev_Msg := Last_Error_Msg;
1132 Next_Msg := No_Error_Msg;
1134 -- Otherwise do a full sequential search for the insertion point
1137 Prev_Msg := No_Error_Msg;
1138 Next_Msg := First_Error_Msg;
1139 while Next_Msg /= No_Error_Msg loop
1141 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
1143 if Errors.Table (Cur_Msg).Sfile = Errors.Table (Next_Msg).Sfile
1145 exit when Sptr < Errors.Table (Next_Msg).Sptr
1146 or else (Sptr = Errors.Table (Next_Msg).Sptr
1147 and then Optr < Errors.Table (Next_Msg).Optr);
1150 Prev_Msg := Next_Msg;
1151 Next_Msg := Errors.Table (Next_Msg).Next;
1155 -- Now we insert the new message in the error chain.
1157 -- The possible insertion point for the new message is after Prev_Msg
1158 -- and before Next_Msg. However, this is where we do a special check
1159 -- for redundant parsing messages, defined as messages posted on the
1160 -- same line. The idea here is that probably such messages are junk
1161 -- from the parser recovering. In full errors mode, we don't do this
1162 -- deletion, but otherwise such messages are discarded at this stage.
1164 if Prev_Msg /= No_Error_Msg
1165 and then Errors.Table (Prev_Msg).Line =
1166 Errors.Table (Cur_Msg).Line
1167 and then Errors.Table (Prev_Msg).Sfile =
1168 Errors.Table (Cur_Msg).Sfile
1169 and then Compiler_State = Parsing
1170 and then not All_Errors_Mode
1172 -- Don't delete unconditional messages and at this stage, don't
1173 -- delete continuation lines; we attempted to delete those earlier
1174 -- if the parent message was deleted.
1176 if not Errors.Table (Cur_Msg).Uncond
1177 and then not Continuation
1179 -- Don't delete if prev msg is warning and new msg is an error.
1180 -- This is because we don't want a real error masked by a
1181 -- warning. In all other cases (that is parse errors for the
1182 -- same line that are not unconditional) we do delete the
1183 -- message. This helps to avoid junk extra messages from
1184 -- cascaded parsing errors
1186 if not (Errors.Table (Prev_Msg).Warn
1188 Errors.Table (Prev_Msg).Style)
1190 (Errors.Table (Cur_Msg).Warn
1192 Errors.Table (Cur_Msg).Style)
1194 -- All tests passed, delete the message by simply returning
1195 -- without any further processing.
1197 pragma Assert (not Continuation);
1199 Last_Killed := True;
1205 -- Come here if message is to be inserted in the error chain
1207 if not Continuation then
1208 Last_Killed := False;
1211 if Prev_Msg = No_Error_Msg then
1212 First_Error_Msg := Cur_Msg;
1214 Errors.Table (Prev_Msg).Next := Cur_Msg;
1217 Errors.Table (Cur_Msg).Next := Next_Msg;
1219 if Next_Msg = No_Error_Msg then
1220 Last_Error_Msg := Cur_Msg;
1224 -- Bump appropriate statistics counts
1226 if Errors.Table (Cur_Msg).Info then
1228 -- Could be (usually is) both "info" and "warning"
1230 if Errors.Table (Cur_Msg).Warn then
1231 Warning_Info_Messages := Warning_Info_Messages + 1;
1232 Warnings_Detected := Warnings_Detected + 1;
1234 Report_Info_Messages := Report_Info_Messages + 1;
1237 elsif Errors.Table (Cur_Msg).Warn
1238 or else Errors.Table (Cur_Msg).Style
1240 Warnings_Detected := Warnings_Detected + 1;
1242 elsif Errors.Table (Cur_Msg).Check then
1243 Check_Messages := Check_Messages + 1;
1246 Total_Errors_Detected := Total_Errors_Detected + 1;
1248 if Errors.Table (Cur_Msg).Serious then
1249 Serious_Errors_Detected := Serious_Errors_Detected + 1;
1250 Handle_Serious_Error;
1252 -- If not serious error, set Fatal_Error to indicate ignored error
1256 U : constant Unit_Number_Type := Get_Source_Unit (Sptr);
1258 if Fatal_Error (U) = None then
1259 Set_Fatal_Error (U, Error_Ignored);
1265 -- Record warning message issued
1267 if Errors.Table (Cur_Msg).Warn
1268 and then not Errors.Table (Cur_Msg).Msg_Cont
1270 Warning_Msg := Cur_Msg;
1273 -- If too many warnings turn off warnings
1275 if Maximum_Messages /= 0 then
1276 if Warnings_Detected = Maximum_Messages then
1277 Warning_Mode := Suppress;
1280 -- If too many errors abandon compilation
1282 if Total_Errors_Detected = Maximum_Messages then
1283 raise Unrecoverable_Error;
1286 end Error_Msg_Internal;
1292 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
1294 Error_Msg_NEL (Msg, N, N, Sloc (N));
1301 procedure Error_Msg_NE
1303 N : Node_Or_Entity_Id;
1304 E : Node_Or_Entity_Id)
1307 Error_Msg_NEL (Msg, N, E, Sloc (N));
1314 procedure Error_Msg_NEL
1316 N : Node_Or_Entity_Id;
1317 E : Node_Or_Entity_Id;
1318 Flag_Location : Source_Ptr)
1321 if Special_Msg_Delete (Msg, N, E) then
1325 Prescan_Message (Msg);
1327 -- Special handling for warning messages
1329 if Is_Warning_Msg then
1331 -- Suppress if no warnings set for either entity or node
1333 if No_Warnings (N) or else No_Warnings (E) then
1335 -- Disable any continuation messages as well
1337 Last_Killed := True;
1341 -- Suppress if inside loop that is known to be null or is probably
1342 -- null (case where loop executes only if invalid values present).
1343 -- In either case warnings in the loop are likely to be junk.
1350 while Present (P) loop
1351 if Nkind (P) = N_Loop_Statement
1352 and then Suppress_Loop_Warnings (P)
1362 -- Test for message to be output
1365 or else Is_Unconditional_Msg
1366 or else Is_Warning_Msg
1368 or else (Msg (Msg'First) = '\' and then not Last_Killed)
1371 Error_Msg_Node_1 := E;
1372 Error_Msg (Msg, Flag_Location);
1375 Last_Killed := True;
1385 procedure Error_Msg_NW
1388 N : Node_Or_Entity_Id)
1392 and then In_Extended_Main_Source_Unit (N)
1393 and then Comes_From_Source (N)
1395 Error_Msg_NEL (Msg, N, N, Sloc (N));
1403 procedure Error_Msg_S (Msg : String) is
1405 Error_Msg (Msg, Scan_Ptr);
1412 procedure Error_Msg_SC (Msg : String) is
1414 -- If we are at end of file, post the flag after the previous token
1416 if Token = Tok_EOF then
1419 -- For all other cases the message is posted at the current token
1423 Error_Msg (Msg, Token_Ptr);
1431 procedure Error_Msg_SP (Msg : String) is
1433 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1434 -- is set to Source_First, which is a reasonable position for the
1435 -- error flag in this situation
1437 Error_Msg (Msg, Prev_Token_Ptr);
1444 procedure Finalize (Last_Call : Boolean) is
1449 procedure Delete_Warning (E : Error_Msg_Id);
1450 -- Delete a warning msg if not already deleted and adjust warning count
1452 --------------------
1453 -- Delete_Warning --
1454 --------------------
1456 procedure Delete_Warning (E : Error_Msg_Id) is
1458 if not Errors.Table (E).Deleted then
1459 Errors.Table (E).Deleted := True;
1460 Warnings_Detected := Warnings_Detected - 1;
1462 if Errors.Table (E).Info then
1463 Warning_Info_Messages := Warning_Info_Messages - 1;
1468 -- Start of processing for Finalize
1471 -- Set Prev pointers
1473 Cur := First_Error_Msg;
1474 while Cur /= No_Error_Msg loop
1475 Nxt := Errors.Table (Cur).Next;
1476 exit when Nxt = No_Error_Msg;
1477 Errors.Table (Nxt).Prev := Cur;
1481 -- Eliminate any duplicated error messages from the list. This is
1482 -- done after the fact to avoid problems with Change_Error_Text.
1484 Cur := First_Error_Msg;
1485 while Cur /= No_Error_Msg loop
1486 Nxt := Errors.Table (Cur).Next;
1489 while F /= No_Error_Msg
1490 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1492 Check_Duplicate_Message (Cur, F);
1493 F := Errors.Table (F).Next;
1499 -- Mark any messages suppressed by specific warnings as Deleted
1501 Cur := First_Error_Msg;
1502 while Cur /= No_Error_Msg loop
1504 CE : Error_Msg_Object renames Errors.Table (Cur);
1505 Tag : constant String := Get_Warning_Tag (Cur);
1508 if (CE.Warn and not CE.Deleted)
1510 (Warning_Specifically_Suppressed (CE.Sptr, CE.Text, Tag) /=
1513 Warning_Specifically_Suppressed (CE.Optr, CE.Text, Tag) /=
1516 Delete_Warning (Cur);
1518 -- If this is a continuation, delete previous parts of message
1521 while Errors.Table (F).Msg_Cont loop
1522 F := Errors.Table (F).Prev;
1523 exit when F = No_Error_Msg;
1527 -- Delete any following continuations
1531 F := Errors.Table (F).Next;
1532 exit when F = No_Error_Msg;
1533 exit when not Errors.Table (F).Msg_Cont;
1539 Cur := Errors.Table (Cur).Next;
1542 Finalize_Called := True;
1544 -- Check consistency of specific warnings (may add warnings). We only
1545 -- do this on the last call, after all possible warnings are posted.
1548 Validate_Specific_Warnings (Error_Msg'Access);
1556 function First_Node (C : Node_Id) return Node_Id is
1557 Orig : constant Node_Id := Original_Node (C);
1558 Loc : constant Source_Ptr := Sloc (Orig);
1559 Sfile : constant Source_File_Index := Get_Source_File_Index (Loc);
1563 function Test_Earlier (N : Node_Id) return Traverse_Result;
1564 -- Function applied to every node in the construct
1566 procedure Search_Tree_First is new Traverse_Proc (Test_Earlier);
1567 -- Create traversal procedure
1573 function Test_Earlier (N : Node_Id) return Traverse_Result is
1574 Norig : constant Node_Id := Original_Node (N);
1575 Loc : constant Source_Ptr := Sloc (Norig);
1578 -- Check for earlier
1582 -- Ignore nodes with no useful location information
1584 and then Loc /= Standard_Location
1585 and then Loc /= No_Location
1587 -- Ignore nodes from a different file. This ensures against cases
1588 -- of strange foreign code somehow being present. We don't want
1589 -- wild placement of messages if that happens.
1591 and then Get_Source_File_Index (Loc) = Sfile
1600 -- Start of processing for First_Node
1603 if Nkind (Orig) in N_Subexpr then
1606 Search_Tree_First (Orig);
1618 function First_Sloc (N : Node_Id) return Source_Ptr is
1619 SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1620 SF : constant Source_Ptr := Source_First (SI);
1625 F := First_Node (N);
1628 -- The following circuit is a bit subtle. When we have parenthesized
1629 -- expressions, then the Sloc will not record the location of the paren,
1630 -- but we would like to post the flag on the paren. So what we do is to
1631 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1632 -- any parentheses we know are present. Yes, we know this circuit is not
1633 -- 100% reliable (e.g. because we don't record all possible paren level
1634 -- values), but this is only for an error message so it is good enough.
1637 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1639 -- We don't look more than 12 characters behind the current
1640 -- location, and in any case not past the front of the source.
1642 Search_Loop : for K in 1 .. 12 loop
1643 exit Search_Loop when S = SF;
1645 if Source_Text (SI) (S - 1) = '(' then
1649 elsif Source_Text (SI) (S - 1) <= ' ' then
1655 end loop Search_Loop;
1656 end loop Paren_Loop;
1658 exit Node_Loop when F = N;
1660 exit Node_Loop when Nkind (F) not in N_Subexpr;
1666 -----------------------
1667 -- Get_Ignore_Errors --
1668 -----------------------
1670 function Get_Ignore_Errors return Boolean is
1672 return Errors_Must_Be_Ignored;
1673 end Get_Ignore_Errors;
1679 procedure Initialize is
1682 First_Error_Msg := No_Error_Msg;
1683 Last_Error_Msg := No_Error_Msg;
1684 Serious_Errors_Detected := 0;
1685 Total_Errors_Detected := 0;
1686 Cur_Msg := No_Error_Msg;
1689 -- Reset counts for warnings
1693 -- Initialize warnings tables
1696 Specific_Warnings.Init;
1703 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1705 if Error_Posted (N) then
1708 elsif Nkind (N) in N_Entity and then Has_Warnings_Off (N) then
1711 elsif Is_Entity_Name (N)
1712 and then Present (Entity (N))
1713 and then Has_Warnings_Off (Entity (N))
1726 function OK_Node (N : Node_Id) return Boolean is
1727 K : constant Node_Kind := Nkind (N);
1730 if Error_Posted (N) then
1733 elsif K in N_Has_Etype
1734 and then Present (Etype (N))
1735 and then Error_Posted (Etype (N))
1740 or else K = N_Attribute_Reference
1741 or else K = N_Character_Literal
1742 or else K = N_Expanded_Name
1743 or else K = N_Identifier
1744 or else K = N_Operator_Symbol)
1745 and then Present (Entity (N))
1746 and then Error_Posted (Entity (N))
1754 ---------------------
1755 -- Output_Messages --
1756 ---------------------
1758 procedure Output_Messages is
1762 procedure Write_Error_Summary;
1763 -- Write error summary
1765 procedure Write_Header (Sfile : Source_File_Index);
1766 -- Write header line (compiling or checking given file)
1768 procedure Write_Max_Errors;
1769 -- Write message if max errors reached
1771 -------------------------
1772 -- Write_Error_Summary --
1773 -------------------------
1775 procedure Write_Error_Summary is
1777 -- Extra blank line if error messages or source listing were output
1779 if Total_Errors_Detected + Warnings_Detected > 0 or else Full_List
1784 -- Message giving number of lines read and number of errors detected.
1785 -- This normally goes to Standard_Output. The exception is when brief
1786 -- mode is not set, verbose mode (or full list mode) is set, and
1787 -- there are errors. In this case we send the message to standard
1788 -- error to make sure that *something* appears on standard error
1789 -- in an error situation.
1791 if Total_Errors_Detected + Warnings_Detected /= 0
1792 and then not Brief_Output
1793 and then (Verbose_Mode or Full_List)
1798 -- Message giving total number of lines. Don't give this message if
1799 -- the Main_Source line is unknown (this happens in error situations,
1800 -- e.g. when integrated preprocessing fails).
1802 if Main_Source_File /= No_Source_File then
1804 Write_Int (Num_Source_Lines (Main_Source_File));
1806 if Num_Source_Lines (Main_Source_File) = 1 then
1807 Write_Str (" line: ");
1809 Write_Str (" lines: ");
1813 if Total_Errors_Detected = 0 then
1814 Write_Str ("No errors");
1816 elsif Total_Errors_Detected = 1 then
1817 Write_Str ("1 error");
1820 Write_Int (Total_Errors_Detected);
1821 Write_Str (" errors");
1824 if Warnings_Detected - Warning_Info_Messages /= 0 then
1826 Write_Int (Warnings_Detected);
1827 Write_Str (" warning");
1829 if Warnings_Detected - Warning_Info_Messages /= 1 then
1833 if Warning_Mode = Treat_As_Error then
1834 Write_Str (" (treated as error");
1836 if Warnings_Detected /= 1 then
1842 elsif Warnings_Treated_As_Errors /= 0 then
1844 Write_Int (Warnings_Treated_As_Errors);
1845 Write_Str (" treated as errors)");
1849 if Warning_Info_Messages + Report_Info_Messages /= 0 then
1851 Write_Int (Warning_Info_Messages + Report_Info_Messages);
1852 Write_Str (" info message");
1854 if Warning_Info_Messages + Report_Info_Messages > 1 then
1860 Set_Standard_Output;
1861 end Write_Error_Summary;
1867 procedure Write_Header (Sfile : Source_File_Index) is
1869 if Verbose_Mode or Full_List then
1870 if Original_Operating_Mode = Generate_Code then
1871 Write_Str ("Compiling: ");
1873 Write_Str ("Checking: ");
1876 Write_Name (Full_File_Name (Sfile));
1878 if not Debug_Flag_7 then
1880 Write_Str ("Source file time stamp: ");
1881 Write_Time_Stamp (Sfile);
1883 Write_Str ("Compiled at: " & Compilation_Time);
1890 ----------------------
1891 -- Write_Max_Errors --
1892 ----------------------
1894 procedure Write_Max_Errors is
1896 if Maximum_Messages /= 0 then
1897 if Warnings_Detected >= Maximum_Messages then
1899 Write_Line ("maximum number of warnings output");
1900 Write_Line ("any further warnings suppressed");
1901 Set_Standard_Output;
1904 -- If too many errors print message
1906 if Total_Errors_Detected >= Maximum_Messages then
1908 Write_Line ("fatal error: maximum number of errors detected");
1909 Set_Standard_Output;
1912 end Write_Max_Errors;
1914 -- Start of processing for Output_Messages
1917 -- Error if Finalize has not been called
1919 if not Finalize_Called then
1920 raise Program_Error;
1923 -- Reset current error source file if the main unit has a pragma
1924 -- Source_Reference. This ensures outputting the proper name of
1925 -- the source file in this situation.
1927 if Main_Source_File = No_Source_File
1928 or else Num_SRef_Pragmas (Main_Source_File) /= 0
1930 Current_Error_Source_File := No_Source_File;
1935 if Brief_Output or (not Full_List and not Verbose_Mode) then
1938 E := First_Error_Msg;
1939 while E /= No_Error_Msg loop
1940 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1941 if Full_Path_Name_For_Brief_Errors then
1942 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1944 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1948 Write_Int (Int (Physical_To_Logical
1949 (Errors.Table (E).Line,
1950 Errors.Table (E).Sfile)));
1953 if Errors.Table (E).Col < 10 then
1957 Write_Int (Int (Errors.Table (E).Col));
1959 Output_Msg_Text (E);
1963 E := Errors.Table (E).Next;
1966 Set_Standard_Output;
1969 -- Full source listing case
1972 List_Pragmas_Index := 1;
1973 List_Pragmas_Mode := True;
1974 E := First_Error_Msg;
1976 -- Normal case, to stdout (copyright notice already output)
1978 if Full_List_File_Name = null then
1979 if not Debug_Flag_7 then
1986 Create_List_File_Access.all (Full_List_File_Name.all);
1987 Set_Special_Output (Write_List_Info_Access.all'Access);
1989 -- Write copyright notice to file
1991 if not Debug_Flag_7 then
1992 Write_Str ("GNAT ");
1993 Write_Str (Gnat_Version_String);
1995 Write_Str ("Copyright 1992-" &
1997 ", Free Software Foundation, Inc.");
2002 -- First list extended main source file units with errors
2004 for U in Main_Unit .. Last_Unit loop
2005 if In_Extended_Main_Source_Unit (Cunit_Entity (U))
2007 -- If debug flag d.m is set, only the main source is listed
2009 and then (U = Main_Unit or else not Debug_Flag_Dot_M)
2011 -- If the unit of the entity does not come from source, it is
2012 -- an implicit subprogram declaration for a child subprogram.
2013 -- Do not emit errors for it, they are listed with the body.
2016 (No (Cunit_Entity (U))
2017 or else Comes_From_Source (Cunit_Entity (U))
2018 or else not Is_Subprogram (Cunit_Entity (U)))
2020 -- If the compilation unit associated with this unit does not
2021 -- come from source, it means it is an instantiation that should
2022 -- not be included in the source listing.
2024 and then Comes_From_Source (Cunit (U))
2027 Sfile : constant Source_File_Index := Source_Index (U);
2032 -- Only write the header if Sfile is known
2034 if Sfile /= No_Source_File then
2035 Write_Header (Sfile);
2039 -- Normally, we don't want an "error messages from file"
2040 -- message when listing the entire file, so we set the
2041 -- current source file as the current error source file.
2042 -- However, the old style of doing things was to list this
2043 -- message if pragma Source_Reference is present, even for
2044 -- the main unit. Since the purpose of the -gnatd.m switch
2045 -- is to duplicate the old behavior, we skip the reset if
2046 -- this debug flag is set.
2048 if not Debug_Flag_Dot_M then
2049 Current_Error_Source_File := Sfile;
2052 -- Only output the listing if Sfile is known, to avoid
2053 -- crashing the compiler.
2055 if Sfile /= No_Source_File then
2056 for N in 1 .. Last_Source_Line (Sfile) loop
2057 while E /= No_Error_Msg
2058 and then Errors.Table (E).Deleted
2060 E := Errors.Table (E).Next;
2065 and then Errors.Table (E).Line = N
2066 and then Errors.Table (E).Sfile = Sfile;
2068 Output_Source_Line (N, Sfile, Err_Flag);
2071 Output_Error_Msgs (E);
2073 if not Debug_Flag_2 then
2083 -- Then output errors, if any, for subsidiary units not in the
2084 -- main extended unit.
2086 -- Note: if debug flag d.m set, include errors for any units other
2087 -- than the main unit in the extended source unit (e.g. spec and
2088 -- subunits for a body).
2090 while E /= No_Error_Msg
2091 and then (not In_Extended_Main_Source_Unit (Errors.Table (E).Sptr)
2094 and then Get_Source_Unit
2095 (Errors.Table (E).Sptr) /= Main_Unit))
2097 if Errors.Table (E).Deleted then
2098 E := Errors.Table (E).Next;
2103 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
2104 Output_Error_Msgs (E);
2108 -- If output to file, write extra copy of error summary to the
2109 -- output file, and then close it.
2111 if Full_List_File_Name /= null then
2112 Write_Error_Summary;
2114 Close_List_File_Access.all;
2115 Cancel_Special_Output;
2119 -- Verbose mode (error lines only with error flags). Normally this is
2120 -- ignored in full list mode, unless we are listing to a file, in which
2121 -- case we still generate -gnatv output to standard output.
2124 and then (not Full_List or else Full_List_File_Name /= null)
2128 -- Output the header only when Main_Source_File is known
2130 if Main_Source_File /= No_Source_File then
2131 Write_Header (Main_Source_File);
2134 E := First_Error_Msg;
2136 -- Loop through error lines
2138 while E /= No_Error_Msg loop
2139 if Errors.Table (E).Deleted then
2140 E := Errors.Table (E).Next;
2144 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
2145 Output_Error_Msgs (E);
2150 -- Output error summary if verbose or full list mode
2152 if Verbose_Mode or else Full_List then
2153 Write_Error_Summary;
2158 -- Even though Warning_Info_Messages are a subclass of warnings, they
2159 -- must not be treated as errors when -gnatwe is in effect.
2161 if Warning_Mode = Treat_As_Error then
2162 Total_Errors_Detected :=
2163 Total_Errors_Detected + Warnings_Detected - Warning_Info_Messages;
2164 Warnings_Detected := Warning_Info_Messages;
2166 end Output_Messages;
2168 ------------------------
2169 -- Output_Source_Line --
2170 ------------------------
2172 procedure Output_Source_Line
2173 (L : Physical_Line_Number;
2174 Sfile : Source_File_Index;
2180 Line_Number_Output : Boolean := False;
2181 -- Set True once line number is output
2183 Empty_Line : Boolean := True;
2184 -- Set False if line includes at least one character
2187 if Sfile /= Current_Error_Source_File then
2188 Write_Str ("==============Error messages for ");
2190 case Sinput.File_Type (Sfile) is
2192 Write_Str ("source");
2194 when Sinput.Config =>
2195 Write_Str ("configuration pragmas");
2198 Write_Str ("symbol definition");
2200 when Sinput.Preproc =>
2201 Write_Str ("preprocessing data");
2204 Write_Str (" file: ");
2205 Write_Name (Full_File_Name (Sfile));
2208 if Num_SRef_Pragmas (Sfile) > 0 then
2209 Write_Str ("--------------Line numbers from file: ");
2210 Write_Name (Full_Ref_Name (Sfile));
2211 Write_Str (" (starting at line ");
2212 Write_Int (Int (First_Mapped_Line (Sfile)));
2217 Current_Error_Source_File := Sfile;
2220 if Errs or List_Pragmas_Mode then
2221 Output_Line_Number (Physical_To_Logical (L, Sfile));
2222 Line_Number_Output := True;
2225 S := Line_Start (L, Sfile);
2228 C := Source_Text (Sfile) (S);
2229 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
2231 -- Deal with matching entry in List_Pragmas table
2234 and then List_Pragmas_Index <= List_Pragmas.Last
2235 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
2237 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
2241 -- Ignore if on line with errors so that error flags
2242 -- get properly listed with the error line .
2245 Write_Char (ASCII.FF);
2249 List_Pragmas_Mode := True;
2251 if not Line_Number_Output then
2252 Output_Line_Number (Physical_To_Logical (L, Sfile));
2253 Line_Number_Output := True;
2260 List_Pragmas_Mode := False;
2263 List_Pragmas_Index := List_Pragmas_Index + 1;
2265 -- Normal case (no matching entry in List_Pragmas table)
2268 if Errs or List_Pragmas_Mode then
2273 Empty_Line := False;
2277 -- If we have output a source line, then add the line terminator, with
2278 -- training spaces preserved (so we output the line exactly as input).
2280 if Line_Number_Output then
2284 Write_Eol_Keep_Blanks;
2287 end Output_Source_Line;
2289 -----------------------------
2290 -- Remove_Warning_Messages --
2291 -----------------------------
2293 procedure Remove_Warning_Messages (N : Node_Id) is
2295 function Check_For_Warning (N : Node_Id) return Traverse_Result;
2296 -- This function checks one node for a possible warning message
2298 function Check_All_Warnings is new Traverse_Func (Check_For_Warning);
2299 -- This defines the traversal operation
2301 -----------------------
2302 -- Check_For_Warning --
2303 -----------------------
2305 function Check_For_Warning (N : Node_Id) return Traverse_Result is
2306 Loc : constant Source_Ptr := Sloc (N);
2309 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
2310 -- Returns True for a message that is to be removed. Also adjusts
2311 -- warning count appropriately.
2317 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
2319 if E /= No_Error_Msg
2321 -- Don't remove if location does not match
2323 and then Errors.Table (E).Optr = Loc
2325 -- Don't remove if not warning/info message. Note that we do
2326 -- not remove style messages here. They are warning messages
2327 -- but not ones we want removed in this context.
2329 and then Errors.Table (E).Warn
2331 -- Don't remove unconditional messages
2333 and then not Errors.Table (E).Uncond
2335 Warnings_Detected := Warnings_Detected - 1;
2337 if Errors.Table (E).Info then
2338 Warning_Info_Messages := Warning_Info_Messages - 1;
2343 -- No removal required
2350 -- Start of processing for Check_For_Warnings
2353 while To_Be_Removed (First_Error_Msg) loop
2354 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
2357 if First_Error_Msg = No_Error_Msg then
2358 Last_Error_Msg := No_Error_Msg;
2361 E := First_Error_Msg;
2362 while E /= No_Error_Msg loop
2363 while To_Be_Removed (Errors.Table (E).Next) loop
2364 Errors.Table (E).Next :=
2365 Errors.Table (Errors.Table (E).Next).Next;
2367 if Errors.Table (E).Next = No_Error_Msg then
2368 Last_Error_Msg := E;
2372 E := Errors.Table (E).Next;
2375 if Nkind (N) = N_Raise_Constraint_Error
2376 and then Original_Node (N) /= N
2377 and then No (Condition (N))
2379 -- Warnings may have been posted on subexpressions of the original
2380 -- tree. We place the original node back on the tree to remove
2381 -- those warnings, whose sloc do not match those of any node in
2382 -- the current tree. Given that we are in unreachable code, this
2383 -- modification to the tree is harmless.
2386 Status : Traverse_Final_Result;
2389 if Is_List_Member (N) then
2390 Set_Condition (N, Original_Node (N));
2391 Status := Check_All_Warnings (Condition (N));
2393 Rewrite (N, Original_Node (N));
2394 Status := Check_All_Warnings (N);
2403 end Check_For_Warning;
2405 -- Start of processing for Remove_Warning_Messages
2408 if Warnings_Detected /= 0 then
2410 Discard : Traverse_Final_Result;
2411 pragma Warnings (Off, Discard);
2414 Discard := Check_All_Warnings (N);
2417 end Remove_Warning_Messages;
2419 procedure Remove_Warning_Messages (L : List_Id) is
2422 if Is_Non_Empty_List (L) then
2424 while Present (Stat) loop
2425 Remove_Warning_Messages (Stat);
2429 end Remove_Warning_Messages;
2431 --------------------
2432 -- Reset_Warnings --
2433 --------------------
2435 procedure Reset_Warnings is
2437 Warnings_Treated_As_Errors := 0;
2438 Warnings_Detected := 0;
2439 Warning_Info_Messages := 0;
2440 Warnings_As_Errors_Count := 0;
2443 ----------------------
2444 -- Adjust_Name_Case --
2445 ----------------------
2447 procedure Adjust_Name_Case
2448 (Buf : in out Bounded_String;
2452 -- We have an all lower case name from Namet, and now we want to set
2453 -- the appropriate case. If possible we copy the actual casing from
2454 -- the source. If not we use standard identifier casing.
2457 Src_Ind : constant Source_File_Index := Get_Source_File_Index (Loc);
2458 Sbuffer : Source_Buffer_Ptr;
2460 Src_Ptr : Source_Ptr;
2466 -- For standard locations, always use mixed case
2468 if Loc <= No_Location then
2469 Set_Casing (Mixed_Case);
2472 -- Determine if the reference we are dealing with corresponds to
2473 -- text at the point of the error reference. This will often be
2474 -- the case for simple identifier references, and is the case
2475 -- where we can copy the casing from the source.
2477 Sbuffer := Source_Text (Src_Ind);
2479 while Ref_Ptr <= Buf.Length loop
2481 Fold_Lower (Sbuffer (Src_Ptr)) /=
2482 Fold_Lower (Buf.Chars (Ref_Ptr));
2483 Ref_Ptr := Ref_Ptr + 1;
2484 Src_Ptr := Src_Ptr + 1;
2487 -- If we get through the loop without a mismatch, then output the
2488 -- name the way it is cased in the source program
2490 if Ref_Ptr > Buf.Length then
2493 for J in 1 .. Buf.Length loop
2494 Buf.Chars (J) := Sbuffer (Src_Ptr);
2495 Src_Ptr := Src_Ptr + 1;
2498 -- Otherwise set the casing using the default identifier casing
2501 Set_Casing (Buf, Identifier_Casing (Src_Ind));
2505 end Adjust_Name_Case;
2507 procedure Adjust_Name_Case (Loc : Source_Ptr) is
2509 Adjust_Name_Case (Global_Name_Buffer, Loc);
2510 end Adjust_Name_Case;
2512 ---------------------------
2513 -- Set_Identifier_Casing --
2514 ---------------------------
2516 procedure Set_Identifier_Casing
2517 (Identifier_Name : System.Address;
2518 File_Name : System.Address)
2520 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
2521 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
2524 Desired_Case : Casing_Type := Mixed_Case;
2525 -- Casing required for result. Default value of Mixed_Case is used if
2526 -- for some reason we cannot find the right file name in the table.
2529 -- Get length of file name
2532 while File (Flen + 1) /= ASCII.NUL loop
2536 -- Loop through file names to find matching one. This is a bit slow, but
2537 -- we only do it in error situations so it is not so terrible. Note that
2538 -- if the loop does not exit, then the desired case will be left set to
2539 -- Mixed_Case, this can happen if the name was not in canonical form.
2541 for J in 1 .. Last_Source_File loop
2542 Get_Name_String (Full_Debug_Name (J));
2545 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
2547 Desired_Case := Identifier_Casing (J);
2552 -- Copy identifier as given to Name_Buffer
2554 for J in Name_Buffer'Range loop
2555 Name_Buffer (J) := Ident (J);
2557 if Name_Buffer (J) = ASCII.NUL then
2563 Set_Casing (Desired_Case);
2564 end Set_Identifier_Casing;
2566 -----------------------
2567 -- Set_Ignore_Errors --
2568 -----------------------
2570 procedure Set_Ignore_Errors (To : Boolean) is
2572 Errors_Must_Be_Ignored := To;
2573 end Set_Ignore_Errors;
2575 ------------------------------
2576 -- Set_Msg_Insertion_Column --
2577 ------------------------------
2579 procedure Set_Msg_Insertion_Column is
2581 if RM_Column_Check then
2582 Set_Msg_Str (" in column ");
2583 Set_Msg_Int (Int (Error_Msg_Col) + 1);
2585 end Set_Msg_Insertion_Column;
2587 ----------------------------
2588 -- Set_Msg_Insertion_Node --
2589 ----------------------------
2591 procedure Set_Msg_Insertion_Node is
2596 Error_Msg_Node_1 = Error
2597 or else Error_Msg_Node_1 = Any_Type;
2599 if Error_Msg_Node_1 = Empty then
2600 Set_Msg_Blank_Conditional;
2601 Set_Msg_Str ("<empty>");
2603 elsif Error_Msg_Node_1 = Error then
2605 Set_Msg_Str ("<error>");
2607 elsif Error_Msg_Node_1 = Standard_Void_Type then
2609 Set_Msg_Str ("procedure name");
2611 elsif Nkind (Error_Msg_Node_1) in N_Entity
2612 and then Ekind (Error_Msg_Node_1) = E_Anonymous_Access_Subprogram_Type
2615 Set_Msg_Str ("access to subprogram");
2618 Set_Msg_Blank_Conditional;
2622 K := Nkind (Error_Msg_Node_1);
2624 -- If we have operator case, skip quotes since name of operator
2625 -- itself will supply the required quotations. An operator can be an
2626 -- applied use in an expression or an explicit operator symbol, or an
2627 -- identifier whose name indicates it is an operator.
2630 or else K = N_Operator_Symbol
2631 or else K = N_Defining_Operator_Symbol
2632 or else ((K = N_Identifier or else K = N_Defining_Identifier)
2633 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
2635 Set_Msg_Node (Error_Msg_Node_1);
2637 -- Normal case, not an operator, surround with quotes
2641 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
2642 Set_Msg_Node (Error_Msg_Node_1);
2647 -- The following assignment ensures that a second ampersand insertion
2648 -- character will correspond to the Error_Msg_Node_2 parameter. We
2649 -- suppress possible validity checks in case operating in -gnatVa mode,
2650 -- and Error_Msg_Node_2 is not needed and has not been set.
2653 pragma Suppress (Range_Check);
2655 Error_Msg_Node_1 := Error_Msg_Node_2;
2657 end Set_Msg_Insertion_Node;
2659 --------------------------------------
2660 -- Set_Msg_Insertion_Type_Reference --
2661 --------------------------------------
2663 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
2669 if Error_Msg_Node_1 = Standard_Void_Type then
2670 Set_Msg_Str ("package or procedure name");
2673 elsif Error_Msg_Node_1 = Standard_Exception_Type then
2674 Set_Msg_Str ("exception name");
2677 elsif Error_Msg_Node_1 = Any_Access
2678 or else Error_Msg_Node_1 = Any_Array
2679 or else Error_Msg_Node_1 = Any_Boolean
2680 or else Error_Msg_Node_1 = Any_Character
2681 or else Error_Msg_Node_1 = Any_Composite
2682 or else Error_Msg_Node_1 = Any_Discrete
2683 or else Error_Msg_Node_1 = Any_Fixed
2684 or else Error_Msg_Node_1 = Any_Integer
2685 or else Error_Msg_Node_1 = Any_Modular
2686 or else Error_Msg_Node_1 = Any_Numeric
2687 or else Error_Msg_Node_1 = Any_Real
2688 or else Error_Msg_Node_1 = Any_Scalar
2689 or else Error_Msg_Node_1 = Any_String
2691 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
2692 Set_Msg_Name_Buffer;
2695 elsif Error_Msg_Node_1 = Universal_Real then
2696 Set_Msg_Str ("type universal real");
2699 elsif Error_Msg_Node_1 = Universal_Integer then
2700 Set_Msg_Str ("type universal integer");
2703 elsif Error_Msg_Node_1 = Universal_Fixed then
2704 Set_Msg_Str ("type universal fixed");
2708 -- Special case of anonymous array
2710 if Nkind (Error_Msg_Node_1) in N_Entity
2711 and then Is_Array_Type (Error_Msg_Node_1)
2712 and then Present (Related_Array_Object (Error_Msg_Node_1))
2714 Set_Msg_Str ("type of ");
2715 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
2716 Set_Msg_Str (" declared");
2717 Set_Msg_Insertion_Line_Number
2718 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
2722 -- If we fall through, it is not a special case, so first output
2723 -- the name of the type, preceded by private for a private type
2725 if Is_Private_Type (Error_Msg_Node_1) then
2726 Set_Msg_Str ("private type ");
2728 Set_Msg_Str ("type ");
2731 Ent := Error_Msg_Node_1;
2733 if Is_Internal_Name (Chars (Ent)) then
2734 Unwind_Internal_Type (Ent);
2737 -- Types in Standard are displayed as "Standard.name"
2739 if Sloc (Ent) <= Standard_Location then
2741 Set_Msg_Str ("Standard.");
2746 -- Types in other language defined units are displayed as
2747 -- "package-name.type-name"
2749 elsif Is_Predefined_Unit (Get_Source_Unit (Ent)) then
2750 Get_Unqualified_Decoded_Name_String
2751 (Unit_Name (Get_Source_Unit (Ent)));
2752 Name_Len := Name_Len - 2;
2753 Set_Msg_Blank_Conditional;
2755 Set_Casing (Mixed_Case);
2756 Set_Msg_Name_Buffer;
2758 Set_Casing (Mixed_Case);
2763 -- All other types display as "type name" defined at line xxx
2764 -- possibly qualified if qualification is requested.
2768 Set_Qualification (Error_Msg_Qual_Level, Ent);
2772 -- If we did not print a name (e.g. in the case of an anonymous
2773 -- subprogram type), there is no name to print, so remove quotes.
2775 if Buffer_Ends_With ('"') then
2776 Buffer_Remove ('"');
2782 -- If the original type did not come from a predefined file, add the
2783 -- location where the type was defined.
2785 if Sloc (Error_Msg_Node_1) > Standard_Location
2787 not Is_Predefined_Unit (Get_Source_Unit (Error_Msg_Node_1))
2789 Get_Name_String (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)));
2790 Set_Msg_Str (" defined");
2791 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
2793 -- If it did come from a predefined file, deal with the case where
2794 -- this was a file with a generic instantiation from elsewhere.
2797 if Sloc (Error_Msg_Node_1) > Standard_Location then
2799 Iloc : constant Source_Ptr :=
2800 Instantiation_Location (Sloc (Error_Msg_Node_1));
2803 if Iloc /= No_Location
2804 and then not Suppress_Instance_Location
2806 Set_Msg_Str (" from instance");
2807 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2812 end Set_Msg_Insertion_Type_Reference;
2814 ---------------------------------
2815 -- Set_Msg_Insertion_Unit_Name --
2816 ---------------------------------
2818 procedure Set_Msg_Insertion_Unit_Name (Suffix : Boolean := True) is
2820 if Error_Msg_Unit_1 = No_Unit_Name then
2823 elsif Error_Msg_Unit_1 = Error_Unit_Name then
2825 Set_Msg_Str ("<error>");
2828 Get_Unit_Name_String (Error_Msg_Unit_1, Suffix);
2831 Set_Msg_Name_Buffer;
2835 -- The following assignment ensures that a second percent insertion
2836 -- character will correspond to the Error_Msg_Unit_2 parameter. We
2837 -- suppress possible validity checks in case operating in -gnatVa mode,
2838 -- and Error_Msg_Unit_2 is not needed and has not been set.
2841 pragma Suppress (Range_Check);
2843 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2845 end Set_Msg_Insertion_Unit_Name;
2851 procedure Set_Msg_Node (Node : Node_Id) is
2857 case Nkind (Node) is
2858 when N_Designator =>
2859 Set_Msg_Node (Name (Node));
2861 Set_Msg_Node (Identifier (Node));
2864 when N_Defining_Program_Unit_Name =>
2865 Set_Msg_Node (Name (Node));
2867 Set_Msg_Node (Defining_Identifier (Node));
2870 when N_Expanded_Name
2871 | N_Selected_Component
2873 Set_Msg_Node (Prefix (Node));
2875 Set_Msg_Node (Selector_Name (Node));
2882 -- The only remaining possibilities are identifiers, defining
2883 -- identifiers, pragmas, and pragma argument associations.
2885 if Nkind (Node) = N_Pragma then
2886 Nam := Pragma_Name (Node);
2889 -- The other cases have Chars fields
2891 -- First deal with internal names, which generally represent something
2892 -- gone wrong. First attempt: if this is a rewritten node that rewrites
2893 -- something with a Chars field that is not an internal name, use that.
2895 elsif Is_Internal_Name (Chars (Node))
2896 and then Nkind (Original_Node (Node)) in N_Has_Chars
2897 and then not Is_Internal_Name (Chars (Original_Node (Node)))
2899 Nam := Chars (Original_Node (Node));
2900 Loc := Sloc (Original_Node (Node));
2902 -- Another shot for internal names, in the case of internal type names,
2903 -- we try to find a reasonable representation for the external name.
2905 elsif Is_Internal_Name (Chars (Node))
2907 ((Is_Entity_Name (Node)
2908 and then Present (Entity (Node))
2909 and then Is_Type (Entity (Node)))
2911 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2913 if Nkind (Node) = N_Identifier then
2914 Ent := Entity (Node);
2921 -- If the type is the designated type of an access_to_subprogram,
2922 -- then there is no name to provide in the call.
2924 if Ekind (Ent) = E_Subprogram_Type then
2927 -- Otherwise, we will be able to find some kind of name to output
2930 Unwind_Internal_Type (Ent);
2934 -- If not internal name, or if we could not find a reasonable possible
2935 -- substitution for the internal name, just use name in Chars field.
2938 Nam := Chars (Node);
2942 -- At this stage, the name to output is in Nam
2944 Get_Unqualified_Decoded_Name_String (Nam);
2946 -- Remove trailing upper case letters from the name (useful for
2947 -- dealing with some cases of internal names).
2949 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A' .. 'Z' loop
2950 Name_Len := Name_Len - 1;
2953 -- If we have any of the names from standard that start with the
2954 -- characters "any " (e.g. Any_Type), then kill the message since
2955 -- almost certainly it is a junk cascaded message.
2958 and then Name_Buffer (1 .. 4) = "any "
2960 Kill_Message := True;
2963 -- If we still have an internal name, kill the message (will only
2964 -- work if we already had errors!)
2966 if Is_Internal_Name then
2967 Kill_Message := True;
2969 -- Remaining step is to adjust casing and possibly add 'Class
2971 Adjust_Name_Case (Global_Name_Buffer, Loc);
2972 Set_Msg_Name_Buffer;
2980 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2981 C : Character; -- Current character
2982 P : Natural; -- Current index;
2984 procedure Skip_Msg_Insertion_Warning (C : Character);
2985 -- Deal with ? ?? ?x? ?X? ?*? ?$? insertion sequences (and the same
2986 -- sequences using < instead of ?). The caller has already bumped
2987 -- the pointer past the initial ? or < and C is set to this initial
2988 -- character (? or <). This procedure skips past the rest of the
2989 -- sequence. We do not need to set Msg_Insertion_Char, since this
2990 -- was already done during the message prescan.
2992 --------------------------------
2993 -- Skip_Msg_Insertion_Warning --
2994 --------------------------------
2996 procedure Skip_Msg_Insertion_Warning (C : Character) is
2998 if P <= Text'Last and then Text (P) = C then
3001 elsif P + 1 <= Text'Last
3002 and then (Text (P) in 'a' .. 'z'
3004 Text (P) in 'A' .. 'Z'
3009 and then Text (P + 1) = C
3013 end Skip_Msg_Insertion_Warning;
3015 -- Start of processing for Set_Msg_Text
3018 Manual_Quote_Mode := False;
3020 Flag_Source := Get_Source_File_Index (Flag);
3022 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
3023 -- will be used (Info field in error message object) to put back the
3024 -- string when it is printed. We need to do this, or we get confused
3025 -- with instantiation continuations.
3028 and then Text (Text'First .. Text'First + 5) = "info: "
3030 P := Text'First + 6;
3035 -- Loop through characters of message
3037 while P <= Text'Last loop
3041 -- Check for insertion character or sequence
3045 if P <= Text'Last and then Text (P) = '%' then
3047 Set_Msg_Insertion_Name_Literal;
3049 Set_Msg_Insertion_Name;
3053 if P <= Text'Last and then Text (P) = '$' then
3055 Set_Msg_Insertion_Unit_Name (Suffix => False);
3057 Set_Msg_Insertion_Unit_Name;
3061 Set_Msg_Insertion_File_Name;
3064 Set_Msg_Insertion_Type_Reference (Flag);
3067 Set_Msg_Insertion_Reserved_Name;
3070 Set_Msg_Insertion_Node;
3073 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
3076 Continuation := True;
3078 if P <= Text'Last and then Text (P) = '\' then
3079 Continuation_New_Line := True;
3084 Set_Msg_Insertion_Column;
3087 Set_Msg_Insertion_Run_Time_Name;
3090 Set_Msg_Insertion_Uint;
3093 Manual_Quote_Mode := not Manual_Quote_Mode;
3097 null; -- already dealt with
3100 Skip_Msg_Insertion_Warning ('?');
3103 Skip_Msg_Insertion_Warning ('<');
3106 null; -- already dealt with
3109 Set_Msg_Char (Text (P));
3113 Set_Msg_Str (Error_Msg_String (1 .. Error_Msg_Strlen));
3115 -- Upper case letter
3119 -- Start of reserved word if two or more
3121 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
3123 Set_Msg_Insertion_Reserved_Word (Text, P);
3125 -- Single upper case letter is just inserted
3131 -- '[' (will be/would have been raised at run time)
3135 -- Switch the message from a warning to an error if the flag
3136 -- -gnatwE is specified to treat run-time exception warnings
3140 and then Warning_Mode = Treat_Run_Time_Warnings_As_Errors
3142 Is_Warning_Msg := False;
3145 if Is_Warning_Msg then
3146 Set_Msg_Str ("will be raised at run time");
3148 Set_Msg_Str ("would have been raised at run time");
3151 -- ']' (may be/might have been raised at run time)
3154 if Is_Warning_Msg then
3155 Set_Msg_Str ("may be raised at run time");
3157 Set_Msg_Str ("might have been raised at run time");
3160 -- Normal character with no special treatment
3172 procedure Set_Posted (N : Node_Id) is
3176 if Is_Serious_Error then
3178 -- We always set Error_Posted on the node itself
3180 Set_Error_Posted (N);
3182 -- If it is a subexpression, then set Error_Posted on parents up to
3183 -- and including the first non-subexpression construct. This helps
3184 -- avoid cascaded error messages within a single expression.
3190 Set_Error_Posted (P);
3191 exit when Nkind (P) not in N_Subexpr;
3194 if Nkind_In (P, N_Pragma_Argument_Association,
3195 N_Component_Association,
3196 N_Discriminant_Association,
3197 N_Generic_Association,
3198 N_Parameter_Association)
3200 Set_Error_Posted (Parent (P));
3203 -- A special check, if we just posted an error on an attribute
3204 -- definition clause, then also set the entity involved as posted.
3205 -- For example, this stops complaining about the alignment after
3206 -- complaining about the size, which is likely to be useless.
3208 if Nkind (P) = N_Attribute_Definition_Clause then
3209 if Is_Entity_Name (Name (P)) then
3210 Set_Error_Posted (Entity (Name (P)));
3216 -----------------------
3217 -- Set_Qualification --
3218 -----------------------
3220 procedure Set_Qualification (N : Nat; E : Entity_Id) is
3222 if N /= 0 and then Scope (E) /= Standard_Standard then
3223 Set_Qualification (N - 1, Scope (E));
3224 Set_Msg_Node (Scope (E));
3227 end Set_Qualification;
3229 ------------------------
3230 -- Special_Msg_Delete --
3231 ------------------------
3233 -- Is it really right to have all this specialized knowledge in errout?
3235 function Special_Msg_Delete
3237 N : Node_Or_Entity_Id;
3238 E : Node_Or_Entity_Id) return Boolean
3241 -- Never delete messages in -gnatdO mode
3243 if Debug_Flag_OO then
3246 -- Processing for "atomic access cannot be guaranteed"
3248 elsif Msg = "atomic access to & cannot be guaranteed" then
3250 -- When an atomic object refers to a non-atomic type in the same
3251 -- scope, we implicitly make the type atomic. In the non-error case
3252 -- this is surely safe (and in fact prevents an error from occurring
3253 -- if the type is not atomic by default). But if the object cannot be
3254 -- made atomic, then we introduce an extra junk message by this
3255 -- manipulation, which we get rid of here.
3257 -- We identify this case by the fact that it references a type for
3258 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
3261 and then Is_Atomic (E)
3262 and then No (Get_Rep_Pragma (E, Name_Atomic))
3267 -- Similar processing for "volatile full access cannot be guaranteed"
3269 elsif Msg = "volatile full access to & cannot be guaranteed" then
3271 and then Is_Volatile_Full_Access (E)
3272 and then No (Get_Rep_Pragma (E, Name_Volatile_Full_Access))
3277 -- Processing for "Size too small" messages
3279 elsif Msg = "size for& too small, minimum allowed is ^" then
3281 -- Suppress "size too small" errors in CodePeer mode, since code may
3282 -- be analyzed in a different configuration than the one used for
3283 -- compilation. Even when the configurations match, this message
3284 -- may be issued on correct code, because pragma Pack is ignored
3285 -- in CodePeer mode.
3287 if CodePeer_Mode then
3290 -- When a size is wrong for a frozen type there is no explicit size
3291 -- clause, and other errors have occurred, suppress the message,
3292 -- since it is likely that this size error is a cascaded result of
3293 -- other errors. The reason we eliminate unfrozen types is that
3294 -- messages issued before the freeze type are for sure OK.
3297 and then Serious_Errors_Detected > 0
3298 and then Nkind (N) /= N_Component_Clause
3299 and then Nkind (Parent (N)) /= N_Component_Clause
3301 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
3303 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
3305 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
3311 -- All special tests complete, so go ahead with message
3314 end Special_Msg_Delete;
3320 procedure SPARK_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
3322 if SPARK_Mode /= Off then
3323 Error_Msg_N (Msg, N);
3331 procedure SPARK_Msg_NE
3333 N : Node_Or_Entity_Id;
3334 E : Node_Or_Entity_Id)
3337 if SPARK_Mode /= Off then
3338 Error_Msg_NE (Msg, N, E);
3342 --------------------------
3343 -- Unwind_Internal_Type --
3344 --------------------------
3346 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
3347 Derived : Boolean := False;
3349 Old_Ent : Entity_Id;
3352 -- Undo placement of a quote, since we will put it back later
3354 Mchar := Msg_Buffer (Msglen);
3357 Msglen := Msglen - 1;
3360 -- The loop here deals with recursive types, we are trying to find a
3361 -- related entity that is not an implicit type. Note that the check with
3362 -- Old_Ent stops us from getting "stuck". Also, we don't output the
3363 -- "type derived from" message more than once in the case where we climb
3364 -- up multiple levels.
3369 -- Implicit access type, use directly designated type In Ada 2005,
3370 -- the designated type may be an anonymous access to subprogram, in
3371 -- which case we can only point to its definition.
3373 if Is_Access_Type (Ent) then
3374 if Ekind (Ent) = E_Access_Subprogram_Type
3375 or else Ekind (Ent) = E_Anonymous_Access_Subprogram_Type
3376 or else Is_Access_Protected_Subprogram_Type (Ent)
3378 Ent := Directly_Designated_Type (Ent);
3380 if not Comes_From_Source (Ent) then
3381 if Buffer_Ends_With ("type ") then
3382 Buffer_Remove ("type ");
3386 if Ekind (Ent) = E_Function then
3387 Set_Msg_Str ("access to function ");
3388 elsif Ekind (Ent) = E_Procedure then
3389 Set_Msg_Str ("access to procedure ");
3391 Set_Msg_Str ("access to subprogram");
3396 -- Type is access to object, named or anonymous
3399 Set_Msg_Str ("access to ");
3400 Ent := Directly_Designated_Type (Ent);
3405 elsif Is_Class_Wide_Type (Ent) then
3407 Ent := Root_Type (Ent);
3409 -- Use base type if this is a subtype
3411 elsif Ent /= Base_Type (Ent) then
3412 Buffer_Remove ("type ");
3414 -- Avoid duplication "subtype of subtype of", and also replace
3415 -- "derived from subtype of" simply by "derived from"
3417 if not Buffer_Ends_With ("subtype of ")
3418 and then not Buffer_Ends_With ("derived from ")
3420 Set_Msg_Str ("subtype of ");
3423 Ent := Base_Type (Ent);
3425 -- If this is a base type with a first named subtype, use the first
3426 -- named subtype instead. This is not quite accurate in all cases,
3427 -- but it makes too much noise to be accurate and add 'Base in all
3428 -- cases. Note that we only do this is the first named subtype is not
3429 -- itself an internal name. This avoids the obvious loop (subtype ->
3430 -- basetype -> subtype) which would otherwise occur).
3434 FST : constant Entity_Id := First_Subtype (Ent);
3437 if not Is_Internal_Name (Chars (FST)) then
3441 -- Otherwise use root type
3445 Buffer_Remove ("type ");
3447 -- Test for "subtype of type derived from" which seems
3448 -- excessive and is replaced by "type derived from".
3450 Buffer_Remove ("subtype of");
3452 -- Avoid duplicated "type derived from type derived from"
3454 if not Buffer_Ends_With ("type derived from ") then
3455 Set_Msg_Str ("type derived from ");
3466 -- If we are stuck in a loop, get out and settle for the internal
3467 -- name after all. In this case we set to kill the message if it is
3468 -- not the first error message (we really try hard not to show the
3469 -- dirty laundry of the implementation to the poor user).
3471 if Ent = Old_Ent then
3472 Kill_Message := True;
3476 -- Get out if we finally found a non-internal name to use
3478 exit Find when not Is_Internal_Name (Chars (Ent));
3484 end Unwind_Internal_Type;
3486 --------------------
3487 -- Warn_Insertion --
3488 --------------------
3490 function Warn_Insertion return String is
3492 case Warning_Msg_Char is
3496 when 'a' .. 'z' | 'A' .. 'Z' | '*' | '$' =>
3497 return '?' & Warning_Msg_Char & '?';
3503 raise Program_Error;