mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 04:08:40 +00:00
cleanup StringReader fields
This commit is contained in:
parent
04b88a9eba
commit
3f461f5ec6
@ -29,16 +29,15 @@ pub struct UnmatchedBrace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct StringReader<'a> {
|
pub struct StringReader<'a> {
|
||||||
crate sess: &'a ParseSess,
|
sess: &'a ParseSess,
|
||||||
/// The absolute offset within the source_map of the current character
|
/// Initial position, read-only.
|
||||||
crate pos: BytePos,
|
start_pos: BytePos,
|
||||||
/// The current character (which has been read from self.pos)
|
/// The absolute offset within the source_map of the current character.
|
||||||
crate source_file: Lrc<syntax_pos::SourceFile>,
|
pos: BytePos,
|
||||||
/// Stop reading src at this index.
|
/// Stop reading src at this index.
|
||||||
crate end_src_index: usize,
|
end_src_index: usize,
|
||||||
fatal_errs: Vec<DiagnosticBuilder<'a>>,
|
fatal_errs: Vec<DiagnosticBuilder<'a>>,
|
||||||
// cache a direct reference to the source text, so that we don't have to
|
/// Source text to tokenize.
|
||||||
// retrieve it via `self.source_file.src.as_ref().unwrap()` all the time.
|
|
||||||
src: Lrc<String>,
|
src: Lrc<String>,
|
||||||
override_span: Option<Span>,
|
override_span: Option<Span>,
|
||||||
}
|
}
|
||||||
@ -56,8 +55,8 @@ impl<'a> StringReader<'a> {
|
|||||||
|
|
||||||
StringReader {
|
StringReader {
|
||||||
sess,
|
sess,
|
||||||
|
start_pos: source_file.start_pos,
|
||||||
pos: source_file.start_pos,
|
pos: source_file.start_pos,
|
||||||
source_file,
|
|
||||||
end_src_index: src.len(),
|
end_src_index: src.len(),
|
||||||
src,
|
src,
|
||||||
fatal_errs: Vec::new(),
|
fatal_errs: Vec::new(),
|
||||||
@ -108,12 +107,12 @@ impl<'a> StringReader<'a> {
|
|||||||
let text: &str = &self.src[start_src_index..self.end_src_index];
|
let text: &str = &self.src[start_src_index..self.end_src_index];
|
||||||
|
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
let span = self.mk_sp(self.source_file.end_pos, self.source_file.end_pos);
|
let span = self.mk_sp(self.pos, self.pos);
|
||||||
return Ok(Token::new(token::Eof, span));
|
return Ok(Token::new(token::Eof, span));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let is_beginning_of_file = self.pos == self.source_file.start_pos;
|
let is_beginning_of_file = self.pos == self.start_pos;
|
||||||
if is_beginning_of_file {
|
if is_beginning_of_file {
|
||||||
if let Some(shebang_len) = rustc_lexer::strip_shebang(text) {
|
if let Some(shebang_len) = rustc_lexer::strip_shebang(text) {
|
||||||
let start = self.pos;
|
let start = self.pos;
|
||||||
@ -533,7 +532,7 @@ impl<'a> StringReader<'a> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn src_index(&self, pos: BytePos) -> usize {
|
fn src_index(&self, pos: BytePos) -> usize {
|
||||||
(pos - self.source_file.start_pos).to_usize()
|
(pos - self.start_pos).to_usize()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Slice of the source text from `start` up to but excluding `self.pos`,
|
/// Slice of the source text from `start` up to but excluding `self.pos`,
|
||||||
|
Loading…
Reference in New Issue
Block a user