diff options
| author | bors <bors@rust-lang.org> | 2013-11-20 23:31:27 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-20 23:31:27 -0800 |
| commit | ea5d1dfb1cab80bedf372d8b24a726ed054f2417 (patch) | |
| tree | 319e66cad1f5ab71ed2514e41d9b6b9323a6afc5 /src/libsyntax | |
| parent | f804bd94d5b43723e0f156114ab9fd7eea98fc8f (diff) | |
| parent | f4c1f49049c1d01a09599aa2b7ea4a6523045d38 (diff) | |
| download | rust-ea5d1dfb1cab80bedf372d8b24a726ed054f2417.tar.gz rust-ea5d1dfb1cab80bedf372d8b24a726ed054f2417.zip | |
auto merge of #10567 : sanxiyn/rust/bytepos, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/codemap.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 |
5 files changed, 15 insertions, 13 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 5e4355161f4..f7590e7b4ed 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -29,9 +29,11 @@ pub trait Pos { fn to_uint(&self) -> uint; } -/// A byte offset +/// A byte offset. Keep this small (currently 32-bits), as AST contains +/// a lot of them. #[deriving(Clone, Eq, IterBytes, Ord)] -pub struct BytePos(uint); +pub struct BytePos(u32); + /// A character offset. Because of multibyte utf8 characters, a byte offset /// is not equivalent to a character offset. The CodeMap will convert BytePos /// values to CharPos values as necessary. @@ -42,8 +44,8 @@ pub struct CharPos(uint); // have been unsuccessful impl Pos for BytePos { - fn from_uint(n: uint) -> BytePos { BytePos(n) } - fn to_uint(&self) -> uint { **self } + fn from_uint(n: uint) -> BytePos { BytePos(n as u32) } + fn to_uint(&self) -> uint { **self as uint } } impl Add<BytePos, BytePos> for BytePos { @@ -278,7 +280,7 @@ impl CodeMap { let filemap = @FileMap { name: filename, substr: substr, src: src, - start_pos: BytePos(start_pos), + start_pos: Pos::from_uint(start_pos), lines: @mut ~[], multibyte_chars: @mut ~[], }; diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 26de9215dbf..dbf485a50ce 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -247,7 +247,7 @@ pub fn bump(rdr: &mut StringReader) { let last_char = rdr.curr; let next = rdr.src.char_range_at(current_byte_offset); let byte_offset_diff = next.next - current_byte_offset; - rdr.pos = rdr.pos + BytePos(byte_offset_diff); + rdr.pos = rdr.pos + Pos::from_uint(byte_offset_diff); rdr.curr = next.ch; rdr.col = rdr.col + CharPos(1u); if last_char == '\n' { @@ -257,7 +257,7 @@ pub fn bump(rdr: &mut StringReader) { if byte_offset_diff > 1 { rdr.filemap.record_multibyte_char( - BytePos(current_byte_offset), byte_offset_diff); + Pos::from_uint(current_byte_offset), byte_offset_diff); } } else { rdr.curr = unsafe { transmute(-1u32) }; // FIXME: #8971: unsound @@ -333,7 +333,7 @@ fn consume_any_line_comment(rdr: @mut StringReader) bump(rdr); // line comments starting with "///" or "//!" are doc-comments if rdr.curr == '/' || rdr.curr == '!' { - let start_bpos = rdr.pos - BytePos(3u); + let start_bpos = rdr.pos - BytePos(3); while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); } @@ -387,7 +387,7 @@ fn consume_block_comment(rdr: @mut StringReader) -> Option<TokenAndSpan> { // block comments starting with "/**" or "/*!" are doc-comments let is_doc_comment = rdr.curr == '*' || rdr.curr == '!'; - let start_bpos = rdr.pos - BytePos(if is_doc_comment {3u} else {2u}); + let start_bpos = rdr.pos - BytePos(if is_doc_comment {3} else {2}); let mut level: int = 1; while level > 0 { @@ -815,7 +815,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token { // Byte offsetting here is okay because the // character before position `start` is an // ascii single quote. - start - BytePos(1u), + start - BytePos(1), rdr.last_pos, ~"unterminated character constant"); } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 947f7a7fc29..8fbd152543d 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -349,7 +349,7 @@ mod test { } // produce a codemap::span - fn sp (a: uint, b: uint) -> Span { + fn sp(a: u32, b: u32) -> Span { Span{lo:BytePos(a),hi:BytePos(b),expn_info:None} } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 6c2df4ad314..486a7a800a0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -606,7 +606,7 @@ impl Parser { token::GT => self.bump(), token::BINOP(token::SHR) => self.replace_token( token::GT, - self.span.lo + BytePos(1u), + self.span.lo + BytePos(1), self.span.hi ), _ => self.fatal(format!("expected `{}`, found `{}`", diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 8d31133e9e2..839a7cd9d57 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2119,7 +2119,7 @@ pub fn maybe_print_trailing_comment(s: @ps, span: codemap::Span, if (*cmnt).style != comments::trailing { return; } let span_line = cm.lookup_char_pos(span.hi); let comment_line = cm.lookup_char_pos((*cmnt).pos); - let mut next = (*cmnt).pos + BytePos(1u); + let mut next = (*cmnt).pos + BytePos(1); match next_pos { None => (), Some(p) => next = p } if span.hi < (*cmnt).pos && (*cmnt).pos < next && span_line.line == comment_line.line { |
