1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 2002-2023, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 -- This package contains routines to output error messages and the
27 -- corresponding instantiation of Styleg, suitable to instantiate Scng.
29 -- It uses the same global variables as Errout, located in packages Atree and
30 -- Err_Vars. Like Errout, it also uses the common variables and routines
31 -- in package Erroutc.
33 -- This package is used by the preprocessor (gprep.adb).
36 with Types
; use Types
;
40 ---------------------------------------------------------
41 -- Error Message Text and Message Insertion Characters --
42 ---------------------------------------------------------
44 -- Error message text strings are composed of lower case letters, digits
45 -- and the special characters space, comma, period, colon and semicolon,
46 -- apostrophe and parentheses. Special insertion characters can also
47 -- appear which cause the error message circuit to modify the given
48 -- string. For a full list of these, see the spec of errout.
50 -----------------------------------------------------
51 -- Format of Messages and Manual Quotation Control --
52 -----------------------------------------------------
54 -- Messages are generally all in lower case, except for inserted names
55 -- and appear in one of the following two forms:
60 -- The prefixes error and warning are supplied automatically (depending
61 -- on the use of the ? insertion character), and the call to the error
62 -- message routine supplies the text. The "error: " prefix is omitted
63 -- in brief error message formats.
65 -- Reserved keywords in the message are in the default keyword case
66 -- (determined from the given source program), surrounded by quotation
67 -- marks. This is achieved by spelling the reserved word in upper case
68 -- letters, which is recognized as a request for insertion of quotation
69 -- marks by the error text processor. Thus for example:
71 -- Error_Msg_AP ("IS expected");
73 -- would result in the output of one of the following:
75 -- error: "is" expected
76 -- error: "IS" expected
77 -- error: "Is" expected
79 -- the choice between these being made by looking at the casing convention
80 -- used for keywords (actually the first compilation unit keyword) in the
83 -- In the case of names, the default mode for the error text processor
84 -- is to surround the name by quotation marks automatically. The case
85 -- used for the identifier names is taken from the source program where
86 -- possible, and otherwise is the default casing convention taken from
87 -- the source file usage.
89 -- In some cases, better control over the placement of quote marks is
90 -- required. This is achieved using manual quotation mode. In this mode,
91 -- one or more insertion sequences is surrounded by backquote characters.
92 -- The backquote characters are output as double quote marks, and normal
93 -- automatic insertion of quotes is suppressed between the double quotes.
96 -- Error_Msg_AP ("`END &;` expected");
98 -- generates a message like
100 -- error: "end Open_Scope;" expected
102 -- where the node specifying the name Open_Scope has been stored in
103 -- Error_Msg_Node_1 prior to the call. The great majority of error
104 -- messages operates in normal quotation mode.
106 -- Note: the normal automatic insertion of spaces before insertion
107 -- sequences (such as those that come from & and %) is suppressed in
108 -- manual quotation mode, so blanks, if needed as in the above example,
109 -- must be explicitly present.
111 ------------------------------
112 -- Error Output Subprograms --
113 ------------------------------
115 procedure Initialize
;
116 -- Initializes for output of error messages. Must be called for each
117 -- file before using any of the other routines in the package.
119 procedure Finalize
(Source_Type
: String := "project");
120 -- Finalize processing of error messages for one file and output message
121 -- indicating the number of detected errors.
122 -- Source_Type is used in verbose mode to indicate the type of the source
123 -- being parsed (project file, definition file or input file for the
126 procedure Error_Msg
(Msg
: String; Flag_Location
: Source_Ptr
);
127 -- Output a message at specified location
129 procedure Error_Msg_S
(Msg
: String);
130 -- Output a message at current scan pointer location
132 procedure Error_Msg_SC
(Msg
: String);
133 -- Output a message at the start of the current token, unless we are at
134 -- the end of file, in which case we always output the message after the
135 -- last real token in the file.
137 procedure Error_Msg_SP
(Msg
: String);
138 -- Output a message at the start of the previous token
140 procedure Set_Ignore_Errors
(To
: Boolean);
141 -- Indicate, when To = True, that all reported errors should
142 -- be ignored. By default reported errors are not ignored.
144 package Style
is new Styleg
145 (Error_Msg
=> Error_Msg
,
146 Error_Msg_S
=> Error_Msg_S
,
147 Error_Msg_SC
=> Error_Msg_SC
,
148 Error_Msg_SP
=> Error_Msg_SP
);
149 -- Instantiation of the generic style package, suitable for an
150 -- instantiation of Scng.