Skip to content

Commit 36b826b

Browse files
committed
---
yaml --- r: 1875 b: refs/heads/master c: 24a75ee h: refs/heads/master i: 1873: 87fcfa6 1871: 636900e v: v3
1 parent 78a2184 commit 36b826b

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: ee686dacb8a2582309e6562d5c37b4cdc776482c
2+
refs/heads/master: 24a75eeccc7990e2c15e47c31283705f6091f752

trunk/src/comp/front/creader.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import util.common;
1616
import util.common.span;
1717

1818
import std._str;
19+
import std._uint;
1920
import std._vec;
2021
import std.ebml;
2122
import std.fs;
@@ -222,8 +223,22 @@ impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
222223

223224
// Rust metadata parsing
224225

225-
fn parse_def_id(str s) -> ast.def_id {
226-
ret tup(1, 0); // TODO
226+
fn parse_def_id(vec[u8] buf) -> ast.def_id {
227+
auto colon_idx = 0u;
228+
auto len = _vec.len[u8](buf);
229+
while (colon_idx < len && buf.(colon_idx) != (':' as u8)) {
230+
colon_idx += 1u;
231+
}
232+
if (colon_idx == len) {
233+
log "didn't find ':' when parsing def id";
234+
fail;
235+
}
236+
237+
auto crate_part = _vec.slice[u8](buf, 0u, colon_idx);
238+
auto def_part = _vec.slice[u8](buf, colon_idx + 1u, len);
239+
auto crate_num = _uint.parse_buf(crate_part, 10u) as int;
240+
auto def_num = _uint.parse_buf(def_part, 10u) as int;
241+
ret tup(crate_num, def_num);
227242
}
228243

229244
// Given a path and serialized crate metadata, returns the ID of the
@@ -259,9 +274,7 @@ impure fn resolve_path(vec[ast.ident] path, vec[u8] data) -> resolve_result {
259274
ebml.move_to_first_child(ebml_r);
260275
auto did_data = ebml.read_data(ebml_r);
261276
ebml.move_to_parent(ebml_r);
262-
auto did_str = _str.unsafe_from_bytes(did_data);
263-
log "did_str: " + did_str;
264-
did_opt = some[ast.def_id](parse_def_id(did_str));
277+
did_opt = some[ast.def_id](parse_def_id(did_data));
265278
}
266279
ebml.move_to_next_sibling(ebml_r);
267280
}
@@ -395,6 +408,9 @@ fn lookup_def(session.session sess, &span sp, int cnum, vec[ast.ident] path)
395408
}
396409
}
397410

411+
log #fmt("resolved '%s' to %d:%d", _str.connect(path, "."), did._0,
412+
did._1);
413+
398414
// TODO: Look up item type, use that to determine the type of def.
399415

400416
fail;

trunk/src/lib/_uint.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ fn next_power_of_two(uint n) -> uint {
3333
ret tmp + 1u;
3434
}
3535

36+
fn parse_buf(vec[u8] buf, uint radix) -> uint {
37+
auto i = _vec.len[u8](buf) - 1u;
38+
auto power = 1u;
39+
auto n = 0u;
40+
while (i >= 0u) {
41+
n += (((buf.(i)) - ('0' as u8)) as uint) * power;
42+
power *= radix;
43+
i -= 1u;
44+
}
45+
ret n;
46+
}
47+
3648
fn to_str(uint num, uint radix) -> str
3749
{
3850
auto n = num;

0 commit comments

Comments
 (0)