Line 0
Link Here
|
|
|
1 |
/* Language-independent diagnostic subroutines for the GNU Compiler Collection |
2 |
Copyright (C) 2009 Free Software Foundation, Inc. |
3 |
Contributed by Manuel Lopez-Ibanez <manu@gcc.gnu.org> |
4 |
|
5 |
This file is part of GCC. |
6 |
|
7 |
GCC is free software; you can redistribute it and/or modify it under |
8 |
the terms of the GNU General Public License as published by the Free |
9 |
Software Foundation; either version 3, or (at your option) any later |
10 |
version. |
11 |
|
12 |
GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
13 |
WARRANTY; without even the implied warranty of MERCHANTABILITY or |
14 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
15 |
for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License |
18 |
along with GCC; see the file COPYING3. If not see |
19 |
<http://www.gnu.org/licenses/>. */ |
20 |
|
21 |
#include "config.h" |
22 |
#undef FLOAT /* This is for hpux. They should change hpux. */ |
23 |
#undef FFS /* Some systems define this in param.h. */ |
24 |
#include "system.h" |
25 |
#include "coretypes.h" |
26 |
#include "tm.h" |
27 |
#include "tree.h" |
28 |
#include "version.h" |
29 |
#include "tm_p.h" |
30 |
#include "flags.h" |
31 |
#include "input.h" |
32 |
#include "toplev.h" |
33 |
#include "intl.h" |
34 |
#include "diagnostic-xml.h" |
35 |
#include "langhooks.h" |
36 |
#include "langhooks-def.h" |
37 |
#include "opts.h" |
38 |
#include "plugin.h" |
39 |
|
40 |
|
41 |
static void xml_diagnostic_starter (diagnostic_context *, |
42 |
diagnostic_info *); |
43 |
static void xml_diagnostic_finalizer (diagnostic_context *, |
44 |
diagnostic_info *); |
45 |
|
46 |
static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; |
47 |
|
48 |
/* Return a malloc'd string containing MSG formatted a la printf. The |
49 |
caller is responsible for freeing the memory. */ |
50 |
static char * |
51 |
build_message_string (const char *msg, ...) |
52 |
{ |
53 |
char *str; |
54 |
va_list ap; |
55 |
|
56 |
va_start (ap, msg); |
57 |
vasprintf (&str, msg, ap); |
58 |
va_end (ap); |
59 |
|
60 |
return str; |
61 |
} |
62 |
|
63 |
/* Return a malloc'd string describing a location. The caller is |
64 |
responsible for freeing the memory. */ |
65 |
static char * |
66 |
xml_diagnostic_build_prefix (diagnostic_info *diagnostic) |
67 |
{ |
68 |
static const char *const diagnostic_kind_text[] = { |
69 |
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T), |
70 |
#include "diagnostic.def" |
71 |
#undef DEFINE_DIAGNOSTIC_KIND |
72 |
"must-not-happen" |
73 |
}; |
74 |
const char *class_text = diagnostic_kind_text[diagnostic->kind]; |
75 |
expanded_location s = expand_location (diagnostic->location); |
76 |
if (diagnostic->override_column) |
77 |
s.column = diagnostic->override_column; |
78 |
gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND); |
79 |
|
80 |
return |
81 |
(s.file == NULL |
82 |
? build_message_string ("<diagnostic class=\"%s\" location=\"%s\">\n", |
83 |
class_text, progname) |
84 |
: flag_show_column |
85 |
? build_message_string ("<diagnostic class=\"%s\" location=\"%s:%d:%d\">\n", |
86 |
class_text, s.file, s.line, s.column) |
87 |
: build_message_string ("<diagnostic class=\"%s\" location=\"%s:%d\">\n", |
88 |
class_text, s.file, s.line)); |
89 |
} |
90 |
|
91 |
static void |
92 |
xml_diagnostic_report_current_module (diagnostic_context *context) |
93 |
{ |
94 |
const struct line_map *map; |
95 |
|
96 |
if (pp_needs_newline (context->printer)) |
97 |
{ |
98 |
pp_newline (context->printer); |
99 |
pp_needs_newline (context->printer) = false; |
100 |
} |
101 |
|
102 |
if (input_location <= BUILTINS_LOCATION) |
103 |
return; |
104 |
|
105 |
map = linemap_lookup (line_table, input_location); |
106 |
if (map && diagnostic_last_module_changed (context, map)) |
107 |
{ |
108 |
diagnostic_set_last_module (context, map); |
109 |
if (! MAIN_FILE_P (map)) |
110 |
{ |
111 |
map = INCLUDED_FROM (line_table, map); |
112 |
if (flag_show_column) |
113 |
pp_verbatim (context->printer, |
114 |
"Included from %s:%d:%d", |
115 |
map->to_file, |
116 |
LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map)); |
117 |
else |
118 |
pp_verbatim (context->printer, |
119 |
"In file included from %s:%d", |
120 |
map->to_file, LAST_SOURCE_LINE (map)); |
121 |
while (! MAIN_FILE_P (map)) |
122 |
{ |
123 |
map = INCLUDED_FROM (line_table, map); |
124 |
pp_verbatim (context->printer, |
125 |
",\n from %s:%d", |
126 |
map->to_file, LAST_SOURCE_LINE (map)); |
127 |
} |
128 |
pp_verbatim (context->printer, ":"); |
129 |
pp_newline (context->printer); |
130 |
} |
131 |
} |
132 |
} |
133 |
|
134 |
static void |
135 |
xml_diagnostic_starter (diagnostic_context *context, |
136 |
diagnostic_info *diagnostic) |
137 |
{ |
138 |
context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE; |
139 |
xml_diagnostic_report_current_module (context); |
140 |
lang_hooks.print_error_function (context, input_filename, diagnostic); |
141 |
pp_set_prefix (context->printer, xml_diagnostic_build_prefix (diagnostic)); |
142 |
} |
143 |
|
144 |
/* Initialize the diagnostic message outputting machinery. */ |
145 |
void |
146 |
xml_diagnostic_initialize (diagnostic_context *context) |
147 |
{ |
148 |
/* Default diagnostic_initialize should have been run again. */ |
149 |
gcc_assert (context); |
150 |
/* Override with xml variants. */ |
151 |
diagnostic_starter (context) = xml_diagnostic_starter; |
152 |
diagnostic_finalizer (context) = xml_diagnostic_finalizer; |
153 |
} |
154 |
|
155 |
|
156 |
static void |
157 |
xml_diagnostic_finalizer (diagnostic_context *context, |
158 |
diagnostic_info *diagnostic ATTRIBUTE_UNUSED) |
159 |
{ |
160 |
pp_newline (context->printer); |
161 |
pp_verbatim (context->printer, "</diagnostic>"); |
162 |
pp_newline (context->printer); |
163 |
pp_destroy_prefix (context->printer); |
164 |
} |