Skip to content

Commit e0c2f3b

Browse files
committed
---
yaml --- r: 145383 b: refs/heads/try2 c: 37c32e2 h: refs/heads/master i: 145381: 57956e2 145379: 7574d78 145375: 6b59e8f v: v3
1 parent bb07fe9 commit e0c2f3b

File tree

5 files changed

+85
-59
lines changed

5 files changed

+85
-59
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 1676e77db279772551cf804bafbad5214096b9a9
8+
refs/heads/try2: 37c32e249505f103f9bcad0bdd83f49f0efec9ef
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/driver/driver.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ pub fn build_configuration(sess: Session) ->
113113
}
114114

115115
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
116-
fn parse_cfgspecs(cfgspecs: ~[~str],
117-
demitter: diagnostic::Emitter) -> ast::CrateConfig {
116+
fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
117+
-> ast::CrateConfig {
118118
do cfgspecs.move_iter().map |s| {
119119
let sess = parse::new_parse_sess(Some(demitter));
120120
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
@@ -589,8 +589,8 @@ static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'stat
589589
("mips", abi::Mips)];
590590

591591
pub fn build_target_config(sopts: @session::options,
592-
demitter: diagnostic::Emitter)
593-
-> @session::config {
592+
demitter: @diagnostic::Emitter)
593+
-> @session::config {
594594
let os = match get_os(sopts.target_triple) {
595595
Some(os) => os,
596596
None => early_error(demitter, ~"unknown operating system")
@@ -638,8 +638,8 @@ pub fn host_triple() -> ~str {
638638

639639
pub fn build_session_options(binary: @str,
640640
matches: &getopts::Matches,
641-
demitter: diagnostic::Emitter)
642-
-> @session::options {
641+
demitter: @diagnostic::Emitter)
642+
-> @session::options {
643643
let crate_type = if matches.opt_present("lib") {
644644
session::lib_crate
645645
} else if matches.opt_present("bin") {
@@ -812,8 +812,8 @@ pub fn build_session_options(binary: @str,
812812
return sopts;
813813
}
814814

815-
pub fn build_session(sopts: @session::options,
816-
demitter: diagnostic::Emitter) -> Session {
815+
pub fn build_session(sopts: @session::options, demitter: @diagnostic::Emitter)
816+
-> Session {
817817
let codemap = @codemap::CodeMap::new();
818818
let diagnostic_handler =
819819
diagnostic::mk_handler(Some(demitter));
@@ -824,9 +824,9 @@ pub fn build_session(sopts: @session::options,
824824

825825
pub fn build_session_(sopts: @session::options,
826826
cm: @codemap::CodeMap,
827-
demitter: diagnostic::Emitter,
827+
demitter: @diagnostic::Emitter,
828828
span_diagnostic_handler: @mut diagnostic::span_handler)
829-
-> Session {
829+
-> Session {
830830
let target_cfg = build_target_config(sopts, demitter);
831831
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,
832832
cm);
@@ -1035,8 +1035,8 @@ pub fn build_output_filenames(input: &input,
10351035
}
10361036
}
10371037

1038-
pub fn early_error(emitter: diagnostic::Emitter, msg: ~str) -> ! {
1039-
emitter(None, msg, diagnostic::fatal);
1038+
pub fn early_error(emitter: @diagnostic::Emitter, msg: ~str) -> ! {
1039+
emitter.emit(None, msg, diagnostic::fatal);
10401040
fail!();
10411041
}
10421042

branches/try2/src/librustc/rustc.rs

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use driver::driver::{compile_input};
3333
use driver::session;
3434
use middle::lint;
3535

36+
use std::comm;
3637
use std::io;
3738
use std::num;
3839
use std::os;
@@ -43,6 +44,7 @@ use std::vec;
4344
use extra::getopts::groups;
4445
use extra::getopts;
4546
use syntax::codemap;
47+
use syntax::diagnostic::Emitter;
4648
use syntax::diagnostic;
4749

4850
pub mod middle {
@@ -191,7 +193,7 @@ pub fn describe_debug_flags() {
191193
}
192194
}
193195

194-
pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
196+
pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
195197
// Don't display log spew by default. Can override with RUST_LOG.
196198
::std::logging::console_off();
197199

@@ -291,6 +293,23 @@ pub enum monitor_msg {
291293
done,
292294
}
293295

296+
struct RustcEmitter {
297+
ch_capture: comm::SharedChan<monitor_msg>
298+
}
299+
300+
impl diagnostic::Emitter for RustcEmitter {
301+
fn emit(&self,
302+
cmsp: Option<(@codemap::CodeMap, codemap::span)>,
303+
msg: &str,
304+
lvl: diagnostic::level) {
305+
if lvl == diagnostic::fatal {
306+
self.ch_capture.send(fatal)
307+
}
308+
309+
diagnostic::DefaultEmitter.emit(cmsp, msg, lvl)
310+
}
311+
}
312+
294313
/*
295314
This is a sanity check that any failure of the compiler is performed
296315
through the diagnostic module and reported properly - we shouldn't be calling
@@ -303,7 +322,7 @@ diagnostic emitter which records when we hit a fatal error. If the task
303322
fails without recording a fatal error then we've encountered a compiler
304323
bug and need to present an error.
305324
*/
306-
pub fn monitor(f: ~fn(diagnostic::Emitter)) {
325+
pub fn monitor(f: ~fn(@diagnostic::Emitter)) {
307326
use std::comm::*;
308327

309328
// XXX: This is a hack for newsched since it doesn't support split stacks.
@@ -324,18 +343,11 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
324343

325344
match do task_builder.try {
326345
let ch = ch_capture.clone();
327-
let ch_capture = ch.clone();
328346
// The 'diagnostics emitter'. Every error, warning, etc. should
329347
// go through this function.
330-
let demitter: @fn(Option<(@codemap::CodeMap, codemap::Span)>,
331-
&str,
332-
diagnostic::level) =
333-
|cmsp, msg, lvl| {
334-
if lvl == diagnostic::fatal {
335-
ch_capture.send(fatal);
336-
}
337-
diagnostic::emit(cmsp, msg, lvl);
338-
};
348+
let demitter = @RustcEmitter {
349+
ch_capture: ch.clone(),
350+
} as @diagnostic::Emitter;
339351

340352
struct finally {
341353
ch: SharedChan<monitor_msg>,
@@ -357,7 +369,7 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
357369
result::Err(_) => {
358370
// Task failed without emitting a fatal diagnostic
359371
if p.recv() == done {
360-
diagnostic::emit(
372+
diagnostic::DefaultEmitter.emit(
361373
None,
362374
diagnostic::ice_msg("unexpected failure"),
363375
diagnostic::error);
@@ -370,7 +382,9 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
370382
to github.com/mozilla/rust/issues"
371383
];
372384
for note in xs.iter() {
373-
diagnostic::emit(None, *note, diagnostic::note)
385+
diagnostic::DefaultEmitter.emit(None,
386+
*note,
387+
diagnostic::note)
374388
}
375389
}
376390
// Fail so the process returns a failure code

branches/try2/src/libsyntax/diagnostic.rs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ use std::io;
1515
use std::local_data;
1616
use extra::term;
1717

18-
pub type Emitter = @fn(cmsp: Option<(@codemap::CodeMap, Span)>,
19-
msg: &str,
20-
lvl: level);
18+
pub trait Emitter {
19+
fn emit(&self,
20+
cmsp: Option<(@codemap::CodeMap, Span)>,
21+
msg: &str,
22+
lvl: level);
23+
}
2124

2225
// a handler deals with errors; certain errors
2326
// (fatal, bug, unimpl) may cause immediate exit,
@@ -55,7 +58,7 @@ pub trait span_handler {
5558

5659
struct HandlerT {
5760
err_count: uint,
58-
emit: Emitter,
61+
emit: @Emitter,
5962
}
6063

6164
struct CodemapT {
@@ -91,11 +94,11 @@ impl span_handler for CodemapT {
9194
9295
impl handler for HandlerT {
9396
fn fatal(@mut self, msg: &str) -> ! {
94-
(self.emit)(None, msg, fatal);
97+
self.emit.emit(None, msg, fatal);
9598
fail!();
9699
}
97100
fn err(@mut self, msg: &str) {
98-
(self.emit)(None, msg, error);
101+
self.emit.emit(None, msg, error);
99102
self.bump_err_count();
100103
}
101104
fn bump_err_count(@mut self) {
@@ -120,10 +123,10 @@ impl handler for HandlerT {
120123
self.fatal(s);
121124
}
122125
fn warn(@mut self, msg: &str) {
123-
(self.emit)(None, msg, warning);
126+
self.emit.emit(None, msg, warning);
124127
}
125128
fn note(@mut self, msg: &str) {
126-
(self.emit)(None, msg, note);
129+
self.emit.emit(None, msg, note);
127130
}
128131
fn bug(@mut self, msg: &str) -> ! {
129132
self.fatal(ice_msg(msg));
@@ -135,7 +138,7 @@ impl handler for HandlerT {
135138
cmsp: Option<(@codemap::CodeMap, Span)>,
136139
msg: &str,
137140
lvl: level) {
138-
(self.emit)(cmsp, msg, lvl);
141+
self.emit.emit(cmsp, msg, lvl);
139142
}
140143
}
141144
@@ -145,19 +148,22 @@ pub fn ice_msg(msg: &str) -> ~str {
145148

146149
pub fn mk_span_handler(handler: @mut handler, cm: @codemap::CodeMap)
147150
-> @mut span_handler {
148-
@mut CodemapT { handler: handler, cm: cm } as @mut span_handler
151+
@mut CodemapT {
152+
handler: handler,
153+
cm: cm,
154+
} as @mut span_handler
149155
}
150156

151-
pub fn mk_handler(emitter: Option<Emitter>) -> @mut handler {
152-
let emit: Emitter = match emitter {
157+
pub fn mk_handler(emitter: Option<@Emitter>) -> @mut handler {
158+
let emit: @Emitter = match emitter {
153159
Some(e) => e,
154-
None => {
155-
let emit: Emitter = |cmsp, msg, t| emit(cmsp, msg, t);
156-
emit
157-
}
160+
None => @DefaultEmitter as @Emitter
158161
};
159162

160-
@mut HandlerT { err_count: 0, emit: emit } as @mut handler
163+
@mut HandlerT {
164+
err_count: 0,
165+
emit: emit,
166+
} as @mut handler
161167
}
162168

163169
#[deriving(Eq)]
@@ -237,24 +243,30 @@ pub fn collect(messages: @mut ~[~str])
237243
f
238244
}
239245

240-
pub fn emit(cmsp: Option<(@codemap::CodeMap, Span)>, msg: &str, lvl: level) {
241-
match cmsp {
242-
Some((cm, sp)) => {
243-
let sp = cm.adjust_span(sp);
244-
let ss = cm.span_to_str(sp);
245-
let lines = cm.span_to_lines(sp);
246-
print_diagnostic(ss, lvl, msg);
247-
highlight_lines(cm, sp, lvl, lines);
248-
print_macro_backtrace(cm, sp);
249-
}
250-
None => {
251-
print_diagnostic("", lvl, msg);
252-
}
246+
pub struct DefaultEmitter;
247+
248+
impl Emitter for DefaultEmitter {
249+
fn emit(&self,
250+
cmsp: Option<(@codemap::CodeMap, Span)>,
251+
msg: &str,
252+
lvl: level) {
253+
match cmsp {
254+
Some((cm, sp)) => {
255+
let sp = cm.adjust_span(sp);
256+
let ss = cm.span_to_str(sp);
257+
let lines = cm.span_to_lines(sp);
258+
print_diagnostic(ss, lvl, msg);
259+
highlight_lines(cm, sp, lvl, lines);
260+
print_macro_backtrace(cm, sp);
261+
}
262+
None => print_diagnostic("", lvl, msg),
263+
}
253264
}
254265
}
255266

256267
fn highlight_lines(cm: @codemap::CodeMap,
257-
sp: Span, lvl: level,
268+
sp: Span,
269+
lvl: level,
258270
lines: @codemap::FileLines) {
259271
let fm = lines.file;
260272

branches/try2/src/libsyntax/parse/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct ParseSess {
4545
included_mod_stack: ~[Path],
4646
}
4747

48-
pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess {
48+
pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess {
4949
let cm = @CodeMap::new();
5050
@mut ParseSess {
5151
cm: cm,

0 commit comments

Comments
 (0)