diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-12 11:27:30 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-09-12 12:04:14 +0200 |
| commit | fc6b7c8b381bcb506eab0f50c69b6cc18aafacb2 (patch) | |
| tree | c3511313bdb6c7cc8919426ce980e558396fe92c /src/comp/front | |
| parent | 64a6376da5ef6e40870af77410d3542ff7bab140 (diff) | |
Reformat for new mode syntax, step 1
Long lines were fixed in a very crude way, as I'll be following up with another reformat in a bit.
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/attr.rs | 42 | ||||
| -rw-r--r-- | src/comp/front/config.rs | 24 | ||||
| -rw-r--r-- | src/comp/front/test.rs | 37 |
3 files changed, 51 insertions, 52 deletions
diff --git a/src/comp/front/attr.rs b/src/comp/front/attr.rs index edb6da5b257..a13fc4aad35 100644 --- a/src/comp/front/attr.rs +++ b/src/comp/front/attr.rs @@ -30,7 +30,7 @@ export mk_attr; // From a list of crate attributes get only the meta_items that impact crate // linkage -fn find_linkage_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] { +fn find_linkage_metas(attrs: [ast::attribute]) -> [@ast::meta_item] { let metas: [@ast::meta_item] = []; for attr: ast::attribute in find_attrs_by_name(attrs, "link") { alt attr.node.value.node { @@ -42,10 +42,10 @@ fn find_linkage_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] { } // Search a list of attributes and return only those with a specific name -fn find_attrs_by_name(attrs: &[ast::attribute], name: ast::ident) -> +fn find_attrs_by_name(attrs: [ast::attribute], name: ast::ident) -> [ast::attribute] { let filter = - bind fn (a: &ast::attribute, name: ast::ident) -> + bind fn (a: ast::attribute, name: ast::ident) -> option::t<ast::attribute> { if get_attr_name(a) == name { option::some(a) @@ -54,14 +54,14 @@ fn find_attrs_by_name(attrs: &[ast::attribute], name: ast::ident) -> ret vec::filter_map(filter, attrs); } -fn get_attr_name(attr: &ast::attribute) -> ast::ident { +fn get_attr_name(attr: ast::attribute) -> ast::ident { get_meta_item_name(@attr.node.value) } -fn find_meta_items_by_name(metas: &[@ast::meta_item], name: ast::ident) -> +fn find_meta_items_by_name(metas: [@ast::meta_item], name: ast::ident) -> [@ast::meta_item] { let filter = - bind fn (m: &@ast::meta_item, name: ast::ident) -> + bind fn (m: @ast::meta_item, name: ast::ident) -> option::t<@ast::meta_item> { if get_meta_item_name(m) == name { option::some(m) @@ -70,7 +70,7 @@ fn find_meta_items_by_name(metas: &[@ast::meta_item], name: ast::ident) -> ret vec::filter_map(filter, metas); } -fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident { +fn get_meta_item_name(meta: @ast::meta_item) -> ast::ident { alt meta.node { ast::meta_word(n) { n } ast::meta_name_value(n, _) { n } @@ -80,7 +80,7 @@ fn get_meta_item_name(meta: &@ast::meta_item) -> ast::ident { // Gets the string value if the meta_item is a meta_name_value variant // containing a string, otherwise none -fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t<str> { +fn get_meta_item_value_str(meta: @ast::meta_item) -> option::t<str> { alt meta.node { ast::meta_name_value(_, v) { alt v.node { ast::lit_str(s) { option::some(s) } _ { option::none } } @@ -89,10 +89,10 @@ fn get_meta_item_value_str(meta: &@ast::meta_item) -> option::t<str> { } } -fn attr_meta(attr: &ast::attribute) -> @ast::meta_item { @attr.node.value } +fn attr_meta(attr: ast::attribute) -> @ast::meta_item { @attr.node.value } // Get the meta_items from inside a vector of attributes -fn attr_metas(attrs: &[ast::attribute]) -> [@ast::meta_item] { +fn attr_metas(attrs: [ast::attribute]) -> [@ast::meta_item] { let mitems = []; for a: ast::attribute in attrs { mitems += [attr_meta(a)]; } ret mitems; @@ -119,7 +119,7 @@ fn eq(a: @ast::meta_item, b: @ast::meta_item) -> bool { } } -fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool { +fn contains(haystack: [@ast::meta_item], needle: @ast::meta_item) -> bool { log #fmt["looking for %s", syntax::print::pprust::meta_item_to_str(*needle)]; for item: @ast::meta_item in haystack { @@ -131,15 +131,15 @@ fn contains(haystack: &[@ast::meta_item], needle: @ast::meta_item) -> bool { ret false; } -fn contains_name(metas: &[@ast::meta_item], name: ast::ident) -> bool { +fn contains_name(metas: [@ast::meta_item], name: ast::ident) -> bool { let matches = find_meta_items_by_name(metas, name); ret vec::len(matches) > 0u; } // FIXME: This needs to sort by meta_item variant in addition to the item name -fn sort_meta_items(items: &[@ast::meta_item]) -> [@ast::meta_item] { - fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool { - fn key(m: &@ast::meta_item) -> ast::ident { +fn sort_meta_items(items: [@ast::meta_item]) -> [@ast::meta_item] { + fn lteq(ma: @ast::meta_item, mb: @ast::meta_item) -> bool { + fn key(m: @ast::meta_item) -> ast::ident { alt m.node { ast::meta_word(name) { name } ast::meta_name_value(name, _) { name } @@ -160,11 +160,11 @@ fn sort_meta_items(items: &[@ast::meta_item]) -> [@ast::meta_item] { ret v2; } -fn remove_meta_items_by_name(items: &[@ast::meta_item], name: &str) -> +fn remove_meta_items_by_name(items: [@ast::meta_item], name: str) -> [@ast::meta_item] { let filter = - bind fn (item: &@ast::meta_item, name: &str) -> + bind fn (item: @ast::meta_item, name: str) -> option::t<@ast::meta_item> { if get_meta_item_name(item) != name { option::some(item) @@ -174,7 +174,7 @@ fn remove_meta_items_by_name(items: &[@ast::meta_item], name: &str) -> ret vec::filter_map(filter, items); } -fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) { +fn require_unique_names(sess: session::session, metas: [@ast::meta_item]) { let map = map::new_str_hash(); for meta: @ast::meta_item in metas { let name = get_meta_item_name(meta); @@ -186,11 +186,11 @@ fn require_unique_names(sess: &session::session, metas: &[@ast::meta_item]) { } } -fn span<@T>(item: &T) -> ast::spanned<T> { +fn span<@T>(item: T) -> ast::spanned<T> { ret {node: item, span: ast_util::dummy_sp()}; } -fn mk_name_value_item_str(name: ast::ident, value: &str) -> @ast::meta_item { +fn mk_name_value_item_str(name: ast::ident, value: str) -> @ast::meta_item { let value_lit = span(ast::lit_str(value)); ret mk_name_value_item(name, value_lit); } @@ -199,7 +199,7 @@ fn mk_name_value_item(name: ast::ident, value: ast::lit) -> @ast::meta_item { ret @span(ast::meta_name_value(name, value)); } -fn mk_list_item(name: ast::ident, items: &[@ast::meta_item]) -> +fn mk_list_item(name: ast::ident, items: [@ast::meta_item]) -> @ast::meta_item { ret @span(ast::meta_list(name, items)); } diff --git a/src/comp/front/config.rs b/src/comp/front/config.rs index 0d391f63c34..843a936cc38 100644 --- a/src/comp/front/config.rs +++ b/src/comp/front/config.rs @@ -24,12 +24,12 @@ fn strip_unconfigured_items(crate: @ast::crate) -> @ast::crate { ret res; } -fn filter_item(cfg: &ast::crate_cfg, item: &@ast::item) -> +fn filter_item(cfg: ast::crate_cfg, item: @ast::item) -> option::t<@ast::item> { if item_in_cfg(cfg, item) { option::some(item) } else { option::none } } -fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) -> +fn fold_mod(cfg: ast::crate_cfg, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { let filter = bind filter_item(cfg, _); let filtered_items = vec::filter_map(filter, m.items); @@ -37,14 +37,14 @@ fn fold_mod(cfg: &ast::crate_cfg, m: &ast::_mod, fld: fold::ast_fold) -> items: vec::map(fld.fold_item, filtered_items)}; } -fn filter_native_item(cfg: &ast::crate_cfg, item: &@ast::native_item) -> +fn filter_native_item(cfg: ast::crate_cfg, item: @ast::native_item) -> option::t<@ast::native_item> { if native_item_in_cfg(cfg, item) { option::some(item) } else { option::none } } -fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod, +fn fold_native_mod(cfg: ast::crate_cfg, nm: ast::native_mod, fld: fold::ast_fold) -> ast::native_mod { let filter = bind filter_native_item(cfg, _); let filtered_items = vec::filter_map(filter, nm.items); @@ -54,7 +54,7 @@ fn fold_native_mod(cfg: &ast::crate_cfg, nm: &ast::native_mod, items: filtered_items}; } -fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) -> +fn filter_stmt(cfg: ast::crate_cfg, stmt: @ast::stmt) -> option::t<@ast::stmt> { alt stmt.node { ast::stmt_decl(decl, _) { @@ -71,7 +71,7 @@ fn filter_stmt(cfg: &ast::crate_cfg, stmt: &@ast::stmt) -> } } -fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) -> +fn fold_block(cfg: ast::crate_cfg, b: ast::blk_, fld: fold::ast_fold) -> ast::blk_ { let filter = bind filter_stmt(cfg, _); let filtered_stmts = vec::filter_map(filter, b.stmts); @@ -81,18 +81,17 @@ fn fold_block(cfg: &ast::crate_cfg, b: &ast::blk_, fld: fold::ast_fold) -> rules: b.rules}; } -fn item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::item) -> bool { +fn item_in_cfg(cfg: ast::crate_cfg, item: @ast::item) -> bool { ret in_cfg(cfg, item.attrs); } -fn native_item_in_cfg(cfg: &ast::crate_cfg, item: &@ast::native_item) -> - bool { +fn native_item_in_cfg(cfg: ast::crate_cfg, item: @ast::native_item) -> bool { ret in_cfg(cfg, item.attrs); } // Determine if an item should be translated in the current crate // configuration based on the item's attributes -fn in_cfg(cfg: &ast::crate_cfg, attrs: &[ast::attribute]) -> bool { +fn in_cfg(cfg: ast::crate_cfg, attrs: [ast::attribute]) -> bool { // The "cfg" attributes on the item let item_cfg_attrs = attr::find_attrs_by_name(attrs, "cfg"); @@ -104,9 +103,8 @@ fn in_cfg(cfg: &ast::crate_cfg, attrs: &[ast::attribute]) -> bool { // which the item is valid let item_cfg_metas = { - fn extract_metas(inner_items: &[@ast::meta_item], - cfg_item: &@ast::meta_item) -> - [@ast::meta_item] { + fn extract_metas(inner_items: [@ast::meta_item], + cfg_item: @ast::meta_item) -> [@ast::meta_item] { alt cfg_item.node { ast::meta_list(name, items) { assert (name == "cfg"); diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index f5ef18066d1..e0d9fa45ce1 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -55,14 +55,13 @@ fn modify_for_testing(crate: @ast::crate) -> @ast::crate { ret res; } -fn fold_mod(_cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) -> - ast::_mod { +fn fold_mod(_cx: test_ctxt, m: ast::_mod, fld: fold::ast_fold) -> ast::_mod { // Remove any defined main function from the AST so it doesn't clash with // the one we're going to add. FIXME: This is sloppy. Instead we should // have some mechanism to indicate to the translation pass which function // we want to be main. - fn nomain(item: &@ast::item) -> option::t<@ast::item> { + fn nomain(item: @ast::item) -> option::t<@ast::item> { alt item.node { ast::item_fn(f, _) { if item.ident == "main" { @@ -78,7 +77,7 @@ fn fold_mod(_cx: &test_ctxt, m: &ast::_mod, fld: fold::ast_fold) -> ret fold::noop_fold_mod(mod_nomain, fld); } -fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) -> +fn fold_crate(cx: test_ctxt, c: ast::crate_, fld: fold::ast_fold) -> ast::crate_ { let folded = fold::noop_fold_crate(c, fld); @@ -88,7 +87,7 @@ fn fold_crate(cx: &test_ctxt, c: &ast::crate_, fld: fold::ast_fold) -> } -fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) -> +fn fold_item(cx: test_ctxt, i: @ast::item, fld: fold::ast_fold) -> @ast::item { cx.path += [i.ident]; @@ -106,11 +105,11 @@ fn fold_item(cx: &test_ctxt, i: &@ast::item, fld: fold::ast_fold) -> ret res; } -fn is_test_fn(i: &@ast::item) -> bool { +fn is_test_fn(i: @ast::item) -> bool { let has_test_attr = vec::len(attr::find_attrs_by_name(i.attrs, "test")) > 0u; - fn has_test_signature(i: &@ast::item) -> bool { + fn has_test_signature(i: @ast::item) -> bool { alt i.node { ast::item_fn(f, tps) { let input_cnt = vec::len(f.decl.inputs); @@ -125,11 +124,11 @@ fn is_test_fn(i: &@ast::item) -> bool { ret has_test_attr && has_test_signature(i); } -fn is_ignored(i: &@ast::item) -> bool { +fn is_ignored(i: @ast::item) -> bool { attr::contains_name(attr::attr_metas(i.attrs), "ignore") } -fn add_test_module(cx: &test_ctxt, m: &ast::_mod) -> ast::_mod { +fn add_test_module(cx: test_ctxt, m: ast::_mod) -> ast::_mod { let testmod = mk_test_module(cx); ret {items: m.items + [testmod] with m}; } @@ -151,7 +150,7 @@ mod __test { */ -fn mk_test_module(cx: &test_ctxt) -> @ast::item { +fn mk_test_module(cx: test_ctxt) -> @ast::item { // A function that generates a vector of test descriptors to feed to the // test runner let testsfn = mk_tests(cx); @@ -172,9 +171,9 @@ fn mk_test_module(cx: &test_ctxt) -> @ast::item { ret @item; } -fn nospan<@T>(t: &T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; } +fn nospan<@T>(t: T) -> ast::spanned<T> { ret {node: t, span: dummy_sp()}; } -fn mk_tests(cx: &test_ctxt) -> @ast::item { +fn mk_tests(cx: test_ctxt) -> @ast::item { let ret_ty = mk_test_desc_vec_ty(cx); let decl: ast::fn_decl = @@ -215,7 +214,7 @@ fn empty_fn_ty() -> ast::ty { } // The ast::ty of [std::test::test_desc] -fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty { +fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty { let test_desc_ty_path: ast::path = nospan({global: false, idents: ["std", "test", "test_desc"], @@ -229,7 +228,7 @@ fn mk_test_desc_vec_ty(cx: &test_ctxt) -> @ast::ty { ret @nospan(ast::ty_vec(vec_mt)); } -fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr { +fn mk_test_desc_vec(cx: test_ctxt) -> @ast::expr { log #fmt["building test vector from %u tests", vec::len(cx.testfns)]; let descs = []; for test: test in cx.testfns { @@ -242,7 +241,7 @@ fn mk_test_desc_vec(cx: &test_ctxt) -> @ast::expr { span: dummy_sp()}; } -fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { +fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr { let path = test.path; log #fmt["encoding %s", ast_util::path_name_i(path)]; @@ -284,13 +283,15 @@ fn mk_test_desc_rec(cx: &test_ctxt, test: test) -> @ast::expr { ret @desc_rec; } -fn mk_main(cx: &test_ctxt) -> @ast::item { +fn mk_main(cx: test_ctxt) -> @ast::item { let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm}; let args_ty: ast::ty = nospan(ast::ty_vec(args_mt)); let args_arg: ast::arg = - {mode: ast::by_ref, ty: @args_ty, ident: "args", + {mode: ast::by_ref, + ty: @args_ty, + ident: "args", id: cx.next_node_id()}; let ret_ty = nospan(ast::ty_nil); @@ -322,7 +323,7 @@ fn mk_main(cx: &test_ctxt) -> @ast::item { ret @item; } -fn mk_test_main_call(cx: &test_ctxt) -> @ast::expr { +fn mk_test_main_call(cx: test_ctxt) -> @ast::expr { // Get the args passed to main so we can pass the to test_main let args_path: ast::path = |
