diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2012-02-10 06:01:32 -0800 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2012-02-10 20:48:28 -0800 |
| commit | fdddf8f9e1d6738d42989a6d8a735dd58127e199 (patch) | |
| tree | 9e324f85345957929daed40aedeaf52d0199b33d /src/comp/middle | |
| parent | dbcb54f4dc44957c9505958655a16e678ee4396b (diff) | |
put serializer into the build and encode full item paths
Diffstat (limited to 'src/comp/middle')
| -rw-r--r-- | src/comp/middle/ast_map.rs | 14 | ||||
| -rw-r--r-- | src/comp/middle/ty.rs | 39 |
2 files changed, 53 insertions, 0 deletions
diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index ca3885d89d7..1504f5f738e 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -6,6 +6,20 @@ import syntax::{visit, codemap}; enum path_elt { path_mod(str), path_name(str) } type path = [path_elt]; +fn path_to_str_with_sep(p: path, sep: str) -> str { + let strs = vec::map(p) {|e| + alt e { + path_mod(s) { s } + path_name(s) { s } + } + }; + str::connect(strs, sep) +} + +fn path_to_str(p: path) -> str { + path_to_str_with_sep(p, "::") +} + enum ast_node { node_item(@item, @path), node_native_item(@native_item, @path), diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs index 5c6e956508f..019ba856e98 100644 --- a/src/comp/middle/ty.rs +++ b/src/comp/middle/ty.rs @@ -128,6 +128,7 @@ export ck_uniq; export param_bound, param_bounds, bound_copy, bound_send, bound_iface; export param_bounds_to_kind; export default_arg_mode_for_ty; +export item_path; // Data types @@ -2371,6 +2372,44 @@ fn substd_enum_variants(cx: ctxt, id: ast::def_id, tps: [ty::t]) } } +fn item_path(cx: ctxt, id: ast::def_id) -> ast_map::path { + if id.crate != ast::local_crate { + csearch::get_item_path(cx, id) + } else { + let node = cx.items.get(id.node); + alt node { + ast_map::node_item(item, path) { + let item_elt = alt item.node { + item_mod(_) | item_native_mod(_) { + ast_map::path_mod(item.ident) + } + _ { + ast_map::path_name(item.ident) + } + }; + *path + [item_elt] + } + + ast_map::node_native_item(nitem, path) { + *path + [ast_map::path_name(nitem.ident)] + } + + ast_map::node_method(method, path) { + *path + [ast_map::path_name(method.ident)] + } + + ast_map::node_variant(variant, _, path) { + vec::init(*path) + [ast_map::path_name(variant.node.name)] + } + + ast_map::node_expr(_) | ast_map::node_arg(_, _) | + ast_map::node_local(_) | ast_map::node_res_ctor(_) { + cx.sess.bug(#fmt["cannot find item_path for node %?", node]); + } + } + } +} + fn enum_variants(cx: ctxt, id: ast::def_id) -> @[variant_info] { alt cx.enum_var_cache.find(id) { some(variants) { ret variants; } |
