Skip to content

Commit 0a67a35

Browse files
committed
---
yaml --- r: 36329 b: refs/heads/try2 c: 2374154 h: refs/heads/master i: 36327: aa1f05e v: v3
1 parent 03ae3fd commit 0a67a35

File tree

5 files changed

+40
-57
lines changed

5 files changed

+40
-57
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: 81d20156cd44358e47e5081635f28ea31c01a757
8+
refs/heads/try2: 2374154ded19a247be0053d71f5bcdd22b95462a
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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,15 @@ pub struct FileMap {
195195
name: FileName,
196196
substr: FileSubstr,
197197
src: @~str,
198-
start_pos: FilePos,
199-
mut lines: ~[FilePos],
198+
start_pos: BytePos,
199+
mut lines: ~[BytePos],
200200
multibyte_chars: DVec<MultiByteChar>
201201
}
202202

203203
pub impl FileMap {
204204
static fn new_w_substr(+filename: FileName, +substr: FileSubstr,
205205
src: @~str,
206-
+start_pos: FilePos)
206+
+start_pos: BytePos)
207207
-> FileMap {
208208
return FileMap {
209209
name: filename, substr: substr, src: src,
@@ -214,18 +214,18 @@ pub impl FileMap {
214214
}
215215

216216
static fn new(+filename: FileName, src: @~str,
217-
+start_pos: FilePos)
217+
+start_pos: BytePos)
218218
-> FileMap {
219219
return FileMap::new_w_substr(filename, FssNone, src,
220220
start_pos);
221221
}
222222

223-
fn next_line(&self, +pos: FilePos) {
223+
fn next_line(&self, +pos: BytePos) {
224224
self.lines.push(pos);
225225
}
226226

227227
pub fn get_line(&self, line: int) -> ~str unsafe {
228-
let begin: BytePos = self.lines[line].byte - self.start_pos.byte;
228+
let begin: BytePos = self.lines[line] - self.start_pos;
229229
let begin = begin.to_uint();
230230
let end = match str::find_char_from(*self.src, '\n', begin) {
231231
Some(e) => e,
@@ -266,11 +266,11 @@ pub impl CodeMap {
266266
let expected_byte_pos = if self.files.len() == 0 {
267267
0
268268
} else {
269-
let last_start = self.files.last().start_pos.byte.to_uint();
269+
let last_start = self.files.last().start_pos.to_uint();
270270
let last_len = self.files.last().src.len();
271271
last_start + last_len
272272
};
273-
let actual_byte_pos = filemap.start_pos.byte.to_uint();
273+
let actual_byte_pos = filemap.start_pos.to_uint();
274274
debug!("codemap: adding filemap: %s", filemap.name);
275275
debug!("codemap: expected offset: %u", expected_byte_pos);
276276
debug!("codemap: actual offset: %u", actual_byte_pos);
@@ -301,7 +301,7 @@ pub impl CodeMap {
301301
}
302302
FssInternal(sp) => {
303303
self.lookup_char_pos_adj(
304-
sp.lo + (pos - loc.file.start_pos.byte))
304+
sp.lo + (pos - loc.file.start_pos))
305305
}
306306
FssExternal(eloc) => {
307307
{filename: /* FIXME (#2543) */ copy eloc.filename,
@@ -318,8 +318,8 @@ pub impl CodeMap {
318318
FssNone => sp,
319319
FssInternal(s) => {
320320
self.adjust_span(span {
321-
lo: s.lo + (sp.lo - line.fm.start_pos.byte),
322-
hi: s.lo + (sp.hi - line.fm.start_pos.byte),
321+
lo: s.lo + (sp.lo - line.fm.start_pos),
322+
hi: s.lo + (sp.hi - line.fm.start_pos),
323323
expn_info: sp.expn_info
324324
})
325325
}
@@ -374,7 +374,7 @@ priv impl CodeMap {
374374
let mut b = len;
375375
while b - a > 1u {
376376
let m = (a + b) / 2u;
377-
if self.files[m].start_pos.byte > pos {
377+
if self.files[m].start_pos > pos {
378378
b = m;
379379
} else {
380380
a = m;
@@ -397,7 +397,7 @@ priv impl CodeMap {
397397
let mut b = vec::len(f.lines);
398398
while b - a > 1u {
399399
let m = (a + b) / 2u;
400-
if f.lines[m].byte > pos { b = m; } else { a = m; }
400+
if f.lines[m] > pos { b = m; } else { a = m; }
401401
}
402402
return {fm: f, line: a};
403403
}
@@ -406,7 +406,7 @@ priv impl CodeMap {
406406
let {fm: f, line: a} = self.lookup_line(pos);
407407
let line = a + 1u; // Line numbers start at 1
408408
let chpos = self.bytepos_to_local_charpos(pos);
409-
let linebpos = f.lines[a].byte;
409+
let linebpos = f.lines[a];
410410
let linechpos = self.bytepos_to_local_charpos(linebpos);
411411
debug!("codemap: byte pos %? is on the line at byte pos %?",
412412
pos, linebpos);
@@ -432,7 +432,7 @@ priv impl CodeMap {
432432
-> {fm: @FileMap, pos: BytePos} {
433433
let idx = self.lookup_filemap_idx(bpos);
434434
let fm = self.files[idx];
435-
let offset = bpos - fm.start_pos.byte;
435+
let offset = bpos - fm.start_pos;
436436
return {fm: fm, pos: offset};
437437
}
438438

branches/try2/src/libsyntax/parse.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type parse_sess = @{
2929
span_diagnostic: span_handler,
3030
interner: @ident_interner,
3131
// must be kept up to date
32-
mut pos: FilePos
32+
mut pos: BytePos
3333
};
3434

3535
fn new_parse_sess(demitter: Option<emitter>) -> parse_sess {
@@ -38,10 +38,8 @@ fn new_parse_sess(demitter: Option<emitter>) -> parse_sess {
3838
mut next_id: 1,
3939
span_diagnostic: mk_span_handler(mk_handler(demitter), cm),
4040
interner: mk_ident_interner(),
41-
mut pos: FilePos {
42-
ch: CharPos(0u),
43-
byte: BytePos(0u)
44-
}};
41+
mut pos: BytePos(0)
42+
};
4543
}
4644

4745
fn new_parse_sess_special_handler(sh: span_handler, cm: @codemap::CodeMap)
@@ -50,10 +48,8 @@ fn new_parse_sess_special_handler(sh: span_handler, cm: @codemap::CodeMap)
5048
mut next_id: 1,
5149
span_diagnostic: sh,
5250
interner: mk_ident_interner(),
53-
mut pos: FilePos {
54-
ch: CharPos(0u),
55-
byte: BytePos(0u)
56-
}};
51+
mut pos: BytePos(0)
52+
};
5753
}
5854

5955
fn parse_crate_from_file(input: &Path, cfg: ast::crate_cfg,
@@ -219,8 +215,5 @@ fn new_parser_from_tt(sess: parse_sess, cfg: ast::crate_cfg,
219215
}
220216

221217
fn update_parse_sess_position(sess: &parse_sess, r: &lexer::string_reader) {
222-
sess.pos = FilePos {
223-
ch: r.last_pos.ch,
224-
byte: r.last_pos.byte
225-
};
218+
sess.pos = r.last_pos
226219
}

branches/try2/src/libsyntax/parse/comments.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn consume_non_eol_whitespace(rdr: string_reader) {
131131
fn push_blank_line_comment(rdr: string_reader, comments: &mut ~[cmnt]) {
132132
debug!(">>> blank-line comment");
133133
let v: ~[~str] = ~[];
134-
comments.push({style: blank_line, lines: v, pos: rdr.last_pos.byte});
134+
comments.push({style: blank_line, lines: v, pos: rdr.last_pos});
135135
}
136136
137137
fn consume_whitespace_counting_blank_lines(rdr: string_reader,
@@ -148,7 +148,7 @@ fn consume_whitespace_counting_blank_lines(rdr: string_reader,
148148
fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool,
149149
comments: &mut ~[cmnt]) {
150150
debug!(">>> shebang comment");
151-
let p = rdr.last_pos.byte;
151+
let p = rdr.last_pos;
152152
debug!("<<< shebang comment");
153153
comments.push({
154154
style: if code_to_the_left { trailing } else { isolated },
@@ -160,7 +160,7 @@ fn read_shebang_comment(rdr: string_reader, code_to_the_left: bool,
160160
fn read_line_comments(rdr: string_reader, code_to_the_left: bool,
161161
comments: &mut ~[cmnt]) {
162162
debug!(">>> line comments");
163-
let p = rdr.last_pos.byte;
163+
let p = rdr.last_pos;
164164
let mut lines: ~[~str] = ~[];
165165
while rdr.curr == '/' && nextch(rdr) == '/' {
166166
let line = read_one_line_comment(rdr);
@@ -209,7 +209,7 @@ fn trim_whitespace_prefix_and_push_line(lines: &mut ~[~str],
209209
fn read_block_comment(rdr: string_reader, code_to_the_left: bool,
210210
comments: &mut ~[cmnt]) {
211211
debug!(">>> block comment");
212-
let p = rdr.last_pos.byte;
212+
let p = rdr.last_pos;
213213
let mut lines: ~[~str] = ~[];
214214
let mut col: CharPos = rdr.col;
215215
bump(rdr);
@@ -292,11 +292,7 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
292292
{cmnts: ~[cmnt], lits: ~[lit]} {
293293
let src = @str::from_bytes(srdr.read_whole_stream());
294294
let itr = parse::token::mk_fake_ident_interner();
295-
let filemap = @FileMap::new(path, src,
296-
FilePos {
297-
ch: CharPos(0u),
298-
byte: BytePos(0u)
299-
});
295+
let filemap = @FileMap::new(path, src, BytePos(0));
300296
let rdr = lexer::new_low_level_string_reader(
301297
span_diagnostic, filemap, itr);
302298
@@ -319,7 +315,7 @@ fn gather_comments_and_literals(span_diagnostic: diagnostic::span_handler,
319315
}
320316
321317
322-
let bstart = rdr.pos.byte;
318+
let bstart = rdr.pos;
323319
rdr.next_token();
324320
//discard, and look ahead; we're working with internal state
325321
let {tok: tok, sp: sp} = rdr.peek();

branches/try2/src/libsyntax/parse/lexer.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ type string_reader = @{
2222
span_diagnostic: span_handler,
2323
src: @~str,
2424
// The absolute offset within the codemap of the next character to read
25-
mut pos: FilePos,
25+
mut pos: BytePos,
2626
// The absolute offset within the codemap of the last character read(curr)
27-
mut last_pos: FilePos,
27+
mut last_pos: BytePos,
2828
// The column of the next character to read
2929
mut col: CharPos,
3030
// The last character to be read
@@ -123,15 +123,15 @@ fn string_advance_token(&&r: string_reader) {
123123
if is_eof(r) {
124124
r.peek_tok = token::EOF;
125125
} else {
126-
let start_bytepos = r.last_pos.byte;
126+
let start_bytepos = r.last_pos;
127127
r.peek_tok = next_token_inner(r);
128-
r.peek_span = ast_util::mk_sp(start_bytepos, r.last_pos.byte);
128+
r.peek_span = ast_util::mk_sp(start_bytepos, r.last_pos);
129129
};
130130

131131
}
132132

133133
fn byte_offset(rdr: string_reader) -> BytePos {
134-
(rdr.pos.byte - rdr.filemap.start_pos.byte)
134+
(rdr.pos - rdr.filemap.start_pos)
135135
}
136136

137137
fn get_str_from(rdr: string_reader, start: BytePos) -> ~str unsafe {
@@ -148,10 +148,7 @@ fn bump(rdr: string_reader) {
148148
let last_char = rdr.curr;
149149
let next = str::char_range_at(*rdr.src, current_byte_offset);
150150
let byte_offset_diff = next.next - current_byte_offset;
151-
rdr.pos = FilePos {
152-
ch: rdr.pos.ch + CharPos(1u),
153-
byte: rdr.pos.byte + BytePos(byte_offset_diff)
154-
};
151+
rdr.pos = rdr.pos + BytePos(byte_offset_diff);
155152
rdr.curr = next.ch;
156153
rdr.col += CharPos(1u);
157154
if last_char == '\n' {
@@ -166,10 +163,7 @@ fn bump(rdr: string_reader) {
166163
} else {
167164
// XXX: What does this accomplish?
168165
if (rdr.curr != -1 as char) {
169-
rdr.pos = FilePos {
170-
ch: rdr.pos.ch + CharPos(1u),
171-
byte: rdr.pos.byte + BytePos(1u)
172-
};
166+
rdr.pos = rdr.pos + BytePos(1u);
173167
rdr.col += CharPos(1u);
174168
rdr.curr = -1 as char;
175169
}
@@ -238,15 +232,15 @@ fn consume_any_line_comment(rdr: string_reader)
238232
bump(rdr);
239233
// line comments starting with "///" or "//!" are doc-comments
240234
if rdr.curr == '/' || rdr.curr == '!' {
241-
let start_bpos = rdr.pos.byte - BytePos(2u);
235+
let start_bpos = rdr.pos - BytePos(2u);
242236
let mut acc = ~"//";
243237
while rdr.curr != '\n' && !is_eof(rdr) {
244238
str::push_char(&mut acc, rdr.curr);
245239
bump(rdr);
246240
}
247241
return Some({
248242
tok: token::DOC_COMMENT(rdr.interner.intern(@acc)),
249-
sp: ast_util::mk_sp(start_bpos, rdr.pos.byte)
243+
sp: ast_util::mk_sp(start_bpos, rdr.pos)
250244
});
251245
} else {
252246
while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); }
@@ -261,7 +255,7 @@ fn consume_any_line_comment(rdr: string_reader)
261255
if nextch(rdr) == '!' {
262256
let cmap = @CodeMap::new();
263257
(*cmap).files.push(rdr.filemap);
264-
let loc = cmap.lookup_char_pos_adj(rdr.last_pos.byte);
258+
let loc = cmap.lookup_char_pos_adj(rdr.last_pos);
265259
if loc.line == 1u && loc.col == CharPos(0u) {
266260
while rdr.curr != '\n' && !is_eof(rdr) { bump(rdr); }
267261
return consume_whitespace_and_comments(rdr);
@@ -277,7 +271,7 @@ fn consume_block_comment(rdr: string_reader)
277271

278272
// block comments starting with "/**" or "/*!" are doc-comments
279273
if rdr.curr == '*' || rdr.curr == '!' {
280-
let start_bpos = rdr.pos.byte - BytePos(2u);
274+
let start_bpos = rdr.pos - BytePos(2u);
281275
let mut acc = ~"/*";
282276
while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
283277
str::push_char(&mut acc, rdr.curr);
@@ -291,7 +285,7 @@ fn consume_block_comment(rdr: string_reader)
291285
bump(rdr);
292286
return Some({
293287
tok: token::DOC_COMMENT(rdr.interner.intern(@acc)),
294-
sp: ast_util::mk_sp(start_bpos, rdr.pos.byte)
288+
sp: ast_util::mk_sp(start_bpos, rdr.pos)
295289
});
296290
}
297291
} else {

0 commit comments

Comments
 (0)