1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- Warning: Error messages can be generated during Gigi processing by direct
27 -- calls to error message routines, so it is essential that the processing
28 -- in this body be consistent with the requirements for the Gigi processing
29 -- environment, and that in particular, no disallowed table expansion is
32 with Atree
; use Atree
;
33 with Casing
; use Casing
;
34 with Csets
; use Csets
;
35 with Debug
; use Debug
;
36 with Einfo
; use Einfo
;
37 with Einfo
.Entities
; use Einfo
.Entities
;
38 with Einfo
.Utils
; use Einfo
.Utils
;
39 with Erroutc
; use Erroutc
;
40 with Gnatvsn
; use Gnatvsn
;
43 with Nlists
; use Nlists
;
44 with Output
; use Output
;
45 with Scans
; use Scans
;
46 with Sem_Aux
; use Sem_Aux
;
47 with Sinput
; use Sinput
;
48 with Sinfo
; use Sinfo
;
49 with Sinfo
.Nodes
; use Sinfo
.Nodes
;
50 with Sinfo
.Utils
; use Sinfo
.Utils
;
51 with Snames
; use Snames
;
52 with Stand
; use Stand
;
53 with Stringt
; use Stringt
;
54 with Stylesw
; use Stylesw
;
56 with Uname
; use Uname
;
59 package body Errout
is
61 Errors_Must_Be_Ignored
: Boolean := False;
62 -- Set to True by procedure Set_Ignore_Errors (True), when calls to error
63 -- message procedures should be ignored (when parsing irrelevant text in
64 -- sources being preprocessed).
66 Finalize_Called
: Boolean := False;
67 -- Set True if the Finalize routine has been called
69 Warn_On_Instance
: Boolean;
70 -- Flag set true for warning message to be posted on instance
72 ------------------------------------
73 -- Table of Non-Instance Messages --
74 ------------------------------------
76 -- This table contains an entry for every error message processed by the
77 -- Error_Msg routine that is not posted on generic (or inlined) instance.
78 -- As explained in further detail in the Error_Msg procedure body, this
79 -- table is used to avoid posting redundant messages on instances.
81 type NIM_Record
is record
85 -- Type used to store text and location of one message
87 package Non_Instance_Msgs
is new Table
.Table
(
88 Table_Component_Type
=> NIM_Record
,
89 Table_Index_Type
=> Int
,
92 Table_Increment
=> 100,
93 Table_Name
=> "Non_Instance_Msgs");
95 -----------------------
96 -- Local Subprograms --
97 -----------------------
99 procedure Error_Msg_Internal
105 -- This is the low-level routine used to post messages after dealing with
106 -- the issue of messages placed on instantiations (which get broken up
107 -- into separate calls in Error_Msg). Span is the location on which the
108 -- flag will be placed in the output. In the case where the flag is on
109 -- the template, this points directly to the template, not to one of the
110 -- instantiation copies of the template. Opan is the original location
111 -- used to flag the error, and this may indeed point to an instantiation
112 -- copy. So typically we can see Opan pointing to the template location
113 -- in an instantiation copy when Span points to the source location of
114 -- the actual instantiation (i.e the line with the new). Msg_Cont is
115 -- set true if this is a continuation message. Node is the relevant
116 -- Node_Id for this message, to be used to compute the enclosing entity if
117 -- Opt.Include_Subprogram_In_Messages is set.
119 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean;
120 -- Determines if warnings should be suppressed for the given node
122 function OK_Node
(N
: Node_Id
) return Boolean;
123 -- Determines if a node is an OK node to place an error message on (return
124 -- True) or if the error message should be suppressed (return False). A
125 -- message is suppressed if the node already has an error posted on it,
126 -- or if it refers to an Etype that has an error posted on it, or if
127 -- it references an Entity that has an error posted on it.
129 procedure Output_JSON_Message
(Error_Id
: Error_Msg_Id
);
130 -- Output error message Error_Id and any subsequent continuation message
131 -- using a JSON format similar to the one GCC uses when passed
132 -- -fdiagnostics-format=json.
134 procedure Output_Source_Line
135 (L
: Physical_Line_Number
;
136 Sfile
: Source_File_Index
;
138 -- Outputs text of source line L, in file S, together with preceding line
139 -- number, as described above for Output_Line_Number. The Errs parameter
140 -- indicates if there are errors attached to the line, which forces
141 -- listing on, even in the presence of pragma List (Off).
143 function Paren_Required
(N
: Node_Id
) return Boolean;
144 -- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
145 -- around node N are required by the Ada syntax, e.g. when N is an
146 -- expression of a qualified expression.
148 procedure Set_Msg_Insertion_Column
;
149 -- Handle column number insertion (@ insertion character)
151 procedure Set_Msg_Insertion_Node
;
152 -- Handle node (name from node) insertion (& insertion character)
154 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
);
155 -- Handle type reference (right brace insertion character). Flag is the
156 -- location of the flag, which is provided for the internal call to
157 -- Set_Msg_Insertion_Line_Number,
159 procedure Set_Msg_Insertion_Unit_Name
(Suffix
: Boolean := True);
160 -- Handle unit name insertion ($ insertion character). Depending on Boolean
161 -- parameter Suffix, (spec) or (body) is appended after the unit name.
163 procedure Set_Msg_Node
(Node
: Node_Id
);
164 -- Add the sequence of characters for the name associated with the given
165 -- node to the current message. For N_Designator, N_Selected_Component,
166 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
169 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
);
170 -- Add a sequence of characters to the current message. The characters may
171 -- be one of the special insertion characters (see documentation in spec).
172 -- Flag is the location at which the error is to be posted, which is used
173 -- to determine whether or not the # insertion needs a file name. The
174 -- variables Msg_Buffer are set on return Msglen.
176 procedure Set_Posted
(N
: Node_Id
);
177 -- Sets the Error_Posted flag on the given node, and all its parents that
178 -- are subexpressions and then on the parent non-subexpression construct
179 -- that contains the original expression. If that parent is a named
180 -- association, the flag is further propagated to its parent. This is done
181 -- in order to guard against cascaded errors. Note that this call has an
182 -- effect for a serious error only.
184 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
);
185 -- Outputs up to N levels of qualification for the given entity. For
186 -- example, the entity A.B.C.D will output B.C. if N = 2.
188 function Special_Msg_Delete
190 N
: Node_Or_Entity_Id
;
191 E
: Node_Or_Entity_Id
) return Boolean;
192 -- This function is called from Error_Msg_NEL, passing the message Msg,
193 -- node N on which the error is to be posted, and the entity or node E
194 -- to be used for an & insertion in the message if any. The job of this
195 -- procedure is to test for certain cascaded messages that we would like
196 -- to suppress. If the message is to be suppressed then we return True.
197 -- If the message should be generated (the normal case) False is returned.
199 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
);
200 -- This procedure is given an entity id for an internal type, i.e. a type
201 -- with an internal name. It unwinds the type to try to get to something
202 -- reasonably printable, generating prefixes like "subtype of", "access
203 -- to", etc along the way in the buffer. The value in Ent on return is the
204 -- final name to be printed. Hopefully this is not an internal name, but in
205 -- some internal name cases, it is an internal name, and has to be printed
206 -- anyway (although in this case the message has been killed if possible).
207 -- The global variable Class_Flag is set to True if the resulting entity
208 -- should have 'Class appended to its name (see Add_Class procedure), and
209 -- is otherwise unchanged.
211 function Warn_Insertion
return String;
212 -- This is called for warning messages only (so Warning_Msg_Char is set)
213 -- and returns a corresponding string to use at the beginning of generated
214 -- auxiliary messages, such as "in instantiation at ...".
217 -- other trimmed, prefixed and suffixed with "?".
219 -----------------------
220 -- Change_Error_Text --
221 -----------------------
223 procedure Change_Error_Text
(Error_Id
: Error_Msg_Id
; New_Msg
: String) is
224 Save_Next
: Error_Msg_Id
;
225 Err_Id
: Error_Msg_Id
:= Error_Id
;
228 Set_Msg_Text
(New_Msg
, Errors
.Table
(Error_Id
).Sptr
.Ptr
);
229 Errors
.Table
(Error_Id
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
231 -- If in immediate error message mode, output modified error message now
232 -- This is just a bit tricky, because we want to output just a single
233 -- message, and the messages we modified is already linked in. We solve
234 -- this by temporarily resetting its forward pointer to empty.
236 if Debug_Flag_OO then
237 Save_Next := Errors.Table (Error_Id).Next;
238 Errors.Table (Error_Id).Next := No_Error_Msg;
241 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
242 Output_Error_Msgs (Err_Id);
243 Errors.Table (Error_Id).Next := Save_Next;
245 end Change_Error_Text;
247 ------------------------
248 -- Compilation_Errors --
249 ------------------------
251 function Compilation_Errors return Boolean is
253 if not Finalize_Called then
256 return Erroutc.Compilation_Errors;
258 end Compilation_Errors;
260 --------------------------------------
261 -- Delete_Warning_And_Continuations --
262 --------------------------------------
264 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
268 pragma Assert (not Errors.Table (Msg).Msg_Cont);
273 M : Error_Msg_Object renames Errors.Table (Id);
276 if not M.Deleted then
278 Warnings_Detected := Warnings_Detected - 1;
281 Warning_Info_Messages := Warning_Info_Messages - 1;
285 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
290 exit when Id = No_Error_Msg;
291 exit when not Errors.Table (Id).Msg_Cont;
294 end Delete_Warning_And_Continuations;
300 -- Error_Msg posts a flag at the given location, except that if the
301 -- Flag_Location/Flag_Span points within a generic template and corresponds
302 -- to an instantiation of this generic template, then the actual message
303 -- will be posted on the generic instantiation, along with additional
304 -- messages referencing the generic declaration.
306 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
308 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
311 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
313 Error_Msg (Msg, Flag_Span, Current_Node);
318 Flag_Location : Source_Ptr;
319 Is_Compile_Time_Pragma : Boolean)
321 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
323 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
324 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
325 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
330 Flag_Location : Source_Ptr;
334 Error_Msg (Msg, To_Span (Flag_Location), N);
339 Flag_Span : Source_Span;
342 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
344 Sindex : Source_File_Index;
345 -- Source index for flag location
347 Orig_Loc : Source_Ptr;
348 -- Original location of Flag_Location (i.e. location in original
349 -- template in instantiation case, otherwise unchanged).
352 -- Return if all errors are to be ignored
354 if Get_Ignore_Errors then
358 -- If we already have messages, and we are trying to place a message at
359 -- No_Location, then just ignore the attempt since we assume that what
360 -- is happening is some cascaded junk. Note that this is safe in the
361 -- sense that proceeding will surely bomb. We will also bomb if the flag
362 -- location is No_Location and we don't have any messages so far, but
363 -- that is a real bug and a legitimate bomb, so we go ahead.
365 if Flag_Location = No_Location
366 and then Total_Errors_Detected > 0
371 -- Start of processing for new message
373 Sindex := Get_Source_File_Index (Flag_Location);
374 Prescan_Message (Msg);
375 Orig_Loc := Original_Location (Flag_Location);
377 -- If the current location is in an instantiation, the issue arises of
378 -- whether to post the message on the template or the instantiation.
380 -- The way we decide is to see if we have posted the same message on
381 -- the template when we compiled the template (the template is always
382 -- compiled before any instantiations). For this purpose, we use a
383 -- separate table of messages. The reason we do this is twofold:
385 -- First, the messages can get changed by various processing
386 -- including the insertion of tokens etc, making it hard to
387 -- do the comparison.
389 -- Second, we will suppress a warning on a template if it is not in
390 -- the current extended source unit. That's reasonable and means we
391 -- don't want the warning on the instantiation here either, but it
392 -- does mean that the main error table would not in any case include
395 if Flag_Location = Orig_Loc then
396 Non_Instance_Msgs.Append ((new String'(Msg
), Flag_Location
));
397 Warn_On_Instance
:= False;
399 -- Here we have an instance message
402 -- Delete if debug flag off, and this message duplicates a message
403 -- already posted on the corresponding template
405 if not Debug_Flag_GG
then
406 for J
in Non_Instance_Msgs
.First
.. Non_Instance_Msgs
.Last
loop
407 if Msg
= Non_Instance_Msgs
.Table
(J
).Msg
.all
408 and then Non_Instance_Msgs
.Table
(J
).Loc
= Orig_Loc
415 -- No duplicate, so error/warning will be posted on instance
417 Warn_On_Instance
:= Is_Warning_Msg
;
420 -- Ignore warning message that is suppressed for this location. Note
421 -- that style checks are not considered warning messages for this
424 if Is_Warning_Msg
and then Warnings_Suppressed
(Orig_Loc
) /= No_String
428 -- For style messages, check too many messages so far
431 and then Maximum_Messages
/= 0
432 and then Warnings_Detected
>= Maximum_Messages
436 -- Suppress warnings inside a loop that is known to be null or is
437 -- probably null (i.e. when loop executes only if invalid values
438 -- present). In either case warnings in the loop are likely to be junk.
440 elsif Is_Warning_Msg
and then Present
(N
) then
447 while Present
(P
) loop
448 if Nkind
(P
) = N_Loop_Statement
449 and then Suppress_Loop_Warnings
(P
)
459 -- The idea at this stage is that we have two kinds of messages
461 -- First, we have those messages that are to be placed as requested at
462 -- Flag_Location. This includes messages that have nothing to do with
463 -- generics, and also messages placed on generic templates that reflect
464 -- an error in the template itself. For such messages we simply call
465 -- Error_Msg_Internal to place the message in the requested location.
467 if Instantiation
(Sindex
) = No_Location
then
468 Error_Msg_Internal
(Msg
, Flag_Span
, Flag_Span
, False, N
);
472 -- If we are trying to flag an error in an instantiation, we may have
473 -- a generic contract violation. What we generate in this case is:
475 -- instantiation error at ...
476 -- original error message
480 -- warning: in instantiation at ...
481 -- warning: original warning message
485 -- info: in instantiation at ...
486 -- info: original info message
488 -- All these messages are posted at the location of the top level
489 -- instantiation. If there are nested instantiations, then the
490 -- instantiation error message can be repeated, pointing to each
491 -- of the relevant instantiations.
493 -- Note: the instantiation mechanism is also shared for inlining of
494 -- subprogram bodies when front end inlining is done. In this case the
495 -- messages have the form:
497 -- in inlined body at ...
498 -- original error message
502 -- warning: in inlined body at ...
503 -- warning: original warning message
507 -- info: in inlined body at ...
508 -- info: original info message
510 -- OK, here we have an instantiation error, and we need to generate the
511 -- error on the instantiation, rather than on the template.
514 Actual_Error_Loc
: Source_Ptr
;
515 -- Location of outer level instantiation in instantiation case, or
516 -- just a copy of Flag_Location in the normal case. This is the
517 -- location where all error messages will actually be posted.
519 Save_Error_Msg_Sloc
: constant Source_Ptr
:= Error_Msg_Sloc
;
520 -- Save possible location set for caller's message. We need to use
521 -- Error_Msg_Sloc for the location of the instantiation error but we
522 -- have to preserve a possible original value.
524 X
: Source_File_Index
;
526 Msg_Cont_Status
: Boolean;
527 -- Used to label continuation lines in instantiation case with
528 -- proper Msg_Cont status.
531 -- Loop to find highest level instantiation, where all error
532 -- messages will be placed.
536 Actual_Error_Loc
:= Instantiation
(X
);
537 X
:= Get_Source_File_Index
(Actual_Error_Loc
);
538 exit when Instantiation
(X
) = No_Location
;
541 -- Since we are generating the messages at the instantiation point in
542 -- any case, we do not want the references to the bad lines in the
543 -- instance to be annotated with the location of the instantiation.
545 Suppress_Instance_Location
:= True;
546 Msg_Cont_Status
:= False;
548 -- Loop to generate instantiation messages
550 Error_Msg_Sloc
:= Flag_Location
;
551 X
:= Get_Source_File_Index
(Flag_Location
);
552 while Instantiation
(X
) /= No_Location
loop
554 -- Suppress instantiation message on continuation lines
556 if Msg
(Msg
'First) /= '\' then
558 -- Case of inlined body
560 if Inlined_Body
(X
) then
563 (Msg
=> "info: in inlined body #",
564 Span
=> To_Span
(Actual_Error_Loc
),
566 Msg_Cont
=> Msg_Cont_Status
,
569 elsif Is_Warning_Msg
then
571 (Msg
=> Warn_Insertion
& "in inlined body #",
572 Span
=> To_Span
(Actual_Error_Loc
),
574 Msg_Cont
=> Msg_Cont_Status
,
577 elsif Is_Style_Msg
then
579 (Msg
=> "style: in inlined body #",
580 Span
=> To_Span
(Actual_Error_Loc
),
582 Msg_Cont
=> Msg_Cont_Status
,
587 (Msg
=> "error in inlined body #",
588 Span
=> To_Span
(Actual_Error_Loc
),
590 Msg_Cont
=> Msg_Cont_Status
,
594 -- Case of generic instantiation
599 (Msg
=> "info: in instantiation #",
600 Span
=> To_Span
(Actual_Error_Loc
),
602 Msg_Cont
=> Msg_Cont_Status
,
605 elsif Is_Warning_Msg
then
607 (Msg
=> Warn_Insertion
& "in instantiation #",
608 Span
=> To_Span
(Actual_Error_Loc
),
610 Msg_Cont
=> Msg_Cont_Status
,
613 elsif Is_Style_Msg
then
615 (Msg
=> "style: in instantiation #",
616 Span
=> To_Span
(Actual_Error_Loc
),
618 Msg_Cont
=> Msg_Cont_Status
,
623 (Msg
=> "instantiation error #",
624 Span
=> To_Span
(Actual_Error_Loc
),
626 Msg_Cont
=> Msg_Cont_Status
,
632 Error_Msg_Sloc
:= Instantiation
(X
);
633 X
:= Get_Source_File_Index
(Error_Msg_Sloc
);
634 Msg_Cont_Status
:= True;
637 Suppress_Instance_Location
:= False;
638 Error_Msg_Sloc
:= Save_Error_Msg_Sloc
;
640 -- Here we output the original message on the outer instantiation
644 Span
=> To_Span
(Actual_Error_Loc
),
646 Msg_Cont
=> Msg_Cont_Status
,
651 ----------------------------------
652 -- Error_Msg_Ada_2005_Extension --
653 ----------------------------------
655 procedure Error_Msg_Ada_2005_Extension
(Extension
: String) is
656 Loc
: constant Source_Ptr
:= Token_Ptr
;
658 if Ada_Version
< Ada_2005
then
659 Error_Msg
(Extension
& " is an Ada 2005 extension", Loc
);
661 if No
(Ada_Version_Pragma
) then
662 Error_Msg
("\unit must be compiled with -gnat05 switch", Loc
);
664 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
665 Error_Msg
("\incompatible with Ada version set#", Loc
);
668 end Error_Msg_Ada_2005_Extension
;
670 --------------------------------
671 -- Error_Msg_Ada_2012_Feature --
672 --------------------------------
674 procedure Error_Msg_Ada_2012_Feature
(Feature
: String; Loc
: Source_Ptr
) is
676 if Ada_Version
< Ada_2012
then
677 Error_Msg
(Feature
& " is an Ada 2012 feature", Loc
);
679 if No
(Ada_Version_Pragma
) then
680 Error_Msg
("\unit must be compiled with -gnat2012 switch", Loc
);
682 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
683 Error_Msg
("\incompatible with Ada version set#", Loc
);
686 end Error_Msg_Ada_2012_Feature
;
688 --------------------------------
689 -- Error_Msg_Ada_2022_Feature --
690 --------------------------------
692 procedure Error_Msg_Ada_2022_Feature
(Feature
: String; Loc
: Source_Ptr
) is
694 if Ada_Version
< Ada_2022
then
695 Error_Msg
(Feature
& " is an Ada 2022 feature", Loc
);
697 if No
(Ada_Version_Pragma
) then
698 Error_Msg
("\unit must be compiled with -gnat2022 switch", Loc
);
700 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
701 Error_Msg
("\incompatible with Ada version set#", Loc
);
704 end Error_Msg_Ada_2022_Feature
;
710 procedure Error_Msg_AP
(Msg
: String) is
715 -- If we had saved the Scan_Ptr value after scanning the previous
716 -- token, then we would have exactly the right place for putting
717 -- the flag immediately at hand. However, that would add at least
718 -- two instructions to a Scan call *just* to service the possibility
719 -- of an Error_Msg_AP call. So instead we reconstruct that value.
721 -- We have two possibilities, start with Prev_Token_Ptr and skip over
722 -- the current token, which is made harder by the possibility that this
723 -- token may be in error, or start with Token_Ptr and work backwards.
724 -- We used to take the second approach, but it's hard because of
725 -- comments, and harder still because things that look like comments
726 -- can appear inside strings. So now we take the first approach.
728 -- Note: in the case where there is no previous token, Prev_Token_Ptr
729 -- is set to Source_First, which is a reasonable position for the
730 -- error flag in this situation.
732 S1
:= Prev_Token_Ptr
;
735 -- If the previous token is a string literal, we need a special approach
736 -- since there may be white space inside the literal and we don't want
737 -- to stop on that white space.
739 -- Note: since this is an error recovery issue anyway, it is not worth
740 -- worrying about special UTF_32 line terminator characters here.
742 if Prev_Token
= Tok_String_Literal
then
746 if Source
(S1
) = C
then
748 exit when Source
(S1
) /= C
;
749 elsif Source
(S1
) in Line_Terminator
then
754 -- Character literal also needs special handling
756 elsif Prev_Token
= Tok_Char_Literal
then
759 -- Otherwise we search forward for the end of the current token, marked
760 -- by a line terminator, white space, a comment symbol or if we bump
761 -- into the following token (i.e. the current token).
763 -- Again, it is not worth worrying about UTF_32 special line terminator
764 -- characters in this context, since this is only for error recovery.
767 while Source
(S1
) not in Line_Terminator
768 and then Source
(S1
) /= ' '
769 and then Source
(S1
) /= ASCII
.HT
770 and then (Source
(S1
) /= '-' or else Source
(S1
+ 1) /= '-')
771 and then S1
/= Token_Ptr
777 -- S1 is now set to the location for the flag
786 procedure Error_Msg_BC
(Msg
: String) is
788 -- If we are at end of file, post the flag after the previous token
790 if Token
= Tok_EOF
then
793 -- If we are at start of file, post the flag at the current token
795 elsif Token_Ptr
= Source_First
(Current_Source_File
) then
798 -- If the character before the current token is a space or a horizontal
799 -- tab, then we place the flag on this character (in the case of a tab
800 -- we would really like to place it in the "last" character of the tab
801 -- space, but that it too much trouble to worry about).
803 elsif Source
(Token_Ptr
- 1) = ' '
804 or else Source
(Token_Ptr
- 1) = ASCII
.HT
806 Error_Msg
(Msg
, Token_Ptr
- 1);
808 -- If there is no space or tab before the current token, then there is
809 -- no room to place the flag before the token, so we place it on the
810 -- token instead (this happens for example at the start of a line).
813 Error_Msg
(Msg
, Token_Ptr
);
821 procedure Error_Msg_CRT
(Feature
: String; N
: Node_Id
) is
823 if No_Run_Time_Mode
then
824 Error_Msg_N
('|' & Feature
& " not allowed in no run time mode", N
);
826 else pragma Assert
(Configurable_Run_Time_Mode
);
827 Error_Msg_N
('|' & Feature
& " not supported by configuration>", N
);
830 Configurable_Run_Time_Violations
:= Configurable_Run_Time_Violations
+ 1;
837 procedure Error_Msg_PT
(E
: Entity_Id
; Iface_Prim
: Entity_Id
) is
840 ("illegal overriding of subprogram inherited from interface", E
);
842 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
844 if Ekind
(E
) = E_Function
then
846 ("\first formal of & declared # must be of mode `IN` "
847 & "or access-to-constant", E
);
850 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
851 & "or access-to-variable", E
);
859 procedure Error_Msg_F
(Msg
: String; N
: Node_Id
) is
862 First_And_Last_Nodes
(N
, Fst
, Lst
);
863 Error_Msg_NEL
(Msg
, N
, N
,
864 To_Span
(Ptr
=> Sloc
(Fst
),
865 First
=> First_Sloc
(Fst
),
866 Last
=> Last_Sloc
(Lst
)));
873 procedure Error_Msg_FE
876 E
: Node_Or_Entity_Id
)
880 First_And_Last_Nodes
(N
, Fst
, Lst
);
881 Error_Msg_NEL
(Msg
, N
, E
,
882 To_Span
(Ptr
=> Sloc
(Fst
),
883 First
=> First_Sloc
(Fst
),
884 Last
=> Last_Sloc
(Lst
)));
887 ------------------------------
888 -- Error_Msg_GNAT_Extension --
889 ------------------------------
891 procedure Error_Msg_GNAT_Extension
894 Is_Core_Extension
: Boolean := False)
897 if (if Is_Core_Extension
898 then Core_Extensions_Allowed
899 else All_Extensions_Allowed
)
904 Error_Msg
(Extension
& " is a 'G'N'A'T-specific extension", Loc
);
906 if No
(Ada_Version_Pragma
) then
907 if Is_Core_Extension
then
909 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
910 "or use pragma Extensions_Allowed (On) '[or All']", Loc
);
913 ("\unit must be compiled with -gnatX0 " &
914 "or use pragma Extensions_Allowed (All)", Loc
);
917 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
918 Error_Msg
("\incompatible with Ada version set#", Loc
);
919 if Is_Core_Extension
then
921 ("\must use pragma Extensions_Allowed (On) '[or All']", Loc
);
924 ("\must use pragma Extensions_Allowed (All)", Loc
);
927 end Error_Msg_GNAT_Extension
;
929 ------------------------
930 -- Error_Msg_Internal --
931 ------------------------
933 procedure Error_Msg_Internal
940 Sptr
: constant Source_Ptr
:= Span
.Ptr
;
941 Optr
: constant Source_Ptr
:= Opan
.Ptr
;
943 Next_Msg
: Error_Msg_Id
;
944 -- Pointer to next message at insertion point
946 Prev_Msg
: Error_Msg_Id
;
947 -- Pointer to previous message at insertion point
949 Temp_Msg
: Error_Msg_Id
;
952 -- Set if warning to be treated as error
954 procedure Handle_Serious_Error
;
955 -- Internal procedure to do all error message handling for a serious
956 -- error message, other than bumping the error counts and arranging
957 -- for the message to be output.
959 --------------------------
960 -- Handle_Serious_Error --
961 --------------------------
963 procedure Handle_Serious_Error
is
965 -- Turn off code generation if not done already
967 if Operating_Mode
= Generate_Code
then
968 Operating_Mode
:= Check_Semantics
;
969 Expander_Active
:= False;
972 -- Set the fatal error flag in the unit table unless we are in
973 -- Try_Semantics mode (in which case we set ignored mode if not
974 -- currently set. This stops the semantics from being performed
975 -- if we find a serious error. This is skipped if we are currently
976 -- dealing with the configuration pragma file.
978 if Current_Source_Unit
/= No_Unit
then
980 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Sptr
);
982 if Try_Semantics
then
983 if Fatal_Error
(U
) = None
then
984 Set_Fatal_Error
(U
, Error_Ignored
);
987 Set_Fatal_Error
(U
, Error_Detected
);
992 -- Disable warnings on unused use clauses and the like. Otherwise, an
993 -- error might hide a reference to an entity in a used package, so
994 -- after fixing the error, the use clause no longer looks like it was
997 Warnsw
.Check_Unreferenced
:= False;
998 Warnsw
.Check_Unreferenced_Formals
:= False;
999 end Handle_Serious_Error
;
1001 -- Start of processing for Error_Msg_Internal
1004 -- Detect common mistake of prefixing or suffixing the message with a
1007 pragma Assert
(Msg
(Msg
'First) /= ' ' and then Msg
(Msg
'Last) /= ' ');
1009 if Raise_Exception_On_Error
/= 0 then
1010 raise Error_Msg_Exception
;
1013 Continuation
:= Msg_Cont
;
1014 Continuation_New_Line
:= False;
1015 Suppress_Message
:= False;
1016 Kill_Message
:= False;
1017 Set_Msg_Text
(Msg
, Sptr
);
1019 -- Kill continuation if parent message killed
1021 if Continuation
and Last_Killed
then
1025 -- Return without doing anything if message is suppressed
1028 and then not All_Errors_Mode
1029 and then not Is_Warning_Msg
1030 and then not Is_Unconditional_Msg
1032 if not Continuation
then
1033 Last_Killed
:= True;
1039 -- Return without doing anything if message is killed and this is not
1040 -- the first error message. The philosophy is that if we get a weird
1041 -- error message and we already have had a message, then we hope the
1042 -- weird message is a junk cascaded message
1045 and then not All_Errors_Mode
1046 and then Total_Errors_Detected
/= 0
1048 if not Continuation
then
1049 Last_Killed
:= True;
1055 -- Special check for warning message to see if it should be output
1057 if Is_Warning_Msg
then
1059 -- Immediate return if warning message and warnings are suppressed
1061 if Warnings_Suppressed
(Optr
) /= No_String
1063 Warnings_Suppressed
(Sptr
) /= No_String
1065 Cur_Msg
:= No_Error_Msg
;
1069 -- If the flag location is in the main extended source unit then for
1070 -- sure we want the warning since it definitely belongs
1072 if In_Extended_Main_Source_Unit
(Sptr
) then
1075 -- If the main unit has not been read yet. The warning must be on
1076 -- a configuration file: gnat.adc or user-defined. This means we
1077 -- are not parsing the main unit yet, so skip following checks.
1079 elsif No
(Cunit
(Main_Unit
)) then
1082 -- If the flag location is not in the extended main source unit, then
1083 -- we want to eliminate the warning, unless it is in the extended
1084 -- main code unit and we want warnings on the instance.
1086 elsif In_Extended_Main_Code_Unit
(Sptr
) and then Warn_On_Instance
then
1089 -- Keep warning if debug flag G set
1091 elsif Debug_Flag_GG
then
1094 -- Keep warning if message text contains !!
1096 elsif Has_Double_Exclam
then
1099 -- Here is where we delete a warning from a with'ed unit
1102 Cur_Msg
:= No_Error_Msg
;
1104 if not Continuation
then
1105 Last_Killed
:= True;
1112 -- If message is to be ignored in special ignore message mode, this is
1113 -- where we do this special processing, bypassing message output.
1115 if Ignore_Errors_Enable
> 0 then
1116 if Is_Serious_Error
then
1117 Handle_Serious_Error
;
1123 -- If error message line length set, and this is a continuation message
1124 -- then all we do is to append the text to the text of the last message
1125 -- with a comma space separator (eliminating a possible (style) or
1128 if Error_Msg_Line_Length
/= 0 and then Continuation
then
1129 Cur_Msg
:= Errors
.Last
;
1132 Oldm
: String_Ptr
:= Errors
.Table
(Cur_Msg
).Text
;
1133 Newm
: String (1 .. Oldm
'Last + 2 + Msglen
);
1138 -- First copy old message to new one and free it
1140 Newm
(Oldm
'Range) := Oldm
.all;
1141 Newl
:= Oldm
'Length;
1144 -- Remove (style) or info: at start of message
1146 if Msglen
> 8 and then Msg_Buffer
(1 .. 8) = "(style) " then
1149 elsif Msglen
> 6 and then Msg_Buffer
(1 .. 6) = "info: " then
1156 -- Now deal with separation between messages. Normally this is
1157 -- simply comma space, but there are some special cases.
1159 -- If continuation new line, then put actual NL character in msg
1161 if Continuation_New_Line
then
1163 Newm
(Newl
) := ASCII
.LF
;
1165 -- If continuation message is enclosed in parentheses, then
1166 -- special treatment (don't need a comma, and we want to combine
1167 -- successive parenthetical remarks into a single one with
1168 -- separating commas).
1170 elsif Msg_Buffer
(M
) = '(' and then Msg_Buffer
(Msglen
) = ')' then
1172 -- Case where existing message ends in right paren, remove
1173 -- and separate parenthetical remarks with a comma.
1175 if Newm
(Newl
) = ')' then
1177 Msg_Buffer
(M
) := ' ';
1179 -- Case where we are adding new parenthetical comment
1186 -- Case where continuation not in parens and no new line
1189 Newm
(Newl
+ 1 .. Newl
+ 2) := ", ";
1193 -- Append new message
1195 Newm
(Newl
+ 1 .. Newl
+ Msglen
- M
+ 1) :=
1196 Msg_Buffer
(M
.. Msglen
);
1197 Newl
:= Newl
+ Msglen
- M
+ 1;
1198 Errors
.Table
(Cur_Msg
).Text
:= new String'(Newm (1 .. Newl));
1200 -- Update warning msg flag and message doc char if needed
1202 if Is_Warning_Msg then
1203 if not Errors.Table (Cur_Msg).Warn then
1204 Errors.Table (Cur_Msg).Warn := True;
1205 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1207 elsif Warning_Msg_Char /= " " then
1208 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1216 -- Here we build a new error object
1219 ((Text => new String'(Msg_Buffer
(1 .. Msglen
)),
1220 Next
=> No_Error_Msg
,
1221 Prev
=> No_Error_Msg
,
1224 Insertion_Sloc
=> (if Has_Insertion_Line
then Error_Msg_Sloc
1226 Sfile
=> Get_Source_File_Index
(Sptr
),
1227 Line
=> Get_Physical_Line_Number
(Sptr
),
1228 Col
=> Get_Column_Number
(Sptr
),
1229 Compile_Time_Pragma
=> Is_Compile_Time_Msg
,
1230 Warn
=> Is_Warning_Msg
,
1231 Info
=> Is_Info_Msg
,
1232 Check
=> Is_Check_Msg
,
1233 Warn_Err
=> False, -- reset below
1234 Warn_Chr
=> Warning_Msg_Char
,
1235 Warn_Runtime_Raise
=> Is_Runtime_Raise
,
1236 Style
=> Is_Style_Msg
,
1237 Serious
=> Is_Serious_Error
,
1238 Uncond
=> Is_Unconditional_Msg
,
1239 Msg_Cont
=> Continuation
,
1242 Cur_Msg
:= Errors
.Last
;
1244 -- Test if warning to be treated as error
1247 (Is_Warning_Msg
or Is_Style_Msg
)
1248 and then (Warning_Treated_As_Error
(Msg_Buffer
(1 .. Msglen
))
1250 Warning_Treated_As_Error
(Get_Warning_Tag
(Cur_Msg
)));
1252 -- Propagate Warn_Err to this message and preceding continuations.
1253 -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
1254 -- current continued message could have been escalated from warning to
1257 for J
in reverse 1 .. Errors
.Last
loop
1258 Errors
.Table
(J
).Warn_Err
:= Warn_Err
;
1259 Errors
.Table
(J
).Warn
:= Is_Warning_Msg
;
1260 Errors
.Table
(J
).Warn_Runtime_Raise
:= Is_Runtime_Raise
;
1261 exit when not Errors
.Table
(J
).Msg_Cont
;
1264 -- If immediate errors mode set, output error message now. Also output
1265 -- now if the -d1 debug flag is set (so node number message comes out
1266 -- just before actual error message)
1268 if Debug_Flag_OO
or else Debug_Flag_1
then
1271 (Errors
.Table
(Cur_Msg
).Line
, Errors
.Table
(Cur_Msg
).Sfile
, True);
1272 Temp_Msg
:= Cur_Msg
;
1273 Output_Error_Msgs
(Temp_Msg
);
1275 -- If not in immediate errors mode, then we insert the message in the
1276 -- error chain for later output by Finalize. The messages are sorted
1277 -- first by unit (main unit comes first), and within a unit by source
1278 -- location (earlier flag location first in the chain).
1281 -- First a quick check, does this belong at the very end of the chain
1282 -- of error messages. This saves a lot of time in the normal case if
1283 -- there are lots of messages.
1285 if Last_Error_Msg
/= No_Error_Msg
1286 and then Errors
.Table
(Cur_Msg
).Sfile
=
1287 Errors
.Table
(Last_Error_Msg
).Sfile
1288 and then (Sptr
> Errors
.Table
(Last_Error_Msg
).Sptr
.Ptr
1290 (Sptr
= Errors
.Table
(Last_Error_Msg
).Sptr
.Ptr
1292 Optr
> Errors
.Table
(Last_Error_Msg
).Optr
.Ptr
))
1294 Prev_Msg
:= Last_Error_Msg
;
1295 Next_Msg
:= No_Error_Msg
;
1297 -- Otherwise do a full sequential search for the insertion point
1300 Prev_Msg
:= No_Error_Msg
;
1301 Next_Msg
:= First_Error_Msg
;
1302 while Next_Msg
/= No_Error_Msg
loop
1304 Errors
.Table
(Cur_Msg
).Sfile
< Errors
.Table
(Next_Msg
).Sfile
;
1306 if Errors
.Table
(Cur_Msg
).Sfile
= Errors
.Table
(Next_Msg
).Sfile
1308 exit when Sptr
< Errors
.Table
(Next_Msg
).Sptr
.Ptr
1309 or else (Sptr
= Errors
.Table
(Next_Msg
).Sptr
.Ptr
1311 Optr
< Errors
.Table
(Next_Msg
).Optr
.Ptr
);
1314 Prev_Msg
:= Next_Msg
;
1315 Next_Msg
:= Errors
.Table
(Next_Msg
).Next
;
1319 -- Now we insert the new message in the error chain.
1321 -- The possible insertion point for the new message is after Prev_Msg
1322 -- and before Next_Msg. However, this is where we do a special check
1323 -- for redundant parsing messages, defined as messages posted on the
1324 -- same line. The idea here is that probably such messages are junk
1325 -- from the parser recovering. In full errors mode, we don't do this
1326 -- deletion, but otherwise such messages are discarded at this stage.
1328 if Prev_Msg
/= No_Error_Msg
1329 and then Errors
.Table
(Prev_Msg
).Line
=
1330 Errors
.Table
(Cur_Msg
).Line
1331 and then Errors
.Table
(Prev_Msg
).Sfile
=
1332 Errors
.Table
(Cur_Msg
).Sfile
1333 and then Compiler_State
= Parsing
1334 and then not All_Errors_Mode
1336 -- Don't delete unconditional messages and at this stage, don't
1337 -- delete continuation lines; we attempted to delete those earlier
1338 -- if the parent message was deleted.
1340 if not Errors
.Table
(Cur_Msg
).Uncond
1341 and then not Continuation
1343 -- Don't delete if prev msg is warning and new msg is an error.
1344 -- This is because we don't want a real error masked by a
1345 -- warning. In all other cases (that is parse errors for the
1346 -- same line that are not unconditional) we do delete the
1347 -- message. This helps to avoid junk extra messages from
1348 -- cascaded parsing errors
1350 if not (Errors
.Table
(Prev_Msg
).Warn
1352 Errors
.Table
(Prev_Msg
).Style
)
1354 (Errors
.Table
(Cur_Msg
).Warn
1356 Errors
.Table
(Cur_Msg
).Style
)
1358 -- All tests passed, delete the message by simply returning
1359 -- without any further processing.
1361 pragma Assert
(not Continuation
);
1363 Last_Killed
:= True;
1369 -- Come here if message is to be inserted in the error chain
1371 if not Continuation
then
1372 Last_Killed
:= False;
1375 if Prev_Msg
= No_Error_Msg
then
1376 First_Error_Msg
:= Cur_Msg
;
1378 Errors
.Table
(Prev_Msg
).Next
:= Cur_Msg
;
1381 Errors
.Table
(Cur_Msg
).Next
:= Next_Msg
;
1383 if Next_Msg
= No_Error_Msg
then
1384 Last_Error_Msg
:= Cur_Msg
;
1388 -- Bump appropriate statistics counts
1390 if Errors
.Table
(Cur_Msg
).Info
then
1392 -- Could be (usually is) both "info" and "warning"
1394 if Errors
.Table
(Cur_Msg
).Warn
then
1395 Warning_Info_Messages
:= Warning_Info_Messages
+ 1;
1396 Warnings_Detected
:= Warnings_Detected
+ 1;
1398 Report_Info_Messages
:= Report_Info_Messages
+ 1;
1401 elsif Errors
.Table
(Cur_Msg
).Warn
1402 or else Errors
.Table
(Cur_Msg
).Style
1404 Warnings_Detected
:= Warnings_Detected
+ 1;
1406 elsif Errors
.Table
(Cur_Msg
).Check
then
1407 Check_Messages
:= Check_Messages
+ 1;
1410 Total_Errors_Detected
:= Total_Errors_Detected
+ 1;
1412 if Errors
.Table
(Cur_Msg
).Serious
then
1413 Serious_Errors_Detected
:= Serious_Errors_Detected
+ 1;
1414 Handle_Serious_Error
;
1416 -- If not serious error, set Fatal_Error to indicate ignored error
1420 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Sptr
);
1422 if Fatal_Error
(U
) = None
then
1423 Set_Fatal_Error
(U
, Error_Ignored
);
1429 -- Record warning message issued
1431 if Errors
.Table
(Cur_Msg
).Warn
1432 and then not Errors
.Table
(Cur_Msg
).Msg_Cont
1434 Warning_Msg
:= Cur_Msg
;
1437 -- If too many warnings turn off warnings
1439 if Maximum_Messages
/= 0 then
1440 if Warnings_Detected
= Maximum_Messages
then
1441 Warning_Mode
:= Suppress
;
1444 -- If too many errors abandon compilation
1446 if Total_Errors_Detected
= Maximum_Messages
then
1447 raise Unrecoverable_Error
;
1451 if Has_Error_Code
then
1453 Msg
: constant String :=
1454 "\launch ""gnatprove --explain=[]"" for more information";
1456 Has_Double_Exclam
:= False;
1457 Has_Error_Code
:= False;
1458 Has_Insertion_Line
:= False;
1468 end Error_Msg_Internal
;
1474 procedure Error_Msg_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
1477 First_And_Last_Nodes
(N
, Fst
, Lst
);
1478 Error_Msg_NEL
(Msg
, N
, N
,
1479 To_Span
(Ptr
=> Sloc
(N
),
1480 First
=> First_Sloc
(Fst
),
1481 Last
=> Last_Sloc
(Lst
)));
1488 procedure Error_Msg_NE
1490 N
: Node_Or_Entity_Id
;
1491 E
: Node_Or_Entity_Id
)
1495 First_And_Last_Nodes
(N
, Fst
, Lst
);
1496 Error_Msg_NEL
(Msg
, N
, E
,
1497 To_Span
(Ptr
=> Sloc
(N
),
1498 First
=> First_Sloc
(Fst
),
1499 Last
=> Last_Sloc
(Lst
)));
1506 procedure Error_Msg_NEL
1508 N
: Node_Or_Entity_Id
;
1509 E
: Node_Or_Entity_Id
;
1510 Flag_Location
: Source_Ptr
)
1514 First_And_Last_Nodes
(N
, Fst
, Lst
);
1517 To_Span
(Ptr
=> Flag_Location
,
1518 First
=> Source_Ptr
'Min (Flag_Location
, First_Sloc
(Fst
)),
1519 Last
=> Source_Ptr
'Max (Flag_Location
, Last_Sloc
(Lst
))));
1522 procedure Error_Msg_NEL
1524 N
: Node_Or_Entity_Id
;
1525 E
: Node_Or_Entity_Id
;
1526 Flag_Span
: Source_Span
)
1529 if Special_Msg_Delete
(Msg
, N
, E
) then
1533 Prescan_Message
(Msg
);
1535 -- Special handling for warning messages
1537 if Is_Warning_Msg
then
1539 -- Suppress if no warnings set for either entity or node
1541 if No_Warnings
(N
) or else No_Warnings
(E
) then
1543 -- Disable any continuation messages as well
1545 Last_Killed
:= True;
1550 -- Test for message to be output
1553 or else Is_Unconditional_Msg
1554 or else Is_Warning_Msg
1556 or else (Msg
(Msg
'First) = '\' and then not Last_Killed
)
1559 Error_Msg_Node_1
:= E
;
1560 Error_Msg
(Msg
, Flag_Span
, N
);
1563 Last_Killed
:= True;
1566 if not Get_Ignore_Errors
then
1575 procedure Error_Msg_NW
1578 N
: Node_Or_Entity_Id
)
1583 and then In_Extended_Main_Source_Unit
(N
)
1584 and then Comes_From_Source
(N
)
1586 First_And_Last_Nodes
(N
, Fst
, Lst
);
1587 Error_Msg_NEL
(Msg
, N
, N
,
1588 To_Span
(Ptr
=> Sloc
(N
),
1589 First
=> First_Sloc
(Fst
),
1590 Last
=> Last_Sloc
(Lst
)));
1598 procedure Error_Msg_S
(Msg
: String) is
1600 Error_Msg
(Msg
, Scan_Ptr
);
1607 procedure Error_Msg_SC
(Msg
: String) is
1609 -- If we are at end of file, post the flag after the previous token
1611 if Token
= Tok_EOF
then
1614 -- For all other cases the message is posted at the current token
1618 Error_Msg
(Msg
, Token_Ptr
);
1626 procedure Error_Msg_SP
(Msg
: String) is
1628 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1629 -- is set to Source_First, which is a reasonable position for the
1630 -- error flag in this situation
1632 Error_Msg
(Msg
, Prev_Token_Ptr
);
1639 procedure Finalize
(Last_Call
: Boolean) is
1644 procedure Delete_Warning
(E
: Error_Msg_Id
);
1645 -- Delete a warning msg if not already deleted and adjust warning count
1647 --------------------
1648 -- Delete_Warning --
1649 --------------------
1651 procedure Delete_Warning
(E
: Error_Msg_Id
) is
1653 if not Errors
.Table
(E
).Deleted
then
1654 Errors
.Table
(E
).Deleted
:= True;
1655 Warnings_Detected
:= Warnings_Detected
- 1;
1657 if Errors
.Table
(E
).Info
then
1658 Warning_Info_Messages
:= Warning_Info_Messages
- 1;
1663 -- Start of processing for Finalize
1666 -- Set Prev pointers
1668 Cur
:= First_Error_Msg
;
1669 while Cur
/= No_Error_Msg
loop
1670 Nxt
:= Errors
.Table
(Cur
).Next
;
1671 exit when Nxt
= No_Error_Msg
;
1672 Errors
.Table
(Nxt
).Prev
:= Cur
;
1676 -- Eliminate any duplicated error messages from the list. This is
1677 -- done after the fact to avoid problems with Change_Error_Text.
1679 Cur
:= First_Error_Msg
;
1680 while Cur
/= No_Error_Msg
loop
1681 Nxt
:= Errors
.Table
(Cur
).Next
;
1684 while F
/= No_Error_Msg
1685 and then Errors
.Table
(F
).Sptr
.Ptr
= Errors
.Table
(Cur
).Sptr
.Ptr
1687 Check_Duplicate_Message
(Cur
, F
);
1688 F
:= Errors
.Table
(F
).Next
;
1694 -- Mark any messages suppressed by specific warnings as Deleted
1696 Cur
:= First_Error_Msg
;
1697 while Cur
/= No_Error_Msg
loop
1699 CE
: Error_Msg_Object
renames Errors
.Table
(Cur
);
1700 Tag
: constant String := Get_Warning_Tag
(Cur
);
1703 if (CE
.Warn
and not CE
.Deleted
)
1705 (Warning_Specifically_Suppressed
(CE
.Sptr
.Ptr
, CE
.Text
, Tag
)
1708 Warning_Specifically_Suppressed
(CE
.Optr
.Ptr
, CE
.Text
, Tag
)
1711 Delete_Warning
(Cur
);
1713 -- If this is a continuation, delete previous parts of message
1716 while Errors
.Table
(F
).Msg_Cont
loop
1717 F
:= Errors
.Table
(F
).Prev
;
1718 exit when F
= No_Error_Msg
;
1722 -- Delete any following continuations
1726 F
:= Errors
.Table
(F
).Next
;
1727 exit when F
= No_Error_Msg
;
1728 exit when not Errors
.Table
(F
).Msg_Cont
;
1734 Cur
:= Errors
.Table
(Cur
).Next
;
1737 Finalize_Called
:= True;
1739 -- Check consistency of specific warnings (may add warnings). We only
1740 -- do this on the last call, after all possible warnings are posted.
1743 Validate_Specific_Warnings
(Error_Msg
'Access);
1751 function First_Node
(C
: Node_Id
) return Node_Id
is
1754 First_And_Last_Nodes
(C
, Fst
, Lst
);
1758 --------------------------
1759 -- First_And_Last_Nodes --
1760 --------------------------
1762 procedure First_And_Last_Nodes
1764 First_Node
, Last_Node
: out Node_Id
)
1766 Orig
: constant Node_Id
:= Original_Node
(C
);
1767 Loc
: constant Source_Ptr
:= Sloc
(Orig
);
1768 Sfile
: constant Source_File_Index
:= Get_Source_File_Index
(Loc
);
1774 function Test_First_And_Last
(N
: Node_Id
) return Traverse_Result
;
1775 -- Function applied to every node in the construct
1777 procedure Search_Tree_First_And_Last
is new
1778 Traverse_Proc
(Test_First_And_Last
);
1779 -- Create traversal procedure
1781 -------------------------
1782 -- Test_First_And_Last --
1783 -------------------------
1785 function Test_First_And_Last
(N
: Node_Id
) return Traverse_Result
is
1786 Norig
: constant Node_Id
:= Original_Node
(N
);
1787 Loc
: constant Source_Ptr
:= Sloc
(Norig
);
1790 -- ??? For assignments that require accessiblity checks, e.g.:
1794 -- the function call gets an extra actual parameter association with
1795 -- Sloc of the assigned name "Y":
1797 -- Y := Func (123, A8b => 2);
1799 -- We can simply ignore those extra actual parameters when
1800 -- determining the Sloc range of the "Func (123)" expression.
1802 if Nkind
(N
) = N_Parameter_Association
1803 and then Is_Accessibility_Actual
(N
)
1808 -- Check for earlier
1812 -- Ignore nodes with no useful location information
1814 and then Loc
/= Standard_Location
1815 and then Loc
/= No_Location
1817 -- Ignore nodes from a different file. This ensures against cases
1818 -- of strange foreign code somehow being present. We don't want
1819 -- wild placement of messages if that happens.
1821 and then Get_Source_File_Index
(Loc
) = Sfile
1831 -- Ignore nodes with no useful location information
1833 and then Loc
/= Standard_Location
1834 and then Loc
/= No_Location
1836 -- Ignore nodes from a different file. This ensures against cases
1837 -- of strange foreign code somehow being present. We don't want
1838 -- wild placement of messages if that happens.
1840 and then Get_Source_File_Index
(Loc
) = Sfile
1847 end Test_First_And_Last
;
1849 -- Start of processing for First_And_Last_Nodes
1852 if Nkind
(Orig
) in N_Subexpr
1854 | N_Access_To_Subprogram_Definition
1855 | N_Generic_Instantiation
1857 | N_Use_Package_Clause
1858 | N_Array_Type_Definition
1859 | N_Renaming_Declaration
1860 | N_Generic_Renaming_Declaration
1861 | N_Assignment_Statement
1863 | N_Simple_Return_Statement
1868 | N_Attribute_Definition_Clause
1869 | N_Subtype_Indication
1875 Search_Tree_First_And_Last
(Orig
);
1876 First_Node
:= Earliest
;
1877 Last_Node
:= Latest
;
1883 end First_And_Last_Nodes
;
1889 function First_Sloc
(N
: Node_Id
) return Source_Ptr
is
1890 SI
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
1891 SF
: constant Source_Ptr
:= Source_First
(SI
);
1892 SL
: constant Source_Ptr
:= Source_Last
(SI
);
1893 Src
: constant Source_Buffer_Ptr
:= Source_Text
(SI
);
1898 F
:= First_Node
(N
);
1901 if S
not in SF
.. SL
then
1905 -- The following circuit is a bit subtle. When we have parenthesized
1906 -- expressions, then the Sloc will not record the location of the paren,
1907 -- but we would like to post the flag on the paren. So what we do is to
1908 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1909 -- any parentheses we know are present. Yes, we know this circuit is not
1910 -- 100% reliable (e.g. because we don't record all possible paren level
1911 -- values), but this is only for an error message so it is good enough.
1914 -- Include parentheses around the top node, except when they are
1915 -- required by the syntax of the parent node.
1917 exit Node_Loop
when F
= N
1918 and then Paren_Required
(N
);
1920 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
1922 -- We don't look more than 12 characters behind the current
1923 -- location, and in any case not past the front of the source.
1925 Search_Loop
: for K
in 1 .. 12 loop
1926 exit Search_Loop
when S
= SF
;
1928 if Src
(S
- 1) = '(' then
1932 elsif Src
(S
- 1) <= ' ' then
1938 end loop Search_Loop
;
1939 end loop Paren_Loop
;
1941 exit Node_Loop
when F
= N
;
1943 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
1949 -----------------------
1950 -- Get_Ignore_Errors --
1951 -----------------------
1953 function Get_Ignore_Errors
return Boolean is
1955 return Errors_Must_Be_Ignored
;
1956 end Get_Ignore_Errors
;
1962 procedure Initialize
is
1965 First_Error_Msg
:= No_Error_Msg
;
1966 Last_Error_Msg
:= No_Error_Msg
;
1967 Serious_Errors_Detected
:= 0;
1968 Total_Errors_Detected
:= 0;
1969 Cur_Msg
:= No_Error_Msg
;
1972 -- Reset counts for warnings
1974 Warnings_Treated_As_Errors
:= 0;
1975 Warnings_Detected
:= 0;
1976 Warning_Info_Messages
:= 0;
1977 Warnings_As_Errors_Count
:= 0;
1979 -- Initialize warnings tables
1982 Specific_Warnings
.Init
;
1985 -------------------------------
1986 -- Is_Size_Too_Small_Message --
1987 -------------------------------
1989 function Is_Size_Too_Small_Message
(S
: String) return Boolean is
1990 Size_For
: constant String := "size for";
1991 pragma Assert
(Size_Too_Small_Message
(1 .. Size_For
'Last) = Size_For
);
1992 -- Assert that Size_Too_Small_Message starts with Size_For
1994 return S
'Length >= Size_For
'Length
1995 and then S
(S
'First .. S
'First + Size_For
'Length - 1) = Size_For
;
1996 -- True if S starts with Size_For
1997 end Is_Size_Too_Small_Message
;
2003 function Last_Node
(C
: Node_Id
) return Node_Id
is
2006 First_And_Last_Nodes
(C
, Fst
, Lst
);
2014 function Last_Sloc
(N
: Node_Id
) return Source_Ptr
is
2015 procedure Skip_Char
(S
: in out Source_Ptr
);
2016 -- Skip one character of the source buffer at location S
2022 procedure Skip_Char
(S
: in out Source_Ptr
) is
2029 SI
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
2030 SF
: constant Source_Ptr
:= Source_First
(SI
);
2031 SL
: constant Source_Ptr
:= Source_Last
(SI
);
2032 Src
: constant Source_Buffer_Ptr
:= Source_Text
(SI
);
2036 -- Start of processing for Last_Sloc
2042 if S
not in SF
.. SL
then
2046 -- For string and character literals simply forward the sloc by their
2047 -- length including the closing quotes. Perhaps we should do something
2048 -- special for multibyte characters, but this code is only used to emit
2049 -- error messages, so it is not worth the effort.
2052 when N_String_Literal
=>
2053 return S
+ Source_Ptr
(String_Length
(Strval
(F
))) + 1;
2055 when N_Character_Literal
=>
2058 -- Skip past integer literals, both decimal and based, integer and
2059 -- real. We can't greedily accept all allowed character, because
2060 -- we would consme too many of them in expressions like "123+ABC"
2061 -- or "123..456", so we follow quite precisely the Ada grammar and
2062 -- consume different characters depending on the context.
2064 when N_Integer_Literal
=>
2066 -- Skip past the initial numeral, which either leads the decimal
2067 -- literal or is the base of a based literal.
2070 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2075 -- Skip past #based_numeral#, if present
2078 and then Src
(S
+ 1) = '#'
2084 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2090 and then Src
(S
+ 1) = '#'
2096 -- Skip past exponent, if present
2099 and then Src
(S
+ 1) in 'e' |
'E'
2103 -- For positive exponents the plus sign is optional, but we
2104 -- can simply skip past both plus and minus.
2107 and then Src
(S
+ 1) in '+' |
'-'
2112 -- Skip past the numeral part
2115 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2121 when N_Real_Literal
=>
2122 -- Skip past the initial numeral, which either leads the decimal
2123 -- literal or is the base of a based literal.
2126 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2133 -- Skip the dot and continue with a decimal literal
2135 if Src
(S
+ 1) = '.' then
2139 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2144 -- Skip the hash and continue with a based literal
2146 elsif Src
(S
+ 1) = '#' then
2151 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2157 and then Src
(S
+ 1) = '.'
2164 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2170 and then Src
(S
+ 1) = '#'
2177 -- Skip past exponent, if present
2180 and then Src
(S
+ 1) in 'e' |
'E'
2183 -- For positive exponents the plus sign is optional, but we
2184 -- can simply skip past both plus and minus.
2186 if Src
(S
+ 1) in '+' |
'-' then
2190 -- Skip past the numeral part
2193 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2199 -- For other nodes simply skip past a keyword/identifier
2202 while S
in SF
.. SL
- 1
2203 and then Src
(S
+ 1)
2205 '0' .. '9' |
'a' .. 'z' |
'A' .. 'Z' |
'_'
2211 -- The following circuit attempts at crawling up the tree from the
2212 -- Last_Node, adjusting the Sloc value for any parentheses we know
2213 -- are present, similarly to what is done in First_Sloc.
2216 -- Include parentheses around the top node, except when they are
2217 -- required by the syntax of the parent node.
2219 exit Node_Loop
when F
= N
2220 and then Paren_Required
(N
);
2222 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
2224 -- We don't look more than 12 characters after the current
2227 Search_Loop
: for K
in 1 .. 12 loop
2228 exit Node_Loop
when S
= SL
;
2230 if Src
(S
+ 1) = ')' then
2234 elsif Src
(S
+ 1) <= ' ' then
2240 end loop Search_Loop
;
2241 end loop Paren_Loop
;
2243 exit Node_Loop
when F
= N
;
2245 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
2248 -- Remove any trailing space
2250 while S
in SF
+ 1 .. SL
2251 and then Src
(S
) = ' '
2263 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean is
2265 if Error_Posted
(N
) then
2268 elsif Nkind
(N
) in N_Entity
and then Has_Warnings_Off
(N
) then
2271 elsif Is_Entity_Name
(N
)
2272 and then Present
(Entity
(N
))
2273 and then Has_Warnings_Off
(Entity
(N
))
2286 function OK_Node
(N
: Node_Id
) return Boolean is
2287 K
: constant Node_Kind
:= Nkind
(N
);
2290 if Error_Posted
(N
) then
2293 elsif K
in N_Has_Etype
2294 and then Present
(Etype
(N
))
2295 and then Error_Posted
(Etype
(N
))
2300 or else K
= N_Attribute_Reference
2301 or else K
= N_Character_Literal
2302 or else K
= N_Expanded_Name
2303 or else K
= N_Identifier
2304 or else K
= N_Operator_Symbol
)
2305 and then Present
(Entity
(N
))
2306 and then Error_Posted
(Entity
(N
))
2314 -------------------------
2315 -- Output_JSON_Message --
2316 -------------------------
2318 procedure Output_JSON_Message
(Error_Id
: Error_Msg_Id
) is
2320 function Is_Continuation
(E
: Error_Msg_Id
) return Boolean;
2321 -- Return True if E is a continuation message.
2323 procedure Write_JSON_Escaped_String
(Str
: String_Ptr
);
2324 procedure Write_JSON_Escaped_String
(Str
: String);
2325 -- Write each character of Str, taking care of preceding each quote and
2326 -- backslash with a backslash. Note that this escaping differs from what
2329 -- Indeed, the JSON specification mandates encoding wide characters
2330 -- either as their direct UTF-8 representation or as their escaped
2331 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2332 -- we choose to use the UTF-8 representation instead.
2334 procedure Write_JSON_Location
(Sptr
: Source_Ptr
);
2335 -- Write Sptr as a JSON location, an object containing a file attribute,
2336 -- a line number and a column number.
2338 procedure Write_JSON_Span
(Error
: Error_Msg_Object
);
2339 -- Write Error as a JSON span, an object containing a "caret" attribute
2340 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2341 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2342 -- locations under the names "start" and "finish".
2343 -- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional,
2344 -- non-standard, attribute named "subprogram" will be added, allowing
2345 -- precisely identifying the subprogram surrounding the span.
2347 -----------------------
2348 -- Is_Continuation --
2349 -----------------------
2351 function Is_Continuation
(E
: Error_Msg_Id
) return Boolean is
2353 return E
<= Last_Error_Msg
and then Errors
.Table
(E
).Msg_Cont
;
2354 end Is_Continuation
;
2356 -------------------------------
2357 -- Write_JSON_Escaped_String --
2358 -------------------------------
2360 procedure Write_JSON_Escaped_String
(Str
: String) is
2363 if C
= '"' or else C
= '\' then
2369 end Write_JSON_Escaped_String
;
2371 -------------------------------
2372 -- Write_JSON_Escaped_String --
2373 -------------------------------
2375 procedure Write_JSON_Escaped_String
(Str
: String_Ptr
) is
2377 Write_JSON_Escaped_String
(Str
.all);
2378 end Write_JSON_Escaped_String
;
2380 -------------------------
2381 -- Write_JSON_Location --
2382 -------------------------
2384 procedure Write_JSON_Location
(Sptr
: Source_Ptr
) is
2385 Name
: constant File_Name_Type
:=
2386 Full_Ref_Name
(Get_Source_File_Index
(Sptr
));
2388 Write_Str
("{""file"":""");
2389 if Full_Path_Name_For_Brief_Errors
then
2390 Write_JSON_Escaped_String
2391 (System
.OS_Lib
.Normalize_Pathname
(Get_Name_String
(Name
)));
2395 Write_Str
(""",""line"":");
2396 Write_Int
(Pos
(Get_Physical_Line_Number
(Sptr
)));
2397 Write_Str
(", ""column"":");
2398 Write_Int
(Nat
(Get_Column_Number
(Sptr
)));
2400 end Write_JSON_Location
;
2402 ---------------------
2403 -- Write_JSON_Span --
2404 ---------------------
2406 procedure Write_JSON_Span
(Error
: Error_Msg_Object
) is
2407 Span
: constant Source_Span
:= Error
.Sptr
;
2409 Write_Str
("{""caret"":");
2410 Write_JSON_Location
(Span
.Ptr
);
2412 if Span
.Ptr
/= Span
.First
then
2413 Write_Str
(",""start"":");
2414 Write_JSON_Location
(Span
.First
);
2417 if Span
.Ptr
/= Span
.Last
then
2418 Write_Str
(",""finish"":");
2419 Write_JSON_Location
(Span
.Last
);
2422 if Include_Subprogram_In_Messages
then
2423 Write_Str
(",""subprogram"":""");
2424 Write_JSON_Escaped_String
(Subprogram_Name_Ptr
(Error
.Node
));
2429 end Write_JSON_Span
;
2433 E
: Error_Msg_Id
:= Error_Id
;
2435 Print_Continuations
: constant Boolean := not Is_Continuation
(E
);
2436 -- Do not print continuations messages as children of the current
2437 -- message if the current message is a continuation message.
2439 Option
: constant String := Get_Warning_Option
(E
);
2440 -- The option that triggered this message.
2442 -- Start of processing for Output_JSON_Message
2446 -- Print message kind
2448 Write_Str
("{""kind"":");
2450 if Errors
.Table
(E
).Warn
and then not Errors
.Table
(E
).Warn_Err
then
2451 Write_Str
("""warning""");
2452 elsif Errors
.Table
(E
).Info
or else Errors
.Table
(E
).Check
then
2453 Write_Str
("""note""");
2455 Write_Str
("""error""");
2458 -- Print message location
2460 Write_Str
(",""locations"":[");
2461 Write_JSON_Span
(Errors
.Table
(E
));
2463 if Errors
.Table
(E
).Optr
.Ptr
/= Errors
.Table
(E
).Sptr
.Ptr
then
2464 Write_Str
(",{""caret"":");
2465 Write_JSON_Location
(Errors
.Table
(E
).Optr
.Ptr
);
2471 -- Print message option, if there is one
2472 if Option
/= "" then
2473 Write_Str
(",""option"":""" & Option
& """");
2476 -- Print message content
2478 Write_Str
(",""message"":""");
2479 Write_JSON_Escaped_String
(Errors
.Table
(E
).Text
);
2484 if Print_Continuations
and then Is_Continuation
(E
) then
2486 Write_Str
(",""children"": [");
2487 Output_JSON_Message
(E
);
2490 while Is_Continuation
(E
) loop
2492 Output_JSON_Message
(E
);
2501 end Output_JSON_Message
;
2503 ---------------------
2504 -- Output_Messages --
2505 ---------------------
2507 procedure Output_Messages
is
2509 -- Local subprograms
2511 procedure Write_Error_Summary
;
2512 -- Write error summary
2514 procedure Write_Header
(Sfile
: Source_File_Index
);
2515 -- Write header line (compiling or checking given file)
2517 procedure Write_Max_Errors
;
2518 -- Write message if max errors reached
2520 procedure Write_Source_Code_Lines
2521 (Span
: Source_Span
;
2523 -- Write the source code line corresponding to Span, as follows when
2524 -- Span in on one line:
2526 -- line | actual code line here with Span somewhere
2529 -- where the caret on the line points to location Span.Ptr, and the
2530 -- range Span.First..Span.Last is underlined.
2532 -- or when the span is over multiple lines:
2534 -- line | beginning of the Span on this line
2536 -- line>| actual code line here with Span.Ptr somewhere
2538 -- line | end of the Span on this line
2540 -- or when the span is a simple location, as follows:
2542 -- line | actual code line here with Span somewhere
2545 -- where the caret on the line points to location Span.Ptr
2547 -- SGR_Span is the SGR string to start the section of code in the span,
2548 -- that should be closed with SGR_Reset.
2550 -------------------------
2551 -- Write_Error_Summary --
2552 -------------------------
2554 procedure Write_Error_Summary
is
2556 -- Extra blank line if error messages or source listing were output
2558 if Total_Errors_Detected
+ Warnings_Detected
> 0 or else Full_List
2563 -- Message giving number of lines read and number of errors detected.
2564 -- This normally goes to Standard_Output. The exception is when brief
2565 -- mode is not set, verbose mode (or full list mode) is set, and
2566 -- there are errors. In this case we send the message to standard
2567 -- error to make sure that *something* appears on standard error
2568 -- in an error situation.
2570 if Total_Errors_Detected
+ Warnings_Detected
/= 0
2571 and then not Brief_Output
2572 and then (Verbose_Mode
or Full_List
)
2577 -- Message giving total number of lines. Don't give this message if
2578 -- the Main_Source line is unknown (this happens in error situations,
2579 -- e.g. when integrated preprocessing fails).
2581 if Main_Source_File
> No_Source_File
then
2583 Write_Int
(Num_Source_Lines
(Main_Source_File
));
2585 if Num_Source_Lines
(Main_Source_File
) = 1 then
2586 Write_Str
(" line: ");
2588 Write_Str
(" lines: ");
2592 if Total_Errors_Detected
= 0 then
2593 Write_Str
("No errors");
2595 elsif Total_Errors_Detected
= 1 then
2596 Write_Str
("1 error");
2599 Write_Int
(Total_Errors_Detected
);
2600 Write_Str
(" errors");
2603 -- We now need to output warnings. When using -gnatwe, all warnings
2604 -- should be treated as errors, except for warnings originating from
2605 -- the use of the Compile_Time_Warning pragma. Another situation
2606 -- where a warning might be treated as an error is when the source
2607 -- code contains a Warning_As_Error pragma.
2608 -- When warnings are treated as errors, we still log them as
2609 -- warnings, but we add a message denoting how many of these warnings
2613 Warnings_Count
: constant Int
:=
2614 Warnings_Detected
- Warning_Info_Messages
;
2616 Compile_Time_Warnings
: Int
;
2617 -- Number of warnings that come from a Compile_Time_Warning
2620 Non_Compile_Time_Warnings
: Int
;
2621 -- Number of warnings that do not come from a Compile_Time_Warning
2625 if Warnings_Count
> 0 then
2627 Write_Int
(Warnings_Count
);
2628 Write_Str
(" warning");
2630 if Warnings_Count
> 1 then
2634 Compile_Time_Warnings
:= Count_Compile_Time_Pragma_Warnings
;
2635 Non_Compile_Time_Warnings
:=
2636 Warnings_Count
- Compile_Time_Warnings
;
2638 if Warning_Mode
= Treat_As_Error
2639 and then Non_Compile_Time_Warnings
> 0
2643 if Compile_Time_Warnings
> 0 then
2644 Write_Int
(Non_Compile_Time_Warnings
);
2648 Write_Str
("treated as error");
2650 if Non_Compile_Time_Warnings
> 1 then
2656 elsif Warnings_Treated_As_Errors
> 0 then
2659 if Warnings_Treated_As_Errors
/= Warnings_Count
then
2660 Write_Int
(Warnings_Treated_As_Errors
);
2664 Write_Str
("treated as error");
2666 if Warnings_Treated_As_Errors
> 1 then
2675 if Warning_Info_Messages
+ Report_Info_Messages
/= 0 then
2677 Write_Int
(Warning_Info_Messages
+ Report_Info_Messages
);
2678 Write_Str
(" info message");
2680 if Warning_Info_Messages
+ Report_Info_Messages
> 1 then
2686 Set_Standard_Output
;
2687 end Write_Error_Summary
;
2693 procedure Write_Header
(Sfile
: Source_File_Index
) is
2695 if Verbose_Mode
or Full_List
then
2696 if Original_Operating_Mode
= Generate_Code
then
2697 Write_Str
("Compiling: ");
2699 Write_Str
("Checking: ");
2702 Write_Name
(Full_File_Name
(Sfile
));
2704 if not Debug_Flag_7
then
2706 Write_Str
("Source file time stamp: ");
2707 Write_Time_Stamp
(Sfile
);
2709 Write_Str
("Compiled at: " & Compilation_Time
);
2716 ----------------------
2717 -- Write_Max_Errors --
2718 ----------------------
2720 procedure Write_Max_Errors
is
2722 if Maximum_Messages
/= 0 then
2723 if Warnings_Detected
>= Maximum_Messages
then
2725 Write_Line
("maximum number of warnings output");
2726 Write_Line
("any further warnings suppressed");
2727 Set_Standard_Output
;
2730 -- If too many errors print message
2732 if Total_Errors_Detected
>= Maximum_Messages
then
2734 Write_Line
("fatal error: maximum number of errors detected");
2735 Set_Standard_Output
;
2738 end Write_Max_Errors
;
2740 -----------------------------
2741 -- Write_Source_Code_Lines --
2742 -----------------------------
2744 procedure Write_Source_Code_Lines
2745 (Span
: Source_Span
;
2748 function Get_Line_End
2749 (Buf
: Source_Buffer_Ptr
;
2750 Loc
: Source_Ptr
) return Source_Ptr
;
2751 -- Get the source location for the end of the line in Buf for Loc. If
2752 -- Loc is past the end of Buf already, return Buf'Last.
2754 function Get_Line_Start
2755 (Buf
: Source_Buffer_Ptr
;
2756 Loc
: Source_Ptr
) return Source_Ptr
;
2757 -- Get the source location for the start of the line in Buf for Loc
2759 function Image
(X
: Positive; Width
: Positive) return String;
2760 -- Output number X over Width characters, with whitespace padding.
2761 -- Only output the low-order Width digits of X, if X is larger than
2764 procedure Write_Buffer
2765 (Buf
: Source_Buffer_Ptr
;
2768 -- Output the characters from First to Last position in Buf, using
2769 -- Write_Buffer_Char.
2771 procedure Write_Buffer_Char
2772 (Buf
: Source_Buffer_Ptr
;
2774 -- Output the characters at position Loc in Buf, translating ASCII.HT
2775 -- in a suitable number of spaces so that the output is not modified
2776 -- by starting in a different column that 1.
2778 procedure Write_Line_Marker
2782 -- Output the line number Num over Width characters, with possibly
2783 -- a Mark to denote the line with the main location when reporting
2784 -- a span over multiple lines.
2790 function Get_Line_End
2791 (Buf
: Source_Buffer_Ptr
;
2792 Loc
: Source_Ptr
) return Source_Ptr
2794 Cur_Loc
: Source_Ptr
:= Source_Ptr
'Min (Loc
, Buf
'Last);
2796 while Cur_Loc
< Buf
'Last
2797 and then Buf
(Cur_Loc
) /= ASCII
.LF
2799 Cur_Loc
:= Cur_Loc
+ 1;
2805 --------------------
2806 -- Get_Line_Start --
2807 --------------------
2809 function Get_Line_Start
2810 (Buf
: Source_Buffer_Ptr
;
2811 Loc
: Source_Ptr
) return Source_Ptr
2813 Cur_Loc
: Source_Ptr
:= Loc
;
2815 while Cur_Loc
> Buf
'First
2816 and then Buf
(Cur_Loc
- 1) /= ASCII
.LF
2818 Cur_Loc
:= Cur_Loc
- 1;
2828 function Image
(X
: Positive; Width
: Positive) return String is
2829 Str
: String (1 .. Width
);
2830 Curr
: Natural := X
;
2832 for J
in reverse 1 .. Width
loop
2834 Str
(J
) := Character'Val (Character'Pos ('0') + Curr
mod 10);
2848 procedure Write_Buffer
2849 (Buf
: Source_Buffer_Ptr
;
2854 for Loc
in First
.. Last
loop
2855 Write_Buffer_Char
(Buf
, Loc
);
2859 -----------------------
2860 -- Write_Buffer_Char --
2861 -----------------------
2863 procedure Write_Buffer_Char
2864 (Buf
: Source_Buffer_Ptr
;
2868 -- If the character ASCII.HT is not the last one in the file,
2869 -- output as many spaces as the character represents in the
2870 -- original source file.
2872 if Buf
(Loc
) = ASCII
.HT
2873 and then Loc
< Buf
'Last
2875 for X
in Get_Column_Number
(Loc
) ..
2876 Get_Column_Number
(Loc
+ 1) - 1
2881 -- Otherwise output the character itself
2884 Write_Char
(Buf
(Loc
));
2886 end Write_Buffer_Char
;
2888 -----------------------
2889 -- Write_Line_Marker --
2890 -----------------------
2892 procedure Write_Line_Marker
2898 Write_Str
(Image
(Positive (Num
), Width
=> Width
));
2899 Write_Str
((if Mark
then ">" else " ") & "|");
2900 end Write_Line_Marker
;
2904 Loc
: constant Source_Ptr
:= Span
.Ptr
;
2905 Line
: constant Pos
:= Pos
(Get_Physical_Line_Number
(Loc
));
2907 Col
: constant Natural := Natural (Get_Column_Number
(Loc
));
2909 Fst
: constant Source_Ptr
:= Span
.First
;
2910 Line_Fst
: constant Pos
:=
2911 Pos
(Get_Physical_Line_Number
(Fst
));
2912 Col_Fst
: constant Natural :=
2913 Natural (Get_Column_Number
(Fst
));
2914 Lst
: constant Source_Ptr
:= Span
.Last
;
2915 Line_Lst
: constant Pos
:=
2916 Pos
(Get_Physical_Line_Number
(Lst
));
2917 Col_Lst
: constant Natural :=
2918 Natural (Get_Column_Number
(Lst
));
2920 Width
: constant := 5;
2921 Buf
: Source_Buffer_Ptr
;
2922 Cur_Loc
: Source_Ptr
:= Fst
;
2923 Cur_Line
: Pos
:= Line_Fst
;
2925 -- Start of processing for Write_Source_Code_Lines
2928 if Loc
>= First_Source_Ptr
then
2929 Buf
:= Source_Text
(Get_Source_File_Index
(Loc
));
2931 -- First line of the span with actual source code. We retrieve
2932 -- the beginning of the line instead of relying on Col_Fst, as
2933 -- ASCII.HT characters change column numbers by possibly more
2938 Line_Fst
/= Line_Lst
and then Cur_Line
= Line
,
2940 Write_Buffer
(Buf
, Get_Line_Start
(Buf
, Cur_Loc
), Cur_Loc
- 1);
2942 -- Output the first/caret/last lines of the span, as well as
2943 -- lines that are directly above/below the caret if they complete
2944 -- the gap with first/last lines, otherwise use ... to denote
2945 -- intermediate lines.
2947 -- If the span is on one line and not a simple source location,
2948 -- color it appropriately.
2950 if Line_Fst
= Line_Lst
2951 and then Col_Fst
/= Col_Lst
2953 Write_Str
(SGR_Span
);
2957 function Do_Write_Line
(Cur_Line
: Pos
) return Boolean is
2958 (Cur_Line
in Line_Fst | Line | Line_Lst
2960 (Cur_Line
= Line_Fst
+ 1 and then Cur_Line
= Line
- 1)
2962 (Cur_Line
= Line
+ 1 and then Cur_Line
= Line_Lst
- 1));
2964 while Cur_Loc
<= Buf
'Last
2965 and then Cur_Loc
<= Lst
2967 if Do_Write_Line
(Cur_Line
) then
2968 Write_Buffer_Char
(Buf
, Cur_Loc
);
2971 if Buf
(Cur_Loc
) = ASCII
.LF
then
2972 Cur_Line
:= Cur_Line
+ 1;
2974 -- Output ... for skipped lines
2977 and then not Do_Write_Line
(Cur_Line
- 1))
2979 (Cur_Line
= Line
+ 1
2980 and then not Do_Write_Line
(Cur_Line
))
2982 Write_Str
((1 .. Width
- 3 => ' ') & "... | ...");
2986 -- Display the line marker if the line should be
2989 if Do_Write_Line
(Cur_Line
) then
2992 Line_Fst
/= Line_Lst
and then Cur_Line
= Line
,
2997 Cur_Loc
:= Cur_Loc
+ 1;
3001 if Line_Fst
= Line_Lst
3002 and then Col_Fst
/= Col_Lst
3004 Write_Str
(SGR_Reset
);
3007 -- Output the rest of the last line of the span
3009 Write_Buffer
(Buf
, Cur_Loc
, Get_Line_End
(Buf
, Cur_Loc
));
3011 -- If the span is on one line, output a second line with caret
3012 -- sign pointing to location Loc
3014 if Line_Fst
= Line_Lst
then
3015 Write_Str
(String'(1 .. Width => ' '));
3017 Write_Str (String'(1 .. Col_Fst
- 1 => ' '));
3019 Write_Str
(SGR_Span
);
3021 Write_Str
(String'(Col_Fst .. Col - 1 => '~
'));
3023 Write_Str (String'(Col
+ 1 .. Col_Lst
=> '~'));
3025 -- If the span is really just a location, add the word "here"
3026 -- to clarify this is the location for the message.
3028 if Col_Fst
= Col_Lst
then
3029 Write_Str
(" here");
3032 Write_Str
(SGR_Reset
);
3037 end Write_Source_Code_Lines
;
3043 Use_Prefix
: Boolean;
3045 -- Start of processing for Output_Messages
3048 -- Error if Finalize has not been called
3050 if not Finalize_Called
then
3051 raise Program_Error
;
3054 -- Reset current error source file if the main unit has a pragma
3055 -- Source_Reference. This ensures outputting the proper name of
3056 -- the source file in this situation.
3058 if Main_Source_File
<= No_Source_File
3059 or else Num_SRef_Pragmas
(Main_Source_File
) /= 0
3061 Current_Error_Source_File
:= No_Source_File
;
3064 if Opt
.JSON_Output
then
3067 E
:= First_Error_Msg
;
3069 -- Find first printable message
3071 while E
/= No_Error_Msg
and then Errors
.Table
(E
).Deleted
loop
3072 E
:= Errors
.Table
(E
).Next
;
3077 if E
/= No_Error_Msg
then
3079 Output_JSON_Message
(E
);
3081 E
:= Errors
.Table
(E
).Next
;
3083 while E
/= No_Error_Msg
loop
3085 -- Skip deleted messages.
3086 -- Also skip continuation messages, as they have already been
3087 -- printed along the message they're attached to.
3089 if not Errors
.Table
(E
).Deleted
3090 and then not Errors
.Table
(E
).Msg_Cont
3093 Output_JSON_Message
(E
);
3096 E
:= Errors
.Table
(E
).Next
;
3102 Set_Standard_Output
;
3106 elsif Brief_Output
or (not Full_List
and not Verbose_Mode
) then
3109 E
:= First_Error_Msg
;
3110 while E
/= No_Error_Msg
loop
3112 -- If -gnatdF is used, separate main messages from previous
3113 -- messages with a newline (unless it is an info message) and
3114 -- make continuation messages follow the main message with only
3115 -- an indentation of two space characters, without repeating
3116 -- file:line:col: prefix.
3119 not (Debug_Flag_FF
and then Errors
.Table
(E
).Msg_Cont
);
3121 if not Errors
.Table
(E
).Deleted
and then not Debug_Flag_KK
then
3123 if Debug_Flag_FF
then
3124 if Errors
.Table
(E
).Msg_Cont
then
3126 elsif not Errors
.Table
(E
).Info
then
3132 Write_Str
(SGR_Locus
);
3134 if Full_Path_Name_For_Brief_Errors
then
3135 Write_Name
(Full_Ref_Name
(Errors
.Table
(E
).Sfile
));
3137 Write_Name
(Reference_Name
(Errors
.Table
(E
).Sfile
));
3141 Write_Int
(Int
(Physical_To_Logical
3142 (Errors
.Table
(E
).Line
,
3143 Errors
.Table
(E
).Sfile
)));
3146 if Errors
.Table
(E
).Col
< 10 then
3150 Write_Int
(Int
(Errors
.Table
(E
).Col
));
3153 Write_Str
(SGR_Reset
);
3156 Output_Msg_Text
(E
);
3159 -- If -gnatdF is used, write the source code line corresponding
3160 -- to the location of the main message (unless it is an info
3161 -- message). Also write the source code line corresponding to
3162 -- an insertion location inside continuation messages.
3165 and then not Errors
.Table
(E
).Info
3167 if Errors
.Table
(E
).Msg_Cont
then
3169 Loc
: constant Source_Ptr
:=
3170 Errors
.Table
(E
).Insertion_Sloc
;
3172 if Loc
/= No_Location
then
3173 Write_Source_Code_Lines
3174 (To_Span
(Loc
), SGR_Span
=> SGR_Note
);
3180 SGR_Span
: constant String :=
3181 (if Errors
.Table
(E
).Info
then SGR_Note
3182 elsif Errors
.Table
(E
).Warn
3183 and then not Errors
.Table
(E
).Warn_Err
3187 Write_Source_Code_Lines
3188 (Errors
.Table
(E
).Optr
, SGR_Span
);
3194 E
:= Errors
.Table
(E
).Next
;
3197 Set_Standard_Output
;
3200 -- Full source listing case
3203 List_Pragmas_Index
:= 1;
3204 List_Pragmas_Mode
:= True;
3205 E
:= First_Error_Msg
;
3207 -- Normal case, to stdout (copyright notice already output)
3209 if Full_List_File_Name
= null then
3210 if not Debug_Flag_7
then
3217 Create_List_File_Access
.all (Full_List_File_Name
.all);
3218 Set_Special_Output
(Write_List_Info_Access
.all'Access);
3220 -- Write copyright notice to file
3222 if not Debug_Flag_7
then
3223 Write_Str
("GNAT ");
3224 Write_Str
(Gnat_Version_String
);
3226 Write_Str
("Copyright 1992-" &
3228 ", Free Software Foundation, Inc.");
3233 -- First list extended main source file units with errors
3235 for U
in Main_Unit
.. Last_Unit
loop
3236 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
))
3238 -- If debug flag d.m is set, only the main source is listed
3240 and then (U
= Main_Unit
or else not Debug_Flag_Dot_M
)
3242 -- If the unit of the entity does not come from source, it is
3243 -- an implicit subprogram declaration for a child subprogram.
3244 -- Do not emit errors for it, they are listed with the body.
3247 (No
(Cunit_Entity
(U
))
3248 or else Comes_From_Source
(Cunit_Entity
(U
))
3249 or else not Is_Subprogram
(Cunit_Entity
(U
)))
3251 -- If the compilation unit associated with this unit does not
3252 -- come from source, it means it is an instantiation that should
3253 -- not be included in the source listing.
3255 and then Comes_From_Source
(Cunit
(U
))
3258 Sfile
: constant Source_File_Index
:= Source_Index
(U
);
3263 -- Only write the header if Sfile is known
3265 if Sfile
> No_Source_File
then
3266 Write_Header
(Sfile
);
3270 -- Normally, we don't want an "error messages from file"
3271 -- message when listing the entire file, so we set the
3272 -- current source file as the current error source file.
3273 -- However, the old style of doing things was to list this
3274 -- message if pragma Source_Reference is present, even for
3275 -- the main unit. Since the purpose of the -gnatd.m switch
3276 -- is to duplicate the old behavior, we skip the reset if
3277 -- this debug flag is set.
3279 if not Debug_Flag_Dot_M
then
3280 Current_Error_Source_File
:= Sfile
;
3283 -- Only output the listing if Sfile is known, to avoid
3284 -- crashing the compiler.
3286 if Sfile
> No_Source_File
then
3287 for N
in 1 .. Last_Source_Line
(Sfile
) loop
3288 while E
/= No_Error_Msg
3289 and then Errors
.Table
(E
).Deleted
3291 E
:= Errors
.Table
(E
).Next
;
3296 and then Errors
.Table
(E
).Line
= N
3297 and then Errors
.Table
(E
).Sfile
= Sfile
;
3299 Output_Source_Line
(N
, Sfile
, Err_Flag
);
3302 Output_Error_Msgs
(E
);
3304 if not Debug_Flag_2
then
3314 -- Then output errors, if any, for subsidiary units not in the
3315 -- main extended unit.
3317 -- Note: if debug flag d.m set, include errors for any units other
3318 -- than the main unit in the extended source unit (e.g. spec and
3319 -- subunits for a body).
3321 while E
/= No_Error_Msg
3322 and then (not In_Extended_Main_Source_Unit
3323 (Errors
.Table
(E
).Sptr
.Ptr
)
3326 and then Get_Source_Unit
3327 (Errors
.Table
(E
).Sptr
.Ptr
) /= Main_Unit
))
3329 if Errors
.Table
(E
).Deleted
then
3330 E
:= Errors
.Table
(E
).Next
;
3335 (Errors
.Table
(E
).Line
, Errors
.Table
(E
).Sfile
, True);
3336 Output_Error_Msgs
(E
);
3340 -- If output to file, write extra copy of error summary to the
3341 -- output file, and then close it.
3343 if Full_List_File_Name
/= null then
3344 Write_Error_Summary
;
3346 Close_List_File_Access
.all;
3347 Cancel_Special_Output
;
3351 -- Verbose mode (error lines only with error flags). Normally this is
3352 -- ignored in full list mode, unless we are listing to a file, in which
3353 -- case we still generate -gnatv output to standard output.
3356 and then (not Full_List
or else Full_List_File_Name
/= null)
3360 -- Output the header only when Main_Source_File is known
3362 if Main_Source_File
> No_Source_File
then
3363 Write_Header
(Main_Source_File
);
3366 E
:= First_Error_Msg
;
3368 -- Loop through error lines
3370 while E
/= No_Error_Msg
loop
3371 if Errors
.Table
(E
).Deleted
then
3372 E
:= Errors
.Table
(E
).Next
;
3376 (Errors
.Table
(E
).Line
, Errors
.Table
(E
).Sfile
, True);
3377 Output_Error_Msgs
(E
);
3382 -- Output error summary if verbose or full list mode
3384 if Verbose_Mode
or else Full_List
then
3385 Write_Error_Summary
;
3388 if not Opt
.JSON_Output
then
3392 -- Even though Warning_Info_Messages are a subclass of warnings, they
3393 -- must not be treated as errors when -gnatwe is in effect.
3395 if Warning_Mode
= Treat_As_Error
then
3397 Compile_Time_Pragma_Warnings
: constant Int
:=
3398 Count_Compile_Time_Pragma_Warnings
;
3400 Total_Errors_Detected
:= Total_Errors_Detected
+ Warnings_Detected
3401 - Warning_Info_Messages
- Compile_Time_Pragma_Warnings
;
3402 Warnings_Detected
:=
3403 Warning_Info_Messages
+ Compile_Time_Pragma_Warnings
;
3406 end Output_Messages
;
3408 ------------------------
3409 -- Output_Source_Line --
3410 ------------------------
3412 procedure Output_Source_Line
3413 (L
: Physical_Line_Number
;
3414 Sfile
: Source_File_Index
;
3420 Line_Number_Output
: Boolean := False;
3421 -- Set True once line number is output
3423 Empty_Line
: Boolean := True;
3424 -- Set False if line includes at least one character
3427 if Sfile
/= Current_Error_Source_File
then
3428 Write_Str
("==============Error messages for ");
3430 case Sinput
.File_Type
(Sfile
) is
3432 Write_Str
("source");
3434 when Sinput
.Config
=>
3435 Write_Str
("configuration pragmas");
3438 Write_Str
("symbol definition");
3440 when Sinput
.Preproc
=>
3441 Write_Str
("preprocessing data");
3444 Write_Str
(" file: ");
3445 Write_Name
(Full_File_Name
(Sfile
));
3448 if Num_SRef_Pragmas
(Sfile
) > 0 then
3449 Write_Str
("--------------Line numbers from file: ");
3450 Write_Name
(Full_Ref_Name
(Sfile
));
3451 Write_Str
(" (starting at line ");
3452 Write_Int
(Int
(First_Mapped_Line
(Sfile
)));
3457 Current_Error_Source_File
:= Sfile
;
3460 if Errs
or List_Pragmas_Mode
then
3461 Output_Line_Number
(Physical_To_Logical
(L
, Sfile
));
3462 Line_Number_Output
:= True;
3465 S
:= Line_Start
(L
, Sfile
);
3468 C
:= Source_Text
(Sfile
) (S
);
3469 exit when C
= ASCII
.LF
or else C
= ASCII
.CR
or else C
= EOF
;
3471 -- Deal with matching entry in List_Pragmas table
3474 and then List_Pragmas_Index
<= List_Pragmas
.Last
3475 and then S
= List_Pragmas
.Table
(List_Pragmas_Index
).Ploc
3477 case List_Pragmas
.Table
(List_Pragmas_Index
).Ptyp
is
3481 -- Ignore if on line with errors so that error flags
3482 -- get properly listed with the error line .
3485 Write_Char
(ASCII
.FF
);
3489 List_Pragmas_Mode
:= True;
3491 if not Line_Number_Output
then
3492 Output_Line_Number
(Physical_To_Logical
(L
, Sfile
));
3493 Line_Number_Output
:= True;
3500 List_Pragmas_Mode
:= False;
3503 List_Pragmas_Index
:= List_Pragmas_Index
+ 1;
3505 -- Normal case (no matching entry in List_Pragmas table)
3508 if Errs
or List_Pragmas_Mode
then
3513 Empty_Line
:= False;
3517 -- If we have output a source line, then add the line terminator, with
3518 -- training spaces preserved (so we output the line exactly as input).
3520 if Line_Number_Output
then
3524 Write_Eol_Keep_Blanks
;
3527 end Output_Source_Line
;
3529 --------------------
3530 -- Paren_Required --
3531 --------------------
3533 function Paren_Required
(N
: Node_Id
) return Boolean is
3535 -- In a qualifed_expression the expression part needs to be enclosed in
3538 if Nkind
(Parent
(N
)) = N_Qualified_Expression
then
3539 return N
= Expression
(Parent
(N
));
3546 -----------------------------
3547 -- Remove_Warning_Messages --
3548 -----------------------------
3550 procedure Remove_Warning_Messages
(N
: Node_Id
) is
3552 function Check_For_Warning
(N
: Node_Id
) return Traverse_Result
;
3553 -- This function checks one node for a possible warning message
3555 procedure Check_All_Warnings
is new Traverse_Proc
(Check_For_Warning
);
3556 -- This defines the traversal operation
3558 -----------------------
3559 -- Check_For_Warning --
3560 -----------------------
3562 function Check_For_Warning
(N
: Node_Id
) return Traverse_Result
is
3563 Loc
: constant Source_Ptr
:= Sloc
(N
);
3566 function To_Be_Removed
(E
: Error_Msg_Id
) return Boolean;
3567 -- Returns True for a message that is to be removed. Also adjusts
3568 -- warning count appropriately.
3574 function To_Be_Removed
(E
: Error_Msg_Id
) return Boolean is
3576 if E
/= No_Error_Msg
3578 -- Don't remove if location does not match
3580 and then Errors
.Table
(E
).Optr
.Ptr
= Loc
3582 -- Don't remove if not warning/info message. Note that we do
3583 -- not remove style messages here. They are warning messages
3584 -- but not ones we want removed in this context.
3586 and then (Errors
.Table
(E
).Warn
3588 Errors
.Table
(E
).Warn_Runtime_Raise
)
3590 -- Don't remove unconditional messages
3592 and then not Errors
.Table
(E
).Uncond
3594 if Errors
.Table
(E
).Warn
then
3595 Warnings_Detected
:= Warnings_Detected
- 1;
3598 if Errors
.Table
(E
).Info
then
3599 Warning_Info_Messages
:= Warning_Info_Messages
- 1;
3602 -- When warning about a runtime exception has been escalated
3603 -- into error, the starting message has increased the total
3604 -- errors counter, so here we decrease this counter.
3606 if Errors
.Table
(E
).Warn_Runtime_Raise
3607 and then not Errors
.Table
(E
).Msg_Cont
3608 and then Warning_Mode
= Treat_Run_Time_Warnings_As_Errors
3610 Total_Errors_Detected
:= Total_Errors_Detected
- 1;
3615 -- No removal required
3622 -- Start of processing for Check_For_Warnings
3625 while To_Be_Removed
(First_Error_Msg
) loop
3626 First_Error_Msg
:= Errors
.Table
(First_Error_Msg
).Next
;
3629 if First_Error_Msg
= No_Error_Msg
then
3630 Last_Error_Msg
:= No_Error_Msg
;
3633 E
:= First_Error_Msg
;
3634 while E
/= No_Error_Msg
loop
3635 while To_Be_Removed
(Errors
.Table
(E
).Next
) loop
3636 Errors
.Table
(E
).Next
:=
3637 Errors
.Table
(Errors
.Table
(E
).Next
).Next
;
3639 if Errors
.Table
(E
).Next
= No_Error_Msg
then
3640 Last_Error_Msg
:= E
;
3644 E
:= Errors
.Table
(E
).Next
;
3647 -- Warnings may have been posted on subexpressions of original tree
3649 if Nkind
(N
) = N_Raise_Constraint_Error
3650 and then Is_Rewrite_Substitution
(N
)
3651 and then No
(Condition
(N
))
3653 Check_All_Warnings
(Original_Node
(N
));
3657 end Check_For_Warning
;
3659 -- Start of processing for Remove_Warning_Messages
3662 if Warnings_Detected
/= 0 then
3663 Check_All_Warnings
(N
);
3665 end Remove_Warning_Messages
;
3667 procedure Remove_Warning_Messages
(L
: List_Id
) is
3671 while Present
(Stat
) loop
3672 Remove_Warning_Messages
(Stat
);
3675 end Remove_Warning_Messages
;
3677 ----------------------
3678 -- Adjust_Name_Case --
3679 ----------------------
3681 procedure Adjust_Name_Case
3682 (Buf
: in out Bounded_String
;
3685 Src_Ind
: constant Source_File_Index
:= Get_Source_File_Index
(Loc
);
3686 Sbuffer
: Source_Buffer_Ptr
;
3688 Src_Ptr
: Source_Ptr
;
3691 -- We have an all lower case name from Namet, and now we want to set
3692 -- the appropriate case. If possible we copy the actual casing from
3693 -- the source. If not we use standard identifier casing.
3698 -- For standard locations, always use mixed case
3700 if Loc
<= No_Location
then
3701 Set_Casing
(Buf
, Mixed_Case
);
3704 -- Determine if the reference we are dealing with corresponds to text
3705 -- at the point of the error reference. This will often be the case
3706 -- for simple identifier references, and is the case where we can
3707 -- copy the casing from the source.
3709 Sbuffer
:= Source_Text
(Src_Ind
);
3711 while Ref_Ptr
<= Buf
.Length
loop
3713 Fold_Lower
(Sbuffer
(Src_Ptr
)) /=
3714 Fold_Lower
(Buf
.Chars
(Ref_Ptr
));
3715 Ref_Ptr
:= Ref_Ptr
+ 1;
3716 Src_Ptr
:= Src_Ptr
+ 1;
3719 -- If we get through the loop without a mismatch, then output the
3720 -- name the way it is cased in the source program.
3722 if Ref_Ptr
> Buf
.Length
then
3725 for J
in 1 .. Buf
.Length
loop
3726 Buf
.Chars
(J
) := Sbuffer
(Src_Ptr
);
3727 Src_Ptr
:= Src_Ptr
+ 1;
3730 -- Otherwise set the casing using the default identifier casing
3733 Set_Casing
(Buf
, Identifier_Casing
(Src_Ind
));
3736 end Adjust_Name_Case
;
3738 ---------------------------
3739 -- Set_Identifier_Casing --
3740 ---------------------------
3742 procedure Set_Identifier_Casing
3743 (Identifier_Name
: System
.Address
;
3744 File_Name
: System
.Address
)
3746 Ident
: constant Big_String_Ptr
:= To_Big_String_Ptr
(Identifier_Name
);
3747 File
: constant Big_String_Ptr
:= To_Big_String_Ptr
(File_Name
);
3750 Desired_Case
: Casing_Type
:= Mixed_Case
;
3751 -- Casing required for result. Default value of Mixed_Case is used if
3752 -- for some reason we cannot find the right file name in the table.
3755 -- Get length of file name
3758 while File
(Flen
+ 1) /= ASCII
.NUL
loop
3762 -- Loop through file names to find matching one. This is a bit slow, but
3763 -- we only do it in error situations so it is not so terrible. Note that
3764 -- if the loop does not exit, then the desired case will be left set to
3765 -- Mixed_Case, this can happen if the name was not in canonical form.
3767 for J
in 1 .. Last_Source_File
loop
3768 Get_Name_String
(Full_Debug_Name
(J
));
3771 and then Name_Buffer
(1 .. Name_Len
) = String (File
(1 .. Flen
))
3773 Desired_Case
:= Identifier_Casing
(J
);
3778 -- Copy identifier as given to Name_Buffer
3780 for J
in Name_Buffer
'Range loop
3781 Name_Buffer
(J
) := Ident
(J
);
3783 if Name_Buffer
(J
) = ASCII
.NUL
then
3789 Set_Casing
(Desired_Case
);
3790 end Set_Identifier_Casing
;
3792 -----------------------
3793 -- Set_Ignore_Errors --
3794 -----------------------
3796 procedure Set_Ignore_Errors
(To
: Boolean) is
3798 Errors_Must_Be_Ignored
:= To
;
3799 end Set_Ignore_Errors
;
3801 ------------------------------
3802 -- Set_Msg_Insertion_Column --
3803 ------------------------------
3805 procedure Set_Msg_Insertion_Column
is
3807 if RM_Column_Check
then
3808 Set_Msg_Str
(" in column ");
3809 Set_Msg_Int
(Int
(Error_Msg_Col
) + 1);
3811 end Set_Msg_Insertion_Column
;
3813 ----------------------------
3814 -- Set_Msg_Insertion_Node --
3815 ----------------------------
3817 procedure Set_Msg_Insertion_Node
is
3822 Error_Msg_Node_1
= Error
3823 or else Error_Msg_Node_1
= Any_Type
;
3825 if Error_Msg_Node_1
= Empty
then
3826 Set_Msg_Blank_Conditional
;
3827 Set_Msg_Str
("<empty>");
3829 elsif Error_Msg_Node_1
= Error
then
3831 Set_Msg_Str
("<error>");
3833 elsif Error_Msg_Node_1
= Standard_Void_Type
then
3835 Set_Msg_Str
("procedure name");
3837 elsif Nkind
(Error_Msg_Node_1
) in N_Entity
3838 and then Ekind
(Error_Msg_Node_1
) = E_Anonymous_Access_Subprogram_Type
3841 Set_Msg_Str
("access to subprogram");
3844 Set_Msg_Blank_Conditional
;
3848 K
:= Nkind
(Error_Msg_Node_1
);
3850 -- If we have operator case, skip quotes since name of operator
3851 -- itself will supply the required quotations. An operator can be an
3852 -- applied use in an expression or an explicit operator symbol, or an
3853 -- identifier whose name indicates it is an operator.
3856 or else K
= N_Operator_Symbol
3857 or else K
= N_Defining_Operator_Symbol
3858 or else ((K
= N_Identifier
or else K
= N_Defining_Identifier
)
3859 and then Is_Operator_Name
(Chars
(Error_Msg_Node_1
)))
3861 Set_Msg_Node
(Error_Msg_Node_1
);
3863 -- Normal case, not an operator, surround with quotes
3867 Set_Qualification
(Error_Msg_Qual_Level
, Error_Msg_Node_1
);
3868 Set_Msg_Node
(Error_Msg_Node_1
);
3873 -- The following assignment ensures that further ampersand insertion
3874 -- characters will correspond to the Error_Msg_Node_# parameter.
3876 Error_Msg_Node_1
:= Error_Msg_Node_2
;
3877 Error_Msg_Node_2
:= Error_Msg_Node_3
;
3878 Error_Msg_Node_3
:= Error_Msg_Node_4
;
3879 Error_Msg_Node_4
:= Error_Msg_Node_5
;
3880 Error_Msg_Node_5
:= Error_Msg_Node_6
;
3881 end Set_Msg_Insertion_Node
;
3883 --------------------------------------
3884 -- Set_Msg_Insertion_Type_Reference --
3885 --------------------------------------
3887 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
) is
3893 if Error_Msg_Node_1
= Standard_Void_Type
then
3894 Set_Msg_Str
("package or procedure name");
3897 elsif Error_Msg_Node_1
= Standard_Exception_Type
then
3898 Set_Msg_Str
("exception name");
3901 elsif Error_Msg_Node_1
= Any_Array
3902 or else Error_Msg_Node_1
= Any_Boolean
3903 or else Error_Msg_Node_1
= Any_Character
3904 or else Error_Msg_Node_1
= Any_Composite
3905 or else Error_Msg_Node_1
= Any_Discrete
3906 or else Error_Msg_Node_1
= Any_Fixed
3907 or else Error_Msg_Node_1
= Any_Integer
3908 or else Error_Msg_Node_1
= Any_Modular
3909 or else Error_Msg_Node_1
= Any_Numeric
3910 or else Error_Msg_Node_1
= Any_Real
3911 or else Error_Msg_Node_1
= Any_Scalar
3912 or else Error_Msg_Node_1
= Any_String
3914 Get_Unqualified_Decoded_Name_String
(Chars
(Error_Msg_Node_1
));
3915 Set_Msg_Name_Buffer
;
3918 elsif Error_Msg_Node_1
= Universal_Integer
then
3919 Set_Msg_Str
("type universal integer");
3922 elsif Error_Msg_Node_1
= Universal_Real
then
3923 Set_Msg_Str
("type universal real");
3926 elsif Error_Msg_Node_1
= Universal_Fixed
then
3927 Set_Msg_Str
("type universal fixed");
3930 elsif Error_Msg_Node_1
= Universal_Access
then
3931 Set_Msg_Str
("type universal access");
3935 -- Special case of anonymous array
3937 if Nkind
(Error_Msg_Node_1
) in N_Entity
3938 and then Is_Array_Type
(Error_Msg_Node_1
)
3939 and then Present
(Related_Array_Object
(Error_Msg_Node_1
))
3941 Set_Msg_Str
("type of ");
3942 Set_Msg_Node
(Related_Array_Object
(Error_Msg_Node_1
));
3943 Set_Msg_Str
(" declared");
3944 Set_Msg_Insertion_Line_Number
3945 (Sloc
(Related_Array_Object
(Error_Msg_Node_1
)), Flag
);
3949 -- If we fall through, it is not a special case, so first output
3950 -- the name of the type, preceded by private for a private type
3952 if Is_Private_Type
(Error_Msg_Node_1
) then
3953 Set_Msg_Str
("private type ");
3955 Set_Msg_Str
("type ");
3958 Ent
:= Error_Msg_Node_1
;
3960 if Is_Internal_Name
(Chars
(Ent
)) then
3961 Unwind_Internal_Type
(Ent
);
3964 -- Types in Standard are displayed as "Standard.name"
3966 if Sloc
(Ent
) <= Standard_Location
then
3968 Set_Msg_Str
("Standard.");
3973 -- Types in other language defined units are displayed as
3974 -- "package-name.type-name"
3976 elsif Is_Predefined_Unit
(Get_Source_Unit
(Ent
)) then
3977 Get_Unqualified_Decoded_Name_String
3978 (Unit_Name
(Get_Source_Unit
(Ent
)));
3979 Name_Len
:= Name_Len
- 2;
3980 Set_Msg_Blank_Conditional
;
3982 Set_Casing
(Mixed_Case
);
3983 Set_Msg_Name_Buffer
;
3985 Set_Casing
(Mixed_Case
);
3990 -- All other types display as "type name" defined at line xxx
3991 -- possibly qualified if qualification is requested.
3995 Set_Qualification
(Error_Msg_Qual_Level
, Ent
);
3999 -- If we did not print a name (e.g. in the case of an anonymous
4000 -- subprogram type), there is no name to print, so remove quotes.
4002 if Buffer_Ends_With
('"') then
4003 Buffer_Remove
('"');
4009 -- If the original type did not come from a predefined file, add the
4010 -- location where the type was defined.
4012 if Sloc
(Error_Msg_Node_1
) > Standard_Location
4014 not Is_Predefined_Unit
(Get_Source_Unit
(Error_Msg_Node_1
))
4016 Get_Name_String
(Unit_File_Name
(Get_Source_Unit
(Error_Msg_Node_1
)));
4017 Set_Msg_Str
(" defined");
4018 Set_Msg_Insertion_Line_Number
(Sloc
(Error_Msg_Node_1
), Flag
);
4020 -- If it did come from a predefined file, deal with the case where
4021 -- this was a file with a generic instantiation from elsewhere.
4024 if Sloc
(Error_Msg_Node_1
) > Standard_Location
then
4026 Iloc
: constant Source_Ptr
:=
4027 Instantiation_Location
(Sloc
(Error_Msg_Node_1
));
4030 if Iloc
/= No_Location
4031 and then not Suppress_Instance_Location
4033 Set_Msg_Str
(" from instance");
4034 Set_Msg_Insertion_Line_Number
(Iloc
, Flag
);
4039 end Set_Msg_Insertion_Type_Reference
;
4041 ---------------------------------
4042 -- Set_Msg_Insertion_Unit_Name --
4043 ---------------------------------
4045 procedure Set_Msg_Insertion_Unit_Name
(Suffix
: Boolean := True) is
4047 if Error_Msg_Unit_1
= No_Unit_Name
then
4050 elsif Error_Msg_Unit_1
= Error_Unit_Name
then
4052 Set_Msg_Str
("<error>");
4055 Get_Unit_Name_String
(Global_Name_Buffer
, Error_Msg_Unit_1
, Suffix
);
4058 Set_Msg_Name_Buffer
;
4062 -- The following assignment ensures that a second percent insertion
4063 -- character will correspond to the Error_Msg_Unit_2 parameter.
4065 Error_Msg_Unit_1
:= Error_Msg_Unit_2
;
4066 end Set_Msg_Insertion_Unit_Name
;
4072 procedure Set_Msg_Node
(Node
: Node_Id
) is
4078 case Nkind
(Node
) is
4079 when N_Designator
=>
4080 Set_Msg_Node
(Name
(Node
));
4082 Set_Msg_Node
(Identifier
(Node
));
4085 when N_Defining_Program_Unit_Name
=>
4086 Set_Msg_Node
(Name
(Node
));
4088 Set_Msg_Node
(Defining_Identifier
(Node
));
4091 when N_Expanded_Name
4092 | N_Selected_Component
4094 Set_Msg_Node
(Prefix
(Node
));
4096 Set_Msg_Node
(Selector_Name
(Node
));
4103 -- The only remaining possibilities are identifiers, defining
4104 -- identifiers, pragmas, and pragma argument associations.
4106 if Nkind
(Node
) = N_Pragma
then
4107 Nam
:= Pragma_Name
(Node
);
4110 -- The other cases have Chars fields
4112 -- First deal with internal names, which generally represent something
4113 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4114 -- something with a Chars field that is not an internal name, use that.
4116 elsif Is_Internal_Name
(Chars
(Node
))
4117 and then Nkind
(Original_Node
(Node
)) in N_Has_Chars
4118 and then not Is_Internal_Name
(Chars
(Original_Node
(Node
)))
4120 Nam
:= Chars
(Original_Node
(Node
));
4121 Loc
:= Sloc
(Original_Node
(Node
));
4123 -- Another shot for internal names, in the case of internal type names,
4124 -- we try to find a reasonable representation for the external name.
4126 elsif Is_Internal_Name
(Chars
(Node
))
4128 ((Is_Entity_Name
(Node
)
4129 and then Present
(Entity
(Node
))
4130 and then Is_Type
(Entity
(Node
)))
4132 (Nkind
(Node
) = N_Defining_Identifier
and then Is_Type
(Node
)))
4134 if Nkind
(Node
) = N_Identifier
then
4135 Ent
:= Entity
(Node
);
4142 -- If the type is the designated type of an access_to_subprogram,
4143 -- then there is no name to provide in the call.
4145 if Ekind
(Ent
) = E_Subprogram_Type
then
4148 -- Otherwise, we will be able to find some kind of name to output
4151 Unwind_Internal_Type
(Ent
);
4155 -- If not internal name, or if we could not find a reasonable possible
4156 -- substitution for the internal name, just use name in Chars field.
4159 Nam
:= Chars
(Node
);
4163 -- At this stage, the name to output is in Nam
4165 Get_Unqualified_Decoded_Name_String
(Nam
);
4167 -- Remove trailing upper case letters from the name (useful for
4168 -- dealing with some cases of internal names).
4170 while Name_Len
> 1 and then Name_Buffer
(Name_Len
) in 'A' .. 'Z' loop
4171 Name_Len
:= Name_Len
- 1;
4174 -- If we have any of the names from standard that start with the
4175 -- characters "any " (e.g. Any_Type), then kill the message since
4176 -- almost certainly it is a junk cascaded message.
4179 and then Name_Buffer
(1 .. 4) = "any "
4181 Kill_Message
:= True;
4184 -- If we still have an internal name, kill the message (will only
4185 -- work if we already had errors!)
4187 if Is_Internal_Name
then
4188 Kill_Message
:= True;
4190 -- Remaining step is to adjust casing and possibly add 'Class
4192 Adjust_Name_Case
(Global_Name_Buffer
, Loc
);
4193 Set_Msg_Name_Buffer
;
4201 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
) is
4202 C
: Character; -- Current character
4203 P
: Natural; -- Current index;
4205 procedure Skip_Msg_Insertion_Warning
(C
: Character);
4206 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4207 -- sequences using < instead of ?). The caller has already bumped
4208 -- the pointer past the initial ? or < and C is set to this initial
4209 -- character (? or <). This procedure skips past the rest of the
4210 -- sequence. We do not need to set Msg_Insertion_Char, since this
4211 -- was already done during the message prescan.
4212 -- No validity check is performed as the insertion sequence is
4213 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4214 -- erroutc.adb for the validity checks.
4216 --------------------------------
4217 -- Skip_Msg_Insertion_Warning --
4218 --------------------------------
4220 procedure Skip_Msg_Insertion_Warning
(C
: Character) is
4222 if P
<= Text
'Last and then Text
(P
) = C
then
4225 elsif P
< Text
'Last and then Text
(P
+ 1) = C
4226 and then Text
(P
) in 'a' .. 'z' |
'A' .. 'Z' |
4227 '0' .. '9' |
'*' |
'$'
4231 elsif P
+ 1 < Text
'Last and then Text
(P
+ 2) = C
4232 and then Text
(P
) in '.' |
'_'
4233 and then Text
(P
+ 1) in 'a' .. 'z'
4237 end Skip_Msg_Insertion_Warning
;
4239 -- Start of processing for Set_Msg_Text
4242 Manual_Quote_Mode
:= False;
4244 Flag_Source
:= Get_Source_File_Index
(Flag
);
4246 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4247 -- will be used (Info field in error message object) to put back the
4248 -- string when it is printed. We need to do this, or we get confused
4249 -- with instantiation continuations.
4252 and then Text
(Text
'First .. Text
'First + 5) = "info: "
4254 P
:= Text
'First + 6;
4259 -- Loop through characters of message
4261 while P
<= Text
'Last loop
4265 -- Check for insertion character or sequence
4269 if P
<= Text
'Last and then Text
(P
) = '%' then
4271 Set_Msg_Insertion_Name_Literal
;
4273 Set_Msg_Insertion_Name
;
4277 if P
<= Text
'Last and then Text
(P
) = '$' then
4279 Set_Msg_Insertion_Unit_Name
(Suffix
=> False);
4281 Set_Msg_Insertion_Unit_Name
;
4285 Set_Msg_Insertion_File_Name
;
4288 Set_Msg_Insertion_Type_Reference
(Flag
);
4291 Set_Msg_Insertion_Reserved_Name
;
4294 Set_Msg_Insertion_Node
;
4297 Set_Msg_Insertion_Line_Number
(Error_Msg_Sloc
, Flag
);
4300 Continuation
:= True;
4302 if P
<= Text
'Last and then Text
(P
) = '\' then
4303 Continuation_New_Line
:= True;
4308 Set_Msg_Insertion_Column
;
4311 Set_Msg_Insertion_Run_Time_Name
;
4314 Set_Msg_Insertion_Uint
;
4317 Manual_Quote_Mode
:= not Manual_Quote_Mode
;
4321 null; -- already dealt with
4324 Skip_Msg_Insertion_Warning
('?');
4327 Skip_Msg_Insertion_Warning
('<');
4330 null; -- already dealt with
4333 Set_Msg_Char
(Text
(P
));
4337 Set_Msg_Str
(Error_Msg_String
(1 .. Error_Msg_Strlen
));
4339 -- Upper case letter
4343 -- Start of reserved word if two or more
4345 if P
<= Text
'Last and then Text
(P
) in 'A' .. 'Z' then
4347 Set_Msg_Insertion_Reserved_Word
(Text
, P
);
4349 -- Single upper case letter is just inserted
4355 -- '[' (will be/would have been raised at run time)
4359 -- "[]" (insertion of error code)
4361 if P
<= Text
'Last and then Text
(P
) = ']' then
4363 Set_Msg_Insertion_Code
;
4366 -- Switch the message from a warning to an error if the flag
4367 -- -gnatwE is specified to treat run-time exception warnings
4371 and then Warning_Mode
= Treat_Run_Time_Warnings_As_Errors
4373 Is_Warning_Msg
:= False;
4374 Is_Runtime_Raise
:= True;
4377 if Is_Warning_Msg
then
4378 Set_Msg_Str
("will be raised at run time");
4380 Set_Msg_Str
("would have been raised at run time");
4384 -- ']' (may be/might have been raised at run time)
4387 if Is_Warning_Msg
then
4388 Set_Msg_Str
("may be raised at run time");
4390 Set_Msg_Str
("might have been raised at run time");
4393 -- Normal character with no special treatment
4405 procedure Set_Posted
(N
: Node_Id
) is
4409 if Is_Serious_Error
then
4411 -- We always set Error_Posted on the node itself
4413 Set_Error_Posted
(N
);
4415 -- If it is a subexpression, then set Error_Posted on parents up to
4416 -- and including the first non-subexpression construct. This helps
4417 -- avoid cascaded error messages within a single expression.
4423 Set_Error_Posted
(P
);
4424 exit when Nkind
(P
) not in N_Subexpr
;
4427 if Nkind
(P
) in N_Pragma_Argument_Association
4428 | N_Component_Association
4429 | N_Discriminant_Association
4430 | N_Generic_Association
4431 | N_Parameter_Association
4433 Set_Error_Posted
(Parent
(P
));
4436 -- A special check, if we just posted an error on an attribute
4437 -- definition clause, then also set the entity involved as posted.
4438 -- For example, this stops complaining about the alignment after
4439 -- complaining about the size, which is likely to be useless.
4441 if Nkind
(P
) = N_Attribute_Definition_Clause
then
4442 if Is_Entity_Name
(Name
(P
)) then
4443 Set_Error_Posted
(Entity
(Name
(P
)));
4449 -----------------------
4450 -- Set_Qualification --
4451 -----------------------
4453 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
) is
4455 if N
/= 0 and then Scope
(E
) /= Standard_Standard
then
4456 Set_Qualification
(N
- 1, Scope
(E
));
4457 Set_Msg_Node
(Scope
(E
));
4460 end Set_Qualification
;
4462 ------------------------
4463 -- Special_Msg_Delete --
4464 ------------------------
4466 -- Is it really right to have all this specialized knowledge in errout?
4468 function Special_Msg_Delete
4470 N
: Node_Or_Entity_Id
;
4471 E
: Node_Or_Entity_Id
) return Boolean
4474 -- Never delete messages in -gnatdO mode
4476 if Debug_Flag_OO
then
4479 -- Processing for "Size too small" messages
4481 elsif Is_Size_Too_Small_Message
(Msg
) then
4483 -- Suppress "size too small" errors in CodePeer mode, since code may
4484 -- be analyzed in a different configuration than the one used for
4485 -- compilation. Even when the configurations match, this message
4486 -- may be issued on correct code, because pragma Pack is ignored
4487 -- in CodePeer mode.
4489 if CodePeer_Mode
then
4492 -- When a size is wrong for a frozen type there is no explicit size
4493 -- clause, and other errors have occurred, suppress the message,
4494 -- since it is likely that this size error is a cascaded result of
4495 -- other errors. The reason we eliminate unfrozen types is that
4496 -- messages issued before the freeze type are for sure OK.
4498 elsif Nkind
(N
) in N_Entity
4499 and then Is_Frozen
(E
)
4500 and then Serious_Errors_Detected
> 0
4501 and then Nkind
(N
) /= N_Component_Clause
4502 and then Nkind
(Parent
(N
)) /= N_Component_Clause
4504 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Size
))
4506 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Object_Size
))
4508 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Value_Size
))
4514 -- All special tests complete, so go ahead with message
4517 end Special_Msg_Delete
;
4523 procedure SPARK_Msg_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
4525 if SPARK_Mode
/= Off
then
4526 Error_Msg_N
(Msg
, N
);
4534 procedure SPARK_Msg_NE
4536 N
: Node_Or_Entity_Id
;
4537 E
: Node_Or_Entity_Id
)
4540 if SPARK_Mode
/= Off
then
4541 Error_Msg_NE
(Msg
, N
, E
);
4545 --------------------------
4546 -- Unwind_Internal_Type --
4547 --------------------------
4549 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
) is
4550 Derived
: Boolean := False;
4552 Old_Ent
: Entity_Id
;
4555 -- Undo placement of a quote, since we will put it back later
4557 Mchar
:= Msg_Buffer
(Msglen
);
4560 Msglen
:= Msglen
- 1;
4563 -- The loop here deals with recursive types, we are trying to find a
4564 -- related entity that is not an implicit type. Note that the check with
4565 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4566 -- "type derived from" message more than once in the case where we climb
4567 -- up multiple levels.
4572 -- Implicit access type, use directly designated type In Ada 2005,
4573 -- the designated type may be an anonymous access to subprogram, in
4574 -- which case we can only point to its definition.
4576 if Is_Access_Type
(Ent
) then
4577 if Ekind
(Ent
) = E_Access_Subprogram_Type
4578 or else Ekind
(Ent
) = E_Anonymous_Access_Subprogram_Type
4579 or else Is_Access_Protected_Subprogram_Type
(Ent
)
4581 Ent
:= Directly_Designated_Type
(Ent
);
4583 if not Comes_From_Source
(Ent
) then
4584 if Buffer_Ends_With
("type ") then
4585 Buffer_Remove
("type ");
4589 if Ekind
(Ent
) = E_Function
then
4590 Set_Msg_Str
("access to function ");
4591 elsif Ekind
(Ent
) = E_Procedure
then
4592 Set_Msg_Str
("access to procedure ");
4594 Set_Msg_Str
("access to subprogram");
4599 -- Type is access to object, named or anonymous
4602 Set_Msg_Str
("access to ");
4603 Ent
:= Directly_Designated_Type
(Ent
);
4608 elsif Is_Class_Wide_Type
(Ent
) then
4610 Ent
:= Root_Type
(Ent
);
4612 -- Use base type if this is a subtype
4614 elsif Ent
/= Base_Type
(Ent
) then
4615 Buffer_Remove
("type ");
4617 -- Avoid duplication "subtype of subtype of", and also replace
4618 -- "derived from subtype of" simply by "derived from"
4620 if not Buffer_Ends_With
("subtype of ")
4621 and then not Buffer_Ends_With
("derived from ")
4623 Set_Msg_Str
("subtype of ");
4626 Ent
:= Base_Type
(Ent
);
4628 -- If this is a base type with a first named subtype, use the first
4629 -- named subtype instead. This is not quite accurate in all cases,
4630 -- but it makes too much noise to be accurate and add 'Base in all
4631 -- cases. Note that we only do this is the first named subtype is not
4632 -- itself an internal name. This avoids the obvious loop (subtype ->
4633 -- basetype -> subtype) which would otherwise occur).
4637 FST
: constant Entity_Id
:= First_Subtype
(Ent
);
4640 if not Is_Internal_Name
(Chars
(FST
)) then
4644 -- Otherwise use root type
4648 Buffer_Remove
("type ");
4650 -- Test for "subtype of type derived from" which seems
4651 -- excessive and is replaced by "type derived from".
4653 Buffer_Remove
("subtype of");
4655 -- Avoid duplicated "type derived from type derived from"
4657 if not Buffer_Ends_With
("type derived from ") then
4658 Set_Msg_Str
("type derived from ");
4669 -- If we are stuck in a loop, get out and settle for the internal
4670 -- name after all. In this case we set to kill the message if it is
4671 -- not the first error message (we really try hard not to show the
4672 -- dirty laundry of the implementation to the poor user).
4674 if Ent
= Old_Ent
then
4675 Kill_Message
:= True;
4679 -- Get out if we finally found a non-internal name to use
4681 exit Find
when not Is_Internal_Name
(Chars
(Ent
));
4687 end Unwind_Internal_Type
;
4689 --------------------
4690 -- Warn_Insertion --
4691 --------------------
4693 function Warn_Insertion
return String is
4695 if Warning_Msg_Char
= "? " then
4697 elsif Warning_Msg_Char
= " " then
4699 elsif Warning_Msg_Char
(2) = ' ' then
4700 return '?' & Warning_Msg_Char
(1) & '?';
4702 return '?' & Warning_Msg_Char
& '?';