Temp commit on the way to making meta_item into an interior vector
This commit is contained in:
parent
3f6c9f8d84
commit
ec890fff23
@ -29,13 +29,11 @@
|
||||
|
||||
// From a list of crate attributes get only the meta_items that impact crate
|
||||
// linkage
|
||||
fn find_linkage_metas(&ast::attribute[] attrs) -> vec[@ast::meta_item] {
|
||||
let vec[@ast::meta_item] metas = [];
|
||||
fn find_linkage_metas(&ast::attribute[] attrs) -> (@ast::meta_item)[] {
|
||||
let (@ast::meta_item)[] metas = ~[];
|
||||
for (ast::attribute attr in find_attrs_by_name(attrs, "link")) {
|
||||
alt (attr.node.value.node) {
|
||||
case (ast::meta_list(_, ?items)) {
|
||||
metas += items;
|
||||
}
|
||||
case (ast::meta_list(_, ?items)) { metas += items; }
|
||||
case (_) {
|
||||
log "ignoring link attribute that has incorrect type";
|
||||
}
|
||||
@ -133,7 +131,7 @@ fn eq(@ast::meta_item a, @ast::meta_item b) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn contains(&vec[@ast::meta_item] haystack, @ast::meta_item needle) -> bool {
|
||||
fn contains(&(@ast::meta_item)[] haystack, @ast::meta_item needle) -> bool {
|
||||
log #fmt("looking for %s",
|
||||
syntax::print::pprust::meta_item_to_str(*needle));
|
||||
for (@ast::meta_item item in haystack) {
|
||||
@ -222,8 +220,8 @@ fn mk_name_value_item(ast::ident name, ast::lit 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, &(@ast::meta_item)[] items)
|
||||
-> @ast::meta_item {
|
||||
ret @span(ast::meta_list(name, items));
|
||||
}
|
||||
|
||||
|
@ -109,9 +109,9 @@ fn in_cfg(&ast::crate_cfg cfg, &ast::attribute[] attrs) -> bool {
|
||||
// so we can match against them. This is the list of configurations for
|
||||
// which the item is valid
|
||||
auto item_cfg_metas = {
|
||||
fn extract_metas(&vec[@ast::meta_item] inner_items,
|
||||
fn extract_metas(&(@ast::meta_item)[] inner_items,
|
||||
&@ast::meta_item cfg_item)
|
||||
-> vec[@ast::meta_item] {
|
||||
-> (@ast::meta_item)[] {
|
||||
|
||||
alt (cfg_item.node) {
|
||||
case (ast::meta_list(?name, ?items)) {
|
||||
@ -122,13 +122,11 @@ fn extract_metas(&vec[@ast::meta_item] inner_items,
|
||||
}
|
||||
}
|
||||
auto cfg_metas = attr::attr_metas(item_cfg_attrs);
|
||||
vec::foldl(extract_metas, [], cfg_metas)
|
||||
ivec::foldl(extract_metas, ~[], cfg_metas)
|
||||
};
|
||||
|
||||
for (@ast::meta_item cfg_mi in item_cfg_metas) {
|
||||
if (attr::contains(cfg, cfg_mi)) {
|
||||
ret true;
|
||||
}
|
||||
if (attr::contains(cfg, cfg_mi)) { ret true; }
|
||||
}
|
||||
|
||||
ret false;
|
||||
|
@ -81,7 +81,7 @@ fn def_id_of_def(def d) -> def_id {
|
||||
|
||||
// The set of meta_items that define the compilation environment of the crate,
|
||||
// used to drive conditional compilation
|
||||
type crate_cfg = vec[@meta_item];
|
||||
type crate_cfg = (@meta_item)[];
|
||||
|
||||
type crate = spanned[crate_];
|
||||
|
||||
@ -105,7 +105,7 @@ fn def_id_of_def(def d) -> def_id {
|
||||
|
||||
tag meta_item_ {
|
||||
meta_word(ident);
|
||||
meta_list(ident, vec[@meta_item]);
|
||||
meta_list(ident, (@meta_item)[]);
|
||||
meta_name_value(ident, lit);
|
||||
}
|
||||
|
||||
@ -505,7 +505,7 @@ fn ty_mach_to_str(ty_mach tm) -> str {
|
||||
type view_item = spanned[view_item_];
|
||||
|
||||
tag view_item_ {
|
||||
view_item_use(ident, vec[@meta_item], node_id);
|
||||
view_item_use(ident, (@meta_item)[], node_id);
|
||||
view_item_import(ident, vec[ident], node_id);
|
||||
view_item_import_glob(vec[ident], node_id);
|
||||
view_item_export(ident, node_id);
|
||||
|
@ -103,7 +103,7 @@ fn fold_meta_item_(&@meta_item mi, ast_fold fld) -> @meta_item {
|
||||
case (meta_word(?id)) { meta_word(fld.fold_ident(id)) }
|
||||
case (meta_list(?id, ?mis)) {
|
||||
auto fold_meta_item = bind fold_meta_item_(_,fld);
|
||||
meta_list(id, map(fold_meta_item, mis))
|
||||
meta_list(id, ivec::map(fold_meta_item, mis))
|
||||
}
|
||||
case (meta_name_value(?id,?s)) {
|
||||
meta_name_value(fld.fold_ident(id),s)
|
||||
@ -134,7 +134,7 @@ fn noop_fold_crate(&crate_ c, ast_fold fld) -> crate_ {
|
||||
ret rec(directives=ivec::map(fld.fold_crate_directive, c.directives),
|
||||
module=fld.fold_mod(c.module),
|
||||
attrs=ivec::map(fold_attribute, c.attrs),
|
||||
config=vec::map(fold_meta_item, c.config));
|
||||
config=ivec::map(fold_meta_item, c.config));
|
||||
}
|
||||
|
||||
fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld)
|
||||
|
@ -591,6 +591,24 @@ fn parse_seq_to_end[T](token::token ket, option::t[token::token] sep,
|
||||
ret v;
|
||||
}
|
||||
|
||||
fn parse_seq_to_end_ivec[T](token::token ket, option::t[token::token] sep,
|
||||
fn(&parser)->T f, &parser p) -> T[] {
|
||||
let bool first = true;
|
||||
let T[] v = ~[];
|
||||
while (p.peek() != ket) {
|
||||
alt (sep) {
|
||||
case (some(?t)) {
|
||||
if (first) { first = false; } else { expect(p, t); }
|
||||
}
|
||||
case (_) { }
|
||||
}
|
||||
v += ~[f(p)];
|
||||
}
|
||||
expect(p, ket);
|
||||
ret v;
|
||||
}
|
||||
|
||||
|
||||
fn parse_seq[T](token::token bra, token::token ket,
|
||||
option::t[token::token] sep, fn(&parser) -> T f, &parser p)
|
||||
-> ast::spanned[vec[T]] {
|
||||
@ -601,6 +619,17 @@ fn parse_seq[T](token::token bra, token::token ket,
|
||||
ret spanned(lo, hi, result);
|
||||
}
|
||||
|
||||
fn parse_seq_ivec[T](token::token bra, token::token ket,
|
||||
option::t[token::token] sep,
|
||||
fn(&parser)->T f, &parser p) -> ast::spanned[T[]] {
|
||||
auto lo = p.get_lo_pos();
|
||||
expect(p, bra);
|
||||
auto result = parse_seq_to_end_ivec[T](ket, sep, f, p);
|
||||
auto hi = p.get_hi_pos();
|
||||
ret spanned(lo, hi, result);
|
||||
}
|
||||
|
||||
|
||||
fn parse_lit(&parser p) -> ast::lit {
|
||||
auto sp = p.get_span();
|
||||
let ast::lit_ lit = ast::lit_nil;
|
||||
@ -2186,15 +2215,15 @@ fn parse_meta_item(&parser p) -> @ast::meta_item {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_meta_seq(&parser p) -> vec[@ast::meta_item] {
|
||||
ret parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
fn parse_meta_seq(&parser p) -> (@ast::meta_item)[] {
|
||||
ret parse_seq_ivec(token::LPAREN, token::RPAREN, some(token::COMMA),
|
||||
parse_meta_item, p).node;
|
||||
}
|
||||
|
||||
fn parse_optional_meta(&parser p) -> vec[@ast::meta_item] {
|
||||
fn parse_optional_meta(&parser p) -> (@ast::meta_item)[] {
|
||||
alt (p.peek()) {
|
||||
case (token::LPAREN) { ret parse_meta_seq(p); }
|
||||
case (_) { let vec[@ast::meta_item] v = []; ret v; }
|
||||
case (_) { ret ~[]; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -2204,8 +2233,7 @@ fn parse_use(&parser p) -> @ast::view_item {
|
||||
auto metadata = parse_optional_meta(p);
|
||||
auto hi = p.get_hi_pos();
|
||||
expect(p, token::SEMI);
|
||||
auto use_decl =
|
||||
ast::view_item_use(ident, metadata, p.get_id());
|
||||
auto use_decl = ast::view_item_use(ident, metadata, p.get_id());
|
||||
ret @spanned(lo, hi, use_decl);
|
||||
}
|
||||
|
||||
|
@ -1118,7 +1118,7 @@ fn print_meta_item(&ps s, &@ast::meta_item item) {
|
||||
case (ast::meta_list(?name, ?items)) {
|
||||
word(s.s, name);
|
||||
popen(s);
|
||||
commasep(s, consistent, items, print_meta_item);
|
||||
commasep_ivec(s, consistent, items, print_meta_item);
|
||||
pclose(s);
|
||||
}
|
||||
}
|
||||
@ -1132,9 +1132,9 @@ fn print_view_item(&ps s, &@ast::view_item item) {
|
||||
case (ast::view_item_use(?id, ?mta, _)) {
|
||||
head(s, "use");
|
||||
word(s.s, id);
|
||||
if (vec::len(mta) > 0u) {
|
||||
if (ivec::len(mta) > 0u) {
|
||||
popen(s);
|
||||
commasep(s, consistent, mta, print_meta_item);
|
||||
commasep_ivec(s, consistent, mta, print_meta_item);
|
||||
pclose(s);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user