Make FileMap::{lines, multibyte_chars, non_narrow_chars} non-mutable.

This commit is contained in:
Michael Woerister
2018-05-23 15:59:42 +02:00
parent c20824323c
commit 257d279fe4
6 changed files with 121 additions and 138 deletions

View File

@@ -51,11 +51,7 @@ pub struct StringReader<'a> {
pub ch: Option<char>,
pub filemap: Lrc<syntax_pos::FileMap>,
/// Stop reading src at this index.
end_src_index: usize,
/// Whether to record new-lines and multibyte chars in filemap.
/// This is only necessary the first time a filemap is lexed.
/// If part of a filemap is being re-lexed, this should be set to false.
save_new_lines_and_multibyte: bool,
pub end_src_index: usize,
// cached:
peek_tok: token::Token,
peek_span: Span,
@@ -188,7 +184,6 @@ impl<'a> StringReader<'a> {
ch: Some('\n'),
filemap,
end_src_index: src.len(),
save_new_lines_and_multibyte: true,
// dummy values; not read
peek_tok: token::Eof,
peek_span: syntax_pos::DUMMY_SP,
@@ -225,7 +220,6 @@ impl<'a> StringReader<'a> {
let mut sr = StringReader::new_raw_internal(sess, begin.fm, None);
// Seek the lexer to the right byte range.
sr.save_new_lines_and_multibyte = false;
sr.next_pos = span.lo();
sr.end_src_index = sr.src_index(span.hi());
@@ -458,18 +452,6 @@ impl<'a> StringReader<'a> {
let next_ch = char_at(&self.src, next_src_index);
let next_ch_len = next_ch.len_utf8();
if self.ch.unwrap() == '\n' {
if self.save_new_lines_and_multibyte {
self.filemap.next_line(self.next_pos);
}
}
if next_ch_len > 1 {
if self.save_new_lines_and_multibyte {
self.filemap.record_multibyte_char(self.next_pos, next_ch_len);
}
}
self.filemap.record_width(self.next_pos, next_ch);
self.ch = Some(next_ch);
self.pos = self.next_pos;
self.next_pos = self.next_pos + Pos::from_usize(next_ch_len);