Skip to content

Commit 5e1e487

Browse files
committed
Make BytePos 32-bit
1 parent c4e28ae commit 5e1e487

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use syntax::parse::token;
2929
use syntax::parse::token::{ident_interner, interner_get};
3030
use syntax::parse::token::special_idents;
3131
use syntax::print::pprust::path_to_str;
32-
use syntax::codemap::{Span, dummy_sp, BytePos};
32+
use syntax::codemap::{Span, dummy_sp, Pos};
3333
use syntax::opt_vec::OptVec;
3434
use syntax::visit;
3535
use syntax::visit::Visitor;
@@ -2624,7 +2624,7 @@ impl Resolver {
26242624
if "???" == module_name {
26252625
let span = Span {
26262626
lo: span.lo,
2627-
hi: span.lo + BytePos(segment_name.len()),
2627+
hi: span.lo + Pos::from_uint(segment_name.len()),
26282628
expn_info: span.expn_info,
26292629
};
26302630
self.resolve_error(span,

src/libsyntax/codemap.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ pub trait Pos {
2929
fn to_uint(&self) -> uint;
3030
}
3131

32-
/// A byte offset
32+
/// A byte offset. Keep this small (currently 32-bits), as AST contains
33+
/// a lot of them.
3334
#[deriving(Clone, Eq, IterBytes, Ord)]
34-
pub struct BytePos(uint);
35+
pub struct BytePos(u32);
36+
3537
/// A character offset. Because of multibyte utf8 characters, a byte offset
3638
/// is not equivalent to a character offset. The CodeMap will convert BytePos
3739
/// values to CharPos values as necessary.
@@ -42,8 +44,8 @@ pub struct CharPos(uint);
4244
// have been unsuccessful
4345

4446
impl Pos for BytePos {
45-
fn from_uint(n: uint) -> BytePos { BytePos(n) }
46-
fn to_uint(&self) -> uint { **self }
47+
fn from_uint(n: uint) -> BytePos { BytePos(n as u32) }
48+
fn to_uint(&self) -> uint { **self as uint }
4749
}
4850

4951
impl Add<BytePos, BytePos> for BytePos {
@@ -278,7 +280,7 @@ impl CodeMap {
278280

279281
let filemap = @FileMap {
280282
name: filename, substr: substr, src: src,
281-
start_pos: BytePos(start_pos),
283+
start_pos: Pos::from_uint(start_pos),
282284
lines: @mut ~[],
283285
multibyte_chars: @mut ~[],
284286
};

src/libsyntax/parse/lexer.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ pub fn bump(rdr: &mut StringReader) {
241241
let last_char = rdr.curr;
242242
let next = rdr.src.char_range_at(current_byte_offset);
243243
let byte_offset_diff = next.next - current_byte_offset;
244-
rdr.pos = rdr.pos + BytePos(byte_offset_diff);
244+
rdr.pos = rdr.pos + Pos::from_uint(byte_offset_diff);
245245
rdr.curr = next.ch;
246246
rdr.col = rdr.col + CharPos(1u);
247247
if last_char == '\n' {
@@ -251,7 +251,7 @@ pub fn bump(rdr: &mut StringReader) {
251251

252252
if byte_offset_diff > 1 {
253253
rdr.filemap.record_multibyte_char(
254-
BytePos(current_byte_offset), byte_offset_diff);
254+
Pos::from_uint(current_byte_offset), byte_offset_diff);
255255
}
256256
} else {
257257
rdr.curr = unsafe { transmute(-1u32) }; // FIXME: #8971: unsound
@@ -327,7 +327,7 @@ fn consume_any_line_comment(rdr: @mut StringReader)
327327
bump(rdr);
328328
// line comments starting with "///" or "//!" are doc-comments
329329
if rdr.curr == '/' || rdr.curr == '!' {
330-
let start_bpos = rdr.pos - BytePos(3u);
330+
let start_bpos = rdr.pos - BytePos(3);
331331
while rdr.curr != '\n' && !is_eof(rdr) {
332332
bump(rdr);
333333
}
@@ -381,7 +381,7 @@ fn consume_block_comment(rdr: @mut StringReader)
381381
-> Option<TokenAndSpan> {
382382
// block comments starting with "/**" or "/*!" are doc-comments
383383
let is_doc_comment = rdr.curr == '*' || rdr.curr == '!';
384-
let start_bpos = rdr.pos - BytePos(if is_doc_comment {3u} else {2u});
384+
let start_bpos = rdr.pos - BytePos(if is_doc_comment {3} else {2});
385385

386386
let mut level: int = 1;
387387
while level > 0 {
@@ -809,7 +809,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
809809
// Byte offsetting here is okay because the
810810
// character before position `start` is an
811811
// ascii single quote.
812-
start - BytePos(1u),
812+
start - BytePos(1),
813813
rdr.last_pos,
814814
~"unterminated character constant");
815815
}

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl Parser {
608608
token::GT => self.bump(),
609609
token::BINOP(token::SHR) => self.replace_token(
610610
token::GT,
611-
self.span.lo + BytePos(1u),
611+
self.span.lo + BytePos(1),
612612
self.span.hi
613613
),
614614
_ => self.fatal(format!("expected `{}`, found `{}`",

src/libsyntax/print/pprust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ pub fn maybe_print_trailing_comment(s: @ps, span: codemap::Span,
21152115
if (*cmnt).style != comments::trailing { return; }
21162116
let span_line = cm.lookup_char_pos(span.hi);
21172117
let comment_line = cm.lookup_char_pos((*cmnt).pos);
2118-
let mut next = (*cmnt).pos + BytePos(1u);
2118+
let mut next = (*cmnt).pos + BytePos(1);
21192119
match next_pos { None => (), Some(p) => next = p }
21202120
if span.hi < (*cmnt).pos && (*cmnt).pos < next &&
21212121
span_line.line == comment_line.line {

0 commit comments

Comments
 (0)