aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <[email protected]>2011-03-25 18:34:21 -0700
committerPatrick Walton <[email protected]>2011-03-25 18:35:30 -0700
commit24a75eeccc7990e2c15e47c31283705f6091f752 (patch)
tree85ad91e31f3b2ccf1385a4992b05186ffe5e5d20 /src
parentAdd get_extern_const, factor get_extern into get_extern_fn and get_simple_ext... (diff)
downloadrust-24a75eeccc7990e2c15e47c31283705f6091f752.tar.xz
rust-24a75eeccc7990e2c15e47c31283705f6091f752.zip
rustc: Parse definition IDs from crates; add a function to parse unsigned ints to the standard library
Diffstat (limited to 'src')
-rw-r--r--src/comp/front/creader.rs26
-rw-r--r--src/lib/_uint.rs12
2 files changed, 33 insertions, 5 deletions
diff --git a/src/comp/front/creader.rs b/src/comp/front/creader.rs
index 977b7186..01203226 100644
--- a/src/comp/front/creader.rs
+++ b/src/comp/front/creader.rs
@@ -16,6 +16,7 @@ import util.common;
import util.common.span;
import std._str;
+import std._uint;
import std._vec;
import std.ebml;
import std.fs;
@@ -222,8 +223,22 @@ impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
// Rust metadata parsing
-fn parse_def_id(str s) -> ast.def_id {
- ret tup(1, 0); // TODO
+fn parse_def_id(vec[u8] buf) -> ast.def_id {
+ auto colon_idx = 0u;
+ auto len = _vec.len[u8](buf);
+ while (colon_idx < len && buf.(colon_idx) != (':' as u8)) {
+ colon_idx += 1u;
+ }
+ if (colon_idx == len) {
+ log "didn't find ':' when parsing def id";
+ fail;
+ }
+
+ auto crate_part = _vec.slice[u8](buf, 0u, colon_idx);
+ auto def_part = _vec.slice[u8](buf, colon_idx + 1u, len);
+ auto crate_num = _uint.parse_buf(crate_part, 10u) as int;
+ auto def_num = _uint.parse_buf(def_part, 10u) as int;
+ ret tup(crate_num, def_num);
}
// 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 {
ebml.move_to_first_child(ebml_r);
auto did_data = ebml.read_data(ebml_r);
ebml.move_to_parent(ebml_r);
- auto did_str = _str.unsafe_from_bytes(did_data);
- log "did_str: " + did_str;
- did_opt = some[ast.def_id](parse_def_id(did_str));
+ did_opt = some[ast.def_id](parse_def_id(did_data));
}
ebml.move_to_next_sibling(ebml_r);
}
@@ -395,6 +408,9 @@ fn lookup_def(session.session sess, &span sp, int cnum, vec[ast.ident] path)
}
}
+ log #fmt("resolved '%s' to %d:%d", _str.connect(path, "."), did._0,
+ did._1);
+
// TODO: Look up item type, use that to determine the type of def.
fail;
diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs
index f456b733..f6686b5d 100644
--- a/src/lib/_uint.rs
+++ b/src/lib/_uint.rs
@@ -33,6 +33,18 @@ fn next_power_of_two(uint n) -> uint {
ret tmp + 1u;
}
+fn parse_buf(vec[u8] buf, uint radix) -> uint {
+ auto i = _vec.len[u8](buf) - 1u;
+ auto power = 1u;
+ auto n = 0u;
+ while (i >= 0u) {
+ n += (((buf.(i)) - ('0' as u8)) as uint) * power;
+ power *= radix;
+ i -= 1u;
+ }
+ ret n;
+}
+
fn to_str(uint num, uint radix) -> str
{
auto n = num;