1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2004 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, 59 Temple Place - Suite 330, Boston, --
20 -- MA 02111-1307, 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 Uintp
; use Uintp
;
53 with Uname
; use Uname
;
55 with Unchecked_Conversion
;
57 package body Errout
is
59 Errors_Must_Be_Ignored
: Boolean := False;
60 -- Set to True by procedure Set_Ignore_Errors (True), when calls to
61 -- error message procedures should be ignored (when parsing irrelevant
62 -- text in sources being preprocessed).
64 Warn_On_Instance
: Boolean;
65 -- Flag set true for warning message to be posted on instance
67 ------------------------------------
68 -- Table of Non-Instance Messages --
69 ------------------------------------
71 -- This table contains an entry for every error message processed by the
72 -- Error_Msg routine that is not posted on generic (or inlined) instance.
73 -- As explained in further detail in the Error_Msg procedure body, this
74 -- table is used to avoid posting redundant messages on instances.
76 type NIM_Record
is record
80 -- Type used to store text and location of one message
82 package Non_Instance_Msgs
is new Table
.Table
(
83 Table_Component_Type
=> NIM_Record
,
84 Table_Index_Type
=> Int
,
87 Table_Increment
=> 100,
88 Table_Name
=> "Non_Instance_Msgs");
90 -----------------------
91 -- Local Subprograms --
92 -----------------------
94 procedure Error_Msg_Internal
99 -- This is the low level routine used to post messages after dealing with
100 -- the issue of messages placed on instantiations (which get broken up
101 -- into separate calls in Error_Msg). Sptr is the location on which the
102 -- flag will be placed in the output. In the case where the flag is on
103 -- the template, this points directly to the template, not to one of the
104 -- instantiation copies of the template. Optr is the original location
105 -- used to flag the error, and this may indeed point to an instantiation
106 -- copy. So typically we can see Optr pointing to the template location
107 -- in an instantiation copy when Sptr points to the source location of
108 -- the actual instantiation (i.e the line with the new). Msg_Cont is
109 -- set true if this is a continuation message.
111 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean;
112 -- Determines if warnings should be suppressed for the given node
114 function OK_Node
(N
: Node_Id
) return Boolean;
115 -- Determines if a node is an OK node to place an error message on (return
116 -- True) or if the error message should be suppressed (return False). A
117 -- message is suppressed if the node already has an error posted on it,
118 -- or if it refers to an Etype that has an error posted on it, or if
119 -- it references an Entity that has an error posted on it.
121 procedure Output_Source_Line
122 (L
: Physical_Line_Number
;
123 Sfile
: Source_File_Index
;
125 -- Outputs text of source line L, in file S, together with preceding line
126 -- number, as described above for Output_Line_Number. The Errs parameter
127 -- indicates if there are errors attached to the line, which forces
128 -- listing on, even in the presence of pragma List (Off).
130 procedure Set_Msg_Insertion_Column
;
131 -- Handle column number insertion (@ insertion character)
133 procedure Set_Msg_Insertion_Node
;
134 -- Handle node (name from node) insertion (& insertion character)
136 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
);
137 -- Handle type reference (right brace insertion character). Flag is the
138 -- location of the flag, which is provided for the internal call to
139 -- Set_Msg_Insertion_Line_Number,
141 procedure Set_Msg_Insertion_Unit_Name
;
142 -- Handle unit name insertion ($ insertion character)
144 procedure Set_Msg_Node
(Node
: Node_Id
);
145 -- Add the sequence of characters for the name associated with the
146 -- given node to the current message.
148 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
);
149 -- Add a sequence of characters to the current message. The characters may
150 -- be one of the special insertion characters (see documentation in spec).
151 -- Flag is the location at which the error is to be posted, which is used
152 -- to determine whether or not the # insertion needs a file name. The
153 -- variables Msg_Buffer, Msglen, Is_Style_Msg, Is_Warning_Msg, and
154 -- Is_Unconditional_Msg are set on return.
156 procedure Set_Posted
(N
: Node_Id
);
157 -- Sets the Error_Posted flag on the given node, and all its parents
158 -- that are subexpressions and then on the parent non-subexpression
159 -- construct that contains the original expression (this reduces the
160 -- number of cascaded messages). Note that this call only has an effect
161 -- for a serious error. For a non-serious error, it has no effect.
163 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
);
164 -- Outputs up to N levels of qualification for the given entity. For
165 -- example, the entity A.B.C.D will output B.C. if N = 2.
167 function Special_Msg_Delete
169 N
: Node_Or_Entity_Id
;
170 E
: Node_Or_Entity_Id
) return Boolean;
171 -- This function is called from Error_Msg_NEL, passing the message Msg,
172 -- node N on which the error is to be posted, and the entity or node E
173 -- to be used for an & insertion in the message if any. The job of this
174 -- procedure is to test for certain cascaded messages that we would like
175 -- to suppress. If the message is to be suppressed then we return True.
176 -- If the message should be generated (the normal case) False is returned.
178 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
);
179 -- This procedure is given an entity id for an internal type, i.e.
180 -- a type with an internal name. It unwinds the type to try to get
181 -- to something reasonably printable, generating prefixes like
182 -- "subtype of", "access to", etc along the way in the buffer. The
183 -- value in Ent on return is the final name to be printed. Hopefully
184 -- this is not an internal name, but in some internal name cases, it
185 -- is an internal name, and has to be printed anyway (although in this
186 -- case the message has been killed if possible). The global variable
187 -- Class_Flag is set to True if the resulting entity should have
188 -- 'Class appended to its name (see Add_Class procedure), and is
189 -- otherwise unchanged.
191 procedure VMS_Convert
;
192 -- This procedure has no effect if called when the host is not OpenVMS.
193 -- If the host is indeed OpenVMS, then the error message stored in
194 -- Msg_Buffer is scanned for appearences of switch names which need
195 -- converting to corresponding VMS qualifer names. See Gnames/Vnames
196 -- table in Errout spec for precise definition of the conversion that
197 -- is performed by this routine in OpenVMS mode.
199 -----------------------
200 -- Change_Error_Text --
201 -----------------------
203 procedure Change_Error_Text
(Error_Id
: Error_Msg_Id
; New_Msg
: String) is
204 Save_Next
: Error_Msg_Id
;
205 Err_Id
: Error_Msg_Id
:= Error_Id
;
208 Set_Msg_Text
(New_Msg
, Errors
.Table
(Error_Id
).Sptr
);
209 Errors
.Table
(Error_Id
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
211 -- If in immediate error message mode, output modified error message now
212 -- This is just a bit tricky, because we want to output just a single
213 -- message, and the messages we modified is already linked in. We solve
214 -- this by temporarily resetting its forward pointer to empty.
216 if Debug_Flag_OO then
217 Save_Next := Errors.Table (Error_Id).Next;
218 Errors.Table (Error_Id).Next := No_Error_Msg;
221 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
222 Output_Error_Msgs (Err_Id);
223 Errors.Table (Error_Id).Next := Save_Next;
225 end Change_Error_Text;
231 -- Error_Msg posts a flag at the given location, except that if the
232 -- Flag_Location points within a generic template and corresponds
233 -- to an instantiation of this generic template, then the actual
234 -- message will be posted on the generic instantiation, along with
235 -- additional messages referencing the generic declaration.
237 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
238 Sindex : Source_File_Index;
239 -- Source index for flag location
241 Orig_Loc : Source_Ptr;
242 -- Original location of Flag_Location (i.e. location in original
243 -- template in instantiation case, otherwise unchanged).
246 -- It is a fatal error to issue an error message when scanning from
247 -- the internal source buffer (see Sinput for further documentation)
249 pragma Assert (Sinput.Source /= Internal_Source_Ptr);
251 -- Return if all errors are to be ignored
253 if Errors_Must_Be_Ignored then
257 -- If we already have messages, and we are trying to place a message
258 -- at No_Location or in package Standard, then just ignore the attempt
259 -- since we assume that what is happening is some cascaded junk. Note
260 -- that this is safe in the sense that proceeding will surely bomb.
262 if Flag_Location < First_Source_Ptr
263 and then Total_Errors_Detected > 0
268 -- Start procesing of new message
270 Sindex := Get_Source_File_Index (Flag_Location);
271 Test_Style_Warning_Serious_Msg (Msg);
272 Orig_Loc := Original_Location (Flag_Location);
274 -- If the current location is in an instantiation, the issue arises
275 -- of whether to post the message on the template or the instantiation.
277 -- The way we decide is to see if we have posted the same message
278 -- on the template when we compiled the template (the template is
279 -- always compiled before any instantiations). For this purpose,
280 -- we use a separate table of messages. The reason we do this is
283 -- First, the messages can get changed by various processing
284 -- including the insertion of tokens etc, making it hard to
285 -- do the comparison.
287 -- Second, we will suppress a warning on a template if it is
288 -- not in the current extended source unit. That's reasonable
289 -- and means we don't want the warning on the instantiation
290 -- here either, but it does mean that the main error table
291 -- would not in any case include the message.
293 if Flag_Location = Orig_Loc then
294 Non_Instance_Msgs.Append ((new String'(Msg
), Flag_Location
));
295 Warn_On_Instance
:= False;
297 -- Here we have an instance message
300 -- Delete if debug flag off, and this message duplicates a
301 -- message already posted on the corresponding template
303 if not Debug_Flag_GG
then
304 for J
in Non_Instance_Msgs
.First
.. Non_Instance_Msgs
.Last
loop
305 if Msg
= Non_Instance_Msgs
.Table
(J
).Msg
.all
306 and then Non_Instance_Msgs
.Table
(J
).Loc
= Orig_Loc
313 -- No duplicate, so error/warning will be posted on instance
315 Warn_On_Instance
:= Is_Warning_Msg
;
318 -- Ignore warning message that is suppressed. Note that style
319 -- checks are not considered warning messages for this purpose
321 if Is_Warning_Msg
and then Warnings_Suppressed
(Orig_Loc
) then
325 -- The idea at this stage is that we have two kinds of messages.
327 -- First, we have those that are to be placed as requested at
328 -- Flag_Location. This includes messages that have nothing to
329 -- do with generics, and also messages placed on generic templates
330 -- that reflect an error in the template itself. For such messages
331 -- we simply call Error_Msg_Internal to place the message in the
332 -- requested location.
334 if Instantiation
(Sindex
) = No_Location
then
335 Error_Msg_Internal
(Msg
, Flag_Location
, Flag_Location
, False);
339 -- If we are trying to flag an error in an instantiation, we may have
340 -- a generic contract violation. What we generate in this case is:
342 -- instantiation error at ...
343 -- original error message
347 -- warning: in instantiation at
348 -- warning: original warning message
350 -- All these messages are posted at the location of the top level
351 -- instantiation. If there are nested instantiations, then the
352 -- instantiation error message can be repeated, pointing to each
353 -- of the relevant instantiations.
355 -- Note: the instantiation mechanism is also shared for inlining
356 -- of subprogram bodies when front end inlining is done. In this
357 -- case the messages have the form:
359 -- in inlined body at ...
360 -- original error message
364 -- warning: in inlined body at
365 -- warning: original warning message
367 -- OK, this is the case where we have an instantiation error, and
368 -- we need to generate the error on the instantiation, rather than
372 Actual_Error_Loc
: Source_Ptr
;
373 -- Location of outer level instantiation in instantiation case, or
374 -- just a copy of Flag_Location in the normal case. This is the
375 -- location where all error messages will actually be posted.
377 Save_Error_Msg_Sloc
: constant Source_Ptr
:= Error_Msg_Sloc
;
378 -- Save possible location set for caller's message. We need to
379 -- use Error_Msg_Sloc for the location of the instantiation error
380 -- but we have to preserve a possible original value.
382 X
: Source_File_Index
;
384 Msg_Cont_Status
: Boolean;
385 -- Used to label continuation lines in instantiation case with
386 -- proper Msg_Cont status.
389 -- Loop to find highest level instantiation, where all error
390 -- messages will be placed.
394 Actual_Error_Loc
:= Instantiation
(X
);
395 X
:= Get_Source_File_Index
(Actual_Error_Loc
);
396 exit when Instantiation
(X
) = No_Location
;
399 -- Since we are generating the messages at the instantiation
400 -- point in any case, we do not want the references to the
401 -- bad lines in the instance to be annotated with the location
402 -- of the instantiation.
404 Suppress_Instance_Location
:= True;
405 Msg_Cont_Status
:= False;
407 -- Loop to generate instantiation messages
409 Error_Msg_Sloc
:= Flag_Location
;
410 X
:= Get_Source_File_Index
(Flag_Location
);
412 while Instantiation
(X
) /= No_Location
loop
414 -- Suppress instantiation message on continuation lines
416 if Msg
(Msg
'First) /= '\' then
418 -- Case of inlined body
420 if Inlined_Body
(X
) then
421 if Is_Warning_Msg
then
423 ("?in inlined body #",
424 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
428 ("error in inlined body #",
429 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
432 -- Case of generic instantiation
435 if Is_Warning_Msg
then
437 ("?in instantiation #",
438 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
442 ("instantiation error #",
443 Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
448 Error_Msg_Sloc
:= Instantiation
(X
);
449 X
:= Get_Source_File_Index
(Error_Msg_Sloc
);
450 Msg_Cont_Status
:= True;
453 Suppress_Instance_Location
:= False;
454 Error_Msg_Sloc
:= Save_Error_Msg_Sloc
;
456 -- Here we output the original message on the outer instantiation
459 (Msg
, Actual_Error_Loc
, Flag_Location
, Msg_Cont_Status
);
467 procedure Error_Msg_AP
(Msg
: String) is
472 -- If we had saved the Scan_Ptr value after scanning the previous
473 -- token, then we would have exactly the right place for putting
474 -- the flag immediately at hand. However, that would add at least
475 -- two instructions to a Scan call *just* to service the possibility
476 -- of an Error_Msg_AP call. So instead we reconstruct that value.
478 -- We have two possibilities, start with Prev_Token_Ptr and skip over
479 -- the current token, which is made harder by the possibility that this
480 -- token may be in error, or start with Token_Ptr and work backwards.
481 -- We used to take the second approach, but it's hard because of
482 -- comments, and harder still because things that look like comments
483 -- can appear inside strings. So now we take the first approach.
485 -- Note: in the case where there is no previous token, Prev_Token_Ptr
486 -- is set to Source_First, which is a reasonable position for the
487 -- error flag in this situation.
489 S1
:= Prev_Token_Ptr
;
492 -- If the previous token is a string literal, we need a special approach
493 -- since there may be white space inside the literal and we don't want
494 -- to stop on that white space.
496 if Prev_Token
= Tok_String_Literal
then
500 if Source
(S1
) = C
then
502 exit when Source
(S1
) /= C
;
503 elsif Source
(S1
) in Line_Terminator
then
508 -- Character literal also needs special handling
510 elsif Prev_Token
= Tok_Char_Literal
then
513 -- Otherwise we search forward for the end of the current token, marked
514 -- by a line terminator, white space, a comment symbol or if we bump
515 -- into the following token (i.e. the current token)
518 while Source
(S1
) not in Line_Terminator
519 and then Source
(S1
) /= ' '
520 and then Source
(S1
) /= ASCII
.HT
521 and then (Source
(S1
) /= '-' or else Source
(S1
+ 1) /= '-')
522 and then S1
/= Token_Ptr
528 -- S1 is now set to the location for the flag
538 procedure Error_Msg_BC
(Msg
: String) is
540 -- If we are at end of file, post the flag after the previous token
542 if Token
= Tok_EOF
then
545 -- If we are at start of file, post the flag at the current token
547 elsif Token_Ptr
= Source_First
(Current_Source_File
) then
550 -- If the character before the current token is a space or a horizontal
551 -- tab, then we place the flag on this character (in the case of a tab
552 -- we would really like to place it in the "last" character of the tab
553 -- space, but that it too much trouble to worry about).
555 elsif Source
(Token_Ptr
- 1) = ' '
556 or else Source
(Token_Ptr
- 1) = ASCII
.HT
558 Error_Msg
(Msg
, Token_Ptr
- 1);
560 -- If there is no space or tab before the current token, then there is
561 -- no room to place the flag before the token, so we place it on the
562 -- token instead (this happens for example at the start of a line).
565 Error_Msg
(Msg
, Token_Ptr
);
573 procedure Error_Msg_CRT
(Feature
: String; N
: Node_Id
) is
574 CNRT
: constant String := " not allowed in no run time mode";
575 CCRT
: constant String := " not supported by configuration>";
577 S
: String (1 .. Feature
'Length + 1 + CCRT
'Length);
583 S
(2 .. Feature
'Length + 1) := Feature
;
584 L
:= Feature
'Length + 2;
586 if No_Run_Time_Mode
then
587 S
(L
.. L
+ CNRT
'Length - 1) := CNRT
;
588 L
:= L
+ CNRT
'Length - 1;
590 else pragma Assert
(Configurable_Run_Time_Mode
);
591 S
(L
.. L
+ CCRT
'Length - 1) := CCRT
;
592 L
:= L
+ CCRT
'Length - 1;
595 Error_Msg_N
(S
(1 .. L
), N
);
596 Configurable_Run_Time_Violations
:= Configurable_Run_Time_Violations
+ 1;
603 procedure Error_Msg_F
(Msg
: String; N
: Node_Id
) is
604 SI
: constant Source_File_Index
:= Source_Index
(Get_Source_Unit
(N
));
605 SF
: constant Source_Ptr
:= Source_First
(SI
);
613 -- The following circuit is a bit subtle. When we have parenthesized
614 -- expressions, then the Sloc will not record the location of the
615 -- paren, but we would like to post the flag on the paren. So what
616 -- we do is to crawl up the tree from the First_Node, adjusting the
617 -- Sloc value for any parentheses we know are present. Yes, we know
618 -- this circuit is not 100% reliable (e.g. because we don't record
619 -- all possible paren level valoues), but this is only for an error
620 -- message so it is good enough.
623 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
625 -- We don't look more than 12 characters behind the current
626 -- location, and in any case not past the front of the source.
628 Search_Loop
: for K
in 1 .. 12 loop
629 exit Search_Loop
when S
= SF
;
631 if Source_Text
(SI
) (S
- 1) = '(' then
635 elsif Source_Text
(SI
) (S
- 1) <= ' ' then
641 end loop Search_Loop
;
644 exit Node_Loop
when F
= N
;
646 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
649 Error_Msg_NEL
(Msg
, N
, N
, S
);
656 procedure Error_Msg_FE
659 E
: Node_Or_Entity_Id
)
662 Error_Msg_NEL
(Msg
, N
, E
, Sloc
(First_Node
(N
)));
665 ------------------------
666 -- Error_Msg_Internal --
667 ------------------------
669 procedure Error_Msg_Internal
675 Next_Msg
: Error_Msg_Id
;
676 -- Pointer to next message at insertion point
678 Prev_Msg
: Error_Msg_Id
;
679 -- Pointer to previous message at insertion point
681 Temp_Msg
: Error_Msg_Id
;
683 procedure Handle_Serious_Error
;
684 -- Internal procedure to do all error message handling for a serious
685 -- error message, other than bumping the error counts and arranging
686 -- for the message to be output.
688 --------------------------
689 -- Handle_Serious_Error --
690 --------------------------
692 procedure Handle_Serious_Error
is
694 -- Turn off code generation if not done already
696 if Operating_Mode
= Generate_Code
then
697 Operating_Mode
:= Check_Semantics
;
698 Expander_Active
:= False;
701 -- Set the fatal error flag in the unit table unless we are
702 -- in Try_Semantics mode. This stops the semantics from being
703 -- performed if we find a serious error. This is skipped if we
704 -- are currently dealing with the configuration pragma file.
707 and then Current_Source_Unit
/= No_Unit
709 Set_Fatal_Error
(Get_Source_Unit
(Sptr
));
711 end Handle_Serious_Error
;
713 -- Start of processing for Error_Msg_Internal
716 if Raise_Exception_On_Error
/= 0 then
717 raise Error_Msg_Exception
;
720 Continuation
:= Msg_Cont
;
721 Suppress_Message
:= False;
722 Kill_Message
:= False;
723 Set_Msg_Text
(Msg
, Sptr
);
725 -- Kill continuation if parent message killed
727 if Continuation
and Last_Killed
then
731 -- Return without doing anything if message is suppressed
734 and not All_Errors_Mode
735 and not (Msg
(Msg
'Last) = '!')
737 if not Continuation
then
744 -- Return without doing anything if message is killed and this
745 -- is not the first error message. The philosophy is that if we
746 -- get a weird error message and we already have had a message,
747 -- then we hope the weird message is a junk cascaded message
750 and then not All_Errors_Mode
751 and then Total_Errors_Detected
/= 0
753 if not Continuation
then
760 -- Special check for warning message to see if it should be output
762 if Is_Warning_Msg
then
764 -- Immediate return if warning message and warnings are suppressed
766 if Warnings_Suppressed
(Optr
)
767 or else Warnings_Suppressed
(Sptr
)
769 Cur_Msg
:= No_Error_Msg
;
773 -- If the flag location is in the main extended source unit
774 -- then for sure we want the warning since it definitely belongs
776 if In_Extended_Main_Source_Unit
(Sptr
) then
779 -- If the flag location is not in the main extended source
780 -- unit then we want to eliminate the warning.
782 elsif In_Extended_Main_Code_Unit
(Sptr
)
783 and then Warn_On_Instance
787 -- Keep warning if debug flag G set
789 elsif Debug_Flag_GG
then
792 -- Here is where we delete a warning from a with'ed unit
795 Cur_Msg
:= No_Error_Msg
;
800 -- If message is to be ignored in special ignore message mode, this is
801 -- where we do this special processing, bypassing message output.
803 if Ignore_Errors_Enable
> 0 then
804 if Is_Serious_Error
then
805 Handle_Serious_Error
;
811 -- Otherwise build error message object for new message
813 Errors
.Increment_Last
;
814 Cur_Msg
:= Errors
.Last
;
815 Errors
.Table
(Cur_Msg
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
816 Errors.Table (Cur_Msg).Next := No_Error_Msg;
817 Errors.Table (Cur_Msg).Sptr := Sptr;
818 Errors.Table (Cur_Msg).Optr := Optr;
819 Errors.Table (Cur_Msg).Sfile := Get_Source_File_Index (Sptr);
820 Errors.Table (Cur_Msg).Line := Get_Physical_Line_Number (Sptr);
821 Errors.Table (Cur_Msg).Col := Get_Column_Number (Sptr);
822 Errors.Table (Cur_Msg).Warn := Is_Warning_Msg;
823 Errors.Table (Cur_Msg).Style := Is_Style_Msg;
824 Errors.Table (Cur_Msg).Serious := Is_Serious_Error;
825 Errors.Table (Cur_Msg).Uncond := Is_Unconditional_Msg;
826 Errors.Table (Cur_Msg).Msg_Cont := Continuation;
827 Errors.Table (Cur_Msg).Deleted := False;
829 -- If immediate errors mode set, output error message now. Also output
830 -- now if the -d1 debug flag is set (so node number message comes out
831 -- just before actual error message)
833 if Debug_Flag_OO or else Debug_Flag_1 then
835 Output_Source_Line (Errors.Table (Cur_Msg).Line,
836 Errors.Table (Cur_Msg).Sfile, True);
838 Output_Error_Msgs (Temp_Msg);
840 -- If not in immediate errors mode, then we insert the message in the
841 -- error chain for later output by Finalize. The messages are sorted
842 -- first by unit (main unit comes first), and within a unit by source
843 -- location (earlier flag location first in the chain).
846 -- First a quick check, does this belong at the very end of the
847 -- chain of error messages. This saves a lot of time in the
848 -- normal case if there are lots of messages.
850 if Last_Error_Msg /= No_Error_Msg
851 and then Errors.Table (Cur_Msg).Sfile =
852 Errors.Table (Last_Error_Msg).Sfile
853 and then (Sptr > Errors.Table (Last_Error_Msg).Sptr
855 (Sptr = Errors.Table (Last_Error_Msg).Sptr
857 Optr > Errors.Table (Last_Error_Msg).Optr))
859 Prev_Msg := Last_Error_Msg;
860 Next_Msg := No_Error_Msg;
862 -- Otherwise do a full sequential search for the insertion point
865 Prev_Msg := No_Error_Msg;
866 Next_Msg := First_Error_Msg;
867 while Next_Msg /= No_Error_Msg loop
869 Errors.Table (Cur_Msg).Sfile < Errors.Table (Next_Msg).Sfile;
871 if Errors.Table (Cur_Msg).Sfile =
872 Errors.Table (Next_Msg).Sfile
874 exit when Sptr < Errors.Table (Next_Msg).Sptr
876 (Sptr = Errors.Table (Next_Msg).Sptr
878 Optr < Errors.Table (Next_Msg).Optr);
881 Prev_Msg := Next_Msg;
882 Next_Msg := Errors.Table (Next_Msg).Next;
886 -- Now we insert the new message in the error chain. The insertion
887 -- point for the message is after Prev_Msg and before Next_Msg.
889 -- The possible insertion point for the new message is after Prev_Msg
890 -- and before Next_Msg. However, this is where we do a special check
891 -- for redundant parsing messages, defined as messages posted on the
892 -- same line. The idea here is that probably such messages are junk
893 -- from the parser recovering. In full errors mode, we don't do this
894 -- deletion, but otherwise such messages are discarded at this stage.
896 if Prev_Msg /= No_Error_Msg
897 and then Errors.Table (Prev_Msg).Line =
898 Errors.Table (Cur_Msg).Line
899 and then Errors.Table (Prev_Msg).Sfile =
900 Errors.Table (Cur_Msg).Sfile
901 and then Compiler_State = Parsing
902 and then not All_Errors_Mode
904 -- Don't delete unconditional messages and at this stage,
905 -- don't delete continuation lines (we attempted to delete
906 -- those earlier if the parent message was deleted.
908 if not Errors.Table (Cur_Msg).Uncond
909 and then not Continuation
911 -- Don't delete if prev msg is warning and new msg is
912 -- an error. This is because we don't want a real error
913 -- masked by a warning. In all other cases (that is parse
914 -- errors for the same line that are not unconditional)
915 -- we do delete the message. This helps to avoid
916 -- junk extra messages from cascaded parsing errors
918 if not (Errors.Table (Prev_Msg).Warn
920 Errors.Table (Prev_Msg).Style)
922 (Errors.Table (Cur_Msg).Warn
924 Errors.Table (Cur_Msg).Style)
926 -- All tests passed, delete the message by simply
927 -- returning without any further processing.
929 if not Continuation then
938 -- Come here if message is to be inserted in the error chain
940 if not Continuation then
941 Last_Killed := False;
944 if Prev_Msg = No_Error_Msg then
945 First_Error_Msg := Cur_Msg;
947 Errors.Table (Prev_Msg).Next := Cur_Msg;
950 Errors.Table (Cur_Msg).Next := Next_Msg;
952 if Next_Msg = No_Error_Msg then
953 Last_Error_Msg := Cur_Msg;
957 -- Bump appropriate statistics count
959 if Errors.Table (Cur_Msg).Warn
960 or else Errors.Table (Cur_Msg).Style
962 Warnings_Detected := Warnings_Detected + 1;
964 Total_Errors_Detected := Total_Errors_Detected + 1;
966 if Errors.Table (Cur_Msg).Serious then
967 Serious_Errors_Detected := Serious_Errors_Detected + 1;
968 Handle_Serious_Error;
972 -- Terminate if max errors reached
974 if Total_Errors_Detected + Warnings_Detected = Maximum_Errors then
975 raise Unrecoverable_Error;
978 end Error_Msg_Internal;
984 procedure Error_Msg_N (Msg : String; N : Node_Or_Entity_Id) is
986 Error_Msg_NEL (Msg, N, N, Sloc (N));
993 procedure Error_Msg_NE
995 N : Node_Or_Entity_Id;
996 E : Node_Or_Entity_Id)
999 Error_Msg_NEL (Msg, N, E, Sloc (N));
1006 procedure Error_Msg_NEL
1008 N : Node_Or_Entity_Id;
1009 E : Node_Or_Entity_Id;
1010 Flag_Location : Source_Ptr)
1013 if Special_Msg_Delete (Msg, N, E) then
1017 Test_Style_Warning_Serious_Msg (Msg);
1019 -- Special handling for warning messages
1021 if Is_Warning_Msg then
1023 -- Suppress if no warnings set for either entity or node
1025 if No_Warnings (N) or else No_Warnings (E) then
1029 -- Suppress if inside loop that is known to be null
1036 while Present (P) loop
1037 if Nkind (P) = N_Loop_Statement and then Is_Null_Loop (P) then
1046 -- Test for message to be output
1049 or else Msg (Msg'Last) = '!'
1051 or else (Msg (Msg'First) = '\
' and not Last_Killed)
1054 Error_Msg_Node_1 := E;
1055 Error_Msg (Msg, Flag_Location);
1058 Last_Killed := True;
1061 if not Is_Warning_Msg and then not Is_Style_Msg then
1070 procedure Error_Msg_NW
1073 N : Node_Or_Entity_Id)
1076 if Eflag and then In_Extended_Main_Source_Unit (N) then
1077 Error_Msg_NEL (Msg, N, N, Sloc (N));
1085 procedure Error_Msg_S (Msg : String) is
1087 Error_Msg (Msg, Scan_Ptr);
1094 procedure Error_Msg_SC (Msg : String) is
1096 -- If we are at end of file, post the flag after the previous token
1098 if Token = Tok_EOF then
1101 -- For all other cases the message is posted at the current token
1105 Error_Msg (Msg, Token_Ptr);
1113 procedure Error_Msg_SP (Msg : String) is
1115 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1116 -- is set to Source_First, which is a reasonable position for the
1117 -- error flag in this situation
1119 Error_Msg (Msg, Prev_Token_Ptr);
1126 procedure Finalize is
1129 E, F : Error_Msg_Id;
1133 -- Reset current error source file if the main unit has a pragma
1134 -- Source_Reference. This ensures outputting the proper name of
1135 -- the source file in this situation.
1137 if Num_SRef_Pragmas (Main_Source_File) /= 0 then
1138 Current_Error_Source_File := No_Source_File;
1141 -- Eliminate any duplicated error messages from the list. This is
1142 -- done after the fact to avoid problems with Change_Error_Text.
1144 Cur := First_Error_Msg;
1145 while Cur /= No_Error_Msg loop
1146 Nxt := Errors.Table (Cur).Next;
1149 while F /= No_Error_Msg
1150 and then Errors.Table (F).Sptr = Errors.Table (Cur).Sptr
1152 Check_Duplicate_Message (Cur, F);
1153 F := Errors.Table (F).Next;
1161 if Brief_Output or (not Full_List and not Verbose_Mode) then
1162 E := First_Error_Msg;
1165 while E /= No_Error_Msg loop
1166 if not Errors.Table (E).Deleted and then not Debug_Flag_KK then
1167 if Full_Path_Name_For_Brief_Errors then
1168 Write_Name (Full_Ref_Name (Errors.Table (E).Sfile));
1170 Write_Name (Reference_Name (Errors.Table (E).Sfile));
1174 Write_Int (Int (Physical_To_Logical
1175 (Errors.Table (E).Line,
1176 Errors.Table (E).Sfile)));
1179 if Errors.Table (E).Col < 10 then
1183 Write_Int (Int (Errors.Table (E).Col));
1185 Output_Msg_Text (E);
1189 E := Errors.Table (E).Next;
1192 Set_Standard_Output;
1195 -- Full source listing case
1198 List_Pragmas_Index := 1;
1199 List_Pragmas_Mode := True;
1200 E := First_Error_Msg;
1203 -- First list initial main source file with its error messages
1205 for N in 1 .. Last_Source_Line (Main_Source_File) loop
1208 and then Errors.Table (E).Line = N
1209 and then Errors.Table (E).Sfile = Main_Source_File;
1211 Output_Source_Line (N, Main_Source_File, Err_Flag);
1214 Output_Error_Msgs (E);
1216 if not Debug_Flag_2 then
1223 -- Then output errors, if any, for subsidiary units
1225 while E /= No_Error_Msg
1226 and then Errors.Table (E).Sfile /= Main_Source_File
1230 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1231 Output_Error_Msgs (E);
1235 -- Verbose mode (error lines only with error flags)
1237 if Verbose_Mode and not Full_List then
1238 E := First_Error_Msg;
1240 -- Loop through error lines
1242 while E /= No_Error_Msg loop
1245 (Errors.Table (E).Line, Errors.Table (E).Sfile, True);
1246 Output_Error_Msgs (E);
1250 -- Output error summary if verbose or full list mode
1252 if Verbose_Mode or else Full_List then
1254 -- Extra blank line if error messages or source listing were output
1256 if Total_Errors_Detected + Warnings_Detected > 0
1262 -- Message giving number of lines read and number of errors detected.
1263 -- This normally goes to Standard_Output. The exception is when brief
1264 -- mode is not set, verbose mode (or full list mode) is set, and
1265 -- there are errors. In this case we send the message to standard
1266 -- error to make sure that *something* appears on standard error in
1267 -- an error situation.
1269 -- Formerly, only the "# errors" suffix was sent to stderr, whereas
1270 -- "# lines:" appeared on stdout. This caused problems on VMS when
1271 -- the stdout buffer was flushed, giving an extra line feed after
1274 if Total_Errors_Detected + Warnings_Detected /= 0
1275 and then not Brief_Output
1276 and then (Verbose_Mode or Full_List)
1281 -- Message giving total number of lines
1284 Write_Int (Num_Source_Lines (Main_Source_File));
1286 if Num_Source_Lines (Main_Source_File) = 1 then
1287 Write_Str (" line: ");
1289 Write_Str (" lines: ");
1292 if Total_Errors_Detected = 0 then
1293 Write_Str ("No errors");
1295 elsif Total_Errors_Detected = 1 then
1296 Write_Str ("1 error");
1299 Write_Int (Total_Errors_Detected);
1300 Write_Str (" errors");
1303 if Warnings_Detected /= 0 then
1305 Write_Int (Warnings_Detected);
1306 Write_Str (" warning");
1308 if Warnings_Detected /= 1 then
1312 if Warning_Mode = Treat_As_Error then
1313 Write_Str (" (treated as error");
1315 if Warnings_Detected /= 1 then
1324 Set_Standard_Output;
1327 if Maximum_Errors /= 0
1328 and then Total_Errors_Detected + Warnings_Detected = Maximum_Errors
1331 Write_Str ("fatal error: maximum errors reached");
1333 Set_Standard_Output;
1336 if Warning_Mode = Treat_As_Error then
1337 Total_Errors_Detected := Total_Errors_Detected + Warnings_Detected;
1338 Warnings_Detected := 0;
1346 function First_Node (C : Node_Id) return Node_Id is
1347 L : constant Source_Ptr := Sloc (C);
1348 Sfile : constant Source_File_Index := Get_Source_File_Index (L);
1351 Discard : Traverse_Result;
1353 pragma Warnings (Off, Discard);
1355 function Test_Earlier (N : Node_Id) return Traverse_Result;
1356 -- Function applied to every node in the construct
1358 function Search_Tree_First is new Traverse_Func (Test_Earlier);
1359 -- Create traversal function
1365 function Test_Earlier (N : Node_Id) return Traverse_Result is
1366 Loc : constant Source_Ptr := Sloc (N);
1369 -- Check for earlier. The tests for being in the same file ensures
1370 -- against strange cases of foreign code somehow being present. We
1371 -- don't want wild placement of messages if that happens, so it is
1372 -- best to just ignore this situation.
1375 and then Get_Source_File_Index (Loc) = Sfile
1384 -- Start of processing for First_Node
1387 Earliest := Original_Node (C);
1388 Eloc := Sloc (Earliest);
1389 Discard := Search_Tree_First (Original_Node (C));
1398 procedure Initialize is
1401 First_Error_Msg := No_Error_Msg;
1402 Last_Error_Msg := No_Error_Msg;
1403 Serious_Errors_Detected := 0;
1404 Total_Errors_Detected := 0;
1405 Warnings_Detected := 0;
1406 Cur_Msg := No_Error_Msg;
1409 -- Initialize warnings table, if all warnings are suppressed, supply
1410 -- an initial dummy entry covering all possible source locations.
1414 if Warning_Mode = Suppress then
1415 Warnings.Increment_Last;
1416 Warnings.Table (Warnings.Last).Start := Source_Ptr'First;
1417 Warnings.Table (Warnings.Last).Stop := Source_Ptr'Last;
1420 -- Set the error nodes to Empty to avoid uninitialized variable
1421 -- references for saves/restores/moves.
1423 Error_Msg_Node_1 := Empty;
1424 Error_Msg_Node_2 := Empty;
1431 function No_Warnings (N : Node_Or_Entity_Id) return Boolean is
1433 if Error_Posted (N) then
1436 elsif Nkind (N) in N_Entity and then Warnings_Off (N) then
1439 elsif Is_Entity_Name (N)
1440 and then Present (Entity (N))
1441 and then Warnings_Off (Entity (N))
1454 function OK_Node (N : Node_Id) return Boolean is
1455 K : constant Node_Kind := Nkind (N);
1458 if Error_Posted (N) then
1461 elsif K in N_Has_Etype
1462 and then Present (Etype (N))
1463 and then Error_Posted (Etype (N))
1468 or else K = N_Attribute_Reference
1469 or else K = N_Character_Literal
1470 or else K = N_Expanded_Name
1471 or else K = N_Identifier
1472 or else K = N_Operator_Symbol)
1473 and then Present (Entity (N))
1474 and then Error_Posted (Entity (N))
1482 ------------------------
1483 -- Output_Source_Line --
1484 ------------------------
1486 procedure Output_Source_Line
1487 (L : Physical_Line_Number;
1488 Sfile : Source_File_Index;
1494 Line_Number_Output : Boolean := False;
1495 -- Set True once line number is output
1498 if Sfile /= Current_Error_Source_File then
1499 Write_Str ("==============Error messages for ");
1501 case Sinput.File_Type (Sfile) is
1503 Write_Str ("source");
1505 when Sinput.Config =>
1506 Write_Str ("configuration pragmas");
1509 Write_Str ("symbol definition");
1511 when Sinput.Preproc =>
1512 Write_Str ("preprocessing data");
1515 Write_Str (" file: ");
1516 Write_Name (Full_File_Name (Sfile));
1519 if Num_SRef_Pragmas (Sfile) > 0 then
1520 Write_Str ("--------------Line numbers from file: ");
1521 Write_Name (Full_Ref_Name (Sfile));
1522 Write_Str (" (starting at line ");
1523 Write_Int (Int (First_Mapped_Line (Sfile)));
1528 Current_Error_Source_File := Sfile;
1531 if Errs or List_Pragmas_Mode then
1532 Output_Line_Number (Physical_To_Logical (L, Sfile));
1533 Line_Number_Output := True;
1536 S := Line_Start (L, Sfile);
1539 C := Source_Text (Sfile) (S);
1540 exit when C = ASCII.LF or else C = ASCII.CR or else C = EOF;
1542 -- Deal with matching entry in List_Pragmas table
1545 and then List_Pragmas_Index <= List_Pragmas.Last
1546 and then S = List_Pragmas.Table (List_Pragmas_Index).Ploc
1548 case List_Pragmas.Table (List_Pragmas_Index).Ptyp is
1552 -- Ignore if on line with errors so that error flags
1553 -- get properly listed with the error line .
1556 Write_Char (ASCII.FF);
1560 List_Pragmas_Mode := True;
1562 if not Line_Number_Output then
1563 Output_Line_Number (Physical_To_Logical (L, Sfile));
1564 Line_Number_Output := True;
1571 List_Pragmas_Mode := False;
1574 List_Pragmas_Index := List_Pragmas_Index + 1;
1576 -- Normal case (no matching entry in List_Pragmas table)
1579 if Errs or List_Pragmas_Mode then
1587 if Line_Number_Output then
1590 end Output_Source_Line;
1592 -----------------------------
1593 -- Remove_Warning_Messages --
1594 -----------------------------
1596 procedure Remove_Warning_Messages (N : Node_Id) is
1598 function Check_For_Warning (N : Node_Id) return Traverse_Result;
1599 -- This function checks one node for a possible warning message.
1601 function Check_All_Warnings is new
1602 Traverse_Func (Check_For_Warning);
1603 -- This defines the traversal operation
1605 -----------------------
1606 -- Check_For_Warning --
1607 -----------------------
1609 function Check_For_Warning (N : Node_Id) return Traverse_Result is
1610 Loc : constant Source_Ptr := Sloc (N);
1613 function To_Be_Removed (E : Error_Msg_Id) return Boolean;
1614 -- Returns True for a message that is to be removed. Also adjusts
1615 -- warning count appropriately.
1621 function To_Be_Removed (E : Error_Msg_Id) return Boolean is
1623 if E /= No_Error_Msg
1624 and then Errors.Table (E).Optr = Loc
1625 and then (Errors.Table (E).Warn or Errors.Table (E).Style)
1627 Warnings_Detected := Warnings_Detected - 1;
1634 -- Start of processing for Check_For_Warnings
1637 while To_Be_Removed (First_Error_Msg) loop
1638 First_Error_Msg := Errors.Table (First_Error_Msg).Next;
1641 if First_Error_Msg = No_Error_Msg then
1642 Last_Error_Msg := No_Error_Msg;
1645 E := First_Error_Msg;
1646 while E /= No_Error_Msg loop
1647 while To_Be_Removed (Errors.Table (E).Next) loop
1648 Errors.Table (E).Next :=
1649 Errors.Table (Errors.Table (E).Next).Next;
1651 if Errors.Table (E).Next = No_Error_Msg then
1652 Last_Error_Msg := E;
1656 E := Errors.Table (E).Next;
1659 if Nkind (N) = N_Raise_Constraint_Error
1660 and then Original_Node (N) /= N
1661 and then No (Condition (N))
1663 -- Warnings may have been posted on subexpressions of
1664 -- the original tree. We place the original node back
1665 -- on the tree to remove those warnings, whose sloc
1666 -- do not match those of any node in the current tree.
1667 -- Given that we are in unreachable code, this modification
1668 -- to the tree is harmless.
1671 Status : Traverse_Result;
1674 if Is_List_Member (N) then
1675 Set_Condition (N, Original_Node (N));
1676 Status := Check_All_Warnings (Condition (N));
1678 Rewrite (N, Original_Node (N));
1679 Status := Check_All_Warnings (N);
1688 end Check_For_Warning;
1690 -- Start of processing for Remove_Warning_Messages
1693 if Warnings_Detected /= 0 then
1695 Discard : Traverse_Result;
1696 pragma Warnings (Off, Discard);
1699 Discard := Check_All_Warnings (N);
1702 end Remove_Warning_Messages;
1704 procedure Remove_Warning_Messages (L : List_Id) is
1707 if Is_Non_Empty_List (L) then
1710 while Present (Stat) loop
1711 Remove_Warning_Messages (Stat);
1715 end Remove_Warning_Messages;
1717 ---------------------------
1718 -- Set_Identifier_Casing --
1719 ---------------------------
1721 procedure Set_Identifier_Casing
1722 (Identifier_Name : System.Address;
1723 File_Name : System.Address)
1725 type Big_String is array (Positive) of Character;
1726 type Big_String_Ptr is access all Big_String;
1728 function To_Big_String_Ptr is new Unchecked_Conversion
1729 (System.Address, Big_String_Ptr);
1731 Ident : constant Big_String_Ptr := To_Big_String_Ptr (Identifier_Name);
1732 File : constant Big_String_Ptr := To_Big_String_Ptr (File_Name);
1735 Desired_Case : Casing_Type := Mixed_Case;
1736 -- Casing required for result. Default value of Mixed_Case is used if
1737 -- for some reason we cannot find the right file name in the table.
1741 -- Get length of file name
1744 while File (Flen + 1) /= ASCII.NUL loop
1748 -- Loop through file names to find matching one. This is a bit slow,
1749 -- but we only do it in error situations so it is not so terrible.
1750 -- Note that if the loop does not exit, then the desired case will
1751 -- be left set to Mixed_Case, this can happen if the name was not
1752 -- in canonical form, and gets canonicalized on VMS. Possibly we
1753 -- could fix this by unconditinally canonicalizing these names ???
1755 for J in 1 .. Last_Source_File loop
1756 Get_Name_String (Full_Debug_Name (J));
1759 and then Name_Buffer (1 .. Name_Len) = String (File (1 .. Flen))
1761 Desired_Case := Identifier_Casing (J);
1766 -- Copy identifier as given to Name_Buffer
1768 for J in Name_Buffer'Range loop
1769 Name_Buffer (J) := Ident (J);
1771 if Name_Buffer (J) = ASCII.Nul then
1777 Set_Casing (Desired_Case);
1778 end Set_Identifier_Casing;
1780 -----------------------
1781 -- Set_Ignore_Errors --
1782 -----------------------
1784 procedure Set_Ignore_Errors (To : Boolean) is
1786 Errors_Must_Be_Ignored := To;
1787 end Set_Ignore_Errors;
1789 ------------------------------
1790 -- Set_Msg_Insertion_Column --
1791 ------------------------------
1793 procedure Set_Msg_Insertion_Column is
1795 if Style.RM_Column_Check then
1796 Set_Msg_Str (" in column ");
1797 Set_Msg_Int (Int (Error_Msg_Col) + 1);
1799 end Set_Msg_Insertion_Column;
1801 ----------------------------
1802 -- Set_Msg_Insertion_Node --
1803 ----------------------------
1805 procedure Set_Msg_Insertion_Node is
1810 Error_Msg_Node_1 = Error
1811 or else Error_Msg_Node_1 = Any_Type;
1813 if Error_Msg_Node_1 = Empty then
1814 Set_Msg_Blank_Conditional;
1815 Set_Msg_Str ("<empty>");
1817 elsif Error_Msg_Node_1 = Error then
1819 Set_Msg_Str ("<error>");
1821 elsif Error_Msg_Node_1 = Standard_Void_Type then
1823 Set_Msg_Str ("procedure name");
1826 Set_Msg_Blank_Conditional;
1830 K := Nkind (Error_Msg_Node_1);
1832 -- If we have operator case, skip quotes since name of operator
1833 -- itself will supply the required quotations. An operator can be
1834 -- an applied use in an expression or an explicit operator symbol,
1835 -- or an identifier whose name indicates it is an operator.
1838 or else K = N_Operator_Symbol
1839 or else K = N_Defining_Operator_Symbol
1840 or else ((K = N_Identifier or else K = N_Defining_Identifier)
1841 and then Is_Operator_Name (Chars (Error_Msg_Node_1)))
1843 Set_Msg_Node (Error_Msg_Node_1);
1845 -- Normal case, not an operator, surround with quotes
1849 Set_Qualification (Error_Msg_Qual_Level, Error_Msg_Node_1);
1850 Set_Msg_Node (Error_Msg_Node_1);
1855 -- The following assignment ensures that a second ampersand insertion
1856 -- character will correspond to the Error_Msg_Node_2 parameter.
1858 Error_Msg_Node_1 := Error_Msg_Node_2;
1859 end Set_Msg_Insertion_Node;
1861 --------------------------------------
1862 -- Set_Msg_Insertion_Type_Reference --
1863 --------------------------------------
1865 procedure Set_Msg_Insertion_Type_Reference (Flag : Source_Ptr) is
1871 if Error_Msg_Node_1 = Standard_Void_Type then
1872 Set_Msg_Str ("package or procedure name");
1875 elsif Error_Msg_Node_1 = Standard_Exception_Type then
1876 Set_Msg_Str ("exception name");
1879 elsif Error_Msg_Node_1 = Any_Access
1880 or else Error_Msg_Node_1 = Any_Array
1881 or else Error_Msg_Node_1 = Any_Boolean
1882 or else Error_Msg_Node_1 = Any_Character
1883 or else Error_Msg_Node_1 = Any_Composite
1884 or else Error_Msg_Node_1 = Any_Discrete
1885 or else Error_Msg_Node_1 = Any_Fixed
1886 or else Error_Msg_Node_1 = Any_Integer
1887 or else Error_Msg_Node_1 = Any_Modular
1888 or else Error_Msg_Node_1 = Any_Numeric
1889 or else Error_Msg_Node_1 = Any_Real
1890 or else Error_Msg_Node_1 = Any_Scalar
1891 or else Error_Msg_Node_1 = Any_String
1893 Get_Unqualified_Decoded_Name_String (Chars (Error_Msg_Node_1));
1894 Set_Msg_Name_Buffer;
1897 elsif Error_Msg_Node_1 = Universal_Real then
1898 Set_Msg_Str ("type universal real");
1901 elsif Error_Msg_Node_1 = Universal_Integer then
1902 Set_Msg_Str ("type universal integer");
1905 elsif Error_Msg_Node_1 = Universal_Fixed then
1906 Set_Msg_Str ("type universal fixed");
1910 -- Special case of anonymous array
1912 if Nkind (Error_Msg_Node_1) in N_Entity
1913 and then Is_Array_Type (Error_Msg_Node_1)
1914 and then Present (Related_Array_Object (Error_Msg_Node_1))
1916 Set_Msg_Str ("type of ");
1917 Set_Msg_Node (Related_Array_Object (Error_Msg_Node_1));
1918 Set_Msg_Str (" declared");
1919 Set_Msg_Insertion_Line_Number
1920 (Sloc (Related_Array_Object (Error_Msg_Node_1)), Flag);
1924 -- If we fall through, it is not a special case, so first output
1925 -- the name of the type, preceded by private for a private type
1927 if Is_Private_Type (Error_Msg_Node_1) then
1928 Set_Msg_Str ("private type ");
1930 Set_Msg_Str ("type ");
1933 Ent := Error_Msg_Node_1;
1935 if Is_Internal_Name (Chars (Ent)) then
1936 Unwind_Internal_Type (Ent);
1939 -- Types in Standard are displayed as "Standard.name"
1941 if Sloc (Ent) <= Standard_Location then
1943 Set_Msg_Str ("Standard.");
1948 -- Types in other language defined units are displayed as
1949 -- "package-name.type-name"
1952 Is_Predefined_File_Name (Unit_File_Name (Get_Source_Unit (Ent)))
1954 Get_Unqualified_Decoded_Name_String
1955 (Unit_Name (Get_Source_Unit (Ent)));
1956 Name_Len := Name_Len - 2;
1958 Set_Casing (Mixed_Case);
1959 Set_Msg_Name_Buffer;
1961 Set_Casing (Mixed_Case);
1966 -- All other types display as "type name" defined at line xxx
1967 -- possibly qualified if qualification is requested.
1971 Set_Qualification (Error_Msg_Qual_Level, Ent);
1977 -- If the original type did not come from a predefined
1978 -- file, add the location where the type was defined.
1980 if Sloc (Error_Msg_Node_1) > Standard_Location
1982 not Is_Predefined_File_Name
1983 (Unit_File_Name (Get_Source_Unit (Error_Msg_Node_1)))
1985 Set_Msg_Str (" defined");
1986 Set_Msg_Insertion_Line_Number (Sloc (Error_Msg_Node_1), Flag);
1988 -- If it did come from a predefined file, deal with the case where
1989 -- this was a file with a generic instantiation from elsewhere.
1992 if Sloc (Error_Msg_Node_1) > Standard_Location then
1994 Iloc : constant Source_Ptr :=
1995 Instantiation_Location (Sloc (Error_Msg_Node_1));
1998 if Iloc /= No_Location
1999 and then not Suppress_Instance_Location
2001 Set_Msg_Str (" from instance");
2002 Set_Msg_Insertion_Line_Number (Iloc, Flag);
2007 end Set_Msg_Insertion_Type_Reference;
2009 ---------------------------------
2010 -- Set_Msg_Insertion_Unit_Name --
2011 ---------------------------------
2013 procedure Set_Msg_Insertion_Unit_Name is
2015 if Error_Msg_Unit_1 = No_Name then
2018 elsif Error_Msg_Unit_1 = Error_Name then
2020 Set_Msg_Str ("<error>");
2023 Get_Unit_Name_String (Error_Msg_Unit_1);
2026 Set_Msg_Name_Buffer;
2030 -- The following assignment ensures that a second percent insertion
2031 -- character will correspond to the Error_Msg_Unit_2 parameter.
2033 Error_Msg_Unit_1 := Error_Msg_Unit_2;
2034 end Set_Msg_Insertion_Unit_Name;
2040 procedure Set_Msg_Node (Node : Node_Id) is
2045 if Nkind (Node) = N_Designator then
2046 Set_Msg_Node (Name (Node));
2048 Set_Msg_Node (Identifier (Node));
2051 elsif Nkind (Node) = N_Defining_Program_Unit_Name then
2052 Set_Msg_Node (Name (Node));
2054 Set_Msg_Node (Defining_Identifier (Node));
2057 elsif Nkind (Node) = N_Selected_Component then
2058 Set_Msg_Node (Prefix (Node));
2060 Set_Msg_Node (Selector_Name (Node));
2064 -- The only remaining possibilities are identifiers, defining
2065 -- identifiers, pragmas, and pragma argument associations, i.e.
2066 -- nodes that have a Chars field.
2068 -- Internal names generally represent something gone wrong. An exception
2069 -- is the case of internal type names, where we try to find a reasonable
2070 -- external representation for the external name
2072 if Is_Internal_Name (Chars (Node))
2074 ((Is_Entity_Name (Node)
2075 and then Present (Entity (Node))
2076 and then Is_Type (Entity (Node)))
2078 (Nkind (Node) = N_Defining_Identifier and then Is_Type (Node)))
2080 if Nkind (Node) = N_Identifier then
2081 Ent := Entity (Node);
2086 Unwind_Internal_Type (Ent);
2090 Nam := Chars (Node);
2093 -- At this stage, the name to output is in Nam
2095 Get_Unqualified_Decoded_Name_String (Nam);
2097 -- Remove trailing upper case letters from the name (useful for
2098 -- dealing with some cases of internal names.
2100 while Name_Len > 1 and then Name_Buffer (Name_Len) in 'A
' .. 'Z
' loop
2101 Name_Len := Name_Len - 1;
2104 -- If we have any of the names from standard that start with the
2105 -- characters "any " (e.g. Any_Type), then kill the message since
2106 -- almost certainly it is a junk cascaded message.
2109 and then Name_Buffer (1 .. 4) = "any "
2111 Kill_Message := True;
2114 -- Now we have to set the proper case. If we have a source location
2115 -- then do a check to see if the name in the source is the same name
2116 -- as the name in the Names table, except for possible differences
2117 -- in case, which is the case when we can copy from the source.
2120 Src_Loc : constant Source_Ptr := Sloc (Error_Msg_Node_1);
2121 Sbuffer : Source_Buffer_Ptr;
2123 Src_Ptr : Source_Ptr;
2129 -- For standard locations, always use mixed case
2131 if Src_Loc <= No_Location
2132 or else Sloc (Node) <= No_Location
2134 Set_Casing (Mixed_Case);
2137 -- Determine if the reference we are dealing with corresponds
2138 -- to text at the point of the error reference. This will often
2139 -- be the case for simple identifier references, and is the case
2140 -- where we can copy the spelling from the source.
2142 Sbuffer := Source_Text (Get_Source_File_Index (Src_Loc));
2144 while Ref_Ptr <= Name_Len loop
2146 Fold_Lower (Sbuffer (Src_Ptr)) /=
2147 Fold_Lower (Name_Buffer (Ref_Ptr));
2148 Ref_Ptr := Ref_Ptr + 1;
2149 Src_Ptr := Src_Ptr + 1;
2152 -- If we get through the loop without a mismatch, then output
2153 -- the name the way it is spelled in the source program
2155 if Ref_Ptr > Name_Len then
2158 for J in 1 .. Name_Len loop
2159 Name_Buffer (J) := Sbuffer (Src_Ptr);
2160 Src_Ptr := Src_Ptr + 1;
2163 -- Otherwise set the casing using the default identifier casing
2166 Set_Casing (Identifier_Casing (Flag_Source), Mixed_Case);
2171 Set_Msg_Name_Buffer;
2179 procedure Set_Msg_Text (Text : String; Flag : Source_Ptr) is
2180 C : Character; -- Current character
2181 P : Natural; -- Current index;
2184 Manual_Quote_Mode := False;
2185 Is_Unconditional_Msg := False;
2187 Flag_Source := Get_Source_File_Index (Flag);
2190 while P <= Text'Last loop
2194 -- Check for insertion character
2198 Set_Msg_Insertion_Name;
2201 Set_Msg_Insertion_Unit_Name;
2204 Set_Msg_Insertion_File_Name;
2207 Set_Msg_Insertion_Type_Reference (Flag);
2210 Set_Msg_Insertion_Reserved_Name;
2213 Set_Msg_Insertion_Node;
2216 Set_Msg_Insertion_Line_Number (Error_Msg_Sloc, Flag);
2219 Continuation := True;
2222 Set_Msg_Insertion_Column;
2225 Set_Msg_Insertion_Run_Time_Name;
2229 Set_Msg_Insertion_Uint;
2232 Manual_Quote_Mode := not Manual_Quote_Mode;
2236 Is_Unconditional_Msg := True;
2239 null; -- already dealt with
2242 null; -- already dealt with
2245 Set_Msg_Char (Text (P));
2248 -- Upper case letter
2252 -- Start of reserved word if two or more
2254 if P <= Text'Last and then Text (P) in 'A' .. 'Z' then
2256 Set_Msg_Insertion_Reserved_Word (Text, P);
2258 -- Single upper case letter is just inserted
2264 -- Normal character with no special treatment
2278 procedure Set_Posted (N : Node_Id) is
2282 if Is_Serious_Error then
2284 -- We always set Error_Posted on the node itself
2286 Set_Error_Posted (N);
2288 -- If it is a subexpression, then set Error_Posted on parents
2289 -- up to and including the first non-subexpression construct. This
2290 -- helps avoid cascaded error messages within a single expression.
2296 Set_Error_Posted (P);
2297 exit when Nkind (P) not in N_Subexpr;
2300 -- A special check, if we just posted an error on an attribute
2301 -- definition clause, then also set the entity involved as posted.
2302 -- For example, this stops complaining about the alignment after
2303 -- complaining about the size, which is likely to be useless.
2305 if Nkind (P) = N_Attribute_Definition_Clause then
2306 if Is_Entity_Name (Name (P)) then
2307 Set_Error_Posted (Entity (Name (P)));
2313 -----------------------
2314 -- Set_Qualification --
2315 -----------------------
2317 procedure Set_Qualification (N : Nat; E : Entity_Id) is
2319 if N /= 0 and then Scope (E) /= Standard_Standard then
2320 Set_Qualification (N - 1, Scope (E));
2321 Set_Msg_Node (Scope (E));
2324 end Set_Qualification;
2326 ------------------------
2327 -- Special_Msg_Delete --
2328 ------------------------
2330 function Special_Msg_Delete
2332 N : Node_Or_Entity_Id;
2333 E : Node_Or_Entity_Id) return Boolean
2336 -- Never delete messages in -gnatdO mode
2338 if Debug_Flag_OO then
2341 -- When an atomic object refers to a non-atomic type in the same
2342 -- scope, we implicitly make the type atomic. In the non-error
2343 -- case this is surely safe (and in fact prevents an error from
2344 -- occurring if the type is not atomic by default). But if the
2345 -- object cannot be made atomic, then we introduce an extra junk
2346 -- message by this manipulation, which we get rid of here.
2348 -- We identify this case by the fact that it references a type for
2349 -- which Is_Atomic is set, but there is no Atomic pragma setting it.
2351 elsif Msg = "atomic
access to
& cannot be guaranteed
"
2352 and then Is_Type (E)
2353 and then Is_Atomic (E)
2354 and then No (Get_Rep_Pragma (E, Name_Atomic))
2358 -- When a size is wrong for a frozen type there is no explicit
2359 -- size clause, and other errors have occurred, suppress the
2360 -- message, since it is likely that this size error is a cascaded
2361 -- result of other errors. The reason we eliminate unfrozen types
2362 -- is that messages issued before the freeze type are for sure OK.
2364 elsif Msg = "size
for& too small
, minimum allowed
is ^
"
2365 and then Is_Frozen (E)
2366 and then Serious_Errors_Detected > 0
2367 and then Nkind (N) /= N_Component_Clause
2368 and then Nkind (Parent (N)) /= N_Component_Clause
2370 No (Get_Attribute_Definition_Clause (E, Attribute_Size))
2372 No (Get_Attribute_Definition_Clause (E, Attribute_Object_Size))
2374 No (Get_Attribute_Definition_Clause (E, Attribute_Value_Size))
2378 -- All special tests complete, so go ahead with message
2383 end Special_Msg_Delete;
2385 --------------------------
2386 -- Unwind_Internal_Type --
2387 --------------------------
2389 procedure Unwind_Internal_Type (Ent : in out Entity_Id) is
2390 Derived : Boolean := False;
2392 Old_Ent : Entity_Id;
2395 -- Undo placement of a quote, since we will put it back later
2397 Mchar := Msg_Buffer (Msglen);
2400 Msglen := Msglen - 1;
2403 -- The loop here deals with recursive types, we are trying to
2404 -- find a related entity that is not an implicit type. Note
2405 -- that the check with Old_Ent stops us from getting "stuck".
2406 -- Also, we don't output the "type derived from" message more
2407 -- than once in the case where we climb up multiple levels.
2412 -- Implicit access type, use directly designated type
2414 if Is_Access_Type (Ent) then
2415 Set_Msg_Str ("access to ");
2416 Ent := Directly_Designated_Type (Ent);
2420 elsif Is_Class_Wide_Type (Ent) then
2422 Ent := Root_Type (Ent);
2424 -- Use base type if this is a subtype
2426 elsif Ent /= Base_Type (Ent) then
2427 Buffer_Remove ("type ");
2429 -- Avoid duplication "subtype of subtype of", and also replace
2430 -- "derived from subtype of" simply by "derived from"
2432 if not Buffer_Ends_With ("subtype of ")
2433 and then not Buffer_Ends_With ("derived from ")
2435 Set_Msg_Str ("subtype of ");
2438 Ent := Base_Type (Ent);
2440 -- If this is a base type with a first named subtype, use the
2441 -- first named subtype instead. This is not quite accurate in
2442 -- all cases, but it makes too much noise to be accurate and
2443 -- add 'Base
in all cases
. Note that we only
do this
is the
2444 -- first named subtype is not itself an internal name. This
2445 -- avoids the obvious loop (subtype->basetype->subtype) which
2446 -- would otherwise occur!)
2448 elsif Present
(Freeze_Node
(Ent
))
2449 and then Present
(First_Subtype_Link
(Freeze_Node
(Ent
)))
2451 not Is_Internal_Name
2452 (Chars
(First_Subtype_Link
(Freeze_Node
(Ent
))))
2454 Ent
:= First_Subtype_Link
(Freeze_Node
(Ent
));
2456 -- Otherwise use root type
2460 Buffer_Remove
("type ");
2462 -- Test for "subtype of type derived from" which seems
2463 -- excessive and is replaced by simply "type derived from"
2465 Buffer_Remove
("subtype of");
2467 -- Avoid duplication "type derived from type derived from"
2469 if not Buffer_Ends_With
("type derived from ") then
2470 Set_Msg_Str
("type derived from ");
2479 -- If we are stuck in a loop, get out and settle for the internal
2480 -- name after all. In this case we set to kill the message if it
2481 -- is not the first error message (we really try hard not to show
2482 -- the dirty laundry of the implementation to the poor user!)
2484 if Ent
= Old_Ent
then
2485 Kill_Message
:= True;
2489 -- Get out if we finally found a non-internal name to use
2491 exit when not Is_Internal_Name
(Chars
(Ent
));
2497 end Unwind_Internal_Type
;
2503 procedure VMS_Convert
is
2513 P
:= Msg_Buffer
'First;
2519 if Msg_Buffer
(P
) = '-' then
2520 for G
in Gnames
'Range loop
2521 L
:= Gnames
(G
)'Length;
2523 -- See if we have "-ggg switch", where ggg is Gnames entry
2525 if P
+ L
+ 7 <= Msglen
2526 and then Msg_Buffer
(P
+ 1 .. P
+ L
) = Gnames
(G
).all
2527 and then Msg_Buffer
(P
+ L
+ 1 .. P
+ L
+ 7) = " switch"
2529 -- Replace by "/vvv qualifier", where vvv is Vnames entry
2531 N
:= Vnames
(G
)'Length;
2532 Msg_Buffer
(P
+ N
+ 11 .. Msglen
+ N
- L
+ 3) :=
2533 Msg_Buffer
(P
+ L
+ 8 .. Msglen
);
2534 Msg_Buffer
(P
) := '/';
2535 Msg_Buffer
(P
+ 1 .. P
+ N
) := Vnames
(G
).all;
2536 Msg_Buffer
(P
+ N
+ 1 .. P
+ N
+ 10) := " qualifier";
2538 Msglen
:= Msglen
+ N
- L
+ 3;