librustc: Remove the remaining direct uses of `@fn` from librustc.

This commit is contained in:
Patrick Walton 2013-08-29 18:34:09 -07:00
parent 1676e77db2
commit 37c32e2495
4 changed files with 84 additions and 58 deletions

View File

@ -113,8 +113,8 @@ pub fn build_configuration(sess: Session) ->
}
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
fn parse_cfgspecs(cfgspecs: ~[~str],
demitter: diagnostic::Emitter) -> ast::CrateConfig {
fn parse_cfgspecs(cfgspecs: ~[~str], demitter: @diagnostic::Emitter)
-> ast::CrateConfig {
do cfgspecs.move_iter().map |s| {
let sess = parse::new_parse_sess(Some(demitter));
parse::parse_meta_from_source_str(@"cfgspec", s.to_managed(), ~[], sess)
@ -589,8 +589,8 @@ static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'stat
("mips", abi::Mips)];
pub fn build_target_config(sopts: @session::options,
demitter: diagnostic::Emitter)
-> @session::config {
demitter: @diagnostic::Emitter)
-> @session::config {
let os = match get_os(sopts.target_triple) {
Some(os) => os,
None => early_error(demitter, ~"unknown operating system")
@ -638,8 +638,8 @@ pub fn host_triple() -> ~str {
pub fn build_session_options(binary: @str,
matches: &getopts::Matches,
demitter: diagnostic::Emitter)
-> @session::options {
demitter: @diagnostic::Emitter)
-> @session::options {
let crate_type = if matches.opt_present("lib") {
session::lib_crate
} else if matches.opt_present("bin") {
@ -812,8 +812,8 @@ pub fn build_session_options(binary: @str,
return sopts;
}
pub fn build_session(sopts: @session::options,
demitter: diagnostic::Emitter) -> Session {
pub fn build_session(sopts: @session::options, demitter: @diagnostic::Emitter)
-> Session {
let codemap = @codemap::CodeMap::new();
let diagnostic_handler =
diagnostic::mk_handler(Some(demitter));
@ -824,9 +824,9 @@ pub fn build_session(sopts: @session::options,
pub fn build_session_(sopts: @session::options,
cm: @codemap::CodeMap,
demitter: diagnostic::Emitter,
demitter: @diagnostic::Emitter,
span_diagnostic_handler: @mut diagnostic::span_handler)
-> Session {
-> Session {
let target_cfg = build_target_config(sopts, demitter);
let p_s = parse::new_parse_sess_special_handler(span_diagnostic_handler,
cm);
@ -1035,8 +1035,8 @@ pub fn build_output_filenames(input: &input,
}
}
pub fn early_error(emitter: diagnostic::Emitter, msg: ~str) -> ! {
emitter(None, msg, diagnostic::fatal);
pub fn early_error(emitter: @diagnostic::Emitter, msg: ~str) -> ! {
emitter.emit(None, msg, diagnostic::fatal);
fail!();
}

View File

@ -33,6 +33,7 @@ use driver::driver::{compile_input};
use driver::session;
use middle::lint;
use std::comm;
use std::io;
use std::num;
use std::os;
@ -43,6 +44,7 @@ use std::vec;
use extra::getopts::groups;
use extra::getopts;
use syntax::codemap;
use syntax::diagnostic::Emitter;
use syntax::diagnostic;
pub mod middle {
@ -191,7 +193,7 @@ pub fn describe_debug_flags() {
}
}
pub fn run_compiler(args: &[~str], demitter: diagnostic::Emitter) {
pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
// Don't display log spew by default. Can override with RUST_LOG.
::std::logging::console_off();
@ -291,6 +293,23 @@ pub enum monitor_msg {
done,
}
struct RustcEmitter {
ch_capture: comm::SharedChan<monitor_msg>
}
impl diagnostic::Emitter for RustcEmitter {
fn emit(&self,
cmsp: Option<(@codemap::CodeMap, codemap::span)>,
msg: &str,
lvl: diagnostic::level) {
if lvl == diagnostic::fatal {
self.ch_capture.send(fatal)
}
diagnostic::DefaultEmitter.emit(cmsp, msg, lvl)
}
}
/*
This is a sanity check that any failure of the compiler is performed
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
fails without recording a fatal error then we've encountered a compiler
bug and need to present an error.
*/
pub fn monitor(f: ~fn(diagnostic::Emitter)) {
pub fn monitor(f: ~fn(@diagnostic::Emitter)) {
use std::comm::*;
// 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)) {
match do task_builder.try {
let ch = ch_capture.clone();
let ch_capture = ch.clone();
// The 'diagnostics emitter'. Every error, warning, etc. should
// go through this function.
let demitter: @fn(Option<(@codemap::CodeMap, codemap::Span)>,
&str,
diagnostic::level) =
|cmsp, msg, lvl| {
if lvl == diagnostic::fatal {
ch_capture.send(fatal);
}
diagnostic::emit(cmsp, msg, lvl);
};
let demitter = @RustcEmitter {
ch_capture: ch.clone(),
} as @diagnostic::Emitter;
struct finally {
ch: SharedChan<monitor_msg>,
@ -357,7 +369,7 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
result::Err(_) => {
// Task failed without emitting a fatal diagnostic
if p.recv() == done {
diagnostic::emit(
diagnostic::DefaultEmitter.emit(
None,
diagnostic::ice_msg("unexpected failure"),
diagnostic::error);
@ -370,7 +382,9 @@ pub fn monitor(f: ~fn(diagnostic::Emitter)) {
to github.com/mozilla/rust/issues"
];
for note in xs.iter() {
diagnostic::emit(None, *note, diagnostic::note)
diagnostic::DefaultEmitter.emit(None,
*note,
diagnostic::note)
}
}
// Fail so the process returns a failure code

View File

@ -15,9 +15,12 @@ use std::io;
use std::local_data;
use extra::term;
pub type Emitter = @fn(cmsp: Option<(@codemap::CodeMap, Span)>,
msg: &str,
lvl: level);
pub trait Emitter {
fn emit(&self,
cmsp: Option<(@codemap::CodeMap, Span)>,
msg: &str,
lvl: level);
}
// a handler deals with errors; certain errors
// (fatal, bug, unimpl) may cause immediate exit,
@ -55,7 +58,7 @@ pub trait span_handler {
struct HandlerT {
err_count: uint,
emit: Emitter,
emit: @Emitter,
}
struct CodemapT {
@ -91,11 +94,11 @@ impl span_handler for CodemapT {
impl handler for HandlerT {
fn fatal(@mut self, msg: &str) -> ! {
(self.emit)(None, msg, fatal);
self.emit.emit(None, msg, fatal);
fail!();
}
fn err(@mut self, msg: &str) {
(self.emit)(None, msg, error);
self.emit.emit(None, msg, error);
self.bump_err_count();
}
fn bump_err_count(@mut self) {
@ -120,10 +123,10 @@ impl handler for HandlerT {
self.fatal(s);
}
fn warn(@mut self, msg: &str) {
(self.emit)(None, msg, warning);
self.emit.emit(None, msg, warning);
}
fn note(@mut self, msg: &str) {
(self.emit)(None, msg, note);
self.emit.emit(None, msg, note);
}
fn bug(@mut self, msg: &str) -> ! {
self.fatal(ice_msg(msg));
@ -135,7 +138,7 @@ impl handler for HandlerT {
cmsp: Option<(@codemap::CodeMap, Span)>,
msg: &str,
lvl: level) {
(self.emit)(cmsp, msg, lvl);
self.emit.emit(cmsp, msg, lvl);
}
}
@ -145,19 +148,22 @@ pub fn ice_msg(msg: &str) -> ~str {
pub fn mk_span_handler(handler: @mut handler, cm: @codemap::CodeMap)
-> @mut span_handler {
@mut CodemapT { handler: handler, cm: cm } as @mut span_handler
@mut CodemapT {
handler: handler,
cm: cm,
} as @mut span_handler
}
pub fn mk_handler(emitter: Option<Emitter>) -> @mut handler {
let emit: Emitter = match emitter {
pub fn mk_handler(emitter: Option<@Emitter>) -> @mut handler {
let emit: @Emitter = match emitter {
Some(e) => e,
None => {
let emit: Emitter = |cmsp, msg, t| emit(cmsp, msg, t);
emit
}
None => @DefaultEmitter as @Emitter
};
@mut HandlerT { err_count: 0, emit: emit } as @mut handler
@mut HandlerT {
err_count: 0,
emit: emit,
} as @mut handler
}
#[deriving(Eq)]
@ -237,24 +243,30 @@ pub fn collect(messages: @mut ~[~str])
f
}
pub fn emit(cmsp: Option<(@codemap::CodeMap, Span)>, msg: &str, lvl: level) {
match cmsp {
Some((cm, sp)) => {
let sp = cm.adjust_span(sp);
let ss = cm.span_to_str(sp);
let lines = cm.span_to_lines(sp);
print_diagnostic(ss, lvl, msg);
highlight_lines(cm, sp, lvl, lines);
print_macro_backtrace(cm, sp);
}
None => {
print_diagnostic("", lvl, msg);
}
pub struct DefaultEmitter;
impl Emitter for DefaultEmitter {
fn emit(&self,
cmsp: Option<(@codemap::CodeMap, Span)>,
msg: &str,
lvl: level) {
match cmsp {
Some((cm, sp)) => {
let sp = cm.adjust_span(sp);
let ss = cm.span_to_str(sp);
let lines = cm.span_to_lines(sp);
print_diagnostic(ss, lvl, msg);
highlight_lines(cm, sp, lvl, lines);
print_macro_backtrace(cm, sp);
}
None => print_diagnostic("", lvl, msg),
}
}
}
fn highlight_lines(cm: @codemap::CodeMap,
sp: Span, lvl: level,
sp: Span,
lvl: level,
lines: @codemap::FileLines) {
let fm = lines.file;

View File

@ -45,7 +45,7 @@ pub struct ParseSess {
included_mod_stack: ~[Path],
}
pub fn new_parse_sess(demitter: Option<Emitter>) -> @mut ParseSess {
pub fn new_parse_sess(demitter: Option<@Emitter>) -> @mut ParseSess {
let cm = @CodeMap::new();
@mut ParseSess {
cm: cm,