Mercurial > hg > CbC > CbC_gcc
comparison libcpp/errors.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | a06113de4d67 |
children | b7f97abdc517 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
26 #include "config.h" | 26 #include "config.h" |
27 #include "system.h" | 27 #include "system.h" |
28 #include "cpplib.h" | 28 #include "cpplib.h" |
29 #include "internal.h" | 29 #include "internal.h" |
30 | 30 |
31 static void print_location (cpp_reader *, source_location, unsigned int); | |
32 | |
33 /* Print the logical file location (LINE, COL) in preparation for a | |
34 diagnostic. Outputs the #include chain if it has changed. A line | |
35 of zero suppresses the include stack, and outputs the program name | |
36 instead. */ | |
37 static void | |
38 print_location (cpp_reader *pfile, source_location line, unsigned int col) | |
39 { | |
40 if (line == 0) | |
41 fprintf (stderr, "%s: ", progname); | |
42 else | |
43 { | |
44 const struct line_map *map; | |
45 linenum_type lin; | |
46 | |
47 map = linemap_lookup (pfile->line_table, line); | |
48 linemap_print_containing_files (pfile->line_table, map); | |
49 | |
50 lin = SOURCE_LINE (map, line); | |
51 if (col == 0) | |
52 { | |
53 col = SOURCE_COLUMN (map, line); | |
54 if (col == 0) | |
55 col = 1; | |
56 } | |
57 | |
58 if (lin == 0) | |
59 fprintf (stderr, "%s:", map->to_file); | |
60 else if (CPP_OPTION (pfile, show_column) == 0) | |
61 fprintf (stderr, "%s:%u:", map->to_file, lin); | |
62 else | |
63 fprintf (stderr, "%s:%u:%u:", map->to_file, lin, col); | |
64 | |
65 fputc (' ', stderr); | |
66 } | |
67 } | |
68 | |
69 /* Set up for a diagnostic: print the file and line, bump the error | |
70 counter, etc. SRC_LOC is the logical line number; zero means to print | |
71 at the location of the previously lexed token, which tends to be | |
72 the correct place by default. The column number can be specified either | |
73 using COLUMN or (if COLUMN==0) extracting SOURCE_COLUMN from SRC_LOC. | |
74 (This may seem redundant, but is useful when pre-scanning (cleaning) a line, | |
75 when we haven't yet verified whether the current line_map has a | |
76 big enough max_column_hint.) | |
77 | |
78 Returns 0 if the error has been suppressed. */ | |
79 static int | |
80 _cpp_begin_message (cpp_reader *pfile, int code, | |
81 source_location src_loc, unsigned int column) | |
82 { | |
83 int level = CPP_DL_EXTRACT (code); | |
84 | |
85 switch (level) | |
86 { | |
87 case CPP_DL_WARNING: | |
88 case CPP_DL_PEDWARN: | |
89 if (cpp_in_system_header (pfile) | |
90 && ! CPP_OPTION (pfile, warn_system_headers)) | |
91 return 0; | |
92 /* Fall through. */ | |
93 | |
94 case CPP_DL_WARNING_SYSHDR: | |
95 if (CPP_OPTION (pfile, warnings_are_errors) | |
96 || (level == CPP_DL_PEDWARN && CPP_OPTION (pfile, pedantic_errors))) | |
97 { | |
98 if (CPP_OPTION (pfile, inhibit_errors)) | |
99 return 0; | |
100 level = CPP_DL_ERROR; | |
101 pfile->errors++; | |
102 } | |
103 else if (CPP_OPTION (pfile, inhibit_warnings)) | |
104 return 0; | |
105 break; | |
106 | |
107 case CPP_DL_ERROR: | |
108 if (CPP_OPTION (pfile, inhibit_errors)) | |
109 return 0; | |
110 /* ICEs cannot be inhibited. */ | |
111 case CPP_DL_ICE: | |
112 pfile->errors++; | |
113 break; | |
114 } | |
115 | |
116 print_location (pfile, src_loc, column); | |
117 if (CPP_DL_WARNING_P (level)) | |
118 fputs (_("warning: "), stderr); | |
119 else if (level == CPP_DL_ICE) | |
120 fputs (_("internal error: "), stderr); | |
121 else | |
122 fputs (_("error: "), stderr); | |
123 | |
124 return 1; | |
125 } | |
126 | |
127 /* Don't remove the blank before do, as otherwise the exgettext | |
128 script will mistake this as a function definition */ | |
129 #define v_message(msgid, ap) \ | |
130 do { vfprintf (stderr, _(msgid), ap); putc ('\n', stderr); } while (0) | |
131 | |
132 /* Exported interface. */ | |
133 | |
134 /* Print an error at the location of the previously lexed token. */ | 31 /* Print an error at the location of the previously lexed token. */ |
135 void | 32 bool |
136 cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) | 33 cpp_error (cpp_reader * pfile, int level, const char *msgid, ...) |
137 { | 34 { |
138 source_location src_loc; | 35 source_location src_loc; |
139 va_list ap; | 36 va_list ap; |
140 | 37 bool ret; |
38 | |
141 va_start (ap, msgid); | 39 va_start (ap, msgid); |
142 | 40 |
143 if (CPP_OPTION (pfile, client_diagnostic)) | 41 if (CPP_OPTION (pfile, traditional)) |
144 pfile->cb.error (pfile, level, _(msgid), &ap); | 42 { |
43 if (pfile->state.in_directive) | |
44 src_loc = pfile->directive_line; | |
45 else | |
46 src_loc = pfile->line_table->highest_line; | |
47 } | |
48 /* We don't want to refer to a token before the beginning of the | |
49 current run -- that is invalid. */ | |
50 else if (pfile->cur_token == pfile->cur_run->base) | |
51 { | |
52 if (pfile->cur_run->prev != NULL) | |
53 src_loc = pfile->cur_run->prev->limit->src_loc; | |
54 else | |
55 src_loc = 0; | |
56 } | |
145 else | 57 else |
146 { | 58 { |
147 if (CPP_OPTION (pfile, traditional)) | 59 src_loc = pfile->cur_token[-1].src_loc; |
148 { | |
149 if (pfile->state.in_directive) | |
150 src_loc = pfile->directive_line; | |
151 else | |
152 src_loc = pfile->line_table->highest_line; | |
153 } | |
154 /* We don't want to refer to a token before the beginning of the | |
155 current run -- that is invalid. */ | |
156 else if (pfile->cur_token == pfile->cur_run->base) | |
157 { | |
158 if (pfile->cur_run->prev != NULL) | |
159 src_loc = pfile->cur_run->prev->limit->src_loc; | |
160 else | |
161 src_loc = 0; | |
162 } | |
163 else | |
164 { | |
165 src_loc = pfile->cur_token[-1].src_loc; | |
166 } | |
167 | |
168 if (_cpp_begin_message (pfile, level, src_loc, 0)) | |
169 v_message (msgid, ap); | |
170 } | 60 } |
171 | 61 |
62 if (!pfile->cb.error) | |
63 abort (); | |
64 ret = pfile->cb.error (pfile, level, src_loc, 0, _(msgid), &ap); | |
65 | |
172 va_end (ap); | 66 va_end (ap); |
67 return ret; | |
173 } | 68 } |
174 | 69 |
175 /* Print an error at a specific location. */ | 70 /* Print an error at a specific location. */ |
176 void | 71 bool |
177 cpp_error_with_line (cpp_reader *pfile, int level, | 72 cpp_error_with_line (cpp_reader *pfile, int level, |
178 source_location src_loc, unsigned int column, | 73 source_location src_loc, unsigned int column, |
179 const char *msgid, ...) | 74 const char *msgid, ...) |
180 { | 75 { |
181 va_list ap; | 76 va_list ap; |
77 bool ret; | |
182 | 78 |
183 va_start (ap, msgid); | 79 va_start (ap, msgid); |
184 | 80 |
185 if (_cpp_begin_message (pfile, level, src_loc, column)) | 81 if (!pfile->cb.error) |
186 v_message (msgid, ap); | 82 abort (); |
83 ret = pfile->cb.error (pfile, level, src_loc, column, _(msgid), &ap); | |
187 | 84 |
188 va_end (ap); | 85 va_end (ap); |
86 return ret; | |
189 } | 87 } |
190 | 88 |
191 void | 89 bool |
192 cpp_errno (cpp_reader *pfile, int level, const char *msgid) | 90 cpp_errno (cpp_reader *pfile, int level, const char *msgid) |
193 { | 91 { |
194 if (msgid[0] == '\0') | 92 if (msgid[0] == '\0') |
195 msgid = _("stdout"); | 93 msgid = _("stdout"); |
196 | 94 |
197 cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno)); | 95 return cpp_error (pfile, level, "%s: %s", msgid, xstrerror (errno)); |
198 } | 96 } |