diff options
| author | Donato Sciarra <sciarp@gmail.com> | 2018-08-18 12:13:56 +0200 |
|---|---|---|
| committer | Donato Sciarra <sciarp@gmail.com> | 2018-08-19 23:00:59 +0200 |
| commit | cbd05957103926fa10d41474fde773167fe64dfb (patch) | |
| tree | 8ff2321dca0305ba524398cf1d415afc51efeeab /src/libsyntax | |
| parent | d6dcbcd4e11a1b787a9db1fa43a49907e8bccecf (diff) | |
| download | rust-cbd05957103926fa10d41474fde773167fe64dfb.tar.gz rust-cbd05957103926fa10d41474fde773167fe64dfb.zip | |
mv filemap source_file
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 88 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/source_util.rs | 6 | ||||
| -rw-r--r-- | src/libsyntax/json.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 38 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/test_snippet.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/util/parser_testing.rs | 6 |
9 files changed, 91 insertions, 91 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index c9a9fbf4d7b..34cd026f7a0 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -109,12 +109,12 @@ impl FileLoader for RealFileLoader { pub struct StableFilemapId(u128); impl StableFilemapId { - pub fn new(filemap: &SourceFile) -> StableFilemapId { + pub fn new(source_file: &SourceFile) -> StableFilemapId { let mut hasher = StableHasher::new(); - filemap.name.hash(&mut hasher); - filemap.name_was_remapped.hash(&mut hasher); - filemap.unmapped_path.hash(&mut hasher); + source_file.name.hash(&mut hasher); + source_file.name_was_remapped.hash(&mut hasher); + source_file.unmapped_path.hash(&mut hasher); StableFilemapId(hasher.finish()) } @@ -126,7 +126,7 @@ impl StableFilemapId { pub(super) struct SourceMapFiles { pub(super) file_maps: Vec<Lrc<SourceFile>>, - stable_id_to_filemap: FxHashMap<StableFilemapId, Lrc<SourceFile>> + stable_id_to_source_file: FxHashMap<StableFilemapId, Lrc<SourceFile>> } pub struct SourceMap { @@ -145,7 +145,7 @@ impl SourceMap { SourceMap { files: Lock::new(SourceMapFiles { file_maps: Vec::new(), - stable_id_to_filemap: FxHashMap(), + stable_id_to_source_file: FxHashMap(), }), file_loader: Box::new(RealFileLoader), path_mapping, @@ -168,7 +168,7 @@ impl SourceMap { SourceMap { files: Lock::new(SourceMapFiles { file_maps: Vec::new(), - stable_id_to_filemap: FxHashMap(), + stable_id_to_source_file: FxHashMap(), }), file_loader: file_loader, path_mapping, @@ -191,15 +191,15 @@ impl SourceMap { } else { path.to_owned().into() }; - Ok(self.new_filemap(filename, src)) + Ok(self.new_source_file(filename, src)) } pub fn files(&self) -> LockGuard<Vec<Lrc<SourceFile>>> { LockGuard::map(self.files.borrow(), |files| &mut files.file_maps) } - pub fn filemap_by_stable_id(&self, stable_id: StableFilemapId) -> Option<Lrc<SourceFile>> { - self.files.borrow().stable_id_to_filemap.get(&stable_id).map(|fm| fm.clone()) + pub fn source_file_by_stable_id(&self, stable_id: StableFilemapId) -> Option<Lrc<SourceFile>> { + self.files.borrow().stable_id_to_source_file.get(&stable_id).map(|fm| fm.clone()) } fn next_start_pos(&self) -> usize { @@ -211,9 +211,9 @@ impl SourceMap { } } - /// Creates a new filemap. + /// Creates a new source_file. /// This does not ensure that only one SourceFile exists per file name. - pub fn new_filemap(&self, filename: FileName, src: String) -> Lrc<SourceFile> { + pub fn new_source_file(&self, filename: FileName, src: String) -> Lrc<SourceFile> { let start_pos = self.next_start_pos(); // The path is used to determine the directory for loading submodules and @@ -230,7 +230,7 @@ impl SourceMap { }, other => (other, false), }; - let filemap = Lrc::new(SourceFile::new( + let source_file = Lrc::new(SourceFile::new( filename, was_remapped, unmapped_path, @@ -240,17 +240,17 @@ impl SourceMap { let mut files = self.files.borrow_mut(); - files.file_maps.push(filemap.clone()); - files.stable_id_to_filemap.insert(StableFilemapId::new(&filemap), filemap.clone()); + files.file_maps.push(source_file.clone()); + files.stable_id_to_source_file.insert(StableFilemapId::new(&source_file), source_file.clone()); - filemap + source_file } /// Allocates a new SourceFile representing a source file from an external - /// crate. The source code of such an "imported filemap" is not available, + /// crate. The source code of such an "imported source_file" is not available, /// but we still know enough to generate accurate debuginfo location /// information for things inlined from other crates. - pub fn new_imported_filemap(&self, + pub fn new_imported_source_file(&self, filename: FileName, name_was_remapped: bool, crate_of_origin: u32, @@ -278,7 +278,7 @@ impl SourceMap { *swc = *swc + start_pos; } - let filemap = Lrc::new(SourceFile { + let source_file = Lrc::new(SourceFile { name: filename, name_was_remapped, unmapped_path: None, @@ -296,10 +296,10 @@ impl SourceMap { let mut files = self.files.borrow_mut(); - files.file_maps.push(filemap.clone()); - files.stable_id_to_filemap.insert(StableFilemapId::new(&filemap), filemap.clone()); + files.file_maps.push(source_file.clone()); + files.stable_id_to_source_file.insert(StableFilemapId::new(&source_file), source_file.clone()); - filemap + source_file } pub fn mk_substr_filename(&self, sp: Span) -> String { @@ -385,9 +385,9 @@ impl SourceMap { } } - // If the relevant filemap is empty, we don't return a line number. + // If the relevant source_file is empty, we don't return a line number. pub fn lookup_line(&self, pos: BytePos) -> Result<SourceFileAndLine, Lrc<SourceFile>> { - let idx = self.lookup_filemap_idx(pos); + let idx = self.lookup_source_file_idx(pos); let f = (*self.files.borrow().file_maps)[idx].clone(); @@ -541,7 +541,7 @@ impl SourceMap { local_end.fm.start_pos) })); } else { - self.ensure_filemap_source_present(local_begin.fm.clone()); + self.ensure_source_file_source_present(local_begin.fm.clone()); let start_index = local_begin.pos.to_usize(); let end_index = local_end.pos.to_usize(); @@ -798,7 +798,7 @@ impl SourceMap { } } - pub fn get_filemap(&self, filename: &FileName) -> Option<Lrc<SourceFile>> { + pub fn get_source_file(&self, filename: &FileName) -> Option<Lrc<SourceFile>> { for fm in self.files.borrow().file_maps.iter() { if *filename == fm.name { return Some(fm.clone()); @@ -809,15 +809,15 @@ impl SourceMap { /// For a global BytePos compute the local offset within the containing SourceFile pub fn lookup_byte_offset(&self, bpos: BytePos) -> SourceFileAndBytePos { - let idx = self.lookup_filemap_idx(bpos); + let idx = self.lookup_source_file_idx(bpos); let fm = (*self.files.borrow().file_maps)[idx].clone(); let offset = bpos - fm.start_pos; SourceFileAndBytePos {fm: fm, pos: offset} } - /// Converts an absolute BytePos to a CharPos relative to the filemap. + /// Converts an absolute BytePos to a CharPos relative to the source_file. pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos { - let idx = self.lookup_filemap_idx(bpos); + let idx = self.lookup_source_file_idx(bpos); let map = &(*self.files.borrow().file_maps)[idx]; // The number of extra bytes due to multibyte chars in the SourceFile @@ -841,13 +841,13 @@ impl SourceMap { CharPos(bpos.to_usize() - map.start_pos.to_usize() - total_extra_bytes as usize) } - // Return the index of the filemap (in self.files) which contains pos. - pub fn lookup_filemap_idx(&self, pos: BytePos) -> usize { + // Return the index of the source_file (in self.files) which contains pos. + pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize { let files = self.files.borrow(); let files = &files.file_maps; let count = files.len(); - // Binary search for the filemap. + // Binary search for the source_file. let mut a = 0; let mut b = count; while b - a > 1 { @@ -966,7 +966,7 @@ impl SourceMapper for SourceMap { } sp } - fn ensure_filemap_source_present(&self, file_map: Lrc<SourceFile>) -> bool { + fn ensure_source_file_source_present(&self, file_map: Lrc<SourceFile>) -> bool { file_map.add_external_src( || match file_map.name { FileName::Real(ref name) => self.file_loader.read_file(name).ok(), @@ -1025,11 +1025,11 @@ mod tests { fn init_code_map() -> SourceMap { let cm = SourceMap::new(FilePathMapping::empty()); - cm.new_filemap(PathBuf::from("blork.rs").into(), + cm.new_source_file(PathBuf::from("blork.rs").into(), "first line.\nsecond line".to_string()); - cm.new_filemap(PathBuf::from("empty.rs").into(), + cm.new_source_file(PathBuf::from("empty.rs").into(), "".to_string()); - cm.new_filemap(PathBuf::from("blork2.rs").into(), + cm.new_source_file(PathBuf::from("blork2.rs").into(), "first line.\nsecond line".to_string()); cm } @@ -1066,7 +1066,7 @@ mod tests { #[test] fn t5() { - // Test zero-length filemaps. + // Test zero-length source_files. let cm = init_code_map(); let loc1 = cm.lookup_char_pos(BytePos(22)); @@ -1083,9 +1083,9 @@ mod tests { fn init_code_map_mbc() -> SourceMap { let cm = SourceMap::new(FilePathMapping::empty()); // € is a three byte utf8 char. - cm.new_filemap(PathBuf::from("blork.rs").into(), + cm.new_source_file(PathBuf::from("blork.rs").into(), "fir€st €€€€ line.\nsecond line".to_string()); - cm.new_filemap(PathBuf::from("blork2.rs").into(), + cm.new_source_file(PathBuf::from("blork2.rs").into(), "first line€€.\n€ second line".to_string()); cm } @@ -1110,7 +1110,7 @@ mod tests { #[test] fn t7() { - // Test span_to_lines for a span ending at the end of filemap + // Test span_to_lines for a span ending at the end of source_file let cm = init_code_map(); let span = Span::new(BytePos(12), BytePos(23), NO_EXPANSION); let file_lines = cm.span_to_lines(span).unwrap(); @@ -1138,7 +1138,7 @@ mod tests { let cm = SourceMap::new(FilePathMapping::empty()); let inputtext = "aaaaa\nbbbbBB\nCCC\nDDDDDddddd\neee\n"; let selection = " \n ~~\n~~~\n~~~~~ \n \n"; - cm.new_filemap(Path::new("blork.rs").to_owned().into(), inputtext.to_string()); + cm.new_source_file(Path::new("blork.rs").to_owned().into(), inputtext.to_string()); let span = span_from_selection(inputtext, selection); // check that we are extracting the text we thought we were extracting @@ -1156,7 +1156,7 @@ mod tests { #[test] fn t8() { - // Test span_to_snippet for a span ending at the end of filemap + // Test span_to_snippet for a span ending at the end of source_file let cm = init_code_map(); let span = Span::new(BytePos(12), BytePos(23), NO_EXPANSION); let snippet = cm.span_to_snippet(span); @@ -1166,7 +1166,7 @@ mod tests { #[test] fn t9() { - // Test span_to_str for a span ending at the end of filemap + // Test span_to_str for a span ending at the end of source_file let cm = init_code_map(); let span = Span::new(BytePos(12), BytePos(23), NO_EXPANSION); let sstr = cm.span_to_string(span); @@ -1181,7 +1181,7 @@ mod tests { let inputtext = "bbbb BB\ncc CCC\n"; let selection1 = " ~~\n \n"; let selection2 = " \n ~~~\n"; - cm.new_filemap(Path::new("blork.rs").to_owned().into(), inputtext.to_owned()); + cm.new_source_file(Path::new("blork.rs").to_owned().into(), inputtext.to_owned()); let span1 = span_from_selection(inputtext, selection1); let span2 = span_from_selection(inputtext, selection2); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ffa2730d686..6b41dfafd07 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1563,7 +1563,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { // Add this input file to the code map to make it available as // dependency information - self.cx.codemap().new_filemap(filename.into(), src); + self.cx.codemap().new_source_file(filename.into(), src); let include_info = vec![ dummy_spanned(ast::NestedMetaItemKind::MetaItem( diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 9b7e0fe1ae5..fdf9c33b6f4 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -63,7 +63,7 @@ pub fn expand_column_gated(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Token } /// file!(): expands to the current filename */ -/// The filemap (`loc.file`) contains a bunch more information we could spit +/// The source_file (`loc.file`) contains a bunch more information we could spit /// out if we wanted. pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult+'static> { @@ -154,7 +154,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenT // Add this input file to the code map to make it available as // dependency information - cx.codemap().new_filemap(file.into(), src); + cx.codemap().new_source_file(file.into(), src); base::MacEager::expr(cx.expr_str(sp, interned_src)) } @@ -184,7 +184,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::Toke Ok(..) => { // Add this input file to the code map to make it available as // dependency information, but don't enter it's contents - cx.codemap().new_filemap(file.into(), "".to_string()); + cx.codemap().new_source_file(file.into(), "".to_string()); base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) } diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index a090083f608..1ac51a68b62 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -340,7 +340,7 @@ impl DiagnosticSpan { } impl DiagnosticSpanLine { - fn line_from_filemap(fm: &syntax_pos::SourceFile, + fn line_from_source_file(fm: &syntax_pos::SourceFile, index: usize, h_start: usize, h_end: usize) @@ -362,7 +362,7 @@ impl DiagnosticSpanLine { lines.lines .iter() .map(|line| { - DiagnosticSpanLine::line_from_filemap(fm, + DiagnosticSpanLine::line_from_source_file(fm, line.line_index, line.start_col.0 + 1, line.end_col.0 + 1) diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 2c227756f9a..f4d4635b61e 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -247,11 +247,11 @@ fn read_block_comment(rdr: &mut StringReader, let mut lines: Vec<String> = Vec::new(); // Count the number of chars since the start of the line by rescanning. - let mut src_index = rdr.src_index(rdr.filemap.line_begin_pos(rdr.pos)); + let mut src_index = rdr.src_index(rdr.source_file.line_begin_pos(rdr.pos)); let end_src_index = rdr.src_index(rdr.pos); assert!(src_index <= end_src_index, "src_index={}, end_src_index={}, line_begin_pos={}", - src_index, end_src_index, rdr.filemap.line_begin_pos(rdr.pos).to_u32()); + src_index, end_src_index, rdr.source_file.line_begin_pos(rdr.pos).to_u32()); let mut n = 0; while src_index < end_src_index { @@ -372,8 +372,8 @@ pub fn gather_comments_and_literals(sess: &ParseSess, path: FileName, srdr: &mut let mut src = String::new(); srdr.read_to_string(&mut src).unwrap(); let cm = SourceMap::new(sess.codemap().path_mapping().clone()); - let filemap = cm.new_filemap(path, src); - let mut rdr = lexer::StringReader::new_raw(sess, filemap, None); + let source_file = cm.new_source_file(path, src); + let mut rdr = lexer::StringReader::new_raw(sess, source_file, None); let mut comments: Vec<Comment> = Vec::new(); let mut literals: Vec<Literal> = Vec::new(); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 654ac692338..acec975d32a 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -49,7 +49,7 @@ pub struct StringReader<'a> { pub pos: BytePos, /// The current character (which has been read from self.pos) pub ch: Option<char>, - pub filemap: Lrc<syntax_pos::SourceFile>, + pub source_file: Lrc<syntax_pos::SourceFile>, /// Stop reading src at this index. pub end_src_index: usize, // cached: @@ -58,7 +58,7 @@ pub struct StringReader<'a> { peek_span_src_raw: Span, fatal_errs: Vec<DiagnosticBuilder<'a>>, // cache a direct reference to the source text, so that we don't have to - // retrieve it via `self.filemap.src.as_ref().unwrap()` all the time. + // retrieve it via `self.source_file.src.as_ref().unwrap()` all the time. src: Lrc<String>, /// Stack of open delimiters and their spans. Used for error message. token: token::Token, @@ -180,31 +180,31 @@ impl<'a> StringReader<'a> { } /// For comments.rs, which hackily pokes into next_pos and ch - fn new_raw(sess: &'a ParseSess, filemap: Lrc<syntax_pos::SourceFile>, override_span: Option<Span>) + fn new_raw(sess: &'a ParseSess, source_file: Lrc<syntax_pos::SourceFile>, override_span: Option<Span>) -> Self { - let mut sr = StringReader::new_raw_internal(sess, filemap, override_span); + let mut sr = StringReader::new_raw_internal(sess, source_file, override_span); sr.bump(); sr } - fn new_raw_internal(sess: &'a ParseSess, filemap: Lrc<syntax_pos::SourceFile>, + fn new_raw_internal(sess: &'a ParseSess, source_file: Lrc<syntax_pos::SourceFile>, override_span: Option<Span>) -> Self { - if filemap.src.is_none() { - sess.span_diagnostic.bug(&format!("Cannot lex filemap without source: {}", - filemap.name)); + if source_file.src.is_none() { + sess.span_diagnostic.bug(&format!("Cannot lex source_file without source: {}", + source_file.name)); } - let src = (*filemap.src.as_ref().unwrap()).clone(); + let src = (*source_file.src.as_ref().unwrap()).clone(); StringReader { sess, - next_pos: filemap.start_pos, - pos: filemap.start_pos, + next_pos: source_file.start_pos, + pos: source_file.start_pos, ch: Some('\n'), - filemap, + source_file, end_src_index: src.len(), // dummy values; not read peek_tok: token::Eof, @@ -221,10 +221,10 @@ impl<'a> StringReader<'a> { } } - pub fn new(sess: &'a ParseSess, filemap: Lrc<syntax_pos::SourceFile>, override_span: Option<Span>) + pub fn new(sess: &'a ParseSess, source_file: Lrc<syntax_pos::SourceFile>, override_span: Option<Span>) -> Self { - let mut sr = StringReader::new_raw(sess, filemap, override_span); + let mut sr = StringReader::new_raw(sess, source_file, override_span); if sr.advance_token().is_err() { sr.emit_fatal_errors(); FatalError.raise(); @@ -364,8 +364,8 @@ impl<'a> StringReader<'a> { if self.is_eof() { self.peek_tok = token::Eof; let (real, raw) = self.mk_sp_and_raw( - self.filemap.end_pos, - self.filemap.end_pos, + self.source_file.end_pos, + self.source_file.end_pos, ); self.peek_span = real; self.peek_span_src_raw = raw; @@ -384,7 +384,7 @@ impl<'a> StringReader<'a> { #[inline] fn src_index(&self, pos: BytePos) -> usize { - (pos - self.filemap.start_pos).to_usize() + (pos - self.source_file.start_pos).to_usize() } /// Calls `f` with a string slice of the source text spanning from `start` @@ -623,7 +623,7 @@ impl<'a> StringReader<'a> { // I guess this is the only way to figure out if // we're at the beginning of the file... let cmap = SourceMap::new(FilePathMapping::empty()); - cmap.files.borrow_mut().file_maps.push(self.filemap.clone()); + cmap.files.borrow_mut().file_maps.push(self.source_file.clone()); let loc = cmap.lookup_char_pos_adj(self.pos); debug!("Skipping a shebang"); if loc.line == 1 && loc.col == CharPos(0) { @@ -1861,7 +1861,7 @@ mod tests { sess: &'a ParseSess, teststr: String) -> StringReader<'a> { - let fm = cm.new_filemap(PathBuf::from("zebra.rs").into(), teststr); + let fm = cm.new_source_file(PathBuf::from("zebra.rs").into(), teststr); StringReader::new(sess, fm, None) } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 65bab94c6bc..07a9f44fe4a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -171,13 +171,13 @@ crate fn parse_stmt_from_source_str(name: FileName, source: String, sess: &Parse pub fn parse_stream_from_source_str(name: FileName, source: String, sess: &ParseSess, override_span: Option<Span>) -> TokenStream { - filemap_to_stream(sess, sess.codemap().new_filemap(name, source), override_span) + source_file_to_stream(sess, sess.codemap().new_source_file(name, source), override_span) } // Create a new parser from a source string pub fn new_parser_from_source_str(sess: &ParseSess, name: FileName, source: String) -> Parser { - let mut parser = filemap_to_parser(sess, sess.codemap().new_filemap(name, source)); + let mut parser = source_file_to_parser(sess, sess.codemap().new_source_file(name, source)); parser.recurse_into_file_modules = false; parser } @@ -185,7 +185,7 @@ pub fn new_parser_from_source_str(sess: &ParseSess, name: FileName, source: Stri /// Create a new parser, handling errors as appropriate /// if the file doesn't exist pub fn new_parser_from_file<'a>(sess: &'a ParseSess, path: &Path) -> Parser<'a> { - filemap_to_parser(sess, file_to_filemap(sess, path, None)) + source_file_to_parser(sess, file_to_source_file(sess, path, None)) } /// Given a session, a crate config, a path, and a span, add @@ -196,16 +196,16 @@ crate fn new_sub_parser_from_file<'a>(sess: &'a ParseSess, directory_ownership: DirectoryOwnership, module_name: Option<String>, sp: Span) -> Parser<'a> { - let mut p = filemap_to_parser(sess, file_to_filemap(sess, path, Some(sp))); + let mut p = source_file_to_parser(sess, file_to_source_file(sess, path, Some(sp))); p.directory.ownership = directory_ownership; p.root_module_name = module_name; p } -/// Given a filemap and config, return a parser -fn filemap_to_parser(sess: & ParseSess, filemap: Lrc<SourceFile>) -> Parser { - let end_pos = filemap.end_pos; - let mut parser = stream_to_parser(sess, filemap_to_stream(sess, filemap, None)); +/// Given a source_file and config, return a parser +fn source_file_to_parser(sess: & ParseSess, source_file: Lrc<SourceFile>) -> Parser { + let end_pos = source_file.end_pos; + let mut parser = stream_to_parser(sess, source_file_to_stream(sess, source_file, None)); if parser.token == token::Eof && parser.span.is_dummy() { parser.span = Span::new(end_pos, end_pos, parser.span.ctxt()); @@ -224,11 +224,11 @@ pub fn new_parser_from_tts(sess: &ParseSess, tts: Vec<TokenTree>) -> Parser { // base abstractions /// Given a session and a path and an optional span (for error reporting), -/// add the path to the session's codemap and return the new filemap. -fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>) +/// add the path to the session's codemap and return the new source_file. +fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option<Span>) -> Lrc<SourceFile> { match sess.codemap().load_file(path) { - Ok(filemap) => filemap, + Ok(source_file) => source_file, Err(e) => { let msg = format!("couldn't read {:?}: {}", path.display(), e); match spanopt { @@ -239,10 +239,10 @@ fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>) } } -/// Given a filemap, produce a sequence of token-trees -pub fn filemap_to_stream(sess: &ParseSess, filemap: Lrc<SourceFile>, override_span: Option<Span>) +/// Given a source_file, produce a sequence of token-trees +pub fn source_file_to_stream(sess: &ParseSess, source_file: Lrc<SourceFile>, override_span: Option<Span>) -> TokenStream { - let mut srdr = lexer::StringReader::new(sess, filemap, override_span); + let mut srdr = lexer::StringReader::new(sess, source_file, override_span); srdr.real_token(); panictry!(srdr.parse_all_token_trees()) } diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index 12f72a3979e..00dd79ffb00 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -51,7 +51,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: & let output = Arc::new(Mutex::new(Vec::new())); let code_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); - code_map.new_filemap(Path::new("test.rs").to_owned().into(), file_text.to_owned()); + code_map.new_source_file(Path::new("test.rs").to_owned().into(), file_text.to_owned()); let primary_span = make_span(&file_text, &span_labels[0].start, &span_labels[0].end); let mut msp = MultiSpan::from_span(primary_span); diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index 46b7f2d7bda..35dae1a4e67 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -10,7 +10,7 @@ use ast::{self, Ident}; use codemap::FilePathMapping; -use parse::{ParseSess, PResult, filemap_to_stream}; +use parse::{ParseSess, PResult, source_file_to_stream}; use parse::{lexer, new_parser_from_source_str}; use parse::parser::Parser; use ptr::P; @@ -21,8 +21,8 @@ use std::path::PathBuf; /// Map a string to tts, using a made-up filename: pub fn string_to_stream(source_str: String) -> TokenStream { let ps = ParseSess::new(FilePathMapping::empty()); - filemap_to_stream(&ps, ps.codemap() - .new_filemap(PathBuf::from("bogofile").into(), source_str), None) + source_file_to_stream(&ps, ps.codemap() + .new_source_file(PathBuf::from("bogofile").into(), source_str), None) } /// Map string to parser (via tts) |
