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 | |
| parent | 97452c0ca16238a2de5503aca07db26ff9e8ba63 (diff) | |
| download | rust-2fe299d1a53355c9bb78b9067bd2d18bd4eb94e7.tar.gz rust-2fe299d1a53355c9bb78b9067bd2d18bd4eb94e7.zip | |
Extend ast_map to know about method declarations in traits.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast_map.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 |
4 files changed, 35 insertions, 10 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0dede78ffd0..5f62c2901f0 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -511,7 +511,7 @@ type ty_field = spanned<ty_field_>; #[auto_serialize] type ty_method = {ident: ident, attrs: ~[attribute], decl: fn_decl, tps: ~[ty_param], self_ty: self_ty, - span: span}; + id: node_id, span: span}; #[auto_serialize] // A trait method is either required (meaning it doesn't have an 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} diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 21d2de2d31b..119f4465d9e 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -316,6 +316,19 @@ fn split_class_items(cs: ~[@class_member]) -> (~[ivar], ~[@method]) { (vs, ms) } +// extract a ty_method from a trait_method. if the trait_method is +// a default, pull out the useful fields to make a ty_method +fn trait_method_to_ty_method(method: trait_method) -> ty_method { + alt method { + required(m) { m } + provided(m) { + {ident: m.ident, attrs: m.attrs, + decl: m.decl, tps: m.tps, self_ty: m.self_ty, + id: m.id, span: m.span} + } + } +} + pure fn class_member_visibility(ci: @class_member) -> visibility { alt ci.node { instance_var(_, _, _, _, vis) { vis } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7d5a088a04f..537e72f707f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -291,7 +291,7 @@ class parser { required({ident: ident, attrs: attrs, decl: {purity: pur with d}, tps: tps, self_ty: self_ty, - span: mk_sp(lo, hi)}) + id: p.get_id(), span: mk_sp(lo, hi)}) } token::LBRACE { debug!{"parse_trait_methods(): parsing provided method"}; |
