libsyntax: add COMMAND_LINE_SP and use it for spans generated from the command line
This commit is contained in:
parent
c41cafb10c
commit
0bd022c893
3 changed files with 23 additions and 8 deletions
|
|
@ -105,6 +105,11 @@ pub struct Span {
|
|||
|
||||
pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION };
|
||||
|
||||
// Generic span to be used for code originating from the command line
|
||||
pub const COMMAND_LINE_SP: Span = Span { lo: BytePos(0),
|
||||
hi: BytePos(0),
|
||||
expn_id: COMMAND_LINE_EXPN };
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
|
||||
pub struct Spanned<T> {
|
||||
pub node: T,
|
||||
|
|
@ -235,6 +240,8 @@ pub struct ExpnInfo {
|
|||
pub struct ExpnId(u32);
|
||||
|
||||
pub const NO_EXPANSION: ExpnId = ExpnId(-1);
|
||||
// For code appearing from the command line
|
||||
pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(-2);
|
||||
|
||||
impl ExpnId {
|
||||
pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ pub use self::RenderSpan::*;
|
|||
pub use self::ColorConfig::*;
|
||||
use self::Destination::*;
|
||||
|
||||
use codemap::{Pos, Span};
|
||||
use codemap::{COMMAND_LINE_SP, Pos, Span};
|
||||
use codemap;
|
||||
use diagnostics;
|
||||
|
||||
|
|
@ -368,6 +368,9 @@ impl Emitter for EmitterWriter {
|
|||
cmsp: Option<(&codemap::CodeMap, Span)>,
|
||||
msg: &str, code: Option<&str>, lvl: Level) {
|
||||
let error = match cmsp {
|
||||
Some((cm, COMMAND_LINE_SP)) => emit(self, cm,
|
||||
FileLine(COMMAND_LINE_SP),
|
||||
msg, code, lvl, false),
|
||||
Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, code, lvl, false),
|
||||
None => print_diagnostic(self, "", lvl, msg, code),
|
||||
};
|
||||
|
|
@ -390,8 +393,11 @@ impl Emitter for EmitterWriter {
|
|||
fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
|
||||
msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> io::IoResult<()> {
|
||||
let sp = rsp.span();
|
||||
let ss = cm.span_to_string(sp);
|
||||
let lines = cm.span_to_lines(sp);
|
||||
let ss = if sp == COMMAND_LINE_SP {
|
||||
"<command line option>".to_string()
|
||||
} else {
|
||||
cm.span_to_string(sp)
|
||||
};
|
||||
if custom {
|
||||
// we want to tell compiletest/runtest to look at the last line of the
|
||||
// span (since `custom_highlight_lines` displays an arrow to the end of
|
||||
|
|
@ -400,15 +406,17 @@ fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
|
|||
let ses = cm.span_to_string(span_end);
|
||||
try!(print_diagnostic(dst, &ses[], lvl, msg, code));
|
||||
if rsp.is_full_span() {
|
||||
try!(custom_highlight_lines(dst, cm, sp, lvl, lines));
|
||||
try!(custom_highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
|
||||
}
|
||||
} else {
|
||||
try!(print_diagnostic(dst, &ss[], lvl, msg, code));
|
||||
if rsp.is_full_span() {
|
||||
try!(highlight_lines(dst, cm, sp, lvl, lines));
|
||||
try!(highlight_lines(dst, cm, sp, lvl, cm.span_to_lines(sp)));
|
||||
}
|
||||
}
|
||||
try!(print_macro_backtrace(dst, cm, sp));
|
||||
if sp != COMMAND_LINE_SP {
|
||||
try!(print_macro_backtrace(dst, cm, sp));
|
||||
}
|
||||
match code {
|
||||
Some(code) =>
|
||||
match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue