rustc: Move some attribute accessors from rustdoc to rustc

This commit is contained in:
Brian Anderson 2012-01-16 21:12:08 -08:00
parent 4f2ad6b124
commit bd63c3928e
2 changed files with 55 additions and 52 deletions

View file

@ -20,6 +20,9 @@ export get_meta_item_name;
export get_meta_item_value_str;
export get_meta_item_value_str_by_name;
export get_meta_item_list;
export meta_item_value_from_list;
export meta_item_list_from_list;
export name_value_str_pair;
export mk_name_value_item_str;
export mk_name_value_item;
export mk_list_item;
@ -217,6 +220,53 @@ fn native_abi(attrs: [ast::attribute]) -> either::t<str, ast::native_abi> {
};
}
fn meta_item_from_list(
items: [@ast::meta_item],
name: str
) -> option<@ast::meta_item> {
let items = attr::find_meta_items_by_name(items, name);
vec::last(items)
}
fn meta_item_value_from_list(
items: [@ast::meta_item],
name: str
) -> option<str> {
alt meta_item_from_list(items, name) {
some(item) {
alt attr::get_meta_item_value_str(item) {
some(value) { some(value) }
none. { none }
}
}
none. { none }
}
}
fn meta_item_list_from_list(
items: [@ast::meta_item],
name: str
) -> option<[@ast::meta_item]> {
alt meta_item_from_list(items, name) {
some(item) {
attr::get_meta_item_list(item)
}
none. { none }
}
}
fn name_value_str_pair(
item: @ast::meta_item
) -> option<(str, str)> {
alt attr::get_meta_item_value_str(item) {
some(value) {
let name = attr::get_meta_item_name(item);
some((name, value))
}
none. { none }
}
}
fn span<T: copy>(item: T) -> ast::spanned<T> {
ret {node: item, span: ast_util::dummy_sp()};
}

View file

@ -71,64 +71,17 @@ fn parse_fn(
};
}
fn meta_item_from_list(
items: [@ast::meta_item],
name: str
) -> option<@ast::meta_item> {
let items = attr::find_meta_items_by_name(items, name);
vec::last(items)
}
fn meta_item_value_from_list(
items: [@ast::meta_item],
name: str
) -> option<str> {
alt meta_item_from_list(items, name) {
some(item) {
alt attr::get_meta_item_value_str(item) {
some(value) { some(value) }
none. { none }
}
}
none. { none }
}
}
fn meta_item_list_from_list(
items: [@ast::meta_item],
name: str
) -> option<[@ast::meta_item]> {
alt meta_item_from_list(items, name) {
some(item) {
attr::get_meta_item_list(item)
}
none. { none }
}
}
fn name_value_str_pair(
item: @ast::meta_item
) -> option<(str, str)> {
alt attr::get_meta_item_value_str(item) {
some(value) {
let name = attr::get_meta_item_name(item);
some((name, value))
}
none. { none }
}
}
fn parse_fn_(
items: [@ast::meta_item]
) -> fn_attrs {
let brief = meta_item_value_from_list(items, "brief");
let desc = meta_item_value_from_list(items, "desc");
let return = meta_item_value_from_list(items, "return");
let brief = attr::meta_item_value_from_list(items, "brief");
let desc = attr::meta_item_value_from_list(items, "desc");
let return = attr::meta_item_value_from_list(items, "return");
let args = alt meta_item_list_from_list(items, "args") {
let args = alt attr::meta_item_list_from_list(items, "args") {
some(items) {
vec::filter_map(items) {|item|
option::map(name_value_str_pair(item)) { |pair|
option::map(attr::name_value_str_pair(item)) { |pair|
{
name: util::fst(pair),
desc: util::snd(pair)