Skip to content

Commit 6a59d18

Browse files
committed
syntax: replace sess.span_diagnostic.cm with sess.codemap().
1 parent f786437 commit 6a59d18

File tree

8 files changed

+18
-28
lines changed

8 files changed

+18
-28
lines changed

src/grammar/verify.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,11 +287,9 @@ fn main() {
287287
let options = config::basic_options();
288288
let session = session::build_session(options, None,
289289
syntax::diagnostics::registry::Registry::new(&[]));
290-
let filemap = parse::string_to_filemap(&session.parse_sess,
291-
code,
292-
String::from_str("<n/a>"));
290+
let filemap = session.parse_sess.codemap().new_filemap(String::from_str("<n/a>"), code);
293291
let mut lexer = lexer::StringReader::new(session.diagnostic(), filemap);
294-
let ref cm = lexer.span_diagnostic.cm;
292+
let cm = session.codemap();
295293

296294
// ANTLR
297295
let mut token_file = File::open(&Path::new(&args.next().unwrap())).unwrap();

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl Session {
231231
&self.parse_sess.span_diagnostic
232232
}
233233
pub fn codemap<'a>(&'a self) -> &'a codemap::CodeMap {
234-
&self.parse_sess.span_diagnostic.cm
234+
self.parse_sess.codemap()
235235
}
236236
// This exists to help with refactoring to eliminate impossible
237237
// cases later on

src/librustdoc/html/highlight.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ use syntax::parse;
2525
pub fn highlight(src: &str, class: Option<&str>, id: Option<&str>) -> String {
2626
debug!("highlighting: ================\n{}\n==============", src);
2727
let sess = parse::ParseSess::new();
28-
let fm = parse::string_to_filemap(&sess,
29-
src.to_string(),
30-
"<stdin>".to_string());
28+
let fm = sess.codemap().new_filemap("<stdin>".to_string(), src.to_string());
3129

3230
let mut out = Vec::new();
3331
doit(&sess,
@@ -62,7 +60,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
6260
loop {
6361
let next = lexer.next_token();
6462

65-
let snip = |sp| sess.span_diagnostic.cm.span_to_snippet(sp).unwrap();
63+
let snip = |sp| sess.codemap().span_to_snippet(sp).unwrap();
6664

6765
if next.tok == token::Eof { break }
6866

@@ -178,7 +176,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
178176

179177
// as mentioned above, use the original source code instead of
180178
// stringifying this token
181-
let snip = sess.span_diagnostic.cm.span_to_snippet(next.sp).unwrap();
179+
let snip = sess.codemap().span_to_snippet(next.sp).unwrap();
182180
if klass == "" {
183181
try!(write!(out, "{}", Escape(&snip)));
184182
} else {

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ impl<'a> ExtCtxt<'a> {
648648
parse::tts_to_parser(self.parse_sess, tts.to_vec(), self.cfg())
649649
}
650650

651-
pub fn codemap(&self) -> &'a CodeMap { &self.parse_sess.span_diagnostic.cm }
651+
pub fn codemap(&self) -> &'a CodeMap { self.parse_sess.codemap() }
652652
pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess }
653653
pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() }
654654
pub fn call_site(&self) -> Span {

src/libsyntax/parse/mod.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl ParseSess {
5858
included_mod_stack: RefCell::new(vec![])
5959
}
6060
}
61+
62+
pub fn codemap(&self) -> &CodeMap {
63+
&self.span_diagnostic.cm
64+
}
6165
}
6266

6367
// a bunch of utility functions of the form parse_<thing>_from_<source>
@@ -170,7 +174,7 @@ pub fn new_parser_from_source_str<'a>(sess: &'a ParseSess,
170174
name: String,
171175
source: String)
172176
-> Parser<'a> {
173-
filemap_to_parser(sess, string_to_filemap(sess, source, name), cfg)
177+
filemap_to_parser(sess, sess.codemap().new_filemap(name, source), cfg)
174178
}
175179

176180
/// Create a new parser, handling errors as appropriate
@@ -234,8 +238,7 @@ pub fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
234238
};
235239
match str::from_utf8(&bytes[..]).ok() {
236240
Some(s) => {
237-
string_to_filemap(sess, s.to_string(),
238-
path.to_str().unwrap().to_string())
241+
sess.codemap().new_filemap(path.to_str().unwrap().to_string(), s.to_string())
239242
}
240243
None => {
241244
err(&format!("{:?} is not UTF-8 encoded", path.display()));
@@ -244,13 +247,6 @@ pub fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
244247
}
245248
}
246249

247-
/// Given a session and a string, add the string to
248-
/// the session's codemap and return the new filemap
249-
pub fn string_to_filemap(sess: &ParseSess, source: String, path: String)
250-
-> Rc<FileMap> {
251-
sess.span_diagnostic.cm.new_filemap(path, source)
252-
}
253-
254250
/// Given a filemap, produce a sequence of token-trees
255251
pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
256252
-> Vec<ast::TokenTree> {
@@ -1104,7 +1100,7 @@ mod tests {
11041100

11051101
let span = tts.iter().rev().next().unwrap().get_span();
11061102

1107-
match sess.span_diagnostic.cm.span_to_snippet(span) {
1103+
match sess.codemap().span_to_snippet(span) {
11081104
Ok(s) => assert_eq!(&s[..], "{ body }"),
11091105
Err(_) => panic!("could not get snippet"),
11101106
}

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4835,8 +4835,7 @@ impl<'a> Parser<'a> {
48354835
outer_attrs: &[ast::Attribute],
48364836
id_sp: Span)
48374837
-> PResult<(ast::Item_, Vec<ast::Attribute> )> {
4838-
let mut prefix = PathBuf::from(&self.sess.span_diagnostic.cm
4839-
.span_to_filename(self.span));
4838+
let mut prefix = PathBuf::from(&self.sess.codemap().span_to_filename(self.span));
48404839
prefix.pop();
48414840
let mut dir_path = prefix;
48424841
for part in &self.mod_path_stack {

src/libsyntax/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn ignored_span(cx: &TestCtxt, sp: Span) -> Span {
301301
allow_internal_unstable: true,
302302
}
303303
};
304-
let expn_id = cx.sess.span_diagnostic.cm.record_expansion(info);
304+
let expn_id = cx.sess.codemap().record_expansion(info);
305305
let mut sp = sp;
306306
sp.expn_id = expn_id;
307307
return sp;

src/libsyntax/util/parser_testing.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use ast;
12-
use parse::{ParseSess,string_to_filemap,filemap_to_tts};
12+
use parse::{ParseSess,filemap_to_tts};
1313
use parse::new_parser_from_source_str;
1414
use parse::parser::Parser;
1515
use parse::token;
@@ -19,8 +19,7 @@ use str::char_at;
1919
/// Map a string to tts, using a made-up filename:
2020
pub fn string_to_tts(source_str: String) -> Vec<ast::TokenTree> {
2121
let ps = ParseSess::new();
22-
filemap_to_tts(&ps,
23-
string_to_filemap(&ps, source_str, "bogofile".to_string()))
22+
filemap_to_tts(&ps, ps.codemap().new_filemap("bogofile".to_string(), source_str))
2423
}
2524

2625
/// Map string to parser (via tts)

0 commit comments

Comments
 (0)