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
|
@ -26,7 +26,7 @@ use syntax::ast;
|
||||||
use syntax::abi;
|
use syntax::abi;
|
||||||
use syntax::attr;
|
use syntax::attr;
|
||||||
use syntax::attr::AttrMetaMethods;
|
use syntax::attr::AttrMetaMethods;
|
||||||
use syntax::codemap::{DUMMY_SP, Span, mk_sp};
|
use syntax::codemap::{COMMAND_LINE_SP, Span, mk_sp};
|
||||||
use syntax::parse;
|
use syntax::parse;
|
||||||
use syntax::parse::token::InternedString;
|
use syntax::parse::token::InternedString;
|
||||||
use syntax::parse::token;
|
use syntax::parse::token;
|
||||||
|
@ -456,7 +456,7 @@ impl<'a> CrateReader<'a> {
|
||||||
ident: s.to_string(),
|
ident: s.to_string(),
|
||||||
id: ast::DUMMY_NODE_ID,
|
id: ast::DUMMY_NODE_ID,
|
||||||
should_link: true,
|
should_link: true,
|
||||||
}, DUMMY_SP)
|
}, COMMAND_LINE_SP)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let target_triple = &self.sess.opts.target_triple[];
|
let target_triple = &self.sess.opts.target_triple[];
|
||||||
|
|
|
@ -105,6 +105,11 @@ pub struct Span {
|
||||||
|
|
||||||
pub const DUMMY_SP: Span = Span { lo: BytePos(0), hi: BytePos(0), expn_id: NO_EXPANSION };
|
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)]
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show, Copy)]
|
||||||
pub struct Spanned<T> {
|
pub struct Spanned<T> {
|
||||||
pub node: T,
|
pub node: T,
|
||||||
|
@ -235,6 +240,8 @@ pub struct ExpnInfo {
|
||||||
pub struct ExpnId(u32);
|
pub struct ExpnId(u32);
|
||||||
|
|
||||||
pub const NO_EXPANSION: ExpnId = ExpnId(-1);
|
pub const NO_EXPANSION: ExpnId = ExpnId(-1);
|
||||||
|
// For code appearing from the command line
|
||||||
|
pub const COMMAND_LINE_EXPN: ExpnId = ExpnId(-2);
|
||||||
|
|
||||||
impl ExpnId {
|
impl ExpnId {
|
||||||
pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
|
pub fn from_llvm_cookie(cookie: c_uint) -> ExpnId {
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub use self::RenderSpan::*;
|
||||||
pub use self::ColorConfig::*;
|
pub use self::ColorConfig::*;
|
||||||
use self::Destination::*;
|
use self::Destination::*;
|
||||||
|
|
||||||
use codemap::{Pos, Span};
|
use codemap::{COMMAND_LINE_SP, Pos, Span};
|
||||||
use codemap;
|
use codemap;
|
||||||
use diagnostics;
|
use diagnostics;
|
||||||
|
|
||||||
|
@ -368,6 +368,9 @@ impl Emitter for EmitterWriter {
|
||||||
cmsp: Option<(&codemap::CodeMap, Span)>,
|
cmsp: Option<(&codemap::CodeMap, Span)>,
|
||||||
msg: &str, code: Option<&str>, lvl: Level) {
|
msg: &str, code: Option<&str>, lvl: Level) {
|
||||||
let error = match cmsp {
|
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),
|
Some((cm, sp)) => emit(self, cm, FullSpan(sp), msg, code, lvl, false),
|
||||||
None => print_diagnostic(self, "", lvl, msg, code),
|
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,
|
fn emit(dst: &mut EmitterWriter, cm: &codemap::CodeMap, rsp: RenderSpan,
|
||||||
msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> io::IoResult<()> {
|
msg: &str, code: Option<&str>, lvl: Level, custom: bool) -> io::IoResult<()> {
|
||||||
let sp = rsp.span();
|
let sp = rsp.span();
|
||||||
let ss = cm.span_to_string(sp);
|
let ss = if sp == COMMAND_LINE_SP {
|
||||||
let lines = cm.span_to_lines(sp);
|
"<command line option>".to_string()
|
||||||
|
} else {
|
||||||
|
cm.span_to_string(sp)
|
||||||
|
};
|
||||||
if custom {
|
if custom {
|
||||||
// we want to tell compiletest/runtest to look at the last line of the
|
// 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
|
// 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);
|
let ses = cm.span_to_string(span_end);
|
||||||
try!(print_diagnostic(dst, &ses[], lvl, msg, code));
|
try!(print_diagnostic(dst, &ses[], lvl, msg, code));
|
||||||
if rsp.is_full_span() {
|
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 {
|
} else {
|
||||||
try!(print_diagnostic(dst, &ss[], lvl, msg, code));
|
try!(print_diagnostic(dst, &ss[], lvl, msg, code));
|
||||||
if rsp.is_full_span() {
|
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 {
|
match code {
|
||||||
Some(code) =>
|
Some(code) =>
|
||||||
match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) {
|
match dst.registry.as_ref().and_then(|registry| registry.find_description(code)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue