rustc: Remove all exterior vectors from the AST

This commit is contained in:
Patrick Walton 2011-07-07 15:31:54 -07:00
parent 3958c72cd8
commit e1b107d74e
12 changed files with 62 additions and 70 deletions

View File

@ -36,9 +36,9 @@ fn filter_item(&ast::crate_cfg cfg,
fn fold_mod(&ast::crate_cfg cfg, &ast::_mod m,
fold::ast_fold fld) -> ast::_mod {
auto filter = bind filter_item(cfg, _);
auto filtered_items = vec::filter_map(filter, m.items);
ret rec(view_items=vec::map(fld.fold_view_item, m.view_items),
items=vec::map(fld.fold_item, filtered_items));
auto filtered_items = ivec::filter_map(filter, m.items);
ret rec(view_items=ivec::map(fld.fold_view_item, m.view_items),
items=ivec::map(fld.fold_item, filtered_items));
}
fn filter_native_item(&ast::crate_cfg cfg, &@ast::native_item item)
@ -53,10 +53,10 @@ fn filter_native_item(&ast::crate_cfg cfg, &@ast::native_item item)
fn fold_native_mod(&ast::crate_cfg cfg, &ast::native_mod nm,
fold::ast_fold fld) -> ast::native_mod {
auto filter = bind filter_native_item(cfg, _);
auto filtered_items = vec::filter_map(filter, nm.items);
auto filtered_items = ivec::filter_map(filter, nm.items);
ret rec(native_name=nm.native_name,
abi=nm.abi,
view_items=vec::map(fld.fold_view_item, nm.view_items),
view_items=ivec::map(fld.fold_view_item, nm.view_items),
items=filtered_items);
}

View File

@ -50,14 +50,12 @@ fn fold_crate(&test_ctxt cx, &ast::crate_ c,
fn add_test_module(&test_ctxt cx, &ast::_mod m) -> ast::_mod {
auto testmod = mk_test_module(cx);
ret rec(items = m.items + [testmod]
with m);
ret rec(items=m.items + ~[testmod] with m);
}
fn mk_test_module(&test_ctxt cx) -> @ast::item {
auto mainfn = mk_main(cx);
let ast::_mod testmod = rec(view_items = [],
items = [mainfn]);
let ast::_mod testmod = rec(view_items=~[], items=~[mainfn]);
auto item_ = ast::item_mod(testmod);
let ast::item item = rec(ident = "__test",
attrs = ~[],

View File

@ -216,7 +216,7 @@ fn encode_tag_variant_info(&@crate_ctxt cx, &ebml::writer ebml_w,
encode_kind(ebml_w, 'v' as u8);
encode_tag_id(ebml_w, local_def(id));
encode_type(cx, ebml_w, node_id_to_monotype(cx.tcx, variant.node.id));
if (vec::len[variant_arg](variant.node.args) > 0u) {
if (ivec::len[variant_arg](variant.node.args) > 0u) {
encode_symbol(cx, ebml_w, variant.node.id);
}
encode_discriminant(cx, ebml_w, variant.node.id);

View File

@ -382,16 +382,15 @@ fn visit_expr_with_scope(&@ast::expr x, &scopes sc, &vt[scopes] v) {
visit::visit_expr(x, new_sc, v);
}
fn follow_import(&env e, &scopes sc,
vec[ident] path, &span sp) -> option::t[def] {
auto path_len = vec::len(path);
fn follow_import(&env e, &scopes sc, &ident[] path, &span sp)
-> option::t[def] {
auto path_len = ivec::len(path);
auto dcur = lookup_in_scope_strict(e, sc, sp, path.(0), ns_module);
auto i = 1u;
while (true && option::is_some(dcur)) {
if (i == path_len) { break; }
dcur =
lookup_in_mod_strict(e, option::get(dcur),
sp, path.(i), ns_module, outside);
dcur = lookup_in_mod_strict(e, option::get(dcur),
sp, path.(i), ns_module, outside);
i += 1u;
}
if (i == path_len) {
@ -399,8 +398,7 @@ fn follow_import(&env e, &scopes sc,
case (ast::def_mod(?def_id)) { ret dcur; }
case (ast::def_native_mod(?def_id)) { ret dcur; }
case (_) {
e.sess.span_err(sp,
str::connect(path, "::") +
e.sess.span_err(sp, str::connect_ivec(path, "::") +
" does not name a module.");
ret none;
}
@ -457,7 +455,7 @@ fn resolve_import(&env e, &@ast::view_item it, &scopes sc) {
}
}
e.imports.insert(defid._1, resolving(it.span));
auto n_idents = vec::len(ids);
auto n_idents = ivec::len(ids);
auto end_id = ids.(n_idents - 1u);
if (n_idents == 1u) {
auto next_sc = std::list::cdr(sc);

View File

@ -8529,7 +8529,7 @@ fn trans_res_ctor(@local_ctxt cx, &span sp, &ast::_fn dtor,
fn trans_tag_variant(@local_ctxt cx, ast::node_id tag_id,
&ast::variant variant, int index, bool is_degen,
&ast::ty_param[] ty_params) {
if (vec::len[ast::variant_arg](variant.node.args) == 0u) {
if (std::ivec::len[ast::variant_arg](variant.node.args) == 0u) {
ret; // nullary constructors are just constants
}
@ -9043,7 +9043,7 @@ fn collect_tag_ctor(@crate_ctxt ccx, &@ast::item i, &vec[str] pt,
alt (i.node) {
case (ast::item_tag(?variants, ?tps)) {
for (ast::variant variant in variants) {
if (vec::len[ast::variant_arg](variant.node.args) != 0u) {
if (std::ivec::len(variant.node.args) != 0u) {
decl_fn_and_pair(ccx, i.span,
new_pt + [variant.node.name], "tag", tps,
variant.node.id);

View File

@ -2830,8 +2830,7 @@ fn tag_variants(&ctxt cx, &ast::def_id id) -> variant_info[] {
auto ctor_ty = node_id_to_monotype
(cx, variant.node.id);
let t[] arg_tys = ~[];
if (vec::len[ast::variant_arg](variant.node.args) >
0u) {
if (std::ivec::len(variant.node.args) > 0u) {
for (arg a in ty_fn_args(cx, ctor_ty)) {
arg_tys += ~[a.ty];
}

View File

@ -692,7 +692,7 @@ mod collect {
// constructors get turned into functions.
auto result_ty;
if (vec::len[ast::variant_arg](variant.node.args) == 0u) {
if (ivec::len[ast::variant_arg](variant.node.args) == 0u) {
result_ty = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
} else {
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()

View File

@ -3,7 +3,6 @@
import std::ivec;
import std::option;
import std::str;
import std::vec;
import codemap::span;
import codemap::filename;
@ -481,7 +480,7 @@ type anon_obj =
// with_obj: the original object being extended, if it exists.
option::t[@expr] with_obj);
type _mod = rec(vec[@view_item] view_items, vec[@item] items);
type _mod = rec((@view_item)[] view_items, (@item)[] items);
tag native_abi {
native_abi_rust;
@ -493,12 +492,12 @@ tag native_abi {
type native_mod =
rec(str native_name,
native_abi abi,
vec[@view_item] view_items,
vec[@native_item] items);
(@view_item)[] view_items,
(@native_item)[] items);
type variant_arg = rec(@ty ty, node_id id);
type variant_ = rec(str name, vec[variant_arg] args, node_id id);
type variant_ = rec(str name, (variant_arg)[] args, node_id id);
type variant = spanned[variant_];
@ -506,8 +505,8 @@ type view_item = spanned[view_item_];
tag view_item_ {
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_import(ident, ident[], node_id);
view_item_import_glob(ident[], node_id);
view_item_export(ident, node_id);
}

View File

@ -463,15 +463,15 @@ fn noop_fold_fn(&_fn f, ast_fold fld) -> _fn {
// ...nor do modules
fn noop_fold_mod(&_mod m, ast_fold fld) -> _mod {
ret rec(view_items=map(fld.fold_view_item, m.view_items),
items=map(fld.fold_item, m.items));
ret rec(view_items=ivec::map(fld.fold_view_item, m.view_items),
items=ivec::map(fld.fold_item, m.items));
}
fn noop_fold_native_mod(&native_mod nm, ast_fold fld) -> native_mod {
ret rec(native_name=nm.native_name,
abi=nm.abi,
view_items=map(fld.fold_view_item, nm.view_items),
items=map(fld.fold_native_item, nm.items))
view_items=ivec::map(fld.fold_view_item, nm.view_items),
items=ivec::map(fld.fold_native_item, nm.items))
}
fn noop_fold_variant(&variant_ v, ast_fold fld) -> variant_ {
@ -480,7 +480,7 @@ fn noop_fold_variant(&variant_ v, ast_fold fld) -> variant_ {
}
auto fold_variant_arg = bind fold_variant_arg_(_,fld);
ret rec(name=v.name,
args=map(fold_variant_arg, v.args),
args=ivec::map(fold_variant_arg, v.args),
id=v.id);
}

View File

@ -25,8 +25,8 @@ type ctx =
ast::crate_cfg cfg);
fn eval_crate_directives(ctx cx, &(@ast::crate_directive)[] cdirs,
str prefix, &mutable vec[@ast::view_item] view_items,
&mutable vec[@ast::item] items) {
str prefix, &mutable (@ast::view_item)[] view_items,
&mutable (@ast::item)[] items) {
for (@ast::crate_directive sub_cdir in cdirs) {
eval_crate_directive(cx, sub_cdir, prefix, view_items, items);
}
@ -34,15 +34,15 @@ fn eval_crate_directives(ctx cx, &(@ast::crate_directive)[] cdirs,
fn eval_crate_directives_to_mod(ctx cx, &(@ast::crate_directive)[] cdirs,
str prefix) -> ast::_mod {
let vec[@ast::view_item] view_items = [];
let vec[@ast::item] items = [];
let (@ast::view_item)[] view_items = ~[];
let (@ast::item)[] items = ~[];
eval_crate_directives(cx, cdirs, prefix, view_items, items);
ret rec(view_items=view_items, items=items);
}
fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
&mutable vec[@ast::view_item] view_items,
&mutable vec[@ast::item] items) {
&mutable (@ast::view_item)[] view_items,
&mutable (@ast::item)[] items) {
alt (cdir.node) {
case (ast::cdir_src_mod(?id, ?file_opt, ?attrs)) {
auto file_path = id + ".rs";
@ -68,7 +68,7 @@ fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
mod_attrs);
// Thread defids and chpos through the parsers
cx.chpos = p0.get_chpos();
vec::push[@ast::item](items, i);
items += ~[i];
}
case (ast::cdir_dir_mod(?id, ?dir_opt, ?cdirs, ?attrs)) {
auto path = id;
@ -85,11 +85,9 @@ fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
node=ast::item_mod(m0),
span=cdir.span);
cx.sess.next_id += 1;
vec::push[@ast::item](items, i);
}
case (ast::cdir_view_item(?vi)) {
vec::push[@ast::view_item](view_items, vi);
items += ~[i];
}
case (ast::cdir_view_item(?vi)) { view_items += ~[vi]; }
case (ast::cdir_syntax(?pth)) { }
case (ast::cdir_auth(?pth, ?eff)) { }
}

View File

@ -1859,15 +1859,15 @@ fn parse_mod_items(&parser p, token::token term,
parse_view(p)
} else {
// Shouldn't be any view items since we've already parsed an item attr
[]
~[]
};
let vec[@ast::item] items = [];
let (@ast::item)[] items = ~[];
auto initial_attrs = first_item_attrs;
while (p.peek() != term) {
auto attrs = initial_attrs + parse_outer_attributes(p);
initial_attrs = ~[];
alt (parse_item(p, attrs)) {
case (got_item(?i)) { vec::push(items, i); }
case (got_item(?i)) { items += ~[i]; }
case (_) {
p.fatal("expected item but found " +
token::to_str(p.get_reader(), p.peek()));
@ -1948,14 +1948,14 @@ fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi,
parse_native_view(p)
} else {
// Shouldn't be any view items since we've already parsed an item attr
[]
~[]
};
let vec[@ast::native_item] items = [];
let (@ast::native_item)[] items = ~[];
auto initial_attrs = first_item_attrs;
while (p.peek() != token::RBRACE) {
auto attrs = initial_attrs + parse_outer_attributes(p);
initial_attrs = ~[];
items += [parse_native_item(p, attrs)];
items += ~[parse_native_item(p, attrs)];
}
ret rec(native_name=native_name,
abi=abi,
@ -2028,7 +2028,7 @@ fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
expect(p, token::SEMI);
auto variant = spanned(ty.span.lo, ty.span.hi,
rec(name=id,
args=[rec(ty=ty, id=p.get_id())],
args=~[rec(ty=ty, id=p.get_id())],
id=p.get_id()));
ret mk_item(p, lo, ty.span.hi, id,
ast::item_tag(~[variant], ty_params), attrs);
@ -2041,14 +2041,14 @@ fn parse_item_tag(&parser p, &ast::attribute[] attrs) -> @ast::item {
check_bad_word(p);
auto vlo = p.get_lo_pos();
p.bump();
let vec[ast::variant_arg] args = [];
let ast::variant_arg[] args = ~[];
alt (p.peek()) {
case (token::LPAREN) {
auto arg_tys =
parse_seq(token::LPAREN, token::RPAREN,
some(token::COMMA), parse_ty, p);
for (@ast::ty ty in arg_tys.node) {
args += [rec(ty=ty, id=p.get_id())];
args += ~[rec(ty=ty, id=p.get_id())];
}
}
case (_) {/* empty */ }
@ -2243,7 +2243,7 @@ fn parse_rest_import_name(&parser p, ast::ident first,
option::t[ast::ident] def_ident) ->
@ast::view_item {
auto lo = p.get_lo_pos();
let vec[ast::ident] identifiers = [first];
let ast::ident[] identifiers = ~[first];
let bool glob = false;
while (true) {
alt (p.peek()) {
@ -2255,7 +2255,7 @@ fn parse_rest_import_name(&parser p, ast::ident first,
case (_) { p.fatal("expecting '::' or ';'"); }
}
alt (p.peek()) {
case (token::IDENT(_, _)) { identifiers += [parse_ident(p)]; }
case (token::IDENT(_, _)) { identifiers += ~[parse_ident(p)]; }
case (
//the lexer can't tell the different kinds of stars apart ) :
token::BINOP(token::STAR)) {
@ -2278,7 +2278,7 @@ fn parse_rest_import_name(&parser p, ast::ident first,
import_decl =
ast::view_item_import_glob(identifiers, p.get_id());
} else {
auto len = vec::len(identifiers);
auto len = ivec::len(identifiers);
import_decl =
ast::view_item_import(identifiers.(len - 1u), identifiers,
p.get_id());
@ -2347,15 +2347,15 @@ fn is_view_item(&parser p) -> bool {
ret false;
}
fn parse_view(&parser p) -> vec[@ast::view_item] {
let vec[@ast::view_item] items = [];
while (is_view_item(p)) { items += [parse_view_item(p)]; }
fn parse_view(&parser p) -> (@ast::view_item)[] {
let (@ast::view_item)[] items = ~[];
while (is_view_item(p)) { items += ~[parse_view_item(p)]; }
ret items;
}
fn parse_native_view(&parser p) -> vec[@ast::view_item] {
let vec[@ast::view_item] items = [];
while (is_view_item(p)) { items += [parse_view_item(p)]; }
fn parse_native_view(&parser p) -> (@ast::view_item)[] {
let (@ast::view_item)[] items = ~[];
while (is_view_item(p)) { items += ~[parse_view_item(p)]; }
ret items;
}

View File

@ -465,7 +465,7 @@ fn print_item(&ps s, &@ast::item item) {
case (ast::item_tag(?variants, ?params)) {
auto newtype = ivec::len(variants) == 1u &&
str::eq(item.ident, variants.(0).node.name) &&
vec::len(variants.(0).node.args) == 1u;
ivec::len(variants.(0).node.args) == 1u;
if (newtype) {
ibox(s, indent_unit);
word_space(s, "tag");
@ -486,13 +486,13 @@ fn print_item(&ps s, &@ast::item item) {
space(s.s);
maybe_print_comment(s, v.span.lo);
word(s.s, v.node.name);
if (vec::len(v.node.args) > 0u) {
if (ivec::len(v.node.args) > 0u) {
popen(s);
fn print_variant_arg(&ps s, &ast::variant_arg arg) {
print_type(s, *arg.ty);
}
commasep(s, consistent, v.node.args,
print_variant_arg);
commasep_ivec(s, consistent, v.node.args,
print_variant_arg);
pclose(s);
}
word(s.s, ";");
@ -1161,7 +1161,7 @@ fn print_view_item(&ps s, &@ast::view_item item) {
}
case (ast::view_item_import(?id, ?ids, _)) {
head(s, "import");
if (!str::eq(id, ids.(vec::len(ids) - 1u))) {
if (!str::eq(id, ids.(ivec::len(ids) - 1u))) {
word_space(s, id);
word_space(s, "=");
}