提交 7b2026bf 编写于 作者: B Brian Anderson

Introduce 'return', 'match' and 'module' as synonyms

上级 7d183698
......@@ -600,21 +600,21 @@ fn load_source_packages(c: cargo, src: source) {
}
fn build_cargo_options(argv: ~[~str]) -> options {
let match = alt getopts::getopts(argv, opts()) {
let matches = alt getopts::getopts(argv, opts()) {
result::ok(m) { m }
result::err(f) {
fail fmt!{"%s", getopts::fail_str(f)};
}
};
let test = opt_present(match, ~"test");
let G = opt_present(match, ~"G");
let g = opt_present(match, ~"g");
let help = opt_present(match, ~"h") || opt_present(match, ~"help");
let len = vec::len(match.free);
let test = opt_present(matches, ~"test");
let G = opt_present(matches, ~"G");
let g = opt_present(matches, ~"g");
let help = opt_present(matches, ~"h") || opt_present(matches, ~"help");
let len = vec::len(matches.free);
let is_install = len > 1u && match.free[1] == ~"install";
let is_uninstall = len > 1u && match.free[1] == ~"uninstall";
let is_install = len > 1u && matches.free[1] == ~"install";
let is_uninstall = len > 1u && matches.free[1] == ~"uninstall";
if G && g { fail ~"-G and -g both provided"; }
......@@ -627,7 +627,7 @@ fn build_cargo_options(argv: ~[~str]) -> options {
else if G { system_mode }
else { local_mode };
{test: test, mode: mode, free: match.free, help: help}
{test: test, mode: mode, free: matches.free, help: help}
}
fn configure(opts: options) -> cargo {
......
......@@ -41,29 +41,29 @@ fn parse_config(args: ~[~str]) -> config {
assert (vec::is_not_empty(args));
let args_ = vec::tail(args);
let match =
let matches =
alt getopts::getopts(args_, opts) {
ok(m) { m }
err(f) { fail getopts::fail_str(f) }
};
ret {compile_lib_path: getopts::opt_str(match, ~"compile-lib-path"),
run_lib_path: getopts::opt_str(match, ~"run-lib-path"),
rustc_path: getopts::opt_str(match, ~"rustc-path"),
src_base: getopts::opt_str(match, ~"src-base"),
build_base: getopts::opt_str(match, ~"build-base"),
aux_base: getopts::opt_str(match, ~"aux-base"),
stage_id: getopts::opt_str(match, ~"stage-id"),
mode: str_mode(getopts::opt_str(match, ~"mode")),
run_ignored: getopts::opt_present(match, ~"ignored"),
ret {compile_lib_path: getopts::opt_str(matches, ~"compile-lib-path"),
run_lib_path: getopts::opt_str(matches, ~"run-lib-path"),
rustc_path: getopts::opt_str(matches, ~"rustc-path"),
src_base: getopts::opt_str(matches, ~"src-base"),
build_base: getopts::opt_str(matches, ~"build-base"),
aux_base: getopts::opt_str(matches, ~"aux-base"),
stage_id: getopts::opt_str(matches, ~"stage-id"),
mode: str_mode(getopts::opt_str(matches, ~"mode")),
run_ignored: getopts::opt_present(matches, ~"ignored"),
filter:
if vec::len(match.free) > 0u {
option::some(match.free[0])
if vec::len(matches.free) > 0u {
option::some(matches.free[0])
} else { option::none },
logfile: getopts::opt_maybe_str(match, ~"logfile"),
runtool: getopts::opt_maybe_str(match, ~"runtool"),
rustcflags: getopts::opt_maybe_str(match, ~"rustcflags"),
verbose: getopts::opt_present(match, ~"verbose")};
logfile: getopts::opt_maybe_str(matches, ~"logfile"),
runtool: getopts::opt_maybe_str(matches, ~"runtool"),
rustcflags: getopts::opt_maybe_str(matches, ~"rustcflags"),
verbose: getopts::opt_present(matches, ~"verbose")};
}
fn log_config(config: config) {
......
......@@ -97,7 +97,7 @@ fn borrow<B>(f: fn(-~[mut A]) -> B) -> B {
}
#[inline(always)]
fn return(-data: ~[mut A]) {
fn give_back(-data: ~[mut A]) {
unsafe {
self.data <- data;
}
......@@ -120,7 +120,7 @@ fn reserve(count: uint) {
*/
#[inline(always)]
fn swap(f: fn(-~[mut A]) -> ~[mut A]) {
self.borrow(|v| self.return(f(v)))
self.borrow(|v| self.give_back(f(v)))
}
/// Returns the number of elements currently in the dvec
......@@ -128,7 +128,7 @@ fn swap(f: fn(-~[mut A]) -> ~[mut A]) {
unchecked {
do self.borrow |v| {
let l = v.len();
self.return(v);
self.give_back(v);
l
}
}
......@@ -145,7 +145,7 @@ fn pop() -> A {
do self.borrow |v| {
let mut v <- v;
let result = vec::pop(v);
self.return(v);
self.give_back(v);
result
}
}
......@@ -175,7 +175,7 @@ fn shift() -> A {
do self.borrow |v| {
let mut v = vec::from_mut(v);
let result = vec::shift(v);
self.return(vec::to_mut(v));
self.give_back(vec::to_mut(v));
result
}
}
......@@ -247,7 +247,7 @@ fn append_iter<A, I:iter::base_iter<A>>(ts: I) {
unchecked {
do self.borrow |v| {
let w = vec::from_mut(copy v);
self.return(v);
self.give_back(v);
w
}
}
......
......@@ -192,18 +192,18 @@ fn sub(&&a: int, &&b: int) -> int {
#[test]
fn test_find_success() {
fn match(&&i: int) -> bool { ret i == 2; }
fn match_(&&i: int) -> bool { ret i == 2; }
let l = from_vec(~[0, 1, 2]);
assert (list::find(l, match) == option::some(2));
assert (list::find(l, match_) == option::some(2));
}
#[test]
fn test_find_fail() {
fn match(&&_i: int) -> bool { ret false; }
fn match_(&&_i: int) -> bool { ret false; }
let l = from_vec(~[0, 1, 2]);
let empty = @list::nil::<int>;
assert (list::find(l, match) == option::none::<int>);
assert (list::find(empty, match) == option::none::<int>);
assert (list::find(l, match_) == option::none::<int>);
assert (list::find(empty, match_) == option::none::<int>);
}
#[test]
......
......@@ -68,19 +68,19 @@ fn test_main(args: ~[~str], tests: ~[test_desc]) {
fn parse_opts(args: ~[~str]) -> opt_res {
let args_ = vec::tail(args);
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
let match =
let matches =
alt getopts::getopts(args_, opts) {
ok(m) { m }
err(f) { ret either::right(getopts::fail_str(f)) }
};
let filter =
if vec::len(match.free) > 0u {
option::some(match.free[0])
if vec::len(matches.free) > 0u {
option::some(matches.free[0])
} else { option::none };
let run_ignored = getopts::opt_present(match, ~"ignored");
let logfile = getopts::opt_maybe_str(match, ~"logfile");
let run_ignored = getopts::opt_present(matches, ~"ignored");
let logfile = getopts::opt_maybe_str(matches, ~"logfile");
let test_opts = {filter: filter, run_ignored: run_ignored,
logfile: logfile};
......
......@@ -129,17 +129,17 @@ fn expand_expr(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
// NB: there is some redundancy between this and expand_item, below, and
// they might benefit from some amount of semantic and language-UI merger.
fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
module: ast::_mod, fld: ast_fold,
module_: ast::_mod, fld: ast_fold,
orig: fn@(ast::_mod, ast_fold) -> ast::_mod)
-> ast::_mod
{
// Fold the contents first:
let module = orig(module, fld);
let module_ = orig(module_, fld);
// For each item, look through the attributes. If any of them are
// decorated with "item decorators", then use that function to transform
// the item into a new set of items.
let new_items = do vec::flat_map(module.items) |item| {
let new_items = do vec::flat_map(module_.items) |item| {
do vec::foldr(item.attrs, ~[item]) |attr, items| {
let mname = alt attr.node.value.node {
ast::meta_word(n) { n }
......@@ -159,7 +159,7 @@ fn expand_mod_items(exts: hashmap<~str, syntax_extension>, cx: ext_ctxt,
}
};
ret {items: new_items with module};
ret {items: new_items with module_};
}
......
......@@ -789,7 +789,7 @@ fn parse_bottom_expr() -> pexpr {
ret pexpr(self.parse_while_expr());
} else if self.eat_keyword(~"loop") {
ret pexpr(self.parse_loop_expr());
} else if self.eat_keyword(~"alt") {
} else if self.eat_keyword(~"alt") || self.eat_keyword(~"match") {
ret pexpr(self.parse_alt_expr());
} else if self.eat_keyword(~"fn") {
let proto = self.parse_fn_ty_proto();
......@@ -838,7 +838,7 @@ fn parse_bottom_expr() -> pexpr {
let e = self.parse_expr();
ex = expr_assert(e);
hi = e.span.hi;
} else if self.eat_keyword(~"ret") {
} else if self.eat_keyword(~"ret") || self.eat_keyword(~"return") {
if can_begin_expr(self.token) {
let e = self.parse_expr();
hi = e.span.hi;
......@@ -2569,7 +2569,11 @@ fn parse_foreign_mod_items(+first_item_attrs: ~[attribute]) ->
}
fn parse_item_foreign_mod() -> item_info {
self.expect_keyword(~"mod");
if self.is_keyword(~"mod") {
self.expect_keyword(~"mod");
} else {
self.expect_keyword(~"module");
}
let id = self.parse_ident();
self.expect(token::LBRACE);
let more_attrs = self.parse_inner_attrs_and_next();
......@@ -2714,7 +2718,7 @@ fn parse_item(+attrs: ~[attribute], vis: visibility)
} else {
self.parse_item_foreign_mod()
}
} else if self.eat_keyword(~"mod") {
} else if self.eat_keyword(~"mod") || self.eat_keyword(~"module") {
self.parse_item_mod()
} else if self.eat_keyword(~"type") {
self.parse_item_type()
......@@ -2919,8 +2923,14 @@ fn parse_crate_directive(first_outer_attr: ~[attribute]) ->
let expect_mod = vec::len(outer_attrs) > 0u;
let lo = self.span.lo;
if expect_mod || self.is_keyword(~"mod") {
self.expect_keyword(~"mod");
if expect_mod || self.is_keyword(~"mod") ||
self.is_keyword(~"module") {
if self.is_keyword(~"mod") {
self.expect_keyword(~"mod");
} else {
self.expect_keyword(~"module");
}
let id = self.parse_ident();
alt self.token {
// mod x = "foo.rs";
......@@ -2958,7 +2968,11 @@ fn parse_crate_directives(term: token::token,
// accept seeing the terminator next, so if we do see it then fail the
// same way parse_crate_directive would
if vec::len(first_outer_attr) > 0u && self.token == term {
self.expect_keyword(~"mod");
if self.is_keyword(~"mod") {
self.expect_keyword(~"mod");
} else {
self.expect_keyword(~"module");
}
}
let mut cdirs: ~[@crate_directive] = ~[];
......
......@@ -327,11 +327,11 @@ fn restricted_keyword_table() -> hashmap<~str, ()> {
~"fail", ~"false", ~"fn", ~"for",
~"if", ~"iface", ~"impl", ~"import",
~"let", ~"log", ~"loop",
~"mod", ~"mut",
~"match", ~"mod", ~"module", ~"mut",
~"new",
~"owned",
~"pure",
~"ret",
~"ret", ~"return",
~"struct",
~"true", ~"trait", ~"type",
~"unchecked", ~"unsafe",
......
......@@ -408,19 +408,19 @@ fn host_triple() -> ~str {
};
}
fn build_session_options(match: getopts::matches,
fn build_session_options(matches: getopts::matches,
demitter: diagnostic::emitter) -> @session::options {
let crate_type = if opt_present(match, ~"lib") {
let crate_type = if opt_present(matches, ~"lib") {
session::lib_crate
} else if opt_present(match, ~"bin") {
} else if opt_present(matches, ~"bin") {
session::bin_crate
} else {
session::unknown_crate
};
let static = opt_present(match, ~"static");
let static = opt_present(matches, ~"static");
let parse_only = opt_present(match, ~"parse-only");
let no_trans = opt_present(match, ~"no-trans");
let parse_only = opt_present(matches, ~"parse-only");
let no_trans = opt_present(matches, ~"no-trans");
let lint_levels = [lint::allow, lint::warn,
lint::deny, lint::forbid];
......@@ -429,8 +429,8 @@ fn build_session_options(match: getopts::matches,
for lint_levels.each |level| {
let level_name = lint::level_to_str(level);
let level_short = level_name.substr(0,1).to_upper();
let flags = vec::append(getopts::opt_strs(match, level_short),
getopts::opt_strs(match, level_name));
let flags = vec::append(getopts::opt_strs(matches, level_short),
getopts::opt_strs(matches, level_name));
for flags.each |lint_name| {
let lint_name = str::replace(lint_name, ~"-", ~"_");
alt lint_dict.find(lint_name) {
......@@ -446,7 +446,7 @@ fn build_session_options(match: getopts::matches,
}
let mut debugging_opts = 0u;
let debug_flags = getopts::opt_strs(match, ~"Z");
let debug_flags = getopts::opt_strs(matches, ~"Z");
let debug_map = session::debugging_opts_map();
for debug_flags.each |debug_flag| {
let mut this_bit = 0u;
......@@ -466,34 +466,34 @@ fn build_session_options(match: getopts::matches,
let output_type =
if parse_only || no_trans {
link::output_type_none
} else if opt_present(match, ~"S") &&
opt_present(match, ~"emit-llvm") {
} else if opt_present(matches, ~"S") &&
opt_present(matches, ~"emit-llvm") {
link::output_type_llvm_assembly
} else if opt_present(match, ~"S") {
} else if opt_present(matches, ~"S") {
link::output_type_assembly
} else if opt_present(match, ~"c") {
} else if opt_present(matches, ~"c") {
link::output_type_object
} else if opt_present(match, ~"emit-llvm") {
} else if opt_present(matches, ~"emit-llvm") {
link::output_type_bitcode
} else { link::output_type_exe };
let extra_debuginfo = opt_present(match, ~"xg");
let debuginfo = opt_present(match, ~"g") || extra_debuginfo;
let sysroot_opt = getopts::opt_maybe_str(match, ~"sysroot");
let target_opt = getopts::opt_maybe_str(match, ~"target");
let save_temps = getopts::opt_present(match, ~"save-temps");
let extra_debuginfo = opt_present(matches, ~"xg");
let debuginfo = opt_present(matches, ~"g") || extra_debuginfo;
let sysroot_opt = getopts::opt_maybe_str(matches, ~"sysroot");
let target_opt = getopts::opt_maybe_str(matches, ~"target");
let save_temps = getopts::opt_present(matches, ~"save-temps");
alt output_type {
// unless we're emitting huamn-readable assembly, omit comments.
link::output_type_llvm_assembly | link::output_type_assembly {}
_ { debugging_opts |= session::no_asm_comments; }
}
let opt_level: uint =
if opt_present(match, ~"O") {
if opt_present(match, ~"opt-level") {
if opt_present(matches, ~"O") {
if opt_present(matches, ~"opt-level") {
early_error(demitter, ~"-O and --opt-level both provided");
}
2u
} else if opt_present(match, ~"opt-level") {
alt getopts::opt_str(match, ~"opt-level") {
} else if opt_present(matches, ~"opt-level") {
alt getopts::opt_str(matches, ~"opt-level") {
~"0" { 0u }
~"1" { 1u }
~"2" { 2u }
......@@ -510,9 +510,9 @@ fn build_session_options(match: getopts::matches,
some(s) { s }
};
let addl_lib_search_paths = getopts::opt_strs(match, ~"L");
let cfg = parse_cfgspecs(getopts::opt_strs(match, ~"cfg"));
let test = opt_present(match, ~"test");
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L");
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"));
let test = opt_present(matches, ~"test");
let sopts: @session::options =
@{crate_type: crate_type,
static: static,
......@@ -719,13 +719,13 @@ mod test {
// When the user supplies --test we should implicitly supply --cfg test
#[test]
fn test_switch_implies_cfg_test() {
let match =
let matches =
alt getopts::getopts(~[~"--test"], opts()) {
ok(m) { m }
err(f) { fail ~"test_switch_implies_cfg_test: " +
getopts::fail_str(f); }
};
let sessopts = build_session_options(match, diagnostic::emit);
let sessopts = build_session_options(matches, diagnostic::emit);
let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
assert (attr::contains_name(cfg, ~"test"));
......@@ -735,7 +735,7 @@ fn test_switch_implies_cfg_test() {
// another --cfg test
#[test]
fn test_switch_implies_cfg_test_unless_cfg_test() {
let match =
let matches =
alt getopts::getopts(~[~"--test", ~"--cfg=test"], opts()) {
ok(m) { m }
err(f) {
......@@ -743,7 +743,7 @@ fn test_switch_implies_cfg_test_unless_cfg_test() {
getopts::fail_str(f);
}
};
let sessopts = build_session_options(match, diagnostic::emit);
let sessopts = build_session_options(matches, diagnostic::emit);
let sess = build_session(sessopts, diagnostic::emit);
let cfg = build_configuration(sess, ~"whatever", str_input(~""));
let test_items = attr::find_meta_items_by_name(cfg, ~"test");
......
......@@ -128,7 +128,7 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) {
if vec::len(args) == 0u { usage(binary); ret; }
let match =
let matches =
alt getopts::getopts(args, opts()) {
ok(m) { m }
err(f) {
......@@ -136,31 +136,31 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) {
}
};
if opt_present(match, ~"h") || opt_present(match, ~"help") {
if opt_present(matches, ~"h") || opt_present(matches, ~"help") {
usage(binary);
ret;
}
let lint_flags = vec::append(getopts::opt_strs(match, ~"W"),
getopts::opt_strs(match, ~"warn"));
let lint_flags = vec::append(getopts::opt_strs(matches, ~"W"),
getopts::opt_strs(matches, ~"warn"));
if lint_flags.contains(~"help") {
describe_warnings();
ret;
}
if getopts::opt_strs(match, ~"Z").contains(~"help") {
if getopts::opt_strs(matches, ~"Z").contains(~"help") {
describe_debug_flags();
ret;
}
if opt_present(match, ~"v") || opt_present(match, ~"version") {
if opt_present(matches, ~"v") || opt_present(matches, ~"version") {
version(binary);
ret;
}
let input = alt vec::len(match.free) {
let input = alt vec::len(matches.free) {
0u { early_error(demitter, ~"no input filename given") }
1u {
let ifile = match.free[0];
let ifile = matches.free[0];
if ifile == ~"-" {
let src = str::from_bytes(io::stdin().read_whole_stream());
str_input(src)
......@@ -171,20 +171,20 @@ fn run_compiler(args: ~[~str], demitter: diagnostic::emitter) {
_ { early_error(demitter, ~"multiple input filenames provided") }
};
let sopts = build_session_options(match, demitter);
let sopts = build_session_options(matches, demitter);
let sess = build_session(sopts, demitter);
let odir = getopts::opt_maybe_str(match, ~"out-dir");
let ofile = getopts::opt_maybe_str(match, ~"o");
let odir = getopts::opt_maybe_str(matches, ~"out-dir");
let ofile = getopts::opt_maybe_str(matches, ~"o");
let cfg = build_configuration(sess, binary, input);
let pretty =
option::map(getopts::opt_default(match, ~"pretty",
option::map(getopts::opt_default(matches, ~"pretty",
~"normal"),
|a| parse_pretty(sess, a) );
alt pretty {
some::<pp_mode>(ppm) { pretty_print_input(sess, cfg, input, ppm); ret; }
none::<pp_mode> {/* continue */ }
}
let ls = opt_present(match, ~"ls");
let ls = opt_present(matches, ~"ls");
if ls {
alt input {
file_input(ifile) {
......
......@@ -78,10 +78,10 @@ fn warn_if_multiple_versions(diag: span_handler,
if matches.len() != 1u {
diag.handler().warn(
fmt!{"using multiple versions of crate `%s`", *name});
for matches.each |match| {
diag.span_note(match.span, ~"used here");
for matches.each |match_| {
diag.span_note(match_.span, ~"used here");
let attrs = ~[
attr::mk_attr(attr::mk_list_item(@~"link", *match.metas))
attr::mk_attr(attr::mk_list_item(@~"link", *match_.metas))
];
loader::note_linkage_attrs(diag, attrs);
}
......
......@@ -157,11 +157,11 @@ fn encode_class_item_paths(ebml_w: ebml::writer,
}
fn encode_module_item_paths(ebml_w: ebml::writer, ecx: @encode_ctxt,
module: _mod, path: ~[ident],
module_: _mod, path: ~[ident],
&index: ~[entry<~str>]) {
for module.items.each |it| {
for module_.items.each |it| {
if !reachable(ecx, it.id) ||
!ast_util::is_exported(it.ident, module) { again; }
!ast_util::is_exported(it.ident, module_) { again; }
if !ast_util::is_item_impl(it) {
add_to_index(ebml_w, path, index, it.ident);
}
......
......@@ -106,9 +106,9 @@ fn find_library_crate_aux(cx: ctxt,
cx.diag.span_err(
cx.span, fmt!{"multiple matching crates for `%s`", *crate_name});
cx.diag.handler().note(~"candidates:");
for matches.each |match| {
cx.diag.handler().note(fmt!{"path: %s", match.ident});
let attrs = decoder::get_crate_attributes(match.data);
for matches.each |match_| {
cx.diag.handler().note(fmt!{"path: %s", match_.ident});
let attrs = decoder::get_crate_attributes(match_.data);
note_linkage_attrs(cx.diag, attrs);
}
cx.diag.handler().abort_if_errors();
......
......@@ -332,13 +332,13 @@ fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint,
pat_box(a) | pat_uniq(a) { some(vec::append(~[a], vec::tail(r))) }
pat_lit(expr) {
let e_v = eval_const_expr(tcx, expr);
let match = alt check ctor_id {
let match_ = alt check ctor_id {
val(v) { compare_const_vals(e_v, v) == 0 }
range(c_lo, c_hi) { compare_const_vals(c_lo, e_v) >= 0 &&
compare_const_vals(c_hi, e_v) <= 0 }
single { true }
};
if match { some(vec::tail(r)) } else { none }
if match_ { some(vec::tail(r)) } else { none }
}
pat_range(lo, hi) {
let (c_lo, c_hi) = alt check ctor_id {
......@@ -348,9 +348,9 @@ fn specialize(tcx: ty::ctxt, r: ~[@pat], ctor_id: ctor, arity: uint,
};
let v_lo = eval_const_expr(tcx, lo),
v_hi = eval_const_expr(tcx, hi);
let match = compare_const_vals(c_lo, v_lo) >= 0 &&
let match_ = compare_const_vals(c_lo, v_lo) >= 0 &&
compare_const_vals(c_hi, v_hi) <= 0;
if match { some(vec::tail(r)) } else { none }
if match_ { some(vec::tail(r)) } else { none }
}
}
}
......
此差异已折叠。
......@@ -93,9 +93,9 @@ fn assoc(key: ast::ident, list: bind_map) -> option<ValueRef> {
data: @{bodycx: block,
guard: option<@ast::expr>,
id_map: pat_id_map}};
type match = ~[match_branch];
type match_ = ~[match_branch];
fn has_nested_bindings(m: match, col: uint) -> bool {
fn has_nested_bindings(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
alt br.pats[col].node {
ast::pat_ident(_, some(_)) { ret true; }
......@@ -105,7 +105,7 @@ fn has_nested_bindings(m: match, col: uint) -> bool {
ret false;
}
fn expand_nested_bindings(m: match, col: uint, val: ValueRef) -> match {
fn expand_nested_bindings(m: match_, col: uint, val: ValueRef) -> match_ {
let mut result = ~[];
for vec::each(m) |br| {
alt br.pats[col].node {
......@@ -129,8 +129,8 @@ fn expand_nested_bindings(m: match, col: uint, val: ValueRef) -> match {
type enter_pat = fn(@ast::pat) -> option<~[@ast::pat]>;
fn enter_match(dm: DefMap, m: match, col: uint, val: ValueRef,
e: enter_pat) -> match {
fn enter_match(dm: DefMap, m: match_, col: uint, val: ValueRef,
e: enter_pat) -> match_ {
let mut result = ~[];
for vec::each(m) |br| {
alt e(br.pats[col]) {
......@@ -154,7 +154,7 @@ fn enter_match(dm: DefMap, m: match, col: uint, val: ValueRef,
ret result;
}
fn enter_default(dm: DefMap, m: match, col: uint, val: ValueRef) -> match {
fn enter_default(dm: DefMap, m: match_, col: uint, val: ValueRef) -> match_ {
do enter_match(dm, m, col, val) |p| {
alt p.node {
ast::pat_wild | ast::pat_rec(_, _) | ast::pat_tup(_) { some(~[]) }
......@@ -166,8 +166,8 @@ fn enter_default(dm: DefMap, m: match, col: uint, val: ValueRef) -> match {
}
}
fn enter_opt(tcx: ty::ctxt, m: match, opt: opt, col: uint,
variant_size: uint, val: ValueRef) -> match {
fn enter_opt(tcx: ty::ctxt, m: match_, opt: opt, col: uint,
variant_size: uint, val: ValueRef) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(tcx.def_map, m, col, val) |p| {
alt p.node {
......@@ -192,8 +192,8 @@ fn enter_opt(tcx: ty::ctxt, m: match, opt: opt, col: uint,
}
}
fn enter_rec(dm: DefMap, m: match, col: uint, fields: ~[ast::ident],
val: ValueRef) -> match {
fn enter_rec(dm: DefMap, m: match_, col: uint, fields: ~[ast::ident],
val: ValueRef) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(dm, m, col, val) |p| {
alt p.node {
......@@ -213,8 +213,8 @@ fn enter_rec(dm: DefMap, m: match, col: uint, fields: ~[ast::ident],
}
}
fn enter_tup(dm: DefMap, m: match, col: uint, val: ValueRef,
n_elts: uint) -> match {
fn enter_tup(dm: DefMap, m: match_, col: uint, val: ValueRef,
n_elts: uint) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(dm, m, col, val) |p| {
alt p.node {
......@@ -224,7 +224,7 @@ fn enter_tup(dm: DefMap, m: match, col: uint, val: ValueRef,
}
}
fn enter_box(dm: DefMap, m: match, col: uint, val: ValueRef) -> match {
fn enter_box(dm: DefMap, m: match_, col: uint, val: ValueRef) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(dm, m, col, val) |p| {
alt p.node {
......@@ -234,7 +234,7 @@ fn enter_box(dm: DefMap, m: match, col: uint, val: ValueRef) -> match {
}
}
fn enter_uniq(dm: DefMap, m: match, col: uint, val: ValueRef) -> match {
fn enter_uniq(dm: DefMap, m: match_, col: uint, val: ValueRef) -> match_ {
let dummy = @{id: 0, node: ast::pat_wild, span: dummy_sp()};
do enter_match(dm, m, col, val) |p| {
alt p.node {
......@@ -244,7 +244,7 @@ fn enter_uniq(dm: DefMap, m: match, col: uint, val: ValueRef) -> match {
}
}
fn get_options(ccx: @crate_ctxt, m: match, col: uint) -> ~[opt] {
fn get_options(ccx: @crate_ctxt, m: match_, col: uint) -> ~[opt] {
fn add_to_set(tcx: ty::ctxt, &&set: dvec<opt>, val: opt) {
if set.any(|l| opt_eq(tcx, l, val)) {ret;}
set.push(val);
......@@ -294,7 +294,7 @@ fn extract_variant_args(bcx: block, pat_id: ast::node_id,
ret {vals: args, bcx: bcx};
}
fn collect_record_fields(m: match, col: uint) -> ~[ast::ident] {
fn collect_record_fields(m: match_, col: uint) -> ~[ast::ident] {
let mut fields: ~[ast::ident] = ~[];
for vec::each(m) |br| {
alt br.pats[col].node {
......@@ -311,7 +311,7 @@ fn collect_record_fields(m: match, col: uint) -> ~[ast::ident] {
ret fields;
}
fn root_pats_as_necessary(bcx: block, m: match, col: uint, val: ValueRef) {
fn root_pats_as_necessary(bcx: block, m: match_, col: uint, val: ValueRef) {
for vec::each(m) |br| {
let pat_id = br.pats[col].id;
......@@ -331,21 +331,21 @@ fn root_pats_as_necessary(bcx: block, m: match, col: uint, val: ValueRef) {
}
}
fn any_box_pat(m: match, col: uint) -> bool {
fn any_box_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
alt br.pats[col].node { ast::pat_box(_) { ret true; } _ { } }
}
ret false;
}
fn any_uniq_pat(m: match, col: uint) -> bool {
fn any_uniq_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
alt br.pats[col].node { ast::pat_uniq(_) { ret true; } _ { } }
}
ret false;
}
fn any_tup_pat(m: match, col: uint) -> bool {
fn any_tup_pat(m: match_, col: uint) -> bool {
for vec::each(m) |br| {
alt br.pats[col].node { ast::pat_tup(_) { ret true; } _ { } }
}
......@@ -355,7 +355,7 @@ fn any_tup_pat(m: match, col: uint) -> bool {
type exit_node = {bound: bind_map, from: BasicBlockRef, to: BasicBlockRef};
type mk_fail = fn@() -> BasicBlockRef;
fn pick_col(m: match) -> uint {
fn pick_col(m: match_) -> uint {
fn score(p: @ast::pat) -> uint {
alt p.node {
ast::pat_lit(_) | ast::pat_enum(_, _) | ast::pat_range(_, _) { 1u }
......@@ -383,7 +383,7 @@ fn score(p: @ast::pat) -> uint {
ret best_col;
}
fn compile_submatch(bcx: block, m: match, vals: ~[ValueRef],
fn compile_submatch(bcx: block, m: match_, vals: ~[ValueRef],
chk: option<mk_fail>, &exits: ~[exit_node]) {
/*
For an empty match, a fall-through case must exist
......@@ -651,7 +651,7 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm],
mode: ast::alt_mode, dest: dest) -> block {
let _icx = scope_cx.insn_ctxt(~"alt::trans_alt_inner");
let bcx = scope_cx, tcx = bcx.tcx();
let mut bodies = ~[], match = ~[];
let mut bodies = ~[], matches = ~[];
let {bcx, val, _} = trans_temp_expr(bcx, expr);
if bcx.unreachable { ret bcx; }
......@@ -661,7 +661,7 @@ fn trans_alt_inner(scope_cx: block, expr: @ast::expr, arms: ~[ast::arm],
let id_map = pat_util::pat_id_map(tcx.def_map, a.pats[0]);
vec::push(bodies, body);
for vec::each(a.pats) |p| {
vec::push(match, @{pats: ~[p],
vec::push(matches, @{pats: ~[p],
bound: ~[],
data: @{bodycx: body, guard: a.guard,
id_map: id_map}});
......@@ -698,7 +698,7 @@ fn mk_fail(bcx: block, sp: span, msg: ~str,
};
let mut exit_map = ~[];
let spilled = spill_if_immediate(bcx, val, t);
compile_submatch(bcx, match, ~[spilled], mk_fail, exit_map);
compile_submatch(bcx, matches, ~[spilled], mk_fail, exit_map);
let mut arm_cxs = ~[], arm_dests = ~[], i = 0u;
for vec::each(arms) |a| {
......
......@@ -363,10 +363,10 @@ fn check_privileged_scopes(crate: @crate) {
visit_crate(*crate, (), mk_vt(@{
visit_item: |item, _context, visitor| {
alt item.node {
item_mod(module) {
item_mod(module_) {
// First, gather up all privileged types.
let privileged_types =
self.gather_privileged_types(module.items);
self.gather_privileged_types(module_.items);
for privileged_types.each |privileged_type| {
debug!{"(checking privileged scopes) entering \
privileged scope of %d:%d",
......@@ -377,7 +377,7 @@ fn check_privileged_scopes(crate: @crate) {
}
// Then visit the module items.
visit_mod(module, item.span, item.id, (), visitor);
visit_mod(module_, item.span, item.id, (), visitor);
// Finally, remove privileged types from the map.
for privileged_types.each |privileged_type| {
......
......@@ -101,11 +101,11 @@ fn parse_config_(
let args = vec::tail(args);
let opts = vec::unzip(opts()).first();
alt getopts::getopts(args, opts) {
result::ok(match) {
if vec::len(match.free) == 1u {
let input_crate = vec::head(match.free);
config_from_opts(input_crate, match, program_output)
} else if vec::is_empty(match.free) {
result::ok(matches) {
if vec::len(matches.free) == 1u {
let input_crate = vec::head(matches.free);
config_from_opts(input_crate, matches, program_output)
} else if vec::is_empty(matches.free) {
result::err(~"no crates specified")
} else {
result::err(~"multiple crates specified")
......@@ -119,14 +119,14 @@ fn parse_config_(
fn config_from_opts(
input_crate: ~str,
match: getopts::matches,
matches: getopts::matches,
program_output: program_output
) -> result<config, ~str> {
let config = default_config(input_crate);
let result = result::ok(config);
let result = do result::chain(result) |config| {
let output_dir = getopts::opt_maybe_str(match, opt_output_dir());
let output_dir = getopts::opt_maybe_str(matches, opt_output_dir());
result::ok({
output_dir: option::get_default(output_dir, config.output_dir)
with config
......@@ -134,7 +134,7 @@ fn config_from_opts(
};
let result = do result::chain(result) |config| {
let output_format = getopts::opt_maybe_str(
match, opt_output_format());
matches, opt_output_format());
do option::map_default(output_format, result::ok(config))
|output_format| {
do result::chain(parse_output_format(output_format))
......@@ -148,7 +148,8 @@ fn config_from_opts(
}
};
let result = do result::chain(result) |config| {
let output_style = getopts::opt_maybe_str(match, opt_output_style());
let output_style =
getopts::opt_maybe_str(matches, opt_output_style());
do option::map_default(output_style, result::ok(config))
|output_style| {
do result::chain(parse_output_style(output_style))
......@@ -161,7 +162,7 @@ fn config_from_opts(
}
};
let result = do result::chain(result) |config| {
let pandoc_cmd = getopts::opt_maybe_str(match, opt_pandoc_cmd());
let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd());
let pandoc_cmd = maybe_find_pandoc(
config, pandoc_cmd, program_output);
do result::chain(pandoc_cmd) |pandoc_cmd| {
......
......@@ -52,11 +52,11 @@ fn mk_itemdoc(id: ast::node_id, name: ast::ident) -> doc::itemdoc {
fn moddoc_from_mod(
itemdoc: doc::itemdoc,
module: ast::_mod
module_: ast::_mod
) -> doc::moddoc {
doc::moddoc_({
item: itemdoc,
items: do vec::filter_map(module.items) |item| {
items: do vec::filter_map(module_.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
ast::item_mod(m) {
......@@ -110,11 +110,11 @@ fn moddoc_from_mod(
fn nmoddoc_from_mod(
itemdoc: doc::itemdoc,
module: ast::foreign_mod
module_: ast::foreign_mod
) -> doc::nmoddoc {
{
item: itemdoc,
fns: do vec::map(module.items) |item| {
fns: do vec::map(module_.items) |item| {
let itemdoc = mk_itemdoc(item.id, item.ident);
alt item.node {
ast::foreign_item_fn(_, _) {
......
// error-pattern: expected `mod`
// error-pattern: expected `module`
#[attr = "val"];
#[attr = "val"] // Unterminated
// ret -> return
// mod -> module
// alt -> match
fn main() {
}
mod foo {
}
fn bar() -> int {
match 0 {
_ { 0 }
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册