Cleanup attribute code. Issue #487
This commit is contained in:
parent
26ce1e1035
commit
70a28dc238
|
@ -14,8 +14,9 @@ export sort_meta_items;
|
|||
export remove_meta_items_by_name;
|
||||
export get_attr_name;
|
||||
export mk_name_value_item;
|
||||
export mk_link_item;
|
||||
export mk_list_item;
|
||||
export mk_word_item;
|
||||
export mk_attr;
|
||||
|
||||
// From a list of crate attributes get only the meta_items that impact crate
|
||||
// linkage
|
||||
|
@ -171,7 +172,8 @@ fn mk_name_value_item(ast::ident name, str value) -> @ast::meta_item {
|
|||
ret @span(ast::meta_name_value(name, value));
|
||||
}
|
||||
|
||||
fn mk_list_item(ast::ident name, &vec[@ast::meta_item] items) -> @ast::meta_item {
|
||||
fn mk_list_item(ast::ident name,
|
||||
&vec[@ast::meta_item] items) -> @ast::meta_item {
|
||||
ret @span(ast::meta_list(name, items));
|
||||
}
|
||||
|
||||
|
@ -179,6 +181,11 @@ fn mk_word_item(ast::ident name) -> @ast::meta_item {
|
|||
ret @span(ast::meta_word(name));
|
||||
}
|
||||
|
||||
fn mk_attr(@ast::meta_item item) -> ast::attribute {
|
||||
ret span(rec(style = ast::attr_inner,
|
||||
value = *item));
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
|
|
|
@ -7,6 +7,7 @@ import std::str;
|
|||
import std::io;
|
||||
import std::map::hashmap;
|
||||
import front::ast;
|
||||
import front::attr;
|
||||
import middle::ty;
|
||||
import tags::*;
|
||||
import tydecode::parse_def_id;
|
||||
|
@ -267,8 +268,7 @@ fn get_meta_items(&ebml::doc md) -> vec[@ast::meta_item] {
|
|||
ebml::tagged_docs(md, tag_meta_item_word)) {
|
||||
auto nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
||||
auto n = str::unsafe_from_bytes(ebml::doc_data(nd));
|
||||
items += [@rec(node=ast::meta_word(n),
|
||||
span=rec(lo=0u, hi=0u))];
|
||||
items += [attr::mk_word_item(n)];
|
||||
}
|
||||
for each (ebml::doc meta_item_doc in
|
||||
ebml::tagged_docs(md, tag_meta_item_name_value)) {
|
||||
|
@ -276,16 +276,14 @@ fn get_meta_items(&ebml::doc md) -> vec[@ast::meta_item] {
|
|||
auto vd = ebml::get_doc(meta_item_doc, tag_meta_item_value);
|
||||
auto n = str::unsafe_from_bytes(ebml::doc_data(nd));
|
||||
auto v = str::unsafe_from_bytes(ebml::doc_data(vd));
|
||||
items += [@rec(node=ast::meta_name_value(n, v),
|
||||
span=rec(lo=0u, hi=0u))];
|
||||
items += [attr::mk_name_value_item(n, v)];
|
||||
}
|
||||
for each (ebml::doc meta_item_doc in
|
||||
ebml::tagged_docs(md, tag_meta_item_list)) {
|
||||
auto nd = ebml::get_doc(meta_item_doc, tag_meta_item_name);
|
||||
auto n = str::unsafe_from_bytes(ebml::doc_data(nd));
|
||||
auto subitems = get_meta_items(meta_item_doc);
|
||||
items += [@rec(node=ast::meta_list(n, subitems),
|
||||
span=rec(lo=0u, hi=0u))];
|
||||
items += [attr::mk_list_item(n, subitems)];
|
||||
}
|
||||
ret items;
|
||||
}
|
||||
|
|
|
@ -463,7 +463,7 @@ fn encode_attributes(&ebml::writer ebml_w, &vec[attribute] attrs) {
|
|||
|
||||
// So there's a special crate attribute called 'link' which defines the
|
||||
// metadata that Rust cares about for linking crates. This attribute requires
|
||||
// name and value attributes, so if the user didn't provide them we will throw
|
||||
// 'name' and 'vers' items, so if the user didn't provide them we will throw
|
||||
// them in anyway with default values.
|
||||
fn synthesize_crate_attrs(&@crate_ctxt cx,
|
||||
&@crate crate) -> vec[attribute] {
|
||||
|
@ -472,33 +472,23 @@ fn synthesize_crate_attrs(&@crate_ctxt cx,
|
|||
&vec[@meta_item] items)
|
||||
-> attribute {
|
||||
|
||||
auto bogus_span = rec(lo = 0u, hi = 0u);
|
||||
assert cx.link_meta.name != "";
|
||||
assert cx.link_meta.vers != "";
|
||||
|
||||
auto name_item_ = meta_name_value("name", cx.link_meta.name);
|
||||
auto name_item = rec(node=name_item_,
|
||||
span=bogus_span);
|
||||
|
||||
auto vers_item_ = meta_name_value("vers", cx.link_meta.vers);
|
||||
auto vers_item = rec(node=vers_item_,
|
||||
span=bogus_span);
|
||||
auto name_item = attr::mk_name_value_item("name",
|
||||
cx.link_meta.name);
|
||||
auto vers_item = attr::mk_name_value_item("vers",
|
||||
cx.link_meta.vers);
|
||||
|
||||
auto other_items = {
|
||||
auto tmp = attr::remove_meta_items_by_name(items, "name");
|
||||
attr::remove_meta_items_by_name(tmp, "vers")
|
||||
};
|
||||
|
||||
auto meta_items = [@name_item] + [@vers_item] + other_items;
|
||||
auto meta_items = [name_item] + [vers_item] + other_items;
|
||||
auto link_item = attr::mk_list_item("link", meta_items);
|
||||
|
||||
auto link_item_ = meta_list("link", meta_items);
|
||||
auto link_item = rec(node=link_item_,
|
||||
span=bogus_span);
|
||||
|
||||
auto attr_ = rec(style = attr_inner,
|
||||
value = link_item);
|
||||
auto attr = rec(node=attr_,
|
||||
span=bogus_span);
|
||||
|
||||
ret attr;
|
||||
ret attr::mk_attr(link_item);
|
||||
}
|
||||
|
||||
let vec[attribute] attrs = [];
|
||||
|
|
Loading…
Reference in New Issue