Skip to content

Commit 8da4f25

Browse files
committed
---
yaml --- r: 36258 b: refs/heads/try2 c: b22f941 h: refs/heads/master v: v3
1 parent 4af6174 commit 8da4f25

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 2ec09c4eb91b94bd68c95eaa8966d4801c3347bf
8+
refs/heads/try2: b22f94148720e1ece7e16afe92f91d998ac9af34
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/src/libsyntax/codemap.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ use std::serialization::{Serializable,
1010
Serializer,
1111
Deserializer};
1212

13+
pub type byte_pos = uint;
14+
pub type char_pos = uint;
15+
1316
pub struct span {
14-
lo: uint,
15-
hi: uint,
17+
lo: char_pos,
18+
hi: char_pos,
1619
expn_info: Option<@expn_info>
1720
}
1821

@@ -34,30 +37,30 @@ impl<D: Deserializer> span: Deserializable<D> {
3437
}
3538
}
3639

37-
pub enum expn_info {
38-
expanded_from({call_site: span,
39-
callie: {name: ~str, span: Option<span>}})
40+
pub struct file_pos {
41+
ch: char_pos, byte: byte_pos
4042
}
4143

42-
pub type filename = ~str;
43-
44-
pub type lookup_fn = pure fn(file_pos) -> uint;
45-
4644
pub struct loc {
4745
file: @filemap, line: uint, col: uint
4846
}
4947

50-
pub struct file_pos {
51-
ch: uint, byte: uint
52-
}
53-
5448
impl file_pos : cmp::Eq {
5549
pure fn eq(other: &file_pos) -> bool {
5650
self.ch == (*other).ch && self.byte == (*other).byte
5751
}
5852
pure fn ne(other: &file_pos) -> bool { !self.eq(other) }
5953
}
6054

55+
pub enum expn_info {
56+
expanded_from({call_site: span,
57+
callie: {name: ~str, span: Option<span>}})
58+
}
59+
60+
pub type filename = ~str;
61+
62+
pub type lookup_fn = pure fn(file_pos) -> uint;
63+
6164
pub struct file_lines {
6265
file: @filemap,
6366
lines: ~[uint]
@@ -90,13 +93,13 @@ pub impl filemap {
9093
}
9194

9295
static fn new(+filename: filename, src: @~str,
93-
start_pos_ch: uint, start_pos_byte: uint)
96+
start_pos_ch: char_pos, start_pos_byte: byte_pos)
9497
-> filemap {
9598
return filemap::new_w_substr(filename, fss_none, src,
9699
start_pos_ch, start_pos_byte);
97100
}
98101

99-
fn next_line(@self, chpos: uint, byte_pos: uint) {
102+
fn next_line(@self, chpos: char_pos, byte_pos: byte_pos) {
100103
self.lines.push(file_pos {ch: chpos, byte: byte_pos + self.start_pos.byte});
101104
}
102105

@@ -127,17 +130,17 @@ pub impl CodeMap {
127130
return fmt!("<%s:%u:%u>", pos.file.name, pos.line, pos.col);
128131
}
129132

130-
pub fn lookup_char_pos(@self, pos: uint) -> loc {
133+
pub fn lookup_char_pos(@self, pos: char_pos) -> loc {
131134
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
132135
return self.lookup_pos(pos, lookup);
133136
}
134137

135-
pub fn lookup_byte_pos(@self, pos: uint) -> loc {
138+
pub fn lookup_byte_pos(@self, pos: byte_pos) -> loc {
136139
pure fn lookup(pos: file_pos) -> uint { return pos.byte; }
137140
return self.lookup_pos(pos, lookup);
138141
}
139142

140-
pub fn lookup_char_pos_adj(@self, pos: uint)
143+
pub fn lookup_char_pos_adj(@self, pos: char_pos)
141144
-> {filename: ~str, line: uint, col: uint, file: Option<@filemap>}
142145
{
143146
let loc = self.lookup_char_pos(pos);
@@ -195,8 +198,8 @@ pub impl CodeMap {
195198
return @file_lines {file: lo.file, lines: lines};
196199
}
197200

198-
fn lookup_byte_offset(@self, chpos: uint)
199-
-> {fm: @filemap, pos: uint} {
201+
fn lookup_byte_offset(@self, chpos: char_pos)
202+
-> {fm: @filemap, pos: byte_pos} {
200203
pure fn lookup(pos: file_pos) -> uint { return pos.ch; }
201204
let {fm, line} = self.lookup_line(chpos, lookup);
202205
let line_offset = fm.lines[line].byte - fm.start_pos.byte;

0 commit comments

Comments
 (0)