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
105 -- This is the low-level routine used to post messages after dealing with
106 -- the issue of messages placed on instantiations (which get broken up
107 -- into separate calls in Error_Msg). Span is the location on which the
108 -- flag will be placed in the output. In the case where the flag is on
109 -- the template, this points directly to the template, not to one of the
110 -- instantiation copies of the template. Opan is the original location
111 -- used to flag the error, and this may indeed point to an instantiation
112 -- copy. So typically we can see Opan pointing to the template location
113 -- in an instantiation copy when Span points to the source location of
114 -- the actual instantiation (i.e the line with the new). Msg_Cont is
115 -- set true if this is a continuation message. Node is the relevant
116 -- Node_Id for this message, to be used to compute the enclosing entity if
117 -- Opt.Include_Subprogram_In_Messages is set.
119 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean;
120 -- Determines if warnings should be suppressed for the given node
122 function OK_Node
(N
: Node_Id
) return Boolean;
123 -- Determines if a node is an OK node to place an error message on (return
124 -- True) or if the error message should be suppressed (return False). A
125 -- message is suppressed if the node already has an error posted on it,
126 -- or if it refers to an Etype that has an error posted on it, or if
127 -- it references an Entity that has an error posted on it.
129 procedure Output_JSON_Message
(Error_Id
: Error_Msg_Id
);
130 -- Output error message Error_Id and any subsequent continuation message
131 -- using a JSON format similar to the one GCC uses when passed
132 -- -fdiagnostics-format=json.
134 procedure Output_Source_Line
135 (L
: Physical_Line_Number
;
136 Sfile
: Source_File_Index
;
138 -- Outputs text of source line L, in file S, together with preceding line
139 -- number, as described above for Output_Line_Number. The Errs parameter
140 -- indicates if there are errors attached to the line, which forces
141 -- listing on, even in the presence of pragma List (Off).
143 function Paren_Required
(N
: Node_Id
) return Boolean;
144 -- Subsidiary to First_Sloc and Last_Sloc. Returns True iff parentheses
145 -- around node N are required by the Ada syntax, e.g. when N is an
146 -- expression of a qualified expression.
148 procedure Set_Msg_Insertion_Column
;
149 -- Handle column number insertion (@ insertion character)
151 procedure Set_Msg_Insertion_Node
;
152 -- Handle node (name from node) insertion (& insertion character)
154 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
);
155 -- Handle type reference (right brace insertion character). Flag is the
156 -- location of the flag, which is provided for the internal call to
157 -- Set_Msg_Insertion_Line_Number,
159 procedure Set_Msg_Insertion_Unit_Name
(Suffix
: Boolean := True);
160 -- Handle unit name insertion ($ insertion character). Depending on Boolean
161 -- parameter Suffix, (spec) or (body) is appended after the unit name.
163 procedure Set_Msg_Node
(Node
: Node_Id
);
164 -- Add the sequence of characters for the name associated with the given
165 -- node to the current message. For N_Designator, N_Selected_Component,
166 -- N_Defining_Program_Unit_Name, and N_Expanded_Name, the Prefix is
169 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
);
170 -- Add a sequence of characters to the current message. The characters may
171 -- be one of the special insertion characters (see documentation in spec).
172 -- Flag is the location at which the error is to be posted, which is used
173 -- to determine whether or not the # insertion needs a file name. The
174 -- variables Msg_Buffer are set on return Msglen.
176 procedure Set_Posted
(N
: Node_Id
);
177 -- Sets the Error_Posted flag on the given node, and all its parents that
178 -- are subexpressions and then on the parent non-subexpression construct
179 -- that contains the original expression. If that parent is a named
180 -- association, the flag is further propagated to its parent. This is done
181 -- in order to guard against cascaded errors. Note that this call has an
182 -- effect for a serious error only.
184 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
);
185 -- Outputs up to N levels of qualification for the given entity. For
186 -- example, the entity A.B.C.D will output B.C. if N = 2.
188 function Should_Ignore_Pragma_SPARK_Mode
return Boolean;
189 -- Return whether pragma Ignore_Pragma (SPARK_Mode) was specified. This is
190 -- similar to Sem_Util.Should_Ignore_Pragma_Par but located here to avoid
191 -- problematic dependency on Sem_Util.
193 function Special_Msg_Delete
195 N
: Node_Or_Entity_Id
;
196 E
: Node_Or_Entity_Id
) return Boolean;
197 -- This function is called from Error_Msg_NEL, passing the message Msg,
198 -- node N on which the error is to be posted, and the entity or node E
199 -- to be used for an & insertion in the message if any. The job of this
200 -- procedure is to test for certain cascaded messages that we would like
201 -- to suppress. If the message is to be suppressed then we return True.
202 -- If the message should be generated (the normal case) False is returned.
204 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
);
205 -- This procedure is given an entity id for an internal type, i.e. a type
206 -- with an internal name. It unwinds the type to try to get to something
207 -- reasonably printable, generating prefixes like "subtype of", "access
208 -- to", etc along the way in the buffer. The value in Ent on return is the
209 -- final name to be printed. Hopefully this is not an internal name, but in
210 -- some internal name cases, it is an internal name, and has to be printed
211 -- anyway (although in this case the message has been killed if possible).
212 -- The global variable Class_Flag is set to True if the resulting entity
213 -- should have 'Class appended to its name (see Add_Class procedure), and
214 -- is otherwise unchanged.
216 function Warn_Insertion
return String;
217 -- This is called for warning messages only (so Warning_Msg_Char is set)
218 -- and returns a corresponding string to use at the beginning of generated
219 -- auxiliary messages, such as "in instantiation at ...".
222 -- other trimmed, prefixed and suffixed with "?".
224 -----------------------
225 -- Change_Error_Text --
226 -----------------------
228 procedure Change_Error_Text
(Error_Id
: Error_Msg_Id
; New_Msg
: String) is
229 Save_Next
: Error_Msg_Id
;
230 Err_Id
: Error_Msg_Id
:= Error_Id
;
233 Set_Msg_Text
(New_Msg
, Errors
.Table
(Error_Id
).Sptr
.Ptr
);
234 Errors
.Table
(Error_Id
).Text
:= new String'(Msg_Buffer (1 .. Msglen));
236 -- If in immediate error message mode, output modified error message now
237 -- This is just a bit tricky, because we want to output just a single
238 -- message, and the messages we modified is already linked in. We solve
239 -- this by temporarily resetting its forward pointer to empty.
241 if Debug_Flag_OO then
242 Save_Next := Errors.Table (Error_Id).Next;
243 Errors.Table (Error_Id).Next := No_Error_Msg;
246 (Errors.Table (Error_Id).Line, Errors.Table (Error_Id).Sfile, True);
247 Output_Error_Msgs (Err_Id);
248 Errors.Table (Error_Id).Next := Save_Next;
250 end Change_Error_Text;
252 ------------------------
253 -- Compilation_Errors --
254 ------------------------
256 function Compilation_Errors return Boolean is
258 if not Finalize_Called then
261 return Erroutc.Compilation_Errors;
263 end Compilation_Errors;
265 --------------------------------------
266 -- Delete_Warning_And_Continuations --
267 --------------------------------------
269 procedure Delete_Warning_And_Continuations (Msg : Error_Msg_Id) is
273 pragma Assert (not Errors.Table (Msg).Msg_Cont);
278 M : Error_Msg_Object renames Errors.Table (Id);
281 if not M.Deleted then
283 Warnings_Detected := Warnings_Detected - 1;
286 Warning_Info_Messages := Warning_Info_Messages - 1;
290 Warnings_Treated_As_Errors := Warnings_Treated_As_Errors - 1;
295 exit when Id = No_Error_Msg;
296 exit when not Errors.Table (Id).Msg_Cont;
299 end Delete_Warning_And_Continuations;
305 -- Error_Msg posts a flag at the given location, except that if the
306 -- Flag_Location/Flag_Span points within a generic template and corresponds
307 -- to an instantiation of this generic template, then the actual message
308 -- will be posted on the generic instantiation, along with additional
309 -- messages referencing the generic declaration.
311 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr) is
313 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
316 procedure Error_Msg (Msg : String; Flag_Span : Source_Span) is
318 Error_Msg (Msg, Flag_Span, Current_Node);
323 Flag_Location : Source_Ptr;
324 Is_Compile_Time_Pragma : Boolean)
326 Save_Is_Compile_Time_Msg : constant Boolean := Is_Compile_Time_Msg;
328 Is_Compile_Time_Msg := Is_Compile_Time_Pragma;
329 Error_Msg (Msg, To_Span (Flag_Location), Current_Node);
330 Is_Compile_Time_Msg := Save_Is_Compile_Time_Msg;
335 Flag_Location : Source_Ptr;
339 Error_Msg (Msg, To_Span (Flag_Location), N);
344 Flag_Span : Source_Span;
347 Flag_Location : constant Source_Ptr := Flag_Span.Ptr;
349 Sindex : Source_File_Index;
350 -- Source index for flag location
352 Orig_Loc : Source_Ptr;
353 -- Original location of Flag_Location (i.e. location in original
354 -- template in instantiation case, otherwise unchanged).
357 -- Return if all errors are to be ignored
359 if Get_Ignore_Errors then
363 -- If we already have messages, and we are trying to place a message at
364 -- No_Location, then just ignore the attempt since we assume that what
365 -- is happening is some cascaded junk. Note that this is safe in the
366 -- sense that proceeding will surely bomb. We will also bomb if the flag
367 -- location is No_Location and we don't have any messages so far, but
368 -- that is a real bug and a legitimate bomb, so we go ahead.
370 if Flag_Location = No_Location
371 and then Total_Errors_Detected > 0
376 -- Start of processing for new message
378 Sindex := Get_Source_File_Index (Flag_Location);
379 Prescan_Message (Msg);
380 Orig_Loc := Original_Location (Flag_Location);
382 -- If the current location is in an instantiation, the issue arises of
383 -- whether to post the message on the template or the instantiation.
385 -- The way we decide is to see if we have posted the same message on
386 -- the template when we compiled the template (the template is always
387 -- compiled before any instantiations). For this purpose, we use a
388 -- separate table of messages. The reason we do this is twofold:
390 -- First, the messages can get changed by various processing
391 -- including the insertion of tokens etc, making it hard to
392 -- do the comparison.
394 -- Second, we will suppress a warning on a template if it is not in
395 -- the current extended source unit. That's reasonable and means we
396 -- don't want the warning on the instantiation here either, but it
397 -- does mean that the main error table would not in any case include
400 if Flag_Location = Orig_Loc then
401 Non_Instance_Msgs.Append ((new String'(Msg
), Flag_Location
));
402 Warn_On_Instance
:= False;
404 -- Here we have an instance message
407 -- Delete if debug flag off, and this message duplicates a message
408 -- already posted on the corresponding template
410 if not Debug_Flag_GG
then
411 for J
in Non_Instance_Msgs
.First
.. Non_Instance_Msgs
.Last
loop
412 if Msg
= Non_Instance_Msgs
.Table
(J
).Msg
.all
413 and then Non_Instance_Msgs
.Table
(J
).Loc
= Orig_Loc
420 -- No duplicate, so error/warning will be posted on instance
422 Warn_On_Instance
:= Is_Warning_Msg
;
425 -- Ignore warning message that is suppressed for this location. Note
426 -- that style checks are not considered warning messages for this
429 if Is_Warning_Msg
and then Warnings_Suppressed
(Orig_Loc
) /= No_String
433 -- For style messages, check too many messages so far
436 and then Maximum_Messages
/= 0
437 and then Warnings_Detected
>= Maximum_Messages
441 -- Suppress warnings inside a loop that is known to be null or is
442 -- probably null (i.e. when loop executes only if invalid values
443 -- present). In either case warnings in the loop are likely to be junk.
445 elsif Is_Warning_Msg
and then Present
(N
) then
452 while Present
(P
) loop
453 if Nkind
(P
) = N_Loop_Statement
454 and then Suppress_Loop_Warnings
(P
)
464 -- The idea at this stage is that we have two kinds of messages
466 -- First, we have those messages that are to be placed as requested at
467 -- Flag_Location. This includes messages that have nothing to do with
468 -- generics, and also messages placed on generic templates that reflect
469 -- an error in the template itself. For such messages we simply call
470 -- Error_Msg_Internal to place the message in the requested location.
472 if Instantiation
(Sindex
) = No_Location
then
473 Error_Msg_Internal
(Msg
, Flag_Span
, Flag_Span
, False, N
);
477 -- If we are trying to flag an error in an instantiation, we may have
478 -- a generic contract violation. What we generate in this case is:
480 -- instantiation error at ...
481 -- original error message
485 -- warning: in instantiation at ...
486 -- warning: original warning message
490 -- info: in instantiation at ...
491 -- info: original info message
493 -- All these messages are posted at the location of the top level
494 -- instantiation. If there are nested instantiations, then the
495 -- instantiation error message can be repeated, pointing to each
496 -- of the relevant instantiations.
498 -- Note: the instantiation mechanism is also shared for inlining of
499 -- subprogram bodies when front end inlining is done. In this case the
500 -- messages have the form:
502 -- in inlined body at ...
503 -- original error message
507 -- warning: in inlined body at ...
508 -- warning: original warning message
512 -- info: in inlined body at ...
513 -- info: original info message
515 -- OK, here we have an instantiation error, and we need to generate the
516 -- error on the instantiation, rather than on the template.
519 Actual_Error_Loc
: Source_Ptr
;
520 -- Location of outer level instantiation in instantiation case, or
521 -- just a copy of Flag_Location in the normal case. This is the
522 -- location where all error messages will actually be posted.
524 Save_Error_Msg_Sloc
: constant Source_Ptr
:= Error_Msg_Sloc
;
525 -- Save possible location set for caller's message. We need to use
526 -- Error_Msg_Sloc for the location of the instantiation error but we
527 -- have to preserve a possible original value.
529 X
: Source_File_Index
;
531 Msg_Cont_Status
: Boolean;
532 -- Used to label continuation lines in instantiation case with
533 -- proper Msg_Cont status.
536 -- Loop to find highest level instantiation, where all error
537 -- messages will be placed.
541 Actual_Error_Loc
:= Instantiation
(X
);
542 X
:= Get_Source_File_Index
(Actual_Error_Loc
);
543 exit when Instantiation
(X
) = No_Location
;
546 -- Since we are generating the messages at the instantiation point in
547 -- any case, we do not want the references to the bad lines in the
548 -- instance to be annotated with the location of the instantiation.
550 Suppress_Instance_Location
:= True;
551 Msg_Cont_Status
:= False;
553 -- Loop to generate instantiation messages
555 Error_Msg_Sloc
:= Flag_Location
;
556 X
:= Get_Source_File_Index
(Flag_Location
);
557 while Instantiation
(X
) /= No_Location
loop
559 -- Suppress instantiation message on continuation lines
561 if Msg
(Msg
'First) /= '\' then
563 -- Case of inlined body
565 if Inlined_Body
(X
) then
568 (Msg
=> "info: in inlined body #",
569 Span
=> To_Span
(Actual_Error_Loc
),
571 Msg_Cont
=> Msg_Cont_Status
,
574 elsif Is_Warning_Msg
then
576 (Msg
=> Warn_Insertion
& "in inlined body #",
577 Span
=> To_Span
(Actual_Error_Loc
),
579 Msg_Cont
=> Msg_Cont_Status
,
582 elsif Is_Style_Msg
then
584 (Msg
=> "style: in inlined body #",
585 Span
=> To_Span
(Actual_Error_Loc
),
587 Msg_Cont
=> Msg_Cont_Status
,
592 (Msg
=> "error in inlined body #",
593 Span
=> To_Span
(Actual_Error_Loc
),
595 Msg_Cont
=> Msg_Cont_Status
,
599 -- Case of generic instantiation
604 (Msg
=> "info: in instantiation #",
605 Span
=> To_Span
(Actual_Error_Loc
),
607 Msg_Cont
=> Msg_Cont_Status
,
610 elsif Is_Warning_Msg
then
612 (Msg
=> Warn_Insertion
& "in instantiation #",
613 Span
=> To_Span
(Actual_Error_Loc
),
615 Msg_Cont
=> Msg_Cont_Status
,
618 elsif Is_Style_Msg
then
620 (Msg
=> "style: in instantiation #",
621 Span
=> To_Span
(Actual_Error_Loc
),
623 Msg_Cont
=> Msg_Cont_Status
,
628 (Msg
=> "instantiation error #",
629 Span
=> To_Span
(Actual_Error_Loc
),
631 Msg_Cont
=> Msg_Cont_Status
,
637 Error_Msg_Sloc
:= Instantiation
(X
);
638 X
:= Get_Source_File_Index
(Error_Msg_Sloc
);
639 Msg_Cont_Status
:= True;
642 Suppress_Instance_Location
:= False;
643 Error_Msg_Sloc
:= Save_Error_Msg_Sloc
;
645 -- Here we output the original message on the outer instantiation
649 Span
=> To_Span
(Actual_Error_Loc
),
651 Msg_Cont
=> Msg_Cont_Status
,
656 ----------------------------------
657 -- Error_Msg_Ada_2005_Extension --
658 ----------------------------------
660 procedure Error_Msg_Ada_2005_Extension
(Extension
: String) is
661 Loc
: constant Source_Ptr
:= Token_Ptr
;
663 if Ada_Version
< Ada_2005
then
664 Error_Msg
(Extension
& " is an Ada 2005 extension", Loc
);
666 if No
(Ada_Version_Pragma
) then
667 Error_Msg
("\unit must be compiled with -gnat05 switch", Loc
);
669 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
670 Error_Msg
("\incompatible with Ada version set#", Loc
);
673 end Error_Msg_Ada_2005_Extension
;
675 --------------------------------
676 -- Error_Msg_Ada_2012_Feature --
677 --------------------------------
679 procedure Error_Msg_Ada_2012_Feature
(Feature
: String; Loc
: Source_Ptr
) is
681 if Ada_Version
< Ada_2012
then
682 Error_Msg
(Feature
& " is an Ada 2012 feature", Loc
);
684 if No
(Ada_Version_Pragma
) then
685 Error_Msg
("\unit must be compiled with -gnat2012 switch", Loc
);
687 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
688 Error_Msg
("\incompatible with Ada version set#", Loc
);
691 end Error_Msg_Ada_2012_Feature
;
693 --------------------------------
694 -- Error_Msg_Ada_2022_Feature --
695 --------------------------------
697 procedure Error_Msg_Ada_2022_Feature
(Feature
: String; Loc
: Source_Ptr
) is
699 if Ada_Version
< Ada_2022
then
700 Error_Msg
(Feature
& " is an Ada 2022 feature", Loc
);
702 if No
(Ada_Version_Pragma
) then
703 Error_Msg
("\unit must be compiled with -gnat2022 switch", Loc
);
705 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
706 Error_Msg
("\incompatible with Ada version set#", Loc
);
709 end Error_Msg_Ada_2022_Feature
;
715 procedure Error_Msg_AP
(Msg
: String) is
720 -- If we had saved the Scan_Ptr value after scanning the previous
721 -- token, then we would have exactly the right place for putting
722 -- the flag immediately at hand. However, that would add at least
723 -- two instructions to a Scan call *just* to service the possibility
724 -- of an Error_Msg_AP call. So instead we reconstruct that value.
726 -- We have two possibilities, start with Prev_Token_Ptr and skip over
727 -- the current token, which is made harder by the possibility that this
728 -- token may be in error, or start with Token_Ptr and work backwards.
729 -- We used to take the second approach, but it's hard because of
730 -- comments, and harder still because things that look like comments
731 -- can appear inside strings. So now we take the first approach.
733 -- Note: in the case where there is no previous token, Prev_Token_Ptr
734 -- is set to Source_First, which is a reasonable position for the
735 -- error flag in this situation.
737 S1
:= Prev_Token_Ptr
;
740 -- If the previous token is a string literal, we need a special approach
741 -- since there may be white space inside the literal and we don't want
742 -- to stop on that white space.
744 -- Note: since this is an error recovery issue anyway, it is not worth
745 -- worrying about special UTF_32 line terminator characters here.
747 if Prev_Token
= Tok_String_Literal
then
751 if Source
(S1
) = C
then
753 exit when Source
(S1
) /= C
;
754 elsif Source
(S1
) in Line_Terminator
then
759 -- Character literal also needs special handling
761 elsif Prev_Token
= Tok_Char_Literal
then
764 -- Otherwise we search forward for the end of the current token, marked
765 -- by a line terminator, white space, a comment symbol or if we bump
766 -- into the following token (i.e. the current token).
768 -- Again, it is not worth worrying about UTF_32 special line terminator
769 -- characters in this context, since this is only for error recovery.
772 while Source
(S1
) not in Line_Terminator
773 and then Source
(S1
) /= ' '
774 and then Source
(S1
) /= ASCII
.HT
775 and then (Source
(S1
) /= '-' or else Source
(S1
+ 1) /= '-')
776 and then S1
/= Token_Ptr
782 -- S1 is now set to the location for the flag
791 procedure Error_Msg_BC
(Msg
: String) is
793 -- If we are at end of file, post the flag after the previous token
795 if Token
= Tok_EOF
then
798 -- If we are at start of file, post the flag at the current token
800 elsif Token_Ptr
= Source_First
(Current_Source_File
) then
803 -- If the character before the current token is a space or a horizontal
804 -- tab, then we place the flag on this character (in the case of a tab
805 -- we would really like to place it in the "last" character of the tab
806 -- space, but that it too much trouble to worry about).
808 elsif Source
(Token_Ptr
- 1) = ' '
809 or else Source
(Token_Ptr
- 1) = ASCII
.HT
811 Error_Msg
(Msg
, Token_Ptr
- 1);
813 -- If there is no space or tab before the current token, then there is
814 -- no room to place the flag before the token, so we place it on the
815 -- token instead (this happens for example at the start of a line).
818 Error_Msg
(Msg
, Token_Ptr
);
826 procedure Error_Msg_CRT
(Feature
: String; N
: Node_Id
) is
828 if No_Run_Time_Mode
then
829 Error_Msg_N
('|' & Feature
& " not allowed in no run time mode", N
);
831 else pragma Assert
(Configurable_Run_Time_Mode
);
832 Error_Msg_N
('|' & Feature
& " not supported by configuration>", N
);
835 Configurable_Run_Time_Violations
:= Configurable_Run_Time_Violations
+ 1;
842 procedure Error_Msg_PT
(E
: Entity_Id
; Iface_Prim
: Entity_Id
) is
845 ("illegal overriding of subprogram inherited from interface", E
);
847 Error_Msg_Sloc
:= Sloc
(Iface_Prim
);
849 if Ekind
(E
) = E_Function
then
851 ("\first formal of & declared # must be of mode `IN` "
852 & "or access-to-constant", E
);
855 ("\first formal of & declared # must be of mode `OUT`, `IN OUT` "
856 & "or access-to-variable", E
);
864 procedure Error_Msg_F
(Msg
: String; N
: Node_Id
) is
867 First_And_Last_Nodes
(N
, Fst
, Lst
);
868 Error_Msg_NEL
(Msg
, N
, N
,
869 To_Span
(Ptr
=> Sloc
(Fst
),
870 First
=> First_Sloc
(Fst
),
871 Last
=> Last_Sloc
(Lst
)));
878 procedure Error_Msg_FE
881 E
: Node_Or_Entity_Id
)
885 First_And_Last_Nodes
(N
, Fst
, Lst
);
886 Error_Msg_NEL
(Msg
, N
, E
,
887 To_Span
(Ptr
=> Sloc
(Fst
),
888 First
=> First_Sloc
(Fst
),
889 Last
=> Last_Sloc
(Lst
)));
892 ------------------------------
893 -- Error_Msg_GNAT_Extension --
894 ------------------------------
896 procedure Error_Msg_GNAT_Extension
899 Is_Core_Extension
: Boolean := False)
902 if (if Is_Core_Extension
903 then Core_Extensions_Allowed
904 else All_Extensions_Allowed
)
909 Error_Msg
(Extension
& " is a 'G'N'A'T-specific extension", Loc
);
911 if No
(Ada_Version_Pragma
) then
912 if Is_Core_Extension
then
914 ("\unit must be compiled with -gnatX '[or -gnatX0'] " &
915 "or use pragma Extensions_Allowed (On) '[or All']", Loc
);
918 ("\unit must be compiled with -gnatX0 " &
919 "or use pragma Extensions_Allowed (All)", Loc
);
922 Error_Msg_Sloc
:= Sloc
(Ada_Version_Pragma
);
923 Error_Msg
("\incompatible with Ada version set#", Loc
);
924 if Is_Core_Extension
then
926 ("\must use pragma Extensions_Allowed (On) '[or All']", Loc
);
929 ("\must use pragma Extensions_Allowed (All)", Loc
);
932 end Error_Msg_GNAT_Extension
;
934 ------------------------
935 -- Error_Msg_Internal --
936 ------------------------
938 procedure Error_Msg_Internal
945 Sptr
: constant Source_Ptr
:= Span
.Ptr
;
946 Optr
: constant Source_Ptr
:= Opan
.Ptr
;
948 Next_Msg
: Error_Msg_Id
;
949 -- Pointer to next message at insertion point
951 Prev_Msg
: Error_Msg_Id
;
952 -- Pointer to previous message at insertion point
954 Temp_Msg
: Error_Msg_Id
;
957 -- Set if warning to be treated as error
959 procedure Handle_Serious_Error
;
960 -- Internal procedure to do all error message handling for a serious
961 -- error message, other than bumping the error counts and arranging
962 -- for the message to be output.
964 --------------------------
965 -- Handle_Serious_Error --
966 --------------------------
968 procedure Handle_Serious_Error
is
970 -- Turn off code generation if not done already
972 if Operating_Mode
= Generate_Code
then
973 Operating_Mode
:= Check_Semantics
;
974 Expander_Active
:= False;
977 -- Set the fatal error flag in the unit table unless we are in
978 -- Try_Semantics mode (in which case we set ignored mode if not
979 -- currently set. This stops the semantics from being performed
980 -- if we find a serious error. This is skipped if we are currently
981 -- dealing with the configuration pragma file.
983 if Current_Source_Unit
/= No_Unit
then
985 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Sptr
);
987 if Try_Semantics
then
988 if Fatal_Error
(U
) = None
then
989 Set_Fatal_Error
(U
, Error_Ignored
);
992 Set_Fatal_Error
(U
, Error_Detected
);
997 -- Disable warnings on unused use clauses and the like. Otherwise, an
998 -- error might hide a reference to an entity in a used package, so
999 -- after fixing the error, the use clause no longer looks like it was
1002 Warnsw
.Check_Unreferenced
:= False;
1003 Warnsw
.Check_Unreferenced_Formals
:= False;
1004 end Handle_Serious_Error
;
1006 -- Start of processing for Error_Msg_Internal
1009 -- Detect common mistake of prefixing or suffixing the message with a
1012 pragma Assert
(Msg
(Msg
'First) /= ' ' and then Msg
(Msg
'Last) /= ' ');
1014 if Raise_Exception_On_Error
/= 0 then
1015 raise Error_Msg_Exception
;
1018 Continuation
:= Msg_Cont
;
1019 Continuation_New_Line
:= False;
1020 Suppress_Message
:= False;
1021 Kill_Message
:= False;
1022 Set_Msg_Text
(Msg
, Sptr
);
1024 -- Kill continuation if parent message killed
1026 if Continuation
and Last_Killed
then
1030 -- Return without doing anything if message is suppressed
1033 and then not All_Errors_Mode
1034 and then not Is_Warning_Msg
1035 and then not Is_Unconditional_Msg
1037 if not Continuation
then
1038 Last_Killed
:= True;
1044 -- Return without doing anything if message is killed and this is not
1045 -- the first error message. The philosophy is that if we get a weird
1046 -- error message and we already have had a message, then we hope the
1047 -- weird message is a junk cascaded message
1050 and then not All_Errors_Mode
1051 and then Total_Errors_Detected
/= 0
1053 if not Continuation
then
1054 Last_Killed
:= True;
1060 -- Special check for warning message to see if it should be output
1062 if Is_Warning_Msg
then
1064 -- Immediate return if warning message and warnings are suppressed
1066 if Warnings_Suppressed
(Optr
) /= No_String
1068 Warnings_Suppressed
(Sptr
) /= No_String
1070 Cur_Msg
:= No_Error_Msg
;
1074 -- If the flag location is in the main extended source unit then for
1075 -- sure we want the warning since it definitely belongs
1077 if In_Extended_Main_Source_Unit
(Sptr
) then
1080 -- If the main unit has not been read yet. The warning must be on
1081 -- a configuration file: gnat.adc or user-defined. This means we
1082 -- are not parsing the main unit yet, so skip following checks.
1084 elsif No
(Cunit
(Main_Unit
)) then
1087 -- If the flag location is not in the extended main source unit, then
1088 -- we want to eliminate the warning, unless it is in the extended
1089 -- main code unit and we want warnings on the instance.
1091 elsif In_Extended_Main_Code_Unit
(Sptr
) and then Warn_On_Instance
then
1094 -- Keep warning if debug flag G set
1096 elsif Debug_Flag_GG
then
1099 -- Keep warning if message text contains !!
1101 elsif Has_Double_Exclam
then
1104 -- Here is where we delete a warning from a with'ed unit
1107 Cur_Msg
:= No_Error_Msg
;
1109 if not Continuation
then
1110 Last_Killed
:= True;
1117 -- If message is to be ignored in special ignore message mode, this is
1118 -- where we do this special processing, bypassing message output.
1120 if Ignore_Errors_Enable
> 0 then
1121 if Is_Serious_Error
then
1122 Handle_Serious_Error
;
1128 -- If error message line length set, and this is a continuation message
1129 -- then all we do is to append the text to the text of the last message
1130 -- with a comma space separator (eliminating a possible (style) or
1133 if Error_Msg_Line_Length
/= 0 and then Continuation
then
1134 Cur_Msg
:= Errors
.Last
;
1137 Oldm
: String_Ptr
:= Errors
.Table
(Cur_Msg
).Text
;
1138 Newm
: String (1 .. Oldm
'Last + 2 + Msglen
);
1143 -- First copy old message to new one and free it
1145 Newm
(Oldm
'Range) := Oldm
.all;
1146 Newl
:= Oldm
'Length;
1149 -- Remove (style) or info: at start of message
1151 if Msglen
> 8 and then Msg_Buffer
(1 .. 8) = "(style) " then
1154 elsif Msglen
> 6 and then Msg_Buffer
(1 .. 6) = "info: " then
1161 -- Now deal with separation between messages. Normally this is
1162 -- simply comma space, but there are some special cases.
1164 -- If continuation new line, then put actual NL character in msg
1166 if Continuation_New_Line
then
1168 Newm
(Newl
) := ASCII
.LF
;
1170 -- If continuation message is enclosed in parentheses, then
1171 -- special treatment (don't need a comma, and we want to combine
1172 -- successive parenthetical remarks into a single one with
1173 -- separating commas).
1175 elsif Msg_Buffer
(M
) = '(' and then Msg_Buffer
(Msglen
) = ')' then
1177 -- Case where existing message ends in right paren, remove
1178 -- and separate parenthetical remarks with a comma.
1180 if Newm
(Newl
) = ')' then
1182 Msg_Buffer
(M
) := ' ';
1184 -- Case where we are adding new parenthetical comment
1191 -- Case where continuation not in parens and no new line
1194 Newm
(Newl
+ 1 .. Newl
+ 2) := ", ";
1198 -- Append new message
1200 Newm
(Newl
+ 1 .. Newl
+ Msglen
- M
+ 1) :=
1201 Msg_Buffer
(M
.. Msglen
);
1202 Newl
:= Newl
+ Msglen
- M
+ 1;
1203 Errors
.Table
(Cur_Msg
).Text
:= new String'(Newm (1 .. Newl));
1205 -- Update warning msg flag and message doc char if needed
1207 if Is_Warning_Msg then
1208 if not Errors.Table (Cur_Msg).Warn then
1209 Errors.Table (Cur_Msg).Warn := True;
1210 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1212 elsif Warning_Msg_Char /= " " then
1213 Errors.Table (Cur_Msg).Warn_Chr := Warning_Msg_Char;
1221 -- Here we build a new error object
1224 ((Text => new String'(Msg_Buffer
(1 .. Msglen
)),
1225 Next
=> No_Error_Msg
,
1226 Prev
=> No_Error_Msg
,
1229 Insertion_Sloc
=> (if Has_Insertion_Line
then Error_Msg_Sloc
1231 Sfile
=> Get_Source_File_Index
(Sptr
),
1232 Line
=> Get_Physical_Line_Number
(Sptr
),
1233 Col
=> Get_Column_Number
(Sptr
),
1234 Compile_Time_Pragma
=> Is_Compile_Time_Msg
,
1235 Warn
=> Is_Warning_Msg
,
1236 Info
=> Is_Info_Msg
,
1237 Check
=> Is_Check_Msg
,
1238 Warn_Err
=> False, -- reset below
1239 Warn_Chr
=> Warning_Msg_Char
,
1240 Warn_Runtime_Raise
=> Is_Runtime_Raise
,
1241 Style
=> Is_Style_Msg
,
1242 Serious
=> Is_Serious_Error
,
1243 Uncond
=> Is_Unconditional_Msg
,
1244 Msg_Cont
=> Continuation
,
1247 Cur_Msg
:= Errors
.Last
;
1249 -- Test if warning to be treated as error
1252 (Is_Warning_Msg
or Is_Style_Msg
)
1253 and then (Warning_Treated_As_Error
(Msg_Buffer
(1 .. Msglen
))
1255 Warning_Treated_As_Error
(Get_Warning_Tag
(Cur_Msg
)));
1257 -- Propagate Warn_Err to this message and preceding continuations.
1258 -- Likewise, propagate Is_Warning_Msg and Is_Runtime_Raise, because the
1259 -- current continued message could have been escalated from warning to
1262 for J
in reverse 1 .. Errors
.Last
loop
1263 Errors
.Table
(J
).Warn_Err
:= Warn_Err
;
1264 Errors
.Table
(J
).Warn
:= Is_Warning_Msg
;
1265 Errors
.Table
(J
).Warn_Runtime_Raise
:= Is_Runtime_Raise
;
1266 exit when not Errors
.Table
(J
).Msg_Cont
;
1269 -- If immediate errors mode set, output error message now. Also output
1270 -- now if the -d1 debug flag is set (so node number message comes out
1271 -- just before actual error message)
1273 if Debug_Flag_OO
or else Debug_Flag_1
then
1276 (Errors
.Table
(Cur_Msg
).Line
, Errors
.Table
(Cur_Msg
).Sfile
, True);
1277 Temp_Msg
:= Cur_Msg
;
1278 Output_Error_Msgs
(Temp_Msg
);
1280 -- If not in immediate errors mode, then we insert the message in the
1281 -- error chain for later output by Finalize. The messages are sorted
1282 -- first by unit (main unit comes first), and within a unit by source
1283 -- location (earlier flag location first in the chain).
1286 -- First a quick check, does this belong at the very end of the chain
1287 -- of error messages. This saves a lot of time in the normal case if
1288 -- there are lots of messages.
1290 if Last_Error_Msg
/= No_Error_Msg
1291 and then Errors
.Table
(Cur_Msg
).Sfile
=
1292 Errors
.Table
(Last_Error_Msg
).Sfile
1293 and then (Sptr
> Errors
.Table
(Last_Error_Msg
).Sptr
.Ptr
1295 (Sptr
= Errors
.Table
(Last_Error_Msg
).Sptr
.Ptr
1297 Optr
> Errors
.Table
(Last_Error_Msg
).Optr
.Ptr
))
1299 Prev_Msg
:= Last_Error_Msg
;
1300 Next_Msg
:= No_Error_Msg
;
1302 -- Otherwise do a full sequential search for the insertion point
1305 Prev_Msg
:= No_Error_Msg
;
1306 Next_Msg
:= First_Error_Msg
;
1307 while Next_Msg
/= No_Error_Msg
loop
1309 Errors
.Table
(Cur_Msg
).Sfile
< Errors
.Table
(Next_Msg
).Sfile
;
1311 if Errors
.Table
(Cur_Msg
).Sfile
= Errors
.Table
(Next_Msg
).Sfile
1313 exit when Sptr
< Errors
.Table
(Next_Msg
).Sptr
.Ptr
1314 or else (Sptr
= Errors
.Table
(Next_Msg
).Sptr
.Ptr
1316 Optr
< Errors
.Table
(Next_Msg
).Optr
.Ptr
);
1319 Prev_Msg
:= Next_Msg
;
1320 Next_Msg
:= Errors
.Table
(Next_Msg
).Next
;
1324 -- Now we insert the new message in the error chain.
1326 -- The possible insertion point for the new message is after Prev_Msg
1327 -- and before Next_Msg. However, this is where we do a special check
1328 -- for redundant parsing messages, defined as messages posted on the
1329 -- same line. The idea here is that probably such messages are junk
1330 -- from the parser recovering. In full errors mode, we don't do this
1331 -- deletion, but otherwise such messages are discarded at this stage.
1333 if Prev_Msg
/= No_Error_Msg
1334 and then Errors
.Table
(Prev_Msg
).Line
=
1335 Errors
.Table
(Cur_Msg
).Line
1336 and then Errors
.Table
(Prev_Msg
).Sfile
=
1337 Errors
.Table
(Cur_Msg
).Sfile
1338 and then Compiler_State
= Parsing
1339 and then not All_Errors_Mode
1341 -- Don't delete unconditional messages and at this stage, don't
1342 -- delete continuation lines; we attempted to delete those earlier
1343 -- if the parent message was deleted.
1345 if not Errors
.Table
(Cur_Msg
).Uncond
1346 and then not Continuation
1348 -- Don't delete if prev msg is warning and new msg is an error.
1349 -- This is because we don't want a real error masked by a
1350 -- warning. In all other cases (that is parse errors for the
1351 -- same line that are not unconditional) we do delete the
1352 -- message. This helps to avoid junk extra messages from
1353 -- cascaded parsing errors
1355 if not (Errors
.Table
(Prev_Msg
).Warn
1357 Errors
.Table
(Prev_Msg
).Style
)
1359 (Errors
.Table
(Cur_Msg
).Warn
1361 Errors
.Table
(Cur_Msg
).Style
)
1363 -- All tests passed, delete the message by simply returning
1364 -- without any further processing.
1366 pragma Assert
(not Continuation
);
1368 Last_Killed
:= True;
1374 -- Come here if message is to be inserted in the error chain
1376 if not Continuation
then
1377 Last_Killed
:= False;
1380 if Prev_Msg
= No_Error_Msg
then
1381 First_Error_Msg
:= Cur_Msg
;
1383 Errors
.Table
(Prev_Msg
).Next
:= Cur_Msg
;
1386 Errors
.Table
(Cur_Msg
).Next
:= Next_Msg
;
1388 if Next_Msg
= No_Error_Msg
then
1389 Last_Error_Msg
:= Cur_Msg
;
1393 -- Bump appropriate statistics counts
1395 if Errors
.Table
(Cur_Msg
).Info
then
1397 -- Could be (usually is) both "info" and "warning"
1399 if Errors
.Table
(Cur_Msg
).Warn
then
1400 Warning_Info_Messages
:= Warning_Info_Messages
+ 1;
1401 Warnings_Detected
:= Warnings_Detected
+ 1;
1403 Report_Info_Messages
:= Report_Info_Messages
+ 1;
1406 elsif Errors
.Table
(Cur_Msg
).Warn
1407 or else Errors
.Table
(Cur_Msg
).Style
1409 Warnings_Detected
:= Warnings_Detected
+ 1;
1411 elsif Errors
.Table
(Cur_Msg
).Check
then
1412 Check_Messages
:= Check_Messages
+ 1;
1415 Total_Errors_Detected
:= Total_Errors_Detected
+ 1;
1417 if Errors
.Table
(Cur_Msg
).Serious
then
1418 Serious_Errors_Detected
:= Serious_Errors_Detected
+ 1;
1419 Handle_Serious_Error
;
1421 -- If not serious error, set Fatal_Error to indicate ignored error
1425 U
: constant Unit_Number_Type
:= Get_Source_Unit
(Sptr
);
1427 if Fatal_Error
(U
) = None
then
1428 Set_Fatal_Error
(U
, Error_Ignored
);
1434 -- Record warning message issued
1436 if Errors
.Table
(Cur_Msg
).Warn
1437 and then not Errors
.Table
(Cur_Msg
).Msg_Cont
1439 Warning_Msg
:= Cur_Msg
;
1442 -- If too many warnings turn off warnings
1444 if Maximum_Messages
/= 0 then
1445 if Warnings_Detected
= Maximum_Messages
then
1446 Warning_Mode
:= Suppress
;
1449 -- If too many errors abandon compilation
1451 if Total_Errors_Detected
= Maximum_Messages
then
1452 raise Unrecoverable_Error
;
1456 if Has_Error_Code
then
1458 Msg
: constant String :=
1459 "\launch ""gnatprove --explain=[]"" for more information";
1461 Has_Double_Exclam
:= False;
1462 Has_Error_Code
:= False;
1463 Has_Insertion_Line
:= False;
1473 end Error_Msg_Internal
;
1479 procedure Error_Msg_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
1482 First_And_Last_Nodes
(N
, Fst
, Lst
);
1483 Error_Msg_NEL
(Msg
, N
, N
,
1484 To_Span
(Ptr
=> Sloc
(N
),
1485 First
=> First_Sloc
(Fst
),
1486 Last
=> Last_Sloc
(Lst
)));
1493 procedure Error_Msg_NE
1495 N
: Node_Or_Entity_Id
;
1496 E
: Node_Or_Entity_Id
)
1500 First_And_Last_Nodes
(N
, Fst
, Lst
);
1501 Error_Msg_NEL
(Msg
, N
, E
,
1502 To_Span
(Ptr
=> Sloc
(N
),
1503 First
=> First_Sloc
(Fst
),
1504 Last
=> Last_Sloc
(Lst
)));
1511 procedure Error_Msg_NEL
1513 N
: Node_Or_Entity_Id
;
1514 E
: Node_Or_Entity_Id
;
1515 Flag_Location
: Source_Ptr
)
1519 First_And_Last_Nodes
(N
, Fst
, Lst
);
1522 To_Span
(Ptr
=> Flag_Location
,
1523 First
=> Source_Ptr
'Min (Flag_Location
, First_Sloc
(Fst
)),
1524 Last
=> Source_Ptr
'Max (Flag_Location
, Last_Sloc
(Lst
))));
1527 procedure Error_Msg_NEL
1529 N
: Node_Or_Entity_Id
;
1530 E
: Node_Or_Entity_Id
;
1531 Flag_Span
: Source_Span
)
1534 if Special_Msg_Delete
(Msg
, N
, E
) then
1538 Prescan_Message
(Msg
);
1540 -- Special handling for warning messages
1542 if Is_Warning_Msg
then
1544 -- Suppress if no warnings set for either entity or node
1546 if No_Warnings
(N
) or else No_Warnings
(E
) then
1548 -- Disable any continuation messages as well
1550 Last_Killed
:= True;
1555 -- Test for message to be output
1558 or else Is_Unconditional_Msg
1559 or else Is_Warning_Msg
1561 or else (Msg
(Msg
'First) = '\' and then not Last_Killed
)
1564 Error_Msg_Node_1
:= E
;
1565 Error_Msg
(Msg
, Flag_Span
, N
);
1568 Last_Killed
:= True;
1571 if not Get_Ignore_Errors
then
1580 procedure Error_Msg_NW
1583 N
: Node_Or_Entity_Id
)
1588 and then In_Extended_Main_Source_Unit
(N
)
1589 and then Comes_From_Source
(N
)
1591 First_And_Last_Nodes
(N
, Fst
, Lst
);
1592 Error_Msg_NEL
(Msg
, N
, N
,
1593 To_Span
(Ptr
=> Sloc
(N
),
1594 First
=> First_Sloc
(Fst
),
1595 Last
=> Last_Sloc
(Lst
)));
1603 procedure Error_Msg_S
(Msg
: String) is
1605 Error_Msg
(Msg
, Scan_Ptr
);
1612 procedure Error_Msg_SC
(Msg
: String) is
1614 -- If we are at end of file, post the flag after the previous token
1616 if Token
= Tok_EOF
then
1619 -- For all other cases the message is posted at the current token
1623 Error_Msg
(Msg
, Token_Ptr
);
1631 procedure Error_Msg_SP
(Msg
: String) is
1633 -- Note: in the case where there is no previous token, Prev_Token_Ptr
1634 -- is set to Source_First, which is a reasonable position for the
1635 -- error flag in this situation
1637 Error_Msg
(Msg
, Prev_Token_Ptr
);
1644 procedure Finalize
(Last_Call
: Boolean) is
1649 procedure Delete_Warning
(E
: Error_Msg_Id
);
1650 -- Delete a warning msg if not already deleted and adjust warning count
1652 --------------------
1653 -- Delete_Warning --
1654 --------------------
1656 procedure Delete_Warning
(E
: Error_Msg_Id
) is
1658 if not Errors
.Table
(E
).Deleted
then
1659 Errors
.Table
(E
).Deleted
:= True;
1660 Warnings_Detected
:= Warnings_Detected
- 1;
1662 if Errors
.Table
(E
).Info
then
1663 Warning_Info_Messages
:= Warning_Info_Messages
- 1;
1668 -- Start of processing for Finalize
1671 -- Set Prev pointers
1673 Cur
:= First_Error_Msg
;
1674 while Cur
/= No_Error_Msg
loop
1675 Nxt
:= Errors
.Table
(Cur
).Next
;
1676 exit when Nxt
= No_Error_Msg
;
1677 Errors
.Table
(Nxt
).Prev
:= Cur
;
1681 -- Eliminate any duplicated error messages from the list. This is
1682 -- done after the fact to avoid problems with Change_Error_Text.
1684 Cur
:= First_Error_Msg
;
1685 while Cur
/= No_Error_Msg
loop
1686 Nxt
:= Errors
.Table
(Cur
).Next
;
1689 while F
/= No_Error_Msg
1690 and then Errors
.Table
(F
).Sptr
.Ptr
= Errors
.Table
(Cur
).Sptr
.Ptr
1692 Check_Duplicate_Message
(Cur
, F
);
1693 F
:= Errors
.Table
(F
).Next
;
1699 -- Mark any messages suppressed by specific warnings as Deleted
1701 Cur
:= First_Error_Msg
;
1702 while Cur
/= No_Error_Msg
loop
1704 CE
: Error_Msg_Object
renames Errors
.Table
(Cur
);
1705 Tag
: constant String := Get_Warning_Tag
(Cur
);
1708 if (CE
.Warn
and not CE
.Deleted
)
1710 (Warning_Specifically_Suppressed
(CE
.Sptr
.Ptr
, CE
.Text
, Tag
)
1713 Warning_Specifically_Suppressed
(CE
.Optr
.Ptr
, CE
.Text
, Tag
)
1716 Delete_Warning
(Cur
);
1718 -- If this is a continuation, delete previous parts of message
1721 while Errors
.Table
(F
).Msg_Cont
loop
1722 F
:= Errors
.Table
(F
).Prev
;
1723 exit when F
= No_Error_Msg
;
1727 -- Delete any following continuations
1731 F
:= Errors
.Table
(F
).Next
;
1732 exit when F
= No_Error_Msg
;
1733 exit when not Errors
.Table
(F
).Msg_Cont
;
1739 Cur
:= Errors
.Table
(Cur
).Next
;
1742 Finalize_Called
:= True;
1744 -- Check consistency of specific warnings (may add warnings). We only
1745 -- do this on the last call, after all possible warnings are posted.
1748 Validate_Specific_Warnings
(Error_Msg
'Access);
1756 function First_Node
(C
: Node_Id
) return Node_Id
is
1759 First_And_Last_Nodes
(C
, Fst
, Lst
);
1763 --------------------------
1764 -- First_And_Last_Nodes --
1765 --------------------------
1767 procedure First_And_Last_Nodes
1769 First_Node
, Last_Node
: out Node_Id
)
1771 Orig
: constant Node_Id
:= Original_Node
(C
);
1772 Loc
: constant Source_Ptr
:= Sloc
(Orig
);
1773 Sfile
: constant Source_File_Index
:= Get_Source_File_Index
(Loc
);
1779 function Test_First_And_Last
(N
: Node_Id
) return Traverse_Result
;
1780 -- Function applied to every node in the construct
1782 procedure Search_Tree_First_And_Last
is new
1783 Traverse_Proc
(Test_First_And_Last
);
1784 -- Create traversal procedure
1786 -------------------------
1787 -- Test_First_And_Last --
1788 -------------------------
1790 function Test_First_And_Last
(N
: Node_Id
) return Traverse_Result
is
1791 Norig
: constant Node_Id
:= Original_Node
(N
);
1792 Loc
: constant Source_Ptr
:= Sloc
(Norig
);
1795 -- ??? For assignments that require accessiblity checks, e.g.:
1799 -- the function call gets an extra actual parameter association with
1800 -- Sloc of the assigned name "Y":
1802 -- Y := Func (123, A8b => 2);
1804 -- We can simply ignore those extra actual parameters when
1805 -- determining the Sloc range of the "Func (123)" expression.
1807 if Nkind
(N
) = N_Parameter_Association
1808 and then Is_Accessibility_Actual
(N
)
1813 -- Check for earlier
1817 -- Ignore nodes with no useful location information
1819 and then Loc
/= Standard_Location
1820 and then Loc
/= No_Location
1822 -- Ignore nodes from a different file. This ensures against cases
1823 -- of strange foreign code somehow being present. We don't want
1824 -- wild placement of messages if that happens.
1826 and then Get_Source_File_Index
(Loc
) = Sfile
1836 -- Ignore nodes with no useful location information
1838 and then Loc
/= Standard_Location
1839 and then Loc
/= No_Location
1841 -- Ignore nodes from a different file. This ensures against cases
1842 -- of strange foreign code somehow being present. We don't want
1843 -- wild placement of messages if that happens.
1845 and then Get_Source_File_Index
(Loc
) = Sfile
1852 end Test_First_And_Last
;
1854 -- Start of processing for First_And_Last_Nodes
1857 if Nkind
(Orig
) in N_Subexpr
1859 | N_Access_To_Subprogram_Definition
1860 | N_Generic_Instantiation
1862 | N_Use_Package_Clause
1863 | N_Array_Type_Definition
1864 | N_Renaming_Declaration
1865 | N_Generic_Renaming_Declaration
1866 | N_Assignment_Statement
1868 | N_Simple_Return_Statement
1873 | N_Attribute_Definition_Clause
1874 | N_Subtype_Indication
1880 Search_Tree_First_And_Last
(Orig
);
1881 First_Node
:= Earliest
;
1882 Last_Node
:= Latest
;
1888 end First_And_Last_Nodes
;
1894 function First_Sloc
(N
: Node_Id
) return Source_Ptr
is
1895 SI
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
1896 SF
: constant Source_Ptr
:= Source_First
(SI
);
1897 SL
: constant Source_Ptr
:= Source_Last
(SI
);
1898 Src
: constant Source_Buffer_Ptr
:= Source_Text
(SI
);
1903 F
:= First_Node
(N
);
1906 if S
not in SF
.. SL
then
1910 -- The following circuit is a bit subtle. When we have parenthesized
1911 -- expressions, then the Sloc will not record the location of the paren,
1912 -- but we would like to post the flag on the paren. So what we do is to
1913 -- crawl up the tree from the First_Node, adjusting the Sloc value for
1914 -- any parentheses we know are present. Yes, we know this circuit is not
1915 -- 100% reliable (e.g. because we don't record all possible paren level
1916 -- values), but this is only for an error message so it is good enough.
1919 -- Include parentheses around the top node, except when they are
1920 -- required by the syntax of the parent node.
1922 exit Node_Loop
when F
= N
1923 and then Paren_Required
(N
);
1925 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
1927 -- We don't look more than 12 characters behind the current
1928 -- location, and in any case not past the front of the source.
1930 Search_Loop
: for K
in 1 .. 12 loop
1931 exit Search_Loop
when S
= SF
;
1933 if Src
(S
- 1) = '(' then
1937 elsif Src
(S
- 1) <= ' ' then
1943 end loop Search_Loop
;
1944 end loop Paren_Loop
;
1946 exit Node_Loop
when F
= N
;
1948 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
1954 -----------------------
1955 -- Get_Ignore_Errors --
1956 -----------------------
1958 function Get_Ignore_Errors
return Boolean is
1960 return Errors_Must_Be_Ignored
;
1961 end Get_Ignore_Errors
;
1967 procedure Initialize
is
1970 First_Error_Msg
:= No_Error_Msg
;
1971 Last_Error_Msg
:= No_Error_Msg
;
1972 Serious_Errors_Detected
:= 0;
1973 Total_Errors_Detected
:= 0;
1974 Cur_Msg
:= No_Error_Msg
;
1977 -- Reset counts for warnings
1979 Warnings_Treated_As_Errors
:= 0;
1980 Warnings_Detected
:= 0;
1981 Warning_Info_Messages
:= 0;
1982 Warnings_As_Errors_Count
:= 0;
1984 -- Initialize warnings tables
1987 Specific_Warnings
.Init
;
1990 -------------------------------
1991 -- Is_Size_Too_Small_Message --
1992 -------------------------------
1994 function Is_Size_Too_Small_Message
(S
: String) return Boolean is
1995 Size_For
: constant String := "size for";
1996 pragma Assert
(Size_Too_Small_Message
(1 .. Size_For
'Last) = Size_For
);
1997 -- Assert that Size_Too_Small_Message starts with Size_For
1999 return S
'Length >= Size_For
'Length
2000 and then S
(S
'First .. S
'First + Size_For
'Length - 1) = Size_For
;
2001 -- True if S starts with Size_For
2002 end Is_Size_Too_Small_Message
;
2008 function Last_Node
(C
: Node_Id
) return Node_Id
is
2011 First_And_Last_Nodes
(C
, Fst
, Lst
);
2019 function Last_Sloc
(N
: Node_Id
) return Source_Ptr
is
2020 procedure Skip_Char
(S
: in out Source_Ptr
);
2021 -- Skip one character of the source buffer at location S
2027 procedure Skip_Char
(S
: in out Source_Ptr
) is
2034 SI
: constant Source_File_Index
:= Get_Source_File_Index
(Sloc
(N
));
2035 SF
: constant Source_Ptr
:= Source_First
(SI
);
2036 SL
: constant Source_Ptr
:= Source_Last
(SI
);
2037 Src
: constant Source_Buffer_Ptr
:= Source_Text
(SI
);
2041 -- Start of processing for Last_Sloc
2047 if S
not in SF
.. SL
then
2051 -- For string and character literals simply forward the sloc by their
2052 -- length including the closing quotes. Perhaps we should do something
2053 -- special for multibyte characters, but this code is only used to emit
2054 -- error messages, so it is not worth the effort.
2057 when N_String_Literal
=>
2058 return S
+ Source_Ptr
(String_Length
(Strval
(F
))) + 1;
2060 when N_Character_Literal
=>
2063 -- Skip past integer literals, both decimal and based, integer and
2064 -- real. We can't greedily accept all allowed character, because
2065 -- we would consme too many of them in expressions like "123+ABC"
2066 -- or "123..456", so we follow quite precisely the Ada grammar and
2067 -- consume different characters depending on the context.
2069 when N_Integer_Literal
=>
2071 -- Skip past the initial numeral, which either leads the decimal
2072 -- literal or is the base of a based literal.
2075 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2080 -- Skip past #based_numeral#, if present
2083 and then Src
(S
+ 1) = '#'
2089 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2095 and then Src
(S
+ 1) = '#'
2101 -- Skip past exponent, if present
2104 and then Src
(S
+ 1) in 'e' |
'E'
2108 -- For positive exponents the plus sign is optional, but we
2109 -- can simply skip past both plus and minus.
2112 and then Src
(S
+ 1) in '+' |
'-'
2117 -- Skip past the numeral part
2120 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2126 when N_Real_Literal
=>
2127 -- Skip past the initial numeral, which either leads the decimal
2128 -- literal or is the base of a based literal.
2131 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2138 -- Skip the dot and continue with a decimal literal
2140 if Src
(S
+ 1) = '.' then
2144 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2149 -- Skip the hash and continue with a based literal
2151 elsif Src
(S
+ 1) = '#' then
2156 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2162 and then Src
(S
+ 1) = '.'
2169 Src
(S
+ 1) in '0' .. '9' |
'a' .. 'f' |
'A' .. 'F' |
'_'
2175 and then Src
(S
+ 1) = '#'
2182 -- Skip past exponent, if present
2185 and then Src
(S
+ 1) in 'e' |
'E'
2188 -- For positive exponents the plus sign is optional, but we
2189 -- can simply skip past both plus and minus.
2191 if Src
(S
+ 1) in '+' |
'-' then
2195 -- Skip past the numeral part
2198 and then Src
(S
+ 1) in '0' .. '9' |
'_'
2204 -- For other nodes simply skip past a keyword/identifier
2207 while S
in SF
.. SL
- 1
2208 and then Src
(S
+ 1)
2210 '0' .. '9' |
'a' .. 'z' |
'A' .. 'Z' |
'_'
2216 -- The following circuit attempts at crawling up the tree from the
2217 -- Last_Node, adjusting the Sloc value for any parentheses we know
2218 -- are present, similarly to what is done in First_Sloc.
2221 -- Include parentheses around the top node, except when they are
2222 -- required by the syntax of the parent node.
2224 exit Node_Loop
when F
= N
2225 and then Paren_Required
(N
);
2227 Paren_Loop
: for J
in 1 .. Paren_Count
(F
) loop
2229 -- We don't look more than 12 characters after the current
2232 Search_Loop
: for K
in 1 .. 12 loop
2233 exit Node_Loop
when S
= SL
;
2235 if Src
(S
+ 1) = ')' then
2239 elsif Src
(S
+ 1) <= ' ' then
2245 end loop Search_Loop
;
2246 end loop Paren_Loop
;
2248 exit Node_Loop
when F
= N
;
2250 exit Node_Loop
when Nkind
(F
) not in N_Subexpr
;
2253 -- Remove any trailing space
2255 while S
in SF
+ 1 .. SL
2256 and then Src
(S
) = ' '
2268 function No_Warnings
(N
: Node_Or_Entity_Id
) return Boolean is
2270 if Error_Posted
(N
) then
2273 elsif Nkind
(N
) in N_Entity
and then Has_Warnings_Off
(N
) then
2276 elsif Is_Entity_Name
(N
)
2277 and then Present
(Entity
(N
))
2278 and then Has_Warnings_Off
(Entity
(N
))
2291 function OK_Node
(N
: Node_Id
) return Boolean is
2292 K
: constant Node_Kind
:= Nkind
(N
);
2295 if Error_Posted
(N
) then
2298 elsif K
in N_Has_Etype
2299 and then Present
(Etype
(N
))
2300 and then Error_Posted
(Etype
(N
))
2305 or else K
= N_Attribute_Reference
2306 or else K
= N_Character_Literal
2307 or else K
= N_Expanded_Name
2308 or else K
= N_Identifier
2309 or else K
= N_Operator_Symbol
)
2310 and then Present
(Entity
(N
))
2311 and then Error_Posted
(Entity
(N
))
2319 -------------------------
2320 -- Output_JSON_Message --
2321 -------------------------
2323 procedure Output_JSON_Message
(Error_Id
: Error_Msg_Id
) is
2325 function Is_Continuation
(E
: Error_Msg_Id
) return Boolean;
2326 -- Return True if E is a continuation message.
2328 procedure Write_JSON_Escaped_String
(Str
: String_Ptr
);
2329 procedure Write_JSON_Escaped_String
(Str
: String);
2330 -- Write each character of Str, taking care of preceding each quote and
2331 -- backslash with a backslash. Note that this escaping differs from what
2334 -- Indeed, the JSON specification mandates encoding wide characters
2335 -- either as their direct UTF-8 representation or as their escaped
2336 -- UTF-16 surrogate pairs representation. GCC seems to prefer escaping -
2337 -- we choose to use the UTF-8 representation instead.
2339 procedure Write_JSON_Location
(Sptr
: Source_Ptr
);
2340 -- Write Sptr as a JSON location, an object containing a file attribute,
2341 -- a line number and a column number.
2343 procedure Write_JSON_Span
(Error
: Error_Msg_Object
);
2344 -- Write Error as a JSON span, an object containing a "caret" attribute
2345 -- whose value is the JSON location of Error.Sptr.Ptr. If Sptr.First and
2346 -- Sptr.Last are different from Sptr.Ptr, they will be printed as JSON
2347 -- locations under the names "start" and "finish".
2348 -- When Include_Subprogram_In_Messages is true (-gnatdJ) an additional,
2349 -- non-standard, attribute named "subprogram" will be added, allowing
2350 -- precisely identifying the subprogram surrounding the span.
2352 -----------------------
2353 -- Is_Continuation --
2354 -----------------------
2356 function Is_Continuation
(E
: Error_Msg_Id
) return Boolean is
2358 return E
<= Last_Error_Msg
and then Errors
.Table
(E
).Msg_Cont
;
2359 end Is_Continuation
;
2361 -------------------------------
2362 -- Write_JSON_Escaped_String --
2363 -------------------------------
2365 procedure Write_JSON_Escaped_String
(Str
: String) is
2368 if C
= '"' or else C
= '\' then
2374 end Write_JSON_Escaped_String
;
2376 -------------------------------
2377 -- Write_JSON_Escaped_String --
2378 -------------------------------
2380 procedure Write_JSON_Escaped_String
(Str
: String_Ptr
) is
2382 Write_JSON_Escaped_String
(Str
.all);
2383 end Write_JSON_Escaped_String
;
2385 -------------------------
2386 -- Write_JSON_Location --
2387 -------------------------
2389 procedure Write_JSON_Location
(Sptr
: Source_Ptr
) is
2390 Name
: constant File_Name_Type
:=
2391 Full_Ref_Name
(Get_Source_File_Index
(Sptr
));
2393 Write_Str
("{""file"":""");
2394 if Full_Path_Name_For_Brief_Errors
then
2395 Write_JSON_Escaped_String
2396 (System
.OS_Lib
.Normalize_Pathname
(Get_Name_String
(Name
)));
2400 Write_Str
(""",""line"":");
2401 Write_Int
(Pos
(Get_Physical_Line_Number
(Sptr
)));
2402 Write_Str
(", ""column"":");
2403 Write_Int
(Nat
(Get_Column_Number
(Sptr
)));
2405 end Write_JSON_Location
;
2407 ---------------------
2408 -- Write_JSON_Span --
2409 ---------------------
2411 procedure Write_JSON_Span
(Error
: Error_Msg_Object
) is
2412 Span
: constant Source_Span
:= Error
.Sptr
;
2414 Write_Str
("{""caret"":");
2415 Write_JSON_Location
(Span
.Ptr
);
2417 if Span
.Ptr
/= Span
.First
then
2418 Write_Str
(",""start"":");
2419 Write_JSON_Location
(Span
.First
);
2422 if Span
.Ptr
/= Span
.Last
then
2423 Write_Str
(",""finish"":");
2424 Write_JSON_Location
(Span
.Last
);
2427 if Include_Subprogram_In_Messages
then
2428 Write_Str
(",""subprogram"":""");
2429 Write_JSON_Escaped_String
(Subprogram_Name_Ptr
(Error
.Node
));
2434 end Write_JSON_Span
;
2438 E
: Error_Msg_Id
:= Error_Id
;
2440 Print_Continuations
: constant Boolean := not Is_Continuation
(E
);
2441 -- Do not print continuations messages as children of the current
2442 -- message if the current message is a continuation message.
2444 Option
: constant String := Get_Warning_Option
(E
);
2445 -- The option that triggered this message.
2447 -- Start of processing for Output_JSON_Message
2451 -- Print message kind
2453 Write_Str
("{""kind"":");
2455 if Errors
.Table
(E
).Warn
and then not Errors
.Table
(E
).Warn_Err
then
2456 Write_Str
("""warning""");
2457 elsif Errors
.Table
(E
).Info
or else Errors
.Table
(E
).Check
then
2458 Write_Str
("""note""");
2460 Write_Str
("""error""");
2463 -- Print message location
2465 Write_Str
(",""locations"":[");
2466 Write_JSON_Span
(Errors
.Table
(E
));
2468 if Errors
.Table
(E
).Optr
.Ptr
/= Errors
.Table
(E
).Sptr
.Ptr
then
2469 Write_Str
(",{""caret"":");
2470 Write_JSON_Location
(Errors
.Table
(E
).Optr
.Ptr
);
2476 -- Print message option, if there is one
2477 if Option
/= "" then
2478 Write_Str
(",""option"":""" & Option
& """");
2481 -- Print message content
2483 Write_Str
(",""message"":""");
2484 Write_JSON_Escaped_String
(Errors
.Table
(E
).Text
);
2489 if Print_Continuations
and then Is_Continuation
(E
) then
2491 Write_Str
(",""children"": [");
2492 Output_JSON_Message
(E
);
2495 while Is_Continuation
(E
) loop
2497 Output_JSON_Message
(E
);
2506 end Output_JSON_Message
;
2508 ---------------------
2509 -- Output_Messages --
2510 ---------------------
2512 procedure Output_Messages
is
2514 -- Local subprograms
2516 procedure Write_Error_Summary
;
2517 -- Write error summary
2519 procedure Write_Header
(Sfile
: Source_File_Index
);
2520 -- Write header line (compiling or checking given file)
2522 procedure Write_Max_Errors
;
2523 -- Write message if max errors reached
2525 procedure Write_Source_Code_Lines
2526 (Span
: Source_Span
;
2528 -- Write the source code line corresponding to Span, as follows when
2529 -- Span in on one line:
2531 -- line | actual code line here with Span somewhere
2534 -- where the caret on the line points to location Span.Ptr, and the
2535 -- range Span.First..Span.Last is underlined.
2537 -- or when the span is over multiple lines:
2539 -- line | beginning of the Span on this line
2541 -- line>| actual code line here with Span.Ptr somewhere
2543 -- line | end of the Span on this line
2545 -- or when the span is a simple location, as follows:
2547 -- line | actual code line here with Span somewhere
2550 -- where the caret on the line points to location Span.Ptr
2552 -- SGR_Span is the SGR string to start the section of code in the span,
2553 -- that should be closed with SGR_Reset.
2555 -------------------------
2556 -- Write_Error_Summary --
2557 -------------------------
2559 procedure Write_Error_Summary
is
2561 -- Extra blank line if error messages or source listing were output
2563 if Total_Errors_Detected
+ Warnings_Detected
> 0 or else Full_List
2568 -- Message giving number of lines read and number of errors detected.
2569 -- This normally goes to Standard_Output. The exception is when brief
2570 -- mode is not set, verbose mode (or full list mode) is set, and
2571 -- there are errors. In this case we send the message to standard
2572 -- error to make sure that *something* appears on standard error
2573 -- in an error situation.
2575 if Total_Errors_Detected
+ Warnings_Detected
/= 0
2576 and then not Brief_Output
2577 and then (Verbose_Mode
or Full_List
)
2582 -- Message giving total number of lines. Don't give this message if
2583 -- the Main_Source line is unknown (this happens in error situations,
2584 -- e.g. when integrated preprocessing fails).
2586 if Main_Source_File
> No_Source_File
then
2588 Write_Int
(Num_Source_Lines
(Main_Source_File
));
2590 if Num_Source_Lines
(Main_Source_File
) = 1 then
2591 Write_Str
(" line: ");
2593 Write_Str
(" lines: ");
2597 if Total_Errors_Detected
= 0 then
2598 Write_Str
("No errors");
2600 elsif Total_Errors_Detected
= 1 then
2601 Write_Str
("1 error");
2604 Write_Int
(Total_Errors_Detected
);
2605 Write_Str
(" errors");
2608 -- We now need to output warnings. When using -gnatwe, all warnings
2609 -- should be treated as errors, except for warnings originating from
2610 -- the use of the Compile_Time_Warning pragma. Another situation
2611 -- where a warning might be treated as an error is when the source
2612 -- code contains a Warning_As_Error pragma.
2613 -- When warnings are treated as errors, we still log them as
2614 -- warnings, but we add a message denoting how many of these warnings
2618 Warnings_Count
: constant Int
:=
2619 Warnings_Detected
- Warning_Info_Messages
;
2621 Compile_Time_Warnings
: Int
;
2622 -- Number of warnings that come from a Compile_Time_Warning
2625 Non_Compile_Time_Warnings
: Int
;
2626 -- Number of warnings that do not come from a Compile_Time_Warning
2630 if Warnings_Count
> 0 then
2632 Write_Int
(Warnings_Count
);
2633 Write_Str
(" warning");
2635 if Warnings_Count
> 1 then
2639 Compile_Time_Warnings
:= Count_Compile_Time_Pragma_Warnings
;
2640 Non_Compile_Time_Warnings
:=
2641 Warnings_Count
- Compile_Time_Warnings
;
2643 if Warning_Mode
= Treat_As_Error
2644 and then Non_Compile_Time_Warnings
> 0
2648 if Compile_Time_Warnings
> 0 then
2649 Write_Int
(Non_Compile_Time_Warnings
);
2653 Write_Str
("treated as error");
2655 if Non_Compile_Time_Warnings
> 1 then
2661 elsif Warnings_Treated_As_Errors
> 0 then
2664 if Warnings_Treated_As_Errors
/= Warnings_Count
then
2665 Write_Int
(Warnings_Treated_As_Errors
);
2669 Write_Str
("treated as error");
2671 if Warnings_Treated_As_Errors
> 1 then
2680 if Warning_Info_Messages
+ Report_Info_Messages
/= 0 then
2682 Write_Int
(Warning_Info_Messages
+ Report_Info_Messages
);
2683 Write_Str
(" info message");
2685 if Warning_Info_Messages
+ Report_Info_Messages
> 1 then
2691 Set_Standard_Output
;
2692 end Write_Error_Summary
;
2698 procedure Write_Header
(Sfile
: Source_File_Index
) is
2700 if Verbose_Mode
or Full_List
then
2701 if Original_Operating_Mode
= Generate_Code
then
2702 Write_Str
("Compiling: ");
2704 Write_Str
("Checking: ");
2707 Write_Name
(Full_File_Name
(Sfile
));
2709 if not Debug_Flag_7
then
2711 Write_Str
("Source file time stamp: ");
2712 Write_Time_Stamp
(Sfile
);
2714 Write_Str
("Compiled at: " & Compilation_Time
);
2721 ----------------------
2722 -- Write_Max_Errors --
2723 ----------------------
2725 procedure Write_Max_Errors
is
2727 if Maximum_Messages
/= 0 then
2728 if Warnings_Detected
>= Maximum_Messages
then
2730 Write_Line
("maximum number of warnings output");
2731 Write_Line
("any further warnings suppressed");
2732 Set_Standard_Output
;
2735 -- If too many errors print message
2737 if Total_Errors_Detected
>= Maximum_Messages
then
2739 Write_Line
("fatal error: maximum number of errors detected");
2740 Set_Standard_Output
;
2743 end Write_Max_Errors
;
2745 -----------------------------
2746 -- Write_Source_Code_Lines --
2747 -----------------------------
2749 procedure Write_Source_Code_Lines
2750 (Span
: Source_Span
;
2753 function Get_Line_End
2754 (Buf
: Source_Buffer_Ptr
;
2755 Loc
: Source_Ptr
) return Source_Ptr
;
2756 -- Get the source location for the end of the line in Buf for Loc. If
2757 -- Loc is past the end of Buf already, return Buf'Last.
2759 function Get_Line_Start
2760 (Buf
: Source_Buffer_Ptr
;
2761 Loc
: Source_Ptr
) return Source_Ptr
;
2762 -- Get the source location for the start of the line in Buf for Loc
2764 function Image
(X
: Positive; Width
: Positive) return String;
2765 -- Output number X over Width characters, with whitespace padding.
2766 -- Only output the low-order Width digits of X, if X is larger than
2769 procedure Write_Buffer
2770 (Buf
: Source_Buffer_Ptr
;
2773 -- Output the characters from First to Last position in Buf, using
2774 -- Write_Buffer_Char.
2776 procedure Write_Buffer_Char
2777 (Buf
: Source_Buffer_Ptr
;
2779 -- Output the characters at position Loc in Buf, translating ASCII.HT
2780 -- in a suitable number of spaces so that the output is not modified
2781 -- by starting in a different column that 1.
2783 procedure Write_Line_Marker
2787 -- Output the line number Num over Width characters, with possibly
2788 -- a Mark to denote the line with the main location when reporting
2789 -- a span over multiple lines.
2795 function Get_Line_End
2796 (Buf
: Source_Buffer_Ptr
;
2797 Loc
: Source_Ptr
) return Source_Ptr
2799 Cur_Loc
: Source_Ptr
:= Source_Ptr
'Min (Loc
, Buf
'Last);
2801 while Cur_Loc
< Buf
'Last
2802 and then Buf
(Cur_Loc
) /= ASCII
.LF
2804 Cur_Loc
:= Cur_Loc
+ 1;
2810 --------------------
2811 -- Get_Line_Start --
2812 --------------------
2814 function Get_Line_Start
2815 (Buf
: Source_Buffer_Ptr
;
2816 Loc
: Source_Ptr
) return Source_Ptr
2818 Cur_Loc
: Source_Ptr
:= Loc
;
2820 while Cur_Loc
> Buf
'First
2821 and then Buf
(Cur_Loc
- 1) /= ASCII
.LF
2823 Cur_Loc
:= Cur_Loc
- 1;
2833 function Image
(X
: Positive; Width
: Positive) return String is
2834 Str
: String (1 .. Width
);
2835 Curr
: Natural := X
;
2837 for J
in reverse 1 .. Width
loop
2839 Str
(J
) := Character'Val (Character'Pos ('0') + Curr
mod 10);
2853 procedure Write_Buffer
2854 (Buf
: Source_Buffer_Ptr
;
2859 for Loc
in First
.. Last
loop
2860 Write_Buffer_Char
(Buf
, Loc
);
2864 -----------------------
2865 -- Write_Buffer_Char --
2866 -----------------------
2868 procedure Write_Buffer_Char
2869 (Buf
: Source_Buffer_Ptr
;
2873 -- If the character ASCII.HT is not the last one in the file,
2874 -- output as many spaces as the character represents in the
2875 -- original source file.
2877 if Buf
(Loc
) = ASCII
.HT
2878 and then Loc
< Buf
'Last
2880 for X
in Get_Column_Number
(Loc
) ..
2881 Get_Column_Number
(Loc
+ 1) - 1
2886 -- Otherwise output the character itself
2889 Write_Char
(Buf
(Loc
));
2891 end Write_Buffer_Char
;
2893 -----------------------
2894 -- Write_Line_Marker --
2895 -----------------------
2897 procedure Write_Line_Marker
2903 Write_Str
(Image
(Positive (Num
), Width
=> Width
));
2904 Write_Str
((if Mark
then ">" else " ") & "|");
2905 end Write_Line_Marker
;
2909 Loc
: constant Source_Ptr
:= Span
.Ptr
;
2910 Line
: constant Pos
:= Pos
(Get_Physical_Line_Number
(Loc
));
2912 Col
: constant Natural := Natural (Get_Column_Number
(Loc
));
2914 Fst
: constant Source_Ptr
:= Span
.First
;
2915 Line_Fst
: constant Pos
:=
2916 Pos
(Get_Physical_Line_Number
(Fst
));
2917 Col_Fst
: constant Natural :=
2918 Natural (Get_Column_Number
(Fst
));
2919 Lst
: constant Source_Ptr
:= Span
.Last
;
2920 Line_Lst
: constant Pos
:=
2921 Pos
(Get_Physical_Line_Number
(Lst
));
2922 Col_Lst
: constant Natural :=
2923 Natural (Get_Column_Number
(Lst
));
2925 Width
: constant := 5;
2926 Buf
: Source_Buffer_Ptr
;
2927 Cur_Loc
: Source_Ptr
:= Fst
;
2928 Cur_Line
: Pos
:= Line_Fst
;
2930 -- Start of processing for Write_Source_Code_Lines
2933 if Loc
>= First_Source_Ptr
then
2934 Buf
:= Source_Text
(Get_Source_File_Index
(Loc
));
2936 -- First line of the span with actual source code. We retrieve
2937 -- the beginning of the line instead of relying on Col_Fst, as
2938 -- ASCII.HT characters change column numbers by possibly more
2943 Line_Fst
/= Line_Lst
and then Cur_Line
= Line
,
2945 Write_Buffer
(Buf
, Get_Line_Start
(Buf
, Cur_Loc
), Cur_Loc
- 1);
2947 -- Output the first/caret/last lines of the span, as well as
2948 -- lines that are directly above/below the caret if they complete
2949 -- the gap with first/last lines, otherwise use ... to denote
2950 -- intermediate lines.
2952 -- If the span is on one line and not a simple source location,
2953 -- color it appropriately.
2955 if Line_Fst
= Line_Lst
2956 and then Col_Fst
/= Col_Lst
2958 Write_Str
(SGR_Span
);
2962 function Do_Write_Line
(Cur_Line
: Pos
) return Boolean is
2963 (Cur_Line
in Line_Fst | Line | Line_Lst
2965 (Cur_Line
= Line_Fst
+ 1 and then Cur_Line
= Line
- 1)
2967 (Cur_Line
= Line
+ 1 and then Cur_Line
= Line_Lst
- 1));
2969 while Cur_Loc
<= Buf
'Last
2970 and then Cur_Loc
<= Lst
2972 if Do_Write_Line
(Cur_Line
) then
2973 Write_Buffer_Char
(Buf
, Cur_Loc
);
2976 if Buf
(Cur_Loc
) = ASCII
.LF
then
2977 Cur_Line
:= Cur_Line
+ 1;
2979 -- Output ... for skipped lines
2982 and then not Do_Write_Line
(Cur_Line
- 1))
2984 (Cur_Line
= Line
+ 1
2985 and then not Do_Write_Line
(Cur_Line
))
2987 Write_Str
((1 .. Width
- 3 => ' ') & "... | ...");
2991 -- Display the line marker if the line should be
2994 if Do_Write_Line
(Cur_Line
) then
2997 Line_Fst
/= Line_Lst
and then Cur_Line
= Line
,
3002 Cur_Loc
:= Cur_Loc
+ 1;
3006 if Line_Fst
= Line_Lst
3007 and then Col_Fst
/= Col_Lst
3009 Write_Str
(SGR_Reset
);
3012 -- Output the rest of the last line of the span
3014 Write_Buffer
(Buf
, Cur_Loc
, Get_Line_End
(Buf
, Cur_Loc
));
3016 -- If the span is on one line, output a second line with caret
3017 -- sign pointing to location Loc
3019 if Line_Fst
= Line_Lst
then
3020 Write_Str
(String'(1 .. Width => ' '));
3022 Write_Str (String'(1 .. Col_Fst
- 1 => ' '));
3024 Write_Str
(SGR_Span
);
3026 Write_Str
(String'(Col_Fst .. Col - 1 => '~
'));
3028 Write_Str (String'(Col
+ 1 .. Col_Lst
=> '~'));
3030 -- If the span is really just a location, add the word "here"
3031 -- to clarify this is the location for the message.
3033 if Col_Fst
= Col_Lst
then
3034 Write_Str
(" here");
3037 Write_Str
(SGR_Reset
);
3042 end Write_Source_Code_Lines
;
3048 Use_Prefix
: Boolean;
3050 -- Start of processing for Output_Messages
3053 -- Error if Finalize has not been called
3055 if not Finalize_Called
then
3056 raise Program_Error
;
3059 -- Reset current error source file if the main unit has a pragma
3060 -- Source_Reference. This ensures outputting the proper name of
3061 -- the source file in this situation.
3063 if Main_Source_File
<= No_Source_File
3064 or else Num_SRef_Pragmas
(Main_Source_File
) /= 0
3066 Current_Error_Source_File
:= No_Source_File
;
3069 if Opt
.JSON_Output
then
3072 E
:= First_Error_Msg
;
3074 -- Find first printable message
3076 while E
/= No_Error_Msg
and then Errors
.Table
(E
).Deleted
loop
3077 E
:= Errors
.Table
(E
).Next
;
3082 if E
/= No_Error_Msg
then
3084 Output_JSON_Message
(E
);
3086 E
:= Errors
.Table
(E
).Next
;
3088 while E
/= No_Error_Msg
loop
3090 -- Skip deleted messages.
3091 -- Also skip continuation messages, as they have already been
3092 -- printed along the message they're attached to.
3094 if not Errors
.Table
(E
).Deleted
3095 and then not Errors
.Table
(E
).Msg_Cont
3098 Output_JSON_Message
(E
);
3101 E
:= Errors
.Table
(E
).Next
;
3107 Set_Standard_Output
;
3111 elsif Brief_Output
or (not Full_List
and not Verbose_Mode
) then
3114 E
:= First_Error_Msg
;
3115 while E
/= No_Error_Msg
loop
3117 -- If -gnatdF is used, separate main messages from previous
3118 -- messages with a newline (unless it is an info message) and
3119 -- make continuation messages follow the main message with only
3120 -- an indentation of two space characters, without repeating
3121 -- file:line:col: prefix.
3124 not (Debug_Flag_FF
and then Errors
.Table
(E
).Msg_Cont
);
3126 if not Errors
.Table
(E
).Deleted
and then not Debug_Flag_KK
then
3128 if Debug_Flag_FF
then
3129 if Errors
.Table
(E
).Msg_Cont
then
3131 elsif not Errors
.Table
(E
).Info
then
3137 Write_Str
(SGR_Locus
);
3139 if Full_Path_Name_For_Brief_Errors
then
3140 Write_Name
(Full_Ref_Name
(Errors
.Table
(E
).Sfile
));
3142 Write_Name
(Reference_Name
(Errors
.Table
(E
).Sfile
));
3146 Write_Int
(Int
(Physical_To_Logical
3147 (Errors
.Table
(E
).Line
,
3148 Errors
.Table
(E
).Sfile
)));
3151 if Errors
.Table
(E
).Col
< 10 then
3155 Write_Int
(Int
(Errors
.Table
(E
).Col
));
3158 Write_Str
(SGR_Reset
);
3161 Output_Msg_Text
(E
);
3164 -- If -gnatdF is used, write the source code line corresponding
3165 -- to the location of the main message (unless it is an info
3166 -- message). Also write the source code line corresponding to
3167 -- an insertion location inside continuation messages.
3170 and then not Errors
.Table
(E
).Info
3172 if Errors
.Table
(E
).Msg_Cont
then
3174 Loc
: constant Source_Ptr
:=
3175 Errors
.Table
(E
).Insertion_Sloc
;
3177 if Loc
/= No_Location
then
3178 Write_Source_Code_Lines
3179 (To_Span
(Loc
), SGR_Span
=> SGR_Note
);
3185 SGR_Span
: constant String :=
3186 (if Errors
.Table
(E
).Info
then SGR_Note
3187 elsif Errors
.Table
(E
).Warn
3188 and then not Errors
.Table
(E
).Warn_Err
3192 Write_Source_Code_Lines
3193 (Errors
.Table
(E
).Optr
, SGR_Span
);
3199 E
:= Errors
.Table
(E
).Next
;
3202 Set_Standard_Output
;
3205 -- Full source listing case
3208 List_Pragmas_Index
:= 1;
3209 List_Pragmas_Mode
:= True;
3210 E
:= First_Error_Msg
;
3212 -- Normal case, to stdout (copyright notice already output)
3214 if Full_List_File_Name
= null then
3215 if not Debug_Flag_7
then
3222 Create_List_File_Access
.all (Full_List_File_Name
.all);
3223 Set_Special_Output
(Write_List_Info_Access
.all'Access);
3225 -- Write copyright notice to file
3227 if not Debug_Flag_7
then
3228 Write_Str
("GNAT ");
3229 Write_Str
(Gnat_Version_String
);
3231 Write_Str
("Copyright 1992-" &
3233 ", Free Software Foundation, Inc.");
3238 -- First list extended main source file units with errors
3240 for U
in Main_Unit
.. Last_Unit
loop
3241 if In_Extended_Main_Source_Unit
(Cunit_Entity
(U
))
3243 -- If debug flag d.m is set, only the main source is listed
3245 and then (U
= Main_Unit
or else not Debug_Flag_Dot_M
)
3247 -- If the unit of the entity does not come from source, it is
3248 -- an implicit subprogram declaration for a child subprogram.
3249 -- Do not emit errors for it, they are listed with the body.
3252 (No
(Cunit_Entity
(U
))
3253 or else Comes_From_Source
(Cunit_Entity
(U
))
3254 or else not Is_Subprogram
(Cunit_Entity
(U
)))
3256 -- If the compilation unit associated with this unit does not
3257 -- come from source, it means it is an instantiation that should
3258 -- not be included in the source listing.
3260 and then Comes_From_Source
(Cunit
(U
))
3263 Sfile
: constant Source_File_Index
:= Source_Index
(U
);
3268 -- Only write the header if Sfile is known
3270 if Sfile
> No_Source_File
then
3271 Write_Header
(Sfile
);
3275 -- Normally, we don't want an "error messages from file"
3276 -- message when listing the entire file, so we set the
3277 -- current source file as the current error source file.
3278 -- However, the old style of doing things was to list this
3279 -- message if pragma Source_Reference is present, even for
3280 -- the main unit. Since the purpose of the -gnatd.m switch
3281 -- is to duplicate the old behavior, we skip the reset if
3282 -- this debug flag is set.
3284 if not Debug_Flag_Dot_M
then
3285 Current_Error_Source_File
:= Sfile
;
3288 -- Only output the listing if Sfile is known, to avoid
3289 -- crashing the compiler.
3291 if Sfile
> No_Source_File
then
3292 for N
in 1 .. Last_Source_Line
(Sfile
) loop
3293 while E
/= No_Error_Msg
3294 and then Errors
.Table
(E
).Deleted
3296 E
:= Errors
.Table
(E
).Next
;
3301 and then Errors
.Table
(E
).Line
= N
3302 and then Errors
.Table
(E
).Sfile
= Sfile
;
3304 Output_Source_Line
(N
, Sfile
, Err_Flag
);
3307 Output_Error_Msgs
(E
);
3309 if not Debug_Flag_2
then
3319 -- Then output errors, if any, for subsidiary units not in the
3320 -- main extended unit.
3322 -- Note: if debug flag d.m set, include errors for any units other
3323 -- than the main unit in the extended source unit (e.g. spec and
3324 -- subunits for a body).
3326 while E
/= No_Error_Msg
3327 and then (not In_Extended_Main_Source_Unit
3328 (Errors
.Table
(E
).Sptr
.Ptr
)
3331 and then Get_Source_Unit
3332 (Errors
.Table
(E
).Sptr
.Ptr
) /= Main_Unit
))
3334 if Errors
.Table
(E
).Deleted
then
3335 E
:= Errors
.Table
(E
).Next
;
3340 (Errors
.Table
(E
).Line
, Errors
.Table
(E
).Sfile
, True);
3341 Output_Error_Msgs
(E
);
3345 -- If output to file, write extra copy of error summary to the
3346 -- output file, and then close it.
3348 if Full_List_File_Name
/= null then
3349 Write_Error_Summary
;
3351 Close_List_File_Access
.all;
3352 Cancel_Special_Output
;
3356 -- Verbose mode (error lines only with error flags). Normally this is
3357 -- ignored in full list mode, unless we are listing to a file, in which
3358 -- case we still generate -gnatv output to standard output.
3361 and then (not Full_List
or else Full_List_File_Name
/= null)
3365 -- Output the header only when Main_Source_File is known
3367 if Main_Source_File
> No_Source_File
then
3368 Write_Header
(Main_Source_File
);
3371 E
:= First_Error_Msg
;
3373 -- Loop through error lines
3375 while E
/= No_Error_Msg
loop
3376 if Errors
.Table
(E
).Deleted
then
3377 E
:= Errors
.Table
(E
).Next
;
3381 (Errors
.Table
(E
).Line
, Errors
.Table
(E
).Sfile
, True);
3382 Output_Error_Msgs
(E
);
3387 -- Output error summary if verbose or full list mode
3389 if Verbose_Mode
or else Full_List
then
3390 Write_Error_Summary
;
3393 if not Opt
.JSON_Output
then
3397 -- Even though Warning_Info_Messages are a subclass of warnings, they
3398 -- must not be treated as errors when -gnatwe is in effect.
3400 if Warning_Mode
= Treat_As_Error
then
3402 Compile_Time_Pragma_Warnings
: constant Int
:=
3403 Count_Compile_Time_Pragma_Warnings
;
3405 Total_Errors_Detected
:= Total_Errors_Detected
+ Warnings_Detected
3406 - Warning_Info_Messages
- Compile_Time_Pragma_Warnings
;
3407 Warnings_Detected
:=
3408 Warning_Info_Messages
+ Compile_Time_Pragma_Warnings
;
3411 end Output_Messages
;
3413 ------------------------
3414 -- Output_Source_Line --
3415 ------------------------
3417 procedure Output_Source_Line
3418 (L
: Physical_Line_Number
;
3419 Sfile
: Source_File_Index
;
3425 Line_Number_Output
: Boolean := False;
3426 -- Set True once line number is output
3428 Empty_Line
: Boolean := True;
3429 -- Set False if line includes at least one character
3432 if Sfile
/= Current_Error_Source_File
then
3433 Write_Str
("==============Error messages for ");
3435 case Sinput
.File_Type
(Sfile
) is
3437 Write_Str
("source");
3439 when Sinput
.Config
=>
3440 Write_Str
("configuration pragmas");
3443 Write_Str
("symbol definition");
3445 when Sinput
.Preproc
=>
3446 Write_Str
("preprocessing data");
3449 Write_Str
(" file: ");
3450 Write_Name
(Full_File_Name
(Sfile
));
3453 if Num_SRef_Pragmas
(Sfile
) > 0 then
3454 Write_Str
("--------------Line numbers from file: ");
3455 Write_Name
(Full_Ref_Name
(Sfile
));
3456 Write_Str
(" (starting at line ");
3457 Write_Int
(Int
(First_Mapped_Line
(Sfile
)));
3462 Current_Error_Source_File
:= Sfile
;
3465 if Errs
or List_Pragmas_Mode
then
3466 Output_Line_Number
(Physical_To_Logical
(L
, Sfile
));
3467 Line_Number_Output
:= True;
3470 S
:= Line_Start
(L
, Sfile
);
3473 C
:= Source_Text
(Sfile
) (S
);
3474 exit when C
= ASCII
.LF
or else C
= ASCII
.CR
or else C
= EOF
;
3476 -- Deal with matching entry in List_Pragmas table
3479 and then List_Pragmas_Index
<= List_Pragmas
.Last
3480 and then S
= List_Pragmas
.Table
(List_Pragmas_Index
).Ploc
3482 case List_Pragmas
.Table
(List_Pragmas_Index
).Ptyp
is
3486 -- Ignore if on line with errors so that error flags
3487 -- get properly listed with the error line .
3490 Write_Char
(ASCII
.FF
);
3494 List_Pragmas_Mode
:= True;
3496 if not Line_Number_Output
then
3497 Output_Line_Number
(Physical_To_Logical
(L
, Sfile
));
3498 Line_Number_Output
:= True;
3505 List_Pragmas_Mode
:= False;
3508 List_Pragmas_Index
:= List_Pragmas_Index
+ 1;
3510 -- Normal case (no matching entry in List_Pragmas table)
3513 if Errs
or List_Pragmas_Mode
then
3518 Empty_Line
:= False;
3522 -- If we have output a source line, then add the line terminator, with
3523 -- training spaces preserved (so we output the line exactly as input).
3525 if Line_Number_Output
then
3529 Write_Eol_Keep_Blanks
;
3532 end Output_Source_Line
;
3534 --------------------
3535 -- Paren_Required --
3536 --------------------
3538 function Paren_Required
(N
: Node_Id
) return Boolean is
3540 -- In a qualifed_expression the expression part needs to be enclosed in
3543 if Nkind
(Parent
(N
)) = N_Qualified_Expression
then
3544 return N
= Expression
(Parent
(N
));
3551 -----------------------------
3552 -- Remove_Warning_Messages --
3553 -----------------------------
3555 procedure Remove_Warning_Messages
(N
: Node_Id
) is
3557 function Check_For_Warning
(N
: Node_Id
) return Traverse_Result
;
3558 -- This function checks one node for a possible warning message
3560 procedure Check_All_Warnings
is new Traverse_Proc
(Check_For_Warning
);
3561 -- This defines the traversal operation
3563 -----------------------
3564 -- Check_For_Warning --
3565 -----------------------
3567 function Check_For_Warning
(N
: Node_Id
) return Traverse_Result
is
3568 Loc
: constant Source_Ptr
:= Sloc
(N
);
3571 function To_Be_Removed
(E
: Error_Msg_Id
) return Boolean;
3572 -- Returns True for a message that is to be removed. Also adjusts
3573 -- warning count appropriately.
3579 function To_Be_Removed
(E
: Error_Msg_Id
) return Boolean is
3581 if E
/= No_Error_Msg
3583 -- Don't remove if location does not match
3585 and then Errors
.Table
(E
).Optr
.Ptr
= Loc
3587 -- Don't remove if not warning/info message. Note that we do
3588 -- not remove style messages here. They are warning messages
3589 -- but not ones we want removed in this context.
3591 and then (Errors
.Table
(E
).Warn
3593 Errors
.Table
(E
).Warn_Runtime_Raise
)
3595 -- Don't remove unconditional messages
3597 and then not Errors
.Table
(E
).Uncond
3599 if Errors
.Table
(E
).Warn
then
3600 Warnings_Detected
:= Warnings_Detected
- 1;
3603 if Errors
.Table
(E
).Info
then
3604 Warning_Info_Messages
:= Warning_Info_Messages
- 1;
3607 -- When warning about a runtime exception has been escalated
3608 -- into error, the starting message has increased the total
3609 -- errors counter, so here we decrease this counter.
3611 if Errors
.Table
(E
).Warn_Runtime_Raise
3612 and then not Errors
.Table
(E
).Msg_Cont
3613 and then Warning_Mode
= Treat_Run_Time_Warnings_As_Errors
3615 Total_Errors_Detected
:= Total_Errors_Detected
- 1;
3620 -- No removal required
3627 -- Start of processing for Check_For_Warnings
3630 while To_Be_Removed
(First_Error_Msg
) loop
3631 First_Error_Msg
:= Errors
.Table
(First_Error_Msg
).Next
;
3634 if First_Error_Msg
= No_Error_Msg
then
3635 Last_Error_Msg
:= No_Error_Msg
;
3638 E
:= First_Error_Msg
;
3639 while E
/= No_Error_Msg
loop
3640 while To_Be_Removed
(Errors
.Table
(E
).Next
) loop
3641 Errors
.Table
(E
).Next
:=
3642 Errors
.Table
(Errors
.Table
(E
).Next
).Next
;
3644 if Errors
.Table
(E
).Next
= No_Error_Msg
then
3645 Last_Error_Msg
:= E
;
3649 E
:= Errors
.Table
(E
).Next
;
3652 -- Warnings may have been posted on subexpressions of original tree
3654 if Nkind
(N
) = N_Raise_Constraint_Error
3655 and then Is_Rewrite_Substitution
(N
)
3656 and then No
(Condition
(N
))
3658 Check_All_Warnings
(Original_Node
(N
));
3662 end Check_For_Warning
;
3664 -- Start of processing for Remove_Warning_Messages
3667 if Warnings_Detected
/= 0 then
3668 Check_All_Warnings
(N
);
3670 end Remove_Warning_Messages
;
3672 procedure Remove_Warning_Messages
(L
: List_Id
) is
3676 while Present
(Stat
) loop
3677 Remove_Warning_Messages
(Stat
);
3680 end Remove_Warning_Messages
;
3682 ----------------------
3683 -- Adjust_Name_Case --
3684 ----------------------
3686 procedure Adjust_Name_Case
3687 (Buf
: in out Bounded_String
;
3690 Src_Ind
: constant Source_File_Index
:= Get_Source_File_Index
(Loc
);
3691 Sbuffer
: Source_Buffer_Ptr
;
3693 Src_Ptr
: Source_Ptr
;
3696 -- We have an all lower case name from Namet, and now we want to set
3697 -- the appropriate case. If possible we copy the actual casing from
3698 -- the source. If not we use standard identifier casing.
3703 -- For standard locations, always use mixed case
3705 if Loc
<= No_Location
then
3706 Set_Casing
(Buf
, Mixed_Case
);
3709 -- Determine if the reference we are dealing with corresponds to text
3710 -- at the point of the error reference. This will often be the case
3711 -- for simple identifier references, and is the case where we can
3712 -- copy the casing from the source.
3714 Sbuffer
:= Source_Text
(Src_Ind
);
3716 while Ref_Ptr
<= Buf
.Length
loop
3718 Fold_Lower
(Sbuffer
(Src_Ptr
)) /=
3719 Fold_Lower
(Buf
.Chars
(Ref_Ptr
));
3720 Ref_Ptr
:= Ref_Ptr
+ 1;
3721 Src_Ptr
:= Src_Ptr
+ 1;
3724 -- If we get through the loop without a mismatch, then output the
3725 -- name the way it is cased in the source program.
3727 if Ref_Ptr
> Buf
.Length
then
3730 for J
in 1 .. Buf
.Length
loop
3731 Buf
.Chars
(J
) := Sbuffer
(Src_Ptr
);
3732 Src_Ptr
:= Src_Ptr
+ 1;
3735 -- Otherwise set the casing using the default identifier casing
3738 Set_Casing
(Buf
, Identifier_Casing
(Src_Ind
));
3741 end Adjust_Name_Case
;
3743 ---------------------------
3744 -- Set_Identifier_Casing --
3745 ---------------------------
3747 procedure Set_Identifier_Casing
3748 (Identifier_Name
: System
.Address
;
3749 File_Name
: System
.Address
)
3751 Ident
: constant Big_String_Ptr
:= To_Big_String_Ptr
(Identifier_Name
);
3752 File
: constant Big_String_Ptr
:= To_Big_String_Ptr
(File_Name
);
3755 Desired_Case
: Casing_Type
:= Mixed_Case
;
3756 -- Casing required for result. Default value of Mixed_Case is used if
3757 -- for some reason we cannot find the right file name in the table.
3760 -- Get length of file name
3763 while File
(Flen
+ 1) /= ASCII
.NUL
loop
3767 -- Loop through file names to find matching one. This is a bit slow, but
3768 -- we only do it in error situations so it is not so terrible. Note that
3769 -- if the loop does not exit, then the desired case will be left set to
3770 -- Mixed_Case, this can happen if the name was not in canonical form.
3772 for J
in 1 .. Last_Source_File
loop
3773 Get_Name_String
(Full_Debug_Name
(J
));
3776 and then Name_Buffer
(1 .. Name_Len
) = String (File
(1 .. Flen
))
3778 Desired_Case
:= Identifier_Casing
(J
);
3783 -- Copy identifier as given to Name_Buffer
3785 for J
in Name_Buffer
'Range loop
3786 Name_Buffer
(J
) := Ident
(J
);
3788 if Name_Buffer
(J
) = ASCII
.NUL
then
3794 Set_Casing
(Desired_Case
);
3795 end Set_Identifier_Casing
;
3797 -----------------------
3798 -- Set_Ignore_Errors --
3799 -----------------------
3801 procedure Set_Ignore_Errors
(To
: Boolean) is
3803 Errors_Must_Be_Ignored
:= To
;
3804 end Set_Ignore_Errors
;
3806 ------------------------------
3807 -- Set_Msg_Insertion_Column --
3808 ------------------------------
3810 procedure Set_Msg_Insertion_Column
is
3812 if RM_Column_Check
then
3813 Set_Msg_Str
(" in column ");
3814 Set_Msg_Int
(Int
(Error_Msg_Col
) + 1);
3816 end Set_Msg_Insertion_Column
;
3818 ----------------------------
3819 -- Set_Msg_Insertion_Node --
3820 ----------------------------
3822 procedure Set_Msg_Insertion_Node
is
3827 Error_Msg_Node_1
= Error
3828 or else Error_Msg_Node_1
= Any_Type
;
3830 if Error_Msg_Node_1
= Empty
then
3831 Set_Msg_Blank_Conditional
;
3832 Set_Msg_Str
("<empty>");
3834 elsif Error_Msg_Node_1
= Error
then
3836 Set_Msg_Str
("<error>");
3838 elsif Error_Msg_Node_1
= Standard_Void_Type
then
3840 Set_Msg_Str
("procedure name");
3842 elsif Nkind
(Error_Msg_Node_1
) in N_Entity
3843 and then Ekind
(Error_Msg_Node_1
) = E_Anonymous_Access_Subprogram_Type
3846 Set_Msg_Str
("access to subprogram");
3849 Set_Msg_Blank_Conditional
;
3853 K
:= Nkind
(Error_Msg_Node_1
);
3855 -- If we have operator case, skip quotes since name of operator
3856 -- itself will supply the required quotations. An operator can be an
3857 -- applied use in an expression or an explicit operator symbol, or an
3858 -- identifier whose name indicates it is an operator.
3861 or else K
= N_Operator_Symbol
3862 or else K
= N_Defining_Operator_Symbol
3863 or else ((K
= N_Identifier
or else K
= N_Defining_Identifier
)
3864 and then Is_Operator_Name
(Chars
(Error_Msg_Node_1
)))
3866 Set_Msg_Node
(Error_Msg_Node_1
);
3868 -- Normal case, not an operator, surround with quotes
3872 Set_Qualification
(Error_Msg_Qual_Level
, Error_Msg_Node_1
);
3873 Set_Msg_Node
(Error_Msg_Node_1
);
3878 -- The following assignment ensures that further ampersand insertion
3879 -- characters will correspond to the Error_Msg_Node_# parameter.
3881 Error_Msg_Node_1
:= Error_Msg_Node_2
;
3882 Error_Msg_Node_2
:= Error_Msg_Node_3
;
3883 Error_Msg_Node_3
:= Error_Msg_Node_4
;
3884 Error_Msg_Node_4
:= Error_Msg_Node_5
;
3885 Error_Msg_Node_5
:= Error_Msg_Node_6
;
3886 end Set_Msg_Insertion_Node
;
3888 --------------------------------------
3889 -- Set_Msg_Insertion_Type_Reference --
3890 --------------------------------------
3892 procedure Set_Msg_Insertion_Type_Reference
(Flag
: Source_Ptr
) is
3898 if Error_Msg_Node_1
= Standard_Void_Type
then
3899 Set_Msg_Str
("package or procedure name");
3902 elsif Error_Msg_Node_1
= Standard_Exception_Type
then
3903 Set_Msg_Str
("exception name");
3906 elsif Error_Msg_Node_1
= Any_Array
3907 or else Error_Msg_Node_1
= Any_Boolean
3908 or else Error_Msg_Node_1
= Any_Character
3909 or else Error_Msg_Node_1
= Any_Composite
3910 or else Error_Msg_Node_1
= Any_Discrete
3911 or else Error_Msg_Node_1
= Any_Fixed
3912 or else Error_Msg_Node_1
= Any_Integer
3913 or else Error_Msg_Node_1
= Any_Modular
3914 or else Error_Msg_Node_1
= Any_Numeric
3915 or else Error_Msg_Node_1
= Any_Real
3916 or else Error_Msg_Node_1
= Any_Scalar
3917 or else Error_Msg_Node_1
= Any_String
3919 Get_Unqualified_Decoded_Name_String
(Chars
(Error_Msg_Node_1
));
3920 Set_Msg_Name_Buffer
;
3923 elsif Error_Msg_Node_1
= Universal_Integer
then
3924 Set_Msg_Str
("type universal integer");
3927 elsif Error_Msg_Node_1
= Universal_Real
then
3928 Set_Msg_Str
("type universal real");
3931 elsif Error_Msg_Node_1
= Universal_Fixed
then
3932 Set_Msg_Str
("type universal fixed");
3935 elsif Error_Msg_Node_1
= Universal_Access
then
3936 Set_Msg_Str
("type universal access");
3940 -- Special case of anonymous array
3942 if Nkind
(Error_Msg_Node_1
) in N_Entity
3943 and then Is_Array_Type
(Error_Msg_Node_1
)
3944 and then Present
(Related_Array_Object
(Error_Msg_Node_1
))
3946 Set_Msg_Str
("type of ");
3947 Set_Msg_Node
(Related_Array_Object
(Error_Msg_Node_1
));
3948 Set_Msg_Str
(" declared");
3949 Set_Msg_Insertion_Line_Number
3950 (Sloc
(Related_Array_Object
(Error_Msg_Node_1
)), Flag
);
3954 -- If we fall through, it is not a special case, so first output
3955 -- the name of the type, preceded by private for a private type
3957 if Is_Private_Type
(Error_Msg_Node_1
) then
3958 Set_Msg_Str
("private type ");
3960 Set_Msg_Str
("type ");
3963 Ent
:= Error_Msg_Node_1
;
3965 if Is_Internal_Name
(Chars
(Ent
)) then
3966 Unwind_Internal_Type
(Ent
);
3969 -- Types in Standard are displayed as "Standard.name"
3971 if Sloc
(Ent
) <= Standard_Location
then
3973 Set_Msg_Str
("Standard.");
3978 -- Types in other language defined units are displayed as
3979 -- "package-name.type-name"
3981 elsif Is_Predefined_Unit
(Get_Source_Unit
(Ent
)) then
3982 Get_Unqualified_Decoded_Name_String
3983 (Unit_Name
(Get_Source_Unit
(Ent
)));
3984 Name_Len
:= Name_Len
- 2;
3985 Set_Msg_Blank_Conditional
;
3987 Set_Casing
(Mixed_Case
);
3988 Set_Msg_Name_Buffer
;
3990 Set_Casing
(Mixed_Case
);
3995 -- All other types display as "type name" defined at line xxx
3996 -- possibly qualified if qualification is requested.
4000 Set_Qualification
(Error_Msg_Qual_Level
, Ent
);
4004 -- If we did not print a name (e.g. in the case of an anonymous
4005 -- subprogram type), there is no name to print, so remove quotes.
4007 if Buffer_Ends_With
('"') then
4008 Buffer_Remove
('"');
4014 -- If the original type did not come from a predefined file, add the
4015 -- location where the type was defined.
4017 if Sloc
(Error_Msg_Node_1
) > Standard_Location
4019 not Is_Predefined_Unit
(Get_Source_Unit
(Error_Msg_Node_1
))
4021 Get_Name_String
(Unit_File_Name
(Get_Source_Unit
(Error_Msg_Node_1
)));
4022 Set_Msg_Str
(" defined");
4023 Set_Msg_Insertion_Line_Number
(Sloc
(Error_Msg_Node_1
), Flag
);
4025 -- If it did come from a predefined file, deal with the case where
4026 -- this was a file with a generic instantiation from elsewhere.
4029 if Sloc
(Error_Msg_Node_1
) > Standard_Location
then
4031 Iloc
: constant Source_Ptr
:=
4032 Instantiation_Location
(Sloc
(Error_Msg_Node_1
));
4035 if Iloc
/= No_Location
4036 and then not Suppress_Instance_Location
4038 Set_Msg_Str
(" from instance");
4039 Set_Msg_Insertion_Line_Number
(Iloc
, Flag
);
4044 end Set_Msg_Insertion_Type_Reference
;
4046 ---------------------------------
4047 -- Set_Msg_Insertion_Unit_Name --
4048 ---------------------------------
4050 procedure Set_Msg_Insertion_Unit_Name
(Suffix
: Boolean := True) is
4052 if Error_Msg_Unit_1
= No_Unit_Name
then
4055 elsif Error_Msg_Unit_1
= Error_Unit_Name
then
4057 Set_Msg_Str
("<error>");
4060 Get_Unit_Name_String
(Global_Name_Buffer
, Error_Msg_Unit_1
, Suffix
);
4063 Set_Msg_Name_Buffer
;
4067 -- The following assignment ensures that a second percent insertion
4068 -- character will correspond to the Error_Msg_Unit_2 parameter.
4070 Error_Msg_Unit_1
:= Error_Msg_Unit_2
;
4071 end Set_Msg_Insertion_Unit_Name
;
4077 procedure Set_Msg_Node
(Node
: Node_Id
) is
4083 case Nkind
(Node
) is
4084 when N_Designator
=>
4085 Set_Msg_Node
(Name
(Node
));
4087 Set_Msg_Node
(Identifier
(Node
));
4090 when N_Defining_Program_Unit_Name
=>
4091 Set_Msg_Node
(Name
(Node
));
4093 Set_Msg_Node
(Defining_Identifier
(Node
));
4096 when N_Expanded_Name
4097 | N_Selected_Component
4099 Set_Msg_Node
(Prefix
(Node
));
4101 Set_Msg_Node
(Selector_Name
(Node
));
4108 -- The only remaining possibilities are identifiers, defining
4109 -- identifiers, pragmas, and pragma argument associations.
4111 if Nkind
(Node
) = N_Pragma
then
4112 Nam
:= Pragma_Name
(Node
);
4115 -- The other cases have Chars fields
4117 -- First deal with internal names, which generally represent something
4118 -- gone wrong. First attempt: if this is a rewritten node that rewrites
4119 -- something with a Chars field that is not an internal name, use that.
4121 elsif Is_Internal_Name
(Chars
(Node
))
4122 and then Nkind
(Original_Node
(Node
)) in N_Has_Chars
4123 and then not Is_Internal_Name
(Chars
(Original_Node
(Node
)))
4125 Nam
:= Chars
(Original_Node
(Node
));
4126 Loc
:= Sloc
(Original_Node
(Node
));
4128 -- Another shot for internal names, in the case of internal type names,
4129 -- we try to find a reasonable representation for the external name.
4131 elsif Is_Internal_Name
(Chars
(Node
))
4133 ((Is_Entity_Name
(Node
)
4134 and then Present
(Entity
(Node
))
4135 and then Is_Type
(Entity
(Node
)))
4137 (Nkind
(Node
) = N_Defining_Identifier
and then Is_Type
(Node
)))
4139 if Nkind
(Node
) = N_Identifier
then
4140 Ent
:= Entity
(Node
);
4147 -- If the type is the designated type of an access_to_subprogram,
4148 -- then there is no name to provide in the call.
4150 if Ekind
(Ent
) = E_Subprogram_Type
then
4153 -- Otherwise, we will be able to find some kind of name to output
4156 Unwind_Internal_Type
(Ent
);
4160 -- If not internal name, or if we could not find a reasonable possible
4161 -- substitution for the internal name, just use name in Chars field.
4164 Nam
:= Chars
(Node
);
4168 -- At this stage, the name to output is in Nam
4170 Get_Unqualified_Decoded_Name_String
(Nam
);
4172 -- Remove trailing upper case letters from the name (useful for
4173 -- dealing with some cases of internal names).
4175 while Name_Len
> 1 and then Name_Buffer
(Name_Len
) in 'A' .. 'Z' loop
4176 Name_Len
:= Name_Len
- 1;
4179 -- If we have any of the names from standard that start with the
4180 -- characters "any " (e.g. Any_Type), then kill the message since
4181 -- almost certainly it is a junk cascaded message.
4184 and then Name_Buffer
(1 .. 4) = "any "
4186 Kill_Message
:= True;
4189 -- If we still have an internal name, kill the message (will only
4190 -- work if we already had errors!)
4192 if Is_Internal_Name
then
4193 Kill_Message
:= True;
4195 -- Remaining step is to adjust casing and possibly add 'Class
4197 Adjust_Name_Case
(Global_Name_Buffer
, Loc
);
4198 Set_Msg_Name_Buffer
;
4206 procedure Set_Msg_Text
(Text
: String; Flag
: Source_Ptr
) is
4207 C
: Character; -- Current character
4208 P
: Natural; -- Current index;
4210 procedure Skip_Msg_Insertion_Warning
(C
: Character);
4211 -- Skip the ? ?? ?x? ?*? ?$? insertion sequences (and the same
4212 -- sequences using < instead of ?). The caller has already bumped
4213 -- the pointer past the initial ? or < and C is set to this initial
4214 -- character (? or <). This procedure skips past the rest of the
4215 -- sequence. We do not need to set Msg_Insertion_Char, since this
4216 -- was already done during the message prescan.
4217 -- No validity check is performed as the insertion sequence is
4218 -- supposed to be sane. See Prescan_Message.Parse_Message_Class in
4219 -- erroutc.adb for the validity checks.
4221 --------------------------------
4222 -- Skip_Msg_Insertion_Warning --
4223 --------------------------------
4225 procedure Skip_Msg_Insertion_Warning
(C
: Character) is
4227 if P
<= Text
'Last and then Text
(P
) = C
then
4230 elsif P
< Text
'Last and then Text
(P
+ 1) = C
4231 and then Text
(P
) in 'a' .. 'z' |
'A' .. 'Z' |
4232 '0' .. '9' |
'*' |
'$'
4236 elsif P
+ 1 < Text
'Last and then Text
(P
+ 2) = C
4237 and then Text
(P
) in '.' |
'_'
4238 and then Text
(P
+ 1) in 'a' .. 'z'
4242 end Skip_Msg_Insertion_Warning
;
4244 -- Start of processing for Set_Msg_Text
4247 Manual_Quote_Mode
:= False;
4249 Flag_Source
:= Get_Source_File_Index
(Flag
);
4251 -- Skip info: at start, we have recorded this in Is_Info_Msg, and this
4252 -- will be used (Info field in error message object) to put back the
4253 -- string when it is printed. We need to do this, or we get confused
4254 -- with instantiation continuations.
4257 and then Text
(Text
'First .. Text
'First + 5) = "info: "
4259 P
:= Text
'First + 6;
4264 -- Loop through characters of message
4266 while P
<= Text
'Last loop
4270 -- Check for insertion character or sequence
4274 if P
<= Text
'Last and then Text
(P
) = '%' then
4276 Set_Msg_Insertion_Name_Literal
;
4278 Set_Msg_Insertion_Name
;
4282 if P
<= Text
'Last and then Text
(P
) = '$' then
4284 Set_Msg_Insertion_Unit_Name
(Suffix
=> False);
4286 Set_Msg_Insertion_Unit_Name
;
4290 Set_Msg_Insertion_File_Name
;
4293 Set_Msg_Insertion_Type_Reference
(Flag
);
4296 Set_Msg_Insertion_Reserved_Name
;
4299 Set_Msg_Insertion_Node
;
4302 Set_Msg_Insertion_Line_Number
(Error_Msg_Sloc
, Flag
);
4305 Continuation
:= True;
4307 if P
<= Text
'Last and then Text
(P
) = '\' then
4308 Continuation_New_Line
:= True;
4313 Set_Msg_Insertion_Column
;
4316 Set_Msg_Insertion_Run_Time_Name
;
4319 Set_Msg_Insertion_Uint
;
4322 Manual_Quote_Mode
:= not Manual_Quote_Mode
;
4326 null; -- already dealt with
4329 Skip_Msg_Insertion_Warning
('?');
4332 Skip_Msg_Insertion_Warning
('<');
4335 null; -- already dealt with
4338 Set_Msg_Char
(Text
(P
));
4342 Set_Msg_Str
(Error_Msg_String
(1 .. Error_Msg_Strlen
));
4344 -- Upper case letter
4348 -- Start of reserved word if two or more
4350 if P
<= Text
'Last and then Text
(P
) in 'A' .. 'Z' then
4352 Set_Msg_Insertion_Reserved_Word
(Text
, P
);
4354 -- Single upper case letter is just inserted
4360 -- '[' (will be/would have been raised at run time)
4364 -- "[]" (insertion of error code)
4366 if P
<= Text
'Last and then Text
(P
) = ']' then
4368 Set_Msg_Insertion_Code
;
4371 -- Switch the message from a warning to an error if the flag
4372 -- -gnatwE is specified to treat run-time exception warnings
4376 and then Warning_Mode
= Treat_Run_Time_Warnings_As_Errors
4378 Is_Warning_Msg
:= False;
4379 Is_Runtime_Raise
:= True;
4382 if Is_Warning_Msg
then
4383 Set_Msg_Str
("will be raised at run time");
4385 Set_Msg_Str
("would have been raised at run time");
4389 -- ']' (may be/might have been raised at run time)
4392 if Is_Warning_Msg
then
4393 Set_Msg_Str
("may be raised at run time");
4395 Set_Msg_Str
("might have been raised at run time");
4398 -- Normal character with no special treatment
4410 procedure Set_Posted
(N
: Node_Id
) is
4414 if Is_Serious_Error
then
4416 -- We always set Error_Posted on the node itself
4418 Set_Error_Posted
(N
);
4420 -- If it is a subexpression, then set Error_Posted on parents up to
4421 -- and including the first non-subexpression construct. This helps
4422 -- avoid cascaded error messages within a single expression.
4428 Set_Error_Posted
(P
);
4429 exit when Nkind
(P
) not in N_Subexpr
;
4432 if Nkind
(P
) in N_Pragma_Argument_Association
4433 | N_Component_Association
4434 | N_Discriminant_Association
4435 | N_Generic_Association
4436 | N_Parameter_Association
4438 Set_Error_Posted
(Parent
(P
));
4441 -- A special check, if we just posted an error on an attribute
4442 -- definition clause, then also set the entity involved as posted.
4443 -- For example, this stops complaining about the alignment after
4444 -- complaining about the size, which is likely to be useless.
4446 if Nkind
(P
) = N_Attribute_Definition_Clause
then
4447 if Is_Entity_Name
(Name
(P
)) then
4448 Set_Error_Posted
(Entity
(Name
(P
)));
4454 -----------------------
4455 -- Set_Qualification --
4456 -----------------------
4458 procedure Set_Qualification
(N
: Nat
; E
: Entity_Id
) is
4460 if N
/= 0 and then Scope
(E
) /= Standard_Standard
then
4461 Set_Qualification
(N
- 1, Scope
(E
));
4462 Set_Msg_Node
(Scope
(E
));
4465 end Set_Qualification
;
4467 -------------------------------------
4468 -- Should_Ignore_Pragma_SPARK_Mode --
4469 -------------------------------------
4471 function Should_Ignore_Pragma_SPARK_Mode
return Boolean is
4473 return Get_Name_Table_Boolean3
(Name_SPARK_Mode
);
4474 end Should_Ignore_Pragma_SPARK_Mode
;
4476 ------------------------
4477 -- Special_Msg_Delete --
4478 ------------------------
4480 -- Is it really right to have all this specialized knowledge in errout?
4482 function Special_Msg_Delete
4484 N
: Node_Or_Entity_Id
;
4485 E
: Node_Or_Entity_Id
) return Boolean
4488 -- Never delete messages in -gnatdO mode
4490 if Debug_Flag_OO
then
4493 -- Processing for "Size too small" messages
4495 elsif Is_Size_Too_Small_Message
(Msg
) then
4497 -- Suppress "size too small" errors in CodePeer mode, since code may
4498 -- be analyzed in a different configuration than the one used for
4499 -- compilation. Even when the configurations match, this message
4500 -- may be issued on correct code, because pragma Pack is ignored
4501 -- in CodePeer mode.
4503 if CodePeer_Mode
then
4506 -- When a size is wrong for a frozen type there is no explicit size
4507 -- clause, and other errors have occurred, suppress the message,
4508 -- since it is likely that this size error is a cascaded result of
4509 -- other errors. The reason we eliminate unfrozen types is that
4510 -- messages issued before the freeze type are for sure OK.
4512 elsif Nkind
(N
) in N_Entity
4513 and then Is_Frozen
(E
)
4514 and then Serious_Errors_Detected
> 0
4515 and then Nkind
(N
) /= N_Component_Clause
4516 and then Nkind
(Parent
(N
)) /= N_Component_Clause
4518 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Size
))
4520 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Object_Size
))
4522 No
(Get_Attribute_Definition_Clause
(E
, Attribute_Value_Size
))
4528 -- All special tests complete, so go ahead with message
4531 end Special_Msg_Delete
;
4537 procedure SPARK_Msg_N
(Msg
: String; N
: Node_Or_Entity_Id
) is
4539 -- If SPARK_Mode is Off, we do not report SPARK legality errors to give
4540 -- the flexibility to opt out of SPARK checking completely. We do the
4541 -- same if pragma Ignore_Pragma (SPARK_Mode) was specified, as a way
4542 -- for tools to ignore SPARK checking even on SPARK code.
4544 if SPARK_Mode
/= Off
4545 and then not Should_Ignore_Pragma_SPARK_Mode
4547 Error_Msg_N
(Msg
, N
);
4555 procedure SPARK_Msg_NE
4557 N
: Node_Or_Entity_Id
;
4558 E
: Node_Or_Entity_Id
)
4561 if SPARK_Mode
/= Off
4562 and then not Should_Ignore_Pragma_SPARK_Mode
4564 Error_Msg_NE
(Msg
, N
, E
);
4568 --------------------------
4569 -- Unwind_Internal_Type --
4570 --------------------------
4572 procedure Unwind_Internal_Type
(Ent
: in out Entity_Id
) is
4573 Derived
: Boolean := False;
4575 Old_Ent
: Entity_Id
;
4578 -- Undo placement of a quote, since we will put it back later
4580 Mchar
:= Msg_Buffer
(Msglen
);
4583 Msglen
:= Msglen
- 1;
4586 -- The loop here deals with recursive types, we are trying to find a
4587 -- related entity that is not an implicit type. Note that the check with
4588 -- Old_Ent stops us from getting "stuck". Also, we don't output the
4589 -- "type derived from" message more than once in the case where we climb
4590 -- up multiple levels.
4595 -- Implicit access type, use directly designated type In Ada 2005,
4596 -- the designated type may be an anonymous access to subprogram, in
4597 -- which case we can only point to its definition.
4599 if Is_Access_Type
(Ent
) then
4600 if Ekind
(Ent
) = E_Access_Subprogram_Type
4601 or else Ekind
(Ent
) = E_Anonymous_Access_Subprogram_Type
4602 or else Is_Access_Protected_Subprogram_Type
(Ent
)
4604 Ent
:= Directly_Designated_Type
(Ent
);
4606 if not Comes_From_Source
(Ent
) then
4607 if Buffer_Ends_With
("type ") then
4608 Buffer_Remove
("type ");
4612 if Ekind
(Ent
) = E_Function
then
4613 Set_Msg_Str
("access to function ");
4614 elsif Ekind
(Ent
) = E_Procedure
then
4615 Set_Msg_Str
("access to procedure ");
4617 Set_Msg_Str
("access to subprogram");
4622 -- Type is access to object, named or anonymous
4625 Set_Msg_Str
("access to ");
4626 Ent
:= Directly_Designated_Type
(Ent
);
4631 elsif Is_Class_Wide_Type
(Ent
) then
4633 Ent
:= Root_Type
(Ent
);
4635 -- Use base type if this is a subtype
4637 elsif Ent
/= Base_Type
(Ent
) then
4638 Buffer_Remove
("type ");
4640 -- Avoid duplication "subtype of subtype of", and also replace
4641 -- "derived from subtype of" simply by "derived from"
4643 if not Buffer_Ends_With
("subtype of ")
4644 and then not Buffer_Ends_With
("derived from ")
4646 Set_Msg_Str
("subtype of ");
4649 Ent
:= Base_Type
(Ent
);
4651 -- If this is a base type with a first named subtype, use the first
4652 -- named subtype instead. This is not quite accurate in all cases,
4653 -- but it makes too much noise to be accurate and add 'Base in all
4654 -- cases. Note that we only do this is the first named subtype is not
4655 -- itself an internal name. This avoids the obvious loop (subtype ->
4656 -- basetype -> subtype) which would otherwise occur).
4660 FST
: constant Entity_Id
:= First_Subtype
(Ent
);
4663 if not Is_Internal_Name
(Chars
(FST
)) then
4667 -- Otherwise use root type
4671 Buffer_Remove
("type ");
4673 -- Test for "subtype of type derived from" which seems
4674 -- excessive and is replaced by "type derived from".
4676 Buffer_Remove
("subtype of");
4678 -- Avoid duplicated "type derived from type derived from"
4680 if not Buffer_Ends_With
("type derived from ") then
4681 Set_Msg_Str
("type derived from ");
4692 -- If we are stuck in a loop, get out and settle for the internal
4693 -- name after all. In this case we set to kill the message if it is
4694 -- not the first error message (we really try hard not to show the
4695 -- dirty laundry of the implementation to the poor user).
4697 if Ent
= Old_Ent
then
4698 Kill_Message
:= True;
4702 -- Get out if we finally found a non-internal name to use
4704 exit Find
when not Is_Internal_Name
(Chars
(Ent
));
4710 end Unwind_Internal_Type
;
4712 --------------------
4713 -- Warn_Insertion --
4714 --------------------
4716 function Warn_Insertion
return String is
4718 if Warning_Msg_Char
= "? " then
4720 elsif Warning_Msg_Char
= " " then
4722 elsif Warning_Msg_Char
(2) = ' ' then
4723 return '?' & Warning_Msg_Char
(1) & '?';
4725 return '?' & Warning_Msg_Char
& '?';