glr2.cc: put create_state_set_index in unnamed namespace
[bison.git] / src / complain.h
blobfe92e7a42672e0ccef2aa2de99e0aa09963eda1c
1 /* Declaration for error-reporting function for Bison.
3 Copyright (C) 2000-2002, 2006, 2009-2015, 2018-2021 Free Software
4 Foundation, Inc.
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.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19 #ifndef COMPLAIN_H_
20 # define COMPLAIN_H_ 1
22 # include <attribute.h>
24 # include "location.h"
26 /*---------------.
27 | Error stream. |
28 `---------------*/
30 /** Enable a style on \a out provided it's stderr. */
31 void begin_use_class (const char *style, FILE *out);
33 /** Disable a style on \a out provided it's stderr. */
34 void end_use_class (const char *style, FILE *out);
36 /** Flush \a out. */
37 void flush (FILE *out);
39 /** Whether there's styling on OUT. */
40 bool is_styled (FILE *out);
42 /*-------------.
43 | --warnings. |
44 `-------------*/
46 /** The bits assigned to each warning type. */
47 typedef enum
49 warning_conflicts_rr,
50 warning_conflicts_sr,
51 warning_counterexamples,
52 warning_dangling_alias,
53 warning_deprecated,
54 warning_empty_rule,
55 warning_midrule_values,
56 warning_other,
57 warning_precedence,
58 warning_yacc, /**< POSIXME. */
60 warnings_size /**< The number of warnings. Must be last. */
61 } warning_bit;
63 /** Whether -Werror was set. */
64 extern bool warnings_are_errors;
66 /** Document --warning arguments. */
67 void warning_usage (FILE *out);
69 /** Decode a single argument from -W.
71 * \param arg the subarguments to decode.
72 * If null, then activate all the flags.
73 * \param no length of the potential "no-" prefix.
74 * Can be 0 or 3. If 3, negate the action of the subargument.
75 * \param err length of a potential "error=".
76 * Can be 0 or 6. If 6, treat the subargument as a CATEGORY.
78 * If VALUE != 0 then KEY sets flags and no-KEY clears them.
79 * If VALUE == 0 then KEY clears all flags from \c all and no-KEY sets all
80 * flags from \c all. Thus no-none = all and no-all = none.
82 void warning_argmatch (char const *arg, size_t no, size_t err);
84 /** Decode a comma-separated list of arguments from -W.
86 * \param args comma separated list of effective subarguments to decode.
87 * If 0, then activate all the flags.
89 void warnings_argmatch (char *args);
92 /*-----------.
93 | complain. |
94 `-----------*/
96 /** Initialize this module. */
97 void complain_init (void);
99 /** Reclaim resources. */
100 void complain_free (void);
102 /** Initialize support for colored messages. */
103 void complain_init_color (void);
105 /** Flags passed to diagnostics functions. */
106 typedef enum
108 Wnone = 0, /**< Issue no warnings. */
110 Wconflicts_rr = 1 << warning_conflicts_rr,
111 Wconflicts_sr = 1 << warning_conflicts_sr,
112 Wcounterexamples = 1 << warning_counterexamples,
113 Wdangling_alias = 1 << warning_dangling_alias,
114 Wdeprecated = 1 << warning_deprecated,
115 Wempty_rule = 1 << warning_empty_rule,
116 Wmidrule_values = 1 << warning_midrule_values,
117 Wother = 1 << warning_other,
118 Wprecedence = 1 << warning_precedence,
119 Wyacc = 1 << warning_yacc,
121 complaint = 1 << 11, /**< All complaints. */
122 fatal = 1 << 12, /**< All fatal errors. */
123 silent = 1 << 13, /**< Do not display the warning type. */
124 no_caret = 1 << 14, /**< Do not display caret location. */
125 note = 1 << 15, /**< Display as a note. */
127 /**< All above warnings. */
128 Weverything = ~complaint & ~fatal & ~silent,
129 Wall = Weverything & ~Wcounterexamples & ~Wdangling_alias & ~Wyacc
130 } warnings;
132 /** Whether the warnings of \a flags are all unset.
133 (Never enabled, never disabled). */
134 bool warning_is_unset (warnings flags);
136 /** Whether warnings of \a flags should be reported. */
137 bool warning_is_enabled (warnings flags);
139 /** Make a complaint, with maybe a location. */
140 void complain (location const *loc, warnings flags, char const *message, ...)
141 ATTRIBUTE_FORMAT ((__printf__, 3, 4));
143 /** Likewise, but with an \a argc/argv interface. */
144 void complain_args (location const *loc, warnings w,
145 int argc, char *arg[]);
147 /** Make a subcomplain with location and note. */
148 void subcomplain (location const *loc, warnings flags,
149 char const *message, ...)
150 ATTRIBUTE_FORMAT ((__printf__, 3, 4));
153 /** GNU Bison extension not valid with POSIX Yacc. */
154 void bison_directive (location const *loc, char const *directive);
156 /** Report an obsolete syntax, suggest the updated one. */
157 void deprecated_directive (location const *loc,
158 char const *obsolete, char const *updated);
160 /** Report a repeated directive. */
161 void duplicate_directive (char const *directive,
162 location first, location second);
164 /** Report a repeated directive for a rule. */
165 void duplicate_rule_directive (char const *directive,
166 location first, location second);
168 /** Report a syntax error, where argv[0] is the unexpected
169 token, and argv[1...argc] are the expected ones. */
170 void syntax_error (location loc,
171 int argc, const char* argv[]);
173 /** Warnings treated as errors shouldn't stop the execution as regular
174 errors should (because due to their nature, it is safe to go
175 on). Thus, there are three possible execution statuses. */
176 typedef enum
178 status_none, /**< No diagnostic issued so far. */
179 status_warning_as_error, /**< A warning was issued (but no error). */
180 status_complaint /**< An error was issued. */
181 } err_status;
183 /** Whether an error was reported. */
184 extern err_status complaint_status;
186 #endif /* !COMPLAIN_H_ */