about summary refs log tree commit diff
path: root/src/libsyntax/parse
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-05-13 23:08:02 +0300
committerEduard Burtescu <edy.burt@gmail.com>2015-05-14 01:47:56 +0300
commit6a59d1824d11b6452463fcc23ad64cd142dfa203 (patch)
tree00094186d425e59e31f44e6f161f27bf0f685884 /src/libsyntax/parse
parentf786437bd223740d9767345731d458d10936f8d7 (diff)
downloadrust-6a59d1824d11b6452463fcc23ad64cd142dfa203.tar.gz
rust-6a59d1824d11b6452463fcc23ad64cd142dfa203.zip
syntax: replace sess.span_diagnostic.cm with sess.codemap().
Diffstat (limited to 'src/libsyntax/parse')
-rw-r--r--src/libsyntax/parse/mod.rs18
-rw-r--r--src/libsyntax/parse/parser.rs3
2 files changed, 8 insertions, 13 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs
index 21253982e51..0db83c6f1b1 100644
--- a/src/libsyntax/parse/mod.rs
+++ b/src/libsyntax/parse/mod.rs
@@ -58,6 +58,10 @@ impl ParseSess {
             included_mod_stack: RefCell::new(vec![])
         }
     }
+
+    pub fn codemap(&self) -> &CodeMap {
+        &self.span_diagnostic.cm
+    }
 }
 
 // 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,
                                       name: String,
                                       source: String)
                                       -> Parser<'a> {
-    filemap_to_parser(sess, string_to_filemap(sess, source, name), cfg)
+    filemap_to_parser(sess, sess.codemap().new_filemap(name, source), cfg)
 }
 
 /// Create a new parser, handling errors as appropriate
@@ -234,8 +238,7 @@ pub fn file_to_filemap(sess: &ParseSess, path: &Path, spanopt: Option<Span>)
     };
     match str::from_utf8(&bytes[..]).ok() {
         Some(s) => {
-            string_to_filemap(sess, s.to_string(),
-                              path.to_str().unwrap().to_string())
+            sess.codemap().new_filemap(path.to_str().unwrap().to_string(), s.to_string())
         }
         None => {
             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>)
     }
 }
 
-/// Given a session and a string, add the string to
-/// the session's codemap and return the new filemap
-pub fn string_to_filemap(sess: &ParseSess, source: String, path: String)
-                         -> Rc<FileMap> {
-    sess.span_diagnostic.cm.new_filemap(path, source)
-}
-
 /// Given a filemap, produce a sequence of token-trees
 pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc<FileMap>)
     -> Vec<ast::TokenTree> {
@@ -1104,7 +1100,7 @@ mod tests {
 
         let span = tts.iter().rev().next().unwrap().get_span();
 
-        match sess.span_diagnostic.cm.span_to_snippet(span) {
+        match sess.codemap().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 541ec16b415..d890708d123 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -4835,8 +4835,7 @@ impl<'a> Parser<'a> {
                     outer_attrs: &[ast::Attribute],
                     id_sp: Span)
                     -> PResult<(ast::Item_, Vec<ast::Attribute> )> {
-        let mut prefix = PathBuf::from(&self.sess.span_diagnostic.cm
-                                            .span_to_filename(self.span));
+        let mut prefix = PathBuf::from(&self.sess.codemap().span_to_filename(self.span));
         prefix.pop();
         let mut dir_path = prefix;
         for part in &self.mod_path_stack {