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>, fn add_annotation_to_file(file_vec: &mut Vec<FileWithAnnotatedLines>,
file: Rc<FileMap>, file: Rc<FileMap>,
line_index: usize, line_index: usize,
@ -175,6 +175,9 @@ impl EmitterWriter {
if span_label.span == DUMMY_SP { if span_label.span == DUMMY_SP {
continue; continue;
} }
cm.load_source_for_filemap(cm.span_to_filename(span_label.span));
let lo = cm.lookup_char_pos(span_label.span.lo); let lo = cm.lookup_char_pos(span_label.span.lo);
let mut hi = cm.lookup_char_pos(span_label.span.hi); 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 span_to_filename(&self, sp: Span) -> FileName;
fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>; fn merge_spans(&self, sp_lhs: Span, sp_rhs: Span) -> Option<Span>;
fn call_span_if_macro(&self, sp: Span) -> 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 { impl CodeSuggestion {

View File

@ -559,7 +559,7 @@ impl CodeMapper for CodeMap {
} }
sp 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) { let file_map = if let Some(fm) = self.get_filemap(&filename) {
fm fm
} else { } else {

View File

@ -374,14 +374,35 @@ pub struct MultiByteChar {
pub bytes: usize, pub bytes: usize,
} }
/// The state of the lazy external source loading mechanism of a FileMap.
#[derive(PartialEq, Eq, Clone)] #[derive(PartialEq, Eq, Clone)]
pub enum ExternalSource { pub enum ExternalSource {
/// The external source has been loaded already.
Present(String), Present(String),
/// No attempt has been made to load the external source.
AbsentOk, AbsentOk,
/// A failed attempt has been made to load the external source.
AbsentErr, AbsentErr,
/// No external source has to be loaded, since the FileMap represents a local crate.
Unneeded, 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. /// A single source in the CodeMap.
#[derive(Clone)] #[derive(Clone)]
pub struct FileMap { pub struct FileMap {
@ -620,7 +641,7 @@ impl FileMap {
} }
pub fn is_imported(&self) -> bool { 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 { pub fn byte_length(&self) -> u32 {