111
|
1 ------------------------------------------------------------------------------
|
|
2 -- --
|
|
3 -- GNAT COMPILER COMPONENTS --
|
|
4 -- --
|
|
5 -- E R R U T I L --
|
|
6 -- --
|
|
7 -- S p e c --
|
|
8 -- --
|
131
|
9 -- Copyright (C) 2002-2018, Free Software Foundation, Inc. --
|
111
|
10 -- --
|
|
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. --
|
|
20 -- --
|
|
21 -- GNAT was originally developed by the GNAT team at New York University. --
|
|
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
|
|
23 -- --
|
|
24 ------------------------------------------------------------------------------
|
|
25
|
|
26 -- This package contains routines to output error messages and the
|
|
27 -- corresponding instantiation of Styleg, suitable to instantiate Scng.
|
|
28
|
|
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.
|
|
32
|
|
33 -- This package is used by the preprocessor (gprep.adb) and the project
|
|
34 -- manager (prj-err.ads).
|
|
35
|
|
36 with Styleg;
|
|
37 with Types; use Types;
|
|
38
|
|
39 package Errutil is
|
|
40
|
|
41 ---------------------------------------------------------
|
|
42 -- Error Message Text and Message Insertion Characters --
|
|
43 ---------------------------------------------------------
|
|
44
|
|
45 -- Error message text strings are composed of lower case letters, digits
|
|
46 -- and the special characters space, comma, period, colon and semicolon,
|
|
47 -- apostrophe and parentheses. Special insertion characters can also
|
|
48 -- appear which cause the error message circuit to modify the given
|
|
49 -- string. For a full list of these, see the spec of errout.
|
|
50
|
|
51 -----------------------------------------------------
|
|
52 -- Format of Messages and Manual Quotation Control --
|
|
53 -----------------------------------------------------
|
|
54
|
|
55 -- Messages are generally all in lower case, except for inserted names
|
|
56 -- and appear in one of the following two forms:
|
|
57
|
|
58 -- error: text
|
|
59 -- warning: text
|
|
60
|
|
61 -- The prefixes error and warning are supplied automatically (depending
|
|
62 -- on the use of the ? insertion character), and the call to the error
|
|
63 -- message routine supplies the text. The "error: " prefix is omitted
|
|
64 -- in brief error message formats.
|
|
65
|
|
66 -- Reserved keywords in the message are in the default keyword case
|
|
67 -- (determined from the given source program), surrounded by quotation
|
|
68 -- marks. This is achieved by spelling the reserved word in upper case
|
|
69 -- letters, which is recognized as a request for insertion of quotation
|
|
70 -- marks by the error text processor. Thus for example:
|
|
71
|
|
72 -- Error_Msg_AP ("IS expected");
|
|
73
|
|
74 -- would result in the output of one of the following:
|
|
75
|
|
76 -- error: "is" expected
|
|
77 -- error: "IS" expected
|
|
78 -- error: "Is" expected
|
|
79
|
|
80 -- the choice between these being made by looking at the casing convention
|
|
81 -- used for keywords (actually the first compilation unit keyword) in the
|
|
82 -- source file.
|
|
83
|
|
84 -- In the case of names, the default mode for the error text processor
|
|
85 -- is to surround the name by quotation marks automatically. The case
|
|
86 -- used for the identifier names is taken from the source program where
|
|
87 -- possible, and otherwise is the default casing convention taken from
|
|
88 -- the source file usage.
|
|
89
|
|
90 -- In some cases, better control over the placement of quote marks is
|
|
91 -- required. This is achieved using manual quotation mode. In this mode,
|
|
92 -- one or more insertion sequences is surrounded by backquote characters.
|
|
93 -- The backquote characters are output as double quote marks, and normal
|
|
94 -- automatic insertion of quotes is suppressed between the double quotes.
|
|
95 -- For example:
|
|
96
|
|
97 -- Error_Msg_AP ("`END &;` expected");
|
|
98
|
|
99 -- generates a message like
|
|
100
|
|
101 -- error: "end Open_Scope;" expected
|
|
102
|
|
103 -- where the node specifying the name Open_Scope has been stored in
|
|
104 -- Error_Msg_Node_1 prior to the call. The great majority of error
|
|
105 -- messages operates in normal quotation mode.
|
|
106
|
|
107 -- Note: the normal automatic insertion of spaces before insertion
|
|
108 -- sequences (such as those that come from & and %) is suppressed in
|
|
109 -- manual quotation mode, so blanks, if needed as in the above example,
|
|
110 -- must be explicitly present.
|
|
111
|
|
112 ------------------------------
|
|
113 -- Error Output Subprograms --
|
|
114 ------------------------------
|
|
115
|
|
116 procedure Initialize;
|
|
117 -- Initializes for output of error messages. Must be called for each
|
|
118 -- file before using any of the other routines in the package.
|
|
119
|
|
120 procedure Finalize (Source_Type : String := "project");
|
|
121 -- Finalize processing of error messages for one file and output message
|
|
122 -- indicating the number of detected errors.
|
|
123 -- Source_Type is used in verbose mode to indicate the type of the source
|
|
124 -- being parsed (project file, definition file or input file for the
|
|
125 -- preprocessor).
|
|
126
|
|
127 procedure Error_Msg (Msg : String; Flag_Location : Source_Ptr);
|
|
128 -- Output a message at specified location
|
|
129
|
|
130 procedure Error_Msg_S (Msg : String);
|
|
131 -- Output a message at current scan pointer location
|
|
132
|
|
133 procedure Error_Msg_SC (Msg : String);
|
|
134 -- Output a message at the start of the current token, unless we are at
|
|
135 -- the end of file, in which case we always output the message after the
|
|
136 -- last real token in the file.
|
|
137
|
|
138 procedure Error_Msg_SP (Msg : String);
|
|
139 -- Output a message at the start of the previous token
|
|
140
|
|
141 procedure Set_Ignore_Errors (To : Boolean);
|
|
142 -- Indicate, when To = True, that all reported errors should
|
|
143 -- be ignored. By default reported errors are not ignored.
|
|
144
|
|
145 package Style is new Styleg
|
|
146 (Error_Msg => Error_Msg,
|
|
147 Error_Msg_S => Error_Msg_S,
|
|
148 Error_Msg_SC => Error_Msg_SC,
|
|
149 Error_Msg_SP => Error_Msg_SP);
|
|
150 -- Instantiation of the generic style package, suitable for an
|
|
151 -- instantiation of Scng.
|
|
152
|
|
153 end Errutil;
|