annotate gcc/diagnostic.c @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Language-independent diagnostic subroutines for the GNU Compiler Collection
16
kono
parents: 14
diff changeset
2 Copyright (C) 1999-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 /* This file implements the language independent aspect of diagnostic
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 message module. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "coretypes.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "version.h"
16
kono
parents: 14
diff changeset
29 #include "demangle.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 #include "intl.h"
16
kono
parents: 14
diff changeset
31 #include "backtrace.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "diagnostic.h"
16
kono
parents: 14
diff changeset
33 #include "diagnostic-color.h"
kono
parents: 14
diff changeset
34 #include "edit-context.h"
kono
parents: 14
diff changeset
35 #include "selftest.h"
kono
parents: 14
diff changeset
36
kono
parents: 14
diff changeset
37 #ifdef HAVE_TERMIOS_H
kono
parents: 14
diff changeset
38 # include <termios.h>
kono
parents: 14
diff changeset
39 #endif
kono
parents: 14
diff changeset
40
kono
parents: 14
diff changeset
41 #ifdef GWINSZ_IN_SYS_IOCTL
kono
parents: 14
diff changeset
42 # include <sys/ioctl.h>
kono
parents: 14
diff changeset
43 #endif
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
45 #define pedantic_warning_kind(DC) \
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
46 ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
47 #define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
48 #define permissive_error_option(DC) ((DC)->opt_permissive)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 /* Prototypes. */
16
kono
parents: 14
diff changeset
51 static bool diagnostic_impl (rich_location *, int, const char *,
kono
parents: 14
diff changeset
52 va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(3,0);
kono
parents: 14
diff changeset
53 static bool diagnostic_n_impl (location_t, int, int, const char *,
kono
parents: 14
diff changeset
54 const char *, va_list *,
kono
parents: 14
diff changeset
55 diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
kono
parents: 14
diff changeset
56 static bool diagnostic_n_impl_richloc (rich_location *, int, int, const char *,
kono
parents: 14
diff changeset
57 const char *, va_list *,
kono
parents: 14
diff changeset
58 diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 static void real_abort (void) ATTRIBUTE_NORETURN;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
63 /* Name of program invoked, sans directories. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
64
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
65 const char *progname;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
66
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 /* A diagnostic_context surrogate for stderr. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
68 static diagnostic_context global_diagnostic_context;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 diagnostic_context *global_dc = &global_diagnostic_context;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
70
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
71 /* Return a malloc'd string containing MSG formatted a la printf. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
72 caller is responsible for freeing the memory. */
16
kono
parents: 14
diff changeset
73 char *
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 build_message_string (const char *msg, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 char *str;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
79 va_start (ap, msg);
16
kono
parents: 14
diff changeset
80 str = xvasprintf (msg, ap);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 return str;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 /* Same as diagnostic_build_prefix, but only the source FILE is given. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 char *
16
kono
parents: 14
diff changeset
88 file_name_as_prefix (diagnostic_context *context, const char *f)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 {
16
kono
parents: 14
diff changeset
90 const char *locus_cs
kono
parents: 14
diff changeset
91 = colorize_start (pp_show_color (context->printer), "locus");
kono
parents: 14
diff changeset
92 const char *locus_ce = colorize_stop (pp_show_color (context->printer));
kono
parents: 14
diff changeset
93 return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
97
16
kono
parents: 14
diff changeset
98 /* Return the value of the getenv("COLUMNS") as an integer. If the
kono
parents: 14
diff changeset
99 value is not set to a positive integer, use ioctl to get the
kono
parents: 14
diff changeset
100 terminal width. If it fails, return INT_MAX. */
kono
parents: 14
diff changeset
101 int
kono
parents: 14
diff changeset
102 get_terminal_width (void)
kono
parents: 14
diff changeset
103 {
kono
parents: 14
diff changeset
104 const char * s = getenv ("COLUMNS");
kono
parents: 14
diff changeset
105 if (s != NULL) {
kono
parents: 14
diff changeset
106 int n = atoi (s);
kono
parents: 14
diff changeset
107 if (n > 0)
kono
parents: 14
diff changeset
108 return n;
kono
parents: 14
diff changeset
109 }
kono
parents: 14
diff changeset
110
kono
parents: 14
diff changeset
111 #ifdef TIOCGWINSZ
kono
parents: 14
diff changeset
112 struct winsize w;
kono
parents: 14
diff changeset
113 w.ws_col = 0;
kono
parents: 14
diff changeset
114 if (ioctl (0, TIOCGWINSZ, &w) == 0 && w.ws_col > 0)
kono
parents: 14
diff changeset
115 return w.ws_col;
kono
parents: 14
diff changeset
116 #endif
kono
parents: 14
diff changeset
117
kono
parents: 14
diff changeset
118 return INT_MAX;
kono
parents: 14
diff changeset
119 }
kono
parents: 14
diff changeset
120
kono
parents: 14
diff changeset
121 /* Set caret_max_width to value. */
kono
parents: 14
diff changeset
122 void
kono
parents: 14
diff changeset
123 diagnostic_set_caret_max_width (diagnostic_context *context, int value)
kono
parents: 14
diff changeset
124 {
kono
parents: 14
diff changeset
125 /* One minus to account for the leading empty space. */
kono
parents: 14
diff changeset
126 value = value ? value - 1
kono
parents: 14
diff changeset
127 : (isatty (fileno (pp_buffer (context->printer)->stream))
kono
parents: 14
diff changeset
128 ? get_terminal_width () - 1: INT_MAX);
kono
parents: 14
diff changeset
129
kono
parents: 14
diff changeset
130 if (value <= 0)
kono
parents: 14
diff changeset
131 value = INT_MAX;
kono
parents: 14
diff changeset
132
kono
parents: 14
diff changeset
133 context->caret_max_width = value;
kono
parents: 14
diff changeset
134 }
kono
parents: 14
diff changeset
135
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 /* Initialize the diagnostic message outputting machinery. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 void
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
138 diagnostic_initialize (diagnostic_context *context, int n_opts)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 {
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
140 int i;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
141
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 /* Allocate a basic pretty-printer. Clients will replace this a
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 much more elaborated pretty-printer if they wish. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 context->printer = XNEW (pretty_printer);
16
kono
parents: 14
diff changeset
145 new (context->printer) pretty_printer ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 context->warning_as_error_requested = false;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
149 context->n_opts = n_opts;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
150 context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
151 for (i = 0; i < n_opts; i++)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
152 context->classify_diagnostic[i] = DK_UNSPECIFIED;
16
kono
parents: 14
diff changeset
153 context->show_caret = false;
kono
parents: 14
diff changeset
154 diagnostic_set_caret_max_width (context, pp_line_cutoff (context->printer));
kono
parents: 14
diff changeset
155 for (i = 0; i < rich_location::STATICALLY_ALLOCATED_RANGES; i++)
kono
parents: 14
diff changeset
156 context->caret_chars[i] = '^';
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 context->show_option_requested = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 context->abort_on_error = false;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
159 context->show_column = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
160 context->pedantic_errors = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
161 context->permissive = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
162 context->opt_permissive = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
163 context->fatal_errors = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
164 context->dc_inhibit_warnings = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
165 context->dc_warn_system_headers = false;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
166 context->max_errors = 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 context->internal_error = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 diagnostic_starter (context) = default_diagnostic_starter;
16
kono
parents: 14
diff changeset
169 context->start_span = default_diagnostic_start_span_fn;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 diagnostic_finalizer (context) = default_diagnostic_finalizer;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
171 context->option_enabled = NULL;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
172 context->option_state = NULL;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
173 context->option_name = NULL;
16
kono
parents: 14
diff changeset
174 context->last_location = UNKNOWN_LOCATION;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 context->last_module = 0;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
176 context->x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 context->lock = 0;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
178 context->inhibit_notes_p = false;
16
kono
parents: 14
diff changeset
179 context->colorize_source_p = false;
kono
parents: 14
diff changeset
180 context->show_ruler_p = false;
kono
parents: 14
diff changeset
181 context->parseable_fixits_p = false;
kono
parents: 14
diff changeset
182 context->edit_context_ptr = NULL;
kono
parents: 14
diff changeset
183 }
kono
parents: 14
diff changeset
184
kono
parents: 14
diff changeset
185 /* Maybe initialize the color support. We require clients to do this
kono
parents: 14
diff changeset
186 explicitly, since most clients don't want color. When called
kono
parents: 14
diff changeset
187 without a VALUE, it initializes with DIAGNOSTICS_COLOR_DEFAULT. */
kono
parents: 14
diff changeset
188
kono
parents: 14
diff changeset
189 void
kono
parents: 14
diff changeset
190 diagnostic_color_init (diagnostic_context *context, int value /*= -1 */)
kono
parents: 14
diff changeset
191 {
kono
parents: 14
diff changeset
192 /* value == -1 is the default value. */
kono
parents: 14
diff changeset
193 if (value < 0)
kono
parents: 14
diff changeset
194 {
kono
parents: 14
diff changeset
195 /* If DIAGNOSTICS_COLOR_DEFAULT is -1, default to
kono
parents: 14
diff changeset
196 -fdiagnostics-color=auto if GCC_COLORS is in the environment,
kono
parents: 14
diff changeset
197 otherwise default to -fdiagnostics-color=never, for other
kono
parents: 14
diff changeset
198 values default to that
kono
parents: 14
diff changeset
199 -fdiagnostics-color={never,auto,always}. */
kono
parents: 14
diff changeset
200 if (DIAGNOSTICS_COLOR_DEFAULT == -1)
kono
parents: 14
diff changeset
201 {
kono
parents: 14
diff changeset
202 if (!getenv ("GCC_COLORS"))
kono
parents: 14
diff changeset
203 return;
kono
parents: 14
diff changeset
204 value = DIAGNOSTICS_COLOR_AUTO;
kono
parents: 14
diff changeset
205 }
kono
parents: 14
diff changeset
206 else
kono
parents: 14
diff changeset
207 value = DIAGNOSTICS_COLOR_DEFAULT;
kono
parents: 14
diff changeset
208 }
kono
parents: 14
diff changeset
209 pp_show_color (context->printer)
kono
parents: 14
diff changeset
210 = colorize_init ((diagnostic_color_rule_t) value);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
211 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
212
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
213 /* Do any cleaning up required after the last diagnostic is emitted. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
214
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
215 void
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
216 diagnostic_finish (diagnostic_context *context)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
217 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
218 /* Some of the errors may actually have been warnings. */
16
kono
parents: 14
diff changeset
219 if (diagnostic_kind_count (context, DK_WERROR))
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
220 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
221 /* -Werror was given. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
222 if (context->warning_as_error_requested)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
223 pp_verbatim (context->printer,
16
kono
parents: 14
diff changeset
224 _("%s: all warnings being treated as errors"),
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
225 progname);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
226 /* At least one -Werror= was given. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
227 else
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
228 pp_verbatim (context->printer,
16
kono
parents: 14
diff changeset
229 _("%s: some warnings being treated as errors"),
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
230 progname);
16
kono
parents: 14
diff changeset
231 pp_newline_and_flush (context->printer);
kono
parents: 14
diff changeset
232 }
kono
parents: 14
diff changeset
233
kono
parents: 14
diff changeset
234 diagnostic_file_cache_fini ();
kono
parents: 14
diff changeset
235
kono
parents: 14
diff changeset
236 XDELETEVEC (context->classify_diagnostic);
kono
parents: 14
diff changeset
237 context->classify_diagnostic = NULL;
kono
parents: 14
diff changeset
238
kono
parents: 14
diff changeset
239 /* diagnostic_initialize allocates context->printer using XNEW
kono
parents: 14
diff changeset
240 and placement-new. */
kono
parents: 14
diff changeset
241 context->printer->~pretty_printer ();
kono
parents: 14
diff changeset
242 XDELETE (context->printer);
kono
parents: 14
diff changeset
243 context->printer = NULL;
kono
parents: 14
diff changeset
244
kono
parents: 14
diff changeset
245 if (context->edit_context_ptr)
kono
parents: 14
diff changeset
246 {
kono
parents: 14
diff changeset
247 delete context->edit_context_ptr;
kono
parents: 14
diff changeset
248 context->edit_context_ptr = NULL;
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
249 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 /* Initialize DIAGNOSTIC, where the message MSG has already been
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 translated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
16
kono
parents: 14
diff changeset
256 va_list *args, rich_location *richloc,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 diagnostic_t kind)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 {
16
kono
parents: 14
diff changeset
259 gcc_assert (richloc);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 diagnostic->message.err_no = errno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 diagnostic->message.args_ptr = args;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 diagnostic->message.format_spec = msg;
16
kono
parents: 14
diff changeset
263 diagnostic->message.m_richloc = richloc;
kono
parents: 14
diff changeset
264 diagnostic->richloc = richloc;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 diagnostic->kind = kind;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 diagnostic->option_index = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 /* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 translated. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
16
kono
parents: 14
diff changeset
273 va_list *args, rich_location *richloc,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 diagnostic_t kind)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 {
16
kono
parents: 14
diff changeset
276 gcc_assert (richloc);
kono
parents: 14
diff changeset
277 diagnostic_set_info_translated (diagnostic, _(gmsgid), args, richloc, kind);
kono
parents: 14
diff changeset
278 }
kono
parents: 14
diff changeset
279
kono
parents: 14
diff changeset
280 static const char *const diagnostic_kind_color[] = {
kono
parents: 14
diff changeset
281 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
kono
parents: 14
diff changeset
282 #include "diagnostic.def"
kono
parents: 14
diff changeset
283 #undef DEFINE_DIAGNOSTIC_KIND
kono
parents: 14
diff changeset
284 NULL
kono
parents: 14
diff changeset
285 };
kono
parents: 14
diff changeset
286
kono
parents: 14
diff changeset
287 /* Get a color name for diagnostics of type KIND
kono
parents: 14
diff changeset
288 Result could be NULL. */
kono
parents: 14
diff changeset
289
kono
parents: 14
diff changeset
290 const char *
kono
parents: 14
diff changeset
291 diagnostic_get_color_for_kind (diagnostic_t kind)
kono
parents: 14
diff changeset
292 {
kono
parents: 14
diff changeset
293 return diagnostic_kind_color[kind];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295
16
kono
parents: 14
diff changeset
296 /* Return a malloc'd string describing a location e.g. "foo.c:42:10".
kono
parents: 14
diff changeset
297 The caller is responsible for freeing the memory. */
kono
parents: 14
diff changeset
298
kono
parents: 14
diff changeset
299 static char *
kono
parents: 14
diff changeset
300 diagnostic_get_location_text (diagnostic_context *context,
kono
parents: 14
diff changeset
301 expanded_location s)
kono
parents: 14
diff changeset
302 {
kono
parents: 14
diff changeset
303 pretty_printer *pp = context->printer;
kono
parents: 14
diff changeset
304 const char *locus_cs = colorize_start (pp_show_color (pp), "locus");
kono
parents: 14
diff changeset
305 const char *locus_ce = colorize_stop (pp_show_color (pp));
kono
parents: 14
diff changeset
306
kono
parents: 14
diff changeset
307 if (s.file == NULL)
kono
parents: 14
diff changeset
308 return build_message_string ("%s%s:%s", locus_cs, progname, locus_ce);
kono
parents: 14
diff changeset
309
kono
parents: 14
diff changeset
310 if (!strcmp (s.file, N_("<built-in>")))
kono
parents: 14
diff changeset
311 return build_message_string ("%s%s:%s", locus_cs, s.file, locus_ce);
kono
parents: 14
diff changeset
312
kono
parents: 14
diff changeset
313 if (context->show_column)
kono
parents: 14
diff changeset
314 return build_message_string ("%s%s:%d:%d:%s", locus_cs, s.file, s.line,
kono
parents: 14
diff changeset
315 s.column, locus_ce);
kono
parents: 14
diff changeset
316 else
kono
parents: 14
diff changeset
317 return build_message_string ("%s%s:%d:%s", locus_cs, s.file, s.line,
kono
parents: 14
diff changeset
318 locus_ce);
kono
parents: 14
diff changeset
319 }
kono
parents: 14
diff changeset
320
kono
parents: 14
diff changeset
321 /* Return a malloc'd string describing a location and the severity of the
kono
parents: 14
diff changeset
322 diagnostic, e.g. "foo.c:42:10: error: ". The caller is responsible for
kono
parents: 14
diff changeset
323 freeing the memory. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 char *
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
325 diagnostic_build_prefix (diagnostic_context *context,
16
kono
parents: 14
diff changeset
326 const diagnostic_info *diagnostic)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 static const char *const diagnostic_kind_text[] = {
16
kono
parents: 14
diff changeset
329 #define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 #include "diagnostic.def"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 #undef DEFINE_DIAGNOSTIC_KIND
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 "must-not-happen"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 };
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335
16
kono
parents: 14
diff changeset
336 const char *text = _(diagnostic_kind_text[diagnostic->kind]);
kono
parents: 14
diff changeset
337 const char *text_cs = "", *text_ce = "";
kono
parents: 14
diff changeset
338 pretty_printer *pp = context->printer;
kono
parents: 14
diff changeset
339
kono
parents: 14
diff changeset
340 if (diagnostic_kind_color[diagnostic->kind])
kono
parents: 14
diff changeset
341 {
kono
parents: 14
diff changeset
342 text_cs = colorize_start (pp_show_color (pp),
kono
parents: 14
diff changeset
343 diagnostic_kind_color[diagnostic->kind]);
kono
parents: 14
diff changeset
344 text_ce = colorize_stop (pp_show_color (pp));
kono
parents: 14
diff changeset
345 }
kono
parents: 14
diff changeset
346
kono
parents: 14
diff changeset
347 expanded_location s = diagnostic_expand_location (diagnostic);
kono
parents: 14
diff changeset
348 char *location_text = diagnostic_get_location_text (context, s);
kono
parents: 14
diff changeset
349
kono
parents: 14
diff changeset
350 char *result = build_message_string ("%s %s%s%s", location_text,
kono
parents: 14
diff changeset
351 text_cs, text, text_ce);
kono
parents: 14
diff changeset
352 free (location_text);
kono
parents: 14
diff changeset
353 return result;
kono
parents: 14
diff changeset
354 }
kono
parents: 14
diff changeset
355
kono
parents: 14
diff changeset
356 /* Functions at which to stop the backtrace print. It's not
kono
parents: 14
diff changeset
357 particularly helpful to print the callers of these functions. */
kono
parents: 14
diff changeset
358
kono
parents: 14
diff changeset
359 static const char * const bt_stop[] =
kono
parents: 14
diff changeset
360 {
kono
parents: 14
diff changeset
361 "main",
kono
parents: 14
diff changeset
362 "toplev::main",
kono
parents: 14
diff changeset
363 "execute_one_pass",
kono
parents: 14
diff changeset
364 "compile_file",
kono
parents: 14
diff changeset
365 };
kono
parents: 14
diff changeset
366
kono
parents: 14
diff changeset
367 /* A callback function passed to the backtrace_full function. */
kono
parents: 14
diff changeset
368
kono
parents: 14
diff changeset
369 static int
kono
parents: 14
diff changeset
370 bt_callback (void *data, uintptr_t pc, const char *filename, int lineno,
kono
parents: 14
diff changeset
371 const char *function)
kono
parents: 14
diff changeset
372 {
kono
parents: 14
diff changeset
373 int *pcount = (int *) data;
kono
parents: 14
diff changeset
374
kono
parents: 14
diff changeset
375 /* If we don't have any useful information, don't print
kono
parents: 14
diff changeset
376 anything. */
kono
parents: 14
diff changeset
377 if (filename == NULL && function == NULL)
kono
parents: 14
diff changeset
378 return 0;
kono
parents: 14
diff changeset
379
kono
parents: 14
diff changeset
380 /* Skip functions in diagnostic.c. */
kono
parents: 14
diff changeset
381 if (*pcount == 0
kono
parents: 14
diff changeset
382 && filename != NULL
kono
parents: 14
diff changeset
383 && strcmp (lbasename (filename), "diagnostic.c") == 0)
kono
parents: 14
diff changeset
384 return 0;
kono
parents: 14
diff changeset
385
kono
parents: 14
diff changeset
386 /* Print up to 20 functions. We could make this a --param, but
kono
parents: 14
diff changeset
387 since this is only for debugging just use a constant for now. */
kono
parents: 14
diff changeset
388 if (*pcount >= 20)
kono
parents: 14
diff changeset
389 {
kono
parents: 14
diff changeset
390 /* Returning a non-zero value stops the backtrace. */
kono
parents: 14
diff changeset
391 return 1;
kono
parents: 14
diff changeset
392 }
kono
parents: 14
diff changeset
393 ++*pcount;
kono
parents: 14
diff changeset
394
kono
parents: 14
diff changeset
395 char *alc = NULL;
kono
parents: 14
diff changeset
396 if (function != NULL)
kono
parents: 14
diff changeset
397 {
kono
parents: 14
diff changeset
398 char *str = cplus_demangle_v3 (function,
kono
parents: 14
diff changeset
399 (DMGL_VERBOSE | DMGL_ANSI
kono
parents: 14
diff changeset
400 | DMGL_GNU_V3 | DMGL_PARAMS));
kono
parents: 14
diff changeset
401 if (str != NULL)
kono
parents: 14
diff changeset
402 {
kono
parents: 14
diff changeset
403 alc = str;
kono
parents: 14
diff changeset
404 function = str;
kono
parents: 14
diff changeset
405 }
kono
parents: 14
diff changeset
406
kono
parents: 14
diff changeset
407 for (size_t i = 0; i < ARRAY_SIZE (bt_stop); ++i)
kono
parents: 14
diff changeset
408 {
kono
parents: 14
diff changeset
409 size_t len = strlen (bt_stop[i]);
kono
parents: 14
diff changeset
410 if (strncmp (function, bt_stop[i], len) == 0
kono
parents: 14
diff changeset
411 && (function[len] == '\0' || function[len] == '('))
kono
parents: 14
diff changeset
412 {
kono
parents: 14
diff changeset
413 if (alc != NULL)
kono
parents: 14
diff changeset
414 free (alc);
kono
parents: 14
diff changeset
415 /* Returning a non-zero value stops the backtrace. */
kono
parents: 14
diff changeset
416 return 1;
kono
parents: 14
diff changeset
417 }
kono
parents: 14
diff changeset
418 }
kono
parents: 14
diff changeset
419 }
kono
parents: 14
diff changeset
420
kono
parents: 14
diff changeset
421 fprintf (stderr, "0x%lx %s\n\t%s:%d\n",
kono
parents: 14
diff changeset
422 (unsigned long) pc,
kono
parents: 14
diff changeset
423 function == NULL ? "???" : function,
kono
parents: 14
diff changeset
424 filename == NULL ? "???" : filename,
kono
parents: 14
diff changeset
425 lineno);
kono
parents: 14
diff changeset
426
kono
parents: 14
diff changeset
427 if (alc != NULL)
kono
parents: 14
diff changeset
428 free (alc);
kono
parents: 14
diff changeset
429
kono
parents: 14
diff changeset
430 return 0;
kono
parents: 14
diff changeset
431 }
kono
parents: 14
diff changeset
432
kono
parents: 14
diff changeset
433 /* A callback function passed to the backtrace_full function. This is
kono
parents: 14
diff changeset
434 called if backtrace_full has an error. */
kono
parents: 14
diff changeset
435
kono
parents: 14
diff changeset
436 static void
kono
parents: 14
diff changeset
437 bt_err_callback (void *data ATTRIBUTE_UNUSED, const char *msg, int errnum)
kono
parents: 14
diff changeset
438 {
kono
parents: 14
diff changeset
439 if (errnum < 0)
kono
parents: 14
diff changeset
440 {
kono
parents: 14
diff changeset
441 /* This means that no debug info was available. Just quietly
kono
parents: 14
diff changeset
442 skip printing backtrace info. */
kono
parents: 14
diff changeset
443 return;
kono
parents: 14
diff changeset
444 }
kono
parents: 14
diff changeset
445 fprintf (stderr, "%s%s%s\n", msg, errnum == 0 ? "" : ": ",
kono
parents: 14
diff changeset
446 errnum == 0 ? "" : xstrerror (errnum));
kono
parents: 14
diff changeset
447 }
kono
parents: 14
diff changeset
448
kono
parents: 14
diff changeset
449 /* Check if we've met the maximum error limit, and if so fatally exit
kono
parents: 14
diff changeset
450 with a message. CONTEXT is the context to check, and FLUSH
kono
parents: 14
diff changeset
451 indicates whether a diagnostic_finish call is needed. */
kono
parents: 14
diff changeset
452
kono
parents: 14
diff changeset
453 void
kono
parents: 14
diff changeset
454 diagnostic_check_max_errors (diagnostic_context *context, bool flush)
kono
parents: 14
diff changeset
455 {
kono
parents: 14
diff changeset
456 if (!context->max_errors)
kono
parents: 14
diff changeset
457 return;
kono
parents: 14
diff changeset
458
kono
parents: 14
diff changeset
459 int count = (diagnostic_kind_count (context, DK_ERROR)
kono
parents: 14
diff changeset
460 + diagnostic_kind_count (context, DK_SORRY)
kono
parents: 14
diff changeset
461 + diagnostic_kind_count (context, DK_WERROR));
kono
parents: 14
diff changeset
462
kono
parents: 14
diff changeset
463 if (count >= context->max_errors)
kono
parents: 14
diff changeset
464 {
kono
parents: 14
diff changeset
465 fnotice (stderr,
kono
parents: 14
diff changeset
466 "compilation terminated due to -fmax-errors=%u.\n",
kono
parents: 14
diff changeset
467 context->max_errors);
kono
parents: 14
diff changeset
468 if (flush)
kono
parents: 14
diff changeset
469 diagnostic_finish (context);
kono
parents: 14
diff changeset
470 exit (FATAL_EXIT_CODE);
kono
parents: 14
diff changeset
471 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
473
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 /* Take any action which is expected to happen after the diagnostic
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 is written out. This function does not always return. */
16
kono
parents: 14
diff changeset
476 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477 diagnostic_action_after_output (diagnostic_context *context,
16
kono
parents: 14
diff changeset
478 diagnostic_t diag_kind)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 {
16
kono
parents: 14
diff changeset
480 switch (diag_kind)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 case DK_DEBUG:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 case DK_NOTE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484 case DK_ANACHRONISM:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 case DK_WARNING:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 case DK_ERROR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 case DK_SORRY:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 if (context->abort_on_error)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 real_abort ();
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
492 if (context->fatal_errors)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
495 diagnostic_finish (context);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
496 exit (FATAL_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 case DK_ICE:
16
kono
parents: 14
diff changeset
501 case DK_ICE_NOBT:
kono
parents: 14
diff changeset
502 {
kono
parents: 14
diff changeset
503 struct backtrace_state *state = NULL;
kono
parents: 14
diff changeset
504 if (diag_kind == DK_ICE)
kono
parents: 14
diff changeset
505 state = backtrace_create_state (NULL, 0, bt_err_callback, NULL);
kono
parents: 14
diff changeset
506 int count = 0;
kono
parents: 14
diff changeset
507 if (state != NULL)
kono
parents: 14
diff changeset
508 backtrace_full (state, 2, bt_callback, bt_err_callback,
kono
parents: 14
diff changeset
509 (void *) &count);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510
16
kono
parents: 14
diff changeset
511 if (context->abort_on_error)
kono
parents: 14
diff changeset
512 real_abort ();
kono
parents: 14
diff changeset
513
kono
parents: 14
diff changeset
514 fnotice (stderr, "Please submit a full bug report,\n"
kono
parents: 14
diff changeset
515 "with preprocessed source if appropriate.\n");
kono
parents: 14
diff changeset
516 if (count > 0)
kono
parents: 14
diff changeset
517 fnotice (stderr,
kono
parents: 14
diff changeset
518 ("Please include the complete backtrace "
kono
parents: 14
diff changeset
519 "with any bug report.\n"));
kono
parents: 14
diff changeset
520 fnotice (stderr, "See %s for instructions.\n", bug_report_url);
kono
parents: 14
diff changeset
521
kono
parents: 14
diff changeset
522 exit (ICE_EXIT_CODE);
kono
parents: 14
diff changeset
523 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 case DK_FATAL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 if (context->abort_on_error)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 real_abort ();
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
528 diagnostic_finish (context);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 fnotice (stderr, "compilation terminated.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 exit (FATAL_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
532 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536
16
kono
parents: 14
diff changeset
537 /* True if the last module or file in which a diagnostic was reported is
kono
parents: 14
diff changeset
538 different from the current one. */
kono
parents: 14
diff changeset
539
kono
parents: 14
diff changeset
540 static bool
kono
parents: 14
diff changeset
541 last_module_changed_p (diagnostic_context *context,
kono
parents: 14
diff changeset
542 const line_map_ordinary *map)
kono
parents: 14
diff changeset
543 {
kono
parents: 14
diff changeset
544 return context->last_module != map;
kono
parents: 14
diff changeset
545 }
kono
parents: 14
diff changeset
546
kono
parents: 14
diff changeset
547 /* Remember the current module or file as being the last one in which we
kono
parents: 14
diff changeset
548 report a diagnostic. */
kono
parents: 14
diff changeset
549
kono
parents: 14
diff changeset
550 static void
kono
parents: 14
diff changeset
551 set_last_module (diagnostic_context *context, const line_map_ordinary *map)
kono
parents: 14
diff changeset
552 {
kono
parents: 14
diff changeset
553 context->last_module = map;
kono
parents: 14
diff changeset
554 }
kono
parents: 14
diff changeset
555
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 void
16
kono
parents: 14
diff changeset
557 diagnostic_report_current_module (diagnostic_context *context, location_t where)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 {
16
kono
parents: 14
diff changeset
559 const line_map_ordinary *map = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 if (pp_needs_newline (context->printer))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 pp_newline (context->printer);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 pp_needs_newline (context->printer) = false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566
16
kono
parents: 14
diff changeset
567 if (where <= BUILTINS_LOCATION)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
568 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569
16
kono
parents: 14
diff changeset
570 linemap_resolve_location (line_table, where,
kono
parents: 14
diff changeset
571 LRK_MACRO_DEFINITION_LOCATION,
kono
parents: 14
diff changeset
572 &map);
kono
parents: 14
diff changeset
573
kono
parents: 14
diff changeset
574 if (map && last_module_changed_p (context, map))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 {
16
kono
parents: 14
diff changeset
576 set_last_module (context, map);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 if (! MAIN_FILE_P (map))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 map = INCLUDED_FROM (line_table, map);
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
580 if (context->show_column)
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
581 pp_verbatim (context->printer,
16
kono
parents: 14
diff changeset
582 "In file included from %r%s:%d:%d%R", "locus",
kono
parents: 14
diff changeset
583 LINEMAP_FILE (map),
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
584 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
585 else
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
586 pp_verbatim (context->printer,
16
kono
parents: 14
diff changeset
587 "In file included from %r%s:%d%R", "locus",
kono
parents: 14
diff changeset
588 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 while (! MAIN_FILE_P (map))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 map = INCLUDED_FROM (line_table, map);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 pp_verbatim (context->printer,
16
kono
parents: 14
diff changeset
593 ",\n from %r%s:%d%R", "locus",
kono
parents: 14
diff changeset
594 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 pp_verbatim (context->printer, ":");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 pp_newline (context->printer);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
602 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 default_diagnostic_starter (diagnostic_context *context,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 diagnostic_info *diagnostic)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 {
16
kono
parents: 14
diff changeset
606 diagnostic_report_current_module (context, diagnostic_location (diagnostic));
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
607 pp_set_prefix (context->printer, diagnostic_build_prefix (context,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
608 diagnostic));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
611 void
16
kono
parents: 14
diff changeset
612 default_diagnostic_start_span_fn (diagnostic_context *context,
kono
parents: 14
diff changeset
613 expanded_location exploc)
kono
parents: 14
diff changeset
614 {
kono
parents: 14
diff changeset
615 pp_set_prefix (context->printer,
kono
parents: 14
diff changeset
616 diagnostic_get_location_text (context, exploc));
kono
parents: 14
diff changeset
617 pp_string (context->printer, "");
kono
parents: 14
diff changeset
618 pp_newline (context->printer);
kono
parents: 14
diff changeset
619 }
kono
parents: 14
diff changeset
620
kono
parents: 14
diff changeset
621 void
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 default_diagnostic_finalizer (diagnostic_context *context,
16
kono
parents: 14
diff changeset
623 diagnostic_info *diagnostic)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 {
16
kono
parents: 14
diff changeset
625 diagnostic_show_locus (context, diagnostic->richloc, diagnostic->kind);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 pp_destroy_prefix (context->printer);
16
kono
parents: 14
diff changeset
627 pp_flush (context->printer);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 /* Interface to specify diagnostic kind overrides. Returns the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631 previous setting, or DK_UNSPECIFIED if the parameters are out of
16
kono
parents: 14
diff changeset
632 range. If OPTION_INDEX is zero, the new setting is for all the
kono
parents: 14
diff changeset
633 diagnostics. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 diagnostic_t
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 diagnostic_classify_diagnostic (diagnostic_context *context,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 int option_index,
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
637 diagnostic_t new_kind,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
638 location_t where)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 diagnostic_t old_kind;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641
16
kono
parents: 14
diff changeset
642 if (option_index < 0
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
643 || option_index >= context->n_opts
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 return DK_UNSPECIFIED;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 old_kind = context->classify_diagnostic[option_index];
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
648
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
649 /* Handle pragmas separately, since we need to keep track of *where*
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
650 the pragmas were. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
651 if (where != UNKNOWN_LOCATION)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
652 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
653 int i;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
654
16
kono
parents: 14
diff changeset
655 /* Record the command-line status, so we can reset it back on DK_POP. */
kono
parents: 14
diff changeset
656 if (old_kind == DK_UNSPECIFIED)
kono
parents: 14
diff changeset
657 {
kono
parents: 14
diff changeset
658 old_kind = !context->option_enabled (option_index,
kono
parents: 14
diff changeset
659 context->option_state)
kono
parents: 14
diff changeset
660 ? DK_IGNORED : (context->warning_as_error_requested
kono
parents: 14
diff changeset
661 ? DK_ERROR : DK_WARNING);
kono
parents: 14
diff changeset
662 context->classify_diagnostic[option_index] = old_kind;
kono
parents: 14
diff changeset
663 }
kono
parents: 14
diff changeset
664
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
665 for (i = context->n_classification_history - 1; i >= 0; i --)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
666 if (context->classification_history[i].option == option_index)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
667 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
668 old_kind = context->classification_history[i].kind;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
669 break;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
670 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
671
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
672 i = context->n_classification_history;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
673 context->classification_history =
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
674 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
675 * sizeof (diagnostic_classification_change_t));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
676 context->classification_history[i].location = where;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
677 context->classification_history[i].option = option_index;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
678 context->classification_history[i].kind = new_kind;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
679 context->n_classification_history ++;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
680 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
681 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
682 context->classify_diagnostic[option_index] = new_kind;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
683
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 return old_kind;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
687 /* Save all diagnostic classifications in a stack. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
688 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
689 diagnostic_push_diagnostics (diagnostic_context *context, location_t where ATTRIBUTE_UNUSED)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
690 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
691 context->push_list = (int *) xrealloc (context->push_list, (context->n_push + 1) * sizeof (int));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
692 context->push_list[context->n_push ++] = context->n_classification_history;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
693 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
694
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
695 /* Restore the topmost classification set off the stack. If the stack
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
696 is empty, revert to the state based on command line parameters. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
697 void
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
698 diagnostic_pop_diagnostics (diagnostic_context *context, location_t where)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
699 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
700 int jump_to;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
701 int i;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
702
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
703 if (context->n_push)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
704 jump_to = context->push_list [-- context->n_push];
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
705 else
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
706 jump_to = 0;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
707
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
708 i = context->n_classification_history;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
709 context->classification_history =
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
710 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
711 * sizeof (diagnostic_classification_change_t));
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
712 context->classification_history[i].location = where;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
713 context->classification_history[i].option = jump_to;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
714 context->classification_history[i].kind = DK_POP;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
715 context->n_classification_history ++;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
716 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
717
16
kono
parents: 14
diff changeset
718 /* Helper function for print_parseable_fixits. Print TEXT to PP, obeying the
kono
parents: 14
diff changeset
719 escaping rules for -fdiagnostics-parseable-fixits. */
kono
parents: 14
diff changeset
720
kono
parents: 14
diff changeset
721 static void
kono
parents: 14
diff changeset
722 print_escaped_string (pretty_printer *pp, const char *text)
kono
parents: 14
diff changeset
723 {
kono
parents: 14
diff changeset
724 gcc_assert (pp);
kono
parents: 14
diff changeset
725 gcc_assert (text);
kono
parents: 14
diff changeset
726
kono
parents: 14
diff changeset
727 pp_character (pp, '"');
kono
parents: 14
diff changeset
728 for (const char *ch = text; *ch; ch++)
kono
parents: 14
diff changeset
729 {
kono
parents: 14
diff changeset
730 switch (*ch)
kono
parents: 14
diff changeset
731 {
kono
parents: 14
diff changeset
732 case '\\':
kono
parents: 14
diff changeset
733 /* Escape backslash as two backslashes. */
kono
parents: 14
diff changeset
734 pp_string (pp, "\\\\");
kono
parents: 14
diff changeset
735 break;
kono
parents: 14
diff changeset
736 case '\t':
kono
parents: 14
diff changeset
737 /* Escape tab as "\t". */
kono
parents: 14
diff changeset
738 pp_string (pp, "\\t");
kono
parents: 14
diff changeset
739 break;
kono
parents: 14
diff changeset
740 case '\n':
kono
parents: 14
diff changeset
741 /* Escape newline as "\n". */
kono
parents: 14
diff changeset
742 pp_string (pp, "\\n");
kono
parents: 14
diff changeset
743 break;
kono
parents: 14
diff changeset
744 case '"':
kono
parents: 14
diff changeset
745 /* Escape doublequotes as \". */
kono
parents: 14
diff changeset
746 pp_string (pp, "\\\"");
kono
parents: 14
diff changeset
747 break;
kono
parents: 14
diff changeset
748 default:
kono
parents: 14
diff changeset
749 if (ISPRINT (*ch))
kono
parents: 14
diff changeset
750 pp_character (pp, *ch);
kono
parents: 14
diff changeset
751 else
kono
parents: 14
diff changeset
752 /* Use octal for non-printable chars. */
kono
parents: 14
diff changeset
753 {
kono
parents: 14
diff changeset
754 unsigned char c = (*ch & 0xff);
kono
parents: 14
diff changeset
755 pp_printf (pp, "\\%o%o%o", (c / 64), (c / 8) & 007, c & 007);
kono
parents: 14
diff changeset
756 }
kono
parents: 14
diff changeset
757 break;
kono
parents: 14
diff changeset
758 }
kono
parents: 14
diff changeset
759 }
kono
parents: 14
diff changeset
760 pp_character (pp, '"');
kono
parents: 14
diff changeset
761 }
kono
parents: 14
diff changeset
762
kono
parents: 14
diff changeset
763 /* Implementation of -fdiagnostics-parseable-fixits. Print a
kono
parents: 14
diff changeset
764 machine-parseable version of all fixits in RICHLOC to PP. */
kono
parents: 14
diff changeset
765
kono
parents: 14
diff changeset
766 static void
kono
parents: 14
diff changeset
767 print_parseable_fixits (pretty_printer *pp, rich_location *richloc)
kono
parents: 14
diff changeset
768 {
kono
parents: 14
diff changeset
769 gcc_assert (pp);
kono
parents: 14
diff changeset
770 gcc_assert (richloc);
kono
parents: 14
diff changeset
771
kono
parents: 14
diff changeset
772 for (unsigned i = 0; i < richloc->get_num_fixit_hints (); i++)
kono
parents: 14
diff changeset
773 {
kono
parents: 14
diff changeset
774 const fixit_hint *hint = richloc->get_fixit_hint (i);
kono
parents: 14
diff changeset
775 source_location start_loc = hint->get_start_loc ();
kono
parents: 14
diff changeset
776 expanded_location start_exploc = expand_location (start_loc);
kono
parents: 14
diff changeset
777 pp_string (pp, "fix-it:");
kono
parents: 14
diff changeset
778 print_escaped_string (pp, start_exploc.file);
kono
parents: 14
diff changeset
779 /* For compatibility with clang, print as a half-open range. */
kono
parents: 14
diff changeset
780 source_location next_loc = hint->get_next_loc ();
kono
parents: 14
diff changeset
781 expanded_location next_exploc = expand_location (next_loc);
kono
parents: 14
diff changeset
782 pp_printf (pp, ":{%i:%i-%i:%i}:",
kono
parents: 14
diff changeset
783 start_exploc.line, start_exploc.column,
kono
parents: 14
diff changeset
784 next_exploc.line, next_exploc.column);
kono
parents: 14
diff changeset
785 print_escaped_string (pp, hint->get_string ());
kono
parents: 14
diff changeset
786 pp_newline (pp);
kono
parents: 14
diff changeset
787 }
kono
parents: 14
diff changeset
788 }
kono
parents: 14
diff changeset
789
kono
parents: 14
diff changeset
790 /* Update the diag_class of DIAGNOSTIC based on its location
kono
parents: 14
diff changeset
791 relative to any
kono
parents: 14
diff changeset
792 #pragma GCC diagnostic
kono
parents: 14
diff changeset
793 directives recorded within CONTEXT.
kono
parents: 14
diff changeset
794
kono
parents: 14
diff changeset
795 Return the new diag_class of DIAGNOSTIC if it was updated, or
kono
parents: 14
diff changeset
796 DK_UNSPECIFIED otherwise. */
kono
parents: 14
diff changeset
797
kono
parents: 14
diff changeset
798 static diagnostic_t
kono
parents: 14
diff changeset
799 update_effective_level_from_pragmas (diagnostic_context *context,
kono
parents: 14
diff changeset
800 diagnostic_info *diagnostic)
kono
parents: 14
diff changeset
801 {
kono
parents: 14
diff changeset
802 diagnostic_t diag_class = DK_UNSPECIFIED;
kono
parents: 14
diff changeset
803
kono
parents: 14
diff changeset
804 if (context->n_classification_history > 0)
kono
parents: 14
diff changeset
805 {
kono
parents: 14
diff changeset
806 location_t location = diagnostic_location (diagnostic);
kono
parents: 14
diff changeset
807
kono
parents: 14
diff changeset
808 /* FIXME: Stupid search. Optimize later. */
kono
parents: 14
diff changeset
809 for (int i = context->n_classification_history - 1; i >= 0; i --)
kono
parents: 14
diff changeset
810 {
kono
parents: 14
diff changeset
811 if (linemap_location_before_p
kono
parents: 14
diff changeset
812 (line_table,
kono
parents: 14
diff changeset
813 context->classification_history[i].location,
kono
parents: 14
diff changeset
814 location))
kono
parents: 14
diff changeset
815 {
kono
parents: 14
diff changeset
816 if (context->classification_history[i].kind == (int) DK_POP)
kono
parents: 14
diff changeset
817 {
kono
parents: 14
diff changeset
818 i = context->classification_history[i].option;
kono
parents: 14
diff changeset
819 continue;
kono
parents: 14
diff changeset
820 }
kono
parents: 14
diff changeset
821 int option = context->classification_history[i].option;
kono
parents: 14
diff changeset
822 /* The option 0 is for all the diagnostics. */
kono
parents: 14
diff changeset
823 if (option == 0 || option == diagnostic->option_index)
kono
parents: 14
diff changeset
824 {
kono
parents: 14
diff changeset
825 diag_class = context->classification_history[i].kind;
kono
parents: 14
diff changeset
826 if (diag_class != DK_UNSPECIFIED)
kono
parents: 14
diff changeset
827 diagnostic->kind = diag_class;
kono
parents: 14
diff changeset
828 break;
kono
parents: 14
diff changeset
829 }
kono
parents: 14
diff changeset
830 }
kono
parents: 14
diff changeset
831 }
kono
parents: 14
diff changeset
832 }
kono
parents: 14
diff changeset
833
kono
parents: 14
diff changeset
834 return diag_class;
kono
parents: 14
diff changeset
835 }
kono
parents: 14
diff changeset
836
kono
parents: 14
diff changeset
837 /* Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's
kono
parents: 14
diff changeset
838 printer, e.g. " [-Werror=uninitialized]".
kono
parents: 14
diff changeset
839 Subroutine of diagnostic_report_diagnostic. */
kono
parents: 14
diff changeset
840
kono
parents: 14
diff changeset
841 static void
kono
parents: 14
diff changeset
842 print_option_information (diagnostic_context *context,
kono
parents: 14
diff changeset
843 const diagnostic_info *diagnostic,
kono
parents: 14
diff changeset
844 diagnostic_t orig_diag_kind)
kono
parents: 14
diff changeset
845 {
kono
parents: 14
diff changeset
846 char *option_text;
kono
parents: 14
diff changeset
847
kono
parents: 14
diff changeset
848 option_text = context->option_name (context, diagnostic->option_index,
kono
parents: 14
diff changeset
849 orig_diag_kind, diagnostic->kind);
kono
parents: 14
diff changeset
850
kono
parents: 14
diff changeset
851 if (option_text)
kono
parents: 14
diff changeset
852 {
kono
parents: 14
diff changeset
853 pretty_printer *pp = context->printer;
kono
parents: 14
diff changeset
854 pp_string (pp, " [");
kono
parents: 14
diff changeset
855 pp_string (pp, colorize_start (pp_show_color (pp),
kono
parents: 14
diff changeset
856 diagnostic_kind_color[diagnostic->kind]));
kono
parents: 14
diff changeset
857 pp_string (pp, option_text);
kono
parents: 14
diff changeset
858 pp_string (pp, colorize_stop (pp_show_color (pp)));
kono
parents: 14
diff changeset
859 pp_character (pp, ']');
kono
parents: 14
diff changeset
860 free (option_text);
kono
parents: 14
diff changeset
861 }
kono
parents: 14
diff changeset
862 }
kono
parents: 14
diff changeset
863
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
864 /* Report a diagnostic message (an error or a warning) as specified by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865 DC. This function is *the* subroutine in terms of which front-ends
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 should implement their specific diagnostic handling modules. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
867 front-end independent format specifiers are exactly those described
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
868 in the documentation of output_format.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 Return true if a diagnostic was printed, false otherwise. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 diagnostic_report_diagnostic (diagnostic_context *context,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
873 diagnostic_info *diagnostic)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 {
16
kono
parents: 14
diff changeset
875 location_t location = diagnostic_location (diagnostic);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
876 diagnostic_t orig_diag_kind = diagnostic->kind;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 /* Give preference to being able to inhibit warnings, before they
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 get reclassified to something else. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
881 && !diagnostic_report_warnings_p (context, location))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
884 if (diagnostic->kind == DK_PEDWARN)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
885 {
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
886 diagnostic->kind = pedantic_warning_kind (context);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
887 /* We do this to avoid giving the message for -pedantic-errors. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
888 orig_diag_kind = diagnostic->kind;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
889 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
890
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
891 if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
892 return false;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
893
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 if (context->lock > 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
896 /* If we're reporting an ICE in the middle of some other error,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897 try to flush out the previous error, then let this one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
898 through. Don't do this more than once. */
16
kono
parents: 14
diff changeset
899 if ((diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT)
kono
parents: 14
diff changeset
900 && context->lock == 1)
kono
parents: 14
diff changeset
901 pp_newline_and_flush (context->printer);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
902 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
903 error_recursion (context);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
904 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
905
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
906 /* If the user requested that warnings be treated as errors, so be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
907 it. Note that we do this before the next block so that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
908 individual warnings can be overridden back to warnings with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
909 -Wno-error=*. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
910 if (context->warning_as_error_requested
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
911 && diagnostic->kind == DK_WARNING)
16
kono
parents: 14
diff changeset
912 diagnostic->kind = DK_ERROR;
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
913
16
kono
parents: 14
diff changeset
914 if (diagnostic->option_index
kono
parents: 14
diff changeset
915 && diagnostic->option_index != permissive_error_option (context))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
916 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
917 /* This tests if the user provided the appropriate -Wfoo or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
918 -Wno-foo option. */
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
919 if (! context->option_enabled (diagnostic->option_index,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
920 context->option_state))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
921 return false;
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
922
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
923 /* This tests for #pragma diagnostic changes. */
16
kono
parents: 14
diff changeset
924 diagnostic_t diag_class
kono
parents: 14
diff changeset
925 = update_effective_level_from_pragmas (context, diagnostic);
kono
parents: 14
diff changeset
926
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
927 /* This tests if the user provided the appropriate -Werror=foo
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
928 option. */
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
929 if (diag_class == DK_UNSPECIFIED
16
kono
parents: 14
diff changeset
930 && (context->classify_diagnostic[diagnostic->option_index]
kono
parents: 14
diff changeset
931 != DK_UNSPECIFIED))
kono
parents: 14
diff changeset
932 diagnostic->kind
kono
parents: 14
diff changeset
933 = context->classify_diagnostic[diagnostic->option_index];
kono
parents: 14
diff changeset
934
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
935 /* This allows for future extensions, like temporarily disabling
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 warnings for ranges of source code. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 if (diagnostic->kind == DK_IGNORED)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940
16
kono
parents: 14
diff changeset
941 if (diagnostic->kind != DK_NOTE)
kono
parents: 14
diff changeset
942 diagnostic_check_max_errors (context);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 context->lock++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
945
16
kono
parents: 14
diff changeset
946 if (diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
947 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
948 /* When not checking, ICEs are converted to fatal errors when an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
949 error has already occurred. This is counteracted by
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
950 abort_on_error. */
16
kono
parents: 14
diff changeset
951 if (!CHECKING_P
kono
parents: 14
diff changeset
952 && (diagnostic_kind_count (context, DK_ERROR) > 0
kono
parents: 14
diff changeset
953 || diagnostic_kind_count (context, DK_SORRY) > 0)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
954 && !context->abort_on_error)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
955 {
16
kono
parents: 14
diff changeset
956 expanded_location s
kono
parents: 14
diff changeset
957 = expand_location (diagnostic_location (diagnostic));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959 s.file, s.line);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
960 exit (ICE_EXIT_CODE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
961 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
962 if (context->internal_error)
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
963 (*context->internal_error) (context,
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
964 diagnostic->message.format_spec,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965 diagnostic->message.args_ptr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 }
16
kono
parents: 14
diff changeset
967 if (diagnostic->kind == DK_ERROR && orig_diag_kind == DK_WARNING)
kono
parents: 14
diff changeset
968 ++diagnostic_kind_count (context, DK_WERROR);
kono
parents: 14
diff changeset
969 else
kono
parents: 14
diff changeset
970 ++diagnostic_kind_count (context, diagnostic->kind);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
971
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
972 diagnostic->message.x_data = &diagnostic->x_data;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
973 diagnostic->x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
974 pp_format (context->printer, &diagnostic->message);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
975 (*diagnostic_starter (context)) (context, diagnostic);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
976 pp_output_formatted_text (context->printer);
16
kono
parents: 14
diff changeset
977 if (context->show_option_requested)
kono
parents: 14
diff changeset
978 print_option_information (context, diagnostic, orig_diag_kind);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
979 (*diagnostic_finalizer (context)) (context, diagnostic);
16
kono
parents: 14
diff changeset
980 if (context->parseable_fixits_p)
kono
parents: 14
diff changeset
981 {
kono
parents: 14
diff changeset
982 print_parseable_fixits (context->printer, diagnostic->richloc);
kono
parents: 14
diff changeset
983 pp_flush (context->printer);
kono
parents: 14
diff changeset
984 }
kono
parents: 14
diff changeset
985 diagnostic_action_after_output (context, diagnostic->kind);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
986 diagnostic->x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
987
16
kono
parents: 14
diff changeset
988 if (context->edit_context_ptr)
kono
parents: 14
diff changeset
989 if (diagnostic->richloc->fixits_can_be_auto_applied_p ())
kono
parents: 14
diff changeset
990 context->edit_context_ptr->add_fixits (diagnostic->richloc);
kono
parents: 14
diff changeset
991
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
992 context->lock--;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
993
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
994 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 /* Given a partial pathname as input, return another pathname that
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998 shares no directory elements with the pathname of __FILE__. This
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 is used by fancy_abort() to print `Internal compiler error in expr.c'
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 const char *
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 trim_filename (const char *name)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1005 static const char this_file[] = __FILE__;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1006 const char *p = name, *q = this_file;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1007
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1008 /* First skip any "../" in each filename. This allows us to give a proper
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1009 reference to a file in a subdirectory. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1010 while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1011 p += 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1014 q += 3;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1015
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1016 /* Now skip any parts the two filenames have in common. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1017 while (*p == *q && *p != 0 && *q != 0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1018 p++, q++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1019
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1020 /* Now go backwards until the previous directory separator. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1021 while (p > name && !IS_DIR_SEPARATOR (p[-1]))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1022 p--;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 return p;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 /* Standard error reporting routines in increasing order of severity.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 All of these take arguments like printf. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1030 /* Text to be emitted verbatim to the error message stream; this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1031 produces no prefix and disables line-wrapping. Use rarely. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1032 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1033 verbatim (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1034 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 text_info text;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 va_start (ap, gmsgid);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 text.err_no = errno;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 text.args_ptr = &ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 text.format_spec = _(gmsgid);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1042 text.x_data = NULL;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 pp_format_verbatim (global_dc->printer, &text);
16
kono
parents: 14
diff changeset
1044 pp_newline_and_flush (global_dc->printer);
kono
parents: 14
diff changeset
1045 va_end (ap);
kono
parents: 14
diff changeset
1046 }
kono
parents: 14
diff changeset
1047
kono
parents: 14
diff changeset
1048 /* Add a note with text GMSGID and with LOCATION to the diagnostic CONTEXT. */
kono
parents: 14
diff changeset
1049 void
kono
parents: 14
diff changeset
1050 diagnostic_append_note (diagnostic_context *context,
kono
parents: 14
diff changeset
1051 location_t location,
kono
parents: 14
diff changeset
1052 const char * gmsgid, ...)
kono
parents: 14
diff changeset
1053 {
kono
parents: 14
diff changeset
1054 diagnostic_info diagnostic;
kono
parents: 14
diff changeset
1055 va_list ap;
kono
parents: 14
diff changeset
1056 const char *saved_prefix;
kono
parents: 14
diff changeset
1057 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1058
kono
parents: 14
diff changeset
1059 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1060 diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc, DK_NOTE);
kono
parents: 14
diff changeset
1061 if (context->inhibit_notes_p)
kono
parents: 14
diff changeset
1062 {
kono
parents: 14
diff changeset
1063 va_end (ap);
kono
parents: 14
diff changeset
1064 return;
kono
parents: 14
diff changeset
1065 }
kono
parents: 14
diff changeset
1066 saved_prefix = pp_get_prefix (context->printer);
kono
parents: 14
diff changeset
1067 pp_set_prefix (context->printer,
kono
parents: 14
diff changeset
1068 diagnostic_build_prefix (context, &diagnostic));
kono
parents: 14
diff changeset
1069 pp_format (context->printer, &diagnostic.message);
kono
parents: 14
diff changeset
1070 pp_output_formatted_text (context->printer);
kono
parents: 14
diff changeset
1071 pp_destroy_prefix (context->printer);
kono
parents: 14
diff changeset
1072 pp_set_prefix (context->printer, saved_prefix);
kono
parents: 14
diff changeset
1073 diagnostic_show_locus (context, &richloc, DK_NOTE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1074 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1075 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1076
16
kono
parents: 14
diff changeset
1077 /* Implement emit_diagnostic, inform, inform_at_rich_loc, warning, warning_at,
kono
parents: 14
diff changeset
1078 warning_at_rich_loc, pedwarn, permerror, permerror_at_rich_loc, error,
kono
parents: 14
diff changeset
1079 error_at, error_at_rich_loc, sorry, fatal_error, internal_error, and
kono
parents: 14
diff changeset
1080 internal_error_no_backtrace, as documented and defined below. */
kono
parents: 14
diff changeset
1081 static bool
kono
parents: 14
diff changeset
1082 diagnostic_impl (rich_location *richloc, int opt,
kono
parents: 14
diff changeset
1083 const char *gmsgid,
kono
parents: 14
diff changeset
1084 va_list *ap, diagnostic_t kind)
kono
parents: 14
diff changeset
1085 {
kono
parents: 14
diff changeset
1086 diagnostic_info diagnostic;
kono
parents: 14
diff changeset
1087 if (kind == DK_PERMERROR)
kono
parents: 14
diff changeset
1088 {
kono
parents: 14
diff changeset
1089 diagnostic_set_info (&diagnostic, gmsgid, ap, richloc,
kono
parents: 14
diff changeset
1090 permissive_error_kind (global_dc));
kono
parents: 14
diff changeset
1091 diagnostic.option_index = permissive_error_option (global_dc);
kono
parents: 14
diff changeset
1092 }
kono
parents: 14
diff changeset
1093 else
kono
parents: 14
diff changeset
1094 {
kono
parents: 14
diff changeset
1095 diagnostic_set_info (&diagnostic, gmsgid, ap, richloc, kind);
kono
parents: 14
diff changeset
1096 if (kind == DK_WARNING || kind == DK_PEDWARN)
kono
parents: 14
diff changeset
1097 diagnostic.option_index = opt;
kono
parents: 14
diff changeset
1098 }
kono
parents: 14
diff changeset
1099 return diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents: 14
diff changeset
1100 }
kono
parents: 14
diff changeset
1101
kono
parents: 14
diff changeset
1102 /* Same as diagonostic_n_impl taking rich_location instead of location_t. */
kono
parents: 14
diff changeset
1103 static bool
kono
parents: 14
diff changeset
1104 diagnostic_n_impl_richloc (rich_location *richloc, int opt, int n,
kono
parents: 14
diff changeset
1105 const char *singular_gmsgid,
kono
parents: 14
diff changeset
1106 const char *plural_gmsgid,
kono
parents: 14
diff changeset
1107 va_list *ap, diagnostic_t kind)
kono
parents: 14
diff changeset
1108 {
kono
parents: 14
diff changeset
1109 diagnostic_info diagnostic;
kono
parents: 14
diff changeset
1110 diagnostic_set_info_translated (&diagnostic,
kono
parents: 14
diff changeset
1111 ngettext (singular_gmsgid, plural_gmsgid, n),
kono
parents: 14
diff changeset
1112 ap, richloc, kind);
kono
parents: 14
diff changeset
1113 if (kind == DK_WARNING)
kono
parents: 14
diff changeset
1114 diagnostic.option_index = opt;
kono
parents: 14
diff changeset
1115 return diagnostic_report_diagnostic (global_dc, &diagnostic);
kono
parents: 14
diff changeset
1116 }
kono
parents: 14
diff changeset
1117
kono
parents: 14
diff changeset
1118 /* Implement inform_n, warning_n, and error_n, as documented and
kono
parents: 14
diff changeset
1119 defined below. */
kono
parents: 14
diff changeset
1120 static bool
kono
parents: 14
diff changeset
1121 diagnostic_n_impl (location_t location, int opt, int n,
kono
parents: 14
diff changeset
1122 const char *singular_gmsgid,
kono
parents: 14
diff changeset
1123 const char *plural_gmsgid,
kono
parents: 14
diff changeset
1124 va_list *ap, diagnostic_t kind)
kono
parents: 14
diff changeset
1125 {
kono
parents: 14
diff changeset
1126 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1127 return diagnostic_n_impl_richloc (&richloc, opt, n,
kono
parents: 14
diff changeset
1128 singular_gmsgid, plural_gmsgid, ap, kind);
kono
parents: 14
diff changeset
1129 }
kono
parents: 14
diff changeset
1130
kono
parents: 14
diff changeset
1131 /* Wrapper around diagnostic_impl taking a variable argument list. */
kono
parents: 14
diff changeset
1132
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 bool
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1134 emit_diagnostic (diagnostic_t kind, location_t location, int opt,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1139 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1140 bool ret = diagnostic_impl (&richloc, opt, gmsgid, &ap, kind);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 va_end (ap);
16
kono
parents: 14
diff changeset
1142 return ret;
kono
parents: 14
diff changeset
1143 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144
16
kono
parents: 14
diff changeset
1145 /* Wrapper around diagnostic_impl taking a va_list parameter. */
kono
parents: 14
diff changeset
1146
kono
parents: 14
diff changeset
1147 bool
kono
parents: 14
diff changeset
1148 emit_diagnostic_valist (diagnostic_t kind, location_t location, int opt,
kono
parents: 14
diff changeset
1149 const char *gmsgid, va_list *ap)
kono
parents: 14
diff changeset
1150 {
kono
parents: 14
diff changeset
1151 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1152 return diagnostic_impl (&richloc, opt, gmsgid, ap, kind);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 /* An informative note at LOCATION. Use this for additional details on an error
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 message. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 inform (location_t location, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 va_list ap;
16
kono
parents: 14
diff changeset
1161 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1162 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1163 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_NOTE);
kono
parents: 14
diff changeset
1164 va_end (ap);
kono
parents: 14
diff changeset
1165 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166
16
kono
parents: 14
diff changeset
1167 /* Same as "inform", but at RICHLOC. */
kono
parents: 14
diff changeset
1168 void
kono
parents: 14
diff changeset
1169 inform_at_rich_loc (rich_location *richloc, const char *gmsgid, ...)
kono
parents: 14
diff changeset
1170 {
kono
parents: 14
diff changeset
1171 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1173 diagnostic_impl (richloc, -1, gmsgid, &ap, DK_NOTE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1174 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1175 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1176
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1177 /* An informative note at LOCATION. Use this for additional details on an
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1178 error message. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1179 void
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1180 inform_n (location_t location, int n, const char *singular_gmsgid,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1181 const char *plural_gmsgid, ...)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1182 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1183 va_list ap;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1184 va_start (ap, plural_gmsgid);
16
kono
parents: 14
diff changeset
1185 diagnostic_n_impl (location, -1, n, singular_gmsgid, plural_gmsgid,
kono
parents: 14
diff changeset
1186 &ap, DK_NOTE);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1187 va_end (ap);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1188 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1189
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1190 /* A warning at INPUT_LOCATION. Use this for code which is correct according
9
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1191 to the relevant language specification but is likely to be buggy anyway.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1192 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1193 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1194 warning (int opt, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1195 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1196 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1197 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1198 rich_location richloc (line_table, input_location);
kono
parents: 14
diff changeset
1199 bool ret = diagnostic_impl (&richloc, opt, gmsgid, &ap, DK_WARNING);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1200 va_end (ap);
16
kono
parents: 14
diff changeset
1201 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1202 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1203
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1204 /* A warning at LOCATION. Use this for code which is correct according to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1205 relevant language specification but is likely to be buggy anyway.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1206 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1207
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1208 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1209 warning_at (location_t location, int opt, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1210 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1211 va_list ap;
16
kono
parents: 14
diff changeset
1212 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1213 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1214 bool ret = diagnostic_impl (&richloc, opt, gmsgid, &ap, DK_WARNING);
kono
parents: 14
diff changeset
1215 va_end (ap);
kono
parents: 14
diff changeset
1216 return ret;
kono
parents: 14
diff changeset
1217 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1218
16
kono
parents: 14
diff changeset
1219 /* Same as warning at, but using RICHLOC. */
kono
parents: 14
diff changeset
1220
kono
parents: 14
diff changeset
1221 bool
kono
parents: 14
diff changeset
1222 warning_at_rich_loc (rich_location *richloc, int opt, const char *gmsgid, ...)
kono
parents: 14
diff changeset
1223 {
kono
parents: 14
diff changeset
1224 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1225 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1226 bool ret = diagnostic_impl (richloc, opt, gmsgid, &ap, DK_WARNING);
kono
parents: 14
diff changeset
1227 va_end (ap);
kono
parents: 14
diff changeset
1228 return ret;
kono
parents: 14
diff changeset
1229 }
kono
parents: 14
diff changeset
1230
kono
parents: 14
diff changeset
1231 /* Same as warning_at_rich_loc but for plural variant. */
kono
parents: 14
diff changeset
1232
kono
parents: 14
diff changeset
1233 bool
kono
parents: 14
diff changeset
1234 warning_at_rich_loc_n (rich_location *richloc, int opt, int n,
kono
parents: 14
diff changeset
1235 const char *singular_gmsgid, const char *plural_gmsgid, ...)
kono
parents: 14
diff changeset
1236 {
kono
parents: 14
diff changeset
1237 va_list ap;
kono
parents: 14
diff changeset
1238 va_start (ap, plural_gmsgid);
kono
parents: 14
diff changeset
1239 bool ret = diagnostic_n_impl_richloc (richloc, opt, n,
kono
parents: 14
diff changeset
1240 singular_gmsgid, plural_gmsgid,
kono
parents: 14
diff changeset
1241 &ap, DK_WARNING);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1242 va_end (ap);
16
kono
parents: 14
diff changeset
1243 return ret;
kono
parents: 14
diff changeset
1244 }
kono
parents: 14
diff changeset
1245
kono
parents: 14
diff changeset
1246 /* A warning at LOCATION. Use this for code which is correct according to the
kono
parents: 14
diff changeset
1247 relevant language specification but is likely to be buggy anyway.
kono
parents: 14
diff changeset
1248 Returns true if the warning was printed, false if it was inhibited. */
kono
parents: 14
diff changeset
1249
kono
parents: 14
diff changeset
1250 bool
kono
parents: 14
diff changeset
1251 warning_n (location_t location, int opt, int n, const char *singular_gmsgid,
kono
parents: 14
diff changeset
1252 const char *plural_gmsgid, ...)
kono
parents: 14
diff changeset
1253 {
kono
parents: 14
diff changeset
1254 va_list ap;
kono
parents: 14
diff changeset
1255 va_start (ap, plural_gmsgid);
kono
parents: 14
diff changeset
1256 bool ret = diagnostic_n_impl (location, opt, n,
kono
parents: 14
diff changeset
1257 singular_gmsgid, plural_gmsgid,
kono
parents: 14
diff changeset
1258 &ap, DK_WARNING);
kono
parents: 14
diff changeset
1259 va_end (ap);
kono
parents: 14
diff changeset
1260 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1261 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1262
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1263 /* A "pedantic" warning at LOCATION: issues a warning unless
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1264 -pedantic-errors was given on the command line, in which case it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1265 issues an error. Use this for diagnostics required by the relevant
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1266 language standard, if you have chosen not to make them errors.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1267
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1268 Note that these diagnostics are issued independent of the setting
16
kono
parents: 14
diff changeset
1269 of the -Wpedantic command-line switch. To get a warning enabled
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1270 only with that switch, use either "if (pedantic) pedwarn
16
kono
parents: 14
diff changeset
1271 (OPT_Wpedantic,...)" or just "pedwarn (OPT_Wpedantic,..)". To get a
kono
parents: 14
diff changeset
1272 pedwarn independently of the -Wpedantic switch use "pedwarn (0,...)".
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1273
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1274 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1275
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1276 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1277 pedwarn (location_t location, int opt, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1278 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1279 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1280 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1281 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1282 bool ret = diagnostic_impl (&richloc, opt, gmsgid, &ap, DK_PEDWARN);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1283 va_end (ap);
16
kono
parents: 14
diff changeset
1284 return ret;
kono
parents: 14
diff changeset
1285 }
kono
parents: 14
diff changeset
1286
kono
parents: 14
diff changeset
1287 /* Same as pedwarn, but using RICHLOC. */
kono
parents: 14
diff changeset
1288
kono
parents: 14
diff changeset
1289 bool
kono
parents: 14
diff changeset
1290 pedwarn_at_rich_loc (rich_location *richloc, int opt, const char *gmsgid, ...)
kono
parents: 14
diff changeset
1291 {
kono
parents: 14
diff changeset
1292 va_list ap;
kono
parents: 14
diff changeset
1293 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1294 bool ret = diagnostic_impl (richloc, opt, gmsgid, &ap, DK_PEDWARN);
kono
parents: 14
diff changeset
1295 va_end (ap);
kono
parents: 14
diff changeset
1296 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1297 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1298
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1299 /* A "permissive" error at LOCATION: issues an error unless
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1300 -fpermissive was given on the command line, in which case it issues
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1301 a warning. Use this for things that really should be errors but we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1302 want to support legacy code.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1303
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1304 Returns true if the warning was printed, false if it was inhibited. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1305
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1306 bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1307 permerror (location_t location, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1308 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1309 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1310 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1311 rich_location richloc (line_table, location);
kono
parents: 14
diff changeset
1312 bool ret = diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_PERMERROR);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1313 va_end (ap);
16
kono
parents: 14
diff changeset
1314 return ret;
kono
parents: 14
diff changeset
1315 }
kono
parents: 14
diff changeset
1316
kono
parents: 14
diff changeset
1317 /* Same as "permerror", but at RICHLOC. */
kono
parents: 14
diff changeset
1318
kono
parents: 14
diff changeset
1319 bool
kono
parents: 14
diff changeset
1320 permerror_at_rich_loc (rich_location *richloc, const char *gmsgid, ...)
kono
parents: 14
diff changeset
1321 {
kono
parents: 14
diff changeset
1322 va_list ap;
kono
parents: 14
diff changeset
1323 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1324 bool ret = diagnostic_impl (richloc, -1, gmsgid, &ap, DK_PERMERROR);
kono
parents: 14
diff changeset
1325 va_end (ap);
kono
parents: 14
diff changeset
1326 return ret;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1327 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1328
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1329 /* A hard error: the code is definitely ill-formed, and an object file
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1330 will not be produced. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1331 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1332 error (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1333 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1334 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1335 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1336 rich_location richloc (line_table, input_location);
kono
parents: 14
diff changeset
1337 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_ERROR);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1338 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1339 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1340
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1341 /* A hard error: the code is definitely ill-formed, and an object file
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1342 will not be produced. */
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1343 void
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1344 error_n (location_t location, int n, const char *singular_gmsgid,
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1345 const char *plural_gmsgid, ...)
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1346 {
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1347 va_list ap;
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1348 va_start (ap, plural_gmsgid);
16
kono
parents: 14
diff changeset
1349 diagnostic_n_impl (location, -1, n, singular_gmsgid, plural_gmsgid,
kono
parents: 14
diff changeset
1350 &ap, DK_ERROR);
11
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1351 va_end (ap);
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1352 }
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 9
diff changeset
1353
16
kono
parents: 14
diff changeset
1354 /* Same as above, but use location LOC instead of input_location. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1355 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1356 error_at (location_t loc, const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1357 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1358 va_list ap;
16
kono
parents: 14
diff changeset
1359 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1360 rich_location richloc (line_table, loc);
kono
parents: 14
diff changeset
1361 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_ERROR);
kono
parents: 14
diff changeset
1362 va_end (ap);
kono
parents: 14
diff changeset
1363 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1364
16
kono
parents: 14
diff changeset
1365 /* Same as above, but use RICH_LOC. */
kono
parents: 14
diff changeset
1366
kono
parents: 14
diff changeset
1367 void
kono
parents: 14
diff changeset
1368 error_at_rich_loc (rich_location *richloc, const char *gmsgid, ...)
kono
parents: 14
diff changeset
1369 {
kono
parents: 14
diff changeset
1370 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1371 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1372 diagnostic_impl (richloc, -1, gmsgid, &ap, DK_ERROR);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1373 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1374 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1375
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1376 /* "Sorry, not implemented." Use for a language feature which is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1377 required by the relevant specification but not implemented by GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1378 An object file will not be produced. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1379 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1380 sorry (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1381 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1382 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1383 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1384 rich_location richloc (line_table, input_location);
kono
parents: 14
diff changeset
1385 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_SORRY);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1386 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1387 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1388
14
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1389 /* Return true if an error or a "sorry" has been seen. Various
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1390 processing is disabled after errors. */
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1391 bool
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1392 seen_error (void)
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1393 {
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1394 return errorcount || sorrycount;
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1395 }
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 11
diff changeset
1396
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1397 /* An error which is severe enough that we make no attempt to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1398 continue. Do not use this for internal consistency checks; that's
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1399 internal_error. Use of this function should be rare. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1400 void
16
kono
parents: 14
diff changeset
1401 fatal_error (location_t loc, const char *gmsgid, ...)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1402 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1403 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1404 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1405 rich_location richloc (line_table, loc);
kono
parents: 14
diff changeset
1406 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_FATAL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1407 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1408
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1409 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1410 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1411
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1412 /* An internal consistency check has failed. We make no attempt to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1413 continue. Note that unless there is debugging value to be had from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1414 a more specific message, or some other good reason, you should use
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1415 abort () instead of calling this function directly. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1416 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1417 internal_error (const char *gmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1418 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1419 va_list ap;
16
kono
parents: 14
diff changeset
1420 va_start (ap, gmsgid);
kono
parents: 14
diff changeset
1421 rich_location richloc (line_table, input_location);
kono
parents: 14
diff changeset
1422 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_ICE);
kono
parents: 14
diff changeset
1423 va_end (ap);
kono
parents: 14
diff changeset
1424
kono
parents: 14
diff changeset
1425 gcc_unreachable ();
kono
parents: 14
diff changeset
1426 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1427
16
kono
parents: 14
diff changeset
1428 /* Like internal_error, but no backtrace will be printed. Used when
kono
parents: 14
diff changeset
1429 the internal error does not happen at the current location, but happened
kono
parents: 14
diff changeset
1430 somewhere else. */
kono
parents: 14
diff changeset
1431 void
kono
parents: 14
diff changeset
1432 internal_error_no_backtrace (const char *gmsgid, ...)
kono
parents: 14
diff changeset
1433 {
kono
parents: 14
diff changeset
1434 va_list ap;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1435 va_start (ap, gmsgid);
16
kono
parents: 14
diff changeset
1436 rich_location richloc (line_table, input_location);
kono
parents: 14
diff changeset
1437 diagnostic_impl (&richloc, -1, gmsgid, &ap, DK_ICE_NOBT);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1438 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1439
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1440 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1441 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1442
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1443 /* Special case error functions. Most are implemented in terms of the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1444 above, or should be. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1445
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1446 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1447 runs its second argument through gettext. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1448 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1449 fnotice (FILE *file, const char *cmsgid, ...)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1450 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1451 va_list ap;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1452
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1453 va_start (ap, cmsgid);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1454 vfprintf (file, _(cmsgid), ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1455 va_end (ap);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1456 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1457
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1458 /* Inform the user that an error occurred while trying to report some
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1459 other error. This indicates catastrophic internal inconsistencies,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1460 so give up now. But do try to flush out the previous error.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1461 This mustn't use internal_error, that will cause infinite recursion. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1462
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1463 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1464 error_recursion (diagnostic_context *context)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1465 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1466 if (context->lock < 3)
16
kono
parents: 14
diff changeset
1467 pp_newline_and_flush (context->printer);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1468
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1469 fnotice (stderr,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1470 "Internal compiler error: Error reporting routines re-entered.\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1471
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1472 /* Call diagnostic_action_after_output to get the "please submit a bug
16
kono
parents: 14
diff changeset
1473 report" message. */
kono
parents: 14
diff changeset
1474 diagnostic_action_after_output (context, DK_ICE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1475
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1476 /* Do not use gcc_unreachable here; that goes through internal_error
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1477 and therefore would cause infinite recursion. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1478 real_abort ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1479 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1480
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1481 /* Report an internal compiler error in a friendly manner. This is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1482 the function that gets called upon use of abort() in the source
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1483 code generally, thanks to a special macro. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1484
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1485 void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1486 fancy_abort (const char *file, int line, const char *function)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1487 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1488 internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1489 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1490
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1491 /* Really call the system 'abort'. This has to go right at the end of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1492 this file, so that there are no functions after it that call abort
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1493 and get the system abort instead of our macro. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1494 #undef abort
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1495 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1496 real_abort (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1497 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1498 abort ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1499 }
16
kono
parents: 14
diff changeset
1500
kono
parents: 14
diff changeset
1501 #if CHECKING_P
kono
parents: 14
diff changeset
1502
kono
parents: 14
diff changeset
1503 namespace selftest {
kono
parents: 14
diff changeset
1504
kono
parents: 14
diff changeset
1505 /* Helper function for test_print_escaped_string. */
kono
parents: 14
diff changeset
1506
kono
parents: 14
diff changeset
1507 static void
kono
parents: 14
diff changeset
1508 assert_print_escaped_string (const location &loc, const char *expected_output,
kono
parents: 14
diff changeset
1509 const char *input)
kono
parents: 14
diff changeset
1510 {
kono
parents: 14
diff changeset
1511 pretty_printer pp;
kono
parents: 14
diff changeset
1512 print_escaped_string (&pp, input);
kono
parents: 14
diff changeset
1513 ASSERT_STREQ_AT (loc, expected_output, pp_formatted_text (&pp));
kono
parents: 14
diff changeset
1514 }
kono
parents: 14
diff changeset
1515
kono
parents: 14
diff changeset
1516 #define ASSERT_PRINT_ESCAPED_STRING_STREQ(EXPECTED_OUTPUT, INPUT) \
kono
parents: 14
diff changeset
1517 assert_print_escaped_string (SELFTEST_LOCATION, EXPECTED_OUTPUT, INPUT)
kono
parents: 14
diff changeset
1518
kono
parents: 14
diff changeset
1519 /* Tests of print_escaped_string. */
kono
parents: 14
diff changeset
1520
kono
parents: 14
diff changeset
1521 static void
kono
parents: 14
diff changeset
1522 test_print_escaped_string ()
kono
parents: 14
diff changeset
1523 {
kono
parents: 14
diff changeset
1524 /* Empty string. */
kono
parents: 14
diff changeset
1525 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"\"", "");
kono
parents: 14
diff changeset
1526
kono
parents: 14
diff changeset
1527 /* Non-empty string. */
kono
parents: 14
diff changeset
1528 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"hello world\"", "hello world");
kono
parents: 14
diff changeset
1529
kono
parents: 14
diff changeset
1530 /* Various things that need to be escaped: */
kono
parents: 14
diff changeset
1531 /* Backslash. */
kono
parents: 14
diff changeset
1532 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\\\after\"",
kono
parents: 14
diff changeset
1533 "before\\after");
kono
parents: 14
diff changeset
1534 /* Tab. */
kono
parents: 14
diff changeset
1535 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\tafter\"",
kono
parents: 14
diff changeset
1536 "before\tafter");
kono
parents: 14
diff changeset
1537 /* Newline. */
kono
parents: 14
diff changeset
1538 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\nafter\"",
kono
parents: 14
diff changeset
1539 "before\nafter");
kono
parents: 14
diff changeset
1540 /* Double quote. */
kono
parents: 14
diff changeset
1541 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\\"after\"",
kono
parents: 14
diff changeset
1542 "before\"after");
kono
parents: 14
diff changeset
1543
kono
parents: 14
diff changeset
1544 /* Non-printable characters: BEL: '\a': 0x07 */
kono
parents: 14
diff changeset
1545 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\007after\"",
kono
parents: 14
diff changeset
1546 "before\aafter");
kono
parents: 14
diff changeset
1547 /* Non-printable characters: vertical tab: '\v': 0x0b */
kono
parents: 14
diff changeset
1548 ASSERT_PRINT_ESCAPED_STRING_STREQ ("\"before\\013after\"",
kono
parents: 14
diff changeset
1549 "before\vafter");
kono
parents: 14
diff changeset
1550 }
kono
parents: 14
diff changeset
1551
kono
parents: 14
diff changeset
1552 /* Tests of print_parseable_fixits. */
kono
parents: 14
diff changeset
1553
kono
parents: 14
diff changeset
1554 /* Verify that print_parseable_fixits emits the empty string if there
kono
parents: 14
diff changeset
1555 are no fixits. */
kono
parents: 14
diff changeset
1556
kono
parents: 14
diff changeset
1557 static void
kono
parents: 14
diff changeset
1558 test_print_parseable_fixits_none ()
kono
parents: 14
diff changeset
1559 {
kono
parents: 14
diff changeset
1560 pretty_printer pp;
kono
parents: 14
diff changeset
1561 rich_location richloc (line_table, UNKNOWN_LOCATION);
kono
parents: 14
diff changeset
1562
kono
parents: 14
diff changeset
1563 print_parseable_fixits (&pp, &richloc);
kono
parents: 14
diff changeset
1564 ASSERT_STREQ ("", pp_formatted_text (&pp));
kono
parents: 14
diff change