From 984e9afae5098192a789dc39d44cec8225067896 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 5 Feb 2014 17:31:33 +1300 Subject: Dump results of analysis phase as CSV Adds the option -Zsave-analysis which will dump the results of syntax and type checking into CSV files. These can be interpreted by tools such as DXR to provide semantic information about Rust programs for code search, cross-reference, etc. Authored by Nick Cameron and Peter Elmers (@pelmers; including enums, type parameters/generics). --- src/libsyntax/codemap.rs | 70 ++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 35 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index d9e3e4e941d..c917198e7d4 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -421,6 +421,41 @@ impl CodeMap { fail!("asking for {} which we don't know about", filename); } + pub fn lookup_byte_offset(&self, bpos: BytePos) -> FileMapAndBytePos { + let idx = self.lookup_filemap_idx(bpos); + let fm = self.files.borrow().get(idx).clone(); + let offset = bpos - fm.start_pos; + FileMapAndBytePos {fm: fm, pos: offset} + } + + // Converts an absolute BytePos to a CharPos relative to the filemap and above. + pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos { + debug!("codemap: converting {:?} to char pos", bpos); + let idx = self.lookup_filemap_idx(bpos); + 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; + + for mbc in map.multibyte_chars.borrow().iter() { + debug!("codemap: {:?}-byte char at {:?}", mbc.bytes, mbc.pos); + if mbc.pos < bpos { + // every character is at least one byte, so we only + // count the actual extra bytes. + total_extra_bytes += mbc.bytes - 1; + // We should never see a byte position in the middle of a + // character + assert!(bpos.to_uint() >= mbc.pos.to_uint() + mbc.bytes); + } else { + break; + } + } + + assert!(map.start_pos.to_uint() + total_extra_bytes <= bpos.to_uint()); + CharPos(bpos.to_uint() - map.start_pos.to_uint() - total_extra_bytes) + } + fn lookup_filemap_idx(&self, pos: BytePos) -> uint { let files = self.files.borrow(); let files = files; @@ -491,41 +526,6 @@ impl CodeMap { col: chpos - linechpos } } - - fn lookup_byte_offset(&self, bpos: BytePos) -> FileMapAndBytePos { - let idx = self.lookup_filemap_idx(bpos); - let fm = self.files.borrow().get(idx).clone(); - let offset = bpos - fm.start_pos; - FileMapAndBytePos {fm: fm, pos: offset} - } - - // Converts an absolute BytePos to a CharPos relative to the filemap. - fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos { - debug!("codemap: converting {:?} to char pos", bpos); - let idx = self.lookup_filemap_idx(bpos); - 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; - - for mbc in map.multibyte_chars.borrow().iter() { - debug!("codemap: {:?}-byte char at {:?}", mbc.bytes, mbc.pos); - if mbc.pos < bpos { - // every character is at least one byte, so we only - // count the actual extra bytes. - total_extra_bytes += mbc.bytes - 1; - // We should never see a byte position in the middle of a - // character - assert!(bpos.to_uint() >= mbc.pos.to_uint() + mbc.bytes); - } else { - break; - } - } - - assert!(map.start_pos.to_uint() + total_extra_bytes <= bpos.to_uint()); - CharPos(bpos.to_uint() - map.start_pos.to_uint() - total_extra_bytes) - } } #[cfg(test)] -- cgit 1.4.1-3-g733a5