]>
git.saurik.com Git - bison.git/blob - src/complain.c
8ebd1fb811feb80368108560a4df06336d502d8f
1 /* Declaration for error-reporting function for Bison.
3 Copyright (C) 2000-2002, 2004-2006, 2009-2012 Free Software
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 <http://www.gnu.org/licenses/>. */
19 /* Based on error.c and error.h,
20 written by David MacKenzie <djm@gnu.ai.mit.edu>. */
32 warnings warnings_flag
=
33 Wconflicts_sr
| Wconflicts_rr
| Wdeprecated
| Wother
;
36 bool complaint_issued
;
37 static unsigned *indent_ptr
= 0;
40 warnings_print_categories (warnings warn_flags
)
42 if (! (warn_flags
& silent
))
44 char const *warn_names
[] =
56 for (i
= 0; i
< ARRAY_CARDINALITY (warn_names
); ++i
)
57 if (warn_flags
& 1 << i
)
59 bool err
= warn_flags
& errors_flag
;
60 fprintf (stderr
, "%s-W", any
? ", " : " [");
61 fprintf (stderr
, "%s%s", err
? "error=" : "" , warn_names
[i
]);
65 fprintf (stderr
, "]");
69 /** Report an error message.
71 * \param loc the location, defaulting to the current file,
72 * or the program name.
73 * \param flags the category for this message.
74 * \param prefix put before the message (e.g., "warning").
75 * \param message the error message, a printf format string. Iff it
76 * ends with ": ", then no trailing newline is printed,
77 * and the caller should print the remaining
78 * newline-terminated message to stderr.
79 * \param args the arguments of the format string.
83 error_message (const location
*loc
, warnings flags
, const char *prefix
,
84 const char *message
, va_list args
)
90 pos
+= location_print (stderr
, *loc
);
92 pos
+= fprintf(stderr
, "%s", current_file
? current_file
: program_name
);
93 pos
+= fprintf(stderr
, ": ");
99 else if (*indent_ptr
> pos
)
100 fprintf (stderr
, "%*s", *indent_ptr
- pos
, "");
105 fprintf (stderr
, "%s: ", prefix
);
107 vfprintf (stderr
, message
, args
);
108 warnings_print_categories (flags
);
110 size_t l
= strlen (message
);
111 if (l
< 2 || message
[l
-2] != ':' || message
[l
-1] != ' ')
119 /** Raise a complaint. That can be a fatal error, a complaint or just a
123 complains (const location
*loc
, warnings flags
, const char *message
,
126 if (flags
& complaint
)
128 error_message (loc
, complaint
, NULL
, message
, args
);
129 complaint_issued
= true;
131 else if (flags
& fatal
)
133 error_message (loc
, fatal
, _("fatal error"), message
, args
);
136 else if (flags
& Wyacc
)
140 error_message (loc
, flags
, NULL
, message
, args
);
141 complaint_issued
= true;
143 else if (warnings_flag
& Wyacc
)
145 char* severity
= Wyacc
& errors_flag
? _("error") : _("warning");
146 set_warning_issued (Wyacc
);
147 error_message (loc
, flags
, severity
, message
, args
);
150 else if (warnings_flag
& flags
)
152 char* severity
= flags
& errors_flag
? _("error") : _("warning");
153 set_warning_issued (flags
);
154 error_message (loc
, flags
, severity
, message
, args
);
159 complain (warnings flags
, const char *message
, ...)
162 va_start (args
, message
);
163 complains (NULL
, flags
, message
, args
);
168 complain_at (location loc
, warnings flags
, const char *message
, ...)
171 va_start (args
, message
);
172 complains (&loc
, flags
, message
, args
);
176 void complain_at_indent (location loc
, warnings flags
, unsigned *indent
,
177 const char *message
, ...)
182 va_start (args
, message
);
183 complains (&loc
, flags
, message
, args
);
187 /*--------------------------------.
188 | Report a warning, and proceed. |
189 `--------------------------------*/
192 set_warning_issued (warnings warning
)
194 static bool warning_issued
= false;
195 if (!warning_issued
&& (warning
& warnings_flag
& errors_flag
))
197 fprintf (stderr
, "%s: warnings being treated as errors\n", program_name
);
198 complaint_issued
= true;
200 warning_issued
= true;