libsyntax: De-`@mut` `CodeMap::files`
This commit is contained in:
parent
39f39ed40b
commit
4c85cf7a40
|
@ -464,9 +464,19 @@ fn write_out_deps(sess: Session, input: &input, outputs: &OutputFilenames, crate
|
|||
|
||||
// Build a list of files used to compile the output and
|
||||
// write Makefile-compatible dependency rules
|
||||
let files: ~[@str] = sess.codemap.files.iter()
|
||||
.filter_map(|fmap| if fmap.is_real_file() { Some(fmap.name) } else { None })
|
||||
.collect();
|
||||
let files: ~[@str] = {
|
||||
let files = sess.codemap.files.borrow();
|
||||
files.get()
|
||||
.iter()
|
||||
.filter_map(|fmap| {
|
||||
if fmap.is_real_file() {
|
||||
Some(fmap.name)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
};
|
||||
let mut file = io::File::create(&deps_filename);
|
||||
for path in out_filenames.iter() {
|
||||
write!(&mut file as &mut Writer,
|
||||
|
|
|
@ -268,13 +268,13 @@ impl FileMap {
|
|||
}
|
||||
|
||||
pub struct CodeMap {
|
||||
files: @mut ~[@FileMap]
|
||||
files: RefCell<~[@FileMap]>
|
||||
}
|
||||
|
||||
impl CodeMap {
|
||||
pub fn new() -> CodeMap {
|
||||
CodeMap {
|
||||
files: @mut ~[],
|
||||
files: RefCell::new(~[]),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,12 +288,12 @@ impl CodeMap {
|
|||
substr: FileSubstr,
|
||||
src: @str)
|
||||
-> @FileMap {
|
||||
let files = &mut *self.files;
|
||||
let start_pos = if files.len() == 0 {
|
||||
let mut files = self.files.borrow_mut();
|
||||
let start_pos = if files.get().len() == 0 {
|
||||
0
|
||||
} else {
|
||||
let last_start = files.last().start_pos.to_uint();
|
||||
let last_len = files.last().src.len();
|
||||
let last_start = files.get().last().start_pos.to_uint();
|
||||
let last_len = files.get().last().src.len();
|
||||
last_start + last_len
|
||||
};
|
||||
|
||||
|
@ -304,7 +304,7 @@ impl CodeMap {
|
|||
multibyte_chars: RefCell::new(~[]),
|
||||
};
|
||||
|
||||
files.push(filemap);
|
||||
files.get().push(filemap);
|
||||
|
||||
return filemap;
|
||||
}
|
||||
|
@ -350,9 +350,11 @@ impl CodeMap {
|
|||
}
|
||||
|
||||
pub fn span_to_str(&self, sp: Span) -> ~str {
|
||||
let files = &*self.files;
|
||||
if files.len() == 0 && sp == DUMMY_SP {
|
||||
return ~"no-location";
|
||||
{
|
||||
let files = self.files.borrow();
|
||||
if files.get().len() == 0 && sp == DUMMY_SP {
|
||||
return ~"no-location";
|
||||
}
|
||||
}
|
||||
|
||||
let lo = self.lookup_char_pos_adj(sp.lo);
|
||||
|
@ -392,7 +394,12 @@ impl CodeMap {
|
|||
}
|
||||
|
||||
pub fn get_filemap(&self, filename: &str) -> @FileMap {
|
||||
for fm in self.files.iter() { if filename == fm.name { return *fm; } }
|
||||
let files = self.files.borrow();
|
||||
for fm in files.get().iter() {
|
||||
if filename == fm.name {
|
||||
return *fm
|
||||
}
|
||||
}
|
||||
//XXjdm the following triggers a mismatched type bug
|
||||
// (or expected function, found _|_)
|
||||
fail!(); // ("asking for " + filename + " which we don't know about");
|
||||
|
@ -401,13 +408,14 @@ impl CodeMap {
|
|||
|
||||
impl CodeMap {
|
||||
fn lookup_filemap_idx(&self, pos: BytePos) -> uint {
|
||||
let files = &*self.files;
|
||||
let files = self.files.borrow();
|
||||
let files = files.get();
|
||||
let len = files.len();
|
||||
let mut a = 0u;
|
||||
let mut b = len;
|
||||
while b - a > 1u {
|
||||
let m = (a + b) / 2u;
|
||||
if self.files[m].start_pos > pos {
|
||||
if files[m].start_pos > pos {
|
||||
b = m;
|
||||
} else {
|
||||
a = m;
|
||||
|
@ -423,7 +431,9 @@ impl CodeMap {
|
|||
fn lookup_line(&self, pos: BytePos) -> FileMapAndLine
|
||||
{
|
||||
let idx = self.lookup_filemap_idx(pos);
|
||||
let f = self.files[idx];
|
||||
|
||||
let files = self.files.borrow();
|
||||
let f = files.get()[idx];
|
||||
let mut a = 0u;
|
||||
let mut lines = f.lines.borrow_mut();
|
||||
let mut b = lines.get().len();
|
||||
|
@ -457,7 +467,8 @@ impl CodeMap {
|
|||
fn lookup_byte_offset(&self, bpos: BytePos)
|
||||
-> FileMapAndBytePos {
|
||||
let idx = self.lookup_filemap_idx(bpos);
|
||||
let fm = self.files[idx];
|
||||
let files = self.files.borrow();
|
||||
let fm = files.get()[idx];
|
||||
let offset = bpos - fm.start_pos;
|
||||
return FileMapAndBytePos {fm: fm, pos: offset};
|
||||
}
|
||||
|
@ -467,7 +478,8 @@ impl CodeMap {
|
|||
fn bytepos_to_local_charpos(&self, bpos: BytePos) -> CharPos {
|
||||
debug!("codemap: converting {:?} to char pos", bpos);
|
||||
let idx = self.lookup_filemap_idx(bpos);
|
||||
let map = self.files[idx];
|
||||
let files = self.files.borrow();
|
||||
let map = files.get()[idx];
|
||||
|
||||
// The number of extra bytes due to multibyte chars in the FileMap
|
||||
let mut total_extra_bytes = 0;
|
||||
|
|
|
@ -109,7 +109,8 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
|||
let s = s.to_managed();
|
||||
// Add this input file to the code map to make it available as
|
||||
// dependency information
|
||||
cx.parse_sess.cm.files.push(@codemap::FileMap {
|
||||
let mut files = cx.parse_sess.cm.files.borrow_mut();
|
||||
files.get().push(@codemap::FileMap {
|
||||
name: file.display().to_str().to_managed(),
|
||||
substr: codemap::FssNone,
|
||||
src: s,
|
||||
|
|
|
@ -361,7 +361,10 @@ fn consume_any_line_comment(rdr: @StringReader)
|
|||
// I guess this is the only way to figure out if
|
||||
// we're at the beginning of the file...
|
||||
let cmap = @CodeMap::new();
|
||||
(*cmap).files.push(rdr.filemap);
|
||||
{
|
||||
let mut files = cmap.files.borrow_mut();
|
||||
files.get().push(rdr.filemap);
|
||||
}
|
||||
let loc = cmap.lookup_char_pos_adj(rdr.last_pos.get());
|
||||
if loc.line == 1u && loc.col == CharPos(0u) {
|
||||
while rdr.curr.get() != '\n' && !is_eof(rdr) { bump(rdr); }
|
||||
|
|
Loading…
Reference in New Issue