diff options
| author | bors <bors@rust-lang.org> | 2018-08-19 23:08:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-08-19 23:08:26 +0000 |
| commit | 6bf6d50a6ff7685b4aa09172d9d09f03f250da9d (patch) | |
| tree | 45b651039eb9347abbb53fff215e936c402653a9 /src/libsyntax | |
| parent | f28f648a9699db67b86735f97d609c3dd06f9ded (diff) | |
| parent | 6138c82803a77a44e0a56cd8999299fa7f214afe (diff) | |
| download | rust-6bf6d50a6ff7685b4aa09172d9d09f03f250da9d.tar.gz rust-6bf6d50a6ff7685b4aa09172d9d09f03f250da9d.zip | |
Auto merge of #52953 - dsciarra:mv-codemap-sourcemap, r=petrochenkov
Rename CodeMap/FileMap to SourceMap/SourceFile A first renaming for #51574
Diffstat (limited to 'src/libsyntax')
27 files changed, 271 insertions, 268 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e53f3ea9036..ec6ac86ba6b 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -16,7 +16,7 @@ pub use symbol::{Ident, Symbol as Name}; pub use util::parser::ExprPrecedence; use syntax_pos::{Span, DUMMY_SP}; -use codemap::{dummy_spanned, respan, Spanned}; +use source_map::{dummy_spanned, respan, Spanned}; use rustc_target::spec::abi::Abi; use ext::hygiene::{Mark, SyntaxContext}; use print::pprust; diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs index 5857bd282f0..cd9d7682210 100644 --- a/src/libsyntax/attr/mod.rs +++ b/src/libsyntax/attr/mod.rs @@ -25,7 +25,7 @@ use ast; use ast::{AttrId, Attribute, AttrStyle, Name, Ident, Path, PathSegment}; use ast::{MetaItem, MetaItemKind, NestedMetaItem, NestedMetaItemKind}; use ast::{Lit, LitKind, Expr, ExprKind, Item, Local, Stmt, StmtKind, GenericParam}; -use codemap::{BytePos, Spanned, respan, dummy_spanned}; +use source_map::{BytePos, Spanned, respan, dummy_spanned}; use syntax_pos::{FileName, Span}; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use parse::parser::Parser; diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index b4e35a9d564..0e52434ec01 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -12,7 +12,7 @@ use attr::HasAttrs; use feature_gate::{feature_err, EXPLAIN_STMT_ATTR_SYNTAX, Features, get_features, GateIssue}; use {fold, attr}; use ast; -use codemap::Spanned; +use source_map::Spanned; use edition::Edition; use parse::{token, ParseSess}; use OneVector; diff --git a/src/libsyntax/diagnostics/metadata.rs b/src/libsyntax/diagnostics/metadata.rs index 61b0579a3e7..1438299d375 100644 --- a/src/libsyntax/diagnostics/metadata.rs +++ b/src/libsyntax/diagnostics/metadata.rs @@ -45,7 +45,7 @@ pub struct ErrorLocation { impl ErrorLocation { /// Create an error location from a span. pub fn from_span(ecx: &ExtCtxt, sp: Span) -> ErrorLocation { - let loc = ecx.codemap().lookup_char_pos_adj(sp.lo()); + let loc = ecx.source_map().lookup_char_pos_adj(sp.lo()); ErrorLocation { filename: loc.filename, line: loc.line diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 6a5a2a5e500..d044efa3c38 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -13,7 +13,7 @@ use std::env; use ast; use ast::{Ident, Name}; -use codemap; +use source_map; use syntax_pos::Span; use ext::base::{ExtCtxt, MacEager, MacResult}; use ext::build::AstBuilder; @@ -223,7 +223,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, ty, expr, ), - vis: codemap::respan(span.shrink_to_lo(), ast::VisibilityKind::Public), + vis: source_map::respan(span.shrink_to_lo(), ast::VisibilityKind::Public), span, tokens: None, }) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 482d8c2cf98..154fe11dd35 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -12,7 +12,7 @@ pub use self::SyntaxExtension::*; use ast::{self, Attribute, Name, PatKind, MetaItem}; use attr::HasAttrs; -use codemap::{self, CodeMap, Spanned, respan}; +use source_map::{self, SourceMap, Spanned, respan}; use syntax_pos::{Span, MultiSpan, DUMMY_SP}; use edition::Edition; use errors::{DiagnosticBuilder, DiagnosticId}; @@ -481,7 +481,7 @@ impl DummyResult { pub fn raw_expr(sp: Span) -> P<ast::Expr> { P(ast::Expr { id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Lit(P(codemap::respan(sp, ast::LitKind::Bool(false)))), + node: ast::ExprKind::Lit(P(source_map::respan(sp, ast::LitKind::Bool(false)))), span: sp, attrs: ThinVec::new(), }) @@ -836,7 +836,7 @@ impl<'a> ExtCtxt<'a> { pub fn new_parser_from_tts(&self, tts: &[tokenstream::TokenTree]) -> parser::Parser<'a> { parse::stream_to_parser(self.parse_sess, tts.iter().cloned().collect()) } - pub fn codemap(&self) -> &'a CodeMap { self.parse_sess.codemap() } + pub fn source_map(&self) -> &'a SourceMap { self.parse_sess.source_map() } pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess } pub fn cfg(&self) -> &ast::CrateConfig { &self.parse_sess.config } pub fn call_site(&self) -> Span { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 1a17aa3e8fb..b1bed9602f3 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -12,7 +12,7 @@ use rustc_target::spec::abi::Abi; use ast::{self, Ident, Generics, Expr, BlockCheckMode, UnOp, PatKind}; use attr; use syntax_pos::{Pos, Span, DUMMY_SP}; -use codemap::{dummy_spanned, respan, Spanned}; +use source_map::{dummy_spanned, respan, Spanned}; use ext::base::ExtCtxt; use ptr::P; use symbol::{Symbol, keywords}; @@ -764,7 +764,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { } fn expr_fail(&self, span: Span, msg: Symbol) -> P<ast::Expr> { - let loc = self.codemap().lookup_char_pos(span.lo()); + let loc = self.source_map().lookup_char_pos(span.lo()); let expr_file = self.expr_str(span, Symbol::intern(&loc.file.name.to_string())); let expr_line = self.expr_u32(span, loc.line as u32); let expr_col = self.expr_u32(span, loc.col.to_usize() as u32 + 1); diff --git a/src/libsyntax/ext/derive.rs b/src/libsyntax/ext/derive.rs index 32ace937ac0..80bbc618932 100644 --- a/src/libsyntax/ext/derive.rs +++ b/src/libsyntax/ext/derive.rs @@ -10,7 +10,7 @@ use attr::HasAttrs; use ast; -use codemap::{hygiene, ExpnInfo, ExpnFormat}; +use source_map::{hygiene, ExpnInfo, ExpnFormat}; use ext::base::ExtCtxt; use ext::build::AstBuilder; use parse::parser::PathStyle; diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index ffa2730d686..b12b2c49caa 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -11,7 +11,7 @@ use ast::{self, Block, Ident, NodeId, PatKind, Path}; use ast::{MacStmtStyle, StmtKind, ItemKind}; use attr::{self, HasAttrs}; -use codemap::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan}; +use source_map::{ExpnInfo, MacroBang, MacroAttribute, dummy_spanned, respan}; use config::{is_test_or_bench, StripUnconfigured}; use errors::{Applicability, FatalError}; use ext::base::*; @@ -267,7 +267,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { pub fn expand_crate(&mut self, mut krate: ast::Crate) -> ast::Crate { let mut module = ModuleData { mod_path: vec![Ident::from_str(&self.cx.ecfg.crate_name)], - directory: match self.cx.codemap().span_to_unmapped_path(krate.span) { + directory: match self.cx.source_map().span_to_unmapped_path(krate.span) { FileName::Real(path) => path, other => PathBuf::from(other.to_string()), }, @@ -1355,7 +1355,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> { module.directory.push(&*item.ident.as_str()); } } else { - let path = self.cx.parse_sess.codemap().span_to_unmapped_path(inner); + let path = self.cx.parse_sess.source_map().span_to_unmapped_path(inner); let mut path = match path { FileName::Real(path) => path, other => PathBuf::from(other.to_string()), @@ -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.source_map().new_source_file(filename.into(), src); let include_info = vec![ dummy_spanned(ast::NestedMetaItemKind::MetaItem( diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 1dc9bae8848..18b4119fde8 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast::{self, NodeId}; -use codemap::{DUMMY_SP, dummy_spanned}; +use source_map::{DUMMY_SP, dummy_spanned}; use ext::base::ExtCtxt; use ext::expand::{AstFragment, AstFragmentKind}; use ext::hygiene::Mark; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index bc891700fc1..13a139deea4 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -9,7 +9,7 @@ // except according to those terms. use ast::{self, Arg, Arm, Block, Expr, Item, Pat, Stmt, Ty}; -use codemap::respan; +use source_map::respan; use syntax_pos::Span; use ext::base::ExtCtxt; use ext::base; @@ -28,7 +28,7 @@ use tokenstream::{TokenStream, TokenTree}; pub mod rt { use ast; - use codemap::Spanned; + use source_map::Spanned; use ext::base::ExtCtxt; use parse::{self, classify}; use parse::token::{self, Token}; @@ -40,7 +40,7 @@ pub mod rt { pub use parse::new_parser_from_tts; pub use syntax_pos::{BytePos, Span, DUMMY_SP, FileName}; - pub use codemap::{dummy_spanned}; + pub use source_map::{dummy_spanned}; pub trait ToTokens { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree>; @@ -802,7 +802,7 @@ fn mk_stmts_let(cx: &ExtCtxt, sp: Span) -> Vec<ast::Stmt> { // they happen to have a compiler on hand). Over all, the phase distinction // just makes quotes "hard to attribute". Possibly this could be fixed // by recreating some of the original qq machinery in the tt regime - // (pushing fake FileMaps onto the parser to account for original sites + // (pushing fake SourceFiles onto the parser to account for original sites // of quotes, for example) but at this point it seems not likely to be // worth the hassle. diff --git a/src/libsyntax/ext/source_util.rs b/src/libsyntax/ext/source_util.rs index 9b7e0fe1ae5..19a204cc989 100644 --- a/src/libsyntax/ext/source_util.rs +++ b/src/libsyntax/ext/source_util.rs @@ -36,7 +36,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) base::check_zero_tts(cx, sp, tts, "line!"); let topmost = cx.expansion_cause().unwrap_or(sp); - let loc = cx.codemap().lookup_char_pos(topmost.lo()); + let loc = cx.source_map().lookup_char_pos(topmost.lo()); base::MacEager::expr(cx.expr_u32(topmost, loc.line as u32)) } @@ -47,7 +47,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[tokenstream::TokenTree]) base::check_zero_tts(cx, sp, tts, "column!"); let topmost = cx.expansion_cause().unwrap_or(sp); - let loc = cx.codemap().lookup_char_pos(topmost.lo()); + let loc = cx.source_map().lookup_char_pos(topmost.lo()); base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1)) } @@ -63,14 +63,14 @@ 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> { base::check_zero_tts(cx, sp, tts, "file!"); let topmost = cx.expansion_cause().unwrap_or(sp); - let loc = cx.codemap().lookup_char_pos(topmost.lo()); + let loc = cx.source_map().lookup_char_pos(topmost.lo()); base::MacEager::expr(cx.expr_str(topmost, Symbol::intern(&loc.file.name.to_string()))) } @@ -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.source_map().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.source_map().new_source_file(file.into(), "".to_string()); base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) } @@ -199,7 +199,7 @@ fn res_rel_file(cx: &mut ExtCtxt, sp: syntax_pos::Span, arg: String) -> PathBuf // after macro expansion (that is, they are unhygienic). if !arg.is_absolute() { let callsite = sp.source_callsite(); - let mut path = match cx.codemap().span_to_unmapped_path(callsite) { + let mut path = match cx.source_map().span_to_unmapped_path(callsite) { FileName::Real(path) => path, other => panic!("cannot resolve relative path in non-file source `{}`", other), }; diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e8245a553eb..74f573fceba 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -29,7 +29,7 @@ use rustc_data_structures::fx::FxHashMap; use rustc_target::spec::abi::Abi; use ast::{self, NodeId, PatKind, RangeEnd}; use attr; -use codemap::Spanned; +use source_map::Spanned; use edition::{ALL_EDITIONS, Edition}; use syntax_pos::{Span, DUMMY_SP}; use errors::{DiagnosticBuilder, Handler}; @@ -1556,7 +1556,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if !name.as_str().is_ascii() { gate_feature_post!(&self, non_ascii_idents, - self.context.parse_sess.codemap().def_span(sp), + self.context.parse_sess.source_map().def_span(sp), "non-ascii idents are not fully supported."); } } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 3209939d9b1..50a49e2f548 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -21,7 +21,7 @@ use ast::*; use ast; use syntax_pos::Span; -use codemap::{Spanned, respan}; +use source_map::{Spanned, respan}; use parse::token::{self, Token}; use ptr::P; use OneVector; diff --git a/src/libsyntax/json.rs b/src/libsyntax/json.rs index 65de1503966..b0cf29e9f63 100644 --- a/src/libsyntax/json.rs +++ b/src/libsyntax/json.rs @@ -19,10 +19,10 @@ // FIXME spec the JSON output properly. -use codemap::{CodeMap, FilePathMapping}; +use source_map::{SourceMap, FilePathMapping}; use syntax_pos::{self, MacroBacktrace, Span, SpanLabel, MultiSpan}; use errors::registry::Registry; -use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, CodeMapper}; +use errors::{DiagnosticBuilder, SubDiagnostic, CodeSuggestion, SourceMapper}; use errors::{DiagnosticId, Applicability}; use errors::emitter::{Emitter, EmitterWriter}; @@ -36,14 +36,14 @@ use rustc_serialize::json::{as_json, as_pretty_json}; pub struct JsonEmitter { dst: Box<dyn Write + Send>, registry: Option<Registry>, - cm: Lrc<dyn CodeMapper + sync::Send + sync::Sync>, + cm: Lrc<dyn SourceMapper + sync::Send + sync::Sync>, pretty: bool, ui_testing: bool, } impl JsonEmitter { pub fn stderr(registry: Option<Registry>, - code_map: Lrc<CodeMap>, + code_map: Lrc<SourceMap>, pretty: bool) -> JsonEmitter { JsonEmitter { dst: Box::new(io::stderr()), @@ -56,13 +56,13 @@ impl JsonEmitter { pub fn basic(pretty: bool) -> JsonEmitter { let file_path_mapping = FilePathMapping::empty(); - JsonEmitter::stderr(None, Lrc::new(CodeMap::new(file_path_mapping)), + JsonEmitter::stderr(None, Lrc::new(SourceMap::new(file_path_mapping)), pretty) } pub fn new(dst: Box<dyn Write + Send>, registry: Option<Registry>, - code_map: Lrc<CodeMap>, + code_map: Lrc<SourceMap>, pretty: bool) -> JsonEmitter { JsonEmitter { dst, @@ -340,7 +340,7 @@ impl DiagnosticSpan { } impl DiagnosticSpanLine { - fn line_from_filemap(fm: &syntax_pos::FileMap, + 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/lib.rs b/src/libsyntax/lib.rs index 0a42325d2b6..289f023cefa 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -145,7 +145,7 @@ pub mod syntax { pub mod ast; pub mod attr; -pub mod codemap; +pub mod source_map; #[macro_use] pub mod config; pub mod entry; diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index b0136c3e18b..a240604bfe0 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -10,7 +10,7 @@ use attr; use ast; -use codemap::respan; +use source_map::respan; use parse::{SeqSep, PResult}; use parse::token::{self, Nonterminal, DelimToken}; use parse::parser::{Parser, TokenType, PathStyle}; diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 2c53dbdc402..dde0466f43c 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -11,7 +11,7 @@ pub use self::CommentStyle::*; use ast; -use codemap::CodeMap; +use source_map::SourceMap; use syntax_pos::{BytePos, CharPos, Pos, FileName}; use parse::lexer::{is_block_doc_comment, is_pattern_whitespace}; use parse::lexer::{self, ParseSess, StringReader, TokenAndSpan}; @@ -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 { @@ -371,9 +371,9 @@ 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 = CodeMap::new(sess.codemap().path_mapping().clone()); - let filemap = cm.new_filemap(path, src); - let mut rdr = lexer::StringReader::new_raw(sess, filemap, None); + let cm = SourceMap::new(sess.source_map().path_mapping().clone()); + 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 bdf25618f47..448ff9676c9 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -10,7 +10,7 @@ use ast::{self, Ident}; use syntax_pos::{self, BytePos, CharPos, Pos, Span, NO_EXPANSION}; -use codemap::{CodeMap, FilePathMapping}; +use source_map::{SourceMap, FilePathMapping}; use errors::{Applicability, FatalError, DiagnosticBuilder}; use parse::{token, ParseSess}; use str::char_at; @@ -43,13 +43,13 @@ impl Default for TokenAndSpan { pub struct StringReader<'a> { pub sess: &'a ParseSess, - /// The absolute offset within the codemap of the next character to read + /// The absolute offset within the source_map of the next character to read pub next_pos: BytePos, - /// The absolute offset within the codemap of the current character + /// The absolute offset within the source_map of the current character pub pos: BytePos, /// The current character (which has been read from self.pos) pub ch: Option<char>, - pub filemap: Lrc<syntax_pos::FileMap>, + 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::FileMap>, override_span: Option<Span>) - -> Self - { - let mut sr = StringReader::new_raw_internal(sess, filemap, override_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, source_file, override_span); sr.bump(); sr } - fn new_raw_internal(sess: &'a ParseSess, filemap: Lrc<syntax_pos::FileMap>, + 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::FileMap>, override_span: Option<Span>) - -> Self - { - let mut sr = StringReader::new_raw(sess, filemap, override_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, source_file, override_span); if sr.advance_token().is_err() { sr.emit_fatal_errors(); FatalError.raise(); @@ -234,8 +234,8 @@ impl<'a> StringReader<'a> { } pub fn retokenize(sess: &'a ParseSess, mut span: Span) -> Self { - let begin = sess.codemap().lookup_byte_offset(span.lo()); - let end = sess.codemap().lookup_byte_offset(span.hi()); + let begin = sess.source_map().lookup_byte_offset(span.lo()); + let end = sess.source_map().lookup_byte_offset(span.hi()); // Make the range zero-length if the span is invalid. if span.lo() > span.hi() || begin.fm.start_pos != end.fm.start_pos { @@ -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` @@ -468,7 +468,7 @@ impl<'a> StringReader<'a> { } /// Advance the StringReader by one character. If a newline is - /// discovered, add it to the FileMap's list of line start offsets. + /// discovered, add it to the SourceFile's list of line start offsets. crate fn bump(&mut self) { let next_src_index = self.src_index(self.next_pos); if next_src_index < self.end_src_index { @@ -622,8 +622,8 @@ 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 = CodeMap::new(FilePathMapping::empty()); - cmap.files.borrow_mut().file_maps.push(self.filemap.clone()); + let cmap = SourceMap::new(FilePathMapping::empty()); + 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) { @@ -1827,7 +1827,7 @@ mod tests { use ast::{Ident, CrateConfig}; use symbol::Symbol; use syntax_pos::{BytePos, Span, NO_EXPANSION}; - use codemap::CodeMap; + use source_map::SourceMap; use errors; use feature_gate::UnstableFeatures; use parse::token; @@ -1837,7 +1837,7 @@ mod tests { use diagnostics::plugin::ErrorMap; use rustc_data_structures::sync::Lock; use with_globals; - fn mk_sess(cm: Lrc<CodeMap>) -> ParseSess { + fn mk_sess(cm: Lrc<SourceMap>) -> ParseSess { let emitter = errors::emitter::EmitterWriter::new(Box::new(io::sink()), Some(cm.clone()), false, @@ -1857,18 +1857,18 @@ mod tests { } // open a string reader for the given string - fn setup<'a>(cm: &CodeMap, + fn setup<'a>(cm: &SourceMap, 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) } #[test] fn t1() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); let mut string_reader = setup(&cm, &sh, @@ -1916,7 +1916,7 @@ mod tests { #[test] fn doublecolonparsing() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); check_tokenization(setup(&cm, &sh, "a b".to_string()), vec![mk_ident("a"), token::Whitespace, mk_ident("b")]); @@ -1926,7 +1926,7 @@ mod tests { #[test] fn dcparsing_2() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); check_tokenization(setup(&cm, &sh, "a::b".to_string()), vec![mk_ident("a"), token::ModSep, mk_ident("b")]); @@ -1936,7 +1936,7 @@ mod tests { #[test] fn dcparsing_3() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); check_tokenization(setup(&cm, &sh, "a ::b".to_string()), vec![mk_ident("a"), token::Whitespace, token::ModSep, mk_ident("b")]); @@ -1946,7 +1946,7 @@ mod tests { #[test] fn dcparsing_4() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); check_tokenization(setup(&cm, &sh, "a:: b".to_string()), vec![mk_ident("a"), token::ModSep, token::Whitespace, mk_ident("b")]); @@ -1956,7 +1956,7 @@ mod tests { #[test] fn character_a() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); assert_eq!(setup(&cm, &sh, "'a'".to_string()).next_token().tok, token::Literal(token::Char(Symbol::intern("a")), None)); @@ -1966,7 +1966,7 @@ mod tests { #[test] fn character_space() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); assert_eq!(setup(&cm, &sh, "' '".to_string()).next_token().tok, token::Literal(token::Char(Symbol::intern(" ")), None)); @@ -1976,7 +1976,7 @@ mod tests { #[test] fn character_escaped() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); assert_eq!(setup(&cm, &sh, "'\\n'".to_string()).next_token().tok, token::Literal(token::Char(Symbol::intern("\\n")), None)); @@ -1986,7 +1986,7 @@ mod tests { #[test] fn lifetime_name() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); assert_eq!(setup(&cm, &sh, "'abc".to_string()).next_token().tok, token::Lifetime(Ident::from_str("'abc"))); @@ -1996,7 +1996,7 @@ mod tests { #[test] fn raw_string() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); assert_eq!(setup(&cm, &sh, "r###\"\"#a\\b\x00c\"\"###".to_string()) .next_token() @@ -2008,7 +2008,7 @@ mod tests { #[test] fn literal_suffixes() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); macro_rules! test { ($input: expr, $tok_type: ident, $tok_contents: expr) => {{ @@ -2054,7 +2054,7 @@ mod tests { #[test] fn nested_block_comments() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); let mut lexer = setup(&cm, &sh, "/* /* */ */'a'".to_string()); match lexer.next_token().tok { @@ -2069,7 +2069,7 @@ mod tests { #[test] fn crlf_comments() { with_globals(|| { - let cm = Lrc::new(CodeMap::new(FilePathMapping::empty())); + let cm = Lrc::new(SourceMap::new(FilePathMapping::empty())); let sh = mk_sess(cm.clone()); let mut lexer = setup(&cm, &sh, "// test\r\n/// test\r\n".to_string()); let comment = lexer.next_token(); diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index d029509f0c1..adf01197c6d 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -13,8 +13,8 @@ use rustc_data_structures::sync::{Lrc, Lock}; use ast::{self, CrateConfig, NodeId}; use early_buffered_lints::{BufferedEarlyLint, BufferedEarlyLintId}; -use codemap::{CodeMap, FilePathMapping}; -use syntax_pos::{Span, FileMap, FileName, MultiSpan}; +use source_map::{SourceMap, FilePathMapping}; +use syntax_pos::{Span, SourceFile, FileName, MultiSpan}; use errors::{Handler, ColorConfig, DiagnosticBuilder}; use feature_gate::UnstableFeatures; use parse::parser::Parser; @@ -57,13 +57,13 @@ pub struct ParseSess { pub non_modrs_mods: Lock<Vec<(ast::Ident, Span)>>, /// Used to determine and report recursive mod inclusions included_mod_stack: Lock<Vec<PathBuf>>, - code_map: Lrc<CodeMap>, + code_map: Lrc<SourceMap>, pub buffered_lints: Lock<Vec<BufferedEarlyLint>>, } impl ParseSess { pub fn new(file_path_mapping: FilePathMapping) -> Self { - let cm = Lrc::new(CodeMap::new(file_path_mapping)); + let cm = Lrc::new(SourceMap::new(file_path_mapping)); let handler = Handler::with_tty_emitter(ColorConfig::Auto, true, false, @@ -71,7 +71,7 @@ impl ParseSess { ParseSess::with_span_handler(handler, cm) } - pub fn with_span_handler(handler: Handler, code_map: Lrc<CodeMap>) -> ParseSess { + pub fn with_span_handler(handler: Handler, code_map: Lrc<SourceMap>) -> ParseSess { ParseSess { span_diagnostic: handler, unstable_features: UnstableFeatures::from_environment(), @@ -86,7 +86,7 @@ impl ParseSess { } } - pub fn codemap(&self) -> &CodeMap { + pub fn source_map(&self) -> &SourceMap { &self.code_map } @@ -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.source_map().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.source_map().new_source_file(name, source)); parser.recurse_into_file_modules = false; parser } @@ -185,27 +185,27 @@ 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 -/// the file at the given path to the codemap, and return a parser. +/// the file at the given path to the source_map, and return a parser. /// On an error, use the given span as the source of the problem. crate fn new_sub_parser_from_file<'a>(sess: &'a ParseSess, path: &Path, 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<FileMap>) -> 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>) - -> Lrc<FileMap> { - match sess.codemap().load_file(path) { - Ok(filemap) => filemap, +/// add the path to the session's source_map and return the new source_file. +fn file_to_source_file(sess: &ParseSess, path: &Path, spanopt: Option<Span>) + -> Lrc<SourceFile> { + match sess.source_map().load_file(path) { + Ok(source_file) => source_file, Err(e) => { let msg = format!("couldn't read {:?}: {}", path.display(), e); match spanopt { @@ -239,10 +239,11 @@ 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<FileMap>, override_span: Option<Span>) - -> TokenStream { - let mut srdr = lexer::StringReader::new(sess, filemap, override_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, source_file, override_span); srdr.real_token(); panictry!(srdr.parse_all_token_trees()) } @@ -969,7 +970,7 @@ mod tests { let span = tts.iter().rev().next().unwrap().span(); - match sess.codemap().span_to_snippet(span) { + match sess.source_map().span_to_snippet(span) { Ok(s) => assert_eq!(&s[..], "{ body }"), Err(_) => panic!("could not get snippet"), } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 345464c6664..b1e2e69863d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -42,7 +42,7 @@ use ast::{UseTree, UseTreeKind}; use ast::{BinOpKind, UnOp}; use ast::{RangeEnd, RangeSyntax}; use {ast, attr}; -use codemap::{self, CodeMap, Spanned, respan}; +use source_map::{self, SourceMap, Spanned, respan}; use syntax_pos::{self, Span, MultiSpan, BytePos, FileName, edition::Edition}; use errors::{self, Applicability, DiagnosticBuilder, DiagnosticId}; use parse::{self, SeqSep, classify, token}; @@ -577,7 +577,7 @@ impl<'a> Parser<'a> { if let Some(directory) = directory { parser.directory = directory; } else if !parser.span.is_dummy() { - if let FileName::Real(mut path) = sess.codemap().span_to_unmapped_path(parser.span) { + if let FileName::Real(mut path) = sess.source_map().span_to_unmapped_path(parser.span) { path.pop(); parser.directory.path = Cow::from(path); } @@ -652,10 +652,10 @@ impl<'a> Parser<'a> { // EOF, don't want to point at the following char, but rather the last token self.prev_span } else { - self.sess.codemap().next_point(self.prev_span) + self.sess.source_map().next_point(self.prev_span) }; let label_exp = format!("expected `{}`", token_str); - let cm = self.sess.codemap(); + let cm = self.sess.source_map(); match (cm.lookup_line(self.span.lo()), cm.lookup_line(sp.lo())) { (Ok(ref a), Ok(ref b)) if a.line == b.line => { // When the spans are in the same line, it means that the only content @@ -720,14 +720,14 @@ impl<'a> Parser<'a> { expect.clone() }; (format!("expected one of {}, found `{}`", expect, actual), - (self.sess.codemap().next_point(self.prev_span), + (self.sess.source_map().next_point(self.prev_span), format!("expected one of {} here", short_expect))) } else if expected.is_empty() { (format!("unexpected token: `{}`", actual), (self.prev_span, "unexpected token after this".to_string())) } else { (format!("expected {}, found `{}`", expect, actual), - (self.sess.codemap().next_point(self.prev_span), + (self.sess.source_map().next_point(self.prev_span), format!("expected {} here", expect))) }; let mut err = self.fatal(&msg_exp); @@ -738,7 +738,7 @@ impl<'a> Parser<'a> { label_sp }; - let cm = self.sess.codemap(); + let cm = self.sess.source_map(); match (cm.lookup_line(self.span.lo()), cm.lookup_line(sp.lo())) { (Ok(ref a), Ok(ref b)) if a.line == b.line => { // When the spans are in the same line, it means that the only content between @@ -1879,7 +1879,7 @@ impl<'a> Parser<'a> { let lit = self.parse_lit_token()?; lit }; - Ok(codemap::Spanned { node: lit, span: lo.to(self.prev_span) }) + Ok(source_map::Spanned { node: lit, span: lo.to(self.prev_span) }) } /// matches '-' lit | lit (cf. ast_validation::AstValidator::check_expr_within_pat) @@ -2185,7 +2185,7 @@ impl<'a> Parser<'a> { pub fn mk_mac_expr(&mut self, span: Span, m: Mac_, attrs: ThinVec<Attribute>) -> P<Expr> { P(Expr { id: ast::DUMMY_NODE_ID, - node: ExprKind::Mac(codemap::Spanned {node: m, span: span}), + node: ExprKind::Mac(source_map::Spanned {node: m, span: span}), span, attrs, }) @@ -2902,7 +2902,7 @@ impl<'a> Parser<'a> { self.this_token_descr())); // span the `not` plus trailing whitespace to avoid // trailing whitespace after the `!` in our suggestion - let to_replace = self.sess.codemap() + let to_replace = self.sess.source_map() .span_until_non_whitespace(lo.to(self.span)); err.span_suggestion_short_with_applicability( to_replace, @@ -3000,7 +3000,7 @@ impl<'a> Parser<'a> { Err(mut err) => { err.span_label(self.span, "expecting a type here because of type ascription"); - let cm = self.sess.codemap(); + let cm = self.sess.source_map(); let cur_pos = cm.lookup_char_pos(self.span.lo()); let op_pos = cm.lookup_char_pos(cur_op_span.hi()); if cur_pos.line != op_pos.line { @@ -3074,7 +3074,7 @@ impl<'a> Parser<'a> { AssocOp::Equal | AssocOp::Less | AssocOp::LessEqual | AssocOp::NotEqual | AssocOp::Greater | AssocOp::GreaterEqual => { let ast_op = op.to_ast_binop().unwrap(); - let binary = self.mk_binary(codemap::respan(cur_op_span, ast_op), lhs, rhs); + let binary = self.mk_binary(source_map::respan(cur_op_span, ast_op), lhs, rhs); self.mk_expr(span, binary, ThinVec::new()) } AssocOp::Assign => @@ -3094,7 +3094,7 @@ impl<'a> Parser<'a> { token::Shl => BinOpKind::Shl, token::Shr => BinOpKind::Shr, }; - let aopexpr = self.mk_assign_op(codemap::respan(cur_op_span, aop), lhs, rhs); + let aopexpr = self.mk_assign_op(source_map::respan(cur_op_span, aop), lhs, rhs); self.mk_expr(span, aopexpr, ThinVec::new()) } AssocOp::As | AssocOp::Colon | AssocOp::DotDot | AssocOp::DotDotEq => { @@ -3161,7 +3161,7 @@ impl<'a> Parser<'a> { id: ast::DUMMY_NODE_ID })); - let expr_str = self.sess.codemap().span_to_snippet(expr.span) + let expr_str = self.sess.source_map().span_to_snippet(expr.span) .unwrap_or(pprust::expr_to_string(&expr)); err.span_suggestion_with_applicability( expr.span, @@ -3277,7 +3277,7 @@ impl<'a> Parser<'a> { // return. This won't catch blocks with an explicit `return`, but that would be caught by // the dead code lint. if self.eat_keyword(keywords::Else) || !cond.returns() { - let sp = self.sess.codemap().next_point(lo); + let sp = self.sess.source_map().next_point(lo); let mut err = self.diagnostic() .struct_span_err(sp, "missing condition for `if` statemement"); err.span_label(sp, "expected if condition here"); @@ -3527,7 +3527,7 @@ impl<'a> Parser<'a> { && self.token != token::CloseDelim(token::Brace); if require_comma { - let cm = self.sess.codemap(); + let cm = self.sess.source_map(); self.expect_one_of(&[token::Comma], &[token::CloseDelim(token::Brace)]) .map_err(|mut err| { match (cm.span_to_lines(expr.span), cm.span_to_lines(arm_start_span)) { @@ -3736,7 +3736,7 @@ impl<'a> Parser<'a> { &mut self, lo: Span, attrs: Vec<Attribute> - ) -> PResult<'a, codemap::Spanned<ast::FieldPat>> { + ) -> PResult<'a, source_map::Spanned<ast::FieldPat>> { // Check if a colon exists one ahead. This means we're parsing a fieldname. let hi; let (subpat, fieldname, is_shorthand) = if self.look_ahead(1, |t| t == &token::Colon) { @@ -3779,7 +3779,7 @@ impl<'a> Parser<'a> { (subpat, fieldname, true) }; - Ok(codemap::Spanned { + Ok(source_map::Spanned { span: lo.to(hi), node: ast::FieldPat { ident: fieldname, @@ -3791,7 +3791,7 @@ impl<'a> Parser<'a> { } /// Parse the fields of a struct-like pattern - fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<codemap::Spanned<ast::FieldPat>>, bool)> { + fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<source_map::Spanned<ast::FieldPat>>, bool)> { let mut fields = Vec::new(); let mut etc = false; let mut ate_comma = true; @@ -3837,7 +3837,7 @@ impl<'a> Parser<'a> { err.span_label(self.span, "expected `}`"); let mut comma_sp = None; if self.token == token::Comma { // Issue #49257 - etc_sp = etc_sp.to(self.sess.codemap().span_until_non_whitespace(self.span)); + etc_sp = etc_sp.to(self.sess.source_map().span_until_non_whitespace(self.span)); err.span_label(etc_sp, "`..` must be at the end and cannot have a trailing comma"); comma_sp = Some(self.span); @@ -3955,7 +3955,7 @@ impl<'a> Parser<'a> { let seq_span = pat.span.to(self.prev_span); let mut err = self.struct_span_err(comma_span, "unexpected `,` in pattern"); - if let Ok(seq_snippet) = self.sess.codemap().span_to_snippet(seq_span) { + if let Ok(seq_snippet) = self.sess.source_map().span_to_snippet(seq_span) { err.span_suggestion_with_applicability( seq_span, "try adding parentheses", @@ -4220,7 +4220,7 @@ impl<'a> Parser<'a> { let parser_snapshot_after_type = self.clone(); mem::replace(self, parser_snapshot_before_type); - let snippet = self.sess.codemap().span_to_snippet(pat.span).unwrap(); + let snippet = self.sess.source_map().span_to_snippet(pat.span).unwrap(); err.span_label(pat.span, format!("while parsing the type for `{}`", snippet)); (Some((parser_snapshot_after_type, colon_sp, err)), None) } @@ -4518,7 +4518,7 @@ impl<'a> Parser<'a> { } } else if let Some(macro_def) = self.eat_macro_def( &attrs, - &codemap::respan(lo, VisibilityKind::Inherited), + &source_map::respan(lo, VisibilityKind::Inherited), lo, )? { Stmt { @@ -5398,7 +5398,7 @@ impl<'a> Parser<'a> { _ => return Ok(None), }; - let eself = codemap::respan(eself_lo.to(eself_hi), eself); + let eself = source_map::respan(eself_lo.to(eself_hi), eself); Ok(Some(Arg::from_self(eself, eself_ident))) } @@ -6039,7 +6039,7 @@ impl<'a> Parser<'a> { err.emit(); } else { if seen_comma == false { - let sp = self.sess.codemap().next_point(previous_span); + let sp = self.sess.source_map().next_point(previous_span); err.span_suggestion_with_applicability( sp, "missing comma here", @@ -6051,7 +6051,7 @@ impl<'a> Parser<'a> { } } _ => { - let sp = self.sess.codemap().next_point(self.prev_span); + let sp = self.sess.source_map().next_point(self.prev_span); let mut err = self.struct_span_err(sp, &format!("expected `,`, or `}}`, found `{}`", self.this_token_to_string())); if self.token.is_ident() { @@ -6322,7 +6322,7 @@ impl<'a> Parser<'a> { id: ast::Ident, relative: Option<ast::Ident>, dir_path: &Path, - codemap: &CodeMap) -> ModulePath + source_map: &SourceMap) -> ModulePath { // If we're in a foo.rs file instead of a mod.rs file, // we need to look for submodules in @@ -6342,8 +6342,8 @@ impl<'a> Parser<'a> { relative_prefix, mod_name, path::MAIN_SEPARATOR); let default_path = dir_path.join(&default_path_str); let secondary_path = dir_path.join(&secondary_path_str); - let default_exists = codemap.file_exists(&default_path); - let secondary_exists = codemap.file_exists(&secondary_path); + let default_exists = source_map.file_exists(&default_path); + let secondary_exists = source_map.file_exists(&secondary_path); let result = match (default_exists, secondary_exists) { (true, false) => Ok(ModulePathSuccess { @@ -6418,7 +6418,7 @@ impl<'a> Parser<'a> { DirectoryOwnership::UnownedViaMod(_) => None, }; let paths = Parser::default_submod_path( - id, relative, &self.directory.path, self.sess.codemap()); + id, relative, &self.directory.path, self.sess.source_map()); match self.directory.ownership { DirectoryOwnership::Owned { .. } => { @@ -6445,7 +6445,7 @@ impl<'a> Parser<'a> { let mut err = self.diagnostic().struct_span_err(id_sp, "cannot declare a new module at this location"); if !id_sp.is_dummy() { - let src_path = self.sess.codemap().span_to_filename(id_sp); + let src_path = self.sess.source_map().span_to_filename(id_sp); if let FileName::Real(src_path) = src_path { if let Some(stem) = src_path.file_stem() { let mut dest_path = src_path.clone(); @@ -7207,7 +7207,7 @@ impl<'a> Parser<'a> { sp, &suggestion, format!(" {} ", kw), Applicability::MachineApplicable ); } else { - if let Ok(snippet) = self.sess.codemap().span_to_snippet(ident_sp) { + if let Ok(snippet) = self.sess.source_map().span_to_snippet(ident_sp) { err.span_suggestion_with_applicability( full_sp, "if you meant to call a macro, try", diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 54ce06f61ef..3065e795ed8 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -16,7 +16,7 @@ use ast::{SelfKind, GenericBound, TraitBoundModifier}; use ast::{Attribute, MacDelimiter, GenericArg}; use util::parser::{self, AssocOp, Fixity}; use attr; -use codemap::{self, CodeMap, Spanned}; +use source_map::{self, SourceMap, Spanned}; use syntax_pos::{self, BytePos}; use syntax_pos::hygiene::{Mark, SyntaxContext}; use parse::token::{self, BinOpToken, Token}; @@ -57,7 +57,7 @@ impl PpAnn for NoAnn {} pub struct State<'a> { pub s: pp::Printer<'a>, - cm: Option<&'a CodeMap>, + cm: Option<&'a SourceMap>, comments: Option<Vec<comments::Comment> >, literals: Peekable<vec::IntoIter<comments::Literal>>, cur_cmnt: usize, @@ -84,7 +84,7 @@ pub const DEFAULT_COLUMNS: usize = 78; /// Requires you to pass an input filename and reader so that /// it can scan the input text for comments and literals to /// copy forward. -pub fn print_crate<'a>(cm: &'a CodeMap, +pub fn print_crate<'a>(cm: &'a SourceMap, sess: &ParseSess, krate: &ast::Crate, filename: FileName, @@ -118,7 +118,7 @@ pub fn print_crate<'a>(cm: &'a CodeMap, } impl<'a> State<'a> { - pub fn new_from_input(cm: &'a CodeMap, + pub fn new_from_input(cm: &'a SourceMap, sess: &ParseSess, filename: FileName, input: &mut dyn Read, @@ -138,7 +138,7 @@ impl<'a> State<'a> { if is_expanded { None } else { Some(lits) }) } - pub fn new(cm: &'a CodeMap, + pub fn new(cm: &'a SourceMap, out: Box<dyn Write+'a>, ann: &'a dyn PpAnn, comments: Option<Vec<comments::Comment>>, @@ -380,7 +380,7 @@ pub fn fun_to_string(decl: &ast::FnDecl, to_string(|s| { s.head("")?; s.print_fn(decl, header, Some(name), - generics, &codemap::dummy_spanned(ast::VisibilityKind::Inherited))?; + generics, &source_map::dummy_spanned(ast::VisibilityKind::Inherited))?; s.end()?; // Close the head box s.end() // Close the outer box }) @@ -1606,7 +1606,7 @@ impl<'a> State<'a> { ti.ident, ty, default.as_ref().map(|expr| &**expr), - &codemap::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited), + &source_map::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited), )?; } ast::TraitItemKind::Method(ref sig, ref body) => { @@ -1617,7 +1617,7 @@ impl<'a> State<'a> { ti.ident, &ti.generics, sig, - &codemap::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited), + &source_map::respan(ti.span.shrink_to_lo(), ast::VisibilityKind::Inherited), )?; if let Some(ref body) = *body { self.nbsp()?; @@ -3085,7 +3085,7 @@ impl<'a> State<'a> { ast::FnHeader { unsafety, abi, ..ast::FnHeader::default() }, name, &generics, - &codemap::dummy_spanned(ast::VisibilityKind::Inherited))?; + &source_map::dummy_spanned(ast::VisibilityKind::Inherited))?; self.end() } @@ -3185,7 +3185,7 @@ mod tests { use super::*; use ast; - use codemap; + use source_map; use syntax_pos; use with_globals; @@ -3205,7 +3205,7 @@ mod tests { &decl, ast::FnHeader { unsafety: ast::Unsafety::Normal, - constness: codemap::dummy_spanned(ast::Constness::NotConst), + constness: source_map::dummy_spanned(ast::Constness::NotConst), asyncness: ast::IsAsync::NotAsync, abi: Abi::Rust, }, @@ -3222,7 +3222,7 @@ mod tests { with_globals(|| { let ident = ast::Ident::from_str("principal_skinner"); - let var = codemap::respan(syntax_pos::DUMMY_SP, ast::Variant_ { + let var = source_map::respan(syntax_pos::DUMMY_SP, ast::Variant_ { ident, attrs: Vec::new(), // making this up as I go.... ? diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/source_map.rs index 0a9991d33b1..c65931a8577 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/source_map.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! The CodeMap tracks all the source code used within a single crate, mapping +//! The SourceMap tracks all the source code used within a single crate, mapping //! from integer byte positions to the original source code location. Each bit //! of source parsed during crate parsing (typically files, in-memory strings, //! or various bits of macro expansion) cover a continuous range of bytes in the -//! CodeMap and are represented by FileMaps. Byte positions are stored in +//! SourceMap and are represented by SourceFiles. Byte positions are stored in //! `spans` and used pervasively in the compiler. They are absolute positions -//! within the CodeMap, which upon request can be converted to line and column +//! within the SourceMap, which upon request can be converted to line and column //! information, source code snippets, etc. @@ -32,7 +32,7 @@ use std::path::{Path, PathBuf}; use std::env; use std::fs; use std::io::{self, Read}; -use errors::CodeMapper; +use errors::SourceMapper; /// Return the span itself if it doesn't come from a macro expansion, /// otherwise return the call site span up to the `enclosing_sp` by @@ -62,7 +62,7 @@ pub fn dummy_spanned<T>(t: T) -> Spanned<T> { } // _____________________________________________________________________________ -// FileMap, MultiByteChar, FileName, FileLines +// SourceFile, MultiByteChar, FileName, FileLines // /// An abstraction over the fs operations used by the Parser. @@ -102,50 +102,50 @@ impl FileLoader for RealFileLoader { } } -// This is a FileMap identifier that is used to correlate FileMaps between +// This is a SourceFile identifier that is used to correlate SourceFiles between // subsequent compilation sessions (which is something we need to do during // incremental compilation). #[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)] pub struct StableFilemapId(u128); impl StableFilemapId { - pub fn new(filemap: &FileMap) -> 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()) } } // _____________________________________________________________________________ -// CodeMap +// SourceMap // -pub(super) struct CodeMapFiles { - pub(super) file_maps: Vec<Lrc<FileMap>>, - stable_id_to_filemap: FxHashMap<StableFilemapId, Lrc<FileMap>> +pub(super) struct SourceMapFiles { + pub(super) file_maps: Vec<Lrc<SourceFile>>, + stable_id_to_source_file: FxHashMap<StableFilemapId, Lrc<SourceFile>> } -pub struct CodeMap { - pub(super) files: Lock<CodeMapFiles>, +pub struct SourceMap { + pub(super) files: Lock<SourceMapFiles>, file_loader: Box<dyn FileLoader + Sync + Send>, // This is used to apply the file path remapping as specified via - // --remap-path-prefix to all FileMaps allocated within this CodeMap. + // --remap-path-prefix to all SourceFiles allocated within this SourceMap. path_mapping: FilePathMapping, /// In case we are in a doctest, replace all file names with the PathBuf, /// and add the given offsets to the line info doctest_offset: Option<(FileName, isize)>, } -impl CodeMap { - pub fn new(path_mapping: FilePathMapping) -> CodeMap { - CodeMap { - files: Lock::new(CodeMapFiles { +impl SourceMap { + pub fn new(path_mapping: FilePathMapping) -> 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, @@ -154,21 +154,21 @@ impl CodeMap { } pub fn new_doctest(path_mapping: FilePathMapping, - file: FileName, line: isize) -> CodeMap { - CodeMap { + file: FileName, line: isize) -> SourceMap { + SourceMap { doctest_offset: Some((file, line)), - ..CodeMap::new(path_mapping) + ..SourceMap::new(path_mapping) } } pub fn with_file_loader(file_loader: Box<dyn FileLoader + Sync + Send>, path_mapping: FilePathMapping) - -> CodeMap { - CodeMap { - files: Lock::new(CodeMapFiles { + -> 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, @@ -184,36 +184,36 @@ impl CodeMap { self.file_loader.file_exists(path) } - pub fn load_file(&self, path: &Path) -> io::Result<Lrc<FileMap>> { + pub fn load_file(&self, path: &Path) -> io::Result<Lrc<SourceFile>> { let src = self.file_loader.read_file(path)?; let filename = if let Some((ref name, _)) = self.doctest_offset { name.clone() } 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<FileMap>>> { + 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<FileMap>> { - 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 { match self.files.borrow().file_maps.last() { None => 0, // Add one so there is some space between files. This lets us distinguish - // positions in the codemap, even in the presence of zero-length files. + // positions in the source_map, even in the presence of zero-length files. Some(last) => last.end_pos.to_usize() + 1, } } - /// Creates a new filemap. - /// This does not ensure that only one FileMap exists per file name. - pub fn new_filemap(&self, filename: FileName, src: String) -> Lrc<FileMap> { + /// Creates a new source_file. + /// This does not ensure that only one SourceFile exists per file name. + 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 CodeMap { }, other => (other, false), }; - let filemap = Lrc::new(FileMap::new( + let source_file = Lrc::new(SourceFile::new( filename, was_remapped, unmapped_path, @@ -240,17 +240,18 @@ impl CodeMap { 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 FileMap representing a source file from an external - /// crate. The source code of such an "imported filemap" is not available, + /// Allocates a new SourceFile representing a source file from an external + /// 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, @@ -260,7 +261,7 @@ impl CodeMap { mut file_local_lines: Vec<BytePos>, mut file_local_multibyte_chars: Vec<MultiByteChar>, mut file_local_non_narrow_chars: Vec<NonNarrowChar>) - -> Lrc<FileMap> { + -> Lrc<SourceFile> { let start_pos = self.next_start_pos(); let end_pos = Pos::from_usize(start_pos + source_len); @@ -278,7 +279,7 @@ impl CodeMap { *swc = *swc + start_pos; } - let filemap = Lrc::new(FileMap { + let source_file = Lrc::new(SourceFile { name: filename, name_was_remapped, unmapped_path: None, @@ -296,10 +297,11 @@ impl CodeMap { 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 { @@ -326,7 +328,7 @@ impl CodeMap { pub fn lookup_char_pos(&self, pos: BytePos) -> Loc { let chpos = self.bytepos_to_file_charpos(pos); match self.lookup_line(pos) { - Ok(FileMapAndLine { fm: f, line: a }) => { + Ok(SourceFileAndLine { fm: f, line: a }) => { let line = a + 1; // Line numbers start at 1 let linebpos = f.lines[a]; let linechpos = self.bytepos_to_file_charpos(linebpos); @@ -385,14 +387,14 @@ impl CodeMap { } } - // If the relevant filemap is empty, we don't return a line number. - pub fn lookup_line(&self, pos: BytePos) -> Result<FileMapAndLine, Lrc<FileMap>> { - let idx = self.lookup_filemap_idx(pos); + // 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_source_file_idx(pos); let f = (*self.files.borrow().file_maps)[idx].clone(); match f.lookup_line(pos) { - Some(line) => Ok(FileMapAndLine { fm: f, line: line }), + Some(line) => Ok(SourceFileAndLine { fm: f, line: line }), None => Err(f) } } @@ -463,7 +465,7 @@ impl CodeMap { pub fn span_to_unmapped_path(&self, sp: Span) -> FileName { self.lookup_char_pos(sp.lo()).file.unmapped_path.clone() - .expect("CodeMap::span_to_unmapped_path called for imported FileMap?") + .expect("SourceMap::span_to_unmapped_path called for imported SourceFile?") } pub fn is_multiline(&self, sp: Span) -> bool { @@ -541,7 +543,7 @@ impl CodeMap { 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 +800,7 @@ impl CodeMap { } } - pub fn get_filemap(&self, filename: &FileName) -> Option<Lrc<FileMap>> { + 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()); @@ -807,20 +809,20 @@ impl CodeMap { None } - /// For a global BytePos compute the local offset within the containing FileMap - pub fn lookup_byte_offset(&self, bpos: BytePos) -> FileMapAndBytePos { - let idx = self.lookup_filemap_idx(bpos); + /// 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_source_file_idx(bpos); let fm = (*self.files.borrow().file_maps)[idx].clone(); let offset = bpos - fm.start_pos; - FileMapAndBytePos {fm: fm, pos: offset} + 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 FileMap + // The number of extra bytes due to multibyte chars in the SourceFile let mut total_extra_bytes = 0; for mbc in map.multibyte_chars.iter() { @@ -841,13 +843,13 @@ impl CodeMap { 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 { @@ -895,7 +897,7 @@ impl CodeMap { /// /// Attention: The method used is very fragile since it essentially duplicates the work of the /// parser. If you need to use this function or something similar, please consider updating the - /// codemap functions and this function to something more robust. + /// source_map functions and this function to something more robust. pub fn generate_local_type_param_snippet(&self, span: Span) -> Option<(Span, String)> { // Try to extend the span to the previous "fn" keyword to retrieve the function // signature @@ -941,7 +943,7 @@ impl CodeMap { } } -impl CodeMapper for CodeMap { +impl SourceMapper for SourceMap { fn lookup_char_pos(&self, pos: BytePos) -> Loc { self.lookup_char_pos(pos) } @@ -966,7 +968,7 @@ impl CodeMapper for CodeMap { } sp } - fn ensure_filemap_source_present(&self, file_map: Lrc<FileMap>) -> 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(), @@ -1023,13 +1025,13 @@ mod tests { use super::*; use rustc_data_structures::sync::Lrc; - fn init_code_map() -> CodeMap { - let cm = CodeMap::new(FilePathMapping::empty()); - cm.new_filemap(PathBuf::from("blork.rs").into(), + fn init_code_map() -> SourceMap { + let cm = SourceMap::new(FilePathMapping::empty()); + 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 +1068,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)); @@ -1080,12 +1082,12 @@ mod tests { assert_eq!(loc2.col, CharPos(0)); } - fn init_code_map_mbc() -> CodeMap { - let cm = CodeMap::new(FilePathMapping::empty()); + 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 +1112,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(); @@ -1135,10 +1137,10 @@ mod tests { /// lines in the middle of a file. #[test] fn span_to_snippet_and_lines_spanning_multiple_lines() { - let cm = CodeMap::new(FilePathMapping::empty()); + 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 +1158,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 +1168,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); @@ -1177,11 +1179,11 @@ mod tests { /// Test failing to merge two spans on different lines #[test] fn span_merging_fail() { - let cm = CodeMap::new(FilePathMapping::empty()); + let cm = SourceMap::new(FilePathMapping::empty()); 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); @@ -1190,18 +1192,18 @@ mod tests { /// Returns the span corresponding to the `n`th occurrence of /// `substring` in `source_text`. - trait CodeMapExtension { + trait SourceMapExtension { fn span_substr(&self, - file: &Lrc<FileMap>, + file: &Lrc<SourceFile>, source_text: &str, substring: &str, n: usize) -> Span; } - impl CodeMapExtension for CodeMap { + impl SourceMapExtension for SourceMap { fn span_substr(&self, - file: &Lrc<FileMap>, + file: &Lrc<SourceFile>, source_text: &str, substring: &str, n: usize) diff --git a/src/libsyntax/std_inject.rs b/src/libsyntax/std_inject.rs index 626a610017d..1210f331b28 100644 --- a/src/libsyntax/std_inject.rs +++ b/src/libsyntax/std_inject.rs @@ -16,12 +16,12 @@ use edition::Edition; use ext::hygiene::{Mark, SyntaxContext}; use symbol::{Symbol, keywords}; use syntax_pos::{DUMMY_SP, Span}; -use codemap::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan}; +use source_map::{ExpnInfo, MacroAttribute, dummy_spanned, hygiene, respan}; use ptr::P; use tokenstream::TokenStream; /// Craft a span that will be ignored by the stability lint's -/// call to codemap's `is_internal` check. +/// call to source_map's `is_internal` check. /// The expanded code uses the unstable `#[prelude_import]` attribute. fn ignored_span(sp: Span) -> Span { let mark = Mark::fresh(Mark::root()); diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 1cbaf3cc312..988f50b4f0c 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -20,9 +20,9 @@ use std::slice; use std::mem; use std::vec; use attr::{self, HasAttrs}; -use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, FileMap, BytePos}; +use syntax_pos::{self, DUMMY_SP, NO_EXPANSION, Span, SourceFile, BytePos}; -use codemap::{self, CodeMap, ExpnInfo, MacroAttribute, dummy_spanned}; +use source_map::{self, SourceMap, ExpnInfo, MacroAttribute, dummy_spanned}; use errors; use config; use entry::{self, EntryPointType}; @@ -324,7 +324,7 @@ fn generate_test_harness(sess: &ParseSess, } /// Craft a span that will be ignored by the stability lint's -/// call to codemap's `is_internal` check. +/// call to source_map's `is_internal` check. /// The expanded code calls some unstable functions in the test crate. fn ignored_span(cx: &TestCtxt, sp: Span) -> Span { sp.with_ctxt(cx.ctxt) @@ -616,8 +616,8 @@ fn mk_test_module(cx: &mut TestCtxt) -> (P<ast::Item>, Option<P<ast::Item>>) { (item, reexport) } -fn nospan<T>(t: T) -> codemap::Spanned<T> { - codemap::Spanned { node: t, span: DUMMY_SP } +fn nospan<T>(t: T) -> source_map::Spanned<T> { + source_map::Spanned { node: t, span: DUMMY_SP } } fn path_node(ids: Vec<Ident>) -> ast::Path { diff --git a/src/libsyntax/test_snippet.rs b/src/libsyntax/test_snippet.rs index c7e4fbd1073..d49965fd936 100644 --- a/src/libsyntax/test_snippet.rs +++ b/src/libsyntax/test_snippet.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use codemap::{CodeMap, FilePathMapping}; +use source_map::{SourceMap, FilePathMapping}; use errors::Handler; use errors::emitter::EmitterWriter; use std::io; @@ -50,8 +50,8 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: & with_globals(|| { let output = Arc::new(Mutex::new(Vec::new())); - let code_map = Lrc::new(CodeMap::new(FilePathMapping::empty())); - code_map.new_filemap(Path::new("test.rs").to_owned().into(), file_text.to_owned()); + let code_map = Lrc::new(SourceMap::new(FilePathMapping::empty())); + 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..374154e6333 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -9,8 +9,8 @@ // except according to those terms. use ast::{self, Ident}; -use codemap::FilePathMapping; -use parse::{ParseSess, PResult, filemap_to_stream}; +use source_map::FilePathMapping; +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.source_map() + .new_source_file(PathBuf::from("bogofile").into(), source_str), None) } /// Map string to parser (via tts) |
