diff options
| author | Michael Sullivan <sully@msully.net> | 2012-08-02 15:52:25 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2012-08-02 16:02:30 -0700 |
| commit | 2fe299d1a53355c9bb78b9067bd2d18bd4eb94e7 (patch) | |
| tree | 39464d3cdfd3f2d9f75a2fc4f49e72454b61e475 /src/libsyntax/ast_map.rs | |
| parent | 97452c0ca16238a2de5503aca07db26ff9e8ba63 (diff) | |
Extend ast_map to know about method declarations in traits.
Diffstat (limited to 'src/libsyntax/ast_map.rs')
| -rw-r--r-- | src/libsyntax/ast_map.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/libsyntax/ast_map.rs b/src/libsyntax/ast_map.rs index 90330db78a7..acd20951328 100644 --- a/src/libsyntax/ast_map.rs +++ b/src/libsyntax/ast_map.rs @@ -35,6 +35,8 @@ fn path_to_str(p: path) -> ~str { enum ast_node { node_item(@item, @path), node_foreign_item(@foreign_item, foreign_abi, @path), + node_trait_method(@trait_method, def_id /* trait did */, + @path /* path to the trait */), node_method(@method, def_id /* impl did */, @path /* path to the impl */), node_variant(variant, @item, @path), node_expr(@expr), @@ -218,19 +220,24 @@ fn map_item(i: @item, cx: ctx, v: vt) { let (_, ms) = ast_util::split_class_items(items); // Map trait refs to their parent classes. This is // so we can find the self_ty - do vec::iter(traits) |p| { cx.map.insert(p.ref_id, - node_item(i, item_path)); - // This is so we can look up the right things when - // encoding/decoding - cx.map.insert(p.impl_id, - node_item(i, item_path)); - - }; + for traits.each |p| { + cx.map.insert(p.ref_id, node_item(i, item_path)); + // This is so we can look up the right things when + // encoding/decoding + cx.map.insert(p.impl_id, node_item(i, item_path)); + } let d_id = ast_util::local_def(i.id); let p = extend(cx, i.ident); // only need to handle methods do vec::iter(ms) |m| { map_method(d_id, p, m, cx); } } + item_trait(tps, methods) { + for methods.each |tm| { + let id = ast_util::trait_method_to_ty_method(tm).id; + let d_id = ast_util::local_def(i.id); + cx.map.insert(id, node_trait_method(@tm, d_id, item_path)); + } + } _ { } } alt i.node { @@ -283,6 +290,11 @@ fn node_id_to_str(map: map, id: node_id) -> ~str { fmt!{"method %s in %s (id=%?)", *m.ident, path_to_str(*path), id} } + some(node_trait_method(tm, impl_did, path)) { + let m = ast_util::trait_method_to_ty_method(*tm); + fmt!{"method %s in %s (id=%?)", + *m.ident, path_to_str(*path), id} + } some(node_variant(variant, def_id, path)) { fmt!{"variant %s in %s (id=%?)", *variant.node.name, path_to_str(*path), id} |
