@@ -10,9 +10,12 @@ use std::serialization::{Serializable,
10
10
Serializer ,
11
11
Deserializer } ;
12
12
13
+ pub type byte_pos = uint ;
14
+ pub type char_pos = uint ;
15
+
13
16
pub struct span {
14
- lo : uint ,
15
- hi : uint ,
17
+ lo : char_pos ,
18
+ hi : char_pos ,
16
19
expn_info : Option < @expn_info >
17
20
}
18
21
@@ -34,30 +37,30 @@ impl<D: Deserializer> span: Deserializable<D> {
34
37
}
35
38
}
36
39
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
40
42
}
41
43
42
- pub type filename = ~str ;
43
-
44
- pub type lookup_fn = pure fn( file_pos ) -> uint ;
45
-
46
44
pub struct loc {
47
45
file : @filemap , line : uint , col : uint
48
46
}
49
47
50
- pub struct file_pos {
51
- ch : uint , byte : uint
52
- }
53
-
54
48
impl file_pos : cmp:: Eq {
55
49
pure fn eq ( other : & file_pos ) -> bool {
56
50
self . ch == ( * other) . ch && self . byte == ( * other) . byte
57
51
}
58
52
pure fn ne ( other : & file_pos ) -> bool { !self . eq ( other) }
59
53
}
60
54
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
+
61
64
pub struct file_lines {
62
65
file : @filemap ,
63
66
lines : ~[ uint ]
@@ -90,13 +93,13 @@ pub impl filemap {
90
93
}
91
94
92
95
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 )
94
97
-> filemap {
95
98
return filemap:: new_w_substr ( filename, fss_none, src,
96
99
start_pos_ch, start_pos_byte) ;
97
100
}
98
101
99
- fn next_line ( @self , chpos : uint , byte_pos : uint ) {
102
+ fn next_line ( @self , chpos : char_pos , byte_pos : byte_pos ) {
100
103
self . lines . push ( file_pos { ch : chpos, byte : byte_pos + self . start_pos . byte } ) ;
101
104
}
102
105
@@ -127,17 +130,17 @@ pub impl CodeMap {
127
130
return fmt ! ( "<%s:%u:%u>" , pos. file. name, pos. line, pos. col) ;
128
131
}
129
132
130
- pub fn lookup_char_pos ( @self , pos : uint ) -> loc {
133
+ pub fn lookup_char_pos ( @self , pos : char_pos ) -> loc {
131
134
pure fn lookup ( pos : file_pos ) -> uint { return pos. ch ; }
132
135
return self . lookup_pos ( pos, lookup) ;
133
136
}
134
137
135
- pub fn lookup_byte_pos ( @self , pos : uint ) -> loc {
138
+ pub fn lookup_byte_pos ( @self , pos : byte_pos ) -> loc {
136
139
pure fn lookup ( pos : file_pos ) -> uint { return pos. byte ; }
137
140
return self . lookup_pos ( pos, lookup) ;
138
141
}
139
142
140
- pub fn lookup_char_pos_adj ( @self , pos : uint )
143
+ pub fn lookup_char_pos_adj ( @self , pos : char_pos )
141
144
-> { filename : ~str , line : uint , col : uint , file : Option < @filemap > }
142
145
{
143
146
let loc = self . lookup_char_pos ( pos) ;
@@ -195,8 +198,8 @@ pub impl CodeMap {
195
198
return @file_lines { file : lo. file , lines : lines} ;
196
199
}
197
200
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 } {
200
203
pure fn lookup ( pos : file_pos ) -> uint { return pos. ch ; }
201
204
let { fm, line} = self . lookup_line ( chpos, lookup) ;
202
205
let line_offset = fm. lines [ line] . byte - fm. start_pos . byte ;
0 commit comments