]> git.lizzy.rs Git - rust.git/commitdiff
Make BytePos 32-bit
authorSeo Sanghyeon <sanxiyn@gmail.com>
Tue, 19 Nov 2013 17:15:49 +0000 (02:15 +0900)
committerSeo Sanghyeon <sanxiyn@gmail.com>
Wed, 20 Nov 2013 07:51:25 +0000 (16:51 +0900)
src/librustc/middle/resolve.rs
src/libsyntax/codemap.rs
src/libsyntax/parse/lexer.rs
src/libsyntax/parse/parser.rs
src/libsyntax/print/pprust.rs

index 4861fa19f7e8f58f5dd8fb4c8e312c362403e215..cd0e437d171054e05269ce7520a3b003a41ce24f 100644 (file)
@@ -29,7 +29,7 @@
 use syntax::parse::token::{ident_interner, interner_get};
 use syntax::parse::token::special_idents;
 use syntax::print::pprust::path_to_str;
-use syntax::codemap::{Span, dummy_sp, BytePos};
+use syntax::codemap::{Span, dummy_sp, Pos};
 use syntax::opt_vec::OptVec;
 use syntax::visit;
 use syntax::visit::Visitor;
@@ -2624,7 +2624,7 @@ fn resolve_module_path_from_root(&mut self,
                     if "???" == module_name {
                         let span = Span {
                             lo: span.lo,
-                            hi: span.lo + BytePos(segment_name.len()),
+                            hi: span.lo + Pos::from_uint(segment_name.len()),
                             expn_info: span.expn_info,
                         };
                         self.resolve_error(span,
index 5e4355161f40af946af3434dfc82b48a59f6afd2..f7590e7b4ed55747fb40af5b4172c12fed66ab4b 100644 (file)
@@ -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 trait Pos {
 // 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 @@ pub fn new_filemap_w_substr(&self,
 
         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 ~[],
         };
index 06a2c557e422889a5b29a19ca0c4ff44cd9774f9..2974b90d97e8be72b515efc29d6eb4a4db3f5f80 100644 (file)
@@ -241,7 +241,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' {
@@ -251,7 +251,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
@@ -327,7 +327,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);
                 }
@@ -381,7 +381,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 {
@@ -809,7 +809,7 @@ fn binop(rdr: @mut StringReader, op: token::binop) -> 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");
         }
index 2ea6878f4a3701219cc9a40d684e30ec6557ff34..2a270b392bcddc55724a790d40f4cbf451f662e2 100644 (file)
@@ -608,7 +608,7 @@ pub fn expect_gt(&self) {
             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 `{}`",
index 68af73d4a01cabd3499dcbc31a5fe3b7f3e1d46d..5e822165da8a3d02c15f18ee4b29dd2717973d31 100644 (file)
@@ -2115,7 +2115,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 {