@@ -18,6 +18,7 @@ use parse::token;
18
18
use parse:: token:: { str_to_ident} ;
19
19
20
20
use std:: cast:: transmute;
21
+ use std:: cell:: Cell ;
21
22
use std:: char;
22
23
use std:: num:: from_str_radix;
23
24
use std:: util;
@@ -43,7 +44,7 @@ pub struct StringReader {
43
44
span_diagnostic : @mut SpanHandler ,
44
45
src : @str ,
45
46
// The absolute offset within the codemap of the next character to read
46
- pos : BytePos ,
47
+ pos : Cell < BytePos > ,
47
48
// The absolute offset within the codemap of the last character read(curr)
48
49
last_pos : BytePos ,
49
50
// The column of the next character to read
@@ -73,7 +74,7 @@ pub fn new_low_level_string_reader(span_diagnostic: @mut SpanHandler,
73
74
let r = @mut StringReader {
74
75
span_diagnostic : span_diagnostic,
75
76
src : filemap. src ,
76
- pos : filemap. start_pos ,
77
+ pos : Cell :: new ( filemap. start_pos ) ,
77
78
last_pos : filemap. start_pos ,
78
79
col : CharPos ( 0 ) ,
79
80
curr : initial_char,
@@ -93,7 +94,7 @@ fn dup_string_reader(r: @mut StringReader) -> @mut StringReader {
93
94
@mut StringReader {
94
95
span_diagnostic : r. span_diagnostic ,
95
96
src : r. src ,
96
- pos : r. pos ,
97
+ pos : Cell :: new ( r. pos . get ( ) ) ,
97
98
last_pos : r. last_pos ,
98
99
col : r. col ,
99
100
curr : r. curr ,
@@ -239,14 +240,14 @@ fn with_str_from_to<T>(
239
240
// EFFECT: advance the StringReader by one character. If a newline is
240
241
// discovered, add it to the FileMap's list of line start offsets.
241
242
pub fn bump ( rdr : & mut StringReader ) {
242
- rdr. last_pos = rdr. pos ;
243
- let current_byte_offset = byte_offset ( rdr, rdr. pos ) . to_uint ( ) ;
243
+ rdr. last_pos = rdr. pos . get ( ) ;
244
+ let current_byte_offset = byte_offset ( rdr, rdr. pos . get ( ) ) . to_uint ( ) ;
244
245
if current_byte_offset < ( rdr. src ) . len ( ) {
245
246
assert ! ( rdr. curr != unsafe { transmute( -1u32 ) } ) ; // FIXME: #8971: unsound
246
247
let last_char = rdr. curr ;
247
248
let next = rdr. src . char_range_at ( current_byte_offset) ;
248
249
let byte_offset_diff = next. next - current_byte_offset;
249
- rdr. pos = rdr. pos + Pos :: from_uint ( byte_offset_diff) ;
250
+ rdr. pos . set ( rdr. pos . get ( ) + Pos :: from_uint ( byte_offset_diff) ) ;
250
251
rdr. curr = next. ch ;
251
252
rdr. col = rdr. col + CharPos ( 1 u) ;
252
253
if last_char == '\n' {
@@ -266,7 +267,7 @@ pub fn is_eof(rdr: @mut StringReader) -> bool {
266
267
rdr. curr == unsafe { transmute ( -1u32 ) } // FIXME: #8971: unsound
267
268
}
268
269
pub fn nextch ( rdr : @mut StringReader ) -> char {
269
- let offset = byte_offset ( rdr, rdr. pos ) . to_uint ( ) ;
270
+ let offset = byte_offset ( rdr, rdr. pos . get ( ) ) . to_uint ( ) ;
270
271
if offset < ( rdr. src ) . len ( ) {
271
272
return rdr. src . char_at ( offset) ;
272
273
} else { return unsafe { transmute ( -1u32 ) } ; } // FIXME: #8971: unsound
@@ -318,7 +319,7 @@ fn consume_any_line_comment(rdr: @mut StringReader)
318
319
bump ( rdr) ;
319
320
// line comments starting with "///" or "//!" are doc-comments
320
321
if rdr. curr == '/' || rdr. curr == '!' {
321
- let start_bpos = rdr. pos - BytePos ( 3 ) ;
322
+ let start_bpos = rdr. pos . get ( ) - BytePos ( 3 ) ;
322
323
while rdr. curr != '\n' && !is_eof ( rdr) {
323
324
bump ( rdr) ;
324
325
}
@@ -327,7 +328,7 @@ fn consume_any_line_comment(rdr: @mut StringReader)
327
328
if !is_line_non_doc_comment ( string) {
328
329
Some ( TokenAndSpan {
329
330
tok : token:: DOC_COMMENT ( str_to_ident ( string) ) ,
330
- sp : codemap:: mk_sp ( start_bpos, rdr. pos )
331
+ sp : codemap:: mk_sp ( start_bpos, rdr. pos . get ( ) )
331
332
} )
332
333
} else {
333
334
None
@@ -371,7 +372,7 @@ fn consume_block_comment(rdr: @mut StringReader)
371
372
-> Option < TokenAndSpan > {
372
373
// block comments starting with "/**" or "/*!" are doc-comments
373
374
let is_doc_comment = rdr. curr == '*' || rdr. curr == '!' ;
374
- let start_bpos = rdr. pos - BytePos ( if is_doc_comment { 3 } else { 2 } ) ;
375
+ let start_bpos = rdr. pos . get ( ) - BytePos ( if is_doc_comment { 3 } else { 2 } ) ;
375
376
376
377
let mut level: int = 1 ;
377
378
while level > 0 {
@@ -401,7 +402,7 @@ fn consume_block_comment(rdr: @mut StringReader)
401
402
if !is_block_non_doc_comment ( string) {
402
403
Some ( TokenAndSpan {
403
404
tok : token:: DOC_COMMENT ( str_to_ident ( string) ) ,
404
- sp : codemap:: mk_sp ( start_bpos, rdr. pos )
405
+ sp : codemap:: mk_sp ( start_bpos, rdr. pos . get ( ) )
405
406
} )
406
407
} else {
407
408
None
@@ -592,7 +593,7 @@ fn scan_numeric_escape(rdr: @mut StringReader, n_hex_digits: uint) -> char {
592
593
while i != 0 u {
593
594
let n = rdr. curr ;
594
595
if !is_hex_digit ( n) {
595
- fatal_span_char ( rdr, rdr. last_pos , rdr. pos ,
596
+ fatal_span_char ( rdr, rdr. last_pos , rdr. pos . get ( ) ,
596
597
~"illegal character in numeric character escape",
597
598
n) ;
598
599
}
@@ -932,7 +933,7 @@ fn next_token_inner(rdr: @mut StringReader) -> token::Token {
932
933
'^' => { return binop ( rdr, token:: CARET ) ; }
933
934
'%' => { return binop ( rdr, token:: PERCENT ) ; }
934
935
c => {
935
- fatal_span_char ( rdr, rdr. last_pos , rdr. pos ,
936
+ fatal_span_char ( rdr, rdr. last_pos , rdr. pos . get ( ) ,
936
937
~"unknown start of token", c) ;
937
938
}
938
939
}
0 commit comments