@@ -16,6 +16,7 @@ import util.common;
16
16
import util. common . span ;
17
17
18
18
import std. _str ;
19
+ import std. _uint ;
19
20
import std. _vec ;
20
21
import std. ebml ;
21
22
import std. fs ;
@@ -222,8 +223,22 @@ impure fn parse_ty_fn(@pstate st, str_def sd) -> tup(vec[ty.arg], @ty.t) {
222
223
223
224
// Rust metadata parsing
224
225
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 = 0 u;
228
+ auto len = _vec. len [ u8] ( buf) ;
229
+ while ( colon_idx < len && buf. ( colon_idx) != ( ':' as u8 ) ) {
230
+ colon_idx += 1 u;
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, 0 u, colon_idx) ;
238
+ auto def_part = _vec. slice [ u8] ( buf, colon_idx + 1 u, len) ;
239
+ auto crate_num = _uint. parse_buf ( crate_part, 10 u) as int ;
240
+ auto def_num = _uint. parse_buf ( def_part, 10 u) as int ;
241
+ ret tup( crate_num, def_num) ;
227
242
}
228
243
229
244
// 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 {
259
274
ebml. move_to_first_child ( ebml_r) ;
260
275
auto did_data = ebml. read_data ( ebml_r) ;
261
276
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) ) ;
265
278
}
266
279
ebml. move_to_next_sibling ( ebml_r) ;
267
280
}
@@ -395,6 +408,9 @@ fn lookup_def(session.session sess, &span sp, int cnum, vec[ast.ident] path)
395
408
}
396
409
}
397
410
411
+ log #fmt( "resolved '%s' to %d:%d" , _str. connect( path, "." ) , did. _0,
412
+ did. _1) ;
413
+
398
414
// TODO: Look up item type, use that to determine the type of def.
399
415
400
416
fail;
0 commit comments