1/* Declaration for error-reporting function for Bison.
2
3 Copyright (C) 2000-2002, 2006, 2009-2015, 2018-2019 Free Software
4 Foundation, Inc.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef COMPLAIN_H_
20# define COMPLAIN_H_ 1
21
22# include "location.h"
23
24/* Sub-messages indent. */
25# define SUB_INDENT (4)
26
27/*---------------.
28| Error stream. |
29`---------------*/
30
31/** Enable a style on \a out provided it's stderr. */
32void begin_use_class (const char *style, FILE *out);
33
34/** Disable a style on \a out provided it's stderr. */
35void end_use_class (const char *style, FILE *out);
36
37/** Flush \a out. */
38void flush (FILE *out);
39
40
41/*-------------.
42| --warnings. |
43`-------------*/
44
45/** The bits assigned to each warning type. */
46typedef enum
47 {
48 warning_midrule_values, /**< Unset or unused midrule values. */
49 warning_yacc, /**< POSIXME. */
50 warning_conflicts_sr, /**< S/R conflicts. */
51 warning_conflicts_rr, /**< R/R conflicts. */
52 warning_empty_rule, /**< Implicitly empty rules. */
53 warning_deprecated, /**< Obsolete constructs. */
54 warning_precedence, /**< Useless precedence and associativity. */
55 warning_other, /**< All other warnings. */
56
57 warnings_size /**< The number of warnings. Must be last. */
58 } warning_bit;
59
60/** Whether -Werror was set. */
61extern bool warnings_are_errors;
62
63/** Decode a single argument from -W.
64 *
65 * \param arg the subarguments to decode.
66 * If null, then activate all the flags.
67 * \param no length of the potential "no-" prefix.
68 * Can be 0 or 3. If 3, negate the action of the subargument.
69 * \param err length of a potential "error=".
70 * Can be 0 or 6. If 6, treat the subargument as a CATEGORY.
71 *
72 * If VALUE != 0 then KEY sets flags and no-KEY clears them.
73 * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
74 * flags from \c all. Thus no-none = all and no-all = none.
75 */
76void warning_argmatch (char const *arg, size_t no, size_t err);
77
78/** Decode a comma-separated list of arguments from -W.
79 *
80 * \param args comma separated list of effective subarguments to decode.
81 * If 0, then activate all the flags.
82 */
83void warnings_argmatch (char *args);
84
85
86/*-----------.
87| complain. |
88`-----------*/
89
90/** Initialize this module. */
91void complain_init (void);
92
93/** Reclaim resources. */
94void complain_free (void);
95
96/** Initialize support for colored messages. */
97void complain_init_color (void);
98
99typedef enum
100 {
101 Wnone = 0, /**< Issue no warnings. */
102
103 Wmidrule_values = 1 << warning_midrule_values,
104 Wyacc = 1 << warning_yacc,
105 Wconflicts_sr = 1 << warning_conflicts_sr,
106 Wconflicts_rr = 1 << warning_conflicts_rr,
107 Wdeprecated = 1 << warning_deprecated,
108 Wempty_rule = 1 << warning_empty_rule,
109 Wprecedence = 1 << warning_precedence,
110 Wother = 1 << warning_other,
111
112 Werror = 1 << 10, /** This bit is no longer used. */
113
114 complaint = 1 << 11, /**< All complaints. */
115 fatal = 1 << 12, /**< All fatal errors. */
116 silent = 1 << 13, /**< Do not display the warning type. */
117 no_caret = 1 << 14, /**< Do not display caret location. */
118
119 /**< All above warnings. */
120 Weverything = ~complaint & ~fatal & ~silent,
121 Wall = Weverything & ~Wyacc
122 } warnings;
123
124/** Whether the warnings of \a flags are all unset.
125 (Never enabled, never disabled). */
126bool warning_is_unset (warnings flags);
127
128/** Whether warnings of \a flags should be reported. */
129bool warning_is_enabled (warnings flags);
130
131/** Make a complaint, with maybe a location. */
132void complain (location const *loc, warnings flags, char const *message, ...)
133 __attribute__ ((__format__ (__printf__, 3, 4)));
134
135/** Likewise, but with an \a argc/argv interface. */
136void complain_args (location const *loc, warnings w, unsigned *indent,
137 int argc, char *arg[]);
138
139/** Make a complaint with location and some indentation. */
140void complain_indent (location const *loc, warnings flags, unsigned *indent,
141 char const *message, ...)
142 __attribute__ ((__format__ (__printf__, 4, 5)));
143
144
145/** GNU Bison extension not valid with POSIX Yacc. */
146void bison_directive (location const *loc, char const *directive);
147
148/** Report an obsolete syntax, suggest the updated one. */
149void deprecated_directive (location const *loc,
150 char const *obsolete, char const *updated);
151
152/** Report a repeated directive. */
153void duplicate_directive (char const *directive,
154 location first, location second);
155
156/** Report a repeated directive for a rule. */
157void duplicate_rule_directive (char const *directive,
158 location first, location second);
159
160/** Warnings treated as errors shouldn't stop the execution as regular
161 errors should (because due to their nature, it is safe to go
162 on). Thus, there are three possible execution statuses. */
163typedef enum
164 {
165 status_none, /**< No diagnostic issued so far. */
166 status_warning_as_error, /**< A warning was issued (but no error). */
167 status_complaint /**< An error was issued. */
168 } err_status;
169
170/** Whether an error was reported. */
171extern err_status complaint_status;
172
173#endif /* !COMPLAIN_H_ */
174