1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2024, 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
104 -- This is the low-level routine used to post messages after dealing with
105 -- the issue of messages placed on instantiations (which get broken up
106 -- into separate calls in Error_Msg). Span is the location on which the
107 -- flag will be placed in the output. In the case where the flag is on
108 -- the template, this points directly to the template, not to one of the
109 -- instantiation copies of the template. Opan is the original location
110 -- used to flag the error, and this may indeed point to an instantiation
111 -- copy. So typically we can see Opan pointing to the template location
112 -- in an instantiation copy when Span points to the source location of
113 -- the actual instantiation (i.e the line with the new). Msg_Cont is
114 -- set true if this is a continuation message.
116 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean;
117 -- Determines if warnings should be suppressed for the given node
119 function OK_Node
(N
: Node_Id
) return Boolean;
120 -- Determines if a node is an OK node to place an error message on (return
121 -- True) or if the error message should be suppressed (return False). A
122 -- message is suppressed if the node already has an error posted on it,
123 -- or if it refers to an Etype that has an error posted on it, or if
124 -- it references an Entity that has an error posted on it.
126 procedure Output_JSON_Message
(Error_Id
: Error_Msg_Id
);
127 -- Output error message Error_Id and any subsequent continuation message
128 -- using a JSON format similar to the one GCC uses when passed
129 -- -fdiagnostics-format=json.
131 procedure Output_Source_Line
132 (L
: Physical_Line_Number
;
133 Sfile
: Source_File_Index
;
135 -- Outputs text of source line L, in file S, together with preceding line
136 -- number, as described above for Output_Line_Number. The Errs parameter
137 -- indicates if there are errors attached to the line, which forces
138 -- listing on, even in the presence of pragma List (Off).
140 function Paren_Required
(N
: Node_Id
) return Boolean;
141 -- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
142 -- around node N are required by the Ada syntax, e.g. when N is an
143 -- expression of a qualified expression.
145 procedure Set_Msg_Insertion_Column
;
146 -- Handle column number insertion (@ insertion character)
148 procedure Set_Msg_Insertion_Node
;
149 -- Handle node (name from node) insertion (& insertion character)
151 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
);
152 -- Handle type reference (right brace insertion character). Flag is the
153 -- location of the flag, which is provided for the internal call to
154 -- Set_Msg_Insertion_Line_Number,
156 procedure Set_Msg_Insertion_Unit_Name
(Suffix
: Boolean := True);
157 -- Handle unit name insertion ($ insertion character). Depending on Boolean
158 -- parameter Suffix, (spec) or (body) is appended after the unit name.
160 procedure Set_Msg_Node
(Node
: Node_Id
);
161 -- Add the sequence of characters for the name associated with the given
162 -- node to the current message. For N_Designator, N_Selected_Component,
163 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
166 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
);
167 -- Add a sequence of characters to the current message. The characters may
168 -- be one of the special insertion characters (see documentation in spec).
169 -- Flag is the location at which the error is to be posted, which is used
170 -- to determine whether or not the # insertion needs a file name. The
171 -- variables Msg_Buffer are set on return Msglen.
173 procedure Set_Posted
(N
: Node_Id
);
174 -- Sets the Error_Posted flag on the given node, and all its parents that
175 -- are subexpressions and then on the parent non-subexpression construct
176 -- that contains the original expression. If that parent is a named
177 -- association, the flag is further propagated to its parent. This is done
178 -- in order to guard against cascaded errors. Note that this call has an
179 -- effect for a serious error only.
181 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
);
182 -- Outputs up to N levels of qualification for the given entity. For
183 -- example, the entity A.B.C.D will output B.C. if N = 2.
185 function Should_Ignore_Pragma_SPARK_Mode
return Boolean;
186 -- Return whether pragma Ignore_Pragma (SPARK_Mode) was specified. This is
187 -- similar to Sem_Util.Should_Ignore_Pragma_Par but located here to avoid
188 -- problematic dependency on Sem_Util.
190 function Special_Msg_Delete
192 N
: Node_Or_Entity_Id
;
193 E
: Node_Or_Entity_Id
) return Boolean;
194 -- This function is called from Error_Msg_NEL, passing the message Msg,
195 -- node N on which the error is to be posted, and the entity or node E
196 -- to be used for an & insertion in the message if any. The job of this
197 -- procedure is to test for certain cascaded messages that we would like
198 -- to suppress. If the message is to be suppressed then we return True.
199 -- If the message should be generated (the normal case) False is returned.
201 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
);
202 -- This procedure is given an entity id for an internal type, i.e. a type
203 -- with an internal name. It unwinds the type to try to get to something
204 -- reasonably printable, generating prefixes like "subtype of", "access
205 -- to", etc along the way in the buffer. The value in Ent on return is the
206 -- final name to be printed. Hopefully this is not an internal name, but in
207 -- some internal name cases, it is an internal name, and has to be printed
208 -- anyway (although in this case the message has been killed if possible).
209 -- The global variable Class_Flag is set to True if the resulting entity
210 -- should have 'Class appended to its name (see Add_Class procedure), and
211 -- is otherwise unchanged.
213 procedure Validate_Specific_Warnings
;
214 -- Checks that specific warnings are consistent (for non-configuration
215 -- case, properly closed, and used).
217 function Warn_Insertion
return String;
218 -- This is called for warning messages only (so Warning_Msg_Char is set)
219 -- and returns a corresponding string to use at the beginning of generated
220 -- auxiliary messages, such as "in instantiation at ...".
223 -- other trimmed, prefixed and suffixed with "?".
225 -----------------------
226 -- Change_Error_Text --
227 -----------------------
229 procedure Change_Error_Text
(Error_Id
: Error_Msg_Id
; New_Msg
: String) is
230 Save_Next
: Error_Msg_Id
;
231 Err_Id
: Error_Msg_Id
:= Error_Id
;
234 Set_Msg_Text
(New_Msg
, Errors
.Table
(Error_Id
).Sptr
.Ptr
);
235 Errors
.Table
(Error_Id
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
237 -- If in immediate error message mode, output modified error message now
238 -- This is just a bit tricky, because we want to output just a single
239 -- message, and the messages we modified is already linked in. We solve
240 -- this by temporarily resetting its forward pointer to empty.
242 if Debug_Flag_OO then
243 Save_Next := Errors.Table (Error_Id).Next;
244 Errors.Table (Error_Id).Next := No_Error_Msg;
247 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
248 Output_Error_Msgs (Err_Id);
249 Errors.Table (Error_Id).Next := Save_Next;
251 end Change_Error_Text;
253 ------------------------
254 -- Compilation_Errors --
255 ------------------------
257 function Compilation_Errors return Boolean is
259 if not Finalize_Called then
262 return Erroutc.Compilation_Errors;
264 end Compilation_Errors;
266 --------------------------------------
267 -- Delete_Warning_And_Continuations --
268 --------------------------------------
270 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
274 pragma Assert (not Errors.Table (Msg).Msg_Cont);
279 M : Error_Msg_Object renames Errors.Table (Id);
282 if not M.Deleted then
284 Warnings_Detected := Warnings_Detected - 1;
287 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
292 exit when Id = No_Error_Msg;
293 exit when not Errors.Table (Id).Msg_Cont;
296 end Delete_Warning_And_Continuations;
302 -- Error_Msg posts a flag at the given location, except that if the
303 -- Flag_Location/Flag_Span points within a generic template and corresponds
304 -- to an instantiation of this generic template, then the actual message
305 -- will be posted on the generic instantiation, along with additional
306 -- messages referencing the generic declaration.
308 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
310 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
313 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
315 Error_Msg (Msg, Flag_Span, Current_Node);
320 Flag_Location : Source_Ptr;
322 Is_Compile_Time_Pragma : Boolean)
324 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
326 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
327 Error_Msg (Msg, To_Span (Flag_Location), N);
328 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
333 Flag_Location : Source_Ptr;
337 Error_Msg (Msg, To_Span (Flag_Location), N);
342 Flag_Span : Source_Span;
345 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
347 Sindex : Source_File_Index;
348 -- Source index for flag location
350 Orig_Loc : Source_Ptr;
351 -- Original location of Flag_Location (i.e. location in original
352 -- template in instantiation case, otherwise unchanged).
355 -- Return if all errors are to be ignored
357 if Get_Ignore_Errors then
361 -- If we already have messages, and we are trying to place a message at
362 -- No_Location, then just ignore the attempt since we assume that what
363 -- is happening is some cascaded junk. Note that this is safe in the
364 -- sense that proceeding will surely bomb. We will also bomb if the flag
365 -- location is No_Location and we don't have any messages so far, but
366 -- that is a real bug and a legitimate bomb, so we go ahead.
368 if Flag_Location = No_Location
369 and then Total_Errors_Detected > 0
374 -- Start of processing for new message
376 Sindex := Get_Source_File_Index (Flag_Location);
377 Prescan_Message (Msg);
378 Orig_Loc := Original_Location (Flag_Location);
380 -- If the current location is in an instantiation, the issue arises of
381 -- whether to post the message on the template or the instantiation.
383 -- The way we decide is to see if we have posted the same message on
384 -- the template when we compiled the template (the template is always
385 -- compiled before any instantiations). For this purpose, we use a
386 -- separate table of messages. The reason we do this is twofold:
388 -- First, the messages can get changed by various processing
389 -- including the insertion of tokens etc, making it hard to
390 -- do the comparison.
392 -- Second, we will suppress a warning on a template if it is not in
393 -- the current extended source unit. That's reasonable and means we
394 -- don't want the warning on the instantiation here either, but it
395 -- does mean that the main error table would not in any case include
398 if Flag_Location = Orig_Loc then
399 Non_Instance_Msgs.Append ((new String'(Msg
), Flag_Location
));
400 Warn_On_Instance
:= False;
402 -- Here we have an instance message
405 -- Delete if debug flag off, and this message duplicates a message
406 -- already posted on the corresponding template
408 if not Debug_Flag_GG
then
409 for J
in Non_Instance_Msgs
.First
.. Non_Instance_Msgs
.Last
loop
410 if Msg
= Non_Instance_Msgs
.Table
(J
).Msg
.all
411 and then Non_Instance_Msgs
.Table
(J
).Loc
= Orig_Loc
418 -- No duplicate, so error/warning will be posted on instance
420 Warn_On_Instance
:= Is_Warning_Msg
;
423 -- Ignore warning message that is suppressed for this location. Note
424 -- that style checks are not considered warning messages for this
428 and then Warnings_Suppressed
(Orig_Loc
) /= No_String
432 -- For style messages, check too many messages so far
435 and then Maximum_Messages
/= 0
436 and then Warnings_Detected
>= Maximum_Messages
440 -- Suppress warnings inside a loop that is known to be null or is
441 -- probably null (i.e. when loop executes only if invalid values
442 -- present). In either case warnings in the loop are likely to be junk.
444 elsif Is_Warning_Msg
and then Present
(N
) then
451 while Present
(P
) loop
452 if Nkind
(P
) = N_Loop_Statement
453 and then Suppress_Loop_Warnings
(P
)
463 -- The idea at this stage is that we have two kinds of messages
465 -- First, we have those messages that are to be placed as requested at
466 -- Flag_Location. This includes messages that have nothing to do with
467 -- generics, and also messages placed on generic templates that reflect
468 -- an error in the template itself. For such messages we simply call
469 -- Error_Msg_Internal to place the message in the requested location.
471 if Instantiation
(Sindex
) = No_Location
then
472 Error_Msg_Internal
(Msg
, Flag_Span
, Flag_Span
, False);
476 -- If we are trying to flag an error in an instantiation, we may have
477 -- a generic contract violation. What we generate in this case is:
479 -- instantiation error at ...
480 -- original error message
484 -- warning: in instantiation at ...
485 -- warning: original warning message
489 -- info: in instantiation at ...
490 -- info: original info message
492 -- All these messages are posted at the location of the top level
493 -- instantiation. If there are nested instantiations, then the
494 -- instantiation error message can be repeated, pointing to each
495 -- of the relevant instantiations.
497 -- Note: the instantiation mechanism is also shared for inlining of
498 -- subprogram bodies when front end inlining is done. In this case the
499 -- messages have the form:
501 -- in inlined body at ...
502 -- original error message
506 -- warning: in inlined body at ...
507 -- warning: original warning message
511 -- info: in inlined body at ...
512 -- info: original info message
514 -- OK, here we have an instantiation error, and we need to generate the
515 -- error on the instantiation, rather than on the template.
518 Actual_Error_Loc
: Source_Ptr
;
519 -- Location of outer level instantiation in instantiation case, or
520 -- just a copy of Flag_Location in the normal case. This is the
521 -- location where all error messages will actually be posted.
523 Save_Error_Msg_Sloc
: constant Source_Ptr
:= Error_Msg_Sloc
;
524 -- Save possible location set for caller's message. We need to use
525 -- Error_Msg_Sloc for the location of the instantiation error but we
526 -- have to preserve a possible original value.
528 X
: Source_File_Index
;
530 Msg_Cont_Status
: Boolean;
531 -- Used to label continuation lines in instantiation case with
532 -- proper Msg_Cont status.
535 -- Loop to find highest level instantiation, where all error
536 -- messages will be placed.
540 Actual_Error_Loc
:= Instantiation
(X
);
541 X
:= Get_Source_File_Index
(Actual_Error_Loc
);
542 exit when Instantiation
(X
) = No_Location
;
545 -- Since we are generating the messages at the instantiation point in
546 -- any case, we do not want the references to the bad lines in the
547 -- instance to be annotated with the location of the instantiation.
549 Suppress_Instance_Location
:= True;
550 Msg_Cont_Status
:= False;
552 -- Loop to generate instantiation messages
554 Error_Msg_Sloc
:= Flag_Location
;
555 X
:= Get_Source_File_Index
(Flag_Location
);
556 while Instantiation
(X
) /= No_Location
loop
558 -- Suppress instantiation message on continuation lines
560 if Msg
(Msg
'First) /= '\' then
562 -- Case of inlined body
564 if Inlined_Body
(X
) then
567 (Msg
=> "info: in inlined body #",
568 Span
=> To_Span
(Actual_Error_Loc
),
570 Msg_Cont
=> Msg_Cont_Status
);
572 elsif Is_Warning_Msg
then
574 (Msg
=> Warn_Insertion
& "in inlined body #",
575 Span
=> To_Span
(Actual_Error_Loc
),
577 Msg_Cont
=> Msg_Cont_Status
);
579 elsif Is_Style_Msg
then
581 (Msg
=> "style: in inlined body #",
582 Span
=> To_Span
(Actual_Error_Loc
),
584 Msg_Cont
=> Msg_Cont_Status
);
588 (Msg
=> "error in inlined body #",
589 Span
=> To_Span
(Actual_Error_Loc
),
591 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
);
604 elsif Is_Warning_Msg
then
606 (Msg
=> Warn_Insertion
& "in instantiation #",
607 Span
=> To_Span
(Actual_Error_Loc
),
609 Msg_Cont
=> Msg_Cont_Status
);
611 elsif Is_Style_Msg
then
613 (Msg
=> "style: in instantiation #",
614 Span
=> To_Span
(Actual_Error_Loc
),
616 Msg_Cont
=> Msg_Cont_Status
);
620 (Msg
=> "instantiation error #",
621 Span
=> To_Span
(Actual_Error_Loc
),
623 Msg_Cont
=> Msg_Cont_Status
);
628 Error_Msg_Sloc
:= Instantiation
(X
);
629 X
:= Get_Source_File_Index
(Error_Msg_Sloc
);
630 Msg_Cont_Status
:= True;
633 Suppress_Instance_Location
:= False;
634 Error_Msg_Sloc
:= Save_Error_Msg_Sloc
;
636 -- Here we output the original message on the outer instantiation
640 Span
=> To_Span
(Actual_Error_Loc
),
642 Msg_Cont
=> Msg_Cont_Status
);
646 ----------------------------------
647 -- Error_Msg_Ada_2005_Extension --
648 ----------------------------------
650 procedure Error_Msg_Ada_2005_Extension
(Extension
: String) is
651 Loc
: constant Source_Ptr
:= Token_Ptr
;
653 if Ada_Version
< Ada_2005
then
654 Error_Msg
(Extension
& " is an Ada 2005 extension", Loc
);
656 if No
(Ada_Version_Pragma
) then
657 Error_Msg
("\unit must be compiled with -gnat05 switch", Loc
);
659 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
660 Error_Msg
("\incompatible with Ada version set#", Loc
);
663 end Error_Msg_Ada_2005_Extension
;
665 --------------------------------
666 -- Error_Msg_Ada_2012_Feature --
667 --------------------------------
669 procedure Error_Msg_Ada_2012_Feature
(Feature
: String; Loc
: Source_Ptr
) is
671 if Ada_Version
< Ada_2012
then
672 Error_Msg
(Feature
& " is an Ada 2012 feature", Loc
);
674 if No
(Ada_Version_Pragma
) then
675 Error_Msg
("\unit must be compiled with -gnat2012 switch", Loc
);
677 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
678 Error_Msg
("\incompatible with Ada version set#", Loc
);
681 end Error_Msg_Ada_2012_Feature
;
683 --------------------------------
684 -- Error_Msg_Ada_2022_Feature --
685 --------------------------------
687 procedure Error_Msg_Ada_2022_Feature
(Feature
: String; Loc
: Source_Ptr
) is
689 if Ada_Version
< Ada_2022
then
690 Error_Msg
(Feature
& " is an Ada 2022 feature", Loc
);
692 if No
(Ada_Version_Pragma
) then
693 Error_Msg
("\unit must be compiled with -gnat2022 switch", Loc
);
695 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
696 Error_Msg
("\incompatible with Ada version set#", Loc
);
699 end Error_Msg_Ada_2022_Feature
;
705 procedure Error_Msg_AP
(Msg
: String) is
710 -- If we had saved the Scan_Ptr value after scanning the previous
711 -- token, then we would have exactly the right place for putting
712 -- the flag immediately at hand. However, that would add at least
713 -- two instructions to a Scan call *just* to service the possibility
714 -- of an Error_Msg_AP call. So instead we reconstruct that value.
716 -- We have two possibilities, start with Prev_Token_Ptr and skip over
717 -- the current token, which is made harder by the possibility that this
718 -- token may be in error, or start with Token_Ptr and work backwards.
719 -- We used to take the second approach, but it's hard because of
720 -- comments, and harder still because things that look like comments
721 -- can appear inside strings. So now we take the first approach.
723 -- Note: in the case where there is no previous token, Prev_Token_Ptr
724 -- is set to Source_First, which is a reasonable position for the
725 -- error flag in this situation.
727 S1
:= Prev_Token_Ptr
;
730 -- If the previous token is a string literal, we need a special approach
731 -- since there may be white space inside the literal and we don't want
732 -- to stop on that white space.
734 -- Note: since this is an error recovery issue anyway, it is not worth
735 -- worrying about special UTF_32 line terminator characters here.
737 if Prev_Token
= Tok_String_Literal
then
741 if Source
(S1
) = C
then
743 exit when Source
(S1
) /= C
;
744 elsif Source
(S1
) in Line_Terminator
then
749 -- Character literal also needs special handling
751 elsif Prev_Token
= Tok_Char_Literal
then
754 -- Otherwise we search forward for the end of the current token, marked
755 -- by a line terminator, white space, a comment symbol or if we bump
756 -- into the following token (i.e. the current token).
758 -- Again, it is not worth worrying about UTF_32 special line terminator
759 -- characters in this context, since this is only for error recovery.
762 while Source
(S1
) not in Line_Terminator
763 and then Source
(S1
) /= ' '
764 and then Source
(S1
) /= ASCII
.HT
765 and then (Source
(S1
) /= '-' or else Source
(S1
+ 1) /= '-')
766 and then S1
/= Token_Ptr
772 -- S1 is now set to the location for the flag
781 procedure Error_Msg_BC
(Msg
: String) is
783 -- If we are at end of file, post the flag after the previous token
785 if Token
= Tok_EOF
then
788 -- If we are at start of file, post the flag at the current token
790 elsif Token_Ptr
= Source_First
(Current_Source_File
) then
793 -- If the character before the current token is a space or a horizontal
794 -- tab, then we place the flag on this character (in the case of a tab
795 -- we would really like to place it in the "last" character of the tab
796 -- space, but that it too much trouble to worry about).
798 elsif Source
(Token_Ptr
- 1) = ' '
799 or else Source
(Token_Ptr
- 1) = ASCII
.HT
801 Error_Msg
(Msg
, Token_Ptr
- 1);
803 -- If there is no space or tab before the current token, then there is
804 -- no room to place the flag before the token, so we place it on the
805 -- token instead (this happens for example at the start of a line).
808 Error_Msg
(Msg
, Token_Ptr
);
816 procedure Error_Msg_CRT
(Feature
: String; N
: Node_Id
) is
818 if No_Run_Time_Mode
then
819 Error_Msg_N
('|' & Feature
& " not allowed in no run time mode", N
);
821 else pragma Assert
(Configurable_Run_Time_Mode
);
822 Error_Msg_N
('|' & Feature
& " not supported by configuration>", N
);
825 Configurable_Run_Time_Violations
:= Configurable_Run_Time_Violations
+ 1;
832 procedure Error_Msg_PT
(E
: Entity_Id
; Iface_Prim
: Entity_Id
) is
835 ("illegal overriding of subprogram inherited from interface", E
);
837 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
839 if Ekind
(E
) = E_Function
then
841 ("\first formal of & declared # must be of mode `IN` "
842 & "or access-to-constant", E
);
845 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
846 & "or access-to-variable", E
);
854 procedure Error_Msg_F
(Msg
: String; N
: Node_Id
) is
857 First_And_Last_Nodes
(N
, Fst
, Lst
);
858 Error_Msg_NEL
(Msg
, N
, N
,
859 To_Span
(Ptr
=> Sloc
(Fst
),
860 First
=> First_Sloc
(Fst
),
861 Last
=> Last_Sloc
(Lst
)));
868 procedure Error_Msg_FE
871 E
: Node_Or_Entity_Id
)
875 First_And_Last_Nodes
(N
, Fst
, Lst
);
876 Error_Msg_NEL
(Msg
, N
, E
,
877 To_Span
(Ptr
=> Sloc
(Fst
),
878 First
=> First_Sloc
(Fst
),
879 Last
=> Last_Sloc
(Lst
)));
882 ------------------------------
883 -- Error_Msg_GNAT_Extension --
884 ------------------------------
886 procedure Error_Msg_GNAT_Extension
889 Is_Core_Extension
: Boolean := False)
892 if (if Is_Core_Extension
893 then Core_Extensions_Allowed
894 else All_Extensions_Allowed
)
899 Error_Msg
(Extension
& " is a 'G'N'A'T-specific extension", Loc
);
901 if No
(Ada_Version_Pragma
) then
902 if Is_Core_Extension
then
904 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
905 "or use pragma Extensions_Allowed (On) '[or All_Extensions']",
909 ("\unit must be compiled with -gnatX0 " &
910 "or use pragma Extensions_Allowed (All_Extensions)", Loc
);
913 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
914 Error_Msg
("\incompatible with Ada version set#", Loc
);
915 if Is_Core_Extension
then
917 ("\must use pragma Extensions_Allowed (On)" &
918 " '[or All_Extensions']", Loc
);
921 ("\must use pragma Extensions_Allowed (All_Extensions)", Loc
);
924 end Error_Msg_GNAT_Extension
;
926 ------------------------
927 -- Error_Msg_Internal --
928 ------------------------
930 procedure Error_Msg_Internal
936 Sptr
: constant Source_Ptr
:= Span
.Ptr
;
937 Optr
: constant Source_Ptr
:= Opan
.Ptr
;
939 Next_Msg
: Error_Msg_Id
;
940 -- Pointer to next message at insertion point
942 Prev_Msg
: Error_Msg_Id
;
943 -- Pointer to previous message at insertion point
945 Temp_Msg
: Error_Msg_Id
;
948 -- Set if warning to be treated as error
950 procedure Handle_Serious_Error
;
951 -- Internal procedure to do all error message handling for a serious
952 -- error message, other than bumping the error counts and arranging
953 -- for the message to be output.
955 --------------------------
956 -- Handle_Serious_Error --
957 --------------------------
959 procedure Handle_Serious_Error
is
961 -- Turn off code generation if not done already
963 if Operating_Mode
= Generate_Code
then
964 Operating_Mode
:= Check_Semantics
;
965 Expander_Active
:= False;
968 -- Set the fatal error flag in the unit table unless we are in
969 -- Try_Semantics mode (in which case we set ignored mode if not
970 -- currently set. This stops the semantics from being performed
971 -- if we find a serious error. This is skipped if we are currently
972 -- dealing with the configuration pragma file.
974 if Current_Source_Unit
/= No_Unit
then
976 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Sptr
);
978 if Try_Semantics
then
979 if Fatal_Error
(U
) = None
then
980 Set_Fatal_Error
(U
, Error_Ignored
);
983 Set_Fatal_Error
(U
, Error_Detected
);
988 -- Disable warnings on unused use clauses and the like. Otherwise, an
989 -- error might hide a reference to an entity in a used package, so
990 -- after fixing the error, the use clause no longer looks like it was
993 Warnsw
.Check_Unreferenced
:= False;
994 Warnsw
.Check_Unreferenced_Formals
:= False;
995 end Handle_Serious_Error
;
997 -- Start of processing for Error_Msg_Internal
1000 -- Detect common mistake of prefixing or suffixing the message with a
1003 pragma Assert
(Msg
(Msg
'First) /= ' ' and then Msg
(Msg
'Last) /= ' ');
1005 if Raise_Exception_On_Error
/= 0 then
1006 raise Error_Msg_Exception
;
1009 Continuation
:= Msg_Cont
;
1010 Continuation_New_Line
:= False;
1011 Suppress_Message
:= False;
1012 Kill_Message
:= False;
1013 Set_Msg_Text
(Msg
, Sptr
);
1015 -- Kill continuation if parent message killed
1017 if Continuation
and Last_Killed
then
1021 -- Return without doing anything if message is suppressed
1024 and then not All_Errors_Mode
1025 and then not Is_Warning_Msg
1026 and then not Is_Unconditional_Msg
1028 if not Continuation
then
1029 Last_Killed
:= True;
1035 -- Return without doing anything if message is killed and this is not
1036 -- the first error message. The philosophy is that if we get a weird
1037 -- error message and we already have had a message, then we hope the
1038 -- weird message is a junk cascaded message
1041 and then not All_Errors_Mode
1042 and then Total_Errors_Detected
/= 0
1044 if not Continuation
then
1045 Last_Killed
:= True;
1053 -- Immediate return if info messages are suppressed
1055 if Info_Suppressed
then
1056 Cur_Msg
:= No_Error_Msg
;
1060 -- If the flag location is in the main extended source unit then for
1061 -- sure we want the message since it definitely belongs.
1063 if In_Extended_Main_Source_Unit
(Sptr
) then
1066 -- Keep info message if message text contains !!
1068 elsif Has_Double_Exclam
then
1071 -- Here is where we delete a message from a with'ed unit
1074 Cur_Msg
:= No_Error_Msg
;
1076 if not Continuation
then
1077 Last_Killed
:= True;
1085 -- Special check for warning message to see if it should be output
1087 if Is_Warning_Msg
then
1089 -- Immediate return if warning message and warnings are suppressed
1091 if Warnings_Suppressed
(Optr
) /= No_String
1093 Warnings_Suppressed
(Sptr
) /= No_String
1095 Cur_Msg
:= No_Error_Msg
;
1099 -- If the flag location is in the main extended source unit then for
1100 -- sure we want the warning since it definitely belongs.
1102 if In_Extended_Main_Source_Unit
(Sptr
) then
1105 -- If the main unit has not been read yet. The warning must be on
1106 -- a configuration file: gnat.adc or user-defined. This means we
1107 -- are not parsing the main unit yet, so skip following checks.
1109 elsif No
(Cunit
(Main_Unit
)) then
1112 -- If the flag location is not in the extended main source unit, then
1113 -- we want to eliminate the warning, unless it is in the extended
1114 -- main code unit and we want warnings on the instance.
1116 elsif In_Extended_Main_Code_Unit
(Sptr
) and then Warn_On_Instance
then
1119 -- Keep warning if debug flag G set
1121 elsif Debug_Flag_GG
then
1124 -- Keep warning if message text contains !!
1126 elsif Has_Double_Exclam
then
1129 -- Here is where we delete a warning from a with'ed unit
1132 Cur_Msg
:= No_Error_Msg
;
1134 if not Continuation
then
1135 Last_Killed
:= True;
1142 -- If message is to be ignored in special ignore message mode, this is
1143 -- where we do this special processing, bypassing message output.
1145 if Ignore_Errors_Enable
> 0 then
1146 if Is_Serious_Error
then
1147 Handle_Serious_Error
;
1153 -- If error message line length set, and this is a continuation message
1154 -- then all we do is to append the text to the text of the last message
1155 -- with a comma space separator (eliminating a possible (style) or
1158 if Error_Msg_Line_Length
/= 0 and then Continuation
then
1159 Cur_Msg
:= Errors
.Last
;
1162 Oldm
: String_Ptr
:= Errors
.Table
(Cur_Msg
).Text
;
1163 Newm
: String (1 .. Oldm
'Last + 2 + Msglen
);
1168 -- First copy old message to new one and free it
1170 Newm
(Oldm
'Range) := Oldm
.all;
1171 Newl
:= Oldm
'Length;
1174 -- Remove (style) or info: at start of message
1176 if Msglen
> 8 and then Msg_Buffer
(1 .. 8) = "(style) " then
1179 elsif Msglen
> 6 and then Msg_Buffer
(1 .. 6) = "info: " then
1186 -- Now deal with separation between messages. Normally this is
1187 -- simply comma space, but there are some special cases.
1189 -- If continuation new line, then put actual NL character in msg
1191 if Continuation_New_Line
then
1193 Newm
(Newl
) := ASCII
.LF
;
1195 -- If continuation message is enclosed in parentheses, then
1196 -- special treatment (don't need a comma, and we want to combine
1197 -- successive parenthetical remarks into a single one with
1198 -- separating commas).
1200 elsif Msg_Buffer
(M
) = '(' and then Msg_Buffer
(Msglen
) = ')' then
1202 -- Case where existing message ends in right paren, remove
1203 -- and separate parenthetical remarks with a comma.
1205 if Newm
(Newl
) = ')' then
1207 Msg_Buffer
(M
) := ' ';
1209 -- Case where we are adding new parenthetical comment
1216 -- Case where continuation not in parens and no new line
1219 Newm
(Newl
+ 1 .. Newl
+ 2) := ", ";
1223 -- Append new message
1225 Newm
(Newl
+ 1 .. Newl
+ Msglen
- M
+ 1) :=
1226 Msg_Buffer
(M
.. Msglen
);
1227 Newl
:= Newl
+ Msglen
- M
+ 1;
1228 Errors
.Table
(Cur_Msg
).Text
:= new String'(Newm (1 .. Newl));
1230 -- Update warning msg flag and message doc char if needed
1232 if Is_Warning_Msg then
1233 if not Errors.Table (Cur_Msg).Warn then
1234 Errors.Table (Cur_Msg).Warn := True;
1235 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1237 elsif Warning_Msg_Char /= " " then
1238 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1246 -- Warning, Style and Info attributes are mutually exclusive
1248 pragma Assert (Boolean'Pos (Is_Warning_Msg) + Boolean'Pos (Is_Info_Msg) +
1249 Boolean'Pos (Is_Style_Msg) <= 1);
1251 -- Here we build a new error object
1254 ((Text => new String'(Msg_Buffer
(1 .. Msglen
)),
1255 Next
=> No_Error_Msg
,
1256 Prev
=> No_Error_Msg
,
1259 Insertion_Sloc
=> (if Has_Insertion_Line
then Error_Msg_Sloc
1261 Sfile
=> Get_Source_File_Index
(Sptr
),
1262 Line
=> Get_Physical_Line_Number
(Sptr
),
1263 Col
=> Get_Column_Number
(Sptr
),
1264 Compile_Time_Pragma
=> Is_Compile_Time_Msg
,
1265 Warn
=> Is_Warning_Msg
,
1266 Info
=> Is_Info_Msg
,
1267 Check
=> Is_Check_Msg
,
1268 Warn_Err
=> False, -- reset below
1269 Warn_Chr
=> Warning_Msg_Char
,
1270 Warn_Runtime_Raise
=> Is_Runtime_Raise
,
1271 Style
=> Is_Style_Msg
,
1272 Serious
=> Is_Serious_Error
,
1273 Uncond
=> Is_Unconditional_Msg
,
1274 Msg_Cont
=> Continuation
,
1276 Cur_Msg
:= Errors
.Last
;
1278 -- Test if warning to be treated as error
1281 (Is_Warning_Msg
or Is_Style_Msg
)
1282 and then (Warning_Treated_As_Error
(Msg_Buffer
(1 .. Msglen
))
1284 Warning_Treated_As_Error
(Get_Warning_Tag
(Cur_Msg
)));
1286 -- Propagate Warn_Err to this message and preceding continuations.
1287 -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
1288 -- current continued message could have been escalated from warning to
1291 for J
in reverse 1 .. Errors
.Last
loop
1292 Errors
.Table
(J
).Warn_Err
:= Warn_Err
;
1293 Errors
.Table
(J
).Warn
:= Is_Warning_Msg
;
1294 Errors
.Table
(J
).Warn_Runtime_Raise
:= Is_Runtime_Raise
;
1295 exit when not Errors
.Table
(J
).Msg_Cont
;
1298 -- If immediate errors mode set, output error message now. Also output
1299 -- now if the -d1 debug flag is set (so node number message comes out
1300 -- just before actual error message)
1302 if Debug_Flag_OO
or else Debug_Flag_1
then
1305 (Errors
.Table
(Cur_Msg
).Line
, Errors
.Table
(Cur_Msg
).Sfile
, True);
1306 Temp_Msg
:= Cur_Msg
;
1307 Output_Error_Msgs
(Temp_Msg
);
1309 -- If not in immediate errors mode, then we insert the message in the
1310 -- error chain for later output by Finalize. The messages are sorted
1311 -- first by unit (main unit comes first), and within a unit by source
1312 -- location (earlier flag location first in the chain).
1315 -- First a quick check, does this belong at the very end of the chain
1316 -- of error messages. This saves a lot of time in the normal case if
1317 -- there are lots of messages.
1319 if Last_Error_Msg
/= No_Error_Msg
1320 and then Errors
.Table
(Cur_Msg
).Sfile
=
1321 Errors
.Table
(Last_Error_Msg
).Sfile
1322 and then (Sptr
> Errors
.Table
(Last_Error_Msg
).Sptr
.Ptr
1324 (Sptr
= Errors
.Table
(Last_Error_Msg
).Sptr
.Ptr
1326 Optr
> Errors
.Table
(Last_Error_Msg
).Optr
.Ptr
))
1328 Prev_Msg
:= Last_Error_Msg
;
1329 Next_Msg
:= No_Error_Msg
;
1331 -- Otherwise do a full sequential search for the insertion point
1334 Prev_Msg
:= No_Error_Msg
;
1335 Next_Msg
:= First_Error_Msg
;
1336 while Next_Msg
/= No_Error_Msg
loop
1338 Errors
.Table
(Cur_Msg
).Sfile
< Errors
.Table
(Next_Msg
).Sfile
;
1340 if Errors
.Table
(Cur_Msg
).Sfile
= Errors
.Table
(Next_Msg
).Sfile
1342 exit when Sptr
< Errors
.Table
(Next_Msg
).Sptr
.Ptr
1343 or else (Sptr
= Errors
.Table
(Next_Msg
).Sptr
.Ptr
1345 Optr
< Errors
.Table
(Next_Msg
).Optr
.Ptr
);
1348 Prev_Msg
:= Next_Msg
;
1349 Next_Msg
:= Errors
.Table
(Next_Msg
).Next
;
1353 -- Now we insert the new message in the error chain.
1355 -- The possible insertion point for the new message is after Prev_Msg
1356 -- and before Next_Msg. However, this is where we do a special check
1357 -- for redundant parsing messages, defined as messages posted on the
1358 -- same line. The idea here is that probably such messages are junk
1359 -- from the parser recovering. In full errors mode, we don't do this
1360 -- deletion, but otherwise such messages are discarded at this stage.
1362 if Prev_Msg
/= No_Error_Msg
1363 and then Errors
.Table
(Prev_Msg
).Line
=
1364 Errors
.Table
(Cur_Msg
).Line
1365 and then Errors
.Table
(Prev_Msg
).Sfile
=
1366 Errors
.Table
(Cur_Msg
).Sfile
1367 and then Compiler_State
= Parsing
1368 and then not All_Errors_Mode
1370 -- Don't delete unconditional messages and at this stage, don't
1371 -- delete continuation lines; we attempted to delete those earlier
1372 -- if the parent message was deleted.
1374 if not Errors
.Table
(Cur_Msg
).Uncond
1375 and then not Continuation
1377 -- Don't delete if prev msg is warning and new msg is an error.
1378 -- This is because we don't want a real error masked by a
1379 -- warning. In all other cases (that is parse errors for the
1380 -- same line that are not unconditional) we do delete the
1381 -- message. This helps to avoid junk extra messages from
1382 -- cascaded parsing errors
1384 if not (Errors
.Table
(Prev_Msg
).Warn
1386 Errors
.Table
(Prev_Msg
).Style
)
1388 (Errors
.Table
(Cur_Msg
).Warn
1390 Errors
.Table
(Cur_Msg
).Style
)
1392 -- All tests passed, delete the message by simply returning
1393 -- without any further processing.
1395 pragma Assert
(not Continuation
);
1397 Last_Killed
:= True;
1403 -- Come here if message is to be inserted in the error chain
1405 if not Continuation
then
1406 Last_Killed
:= False;
1409 if Prev_Msg
= No_Error_Msg
then
1410 First_Error_Msg
:= Cur_Msg
;
1412 Errors
.Table
(Prev_Msg
).Next
:= Cur_Msg
;
1415 Errors
.Table
(Cur_Msg
).Next
:= Next_Msg
;
1417 if Next_Msg
= No_Error_Msg
then
1418 Last_Error_Msg
:= Cur_Msg
;
1422 -- Bump appropriate statistics counts
1424 if Errors
.Table
(Cur_Msg
).Info
then
1425 Info_Messages
:= Info_Messages
+ 1;
1427 elsif Errors
.Table
(Cur_Msg
).Warn
1428 or else Errors
.Table
(Cur_Msg
).Style
1430 Warnings_Detected
:= Warnings_Detected
+ 1;
1432 elsif Errors
.Table
(Cur_Msg
).Check
then
1433 Check_Messages
:= Check_Messages
+ 1;
1436 Total_Errors_Detected
:= Total_Errors_Detected
+ 1;
1438 if Errors
.Table
(Cur_Msg
).Serious
then
1439 Serious_Errors_Detected
:= Serious_Errors_Detected
+ 1;
1440 Handle_Serious_Error
;
1442 -- If not serious error, set Fatal_Error to indicate ignored error
1446 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Sptr
);
1448 if Fatal_Error
(U
) = None
then
1449 Set_Fatal_Error
(U
, Error_Ignored
);
1455 -- Record warning message issued
1457 if Errors
.Table
(Cur_Msg
).Warn
1458 and then not Errors
.Table
(Cur_Msg
).Msg_Cont
1460 Warning_Msg
:= Cur_Msg
;
1463 -- If too many warnings turn off warnings
1465 if Maximum_Messages
/= 0 then
1466 if Warnings_Detected
= Maximum_Messages
then
1467 Warning_Mode
:= Suppress
;
1470 -- If too many errors abandon compilation
1472 if Total_Errors_Detected
= Maximum_Messages
then
1473 raise Unrecoverable_Error
;
1477 if Has_Error_Code
then
1479 Msg
: constant String :=
1480 "\launch ""gnatprove --explain=[]"" for more information";
1482 Has_Double_Exclam
:= False;
1483 Has_Error_Code
:= False;
1484 Has_Insertion_Line
:= False;
1493 end Error_Msg_Internal
;
1499 procedure Error_Msg_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
1502 First_And_Last_Nodes
(N
, Fst
, Lst
);
1503 Error_Msg_NEL
(Msg
, N
, N
,
1504 To_Span
(Ptr
=> Sloc
(N
),
1505 First
=> First_Sloc
(Fst
),
1506 Last
=> Last_Sloc
(Lst
)));
1513 procedure Error_Msg_NE
1515 N
: Node_Or_Entity_Id
;
1516 E
: Node_Or_Entity_Id
)
1520 First_And_Last_Nodes
(N
, Fst
, Lst
);
1521 Error_Msg_NEL
(Msg
, N
, E
,
1522 To_Span
(Ptr
=> Sloc
(N
),
1523 First
=> First_Sloc
(Fst
),
1524 Last
=> Last_Sloc
(Lst
)));
1531 procedure Error_Msg_NEL
1533 N
: Node_Or_Entity_Id
;
1534 E
: Node_Or_Entity_Id
;
1535 Flag_Location
: Source_Ptr
)
1539 First_And_Last_Nodes
(N
, Fst
, Lst
);
1542 To_Span
(Ptr
=> Flag_Location
,
1543 First
=> Source_Ptr
'Min (Flag_Location
, First_Sloc
(Fst
)),
1544 Last
=> Source_Ptr
'Max (Flag_Location
, Last_Sloc
(Lst
))));
1547 procedure Error_Msg_NEL
1549 N
: Node_Or_Entity_Id
;
1550 E
: Node_Or_Entity_Id
;
1551 Flag_Span
: Source_Span
)
1554 if Special_Msg_Delete
(Msg
, N
, E
) then
1558 Prescan_Message
(Msg
);
1560 -- Special handling for warning messages
1562 if Is_Warning_Msg
then
1564 -- Suppress if no warnings set for either entity or node
1566 if No_Warnings
(N
) or else No_Warnings
(E
) then
1568 -- Disable any continuation messages as well
1570 Last_Killed
:= True;
1575 -- Test for message to be output
1578 or else Is_Unconditional_Msg
1579 or else Is_Warning_Msg
1581 or else (Msg
(Msg
'First) = '\' and then not Last_Killed
)
1584 Error_Msg_Node_1
:= E
;
1585 Error_Msg
(Msg
, Flag_Span
, N
);
1588 Last_Killed
:= True;
1591 if not Get_Ignore_Errors
then
1600 procedure Error_Msg_NW
1603 N
: Node_Or_Entity_Id
)
1608 and then In_Extended_Main_Source_Unit
(N
)
1609 and then Comes_From_Source
(N
)
1611 First_And_Last_Nodes
(N
, Fst
, Lst
);
1612 Error_Msg_NEL
(Msg
, N
, N
,
1613 To_Span
(Ptr
=> Sloc
(N
),
1614 First
=> First_Sloc
(Fst
),
1615 Last
=> Last_Sloc
(Lst
)));
1623 procedure Error_Msg_S
(Msg
: String) is
1625 Error_Msg
(Msg
, Scan_Ptr
);
1632 procedure Error_Msg_SC
(Msg
: String) is
1634 -- If we are at end of file, post the flag after the previous token
1636 if Token
= Tok_EOF
then
1639 -- For all other cases the message is posted at the current token
1643 Error_Msg
(Msg
, Token_Ptr
);
1651 procedure Error_Msg_SP
(Msg
: String) is
1653 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1654 -- is set to Source_First, which is a reasonable position for the
1655 -- error flag in this situation
1657 Error_Msg
(Msg
, Prev_Token_Ptr
);
1664 procedure Finalize
(Last_Call
: Boolean) is
1669 procedure Delete_Warning
(E
: Error_Msg_Id
);
1670 -- Delete a warning msg if not already deleted and adjust warning count
1672 --------------------
1673 -- Delete_Warning --
1674 --------------------
1676 procedure Delete_Warning
(E
: Error_Msg_Id
) is
1678 if not Errors
.Table
(E
).Deleted
then
1679 Errors
.Table
(E
).Deleted
:= True;
1680 Warnings_Detected
:= Warnings_Detected
- 1;
1684 -- Start of processing for Finalize
1687 -- Set Prev pointers
1689 Cur
:= First_Error_Msg
;
1690 while Cur
/= No_Error_Msg
loop
1691 Nxt
:= Errors
.Table
(Cur
).Next
;
1692 exit when Nxt
= No_Error_Msg
;
1693 Errors
.Table
(Nxt
).Prev
:= Cur
;
1697 -- Eliminate any duplicated error messages from the list. This is
1698 -- done after the fact to avoid problems with Change_Error_Text.
1700 Cur
:= First_Error_Msg
;
1701 while Cur
/= No_Error_Msg
loop
1702 Nxt
:= Errors
.Table
(Cur
).Next
;
1705 while F
/= No_Error_Msg
1706 and then Errors
.Table
(F
).Sptr
.Ptr
= Errors
.Table
(Cur
).Sptr
.Ptr
1708 Check_Duplicate_Message
(Cur
, F
);
1709 F
:= Errors
.Table
(F
).Next
;
1715 -- Mark any messages suppressed by specific warnings as Deleted
1717 Cur
:= First_Error_Msg
;
1718 while Cur
/= No_Error_Msg
loop
1720 CE
: Error_Msg_Object
renames Errors
.Table
(Cur
);
1721 Tag
: constant String := Get_Warning_Tag
(Cur
);
1725 and then not CE
.Deleted
1727 (Warning_Specifically_Suppressed
(CE
.Sptr
.Ptr
, CE
.Text
, Tag
)
1730 Warning_Specifically_Suppressed
(CE
.Optr
.Ptr
, CE
.Text
, Tag
)
1733 Delete_Warning
(Cur
);
1735 -- If this is a continuation, delete previous parts of message
1738 while Errors
.Table
(F
).Msg_Cont
loop
1739 F
:= Errors
.Table
(F
).Prev
;
1740 exit when F
= No_Error_Msg
;
1744 -- Delete any following continuations
1748 F
:= Errors
.Table
(F
).Next
;
1749 exit when F
= No_Error_Msg
;
1750 exit when not Errors
.Table
(F
).Msg_Cont
;
1756 Cur
:= Errors
.Table
(Cur
).Next
;
1759 Finalize_Called
:= True;
1761 -- Check consistency of specific warnings (may add warnings). We only
1762 -- do this on the last call, after all possible warnings are posted.
1765 Validate_Specific_Warnings
;
1773 function First_Node
(C
: Node_Id
) return Node_Id
is
1776 First_And_Last_Nodes
(C
, Fst
, Lst
);
1780 --------------------------
1781 -- First_And_Last_Nodes --
1782 --------------------------
1784 procedure First_And_Last_Nodes
1786 First_Node
, Last_Node
: out Node_Id
)
1788 Orig
: constant Node_Id
:= Original_Node
(C
);
1789 Loc
: constant Source_Ptr
:= Sloc
(Orig
);
1790 Sfile
: constant Source_File_Index
:= Get_Source_File_Index
(Loc
);
1796 function Test_First_And_Last
(N
: Node_Id
) return Traverse_Result
;
1797 -- Function applied to every node in the construct
1799 procedure Search_Tree_First_And_Last
is new
1800 Traverse_Proc
(Test_First_And_Last
);
1801 -- Create traversal procedure
1803 -------------------------
1804 -- Test_First_And_Last --
1805 -------------------------
1807 function Test_First_And_Last
(N
: Node_Id
) return Traverse_Result
is
1808 Norig
: constant Node_Id
:= Original_Node
(N
);
1809 Loc
: constant Source_Ptr
:= Sloc
(Norig
);
1812 -- ??? For assignments that require accessiblity checks, e.g.:
1816 -- the function call gets an extra actual parameter association with
1817 -- Sloc of the assigned name "Y":
1819 -- Y := Func (123, A8b => 2);
1821 -- We can simply ignore those extra actual parameters when
1822 -- determining the Sloc range of the "Func (123)" expression.
1824 if Nkind
(N
) = N_Parameter_Association
1825 and then Is_Accessibility_Actual
(N
)
1830 -- Check for earlier
1834 -- Ignore nodes with no useful location information
1836 and then Loc
/= Standard_Location
1837 and then Loc
/= No_Location
1839 -- Ignore nodes from a different file. This ensures against cases
1840 -- of strange foreign code somehow being present. We don't want
1841 -- wild placement of messages if that happens.
1843 and then Get_Source_File_Index
(Loc
) = Sfile
1853 -- Ignore nodes with no useful location information
1855 and then Loc
/= Standard_Location
1856 and then Loc
/= No_Location
1858 -- Ignore nodes from a different file. This ensures against cases
1859 -- of strange foreign code somehow being present. We don't want
1860 -- wild placement of messages if that happens.
1862 and then Get_Source_File_Index
(Loc
) = Sfile
1869 end Test_First_And_Last
;
1871 -- Start of processing for First_And_Last_Nodes
1874 if Nkind
(Orig
) in N_Subexpr
1876 | N_Access_To_Subprogram_Definition
1877 | N_Generic_Instantiation
1879 | N_Use_Package_Clause
1880 | N_Array_Type_Definition
1881 | N_Renaming_Declaration
1882 | N_Generic_Renaming_Declaration
1883 | N_Assignment_Statement
1885 | N_Simple_Return_Statement
1890 | N_Attribute_Definition_Clause
1891 | N_Subtype_Indication
1897 Search_Tree_First_And_Last
(Orig
);
1898 First_Node
:= Earliest
;
1899 Last_Node
:= Latest
;
1905 end First_And_Last_Nodes
;
1911 function First_Sloc
(N
: Node_Id
) return Source_Ptr
is
1912 SI
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
1913 SF
: constant Source_Ptr
:= Source_First
(SI
);
1914 SL
: constant Source_Ptr
:= Source_Last
(SI
);
1915 Src
: constant Source_Buffer_Ptr
:= Source_Text
(SI
);
1920 F
:= First_Node
(N
);
1923 if S
not in SF
.. SL
then
1927 -- The following circuit is a bit subtle. When we have parenthesized
1928 -- expressions, then the Sloc will not record the location of the paren,
1929 -- but we would like to post the flag on the paren. So what we do is to
1930 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1931 -- any parentheses we know are present. Yes, we know this circuit is not
1932 -- 100% reliable (e.g. because we don't record all possible paren level
1933 -- values), but this is only for an error message so it is good enough.
1936 -- Include parentheses around the top node, except when they are
1937 -- required by the syntax of the parent node.
1939 exit Node_Loop
when F
= N
1940 and then Paren_Required
(N
);
1942 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
1944 -- We don't look more than 12 characters behind the current
1945 -- location, and in any case not past the front of the source.
1947 Search_Loop
: for K
in 1 .. 12 loop
1948 exit Search_Loop
when S
= SF
;
1950 if Src
(S
- 1) = '(' then
1954 elsif Src
(S
- 1) <= ' ' then
1960 end loop Search_Loop
;
1961 end loop Paren_Loop
;
1963 exit Node_Loop
when F
= N
;
1965 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
1971 -----------------------
1972 -- Get_Ignore_Errors --
1973 -----------------------
1975 function Get_Ignore_Errors
return Boolean is
1977 return Errors_Must_Be_Ignored
;
1978 end Get_Ignore_Errors
;
1984 procedure Initialize
is
1987 First_Error_Msg
:= No_Error_Msg
;
1988 Last_Error_Msg
:= No_Error_Msg
;
1989 Serious_Errors_Detected
:= 0;
1990 Total_Errors_Detected
:= 0;
1991 Cur_Msg
:= No_Error_Msg
;
1994 -- Reset counts for warnings
1996 Warnings_Treated_As_Errors
:= 0;
1997 Warnings_Detected
:= 0;
1998 Warnings_As_Errors_Count
:= 0;
2000 -- Initialize warnings tables
2003 Specific_Warnings
.Init
;
2006 -------------------------------
2007 -- Is_Size_Too_Small_Message --
2008 -------------------------------
2010 function Is_Size_Too_Small_Message
(S
: String) return Boolean is
2011 Size_For
: constant String := "size for";
2012 pragma Assert
(Size_Too_Small_Message
(1 .. Size_For
'Last) = Size_For
);
2013 -- Assert that Size_Too_Small_Message starts with Size_For
2015 return S
'Length >= Size_For
'Length
2016 and then S
(S
'First .. S
'First + Size_For
'Length - 1) = Size_For
;
2017 -- True if S starts with Size_For
2018 end Is_Size_Too_Small_Message
;
2020 --------------------------------
2021 -- Validate_Specific_Warnings --
2022 --------------------------------
2024 procedure Validate_Specific_Warnings
is
2026 if not Warnsw
.Warn_On_Warnings_Off
then
2030 for J
in Specific_Warnings
.First
.. Specific_Warnings
.Last
loop
2032 SWE
: Specific_Warning_Entry
renames Specific_Warnings
.Table
(J
);
2035 if not SWE
.Config
then
2037 -- Warn for unmatched Warnings (Off, ...)
2041 ("?.w?pragma Warnings Off with no matching Warnings On",
2044 -- Warn for ineffective Warnings (Off, ..)
2048 -- Do not issue this warning for -Wxxx messages since the
2049 -- back-end doesn't report the information. Note that there
2050 -- is always an asterisk at the start of every message.
2053 (SWE
.Msg
'Length > 3 and then SWE
.Msg
(2 .. 3) = "-W")
2056 ("?.w?no warning suppressed by this pragma",
2062 end Validate_Specific_Warnings
;
2068 function Last_Node
(C
: Node_Id
) return Node_Id
is
2071 First_And_Last_Nodes
(C
, Fst
, Lst
);
2079 function Last_Sloc
(N
: Node_Id
) return Source_Ptr
is
2080 procedure Skip_Char
(S
: in out Source_Ptr
);
2081 -- Skip one character of the source buffer at location S
2087 procedure Skip_Char
(S
: in out Source_Ptr
) is
2094 SI
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
2095 SF
: constant Source_Ptr
:= Source_First
(SI
);
2096 SL
: constant Source_Ptr
:= Source_Last
(SI
);
2097 Src
: constant Source_Buffer_Ptr
:= Source_Text
(SI
);
2101 -- Start of processing for Last_Sloc
2107 if S
not in SF
.. SL
then
2111 -- For string and character literals simply forward the sloc by their
2112 -- length including the closing quotes. Perhaps we should do something
2113 -- special for multibyte characters, but this code is only used to emit
2114 -- error messages, so it is not worth the effort.
2117 when N_String_Literal
=>
2118 return S
+ Source_Ptr
(String_Length
(Strval
(F
))) + 1;
2120 when N_Character_Literal
=>
2123 -- Skip past integer literals, both decimal and based, integer and
2124 -- real. We can't greedily accept all allowed character, because
2125 -- we would consme too many of them in expressions like "123+ABC"
2126 -- or "123..456", so we follow quite precisely the Ada grammar and
2127 -- consume different characters depending on the context.
2129 when N_Integer_Literal
=>
2131 -- Skip past the initial numeral, which either leads the decimal
2132 -- literal or is the base of a based literal.
2135 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2140 -- Skip past #based_numeral#, if present
2143 and then Src
(S
+ 1) = '#'
2149 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2155 and then Src
(S
+ 1) = '#'
2161 -- Skip past exponent, if present
2164 and then Src
(S
+ 1) in 'e' |
'E'
2168 -- For positive exponents the plus sign is optional, but we
2169 -- can simply skip past both plus and minus.
2172 and then Src
(S
+ 1) in '+' |
'-'
2177 -- Skip past the numeral part
2180 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2186 when N_Real_Literal
=>
2187 -- Skip past the initial numeral, which either leads the decimal
2188 -- literal or is the base of a based literal.
2191 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2198 -- Skip the dot and continue with a decimal literal
2200 if Src
(S
+ 1) = '.' then
2204 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2209 -- Skip the hash and continue with a based literal
2211 elsif Src
(S
+ 1) = '#' then
2216 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2222 and then Src
(S
+ 1) = '.'
2229 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2235 and then Src
(S
+ 1) = '#'
2242 -- Skip past exponent, if present
2245 and then Src
(S
+ 1) in 'e' |
'E'
2248 -- For positive exponents the plus sign is optional, but we
2249 -- can simply skip past both plus and minus.
2251 if Src
(S
+ 1) in '+' |
'-' then
2255 -- Skip past the numeral part
2258 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2264 -- For other nodes simply skip past a keyword/identifier
2267 while S
in SF
.. SL
- 1
2268 and then Src
(S
+ 1)
2270 '0' .. '9' |
'a' .. 'z' |
'A' .. 'Z' |
'_'
2276 -- The following circuit attempts at crawling up the tree from the
2277 -- Last_Node, adjusting the Sloc value for any parentheses we know
2278 -- are present, similarly to what is done in First_Sloc.
2281 -- Include parentheses around the top node, except when they are
2282 -- required by the syntax of the parent node.
2284 exit Node_Loop
when F
= N
2285 and then Paren_Required
(N
);
2287 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
2289 -- We don't look more than 12 characters after the current
2292 Search_Loop
: for K
in 1 .. 12 loop
2293 exit Node_Loop
when S
= SL
;
2295 if Src
(S
+ 1) = ')' then
2299 elsif Src
(S
+ 1) <= ' ' then
2305 end loop Search_Loop
;
2306 end loop Paren_Loop
;
2308 exit Node_Loop
when F
= N
;
2310 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
2313 -- Remove any trailing space
2315 while S
in SF
+ 1 .. SL
2316 and then Src
(S
) = ' '
2328 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean is
2330 if Error_Posted
(N
) then
2333 elsif Nkind
(N
) in N_Entity
and then Has_Warnings_Off
(N
) then
2336 elsif Is_Entity_Name
(N
)
2337 and then Present
(Entity
(N
))
2338 and then Has_Warnings_Off
(Entity
(N
))
2351 function OK_Node
(N
: Node_Id
) return Boolean is
2352 K
: constant Node_Kind
:= Nkind
(N
);
2355 if Error_Posted
(N
) then
2358 elsif K
in N_Has_Etype
2359 and then Present
(Etype
(N
))
2360 and then Error_Posted
(Etype
(N
))
2365 or else K
= N_Attribute_Reference
2366 or else K
= N_Character_Literal
2367 or else K
= N_Expanded_Name
2368 or else K
= N_Identifier
2369 or else K
= N_Operator_Symbol
)
2370 and then Present
(Entity
(N
))
2371 and then Error_Posted
(Entity
(N
))
2379 -------------------------
2380 -- Output_JSON_Message --
2381 -------------------------
2383 procedure Output_JSON_Message
(Error_Id
: Error_Msg_Id
) is
2385 function Is_Continuation
(E
: Error_Msg_Id
) return Boolean;
2386 -- Return True if E is a continuation message.
2388 procedure Write_JSON_Escaped_String
(Str
: String_Ptr
);
2389 procedure Write_JSON_Escaped_String
(Str
: String);
2390 -- Write each character of Str, taking care of preceding each quote and
2391 -- backslash with a backslash. Note that this escaping differs from what
2394 -- Indeed, the JSON specification mandates encoding wide characters
2395 -- either as their direct UTF-8 representation or as their escaped
2396 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2397 -- we choose to use the UTF-8 representation instead.
2399 procedure Write_JSON_Location
(Sptr
: Source_Ptr
);
2400 -- Write Sptr as a JSON location, an object containing a file attribute,
2401 -- a line number and a column number.
2403 procedure Write_JSON_Span
(Error
: Error_Msg_Object
);
2404 -- Write Error as a JSON span, an object containing a "caret" attribute
2405 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2406 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2407 -- locations under the names "start" and "finish".
2409 -----------------------
2410 -- Is_Continuation --
2411 -----------------------
2413 function Is_Continuation
(E
: Error_Msg_Id
) return Boolean is
2415 return E
<= Last_Error_Msg
and then Errors
.Table
(E
).Msg_Cont
;
2416 end Is_Continuation
;
2418 -------------------------------
2419 -- Write_JSON_Escaped_String --
2420 -------------------------------
2422 procedure Write_JSON_Escaped_String
(Str
: String) is
2425 if C
= '"' or else C
= '\' then
2431 end Write_JSON_Escaped_String
;
2433 -------------------------------
2434 -- Write_JSON_Escaped_String --
2435 -------------------------------
2437 procedure Write_JSON_Escaped_String
(Str
: String_Ptr
) is
2439 Write_JSON_Escaped_String
(Str
.all);
2440 end Write_JSON_Escaped_String
;
2442 -------------------------
2443 -- Write_JSON_Location --
2444 -------------------------
2446 procedure Write_JSON_Location
(Sptr
: Source_Ptr
) is
2447 Name
: constant File_Name_Type
:=
2448 Full_Ref_Name
(Get_Source_File_Index
(Sptr
));
2450 Write_Str
("{""file"":""");
2451 if Full_Path_Name_For_Brief_Errors
then
2452 Write_JSON_Escaped_String
2453 (System
.OS_Lib
.Normalize_Pathname
(Get_Name_String
(Name
)));
2457 Write_Str
(""",""line"":");
2458 Write_Int
(Pos
(Get_Physical_Line_Number
(Sptr
)));
2459 Write_Str
(", ""column"":");
2460 Write_Int
(Nat
(Get_Column_Number
(Sptr
)));
2462 end Write_JSON_Location
;
2464 ---------------------
2465 -- Write_JSON_Span --
2466 ---------------------
2468 procedure Write_JSON_Span
(Error
: Error_Msg_Object
) is
2469 Span
: constant Source_Span
:= Error
.Sptr
;
2471 Write_Str
("{""caret"":");
2472 Write_JSON_Location
(Span
.Ptr
);
2474 if Span
.Ptr
/= Span
.First
then
2475 Write_Str
(",""start"":");
2476 Write_JSON_Location
(Span
.First
);
2479 if Span
.Ptr
/= Span
.Last
then
2480 Write_Str
(",""finish"":");
2481 Write_JSON_Location
(Span
.Last
);
2485 end Write_JSON_Span
;
2489 E
: Error_Msg_Id
:= Error_Id
;
2491 Print_Continuations
: constant Boolean := not Is_Continuation
(E
);
2492 -- Do not print continuations messages as children of the current
2493 -- message if the current message is a continuation message.
2495 Option
: constant String := Get_Warning_Option
(E
);
2496 -- The option that triggered this message.
2498 -- Start of processing for Output_JSON_Message
2501 -- Print message kind
2503 Write_Str
("{""kind"":");
2505 if Errors
.Table
(E
).Warn
and then not Errors
.Table
(E
).Warn_Err
then
2506 Write_Str
("""warning""");
2507 elsif Errors
.Table
(E
).Info
or else Errors
.Table
(E
).Check
then
2508 Write_Str
("""note""");
2510 Write_Str
("""error""");
2513 -- Print message location
2515 Write_Str
(",""locations"":[");
2516 Write_JSON_Span
(Errors
.Table
(E
));
2518 if Errors
.Table
(E
).Optr
.Ptr
/= Errors
.Table
(E
).Sptr
.Ptr
then
2519 Write_Str
(",{""caret"":");
2520 Write_JSON_Location
(Errors
.Table
(E
).Optr
.Ptr
);
2526 -- Print message option, if there is one
2527 if Option
/= "" then
2528 Write_Str
(",""option"":""" & Option
& """");
2531 -- Print message content
2533 Write_Str
(",""message"":""");
2534 Write_JSON_Escaped_String
(Errors
.Table
(E
).Text
);
2539 if Print_Continuations
and then Is_Continuation
(E
) then
2541 Write_Str
(",""children"": [");
2542 Output_JSON_Message
(E
);
2545 while Is_Continuation
(E
) loop
2547 Output_JSON_Message
(E
);
2556 end Output_JSON_Message
;
2558 ---------------------
2559 -- Output_Messages --
2560 ---------------------
2562 procedure Output_Messages
is
2564 -- Local subprograms
2566 procedure Write_Error_Summary
;
2567 -- Write error summary
2569 procedure Write_Header
(Sfile
: Source_File_Index
);
2570 -- Write header line (compiling or checking given file)
2572 procedure Write_Max_Errors
;
2573 -- Write message if max errors reached
2575 procedure Write_Source_Code_Lines
2576 (Span
: Source_Span
;
2578 -- Write the source code line corresponding to Span, as follows when
2579 -- Span in on one line:
2581 -- line | actual code line here with Span somewhere
2584 -- where the caret on the line points to location Span.Ptr, and the
2585 -- range Span.First..Span.Last is underlined.
2587 -- or when the span is over multiple lines:
2589 -- line | beginning of the Span on this line
2591 -- line>| actual code line here with Span.Ptr somewhere
2593 -- line | end of the Span on this line
2595 -- or when the span is a simple location, as follows:
2597 -- line | actual code line here with Span somewhere
2600 -- where the caret on the line points to location Span.Ptr
2602 -- SGR_Span is the SGR string to start the section of code in the span,
2603 -- that should be closed with SGR_Reset.
2605 -------------------------
2606 -- Write_Error_Summary --
2607 -------------------------
2609 procedure Write_Error_Summary
is
2611 -- Extra blank line if error messages or source listing were output
2613 if Total_Errors_Detected
+ Warnings_Detected
> 0 or else Full_List
2618 -- Message giving number of lines read and number of errors detected.
2619 -- This normally goes to Standard_Output. The exception is when brief
2620 -- mode is not set, verbose mode (or full list mode) is set, and
2621 -- there are errors. In this case we send the message to standard
2622 -- error to make sure that *something* appears on standard error
2623 -- in an error situation.
2625 if Total_Errors_Detected
+ Warnings_Detected
/= 0
2626 and then not Brief_Output
2627 and then (Verbose_Mode
or Full_List
)
2632 -- Message giving total number of lines. Don't give this message if
2633 -- the Main_Source line is unknown (this happens in error situations,
2634 -- e.g. when integrated preprocessing fails).
2636 if Main_Source_File
> No_Source_File
then
2638 Write_Int
(Num_Source_Lines
(Main_Source_File
));
2640 if Num_Source_Lines
(Main_Source_File
) = 1 then
2641 Write_Str
(" line: ");
2643 Write_Str
(" lines: ");
2647 if Total_Errors_Detected
= 0 then
2648 Write_Str
("No errors");
2650 elsif Total_Errors_Detected
= 1 then
2651 Write_Str
("1 error");
2654 Write_Int
(Total_Errors_Detected
);
2655 Write_Str
(" errors");
2658 -- We now need to output warnings. When using -gnatwe, all warnings
2659 -- should be treated as errors, except for warnings originating from
2660 -- the use of the Compile_Time_Warning pragma. Another situation
2661 -- where a warning might be treated as an error is when the source
2662 -- code contains a Warning_As_Error pragma.
2663 -- When warnings are treated as errors, we still log them as
2664 -- warnings, but we add a message denoting how many of these warnings
2668 Warnings_Count
: constant Int
:= Warnings_Detected
;
2670 Compile_Time_Warnings
: Int
;
2671 -- Number of warnings that come from a Compile_Time_Warning
2674 Non_Compile_Time_Warnings
: Int
;
2675 -- Number of warnings that do not come from a Compile_Time_Warning
2679 if Warnings_Count
> 0 then
2681 Write_Int
(Warnings_Count
);
2682 Write_Str
(" warning");
2684 if Warnings_Count
> 1 then
2688 Compile_Time_Warnings
:= Count_Compile_Time_Pragma_Warnings
;
2689 Non_Compile_Time_Warnings
:=
2690 Warnings_Count
- Compile_Time_Warnings
;
2692 if Warning_Mode
= Treat_As_Error
2693 and then Non_Compile_Time_Warnings
> 0
2697 if Compile_Time_Warnings
> 0 then
2698 Write_Int
(Non_Compile_Time_Warnings
);
2702 Write_Str
("treated as error");
2704 if Non_Compile_Time_Warnings
> 1 then
2710 elsif Warnings_Treated_As_Errors
> 0 then
2713 if Warnings_Treated_As_Errors
/= Warnings_Count
then
2714 Write_Int
(Warnings_Treated_As_Errors
);
2718 Write_Str
("treated as error");
2720 if Warnings_Treated_As_Errors
> 1 then
2729 if Info_Messages
/= 0 then
2731 Write_Int
(Info_Messages
);
2732 Write_Str
(" info message");
2734 if Info_Messages
> 1 then
2740 Set_Standard_Output
;
2741 end Write_Error_Summary
;
2747 procedure Write_Header
(Sfile
: Source_File_Index
) is
2749 if Verbose_Mode
or Full_List
then
2750 if Original_Operating_Mode
= Generate_Code
then
2751 Write_Str
("Compiling: ");
2753 Write_Str
("Checking: ");
2756 Write_Name
(Full_File_Name
(Sfile
));
2758 if not Debug_Flag_7
then
2760 Write_Str
("Source file time stamp: ");
2761 Write_Time_Stamp
(Sfile
);
2763 Write_Str
("Compiled at: " & Compilation_Time
);
2770 ----------------------
2771 -- Write_Max_Errors --
2772 ----------------------
2774 procedure Write_Max_Errors
is
2776 if Maximum_Messages
/= 0 then
2777 if Warnings_Detected
>= Maximum_Messages
then
2779 Write_Line
("maximum number of warnings output");
2780 Write_Line
("any further warnings suppressed");
2781 Set_Standard_Output
;
2784 -- If too many errors print message
2786 if Total_Errors_Detected
>= Maximum_Messages
then
2788 Write_Line
("fatal error: maximum number of errors detected");
2789 Set_Standard_Output
;
2792 end Write_Max_Errors
;
2794 -----------------------------
2795 -- Write_Source_Code_Lines --
2796 -----------------------------
2798 procedure Write_Source_Code_Lines
2799 (Span
: Source_Span
;
2802 function Get_Line_End
2803 (Buf
: Source_Buffer_Ptr
;
2804 Loc
: Source_Ptr
) return Source_Ptr
;
2805 -- Get the source location for the end of the line in Buf for Loc. If
2806 -- Loc is past the end of Buf already, return Buf'Last.
2808 function Get_Line_Start
2809 (Buf
: Source_Buffer_Ptr
;
2810 Loc
: Source_Ptr
) return Source_Ptr
;
2811 -- Get the source location for the start of the line in Buf for Loc
2813 function Image
(X
: Positive; Width
: Positive) return String;
2814 -- Output number X over Width characters, with whitespace padding.
2815 -- Only output the low-order Width digits of X, if X is larger than
2818 procedure Write_Buffer
2819 (Buf
: Source_Buffer_Ptr
;
2822 -- Output the characters from First to Last position in Buf, using
2823 -- Write_Buffer_Char.
2825 procedure Write_Buffer_Char
2826 (Buf
: Source_Buffer_Ptr
;
2828 -- Output the characters at position Loc in Buf, translating ASCII.HT
2829 -- in a suitable number of spaces so that the output is not modified
2830 -- by starting in a different column that 1.
2832 procedure Write_Line_Marker
2836 -- Output the line number Num over Width characters, with possibly
2837 -- a Mark to denote the line with the main location when reporting
2838 -- a span over multiple lines.
2844 function Get_Line_End
2845 (Buf
: Source_Buffer_Ptr
;
2846 Loc
: Source_Ptr
) return Source_Ptr
2848 Cur_Loc
: Source_Ptr
:= Source_Ptr
'Min (Loc
, Buf
'Last);
2850 while Cur_Loc
< Buf
'Last
2851 and then Buf
(Cur_Loc
) /= ASCII
.LF
2853 Cur_Loc
:= Cur_Loc
+ 1;
2859 --------------------
2860 -- Get_Line_Start --
2861 --------------------
2863 function Get_Line_Start
2864 (Buf
: Source_Buffer_Ptr
;
2865 Loc
: Source_Ptr
) return Source_Ptr
2867 Cur_Loc
: Source_Ptr
:= Loc
;
2869 while Cur_Loc
> Buf
'First
2870 and then Buf
(Cur_Loc
- 1) /= ASCII
.LF
2872 Cur_Loc
:= Cur_Loc
- 1;
2882 function Image
(X
: Positive; Width
: Positive) return String is
2883 Str
: String (1 .. Width
);
2884 Curr
: Natural := X
;
2886 for J
in reverse 1 .. Width
loop
2888 Str
(J
) := Character'Val (Character'Pos ('0') + Curr
mod 10);
2902 procedure Write_Buffer
2903 (Buf
: Source_Buffer_Ptr
;
2908 for Loc
in First
.. Last
loop
2909 Write_Buffer_Char
(Buf
, Loc
);
2913 -----------------------
2914 -- Write_Buffer_Char --
2915 -----------------------
2917 procedure Write_Buffer_Char
2918 (Buf
: Source_Buffer_Ptr
;
2922 -- If the character ASCII.HT is not the last one in the file,
2923 -- output as many spaces as the character represents in the
2924 -- original source file.
2926 if Buf
(Loc
) = ASCII
.HT
2927 and then Loc
< Buf
'Last
2929 for X
in Get_Column_Number
(Loc
) ..
2930 Get_Column_Number
(Loc
+ 1) - 1
2935 -- Otherwise output the character itself
2938 Write_Char
(Buf
(Loc
));
2940 end Write_Buffer_Char
;
2942 -----------------------
2943 -- Write_Line_Marker --
2944 -----------------------
2946 procedure Write_Line_Marker
2952 Write_Str
(Image
(Positive (Num
), Width
=> Width
));
2953 Write_Str
((if Mark
then ">" else " ") & "|");
2954 end Write_Line_Marker
;
2958 Loc
: constant Source_Ptr
:= Span
.Ptr
;
2959 Line
: constant Pos
:= Pos
(Get_Physical_Line_Number
(Loc
));
2961 Col
: constant Natural := Natural (Get_Column_Number
(Loc
));
2963 Fst
: constant Source_Ptr
:= Span
.First
;
2964 Line_Fst
: constant Pos
:=
2965 Pos
(Get_Physical_Line_Number
(Fst
));
2966 Col_Fst
: constant Natural :=
2967 Natural (Get_Column_Number
(Fst
));
2968 Lst
: constant Source_Ptr
:= Span
.Last
;
2969 Line_Lst
: constant Pos
:=
2970 Pos
(Get_Physical_Line_Number
(Lst
));
2971 Col_Lst
: constant Natural :=
2972 Natural (Get_Column_Number
(Lst
));
2974 Width
: constant := 5;
2975 Buf
: Source_Buffer_Ptr
;
2976 Cur_Loc
: Source_Ptr
:= Fst
;
2977 Cur_Line
: Pos
:= Line_Fst
;
2979 -- Start of processing for Write_Source_Code_Lines
2982 if Loc
>= First_Source_Ptr
then
2983 Buf
:= Source_Text
(Get_Source_File_Index
(Loc
));
2985 -- First line of the span with actual source code. We retrieve
2986 -- the beginning of the line instead of relying on Col_Fst, as
2987 -- ASCII.HT characters change column numbers by possibly more
2992 Line_Fst
/= Line_Lst
and then Cur_Line
= Line
,
2994 Write_Buffer
(Buf
, Get_Line_Start
(Buf
, Cur_Loc
), Cur_Loc
- 1);
2996 -- Output the first/caret/last lines of the span, as well as
2997 -- lines that are directly above/below the caret if they complete
2998 -- the gap with first/last lines, otherwise use ... to denote
2999 -- intermediate lines.
3001 -- If the span is on one line and not a simple source location,
3002 -- color it appropriately.
3004 if Line_Fst
= Line_Lst
3005 and then Col_Fst
/= Col_Lst
3007 Write_Str
(SGR_Span
);
3011 function Do_Write_Line
(Cur_Line
: Pos
) return Boolean is
3012 (Cur_Line
in Line_Fst | Line | Line_Lst
3014 (Cur_Line
= Line_Fst
+ 1 and then Cur_Line
= Line
- 1)
3016 (Cur_Line
= Line
+ 1 and then Cur_Line
= Line_Lst
- 1));
3018 while Cur_Loc
<= Buf
'Last
3019 and then Cur_Loc
<= Lst
3021 if Do_Write_Line
(Cur_Line
) then
3022 Write_Buffer_Char
(Buf
, Cur_Loc
);
3025 if Buf
(Cur_Loc
) = ASCII
.LF
then
3026 Cur_Line
:= Cur_Line
+ 1;
3028 -- Output ... for skipped lines
3031 and then not Do_Write_Line
(Cur_Line
- 1))
3033 (Cur_Line
= Line
+ 1
3034 and then not Do_Write_Line
(Cur_Line
))
3036 Write_Str
((1 .. Width
- 3 => ' ') & "... | ...");
3040 -- Display the line marker if the line should be
3043 if Do_Write_Line
(Cur_Line
) then
3046 Line_Fst
/= Line_Lst
and then Cur_Line
= Line
,
3051 Cur_Loc
:= Cur_Loc
+ 1;
3055 if Line_Fst
= Line_Lst
3056 and then Col_Fst
/= Col_Lst
3058 Write_Str
(SGR_Reset
);
3061 -- Output the rest of the last line of the span
3063 Write_Buffer
(Buf
, Cur_Loc
, Get_Line_End
(Buf
, Cur_Loc
));
3065 -- If the span is on one line, output a second line with caret
3066 -- sign pointing to location Loc
3068 if Line_Fst
= Line_Lst
then
3069 Write_Str
(String'(1 .. Width => ' '));
3071 Write_Str (String'(1 .. Col_Fst
- 1 => ' '));
3073 Write_Str
(SGR_Span
);
3075 Write_Str
(String'(Col_Fst .. Col - 1 => '~
'));
3077 Write_Str (String'(Col
+ 1 .. Col_Lst
=> '~'));
3079 -- If the span is really just a location, add the word "here"
3080 -- to clarify this is the location for the message.
3082 if Col_Fst
= Col_Lst
then
3083 Write_Str
(" here");
3086 Write_Str
(SGR_Reset
);
3091 end Write_Source_Code_Lines
;
3097 Use_Prefix
: Boolean;
3099 -- Start of processing for Output_Messages
3102 -- Error if Finalize has not been called
3104 if not Finalize_Called
then
3105 raise Program_Error
;
3108 -- Reset current error source file if the main unit has a pragma
3109 -- Source_Reference. This ensures outputting the proper name of
3110 -- the source file in this situation.
3112 if Main_Source_File
<= No_Source_File
3113 or else Num_SRef_Pragmas
(Main_Source_File
) /= 0
3115 Current_Error_Source_File
:= No_Source_File
;
3118 if Opt
.JSON_Output
then
3121 E
:= First_Error_Msg
;
3123 -- Find first printable message
3125 while E
/= No_Error_Msg
and then Errors
.Table
(E
).Deleted
loop
3126 E
:= Errors
.Table
(E
).Next
;
3131 if E
/= No_Error_Msg
then
3133 Output_JSON_Message
(E
);
3135 E
:= Errors
.Table
(E
).Next
;
3137 while E
/= No_Error_Msg
loop
3139 -- Skip deleted messages.
3140 -- Also skip continuation messages, as they have already been
3141 -- printed along the message they're attached to.
3143 if not Errors
.Table
(E
).Deleted
3144 and then not Errors
.Table
(E
).Msg_Cont
3147 Output_JSON_Message
(E
);
3150 E
:= Errors
.Table
(E
).Next
;
3156 Set_Standard_Output
;
3160 elsif Brief_Output
or (not Full_List
and not Verbose_Mode
) then
3163 E
:= First_Error_Msg
;
3164 while E
/= No_Error_Msg
loop
3166 -- If -gnatdF is used, separate main messages from previous
3167 -- messages with a newline (unless it is an info message) and
3168 -- make continuation messages follow the main message with only
3169 -- an indentation of two space characters, without repeating
3170 -- file:line:col: prefix.
3173 not (Debug_Flag_FF
and then Errors
.Table
(E
).Msg_Cont
);
3175 if not Errors
.Table
(E
).Deleted
and then not Debug_Flag_KK
then
3177 if Debug_Flag_FF
then
3178 if Errors
.Table
(E
).Msg_Cont
then
3180 elsif not Errors
.Table
(E
).Info
then
3186 Write_Str
(SGR_Locus
);
3188 if Full_Path_Name_For_Brief_Errors
then
3189 Write_Name
(Full_Ref_Name
(Errors
.Table
(E
).Sfile
));
3191 Write_Name
(Reference_Name
(Errors
.Table
(E
).Sfile
));
3195 Write_Int
(Int
(Physical_To_Logical
3196 (Errors
.Table
(E
).Line
,
3197 Errors
.Table
(E
).Sfile
)));
3200 if Errors
.Table
(E
).Col
< 10 then
3204 Write_Int
(Int
(Errors
.Table
(E
).Col
));
3207 Write_Str
(SGR_Reset
);
3210 Output_Msg_Text
(E
);
3213 -- If -gnatdF is used, write the source code line corresponding
3214 -- to the location of the main message (unless it is an info
3215 -- message). Also write the source code line corresponding to
3216 -- an insertion location inside continuation messages.
3219 and then not Errors
.Table
(E
).Info
3221 if Errors
.Table
(E
).Msg_Cont
then
3223 Loc
: constant Source_Ptr
:=
3224 Errors
.Table
(E
).Insertion_Sloc
;
3226 if Loc
/= No_Location
then
3227 Write_Source_Code_Lines
3228 (To_Span
(Loc
), SGR_Span
=> SGR_Note
);
3234 SGR_Span
: constant String :=
3235 (if Errors
.Table
(E
).Info
then SGR_Note
3236 elsif Errors
.Table
(E
).Warn
3237 and then not Errors
.Table
(E
).Warn_Err
3241 Write_Source_Code_Lines
3242 (Errors
.Table
(E
).Optr
, SGR_Span
);
3248 E
:= Errors
.Table
(E
).Next
;
3251 Set_Standard_Output
;
3254 -- Full source listing case
3257 List_Pragmas_Index
:= 1;
3258 List_Pragmas_Mode
:= True;
3259 E
:= First_Error_Msg
;
3261 -- Normal case, to stdout (copyright notice already output)
3263 if Full_List_File_Name
= null then
3264 if not Debug_Flag_7
then
3271 Create_List_File_Access
.all (Full_List_File_Name
.all);
3272 Set_Special_Output
(Write_List_Info_Access
.all'Access);
3274 -- Write copyright notice to file
3276 if not Debug_Flag_7
then
3277 Write_Str
("GNAT ");
3278 Write_Str
(Gnat_Version_String
);
3280 Write_Str
("Copyright 1992-" &
3282 ", Free Software Foundation, Inc.");
3287 -- First list extended main source file units with errors
3289 for U
in Main_Unit
.. Last_Unit
loop
3290 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
))
3292 -- If debug flag d.m is set, only the main source is listed
3294 and then (U
= Main_Unit
or else not Debug_Flag_Dot_M
)
3296 -- If the unit of the entity does not come from source, it is
3297 -- an implicit subprogram declaration for a child subprogram.
3298 -- Do not emit errors for it, they are listed with the body.
3301 (No
(Cunit_Entity
(U
))
3302 or else Comes_From_Source
(Cunit_Entity
(U
))
3303 or else not Is_Subprogram
(Cunit_Entity
(U
)))
3305 -- If the compilation unit associated with this unit does not
3306 -- come from source, it means it is an instantiation that should
3307 -- not be included in the source listing.
3309 and then Comes_From_Source
(Cunit
(U
))
3312 Sfile
: constant Source_File_Index
:= Source_Index
(U
);
3317 -- Only write the header if Sfile is known
3319 if Sfile
> No_Source_File
then
3320 Write_Header
(Sfile
);
3324 -- Normally, we don't want an "error messages from file"
3325 -- message when listing the entire file, so we set the
3326 -- current source file as the current error source file.
3327 -- However, the old style of doing things was to list this
3328 -- message if pragma Source_Reference is present, even for
3329 -- the main unit. Since the purpose of the -gnatd.m switch
3330 -- is to duplicate the old behavior, we skip the reset if
3331 -- this debug flag is set.
3333 if not Debug_Flag_Dot_M
then
3334 Current_Error_Source_File
:= Sfile
;
3337 -- Only output the listing if Sfile is known, to avoid
3338 -- crashing the compiler.
3340 if Sfile
> No_Source_File
then
3341 for N
in 1 .. Last_Source_Line
(Sfile
) loop
3342 while E
/= No_Error_Msg
3343 and then Errors
.Table
(E
).Deleted
3345 E
:= Errors
.Table
(E
).Next
;
3350 and then Errors
.Table
(E
).Line
= N
3351 and then Errors
.Table
(E
).Sfile
= Sfile
;
3353 Output_Source_Line
(N
, Sfile
, Err_Flag
);
3356 Output_Error_Msgs
(E
);
3358 if not Debug_Flag_2
then
3368 -- Then output errors, if any, for subsidiary units not in the
3369 -- main extended unit.
3371 -- Note: if debug flag d.m set, include errors for any units other
3372 -- than the main unit in the extended source unit (e.g. spec and
3373 -- subunits for a body).
3375 while E
/= No_Error_Msg
3376 and then (not In_Extended_Main_Source_Unit
3377 (Errors
.Table
(E
).Sptr
.Ptr
)
3380 and then Get_Source_Unit
3381 (Errors
.Table
(E
).Sptr
.Ptr
) /= Main_Unit
))
3383 if Errors
.Table
(E
).Deleted
then
3384 E
:= Errors
.Table
(E
).Next
;
3389 (Errors
.Table
(E
).Line
, Errors
.Table
(E
).Sfile
, True);
3390 Output_Error_Msgs
(E
);
3394 -- If output to file, write extra copy of error summary to the
3395 -- output file, and then close it.
3397 if Full_List_File_Name
/= null then
3398 Write_Error_Summary
;
3400 Close_List_File_Access
.all;
3401 Cancel_Special_Output
;
3405 -- Verbose mode (error lines only with error flags). Normally this is
3406 -- ignored in full list mode, unless we are listing to a file, in which
3407 -- case we still generate -gnatv output to standard output.
3410 and then (not Full_List
or else Full_List_File_Name
/= null)
3414 -- Output the header only when Main_Source_File is known
3416 if Main_Source_File
> No_Source_File
then
3417 Write_Header
(Main_Source_File
);
3420 E
:= First_Error_Msg
;
3422 -- Loop through error lines
3424 while E
/= No_Error_Msg
loop
3425 if Errors
.Table
(E
).Deleted
then
3426 E
:= Errors
.Table
(E
).Next
;
3430 (Errors
.Table
(E
).Line
, Errors
.Table
(E
).Sfile
, True);
3431 Output_Error_Msgs
(E
);
3436 -- Output error summary if verbose or full list mode
3438 if Verbose_Mode
or else Full_List
then
3439 Write_Error_Summary
;
3442 if not Opt
.JSON_Output
then
3446 if Warning_Mode
= Treat_As_Error
then
3448 Compile_Time_Pragma_Warnings
: constant Nat
:=
3449 Count_Compile_Time_Pragma_Warnings
;
3450 Total
: constant Int
:= Total_Errors_Detected
+ Warnings_Detected
3451 - Compile_Time_Pragma_Warnings
;
3452 -- We need to protect against a negative Total here, because
3453 -- if a pragma Compile_Time_Warning occurs in dead code, it
3454 -- gets counted in Compile_Time_Pragma_Warnings but not in
3455 -- Warnings_Detected.
3457 Total_Errors_Detected
:= Int
'Max (Total
, 0);
3458 Warnings_Detected
:= Compile_Time_Pragma_Warnings
;
3461 end Output_Messages
;
3463 ------------------------
3464 -- Output_Source_Line --
3465 ------------------------
3467 procedure Output_Source_Line
3468 (L
: Physical_Line_Number
;
3469 Sfile
: Source_File_Index
;
3475 Line_Number_Output
: Boolean := False;
3476 -- Set True once line number is output
3478 Empty_Line
: Boolean := True;
3479 -- Set False if line includes at least one character
3482 if Sfile
/= Current_Error_Source_File
then
3483 Write_Str
("==============Error messages for ");
3485 case Sinput
.File_Type
(Sfile
) is
3487 Write_Str
("source");
3489 when Sinput
.Config
=>
3490 Write_Str
("configuration pragmas");
3493 Write_Str
("symbol definition");
3495 when Sinput
.Preproc
=>
3496 Write_Str
("preprocessing data");
3499 Write_Str
(" file: ");
3500 Write_Name
(Full_File_Name
(Sfile
));
3503 if Num_SRef_Pragmas
(Sfile
) > 0 then
3504 Write_Str
("--------------Line numbers from file: ");
3505 Write_Name
(Full_Ref_Name
(Sfile
));
3506 Write_Str
(" (starting at line ");
3507 Write_Int
(Int
(First_Mapped_Line
(Sfile
)));
3512 Current_Error_Source_File
:= Sfile
;
3515 if Errs
or List_Pragmas_Mode
then
3516 Output_Line_Number
(Physical_To_Logical
(L
, Sfile
));
3517 Line_Number_Output
:= True;
3520 S
:= Line_Start
(L
, Sfile
);
3523 C
:= Source_Text
(Sfile
) (S
);
3524 exit when C
= ASCII
.LF
or else C
= ASCII
.CR
or else C
= EOF
;
3526 -- Deal with matching entry in List_Pragmas table
3529 and then List_Pragmas_Index
<= List_Pragmas
.Last
3530 and then S
= List_Pragmas
.Table
(List_Pragmas_Index
).Ploc
3532 case List_Pragmas
.Table
(List_Pragmas_Index
).Ptyp
is
3536 -- Ignore if on line with errors so that error flags
3537 -- get properly listed with the error line .
3540 Write_Char
(ASCII
.FF
);
3544 List_Pragmas_Mode
:= True;
3546 if not Line_Number_Output
then
3547 Output_Line_Number
(Physical_To_Logical
(L
, Sfile
));
3548 Line_Number_Output
:= True;
3555 List_Pragmas_Mode
:= False;
3558 List_Pragmas_Index
:= List_Pragmas_Index
+ 1;
3560 -- Normal case (no matching entry in List_Pragmas table)
3563 if Errs
or List_Pragmas_Mode
then
3568 Empty_Line
:= False;
3572 -- If we have output a source line, then add the line terminator, with
3573 -- training spaces preserved (so we output the line exactly as input).
3575 if Line_Number_Output
then
3579 Write_Eol_Keep_Blanks
;
3582 end Output_Source_Line
;
3584 --------------------
3585 -- Paren_Required --
3586 --------------------
3588 function Paren_Required
(N
: Node_Id
) return Boolean is
3590 -- In a qualifed_expression the expression part needs to be enclosed in
3593 if Nkind
(Parent
(N
)) = N_Qualified_Expression
then
3594 return N
= Expression
(Parent
(N
));
3601 -----------------------------
3602 -- Remove_Warning_Messages --
3603 -----------------------------
3605 procedure Remove_Warning_Messages
(N
: Node_Id
) is
3607 function Check_For_Warning
(N
: Node_Id
) return Traverse_Result
;
3608 -- This function checks one node for a possible warning message
3610 procedure Check_All_Warnings
is new Traverse_Proc
(Check_For_Warning
);
3611 -- This defines the traversal operation
3613 -----------------------
3614 -- Check_For_Warning --
3615 -----------------------
3617 function Check_For_Warning
(N
: Node_Id
) return Traverse_Result
is
3618 Loc
: constant Source_Ptr
:= Sloc
(N
);
3621 function To_Be_Removed
(E
: Error_Msg_Id
) return Boolean;
3622 -- Returns True for a message that is to be removed. Also adjusts
3623 -- warning count appropriately.
3629 function To_Be_Removed
(E
: Error_Msg_Id
) return Boolean is
3631 if E
/= No_Error_Msg
3633 -- Don't remove if location does not match
3635 and then Errors
.Table
(E
).Optr
.Ptr
= Loc
3637 -- Don't remove if not warning/info message. Note that we do
3638 -- not remove style messages here. They are warning messages
3639 -- but not ones we want removed in this context.
3641 and then (Errors
.Table
(E
).Warn
3643 Errors
.Table
(E
).Warn_Runtime_Raise
)
3645 -- Don't remove unconditional messages
3647 and then not Errors
.Table
(E
).Uncond
3649 if Errors
.Table
(E
).Warn
then
3650 Warnings_Detected
:= Warnings_Detected
- 1;
3653 -- When warning about a runtime exception has been escalated
3654 -- into error, the starting message has increased the total
3655 -- errors counter, so here we decrease this counter.
3657 if Errors
.Table
(E
).Warn_Runtime_Raise
3658 and then not Errors
.Table
(E
).Msg_Cont
3659 and then Warning_Mode
= Treat_Run_Time_Warnings_As_Errors
3661 Total_Errors_Detected
:= Total_Errors_Detected
- 1;
3666 -- No removal required
3673 -- Start of processing for Check_For_Warnings
3676 while To_Be_Removed
(First_Error_Msg
) loop
3677 First_Error_Msg
:= Errors
.Table
(First_Error_Msg
).Next
;
3680 if First_Error_Msg
= No_Error_Msg
then
3681 Last_Error_Msg
:= No_Error_Msg
;
3684 E
:= First_Error_Msg
;
3685 while E
/= No_Error_Msg
loop
3686 while To_Be_Removed
(Errors
.Table
(E
).Next
) loop
3687 Errors
.Table
(E
).Next
:=
3688 Errors
.Table
(Errors
.Table
(E
).Next
).Next
;
3690 if Errors
.Table
(E
).Next
= No_Error_Msg
then
3691 Last_Error_Msg
:= E
;
3695 E
:= Errors
.Table
(E
).Next
;
3698 -- Warnings may have been posted on subexpressions of original tree
3700 if Nkind
(N
) = N_Raise_Constraint_Error
3701 and then Is_Rewrite_Substitution
(N
)
3702 and then No
(Condition
(N
))
3704 Check_All_Warnings
(Original_Node
(N
));
3708 end Check_For_Warning
;
3710 -- Start of processing for Remove_Warning_Messages
3713 if Warnings_Detected
/= 0 then
3714 Check_All_Warnings
(N
);
3716 end Remove_Warning_Messages
;
3718 procedure Remove_Warning_Messages
(L
: List_Id
) is
3722 while Present
(Stat
) loop
3723 Remove_Warning_Messages
(Stat
);
3726 end Remove_Warning_Messages
;
3728 ----------------------
3729 -- Adjust_Name_Case --
3730 ----------------------
3732 procedure Adjust_Name_Case
3733 (Buf
: in out Bounded_String
;
3736 Src_Ind
: constant Source_File_Index
:= Get_Source_File_Index
(Loc
);
3737 Sbuffer
: Source_Buffer_Ptr
;
3739 Src_Ptr
: Source_Ptr
;
3742 -- We have an all lower case name from Namet, and now we want to set
3743 -- the appropriate case. If possible we copy the actual casing from
3744 -- the source. If not we use standard identifier casing.
3749 -- For standard locations, always use mixed case
3751 if Loc
<= No_Location
then
3752 Set_Casing
(Buf
, Mixed_Case
);
3755 -- Determine if the reference we are dealing with corresponds to text
3756 -- at the point of the error reference. This will often be the case
3757 -- for simple identifier references, and is the case where we can
3758 -- copy the casing from the source.
3760 Sbuffer
:= Source_Text
(Src_Ind
);
3762 while Ref_Ptr
<= Buf
.Length
loop
3764 Fold_Lower
(Sbuffer
(Src_Ptr
)) /=
3765 Fold_Lower
(Buf
.Chars
(Ref_Ptr
));
3766 Ref_Ptr
:= Ref_Ptr
+ 1;
3767 Src_Ptr
:= Src_Ptr
+ 1;
3770 -- If we get through the loop without a mismatch, then output the
3771 -- name the way it is cased in the source program.
3773 if Ref_Ptr
> Buf
.Length
then
3776 for J
in 1 .. Buf
.Length
loop
3777 Buf
.Chars
(J
) := Sbuffer
(Src_Ptr
);
3778 Src_Ptr
:= Src_Ptr
+ 1;
3781 -- Otherwise set the casing using the default identifier casing
3784 Set_Casing
(Buf
, Identifier_Casing
(Src_Ind
));
3787 end Adjust_Name_Case
;
3789 ---------------------------
3790 -- Set_Identifier_Casing --
3791 ---------------------------
3793 procedure Set_Identifier_Casing
3794 (Identifier_Name
: System
.Address
;
3795 File_Name
: System
.Address
)
3797 Ident
: constant Big_String_Ptr
:= To_Big_String_Ptr
(Identifier_Name
);
3798 File
: constant Big_String_Ptr
:= To_Big_String_Ptr
(File_Name
);
3801 Desired_Case
: Casing_Type
:= Mixed_Case
;
3802 -- Casing required for result. Default value of Mixed_Case is used if
3803 -- for some reason we cannot find the right file name in the table.
3806 -- Get length of file name
3809 while File
(Flen
+ 1) /= ASCII
.NUL
loop
3813 -- Loop through file names to find matching one. This is a bit slow, but
3814 -- we only do it in error situations so it is not so terrible. Note that
3815 -- if the loop does not exit, then the desired case will be left set to
3816 -- Mixed_Case, this can happen if the name was not in canonical form.
3818 for J
in 1 .. Last_Source_File
loop
3819 Get_Name_String
(Full_Debug_Name
(J
));
3822 and then Name_Buffer
(1 .. Name_Len
) = String (File
(1 .. Flen
))
3824 Desired_Case
:= Identifier_Casing
(J
);
3829 -- Copy identifier as given to Name_Buffer
3831 for J
in Name_Buffer
'Range loop
3832 Name_Buffer
(J
) := Ident
(J
);
3834 if Name_Buffer
(J
) = ASCII
.NUL
then
3840 Set_Casing
(Desired_Case
);
3841 end Set_Identifier_Casing
;
3843 -----------------------
3844 -- Set_Ignore_Errors --
3845 -----------------------
3847 procedure Set_Ignore_Errors
(To
: Boolean) is
3849 Errors_Must_Be_Ignored
:= To
;
3850 end Set_Ignore_Errors
;
3852 ------------------------------
3853 -- Set_Msg_Insertion_Column --
3854 ------------------------------
3856 procedure Set_Msg_Insertion_Column
is
3858 if RM_Column_Check
then
3859 Set_Msg_Str
(" in column ");
3860 Set_Msg_Int
(Int
(Error_Msg_Col
) + 1);
3862 end Set_Msg_Insertion_Column
;
3864 ----------------------------
3865 -- Set_Msg_Insertion_Node --
3866 ----------------------------
3868 procedure Set_Msg_Insertion_Node
is
3869 pragma Assert
(Present
(Error_Msg_Node_1
));
3873 Suppress_Message
:= Error_Msg_Node_1
in Error | Any_Type
;
3875 if Error_Msg_Node_1
= Error
then
3877 Set_Msg_Str
("<error>");
3879 elsif Error_Msg_Node_1
= Standard_Void_Type
then
3881 Set_Msg_Str
("procedure name");
3883 elsif Nkind
(Error_Msg_Node_1
) in N_Entity
3884 and then Ekind
(Error_Msg_Node_1
) = E_Anonymous_Access_Subprogram_Type
3887 Set_Msg_Str
("access to subprogram");
3890 Set_Msg_Blank_Conditional
;
3894 K
:= Nkind
(Error_Msg_Node_1
);
3896 -- Skip quotes in the operator case, because the operator will supply
3897 -- the required quotes.
3899 if K
in N_Op | N_Operator_Symbol | N_Defining_Operator_Symbol
3900 or else (K
in N_Identifier | N_Defining_Identifier
3901 and then Is_Operator_Name
(Chars
(Error_Msg_Node_1
)))
3903 Set_Msg_Node
(Error_Msg_Node_1
);
3905 -- Normal case, not an operator, surround with quotes
3909 Set_Qualification
(Error_Msg_Qual_Level
, Error_Msg_Node_1
);
3910 Set_Msg_Node
(Error_Msg_Node_1
);
3915 -- The following assignment ensures that further ampersand insertion
3916 -- characters will correspond to the Error_Msg_Node_# parameter.
3918 Error_Msg_Node_1
:= Error_Msg_Node_2
;
3919 Error_Msg_Node_2
:= Error_Msg_Node_3
;
3920 Error_Msg_Node_3
:= Error_Msg_Node_4
;
3921 Error_Msg_Node_4
:= Error_Msg_Node_5
;
3922 Error_Msg_Node_5
:= Error_Msg_Node_6
;
3923 end Set_Msg_Insertion_Node
;
3925 --------------------------------------
3926 -- Set_Msg_Insertion_Type_Reference --
3927 --------------------------------------
3929 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
) is
3935 if Error_Msg_Node_1
= Standard_Void_Type
then
3936 Set_Msg_Str
("package or procedure name");
3939 elsif Error_Msg_Node_1
= Standard_Exception_Type
then
3940 Set_Msg_Str
("exception name");
3943 elsif Error_Msg_Node_1
= Any_Array
3944 or else Error_Msg_Node_1
= Any_Boolean
3945 or else Error_Msg_Node_1
= Any_Character
3946 or else Error_Msg_Node_1
= Any_Composite
3947 or else Error_Msg_Node_1
= Any_Discrete
3948 or else Error_Msg_Node_1
= Any_Fixed
3949 or else Error_Msg_Node_1
= Any_Integer
3950 or else Error_Msg_Node_1
= Any_Modular
3951 or else Error_Msg_Node_1
= Any_Numeric
3952 or else Error_Msg_Node_1
= Any_Real
3953 or else Error_Msg_Node_1
= Any_Scalar
3954 or else Error_Msg_Node_1
= Any_String
3956 Get_Unqualified_Decoded_Name_String
(Chars
(Error_Msg_Node_1
));
3957 Set_Msg_Name_Buffer
;
3960 elsif Error_Msg_Node_1
= Universal_Integer
then
3961 Set_Msg_Str
("type universal integer");
3964 elsif Error_Msg_Node_1
= Universal_Real
then
3965 Set_Msg_Str
("type universal real");
3968 elsif Error_Msg_Node_1
= Universal_Fixed
then
3969 Set_Msg_Str
("type universal fixed");
3972 elsif Error_Msg_Node_1
= Universal_Access
then
3973 Set_Msg_Str
("type universal access");
3977 -- Special case of anonymous array
3979 if Nkind
(Error_Msg_Node_1
) in N_Entity
3980 and then Is_Array_Type
(Error_Msg_Node_1
)
3981 and then Present
(Related_Array_Object
(Error_Msg_Node_1
))
3983 Set_Msg_Str
("type of ");
3984 Set_Msg_Node
(Related_Array_Object
(Error_Msg_Node_1
));
3985 Set_Msg_Str
(" declared");
3986 Set_Msg_Insertion_Line_Number
3987 (Sloc
(Related_Array_Object
(Error_Msg_Node_1
)), Flag
);
3991 -- If we fall through, it is not a special case, so first output
3992 -- the name of the type, preceded by private for a private type
3994 if Is_Private_Type
(Error_Msg_Node_1
) then
3995 Set_Msg_Str
("private type ");
3997 Set_Msg_Str
("type ");
4000 Ent
:= Error_Msg_Node_1
;
4002 if Is_Internal_Name
(Chars
(Ent
)) then
4003 Unwind_Internal_Type
(Ent
);
4006 -- Types in Standard are displayed as "Standard.name"
4008 if Sloc
(Ent
) <= Standard_Location
then
4010 Set_Msg_Str
("Standard.");
4015 -- Types in other language defined units are displayed as
4016 -- "package-name.type-name"
4018 elsif Is_Predefined_Unit
(Get_Source_Unit
(Ent
)) then
4019 Get_Unqualified_Decoded_Name_String
4020 (Unit_Name
(Get_Source_Unit
(Ent
)));
4021 Name_Len
:= Name_Len
- 2;
4022 Set_Msg_Blank_Conditional
;
4024 Set_Casing
(Mixed_Case
);
4025 Set_Msg_Name_Buffer
;
4027 Set_Casing
(Mixed_Case
);
4032 -- All other types display as "type name" defined at line xxx
4033 -- possibly qualified if qualification is requested.
4037 Set_Qualification
(Error_Msg_Qual_Level
, Ent
);
4041 -- If we did not print a name (e.g. in the case of an anonymous
4042 -- subprogram type), there is no name to print, so remove quotes.
4044 if Buffer_Ends_With
('"') then
4045 Buffer_Remove
('"');
4051 -- If the original type did not come from a predefined file, add the
4052 -- location where the type was defined.
4054 if Sloc
(Error_Msg_Node_1
) > Standard_Location
4056 not Is_Predefined_Unit
(Get_Source_Unit
(Error_Msg_Node_1
))
4058 Get_Name_String
(Unit_File_Name
(Get_Source_Unit
(Error_Msg_Node_1
)));
4059 Set_Msg_Str
(" defined");
4060 Set_Msg_Insertion_Line_Number
(Sloc
(Error_Msg_Node_1
), Flag
);
4062 -- If it did come from a predefined file, deal with the case where
4063 -- this was a file with a generic instantiation from elsewhere.
4066 if Sloc
(Error_Msg_Node_1
) > Standard_Location
then
4068 Iloc
: constant Source_Ptr
:=
4069 Instantiation_Location
(Sloc
(Error_Msg_Node_1
));
4072 if Iloc
/= No_Location
4073 and then not Suppress_Instance_Location
4075 Set_Msg_Str
(" from instance");
4076 Set_Msg_Insertion_Line_Number
(Iloc
, Flag
);
4081 end Set_Msg_Insertion_Type_Reference
;
4083 ---------------------------------
4084 -- Set_Msg_Insertion_Unit_Name --
4085 ---------------------------------
4087 procedure Set_Msg_Insertion_Unit_Name
(Suffix
: Boolean := True) is
4089 if Error_Msg_Unit_1
= No_Unit_Name
then
4092 elsif Error_Msg_Unit_1
= Error_Unit_Name
then
4094 Set_Msg_Str
("<error>");
4097 Get_Unit_Name_String
(Global_Name_Buffer
, Error_Msg_Unit_1
, Suffix
);
4100 Set_Msg_Name_Buffer
;
4104 -- The following assignment ensures that a second percent insertion
4105 -- character will correspond to the Error_Msg_Unit_2 parameter.
4107 Error_Msg_Unit_1
:= Error_Msg_Unit_2
;
4108 end Set_Msg_Insertion_Unit_Name
;
4114 procedure Set_Msg_Node
(Node
: Node_Id
) is
4120 case Nkind
(Node
) is
4121 when N_Designator
=>
4122 Set_Msg_Node
(Name
(Node
));
4124 Set_Msg_Node
(Identifier
(Node
));
4127 when N_Defining_Program_Unit_Name
=>
4128 Set_Msg_Node
(Name
(Node
));
4130 Set_Msg_Node
(Defining_Identifier
(Node
));
4133 when N_Expanded_Name
4134 | N_Selected_Component
4136 Set_Msg_Node
(Prefix
(Node
));
4138 Set_Msg_Node
(Selector_Name
(Node
));
4145 -- The only remaining possibilities are identifiers, defining
4146 -- identifiers, pragmas, and pragma argument associations.
4148 if Nkind
(Node
) = N_Pragma
then
4149 Nam
:= Pragma_Name
(Node
);
4152 -- The other cases have Chars fields
4154 -- First deal with internal names, which generally represent something
4155 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4156 -- something with a Chars field that is not an internal name, use that.
4158 elsif Is_Internal_Name
(Chars
(Node
))
4159 and then Nkind
(Original_Node
(Node
)) in N_Has_Chars
4160 and then not Is_Internal_Name
(Chars
(Original_Node
(Node
)))
4162 Nam
:= Chars
(Original_Node
(Node
));
4163 Loc
:= Sloc
(Original_Node
(Node
));
4165 -- Another shot for internal names, in the case of internal type names,
4166 -- we try to find a reasonable representation for the external name.
4168 elsif Is_Internal_Name
(Chars
(Node
))
4170 ((Is_Entity_Name
(Node
)
4171 and then Present
(Entity
(Node
))
4172 and then Is_Type
(Entity
(Node
)))
4174 (Nkind
(Node
) = N_Defining_Identifier
and then Is_Type
(Node
)))
4176 if Nkind
(Node
) = N_Identifier
then
4177 Ent
:= Entity
(Node
);
4184 -- If the type is the designated type of an access_to_subprogram,
4185 -- then there is no name to provide in the call.
4187 if Ekind
(Ent
) = E_Subprogram_Type
then
4190 -- Otherwise, we will be able to find some kind of name to output
4193 Unwind_Internal_Type
(Ent
);
4197 -- If not internal name, or if we could not find a reasonable possible
4198 -- substitution for the internal name, just use name in Chars field.
4201 Nam
:= Chars
(Node
);
4205 -- At this stage, the name to output is in Nam
4207 Get_Unqualified_Decoded_Name_String
(Nam
);
4209 -- Remove trailing upper case letters from the name (useful for
4210 -- dealing with some cases of internal names).
4212 while Name_Len
> 1 and then Name_Buffer
(Name_Len
) in 'A' .. 'Z' loop
4213 Name_Len
:= Name_Len
- 1;
4216 -- If we have any of the names from standard that start with the
4217 -- characters "any " (e.g. Any_Type), then kill the message since
4218 -- almost certainly it is a junk cascaded message.
4221 and then Name_Buffer
(1 .. 4) = "any "
4223 Kill_Message
:= True;
4226 -- If we still have an internal name, kill the message (will only
4227 -- work if we already had errors!)
4229 if Is_Internal_Name
then
4230 Kill_Message
:= True;
4232 -- Remaining step is to adjust casing and possibly add 'Class
4234 Adjust_Name_Case
(Global_Name_Buffer
, Loc
);
4235 Set_Msg_Name_Buffer
;
4243 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
) is
4244 C
: Character; -- Current character
4245 P
: Natural; -- Current index;
4247 procedure Skip_Msg_Insertion_Warning
(C
: Character);
4248 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4249 -- sequences using < instead of ?). The caller has already bumped
4250 -- the pointer past the initial ? or < and C is set to this initial
4251 -- character (? or <). This procedure skips past the rest of the
4252 -- sequence. We do not need to set Msg_Insertion_Char, since this
4253 -- was already done during the message prescan.
4254 -- No validity check is performed as the insertion sequence is
4255 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4256 -- erroutc.adb for the validity checks.
4258 --------------------------------
4259 -- Skip_Msg_Insertion_Warning --
4260 --------------------------------
4262 procedure Skip_Msg_Insertion_Warning
(C
: Character) is
4264 if P
<= Text
'Last and then Text
(P
) = C
then
4267 elsif P
< Text
'Last and then Text
(P
+ 1) = C
4268 and then Text
(P
) in 'a' .. 'z' |
'A' .. 'Z' |
4269 '0' .. '9' |
'*' |
'$'
4273 elsif P
+ 1 < Text
'Last and then Text
(P
+ 2) = C
4274 and then Text
(P
) in '.' |
'_'
4275 and then Text
(P
+ 1) in 'a' .. 'z'
4279 end Skip_Msg_Insertion_Warning
;
4281 -- Start of processing for Set_Msg_Text
4284 Manual_Quote_Mode
:= False;
4286 Flag_Source
:= Get_Source_File_Index
(Flag
);
4288 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4289 -- will be used (Info field in error message object) to put back the
4290 -- string when it is printed. We need to do this, or we get confused
4291 -- with instantiation continuations.
4294 and then Text
(Text
'First .. Text
'First + 5) = "info: "
4296 P
:= Text
'First + 6;
4301 -- Loop through characters of message
4303 while P
<= Text
'Last loop
4307 -- Check for insertion character or sequence
4311 if P
<= Text
'Last and then Text
(P
) = '%' then
4313 Set_Msg_Insertion_Name_Literal
;
4315 Set_Msg_Insertion_Name
;
4319 if P
<= Text
'Last and then Text
(P
) = '$' then
4321 Set_Msg_Insertion_Unit_Name
(Suffix
=> False);
4323 Set_Msg_Insertion_Unit_Name
;
4327 Set_Msg_Insertion_File_Name
;
4330 Set_Msg_Insertion_Type_Reference
(Flag
);
4333 Set_Msg_Insertion_Reserved_Name
;
4336 Set_Msg_Insertion_Node
;
4339 Set_Msg_Insertion_Line_Number
(Error_Msg_Sloc
, Flag
);
4342 Continuation
:= True;
4344 if P
<= Text
'Last and then Text
(P
) = '\' then
4345 Continuation_New_Line
:= True;
4350 Set_Msg_Insertion_Column
;
4353 Set_Msg_Insertion_Run_Time_Name
;
4356 Set_Msg_Insertion_Uint
;
4359 Manual_Quote_Mode
:= not Manual_Quote_Mode
;
4363 null; -- already dealt with
4366 Skip_Msg_Insertion_Warning
('?');
4369 Skip_Msg_Insertion_Warning
('<');
4372 null; -- already dealt with
4375 Set_Msg_Char
(Text
(P
));
4379 Set_Msg_Str
(Error_Msg_String
(1 .. Error_Msg_Strlen
));
4381 -- Upper case letter
4385 -- Start of reserved word if two or more
4387 if P
<= Text
'Last and then Text
(P
) in 'A' .. 'Z' then
4389 Set_Msg_Insertion_Reserved_Word
(Text
, P
);
4391 -- Single upper case letter is just inserted
4397 -- '[' (will be/would have been raised at run time)
4401 -- "[]" (insertion of error code)
4403 if P
<= Text
'Last and then Text
(P
) = ']' then
4405 Set_Msg_Insertion_Code
;
4408 -- Switch the message from a warning to an error if the flag
4409 -- -gnatwE is specified to treat run-time exception warnings
4413 and then Warning_Mode
= Treat_Run_Time_Warnings_As_Errors
4415 Is_Warning_Msg
:= False;
4416 Is_Runtime_Raise
:= True;
4419 if Is_Warning_Msg
then
4420 Set_Msg_Str
("will be raised at run time");
4422 Set_Msg_Str
("would have been raised at run time");
4426 -- ']' (may be/might have been raised at run time)
4429 if Is_Warning_Msg
then
4430 Set_Msg_Str
("may be raised at run time");
4432 Set_Msg_Str
("might have been raised at run time");
4435 -- Normal character with no special treatment
4447 procedure Set_Posted
(N
: Node_Id
) is
4451 if Is_Serious_Error
then
4453 -- We always set Error_Posted on the node itself
4455 Set_Error_Posted
(N
);
4457 -- If it is a subexpression, then set Error_Posted on parents up to
4458 -- and including the first non-subexpression construct. This helps
4459 -- avoid cascaded error messages within a single expression.
4465 Set_Error_Posted
(P
);
4466 exit when Nkind
(P
) not in N_Subexpr
;
4469 if Nkind
(P
) in N_Pragma_Argument_Association
4470 | N_Component_Association
4471 | N_Discriminant_Association
4472 | N_Generic_Association
4473 | N_Parameter_Association
4475 Set_Error_Posted
(Parent
(P
));
4478 -- A special check, if we just posted an error on an attribute
4479 -- definition clause, then also set the entity involved as posted.
4480 -- For example, this stops complaining about the alignment after
4481 -- complaining about the size, which is likely to be useless.
4483 if Nkind
(P
) = N_Attribute_Definition_Clause
then
4484 if Is_Entity_Name
(Name
(P
)) then
4485 Set_Error_Posted
(Entity
(Name
(P
)));
4491 -----------------------
4492 -- Set_Qualification --
4493 -----------------------
4495 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
) is
4497 if N
/= 0 and then Scope
(E
) /= Standard_Standard
then
4498 Set_Qualification
(N
- 1, Scope
(E
));
4499 Set_Msg_Node
(Scope
(E
));
4502 end Set_Qualification
;
4504 -------------------------------------
4505 -- Should_Ignore_Pragma_SPARK_Mode --
4506 -------------------------------------
4508 function Should_Ignore_Pragma_SPARK_Mode
return Boolean is
4510 return Get_Name_Table_Boolean3
(Name_SPARK_Mode
);
4511 end Should_Ignore_Pragma_SPARK_Mode
;
4513 ------------------------
4514 -- Special_Msg_Delete --
4515 ------------------------
4517 -- Is it really right to have all this specialized knowledge in errout?
4519 function Special_Msg_Delete
4521 N
: Node_Or_Entity_Id
;
4522 E
: Node_Or_Entity_Id
) return Boolean
4525 -- Never delete messages in -gnatdO mode
4527 if Debug_Flag_OO
then
4530 -- Processing for "Size too small" messages
4532 elsif Is_Size_Too_Small_Message
(Msg
) then
4534 -- Suppress "size too small" errors in CodePeer mode, since code may
4535 -- be analyzed in a different configuration than the one used for
4536 -- compilation. Even when the configurations match, this message
4537 -- may be issued on correct code, because pragma Pack is ignored
4538 -- in CodePeer mode.
4540 if CodePeer_Mode
then
4543 -- When a size is wrong for a frozen type there is no explicit size
4544 -- clause, and other errors have occurred, suppress the message,
4545 -- since it is likely that this size error is a cascaded result of
4546 -- other errors. The reason we eliminate unfrozen types is that
4547 -- messages issued before the freeze type are for sure OK.
4549 elsif Nkind
(N
) in N_Entity
4550 and then Is_Frozen
(E
)
4551 and then Serious_Errors_Detected
> 0
4552 and then Nkind
(N
) /= N_Component_Clause
4553 and then Nkind
(Parent
(N
)) /= N_Component_Clause
4555 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Size
))
4557 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Object_Size
))
4559 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Value_Size
))
4565 -- All special tests complete, so go ahead with message
4568 end Special_Msg_Delete
;
4574 procedure SPARK_Msg_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
4576 -- If SPARK_Mode is Off, we do not report SPARK legality errors to give
4577 -- the flexibility to opt out of SPARK checking completely. We do the
4578 -- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
4579 -- for tools to ignore SPARK checking even on SPARK code.
4581 if SPARK_Mode
/= Off
4582 and then not Should_Ignore_Pragma_SPARK_Mode
4584 Error_Msg_N
(Msg
, N
);
4592 procedure SPARK_Msg_NE
4594 N
: Node_Or_Entity_Id
;
4595 E
: Node_Or_Entity_Id
)
4598 if SPARK_Mode
/= Off
4599 and then not Should_Ignore_Pragma_SPARK_Mode
4601 Error_Msg_NE
(Msg
, N
, E
);
4605 --------------------------
4606 -- Unwind_Internal_Type --
4607 --------------------------
4609 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
) is
4610 Derived
: Boolean := False;
4612 Old_Ent
: Entity_Id
;
4615 -- Undo placement of a quote, since we will put it back later
4617 Mchar
:= Msg_Buffer
(Msglen
);
4620 Msglen
:= Msglen
- 1;
4623 -- The loop here deals with recursive types, we are trying to find a
4624 -- related entity that is not an implicit type. Note that the check with
4625 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4626 -- "type derived from" message more than once in the case where we climb
4627 -- up multiple levels.
4632 -- Implicit access type, use directly designated type In Ada 2005,
4633 -- the designated type may be an anonymous access to subprogram, in
4634 -- which case we can only point to its definition.
4636 if Is_Access_Type
(Ent
) then
4637 if Ekind
(Ent
) = E_Access_Subprogram_Type
4638 or else Ekind
(Ent
) = E_Anonymous_Access_Subprogram_Type
4639 or else Is_Access_Protected_Subprogram_Type
(Ent
)
4641 Ent
:= Directly_Designated_Type
(Ent
);
4643 if not Comes_From_Source
(Ent
) then
4644 if Buffer_Ends_With
("type ") then
4645 Buffer_Remove
("type ");
4649 if Ekind
(Ent
) = E_Function
then
4650 Set_Msg_Str
("access to function ");
4651 elsif Ekind
(Ent
) = E_Procedure
then
4652 Set_Msg_Str
("access to procedure ");
4654 Set_Msg_Str
("access to subprogram");
4659 -- Type is access to object, named or anonymous
4662 Set_Msg_Str
("access to ");
4663 Ent
:= Directly_Designated_Type
(Ent
);
4668 elsif Is_Class_Wide_Type
(Ent
) then
4670 Ent
:= Root_Type
(Ent
);
4672 -- Use base type if this is a subtype
4674 elsif Ent
/= Base_Type
(Ent
) then
4675 Buffer_Remove
("type ");
4677 -- Avoid duplication "subtype of subtype of", and also replace
4678 -- "derived from subtype of" simply by "derived from"
4680 if not Buffer_Ends_With
("subtype of ")
4681 and then not Buffer_Ends_With
("derived from ")
4683 Set_Msg_Str
("subtype of ");
4686 Ent
:= Base_Type
(Ent
);
4688 -- If this is a base type with a first named subtype, use the first
4689 -- named subtype instead. This is not quite accurate in all cases,
4690 -- but it makes too much noise to be accurate and add 'Base in all
4691 -- cases. Note that we only do this is the first named subtype is not
4692 -- itself an internal name. This avoids the obvious loop (subtype ->
4693 -- basetype -> subtype) which would otherwise occur).
4697 FST
: constant Entity_Id
:= First_Subtype
(Ent
);
4700 if not Is_Internal_Name
(Chars
(FST
)) then
4704 -- Otherwise use root type
4708 Buffer_Remove
("type ");
4710 -- Test for "subtype of type derived from" which seems
4711 -- excessive and is replaced by "type derived from".
4713 Buffer_Remove
("subtype of");
4715 -- Avoid duplicated "type derived from type derived from"
4717 if not Buffer_Ends_With
("type derived from ") then
4718 Set_Msg_Str
("type derived from ");
4729 -- If we are stuck in a loop, get out and settle for the internal
4730 -- name after all. In this case we set to kill the message if it is
4731 -- not the first error message (we really try hard not to show the
4732 -- dirty laundry of the implementation to the poor user).
4734 if Ent
= Old_Ent
then
4735 Kill_Message
:= True;
4739 -- Get out if we finally found a non-internal name to use
4741 exit Find
when not Is_Internal_Name
(Chars
(Ent
));
4747 end Unwind_Internal_Type
;
4749 --------------------
4750 -- Warn_Insertion --
4751 --------------------
4753 function Warn_Insertion
return String is
4755 if Warning_Msg_Char
= "? " then
4757 elsif Warning_Msg_Char
= " " then
4759 elsif Warning_Msg_Char
(2) = ' ' then
4760 return '?' & Warning_Msg_Char
(1) & '?';
4762 return '?' & Warning_Msg_Char
& '?';