2012-01-19 01:48:25 -06:00
|
|
|
#[doc = "Records the full path to items"];
|
|
|
|
|
|
|
|
export mk_pass;
|
|
|
|
|
2012-02-27 20:07:16 -06:00
|
|
|
fn mk_pass() -> pass {
|
|
|
|
{
|
|
|
|
name: "path",
|
|
|
|
f: run
|
|
|
|
}
|
|
|
|
}
|
2012-01-19 01:48:25 -06:00
|
|
|
|
|
|
|
type ctxt = {
|
|
|
|
srv: astsrv::srv,
|
|
|
|
mutable path: [str]
|
|
|
|
};
|
|
|
|
|
|
|
|
fn run(srv: astsrv::srv, doc: doc::cratedoc) -> doc::cratedoc {
|
|
|
|
let ctxt = {
|
|
|
|
srv: srv,
|
|
|
|
mutable path: []
|
|
|
|
};
|
|
|
|
let fold = fold::fold({
|
2012-02-17 19:48:37 -06:00
|
|
|
fold_item: fold_item,
|
2012-02-24 16:08:47 -06:00
|
|
|
fold_mod: fold_mod,
|
|
|
|
fold_nmod: fold_nmod
|
2012-02-21 00:24:59 -06:00
|
|
|
with *fold::default_any_fold(ctxt)
|
2012-01-19 01:48:25 -06:00
|
|
|
});
|
|
|
|
fold.fold_crate(fold, doc)
|
|
|
|
}
|
|
|
|
|
2012-02-17 19:48:37 -06:00
|
|
|
fn fold_item(fold: fold::fold<ctxt>, doc: doc::itemdoc) -> doc::itemdoc {
|
|
|
|
{
|
|
|
|
path: fold.ctxt.path
|
|
|
|
with doc
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-19 01:48:25 -06:00
|
|
|
fn fold_mod(fold: fold::fold<ctxt>, doc: doc::moddoc) -> doc::moddoc {
|
2012-02-17 16:46:30 -06:00
|
|
|
let is_topmod = doc.id() == rustc::syntax::ast::crate_node_id;
|
2012-01-19 01:48:25 -06:00
|
|
|
|
2012-02-17 16:46:30 -06:00
|
|
|
if !is_topmod { vec::push(fold.ctxt.path, doc.name()); }
|
2012-02-21 00:24:59 -06:00
|
|
|
let doc = fold::default_any_fold_mod(fold, doc);
|
2012-01-19 01:48:25 -06:00
|
|
|
if !is_topmod { vec::pop(fold.ctxt.path); }
|
2012-02-17 19:48:37 -06:00
|
|
|
|
2012-01-30 15:05:25 -06:00
|
|
|
{
|
2012-02-17 19:48:37 -06:00
|
|
|
item: fold.fold_item(fold, doc.item)
|
2012-01-30 15:05:25 -06:00
|
|
|
with doc
|
2012-01-19 01:48:25 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-24 16:08:47 -06:00
|
|
|
fn fold_nmod(fold: fold::fold<ctxt>, doc: doc::nmoddoc) -> doc::nmoddoc {
|
|
|
|
vec::push(fold.ctxt.path, doc.name());
|
|
|
|
let doc = fold::default_seq_fold_nmod(fold, doc);
|
|
|
|
vec::pop(fold.ctxt.path);
|
2012-02-24 17:22:57 -06:00
|
|
|
|
|
|
|
{
|
|
|
|
item: fold.fold_item(fold, doc.item)
|
|
|
|
with doc
|
|
|
|
}
|
2012-02-24 16:08:47 -06:00
|
|
|
}
|
|
|
|
|
2012-01-19 01:48:25 -06:00
|
|
|
#[test]
|
|
|
|
fn should_record_mod_paths() {
|
|
|
|
let source = "mod a { mod b { mod c { } } mod d { mod e { } } }";
|
2012-02-20 23:08:19 -06:00
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = run(srv, doc);
|
|
|
|
assert doc.topmod.mods()[0].mods()[0].mods()[0].path() == ["a", "b"];
|
|
|
|
assert doc.topmod.mods()[0].mods()[1].mods()[0].path() == ["a", "d"];
|
|
|
|
}
|
2012-02-17 19:48:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn should_record_fn_paths() {
|
|
|
|
let source = "mod a { fn b() { } }";
|
2012-02-20 23:08:19 -06:00
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = run(srv, doc);
|
|
|
|
assert doc.topmod.mods()[0].fns()[0].path() == ["a"];
|
|
|
|
}
|
2012-02-24 16:08:47 -06:00
|
|
|
}
|
|
|
|
|
2012-02-24 17:22:57 -06:00
|
|
|
#[test]
|
|
|
|
fn should_record_native_mod_paths() {
|
|
|
|
let source = "mod a { native mod b { } }";
|
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = run(srv, doc);
|
|
|
|
assert doc.topmod.mods()[0].nmods()[0].path() == ["a"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-24 16:08:47 -06:00
|
|
|
#[test]
|
|
|
|
fn should_record_native_fn_paths() {
|
|
|
|
let source = "native mod a { fn b(); }";
|
|
|
|
astsrv::from_str(source) {|srv|
|
|
|
|
let doc = extract::from_srv(srv, "");
|
|
|
|
let doc = run(srv, doc);
|
|
|
|
assert doc.topmod.nmods()[0].fns[0].path() == ["a"];
|
|
|
|
}
|
2012-01-19 01:48:25 -06:00
|
|
|
}
|