@@ -33,7 +33,6 @@ pub trait handler {
33
33
fn bump_err_count ( @mut self ) ;
34
34
fn has_errors ( @mut self ) -> bool ;
35
35
fn abort_if_errors ( @mut self ) ;
36
- fn abort_error_print ( @mut self ) ;
37
36
fn warn ( @mut self , msg : & str ) ;
38
37
fn note ( @mut self , msg : & str ) ;
39
38
// used to indicate a bug in the compiler:
@@ -43,7 +42,6 @@ pub trait handler {
43
42
cmsp : Option < ( @codemap:: CodeMap , span ) > ,
44
43
msg : & str ,
45
44
lvl : level ) ;
46
- fn emit_print ( @mut self , lvl : level ) ;
47
45
}
48
46
49
47
// a span-handler is like a handler but also
@@ -59,15 +57,8 @@ pub trait span_handler {
59
57
fn handler ( @mut self ) -> @handler ;
60
58
}
61
59
62
- struct emitter_arg {
63
- cmsp : Option < ( @codemap:: CodeMap , span ) > ,
64
- msg : ~str ,
65
- lvl : level ,
66
- }
67
-
68
60
struct HandlerT {
69
61
err_count : uint ,
70
- emitters : ~[ emitter_arg ] ,
71
62
emit : Emitter ,
72
63
}
73
64
@@ -78,19 +69,15 @@ struct CodemapT {
78
69
79
70
impl span_handler for CodemapT {
80
71
fn span_fatal ( @mut self , sp : span , msg : & str ) -> ! {
81
- self . handler . bump_err_count ( ) ;
82
72
self . handler . emit ( Some ( ( self . cm , sp) ) , msg, fatal) ;
83
- self . handler . emit_print ( error) ;
84
- self . handler . emit_print ( note) ;
85
- self . handler . abort_error_print ( ) ;
86
73
fail ! ( ) ;
87
74
}
88
75
fn span_err ( @mut self , sp : span , msg : & str ) {
89
76
self . handler . emit ( Some ( ( self . cm , sp) ) , msg, error) ;
90
77
self . handler . bump_err_count ( ) ;
91
78
}
92
79
fn span_warn ( @mut self , sp : span , msg : & str ) {
93
- emit_one ( Some ( ( self . cm , sp) ) , msg, warning) ;
80
+ self . handler . emit ( Some ( ( self . cm , sp) ) , msg, warning) ;
94
81
}
95
82
fn span_note ( @mut self , sp : span , msg : & str ) {
96
83
self . handler . emit ( Some ( ( self . cm , sp) ) , msg, note) ;
@@ -108,13 +95,11 @@ impl span_handler for CodemapT {
108
95
109
96
impl handler for HandlerT {
110
97
fn fatal(@mut self, msg: &str) -> ! {
111
- self.emit_print(error);
112
- self.emit_print(note);
113
- emit_one(None, msg, fatal);
98
+ (self.emit)(None, msg, fatal);
114
99
fail!();
115
100
}
116
101
fn err(@mut self, msg: &str) {
117
- emit_one (None, msg, error);
102
+ (self.emit) (None, msg, error);
118
103
self.bump_err_count();
119
104
}
120
105
fn bump_err_count(@mut self) {
@@ -133,26 +118,13 @@ impl handler for HandlerT {
133
118
}
134
119
self . fatal( s) ;
135
120
}
136
- fn abort_error_print ( @mut self ) {
137
- let s;
138
- match self . err_count {
139
- 0 u => return ,
140
- 1 u => s = ~"aborting due to previous error",
141
- _ => {
142
- s = fmt ! ( "aborting due to %u previous errors" ,
143
- self . err_count) ;
144
- }
145
- }
146
- emit_one ( None , s, fatal) ;
147
- }
148
121
fn warn ( @mut self , msg : & str ) {
149
- emit_one ( None , msg, warning) ;
122
+ ( self . emit ) ( None , msg, warning) ;
150
123
}
151
124
fn note ( @mut self , msg : & str ) {
152
- self . emit ( None , msg, note) ;
125
+ ( self . emit ) ( None , msg, note) ;
153
126
}
154
127
fn bug ( @mut self , msg : & str ) -> ! {
155
- self . bump_err_count ( ) ;
156
128
self . fatal ( ice_msg ( msg) ) ;
157
129
}
158
130
fn unimpl ( @mut self , msg : & str ) -> ! {
@@ -163,50 +135,6 @@ impl handler for HandlerT {
163
135
msg: &str,
164
136
lvl: level) {
165
137
(self.emit)(cmsp, msg, lvl);
166
- let emitter = emitter_arg { cmsp: cmsp,
167
- msg: str::from_slice(msg),
168
- lvl: lvl };
169
- self.emitters.push(emitter);
170
- }
171
-
172
- fn emit_print(@mut self, lvl: level) {
173
- let mut old_cmsp = None;
174
- let mut old_line = 0u;
175
-
176
- let emitters = self.emitters;
177
- let length = emitters.len();
178
- for uint::range(0, length) |i| {
179
- let emitter = copy self.emitters[i];
180
- let cmsp = emitter.cmsp;
181
- let msg = emitter.msg;
182
- if diagnosticstr(lvl) == diagnosticstr(emitter.lvl) {
183
- match cmsp {
184
- Some((cm, sp)) => {
185
- let lo = cm.lookup_char_pos_adj(sp.lo);
186
- let sp = cm.adjust_span(sp);
187
- let ss = cm.span_to_str(sp);
188
- if i == 0 || old_line == lo.line {
189
- if old_line == lo.line {
190
- highlight_lines_cmp(cmsp, old_cmsp);
191
- }
192
- print_diagnostic(ss, lvl, msg);
193
- highlight_lines_cmp(old_cmsp, cmsp);
194
- } else {
195
- highlight_lines(old_cmsp);
196
- print_macro_backtrace(old_cmsp);
197
- print_diagnostic(ss, lvl, msg);
198
- }
199
- old_line = lo.line;
200
- old_cmsp = emitter.cmsp;
201
- }
202
- None => {
203
- print_diagnostic(~" ", lvl, msg) ;
204
- }
205
- }
206
- }
207
- }
208
- highlight_lines ( old_cmsp) ;
209
- print_macro_backtrace ( old_cmsp) ;
210
138
}
211
139
}
212
140
@@ -228,9 +156,7 @@ pub fn mk_handler(emitter: Option<Emitter>) -> @handler {
228
156
}
229
157
} ;
230
158
231
- @mut HandlerT { err_count : 0 ,
232
- emitters : ~[ ] ,
233
- emit : emit } as @handler
159
+ @mut HandlerT { err_count : 0 , emit : emit } as @handler
234
160
}
235
161
236
162
#[ deriving( Eq ) ]
@@ -282,27 +208,23 @@ pub fn collect(messages: @mut ~[~str])
282
208
f
283
209
}
284
210
285
- pub fn emit ( _cmsp : Option < ( @codemap:: CodeMap , span ) > , _msg : & str , _lvl : level ) {
286
- // Nothing to do
287
- }
288
-
289
- pub fn emit_one ( cmsp : Option < ( @codemap:: CodeMap , span ) > ,
290
- msg : & str , lvl : level ) {
211
+ pub fn emit ( cmsp : Option < ( @codemap:: CodeMap , span ) > , msg : & str , lvl : level ) {
291
212
match cmsp {
292
213
Some ( ( cm, sp) ) => {
293
214
let sp = cm. adjust_span ( sp) ;
294
215
let ss = cm. span_to_str ( sp) ;
216
+ let lines = cm. span_to_lines ( sp) ;
295
217
print_diagnostic ( ss, lvl, msg) ;
296
- highlight_lines ( cmsp ) ;
297
- print_macro_backtrace ( cmsp ) ;
218
+ highlight_lines ( cm , sp , lines ) ;
219
+ print_macro_backtrace ( cm , sp ) ;
298
220
}
299
221
None => {
300
222
print_diagnostic ( ~"", lvl, msg) ;
301
223
}
302
224
}
303
225
}
304
226
305
- fn highlight_lines_internal ( cm : @codemap:: CodeMap ,
227
+ fn highlight_lines ( cm : @codemap:: CodeMap ,
306
228
sp : span ,
307
229
lines : @codemap:: FileLines ) {
308
230
let fm = lines. file ;
@@ -369,70 +291,14 @@ fn highlight_lines_internal(cm: @codemap::CodeMap,
369
291
}
370
292
}
371
293
372
- fn highlight_lines( cmsp: Option < ( @codemap:: CodeMap , span ) > ) {
373
- match cmsp {
374
- Some ( ( cm, sp) ) => {
375
- let sp = cm. adjust_span( sp) ;
376
- let lines = cm. span_to_lines( sp) ;
377
- highlight_lines_internal( cm, sp, lines) ;
378
- }
379
- None => ( )
380
- }
381
- }
382
-
383
- fn highlight_lines_cmp( old_cmsp: Option < ( @codemap:: CodeMap , span ) > ,
384
- cmsp: Option < ( @codemap:: CodeMap , span ) > ) {
385
- let mut old_line = ~[ ] ;
386
- let mut new_line = ~[ ] ;
387
- let mut old_lo = 0 u;
388
- let mut new_lo = 0 u;
389
- let mut flag = true ;
390
- match old_cmsp {
391
- Some ( ( cm, sp) ) => {
392
- let lo = cm. lookup_char_pos( sp. lo) ;
393
- let sp = cm. adjust_span( sp) ;
394
- let lines = cm. span_to_lines( sp) ;
395
- old_line = lines. lines;
396
- old_lo = lo. col. to_uint( ) ;
397
- }
398
- None => { flag = false ; }
399
- }
400
-
401
- match cmsp {
402
- Some ( ( cm, sp) ) => {
403
- let lo = cm. lookup_char_pos( sp. lo) ;
404
- let sp = cm. adjust_span( sp) ;
405
- let lines = cm. span_to_lines( sp) ;
406
- new_line = lines. lines;
407
- new_lo = lo. col. to_uint( ) ;
408
- }
409
- None => { flag = false ; }
410
- }
411
-
412
- if flag {
413
- if old_line == new_line && old_lo > new_lo {
414
- highlight_lines( cmsp) ;
415
- }
416
- }
417
- }
418
-
419
- fn print_macro_backtrace_internal( cm: @codemap:: CodeMap , sp: span) {
294
+ fn print_macro_backtrace( cm: @codemap:: CodeMap , sp: span) {
420
295
for sp. expn_info. each |ei| {
421
296
let ss = ei. callee. span. map_default( @~"", |span| @cm. span_to_str( * span) ) ;
422
297
print_diagnostic( * ss, note,
423
298
fmt ! ( "in expansion of %s!" , ei. callee. name) ) ;
424
299
let ss = cm. span_to_str( ei. call_site) ;
425
300
print_diagnostic( ss, note, ~"expansion site") ;
426
- print_macro_backtrace_internal( cm, ei. call_site) ;
427
- }
428
- }
429
-
430
- fn print_macro_backtrace( cmsp: Option <( @codemap:: CodeMap , span) >) {
431
- match cmsp {
432
- Some ( ( cm, sp) ) => {
433
- print_macro_backtrace_internal( cm, sp) ;
434
- }
435
- None => ( )
301
+ print_macro_backtrace( cm, ei. call_site) ;
436
302
}
437
303
}
438
304
0 commit comments