1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2006, 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 2, 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 COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- GNAT was originally developed by the GNAT team at New York University. --
23 -- Extensive contributions were provided by Ada Core Technologies Inc. --
25 ------------------------------------------------------------------------------
27 -- Warning! Error messages can be generated during Gigi processing by direct
28 -- calls to error message routines, so it is essential that the processing
29 -- in this body be consistent with the requirements for the Gigi processing
30 -- environment, and that in particular, no disallowed table expansion is
33 with Atree
; use Atree
;
34 with Casing
; use Casing
;
35 with Csets
; use Csets
;
36 with Debug
; use Debug
;
37 with Einfo
; use Einfo
;
38 with Erroutc
; use Erroutc
;
39 with Fname
; use Fname
;
40 with Hostparm
; use Hostparm
;
42 with Namet
; use Namet
;
44 with Nlists
; use Nlists
;
45 with Output
; use Output
;
46 with Scans
; use Scans
;
47 with Sinput
; use Sinput
;
48 with Sinfo
; use Sinfo
;
49 with Snames
; use Snames
;
50 with Stand
; use Stand
;
52 with Uname
; use Uname
;
54 with Unchecked_Conversion
;
56 package body Errout
is
58 Errors_Must_Be_Ignored
: Boolean := False;
59 -- Set to True by procedure Set_Ignore_Errors (True), when calls to
60 -- error message procedures should be ignored (when parsing irrelevant
61 -- text in sources being preprocessed).
63 Warn_On_Instance
: Boolean;
64 -- Flag set true for warning message to be posted on instance
66 ------------------------------------
67 -- Table of Non-Instance Messages --
68 ------------------------------------
70 -- This table contains an entry for every error message processed by the
71 -- Error_Msg routine that is not posted on generic (or inlined) instance.
72 -- As explained in further detail in the Error_Msg procedure body, this
73 -- table is used to avoid posting redundant messages on instances.
75 type NIM_Record
is record
79 -- Type used to store text and location of one message
81 package Non_Instance_Msgs
is new Table
.Table
(
82 Table_Component_Type
=> NIM_Record
,
83 Table_Index_Type
=> Int
,
86 Table_Increment
=> 100,
87 Table_Name
=> "Non_Instance_Msgs");
89 -----------------------
90 -- Local Subprograms --
91 -----------------------
93 procedure Error_Msg_Internal
98 -- This is the low level routine used to post messages after dealing with
99 -- the issue of messages placed on instantiations (which get broken up
100 -- into separate calls in Error_Msg). Sptr is the location on which the
101 -- flag will be placed in the output. In the case where the flag is on
102 -- the template, this points directly to the template, not to one of the
103 -- instantiation copies of the template. Optr is the original location
104 -- used to flag the error, and this may indeed point to an instantiation
105 -- copy. So typically we can see Optr pointing to the template location
106 -- in an instantiation copy when Sptr points to the source location of
107 -- the actual instantiation (i.e the line with the new). Msg_Cont is
108 -- set true if this is a continuation message.
110 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean;
111 -- Determines if warnings should be suppressed for the given node
113 function OK_Node
(N
: Node_Id
) return Boolean;
114 -- Determines if a node is an OK node to place an error message on (return
115 -- True) or if the error message should be suppressed (return False). A
116 -- message is suppressed if the node already has an error posted on it,
117 -- or if it refers to an Etype that has an error posted on it, or if
118 -- it references an Entity that has an error posted on it.
120 procedure Output_Source_Line
121 (L
: Physical_Line_Number
;
122 Sfile
: Source_File_Index
;
124 -- Outputs text of source line L, in file S, together with preceding line
125 -- number, as described above for Output_Line_Number. The Errs parameter
126 -- indicates if there are errors attached to the line, which forces
127 -- listing on, even in the presence of pragma List (Off).
129 procedure Set_Msg_Insertion_Column
;
130 -- Handle column number insertion (@ insertion character)
132 procedure Set_Msg_Insertion_Node
;
133 -- Handle node (name from node) insertion (& insertion character)
135 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
);
136 -- Handle type reference (right brace insertion character). Flag is the
137 -- location of the flag, which is provided for the internal call to
138 -- Set_Msg_Insertion_Line_Number,
140 procedure Set_Msg_Insertion_Unit_Name
;
141 -- Handle unit name insertion ($ insertion character)
143 procedure Set_Msg_Node
(Node
: Node_Id
);
144 -- Add the sequence of characters for the name associated with the
145 -- given node to the current message.
147 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
);
148 -- Add a sequence of characters to the current message. The characters may
149 -- be one of the special insertion characters (see documentation in spec).
150 -- Flag is the location at which the error is to be posted, which is used
151 -- to determine whether or not the # insertion needs a file name. The
152 -- variables Msg_Buffer, Msglen, Is_Style_Msg, Is_Warning_Msg, and
153 -- Is_Unconditional_Msg are set on return.
155 procedure Set_Posted
(N
: Node_Id
);
156 -- Sets the Error_Posted flag on the given node, and all its parents
157 -- that are subexpressions and then on the parent non-subexpression
158 -- construct that contains the original expression (this reduces the
159 -- number of cascaded messages). Note that this call only has an effect
160 -- for a serious error. For a non-serious error, it has no effect.
162 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
);
163 -- Outputs up to N levels of qualification for the given entity. For
164 -- example, the entity A.B.C.D will output B.C. if N = 2.
166 function Special_Msg_Delete
168 N
: Node_Or_Entity_Id
;
169 E
: Node_Or_Entity_Id
) return Boolean;
170 -- This function is called from Error_Msg_NEL, passing the message Msg,
171 -- node N on which the error is to be posted, and the entity or node E
172 -- to be used for an & insertion in the message if any. The job of this
173 -- procedure is to test for certain cascaded messages that we would like
174 -- to suppress. If the message is to be suppressed then we return True.
175 -- If the message should be generated (the normal case) False is returned.
177 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
);
178 -- This procedure is given an entity id for an internal type, i.e.
179 -- a type with an internal name. It unwinds the type to try to get
180 -- to something reasonably printable, generating prefixes like
181 -- "subtype of", "access to", etc along the way in the buffer. The
182 -- value in Ent on return is the final name to be printed. Hopefully
183 -- this is not an internal name, but in some internal name cases, it
184 -- is an internal name, and has to be printed anyway (although in this
185 -- case the message has been killed if possible). The global variable
186 -- Class_Flag is set to True if the resulting entity should have
187 -- 'Class appended to its name (see Add_Class procedure), and is
188 -- otherwise unchanged.
190 procedure VMS_Convert
;
191 -- This procedure has no effect if called when the host is not OpenVMS.
192 -- If the host is indeed OpenVMS, then the error message stored in
193 -- Msg_Buffer is scanned for appearences of switch names which need
194 -- converting to corresponding VMS qualifer names. See Gnames/Vnames
195 -- table in Errout spec for precise definition of the conversion that
196 -- is performed by this routine in OpenVMS mode.
198 -----------------------
199 -- Change_Error_Text --
200 -----------------------
202 procedure Change_Error_Text
(Error_Id
: Error_Msg_Id
; New_Msg
: String) is
203 Save_Next
: Error_Msg_Id
;
204 Err_Id
: Error_Msg_Id
:= Error_Id
;
207 Set_Msg_Text
(New_Msg
, Errors
.Table
(Error_Id
).Sptr
);
208 Errors
.Table
(Error_Id
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
210 -- If in immediate error message mode, output modified error message now
211 -- This is just a bit tricky, because we want to output just a single
212 -- message, and the messages we modified is already linked in. We solve
213 -- this by temporarily resetting its forward pointer to empty.
215 if Debug_Flag_OO then
216 Save_Next := Errors.Table (Error_Id).Next;
217 Errors.Table (Error_Id).Next := No_Error_Msg;
220 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
221 Output_Error_Msgs (Err_Id);
222 Errors.Table (Error_Id).Next := Save_Next;
224 end Change_Error_Text;
230 -- Error_Msg posts a flag at the given location, except that if the
231 -- Flag_Location points within a generic template and corresponds
232 -- to an instantiation of this generic template, then the actual
233 -- message will be posted on the generic instantiation, along with
234 -- additional messages referencing the generic declaration.
236 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
237 Sindex : Source_File_Index;
238 -- Source index for flag location
240 Orig_Loc : Source_Ptr;
241 -- Original location of Flag_Location (i.e. location in original
242 -- template in instantiation case, otherwise unchanged).
245 -- It is a fatal error to issue an error message when scanning from
246 -- the internal source buffer (see Sinput for further documentation)
248 pragma Assert (Sinput.Source /= Internal_Source_Ptr);
250 -- Return if all errors are to be ignored
252 if Errors_Must_Be_Ignored then
256 -- If we already have messages, and we are trying to place a message
257 -- at No_Location or in package Standard, then just ignore the attempt
258 -- since we assume that what is happening is some cascaded junk. Note
259 -- that this is safe in the sense that proceeding will surely bomb.
261 if Flag_Location < First_Source_Ptr
262 and then Total_Errors_Detected > 0
267 -- Start procesing of new message
269 Sindex := Get_Source_File_Index (Flag_Location);
270 Test_Style_Warning_Serious_Msg (Msg);
271 Orig_Loc := Original_Location (Flag_Location);
273 -- If the current location is in an instantiation, the issue arises
274 -- of whether to post the message on the template or the instantiation.
276 -- The way we decide is to see if we have posted the same message
277 -- on the template when we compiled the template (the template is
278 -- always compiled before any instantiations). For this purpose,
279 -- we use a separate table of messages. The reason we do this is
282 -- First, the messages can get changed by various processing
283 -- including the insertion of tokens etc, making it hard to
284 -- do the comparison.
286 -- Second, we will suppress a warning on a template if it is
287 -- not in the current extended source unit. That's reasonable
288 -- and means we don't want the warning on the instantiation
289 -- here either, but it does mean that the main error table
290 -- would not in any case include the message.
292 if Flag_Location = Orig_Loc then
293 Non_Instance_Msgs.Append ((new String'(Msg
), Flag_Location
));
294 Warn_On_Instance
:= False;
296 -- Here we have an instance message
299 -- Delete if debug flag off, and this message duplicates a
300 -- message already posted on the corresponding template
302 if not Debug_Flag_GG
then
303 for J
in Non_Instance_Msgs
.First
.. Non_Instance_Msgs
.Last
loop
304 if Msg
= Non_Instance_Msgs
.Table
(J
).Msg
.all
305 and then Non_Instance_Msgs
.Table
(J
).Loc
= Orig_Loc
312 -- No duplicate, so error/warning will be posted on instance
314 Warn_On_Instance
:= Is_Warning_Msg
;
317 -- Ignore warning message that is suppressed. Note that style
318 -- checks are not considered warning messages for this purpose
320 if Is_Warning_Msg
and then Warnings_Suppressed
(Orig_Loc
) then
324 -- The idea at this stage is that we have two kinds of messages
326 -- First, we have those messages that are to be placed as requested at
327 -- Flag_Location. This includes messages that have nothing to do with
328 -- generics, and also messages placed on generic templates that reflect
329 -- an error in the template itself. For such messages we simply call
330 -- Error_Msg_Internal to place the message in the requested location.
332 if Instantiation
(Sindex
) = No_Location
then
333 Error_Msg_Internal
(Msg
, Flag_Location
, Flag_Location
, False);
337 -- If we are trying to flag an error in an instantiation, we may have
338 -- a generic contract violation. What we generate in this case is:
340 -- instantiation error at ...
341 -- original error message
345 -- warning: in instantiation at
346 -- warning: original warning message
348 -- All these messages are posted at the location of the top level
349 -- instantiation. If there are nested instantiations, then the
350 -- instantiation error message can be repeated, pointing to each
351 -- of the relevant instantiations.
353 -- Note: the instantiation mechanism is also shared for inlining
354 -- of subprogram bodies when front end inlining is done. In this
355 -- case the messages have the form:
357 -- in inlined body at ...
358 -- original error message
362 -- warning: in inlined body at
363 -- warning: original warning message
365 -- OK, this is the case where we have an instantiation error, and
366 -- we need to generate the error on the instantiation, rather than
370 Actual_Error_Loc
: Source_Ptr
;
371 -- Location of outer level instantiation in instantiation case, or
372 -- just a copy of Flag_Location in the normal case. This is the
373 -- location where all error messages will actually be posted.
375 Save_Error_Msg_Sloc
: constant Source_Ptr
:= Error_Msg_Sloc
;
376 -- Save possible location set for caller's message. We need to
377 -- use Error_Msg_Sloc for the location of the instantiation error
378 -- but we have to preserve a possible original value.
380 X
: Source_File_Index
;
382 Msg_Cont_Status
: Boolean;
383 -- Used to label continuation lines in instantiation case with
384 -- proper Msg_Cont status.
387 -- Loop to find highest level instantiation, where all error
388 -- messages will be placed.
392 Actual_Error_Loc
:= Instantiation
(X
);
393 X
:= Get_Source_File_Index
(Actual_Error_Loc
);
394 exit when Instantiation
(X
) = No_Location
;
397 -- Since we are generating the messages at the instantiation
398 -- point in any case, we do not want the references to the
399 -- bad lines in the instance to be annotated with the location
400 -- of the instantiation.
402 Suppress_Instance_Location
:= True;
403 Msg_Cont_Status
:= False;
405 -- Loop to generate instantiation messages
407 Error_Msg_Sloc
:= Flag_Location
;
408 X
:= Get_Source_File_Index
(Flag_Location
);
410 while Instantiation
(X
) /= No_Location
loop
412 -- Suppress instantiation message on continuation lines
414 if Msg
(Msg
'First) /= '\' then
416 -- Case of inlined body
418 if Inlined_Body
(X
) then
419 if Is_Warning_Msg
then
421 ("?in inlined body #",
422 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
426 ("error in inlined body #",
427 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
430 -- Case of generic instantiation
433 if Is_Warning_Msg
then
435 ("?in instantiation #",
436 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
440 ("instantiation error #",
441 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
446 Error_Msg_Sloc
:= Instantiation
(X
);
447 X
:= Get_Source_File_Index
(Error_Msg_Sloc
);
448 Msg_Cont_Status
:= True;
451 Suppress_Instance_Location
:= False;
452 Error_Msg_Sloc
:= Save_Error_Msg_Sloc
;
454 -- Here we output the original message on the outer instantiation
457 (Msg
, Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
465 procedure Error_Msg_AP
(Msg
: String) is
470 -- If we had saved the Scan_Ptr value after scanning the previous
471 -- token, then we would have exactly the right place for putting
472 -- the flag immediately at hand. However, that would add at least
473 -- two instructions to a Scan call *just* to service the possibility
474 -- of an Error_Msg_AP call. So instead we reconstruct that value.
476 -- We have two possibilities, start with Prev_Token_Ptr and skip over
477 -- the current token, which is made harder by the possibility that this
478 -- token may be in error, or start with Token_Ptr and work backwards.
479 -- We used to take the second approach, but it's hard because of
480 -- comments, and harder still because things that look like comments
481 -- can appear inside strings. So now we take the first approach.
483 -- Note: in the case where there is no previous token, Prev_Token_Ptr
484 -- is set to Source_First, which is a reasonable position for the
485 -- error flag in this situation.
487 S1
:= Prev_Token_Ptr
;
490 -- If the previous token is a string literal, we need a special approach
491 -- since there may be white space inside the literal and we don't want
492 -- to stop on that white space.
494 -- Note: since this is an error recovery issue anyway, it is not worth
495 -- worrying about special UTF_32 line terminator characters here.
497 if Prev_Token
= Tok_String_Literal
then
501 if Source
(S1
) = C
then
503 exit when Source
(S1
) /= C
;
504 elsif Source
(S1
) in Line_Terminator
then
509 -- Character literal also needs special handling
511 elsif Prev_Token
= Tok_Char_Literal
then
514 -- Otherwise we search forward for the end of the current token, marked
515 -- by a line terminator, white space, a comment symbol or if we bump
516 -- into the following token (i.e. the current token).
518 -- Again, it is not worth worrying about UTF_32 special line terminator
519 -- characters in this context, since this is only for error recovery.
522 while Source
(S1
) not in Line_Terminator
523 and then Source
(S1
) /= ' '
524 and then Source
(S1
) /= ASCII
.HT
525 and then (Source
(S1
) /= '-' or else Source
(S1
+ 1) /= '-')
526 and then S1
/= Token_Ptr
532 -- S1 is now set to the location for the flag
541 procedure Error_Msg_BC
(Msg
: String) is
543 -- If we are at end of file, post the flag after the previous token
545 if Token
= Tok_EOF
then
548 -- If we are at start of file, post the flag at the current token
550 elsif Token_Ptr
= Source_First
(Current_Source_File
) then
553 -- If the character before the current token is a space or a horizontal
554 -- tab, then we place the flag on this character (in the case of a tab
555 -- we would really like to place it in the "last" character of the tab
556 -- space, but that it too much trouble to worry about).
558 elsif Source
(Token_Ptr
- 1) = ' '
559 or else Source
(Token_Ptr
- 1) = ASCII
.HT
561 Error_Msg
(Msg
, Token_Ptr
- 1);
563 -- If there is no space or tab before the current token, then there is
564 -- no room to place the flag before the token, so we place it on the
565 -- token instead (this happens for example at the start of a line).
568 Error_Msg
(Msg
, Token_Ptr
);
576 procedure Error_Msg_CRT
(Feature
: String; N
: Node_Id
) is
577 CNRT
: constant String := " not allowed in no run time mode";
578 CCRT
: constant String := " not supported by configuration>";
580 S
: String (1 .. Feature
'Length + 1 + CCRT
'Length);
585 S
(2 .. Feature
'Length + 1) := Feature
;
586 L
:= Feature
'Length + 2;
588 if No_Run_Time_Mode
then
589 S
(L
.. L
+ CNRT
'Length - 1) := CNRT
;
590 L
:= L
+ CNRT
'Length - 1;
592 else pragma Assert
(Configurable_Run_Time_Mode
);
593 S
(L
.. L
+ CCRT
'Length - 1) := CCRT
;
594 L
:= L
+ CCRT
'Length - 1;
597 Error_Msg_N
(S
(1 .. L
), N
);
598 Configurable_Run_Time_Violations
:= Configurable_Run_Time_Violations
+ 1;
605 procedure Error_Msg_F
(Msg
: String; N
: Node_Id
) is
607 Error_Msg_NEL
(Msg
, N
, N
, Sloc
(First_Node
(N
)));
614 procedure Error_Msg_FE
617 E
: Node_Or_Entity_Id
)
620 Error_Msg_NEL
(Msg
, N
, E
, Sloc
(First_Node
(N
)));
623 ------------------------
624 -- Error_Msg_Internal --
625 ------------------------
627 procedure Error_Msg_Internal
633 Next_Msg
: Error_Msg_Id
;
634 -- Pointer to next message at insertion point
636 Prev_Msg
: Error_Msg_Id
;
637 -- Pointer to previous message at insertion point
639 Temp_Msg
: Error_Msg_Id
;
641 procedure Handle_Serious_Error
;
642 -- Internal procedure to do all error message handling for a serious
643 -- error message, other than bumping the error counts and arranging
644 -- for the message to be output.
646 --------------------------
647 -- Handle_Serious_Error --
648 --------------------------
650 procedure Handle_Serious_Error
is
652 -- Turn off code generation if not done already
654 if Operating_Mode
= Generate_Code
then
655 Operating_Mode
:= Check_Semantics
;
656 Expander_Active
:= False;
659 -- Set the fatal error flag in the unit table unless we are
660 -- in Try_Semantics mode. This stops the semantics from being
661 -- performed if we find a serious error. This is skipped if we
662 -- are currently dealing with the configuration pragma file.
665 and then Current_Source_Unit
/= No_Unit
667 Set_Fatal_Error
(Get_Source_Unit
(Sptr
));
669 end Handle_Serious_Error
;
671 -- Start of processing for Error_Msg_Internal
674 if Raise_Exception_On_Error
/= 0 then
675 raise Error_Msg_Exception
;
678 Continuation
:= Msg_Cont
;
679 Suppress_Message
:= False;
680 Kill_Message
:= False;
681 Set_Msg_Text
(Msg
, Sptr
);
683 -- Kill continuation if parent message killed
685 if Continuation
and Last_Killed
then
689 -- Return without doing anything if message is suppressed
692 and not All_Errors_Mode
693 and not (Msg
(Msg
'Last) = '!')
694 and not Is_Warning_Msg
696 if not Continuation
then
703 -- Return without doing anything if message is killed and this
704 -- is not the first error message. The philosophy is that if we
705 -- get a weird error message and we already have had a message,
706 -- then we hope the weird message is a junk cascaded message
709 and then not All_Errors_Mode
710 and then Total_Errors_Detected
/= 0
712 if not Continuation
then
719 -- Special check for warning message to see if it should be output
721 if Is_Warning_Msg
then
723 -- Immediate return if warning message and warnings are suppressed
725 if Warnings_Suppressed
(Optr
)
726 or else Warnings_Suppressed
(Sptr
)
728 Cur_Msg
:= No_Error_Msg
;
732 -- If the flag location is in the main extended source unit
733 -- then for sure we want the warning since it definitely belongs
735 if In_Extended_Main_Source_Unit
(Sptr
) then
738 -- If the flag location is not in the main extended source
739 -- unit then we want to eliminate the warning.
741 elsif In_Extended_Main_Code_Unit
(Sptr
)
742 and then Warn_On_Instance
746 -- Keep warning if debug flag G set
748 elsif Debug_Flag_GG
then
751 -- Here is where we delete a warning from a with'ed unit
754 Cur_Msg
:= No_Error_Msg
;
759 -- If message is to be ignored in special ignore message mode, this is
760 -- where we do this special processing, bypassing message output.
762 if Ignore_Errors_Enable
> 0 then
763 if Is_Serious_Error
then
764 Handle_Serious_Error
;
770 -- Otherwise build error message object for new message
772 Errors
.Increment_Last
;
773 Cur_Msg
:= Errors
.Last
;
774 Errors
.Table
(Cur_Msg
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
775 Errors.Table (Cur_Msg).Next := No_Error_Msg;
776 Errors.Table (Cur_Msg).Sptr := Sptr;
777 Errors.Table (Cur_Msg).Optr := Optr;
778 Errors.Table (Cur_Msg).Sfile := Get_Source_File_Index (Sptr);
779 Errors.Table (Cur_Msg).Line := Get_Physical_Line_Number (Sptr);
780 Errors.Table (Cur_Msg).Col := Get_Column_Number (Sptr);
781 Errors.Table (Cur_Msg).Warn := Is_Warning_Msg;
782 Errors.Table (Cur_Msg).Style := Is_Style_Msg;
783 Errors.Table (Cur_Msg).Serious := Is_Serious_Error;
784 Errors.Table (Cur_Msg).Uncond
785 := Is_Unconditional_Msg or Is_Warning_Msg;
786 Errors.Table (Cur_Msg).Msg_Cont := Continuation;
787 Errors.Table (Cur_Msg).Deleted := False;
789 -- If immediate errors mode set, output error message now. Also output
790 -- now if the -d1 debug flag is set (so node number message comes out
791 -- just before actual error message)
793 if Debug_Flag_OO or else Debug_Flag_1 then
795 Output_Source_Line (Errors.Table (Cur_Msg).Line,
796 Errors.Table (Cur_Msg).Sfile, True);
798 Output_Error_Msgs (Temp_Msg);
800 -- If not in immediate errors mode, then we insert the message in the
801 -- error chain for later output by Finalize. The messages are sorted
802 -- first by unit (main unit comes first), and within a unit by source
803 -- location (earlier flag location first in the chain).
806 -- First a quick check, does this belong at the very end of the
807 -- chain of error messages. This saves a lot of time in the
808 -- normal case if there are lots of messages.
810 if Last_Error_Msg /= No_Error_Msg
811 and then Errors.Table (Cur_Msg).Sfile =
812 Errors.Table (Last_Error_Msg).Sfile
813 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
815 (Sptr = Errors.Table (Last_Error_Msg).Sptr
817 Optr > Errors.Table (Last_Error_Msg).Optr))
819 Prev_Msg := Last_Error_Msg;
820 Next_Msg := No_Error_Msg;
822 -- Otherwise do a full sequential search for the insertion point
825 Prev_Msg := No_Error_Msg;
826 Next_Msg := First_Error_Msg;
827 while Next_Msg /= No_Error_Msg loop
829 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
831 if Errors.Table (Cur_Msg).Sfile =
832 Errors.Table (Next_Msg).Sfile
834 exit when Sptr < Errors.Table (Next_Msg).Sptr
836 (Sptr = Errors.Table (Next_Msg).Sptr
838 Optr < Errors.Table (Next_Msg).Optr);
841 Prev_Msg := Next_Msg;
842 Next_Msg := Errors.Table (Next_Msg).Next;
846 -- Now we insert the new message in the error chain. The insertion
847 -- point for the message is after Prev_Msg and before Next_Msg.
849 -- The possible insertion point for the new message is after Prev_Msg
850 -- and before Next_Msg. However, this is where we do a special check
851 -- for redundant parsing messages, defined as messages posted on the
852 -- same line. The idea here is that probably such messages are junk
853 -- from the parser recovering. In full errors mode, we don't do this
854 -- deletion, but otherwise such messages are discarded at this stage.
856 if Prev_Msg /= No_Error_Msg
857 and then Errors.Table (Prev_Msg).Line =
858 Errors.Table (Cur_Msg).Line
859 and then Errors.Table (Prev_Msg).Sfile =
860 Errors.Table (Cur_Msg).Sfile
861 and then Compiler_State = Parsing
862 and then not All_Errors_Mode
864 -- Don't delete unconditional messages and at this stage,
865 -- don't delete continuation lines (we attempted to delete
866 -- those earlier if the parent message was deleted.
868 if not Errors.Table (Cur_Msg).Uncond
869 and then not Continuation
871 -- Don't delete if prev msg is warning and new msg is
872 -- an error. This is because we don't want a real error
873 -- masked by a warning. In all other cases (that is parse
874 -- errors for the same line that are not unconditional)
875 -- we do delete the message. This helps to avoid
876 -- junk extra messages from cascaded parsing errors
878 if not (Errors.Table (Prev_Msg).Warn
880 Errors.Table (Prev_Msg).Style)
882 (Errors.Table (Cur_Msg).Warn
884 Errors.Table (Cur_Msg).Style)
886 -- All tests passed, delete the message by simply
887 -- returning without any further processing.
889 if not Continuation then
898 -- Come here if message is to be inserted in the error chain
900 if not Continuation then
901 Last_Killed := False;
904 if Prev_Msg = No_Error_Msg then
905 First_Error_Msg := Cur_Msg;
907 Errors.Table (Prev_Msg).Next := Cur_Msg;
910 Errors.Table (Cur_Msg).Next := Next_Msg;
912 if Next_Msg = No_Error_Msg then
913 Last_Error_Msg := Cur_Msg;
917 -- Bump appropriate statistics count
919 if Errors.Table (Cur_Msg).Warn
920 or else Errors.Table (Cur_Msg).Style
922 Warnings_Detected := Warnings_Detected + 1;
924 Total_Errors_Detected := Total_Errors_Detected + 1;
926 if Errors.Table (Cur_Msg).Serious then
927 Serious_Errors_Detected := Serious_Errors_Detected + 1;
928 Handle_Serious_Error;
932 -- Terminate if max errors reached
934 if Total_Errors_Detected + Warnings_Detected = Maximum_Errors then
935 raise Unrecoverable_Error;
938 end Error_Msg_Internal;
944 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
946 Error_Msg_NEL (Msg, N, N, Sloc (N));
953 procedure Error_Msg_NE
955 N : Node_Or_Entity_Id;
956 E : Node_Or_Entity_Id)
959 Error_Msg_NEL (Msg, N, E, Sloc (N));
966 procedure Error_Msg_NEL
968 N : Node_Or_Entity_Id;
969 E : Node_Or_Entity_Id;
970 Flag_Location : Source_Ptr)
973 if Special_Msg_Delete (Msg, N, E) then
977 Test_Style_Warning_Serious_Msg (Msg);
979 -- Special handling for warning messages
981 if Is_Warning_Msg then
983 -- Suppress if no warnings set for either entity or node
985 if No_Warnings (N) or else No_Warnings (E) then
989 -- Suppress if inside loop that is known to be null
996 while Present (P) loop
997 if Nkind (P) = N_Loop_Statement and then Is_Null_Loop (P) then
1006 -- Test for message to be output
1009 or else Msg (Msg'Last) = '!'
1010 or else Is_Warning_Msg
1012 or else (Msg (Msg'First) = '\
' and not Last_Killed)
1015 Error_Msg_Node_1 := E;
1016 Error_Msg (Msg, Flag_Location);
1019 Last_Killed := True;
1022 if not Is_Warning_Msg and then not Is_Style_Msg then
1031 procedure Error_Msg_NW
1034 N : Node_Or_Entity_Id)
1038 and then In_Extended_Main_Source_Unit (N)
1039 and then Comes_From_Source (N)
1041 Error_Msg_NEL (Msg, N, N, Sloc (N));
1049 procedure Error_Msg_S (Msg : String) is
1051 Error_Msg (Msg, Scan_Ptr);
1058 procedure Error_Msg_SC (Msg : String) is
1060 -- If we are at end of file, post the flag after the previous token
1062 if Token = Tok_EOF then
1065 -- For all other cases the message is posted at the current token
1069 Error_Msg (Msg, Token_Ptr);
1077 procedure Error_Msg_SP (Msg : String) is
1079 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1080 -- is set to Source_First, which is a reasonable position for the
1081 -- error flag in this situation
1083 Error_Msg (Msg, Prev_Token_Ptr);
1090 procedure Finalize is
1093 E, F : Error_Msg_Id;
1097 -- Reset current error source file if the main unit has a pragma
1098 -- Source_Reference. This ensures outputting the proper name of
1099 -- the source file in this situation.
1101 if Main_Source_File = No_Source_File or else
1102 Num_SRef_Pragmas (Main_Source_File) /= 0
1104 Current_Error_Source_File := No_Source_File;
1107 -- Eliminate any duplicated error messages from the list. This is
1108 -- done after the fact to avoid problems with Change_Error_Text.
1110 Cur := First_Error_Msg;
1111 while Cur /= No_Error_Msg loop
1112 Nxt := Errors.Table (Cur).Next;
1115 while F /= No_Error_Msg
1116 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1118 Check_Duplicate_Message (Cur, F);
1119 F := Errors.Table (F).Next;
1127 if Brief_Output or (not Full_List and not Verbose_Mode) then
1130 E := First_Error_Msg;
1131 while E /= No_Error_Msg loop
1132 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1133 if Full_Path_Name_For_Brief_Errors then
1134 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1136 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1140 Write_Int (Int (Physical_To_Logical
1141 (Errors.Table (E).Line,
1142 Errors.Table (E).Sfile)));
1145 if Errors.Table (E).Col < 10 then
1149 Write_Int (Int (Errors.Table (E).Col));
1151 Output_Msg_Text (E);
1155 E := Errors.Table (E).Next;
1158 Set_Standard_Output;
1161 -- Full source listing case
1164 List_Pragmas_Index := 1;
1165 List_Pragmas_Mode := True;
1166 E := First_Error_Msg;
1169 -- First list initial main source file with its error messages
1171 for N in 1 .. Last_Source_Line (Main_Source_File) loop
1174 and then Errors.Table (E).Line = N
1175 and then Errors.Table (E).Sfile = Main_Source_File;
1177 Output_Source_Line (N, Main_Source_File, Err_Flag);
1180 Output_Error_Msgs (E);
1182 if not Debug_Flag_2 then
1189 -- Then output errors, if any, for subsidiary units
1191 while E /= No_Error_Msg
1192 and then Errors.Table (E).Sfile /= Main_Source_File
1196 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1197 Output_Error_Msgs (E);
1201 -- Verbose mode (error lines only with error flags)
1203 if Verbose_Mode and not Full_List then
1204 E := First_Error_Msg;
1206 -- Loop through error lines
1208 while E /= No_Error_Msg loop
1211 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1212 Output_Error_Msgs (E);
1216 -- Output error summary if verbose or full list mode
1218 if Verbose_Mode or else Full_List then
1220 -- Extra blank line if error messages or source listing were output
1222 if Total_Errors_Detected + Warnings_Detected > 0
1228 -- Message giving number of lines read and number of errors detected.
1229 -- This normally goes to Standard_Output. The exception is when brief
1230 -- mode is not set, verbose mode (or full list mode) is set, and
1231 -- there are errors. In this case we send the message to standard
1232 -- error to make sure that *something* appears on standard error in
1233 -- an error situation.
1235 -- Formerly, only the "# errors" suffix was sent to stderr, whereas
1236 -- "# lines:" appeared on stdout. This caused problems on VMS when
1237 -- the stdout buffer was flushed, giving an extra line feed after
1240 if Total_Errors_Detected + Warnings_Detected /= 0
1241 and then not Brief_Output
1242 and then (Verbose_Mode or Full_List)
1247 -- Message giving total number of lines
1250 Write_Int (Num_Source_Lines (Main_Source_File));
1252 if Num_Source_Lines (Main_Source_File) = 1 then
1253 Write_Str (" line: ");
1255 Write_Str (" lines: ");
1258 if Total_Errors_Detected = 0 then
1259 Write_Str ("No errors");
1261 elsif Total_Errors_Detected = 1 then
1262 Write_Str ("1 error");
1265 Write_Int (Total_Errors_Detected);
1266 Write_Str (" errors");
1269 if Warnings_Detected /= 0 then
1271 Write_Int (Warnings_Detected);
1272 Write_Str (" warning");
1274 if Warnings_Detected /= 1 then
1278 if Warning_Mode = Treat_As_Error then
1279 Write_Str (" (treated as error");
1281 if Warnings_Detected /= 1 then
1290 Set_Standard_Output;
1293 if Maximum_Errors /= 0
1294 and then Total_Errors_Detected + Warnings_Detected = Maximum_Errors
1297 Write_Str ("fatal error: maximum errors reached");
1299 Set_Standard_Output;
1302 if Warning_Mode = Treat_As_Error then
1303 Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected;
1304 Warnings_Detected := 0;
1312 function First_Node (C : Node_Id) return Node_Id is
1313 L : constant Source_Ptr := Sloc (C);
1314 Sfile : constant Source_File_Index := Get_Source_File_Index (L);
1317 Discard : Traverse_Result;
1319 pragma Warnings (Off, Discard);
1321 function Test_Earlier (N : Node_Id) return Traverse_Result;
1322 -- Function applied to every node in the construct
1324 function Search_Tree_First is new Traverse_Func (Test_Earlier);
1325 -- Create traversal function
1331 function Test_Earlier (N : Node_Id) return Traverse_Result is
1332 Loc : constant Source_Ptr := Sloc (N);
1335 -- Check for earlier. The tests for being in the same file ensures
1336 -- against strange cases of foreign code somehow being present. We
1337 -- don't want wild placement of messages if that happens, so it is
1338 -- best to just ignore this situation.
1341 and then Get_Source_File_Index (Loc) = Sfile
1350 -- Start of processing for First_Node
1353 Earliest := Original_Node (C);
1354 Eloc := Sloc (Earliest);
1355 Discard := Search_Tree_First (Original_Node (C));
1363 function First_Sloc (N : Node_Id) return Source_Ptr is
1364 SI : constant Source_File_Index := Source_Index (Get_Source_Unit (N));
1365 SF : constant Source_Ptr := Source_First (SI);
1370 F := First_Node (N);
1373 -- The following circuit is a bit subtle. When we have parenthesized
1374 -- expressions, then the Sloc will not record the location of the
1375 -- paren, but we would like to post the flag on the paren. So what
1376 -- we do is to crawl up the tree from the First_Node, adjusting the
1377 -- Sloc value for any parentheses we know are present. Yes, we know
1378 -- this circuit is not 100% reliable (e.g. because we don't record
1379 -- all possible paren level valoues), but this is only for an error
1380 -- message so it is good enough.
1383 Paren_Loop : for J in 1 .. Paren_Count (F) loop
1385 -- We don't look more than 12 characters behind the current
1386 -- location, and in any case not past the front of the source.
1388 Search_Loop : for K in 1 .. 12 loop
1389 exit Search_Loop when S = SF;
1391 if Source_Text (SI) (S - 1) = '(' then
1395 elsif Source_Text (SI) (S - 1) <= ' ' then
1401 end loop Search_Loop;
1402 end loop Paren_Loop;
1404 exit Node_Loop when F = N;
1406 exit Node_Loop when Nkind (F) not in N_Subexpr;
1416 procedure Initialize is
1419 First_Error_Msg := No_Error_Msg;
1420 Last_Error_Msg := No_Error_Msg;
1421 Serious_Errors_Detected := 0;
1422 Total_Errors_Detected := 0;
1423 Warnings_Detected := 0;
1424 Cur_Msg := No_Error_Msg;
1427 -- Initialize warnings table, if all warnings are suppressed, supply
1428 -- an initial dummy entry covering all possible source locations.
1432 if Warning_Mode = Suppress then
1433 Warnings.Increment_Last;
1434 Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
1435 Warnings.Table (Warnings.Last).Stop := Source_Ptr'Last;
1443 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1445 if Error_Posted (N) then
1448 elsif Nkind (N) in N_Entity and then Warnings_Off (N) then
1451 elsif Is_Entity_Name (N)
1452 and then Present (Entity (N))
1453 and then Warnings_Off (Entity (N))
1466 function OK_Node (N : Node_Id) return Boolean is
1467 K : constant Node_Kind := Nkind (N);
1470 if Error_Posted (N) then
1473 elsif K in N_Has_Etype
1474 and then Present (Etype (N))
1475 and then Error_Posted (Etype (N))
1480 or else K = N_Attribute_Reference
1481 or else K = N_Character_Literal
1482 or else K = N_Expanded_Name
1483 or else K = N_Identifier
1484 or else K = N_Operator_Symbol)
1485 and then Present (Entity (N))
1486 and then Error_Posted (Entity (N))
1494 ------------------------
1495 -- Output_Source_Line --
1496 ------------------------
1498 procedure Output_Source_Line
1499 (L : Physical_Line_Number;
1500 Sfile : Source_File_Index;
1506 Line_Number_Output : Boolean := False;
1507 -- Set True once line number is output
1510 if Sfile /= Current_Error_Source_File then
1511 Write_Str ("==============Error messages for ");
1513 case Sinput.File_Type (Sfile) is
1515 Write_Str ("source");
1517 when Sinput.Config =>
1518 Write_Str ("configuration pragmas");
1521 Write_Str ("symbol definition");
1523 when Sinput.Preproc =>
1524 Write_Str ("preprocessing data");
1527 Write_Str (" file: ");
1528 Write_Name (Full_File_Name (Sfile));
1531 if Num_SRef_Pragmas (Sfile) > 0 then
1532 Write_Str ("--------------Line numbers from file: ");
1533 Write_Name (Full_Ref_Name (Sfile));
1534 Write_Str (" (starting at line ");
1535 Write_Int (Int (First_Mapped_Line (Sfile)));
1540 Current_Error_Source_File := Sfile;
1543 if Errs or List_Pragmas_Mode then
1544 Output_Line_Number (Physical_To_Logical (L, Sfile));
1545 Line_Number_Output := True;
1548 S := Line_Start (L, Sfile);
1551 C := Source_Text (Sfile) (S);
1552 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
1554 -- Deal with matching entry in List_Pragmas table
1557 and then List_Pragmas_Index <= List_Pragmas.Last
1558 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
1560 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
1564 -- Ignore if on line with errors so that error flags
1565 -- get properly listed with the error line .
1568 Write_Char (ASCII.FF);
1572 List_Pragmas_Mode := True;
1574 if not Line_Number_Output then
1575 Output_Line_Number (Physical_To_Logical (L, Sfile));
1576 Line_Number_Output := True;
1583 List_Pragmas_Mode := False;
1586 List_Pragmas_Index := List_Pragmas_Index + 1;
1588 -- Normal case (no matching entry in List_Pragmas table)
1591 if Errs or List_Pragmas_Mode then
1599 if Line_Number_Output then
1602 end Output_Source_Line;
1604 -----------------------------
1605 -- Remove_Warning_Messages --
1606 -----------------------------
1608 procedure Remove_Warning_Messages (N : Node_Id) is
1610 function Check_For_Warning (N : Node_Id) return Traverse_Result;
1611 -- This function checks one node for a possible warning message
1613 function Check_All_Warnings is new
1614 Traverse_Func (Check_For_Warning);
1615 -- This defines the traversal operation
1617 -----------------------
1618 -- Check_For_Warning --
1619 -----------------------
1621 function Check_For_Warning (N : Node_Id) return Traverse_Result is
1622 Loc : constant Source_Ptr := Sloc (N);
1625 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
1626 -- Returns True for a message that is to be removed. Also adjusts
1627 -- warning count appropriately.
1633 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
1635 if E /= No_Error_Msg
1636 and then Errors.Table (E).Optr = Loc
1637 and then (Errors.Table (E).Warn or Errors.Table (E).Style)
1639 Warnings_Detected := Warnings_Detected - 1;
1646 -- Start of processing for Check_For_Warnings
1649 while To_Be_Removed (First_Error_Msg) loop
1650 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
1653 if First_Error_Msg = No_Error_Msg then
1654 Last_Error_Msg := No_Error_Msg;
1657 E := First_Error_Msg;
1658 while E /= No_Error_Msg loop
1659 while To_Be_Removed (Errors.Table (E).Next) loop
1660 Errors.Table (E).Next :=
1661 Errors.Table (Errors.Table (E).Next).Next;
1663 if Errors.Table (E).Next = No_Error_Msg then
1664 Last_Error_Msg := E;
1668 E := Errors.Table (E).Next;
1671 if Nkind (N) = N_Raise_Constraint_Error
1672 and then Original_Node (N) /= N
1673 and then No (Condition (N))
1675 -- Warnings may have been posted on subexpressions of
1676 -- the original tree. We place the original node back
1677 -- on the tree to remove those warnings, whose sloc
1678 -- do not match those of any node in the current tree.
1679 -- Given that we are in unreachable code, this modification
1680 -- to the tree is harmless.
1683 Status : Traverse_Result;
1686 if Is_List_Member (N) then
1687 Set_Condition (N, Original_Node (N));
1688 Status := Check_All_Warnings (Condition (N));
1690 Rewrite (N, Original_Node (N));
1691 Status := Check_All_Warnings (N);
1700 end Check_For_Warning;
1702 -- Start of processing for Remove_Warning_Messages
1705 if Warnings_Detected /= 0 then
1707 Discard : Traverse_Result;
1708 pragma Warnings (Off, Discard);
1711 Discard := Check_All_Warnings (N);
1714 end Remove_Warning_Messages;
1716 procedure Remove_Warning_Messages (L : List_Id) is
1719 if Is_Non_Empty_List (L) then
1722 while Present (Stat) loop
1723 Remove_Warning_Messages (Stat);
1727 end Remove_Warning_Messages;
1729 ---------------------------
1730 -- Set_Identifier_Casing --
1731 ---------------------------
1733 procedure Set_Identifier_Casing
1734 (Identifier_Name : System.Address;
1735 File_Name : System.Address)
1737 type Big_String is array (Positive) of Character;
1738 type Big_String_Ptr is access all Big_String;
1740 function To_Big_String_Ptr is new Unchecked_Conversion
1741 (System.Address, Big_String_Ptr);
1743 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
1744 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
1747 Desired_Case : Casing_Type := Mixed_Case;
1748 -- Casing required for result. Default value of Mixed_Case is used if
1749 -- for some reason we cannot find the right file name in the table.
1752 -- Get length of file name
1755 while File (Flen + 1) /= ASCII.NUL loop
1759 -- Loop through file names to find matching one. This is a bit slow,
1760 -- but we only do it in error situations so it is not so terrible.
1761 -- Note that if the loop does not exit, then the desired case will
1762 -- be left set to Mixed_Case, this can happen if the name was not
1763 -- in canonical form, and gets canonicalized on VMS. Possibly we
1764 -- could fix this by unconditinally canonicalizing these names ???
1766 for J in 1 .. Last_Source_File loop
1767 Get_Name_String (Full_Debug_Name (J));
1770 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
1772 Desired_Case := Identifier_Casing (J);
1777 -- Copy identifier as given to Name_Buffer
1779 for J in Name_Buffer'Range loop
1780 Name_Buffer (J) := Ident (J);
1782 if Name_Buffer (J) = ASCII.Nul then
1788 Set_Casing (Desired_Case);
1789 end Set_Identifier_Casing;
1791 -----------------------
1792 -- Set_Ignore_Errors --
1793 -----------------------
1795 procedure Set_Ignore_Errors (To : Boolean) is
1797 Errors_Must_Be_Ignored := To;
1798 end Set_Ignore_Errors;
1800 ------------------------------
1801 -- Set_Msg_Insertion_Column --
1802 ------------------------------
1804 procedure Set_Msg_Insertion_Column is
1806 if Style.RM_Column_Check then
1807 Set_Msg_Str (" in column ");
1808 Set_Msg_Int (Int (Error_Msg_Col) + 1);
1810 end Set_Msg_Insertion_Column;
1812 ----------------------------
1813 -- Set_Msg_Insertion_Node --
1814 ----------------------------
1816 procedure Set_Msg_Insertion_Node is
1821 Error_Msg_Node_1 = Error
1822 or else Error_Msg_Node_1 = Any_Type;
1824 if Error_Msg_Node_1 = Empty then
1825 Set_Msg_Blank_Conditional;
1826 Set_Msg_Str ("<empty>");
1828 elsif Error_Msg_Node_1 = Error then
1830 Set_Msg_Str ("<error>");
1832 elsif Error_Msg_Node_1 = Standard_Void_Type then
1834 Set_Msg_Str ("procedure name");
1837 Set_Msg_Blank_Conditional;
1841 K := Nkind (Error_Msg_Node_1);
1843 -- If we have operator case, skip quotes since name of operator
1844 -- itself will supply the required quotations. An operator can be
1845 -- an applied use in an expression or an explicit operator symbol,
1846 -- or an identifier whose name indicates it is an operator.
1849 or else K = N_Operator_Symbol
1850 or else K = N_Defining_Operator_Symbol
1851 or else ((K = N_Identifier or else K = N_Defining_Identifier)
1852 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
1854 Set_Msg_Node (Error_Msg_Node_1);
1856 -- Normal case, not an operator, surround with quotes
1860 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
1861 Set_Msg_Node (Error_Msg_Node_1);
1866 -- The following assignment ensures that a second ampersand insertion
1867 -- character will correspond to the Error_Msg_Node_2 parameter. We
1868 -- suppress possible validity checks in case operating in -gnatVa mode,
1869 -- and Error_Msg_Node_2 is not needed and has not been set.
1872 pragma Suppress (Range_Check);
1874 Error_Msg_Node_1 := Error_Msg_Node_2;
1876 end Set_Msg_Insertion_Node;
1878 --------------------------------------
1879 -- Set_Msg_Insertion_Type_Reference --
1880 --------------------------------------
1882 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
1888 if Error_Msg_Node_1 = Standard_Void_Type then
1889 Set_Msg_Str ("package or procedure name");
1892 elsif Error_Msg_Node_1 = Standard_Exception_Type then
1893 Set_Msg_Str ("exception name");
1896 elsif Error_Msg_Node_1 = Any_Access
1897 or else Error_Msg_Node_1 = Any_Array
1898 or else Error_Msg_Node_1 = Any_Boolean
1899 or else Error_Msg_Node_1 = Any_Character
1900 or else Error_Msg_Node_1 = Any_Composite
1901 or else Error_Msg_Node_1 = Any_Discrete
1902 or else Error_Msg_Node_1 = Any_Fixed
1903 or else Error_Msg_Node_1 = Any_Integer
1904 or else Error_Msg_Node_1 = Any_Modular
1905 or else Error_Msg_Node_1 = Any_Numeric
1906 or else Error_Msg_Node_1 = Any_Real
1907 or else Error_Msg_Node_1 = Any_Scalar
1908 or else Error_Msg_Node_1 = Any_String
1910 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
1911 Set_Msg_Name_Buffer;
1914 elsif Error_Msg_Node_1 = Universal_Real then
1915 Set_Msg_Str ("type universal real");
1918 elsif Error_Msg_Node_1 = Universal_Integer then
1919 Set_Msg_Str ("type universal integer");
1922 elsif Error_Msg_Node_1 = Universal_Fixed then
1923 Set_Msg_Str ("type universal fixed");
1927 -- Special case of anonymous array
1929 if Nkind (Error_Msg_Node_1) in N_Entity
1930 and then Is_Array_Type (Error_Msg_Node_1)
1931 and then Present (Related_Array_Object (Error_Msg_Node_1))
1933 Set_Msg_Str ("type of ");
1934 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
1935 Set_Msg_Str (" declared");
1936 Set_Msg_Insertion_Line_Number
1937 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
1941 -- If we fall through, it is not a special case, so first output
1942 -- the name of the type, preceded by private for a private type
1944 if Is_Private_Type (Error_Msg_Node_1) then
1945 Set_Msg_Str ("private type ");
1947 Set_Msg_Str ("type ");
1950 Ent := Error_Msg_Node_1;
1952 if Is_Internal_Name (Chars (Ent)) then
1953 Unwind_Internal_Type (Ent);
1956 -- Types in Standard are displayed as "Standard.name"
1958 if Sloc (Ent) <= Standard_Location then
1960 Set_Msg_Str ("Standard.");
1965 -- Types in other language defined units are displayed as
1966 -- "package-name.type-name"
1969 Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Ent)))
1971 Get_Unqualified_Decoded_Name_String
1972 (Unit_Name (Get_Source_Unit (Ent)));
1973 Name_Len := Name_Len - 2;
1975 Set_Casing (Mixed_Case);
1976 Set_Msg_Name_Buffer;
1978 Set_Casing (Mixed_Case);
1983 -- All other types display as "type name" defined at line xxx
1984 -- possibly qualified if qualification is requested.
1988 Set_Qualification (Error_Msg_Qual_Level, Ent);
1994 -- If the original type did not come from a predefined
1995 -- file, add the location where the type was defined.
1997 if Sloc (Error_Msg_Node_1) > Standard_Location
1999 not Is_Predefined_File_Name
2000 (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)))
2002 Set_Msg_Str (" defined");
2003 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
2005 -- If it did come from a predefined file, deal with the case where
2006 -- this was a file with a generic instantiation from elsewhere.
2009 if Sloc (Error_Msg_Node_1) > Standard_Location then
2011 Iloc : constant Source_Ptr :=
2012 Instantiation_Location (Sloc (Error_Msg_Node_1));
2015 if Iloc /= No_Location
2016 and then not Suppress_Instance_Location
2018 Set_Msg_Str (" from instance");
2019 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2024 end Set_Msg_Insertion_Type_Reference;
2026 ---------------------------------
2027 -- Set_Msg_Insertion_Unit_Name --
2028 ---------------------------------
2030 procedure Set_Msg_Insertion_Unit_Name is
2032 if Error_Msg_Unit_1 = No_Name then
2035 elsif Error_Msg_Unit_1 = Error_Name then
2037 Set_Msg_Str ("<error>");
2040 Get_Unit_Name_String (Error_Msg_Unit_1);
2043 Set_Msg_Name_Buffer;
2047 -- The following assignment ensures that a second percent insertion
2048 -- character will correspond to the Error_Msg_Unit_2 parameter. We
2049 -- suppress possible validity checks in case operating in -gnatVa mode,
2050 -- and Error_Msg_Unit_2 is not needed and has not been set.
2053 pragma Suppress (Range_Check);
2055 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2057 end Set_Msg_Insertion_Unit_Name;
2063 procedure Set_Msg_Node (Node : Node_Id) is
2068 if Nkind (Node) = N_Designator then
2069 Set_Msg_Node (Name (Node));
2071 Set_Msg_Node (Identifier (Node));
2074 elsif Nkind (Node) = N_Defining_Program_Unit_Name then
2075 Set_Msg_Node (Name (Node));
2077 Set_Msg_Node (Defining_Identifier (Node));
2080 elsif Nkind (Node) = N_Selected_Component then
2081 Set_Msg_Node (Prefix (Node));
2083 Set_Msg_Node (Selector_Name (Node));
2087 -- The only remaining possibilities are identifiers, defining
2088 -- identifiers, pragmas, and pragma argument associations, i.e.
2089 -- nodes that have a Chars field.
2091 -- Internal names generally represent something gone wrong. An exception
2092 -- is the case of internal type names, where we try to find a reasonable
2093 -- external representation for the external name
2095 if Is_Internal_Name (Chars (Node))
2097 ((Is_Entity_Name (Node)
2098 and then Present (Entity (Node))
2099 and then Is_Type (Entity (Node)))
2101 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2103 if Nkind (Node) = N_Identifier then
2104 Ent := Entity (Node);
2109 Unwind_Internal_Type (Ent);
2113 Nam := Chars (Node);
2116 -- At this stage, the name to output is in Nam
2118 Get_Unqualified_Decoded_Name_String (Nam);
2120 -- Remove trailing upper case letters from the name (useful for
2121 -- dealing with some cases of internal names.
2123 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A
' .. 'Z
' loop
2124 Name_Len := Name_Len - 1;
2127 -- If we have any of the names from standard that start with the
2128 -- characters "any " (e.g. Any_Type), then kill the message since
2129 -- almost certainly it is a junk cascaded message.
2132 and then Name_Buffer (1 .. 4) = "any "
2134 Kill_Message := True;
2137 -- Now we have to set the proper case. If we have a source location
2138 -- then do a check to see if the name in the source is the same name
2139 -- as the name in the Names table, except for possible differences
2140 -- in case, which is the case when we can copy from the source.
2143 Src_Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
2144 Sbuffer : Source_Buffer_Ptr;
2146 Src_Ptr : Source_Ptr;
2152 -- For standard locations, always use mixed case
2154 if Src_Loc <= No_Location
2155 or else Sloc (Node) <= No_Location
2157 Set_Casing (Mixed_Case);
2160 -- Determine if the reference we are dealing with corresponds
2161 -- to text at the point of the error reference. This will often
2162 -- be the case for simple identifier references, and is the case
2163 -- where we can copy the spelling from the source.
2165 Sbuffer := Source_Text (Get_Source_File_Index (Src_Loc));
2167 while Ref_Ptr <= Name_Len loop
2169 Fold_Lower (Sbuffer (Src_Ptr)) /=
2170 Fold_Lower (Name_Buffer (Ref_Ptr));
2171 Ref_Ptr := Ref_Ptr + 1;
2172 Src_Ptr := Src_Ptr + 1;
2175 -- If we get through the loop without a mismatch, then output
2176 -- the name the way it is spelled in the source program
2178 if Ref_Ptr > Name_Len then
2181 for J in 1 .. Name_Len loop
2182 Name_Buffer (J) := Sbuffer (Src_Ptr);
2183 Src_Ptr := Src_Ptr + 1;
2186 -- Otherwise set the casing using the default identifier casing
2189 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
2194 Set_Msg_Name_Buffer;
2202 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2203 C : Character; -- Current character
2204 P : Natural; -- Current index;
2207 Manual_Quote_Mode := False;
2208 Is_Unconditional_Msg := False;
2210 Flag_Source := Get_Source_File_Index (Flag);
2213 while P <= Text'Last loop
2217 -- Check for insertion character
2221 Set_Msg_Insertion_Name;
2224 Set_Msg_Insertion_Unit_Name;
2227 Set_Msg_Insertion_File_Name;
2230 Set_Msg_Insertion_Type_Reference (Flag);
2233 Set_Msg_Insertion_Reserved_Name;
2236 Set_Msg_Insertion_Node;
2239 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
2242 Continuation := True;
2245 Set_Msg_Insertion_Column;
2248 Set_Msg_Insertion_Run_Time_Name;
2251 Set_Msg_Insertion_Uint;
2254 Manual_Quote_Mode := not Manual_Quote_Mode;
2258 Is_Unconditional_Msg := True;
2261 null; -- already dealt with
2264 null; -- already dealt with
2267 null; -- already dealt with
2270 Set_Msg_Char (Text (P));
2273 -- Upper case letter
2277 -- Start of reserved word if two or more
2279 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
2281 Set_Msg_Insertion_Reserved_Word (Text, P);
2283 -- Single upper case letter is just inserted
2289 -- Normal character with no special treatment
2303 procedure Set_Posted (N : Node_Id) is
2307 if Is_Serious_Error then
2309 -- We always set Error_Posted on the node itself
2311 Set_Error_Posted (N);
2313 -- If it is a subexpression, then set Error_Posted on parents
2314 -- up to and including the first non-subexpression construct. This
2315 -- helps avoid cascaded error messages within a single expression.
2321 Set_Error_Posted (P);
2322 exit when Nkind (P) not in N_Subexpr;
2325 -- A special check, if we just posted an error on an attribute
2326 -- definition clause, then also set the entity involved as posted.
2327 -- For example, this stops complaining about the alignment after
2328 -- complaining about the size, which is likely to be useless.
2330 if Nkind (P) = N_Attribute_Definition_Clause then
2331 if Is_Entity_Name (Name (P)) then
2332 Set_Error_Posted (Entity (Name (P)));
2338 -----------------------
2339 -- Set_Qualification --
2340 -----------------------
2342 procedure Set_Qualification (N : Nat; E : Entity_Id) is
2344 if N /= 0 and then Scope (E) /= Standard_Standard then
2345 Set_Qualification (N - 1, Scope (E));
2346 Set_Msg_Node (Scope (E));
2349 end Set_Qualification;
2351 ------------------------
2352 -- Special_Msg_Delete --
2353 ------------------------
2355 function Special_Msg_Delete
2357 N : Node_Or_Entity_Id;
2358 E : Node_Or_Entity_Id) return Boolean
2361 -- Never delete messages in -gnatdO mode
2363 if Debug_Flag_OO then
2366 -- When an atomic object refers to a non-atomic type in the same
2367 -- scope, we implicitly make the type atomic. In the non-error
2368 -- case this is surely safe (and in fact prevents an error from
2369 -- occurring if the type is not atomic by default). But if the
2370 -- object cannot be made atomic, then we introduce an extra junk
2371 -- message by this manipulation, which we get rid of here.
2373 -- We identify this case by the fact that it references a type for
2374 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
2376 elsif Msg = "atomic
access to
& cannot be guaranteed
"
2377 and then Is_Type (E)
2378 and then Is_Atomic (E)
2379 and then No (Get_Rep_Pragma (E, Name_Atomic))
2383 -- When a size is wrong for a frozen type there is no explicit
2384 -- size clause, and other errors have occurred, suppress the
2385 -- message, since it is likely that this size error is a cascaded
2386 -- result of other errors. The reason we eliminate unfrozen types
2387 -- is that messages issued before the freeze type are for sure OK.
2389 elsif Msg = "size
for& too small
, minimum allowed
is ^
"
2390 and then Is_Frozen (E)
2391 and then Serious_Errors_Detected > 0
2392 and then Nkind (N) /= N_Component_Clause
2393 and then Nkind (Parent (N)) /= N_Component_Clause
2395 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
2397 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
2399 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
2403 -- All special tests complete, so go ahead with message
2408 end Special_Msg_Delete;
2410 --------------------------
2411 -- Unwind_Internal_Type --
2412 --------------------------
2414 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
2415 Derived : Boolean := False;
2417 Old_Ent : Entity_Id;
2420 -- Undo placement of a quote, since we will put it back later
2422 Mchar := Msg_Buffer (Msglen);
2425 Msglen := Msglen - 1;
2428 -- The loop here deals with recursive types, we are trying to
2429 -- find a related entity that is not an implicit type. Note
2430 -- that the check with Old_Ent stops us from getting "stuck".
2431 -- Also, we don't output the "type derived from" message more
2432 -- than once in the case where we climb up multiple levels.
2437 -- Implicit access type, use directly designated type
2439 if Is_Access_Type (Ent) then
2440 Set_Msg_Str ("access to ");
2441 Ent := Directly_Designated_Type (Ent);
2445 elsif Is_Class_Wide_Type (Ent) then
2447 Ent := Root_Type (Ent);
2449 -- Use base type if this is a subtype
2451 elsif Ent /= Base_Type (Ent) then
2452 Buffer_Remove ("type ");
2454 -- Avoid duplication "subtype of subtype of", and also replace
2455 -- "derived from subtype of" simply by "derived from"
2457 if not Buffer_Ends_With ("subtype of ")
2458 and then not Buffer_Ends_With ("derived from ")
2460 Set_Msg_Str ("subtype of ");
2463 Ent := Base_Type (Ent);
2465 -- If this is a base type with a first named subtype, use the
2466 -- first named subtype instead. This is not quite accurate in
2467 -- all cases, but it makes too much noise to be accurate and
2468 -- add 'Base
in all cases
. Note that we only
do this
is the
2469 -- first named subtype is not itself an internal name. This
2470 -- avoids the obvious loop (subtype->basetype->subtype) which
2471 -- would otherwise occur!)
2473 elsif Present
(Freeze_Node
(Ent
))
2474 and then Present
(First_Subtype_Link
(Freeze_Node
(Ent
)))
2476 not Is_Internal_Name
2477 (Chars
(First_Subtype_Link
(Freeze_Node
(Ent
))))
2479 Ent
:= First_Subtype_Link
(Freeze_Node
(Ent
));
2481 -- Otherwise use root type
2485 Buffer_Remove
("type ");
2487 -- Test for "subtype of type derived from" which seems
2488 -- excessive and is replaced by simply "type derived from"
2490 Buffer_Remove
("subtype of");
2492 -- Avoid duplication "type derived from type derived from"
2494 if not Buffer_Ends_With
("type derived from ") then
2495 Set_Msg_Str
("type derived from ");
2504 -- If we are stuck in a loop, get out and settle for the internal
2505 -- name after all. In this case we set to kill the message if it
2506 -- is not the first error message (we really try hard not to show
2507 -- the dirty laundry of the implementation to the poor user!)
2509 if Ent
= Old_Ent
then
2510 Kill_Message
:= True;
2514 -- Get out if we finally found a non-internal name to use
2516 exit when not Is_Internal_Name
(Chars
(Ent
));
2522 end Unwind_Internal_Type
;
2528 procedure VMS_Convert
is
2538 P
:= Msg_Buffer
'First;
2544 if Msg_Buffer
(P
) = '-' then
2545 for G
in Gnames
'Range loop
2546 L
:= Gnames
(G
)'Length;
2548 -- See if we have "-ggg switch", where ggg is Gnames entry
2550 if P
+ L
+ 7 <= Msglen
2551 and then Msg_Buffer
(P
+ 1 .. P
+ L
) = Gnames
(G
).all
2552 and then Msg_Buffer
(P
+ L
+ 1 .. P
+ L
+ 7) = " switch"
2554 -- Replace by "/vvv qualifier", where vvv is Vnames entry
2556 N
:= Vnames
(G
)'Length;
2557 Msg_Buffer
(P
+ N
+ 11 .. Msglen
+ N
- L
+ 3) :=
2558 Msg_Buffer
(P
+ L
+ 8 .. Msglen
);
2559 Msg_Buffer
(P
) := '/';
2560 Msg_Buffer
(P
+ 1 .. P
+ N
) := Vnames
(G
).all;
2561 Msg_Buffer
(P
+ N
+ 1 .. P
+ N
+ 10) := " qualifier";
2563 Msglen
:= Msglen
+ N
- L
+ 3;