Improved lazy external source loading and inserted calls.

This commit is contained in:
Inokentiy Babushkin 2017-06-11 10:19:46 +02:00
parent c2c31b2db3
commit c04aa4ed0c
No known key found for this signature in database
GPG Key ID: 7EFC8EC5224DE8EC
4 changed files with 28 additions and 4 deletions

View File

@ -131,7 +131,7 @@ impl EmitterWriter {
}
}
fn preprocess_annotations(&self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
fn preprocess_annotations(&mut self, msp: &MultiSpan) -> Vec<FileWithAnnotatedLines> {
fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
file: Rc<FileMap>,
line_index: usize,
@ -175,6 +175,9 @@ impl EmitterWriter {
if span_label.span == DUMMY_SP {
continue;
}
cm.load_source_for_filemap(cm.span_to_filename(span_label.span));
let lo = cm.lookup_char_pos(span_label.span.lo);
let mut hi = cm.lookup_char_pos(span_label.span.hi);

View File

@ -103,7 +103,7 @@ pub trait CodeMapper {
fn span_to_filename(&self, sp: Span) -> FileName;
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
fn call_span_if_macro(&self, sp: Span) -> Span;
fn load_source_for_filemap(&mut self, file: FileName) -> bool;
fn load_source_for_filemap(&self, file: FileName) -> bool;
}
impl CodeSuggestion {

View File

@ -559,7 +559,7 @@ impl CodeMapper for CodeMap {
}
sp
}
fn load_source_for_filemap(&mut self, filename: FileName) -> bool {
fn load_source_for_filemap(&self, filename: FileName) -> bool {
let file_map = if let Some(fm) = self.get_filemap(&filename) {
fm
} else {

View File

@ -374,14 +374,35 @@ pub struct MultiByteChar {
pub bytes: usize,
}
/// The state of the lazy external source loading mechanism of a FileMap.
#[derive(PartialEq, Eq, Clone)]
pub enum ExternalSource {
/// The external source has been loaded already.
Present(String),
/// No attempt has been made to load the external source.
AbsentOk,
/// A failed attempt has been made to load the external source.
AbsentErr,
/// No external source has to be loaded, since the FileMap represents a local crate.
Unneeded,
}
impl ExternalSource {
pub fn is_absent(&self) -> bool {
match *self {
ExternalSource::Present(_) => false,
_ => true,
}
}
pub fn get_source(&self) -> Option<&str> {
match *self {
ExternalSource::Present(ref src) => Some(src),
_ => None,
}
}
}
/// A single source in the CodeMap.
#[derive(Clone)]
pub struct FileMap {
@ -620,7 +641,7 @@ impl FileMap {
}
pub fn is_imported(&self) -> bool {
self.src.is_none()
self.src.is_none() // TODO: change to something more sensible
}
pub fn byte_length(&self) -> u32 {